Skip to content

feat: add compact file-level impact context - #1144

Merged
2 commits merged into
tirth8205:stagingfrom
witheez:feat/compact-file-impact
Nov 9, 2026
Merged

2 commits merged into
tirth8205:stagingfrom
witheez:feat/compact-file-impact

Conversation

@witheez

@witheez witheez commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Linked issue

No separate issue: this is a focused, opt-in response-format improvement found while evaluating impact queries on a large TypeScript repository.

What & why

An agent asking which files to inspect currently chooses between a standard impact response containing full node/edge records and a minimal summary without affected file paths. The CLI also cannot select the existing minimal mode.

Add detail_level="compact" to the impact tool and impact --detail-level compact --max-files 25 to the CLI. The compact response contains repository-relative paths in the graph's best-first order, counts, omission/truncation markers, and the existing uncertainty/unresolved-call-site information. It skips serialization of full graph records. The new file display limit is independent of max_results, so asking to see fewer files does not shrink the graph traversal. The existing standard and minimal responses remain unchanged.

On four local impact queries, compact responses used 375–426 tokens versus 27,833–33,901 in standard mode (cl100k_base, compact native JSON serialization). These are 25-file previews, not lossless replacements for full graph responses: all expected direct production importers appeared on three tasks; the high-fanout task returned 23 of 69 in the preview, versus 31 of 69 in the bounded standard response. Both formats expose omitted context. These application-specific measurements are observational; the included synthetic tests independently verify that the complete affected file set is preserved when it fits the display limit and that the serialized response is less than one quarter of standard size.

How it was tested

uv run pytest tests/test_compact_impact.py -q --tb=short
# 14 passed
uv run pytest tests/test_compact_impact.py tests/test_cli_tool_commands.py tests/test_tools.py -q --tb=short
# 191 passed, 1 skipped
uv run pytest tests/ -q --tb=short
# 5054 passed, 884 skipped, 3 xfailed, 2 xpassed; one pre-existing failure (below)
uv run ruff check code_review_graph/ tests/test_compact_impact.py tests/test_cli_tool_commands.py
# passed
uv run mypy code_review_graph/ --ignore-missing-imports --no-strict-optional
# passed

The full-suite failure is test_worst_case_args_stay_in_budget[get_affected_flows_tool]: the fallback counter measures 40,129 against a 40,000 ceiling on this macOS temporary-directory layout. It also fails in a separate, unchanged checkout of base commit d72e8fb. This PR does not change that tool or its budget. With optional tiktoken installed, the token-budget module has five failures; the same five reproduce on the unchanged base (cross-repo search, callers-of default/worst, affected flows, review context). No budget thresholds were relaxed.

The new tests cover the real graph-store path through Python, MCP, and CLI, file/graph limit independence, hard display bounds, best-first ordering, skipped graph-record serialization, empty changes, an unindexed file's uncertainty marker, and unchanged standard output.

Checklist

  • Tests added for new functionality
  • All tests pass (one independently reproduced baseline failure; see above)
  • Linting passes
  • Type checking passes
  • Lines are at most 100 characters
  • Docs updated where behavior changed

Copilot AI 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.

🟡 Changes recommended

Path handling omits unindexed changes and misrepresents cwd-relative graph paths, while Windows separator mismatches disconnect test edges and cause the new assertions to fail.

3 open issues
What changed in this PR

Adds an opt-in compact impact response so agents can identify affected files without receiving full graph records.

Changes:

  • Adds ranked file paths, counts, and truncation markers with a display limit independent of traversal.
  • Exposes compact mode through MCP and CLI, plus minimal mode through CLI.
  • Documents the response format and adds regression coverage.
File Description
tests/​test_compact_impact.py Tests compact responses, limits, ordering, and API integration.
tests/​test_cli_tool_commands.py Updates expected impact CLI arguments.
docs/​COMMANDS.md Documents compact output and CLI controls.
code_review_graph/​tools/​query.py Builds compact file-level impact responses.
code_review_graph/​main.py Exposes compact options through MCP.
code_review_graph/​cli.py Adds detail-level and file-limit flags.

Review effort: Balanced

Comment thread code_review_graph/tools/query.py Outdated
Comment on lines +211 to +214
return Path(path).relative_to(root).as_posix()
except ValueError:
# A graph may include an external file: retain its identity.
return path

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 341f543, with a regression test where applicable.

Comment thread code_review_graph/tools/query.py Outdated

if detail_level == "compact":
compact_response = _compact_impact_response(
result, root, abs_files, max_files, resolution,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 341f543, with a regression test where applicable.

Comment thread tests/test_compact_impact.py Outdated
Comment on lines +43 to +44
kind="CALLS", source=f"{path}::{name}",
target=f"{paths[0]}::execute", file_path=str(path), line=1,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 341f543, with a regression test where applicable.

- Display requested changed files, not only the ones found in the graph
- Map cwd-relative graph paths onto the repository root
- Use POSIX qualified names in the fixture's CALLS edges (Windows)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@tirth8205 tirth8205 closed this pull request by merging all changes into tirth8205:staging in d01c1fd Nov 9, 2026
HengYangDS pushed a commit to HengYangDS/code-review-graph that referenced this pull request Nov 9, 2026
…irth8205#1144)

A changed file deleted by the change, or a graph row whose file has gone
since the build, lost a leading directory that shared the checkout's name:
django/x.py in a checkout called django came back as x.py. The cwd-relative
fix now applies only to paths the graph stored relative; the caller's own
paths are shown as given.

The compact changed_files list echoed every requested file, so a whole-repo
diff made the compact answer as long as the repository. It now gets the
max_files limit with changed_file_count and changed_files_omitted, and the
response carries the unmatched_files marker standard and minimal already
have. Adds a compact entry to the token budget table and a CHANGELOG entry.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@witheez
witheez deleted the feat/compact-file-impact branch November 13, 2026 07:01
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.

3 participants