@jeiemgi/cckit 0.8.0 → 0.10.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 (309) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/AGENTS.md +169 -21
  3. package/README.md +505 -35
  4. package/SECURITY.md +5 -0
  5. package/bin/cckit +189 -20
  6. package/cckit.config.json +1 -1
  7. package/commands/kit-doctor.md +13 -5
  8. package/commands/kit-export-project.md +0 -2
  9. package/commands/kit-export-training.md +6 -9
  10. package/commands/kit-init.md +43 -13
  11. package/commands/kit-routines.md +1 -1
  12. package/commands/kit-update.md +11 -6
  13. package/databases/supabase/guide.html +106 -0
  14. package/databases/supabase/nextjs/lib/supabase/client.ts +9 -0
  15. package/databases/supabase/nextjs/lib/supabase/server.ts +29 -0
  16. package/databases/supabase.json +70 -0
  17. package/integrations/emil-design-eng.json +41 -0
  18. package/integrations/graft.json +81 -0
  19. package/integrations/impeccable.json +42 -0
  20. package/integrations/integration.schema.json +215 -0
  21. package/integrations/lavish.json +43 -0
  22. package/integrations/mempalace.json +28 -0
  23. package/integrations/mlx-lm.json +32 -0
  24. package/integrations/web-design-guidelines.json +42 -0
  25. package/kit.config.schema.json +183 -5
  26. package/package.json +4 -1
  27. package/profiles/automation.json +7 -1
  28. package/profiles/content.json +10 -2
  29. package/profiles/marketing.json +57 -0
  30. package/profiles/minimal.json +7 -1
  31. package/profiles/research.json +7 -1
  32. package/profiles/software.json +7 -1
  33. package/recipes/nextjs-shadcn.json +49 -0
  34. package/scripts/agent-skills-external.txt +45 -0
  35. package/scripts/agent-skills-lint-test.sh +131 -0
  36. package/scripts/agent-skills-lint.sh +115 -0
  37. package/scripts/agent-template-lint-test.sh +42 -0
  38. package/scripts/agent-template-lint.sh +58 -0
  39. package/scripts/annotate-setup.sh +1 -1
  40. package/scripts/autopilot-run-test.sh +338 -0
  41. package/scripts/autopilot-run.sh +448 -0
  42. package/scripts/autopilot-test.sh +8 -0
  43. package/scripts/autopilot.sh +10 -1
  44. package/scripts/benchmark/benchmark-test.sh +85 -0
  45. package/scripts/benchmark/checkpoint-test.sh +314 -0
  46. package/scripts/benchmark/checkpoint.sh +408 -0
  47. package/scripts/benchmark/lib/model.sh +31 -6
  48. package/scripts/benchmark/report.sh +17 -2
  49. package/scripts/benchmark/run-quality.sh +36 -10
  50. package/scripts/benchmark/verb-timings-test.sh +124 -0
  51. package/scripts/benchmark/verb-timings.sh +149 -0
  52. package/scripts/check.sh +29 -19
  53. package/scripts/content-skills-test.sh +144 -0
  54. package/scripts/copilot-loop-test.sh +25 -0
  55. package/scripts/database-supabase-test.sh +121 -0
  56. package/scripts/docs-marketing-words-test.sh +73 -0
  57. package/scripts/docs-record-tables-test.sh +72 -0
  58. package/scripts/guard-raw-git-ops-test.sh +8 -0
  59. package/scripts/hook-adapter-test.sh +193 -0
  60. package/scripts/init-content-test.sh +225 -0
  61. package/scripts/init-guided-test.sh +474 -0
  62. package/scripts/init-recipes-test.sh +104 -0
  63. package/scripts/init-upgrade-test.sh +341 -2
  64. package/scripts/init.sh +746 -95
  65. package/scripts/instruction-budget-baseline.txt +8 -0
  66. package/scripts/instruction-budget-lint-test.sh +166 -0
  67. package/scripts/instruction-budget-lint.sh +219 -0
  68. package/scripts/integrations-check-test.sh +200 -0
  69. package/scripts/integrations-check.sh +157 -0
  70. package/scripts/kit-add-test.sh +214 -0
  71. package/scripts/kit-add.sh +305 -5
  72. package/scripts/kit-adopt-test.sh +16 -0
  73. package/scripts/kit-adopt.sh +3 -2
  74. package/scripts/kit-digest.sh +2 -2
  75. package/scripts/kit-doctor-test.sh +293 -0
  76. package/scripts/kit-doctor.sh +272 -140
  77. package/scripts/kit-export-project-test.sh +3 -3
  78. package/scripts/kit-remove-test.sh +19 -0
  79. package/scripts/kit-routines.sh +2 -2
  80. package/scripts/kit-self-update.sh +1 -1
  81. package/scripts/kit-version-check-test.sh +4 -0
  82. package/scripts/kit-version-check.sh +4 -2
  83. package/scripts/knowledge-lint.sh +4 -4
  84. package/scripts/leak-fence-test.sh +89 -0
  85. package/scripts/lib/adapter-select-test.sh +136 -0
  86. package/scripts/lib/adapter-select.sh +158 -0
  87. package/scripts/lib/agent-def-test.sh +69 -0
  88. package/scripts/lib/agent-def.sh +106 -0
  89. package/scripts/lib/agent-launch-test.sh +212 -0
  90. package/scripts/lib/agent-launch.sh +335 -0
  91. package/scripts/lib/board-view-test.sh +11 -0
  92. package/scripts/lib/board-view.sh +42 -26
  93. package/scripts/lib/branch-owner-test.sh +26 -0
  94. package/scripts/lib/branch-owner.sh +16 -9
  95. package/scripts/lib/captain-test.sh +105 -0
  96. package/scripts/lib/captain.sh +87 -8
  97. package/scripts/lib/codex-hooks-test.sh +100 -0
  98. package/scripts/lib/codex-hooks.sh +69 -0
  99. package/scripts/lib/commitlint.sh +1 -1
  100. package/scripts/lib/content-kinds-gc-test.sh +88 -0
  101. package/scripts/lib/copilot-test.sh +70 -4
  102. package/scripts/lib/copilot.sh +66 -14
  103. package/scripts/lib/effort-dispatch-test.sh +3 -3
  104. package/scripts/lib/effort-metrics-test.sh +178 -1
  105. package/scripts/lib/effort-metrics.sh +188 -35
  106. package/scripts/lib/effort-ops-test.sh +217 -7
  107. package/scripts/lib/effort-ops.sh +281 -49
  108. package/scripts/lib/effort-parity-test.sh +49 -13
  109. package/scripts/lib/effort-plan-test.sh +337 -0
  110. package/scripts/lib/effort-plan.sh +200 -23
  111. package/scripts/lib/effort-slug.sh +16 -2
  112. package/scripts/lib/effort.sh +67 -12
  113. package/scripts/lib/errors-header-test.sh +1 -1
  114. package/scripts/lib/gh-project-test.sh +35 -1
  115. package/scripts/lib/gh-project.sh +37 -16
  116. package/scripts/lib/gh-rest-test.sh +330 -0
  117. package/scripts/lib/gh-rest.sh +304 -0
  118. package/scripts/lib/hook-refresh.sh +1 -1
  119. package/scripts/lib/init-github.sh +412 -0
  120. package/scripts/lib/init-guide.sh +630 -0
  121. package/scripts/lib/integration-install-test.sh +343 -0
  122. package/scripts/lib/integration-install.sh +257 -0
  123. package/scripts/lib/integrations-test.sh +366 -0
  124. package/scripts/lib/integrations.sh +244 -0
  125. package/scripts/lib/kinds-test.sh +125 -0
  126. package/scripts/lib/kinds.sh +66 -0
  127. package/scripts/lib/kit-brief-test.sh +22 -3
  128. package/scripts/lib/kit-brief.sh +45 -5
  129. package/scripts/lib/kit-config-resolve.sh +2 -2
  130. package/scripts/lib/kit-config-test.sh +64 -1
  131. package/scripts/lib/kit-config.sh +37 -1
  132. package/scripts/lib/kit-events.sh +7 -0
  133. package/scripts/lib/kit-gc-test.sh +173 -1
  134. package/scripts/lib/kit-gc.sh +244 -37
  135. package/scripts/lib/kit-hotfix.sh +216 -0
  136. package/scripts/lib/kit-interview-test.sh +93 -0
  137. package/scripts/lib/kit-interview.sh +117 -8
  138. package/scripts/lib/kit-lib-test.sh +1 -1
  139. package/scripts/lib/kit-lib.sh +3 -3
  140. package/scripts/lib/kit-local.sh +2 -2
  141. package/scripts/lib/kit-manifest.sh +33 -1
  142. package/scripts/lib/kit-profile-test.sh +3 -3
  143. package/scripts/lib/kit-status-test.sh +112 -4
  144. package/scripts/lib/kit-status.sh +246 -16
  145. package/scripts/lib/kit-task-ops-test.sh +37 -0
  146. package/scripts/lib/kit-task-ops.sh +362 -89
  147. package/scripts/lib/kto-hotfix-test.sh +232 -0
  148. package/scripts/lib/kto-task-close-test.sh +83 -0
  149. package/scripts/lib/kto-task-new-test.sh +95 -0
  150. package/scripts/lib/kto-task-pr-merge-test.sh +97 -6
  151. package/scripts/lib/kto-task-pr-test.sh +70 -0
  152. package/scripts/lib/leak-fence.sh +89 -0
  153. package/scripts/lib/light-task-run-test.sh +255 -0
  154. package/scripts/lib/light-task-test.sh +309 -0
  155. package/scripts/lib/light-task.sh +706 -0
  156. package/scripts/lib/next-test.sh +99 -0
  157. package/scripts/lib/next.sh +9 -3
  158. package/scripts/lib/orchestration-runtime-test.sh +72 -0
  159. package/scripts/lib/orchestration-runtime.sh +57 -5
  160. package/scripts/lib/plan-machine-test.sh +15 -2
  161. package/scripts/lib/plan-machine.sh +20 -7
  162. package/scripts/lib/plan-next-test.sh +1 -1
  163. package/scripts/lib/plan-next.sh +4 -4
  164. package/scripts/lib/pr-evidence-test.sh +3 -3
  165. package/scripts/lib/pr-evidence.sh +1 -1
  166. package/scripts/lib/qa-lane-test.sh +626 -0
  167. package/scripts/lib/qa-lane.sh +1357 -0
  168. package/scripts/lib/qa-lanes-test.sh +175 -0
  169. package/scripts/lib/react-detect.sh +1 -1
  170. package/scripts/lib/render-test.sh +1 -1
  171. package/scripts/lib/review-page-test.sh +318 -0
  172. package/scripts/lib/review-page.sh +369 -0
  173. package/scripts/lib/review-stage-test.sh +62 -11
  174. package/scripts/lib/review-stage.sh +42 -60
  175. package/scripts/lib/role-identity-test.sh +65 -0
  176. package/scripts/lib/role-identity.sh +25 -2
  177. package/scripts/lib/secret-guard.sh +3 -3
  178. package/scripts/lib/session-registry-test.sh +111 -0
  179. package/scripts/lib/session-registry.sh +233 -0
  180. package/scripts/lib/stage-receipt-test.sh +14 -1
  181. package/scripts/lib/stage-receipt.sh +13 -8
  182. package/scripts/lib/task-source-file.sh +309 -0
  183. package/scripts/lib/task-source.sh +130 -0
  184. package/scripts/lib/test-env-test.sh +3 -3
  185. package/scripts/lib/test-env.sh +7 -4
  186. package/scripts/lib/upgrade-report-test.sh +120 -0
  187. package/scripts/lib/upgrade-report.sh +138 -0
  188. package/scripts/lib/version-bump.sh +3 -3
  189. package/scripts/lib/wave-result-test.sh +80 -0
  190. package/scripts/lib/wave-result.sh +127 -0
  191. package/scripts/lib/worker-brief-test.sh +5 -0
  192. package/scripts/lib/worker-brief.sh +2 -2
  193. package/scripts/lib/worktree-issue-test.sh +30 -1
  194. package/scripts/lib/worktree-issue.sh +93 -9
  195. package/scripts/lib/worktree-ports-test.sh +57 -4
  196. package/scripts/lib/worktree-start-test.sh +197 -0
  197. package/scripts/lib/worktree-start.sh +169 -32
  198. package/scripts/lib/zsh-safety-test.sh +19 -3
  199. package/scripts/marketing-walkthrough-test.sh +152 -0
  200. package/scripts/night-grant-test.sh +37 -0
  201. package/scripts/night-grant.sh +448 -0
  202. package/scripts/night-run-test.sh +8 -0
  203. package/scripts/night-run.mjs +275 -0
  204. package/scripts/night-run.test.mjs +324 -0
  205. package/scripts/orchestrate-test.sh +190 -0
  206. package/scripts/orchestrate.sh +79 -8
  207. package/scripts/portable-test.sh +11 -2
  208. package/scripts/publish.sh +28 -3
  209. package/scripts/review-lint-test.sh +7 -7
  210. package/scripts/review-lint.sh +2 -2
  211. package/scripts/review-rules.conf +8 -0
  212. package/scripts/rule-recipes-test.sh +96 -0
  213. package/scripts/self-install-test.sh +39 -9
  214. package/scripts/setup-labels.sh +18 -1
  215. package/scripts/setup-milestones.sh +1 -1
  216. package/scripts/showcase.sh +1 -1
  217. package/scripts/skill-frontmatter-lint-test.sh +4 -4
  218. package/scripts/skill-frontmatter-lint.sh +1 -1
  219. package/scripts/status-test.sh +113 -2
  220. package/scripts/status.sh +16 -3
  221. package/scripts/task-sync-test.sh +154 -0
  222. package/scripts/task-sync.sh +243 -32
  223. package/scripts/test-runner-test.sh +158 -0
  224. package/scripts/test.sh +131 -23
  225. package/scripts/update-path-test.sh +279 -0
  226. package/scripts/ux-ds-audit.sh +1 -1
  227. package/scripts/ux-graph-scan.sh +6 -6
  228. package/scripts/wave-worker.sh +54 -0
  229. package/skills/kit-add/SKILL.md +77 -0
  230. package/skills/kit-autopilot/SKILL.md +123 -12
  231. package/skills/kit-cleanup/SKILL.md +5 -2
  232. package/skills/kit-contribute/SKILL.md +4 -4
  233. package/skills/kit-docs-writer/SKILL.md +16 -6
  234. package/skills/kit-effort-close/SKILL.md +17 -8
  235. package/skills/kit-effort-new/SKILL.md +15 -9
  236. package/skills/kit-effort-pr/SKILL.md +15 -7
  237. package/skills/kit-effort-start/SKILL.md +5 -2
  238. package/skills/kit-gc/SKILL.md +5 -2
  239. package/skills/kit-next/SKILL.md +5 -1
  240. package/skills/kit-onboard/SKILL.md +3 -3
  241. package/skills/kit-page/SKILL.md +93 -0
  242. package/skills/kit-plan-next/SKILL.md +8 -4
  243. package/skills/kit-security-sweep/SKILL.md +1 -3
  244. package/skills/kit-ship/SKILL.md +2 -3
  245. package/skills/kit-status/SKILL.md +35 -4
  246. package/skills/kit-task-new/SKILL.md +3 -3
  247. package/skills/kit-task-pr/SKILL.md +7 -2
  248. package/skills/kit-task-pr-merge/SKILL.md +7 -2
  249. package/skills/kit-task-start/SKILL.md +7 -7
  250. package/skills/kit-task-sync/SKILL.md +19 -3
  251. package/skills/kit-ux-audit/SKILL.md +3 -2
  252. package/templates/agents/auto-dev.md +5 -4
  253. package/templates/agents/backend.md +1 -1
  254. package/templates/agents/designer.md +2 -0
  255. package/templates/agents/devops.md +1 -1
  256. package/templates/agents/editor.md +9 -1
  257. package/templates/agents/frontend.md +1 -1
  258. package/templates/agents/local-delegate.md +1 -1
  259. package/templates/agents/pm.md +5 -5
  260. package/templates/agents/tech-lead.md +1 -1
  261. package/templates/benchmarks/SCHEMA.md +9 -3
  262. package/templates/codex/hooks.json.tmpl +89 -0
  263. package/templates/hooks/guard-base-branch-commit.sh.tmpl +13 -7
  264. package/templates/hooks/guard-raw-git-ops.sh.tmpl +27 -14
  265. package/templates/hooks/mempal_followup.sh.tmpl +2 -2
  266. package/templates/hooks/mempal_session_start.sh.tmpl +1 -1
  267. package/templates/hooks/prepush_gate.sh.tmpl +4 -2
  268. package/templates/hooks/repo-hygiene.sh.tmpl +3 -2
  269. package/templates/instructions.md.tmpl +174 -0
  270. package/templates/kit.config.json.tmpl +3 -3
  271. package/templates/knowledge-INDEX.md.tmpl +1 -1
  272. package/templates/lib/kit-sigil.sh.tmpl +1 -1
  273. package/templates/rules/authoring.md +106 -0
  274. package/templates/rules/branch-naming.md +40 -4
  275. package/templates/rules/code-retrieval.md +63 -0
  276. package/templates/rules/delegation-brief.md +0 -3
  277. package/templates/rules/design-routing.md +3 -3
  278. package/templates/rules/effort-model.md +14 -10
  279. package/templates/rules/gate-and-review.md +94 -0
  280. package/templates/rules/issue-lifecycle.md +88 -0
  281. package/templates/rules/knowledge-base.md +1 -1
  282. package/templates/rules/mempalace.md +1 -1
  283. package/templates/rules/merge-safety.md +108 -0
  284. package/templates/rules/naming-and-ids.md +23 -17
  285. package/templates/rules/plain-language.md +59 -0
  286. package/templates/rules/plan-next.md +9 -11
  287. package/templates/rules/react-annotate.md +6 -0
  288. package/templates/rules/review-pages.md +49 -0
  289. package/templates/rules/risk-tiered-review.md +13 -4
  290. package/templates/rules/shared-checkout.md +106 -0
  291. package/templates/rules/skill-gaps.md +2 -7
  292. package/templates/rules/task-management.md +13 -1
  293. package/templates/skills/brand-voice/SKILL.md +91 -0
  294. package/templates/skills/brand-voice/references/voice-template.md +61 -0
  295. package/templates/skills/campaign/SKILL.md +123 -0
  296. package/templates/skills/campaign/references/plan-template.md +55 -0
  297. package/templates/skills/concrete/SKILL.md +2 -2
  298. package/templates/skills/copywriting/SKILL.md +8 -1
  299. package/templates/skills/feature-build-refine/SKILL.md +2 -4
  300. package/templates/skills/morning-briefing/SKILL.md +2 -2
  301. package/templates/skills/page-design/SKILL.md +145 -0
  302. package/templates/skills/page-design/add.json +5 -0
  303. package/templates/skills/page-design/references/design-file-template.md +40 -0
  304. package/templates/skills/page-design/references/generic-page-patterns.md +43 -0
  305. package/templates/skills/page-design/references/minimum-rules.md +42 -0
  306. package/templates/skills/speckit/SKILL.md +4 -5
  307. package/templates/skills/supabase-patterns/SKILL.md +1 -1
  308. package/commands/kit-add.md +0 -42
  309. package/templates/CLAUDE.md.tmpl +0 -106
@@ -17,6 +17,12 @@
17
17
  # RECORDED under the git-common-dir, so uniqueness is by construction and an issue keeps its
18
18
  # slot for as long as its worktree lives.
19
19
  #
20
+ # 4. A LOCK THAT DID NOT EXCLUDE (#449). The ledger lock was `mkdir`. The `mkdir` of uutils
21
+ # coreutils 0.10.0 (Ubuntu 26.04, GitHub's `ubuntu-latest`) exits 0 for the loser of a race, so
22
+ # two allocations ran together and took the same slot: 4 of 70 runs of this file on that
23
+ # runner, 52 of 100 runs of section 6 in an Ubuntu 26.04 container. Section 7 races the
24
+ # primitive itself.
25
+ #
20
26
  # The bar: N worktrees over arbitrary issue numbers, in either config layout, produce N disjoint
21
27
  # port sets — and re-running for a live issue never renumbers it.
22
28
  #
@@ -85,6 +91,20 @@ wt_assign_ports "$W" 7 "$P" >/dev/null 2>&1
85
91
  after="$(ports_of "$W" | tr '\n' ' ')"
86
92
  [ "$before" = "$after" ] && ok || bad "re-run renumbered a live lane: '$before' -> '$after'"
87
93
 
94
+ # ── 4b. the public readers agree with the allocation (#295) ───────────────────────────────────
95
+ # The QA lane derives its ports from wt_port_slot + wt_port_stride. If either disagreed with what
96
+ # wt_assign_ports wrote, a lane's stack would boot off the worktree's own port block.
97
+ slot7="$(wt_port_slot "$P" 7 "$W" 2>/dev/null)"
98
+ stride7="$(wt_port_stride "$P/cckit.config.json")"
99
+ [ "$stride7" = 10 ] && ok || bad "wt_port_stride default: got '$stride7', want 10"
100
+ first7="$(ports_of "$W" | sed -n 1p)"
101
+ [ "$first7" = "$(( 3001 + slot7 * stride7 ))" ] && ok || bad "wt_port_slot disagrees with the assigned port: slot '$slot7' stride '$stride7' port '$first7'"
102
+ [ "$(wt_port_slot "$P" 7 "$W" 2>/dev/null)" = "$slot7" ] && ok || bad "wt_port_slot renumbered a live issue"
103
+ printf '%s' '{"worktree":{"devPortStride":25}}' > "$TMP/stride.json"
104
+ [ "$(wt_port_stride "$TMP/stride.json")" = 25 ] && ok || bad "wt_port_stride ignored worktree.devPortStride"
105
+ printf '%s' '{"worktree":{"devPortStride":"wide"}}' > "$TMP/stride.json"
106
+ [ "$(wt_port_stride "$TMP/stride.json")" = 10 ] && ok || bad "wt_port_stride accepted a non-integer stride"
107
+
88
108
  # ── 5. a freed slot is reclaimed, not leaked ──────────────────────────────────────────────────
89
109
  slots="$(git -C "$P" rev-parse --git-common-dir 2>/dev/null)"
90
110
  case "$slots" in /*) : ;; *) slots="$(cd "$P" && cd "$slots" && pwd)" ;; esac
@@ -119,7 +139,7 @@ for num in $RACE_NUMS; do
119
139
  while [ "$(lines_in "$barrier")" -lt "$RACE_N" ] && [ "$waited" -lt 50 ]; do
120
140
  sleep 0.1; waited=$(( waited + 1 ))
121
141
  done
122
- wt_assign_ports "$W" "$num" "$P" >/dev/null 2>&1
142
+ wt_assign_ports "$W" "$num" "$P" >/dev/null 2>"$P/.err.$num"
123
143
  ) &
124
144
  pids="$pids $!"
125
145
  done
@@ -134,13 +154,46 @@ race_uniq="$(printf '%s' "$race" | sort -u | grep -c .)"
134
154
  [ "$race_total" = 24 ] && ok || bad "parallel: expected 24 ports over 8 concurrent worktrees, got $race_total"
135
155
  if [ "$race_total" = "$race_uniq" ]; then ok; else
136
156
  bad "parallel port collision: $race_total ports but only $race_uniq distinct ($(printf '%s' "$race" | sort | uniq -d | tr '\n' ' '))"
157
+ # The evidence, not only the verdict: what the ledger recorded and what the allocator said on
158
+ # stderr (a lock that timed out warns there). Without these a collision cannot be traced (#449).
159
+ echo " ledger:"; sed 's/^/ /' "$P/.git/kit-portslots.tsv" 2>&1
160
+ echo " allocator stderr:"; cat "$P"/.err.* 2>/dev/null | grep -v ' PORT=' | sed 's/^/ /'
137
161
  fi
138
162
 
139
- # The lock is released on the way out — a leftover lock directory wedges every later start until
140
- # the one-minute abandonment window elapses.
163
+ # The lock is released on the way out — a leftover lock wedges every later start until the
164
+ # one-minute abandonment window elapses.
141
165
  race_gcd="$(git -C "$P" rev-parse --git-common-dir 2>/dev/null)"
142
166
  case "$race_gcd" in /*) : ;; *) race_gcd="$(cd "$P" && cd "$race_gcd" && pwd)" ;; esac
143
- [ ! -d "$race_gcd/kit-portslots.tsv.lock" ] && ok || bad "the port-slot lock was left behind after allocation"
167
+ [ ! -e "$race_gcd/kit-portslots.tsv.lock" ] && ok || bad "the port-slot lock was left behind after allocation"
168
+
169
+ # ── 7. the lock primitive excludes: of N simultaneous attempts exactly one wins (#449) ────────
170
+ # Section 6 only fails when two allocations happen to overlap. This one asks the primitive
171
+ # directly: eight processes make ONE attempt each on the same lock, released together by a start
172
+ # file, and the winners are counted. A primitive that checks and then creates (uutils `mkdir`)
173
+ # reports several winners in most rounds, so 25 rounds do not pass by luck.
174
+ LOCK_ROUNDS=25; lock_bad=0; lock_detail=""
175
+ L="$TMP/prim.lock"; go="$TMP/prim.go"; won="$TMP/prim.won"
176
+ r=0
177
+ while [ "$r" -lt "$LOCK_ROUNDS" ]; do
178
+ r=$((r+1)); rm -rf "$L" "$go"; : > "$won"; pids=""
179
+ for k in 1 2 3 4 5 6 7 8; do
180
+ (
181
+ waited=0
182
+ while [ ! -e "$go" ] && [ "$waited" -lt 20000 ]; do waited=$((waited+1)); done # spin: a sleep would spread the attempts out
183
+ _wt_lock_try "$L" && echo "$k" >> "$won"
184
+ ) &
185
+ pids="$pids $!"
186
+ done
187
+ : > "$go"
188
+ for pid in $pids; do wait "$pid"; done
189
+ winners="$(lines_in "$won")"
190
+ [ "$winners" = 1 ] || { lock_bad=$((lock_bad+1)); lock_detail="$lock_detail $winners"; }
191
+ done
192
+ [ "$lock_bad" = 0 ] && ok || bad "the lock primitive let $lock_bad of $LOCK_ROUNDS rounds end without exactly one winner (winners per bad round:$lock_detail)"
193
+ _wt_unlock "$L"; [ ! -e "$L" ] && ok || bad "_wt_unlock left the lock in place"
194
+ # A cckit from before #449 leaves a lock DIRECTORY at the same path: it must still block.
195
+ mkdir "$L"; if _wt_lock_try "$L"; then bad "a lock directory from an older cckit did not block"; else ok; fi
196
+ _wt_unlock "$L"; [ ! -e "$L" ] && ok || bad "_wt_unlock left an older lock directory in place"
144
197
 
145
198
  echo "worktree-ports-test: $n assertion(s), $([ "$fail" = 0 ] && echo "all passed" || echo "FAILURES")"
146
199
  exit "$fail"
@@ -0,0 +1,197 @@
1
+ #!/usr/bin/env bash
2
+ # worktree-start-test.sh — wt_start sees live session claims (#384).
3
+ #
4
+ # The bug: a second `cckit start <N>` from another session got "reusing worktree" and rc 0, so two
5
+ # agents wrote one tree. The bar: a LIVE claim by another session refuses the start before any
6
+ # fetch, branch or worktree; `--force` / KIT_FORCE=1 proceeds; a dead session's claim is reaped;
7
+ # the claimant's own re-run stays a no-op; `cckit claims` lists and writes nothing.
8
+ #
9
+ # Hermetic: a throwaway repo with a local bare origin, a stubbed `gh` (no network, no auth) and a
10
+ # stubbed `zoxide` (so no temp path lands in the developer's jump database). A "session" is a
11
+ # background `sleep` whose pid is handed to wt_start through KIT_SESSION_PID.
12
+ #
13
+ # Run: bash scripts/lib/worktree-start-test.sh
14
+ # errors: strict — a test runner: rc 1 on any failed assertion
15
+ set -u
16
+ LIB="$(cd "$(dirname "$0")" && pwd)"
17
+ ROOT="$(cd "$LIB/../.." && pwd)"
18
+ # shellcheck source=/dev/null
19
+ . "$LIB/test-env.sh" && test_env_seal
20
+ command -v jq >/dev/null 2>&1 || { echo "worktree-start-test: jq required" >&2; exit 1; }
21
+
22
+ fail=0
23
+ t() { if [ "$2" = "$3" ]; then echo "ok: $1"; else echo "FAIL: $1 -> got '[$2]' want '[$3]'"; fail=1; fi; }
24
+ has() { case "$2" in *"$3"*) echo "ok: $1" ;; *) echo "FAIL: $1 -> missing '$3' in [$2]"; fail=1 ;; esac; }
25
+
26
+ tmp="$(cd "$(mktemp -d 2>/dev/null || mktemp -d -t wst)" && pwd -P)"
27
+ SESS_A=""; SESS_B=""
28
+ cleanup() {
29
+ [ -n "$SESS_A" ] && kill "$SESS_A" 2>/dev/null
30
+ [ -n "$SESS_B" ] && kill "$SESS_B" 2>/dev/null
31
+ rm -rf "$tmp"
32
+ }
33
+ trap cleanup EXIT INT TERM
34
+
35
+ # ── fixture: stubs, a bare origin with `main`, and a clone to start worktrees from ─────────────
36
+ mkdir -p "$tmp/bin"
37
+ cat > "$tmp/bin/gh" <<'SH'
38
+ #!/usr/bin/env bash
39
+ # Every call is logged, so a test can assert a refusal made NO GitHub read.
40
+ printf '%s\n' "$*" >> "${GH_CALL_LOG:-/dev/null}"
41
+ case "$*" in
42
+ *"issue view"*) echo '{"title":"Claimed thing","labels":[{"name":"kind:task"}]}' ;;
43
+ *graphql*) echo '{"data":{}}' ;;
44
+ *) echo '[]' ;;
45
+ esac
46
+ SH
47
+ printf '#!/bin/sh\nexit 0\n' > "$tmp/bin/zoxide"
48
+ chmod +x "$tmp/bin/gh" "$tmp/bin/zoxide"
49
+ PATH="$tmp/bin:$PATH"; export PATH
50
+ export GH_CALL_LOG="$tmp/gh.calls"; : > "$GH_CALL_LOG"
51
+
52
+ git init -q --bare "$tmp/origin.git"
53
+ git init -q "$tmp/repo"
54
+ (
55
+ cd "$tmp/repo" || exit 1
56
+ git config user.email t@example.invalid; git config user.name t; git config commit.gpgsign false
57
+ git checkout -q -b main
58
+ printf '{ "kitVersion":"9.9.9", "project":{"name":"fx","slug":"fx"},\n "github":{"repo":"octo/fx","owner":"octo","baseBranch":"main","projectsV2":false} }\n' > cckit.config.json
59
+ git add cckit.config.json && git commit -q -m init
60
+ git remote add origin "$tmp/origin.git" && git push -q origin main
61
+ ) || { echo "FAIL: fixture repo setup"; exit 1; }
62
+ REPO="$tmp/repo"
63
+ REG="$REPO/.git/kit-sessions"
64
+
65
+ export WT_START_REPO="octo/fx" KIT_BASE_BRANCH="main" KIT_WT_INSTALL=0
66
+ # shellcheck source=/dev/null
67
+ . "$LIB/worktree-start.sh"
68
+
69
+ sleep 600 & SESS_A=$!
70
+ sleep 600 & SESS_B=$!
71
+
72
+ # start_as <session-pid> <args…> — wt_start from the main checkout, as that session.
73
+ start_as() { local sp="$1"; shift; ( cd "$REPO" && KIT_SESSION_PID="$sp" wt_start "$@" ); }
74
+ branches() { git -C "$REPO" for-each-ref --format='%(refname:short)' refs/heads | sort | tr '\n' ' '; }
75
+ worktrees() { git -C "$REPO" worktree list --porcelain | grep -c '^worktree '; }
76
+
77
+ # ── 1. first start: creates the worktree and writes the claim ──────────────────────────────────
78
+ out="$(start_as "$SESS_A" 7 2>/dev/null)"; rc=$?
79
+ t "first start succeeds" "$rc" "0"
80
+ WT7="$REPO/.claude/worktrees/task+7-claimed-thing"
81
+ t "first start prints path|branch|issue" "$out" "$WT7|task/7-claimed-thing|7"
82
+ t "claim file written" "$([ -f "$REG/issue-7.json" ] && echo yes || echo no)" "yes"
83
+ t "claim records the session pid" "$(jq -r .pid "$REG/issue-7.json" 2>/dev/null)" "$SESS_A"
84
+ t "claim records the worktree" "$(jq -r .worktree "$REG/issue-7.json" 2>/dev/null)" "$WT7"
85
+ t "claim records the branch" "$(jq -r .branch "$REG/issue-7.json" 2>/dev/null)" "task/7-claimed-thing"
86
+ t "claim records the issue" "$(jq -r .issue "$REG/issue-7.json" 2>/dev/null)" "7"
87
+ t "claim records a start time" "$(jq -r '.started | type' "$REG/issue-7.json" 2>/dev/null)" "number"
88
+
89
+ # ── 6. the EXISTING reader sees the claim (it reads .pid + .cwd, skips cache-*) ────────────────
90
+ _wt_session_owns "$REPO" "$WT7"; t "_wt_session_owns sees the wt_start claim" "$?" "0"
91
+ _wt_session_owns "$REPO" "$REPO/.claude/worktrees/task+8-nope"; t "_wt_session_owns is false for an unclaimed path" "$?" "1"
92
+
93
+ # ── 1. a second session is refused — and nothing is created, nothing is fetched or read ────────
94
+ # A second issue number makes "no new worktree, no new branch" observable: 7 already has both, so
95
+ # the refusal case that proves it is a claim on an issue whose worktree does NOT exist yet.
96
+ mkdir -p "$REG"
97
+ jq -n --argjson pid "$SESS_A" --arg host "$(hostname)" --arg wt "$REPO/.claude/worktrees/task+9-claimed-thing" \
98
+ --argjson started "$(date +%s)" \
99
+ '{issue:9, branch:"task/9-claimed-thing", worktree:$wt, cwd:$wt, pid:$pid, host:$host, started:$started}' \
100
+ > "$REG/issue-9.json"
101
+ b_before="$(branches)"; w_before="$(worktrees)"; : > "$GH_CALL_LOG"
102
+ fetch_before="$(stat -c %Y "$REPO/.git/FETCH_HEAD" 2>/dev/null || stat -f %m "$REPO/.git/FETCH_HEAD" 2>/dev/null)"
103
+ err="$(start_as "$SESS_B" 9 2>&1 >/dev/null)"; rc=$?
104
+ t "second session on a claimed issue is refused (rc 1)" "$rc" "1"
105
+ has "refusal names the claimant pid" "$err" "pid $SESS_A"
106
+ has "refusal names the escape hatch" "$err" "--force"
107
+ t "refusal creates no branch" "$(branches)" "$b_before"
108
+ t "refusal creates no worktree" "$(worktrees)" "$w_before"
109
+ t "refusal creates no worktree dir" "$([ -e "$REPO/.claude/worktrees/task+9-claimed-thing" ] && echo yes || echo no)" "no"
110
+ t "refusal makes no gh call (it runs before the issue read)" "$(wc -l < "$GH_CALL_LOG" | tr -d ' ')" "0"
111
+ t "refusal runs before the fetch (FETCH_HEAD untouched)" \
112
+ "$(stat -c %Y "$REPO/.git/FETCH_HEAD" 2>/dev/null || stat -f %m "$REPO/.git/FETCH_HEAD" 2>/dev/null)" "$fetch_before"
113
+ t "refusal leaves the claim with its owner" "$(jq -r .pid "$REG/issue-9.json")" "$SESS_A"
114
+
115
+ # The same refusal on the issue that already has a worktree: no "reusing worktree" success.
116
+ out="$(start_as "$SESS_B" 7 2>/dev/null)"; rc=$?
117
+ t "second session on a claimed, existing worktree is refused" "$rc" "1"
118
+ t "refused start prints no worktree line" "$out" ""
119
+
120
+ # ── 2. --force and KIT_FORCE=1 proceed ─────────────────────────────────────────────────────────
121
+ out="$(start_as "$SESS_B" --force 9 2>/dev/null)"; rc=$?
122
+ t "--force starts a claimed issue" "$rc" "0"
123
+ t "--force is not taken for the issue number" "$out" "$REPO/.claude/worktrees/task+9-claimed-thing|task/9-claimed-thing|9"
124
+ t "--force takes the claim over" "$(jq -r .pid "$REG/issue-9.json")" "$SESS_B"
125
+ out="$(start_as "$SESS_B" 7 --force 2>/dev/null)"; rc=$?
126
+ t "--force after the issue number also works" "$rc" "0"
127
+ t "claim 7 now belongs to the forcing session" "$(jq -r .pid "$REG/issue-7.json")" "$SESS_B"
128
+ out="$( cd "$REPO" && KIT_FORCE=1 KIT_SESSION_PID="$SESS_A" wt_start 7 2>/dev/null )"; rc=$?
129
+ t "KIT_FORCE=1 starts a claimed issue" "$rc" "0"
130
+ t "KIT_FORCE=1 takes the claim over" "$(jq -r .pid "$REG/issue-7.json")" "$SESS_A"
131
+ err="$(start_as "$SESS_A" --bogus 7 2>&1 >/dev/null)"; rc=$?
132
+ t "an unknown flag is refused, not read as the issue" "$rc" "1"
133
+
134
+ # ── 4. the claimant's own re-run is a no-op success ────────────────────────────────────────────
135
+ before="$(cat "$REG/issue-7.json")"
136
+ out="$(start_as "$SESS_A" 7 2>/dev/null)"; rc=$?
137
+ t "re-run by the claiming session succeeds" "$rc" "0"
138
+ t "re-run by the claiming session leaves the claim untouched" "$(cat "$REG/issue-7.json")" "$before"
139
+ # From inside the claim's own worktree, as a session with a DIFFERENT pid (an agent's fresh shell).
140
+ out="$( cd "$WT7" && KIT_SESSION_PID="$SESS_B" wt_start 7 2>/dev/null )"; rc=$?
141
+ t "re-run from the claim's own worktree succeeds" "$rc" "0"
142
+ t "re-run from the claim's own worktree prints the same line" "$out" "$WT7|task/7-claimed-thing|7"
143
+ t "re-run from the claim's own worktree leaves the claim untouched" "$(cat "$REG/issue-7.json")" "$before"
144
+ t "re-run added no worktree" "$(worktrees)" "3"
145
+
146
+ # ── 5. `cckit claims` lists the live claims and writes nothing ─────────────────────────────────
147
+ snap() { ( cd "$REG" && ls -la . && cat issue-*.json ) 2>/dev/null; }
148
+ before="$(snap)"
149
+ human="$( cd "$REPO" && "$ROOT/bin/cckit" claims 2>/dev/null )"; rc=$?
150
+ t "cckit claims exits 0" "$rc" "0"
151
+ has "cckit claims lists issue 7" "$human" "#7"
152
+ has "cckit claims lists the branch" "$human" "task/7-claimed-thing"
153
+ json="$( cd "$REPO" && "$ROOT/bin/cckit" claims --llm 2>/dev/null )"
154
+ t "cckit claims --llm is a JSON array of both live claims" "$(printf '%s' "$json" | jq -c '[.[].issue]' 2>/dev/null)" "[7,9]"
155
+ t "cckit claims --llm carries the pid" "$(printf '%s' "$json" | jq -r '.[0].pid' 2>/dev/null)" "$SESS_A"
156
+ t "cckit claims works from inside a worktree" "$( cd "$WT7" && "$ROOT/bin/cckit" claims --llm 2>/dev/null | jq -c '[.[].issue]' )" "[7,9]"
157
+ t "cckit claims writes nothing" "$(snap)" "$before"
158
+
159
+ # ── 3. a dead session's claim is reaped and the start proceeds ─────────────────────────────────
160
+ kill "$SESS_A" 2>/dev/null; wait "$SESS_A" 2>/dev/null; DEAD="$SESS_A"; SESS_A=""
161
+ before="$(snap)"
162
+ t "cckit claims hides a dead session's claim" "$( cd "$REPO" && "$ROOT/bin/cckit" claims --llm 2>/dev/null | jq -c '[.[].issue]' )" "[9]"
163
+ t "cckit claims does not reap it (read-only)" "$(snap)" "$before"
164
+ _wt_session_owns "$REPO" "$WT7"; t "_wt_session_owns is false once the session died" "$?" "1"
165
+ out="$(start_as "$SESS_B" 7 2>/dev/null)"; rc=$?
166
+ t "start over a dead session's claim proceeds" "$rc" "0"
167
+ t "the dead claim was replaced by the new session's" "$(jq -r .pid "$REG/issue-7.json")" "$SESS_B"
168
+ t "the dead pid is gone from the registry" "$(grep -l "\"pid\": *$DEAD\b" "$REG"/issue-*.json 2>/dev/null | wc -l | tr -d ' ')" "0"
169
+
170
+ # A claim whose worktree was removed (the PR merged, cleanup ran) is dead even with a live pid,
171
+ # once it is older than the grace that covers the claim→`worktree add` window.
172
+ jq -n --argjson pid "$SESS_B" --arg host "$(hostname)" --arg wt "$tmp/gone" --argjson started "$(( $(date +%s) - 4000 ))" \
173
+ '{issue:11, branch:"task/11-x", worktree:$wt, cwd:$wt, pid:$pid, host:$host, started:$started}' > "$REG/issue-11.json"
174
+ start_as "$$" 11 >/dev/null 2>&1; rc=$?
175
+ t "a claim whose worktree is long gone does not block" "$rc" "0"
176
+
177
+ # ── a failed start does not leave a claim behind ───────────────────────────────────────────────
178
+ # `git worktree add -B` fails when the branch is checked out in the main checkout.
179
+ git -C "$REPO" checkout -q -b task/12-claimed-thing
180
+ start_as "$SESS_B" 12 >/dev/null 2>&1; rc=$?
181
+ t "a start whose worktree add fails returns 1" "$rc" "1"
182
+ t "…and releases the claim it had just taken" "$([ -e "$REG/issue-12.json" ] && echo yes || echo no)" "no"
183
+ git -C "$REPO" checkout -q main
184
+
185
+ # ── 7. the CLI reports the ISSUE, not the flag ─────────────────────────────────────────────────
186
+ json="$( cd "$REPO" && KIT_SESSION_PID="$$" "$ROOT/bin/cckit" start --force 9 --llm 2>/dev/null )"
187
+ t "cckit start --force N --llm reports issue N" "$(printf '%s' "$json" | jq -r '.issue' 2>/dev/null)" "9"
188
+ t "cckit start --force N --llm is ok" "$(printf '%s' "$json" | jq -r '.ok' 2>/dev/null)" "true"
189
+ json="$( cd "$REPO" && KIT_SESSION_PID="$SESS_B" "$ROOT/bin/cckit" start 9 --llm 2>/dev/null )"; rc=$?
190
+ t "cckit start on a claimed issue exits 1" "$rc" "1"
191
+ t "cckit start on a claimed issue reports ok:false" "$(printf '%s' "$json" | jq -r '.ok' 2>/dev/null)" "false"
192
+ err="$( cd "$REPO" && KIT_SESSION_PID="$SESS_B" "$ROOT/bin/cckit" start 9 2>&1 >/dev/null )"; rc=$?
193
+ t "cckit start (human mode) on a claimed issue exits 1" "$rc" "1"
194
+ has "cckit start (human mode) prints the refusal" "$err" "refused: a live session already claims this issue"
195
+
196
+ [ "$fail" -eq 0 ] && echo "ALL OK (worktree-start)" || echo "worktree-start: FAILURES"
197
+ exit "$fail"