--- name: review description: 'Brutally rigorous, evidence-bound AI code review (RLM decomposition) for GitHub PRs, GitLab MRs, or local diffs. Every FILE and every changed FUNCTION/HUNK gets a macro (blast-radius / architecture / placement) and micro (line-level projection-simulation) pass. No finding ships without file:line of real cited code + a category-appropriate counterexample (repro / source->sink / interleaving / benchmark). Severity and confidence are DECOUPLED: a high-severity low-confidence finding is NEVER dropped, only routed to a gating "Needs Verification" tier. Deterministic tiers (linters/SAST/SCA/ secrets/IaC + build+test) run for real with captured exit codes; the tier table is generated from captured output, not narrated. An EXTERNAL, non-LLM manifest verifier recomputes hunks+symbols from git and INVALIDATES the run on mismatch — this is what makes fake-pass mechanically detectable. Tool-absent is distinct from N/A. Cyclic: /review --loop converges on correctness, not tone. Use when to review a GitHub PR, a GitLab MR, or a local diff with evidence-bound findings — every finding cites real code at file:line plus a counterexample, and the deterministic scanners actually run.' metadata: short-description: 'Brutally rigorous, evidence-bound AI code review (RLM decomposition) for GitHub ' generated-from: plugins/*/skills/review argument-hint: '[||] [--loop] [--plan ]' --- > Paths below are rooted at `${CODEX_HOME:-$HOME/.codex}/plugins/cache/kodflow/kodflow-review/0.0.0-rba4d9f0187f5`, where Codex installs this plugin. If that directory is missing, the plugin root is the directory two levels above this SKILL.md. # /review — Brutal, Evidence-Bound Code Review (RLM Architecture) the arguments --- ## Core Doctrine (read before anything else) 1. **Evidence or it didn't happen.** Every finding carries `file:line(s)` of real cited code AND a category-appropriate counterexample. No concrete location -> auto-rejected by the Judge before output. 2. **Pure intelligence over pattern-matching.** You do not just grep for smells. You *projection-simulate* code paths with boundary inputs, *compare* the diff against its stated intent, and where a perf/correctness claim is made you *attempt* a runnable POC / A-B benchmark. Where isolation is infeasible, you **demote to Needs-Verification with the simulation trace** — demotion is the default, proof is the bonus. 3. **Macro + micro on EVERY file and EVERY changed function/hunk.** No file is "too small to read." No function ships un-simulated. Non-function hunks (config/IaC/SQL/schema/ protobuf/Dockerfile/YAML) get `micro_per_hunk`. The verifier enforces this. 4. **Severity and confidence are DECOUPLED.** A real HIGH-severity bug with weak confidence is **never deleted** — it lands in the gating "Needs Verification" tier (see §Severity). 5. **Deterministic tiers run for real.** Tools execute; the report's tier table is **generated by parsing captured `.out` files**, never narrated by the model. A tool's status is one of `ran | absent | na | failed` (§Phase 3) — `absent != na`. 6. **The manifest is verified by a non-LLM script.** `review-verify-manifest.sh` recomputes hunks and changed symbols from `git diff` and FAILS the run on any mismatch. The model may not define the denominator of its own coverage metric. 7. **Anti-theater.** Editing a comment, posting "LGTM", or re-emitting a prior summary is NOT a review. The run is invalid without a verifier-passed coverage manifest. 8. **Honest limit of the verifier.** It proves *coverage* (diff enumerated, symbols inspected, tiers real), not *quality*: a structurally complete but lazy pass (fabricated `clean:` lines, an auto-asserted `canary: passed`) still satisfies the script. YOU judge finding quality. Read `VERIFIER: PASS` as "the review was actually performed", never as "the review is good." --- ## Portable delegation For defensive review of a local diff, use this package's generated workflow on [Claude](../../io.github.kodflow/projections/workflows/review-claude.md), [Codex](../../io.github.kodflow/projections/workflows/review-openai.md), or [Perplexity](../../io.github.kodflow/projections/workflows/review-perplexity.md) when the installation includes it. Check required capabilities before starting. The workflow orders specialist, consolidation, and verification work. The existing inspection scope, coverage manifest, deterministic tiers, and local report still apply. When there is no packaged workflow, the steps below remain the native entry point. --- ## Library facts Resolve a library's real API with the library-documentation tool + the library-documentation tool before asserting that a call is wrong. A finding that a method "does not exist" is worthless if it does — cite the doc you checked, or downgrade the finding to Needs Verification. ## Overview — Phase Map | Phase | Name | Action | |------|------|--------| | 0 | Context | `review-context.sh `: platform, branch, diff, PR/MR, CI | | 0.5 | Repo Profile | Cached conventions, architecture style, ownership (7d TTL) | | 0.6 | **File Classification** | Tag each changed file: code/config/iac/generated/vendored/binary/rename | | 0.7 | **Platform Probe** | Detect cross-platform scope (OS/arch/runtime matrix) — else skip portability | | 0.8 | **Canary Self-Test** | Seed a known defect in a scratch copy; assert the pipeline flags it | | 1 | Intent + Risk | Parse PR/MR + linked issue; risk tags; acceptance criteria | | 1.5 | Describe | Auto-generate PR/MR description only if missing (drafted for user) | | 2 | Feedback | Collect ALL comments/reviews (human vs bot) | | 2.5 | Questions | Draft answers to human questions (NO AI mention — delivered as DRAFTS only) | | 3 | **Deterministic Tiers** | Run linters/SAST/SCA/secrets/IaC + build + existing tests; capture exit codes | | 3.5 | **Call/Dependency Graph** | Per changed symbol: callers/dependents (bounded blast radius) | | 3.7 | **Change-Coupling** | git-log co-occurrence: flag missed sibling/test/doc/migration edits | | 4 | **Macro Pass** | Per-file architecture/layering/placement/intent + Mermaid + can_be_split | | 5 | **Micro Pass** | Per-function projection-simulation; per-hunk for non-function files | | 5.5 | **POC / A-B** | Attempt repro for bugs / benchmark for perf; else demote | | 5.7 | **Doc & CLAUDE.md Sync** | Compute touched-dirs+ancestors; list stale docs; emit CLAUDE.md re-sync into the plan (gated by verifier `doc-sync`) | | 6 | Specialist Dispatch | Cross-cutting executors + language specialist (via routing table) | | 7 | Generate-then-Filter | Over-generate -> dedup -> evidence-check -> confidence -> learnings | | 7.5 | **Judge / Verifier** | Re-ground every finding against cited code; demote/drop with logged reason | | 8 | **Coverage Manifest** | Emit machine file; **run external verifier** (gates APPROVE) | | 9 | Synthesis | Decoupled verdict (0–5 / INCONCLUSIVE), tiers, Needs-Verification, LOCAL report | | 9.5 | Fix Patches | Per actionable finding: /refine→/goal-ready patch, validated in worktree when buildable | | 10 | Cyclic | --loop: review -> /refine -> /goal -> re-review until correctness-clear AND verifier-green | **RLM:** Peek -> Decompose -> Parallelize -> Synthesize. --- ## Phase 0-2 — Setup (delegated) Binds `$REPO`, `$BASE`, `$HEAD`, `$CHANGED_FILES` and the routing profile **once**, and runs the canary self-test. Every later phase reads these variables, so this phase is not optional and not re-derivable downstream. A shallow clone or an unresolvable `$BASE` exits `INCONCLUSIVE` rather than guessing. Read `setup.md`. ## Phases 3, 3.5, 3.7 — Deterministic tiers + blast radius Linters, SAST, SCA, secrets, IaC, build and tests execute for real; their exit codes populate the tier table. Then the call graph (3.5) and change-coupling (3.7) bound what the diff can actually break. `tool-absent` ≠ `N/A`. Read `scanning.md`. ## Phases 4-5 — Macro and micro passes (mandatory) Every changed FILE gets a macro pass (blast radius, architecture, placement); every changed FUNCTION and every non-function hunk gets a micro pass (line-level projection-simulation). A finding without `file:line` of real cited code and a category-appropriate counterexample does not ship. Read `passes.md`. ## Phase 6 — Specialist + Executor Dispatch (the real producers) Findings come from TWO producer classes, both real agents on disk: **Cross-cutting executors (own the dimensions):** `developer-executor-correctness`, `developer-executor-security` (taint/OWASP/PII), `developer-executor-design`, `developer-executor-quality`, `developer-executor-shell`. **Language specialists (own idioms + portability):** resolve via the canonical routing layer rather than a hand-maintained table that drifts: ```bash bash "${CODEX_HOME:-$HOME/.codex}/plugins/cache/kodflow/kodflow-review/0.0.0-rba4d9f0187f5"/skills/_shared/scripts/route-agent.sh --skill /review --phase review \ --profile "$SCRATCH/repo-profile.json" # reads _shared/routing-table.jsonl # --phase review = the /review rules (language fanout + react, postgres, protobuf); --profile = the file # Phase 0.5 wrote (.languages). A missing --phase or an absent profile exits 2/20 every run. ``` The routing table (`_shared/routing-table.jsonl`, shipped with the plugin) provides guard+priority selection, `agent_template: developer-specialist-{language}` multi-language fan-out, and tool routes (e.g. `developer-specialist-react` when react detected, `data-specialist-postgres` for psql). Per-extension correctness for the common stacks (corrected names — verified on disk): | Ext | Specialist | |-----|-----------| | `.go` | `developer-specialist-go` (error wrapping `%w`, ctx propagation, goroutine leaks, defer-in-loop, nil interface) | | `.rs` | `developer-specialist-rust` (unwrap/expect in libs, needless clone, unsafe justification, blocking-in-async) | | `.py` | `developer-specialist-python` (mutable defaults, bare except, `==` vs `is`, Decimal for money, f-string injection) | | `.ts/.tsx/.js/.jsx` | `developer-specialist-nodejs` (+`developer-specialist-react` when react detected): `any`, `==` vs `===`, floating promises, non-null abuse, exhaustive switch | | `.c/.h` | `developer-specialist-c` (bounds, signed/unsigned, UAF/double-free, format string, uninit memory) | | `.cpp/.hpp/.cc/.cxx` | `developer-specialist-cpp` (RAII, rule-of-5, move/forwarding, span/iterator invalidation, packing/alignment) | | `.zig` | `developer-specialist-zig` (errdefer vs defer, allocator discipline, 0.15 std.Io interfaces, cast soundness) | | `.sql`, migrations | `data-specialist-postgres` (index choice, lock scope, migration reversibility) | | `.sh`, `Dockerfile`, CI YAML, `.tf`, `.yaml` | `developer-executor-shell` (unquoted expansion, missing `set -euo pipefail`, root containers) + `devops-specialist-*` for cloud/IaC | | `.yml` under `.github/workflows/` | `tooling-specialist-github-actions` (unpinned actions, token scope, injection via `${{ }}`) | | any other language | **no specialist installed** — review it directly and label the finding as unbacked | Dispatch in parallel. **Execution mode**: read `../_shared/team-mode.md`; branch on `detect_runtime_mode` (from `"${CODEX_HOME:-$HOME/.codex}/plugins/cache/kodflow/kodflow-review/0.0.0-rba4d9f0187f5"/skills/_shared/scripts/team-mode-primitives.sh`) -> `TEAMS_TMUX`/`TEAMS_INPROCESS` (Agent Teams) vs `SUBAGENTS` (Task tool). Both paths MUST be schema- and severity-equivalent. Each producer receives: the repo profile, the file's macro record, its changed functions/hunks, the blast-radius callers, the deterministic-tier hits for that file, the review scope (this diff alone, or the wider topic the caller named), the threat model the repository records (what is public, who may attack it) or "none recorded", the dimension each other producer owns (`dimensions.md`), so a point owned elsewhere is left to its owner, a **report-file path** in the session scratchpad (`REPORTS=$(mktemp -d "${TMPDIR:-/tmp}/review-reports.XXXXXX")`, one `$REPORTS/.md` each — never inside the worktree, where the file would land as `??` in the next `git status` and fold itself into the diff under review), and these two contracts: - **Report file.** Write `status: in-progress` into it BEFORE reading the reviewed material (the brief comes first), append each finding in the strict JSON schema (triage.md) as soon as it is established — not batched at the end — and end it with a `status: complete` line as the last action (a producer without `Edit` writes the whole file again each time). **A missing file, or one not ending in `status: complete`, makes that pass INCOMPLETE**: re-brief it narrower or cover that dimension inline. Never read it as a favorable verdict — a producer that found nothing and a producer that died mid-read return the same silence. - **Compact return.** At most ~1500 characters back to the main thread: one summary line, then one line per finding as `SEVERITY | file:line | expected fix`, nothing else — no reasoning, no restated diff, since the orchestrator re-reads every returned character on every later turn. The full findings stay in the report file. The summary line is exactly `### : C critical, H high, M medium, L low` — the producer's own agent name, then our four severities (§Severity) in that order and spelling, so Phase 7 can parse it. On overflow, keep the summary line plus the highest-severity finding lines first. Also brief each producer: do not spawn any agent yourself. Two-tier effort: a fast default pass; a **deep pass** (whole-repo exploration, ensemble over N=3 shuffled passes) only under `--deep` or for security-sensitive/cross-service/large diffs. Never promise per-subagent model selection that Task cannot guarantee. Stamp which tier and N ran in the report. --- ## Phase 7 — Generate-then-Filter Over-generate candidates from all producers (executors + language specialists + tiers), then a deterministic pipeline: ``` candidates -> dedup (key: {category}:{file}:{line}:{normalized_title}, keep-highest-severity) -> cross-tier merge (tool-confirmed -> +confidence, tag "multi-tier-confirmed") -> evidence-check (no file:line OR no counterexample -> mark for Judge) -> learnings filter (.claude/review-learnings.md, create-if-absent: categories rejected Nx -> auto-suppress, LOGGED) -> output ``` **Every drop/suppression is logged** in a transparent appendix (what + why + cited evidence). Silent discard is forbidden. ## Phase 7.5 — Judge / Verifier (separate stage; guards both directions) A dedicated verifier agent re-reads each surviving finding **against the cited code** and: - Records the `grep`/`ast-grep`/`Read`/linter command + output that grounds it. - **Demotes** (never deletes) any finding it cannot ground -> Needs-Verification, with an explicit "could not confirm because …" note. "An empty grep is not proof of a bug." - Drops ONLY hallucinations (cited line absent, or saying the opposite) — logged. - **False-negative guard:** cross-checks the Phase 0.8 canary result and the per-dimension `clean:` justifications; if any owner marked a dimension clean with no cited line, that dimension reverts to `unverified` and the verdict cannot be APPROVE. For high-stakes diffs run the ensemble: findings in >1 pass -> full confidence; single-pass -> Needs-Verification. --- ## Phase 8 — Coverage manifest + external verifier (mandatory) Write the coverage manifest, then hand it to the **non-LLM** verifier: ```bash bash "${CODEX_HOME:-$HOME/.codex}/plugins/cache/kodflow/kodflow-review/0.0.0-rba4d9f0187f5"/skills/_shared/scripts/review-verify-manifest.sh --repo "$REPO" \ --base "$BASE" --head "$HEAD" --manifest "$MANIFEST" ``` It recomputes hunks, symbols and `diff_hash` from git and validates each tier's `.out` file. Exit `0`=PASS · `1`=INVALID · `2`=not-approve-eligible · `3`=usage. **Branch on the exit code.** A non-zero exit is the verdict — never narrate it and proceed to APPROVE. Manifest schema, file-class enum, `micro_per_hunk`, the Judge protocol and the full invocation contract: read `manifest.md`. ## Phase 9.5 — Verified Fix Patches For each **actionable** finding, produce a `/refine`->`/goal`-ready patch and validate it in an isolated worktree (build + tests via the allow-listed `go/cargo/npm/pytest/make` commands) before presenting. When the project is not buildable in-container, the patch is marked "proposed (unverified)". A stable **patch-ID** per finding tracks resolution across `--loop` iterations — resolved items are auto-resolved and never re-reported. --- ## Phase 10 — Cyclic Loop (--loop) ``` /review --loop - Phases 0–8: full review + manifest + EXTERNAL verifier - Phase 9.5: emit verified fix patches -> .claude/plans/review-fixes-{ts}.md - /refine -> /goal applies fixes (incl. doc & CLAUDE.md re-sync) via specialists - re-review (patch-ID aware: skip resolved) ``` **Exit ONLY when ALL hold:** 1. No CRITICAL/HIGH Confirmed remaining, AND 2. No CRITICAL/HIGH in Needs-Verification (the gate), AND 3. External manifest verifier passes (0 uninspected, symbol set matched, canary `detected==true`, **doc-sync satisfied**), AND 4. `verdict != INCONCLUSIVE` (C11 — an absent CRITICAL-capable tier, a `--no-poc` run, or a TRIAGE micro-defer forces INCONCLUSIVE, which can NEVER satisfy loop exit), AND 5. All *applicable* deterministic tiers are green OR justified N/A; merely `absent` tiers are named and cap confidence but do not themselves block convergence (one gating a CRITICAL-capable dimension is already blocked by condition 4, via INCONCLUSIVE), AND 6. **Every touched-folder + ancestor CLAUDE.md is synced** and no project doc is left stale vs the diff (verifier `doc-sync` check passes). Cyclic details: **read `cyclic.md`**. --- ## Output, flags, and budget Report layout, the flag reference (`--loop`, `--plan`, `--comment`, scope selectors), and the budget controller for large diffs: read `output.md`. ## Module Breakdown Every module lives beside this file. Read one when you reach its phase. | Module | Covers | |--------|--------| | `setup.md` | Phases 0-2 — binds `$REPO/$BASE/$HEAD/$CHANGED_FILES`, routing profile, canary | | `dispatch.md` | Phases 0-1.5 — context, repo profile, intent/risk, auto-describe | | `scanning.md` | Phases 3, 3.5, 3.7 — deterministic tiers, call graph, change-coupling | | `deterministic.md` | Tier runner: per-language/IaC commands, `run()`, `_table.tsv`, tool-status model | | `graph.md` | Bounded blast radius (diff hunk headers + ast-grep when installed + rg; never `sg`) | | `passes.md` | Phases 4-5 — the macro (per file) and micro (per function/hunk) passes | | `dimensions.md` | The full taxonomy: macro+micro checks and the owner agent per dimension | | `triage.md` | Finding JSON schema, severity rubric, executor/specialist dispatch | | `contract.md` | Severity/confidence model (decoupled) + the anti-theater hard rules | | `manifest.md` | Manifest schema, file-class enum, `micro_per_hunk`, Judge protocol, verifier contract | | `tiers.md` | T2 CodeRabbit (auth-probe) integration | | `synthesis.md` | Verdict incl. INCONCLUSIVE, Needs-Verification gate, local report, `/plan` output | | `output.md` | Report layout, flag reference, budget controller | | `cyclic.md` | `--loop` correctness gate, patch-ID tracking, guardrails | The verdict-gating guardrails are duplicated in this file **and** in the verifier script, so a budget-pressured run cannot bypass them by skipping a module. --- ## Guardrails (quick reference) | Action | Status | |--------|--------| | Auto-approve / auto-merge | FORBIDDEN | | APPROVE without a verifier-passed coverage manifest | FORBIDDEN (invalid run) | | Self-attest coverage without the external verifier | FORBIDDEN | | Drop a high-severity finding for low confidence | FORBIDDEN (demote to gating Needs-Verification) | | Report a finding without file:line + counterexample | FORBIDDEN | | Author tier exit codes/counts by hand | FORBIDDEN (parse `.out`) | | Treat an absent tool as a pass | FORBIDDEN (status=absent, confidence-capped) | | Mark a dimension checked with no owner/cited line | FORBIDDEN | | Read a missing or `in-progress` producer report as a clean pass | FORBIDDEN (INCOMPLETE — re-brief or cover inline) | | Let a producer return its reasoning instead of the ~1500-char contract | FORBIDDEN (findings live in its report file) | | Write a producer report inside the worktree | FORBIDDEN (scratchpad — it would pollute the reviewed diff) | | Return APPROVE after --no-poc or TRIAGE micro-defer | FORBIDDEN (INCONCLUSIVE) | | Use `sg` for AST search | FORBIDDEN (it is newgrp) | | Suppress a finding without citing the justifying line | FORBIDDEN (itself a finding) | | Modify repo code directly | FORBIDDEN (patches go to /plan) | | Post comments / MR-PR replies | FORBIDDEN (drafts for user only) | | Mention AI in PR/MR draft responses | ABSOLUTE FORBIDDEN | | Expose secrets in evidence/output | FORBIDDEN (mask AWS/PAT/JWT/PEM/Bearer) | | Politeness inflation / "LGTM" without proof | FORBIDDEN |