@jeiemgi/cckit 0.8.0 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (309) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/AGENTS.md +169 -21
  3. package/README.md +505 -35
  4. package/SECURITY.md +5 -0
  5. package/bin/cckit +189 -20
  6. package/cckit.config.json +1 -1
  7. package/commands/kit-doctor.md +13 -5
  8. package/commands/kit-export-project.md +0 -2
  9. package/commands/kit-export-training.md +6 -9
  10. package/commands/kit-init.md +43 -13
  11. package/commands/kit-routines.md +1 -1
  12. package/commands/kit-update.md +11 -6
  13. package/databases/supabase/guide.html +106 -0
  14. package/databases/supabase/nextjs/lib/supabase/client.ts +9 -0
  15. package/databases/supabase/nextjs/lib/supabase/server.ts +29 -0
  16. package/databases/supabase.json +70 -0
  17. package/integrations/emil-design-eng.json +41 -0
  18. package/integrations/graft.json +81 -0
  19. package/integrations/impeccable.json +42 -0
  20. package/integrations/integration.schema.json +215 -0
  21. package/integrations/lavish.json +43 -0
  22. package/integrations/mempalace.json +28 -0
  23. package/integrations/mlx-lm.json +32 -0
  24. package/integrations/web-design-guidelines.json +42 -0
  25. package/kit.config.schema.json +183 -5
  26. package/package.json +4 -1
  27. package/profiles/automation.json +7 -1
  28. package/profiles/content.json +10 -2
  29. package/profiles/marketing.json +57 -0
  30. package/profiles/minimal.json +7 -1
  31. package/profiles/research.json +7 -1
  32. package/profiles/software.json +7 -1
  33. package/recipes/nextjs-shadcn.json +49 -0
  34. package/scripts/agent-skills-external.txt +45 -0
  35. package/scripts/agent-skills-lint-test.sh +131 -0
  36. package/scripts/agent-skills-lint.sh +115 -0
  37. package/scripts/agent-template-lint-test.sh +42 -0
  38. package/scripts/agent-template-lint.sh +58 -0
  39. package/scripts/annotate-setup.sh +1 -1
  40. package/scripts/autopilot-run-test.sh +338 -0
  41. package/scripts/autopilot-run.sh +448 -0
  42. package/scripts/autopilot-test.sh +8 -0
  43. package/scripts/autopilot.sh +10 -1
  44. package/scripts/benchmark/benchmark-test.sh +85 -0
  45. package/scripts/benchmark/checkpoint-test.sh +314 -0
  46. package/scripts/benchmark/checkpoint.sh +408 -0
  47. package/scripts/benchmark/lib/model.sh +31 -6
  48. package/scripts/benchmark/report.sh +17 -2
  49. package/scripts/benchmark/run-quality.sh +36 -10
  50. package/scripts/benchmark/verb-timings-test.sh +124 -0
  51. package/scripts/benchmark/verb-timings.sh +149 -0
  52. package/scripts/check.sh +29 -19
  53. package/scripts/content-skills-test.sh +144 -0
  54. package/scripts/copilot-loop-test.sh +25 -0
  55. package/scripts/database-supabase-test.sh +121 -0
  56. package/scripts/docs-marketing-words-test.sh +73 -0
  57. package/scripts/docs-record-tables-test.sh +72 -0
  58. package/scripts/guard-raw-git-ops-test.sh +8 -0
  59. package/scripts/hook-adapter-test.sh +193 -0
  60. package/scripts/init-content-test.sh +225 -0
  61. package/scripts/init-guided-test.sh +474 -0
  62. package/scripts/init-recipes-test.sh +104 -0
  63. package/scripts/init-upgrade-test.sh +341 -2
  64. package/scripts/init.sh +746 -95
  65. package/scripts/instruction-budget-baseline.txt +8 -0
  66. package/scripts/instruction-budget-lint-test.sh +166 -0
  67. package/scripts/instruction-budget-lint.sh +219 -0
  68. package/scripts/integrations-check-test.sh +200 -0
  69. package/scripts/integrations-check.sh +157 -0
  70. package/scripts/kit-add-test.sh +214 -0
  71. package/scripts/kit-add.sh +305 -5
  72. package/scripts/kit-adopt-test.sh +16 -0
  73. package/scripts/kit-adopt.sh +3 -2
  74. package/scripts/kit-digest.sh +2 -2
  75. package/scripts/kit-doctor-test.sh +293 -0
  76. package/scripts/kit-doctor.sh +272 -140
  77. package/scripts/kit-export-project-test.sh +3 -3
  78. package/scripts/kit-remove-test.sh +19 -0
  79. package/scripts/kit-routines.sh +2 -2
  80. package/scripts/kit-self-update.sh +1 -1
  81. package/scripts/kit-version-check-test.sh +4 -0
  82. package/scripts/kit-version-check.sh +4 -2
  83. package/scripts/knowledge-lint.sh +4 -4
  84. package/scripts/leak-fence-test.sh +89 -0
  85. package/scripts/lib/adapter-select-test.sh +136 -0
  86. package/scripts/lib/adapter-select.sh +158 -0
  87. package/scripts/lib/agent-def-test.sh +69 -0
  88. package/scripts/lib/agent-def.sh +106 -0
  89. package/scripts/lib/agent-launch-test.sh +212 -0
  90. package/scripts/lib/agent-launch.sh +335 -0
  91. package/scripts/lib/board-view-test.sh +11 -0
  92. package/scripts/lib/board-view.sh +42 -26
  93. package/scripts/lib/branch-owner-test.sh +26 -0
  94. package/scripts/lib/branch-owner.sh +16 -9
  95. package/scripts/lib/captain-test.sh +105 -0
  96. package/scripts/lib/captain.sh +87 -8
  97. package/scripts/lib/codex-hooks-test.sh +100 -0
  98. package/scripts/lib/codex-hooks.sh +69 -0
  99. package/scripts/lib/commitlint.sh +1 -1
  100. package/scripts/lib/content-kinds-gc-test.sh +88 -0
  101. package/scripts/lib/copilot-test.sh +70 -4
  102. package/scripts/lib/copilot.sh +66 -14
  103. package/scripts/lib/effort-dispatch-test.sh +3 -3
  104. package/scripts/lib/effort-metrics-test.sh +178 -1
  105. package/scripts/lib/effort-metrics.sh +188 -35
  106. package/scripts/lib/effort-ops-test.sh +217 -7
  107. package/scripts/lib/effort-ops.sh +281 -49
  108. package/scripts/lib/effort-parity-test.sh +49 -13
  109. package/scripts/lib/effort-plan-test.sh +337 -0
  110. package/scripts/lib/effort-plan.sh +200 -23
  111. package/scripts/lib/effort-slug.sh +16 -2
  112. package/scripts/lib/effort.sh +67 -12
  113. package/scripts/lib/errors-header-test.sh +1 -1
  114. package/scripts/lib/gh-project-test.sh +35 -1
  115. package/scripts/lib/gh-project.sh +37 -16
  116. package/scripts/lib/gh-rest-test.sh +330 -0
  117. package/scripts/lib/gh-rest.sh +304 -0
  118. package/scripts/lib/hook-refresh.sh +1 -1
  119. package/scripts/lib/init-github.sh +412 -0
  120. package/scripts/lib/init-guide.sh +630 -0
  121. package/scripts/lib/integration-install-test.sh +343 -0
  122. package/scripts/lib/integration-install.sh +257 -0
  123. package/scripts/lib/integrations-test.sh +366 -0
  124. package/scripts/lib/integrations.sh +244 -0
  125. package/scripts/lib/kinds-test.sh +125 -0
  126. package/scripts/lib/kinds.sh +66 -0
  127. package/scripts/lib/kit-brief-test.sh +22 -3
  128. package/scripts/lib/kit-brief.sh +45 -5
  129. package/scripts/lib/kit-config-resolve.sh +2 -2
  130. package/scripts/lib/kit-config-test.sh +64 -1
  131. package/scripts/lib/kit-config.sh +37 -1
  132. package/scripts/lib/kit-events.sh +7 -0
  133. package/scripts/lib/kit-gc-test.sh +173 -1
  134. package/scripts/lib/kit-gc.sh +244 -37
  135. package/scripts/lib/kit-hotfix.sh +216 -0
  136. package/scripts/lib/kit-interview-test.sh +93 -0
  137. package/scripts/lib/kit-interview.sh +117 -8
  138. package/scripts/lib/kit-lib-test.sh +1 -1
  139. package/scripts/lib/kit-lib.sh +3 -3
  140. package/scripts/lib/kit-local.sh +2 -2
  141. package/scripts/lib/kit-manifest.sh +33 -1
  142. package/scripts/lib/kit-profile-test.sh +3 -3
  143. package/scripts/lib/kit-status-test.sh +112 -4
  144. package/scripts/lib/kit-status.sh +246 -16
  145. package/scripts/lib/kit-task-ops-test.sh +37 -0
  146. package/scripts/lib/kit-task-ops.sh +362 -89
  147. package/scripts/lib/kto-hotfix-test.sh +232 -0
  148. package/scripts/lib/kto-task-close-test.sh +83 -0
  149. package/scripts/lib/kto-task-new-test.sh +95 -0
  150. package/scripts/lib/kto-task-pr-merge-test.sh +97 -6
  151. package/scripts/lib/kto-task-pr-test.sh +70 -0
  152. package/scripts/lib/leak-fence.sh +89 -0
  153. package/scripts/lib/light-task-run-test.sh +255 -0
  154. package/scripts/lib/light-task-test.sh +309 -0
  155. package/scripts/lib/light-task.sh +706 -0
  156. package/scripts/lib/next-test.sh +99 -0
  157. package/scripts/lib/next.sh +9 -3
  158. package/scripts/lib/orchestration-runtime-test.sh +72 -0
  159. package/scripts/lib/orchestration-runtime.sh +57 -5
  160. package/scripts/lib/plan-machine-test.sh +15 -2
  161. package/scripts/lib/plan-machine.sh +20 -7
  162. package/scripts/lib/plan-next-test.sh +1 -1
  163. package/scripts/lib/plan-next.sh +4 -4
  164. package/scripts/lib/pr-evidence-test.sh +3 -3
  165. package/scripts/lib/pr-evidence.sh +1 -1
  166. package/scripts/lib/qa-lane-test.sh +626 -0
  167. package/scripts/lib/qa-lane.sh +1357 -0
  168. package/scripts/lib/qa-lanes-test.sh +175 -0
  169. package/scripts/lib/react-detect.sh +1 -1
  170. package/scripts/lib/render-test.sh +1 -1
  171. package/scripts/lib/review-page-test.sh +318 -0
  172. package/scripts/lib/review-page.sh +369 -0
  173. package/scripts/lib/review-stage-test.sh +62 -11
  174. package/scripts/lib/review-stage.sh +42 -60
  175. package/scripts/lib/role-identity-test.sh +65 -0
  176. package/scripts/lib/role-identity.sh +25 -2
  177. package/scripts/lib/secret-guard.sh +3 -3
  178. package/scripts/lib/session-registry-test.sh +111 -0
  179. package/scripts/lib/session-registry.sh +233 -0
  180. package/scripts/lib/stage-receipt-test.sh +14 -1
  181. package/scripts/lib/stage-receipt.sh +13 -8
  182. package/scripts/lib/task-source-file.sh +309 -0
  183. package/scripts/lib/task-source.sh +130 -0
  184. package/scripts/lib/test-env-test.sh +3 -3
  185. package/scripts/lib/test-env.sh +7 -4
  186. package/scripts/lib/upgrade-report-test.sh +120 -0
  187. package/scripts/lib/upgrade-report.sh +138 -0
  188. package/scripts/lib/version-bump.sh +3 -3
  189. package/scripts/lib/wave-result-test.sh +80 -0
  190. package/scripts/lib/wave-result.sh +127 -0
  191. package/scripts/lib/worker-brief-test.sh +5 -0
  192. package/scripts/lib/worker-brief.sh +2 -2
  193. package/scripts/lib/worktree-issue-test.sh +30 -1
  194. package/scripts/lib/worktree-issue.sh +93 -9
  195. package/scripts/lib/worktree-ports-test.sh +57 -4
  196. package/scripts/lib/worktree-start-test.sh +197 -0
  197. package/scripts/lib/worktree-start.sh +169 -32
  198. package/scripts/lib/zsh-safety-test.sh +19 -3
  199. package/scripts/marketing-walkthrough-test.sh +152 -0
  200. package/scripts/night-grant-test.sh +37 -0
  201. package/scripts/night-grant.sh +448 -0
  202. package/scripts/night-run-test.sh +8 -0
  203. package/scripts/night-run.mjs +275 -0
  204. package/scripts/night-run.test.mjs +324 -0
  205. package/scripts/orchestrate-test.sh +190 -0
  206. package/scripts/orchestrate.sh +79 -8
  207. package/scripts/portable-test.sh +11 -2
  208. package/scripts/publish.sh +28 -3
  209. package/scripts/review-lint-test.sh +7 -7
  210. package/scripts/review-lint.sh +2 -2
  211. package/scripts/review-rules.conf +8 -0
  212. package/scripts/rule-recipes-test.sh +96 -0
  213. package/scripts/self-install-test.sh +39 -9
  214. package/scripts/setup-labels.sh +18 -1
  215. package/scripts/setup-milestones.sh +1 -1
  216. package/scripts/showcase.sh +1 -1
  217. package/scripts/skill-frontmatter-lint-test.sh +4 -4
  218. package/scripts/skill-frontmatter-lint.sh +1 -1
  219. package/scripts/status-test.sh +113 -2
  220. package/scripts/status.sh +16 -3
  221. package/scripts/task-sync-test.sh +154 -0
  222. package/scripts/task-sync.sh +243 -32
  223. package/scripts/test-runner-test.sh +158 -0
  224. package/scripts/test.sh +131 -23
  225. package/scripts/update-path-test.sh +279 -0
  226. package/scripts/ux-ds-audit.sh +1 -1
  227. package/scripts/ux-graph-scan.sh +6 -6
  228. package/scripts/wave-worker.sh +54 -0
  229. package/skills/kit-add/SKILL.md +77 -0
  230. package/skills/kit-autopilot/SKILL.md +123 -12
  231. package/skills/kit-cleanup/SKILL.md +5 -2
  232. package/skills/kit-contribute/SKILL.md +4 -4
  233. package/skills/kit-docs-writer/SKILL.md +16 -6
  234. package/skills/kit-effort-close/SKILL.md +17 -8
  235. package/skills/kit-effort-new/SKILL.md +15 -9
  236. package/skills/kit-effort-pr/SKILL.md +15 -7
  237. package/skills/kit-effort-start/SKILL.md +5 -2
  238. package/skills/kit-gc/SKILL.md +5 -2
  239. package/skills/kit-next/SKILL.md +5 -1
  240. package/skills/kit-onboard/SKILL.md +3 -3
  241. package/skills/kit-page/SKILL.md +93 -0
  242. package/skills/kit-plan-next/SKILL.md +8 -4
  243. package/skills/kit-security-sweep/SKILL.md +1 -3
  244. package/skills/kit-ship/SKILL.md +2 -3
  245. package/skills/kit-status/SKILL.md +35 -4
  246. package/skills/kit-task-new/SKILL.md +3 -3
  247. package/skills/kit-task-pr/SKILL.md +7 -2
  248. package/skills/kit-task-pr-merge/SKILL.md +7 -2
  249. package/skills/kit-task-start/SKILL.md +7 -7
  250. package/skills/kit-task-sync/SKILL.md +19 -3
  251. package/skills/kit-ux-audit/SKILL.md +3 -2
  252. package/templates/agents/auto-dev.md +5 -4
  253. package/templates/agents/backend.md +1 -1
  254. package/templates/agents/designer.md +2 -0
  255. package/templates/agents/devops.md +1 -1
  256. package/templates/agents/editor.md +9 -1
  257. package/templates/agents/frontend.md +1 -1
  258. package/templates/agents/local-delegate.md +1 -1
  259. package/templates/agents/pm.md +5 -5
  260. package/templates/agents/tech-lead.md +1 -1
  261. package/templates/benchmarks/SCHEMA.md +9 -3
  262. package/templates/codex/hooks.json.tmpl +89 -0
  263. package/templates/hooks/guard-base-branch-commit.sh.tmpl +13 -7
  264. package/templates/hooks/guard-raw-git-ops.sh.tmpl +27 -14
  265. package/templates/hooks/mempal_followup.sh.tmpl +2 -2
  266. package/templates/hooks/mempal_session_start.sh.tmpl +1 -1
  267. package/templates/hooks/prepush_gate.sh.tmpl +4 -2
  268. package/templates/hooks/repo-hygiene.sh.tmpl +3 -2
  269. package/templates/instructions.md.tmpl +174 -0
  270. package/templates/kit.config.json.tmpl +3 -3
  271. package/templates/knowledge-INDEX.md.tmpl +1 -1
  272. package/templates/lib/kit-sigil.sh.tmpl +1 -1
  273. package/templates/rules/authoring.md +106 -0
  274. package/templates/rules/branch-naming.md +40 -4
  275. package/templates/rules/code-retrieval.md +63 -0
  276. package/templates/rules/delegation-brief.md +0 -3
  277. package/templates/rules/design-routing.md +3 -3
  278. package/templates/rules/effort-model.md +14 -10
  279. package/templates/rules/gate-and-review.md +94 -0
  280. package/templates/rules/issue-lifecycle.md +88 -0
  281. package/templates/rules/knowledge-base.md +1 -1
  282. package/templates/rules/mempalace.md +1 -1
  283. package/templates/rules/merge-safety.md +108 -0
  284. package/templates/rules/naming-and-ids.md +23 -17
  285. package/templates/rules/plain-language.md +59 -0
  286. package/templates/rules/plan-next.md +9 -11
  287. package/templates/rules/react-annotate.md +6 -0
  288. package/templates/rules/review-pages.md +49 -0
  289. package/templates/rules/risk-tiered-review.md +13 -4
  290. package/templates/rules/shared-checkout.md +106 -0
  291. package/templates/rules/skill-gaps.md +2 -7
  292. package/templates/rules/task-management.md +13 -1
  293. package/templates/skills/brand-voice/SKILL.md +91 -0
  294. package/templates/skills/brand-voice/references/voice-template.md +61 -0
  295. package/templates/skills/campaign/SKILL.md +123 -0
  296. package/templates/skills/campaign/references/plan-template.md +55 -0
  297. package/templates/skills/concrete/SKILL.md +2 -2
  298. package/templates/skills/copywriting/SKILL.md +8 -1
  299. package/templates/skills/feature-build-refine/SKILL.md +2 -4
  300. package/templates/skills/morning-briefing/SKILL.md +2 -2
  301. package/templates/skills/page-design/SKILL.md +145 -0
  302. package/templates/skills/page-design/add.json +5 -0
  303. package/templates/skills/page-design/references/design-file-template.md +40 -0
  304. package/templates/skills/page-design/references/generic-page-patterns.md +43 -0
  305. package/templates/skills/page-design/references/minimum-rules.md +42 -0
  306. package/templates/skills/speckit/SKILL.md +4 -5
  307. package/templates/skills/supabase-patterns/SKILL.md +1 -1
  308. package/commands/kit-add.md +0 -42
  309. package/templates/CLAUDE.md.tmpl +0 -106
@@ -0,0 +1,106 @@
1
+ #!/usr/bin/env bash
2
+ # shellcheck shell=bash
3
+ # agent-def.sh — read a specialist role template and translate it per runtime (E257.6, #263).
4
+ #
5
+ # A role lives ONCE, in templates/agents/<role>.md: YAML frontmatter (name, description, tools,
6
+ # skills) over a markdown body of responsibilities. Claude Code reads that file as-is, installed at
7
+ # .claude/agents/<role>/AGENT.md. Codex reads a custom agent as TOML at .codex/agents/<role>.toml
8
+ # with three required keys — name, description, developer_instructions. This file is the one
9
+ # translation, so the two definitions cannot drift apart: both come from the same rendered role.
10
+ #
11
+ # What does NOT translate, and is written into the TOML as a comment rather than dropped silently:
12
+ # tools: a Claude Code tool allowlist. Codex has no per-agent tool list; its sandbox and
13
+ # approval policy govern the agent instead.
14
+ # model: a Claude model alias. cckit never names a model for another runtime.
15
+ #
16
+ # agent_def_field <file> <key> one frontmatter scalar (empty when absent)
17
+ # agent_def_skills <file> the skills: list, one name per line (inline or block form)
18
+ # agent_def_body <file> the markdown after the frontmatter
19
+ # agent_def_codex_name <role> the Codex agent name for a role (tech-lead -> tech_lead)
20
+ # agent_def_codex <file> stdout: the Codex TOML for an already-rendered role file
21
+ #
22
+ # bash 3.2 + zsh compatible: awk and sed only, no arrays.
23
+ # errors: strict — agent_def_codex returns 1 when the role has no name or no description, because
24
+ # Codex refuses an agent file missing either and a silent empty value would install a dead agent.
25
+
26
+ agent_def_field() {
27
+ awk -v key="${2:-}" '
28
+ NR == 1 && /^---[[:space:]]*$/ { fm = 1; next }
29
+ fm && /^---[[:space:]]*$/ { exit }
30
+ fm && index($0, key ":") == 1 {
31
+ v = substr($0, length(key) + 2)
32
+ sub(/^[[:space:]]+/, "", v); sub(/[[:space:]]+$/, "", v)
33
+ print v; exit
34
+ }' "${1:-/dev/null}"
35
+ }
36
+
37
+ agent_def_skills() {
38
+ awk '
39
+ NR == 1 && /^---[[:space:]]*$/ { fm = 1; next }
40
+ fm && /^---[[:space:]]*$/ { exit }
41
+ !fm { next }
42
+ /^skills:/ {
43
+ inlist = 1
44
+ v = $0; sub(/^skills:[[:space:]]*/, "", v)
45
+ if (v ~ /^\[/) {
46
+ gsub(/[][]/, "", v)
47
+ n = split(v, parts, ",")
48
+ for (i = 1; i <= n; i++) { p = parts[i]; gsub(/^[[:space:]]+|[[:space:]]+$/, "", p); if (p != "") print p }
49
+ inlist = 0
50
+ }
51
+ next
52
+ }
53
+ inlist && /^[[:space:]]+-[[:space:]]/ {
54
+ v = $0; sub(/^[[:space:]]+-[[:space:]]+/, "", v); sub(/[[:space:]]+#.*$/, "", v)
55
+ gsub(/^[[:space:]]+|[[:space:]]+$/, "", v); gsub(/^["\047]|["\047]$/, "", v)
56
+ if (v != "") print v
57
+ next
58
+ }
59
+ inlist && /^[^[:space:]]/ { inlist = 0 }' "${1:-/dev/null}"
60
+ }
61
+
62
+ agent_def_body() {
63
+ awk '
64
+ NR == 1 && /^---[[:space:]]*$/ { fm = 1; next }
65
+ fm == 1 && /^---[[:space:]]*$/ { fm = 2; next }
66
+ fm == 1 { next }
67
+ !started && /^[[:space:]]*$/ { next }
68
+ { started = 1; print }' "${1:-/dev/null}"
69
+ }
70
+
71
+ agent_def_codex_name() { printf '%s\n' "${1:-}" | tr '-' '_'; }
72
+
73
+ # TOML basic-string escaping: a backslash and a double quote are the only two characters that can
74
+ # end or corrupt a basic string, single- or multi-line. Escaping every quote (not just runs of
75
+ # three) keeps one rule for both string forms.
76
+ _agent_def_toml_escape() { sed 's/\\/\\\\/g; s/"/\\"/g'; }
77
+
78
+ agent_def_codex() {
79
+ local f="${1:-}" name desc when tools model skills
80
+ [ -f "$f" ] || { echo "agent-def: no such role file: $f" >&2; return 1; }
81
+ name="$(agent_def_field "$f" name)"
82
+ desc="$(agent_def_field "$f" description)"
83
+ when="$(agent_def_field "$f" when_to_use)"
84
+ tools="$(agent_def_field "$f" tools)"
85
+ model="$(agent_def_field "$f" model)"
86
+ skills="$(agent_def_skills "$f")"
87
+ [ -n "$name" ] || { echo "agent-def: $f has no name: in its frontmatter" >&2; return 1; }
88
+ [ -n "$desc" ] || { echo "agent-def: $f has no description: in its frontmatter" >&2; return 1; }
89
+ [ -z "$when" ] || desc="$desc $when"
90
+
91
+ printf '# Codex custom agent for the %s role. cckit init renders it from templates/agents/%s.md,\n' "$name" "$name"
92
+ printf '# the same role source the Claude Code adapter installs as AGENT.md.\n'
93
+ [ -z "$tools" ] || printf '# Not translated — Claude Code tool allowlist: %s\n' "$tools"
94
+ [ -z "$model" ] || printf '# Not translated — Claude model alias: %s\n' "$model"
95
+ printf 'name = "%s"\n' "$(agent_def_codex_name "$name" | _agent_def_toml_escape)"
96
+ printf 'description = "%s"\n' "$(printf '%s' "$desc" | _agent_def_toml_escape)"
97
+ printf 'developer_instructions = """\n'
98
+ agent_def_body "$f" | _agent_def_toml_escape
99
+ if [ -n "$skills" ]; then
100
+ printf '\n## Skills this role names\n\n'
101
+ printf 'Codex loads a skill only when it is installed (the project .agents/skills/ or your Codex\n'
102
+ printf 'home). A kit-* name is a Claude Code plugin skill: in Codex, run the cckit verb it wraps.\n\n'
103
+ printf '%s\n' "$skills" | sed 's/^/- /' | _agent_def_toml_escape
104
+ fi
105
+ printf '"""\n'
106
+ }
@@ -0,0 +1,212 @@
1
+ #!/usr/bin/env bash
2
+ # agent-launch-test.sh — the shared headless launcher (E257.7, #264).
3
+ #
4
+ # Hermetic: no agent, no network. The commands al_run bounds are plain shell, and the usage parser
5
+ # reads fixture output written here in the shapes each runtime documents.
6
+ # Run: bash scripts/lib/agent-launch-test.sh
7
+ # errors: strict — a test runner: rc 1 on any failed assertion
8
+ # shellcheck shell=bash
9
+ set -u
10
+ ROOT="$(cd "$(dirname "$0")/../.." && pwd)"
11
+ tmp="$(mktemp -d)"; trap 'rm -rf "$tmp"' EXIT
12
+ # shellcheck source=/dev/null
13
+ source "$ROOT/scripts/lib/agent-launch.sh"
14
+
15
+ fail=0
16
+ t() { if [ "$2" = "$3" ]; then echo "ok: $1"; else echo "FAIL: $1 -> got '[$2]' want '[$3]'"; fail=1; fi; }
17
+ rc() { if [ "$2" = "$3" ]; then echo "ok: $1"; else echo "FAIL: $1 -> rc '[$2]' want '[$3]'"; fail=1; fi; }
18
+
19
+ # ── which kinds have a headless form ─────────────────────────────────────────────────────────────
20
+ al_supported claude; rc "claude is supported" "$?" "0"
21
+ al_supported codex; rc "codex is supported" "$?" "0"
22
+ al_supported /opt/bin/codex; rc "a path to codex is supported" "$?" "0"
23
+ al_supported aider; rc "an unknown kind is not" "$?" "1"
24
+ al_supported ""; rc "an empty kind is not" "$?" "1"
25
+
26
+ # ── the command line ─────────────────────────────────────────────────────────────────────────────
27
+ t "claude text" "$(al_headless_cmd claude text)" "'claude' -p"
28
+ t "claude json" "$(al_headless_cmd claude json)" "'claude' -p --output-format json"
29
+ t "claude events" "$(al_headless_cmd claude events)" "'claude' -p --output-format stream-json --verbose"
30
+ t "codex events is its one JSON mode" "$(al_headless_cmd codex events)" "'codex' exec --json -"
31
+ t "codex text reads stdin" "$(al_headless_cmd codex text)" "'codex' exec -"
32
+ t "codex json reads stdin" "$(al_headless_cmd codex json)" "'codex' exec --json -"
33
+ t "args are quoted and precede codex's stdin marker" \
34
+ "$(al_headless_cmd codex json "$(printf '%s\n' '-s' 'workspace-write' "it's here")")" \
35
+ "'codex' exec --json '-s' 'workspace-write' 'it'\\''s here' -"
36
+ t "claude args follow the mode" \
37
+ "$(al_headless_cmd claude text "$(printf '%s\n' '--permission-mode' 'acceptEdits')")" \
38
+ "'claude' -p '--permission-mode' 'acceptEdits'"
39
+ al_headless_cmd aider text >/dev/null 2>&1; rc "an unsupported kind is rc 2" "$?" "2"
40
+ t "an unsupported kind prints no command" "$(al_headless_cmd aider text 2>/dev/null)" ""
41
+
42
+ # The built line really runs: a stub named codex receives the argv and the prompt on stdin.
43
+ mkdir -p "$tmp/bin"
44
+ cat > "$tmp/bin/codex" <<'STUB'
45
+ #!/usr/bin/env bash
46
+ printf 'argv:%s|' "$*"; cat
47
+ STUB
48
+ chmod +x "$tmp/bin/codex"
49
+ got="$(printf 'the prompt' | PATH="$tmp/bin:$PATH" al_run 10 "$(al_headless_cmd codex text "$(printf '%s\n' 'a b')")")"
50
+ t "the stub gets the argv and the prompt on stdin" "$got" "argv:exec a b -|the prompt"
51
+
52
+ # ── the bound ────────────────────────────────────────────────────────────────────────────────────
53
+ t "a command inside its bound returns its output" "$(printf '' | al_run 10 'echo alive')" "alive"
54
+ t "stdin reaches the command" "$(printf 'piped' | al_run 10 'cat')" "piped"
55
+ printf '' | al_run 10 'exit 7' >/dev/null 2>&1
56
+ rc "a command's own exit code survives" "$?" "7"
57
+ t "AL_PID is cleared after a run" "$AL_PID" ""
58
+
59
+ start=$(date +%s)
60
+ printf 'ignored\n' | al_run 1 'sleep 60' >/dev/null 2>&1
61
+ rc "a command past its bound is rc 124" "$?" "124"
62
+ elapsed=$(( $(date +%s) - start ))
63
+ [ "$elapsed" -lt 20 ] && echo "ok: it was killed in ${elapsed}s, not left running" \
64
+ || { echo "FAIL: still ran ${elapsed}s after a 1s bound"; fail=1; }
65
+
66
+ # TERM is ignored -> KILL lands. The marker file proves the command was running when the bound hit.
67
+ start=$(date +%s)
68
+ al_run 1 "trap '' TERM; echo up > '$tmp/stubborn'; while :; do sleep 1; done" </dev/null >/dev/null 2>&1
69
+ rc "a command that ignores TERM is still rc 124" "$?" "124"
70
+ t "it had started" "$(cat "$tmp/stubborn" 2>/dev/null)" "up"
71
+ elapsed=$(( $(date +%s) - start ))
72
+ [ "$elapsed" -lt 40 ] && echo "ok: KILL followed TERM (${elapsed}s)" \
73
+ || { echo "FAIL: a TERM-ignoring command ran ${elapsed}s"; fail=1; }
74
+
75
+ # A grandchild does not outlive the bound when perl gives the command its own process group.
76
+ if command -v perl >/dev/null 2>&1; then
77
+ al_run 1 "(sleep 300 & echo \$! > '$tmp/grandchild'; wait)" </dev/null >/dev/null 2>&1
78
+ gpid="$(cat "$tmp/grandchild" 2>/dev/null)"
79
+ sleep 1
80
+ if [ -n "$gpid" ] && kill -0 "$gpid" 2>/dev/null; then
81
+ echo "FAIL: grandchild $gpid survived the bound"; kill -KILL "$gpid" 2>/dev/null; fail=1
82
+ else echo "ok: the grandchild died with the bound"; fi
83
+ else
84
+ echo "skip: perl absent — process-group kill not exercised"
85
+ fi
86
+
87
+ # ── the pid file, and a caller that dies without running a trap ──────────────────────────────────
88
+ # AL_PIDFILE exists while a command runs and is gone once it is reaped.
89
+ AL_PIDFILE="$tmp/run.pid"
90
+ al_run 10 "cat '$tmp/run.pid' > '$tmp/seen.pid'" </dev/null >/dev/null 2>&1
91
+ t "the pid file is there while the command runs" "$([ -s "$tmp/seen.pid" ] && echo yes || echo no)" "yes"
92
+ t "and removed once it is reaped" "$([ -e "$tmp/run.pid" ] && echo left || echo gone)" "gone"
93
+ al_run 1 'sleep 60' </dev/null >/dev/null 2>&1
94
+ t "a command killed at its bound leaves no pid file" "$([ -e "$tmp/run.pid" ] && echo left || echo gone)" "gone"
95
+ AL_PIDFILE=""
96
+
97
+ sleep 60 & live=$!
98
+ printf '%s 0\n' "$live" > "$tmp/live.pid"
99
+ al_pidfile_alive "$tmp/live.pid"; rc "a recorded live pid reads alive" "$?" "0"
100
+ kill "$live" 2>/dev/null; wait "$live" 2>/dev/null
101
+ al_pidfile_alive "$tmp/live.pid"; rc "a recorded dead pid does not" "$?" "1"
102
+ al_pidfile_alive "$tmp/absent.pid"; rc "a missing pid file does not" "$?" "1"
103
+ # A zombie answers `kill -0` and is not running. The subshell execs sleep without ever waiting for
104
+ # the child it started, so that child stays a zombie until the sleep ends.
105
+ if ps -A -o pid=,pgid=,stat= >/dev/null 2>&1; then
106
+ ( sh -c "echo \$\$ > '$tmp/zombie.raw'" & exec sleep 20 ) & holder=$!
107
+ i=0; while [ ! -s "$tmp/zombie.raw" ] && [ "$i" -lt 50 ]; do sleep 0.2; i=$((i + 1)); done
108
+ sleep 0.5
109
+ zpid="$(cat "$tmp/zombie.raw" 2>/dev/null)"
110
+ printf '%s 0\n' "$zpid" > "$tmp/zombie.pid"
111
+ if kill -0 "$zpid" 2>/dev/null; then
112
+ al_pidfile_alive "$tmp/zombie.pid"; rc "a recorded zombie does not read alive" "$?" "1"
113
+ else
114
+ echo "skip: no zombie to probe (pid $zpid was already reaped)"
115
+ fi
116
+ kill "$holder" 2>/dev/null; wait "$holder" 2>/dev/null
117
+ else
118
+ echo "skip: ps absent — zombie state not exercised"
119
+ fi
120
+ printf 'junk\n' > "$tmp/junk.pid"
121
+ al_pidfile_alive "$tmp/junk.pid"; rc "a pid file that holds no pid does not" "$?" "1"
122
+
123
+ # The shell that called al_run is killed with SIGKILL: no trap runs, nothing calls al_stop. The
124
+ # watchdog notices its parent is gone and stops the command's group.
125
+ if command -v perl >/dev/null 2>&1; then
126
+ cat > "$tmp/caller.sh" <<CALLER
127
+ . "$ROOT/scripts/lib/agent-launch.sh"
128
+ al_run 300 "echo \\\$\\\$ > '$tmp/orphan.pid'; exec sleep 300" </dev/null >/dev/null 2>&1
129
+ CALLER
130
+ bash "$tmp/caller.sh" & caller=$!
131
+ i=0; while [ ! -s "$tmp/orphan.pid" ] && [ "$i" -lt 50 ]; do sleep 0.2; i=$((i + 1)); done
132
+ opid="$(cat "$tmp/orphan.pid" 2>/dev/null)"
133
+ t "the command started under the caller" "$([ -n "$opid" ] && kill -0 "$opid" 2>/dev/null && echo alive || echo gone)" "alive"
134
+ kill -KILL "$caller"; wait "$caller" 2>/dev/null
135
+ i=0; while [ -n "$opid" ] && kill -0 "$opid" 2>/dev/null && [ "$i" -lt 100 ]; do sleep 0.2; i=$((i + 1)); done
136
+ if [ -n "$opid" ] && kill -0 "$opid" 2>/dev/null; then
137
+ echo "FAIL: command $opid outlived its SIGKILLed caller"; kill -KILL "$opid" 2>/dev/null; fail=1
138
+ else echo "ok: the command does not outlive a SIGKILLed caller"; fi
139
+ else
140
+ echo "skip: perl absent — the watchdog is not exercised"
141
+ fi
142
+
143
+ # ── usage, from the runtime's own output ─────────────────────────────────────────────────────────
144
+ cat > "$tmp/claude.json" <<'JSON'
145
+ {"type":"result","subtype":"success","is_error":false,"result":"done","total_cost_usd":0.0421,"usage":{"input_tokens":120,"cache_creation_input_tokens":30,"cache_read_input_tokens":50,"output_tokens":75}}
146
+ JSON
147
+ t "claude: input includes cache tokens, cost is the runtime's own" \
148
+ "$(al_usage claude "$tmp/claude.json")" "200 75 0.0421"
149
+
150
+ # The same result as the last element of an event array.
151
+ printf '%s\n' '[{"type":"system"},{"type":"result","usage":{"input_tokens":5,"output_tokens":6}}]' > "$tmp/claude-arr.json"
152
+ t "claude: a result inside an array, no cost printed" "$(al_usage claude "$tmp/claude-arr.json")" "5 6 unknown"
153
+
154
+ cat > "$tmp/codex.jsonl" <<'JSONL'
155
+ {"type":"thread.started","thread_id":"t"}
156
+ not json at all
157
+ {"type":"turn.completed","usage":{"input_tokens":1000,"cached_input_tokens":400,"output_tokens":200}}
158
+ {"type":"turn.completed","usage":{"input_tokens":500,"cached_input_tokens":0,"output_tokens":50}}
159
+ JSONL
160
+ t "codex: turns are summed, a non-JSON line is skipped, cost is unknown" \
161
+ "$(al_usage codex "$tmp/codex.jsonl")" "1500 250 unknown"
162
+
163
+ printf 'plain text reply\n' > "$tmp/plain.txt"
164
+ t "claude: text output has no usage" "$(al_usage claude "$tmp/plain.txt")" "unknown unknown unknown"
165
+ t "codex: text output has no usage" "$(al_usage codex "$tmp/plain.txt")" "unknown unknown unknown"
166
+ t "codex output read as claude is unknown, not a wrong number" \
167
+ "$(al_usage claude "$tmp/codex.jsonl")" "unknown unknown unknown"
168
+ t "a missing file is unknown" "$(al_usage codex "$tmp/absent")" "unknown unknown unknown"
169
+ t "an unsupported kind is unknown" "$(al_usage aider "$tmp/claude.json")" "unknown unknown unknown"
170
+ : > "$tmp/empty"
171
+ t "an empty file is unknown" "$(al_usage claude "$tmp/empty")" "unknown unknown unknown"
172
+
173
+ # ── skills, from the runtime's own event output (#504) ───────────────────────────────────────────
174
+ # Four calls: a Skill call that returned, a Skill call the runtime answered with an error (a skill
175
+ # that is not installed), a Read of a SKILL.md, and a Skill call with no result at all. The last
176
+ # assistant line is the agent CLAIMING a skill in prose.
177
+ cat > "$tmp/claude-events.jsonl" <<'JSONL'
178
+ {"type":"system","subtype":"init","skills":["page-design","impeccable","web-design-guidelines"]}
179
+ {"type":"assistant","message":{"role":"assistant","content":[{"type":"tool_use","id":"t1","name":"Skill","input":{"skill":"page-design"}}]}}
180
+ {"type":"user","message":{"role":"user","content":[{"type":"tool_result","tool_use_id":"t1","content":"ok"}]}}
181
+ {"type":"assistant","message":{"role":"assistant","content":[{"type":"tool_use","id":"t2","name":"Skill","input":{"skill":"impeccable"}},{"type":"tool_use","id":"t3","name":"Read","input":{"file_path":"/w/.claude/skills/emil-design-eng/SKILL.md"}},{"type":"tool_use","id":"t4","name":"Read","input":{"file_path":"/w/app/page.tsx"}}]}}
182
+ {"type":"user","message":{"role":"user","content":[{"type":"tool_result","tool_use_id":"t2","is_error":true,"content":"Unknown skill: impeccable"},{"type":"tool_result","tool_use_id":"t3","content":"…"},{"type":"tool_result","tool_use_id":"t4","content":"…"}]}}
183
+ {"type":"assistant","message":{"role":"assistant","content":[{"type":"tool_use","id":"t5","name":"Skill","input":{"skill":"web-design-guidelines"}}]}}
184
+ not json at all
185
+ {"type":"assistant","message":{"role":"assistant","content":[{"type":"text","text":"I applied impeccable and web-design-guidelines."}]}}
186
+ {"type":"result","total_cost_usd":0.02,"usage":{"input_tokens":10,"output_tokens":4}}
187
+ JSONL
188
+ t "claude: only calls that returned without an error are loaded skills" \
189
+ "$(al_skills claude "$tmp/claude-events.jsonl" | tr '\n' ' ')" "emil-design-eng page-design "
190
+ al_skills claude "$tmp/claude-events.jsonl" >/dev/null; rc "claude: an event stream is a reading" "$?" "0"
191
+ t "claude: usage is read from the same event stream" "$(al_usage claude "$tmp/claude-events.jsonl")" "10 4 0.02"
192
+ printf '%s\n' '{"type":"system","subtype":"init"}' '{"type":"result","usage":{"input_tokens":1,"output_tokens":1}}' > "$tmp/claude-noskill.jsonl"
193
+ t "claude: events with no skill call list nothing" "$(al_skills claude "$tmp/claude-noskill.jsonl")" ""
194
+ al_skills claude "$tmp/claude-noskill.jsonl" >/dev/null; rc "claude: and that is still a reading" "$?" "0"
195
+ al_skills claude "$tmp/claude.json" >/dev/null; rc "claude: a lone result object cannot tell" "$?" "1"
196
+ al_skills claude "$tmp/plain.txt" >/dev/null; rc "claude: text output cannot tell" "$?" "1"
197
+ al_skills claude "$tmp/empty" >/dev/null; rc "an empty file cannot tell" "$?" "1"
198
+ al_skills claude "$tmp/absent" >/dev/null; rc "a missing file cannot tell" "$?" "1"
199
+ al_skills aider "$tmp/claude-events.jsonl" >/dev/null; rc "an unsupported kind cannot tell" "$?" "1"
200
+ cat > "$tmp/codex-events.jsonl" <<'JSONL'
201
+ {"type":"thread.started","thread_id":"t"}
202
+ {"type":"item.completed","item":{"id":"i1","type":"command_execution","command":"bash -lc 'cat .agents/skills/page-design/SKILL.md'","exit_code":0}}
203
+ {"type":"item.completed","item":{"id":"i2","type":"command_execution","command":"cat .agents/skills/impeccable/SKILL.md","exit_code":1}}
204
+ {"type":"item.completed","item":{"id":"i3","type":"agent_message","text":"I read skills/emil-design-eng/SKILL.md"}}
205
+ {"type":"turn.completed","usage":{"input_tokens":5,"output_tokens":6}}
206
+ JSONL
207
+ t "codex: a skill file read by a command that exited 0" "$(al_skills codex "$tmp/codex-events.jsonl" | tr '\n' ' ')" "page-design "
208
+ al_skills codex "$tmp/codex.jsonl" >/dev/null; rc "codex: events with no skill read are a reading" "$?" "0"
209
+ al_skills codex "$tmp/plain.txt" >/dev/null; rc "codex: text output cannot tell" "$?" "1"
210
+
211
+ [ "$fail" -eq 0 ] && echo "ALL OK (agent-launch)" || echo "agent-launch: FAILURES"
212
+ exit "$fail"