Skip to content

feat(review): ground /review findings in the code and verify each one - #2298

Merged
akramcodez merged 7 commits into
Nano-Collective:feat/1287-grounded-reviewfrom
puri-adityakumar:review-1287/2-grounded
Nov 25, 2026
Merged

akramcodez merged 7 commits into
Nano-Collective:feat/1287-grounded-reviewfrom
puri-adityakumar:review-1287/2-grounded

Conversation

@puri-adityakumar

Copy link
Copy Markdown
Contributor

Description

Part 2 of 4 for #1287. Targets feat/1287-grounded-review and builds on part 1 (#2297), so please merge that first. Until #2297 is merged, this diff also shows its 2 commits; the new work here is the last 2 commits.

Problem. /review sends the diff to the model in one shot. The model can report issues that are not in the code, cite lines that do not exist, or say "looks good" after reading only part of the change, and nothing checks any of it.

What this PR does. /review now runs a grounded review over the pinned revision from part 1:

  1. A finder agent reads the change with read-only review tools (changed files, file reads, search, diff, log) under a fixed budget (14 turns, 24 tool calls).
  2. Every issue must cite file:line inside the changed code. Issues without a valid citation are dropped and listed as dropped.
  3. A separate verifier re-checks each issue against the code (up to 8 per review). Only issues it confirms with confidence 80 or higher are reported.
  4. The report says "incomplete" instead of "completed" whenever coverage was limited: a budget was hit, the model output was cut off, a large file was not fully read, or an issue was left unverified.

Other changes:

  • A live panel shows agents, tool calls and model calls while the review runs (d for details, Esc to cancel).
  • /review activity shows the trace of the last review, and the report is saved with the session so it comes back on resume.
  • /review quick keeps the old one-shot review.
  • The activity line now shows "incomplete" (in the warning color) when a finished review is incomplete. Before, it said "completed" even when the report below said "incomplete".
  • Docs: docs/features/review.md, docs/features/commands.md, docs/getting-started/index.md.
  • Changeset: .changeset/grounded-default-review.md.
  • Removes the knip.json ignores from part 1, since the files are now used.

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update

Changeset

  • Added a changeset (pnpm changeset) describing this change for the changelog

Testing

Automated Tests

  • New features include passing tests in .spec.ts/tsx files
  • All existing tests pass (pnpm test:all completes successfully)
  • Tests cover both success and error scenarios

Run on macOS, Node 22:

  • test:format, test:lint, test:types, test:knip, build: pass.
  • test:ava: 11,414 pass, 38 fail. The same 38 fail on plain feat/1287-grounded-review in the same setup, so none come from this PR (34 in cli-value-flags.cli-integration with a React duplicate-key error, 2 --acp trust checks that need a trusted checkout, 2 auto-commit tests).
  • The new activity-line test fails without the fix and passes with it.

Manual Testing

  • Tested with Ollama
  • Tested with OpenRouter
  • Tested with OpenAI-compatible API
  • Tested MCP integration (if applicable)

GMI Cloud (zai-org/GLM-5.3-Flash) on a fixture repo whose feature/users branch has four seeded bugs in src/users.js. /review completed with 5 agents, 17 tool calls and 12 model calls, and found and verified all four bugs.

Live panel:

Grounded review live panel

Report:

Grounded review report, top

Grounded review report, bottom

/review activity (from a second run, which completed with 4 agents and 3 verified issues):

/review activity

/review quick still runs the one-shot review:

/review quick

Checklist

  • If this was for an open issue, I was assigned to it
  • Code follows project style guidelines
  • Self-review completed
  • Documentation updated (if needed)
  • No breaking changes (or clearly documented)
  • Appropriate logging added using structured logging (see CONTRIBUTING.md)

Not a breaking change in the API sense, but plain /review now does more work (several model calls instead of one). /review quick keeps the old behavior. Logging: review steps go to the review activity store, which the live panel and /review activity read.

Part of #1287.

@will-lamerton will-lamerton left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks @puri-adityakumar, this is a strong piece of work. I went through it closely:

  • Read-only holds. Agents get a fixed five-tool allowlist (review-context.ts) that never touches the tool manager, MCP, shell or network, and unknown tool names error out (review-agent.ts:334).
  • Reads are pinned. Everything comes from git objects at the pinned headOid via spawn with fixed argv. normalizeCitationPath rejects .., absolute paths, ~, drive letters and NUL.
  • Citations are enforced against the zero-context hunk map, including deletion anchors.
  • It's bounded: at most 71 model calls and 88 tool calls, with the abort signal checked before every one.
  • /review quick is still there and documented.
  • Tests: on a trial merge with current main it typechecks and 392 specs pass, including layering.spec. The only conflict is two adjacent tests in session-history-renderer.spec.tsx; keep both.

Two changes before merge:

1. Run the finder and verifier on the shared turn engine. review-agent.ts:109-378 is a hand-rolled agent loop: text-mode tool-call parsing, malformed-call retries, and a forced final turn without tools. That's what source/agent-loop/turn-engine.ts (#2097) exists for. TUI, --plain, ACP and subagents (subagent-executor.ts) all run on it now, and the goal is no per-frontend copies, so fixes like the malformed-call caps or XML-parsing changes reach every loop at once. The review-specific parts fit the engine's adapter: the fixed tool allowlist and the 24-call budget in executeTools, and the turn ceiling via its options (#2125 added a turn ceiling for subagents). Please port the loop onto runTurnEngine and drop the bespoke retry and parsing logic.

2. Changeset level. .changeset/grounded-default-review.md is patch, but making grounded review the default for /review and nanocoder review changes user-facing behaviour, so it should be minor.

Should fix (fine as a follow-up):

  • Context window: tool results aren't counted against the model's context. Only the initial diff is scaled (run-grounded-review.ts:104). On a 32k-context model (common with Ollama), ~38k chars of diff plus up to 24 tool results of ~12k chars overflow around turn 7, and the whole review reports failed rather than incomplete. Budgeting tool output against the remaining context, or truncating older results, would fix it.
  • Docs: "cites a line inside the changed code" really means within ±3 lines of a changed line or deletion anchor; worth saying so.

Nit: ReviewFoundationTools.execGh is exposed to the review tools but unused.

@puri-adityakumar

Copy link
Copy Markdown
Contributor Author

Thanks @will-lamerton, appreciate the close review. You're right that keeping a second agent loop in review-agent.ts would drift from runTurnEngine, and that switching /review to grounded by default is a minor change.

I've pushed the updates in ba2e6e38 (and synced #2299 and #2300 on top):

  1. source/review/review-agent.ts now runs on runTurnEngine from source/agent-loop/turn-engine.ts, dropping the hand-rolled loop, XML parsing, and malformed-call retries. To keep review isolated without changing defaults for TUI, --plain, ACP, or subagents, I added five opt-in flags on TurnEnginePolicy (onlyOfferedTextToolCalls so quoted JSX in findings isn't parsed as a tool call, textToolHistory: 'text' for text-mode transcripts, autoCompact: false, capHistory: false, and finalTurnInstruction).
  2. Bumped .changeset/grounded-default-review.md to minor, and did the same for .changeset/deep-review.md in feat(review): add /review deep so one finder's blind spots don't go unreviewed #2299 and .changeset/headless-review.md in feat(review): let nanocoder review run in CI and pipes without a terminal #2300.
  3. Added context-window budgeting in review-agent.ts (and a char cap in clipDiff) so smaller-context models like 32k cap tool output against the remaining window, run the tool-free final report turn, and report incomplete instead of overflowing and failing.
  4. Updated the short summaries in docs/features/review.md, docs/features/commands.md, docs/getting-started/index.md, and the changeset so they note the ±3-line and deletion-boundary citation rule.
  5. Narrowed createReviewContextTools in source/review/review-context.ts to Pick<ReviewFoundationTools, 'execGit' | 'execGitBuffer'> so execGh is no longer exposed to review tools.

I also checked a trial merge with current main: turn-engine.ts merges cleanly, leaving only that session-history-renderer.spec.tsx adjacent-test conflict once feat/1287-grounded-review is synced with main. Ready for another look whenever you have a chance, and happy to rebase the stack once the base branch moves.

@akramcodez
akramcodez merged commit 7c63d3d into Nano-Collective:feat/1287-grounded-review Nov 25, 2026
akramcodez added a commit that referenced this pull request Nov 26, 2026
…CLI (#2417)

* feat(review): restore the review foundation that grounded /review builds on (#2297)

* feat(review): restore the review foundation

* fix(review): catch same-second worktree edits in review snapshots

* feat(review): ground /review findings in the code and verify each one (#2298)

* feat(review): restore the review foundation

* fix(review): catch same-second worktree edits in review snapshots

* feat(review): make grounded review the default /review

* fix(review): show incomplete reviews as incomplete in the activity line

* refactor(review): run review agents on the shared turn engine

* fix(review): keep offered text tool calls beside quoted markup and bound unknown context sizes

---------

Co-authored-by: akramcodez <[email protected]>

* feat(review): add /review deep so one finder's blind spots don't go unreviewed (#2299)

* feat(review): restore the review foundation

* fix(review): catch same-second worktree edits in review snapshots

* feat(review): make grounded review the default /review

* fix(review): show incomplete reviews as incomplete in the activity line

* feat(review): add /review deep with specialist finders

* refactor(review): run review agents on the shared turn engine

* fix(review): keep offered text tool calls beside quoted markup and bound unknown context sizes

* fix(review): share the diff size limit so deep review and the verifier bound unknown context sizes

---------

Co-authored-by: akramcodez <[email protected]>

* feat(review): let nanocoder review run in CI and pipes without a terminal (#2300)

* feat(review): restore the review foundation

* fix(review): catch same-second worktree edits in review snapshots

* feat(review): make grounded review the default /review

* fix(review): show incomplete reviews as incomplete in the activity line

* feat(review): add /review deep with specialist finders

* feat(review): run nanocoder review without a terminal

* refactor(review): run review agents on the shared turn engine

* fix(review): keep offered text tool calls beside quoted markup and bound unknown context sizes

* fix(review): share the diff size limit so deep review and the verifier bound unknown context sizes

* fix(review): keep the cancelled report and exit code when a headless review is interrupted

---------

Co-authored-by: akramcodez <[email protected]>

* fix(review): align review specs and docs with main after merge

* fix(review): strip ANSI in review specs so they pass with color forced on

* fix(review): stop headless quick review passing on empty or partial output

---------

Co-authored-by: Aditya Kumar Puri <[email protected]>
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