Repository navigation
feat: add sumo_qa_scan_repo MCP tool (#155 slice 3) - #230
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0f2599b24f
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
The tool writes the full repo-map artifact to an arbitrary path when write_to is set, so advertising readOnlyHint=True was misleading — a host that trusts that hint could auto-run it or skip write confirmation and silently overwrite a local file. Register with _writer_local (the same annotation the other file-writing tools use) and assert the writer shape in the registration test. Addresses the P2 Codex review finding on PR #230.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 27a98aa0e7
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
1110cf1 to
ac24533
Compare
Third implementation slice under #154's QA-native repo-understanding epic. Wraps the slice-2 deterministic scanner in a host-callable MCP tool so any host (Claude Code, IntelliJ AI Assistant, VS Code + Copilot) can map an arbitrary repo from the slash menu. Tool signature: sumo_qa_scan_repo( root: str, generator_version: str | None = None, write_to: str | None = None, ) -> RepoMapScanOutput | ErrorEnvelope Design choices: - Compact-by-default response: per-type node counts, per-type + per-confidence edge counts, command counts by kind, warning counts by kind. NO node/edge arrays — a real scan of this repo produces 242 nodes and 84KB JSON; the host budget can't carry that on every call. Callers who need the full artifact pass `write_to=<path>` and read it from disk. - `generator_version` defaults to the installed sumo-qa version via `importlib.metadata.version("sumo-qa")` so the artifact's freshness metadata accurately identifies the producer. - Read-only annotation, openWorldHint=False — the tool reads the local filesystem only, no network calls. - Failures (missing directory, file-as-root, scanner exceptions) come back through the standard `{"isError": True, "error": {...}}` envelope with an actionable hint. Wired in src/sumo_qa/server.py via `@mcp.tool`; output schema is the new `RepoMapScanOutput` in server_schemas.py (under the existing `_StrictBase`). REQUIRED_TOOL_NAMES in installer.py bumped from 16 to 17 — the doctor / verify handshake fails if a host install drops it. 10 new tests in tests/test_server_repo_map_tool.py cover registration, annotation shape, declarative description, compact summary, optional write_to + slice-1 load_repo_map round-trip, default vs explicit generator_version, and both error-envelope arms. Existing test_server / test_installer_verify / test_skill_tool_crossref updated for the new tool name. Full suite: 1123 passed, 100% coverage; mypy + ruff clean. Live demo on this repo produced 242 nodes / 21 high-confidence likely_tests edges / 9 commands / 12 warnings, 84425-byte artifact, all schema- validated. Refs #154.
The tool writes the full repo-map artifact to an arbitrary path when write_to is set, so advertising readOnlyHint=True was misleading — a host that trusts that hint could auto-run it or skip write confirmation and silently overwrite a local file. Register with _writer_local (the same annotation the other file-writing tools use) and assert the writer shape in the registration test. Addresses the P2 Codex review finding on PR #230.
27a98aa to
e6b98d8
Compare
A relative write_to (the conventional .sumo-qa/repo-map.json) was resolved against the MCP server's cwd, so when root != cwd the artifact landed in the wrong workspace and downstream repo-map consumers wouldn't find it. Resolve non-absolute write_to as Path(root) / write_to; absolute paths unchanged. Addresses the P2 Codex review finding on PR #230.
…#233) ## What First consumer of the repo-map: `sumo_qa_analyze_diff_impact`. Given a set of changed files it uses the persisted `.sumo-qa/repo-map.json` (live-scan fallback) to answer the QA-native question — **which tests exercise these changes, and which changed sources have no mapped coverage (the risk surface)?** This is the first cut of **issue #156** ("Add repo-map query and diff-impact analysis tools"), branched off slice 3 so the diff shows only the slice-4 delta. Scope is deliberately the **diff-impact tool only**; `sumo_qa_query_repo_map` and the skill-wiring (`reviewing-before-merge` / `preparing-for-work` / `strategising`) are follow-up slices. ## How Mirrors the slice-2 (pure service) + slice-3 (thin MCP wrapper) split: - **`src/sumo_qa/repo_map_impact.py`** (new) — pure `analyze_diff_impact(repo_map, changed_files) -> DiffImpact` (no I/O); plus `changed_files_from_git(root, base_ref)` which diffs the working tree against `merge-base(base_ref, HEAD)` using `git diff --name-only -z` (clean GIT_* env + toplevel cross-check, same hygiene as the scanner). - **`repo_map_models.py`** — `ImpactNode` + `DiffImpact` models. - **`server_schemas.py`** — compact `DiffImpactOutput` (bounded by the changeset, no full node/edge arrays). - **`server.py`** — the `sumo_qa_analyze_diff_impact` MCP tool: loads the artifact (ignores a foreign-root artifact, falls back to a live scan), resolves changed files from an explicit list or `base_ref`, detects staleness vs HEAD, and optionally writes a `.sumo-qa/diff-impact.json` overlay. Registered `_writer_local` from the start (carries forward the PR #230 read-only-hint lesson). ## Output (per changeset) `changed_nodes`, `affected_nodes` (one-hop), `related_tests`, `unmapped_files`, **`risk_surface`** (changed sources with no mapped test), `suggested_inspections`, plus `is_stale` / `used_live_scan` flags and warning counts. ## Tests / verification - New: `tests/test_repo_map_impact.py` (core + git helper), `tests/test_server_diff_impact_tool.py` (wrapper). Contract/registration tests + tools-list snapshot updated (31 → 32 tools; installer required-tool count 17 → 18). - Full suite: **1147 passed, 1 xfailed, 100% coverage**; ruff + ruff-format + mypy(py3.10) clean. - Live demo on this repo: changed sources mapped to their tests, risk surface empty (both covered). ## Review Codex reviewed the diff (two rounds): round 1 → diff against merge-base not base-tip, `-z` for non-ASCII paths, foreign-artifact guard; round 2 → suppress a redundant live-scan warning, tighten the foreign-artifact test, sync the docstring. All applied and re-verified green. The GitHub Codex bot will also review on open. Stacked on #230 (slice 3). Merge order: #222 → #229 → #230 → this. --------- Co-authored-by: t <t@t>
Stacked on #229 (slice 2) which is stacked on #222 (slice 1). When upstream PRs land on main, this PR's base auto-rebases.
Third implementation slice under #154's QA-native repo-understanding epic. Wraps the slice-2 deterministic scanner in a host-callable MCP tool so any host (Claude Code, IntelliJ AI Assistant, VS Code + Copilot) can map an arbitrary repo from the slash menu.
Refs #155.
Tool signature
Design choices
write_to=<path>and read it from disk.generator_versiondefaults to the installed sumo-qa version viaimportlib.metadata.version("sumo-qa")so freshness metadata accurately identifies the producer.openWorldHint=False— reads the local filesystem only, no network calls.{"isError": True, "error": {...}}envelope with an actionable hint.Live demo (against this actual repo)
Full artifact round-trips cleanly through slice 1's
load_repo_map.Evidence
uv run pytest -qsrc/sumo_qauv run mypy src/sumo_qa/server.py src/sumo_qa/server_schemas.pyuv run ruff check+ruff format --checkREQUIRED_TOOL_NAMESbumped 16 → 17tests/fixtures/mcp_tools_list_snapshot.jsonscripts/regen_tools_list_snapshot.pyWhat landed
src/sumo_qa/server_schemas.py— newRepoMapScanOutputmodel (under existing_StrictBase)src/sumo_qa/server.py—@mcp.toolregistration,_package_version()helper,_build_scan_summary()aggregator,_HINT_SCAN_REPOsrc/sumo_qa/installer.py—sumo_qa_scan_repoadded toREQUIRED_TOOL_NAMES; doctor/verify handshake fails if a host install drops ittests/test_server_repo_map_tool.py— 10 new tests (registration, annotation shape, declarative description, compact summary, optional write_to + slice-1 round-trip, default vs explicit generator_version, both error-envelope arms)tests/test_server.py,tests/test_installer_verify.py,tests/test_skill_tool_crossref.py— updated for the new tool nametests/fixtures/mcp_tools_list_snapshot.json— regeneratedNotes
repo-walkSKILL.md update referencingsumo_qa_scan_repois a small follow-up (the skill-tool-crossref test currently whitelists the tool as a standalone utility).