agentleFS
teltringhamteltringham/sdd-plugin/skills/sdd-iterate/SKILL.md

sdd-iterate

Skill0 starsChanged 8 months agoMITView on GitHub

Runs the backpropagation workflow — traces bugs and manual fixes back to specs, suggests spec amendments, and optionally re-runs implementation from updated specs. The killer feature of SDD. Use when bugs are found, after manual code fixes, or when specs need hardening.

The file

Show its rules and text

We split this skill into the rules it gives an agent

23 rules. About 0 are common, 10 are distinctive, and 13 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈10

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 13

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Use the MCP tool sdd_backprop_analyze to scan recent git history:

    line 18
  2. Very specific:

    If $ARGUMENTS is a specific commit hash, analyze just that commit

    line 19
  3. Very specific:

    If $ARGUMENTS is "all", analyze all commits since the last spec-update commit

    line 20
  4. Very specific:

    If omitted, analyze commits since the most recent commit with an Attempt: trailer (last Ralph run)

    line 21
  5. Distinctive:

    If no candidates found, report "No backpropagation candidates.

    line 29
  6. Distinctive:

    Before drafting any new amendments, replay the existing regression corpus to confirm prior amendments still hold.

    line 50
  7. Very specific:

    Run the entry's minimal_repro.test_command

    line 53
  8. Very specific:

    If ANY entry fails, halt iterate: "Regression corpus is broken — entry bp-NNN no longer passes.

    line 55
  9. Very specific:

    Use MCP tool sdd_trace_artifact to walk the traceability chain:

    line 63
  10. Distinctive:

    Read the relevant spec sections

    line 65
  11. Very specific:

    Before presenting to user, optionally invoke the sdd-skeptic agent on the proposed amendment:

    line 94
  12. Very specific:

    Default: ON for omission and under-specification (most prone to over-fitting).

    line 98
  13. Distinctive:

    Critical: backpropagation is human-gated: Never auto-modify specs. Constitutional Article 2.

    line 123
  14. Distinctive:

    Add the new/modified requirement to the spec file

    line 128
  15. Distinctive:

    Add an entry to the spec's backpropagation log table

    line 130
  16. Very specific:

    Update context/impl/backprop-log.json (schema at ${CLAUDE_PLUGIN_ROOT}/templates/backprop/backprop-log.schema.json):

    line 138
  17. Distinctive:

    If the backpropagator recommended re-running implementation:

    line 183
  18. Distinctive:

    Ask the user: "Re-run implementation from updated spec to verify the fix emerges from specs alone?

    line 185
  19. Very specific:

    Run /sdd-implement on those stories

    line 189
  20. Very specific:

    If status == "complete", write the populated verification record and the derived verified_via_ralph: true to the entry.

    line 208
  21. Very specific:

    If implementation does not produce the fix from specs alone (regression corpus regresses or the trigger reproducer still fails), close with …

    line 209
  22. Distinctive:

    Every amendment carries a minimal reproducer and test command

    line 221
  23. Distinctive:

    Stop-the-line triggers if ≥3 amendments to one spec in one session

    line 228

≈ “Common” is an estimate: at least 1 in 5 of the 213,895 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

SDD Iterate (Backpropagation)

Trace bugs to specs. Fix specs. Regenerate.

Arguments

$ARGUMENTS — optional commit hash or "all" to analyze all recent manual fixes. If omitted, analyzes commits since the last Ralph run.

Process

1. Find backpropagation candidates

Use the MCP tool sdd_backprop_analyze to scan recent git history:

  • If $ARGUMENTS is a specific commit hash, analyze just that commit
  • If $ARGUMENTS is "all", analyze all commits since the last spec-update commit
  • If omitted, analyze commits since the most recent commit with an Attempt: trailer (last Ralph run)

The tool classifies each commit as:

  • ralph-generated — created by the Ralph loop (has Attempt: trailer) — skip
  • manual-fix — human or ad-hoc fix (message matches fix/bug/patch) — backprop candidate
  • spec-update — edits to context/specs/ — skip
  • infrastructure — everything else — skip

If no candidates found, report "No backpropagation candidates. All recent changes are spec-driven." and exit.

1.5 Cluster check (cumulative cross-session)

Before replaying the regression corpus or drafting any amendments, invoke the MCP tool sdd_cluster_check with default arguments. This is the cumulative methodology gate (per Phase 2.1 of spec-plugin-v1.md) — counts amendments by spec_updated across all time, not just this session, and is a strict superset of the per-session Step 7 gate below.

Read the response:

  • threshold_breach == "none": continue to Step 2.
  • threshold_breach == "warn": emit a methodology warning citing the breaching spec(s) and current count, then continue to Step 2. Recommended phrasing: "⚠ Methodology signal: spec {spec_updated} has accumulated {count} cumulative amendments. Consider whether further iteration is productive or whether a step-back to characterization is warranted."
  • threshold_breach == "hard-stop" AND override_active == false: HALT iterate. Refuse to proceed. Recommended phrasing: "⛔ Halted by cluster check: spec {spec_updated} has accumulated {count} cumulative amendments (threshold 5). Iteration cannot proceed without a recorded characterization plan. See spec-plugin-v1.md §2.6 (characterization story tag in sdd-plan) for plan creation; or §2.5 (interface-maturity gate in sdd-spec) for upstream context."
  • threshold_breach == "hard-stop" AND override_active == true: emit override notice — "Cluster check hard-stop overridden by characterization plan recorded for {spec_updated}" — and continue to Step 2.

Constitutional Article 2 still applies — never auto-modify specs. The hard-stop is a refusal to proceed with iteration, not a code-level exception.

A characterization plan is considered "recorded" for a spec if EITHER context/plans/characterization-{spec-slug}.md exists (where {spec-slug} is the spec_updated path's basename without extension), OR any prd.json story in spec/active/ has a tags array containing "characterization" and a parent_spec matching spec_updated. (§2.6 will codify a tighter convention later; this is a permissive OR for v1.0.0.)

Follow-up stories are not exempt (W2 interaction). Amendments triggered by follow-up stories (those with a non-null parent_story_id, generated by the orchestrator when sdd-evaluator or sdd-ux-validator failed on a specific criterion) DO count toward the parent spec's cumulative cluster count. sdd_cluster_check already counts cumulatively across all entries keyed by spec_updated; this note simply records that follow-up-derived amendments are not special-cased out. Do not modify the threshold logic — the cluster check correctly treats follow-up amendments the same as any other amendment to the same spec.

2. Replay the regression corpus FIRST

Before drafting any new amendments, replay the existing regression corpus to confirm prior amendments still hold. This is the held-out eval set discipline (Anthropic Demystifying Evals).

The log's root key is entries as of v1.0.0. Older projects may still have backpropagation_log as the root key — accept both during the migration window, prefer entries. For each entry in context/impl/backprop-log.json (with a minimal_repro block):

  1. Run the entry's minimal_repro.test_command
  2. Set regression_corpus_pass: true | false on that entry
  3. If ANY entry fails, halt iterate: "Regression corpus is broken — entry bp-NNN no longer passes. Fix that before introducing new amendments."

The simpler rule: every prior amendment's minimal-repro must continue to pass before any new amendment can land.

3. Trace each candidate

For each manual-fix commit:

  1. Use MCP tool sdd_trace_artifact to walk the traceability chain:
    • Changed files -> which STORY owns these files -> which SPEC requirements
  2. Read the relevant spec sections
  3. Construct the minimal reproducer — before invoking the backpropagator, identify the smallest input/state that reproduces the failure. This is iterate's first artifact, before any amendment. (Borrowed from property-based shrinking.)
  4. Invoke the sdd-backpropagator agent with:
    • The commit diff (git show {hash})
    • The minimal reproducer description and test command
    • The traced spec requirements
    • The spec file content

The backpropagator will produce:

  • Root cause classification (one of: ambiguity | omission | contradiction | under-specification | implementation-error | plan-gap | test-gap | infrastructure)
  • Action category: prevent (tighten AC) | detect (add observability/test) | mitigate (add recovery requirement) — borrowed from AWS COE
  • The missing constraint
  • A draft spec amendment

Framing discipline. Backpropagator must use "how, not why" framing (Allspaw, The Infinite Hows). Frame amendments as "what would have made this detectable" rather than "what should the spec have said". Counterfactual reasoning ("the spec should have said X") is hindsight bias dressed as analysis — it makes us feel productive without actually improving future detection.

3.5 Failed assertion → spec amendment (§2.9 / W10 discipline)

When a validator (sdd-evaluator, sdd-ux-validator, or the checks_result runner) fails on a story, identify which outcome-assertion(s) the failure invalidates by reading the PRD's assertions corpus and the failing story's assertion_ids. The asymmetry below is non-negotiable — it is the entire point of the §2.9 coverage gate:

  • Failed assertion → SPEC AMENDMENT (NOT assertion edit, NOT test edit). The assertion was outcome-shaped at planning time; if it failed at runtime, the spec under-specified the outcome contract. Backprop tightens the spec. The assertion's description may be revised IF AND ONLY IF the spec amendment changes the outcome contract that produced it; the assertion is never edited in isolation to make a passing implementation look correct. New assertions may be added if the failure surfaced a previously-unstated invariant.
  • Failed implementation against a passing assertion → IMPL FIX (NOT assertion edit). The assertion was right; the code was wrong. Generate a follow-up story per the orchestrator's W2 loop and let it converge.

Never edit an assertion to match what the code does. That collapse is exactly the failure mode §2.9 was added to prevent — once assertions become tests-fitted-to-the-code, the validation contract is meaningless and every prior assertion failure becomes deniable. Surface any ambiguous case to the operator before touching the corpus. (See spec-plugin-v1.md §2.9 motivation; cross-references missions-parity-handoff.md W10 and the production-data target language "validation never passes first try → expect follow-up features".)

This rule interlocks with §2.2 — the verification record's notes field SHOULD cite the specific assertion ID(s) the verification satisfied when the closing entry corresponds to an assertion-driven failure. It also interlocks with §2.7 — repeated assertion failures on the same surface count as methodology risk via sdd_cluster_check, not just drift.

4. Optional adversarial review of the amendment

Before presenting to user, optionally invoke the sdd-skeptic agent on the proposed amendment:

  • Skeptic asks: does this amendment over-fit to the failing case? Would it block legitimate uses? Does it cite a concrete reproducer or speculate about a "class of bug"? Does it mix prevent/detect/mitigate (it should be tagged exactly one)?
  • Output: list of concrete weaknesses; backpropagator revises.

Default: ON for omission and under-specification (most prone to over-fitting). OFF for implementation-error (no amendment needed).

5. Present suggestions to user

For each candidate, present the backpropagation report:

## Backpropagation: {commit hash}

**Commit:** {message}
**Classification:** {gap type}
**Category:** prevent | detect | mitigate
**Affected spec:** {spec file} — {requirement IDs}
**Minimal reproducer:** {description} — `{test command}`
**Missing constraint:** {description}

### Suggested amendment:
{Given/When/Then requirement}

### Skeptic findings (if run):
{list or "none"}

Apply this spec update? [yes / modify / skip]

Critical: backpropagation is human-gated. Never auto-modify specs. Constitutional Article 2.

6. Apply approved amendments

For each approved amendment:

  1. Add the new/modified requirement to the spec file
  2. Assign the next sequential traceability ID (SPEC-{slug}-{next_number})
  3. Add an entry to the spec's backpropagation log table
  4. Commit with:
    docs: backprop spec-{slug} — add {requirement title}
    
    Spec-Ref: context/specs/spec-{slug}.md
    Backprop-From: {original-fix-commit-hash}
  5. Update context/impl/backprop-log.json (schema at ${CLAUDE_PLUGIN_ROOT}/templates/backprop/backprop-log.schema.json):

    {
      "id": "bp-{NNN}",
      "trigger_commit": "{hash}",
      "trigger_type": "manual-fix",
      "classification": "{gap type}",
      "category": "{prevent|detect|mitigate}",
      "spec_updated": "{spec path}",
      "requirement_added": "SPEC-{slug}-{NNN}",
      "minimal_repro": {
        "description": "{the minimal reproducer from step 3}",
        "test_command": "{shell command that fails before fix, passes after}"
      },
      "verification": null,
      "verified_via_ralph": false,
      "regression_corpus_pass": true,
      "date": "{ISO timestamp}"
    }

    verification is null at creation time — the entry has been amended but not yet verified. Step 8 populates the structured record and gates closure on sdd_verification_check. verified_via_ralph is now a derived summary computed from record completeness + wiring_audit_pass; do not set it independently.

7. Stop-the-line gate

If iterate produces 3+ amendments to the same spec slug in a single run, halt rather than amending unboundedly. Report: "Spec {slug} has accumulated N amendments this session. This is a Toyota-Andon signal — the spec may need a holistic rewrite, not more bolt-ons. Recommend manual review before continuing."

7.5 Wiring audit gate (§2.4)

Before any verification record construction in Step 8, invoke sdd_wiring_audit_check with the proposed amendment's entry_id to determine whether this entry's classification or category triggers the cross-family wiring-audit requirement (per spec-plugin-v1.md §2.4 + A1 amendment + Codex audit recommendation #5). The five trigger categories are pinned in the predicate: detect, quantitative_gate, abort_rate_threshold, subprocess_protocol, runtime_callback_wiring.

Branch on status:

  • not_required — entry's classification/category does not match a trigger. Proceed directly to Step 8 verification record construction.
  • gate_required_missing — entry's category requires a wiring audit but the verification record is absent (expected at this point, since the entry was created at Step 6 with verification: null) or wiring_audit_pass is not true, OR the project has no .sdd/config.json to resolve providers against. HALT closure. Surface to operator: this amendment must route to a cross-family validator per the per-project provider config. The auditor (an agent whose name starts with sdd-, or a human like tyler / matt) populates wiring_audit_pass: true, auditor, and the implicit auditor_provider (resolved from the auditor's agent name via sdd_resolve_provider) into the verification record at Step 8 sub-step 4. Re-attempt close after the audit runs and the record is populated.
  • cross_family_violation — wiring audit ran but the auditor's provider is same-family as the worker (either provider strings match or same_family_warning=true in the config). HALT closure (per A1 spec amendment + locked decision #5 — wiring audits MUST route cross-family). Surface to operator and re-run with a cross-family auditor. Recommended phrasing: "⛔ Wiring audit ran same-family. Per §2.4 A1 + locked decision #5, cross-family routing is required. Re-dispatch the audit to an agent whose resolved provider differs from worker.provider per .sdd/config.json."
  • complete — gate satisfied. Proceed to Step 8.
  • no_log — backprop log or entry not found at the resolved path. HALT with the predicate's error cited.

This gate is the programmatic enforcement of the cross-family discipline previously operator-enforced in Step 8 sub-step 4 prose ("Cross-family wiring audit (per locked decision #5)"). The prose remains as backup guidance for the operator constructing the record, but the gate is now authoritative — Step 8 sub-step 5 (sdd_verification_check) confirms structural completeness; this gate confirms cross-family routing. Both must pass before Step 8 sub-step 6 writes the populated record.

For amendments whose category is not in the trigger list (e.g. pure prevent amendments to documented-internal interfaces), this gate is a no-op (not_required); the operator-enforced cross-family prose in Step 8 sub-step 4 still applies as guidance, but the predicate does not block.

8. Optionally verify via regeneration AND close the entry

If the backpropagator recommended re-running implementation:

Ask the user: "Re-run implementation from updated spec to verify the fix emerges from specs alone? This will re-attempt the affected stories."

If approved:

  1. Reset the affected stories in prd.json: set passes: false, reset attempts to 0, set phase: "pending". Phase-first read (v1.1+): when checking which stories need re-run, a story is "done" when phase == "done". Legacy PRDs without a phase field fall back to passes == true. Never read passes alone to determine done status on PRDs that carry a phase field.
  2. Run /sdd-implement on those stories
  3. Replay the full regression corpus — every prior minimal_repro must still pass.
  4. Construct the verification record (per Phase 2.2 of spec-plugin-v1.md). Populate the entry's verification field with all seven sub-fields:

    • command — exact command run to verify (e.g. the entry's minimal_repro.test_command, or a pytest invocation)
    • artifact_path — path to test output, screenshot, or log demonstrating verification (or null)
    • production_entrypoint — code path the verification exercised (e.g. src/foo.py:run_pipeline)
    • calibration_lineage — required field encoding how this verification's calibration relates to prior calibrations on the same spec. Must take exactly one of three forms:
      • (a) Extension — cite a prior bp-NNN entry ID whose calibration this extends, AND name what was PRESERVED from that calibration AND what was CHANGED. Example: "extends bp-007: preserved threshold=0.85, changed window from 5m to 15m".
      • (b) Scratch — the literal string "scratch" PLUS an explicit retirement reason citing every prior bp-NNN entry on the same spec_updated whose calibration is being abandoned. Example: "scratch — retires bp-003 and bp-007: prior calibration coupled to deprecated input shape". If no prior calibrations exist on this spec, scratch is permitted with the reason "no prior calibration on this spec".
      • (c) Null — null is acceptable ONLY when the change genuinely has no calibration surface (e.g. a docs-only requirement, a pure rename). This determination must be explicit, not a default: if you populate null, the notes field MUST state why no calibration surface exists. Any change that tunes thresholds, windows, prompts, weights, ranking, or numeric guardrails has a calibration surface and MUST use form (a) or (b).
    • wiring_audit_pass — boolean — explicit cross-family wiring-audit verdict (per §2.4 / locked decision #5)
    • auditor — agent or human that performed the audit (e.g. "sdd-evaluator", "sdd-skeptic", "tyler")
    • notes — free-form context (or null)

    Calibration discipline (per §2.3). calibration_lineage is never a free-text afterthought. You MUST pick form (a) extension, (b) scratch with retirement reason, or (c) null with explicit no-surface justification — and you MUST NOT default to null to silence the field. If a prior bp-NNN entry exists on the same spec_updated and you choose (a) or (c), be prepared to defend why retirement (form b) is not warranted. Until programmatic enforcement lands in verification-check.ts, this constraint is operator-enforced — surface any ambiguous lineage call to the user before closing.

    Cross-family wiring audit (per locked decision #5). If you implemented the change, you MUST NOT also fill wiring_audit_pass — route the wiring audit to a cross-family validator (e.g. hosted Anthropic if the implementer ran on a local model, or vice versa) per the project's per-project provider config. Until §2.4 ships full programmatic enforcement, this constraint is operator-enforced — surface any same-family verification path explicitly to the user before populating wiring_audit_pass.

  5. Invoke sdd_verification_check on the proposed entry. If status != "complete", refuse to close — report the missing_fields to the user and ask them to populate or revise. Do not write the entry until the predicate returns "complete".
  6. If status == "complete", write the populated verification record and the derived verified_via_ralph: true to the entry. The boolean is computed from record completeness + wiring_audit_pass; never set it independently.
  7. If implementation does not produce the fix from specs alone (regression corpus regresses or the trigger reproducer still fails), close with verification: null and verified_via_ralph: false, and flag the spec amendment as needing further refinement.

9. Update progress

Append to progress.txt:

  • [{timestamp}] Backpropagation: analyzed {N} candidates, {M} spec amendments applied, {K} corpus regressions
  • For each amendment: - {spec file}: added {requirement ID} from commit {hash} (category={prevent|detect|mitigate})

Output contract

  • Regression corpus replayed BEFORE any new amendment is drafted
  • Each manual-fix commit is analyzed, classified, and assigned a category (prevent/detect/mitigate)
  • Every amendment carries a minimal reproducer and test command
  • "How, not why" framing in all amendment proposals
  • User approves all spec amendments (never auto-modified)
  • Approved amendments are committed with Backprop-From trailers
  • backprop-log.json is updated with the extended schema, including the structured verification field (null at creation, populated at closure)
  • Closure of an entry requires sdd_verification_check status "complete"; verified_via_ralph is derived from record completeness + wiring_audit_pass, never set independently
  • Cross-family wiring-audit constraint enforced operator-side until §2.4 ships full programmatic enforcement
  • Stop-the-line triggers if ≥3 amendments to one spec in one session
  • progress.txt is updated

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.