Review Code
Run bounded review; route report/actions by mode.
Always
- Select exactly one mode: PR, local, or planned-feature pipeline.
- Keep PR/local review separate from Slice/result/audit obligations unless pipeline artifacts are in scope.
- Pipeline review checks one frozen integrated state for production integration correctness: cross-package seams,
shared/public contracts, caller/callee behavior, whole-feature coherence, integration-only changes, and triggered
security/privacy/data/concurrency/lifecycle risk. It trusts fresh package-local verification and is not a
whole-feature completeness gate or a second package-test review.
CLEAN means no open blocking finding remains for the reviewed state; it is not audit PASS or merge readiness.
- Main agent owns orchestration, state gates, reports, and action routing; semantic review/role work happen through dispatched sub-agents. No mutation until the active mode allows it.
- Revalidate reviewed-state metadata before posting, fixing, committing, evidence refresh, or audit-context handoff.
Mode Routing
- PR mode: PR URL,
owner/repo#N, or #N in repo context → load references/pr-workflow.md. PR mode is review-only for code changes.
- Local mode: no pipeline context and no PR identifier → load
references/local-workflow.md.
- Pipeline mode: feature context plus artifact root, SPEC (including
## Acceptance), registry, package
Markdown with Acceptance Checklists, package result reports, and integrated code worktree state → load
references/pipeline-report.md.
- Before reviewer dispatch, capture immutable refs/SHAs, worktree or PR identity, diff checksum or saved
diff, file list/status, artifact root, code root, and mode artifact context.
Review Engine and Big Diffs
- Build a compact manifest: core/runtime, public contracts, generated/schema/config, proof-critical tests, fixtures/snapshots, docs/tooling.
- Use semantic batching when the diff is about 2,000+ lines, many files, mixed domains, generated churn, or too broad for one coherent review.
- Split by package, module, seam, or risk surface (never arbitrary line chunks); keep source and tests that prove the same behavior together when practical.
- For low-risk generated/docs/snapshots/repetitive fixtures, verify provenance or sample with the owning surface.
- Per batch preserve mode metadata, run bounded topology, assign stable dedupe keys, and merge verdicts into one cross-batch set; after batches, run one global integration pass (duplicates, conflicting recommendations, cross-batch serious risks, seam issues), reopening fanout only when batch boundaries cannot preserve confidence.
- Run one default Code Reviewer sub-agent per diff/batch; add at most one specialist only when the diff/evidence triggers a sensitive surface: security/privacy/safety;
data/persistence/change-safety; performance/concurrency; or public-contract/architecture/integration.
- Add Skeptic only for serious findings, risky-clean coverage, cross-batch serious conflicts, or required mode gates. Caps include Skeptic: normal 2, risky 3.
- Resolve reviewer model only when local policy matters (
../../references/model-preferences.md); pass ../../references/clean-code-rules.md without loading it in the orchestrator.
- For changed test-relevant surfaces, confirm the change is covered by a check that actually ran; do not impose
receipt-grammar ceremony. In pipeline mode, do not routinely inspect the full test diff, line-review already
verified package-local tests/fixtures/snapshots, or rerun package-local checks. Follow the bounded widening gate
in
references/pipeline-report.md and inspect only the minimum evidence needed.
- In pipeline mode, add Slice-first artifact-root context (package IDs, result report paths, Slice/H3 IDs,
Acceptance Checklist results, integrated code state) and stay production-integration-first. Route
product/design Slice drift as advisory unless it is a real integration contradiction.
Coverage Gate
Every discovery reviewer output begins with internal coverage rows; do not render them to the user:
DISCOVERY_COVERAGE:
| Lens | Required depth | Result | Evidence | Source |
|---|---|---|---|---|
| <lens> | deep/sniff/not_applicable | deep/sniff/not_applicable | <files/symbols/artifacts/commands or precise N/A reason> | required/reviewer-added |
Required lenses come from mode, diff surface, risk notes, changed files, security/privacy/safety sniff, and discovered risks. Pipeline lenses include seams,
Slice/result contradictions, result-critical tests, public contracts, data integrity, performance/concurrency,
package regressions, report freshness, and audit
boundary.
Before clean: every required lens has concrete evidence; no vague rows (looks good, covered, bare N/A). Give weak rows one focused follow-up. Use
Skeptic/stronger review only for high-risk unresolved coverage.
Findings, Skeptic, and Suggestions
Severity (two tiers — the bar):
- 🔴 BLOCKING — must resolve before merge/commit/audit handoff: correctness, security, privacy, safety,
data loss, integrity, or a broken stated contract. Only these trigger a fix loop.
- 🟡 ADVISORY — everything else: maintainability opinions, brittleness, style, taste, non-blocking
regressions with no evidence of a real defect. Report-only; never blocks, never starts a fix loop.
A finding is blocking only when it makes the software wrong, unsafe, lose data, or break a stated contract.
Do not manufacture blockers from taste or speculative completeness.
Over-engineering lens: flag complexity not traced to an accepted requirement or the ## Acceptance criteria
— speculative abstraction, unused extensibility, needless layers/config/flags, or premature optimization. Report
it as 🟡 ADVISORY by default; escalate to 🔴 BLOCKING only when the excess creates a real
correctness/security/data/contract risk. Do not demand rewrites of working, right-sized code, and do not treat
simplicity itself as a defect — under-engineering (missing validation, error handling, or tests) is a separate
finding.
Internal fields: severity, tags, location, title, evidence, artifact refs, introduced-by-change, planned signal, recommendation, dedupe key, Skeptic verdict,
suggestion actionability, fix status.
Serious candidates require Skeptic verification before reporting or fixing. Skeptic tries to disprove against introduced-change, surrounding code/callers,
framework absorption, reachability, documented intent, test-only scope, reviewed scope, and planned artifacts. Output verdict, decisive check(s), evidence,
reason. Verbose rows are optional.
Documented intent disputes only non-security/privacy/safety findings; real security/privacy/safety risks stay confirmed. Test-only scope disputes serious
findings unless it masks production regression. Planned-requirement claims require artifact evidence; review-code is not final audit.
Only CONFIRMED 🔴 blocking findings are reportable as blocking or fixable. DISPUTED findings are excluded. DOWNGRADED findings may appear only as 🟡 advisory
suggestions.
Suggestions are report-only and never start a separate fix loop. Auto-fix at most 1–3 per batch only when bundled with an approved 🔴 fix, same
file/symbol/root cause, behavior-preserving, no public/API/schema/config/permission/persistence/error/test/user-visible change, no extra surface, and optional
to closing the serious finding.
Promote a user-decision card only when a confirmed serious finding has multiple valid fixes with materially different runtime behavior, blast radius, or public
surface, and choice needs product/architecture authority. Otherwise delegate unambiguous fixes when mode permits. Use ../../references/decision-prompts.md.
Report Template
Render one Markdown body, not inline diff comments: header, optional verdict, finding counts, file/line counts, metadata, then 🔴/🟡 sections. Each finding
needs title, Path, evidence, and recommendation/tradeoffs. Omit empty sections; if all empty, render No issues found. ✅.
Footer states bounded review and Skeptic verification for serious findings, plus mode footer. Never
render coverage rows, raw tags, dedupe keys, state/lifecycle fields, or tracking IDs. Pipeline
findings are consistency/evidence signals.
Fix Verification Gate
Every review-owned local/pipeline repair passes references/fix-implementer-contract.md to a fresh Fix
Implementer; PR mode has no fix path. For caller-owned local repair, review-code returns only an untrusted repair
proposal—and, in explicit mode, its accepted-fix receipt—to the owner; the owner validates it and constructs
bound-contract authoritative control. Review-code/Main never builds a caller packet or edits caller-owned repair.
Only for review-owned repair may Main apply a trivial behavior-preserving mechanical edit, with rationale.
After a delegated fix cluster, run focused Fix Verification as a fresh closure gate, not second discovery.
Cluster only shared root cause, writable scope, and verification envelope; preserve logical cluster identity and
the three-attempt cap. Review-owned cross-package repair is allowed only when every affected package, path, and
finding is explicitly enumerated under one coherent seam authority/verification envelope; otherwise split or stop.
Refresh only affected package evidence and focused seams, plus feature Acceptance. Return per finding:
verdict: closed|not_closed|reopened, evidence, and next_action: none|same_scope_fix|authority_boundary.
Unaffected results remain reusable. CLEAN may be restored for the new freeze, but cannot substitute for the
fresh cold auditor's complete same-freeze PASS. Keep Fix Implementer, Fix Verification, and auditor separate.
Stop if
- Mode ambiguity changes side-effect authority.
- PR/local review is asked to satisfy planned-feature audit gates, or pipeline review is asked to own
whole-feature completeness; switch/stop at the owning gate.
- Reviewed state is stale, broadened, ambiguous, or not bound to the requested action.
- A blocking finding lacks Skeptic verdict or required lens coverage is weak.
- A fix requires product/design choice, scope expansion, new dependency/service, unsafe command, credentials, external facts, destructive action, or risk
acceptance.
- A blocking seam finding will not converge within 3 attempts.
Output
Return the mode report, verdict, allowed next actions, and blocked readiness reason. In pipeline mode, state whether review-code is audit-ready; never state
final audit PASS or merge readiness.
1---2name: review-code3description: Reviews code changes with bounded multi-agent analysis. Use for PRs, local diffs, or planned-feature final integrated review. Do not use for final planned-feature audit or PR/local repairs unless the selected mode explicitly permits fixes.4---56# Review Code78Run bounded review; route report/actions by mode.910## Always1112- Select exactly one mode: PR, local, or planned-feature pipeline.13- Keep PR/local review separate from Slice/result/audit obligations unless pipeline artifacts are in scope.14- Pipeline review checks one frozen integrated state for production integration correctness: cross-package seams,15 shared/public contracts, caller/callee behavior, whole-feature coherence, integration-only changes, and triggered16 security/privacy/data/concurrency/lifecycle risk. It trusts fresh package-local verification and is not a17 whole-feature completeness gate or a second package-test review.18- `CLEAN` means no open blocking finding remains for the reviewed state; it is not audit PASS or merge readiness.19- Main agent owns orchestration, state gates, reports, and action routing; semantic review/role work happen through dispatched sub-agents. No mutation until the active mode allows it.20- Revalidate reviewed-state metadata before posting, fixing, committing, evidence refresh, or audit-context handoff.2122## Mode Routing23241. PR mode: PR URL, `owner/repo#N`, or `#N` in repo context → load `references/pr-workflow.md`. PR mode is review-only for code changes.252. Local mode: no pipeline context and no PR identifier → load `references/local-workflow.md`.263. Pipeline mode: feature context plus artifact root, SPEC (including `## Acceptance`), registry, package27 Markdown with Acceptance Checklists, package result reports, and integrated code worktree state → load28 `references/pipeline-report.md`.294. Before reviewer dispatch, capture immutable refs/SHAs, worktree or PR identity, diff checksum or saved30 diff, file list/status, artifact root, code root, and mode artifact context.3132## Review Engine and Big Diffs3334- Build a compact manifest: core/runtime, public contracts, generated/schema/config, proof-critical tests, fixtures/snapshots, docs/tooling.35- Use semantic batching when the diff is about 2,000+ lines, many files, mixed domains, generated churn, or too broad for one coherent review.36- Split by package, module, seam, or risk surface (never arbitrary line chunks); keep source and tests that prove the same behavior together when practical.37- For low-risk generated/docs/snapshots/repetitive fixtures, verify provenance or sample with the owning surface.38- Per batch preserve mode metadata, run bounded topology, assign stable dedupe keys, and merge verdicts into one cross-batch set; after batches, run one global integration pass (duplicates, conflicting recommendations, cross-batch serious risks, seam issues), reopening fanout only when batch boundaries cannot preserve confidence.39- Run one default Code Reviewer sub-agent per diff/batch; add at most one specialist only when the diff/evidence triggers a sensitive surface: security/privacy/safety;40 data/persistence/change-safety; performance/concurrency; or public-contract/architecture/integration.41- Add Skeptic only for serious findings, risky-clean coverage, cross-batch serious conflicts, or required mode gates. Caps include Skeptic: normal 2, risky 3.42- Resolve reviewer model only when local policy matters (`../../references/model-preferences.md`); pass `../../references/clean-code-rules.md` without loading it in the orchestrator.43- For changed test-relevant surfaces, confirm the change is covered by a check that actually ran; do not impose44 receipt-grammar ceremony. In pipeline mode, do not routinely inspect the full test diff, line-review already45 verified package-local tests/fixtures/snapshots, or rerun package-local checks. Follow the bounded widening gate46 in `references/pipeline-report.md` and inspect only the minimum evidence needed.47- In pipeline mode, add Slice-first artifact-root context (package IDs, result report paths, Slice/H3 IDs,48 Acceptance Checklist results, integrated code state) and stay production-integration-first. Route49 product/design Slice drift as advisory unless it is a real integration contradiction.5051## Coverage Gate5253Every discovery reviewer output begins with internal coverage rows; do not render them to the user:5455```markdown56DISCOVERY_COVERAGE:57| Lens | Required depth | Result | Evidence | Source |58|---|---|---|---|---|59| <lens> | deep/sniff/not_applicable | deep/sniff/not_applicable | <files/symbols/artifacts/commands or precise N/A reason> | required/reviewer-added |60```6162Required lenses come from mode, diff surface, risk notes, changed files, security/privacy/safety sniff, and discovered risks. Pipeline lenses include seams,63Slice/result contradictions, result-critical tests, public contracts, data integrity, performance/concurrency,64package regressions, report freshness, and audit65boundary.6667Before clean: every required lens has concrete evidence; no vague rows (`looks good`, `covered`, bare `N/A`). Give weak rows one focused follow-up. Use68Skeptic/stronger review only for high-risk unresolved coverage.6970## Findings, Skeptic, and Suggestions7172Severity (two tiers — the bar):7374- 🔴 **BLOCKING** — must resolve before merge/commit/audit handoff: correctness, security, privacy, safety,75 data loss, integrity, or a broken stated contract. Only these trigger a fix loop.76- 🟡 **ADVISORY** — everything else: maintainability opinions, brittleness, style, taste, non-blocking77 regressions with no evidence of a real defect. Report-only; never blocks, never starts a fix loop.7879A finding is blocking only when it makes the software wrong, unsafe, lose data, or break a stated contract.80Do not manufacture blockers from taste or speculative completeness.8182**Over-engineering lens:** flag complexity not traced to an accepted requirement or the `## Acceptance` criteria83— speculative abstraction, unused extensibility, needless layers/config/flags, or premature optimization. Report84it as 🟡 **ADVISORY** by default; escalate to 🔴 **BLOCKING** only when the excess creates a real85correctness/security/data/contract risk. Do not demand rewrites of working, right-sized code, and do not treat86simplicity itself as a defect — under-engineering (missing validation, error handling, or tests) is a separate87finding.8889Internal fields: severity, tags, location, title, evidence, artifact refs, introduced-by-change, planned signal, recommendation, dedupe key, Skeptic verdict,90suggestion actionability, fix status.9192Serious candidates require Skeptic verification before reporting or fixing. Skeptic tries to disprove against introduced-change, surrounding code/callers,93framework absorption, reachability, documented intent, test-only scope, reviewed scope, and planned artifacts. Output verdict, decisive check(s), evidence,94reason. Verbose rows are optional.9596Documented intent disputes only non-security/privacy/safety findings; real security/privacy/safety risks stay confirmed. Test-only scope disputes serious97findings unless it masks production regression. Planned-requirement claims require artifact evidence; review-code is not final audit.9899Only `CONFIRMED` 🔴 blocking findings are reportable as blocking or fixable. `DISPUTED` findings are excluded. `DOWNGRADED` findings may appear only as 🟡 advisory100suggestions.101102Suggestions are report-only and never start a separate fix loop. Auto-fix at most 1–3 per batch only when bundled with an approved 🔴 fix, same103file/symbol/root cause, behavior-preserving, no public/API/schema/config/permission/persistence/error/test/user-visible change, no extra surface, and optional104to closing the serious finding.105106Promote a user-decision card only when a confirmed serious finding has multiple valid fixes with materially different runtime behavior, blast radius, or public107surface, and choice needs product/architecture authority. Otherwise delegate unambiguous fixes when mode permits. Use `../../references/decision-prompts.md`.108109## Report Template110111Render one Markdown body, not inline diff comments: header, optional verdict, finding counts, file/line counts, metadata, then 🔴/🟡 sections. Each finding112needs title, `Path`, evidence, and recommendation/tradeoffs. Omit empty sections; if all empty, render `No issues found. ✅`.113114Footer states bounded review and Skeptic verification for serious findings, plus mode footer. Never115render coverage rows, raw tags, dedupe keys, state/lifecycle fields, or tracking IDs. Pipeline116findings are consistency/evidence signals.117118## Fix Verification Gate119120Every review-owned local/pipeline repair passes `references/fix-implementer-contract.md` to a fresh Fix121Implementer; PR mode has no fix path. For caller-owned local repair, review-code returns only an untrusted repair122proposal—and, in explicit mode, its accepted-fix receipt—to the owner; the owner validates it and constructs123bound-contract authoritative control. Review-code/Main never builds a caller packet or edits caller-owned repair.124Only for review-owned repair may Main apply a trivial behavior-preserving mechanical edit, with rationale.125126After a delegated fix cluster, run focused Fix Verification as a fresh closure gate, not second discovery.127Cluster only shared root cause, writable scope, and verification envelope; preserve logical cluster identity and128the three-attempt cap. Review-owned cross-package repair is allowed only when every affected package, path, and129finding is explicitly enumerated under one coherent seam authority/verification envelope; otherwise split or stop.130131Refresh **only affected package evidence and focused seams**, plus feature Acceptance. Return per finding:132`verdict: closed|not_closed|reopened`, evidence, and `next_action: none|same_scope_fix|authority_boundary`.133Unaffected results remain reusable. `CLEAN` may be restored for the new freeze, but cannot substitute for the134fresh cold auditor's complete same-freeze PASS. Keep Fix Implementer, Fix Verification, and auditor separate.135136## Stop if137138- Mode ambiguity changes side-effect authority.139- PR/local review is asked to satisfy planned-feature audit gates, or pipeline review is asked to own140 whole-feature completeness; switch/stop at the owning gate.141- Reviewed state is stale, broadened, ambiguous, or not bound to the requested action.142- A blocking finding lacks Skeptic verdict or required lens coverage is weak.143- A fix requires product/design choice, scope expansion, new dependency/service, unsafe command, credentials, external facts, destructive action, or risk144 acceptance.145- A blocking seam finding will not converge within 3 attempts.146147## Output148Return the mode report, verdict, allowed next actions, and blocked readiness reason. In pipeline mode, state whether review-code is audit-ready; never state149final audit PASS or merge readiness.