Skip to content

feat(mcp): scan_prepare selection inputs, source-first ordering, planning data (#686) - #709

Merged
ajianaz merged 1 commit into
developfrom
feat/mcp-scan-prepare-filters
Oct 27, 2026
Merged

ajianaz merged 1 commit into
developfrom
feat/mcp-scan-prepare-filters

Conversation

@ajianaz

@ajianaz ajianaz commented Oct 27, 2026

Copy link
Copy Markdown
Collaborator

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

…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
ajianaz merged commit c49b27a into develop Oct 27, 2026
13 checks passed
@ajianaz
ajianaz deleted the feat/mcp-scan-prepare-filters branch October 27, 2026 16:26
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>
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.

feat(mcp): cora.scan_prepare needs include/exclude, smarter batch ordering and size hints (agent mode is impractical on large repos)

1 participant