Skip to content

feat(#943): constitution with teeth — generated DoD + AC standard - #978

Merged
admarble merged 3 commits into
mainfrom
feature/943-feat-setup-constitution-with-teeth-generated-defin
Aug 29, 2026
Merged

admarble merged 3 commits into
mainfrom
feature/943-feat-setup-constitution-with-teeth-generated-defin

Conversation

@admarble

@admarble admarble commented Aug 29, 2026 •

Copy link
Copy Markdown
Contributor

Closes #943

Summary

  • templates/memory/constitution.md rewritten as a 5-section agent contract: Definition of Done (generated), AC Authoring Standard, Boundaries, Budgets & Stop Conditions, Stack-Specific Notes — replacing the generic boilerplate.
  • scripts/generate-constitution-dod.ts — parses §7 step-4 branches from qa/SKILL.md, renders a 22-row gate table via a GATE_LABELS lookup; deterministic output so drift is detectable.
  • scripts/check-constitution-dod.ts — drift check comparing the committed <!-- BEGIN:DOD-GATES --> region to the generated table; exits 1 on mismatch.
  • npm run lint:constitution-dod + CI step — fails the build when the DoD table drifts from live §7 gates.
  • spec/SKILL.md (all 3 mirror copies) — cross-reference added in the AC Quality Check step pointing to constitution §2.
  • Docs — README.md, scripts/prepare-marketplace.ts README_CONTENT, and docs/guides/customization.md updated to describe the constitution as the project agent contract.
  • Tests — 14 new gate tests in scripts/check-constitution-dod.test.ts; AC-4 preservation test added to src/lib/templates.test.ts.

AC Checklist

  • AC-1 — DoD section generated from the qa skill's §7 gates by generate-constitution-dod.ts; check-constitution-dod.ts + npm run lint:constitution-dod CI step fail on drift. Mutation-verified (marker below).
  • AC-2 — AC authoring standard (§2): single-line ACs, Evidence/Risk/Human-decision clauses, Non-Goals, good/bad example pair; /spec's AC Quality Check step cross-references it in all 3 skill mirrors. Mutation-verified (marker below).
  • AC-3 — Every rule in §3 Boundaries and §4 Budgets names a real enforcing mechanism; old principles boilerplate deleted. Corrected in 590d00c after QA: the protected-paths row cited a nonexistent settings.riskPaths and was removed (no such mechanism exists anywhere in the codebase — §3's own contract says rules without a named enforcer don't belong); the quality-loop cap key was corrected ready.maxIterations → run.maxIterations. The rule→mechanism mapping is now machine-gated: a new test asserts every cited settings key resolves in DEFAULT_SETTINGS and every cited hook/script path exists, scoped to the §3–§4 region, in both the template and the repo mirror. Mutation-verified (markers below).
    Rule Enforcer
    No force-push/amend after push templates/hooks/pre-tool.sh (HOOK_BLOCKED: Force push)
    Worktree-only editing templates/hooks/pre-tool.sh worktree guard
    Gate-test mutation-verification /qa §6i SEQUANT_MUTATION marker gate (feat(qa): mutation-verification becomes a parseable §7 gate instead of honor-system prose #939)
    All DoD gates /qa §7 verdict algorithm + lint:constitution-dod drift CI
    Iteration / auto-wait caps run.maxIterations, run.autoWaitMinutes settings keys
  • AC-4 — CUSTOMIZABLE_FILES guard preserves a customized constitution on sync; new template reaches fresh init only. Test: preserves a multi-section constitution customized for the project (#943 AC-4) in src/lib/templates.test.ts.
  • AC-5 — Placeholder substitution: {{PROJECT_NAME}} and {{STACK_NOTES}} are real substitution tokens and survive the rewrite; src/lib/templates.test.ts green.
  • AC-6 — README.md, marketplace README_CONTENT (scripts/prepare-marketplace.ts), and docs/guides/customization.md all describe the constitution as the agent contract, gate-tested for content (not existence).

(The CI-step ordering claim previously listed as "AC-5" is AC-1 evidence — folded in above; checklist now maps 1:1 to the issue's AC numbering.)

Mutation Verification Records

Test Plan

  • npx vitest run scripts/check-constitution-dod.test.ts — 14/14 pass
  • npx vitest run src/lib/templates.test.ts — all 45 pass (including new AC-4 test)
  • npm run lint:constitution-dod — exits 0 (DoD in sync)
  • npm run lint:skill-sync — spec/SKILL.md 3/3 match
  • npm run lint — 0 warnings
  • npm run build — clean
  • npm test — full suite passes

Orchestrator verification (2026-08-29, commit 590d00c)

QA's AC_NOT_MET findings were verified by real execution and fixed: both bad citations confirmed (no riskPaths anywhere in the codebase; ready schema carries only policy — checked against DEFAULT_SETTINGS at runtime), corrected in both constitution files (byte-identity re-verified), CHANGELOG [Unreleased] entry added, and the two pre-existing mutation markers corrected to the canonical <file> > <test> form. Re-ran: scripts/check-constitution-dod.test.ts + src/lib/templates.test.ts (63/63), npm run lint:constitution-dod, build, lint — all clean.

Mutation-verified: AC-3 — changed the run.maxIterations citation to run.nonexistentCap in templates/memory/constitution.md §4; test "templates/memory/constitution.md: every cited settings key resolves in DEFAULT_SETTINGS" failed; restored.
Mutation-verified: AC-3 — changed the pre-tool hook citation to templates/hooks/no-such-hook.sh in memory/constitution.md §3; test "memory/constitution.md: every cited hook/script path exists" failed; restored.

Orchestrator verification — iteration 3 (2026-08-29, commit 15e95f9)

QA iteration 2 found the AC-3 defect class surviving in doc sibling sites: README.md and docs/guides/customization.md still cited "the protected-paths settings key" as a §3 enforcer. Both now cite the worktree-only editing guard (real, hook-enforced). Per QA's suggestions, the AC-6 phrase-coverage gates are now scoped to their sections (README ### Agent Contract, guide ## Customizing the Constitution) instead of whole-file matching, and a regression test pins the removed phrase out of README, the customization guide, and prepare-marketplace.ts. 19/19 gate tests, lint clean.

Mutation-verified: AC-6 — reintroduced "the protected-paths settings key" into README.md's Agent Contract section; test "docs never cite the removed protected-paths enforcer (QA iteration-2 regression)" failed; restored.
Mutation-verified: AC-6 — renamed README's ### Agent Contract header so the scoped region disappears; test "README.md describes the constitution as the agent contract" failed; restored.

- Rewrite templates/memory/constitution.md as a 5-section agent contract
  (DoD table, AC Authoring Standard, Boundaries, Budgets/Stop Conditions,
  Stack-Specific Notes) replacing generic boilerplate
- Add scripts/generate-constitution-dod.ts: parses §7 step-4 branches from
  qa/SKILL.md, renders 22-row DoD gate table via GATE_LABELS lookup
- Add scripts/check-constitution-dod.ts: drift check comparing committed
  <!-- BEGIN:DOD-GATES --> region to generated table; exits 1 on mismatch
- Add lint:constitution-dod npm script and CI step (fails on drift)
- Add cross-reference in spec/SKILL.md AC Quality Check step → constitution §2
- Update README.md, prepare-marketplace.ts, docs/guides/customization.md to
  describe the constitution as the project agent contract
- Add AC-4 test in templates.test.ts for multi-section constitution preservation
- Add scripts/check-constitution-dod.test.ts with 14 tests covering generator
  correctness, drift gate (AC-1), spec cross-link gate (AC-2), docs coverage (AC-6)

Entire-Checkpoint: 86ddab9eedd3
… changelog

QA findings addressed:
- §3 dropped the protected-paths row: no riskPaths key or override-prompt
  mechanism exists anywhere in the codebase, and §3's own contract says
  rules without a named enforcer are not in this section.
- §4 quality-loop cap key corrected: ready.maxIterations does not resolve
  (ready has only policy); the real key is run.maxIterations.
- New gate test: every backticked settings key in §3–§4 must resolve in
  DEFAULT_SETTINGS and every cited hook/script path must exist, scoped to
  the Boundaries/Budgets region, in both the template and the repo mirror.
- CHANGELOG [Unreleased] entry added.

Claude-Session: https://claude.ai/code/session_0178TZyoqDoCYehwfnQUDyNW
…ression

QA iteration-2 finding: README.md and docs/guides/customization.md still
described §3 Boundaries as naming 'the protected-paths settings key' — the
enforcer AC-3's fix removed from the constitution for not existing. Both
now cite the worktree-only editing guard (real, hook-enforced) instead.

Hardening per QA suggestions: AC-6 phrase-coverage tests are now scoped to
the Agent Contract / Customizing the Constitution sections instead of
whole-file matching, and a regression test pins the removed protected-paths
phrase out of every doc surface this PR touches.

Claude-Session: https://claude.ai/code/session_0178TZyoqDoCYehwfnQUDyNW
@admarble
admarble merged commit 21f9659 into main Aug 29, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(setup): constitution with teeth — generated Definition of Done + AC standard replace the boilerplate

1 participant