Repository navigation
feat(rag): expose bounded multi-section document context over MCP - #25
Conversation
ipiton
left a comment
There was a problem hiding this comment.
Thanks — the use case is real, and tests/eval/plugin-smoke pass on current main. Two design issues before this can go in:
- It does not work from a worktree under the Claude Code plugin. The plugin runs with
MCP_DATA_SCOPE=project(plugin/scripts/launch.sh), where the index is built from the main checkout (RAG.IndexRoot, T165) whilepathGuardresolves againstRootPath(the worktree).callDocumentContextrequires the guard-resolved path to equal the indexed physical path, so every call from a worktree fails with "indexed source does not match the allowed file" — even for a pathsemantic_searchjust returned.TestDocumentContextCannotBypassAllowlistOrReadAnotherIndexRootasserts this "cross-root" refusal, but that layout is the supported default, not an attack. The logical path should be resolved against the index root the server is configured with. - We already have the read side:
Engine.ExpandSection(internal/rag/rag.go, T49 "pointer-based context") —semantic_searchreturnssection_key, andExpandSection(doc_path, section_key)materialises the whole section. It just isn't exposed over MCP. Please build on it (expose it, then extend to several sections + a shared budget + optional in-file query ranking) instead of a parallel breadcrumb/merge path.
With that, the per-file source_path:* rows in index_metadata, EvalSymlinks in processFile and the snapshot transaction look unnecessary: repo_read relies on pathGuard alone, and indexed text shouldn't need a stricter provenance model than a live file read. If you think physical-origin binding is still needed, let's discuss it separately — and it would belong in indexed_files, not as one metadata key per file. Smaller points: the tool description should tell an agent when to use it (and describe path), and I'd keep it out of the core profile for now.
|
Updated against current
All five upstream GitHub checks passed on |
|
Thanks — both blockers from the previous review are addressed, and this branch passes build, vet, One integration issue with #21, which is landing first: on This branch now stores the Please rebase on |
|
Thanks for testing the two changes together. I merged current Indexing now uses the same resolved root to write The discovery, document-context and linked-checkout tests and On |
|
Thanks — the #21 conflict is resolved, and One gap remains: upgrading an existing index when the project root is reached through a symlink. Indexes written by current
The last one is the loss #21 is meant to prevent, reached by following our own error message. A candidate fix, right after if !sameRoot && oldRoot != "" && rootResolutionErr == nil {
if resolvedOld, err := filepath.EvalSymlinks(oldRoot); err == nil && resolvedOld == indexRoot {
sameRoot = true
}
}With it, these three cases and all of Please add a regression test for a legacy unresolved |
|
Fixed the legacy-root upgrade cases in The stored alias is resolved at upgrade time when the index has no matching resolved-root marker. If it resolves to the current physical root, indexing retains unavailable records and publishes the canonical root even when no document content changed. A small per-index marker prevents a newly recorded physical root from later being reinterpreted as an old alias. No schema change or per-file backfill is needed. Regression tests reproduce all three reported cases: a partial outage, the only source unavailable, and a partial outage with Local validation passed: |
After
semantic_searchfinds a file,document_contextreads several indexed sections within a shared character budget. Pass section keys, the original question for in-file ranking, or neither to read in document order. The tool is available in the full profile, including groupedsearchwithaction: "context". Search in that profile prints section keys.The tool uses the section assembly behind
Engine.ExpandSection. In project scope it applies the existing allowlist rules relative to the configured index root, so a linked worktree can read indexed sections from the main checkout. Repository file tools still resolve against the calling worktree. The index root captured by path authorization is compared with the root recorded at indexing time.This revision removes per-file origin metadata, indexing-time resolution of each source file, and the special SQLite snapshot. It reads the existing document rows and checks readiness and publication stamps. A completed index that records the resolved root needs no schema change or per-file backfill. For an older index without the resolved-root marker, indexing resolves the stored alias at upgrade time. If it matches the current physical root, indexing upgrades the root stamps while retaining records under unavailable sources. A new per-index marker distinguishes resolved roots from legacy aliases; it needs no schema change or per-file backfill. If no root is recorded, automatic adoption waits for unavailable sources that still contain indexed files. The returned text reflects the index and can lag edits or source-link changes.
Integration with #21
The branch includes current
mainatcba46cf. Indexing uses the same resolved root to record and compare the index identity. A temporary source outage preserves existing fragments when the root is unchanged, including with--allow-root-change. If a linked project root stops resolving, the override cannot discard protected records based on an unverified root change.The legacy-upgrade regressions also cover a partial outage, an outage of the only source, and a partial outage with
--allow-root-change. Available documents remain readable throughdocument_contextafter the upgrade. Separate negative cases retain the foreign-root guard, including replacement of a previously resolved physical root by a link.Validation
make build test vet eval plugin-smokego test -race ./...--allow-root-change, and for a dangling root with a readable external source.adf9d6c, including both macOS smoke jobs.