@jeiemgi/cckit 0.12.0 → 0.13.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 (548) hide show
  1. package/.claude-plugin/plugin.json +4 -2
  2. package/AGENTS.md +17 -237
  3. package/README.md +27 -27
  4. package/SECURITY.md +4 -4
  5. package/bin/PROMPTS.md +12 -0
  6. package/bin/cckit +86 -86
  7. package/cckit.config.json +1 -1
  8. package/kit/PROMPTS.md +14 -0
  9. package/{commands → kit/commands}/kit-doctor.md +3 -4
  10. package/{commands → kit/commands}/kit-export-project.md +1 -1
  11. package/{commands → kit/commands}/kit-init.md +8 -20
  12. package/{commands → kit/commands}/kit-routines.md +1 -1
  13. package/{commands → kit/commands}/kit-update.md +3 -3
  14. package/kit/completions/cckit.bash +9 -0
  15. package/{databases → kit/databases}/supabase.json +1 -1
  16. package/{integrations → kit/integrations}/integration.schema.json +3 -3
  17. package/kit/interview/global.json +54 -0
  18. package/kit/interview/project.json +133 -0
  19. package/kit/modules/qa.json +63 -0
  20. package/kit/modules/software.json +48 -0
  21. package/{profiles → kit/profiles}/automation.json +1 -3
  22. package/{profiles → kit/profiles}/content.json +0 -2
  23. package/{profiles → kit/profiles}/marketing.json +0 -2
  24. package/{profiles → kit/profiles}/minimal.json +1 -3
  25. package/{profiles → kit/profiles}/research.json +1 -3
  26. package/{profiles → kit/profiles}/software.json +0 -2
  27. package/kit/routines/catalogue.json +84 -0
  28. package/{skills → kit/skills}/kit-add/SKILL.md +3 -3
  29. package/{skills → kit/skills}/kit-annotate/SKILL.md +2 -4
  30. package/{skills → kit/skills}/kit-autopilot/SKILL.md +6 -6
  31. package/{skills → kit/skills}/kit-cleanup/SKILL.md +2 -2
  32. package/{skills → kit/skills}/kit-contribute/SKILL.md +8 -12
  33. package/{skills → kit/skills}/kit-customize/SKILL.md +5 -8
  34. package/{skills → kit/skills}/kit-dev/SKILL.md +1 -1
  35. package/{skills → kit/skills}/kit-digest/SKILL.md +3 -3
  36. package/{skills → kit/skills}/kit-effort-close/SKILL.md +4 -4
  37. package/{skills → kit/skills}/kit-effort-new/SKILL.md +6 -6
  38. package/{skills → kit/skills}/kit-effort-start/SKILL.md +3 -3
  39. package/{skills → kit/skills}/kit-gc/SKILL.md +3 -3
  40. package/{skills → kit/skills}/kit-page/SKILL.md +1 -1
  41. package/{skills → kit/skills}/kit-status/SKILL.md +1 -1
  42. package/{skills → kit/skills}/kit-task-close/SKILL.md +5 -5
  43. package/{skills → kit/skills}/kit-task-new/SKILL.md +5 -5
  44. package/{skills → kit/skills}/kit-task-pr/SKILL.md +5 -5
  45. package/{skills → kit/skills}/kit-task-pr-merge/SKILL.md +7 -7
  46. package/{skills → kit/skills}/kit-task-start/SKILL.md +1 -1
  47. package/{skills → kit/skills}/kit-task-sync/SKILL.md +3 -3
  48. package/{skills → kit/skills}/kit-ux-audit/SKILL.md +16 -35
  49. package/{skills → kit/skills}/kit-ux-audit/references/graph-model.md +7 -26
  50. package/{skills → kit/skills}/kit-ux-audit/references/report.md +2 -3
  51. package/{skills → kit/skills}/routing.yaml +1 -1
  52. package/kit/statusline/kit-statusline.sh +82 -0
  53. package/{templates → kit/templates}/agents/analyst.md +0 -11
  54. package/{templates → kit/templates}/agents/auto-dev.md +0 -13
  55. package/{templates → kit/templates}/agents/backend.md +0 -11
  56. package/{templates → kit/templates}/agents/designer.md +0 -11
  57. package/{templates → kit/templates}/agents/devops.md +0 -11
  58. package/{templates → kit/templates}/agents/editor.md +0 -11
  59. package/{templates → kit/templates}/agents/frontend.md +0 -11
  60. package/{templates → kit/templates}/agents/generalist.md +0 -11
  61. package/{templates → kit/templates}/agents/local-delegate.md +0 -13
  62. package/{templates → kit/templates}/agents/n8n.md +0 -11
  63. package/{templates → kit/templates}/agents/pm.md +0 -11
  64. package/{templates → kit/templates}/agents/qa.md +0 -11
  65. package/{templates → kit/templates}/agents/researcher.md +0 -11
  66. package/{templates → kit/templates}/agents/security.md +0 -11
  67. package/{templates → kit/templates}/agents/tech-lead.md +0 -11
  68. package/{templates → kit/templates}/agents/ux.md +3 -14
  69. package/{templates → kit/templates}/instructions.md.tmpl +1 -18
  70. package/{templates → kit/templates}/kit.config.json.tmpl +0 -6
  71. package/{templates → kit/templates}/rules/branch-naming.md +3 -2
  72. package/{templates → kit/templates}/rules/merge-safety.md +3 -2
  73. package/{templates → kit/templates}/rules/react-annotate.md +0 -8
  74. package/kit.config.schema.json +11 -11
  75. package/lib/PROMPTS.md +14 -0
  76. package/{scripts/lib → lib/core}/adapter-select-test.sh +7 -7
  77. package/{scripts → lib/core}/advisor-test.sh +3 -3
  78. package/{scripts/lib → lib/core}/agent-def-test.sh +1 -1
  79. package/{scripts/lib → lib/core}/agent-def.sh +2 -2
  80. package/{scripts/lib → lib/core}/agent-launch-test.sh +3 -3
  81. package/{scripts/lib → lib/core}/agent-profile-test.sh +2 -2
  82. package/{scripts/lib → lib/core}/agent-resolve-test.sh +2 -2
  83. package/{scripts/lib → lib/core}/agent-resolve.sh +2 -2
  84. package/{scripts → lib/core}/agent-skills-external.txt +3 -3
  85. package/{scripts → lib/core}/agent-skills-lint-test.sh +17 -17
  86. package/lib/core/agent-skills-lint.sh +115 -0
  87. package/{scripts → lib/core}/agent-template-lint-test.sh +7 -7
  88. package/lib/core/agent-template-lint.sh +58 -0
  89. package/{scripts/lib → lib/core}/board-view-test.sh +3 -3
  90. package/lib/core/board-view.sh +97 -0
  91. package/{scripts/lib → lib/core}/branch-owner-test.sh +3 -3
  92. package/lib/core/branch-owner.sh +201 -0
  93. package/lib/core/check.sh +125 -0
  94. package/{scripts/lib → lib/core}/codex-hooks-test.sh +3 -3
  95. package/{scripts → lib/core}/commitlint-test.sh +6 -6
  96. package/lib/core/commitlint.sh +54 -0
  97. package/{scripts/config-path-test.sh → lib/core/config-path-scan-test.sh} +2 -2
  98. package/{scripts/lib → lib/core}/config-path-test.sh +3 -3
  99. package/lib/core/config-path.sh +30 -0
  100. package/{scripts → lib/core}/content-skills-test.sh +16 -16
  101. package/{scripts → lib/core}/docs-marketing-words-test.sh +2 -2
  102. package/{scripts → lib/core}/docs-record-tables-test.sh +2 -2
  103. package/{scripts/lib → lib/core}/effort-metrics-test.sh +6 -6
  104. package/lib/core/effort-metrics.sh +591 -0
  105. package/{scripts/lib → lib/core}/effort-slug-test.sh +4 -4
  106. package/{scripts/lib → lib/core}/effort-slug.sh +3 -3
  107. package/lib/core/effort.sh +339 -0
  108. package/{scripts/lib → lib/core}/errors-header-test.sh +19 -9
  109. package/lib/core/errors-header.exempt +49 -0
  110. package/{scripts → lib/core}/exec-targets-test.sh +3 -3
  111. package/lib/core/feature-map.sh +76 -0
  112. package/{scripts → lib/core}/force-push-fence-test.sh +8 -8
  113. package/lib/core/force-push-fence.sh +51 -0
  114. package/{scripts → lib/core}/forge-fence-test.sh +13 -13
  115. package/{scripts → lib/core}/forge-fence.sh +14 -14
  116. package/{scripts → lib/core}/forge-report-test.sh +5 -5
  117. package/{scripts → lib/core}/forge-report.sh +18 -14
  118. package/{scripts/lib → lib/core}/git-core-test.sh +5 -5
  119. package/{scripts/lib → lib/core}/git-remote-test.sh +3 -3
  120. package/{scripts → lib/core}/guard-raw-git-ops-test.sh +4 -4
  121. package/{scripts → lib/core}/hook-adapter-test.sh +5 -5
  122. package/{scripts/lib → lib/core}/hook-refresh-test.sh +5 -5
  123. package/{scripts → lib/core}/instruction-budget-baseline.txt +1 -1
  124. package/lib/core/instruction-budget-lint.sh +238 -0
  125. package/{scripts/lib → lib/core}/integration-install-test.sh +12 -12
  126. package/lib/core/integration-install.sh +257 -0
  127. package/{scripts/lib → lib/core}/integrations-test.sh +38 -45
  128. package/lib/core/integrations.sh +244 -0
  129. package/{scripts/lib → lib/core}/kinds-test.sh +5 -5
  130. package/lib/core/kinds.sh +66 -0
  131. package/{scripts/lib → lib/core}/kit-cli-test.sh +1 -1
  132. package/{scripts/lib → lib/core}/kit-cli.sh +1 -1
  133. package/{scripts/lib → lib/core}/kit-config-resolve.sh +2 -2
  134. package/{scripts/lib → lib/core}/kit-config-test.sh +11 -11
  135. package/lib/core/kit-config.sh +164 -0
  136. package/{scripts/lib → lib/core}/kit-engine-test.sh +1 -1
  137. package/lib/core/kit-events.sh +72 -0
  138. package/lib/core/kit-local.sh +87 -0
  139. package/{scripts/lib → lib/core}/kit-manifest.sh +1 -1
  140. package/{scripts/lib → lib/core}/kit-mode-test.sh +1 -1
  141. package/{scripts/lib → lib/core}/kit-mode.sh +3 -3
  142. package/{scripts/lib → lib/core}/kit-operate.sh +1 -1
  143. package/{scripts/lib → lib/core}/kit-profile-test.sh +1 -1
  144. package/{scripts/lib → lib/core}/kit-profile.sh +2 -2
  145. package/{scripts/lib → lib/core}/kit-state-test.sh +1 -1
  146. package/lib/core/knowledge-lint.sh +106 -0
  147. package/lib/core/layout-fence-test.sh +35 -0
  148. package/lib/core/layout-fence.allow +15 -0
  149. package/lib/core/layout-fence.baseline +4 -0
  150. package/lib/core/layout-fence.sh +50 -0
  151. package/{scripts → lib/core}/leak-fence-test.sh +10 -10
  152. package/{scripts/lib → lib/core}/leak-fence.sh +1 -1
  153. package/{scripts → lib/core}/loose-issues-test.sh +8 -8
  154. package/{scripts → lib/core}/loose-issues.baseline +1 -1
  155. package/{scripts/lib → lib/core}/loose-issues.sh +2 -2
  156. package/{scripts → lib/core}/marketing-walkthrough-test.sh +7 -7
  157. package/{scripts/lib → lib/core}/naming-test.sh +2 -2
  158. package/{scripts/lib → lib/core}/naming-verbs-test.sh +8 -8
  159. package/lib/core/naming.sh +172 -0
  160. package/{scripts/lib → lib/core}/orchestration-runtime-test.sh +4 -4
  161. package/{scripts → lib/core}/portable-test.sh +10 -6
  162. package/{scripts/lib → lib/core}/pr-evidence-test.sh +5 -5
  163. package/lib/core/pr-evidence.sh +361 -0
  164. package/{scripts/lib → lib/core}/qa-lane-test.sh +7 -7
  165. package/{scripts/lib → lib/core}/qa-lane.sh +3 -3
  166. package/{scripts/lib → lib/core}/qa-lanes-test.sh +5 -5
  167. package/lib/core/react-detect.sh +79 -0
  168. package/{scripts/lib → lib/core}/render-test.sh +1 -1
  169. package/lib/core/resident-context-test.sh +42 -0
  170. package/lib/core/resident-context.baseline +1 -0
  171. package/lib/core/resident-context.sh +56 -0
  172. package/lib/core/review-lint-baseline.txt +28 -0
  173. package/lib/core/review-lint.sh +266 -0
  174. package/{scripts → lib/core}/review-rules.conf +1 -1
  175. package/{scripts/lib → lib/core}/review-stage-test.sh +2 -2
  176. package/{scripts/lib → lib/core}/role-identity-test.sh +3 -3
  177. package/lib/core/role-identity.sh +71 -0
  178. package/{scripts → lib/core}/rule-recipes-test.sh +5 -5
  179. package/lib/core/secret-guard.sh +116 -0
  180. package/{scripts → lib/core}/self-install-test.sh +15 -16
  181. package/{scripts/lib → lib/core}/session-registry-test.sh +1 -1
  182. package/lib/core/session-registry.sh +233 -0
  183. package/{scripts → lib/core}/skill-frontmatter-baseline.txt +1 -1
  184. package/lib/core/skill-frontmatter-lint.sh +189 -0
  185. package/{scripts/lib → lib/core}/spec-lint-test.sh +1 -1
  186. package/lib/core/spec-lint.sh +95 -0
  187. package/{scripts/lib → lib/core}/stage-receipt-test.sh +4 -4
  188. package/{scripts/lib → lib/core}/stage-receipt.sh +3 -3
  189. package/{scripts → lib/core}/terms-check-test.sh +6 -6
  190. package/lib/core/terms-check.sh +244 -0
  191. package/{scripts/lib → lib/core}/test-env-test.sh +2 -2
  192. package/{scripts/lib → lib/core}/test-env.sh +1 -1
  193. package/{scripts → lib/core}/test-runner-test.sh +11 -11
  194. package/{scripts → lib/core}/test.sh +12 -12
  195. package/{scripts → lib/core}/update-path-test.sh +3 -3
  196. package/{scripts → lib/core}/verbs-gen.sh +9 -9
  197. package/{scripts → lib/core}/verbs-help-test.sh +4 -4
  198. package/{scripts → lib/core}/verbs-ratchet-test.sh +18 -18
  199. package/{scripts → lib/core}/verbs-ratchet.sh +8 -8
  200. package/{scripts → lib/core}/verbs-test.sh +19 -19
  201. package/lib/core/verbs.baseline +5 -0
  202. package/{scripts/lib → lib/core}/verbs.sh +2 -2
  203. package/{scripts/lib → lib/core}/verbs.tsv +5 -5
  204. package/{scripts/lib → lib/core}/version-bump-test.sh +29 -8
  205. package/{scripts/lib → lib/core}/version-bump.sh +15 -2
  206. package/{scripts/lib → lib/core}/wave-result-test.sh +2 -2
  207. package/{scripts/lib → lib/core}/wave-result.sh +1 -1
  208. package/{scripts/lib → lib/core}/worker-brief-test.sh +3 -3
  209. package/{scripts/lib → lib/core}/worktree-bootstrap-test.sh +1 -1
  210. package/{scripts/lib → lib/core}/worktree-issue-test.sh +2 -2
  211. package/lib/core/worktree-issue.sh +172 -0
  212. package/{scripts/lib → lib/core}/worktree-ports-test.sh +1 -1
  213. package/{scripts/lib → lib/core}/worktree-start-test.sh +2 -2
  214. package/lib/core/worktree-start.sh +790 -0
  215. package/{scripts/lib → lib/core}/zsh-safety-test.sh +11 -11
  216. package/{scripts/lib → lib/forge}/forge-test.sh +4 -4
  217. package/{scripts/lib → lib/forge}/forge.sh +1 -1
  218. package/{scripts/lib → lib/forge}/gh-board-add-test.sh +3 -3
  219. package/lib/forge/gh-log.sh +59 -0
  220. package/{scripts/lib → lib/forge}/gh-project-test.sh +18 -17
  221. package/lib/forge/gh-project.sh +379 -0
  222. package/{scripts/lib → lib/forge}/gh-rest-test.sh +5 -5
  223. package/{scripts/lib → lib/forge}/gh-rest.sh +1 -1
  224. package/{scripts/lib → lib/forge}/init-github.sh +18 -8
  225. package/lib/verbs/PROMPTS.md +146 -0
  226. package/lib/verbs/annotate-setup.sh +149 -0
  227. package/{scripts → lib/verbs}/autopilot-run-test.sh +9 -9
  228. package/{scripts → lib/verbs}/autopilot-run.sh +9 -9
  229. package/{scripts → lib/verbs}/autopilot-test.sh +7 -6
  230. package/{scripts → lib/verbs}/autopilot.sh +3 -3
  231. package/{scripts/lib → lib/verbs}/captain-test.sh +1 -1
  232. package/{scripts/lib → lib/verbs}/captain.sh +7 -7
  233. package/lib/verbs/capture-project-ids.sh +99 -0
  234. package/{scripts/lib → lib/verbs}/content-kinds-gc-test.sh +7 -7
  235. package/{scripts/lib → lib/verbs}/contribute-root-test.sh +4 -4
  236. package/{scripts/lib → lib/verbs}/contribute-root.sh +1 -1
  237. package/{scripts → lib/verbs}/contribute.sh +8 -8
  238. package/{scripts → lib/verbs}/copilot-loop-test.sh +4 -4
  239. package/{scripts/lib → lib/verbs}/copilot-test.sh +11 -10
  240. package/{scripts/lib → lib/verbs}/copilot.sh +7 -7
  241. package/{scripts → lib/verbs}/database-supabase-test.sh +6 -6
  242. package/{scripts/lib → lib/verbs}/effort-close-subs-test.sh +6 -6
  243. package/{scripts/lib → lib/verbs}/effort-dispatch-test.sh +3 -3
  244. package/{scripts/lib → lib/verbs}/effort-flows-test.sh +5 -5
  245. package/{scripts/lib → lib/verbs}/effort-ops-test.sh +13 -13
  246. package/lib/verbs/effort-ops.sh +1571 -0
  247. package/{scripts/lib → lib/verbs}/effort-parity-test.sh +10 -10
  248. package/{scripts/lib → lib/verbs}/effort-plan-test.sh +7 -7
  249. package/lib/verbs/effort-plan.sh +289 -0
  250. package/{scripts/lib → lib/verbs}/effort-review-test.sh +5 -5
  251. package/{scripts/lib → lib/verbs}/effort-review.sh +2 -2
  252. package/{scripts/lib → lib/verbs}/grill-record-test.sh +1 -1
  253. package/lib/verbs/grill-record.sh +88 -0
  254. package/{scripts/lib → lib/verbs}/handoff.sh +2 -2
  255. package/{scripts → lib/verbs}/init-content-test.sh +14 -14
  256. package/{scripts/lib → lib/verbs}/init-guide.sh +6 -6
  257. package/{scripts → lib/verbs}/init-guided-test.sh +9 -9
  258. package/{scripts → lib/verbs}/init-recipes-test.sh +7 -7
  259. package/{scripts → lib/verbs}/init-upgrade-test.sh +9 -10
  260. package/lib/verbs/init.sh +1598 -0
  261. package/{scripts → lib/verbs}/install-test.sh +5 -5
  262. package/lib/verbs/install.sh +31 -0
  263. package/{scripts → lib/verbs}/integrations-check-test.sh +9 -9
  264. package/lib/verbs/integrations-check.sh +157 -0
  265. package/{scripts → lib/verbs}/kit-add-test.sh +8 -8
  266. package/lib/verbs/kit-add.sh +415 -0
  267. package/{scripts → lib/verbs}/kit-adopt-test.sh +4 -4
  268. package/{scripts → lib/verbs}/kit-adopt.sh +6 -6
  269. package/{scripts/lib → lib/verbs}/kit-brief-test.sh +15 -15
  270. package/{scripts/lib → lib/verbs}/kit-brief.sh +12 -12
  271. package/lib/verbs/kit-bump-version.sh +79 -0
  272. package/lib/verbs/kit-digest.sh +126 -0
  273. package/{scripts → lib/verbs}/kit-doctor-test.sh +52 -32
  274. package/lib/verbs/kit-doctor.sh +991 -0
  275. package/{scripts → lib/verbs}/kit-export-project-test.sh +4 -4
  276. package/lib/verbs/kit-export-project.sh +245 -0
  277. package/{scripts → lib/verbs}/kit-export-training-test.sh +3 -3
  278. package/lib/verbs/kit-export-training.sh +175 -0
  279. package/{scripts/lib → lib/verbs}/kit-gc-test.sh +5 -5
  280. package/lib/verbs/kit-gc.sh +804 -0
  281. package/{scripts/lib → lib/verbs}/kit-hotfix.sh +3 -3
  282. package/{scripts/lib → lib/verbs}/kit-interview-test.sh +2 -2
  283. package/lib/verbs/kit-interview.sh +319 -0
  284. package/{scripts/lib → lib/verbs}/kit-lib-test.sh +1 -1
  285. package/{scripts/lib → lib/verbs}/kit-lib.sh +3 -3
  286. package/{scripts → lib/verbs}/kit-migrate-test.sh +4 -4
  287. package/{scripts → lib/verbs}/kit-migrate.sh +5 -5
  288. package/{scripts/lib → lib/verbs}/kit-msg-test.sh +2 -2
  289. package/{scripts/lib → lib/verbs}/kit-msg.sh +2 -2
  290. package/{scripts → lib/verbs}/kit-onboard-test.sh +2 -3
  291. package/lib/verbs/kit-onboard.sh +69 -0
  292. package/{scripts → lib/verbs}/kit-promote-test.sh +4 -4
  293. package/{scripts → lib/verbs}/kit-promote.sh +4 -4
  294. package/{scripts → lib/verbs}/kit-remove-test.sh +4 -4
  295. package/{scripts → lib/verbs}/kit-remove.sh +5 -5
  296. package/lib/verbs/kit-routines.sh +322 -0
  297. package/lib/verbs/kit-self-update.sh +55 -0
  298. package/{scripts/lib → lib/verbs}/kit-status-test.sh +2 -2
  299. package/lib/verbs/kit-status.sh +650 -0
  300. package/{scripts/lib → lib/verbs}/kit-task-ops-test.sh +8 -2
  301. package/lib/verbs/kit-task-ops.sh +793 -0
  302. package/{scripts → lib/verbs}/kit-version-check-test.sh +3 -3
  303. package/lib/verbs/kit-version-check.sh +121 -0
  304. package/{scripts → lib/verbs}/kit-wire-test.sh +6 -6
  305. package/{scripts → lib/verbs}/kit-wire.sh +8 -8
  306. package/{scripts/lib → lib/verbs}/kto-hotfix-test.sh +3 -3
  307. package/{scripts/lib → lib/verbs}/kto-task-close-test.sh +2 -2
  308. package/{scripts/lib → lib/verbs}/kto-task-new-test.sh +2 -2
  309. package/{scripts/lib → lib/verbs}/kto-task-pr-merge-test.sh +2 -2
  310. package/{scripts/lib → lib/verbs}/kto-task-pr-test.sh +3 -3
  311. package/{scripts/lib → lib/verbs}/light-task-run-test.sh +4 -4
  312. package/{scripts/lib → lib/verbs}/light-task-test.sh +9 -9
  313. package/{scripts/lib → lib/verbs}/light-task.sh +11 -11
  314. package/{scripts/lib → lib/verbs}/next-test.sh +2 -2
  315. package/{scripts/lib → lib/verbs}/next.sh +4 -4
  316. package/{scripts → lib/verbs}/night-grant-test.sh +4 -4
  317. package/lib/verbs/night-grant.sh +454 -0
  318. package/{scripts → lib/verbs}/night-run-test.sh +3 -3
  319. package/{scripts → lib/verbs}/night-run.mjs +2 -2
  320. package/{scripts → lib/verbs}/orchestrate-test.sh +5 -5
  321. package/{scripts → lib/verbs}/orchestrate.sh +15 -15
  322. package/{scripts/lib → lib/verbs}/plan-machine-test.sh +1 -1
  323. package/{scripts/lib → lib/verbs}/plan-machine.sh +4 -4
  324. package/{scripts/lib → lib/verbs}/plan-next-test.sh +1 -1
  325. package/lib/verbs/plan-next.sh +213 -0
  326. package/{scripts → lib/verbs}/publish.sh +10 -10
  327. package/{scripts/lib → lib/verbs}/review-page-test.sh +4 -4
  328. package/lib/verbs/review-page.sh +375 -0
  329. package/lib/verbs/setup-labels.sh +96 -0
  330. package/lib/verbs/setup-milestones.sh +34 -0
  331. package/{scripts → lib/verbs}/showcase.sh +2 -2
  332. package/{scripts/lib → lib/verbs}/sprint-test.sh +5 -5
  333. package/{scripts/lib → lib/verbs}/sprint.sh +2 -2
  334. package/{scripts → lib/verbs}/status-test.sh +7 -7
  335. package/{scripts → lib/verbs}/status.sh +12 -12
  336. package/{scripts → lib/verbs}/task-sync-test.sh +6 -6
  337. package/lib/verbs/task-sync.sh +462 -0
  338. package/{scripts/lib → lib/verbs}/upgrade-report-test.sh +4 -4
  339. package/lib/verbs/ux-a11y-scan.sh +96 -0
  340. package/lib/verbs/ux-ds-audit.sh +146 -0
  341. package/lib/verbs/ux-graph-scan.sh +188 -0
  342. package/{scripts → lib/verbs}/wave-worker.sh +2 -2
  343. package/lib/verbs/web-install.sh +22 -0
  344. package/package.json +3 -10
  345. package/scripts/PROMPTS.md +13 -0
  346. package/scripts/agent-skills-lint.sh +12 -113
  347. package/scripts/agent-template-lint.sh +12 -56
  348. package/scripts/annotate-setup.sh +11 -151
  349. package/scripts/benchmark/checkpoint-test.sh +1 -1
  350. package/scripts/benchmark/checkpoint.sh +1 -1
  351. package/scripts/benchmark/gate.sh +2 -2
  352. package/scripts/benchmark/lib/bench-common.sh +1 -1
  353. package/scripts/capture-project-ids.sh +12 -86
  354. package/scripts/check.sh +12 -112
  355. package/scripts/force-push-fence.sh +12 -49
  356. package/scripts/init.sh +13 -1637
  357. package/scripts/install.sh +12 -29
  358. package/scripts/instruction-budget-lint.sh +13 -218
  359. package/scripts/integrations-check.sh +12 -155
  360. package/scripts/kit-add.sh +12 -413
  361. package/scripts/kit-bump-version.sh +13 -78
  362. package/scripts/kit-digest.sh +13 -125
  363. package/scripts/kit-doctor.sh +13 -1065
  364. package/scripts/kit-export-project.sh +12 -243
  365. package/scripts/kit-export-training.sh +12 -173
  366. package/scripts/kit-onboard.sh +12 -67
  367. package/scripts/kit-routines.sh +12 -320
  368. package/scripts/kit-self-update.sh +12 -53
  369. package/scripts/kit-version-check.sh +12 -106
  370. package/scripts/knowledge-lint.sh +13 -98
  371. package/scripts/lib/board-view.sh +13 -96
  372. package/scripts/lib/branch-owner.sh +12 -199
  373. package/scripts/lib/commitlint.sh +12 -52
  374. package/scripts/lib/config-path.sh +13 -29
  375. package/scripts/lib/effort-metrics.sh +12 -589
  376. package/scripts/lib/effort-ops.sh +13 -1570
  377. package/scripts/lib/effort-plan.sh +12 -287
  378. package/scripts/lib/effort.sh +13 -338
  379. package/scripts/lib/gh-log.sh +14 -59
  380. package/scripts/lib/gh-project.sh +13 -376
  381. package/scripts/lib/grill-record.sh +13 -87
  382. package/scripts/lib/integration-install.sh +12 -255
  383. package/scripts/lib/integrations.sh +12 -242
  384. package/scripts/lib/kinds.sh +13 -65
  385. package/scripts/lib/kit-config.sh +12 -165
  386. package/scripts/lib/kit-events.sh +13 -71
  387. package/scripts/lib/kit-gc.sh +12 -802
  388. package/scripts/lib/kit-interview.sh +11 -316
  389. package/scripts/lib/kit-local.sh +12 -85
  390. package/scripts/lib/kit-status.sh +12 -648
  391. package/scripts/lib/kit-task-ops.sh +13 -789
  392. package/scripts/lib/naming.sh +12 -170
  393. package/scripts/lib/plan-next.sh +13 -212
  394. package/scripts/lib/pr-evidence.sh +12 -359
  395. package/scripts/lib/react-detect.sh +12 -77
  396. package/scripts/lib/review-page.sh +11 -372
  397. package/scripts/lib/role-identity.sh +13 -70
  398. package/scripts/lib/secret-guard.sh +12 -114
  399. package/scripts/lib/session-registry.sh +13 -232
  400. package/scripts/lib/spec-lint.sh +13 -94
  401. package/scripts/lib/worktree-issue.sh +12 -170
  402. package/scripts/lib/worktree-start.sh +13 -789
  403. package/scripts/night-grant.sh +12 -452
  404. package/scripts/review-lint.sh +13 -258
  405. package/scripts/setup-labels.sh +11 -82
  406. package/scripts/setup-milestones.sh +12 -21
  407. package/scripts/skill-frontmatter-lint.sh +13 -181
  408. package/scripts/task-sync.sh +13 -450
  409. package/scripts/terms-check.sh +13 -241
  410. package/scripts/ux-a11y-scan.sh +13 -95
  411. package/scripts/ux-ds-audit.sh +12 -144
  412. package/scripts/ux-graph-scan.sh +12 -186
  413. package/scripts/web-install.sh +16 -20
  414. package/docs/kit-annotate/01-explainer.html +0 -225
  415. package/docs/kit-annotate/02-implementation-plan.html +0 -196
  416. package/docs/media/.onboarding-capture.cast +0 -5
  417. package/docs/media/README.md +0 -43
  418. package/docs/media/build-demo.sh +0 -63
  419. package/docs/media/build-kit-init.sh +0 -51
  420. package/docs/media/build-onboarding.sh +0 -51
  421. package/docs/media/kit-dry-run.cast +0 -107
  422. package/docs/media/kit-dry-run.gif +0 -0
  423. package/docs/media/kit-init.cast +0 -56
  424. package/docs/media/kit-init.gif +0 -0
  425. package/docs/media/kit-onboarding.cast +0 -148
  426. package/docs/media/kit-onboarding.gif +0 -0
  427. package/integrations/mempalace.json +0 -28
  428. package/scripts/review-lint-baseline.txt +0 -28
  429. package/scripts/verbs.baseline +0 -5
  430. package/templates/hooks/mempal_followup.sh.tmpl +0 -97
  431. package/templates/hooks/mempal_precompact.sh.tmpl +0 -4
  432. package/templates/hooks/mempal_save.sh.tmpl +0 -4
  433. package/templates/hooks/mempal_session_start.sh.tmpl +0 -42
  434. package/templates/rules/mempalace.md +0 -111
  435. /package/{commands → kit/commands}/kit-docs.md +0 -0
  436. /package/{commands → kit/commands}/kit-export-training.md +0 -0
  437. /package/{databases → kit/databases}/supabase/guide.html +0 -0
  438. /package/{databases → kit/databases}/supabase/nextjs/lib/supabase/client.ts +0 -0
  439. /package/{databases → kit/databases}/supabase/nextjs/lib/supabase/server.ts +0 -0
  440. /package/{githooks → kit/githooks}/pre-commit +0 -0
  441. /package/{integrations → kit/integrations}/emil-design-eng.json +0 -0
  442. /package/{integrations → kit/integrations}/graft.json +0 -0
  443. /package/{integrations → kit/integrations}/impeccable.json +0 -0
  444. /package/{integrations → kit/integrations}/lavish.json +0 -0
  445. /package/{integrations → kit/integrations}/mlx-lm.json +0 -0
  446. /package/{integrations → kit/integrations}/web-design-guidelines.json +0 -0
  447. /package/{recipes → kit/recipes}/nextjs-shadcn.json +0 -0
  448. /package/{skills → kit/skills}/kit-advisor/SKILL.md +0 -0
  449. /package/{skills → kit/skills}/kit-advisor/references/close.md +0 -0
  450. /package/{skills → kit/skills}/kit-advisor/references/grill.md +0 -0
  451. /package/{skills → kit/skills}/kit-advisor/references/orchestrate.md +0 -0
  452. /package/{skills → kit/skills}/kit-advisor/references/plan.md +0 -0
  453. /package/{skills → kit/skills}/kit-advisor/references/review.md +0 -0
  454. /package/{skills → kit/skills}/kit-advisor/references/step-report.md +0 -0
  455. /package/{skills → kit/skills}/kit-docs-writer/SKILL.md +0 -0
  456. /package/{skills → kit/skills}/kit-effort-pr/SKILL.md +0 -0
  457. /package/{skills → kit/skills}/kit-next/SKILL.md +0 -0
  458. /package/{skills → kit/skills}/kit-onboard/SKILL.md +0 -0
  459. /package/{skills → kit/skills}/kit-plan-next/SKILL.md +0 -0
  460. /package/{skills → kit/skills}/kit-security-sweep/SKILL.md +0 -0
  461. /package/{skills → kit/skills}/kit-ship/SKILL.md +0 -0
  462. /package/{skills → kit/skills}/kit-task-pr-auto/SKILL.md +0 -0
  463. /package/{skills → kit/skills}/kit-ux-audit/references/a11y.md +0 -0
  464. /package/{skills → kit/skills}/kit-ux-audit/references/consistency.md +0 -0
  465. /package/{skills → kit/skills}/kit-ux-audit/references/heuristics.md +0 -0
  466. /package/{templates → kit/templates}/benchmarks/SCHEMA.md +0 -0
  467. /package/{templates → kit/templates}/benchmarks/abstain.jsonl +0 -0
  468. /package/{templates → kit/templates}/benchmarks/adversarial.jsonl +0 -0
  469. /package/{templates → kit/templates}/benchmarks/benchmark.config.json +0 -0
  470. /package/{templates → kit/templates}/benchmarks/quality.jsonl +0 -0
  471. /package/{templates → kit/templates}/benchmarks/retrieval.jsonl +0 -0
  472. /package/{templates → kit/templates}/codex/hooks.json.tmpl +0 -0
  473. /package/{templates → kit/templates}/hooks/guard-base-branch-commit.sh.tmpl +0 -0
  474. /package/{templates → kit/templates}/hooks/guard-raw-git-ops.sh.tmpl +0 -0
  475. /package/{templates → kit/templates}/hooks/kit-local-status.sh.tmpl +0 -0
  476. /package/{templates → kit/templates}/hooks/kit-mail-check.sh.tmpl +0 -0
  477. /package/{templates → kit/templates}/hooks/kit_version_check.sh.tmpl +0 -0
  478. /package/{templates → kit/templates}/hooks/prepush_gate.sh.tmpl +0 -0
  479. /package/{templates → kit/templates}/hooks/repo-hygiene.sh.tmpl +0 -0
  480. /package/{templates → kit/templates}/knowledge-INDEX.md.tmpl +0 -0
  481. /package/{templates → kit/templates}/lib/kit-sigil.sh.tmpl +0 -0
  482. /package/{templates → kit/templates}/rules/authoring.md +0 -0
  483. /package/{templates → kit/templates}/rules/code-retrieval.md +0 -0
  484. /package/{templates → kit/templates}/rules/communication-style.md +0 -0
  485. /package/{templates → kit/templates}/rules/delegation-brief.md +0 -0
  486. /package/{templates → kit/templates}/rules/design-routing.md +0 -0
  487. /package/{templates → kit/templates}/rules/effort-model.md +0 -0
  488. /package/{templates → kit/templates}/rules/gate-and-review.md +0 -0
  489. /package/{templates → kit/templates}/rules/issue-lifecycle.md +0 -0
  490. /package/{templates → kit/templates}/rules/knowledge-base.md +0 -0
  491. /package/{templates → kit/templates}/rules/naming-and-ids.md +0 -0
  492. /package/{templates → kit/templates}/rules/plain-language.md +0 -0
  493. /package/{templates → kit/templates}/rules/plan-next.md +0 -0
  494. /package/{templates → kit/templates}/rules/plan-output-format.md +0 -0
  495. /package/{templates → kit/templates}/rules/review-pages.md +0 -0
  496. /package/{templates → kit/templates}/rules/risk-tiered-review.md +0 -0
  497. /package/{templates → kit/templates}/rules/shared-checkout.md +0 -0
  498. /package/{templates → kit/templates}/rules/skill-gaps.md +0 -0
  499. /package/{templates → kit/templates}/rules/task-management.md +0 -0
  500. /package/{templates → kit/templates}/settings/settings.json.tmpl +0 -0
  501. /package/{templates → kit/templates}/settings/settings.local.json.tmpl +0 -0
  502. /package/{templates → kit/templates}/skills/NAMESPACED +0 -0
  503. /package/{templates → kit/templates}/skills/brand-voice/SKILL.md +0 -0
  504. /package/{templates → kit/templates}/skills/brand-voice/references/voice-template.md +0 -0
  505. /package/{templates → kit/templates}/skills/campaign/SKILL.md +0 -0
  506. /package/{templates → kit/templates}/skills/campaign/references/plan-template.md +0 -0
  507. /package/{templates → kit/templates}/skills/concrete/SKILL.md +0 -0
  508. /package/{templates → kit/templates}/skills/copywriting/SKILL.md +0 -0
  509. /package/{templates → kit/templates}/skills/copywriting/references/copy-frameworks.md +0 -0
  510. /package/{templates → kit/templates}/skills/copywriting/references/natural-transitions.md +0 -0
  511. /package/{templates → kit/templates}/skills/feature-build-refine/SKILL.md +0 -0
  512. /package/{templates → kit/templates}/skills/karpathy-guidelines/SKILL.md +0 -0
  513. /package/{templates → kit/templates}/skills/morning-briefing/SKILL.md +0 -0
  514. /package/{templates → kit/templates}/skills/page-design/SKILL.md +0 -0
  515. /package/{templates → kit/templates}/skills/page-design/add.json +0 -0
  516. /package/{templates → kit/templates}/skills/page-design/references/design-file-template.md +0 -0
  517. /package/{templates → kit/templates}/skills/page-design/references/generic-page-patterns.md +0 -0
  518. /package/{templates → kit/templates}/skills/page-design/references/minimum-rules.md +0 -0
  519. /package/{templates → kit/templates}/skills/speckit/SKILL.md +0 -0
  520. /package/{templates → kit/templates}/skills/supabase-patterns/SKILL.md +0 -0
  521. /package/{scripts/lib → lib/core}/adapter-select.sh +0 -0
  522. /package/{scripts/lib → lib/core}/agent-launch.sh +0 -0
  523. /package/{scripts/lib → lib/core}/agent-profile.sh +0 -0
  524. /package/{scripts/lib → lib/core}/cckit-output.sh +0 -0
  525. /package/{scripts/lib → lib/core}/codex-hooks.sh +0 -0
  526. /package/{scripts → lib/core}/force-push-fence.baseline +0 -0
  527. /package/{scripts → lib/core}/forge-fence.baseline +0 -0
  528. /package/{scripts/lib → lib/core}/git-remote.sh +0 -0
  529. /package/{scripts/lib → lib/core}/hook-refresh.sh +0 -0
  530. /package/{scripts → lib/core}/instruction-budget-lint-test.sh +0 -0
  531. /package/{scripts/lib → lib/core}/kit-state.sh +0 -0
  532. /package/{scripts/lib → lib/core}/orchestration-runtime.sh +0 -0
  533. /package/{scripts/lib → lib/core}/project-scan.sh +0 -0
  534. /package/{scripts/lib → lib/core}/render.sh +0 -0
  535. /package/{scripts → lib/core}/review-lint-test.sh +0 -0
  536. /package/{scripts/lib → lib/core}/review-stage.sh +0 -0
  537. /package/{scripts → lib/core}/skill-frontmatter-lint-test.sh +0 -0
  538. /package/{scripts/lib → lib/core}/task-source-file.sh +0 -0
  539. /package/{scripts/lib → lib/core}/task-source.sh +0 -0
  540. /package/{scripts/lib → lib/core}/toon.sh +0 -0
  541. /package/{scripts/lib → lib/core}/ui.sh +0 -0
  542. /package/{scripts/lib → lib/core}/worker-brief.sh +0 -0
  543. /package/{scripts/lib → lib/forge}/forge-github.sh +0 -0
  544. /package/{scripts/lib → lib/forge}/forge-none.sh +0 -0
  545. /package/{scripts/lib → lib/forge}/test-forge-shim.sh +0 -0
  546. /package/{scripts → lib/verbs}/debug.sh +0 -0
  547. /package/{scripts → lib/verbs}/night-run.test.mjs +0 -0
  548. /package/{scripts/lib → lib/verbs}/upgrade-report.sh +0 -0
@@ -1,790 +1,14 @@
1
1
  #!/usr/bin/env bash
2
- # worktree-start.sh — the canonical "start a worktree for an issue" git-mechanic.
3
- #
4
- # Family 1 of kit-engine-boundary.md (rule #1/#2): one bash home for the op, consumed by the
5
- # kit-task-start skill, scripts/orchestrate.sh, and `kit task start`. No second implementation.
6
- #
7
- # wt_start [--force] <issue-number|E<n>|E<n>.<step>> [slug-override]
8
- # A token resolves first: E<n> is issue n, E<n>.<step> the effort's sub at that step.
9
- # Refuses (rc 1, before any fetch / branch / worktree) when another LIVE session already holds
10
- # the issue's claim in <git-common-dir>/kit-sessions (session-registry.sh). `--force` or
11
- # KIT_FORCE=1 starts anyway and takes the claim over.
12
- # stdout: "<worktree-path>|<branch>|<issue-number>" (one line, machine-readable)
13
- # stderr: human progress
14
- # returns: 0 on success (created or reused), 1 on failure
15
- #
16
- # Requires: gh, jq, git, scripts/lib/gh-project.sh (board update). bash 3.2 compatible.
17
- # errors: strict — rc 1 on failure; a half-made worktree is never reported as ready
18
-
19
- # The GitHub transport switch (#396): rest mode routes the gh calls below through gh-rest.sh.
20
- # The forge port (E537): every GitHub call goes through forge_* / gh_rest_* (scripts/lib/gh-rest.sh).
21
- if ! command -v gh_rest_issue_json >/dev/null 2>&1; then
22
- # shellcheck source=/dev/null
23
- . "$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" && pwd)/gh-rest.sh"
24
- fi
25
-
26
- if ! command -v cckit_gh_rest >/dev/null 2>&1; then
27
- _ghr_lib="$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" 2>/dev/null && pwd)/gh-rest.sh"
28
- # shellcheck source=/dev/null
29
- [ -f "$_ghr_lib" ] && . "$_ghr_lib"
30
- unset _ghr_lib
31
- fi
32
- command -v cckit_gh_rest >/dev/null 2>&1 || cckit_gh_rest() { return 1; }
33
-
34
- # The claims registry (#384). Guarded: a project scaffolded before session-registry.sh shipped has
35
- # worktree-start.sh without it, and there wt_start runs with no claim check rather than failing.
36
- if ! command -v sreg_claim >/dev/null 2>&1; then
37
- _sr_lib="$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" 2>/dev/null && pwd)/session-registry.sh"
38
- # shellcheck source=/dev/null
39
- [ -f "$_sr_lib" ] && . "$_sr_lib"
40
- unset _sr_lib
41
- fi
42
-
43
- # The closed kind: vocabulary (kinds.sh). The issue's `kind:` label becomes the branch prefix, so it
44
- # is mapped through the set: a label outside it (kind:bug, kind:docs, a typo) would otherwise produce
45
- # a branch the hygiene hook rejects as non-conventional.
46
- if ! command -v kit_kind_branch >/dev/null 2>&1; then
47
- _wtk_lib="$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" 2>/dev/null && pwd)/kinds.sh"
48
- # shellcheck source=/dev/null
49
- [ -f "$_wtk_lib" ] && . "$_wtk_lib"
50
- unset _wtk_lib
51
- fi
52
- # _wt_kind_prefix <kind> — the branch prefix for a kind label value. With kinds.sh loaded: the value
53
- # itself when it is in the closed set, else `task` plus a warning on stderr. Without kinds.sh (a
54
- # project scaffolded before it shipped) the value passes through unchanged, as it always did.
55
- _wt_kind_prefix() {
56
- if command -v kit_kind_branch >/dev/null 2>&1; then kit_kind_branch "${1:-}"; else printf '%s\n' "${1:-task}"; fi
57
- }
58
-
59
- WT_START_REPO="${WT_START_REPO:-${KIT_REPO:-}}"
60
-
61
- # The token parser (naming.sh, E546.1): `start E545` / `start E545.1` name an effort or a sub.
62
- if ! command -v naming_token_parse >/dev/null 2>&1; then
63
- _wt_naming="$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" 2>/dev/null && pwd)/naming.sh"
64
- # shellcheck source=/dev/null
65
- [ -f "$_wt_naming" ] && . "$_wt_naming"
66
- unset _wt_naming
67
- fi
68
-
69
- # _wt_resolve_token <token> — the issue number a token names (rules/naming-and-ids.md). E<n> is
70
- # issue n. E<n>.<step> reads effort n's native sub-issues and takes the one titled [E<n>.<step>]
71
- # (or the legacy [Effort <n>] <step> · ), else the sub at position <step>. rc 1, with the reason on
72
- # stderr, when no sub matches or the sub-issues cannot be read.
73
- _wt_resolve_token() {
74
- local tok="$1" parsed n s subs hit
75
- parsed="$(naming_token_parse "$tok")" || { echo "wt_start: '$tok' is not an E<n> or E<n>.<step> token" >&2; return 1; }
76
- n="${parsed%% *}"; s=""
77
- case "$parsed" in *" "*) s="${parsed#* }" ;; esac
78
- if [ -z "$s" ]; then printf '%s' "$n"; return 0; fi
79
- if ! forge_available; then
80
- echo "wt_start: $tok is step $s of effort $n; resolving it reads the effort's sub-issues and no forge is configured — pass the sub's issue number" >&2
81
- return 1
82
- fi
83
- subs="$(forge_rest "repos/$WT_START_REPO/issues/$n/sub_issues" -X GET -f per_page=100 \
84
- --jq '.[] | "\(.number)\t\(.title // "")"' 2>/dev/null)" \
85
- || { echo "wt_start: could not read the sub-issues of effort $n" >&2; return 1; }
86
- hit="$(printf '%s\n' "$subs" | awk -F'\t' -v t="[E$n.$s] " -v l="[Effort $n] $s " \
87
- 'index($2, t) == 1 || index($2, l) == 1 { print $1; exit }')"
88
- [ -n "$hit" ] || hit="$(printf '%s\n' "$subs" | awk -F'\t' -v s="$s" 'NF && ++i == s { print $1; exit }')"
89
- if [ -z "$hit" ]; then
90
- echo "wt_start: $tok not found — effort $n has no sub titled [E$n.$s] and fewer than $s sub-issues" >&2
91
- return 1
92
- fi
93
- echo "[$tok] → #$hit" >&2
94
- printf '%s' "$hit"
95
- }
96
-
97
- # _wt_set_port <app-env-file> <port> <issue-num> — append a per-worktree dev PORT to an app's
98
- # .env.local, but only where one exists (i.e. the app is locally runnable). Idempotent: an existing
99
- # PORT= line wins.
100
- #
101
- # BEST-EFFORT, NOT A GUARANTEE. This write only takes effect for an app that actually reads the
102
- # file. A script like `next dev -p ${PORT:-3003}` is expanded by the npm-script shell, which never
103
- # reads .env.local, so the value is INERT for it and every worktree falls back to the same default.
104
- # cckit therefore does not RELY on it: everything cckit launches itself passes the port explicitly
105
- # (scripts/lib/qa-lane.sh exports each port env var the project declared in `qa.ports`, set to that
106
- # lane's port, into the command it launches). Treat the .env.local write as
107
- # a convenience for apps that do read it — and if you start a dev server by hand in a worktree,
108
- # check which port you actually got.
109
- _wt_set_port() {
110
- local file="$1" port="$2" num="$3"
111
- [[ -f "$file" ]] || return 0
112
- grep -q '^PORT=' "$file" 2>/dev/null && return 0
113
- printf '\n# kit worktree #%s — per-worktree dev port (#773)\nPORT=%s\n' "$num" "$port" >> "$file"
114
- echo "[#$num] PORT=$port -> $file" >&2
115
- }
116
-
117
- # wt_assign_ports <worktree> <issue-num> <root> — assign a per-worktree dev PORT to each app whose
118
- # env file is listed in `.worktree.devPorts` of <root>/.claude/kit.config.json. Each entry is
119
- # {path, base}; the port = base + (issue % 40) * <stride> so lanes stay disjoint within and across
120
- # worktrees (stride = `worktree.devPortStride`, default 10 — never the service count, see below). Config-driven (no hardcoded app paths) so the kit stays portable: a project with no
121
- # `.worktree.devPorts` (or no kit.config.json) is a silent no-op. bash 3.2.
122
- # ── port SLOTS: an allocation, not a hash (the QA lane depends on lanes never colliding) ──────
123
- # `issue % 40` is a hash: two issues 40 apart get byte-identical ports, and a repo whose numbers are
124
- # in the thousands hits that constantly (#1700 and #1740 in the same wave is unremarkable). A slot is
125
- # RECORDED instead, so uniqueness is by construction rather than by hoping about issue numbers.
126
- #
127
- # State lives beside the event log under the git-common-dir, so it is worktree-durable and shared by
128
- # every checkout. Each line: <issue>\t<slot>\t<worktree-path>. A slot whose worktree is gone is
129
- # reclaimed on the next call, which is what keeps the 40 slots from leaking away over a long project.
130
- # _wt_num_hash <key> — <key> itself when it is a number, else a number derived from it. The slot
131
- # ledger is keyed by issue number; a light task (#450) is keyed by its id (`t3f9a`), and the hashed
132
- # fallbacks below do arithmetic on the key.
133
- _wt_num_hash() {
134
- case "$1" in
135
- ''|*[!0-9]*) printf '%s' "$1" | cksum | cut -d' ' -f1 ;;
136
- *) printf '%s' "$1" ;;
137
- esac
138
- }
139
-
140
- _wt_slots_file() {
141
- local gcd
142
- gcd="$(git -C "${1:-.}" rev-parse --git-common-dir 2>/dev/null)" || return 1
143
- case "$gcd" in /*) : ;; *) gcd="$(cd "${1:-.}" && cd "$gcd" 2>/dev/null && pwd)" || return 1 ;; esac
144
- printf '%s/kit-portslots.tsv' "$gcd"
145
- }
146
-
147
- # ── the ledger LOCK: allocation is a read-modify-write, so it has to be serialized ────────────
148
- # Two `cckit start` processes racing through _wt_slot_alloc both read the same `held` set, both
149
- # pick the same lowest free slot, and both append it — two worktrees, one port block, which is the
150
- # very defect the slot ledger exists to remove. The reclaim rewrite races worse than the append:
151
- # it `mv`s a snapshot over the ledger, silently dropping any row another process added in between.
152
- #
153
- # The lock primitive is the shell's own noclobber redirection: `set -C; : > file` opens with
154
- # O_CREAT|O_EXCL, which the kernel makes exclusive, and no external tool is involved. A stock macOS
155
- # has no flock(1) and this file targets bash 3.2.
156
- #
157
- # It was `mkdir` until #449. `mkdir` is exclusive only when the binary makes ONE mkdir(2) call and
158
- # reports its EEXIST. uutils coreutils 0.10.0 (the `mkdir` of Ubuntu 26.04, and of GitHub's
159
- # `ubuntu-latest` runner) calls statx first and exits 0 for the loser of a race: 8 processes running
160
- # `mkdir <same path>` at once all "succeeded" in 183 of 200 rounds. Two `cckit start` runs then held
161
- # this lock together and were given the same slot.
162
- _WT_LOCK_WAIT="${_WT_LOCK_WAIT:-10}" # seconds to wait for a held lock before giving up
163
-
164
- # _wt_lock_try <lockfile> — ONE attempt: 0 when this call created the lock, 1 when it exists. The
165
- # subshell keeps noclobber out of the caller's shell. Never replace this with an external command
166
- # without racing it first (scripts/lib/worktree-ports-test.sh section 7 does).
167
- _wt_lock_try() { ( set -C; : > "$1" ) 2>/dev/null; }
168
-
169
- # _wt_lock <lockfile> — 0 when the lock is held, 1 when it is not. A caller that fails to lock
170
- # proceeds ANYWAY: an unserialized allocation can collide, but a `cckit start` that refuses to run
171
- # cannot be worked around. Degrade, don't block.
172
- #
173
- # A lock older than a minute is treated as abandoned and broken, so a process killed
174
- # mid-allocation cannot wedge every future start. The age floor is well above _WT_LOCK_WAIT, so a
175
- # slow-but-live holder is never stolen from. `rm -rf` because a cckit from before #449 leaves a
176
- # lock DIRECTORY at the same path; either kind blocks the other, so mixed versions still exclude.
177
- _wt_lock() {
178
- local d="$1" tries=0 max
179
- max=$(( _WT_LOCK_WAIT * 10 ))
180
- while [[ "$tries" -lt "$max" ]]; do
181
- _wt_lock_try "$d" && return 0
182
- sleep 0.1 2>/dev/null || sleep 1
183
- tries=$(( tries + 1 ))
184
- done
185
- if [[ -n "$(find "$d" -maxdepth 0 -mmin +1 2>/dev/null)" ]]; then
186
- rm -rf "$d" 2>/dev/null
187
- _wt_lock_try "$d" && { echo "warn: broke an abandoned port-slot lock ($d)" >&2; return 0; }
188
- fi
189
- return 1
190
- }
191
-
192
- _wt_unlock() { rm -rf "$1" 2>/dev/null; }
193
-
194
- # _wt_slot_alloc <ledger> <issue-num> <worktree> — the ledger transaction: reclaim dead rows,
195
- # return the issue's existing allocation if it has one, else take the lowest free slot and append
196
- # it. Every step reads and writes <ledger>, so the CALLER must hold the lock around the whole
197
- # function — splitting any step out of it reopens the race.
198
- _wt_slot_alloc() {
199
- local f="$1" num="$2" wt="$3" i held mine tmp i_num i_slot i_path
200
-
201
- # Reclaim: keep only rows whose worktree still exists (or that have no path recorded).
202
- tmp="$(mktemp 2>/dev/null)" || tmp=""
203
- if [[ -n "$tmp" ]]; then
204
- while IFS="$(printf '\t')" read -r i_num i_slot i_path; do
205
- [[ -n "$i_num" ]] || continue
206
- if [[ -z "$i_path" || -d "$i_path" ]]; then printf '%s\t%s\t%s\n' "$i_num" "$i_slot" "$i_path" >> "$tmp"; fi
207
- done < "$f"
208
- mv "$tmp" "$f" 2>/dev/null || rm -f "$tmp"
209
- fi
210
-
211
- # Already allocated? Keep it.
212
- mine="$(awk -F"\t" -v n="$num" '$1==n {print $2; exit}' "$f" 2>/dev/null)"
213
- if [[ "$mine" =~ ^[0-9]+$ ]]; then printf '%s' "$mine"; return 0; fi
214
-
215
- held="$(cut -f2 "$f" 2>/dev/null | tr '\n' ' ')"
216
- i=0
217
- while [[ "$i" -lt 40 ]]; do
218
- case " $held " in *" $i "*) : ;; *) printf '%s\t%s\t%s\n' "$num" "$i" "$wt" >> "$f" 2>/dev/null; printf '%s' "$i"; return 0 ;; esac
219
- i=$(( i + 1 ))
220
- done
221
- echo "[#$num] warn: all 40 dev-port slots are held — falling back to a hashed port (collisions possible); run cckit gc" >&2
222
- printf '%s' $(( $(_wt_num_hash "$num") % 40 ))
223
- }
224
-
225
- # _wt_slot_for <root> <issue-num> <worktree> — echo this issue's slot (0-39), allocating on first
226
- # call under the ledger lock. IDEMPOTENT: an issue keeps its slot for as long as its worktree
227
- # exists, so re-running `cckit start` never renumbers a live lane. Falls back to the old hash (with
228
- # a warning) only when every slot is genuinely held.
229
- _wt_slot_for() {
230
- local root="$1" num="$2" wt="$3" f lock out locked=0
231
- f="$(_wt_slots_file "$root")" || { printf '%s' $(( $(_wt_num_hash "$num") % 40 )); return 0; }
232
- # `>>`, not `>`: this line runs BEFORE the lock, so a truncating create could empty a ledger that
233
- # another process created and wrote to between the test and the redirection.
234
- [[ -f "$f" ]] || : >> "$f" 2>/dev/null || { printf '%s' $(( $(_wt_num_hash "$num") % 40 )); return 0; }
235
-
236
- lock="$f.lock"
237
- if _wt_lock "$lock"; then locked=1; else
238
- echo "[#$num] warn: the port-slot ledger stayed locked — allocating unserialized, so two lanes can land on one slot" >&2
239
- fi
240
- out="$(_wt_slot_alloc "$f" "$num" "$wt")"
241
- [[ "$locked" = 1 ]] && _wt_unlock "$lock"
242
- printf '%s' "$out"
243
- }
244
-
245
- # wt_port_slot <root> <issue-num> <worktree> — the PUBLIC reader of the slot ledger: echo the slot
246
- # (0-39) this issue holds, allocating one on first call. Same row `cckit start` uses, so a caller
247
- # that launches something for an issue's worktree (the QA lane, qa-lane.sh) lands on the port block
248
- # that worktree already owns instead of deriving a second one.
249
- wt_port_slot() { _wt_slot_for "$1" "$2" "$3"; }
250
-
251
- # wt_port_stride <config-file> — the distance between one slot's port block and the next:
252
- # `worktree.devPortStride`, default 10. One reader, so wt_assign_ports and the QA lane cannot
253
- # disagree about where the next block starts.
254
- wt_port_stride() {
255
- local stride=""
256
- stride="$(jq -r '.worktree.devPortStride // empty' "${1:-}" 2>/dev/null)"
257
- [[ "$stride" =~ ^[0-9]+$ && "$stride" -gt 0 ]] || stride=10
258
- printf '%s' "$stride"
259
- }
260
-
261
- wt_assign_ports() {
262
- # `apppath`, not `path`: under zsh `path` is tied to PATH (special array); a bare `path` local
263
- # would clobber the command search path on assignment. A namespaced name is inert.
264
- local wt="$1" num="$2" root="$3" cfg ports n offset i apppath base stride spread
265
- # Both supported layouts (self-host root cckit.config.json · scaffolded
266
- # .claude/kit.config.json) via the same resolver used below. Hardcoding the scaffolded
267
- # path made this a silent no-op in every self-hosting repo: ports read as "assigned"
268
- # and nothing was ever written.
269
- cfg="$(_wt_cfg "$root")" || return 0
270
- # jq is a stated requirement of this file (see header) — don't pre-check `command -v jq` here: the
271
- # `command -v … || return` idiom mis-fires under zsh, and the jq read below already no-ops on a
272
- # missing config / missing jq. Guard only on the config file existing.
273
- [[ -f "$cfg" ]] || return 0
274
- ports="$(jq -c '.worktree.devPorts // []' "$cfg" 2>/dev/null)" || return 0
275
- [[ -n "$ports" && "$ports" != "[]" ]] || return 0
276
- n="$(jq 'length' <<<"$ports" 2>/dev/null)"; [[ "$n" =~ ^[0-9]+$ && "$n" -gt 0 ]] || return 0
277
-
278
- # STRIDE — the distance between one worktree's port block and the next. It must NOT be the
279
- # service count: with stride == n, two bases that are congruent mod n hand the same port to two
280
- # different worktrees. Real example (bases 3001/3003/3004, n=3): worktree offset k+1's admin port
281
- # (3004+3k) IS worktree offset k's api port. Configurable as `worktree.devPortStride`; the default
282
- # leaves room for up to 10 services per project.
283
- stride="$(wt_port_stride "$cfg")"
284
-
285
- # The invariant that keeps blocks disjoint: every base must sit inside ONE stride-wide window.
286
- # Warn rather than fail — the ports still work, they just stop being collision-proof, and a
287
- # config the owner can fix should not break `cckit start`.
288
- spread="$(jq -r '[.[].base] | (max - min)' <<<"$ports" 2>/dev/null)"
289
- if [[ "$spread" =~ ^[0-9]+$ && "$spread" -ge "$stride" ]]; then
290
- echo "[#$num] warn: worktree.devPorts bases span $spread >= stride $stride — port blocks can overlap across worktrees; widen worktree.devPortStride" >&2
291
- fi
292
-
293
- offset="$(_wt_slot_for "$root" "$num" "$wt")"
294
- [[ "$offset" =~ ^[0-9]+$ ]] || offset=$(( $(_wt_num_hash "$num") % 40 ))
295
- i=0
296
- while [[ "$i" -lt "$n" ]]; do
297
- apppath="$(jq -r ".[$i].path // empty" <<<"$ports")"
298
- base="$(jq -r ".[$i].base // empty" <<<"$ports")"
299
- [[ -n "$apppath" && "$base" =~ ^[0-9]+$ ]] && _wt_set_port "$wt/$apppath" $(( base + offset * stride )) "$num"
300
- i=$(( i + 1 ))
301
- done
302
- }
303
-
304
- # ── Where does `pnpm install` actually have work to do? (#255) ────────────────────────────────
305
- # The bootstrap install used to run unconditionally at the worktree ROOT. In a repo whose root
306
- # manifest declares no dependencies (a published CLI, a docs-only repo, a shell toolkit), pnpm has
307
- # nothing to resolve — but it still WRITES a 9-line `pnpm-lock.yaml` with an empty `.: {}` importer.
308
- # That stray lockfile then trips the captain's own policy floor (captain.sh, lockfile/dependency-
309
- # graph paths) and HOLDS the PR for human review. The helpers below answer "is there anything to
310
- # install, and where?" from the project's ACTUAL manifest — never from a hardcoded layout.
311
-
312
- # _wt_cfg <dir> — path to <dir>'s project config, or nothing. Mirrors config-path.sh's two supported
313
- # layouts (self-host root `cckit.config.json`, scaffolded `.claude/kit.config.json`) without taking
314
- # a source-time dependency on it — worktree-start.sh is sourced standalone by effort-ops.sh.
315
- _wt_cfg() {
316
- [[ -f "$1/cckit.config.json" ]] && { printf '%s\n' "$1/cckit.config.json"; return 0; }
317
- [[ -f "$1/.claude/kit.config.json" ]] && { printf '%s\n' "$1/.claude/kit.config.json"; return 0; }
318
- return 1
319
- }
320
-
321
- # _wt_json_has <file> <jq-filter> <fallback-regex> — true when <file> satisfies <jq-filter>. jq is
322
- # the stated dependency of this lib, but the install decision must stay correct without it, so a
323
- # whitespace-stripped regex over the raw JSON is the fallback. Never fails the caller.
324
- _wt_json_has() {
325
- local file="$1" filter="$2" re="$3"
326
- [[ -f "$file" ]] || return 1
327
- if command -v jq >/dev/null 2>&1; then
328
- jq -e "$filter" "$file" >/dev/null 2>&1
329
- else
330
- grep -qE "$re" <<<"$(tr -d ' \n\t' < "$file" 2>/dev/null)"
331
- fi
332
- }
333
-
334
- # _wt_manifest_has_deps <dir> — true when <dir>/package.json declares at least ONE dependency in any
335
- # of the four dependency blocks. An empty block (`"dependencies": {}`) counts as none: pnpm would
336
- # resolve nothing and write only the empty-importer lockfile.
337
- _wt_manifest_has_deps() {
338
- _wt_json_has "$1/package.json" \
339
- '[(.dependencies,.devDependencies,.optionalDependencies,.peerDependencies)
340
- | select(type=="object") | length] | add // 0 | . > 0' \
341
- '"(dependencies|devDependencies|optionalDependencies|peerDependencies)":\{"'
342
- }
343
-
344
- # _wt_yaml_has_members <file> — true when a pnpm-workspace.yaml declares at least one ACTUAL member
345
- # pattern under `packages:`. The KEY alone is not enough: `packages: []` and a `packages:` with an
346
- # empty block below it declare no members, so pnpm resolves nothing and writes only the empty-
347
- # importer lockfile — the exact #255 symptom. Handles both YAML sequence forms:
348
- # packages: ["apps/*"] (inline flow) packages: (block)
349
- # - "apps/*"
350
- # Comments are stripped first so `packages: [] # later` and `- # nothing` can't fake a member.
351
- _wt_yaml_has_members() {
352
- [[ -f "$1" ]] || return 1
353
- awk '
354
- { line = $0; sub(/^[[:space:]]*#.*$/, "", line); sub(/[[:space:]]+#.*$/, "", line) }
355
- inblock {
356
- if (line ~ /^[[:space:]]*$/) next
357
- # a member entry: "- " followed by something real
358
- if (line ~ /^[[:space:]]*-[[:space:]]*[^[:space:]]/) { found = 1; exit }
359
- inblock = 0 # any other content ends the block without a member
360
- }
361
- !inblock {
362
- if (line ~ /^[[:space:]]*packages:[[:space:]]*\[/) {
363
- rest = line; sub(/^[^[]*\[/, "", rest); gsub(/[[:space:]]/, "", rest)
364
- if (rest !~ /^\]/) { found = 1; exit } # non-empty inline flow sequence
365
- } else if (line ~ /^[[:space:]]*packages:[[:space:]]*$/) {
366
- inblock = 1
367
- }
368
- }
369
- END { exit(found ? 0 : 1) }
370
- ' "$1" 2>/dev/null
371
- }
372
-
373
- # _wt_is_workspace_root <dir> — true when <dir> is the root of a package-manager workspace WITH AT
374
- # LEAST ONE MEMBER. Such a root legitimately declares no dependencies of its own (the members hold
375
- # them) and its root lockfile is the real one, so `pnpm install` there IS genuine work.
376
- #
377
- # A declaration with no members is NOT a workspace root, and this distinction is the whole point:
378
- # `packages: []`, `"workspaces": []`, `"workspaces": {}` and `"workspaces": {"packages": []}` all
379
- # leave pnpm with nothing to resolve, so treating them as workspace roots would re-create #255.
380
- # Likewise a `pnpm-workspace.yaml` carrying only settings (pnpm 10 `overrides:` /
381
- # `onlyBuiltDependencies:`) with no `packages:` key at all.
382
- _wt_is_workspace_root() {
383
- local d="$1" f
384
- for f in "$d/pnpm-workspace.yaml" "$d/pnpm-workspace.yml"; do
385
- _wt_yaml_has_members "$f" && return 0
386
- done
387
- # package.json `workspaces`: the array form IS the member list; the object form (npm/yarn) keeps
388
- # it under `.packages` alongside `nohoist`. Either way, count real non-empty patterns.
389
- _wt_json_has "$d/package.json" \
390
- 'def members: if type=="array" then . elif type=="object" then (.packages // []) else [] end;
391
- ((.workspaces // null) | members | map(select(type=="string" and length > 0)) | length) > 0' \
392
- '"workspaces":(\["|\{[^}]*"packages":\[")'
393
- }
394
-
395
- # _wt_safe_target <worktree> <target> — echo the normalized, worktree-relative form of <target> when
396
- # it is SAFE to install in; nothing + rc 1 otherwise. A target MUST stay inside the worktree.
397
- #
398
- # This is not hypothetical: a worktree lives at `<root>/.claude/worktrees/<kind>+<N>-<slug>`, three
399
- # levels under the primary checkout, so an installPaths entry of `../../..` would run `pnpm install`
400
- # in the SHARED main checkout — writing node_modules and a pnpm-lock.yaml into whatever another
401
- # session has parked there. Config is project-controlled input, so it gets validated like input.
402
- #
403
- # Two gates, because they catch different escapes:
404
- # • lexical — reject an absolute path, and resolve `.`/`..` segments, failing if they climb above
405
- # the worktree. Pure parameter expansion (no `set --`, which zsh does not word-split), so it
406
- # works on a path that does not exist yet and behaves identically in bash and zsh.
407
- # • physical — when the directory does exist, compare `pwd -P` against the worktree's, which is
408
- # the only thing that catches a symlink pointing out of the tree.
409
- _wt_safe_target() {
410
- local wt="$1" t="$2" rest seg out="" base abs
411
- [[ -n "$t" ]] || return 1
412
- case "$t" in /*) return 1 ;; esac # absolute — never a worktree-relative target
413
- rest="$t"
414
- while [[ -n "$rest" ]]; do
415
- seg="${rest%%/*}"
416
- if [[ "$seg" == "$rest" ]]; then rest=""; else rest="${rest#*/}"; fi
417
- case "$seg" in
418
- ''|'.') continue ;;
419
- '..')
420
- [[ -n "$out" ]] || return 1 # climbing above the worktree root
421
- case "$out" in */*) out="${out%/*}" ;; *) out="" ;; esac ;;
422
- *) out="${out:+$out/}$seg" ;;
423
- esac
424
- done
425
- out="${out:-.}"
426
- base="$(cd -P "$wt" 2>/dev/null && pwd -P)" || return 1
427
- if [[ -d "$wt/$out" ]]; then
428
- abs="$(cd -P "$wt/$out" 2>/dev/null && pwd -P)" || return 1
429
- case "$abs" in "$base"|"$base"/*) : ;; *) return 1 ;; esac
430
- fi
431
- printf '%s\n' "$out"
432
- }
433
-
434
- # wt_install_targets <worktree> — emit one worktree-relative directory per line that the bootstrap
435
- # should run `pnpm install` in. Every emitted target is validated to live INSIDE the worktree
436
- # (_wt_safe_target). Empty output means "nothing to install" — the correct answer for a
437
- # dependency-free root. Decision order:
438
- # 1. `.worktree.installPaths` in the project config wins outright — explicit project intent for
439
- # repos whose Node projects live in subdirectories (e.g. ["docs-site"]). `[]` means install
440
- # nothing. This is the generic escape hatch; the kit hardcodes no project's layout.
441
- # 2. Otherwise the worktree root ".", but ONLY when its manifest declares dependencies or it is a
442
- # workspace root.
443
- # 3. Otherwise nothing.
444
- wt_install_targets() {
445
- local wt="$1" cfg paths n i p safe
446
- if cfg="$(_wt_cfg "$wt")" && command -v jq >/dev/null 2>&1; then
447
- paths="$(jq -c '.worktree.installPaths // empty' "$cfg" 2>/dev/null)"
448
- if [[ -n "$paths" && "$paths" != "null" ]]; then
449
- n="$(jq 'length' <<<"$paths" 2>/dev/null)"; [[ "$n" =~ ^[0-9]+$ ]] || return 0
450
- i=0
451
- while [[ "$i" -lt "$n" ]]; do
452
- p="$(jq -r ".[$i] // empty" <<<"$paths")"
453
- if [[ -n "$p" ]]; then
454
- if safe="$(_wt_safe_target "$wt" "$p")"; then
455
- printf '%s\n' "$safe"
456
- else
457
- echo "wt_install_targets: refusing installPaths entry '$p' — outside the worktree" >&2
458
- fi
459
- fi
460
- i=$(( i + 1 ))
461
- done
462
- return 0
463
- fi
464
- fi
465
- _wt_manifest_has_deps "$wt" || _wt_is_workspace_root "$wt" || return 0
466
- printf '.\n'
467
- }
468
-
469
- # wt_bootstrap <root> <worktree> <issue-num> — make a fresh worktree runnable for local dev.
470
- # A new worktree inherits no .gitignored local config and no node_modules, and parallel worktrees
471
- # collide on the hardcoded dev port. This copies the local env, assigns a per-worktree dev port, and
472
- # installs deps WHERE THERE ARE ANY (wt_install_targets — #255). Every step is best-effort +
473
- # idempotent — never fail the start (#773).
474
- wt_bootstrap() {
475
- local root="$1" wt="$2" num="$3" rel src dst offset target where ran
476
- [[ -d "$wt" ]] || return 0
477
-
478
- # 1. Copy gitignored local config the worktree can't inherit: every .env.local* + project ids.
479
- while IFS= read -r rel; do
480
- [[ -n "$rel" ]] || continue
481
- src="$root/$rel"; dst="$wt/$rel"
482
- [[ -f "$src" ]] || continue
483
- [[ -f "$dst" ]] && continue # idempotent: never clobber edits already made in the worktree
484
- mkdir -p "$(dirname "$dst")"
485
- cp "$src" "$dst" && echo "[#$num] copied $rel" >&2
486
- done < <(cd "$root" && {
487
- find . -name '.env.local*' \
488
- -not -path './node_modules/*' -not -path './.git/*' -not -path './.claude/worktrees/*' 2>/dev/null
489
- [[ -f scripts/.project-ids.env ]] && echo './scripts/.project-ids.env'
490
- } | sed 's|^\./||' | sort -u)
491
-
492
- # 2. Assign a per-worktree dev PORT per app (base + offset*lanes from the issue number) so two
493
- # worktrees never fight for the same port. The app→base map is config-driven
494
- # (`.worktree.devPorts` in kit.config.json) so the kit carries no hardcoded app paths.
495
- wt_assign_ports "$wt" "$num" "$root"
496
-
497
- # 3. Install deps — node_modules is per-worktree, not shared. Opt out with KIT_WT_INSTALL=0.
498
- # Runs ONLY where wt_install_targets says there is genuinely something to install. A root
499
- # manifest with no dependencies is skipped: pnpm would resolve nothing and leave behind an
500
- # empty `pnpm-lock.yaml` that the captain's lockfile policy floor then holds the PR on (#255).
501
- if [[ "${KIT_WT_INSTALL:-1}" != "0" ]] && command -v pnpm >/dev/null 2>&1; then
502
- ran=0
503
- while IFS= read -r target; do
504
- [[ -n "$target" ]] || continue
505
- # Re-validate containment at the point of USE, not just where the target was produced: this
506
- # is the line that actually `cd`s and runs pnpm, so it is the one that must never be talked
507
- # into stepping outside the worktree (a `../../..` would land in the shared main checkout).
508
- target="$(_wt_safe_target "$wt" "$target")" || continue
509
- [[ -d "$wt/$target" && -f "$wt/$target/package.json" ]] || continue
510
- ran=1
511
- [[ "$target" == "." ]] && where="" || where=" in $target"
512
- echo "[#$num] pnpm install$where (set KIT_WT_INSTALL=0 to skip)..." >&2
513
- ( cd "$wt/$target" && pnpm install --prefer-offline >/dev/null 2>&1 ) \
514
- && echo "[#$num] deps installed$where" >&2 \
515
- || echo "[#$num] pnpm install$where failed — run 'pnpm install' there manually" >&2
516
- done < <(wt_install_targets "$wt")
517
- [[ "$ran" == "0" ]] \
518
- && echo "[#$num] no dependencies declared — skipping pnpm install" >&2
519
- fi
520
- return 0
521
- }
522
-
523
- # ── Idle-worktree pool (OPT-IN, KIT_WT_POOL=1) ──────────────────────────────────────────────
524
- # Treehouse-style reuse: instead of always creating a fresh worktree, recycle an IDLE one whose
525
- # work already landed — saving the `git worktree add` + env copy + dependency install. OFF by
526
- # default: with KIT_WT_POOL unset/0, wt_start takes the exact same create path as before and none
527
- # of these helpers run. A worktree is REUSABLE only when ALL of these hold (conservative — if
528
- # unsure, don't reuse; fall through to create):
529
- # • it lives under .claude/worktrees/ (a pooled tree — never the main checkout or the target)
530
- # • it is not locked
531
- # • its branch is already merged into origin/${KIT_BASE_BRANCH:-main} (the committed work landed — recycling it
532
- # destroys nothing; the old branch ref survives in the object store regardless)
533
- # • its working tree is clean (no staged/unstaged/untracked changes — recover-before-prune)
534
- # • no LIVE session owns it (kit-sessions registry: no live pid sitting in that dir)
535
-
536
- # _wt_mtime <path> — file mtime as epoch seconds (BSD stat, then GNU stat). Picks the oldest tree.
537
- _wt_mtime() { stat -c %Y "$1" 2>/dev/null || stat -f %m "$1" 2>/dev/null; }
538
-
539
- # _wt_list <root> — emit one "<path>\t<branch-or-->\t<locked:0|1>" line per worktree (porcelain).
540
- _wt_list() {
541
- local root="$1" line wt_path="" branch="" locked="0"
542
- while IFS= read -r line; do
543
- case "$line" in
544
- "worktree "*) wt_path="${line#worktree }" ;;
545
- "branch refs/heads/"*) branch="${line#branch refs/heads/}" ;;
546
- "detached") branch="-" ;;
547
- "locked"*) locked="1" ;;
548
- "") [[ -n "$wt_path" ]] && printf '%s\t%s\t%s\n' "$wt_path" "${branch:--}" "$locked"
549
- wt_path=""; branch=""; locked="0" ;;
550
- esac
551
- done < <(git -C "$root" worktree list --porcelain 2>/dev/null)
552
- [[ -n "$wt_path" ]] && printf '%s\t%s\t%s\n' "$wt_path" "${branch:--}" "$locked"
553
- }
554
-
555
- # _wt_branch_merged <root> <branch> — true when <branch> is an ancestor of origin/${KIT_BASE_BRANCH:-main} (landed).
556
- _wt_branch_merged() {
557
- local root="$1" branch="$2"
558
- [[ -n "$branch" && "$branch" != "-" ]] || return 1
559
- git -C "$root" merge-base --is-ancestor "refs/heads/$branch" origin/${KIT_BASE_BRANCH:-main} 2>/dev/null
560
- }
561
-
562
- # _wt_is_clean <path> — true only when the worktree exists AND has no staged/unstaged/untracked
563
- # changes. A missing/zombie dir (git -C fails) is reported NOT clean, so it can never be recycled.
564
- _wt_is_clean() {
565
- local out
566
- out="$(git -C "$1" status --porcelain 2>/dev/null)" || return 1
567
- [[ -z "$out" ]]
568
- }
569
-
570
- # _wt_session_owns <root> <path> — true when a LIVE Claude session sits in <path> (or a subdir),
571
- # per the kit-sessions registry (.git/kit-sessions/*.json — wt_start writes one claim per issue
572
- # through session-registry.sh, with `cwd` set to the worktree). A dead
573
- # pid is not an owner. No registry → no known live owner (returns false).
574
- _wt_session_owns() {
575
- local root="$1" wt_path="$2" common reg f opid ocwd
576
- common="$(git -C "$root" rev-parse --path-format=absolute --git-common-dir 2>/dev/null)" || return 1
577
- reg="$common/kit-sessions"
578
- [[ -d "$reg" ]] || return 1
579
- for f in "$reg"/*.json; do
580
- [[ -e "$f" ]] || continue
581
- case "$f" in "$reg"/cache-*) continue ;; esac
582
- opid="$(jq -r '.pid // 0' "$f" 2>/dev/null)"
583
- [[ "$opid" =~ ^[1-9][0-9]*$ ]] || continue
584
- kill -0 "$opid" 2>/dev/null || continue
585
- ocwd="$(jq -r '.cwd // empty' "$f" 2>/dev/null)"
586
- case "$ocwd" in "$wt_path"|"$wt_path"/*) return 0 ;; esac
587
- done
588
- return 1
589
- }
590
-
591
- # _wt_pool_find <root> <target> — path of the OLDEST reusable pooled worktree, or nothing. Applies
592
- # the full eligibility gate above; <target> (the path wt_start is about to use) is always excluded.
593
- _wt_pool_find() {
594
- local root="$1" target="$2" wtdir best="" best_mt="" wt_path branch locked mt
595
- wtdir="$root/.claude/worktrees/"
596
- while IFS=$'\t' read -r wt_path branch locked; do
597
- [[ -n "$wt_path" ]] || continue
598
- case "$wt_path" in "$wtdir"*) : ;; *) continue ;; esac
599
- [[ "$wt_path" == "$target" ]] && continue
600
- [[ -d "$wt_path" ]] || continue
601
- [[ "$locked" == "1" ]] && continue
602
- _wt_branch_merged "$root" "$branch" || continue
603
- _wt_is_clean "$wt_path" || continue
604
- _wt_session_owns "$root" "$wt_path" && continue
605
- mt="$(_wt_mtime "$wt_path")"; [[ "$mt" =~ ^[0-9]+$ ]] || mt=0
606
- if [[ -z "$best" || "$mt" -lt "$best_mt" ]]; then best="$wt_path"; best_mt="$mt"; fi
607
- done < <(_wt_list "$root")
608
- [[ -n "$best" ]] && printf '%s\n' "$best"
609
- }
610
-
611
- # wt_pool_status — diagnostic listing of pooled worktrees + their reuse signals (read-only; never
612
- # mutates). Shows branch / merged-into-develop? / clean? / live-session? / overall reusable?.
613
- wt_pool_status() {
614
- local root wtdir wt_path branch locked merged clean owned reusable any=0
615
- root="$(git worktree list --porcelain | awk '/^worktree / && !hit {print $2; hit=1}')"
616
- [[ -n "$root" ]] || { echo "wt_pool_status: not in a git repo" >&2; return 1; }
617
- wtdir="$root/.claude/worktrees/"
618
- git -C "$root" fetch origin "${KIT_BASE_BRANCH:-main}" --quiet 2>/dev/null || true
619
- printf '%-44s %-26s %-7s %-6s %-8s %s\n' "WORKTREE" "BRANCH" "MERGED" "CLEAN" "SESSION" "REUSABLE"
620
- while IFS=$'\t' read -r wt_path branch locked; do
621
- [[ -n "$wt_path" ]] || continue
622
- case "$wt_path" in "$wtdir"*) : ;; *) continue ;; esac
623
- any=1
624
- _wt_branch_merged "$root" "$branch" && merged="yes" || merged="no"
625
- _wt_is_clean "$wt_path" && clean="yes" || clean="no"
626
- _wt_session_owns "$root" "$wt_path" && owned="live" || owned="-"
627
- if [[ "$locked" != "1" && "$merged" == "yes" && "$clean" == "yes" && "$owned" == "-" ]]; then
628
- reusable="yes"
629
- else
630
- reusable="no"
631
- fi
632
- printf '%-44s %-26s %-7s %-6s %-8s %s\n' "${wt_path#"$wtdir"}" "$branch" "$merged" "$clean" "$owned" "$reusable"
633
- done < <(_wt_list "$root")
634
- [[ "$any" == "1" ]] || echo "(no pooled worktrees under $wtdir)"
635
- }
636
-
637
- # _wt_claim_desc <tsv-row> — one human line for a claim row from sreg_issue_claim.
638
- _wt_claim_desc() {
639
- local c_issue c_branch c_wt c_pid c_host c_started
640
- IFS=$'\t' read -r c_issue c_branch c_wt c_pid c_host c_started <<EOF
641
- $1
642
- EOF
643
- printf 'pid %s on %s, worktree %s' "$c_pid" "$c_host" "$c_wt"
644
- }
645
-
646
- wt_start() {
647
- local num="" slug_override="" root meta title kind slug branch wt reused cand
648
- local force="${KIT_FORCE:-0}" _arg _claim _claimed="" _crc
649
- for _arg in "$@"; do
650
- case "$_arg" in
651
- --force) force=1 ;;
652
- -*) echo "wt_start: unknown flag '$_arg' (usage: start [--force] <issue> [slug])" >&2; return 1 ;;
653
- *) if [[ -z "$num" ]]; then num="$_arg"; elif [[ -z "$slug_override" ]]; then slug_override="$_arg"; fi ;;
654
- esac
655
- done
656
- [[ -n "$num" ]] || { echo "wt_start: issue number required" >&2; return 1; }
657
- # An E<n> / E<n>.<step> token resolves to its issue number before anything else runs.
658
- case "$num" in
659
- [Ee][0-9]*) num="$(_wt_resolve_token "$num")" || return 1 ;;
660
- esac
661
-
662
- root="$(git worktree list --porcelain | awk '/^worktree / && !hit {print $2; hit=1}')"
663
- [[ -n "$root" ]] || { echo "wt_start: not in a git repo" >&2; return 1; }
664
-
665
- # Claim check (#384) — BEFORE the issue read, the fetch and `git worktree add`, so a refusal
666
- # makes no network call, no branch and no worktree. A claim this session already holds (same
667
- # session pid, or the caller stands inside the claimed worktree) is not a collision: re-running
668
- # start stays the no-op it always was.
669
- if command -v sreg_issue_claim >/dev/null 2>&1 && _claim="$(sreg_issue_claim "$root" "$num")" \
670
- && ! sreg_claim_mine "$root" "$num"; then
671
- if [[ "$force" != "1" ]]; then
672
- echo "[#$num] refused: a live session already claims this issue — $(_wt_claim_desc "$_claim")" >&2
673
- echo "[#$num] see 'cckit claims'; 'cckit start --force $num' (or KIT_FORCE=1) starts anyway and takes the claim." >&2
674
- return 1
675
- fi
676
- echo "[#$num] ⚠ --force: taking over the claim of a live session — $(_wt_claim_desc "$_claim")" >&2
677
- fi
678
-
679
- # The board helpers load lazily, further down: Status is otherwise set server-side by built-in
680
- # automations (Item closed→Done, PR merged→Done), and In Progress is the one write wt_start owns.
681
-
682
- # Without a forge the issue is not read: the branch is task/<N>-<slug> with the slug given on the
683
- # command line, else issue-<N>. Said once, never silent.
684
- if forge_available; then
685
- meta="$(gh_rest_issue_json "$WT_START_REPO" "$num" 2>/dev/null)" || { echo "[#$num] issue not found" >&2; return 1; }
686
- title="$(echo "$meta" | jq -r '.title')"
687
- kind="$(echo "$meta" | jq -r '([.labels[].name | select(startswith("kind:"))][0] // "kind:task") | sub("^kind:";"")')"
688
- else
689
- forge_note_none start "issue #$num is not read; the branch is task/$num-${slug_override:-issue-$num} (pass a slug to name it)"
690
- title=""; kind="task"
691
- [[ -n "$slug_override" ]] || slug_override="issue-$num"
692
- fi
693
- kind="$(_wt_kind_prefix "$kind")"
694
- if [[ -n "$slug_override" ]]; then
695
- slug="$slug_override"
696
- else
697
- slug="$(echo "$title" \
698
- | sed -E 's/^\[[^]]+\][[:space:]]*//' \
699
- | tr '[:upper:]' '[:lower:]' \
700
- | sed -E 's/[^a-z0-9]+/-/g; s/^-+|-+$//g' \
701
- | cut -c1-40)"
702
- fi
703
- branch="$kind/$num-$slug"
704
- wt="$root/.claude/worktrees/${kind}+${num}-${slug}"
705
-
706
- # Take the claim now that the worktree path is known, still before the fetch. rc 3 = another
707
- # session claimed the issue between the check above and here. An unwritable registry only warns:
708
- # the registry is a guard, not a precondition for working.
709
- if command -v sreg_claim >/dev/null 2>&1; then
710
- # _claimed marks a claim THIS call writes (none before, or one taken over by force), so a
711
- # failed `worktree add` below releases only that — never a claim the session already held.
712
- sreg_claim_mine "$root" "$num" || _claimed="1"
713
- # `&& … ||` so a caller running under `set -e` (bin/cckit) reaches the refusal message.
714
- sreg_claim "$root" "$num" "$branch" "$wt" "$force" && _crc=0 || _crc=$?
715
- if [[ "$_crc" -eq 3 ]]; then
716
- echo "[#$num] refused: another session claimed this issue just now — see 'cckit claims'." >&2
717
- return 1
718
- elif [[ "$_crc" -ne 0 ]]; then
719
- _claimed=""
720
- echo "[#$num] ⚠ could not record the session claim; continuing without one." >&2
721
- fi
722
- fi
723
-
724
- git -C "$root" fetch origin "${KIT_BASE_BRANCH:-main}" --quiet
725
- if grep -q "/${kind}+${num}-${slug}$" <<<"$(git -C "$root" worktree list --porcelain)"; then
726
- echo "[#$num] reusing worktree $wt" >&2
727
- else
728
- reused=""
729
- # OPT-IN (KIT_WT_POOL=1): recycle an idle, already-landed worktree instead of creating one.
730
- # Safe by construction: _wt_pool_find only returns a clean, merged, session-free tree, and we
731
- # only attempt it when the new branch does not yet exist — so re-pointing can't collide with a
732
- # branch checked out elsewhere. Any hiccup leaves `reused` empty and falls through to the
733
- # unchanged create path below; with the flag off this whole block is skipped.
734
- if [[ "${KIT_WT_POOL:-0}" == "1" ]] && ! git -C "$root" show-ref --verify --quiet "refs/heads/$branch"; then
735
- cand="$(_wt_pool_find "$root" "$wt")"
736
- if [[ -n "$cand" ]] && git -C "$root" worktree move "$cand" "$wt" >/dev/null 2>&1; then
737
- # The recycled tree is now at the conventional path with its env + dependencies intact
738
- # (they moved with the dir — the pool's whole payoff). Re-point it to a fresh branch off
739
- # the latest develop; the clean+merged+branch-absent preconditions make -B reliable.
740
- git -C "$wt" checkout -B "$branch" origin/${KIT_BASE_BRANCH:-main} >/dev/null 2>&1 || true
741
- reused="1"
742
- echo "[#$num] reused idle worktree $wt" >&2
743
- fi
744
- fi
745
- if [[ -z "$reused" ]]; then
746
- git -C "$root" worktree add -B "$branch" "$wt" origin/${KIT_BASE_BRANCH:-main} >/dev/null 2>&1 \
747
- || { if [[ -n "$_claimed" ]]; then sreg_release "$root" "$num" 2>/dev/null || true; fi
748
- echo "[#$num] worktree add failed (branch $branch may exist elsewhere)" >&2; return 1; }
749
- echo "[#$num] created worktree $wt (branch $branch)" >&2
750
- fi
751
- fi
752
-
753
- # Bootstrap the worktree for local dev: copy local env, install deps, assign a dev port (#773).
754
- # Best-effort — a bootstrap hiccup never fails the start.
755
- wt_bootstrap "$root" "$wt" "$num" || true
756
-
757
- # Register with zoxide so `kit cd <issue|slug>` can jump here (no-op when zoxide is absent).
758
- command -v zoxide >/dev/null && zoxide add "$wt" >/dev/null 2>&1 || true
759
-
760
- # Mark the issue In Progress on the board. The board's built-in automations own the other
761
- # transitions server-side (Item added→Todo, PR linked→In Review, closed/merged→Done) — but GitHub
762
- # has no "branch started" trigger, so the kit owns In Progress. Cheap now: an O(1) issue.projectItems
763
- # lookup on the org board, not a full-board scan. Best-effort — a board hiccup never fails the start.
764
- if cckit_gh_rest; then
765
- command -v cckit_board_skipped >/dev/null 2>&1 && cckit_board_skipped
766
- elif source "$root/scripts/lib/gh-project.sh" 2>/dev/null; then
767
- [[ -n "${STATUS_FIELD_ID:-}" ]] || load_project_ids >/dev/null 2>&1 || true
768
- # Board precheck (#124, #384): an issue ALREADY In Progress or In Review may belong to someone
769
- # the local claims registry cannot see (a teammate's machine). Warn only — wt_start writes In
770
- # Progress itself and nothing resets it when a session dies, so refusing on board Status would
771
- # lock out every restart after a crash. The refusal is the live claim, checked at the top.
772
- if command -v project_issue_status >/dev/null 2>&1; then
773
- local _prev_status; _prev_status="$(project_issue_status "$num" 2>/dev/null || true)"
774
- [[ "$_prev_status" == "In Progress" || "$_prev_status" == "In Review" ]] \
775
- && echo "[#$num] ⚠ already $_prev_status on the board — another session may own this issue; continuing." >&2
776
- fi
777
- item="$(project_find_item_by_issue "$num" 2>/dev/null)"
778
- if [[ -z "$item" ]]; then
779
- local content_id
780
- content_id="$(forge_rest graphql -f query='query($o:String!,$r:String!,$n:Int!){repository(owner:$o,name:$r){issue(number:$n){id}}}' \
781
- -F o="${WT_START_REPO%/*}" -F r="${WT_START_REPO#*/}" -F n="$num" --jq '.data.repository.issue.id' 2>/dev/null)"
782
- [[ -n "$content_id" ]] && item="$(project_add_item "$content_id" 2>/dev/null)"
783
- fi
784
- [[ -n "$item" && -n "${STATUS_FIELD_ID:-}" && -n "${STATUS_OPT_IN_PROGRESS:-}" ]] \
785
- && project_set_single_select "$item" "$STATUS_FIELD_ID" "$STATUS_OPT_IN_PROGRESS" >/dev/null 2>&1 \
786
- && echo "[#$num] board → In Progress" >&2 || true
787
- fi
788
-
789
- echo "$wt|$branch|$num"
790
- }
2
+ # cckit-forwarding-stub: scripts/lib/worktree-start.sh moved to lib/core/worktree-start.sh (#600). Installed projects call this path, so
3
+ # the stub stays until the release after 0.13 (decision 66). Sourced (bash or zsh) or run, it forwards.
4
+ _cckit_self="${BASH_SOURCE[0]:-$0}"
5
+ _cckit_fwd="$(cd "$(dirname "$_cckit_self")" 2>/dev/null && pwd)/../../lib/core/worktree-start.sh"
6
+ _cckit_sourced=0
7
+ if [ -n "${ZSH_VERSION:-}" ]; then
8
+ case "${ZSH_EVAL_CONTEXT:-}" in *file*) _cckit_sourced=1 ;; esac
9
+ elif [ "$_cckit_self" != "$0" ]; then
10
+ _cckit_sourced=1
11
+ fi
12
+ # shellcheck source=/dev/null
13
+ if [ "$_cckit_sourced" = 1 ]; then unset _cckit_self _cckit_sourced; . "$_cckit_fwd" "$@"; return $?; fi
14
+ exec bash "$_cckit_fwd" "$@"