feat(cli): add indexing and search commands#721
Merged
Conversation
2965d24 to
d25b7a7
Compare
Owner
|
Thanks @dennesneumann. Conflicting on Optional follow-up nit: pass Verdict was MERGE_WITH_NITS — re-ping after rebase. |
Add terminal commands for indexing local files or directories into the persistent FTS5 content store and searching that store by project/source. Expose slash-style ctx-index and ctx-search skill triggers, update README utility command docs, and cover the new CLI/skill surface in focused tests. Validation: pnpm exec tsc --noEmit --pretty false; pnpm exec vitest run tests/core/cli.test.ts --reporter=dot; CLI smoke index/search with temporary CONTEXT_MODE_DIR; git diff --check.
d25b7a7 to
c863044
Compare
mksglu
added a commit
that referenced
this pull request
May 31, 2026
Adds an opt-in `project` parameter to `ctx_search` that scopes the FTS5
ContentStore to a single project directory when the user runs in shared-
DB mode (`CONTEXT_MODE_PROJECT_DIR` set at launch). The field is
registered conditionally on the schema — it physically does not exist
on the tool surface when shared mode is off — so the LLM cannot pass an
inactionable parameter. This is a stronger guarantee than runtime
validation that depends on the model honouring the description.
`src/search/ctx-search-schema.ts` factors the schema builder out of
`server.ts` to keep the conditional field path testable in isolation:
- `buildCtxSearchInputSchema(isSharedMode)` composes the Zod object.
When `isSharedMode === false`, `Object.keys(schema.shape)` does NOT
include `project`; when true, it does. The base fields and their
`z.coerce.number()` / `z.preprocess(coerceJsonArray, ...)` semantics
match the previous inline definition byte-for-byte, including the
bare-string lift behaviour relied on by the OpenCode native plugin
bridge (regression coverage in tests/opencode-plugin.test.ts).
- `resolveProjectScope(raw, isSharedMode, getProjectDirFn)` normalises
the param into the three-state contract that `searchAllSources`
consumes: `undefined` (no filter), `null` (cross-project recall),
`string` (restrict to that path).
- `CTX_SEARCH_SHARED_MODE` snapshots `process.env.CONTEXT_MODE_PROJECT_DIR`
at module load. The tool surface registered with
`server.registerTool` should never flip mid-session, so the env read
happens once.
The ctx_search handler in `src/server.ts` opens SessionDB whenever a
string `projectScope` is in play (not only in timeline mode) so the
relevance-mode path can resolve the same allow-set that searchAllSources
resolves internally for timeline mode. Both paths now agree on
filtering, and an absent / `null` scope preserves today's behaviour.
Test coverage in `tests/core/search-project-filter.test.ts` covers:
- Slice 1 — ContentStore.searchWithFallback with the allow-set,
including legacy session_id='' visibility and a no-op undefined
pass.
- Slice 2 — SessionDB.getSessionIdsForProject with multi-project
fixtures and a 1000-session perf sanity bound.
- Slice 3 — searchAllSources.projectScope wired end-to-end
(string, null, undefined).
- Slice 4 — Conditional schema registration.
- Slice 5 — resolveProjectScope helper truth table.
Closes #737. Refs e7dbf58 (#363 — unified persistent memory baseline),
ead9177 (#367 — searchAllSources unification), PR #698 (query_scope
precedent for parameter shape), PR #721 (CLI --project naming parity).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds terminal and slash-style entry points for pre-warming and querying context-mode's persistent FTS5 knowledge base.
context-mode index <path>for indexing local files/directories into the per-project content DBcontext-mode search <query...>for querying indexed content from the terminal/context-mode:ctx-indexand/context-mode:ctx-searchskillsWhy
ctx_index(path)already supports indexing file and directory content through MCP, but there was no deterministic terminal entry point for pre-filling the SQLite/FTS5 store before or outside an agent session. This makes the workflow discoverable and automatable while keeping raw project bytes out of chat context.Validation
pnpm exec tsc --noEmit --pretty falsepnpm exec vitest run tests/core/cli.test.ts --reporter=dotcontext-mode index README.md --project . --source smoke:readme, thencontext-mode search "context savings" --project . --source smoke:readme --limit 1git diff --check