@jeiemgi/cckit 0.9.0 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (305) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/AGENTS.md +169 -21
  3. package/README.md +491 -35
  4. package/SECURITY.md +5 -0
  5. package/bin/cckit +182 -17
  6. package/cckit.config.json +1 -1
  7. package/commands/kit-doctor.md +13 -5
  8. package/commands/kit-export-project.md +0 -2
  9. package/commands/kit-export-training.md +6 -9
  10. package/commands/kit-init.md +43 -13
  11. package/commands/kit-routines.md +1 -1
  12. package/commands/kit-update.md +11 -6
  13. package/databases/supabase/guide.html +106 -0
  14. package/databases/supabase/nextjs/lib/supabase/client.ts +9 -0
  15. package/databases/supabase/nextjs/lib/supabase/server.ts +29 -0
  16. package/databases/supabase.json +70 -0
  17. package/integrations/emil-design-eng.json +41 -0
  18. package/integrations/graft.json +81 -0
  19. package/integrations/impeccable.json +42 -0
  20. package/integrations/integration.schema.json +215 -0
  21. package/integrations/lavish.json +43 -0
  22. package/integrations/mempalace.json +28 -0
  23. package/integrations/mlx-lm.json +32 -0
  24. package/integrations/web-design-guidelines.json +42 -0
  25. package/kit.config.schema.json +183 -5
  26. package/package.json +4 -1
  27. package/profiles/automation.json +7 -1
  28. package/profiles/content.json +10 -2
  29. package/profiles/marketing.json +57 -0
  30. package/profiles/minimal.json +7 -1
  31. package/profiles/research.json +7 -1
  32. package/profiles/software.json +7 -1
  33. package/recipes/nextjs-shadcn.json +49 -0
  34. package/scripts/agent-skills-external.txt +45 -0
  35. package/scripts/agent-skills-lint-test.sh +131 -0
  36. package/scripts/agent-skills-lint.sh +115 -0
  37. package/scripts/agent-template-lint-test.sh +42 -0
  38. package/scripts/agent-template-lint.sh +58 -0
  39. package/scripts/annotate-setup.sh +1 -1
  40. package/scripts/autopilot-run-test.sh +338 -0
  41. package/scripts/autopilot-run.sh +448 -0
  42. package/scripts/autopilot-test.sh +8 -0
  43. package/scripts/autopilot.sh +10 -1
  44. package/scripts/benchmark/benchmark-test.sh +85 -0
  45. package/scripts/benchmark/checkpoint-test.sh +314 -0
  46. package/scripts/benchmark/checkpoint.sh +408 -0
  47. package/scripts/benchmark/lib/model.sh +31 -6
  48. package/scripts/benchmark/report.sh +17 -2
  49. package/scripts/benchmark/run-quality.sh +36 -10
  50. package/scripts/benchmark/verb-timings-test.sh +124 -0
  51. package/scripts/benchmark/verb-timings.sh +149 -0
  52. package/scripts/check.sh +29 -19
  53. package/scripts/content-skills-test.sh +144 -0
  54. package/scripts/copilot-loop-test.sh +25 -0
  55. package/scripts/database-supabase-test.sh +121 -0
  56. package/scripts/docs-marketing-words-test.sh +73 -0
  57. package/scripts/docs-record-tables-test.sh +72 -0
  58. package/scripts/hook-adapter-test.sh +193 -0
  59. package/scripts/init-content-test.sh +225 -0
  60. package/scripts/init-guided-test.sh +474 -0
  61. package/scripts/init-recipes-test.sh +104 -0
  62. package/scripts/init-upgrade-test.sh +341 -2
  63. package/scripts/init.sh +746 -95
  64. package/scripts/instruction-budget-baseline.txt +8 -0
  65. package/scripts/instruction-budget-lint-test.sh +166 -0
  66. package/scripts/instruction-budget-lint.sh +219 -0
  67. package/scripts/integrations-check-test.sh +200 -0
  68. package/scripts/integrations-check.sh +157 -0
  69. package/scripts/kit-add-test.sh +214 -0
  70. package/scripts/kit-add.sh +305 -5
  71. package/scripts/kit-adopt-test.sh +16 -0
  72. package/scripts/kit-adopt.sh +3 -2
  73. package/scripts/kit-digest.sh +2 -2
  74. package/scripts/kit-doctor-test.sh +293 -0
  75. package/scripts/kit-doctor.sh +272 -140
  76. package/scripts/kit-export-project-test.sh +3 -3
  77. package/scripts/kit-remove-test.sh +19 -0
  78. package/scripts/kit-routines.sh +2 -2
  79. package/scripts/kit-self-update.sh +1 -1
  80. package/scripts/kit-version-check-test.sh +4 -0
  81. package/scripts/kit-version-check.sh +4 -2
  82. package/scripts/knowledge-lint.sh +4 -4
  83. package/scripts/leak-fence-test.sh +89 -0
  84. package/scripts/lib/adapter-select-test.sh +136 -0
  85. package/scripts/lib/adapter-select.sh +158 -0
  86. package/scripts/lib/agent-def-test.sh +69 -0
  87. package/scripts/lib/agent-def.sh +106 -0
  88. package/scripts/lib/agent-launch-test.sh +212 -0
  89. package/scripts/lib/agent-launch.sh +335 -0
  90. package/scripts/lib/board-view-test.sh +11 -0
  91. package/scripts/lib/board-view.sh +42 -26
  92. package/scripts/lib/branch-owner-test.sh +26 -0
  93. package/scripts/lib/branch-owner.sh +16 -9
  94. package/scripts/lib/captain-test.sh +105 -0
  95. package/scripts/lib/captain.sh +87 -8
  96. package/scripts/lib/codex-hooks-test.sh +100 -0
  97. package/scripts/lib/codex-hooks.sh +69 -0
  98. package/scripts/lib/commitlint.sh +1 -1
  99. package/scripts/lib/content-kinds-gc-test.sh +88 -0
  100. package/scripts/lib/copilot-test.sh +70 -4
  101. package/scripts/lib/copilot.sh +66 -14
  102. package/scripts/lib/effort-dispatch-test.sh +3 -3
  103. package/scripts/lib/effort-metrics-test.sh +178 -1
  104. package/scripts/lib/effort-metrics.sh +175 -35
  105. package/scripts/lib/effort-ops-test.sh +205 -7
  106. package/scripts/lib/effort-ops.sh +198 -43
  107. package/scripts/lib/effort-parity-test.sh +49 -13
  108. package/scripts/lib/effort-plan-test.sh +337 -0
  109. package/scripts/lib/effort-plan.sh +200 -23
  110. package/scripts/lib/effort.sh +56 -11
  111. package/scripts/lib/errors-header-test.sh +1 -1
  112. package/scripts/lib/gh-project-test.sh +35 -1
  113. package/scripts/lib/gh-project.sh +23 -16
  114. package/scripts/lib/gh-rest-test.sh +32 -3
  115. package/scripts/lib/gh-rest.sh +17 -2
  116. package/scripts/lib/hook-refresh.sh +1 -1
  117. package/scripts/lib/init-github.sh +412 -0
  118. package/scripts/lib/init-guide.sh +630 -0
  119. package/scripts/lib/integration-install-test.sh +343 -0
  120. package/scripts/lib/integration-install.sh +257 -0
  121. package/scripts/lib/integrations-test.sh +366 -0
  122. package/scripts/lib/integrations.sh +244 -0
  123. package/scripts/lib/kinds-test.sh +125 -0
  124. package/scripts/lib/kinds.sh +66 -0
  125. package/scripts/lib/kit-brief-test.sh +22 -3
  126. package/scripts/lib/kit-brief.sh +45 -5
  127. package/scripts/lib/kit-config-resolve.sh +2 -2
  128. package/scripts/lib/kit-config-test.sh +64 -1
  129. package/scripts/lib/kit-config.sh +37 -1
  130. package/scripts/lib/kit-events.sh +7 -0
  131. package/scripts/lib/kit-gc-test.sh +173 -1
  132. package/scripts/lib/kit-gc.sh +226 -37
  133. package/scripts/lib/kit-hotfix.sh +216 -0
  134. package/scripts/lib/kit-interview-test.sh +93 -0
  135. package/scripts/lib/kit-interview.sh +117 -8
  136. package/scripts/lib/kit-lib-test.sh +1 -1
  137. package/scripts/lib/kit-lib.sh +3 -3
  138. package/scripts/lib/kit-local.sh +2 -2
  139. package/scripts/lib/kit-manifest.sh +33 -1
  140. package/scripts/lib/kit-profile-test.sh +3 -3
  141. package/scripts/lib/kit-status-test.sh +112 -4
  142. package/scripts/lib/kit-status.sh +246 -16
  143. package/scripts/lib/kit-task-ops-test.sh +37 -0
  144. package/scripts/lib/kit-task-ops.sh +175 -31
  145. package/scripts/lib/kto-hotfix-test.sh +232 -0
  146. package/scripts/lib/kto-task-close-test.sh +1 -1
  147. package/scripts/lib/kto-task-new-test.sh +95 -0
  148. package/scripts/lib/kto-task-pr-merge-test.sh +37 -3
  149. package/scripts/lib/kto-task-pr-test.sh +70 -0
  150. package/scripts/lib/leak-fence.sh +89 -0
  151. package/scripts/lib/light-task-run-test.sh +255 -0
  152. package/scripts/lib/light-task-test.sh +309 -0
  153. package/scripts/lib/light-task.sh +706 -0
  154. package/scripts/lib/next-test.sh +99 -0
  155. package/scripts/lib/next.sh +9 -3
  156. package/scripts/lib/orchestration-runtime-test.sh +72 -0
  157. package/scripts/lib/orchestration-runtime.sh +57 -5
  158. package/scripts/lib/plan-machine-test.sh +15 -2
  159. package/scripts/lib/plan-machine.sh +20 -7
  160. package/scripts/lib/plan-next-test.sh +1 -1
  161. package/scripts/lib/plan-next.sh +4 -4
  162. package/scripts/lib/pr-evidence-test.sh +3 -3
  163. package/scripts/lib/pr-evidence.sh +1 -1
  164. package/scripts/lib/qa-lane-test.sh +626 -0
  165. package/scripts/lib/qa-lane.sh +1357 -0
  166. package/scripts/lib/qa-lanes-test.sh +175 -0
  167. package/scripts/lib/react-detect.sh +1 -1
  168. package/scripts/lib/render-test.sh +1 -1
  169. package/scripts/lib/review-page-test.sh +318 -0
  170. package/scripts/lib/review-page.sh +369 -0
  171. package/scripts/lib/review-stage-test.sh +62 -11
  172. package/scripts/lib/review-stage.sh +42 -60
  173. package/scripts/lib/role-identity-test.sh +65 -0
  174. package/scripts/lib/role-identity.sh +25 -2
  175. package/scripts/lib/secret-guard.sh +3 -3
  176. package/scripts/lib/session-registry-test.sh +111 -0
  177. package/scripts/lib/session-registry.sh +233 -0
  178. package/scripts/lib/stage-receipt-test.sh +14 -1
  179. package/scripts/lib/stage-receipt.sh +13 -8
  180. package/scripts/lib/task-source-file.sh +309 -0
  181. package/scripts/lib/task-source.sh +130 -0
  182. package/scripts/lib/upgrade-report-test.sh +120 -0
  183. package/scripts/lib/upgrade-report.sh +138 -0
  184. package/scripts/lib/version-bump.sh +3 -3
  185. package/scripts/lib/wave-result-test.sh +80 -0
  186. package/scripts/lib/wave-result.sh +127 -0
  187. package/scripts/lib/worker-brief-test.sh +5 -0
  188. package/scripts/lib/worker-brief.sh +2 -2
  189. package/scripts/lib/worktree-issue-test.sh +30 -1
  190. package/scripts/lib/worktree-issue.sh +82 -12
  191. package/scripts/lib/worktree-ports-test.sh +57 -4
  192. package/scripts/lib/worktree-start-test.sh +197 -0
  193. package/scripts/lib/worktree-start.sh +153 -31
  194. package/scripts/lib/zsh-safety-test.sh +19 -3
  195. package/scripts/marketing-walkthrough-test.sh +152 -0
  196. package/scripts/night-grant-test.sh +37 -0
  197. package/scripts/night-grant.sh +448 -0
  198. package/scripts/night-run-test.sh +8 -0
  199. package/scripts/night-run.mjs +275 -0
  200. package/scripts/night-run.test.mjs +324 -0
  201. package/scripts/orchestrate-test.sh +190 -0
  202. package/scripts/orchestrate.sh +79 -8
  203. package/scripts/portable-test.sh +11 -2
  204. package/scripts/publish.sh +28 -3
  205. package/scripts/review-lint-test.sh +7 -7
  206. package/scripts/review-lint.sh +2 -2
  207. package/scripts/review-rules.conf +8 -0
  208. package/scripts/rule-recipes-test.sh +96 -0
  209. package/scripts/self-install-test.sh +39 -9
  210. package/scripts/setup-labels.sh +18 -1
  211. package/scripts/setup-milestones.sh +1 -1
  212. package/scripts/showcase.sh +1 -1
  213. package/scripts/skill-frontmatter-lint-test.sh +4 -4
  214. package/scripts/skill-frontmatter-lint.sh +1 -1
  215. package/scripts/status-test.sh +113 -2
  216. package/scripts/status.sh +16 -3
  217. package/scripts/task-sync-test.sh +154 -0
  218. package/scripts/task-sync.sh +243 -32
  219. package/scripts/test-runner-test.sh +158 -0
  220. package/scripts/test.sh +131 -23
  221. package/scripts/update-path-test.sh +279 -0
  222. package/scripts/ux-ds-audit.sh +1 -1
  223. package/scripts/ux-graph-scan.sh +6 -6
  224. package/scripts/wave-worker.sh +54 -0
  225. package/skills/kit-add/SKILL.md +77 -0
  226. package/skills/kit-autopilot/SKILL.md +123 -12
  227. package/skills/kit-cleanup/SKILL.md +5 -2
  228. package/skills/kit-contribute/SKILL.md +4 -4
  229. package/skills/kit-docs-writer/SKILL.md +16 -6
  230. package/skills/kit-effort-close/SKILL.md +17 -8
  231. package/skills/kit-effort-new/SKILL.md +15 -9
  232. package/skills/kit-effort-pr/SKILL.md +15 -7
  233. package/skills/kit-effort-start/SKILL.md +5 -2
  234. package/skills/kit-gc/SKILL.md +5 -2
  235. package/skills/kit-next/SKILL.md +5 -1
  236. package/skills/kit-onboard/SKILL.md +3 -3
  237. package/skills/kit-page/SKILL.md +93 -0
  238. package/skills/kit-plan-next/SKILL.md +8 -4
  239. package/skills/kit-security-sweep/SKILL.md +1 -3
  240. package/skills/kit-ship/SKILL.md +2 -3
  241. package/skills/kit-status/SKILL.md +35 -4
  242. package/skills/kit-task-new/SKILL.md +3 -3
  243. package/skills/kit-task-pr/SKILL.md +7 -2
  244. package/skills/kit-task-pr-merge/SKILL.md +7 -2
  245. package/skills/kit-task-start/SKILL.md +7 -7
  246. package/skills/kit-task-sync/SKILL.md +19 -3
  247. package/skills/kit-ux-audit/SKILL.md +3 -2
  248. package/templates/agents/auto-dev.md +5 -4
  249. package/templates/agents/backend.md +1 -1
  250. package/templates/agents/designer.md +2 -0
  251. package/templates/agents/devops.md +1 -1
  252. package/templates/agents/editor.md +9 -1
  253. package/templates/agents/frontend.md +1 -1
  254. package/templates/agents/local-delegate.md +1 -1
  255. package/templates/agents/pm.md +5 -5
  256. package/templates/agents/tech-lead.md +1 -1
  257. package/templates/benchmarks/SCHEMA.md +9 -3
  258. package/templates/codex/hooks.json.tmpl +89 -0
  259. package/templates/hooks/guard-base-branch-commit.sh.tmpl +13 -7
  260. package/templates/hooks/guard-raw-git-ops.sh.tmpl +12 -12
  261. package/templates/hooks/mempal_followup.sh.tmpl +2 -2
  262. package/templates/hooks/mempal_session_start.sh.tmpl +1 -1
  263. package/templates/hooks/prepush_gate.sh.tmpl +4 -2
  264. package/templates/hooks/repo-hygiene.sh.tmpl +3 -2
  265. package/templates/instructions.md.tmpl +174 -0
  266. package/templates/kit.config.json.tmpl +3 -3
  267. package/templates/knowledge-INDEX.md.tmpl +1 -1
  268. package/templates/lib/kit-sigil.sh.tmpl +1 -1
  269. package/templates/rules/authoring.md +106 -0
  270. package/templates/rules/branch-naming.md +40 -4
  271. package/templates/rules/code-retrieval.md +63 -0
  272. package/templates/rules/delegation-brief.md +0 -3
  273. package/templates/rules/design-routing.md +3 -3
  274. package/templates/rules/effort-model.md +14 -10
  275. package/templates/rules/gate-and-review.md +94 -0
  276. package/templates/rules/issue-lifecycle.md +88 -0
  277. package/templates/rules/knowledge-base.md +1 -1
  278. package/templates/rules/mempalace.md +1 -1
  279. package/templates/rules/merge-safety.md +108 -0
  280. package/templates/rules/naming-and-ids.md +23 -17
  281. package/templates/rules/plain-language.md +59 -0
  282. package/templates/rules/plan-next.md +9 -11
  283. package/templates/rules/react-annotate.md +6 -0
  284. package/templates/rules/review-pages.md +49 -0
  285. package/templates/rules/risk-tiered-review.md +13 -4
  286. package/templates/rules/shared-checkout.md +106 -0
  287. package/templates/rules/skill-gaps.md +2 -7
  288. package/templates/rules/task-management.md +13 -1
  289. package/templates/skills/brand-voice/SKILL.md +91 -0
  290. package/templates/skills/brand-voice/references/voice-template.md +61 -0
  291. package/templates/skills/campaign/SKILL.md +123 -0
  292. package/templates/skills/campaign/references/plan-template.md +55 -0
  293. package/templates/skills/concrete/SKILL.md +2 -2
  294. package/templates/skills/copywriting/SKILL.md +8 -1
  295. package/templates/skills/feature-build-refine/SKILL.md +2 -4
  296. package/templates/skills/morning-briefing/SKILL.md +2 -2
  297. package/templates/skills/page-design/SKILL.md +145 -0
  298. package/templates/skills/page-design/add.json +5 -0
  299. package/templates/skills/page-design/references/design-file-template.md +40 -0
  300. package/templates/skills/page-design/references/generic-page-patterns.md +43 -0
  301. package/templates/skills/page-design/references/minimum-rules.md +42 -0
  302. package/templates/skills/speckit/SKILL.md +4 -5
  303. package/templates/skills/supabase-patterns/SKILL.md +1 -1
  304. package/commands/kit-add.md +0 -42
  305. package/templates/CLAUDE.md.tmpl +0 -106
@@ -0,0 +1,412 @@
1
+ #!/usr/bin/env bash
2
+ # shellcheck shell=bash
3
+ # init-github.sh — the git + GitHub half of `cckit init` (#456): every step between "a folder with
4
+ # the kit files in it" and "a repository `cckit start` can work on".
5
+ #
6
+ # The steps, in order. Each one checks first and is SKIPPED when its result is already there, so a
7
+ # re-run on a set-up project changes nothing; each reports done / skipped / failed through
8
+ # init_step (init-guide.sh), and a failed step never stops the ones after it.
9
+ #
10
+ # 1. git repository git init (branch main) when the folder is not one
11
+ # 2. first commit only on a repository with no commit yet (the cckit files are in it)
12
+ # 3. cckit files commit on a repository that already had commits: ONE commit holding the files
13
+ # cckit init wrote, on the base branch (#487). Skipped once the project
14
+ # config is tracked. Never an env file, never an ignored file
15
+ # 4. GitHub repository adopt `origin`, or link / create <owner>/<name> (private unless IG_VISIBILITY=public)
16
+ # 5. base branch create it from the current commit and push it; when GitHub already has
17
+ # it, push the cckit files commit to it
18
+ # 6. default branch set to the base branch — only on a repository this run created
19
+ # 7. labels create the ones setup-labels.sh lists and the repository lacks
20
+ # 8. milestones setup-milestones.sh (it creates only the missing ones)
21
+ # 9. head branches "automatically delete head branches" on merge
22
+ # 10. branch protection the base branch: pull request required, branch up to date, no
23
+ # force-push, no deletion. A plan that refuses it (HTTP 403 on a private
24
+ # repository of a free account) is a skip with the reason, not a failure
25
+ # 11. Projects v2 ids only when the project has a board
26
+ # 12. doctor the read-only report
27
+ #
28
+ # Steps 4-11 write to GitHub. init_setup_plan prints all of them BEFORE any runs, and the caller
29
+ # (init.sh) runs init_setup_run only after one confirmation: a yes on a terminal, or --yes.
30
+ #
31
+ # Inputs (set by the caller): IG_TARGET (project dir), IG_REPO (owner/name), IG_BASE (base branch),
32
+ # IG_VISIBILITY (private|public), IG_PROJECTS_V2 (true|false), IG_KIT_ROOT (the kit), IG_DOCTOR (1|0),
33
+ # IG_CONFIG_REL (the project config, relative to IG_TARGET).
34
+ # init_setup_plan print the numbered plan (local reads only)
35
+ # init_setup_run run it; rc 0, failures are counted in INIT_FAILED
36
+ # init_scaffold_pending rc 0 when the repository has commits and the cckit files are not in one
37
+ # init_scaffold_command the git command that commits them by hand (for a run with no setup)
38
+ # init_base_missing rc 0 when the base branch exists neither here nor on origin
39
+ # Requires: git, gh, jq. bash 3.2 compatible.
40
+ # errors: best-effort — a failed step is reported and counted in INIT_FAILED; the run continues
41
+
42
+ IG_CREATED=0 # 1 when THIS run created the GitHub repository
43
+ IG_REPO_OK=0 # 1 once the project has a GitHub repository to write to
44
+ IG_FIRST_COMMIT=0 # 1 when THIS run made the repository's first commit (the cckit files are in it)
45
+
46
+ _GS_SCAFFOLD_MSG="chore: add the cckit project files"
47
+ # The top-level paths cckit init writes into. `scripts/` is narrowed to the files the kit ships
48
+ # (_gs_scaffold_files), so a script of the project's own is never swept into the commit.
49
+ _GS_SCAFFOLD_PATHS=".gitignore CLAUDE.md AGENTS.md cckit.config.json .claude .agents .codex benchmarks knowledge scripts"
50
+
51
+ _gs_git() { git -C "$IG_TARGET" "$@"; }
52
+ _gs_last() { printf '%s' "$1" | grep -v '^[[:space:]]*$' | tail -1 | cut -c1-200; }
53
+ _gs_refused_by_plan() { grep -qiE 'HTTP 403|Upgrade to GitHub' <<<"$1"; }
54
+
55
+ # init_setup_plan -> what will be attempted, from local state alone (no network).
56
+ init_setup_plan() {
57
+ local in_git=0 has_commit=0 origin="" n=0
58
+ if _gs_git rev-parse --is-inside-work-tree >/dev/null 2>&1; then
59
+ in_git=1
60
+ _gs_git rev-parse --verify -q HEAD >/dev/null 2>&1 && has_commit=1
61
+ origin="$(_gs_git remote get-url origin 2>/dev/null || true)"
62
+ fi
63
+ echo " On this computer:"
64
+ if [ "$in_git" -eq 0 ]; then n=$((n + 1)); echo " $n. Start version control in $IG_TARGET (git init)"; fi
65
+ if [ "$has_commit" -eq 0 ]; then
66
+ n=$((n + 1)); echo " $n. Save the first version (first commit, the cckit files included)"
67
+ elif ! _gs_config_tracked; then
68
+ n=$((n + 1)); echo " $n. Save the cckit files as one commit on '$IG_BASE' (no env file, nothing git ignores)"
69
+ fi
70
+ [ "$n" -eq 0 ] && echo " (nothing — it is already a git repository and the cckit files are committed)"
71
+ echo " On GitHub ($IG_REPO):"
72
+ n=$((n + 1))
73
+ if [ -n "$origin" ]; then
74
+ echo " $n. Use the repository this folder is already connected to"
75
+ else
76
+ echo " $n. Create the $(printf '%s' "$IG_VISIBILITY" | tr '[:lower:]' '[:upper:]') repository $IG_REPO (or connect to it when it exists)"
77
+ fi
78
+ n=$((n + 1)); echo " $n. Create the branch '$IG_BASE' and push it, the cckit files commit included; make it the default branch of a new repository"
79
+ n=$((n + 1)); echo " $n. Add the labels and milestones the workflow uses (only the missing ones)"
80
+ n=$((n + 1)); echo " $n. Turn on \"automatically delete head branches\" after a merge"
81
+ n=$((n + 1)); echo " $n. Protect '$IG_BASE': changes arrive by pull request, up to date, no force-push"
82
+ if [ "${IG_PROJECTS_V2:-false}" = "true" ]; then n=$((n + 1)); echo " $n. Read the Projects v2 board's field ids"; fi
83
+ echo " Then: the cckit doctor report."
84
+ echo " A step whose result is already there is skipped."
85
+ }
86
+
87
+ _gs_step_git_init() {
88
+ if _gs_git rev-parse --is-inside-work-tree >/dev/null 2>&1; then
89
+ init_step skipped "git repository" "already one"; return 0
90
+ fi
91
+ if _gs_git init -q 2>/dev/null && _gs_git symbolic-ref HEAD refs/heads/main 2>/dev/null; then
92
+ init_step done "git repository" "git init, branch main"
93
+ else
94
+ init_step failed "git repository" "git init did not work in $IG_TARGET"
95
+ fi
96
+ }
97
+
98
+ _gs_step_first_commit() {
99
+ local e out
100
+ _gs_git rev-parse --is-inside-work-tree >/dev/null 2>&1 || { init_step skipped "first commit" "no git repository (see above)"; return 0; }
101
+ if _gs_git rev-parse --verify -q HEAD >/dev/null 2>&1; then
102
+ init_step skipped "first commit" "the repository already has commits"; return 0
103
+ fi
104
+ # An env file is never part of the first commit.
105
+ for e in .env .env.local; do
106
+ [ -f "$IG_TARGET/$e" ] || continue
107
+ _gs_git check-ignore -q "$e" 2>/dev/null || printf '%s\n' "$e" >> "$IG_TARGET/.gitignore"
108
+ done
109
+ if [ -z "$(_gs_git config user.name 2>/dev/null || true)" ] || [ -z "$(_gs_git config user.email 2>/dev/null || true)" ]; then
110
+ init_step failed "first commit" "git does not know who you are yet. Run: git config --global user.name \"Your Name\" and git config --global user.email \"you@example.com\", then run cckit init again"
111
+ return 0
112
+ fi
113
+ if out="$(_gs_git add -A 2>&1 && _gs_git commit -q -m "chore: set up the project with cckit" 2>&1)"; then
114
+ IG_FIRST_COMMIT=1
115
+ init_step done "first commit"
116
+ else
117
+ init_step failed "first commit" "$(_gs_last "$out")"
118
+ fi
119
+ }
120
+
121
+ # ── the cckit files commit (#487) ────────────────────────────────────────────────────────────────
122
+ # A project that already had commits kept every file cckit init wrote untracked: a worktree cut from
123
+ # the base branch had no .claude/ and no CLAUDE.md, and a teammate who cloned got no setup.
124
+
125
+ _gs_config_tracked() {
126
+ [ -n "${IG_CONFIG_REL:-}" ] && _gs_git ls-files --error-unmatch -- "$IG_CONFIG_REL" >/dev/null 2>&1
127
+ }
128
+
129
+ # _gs_scaffold_specs -> the paths of _GS_SCAFFOLD_PATHS that exist in the project, one per line.
130
+ _gs_scaffold_specs() {
131
+ local p
132
+ for p in $_GS_SCAFFOLD_PATHS; do
133
+ if [ -e "$IG_TARGET/$p" ]; then printf '%s\n' "$p"; fi
134
+ done
135
+ }
136
+
137
+ # _gs_scaffold_files -> NUL-separated: the untracked or modified files under those paths that belong
138
+ # in the commit. Git's ignore rules apply (so settings.local.json, the manifest and .cckit/ never
139
+ # appear); an env file and a worktree are left out by name; under scripts/ only a file the kit
140
+ # ships at the same path is kept.
141
+ _gs_scaffold_files() {
142
+ local specs f
143
+ specs="$(_gs_scaffold_specs)"
144
+ [ -n "$specs" ] || return 0
145
+ # shellcheck disable=SC2086 # one pathspec per word; none of the names holds a space
146
+ _gs_git ls-files -z --others --modified --exclude-standard -- $specs 2>/dev/null \
147
+ | while IFS= read -r -d '' f; do
148
+ case "$f" in
149
+ .claude/worktrees/*) continue ;;
150
+ .env|.env.*|*/.env|*/.env.*|*.env) continue ;;
151
+ scripts/*) [ -e "$IG_KIT_ROOT/$f" ] || continue ;;
152
+ esac
153
+ [ -e "$IG_TARGET/$f" ] || continue
154
+ printf '%s\0' "$f"
155
+ done
156
+ }
157
+
158
+ # init_scaffold_pending -> rc 0 when the repository has commits and the project config is in none.
159
+ init_scaffold_pending() {
160
+ _gs_git rev-parse --verify -q HEAD >/dev/null 2>&1 || return 1
161
+ [ -n "${IG_CONFIG_REL:-}" ] && [ -e "$IG_TARGET/$IG_CONFIG_REL" ] || return 1
162
+ ! _gs_config_tracked
163
+ }
164
+
165
+ # init_scaffold_command -> the command that makes the same commit by hand. `git add` skips what git
166
+ # ignores; this form adds every file under scripts/, the project's own included.
167
+ init_scaffold_command() {
168
+ printf 'git add %s && git commit -m "%s"' "$(_gs_scaffold_specs | tr '\n' ' ' | sed 's/ $//')" "$_GS_SCAFFOLD_MSG"
169
+ }
170
+
171
+ # init_base_missing -> rc 0 when IG_BASE is neither a local branch nor a branch of origin (cached).
172
+ init_base_missing() {
173
+ _gs_git rev-parse --is-inside-work-tree >/dev/null 2>&1 || return 0
174
+ _gs_git show-ref --verify -q "refs/heads/$IG_BASE" && return 1
175
+ _gs_git show-ref --verify -q "refs/remotes/origin/$IG_BASE" && return 1
176
+ return 0
177
+ }
178
+
179
+ _gs_step_scaffold_commit() {
180
+ local cur out n=0 f files=()
181
+ _gs_git rev-parse --verify -q HEAD >/dev/null 2>&1 || { init_step skipped "cckit files commit" "no commit to add to (see above)"; return 0; }
182
+ if [ "${IG_FIRST_COMMIT:-0}" -eq 1 ]; then init_step skipped "cckit files commit" "they are in the first commit"; return 0; fi
183
+ if _gs_config_tracked; then init_step skipped "cckit files commit" "already committed"; return 0; fi
184
+ cur="$(_gs_git symbolic-ref --short -q HEAD 2>/dev/null || true)"
185
+ if [ -z "$cur" ]; then
186
+ init_step failed "cckit files commit" "no branch is checked out here. Run: git switch $IG_BASE — then cckit init --yes again"
187
+ return 0
188
+ fi
189
+ # The commit goes on the base branch. A base branch that does not exist yet is created from this
190
+ # commit by the next step, so the checked-out branch stands in for it.
191
+ if [ "$cur" != "$IG_BASE" ] && { _gs_git show-ref --verify -q "refs/heads/$IG_BASE" || _gs_git show-ref --verify -q "refs/remotes/origin/$IG_BASE"; }; then
192
+ init_step failed "cckit files commit" "this folder is on '$cur' and the files belong on '$IG_BASE'. Run: git switch $IG_BASE — then cckit init --yes again"
193
+ return 0
194
+ fi
195
+ while IFS= read -r -d '' f; do files[n]="$f"; n=$((n + 1)); done < <(_gs_scaffold_files)
196
+ if [ "$n" -eq 0 ]; then init_step skipped "cckit files commit" "no cckit file is waiting"; return 0; fi
197
+ if [ -z "$(_gs_git config user.name 2>/dev/null || true)" ] || [ -z "$(_gs_git config user.email 2>/dev/null || true)" ]; then
198
+ init_step failed "cckit files commit" "git does not know who you are yet. Run: git config --global user.name \"Your Name\" and git config --global user.email \"you@example.com\", then run cckit init again"
199
+ return 0
200
+ fi
201
+ # --only: the commit holds these paths and nothing else the project had staged.
202
+ if out="$(_gs_git add -- "${files[@]}" 2>&1 && _gs_git commit -q --only -m "$_GS_SCAFFOLD_MSG" -- "${files[@]}" 2>&1)"; then
203
+ init_step done "cckit files commit" "$n files on $cur"
204
+ else
205
+ init_step failed "cckit files commit" "$(_gs_last "$out")"
206
+ fi
207
+ }
208
+
209
+ # _gs_scaffold_unpushed -> rc 0 when the local base branch holds a cckit files commit origin lacks.
210
+ _gs_scaffold_unpushed() {
211
+ local subjects
212
+ _gs_git show-ref --verify -q "refs/heads/$IG_BASE" || return 1
213
+ _gs_git fetch -q origin "$IG_BASE" 2>/dev/null || true
214
+ subjects="$(_gs_git log --format=%s "origin/$IG_BASE..$IG_BASE" 2>/dev/null || true)"
215
+ grep -qxF "$_GS_SCAFFOLD_MSG" <<<"$subjects"
216
+ }
217
+
218
+ _gs_step_repo() {
219
+ local origin out url
220
+ # IG_REPO is the name init.sh resolved: `gh repo view` in the folder when it has a remote.
221
+ _gs_git rev-parse --is-inside-work-tree >/dev/null 2>&1 || { init_step skipped "GitHub repository" "no git repository (see above)"; return 0; }
222
+ origin="$(_gs_git remote get-url origin 2>/dev/null || true)"
223
+ if [ -n "$origin" ]; then
224
+ IG_REPO_OK=1
225
+ init_step skipped "GitHub repository" "already connected to $IG_REPO"; return 0
226
+ fi
227
+ case "$IG_REPO" in
228
+ */*) ;;
229
+ *) init_step failed "GitHub repository" "could not read your GitHub account. Run: gh auth login — then run cckit init again"; return 0 ;;
230
+ esac
231
+ if out="$(gh repo view "$IG_REPO" --json url,sshUrl -q '[.url, .sshUrl] | @tsv' 2>/dev/null)" && [ -n "$out" ]; then
232
+ url="$(printf '%s' "$out" | cut -f1).git"
233
+ [ "${IG_PROTO:-https}" = "ssh" ] && [ -n "$(printf '%s' "$out" | cut -f2)" ] && url="$(printf '%s' "$out" | cut -f2)"
234
+ if _gs_git remote add origin "$url" 2>/dev/null; then
235
+ IG_REPO_OK=1; init_step done "GitHub repository" "$IG_REPO exists — connected this folder to it"
236
+ else
237
+ init_step failed "GitHub repository" "could not connect this folder to $IG_REPO"
238
+ fi
239
+ return 0
240
+ fi
241
+ if out="$(gh repo create "$IG_REPO" "--$IG_VISIBILITY" --source "$IG_TARGET" --remote origin 2>&1)"; then
242
+ IG_CREATED=1; IG_REPO_OK=1
243
+ init_step done "GitHub repository" "created $IG_REPO ($IG_VISIBILITY)"
244
+ else
245
+ init_step failed "GitHub repository" "$(_gs_last "$out")"
246
+ fi
247
+ }
248
+
249
+ _gs_remote_has() { _gs_git ls-remote --exit-code --heads origin "$1" >/dev/null 2>&1; }
250
+
251
+ _gs_step_base_branch() {
252
+ local cur out
253
+ [ "$IG_REPO_OK" -eq 1 ] || { init_step skipped "branch $IG_BASE" "needs the GitHub repository (see above)"; return 0; }
254
+ if ! _gs_git rev-parse --verify -q HEAD >/dev/null 2>&1; then
255
+ init_step skipped "branch $IG_BASE" "nothing to push yet — the repository has no commit"; return 0
256
+ fi
257
+ cur="$(_gs_git symbolic-ref --short -q HEAD 2>/dev/null || true)"
258
+ if _gs_remote_has "$IG_BASE"; then
259
+ # GitHub has the branch. The one thing left to send is a cckit files commit made on it here.
260
+ if _gs_scaffold_unpushed; then
261
+ if out="$(_gs_git push -q origin "$IG_BASE" 2>&1)"; then
262
+ init_step done "branch $IG_BASE" "pushed the cckit files commit"
263
+ else
264
+ init_step failed "branch $IG_BASE" "the cckit files commit is saved here but GitHub refused the push ($(_gs_last "$out")). If '$IG_BASE' is protected, send the commit as a pull request"
265
+ fi
266
+ return 0
267
+ fi
268
+ init_step skipped "branch $IG_BASE" "GitHub already has it"; return 0
269
+ fi
270
+ # A repository with no branch at all gets the current one first (main, the release branch).
271
+ if [ -n "$cur" ] && [ "$cur" != "$IG_BASE" ] && [ -z "$(_gs_git ls-remote --heads origin 2>/dev/null)" ]; then
272
+ out="$(_gs_git push -q -u origin "$cur" 2>&1)" || { init_step failed "branch $IG_BASE" "could not push $cur: $(_gs_last "$out")"; return 0; }
273
+ fi
274
+ _gs_git show-ref --verify -q "refs/heads/$IG_BASE" || _gs_git branch "$IG_BASE" >/dev/null 2>&1 || true
275
+ if out="$(_gs_git push -q -u origin "$IG_BASE" 2>&1)"; then
276
+ # Same commit, so switching moves no file. Only on a repository this run created: an existing
277
+ # project's checkout is never moved.
278
+ [ "$IG_CREATED" -eq 1 ] && [ "$cur" != "$IG_BASE" ] && _gs_git checkout -q "$IG_BASE" >/dev/null 2>&1 || true
279
+ init_step done "branch $IG_BASE" "created from ${cur:-the current commit} and pushed"
280
+ else
281
+ init_step failed "branch $IG_BASE" "$(_gs_last "$out")"
282
+ fi
283
+ }
284
+
285
+ _gs_step_default_branch() {
286
+ local def out
287
+ [ "$IG_REPO_OK" -eq 1 ] || { init_step skipped "default branch" "needs the GitHub repository (see above)"; return 0; }
288
+ def="$(gh repo view "$IG_REPO" --json defaultBranchRef -q '.defaultBranchRef.name' 2>/dev/null || true)"
289
+ if [ "$def" = "$IG_BASE" ]; then init_step skipped "default branch" "already $IG_BASE"; return 0; fi
290
+ if [ "$IG_CREATED" -ne 1 ]; then
291
+ init_step skipped "default branch" "it is '${def:-unknown}'; an existing repository keeps its own (to change it: gh repo edit $IG_REPO --default-branch $IG_BASE)"
292
+ return 0
293
+ fi
294
+ if out="$(gh repo edit "$IG_REPO" --default-branch "$IG_BASE" 2>&1)"; then
295
+ init_step done "default branch" "$IG_BASE"
296
+ else
297
+ init_step failed "default branch" "$(_gs_last "$out")"
298
+ fi
299
+ }
300
+
301
+ _gs_step_labels() {
302
+ local want have name color desc made=0 bad=0 total=0 out
303
+ [ "$IG_REPO_OK" -eq 1 ] || { init_step skipped "labels" "needs the GitHub repository (see above)"; return 0; }
304
+ want="$( cd "$IG_TARGET" && KIT_LABELS_LIST=1 bash "$IG_KIT_ROOT/scripts/setup-labels.sh" 2>/dev/null )" || want=""
305
+ [ -n "$want" ] || { init_step failed "labels" "could not read the label list from the project config"; return 0; }
306
+ if ! have="$(gh label list --repo "$IG_REPO" --limit 1000 --json name -q '.[].name' 2>&1)"; then
307
+ init_step failed "labels" "$(_gs_last "$have")"; return 0
308
+ fi
309
+ while IFS="$(printf '\t')" read -r name color desc; do
310
+ [ -n "$name" ] || continue
311
+ total=$((total + 1))
312
+ grep -qxF "$name" <<<"$have" && continue
313
+ if out="$(gh label create "$name" --repo "$IG_REPO" --color "$color" --description "$desc" 2>&1)"; then made=$((made + 1)); else bad=$((bad + 1)); fi
314
+ done <<EOF
315
+ $want
316
+ EOF
317
+ if [ "$bad" -gt 0 ]; then init_step failed "labels" "$bad of $total could not be created: $(_gs_last "$out")"
318
+ elif [ "$made" -eq 0 ]; then init_step skipped "labels" "all $total are there"
319
+ else init_step done "labels" "created $made, $((total - made)) were there"; fi
320
+ }
321
+
322
+ _gs_step_milestones() {
323
+ local out made
324
+ [ "$IG_REPO_OK" -eq 1 ] || { init_step skipped "milestones" "needs the GitHub repository (see above)"; return 0; }
325
+ if out="$( cd "$IG_TARGET" && bash "$IG_KIT_ROOT/scripts/setup-milestones.sh" 2>&1 )"; then
326
+ made="$(printf '%s\n' "$out" | grep -c '^ ✓ ' || true)"
327
+ if [ "${made:-0}" -eq 0 ]; then init_step skipped "milestones" "all are there"; else init_step done "milestones" "created $made"; fi
328
+ else
329
+ init_step failed "milestones" "$(_gs_last "$out")"
330
+ fi
331
+ }
332
+
333
+ _gs_step_delete_head_branches() {
334
+ local cur out
335
+ [ "$IG_REPO_OK" -eq 1 ] || { init_step skipped "delete head branches on merge" "needs the GitHub repository (see above)"; return 0; }
336
+ if ! cur="$(gh api "repos/$IG_REPO" --jq '.delete_branch_on_merge' 2>&1)"; then
337
+ init_step failed "delete head branches on merge" "$(_gs_last "$cur")"; return 0
338
+ fi
339
+ if [ "$cur" = "true" ]; then init_step skipped "delete head branches on merge" "already on"; return 0; fi
340
+ if out="$(gh api -X PATCH "repos/$IG_REPO" -F delete_branch_on_merge=true 2>&1)"; then
341
+ init_step done "delete head branches on merge"
342
+ else
343
+ init_step failed "delete head branches on merge" "$(_gs_last "$out")"
344
+ fi
345
+ }
346
+
347
+ # The protection cckit's rules ask for (merge-safety.md convention 1): a pull request is required,
348
+ # the branch must be up to date with the base before it merges, history stays linear, and the base
349
+ # is never force-pushed or deleted. No status check is named: a new project has no CI job yet.
350
+ _GS_PROTECTION='{"required_status_checks":{"strict":true,"contexts":[]},"enforce_admins":false,"required_pull_request_reviews":{"required_approving_review_count":0},"restrictions":null,"required_linear_history":true,"allow_force_pushes":false,"allow_deletions":false}'
351
+ _GS_PLAN_REASON="GitHub does not offer branch protection for a private repository on this account's plan (HTTP 403). It is available on a public repository or a paid plan"
352
+
353
+ _gs_step_protection() {
354
+ local out
355
+ [ "$IG_REPO_OK" -eq 1 ] || { init_step skipped "protect $IG_BASE" "needs the GitHub repository (see above)"; return 0; }
356
+ if out="$(gh api "repos/$IG_REPO/branches/$IG_BASE/protection" 2>&1)"; then
357
+ init_step skipped "protect $IG_BASE" "already protected"; return 0
358
+ fi
359
+ if _gs_refused_by_plan "$out"; then init_step skipped "protect $IG_BASE" "$_GS_PLAN_REASON"; return 0; fi
360
+ if out="$(printf '%s' "$_GS_PROTECTION" | gh api -X PUT "repos/$IG_REPO/branches/$IG_BASE/protection" --input - 2>&1)"; then
361
+ init_step done "protect $IG_BASE" "pull request required, branch up to date, no force-push"
362
+ elif _gs_refused_by_plan "$out"; then
363
+ init_step skipped "protect $IG_BASE" "$_GS_PLAN_REASON"
364
+ else
365
+ init_step failed "protect $IG_BASE" "$(_gs_last "$out")"
366
+ fi
367
+ }
368
+
369
+ _gs_step_project_ids() {
370
+ local out
371
+ [ "${IG_PROJECTS_V2:-false}" = "true" ] || return 0
372
+ if [ -f "$IG_TARGET/scripts/.project-ids.env" ]; then init_step skipped "Projects v2 ids" "already captured"; return 0; fi
373
+ if [ ! -f "$IG_TARGET/scripts/capture-project-ids.sh" ]; then init_step failed "Projects v2 ids" "scripts/capture-project-ids.sh is not in the project"; return 0; fi
374
+ if out="$( cd "$IG_TARGET" && bash scripts/capture-project-ids.sh 2>&1 )"; then
375
+ init_step done "Projects v2 ids"
376
+ else
377
+ init_step failed "Projects v2 ids" "$(_gs_last "$out")"
378
+ fi
379
+ }
380
+
381
+ _gs_step_doctor() {
382
+ if [ "${IG_DOCTOR:-1}" != "1" ] || [ ! -f "$IG_KIT_ROOT/scripts/kit-doctor.sh" ]; then
383
+ init_step skipped "doctor report" "turned off for this run"; return 0
384
+ fi
385
+ echo ""
386
+ if ( cd "$IG_TARGET" && bash "$IG_KIT_ROOT/scripts/kit-doctor.sh" --dry-run ); then
387
+ init_step done "doctor report" "nothing to fix"
388
+ else
389
+ init_step failed "doctor report" "it lists things to fix above"
390
+ fi
391
+ }
392
+
393
+ # init_setup_run -> every step, in order. rc 0 always; INIT_FAILED carries the failures.
394
+ init_setup_run() {
395
+ export GH_PROMPT_DISABLED=1
396
+ IG_PROTO="$(gh config get git_protocol 2>/dev/null || echo https)"
397
+ echo ""
398
+ echo "Project setup — $IG_TARGET"
399
+ _gs_step_git_init
400
+ _gs_step_first_commit
401
+ _gs_step_scaffold_commit
402
+ _gs_step_repo
403
+ _gs_step_base_branch
404
+ _gs_step_default_branch
405
+ _gs_step_labels
406
+ _gs_step_milestones
407
+ _gs_step_delete_head_branches
408
+ _gs_step_protection
409
+ _gs_step_project_ids
410
+ _gs_step_doctor
411
+ return 0
412
+ }