Code (CD)
Intent
Finish one slice end-to-end with proof (≥1 validation signal). Constrain scope, define "done," require evidence. Deliver an apply_patch diff (no PR).
Definition of Done (CD)
Done when:
- •Slice acceptance criteria met.
- •Formatter/lint-typecheck/build/tests run (or N/A).
- •≥1 validation signal recorded (see "Proof").
- •Handoff includes an
apply_patchdiff + notes.
Workflow
0) Preflight (don't skip)
- •Confirm slice brief (source of truth) + explicit
codeinvocation. - •If missing requirements (acceptance criteria or full validation command list), stop and ask.
1) Identify the slice (source of truth)
- •Anchor on the slice brief (issue/ticket description + slice text).
- •Restate "done" for this slice (1 sentence + acceptance criteria).
- •Confirm the exact full validation command list to run; if missing, stop and ask.
2) Clarify until requirements are implementable
- •Ask only judgment calls; everything else is in repo/slice brief.
- •If ambiguity appears mid-implementation, stop and re-clarify.
3) Audit the working tree (scope containment)
- •Audit early/often; keep diffs surgical.
4) Do the work (how the work is accomplished)
4.1) Mandatory TRACE mini-pass
Before first incision, run a small TRACE mini-pass (do not invoke $fix unless explicitly instructed):
- •Heat map: hotspots + surprises.
- •Failure triage: crash > corruption > logic.
- •Invariant: what must remain true after the change?
- •Footgun scan: any misuse-prone surface?
- •Incidental complexity: flatten/rename/extract only if risk drops.
4.2) Complexity gate (stop and ask)
If complex (multi-constraint, cross-subsystem, high uncertainty, multiple viable designs), stop and ask.
Provide a five-tier portfolio (Quick Win, Strategic Play, Advantage Play, Transformative Move, Moonshot), each with an expected signal + escape hatch. Ask for a selection, then resume.
If available, you may use $creative-problem-solver to generate the portfolio, but still present it explicitly.
4.3) Surgeon loop (execution)
Tight loop:
- •Hypothesis: what change likely satisfies the slice?
- •Smallest incision: smallest change that could be correct.
- •Observable: test/invariant/log.
- •Implement: minimal collateral.
- •Re-check: rerun closest fast signal.
- •Repeat until acceptance criteria pass.
Autonomy gate: proceed without further clarification only when all are true:
- •Local repro (or a tight, credible signal).
- •Invariant stated.
- •Minimal diff.
- •At least one validation signal passes.
Otherwise, clarify before widening scope.
Heuristics by slice type:
- •Bug: reproduce if possible; otherwise add a characterization test or diagnostic signal, then fix.
- •Feature: smallest end-to-end slice (vertical slice > layered scaffolding).
- •Refactor: preserve behavior; add a characterization test/invariant first.
Refactor hygiene (within slice scope):
- •Limit simplification to slice-touched code unless explicitly asked.
- •Cleanup must preserve behavior outside the slice.
- •Prefer explicit, readable code; avoid nested ternaries (use if/else/switch).
- •Remove redundant comments; keep clarifying ones.
- •Keep helpful abstractions; don't flatten at the cost of clarity.
5) Validation (all musts)
Run all: Formatter, Lint/typecheck, Build, Tests (unit/integration).
Order: formatter + lint/typecheck + focused tests, then build + full suites. Patch handoff is blocked until all categories run.
Entry points: prefer canonical (make, just, task, npm run, cargo, go test, etc.); if multiple, run all or justify the skip.
If a category doesn't exist: record N/A with a 1-line reason and run the nearest substitute.
6) Collect ≥1 validation signal (minimum one)
After changes + validations, explicitly record ≥1 signal (see "Proof"). Prefer higher-strength signals: tests > build > lint/typecheck > formatter > runtime log/manual repro.
7) Record proof (make results auditable)
Record proof in the handoff:
- •Commands run + outcomes.
- •Signals (≥1; include the strongest).
- •Decision (portfolio selection, if used).
- •Notes (N/A validations, limits, follow-ups).
- •Simplification (only significant refactors).
8) Deliver a patch (no PR)
- •Deliver an
apply_patchdiff that applies cleanly. - •Stop: no PR/push/commit unless explicitly asked.
Principles
- •Source of truth: the slice brief wins.
- •Safety nets: compile/construction-time invariants > focused test > minimal guard/log.
- •Surgeon's principle: smallest correct change.
Failure Paths
- •No slice brief: stop and request one.
- •Unclear requirements: stop and ask; don't guess.
- •Unrelated diffs: ignore; don't touch or stage; continue. If the task would touch the same lines/hunks, stop and ask.
- •Validation fails: fix and rerun before delivering the patch.
- •Bug can't be reproduced: add instrumentation or a characterization test; state limits in proof.
Deliverable
- •Patch-ready changes (formatted, linted/typechecked, built, tested).
- •Handoff includes:
apply_patchdiff, assumptions, proof (signals), and deliberate non-scope.
Examples (calibration)
Bug slice
- •Slice brief shows bug
X; restate done + acceptance criteria. - •TRACE mini-pass (heat map, failure modes, invariant).
- •Reproduce or characterize.
- •Smallest fix.
- •Fast checks (format + lint/typecheck + focused tests).
- •Slow checks (build + full suites).
- •Record proof (handoff).
- •Deliver
apply_patchdiff.
Feature slice
- •Slice brief shows feature
Y; restate done + acceptance criteria. - •TRACE mini-pass (heat map, failure modes, invariant).
- •If complex, stop and ask (portfolio); pause for selection.
- •Smallest vertical slice users can exercise.
- •Add/extend tests.
- •Fast checks (format + lint/typecheck + focused tests).
- •Slow checks (build + full suites).
- •Record proof (handoff).
- •Deliver
apply_patchdiff.
Guardrails
- •Explicit-only; never auto-trigger.
- •Patch-only: no PR/push/commit unless explicitly asked.