Harness Intelligence Wiki
SpecsCLIReview Phase Token Rebuild

Review Phase Token Rebuild

Spec: Review Phase Token Rebuild

Context

One Full Code Review Pass of review-phase costs 25–30M tokens today. Most of the cost is a gate subagent that does mechanical work over about 90 turns: it reads about 31k tokens of graph documentation, hashes inputs, builds the Review Packet and writes the report. Two axis subagents only start the vendored autoreview helper and wait. The helper is a frozen May 2026 fork: in prepared mode it applies none of the upstream review method. When the Codex quota ran out on 2026-10-22, the skill text made the agent retry the same engine, and one pass ran 200 minutes with no result. Reports live in the wiki and enter later review scopes. Evidence: the Brainstorm Brief Findings table and the closed grill.

The rebuild keeps the two review axes (Standards, Spec) and the delivery pass rules. It moves all mechanical work into scripts, runs the upstream helper unchanged through a wrapper, adds Engine Fallback, uses one Adjudicator, and stores a temporary Pass Report in the delivery folder.

Actors: the root delivery agent, the review.mjs script, the engine CLIs (claude --print, codex exec), the Adjudicator subagent, human operators, and maintainers who publish the Baseline. Terms follow the glossary.

Root agent          review.mjs                          Engines
status ───────────▶ next step + pass count
prepare ──────────▶ freeze, packet, budget, context, --dry-run size, mechanical checks
run (background) ─▶ Axis Run standards ──▶ host engine ─fail─▶ next engine
                    Axis Run spec ───────▶ host engine ─fail─▶ next engine
Adjudicator ◀────── packet + 2 Review Lens Results  → adjudication.json
retain ───────────▶ pass-<n>.json (exclusive create, pathspec commit) → route

Non-Goals

  • PR bots (for example greptile) and CI overlap.
  • Usage accounting for the Claude engine.
  • The 2026-10-05 to 2026-10-19 subagent start-context inflation.
  • Migration or deletion of existing wiki review reports (Q18).
  • A runtime token guard (Q19).
  • Review of content that is not a Git change (Q15).

Requirements and Outcomes

OUT-001: A pass is cheap and its cost is measured

The median Full Code Review Pass costs at most 4M tokens and at most 10 model turns outside the Adjudicator. Each Pass Report records the usage needed to measure this.

Architecture: OUT-001, ARC-012, FLOW-001.

OUT-002: Scripts own the mechanical pass work

review.mjs freezes the target, builds the Review Packet, checks budget, size and mechanical evidence, controls engines, writes the Pass Report and derives routing. No model turn does this work.

Architecture: OUT-002, ARC-002, ARC-003, FLOW-001.

OUT-003: Axis Runs apply the upstream review method with axis guidance

Each pass has a Standards Axis Run and a Spec Axis Run. Each calls the upstream helper unchanged with its axis guidance and source context.

Architecture: OUT-003, ARC-006, FLOW-001-STEP-004.

OUT-004: Engines never stall a pass

The pass uses the host's own model by default and moves to the next engine on any engine failure or timeout. When every engine fails, the pass stops with an exact blocker.

Architecture: OUT-004, ARC-005, FLOW-002.

OUT-005: One Adjudicator verifies candidates

One readonly subagent verifies every distinct candidate against the real code and sets final severity and route.

Architecture: OUT-005, ARC-007, FLOW-001-STEP-006.

OUT-006: The Pass Report is the temporary, single source of the pass count

A completed pass writes one Pass Report in the delivery folder. The number of valid Pass Reports is the completed pass count. Reports never enter a review target or the wiki.

Architecture: OUT-006, ARC-009, FLOW-001-STEP-007.

OUT-007: A pass resumes without repeating completed work

After an interruption, a pass reruns only what is missing.

Architecture: OUT-007, ARC-008, FLOW-003.

OUT-008: Standalone review covers committed artifacts

An operator can review a committed plan, spec, docs or code change without a delivery budget.

Architecture: OUT-008, ARC-011, FLOW-004.

OUT-009: review-phase is one small skill with a vendored upstream helper

review-phase holds one short procedure, four references, its scripts and the unchanged upstream helper. The autoreview and review skills no longer exist.

Architecture: OUT-009, ARC-001, ARC-004.

OUT-010: Delivery consumes the new pass contract

delivery-phase reads the Pass Report path and run identity and derives the pass count.

Architecture: OUT-010, ARC-010.

OUT-011: Harness consumers, docs and release move with the change

The HI catalog, manifests, prompts, wiki, runbook, other skills and the Baseline changelog describe the new pass, and consumer repos converge through hi update.

Architecture: OUT-011, ARC-013.

OUT-012: Tests prove the pass through its public seams

CLI and library tests with fake engines replace the graph contract tests.

Architecture: OUT-012, ARC-014.

OUT-013: Agent-facing text follows the writing discipline

Every prompt and skill text this change creates or edits applies $writing-for-agents.

Architecture: OUT-013, ARC-015.

Acceptance Criteria

  • AC-001: Every Pass Report records, for each Axis Run attempt, engine, model, seconds, outcome and upstream usage (or null when the engine reports none), and records the Adjudicator's subagent_tokens.
  • AC-002: A validation of at least three Full Code Review Passes over real deliveries shows a median of at most 4M tokens per pass (root-agent review turns plus Adjudicator subagent_tokens plus recorded engine usage) and at most 10 root-agent model turns from status to route return.
  • AC-003: No pass fails or stops because of its token use; the only runtime limits are the per-attempt engine timeout and the --dry-run size check.
  • AC-004: review.mjs provides prepare, run, retain and status; each prints exactly one JSON line on stdout with the fields of Q32, and a non-null blocker is one sentence.
  • AC-005: prepare freezes base..HEAD, derives the Review Packet identity, checks the pass budget, selects source context, sizes both axes with upstream --dry-run, and runs the skill-evidence cardinality check and the acceptance-criterion-to-Verification record check, all without starting a model; gaps from the two checks become candidates, and oversize, budget exhaustion or a missing source returns a blocker before any engine starts.
  • AC-006: review-contract.mjs exports reviewPacketIdentity, planDeliveryReviewGate, deriveReviewRouting, recoverPassCount, validatePassReport, planEngineOrder and selectSourceContext, and no longer exports validateRetainedPass, resolveRetainedRun, wiki report path, Markdown report encode/parse, retained-ref or standalone bundle functions.
  • AC-007: Each Axis Run calls scripts/vendor/autoreview with --mode branch --base <base> (or the standalone commit or range), --max-priority P2, --engine <engine>, --engine-timeout-seconds, --prompt-file of its axis-standards.md or axis-spec.md, its --source-context list, and --json-output/--status-output inside the run directory.
  • AC-008: The Standards source context holds the AGENTS.md chain of the touched paths, the matched Codebase Rules and each assigned skill's SKILL.md; the Spec source context holds SPEC.md, ARCHITECTURE.md, PLAN.md and IMPLEMENTATION-NOTES.md.
  • AC-009: axis-standards.md states documented repo standards as hard rules, labels Fowler smells as P3 information, and contains no simplify check.
  • AC-010: With CLAUDECODE=1 the engine order is [claude, codex]; with CODEX_THREAD_ID set it is [codex, claude]; HI_REVIEW_ENGINES replaces the order when set; models stay at upstream defaults unless overridden.
  • AC-011: When an engine attempt ends in reviewer_unavailable, timed_out, incomplete or a refusal exit, run starts the same Axis Run on the next engine at once and never retries the same engine.
  • AC-012: When every engine fails for an axis, its Review Lens Result is incomplete with every attempt and cause, run prints a blocker, and no completed pass is counted.
  • AC-013: The review-phase procedure starts run in the background and contains no step that watches, polls or sleeps on an engine process.
  • AC-014: The Adjudicator is one readonly subagent that receives the packet and both Review Lens Result paths and writes adjudication.json with findings (id, axis, severity, location, evidence, action, return_route) and rejected candidates with reasons; retain refuses an invalid file.
  • AC-015: references/adjudicator.md allows a command only to test one specific candidate and contains no repeat of Task Gate validation.
  • AC-016: retain creates .devpunks/delivery/<goal>/reviews/pass-<n>.json with an exclusive create and commits only that path; a second writer for the same n fails without overwriting.
  • AC-017: A Pass Report follows pass-report-v1 with the fields of Q34 and has no Markdown body or wiki frontmatter.
  • AC-018: The completed pass count equals the number of valid Pass Reports for the goal; status reports it; one pass is the default, a second needs an accepted-risk trigger and a further pass needs explicit human direction.
  • AC-019: Every review target excludes .devpunks/delivery/**/reviews/.
  • AC-020: No new pass writes to the wiki; Pass Reports stay in the delivery folder after closeout; legacy wiki review reports are not read for the count.
  • AC-021: Run state lives only in $TMPDIR/hi-review/<run-id>/, and retain removes that directory.
  • AC-022: On resume, run keeps each Review Lens Result whose packet identity is unchanged and reruns only failed or missing axes; with no run directory both axes run from a new prepare.
  • AC-023: prepare --standalone accepts a commit or commit range, refuses a target that is not a Git change, and reads and writes no delivery counter.
  • AC-024: review-phase/scripts/vendor/autoreview holds the upstream v0.6.0 helper bytes unchanged, scripts/vendor/UPSTREAM.md records the tag and its --version source-sha256, and no test asserts byte identity.
  • AC-025: review-phase has SKILL.md, references/{adjudicator,axis-standards,axis-spec,routing}.md, the mattpocock UPSTREAM.md and LICENSE, and scripts/; phases/, AUTHORING-HANDOFF.md and references/{durable-report,runtime-handoff,state-graph,targets,review-packet}.md are absent.
  • AC-026: skills/agnostic/quality/autoreview/ and skills/agnostic/quality/review/ are absent from the skills repo.
  • AC-027: delivery-phase references/phase-handoff.md and artifact-state.md carry pass_report and review_run_id instead of report path, report SHA-256, report commit and verified_retained_ref; no file stores review_count; phases/{review,router,closeout,implement,debug}.md match.
  • AC-028: The HI catalog (skills.ts, packs.ts) and both subagent manifests contain no autoreview or review entry; spec-reviewer keeps review-phase; the publisher test pins skills/review-phase/scripts/vendor/autoreview as an executable copy.
  • AC-029: hi update in a consumer repo removes unedited copies of autoreview and review and reports edited copies, and BASELINE_CHANGELOG.md Unreleased tells operators to run hi update --yes for edited copies and that in-flight deliveries restart their pass count.
  • AC-030: ask-hi references, the debugging-phase and finder-phase $review-phase invocations, the harness prompt templates, harness/entrypoints/review.mdx with the other review wiki pages, and runbook hi-cli-scaffolding.md describe the new pass; project/reviews/ is marked frozen history; the scaffolded wiki contract has no reviews/ section.
  • AC-031: tests/review-phase-cli.test.mjs proves Engine Fallback, timeout to the next engine, resume reuse, exclusive ordinal, the oversize blocker and routing with fake engines through CODEX_BIN/CLAUDE_BIN; review-contract.mjs unit tests exist; the graph and v43-frozen-review tests and their fixtures are removed; text-pin tests that named removed files are updated; npm test passes in the skills repo.
  • AC-032: The implementation notes record $writing-for-agents application for every prompt and skill text created or edited.

Constraints

  • Skills are edited only in /home/stefan/repos/skills on main, then synced with bun run sync:skills (root AGENTS.md).
  • The upstream helper stays unchanged; local behaviour lives in review.mjs (Q6).
  • Engines see only the bundle and source context (upstream S:4236).
  • Upstream reviews only Git changes (upstream S:4224, S:2055).
  • Canonical terms: Axis Run, Adjudicator, Engine Fallback, Pass Report, Full Code Review Pass, Review Packet, Review Lens Result.

Dependency Readiness

Ready.

  • openclaw/agent-skills tag v0.6.0, commit aa2f8f7afd8ff26a26ac0b20b8d5a62b7dd16fae, path skills/autoreview/scripts/autoreview (landed upstream release).
  • wearedevpunks/skills main @ 979a504f0fd7cd49f01b16689e224db608c89f5c (current source of review-phase, review, autoreview).

Branch/Base Intent

  • wearedevpunks/skills: commit on main directly (root AGENTS.md shared skills rule); no pull request.
  • wearedevpunks/harness-intelligence: one delivery branch from main, one pull request against main (one PR per Touched Repository).

Architecture Source

Accepted Technical Decisions

  • Pass shape prepare → run → adjudicate → retain; no axis subagents (Q3, Q4; ARC-002).
  • Node ESM review-phase/scripts/review.mjs with prepare, run, retain, status; one JSON line each; --standalone flag (Q20, Q32).
  • Side effects in review.mjs, pure logic in review-contract.mjs (Q33, Q36).
  • Run state $TMPDIR/hi-review/<run-id>/, removed by retain (Q21).
  • Upstream helper unchanged at review-phase/scripts/vendor/autoreview with vendor/UPSTREAM.md (tag + --version source-sha256) (Q25).
  • Upstream review prompt in both Axis Runs; axis guidance through --prompt-file; --max-priority P2; no third run (Q7, Q8).
  • Host detection CLAUDECODE=1 / CODEX_THREAD_ID; order [host, other]; override HI_REVIEW_ENGINES; upstream model defaults (Q9, Q26).
  • Engine Fallback on any engine failure or timeout; all engines fail → incomplete + blocker (Q10).
  • Pass Report pass-report-v1 at .devpunks/delivery/<goal>/reviews/pass-<n>.json; exclusive create; pathspec commit; count = valid files; debt keys = report path + finding ID (Q13, Q23, Q34).
  • Delivery handoff pass_report + review_run_id; derived count (Q37).
  • review guidance moves to axis-standards.md / axis-spec.md; review and autoreview skills deleted (Q25, Q29).
  • One delivery across skills and harness; consumers converge through STEP-011 stale removal (Q38).

Explanation and diagrams: architecture.

Accepted Testing Decisions

  • The engine test seam is upstream CODEX_BIN / CLAUDE_BIN with fake engine binaries (Q33).
  • tests/review-phase-cli.test.mjs plus review-contract.mjs unit tests replace the graph and v43-frozen-review tests (Q39).
  • No byte-identity test on the vendored helper (Q25).

Verification Seams

  • review.mjs stdout JSON lines and exit codes.
  • The Pass Report file and its Git commit.
  • The run directory contents under $TMPDIR/hi-review/<run-id>/.
  • Fake engine binaries on CODEX_BIN / CLAUDE_BIN.
  • hi update report rows (removed, stale-reported) in a consumer fixture.
  • npm test in the skills repo; harness catalog and publisher tests.

Parked Decisions

  • PR bots and CI, Claude-engine usage, subagent start-context inflation: owner maintainer; resume trigger a later grill (status branch Out of scope).

Decision Log

DecisionEvidenceRationale
Scripts own mechanical workQ2; Brief FindingsGate subagent costs 12–26M tokens per pass
Upstream helper unchanged + wrapperQ6, Q25Clean updates; helper only inside review-phase
Engine Fallback on any failureQ10; upstream S:5910Upstream cannot detect quota and never switches engine
Temporary Pass ReportQ13, Q16, Q23One count source; out of wiki and review scope
Acceptance measurement, not runtime guardQ19A token guard leaves code unreviewed

On this page