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,122 @@
1
+ #!/usr/bin/env bash
2
+ #
3
+ # new-feature.sh — spin up an ISOLATED git worktree for one feature so features
4
+ # can be built fully in parallel. Rendered from a template by /cohorte-init-pipeline;
5
+ # the double-underscore tokens below are substituted from PIPELINE.md §isolation.
6
+ # (This comment deliberately avoids spelling the token pattern: /cohorte-doctor flags any
7
+ # leftover double-underscore-caps token in the RENDERED script as unrendered.)
8
+ #
9
+ # Usage: scripts/new-feature.sh <feature_id>
10
+ #
11
+ # Creates a sibling worktree ../__PROJECT_SLUG__-<id> on branch
12
+ # __BRANCH_PREFIX__<id> (off __DEFAULT_BRANCH__) with its own isolation slot:
13
+ # • its own database __DB_NAME_PATTERN__ (if DB isolation is enabled)
14
+ # • its own API port __API_PORT_BASE__ + slot
15
+ # • its own web port __WEB_PORT_BASE__ + slot
16
+ # The infra servers stay a SINGLE shared stack — only the logical db + ports
17
+ # differ per worktree. Slot 0 = main checkout. New worktrees get slot >= 1.
18
+
19
+ set -euo pipefail
20
+
21
+ id="${1:-}"
22
+ if [[ -z "$id" ]]; then
23
+ echo "usage: scripts/new-feature.sh <feature_id>" >&2
24
+ exit 1
25
+ fi
26
+
27
+ repo_root="$(git -C "$(dirname "${BASH_SOURCE[0]}")" rev-parse --show-toplevel)"
28
+ branch="__BRANCH_PREFIX__${id}"
29
+ worktree_dir="$(dirname "$repo_root")/__PROJECT_SLUG__-${id}"
30
+ db_name="__PROJECT_SLUG___$(echo "$id" | tr -c 'a-zA-Z0-9' '_' | sed 's/_*$//')"
31
+
32
+ registry_dir="$repo_root/.worktrees"
33
+ registry="$registry_dir/slots.tsv"
34
+ mkdir -p "$registry_dir"
35
+ touch "$registry"
36
+
37
+ if [[ -e "$worktree_dir" ]]; then
38
+ echo "error: $worktree_dir already exists" >&2
39
+ exit 1
40
+ fi
41
+
42
+ slot="$(awk -F'\t' -v id="$id" '$1==id{print $2}' "$registry" | head -n1)"
43
+ if [[ -z "$slot" ]]; then
44
+ slot=1
45
+ while awk -F'\t' -v s="$slot" '$2==s{found=1} END{exit !found}' "$registry"; do
46
+ slot=$((slot + 1))
47
+ done
48
+ printf '%s\t%s\n' "$id" "$slot" >>"$registry"
49
+ fi
50
+
51
+ api_port=$((__API_PORT_BASE__ + slot))
52
+ web_port=$((__WEB_PORT_BASE__ + slot))
53
+
54
+ echo "→ feature '$id' → slot $slot (db $db_name · api :$api_port · web :$web_port)"
55
+ echo "→ creating worktree $worktree_dir on $branch (off __DEFAULT_BRANCH__)"
56
+ # Branch off the REMOTE ref when it exists: `git fetch origin <branch>` updates
57
+ # origin/<branch>, never the local one, so branching off the local ref silently
58
+ # started every feature from wherever the local default branch last sat.
59
+ git -C "$repo_root" fetch --quiet origin __DEFAULT_BRANCH__ || true
60
+ base=__DEFAULT_BRANCH__
61
+ if git -C "$repo_root" rev-parse --verify -q "origin/__DEFAULT_BRANCH__" >/dev/null 2>&1; then
62
+ base="origin/__DEFAULT_BRANCH__"
63
+ fi
64
+ git -C "$repo_root" worktree add -b "$branch" "$worktree_dir" "$base"
65
+
66
+ # --- carry the feature's UNCOMMITTED files into the new worktree --------------
67
+ # The worktree starts from the remote default branch, but a frozen spec is not committed
68
+ # until /cohorte-ship: specs/<id>.md, specs/design/<id>.md and (once /cohorte-build has
69
+ # authored it) the contract file <contract.path>/<id>.<ext> exist only in THIS checkout, and
70
+ # /cohorte-build in the worktree then refused ("no frozen spec"). Copy every untracked or
71
+ # modified, non-ignored file whose name is `<id>.<anything>` — no profile parsing needed, and
72
+ # the worktree is brand new (the script refuses an existing one), so nothing of its own is
73
+ # overwritten. Gitignored buffers (specs/reports/) stay behind: they describe this checkout.
74
+ carried=0
75
+ while IFS= read -r rel; do
76
+ [[ -n "$rel" && -f "$repo_root/$rel" ]] || continue
77
+ case "${rel##*/}" in "$id".*) ;; *) continue ;; esac
78
+ mkdir -p "$(dirname "$worktree_dir/$rel")"
79
+ cp -p "$repo_root/$rel" "$worktree_dir/$rel"
80
+ echo "→ carried $rel into the worktree"
81
+ carried=$((carried + 1))
82
+ done < <(git -C "$repo_root" ls-files --others --modified --exclude-standard)
83
+ if [[ "$carried" -gt 0 ]]; then
84
+ echo " the worktree's copies are now the ones that evolve; delete the main checkout's once you"
85
+ echo " are working there (git pull refuses to overwrite an untracked file when the PR merges)"
86
+ else
87
+ echo " ! no uncommitted specs/${id}.md found to carry — /cohorte-build in the worktree needs a frozen spec" >&2
88
+ fi
89
+
90
+ # Replace (or append) KEY=VALUE in a dotenv file — one definitive line per key.
91
+ set_env() {
92
+ local file="$1" key="$2" value="$3" tmp
93
+ if [[ -s "$file" && -n "$(tail -c1 "$file")" ]]; then printf '\n' >>"$file"; fi
94
+ tmp="$(mktemp)"
95
+ grep -vE "^${key}=" "$file" >"$tmp" || true
96
+ mv "$tmp" "$file"
97
+ printf '%s=%s\n' "$key" "$value" >>"$file"
98
+ }
99
+
100
+ # --- per-worktree env (init customizes these stanzas per surface) -----------
101
+ # __ENV_STANZAS__
102
+
103
+ # --- create the isolated database (if DB isolation enabled) -----------------
104
+ # __DB_STANZA__
105
+
106
+ echo "→ ${repo_root##*/} install (shared store)"
107
+ ( cd "$worktree_dir" && __INSTALL_CMD__ )
108
+
109
+ cat <<EOF
110
+
111
+ ✓ worktree ready: $worktree_dir (branch $branch, slot $slot)
112
+ api http://localhost:$api_port
113
+ web http://localhost:$web_port
114
+
115
+ Fully isolated — run its dev + migrations alongside other worktrees:
116
+ cd $worktree_dir
117
+ __MIGRATE_CMD__
118
+ cd $worktree_dir && __DEV_CMD__
119
+ /cohorte-build $id → test → /cohorte-review $id → /cohorte-ship $id (spec carried in: $carried file(s))
120
+
121
+ Tear down when merged: scripts/remove-feature.sh $id
122
+ EOF
@@ -0,0 +1,114 @@
1
+ #!/bin/sh
2
+ #
3
+ # preflight.sh — deterministic phase gate for /cohorte-review.
4
+ #
5
+ # Runs the profile's mechanical checks (typecheck, lint, tests — whatever the caller
6
+ # passes) BEFORE any agent is spawned. A red gate means the caller aborts and relays
7
+ # the raw failure — dispatching reviewers onto code that doesn't even compile burns
8
+ # their whole run on noise a compiler already printed for free.
9
+ #
10
+ # preflight.sh <report-file> "<cmd>" ["<cmd>"...]
11
+ #
12
+ # - Each command runs through `sh -c`, all output appended to <report-file> — the bulk
13
+ # never enters the calling agent's context.
14
+ # - First failure: prints the last 40 lines of the report raw to stderr and exits 1.
15
+ # The caller must stop there — no agents.
16
+ # - All green: writes `<project>/.claude/preflight.ok` ("<epoch> <HEAD sha> <tree digest>")
17
+ # — the stamp `hooks/gate.py` checks (gate-config.json `preflight` block) before letting
18
+ # review agents dispatch.
19
+ #
20
+ # The stamp is a LOCAL, GITIGNORED artifact. Versioning it breaks the gate outright: the
21
+ # stamp records the pre-commit sha, committing it moves HEAD, so the checked-out stamp can
22
+ # never match its own commit — every dispatch then reports "HEAD moved" on a clean tree.
23
+ # A tracked stamp also rides into every new worktree, handing it a green it never earned.
24
+
25
+ set -u
26
+
27
+ report="${1:?usage: preflight.sh <report-file> \"<cmd>\" [\"<cmd>\"...]}"
28
+ shift
29
+ [ "$#" -gt 0 ] || { echo "preflight: no commands given" >&2; exit 2; }
30
+
31
+ mkdir -p "$(dirname "$report")" 2>/dev/null || true
32
+ : > "$report"
33
+
34
+ n=0
35
+ for cmd in "$@"; do
36
+ [ -n "$cmd" ] || continue
37
+ n=$((n + 1))
38
+ printf '\n$ %s\n' "$cmd" >> "$report"
39
+ if ! sh -c "$cmd" >> "$report" 2>&1; then
40
+ echo "PREFLIGHT FAIL — $cmd" >&2
41
+ echo "--- last 40 lines of $report ---" >&2
42
+ tail -40 "$report" >&2
43
+ exit 1
44
+ fi
45
+ done
46
+ # All-empty arguments verified nothing — stamping green here would gate reviews on a
47
+ # check that never ran. Same failure as zero arguments, and the same exit.
48
+ [ "$n" -gt 0 ] || { echo "preflight: every command argument was empty — nothing was verified" >&2; exit 2; }
49
+
50
+ # Stamp for the gate.py phase gate: epoch + HEAD sha of the checkout we verified.
51
+ # The stamp MUST land where gate.py reads it: <main checkout>/.claude. CLAUDE_PROJECT_DIR
52
+ # is only exported to hooks — in an agent's Bash call it is unset, and a bare `.` would
53
+ # drop the stamp in the feature worktree where the gate never looks. git-common-dir
54
+ # resolves to the MAIN checkout's .git from any worktree.
55
+ proj="${CLAUDE_PROJECT_DIR:-$(dirname "$(git rev-parse --git-common-dir 2>/dev/null || echo ./.git)")}"
56
+ sha=$(git rev-parse HEAD 2>/dev/null || echo none)
57
+
58
+ # Content digest of the state we actually verified: the git TREE id of the working tree,
59
+ # built in a throwaway index so nothing touches the real one. The sha alone is the wrong
60
+ # key — the reviewed tree is normally DIRTY (uncommitted feature work), so committing it
61
+ # invalidates the stamp without changing a line of code, while an implementer's edit
62
+ # changes every line without moving HEAD. A tree id is content-addressed: it survives a
63
+ # commit of the same content and dies on any real edit (including new untracked files).
64
+ # `.claude` (stamps, metrics) and `specs` (DoD ticks, report buffer) are excluded — the
65
+ # pipeline writes those itself between the preflight and the dispatch it must not invalidate.
66
+ # gate.py recomputes this identically; any change here must land there too.
67
+ digest=none
68
+ tmpidx=$(mktemp 2>/dev/null || echo "")
69
+ if [ -n "$tmpidx" ]; then
70
+ # Seed from the real index (not `read-tree HEAD`) so its stat cache is preserved and
71
+ # `add` only re-hashes files that actually changed.
72
+ idx=$(git rev-parse --git-path index 2>/dev/null || echo "")
73
+ if [ -n "$idx" ] && [ -f "$idx" ]; then
74
+ cp "$idx" "$tmpidx" 2>/dev/null || true
75
+ # Backdate the copy, for the reason spelled out in gate.py's tree_digest(): git trusts an
76
+ # entry's cached stat data only when its mtime predates the index file's, so a copy stamped
77
+ # `now` makes a file edited in this same second look clean. Both sides must age it by the
78
+ # same window or they compute different trees for the same content. `date -d` is GNU and
79
+ # `date -v` is BSD — try both, and if neither exists just skip the touch (the digest is
80
+ # still correct for anything not edited in the last few seconds).
81
+ # LOCAL time on purpose: `touch -t` interprets its stamp as local time, so a
82
+ # UTC-formatted stamp future-dates the index anywhere west of UTC — which makes
83
+ # git trust the stat cache of files edited THIS second, the exact race the
84
+ # backdate exists to prevent. (gate.py's side uses os.utime with an epoch, which
85
+ # has no timezone to get wrong.)
86
+ stamp=$(date -d '5 seconds ago' +%Y%m%d%H%M.%S 2>/dev/null \
87
+ || date -v-5S +%Y%m%d%H%M.%S 2>/dev/null || echo "")
88
+ [ -n "$stamp" ] && touch -t "$stamp" "$tmpidx" 2>/dev/null || true
89
+ else
90
+ rm -f "$tmpidx" # a 0-byte index is a corrupt index
91
+ fi
92
+ # Drop the excluded paths from the throwaway index entirely: an `add` exclude only stops
93
+ # them being *updated*, so anything already tracked there (a committed stamp, a spec)
94
+ # would still land in the tree and shift the digest.
95
+ GIT_INDEX_FILE="$tmpidx" git rm --cached -r -q --ignore-unmatch -- .claude specs > /dev/null 2>&1 || true
96
+ if GIT_INDEX_FILE="$tmpidx" git add -A -- . ':(exclude).claude' ':(exclude)specs' > /dev/null 2>&1; then
97
+ digest=$(GIT_INDEX_FILE="$tmpidx" git write-tree 2>/dev/null || echo none)
98
+ fi
99
+ rm -f "$tmpidx" "$tmpidx.lock" 2>/dev/null || true
100
+ fi
101
+ [ -n "$digest" ] || digest=none
102
+ # Stamp BOTH the main checkout and the cwd: gate.py reads CLAUDE_PROJECT_DIR, which is the
103
+ # worktree when the session was opened there and the main checkout when it wasn't — the two
104
+ # disagree, and either layout is supported.
105
+ now=$(date +%s)
106
+ last=""
107
+ for d in "$proj" "$(pwd)"; do
108
+ [ "$d" = "$last" ] && continue # same dir twice in the main checkout
109
+ last="$d"
110
+ mkdir -p "$d/.claude" 2>/dev/null || true
111
+ printf '%s %s %s\n' "$now" "$sha" "$digest" > "$d/.claude/preflight.ok" 2>/dev/null || true
112
+ done
113
+
114
+ echo "PREFLIGHT PASS ($n checks green) — full log: $report"
@@ -0,0 +1,56 @@
1
+ #!/usr/bin/env bash
2
+ #
3
+ # remove-feature.sh — tear down a feature's isolated worktree. Rendered from a
4
+ # template by /cohorte-init-pipeline (double-underscore tokens from PIPELINE.md §isolation —
5
+ # spelled out here so /cohorte-doctor's unrendered-token check never trips on this comment).
6
+ #
7
+ # Usage: scripts/remove-feature.sh <feature_id> [--drop-db]
8
+ #
9
+ # Removes the ../__PROJECT_SLUG__-<id> worktree, frees its slot, and (with
10
+ # --drop-db) drops its database. The db is kept by default. The shared stack and
11
+ # the main checkout are never touched.
12
+
13
+ set -euo pipefail
14
+
15
+ id="${1:-}"
16
+ drop_db="no"
17
+ [[ "${2:-}" == "--drop-db" ]] && drop_db="yes"
18
+
19
+ if [[ -z "$id" ]]; then
20
+ echo "usage: scripts/remove-feature.sh <feature_id> [--drop-db]" >&2
21
+ exit 1
22
+ fi
23
+
24
+ repo_root="$(git -C "$(dirname "${BASH_SOURCE[0]}")" rev-parse --show-toplevel)"
25
+ worktree_dir="$(dirname "$repo_root")/__PROJECT_SLUG__-${id}"
26
+ db_name="__PROJECT_SLUG___$(echo "$id" | tr -c 'a-zA-Z0-9' '_' | sed 's/_*$//')"
27
+ registry="$repo_root/.worktrees/slots.tsv"
28
+ branch="__BRANCH_PREFIX__${id}"
29
+
30
+ echo "→ removing worktree $worktree_dir"
31
+ # Porcelain + fixed-string + whole-line: the human-readable list matched any worktree
32
+ # whose path merely CONTAINS this one (auth vs auth-2fa), and dots in the path were regex.
33
+ if git -C "$repo_root" worktree list --porcelain | grep -Fxq "worktree $worktree_dir"; then
34
+ git -C "$repo_root" worktree remove "$worktree_dir" "${@:3}"
35
+ else
36
+ echo " (no such worktree registered — skipping)"
37
+ fi
38
+
39
+ if git -C "$repo_root" show-ref --verify --quiet "refs/heads/$branch"; then
40
+ if git -C "$repo_root" branch -d "$branch" 2>/dev/null; then
41
+ echo "→ deleted merged branch $branch"
42
+ else
43
+ echo " ! branch $branch is not fully merged — kept it." >&2
44
+ echo " delete manually when ready: git branch -D $branch" >&2
45
+ fi
46
+ fi
47
+
48
+ if [[ -f "$registry" ]]; then
49
+ tmp="$(mktemp)"
50
+ awk -F'\t' -v id="$id" '$1!=id' "$registry" >"$tmp" && mv "$tmp" "$registry"
51
+ echo "→ freed slot for '$id'"
52
+ fi
53
+
54
+ # __DB_DROP_STANZA__
55
+
56
+ echo "✓ feature '$id' torn down"