Implement plan (audited)
Same execution shape as implement-plan, with one addition: at strategic audit checkpoints (not after every increment), the audit-* specialist subagents run in parallel against the cumulative diff since the previous checkpoint and either auto-apply their fixes (auto mode) or surface them for user review (manual mode). The specialist subset is decided per checkpoint by audit-triage.
Choose checkpoints before execution and record them in state.json. Keep audit notes in worklog.md.
Specialists read the diff and their brief, without the plan or the user's goal.
Read the installed code-audit skill for orchestration. The native audit agent definitions contain the specialist briefs.
This skill inherits the entire per-increment verification loop from implement-plan Step 3, and the commit cadence contract CC-1 from implement-plan Step 3.5. It does not redefine them.
Args
mode=manual|auto— defaultmanual.plan=<path>— explicit plan file path. Default: detect from.plans/.commit=auto|yes|no— defaultauto. Per-increment AND per-audit-checkpoint commits unless onmain/master.yesforces commits on trunk;nosuppresses entirely.
Process
Step 1 — Bootstrap context
Delegates to implement-plan Step 1 (plan file, global standards, common-mistakes index, project check command, current git ref).
Additions:
- On a new run, save the pre-execution git ref as
state.json.audit.baseRefbefore implementation. On resume, retain the saved reference. - If completed work exists without an audit base, recover it from prior execution evidence. Stop if the audit range cannot be established.
- Maintain an in-memory specialist findings ledger for this run:
{specialist: [findings_count_by_checkpoint]}. Used in Step 3 for adaptive triage. Initially empty.
Big-output discipline applies throughout: redirect heavy command output to /tmp/hawk-implement-plan-audited-<step>.log, inspect with rg -n 'error|warning|fail|FAIL' /tmp/hawk-implement-plan-audited-<step>.log | head -50. <step> is e.g. inc3-check, ckpt2-check, final-check.
Step 1.5 — Record audit checkpoints
Use the work units, ids, and dependency graph from implement-plan.
Read its references/execution-state.md for state updates and resume rules.
Honor existing checkpoint choices in state or older **Audit checkpoint:** yes plan fields.
Import older markers into state without editing the plan.
When no cadence exists, place checkpoints at meaningful risk or integration boundaries.
Examples include a changed authorization boundary, a migration stage, or a complete external integration.
Group routine work between those boundaries. Audit the final executable unit so no completed work remains unaudited.
Do not assign checkpoints to blocked units. A small plan has one unit and one final audit.
No size score is required.
Set state.json.increments[<id>].auditCheckpoint = true under the state lock.
Set auditStatus to pending for a new checkpoint. Preserve recorded audit completion on resume.
For older records, accept completion only when the worklog contains the completed audit and its range.
Preserve these fields when recording implementation outcomes.
Summarize where audits will run. Keep the plan unchanged.
Step 2 — Execution loop
For each increment in dependency order:
Before new implementation, run any pending checkpoint whose unit is already done.
Do not repeat its application work. Audit completion is separate from implementation completion.
- Read forwarded markers in
state.json.increments[<id>].planOverride. Read the referenced audit note before choosing the implementation approach.
- Implement. Run
implement-planStep 3 in full (substeps 3.1–3.10, including the done-criteria check, the file-divergence check, and the structured outcome record). The per-increment commit fires via CC-1 (implement-planStep 3.5).
- Checkpoint gate. If this unit has
auditCheckpoint: trueandauditStatus: pendingin state:
- Audit the cumulative diff from
state.json.audit.baseRef— see Step 3. - Reconcile — see Step 4.
- Append the structured audit note to
worklog.mdunder this unit id (format in Step 4). - After reconciliation and any audit-fix commit, record the completed range in the worklog.
- Under the state lock, mark
auditStatus: doneand advanceaudit.baseRefto the audited HEAD together.
- Mode gate.
manual— pause and report the increment outcome (and audit outcome, if a checkpoint just ran) before starting the next increment.auto— proceed immediately. No prompts. Exceptions: behavior-change FIXes and architecture-level plan-overrides stop at the next checkpoint regardless of mode (see Step 4).
Manual / user-driven increments are marked blocked-on-user and skipped, regardless of mode.
Step 3 — Launch the audit specialists
At a checkpoint, capture the cumulative diff per-file. Per-file enumeration first, then per-file capture — never the raw concatenated cumulative diff:
git diff --name-only <prev_checkpoint_ref>..HEAD > /tmp/hawk-implement-plan-audited-files-<ckpt>.log
# for each file in that list:
git diff <prev_checkpoint_ref>..HEAD -- <path> > /tmp/hawk-implement-plan-audited-diff-<ckpt>-<file-slug>.patch 2>&1
Specialist user prompts receive narrowed rg -n slices from the per-file captures, never the full cumulative diff.
Per-checkpoint triage
Before fan-out, call:
reviewer: audit-triage; brief: <scope, signals>
The triage agent contract (decision rule, output schema) is owned by agents/audit-triage.md and reused here without modification.
The orchestrator-side triage call — what fields to assemble in the user prompt — is mostly shared with code-audit/SKILL.md Step 2, with explicit deltas because the two skills capture diffs differently. The delegation table is the single source of truth:
| Field | Source |
| ----- | ------ |
| Changed files | Supersedes code-audit Step 2. This skill uses git diff --name-only <prev_checkpoint_ref>..HEAD (from the per-file capture flow), not git diff --name-only --stat <range>. |
| Risk-signal greps | Same as code-audit Step 2: narrowed rg -n over the diff captures, omit signals with no matches. Aggregation: greps run per-file; aggregate matches across all per-file captures into a single combined set, then apply the ~30-line cap to the combined set (not per file). |
| Scope stats | Same as code-audit Step 2 (files: N, lines added/removed: +A/-B, layers spanned: …) plus an additional field: increments covered: <N> increments (count, not the index range). |
| Adaptive bias | Delta: pass the specialist findings ledger from Step 1's run state. The triage agent may use this as a tiebreak: specialists with ≥2 prior findings this run get included automatically; specialists with 0 findings across ≥3 prior checkpoints may be safely skipped when other signals don't argue for them. |
| Parse contract | Same: tier: / specialists: / reason: lines, in that order. |
| Parse-fail fallback | Same: tier=standard, continue, never silently skip the audit. Auto mode does not stop on a malformed triage — bias is up. |
| When forced | Same: tier=light\|standard\|deep skips triage and uses the static mapping in code-audit/SKILL.md. |
| When run | Delta: per checkpoint, not once per skill invocation. Different checkpoints in the same run can legitimately land on different tiers. |
If code-audit Step 2 changes any "Same" row, this skill inherits the change automatically; the "Supersedes" and "Delta" rows are this skill's responsibility.
Triage decision is internal; record it in the structured audit note (Step 4).
Fan out the specialists in parallel
Start one independent reviewer per role in the selected subset. Use concrete agent names so install-time prefix rewriting stays consistent:
reviewer: audit-logic; brief: <USER PROMPT>
reviewer: audit-security; brief: <USER PROMPT>
reviewer: audit-simplification; brief: <USER PROMPT>
reviewer: audit-research; brief: <USER PROMPT>
reviewer: audit-architecture; brief: <USER PROMPT>
Skip any role not in the triage subset.
Do not delegate to code-audit; it is a skill, not an agent. Run the audit-* specialists directly from the main session.
Specialist user prompt — minimum-context principle
The agent body owns the role, anti-bias contract, verification rule, and output schema. The orchestrator's per-call user prompt contains only what specialists need to evaluate the code on its own merits:
## Files / diff in scope
{narrowed `rg -n` slices from the per-file captures}
## Standards (pasted inline, do not fetch)
{full content of every relevant `.agents/standards/` file}
## Common mistakes (pasted inline, do not fetch)
{full content of every relevant `.agents/common-mistakes/` file}
## Scope
This diff covers {N} increments — {files} files, +{added}/-{removed} lines, layers: {layers}. Do NOT look up which increments those are or what they did. Scale your reasoning to the diff size, nothing more.
## Verification clause requirement
For every FIX you propose, include a `verify:` clause — a concrete check that confirms your fix actually resolves the finding (a command to run, a test to add, an assertion to make, a query to evaluate). FIXes without a verify clause will be rejected at reconcile.
No increment indices in the prompt — scope stats only. The orchestrator keeps the index mapping internally for its own reconciliation; the specialist doesn't need it. Removes the bias risk where "Inc 1–3" might imply foundation work and bias the specialist toward foundational concerns.
Step 4 — Reconcile
When all specialists return:
- Merge their FIX / NOTE / QUESTION outputs the same way
code-auditmerges them — dedupe bypath:line, attach overlapping reasoning, surface QUESTIONs immediately.
- Validate verify clauses. For each FIX in the merged set, confirm a
verify:clause is present and the clause is runnable (a command, a test name, a specific assertion — not "ensure correctness"). FIXes missing or with non-runnable verify clauses are returned to the specialist if there's session budget, or escalated to the user.
- Apply, depending on mode:
auto— apply every validated FIX directly. For each FIX:- Apply the change.
- Run the FIX's
verify:clause. The verify clause must pass — otherwise the fix did not resolve the finding (it may have masked it). On verify failure, revert that specific fix and surface to the user; do not silently proceed. - When all FIXes are applied and verified, run the project check command with the full layered retry ladder (
implement-planStep 3.5 Stages 1–4). If the ladder exhausts without a clean check: stop, fall back to manual mode, surface the audit output and the failing diff. - Record each NOTE that remains after promotion in
worklog.mdunder the checkpoint unit id, with itsBenefit,Blocker, andNextroute. Step 6 routes them. They do not stop the run. manual— present the merged FIX list (with verify clauses) and the NOTEs (withNextroutes) to the user. Apply only what the user approves. Then run each approved fix's verify clause, then the project check command.
- Plan-override flagging. If the merged output reveals that the approach taken in any covered increment was structurally wrong (a specialist's
Why:describes a fundamentally cleaner architecture, or a fix touches the public API the plan specified):
- Apply the fix (the immediate code is now corrected).
- Propagate the override. Walk the remaining increments in the DAG. For any increment that depends on the audited range — directly or transitively — record a forward marker:
- Set
state.json.increments[<id>].planOverride = "ckptN: <audit note ref>"under the state lock. - Record the correction in
worklog.md. Keep the plan unchanged.
Step 2 reads this marker before implementing the affected unit.
- Architecture-level overrides stop at the next checkpoint regardless of mode. If the override is structural (changes module boundaries, public API surface, data model in a way the plan didn't anticipate), auto mode finishes the current run-up to the next checkpoint, runs that checkpoint's audit, then stops and surfaces to the user. Bounds the blast radius to one additional checkpoint of work.
- Behavior-preservation FIXes. Any FIX that changes external behavior (HTTP response shape, function signature, side effects, error semantics, persisted data):
- Apply and commit as its own commit (per Step 5 cadence).
- Write
BEHAVIOR_CHANGE.mdin the plan directory (.plans/<slug>/BEHAVIOR_CHANGE.md), appending an entry: timestamp, ckpt id, file:line, one-line description of what changed, link to the audit note. - Stop at the next checkpoint regardless of mode. Behavior changes that emerge mid-run need explicit user acknowledgement before further increments build on them.
- Update the specialist findings ledger (in-memory from Step 1) with this checkpoint's per-specialist counts. The next checkpoint's triage sees this.
- Append the structured audit note to
worklog.mdunder the checkpoint unit id:
**Audit checkpoint:** yes (executed)
audit-ckpt<N>: tier=<light|standard|deep> specialists=[<list>] reason="<from triage>"
fixes=<count> notes=<count> plan-overrides=<count> behavior-changes=<count> covers=<inc-labels>
Three lines, structured fields, parseable. A reviewer reconstructing the run can read it in 5 seconds; a tool can parse it for run analytics.
The audit note is distinct from the per-increment outcome record owned by implement-plan Step 3.10 — different artifacts, different owners. Do not merge or duplicate them.
Because a checkpoint covers multiple increments, the merged FIX list will often be larger than a per-increment audit. Group findings by file in the user-facing report (manual mode) so reviewers can scan quickly.
Step 5 — Commit hygiene (delta over CC-1)
The contract is implement-plan CC-1 (Step 3.5). Per-increment commits delegate to it in full — branch detection, opt-out flow, stop-out edge cases, staging-by-discovery, rename/deletion handling, no-AI-attribution rule, pre-commit hook failure handling, empty-change skip. The additions here are separate audit-fix commits and a BEHAVIOR_CHANGE.md commit when applicable.
Cadence.
- Per increment — handled by CC-1 inside the per-increment loop (Step 2.2). The outcome is in
worklog.mdandstate.jsonbefore commit. - Per audit-fix pass — after Step 4 applies fixes and the check command is clean. Re-discover changes with
git diff --name-only HEADafter applying fixes (do not track per-FIX file lists during Step 4 — re-discovery is the canonical source). Separate commit from the increment commit, so audit cleanup is bisectable independent of feature work. - BEHAVIOR_CHANGE.md commit — when Step 4 wrote a new entry. Can be folded into the audit-fix commit if the same checkpoint produced both, or stand alone if the audit-fix commit was skipped (verify failure path).
- If the audit applied zero fixes, skip the audit commit entirely (no empty commits).
Ordering when the increment IS the checkpoint. The increment commit fires first (inside CC-1), then the checkpoint audit runs against the new HEAD, then any audit-fix commit fires after reconcile. git diff --name-only HEAD for audit-fix staging therefore sees only the audit's changes, not the increment's — because the increment was already committed.
Commit message style — discovery-driven, with audit-commit disambiguation. Read git log -10 --oneline to detect the dominant style (done once per run, by CC-1). Mirror it verbatim for increment commits. For audit commits, keep them peelable with git revert — match the detected style, checking Conventional Commits first because its <type>(<scope>): pattern overlaps the plain-scope pattern:
- Conventional Commits (messages match
<type>(<scope>):) →chore({slug}): audit cleanup for {increment-labels}(e.g.chore(billing): audit cleanup for Inc 5–7). - Plain
<scope>: <description>(no parentheses) →audit: cleanup for {increment-labels}. - Plain lowercase imperative, no prefix → prefix with
audit:literally. - Mixed / emoji-prefixed / JIRA-prefixed / unclear → default to plain
audit: cleanup for {increment-labels}.
{slug} = the plan directory name (last component of .plans/<slug>/). {increment-labels} match the plan's increment labels — Inc 5–7 for a numeric range, Inc foo-bar for non-numeric. Mirror the plan, do not normalize.
Auto mode honors the same cadence — the per-increment and per-audit commits make a long unattended run easy to bisect after the fact, and each commit is a recovery point if a later step fails.
Step 6 — Completion
When all increments are done or blocked-on-user:
- Run pending checkpoints for completed units. Audit any completed work beyond the last recorded audit range before declaring completion.
- Run a final check command.
- Route open NOTEs. Read the NOTEs recorded in
worklog.mdduring this run. Cluster related NOTEs by module or theme. Write one plan for each cluster withplan-small, or withplan-largewhen the cluster spans modules or PRs. Do not implement these plans in this run. - Summarize to the user:
- Increments completed and blocked.
- Per-increment outcomes — read attempts and evidence from
state.jsonandworklog.md. Explain unresolved failures. - Done-criteria evidence paths — list each
/tmp/hawk-implement-plan-verify-incN.log. Explicit audit trail. - Audit checkpoints — for each, paste the structured audit note (tier, specialists, fixes, plan-overrides, behavior-changes, covers).
- Plan-override flags raised — affected unit ids from state, the correction, and any required stop.
- BEHAVIOR_CHANGE.md contents if any entries — read the file back, paste each entry.
- Open improvements — the path of each plan from item 3 and the NOTEs it covers.
- Any QUESTIONs the audit surfaced — how the orchestrator answered them, or what was surfaced for the user.
- Commit count when commits are enabled: "N feature commits + M audit commits". If skipped, say so explicitly so the user isn't surprised by a clean
git log.
Auto mode — failure floors
Auto mode is for unattended runs. Every gate is a hard floor — auto mode will not loop indefinitely. Each of the following stops the run:
- Increment implementation fails the layered ladder (
implement-planStep 3.5, Stage 4) → already escalated byimplement-planitself. - Done-criteria check cannot produce evidence (
implement-planStep 3.6) → escalated byimplement-plan. - File divergence is material and unexplained (
implement-planStep 3.7) → escalated byimplement-plan. - Audit FIX applied → its
verify:clause fails → revert that fix, surface, stop. - Audit fixes applied → check command fails the layered ladder → stop, fall back to manual.
- A specialist surfaces a QUESTION it can't resolve → stop, ask the user. Auto mode does not guess on blocking questions.
- A non-architecture plan-override → apply the fix, propagate the marker, continue. User sees it in the completion summary.
- An architecture-level plan-override → apply, propagate, finish the current run-up to the next checkpoint, run that checkpoint, then stop.
- A behavior-change FIX → apply, commit, write BEHAVIOR_CHANGE.md, finish the current run-up to the next checkpoint, then stop.
Stopping in auto mode means: print the current state, the merged audit output (if any), the failing diff or failing verify clause, and the contents of BEHAVIOR_CHANGE.md if written. Wait for user input. Do not revert (except for the specific failed-verify FIX in case 4).
Hard floors
Process steps above are the source of truth. Floors that must not slip:
- Audits run only at annotated checkpoints, not after every increment. Step 1.5 computes the cadence; the loop honors it.
- Triage runs once per checkpoint, not once per skill invocation. Different checkpoints can legitimately land on different tiers.
- Specialists run in parallel as fresh subagents. A single-pass non-parallel audit is never allowed.
- Specialist prompts are blind and minimum-context. No plan path, no goal, no chat history, no increment indices.
- Every FIX must include a runnable
verify:clause. Findings without verify clauses can't close; FIXes whose verify clauses fail can't be accepted. - Plan-overrides propagate through state. Read the correction before starting an affected unit. Architecture-level overrides stop at the next checkpoint regardless of mode.
- No audit finding ends as "no action". FIXes are applied; NOTEs that remain go to plans at completion.
- Behavior-changing FIXes are never silent. Apply, commit, write to BEHAVIOR_CHANGE.md, stop at the next checkpoint.
- The specialist findings ledger informs adaptive triage within a run — earned seats for specialists with hits, optional skip for specialists with consistent zero findings.
- Store audit markers in
state.jsonand audit notes inworklog.md. Keep execution records outside the plan. - Honor user checkpoint choices and existing state. Import older plan markers without editing the source.
- Triage-call shape is owned by
code-audit/SKILL.mdStep 2 and inherited via the delegation table in Step 3. - Commit hygiene delegates to CC-1 (
implement-planStep 3.5) for per-increment commits, with Step 5 here adding audit-fix and BEHAVIOR_CHANGE.md commits. No AI attribution, ever. No empty audit commits. No--no-verify. Both modes. - Big-output discipline. Heavy command output goes to
/tmp/hawk-implement-plan-audited-<step>.log(or a unique slug with randomness for parallel-safe contexts), thenrg -n '<pattern>' /tmp/... | head -50extracts what's needed. Read only the required lines from the file. In auto mode, never paste a raw/tmpcapture into the conversation — only narrowed slices.