Skip to content

Improve context-store setup and cleanup UX#1137

Merged
alfred-openspec merged 3 commits into
mainfrom
codex/context-store-first-run-cleanup-ux
May 28, 2026
Merged

Improve context-store setup and cleanup UX#1137
alfred-openspec merged 3 commits into
mainfrom
codex/context-store-first-run-cleanup-ux

Conversation

@TabishB

@TabishB TabishB commented May 28, 2026

Copy link
Copy Markdown
Contributor

Summary

  • add guided interactive context-store setup with explicit non-interactive/JSON validation
  • add path safety checks for setup inside existing Git repositories
  • add context-store unregister and context-store remove cleanup flows with docs, completions, and tests

Verification

  • pnpm build
  • pnpm lint
  • pnpm vitest run test/commands/context-store.test.ts test/core/context-store/registry.test.ts
  • pnpm test

Summary by CodeRabbit

  • New Features

    • Added context-store unregister (forget registration) and context-store remove (forget + delete local store; non-interactive requires --yes)
    • context-store setup supports interactive no-arg guided setup and deterministic non-interactive JSON usage
  • Behavior / Safety

    • Blocks creating managed stores inside existing Git repos unless explicitly confirmed
    • Removal refuses deletion when store metadata doesn’t match; safer deletion checks
  • Documentation

    • Updated CLI reference, user guide, and agent playbook for these flows
  • Tests

    • Expanded tests for setup, unregister, remove, and Git-related scenarios

Review Change Stack

@coderabbitai

coderabbitai Bot commented May 28, 2026

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 7b7d052e-07df-4c0f-a383-e682deca37c4

📥 Commits

Reviewing files that changed from the base of the PR and between 2dd15a6 and 47b9f40.

📒 Files selected for processing (1)
  • test/core/context-store/registry.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • test/core/context-store/registry.test.ts

📝 Walkthrough

Walkthrough

Adds context-store unregister and remove; refactors context-store setup for interactive no-args prompts with ~ expansion and Git-repo nesting checks; implements registry retrieval/unregister APIs and safer removal logic; updates CLI wiring, tests, docs, and spec to emit human/JSON outputs.

Changes

Context Store Cleanup Commands and Interactive Setup

Layer / File(s) Summary
Core cleanup operations and registry types
src/core/context-store/operations.ts, src/core/context-store/registry.ts, src/core/context-store/foundation.ts
Adds ContextStoreCleanupResult, expandUserPath() (~ expansion), Git-nesting detection and guards, prepareContextStoreCleanup/unregisterContextStore/removeContextStore, and registry helpers (getRegisteredContextStore, unregisterContextStoreRegistration) with backend-matching and safe deletion checks.
CLI setup, unregister, and remove commands
src/commands/context-store.ts
Refactors setup to resolve id/path interactively when no args are provided, adds confirmation flow for Git-nesting, and implements unregister and remove subcommands with human vs JSON output (ContextStoreCleanupOutput, toCleanupOutput).
Command registry metadata
src/core/completions/command-registry.ts
Adds unregister and remove subcommands to the command registry/completions with required id positional and flags (--json, --yes).
User-facing CLI and playbook documentation
docs/cli.md, docs/workspaces-beta/user-guide.md, docs/workspaces-beta/agent-cli-playbook.md
Documents interactive openspec context-store setup no-arg prompts, agent non-interactive JSON usage, and new unregister (forget only) vs remove (forget + delete, requires --yes for non-interactive) semantics and examples.
Implementation specification and roadmap
openspec/initiatives/context-store-and-initiatives/...
Marks work item implemented and records UX decisions: interactive vs deterministic non-interactive flows, Git init constraints, cleanup intent distinction, and JSON output contract (no next_commands).
CLI and core tests
test/commands/context-store.test.ts, test/core/context-store/registry.test.ts, test/core/completions/command-registry.test.ts
Adds tests for guided interactive setup, non-interactive/JSON validation, Git-nesting rejection/confirmation, unregister/remove lifecycle (including --yes gating and metadata-matching refusal), registry safety on mutated backends, and deletion-error handling.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

  • Fission-AI/OpenSpec#1127: Builds on the context-store foundation by extending registry/operations with cleanup/unregister/remove mechanics.
  • Fission-AI/OpenSpec#289: Related to adding command registry/completions entries used by the new unregister/remove commands.

Suggested reviewers

  • alfred-openspec

Poem

🐰 I hopped through docs and code with care,

Added commands to tidy what we share.
~ expands, prompts guide the way,
Git-nesting checks keep surprises at bay.
Unregister forgets; remove clears the lair—hop on, all set and fair!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely summarizes the primary change: improving the UX for context-store setup and cleanup operations, which aligns with all major modifications across documentation, core operations, and command implementations.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/context-store-first-run-cleanup-ux

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@TabishB

TabishB commented May 28, 2026

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented May 28, 2026

Copy link
Copy Markdown
Contributor
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@docs/cli.md`:
- Line 11: The Agent-Compatible Commands matrix is missing the newly added
context-store commands; update the table to include `context-store unregister`
and `context-store remove` as agent-compatible entries, documenting that both
accept `--json` for machine-friendly output and that `context-store remove`
additionally supports a non-interactive `--yes` flag for forced deletion; locate
the matrix generation/markdown row for "Shared context (beta)" and add these two
commands with the same formatting and notes used for other context-store
commands (e.g., matching how `context-store register`/`list` are represented).

In `@src/core/context-store/operations.ts`:
- Around line 183-206: In findContainingGitRepositoryRoot, don't swallow all
execFileAsync('git'...) failures; in the catch block perform a filesystem-only
parent walk from nearestParent looking for a ".git" entry (use
FileSystemUtils.canonicalizeExistingPath and path.dirname/path.join or
nearestExistingDirectory to ascend) and if you find a .git directory treat that
ancestor as the git root (compute comparableStoreRoot relative check as
currently done), otherwise throw a ContextStoreError that includes the original
error information instead of returning null; keep execFileAsync,
nearestExistingDirectory and FileSystemUtils calls as the primary utilities to
locate/normalize paths.

In `@src/core/context-store/registry.ts`:
- Around line 158-167: The equality check in contextStoreBackendsMatch treats
local_path as a raw string, so normalize both actual.local_path and
expected.local_path with the same canonicalization helper used by conflict
detection (e.g., canonicalizeLocalPath or the project's path canonicalizer)
before comparing; update contextStoreBackendsMatch to call that helper on both
local_path values and compare the canonicalized results while leaving
comparisons of actual.type, actual.remote, and actual.branch unchanged.

In `@test/commands/context-store.test.ts`:
- Around line 439-450: Tests currently compare raw temp paths (storeRoot)
against registry/cleanup identities which can differ when temp dirs are
symlinked; update assertions to canonicalize expected paths by calling
expectedExistingPath(storeRoot) and use that canonical value in the
parseJson(...) assertions (e.g., where parseJson(result) is asserted to contain
files.left_on_disk or registry identities). For the successful remove case,
capture the canonical path into a variable before invoking runCLI() (so the
folder can be deleted) and assert against that captured canonical value; ensure
you call expectedExistingPath(storeRoot) wherever the test currently uses raw
storeRoot for path identity comparisons (including the other two similar
blocks).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: bdcad684-0a3b-4ede-ba8b-a215f088d4d8

📥 Commits

Reviewing files that changed from the base of the PR and between 21c1805 and 427d37d.

📒 Files selected for processing (14)
  • docs/cli.md
  • docs/workspaces-beta/agent-cli-playbook.md
  • docs/workspaces-beta/user-guide.md
  • openspec/initiatives/context-store-and-initiatives/tasks.md
  • openspec/initiatives/context-store-and-initiatives/work-items/12-context-store-first-run-and-cleanup-ux/evidence.md
  • openspec/initiatives/context-store-and-initiatives/work-items/12-context-store-first-run-and-cleanup-ux/plan.md
  • openspec/initiatives/context-store-and-initiatives/work-items/12-context-store-first-run-and-cleanup-ux/tasks.md
  • src/commands/context-store.ts
  • src/core/completions/command-registry.ts
  • src/core/context-store/operations.ts
  • src/core/context-store/registry.ts
  • test/commands/context-store.test.ts
  • test/core/completions/command-registry.test.ts
  • test/core/context-store/registry.test.ts

Comment thread docs/cli.md
Comment thread src/core/context-store/operations.ts
Comment thread src/core/context-store/operations.ts Outdated
Comment thread src/core/context-store/registry.ts
Comment thread test/commands/context-store.test.ts

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@test/core/context-store/registry.test.ts`:
- Around line 545-548: The assertion currently compares the raw storeRoot
string; canonicalize filesystem identity by applying fs.realpathSync.native() to
the expected storeRoot in the test. Update the assertion that checks the
objectContaining for id 'team-context' to use storeRoot:
fs.realpathSync.native(storeRoot) (or realpath the actual result if you prefer),
ensuring you use the same fs.realpathSync.native() call used elsewhere in this
test file so both expected and actual filesystem paths are compared by canonical
identity.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 57d11014-f510-4adb-9eaf-28405df2db6e

📥 Commits

Reviewing files that changed from the base of the PR and between 427d37d and 2dd15a6.

📒 Files selected for processing (6)
  • docs/cli.md
  • src/core/context-store/foundation.ts
  • src/core/context-store/operations.ts
  • src/core/context-store/registry.ts
  • test/commands/context-store.test.ts
  • test/core/context-store/registry.test.ts
🚧 Files skipped from review as they are similar to previous changes (4)
  • docs/cli.md
  • src/core/context-store/registry.ts
  • test/commands/context-store.test.ts
  • src/core/context-store/operations.ts

Comment thread test/core/context-store/registry.test.ts Outdated
@coderabbitai

coderabbitai Bot commented May 28, 2026

Copy link
Copy Markdown
Contributor

Actionable comments posted: 0

@alfred-openspec alfred-openspec added this pull request to the merge queue May 28, 2026
Merged via the queue into main with commit 0c5f0c6 May 28, 2026
12 checks passed
@alfred-openspec alfred-openspec deleted the codex/context-store-first-run-cleanup-ux branch May 28, 2026 18:04
linjinze999 pushed a commit to linjinze999/OpenSpec that referenced this pull request Jun 4, 2026
* Improve context-store setup and cleanup UX

* Address CodeRabbit context-store feedback

* Canonicalize cleanup registry test assertion
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants