@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
@@ -51,9 +51,9 @@ if [ -n "${KIT_EXPORT_TEST_INNER:-}" ]; then
51
51
 
52
52
  # matrix has the three surfaces.
53
53
  m="$(kit_export_matrix)"
54
- t "matrix names claude.ai" "$(printf '%s' "$m" | grep -qi 'claude.ai' && echo yes || echo no)" "yes"
55
- t "matrix names Cowork" "$(printf '%s' "$m" | grep -qi 'Cowork' && echo yes || echo no)" "yes"
56
- t "matrix names Terminal" "$(printf '%s' "$m" | grep -qi 'Terminal' && echo yes || echo no)" "yes"
54
+ t "matrix names claude.ai" "$(grep -qi 'claude.ai' <<<"$m" && echo yes || echo no)" "yes"
55
+ t "matrix names Cowork" "$(grep -qi 'Cowork' <<<"$m" && echo yes || echo no)" "yes"
56
+ t "matrix names Terminal" "$(grep -qi 'Terminal' <<<"$m" && echo yes || echo no)" "yes"
57
57
 
58
58
  # Now make the hook tier-A via the manifest: --verify should pass (portable).
59
59
  kit_manifest_record .claude/rules/branch-naming.md A wire >/dev/null 2>&1
@@ -46,6 +46,25 @@ if [ -n "${KIT_REMOVE_TEST_INNER:-}" ]; then
46
46
  t "dry-run keeps file" "$([ -f .claude/f.sh ] && echo yes || echo no)" "yes"
47
47
  t "dry-run keeps manifest" "$([ -f .claude/kit.manifest.json ] && echo yes || echo no)" "yes"
48
48
 
49
+ # Codex-only project (E257.3): the manifest lives at .cckit/kit.manifest.json and removal walks
50
+ # it the same way — intact adapter files go, an edited one and the project's own files stay.
51
+ proj3="$(mktemp -d)"; cd "$proj3"
52
+ mkdir -p .agents/skills/concrete .agents/rules .cckit
53
+ printf '{"schema":1,"entries":{}}\n' > .cckit/kit.manifest.json
54
+ printf 's\n' > .agents/skills/concrete/SKILL.md; kit_manifest_record .agents/skills/concrete/SKILL.md A init 1 2026-01-01T00:00:00Z
55
+ printf 'r\n' > .agents/rules/branch-naming.md; kit_manifest_record .agents/rules/branch-naming.md A init 1 2026-01-01T00:00:00Z
56
+ printf 'i\n' > AGENTS.md; kit_manifest_record AGENTS.md A init 1 2026-01-01T00:00:00Z
57
+ printf 'EDITED\n' > AGENTS.md
58
+ printf 'mine\n' > .agents/product-marketing.md
59
+ t "codex: record did not create .claude" "$([ -e .claude ] && echo yes || echo no)" "no"
60
+ printf 'n\n' | kit_remove_all >/dev/null 2>&1
61
+ t "codex: intact skill deleted" "$([ -f .agents/skills/concrete/SKILL.md ] && echo yes || echo no)" "no"
62
+ t "codex: intact rule deleted" "$([ -f .agents/rules/branch-naming.md ] && echo yes || echo no)" "no"
63
+ t "codex: edited AGENTS.md KEPT" "$(cat AGENTS.md)" "EDITED"
64
+ t "codex: user file under .agents SAFE" "$([ -f .agents/product-marketing.md ] && echo yes || echo no)" "yes"
65
+ t "codex: only the edited entry left" "$(kit_manifest_list | tr '\n' ',')" "AGENTS.md,"
66
+ cd "$proj"; rm -rf "$proj2" "$proj3"
67
+
49
68
  [ "$fail" -eq 0 ] && echo "ALL OK($KIT_REMOVE_TEST_INNER)"
50
69
  exit "$fail"
51
70
  fi
@@ -85,7 +85,7 @@ _kit_rt_expand_command() {
85
85
  # kit_routines_cron_has <sentinel> -> rc 0 if present in crontab
86
86
  kit_routines_cron_has() {
87
87
  local sentinel="$1"
88
- crontab -l 2>/dev/null | grep -qF "$sentinel"
88
+ grep -qF "$sentinel" <<<"$(crontab -l 2>/dev/null)"
89
89
  }
90
90
 
91
91
  # kit_routines_cron_add <sentinel> <cron_line_pair>
@@ -173,7 +173,7 @@ kit_routines_list() {
173
173
  cad="$(printf '%s' "$cat" | jq -r ".routines[$i].cadence")"
174
174
  cost="$(printf '%s' "$cat" | jq -r ".routines[$i].cost")"
175
175
  desc="$(printf '%s' "$cat" | jq -r ".routines[$i].description" | cut -c1-50)"
176
- if printf '%s\n' "$accepted" | grep -qx "$id" 2>/dev/null; then
176
+ if grep -qx "$id" <<<"$accepted" 2>/dev/null; then
177
177
  status="accepted"
178
178
  else
179
179
  status="available"
@@ -36,7 +36,7 @@ STAMP_DIR="${XDG_CACHE_HOME:-$HOME/.cache}/cckit"
36
36
  STAMP="$STAMP_DIR/self-update.stamp"
37
37
  if [[ $FORCE -eq 0 && -f "$STAMP" ]]; then
38
38
  now=$(date +%s)
39
- last=$(stat -f %m "$STAMP" 2>/dev/null || stat -c %Y "$STAMP" 2>/dev/null || echo 0)
39
+ last=$(stat -c %Y "$STAMP" 2>/dev/null || stat -f %m "$STAMP" 2>/dev/null || echo 0)
40
40
  (( now - last < THROTTLE )) && exit 0
41
41
  fi
42
42
  mkdir -p "$STAMP_DIR" 2>/dev/null && touch "$STAMP" 2>/dev/null
@@ -21,6 +21,10 @@ printf '{"kitVersion":"0.0.1"}' > "$tmp/cckit.config.json"
21
21
  out="$(env -u CLAUDE_PLUGIN_ROOT bash "$SCRIPT" --target "$tmp" 2>&1)"; rc=$?
22
22
  t "behind project → exit 10 (self-resolved, not a silent no-op)" "$rc" "10"
23
23
  case "$out" in *"$INSTALLED"*) echo "ok: notice names the resolved install version ($INSTALLED)" ;; *) echo "FAIL: notice lacks install version: $out"; fail=1 ;; esac
24
+ # #448: the notice names the command a terminal user or a non-Claude agent runs, beside the slash
25
+ # command — `/kit-update` alone exists only inside Claude Code.
26
+ case "$out" in *"cckit init --upgrade"*) echo "ok: notice names cckit init --upgrade" ;; *) echo "FAIL: notice lacks 'cckit init --upgrade': $out"; fail=1 ;; esac
27
+ case "$out" in *"/kit-update"*) echo "ok: notice still names /kit-update" ;; *) echo "FAIL: notice lacks '/kit-update': $out"; fail=1 ;; esac
24
28
 
25
29
  # A project recorded AT the installed version → up to date (exit 0), still self-resolved.
26
30
  printf '{"kitVersion":"%s"}' "$INSTALLED" > "$tmp/cckit.config.json"
@@ -42,7 +42,7 @@ if [[ -z "$pj" ]]; then
42
42
  "$HOME"/.claude/plugins/*/claude-kit*/.claude-plugin/plugin.json \
43
43
  "$HOME"/.claude/plugins/*/*/claude-kit*/.claude-plugin/plugin.json \
44
44
  "$HOME"/.claude/plugins/*/*/claude-kit*/*/.claude-plugin/plugin.json \
45
- "$HOME"/.claude/plugins/*/*/*/claude-kit*/.claude-plugin/plugin.json 2>/dev/null | head -1 || true)"
45
+ "$HOME"/.claude/plugins/*/*/*/claude-kit*/.claude-plugin/plugin.json 2>/dev/null | sed -n 1p || true)"
46
46
  fi
47
47
  [[ -n "$pj" && -f "$pj" ]] || exit 0
48
48
 
@@ -97,7 +97,9 @@ ver_is_newer() { # ver_is_newer HAVE LATEST → exit 0 if LATEST strictly newer
97
97
  }
98
98
 
99
99
  if ver_is_newer "$have" "$latest"; then
100
- banner "update available" "$have -> $latest · run /kit-update to merge new features (your edits are preserved)"
100
+ # Both entry points are named: `cckit init --upgrade` is what a terminal user or any agent runs;
101
+ # /kit-update is the Claude Code command that wraps it (#448).
102
+ banner "update available" "$have -> $latest · run: cckit init --upgrade (in Claude Code: /kit-update) · preview with --dry-run · your edits are kept"
101
103
  exit 10 # signal: behind
102
104
  fi
103
105
 
@@ -35,9 +35,9 @@ if [[ -d "$KNOWLEDGE_DIR" ]]; then
35
35
  fi
36
36
  fm="$(awk '/^---$/{n++; next} n==1{print} n>=2{exit}' "$f")"
37
37
  for field in status owner updated; do
38
- echo "$fm" | grep -q "^${field}:" || err "$f: missing frontmatter field '${field}:'"
38
+ grep -q "^${field}:" <<<"$fm" || err "$f: missing frontmatter field '${field}:'"
39
39
  done
40
- status_val="$(echo "$fm" | grep '^status:' | head -1 | sed 's/^status:[[:space:]]*//')"
40
+ status_val="$(echo "$fm" | grep '^status:' | sed -n 1p | sed 's/^status:[[:space:]]*//')"
41
41
  case "$status_val" in
42
42
  canonical|reference|historical|"") ;;
43
43
  *) err "$f: invalid status '$status_val' (canonical|reference|historical)" ;;
@@ -77,9 +77,9 @@ if [[ -n "$PLANS_DIR" && "$PLANS_FORMAT" != "none" && -d "$PLANS_DIR" ]]; then
77
77
  [[ -e "$p" ]] || continue
78
78
  fm="$(awk '/^---$/{n++; next} n==1{print} n>=2{exit}' "$p")"
79
79
  for field in title status; do
80
- echo "$fm" | grep -q "^${field}:" || err "$p: missing frontmatter '${field}:'"
80
+ grep -q "^${field}:" <<<"$fm" || err "$p: missing frontmatter '${field}:'"
81
81
  done
82
- if ! grep -qiE '^##+ .*deliverables' "$p" && ! echo "$fm" | grep -q '^deliverables:[[:space:]]*none'; then
82
+ if ! grep -qiE '^##+ .*deliverables' "$p" && ! grep -q '^deliverables:[[:space:]]*none' <<<"$fm"; then
83
83
  err "$p: no Deliverables section and no 'deliverables: none' (the completion contract is required)"
84
84
  fi
85
85
  done
@@ -0,0 +1,89 @@
1
+ #!/usr/bin/env bash
2
+ # shellcheck shell=bash
3
+ # leak-fence-test.sh — selftest of the leak fence (scripts/lib/leak-fence.sh, gate step 3).
4
+ # Builds a throwaway git repository under its own mktemp -d and checks:
5
+ # - a tracked file containing a list word fails the fence; removing the file passes it
6
+ # - with no list present, the built-in word still fails (fresh clone, fork)
7
+ # - CCKIT_LEAK_WORDS (CI) is read, `|`-separated, and a hit prints file:line only — never the word
8
+ # - comments and blank lines in the list are skipped
9
+ # The built-in word is spelled in two halves below so this test file itself never trips the fence.
10
+ # Run: bash scripts/leak-fence-test.sh
11
+ set -u
12
+ ROOT="$(cd "$(dirname "$0")/.." && pwd)"
13
+ fail=0
14
+ t() { if [ "$2" = "$3" ]; then echo "ok: $1"; else echo "FAIL: $1 -> got '[$2]' want '[$3]'"; fail=1; fi; }
15
+
16
+ tmp="$(mktemp -d)"; trap 'rm -rf "$tmp"' EXIT
17
+ repo="$tmp/repo"; mkdir -p "$repo/scripts/lib" "$repo/.cckit"
18
+ cp "$ROOT/scripts/lib/leak-fence.sh" "$repo/scripts/lib/leak-fence.sh"
19
+ git -C "$repo" init -q
20
+ git -C "$repo" -c user.name=t -c user.email=t@example.com -c commit.gpgsign=false add -A
21
+ git -C "$repo" -c user.name=t -c user.email=t@example.com -c commit.gpgsign=false commit -qm init
22
+ printf '.cckit/\n' > "$repo/.gitignore"
23
+
24
+ # The fence under test runs inside the fixture repo, with the fixture's own list file.
25
+ fence() { ( cd "$repo" && CCKIT_LEAK_WORDS_FILE="$repo/.cckit/leak-words" bash -c '. scripts/lib/leak-fence.sh; leak_fence_check' 2>&1 ); }
26
+ track() { printf '%s\n' "$2" > "$repo/$1"; git -C "$repo" add "$1"; }
27
+ untrack() { git -C "$repo" rm -q --cached "$repo/$1"; rm -f "$repo/$1"; }
28
+
29
+ builtin_word="te""dos"
30
+ word="zorblax"
31
+
32
+ # 1. no list, clean tree → passes
33
+ out="$(fence)"; rc=$?
34
+ t "clean tree, no list: passes" "$rc" "0"
35
+
36
+ # 2. no list present → the built-in word still fails
37
+ track "README.md" "powered by $builtin_word"
38
+ out="$(fence)"; rc=$?
39
+ t "no list: built-in word fails" "$rc" "1"
40
+ case "$out" in *"README.md:1"*) echo "ok: hit reported as file:line" ;; *) echo "FAIL: hit not reported: $out"; fail=1 ;; esac
41
+ case "$out" in *"$builtin_word"*) echo "FAIL: output echoes the word: $out"; fail=1 ;; *) echo "ok: output does not echo the word" ;; esac
42
+ untrack "README.md"
43
+
44
+ # 3. a list word in a tracked file fails; removing the file passes (fail → pass)
45
+ printf '# private words\n\n%s\n' "$word" > "$repo/.cckit/leak-words"
46
+ track "docs/note.md" "the $word launch" 2>/dev/null || { mkdir -p "$repo/docs"; track "docs/note.md" "the $word launch"; }
47
+ out="$(fence)"; rc=$?
48
+ t "list word in a tracked file: fails" "$rc" "1"
49
+ case "$out" in *"docs/note.md:1"*) echo "ok: list hit reported as file:line" ;; *) echo "FAIL: list hit not reported: $out"; fail=1 ;; esac
50
+ case "$out" in *"$word"*) echo "FAIL: output echoes the list word: $out"; fail=1 ;; *) echo "ok: output does not echo the list word" ;; esac
51
+ untrack "docs/note.md"
52
+ out="$(fence)"; rc=$?
53
+ t "file removed: passes" "$rc" "0"
54
+
55
+ # 4. case-insensitive, and the list itself is never scanned (it is untracked)
56
+ track "docs/caps.md" "$(printf '%s' "$word" | tr a-z A-Z)"
57
+ out="$(fence)"; rc=$?
58
+ t "list word in caps: fails (case-insensitive)" "$rc" "1"
59
+ untrack "docs/caps.md"
60
+ out="$(fence)"; rc=$?
61
+ t "untracked list file is not itself a hit" "$rc" "0"
62
+
63
+ # 5. CI: CCKIT_LEAK_WORDS, `|`-separated, with no list file
64
+ rm -f "$repo/.cckit/leak-words"
65
+ track "docs/ci.md" "mentions quuxcorp here"
66
+ out="$( cd "$repo" && CCKIT_LEAK_WORDS='frobnic|quuxcorp' bash -c '. scripts/lib/leak-fence.sh; leak_fence_check' 2>&1 )"; rc=$?
67
+ t "CCKIT_LEAK_WORDS hit: fails" "$rc" "1"
68
+ case "$out" in *"quuxcorp"*) echo "FAIL: output echoes the env word: $out"; fail=1 ;; *) echo "ok: output does not echo the env word" ;; esac
69
+ out="$( cd "$repo" && CCKIT_LEAK_WORDS='frobnic' bash -c '. scripts/lib/leak-fence.sh; leak_fence_check' 2>&1 )"; rc=$?
70
+ t "CCKIT_LEAK_WORDS without the word: passes" "$rc" "0"
71
+ untrack "docs/ci.md"
72
+
73
+ # 5b. a secret set from the list file carries its comment lines, one with `|`: comments are dropped
74
+ # before the split, so the scan still runs and still catches the word
75
+ track "docs/ci.md" "mentions quuxcorp here"
76
+ out="$( cd "$repo" && CCKIT_LEAK_WORDS=$'# words (a|b), see docs\nfrobnic|quuxcorp' bash -c '. scripts/lib/leak-fence.sh; leak_fence_check' 2>&1 )"; rc=$?
77
+ t "CCKIT_LEAK_WORDS with a comment line containing |: comment skipped, word caught" "$rc" "1"
78
+ case "$out" in *"docs/ci.md:1"*) echo "ok: hit reported with the comment present" ;; *) echo "FAIL: scan did not run: $out"; fail=1 ;; esac
79
+ # 5c. a pattern that does not compile fails the gate instead of passing on an empty scan
80
+ out="$( cd "$repo" && CCKIT_LEAK_WORDS='(unbalanced' bash -c '. scripts/lib/leak-fence.sh; leak_fence_check' 2>&1 )"; rc=$?
81
+ t "invalid pattern: the gate fails, it does not pass silently" "$rc" "1"
82
+ case "$out" in *"did not compile"*) echo "ok: names the cause" ;; *) echo "FAIL: cause not named: $out"; fail=1 ;; esac
83
+ untrack "docs/ci.md"
84
+
85
+ # 6. the fence file itself names the built-in word and is excluded from its own scan
86
+ out="$(fence)"; rc=$?
87
+ t "the fence source is not a hit" "$rc" "0"
88
+
89
+ [ "$fail" -eq 0 ] && echo "leak-fence-test: PASS" || { echo "leak-fence-test: FAIL"; exit 1; }
@@ -0,0 +1,136 @@
1
+ #!/usr/bin/env bash
2
+ # adapter-select-test.sh — self-test for the adapter selection lib (E257.3, #260).
3
+ # Runs under bash AND zsh. Run: bash scripts/lib/adapter-select-test.sh
4
+ # errors: strict — a test runner: rc 1 on any failed assertion
5
+ PLUGIN_DIR=$(CDPATH='' cd -- "$(dirname -- "$0")/../.." && pwd)
6
+
7
+ if [ -n "${ADAPTER_TEST_INNER:-}" ]; then
8
+ set -u
9
+ fail=0
10
+ t() { if [ "$2" != "$3" ]; then echo "FAIL($ADAPTER_TEST_INNER): $1 -> got '[$2]' want '[$3]'"; fail=1; else echo "ok($ADAPTER_TEST_INNER): $1"; fi; }
11
+
12
+ . "$PLUGIN_DIR/scripts/lib/config-path.sh"
13
+ . "$PLUGIN_DIR/scripts/lib/adapter-select.sh"
14
+ tmp="$(mktemp -d)"; trap 'rm -rf "$tmp"' EXIT
15
+
16
+ # --- normalize ---------------------------------------------------------------------------
17
+ t "claude" "$(adapter_normalize claude)" "claude"
18
+ t "codex" "$(adapter_normalize codex)" "codex"
19
+ t "both" "$(adapter_normalize both)" "claude codex"
20
+ t "comma list, any order" "$(adapter_normalize codex,claude)" "claude codex"
21
+ t "case-insensitive" "$(adapter_normalize Codex)" "codex"
22
+ t "repeat collapses" "$(adapter_normalize 'codex codex')" "codex"
23
+ adapter_normalize cursor >/dev/null 2>&1; t "unknown name refused (rc)" "$?" "1"
24
+ t "unknown name prints nothing on stdout" "$(adapter_normalize cursor 2>/dev/null)" ""
25
+ adapter_normalize "" >/dev/null 2>&1; t "empty spec refused (rc)" "$?" "1"
26
+
27
+ # --- set ops -----------------------------------------------------------------------------
28
+ t "union adds the second" "$(adapter_union claude codex)" "claude codex"
29
+ t "union is idempotent" "$(adapter_union 'claude codex' codex)" "claude codex"
30
+ adapter_has "claude codex" codex; t "has codex in both" "$?" "0"
31
+ adapter_has "claude" codex; t "no codex in claude" "$?" "1"
32
+ adapter_has "codex" claude; t "no claude in codex" "$?" "1"
33
+ t "json one" "$(adapter_json claude)" '["claude"]'
34
+ t "json both" "$(adapter_json 'claude codex')" '["claude","codex"]'
35
+
36
+ # --- per-adapter layout ------------------------------------------------------------------
37
+ t "claude dir" "$(adapter_dir claude)" ".claude"
38
+ t "codex dir" "$(adapter_dir codex)" ".agents"
39
+ t "claude instructions" "$(adapter_instructions claude)" "CLAUDE.md"
40
+ t "codex instructions" "$(adapter_instructions codex)" "AGENTS.md"
41
+ t "hook is tier B" "$(adapter_tier .claude/hooks/repo-hygiene.sh)" "B"
42
+ t "claude skill is tier A" "$(adapter_tier .claude/skills/concrete/SKILL.md)" "A"
43
+ t "codex skill is tier A" "$(adapter_tier .agents/skills/concrete/SKILL.md)" "A"
44
+ adapter_managed AGENTS.md; t "AGENTS.md is managed" "$?" "0"
45
+ adapter_managed .agents/rules/branch-naming.md; t "codex rule is managed" "$?" "0"
46
+ adapter_managed .claude/kit.config.json; t "config is NOT a managed artifact" "$?" "1"
47
+ adapter_managed .claude/settings.local.json; t "settings.local is NOT managed" "$?" "1"
48
+ adapter_managed scripts/task-sync.sh; t "shared script is NOT adapter-managed" "$?" "1"
49
+ adapter_managed .agents/product-marketing.md; t "user file under .agents is NOT managed" "$?" "1"
50
+ t "codex hook is tier B" "$(adapter_tier .codex/hooks/kit-mail-check.sh)" "B"
51
+ adapter_managed .codex/hooks/kit-mail-check.sh; t "codex hook script is managed" "$?" "0"
52
+ adapter_managed .codex/hooks.json; t "codex hooks.json is managed" "$?" "0"
53
+ adapter_managed .codex/config.toml; t "codex config.toml is NOT managed" "$?" "1"
54
+
55
+ # --- stored selection --------------------------------------------------------------------
56
+ printf '{"kitVersion":"1"}' > "$tmp/old.json"
57
+ printf '{"adapters":["codex"]}' > "$tmp/codex.json"
58
+ printf '{"adapters":["codex","claude"]}' > "$tmp/both.json"
59
+ printf '{"adapters":["cursor"]}' > "$tmp/bad.json"
60
+ t "no key means claude" "$(adapter_list_from_config "$tmp/old.json")" "claude"
61
+ t "stored codex" "$(adapter_list_from_config "$tmp/codex.json")" "codex"
62
+ t "stored both, canonical" "$(adapter_list_from_config "$tmp/both.json")" "claude codex"
63
+ t "missing config means claude" "$(adapter_list_from_config "$tmp/none.json")" "claude"
64
+ adapter_list_from_config "$tmp/bad.json" >/dev/null 2>&1; t "unknown stored adapter refused" "$?" "1"
65
+
66
+ # --- config + manifest location ----------------------------------------------------------
67
+ mkdir -p "$tmp/c/.claude" "$tmp/x" "$tmp/self" "$tmp/new"
68
+ printf '{}' > "$tmp/c/.claude/kit.config.json"
69
+ printf '{"adapters":["codex"]}' > "$tmp/x/cckit.config.json"
70
+ printf '{"github":{}}' > "$tmp/self/cckit.config.json"
71
+ t "claude layout found" "$(adapter_config_existing "$tmp/c")" "$tmp/c/.claude/kit.config.json"
72
+ t "codex-only layout found" "$(adapter_config_existing "$tmp/x")" "$tmp/x/cckit.config.json"
73
+ adapter_config_existing "$tmp/self" >/dev/null 2>&1; t "self-host root config is not a scaffold" "$?" "1"
74
+ adapter_config_existing "$tmp/new" >/dev/null 2>&1; t "no config -> rc 1" "$?" "1"
75
+ t "new claude config path" "$(adapter_config_default "$tmp/new" claude)" "$tmp/new/.claude/kit.config.json"
76
+ t "new both config path" "$(adapter_config_default "$tmp/new" 'claude codex')" "$tmp/new/.claude/kit.config.json"
77
+ t "new codex-only config path" "$(adapter_config_default "$tmp/new" codex)" "$tmp/new/cckit.config.json"
78
+ t "new claude manifest" "$(adapter_manifest_rel "$tmp/new" claude)" ".claude/kit.manifest.json"
79
+ t "new codex-only manifest" "$(adapter_manifest_rel "$tmp/new" codex)" ".cckit/kit.manifest.json"
80
+ mkdir -p "$tmp/x/.cckit"; printf '{}' > "$tmp/x/.cckit/kit.manifest.json"
81
+ t "manifest does not move when claude is added" "$(adapter_manifest_rel "$tmp/x" 'claude codex')" ".cckit/kit.manifest.json"
82
+ t "project selection read through the resolver" "$(KIT_CONFIG='' adapter_project_list "$tmp/x")" "codex"
83
+
84
+ # --- ownership manifest: location + batch record (kit-manifest.sh) --------------------------
85
+ . "$PLUGIN_DIR/scripts/lib/kit-manifest.sh"
86
+ if command -v jq >/dev/null 2>&1; then
87
+ mkdir -p "$tmp/m" && cd "$tmp/m"
88
+ t "manifest default path" "$(KIT_MANIFEST='' kit_manifest_path)" ".claude/kit.manifest.json"
89
+ mkdir -p .cckit .agents/skills/a; printf '{"schema":1,"entries":{}}' > .cckit/kit.manifest.json
90
+ t "codex-only manifest found by existence" "$(KIT_MANIFEST='' kit_manifest_path)" ".cckit/kit.manifest.json"
91
+ printf 'one\n' > .agents/skills/a/SKILL.md; printf 'two\n' > AGENTS.md
92
+ printf 'A\t.agents/skills/a/SKILL.md\nA\tAGENTS.md\nA\tmissing.md\n' | KIT_MANIFEST='' kit_manifest_record_batch init 1 2026-01-01T00:00:00Z
93
+ t "batch rc" "$?" "0"
94
+ t "batch records existing files only" "$(jq -r '.entries | keys | join(",")' .cckit/kit.manifest.json)" ".agents/skills/a/SKILL.md,AGENTS.md"
95
+ t "batch entry verifies intact" "$(KIT_MANIFEST='' kit_manifest_verify AGENTS.md)" "intact"
96
+ t "batch stamps op + tier" "$(jq -r '.entries["AGENTS.md"] | .op + "/" + .tier + "/" + .kitVersion' .cckit/kit.manifest.json)" "init/A/1"
97
+ printf 'A\tAGENTS.md\nA\tAGENTS.md\n' | KIT_MANIFEST='' kit_manifest_record_batch init 2 2026-01-02T00:00:00Z
98
+ t "re-recording adds no duplicate" "$(jq -r '.entries | length' .cckit/kit.manifest.json)" "2"
99
+ printf 'Z\tAGENTS.md\n' | KIT_MANIFEST='' kit_manifest_record_batch init 1 >/dev/null 2>&1
100
+ t "batch refuses an unknown tier" "$?" "1"
101
+ t "batch made no .claude tree" "$([ -e .claude ] && echo yes || echo no)" "no"
102
+ mkdir -p .claude; printf '{"schema":1,"entries":{}}' > .claude/kit.manifest.json
103
+ t ".claude manifest wins when both exist" "$(KIT_MANIFEST='' kit_manifest_path)" ".claude/kit.manifest.json"
104
+ cd "$tmp" || exit 1
105
+ fi
106
+
107
+ # --- runtime report ----------------------------------------------------------------------
108
+ mkdir -p "$tmp/bin"
109
+ printf '#!/bin/sh\necho "codex-cli 9.9.9"\n' > "$tmp/bin/codex"; chmod +x "$tmp/bin/codex"
110
+ rep="$(PATH="$tmp/bin:/usr/bin:/bin" adapter_runtime_report "claude codex")"
111
+ t "selected runtime absent" "$(printf '%s\n' "$rep" | sed -n 1p)" "$(printf 'claude\tabsent\t')"
112
+ t "selected runtime present" "$(printf '%s\n' "$rep" | sed -n 2p)" "$(printf 'codex\tpresent\tcodex-cli 9.9.9')"
113
+ t "only selected runtimes are reported" "$(PATH="$tmp/bin:/usr/bin:/bin" adapter_runtime_report codex | wc -l | tr -d ' ')" "1"
114
+
115
+ # --- packaging: everything the installer reads ships in the npm artifact -------------------
116
+ if command -v jq >/dev/null 2>&1; then
117
+ for need in templates scripts; do
118
+ t "package.json files[] ships $need/" "$(jq -r --arg n "$need" '.files | index($n) != null' "$PLUGIN_DIR/package.json")" "true"
119
+ done
120
+ t "one instruction source exists" "$([ -f "$PLUGIN_DIR/templates/instructions.md.tmpl" ] && echo yes || echo no)" "yes"
121
+ t "no second instruction source" "$(ls "$PLUGIN_DIR/templates" | grep -cE '^(CLAUDE|AGENTS)\.md\.tmpl$')" "0"
122
+ fi
123
+
124
+ [ "$fail" -eq 0 ] && echo "ALL OK($ADAPTER_TEST_INNER)"
125
+ exit "$fail"
126
+ fi
127
+
128
+ rc=0; ran=0
129
+ for sh in bash zsh; do
130
+ command -v "$sh" >/dev/null 2>&1 || continue
131
+ ran=$((ran+1)); echo "--- $sh ---"
132
+ rcflag=""; [ "$sh" = "zsh" ] && rcflag="--no-rcs"
133
+ ADAPTER_TEST_INNER="$sh" PATH="$PATH" PLUGIN_DIR="$PLUGIN_DIR" "$sh" $rcflag "$0" || rc=1
134
+ done
135
+ [ "$ran" -eq 0 ] && { echo "no shell"; exit 1; }
136
+ exit "$rc"
@@ -0,0 +1,158 @@
1
+ #!/usr/bin/env bash
2
+ # shellcheck shell=bash
3
+ # adapter-select.sh — which agent adapters a project runs (E257.3, #260).
4
+ #
5
+ # cckit ships two adapters in one version: Claude Code and Codex. A project selects one or both at
6
+ # `cckit init --adapter <claude|codex|both>`; the selection is stored as `adapters` in the project
7
+ # config and every later op (upgrade, wire, doctor) reads it from there instead of guessing from
8
+ # which directories happen to exist.
9
+ #
10
+ # An adapter list is a space-separated string in canonical order: "claude", "codex", "claude codex".
11
+ # A config with no `adapters` key means "claude" — every project scaffolded before this key existed.
12
+ #
13
+ # adapter_normalize <spec> "claude" | "codex" | "both" | "claude,codex" -> canonical list
14
+ # adapter_union <list> <list> both lists merged, canonical order
15
+ # adapter_has <list> <name> rc 0 when <name> is in <list>
16
+ # adapter_json <list> the list as a JSON array
17
+ # adapter_dir <name> the project dir the adapter's skills/rules live in
18
+ # adapter_instructions <name> the instruction file the runtime reads at the project root
19
+ # adapter_tier <relpath> manifest tier of an adapter-managed path (A portable, B CLI-only)
20
+ # adapter_managed <relpath> rc 0 when <relpath> is an adapter file init records as owned
21
+ # adapter_list_from_config <cfg> the stored selection ("claude" when the key is absent)
22
+ # adapter_project_list [dir] the selection of the project containing [dir]
23
+ # adapter_config_existing <target> path of <target>'s init-scaffolded config, or rc 1
24
+ # adapter_config_default <target> <list> where a NEW config goes for that selection
25
+ # adapter_manifest_rel <target> <list> the ownership manifest's path relative to <target>
26
+ # adapter_runtime_report <list> one "<name>\t<present|absent>\t<version>" line per adapter
27
+ #
28
+ # Requires jq for the config readers. bash 3.2 + zsh compatible: no arrays, no unquoted-variable
29
+ # word splitting (zsh does not split those).
30
+ # errors: strict — an unknown adapter name is refused, never silently dropped
31
+
32
+ adapter_normalize() {
33
+ local spec tok c=0 x=0
34
+ spec="$(printf '%s' "${1:-}" | tr 'A-Z,+' 'a-z ')"
35
+ for tok in $(printf '%s\n' "$spec"); do
36
+ case "$tok" in
37
+ claude) c=1 ;;
38
+ codex) x=1 ;;
39
+ both|all) c=1; x=1 ;;
40
+ *) echo "adapter: unknown adapter '$tok' (expected claude, codex or both)" >&2; return 1 ;;
41
+ esac
42
+ done
43
+ if [ "$c" = 1 ] && [ "$x" = 1 ]; then printf 'claude codex\n'
44
+ elif [ "$c" = 1 ]; then printf 'claude\n'
45
+ elif [ "$x" = 1 ]; then printf 'codex\n'
46
+ else echo "adapter: no adapter named (expected claude, codex or both)" >&2; return 1
47
+ fi
48
+ }
49
+
50
+ adapter_union() { adapter_normalize "${1:-} ${2:-}"; }
51
+
52
+ adapter_has() {
53
+ case " ${1:-} " in *" ${2:-} "*) return 0 ;; esac
54
+ return 1
55
+ }
56
+
57
+ adapter_json() {
58
+ local out="" a
59
+ for a in $(printf '%s\n' "${1:-}"); do out="${out:+$out,}\"$a\""; done
60
+ printf '[%s]\n' "$out"
61
+ }
62
+
63
+ adapter_dir() {
64
+ case "${1:-}" in
65
+ claude) printf '.claude\n' ;;
66
+ codex) printf '.agents\n' ;;
67
+ *) return 1 ;;
68
+ esac
69
+ }
70
+
71
+ adapter_instructions() {
72
+ case "${1:-}" in
73
+ claude) printf 'CLAUDE.md\n' ;;
74
+ codex) printf 'AGENTS.md\n' ;;
75
+ *) return 1 ;;
76
+ esac
77
+ }
78
+
79
+ # Statusline shim, settings, hooks and the sigil lib only do anything inside an agent CLI (tier B):
80
+ # Claude Code for .claude/, Codex for .codex/. Instruction files, skills, rules and agents are plain
81
+ # markdown (tier A).
82
+ adapter_tier() {
83
+ case "${1:-}" in
84
+ .claude/statusline.sh|.claude/settings.json|.claude/hooks/*|.claude/lib/*|.codex/hooks.json|.codex/hooks/*) printf 'B\n' ;;
85
+ *) printf 'A\n' ;;
86
+ esac
87
+ }
88
+
89
+ # The adapter files init records in the ownership manifest. NOT the project config and NOT
90
+ # settings.local.json: the first is the project's own record, the second is per-checkout and
91
+ # gitignored, and neither is something `cckit remove` should treat as a kit artifact. Under .codex/
92
+ # only the hook scripts, hooks.json (E257.5) and the role agents init wrote (E257.6) are cckit's;
93
+ # config.toml and the rest is the user's Codex setup. init records hooks.json only when it created
94
+ # the file or the manifest still proves it unmodified.
95
+ adapter_managed() {
96
+ case "${1:-}" in
97
+ .claude/kit.config.json|.claude/kit.manifest.json|.claude/settings.local.json) return 1 ;;
98
+ CLAUDE.md|AGENTS.md|.claude/*|.agents/skills/*|.agents/rules/*|.codex/hooks.json|.codex/hooks/*|.codex/agents/*) return 0 ;;
99
+ esac
100
+ return 1
101
+ }
102
+
103
+ adapter_list_from_config() {
104
+ local cfg="${1:-}" raw
105
+ [ -f "$cfg" ] || { printf 'claude\n'; return 0; }
106
+ command -v jq >/dev/null 2>&1 || { printf 'claude\n'; return 0; }
107
+ raw="$(jq -r 'if has("adapters") then (.adapters | if type == "array" then join(" ") else tostring end) else "claude" end' "$cfg" 2>/dev/null)" \
108
+ || { echo "adapter: cannot read adapters from $cfg" >&2; return 1; }
109
+ adapter_normalize "$raw"
110
+ }
111
+
112
+ adapter_project_list() {
113
+ local cfg=""
114
+ if command -v kit_config_path >/dev/null 2>&1; then cfg="$(kit_config_path "${1:-$PWD}" 2>/dev/null || true)"; fi
115
+ adapter_list_from_config "$cfg"
116
+ }
117
+
118
+ # A root cckit.config.json counts as init-scaffolded only when it carries `adapters`: that is the
119
+ # layout init writes for a Codex-only project. A root config without the key is the self-host layout
120
+ # (cckit's own repo), which init must keep refusing to upgrade over.
121
+ adapter_config_existing() {
122
+ local t="${1:-.}"
123
+ if [ -f "$t/cckit.config.json" ] && command -v jq >/dev/null 2>&1 \
124
+ && jq -e 'has("adapters")' "$t/cckit.config.json" >/dev/null 2>&1; then
125
+ printf '%s\n' "$t/cckit.config.json"; return 0
126
+ fi
127
+ if [ -f "$t/.claude/kit.config.json" ]; then printf '%s\n' "$t/.claude/kit.config.json"; return 0; fi
128
+ return 1
129
+ }
130
+
131
+ # A project that selects Claude keeps the layout every existing project has. A Codex-only project
132
+ # gets no .claude/ tree at all, so its config goes to the adapter-neutral root file the resolver
133
+ # (config-path.sh) already checks first.
134
+ adapter_config_default() {
135
+ if adapter_has "${2:-}" claude; then printf '%s\n' "${1:-.}/.claude/kit.config.json"
136
+ else printf '%s\n' "${1:-.}/cckit.config.json"; fi
137
+ }
138
+
139
+ # The manifest stays wherever the first install put it — enabling a second adapter never moves it.
140
+ adapter_manifest_rel() {
141
+ local t="${1:-.}"
142
+ if [ -f "$t/.claude/kit.manifest.json" ]; then printf '.claude/kit.manifest.json\n'
143
+ elif [ -f "$t/.cckit/kit.manifest.json" ]; then printf '.cckit/kit.manifest.json\n'
144
+ elif adapter_has "${2:-}" claude; then printf '.claude/kit.manifest.json\n'
145
+ else printf '.cckit/kit.manifest.json\n'; fi
146
+ }
147
+
148
+ adapter_runtime_report() {
149
+ local a ver
150
+ for a in $(printf '%s\n' "${1:-}"); do
151
+ if command -v "$a" >/dev/null 2>&1; then
152
+ ver="$("$a" --version 2>/dev/null | sed -n 1p)"
153
+ printf '%s\tpresent\t%s\n' "$a" "${ver:-version unknown}"
154
+ else
155
+ printf '%s\tabsent\t\n' "$a"
156
+ fi
157
+ done
158
+ }
@@ -0,0 +1,69 @@
1
+ #!/bin/sh
2
+ # agent-def-test.sh — self-test for agent-def.sh under bash AND zsh (E257.6, #263).
3
+ # Hermetic: parses and translates a fixture role file. Run: bash scripts/lib/agent-def-test.sh
4
+ # errors: strict — a test runner: rc 1 on any failed assertion
5
+
6
+ dir=$(CDPATH='' cd -- "$(dirname -- "$0")" && pwd)
7
+
8
+ if [ -n "${AD_TEST_INNER:-}" ]; then
9
+ . "$dir/agent-def.sh"
10
+ fail=0
11
+ t() { if [ "$2" = "$3" ]; then :; else echo "FAIL($AD_TEST_INNER): $1 -> got '[$2]' want '[$3]'"; fail=1; fi; }
12
+ has() { case "$2" in *"$3"*) ;; *) echo "FAIL($AD_TEST_INNER): $1 missing '[$3]'"; fail=1 ;; esac; }
13
+ no() { case "$2" in *"$3"*) echo "FAIL($AD_TEST_INNER): $1 has unexpected '[$3]'"; fail=1 ;; esac; }
14
+
15
+ tmp="$(mktemp -d)"; trap 'rm -rf "$tmp"' EXIT
16
+ cat > "$tmp/tech-lead.md" <<'MD'
17
+ ---
18
+ name: tech-lead
19
+ model: sonnet
20
+ description: Tech Lead. Owns the "build" system and C:\paths.
21
+ when_to_use: When the toolchain changes.
22
+ tools: [Bash, Read, Edit]
23
+ skills:
24
+ - kit-task-pr # open the PR
25
+ - 'agent-skills:context7'
26
+ ---
27
+
28
+ # Tech Lead
29
+
30
+ Say "hello" and keep `a\b` literal.
31
+ MD
32
+ printf -- '---\nname: editor\ndescription: Edits.\nskills: [one, two]\n---\nbody\n' > "$tmp/editor.md"
33
+ printf -- '---\nname: bare\ndescription: Nothing listed.\nskills: []\n---\nbody\n' > "$tmp/bare.md"
34
+ printf -- '---\nname: nodesc\n---\nbody\n' > "$tmp/nodesc.md"
35
+
36
+ t "field: name" "$(agent_def_field "$tmp/tech-lead.md" name)" "tech-lead"
37
+ t "field: absent key is empty" "$(agent_def_field "$tmp/editor.md" model)" ""
38
+ t "field: body text is not frontmatter" "$(agent_def_field "$tmp/tech-lead.md" Say)" ""
39
+ t "skills: block list, comments and quotes stripped" "$(agent_def_skills "$tmp/tech-lead.md" | tr '\n' ' ')" "kit-task-pr agent-skills:context7 "
40
+ t "skills: inline list" "$(agent_def_skills "$tmp/editor.md" | tr '\n' ' ')" "one two "
41
+ t "skills: empty inline list" "$(agent_def_skills "$tmp/bare.md")" ""
42
+ t "body: starts at the first content line" "$(agent_def_body "$tmp/tech-lead.md" | sed -n 1p)" "# Tech Lead"
43
+ t "codex name: hyphen becomes underscore" "$(agent_def_codex_name tech-lead)" "tech_lead"
44
+
45
+ out="$(agent_def_codex "$tmp/tech-lead.md")"; t "codex: rc 0" "$?" "0"
46
+ has "codex: name key" "$out" 'name = "tech_lead"'
47
+ has "codex: description carries when_to_use, quotes and backslashes escaped" "$out" 'description = "Tech Lead. Owns the \"build\" system and C:\\paths. When the toolchain changes."'
48
+ has "codex: instructions open" "$out" 'developer_instructions = """'
49
+ has "codex: body escaped" "$out" 'Say \"hello\" and keep `a\\b` literal.'
50
+ has "codex: skills listed" "$out" '- agent-skills:context7'
51
+ has "codex: tools named as untranslated" "$out" '# Not translated — Claude Code tool allowlist: [Bash, Read, Edit]'
52
+ has "codex: model named as untranslated" "$out" '# Not translated — Claude model alias: sonnet'
53
+ no "codex: no tools key" "$out" 'tools ='
54
+ no "codex: no model key" "$out" 'model ='
55
+ t "codex: instructions close once" "$(printf '%s\n' "$out" | grep -c '^"""$')" "1"
56
+ no "codex: no skills section without skills" "$(agent_def_codex "$tmp/bare.md")" "Skills this role names"
57
+ agent_def_codex "$tmp/nodesc.md" >/dev/null 2>&1; t "codex: a role with no description is refused" "$?" "1"
58
+ agent_def_codex "$tmp/missing.md" >/dev/null 2>&1; t "codex: a missing file is refused" "$?" "1"
59
+
60
+ if [ "$fail" -eq 0 ]; then echo "PASS($AD_TEST_INNER): agent definition reader + Codex translation"; fi
61
+ exit "$fail"
62
+ fi
63
+
64
+ rc=0
65
+ for sh in bash zsh; do
66
+ command -v "$sh" >/dev/null 2>&1 || continue
67
+ AD_TEST_INNER="$sh" "$sh" "$0" || rc=1
68
+ done
69
+ exit "$rc"