@friedbotstudio/create-baseline 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (197) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +222 -0
  3. package/bin/cli.js +247 -0
  4. package/obj/template/.claude/agents/swarm-worker.md +52 -0
  5. package/obj/template/.claude/bin/LICENSE +201 -0
  6. package/obj/template/.claude/bin/NOTICE +48 -0
  7. package/obj/template/.claude/commands/approve-spec.md +29 -0
  8. package/obj/template/.claude/commands/approve-swarm.md +27 -0
  9. package/obj/template/.claude/commands/grant-commit.md +19 -0
  10. package/obj/template/.claude/commands/init-project.md +191 -0
  11. package/obj/template/.claude/hooks/artifact_template_guard.sh +141 -0
  12. package/obj/template/.claude/hooks/consent_gate_grant.sh +89 -0
  13. package/obj/template/.claude/hooks/destructive_cmd_guard.sh +42 -0
  14. package/obj/template/.claude/hooks/env_guard.sh +36 -0
  15. package/obj/template/.claude/hooks/git_commit_guard.sh +93 -0
  16. package/obj/template/.claude/hooks/harness_continuation.sh +121 -0
  17. package/obj/template/.claude/hooks/lib/__pycache__/resume_writer.cpython-314.pyc +0 -0
  18. package/obj/template/.claude/hooks/lib/common.sh +328 -0
  19. package/obj/template/.claude/hooks/lib/resume_writer.py +341 -0
  20. package/obj/template/.claude/hooks/lint_runner.sh +55 -0
  21. package/obj/template/.claude/hooks/memory_pre_compact.sh +36 -0
  22. package/obj/template/.claude/hooks/memory_session_start.sh +244 -0
  23. package/obj/template/.claude/hooks/memory_stop.sh +173 -0
  24. package/obj/template/.claude/hooks/plantuml_syntax_guard.sh +161 -0
  25. package/obj/template/.claude/hooks/process_lifecycle_guard.sh +89 -0
  26. package/obj/template/.claude/hooks/setup_guard.sh +50 -0
  27. package/obj/template/.claude/hooks/spec_approval_guard.sh +81 -0
  28. package/obj/template/.claude/hooks/spec_design_calls_guard.sh +183 -0
  29. package/obj/template/.claude/hooks/spec_diagram_presence_guard.sh +141 -0
  30. package/obj/template/.claude/hooks/swarm_approval_guard.sh +39 -0
  31. package/obj/template/.claude/hooks/swarm_boundary_guard.sh +136 -0
  32. package/obj/template/.claude/hooks/tdd_order_guard.sh +176 -0
  33. package/obj/template/.claude/hooks/test_runner.sh +75 -0
  34. package/obj/template/.claude/hooks/tests/fixtures/ac008_byte_equal_reference.txt +12 -0
  35. package/obj/template/.claude/hooks/tests/memory_session_start_test.sh +285 -0
  36. package/obj/template/.claude/hooks/track_guard.sh +127 -0
  37. package/obj/template/.claude/hooks/verify_pass_guard.sh +88 -0
  38. package/obj/template/.claude/memory/README.md +108 -0
  39. package/obj/template/.claude/memory/_pending.md +15 -0
  40. package/obj/template/.claude/memory/_resume.md +12 -0
  41. package/obj/template/.claude/memory/conventions.md +26 -0
  42. package/obj/template/.claude/memory/decisions.md +29 -0
  43. package/obj/template/.claude/memory/landmarks.md +26 -0
  44. package/obj/template/.claude/memory/landmines.md +27 -0
  45. package/obj/template/.claude/memory/libraries.md +27 -0
  46. package/obj/template/.claude/memory/pending-questions.md +28 -0
  47. package/obj/template/.claude/project.json +221 -0
  48. package/obj/template/.claude/settings.json +110 -0
  49. package/obj/template/.claude/skills/archive/SKILL.md +48 -0
  50. package/obj/template/.claude/skills/archive/archive.sh +145 -0
  51. package/obj/template/.claude/skills/audit-baseline/SKILL.md +80 -0
  52. package/obj/template/.claude/skills/audit-baseline/audit.sh +919 -0
  53. package/obj/template/.claude/skills/brd/SKILL.md +44 -0
  54. package/obj/template/.claude/skills/brd/template.md +83 -0
  55. package/obj/template/.claude/skills/chore/SKILL.md +99 -0
  56. package/obj/template/.claude/skills/claude-automation-recommender/LICENSE +202 -0
  57. package/obj/template/.claude/skills/claude-automation-recommender/NOTICE +69 -0
  58. package/obj/template/.claude/skills/claude-automation-recommender/SKILL.md +358 -0
  59. package/obj/template/.claude/skills/claude-automation-recommender/references/hooks-patterns.md +226 -0
  60. package/obj/template/.claude/skills/claude-automation-recommender/references/mcp-servers.md +263 -0
  61. package/obj/template/.claude/skills/claude-automation-recommender/references/plugins-reference.md +98 -0
  62. package/obj/template/.claude/skills/claude-automation-recommender/references/skills-reference.md +408 -0
  63. package/obj/template/.claude/skills/claude-automation-recommender/references/subagent-templates.md +181 -0
  64. package/obj/template/.claude/skills/code-structure/SKILL.md +204 -0
  65. package/obj/template/.claude/skills/commit/SKILL.md +21 -0
  66. package/obj/template/.claude/skills/copywriting/SKILL.md +252 -0
  67. package/obj/template/.claude/skills/copywriting/evals/evals.json +111 -0
  68. package/obj/template/.claude/skills/copywriting/references/ai-writing-detection.md +200 -0
  69. package/obj/template/.claude/skills/copywriting/references/copy-frameworks.md +344 -0
  70. package/obj/template/.claude/skills/copywriting/references/natural-transitions.md +272 -0
  71. package/obj/template/.claude/skills/design-ui/SKILL.md +175 -0
  72. package/obj/template/.claude/skills/design-ui/references/design-vs-development.md +89 -0
  73. package/obj/template/.claude/skills/design-ui/references/intent-table.md +64 -0
  74. package/obj/template/.claude/skills/design-ui/references/orchestration.md +121 -0
  75. package/obj/template/.claude/skills/design-ui/references/state-machine.md +125 -0
  76. package/obj/template/.claude/skills/document/SKILL.md +66 -0
  77. package/obj/template/.claude/skills/documentation/SKILL.md +50 -0
  78. package/obj/template/.claude/skills/harness/SKILL.md +169 -0
  79. package/obj/template/.claude/skills/humanizer/SKILL.md +489 -0
  80. package/obj/template/.claude/skills/humanizer/references/ai-writing-detection.md +208 -0
  81. package/obj/template/.claude/skills/impeccable/PROJECT_NOTES.md +22 -0
  82. package/obj/template/.claude/skills/impeccable/SKILL.md +153 -0
  83. package/obj/template/.claude/skills/impeccable/agents/openai.yaml +4 -0
  84. package/obj/template/.claude/skills/impeccable/reference/adapt.md +190 -0
  85. package/obj/template/.claude/skills/impeccable/reference/animate.md +173 -0
  86. package/obj/template/.claude/skills/impeccable/reference/audit.md +134 -0
  87. package/obj/template/.claude/skills/impeccable/reference/bolder.md +113 -0
  88. package/obj/template/.claude/skills/impeccable/reference/brand.md +104 -0
  89. package/obj/template/.claude/skills/impeccable/reference/clarify.md +174 -0
  90. package/obj/template/.claude/skills/impeccable/reference/cognitive-load.md +106 -0
  91. package/obj/template/.claude/skills/impeccable/reference/color-and-contrast.md +105 -0
  92. package/obj/template/.claude/skills/impeccable/reference/colorize.md +154 -0
  93. package/obj/template/.claude/skills/impeccable/reference/craft.md +138 -0
  94. package/obj/template/.claude/skills/impeccable/reference/critique.md +213 -0
  95. package/obj/template/.claude/skills/impeccable/reference/delight.md +302 -0
  96. package/obj/template/.claude/skills/impeccable/reference/distill.md +111 -0
  97. package/obj/template/.claude/skills/impeccable/reference/document.md +427 -0
  98. package/obj/template/.claude/skills/impeccable/reference/extract.md +70 -0
  99. package/obj/template/.claude/skills/impeccable/reference/harden.md +347 -0
  100. package/obj/template/.claude/skills/impeccable/reference/heuristics-scoring.md +234 -0
  101. package/obj/template/.claude/skills/impeccable/reference/interaction-design.md +195 -0
  102. package/obj/template/.claude/skills/impeccable/reference/layout.md +141 -0
  103. package/obj/template/.claude/skills/impeccable/reference/live.md +513 -0
  104. package/obj/template/.claude/skills/impeccable/reference/motion-design.md +99 -0
  105. package/obj/template/.claude/skills/impeccable/reference/onboard.md +234 -0
  106. package/obj/template/.claude/skills/impeccable/reference/optimize.md +258 -0
  107. package/obj/template/.claude/skills/impeccable/reference/overdrive.md +130 -0
  108. package/obj/template/.claude/skills/impeccable/reference/personas.md +178 -0
  109. package/obj/template/.claude/skills/impeccable/reference/polish.md +232 -0
  110. package/obj/template/.claude/skills/impeccable/reference/product.md +62 -0
  111. package/obj/template/.claude/skills/impeccable/reference/quieter.md +99 -0
  112. package/obj/template/.claude/skills/impeccable/reference/responsive-design.md +114 -0
  113. package/obj/template/.claude/skills/impeccable/reference/shape.md +136 -0
  114. package/obj/template/.claude/skills/impeccable/reference/spatial-design.md +100 -0
  115. package/obj/template/.claude/skills/impeccable/reference/teach.md +137 -0
  116. package/obj/template/.claude/skills/impeccable/reference/typeset.md +124 -0
  117. package/obj/template/.claude/skills/impeccable/reference/typography.md +159 -0
  118. package/obj/template/.claude/skills/impeccable/reference/ux-writing.md +107 -0
  119. package/obj/template/.claude/skills/impeccable/scripts/cleanup-deprecated.mjs +284 -0
  120. package/obj/template/.claude/skills/impeccable/scripts/command-metadata.json +94 -0
  121. package/obj/template/.claude/skills/impeccable/scripts/design-parser.mjs +820 -0
  122. package/obj/template/.claude/skills/impeccable/scripts/detect-csp.mjs +198 -0
  123. package/obj/template/.claude/skills/impeccable/scripts/is-generated.mjs +69 -0
  124. package/obj/template/.claude/skills/impeccable/scripts/live-accept.mjs +465 -0
  125. package/obj/template/.claude/skills/impeccable/scripts/live-browser.js +4684 -0
  126. package/obj/template/.claude/skills/impeccable/scripts/live-inject.mjs +436 -0
  127. package/obj/template/.claude/skills/impeccable/scripts/live-poll.mjs +187 -0
  128. package/obj/template/.claude/skills/impeccable/scripts/live-server.mjs +679 -0
  129. package/obj/template/.claude/skills/impeccable/scripts/live-wrap.mjs +395 -0
  130. package/obj/template/.claude/skills/impeccable/scripts/live.mjs +247 -0
  131. package/obj/template/.claude/skills/impeccable/scripts/load-context.mjs +93 -0
  132. package/obj/template/.claude/skills/impeccable/scripts/modern-screenshot.umd.js +14 -0
  133. package/obj/template/.claude/skills/impeccable/scripts/pin.mjs +214 -0
  134. package/obj/template/.claude/skills/implement/SKILL.md +83 -0
  135. package/obj/template/.claude/skills/intake/SKILL.md +46 -0
  136. package/obj/template/.claude/skills/intake/template.md +61 -0
  137. package/obj/template/.claude/skills/integrate/SKILL.md +62 -0
  138. package/obj/template/.claude/skills/memory-flush/SKILL.md +172 -0
  139. package/obj/template/.claude/skills/memory-flush/sweep.py +286 -0
  140. package/obj/template/.claude/skills/memory-flush/tests/run.sh +327 -0
  141. package/obj/template/.claude/skills/prose/SKILL.md +119 -0
  142. package/obj/template/.claude/skills/rca/SKILL.md +42 -0
  143. package/obj/template/.claude/skills/rca/template.md +83 -0
  144. package/obj/template/.claude/skills/research/SKILL.md +75 -0
  145. package/obj/template/.claude/skills/scenario/SKILL.md +64 -0
  146. package/obj/template/.claude/skills/scout/SKILL.md +72 -0
  147. package/obj/template/.claude/skills/security/SKILL.md +75 -0
  148. package/obj/template/.claude/skills/simplify/SKILL.md +67 -0
  149. package/obj/template/.claude/skills/spec/SKILL.md +69 -0
  150. package/obj/template/.claude/skills/spec/template.md +274 -0
  151. package/obj/template/.claude/skills/spec-diagram-review/SKILL.md +81 -0
  152. package/obj/template/.claude/skills/spec-lint/SKILL.md +55 -0
  153. package/obj/template/.claude/skills/spec-lint/lint.sh +218 -0
  154. package/obj/template/.claude/skills/spec-render/SKILL.md +45 -0
  155. package/obj/template/.claude/skills/spec-render/render.sh +109 -0
  156. package/obj/template/.claude/skills/spec-traceability-review/SKILL.md +72 -0
  157. package/obj/template/.claude/skills/swarm-dispatch/SKILL.md +212 -0
  158. package/obj/template/.claude/skills/swarm-dispatch/swarm_merge.sh +154 -0
  159. package/obj/template/.claude/skills/swarm-plan/SKILL.md +90 -0
  160. package/obj/template/.claude/skills/swarm-plan/validate.sh +181 -0
  161. package/obj/template/.claude/skills/tdd/SKILL.md +100 -0
  162. package/obj/template/.claude/skills/technical-tutorials/SKILL.md +569 -0
  163. package/obj/template/.claude/skills/technical-tutorials/references/audience-context-README.md +53 -0
  164. package/obj/template/.claude/skills/technical-tutorials/references/audience-context.md +246 -0
  165. package/obj/template/.claude/skills/technical-tutorials/references/audience-example.md +175 -0
  166. package/obj/template/.claude/skills/technical-tutorials/references/audience-template.md +152 -0
  167. package/obj/template/.claude/skills/triage/SKILL.md +55 -0
  168. package/obj/template/.claude/skills/verify/SKILL.md +74 -0
  169. package/obj/template/.mcp.json +24 -0
  170. package/obj/template/CLAUDE.md +327 -0
  171. package/obj/template/docs/init/seed.md +585 -0
  172. package/obj/template/manifest.json +214 -0
  173. package/package.json +48 -0
  174. package/src/.mcp.template.json +24 -0
  175. package/src/.npmrc.template +2 -0
  176. package/src/CLAUDE.template.md +327 -0
  177. package/src/agents/swarm-worker.template.md +51 -0
  178. package/src/cli/conflict.js +31 -0
  179. package/src/cli/doctor.js +152 -0
  180. package/src/cli/install.js +93 -0
  181. package/src/cli/io.js +27 -0
  182. package/src/cli/manifest.js +38 -0
  183. package/src/cli/mcp.js +54 -0
  184. package/src/cli/merge.js +107 -0
  185. package/src/cli/plantuml.js +121 -0
  186. package/src/cli/util.js +10 -0
  187. package/src/memory/_pending.template.md +15 -0
  188. package/src/memory/_resume.template.md +12 -0
  189. package/src/memory/conventions.template.md +26 -0
  190. package/src/memory/decisions.template.md +29 -0
  191. package/src/memory/landmarks.template.md +26 -0
  192. package/src/memory/landmines.template.md +27 -0
  193. package/src/memory/libraries.template.md +27 -0
  194. package/src/memory/pending-questions.template.md +28 -0
  195. package/src/project.template.json +221 -0
  196. package/src/seed.template.md +585 -0
  197. package/src/settings.template.json +110 -0
@@ -0,0 +1,121 @@
1
+ # Orchestration — Stage 3 gates and loop logic
2
+
3
+ Stage 3 of `design-ui` runs the impeccable recipe step-by-step in main context. This file documents the gates that decide when to continue, when to loop, when to surface to the user, and when to block.
4
+
5
+ ## The orchestration loop, top level
6
+
7
+ ```
8
+ for each step in recipe:
9
+ pre-checkpoint -> .claude/state/design/<slug>.json {step_index, next_cmd}
10
+ invoke -> Skill(impeccable, "<cmd>", "<args>")
11
+ capture -> read impeccable's structured result
12
+ branch -> see gates below
13
+ post-checkpoint -> .claude/state/design/<slug>.json {step_index++, invocations[]}
14
+ ```
15
+
16
+ The state file is written *before* and *after* each step so a mid-step interruption (session end, context compact, user abort) is recoverable on next invocation per `state-machine.md`.
17
+
18
+ ## Gates within the orchestration
19
+
20
+ ### Gate 1 — P0 blocks
21
+
22
+ If the previous step was `audit` (or `critique`) and its return value reports `P0 ≥ 1`:
23
+
24
+ - Do **not** auto-chain to `polish`.
25
+ - Surface the P0 list to the caller (or the user, on direct invocation).
26
+ - Persist `state: "blocked"` to the state file.
27
+ - Return `{ final_state: "blocked", reason: "P0 issues require user direction", audit_report_path }`.
28
+
29
+ P0 issues are by definition blockers: accessibility failures (focus traps, missing labels, color contrast < 3:1), broken core functionality, semantic-HTML violations. Looping `polish` on a P0 risks compounding the issue; the user must direct the fix.
30
+
31
+ ### Gate 2 — P1 looping with cap 3
32
+
33
+ If the previous step was `audit` and reports `P1 ≥ 1` and `P0 == 0`:
34
+
35
+ - Run `polish` against the audit report.
36
+ - Re-run `audit` to measure progress.
37
+ - Repeat up to **3 iterations** (audit → polish → audit → polish → audit → polish → audit, where the final audit is the verification).
38
+ - After iteration 3's verification audit, if P1 is still > 0:
39
+ - Terminate with `state: "needs_human"`.
40
+ - Persist `.claude/state/design/<slug>.json` with the audit history.
41
+ - Materialize `docs/design/<slug>.audit.md` (human-readable report).
42
+ - Emit a memory candidate via `memory_stop` so `_pending.md` carries the issue forward.
43
+ - Return `{ final_state: "needs_human", iterations: 3, audit_report_path, state_file }`.
44
+ - After iteration 3, **no fourth polish runs**. The cap is hard. The user can re-invoke design-ui (resume from state) or invoke `/impeccable polish` directly for one-off iteration.
45
+
46
+ The 3-iteration cap is a discipline: if three rounds of `polish` cannot clear P1, the issue likely needs a design call (a register change, a deliberate exception per CLAUDE.md Article X) or human judgement on tradeoffs. Continuing to loop would burn iteration budget without convergence.
47
+
48
+ ### Gate 3 — Recipe mode (auto vs ask)
49
+
50
+ After Stage 2 (translate) returns a recipe, Stage 3 reads the recipe's `mode`:
51
+
52
+ - **auto**: execute without prompting. Used for single-step recipes (`shape`, `live`, `extract`) and for atomic recipes (`audit → polish → audit` treated as one unit, mode-stamped `auto` by the intent-table).
53
+ - **ask**: surface the plan, await user `proceed`. The prompt format:
54
+ > "Recipe: `[shape, craft, audit]`. Proceed? (or describe an override)"
55
+
56
+ On `proceed` (or any non-negative response), continue. On override, re-invoke Stage 2 with the user's adjusted intent. On refusal, persist `state: "blocked"` and return `{ final_state: "blocked", reason: "user declined recipe" }`.
57
+
58
+ ### Gate 4 — Target-file existence
59
+
60
+ Before invoking any impeccable subcommand that writes (`craft`, `polish`, refines, enhances, fixes), Stage 3 verifies each `target_files` path's *parent directory* exists. If a parent is missing:
61
+
62
+ - Persist `state: "blocked"`.
63
+ - Return `{ final_state: "blocked", reason: "target_files parent directory missing: <path>", state_file }`.
64
+
65
+ This prevents impeccable from generating code with no home. design-ui never creates parent directories itself — that would be a write outside the thin-glue contract.
66
+
67
+ For surface-less intents (`extract`, `live`, `shape`-only) this gate is skipped: `target_files` may be empty or `—` per the schema, and the impeccable subcommand handles its own output destination.
68
+
69
+ ### Gate 5 — Register conflict
70
+
71
+ If `task_brief.register_override` is set and conflicts with `PRODUCT.md`'s declared register (e.g., override is `brand` but PRODUCT.md says `product`), Stage 3 surfaces:
72
+
73
+ > "Register mismatch: task_brief requests `brand`, PRODUCT.md declares `product`. Proceed with override, or align?"
74
+
75
+ On `proceed`, run the recipe with the override. On `align`, re-invoke Stage 2 with the PRODUCT.md register. On refusal, block.
76
+
77
+ This gate is intentionally a soft yield — register overrides are legitimate (a product app's marketing splash page wants `brand` register), but they should be intentional.
78
+
79
+ ## Iteration accounting
80
+
81
+ The state file records every invocation:
82
+
83
+ ```jsonc
84
+ {
85
+ "invocations": [
86
+ { "cmd": "audit", "iteration": 1, "started_at": "...", "completed_at": "...", "p0": 0, "p1": 3 },
87
+ { "cmd": "polish", "iteration": 1, "started_at": "...", "completed_at": "...", "files_written": [...] },
88
+ { "cmd": "audit", "iteration": 2, "started_at": "...", "completed_at": "...", "p0": 0, "p1": 2 },
89
+ { "cmd": "polish", "iteration": 2, "started_at": "...", "completed_at": "...", "files_written": [...] },
90
+ { "cmd": "audit", "iteration": 3, "started_at": "...", "completed_at": "...", "p0": 0, "p1": 1 }
91
+ ]
92
+ }
93
+ ```
94
+
95
+ The `iteration` counter increments inside a polish-atom loop (1, 2, 3). It is independent of `step_index` (which tracks position in the recipe). For non-loop recipes, `iteration` is 1 throughout.
96
+
97
+ ## Critique scoring loop (optional, recipe-driven)
98
+
99
+ Some recipes (`bolder`, `quieter`, `distill`) pair with `critique` as the verification step. The same cap-3 rule applies, but the threshold is `critique` score:
100
+
101
+ - If `critique` returns score < 14/20 after the refine step, loop with the same refine command (up to 2 additional iterations beyond the first).
102
+ - If score still < 14/20 after 3 total iterations, terminate with `needs_human`.
103
+
104
+ This is the same cap-3 shape as the polish loop, with `critique` as the gating signal instead of `audit`.
105
+
106
+ ## What the orchestrator never does
107
+
108
+ - **Does not pick aesthetic direction.** Stage 2's recipe choice and Stage 3's gates are about *flow*, not *style*. Every style decision flows through `impeccable`.
109
+ - **Does not write product code directly.** Thin glue only — state JSON, brief snapshots, audit snapshots under `docs/design/`. Product code is `impeccable`'s territory exclusively.
110
+ - **Does not retry after `needs_human`.** Once the cap fires, the caller (or user) decides. design-ui's resume reads the state file and continues *only* if a user action has materially changed the inputs (e.g., the audit report has been addressed manually, the state has been moved to `in_progress` explicitly).
111
+ - **Does not silently skip gates.** Every gate has an explicit branch with a recorded reason. Skipping is failure; surface always.
112
+ - **Does not invoke more than one impeccable subcommand at a time.** Sequential only. The `∥` notation in the intent table for `critique ∥ audit` is shorthand for "call both, collect results, neither blocks the other" — but they remain two sequential `Skill(impeccable, …)` calls in main context.
113
+
114
+ ## Caller policy at `final_state`
115
+
116
+ | State returned to caller | Caller policy (for `/tdd` Step 6 specifically) |
117
+ |---|---|
118
+ | `complete` | Mark the design call done; proceed to next call in design_calls; after all complete, re-invoke `verify`. |
119
+ | `needs_human` | Warn and continue. design-ui has surfaced; the user can re-invoke later. /tdd Step 6 does NOT fail. The audit report path goes in /tdd's notes. |
120
+ | `blocked` | Stop /tdd Step 6. Surface the blocker to the user. /tdd's `## 7. Decide on the result` step receives this and decides whether to escalate to a spec change. |
121
+ | `not_a_design_task` | Stage 0 misroute. /tdd surfaces "design-ui returned not_a_design_task — was this design_call mis-classified in the spec?" and stops to reconcile. |
@@ -0,0 +1,125 @@
1
+ # State machine — `.claude/state/design/<slug>.json`
2
+
3
+ `design-ui` persists every orchestration to `.claude/state/design/<slug>.json`. The file is the resume point: a second invocation with the same `slug` reads the file, finds `step_index`, and continues from there without re-running completed steps.
4
+
5
+ ## File location
6
+
7
+ `.claude/state/design/<slug>.json` — one file per orchestration, keyed by `slug`. The directory is gitignored (the whole `.claude/state/` tree is) so state files are local-only.
8
+
9
+ The first invocation creates the directory if it does not exist (`mkdir -p`). Subsequent invocations write atomically (write to a tmp file, then rename). On read, malformed JSON triggers `state: "blocked"` with `reason: "state file is malformed"`.
10
+
11
+ ## File shape
12
+
13
+ ```jsonc
14
+ {
15
+ "slug": "<kebab-case>",
16
+ "started_at": "<ISO 8601 UTC>",
17
+ "updated_at": "<ISO 8601 UTC>",
18
+ "intent": "<the natural-language intent from task_brief>",
19
+ "register": "brand" | "product",
20
+ "recipe": ["<impeccable_cmd>", ...],
21
+ "step_index": <int, 0-based; index of the NEXT step to run>,
22
+ "invocations": [InvocationRecord, ...],
23
+ "verifications": [VerificationRecord, ...],
24
+ "state": "in_progress" | "complete" | "needs_human" | "blocked" | "not_a_design_task",
25
+ "next_actions": ["<human-readable action>", ...]
26
+ }
27
+ ```
28
+
29
+ ### `InvocationRecord`
30
+
31
+ One record per `Skill(impeccable, ...)` call:
32
+
33
+ ```jsonc
34
+ {
35
+ "cmd": "shape", // impeccable subcommand name
36
+ "iteration": 1, // 1 for non-loop steps; counter inside polish atoms
37
+ "started_at": "<ISO 8601 UTC>",
38
+ "completed_at": "<ISO 8601 UTC>",
39
+ "output_path": "docs/design/<slug>.brief.md" | null,
40
+ "files_written": ["<path>", ...]
41
+ }
42
+ ```
43
+
44
+ ### `VerificationRecord`
45
+
46
+ One record per `audit` or `critique` invocation. These also appear in `invocations[]`; this list collates them for quick access:
47
+
48
+ ```jsonc
49
+ {
50
+ "cmd": "audit",
51
+ "iteration": 2, // matches the iteration in invocations[]
52
+ "score": "17/20",
53
+ "p0": 0,
54
+ "p1": 2,
55
+ "report_path": "docs/design/<slug>.audit.md"
56
+ }
57
+ ```
58
+
59
+ ## Required fields
60
+
61
+ Every state file MUST carry these fields. Stage 3's checkpoint writes them all on each step. The audit-baseline check `state-file: shape` (if added) verifies their presence on any state file under `.claude/state/design/`.
62
+
63
+ | Field | Required | Notes |
64
+ |---|---|---|
65
+ | `slug` | yes | The state file's basename. Self-referential check. |
66
+ | `started_at` | yes | When the orchestration began. Never updated on subsequent steps. |
67
+ | `intent` | yes | The natural-language intent. Used in resume to confirm the user is resuming the same orchestration. |
68
+ | `recipe` | yes | The full step sequence. Set at Stage 2; never mutated. |
69
+ | `step_index` | yes | The position to resume from. 0 = nothing run yet; N = N steps completed. |
70
+ | `invocations` | yes | Append-only list. Each step's invocation appears here. |
71
+ | `verifications` | yes | Subset of invocations[] limited to evaluation steps (audit, critique). |
72
+ | `state` | yes | One of the five terminal/transitional states. |
73
+
74
+ Optional fields:
75
+ - `register`, `updated_at`, `next_actions` — present when the orchestration has produced them; absent before Stage 1 completes the capture.
76
+ - `register_override`, `references`, `target_files`, `write_set` — echoed from the task_brief for traceability; not required.
77
+
78
+ ## Terminal states
79
+
80
+ The five values of `state` and their meaning:
81
+
82
+ | State | Meaning | Caller action |
83
+ |---|---|---|
84
+ | `in_progress` | Orchestration is mid-flight. Either Stage 3 is running or the session ended mid-step. | Resume on next invocation. |
85
+ | `complete` | All recipe steps ran to completion. Final audit/critique passed thresholds. | Read `Report` and continue. |
86
+ | `needs_human` | Loop cap fired (3 iterations on audit→polish or critique-driven refine). P1 issues remain unresolved. | Caller decides whether to surface and stop, or warn and continue. Per `/tdd` Step 6 policy: warn and continue. |
87
+ | `blocked` | A gate fired. P0 blockers, register conflict declined, target_files parent missing, malformed state file, user refused recipe. | Caller surfaces the reason and stops the immediate flow. |
88
+ | `not_a_design_task` | Stage 0 classified the intent as development or copy. Set on the first checkpoint write of the orchestration. | Caller routes to `correct_lane` (`/tdd` or `/document`). |
89
+
90
+ ## Resume logic
91
+
92
+ On any `Skill(design-ui, task_brief)` invocation:
93
+
94
+ 1. Compute the slug (from `task_brief.slug`, or derive from `task_brief.intent` per the kebab-case-first-noun-phrase rule from `/intake`).
95
+ 2. Look for `.claude/state/design/<slug>.json`:
96
+ - **Not present** → fresh orchestration. Start Stage 0.
97
+ - **Present and `state` is `complete`** → return the existing Report; no work to redo.
98
+ - **Present and `state` is `in_progress`** → resume. Skip steps prior to `step_index`; start at `step_index`.
99
+ - **Present and `state` is `needs_human`** → caller must signal intent to resume. If `task_brief` is identical to the stored intent and the caller is re-invoking explicitly, restart the loop from `step_index` (which points at the audit that fired the cap). The user is asserting that conditions have changed (e.g., P1 issues were addressed externally) and the loop should re-run.
100
+ - **Present and `state` is `blocked`** → return the existing Report with the blocker reason. User must materially change the input (re-state intent, expand write_set, etc.) before progress.
101
+ - **Present and `state` is `not_a_design_task`** → return the existing Report; the misroute is sticky for this slug.
102
+ - **Present but malformed JSON** → return `Report { final_state: "blocked", reason: "state file malformed", state_file }`. Do NOT overwrite — preserve for human inspection.
103
+
104
+ The resume rule: **skip steps prior to `step_index`; start at `step_index`**. Completed steps are never re-run unless the user explicitly requests it (e.g., by deleting the state file and re-invoking).
105
+
106
+ ## Atomic writes
107
+
108
+ The state file is written via tmp-then-rename:
109
+
110
+ ```
111
+ 1. write .claude/state/design/<slug>.json.tmp.<pid>
112
+ 2. rename .tmp.<pid> → .json
113
+ ```
114
+
115
+ This prevents partial-write corruption if the process is killed mid-write. Readers always see either the old version or the complete new version.
116
+
117
+ ## What the state file is NOT
118
+
119
+ - Not a transcript of impeccable's design decisions — those live in `docs/design/<slug>.brief.md` and `<slug>.audit.md` (snapshots design-ui materializes from impeccable's returns).
120
+ - Not a log — `_resume.md` carries the session-level continuity snapshot. The state file is specific to one orchestration.
121
+ - Not user-readable as the primary surface — humans should read the brief and audit reports under `docs/design/`. The state file is the machine-readable resume point.
122
+
123
+ ## Related skill memory entry
124
+
125
+ The `audit-baseline` skill checks that this state-machine documentation is present and aligned with any rule it enforces. If a future audit check verifies state-file shape on disk, it parses `.claude/state/design/*.json` and asserts the required fields above are present.
@@ -0,0 +1,66 @@
1
+ ---
2
+ name: document
3
+ owner: baseline
4
+ description: Workflow Phase 10 — orchestrator for documentation work. Surveys the diff, routes technical writing through the `documentation` skill, tutorials through `technical-tutorials`, and all prose body work (inline docs, README updates, user-facing copy) through the `prose` skill (which mandates `humanizer` and conditionally `copywriting`). Verifies completeness and marks phase done.
5
+ ---
6
+
7
+ # document — Phase 10 orchestrator
8
+
9
+ This skill does **not** write docs directly. It surveys the diff, decides what kinds of doc work are needed, and delegates via the Skill tool.
10
+
11
+ | Delegate skill | Kind | Runs on |
12
+ |---|---|---|
13
+ | `prose` | Prose body — any English writing that needs humanizing | inline docs, README surface, user-facing copy, summary/narrative sections |
14
+ | `documentation` | Technical reference | API docs, architecture notes, operational runbooks |
15
+ | `technical-tutorials` | Step-by-step narrative | quickstarts, walkthroughs, code tutorials |
16
+
17
+ The key shift: **`prose` is the sole channel for prose-shaping work**. It owns the `humanizer` pass so every word we ship is filtered. The other two are technical specialists that produce structured reference material; when they output prose paragraphs that matter, they invoke `prose` themselves.
18
+
19
+ ## Prereq
20
+
21
+ `integrate` in `completed` (or `exceptions`).
22
+
23
+ ## When each delegate fires
24
+
25
+ - **`documentation`** — diff touches a public API, config surface, module architecture, or adds runbook-worthy operational behavior. Reference material a future engineer will look up.
26
+ - **`technical-tutorials`** — diff adds a feature a *first-time user* must learn by doing. Hands-on-learning, not lookup-reference.
27
+ - **`prose`** — when prose needs to be written or revised:
28
+ - Narrative sections inside docs the above two skills produce.
29
+ - README surface updates.
30
+ - User-facing marketing/product copy on landing, pricing, feature pages.
31
+ - One-paragraph summaries, migration narratives, release notes.
32
+
33
+ Multiple can fire on one diff. A feature that ships an API, needs a quickstart, and updates the pricing page triggers all three.
34
+
35
+ ## Steps
36
+
37
+ 1. **Verify prereq.** `integrate` is in `completed` or `exceptions`. Otherwise stop and say which phase is missing.
38
+
39
+ 2. **Survey the diff.** `git diff --name-status <merge-base>..HEAD`. Classify touched files:
40
+ - Public API / CLI / contract surfaces → `documentation` candidate.
41
+ - New capability a user learns by doing → `technical-tutorials` candidate.
42
+ - Marketing / pricing / feature / landing pages → `prose` (persuasive register) candidate.
43
+ - README surface or prose anywhere in the diff → `prose` candidate.
44
+ - Internal-only refactor with no external surface → just inline docstrings + the README sanity check.
45
+
46
+ 3. **Always: inline docs.** For every changed public symbol — module-level docstring / header comment / doc comment appropriate to the language. Short. If you need a comment to explain *what*, the abstraction is wrong; comments are for non-obvious *why*.
47
+
48
+ 4. **Delegate.** For each matched category, invoke the delegate skill with a scoped brief:
49
+ - `documentation` / `technical-tutorials`: invoke via `Skill(...)`. Include the diff slice, upstream spec/intake, and the specific deliverable (e.g., "API reference for the new retry endpoint"). Read its output and incorporate it.
50
+ - `prose`: invoke via `Skill(prose)` with brief, source material (diff slice, spec excerpt), audience, register, and output target (file path or section). The `prose` skill applies `humanizer` always, plus the conditional skill you name.
51
+
52
+ 5. **README surface check.** If the root `README.md` or any top-level doc claims behavior the diff changed, update it — route through `prose` so the copy gets humanized.
53
+
54
+ 6. **Scrub.** No `TODO` / `FIXME` / `HACK` / `XXX` in files this phase touched. Seed.md forbids them; humanizer doesn't catch them.
55
+
56
+ 7. **Append `"document"` to `.claude/state/workflow.json → completed`.**
57
+
58
+ 8. Tell the user: "Documentation pass complete. Invoked: `<list of delegates>`. Next: `/archive`."
59
+
60
+ ## Constraints
61
+
62
+ - **Delegation is mandatory.** You do not write prose here; `prose` does. You do not write API reference here; `documentation` does. You do not write tutorials here; `technical-tutorials` does. This skill decides *who* writes *what* and stitches the result.
63
+ - **Do not skip the humanizer pass.** Everything in `prose` runs it. If you find yourself tempted to write a README paragraph inline to save a hop, don't — route it through `prose`.
64
+ - **Do not invoke delegates that don't apply.** Internal refactor with no external surface? Don't fire `prose` (persuasive register) just because the skill is available. Step 2's survey gates the invocations.
65
+ - **Keep this skill lightweight.** The body is mostly "decide → delegate → verify → mark done". Heavy lifting lives in the delegates.
66
+ - **YAGNI on docs.** A doc exists because the code change made it necessary. No speculative documentation.
@@ -0,0 +1,50 @@
1
+ ---
2
+ name: documentation
3
+ owner: baseline
4
+ description: Write and maintain technical documentation. Trigger with "write docs for", "document this", "create a README", "write a runbook", "onboarding guide", or when the user needs help with any form of technical writing — API docs, architecture docs, or operational runbooks.
5
+ ---
6
+
7
+ # Technical Documentation
8
+
9
+ Write clear, maintainable technical documentation for different audiences and purposes.
10
+
11
+ ## Document Types
12
+
13
+ ### README
14
+ - What this is and why it exists
15
+ - Quick start (< 5 minutes to first success)
16
+ - Configuration and usage
17
+ - Contributing guide
18
+
19
+ ### API Documentation
20
+ - Endpoint reference with request/response examples
21
+ - Authentication and error codes
22
+ - Rate limits and pagination
23
+ - SDK examples
24
+
25
+ ### Runbook
26
+ - When to use this runbook
27
+ - Prerequisites and access needed
28
+ - Step-by-step procedure
29
+ - Rollback steps
30
+ - Escalation path
31
+
32
+ ### Architecture Doc
33
+ - Context and goals
34
+ - High-level design with diagrams
35
+ - Key decisions and trade-offs
36
+ - Data flow and integration points
37
+
38
+ ### Onboarding Guide
39
+ - Environment setup
40
+ - Key systems and how they connect
41
+ - Common tasks with walkthroughs
42
+ - Who to ask for what
43
+
44
+ ## Principles
45
+
46
+ 1. **Write for the reader** — Who is reading this and what do they need?
47
+ 2. **Start with the most useful information** — Don't bury the lede
48
+ 3. **Show, don't tell** — Code examples, commands, screenshots
49
+ 4. **Keep it current** — Outdated docs are worse than no docs
50
+ 5. **Link, don't duplicate** — Reference other docs instead of copying
@@ -0,0 +1,169 @@
1
+ ---
2
+ name: harness
3
+ owner: baseline
4
+ description: End-to-end workflow orchestrator. Walks the 11-phase pipeline, invoking each phase skill in order inside an internal loop, yielding at consent gates (/approve-spec, /approve-swarm, /grant-commit), and exiting cleanly on yield/failure/done. Decides swarm-vs-solo at Phase 6. Auto-loops /tdd on integrate failures that don't require a spec change. The harness_continuation Stop hook is a safety net that re-fires harness only when the loop exited mid-flow.
5
+ argument-hint: "[optional: \"<request in plain English>\" on fresh start]"
6
+ ---
7
+
8
+ # harness — workflow orchestrator with internal loop
9
+
10
+ User-invokable and model-invokable. The harness chains the 11-phase pipeline by **looping internally through non-gated phases** until the loop hits one of four exit conditions: consent gate, phase-skill failure, integrate-failure-needs-spec-change, or workflow done. The user types only at consent gates (`/approve-spec`, `/approve-swarm`, `/grant-commit`) and at integrate-failure decisions that need a spec change.
11
+
12
+ ## Internal loop atomicity (the contract)
13
+
14
+ A single `Skill(harness)` invocation **loops through every non-gated phase boundary** in one user turn. Inside the loop, each iteration invokes exactly one phase skill via the `Skill` tool, updates state and TaskList, then re-enters the loop. The loop exits — and the model emits its terminal message — only when one of these four conditions holds:
15
+
16
+ - **Yield**: the next pending task carries `metadata.needs_user: true` (consent gate, or integrate-failure-needs-spec-change). Write `harness_state: yielded`; surface the gate; exit.
17
+ - **Phase-skill failure**: a `Skill(<phase>)` call returned error. Write `harness_state: yielded` with `reason: "<phase> failed: <summary>"`; surface; exit.
18
+ - **Done**: `workflow.json → completed` now contains every non-excepted phase. Write `harness_state: done`; surface completion; exit.
19
+ - **(Rare) Mid-loop interruption**: the model decides to stop emitting before any of the above (context pressure, runtime limit, external interruption). The on-disk state stays `state: continue` with the marker present — the Stop hook safety net handles this.
20
+
21
+ `.claude/state/harness_state` is flat JSON with one of three states:
22
+
23
+ - `continue` — the harness is in the loop body (or was interrupted mid-loop). The Stop hook safety net is armed.
24
+ - `yielded` — the loop exited cleanly at a gate or failure. Stop hook stays silent.
25
+ - `done` — the loop exited cleanly at workflow completion. Stop hook stays silent.
26
+
27
+ The state file shape:
28
+
29
+ ```json
30
+ {
31
+ "state": "continue|yielded|done",
32
+ "slug": "<workflow slug>",
33
+ "reason": "<one sentence>"
34
+ }
35
+ ```
36
+
37
+ Exactly three fields. No `written_at`, no `tick_count` — those tunables were removed in the active-marker redesign. The internal-loop redesign retains the shape; the meaning of `state: continue` shifted from "next tick will be auto-fired by the hook" to "the harness is inside the loop body (or was interrupted)".
38
+
39
+ ### The safety net
40
+
41
+ The `harness_continuation` Stop hook (Article VIII) is a safety net only. Its three-rung gate (`stop_hook_active` absent → `.harness_active` marker exists → `state == "continue"`) emits `{"decision":"block","reason":"…invoke Skill(harness)…"}` **only when the loop exited mid-flow** without writing `yielded`/`done` — i.e., the loop iteration completed an arm-but-did-not-exit-cleanly path. In normal operation (loop runs to gate/failure/done), the hook sees `state != continue` or marker absent, stays silent, and the turn ends naturally. The hook is unchanged by the internal-loop redesign; what changed is the harness skill, which now exits the loop with `yielded`/`done` in the common case, leaving the hook quiescent.
42
+
43
+ ### Marker-then-state ordering (every state-write)
44
+
45
+ Before writing `harness_state`, do the marker op FIRST:
46
+
47
+ - On `state: "continue"` → `echo "<slug>" > .claude/state/.harness_active` (creates or refreshes the marker).
48
+ - On `state: "yielded"` or `state: "done"` → `rm -f .claude/state/.harness_active` (deletes; safe if absent).
49
+
50
+ THEN write `harness_state`. The marker is the session-scoped "in the loop" signal; partial-write resilience requires marker-first ordering so a crash between steps leaves the conservative state on disk.
51
+
52
+ ## Preflight (once per Skill(harness) invocation, before entering the loop)
53
+
54
+ 1. **Project configured?** Read `.claude/project.json`. If `configured: false` → stop with: "Run `/init-project` first. The baseline hooks are in guide mode until the project is configured."
55
+ 2. **Continuity check.** Read `.claude/memory/_resume.md` if present. This is the cross-session snapshot written by the PreCompact and Stop hooks; it tells you what the prior session was actually doing in conversational terms.
56
+ 3. **Fresh start or resume?**
57
+ - `.claude/state/workflow.json` exists → **resume**.
58
+ - Absent → **fresh start**. The argument (or surrounding conversation) is the request; proceed to Pillar 1.
59
+ 4. **Ground the user before acting.** When `_resume.md` is present, open with one sentence summarizing where things stood. Grounding only — do not invent state not in `workflow.json`.
60
+ 5. **Detect divergence.** If `_resume.md`'s recent prompts contradict `workflow.json` (e.g., the user said "actually skip security" mid-session and `exceptions` doesn't reflect it), do **not** auto-proceed. Surface as a clarifying question. Memory accelerates triage; it never authorizes a skip.
61
+ 6. **Arm the safety net.** Marker FIRST: `echo "<slug>" > .claude/state/.harness_active`. Then write `harness_state` with `{state: "continue", slug, reason: "loop armed; preflight passed"}`. This pair stays in place for the entire loop; mid-loop crashes are now covered by the Stop hook.
62
+
63
+ Log every transition to `.claude/state/harness/<slug>.log` with timestamp + `entered <phase>` / `completed <phase>` / `yielded at <gate>`.
64
+
65
+ ## The loop body
66
+
67
+ Inside each iteration:
68
+
69
+ 1. **TaskList.** If empty (first invocation in a fresh session, or session-bound state was reset), **re-seed**: read `workflow.json → completed + exceptions + entry_phase` and recreate tasks for every remaining phase using the canonical templates from `triage`'s SKILL.md. Skip phases already in `completed`. Wire `addBlockedBy` so the dependency chain is preserved.
70
+ 2. **Pick the next action.** Find the lowest-id `pending` task whose `blockedBy` list is empty.
71
+ 3. **If no pending task remains** (workflow complete), **EXIT LOOP with DONE**:
72
+ - Marker FIRST: `rm -f .claude/state/.harness_active`.
73
+ - Write `harness_state` with `{state: "done", slug, reason: "workflow complete"}`.
74
+ - Break out of the loop; the terminal message is emitted after loop exit.
75
+ 4. **If `task.metadata.needs_user == true`** (consent-gate placeholder), **EXIT LOOP with YIELD**:
76
+ - Marker FIRST: `rm -f .claude/state/.harness_active`.
77
+ - Write `harness_state` with `{state: "yielded", slug, reason: "yielded at /<gate>"}` — exactly three fields.
78
+ - Break out of the loop; the terminal message names the consent command for the user to run.
79
+ 5. **Otherwise INVOKE the phase skill:**
80
+ - `TaskUpdate` to `in_progress` (set `activeForm` to the imperative-progressive form, e.g. "Running scout").
81
+ - Log `entered <phase>` to `.claude/state/harness/<slug>.log`.
82
+ - Invoke the matching phase skill via the **`Skill` tool — one invocation per loop iteration**.
83
+ - On phase-skill success:
84
+ - `TaskUpdate` to `completed`.
85
+ - Append the phase name to `workflow.json → completed`; update `updated_at`.
86
+ - Log `completed <phase>`.
87
+ - Refresh the marker (`echo "<slug>" > .claude/state/.harness_active`) and rewrite `harness_state` with `{state: "continue", slug, reason: "<phase> done; next: <next phase>"}`.
88
+ - **Continue the loop** to the next iteration (return to step 1).
89
+ - On phase-skill failure (non-integrate):
90
+ - Leave the task `in_progress` (do NOT mark `completed`).
91
+ - Do NOT append to `workflow.json → completed`.
92
+ - **EXIT LOOP with YIELD**: marker FIRST (`rm -f .claude/state/.harness_active`), then write `harness_state` with `{state: "yielded", slug, reason: "<phase> failed: <one-line summary>"}`.
93
+ - Surface the error; break out of the loop.
94
+ - On `/integrate` failure: classify per the **Integrate-failure decision tree** below. If auto-loop, re-invoke `Skill(tdd)` and `Skill(integrate)` inside this same loop iteration (the auto-loop happens in-place, not via a new loop iteration). If stop-and-surface, **EXIT LOOP with YIELD** as above.
95
+
96
+ After the loop exits, emit a single terminal message naming the workflow state. Do not emit per-iteration terminal messages — those would invite the model to stop emitting mid-loop and trigger the safety net unnecessarily.
97
+
98
+ **Resume after a `needs_user` yield**: the user runs the consent command, then `/harness` again. The next Skill(harness) invocation re-enters preflight, finds the consent-gate task with its `needs_user` flag still set but the gate now satisfied (token on disk), marks that task `completed`, and proceeds into the loop body.
99
+
100
+ **Drift between TaskList and `workflow.json → completed`**: `workflow.json → completed` is durable across sessions; TaskList is session-bound. When they disagree, trust `workflow.json` and rebuild the task state to match.
101
+
102
+ ## Phase ordering — the 11-phase pipeline
103
+
104
+ The phases the harness loops through, in order:
105
+
106
+ ```
107
+ intake → scout → research → spec → /approve-spec → tdd → simplify →
108
+ security → integrate → document → archive → /grant-commit → commit
109
+ ```
110
+
111
+ - Phases listed in `workflow.json → exceptions` are skipped.
112
+ - Non-git projects auto-except `grant-commit` and `commit`; the workflow ends after `/archive`.
113
+ - The four-pillar framing (Intake analysis · Track alignment · Implementation · Tying open ends) is documentary; the actual execution model is one phase per loop iteration, with the loop continuing through every non-gated boundary until it exits cleanly.
114
+
115
+ ### Swarm vs solo at Phase 6
116
+
117
+ Once the spec approval token is present on resume, count C4 Components in the approved spec:
118
+
119
+ ```
120
+ grep -cE '^\s*Component\(' docs/specs/<slug>.md
121
+ ```
122
+
123
+ - Count ≥ `project.json → swarm.min_tasks_worth_swarming` (default 3) **and** the components are genuinely independent (their dependency graph has ≥ 2 nodes with no cross-edge) **and** the project is a git repository (`git rev-parse --is-inside-work-tree` exits 0) → **swarm path**: `swarm-plan` → `/approve-swarm` → `swarm-dispatch`.
124
+ - Otherwise → **solo path**: `tdd` directly.
125
+ - Non-git projects never reach the swarm path: `/triage` auto-excepts `swarm-plan`, `approve-swarm`, and `swarm-dispatch` at workflow-creation time per CLAUDE.md Article IV ("Phase 6c and Phase 11 are git-conditional"), so the harness sees them in `exceptions` and routes Phase 6 straight to `/tdd`.
126
+ - User can override in conversation: "run /tdd solo for this one" or "use swarm." Log the override. A "use swarm" override on a non-git project SHALL be refused with the reason `swarm requires git; swarm phases are excepted on this workflow`.
127
+
128
+ ## Integrate-failure decision tree
129
+
130
+ When `/integrate` fails inside the loop, judge: is this a simple bug (auto-retryable in-place) or does it need human input on scope/spec?
131
+
132
+ **Auto-loop to `/tdd`** when **all** of these hold:
133
+ - The failing tests are assertions on behavior the spec clearly defines.
134
+ - The failure is localized (one component, one AC, no cross-spec contract conflict).
135
+ - The fix is mechanical (implementation mismatch, edge case missed, off-by-one).
136
+
137
+ On auto-loop: invoke `Skill(tdd)` with a brief telling it to focus on the failing test(s) only, then invoke `Skill(integrate)` again — **both calls happen inside the same loop iteration** (no Stop-hook hop, no new user `/harness` invocation needed). Cap at 3 auto-loops within one iteration; if still red after 3, stop and surface (exit loop with yield).
138
+
139
+ **Stop and surface** when **any** of these hold:
140
+ - The failing test expects behavior the spec doesn't define → spec change needed.
141
+ - The test exposes a contradiction between two spec ACs → spec change needed.
142
+ - The failure reveals a component or interaction the spec doesn't name → scope expansion.
143
+ - A swarm-dispatch integration failure spans components dispatched in different waves (coupling the spec missed).
144
+
145
+ On surface: exit the loop with `harness_state` `state: "yielded"`, `reason: "integrate failed: needs spec change"`. Show the failing test output, name which criterion tripped, and tell the user: "This needs a spec change / scope decision. Update `docs/specs/<slug>.md`, re-run `/approve-spec`, then `/harness` to resume."
146
+
147
+ ## State machine (resume logic)
148
+
149
+ On each `/harness` invocation, read `workflow.json` and decide whether to enter the loop and at which task:
150
+
151
+ | Condition | Action |
152
+ |---|---|
153
+ | No `workflow.json` | Fresh start → Pillar 1 |
154
+ | `completed` contains all non-excepted phases | Enter loop; loop exits immediately with `state: done` |
155
+ | `completed` contains `spec` but no `spec_approvals/<slug>.approval` token | Enter loop; loop exits at first iteration with `state: yielded` (approve-spec gate) |
156
+ | `completed` contains `spec` **and** approval token present, but `tdd`/`swarm-dispatch` not in `completed` | Enter loop; decide swarm-vs-solo at first iteration; invoke the next phase |
157
+ | `completed` contains `swarm-plan` but no `swarm_approvals/<slug>.approval` | Enter loop; loop exits with `state: yielded` (approve-swarm gate) |
158
+ | `completed` contains `archive` but no `commit_consent` (git project) | Enter loop; loop exits with `state: yielded` (grant-commit gate) |
159
+ | Phase skill returned an error this invocation | Loop exits with phase-failure reason; user investigates |
160
+
161
+ ## Constraints
162
+
163
+ - **Never skip a consent gate.** If the approval/consent token is missing, the loop exits with `state: yielded`. Never generate the token yourself.
164
+ - **Never auto-proceed past an integrate failure** outside the decision-tree criteria above.
165
+ - **Never re-run a phase already in `workflow.json → completed`** unless the user explicitly asks.
166
+ - **Every phase invocation inside the loop uses the Skill tool — one invocation per loop iteration.** Do not re-implement phase logic here.
167
+ - **Always refresh `harness_state` after each successful phase invocation** (still `state: continue` during the loop body). The safety net depends on the marker + state being consistent.
168
+ - **Log every transition** to `.claude/state/harness/<slug>.log`.
169
+ - **If the user overrides a decision in conversation** (e.g., "skip security", "force swarm"), honor the override and log it as a manual adjustment.