Repository navigation
feat(mcp): scan_prepare selection inputs, source-first ordering, planning data (#686) - #709
Merged
Merged
Conversation
…ning data (#686) scan_prepare and scan_finalize accept include, exclude, extensions, incremental, changed_since and order, mirroring `cora scan`. Exclude merges config ignore.files like the CLI; changed_since is `git diff --relative <rev>` plus untracked files; incremental reuses the CLI scan cache. Batches default to `order: "source-first"` (code before docs/data, shallower first, then path); `"path"` keeps the legacy walk order. Every prepare response now carries total_chars, estimated_tokens (chars/4), per-batch files/chars, the chosen order and the effective include/exclude. Finalize compatibility: finalize recomputes the file set with the same selection code and ordering, so files_fingerprint matches only when the same inputs are passed; different filters or order refuse as "project files changed". Finalize records the incremental cache only after a complete judgement. Fixes #686
ajianaz
added a commit
that referenced
this pull request
Oct 27, 2026
…ning data (#686) (#709) ## What Implements #686 for the MCP agent-as-reviewer scan tools: - `cora.scan_prepare` + `cora.scan_finalize` now accept the CLI's selection inputs: `include` (globs), `exclude` (globs, merged with `config.ignore.files`), `extensions`, `incremental` (same cache as `cora scan --incremental`), `changed_since` (git rev — files changed since it, untracked included), and `order` (`source-first` default | `path` legacy walk order). - `source-first` ordering: code extensions first, then shallower paths, then path — deterministic. - Every prepare response carries planning data: `total_chars`, `estimated_tokens` (`total_chars/4`), per-batch `files` + `chars`, plus the effective `order`/`include`/`exclude`. - Finalize consistency: both tools go through one `scan_selection()` + `scan_files_for()`; `files_fingerprint` still guards — different filters/order refuse with "project files changed". `incremental` finalize depends on the cache not changing between calls. - `changed_since` implementation: `git diff --name-only --relative <rev>` + untracked files, filtered into the walked set; revs starting with `-` are rejected. ## Why Issue #686: agent mode on a real workspace was unusable — no way to narrow scope beyond `path`, path-ordered batches put core sources last, and no size/token estimate before committing to hundreds of thousands of tokens. ## Testing - TDD: 5 of 6 new tests RED on the old code, all GREEN after (26/26 agent_tools tests). - Full suite: `cargo test --features tree-sitter` = 1312 passed, 0 failed (independently re-verified by CTO: 10/10 suites ok). - Gates: fmt clean; clippy `--all-targets --features tree-sitter -D warnings` clean (CTO re-ran); pre-commit hook (fmt+clippy+cora code review) passed at commit. - Done-when check from the issue: `scan_prepare {"include": ["crates/**/*.rs"], "exclude": ["**/tests/**"]}` returns only matching files, reports estimated totals, orders sources first — covered by `include_exclude_filter_and_planning_data_is_reported` against a fixture. Fixes #686 Co-authored-by: ajianaz <ajianaz@users.noreply.github.com>
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.
What
Implements #686 for the MCP agent-as-reviewer scan tools:
cora.scan_prepare+cora.scan_finalizenow accept the CLI's selection inputs:include(globs),exclude(globs, merged withconfig.ignore.files),extensions,incremental(same cache ascora scan --incremental),changed_since(git rev — files changed since it, untracked included), andorder(source-firstdefault |pathlegacy walk order).source-firstordering: code extensions first, then shallower paths, then path — deterministic.total_chars,estimated_tokens(total_chars/4), per-batchfiles+chars, plus the effectiveorder/include/exclude.scan_selection()+scan_files_for();files_fingerprintstill guards — different filters/order refuse with "project files changed".incrementalfinalize depends on the cache not changing between calls.changed_sinceimplementation:git diff --name-only --relative <rev>+ untracked files, filtered into the walked set; revs starting with-are rejected.Why
Issue #686: agent mode on a real workspace was unusable — no way to narrow scope beyond
path, path-ordered batches put core sources last, and no size/token estimate before committing to hundreds of thousands of tokens.Testing
cargo test --features tree-sitter= 1312 passed, 0 failed (independently re-verified by CTO: 10/10 suites ok).--all-targets --features tree-sitter -D warningsclean (CTO re-ran); pre-commit hook (fmt+clippy+cora code review) passed at commit.scan_prepare {"include": ["crates/**/*.rs"], "exclude": ["**/tests/**"]}returns only matching files, reports estimated totals, orders sources first — covered byinclude_exclude_filter_and_planning_data_is_reportedagainst a fixture.Fixes #686