@jeiemgi/cckit 0.11.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 (549) hide show
  1. package/.claude-plugin/plugin.json +4 -2
  2. package/AGENTS.md +22 -238
  3. package/README.md +66 -56
  4. package/SECURITY.md +4 -4
  5. package/bin/PROMPTS.md +12 -0
  6. package/bin/cckit +181 -140
  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 +4 -4
  29. package/kit/skills/kit-advisor/SKILL.md +75 -0
  30. package/kit/skills/kit-advisor/references/close.md +53 -0
  31. package/kit/skills/kit-advisor/references/grill.md +69 -0
  32. package/kit/skills/kit-advisor/references/orchestrate.md +56 -0
  33. package/kit/skills/kit-advisor/references/plan.md +64 -0
  34. package/kit/skills/kit-advisor/references/review.md +47 -0
  35. package/kit/skills/kit-advisor/references/step-report.md +61 -0
  36. package/{skills → kit/skills}/kit-annotate/SKILL.md +2 -4
  37. package/{skills → kit/skills}/kit-autopilot/SKILL.md +7 -7
  38. package/{skills → kit/skills}/kit-cleanup/SKILL.md +4 -4
  39. package/{skills → kit/skills}/kit-contribute/SKILL.md +8 -12
  40. package/{skills → kit/skills}/kit-customize/SKILL.md +5 -8
  41. package/{skills → kit/skills}/kit-dev/SKILL.md +1 -1
  42. package/{skills → kit/skills}/kit-digest/SKILL.md +3 -3
  43. package/{skills → kit/skills}/kit-effort-close/SKILL.md +20 -12
  44. package/{skills → kit/skills}/kit-effort-new/SKILL.md +17 -14
  45. package/{skills → kit/skills}/kit-effort-pr/SKILL.md +7 -7
  46. package/{skills → kit/skills}/kit-effort-start/SKILL.md +3 -3
  47. package/{skills → kit/skills}/kit-gc/SKILL.md +3 -3
  48. package/{skills → kit/skills}/kit-next/SKILL.md +7 -7
  49. package/{skills → kit/skills}/kit-page/SKILL.md +1 -1
  50. package/{skills → kit/skills}/kit-plan-next/SKILL.md +10 -11
  51. package/{skills → kit/skills}/kit-status/SKILL.md +6 -6
  52. package/{skills → kit/skills}/kit-task-close/SKILL.md +5 -5
  53. package/{skills → kit/skills}/kit-task-new/SKILL.md +5 -5
  54. package/{skills → kit/skills}/kit-task-pr/SKILL.md +5 -5
  55. package/{skills → kit/skills}/kit-task-pr-auto/SKILL.md +1 -1
  56. package/{skills → kit/skills}/kit-task-pr-merge/SKILL.md +10 -10
  57. package/{skills → kit/skills}/kit-task-start/SKILL.md +1 -1
  58. package/{skills → kit/skills}/kit-task-sync/SKILL.md +5 -3
  59. package/{skills → kit/skills}/kit-ux-audit/SKILL.md +16 -35
  60. package/{skills → kit/skills}/kit-ux-audit/references/graph-model.md +7 -26
  61. package/{skills → kit/skills}/kit-ux-audit/references/report.md +2 -3
  62. package/{skills → kit/skills}/routing.yaml +6 -1
  63. package/kit/statusline/kit-statusline.sh +82 -0
  64. package/{templates → kit/templates}/agents/analyst.md +0 -11
  65. package/{templates → kit/templates}/agents/auto-dev.md +0 -13
  66. package/{templates → kit/templates}/agents/backend.md +0 -11
  67. package/{templates → kit/templates}/agents/designer.md +0 -11
  68. package/{templates → kit/templates}/agents/devops.md +0 -11
  69. package/{templates → kit/templates}/agents/editor.md +0 -11
  70. package/{templates → kit/templates}/agents/frontend.md +0 -11
  71. package/{templates → kit/templates}/agents/generalist.md +0 -11
  72. package/{templates → kit/templates}/agents/local-delegate.md +0 -13
  73. package/{templates → kit/templates}/agents/n8n.md +0 -11
  74. package/{templates → kit/templates}/agents/pm.md +0 -11
  75. package/{templates → kit/templates}/agents/qa.md +0 -11
  76. package/{templates → kit/templates}/agents/researcher.md +0 -11
  77. package/{templates → kit/templates}/agents/security.md +0 -11
  78. package/{templates → kit/templates}/agents/tech-lead.md +0 -11
  79. package/{templates → kit/templates}/agents/ux.md +3 -14
  80. package/{templates → kit/templates}/hooks/kit-mail-check.sh.tmpl +1 -1
  81. package/{templates → kit/templates}/instructions.md.tmpl +4 -21
  82. package/{templates → kit/templates}/kit.config.json.tmpl +0 -6
  83. package/{templates → kit/templates}/rules/authoring.md +7 -3
  84. package/{templates → kit/templates}/rules/branch-naming.md +3 -2
  85. package/{templates → kit/templates}/rules/delegation-brief.md +4 -0
  86. package/{templates → kit/templates}/rules/effort-model.md +34 -31
  87. package/{templates → kit/templates}/rules/gate-and-review.md +1 -1
  88. package/{templates → kit/templates}/rules/merge-safety.md +12 -9
  89. package/{templates → kit/templates}/rules/naming-and-ids.md +20 -24
  90. package/{templates → kit/templates}/rules/plan-next.md +5 -5
  91. package/{templates → kit/templates}/rules/react-annotate.md +0 -8
  92. package/{templates → kit/templates}/skills/campaign/SKILL.md +2 -2
  93. package/kit.config.schema.json +11 -11
  94. package/lib/PROMPTS.md +14 -0
  95. package/{scripts/lib → lib/core}/adapter-select-test.sh +7 -7
  96. package/lib/core/advisor-test.sh +55 -0
  97. package/{scripts/lib → lib/core}/agent-def-test.sh +1 -1
  98. package/{scripts/lib → lib/core}/agent-def.sh +2 -2
  99. package/{scripts/lib → lib/core}/agent-launch-test.sh +3 -3
  100. package/{scripts/lib → lib/core}/agent-profile-test.sh +2 -2
  101. package/{scripts/lib → lib/core}/agent-resolve-test.sh +4 -2
  102. package/{scripts/lib → lib/core}/agent-resolve.sh +5 -4
  103. package/{scripts → lib/core}/agent-skills-external.txt +3 -3
  104. package/{scripts → lib/core}/agent-skills-lint-test.sh +17 -17
  105. package/lib/core/agent-skills-lint.sh +115 -0
  106. package/{scripts → lib/core}/agent-template-lint-test.sh +7 -7
  107. package/lib/core/agent-template-lint.sh +58 -0
  108. package/{scripts/lib → lib/core}/board-view-test.sh +3 -3
  109. package/lib/core/board-view.sh +97 -0
  110. package/{scripts/lib → lib/core}/branch-owner-test.sh +3 -3
  111. package/lib/core/branch-owner.sh +201 -0
  112. package/lib/core/check.sh +125 -0
  113. package/{scripts/lib → lib/core}/codex-hooks-test.sh +3 -3
  114. package/{scripts → lib/core}/commitlint-test.sh +6 -6
  115. package/lib/core/commitlint.sh +54 -0
  116. package/{scripts/config-path-test.sh → lib/core/config-path-scan-test.sh} +2 -2
  117. package/{scripts/lib → lib/core}/config-path-test.sh +3 -3
  118. package/lib/core/config-path.sh +30 -0
  119. package/{scripts → lib/core}/content-skills-test.sh +17 -17
  120. package/{scripts → lib/core}/docs-marketing-words-test.sh +2 -2
  121. package/{scripts → lib/core}/docs-record-tables-test.sh +2 -2
  122. package/{scripts/lib → lib/core}/effort-metrics-test.sh +6 -6
  123. package/lib/core/effort-metrics.sh +591 -0
  124. package/{scripts/lib → lib/core}/effort-slug-test.sh +8 -4
  125. package/{scripts/lib → lib/core}/effort-slug.sh +8 -7
  126. package/lib/core/effort.sh +339 -0
  127. package/{scripts/lib → lib/core}/errors-header-test.sh +19 -9
  128. package/lib/core/errors-header.exempt +49 -0
  129. package/{scripts → lib/core}/exec-targets-test.sh +3 -3
  130. package/lib/core/feature-map.sh +76 -0
  131. package/lib/core/force-push-fence-test.sh +44 -0
  132. package/lib/core/force-push-fence.baseline +1 -0
  133. package/lib/core/force-push-fence.sh +51 -0
  134. package/{scripts → lib/core}/forge-fence-test.sh +13 -13
  135. package/{scripts → lib/core}/forge-fence.sh +14 -14
  136. package/{scripts → lib/core}/forge-report-test.sh +5 -5
  137. package/{scripts → lib/core}/forge-report.sh +18 -14
  138. package/{scripts/lib → lib/core}/git-core-test.sh +7 -7
  139. package/{scripts/lib → lib/core}/git-remote-test.sh +3 -3
  140. package/{scripts → lib/core}/guard-raw-git-ops-test.sh +4 -4
  141. package/{scripts → lib/core}/hook-adapter-test.sh +5 -5
  142. package/{scripts/lib → lib/core}/hook-refresh-test.sh +5 -5
  143. package/{scripts → lib/core}/instruction-budget-baseline.txt +2 -2
  144. package/lib/core/instruction-budget-lint.sh +238 -0
  145. package/{scripts/lib → lib/core}/integration-install-test.sh +12 -12
  146. package/lib/core/integration-install.sh +257 -0
  147. package/{scripts/lib → lib/core}/integrations-test.sh +38 -45
  148. package/lib/core/integrations.sh +244 -0
  149. package/{scripts/lib → lib/core}/kinds-test.sh +5 -5
  150. package/lib/core/kinds.sh +66 -0
  151. package/{scripts/lib → lib/core}/kit-cli-test.sh +1 -1
  152. package/{scripts/lib → lib/core}/kit-cli.sh +1 -1
  153. package/{scripts/lib → lib/core}/kit-config-resolve.sh +2 -2
  154. package/{scripts/lib → lib/core}/kit-config-test.sh +11 -11
  155. package/lib/core/kit-config.sh +164 -0
  156. package/{scripts/lib → lib/core}/kit-engine-test.sh +1 -1
  157. package/lib/core/kit-events.sh +72 -0
  158. package/lib/core/kit-local.sh +87 -0
  159. package/{scripts/lib → lib/core}/kit-manifest.sh +1 -1
  160. package/{scripts/lib → lib/core}/kit-mode-test.sh +1 -1
  161. package/{scripts/lib → lib/core}/kit-mode.sh +3 -3
  162. package/{scripts/lib → lib/core}/kit-operate.sh +1 -1
  163. package/{scripts/lib → lib/core}/kit-profile-test.sh +1 -1
  164. package/{scripts/lib → lib/core}/kit-profile.sh +2 -2
  165. package/{scripts/lib → lib/core}/kit-state-test.sh +1 -1
  166. package/lib/core/knowledge-lint.sh +106 -0
  167. package/lib/core/layout-fence-test.sh +35 -0
  168. package/lib/core/layout-fence.allow +15 -0
  169. package/lib/core/layout-fence.baseline +4 -0
  170. package/lib/core/layout-fence.sh +50 -0
  171. package/{scripts → lib/core}/leak-fence-test.sh +10 -10
  172. package/{scripts/lib → lib/core}/leak-fence.sh +1 -1
  173. package/lib/core/loose-issues-test.sh +102 -0
  174. package/lib/core/loose-issues.baseline +5 -0
  175. package/lib/core/loose-issues.sh +65 -0
  176. package/{scripts → lib/core}/marketing-walkthrough-test.sh +7 -7
  177. package/lib/core/naming-test.sh +112 -0
  178. package/lib/core/naming-verbs-test.sh +126 -0
  179. package/lib/core/naming.sh +172 -0
  180. package/{scripts/lib → lib/core}/orchestration-runtime-test.sh +4 -4
  181. package/{scripts → lib/core}/portable-test.sh +11 -7
  182. package/{scripts/lib → lib/core}/pr-evidence-test.sh +5 -5
  183. package/lib/core/pr-evidence.sh +361 -0
  184. package/{scripts/lib → lib/core}/qa-lane-test.sh +7 -7
  185. package/{scripts/lib → lib/core}/qa-lane.sh +4 -4
  186. package/{scripts/lib → lib/core}/qa-lanes-test.sh +5 -5
  187. package/lib/core/react-detect.sh +79 -0
  188. package/{scripts/lib → lib/core}/render-test.sh +1 -1
  189. package/lib/core/resident-context-test.sh +42 -0
  190. package/lib/core/resident-context.baseline +1 -0
  191. package/lib/core/resident-context.sh +56 -0
  192. package/lib/core/review-lint-baseline.txt +28 -0
  193. package/lib/core/review-lint.sh +266 -0
  194. package/{scripts → lib/core}/review-rules.conf +1 -1
  195. package/{scripts/lib → lib/core}/review-stage-test.sh +2 -2
  196. package/{scripts/lib → lib/core}/role-identity-test.sh +3 -3
  197. package/lib/core/role-identity.sh +71 -0
  198. package/{scripts → lib/core}/rule-recipes-test.sh +5 -5
  199. package/lib/core/secret-guard.sh +116 -0
  200. package/{scripts → lib/core}/self-install-test.sh +15 -16
  201. package/{scripts/lib → lib/core}/session-registry-test.sh +1 -1
  202. package/lib/core/session-registry.sh +233 -0
  203. package/{scripts → lib/core}/skill-frontmatter-baseline.txt +1 -1
  204. package/lib/core/skill-frontmatter-lint.sh +189 -0
  205. package/lib/core/spec-lint-test.sh +63 -0
  206. package/lib/core/spec-lint.sh +95 -0
  207. package/{scripts/lib → lib/core}/stage-receipt-test.sh +136 -4
  208. package/{scripts/lib → lib/core}/stage-receipt.sh +186 -7
  209. package/{scripts → lib/core}/terms-check-test.sh +6 -6
  210. package/lib/core/terms-check.sh +244 -0
  211. package/{scripts/lib → lib/core}/test-env-test.sh +2 -2
  212. package/{scripts/lib → lib/core}/test-env.sh +1 -1
  213. package/{scripts → lib/core}/test-runner-test.sh +11 -11
  214. package/{scripts → lib/core}/test.sh +12 -12
  215. package/{scripts → lib/core}/update-path-test.sh +3 -3
  216. package/{scripts → lib/core}/verbs-gen.sh +9 -9
  217. package/{scripts → lib/core}/verbs-help-test.sh +4 -4
  218. package/{scripts → lib/core}/verbs-ratchet-test.sh +24 -19
  219. package/{scripts → lib/core}/verbs-ratchet.sh +8 -8
  220. package/{scripts → lib/core}/verbs-test.sh +23 -23
  221. package/lib/core/verbs.baseline +5 -0
  222. package/{scripts/lib → lib/core}/verbs.sh +3 -3
  223. package/{scripts/lib → lib/core}/verbs.tsv +22 -20
  224. package/{scripts/lib → lib/core}/version-bump-test.sh +29 -8
  225. package/{scripts/lib → lib/core}/version-bump.sh +15 -2
  226. package/{scripts/lib → lib/core}/wave-result-test.sh +2 -2
  227. package/{scripts/lib → lib/core}/wave-result.sh +1 -1
  228. package/{scripts/lib → lib/core}/worker-brief-test.sh +4 -4
  229. package/{scripts/lib → lib/core}/worker-brief.sh +1 -1
  230. package/{scripts/lib → lib/core}/worktree-bootstrap-test.sh +1 -1
  231. package/{scripts/lib → lib/core}/worktree-issue-test.sh +2 -2
  232. package/lib/core/worktree-issue.sh +172 -0
  233. package/{scripts/lib → lib/core}/worktree-ports-test.sh +1 -1
  234. package/{scripts/lib → lib/core}/worktree-start-test.sh +2 -2
  235. package/lib/core/worktree-start.sh +790 -0
  236. package/{scripts/lib → lib/core}/zsh-safety-test.sh +11 -11
  237. package/{scripts/lib → lib/forge}/forge-github.sh +18 -7
  238. package/{scripts/lib → lib/forge}/forge-test.sh +4 -4
  239. package/{scripts/lib → lib/forge}/forge.sh +1 -1
  240. package/lib/forge/gh-board-add-test.sh +118 -0
  241. package/lib/forge/gh-log.sh +59 -0
  242. package/lib/forge/gh-project-test.sh +251 -0
  243. package/lib/forge/gh-project.sh +379 -0
  244. package/{scripts/lib → lib/forge}/gh-rest-test.sh +17 -13
  245. package/{scripts/lib → lib/forge}/gh-rest.sh +190 -16
  246. package/{scripts/lib → lib/forge}/init-github.sh +18 -8
  247. package/{scripts/lib → lib/forge}/test-forge-shim.sh +2 -1
  248. package/lib/verbs/PROMPTS.md +146 -0
  249. package/lib/verbs/annotate-setup.sh +149 -0
  250. package/{scripts → lib/verbs}/autopilot-run-test.sh +9 -9
  251. package/{scripts → lib/verbs}/autopilot-run.sh +9 -9
  252. package/{scripts → lib/verbs}/autopilot-test.sh +7 -6
  253. package/{scripts → lib/verbs}/autopilot.sh +7 -7
  254. package/{scripts/lib → lib/verbs}/captain-test.sh +1 -1
  255. package/{scripts/lib → lib/verbs}/captain.sh +8 -8
  256. package/lib/verbs/capture-project-ids.sh +99 -0
  257. package/{scripts/lib → lib/verbs}/content-kinds-gc-test.sh +7 -7
  258. package/{scripts/lib → lib/verbs}/contribute-root-test.sh +4 -4
  259. package/{scripts/lib → lib/verbs}/contribute-root.sh +1 -1
  260. package/{scripts → lib/verbs}/contribute.sh +8 -8
  261. package/{scripts → lib/verbs}/copilot-loop-test.sh +12 -12
  262. package/{scripts/lib → lib/verbs}/copilot-test.sh +15 -14
  263. package/{scripts/lib → lib/verbs}/copilot.sh +19 -19
  264. package/{scripts → lib/verbs}/database-supabase-test.sh +6 -6
  265. package/lib/verbs/effort-close-subs-test.sh +96 -0
  266. package/{scripts/lib → lib/verbs}/effort-dispatch-test.sh +5 -5
  267. package/{scripts/lib → lib/verbs}/effort-flows-test.sh +5 -5
  268. package/{scripts/lib → lib/verbs}/effort-ops-test.sh +111 -22
  269. package/lib/verbs/effort-ops.sh +1571 -0
  270. package/{scripts/lib → lib/verbs}/effort-parity-test.sh +47 -41
  271. package/{scripts/lib → lib/verbs}/effort-plan-test.sh +7 -7
  272. package/lib/verbs/effort-plan.sh +289 -0
  273. package/lib/verbs/effort-review-test.sh +107 -0
  274. package/lib/verbs/effort-review.sh +93 -0
  275. package/lib/verbs/grill-record-test.sh +49 -0
  276. package/lib/verbs/grill-record.sh +88 -0
  277. package/{scripts/lib → lib/verbs}/handoff.sh +3 -3
  278. package/{scripts → lib/verbs}/init-content-test.sh +14 -14
  279. package/{scripts/lib → lib/verbs}/init-guide.sh +6 -6
  280. package/{scripts → lib/verbs}/init-guided-test.sh +9 -9
  281. package/{scripts → lib/verbs}/init-recipes-test.sh +7 -7
  282. package/{scripts → lib/verbs}/init-upgrade-test.sh +9 -10
  283. package/lib/verbs/init.sh +1598 -0
  284. package/{scripts → lib/verbs}/install-test.sh +5 -5
  285. package/lib/verbs/install.sh +31 -0
  286. package/{scripts → lib/verbs}/integrations-check-test.sh +9 -9
  287. package/lib/verbs/integrations-check.sh +157 -0
  288. package/{scripts → lib/verbs}/kit-add-test.sh +8 -8
  289. package/lib/verbs/kit-add.sh +415 -0
  290. package/{scripts → lib/verbs}/kit-adopt-test.sh +4 -4
  291. package/{scripts → lib/verbs}/kit-adopt.sh +6 -6
  292. package/{scripts/lib → lib/verbs}/kit-brief-test.sh +44 -15
  293. package/{scripts/lib → lib/verbs}/kit-brief.sh +101 -16
  294. package/lib/verbs/kit-bump-version.sh +79 -0
  295. package/lib/verbs/kit-digest.sh +126 -0
  296. package/{scripts → lib/verbs}/kit-doctor-test.sh +57 -32
  297. package/lib/verbs/kit-doctor.sh +991 -0
  298. package/{scripts → lib/verbs}/kit-export-project-test.sh +4 -4
  299. package/lib/verbs/kit-export-project.sh +245 -0
  300. package/{scripts → lib/verbs}/kit-export-training-test.sh +3 -3
  301. package/lib/verbs/kit-export-training.sh +175 -0
  302. package/{scripts/lib → lib/verbs}/kit-gc-test.sh +5 -5
  303. package/lib/verbs/kit-gc.sh +804 -0
  304. package/{scripts/lib → lib/verbs}/kit-hotfix.sh +3 -3
  305. package/{scripts/lib → lib/verbs}/kit-interview-test.sh +2 -2
  306. package/lib/verbs/kit-interview.sh +319 -0
  307. package/{scripts/lib → lib/verbs}/kit-lib-test.sh +2 -2
  308. package/{scripts/lib → lib/verbs}/kit-lib.sh +10 -10
  309. package/{scripts → lib/verbs}/kit-migrate-test.sh +4 -4
  310. package/{scripts → lib/verbs}/kit-migrate.sh +5 -5
  311. package/{scripts/lib → lib/verbs}/kit-msg-test.sh +2 -2
  312. package/{scripts/lib → lib/verbs}/kit-msg.sh +5 -5
  313. package/{scripts → lib/verbs}/kit-onboard-test.sh +2 -3
  314. package/lib/verbs/kit-onboard.sh +69 -0
  315. package/{scripts → lib/verbs}/kit-promote-test.sh +4 -4
  316. package/{scripts → lib/verbs}/kit-promote.sh +4 -4
  317. package/{scripts → lib/verbs}/kit-remove-test.sh +4 -4
  318. package/{scripts → lib/verbs}/kit-remove.sh +5 -5
  319. package/lib/verbs/kit-routines.sh +322 -0
  320. package/lib/verbs/kit-self-update.sh +55 -0
  321. package/{scripts/lib → lib/verbs}/kit-status-test.sh +2 -2
  322. package/lib/verbs/kit-status.sh +650 -0
  323. package/{scripts/lib → lib/verbs}/kit-task-ops-test.sh +25 -2
  324. package/lib/verbs/kit-task-ops.sh +793 -0
  325. package/{scripts → lib/verbs}/kit-version-check-test.sh +3 -3
  326. package/lib/verbs/kit-version-check.sh +121 -0
  327. package/{scripts → lib/verbs}/kit-wire-test.sh +6 -6
  328. package/{scripts → lib/verbs}/kit-wire.sh +8 -8
  329. package/{scripts/lib → lib/verbs}/kto-hotfix-test.sh +3 -3
  330. package/{scripts/lib → lib/verbs}/kto-task-close-test.sh +2 -2
  331. package/{scripts/lib → lib/verbs}/kto-task-new-test.sh +20 -2
  332. package/{scripts/lib → lib/verbs}/kto-task-pr-merge-test.sh +46 -2
  333. package/{scripts/lib → lib/verbs}/kto-task-pr-test.sh +6 -6
  334. package/{scripts/lib → lib/verbs}/light-task-run-test.sh +4 -4
  335. package/{scripts/lib → lib/verbs}/light-task-test.sh +9 -9
  336. package/{scripts/lib → lib/verbs}/light-task.sh +26 -11
  337. package/{scripts/lib → lib/verbs}/next-test.sh +3 -3
  338. package/{scripts/lib → lib/verbs}/next.sh +10 -10
  339. package/{scripts → lib/verbs}/night-grant-test.sh +4 -4
  340. package/lib/verbs/night-grant.sh +454 -0
  341. package/{scripts → lib/verbs}/night-run-test.sh +3 -3
  342. package/{scripts → lib/verbs}/night-run.mjs +2 -2
  343. package/{scripts → lib/verbs}/orchestrate-test.sh +5 -5
  344. package/{scripts → lib/verbs}/orchestrate.sh +15 -15
  345. package/{scripts/lib → lib/verbs}/plan-machine-test.sh +1 -1
  346. package/{scripts/lib → lib/verbs}/plan-machine.sh +13 -13
  347. package/{scripts/lib → lib/verbs}/plan-next-test.sh +1 -1
  348. package/lib/verbs/plan-next.sh +213 -0
  349. package/{scripts → lib/verbs}/publish.sh +10 -10
  350. package/{scripts/lib → lib/verbs}/review-page-test.sh +4 -4
  351. package/lib/verbs/review-page.sh +375 -0
  352. package/lib/verbs/setup-labels.sh +96 -0
  353. package/lib/verbs/setup-milestones.sh +34 -0
  354. package/{scripts → lib/verbs}/showcase.sh +2 -2
  355. package/lib/verbs/sprint-test.sh +96 -0
  356. package/lib/verbs/sprint.sh +216 -0
  357. package/{scripts → lib/verbs}/status-test.sh +8 -8
  358. package/{scripts → lib/verbs}/status.sh +16 -16
  359. package/{scripts → lib/verbs}/task-sync-test.sh +40 -6
  360. package/lib/verbs/task-sync.sh +462 -0
  361. package/{scripts/lib → lib/verbs}/upgrade-report-test.sh +4 -4
  362. package/lib/verbs/ux-a11y-scan.sh +96 -0
  363. package/lib/verbs/ux-ds-audit.sh +146 -0
  364. package/lib/verbs/ux-graph-scan.sh +188 -0
  365. package/{scripts → lib/verbs}/wave-worker.sh +2 -2
  366. package/lib/verbs/web-install.sh +22 -0
  367. package/package.json +3 -10
  368. package/scripts/PROMPTS.md +13 -0
  369. package/scripts/agent-skills-lint.sh +12 -113
  370. package/scripts/agent-template-lint.sh +12 -56
  371. package/scripts/annotate-setup.sh +11 -151
  372. package/scripts/benchmark/checkpoint-test.sh +1 -1
  373. package/scripts/benchmark/checkpoint.sh +1 -1
  374. package/scripts/benchmark/gate.sh +2 -2
  375. package/scripts/benchmark/lib/bench-common.sh +1 -1
  376. package/scripts/capture-project-ids.sh +12 -70
  377. package/scripts/check.sh +12 -106
  378. package/scripts/force-push-fence.sh +14 -0
  379. package/scripts/init.sh +13 -1637
  380. package/scripts/install.sh +12 -29
  381. package/scripts/instruction-budget-lint.sh +13 -218
  382. package/scripts/integrations-check.sh +12 -155
  383. package/scripts/kit-add.sh +12 -413
  384. package/scripts/kit-bump-version.sh +13 -78
  385. package/scripts/kit-digest.sh +13 -125
  386. package/scripts/kit-doctor.sh +13 -971
  387. package/scripts/kit-export-project.sh +12 -243
  388. package/scripts/kit-export-training.sh +12 -173
  389. package/scripts/kit-onboard.sh +12 -67
  390. package/scripts/kit-routines.sh +12 -320
  391. package/scripts/kit-self-update.sh +12 -53
  392. package/scripts/kit-version-check.sh +12 -106
  393. package/scripts/knowledge-lint.sh +13 -98
  394. package/scripts/lib/board-view.sh +13 -96
  395. package/scripts/lib/branch-owner.sh +12 -199
  396. package/scripts/lib/commitlint.sh +12 -52
  397. package/scripts/lib/config-path.sh +13 -29
  398. package/scripts/lib/effort-metrics.sh +12 -589
  399. package/scripts/lib/effort-ops.sh +13 -1243
  400. package/scripts/lib/effort-plan.sh +12 -287
  401. package/scripts/lib/effort.sh +13 -365
  402. package/scripts/lib/gh-log.sh +14 -59
  403. package/scripts/lib/gh-project.sh +13 -254
  404. package/scripts/lib/grill-record.sh +14 -0
  405. package/scripts/lib/integration-install.sh +12 -255
  406. package/scripts/lib/integrations.sh +12 -242
  407. package/scripts/lib/kinds.sh +13 -65
  408. package/scripts/lib/kit-config.sh +12 -165
  409. package/scripts/lib/kit-events.sh +13 -71
  410. package/scripts/lib/kit-gc.sh +12 -802
  411. package/scripts/lib/kit-interview.sh +11 -316
  412. package/scripts/lib/kit-local.sh +12 -85
  413. package/scripts/lib/kit-status.sh +12 -648
  414. package/scripts/lib/kit-task-ops.sh +13 -738
  415. package/scripts/lib/naming.sh +14 -0
  416. package/scripts/lib/plan-next.sh +13 -212
  417. package/scripts/lib/pr-evidence.sh +12 -359
  418. package/scripts/lib/react-detect.sh +12 -77
  419. package/scripts/lib/review-page.sh +11 -372
  420. package/scripts/lib/role-identity.sh +13 -70
  421. package/scripts/lib/secret-guard.sh +12 -114
  422. package/scripts/lib/session-registry.sh +13 -232
  423. package/scripts/lib/spec-lint.sh +14 -0
  424. package/scripts/lib/worktree-issue.sh +12 -170
  425. package/scripts/lib/worktree-start.sh +13 -748
  426. package/scripts/night-grant.sh +12 -452
  427. package/scripts/review-lint.sh +13 -258
  428. package/scripts/setup-labels.sh +11 -82
  429. package/scripts/setup-milestones.sh +12 -21
  430. package/scripts/skill-frontmatter-lint.sh +13 -181
  431. package/scripts/task-sync.sh +13 -370
  432. package/scripts/terms-check.sh +13 -241
  433. package/scripts/ux-a11y-scan.sh +13 -95
  434. package/scripts/ux-ds-audit.sh +12 -144
  435. package/scripts/ux-graph-scan.sh +12 -186
  436. package/scripts/web-install.sh +16 -20
  437. package/docs/kit-annotate/01-explainer.html +0 -225
  438. package/docs/kit-annotate/02-implementation-plan.html +0 -196
  439. package/docs/media/.onboarding-capture.cast +0 -5
  440. package/docs/media/README.md +0 -43
  441. package/docs/media/build-demo.sh +0 -63
  442. package/docs/media/build-kit-init.sh +0 -51
  443. package/docs/media/build-onboarding.sh +0 -51
  444. package/docs/media/kit-dry-run.cast +0 -107
  445. package/docs/media/kit-dry-run.gif +0 -0
  446. package/docs/media/kit-init.cast +0 -56
  447. package/docs/media/kit-init.gif +0 -0
  448. package/docs/media/kit-onboarding.cast +0 -148
  449. package/docs/media/kit-onboarding.gif +0 -0
  450. package/integrations/mempalace.json +0 -28
  451. package/scripts/lib/gh-project-test.sh +0 -135
  452. package/scripts/review-lint-baseline.txt +0 -28
  453. package/scripts/verbs.baseline +0 -5
  454. package/templates/hooks/mempal_followup.sh.tmpl +0 -97
  455. package/templates/hooks/mempal_precompact.sh.tmpl +0 -4
  456. package/templates/hooks/mempal_save.sh.tmpl +0 -4
  457. package/templates/hooks/mempal_session_start.sh.tmpl +0 -42
  458. package/templates/rules/mempalace.md +0 -111
  459. /package/{commands → kit/commands}/kit-docs.md +0 -0
  460. /package/{commands → kit/commands}/kit-export-training.md +0 -0
  461. /package/{databases → kit/databases}/supabase/guide.html +0 -0
  462. /package/{databases → kit/databases}/supabase/nextjs/lib/supabase/client.ts +0 -0
  463. /package/{databases → kit/databases}/supabase/nextjs/lib/supabase/server.ts +0 -0
  464. /package/{githooks → kit/githooks}/pre-commit +0 -0
  465. /package/{integrations → kit/integrations}/emil-design-eng.json +0 -0
  466. /package/{integrations → kit/integrations}/graft.json +0 -0
  467. /package/{integrations → kit/integrations}/impeccable.json +0 -0
  468. /package/{integrations → kit/integrations}/lavish.json +0 -0
  469. /package/{integrations → kit/integrations}/mlx-lm.json +0 -0
  470. /package/{integrations → kit/integrations}/web-design-guidelines.json +0 -0
  471. /package/{recipes → kit/recipes}/nextjs-shadcn.json +0 -0
  472. /package/{skills → kit/skills}/kit-docs-writer/SKILL.md +0 -0
  473. /package/{skills → kit/skills}/kit-onboard/SKILL.md +0 -0
  474. /package/{skills → kit/skills}/kit-security-sweep/SKILL.md +0 -0
  475. /package/{skills → kit/skills}/kit-ship/SKILL.md +0 -0
  476. /package/{skills → kit/skills}/kit-ux-audit/references/a11y.md +0 -0
  477. /package/{skills → kit/skills}/kit-ux-audit/references/consistency.md +0 -0
  478. /package/{skills → kit/skills}/kit-ux-audit/references/heuristics.md +0 -0
  479. /package/{templates → kit/templates}/benchmarks/SCHEMA.md +0 -0
  480. /package/{templates → kit/templates}/benchmarks/abstain.jsonl +0 -0
  481. /package/{templates → kit/templates}/benchmarks/adversarial.jsonl +0 -0
  482. /package/{templates → kit/templates}/benchmarks/benchmark.config.json +0 -0
  483. /package/{templates → kit/templates}/benchmarks/quality.jsonl +0 -0
  484. /package/{templates → kit/templates}/benchmarks/retrieval.jsonl +0 -0
  485. /package/{templates → kit/templates}/codex/hooks.json.tmpl +0 -0
  486. /package/{templates → kit/templates}/hooks/guard-base-branch-commit.sh.tmpl +0 -0
  487. /package/{templates → kit/templates}/hooks/guard-raw-git-ops.sh.tmpl +0 -0
  488. /package/{templates → kit/templates}/hooks/kit-local-status.sh.tmpl +0 -0
  489. /package/{templates → kit/templates}/hooks/kit_version_check.sh.tmpl +0 -0
  490. /package/{templates → kit/templates}/hooks/prepush_gate.sh.tmpl +0 -0
  491. /package/{templates → kit/templates}/hooks/repo-hygiene.sh.tmpl +0 -0
  492. /package/{templates → kit/templates}/knowledge-INDEX.md.tmpl +0 -0
  493. /package/{templates → kit/templates}/lib/kit-sigil.sh.tmpl +0 -0
  494. /package/{templates → kit/templates}/rules/code-retrieval.md +0 -0
  495. /package/{templates → kit/templates}/rules/communication-style.md +0 -0
  496. /package/{templates → kit/templates}/rules/design-routing.md +0 -0
  497. /package/{templates → kit/templates}/rules/issue-lifecycle.md +0 -0
  498. /package/{templates → kit/templates}/rules/knowledge-base.md +0 -0
  499. /package/{templates → kit/templates}/rules/plain-language.md +0 -0
  500. /package/{templates → kit/templates}/rules/plan-output-format.md +0 -0
  501. /package/{templates → kit/templates}/rules/review-pages.md +0 -0
  502. /package/{templates → kit/templates}/rules/risk-tiered-review.md +0 -0
  503. /package/{templates → kit/templates}/rules/shared-checkout.md +0 -0
  504. /package/{templates → kit/templates}/rules/skill-gaps.md +0 -0
  505. /package/{templates → kit/templates}/rules/task-management.md +0 -0
  506. /package/{templates → kit/templates}/settings/settings.json.tmpl +0 -0
  507. /package/{templates → kit/templates}/settings/settings.local.json.tmpl +0 -0
  508. /package/{templates → kit/templates}/skills/NAMESPACED +0 -0
  509. /package/{templates → kit/templates}/skills/brand-voice/SKILL.md +0 -0
  510. /package/{templates → kit/templates}/skills/brand-voice/references/voice-template.md +0 -0
  511. /package/{templates → kit/templates}/skills/campaign/references/plan-template.md +0 -0
  512. /package/{templates → kit/templates}/skills/concrete/SKILL.md +0 -0
  513. /package/{templates → kit/templates}/skills/copywriting/SKILL.md +0 -0
  514. /package/{templates → kit/templates}/skills/copywriting/references/copy-frameworks.md +0 -0
  515. /package/{templates → kit/templates}/skills/copywriting/references/natural-transitions.md +0 -0
  516. /package/{templates → kit/templates}/skills/feature-build-refine/SKILL.md +0 -0
  517. /package/{templates → kit/templates}/skills/karpathy-guidelines/SKILL.md +0 -0
  518. /package/{templates → kit/templates}/skills/morning-briefing/SKILL.md +0 -0
  519. /package/{templates → kit/templates}/skills/page-design/SKILL.md +0 -0
  520. /package/{templates → kit/templates}/skills/page-design/add.json +0 -0
  521. /package/{templates → kit/templates}/skills/page-design/references/design-file-template.md +0 -0
  522. /package/{templates → kit/templates}/skills/page-design/references/generic-page-patterns.md +0 -0
  523. /package/{templates → kit/templates}/skills/page-design/references/minimum-rules.md +0 -0
  524. /package/{templates → kit/templates}/skills/speckit/SKILL.md +0 -0
  525. /package/{templates → kit/templates}/skills/supabase-patterns/SKILL.md +0 -0
  526. /package/{scripts/lib → lib/core}/adapter-select.sh +0 -0
  527. /package/{scripts/lib → lib/core}/agent-launch.sh +0 -0
  528. /package/{scripts/lib → lib/core}/agent-profile.sh +0 -0
  529. /package/{scripts/lib → lib/core}/cckit-output.sh +0 -0
  530. /package/{scripts/lib → lib/core}/codex-hooks.sh +0 -0
  531. /package/{scripts → lib/core}/forge-fence.baseline +0 -0
  532. /package/{scripts/lib → lib/core}/git-remote.sh +0 -0
  533. /package/{scripts/lib → lib/core}/hook-refresh.sh +0 -0
  534. /package/{scripts → lib/core}/instruction-budget-lint-test.sh +0 -0
  535. /package/{scripts/lib → lib/core}/kit-state.sh +0 -0
  536. /package/{scripts/lib → lib/core}/orchestration-runtime.sh +0 -0
  537. /package/{scripts/lib → lib/core}/project-scan.sh +0 -0
  538. /package/{scripts/lib → lib/core}/render.sh +0 -0
  539. /package/{scripts → lib/core}/review-lint-test.sh +0 -0
  540. /package/{scripts/lib → lib/core}/review-stage.sh +0 -0
  541. /package/{scripts → lib/core}/skill-frontmatter-lint-test.sh +0 -0
  542. /package/{scripts/lib → lib/core}/task-source-file.sh +0 -0
  543. /package/{scripts/lib → lib/core}/task-source.sh +0 -0
  544. /package/{scripts/lib → lib/core}/toon.sh +0 -0
  545. /package/{scripts/lib → lib/core}/ui.sh +0 -0
  546. /package/{scripts/lib → lib/forge}/forge-none.sh +0 -0
  547. /package/{scripts → lib/verbs}/debug.sh +0 -0
  548. /package/{scripts → lib/verbs}/night-run.test.mjs +0 -0
  549. /package/{scripts/lib → lib/verbs}/upgrade-report.sh +0 -0
package/scripts/init.sh CHANGED
@@ -1,1638 +1,14 @@
1
1
  #!/usr/bin/env bash
2
- # claude-kit init — scaffold a tailored .claude/ into a target project.
3
- # Substitutes {{VARS}} and resolves <!-- IF:FLAG --> blocks from a role profile.
4
- #
5
- # Usage:
6
- # scripts/init.sh [<folder>] [flags] # guided setup: detect, ask, scaffold, git + GitHub
7
- # scripts/init.sh --profile software --no-github # scaffold only, nothing outside the folder
8
- # scripts/init.sh --upgrade --target <dir> # merge new features into an existing setup
9
- #
10
- # Flags (all optional; sensible defaults derived otherwise):
11
- # <folder> | --target <dir> project folder (created when missing) (default: $PWD)
12
- # --no-github scaffold only: no git init, no commit, no GitHub write
13
- # --yes run the git + GitHub setup without asking (required with no terminal)
14
- # --public create the GitHub repository public (default: private)
15
- # --answers <file> JSON {"<question key>":"<answer>"} for the guided questions
16
- # --recipe <id|none> start a NEW project from recipes/<id>.json
17
- # --database <id|none> add the database option databases/<id>.json
18
- # --profile <name> role profile, one of profiles/*.json: software · content · marketing ·
19
- # research · automation · minimal (asked when a terminal or an
20
- # answers file is there; else required unless --upgrade)
21
- # --name <str> human project name (default: target basename)
22
- # --slug <str> short slug / mempalace wing (default: lowercased basename)
23
- # --repo <owner/repo> GitHub repo (default: <owner>/<slug>)
24
- # --owner-login <login> GitHub user/org login (default: forge_rest user)
25
- # --owner-name <str> human owner name (default: owner-login)
26
- # --project-number <int> Projects v2 number (enables board) (default: none -> board off)
27
- # --plans <mdx|markdown|none> plan file format (default: profile default)
28
- # --plans-dir <dir> where plans live (default: per format)
29
- # --memory <on|off> enable MemPalace memory + hooks (default: profile default)
30
- # --speckit <on|off> add the Spec-Driven Development flow (default: off)
31
- # --plain-language <on|off> install the plain-language rule: the agent says draft, review and
32
- # approve, and names git mechanics only when asked (default: profile default)
33
- # --prepush "<command>" install an opt-in pre-push gate that runs <command> before
34
- # `git push` and blocks on failure (default: none -> no gate)
35
- # --local <on|off> local model layer (mlx_lm.server) for NL chores at $0 API cost
36
- # (config + SessionStart status hook) (default: off)
37
- # --lang <str> working language (default: English)
38
- # --adapter <claude|codex|both> which agent adapter(s) to install (default: claude; with
39
- # --upgrade: the stored selection, and a named adapter is ADDED to it)
40
- # --upgrade merge new kit features into an existing .claude/ (preserves your edits)
41
- # --dry-run print the scaffold plan and exit, writing nothing
42
- # --force overwrite without prompting
43
- # The forge port (E537): every GitHub call goes through forge_* / gh_rest_* (scripts/lib/gh-rest.sh).
44
- if ! command -v gh_rest_issue_json >/dev/null 2>&1; then
45
- # shellcheck source=/dev/null
46
- . "$(cd "$(dirname "$0")" && pwd)/lib/gh-rest.sh"
47
- fi
48
-
49
- set -euo pipefail
50
-
51
- # ============================================================================
52
- # TERMINAL IDENTITY — init banner + golden-angle plant animation #
53
- # Canonical brief: the cckit docs ( #
54
- # terminal-identity brief) #
55
- # Sources kit-sigil.sh for palette/mode detection when available. #
56
- # ============================================================================
57
-
58
- # _kit_banner_detect_mode — populate KIT_COLOR, KIT_UNICODE, and palette vars.
59
- # Tries to source the plugin's kit-sigil template (plain bash, no {{VARS}});
60
- # falls back to inline detection if the template is unavailable or fails.
61
- _kit_banner_detect_mode() {
62
- # Try the plugin's sigil template (lives beside this script in the plugin tree)
63
- local _sigil
64
- _sigil="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)/templates/lib/kit-sigil.sh.tmpl"
65
- if [ -f "$_sigil" ]; then
66
- # shellcheck disable=SC1090
67
- if source "$_sigil" 2>/dev/null; then
68
- kit_color_mode 2>/dev/null && return 0
69
- fi
70
- fi
71
- # Inline fallback — matches the logic in kit-sigil.sh exactly.
72
- local _loc="${LC_ALL:-${LC_CTYPE:-${LANG:-}}}"
73
- if [ "${KIT_ASCII:-}" = "1" ]; then
74
- KIT_UNICODE=0
75
- elif grep -qiE 'utf-?8' <<<"$_loc"; then
76
- KIT_UNICODE=1
77
- else
78
- KIT_UNICODE=0
79
- fi
80
- if [ "${FORCE_COLOR:-}" = "1" ]; then
81
- KIT_COLOR=1
82
- elif [ -t 1 ] && [ -z "${NO_COLOR+x}" ]; then
83
- KIT_COLOR=1
84
- else
85
- KIT_COLOR=0
86
- fi
87
- if [ "$KIT_COLOR" = 1 ]; then
88
- KIT_AZAFRAN=$'\033[38;2;201;122;44m'
89
- KIT_INK=$'\033[2m'
90
- KIT_POLVO=$'\033[38;2;168;160;151m'
91
- KIT_RESET=$'\033[0m'
92
- else
93
- KIT_AZAFRAN=''; KIT_INK=''; KIT_POLVO=''; KIT_RESET=''
94
- fi
95
- }
96
-
97
- # _kit_print_static_banner — the V4 box-drawing CLAUDE KIT banner (§7 exact form).
98
- # Always printed: after the animation on TTY, or alone when non-TTY / ASCII mode.
99
- # Reads: KIT_COLOR KIT_UNICODE KIT_AZAFRAN KIT_INK KIT_POLVO KIT_RESET
100
- # Arg 1 (optional): version string, no "v" prefix (e.g. "0.7.0").
101
- _kit_print_static_banner() {
102
- local _ver="${1:-}"
103
- printf '\n'
104
- if [ "${KIT_UNICODE:-0}" = "1" ]; then
105
- # V4 box-drawing letterforms — ink-dim body, single Azafran seed as I-dot of KIT.
106
- # Brief §7 exact layout (three rows of box-drawing, then lockup + tagline):
107
- #
108
- # ┌─┐┬ ┌─┐┬ ┬┌┬┐┌─┐ ┬┌─┬┌┬┐
109
- # │ │ ├─┤│ │ ││├┤ ├┴┐│ │ ● <- Azafran seed (I-dot of KIT)
110
- # └─┘┴─┘┴ ┴└─┘─┴┘└─┘ ┴ ┴┴ ┴
111
- #
112
- # ⡶ / claude-kit agentic workflows for your repo
113
- # v0.7.0 · the seed is planted
114
- printf ' %s%s%s\n' \
115
- "${KIT_INK}" \
116
- '┌─┐┬ ┌─┐┬ ┬┌┬┐┌─┐ ┬┌─┬┌┬┐' \
117
- "${KIT_RESET}"
118
- # Row 2: letterforms + Azafran seed to the right (the I-dot of KIT)
119
- printf ' %s%s%s %s%s%s\n' \
120
- "${KIT_INK}" '│ │ ├─┤│ │ ││├┤ ├┴┐│ │ ' "${KIT_RESET}" \
121
- "${KIT_AZAFRAN}" '●' "${KIT_RESET}"
122
- printf ' %s%s%s\n' \
123
- "${KIT_INK}" \
124
- '└─┘┴─┘┴ ┴└─┘─┴┘└─┘ ┴ ┴┴ ┴' \
125
- "${KIT_RESET}"
126
- printf '\n'
127
- # Lockup line: seed-head leader + wordmark + tagline
128
- printf ' %s%s%s%s%s\n' \
129
- "${KIT_AZAFRAN}" '⡶' "${KIT_RESET}" \
130
- "${KIT_INK}" " / claude-kit agentic workflows for your repo${KIT_RESET}"
131
- if [ -n "$_ver" ]; then
132
- printf ' %s%s%s\n' "${KIT_POLVO}" "v${_ver} · the seed is planted" "${KIT_RESET}"
133
- else
134
- printf ' %s%s%s\n' "${KIT_POLVO}" '· the seed is planted' "${KIT_RESET}"
135
- fi
136
- else
137
- # ASCII fallback — no box-drawing, no Braille (KIT_ASCII=1 or non-UTF-8 locale).
138
- printf ' CLAUDE KIT\n'
139
- printf ' ----------\n'
140
- printf '\n'
141
- printf ' o / claude-kit agentic workflows for your repo\n'
142
- if [ -n "$_ver" ]; then
143
- printf ' v%s . the seed is planted\n' "$_ver"
144
- else
145
- printf ' . the seed is planted\n'
146
- fi
147
- fi
148
- printf '\n'
149
- }
150
-
151
- # _kit_plant_animation — golden-angle Vogel seed-head plant animation (§7 beat 1).
152
- #
153
- # Guard: runs ONLY when stdout is a TTY AND KIT_UNICODE=1 (full Unicode, not ASCII mode).
154
- # Uses ANSI cursor-up to repaint a 4-row Braille grid in-place as seeds enter.
155
- #
156
- # Geometry: n=13, fixed scale, 10x16 dot grid => 5 Braille cols x 4 rows.
157
- # Seed n at angle n*137.50776 deg, radius sqrt(n). Coordinates locked to the
158
- # full n=13 scatter so each seed lands in its final position (no rescaling).
159
- # Pre-computed in Python from the Vogel rule; see brief §2 for derivation.
160
- #
161
- # Animation frames (seeds visible: 1, 2, 4, 7, 13):
162
- # f1 = seed n=0 only (center)
163
- # f2 = seeds n=0,1
164
- # f4 = seeds n=0..3
165
- # f7 = seeds n=0..6
166
- # ff = seeds n=0..12 (full n=13 hero)
167
- #
168
- # Braille rows — each string is 5 Braille chars (U+2800-28FF).
169
- # Row 0 = top, row 3 = bottom. Center seed (n=0) lives at row 1, col 2.
170
- _kit_plant_animation() {
171
- [ -t 1 ] || return 0 # non-TTY: skip, banner will print statically
172
- [ "${KIT_UNICODE:-0}" = "1" ] || return 0 # ASCII mode: skip
173
-
174
- local ind=' ' # indent to align with banner text
175
-
176
- # Frame data — pre-computed Braille rows (5 chars each, 4 rows per frame).
177
- # Stored as positional arrays via function-local vars (portable; no declare -a needed).
178
- # Frame f1: seed n=0 (center seed only)
179
- local f1_0='⠀⠀⠀⠀⠀' f1_1='⠀⠀⢀⠀⠀' f1_2='⠀⠀⠀⠀⠀' f1_3='⠀⠀⠀⠀⠀'
180
- # Frame f2: seeds n=0,1
181
- local f2_0='⠀⠀⠀⠀⠀' f2_1='⠀⠀⢀⠀⠀' f2_2='⠀⠀⠂⠀⠀' f2_3='⠀⠀⠀⠀⠀'
182
- # Frame f4: seeds n=0..3
183
- local f4_0='⠀⠀⠀⠀⠀' f4_1='⠀⠀⢈⠀⠀' f4_2='⠀⠀⠂⠄⠀' f4_3='⠀⠀⠀⠀⠀'
184
- # Frame f7: seeds n=0..6
185
- local f7_0='⠀⠀⠀⠀⠀' f7_1='⠀⠄⢈⠐⠀' f7_2='⠀⠀⠂⠄⠀' f7_3='⠀⠀⠁⠀⠀'
186
- # Frame ff: seeds n=0..12 (full n=13 hero)
187
- local ff_0='⢀⠠⠀⠐⠀' ff_1='⠀⠄⢈⠐⠀' ff_2='⠠⠀⠂⠄⠂' ff_3='⠀⠀⠁⠄⠀'
188
-
189
- # Print one frame: 4 Braille rows in ink-dim.
190
- # Args: row0 row1 row2 row3
191
- _print_frame() {
192
- printf '%s%s%s\n' "${KIT_INK}${ind}" "$1" "${KIT_RESET}"
193
- printf '%s%s%s\n' "${KIT_INK}${ind}" "$2" "${KIT_RESET}"
194
- printf '%s%s%s\n' "${KIT_INK}${ind}" "$3" "${KIT_RESET}"
195
- printf '%s%s%s\n' "${KIT_INK}${ind}" "$4" "${KIT_RESET}"
196
- }
197
-
198
- # Cursor up N lines (ANSI CSI A).
199
- _cur_up() { printf '\033[%dA' "$1"; }
200
-
201
- # Portable fractional sleep — silently ignores if the system only takes integers.
202
- _psleep() { sleep "$1" 2>/dev/null || true; }
203
-
204
- # Print a leading blank line and the first frame (no repaint yet).
205
- printf '\n'
206
- _print_frame "$f1_0" "$f1_1" "$f1_2" "$f1_3"
207
-
208
- # Subsequent frames: cursor-up 4, repaint in-place.
209
- _psleep 0.12
210
- _cur_up 4; _print_frame "$f2_0" "$f2_1" "$f2_2" "$f2_3"
211
-
212
- _psleep 0.12
213
- _cur_up 4; _print_frame "$f4_0" "$f4_1" "$f4_2" "$f4_3"
214
-
215
- _psleep 0.12
216
- _cur_up 4; _print_frame "$f7_0" "$f7_1" "$f7_2" "$f7_3"
217
-
218
- _psleep 0.18
219
- _cur_up 4; _print_frame "$ff_0" "$ff_1" "$ff_2" "$ff_3"
220
-
221
- # Brief pause before the banner snaps in, then clear the animation grid.
222
- _psleep 0.30
223
- # Move up past the 4 grid rows + the blank line printed before the grid (5 lines total),
224
- # then erase from cursor to end of screen so the banner replaces the grid cleanly.
225
- _cur_up 5
226
- printf '\033[J' # CSI J — erase from cursor to end of screen
227
- }
228
-
229
- # _kit_init_banner — entry point for a fresh init run (not --upgrade, not --dry-run).
230
- # Arg 1 (optional): plugin version string without "v" prefix.
231
- _kit_init_banner() {
232
- _kit_banner_detect_mode
233
- _kit_plant_animation # no-op when non-TTY / KIT_ASCII=1 / non-UTF-8
234
- _kit_print_static_banner "${1:-}" # always prints (static or after animation)
235
- }
236
-
237
- # ============================================================================
238
- # END TERMINAL IDENTITY #
239
- # ============================================================================
240
-
241
- KIT_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
242
-
243
- # ---- preflight: run kit-doctor for Tier 1 hard deps (jq, perl, gh, git) ----
244
- # Skip during --upgrade (already initialized) and --dry-run (read-only; doctor
245
- # would be redundant). In interactive runs the doctor auto-installs what it can;
246
- # if Tier 1 deps are still missing after it runs, init exits with a clear report.
247
- _DOCTOR="$KIT_ROOT/scripts/kit-doctor.sh"
248
- _INIT_SKIP_PREFLIGHT=0
249
- for _ia in "$@"; do [[ "$_ia" == "--upgrade" || "$_ia" == "--dry-run" ]] && _INIT_SKIP_PREFLIGHT=1; done
250
- # KIT_INIT_PREFLIGHT=0 skips it too: the fixture tests drive a FRESH init, and the doctor installs
251
- # packages and checks gh auth — neither belongs in a network-free test.
252
- [[ "${KIT_INIT_PREFLIGHT:-1}" == "0" ]] && _INIT_SKIP_PREFLIGHT=1
253
-
254
- if [[ $_INIT_SKIP_PREFLIGHT -eq 0 && -x "$_DOCTOR" ]]; then
255
- # --yes: init's preflight installs Tier-1 deps non-interactively (no approval prompt here; the
256
- # user already opted into setup by running init). A human running `cckit doctor` directly is asked.
257
- bash "$_DOCTOR" --yes || {
258
- echo "" >&2
259
- echo "x kit-doctor reported unresolved issues — fix them and re-run /kit-init." >&2
260
- exit 1
261
- }
262
- else
263
- # Fallback bare checks (upgrade/dry-run path: doctor was already run on init)
264
- command -v jq >/dev/null 2>&1 || { echo "x jq is required." >&2; exit 1; }
265
- command -v perl >/dev/null 2>&1 || { echo "x perl is required." >&2; exit 1; }
266
- fi
267
-
268
- # ---- parse flags ---------------------------------------------------------
269
- _INIT_ARGS=("$@") # as typed — the --upgrade dry run replays them against a copy (#448)
270
- PROFILE=""; TARGET="$PWD"; NAME=""; SLUG=""; REPO=""; GH_OWNER=""; OWNER_NAME=""
271
- PROJECT_NUMBER=""; PLANS_FORMAT=""; PLANS_DIR=""; MEMORY=""; LANG_PREF="English"; FORCE=0
272
- PLAIN_LANGUAGE=""
273
- TASKS_DEFAULT="" # light | issues — the profile's defaults.tasks; on --upgrade, the stored tasks.default
274
- SPECKIT=""; PREPUSH_CMD=""; LOCAL_LAYER=""; LOCAL_EXPLICIT=0; DRY_RUN=0; UPGRADE=0
275
- ADAPTER_ARG="" # --adapter as typed; resolved to ADAPTERS below (stored selection wins on upgrade)
276
- # Guided setup (#456): the folder as typed, the git + GitHub steps, the advisor's answers.
277
- FOLDER_GIVEN=0; NO_GITHUB=0; ASSUME_YES=0; REPO_VISIBILITY="private"; INIT_ANSWERS=""
278
- RECIPE_ARG=""; DATABASE_ARG=""
279
- SKILL_PREFIX="" # namespace applied to kit-namespaced skill templates (from kit.config .skillPrefix on upgrade)
280
- while [[ $# -gt 0 ]]; do
281
- case "$1" in
282
- --profile) PROFILE="$2"; shift 2 ;;
283
- --target) TARGET="$2"; FOLDER_GIVEN=1; shift 2 ;;
284
- --name) NAME="$2"; shift 2 ;;
285
- --slug) SLUG="$2"; shift 2 ;;
286
- --repo) REPO="$2"; shift 2 ;;
287
- --owner-login) GH_OWNER="$2"; shift 2 ;;
288
- --owner-name) OWNER_NAME="$2"; shift 2 ;;
289
- --project-number) PROJECT_NUMBER="$2"; shift 2 ;;
290
- --plans) PLANS_FORMAT="$2"; shift 2 ;;
291
- --plans-dir) PLANS_DIR="$2"; shift 2 ;;
292
- --memory) MEMORY="$2"; shift 2 ;;
293
- --speckit) SPECKIT="$2"; shift 2 ;;
294
- --plain-language) PLAIN_LANGUAGE="$2"; shift 2 ;;
295
- --prepush) PREPUSH_CMD="$2"; shift 2 ;;
296
- --local) LOCAL_LAYER="$2"; LOCAL_EXPLICIT=1; shift 2 ;;
297
- --lang) LANG_PREF="$2"; shift 2 ;;
298
- --force) FORCE=1; shift ;;
299
- --upgrade) UPGRADE=1; shift ;;
300
- --dry-run) DRY_RUN=1; shift ;;
301
- --adapter) ADAPTER_ARG="$2"; shift 2 ;;
302
- --no-github) NO_GITHUB=1; shift ;;
303
- --yes|-y) ASSUME_YES=1; shift ;;
304
- --public) REPO_VISIBILITY="public"; shift ;;
305
- --answers) INIT_ANSWERS="$2"; shift 2 ;;
306
- --recipe) RECIPE_ARG="$2"; shift 2 ;;
307
- --database) DATABASE_ARG="$2"; shift 2 ;;
308
- -h|--help) sed -n '2,42p' "$0"; exit 0 ;;
309
- -*) echo "x unknown flag: $1" >&2; exit 1 ;;
310
- *) if [[ $FOLDER_GIVEN -eq 1 ]]; then echo "x one folder only (got '$TARGET' and '$1')" >&2; exit 1; fi
311
- TARGET="$1"; FOLDER_GIVEN=1; shift ;;
312
- esac
313
- done
314
-
315
- # ---- adapter selection (E257.3) -------------------------------------------
316
- # Validated here, before anything is written: an unknown adapter name refuses the whole run.
317
- # shellcheck source=/dev/null
318
- . "$KIT_ROOT/scripts/lib/adapter-select.sh"
319
- ADAPTERS_NEW=""
320
- if [[ -n "$ADAPTER_ARG" ]]; then
321
- ADAPTERS_NEW="$(adapter_normalize "$ADAPTER_ARG")" || { echo "x --adapter takes claude, codex or both (got '$ADAPTER_ARG')" >&2; exit 1; }
322
- fi
323
- ADAPTERS="${ADAPTERS_NEW:-claude}" # fresh init; --upgrade replaces this with the stored selection
324
- ADAPTER_ADDED=0
325
-
326
- # ---- guided setup: name the folder, ask what is missing (#456) -------------
327
- # Before anything is written. `--upgrade` never enters it: an upgrade works on a project that is
328
- # already set up and asks nothing.
329
- # shellcheck source=/dev/null
330
- . "$KIT_ROOT/scripts/lib/init-guide.sh"
331
- # shellcheck source=/dev/null
332
- . "$KIT_ROOT/scripts/lib/init-github.sh"
333
- INIT_CLASS=""; INIT_NEW=0; INIT_ALREADY=0; RECIPE_FILE=""; DB_FILE=""; DB_STACK=""; SETUP_RUN=0
334
- if [[ $UPGRADE -eq 0 ]]; then
335
- if [[ -n "$INIT_ANSWERS" && ! -f "$INIT_ANSWERS" ]]; then echo "x --answers: no such file: $INIT_ANSWERS" >&2; exit 2; fi
336
- if [[ -n "$INIT_ANSWERS" ]] && ! jq -e 'type == "object"' "$INIT_ANSWERS" >/dev/null 2>&1; then
337
- echo "x --answers: $INIT_ANSWERS is not a JSON object of {\"question\": \"answer\"}" >&2; exit 2
338
- fi
339
- init_guide_resolve
340
- fi
341
-
342
- # Installed plugin version -> recorded into kit.config as kitVersion (drives /kit-update checks).
343
- PLUGIN_VERSION="$(jq -r '.version // "0.0.0"' "$KIT_ROOT/.claude-plugin/plugin.json" 2>/dev/null || echo "0.0.0")"
344
-
345
- # ---- upgrade mode: backfill inputs from the project's existing config ----
346
- if [[ $UPGRADE -eq 1 ]]; then
347
- UP_TARGET="$(cd "${TARGET:-$PWD}" && pwd)"
348
- UP_CFG="$(adapter_config_existing "$UP_TARGET" || true)"
349
- [[ -n "$UP_CFG" && -f "$UP_CFG" ]] || { echo "x --upgrade needs $UP_TARGET/.claude/kit.config.json (run /kit-init first)."; exit 1; }
350
- # The stored selection is the truth on upgrade. --adapter only ever ADDS to it: dropping an
351
- # adapter is an uninstall of its files, which is `cckit remove`'s job, not an upgrade side effect.
352
- ADAPTERS_HAVE="$(adapter_list_from_config "$UP_CFG")" || { echo "x $UP_CFG has an invalid 'adapters' value (expected claude and/or codex)." >&2; exit 1; }
353
- ADAPTERS="$(adapter_union "$ADAPTERS_HAVE" "$ADAPTERS_NEW")"
354
- [[ "$ADAPTERS" != "$ADAPTERS_HAVE" ]] && ADAPTER_ADDED=1
355
-
356
- # ---- guard: never apply the kit over its OWN home, or downgrade ----------
357
- # The kit is DEVELOPED in-tree in its home repo (packages/claude-kit-plugin/). Running
358
- # --upgrade there would copy the installed (usually OLDER) plugin snapshot over the live
359
- # source — the recurring "every time I improve the kit, /kit-update fights me" footgun.
360
- # Refuse cleanly (exit 0, not an error) so the home repo edits the source directly.
361
- if [[ -f "$UP_TARGET/packages/claude-kit-plugin/.claude-plugin/plugin.json" ]]; then
362
- echo "x $UP_TARGET is claude-kit's home repo -- edit packages/claude-kit-plugin/ directly; /kit-update is for consumer projects, not the kit's source."
363
- exit 0
364
- fi
365
- # Nothing to do when the installed plugin is the SAME version as the project (avoids the
366
- # confusing re-scan + any stray re-add). A genuinely-behind consumer (kitVersion < plugin)
367
- # still upgrades normally.
368
- _have_kv="$(jq -r '.kitVersion // "0.0.0"' "$UP_CFG" 2>/dev/null || echo 0.0.0)"
369
- # ...unless this run enables a second adapter: that is new work at the same version. So is a
370
- # Codex project whose hooks are not registered (a hooks.json that was unparseable at init, or a
371
- # project scaffolded before E257.5): `cckit doctor` sends the user here to repair exactly that.
372
- _cx_unregistered=0
373
- if adapter_has "$ADAPTERS" codex; then
374
- # shellcheck source=/dev/null
375
- . "$KIT_ROOT/scripts/lib/codex-hooks.sh"
376
- codex_hooks_registered "$UP_TARGET/.codex/hooks.json" guard-base-branch-commit.sh || _cx_unregistered=1
377
- fi
378
- if [[ "$_have_kv" == "$PLUGIN_VERSION" && $ADAPTER_ADDED -eq 0 && $_cx_unregistered -eq 0 ]]; then
379
- echo "x already at $PLUGIN_VERSION -- nothing to upgrade. (To pull a newer release, refresh the plugin cache: claude plugin update.)"
380
- exit 0
381
- fi
382
-
383
- [[ -z "$PROFILE" ]] && PROFILE="$(jq -r '.profile // "minimal"' "$UP_CFG")"
384
- [[ -z "$NAME" ]] && NAME="$(jq -r '.project.name // ""' "$UP_CFG")"
385
- [[ -z "$SLUG" ]] && SLUG="$(jq -r '.project.slug // ""' "$UP_CFG")"
386
- [[ -z "$REPO" ]] && REPO="$(jq -r '.github.repo // ""' "$UP_CFG")"
387
- [[ -z "$GH_OWNER" ]] && GH_OWNER="$(jq -r '.github.owner // ""' "$UP_CFG")"
388
- [[ -z "$MEMORY" ]] && MEMORY="$(jq -r 'if .memory.enabled then "on" else "off" end' "$UP_CFG")"
389
- [[ -z "$SPECKIT" ]] && SPECKIT="$(jq -r 'if (.specKit.enabled // false) then "on" else "off" end' "$UP_CFG")"
390
- [[ -z "$LOCAL_LAYER" ]] && LOCAL_LAYER="$(jq -r 'if (.local.enabled // false) then "on" else "off" end' "$UP_CFG")"
391
- # The stored switch is the truth on upgrade: a project that turned plain language off keeps it
392
- # off whatever its profile defaults to.
393
- [[ -z "$PLAIN_LANGUAGE" ]] && PLAIN_LANGUAGE="$(jq -r 'if (.plainLanguage.enabled // false) then "on" else "off" end' "$UP_CFG")"
394
- # Same for the default task list: the project's tasks.default, never the profile default.
395
- TASKS_DEFAULT="$(jq -r '.tasks.default // "issues"' "$UP_CFG")"
396
- # A config with NO plans key at all deliberately runs without plan files — upgrade must not
397
- # resurrect the profile default (and with it the plans rule + config block) (#149).
398
- [[ -z "$PLANS_FORMAT" ]] && PLANS_FORMAT="$(jq -r 'if has("plans") then (.plans.format // "") else "none" end' "$UP_CFG")"
399
- [[ "$LANG_PREF" == "English" ]] && LANG_PREF="$(jq -r '.project.language // "English"' "$UP_CFG")"
400
- # Skill-name prefix: projects that namespace their kit skills (e.g. "kit-task-close") set
401
- # `skillPrefix` so upgrade scaffolds namespaced templates to the matching name instead of
402
- # creating bare-name duplicates. Empty = bare names (default).
403
- [[ -z "$SKILL_PREFIX" ]] && SKILL_PREFIX="$(jq -r '.skillPrefix // ""' "$UP_CFG")"
404
- _UPNUM="$(jq -r '.github.projectNumber // empty' "$UP_CFG")"
405
- [[ -z "$PROJECT_NUMBER" && -n "$_UPNUM" && "$_UPNUM" != "null" ]] && PROJECT_NUMBER="$_UPNUM"
406
- _UPPP="$(jq -r '.prePush.command // ""' "$UP_CFG")"
407
- [[ -z "$PREPUSH_CMD" && -n "$_UPPP" && "$_UPPP" != "null" ]] && PREPUSH_CMD="$_UPPP"
408
-
409
- # ---- upgrade exclusion registry (#334) ----------------------------------
410
- # `upgrade.removed[]` + keys of `upgrade.renamed{}` are paths the project
411
- # deleted/renamed ON PURPOSE. The upgrade must never re-add them ("add missing
412
- # files" doesn't know the project's deliberate state). Read from the EXISTING
413
- # config (pre-merge) into a newline-delimited list consumed by _upgrade_excluded.
414
- UPGRADE_EXCLUDE="$(jq -r '((.upgrade.removed // []) + ((.upgrade.renamed // {}) | keys)) | .[]' "$UP_CFG" 2>/dev/null || true)"
415
-
416
- # ---- dirty working tree guard (upgrade mode only) -----------------------
417
- # Refuse to write files into a project with uncommitted changes.
418
- # Safe no-op when git is unavailable or UP_TARGET is not a git repo.
419
- # Pass --force to skip at your own risk.
420
- if [[ $DRY_RUN -eq 0 && $FORCE -eq 0 ]]; then
421
- if git -C "$UP_TARGET" rev-parse --git-dir >/dev/null 2>&1; then
422
- _dirty="$(git -C "$UP_TARGET" status --porcelain 2>/dev/null || true)"
423
- if [[ -n "$_dirty" ]]; then
424
- echo "x working tree is dirty -- commit, stash, or discard before running /kit-update" >&2
425
- echo " (pass --force to override at your own risk)" >&2
426
- exit 1
427
- fi
428
- fi
429
- fi
430
- fi
431
-
432
- # The profile names come from profiles/*.json, so a profile added there is offered here.
433
- _PROFILE_NAMES="$(for _pf in "$KIT_ROOT"/profiles/*.json; do [[ -f "$_pf" ]] && basename "$_pf" .json; done | paste -sd '|' -)"
434
- [[ -z "$PROFILE" ]] && { echo "x --profile is required ($_PROFILE_NAMES)"; exit 1; }
435
- PROFILE_FILE="$KIT_ROOT/profiles/$PROFILE.json"
436
- [[ -f "$PROFILE_FILE" ]] || { echo "x no such profile: $PROFILE — one of: $_PROFILE_NAMES"; exit 1; }
437
-
438
- # ---- resolve target + defaults ------------------------------------------
439
- # A folder that is not there yet is created when the first file is written, not here: a dry run
440
- # and a declined confirmation leave nothing behind (#456).
441
- if [[ -d "$TARGET" ]]; then TARGET="$(cd "$TARGET" && pwd)"; else TARGET="$(init_abs_path "$TARGET")"; fi
442
- BASENAME="$(basename "$TARGET")"
443
- # Prefer the ACTUAL repo name from the git remote — the local directory is often cloned/renamed to a
444
- # different name — and only fall back to the directory basename (#73).
445
- # shellcheck source=/dev/null
446
- . "$KIT_ROOT/scripts/lib/git-remote.sh"
447
- # shellcheck source=/dev/null
448
- . "$KIT_ROOT/scripts/lib/hook-refresh.sh" # hook_refresh_state — refresh unmodified hooks (#370)
449
- # shellcheck source=/dev/null
450
- . "$KIT_ROOT/scripts/lib/upgrade-report.sh" # measured change list + minimal JSON writes (#448)
451
- NAME_SRC="$(git_remote_repo_name "$TARGET" 2>/dev/null || true)"; NAME_SRC="${NAME_SRC:-$BASENAME}"
452
- [[ -z "$NAME" ]] && NAME="$NAME_SRC"
453
- [[ -z "$SLUG" ]] && SLUG="$(echo "$NAME_SRC" | tr '[:upper:]' '[:lower:]' | tr -cs 'a-z0-9' '-' | sed -E 's/^-|-$//g')"
454
- if [[ -z "$GH_OWNER" ]]; then GH_OWNER="$(forge_rest user --jq .login 2>/dev/null || echo "")"; fi
455
- [[ -z "$OWNER_NAME" ]] && OWNER_NAME="${GH_OWNER:-owner}"
456
- # Prefer the project's ACTUAL GitHub remote over an <owner>/<dir-basename> guess — the local
457
- # directory name often differs from the repo name (would target a non-existent repo otherwise).
458
- if [[ -z "$REPO" && $INIT_ALREADY -eq 1 ]]; then
459
- REPO="$(jq -r '.github.repo // empty' "$(adapter_config_existing "$TARGET")" 2>/dev/null || true)"
460
- fi
461
- [[ -z "$REPO" ]] && REPO="$(forge_repo_from_git "$TARGET" 2>/dev/null || true)"
462
- [[ -z "$REPO" && -n "$GH_OWNER" ]] && REPO="$GH_OWNER/$SLUG"
463
- [[ -z "$REPO" ]] && REPO="$SLUG"
464
-
465
- # ---- base branch ---------------------------------------------------------
466
- # Rules that name the integration branch are TEMPLATED on it ({{BASE_BRANCH}}), so a project that
467
- # integrates on `develop` does not scaffold a rule telling agents to branch from `main` (#283).
468
- # Resolved the same way the rest of the kit resolves it (kit-config.sh: baseBranch -> integrationBranch
469
- # -> flow -> "main"), then WRITTEN into the generated config below — a rendered rule that disagrees
470
- # with KIT_BASE_BRANCH is the bug this parameterization exists to remove.
471
- # 1. KIT_BASE_BRANCH from the environment (an explicit caller override)
472
- # 2. the project's existing config, found by kit_config_path (re-init / --upgrade keeps the
473
- # project's choice) — the ONE resolver, so this honors $KIT_CONFIG and finds a config in an
474
- # ancestor directory. Hand-checking two TARGET-local filenames skipped both.
475
- # 3. the repo's actual GitHub default branch (same source as REPO/GH_OWNER above)
476
- # 4. "main"
477
- # Unconditional, not `[[ -z ${BASE_BRANCH:-} ]]`: KIT_BASE_BRANCH is the DOCUMENTED override, and
478
- # BASE_BRANCH is an internal name this script exports for `emit` — an inherited BASE_BRANCH from a
479
- # caller's environment must not silently outrank it.
480
- BASE_BRANCH="${KIT_BASE_BRANCH:-}"
481
- if [[ -z "$BASE_BRANCH" ]]; then
482
- # shellcheck source=/dev/null
483
- . "$KIT_ROOT/scripts/lib/config-path.sh"
484
- _bb_cfg="$(kit_config_path "$TARGET" 2>/dev/null || true)"
485
- if [[ -n "$_bb_cfg" && -f "$_bb_cfg" ]]; then
486
- BASE_BRANCH="$(jq -r '.github.baseBranch // .github.integrationBranch // .github.flow // empty' "$_bb_cfg" 2>/dev/null || true)"
487
- fi
488
- fi
489
- [[ -z "$BASE_BRANCH" && "$REPO" == */* ]] && BASE_BRANCH="$(gh_rest_repo_default_branch "$REPO" 2>/dev/null || true)"
490
- # The git + GitHub setup (#456) runs when it is wanted AND confirmed: --yes, or a terminal to ask
491
- # on. A dry run plans as if it were confirmed. A project with no `origin` remote that the setup is
492
- # about to give a repository integrates on `develop` (main stays the release branch).
493
- SETUP_WANTED=0; SETUP_BASE_CHOSEN=0
494
- if [[ $UPGRADE -eq 0 && $NO_GITHUB -eq 0 ]] && { [[ $ASSUME_YES -eq 1 || $DRY_RUN -eq 1 ]] || _ig_tty; }; then
495
- SETUP_WANTED=1
496
- fi
497
- if [[ -z "$BASE_BRANCH" && $SETUP_WANTED -eq 1 ]] && [[ -z "$(git -C "$TARGET" remote get-url origin 2>/dev/null || true)" ]]; then
498
- BASE_BRANCH="develop"; SETUP_BASE_CHOSEN=1
499
- fi
500
- # No setup, no remote default, no config: `main` when the repository has it (or has no commit yet),
501
- # else the branch that is checked out — a base branch the repository does not have stops the first
502
- # `cckit start` / `cckit task start` (#487).
503
- _init_fallback_base() {
504
- local cur
505
- if git -C "$TARGET" rev-parse --verify -q HEAD >/dev/null 2>&1 \
506
- && ! git -C "$TARGET" show-ref --verify -q refs/heads/main \
507
- && ! git -C "$TARGET" show-ref --verify -q refs/remotes/origin/main; then
508
- cur="$(git -C "$TARGET" symbolic-ref --short -q HEAD 2>/dev/null || true)"
509
- if [[ -n "$cur" ]]; then printf '%s' "$cur"; return 0; fi
510
- fi
511
- printf 'main'
512
- }
513
- [[ -z "$BASE_BRANCH" ]] && BASE_BRANCH="$(_init_fallback_base)"
514
-
515
- # profile defaults
516
- [[ -z "$PLANS_FORMAT" ]] && PLANS_FORMAT="$(jq -r '.defaults.plans_format' "$PROFILE_FILE")"
517
- [[ -z "$MEMORY" ]] && MEMORY="$(jq -r '.defaults.memory' "$PROFILE_FILE")"
518
- [[ -z "$SPECKIT" ]] && SPECKIT="$(jq -r '.defaults.speckit // "off"' "$PROFILE_FILE")"
519
- [[ -z "$LOCAL_LAYER" ]] && LOCAL_LAYER="$(jq -r '.defaults.local // "off"' "$PROFILE_FILE")"
520
- # Content work (E415). Profile defaults only — no flag: a project changes them in its config.
521
- # content_kinds on -> kinds.content: true (setup-labels.sh provisions the content kind labels)
522
- CONTENT_KINDS="$(jq -r '.defaults.content_kinds // "off"' "$PROFILE_FILE")"
523
- # pr_body content -> pr.bodyStyle: "content" (draft-and-review wording in generated PR bodies)
524
- case "$CONTENT_KINDS" in on|true|yes) CONTENT_KINDS_ON="true";; *) CONTENT_KINDS_ON="false";; esac
525
- # plain_language on -> plainLanguage.enabled: true + the plain-language rule (--plain-language wins)
526
- PR_BODY_STYLE="$(jq -r '.defaults.pr_body // "code"' "$PROFILE_FILE")"
527
- [[ -z "$PLAIN_LANGUAGE" ]] && PLAIN_LANGUAGE="$(jq -r '.defaults.plain_language // "off"' "$PROFILE_FILE")"
528
- case "$PLAIN_LANGUAGE" in on|true|yes) PLAIN_ON="true";; *) PLAIN_ON="false";; esac
529
- # tasks light -> tasks.default: "light" (a bare `cckit next` answers from `cckit task`)
530
- [[ -z "$TASKS_DEFAULT" ]] && TASKS_DEFAULT="$(jq -r '.defaults.tasks // "issues"' "$PROFILE_FILE")"
531
- [[ "$TASKS_DEFAULT" == "light" ]] || TASKS_DEFAULT="issues"
532
- [[ "$PR_BODY_STYLE" == "content" ]] || PR_BODY_STYLE="code"
533
- if [[ -z "$PLANS_DIR" ]]; then
534
- case "$PLANS_FORMAT" in
535
- mdx) PLANS_DIR="apps/plans/src/briefs" ;;
536
- *) PLANS_DIR="docs/plans" ;;
537
- esac
538
- fi
539
-
540
- # arrays from profile
541
- ROLES_NL="$(jq -r '.roles[]' "$PROFILE_FILE")"
542
- MS_NL="$(jq -r '.milestones[]' "$PROFILE_FILE")"
543
- AGENTS="$(jq -r '.agents[]' "$PROFILE_FILE")"
544
- SKILLS="$(jq -r '.skills[]' "$PROFILE_FILE")"
545
- # page-design (#504) is installed wherever pages are designed: a profile that lists it (marketing),
546
- # a recipe whose config sets `tasks.design: true` (nextjs-shadcn), or, on --upgrade, a project
547
- # config that holds that key. One switch, so the skill and the page-task rule of `cckit task run`
548
- # cannot disagree.
549
- DESIGN_SKILL_ON=""
550
- if [[ -n "$RECIPE_FILE" ]]; then DESIGN_SKILL_ON="$(jq -r '.config.tasks.design // empty' "$RECIPE_FILE" 2>/dev/null || true)"; fi
551
- if [[ $UPGRADE -eq 1 && -n "${UP_CFG:-}" && -f "${UP_CFG:-}" ]]; then DESIGN_SKILL_ON="$(jq -r '.tasks.design // empty' "$UP_CFG" 2>/dev/null || true)"; fi
552
- if [[ "$DESIGN_SKILL_ON" == "true" ]] && ! grep -qx "page-design" <<<"$SKILLS"; then
553
- SKILLS="$SKILLS
554
- page-design"
555
- fi
556
- RULES="$(jq -r '.rules[]' "$PROFILE_FILE")"
557
-
558
- # Kit-namespaced skill set: templates whose names take $SKILL_PREFIX (the workflow skills:
559
- # task-*, effort-*). Content skills (morning-briefing, karpathy-…) are NOT listed and stay bare.
560
- # Listed in templates/skills/NAMESPACED (one name per line) so the marker lives outside the artifact.
561
- NAMESPACED_SKILLS="$(grep -vE '^\s*(#|$)' "$KIT_ROOT/templates/skills/NAMESPACED" 2>/dev/null || true)"
562
- _is_namespaced() { # <skill-name> -> 0 if it takes the prefix
563
- grep -qxF "$1" <<<"$NAMESPACED_SKILLS"
564
- }
565
- # Rewrite a freshly-scaffolded namespaced skill so its own name: + sibling /command refs + sigil
566
- # label carry $SKILL_PREFIX (template ships bare; the project namespaces). The (?![\w-]) guard stops
567
- # /task-pr matching inside /task-pr-merge. perl is a Tier-1 dep (kit-doctor).
568
- _prefix_skill_file() { # <file>
569
- local f="$1" n
570
- printf '%s\n' "$NAMESPACED_SKILLS" | while IFS= read -r n; do
571
- [[ -n "$n" ]] || continue
572
- P="$SKILL_PREFIX" N="$n" perl -i -pe '
573
- my ($p,$n)=($ENV{P},$ENV{N});
574
- s{^name:\h*\Q$n\E\h*$}{name: $p$n};
575
- s{/\Q$n\E(?![\w-])}{/$p$n}g;
576
- s{kit_sigil "\Q$n\E"}{kit_sigil "$p$n"}g;
577
- ' "$f"
578
- done
579
- }
580
-
581
- ROLES_JSON="$(printf '%s' "$ROLES_NL" | jq -Rs 'split("\n")|map(select(length>0))')"
582
- MS_JSON="$(printf '%s' "$MS_NL" | jq -Rs 'split("\n")|map(select(length>0))')"
583
- ROLES_HUMAN="$(printf '%s' "$ROLES_NL" | paste -sd '·' - | sed 's/·/ · /g')"
584
- MILESTONES_HUMAN="$(printf '%s' "$MS_NL" | paste -sd '·' - | sed 's/·/ · /g')"
585
-
586
- # flags / booleans
587
- if [[ -n "$PROJECT_NUMBER" ]]; then PROJECTS_V2="true"; PNUM_JSON="$PROJECT_NUMBER"; else PROJECTS_V2="false"; PNUM_JSON="null"; PROJECT_NUMBER="null"; fi
588
- case "$MEMORY" in on|true|yes) MEMORY_BOOL="true";; *) MEMORY_BOOL="false";; esac
589
- if [[ "$PLANS_FORMAT" == "none" ]]; then PLANS_ON="false"; else PLANS_ON="true"; fi
590
- if grep -qx "Designer" <<<"$ROLES_NL"; then DESIGN_ON="true"; else DESIGN_ON="false"; fi
591
- CLAUDE_PROJECT_SLUG="$(echo "$TARGET" | sed 's#/#-#g')"
592
-
593
- # spec kit
594
- case "$SPECKIT" in on|true|yes) SPECKIT_ON="true";; *) SPECKIT_ON="false";; esac
595
- SPECKIT_JSON="$SPECKIT_ON"
596
-
597
- # pre-push gate (opt-in: enabled when a check command is provided)
598
- if [[ -n "$PREPUSH_CMD" ]]; then PREPUSH_ENABLED="true"; else PREPUSH_ENABLED="false"; fi
599
-
600
- # local model layer (opt-in: mlx_lm.server for NL chores)
601
- case "$LOCAL_LAYER" in on|true|yes) LOCAL_ON="true";; *) LOCAL_ON="false";; esac
602
-
603
- # stack-gated build skills present in this profile?
604
- if grep -qE '^(feature-build-refine|supabase-patterns)$' <<<"$SKILLS"; then STACK_SKILLS_ON="true"; else STACK_SKILLS_ON="false"; fi
605
-
606
- # code graph (an integration, switched on by `cckit add <id>` — never by an init flag). A fresh
607
- # scaffold therefore has it off; only --upgrade can find it on, in the project's existing config.
608
- CODEGRAPH_ON="false"
609
- if [[ $UPGRADE -eq 1 ]]; then
610
- _cg="$(jq -r '.codeGraph.provider // ""' "$UP_CFG" 2>/dev/null || true)"
611
- [[ -n "$_cg" && "$_cg" != "none" ]] && CODEGRAPH_ON="true"
612
- fi
613
-
614
- # FLAGS_ON drives <!-- IF:X --> resolution
615
- FLAGS_ON=""
616
- [[ "$MEMORY_BOOL" == "true" ]] && FLAGS_ON="${FLAGS_ON}MEMORY,"
617
- [[ "$PROJECTS_V2" == "true" ]] && FLAGS_ON="${FLAGS_ON}PROJECTS_V2,"
618
- [[ "$PLANS_ON" == "true" ]] && FLAGS_ON="${FLAGS_ON}PLANS,"
619
- [[ "$DESIGN_ON" == "true" ]] && FLAGS_ON="${FLAGS_ON}DESIGN,"
620
- [[ "$SPECKIT_ON" == "true" ]] && FLAGS_ON="${FLAGS_ON}SPECKIT,"
621
- [[ "$STACK_SKILLS_ON" == "true" ]] && FLAGS_ON="${FLAGS_ON}STACK_SKILLS,"
622
- [[ "$CODEGRAPH_ON" == "true" ]] && FLAGS_ON="${FLAGS_ON}CODEGRAPH,"
623
- [[ "$TASKS_DEFAULT" == "light" ]] && FLAGS_ON="${FLAGS_ON}LIGHT_TASKS,"
624
- # The counterpart, so the instruction file can say "GitHub issues are the task list" only where
625
- # that is true (#487).
626
- [[ "$TASKS_DEFAULT" == "light" ]] || FLAGS_ON="${FLAGS_ON}ISSUE_TASKS,"
627
-
628
- # ---- build agent/skill tables -------------------------------------------
629
- # short_desc <file> -> the frontmatter description, at most 92 characters. A folded or literal
630
- # block (`description: >` with the text on the indented lines below it) is joined into one line;
631
- # the old one-line read printed the `>` itself in the skills table (#487).
632
- short_desc() {
633
- awk '
634
- /^---[[:space:]]*$/ { fm++; if (fm == 2) exit; next }
635
- fm != 1 { next }
636
- inblock {
637
- if ($0 ~ /^[[:space:]]+[^[:space:]]/) { t = $0; sub(/^[[:space:]]+/, "", t); sub(/[[:space:]]+$/, "", t); out = out (out == "" ? "" : " ") t; next }
638
- if ($0 ~ /^[[:space:]]*$/) next
639
- inblock = 0
640
- }
641
- /^description:/ && !seen {
642
- seen = 1; v = $0; sub(/^description:[[:space:]]*/, "", v); sub(/[[:space:]]+$/, "", v)
643
- if (v == "" || v ~ /^[>|][+-]?$/) { inblock = 1 } else { out = v }
644
- }
645
- END { print out }' "$1" | cut -c1-92
646
- }
647
- AGENT_TABLE="| Agent | Role |
648
- | ----- | ---- |"
649
- for a in $AGENTS; do
650
- f="$KIT_ROOT/templates/agents/$a.md"
651
- [[ -f "$f" ]] || { echo " missing agent template: $a" >&2; continue; }
652
- AGENT_TABLE="$AGENT_TABLE
653
- | \`$a\` | $(short_desc "$f") |"
654
- done
655
- SKILL_TABLE="| Skill | When |
656
- | ----- | ---- |"
657
- for s in $SKILLS; do
658
- f="$KIT_ROOT/templates/skills/$s/SKILL.md"
659
- [[ -f "$f" ]] || { echo " missing skill template: $s" >&2; continue; }
660
- SKILL_TABLE="$SKILL_TABLE
661
- | \`$s\` | $(short_desc "$f") |"
662
- done
663
-
664
- # ---- export vars for substitution ---------------------------------------
665
- export PROJECT_NAME="$NAME" PROJECT_SLUG="$SLUG" OWNER_NAME="$OWNER_NAME" COMMS_LANG="$LANG_PREF"
666
- export PROFILE GH_REPO="$REPO" GH_OWNER="$GH_OWNER" PROJECT_NUMBER PROJECT_BOARD_TITLE="$NAME"
667
- export BASE_BRANCH
668
- export PLANS_DIR PLANS_FORMAT KNOWLEDGE_DIR="knowledge" WING="$SLUG" CLAUDE_PROJECT_SLUG
669
- export MILESTONES_HUMAN ROLES_HUMAN AGENT_TABLE SKILL_TABLE
670
- export KIT_FLAGS_ON="$FLAGS_ON"
671
-
672
- # ---- per-adapter layout --------------------------------------------------
673
- # One template set renders for both adapters. What differs is where the files land ({{ADAPTER_DIR}}),
674
- # which IF:ADAPTER_* blocks survive, and the instruction file name — nothing else.
675
- KITCFG="$(adapter_config_existing "$TARGET" || true)"
676
- [[ -n "$KITCFG" ]] || KITCFG="$(adapter_config_default "$TARGET" "$ADAPTERS")"
677
- CONFIG_REL="${KITCFG#"$TARGET"/}"
678
- MANIFEST_REL="$(adapter_manifest_rel "$TARGET" "$ADAPTERS")"
679
- export CONFIG_REL
680
- _rule_enabled() { # <rule> -> 0 unless its feature is off for this project
681
- case "$1" in
682
- mempalace) [[ "$MEMORY_BOOL" == "true" ]] || return 1 ;;
683
- design-routing) [[ "$DESIGN_ON" == "true" ]] || return 1 ;;
684
- plan-output-format) [[ "$PLANS_ON" == "true" ]] || return 1 ;;
685
- plain-language) [[ "$PLAIN_ON" == "true" ]] || return 1 ;;
686
- esac
687
- return 0
688
- }
689
- # The plain-language rule follows its switch, not the profile list: a profile that lists it gets it
690
- # only while the switch is on, and `--plain-language on` adds it to a profile that does not list it.
691
- if [[ "$PLAIN_ON" == "true" ]] && ! grep -qx 'plain-language' <<<"$RULES"; then
692
- RULES="$RULES
693
- plain-language"
694
- fi
695
- RULE_LIST=""
696
- for r in $RULES; do
697
- _rule_enabled "$r" && [[ -f "$KIT_ROOT/templates/rules/$r.md" ]] || continue
698
- RULE_LIST="${RULE_LIST:+$RULE_LIST
699
- }- \`.agents/rules/$r.md\`"
700
- done
701
- export RULE_LIST
702
- use_adapter() { # <claude|codex> — point emit at that adapter's dir + IF blocks
703
- ADAPTER_DIR="$(adapter_dir "$1")"
704
- KIT_FLAGS_ON="${FLAGS_ON}ADAPTER_$(printf '%s' "$1" | tr '[:lower:]' '[:upper:]'),"
705
- ADAPTER_INSTRUCTIONS="$(adapter_instructions "$1")"
706
- export ADAPTER_DIR KIT_FLAGS_ON ADAPTER_INSTRUCTIONS
707
- }
708
- # Shared (adapter-neutral) files that name a rules path point at the first selected adapter's copy.
709
- use_adapter "${ADAPTERS%% *}"
710
-
711
- # emit: resolve IF blocks, then substitute {{VARS}}
712
- render_tpl() { # <src> -> stdout
713
- perl -0777 -pe '
714
- my %on = map { $_=>1 } grep { length } split /,/, ($ENV{KIT_FLAGS_ON}//"");
715
- 1 while s{<!-- IF:(\w+) -->(.*?)<!-- /IF:\1 -->}{ $on{$1} ? $2 : "" }gse;
716
- s/\{\{(\w+)\}\}/ exists $ENV{$1} ? $ENV{$1} : "{{$1}}" /ge;
717
- ' "$1"
718
- }
719
- emit() { # <src> <dest>
720
- mkdir -p "$(dirname "$2")"
721
- render_tpl "$1" > "$2"
722
- WRITTEN+=("${2#"$TARGET"/}")
723
- }
724
- WRITTEN=() # every path this run wrote (not preserved) — the adapter-managed ones go in the manifest
725
-
726
- # _upgrade_excluded: true when <rel> was removed/renamed by the project on purpose
727
- # (registered in kit.config.json `upgrade.removed[]` / `upgrade.renamed{}`). Matches an
728
- # entry exactly OR as a directory prefix (entry "/.claude/skills/foo" covers its SKILL.md
729
- # + references/). Only meaningful in --upgrade; always false otherwise. (#334)
730
- _upgrade_excluded() { # <rel>
731
- [[ $UPGRADE -eq 1 ]] || return 1
732
- local rel="$1" e
733
- while IFS= read -r e; do
734
- [[ -z "$e" ]] && continue
735
- [[ "$rel" == "$e" || "$rel" == "$e"/* ]] && return 0
736
- done <<< "${UPGRADE_EXCLUDE:-}"
737
- return 1
738
- }
739
-
740
- # safe_write: in --upgrade, never overwrite an existing file (preserve user edits) and never
741
- # re-add a config-excluded path — only add genuinely new files. In normal mode it is just emit.
742
- # Tracks added / preserved / skipped-by-config paths for the upgrade summary. (#334)
743
- safe_write() { # <src> <dest>
744
- local rel="${2#"$TARGET"/}"
745
- if _upgrade_excluded "$rel"; then
746
- UPGRADE_SKIPPED+=("$rel"); return 0
747
- fi
748
- if [[ $UPGRADE -eq 1 && -e "$2" ]]; then
749
- UPGRADE_PRESERVED+=("$rel"); return 0
750
- fi
751
- emit "$1" "$2"
752
- [[ $UPGRADE -eq 1 ]] && UPGRADE_ADDED+=("$rel")
753
- return 0
754
- }
755
-
756
- # safe_copy: verbatim (non-templated) counterpart of safe_write for kit-owned files copied
757
- # as-is (scripts/, skill references). Honors the SAME upgrade contract — existing files are
758
- # PRESERVED, config-excluded paths are SKIPPED — fixing the downgrade where scripts/ used to
759
- # be unconditionally overwritten with older templates. Pass "exec" as $3 to chmod +x. (#334)
760
- safe_copy() { # <src> <dest> [exec]
761
- local rel="${2#"$TARGET"/}"
762
- [[ -f "$1" ]] || return 0
763
- if _upgrade_excluded "$rel"; then
764
- UPGRADE_SKIPPED+=("$rel"); return 0
765
- fi
766
- if [[ $UPGRADE -eq 1 && -e "$2" ]]; then
767
- UPGRADE_PRESERVED+=("$rel"); return 0
768
- fi
769
- mkdir -p "$(dirname "$2")"
770
- cp "$1" "$2"
771
- WRITTEN+=("$rel")
772
- [[ "${3:-}" == "exec" ]] && chmod +x "$2" 2>/dev/null
773
- [[ $UPGRADE -eq 1 ]] && UPGRADE_ADDED+=("$rel")
774
- return 0
775
- }
776
-
777
- # hook_write: safe_write for a kit-owned HOOK (#370). In --upgrade an existing hook is refreshed when
778
- # it is an unmodified copy of an earlier template version (hook_refresh_state: the manifest hash or
779
- # cckit's own template history), and reported as drifted — never overwritten — when the repo
780
- # customized it. Everything else (new file, config-excluded path, normal init) is safe_write.
781
- hook_write() { # <src> <dest>
782
- local rel="${2#"$TARGET"/}" state
783
- if [[ $UPGRADE -ne 1 || ! -e "$2" ]] || _upgrade_excluded "$rel"; then safe_write "$1" "$2"; return 0; fi
784
- state="$(hook_refresh_state "$2" "$1" "$KIT_ROOT" "$TARGET/$MANIFEST_REL" "$rel")"
785
- case "$state" in
786
- refresh) emit "$1" "$2"; UPGRADE_REFRESHED+=("$rel") ;;
787
- drifted) UPGRADE_DRIFTED+=("$rel") ;;
788
- *) UPGRADE_PRESERVED+=("$rel") ;;
789
- esac
790
- return 0
791
- }
792
-
793
- # ---- git + GitHub setup: the whole plan first, then ONE confirmation (#456) ----
794
- # Nothing has been written yet. --yes confirms; a terminal is asked once; with neither, the setup
795
- # does not run and the run says so at the end (re-run with --yes). A dry run only prints the plan.
796
- IG_TARGET="$TARGET"; IG_REPO="$REPO"; IG_BASE="$BASE_BRANCH"; IG_VISIBILITY="$REPO_VISIBILITY"
797
- IG_PROJECTS_V2="$PROJECTS_V2"; IG_KIT_ROOT="$KIT_ROOT"; IG_DOCTOR=1; IG_CONFIG_REL="$CONFIG_REL"
798
- [[ "${KIT_INIT_PREFLIGHT:-1}" == "0" ]] && IG_DOCTOR=0 # the fixture tests' switch: no doctor, no network
799
- SETUP_DECLINED=0
800
- if [[ $SETUP_WANTED -eq 1 && $DRY_RUN -eq 0 ]]; then
801
- echo ""
802
- echo "cckit init is about to set up \"$NAME\" in $TARGET"
803
- [[ -n "$RECIPE_FILE" ]] && echo " Starting point: $(jq -r .label "$RECIPE_FILE")"
804
- [[ -n "$DB_FILE" ]] && echo " Database: $(jq -r .label "$DB_FILE")"
805
- echo " Git and GitHub setup:"
806
- init_setup_plan | sed 's/^/ /'
807
- if [[ $ASSUME_YES -eq 1 ]]; then
808
- SETUP_RUN=1
809
- else
810
- printf '\nGo ahead? [Y/n] (n = only the files in the folder; nothing is created on GitHub) '
811
- IFS= read -r _setup_ok || _setup_ok="n"
812
- case "$_setup_ok" in ""|y|Y|yes|Yes|YES) SETUP_RUN=1 ;; *) SETUP_DECLINED=1 ;; esac
813
- fi
814
- # Declined: the project keeps the base branch it would have had without the setup.
815
- if [[ $SETUP_RUN -eq 0 && $SETUP_BASE_CHOSEN -eq 1 ]]; then BASE_BRANCH="$(_init_fallback_base)"; IG_BASE="$BASE_BRANCH"; fi
816
- fi
817
-
818
- # _init_finish — the closing lines of a guided run: the database guide, why the setup did not run
819
- # (when it did not), the step totals. Exits 1 when a step failed, 0 otherwise.
820
- _init_finish() {
821
- local _d _s _f
822
- if [[ -n "$DB_FILE" ]]; then database_guide "$DB_FILE" "$TARGET"; fi
823
- if [[ $UPGRADE -eq 0 && $NO_GITHUB -eq 0 && $SETUP_RUN -eq 0 ]]; then
824
- echo ""
825
- if [[ $SETUP_DECLINED -eq 1 ]]; then
826
- echo "Git and GitHub setup: not run (you answered no). To run it later: cckit init --yes (inside $TARGET)"
827
- else
828
- echo "Git and GitHub setup: not run — there is no terminal to confirm on."
829
- echo " To run it: cckit init --yes (inside $TARGET). To leave it out on purpose: --no-github."
830
- fi
831
- fi
832
- # A run without the setup says what it left undone, with the command that does it (#487).
833
- if [[ $UPGRADE -eq 0 && $SETUP_RUN -eq 0 ]]; then
834
- if ! git -C "$TARGET" rev-parse --is-inside-work-tree >/dev/null 2>&1; then
835
- if [[ $NO_GITHUB -eq 0 ]]; then
836
- echo " Not done: $TARGET is not a git repository yet, so no task can be started in it."
837
- echo " cckit init --yes starts version control, saves the cckit files and creates the branch '$BASE_BRANCH'."
838
- fi
839
- else
840
- if init_base_missing; then
841
- echo ""
842
- echo "Not done: the branch '$BASE_BRANCH' (github.baseBranch in $CONFIG_REL) does not exist in this repository."
843
- echo " cckit start and cckit task start cut their work from it and stop until it exists."
844
- echo " To create it and push it: cckit init --yes (inside $TARGET)"
845
- fi
846
- if init_scaffold_pending; then
847
- echo ""
848
- echo "Not done: the cckit files are not committed. A task started now gets a folder without them,"
849
- echo " and a teammate who clones the project gets no setup."
850
- if [[ $NO_GITHUB -eq 1 ]]; then
851
- echo " To commit them, on the branch '$BASE_BRANCH': $(init_scaffold_command)"
852
- else
853
- echo " To commit them on '$BASE_BRANCH' and push: cckit init --yes (inside $TARGET)"
854
- fi
855
- fi
856
- fi
857
- fi
858
- if [[ -n "$INIT_STEP_LOG" ]]; then
859
- _d="$(printf '%s' "$INIT_STEP_LOG" | grep -c '^ \[done' || true)"
860
- _s="$(printf '%s' "$INIT_STEP_LOG" | grep -c '^ \[skipped' || true)"
861
- _f="$(printf '%s' "$INIT_STEP_LOG" | grep -c '^ \[failed' || true)"
862
- echo ""
863
- echo "Result: $_d done · $_s skipped (already there, or not available) · $_f failed"
864
- if [[ "$_f" -gt 0 ]]; then
865
- printf '%s' "$INIT_STEP_LOG" | grep '^ \[failed'
866
- echo "Fix what failed and run cckit init again: finished steps are skipped."
867
- fi
868
- fi
869
- if [[ -n "$RECIPE_FILE" && $INIT_FAILED -eq 0 ]]; then
870
- _s="$(jq -r '.start // empty' "$RECIPE_FILE")"
871
- [[ -n "$_s" ]] && echo "To see the project running: cd $TARGET && $_s"
872
- fi
873
- [[ $INIT_FAILED -gt 0 ]] && exit 1
874
- exit 0
875
- }
876
-
877
- # ---- dry run: print the plan and exit, writing nothing -------------------
878
- if [[ $DRY_RUN -eq 1 ]]; then
879
- echo "-> DRY RUN — nothing will be written. Plan for $TARGET:"
880
- [[ $UPGRADE -eq 1 ]] && echo " (UPGRADE: existing files are PRESERVED; only genuinely-missing files are added; config keys merged.)"
881
- [[ $UPGRADE -eq 1 && -n "${UPGRADE_EXCLUDE:-}" ]] && { echo " (SKIPPED by kit.config upgrade.removed/renamed — never re-added:)"; printf '%s\n' "${UPGRADE_EXCLUDE}" | sed 's/^/ - /'; }
882
- echo ""
883
- echo " Profile : $PROFILE"
884
- echo " Project : $NAME ($SLUG)"
885
- echo " Repo : $REPO"
886
- echo " Base : $BASE_BRANCH (rules that name the integration branch render this)"
887
- echo " Adapters: $ADAPTERS$([[ $ADAPTER_ADDED -eq 1 ]] && echo " (adding to stored: $ADAPTERS_HAVE)")"
888
- echo " Board : $([[ "$PROJECTS_V2" == "true" ]] && echo "Projects v2 #$PROJECT_NUMBER" || echo "off (gh issues only)")"
889
- echo " Memory : $MEMORY_BOOL Plans: $PLANS_FORMAT Lang: $LANG_PREF"
890
- echo " Spec Kit: $SPECKIT_ON Pre-push gate: $PREPUSH_ENABLED Local model: $LOCAL_ON kitVersion: $PLUGIN_VERSION"
891
- [[ "$CONTENT_KINDS_ON" == "true" ]] && echo " Content : kind labels post · campaign · brand · research"
892
- [[ "$PR_BODY_STYLE" == "content" ]] && echo " PR text : content (draft and review wording)"
893
- [[ "$PLAIN_ON" == "true" ]] && echo " Wording : plain language (draft, review, approve)"
894
- [[ "$TASKS_DEFAULT" == "light" ]] && echo " Tasks : light tasks are the default list (cckit task; no GitHub issue per task)"
895
- echo ""
896
- if [[ $UPGRADE -eq 1 ]]; then
897
- # An upgrade's dry run is the upgrade itself, run on a temporary copy of the kit-managed paths
898
- # and measured (#448) — not the list below, which names everything a FRESH init can write.
899
- upgrade_dry_run "$TARGET" "$KIT_ROOT/scripts/init.sh" "${_INIT_ARGS[@]}" || exit $?
900
- echo ""
901
- echo " A = added · M = modified. Measured by running the upgrade on a temporary copy; $TARGET was not written."
902
- echo "Re-run without --dry-run to apply."
903
- exit 0
904
- fi
905
- # A project that already has the kit files (#456): a real run leaves them alone, so the plan is
906
- # the database option and the setup steps, not the file list.
907
- if [[ $INIT_ALREADY -eq 1 && ( $SETUP_WANTED -eq 1 || -n "$DB_FILE" ) ]]; then
908
- echo " cckit files: already there ($CONFIG_REL) — a run leaves them as they are (--upgrade merges in new kit features)."
909
- echo ""
910
- if [[ -n "$DB_FILE" ]]; then
911
- echo " Database option $(jq -r .id "$DB_FILE") would add what is missing of:"
912
- database_plan "$DB_FILE" "$DB_STACK"
913
- echo ""
914
- fi
915
- if [[ $SETUP_WANTED -eq 1 ]]; then
916
- echo " Git and GitHub setup would run these steps (nothing is written to GitHub by a dry run):"
917
- init_setup_plan | sed 's/^/ /'
918
- echo ""
919
- fi
920
- echo "Re-run without --dry-run to apply."
921
- exit 0
922
- fi
923
- echo " Would write:"
924
- echo " $CONFIG_REL"
925
- echo " $MANIFEST_REL (ownership manifest, gitignored)"
926
- if adapter_has "$ADAPTERS" claude; then
927
- echo " .claude/settings.local.json"
928
- echo " .claude/hooks/repo-hygiene.sh (SessionStart: read-only repo-hygiene report)"
929
- echo " .claude/hooks/guard-base-branch-commit.sh (PreToolUse Bash: block commits to base branch)"
930
- echo " .claude/hooks/guard-raw-git-ops.sh (PreToolUse Bash, tracked settings.json: raw gh/git -> cckit verb)"
931
- echo " .claude/hooks/kit_version_check.sh (SessionStart: update check)"
932
- echo " .claude/hooks/kit-mail-check.sh (session mail, tracked settings.json: PostToolUse / UserPromptSubmit / SessionStart / Stop)"
933
- for a in $AGENTS; do
934
- [[ -f "$KIT_ROOT/templates/agents/$a.md" ]] && echo " .claude/agents/$a/AGENT.md"
935
- done
936
- fi
937
- for _ad in $ADAPTERS; do
938
- _add="$(adapter_dir "$_ad")"
939
- echo " $(adapter_instructions "$_ad")"
940
- for r in $RULES; do
941
- _rule_enabled "$r" || continue
942
- [[ -f "$KIT_ROOT/templates/rules/$r.md" ]] && echo " $_add/rules/$r.md"
943
- done
944
- [[ "$CODEGRAPH_ON" == "true" ]] && echo " $_add/rules/code-retrieval.md (codeGraph.provider is set)"
945
- for s in $SKILLS; do
946
- _dn="$s"; { [[ -n "$SKILL_PREFIX" ]] && _is_namespaced "$s"; } && _dn="${SKILL_PREFIX}${s}"
947
- [[ -f "$KIT_ROOT/templates/skills/$s/SKILL.md" ]] && echo " $_add/skills/$_dn/SKILL.md"
948
- [[ -d "$KIT_ROOT/templates/skills/$s/references" ]] && echo " $_add/skills/$_dn/references/"
949
- done
950
- done
951
- if adapter_has "$ADAPTERS" codex; then
952
- echo " .codex/hooks/ (repo-hygiene.sh, kit_version_check.sh, kit-mail-check.sh, guard-base-branch-commit.sh, guard-raw-git-ops.sh$([[ "$PREPUSH_ENABLED" == "true" ]] && echo ", prepush_gate.sh")$([[ "$LOCAL_ON" == "true" ]] && echo ", kit-local-status.sh"))"
953
- echo " .codex/hooks.json (merged: cckit's registrations are added, yours are kept; trust them in Codex with /hooks)"
954
- for a in $AGENTS; do
955
- [[ -f "$KIT_ROOT/templates/agents/$a.md" ]] && echo " .codex/agents/$a.toml"
956
- done
957
- echo " (Codex adapter: no memory hooks — they read Claude Code transcripts)"
958
- fi
959
- echo " scripts/ (kit-config.sh, gh-project.sh, kit-version-check.sh, setup-labels.sh, setup-milestones.sh, capture-project-ids.sh, task-sync.sh, knowledge-lint.sh, review-lint.sh + review-rules.conf, skill-frontmatter-lint.sh, instruction-budget-lint.sh)"
960
- echo " knowledge/INDEX.md (knowledge-base manifest — rules/knowledge-base.md)"
961
- if adapter_has "$ADAPTERS" claude; then
962
- echo " .claude/lib/kit-sigil.sh (claude-kit attribution sigil helper, sourced by task-* footers)"
963
- [[ "$MEMORY_BOOL" == "true" ]] && echo " .claude/hooks/mempal_session_start.sh + mempal_save.sh + mempal_precompact.sh + mempal_followup.sh (SessionStart / Stop / PreCompact / SessionEnd)"
964
- [[ "$MEMORY_BOOL" == "true" ]] && echo " .claude/mempal-identity.$SLUG.txt (per-wing wake-up header — edit the Stack line)"
965
- [[ "$PREPUSH_ENABLED" == "true" ]] && echo " .claude/hooks/prepush_gate.sh (PreToolUse Bash gate: $PREPUSH_CMD)"
966
- [[ "$LOCAL_ON" == "true" ]] && echo " .claude/hooks/kit-local-status.sh (SessionStart: announce local model layer when alive)"
967
- fi
968
- echo ""
969
- echo " Onboarding would offer (opt-in): gh auth$([[ "$MEMORY_BOOL" == "true" ]] && echo " · MemPalace (mempalace-mcp)") · gws (if you use Google Workspace) · local model layer (--local on: NL chores at \$0 via mlx_lm.server)"
970
- echo ""
971
- if [[ -n "$RECIPE_FILE" ]]; then
972
- echo " Recipe $(jq -r .id "$RECIPE_FILE") would run, in $TARGET:"
973
- recipe_plan "$RECIPE_FILE"
974
- echo ""
975
- fi
976
- if [[ -n "$DB_FILE" ]]; then
977
- echo " Database option $(jq -r .id "$DB_FILE") would add:"
978
- database_plan "$DB_FILE" "$DB_STACK"
979
- echo ""
980
- fi
981
- if [[ $SETUP_WANTED -eq 1 ]]; then
982
- echo " Git and GitHub setup would run these steps (nothing is written to GitHub by a dry run):"
983
- init_setup_plan | sed 's/^/ /'
984
- echo ""
985
- elif [[ $NO_GITHUB -eq 1 ]]; then
986
- echo " Git and GitHub setup: off (--no-github)."
987
- echo ""
988
- fi
989
- echo "Re-run without --dry-run to write these files."
990
- exit 0
991
- fi
992
-
993
- # ---- guard ---------------------------------------------------------------
994
- if [[ -e "$KITCFG" && $FORCE -eq 0 && $UPGRADE -eq 0 ]]; then
995
- # A re-run of the guided setup on a project that already has the kit files (#456): the files are
996
- # left as they are, and only the steps that are still missing run.
997
- if [[ $SETUP_RUN -eq 1 || -n "$DB_FILE" ]]; then
998
- echo ""
999
- echo "-> $TARGET already has the cckit files ($CONFIG_REL)"
1000
- init_step skipped "cckit files" "already there (cckit init --upgrade merges in new kit features)"
1001
- if [[ -n "$DB_FILE" ]]; then database_apply "$DB_FILE" "$DB_STACK" "$TARGET"; fi
1002
- if [[ $SETUP_RUN -eq 1 ]]; then init_setup_run; fi
1003
- _init_finish
1004
- fi
1005
- echo " $TARGET already initialized ($CONFIG_REL). Re-run with --upgrade to merge in new features (preserves your edits), or --force to overwrite generated files."
1006
- exit 1
1007
- fi
1008
-
1009
- # ---- recipe + database: the project itself, before the kit files (#456) ---
1010
- # The recipe's generators want an empty folder, so they run first; the kit files land on top.
1011
- if [[ -n "$RECIPE_FILE" ]]; then
1012
- echo ""
1013
- echo "-> Starting point: $(jq -r .label "$RECIPE_FILE") (this downloads packages and can take a few minutes)"
1014
- if ! recipe_run "$RECIPE_FILE" "$TARGET"; then
1015
- echo "" >&2
1016
- echo "x The starting point could not be built, so nothing else was set up." >&2
1017
- echo " Fix the problem shown above, delete the folder $TARGET, and run cckit init again." >&2
1018
- exit 1
1019
- fi
1020
- fi
1021
- if [[ -n "$DB_FILE" ]]; then
1022
- echo ""
1023
- echo "-> Database: $(jq -r .label "$DB_FILE")"
1024
- mkdir -p "$TARGET"
1025
- database_apply "$DB_FILE" "$DB_STACK" "$TARGET"
1026
- fi
1027
-
1028
- # ---- init banner (fresh init only; not on --upgrade) ---------------------
1029
- # Beat 1: golden-angle plant animation (TTY + Unicode only, else skipped).
1030
- # Beat 2: V4 box-drawing CLAUDE KIT banner snap (always).
1031
- if [[ $UPGRADE -eq 0 ]]; then
1032
- _kit_init_banner "$PLUGIN_VERSION"
1033
- fi
1034
-
1035
- UPGRADE_ADDED=(); UPGRADE_PRESERVED=(); UPGRADE_SKIPPED=(); UPGRADE_REFRESHED=(); UPGRADE_DRIFTED=()
1036
- # Checksums of the kit-managed paths before the first write: the summary prints what differs after
1037
- # the last one, so a file a later step merges into is reported as modified, not as preserved (#448).
1038
- _UP_SNAP=""
1039
- if [[ $UPGRADE -eq 1 && -z "${KIT_UPGRADE_SIMULATED:-}" ]]; then
1040
- _UP_SNAP="$(mktemp -d)" && upgrade_snapshot "$TARGET" > "$_UP_SNAP/before"
1041
- fi
1042
- echo "-> $([[ $UPGRADE -eq 1 ]] && echo Upgrading || echo Scaffolding) $PROFILE profile $([[ $UPGRADE -eq 1 ]] && echo in || echo into) $TARGET"
1043
- mkdir -p "$TARGET/scripts/lib" "$(dirname "$KITCFG")"
1044
- adapter_has "$ADAPTERS" claude && mkdir -p "$TARGET/.claude/agents" "$TARGET/.claude/skills" "$TARGET/.claude/rules"
1045
-
1046
- # ---- kit.config.json (built with jq for correctness) --------------------
1047
- RECIPE_CFG='{}'
1048
- [[ -n "$RECIPE_FILE" ]] && RECIPE_CFG="$(jq -c '.config // {}' "$RECIPE_FILE")"
1049
- # Location: .claude/kit.config.json when the Claude adapter is selected (the layout every existing
1050
- # project has); the root cckit.config.json for a Codex-only project, which gets no .claude/ tree.
1051
- jq -n \
1052
- --argjson adapters "$(adapter_json "$ADAPTERS")" \
1053
- --arg kitver "$PLUGIN_VERSION" \
1054
- --arg name "$NAME" --arg slug "$SLUG" --arg owner "$OWNER_NAME" --arg lang "$LANG_PREF" --arg path "$TARGET" \
1055
- --arg profile "$PROFILE" --argjson roles "$ROLES_JSON" \
1056
- --arg repo "$REPO" --arg ghowner "$GH_OWNER" \
1057
- --arg base "$BASE_BRANCH" \
1058
- --argjson pv2 "$PROJECTS_V2" --argjson pnum "$PNUM_JSON" --arg ptitle "$NAME" \
1059
- --argjson milestones "$MS_JSON" \
1060
- --arg pfmt "$PLANS_FORMAT" --arg pdir "$PLANS_DIR" \
1061
- --argjson mem "$MEMORY_BOOL" --arg wing "$SLUG" --arg cps "$CLAUDE_PROJECT_SLUG" \
1062
- --argjson speckit "$SPECKIT_JSON" \
1063
- --argjson ppen "$PREPUSH_ENABLED" --arg ppcmd "$PREPUSH_CMD" \
1064
- --argjson localon "$LOCAL_ON" \
1065
- --argjson ckinds "$CONTENT_KINDS_ON" --arg prbody "$PR_BODY_STYLE" --argjson plain "$PLAIN_ON" \
1066
- --arg tasksdef "$TASKS_DEFAULT" \
1067
- --argjson recipecfg "$RECIPE_CFG" \
1068
- '{kitVersion:$kitver,
1069
- adapters:$adapters,
1070
- project:{name:$name,slug:$slug,owner:$owner,language:$lang,path:$path},
1071
- profile:$profile, roles:$roles,
1072
- github:{repo:$repo,owner:$ghowner,baseBranch:$base,projectsV2:$pv2,projectNumber:$pnum,projectTitle:$ptitle},
1073
- milestones:$milestones,
1074
- plans:{format:$pfmt,dir:$pdir},
1075
- knowledge:{dir:"knowledge"},
1076
- specKit:{enabled:$speckit},
1077
- prePush:{enabled:$ppen,command:$ppcmd},
1078
- local:{enabled:$localon,port:8080,model:"mlx-community/Qwen3-8B-4bit"},
1079
- memory:{enabled:$mem,provider:"mempalace",wing:$wing,claudeProjectSlug:$cps}}
1080
- # Content-work keys are written only when the profile turns them on, so the config of a
1081
- # software project does not gain keys it never reads (E415).
1082
- | if $ckinds then .kinds = {content:true} else . end
1083
- | if $prbody == "content" then .pr = {bodyStyle:"content"} else . end
1084
- | if $plain then .plainLanguage = {enabled:true} else . end
1085
- | if $tasksdef == "light" then .tasks = {default:"light"} else . end
1086
- # Config keys the recipe carries (`config` in recipes/<id>.json), merged over the above: the
1087
- # recipe knows the commands of the project it made (tasks.check, the gate of `cckit task run`).
1088
- | . * $recipecfg
1089
- # The config is committed by the guided setup, so it carries no absolute machine path (#490).
1090
- | del(.project.path)' \
1091
- > "$KITCFG.kit-new"
1092
- if [[ $UPGRADE -eq 1 && -f "$KITCFG" ]]; then
1093
- # deep-merge: existing values win (preserve user choices), new REQUIRED keys added, version
1094
- # bumped. FEATURE blocks (plans/specKit/prePush/local/memory) are additive only when the
1095
- # project's config ALREADY has them — a missing feature key is a deliberate absence, and an
1096
- # upgrade must never inject profile defaults over it (#149). `adapters` follows the same rule: a
1097
- # config without the key means Claude, and an upgrade that changes nothing must not write it.
1098
- # The project's key order is kept: a key the template adds goes after the keys already there, at
1099
- # every depth. (`$tmpl * $have` gave the same values in the TEMPLATE's order, which moved the
1100
- # project's own blocks around on every upgrade — #448.)
1101
- jq -s --arg kitver "$PLUGIN_VERSION" '
1102
- def fill($h; $t):
1103
- if ($h | type) == "object" and ($t | type) == "object"
1104
- then reduce ($t | keys_unsorted[]) as $k ($h;
1105
- if has($k) then .[$k] = fill($h[$k]; $t[$k]) else .[$k] = $t[$k] end)
1106
- else $h end;
1107
- .[1] as $have
1108
- | (.[0] | with_entries(.key as $k | select(
1109
- (["plans","specKit","prePush","local","memory","adapters","plainLanguage"] | index($k)) == null
1110
- or ($have | has($k))))) as $tmpl
1111
- | fill($have; $tmpl) | .kitVersion = $kitver' "$KITCFG.kit-new" "$KITCFG" \
1112
- > "$KITCFG.merged"
1113
- rm -f "$KITCFG.kit-new"
1114
- # Existing values win in the merge — but an EXPLICIT --local flag is a user decision now,
1115
- # so it overrides the preserved value (port/model stay as the user configured them).
1116
- if [[ $LOCAL_EXPLICIT -eq 1 ]]; then
1117
- jq --argjson v "$LOCAL_ON" '.local = ((.local // {port:8080,model:"mlx-community/Qwen3-8B-4bit"}) | .enabled = $v)' \
1118
- "$KITCFG.merged" > "$KITCFG.tmp" && mv "$KITCFG.tmp" "$KITCFG.merged"
1119
- fi
1120
- # An explicit --adapter is a decision made now, so it is written even where the key was absent.
1121
- if [[ -n "$ADAPTERS_NEW" ]]; then
1122
- jq --argjson v "$(adapter_json "$ADAPTERS")" '.adapters = $v' "$KITCFG.merged" > "$KITCFG.tmp" && mv "$KITCFG.tmp" "$KITCFG.merged"
1123
- fi
1124
- # Written with the fewest changed lines: a version bump alone edits the one `kitVersion` line and
1125
- # leaves the file's formatting as the project keeps it. A merge that adds keys re-serialises it.
1126
- _cfg_how="$(json_write_minimal "$KITCFG.merged" "$KITCFG")"
1127
- echo " + $CONFIG_REL (merged · kitVersion -> $PLUGIN_VERSION · $_cfg_how)"
1128
- else
1129
- mv "$KITCFG.kit-new" "$KITCFG"
1130
- echo " + $CONFIG_REL"
1131
- fi
1132
-
1133
- # ---- agents: one role source, one definition per selected runtime (E257.6) ----
1134
- # templates/agents/<role>.md is the role. Claude Code reads it as markdown; Codex reads a custom
1135
- # agent as TOML, so the SAME rendered role is translated by agent_def_codex (scripts/lib/agent-def.sh).
1136
- if adapter_has "$ADAPTERS" claude; then
1137
- use_adapter claude
1138
- for a in $AGENTS; do
1139
- src="$KIT_ROOT/templates/agents/$a.md"
1140
- [[ -f "$src" ]] || continue
1141
- safe_write "$src" "$TARGET/.claude/agents/$a/AGENT.md"
1142
- echo " + .claude/agents/$a/AGENT.md"
1143
- done
1144
- fi
1145
- if adapter_has "$ADAPTERS" codex; then
1146
- use_adapter codex
1147
- # shellcheck source=/dev/null
1148
- . "$KIT_ROOT/scripts/lib/agent-def.sh"
1149
- for a in $AGENTS; do
1150
- src="$KIT_ROOT/templates/agents/$a.md"
1151
- [[ -f "$src" ]] || continue
1152
- _ca_rel=".codex/agents/$a.toml"; _ca_dst="$TARGET/$_ca_rel"
1153
- if _upgrade_excluded "$_ca_rel"; then UPGRADE_SKIPPED+=("$_ca_rel"); continue; fi
1154
- if [[ $UPGRADE -eq 1 && -e "$_ca_dst" ]]; then UPGRADE_PRESERVED+=("$_ca_rel"); continue; fi
1155
- if [[ $UPGRADE -eq 0 && $FORCE -eq 0 && -e "$_ca_dst" ]]; then
1156
- # A fresh init over a .codex/agents/ the user already keeps: their file wins, as AGENTS.md does.
1157
- echo " = $_ca_rel (already there — kept; --force replaces it)"; continue
1158
- fi
1159
- _ca_tmp="$(mktemp)"
1160
- render_tpl "$src" > "$_ca_tmp"
1161
- mkdir -p "$TARGET/.codex/agents"
1162
- if agent_def_codex "$_ca_tmp" > "$_ca_dst.kit-new"; then
1163
- mv "$_ca_dst.kit-new" "$_ca_dst"
1164
- WRITTEN+=("$_ca_rel")
1165
- [[ $UPGRADE -eq 1 ]] && UPGRADE_ADDED+=("$_ca_rel")
1166
- echo " + $_ca_rel"
1167
- else
1168
- rm -f "$_ca_dst.kit-new"
1169
- echo " ! $_ca_rel not written — templates/agents/$a.md has no name or description" >&2
1170
- fi
1171
- rm -f "$_ca_tmp"
1172
- done
1173
- fi
1174
- use_adapter "${ADAPTERS%% *}"
1175
-
1176
- # ---- instructions + rules + skills, once per selected adapter ------------
1177
- # Same templates, same loop: the adapter decides the destination dir and the IF:ADAPTER_* blocks.
1178
- # A second adapter's pass never touches the first one's tree.
1179
- for _ad in $ADAPTERS; do
1180
- use_adapter "$_ad"
1181
- AD="$ADAPTER_DIR"; _instr="$(adapter_instructions "$_ad")"
1182
-
1183
- # CLAUDE.md / AGENTS.md — one source (templates/instructions.md.tmpl). A pre-existing AGENTS.md is
1184
- # usually the project's own contract, so a fresh init keeps it unless --force (CLAUDE.md keeps its
1185
- # historical behavior: a fresh init writes it).
1186
- if [[ "$_ad" == "codex" && -e "$TARGET/$_instr" && $UPGRADE -eq 0 && $FORCE -eq 0 ]]; then
1187
- echo " = $_instr exists — kept (re-run with --force to replace it with the cckit instructions)"
1188
- else
1189
- safe_write "$KIT_ROOT/templates/instructions.md.tmpl" "$TARGET/$_instr"
1190
- echo " + $_instr"
1191
- fi
1192
-
1193
- # ---- rules (filtered by enabled flags) ----------------------------------
1194
- for r in $RULES; do
1195
- # Skip rules whose feature is disabled for this project.
1196
- _rule_enabled "$r" || continue
1197
- src="$KIT_ROOT/templates/rules/$r.md"
1198
- [[ -f "$src" ]] || { echo " missing rule: $r"; continue; }
1199
- safe_write "$src" "$TARGET/$AD/rules/$r.md"
1200
- echo " + $AD/rules/$r.md"
1201
- done
1202
- # code-retrieval is in no profile: `cckit add <id>` writes it when a code-graph integration is
1203
- # switched on. An upgrade re-adds it only for a project whose config already has one on.
1204
- if [[ "$CODEGRAPH_ON" == "true" ]]; then
1205
- safe_write "$KIT_ROOT/templates/rules/code-retrieval.md" "$TARGET/$AD/rules/code-retrieval.md"
1206
- echo " + $AD/rules/code-retrieval.md"
1207
- fi
1208
-
1209
- # ---- skills --------------------------------------------------------------
1210
- for s in $SKILLS; do
1211
- src="$KIT_ROOT/templates/skills/$s/SKILL.md"
1212
- [[ -f "$src" ]] || continue
1213
- # Namespaced skills take $SKILL_PREFIX so we scaffold to the project's name (kit-task-close)
1214
- # instead of a bare-name duplicate (task-close) alongside it.
1215
- dest_name="$s"
1216
- if [[ -n "$SKILL_PREFIX" ]] && _is_namespaced "$s"; then
1217
- dest_name="${SKILL_PREFIX}${s}"
1218
- fi
1219
- safe_write "$src" "$TARGET/$AD/skills/$dest_name/SKILL.md"
1220
- # If prefixed AND this was a FRESH scaffold (frontmatter still bare), rewrite name + sibling refs.
1221
- # An existing (preserved) skill already reads `name: $dest_name`, so the guard skips it.
1222
- if [[ "$dest_name" != "$s" && -f "$TARGET/$AD/skills/$dest_name/SKILL.md" ]] \
1223
- && grep -qE "^name:[[:space:]]*${s}[[:space:]]*\$" "$TARGET/$AD/skills/$dest_name/SKILL.md"; then
1224
- _prefix_skill_file "$TARGET/$AD/skills/$dest_name/SKILL.md"
1225
- fi
1226
- echo " + $AD/skills/$dest_name/SKILL.md"
1227
- # bundled references for multi-file skills (copied verbatim, no templating).
1228
- # Per-file safe_copy so the upgrade contract (preserve existing, skip excluded) applies.
1229
- if [[ -d "$KIT_ROOT/templates/skills/$s/references" ]]; then
1230
- for _ref in "$KIT_ROOT/templates/skills/$s/references/"*; do
1231
- [[ -f "$_ref" ]] || continue
1232
- safe_copy "$_ref" "$TARGET/$AD/skills/$dest_name/references/$(basename "$_ref")"
1233
- done
1234
- echo " + $AD/skills/$dest_name/references/"
1235
- fi
1236
- done
1237
- done # adapters
1238
- use_adapter "${ADAPTERS%% *}"
1239
-
1240
- # ---- scripts (libs + setup + sync; kit-owned) ---------------------------
1241
- # safe_copy honors the upgrade contract: on --upgrade an EXISTING script is PRESERVED, never
1242
- # overwritten with an older template (the #334 downgrade that erased #307/#313/#314). Fresh
1243
- # inits get the current scripts; to refresh a kit-owned script later, delete it then re-upgrade.
1244
- safe_copy "$KIT_ROOT/scripts/lib/kit-config.sh" "$TARGET/scripts/lib/kit-config.sh"
1245
- # kit-config.sh and kit-version-check.sh both source this resolver from beside themselves; without it
1246
- # they only ever look at .claude/kit.config.json and miss a Codex-only project's root config.
1247
- safe_copy "$KIT_ROOT/scripts/lib/config-path.sh" "$TARGET/scripts/lib/config-path.sh"
1248
- safe_copy "$KIT_ROOT/scripts/lib/gh-project.sh" "$TARGET/scripts/lib/gh-project.sh"
1249
- safe_copy "$KIT_ROOT/scripts/lib/worktree-issue.sh" "$TARGET/scripts/lib/worktree-issue.sh"
1250
- safe_copy "$KIT_ROOT/scripts/lib/role-identity.sh" "$TARGET/scripts/lib/role-identity.sh"
1251
- safe_copy "$KIT_ROOT/scripts/lib/kit-local.sh" "$TARGET/scripts/lib/kit-local.sh"
1252
- safe_copy "$KIT_ROOT/scripts/lib/effort-metrics.sh" "$TARGET/scripts/lib/effort-metrics.sh"
1253
- safe_copy "$KIT_ROOT/scripts/lib/gh-log.sh" "$TARGET/scripts/lib/gh-log.sh"
1254
- safe_copy "$KIT_ROOT/scripts/lib/kit-events.sh" "$TARGET/scripts/lib/kit-events.sh"
1255
- # task-sync.sh sources board-view.sh unguarded (set -e) and effort-plan.sh for `--plan`.
1256
- safe_copy "$KIT_ROOT/scripts/lib/board-view.sh" "$TARGET/scripts/lib/board-view.sh"
1257
- safe_copy "$KIT_ROOT/scripts/lib/effort-plan.sh" "$TARGET/scripts/lib/effort-plan.sh"
1258
- safe_copy "$KIT_ROOT/scripts/lib/worktree-start.sh" "$TARGET/scripts/lib/worktree-start.sh"
1259
- # pr-evidence.sh is the helper rules/gate-and-review.md tells a project to source; without this copy
1260
- # `cckit lib` resolves to the project's own scripts/lib, where the helper would be missing.
1261
- safe_copy "$KIT_ROOT/scripts/lib/pr-evidence.sh" "$TARGET/scripts/lib/pr-evidence.sh"
1262
- safe_copy "$KIT_ROOT/scripts/lib/session-registry.sh" "$TARGET/scripts/lib/session-registry.sh"
1263
- safe_copy "$KIT_ROOT/scripts/lib/kinds.sh" "$TARGET/scripts/lib/kinds.sh"
1264
- safe_copy "$KIT_ROOT/scripts/kit-version-check.sh" "$TARGET/scripts/kit-version-check.sh" exec
1265
- for sc in setup-labels.sh setup-milestones.sh capture-project-ids.sh task-sync.sh knowledge-lint.sh \
1266
- review-lint.sh skill-frontmatter-lint.sh instruction-budget-lint.sh; do
1267
- safe_copy "$KIT_ROOT/scripts/$sc" "$TARGET/scripts/$sc" exec
1268
- done
1269
- # review-lint is table-driven: the engine is useless without a rule table, so the starter table
1270
- # travels with it. Every lint self-disables when it does not apply (no rule table / no skills dir /
1271
- # no CLAUDE.md and no rules dir), so shipping them to every project is safe.
1272
- safe_copy "$KIT_ROOT/scripts/review-rules.conf" "$TARGET/scripts/review-rules.conf"
1273
- # Seed each baseline ONCE so a fresh project starts green and only *new* defects fail. Never
1274
- # regenerate an existing baseline - that would silently re-grandfather drift on upgrade.
1275
- #
1276
- # ASK for the path, never reconstruct it. This used to test "$_lint-baseline.txt", which is right
1277
- # for review-lint and wrong for skill-frontmatter-lint (it writes skill-frontmatter-baseline.txt, no
1278
- # "-lint"). The guessed name never existed, so the "already seeded" guard never matched and every
1279
- # upgrade re-baselined it - exactly what the line above forbids.
1280
- #
1281
- # KIT_LINT_WALK=1 so the seed sees the files just written. init.sh usually scaffolds into a repo
1282
- # that already has commits, where `git ls-files` is non-empty and the untracked kit files are
1283
- # invisible to it; the baseline would come out empty and the gate would go red on the user's first
1284
- # commit of the scaffold.
1285
- for _lint in review-lint skill-frontmatter-lint instruction-budget-lint; do
1286
- [[ -f "$TARGET/scripts/$_lint.sh" ]] || continue
1287
- _baseline="$( cd "$TARGET" && bash "scripts/$_lint.sh" --baseline-path 2>/dev/null )"
1288
- [[ -n "$_baseline" ]] || continue
1289
- [[ -e "$TARGET/$_baseline" ]] && continue
1290
- ( cd "$TARGET" && KIT_LINT_WALK=1 bash "scripts/$_lint.sh" --update ) >/dev/null 2>&1 || true
1291
- done
1292
- echo " + scripts/ (libs + setup + task-sync + version-check + knowledge-lint + review-lint + skill-frontmatter-lint + instruction-budget-lint)"
1293
-
1294
- # ---- benchmark harness (generic machinery; kit-owned) + example dataset ----
1295
- # The harness measures how well THIS project's own canonical docs can be found + used by a cold
1296
- # agent (retrieval / adversarial / abstain / quality tiers). Machinery is kit-owned (refreshed on
1297
- # upgrade); the datasets under benchmarks/ are the project's own — we scaffold an EXAMPLE set +
1298
- # schema only, and safe_write preserves it on upgrade so growth is never clobbered.
1299
- for bs in run.sh run-quality.sh report.sh gate.sh stop-check.sh benchmark-test.sh; do
1300
- safe_copy "$KIT_ROOT/scripts/benchmark/$bs" "$TARGET/scripts/benchmark/$bs" exec
1301
- done
1302
- safe_copy "$KIT_ROOT/scripts/benchmark/lib/model.sh" "$TARGET/scripts/benchmark/lib/model.sh"
1303
- safe_copy "$KIT_ROOT/scripts/benchmark/lib/bench-common.sh" "$TARGET/scripts/benchmark/lib/bench-common.sh"
1304
- echo " + scripts/benchmark/ (doc-retrieval benchmark harness — see benchmarks/SCHEMA.md)"
1305
-
1306
- mkdir -p "$TARGET/benchmarks"
1307
- for bf in SCHEMA.md benchmark.config.json retrieval.jsonl adversarial.jsonl abstain.jsonl quality.jsonl .gitignore; do
1308
- safe_write "$KIT_ROOT/templates/benchmarks/$bf" "$TARGET/benchmarks/$bf"
1309
- done
1310
- echo " + benchmarks/ (example dataset + schema — grow your own; run: scripts/benchmark/report.sh)"
1311
-
1312
- # ---- knowledge base (governed dir: INDEX manifest; upgrade-safe) ---------
1313
- mkdir -p "$TARGET/knowledge"
1314
- safe_write "$KIT_ROOT/templates/knowledge-INDEX.md.tmpl" "$TARGET/knowledge/INDEX.md"
1315
- echo " + knowledge/INDEX.md (manifest — see $ADAPTER_DIR/rules/knowledge-base.md)"
1316
-
1317
- # ==== Claude adapter only: sigil lib, settings, hooks, statusline wiring ====
1318
- # Everything from here to the matching `fi` is Claude Code configuration. A Codex-only project gets
1319
- # none of it — Codex hook registration is E257.5 — and the body is left unindented on purpose so the
1320
- # hook blocks keep their history.
1321
- if adapter_has "$ADAPTERS" claude; then
1322
-
1323
- # ---- .claude/lib (kit-sigil attribution helper; all projects; idempotent) ----
1324
- # Sourced by the task-* skill footers + repo-hygiene to emit one "claude-kit"
1325
- # attribution sigil per kit-action boundary (see knowledge/brand.md §6).
1326
- mkdir -p "$TARGET/.claude/lib"
1327
- safe_write "$KIT_ROOT/templates/lib/kit-sigil.sh.tmpl" "$TARGET/.claude/lib/kit-sigil.sh"
1328
- chmod +x "$TARGET/.claude/lib/kit-sigil.sh" 2>/dev/null || true
1329
- echo " + .claude/lib/kit-sigil.sh"
1330
-
1331
- # ---- settings.json (versioned — travels to worktrees + collaborators) ---
1332
- # Unlike settings.local.json (gitignored, per-checkout), this one is CHECKED IN so the
1333
- # captain's pre-authorized wave-merge (gh pr merge under an approved plan) works in every
1334
- # worktree and for every collaborator without re-prompting. safe_write = preserve-if-exists.
1335
- mkdir -p "$TARGET/.claude"
1336
- safe_write "$KIT_ROOT/templates/settings/settings.json.tmpl" "$TARGET/.claude/settings.json"
1337
- echo " + .claude/settings.json (versioned captain merge permission)"
1338
-
1339
- # ---- settings.local.json (+ hooks, additive) ----------------------------
1340
- mkdir -p "$TARGET/.claude"
1341
- safe_write "$KIT_ROOT/templates/settings/settings.local.json.tmpl" "$TARGET/.claude/settings.local.json"
1342
- SETTINGS="$TARGET/.claude/settings.local.json"
1343
- # A merge that leaves the value as it was does not rewrite the file (json_write_minimal, #448).
1344
- merge_settings() { jq "$@" "$SETTINGS" > "$SETTINGS.tmp" && json_write_minimal "$SETTINGS.tmp" "$SETTINGS" >/dev/null; }
1345
- HOOK_NOTE=""
1346
-
1347
- if [[ "$MEMORY_BOOL" == "true" && $UPGRADE -eq 0 ]]; then
1348
- mkdir -p "$TARGET/.claude/hooks"
1349
- emit "$KIT_ROOT/templates/hooks/mempal_session_start.sh.tmpl" "$TARGET/.claude/hooks/mempal_session_start.sh"
1350
- emit "$KIT_ROOT/templates/hooks/mempal_save.sh.tmpl" "$TARGET/.claude/hooks/mempal_save.sh"
1351
- emit "$KIT_ROOT/templates/hooks/mempal_precompact.sh.tmpl" "$TARGET/.claude/hooks/mempal_precompact.sh"
1352
- emit "$KIT_ROOT/templates/hooks/mempal_followup.sh.tmpl" "$TARGET/.claude/hooks/mempal_followup.sh"
1353
- chmod +x "$TARGET/.claude/hooks/mempal_session_start.sh" "$TARGET/.claude/hooks/mempal_save.sh" "$TARGET/.claude/hooks/mempal_precompact.sh" "$TARGET/.claude/hooks/mempal_followup.sh"
1354
- # Per-wing wake-up header — without it, `mempalace wake-up` shows the single global
1355
- # ~/.mempalace/identity.txt for every wing (the session-start hook swaps this in). See
1356
- # templates/rules/mempalace.md; `cckit doctor` re-seeds it if it goes missing.
1357
- _mpid="$TARGET/.claude/mempal-identity.$SLUG.txt"
1358
- if [[ ! -e "$_mpid" ]]; then
1359
- {
1360
- printf 'Project: %s (wing: %s)\n' "$NAME" "$SLUG"
1361
- [[ -n "$OWNER_NAME" ]] && printf 'Owner: %s\n' "$OWNER_NAME"
1362
- printf 'Stack: (describe this project — this header shows on every session wake-up)\n'
1363
- } > "$_mpid"
1364
- fi
1365
- merge_settings --arg start "$TARGET/.claude/hooks/mempal_session_start.sh" --arg save "$TARGET/.claude/hooks/mempal_save.sh" --arg pre "$TARGET/.claude/hooks/mempal_precompact.sh" --arg fup "$TARGET/.claude/hooks/mempal_followup.sh" \
1366
- '.hooks.SessionStart = [{matcher:"",hooks:[{type:"command",command:$start,timeout:30}]}]
1367
- | .hooks.Stop = [{matcher:"",hooks:[{type:"command",command:$save,timeout:30}]}]
1368
- | .hooks.PreCompact = [{matcher:"",hooks:[{type:"command",command:$pre,timeout:30}]}]
1369
- | .hooks.SessionEnd = [{matcher:"",hooks:[{type:"command",command:$fup,timeout:30}]}]'
1370
- HOOK_NOTE="$HOOK_NOTE + MemPalace"
1371
- fi
1372
-
1373
- if [[ "$PREPUSH_ENABLED" == "true" && $UPGRADE -eq 0 ]]; then
1374
- mkdir -p "$TARGET/.claude/hooks"
1375
- emit "$KIT_ROOT/templates/hooks/prepush_gate.sh.tmpl" "$TARGET/.claude/hooks/prepush_gate.sh"
1376
- chmod +x "$TARGET/.claude/hooks/prepush_gate.sh"
1377
- merge_settings --arg gate "$TARGET/.claude/hooks/prepush_gate.sh" \
1378
- '.hooks.PreToolUse = [{matcher:"Bash",hooks:[{type:"command",command:$gate,timeout:120}]}]'
1379
- HOOK_NOTE="$HOOK_NOTE + pre-push gate"
1380
- fi
1381
-
1382
- # ---- local model layer SessionStart hook (opt-in; idempotent, also on --upgrade) ----
1383
- if [[ "$LOCAL_ON" == "true" ]]; then
1384
- mkdir -p "$TARGET/.claude/hooks"
1385
- hook_write "$KIT_ROOT/templates/hooks/kit-local-status.sh.tmpl" "$TARGET/.claude/hooks/kit-local-status.sh"
1386
- chmod +x "$TARGET/.claude/hooks/kit-local-status.sh" 2>/dev/null || true
1387
- merge_settings --arg ls "$TARGET/.claude/hooks/kit-local-status.sh" \
1388
- '.hooks.SessionStart = (((.hooks.SessionStart // []) | map(select((.hooks[0].command // "") != $ls))) + [{matcher:"",hooks:[{type:"command",command:$ls,timeout:10}]}])'
1389
- HOOK_NOTE="$HOOK_NOTE + local-status"
1390
- fi
1391
-
1392
- # ---- repo-hygiene SessionStart hook (all projects; read-only; idempotent) ----
1393
- mkdir -p "$TARGET/.claude/hooks"
1394
- hook_write "$KIT_ROOT/templates/hooks/repo-hygiene.sh.tmpl" "$TARGET/.claude/hooks/repo-hygiene.sh"
1395
- chmod +x "$TARGET/.claude/hooks/repo-hygiene.sh" 2>/dev/null || true
1396
- merge_settings --arg rh "$TARGET/.claude/hooks/repo-hygiene.sh" \
1397
- '.hooks.SessionStart = (((.hooks.SessionStart // []) | map(select((.hooks[0].command // "") != $rh))) + [{matcher:"",hooks:[{type:"command",command:$rh,timeout:10}]}])'
1398
- HOOK_NOTE="$HOOK_NOTE + repo-hygiene"
1399
-
1400
- # ---- base-branch commit guard PreToolUse(Bash) hook (all projects; idempotent) ----
1401
- mkdir -p "$TARGET/.claude/hooks"
1402
- hook_write "$KIT_ROOT/templates/hooks/guard-base-branch-commit.sh.tmpl" "$TARGET/.claude/hooks/guard-base-branch-commit.sh"
1403
- chmod +x "$TARGET/.claude/hooks/guard-base-branch-commit.sh" 2>/dev/null || true
1404
- merge_settings --arg gd "$TARGET/.claude/hooks/guard-base-branch-commit.sh" \
1405
- '.hooks.PreToolUse = (((.hooks.PreToolUse // []) | map(select((.hooks[0].command // "") != $gd))) + [{matcher:"Bash",hooks:[{type:"command",command:$gd,timeout:10}]}])'
1406
- HOOK_NOTE="$HOOK_NOTE + commit-guard"
1407
-
1408
- # ---- raw-git guard PreToolUse(Bash) hook (all projects; init AND --upgrade; idempotent) ----
1409
- # Blocks raw gh issue create / pr create / pr merge / issue close and branch-from-base, and names the
1410
- # cckit verb to run instead (#364). Wired in the TRACKED settings.json with $CLAUDE_PROJECT_DIR, not
1411
- # settings.local.json: the local file is per-checkout and gitignored, so a guard wired there never
1412
- # reaches a worktree — which is exactly where agents work.
1413
- hook_write "$KIT_ROOT/templates/hooks/guard-raw-git-ops.sh.tmpl" "$TARGET/.claude/hooks/guard-raw-git-ops.sh"
1414
- chmod +x "$TARGET/.claude/hooks/guard-raw-git-ops.sh" 2>/dev/null || true
1415
- _TRACKED="$TARGET/.claude/settings.json"
1416
- [[ -f "$_TRACKED" ]] || echo '{}' > "$_TRACKED"
1417
- # A registration that is already there — in its own block or inside one the project arranged — is
1418
- # left where it is; the file is rewritten only when the guard had to be added (#448: the upgrade
1419
- # moved it into a new block on every run and still listed settings.json as preserved).
1420
- # shellcheck disable=SC2016 # $CLAUDE_PROJECT_DIR is expanded by Claude Code at hook time
1421
- jq --arg g '$CLAUDE_PROJECT_DIR/.claude/hooks/guard-raw-git-ops.sh' \
1422
- 'if ([ (.hooks.PreToolUse // [])[] | (.hooks // [])[] | .command ] | index($g)) != null then .
1423
- else .hooks.PreToolUse = ((.hooks.PreToolUse // []) + [{matcher:"Bash",hooks:[{type:"command",command:$g,timeout:10}]}])
1424
- end' "$_TRACKED" > "$_TRACKED.tmp" && json_write_minimal "$_TRACKED.tmp" "$_TRACKED" >/dev/null
1425
- echo " + .claude/hooks/guard-raw-git-ops.sh (PreToolUse Bash, wired in tracked settings.json: raw gh/git -> cckit verb)"
1426
-
1427
- # ---- session-mail hook (all projects; init AND --upgrade; idempotent) ----
1428
- # One script on four events delivers `cckit msg` mail to a running session (E257.5). Wired in the
1429
- # TRACKED settings.json for the same reason as the raw-git guard: mail has to reach worktrees. A
1430
- # registration that is already there is left as it is (its timeout or position may be the user's),
1431
- # and a project that listed the hook in `upgrade.removed` is not re-wired.
1432
- if ! _upgrade_excluded ".claude/hooks/kit-mail-check.sh"; then
1433
- hook_write "$KIT_ROOT/templates/hooks/kit-mail-check.sh.tmpl" "$TARGET/.claude/hooks/kit-mail-check.sh"
1434
- chmod +x "$TARGET/.claude/hooks/kit-mail-check.sh" 2>/dev/null || true
1435
- # shellcheck disable=SC2016 # $CLAUDE_PROJECT_DIR is expanded by Claude Code at hook time
1436
- jq --arg m 'bash "$CLAUDE_PROJECT_DIR/.claude/hooks/kit-mail-check.sh"' '
1437
- reduce (["PostToolUse","*"], ["UserPromptSubmit",""], ["SessionStart",""], ["Stop",""]) as [$e, $mt] (.;
1438
- if ([ (.hooks[$e] // [])[] | (.hooks // [])[] | .command ] | index($m)) != null then .
1439
- else .hooks[$e] = ((.hooks[$e] // [])
1440
- + [ (if $mt == "" then {} else {matcher: $mt} end) + {hooks: [{type: "command", command: $m, timeout: 10}]} ])
1441
- end)' "$_TRACKED" > "$_TRACKED.tmp" && json_write_minimal "$_TRACKED.tmp" "$_TRACKED" >/dev/null
1442
- echo " + .claude/hooks/kit-mail-check.sh (session mail, wired in tracked settings.json on 4 events)"
1443
- fi
1444
-
1445
- # ---- version-check SessionStart hook (all projects; idempotent) ---------
1446
- mkdir -p "$TARGET/.claude/hooks"
1447
- hook_write "$KIT_ROOT/templates/hooks/kit_version_check.sh.tmpl" "$TARGET/.claude/hooks/kit_version_check.sh"
1448
- chmod +x "$TARGET/.claude/hooks/kit_version_check.sh" 2>/dev/null || true
1449
- merge_settings --arg vc "$TARGET/.claude/hooks/kit_version_check.sh" \
1450
- '.hooks.SessionStart = (((.hooks.SessionStart // []) | map(select((.hooks[0].command // "") != $vc))) + [{matcher:"",hooks:[{type:"command",command:$vc,timeout:10}]}])'
1451
- HOOK_NOTE="$HOOK_NOTE + version-check"
1452
-
1453
- echo " + .claude/settings.local.json${HOOK_NOTE:+ (}${HOOK_NOTE# + }${HOOK_NOTE:+)}"
1454
- else
1455
- echo " · Codex adapter only: no .claude/ tree"
1456
- fi # ==== end Claude adapter only ====
1457
-
1458
- # ==== Codex adapter: hook scripts + their registration in .codex/hooks.json (E257.5) ====
1459
- # The SAME hook templates as the Claude adapter, rendered into .codex/hooks/: Codex sends the event
1460
- # fields they read (hook_event_name, cwd, tool_input.command) and honours the same answers (exit 2 +
1461
- # stderr blocks a tool, decision:block continues a Stop, additionalContext injects text).
1462
- # Not installed: the MemPalace hooks. mempal_save / mempal_precompact mine ~/.claude/projects/, the
1463
- # Claude Code transcript store, and no Codex transcript format has been validated against
1464
- # `mempalace mine` — see agent-compatibility.mdx.
1465
- CODEX_HOOKS_CHANGED=0
1466
- if adapter_has "$ADAPTERS" codex; then
1467
- # shellcheck source=/dev/null
1468
- . "$KIT_ROOT/scripts/lib/codex-hooks.sh"
1469
- # shellcheck source=/dev/null
1470
- . "$KIT_ROOT/scripts/lib/kit-manifest.sh"
1471
- mkdir -p "$TARGET/.codex/hooks"
1472
- _CX_SRC="$(mktemp)"
1473
- cp "$KIT_ROOT/templates/codex/hooks.json.tmpl" "$_CX_SRC"
1474
- _CX_HOOKS="repo-hygiene.sh kit_version_check.sh kit-mail-check.sh guard-base-branch-commit.sh guard-raw-git-ops.sh"
1475
- _cx_optional() { # <event> <matcher> <script> <timeout> — an opt-in hook joins the set to register
1476
- local frag; frag="$(mktemp)"
1477
- codex_hooks_fragment "$1" "$2" "$3" "$4" > "$frag" && codex_hooks_merge "$_CX_SRC" "$frag" >/dev/null
1478
- rm -f "$frag"
1479
- _CX_HOOKS="$_CX_HOOKS $3"
1480
- }
1481
- [[ "$PREPUSH_ENABLED" == "true" ]] && _cx_optional PreToolUse Bash prepush_gate.sh 120
1482
- [[ "$LOCAL_ON" == "true" ]] && _cx_optional SessionStart "" kit-local-status.sh 10
1483
- for _h in $_CX_HOOKS; do
1484
- _cx_dst="$TARGET/.codex/hooks/$_h"
1485
- _cx_n=$(( ${#WRITTEN[@]} + ${#UPGRADE_REFRESHED[@]} ))
1486
- if [[ $UPGRADE -eq 0 && $FORCE -eq 0 && -e "$_cx_dst" ]]; then
1487
- # A fresh init over a .codex/hooks/ the user already keeps: their file wins, as AGENTS.md does.
1488
- echo " = .codex/hooks/$_h (already there — kept; --force replaces it)"
1489
- else
1490
- hook_write "$KIT_ROOT/templates/hooks/$_h.tmpl" "$_cx_dst"
1491
- chmod +x "$_cx_dst" 2>/dev/null || true
1492
- fi
1493
- [[ $(( ${#WRITTEN[@]} + ${#UPGRADE_REFRESHED[@]} )) -gt $_cx_n ]] && CODEX_HOOKS_CHANGED=1
1494
- done
1495
- echo " + .codex/hooks/ ($(printf '%s' "$_CX_HOOKS" | sed 's/ /, /g'))"
1496
- # hooks.json is the project's file. cckit's handlers are merged in (a handler already registered for
1497
- # the event is skipped, everything else in the file is kept) and a merge that changes nothing does
1498
- # not rewrite it. It is recorded as kit-owned only when cckit created it or the manifest still
1499
- # proves it unmodified — a hooks.json holding the user's own entries is never claimed.
1500
- _CX_JSON="$TARGET/.codex/hooks.json"; _cx_own=0
1501
- if [[ ! -e "$_CX_JSON" ]]; then _cx_own=1
1502
- elif [[ "$( cd "$TARGET" && KIT_MANIFEST="$MANIFEST_REL" kit_manifest_verify .codex/hooks.json 2>/dev/null )" == "intact" ]]; then _cx_own=1
1503
- fi
1504
- if _upgrade_excluded ".codex/hooks.json"; then
1505
- UPGRADE_SKIPPED+=(".codex/hooks.json")
1506
- elif _cx_state="$(codex_hooks_merge "$_CX_JSON" "$_CX_SRC")"; then
1507
- case "$_cx_state" in
1508
- created) echo " + .codex/hooks.json (SessionStart / PreToolUse Bash / PostToolUse / UserPromptSubmit / Stop)"
1509
- [[ $UPGRADE -eq 1 ]] && UPGRADE_ADDED+=(".codex/hooks.json") ;;
1510
- merged) echo " ~ .codex/hooks.json (cckit's hooks added; the entries already there are kept)" ;;
1511
- *) [[ $UPGRADE -eq 1 ]] && UPGRADE_PRESERVED+=(".codex/hooks.json") ;;
1512
- esac
1513
- if [[ "$_cx_state" != "unchanged" ]]; then
1514
- CODEX_HOOKS_CHANGED=1
1515
- [[ $_cx_own -eq 1 ]] && WRITTEN+=(".codex/hooks.json")
1516
- fi
1517
- else
1518
- echo " ! .codex/hooks.json was left untouched — cckit's Codex hooks are NOT registered. Fix the file, then run: cckit init --upgrade" >&2
1519
- fi
1520
- rm -f "$_CX_SRC"
1521
- [[ "$MEMORY_BOOL" == "true" ]] && echo " · Codex adapter: no memory hooks — the transcript sweep reads Claude Code's ~/.claude/projects/ only"
1522
- fi # ==== end Codex adapter hooks ====
1523
-
1524
- # ---- recommended .gitignore entries (idempotent) ------------------------
1525
- # kit.manifest.json is kit-managed bookkeeping (content hashes + timestamps, re-stamped on every
1526
- # wire) — tracking it would dirty the tree on every session/upgrade, the exact churn #334 removes.
1527
- GI="$TARGET/.gitignore"
1528
- _GI_LOCAL=""; adapter_has "$ADAPTERS" claude && _GI_LOCAL=".claude/settings.local.json"
1529
- # .cckit/ is cckit's local state (consent, mail, handoff, autopilot runs) and .claude/worktrees/ holds
1530
- # the checkouts `cckit start` and `cckit task start` create: neither is ever committed (#487).
1531
- for _ig in "$_GI_LOCAL" "$MANIFEST_REL" ".kann/" ".cckit/" ".claude/worktrees/"; do
1532
- [[ -n "$_ig" ]] || continue
1533
- if [[ -f "$GI" ]]; then grep -qxF "$_ig" "$GI" || printf '%s\n' "$_ig" >> "$GI"; else printf '%s\n' "$_ig" > "$GI"; fi
1534
- done
1535
-
1536
- # ---- wire (converge) -----------------------------------------------------
1537
- # Runs on BOTH scaffold and --upgrade so every update re-wires (fixes the class of bug where
1538
- # /kit-update refreshed files but never re-ran the wiring → statusline/settings drifted). #369
1539
- if [[ -f "$KIT_ROOT/scripts/kit-wire.sh" ]] && adapter_has "$ADAPTERS" claude; then
1540
- # On --upgrade an EXISTING .claude/statusline.sh follows the same contract as safe_write: the
1541
- # conffiles guard in kit-operate keeps a customized (or untracked) shim; only a shim the kit
1542
- # provably owns intact is refreshed (#149).
1543
- _SHIM="$TARGET/.claude/statusline.sh"
1544
- _shim_before=""; [[ -f "$_SHIM" ]] && _shim_before="$(cat "$_SHIM" 2>/dev/null)"
1545
- if ( cd "$TARGET" && KIT_MANIFEST="$MANIFEST_REL" CLAUDE_PLUGIN_ROOT="$KIT_ROOT" KIT_ASSUME_YES=1 bash "$KIT_ROOT/scripts/kit-wire.sh" >/dev/null 2>&1 ); then
1546
- echo " + wired: statusline shim + settings.statusLine (kit-wire)"
1547
- fi
1548
- if [[ $UPGRADE -eq 1 && -n "$_shim_before" && "$_shim_before" == "$(cat "$_SHIM" 2>/dev/null)" ]]; then
1549
- UPGRADE_PRESERVED+=(".claude/statusline.sh")
1550
- fi
1551
- fi
1552
-
1553
- # ---- ownership manifest: record what this run wrote ----------------------
1554
- # Only the adapter files written NOW (never a preserved one — its content may be the user's), hashed
1555
- # after every merge above so the recorded hash is the file as it was left. Keyed by path, so a
1556
- # repeated upgrade updates nothing and adds nothing. This is what lets `cckit remove` and a later
1557
- # upgrade tell a kit-owned file from an edited one for BOTH adapters.
1558
- # shellcheck source=/dev/null
1559
- . "$KIT_ROOT/scripts/lib/kit-manifest.sh"
1560
- if [[ ${#WRITTEN[@]} -gt 0 ]]; then
1561
- ( cd "$TARGET" && for _w in "${WRITTEN[@]}"; do
1562
- if adapter_managed "$_w"; then printf '%s\t%s\n' "$(adapter_tier "$_w")" "$_w"; fi
1563
- done | sort -u | KIT_MANIFEST="$MANIFEST_REL" kit_manifest_record_batch init "$PLUGIN_VERSION" ) \
1564
- || echo " ! could not record the ownership manifest ($MANIFEST_REL)" >&2
1565
- fi
1566
-
1567
- # ---- summary -------------------------------------------------------------
1568
- echo ""
1569
- echo "claude-kit $([[ $UPGRADE -eq 1 ]] && echo upgraded || echo scaffolded) — profile: $PROFILE"
1570
- echo " Project : $NAME ($SLUG)"
1571
- echo " Repo : $REPO"
1572
- echo " Adapters: $ADAPTERS"
1573
- echo " Board : $([[ "$PROJECTS_V2" == "true" ]] && echo "Projects v2 #$PROJECT_NUMBER" || echo "off (gh issues only)")"
1574
- echo " Agents : $(echo $AGENTS | tr '\n' ' ')"
1575
- echo " Memory : $MEMORY_BOOL Plans: $PLANS_FORMAT Lang: $LANG_PREF kitVersion: $PLUGIN_VERSION"
1576
- echo " Spec Kit: $SPECKIT_ON Pre-push gate: $PREPUSH_ENABLED Local model: $LOCAL_ON Stack skills self-gate by package.json"
1577
- [[ "$PLAIN_ON" == "true" ]] && echo " Wording : plain language (draft, review, approve)"
1578
- [[ "$TASKS_DEFAULT" == "light" ]] && echo " Tasks : light tasks are the default list (cckit task; no GitHub issue per task)"
1579
-
1580
- if [[ $UPGRADE -eq 1 ]]; then
1581
- echo ""
1582
- echo " Upgrade -> kitVersion $PLUGIN_VERSION"
1583
- # What changed on disk, measured (the same block `--upgrade --dry-run` prints as "Would change").
1584
- # A file the helpers left alone but a later step merged into — .claude/settings.json gaining a hook
1585
- # registration — is in this block as M and is taken out of the Preserved list below.
1586
- if [[ -n "$_UP_SNAP" && -f "$_UP_SNAP/before" ]]; then
1587
- upgrade_snapshot "$TARGET" > "$_UP_SNAP/after"
1588
- upgrade_changes "$_UP_SNAP/before" "$_UP_SNAP/after" > "$_UP_SNAP/changes"
1589
- upgrade_changes_print "$_UP_SNAP/changes" "Changed on disk"
1590
- _UP_MEASURED=1
1591
- if [[ ${#UPGRADE_PRESERVED[@]} -gt 0 ]]; then
1592
- _up_kept=()
1593
- for _p in "${UPGRADE_PRESERVED[@]}"; do
1594
- grep -qxF "M $_p" "$_UP_SNAP/changes" || _up_kept+=("$_p")
1595
- done
1596
- UPGRADE_PRESERVED=(); [[ ${#_up_kept[@]} -gt 0 ]] && UPGRADE_PRESERVED=("${_up_kept[@]}")
1597
- fi
1598
- rm -rf "$_UP_SNAP"
1599
- fi
1600
- # The A rows above already name every added file; the helper's own list is printed only when no
1601
- # measurement was taken.
1602
- if [[ ${_UP_MEASURED:-0} -eq 0 && ${#UPGRADE_ADDED[@]} -gt 0 ]]; then echo " Added (new in this kit version):"; printf ' + %s\n' "${UPGRADE_ADDED[@]}"; fi
1603
- if [[ ${#UPGRADE_PRESERVED[@]} -gt 0 ]]; then echo " Preserved (your edits, untouched):"; printf ' = %s\n' "${UPGRADE_PRESERVED[@]}"; fi
1604
- if [[ ${#UPGRADE_SKIPPED[@]} -gt 0 ]]; then echo " Skipped (removed/renamed via kit.config upgrade):"; printf ' - %s\n' "${UPGRADE_SKIPPED[@]}"; fi
1605
- if [[ ${#UPGRADE_REFRESHED[@]} -gt 0 ]]; then echo " Refreshed (unmodified hook, now the current template):"; printf ' ~ %s\n' "${UPGRADE_REFRESHED[@]}"; fi
1606
- if [[ ${#UPGRADE_DRIFTED[@]} -gt 0 ]]; then echo " Drifted (customized hook, kept — diff it against templates/hooks/ by hand):"; printf ' ! %s\n' "${UPGRADE_DRIFTED[@]}"; fi
1607
- [[ $CODEX_HOOKS_CHANGED -eq 1 ]] && echo " Codex hooks changed: Codex skips a new or changed hook until you trust it — run /hooks in Codex."
1608
- else
1609
- echo ""
1610
- echo "Next steps:"
1611
- echo " 1. Review $(adapter_instructions "${ADAPTERS%% *}") and $CONFIG_REL"
1612
- # Labels and milestones belong to GitHub issues. A project whose task list is light tasks is not
1613
- # told to seed them (#487); `cckit init --yes` still creates them with the rest of the setup.
1614
- if [[ $SETUP_RUN -eq 0 && "$TASKS_DEFAULT" != "light" ]]; then
1615
- echo " 2. ./scripts/setup-labels.sh && ./scripts/setup-milestones.sh # seed the repo"
1616
- if [[ "$PROJECTS_V2" == "true" ]]; then echo " 3. ./scripts/capture-project-ids.sh # cache Projects v2 field IDs"; fi
1617
- fi
1618
- if [[ "$TASKS_DEFAULT" == "light" ]]; then
1619
- echo " 2. Add the first task: cckit task new \"<title>\" then: cckit next"
1620
- echo " 3. Start it: cckit task start <id>"
1621
- fi
1622
- [[ "$LOCAL_ON" == "true" ]] && echo " 4. /kit-doctor # local model layer: installs mlx-lm (recipe: integrations/mlx-lm.json) + starts mlx_lm.server"
1623
- # The page-design skill coordinates three third-party design skills. They are offered, never
1624
- # installed by init: each is an integration the person switches on and consents to (#504).
1625
- if grep -qx "page-design" <<<"$SKILLS"; then
1626
- echo " · Pages: the page-design skill is installed. It works with three third-party design skills, off until you add them:"
1627
- echo " cckit add impeccable && cckit add emil-design-eng && cckit add web-design-guidelines && cckit doctor --fix"
1628
- fi
1629
- adapter_has "$ADAPTERS" codex && echo " · Codex: commit .codex/, then run /hooks in Codex and trust the project hooks — Codex skips them until you do."
1630
- fi
1631
-
1632
- # ---- git + GitHub setup, then the closing report (#456) --------------------
1633
- if [[ $UPGRADE -eq 0 ]]; then
1634
- if [[ $SETUP_RUN -eq 1 ]]; then init_setup_run; fi
1635
- _init_finish
1636
- fi
1637
-
1638
- exit 0
2
+ # cckit-forwarding-stub: scripts/init.sh moved to lib/verbs/init.sh (#602). 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/verbs/init.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" "$@"