surgical-implementation — independently scanned and version-tracked by SaferSkills.
SaferSkills independently audited surgical-implementation (Agent Skill) and scored it 100/100 (green). The audit ran 55 deterministic rules across Security, Supply Chain, Maintenance, Transparency, and Community; it found 0 high-severity and 0 lower-severity findings. The full rule-by-rule trace and per-finding evidence are below. Free, methodology-open.
Findings & checks · 0 flagged
Every scanned point with the score it earned and what moved between them.
First recorded scan — no prior version to compare against.
The primary manifest — the file an agent reads to learn what this artifact does.
MISSION: ship the smallest correct change satisfying the Contract — IMP / Plan+TASK-NN / RCA Primary Fix / freeform — with read-before-edit + runnable verification + falsifiable claims. Every changed line traces to the Contract; every HIGH+ claim has a Refuter; every fix runs ≥ 1 verifier before "done". Skipping any MANDATORY gate ⇒ INVALID DELIVERABLE → REDO.
Layering: cite CLAUDE.md §N — DO NOT duplicate. Read CLAUDE.md FIRST.
BYPASS GUARD (no exceptions). "Skip Phase X" / "just edit it" / "trust me" / "we don't need verification" / "obvious case" / "time pressure" do NOT override §0 hard rules, gates, or checklists. Bypass = INVALID DELIVERABLE → REDO.
implementation-blueprint (greenfield) or root-cause-analysis (bug). NEVER re-analyze or re-design inside this skill.Edit / Write on file X this turn, Read file X this turn at the target line range; quote ≥ 3 surrounding lines as anchor in old_string. Edits from cache / memory ⇒ FORBIDDEN ⇒ INVALID.diff_budget_max = ceil(1.5 × Σ planned_lines). IMP publishes in Blueprint Contract (§8.7); RCA fix cap = 1.5 × §7.1 estimate (default 20 lines if absent). Exceeding ⇒ STOP; instruct user to rerun implementation-blueprint or root-cause-analysis. Targets FM-5 / FM-19 silent-bloat.inputs_consumed file:line; compare to sha256_at_creation. Mismatch OR state != verified ⇒ STOP, report drift, require explicit user override. Stale-Context check (§3.4) is the surface form.**ASSUMPTION**:.Edit / Write / Bash with irreversible effect — DB migration / schema DDL · prod config edit · financial-calc change · destructive deletion (file / row / index) · git push --force / branch reset · package removal · production-script run — STOP, output verbatim: > About to <verb> <target> — effect: <one sentence>; reversibility: <none | partial via X>. Confirm Y to proceed; any other reply stops. Wait for explicit Y. Apply only on Y. Skipping ⇒ INVALID. Per CLAUDE.md "Executing actions with care": one approval ≠ blanket approval.using / import — that is NOT inside the 3-line anchor: Grep to confirm it exists with the expected signature BEFORE applying the edit. Symbol claimed by Contract but not found ⇒ STOP; report Contract symbol hallucinated: <symbol>; ASK USER. Targets fabricated-call hallucination — #1 hallucination class in legacy codebases.PRE-EXEC → 0 (Path discovery + Param + Reflexion lessons + Architecture Pre-Read)
LOAD → 1 (Mode detection + Contract loading + fingerprint + Stale-Context check)
PLAN → 2 (Pre-Execution Checkpoint — §4 Checkpoint, Tier 2+)
▸ 3 (Pre-Implementation Verification — Invariants · IS/IS NOT · YAGNI Master · Open Question Register)
▸ 4 (Impact Pre-Check — blast radius, conditional)
EXECUTE → 5 (Read-before-edit + Anchored Edit + Style Match + Diff-Budget Watch)
VERIFY → 6 (Verifier-Guided Self-Refinement Loop — run → on FAIL revise → rerun, max 3)
▸ 7 (Cross-File Consistency — multi-file only)
▸ 8 (Semantic Diff Guard + Mutation Challenge + Backward-Compat Check)
REPORT → 9 (Final Verification — CHAT ONLY)
▸ 10 (Save FIX / IMPL-EXEC report — optional, on user request)
▸ 11 (Reflexion Lesson — FAIL-only)| Mode | Trigger | Output |
|---|---|---|
| IMPLEMENT | IMP-.md OR PLAN-.md + TASK-NN OR freeform task / Jira without RCA | Source edits per IMP §6.2 / Plan TASK Outputs; optional IMPL-EXEC report |
| FIX | RCA-*.md OR pasted RCA content with §4.3 Root Cause + §7.1 Primary Fix | Source edits per RCA §7.1 PRIMARY ONLY (§7.2 NEVER without explicit user request); optional FIX report |
| Sub-mode | Trigger | Effect |
|---|---|---|
| LITE | Tier 1–2, 1–2 files, 1 layer, no schema/config | Inline checkpoint; lighter verification (lint + 1 test); no async subagents |
| FULL | Tier 2+ with 3+ files OR new endpoint OR schema/config OR irreversible op | Full Phase 4 impact pre-check; full Phase 6 self-refinement loop; Phase 8 mutation challenge MANDATORY; async subagents per CLAUDE.md §14 for multi-layer |
When in doubt → FULL. Security boundary / irreversible ⇒ auto Tier 3 / FULL. Tier 0 single-line typos do NOT use this skill — implement directly (CLAUDE.md §3).
| Step | Action |
|---|---|
| 0.1 Path discovery | Glob("**/Domain_Glossary.md") → DOCS_ROOT (parent of containing dir); Glob("**/LOCAL-MEMORY") → OUTPUT_ROOT. Forward slashes; absolute. Record in §4 Checkpoint header on first session response. |
| 0.2 Param validation | Empty input ⇒ exit. Single param + .md exists → READ + classify per §3.1. Two params (path + TASK-\d+) → PLAN MODE. Jira [A-Z]{2,10}-\d+ → fetch via Atlassian MCP, treat as freeform. |
| 0.3 Reflexion lessons | Glob("**/LESSONS/*.md") over OUTPUT_ROOT; filter by topic / related_failure_modes; load top 3 (CLAUDE.md §13). |
0.4 Architecture Pre-Read (MANDATORY when 3+ layers OR Core/ / BO/ / security boundary) | Read context/01_Solution_Overview/Project_Overview.md; Read context/03_Projects/{ProjectName}.md when applicable. Record: layer-boundary the data crosses · governing F/B/D-XXX patterns · invariants. Skipping ⇒ INVALID. |
| 0.5 STOP rules | Max 15 files read for context. Soft cap 75 % context window before Phase 9; at 95 % (CLAUDE.md P0 #11) ⇒ STOP, instruct user to resume from LOCAL-MEMORY/CURRENT_TASK/state-{ts}.md in fresh session. |
IF input matches IMP-*.md OR has "## Implementation Blueprint" / "## Approach / Files Table / Steps":
→ MODE = IMPLEMENT (sub-mode: ANALYSIS-from-IMP)
ELIF input matches PLAN-*.md AND TASK-NN provided:
→ MODE = IMPLEMENT (sub-mode: PLAN+TASK)
ELIF input matches RCA-*.md OR contains §4.3 Root Cause + §7.1 Primary Fix:
→ MODE = FIX
ELIF freeform task / Jira / "implement X" without IMP/RCA:
→ STOP; propose: "No Contract source detected. Run `implementation-blueprint` (feature)
or `root-cause-analysis` (bug) FIRST so I have a falsifiable contract to execute against."
→ User MAY override with @quick — see §5.IMPLEMENT — from IMP: Files Table (§6.2) · Steps (§6.3) with req_id per AC · Blueprint Contract MUST/MUST NOT (§6.7) · Diff Budget cap (§6.7) · Out of Scope (§6.9) · Reproducing Test Sketch (§6.6, when present) · Security checklist (§6.10).
IMPLEMENT — from PLAN+TASK: Task What · Where · Inputs · Outputs · Verify · Depends On · Implements (REQ-IDs / Jira IDs).
IMPLEMENT — from freeform (only after user override): Treat user message as Contract; restate it back; ASK-USER confirm before Phase 5.
FIX — from RCA: §4.3 Root Cause Statement · §4.3 Location (file:line regex ^[a-zA-Z0-9_/\\.-]+\.(cs|ts|tsx|js|jsx|sql|json|xml|config):\d+(-\d+)?$) · §7.1 PRIMARY Fix (What / Where / How) · §7.1 Code Before/After or §Appendix B · Confidence · Risk Level. §7.2 Additional Recommendations NEVER implemented in FIX mode unless user explicitly requests.
For each inputs_consumed entry in Contract YAML frontmatter (CLAUDE.md §9):
Read cited file:line THIS turn.sha256_at_creation (or mtime fallback).state field — MUST be verified (or explicit override).For EACH file in Contract Where / Files to Modify / RCA §7.1 Where:
Read file at specified lines THIS turn (CLAUDE.md P0 #1).⚠️ Lines shifted in <file>. Expected line X, found at Y. Adjusting. Update line refs.Contract vague ("update the service", "fix the validation") ⇒ pick the smallest interpretation that satisfies the literal text — NEVER the richest (CLAUDE.md P0 #4). Document alternative interpretations as Open Questions; do NOT silently expand scope. Richest interpretation = YAGNI breach ⇒ INVALID.
⛔ GATE 1: Mode classified? Contract source cited? Fingerprint check executed (when applicable)? Stale-Context check executed for EVERY target file? Conservative-Reading applied for any vague Contract item? Every Step / Output / RCA §7.1 line resolves to a concrete `file:line`? Vague execute-time targets ("modify the service", "fix the validation", "update the mapper") ⇒ FORBIDDEN — Conservative-Reading applies to vague acceptance criteria during planning, NOT to vague file targets during execution. Vague target ⇒ STOP, treat Contract as incomplete, escalate: Contract step <N> lacks file:line. Cannot guess-edit. Rerun upstream skill or specify target.
Output the §4.2 Tier 2 Checkpoint (or §4.3 Tier 3 if Reversibility=irreversible / migration / financial calc / prod config / security boundary). Field order = reasoning order; conclusion / code MUST appear AFTER all reasoning fields (CLAUDE.md §4.0).
Mode-specific extensions (inline rows of the §4 Checkpoint, NOT separate blocks):
**Contract source**: IMP path | PLAN path + TASK-NN | RCA path | freeform-with-override
**Mode**: IMPLEMENT (ANALYSIS-from-IMP | PLAN+TASK | freeform) | FIX
**Sub-mode**: LITE | FULL
**Diff Budget**: <planned_lines from Contract> · <max = ceil(1.5 ×)>
**Stale-Context Status**: ✅ Verified / ⚠️ Shifted (adjusted) / ❌ Drifted (ASK USER)
**Security Touch**: yes / no — if yes, authorization scope check point: <file:line>Tier 3 promotion triggers (CLAUDE.md §3): irreversible op (DB migration / deletion / prod config / financial calc), security boundary, schema change, public-API contract change, new endpoint. Tier 3 ⇒ Reversibility=irreversible header + Two-Stage Confirm (**Two-Stage Confirm:** required) + Multi-Agent Vote (k=3) + Architectural Decision Plan after solution.
⛔ GATE 2: §4 Checkpoint emitted as first visible block? §4.6 quality gates pass (Intent + Docs Read with file:line + Glossary Hit table + Refuter for HIGH+ + Killer Hypothesis + Self-Check)? Confidence on the plan declared BEFORE any code? No cargo-cult labels (Technique=CoT, anti-pattern pass=Y)? No ASCII-box decoration (═══)?
Multi-step / uncertain ⇒ MUST output Plan-and-Solve outline (2–5 sub-steps) before acting (CLAUDE.md §6).
IMPLEMENT — Pre-Implementation Plan (ALL must be YES):
req_id is covered by ≥ 1 Step (no orphan AC).Glob pattern file under DOCS_ROOT/07_Code_Patterns/).file:line of working similar implementation in same layer.FIX — Pre-Fix Invariants (ALL must be YES):
Trigger → A → B → ROOT → Error; confirmed ROOT not symptom.Trigger → A → B → FIX → Correct Behavior; chain-break point identified.Output a short Pre-Implementation Proof (IMPLEMENT) or Pre-Fix Understanding Proof (FIX) — table form, ≤ 12 lines. End with Final Answer: Proceed | STOP — <one-line reason>. Skipping ⇒ INVALID.
| Dim | IS (will change) | IS NOT (could be but isn't) | Distinction |
|---|---|---|---|
| WHAT | … | … | … |
| WHERE | … | … | … |
| EXTENT | … | … | … |
≥ 2 IS NOT rows MANDATORY. Cannot fill 2 ⇒ Contract scope unclear → STOP, ASK USER.
| YC-# | Check |
|---|---|
| YC-1 | Every change produces an item in Contract Outputs / Steps / RCA §7.1 |
| YC-2 | No file modified outside Contract Where / Files Table |
| YC-3 | Every changed line traces to a req_id (IMPLEMENT) or RCA §7.1 (FIX) |
| YC-4 | Code is the MINIMUM that satisfies the requirement |
| YC-5 | Existing pattern (F/B/D-XXX) used; NO reinvented abstraction |
| YC-6 | Could remove any line and still pass Verify? Then remove it |
| YC-7 | NO "while I'm here" additions |
| YC-8 | NO speculative error handling / null checks beyond Contract |
| YC-9 | NO unrelated refactor / formatting / import re-order |
| YC-10 | NO features outside the Contract |
| YC-11 | NO single-use abstractions (interface for one impl, helper for one call) |
| YC-12 | NO comments explaining obvious code |
ANY ❌ ⇒ STOP; remove the extra; reverify.
| # | Falsifier (concrete observation) | Where it would appear (file:line / test / config / trace) | Resolution path | Severity |
|---|---|---|---|---|
| 1 | <falsifier statement> | <file:line> | re-read · spawn Agent · ASK USER | H/M/L |
| 2 | <falsifier statement> | <file:line> | re-read · spawn Agent · ASK USER | H/M/L |
Rules: ≥ 2 rows for HIGH+ on Tier 2+. Tier 3 ⇒ ≥ 1 row MUST cite ASK-USER resolution path. < 2 rows ⇒ DOWNGRADE confidence one level. All entries MUST be falsifiers (would force retraction), NOT supporting evidence rephrased.
⛔ GATE 3: Pre-Implementation Plan / Pre-Fix Invariants ALL YES? IS / IS NOT (≥ 2 IS NOT)? YAGNI Master Checklist all ✅? Open Question Register filled (HIGH+ only)? Authorization scope verified for every data-access edit?
Trigger (any one): file in {YOUR_DOMAIN_LAYER}/ / Core/ / Services/ · 6+ planned lines · 2+ files · 2+ direct dependencies · Contract Confidence MEDIUM/LOW · FIX with §7.1 confidence ≠ HIGH.
Action (load code-analysis skill — see §14):
white-box-trace REAL Phase 5R forward slice; confirm exact affected statements; flag unintended propagation.IS NOT + Contract §6.9) is NOT touched by transitive impact.⛔ GATE 4 (when triggered): blast radius computed? Risk band assigned? Forward slice executed (if Risk ≥ MEDIUM)? Out of Scope verified untouched? HIGH band → user confirmation received?
Edit / Write callFOR EACH file in Contract Where (one file at a time, complete-then-next):
1. Read target file at specified lines THIS turn (Hard rule 2).
↳ MULTI-EDIT-SAME-FILE rule: every prior `Edit` on this file shifted line numbers.
Before EACH subsequent edit on the same file, `Read` AGAIN at the new expected
line range. Cached-from-first-Read line numbers are FORBIDDEN once any Edit
has landed in the file this session. Stale anchors on follow-up edits = #1
cause of cascading patch failures (FM-2).
2. Verify surrounding context (±10 lines) matches Contract expectations.
↳ Drifted ⇒ adapt or report blocked (Phase 1 stale check should have caught — re-run if not).
3. Identify EXACT edit point by matching ≥ 3 surrounding lines.
4. Quote the 3-line anchor in `old_string` (Edit tool) — NEVER use only the target line.
4.5 SYMBOL EXISTENCE GATE (Hard rule 17, FM-2 / FM-14).
For every NEW external symbol this edit introduces (method call · class · interface
· attribute · constant · namespace · `using` / `import`) that is NOT visible inside
the 3-line anchor:
a. `Grep` for the symbol's declaration pattern (per `reference.md` §5
AST-aware grep: `class <X>`, `interface I<X>`, `void.*<X>`, etc.).
b. Verify SIGNATURE matches the call site (param count, return type, access).
c. Found + signature matches ⇒ proceed to step 5.
d. Found but signature differs ⇒ STOP; "Symbol exists but signature differs from
Contract"; ASK USER (Contract may be stale).
e. Not found AND Contract claimed it exists ⇒ STOP; "Contract symbol hallucinated:
<symbol>"; ASK USER (rerun upstream skill).
f. Not found AND it's a NEW symbol authorized by Contract (e.g. IMP §6.3 Step says
"Add new method `Foo`") ⇒ confirmed by Contract; proceed.
For external libs / package manager deps: CLAUDE.md P0 #14 dep-verify
(e.g. `npm ls` / `pip show` / your package manager) instead of repo Grep.
5. Apply Edit / Write with anchored `old_string` (3–5 lines before + target + 3–5 lines after).
6. IMMEDIATELY verify: syntax, imports, types, pattern compliance, style match.
7. Run targeted lint (if applicable) — see §8.
8. ✅ Pass ⇒ next file (OR next edit on same file → restart at step 1 with fresh `Read`).
❌ Fail ⇒ §7.4 Error Recovery.Match existing code style in target file: indentation (tabs vs spaces, width), brace placement, naming convention, language version. `{LANG_VERSION}` only in this codebase (CLAUDE.md P0 #6) — {LANG_SPECIFIC_SYNTAX}. Unsure ⇒ use older, more explicit syntax. Match-not-perfect ⇒ revert to surrounding style even if you would do it differently.
IF actual_diff > 1.5 × planned_lines:
→ STOP: "⚠️ Implementation exceeds Contract estimate.
Planned: ~N lines. Actual: ~M lines. Likely YAGNI breach OR Contract underspecified.
Review changes for scope creep; revert orthogonal damage; OR rerun upstream skill."| Task size | Expected diff | If exceeded |
|---|---|---|
| S (1–30 LOC plan) | 1–30 lines | ✅ on track |
| M (30–100 LOC) | 30–100 lines | ✅ on track |
| L (100–300 LOC) | 100–300 lines | ⚠️ check YAGNI; consider splitting |
| Any | > 1.5× plan | ⛔ STOP — Contract drift suspected |
CLAUDE.md §10 absolute ceilings still apply (≥ 100 lines = REFUSE; rerun upstream).
Edit failuresIF Edit fails (old_string not found):
STEP 1: `Read` target file again (context may have shifted since Phase 1).
STEP 2: Search ±50 lines around expected location with Grep (≥ 3-line anchor pattern).
STEP 3: Found at different line ⇒ adjust old_string with new surrounding context; retry.
STEP 4: Not found at all ⇒ "⚠️ Expected code not found in <file:line>. Possible cause:
file changed since Contract created; prior step modified this area."
Report BLOCKED; ASK USER.
STEP 5: old_string non-unique ⇒ expand anchor to 7–10 lines; retry.
MAX RETRIES: 3 per edit. After 3 ⇒ STOP, report blocked.Where / Files Table.Outputs / Steps / §7.1.[N/M] files modified before block; do NOT auto-revert; ASK USER.⚠️ Found issue in <file:line>: <desc> and continue.Triggers (any one fires the gate):
git push --force / branch reset · package removal · production-script run).@quick mode user override on what would otherwise be Tier 3 ⇒ STILL fires; CLAUDE.md §5 forbids @quick from bypassing irreversibility.Gate output (verbatim format — DO NOT paraphrase):
About to <verb> <target> — effect: <one sentence>; reversibility: <none | partial via X | reversible via Y>. Confirm Y to proceed; any other reply stops.
Wait for explicit `Y`. Any other reply (including silence, "ok", "go ahead", "looks good") ⇒ STOP, do not apply.
Gate fires BEFORE the first triggering tool call. A single Y covers a contiguous batch of edits described in the prompt; a NEW triggering op (different table, different prod system, different financial path) ⇒ NEW gate. Gate state is per-action, not per-session — one approval ≠ blanket approval.
⛔ GATE 5: Each edit anchored ≥ 3 lines? Style match per file? Diff Budget watched? Error Recovery executed for any failures? STOP-triggers honoured? Two-Stage Confirm fired and `Y` received before the first triggering Edit/Write/Bash (when applicable)?
Highest-leverage rule: run code, observe reality, refine on FAIL beats imagine code, declare done.
| Priority | Artefact | When | Tool |
|---|---|---|---|
| 1 | Repro Kernel (CLAUDE.md §12) | FIX mode + RCA had repro; IMPLEMENT mode + IMP §6.6 Reproducing Test Sketch | Bash runs the script / test ID; expect FAIL before, PASS after |
| 2 | Targeted unit / integration test | Contract Verify cites tests; or existing tests cover changed methods | {YOUR_TEST_COMMAND} |
| 3 | Build + lint | Compiled languages; types matter | language build tool / linter |
| 4 | Static-only re-read + Grep evidence | Runtime infeasible (deploy-only, manual UI) | Read modified file; Grep for the change at the right file:line |
| 5 | Manual test plan | UI-only, no automation feasible | Cite exact steps + expected vs observed; user runs and reports back |
Forbidden (FM-2 / FM-20): "should compile", "looks correct", "code reaches the line", "trust me".
Trigger (any one):
Core/ / BO/ / Services/ / shared interface / base class.white-box-trace REAL Phase 5R forward slice was invoked at Phase 4.Action: targeted unit test (priority 1–2) is NOT enough. Run additionally:
| Layer | Command | Why |
|---|---|---|
| Project-level test suite | {YOUR_TEST_COMMAND} (one project, not whole solution) | Catches FM-18 hidden coupling in same-project tests not directly named in Contract |
| Forward-slice tests | For each dependent symbol surfaced by white-box-trace forward slice — locate its test (Grep "<DependentSymbol>" --include='*Test*') and run | Catches transitive impact (CLAUDE.md §6.1 Slice-Based Downstream Count) |
| Regression integration test (Tier 3 only) | {YOUR_TEST_COMMAND} (integration category) | Catches cross-project coupling on shared-interface changes |
Verdict logic:
executed: false_with_reason: <specific>; downgrade aggregate confidence to MEDIUM; cite the sweep command in the report so the developer runs it post-merge.Anti-cheat: narrowing test filter to skip the broader sweep = FM-18→FM-20 (verifier-claimed-not-run). Run honestly OR mark executed: false_with_reason. Silent skip ⇒ INVALID.
attempt = 1
WHILE attempt ≤ 3:
1. Run verification artefact (priority 1 → 5).
2. Capture transcript (paste in Phase 9 OR cite absolute path under OUTPUT_ROOT/CURRENT_TASK/verify-{ts}.log).
3. PASS ⇒ goto 8.3 Mutation Challenge.
4. FAIL ⇒ analyze failure cause:
a. My code is wrong ⇒ revise ONLY the failing edit (no scope expansion); reapply per §7.1; attempt++.
b. Test is wrong ⇒ DO NOT modify test (Hard rule 14). Re-read RCA / IMP; if test contradicts
Contract, ASK USER. Most likely: my code is wrong and the test is correct.
c. Environment / dependency issue ⇒ diagnose; do NOT silently skip the test.
d. Repro Kernel passes UNCHANGED (no FAIL before fix) ⇒ RCA was wrong; STOP, escalate to user.
5. attempt++
attempt > 3 ⇒ STOP, report:
"⚠️ Verifier-Guided Self-Refinement exhausted (3 attempts).
Likely Contract is wrong, root cause misidentified, or hidden coupling.
Recommend: rerun root-cause-analysis OR implementation-blueprint with broader scope.
Last failure: <transcript>."Loop discipline (FM-9 self-correction illusion): each iteration MUST quote the failing line / assertion AND state the specific code change. "I tweaked things" is not an iteration ⇒ INVALID.
For every load-bearing claim of "the fix works":
white-box-trace REAL Phase 5R live-mutation testing; confirm mutant is killed.If any signature, schema, or external contract changed (Contract MUST authorize this; else Hard rule 7 violated):
context/... migration pattern.⛔ GATE 6: Verification artefact RUN this turn (not "would run") OR executed: false_with_reason honestly stated? Transcript present in chat OR path cited? Self-refinement loop respected (max 3, no test mutation)? Mutation Challenge applied (FULL mode)? Backward-compat checked (when applicable)? Risk-Tier Regression Sweep executed (when triggered)?
For each pair of modified files that interact:
| File Pair | Check | Status |
|---|---|---|
| A ↔ B | Method signatures match definition vs usage | ✅/❌ |
| A ↔ B | Imports / using added where needed | ✅/❌ |
| A ↔ B | Type names consistent | ✅/❌ |
| A ↔ B | No circular dependency introduced | ✅/❌ |
❌ ⇒ fix immediately within scope (still bound by Hard rule 3); rerun §8.
⛔ GATE 7: For multi-file edits — every interacting pair checked? Inconsistencies fixed and re-verified?
Read each modified file's diff (or git diff <file>). Classify each change:
| Change Type | Allowed? | Rule |
|---|---|---|
| Bug behaviour fixed (FIX mode) | ✅ Required | RCA §7.1 |
| Contract Output / Step delivered (IMPLEMENT mode) | ✅ Required | IMP §6.3 |
| Method signature change | ❌ Forbidden | unless in Contract |
| Public API / interface contract | ❌ Forbidden | unless in Contract |
| Class / interface definition | ❌ Forbidden | unless in Contract |
| Database schema | ❌ Forbidden | unless in Contract; auto Tier 3 |
| Config file | ❌ Forbidden | unless in Contract |
| Logging statement add/remove | ❌ Forbidden | unless in Contract |
| Comment edit (add / remove / rephrase) | ❌ Forbidden | unless in Contract |
| Error-message rewording | ❌ Forbidden | unless bug-related and in Contract |
| Formatting / whitespace / line-ending | ❌ Forbidden | always |
Import / using re-ordering | ❌ Forbidden | always |
| Variable rename in untouched code | ❌ Forbidden | always |
Forbidden ❌ found and not authorized ⇒ REVERT before sending (CLAUDE.md §7 Semantic Diff Guard). Not reverted ⇒ INVALID.
⛔ GATE 8: Every changed line classified? Forbidden types either authorized by Contract or REVERTED?
Output the verification block in chat. MUST NOT appear in any saved report. Apply CLAUDE.md §11 Pre-Send Checklist + §11.9 Contradiction Detector (seven types).
---
## 🔍 Final Verification (Chat Only — Not Saved to File)
---
### Stale-Context Status
| File | Context Match | Notes |
|------|---------------|-------|
| <path> | ✅ Verified / ⚠️ Shifted (adjusted) / ❌ Drifted | <details> |
### Pre-Implementation / Pre-Fix Invariants
| Invariant | Status |
|-----------|:------:|
| Contract source cited | ✅/❌ |
| Fingerprint check passed | ✅/❌/N-A |
| Pattern verified vs repo | ✅/❌ |
| Authorization scope verified | ✅/❌/N-A |
### Contract Delivery
| Output / Step / §7.1 line | Status | Evidence (`file:line`) |
|---------------------------|:------:|-------------------------|
| <item> | ✅/❌ | <…> |
### YAGNI Audit (Master Checklist YC-1..YC-12)
| YC-# | Status |
|:----:|:------:|
| 1..12 | ✅/❌ |
**YAGNI Compliance**: ✅ PASS / ❌ FAIL (ANY ❌ = FAIL → revert)
### Cross-File Consistency (multi-file)
| File Pair | Signatures | Imports | Types | Status |
|-----------|:----------:|:-------:|:-----:|:------:|
### Semantic Diff Guard
| Forbidden Type | Present? | Authorized? |
|----------------|:--------:|:-----------:|
| Method signature / public API / schema / config / formatting / imports / comments / logging | ❌ | n/a |
### Diff-Budget Status
| Planned | Actual | Ratio | Within 1.5×? |
|--------:|-------:|------:|:------------:|
| N | M | M/N | ✅/❌ |
### Verification Loop (P0 #16)
| Artefact | Executed? | Result | Transcript |
|----------|:---------:|--------|-----------|
| <Repro Kernel / test / build / re-read+grep / manual plan> | ✅/❌ + reason | PASS/FAIL | inline OR `<path>` |
### Mutation Challenge (FULL mode)
| Claim | Discriminating? | Notes |
|-------|:---------------:|-------|
| <claim> | ✅/❌ | <reason> |
### Adversarial Self-Check (3 questions)
| # | Question | Answer |
|:-:|----------|--------|
| 1 | How could I misunderstand this Contract? | <1–2 alt interpretations> |
| 2 | What would a senior reviewer flag? | <1–2 concerns> |
| 3 | If this breaks in production, most likely cause? | <failure mode> |
### Improvement Hypotheses (5+)
| # | Hypothesis | Keep/Reject | Reason |
|:-:|------------|:-----------:|--------|
| H1 | <hypothesis> | Reject | YAGNI — not in Contract |
| H2..H5 | … | … | … |
### Contradiction Detector (CLAUDE.md §11.9 — seven types)
| Type | Triggered? | Action |
|------|:----------:|--------|
| Say-vs-Do (claimed pattern vs actual code) | ✅/❌ | <fix or N-A> |
| YAGNI breach (minimal claimed but extras shipped) | ✅/❌ | <…> |
| Unverified-as-fact (no `file:line`) | ✅/❌ | <…> |
| Complexity vs LOC (simple claimed but > 100 lines) | ✅/❌ | <…> |
| Confidence vs Evidence (HIGH on WEAK or no Refuter) | ✅/❌ | <…> |
| Contract drift (fingerprint mismatch unaddressed) | ✅/❌ | <…> |
| Verifier-claimed-not-run (P0 #16 violation) | ✅/❌ | <…> |
**Any ✅ ⇒ FIX before sending.**
### Self-Verification Checklist
- [ ] §4 Checkpoint emitted FIRST (P0 #15)
- [ ] Contract source cited; fingerprint check (when applicable)
- [ ] Stale-Context check executed for every target file
- [ ] Pre-Implementation Plan / Pre-Fix Invariants ALL YES
- [ ] IS / IS NOT (≥ 2 IS NOT)
- [ ] YAGNI Master Checklist (YC-1..YC-12) all ✅
- [ ] Open Question Register filled (HIGH+ on Tier 2+)
- [ ] All edits anchored ≥ 3 lines; style matches surrounding code
- [ ] **Symbol Existence Gate fired for every NEW external symbol introduced (Hard rule 17 / §7.1 step 4.5)**
- [ ] **Fresh `Read` before EACH subsequent edit on the same file (§7.1 step 1 multi-edit rule)**
- [ ] **Two-Stage Confirm `Y` received before any irreversible Edit/Write/Bash (Hard rule 16 / §7.6)**
- [ ] **Risk-Tier Regression Sweep executed (or honestly marked non-executable) when triggered (§8.1.5)**
- [ ] **No vague-target edits — every executed step had concrete `file:line` (§3 GATE 1)**
- [ ] Diff Budget within 1.5× planned
- [ ] Cross-File Consistency (multi-file)
- [ ] Semantic Diff Guard (no orthogonal damage)
- [ ] Verification Loop RUN this turn — transcript or path cited (P0 #16)
- [ ] Mutation Challenge (FULL)
- [ ] Backward-Compat (when public API / schema / config)
- [ ] Authorization scope verified end-to-end
- [ ] `{LANG_VERSION}` syntax only (CLAUDE.md P0 #6)
- [ ] No test modified (P0 #13)
- [ ] **In one sentence:** [what was delivered]
- [ ] **Contract items:** [list]; **Implemented:** [Y/N per item]
---ANY unchecked / ❌ ⇒ INVALID DELIVERABLE → REDO.
This run refutes any prior IMP / RCA / earlier IMPL-EXEC ⇒ surface as first-class block:
Disagreement with upstream artifact `<path>`:<their claim>vs<my finding>; rationale:<one paragraph>; recommended action: rerun upstream OR proceed with override + log dissent.
⛔ GATE 9: Final Verification block in chat? Self-Verification Checklist ALL ✅? Contradiction Detector clean? Disagreement-with-upstream surfaced (when applicable)?
Reports are NOT auto-saved. Default: edits applied + chat verification + done. Save report only when user asks ("save the fix report", "create IMPL-EXEC artefact").
When saving, use report-template.md. Path:
OUTPUT_ROOT/{BUG-<id>-<slug>|CURRENT_TASK}/FIX-YYYYMMDD-HHmm-<slug>.mdOUTPUT_ROOT/{STORY-<id>-<slug>|CURRENT_TASK}/IMPL-EXEC-YYYYMMDD-HHmm-<slug>.mdYAML frontmatter (CLAUDE.md §9, MANDATORY):
---
artifact_type: FIX | IMPL-EXEC
producer: claude-code
state: draft | verified | superseded
parent_artifact: <RCA / IMP / PLAN path>
inputs_consumed:
- path: <src/path/to/file.ext>
line_range: <40-60>
sha256_at_creation: <hash-or-mtime>
fingerprint: <sha256 over inputs_consumed>
created: <ISO-8601 UTC>
tier: 2|3
mode: IMPLEMENT | FIX
sub_mode: LITE | FULL
diff_budget_planned: <N>
diff_budget_actual: <M>
targets_failure_modes: [FM-2, FM-5, FM-9, FM-16, FM-18, FM-19, FM-20]
verification:
command: "<exact command>"
expected: "<exact expected output>"
transcript_path: <OUTPUT_ROOT>/CURRENT_TASK/verify-{ts}.log
executed: true | false_with_reason
lessons_loaded: [<paths>]
---Hard rule 13: Phase 9 verification block MUST NOT be inside the saved report.
Trigger: any FAIL verdict, blocked Gate, contradiction resolved, or revision cycle on Tier 2+ (CLAUDE.md §13). Real-time trigger: user correction in this session ⇒ propose lesson update in same response.
Write OUTPUT_ROOT/LESSONS/{YYYY-MM-DD}-{topic}.md with frontmatter:
---
artifact_type: LESSON
producer: claude-code
created: <ISO-8601>
related_failure_modes: [FM-N, FM-M]
target_artifact: <RCA / IMP / IMPL-EXEC / FIX path>
---
## What was tried
## Why it failed (root signal)
## What signal was missed
## One-line rule for next timeOn Tier 2+ task start, scan LESSONS/ for matching topic / FM tags; load top 3.
| Situation | Action |
|---|---|
| Codebase / file search | codebase-search-protocol skill — CLASSIFY → LOCATE → FILTER → SCAN → EXPAND. Implementation profile: stop when target + similar example found; max 10 files. |
| Layer-by-layer analysis, blast radius | code-analysis skill ("what to document"); Phase 4 trigger. |
| Forward slice / live mutation when Risk ≥ MEDIUM or downstream ≥ 3 | .claude/skills/white-box-trace/ REAL Phase 5R forward slice; mutation testing. |
| Vague Contract item (Phase 1 §3.5 Conservative-Reading) | requirements-analysis skill (Plan-and-Solve + EARS + GWT). |
| Reasoning trigger | reasoning skill (Plan-and-Solve / ToT / CoVe). Use "Verify your reasoning", NEVER "Find all your mistakes" (over-correction). |
| Mermaid diagrams (when Contract requires) | mermaid-diagrams skill — validation checklist before emit. |
| Jira / Confluence | Atlassian MCP (mcp__claude_ai_Atlassian__*). |
| External lib / CVE / framework version (CLAUDE.md P0 #14) | WebSearch then WebFetch known URL — ◆◆○ MODERATE; cite source URL. |
| Multi-layer (≥ 3 layers) investigation | Agent (subagent_type: Explore) per layer cluster; main agent writes (CLAUDE.md §14). NEVER spawn parallel writers. |
| Self-falsify completed implementation | .claude/skills/white-box-trace/ REAL mode (/trace.real). |
| Falsify a Contract before executing it | .claude/skills/white-box-trace/ VIRTUAL mode (/trace.virtual) — escalate to user before proceeding. |
| Consuming an existing RCA | .claude/skills/root-cause-analysis/ — read RCA, fingerprint-check inputs_consumed, extract §7.1 PRIMARY only. |
| Consuming an existing IMP | .claude/skills/implementation-blueprint/ — read IMP, fingerprint-check inputs_consumed, extract §6.2 / §6.3 / §6.7 Blueprint Contract. |
| ❌ FORBIDDEN | ✅ REQUIRED |
|---|---|
| Edit without Contract source | STOP; instruct user to run upstream skill |
Edit from memory / cache without Read this turn | Read target file at line range THIS turn (Hard rule 2) |
Use only target line as old_string | Anchor with 3–5 lines before + after |
{POST_LANG_VERSION} syntax ({LANG_SPECIFIC_SYNTAX}) | {LANG_VERSION} only (CLAUDE.md P0 #6) |
| "While I'm here" reformat / refactor / rename | Surgical: only Contract items |
| Add null checks / try-catch / logging beyond Contract | Add ONLY what Contract authorizes |
| Create helper class / interface for one use | Inline; reuse existing pattern |
| Modify a test to make it pass | Fix the code (Hard rule 14) |
| Implement RCA §7.2 in FIX mode | §7.1 PRIMARY only; §7.2 = separate user request |
| Skip Stale-Context check | Read target file THIS turn; compare vs Contract snippet |
| "Should compile" / "looks correct" / "code reaches the line" as evidence | Run a verification artefact; paste transcript or path |
| Modify test to silence FAIL | Hard rule 14; fix the code or ASK USER |
| Self-refinement loop > 3 iterations | STOP at 3; rerun upstream skill |
| Save Phase 9 verification inside the report | CHAT ONLY (Hard rule 13) |
| Edit two files concurrently in parallel writes | Complete-then-next; sequential writes |
| Spawn parallel writer subagents | Subagents READ; main agent WRITES (CLAUDE.md §14) |
| Reference a method / class / namespace not in repo, trusting Contract names verbatim | Symbol Existence Gate (Hard rule 17, §7.1 step 4.5) — Grep to confirm before edit |
Re-use the line numbers from first Read for a 2nd / 3rd edit on the same file | Re-Read before EACH edit on the same file (§7.1 step 1) |
Run irreversible op without explicit Y confirmation | Two-Stage Confirm Gate (Hard rule 16, §7.6) — verbatim prompt, wait for Y |
| Stop verification at the targeted unit test on Risk ≥ MEDIUM / multi-file / shared interface | Risk-Tier Regression Sweep (§8.1.5) — project-level + forward-slice tests |
Guess-edit on a Contract step that lacks file:line | Vague-Targets Hard Stop (§3 GATE 1) — escalate to user, rerun upstream |
| Trust ticket framing ("trivial fix", "5 min job") | Sycophancy guard (CLAUDE.md §11.11) — judge on evidence |
| "Verified via mutation tool" without tool result this turn | Action-execution honesty (Hard rule 12); run it OR **ASSUMPTION**: |
| Fabricate root cause / fix when Contract is incomplete | Inconclusive (Hard rule 15); escalate to user |
| Edit > 95 % context window | STOP; save state; resume in fresh session (CLAUDE.md P0 #11) |
implementation-blueprint.root-cause-analysis./review.white-box-trace REAL.white-box-trace VIRTUAL.| FM | Trigger | Recovery (MANDATORY) |
|---|---|---|
| FM-A Stale Contract (RCA / IMP) | Fingerprint mismatch OR target file content drifted significantly | STOP; report drift; require user to rerun upstream OR explicit override with risk acknowledgement. |
FM-B Hallucinated file:line in Contract | Cited file:line does not exist or out of range | Re-Read; downgrade to **ASSUMPTION**:; if drops to LOW ⇒ STOP. |
| FM-C Forbidden semantic-diff slipped through | §10 detected reformat / import re-order / comment edit not authorized | REVERT same turn; rerun §8 verification; surface in §11 Self-Check. |
| FM-D Verifier-claimed-not-run (FM-20 / P0 #16) | "Tested" with no transcript / no path / fabricated executed: false_with_reason | Run verification THIS turn OR honestly mark executed: false_with_reason: <specific>; downgrade aggregate confidence to MEDIUM. |
| FM-E Self-refinement loop oscillation | 3 attempts, FAIL each, different failure each time | STOP; root cause likely deeper than Contract suggests; escalate to root-cause-analysis rerun. |
| FM-F Authorization leak | Data-access edit shipped without authorization scope check | REVERT immediately; auto-promote to Tier 3; ASK USER even if originally Tier 2. |
| FM-G Diff-Budget exceeded | actual_diff > 1.5 × planned_lines | STOP; bisect orthogonal damage; revert non-Contract changes; pure Contract overflow ⇒ rerun upstream skill. |
| FM-H Test mutated to silence FAIL | Modified test instead of code | REVERT test; fix code; surface in §11 Self-Check + LESSONS entry. |
| FM-I Sycophancy on user pushback | "But the user said it's a quick fix" | Re-anchor on evidence (CLAUDE.md §11.11); agree only if ≥ 1 ◆◆◆ supports; otherwise restate concern with Refuter. |
| FM-J Action-execution dishonesty | "I ran the test" without preceding tool result | Re-prefix as **ASSUMPTION**:; perform action now; quote result; reassess. |
| FM-K Symbol hallucinated by Contract | Contract names a method / class not in repo | STOP per Hard rule 17; report Contract symbol hallucinated: <symbol>; ASK USER. |
| FM-L Stale anchor on follow-up edit | Cached line numbers from first Read used on 2nd / 3rd edit | Per §7.1 step 1 multi-edit rule: re-Read before EACH subsequent edit on same file. |
| FM-M Irreversible op shipped without Two-Stage Confirm | Hard rule 16 bypassed | If applied: surface in §11 Self-Check + LESSONS; if not yet applied: STOP, fire gate, wait for Y. |
CLAUDE.md — project doctrine. Read FIRST. P0 #1–17..claude/skills/implementation-blueprint/SKILL.md — sibling. IMPLEMENT mode consumes IMP as parent_artifact..claude/skills/root-cause-analysis/SKILL.md — sibling. FIX mode consumes RCA as parent_artifact..claude/skills/white-box-trace/SKILL.md — companion. REAL Phase 5R forward slice + mutation testing; VIRTUAL falsifies a Contract before executing..claude/skills/task-verification/SKILL.md · code-analysis/SKILL.md · requirements-analysis/SKILL.md · reasoning/SKILL.md · mermaid-diagrams/SKILL.md — verification, analysis, requirements, reasoning, diagrams.context/05_AI_Rules_And_Context/FAILURE-MODE-REGISTRY.md — FM tagging. Typical IMPL-EXEC / FIX coverage: FM-2, FM-5, FM-9, FM-16, FM-18, FM-19, FM-20.Tagline: Read before you edit. Anchor every change. Run before you claim. Surgical or not at all.
~30 seconds. Free. No account. Every finding cites a rule and a line of evidence.