@jeiemgi/cckit 0.8.0 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (309) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/AGENTS.md +169 -21
  3. package/README.md +505 -35
  4. package/SECURITY.md +5 -0
  5. package/bin/cckit +189 -20
  6. package/cckit.config.json +1 -1
  7. package/commands/kit-doctor.md +13 -5
  8. package/commands/kit-export-project.md +0 -2
  9. package/commands/kit-export-training.md +6 -9
  10. package/commands/kit-init.md +43 -13
  11. package/commands/kit-routines.md +1 -1
  12. package/commands/kit-update.md +11 -6
  13. package/databases/supabase/guide.html +106 -0
  14. package/databases/supabase/nextjs/lib/supabase/client.ts +9 -0
  15. package/databases/supabase/nextjs/lib/supabase/server.ts +29 -0
  16. package/databases/supabase.json +70 -0
  17. package/integrations/emil-design-eng.json +41 -0
  18. package/integrations/graft.json +81 -0
  19. package/integrations/impeccable.json +42 -0
  20. package/integrations/integration.schema.json +215 -0
  21. package/integrations/lavish.json +43 -0
  22. package/integrations/mempalace.json +28 -0
  23. package/integrations/mlx-lm.json +32 -0
  24. package/integrations/web-design-guidelines.json +42 -0
  25. package/kit.config.schema.json +183 -5
  26. package/package.json +4 -1
  27. package/profiles/automation.json +7 -1
  28. package/profiles/content.json +10 -2
  29. package/profiles/marketing.json +57 -0
  30. package/profiles/minimal.json +7 -1
  31. package/profiles/research.json +7 -1
  32. package/profiles/software.json +7 -1
  33. package/recipes/nextjs-shadcn.json +49 -0
  34. package/scripts/agent-skills-external.txt +45 -0
  35. package/scripts/agent-skills-lint-test.sh +131 -0
  36. package/scripts/agent-skills-lint.sh +115 -0
  37. package/scripts/agent-template-lint-test.sh +42 -0
  38. package/scripts/agent-template-lint.sh +58 -0
  39. package/scripts/annotate-setup.sh +1 -1
  40. package/scripts/autopilot-run-test.sh +338 -0
  41. package/scripts/autopilot-run.sh +448 -0
  42. package/scripts/autopilot-test.sh +8 -0
  43. package/scripts/autopilot.sh +10 -1
  44. package/scripts/benchmark/benchmark-test.sh +85 -0
  45. package/scripts/benchmark/checkpoint-test.sh +314 -0
  46. package/scripts/benchmark/checkpoint.sh +408 -0
  47. package/scripts/benchmark/lib/model.sh +31 -6
  48. package/scripts/benchmark/report.sh +17 -2
  49. package/scripts/benchmark/run-quality.sh +36 -10
  50. package/scripts/benchmark/verb-timings-test.sh +124 -0
  51. package/scripts/benchmark/verb-timings.sh +149 -0
  52. package/scripts/check.sh +29 -19
  53. package/scripts/content-skills-test.sh +144 -0
  54. package/scripts/copilot-loop-test.sh +25 -0
  55. package/scripts/database-supabase-test.sh +121 -0
  56. package/scripts/docs-marketing-words-test.sh +73 -0
  57. package/scripts/docs-record-tables-test.sh +72 -0
  58. package/scripts/guard-raw-git-ops-test.sh +8 -0
  59. package/scripts/hook-adapter-test.sh +193 -0
  60. package/scripts/init-content-test.sh +225 -0
  61. package/scripts/init-guided-test.sh +474 -0
  62. package/scripts/init-recipes-test.sh +104 -0
  63. package/scripts/init-upgrade-test.sh +341 -2
  64. package/scripts/init.sh +746 -95
  65. package/scripts/instruction-budget-baseline.txt +8 -0
  66. package/scripts/instruction-budget-lint-test.sh +166 -0
  67. package/scripts/instruction-budget-lint.sh +219 -0
  68. package/scripts/integrations-check-test.sh +200 -0
  69. package/scripts/integrations-check.sh +157 -0
  70. package/scripts/kit-add-test.sh +214 -0
  71. package/scripts/kit-add.sh +305 -5
  72. package/scripts/kit-adopt-test.sh +16 -0
  73. package/scripts/kit-adopt.sh +3 -2
  74. package/scripts/kit-digest.sh +2 -2
  75. package/scripts/kit-doctor-test.sh +293 -0
  76. package/scripts/kit-doctor.sh +272 -140
  77. package/scripts/kit-export-project-test.sh +3 -3
  78. package/scripts/kit-remove-test.sh +19 -0
  79. package/scripts/kit-routines.sh +2 -2
  80. package/scripts/kit-self-update.sh +1 -1
  81. package/scripts/kit-version-check-test.sh +4 -0
  82. package/scripts/kit-version-check.sh +4 -2
  83. package/scripts/knowledge-lint.sh +4 -4
  84. package/scripts/leak-fence-test.sh +89 -0
  85. package/scripts/lib/adapter-select-test.sh +136 -0
  86. package/scripts/lib/adapter-select.sh +158 -0
  87. package/scripts/lib/agent-def-test.sh +69 -0
  88. package/scripts/lib/agent-def.sh +106 -0
  89. package/scripts/lib/agent-launch-test.sh +212 -0
  90. package/scripts/lib/agent-launch.sh +335 -0
  91. package/scripts/lib/board-view-test.sh +11 -0
  92. package/scripts/lib/board-view.sh +42 -26
  93. package/scripts/lib/branch-owner-test.sh +26 -0
  94. package/scripts/lib/branch-owner.sh +16 -9
  95. package/scripts/lib/captain-test.sh +105 -0
  96. package/scripts/lib/captain.sh +87 -8
  97. package/scripts/lib/codex-hooks-test.sh +100 -0
  98. package/scripts/lib/codex-hooks.sh +69 -0
  99. package/scripts/lib/commitlint.sh +1 -1
  100. package/scripts/lib/content-kinds-gc-test.sh +88 -0
  101. package/scripts/lib/copilot-test.sh +70 -4
  102. package/scripts/lib/copilot.sh +66 -14
  103. package/scripts/lib/effort-dispatch-test.sh +3 -3
  104. package/scripts/lib/effort-metrics-test.sh +178 -1
  105. package/scripts/lib/effort-metrics.sh +188 -35
  106. package/scripts/lib/effort-ops-test.sh +217 -7
  107. package/scripts/lib/effort-ops.sh +281 -49
  108. package/scripts/lib/effort-parity-test.sh +49 -13
  109. package/scripts/lib/effort-plan-test.sh +337 -0
  110. package/scripts/lib/effort-plan.sh +200 -23
  111. package/scripts/lib/effort-slug.sh +16 -2
  112. package/scripts/lib/effort.sh +67 -12
  113. package/scripts/lib/errors-header-test.sh +1 -1
  114. package/scripts/lib/gh-project-test.sh +35 -1
  115. package/scripts/lib/gh-project.sh +37 -16
  116. package/scripts/lib/gh-rest-test.sh +330 -0
  117. package/scripts/lib/gh-rest.sh +304 -0
  118. package/scripts/lib/hook-refresh.sh +1 -1
  119. package/scripts/lib/init-github.sh +412 -0
  120. package/scripts/lib/init-guide.sh +630 -0
  121. package/scripts/lib/integration-install-test.sh +343 -0
  122. package/scripts/lib/integration-install.sh +257 -0
  123. package/scripts/lib/integrations-test.sh +366 -0
  124. package/scripts/lib/integrations.sh +244 -0
  125. package/scripts/lib/kinds-test.sh +125 -0
  126. package/scripts/lib/kinds.sh +66 -0
  127. package/scripts/lib/kit-brief-test.sh +22 -3
  128. package/scripts/lib/kit-brief.sh +45 -5
  129. package/scripts/lib/kit-config-resolve.sh +2 -2
  130. package/scripts/lib/kit-config-test.sh +64 -1
  131. package/scripts/lib/kit-config.sh +37 -1
  132. package/scripts/lib/kit-events.sh +7 -0
  133. package/scripts/lib/kit-gc-test.sh +173 -1
  134. package/scripts/lib/kit-gc.sh +244 -37
  135. package/scripts/lib/kit-hotfix.sh +216 -0
  136. package/scripts/lib/kit-interview-test.sh +93 -0
  137. package/scripts/lib/kit-interview.sh +117 -8
  138. package/scripts/lib/kit-lib-test.sh +1 -1
  139. package/scripts/lib/kit-lib.sh +3 -3
  140. package/scripts/lib/kit-local.sh +2 -2
  141. package/scripts/lib/kit-manifest.sh +33 -1
  142. package/scripts/lib/kit-profile-test.sh +3 -3
  143. package/scripts/lib/kit-status-test.sh +112 -4
  144. package/scripts/lib/kit-status.sh +246 -16
  145. package/scripts/lib/kit-task-ops-test.sh +37 -0
  146. package/scripts/lib/kit-task-ops.sh +362 -89
  147. package/scripts/lib/kto-hotfix-test.sh +232 -0
  148. package/scripts/lib/kto-task-close-test.sh +83 -0
  149. package/scripts/lib/kto-task-new-test.sh +95 -0
  150. package/scripts/lib/kto-task-pr-merge-test.sh +97 -6
  151. package/scripts/lib/kto-task-pr-test.sh +70 -0
  152. package/scripts/lib/leak-fence.sh +89 -0
  153. package/scripts/lib/light-task-run-test.sh +255 -0
  154. package/scripts/lib/light-task-test.sh +309 -0
  155. package/scripts/lib/light-task.sh +706 -0
  156. package/scripts/lib/next-test.sh +99 -0
  157. package/scripts/lib/next.sh +9 -3
  158. package/scripts/lib/orchestration-runtime-test.sh +72 -0
  159. package/scripts/lib/orchestration-runtime.sh +57 -5
  160. package/scripts/lib/plan-machine-test.sh +15 -2
  161. package/scripts/lib/plan-machine.sh +20 -7
  162. package/scripts/lib/plan-next-test.sh +1 -1
  163. package/scripts/lib/plan-next.sh +4 -4
  164. package/scripts/lib/pr-evidence-test.sh +3 -3
  165. package/scripts/lib/pr-evidence.sh +1 -1
  166. package/scripts/lib/qa-lane-test.sh +626 -0
  167. package/scripts/lib/qa-lane.sh +1357 -0
  168. package/scripts/lib/qa-lanes-test.sh +175 -0
  169. package/scripts/lib/react-detect.sh +1 -1
  170. package/scripts/lib/render-test.sh +1 -1
  171. package/scripts/lib/review-page-test.sh +318 -0
  172. package/scripts/lib/review-page.sh +369 -0
  173. package/scripts/lib/review-stage-test.sh +62 -11
  174. package/scripts/lib/review-stage.sh +42 -60
  175. package/scripts/lib/role-identity-test.sh +65 -0
  176. package/scripts/lib/role-identity.sh +25 -2
  177. package/scripts/lib/secret-guard.sh +3 -3
  178. package/scripts/lib/session-registry-test.sh +111 -0
  179. package/scripts/lib/session-registry.sh +233 -0
  180. package/scripts/lib/stage-receipt-test.sh +14 -1
  181. package/scripts/lib/stage-receipt.sh +13 -8
  182. package/scripts/lib/task-source-file.sh +309 -0
  183. package/scripts/lib/task-source.sh +130 -0
  184. package/scripts/lib/test-env-test.sh +3 -3
  185. package/scripts/lib/test-env.sh +7 -4
  186. package/scripts/lib/upgrade-report-test.sh +120 -0
  187. package/scripts/lib/upgrade-report.sh +138 -0
  188. package/scripts/lib/version-bump.sh +3 -3
  189. package/scripts/lib/wave-result-test.sh +80 -0
  190. package/scripts/lib/wave-result.sh +127 -0
  191. package/scripts/lib/worker-brief-test.sh +5 -0
  192. package/scripts/lib/worker-brief.sh +2 -2
  193. package/scripts/lib/worktree-issue-test.sh +30 -1
  194. package/scripts/lib/worktree-issue.sh +93 -9
  195. package/scripts/lib/worktree-ports-test.sh +57 -4
  196. package/scripts/lib/worktree-start-test.sh +197 -0
  197. package/scripts/lib/worktree-start.sh +169 -32
  198. package/scripts/lib/zsh-safety-test.sh +19 -3
  199. package/scripts/marketing-walkthrough-test.sh +152 -0
  200. package/scripts/night-grant-test.sh +37 -0
  201. package/scripts/night-grant.sh +448 -0
  202. package/scripts/night-run-test.sh +8 -0
  203. package/scripts/night-run.mjs +275 -0
  204. package/scripts/night-run.test.mjs +324 -0
  205. package/scripts/orchestrate-test.sh +190 -0
  206. package/scripts/orchestrate.sh +79 -8
  207. package/scripts/portable-test.sh +11 -2
  208. package/scripts/publish.sh +28 -3
  209. package/scripts/review-lint-test.sh +7 -7
  210. package/scripts/review-lint.sh +2 -2
  211. package/scripts/review-rules.conf +8 -0
  212. package/scripts/rule-recipes-test.sh +96 -0
  213. package/scripts/self-install-test.sh +39 -9
  214. package/scripts/setup-labels.sh +18 -1
  215. package/scripts/setup-milestones.sh +1 -1
  216. package/scripts/showcase.sh +1 -1
  217. package/scripts/skill-frontmatter-lint-test.sh +4 -4
  218. package/scripts/skill-frontmatter-lint.sh +1 -1
  219. package/scripts/status-test.sh +113 -2
  220. package/scripts/status.sh +16 -3
  221. package/scripts/task-sync-test.sh +154 -0
  222. package/scripts/task-sync.sh +243 -32
  223. package/scripts/test-runner-test.sh +158 -0
  224. package/scripts/test.sh +131 -23
  225. package/scripts/update-path-test.sh +279 -0
  226. package/scripts/ux-ds-audit.sh +1 -1
  227. package/scripts/ux-graph-scan.sh +6 -6
  228. package/scripts/wave-worker.sh +54 -0
  229. package/skills/kit-add/SKILL.md +77 -0
  230. package/skills/kit-autopilot/SKILL.md +123 -12
  231. package/skills/kit-cleanup/SKILL.md +5 -2
  232. package/skills/kit-contribute/SKILL.md +4 -4
  233. package/skills/kit-docs-writer/SKILL.md +16 -6
  234. package/skills/kit-effort-close/SKILL.md +17 -8
  235. package/skills/kit-effort-new/SKILL.md +15 -9
  236. package/skills/kit-effort-pr/SKILL.md +15 -7
  237. package/skills/kit-effort-start/SKILL.md +5 -2
  238. package/skills/kit-gc/SKILL.md +5 -2
  239. package/skills/kit-next/SKILL.md +5 -1
  240. package/skills/kit-onboard/SKILL.md +3 -3
  241. package/skills/kit-page/SKILL.md +93 -0
  242. package/skills/kit-plan-next/SKILL.md +8 -4
  243. package/skills/kit-security-sweep/SKILL.md +1 -3
  244. package/skills/kit-ship/SKILL.md +2 -3
  245. package/skills/kit-status/SKILL.md +35 -4
  246. package/skills/kit-task-new/SKILL.md +3 -3
  247. package/skills/kit-task-pr/SKILL.md +7 -2
  248. package/skills/kit-task-pr-merge/SKILL.md +7 -2
  249. package/skills/kit-task-start/SKILL.md +7 -7
  250. package/skills/kit-task-sync/SKILL.md +19 -3
  251. package/skills/kit-ux-audit/SKILL.md +3 -2
  252. package/templates/agents/auto-dev.md +5 -4
  253. package/templates/agents/backend.md +1 -1
  254. package/templates/agents/designer.md +2 -0
  255. package/templates/agents/devops.md +1 -1
  256. package/templates/agents/editor.md +9 -1
  257. package/templates/agents/frontend.md +1 -1
  258. package/templates/agents/local-delegate.md +1 -1
  259. package/templates/agents/pm.md +5 -5
  260. package/templates/agents/tech-lead.md +1 -1
  261. package/templates/benchmarks/SCHEMA.md +9 -3
  262. package/templates/codex/hooks.json.tmpl +89 -0
  263. package/templates/hooks/guard-base-branch-commit.sh.tmpl +13 -7
  264. package/templates/hooks/guard-raw-git-ops.sh.tmpl +27 -14
  265. package/templates/hooks/mempal_followup.sh.tmpl +2 -2
  266. package/templates/hooks/mempal_session_start.sh.tmpl +1 -1
  267. package/templates/hooks/prepush_gate.sh.tmpl +4 -2
  268. package/templates/hooks/repo-hygiene.sh.tmpl +3 -2
  269. package/templates/instructions.md.tmpl +174 -0
  270. package/templates/kit.config.json.tmpl +3 -3
  271. package/templates/knowledge-INDEX.md.tmpl +1 -1
  272. package/templates/lib/kit-sigil.sh.tmpl +1 -1
  273. package/templates/rules/authoring.md +106 -0
  274. package/templates/rules/branch-naming.md +40 -4
  275. package/templates/rules/code-retrieval.md +63 -0
  276. package/templates/rules/delegation-brief.md +0 -3
  277. package/templates/rules/design-routing.md +3 -3
  278. package/templates/rules/effort-model.md +14 -10
  279. package/templates/rules/gate-and-review.md +94 -0
  280. package/templates/rules/issue-lifecycle.md +88 -0
  281. package/templates/rules/knowledge-base.md +1 -1
  282. package/templates/rules/mempalace.md +1 -1
  283. package/templates/rules/merge-safety.md +108 -0
  284. package/templates/rules/naming-and-ids.md +23 -17
  285. package/templates/rules/plain-language.md +59 -0
  286. package/templates/rules/plan-next.md +9 -11
  287. package/templates/rules/react-annotate.md +6 -0
  288. package/templates/rules/review-pages.md +49 -0
  289. package/templates/rules/risk-tiered-review.md +13 -4
  290. package/templates/rules/shared-checkout.md +106 -0
  291. package/templates/rules/skill-gaps.md +2 -7
  292. package/templates/rules/task-management.md +13 -1
  293. package/templates/skills/brand-voice/SKILL.md +91 -0
  294. package/templates/skills/brand-voice/references/voice-template.md +61 -0
  295. package/templates/skills/campaign/SKILL.md +123 -0
  296. package/templates/skills/campaign/references/plan-template.md +55 -0
  297. package/templates/skills/concrete/SKILL.md +2 -2
  298. package/templates/skills/copywriting/SKILL.md +8 -1
  299. package/templates/skills/feature-build-refine/SKILL.md +2 -4
  300. package/templates/skills/morning-briefing/SKILL.md +2 -2
  301. package/templates/skills/page-design/SKILL.md +145 -0
  302. package/templates/skills/page-design/add.json +5 -0
  303. package/templates/skills/page-design/references/design-file-template.md +40 -0
  304. package/templates/skills/page-design/references/generic-page-patterns.md +43 -0
  305. package/templates/skills/page-design/references/minimum-rules.md +42 -0
  306. package/templates/skills/speckit/SKILL.md +4 -5
  307. package/templates/skills/supabase-patterns/SKILL.md +1 -1
  308. package/commands/kit-add.md +0 -42
  309. package/templates/CLAUDE.md.tmpl +0 -106
@@ -0,0 +1,630 @@
1
+ #!/usr/bin/env bash
2
+ # shellcheck shell=bash
3
+ # init-guide.sh — the guided half of `cckit init` (#456): what kind of folder this is, the
4
+ # plain-language questions, and the recipe + database registries a new project starts from.
5
+ #
6
+ # Three things live here, and none of them writes to GitHub (that is init-github.sh):
7
+ #
8
+ # 1. DETECTION — init_detect_class <dir> names the folder before anything is written:
9
+ # home the home directory or another place a project never lives
10
+ # ($HOME, its parent, /, ~/Desktop, ~/Documents, ~/Downloads)
11
+ # missing | empty no folder yet, or nothing in it
12
+ # files files, but no project marker and no git repository
13
+ # project-nogit a project marker (package.json, go.mod, a kit config, …), no git
14
+ # git-noremote a git repository with no `origin` remote
15
+ # project-remote a git repository with an `origin` remote
16
+ # 2. THE ADVISOR — init_ask / init_ask_text put ONE question at a time, every choice with a
17
+ # description and exactly one marked recommended. The answer comes from, in order: the answers
18
+ # file (`--answers FILE`, a JSON object {"<key>":"<value>"}, the `cckit add --answers` format),
19
+ # the terminal, or — with an answers file and no entry for the key — the recommended option.
20
+ # With neither a terminal nor an answers file the advisor is off and init runs from flags only.
21
+ # 3. RECIPES AND DATABASES AS DATA — one JSON descriptor per recipe in recipes/ and per database
22
+ # option in databases/ at the kit root. Adding one is adding a file: nothing here names an id.
23
+ #
24
+ # init_detect_class <dir> one of the class names above
25
+ # init_abs_path <path> absolute path of a folder that may not exist yet
26
+ # init_slugify <text> lowercase-dashed slug
27
+ # init_advisor_on rc 0 when a question can be answered (answers file or TTY)
28
+ # init_ask <key> <question> <why> <option>… option = "value|label|description|R" (R = recommended)
29
+ # init_ask_text <key> <question> <default>
30
+ # recipes_dir | recipes_list | recipe_file <id> | recipe_validate <file>
31
+ # databases_dir | databases_list | database_file <id> | database_validate <file>
32
+ # database_offered <file> rc 0 when the option ships its guide page AND its setup test
33
+ # recipe_run <file> <dir> run the recipe's commands in <dir>
34
+ # database_apply <file> <stack> <dir> packages, client code, env file, gitignore
35
+ # database_guide <file> <dir> open the guide page, or print the same steps
36
+ # Requires: jq. bash 3.2 compatible.
37
+ # errors: mixed — detection and the registries are pure; recipe_run / database_apply return rc 1
38
+ # on a failed command and report every step they took
39
+
40
+ _ig_self_dir="$(CDPATH='' cd -- "$(dirname -- "${BASH_SOURCE[0]:-$0}")" && pwd)"
41
+ _ig_kit_root="$(CDPATH='' cd -- "$_ig_self_dir/../.." && pwd)"
42
+
43
+ # ── small helpers ───────────────────────────────────────────────────────────────────────────────
44
+
45
+ init_slugify() { printf '%s' "$1" | tr '[:upper:]' '[:lower:]' | tr -cs 'a-z0-9' '-' | sed -E 's/^-+//; s/-+$//'; }
46
+
47
+ # init_abs_path <path> -> the absolute path, resolving the deepest ancestor that exists. A folder
48
+ # that is not there yet still gets a real path, so a dry run can name it without creating it.
49
+ init_abs_path() {
50
+ local p="$1" tail="" base
51
+ case "$p" in "~") p="$HOME" ;; "~/"*) p="$HOME/${p#\~/}" ;; esac
52
+ case "$p" in /*) ;; *) p="$PWD/$p" ;; esac
53
+ while [ ! -d "$p" ] && [ "$p" != "/" ]; do
54
+ base="$(basename "$p")"
55
+ case "$base" in
56
+ .) ;;
57
+ *) tail="/$base$tail" ;;
58
+ esac
59
+ p="$(dirname "$p")"
60
+ done
61
+ # Logical, not physical: `cd && pwd` is what --upgrade resolves, and a hook path written by a
62
+ # fresh init must be the same string an upgrade computes (on macOS /var is a link to /private/var).
63
+ p="$(CDPATH='' cd -- "$p" 2>/dev/null && pwd)" || return 1
64
+ [ "$p" = "/" ] && p=""
65
+ printf '%s%s\n' "$p" "${tail:-}" | sed 's#^$#/#'
66
+ }
67
+
68
+ # _ig_is_home <abs dir> -> rc 0 for a location a project is never scaffolded into.
69
+ _ig_is_home() {
70
+ local d="$1" h=""
71
+ [ "$d" = "/" ] && return 0
72
+ [ -n "${HOME:-}" ] && h="$(CDPATH='' cd -- "$HOME" 2>/dev/null && pwd -P)"
73
+ [ -n "$h" ] || return 1
74
+ case "$d" in
75
+ "$h"|"$(dirname "$h")"|"$h/Desktop"|"$h/Documents"|"$h/Downloads") return 0 ;;
76
+ esac
77
+ return 1
78
+ }
79
+
80
+ # The files that say "this is already a project". A kit config counts: a re-run lands here.
81
+ _IG_MARKERS="package.json pyproject.toml requirements.txt setup.py Cargo.toml go.mod Gemfile composer.json pom.xml build.gradle build.gradle.kts Makefile deno.json pubspec.yaml mix.exs CMakeLists.txt cckit.config.json .claude/kit.config.json"
82
+
83
+ init_detect_class() {
84
+ local d="$1" m
85
+ [ -e "$d" ] || { echo missing; return 0; }
86
+ d="$(CDPATH='' cd -- "$d" 2>/dev/null && pwd -P)" || { echo missing; return 0; }
87
+ if _ig_is_home "$d"; then echo home; return 0; fi
88
+ if git -C "$d" rev-parse --is-inside-work-tree >/dev/null 2>&1; then
89
+ if [ -n "$(git -C "$d" remote get-url origin 2>/dev/null || true)" ]; then echo project-remote; else echo git-noremote; fi
90
+ return 0
91
+ fi
92
+ # Nothing but macOS folder metadata is an empty folder.
93
+ if [ -z "$(find "$d" -mindepth 1 -maxdepth 1 ! -name .DS_Store 2>/dev/null | sed -n 1p)" ]; then echo empty; return 0; fi
94
+ for m in $_IG_MARKERS; do
95
+ [ -e "$d/$m" ] && { echo project-nogit; return 0; }
96
+ done
97
+ echo files
98
+ }
99
+
100
+ # ── the advisor ─────────────────────────────────────────────────────────────────────────────────
101
+ # INIT_ANSWERS path of the answers file ("" = none)
102
+ # KIT_INIT_TTY 1 / 0 forces the terminal check (a test has no TTY; a wrapper may know better)
103
+
104
+ _ig_tty() {
105
+ case "${KIT_INIT_TTY:-}" in 1) return 0 ;; 0) return 1 ;; esac
106
+ [ -t 0 ] && [ -t 1 ]
107
+ }
108
+
109
+ init_advisor_on() { [ -n "${INIT_ANSWERS:-}" ] || _ig_tty; }
110
+
111
+ # _ig_answer <key> -> the answers-file value for key; rc 1 when there is none.
112
+ _ig_answer() {
113
+ [ -n "${INIT_ANSWERS:-}" ] && [ -f "$INIT_ANSWERS" ] || return 1
114
+ jq -e -r --arg k "$1" 'if (has($k) and (.[$k] != null)) then (.[$k] | tostring) else empty end' "$INIT_ANSWERS" 2>/dev/null
115
+ }
116
+
117
+ # init_ask <key> <question> <why> <option>… -> the chosen value on stdout; the conversation goes to
118
+ # stderr. Each option is "value|label|description" with a 4th field "R" on the recommended one.
119
+ # rc 2 when an answers-file value is not one of the options.
120
+ init_ask() {
121
+ local key="$1" q="$2" why="$3"; shift 3
122
+ local rec="" n=0 o v l d r ans="" i pick
123
+ for o in "$@"; do
124
+ IFS='|' read -r v l d r <<EOF
125
+ $o
126
+ EOF
127
+ if [ -z "$rec" ] && [ "${r:-}" = "R" ]; then rec="$v"; fi
128
+ done
129
+ [ -n "$rec" ] || rec="${1%%|*}"
130
+ if ans="$(_ig_answer "$key")"; then
131
+ for o in "$@"; do
132
+ if [ "${o%%|*}" = "$ans" ]; then
133
+ printf ' ? %s -> %s (answers file)\n' "$q" "$ans" >&2
134
+ printf '%s\n' "$ans"; return 0
135
+ fi
136
+ done
137
+ printf 'x "%s" is not an answer to "%s" (%s). Choose one of:' "$ans" "$key" "$q" >&2
138
+ for o in "$@"; do printf ' %s' "${o%%|*}" >&2; done
139
+ printf '\n' >&2
140
+ return 2
141
+ fi
142
+ if ! _ig_tty; then
143
+ printf ' ? %s -> %s (recommended; "%s" is not in the answers file)\n' "$q" "$rec" "$key" >&2
144
+ printf '%s\n' "$rec"; return 0
145
+ fi
146
+ {
147
+ printf '\n%s\n' "$q"
148
+ [ -n "$why" ] && printf ' %s\n' "$why"
149
+ for o in "$@"; do
150
+ n=$((n + 1))
151
+ IFS='|' read -r v l d r <<EOF
152
+ $o
153
+ EOF
154
+ printf ' %d) %s%s\n' "$n" "$l" "$([ "$v" = "$rec" ] && printf ' (Recommended)')"
155
+ [ -n "$d" ] && printf ' %s\n' "$d"
156
+ done
157
+ printf 'Type a number and press Enter (Enter alone takes the recommended one): '
158
+ } >&2
159
+ while :; do
160
+ IFS= read -r pick || pick=""
161
+ [ -z "$pick" ] && { printf '%s\n' "$rec"; return 0; }
162
+ i=0
163
+ for o in "$@"; do
164
+ i=$((i + 1))
165
+ if [ "$pick" = "$i" ] || [ "$pick" = "${o%%|*}" ]; then printf '%s\n' "${o%%|*}"; return 0; fi
166
+ done
167
+ printf 'That is not one of the choices. Type a number from 1 to %d: ' "$n" >&2
168
+ done
169
+ }
170
+
171
+ # init_ask_text <key> <question> <default> -> free text; an empty answer takes the default.
172
+ init_ask_text() {
173
+ local key="$1" q="$2" def="$3" ans=""
174
+ if ans="$(_ig_answer "$key")" && [ -n "$ans" ]; then
175
+ printf ' ? %s -> %s (answers file)\n' "$q" "$ans" >&2
176
+ printf '%s\n' "$ans"; return 0
177
+ fi
178
+ if ! _ig_tty; then
179
+ printf ' ? %s -> %s (default; "%s" is not in the answers file)\n' "$q" "$def" "$key" >&2
180
+ printf '%s\n' "$def"; return 0
181
+ fi
182
+ printf '\n%s\n Press Enter for: %s\n> ' "$q" "$def" >&2
183
+ IFS= read -r ans || ans=""
184
+ printf '%s\n' "${ans:-$def}"
185
+ }
186
+
187
+ # ── registries: recipes/ and databases/ ─────────────────────────────────────────────────────────
188
+
189
+ recipes_dir() { printf '%s\n' "${KIT_RECIPES_DIR:-$_ig_kit_root/recipes}"; }
190
+ databases_dir() { printf '%s\n' "${KIT_DATABASES_DIR:-$_ig_kit_root/databases}"; }
191
+
192
+ _ig_list() { # <dir> -> descriptor ids, sorted (a *.schema.json file is not a descriptor)
193
+ [ -d "$1" ] || return 0
194
+ find "$1" -maxdepth 1 -type f -name '*.json' ! -name '*.schema.json' 2>/dev/null \
195
+ | sed -e 's#.*/##' -e 's#\.json$##' | sort
196
+ }
197
+ recipes_list() { _ig_list "$(recipes_dir)"; }
198
+ databases_list() { _ig_list "$(databases_dir)"; }
199
+
200
+ _ig_file() { # <dir> <id>
201
+ case "$2" in ""|*/*|.*) return 1 ;; esac
202
+ [ -f "$1/$2.json" ] || return 1
203
+ printf '%s\n' "$1/$2.json"
204
+ }
205
+ recipe_file() { _ig_file "$(recipes_dir)" "$1"; }
206
+ database_file() { _ig_file "$(databases_dir)" "$1"; }
207
+
208
+ # _ig_validate <file> <jq predicate…> — each predicate is "field problem|jq expression that must be true".
209
+ _ig_validate() {
210
+ local f="$1" id rc=0 chk expr msg; shift
211
+ id="$(basename "$f" .json)"
212
+ jq -e 'type == "object"' "$f" >/dev/null 2>&1 || { echo "$id: not a JSON object" >&2; return 1; }
213
+ for chk in "$@"; do
214
+ msg="${chk%%|*}"; expr="${chk#*|}"
215
+ jq -e --arg id "$id" "$expr" "$f" >/dev/null 2>&1 || { echo "$id: $msg" >&2; rc=1; }
216
+ done
217
+ return $rc
218
+ }
219
+
220
+ recipe_validate() {
221
+ _ig_validate "$1" \
222
+ 'id: must equal the file name|.id == $id' \
223
+ 'label: required text|(.label | type) == "string" and (.label | length) > 0' \
224
+ 'summary: required text|(.summary | type) == "string" and (.summary | length) > 0' \
225
+ 'profile: required text|(.profile | type) == "string" and (.profile | length) > 0' \
226
+ 'stack: required text|(.stack | type) == "string" and (.stack | length) > 0' \
227
+ 'recommended: must be true or false|(.recommended | type) == "boolean"' \
228
+ 'steps: one or more {label, run}|(.steps | type) == "array" and (.steps | length) > 0 and all(.steps[]; (.label | type) == "string" and (.run | type) == "string" and (.run | length) > 0)' \
229
+ 'config: an object of project config keys|((.config // {}) | type) == "object"' \
230
+ 'requires: a list of {command, why}|((.requires // []) | type) == "array" and all((.requires // [])[]; (.command | type) == "string")' \
231
+ 'lastVerified: a YYYY-MM-DD date|(.lastVerified // "") | test("^[0-9]{4}-[0-9]{2}-[0-9]{2}$")'
232
+ }
233
+
234
+ database_validate() {
235
+ _ig_validate "$1" \
236
+ 'id: must equal the file name|.id == $id' \
237
+ 'label: required text|(.label | type) == "string" and (.label | length) > 0' \
238
+ 'summary: required text|(.summary | type) == "string" and (.summary | length) > 0' \
239
+ 'fits: required text (when this option fits)|(.fits | type) == "string" and (.fits | length) > 0' \
240
+ 'recommended: must be true or false|(.recommended | type) == "boolean"' \
241
+ 'envFile: required text|(.envFile | type) == "string" and (.envFile | length) > 0' \
242
+ 'env: one or more {name, placeholder, what, where}|(.env | type) == "array" and (.env | length) > 0 and all(.env[]; (.name | test("^[A-Z][A-Z0-9_]*$")) and (.placeholder | type) == "string" and (.what | type) == "string" and (.where | type) == "string")' \
243
+ 'guide: required path|(.guide | type) == "string" and (.guide | length) > 0' \
244
+ 'test: required path|(.test | type) == "string" and (.test | length) > 0' \
245
+ 'steps: one or more lines of text|(.steps | type) == "array" and (.steps | length) > 0 and all(.steps[]; type == "string")' \
246
+ 'stacks: one or more {install, packages, files}|(.stacks | type) == "object" and (.stacks | length) > 0 and all(.stacks[]; (.install | type) == "string" and (.packages | type) == "array" and (.files | type) == "array" and all(.files[]; (.from | type) == "string" and (.to | type) == "string"))' \
247
+ 'lastVerified: a YYYY-MM-DD date|(.lastVerified // "") | test("^[0-9]{4}-[0-9]{2}-[0-9]{2}$")'
248
+ }
249
+
250
+ # database_path <file> <relative> -> a descriptor-relative path made absolute. Paths in a database
251
+ # descriptor are relative to the directory the descriptor is in.
252
+ database_path() { printf '%s/%s\n' "$(CDPATH='' cd -- "$(dirname "$1")" && pwd)" "$2"; }
253
+
254
+ # database_offered <file> -> rc 0 when the option is valid and ships BOTH its guide page and its
255
+ # setup test. An option without them is never shown.
256
+ database_offered() {
257
+ local f="$1" g t
258
+ database_validate "$f" 2>/dev/null || return 1
259
+ g="$(database_path "$f" "$(jq -r '.guide' "$f")")"; t="$(database_path "$f" "$(jq -r '.test' "$f")")"
260
+ [ -f "$g" ] && [ -f "$t" ]
261
+ }
262
+
263
+ # database_stack_for <file> <dir> [stack] -> the stack block name to use: the given one when the
264
+ # descriptor has it, else the first stack whose detect.packageDependency is in <dir>/package.json.
265
+ database_stack_for() {
266
+ local f="$1" d="$2" want="${3:-}" s dep
267
+ if [ -n "$want" ]; then
268
+ jq -e --arg s "$want" '.stacks | has($s)' "$f" >/dev/null 2>&1 && { printf '%s\n' "$want"; return 0; }
269
+ return 1
270
+ fi
271
+ [ -f "$d/package.json" ] || return 1
272
+ for s in $(jq -r '.stacks | keys[]' "$f"); do
273
+ dep="$(jq -r --arg s "$s" '.stacks[$s].detect.packageDependency // empty' "$f")"
274
+ [ -n "$dep" ] || continue
275
+ jq -e --arg d "$dep" '((.dependencies // {}) + (.devDependencies // {})) | has($d)' "$d/package.json" >/dev/null 2>&1 \
276
+ && { printf '%s\n' "$s"; return 0; }
277
+ done
278
+ return 1
279
+ }
280
+
281
+ # ── step lines ──────────────────────────────────────────────────────────────────────────────────
282
+ # One line per step, the same three words everywhere: done · skipped · failed. INIT_FAILED counts
283
+ # the failures so the caller can exit non-zero after every later step has still run.
284
+ INIT_FAILED="${INIT_FAILED:-0}"
285
+ INIT_STEP_LOG="${INIT_STEP_LOG:-}"
286
+ init_step() { # <done|skipped|failed> <what> [detail]
287
+ local line
288
+ line="$(printf ' [%-7s] %s%s' "$1" "$2" "${3:+ — $3}")"
289
+ printf '%s\n' "$line"
290
+ INIT_STEP_LOG="${INIT_STEP_LOG}${line}
291
+ "
292
+ [ "$1" = "failed" ] && INIT_FAILED=$((INIT_FAILED + 1))
293
+ return 0
294
+ }
295
+
296
+ # _ig_run_in <dir> <command> -> run it there with no stdin, output indented as it arrives; the
297
+ # rc is the command's own (a subshell, so the caller's `set -e` / pipefail are not in play).
298
+ _ig_run_in() {
299
+ ( set +e; ( cd "$1" && bash -c "$2" </dev/null ) 2>&1 | sed 's/^/ | /'; exit "${PIPESTATUS[0]}" )
300
+ }
301
+
302
+ # ── recipes ─────────────────────────────────────────────────────────────────────────────────────
303
+
304
+ # recipe_plan <file> -> the commands the recipe runs, one per line, for a dry run or a preview.
305
+ recipe_plan() { jq -r '.steps[] | " $ \(.run) # \(.label)"' "$1"; }
306
+
307
+ # recipe_missing_tools <file> -> one "command — why" line per required command not on PATH.
308
+ recipe_missing_tools() {
309
+ local f="$1" c
310
+ for c in $(jq -r '(.requires // [])[].command' "$f"); do
311
+ command -v "$c" >/dev/null 2>&1 || jq -r --arg c "$c" '(.requires // [])[] | select(.command == $c) | "\(.command) — \(.why // "needed by this recipe")"' "$f"
312
+ done
313
+ }
314
+
315
+ # recipe_run <file> <dir> -> runs every step in <dir>. Stops at the first failed command: the steps
316
+ # build on each other, so a later one cannot succeed. rc 1 on a failure.
317
+ recipe_run() {
318
+ local f="$1" d="$2" n i label run rc missing
319
+ missing="$(recipe_missing_tools "$f")"
320
+ if [ -n "$missing" ]; then
321
+ init_step failed "recipe $(jq -r .id "$f")" "missing on this computer: $(printf '%s' "$missing" | tr '\n' ';')"
322
+ return 1
323
+ fi
324
+ mkdir -p "$d" || return 1
325
+ n="$(jq '.steps | length' "$f")"; i=0
326
+ while [ "$i" -lt "$n" ]; do
327
+ label="$(jq -r --argjson i "$i" '.steps[$i].label' "$f")"
328
+ run="$(jq -r --argjson i "$i" '.steps[$i].run' "$f")"
329
+ printf ' -> %s\n $ %s\n' "$label" "$run"
330
+ rc=0; _ig_run_in "$d" "$run" || rc=$?
331
+ if [ "$rc" -ne 0 ]; then
332
+ init_step failed "$label" "\`$run\` exited $rc"
333
+ return 1
334
+ fi
335
+ init_step done "$label"
336
+ i=$((i + 1))
337
+ done
338
+ return 0
339
+ }
340
+
341
+ # ── databases ───────────────────────────────────────────────────────────────────────────────────
342
+
343
+ # database_plan <file> <stack> -> what database_apply would do, for a dry run.
344
+ database_plan() {
345
+ local f="$1" s="$2"
346
+ jq -r --arg s "$s" '
347
+ " $ \(.stacks[$s].install)",
348
+ (.stacks[$s].files[] | " + \(.to)"),
349
+ " + \(.envFile) (\([.env[].name] | join(", ")) — placeholders; you type the real values)",
350
+ " + .gitignore entry for \(.envFile)"' "$f"
351
+ }
352
+
353
+ # _ig_env_ignored <dir> <envfile> -> rc 0 when git would ignore it (or .gitignore already names it).
354
+ _ig_env_ignored() {
355
+ local d="$1" e="$2"
356
+ if git -C "$d" rev-parse --is-inside-work-tree >/dev/null 2>&1; then
357
+ git -C "$d" check-ignore -q "$e" 2>/dev/null && return 0
358
+ return 1
359
+ fi
360
+ [ -f "$d/.gitignore" ] || return 1
361
+ grep -qxF "$e" "$d/.gitignore" && return 0
362
+ grep -qxE '\.env\*|\.env\.\*|\.env\*\.local|\.env\.local' "$d/.gitignore"
363
+ }
364
+
365
+ # database_apply <file> <stack> <dir> -> the four steps, each reported. Idempotent: a package that
366
+ # is already a dependency, a file that is already there, a variable the env file already names and
367
+ # an ignore rule that already matches are each skipped. A VALUE in the env file is never read into
368
+ # a variable and never printed: only variable NAMES are compared.
369
+ database_apply() {
370
+ local f="$1" s="$2" d="$3" id env_file install need p n i from to src name ph added
371
+ id="$(jq -r .id "$f")"; env_file="$(jq -r .envFile "$f")"
372
+ # 1. packages
373
+ install="$(jq -r --arg s "$s" '.stacks[$s].install' "$f")"
374
+ need=0
375
+ for p in $(jq -r --arg s "$s" '.stacks[$s].packages[]' "$f"); do
376
+ [ -f "$d/package.json" ] && jq -e --arg p "$p" '((.dependencies // {}) + (.devDependencies // {})) | has($p)' "$d/package.json" >/dev/null 2>&1 || need=1
377
+ done
378
+ if [ "$need" -eq 0 ]; then
379
+ init_step skipped "$id packages" "already in package.json"
380
+ else
381
+ printf ' -> %s packages\n $ %s\n' "$id" "$install"
382
+ i=0; _ig_run_in "$d" "$install" || i=$?
383
+ if [ "$i" -ne 0 ]; then init_step failed "$id packages" "\`$install\` exited $i"; else init_step done "$id packages"; fi
384
+ fi
385
+ # 2. client code
386
+ n="$(jq --arg s "$s" '.stacks[$s].files | length' "$f")"; i=0
387
+ while [ "$i" -lt "$n" ]; do
388
+ from="$(jq -r --arg s "$s" --argjson i "$i" '.stacks[$s].files[$i].from' "$f")"
389
+ to="$(jq -r --arg s "$s" --argjson i "$i" '.stacks[$s].files[$i].to' "$f")"
390
+ src="$(database_path "$f" "$from")"
391
+ case "$to" in /*|*..*) init_step failed "$to" "a recipe file must stay inside the project"; i=$((i + 1)); continue ;; esac
392
+ if [ ! -f "$src" ]; then
393
+ init_step failed "$to" "the kit does not ship $from"
394
+ elif [ -f "$d/$to" ]; then
395
+ if cmp -s "$src" "$d/$to"; then init_step skipped "$to" "already there"; else init_step skipped "$to" "already there, with your changes — left as it is"; fi
396
+ else
397
+ mkdir -p "$(dirname "$d/$to")" && cp "$src" "$d/$to" && init_step done "$to" || init_step failed "$to" "could not write it"
398
+ fi
399
+ i=$((i + 1))
400
+ done
401
+ # 3. env file: names with placeholders; an existing line is never changed
402
+ added=""
403
+ for name in $(jq -r '.env[].name' "$f"); do
404
+ if [ -f "$d/$env_file" ] && grep -qE "^[[:space:]]*(export[[:space:]]+)?${name}=" "$d/$env_file"; then continue; fi
405
+ ph="$(jq -r --arg n "$name" '.env[] | select(.name == $n) | .placeholder' "$f")"
406
+ if [ ! -f "$d/$env_file" ]; then
407
+ printf '# %s — replace each placeholder with your own value. This file stays on your computer: git ignores it.\n' "$(jq -r .label "$f")" > "$d/$env_file"
408
+ fi
409
+ printf '%s=%s\n' "$name" "$ph" >> "$d/$env_file"
410
+ added="$added $name"
411
+ done
412
+ if [ -n "$added" ]; then init_step done "$env_file" "added the names$added (placeholders)"; else init_step skipped "$env_file" "already names every variable"; fi
413
+ # 4. the env file is never committed
414
+ if _ig_env_ignored "$d" "$env_file"; then
415
+ init_step skipped ".gitignore" "$env_file is already ignored"
416
+ else
417
+ printf '%s\n' "$env_file" >> "$d/.gitignore" && init_step done ".gitignore" "$env_file is now ignored"
418
+ fi
419
+ return 0
420
+ }
421
+
422
+ # _ig_browser_possible -> rc 0 when a page can be opened for the person at the keyboard.
423
+ # KIT_INIT_BROWSER=0 turns it off; a run without a terminal, over SSH, or in CI never opens one.
424
+ _ig_browser_possible() {
425
+ [ "${KIT_INIT_BROWSER:-1}" = "0" ] && return 1
426
+ _ig_tty || return 1
427
+ [ -n "${CI:-}" ] && return 1
428
+ [ -n "${SSH_CONNECTION:-}${SSH_TTY:-}" ] && return 1
429
+ command -v npx >/dev/null 2>&1 || return 1
430
+ case "$(uname -s)" in
431
+ Darwin) return 0 ;;
432
+ *) [ -n "${DISPLAY:-}${WAYLAND_DISPLAY:-}" ] ;;
433
+ esac
434
+ }
435
+
436
+ # database_steps <file> <dir> -> the credential steps as numbered text. Names only, never a value.
437
+ database_steps() {
438
+ local f="$1" d="$2"
439
+ jq -r --arg d "$d" '
440
+ " \(.label): where each value comes from (checked against the provider on \(.lastVerified))",
441
+ (.steps | to_entries[] | " \(.key + 1). \(.value)"),
442
+ " The file to edit: \($d)/\(.envFile)",
443
+ (.env[] | " \(.name) = \(.what) (\(.where))"),
444
+ " Type the values into that file yourself. cckit never reads them back, and git ignores the file."' "$f"
445
+ }
446
+
447
+ # database_guide <file> <dir> -> open the guide page when a browser is possible; otherwise print
448
+ # the same steps. Always prints where the page is.
449
+ database_guide() {
450
+ local f="$1" d="$2" g
451
+ g="$(database_path "$f" "$(jq -r .guide "$f")")"
452
+ echo ""
453
+ if _ig_browser_possible; then
454
+ echo " Opening the $(jq -r .label "$f") guide in your browser: $g"
455
+ if ! ( cd "$d" && npx -y lavish-axi "$g" </dev/null >/dev/null 2>&1 ); then
456
+ echo " The page did not open. The same steps:"
457
+ database_steps "$f" "$d"
458
+ fi
459
+ else
460
+ database_steps "$f" "$d"
461
+ echo " The same guide as a page: $g"
462
+ fi
463
+ }
464
+
465
+ # ── the guided resolution init.sh calls before anything is written ──────────────────────────────
466
+ # Reads the caller's globals TARGET, FOLDER_GIVEN, NAME, PROFILE, FORCE, RECIPE_ARG, DATABASE_ARG and
467
+ # sets: TARGET (absolute), NAME, PROFILE, INIT_CLASS, INIT_NEW (1 = a new project), INIT_ALREADY
468
+ # (1 = the kit config is already there), RECIPE_FILE, DB_FILE, DB_STACK. Exits 0 when the user
469
+ # stops, 2 on an answer or a folder it has to refuse. It writes nothing.
470
+
471
+ _ig_opt_text() { printf '%s' "$1" | tr '|\n' '/ '; }
472
+
473
+ # _ig_pick_location <base dir> <allow here: 1|0> -> sets TARGET (and NAME when it was empty).
474
+ _ig_pick_location() {
475
+ local base="$1" allow_here="$2" name slug loc cls
476
+ name="$(init_ask_text project_name "What should the project be called?" "${NAME:-$([ "$allow_here" = 1 ] && basename "$base" || echo my-project)}")"
477
+ slug="$(init_slugify "$name")"; [ -n "$slug" ] || slug="my-project"
478
+ if [ "$allow_here" = 1 ]; then
479
+ loc="$(init_ask_text location "Where should it live? Type a folder, or the word here for $base" "here")"
480
+ else
481
+ loc="$(init_ask_text location "Where should it live? Type the folder for it (it is created for you)" "$base/$slug")"
482
+ fi
483
+ if [ "$loc" = "here" ]; then
484
+ [ "$allow_here" = 1 ] || { echo "x A project cannot live directly in $base. Give it a folder of its own, for example $base/$slug" >&2; exit 2; }
485
+ TARGET="$base"
486
+ else
487
+ TARGET="$(init_abs_path "$loc")" || { echo "x cannot use the folder '$loc'" >&2; exit 2; }
488
+ fi
489
+ [ -n "${NAME:-}" ] || NAME="$name"
490
+ cls="$(init_detect_class "$TARGET")"
491
+ case "$cls" in
492
+ empty|missing) ;;
493
+ home) echo "x $TARGET is a home or system folder. A project needs a folder of its own, for example $TARGET/$slug" >&2; exit 2 ;;
494
+ *) echo "x $TARGET already has things in it. A new project needs an empty or new folder." >&2; exit 2 ;;
495
+ esac
496
+ INIT_CLASS="$cls"
497
+ }
498
+
499
+ init_guide_resolve() {
500
+ local adv=0 ans id f opts stack cfg n
501
+ TARGET="$(init_abs_path "$TARGET")" || { echo "x cannot use the folder '$TARGET'" >&2; exit 2; }
502
+ INIT_CLASS="$(init_detect_class "$TARGET")"
503
+ INIT_NEW=0; INIT_ALREADY=0; RECIPE_FILE=""; DB_FILE=""; DB_STACK=""
504
+ init_advisor_on && adv=1
505
+
506
+ case "$INIT_CLASS" in
507
+ home)
508
+ if [ "$adv" -eq 0 ]; then
509
+ echo "x $TARGET is a home or system folder, not a project folder, so nothing is set up in it." >&2
510
+ echo " A new project: name the folder it should live in — cckit init <folder>" >&2
511
+ echo " A project you already have: run cckit init inside its folder." >&2
512
+ exit 2
513
+ fi
514
+ ans="$(init_ask new_project "Is this a new project?" \
515
+ "You are in $TARGET. That is not a project folder, and nothing is ever set up directly in it." \
516
+ "yes|Yes, start a new project|It gets a folder of its own. You choose where in the next question.|R" \
517
+ "no|No, the project already exists|Nothing is written. Open that project's folder and run cckit init there.")" || exit $?
518
+ if [ "$ans" = "no" ]; then echo "Nothing was written. Open your project's folder in the terminal and run: cckit init"; exit 0; fi
519
+ _ig_pick_location "$TARGET" 0
520
+ INIT_NEW=1
521
+ ;;
522
+ empty|missing)
523
+ if [ "$adv" -eq 1 ]; then
524
+ ans="$(init_ask new_project "Is this a new project?" \
525
+ "$TARGET $([ "$INIT_CLASS" = missing ] && echo "does not exist yet" || echo "is empty")." \
526
+ "yes|Yes, start a new project here|The next questions choose what goes in it.|R" \
527
+ "no|No, I meant a project that already exists|Nothing is written. Open that project's folder and run cckit init there.")" || exit $?
528
+ if [ "$ans" = "no" ]; then echo "Nothing was written. Open your project's folder in the terminal and run: cckit init"; exit 0; fi
529
+ [ "${FOLDER_GIVEN:-0}" = "1" ] || _ig_pick_location "$TARGET" 1
530
+ fi
531
+ INIT_NEW=1
532
+ ;;
533
+ files)
534
+ if [ "$adv" -eq 1 ]; then
535
+ ans="$(init_ask folder_use "This folder has files in it but does not look like a project yet. What should happen?" \
536
+ "$TARGET has no project file (such as package.json) and is not a git repository." \
537
+ "here|Set it up as a project, right here|The cckit files are added next to what is already there. Nothing of yours is changed or removed.|R" \
538
+ "new|Start a new project in a folder of its own|This folder is left alone. You choose the new folder next." \
539
+ "cancel|Stop|Nothing is written.")" || exit $?
540
+ case "$ans" in
541
+ cancel) echo "Nothing was written."; exit 0 ;;
542
+ new) _ig_pick_location "$TARGET" 0; INIT_NEW=1 ;;
543
+ esac
544
+ fi
545
+ ;;
546
+ esac
547
+
548
+ # A kit config that is already there makes this a re-run: the profile comes from it.
549
+ cfg="$(adapter_config_existing "$TARGET" 2>/dev/null || true)"
550
+ if [ -n "$cfg" ] && [ -f "$cfg" ] && [ "${FORCE:-0}" -eq 0 ]; then
551
+ INIT_ALREADY=1
552
+ [ -n "${PROFILE:-}" ] || PROFILE="$(jq -r '.profile // "minimal"' "$cfg" 2>/dev/null || echo minimal)"
553
+ fi
554
+
555
+ # ---- recipe ----
556
+ if [ -n "${RECIPE_ARG:-}" ]; then
557
+ if [ "$RECIPE_ARG" != "none" ]; then
558
+ RECIPE_FILE="$(recipe_file "$RECIPE_ARG")" || { echo "x no recipe named '$RECIPE_ARG'. Available: $(recipes_list | tr '\n' ' ')" >&2; exit 2; }
559
+ fi
560
+ elif [ "$INIT_NEW" -eq 1 ] && [ "$adv" -eq 1 ] && [ -n "$(recipes_list)" ]; then
561
+ set --
562
+ for id in $(recipes_list); do
563
+ f="$(recipe_file "$id")"; recipe_validate "$f" 2>/dev/null || continue
564
+ set -- "$@" "$id|$(_ig_opt_text "$(jq -r .label "$f")")|$(_ig_opt_text "$(jq -r '.summary + (if .fits then " Fits: " + .fits else "" end)' "$f")")|$(jq -r 'if .recommended then "R" else "" end' "$f")"
565
+ done
566
+ if [ $# -gt 0 ]; then
567
+ ans="$(init_ask recipe "What should the project start from?" \
568
+ "A recipe builds a working starting point, so the first thing you see is something that runs." \
569
+ "$@" "none|An empty project|Only the cckit workflow files. You add the app yourself.")" || exit $?
570
+ [ "$ans" = "none" ] || RECIPE_FILE="$(recipe_file "$ans")"
571
+ fi
572
+ fi
573
+ if [ -n "$RECIPE_FILE" ]; then
574
+ recipe_validate "$RECIPE_FILE" || { echo "x the recipe $(basename "$RECIPE_FILE") is not valid (problems above)" >&2; exit 2; }
575
+ case "$INIT_CLASS" in
576
+ empty|missing) ;;
577
+ *) echo "x A recipe starts a NEW project and needs an empty folder; $TARGET already has files. Run it on a new folder: cckit init <folder> --recipe $(jq -r .id "$RECIPE_FILE")" >&2; exit 2 ;;
578
+ esac
579
+ n="$(jq -r '.folderName // empty' "$RECIPE_FILE")"
580
+ if [ -n "$n" ] && ! grep -qE "$n" <<<"$(basename "$TARGET")"; then
581
+ echo "x This recipe needs a folder name in lowercase letters, digits and dashes; '$(basename "$TARGET")' is not. Try: $(dirname "$TARGET")/$(init_slugify "$(basename "$TARGET")")" >&2
582
+ exit 2
583
+ fi
584
+ [ -n "${PROFILE:-}" ] || PROFILE="$(jq -r .profile "$RECIPE_FILE")"
585
+ fi
586
+
587
+ # ---- database ----
588
+ stack=""; [ -n "$RECIPE_FILE" ] && stack="$(jq -r .stack "$RECIPE_FILE")"
589
+ if [ -n "${DATABASE_ARG:-}" ]; then
590
+ if [ "$DATABASE_ARG" != "none" ]; then
591
+ DB_FILE="$(database_file "$DATABASE_ARG")" || { echo "x no database option named '$DATABASE_ARG'. Available: $(databases_list | tr '\n' ' ')" >&2; exit 2; }
592
+ database_validate "$DB_FILE" || { echo "x the database option '$DATABASE_ARG' is not valid (problems above)" >&2; exit 2; }
593
+ database_offered "$DB_FILE" || { echo "x the database option '$DATABASE_ARG' is not offered: its guide page or its setup test is missing" >&2; exit 2; }
594
+ fi
595
+ elif [ "$INIT_NEW" -eq 1 ] && [ "$adv" -eq 1 ] && [ -n "$RECIPE_FILE" ]; then
596
+ set --
597
+ for id in $(databases_list); do
598
+ f="$(database_file "$id")"; database_offered "$f" || continue
599
+ database_stack_for "$f" "$TARGET" "$stack" >/dev/null 2>&1 || continue
600
+ set -- "$@" "$id|$(_ig_opt_text "$(jq -r .label "$f")")|$(_ig_opt_text "$(jq -r '.summary + " Fits: " + .fits' "$f")")|$(jq -r 'if .recommended then "R" else "" end' "$f")"
601
+ done
602
+ if [ $# -gt 0 ]; then
603
+ ans="$(init_ask database_needed "Will the project need to remember things — accounts, saved items, orders?" \
604
+ "That is what a database is for. It can also be added later: run cckit init --database <name> inside the project." \
605
+ "yes|Yes, set one up now|You get the code that talks to it and a step-by-step guide for the account and the keys.|R" \
606
+ "no|No, not now|Nothing is added. The project works without one.")" || exit $?
607
+ if [ "$ans" = "yes" ]; then
608
+ ans="$(init_ask database "Which database?" "Each one is a service that stores the project's information." "$@")" || exit $?
609
+ DB_FILE="$(database_file "$ans")"
610
+ fi
611
+ fi
612
+ fi
613
+ if [ -n "$DB_FILE" ]; then
614
+ DB_STACK="$(database_stack_for "$DB_FILE" "$TARGET" "$stack")" || {
615
+ echo "x $(jq -r .label "$DB_FILE") has no setup for this project. It supports: $(jq -r '.stacks | keys | join(", ")' "$DB_FILE")" >&2; exit 2; }
616
+ fi
617
+
618
+ # ---- profile ----
619
+ if [ -z "${PROFILE:-}" ] && [ "$adv" -eq 1 ]; then
620
+ set --
621
+ for f in "$_ig_kit_root"/profiles/*.json; do
622
+ [ -f "$f" ] || continue
623
+ id="$(basename "$f" .json)"
624
+ set -- "$@" "$id|$(_ig_opt_text "$(jq -r '.label // .name' "$f")")|$(_ig_opt_text "$(jq -r '.description // ""' "$f")")|$([ "$id" = software ] && echo R)"
625
+ done
626
+ PROFILE="$(init_ask profile "What kind of work is this project?" \
627
+ "It decides which helpers (agents, skills, rules) are installed. It can be changed later." "$@")" || exit $?
628
+ fi
629
+ return 0
630
+ }