cohorte 3.0.0-dev.8 → 3.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 (251) hide show
  1. package/CHANGELOG.md +1637 -0
  2. package/README.md +322 -62
  3. package/bin/cli.js +213 -0
  4. package/bin/report.js +141 -0
  5. package/core/agents/cohorte-profile-reader.md +40 -0
  6. package/core/agents/cohorte-release.md +61 -0
  7. package/core/agents/cohorte-review.md +200 -0
  8. package/core/agents/implementer.template.md +154 -0
  9. package/core/commands/cohorte-align-ds.md +33 -0
  10. package/core/commands/cohorte-audit.md +74 -0
  11. package/core/commands/cohorte-brainstorm.md +73 -0
  12. package/core/commands/cohorte-build.md +248 -0
  13. package/core/commands/cohorte-doctor.md +135 -0
  14. package/core/commands/cohorte-fix.md +80 -0
  15. package/core/commands/cohorte-fleet.md +111 -0
  16. package/core/commands/cohorte-init-pipeline.md +30 -0
  17. package/core/commands/cohorte-intake.md +92 -0
  18. package/core/commands/cohorte-patch.md +118 -0
  19. package/core/commands/cohorte-refactor.md +122 -0
  20. package/core/commands/cohorte-retro.md +85 -0
  21. package/core/commands/cohorte-revert.md +104 -0
  22. package/core/commands/cohorte-review.md +239 -0
  23. package/core/commands/cohorte-ship.md +167 -0
  24. package/core/commands/cohorte-spec.md +114 -0
  25. package/core/commands/cohorte-update-pipeline.md +119 -0
  26. package/core/commands/cohorte-verify.md +106 -0
  27. package/core/hooks/gate.py +3236 -0
  28. package/core/templates/agent-handoff.md +34 -0
  29. package/core/templates/brainstorm-return.md +42 -0
  30. package/core/templates/decisions.template.md +42 -0
  31. package/core/templates/design-brief.md +37 -0
  32. package/core/templates/patch.template.md +95 -0
  33. package/core/templates/pr-body.md +25 -0
  34. package/core/templates/review-feedback.md +46 -0
  35. package/core/templates/spec.template.md +109 -0
  36. package/core/templates/steps/init-pipeline/01-detect-stack.md +53 -0
  37. package/core/templates/steps/init-pipeline/02-interview-gaps.md +78 -0
  38. package/core/templates/steps/init-pipeline/03-draft-profile.md +10 -0
  39. package/core/templates/steps/init-pipeline/04-write-render.md +95 -0
  40. package/core/templates/steps/init-pipeline/05-report.md +11 -0
  41. package/core/templates/steps/review-pr/01-pr-mode.md +54 -0
  42. package/core/workflows/audit.js +311 -0
  43. package/core/workflows/loop.js +692 -0
  44. package/core/workflows/refactor.js +398 -0
  45. package/core/workflows/review.js +505 -0
  46. package/install.ps1 +72 -0
  47. package/install.sh +69 -0
  48. package/lib/doctor.js +506 -0
  49. package/lib/install.js +386 -0
  50. package/lib/project.js +359 -0
  51. package/lib/render.js +121 -0
  52. package/lib/versions.js +145 -0
  53. package/lib/yaml.js +183 -0
  54. package/package.json +36 -17
  55. package/profile/PIPELINE.template.md +288 -0
  56. package/profile/SCHEMA.md +30 -0
  57. package/profile/cohorte.config.template.yaml +43 -0
  58. package/profile/schema/dead-agents.md +29 -0
  59. package/profile/schema/decisions.md +23 -0
  60. package/profile/schema/deferred.md +22 -0
  61. package/profile/schema/feature-diff.md +20 -0
  62. package/profile/schema/kanban.md +95 -0
  63. package/profile/schema/metrics.md +23 -0
  64. package/profile/schema/output-discipline.md +21 -0
  65. package/profile/schema/preflight.md +81 -0
  66. package/profile/schema/profile-block.md +103 -0
  67. package/profile/schema/project-kinds.md +89 -0
  68. package/profile/schema/readiness.md +17 -0
  69. package/profile/schema/reconcile.md +64 -0
  70. package/profile/schema/release-notes.md +29 -0
  71. package/profile/schema/rendering.md +48 -0
  72. package/profile/schema/retrieval.md +58 -0
  73. package/profile/schema/spec-status.md +79 -0
  74. package/profile/schema/specialization.md +41 -0
  75. package/profile/schema/verify.md +115 -0
  76. package/profile/schema/workflows.md +78 -0
  77. package/scripts/feature-diff.sh +118 -0
  78. package/scripts/kanban-move.sh +349 -0
  79. package/scripts/metrics/collect.mjs +542 -0
  80. package/scripts/metrics/prices.json +42 -0
  81. package/scripts/new-feature.sh.template +122 -0
  82. package/scripts/preflight.sh +114 -0
  83. package/scripts/remove-feature.sh.template +56 -0
  84. package/scripts/verify-run.sh +509 -0
  85. package/assets/manifest.json +0 -203
  86. package/assets/migrations/config/README.md +0 -12
  87. package/assets/migrations/state/0001_init.sql +0 -154
  88. package/assets/prompts/README.md +0 -11
  89. package/assets/prompts/agents/brainstormer.md +0 -3
  90. package/assets/prompts/agents/fixer.md +0 -7
  91. package/assets/prompts/agents/implementer.md +0 -12
  92. package/assets/prompts/agents/reviewer.md +0 -8
  93. package/assets/prompts/agents/security-reviewer.md +0 -7
  94. package/assets/prompts/agents/spec-author.md +0 -3
  95. package/assets/prompts/phases/build.md +0 -5
  96. package/assets/prompts/phases/review.md +0 -5
  97. package/assets/prompts/phases/test.md +0 -5
  98. package/assets/prompts/system.md +0 -11
  99. package/assets/schemas/agent-output.schema.json +0 -225
  100. package/assets/schemas/auth-status.schema.json +0 -87
  101. package/assets/schemas/command-result.schema.json +0 -192
  102. package/assets/schemas/commands.schema.json +0 -959
  103. package/assets/schemas/config.schema.json +0 -2281
  104. package/assets/schemas/doctor-report.schema.json +0 -104
  105. package/assets/schemas/events.schema.json +0 -8514
  106. package/assets/schemas/fake-script.schema.json +0 -549
  107. package/assets/schemas/inspect.schema.json +0 -3133
  108. package/assets/schemas/manifest.schema.json +0 -79
  109. package/assets/schemas/ownership.schema.json +0 -52
  110. package/assets/schemas/policy-verdict.schema.json +0 -282
  111. package/assets/schemas/project-model.schema.json +0 -783
  112. package/assets/schemas/project-status.schema.json +0 -217
  113. package/assets/schemas/reconcile-plan.schema.json +0 -154
  114. package/assets/schemas/run-diff.schema.json +0 -177
  115. package/assets/schemas/run-snapshot-manifest.schema.json +0 -2104
  116. package/assets/schemas/run-state.schema.json +0 -1755
  117. package/assets/schemas/runtime-capabilities.schema.json +0 -1545
  118. package/assets/schemas/sandbox-capabilities.schema.json +0 -116
  119. package/assets/schemas/skill.schema.json +0 -87
  120. package/assets/schemas/spec.schema.json +0 -202
  121. package/assets/schemas/tool-catalogue.schema.json +0 -655
  122. package/assets/schemas/trust-record.schema.json +0 -38
  123. package/assets/skills/README.md +0 -9
  124. package/assets/skills/inspect-surface.md +0 -4
  125. package/dist/agent-host.mjs +0 -2187
  126. package/dist/agent-host.mjs.map +0 -1
  127. package/dist/bundle-manifest.json +0 -128
  128. package/dist/chunks/__host-DgGPyco9.mjs +0 -18
  129. package/dist/chunks/__host-DgGPyco9.mjs.map +0 -1
  130. package/dist/chunks/align-ds-r_X_1aQ_.mjs +0 -93
  131. package/dist/chunks/align-ds-r_X_1aQ_.mjs.map +0 -1
  132. package/dist/chunks/approve-Cv135UqI.mjs +0 -19
  133. package/dist/chunks/approve-Cv135UqI.mjs.map +0 -1
  134. package/dist/chunks/audit-B4ZWQ_DI.mjs +0 -179
  135. package/dist/chunks/audit-B4ZWQ_DI.mjs.map +0 -1
  136. package/dist/chunks/auth-BT5oVp76.mjs +0 -132
  137. package/dist/chunks/auth-BT5oVp76.mjs.map +0 -1
  138. package/dist/chunks/auth-Dnlksuo5.mjs +0 -141
  139. package/dist/chunks/auth-Dnlksuo5.mjs.map +0 -1
  140. package/dist/chunks/brainstorm-SJwOIEif.mjs +0 -123
  141. package/dist/chunks/brainstorm-SJwOIEif.mjs.map +0 -1
  142. package/dist/chunks/build-C_-mbZfD.mjs +0 -19
  143. package/dist/chunks/build-C_-mbZfD.mjs.map +0 -1
  144. package/dist/chunks/cancel-KV_cpsqS.mjs +0 -15
  145. package/dist/chunks/cancel-KV_cpsqS.mjs.map +0 -1
  146. package/dist/chunks/canonical-C8UxeEmB.mjs +0 -57
  147. package/dist/chunks/canonical-C8UxeEmB.mjs.map +0 -1
  148. package/dist/chunks/catalogue-IaCJdfB8.mjs +0 -1549
  149. package/dist/chunks/catalogue-IaCJdfB8.mjs.map +0 -1
  150. package/dist/chunks/compose-DRKjQcn0.mjs +0 -7333
  151. package/dist/chunks/compose-DRKjQcn0.mjs.map +0 -1
  152. package/dist/chunks/config-Cqu5XQoP.mjs +0 -96
  153. package/dist/chunks/config-Cqu5XQoP.mjs.map +0 -1
  154. package/dist/chunks/contract-DjssDPpS.mjs +0 -335
  155. package/dist/chunks/contract-DjssDPpS.mjs.map +0 -1
  156. package/dist/chunks/contract-bQ9FJl4N.mjs +0 -123
  157. package/dist/chunks/contract-bQ9FJl4N.mjs.map +0 -1
  158. package/dist/chunks/deny-ClTxSvHJ.mjs +0 -15
  159. package/dist/chunks/deny-ClTxSvHJ.mjs.map +0 -1
  160. package/dist/chunks/diff-Qw0II0sj.mjs +0 -101
  161. package/dist/chunks/diff-Qw0II0sj.mjs.map +0 -1
  162. package/dist/chunks/discover-BZPolSZG.mjs +0 -21
  163. package/dist/chunks/discover-BZPolSZG.mjs.map +0 -1
  164. package/dist/chunks/doctor-DcDFPvQM.mjs +0 -222
  165. package/dist/chunks/doctor-DcDFPvQM.mjs.map +0 -1
  166. package/dist/chunks/fix-C9roGiQz.mjs +0 -82
  167. package/dist/chunks/fix-C9roGiQz.mjs.map +0 -1
  168. package/dist/chunks/fleet-yWHQY2ya.mjs +0 -297
  169. package/dist/chunks/fleet-yWHQY2ya.mjs.map +0 -1
  170. package/dist/chunks/gc-BBXlBF5w.mjs +0 -161
  171. package/dist/chunks/gc-BBXlBF5w.mjs.map +0 -1
  172. package/dist/chunks/init--FxxkrcT.mjs +0 -63
  173. package/dist/chunks/init--FxxkrcT.mjs.map +0 -1
  174. package/dist/chunks/inspect-Buby4cQD.mjs +0 -22
  175. package/dist/chunks/inspect-Buby4cQD.mjs.map +0 -1
  176. package/dist/chunks/intake-C1pesxCJ.mjs +0 -12
  177. package/dist/chunks/intake-C1pesxCJ.mjs.map +0 -1
  178. package/dist/chunks/logs-Giq5sUau.mjs +0 -25
  179. package/dist/chunks/logs-Giq5sUau.mjs.map +0 -1
  180. package/dist/chunks/loop-BWsUpyus.mjs +0 -212
  181. package/dist/chunks/loop-BWsUpyus.mjs.map +0 -1
  182. package/dist/chunks/migrate-DuYCAbE3.mjs +0 -33
  183. package/dist/chunks/migrate-DuYCAbE3.mjs.map +0 -1
  184. package/dist/chunks/models-Btp6X2YZ.mjs +0 -24
  185. package/dist/chunks/models-Btp6X2YZ.mjs.map +0 -1
  186. package/dist/chunks/obsidian-BHLkXx_H.mjs +0 -235
  187. package/dist/chunks/obsidian-BHLkXx_H.mjs.map +0 -1
  188. package/dist/chunks/patch-sAgVqjpx.mjs +0 -50
  189. package/dist/chunks/patch-sAgVqjpx.mjs.map +0 -1
  190. package/dist/chunks/pause-BASBfKLO.mjs +0 -16
  191. package/dist/chunks/pause-BASBfKLO.mjs.map +0 -1
  192. package/dist/chunks/policy-Du7WVBFX.mjs +0 -139
  193. package/dist/chunks/policy-Du7WVBFX.mjs.map +0 -1
  194. package/dist/chunks/providers-Dx78imKj.mjs +0 -19
  195. package/dist/chunks/providers-Dx78imKj.mjs.map +0 -1
  196. package/dist/chunks/reconcile-BHn66X3C.mjs +0 -50
  197. package/dist/chunks/reconcile-BHn66X3C.mjs.map +0 -1
  198. package/dist/chunks/refactor-DV3RfGjk.mjs +0 -153
  199. package/dist/chunks/refactor-DV3RfGjk.mjs.map +0 -1
  200. package/dist/chunks/render-DyZr5Lgi.mjs +0 -53
  201. package/dist/chunks/render-DyZr5Lgi.mjs.map +0 -1
  202. package/dist/chunks/resume-GJQRb2Eb.mjs +0 -15
  203. package/dist/chunks/resume-GJQRb2Eb.mjs.map +0 -1
  204. package/dist/chunks/retro-Dr-2RTNN.mjs +0 -78
  205. package/dist/chunks/retro-Dr-2RTNN.mjs.map +0 -1
  206. package/dist/chunks/retry-CLrUem1H.mjs +0 -15
  207. package/dist/chunks/retry-CLrUem1H.mjs.map +0 -1
  208. package/dist/chunks/review-ZsBqp3vZ.mjs +0 -35
  209. package/dist/chunks/review-ZsBqp3vZ.mjs.map +0 -1
  210. package/dist/chunks/run-BGabwbDL.mjs +0 -109
  211. package/dist/chunks/run-BGabwbDL.mjs.map +0 -1
  212. package/dist/chunks/run-tool-C3rAv4XF.mjs +0 -26
  213. package/dist/chunks/run-tool-C3rAv4XF.mjs.map +0 -1
  214. package/dist/chunks/scan-C5uDr7Yq.mjs +0 -167
  215. package/dist/chunks/scan-C5uDr7Yq.mjs.map +0 -1
  216. package/dist/chunks/schema-Bq9qtgsd.mjs +0 -583
  217. package/dist/chunks/schema-Bq9qtgsd.mjs.map +0 -1
  218. package/dist/chunks/send-BdnJ85Nz.mjs +0 -19
  219. package/dist/chunks/send-BdnJ85Nz.mjs.map +0 -1
  220. package/dist/chunks/ship-BizfUe62.mjs +0 -140
  221. package/dist/chunks/ship-BizfUe62.mjs.map +0 -1
  222. package/dist/chunks/shutdown-BM92Iyv2.mjs +0 -15
  223. package/dist/chunks/shutdown-BM92Iyv2.mjs.map +0 -1
  224. package/dist/chunks/skip-DZG5kpcH.mjs +0 -18
  225. package/dist/chunks/skip-DZG5kpcH.mjs.map +0 -1
  226. package/dist/chunks/spec-C2h3U64g.mjs +0 -65
  227. package/dist/chunks/spec-C2h3U64g.mjs.map +0 -1
  228. package/dist/chunks/spec-path-tptqR7W8.mjs +0 -10
  229. package/dist/chunks/spec-path-tptqR7W8.mjs.map +0 -1
  230. package/dist/chunks/src-Bfr1yzsn.mjs +0 -1689
  231. package/dist/chunks/src-Bfr1yzsn.mjs.map +0 -1
  232. package/dist/chunks/src-CPW2_Ons.mjs +0 -5487
  233. package/dist/chunks/src-CPW2_Ons.mjs.map +0 -1
  234. package/dist/chunks/src-Cu3TxNob.mjs +0 -783
  235. package/dist/chunks/src-Cu3TxNob.mjs.map +0 -1
  236. package/dist/chunks/src-DNsLSxgm.mjs +0 -928
  237. package/dist/chunks/src-DNsLSxgm.mjs.map +0 -1
  238. package/dist/chunks/src-DbS9gkJy.mjs +0 -117
  239. package/dist/chunks/src-DbS9gkJy.mjs.map +0 -1
  240. package/dist/chunks/src-yi5whv3n.mjs +0 -2118
  241. package/dist/chunks/src-yi5whv3n.mjs.map +0 -1
  242. package/dist/chunks/status-SMjiOMYy.mjs +0 -29
  243. package/dist/chunks/status-SMjiOMYy.mjs.map +0 -1
  244. package/dist/chunks/tail-BuhT-2PH.mjs +0 -25
  245. package/dist/chunks/tail-BuhT-2PH.mjs.map +0 -1
  246. package/dist/chunks/update-BXIppsbi.mjs +0 -16
  247. package/dist/chunks/update-BXIppsbi.mjs.map +0 -1
  248. package/dist/chunks/update-pipeline-Du-Gu1Pl.mjs +0 -56
  249. package/dist/chunks/update-pipeline-Du-Gu1Pl.mjs.map +0 -1
  250. package/dist/cli.mjs +0 -186
  251. package/dist/cli.mjs.map +0 -1
@@ -0,0 +1,48 @@
1
+ ## Rendering / reconciling a surface agent (shared procedure)
2
+
3
+ Both `/cohorte-init-pipeline` (initial render) and `/cohorte-build` (auto-reconcile when a spec needs a new agent) use
4
+ this exact procedure so a surface is always defined the same way. To add surface `S`:
5
+
6
+ 1. **Add the `surfaces[]` entry** to `PIPELINE.md`: `key`, `path` (the disjoint tree it exclusively
7
+ owns), `label`, `agent` (rendered file name), `tools` (add `DesignSync` only if `uses_design: true`;
8
+ append the retrieval provider's MCP tools when `retrieval.provider` ≠ `none` — e.g. `mcp__serena`),
9
+ `model` (tier for the rendered agent: `sonnet` (default) — the implementer mostly applies a frozen
10
+ contract, which Sonnet does well at a fraction of the Opus-lead cost; `haiku` for purely mechanical
11
+ scaffolding; `inherit` only when the surface makes real design decisions worth the lead's model),
12
+ the five `*_cmd`s (derive from the surface's `package.json` / workspace
13
+ filter, mirroring a sibling surface), and `uses_design`. Then run `<sync>`: it regenerates
14
+ `<state>/profile.json` (the parsed machine block agents read), which otherwise lacks `S`.
15
+ 2. **Render the agent file** `<agents>/<agent>.md` from `<core>/pipeline/implementer.template.md`
16
+ — the template is already rendered for this runtime, so only the placeholders are yours to fill —
17
+ substituting `<SURFACE_AGENT>`, `<SURFACE_LABEL>`,
18
+ `<SURFACE_PATH>`, `<SURFACE_TOOLS>`, `<SURFACE_MODEL>`, `<PROJECT_NAME>`, and the surface-specific
19
+ blocks (`<SURFACE_EXTRA_NEVER>`, `<SURFACE_DESIGN_INPUT>`, `<SURFACE_TDD_STEP1>` — leave the design
20
+ ones empty unless `uses_design`). Fill `<SURFACE_CONVENTIONS>` with the surface's convention slice
21
+ **baked at render time**: `PIPELINE.md` §Conventions `### Shared` + this surface's
22
+ `### Surface: <key>` stanza + its §Testing lines, verbatim. At runtime the agent then reads only
23
+ the profile's machine block (the fenced `yaml pipeline-profile`) — never the prose sections. The
24
+ bake stays honest because §Conventions edits go through `/cohorte-update-pipeline`, whose reconcile
25
+ re-renders every agent (§Reconcile step 2, `<core>/pipeline/schema/reconcile.md`); hand-edit the prose without re-rendering and the baked
26
+ slice goes stale — that's the trade for not re-reading the prose on every dispatch. For a `uses_design` surface, fill them **link-based** (never with a
27
+ stored `design_project` id — that goes stale on a DS rebuild):
28
+ - `<SURFACE_DESIGN_INPUT>` — a 4th input bullet: _"The **feature design** — the pages this feature
29
+ touches, listed in your dispatch's design slot as full links
30
+ (`https://claude.ai/design/p/<projectId>?file=<file>`); a slot saying `none` means a fix loop with
31
+ no visual work — skip DesignSync entirely. For each link, extract the `<projectId>` (the
32
+ `/p/…` segment) and `<file>` (the `?file=` query) from the URL and read it read-only via `DesignSync
33
+ get_file(<projectId>, <file>)`; `list_files(<projectId>)` to catch linked pages (shared nav/modals)
34
+ this feature also changes. The link is self-contained — no stored project id. Build with the code UI
35
+ kit (the `design_system_project`'s materialization: `@/components/ui/*` + tokens); read a primitive
36
+ via `get_file` only if it's missing/stale in code. Mobile-first."_
37
+ - `<SURFACE_TDD_STEP1>` — a **lead-in paragraph** above the TDD list (not a numbered item; it
38
+ renders as nothing for a non-design surface, which is why the list must not start at it):
39
+ _"**Pull the feature design first** (skip if your dispatch's design slot
40
+ says `none`): `DesignSync get_file(<projectId>, <file>)` for each link in the slot and translate
41
+ each into the code design system (`@/components/ui/*`, `cn()` + CVA), mobile-first — never ad-hoc
42
+ CSS. Then:"_
43
+ 3. **Add a §Conventions + §Testing stanza** for `S` in `PIPELINE.md` (mirror a sibling surface; keep it
44
+ rule-shaped). If `S` is a shared-code surface, its convention is "single owner of shared X; slices
45
+ consume, never redefine."
46
+
47
+ Removing/merging a surface is the reverse: drop the `surfaces[]` entry, delete its agent file, fold its
48
+ conventions, run `<sync>`. Never leave an agent file with no matching `surfaces[]` entry (orphan) or vice-versa.
@@ -0,0 +1,58 @@
1
+ ## Code retrieval — `retrieval.provider`
2
+
3
+ Agents spend most of their wall-clock reading the repo; a retrieval provider replaces grep-and-read
4
+ with symbol/graph queries. The flag is a **value, not a boolean**, so switching provider later is a
5
+ one-line profile change + re-running the wiring (no agent re-render needed — the guidance agents
6
+ follow is provider-agnostic: _"prefer the retrieval MCP tools over Grep/Glob + whole-file Reads"_).
7
+
8
+ | Provider | Mechanism | Freshness | Cost |
9
+ | --- | --- | --- | --- |
10
+ | `serena` (default) | live LSP symbol navigation (find symbol, references, semantic edits) | always current | none — no index |
11
+ | `graphify` | persistent tree-sitter knowledge graph over code + docs | as fresh as the last rescan | index step + re-index discipline |
12
+ | `none` | agents fall back to Grep/Glob/Read | — | — |
13
+
14
+ **Wiring (done by `/cohorte-init-pipeline`, or `/cohorte-update-pipeline` retroactively):**
15
+
16
+ - `serena` — requires the `serena` CLI (`uv tool install -p 3.13 serena-agent`). For day-to-day CLI
17
+ use it should also be on PATH (`uv tool update-shell`; uv installs to `~/.local/bin`). Register at
18
+ **project scope** so the registration is committed and portable (`--project-from-cwd` resolves the
19
+ project at server start, so the committed entry works on every machine) — and register the
20
+ **PATH-proof launcher**, not the bare command: Claude Code spawns MCP servers with whatever
21
+ environment it was launched from (a stale terminal, a GUI/IDE launch that never sourced a shell
22
+ profile), where `~/.local/bin` may be missing from PATH — a bare `serena` entry then dies with
23
+ ENOENT and agents silently fall back to Grep/Read:
24
+
25
+ ```sh
26
+ claude mcp add --scope project serena -- sh -c 'exec "$(command -v serena || echo "$HOME/.local/bin/serena")" start-mcp-server --context claude-code --project-from-cwd --open-web-dashboard False'
27
+ ```
28
+
29
+ (Windows-native teams: no `sh` — register the bare `serena` form instead and ensure the uv tools
30
+ dir is on PATH; keep the `--open-web-dashboard False` flag.) `--open-web-dashboard False` keeps the
31
+ dashboard available (reachable at `http://localhost:24282/dashboard/`) but stops it popping a browser
32
+ tab on every server start — the flag overrides the machine's `serena_config.yml`, so the behaviour is
33
+ the same for everyone on the repo. Gitignore `.serena/` (per-machine cache/config). Optionally
34
+ pre-index large repos once: `serena project index`.
35
+ - `graphify` — requires `uv tool install graphify` + `graphify install`; build the initial graph
36
+ (`/graphify .`) and rescan incrementally after big changes (`--update`). See graphify.net.
37
+ - Rendered agents get the provider's MCP tools appended to their `tools:` list (e.g. `mcp__serena`
38
+ grants the whole server); `none` ⇒ nothing appended.
39
+
40
+ **Serena health check** — run after wiring in `/cohorte-init-pipeline` AND on every `/cohorte-update-pipeline`
41
+ reconcile (wiring that worked once can rot: PATH changes, tool uninstalled, entry hand-edited):
42
+
43
+ 1. **CLI resolves:** `command -v serena`. Fails but `~/.local/bin/serena` exists ⇒ PATH repair
44
+ above; missing entirely ⇒ reinstall.
45
+ 2. **Registered:** this repo's `.mcp.json` has the `serena` entry ⇒ else re-run the `claude mcp add`.
46
+ If the entry is the bare `serena` form on a POSIX machine, upgrade it to the PATH-proof launcher
47
+ above (immune to launch-environment PATH gaps). If a launcher entry predates the
48
+ `--open-web-dashboard False` flag, append it so the dashboard no longer auto-opens a browser tab.
49
+ 3. **Gitignored:** `.serena/` is in `.gitignore` ⇒ else append it.
50
+ 4. **Actually connected:** the `mcp__serena` tools are exposed in the session (or `claude mcp list`
51
+ shows serena connected). If 1–3 pass but this fails, a session restart is needed — say so
52
+ explicitly instead of reporting success.
53
+
54
+ Report each check's result; never report Serena "wired" on registration alone.
55
+
56
+ Teammates cloning the repo get the committed `.mcp.json` and only need the provider CLI installed
57
+ and on PATH — if either is missing, the MCP server fails to start and agents silently fall back to
58
+ Grep/Read; the health check above is the diagnostic.
@@ -0,0 +1,79 @@
1
+ ## Spec status — the lifecycle state machine
2
+
3
+ A spec's front-matter `status` is not a label, it is the pipeline's **state**: every command routes on
4
+ it, `cohorte specs` boards on it, and the kanban backfill maps it to a column. Eight states:
5
+
6
+ | status | meaning | written by | who may build it |
7
+ | --- | --- | --- | --- |
8
+ | `draft` | the interview is open, nothing is frozen | `/cohorte-spec` Mode A | no |
9
+ | `frozen` | the contract is frozen — the handoff to `/cohorte-build` | `/cohorte-spec` Mode A freeze | yes |
10
+ | `in-progress` | a round is under way on this spec (or died mid-way) | an automated driver, if any | yes |
11
+ | `in-review` | reviewed / awaiting the next round or `/cohorte-ship` | `/cohorte-spec` Mode B, `/cohorte-fix` | yes |
12
+ | `blocked` | a round gave up here (non-convergent, no verdict, not implementable) | an automated driver, if any | yes, with the reason named |
13
+ | `shipped` | the PR is open; the status flip is part of the release commit | `/cohorte-ship` | no |
14
+ | `merged` | the PR merged — reconciled from `gh pr view`, never assumed | `/cohorte-ship` §0/§5, `/cohorte-doctor` reconcile | no |
15
+ | `abandoned` | the feature was dropped (PR closed unmerged, or never shipped) — the human's call | `/cohorte-ship` §0, the human | no |
16
+
17
+ **`merged` and `abandoned` close the lifecycle.** `shipped` only says a PR was opened; whether it
18
+ landed is a fact on the host, so it is **reconciled**, not guessed: `/cohorte-ship` re-entered on a
19
+ `shipped` spec and `/cohorte-doctor` both run `gh pr view <branch> --json state` — `MERGED` ⇒
20
+ `merged`; `CLOSED` unmerged ⇒ the human decides (reopen and continue, or `abandoned`). Both are
21
+ terminal: every builder refuses them, the kanban backfill maps them to `shipped`, and a worktree
22
+ still alive for one is a teardown candidate.
23
+
24
+ **`in-progress` and `blocked` are driver states.** No conversational command writes them — the
25
+ human-driven cycle moves `frozen` → `in-review` → `shipped` → `merged`. Their producer is the
26
+ **loop workflow** (`cohorte-loop.js`, from `core/workflows/loop.js` — the successor of the
27
+ 2.2.0-retired conversational driver): it stamps `in-progress` at each round, `in-review` when a
28
+ run ends at zero blocking findings, and `blocked` when a round gives up, with the reason in
29
+ `specs/reports/<id>.loop.json`. A **resumable** stop (a dead agent, a red preflight, an
30
+ unreviewed surface, a report that never landed) writes `reason` and **no** `outcome`, and
31
+ re-invoking the loop resumes at that round; a **terminal** one (treading water, max rounds, a
32
+ contract-change finding) writes both, and the next run starts fresh once a human re-entered
33
+ through `/cohorte-fix` or `/cohorte-build` (which rewrites `readiness.json` after `loop.json`).
34
+ External drivers may write these states too. Every reader routes on
35
+ them either way, and a stamp on a spec with no front-matter stays a silent no-op — no driver
36
+ dies over a status line.
37
+
38
+ **`kind` — feature (default), `patch` or `refactor`.** Orthogonal to `status`, and — with `migrations`
39
+ (below) — the only other front-matter field commands route on. `/cohorte-patch` freezes `specs/patch-<slug>.md` with `kind: patch` from
40
+ `templates/patch.template.md`: a ~60-line bug spec whose §4 **regression test** replaces §5 CONTRACT
41
+ as the thing the diff is checked against. It moves through the same states and the same commands —
42
+ `/cohorte-build` → `/cohorte-review` → `/cohorte-fix`* → `/cohorte-ship` — which is the whole design:
43
+ a patch is a spec, so nothing downstream is special-cased beyond three lines.
44
+
45
+ | what reads `kind: patch` | what it does differently |
46
+ | --- | --- |
47
+ | `/cohorte-build` §1.6 | judges §1 repro + §4 regression test instead of contract completeness; gap check `repro` |
48
+ | `/cohorte-build` §2 | authors no contract when §5 Contract delta is `none` (the usual case) |
49
+ | `/cohorte-ship` §1/§2b/§3 | branches off `vcs.patch_branch_prefix`; a `patch` bump by default; `fix(<scope>)` commit |
50
+
51
+ `/cohorte-refactor` §4 freezes `specs/refactor-<domains>-<date>.md` with `kind: refactor`: no
52
+ contract, §6 = the cleared backlog items, §9 = public behaviour preserved + tests green. It enters at
53
+ `/cohorte-review` (behaviour preservation + items landed + scope instead of contract conformance),
54
+ then `/cohorte-ship` (`refactor(<scope>)` commit) — never `/cohorte-build` or the loop workflow.
55
+
56
+ A patch may span **several surfaces** — one bug, one repro, one spec. What it may never do is add
57
+ **new** contract surface area: two surfaces agreeing on a shape that doesn't exist yet is what §5 is
58
+ for, so `/cohorte-patch` routes that to `/cohorte-spec` instead. Changing an *existing* contract entry
59
+ is a legitimate delta. The patch template keeps contract on **§5** and acceptance on **§9** — the two
60
+ numbers `review.md` and `implementer.template.md` name verbatim — and simply has no §8.
61
+
62
+ **`migrations` — `true` when the spec changes the database.** The third routed field. `/cohorte-spec`
63
+ sets it when §4 adds or alters a migration (or the contract changes what is persisted); absent
64
+ means `false`. It makes `## Rollback` mandatory — `/cohorte-ship` refuses the spec while
65
+ `verify-run.sh rollback-check` calls it empty — and makes `/cohorte-verify` run the migration (and its
66
+ down-then-up) on the dev database. See `<core>/pipeline/schema/verify.md`. `/cohorte-revert` reads
67
+ `## Rollback` for a `merged` spec and, on the human's word, sets `status: abandoned` inside the revert
68
+ commit — so the spec says so only if the revert actually merges.
69
+
70
+ Corollaries worth knowing:
71
+
72
+ - A spec with no front-matter makes every stamp a **silent no-op** — the state is bookkeeping, and the
73
+ loop must never die over a status line.
74
+ - Child commands write `status` too (`/cohorte-fix` sets `in-review`); re-stamping before each phase is what
75
+ keeps `in-progress` true for the duration of the run rather than for its first phase.
76
+ - `blocked` is not a failure to hide: `/cohorte-build` accepts it, names the `loop.json` reason, routes
77
+ by the spec's `## Remediation` (open items ⇒ `/cohorte-fix`), and sets `in-review` once its readiness
78
+ verdict is written. `/cohorte-build <id> --readiness-only` does that re-entry (checks, readiness,
79
+ contract) without dispatching anything — the loop then builds.
@@ -0,0 +1,41 @@
1
+ ## Specialization — when to split one surface into more agents
2
+
3
+ `/cohorte-build` dispatches ONE agent per surface, in parallel, so build wall-clock ≈ the **slowest single
4
+ surface**. More agents only build faster when they let the *slowest* surface's work run concurrently —
5
+ and only if the split is safe. The invariant that keeps parallelism safe is **one owner per tree, and
6
+ the frozen contract as the only cross-surface channel**. So specialization means carving a surface into
7
+ **smaller non-overlapping surfaces**, never pointing two agents at the same tree.
8
+
9
+ **Split a surface into specialized sub-surfaces only when BOTH hold:**
10
+
11
+ 1. **It's a bottleneck** — the surface is large (many modules / high LOC) and dominates build time.
12
+ 2. **The boundary is clean** — its work partitions into trees that don't share files, e.g. feature
13
+ modules (`src/features/*`, `src/modules/*`), route groups, or independent services (`services/*`).
14
+
15
+ **Rules when splitting (non-negotiable — they preserve the invariant):**
16
+
17
+ - **One owner per tree is a convention, not a sandbox.** Nothing mechanical enforces it: an agent's
18
+ `tools:` frontmatter names tools, not paths, and implementers have Write/Edit/Bash on the whole
19
+ repo. It holds because each dispatch names one tree ("Touch only `<surface.path>`"), the rendered
20
+ agent says the same, and review reads the diff per surface — so a stray write shows up there.
21
+ - **Shared code gets its own surface with a single owner.** Anything two slices both touch — routing,
22
+ global state/store, the design-system kit + tokens, shared utils — becomes its OWN surface (e.g.
23
+ `web-shared`), owned by exactly one agent. Never let two feature-slice agents both edit shared trees.
24
+ - **Cross-slice references go through the contract**, not direct imports between slice trees. If
25
+ `web-checkout` needs a shape produced by `api-billing`, that shape lives in the frozen contract.
26
+ - **Don't over-split.** A slice too small to hold ≥1 real task, or one with tangled boundaries, is worse
27
+ than not splitting — the coordination + token cost (each stateless agent re-reads `PIPELINE.md` + spec)
28
+ outweighs the parallelism. When boundaries aren't clean, keep one surface.
29
+
30
+ Coarse first, specialize on evidence: start with one `frontend` / `backend` surface each; split only a
31
+ surface that's proven slow and cleanly separable. The evidence lives in
32
+ the **main checkout's** `<state>/pipeline-metrics.jsonl` (gitignored) — one JSONL line per phase batch
33
+ (`ts`/`feature`/`phase`/`seconds`/`surfaces:{key: result}`), appended by `/cohorte-build`, `/cohorte-review`
34
+ and `/cohorte-fix`.
35
+ **`surfaces` keys are surface keys, nothing else** — run-level facts go in their own top-level
36
+ fields. Anything put inside `surfaces` is read
37
+ as a surface: `cohorte doctor` renders it as a row in the per-surface table and scores a non-`ok`
38
+ value as that surface failing. Always the main checkout, never the feature worktree (which dies at teardown while
39
+ metrics must accumulate across features) — resolve from anywhere with
40
+ `$(dirname "$(git rev-parse --git-common-dir)")/<state>/pipeline-metrics.jsonl`. Read it before
41
+ proposing a split: split the surface that actually dominates wall-clock, not the one that feels big.
@@ -0,0 +1,115 @@
1
+ ## Verify — "does it actually work", migrations and rollback
2
+
3
+ The preflight proves the code compiles and its tests pass; the review proves the diff matches
4
+ the spec. Neither starts the app, so runtime DoD items (the page renders, the migration rolls
5
+ back, the repro is gone) were never ticked by the pipeline. `/cohorte-verify <id>` is that step,
6
+ between a `SHIP` verdict and `/cohorte-ship`. It moves no kanban card: the board has no column
7
+ for it, and the card stays in Review.
8
+
9
+ ### Configured
10
+
11
+ Verify applies when `verify.enabled` is not `false` and the profile has
12
+ `commands.smoke`, `commands.e2e`, or `commands.dev` **with** `commands.dev_ready` (a server nobody
13
+ probes proves nothing). A spec with `migrations: true` and a `commands.migrate` counts too. Not
14
+ configured ⇒ `/cohorte-verify` says so and stops, and `/cohorte-ship` skips its runtime gate
15
+ silently.
16
+
17
+ ### The script
18
+
19
+ `<core>/pipeline/scripts/verify-run.sh run <id> …` takes every
20
+ command as an argument, exactly as the profile spells it, and handles the process work:
21
+
22
+ - It starts `commands.dev` in its own process group and probes `commands.dev_ready` (a URL that
23
+ answers 2xx/3xx, or a command that exits 0).
24
+ - It runs the checks under timeouts, in order: `smoke`, `smoke:<surface>`, `e2e`.
25
+ - When a local Playwright CLI resolves, it takes the screenshots.
26
+ - It **always stops the server**, on every exit path (stale groups from a SIGKILLed run are
27
+ reaped by `verify-run.sh stop <id>` or by the next run).
28
+ - It refuses when the ready probe already answers before the start, because that is someone
29
+ else's server.
30
+ - It never touches git: no checkout, commit, push or merge.
31
+
32
+ The lead never starts, probes or kills a process by hand. Run the call with the Bash timeout at
33
+ 600000 ms. The script's own `--deadline` (540 s) sits below that, so the deadline fires before the
34
+ tool timeout.
35
+
36
+ ### The gate
37
+
38
+ The hook only sees `verify-run.sh …`, so the script asks
39
+ `.claude/hooks/cohorte-gate.py --check` about each command before it runs any of them:
40
+
41
+ - `deny` ⇒ that check is recorded `SKIPPED` and never run.
42
+ - `ask` ⇒ exit 4 and nothing is started. The lead shows the human the list and re-runs with
43
+ `--confirmed` only after a yes in this session.
44
+
45
+ A `commands.migrate_down` that sits in `gate.deny` (`migration:rollback` usually does) is never
46
+ verified. To let the pipeline check rollbacks on the dev DB, move it to `gate.ask`.
47
+
48
+ ### Databases — dev only, never shared
49
+
50
+ Migrations run only when the spec says `migrations: true`.
51
+ `commands.migrate` runs before the app starts. When `commands.migrate_down` is set, the script then
52
+ runs down followed by `migrate` again, as one `rollback` check. `verify.db: shared` (a team DB,
53
+ staging) refuses every migration unless `isolation.db_per_worktree` is true **and** the run is in a
54
+ feature worktree that `new-feature.sh` registered (a row in `isolation.registry` for the branch's
55
+ last path segment), which has its own `<name>_<id>` DB. A bare `git worktree add` shares the main
56
+ checkout's database and is refused. The refusal is decided in the script,
57
+ and the run is then `SKIPPED`. No command ever targets a production database: the pipeline holds no
58
+ credentials for one, and the lead never edits an `.env` to point elsewhere.
59
+
60
+ ### Ports
61
+
62
+ The profile's URLs name the main checkout's ports. In a feature worktree,
63
+ substitute the slot's port (`isolation.port_base.<x>` + the slot from `.worktrees/slots.tsv`) in
64
+ `dev_ready`, `smoke` and `base_url`. Otherwise the probe can hit the main checkout's app, which the
65
+ script reports as "already answering".
66
+
67
+ ### verify.json
68
+
69
+ `specs/reports/<id>.verify.json` is the machine verdict, overwritten with an `incomplete` FAIL at
70
+ the start of every run:
71
+ `{id, phase, ts, verdict: PASS|FAIL|SKIPPED, reason, head, digest_base, digest, digest_after, checks: [{name, status, exit, seconds, cmd, log, note}], evidence: [paths]}`.
72
+ - Any check FAIL ⇒ the verdict is `FAIL`. Otherwise one PASS ⇒ `PASS`. Otherwise `SKIPPED`.
73
+ - `digest` is `feature-diff.sh --base <reviewed_base> --digest` of the verified tree.
74
+ - A check that changes it (a file written outside `specs/` and `.claude/` that is not gitignored)
75
+ adds a `tree` FAIL. Point outputs at `$VERIFY_ARTIFACTS` instead.
76
+ - `<id>.verify.md` is the human copy. Logs and screenshots go in `specs/reports/<id>.verify/`,
77
+ which is a gitignored buffer.
78
+
79
+ ### DoD — runtime items only, evidence or nothing
80
+
81
+ A DoD line that only a running app can prove
82
+ carries a trailing `· runtime: <check>` tag. Verify ticks it only when every check named `<check>`
83
+ or `<check>:…` exists with `PASS`, and it appends the line plus its evidence path under `## DoD` in
84
+ `<id>.verify.md`. A bare `· runtime` (responsive layout, "looks right") is never auto-ticked. A
85
+ screenshot shows that the page rendered, not that it is correct, so it is listed as evidence for a
86
+ human. Verify never ticks an untagged item and never unticks one.
87
+
88
+ ### Ship
89
+
90
+ | verify.json | ship |
91
+ | --- | --- |
92
+ | not configured (above) | silent, no gate |
93
+ | `FAIL`, fresh or stale | **blocks** until a newer run overwrites it |
94
+ | `PASS` with `digest` = spec `reviewed_digest` | proceeds |
95
+ | absent, `SKIPPED`, or stale `PASS` | asks: "not verified at runtime — ship anyway?" |
96
+
97
+ ### Migrations
98
+
99
+ `/cohorte-spec` sets `migrations: true` when §4 adds or changes a
100
+ migration, or when the contract changes what is persisted. It then fills `## Rollback` with three
101
+ lines: what to revert, the data implications (a dropped column's values do not come back), and the
102
+ exact down step. A missing `migrations:` key means `false`, for legacy specs. `verify-run.sh
103
+ rollback-check specs/<id>.md` exits 1 when `migrations: true` and `## Rollback` holds only template
104
+ stubs. `/cohorte-spec` runs it before freezing, and `/cohorte-ship` refuses on it.
105
+
106
+ ### Revert
107
+
108
+ `/cohorte-revert <id>` undoes a `merged` feature as a reviewable PR, never as a push to the
109
+ default branch:
110
+ - It finds the merge or squash commit via `gh`, and asks the human when the PR was rebase-merged.
111
+ - It reads `## Rollback` first, because the revert deletes the spec, which is restored into the
112
+ revert commit.
113
+ - It runs the down step with `verify-run.sh run <id> --phase revert`: same gate consult, same
114
+ dev-only DB rule, writes `<id>.revert.json`. The step runs while the migration files still exist.
115
+ - It opens a PR whose body carries `## Rollback` for the operator who rolls back production.
@@ -0,0 +1,78 @@
1
+ ## Workflows — deterministic multi-agent runs (opt-in)
2
+
3
+ Four scripts run under the Claude Code Workflow runtime instead of the lead reasoning out the
4
+ fan-out turn by turn: `<workflows>/cohorte-review.js`, `cohorte-audit.js`, `cohorte-refactor.js` — each the
5
+ **workflow variant** of its same-named conversational command — plus **the loop workflow**
6
+ (`cohorte-loop.js`), which has **no conversational form at all** (below). For the variant pairs,
7
+ the conversational commands (`/cohorte-review`, `/cohorte-audit`, `/cohorte-refactor`)
8
+ **remain the default path and the fallback** — a workflow runs only when the human explicitly asks
9
+ for it ("run the review workflow"), and requires Claude Code ≥ **2.1.154** with workflows
10
+ enabled.
11
+ `/cohorte-doctor` reports which path a session will take. The interactive commands (`/cohorte-init-pipeline`,
12
+ `/cohorte-brainstorm`, `/cohorte-spec`) and the dispatch-only ones (`/cohorte-build`, `/cohorte-ship`) have **no** workflow variant on
13
+ purpose: they're interviews or already a single parallel dispatch — a script adds nothing.
14
+ The loop workflow does not change that: it **consumes** `/cohorte-build`'s outputs (the frozen
15
+ spec, `readiness.json`, the lead-authored contract, `build.json`) — it is not a build variant,
16
+ and adding one would put the lead-only steps (§1.5 reconcile, §2 contract authoring) inside a
17
+ script that cannot ask.
18
+
19
+ Shared design, all four scripts:
20
+
21
+ - **Phase 0 is always `cohorte-profile-reader`** — workflow scripts have no filesystem or shell access, so a
22
+ dedicated agent (`core/agents/cohorte-profile-reader.md`, haiku, read-only) returns the
23
+ `yaml pipeline-profile` block as JSON — one Read of `<state>/profile.json` (already parsed by
24
+ `<sync>`), falling back to parsing `PIPELINE.md` when that file is absent. Every later phase is parameterized from that object.
25
+ - **Mechanical phases run on haiku** (profile read, preflight, diff staging, report merging/writing);
26
+ judgment phases dispatch the same pinned agents the commands use (`review` at sonnet, the surface
27
+ implementers at their `surfaces[].model` tier) — the per-surface `model:` routing carries over.
28
+ - **Only the verdict comes back.** Bulk (diffs, reports, backlogs) is staged to the same disk
29
+ buffers the commands use (`specs/reports/`, `specs/refactor-backlog.md`); the workflow's return is
30
+ counts + verdict + paths.
31
+ - **A dead agent is never a clean result.** `agent()` resolves to `null` when a subagent dies, and a
32
+ dead *reviewer* returns zero findings — byte-identical to a surface that is genuinely clean. Any
33
+ script that derives a verdict from "how many findings came back" must first subtract the agents
34
+ that never answered: `review.js` names them in `unreviewedSurfaces` and refuses to score
35
+ `SHIP`. `scripts/test-workflows.mjs`
36
+ pins this — it is the one invariant the structural checks in `validate-core.mjs` cannot see.
37
+ The conversational commands enforce the same rule by roll call (§Dead agents, `<core>/pipeline/schema/dead-agents.md`); it was the workflows
38
+ that had it first, and for three releases they had it **alone** — the same crash on the
39
+ conversational path went unreported.
40
+ - **`review.js`** — preflight gate (aborts red, zero agents), the changed paths listed once and the
41
+ hunks staged per touched surface (§Feature diff, `<core>/pipeline/schema/feature-diff.md` — an empty diff aborts, it is never a SHIP), one
42
+ reviewer per surface in parallel (a dead one retried once), then an **adversarial cross-check**
43
+ phase that tries to refute each CRITICAL/security finding before it can trigger a fix loop. The
44
+ verdict — merged and per surface — is recomputed from the surviving findings by the review
45
+ agent's one rule.
46
+ - **`audit.js`** — one auditor per domain (each surface + `shared`), concurrency capped by the
47
+ runtime (~16), merged into `specs/refactor-backlog.md` — only the audited domains' sections are
48
+ rewritten (§Deferred findings, `<core>/pipeline/schema/deferred.md`).
49
+ - **`refactor.js`** — big domains only (it skips domains with a handful of open items — the
50
+ conversational `/cohorte-refactor` is cheaper there): `shared` first and alone (verified with the
51
+ repo-wide commands — it has no surface commands of its own), then the other domains'
52
+ implementers in parallel, each verified per-domain; then, gates green, it freezes the round as one
53
+ `kind: refactor` spec and ticks the backlog with `· refactor:<id>` (review → ship from there).
54
+ - **`loop.js`** (the loop workflow, `cohorte-loop.js`) — build → review → [fix → review]* for ONE feature, unattended and
55
+ resumable. Preconditions it verifies and refuses to work around: frozen/`in-review` spec, a fresh
56
+ `readiness.json` at `READY`/`RESERVATIONS`, the contract on disk, every readiness surface owned by
57
+ the profile. Round exits, in order: child abort relayed → `unreviewed` non-empty → `blocking == 0`
58
+ ⇒ ship → same blocking-item identity two consecutive rounds ⇒ treading water → `maxRounds`
59
+ (default 5). A blocking finding on the contract file aborts (`contract-change` — lead-only, per
60
+ `/cohorte-fix` §1). It calls the review **workflow** per round and reads the same `verdict.json`
61
+ contract the conversational `/cohorte-review` §3 writes; it stamps `in-progress` while running,
62
+ `in-review` on ship, `blocked` on a give-up (resumable or terminal — §Spec status, `<core>/pipeline/schema/spec-status.md`). The review runs
63
+ as a child via `workflow('cohorte-review', {feature})`, the runtime's one-level nesting call; a
64
+ throw (runtime or script missing) closes the run as `review-workflow-unavailable`, resumable.
65
+ **Workflow-only, no command file, ever**
66
+ (`validate-core.mjs` pins it): if the runtime is unavailable it refuses explicitly rather than
67
+ degrading to a lead re-reasoning the fan-out every round at session-model prices.
68
+ - **No input mid-run.** A workflow runs to completion without questions; anything interactive
69
+ (contract changes, human decisions) belongs to the conversational path. The gate hook still
70
+ fires on workflow subagents (see
71
+ §Preflight, `<core>/pipeline/schema/preflight.md`) — in unattended runs its asks become denies. Know what that means for edits:
72
+ workflow subagents run in **`acceptEdits` whatever the session mode**, so for the length of a
73
+ run — and `loop.js` runs long, unattended stretches — `hooks/gate.py` is the only brake on
74
+ what agents write (the project hook also guards the gate's own files on `Write|Edit|MultiEdit|NotebookEdit`). That is stated here rather than discovered.
75
+ - **Permissions:** `/cohorte-init-pipeline` and `/cohorte-update-pipeline` extend the generated `settings.json`
76
+ `allow` list with what workflow agents need (the quiet commands, the shipped
77
+ `pipeline/scripts/*.sh`, read-only git incl. `git rev-parse`, and the retrieval provider's MCP
78
+ tools) so a run never stalls mid-workflow on a permission prompt nobody is watching.
@@ -0,0 +1,118 @@
1
+ #!/bin/sh
2
+ #
3
+ # feature-diff.sh — the ONE way the pipeline computes "what this feature changed".
4
+ #
5
+ # feature-diff.sh --default <branch> <mode> [-- <pathspec>...]
6
+ # feature-diff.sh --base <sha> <mode> [-- <pathspec>...]
7
+ #
8
+ # modes: --base-only print the resolved base sha and nothing else
9
+ # --numstat `<added>\t<deleted>\t<path>` per changed file (full paths, no
10
+ # abbreviation — group by surface prefix on this, never on --stat)
11
+ # --name-only one changed path per line
12
+ # --patch the full patch (redirect it to a file; never into a context)
13
+ # --digest 16 hex chars of sha256 over the patch — the freshness stamp
14
+ #
15
+ # Two facts make a plain `git diff <default_branch>` wrong for a pipeline review, and this
16
+ # script exists to get both right in one place instead of in six prompts:
17
+ #
18
+ # 1. Feature work stays UNCOMMITTED until /cohorte-ship, and `git diff <ref>` ignores
19
+ # untracked files. Every new module a feature adds escaped review; a feature that only
20
+ # added files produced an EMPTY diff, which scored SHIP with nothing reviewed. So the
21
+ # diff is taken from a THROWAWAY index: seeded from the real one, `git add -A` run on
22
+ # the copy, `git diff --cached <base>` read from it. The human's real index — and
23
+ # whatever they staged in it — is never touched.
24
+ # 2. The base is the MERGE-BASE with the default branch, not its tip: the moment the
25
+ # default branch advances, a tip diff shows every file it gained as "deleted by the
26
+ # feature". Both the local `<branch>` and `origin/<branch>` are considered (worktrees
27
+ # from new-feature.sh branch off the remote ref, and the local one can lag it); the
28
+ # newer of the two merge-bases wins.
29
+ #
30
+ # `.claude` (pipeline state, rendered agents) and `specs` (the spec, its DoD ticks, the
31
+ # report buffer) are ALWAYS excluded — the pipeline writes those itself between a review
32
+ # and a ship, and they are not feature code. Gitignored files never enter (`git add -A`
33
+ # honours .gitignore). Pathspecs are repo-root relative; the script cds to the top level.
34
+ #
35
+ # Exit codes: 0 ok (an empty diff is a legitimate, empty answer) · 2 usage · 3 the base
36
+ # cannot be resolved (no such branch, no common history). A non-zero exit means NO diff
37
+ # was computed — a caller must stop, never fall back to a plain `git diff`, which is the
38
+ # exact bug this script replaces.
39
+
40
+ set -u
41
+
42
+ usage() {
43
+ echo "usage: feature-diff.sh (--default <branch> | --base <sha>) (--base-only|--numstat|--name-only|--patch|--digest) [-- <pathspec>...]" >&2
44
+ exit 2
45
+ }
46
+
47
+ default=""
48
+ base=""
49
+ mode=""
50
+ while [ $# -gt 0 ]; do
51
+ case "$1" in
52
+ --default) [ $# -ge 2 ] || usage; default=$2; shift 2 ;;
53
+ --base) [ $# -ge 2 ] || usage; base=$2; shift 2 ;;
54
+ --base-only|--numstat|--name-only|--patch|--digest)
55
+ [ -z "$mode" ] || usage; mode=$1; shift ;;
56
+ --) shift; break ;;
57
+ *) echo "feature-diff: unknown argument $1" >&2; usage ;;
58
+ esac
59
+ done
60
+ [ -n "$mode" ] || usage
61
+ { [ -n "$default" ] && [ -z "$base" ]; } || { [ -z "$default" ] && [ -n "$base" ]; } || usage
62
+
63
+ top=$(git rev-parse --show-toplevel 2>/dev/null) || { echo "feature-diff: not inside a git work tree" >&2; exit 3; }
64
+ cd "$top" || exit 3
65
+
66
+ if [ -n "$default" ]; then
67
+ mb_local=""; mb_remote=""
68
+ git rev-parse --verify -q "$default^{commit}" >/dev/null 2>&1 \
69
+ && mb_local=$(git merge-base "$default" HEAD 2>/dev/null || echo "")
70
+ git rev-parse --verify -q "origin/$default^{commit}" >/dev/null 2>&1 \
71
+ && mb_remote=$(git merge-base "origin/$default" HEAD 2>/dev/null || echo "")
72
+ if [ -n "$mb_local" ] && [ -n "$mb_remote" ]; then
73
+ # The newer merge-base is the one the other is an ancestor of.
74
+ if git merge-base --is-ancestor "$mb_local" "$mb_remote" 2>/dev/null; then base=$mb_remote; else base=$mb_local; fi
75
+ else
76
+ base="${mb_local:-$mb_remote}"
77
+ fi
78
+ [ -n "$base" ] || { echo "feature-diff: no merge-base between HEAD and $default (nor origin/$default)" >&2; exit 3; }
79
+ else
80
+ base=$(git rev-parse --verify -q "$base^{commit}" 2>/dev/null) \
81
+ || { echo "feature-diff: base $base is not a commit in this repo" >&2; exit 3; }
82
+ fi
83
+
84
+ if [ "$mode" = --base-only ]; then echo "$base"; exit 0; fi
85
+
86
+ [ $# -gt 0 ] || set -- .
87
+ set -- "$@" ':(exclude).claude' ':(exclude)specs'
88
+
89
+ # A path INSIDE a fresh temp dir, not `mktemp` itself: a 0-byte file is a corrupt index to git.
90
+ tmpd=$(mktemp -d 2>/dev/null) || { echo "feature-diff: mktemp -d failed" >&2; exit 3; }
91
+ trap 'rm -rf "$tmpd"' EXIT INT TERM
92
+ idx="$tmpd/index"
93
+ real=$(git rev-parse --git-path index 2>/dev/null || echo "")
94
+ if [ -n "$real" ] && [ -f "$real" ]; then
95
+ # `cp -p` keeps the stat cache (only changed files get re-hashed) AND the index file's
96
+ # mtime, which is what git's racy-entry check compares against — so the copy trusts
97
+ # exactly the entries the real index would, no more.
98
+ cp -p "$real" "$idx" || { echo "feature-diff: cannot copy the index" >&2; exit 3; }
99
+ elif git rev-parse --verify -q HEAD >/dev/null 2>&1; then
100
+ GIT_INDEX_FILE="$idx" git read-tree HEAD || exit 3
101
+ else
102
+ GIT_INDEX_FILE="$idx" git read-tree --empty || exit 3
103
+ fi
104
+ # The WHOLE tree goes into the copy; the caller's pathspec only narrows the diff below. (Adding
105
+ # just the pathspec fails outright on a surface path that does not exist yet.)
106
+ GIT_INDEX_FILE="$idx" git add -A -- . ':(exclude).claude' ':(exclude)specs' >/dev/null 2>&1 \
107
+ || { echo "feature-diff: git add into the temporary index failed" >&2; exit 3; }
108
+
109
+ d() { GIT_INDEX_FILE="$idx" git -c core.quotepath=off diff --cached --no-color --no-ext-diff "$@"; }
110
+ case "$mode" in
111
+ --numstat) d --no-renames --numstat "$base" -- "$@" ;;
112
+ --name-only) d --no-renames --name-only "$base" -- "$@" ;;
113
+ --patch) d --binary "$base" -- "$@" ;;
114
+ --digest)
115
+ out=$(d --binary --no-renames "$base" -- "$@" | { sha256sum 2>/dev/null || shasum -a 256; } | cut -c1-16)
116
+ [ -n "$out" ] || exit 3
117
+ echo "$out" ;;
118
+ esac