@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,216 @@
1
+ #!/usr/bin/env bash
2
+ # shellcheck shell=bash
3
+ # kit-hotfix.sh — `cckit hotfix <pr|sha> [--base <branch>]` (#360): carry ONE already-merged change
4
+ # to the release branch without waiting for the next promotion.
5
+ #
6
+ # `cckit pr` cannot do this on its own: it needs an issue (a cherry-pick of a merged PR has none) and
7
+ # it writes `Closes #N`. So the hotfix has its own path:
8
+ #
9
+ # 1. resolve the source — a PR number (its merge commit + title, read from GitHub; refused unless
10
+ # MERGED) or a commit (its subject; the PR number is read from a squash `… (#N)` suffix or a
11
+ # `Merge pull request #N` subject, when there is one)
12
+ # 2. worktree `.claude/worktrees/fix+<N>-hotfix-<base>` on branch `fix/<N>-hotfix-<base>`, cut
13
+ # from origin/<base> (`fix/hotfix-<sha7>-<base>` when the commit names no PR)
14
+ # 3. `git cherry-pick -x` (`-m 1` for a merge commit). A PR that was REBASE-merged has no single
15
+ # commit carrying it — GitHub reports only the last rebased commit as its merge commit — so
16
+ # every one of its commits is picked, oldest first
17
+ # 4. push, with the target exported to the git pre-push hook as KIT_PR_BASE
18
+ # 5. open the PR against <base>, titled after the source, body `Cherry-pick of #N`
19
+ #
20
+ # Re-runnable: a commit already picked is not picked again, and a PR already open for the branch is
21
+ # reported instead of re-created. A conflicting pick stops before the push — resolve it in the
22
+ # worktree, `git cherry-pick --continue`, and run the same command again.
23
+ #
24
+ # kto_hotfix <pr|sha> [--base <branch>]
25
+ # stdout: "worktree: <path>" then "✓ <pr-url>"
26
+ # stderr: human progress
27
+ # returns: 0 on success, 1 on a refusal or failed step, 2 on a usage error
28
+ #
29
+ # <base> defaults to KIT_HOTFIX_BASE, else `main`. A digits-only source (optionally `#`-prefixed) is
30
+ # a PR number; anything else is a commit.
31
+ # Requires: git, gh, jq. bash 3.2 compatible; sourceable under zsh.
32
+ # errors: strict — rc 1 on any failed step; nothing is pushed or opened after a failure
33
+ # Runs under the dispatcher's `set -e`: every read that may fail carries `|| true` and is checked
34
+ # on the next line, so a refusal prints its reason instead of exiting silently.
35
+
36
+ if ! type cckit_gh_rest >/dev/null 2>&1; then
37
+ if [ -n "${BASH_SOURCE:-}" ]; then _kh_self="${BASH_SOURCE[0]}"
38
+ elif [ -n "${ZSH_VERSION:-}" ]; then eval '_kh_self="${(%):-%x}"'
39
+ else _kh_self="$0"; fi
40
+ _kh_self="$(cd "$(dirname "$_kh_self")" 2>/dev/null && pwd)/gh-rest.sh"
41
+ # shellcheck source=gh-rest.sh
42
+ [ -f "$_kh_self" ] && . "$_kh_self"
43
+ unset _kh_self
44
+ fi
45
+ type cckit_gh_rest >/dev/null 2>&1 || cckit_gh_rest() { return 1; }
46
+
47
+ _kh_usage() { echo 'cckit hotfix <pr|sha> [--base <branch>] (base defaults to main)' >&2; }
48
+
49
+ # The PR number a commit subject names: a squash `… (#N)` suffix, or `Merge pull request #N …`.
50
+ # Empty when it names none.
51
+ kto_hotfix_subject_pr() {
52
+ printf '%s\n' "$1" | sed -nE 's/^Merge pull request #([0-9]+) .*$/\1/p; s/^.* \(#([0-9]+)\)$/\1/p' | sed -n 1p
53
+ }
54
+
55
+ kto_hotfix() {
56
+ local src="" base="" repo root sha="" title="" pr="" meta subject slug branch wt made="" url="" body n
57
+ local picks="" subjects="" c had="" new="" log
58
+
59
+ while [ $# -gt 0 ]; do
60
+ case "$1" in
61
+ --base)
62
+ [ $# -ge 2 ] && [ -n "$2" ] || { echo "✗ hotfix: --base needs a branch name" >&2; _kh_usage; return 2; }
63
+ base="$2"; shift 2 ;;
64
+ --base=*) base="${1#--base=}"; shift ;;
65
+ -h|--help) _kh_usage; return 0 ;;
66
+ -*) echo "✗ hotfix: unknown flag '$1'" >&2; _kh_usage; return 2 ;;
67
+ *)
68
+ [ -z "$src" ] || { echo "✗ hotfix: one source only (got '$src' and '$1')" >&2; _kh_usage; return 2; }
69
+ src="$1"; shift ;;
70
+ esac
71
+ done
72
+ [ -n "$src" ] || { _kh_usage; return 2; }
73
+ [ -n "$base" ] || base="${KIT_HOTFIX_BASE:-main}"
74
+ [ -n "$base" ] || { echo "✗ hotfix: --base needs a branch name" >&2; return 2; }
75
+
76
+ repo="${KIT_TASK_REPO:-${KIT_REPO:-}}"
77
+ root="$(git worktree list --porcelain 2>/dev/null | awk '/^worktree / && !hit {print $2; hit=1}')"
78
+ [ -n "$root" ] || { echo "✗ hotfix: not in a git repo" >&2; return 1; }
79
+
80
+ git -C "$root" fetch --quiet origin "$base" 2>/dev/null \
81
+ && git -C "$root" rev-parse --verify --quiet "refs/remotes/origin/$base" >/dev/null \
82
+ || { echo "✗ hotfix: origin has no branch '$base'" >&2; return 1; }
83
+
84
+ # 1. the source
85
+ case "${src#\#}" in
86
+ ''|*[!0-9]*)
87
+ sha="$(git -C "$root" rev-parse --verify --quiet "$src^{commit}" 2>/dev/null || true)"
88
+ if [ -z "$sha" ]; then
89
+ git -C "$root" fetch --quiet origin 2>/dev/null || true
90
+ sha="$(git -C "$root" rev-parse --verify --quiet "$src^{commit}" 2>/dev/null || true)"
91
+ fi
92
+ [ -n "$sha" ] || { echo "✗ hotfix: '$src' is not a commit in this repo" >&2; return 1; }
93
+ subject="$(git -C "$root" log -1 --format=%s "$sha")"
94
+ pr="$(kto_hotfix_subject_pr "$subject")"
95
+ title="$(printf '%s\n' "$subject" | sed -E 's/ \(#[0-9]+\)$//')"
96
+ ;;
97
+ *)
98
+ pr="${src#\#}"
99
+ if cckit_gh_rest; then meta="$(gh_rest_pr_json "$repo" "$pr" || true)"
100
+ else meta="$(gh pr view "$pr" --repo "$repo" --json title,state,mergeCommit,commits || true)"; fi
101
+ [ -n "$meta" ] || { echo "✗ hotfix: PR #$pr not found in $repo" >&2; return 1; }
102
+ [ "$(printf '%s' "$meta" | jq -r '.state // ""')" = "MERGED" ] \
103
+ || { echo "✗ hotfix: PR #$pr is not merged — a hotfix carries a change that already landed" >&2; return 1; }
104
+ sha="$(printf '%s' "$meta" | jq -r '.mergeCommit.oid // ""')"
105
+ title="$(printf '%s' "$meta" | jq -r '.title // ""')"
106
+ [ -n "$sha" ] || { echo "✗ hotfix: PR #$pr has no merge commit" >&2; return 1; }
107
+ git -C "$root" cat-file -e "$sha^{commit}" 2>/dev/null \
108
+ || git -C "$root" fetch --quiet origin "$sha" 2>/dev/null \
109
+ || git -C "$root" fetch --quiet origin 2>/dev/null || true
110
+ git -C "$root" cat-file -e "$sha^{commit}" 2>/dev/null \
111
+ || { echo "✗ hotfix: merge commit $sha of PR #$pr is not on origin" >&2; return 1; }
112
+ # A single-parent merge commit is the whole PR only when the PR was squashed. After a rebase
113
+ # merge it is the LAST of the PR's commits, the others sitting right under it with their
114
+ # subjects unchanged — that run of subjects is the tell, and then the whole run is picked.
115
+ if [ "$(git -C "$root" rev-list --parents -n 1 "$sha" | wc -w | tr -d ' ')" -eq 2 ]; then
116
+ if cckit_gh_rest; then subjects="$(gh_rest_pr_commit_subjects "$repo" "$pr" || true)"
117
+ else subjects="$(printf '%s' "$meta" | jq -r '.commits[]?.messageHeadline // empty')"; fi
118
+ n="$(printf '%s\n' "$subjects" | grep -c . || true)"
119
+ [ "$n" -ge 1 ] || { echo "✗ hotfix: cannot read the commits of PR #$pr, so cannot tell a squash from a rebase merge — pass the commit sha instead" >&2; return 1; }
120
+ if [ "$n" -gt 1 ] \
121
+ && [ "$(git -C "$root" log --first-parent --reverse --format=%s -n "$n" "$sha")" = "$subjects" ]; then
122
+ picks="$(git -C "$root" rev-list --first-parent --reverse -n "$n" "$sha")"
123
+ echo "[hotfix] PR #$pr was rebase-merged: carrying its $n commits" >&2
124
+ fi
125
+ fi
126
+ ;;
127
+ esac
128
+ [ -n "$picks" ] || picks="$sha"
129
+ [ -n "$title" ] || title="hotfix: cherry-pick $(git -C "$root" rev-parse --short=7 "$sha")"
130
+
131
+ # 2. the worktree, cut from origin/<base>
132
+ slug="$(printf '%s' "$base" | tr '[:upper:]' '[:lower:]' | sed -E 's/[^a-z0-9]+/-/g; s/^-+|-+$//g')"
133
+ if [ -n "$pr" ]; then branch="fix/$pr-hotfix-$slug"
134
+ else branch="fix/hotfix-$(git -C "$root" rev-parse --short=7 "$sha")-$slug"; fi
135
+ wt="$root/.claude/worktrees/$(printf '%s' "$branch" | tr '/' '+')"
136
+
137
+ if grep -qxF "worktree $wt" <<<"$(git -C "$root" worktree list --porcelain)"; then
138
+ echo "[hotfix] reusing worktree $wt" >&2
139
+ elif git -C "$root" show-ref --verify --quiet "refs/heads/$branch"; then
140
+ git -C "$root" worktree add "$wt" "$branch" >/dev/null 2>&1 \
141
+ || { echo "✗ hotfix: worktree add failed (branch $branch may be checked out elsewhere)" >&2; return 1; }
142
+ echo "[hotfix] created worktree $wt (existing branch $branch)" >&2
143
+ else
144
+ git -C "$root" worktree add --no-track -b "$branch" "$wt" "origin/$base" >/dev/null 2>&1 \
145
+ || { echo "✗ hotfix: worktree add failed for $branch" >&2; return 1; }
146
+ made=1
147
+ echo "[hotfix] created worktree $wt (branch $branch from origin/$base)" >&2
148
+ if type wt_bootstrap >/dev/null 2>&1; then wt_bootstrap "$root" "$wt" "${pr:-0}" >&2 || true; fi
149
+ fi
150
+
151
+ # 3. the pick
152
+ if git -C "$wt" rev-parse --verify --quiet CHERRY_PICK_HEAD >/dev/null; then
153
+ echo "✗ hotfix: a cherry-pick is still in progress in $wt" >&2
154
+ echo " resolve it, run \`git cherry-pick --continue\` there, then re-run this command" >&2
155
+ return 1
156
+ fi
157
+ log="$(git -C "$wt" log "origin/$base..HEAD" --format=%B)"
158
+ for c in $(printf '%s\n' "$picks"); do
159
+ if grep -qF "(cherry picked from commit $c)" <<<"$log"; then
160
+ echo "[hotfix] $c is already picked onto $branch" >&2
161
+ had=1
162
+ continue
163
+ fi
164
+ set -- -x
165
+ n="$(git -C "$wt" rev-list --parents -n 1 "$c" | wc -w | tr -d ' ')"
166
+ if [ "$n" -gt 2 ]; then set -- "$@" -m 1; fi
167
+ if ! git -C "$wt" cherry-pick "$@" "$c" >&2; then
168
+ if [ -z "$(git -C "$wt" status --porcelain --untracked-files=no)" ]; then
169
+ # Nothing to commit: origin/<base> already carries this commit.
170
+ git -C "$wt" cherry-pick --abort >/dev/null 2>&1 || true
171
+ echo "[hotfix] $c changes nothing on origin/$base — it is already there" >&2
172
+ continue
173
+ fi
174
+ echo "✗ hotfix: the cherry-pick of $c onto origin/$base conflicts" >&2
175
+ echo " resolve it in $wt, run \`git cherry-pick --continue\` there, then re-run this command" >&2
176
+ return 1
177
+ fi
178
+ new=1
179
+ done
180
+ if [ -z "$new" ] && [ -z "$had" ]; then
181
+ if [ -n "$made" ]; then
182
+ git -C "$root" worktree remove --force "$wt" >/dev/null 2>&1 || true
183
+ git -C "$root" branch -D "$branch" >/dev/null 2>&1 || true
184
+ fi
185
+ echo "✗ hotfix: $sha changes nothing on origin/$base — it is already there" >&2
186
+ return 1
187
+ fi
188
+
189
+ # 4. push — the target reaches a git pre-push hook as KIT_PR_BASE
190
+ KIT_PR_BASE="$base" git -C "$wt" push -u origin "$branch" >&2 || return 1
191
+ echo "worktree: $wt"
192
+
193
+ # 5. the PR
194
+ if cckit_gh_rest; then
195
+ n="$(gh_rest_pr_for_head "$repo" "$branch" 2>/dev/null || true)"
196
+ if [ -n "$n" ]; then url="https://github.com/$repo/pull/$n"; fi
197
+ else
198
+ url="$(gh pr list --repo "$repo" --head "$branch" --state open --json url --jq '.[0].url // empty' 2>/dev/null || true)"
199
+ fi
200
+ if [ -n "$url" ]; then
201
+ echo "[hotfix] a PR is already open for $branch" >&2
202
+ echo "✓ $url"
203
+ return 0
204
+ fi
205
+ if [ "$picks" != "$sha" ]; then
206
+ body="$(printf 'Cherry-pick of #%s onto `%s`.\n\nSource commits (rebase-merged, oldest first):\n%s' "$pr" "$base" "$picks")"
207
+ elif [ -n "$pr" ]; then body="$(printf 'Cherry-pick of #%s onto `%s`.\n\nSource commit: %s' "$pr" "$base" "$sha")"
208
+ else body="$(printf 'Cherry-pick of %s onto `%s`.' "$sha" "$base")"; fi
209
+ if cckit_gh_rest; then
210
+ url="$(gh_rest_pr_create "$repo" "$base" "$branch" "$title" "$body" "" "")" || return 1
211
+ else
212
+ url="$(gh pr create --repo "$repo" --base "$base" --head "$branch" \
213
+ --title "$title" --body "$body" --assignee "@me")" || return 1
214
+ fi
215
+ echo "✓ $url"
216
+ }
@@ -63,6 +63,99 @@ if [ -n "${KIT_IV_TEST_INNER:-}" ]; then
63
63
  swd="$(kit_interview_apply software "$work/ans-empty.json")"
64
64
  t "apply default deploy" "$(printf '%s' "$swd" | jq -r .deploy.target)" "none"
65
65
 
66
+ # --- an integration tier: the catalog is DERIVED from the descriptor (E303.2) ---
67
+ export KIT_INTEGRATIONS_DIR="$work/integrations"; mkdir -p "$KIT_INTEGRATIONS_DIR"
68
+ mkdesc() { # <id> <config json>
69
+ jq -n --arg id "$1" --argjson c "$2" '{id: $id, label: "A Rather Long Tool Label", summary: "Does a thing.",
70
+ config: $c, docs: "https://example.invalid/d",
71
+ attribution: {author: "X", homepage: "https://example.invalid", affiliated: false, notice: "Not affiliated."}}' \
72
+ > "$KIT_INTEGRATIONS_DIR/$1.json"
73
+ }
74
+ mkdesc igstr '{"key":"codeGraph.provider","value":"igstr-graph"}'
75
+ mkdesc igbool '{"key":"memory.enabled"}'
76
+ ic="$(kit_interview_catalog igstr)"
77
+ t "integration catalog tier" "$(printf '%s' "$ic" | jq -r .tier)" "igstr"
78
+ t "integration one question" "$(printf '%s' "$ic" | jq -c '[.questions[].key]')" '["enable"]'
79
+ t "integration header <= 12" "$(printf '%s' "$ic" | jq -r '.questions[0].header | length')" "12"
80
+ t "integration yes sets the key" "$(printf '%s' "$ic" | jq -c '.questions[0].options[] | select(.value=="yes").set')" \
81
+ '[{"path":"codeGraph.provider","value":"igstr-graph","valtype":"string"}]'
82
+ t "integration no sets nothing" "$(printf '%s' "$ic" | jq -c '.questions[0].options[] | select(.value=="no") | has("set")')" "false"
83
+ t "integration intro = notice" "$(printf '%s' "$ic" | jq -r .intro)" "Not affiliated."
84
+ t "render works on an integration" "$(kit_interview_render igstr "$work/proj" | jq -r '.questions[0].default')" "yes"
85
+ printf '%s\n' '{"keep":{"me":1}}' > "$work/ig-base.json"
86
+ t "apply integration (default yes)" "$(kit_interview_apply igstr "$work/ans-empty.json" "$work/ig-base.json" | jq -c .)" \
87
+ '{"keep":{"me":1},"codeGraph":{"provider":"igstr-graph"}}'
88
+ printf '%s\n' '{"enable":"no"}' > "$work/ans-no.json"
89
+ t "apply integration (no) changes nothing" "$(kit_interview_apply igstr "$work/ans-no.json" "$work/ig-base.json" | jq -c .)" '{"keep":{"me":1}}'
90
+ t "apply integration bool ON value" "$(kit_interview_apply igbool "$work/ans-empty.json" | jq -c .)" '{"memory":{"enabled":true}}'
91
+ # a module keeps a name it shares with an integration; an id outside the grammar resolves nothing
92
+ mkdesc software '{"key":"codeGraph.provider","value":"clash"}'
93
+ t "module wins a shared name" "$(kit_interview_catalog software | jq -r '.module // "derived"')" "software"
94
+ kit_interview_catalog ../igstr >/dev/null 2>&1; t "path-shaped tier rc" "$?" "1"
95
+ unset KIT_INTEGRATIONS_DIR
96
+
97
+ # --- qa module (#294): how this project boots — lists, pairs, names-only credentials ---
98
+ t "catalog qa tier" "$(kit_interview_catalog qa | jq -r .tier)" "qa"
99
+ case "$(kit_interview_catalog_file qa)" in
100
+ */modules/qa.json) t "qa routes to modules/" yes yes;;
101
+ *) t "qa routes to modules/" "$(kit_interview_catalog_file qa)" "*/modules/qa.json";;
102
+ esac
103
+ printf '%s\n' '{"command":"pnpm dev:stack","ports":"WEB_PORT=3000, API_PORT=4000","readiness":"WEB_PORT=/, API_PORT=/health","route":"/dashboard","credentialEnv":"QA_EMAIL, QA_PASSWORD"}' > "$work/ans-qa.json"
104
+ # The VALUES live in the environment only. Nothing the interview derives may read them.
105
+ qa1="$(QA_EMAIL='reviewer@example.test' QA_PASSWORD='s3cret-value' kit_interview_apply qa "$work/ans-qa.json" "$work/base.json")"
106
+ t "qa command is a string" "$(printf '%s' "$qa1" | jq -r '.qa.command | type')" "string"
107
+ t "qa command" "$(printf '%s' "$qa1" | jq -r .qa.command)" "pnpm dev:stack"
108
+ t "qa route is a string" "$(printf '%s' "$qa1" | jq -r '.qa.route | type')" "string"
109
+ t "qa route" "$(printf '%s' "$qa1" | jq -r .qa.route)" "/dashboard"
110
+ t "qa ports is an array" "$(printf '%s' "$qa1" | jq -r '.qa.ports | type')" "array"
111
+ t "qa port env names" "$(printf '%s' "$qa1" | jq -c '[.qa.ports[].env]')" '["WEB_PORT","API_PORT"]'
112
+ t "qa port bases are numbers" "$(printf '%s' "$qa1" | jq -c '[.qa.ports[].base]')" '[3000,4000]'
113
+ t "qa readiness: web AND api" "$(printf '%s' "$qa1" | jq -c .qa.readiness)" '[{"env":"WEB_PORT","path":"/"},{"env":"API_PORT","path":"/health"}]'
114
+ t "qa credentialEnv is an array" "$(printf '%s' "$qa1" | jq -r '.qa.credentialEnv | type')" "array"
115
+ t "qa credential NAMES" "$(printf '%s' "$qa1" | jq -c .qa.credentialEnv)" '["QA_EMAIL","QA_PASSWORD"]'
116
+ t "qa in modules, base kept" "$(printf '%s' "$qa1" | jq -c '[.modules, .project.name]')" '[["qa"],"My App"]'
117
+ case "$qa1" in
118
+ *reviewer@example.test*|*s3cret-value*) t "no credential VALUE in merged JSON" leaked clean;;
119
+ *) t "no credential VALUE in merged JSON" clean clean;;
120
+ esac
121
+
122
+ # a port var with no base DERIVES one (3000 + its position); a probe with no path probes /
123
+ printf '%s\n' '{"command":"make stack","ports":"WEB_PORT, API_PORT","readiness":"WEB_PORT"}' > "$work/ans-qa-derive.json"
124
+ qad="$(kit_interview_apply qa "$work/ans-qa-derive.json")"
125
+ t "qa derived bases" "$(printf '%s' "$qad" | jq -c .qa.ports)" '[{"env":"WEB_PORT","base":3000},{"env":"API_PORT","base":3001}]'
126
+ t "qa derived probe path" "$(printf '%s' "$qad" | jq -c .qa.readiness)" '[{"env":"WEB_PORT","path":"/"}]'
127
+ t "qa route default" "$(printf '%s' "$qad" | jq -r .qa.route)" "/"
128
+ t "qa unanswered list: no key" "$(printf '%s' "$qad" | jq -r '.qa | has("credentialEnv")')" "false"
129
+
130
+ # answers given as JSON arrays (what a skill may build) land in the same shape
131
+ printf '%s\n' '{"command":"make stack","ports":[{"env":"WEB_PORT","base":5000}],"credentialEnv":["QA_EMAIL","QA_EMAIL"]}' > "$work/ans-qa-arr.json"
132
+ qaa="$(kit_interview_apply qa "$work/ans-qa-arr.json")"
133
+ t "qa array answer: ports" "$(printf '%s' "$qaa" | jq -c .qa.ports)" '[{"env":"WEB_PORT","base":5000}]'
134
+ t "qa array answer: deduped" "$(printf '%s' "$qaa" | jq -c .qa.credentialEnv)" '["QA_EMAIL"]'
135
+
136
+ # re-applying onto its own output changes nothing; a shorter answer REPLACES the list
137
+ printf '%s\n' "$qa1" > "$work/base-qa.json"
138
+ qa2="$(kit_interview_apply qa "$work/ans-qa.json" "$work/base-qa.json")"
139
+ t "qa apply idempotent" "$qa2" "$qa1"
140
+ printf '%s\n' '{"command":"pnpm dev:stack","ports":"WEB_PORT=3000","credentialEnv":"QA_EMAIL"}' > "$work/ans-qa-less.json"
141
+ qa3="$(kit_interview_apply qa "$work/ans-qa-less.json" "$work/base-qa.json")"
142
+ t "qa list replaced, not unioned" "$(printf '%s' "$qa3" | jq -c '[(.qa.ports | length), .qa.credentialEnv]')" '[1,["QA_EMAIL"]]'
143
+
144
+ # a credential VALUE is refused: rc 1, nothing on stdout, and stderr never echoes the value
145
+ printf '%s\n' '{"command":"make stack","credentialEnv":"QA_EMAIL, QA_PASSWORD=hunter2-value"}' > "$work/ans-qa-leak.json"
146
+ qal="$(kit_interview_apply qa "$work/ans-qa-leak.json" 2>"$work/leak.err")"; t "qa credential value rc" "$?" "1"
147
+ t "qa credential value: no output" "$qal" ""
148
+ t "qa refusal hides the value" "$(grep -c 'hunter2-value' "$work/leak.err")" "0"
149
+ t "qa refusal names the question" "$(grep -c 'credentialEnv' "$work/leak.err" | sed 's/^[1-9][0-9]*$/named/')" "named"
150
+ # malformed pairs and a missing required command are refused too
151
+ printf '%s\n' '{"command":"make stack","ports":"WEB_PORT=abc"}' > "$work/ans-qa-bad.json"
152
+ kit_interview_apply qa "$work/ans-qa-bad.json" >/dev/null 2>&1; t "qa non-numeric base rc" "$?" "1"
153
+ printf '%s\n' '{"command":"make stack","ports":"WEB_PORT=1, WEB_PORT=2"}' > "$work/ans-qa-dup.json"
154
+ kit_interview_apply qa "$work/ans-qa-dup.json" >/dev/null 2>&1; t "qa repeated port var rc" "$?" "1"
155
+ printf '%s\n' '{"command":"make stack","readiness":"/health"}' > "$work/ans-qa-path.json"
156
+ kit_interview_apply qa "$work/ans-qa-path.json" >/dev/null 2>&1; t "qa probe with no port var rc" "$?" "1"
157
+ kit_interview_apply qa "$work/ans-empty.json" >/dev/null 2>&1; t "qa missing command rc" "$?" "1"
158
+
66
159
  [ "$fail" -eq 0 ] && echo "ALL OK($KIT_IV_TEST_INNER)"
67
160
  exit "$fail"
68
161
  fi
@@ -4,8 +4,10 @@
4
4
  # THE SPLIT: the ASKING is interactive (the kit-onboard skill drives AskUserQuestion — Tier A,
5
5
  # portable to Cowork/claude.ai). The DERIVING is pure data and lives here, so it is unit-testable
6
6
  # under bash AND zsh with zero interactivity:
7
- # - catalog : the question set per tier (global | project | software), loaded from interview/*.json
8
- # and modules/*.json — data, reviewable, not buried in bash.
7
+ # - catalog : the question set per tier (global | project | software | qa), loaded from interview/*.json
8
+ # and modules/*.json — data, reviewable, not buried in bash. A tier that names an
9
+ # integration descriptor (integrations/<id>.json) gets a one-question catalog DERIVED
10
+ # from that descriptor, so `cckit add <integration>` runs through this same engine.
9
11
  # - context : profile + repo detection, used to PRE-FILL per-project / wizard defaults.
10
12
  # - render : the catalog with every `default` resolved from context (what the skill renders).
11
13
  # - apply : answers {key:value} + a base config -> merged config JSON (no side effects).
@@ -25,6 +27,8 @@ _kit_iv_dir="$(CDPATH='' cd -- "$(dirname -- "${BASH_SOURCE[0]:-$0}")" && pwd)"
25
27
  . "$_kit_iv_dir/kit-cli.sh" # kit_is_main, kit_say/warn/die
26
28
  # shellcheck source=/dev/null
27
29
  . "$_kit_iv_dir/kit-profile.sh" # kit_profile_read
30
+ # shellcheck source=/dev/null
31
+ . "$_kit_iv_dir/integrations.sh" # integration_file — the descriptor behind an integration tier
28
32
 
29
33
  # Plugin root = two levels up from scripts/lib/. Override with KIT_PLUGIN_ROOT (tests).
30
34
  kit_iv_plugin_root() {
@@ -45,11 +49,55 @@ kit_interview_catalog_file() {
45
49
  esac
46
50
  }
47
51
 
48
- # kit_interview_catalog <tier> -> the catalog JSON (verbatim)
52
+ # kit_interview_integration_catalog <descriptor> -> a catalog JSON derived from one integration
53
+ # descriptor: ONE select question, `enable`. `yes` sets the descriptor's `config.key` to its ON
54
+ # value (`config.value`, or boolean true when the descriptor names none); `no` carries no `set`,
55
+ # so declining writes nothing — except for a descriptor that is on by default (`config.default`),
56
+ # where `no` writes the off value (`false`, or `"none"` for a named key). The shape is the one modules/*.json uses, which is why render and
57
+ # apply need no integration-specific branch.
58
+ kit_interview_integration_catalog() {
59
+ _kit_iv_require || return 1
60
+ local f="${1:-}"
61
+ [ -f "$f" ] || { kit_warn "kit-interview: no integration descriptor at '$f'"; return 1; }
62
+ jq '
63
+ (.config) as $c
64
+ | (if ($c | has("value")) then $c.value else true end) as $on
65
+ | ($on | type) as $t
66
+ | { integration: .id, tier: .id, label: .label, description: .summary, title: .label,
67
+ intro: ([(.why // empty), .attribution.notice] | join(" ")),
68
+ docs: .docs,
69
+ questions: [
70
+ { key: "enable", header: (.label | .[0:12]), question: "Use \(.label) in this project?",
71
+ type: "select", default: "yes",
72
+ options: [
73
+ { label: "Yes", value: "yes", description: .summary,
74
+ set: [ { path: $c.key,
75
+ value: (if $t == "string" then $on else ($on | tojson) end),
76
+ valtype: (if $t == "string" then "string" elif $t == "boolean" then "bool"
77
+ elif $t == "number" then "number" else "json" end) } ] },
78
+ (if $c.default == true
79
+ then { label: "No", value: "no",
80
+ description: "Turn it off: it is on by default, so the config records the off value.",
81
+ set: [ { path: $c.key,
82
+ value: (if $t == "boolean" then "false" else "none" end),
83
+ valtype: (if $t == "boolean" then "bool" else "string" end) } ] }
84
+ else { label: "No", value: "no", description: "Leave it off. Nothing is written." } end)
85
+ ] }
86
+ ] }' "$f" 2>/dev/null || { kit_warn "kit-interview: cannot read integration descriptor $f"; return 1; }
87
+ }
88
+
89
+ # kit_interview_catalog <tier> -> the catalog JSON (verbatim for interview/ and modules/; derived
90
+ # for a tier that names an integration). A module wins a name it shares with an integration.
49
91
  kit_interview_catalog() {
50
92
  _kit_iv_require || return 1
51
- local f; f="$(kit_interview_catalog_file "$1")"
52
- [ -f "$f" ] || { kit_warn "kit-interview: no catalog for tier '$1' ($f)"; return 1; }
93
+ local f ig; f="$(kit_interview_catalog_file "$1")"
94
+ if [ ! -f "$f" ]; then
95
+ case "$1" in
96
+ global|project) ;;
97
+ *) if ig="$(integration_file "$1")"; then kit_interview_integration_catalog "$ig"; return $?; fi ;;
98
+ esac
99
+ kit_warn "kit-interview: no catalog for tier '$1' ($f)"; return 1
100
+ fi
53
101
  jq -e . "$f" >/dev/null 2>&1 || { kit_warn "kit-interview: invalid JSON in $f"; return 1; }
54
102
  cat "$f"
55
103
  }
@@ -121,15 +169,67 @@ _kit_iv_apply_set() {
121
169
  esac
122
170
  }
123
171
 
172
+ # _kit_iv_listval <question-json> <answersfile> -> a JSON array on stdout, for `list` / `pairs`
173
+ # questions (text answers only ever wrote ONE string; a QA block needs lists — #294).
174
+ # list : "A, B" or ["A","B"] -> ["A","B"] (order kept, duplicates dropped)
175
+ # pairs : "A=1, B" or [{k:..,v:..}, ...] -> [{<k>:"A",<v>:1}, …] keyed by .pairKeys = [k, v].
176
+ # A pair with no value DERIVES one from .pairDefault: number -> default + its position,
177
+ # string -> the default itself. .pairValtype: number | string.
178
+ # .pattern constrains every list item / pair KEY. That is the credential guard: a pattern of bare
179
+ # env-var NAMES makes `QA_PASSWORD=hunter2` fail instead of landing in config. A refusal names the
180
+ # question and the item's POSITION, never the item — the refused text may be the secret itself.
181
+ # rc 1 on a refused answer (nothing on stdout). An empty answer yields [].
182
+ _kit_iv_listval() {
183
+ local q="$1" ans="$2"
184
+ jq -c --argjson q "$q" '
185
+ def items: if type=="array" then . elif type=="string" then [splits("[,\\s]+") | select(length>0)] else [] end;
186
+ def refuse($i; $why): error("answer for \($q.key): item \($i + 1) \($why)");
187
+ ($q.pattern // "") as $pat
188
+ | ($q.pairKeys // ["key","value"]) as $pk
189
+ | ($q.pairValtype // "string") as $vt
190
+ | (.[$q.key] // null) as $raw
191
+ | (if ($raw == null or $raw == "" or $raw == []) then ($q.default // "") else $raw end | items) as $it
192
+ | if ($q.type == "list") then
193
+ reduce range(0; $it|length) as $i ([];
194
+ ($it[$i]) as $x
195
+ | if ($x|type) != "string" then refuse($i; "is not a string")
196
+ elif ($pat != "" and ($x|test($pat)|not)) then refuse($i; "is not a bare name (names only — a value is never stored)")
197
+ elif any(.[]; . == $x) then .
198
+ else . + [$x] end)
199
+ else
200
+ reduce range(0; $it|length) as $i ([];
201
+ ($it[$i]) as $x
202
+ | (if ($x|type) == "string" then ($x | capture("^(?<k>[^=]*)(=(?<v>.*))?$"))
203
+ elif ($x|type) == "object" then {k: $x[$pk[0]], v: $x[$pk[1]]}
204
+ else refuse($i; "is neither NAME=value nor an object") end) as $kv
205
+ | if ($kv.k|type) != "string" or ($pat != "" and ($kv.k|test($pat)|not)) then refuse($i; "has no valid name before `=`")
206
+ elif any(.[]; .[$pk[0]] == $kv.k) then refuse($i; "repeats a name already given")
207
+ else
208
+ (if ($kv.v == null or $kv.v == "") then
209
+ (if $vt == "number" then (($q.pairDefault // 0) + $i) else ($q.pairDefault // refuse($i; "has no value after `=`")) end)
210
+ elif $vt == "number" then
211
+ (if ($kv.v|type) == "number" then $kv.v
212
+ elif (($kv.v|type) == "string" and ($kv.v|test("^[0-9]+$"))) then ($kv.v|tonumber)
213
+ else refuse($i; "needs a whole number after `=`") end)
214
+ else ($kv.v|tostring) end) as $v
215
+ | . + [{($pk[0]): $kv.k, ($pk[1]): $v}]
216
+ end)
217
+ end
218
+ ' "$ans"
219
+ }
220
+
124
221
  # kit_interview_apply <tier> <answersfile> [basefile] -> merged config JSON on stdout.
125
222
  # answersfile: {"<key>":"<chosen value>", ...}. Unanswered questions fall back to their default.
223
+ # Question types: select (the option's set[]) · text (one string at .target) · list / pairs (an
224
+ # ARRAY at .target, REPLACED not unioned, so re-answering shrinks it and a re-run is a no-op).
225
+ # A question marked "required": true with no answer and no default fails the whole apply (rc 1).
126
226
  # Control questions (e.g. project.software) carry no `set` — they steer the caller, not the config.
127
227
  kit_interview_apply() {
128
228
  _kit_iv_require || return 1
129
229
  # ALL locals declared ONCE up front. A BARE `local x` re-run inside a loop PRINTS the var under
130
230
  # zsh (treated like `typeset x`), polluting stdout — so never re-declare locals in the loops below.
131
231
  local tier="$1" ans="$2" base="${3:-}"
132
- local catalog merged nsets nq i p v vt tmp q key qtype def answer target nset j
232
+ local catalog merged nsets nq i p v vt tmp q key qtype def answer target nset j arr
133
233
  [ -f "$ans" ] || { kit_warn "kit-interview apply: answers file missing: $ans"; return 1; }
134
234
  catalog="$(kit_interview_catalog "$tier")" || return 1
135
235
  merged="$(mktemp)" || return 1
@@ -154,10 +254,19 @@ kit_interview_apply() {
154
254
  key="$(printf '%s' "$q" | jq -r '.key')"
155
255
  qtype="$(printf '%s' "$q" | jq -r '.type // "text"')"
156
256
  def="$(printf '%s' "$q" | jq -r '.default // ""')"
157
- answer="$(jq -r --arg k "$key" '.[$k] // empty' "$ans")"
257
+ answer="$(jq -r --arg k "$key" '.[$k] // empty | if type=="array" then map(tostring) | join(",") else . end' "$ans")"
158
258
  [ -z "$answer" ] && answer="$def"
259
+ if [ -z "$answer" ] && [ "$(printf '%s' "$q" | jq -r '.required // false')" = "true" ]; then
260
+ kit_warn "kit-interview apply: '$key' is required and has no answer"; rm -f "$merged"; return 1
261
+ fi
159
262
 
160
- if [ "$qtype" = "text" ]; then
263
+ if [ "$qtype" = "list" ] || [ "$qtype" = "pairs" ]; then
264
+ target="$(printf '%s' "$q" | jq -r '.target // empty')"
265
+ arr="$(_kit_iv_listval "$q" "$ans")" || { kit_warn "kit-interview apply: answer for '$key' refused — nothing written"; rm -f "$merged"; return 1; }
266
+ if [ -n "$target" ] && [ "$arr" != "[]" ]; then
267
+ tmp="$(mktemp)"; jq --argjson v "$arr" "setpath($(printf '%s' "$target" | jq -Rc 'split(".")'); \$v)" < "$merged" > "$tmp" && mv "$tmp" "$merged" || { rm -f "$tmp" "$merged"; return 1; }
268
+ fi
269
+ elif [ "$qtype" = "text" ]; then
161
270
  target="$(printf '%s' "$q" | jq -r '.target // empty')"
162
271
  if [ -n "$target" ] && [ -n "$answer" ]; then
163
272
  tmp="$(mktemp)"; _kit_iv_apply_set "$target" "$answer" string < "$merged" > "$tmp" && mv "$tmp" "$merged" || { rm -f "$tmp" "$merged"; return 1; }
@@ -166,7 +166,7 @@ if [ -n "${KL_TEST_INNER:-}" ]; then
166
166
  has "TOON header" "$llm" "{file,errors,functions,purpose}"
167
167
  has "TOON row" "$llm" '"alpha.sh"'
168
168
  has "TOON keeps unknown" "$llm" '"unknown"'
169
- eq "TOON row count" "$(printf '%s\n' "$llm" | head -1)" "[5]{file,errors,functions,purpose}:"
169
+ eq "TOON row count" "$(printf '%s\n' "$llm" | sed -n 1p)" "[5]{file,errors,functions,purpose}:"
170
170
  # an empty catalog is [] — never an error
171
171
  eq "empty catalog is []" "$(KIT_LIB_DIR="$empty" CCKIT_OUTPUT=json kit_lib --llm)" "[]"
172
172
  err="$(KIT_LIB_DIR="$fix" CCKIT_OUTPUT=json kit_lib --llm --bogus)"; brc=$?
@@ -61,7 +61,7 @@ _kl_sentence() {
61
61
  kit_lib_purpose() {
62
62
  local f="$1" t
63
63
  [ -f "$f" ] || { printf '%s' "unknown"; return 0; }
64
- t="$(sed -n '1,25p' "$f" | sed -n '/^#!/d; /^#[[:space:]]*shellcheck/d; /^#/p' | head -1)"
64
+ t="$(sed -n '1,25p' "$f" | sed -n '/^#!/d; /^#[[:space:]]*shellcheck/d; /^#/p' | sed -n 1p)"
65
65
  [ -n "$t" ] || { printf '%s' "unknown"; return 0; }
66
66
  t="${t#\#}"
67
67
  # trim leading blanks without a subprocess (portable across bash 3.2 + zsh)
@@ -112,7 +112,7 @@ _kl_header() {
112
112
  kit_lib_errors() {
113
113
  local v=""
114
114
  # Read the header block only (see _kl_header) so a body comment is never taken for the contract.
115
- [ -f "$1" ] && v="$(_kl_header "$1" | sed -n 's/^#[[:space:]]*errors:[[:space:]]*\([a-z-]*\).*/\1/p' | head -1)"
115
+ [ -f "$1" ] && v="$(_kl_header "$1" | sed -n 's/^#[[:space:]]*errors:[[:space:]]*\([a-z-]*\).*/\1/p' | sed -n 1p)"
116
116
  [ -n "$v" ] || v="unknown"
117
117
  printf '%s' "$v"
118
118
  }
@@ -121,7 +121,7 @@ kit_lib_errors() {
121
121
  # file this is the ONLY thing saying which half propagates, so the catalog always shows it there.
122
122
  kit_lib_errors_reason() {
123
123
  local line=""
124
- [ -f "$1" ] && line="$(_kl_header "$1" | sed -n 's/^#[[:space:]]*errors:[[:space:]]*//p' | head -1)"
124
+ [ -f "$1" ] && line="$(_kl_header "$1" | sed -n 's/^#[[:space:]]*errors:[[:space:]]*//p' | sed -n 1p)"
125
125
  case "$line" in
126
126
  *'— '*) printf '%s' "${line#*'— '}" ;;
127
127
  *) printf '' ;;
@@ -3,8 +3,8 @@
3
3
  # Backed by mlx_lm.server (Apple MLX), an OpenAI-compatible HTTP server on localhost.
4
4
  #
5
5
  # Setup (one-time — /kit-doctor does both automatically, #313):
6
- # uv tool install mlx-lm # isolated venv, PEP 668-safe (fallback: pipx install mlx-lm)
7
- # mlx_lm.server --model mlx-community/Qwen3-8B-4bit --port 8080
6
+ # the runtime: the install recipe is integrations/mlx-lm.json, run by lib/integration-install.sh
7
+ # the server: mlx_lm.server --model mlx-community/Qwen3-8B-4bit --port 8080
8
8
  #
9
9
  # Source this from hooks/skills: source scripts/lib/kit-local.sh
10
10
  # kit_local_alive -> 0 if the server responds (fast: 1s timeout)
@@ -11,7 +11,7 @@
11
11
  # Source it: source scripts/lib/kit-manifest.sh
12
12
  # Requires: jq + a sha256 tool (shasum -a 256 | sha256sum).
13
13
  #
14
- # Manifest shape (.claude/kit.manifest.json):
14
+ # Manifest shape (.claude/kit.manifest.json; .cckit/kit.manifest.json in a Codex-only project):
15
15
  # {
16
16
  # "schema": 1,
17
17
  # "entries": {
@@ -23,8 +23,14 @@
23
23
 
24
24
  # --- location -------------------------------------------------------------
25
25
  # Manifest lives at the project root's .claude/kit.manifest.json. Override with KIT_MANIFEST.
26
+ # A Codex-only project has no .claude/ tree, so `cckit init --adapter codex` creates the manifest at
27
+ # .cckit/kit.manifest.json instead (E257.3). It is found here by existence, and it stays there if the
28
+ # Claude adapter is enabled later — the manifest never moves once a project has one.
26
29
  kit_manifest_path() {
27
30
  if [ -n "${KIT_MANIFEST:-}" ]; then printf '%s\n' "$KIT_MANIFEST"; return 0; fi
31
+ if [ ! -f ".claude/kit.manifest.json" ] && [ -f ".cckit/kit.manifest.json" ]; then
32
+ printf '%s\n' ".cckit/kit.manifest.json"; return 0
33
+ fi
28
34
  printf '%s\n' ".claude/kit.manifest.json"
29
35
  }
30
36
 
@@ -73,6 +79,32 @@ kit_manifest_record() {
73
79
  && mv "$tmp" "$mf" || { rm -f "$tmp"; return 1; }
74
80
  }
75
81
 
82
+ # kit_manifest_record_batch [op] [kitVersion] [ts] — stdin: one "<tier>\t<relpath>" per line.
83
+ # Records every listed file that exists, hashing its CURRENT content, in ONE manifest rewrite
84
+ # (kit_manifest_record costs a jq run per file; init writes dozens). A path already in the manifest
85
+ # is updated in place, so recording the same file twice never yields two entries.
86
+ kit_manifest_record_batch() {
87
+ _kit_manifest_require || return 1
88
+ local op="${1:-wire}" ver="${2:-${KIT_VERSION:-0.0.0}}" ts="${3:-}" mf tier rel hash rows="" tmp tab
89
+ tab="$(printf '\t')"
90
+ mf="$(kit_manifest_path)"; kit_manifest_init || return 1
91
+ if [ -z "$ts" ]; then ts="$(date -u +%Y-%m-%dT%H:%M:%SZ 2>/dev/null || echo unknown)"; fi
92
+ while IFS="$tab" read -r tier rel; do
93
+ [ -n "$rel" ] || continue
94
+ case "$tier" in A|B) ;; *) echo "kit-manifest: tier must be A or B (got '$tier')" >&2; return 1;; esac
95
+ [ -f "$rel" ] || continue
96
+ hash="$(kit_manifest_hash "$rel")" || return 1
97
+ rows="${rows}${tier}${tab}${rel}${tab}${hash}
98
+ "
99
+ done
100
+ [ -n "$rows" ] || return 0
101
+ tmp="$(mktemp)" || return 1
102
+ printf '%s' "$rows" | jq -Rn --arg o "$op" --arg v "$ver" --arg ts "$ts" --slurpfile m "$mf" '
103
+ reduce (inputs | select(length > 0) | split("\t")) as $r ($m[0];
104
+ .entries[$r[1]] = {hash:$r[2], kitVersion:$v, tier:$r[0], op:$o, ts:$ts})' > "$tmp" \
105
+ && mv "$tmp" "$mf" || { rm -f "$tmp"; return 1; }
106
+ }
107
+
76
108
  # kit_manifest_get <relpath> -> the entry JSON (or empty + rc 1 if untracked)
77
109
  kit_manifest_get() {
78
110
  _kit_manifest_require || return 1
@@ -14,7 +14,7 @@ if [ -n "${KIT_PROFILE_TEST_INNER:-}" ]; then
14
14
  export KIT_PROFILE_HOME="$(mktemp -d)"; trap 'rm -rf "$KIT_PROFILE_HOME"' EXIT
15
15
 
16
16
  # slug normalization (O8)
17
- t "slug spaces+case" "$(KIT_PROFILE_USER='Jose Gutierrez' kit_profile_user_slug)" "jose-gutierrez"
17
+ t "slug spaces+case" "$(KIT_PROFILE_USER='Ada Example' kit_profile_user_slug)" "ada-example"
18
18
  t "slug explicit arg" "$(kit_profile_user_slug 'Ada Lovelace')" "ada-lovelace"
19
19
  t "slug all-symbols -> user" "$(kit_profile_user_slug '!!!')" "user"
20
20
 
@@ -32,8 +32,8 @@ if [ -n "${KIT_PROFILE_TEST_INNER:-}" ]; then
32
32
  t "init idempotent" "$h1" "$h2"
33
33
 
34
34
  # set / get scalar + nested
35
- kit_profile_set name "Jose" string tester
36
- t "get name" "$(kit_profile_get .name tester)" "Jose"
35
+ kit_profile_set name "Ada" string tester
36
+ t "get name" "$(kit_profile_get .name tester)" "Ada"
37
37
  kit_profile_set defaults.mode guided string tester
38
38
  t "get nested mode" "$(kit_profile_get .defaults.mode tester)" "guided"
39
39
  kit_profile_set defaults.memory_on true bool tester