@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,338 @@
1
+ #!/usr/bin/env bash
2
+ # autopilot-run-test.sh — scenario A07 as a fixture: a bounded headless objective, under both
3
+ # launch kinds, stopped by a failing check, a no-progress round, a kill mid-run (TERM and KILL) and
4
+ # each configured limit, then resumed without a second PR or a second agent (E257.7, #264).
5
+ #
6
+ # Hermetic. `claude` and `codex` are stub scripts on PATH whose behaviour STUB_MODE selects, `gh` is
7
+ # a stub that records every `pr create`, and origin is a bare repo in the temp dir. This proves what
8
+ # cckit's code decides around an agent process; it does not prove either real agent behaves.
9
+ # errors: strict — a test runner: rc 1 on any failed assertion
10
+ # shellcheck shell=bash
11
+ set -u
12
+ ROOT="$(cd "$(dirname "$0")/.." && pwd)"
13
+ command -v jq >/dev/null 2>&1 || { echo "autopilot-run-test: jq absent — skipping"; exit 0; }
14
+ # shellcheck source=/dev/null
15
+ . "$ROOT/scripts/lib/agent-launch.sh"
16
+
17
+ TMP="$(mktemp -d)"; trap 'rm -rf "$TMP"' EXIT
18
+ fail=0
19
+ t() { if [ "$2" = "$3" ]; then echo "ok: $1"; else echo "FAIL: $1 -> got '[$2]' want '[$3]'"; fail=1; fi; }
20
+ has() { case "$2" in *"$3"*) echo "ok: $1" ;; *) echo "FAIL: $1 -> '[$2]' lacks '$3'"; fail=1 ;; esac; }
21
+
22
+ # ── fixture: a project on a task branch, with a bare origin ──────────────────────────────────────
23
+ mkdir -p "$TMP/bin" "$TMP/project"
24
+ git init -q --bare "$TMP/origin.git"
25
+ P="$TMP/project"
26
+ git -C "$P" init -q
27
+ git -C "$P" config user.email t@example.invalid
28
+ git -C "$P" config user.name tester
29
+ git -C "$P" config commit.gpgsign false
30
+ printf '%s\n' '{"project":{"name":"fx","slug":"fx"},"github":{"repo":"fixture/project","owner":"fixture","baseBranch":"develop","projectsV2":false}}' > "$P/cckit.config.json"
31
+ echo seed > "$P/work.txt"
32
+ git -C "$P" add -A && git -C "$P" commit -q -m seed
33
+ git -C "$P" branch -M develop
34
+ git -C "$P" remote add origin "$TMP/origin.git"
35
+ git -C "$P" push -q origin develop
36
+ git -C "$P" checkout -q -b task/7-thing
37
+
38
+ export KIT_CONFIG="$P/cckit.config.json"
39
+ export KIT_STATE_DIR="$TMP/state"
40
+ export FX="$TMP"
41
+ unset KIT_BASE_BRANCH CCKIT_AGENT CCKIT_OUTPUT 2>/dev/null || true
42
+ STATE="$TMP/state/autopilot/task_7-thing.json"
43
+
44
+ # The agent stub. One file, installed under both names; it reads the prompt like the real CLIs do
45
+ # and prints usage in the shape its name documents.
46
+ cat > "$TMP/bin/agent-stub" <<'STUB'
47
+ #!/usr/bin/env bash
48
+ me="$(basename "$0")"; argv="$*"
49
+ printf '%s\n' "$*" > "$FX/$me.argv"
50
+ cat > "$FX/$me.prompt"
51
+ n="$(cat "$FX/rounds" 2>/dev/null || echo 0)"; n=$((n + 1)); echo "$n" > "$FX/rounds"
52
+ usage() {
53
+ # Event output, when cckit asked claude for it: one Skill call that returned (STUB_SKILL).
54
+ case "$me:$argv" in claude:*stream-json*)
55
+ printf '{"type":"system","subtype":"init"}\n'
56
+ if [ -n "${STUB_SKILL:-}" ]; then
57
+ printf '{"type":"assistant","message":{"content":[{"type":"tool_use","id":"s%s","name":"Skill","input":{"skill":"%s"}}]}}\n' "$n" "$STUB_SKILL"
58
+ printf '{"type":"user","message":{"content":[{"type":"tool_result","tool_use_id":"s%s","content":"ok"}]}}\n' "$n"
59
+ fi ;;
60
+ esac
61
+ case "$me" in
62
+ claude) printf '{"type":"result","total_cost_usd":0.01,"usage":{"input_tokens":100,"output_tokens":50}}\n' ;;
63
+ codex) printf '{"type":"turn.completed","usage":{"input_tokens":100,"output_tokens":50}}\n' ;;
64
+ esac
65
+ }
66
+ work() { echo "round $n" >> work.txt; git add -A >/dev/null 2>&1; git commit -q -m "round $n"; }
67
+ case "${STUB_MODE:-work}" in
68
+ work) work; [ "$n" -ge "${STUB_DONE_AT:-1}" ] && touch "$FX/done.flag"; usage ;;
69
+ idle) usage ;;
70
+ nousage) work; echo "plain text, no usage" ;;
71
+ fail) echo "boom" >&2; exit 9 ;;
72
+ hang) echo "$$" > "$FX/agent.pid"; sleep 300 ;;
73
+ esac
74
+ STUB
75
+ chmod +x "$TMP/bin/agent-stub"
76
+ cp "$TMP/bin/agent-stub" "$TMP/bin/claude"; cp "$TMP/bin/agent-stub" "$TMP/bin/codex"
77
+
78
+ cat > "$TMP/bin/gh" <<'STUB'
79
+ #!/usr/bin/env bash
80
+ case "$1 $2" in
81
+ 'pr list') [ -f "$FX/pr.url" ] && cat "$FX/pr.url"; exit 0 ;;
82
+ 'pr create') echo "create $*" >> "$FX/gh.log"
83
+ echo "https://github.com/fixture/project/pull/41" | tee "$FX/pr.url" ;;
84
+ 'issue view') echo '{"title":"thing","labels":[{"name":"kind:task"}],"milestone":null}' ;;
85
+ *) echo "other $*" >> "$FX/gh.log"; exit 0 ;;
86
+ esac
87
+ STUB
88
+ chmod +x "$TMP/bin/gh"
89
+ export PATH="$TMP/bin:$PATH"
90
+
91
+ cd "$P" || exit 1
92
+ run() { bash "$ROOT/scripts/autopilot.sh" run "$@" > "$TMP/out" 2>&1; }
93
+ reason() { jq -r .reason "$STATE" 2>/dev/null; }
94
+ field() { jq -r "$1" "$STATE" 2>/dev/null; }
95
+ creates() { if [ -f "$TMP/gh.log" ]; then grep -c '^create ' "$TMP/gh.log"; else echo 0; fi; }
96
+ reset() { rm -rf "$TMP/state" "$TMP/rounds" "$TMP/done.flag" "$TMP/agent.pid" "$TMP/gh.log" "$TMP/pr.url"; }
97
+ UNTIL="test -f '$TMP/done.flag'"
98
+
99
+ # ── refusals write nothing ───────────────────────────────────────────────────────────────────────
100
+ run --agent aider --objective x; t "an agent with no headless form is refused" "$?" "2"
101
+ has "and says which are supported" "$(cat "$TMP/out")" "supported: claude, codex"
102
+ run; t "no objective is refused" "$?" "2"
103
+ run --objective x --notify me; t "--notify is refused as unsupported" "$?" "2"
104
+ has "and says it is not supported" "$(cat "$TMP/out")" "'--notify' is not supported"
105
+ run --objective x --max-iters 0; t "a zero limit is refused" "$?" "2"
106
+ run --objective x --max-tokens lots; t "a non-numeric token limit is refused" "$?" "2"
107
+ run --objective x --publish; t "--publish without --summary is refused" "$?" "2"
108
+ run --resume; t "--resume with no state is refused" "$?" "2"
109
+ git checkout -q develop
110
+ run --objective x; t "the base branch is refused" "$?" "2"
111
+ git checkout -q task/7-thing
112
+ t "no refusal started an agent" "$([ -f "$TMP/rounds" ] && echo ran || echo no)" "no"
113
+ t "no refusal wrote state" "$([ -d "$TMP/state" ] && echo wrote || echo no)" "no"
114
+
115
+ run --dry-run --agent codex --agent-arg -s --agent-arg workspace-write --objective x --max-tokens 9
116
+ t "--dry-run exits 0" "$?" "0"
117
+ has "--dry-run shows the non-interactive codex line" "$(cat "$TMP/out")" "'codex' exec --json '-s' 'workspace-write' -"
118
+ t "--dry-run wrote no state" "$([ -d "$TMP/state" ] && echo wrote || echo no)" "no"
119
+
120
+ # ── --until that already passes: exit 0, no round, and stderr says nothing was done (#496) ───────
121
+ reset
122
+ bash "$ROOT/scripts/autopilot.sh" run --objective x --until "true" > "$TMP/out" 2> "$TMP/err"
123
+ t "an --until that already passes exits 0" "$?" "0"
124
+ t "reason is done" "$(reason)" "done"
125
+ t "no round ran" "$(field .rounds)" "0"
126
+ t "no agent was started" "$([ -f "$TMP/rounds" ] && echo ran || echo no)" "no"
127
+ has "stderr says no round ran and nothing changed" "$(cat "$TMP/err")" "no round ran and nothing was changed"
128
+ has "stderr names --check as the gate flag" "$(cat "$TMP/err")" 'use --check "<cmd>"'
129
+ # A run that did work before --until passed is not told that.
130
+ reset
131
+ run --objective x --until "$UNTIL"
132
+ case "$(cat "$TMP/out")" in *"no round ran"*) echo "FAIL: a run that worked was told no round ran"; fail=1 ;; *) echo "ok: a run that worked gets no such notice" ;; esac
133
+
134
+ # ── every stop reason, under both launch kinds ───────────────────────────────────────────────────
135
+ for agent in claude codex; do
136
+ # done: the completion check passes after round 2.
137
+ reset
138
+ STUB_DONE_AT=2 run --agent "$agent" --objective "build the thing" --until "$UNTIL" --agent-arg --flag
139
+ t "[$agent] a met --until exits 0" "$?" "0"
140
+ t "[$agent] reason is done" "$(reason)" "done"
141
+ t "[$agent] it took two rounds" "$(field .rounds)" "2"
142
+ t "[$agent] tokens come from the runtime's output" "$(field .usage.tokens)" "300"
143
+ t "[$agent] usage names its source" "$(field .usage.source)" "$agent"
144
+ has "[$agent] the objective reached the agent on stdin" "$(cat "$TMP/$agent.prompt")" "build the thing"
145
+ has "[$agent] round 2 was told why round 1 was not enough" "$(cat "$TMP/$agent.prompt")" "It failed after the previous round"
146
+ t "[$agent] a finished run offers no resume" "$(field .resume)" ""
147
+ case "$agent" in
148
+ claude) t "[claude] argv is print mode + json" "$(cat "$TMP/claude.argv")" "-p --output-format json --flag"
149
+ t "[claude] cost is what claude printed" "$(field .usage.cost_usd)" "0.02" ;;
150
+ codex) t "[codex] argv is exec + json + stdin" "$(cat "$TMP/codex.argv")" "exec --json --flag -"
151
+ t "[codex] cost is unknown, never a Claude price" "$(field .usage.cost_usd)" "unknown" ;;
152
+ esac
153
+
154
+ # failing check: the work is complete, the gate is not green, nothing is published.
155
+ reset
156
+ run --agent "$agent" --objective x --until "$UNTIL" --check "echo gate-red; exit 1" --publish --summary s
157
+ t "[$agent] a failing gate exits 6" "$?" "6"
158
+ t "[$agent] reason is check-failed" "$(reason)" "check-failed"
159
+ t "[$agent] a failing gate opens no PR" "$(creates)" "0"
160
+ has "[$agent] the gate output is kept" "$(cat "$TMP/state/autopilot/task_7-thing.check.out")" "gate-red"
161
+
162
+ # no-progress: the agent exits 0 having changed nothing.
163
+ reset
164
+ STUB_MODE=idle run --agent "$agent" --objective x --until "$UNTIL"
165
+ t "[$agent] a round that changed nothing exits 5" "$?" "5"
166
+ t "[$agent] reason is no-progress" "$(reason)" "no-progress"
167
+ t "[$agent] it stopped after that one round" "$(field .rounds)" "1"
168
+
169
+ # configured limit: rounds.
170
+ reset
171
+ STUB_DONE_AT=99 run --agent "$agent" --objective x --until "$UNTIL" --max-iters 2
172
+ t "[$agent] the round limit exits 4" "$?" "4"
173
+ t "[$agent] reason is limit-iters" "$(reason)" "limit-iters"
174
+ t "[$agent] exactly two rounds ran" "$(cat "$TMP/rounds")" "2"
175
+ has "[$agent] the state names the resume command" "$(field .resume)" "cckit autopilot run --resume"
176
+ # Resuming under the same limit starts no round: the counter carried over.
177
+ STUB_DONE_AT=99 run --resume
178
+ t "[$agent] resume under the same limit stops again" "$(reason)" "limit-iters"
179
+ t "[$agent] and starts no agent" "$(cat "$TMP/rounds")" "2"
180
+ # Raising the limit on resume buys exactly the extra rounds.
181
+ STUB_DONE_AT=3 run --resume --max-iters 3
182
+ t "[$agent] a raised limit lets the run finish" "$(reason)" "done"
183
+ t "[$agent] rounds continue from the count" "$(field .rounds)" "3"
184
+ t "[$agent] tokens accumulate across the resume" "$(field .usage.tokens)" "450"
185
+
186
+ # configured limit: wall clock. The hung agent is killed, not left running.
187
+ reset
188
+ STUB_MODE=hang run --agent "$agent" --objective x --round-seconds 1
189
+ t "[$agent] the time bound exits 4" "$?" "4"
190
+ t "[$agent] reason is limit-seconds" "$(reason)" "limit-seconds"
191
+ apid="$(cat "$TMP/agent.pid" 2>/dev/null)"
192
+ t "[$agent] the hung agent is gone" "$([ -n "$apid" ] && kill -0 "$apid" 2>/dev/null && echo alive || echo gone)" "gone"
193
+
194
+ # configured limit: tokens, checked between rounds from reported usage (150 per round).
195
+ reset
196
+ STUB_DONE_AT=99 run --agent "$agent" --objective x --until "$UNTIL" --max-tokens 200
197
+ t "[$agent] the token ceiling exits 4" "$?" "4"
198
+ t "[$agent] reason is limit-tokens" "$(reason)" "limit-tokens"
199
+ t "[$agent] it stopped once 300 >= 200, after round 2" "$(cat "$TMP/rounds")" "2"
200
+
201
+ # a token ceiling the runtime gives no usage for is treated as reached, not ignored.
202
+ reset
203
+ STUB_MODE=nousage run --agent "$agent" --objective x --until "$UNTIL" --max-tokens 200
204
+ t "[$agent] an uncheckable ceiling exits 4" "$?" "4"
205
+ t "[$agent] reason is usage-unknown" "$(reason)" "usage-unknown"
206
+ t "[$agent] tokens read unknown" "$(field .usage.tokens)" "unknown"
207
+ t "[$agent] cost reads unknown" "$(field .usage.cost_usd)" "unknown"
208
+ t "[$agent] one round ran before it stopped" "$(cat "$TMP/rounds")" "1"
209
+
210
+ # the agent itself fails.
211
+ reset
212
+ STUB_MODE=fail run --agent "$agent" --objective x
213
+ t "[$agent] a failing agent exits 3" "$?" "3"
214
+ t "[$agent] reason is agent-failed" "$(reason)" "agent-failed"
215
+
216
+ # kill mid-run, then resume: one PR, and none on a second resume.
217
+ reset
218
+ STUB_MODE=hang bash "$ROOT/scripts/autopilot.sh" run --agent "$agent" --objective x --until "$UNTIL" \
219
+ --publish --summary "the thing works" > "$TMP/bg.out" 2>&1 &
220
+ dpid=$!
221
+ i=0; while [ ! -f "$TMP/agent.pid" ] && [ "$i" -lt 100 ]; do sleep 0.2; i=$((i + 1)); done
222
+ apid="$(cat "$TMP/agent.pid" 2>/dev/null)"
223
+ t "[$agent] the state says running while the agent works" "$(field .status)" "running"
224
+ run --agent "$agent" --objective y --fresh
225
+ t "[$agent] a second run on the live branch is refused" "$?" "2"
226
+ kill -TERM "$dpid"; wait "$dpid"
227
+ t "[$agent] a killed run exits 130" "$?" "130"
228
+ t "[$agent] reason is interrupted" "$(reason)" "interrupted"
229
+ t "[$agent] status is stopped" "$(field .status)" "stopped"
230
+ t "[$agent] the agent died with it" "$([ -n "$apid" ] && kill -0 "$apid" 2>/dev/null && echo alive || echo gone)" "gone"
231
+ t "[$agent] no PR from a killed run" "$(creates)" "0"
232
+ # The interrupted round printed no usage, so the total is unknown, not the sum without it.
233
+ t "[$agent] an interrupted round reads tokens unknown" "$(field .usage.tokens)" "unknown"
234
+ t "[$agent] and cost unknown" "$(field .usage.cost_usd)" "unknown"
235
+ t "[$agent] the record leaves no round open" "$(field .round_open)" "false"
236
+ run --objective again
237
+ t "[$agent] a new run over a stopped one is refused" "$?" "2"
238
+ has "[$agent] and points at --resume" "$(cat "$TMP/out")" "--resume"
239
+
240
+ run --resume
241
+ t "[$agent] the resumed run finishes" "$?" "0"
242
+ t "[$agent] reason is done after resume" "$(reason)" "done"
243
+ t "[$agent] the interrupted round counted" "$(field .rounds)" "2"
244
+ t "[$agent] exactly one PR was opened" "$(creates)" "1"
245
+ t "[$agent] the PR is recorded" "$(field .pr_url)" "https://github.com/fixture/project/pull/41"
246
+ run --resume
247
+ t "[$agent] resuming a finished run exits 0" "$?" "0"
248
+ t "[$agent] and opens no second PR" "$(creates)" "1"
249
+
250
+ # A token ceiling cannot be checked across an interrupted round: resuming under one stops with
251
+ # usage-unknown before another round starts, instead of counting the cut-short round as zero.
252
+ reset
253
+ STUB_MODE=hang bash "$ROOT/scripts/autopilot.sh" run --agent "$agent" --objective x --until "$UNTIL" > "$TMP/bg.out" 2>&1 &
254
+ dpid=$!
255
+ i=0; while [ ! -f "$TMP/agent.pid" ] && [ "$i" -lt 100 ]; do sleep 0.2; i=$((i + 1)); done
256
+ kill -TERM "$dpid"; wait "$dpid"
257
+ run --resume --max-tokens 100000
258
+ t "[$agent] resume under --max-tokens after an interrupt exits 4" "$?" "4"
259
+ t "[$agent] reason is usage-unknown, not an undercount" "$(reason)" "usage-unknown"
260
+ t "[$agent] and no further round ran" "$(cat "$TMP/rounds")" "1"
261
+
262
+ # The runner is killed outright (SIGKILL): no trap runs. The agent must not outlive it, the
263
+ # round it left open is counted on resume, and a second resume does not count it twice.
264
+ if command -v perl >/dev/null 2>&1; then
265
+ reset
266
+ STUB_MODE=hang bash "$ROOT/scripts/autopilot.sh" run --agent "$agent" --objective x --until "$UNTIL" > "$TMP/bg.out" 2>&1 &
267
+ dpid=$!
268
+ i=0; while [ ! -f "$TMP/agent.pid" ] && [ "$i" -lt 100 ]; do sleep 0.2; i=$((i + 1)); done
269
+ apid="$(cat "$TMP/agent.pid" 2>/dev/null)"
270
+ t "[$agent] the running agent is recorded beside the state" "$([ -s "$TMP/state/autopilot/task_7-thing.agent.pid" ] && echo yes || echo no)" "yes"
271
+ kill -KILL "$dpid"; wait "$dpid" 2>/dev/null
272
+ i=0; while [ -n "$apid" ] && kill -0 "$apid" 2>/dev/null && [ "$i" -lt 100 ]; do sleep 0.2; i=$((i + 1)); done
273
+ t "[$agent] the agent does not outlive a SIGKILLed runner" "$([ -n "$apid" ] && kill -0 "$apid" 2>/dev/null && echo alive || echo gone)" "gone"
274
+ # The watchdog reaps the agent and then exits; until it has, a start is refused, correctly.
275
+ i=0; while al_pidfile_alive "$TMP/state/autopilot/task_7-thing.agent.pid" && [ "$i" -lt 100 ]; do sleep 0.2; i=$((i + 1)); done
276
+ t "[$agent] nor does the process recorded for it" "$(al_pidfile_alive "$TMP/state/autopilot/task_7-thing.agent.pid" && echo alive || echo gone)" "gone"
277
+ t "[$agent] the dead runner left status running" "$(field .status)" "running"
278
+ t "[$agent] with the round marked open" "$(field .round_open)" "true"
279
+ run --resume --max-tokens 100000
280
+ t "[$agent] resume after SIGKILL under --max-tokens exits 4" "$?" "4"
281
+ t "[$agent] the open round made usage unknown" "$(reason)" "usage-unknown"
282
+ t "[$agent] no second agent was started" "$(cat "$TMP/rounds")" "1"
283
+ t "[$agent] the open round is closed in the record" "$(field .round_open)" "false"
284
+ fi
285
+
286
+ # Without the watchdog (no perl) a SIGKILLed runner can leave its agent alive. The recorded pid
287
+ # is what stops the next start: a live one refuses --resume, --fresh and a new run alike.
288
+ reset
289
+ STUB_MODE=hang bash "$ROOT/scripts/autopilot.sh" run --agent "$agent" --objective x --until "$UNTIL" > "$TMP/bg.out" 2>&1 &
290
+ dpid=$!
291
+ i=0; while [ ! -f "$TMP/agent.pid" ] && [ "$i" -lt 100 ]; do sleep 0.2; i=$((i + 1)); done
292
+ kill -TERM "$dpid"; wait "$dpid"
293
+ sleep 300 & orphan=$!
294
+ jq '.status = "running" | .round_open = true' "$STATE" > "$STATE.t" && mv "$STATE.t" "$STATE"
295
+ printf '%s 0\n' "$orphan" > "$TMP/state/autopilot/task_7-thing.agent.pid"
296
+ before_rounds="$(cat "$TMP/rounds")"
297
+ run --resume
298
+ t "[$agent] --resume is refused while the earlier agent lives" "$?" "2"
299
+ has "[$agent] and names the live agent pid" "$(cat "$TMP/out")" "still alive (pid $orphan)"
300
+ run --agent "$agent" --objective y --fresh
301
+ t "[$agent] --fresh is refused too" "$?" "2"
302
+ t "[$agent] neither refusal started an agent" "$(cat "$TMP/rounds")" "$before_rounds"
303
+ kill "$orphan" 2>/dev/null; wait "$orphan" 2>/dev/null
304
+ STUB_DONE_AT=2 run --resume
305
+ t "[$agent] once that agent is gone the run resumes" "$?" "0"
306
+ t "[$agent] and finishes" "$(reason)" "done"
307
+
308
+ # The state file is lost but the PR exists: a fresh run finds it instead of opening another.
309
+ rm -rf "$TMP/state" "$TMP/rounds" "$TMP/done.flag"
310
+ run --agent "$agent" --objective x --until "$UNTIL" --publish --summary "the thing works"
311
+ t "[$agent] a run with lost state still finishes" "$(reason)" "done"
312
+ t "[$agent] and still opens no second PR" "$(creates)" "1"
313
+ t "[$agent] it records the PR it found" "$(field .pr_url)" "https://github.com/fixture/project/pull/41"
314
+ done
315
+
316
+ # ── --record-skills: the skills each round loaded, from the CLI's events (#504) ─────────────────
317
+ reset
318
+ run --objective x
319
+ t "without --record-skills the state holds no skill list" "$(field '.skills')" "null"
320
+ t "and claude is started in its single-result mode" "$(cat "$TMP/claude.argv")" "-p --output-format json"
321
+ reset
322
+ STUB_SKILL=page-design STUB_DONE_AT=2 run --objective x --until "$UNTIL" --max-iters 1 --record-skills
323
+ t "a limit stop with --record-skills exits 4" "$?" "4"
324
+ t "claude is started with event output" "$(cat "$TMP/claude.argv")" "-p --output-format stream-json --verbose"
325
+ t "round 1's skill is in the state" "$(field '.skills | [.loaded, .complete, .source] | tostring')" '[["page-design"],true,"claude"]'
326
+ t "usage is still counted from the event output" "$(field .usage.tokens)" "150"
327
+ STUB_SKILL=impeccable STUB_DONE_AT=2 run --resume --max-iters 2
328
+ t "the resumed run exits 0" "$?" "0"
329
+ t "a resumed run keeps recording without the flag" "$(cat "$TMP/claude.argv")" "-p --output-format stream-json --verbose"
330
+ t "skills from both rounds are in the state" "$(field '.skills.loaded | tostring')" '["impeccable","page-design"]'
331
+ reset
332
+ STUB_MODE=nousage run --objective x --record-skills
333
+ t "a round whose output holds no event leaves the list incomplete" "$(field '.skills | [.loaded, .complete] | tostring')" '[[],false]'
334
+ run --dry-run --objective x --record-skills
335
+ has "--dry-run shows the event form of the command" "$(cat "$TMP/out")" "'claude' -p --output-format stream-json --verbose"
336
+
337
+ [ "$fail" -eq 0 ] && echo "ALL OK (autopilot-run: A07 fixture, claude + codex)" || echo "autopilot-run: FAILURES"
338
+ exit "$fail"