@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
@@ -50,6 +50,25 @@ t "scaffold added morning-briefing skill" "$([ -f .claude/skills/morning-briefin
50
50
  t "scaffold added speckit skill" "$([ -d .claude/skills/speckit ] && echo yes || echo no)" "yes"
51
51
  t "scaffold added task-management rule" "$([ -f .claude/rules/task-management.md ] && echo yes || echo no)" "yes"
52
52
  t "scaffold copied task-sync.sh" "$([ -f scripts/task-sync.sh ] && echo yes || echo no)" "yes"
53
+ # E303.10: the code-graph integration is off in this config, so the scaffold carries neither the
54
+ # retrieval rule nor its CLAUDE.md line.
55
+ t "integration off: no code-retrieval rule" "$([ -e .claude/rules/code-retrieval.md ] && echo present || echo absent)" "absent"
56
+ t "integration off: no CLAUDE.md line" "$(grep -c 'code-retrieval' CLAUDE.md)" "0"
57
+ t "no unresolved IF marker in CLAUDE.md" "$(grep -c 'IF:CODEGRAPH' CLAUDE.md)" "0"
58
+ # task-sync.sh sources board-view.sh under `set -e` and effort-plan.sh for --plan (#383).
59
+ t "scaffold copied board-view.sh" "$([ -f scripts/lib/board-view.sh ] && echo yes || echo no)" "yes"
60
+ t "scaffold copied effort-plan.sh" "$([ -f scripts/lib/effort-plan.sh ] && echo yes || echo no)" "yes"
61
+
62
+
63
+ # #357: the instruction-budget lint ships with the scaffold, its baseline is seeded once, and the
64
+ # scaffold starts green — the two shipped rules over 200 lines are grandfathered, not failures.
65
+ t "scaffold copied instruction-budget-lint.sh" "$([ -x scripts/instruction-budget-lint.sh ] && echo yes || echo no)" "yes"
66
+ IB_BASELINE="$(bash scripts/instruction-budget-lint.sh --baseline-path 2>/dev/null)"
67
+ t "instruction-budget baseline seeded" "$([ -f "$IB_BASELINE" ] && echo yes || echo no)" "yes"
68
+ t "seeded baseline grandfathers effort-model.md" "$(grep -c '^\.claude/rules/effort-model\.md [0-9]*$' "$IB_BASELINE")" "1"
69
+ t "scaffolded project passes the instruction-budget lint" "$(bash scripts/instruction-budget-lint.sh >/dev/null 2>&1; echo $?)" "0"
70
+ IB_MARKER="# LOCAL-BASELINE-MARKER-#357 (a second init run must not rewrite the baseline)"
71
+ printf '%s\n' "$IB_MARKER" >> "$IB_BASELINE"
53
72
 
54
73
  git add -A && git commit -q -m "scaffold"
55
74
 
@@ -84,12 +103,14 @@ t "renamed target still present" "$([ -d .claude/skills/kit-morning-brie
84
103
  # 2. kit-owned script PRESERVED (not downgraded — marker survives)
85
104
  t "script not downgraded (marker kept)" "$(grep -cF "$MARKER" scripts/task-sync.sh)" "1"
86
105
 
106
+ t "instruction-budget baseline not rewritten (marker kept)" "$(grep -cF "$IB_MARKER" "$IB_BASELINE")" "1"
107
+
87
108
  # 3. net effect = ONLY the kitVersion bump
88
109
  changed="$(git status --porcelain | awk '{print $2}' | sort | tr '\n' ' ' | sed 's/ $//')"
89
110
  t "only kit.config.json changed" "$changed" ".claude/kit.config.json"
90
111
 
91
112
  diff_body="$(git diff -- .claude/kit.config.json | grep -E '^[+-]' | grep -vE '^(\+\+\+|---)')"
92
- only_kitver="$(printf '%s\n' "$diff_body" | grep -vqE '"kitVersion"' && echo no || echo yes)"
113
+ only_kitver="$([ -n "$(printf '%s' "$diff_body" | grep -vE '"kitVersion"')" ] && echo no || echo yes)"
93
114
  t "diff is only the kitVersion line" "$only_kitver" "yes"
94
115
  t "kitVersion bumped to plugin version" "$(jq -r '.kitVersion' .claude/kit.config.json)" "$PLUGIN_VERSION"
95
116
  t "upgrade block preserved through merge" "$(jq -r '.upgrade.removed | length' .claude/kit.config.json)" "2"
@@ -128,6 +149,324 @@ CLAUDE_PLUGIN_ROOT="$PLUGIN_DIR" bash "$INIT" --upgrade --target "$proj" >/dev/n
128
149
  t "customized statusline preserved (untracked)" "$(grep -cF "$SL_MARKER" .claude/statusline.sh)" "1"
129
150
  t "feature keys still absent after repeat upgrades" "$(jq 'has("plans")' .claude/kit.config.json)" "false"
130
151
 
152
+ # --- E303.10: an upgrade over a config with a code-graph integration ON -----------------
153
+ # `"none"` is off; a provider name is on. CLAUDE.md is removed first so the upgrade regenerates it
154
+ # (an existing CLAUDE.md is preserved, line or no line).
155
+ git add -A && git commit -q -m "settle before code-graph cases"
156
+ jq '.kitVersion = "0.0.4" | .codeGraph = {provider: "none"}' .claude/kit.config.json > .claude/kit.config.json.tmp \
157
+ && mv .claude/kit.config.json.tmp .claude/kit.config.json
158
+ rm -f CLAUDE.md
159
+ git add -A && git commit -q -m "codeGraph none"
160
+ CLAUDE_PLUGIN_ROOT="$PLUGIN_DIR" bash "$INIT" --upgrade --target "$proj" >/dev/null 2>&1 \
161
+ || { echo "FAIL: codeGraph-none upgrade run exited non-zero"; exit 1; }
162
+ t "provider none: no code-retrieval rule" "$([ -e .claude/rules/code-retrieval.md ] && echo present || echo absent)" "absent"
163
+ t "provider none: no CLAUDE.md line" "$(grep -c 'code-retrieval' CLAUDE.md)" "0"
164
+
165
+ jq '.kitVersion = "0.0.5" | .codeGraph.provider = "graft"' .claude/kit.config.json > .claude/kit.config.json.tmp \
166
+ && mv .claude/kit.config.json.tmp .claude/kit.config.json
167
+ rm -f CLAUDE.md
168
+ git add -A && git commit -q -m "codeGraph graft"
169
+ CLAUDE_PLUGIN_ROOT="$PLUGIN_DIR" bash "$INIT" --upgrade --target "$proj" >/dev/null 2>&1 \
170
+ || { echo "FAIL: codeGraph-on upgrade run exited non-zero"; exit 1; }
171
+ t "provider on: code-retrieval rule added" "$([ -f .claude/rules/code-retrieval.md ] && echo yes || echo no)" "yes"
172
+ t "provider on: CLAUDE.md carries the line" "$(grep -c 'rules/code-retrieval.md' CLAUDE.md)" "1"
173
+ t "provider on: the key survives the merge" "$(jq -r '.codeGraph.provider' .claude/kit.config.json)" "graft"
174
+
175
+ # --- E257.3: adapter selection — claude / codex / both ----------------------------------
176
+ # Fresh inits in throwaway projects. KIT_INIT_PREFLIGHT=0 skips the doctor (it installs packages and
177
+ # checks gh auth); --repo/--owner-login/KIT_BASE_BRANCH answer every question gh would be asked.
178
+ fx="$(mktemp -d)"; trap 'rm -rf "$proj" "$fx"' EXIT
179
+ fresh() { # fresh <dir> <adapter>
180
+ mkdir -p "$fx/$1" && git -C "$fx/$1" init -q \
181
+ && git -C "$fx/$1" config user.email kit-test@example.com && git -C "$fx/$1" config user.name kit-test \
182
+ && KIT_INIT_PREFLIGHT=0 KIT_BASE_BRANCH=main CLAUDE_PLUGIN_ROOT="$PLUGIN_DIR" bash "$INIT" \
183
+ --profile minimal --adapter "$2" --target "$fx/$1" --repo example/fx --owner-login example \
184
+ >/dev/null 2>&1 </dev/null
185
+ }
186
+ upgrade() { # upgrade <dir> [extra init flags…]
187
+ local d="$1"; shift
188
+ CLAUDE_PLUGIN_ROOT="$PLUGIN_DIR" bash "$INIT" --upgrade --target "$fx/$d" "$@" >/dev/null 2>&1 </dev/null
189
+ }
190
+ settle() { git -C "$fx/$1" add -A >/dev/null 2>&1 && git -C "$fx/$1" commit -q -m "$2" >/dev/null 2>&1; }
191
+ setver() { # setver <dir> <config-relpath> <version>
192
+ jq --arg v "$3" '.kitVersion = $v' "$fx/$1/$2" > "$fx/$1/$2.tmp" && mv "$fx/$1/$2.tmp" "$fx/$1/$2"
193
+ }
194
+ # Every file under an adapter's managed trees (and its instruction file) — what the manifest must list.
195
+ managed_files() { # managed_files <dir> <claude|codex>
196
+ ( cd "$fx/$1" || exit 0
197
+ if [ "$2" = claude ]; then
198
+ find .claude/skills .claude/rules .claude/agents .claude/hooks .claude/lib -type f 2>/dev/null
199
+ [ -f CLAUDE.md ] && echo CLAUDE.md
200
+ else
201
+ find .agents/skills .agents/rules .codex/agents -type f 2>/dev/null
202
+ [ -f AGENTS.md ] && echo AGENTS.md
203
+ fi ) | sed 's|^\./||' | sort
204
+ }
205
+ unrecorded() { # unrecorded <dir> <manifest-relpath> <adapter> -> managed files missing from the manifest
206
+ managed_files "$1" "$3" | while IFS= read -r f; do
207
+ jq -e --arg f "$f" '.entries | has($f)' "$fx/$1/$2" >/dev/null 2>&1 || echo "$f"
208
+ done | tr '\n' ' '
209
+ }
210
+ tree_hash() { # tree_hash <dir> <path…> -> one hash over every file's path + content
211
+ local d="$1"; shift
212
+ ( cd "$fx/$d" && find "$@" -type f 2>/dev/null | sort | while IFS= read -r f; do
213
+ printf '%s ' "$f"; { shasum -a 256 "$f" 2>/dev/null || sha256sum "$f"; } | awk '{print $1}'
214
+ done ) | { shasum -a 256 2>/dev/null || sha256sum; } | awk '{print $1}'
215
+ }
216
+ has_path() { [ -e "$fx/$1/$2" ] && echo yes || echo no; }
217
+
218
+ fresh c claude || { echo "FAIL: fresh --adapter claude exited non-zero"; fail=1; }
219
+ fresh x codex || { echo "FAIL: fresh --adapter codex exited non-zero"; fail=1; }
220
+ fresh b both || { echo "FAIL: fresh --adapter both exited non-zero"; fail=1; }
221
+
222
+ # 6. each selection produces ONLY its adapter's managed files
223
+ t "claude: CLAUDE.md written" "$(has_path c CLAUDE.md)" "yes"
224
+ t "claude: .claude skills written" "$(has_path c .claude/skills/concrete/SKILL.md)" "yes"
225
+ t "claude: no AGENTS.md" "$(has_path c AGENTS.md)" "no"
226
+ t "claude: no .agents tree" "$(has_path c .agents)" "no"
227
+ t "claude: stored selection" "$(jq -c '.adapters' "$fx/c/.claude/kit.config.json")" '["claude"]'
228
+ t "codex: AGENTS.md written" "$(has_path x AGENTS.md)" "yes"
229
+ t "codex: skills under .agents/skills" "$(has_path x .agents/skills/concrete/SKILL.md)" "yes"
230
+ t "codex: rules under .agents/rules" "$(has_path x .agents/rules/branch-naming.md)" "yes"
231
+ t "codex: no CLAUDE.md" "$(has_path x CLAUDE.md)" "no"
232
+ t "codex: no .claude tree at all" "$(has_path x .claude)" "no"
233
+ t "codex: config at the root" "$(jq -c '.adapters' "$fx/x/cckit.config.json")" '["codex"]'
234
+ t "codex: manifest under .cckit/" "$(has_path x .cckit/kit.manifest.json)" "yes"
235
+ t "codex: manifest is gitignored" "$(grep -cxF '.cckit/kit.manifest.json' "$fx/x/.gitignore")" "1"
236
+ t "codex: no Claude settings ignore line" "$(grep -cF '.claude/settings' "$fx/x/.gitignore")" "0"
237
+ t "codex: .cckit/ is gitignored" "$(grep -cxF '.cckit/' "$fx/x/.gitignore")" "1"
238
+ t "both: CLAUDE.md + AGENTS.md" "$(has_path b CLAUDE.md)$(has_path b AGENTS.md)" "yesyes"
239
+ t "both: both skill trees" "$(has_path b .claude/skills/concrete/SKILL.md)$(has_path b .agents/skills/concrete/SKILL.md)" "yesyes"
240
+ t "both: stored selection" "$(jq -c '.adapters' "$fx/b/.claude/kit.config.json")" '["claude","codex"]'
241
+ t "both: one manifest, in .claude/" "$(has_path b .claude/kit.manifest.json)$(has_path b .cckit)" "yesno"
242
+
243
+ # 7. every managed file is in the ownership manifest
244
+ t "claude: every managed file recorded" "$(unrecorded c .claude/kit.manifest.json claude)" ""
245
+ t "codex: every managed file recorded" "$(unrecorded x .cckit/kit.manifest.json codex)" ""
246
+ t "both: claude files recorded" "$(unrecorded b .claude/kit.manifest.json claude)" ""
247
+ t "both: codex files recorded" "$(unrecorded b .claude/kit.manifest.json codex)" ""
248
+ t "codex: managed set is not empty" "$([ "$(managed_files x codex | wc -l | tr -d ' ')" -ge 5 ] && echo yes || echo no)" "yes"
249
+ t "config is not a manifest entry" "$(jq '.entries | has("cckit.config.json") or has(".claude/kit.config.json")' "$fx/x/.cckit/kit.manifest.json")" "false"
250
+
251
+ # 8. nothing generated on the Codex side carries a machine path or a Claude plugin variable
252
+ t "codex: no absolute machine path" "$(grep -rlF "$fx" "$fx/x/AGENTS.md" "$fx/x/.agents" "$fx/x/cckit.config.json" 2>/dev/null | wc -l | tr -d ' ')" "0"
253
+ t "codex: no CLAUDE_PLUGIN_ROOT" "$(grep -rlE 'CLAUDE_PLUGIN_ROOT|CLAUDE_PROJECT_DIR' "$fx/x/AGENTS.md" "$fx/x/.agents" "$fx/x/cckit.config.json" 2>/dev/null | wc -l | tr -d ' ')" "0"
254
+ t "codex: no unrendered placeholder" "$(grep -rlE '\{\{[A-Z_]+\}\}' "$fx/x/AGENTS.md" "$fx/x/.agents" 2>/dev/null | wc -l | tr -d ' ')" "0"
255
+ t "codex: instructions point at .agents" "$(grep -c '\.agents/rules/branch-naming\.md' "$fx/x/AGENTS.md")" "1"
256
+ t "codex: instructions name no .claude path" "$(grep -c '\.claude/' "$fx/x/AGENTS.md")" "0"
257
+ t "both: codex side has no machine path" "$(grep -rlF "$fx" "$fx/b/AGENTS.md" "$fx/b/.agents" 2>/dev/null | wc -l | tr -d ' ')" "0"
258
+
259
+ # 9. an unknown adapter refuses before anything is written
260
+ mkdir -p "$fx/bad"
261
+ KIT_INIT_PREFLIGHT=0 bash "$INIT" --profile minimal --adapter cursor --target "$fx/bad" >/dev/null 2>&1 </dev/null
262
+ t "unknown adapter refused (rc)" "$?" "1"
263
+ t "unknown adapter wrote nothing" "$(ls -A "$fx/bad" | wc -l | tr -d ' ')" "0"
264
+
265
+ # 10. --upgrade keeps the stored selection and a hand-edited adapter file (Codex-only project)
266
+ settle x "scaffold codex"
267
+ X_MARKER="# LOCAL-CODEX-EDIT (must survive upgrade)"
268
+ printf '\n%s\n' "$X_MARKER" >> "$fx/x/.agents/skills/concrete/SKILL.md"
269
+ rm -f "$fx/x/.agents/rules/branch-naming.md" # a missing file the upgrade should restore
270
+ setver x cckit.config.json 0.0.1
271
+ settle x "edit a skill, drop a rule, reset version"
272
+ x_entries="$(jq '.entries | length' "$fx/x/.cckit/kit.manifest.json")"
273
+ upgrade x || { echo "FAIL: codex-only upgrade exited non-zero"; fail=1; }
274
+ t "upgrade: selection still codex" "$(jq -c '.adapters' "$fx/x/cckit.config.json")" '["codex"]'
275
+ t "upgrade: kitVersion bumped" "$(jq -r '.kitVersion' "$fx/x/cckit.config.json")" "$PLUGIN_VERSION"
276
+ t "upgrade: still no .claude tree" "$(has_path x .claude)" "no"
277
+ t "upgrade: still no CLAUDE.md" "$(has_path x CLAUDE.md)" "no"
278
+ t "upgrade: hand-edited skill kept" "$(grep -cF "$X_MARKER" "$fx/x/.agents/skills/concrete/SKILL.md")" "1"
279
+ t "upgrade: edited skill reads modified" "$(cd "$fx/x" && . "$PLUGIN_DIR/scripts/lib/kit-manifest.sh" && kit_manifest_verify .agents/skills/concrete/SKILL.md)" "modified"
280
+ t "upgrade: missing rule restored" "$(has_path x .agents/rules/branch-naming.md)" "yes"
281
+ t "upgrade: no duplicate manifest entries" "$(jq '.entries | length' "$fx/x/.cckit/kit.manifest.json")" "$x_entries"
282
+
283
+ # 11. a repeated upgrade changes nothing
284
+ settle x "settle upgrade"
285
+ x_manifest="$(jq -S '.entries | map_values(.hash)' "$fx/x/.cckit/kit.manifest.json")"
286
+ setver x cckit.config.json 0.0.2; settle x "reset version again"
287
+ upgrade x || { echo "FAIL: repeated codex upgrade exited non-zero"; fail=1; }
288
+ t "repeat: same manifest paths + hashes" "$(jq -S '.entries | map_values(.hash)' "$fx/x/.cckit/kit.manifest.json")" "$x_manifest"
289
+ t "repeat: only the config changed" "$(git -C "$fx/x" status --porcelain | awk '{print $2}' | tr '\n' ' ' | sed 's/ $//')" "cckit.config.json"
290
+ upgrade x; t "same-version upgrade is a no-op (rc 0)" "$?" "0"
291
+ t "same-version upgrade wrote nothing" "$(git -C "$fx/x" status --porcelain | awk '{print $2}' | tr '\n' ' ' | sed 's/ $//')" "cckit.config.json"
292
+
293
+ # 12. enabling the second adapter leaves the first one's files byte-identical
294
+ settle c "scaffold claude"
295
+ c_before="$(tree_hash c .claude/skills .claude/rules .claude/agents .claude/hooks .claude/lib .claude/settings.json .claude/settings.local.json .claude/statusline.sh CLAUDE.md)"
296
+ c_entries="$(jq '.entries | length' "$fx/c/.claude/kit.manifest.json")"
297
+ upgrade c --adapter codex || { echo "FAIL: enabling codex on a claude project exited non-zero"; fail=1; }
298
+ t "add codex: claude files byte-identical" "$(tree_hash c .claude/skills .claude/rules .claude/agents .claude/hooks .claude/lib .claude/settings.json .claude/settings.local.json .claude/statusline.sh CLAUDE.md)" "$c_before"
299
+ t "add codex: selection is both" "$(jq -c '.adapters' "$fx/c/.claude/kit.config.json")" '["claude","codex"]'
300
+ t "add codex: AGENTS.md + skills arrive" "$(has_path c AGENTS.md)$(has_path c .agents/skills/concrete/SKILL.md)" "yesyes"
301
+ t "add codex: config did not move" "$(has_path c cckit.config.json)" "no"
302
+ t "add codex: codex files recorded" "$(unrecorded c .claude/kit.manifest.json codex)" ""
303
+ t "add codex: claude entries kept" "$([ "$(jq '.entries | length' "$fx/c/.claude/kit.manifest.json")" -gt "$c_entries" ] && echo yes || echo no)" "yes"
304
+
305
+ settle x "settle before enabling claude"
306
+ x_before="$(tree_hash x .agents AGENTS.md)"
307
+ upgrade x --adapter claude || { echo "FAIL: enabling claude on a codex project exited non-zero"; fail=1; }
308
+ t "add claude: codex files byte-identical" "$(tree_hash x .agents AGENTS.md)" "$x_before"
309
+ t "add claude: selection is both" "$(jq -c '.adapters' "$fx/x/cckit.config.json")" '["claude","codex"]'
310
+ t "add claude: CLAUDE.md + skills arrive" "$(has_path x CLAUDE.md)$(has_path x .claude/skills/concrete/SKILL.md)" "yesyes"
311
+ t "add claude: config stays at the root" "$(has_path x .claude/kit.config.json)" "no"
312
+ t "add claude: manifest stays in .cckit/" "$(has_path x .claude/kit.manifest.json)" "no"
313
+ t "add claude: claude files recorded" "$(unrecorded x .cckit/kit.manifest.json claude)" ""
314
+
315
+ # 13. a project's own AGENTS.md is not replaced by a fresh Codex init
316
+ mkdir -p "$fx/own" && printf 'my own contract\n' > "$fx/own/AGENTS.md"
317
+ fresh own codex || { echo "FAIL: fresh codex init over an existing AGENTS.md exited non-zero"; fail=1; }
318
+ t "existing AGENTS.md kept" "$(cat "$fx/own/AGENTS.md")" "my own contract"
319
+ t "kept AGENTS.md is not claimed as owned" "$(jq '.entries | has("AGENTS.md")' "$fx/own/.cckit/kit.manifest.json")" "false"
320
+
321
+ # 14. doctor reports each SELECTED runtime present / absent (stub binaries; no network)
322
+ mkdir -p "$fx/bin"
323
+ printf '#!/bin/sh\necho "codex-cli 9.9.9"\n' > "$fx/bin/codex"; chmod +x "$fx/bin/codex"
324
+ doc="$(cd "$fx/b" && PATH="$fx/bin:/usr/bin:/bin" KIT_ASCII=1 NO_COLOR=1 bash "$PLUGIN_DIR/scripts/kit-doctor.sh" --agents 2>&1)"; doc_rc=$?
325
+ t "doctor: absent runtime exits 1" "$doc_rc" "1"
326
+ t "doctor: codex reported present" "$(printf '%s\n' "$doc" | grep -c 'codex .*codex-cli 9.9.9')" "1"
327
+ t "doctor: claude reported absent" "$(printf '%s\n' "$doc" | grep -c 'claude .*absent')" "1"
328
+ printf '#!/bin/sh\necho "9.9.9 (Claude Code)"\n' > "$fx/bin/claude"; chmod +x "$fx/bin/claude"
329
+ ( cd "$fx/b" && PATH="$fx/bin:/usr/bin:/bin" KIT_ASCII=1 NO_COLOR=1 bash "$PLUGIN_DIR/scripts/kit-doctor.sh" --agents >/dev/null 2>&1 )
330
+ t "doctor: both present exits 0" "$?" "0"
331
+ rm -f "$fx/bin/claude"
332
+ doc="$(cd "$fx/own" && PATH="$fx/bin:/usr/bin:/bin" KIT_ASCII=1 NO_COLOR=1 bash "$PLUGIN_DIR/scripts/kit-doctor.sh" --agents 2>&1)"; doc_rc=$?
333
+ t "doctor: unselected runtime not checked" "$doc_rc$(printf '%s\n' "$doc" | grep -c 'claude')" "00"
334
+
335
+ # --- E257.5: hooks and session mail on both adapters ------------------------------------
336
+ # shellcheck disable=SC2016
337
+ MAILCMD='bash "$CLAUDE_PROJECT_DIR/.claude/hooks/kit-mail-check.sh"'
338
+ CXMAIL='bash "$(git rev-parse --show-toplevel)/.codex/hooks/kit-mail-check.sh"'
339
+ mail_events() { # mail_events <file> <command> -> the events that run <command>, sorted
340
+ jq -r --arg c "$2" '[(.hooks // {}) | to_entries[] | select([.value[].hooks[].command] | index($c)) | .key] | sort | join(" ")' "$1" 2>/dev/null
341
+ }
342
+
343
+ # 15. the Claude adapter installs AND wires the mail hook (it shipped as a template only before)
344
+ fresh hc claude || { echo "FAIL: fresh claude init (hooks) exited non-zero"; fail=1; }
345
+ t "claude: mail hook installed" "$([ -x "$fx/hc/.claude/hooks/kit-mail-check.sh" ] && echo yes || echo no)" "yes"
346
+ t "claude: mail wired on four events" "$(mail_events "$fx/hc/.claude/settings.json" "$MAILCMD")" "PostToolUse SessionStart Stop UserPromptSubmit"
347
+ t "claude: mail hook recorded as owned" "$(jq '.entries | has(".claude/hooks/kit-mail-check.sh")' "$fx/hc/.claude/kit.manifest.json")" "true"
348
+ t "claude: no .codex tree" "$(has_path hc .codex)" "no"
349
+ settle hc "scaffold claude with mail"
350
+ # a user-tuned registration survives the upgrade, and nothing is registered twice
351
+ jq --arg c "$MAILCMD" '(.hooks.Stop[] | select(.hooks[0].command == $c) | .hooks[0].timeout) = 45' \
352
+ "$fx/hc/.claude/settings.json" > "$fx/hc/s.tmp" && mv "$fx/hc/s.tmp" "$fx/hc/.claude/settings.json"
353
+ setver hc .claude/kit.config.json 0.0.1; settle hc "tune the Stop timeout"
354
+ upgrade hc || { echo "FAIL: claude upgrade (hooks) exited non-zero"; fail=1; }
355
+ t "claude upgrade: tuned timeout kept" "$(jq --arg c "$MAILCMD" '[.hooks.Stop[].hooks[] | select(.command == $c) | .timeout] | join(",")' "$fx/hc/.claude/settings.json")" '"45"'
356
+ t "claude upgrade: one mail handler per event" "$(jq --arg c "$MAILCMD" '[.hooks[][].hooks[] | select(.command == $c)] | length' "$fx/hc/.claude/settings.json")" "4"
357
+ t "claude upgrade: only the config changed" "$(git -C "$fx/hc" status --porcelain | awk '{print $2}' | tr '\n' ' ' | sed 's/ $//')" ".claude/kit.config.json"
358
+
359
+ # 16. a Codex-only project gets the hook scripts and a hooks.json with no machine path
360
+ fresh hx codex || { echo "FAIL: fresh codex init (hooks) exited non-zero"; fail=1; }
361
+ t "codex: hook scripts installed" "$(ls "$fx/hx/.codex/hooks" 2>/dev/null | LC_ALL=C sort | tr '\n' ' ')" "guard-base-branch-commit.sh guard-raw-git-ops.sh kit-mail-check.sh kit_version_check.sh repo-hygiene.sh "
362
+ t "codex: hook scripts are executable" "$(find "$fx/hx/.codex/hooks" -type f ! -perm -u+x | wc -l | tr -d ' ')" "0"
363
+ t "codex: mail on four events" "$(mail_events "$fx/hx/.codex/hooks.json" "$CXMAIL")" "PostToolUse SessionStart Stop UserPromptSubmit"
364
+ t "codex: hooks carry no machine path" "$(grep -rlF "$fx" "$fx/hx/.codex" 2>/dev/null | wc -l | tr -d ' ')" "0"
365
+ t "codex: no memory hook installed" "$(ls "$fx/hx/.codex/hooks" | grep -c mempal)" "0"
366
+ t "codex: still no .claude tree" "$(has_path hx .claude)" "no"
367
+ t "codex: hooks recorded as owned" "$(jq -r '[.entries | keys[] | select(startswith(".codex/hooks"))] | length' "$fx/hx/.cckit/kit.manifest.json")" "6"
368
+ settle hx "scaffold codex with hooks"
369
+ hx_before="$(tree_hash hx .codex)"
370
+ setver hx cckit.config.json 0.0.1; settle hx "reset version"
371
+ upgrade hx || { echo "FAIL: codex upgrade (hooks) exited non-zero"; fail=1; }
372
+ t "codex upgrade: .codex byte-identical (hook trust kept)" "$(tree_hash hx .codex)" "$hx_before"
373
+ t "codex upgrade: only the config changed" "$(git -C "$fx/hx" status --porcelain | awk '{print $2}' | tr '\n' ' ' | sed 's/ $//')" "cckit.config.json"
374
+
375
+ # 17. a project that already keeps its own .codex/ — entries, a script, config.toml — keeps all of it
376
+ mkdir -p "$fx/hu/.codex/hooks"
377
+ cat > "$fx/hu/.codex/hooks.json" <<'JSON'
378
+ { "hooks": { "PreToolUse": [ { "matcher": "Bash", "hooks": [ { "type": "command", "command": "python3 my_policy.py", "timeout": 30 } ] } ],
379
+ "SubagentStop": [ { "hooks": [ { "type": "command", "command": "echo mine" } ] } ] } }
380
+ JSON
381
+ printf '#!/bin/sh\n# my own mail hook\n' > "$fx/hu/.codex/hooks/kit-mail-check.sh"
382
+ printf '[mcp_servers.mine]\ncommand = "npx"\n' > "$fx/hu/.codex/config.toml"
383
+ fresh hu codex || { echo "FAIL: fresh codex init over an existing .codex exited non-zero"; fail=1; }
384
+ t "merge: the user's guard entry is kept, first" "$(jq -r '.hooks.PreToolUse[0].hooks[0].command' "$fx/hu/.codex/hooks.json")" "python3 my_policy.py"
385
+ t "merge: the user's other event is kept" "$(jq -r '.hooks.SubagentStop[0].hooks[0].command' "$fx/hu/.codex/hooks.json")" "echo mine"
386
+ t "merge: cckit's guards were added" "$(jq '.hooks.PreToolUse | length' "$fx/hu/.codex/hooks.json")" "3"
387
+ t "merge: cckit's mail was added" "$(mail_events "$fx/hu/.codex/hooks.json" "$CXMAIL")" "PostToolUse SessionStart Stop UserPromptSubmit"
388
+ t "merge: no machine path" "$(grep -cF "$fx" "$fx/hu/.codex/hooks.json")" "0"
389
+ t "merge: the user's hooks.json is not claimed as owned" "$(jq '.entries | has(".codex/hooks.json")' "$fx/hu/.cckit/kit.manifest.json")" "false"
390
+ t "merge: the user's own hook script is kept" "$(sed -n 2p "$fx/hu/.codex/hooks/kit-mail-check.sh")" "# my own mail hook"
391
+ t "merge: the kept script is not claimed" "$(jq '.entries | has(".codex/hooks/kit-mail-check.sh")' "$fx/hu/.cckit/kit.manifest.json")" "false"
392
+ t "merge: config.toml untouched" "$(cat "$fx/hu/.codex/config.toml")" "$(printf '[mcp_servers.mine]\ncommand = "npx"')"
393
+ settle hu "scaffold over my own .codex"
394
+ hu_before="$(tree_hash hu .codex)"
395
+ setver hu cckit.config.json 0.0.1; settle hu "reset version"
396
+ upgrade hu || { echo "FAIL: upgrade over a user-edited hooks.json exited non-zero"; fail=1; }
397
+ t "merge: upgrade leaves .codex byte-identical" "$(tree_hash hu .codex)" "$hu_before"
398
+
399
+ # 18. an unparseable hooks.json is left alone, reported, and repairable at the same version
400
+ mkdir -p "$fx/hb/.codex" && printf '{ not json\n' > "$fx/hb/.codex/hooks.json"
401
+ fresh hb codex; t "bad hooks.json: init still completes (rc)" "$?" "0"
402
+ t "bad hooks.json: file untouched" "$(cat "$fx/hb/.codex/hooks.json")" "{ not json"
403
+ doc="$(cd "$fx/hb" && PATH="$fx/bin:$PATH" KIT_ASCII=1 NO_COLOR=1 bash "$PLUGIN_DIR/scripts/kit-doctor.sh" --agents 2>&1)"
404
+ t "doctor: unregistered codex hooks reported" "$(printf '%s\n' "$doc" | grep -c 'codex hooks .*not registered')" "1"
405
+ printf '{}\n' > "$fx/hb/.codex/hooks.json"; settle hb "fix hooks.json"
406
+ upgrade hb; t "repair: same-version upgrade runs (rc)" "$?" "0"
407
+ t "repair: hooks now registered" "$(mail_events "$fx/hb/.codex/hooks.json" "$CXMAIL")" "PostToolUse SessionStart Stop UserPromptSubmit"
408
+ doc="$(cd "$fx/hb" && PATH="$fx/bin:$PATH" KIT_ASCII=1 NO_COLOR=1 bash "$PLUGIN_DIR/scripts/kit-doctor.sh" --agents 2>&1)"
409
+ t "doctor: registered codex hooks reported" "$(printf '%s\n' "$doc" | grep -c 'codex hooks .*registered in .codex/hooks.json')" "1"
410
+ t "doctor: says trust is not readable" "$(printf '%s\n' "$doc" | grep -c 'trust is not readable')" "1"
411
+
412
+ # 19. enabling Codex on a Claude project adds the Codex hooks and leaves the Claude ones alone
413
+ settle hc "settle before enabling codex"
414
+ hc_before="$(tree_hash hc .claude/hooks .claude/settings.json .claude/settings.local.json)"
415
+ upgrade hc --adapter codex || { echo "FAIL: enabling codex (hooks) exited non-zero"; fail=1; }
416
+ t "add codex: claude hooks byte-identical" "$(tree_hash hc .claude/hooks .claude/settings.json .claude/settings.local.json)" "$hc_before"
417
+ t "add codex: codex hooks registered" "$(mail_events "$fx/hc/.codex/hooks.json" "$CXMAIL")" "PostToolUse SessionStart Stop UserPromptSubmit"
418
+ t "add codex: one mail script, same bytes" "$(cmp -s "$fx/hc/.claude/hooks/kit-mail-check.sh" "$fx/hc/.codex/hooks/kit-mail-check.sh" && echo same || echo differs)" "same"
419
+
420
+ # --- E257.6: one role source, one agent definition per runtime ---------------------------
421
+ # `x` is the Codex-only project and `b` selects both, each on the minimal profile (pm, generalist).
422
+ toml_get() { # toml_get <file> <key> -> the value of a single-line `key = "…"` entry, unescaped
423
+ sed -n "s/^$2 = \"\(.*\)\"\$/\1/p" "$1" | sed 's/\\"/"/g; s/\\\\/\\/g'
424
+ }
425
+ # 20. Codex gets one agent definition per role, and a Claude-only project gets none
426
+ t "codex: one agent per profile role" "$(ls "$fx/x/.codex/agents" 2>/dev/null | LC_ALL=C sort | tr '\n' ' ')" "generalist.toml pm.toml "
427
+ t "both: same roles on both runtimes" "$(ls "$fx/b/.claude/agents" | LC_ALL=C sort | tr '\n' ' ')|$(ls "$fx/b/.codex/agents" | sed 's/\.toml$//' | LC_ALL=C sort | tr '\n' ' ')" "generalist pm |generalist pm "
428
+ fresh ac claude || { echo "FAIL: fresh claude init (agents) exited non-zero"; fail=1; }
429
+ t "claude: no .codex/agents" "$(has_path ac .codex)$(has_path ac .claude/agents/pm/AGENT.md)" "noyes"
430
+ t "codex: agent has the three required keys" "$(grep -cE '^(name|description|developer_instructions) = ' "$fx/x/.codex/agents/pm.toml")" "3"
431
+ # 21. the two definitions are the same role: description and body come from one template
432
+ b_desc="$(sed -n 's/^description: //p' "$fx/b/.claude/agents/generalist/AGENT.md") $(sed -n 's/^when_to_use: //p' "$fx/b/.claude/agents/generalist/AGENT.md")"
433
+ t "same role: description + when_to_use" "$(toml_get "$fx/b/.codex/agents/generalist.toml" description)" "$b_desc"
434
+ b_body="$(awk 'c>=2{print} /^---$/{c++}' "$fx/b/.claude/agents/generalist/AGENT.md" | sed '/./,$!d')"
435
+ x_body="$(awk '/^developer_instructions = """$/{on=1;next} /^"""$/{on=0} on' "$fx/b/.codex/agents/generalist.toml" | sed 's/\\"/"/g; s/\\\\/\\/g')"
436
+ t "same role: instructions are the role body" "$x_body" "$b_body"
437
+ t "codex: Claude tool allowlist is not a key" "$(grep -cE '^tools' "$fx/x/.codex/agents/pm.toml")" "0"
438
+ t "codex: untranslated allowlist is stated" "$(grep -c '^# Not translated — Claude Code tool allowlist' "$fx/x/.codex/agents/pm.toml")" "1"
439
+ t "codex: pm names the skills that exist" "$(grep -cE '^- kit-task-(sync|new|close)$' "$fx/x/.codex/agents/pm.toml")" "3"
440
+ if command -v python3 >/dev/null 2>&1 && python3 -c 'import tomllib' 2>/dev/null; then
441
+ t "codex: every agent file parses as TOML" "$(python3 -c '
442
+ import sys, tomllib
443
+ for f in sys.argv[1:]:
444
+ d = tomllib.load(open(f, "rb"))
445
+ assert d["name"] and d["description"] and d["developer_instructions"], f
446
+ print("ok")' "$fx"/x/.codex/agents/*.toml "$fx"/b/.codex/agents/*.toml 2>&1)" "ok"
447
+ fi
448
+ # 22. nothing Claude-specific or machine-specific leaks into a Codex-only project's agents
449
+ t "codex agents: no .claude path" "$(grep -rl '\.claude/' "$fx/x/.codex/agents" 2>/dev/null | wc -l | tr -d ' ')" "0"
450
+ t "codex agents: no machine path" "$(grep -rlF "$fx" "$fx/x/.codex/agents" "$fx/b/.codex/agents" 2>/dev/null | wc -l | tr -d ' ')" "0"
451
+ t "codex agents: no unrendered placeholder" "$(grep -rlE '\{\{[A-Z_]+\}\}|IF:ADAPTER' "$fx/x/.codex/agents" 2>/dev/null | wc -l | tr -d ' ')" "0"
452
+ t "codex: AGENTS.md lists the roles" "$(grep -cE '^\| `(pm|generalist)` \|' "$fx/x/AGENTS.md")" "2"
453
+ t "codex agents: recorded as owned" "$(jq -r '[.entries | keys[] | select(startswith(".codex/agents/"))] | length' "$fx/x/.cckit/kit.manifest.json")" "2"
454
+ # 23. a hand-edited agent survives an upgrade; a deleted one is restored; the user's own is kept
455
+ A_MARKER="# LOCAL-AGENT-EDIT (must survive upgrade)"
456
+ printf '%s\n' "$A_MARKER" >> "$fx/x/.codex/agents/pm.toml"
457
+ rm -f "$fx/x/.codex/agents/generalist.toml"
458
+ setver x cckit.config.json 0.0.4; settle x "edit one agent, drop another"
459
+ upgrade x || { echo "FAIL: codex upgrade (agents) exited non-zero"; fail=1; }
460
+ t "upgrade: hand-edited agent kept" "$(grep -cF "$A_MARKER" "$fx/x/.codex/agents/pm.toml")" "1"
461
+ t "upgrade: missing agent restored" "$(has_path x .codex/agents/generalist.toml)" "yes"
462
+ mkdir -p "$fx/au/.codex/agents" && printf 'name = "pm"\n# mine\n' > "$fx/au/.codex/agents/pm.toml"
463
+ fresh au codex || { echo "FAIL: fresh codex init over an existing agent exited non-zero"; fail=1; }
464
+ t "own agent: the user's file is kept" "$(sed -n 2p "$fx/au/.codex/agents/pm.toml")" "# mine"
465
+ t "own agent: not claimed as owned" "$(jq '.entries | has(".codex/agents/pm.toml")' "$fx/au/.cckit/kit.manifest.json")" "false"
466
+ t "own agent: the other role still arrives" "$(has_path au .codex/agents/generalist.toml)" "yes"
467
+ # 24. enabling Codex on a Claude project adds its agents without touching the Claude ones
468
+ t "add codex: agents arrive" "$(ls "$fx/hc/.codex/agents" 2>/dev/null | LC_ALL=C sort | tr '\n' ' ')" "generalist.toml pm.toml "
469
+
131
470
  echo ""
132
- [ "$fail" -eq 0 ] && echo "PASS: init.sh --upgrade honors the preserve/exclude contract (#334, #149)" || echo "FAILED"
471
+ [ "$fail" -eq 0 ] && echo "PASS: init.sh --upgrade honors the preserve/exclude contract (#334, #149), adapter selection (E257.3), hook registration (E257.5) and per-runtime agents (E257.6)" || echo "FAILED"
133
472
  exit "$fail"