@jeiemgi/cckit 0.9.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 (305) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/AGENTS.md +169 -21
  3. package/README.md +491 -35
  4. package/SECURITY.md +5 -0
  5. package/bin/cckit +182 -17
  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/hook-adapter-test.sh +193 -0
  59. package/scripts/init-content-test.sh +225 -0
  60. package/scripts/init-guided-test.sh +474 -0
  61. package/scripts/init-recipes-test.sh +104 -0
  62. package/scripts/init-upgrade-test.sh +341 -2
  63. package/scripts/init.sh +746 -95
  64. package/scripts/instruction-budget-baseline.txt +8 -0
  65. package/scripts/instruction-budget-lint-test.sh +166 -0
  66. package/scripts/instruction-budget-lint.sh +219 -0
  67. package/scripts/integrations-check-test.sh +200 -0
  68. package/scripts/integrations-check.sh +157 -0
  69. package/scripts/kit-add-test.sh +214 -0
  70. package/scripts/kit-add.sh +305 -5
  71. package/scripts/kit-adopt-test.sh +16 -0
  72. package/scripts/kit-adopt.sh +3 -2
  73. package/scripts/kit-digest.sh +2 -2
  74. package/scripts/kit-doctor-test.sh +293 -0
  75. package/scripts/kit-doctor.sh +272 -140
  76. package/scripts/kit-export-project-test.sh +3 -3
  77. package/scripts/kit-remove-test.sh +19 -0
  78. package/scripts/kit-routines.sh +2 -2
  79. package/scripts/kit-self-update.sh +1 -1
  80. package/scripts/kit-version-check-test.sh +4 -0
  81. package/scripts/kit-version-check.sh +4 -2
  82. package/scripts/knowledge-lint.sh +4 -4
  83. package/scripts/leak-fence-test.sh +89 -0
  84. package/scripts/lib/adapter-select-test.sh +136 -0
  85. package/scripts/lib/adapter-select.sh +158 -0
  86. package/scripts/lib/agent-def-test.sh +69 -0
  87. package/scripts/lib/agent-def.sh +106 -0
  88. package/scripts/lib/agent-launch-test.sh +212 -0
  89. package/scripts/lib/agent-launch.sh +335 -0
  90. package/scripts/lib/board-view-test.sh +11 -0
  91. package/scripts/lib/board-view.sh +42 -26
  92. package/scripts/lib/branch-owner-test.sh +26 -0
  93. package/scripts/lib/branch-owner.sh +16 -9
  94. package/scripts/lib/captain-test.sh +105 -0
  95. package/scripts/lib/captain.sh +87 -8
  96. package/scripts/lib/codex-hooks-test.sh +100 -0
  97. package/scripts/lib/codex-hooks.sh +69 -0
  98. package/scripts/lib/commitlint.sh +1 -1
  99. package/scripts/lib/content-kinds-gc-test.sh +88 -0
  100. package/scripts/lib/copilot-test.sh +70 -4
  101. package/scripts/lib/copilot.sh +66 -14
  102. package/scripts/lib/effort-dispatch-test.sh +3 -3
  103. package/scripts/lib/effort-metrics-test.sh +178 -1
  104. package/scripts/lib/effort-metrics.sh +175 -35
  105. package/scripts/lib/effort-ops-test.sh +205 -7
  106. package/scripts/lib/effort-ops.sh +198 -43
  107. package/scripts/lib/effort-parity-test.sh +49 -13
  108. package/scripts/lib/effort-plan-test.sh +337 -0
  109. package/scripts/lib/effort-plan.sh +200 -23
  110. package/scripts/lib/effort.sh +56 -11
  111. package/scripts/lib/errors-header-test.sh +1 -1
  112. package/scripts/lib/gh-project-test.sh +35 -1
  113. package/scripts/lib/gh-project.sh +23 -16
  114. package/scripts/lib/gh-rest-test.sh +32 -3
  115. package/scripts/lib/gh-rest.sh +17 -2
  116. package/scripts/lib/hook-refresh.sh +1 -1
  117. package/scripts/lib/init-github.sh +412 -0
  118. package/scripts/lib/init-guide.sh +630 -0
  119. package/scripts/lib/integration-install-test.sh +343 -0
  120. package/scripts/lib/integration-install.sh +257 -0
  121. package/scripts/lib/integrations-test.sh +366 -0
  122. package/scripts/lib/integrations.sh +244 -0
  123. package/scripts/lib/kinds-test.sh +125 -0
  124. package/scripts/lib/kinds.sh +66 -0
  125. package/scripts/lib/kit-brief-test.sh +22 -3
  126. package/scripts/lib/kit-brief.sh +45 -5
  127. package/scripts/lib/kit-config-resolve.sh +2 -2
  128. package/scripts/lib/kit-config-test.sh +64 -1
  129. package/scripts/lib/kit-config.sh +37 -1
  130. package/scripts/lib/kit-events.sh +7 -0
  131. package/scripts/lib/kit-gc-test.sh +173 -1
  132. package/scripts/lib/kit-gc.sh +226 -37
  133. package/scripts/lib/kit-hotfix.sh +216 -0
  134. package/scripts/lib/kit-interview-test.sh +93 -0
  135. package/scripts/lib/kit-interview.sh +117 -8
  136. package/scripts/lib/kit-lib-test.sh +1 -1
  137. package/scripts/lib/kit-lib.sh +3 -3
  138. package/scripts/lib/kit-local.sh +2 -2
  139. package/scripts/lib/kit-manifest.sh +33 -1
  140. package/scripts/lib/kit-profile-test.sh +3 -3
  141. package/scripts/lib/kit-status-test.sh +112 -4
  142. package/scripts/lib/kit-status.sh +246 -16
  143. package/scripts/lib/kit-task-ops-test.sh +37 -0
  144. package/scripts/lib/kit-task-ops.sh +175 -31
  145. package/scripts/lib/kto-hotfix-test.sh +232 -0
  146. package/scripts/lib/kto-task-close-test.sh +1 -1
  147. package/scripts/lib/kto-task-new-test.sh +95 -0
  148. package/scripts/lib/kto-task-pr-merge-test.sh +37 -3
  149. package/scripts/lib/kto-task-pr-test.sh +70 -0
  150. package/scripts/lib/leak-fence.sh +89 -0
  151. package/scripts/lib/light-task-run-test.sh +255 -0
  152. package/scripts/lib/light-task-test.sh +309 -0
  153. package/scripts/lib/light-task.sh +706 -0
  154. package/scripts/lib/next-test.sh +99 -0
  155. package/scripts/lib/next.sh +9 -3
  156. package/scripts/lib/orchestration-runtime-test.sh +72 -0
  157. package/scripts/lib/orchestration-runtime.sh +57 -5
  158. package/scripts/lib/plan-machine-test.sh +15 -2
  159. package/scripts/lib/plan-machine.sh +20 -7
  160. package/scripts/lib/plan-next-test.sh +1 -1
  161. package/scripts/lib/plan-next.sh +4 -4
  162. package/scripts/lib/pr-evidence-test.sh +3 -3
  163. package/scripts/lib/pr-evidence.sh +1 -1
  164. package/scripts/lib/qa-lane-test.sh +626 -0
  165. package/scripts/lib/qa-lane.sh +1357 -0
  166. package/scripts/lib/qa-lanes-test.sh +175 -0
  167. package/scripts/lib/react-detect.sh +1 -1
  168. package/scripts/lib/render-test.sh +1 -1
  169. package/scripts/lib/review-page-test.sh +318 -0
  170. package/scripts/lib/review-page.sh +369 -0
  171. package/scripts/lib/review-stage-test.sh +62 -11
  172. package/scripts/lib/review-stage.sh +42 -60
  173. package/scripts/lib/role-identity-test.sh +65 -0
  174. package/scripts/lib/role-identity.sh +25 -2
  175. package/scripts/lib/secret-guard.sh +3 -3
  176. package/scripts/lib/session-registry-test.sh +111 -0
  177. package/scripts/lib/session-registry.sh +233 -0
  178. package/scripts/lib/stage-receipt-test.sh +14 -1
  179. package/scripts/lib/stage-receipt.sh +13 -8
  180. package/scripts/lib/task-source-file.sh +309 -0
  181. package/scripts/lib/task-source.sh +130 -0
  182. package/scripts/lib/upgrade-report-test.sh +120 -0
  183. package/scripts/lib/upgrade-report.sh +138 -0
  184. package/scripts/lib/version-bump.sh +3 -3
  185. package/scripts/lib/wave-result-test.sh +80 -0
  186. package/scripts/lib/wave-result.sh +127 -0
  187. package/scripts/lib/worker-brief-test.sh +5 -0
  188. package/scripts/lib/worker-brief.sh +2 -2
  189. package/scripts/lib/worktree-issue-test.sh +30 -1
  190. package/scripts/lib/worktree-issue.sh +82 -12
  191. package/scripts/lib/worktree-ports-test.sh +57 -4
  192. package/scripts/lib/worktree-start-test.sh +197 -0
  193. package/scripts/lib/worktree-start.sh +153 -31
  194. package/scripts/lib/zsh-safety-test.sh +19 -3
  195. package/scripts/marketing-walkthrough-test.sh +152 -0
  196. package/scripts/night-grant-test.sh +37 -0
  197. package/scripts/night-grant.sh +448 -0
  198. package/scripts/night-run-test.sh +8 -0
  199. package/scripts/night-run.mjs +275 -0
  200. package/scripts/night-run.test.mjs +324 -0
  201. package/scripts/orchestrate-test.sh +190 -0
  202. package/scripts/orchestrate.sh +79 -8
  203. package/scripts/portable-test.sh +11 -2
  204. package/scripts/publish.sh +28 -3
  205. package/scripts/review-lint-test.sh +7 -7
  206. package/scripts/review-lint.sh +2 -2
  207. package/scripts/review-rules.conf +8 -0
  208. package/scripts/rule-recipes-test.sh +96 -0
  209. package/scripts/self-install-test.sh +39 -9
  210. package/scripts/setup-labels.sh +18 -1
  211. package/scripts/setup-milestones.sh +1 -1
  212. package/scripts/showcase.sh +1 -1
  213. package/scripts/skill-frontmatter-lint-test.sh +4 -4
  214. package/scripts/skill-frontmatter-lint.sh +1 -1
  215. package/scripts/status-test.sh +113 -2
  216. package/scripts/status.sh +16 -3
  217. package/scripts/task-sync-test.sh +154 -0
  218. package/scripts/task-sync.sh +243 -32
  219. package/scripts/test-runner-test.sh +158 -0
  220. package/scripts/test.sh +131 -23
  221. package/scripts/update-path-test.sh +279 -0
  222. package/scripts/ux-ds-audit.sh +1 -1
  223. package/scripts/ux-graph-scan.sh +6 -6
  224. package/scripts/wave-worker.sh +54 -0
  225. package/skills/kit-add/SKILL.md +77 -0
  226. package/skills/kit-autopilot/SKILL.md +123 -12
  227. package/skills/kit-cleanup/SKILL.md +5 -2
  228. package/skills/kit-contribute/SKILL.md +4 -4
  229. package/skills/kit-docs-writer/SKILL.md +16 -6
  230. package/skills/kit-effort-close/SKILL.md +17 -8
  231. package/skills/kit-effort-new/SKILL.md +15 -9
  232. package/skills/kit-effort-pr/SKILL.md +15 -7
  233. package/skills/kit-effort-start/SKILL.md +5 -2
  234. package/skills/kit-gc/SKILL.md +5 -2
  235. package/skills/kit-next/SKILL.md +5 -1
  236. package/skills/kit-onboard/SKILL.md +3 -3
  237. package/skills/kit-page/SKILL.md +93 -0
  238. package/skills/kit-plan-next/SKILL.md +8 -4
  239. package/skills/kit-security-sweep/SKILL.md +1 -3
  240. package/skills/kit-ship/SKILL.md +2 -3
  241. package/skills/kit-status/SKILL.md +35 -4
  242. package/skills/kit-task-new/SKILL.md +3 -3
  243. package/skills/kit-task-pr/SKILL.md +7 -2
  244. package/skills/kit-task-pr-merge/SKILL.md +7 -2
  245. package/skills/kit-task-start/SKILL.md +7 -7
  246. package/skills/kit-task-sync/SKILL.md +19 -3
  247. package/skills/kit-ux-audit/SKILL.md +3 -2
  248. package/templates/agents/auto-dev.md +5 -4
  249. package/templates/agents/backend.md +1 -1
  250. package/templates/agents/designer.md +2 -0
  251. package/templates/agents/devops.md +1 -1
  252. package/templates/agents/editor.md +9 -1
  253. package/templates/agents/frontend.md +1 -1
  254. package/templates/agents/local-delegate.md +1 -1
  255. package/templates/agents/pm.md +5 -5
  256. package/templates/agents/tech-lead.md +1 -1
  257. package/templates/benchmarks/SCHEMA.md +9 -3
  258. package/templates/codex/hooks.json.tmpl +89 -0
  259. package/templates/hooks/guard-base-branch-commit.sh.tmpl +13 -7
  260. package/templates/hooks/guard-raw-git-ops.sh.tmpl +12 -12
  261. package/templates/hooks/mempal_followup.sh.tmpl +2 -2
  262. package/templates/hooks/mempal_session_start.sh.tmpl +1 -1
  263. package/templates/hooks/prepush_gate.sh.tmpl +4 -2
  264. package/templates/hooks/repo-hygiene.sh.tmpl +3 -2
  265. package/templates/instructions.md.tmpl +174 -0
  266. package/templates/kit.config.json.tmpl +3 -3
  267. package/templates/knowledge-INDEX.md.tmpl +1 -1
  268. package/templates/lib/kit-sigil.sh.tmpl +1 -1
  269. package/templates/rules/authoring.md +106 -0
  270. package/templates/rules/branch-naming.md +40 -4
  271. package/templates/rules/code-retrieval.md +63 -0
  272. package/templates/rules/delegation-brief.md +0 -3
  273. package/templates/rules/design-routing.md +3 -3
  274. package/templates/rules/effort-model.md +14 -10
  275. package/templates/rules/gate-and-review.md +94 -0
  276. package/templates/rules/issue-lifecycle.md +88 -0
  277. package/templates/rules/knowledge-base.md +1 -1
  278. package/templates/rules/mempalace.md +1 -1
  279. package/templates/rules/merge-safety.md +108 -0
  280. package/templates/rules/naming-and-ids.md +23 -17
  281. package/templates/rules/plain-language.md +59 -0
  282. package/templates/rules/plan-next.md +9 -11
  283. package/templates/rules/react-annotate.md +6 -0
  284. package/templates/rules/review-pages.md +49 -0
  285. package/templates/rules/risk-tiered-review.md +13 -4
  286. package/templates/rules/shared-checkout.md +106 -0
  287. package/templates/rules/skill-gaps.md +2 -7
  288. package/templates/rules/task-management.md +13 -1
  289. package/templates/skills/brand-voice/SKILL.md +91 -0
  290. package/templates/skills/brand-voice/references/voice-template.md +61 -0
  291. package/templates/skills/campaign/SKILL.md +123 -0
  292. package/templates/skills/campaign/references/plan-template.md +55 -0
  293. package/templates/skills/concrete/SKILL.md +2 -2
  294. package/templates/skills/copywriting/SKILL.md +8 -1
  295. package/templates/skills/feature-build-refine/SKILL.md +2 -4
  296. package/templates/skills/morning-briefing/SKILL.md +2 -2
  297. package/templates/skills/page-design/SKILL.md +145 -0
  298. package/templates/skills/page-design/add.json +5 -0
  299. package/templates/skills/page-design/references/design-file-template.md +40 -0
  300. package/templates/skills/page-design/references/generic-page-patterns.md +43 -0
  301. package/templates/skills/page-design/references/minimum-rules.md +42 -0
  302. package/templates/skills/speckit/SKILL.md +4 -5
  303. package/templates/skills/supabase-patterns/SKILL.md +1 -1
  304. package/commands/kit-add.md +0 -42
  305. package/templates/CLAUDE.md.tmpl +0 -106
@@ -0,0 +1,138 @@
1
+ #!/usr/bin/env bash
2
+ # shellcheck shell=bash
3
+ # upgrade-report.sh — what `cckit init --upgrade` changed on disk, measured, not narrated (#448).
4
+ #
5
+ # The upgrade's own bookkeeping (added / preserved / refreshed) is filled in by the write helpers,
6
+ # and a file a later step merges into (`.claude/settings.json`, the config) was reported as
7
+ # preserved while its bytes changed. The dry run printed a hand-kept list of everything the kit
8
+ # could ever write. Both are replaced by ONE measurement: checksum the kit-managed paths before and
9
+ # after, and print the difference. The dry run takes the same measurement on a temporary copy.
10
+ #
11
+ # upgrade_snapshot <dir> -> "<path>\t<crc>:<bytes>" per file, sorted by path
12
+ # upgrade_changes <before> <after> -> "A\t<path>" / "M\t<path>" / "D\t<path>", sorted by path
13
+ # upgrade_changes_print <changes> <head> -> the block both the dry run and the real run print
14
+ # upgrade_dry_run <target> <init.sh> <args…>
15
+ # -> runs the real upgrade on a copy; prints the block
16
+ # json_write_minimal <merged> <file> -> replace <file> by <merged> with the fewest changed lines
17
+ #
18
+ # Runs under bash 3.2 and zsh: no word-splitting of a variable, no arrays indexed from 0.
19
+ # errors: mixed — upgrade_snapshot / upgrade_changes / upgrade_changes_print always return 0 (an
20
+ # unreadable dir is an empty snapshot); upgrade_dry_run returns the simulated run's rc; json_write_minimal
21
+ # returns non-zero only when the final write fails.
22
+
23
+ # The paths an upgrade can write under. `.claude/worktrees` (other checkouts), `node_modules` and
24
+ # `.git` are never the kit's, so they are pruned from both the snapshot and the dry-run copy.
25
+ _upgrade_roots() {
26
+ printf '%s\n' .claude .codex .agents .cckit scripts knowledge benchmarks \
27
+ CLAUDE.md AGENTS.md .gitignore cckit.config.json
28
+ }
29
+
30
+ upgrade_snapshot() { # <dir>
31
+ ( cd "$1" 2>/dev/null || exit 0
32
+ _upgrade_roots | while IFS= read -r _ur; do
33
+ [ -e "$_ur" ] || continue
34
+ find "$_ur" \( -name worktrees -o -name node_modules -o -name .git \) -prune -o -type f -print0
35
+ done | xargs -0 cksum /dev/null 2>/dev/null \
36
+ | sed -n 's/^\([0-9][0-9]*\) \([0-9][0-9]*\) \(.*\)$/\3 \1:\2/p' \
37
+ | grep -v '^/dev/null ' | LC_ALL=C sort ) || true
38
+ }
39
+
40
+ upgrade_changes() { # <before-file> <after-file>
41
+ awk -F'\t' '
42
+ NR == FNR { b[$1] = $2; next }
43
+ { seen[$1] = 1 }
44
+ !($1 in b) { print "A\t" $1; next }
45
+ b[$1] != $2 { print "M\t" $1 }
46
+ END { for (p in b) if (!(p in seen)) print "D\t" p }
47
+ ' "$1" "$2" | LC_ALL=C sort -t' ' -k2
48
+ }
49
+
50
+ upgrade_changes_print() { # <changes-file> <heading>
51
+ local a m d
52
+ a="$(grep -c '^A ' "$1" 2>/dev/null || true)"; m="$(grep -c '^M ' "$1" 2>/dev/null || true)"
53
+ d="$(grep -c '^D ' "$1" 2>/dev/null || true)"
54
+ printf ' %s (%s added, %s modified' "$2" "${a:-0}" "${m:-0}"
55
+ [ "${d:-0}" -gt 0 ] && printf ', %s deleted' "$d"
56
+ printf '):\n'
57
+ if [ -s "$1" ]; then sed 's/^\(.\) / \1 /' "$1"; else printf ' (nothing)\n'; fi
58
+ }
59
+
60
+ # upgrade_dry_run — the dry run of an upgrade IS the upgrade, run on a copy.
61
+ # Copies the kit-managed paths of <target> into a temp dir of the same basename, runs init.sh there
62
+ # with the caller's own flags (minus --dry-run, plus --force: the copy has no git history to guard),
63
+ # and prints the before/after difference. <target> is never written. rc = the simulated run's rc.
64
+ upgrade_dry_run() { # <target> <init.sh> <args…>
65
+ local target="$1" init="$2" tmp copy a rc=0 r
66
+ shift 2
67
+ tmp="$(mktemp -d)" || return 1
68
+ copy="$tmp/$(basename "$target")"
69
+ mkdir -p "$copy" || { rm -rf "$tmp"; return 1; }
70
+ copy="$(cd "$copy" && pwd)"
71
+ _upgrade_roots | while IFS= read -r r; do
72
+ [ -e "$target/$r" ] || continue
73
+ ( cd "$target" && tar -cf - --exclude 'worktrees' --exclude 'node_modules' --exclude '.git' "$r" ) \
74
+ | ( cd "$copy" && tar -xf - )
75
+ done
76
+ # Absolute paths the project recorded (hook commands in settings.local.json, project.path) name
77
+ # <target>. Point them at the copy, so the simulated run sees a project that is consistent with
78
+ # where it lives — otherwise a registration it would recognise looks foreign and is added twice.
79
+ grep -rlF -- "$target" "$copy" 2>/dev/null | while IFS= read -r r; do
80
+ FROM="$target" TO="$copy" perl -pi -e 's/\Q$ENV{FROM}\E/$ENV{TO}/g' "$r" 2>/dev/null
81
+ done
82
+ upgrade_snapshot "$copy" > "$tmp/before"
83
+ set -- "$@" --target "$copy" --force
84
+ local n=$# i=0
85
+ while [ "$i" -lt "$n" ]; do
86
+ a="$1"; shift; i=$((i + 1))
87
+ [ "$a" = "--dry-run" ] || set -- "$@" "$a"
88
+ done
89
+ KIT_UPGRADE_SIMULATED=1 bash "$init" "$@" > "$tmp/out" 2>&1 </dev/null || rc=$?
90
+ if [ "$rc" -ne 0 ]; then
91
+ printf ' x the simulated upgrade failed (exit %s) — nothing was written to %s. Its output:\n' "$rc" "$target" >&2
92
+ sed "s|$copy|$target|g; s/^/ /" "$tmp/out" >&2
93
+ rm -rf "$tmp"; return "$rc"
94
+ fi
95
+ upgrade_snapshot "$copy" > "$tmp/after"
96
+ upgrade_changes "$tmp/before" "$tmp/after" > "$tmp/changes"
97
+ upgrade_changes_print "$tmp/changes" "Would change"
98
+ rm -rf "$tmp"
99
+ return 0
100
+ }
101
+
102
+ # json_write_minimal — write <merged> over <file> changing as few lines as the change needs.
103
+ # jq re-serialises a whole document: a one-key change rewrote every line whose formatting differed
104
+ # from jq's (inline arrays expanded, 66 changed lines for a `kitVersion` bump). So:
105
+ # - same value as <file> already holds -> <file> is not touched (prints "unchanged")
106
+ # - only top-level string keys differ -> each is replaced in place, by text (prints "in-place")
107
+ # - anything else -> <merged> replaces <file> (prints "rewritten")
108
+ # The in-place result is re-parsed and compared with <merged>; on any difference it falls back to
109
+ # "rewritten", so the file always ends up holding exactly <merged>'s value. <merged> is consumed.
110
+ json_write_minimal() { # <merged-file> <file>
111
+ local merged="$1" file="$2" keys k v tmp
112
+ if [ ! -f "$file" ]; then mv "$merged" "$file" && echo rewritten; return; fi
113
+ if jq -e -n --slurpfile a "$merged" --slurpfile b "$file" '$a[0] == $b[0]' >/dev/null 2>&1; then
114
+ rm -f "$merged"; echo unchanged; return 0
115
+ fi
116
+ # Top-level keys present in both, strings in both, whose value differs — and nothing else differs.
117
+ keys="$(jq -r -n --slurpfile a "$merged" --slurpfile b "$file" '
118
+ $a[0] as $m | $b[0] as $h
119
+ | [ $m | keys_unsorted[] | select($m[.] != $h[.]) ] as $diff
120
+ | if ($m | keys) == ($h | keys)
121
+ and ($diff | all(. as $k | ($m[$k] | type) == "string" and ($h[$k] | type) == "string"))
122
+ then $diff[] else empty end' 2>/dev/null || true)"
123
+ if [ -n "$keys" ] && command -v perl >/dev/null 2>&1; then
124
+ tmp="$file.kit-inplace"
125
+ cp "$file" "$tmp"
126
+ printf '%s\n' "$keys" | while IFS= read -r k; do
127
+ v="$(jq -n --slurpfile a "$merged" --arg k "$k" '$a[0][$k]')" # JSON-encoded, quotes included
128
+ K="$k" V="$v" perl -0777 -i -pe '
129
+ my ($k, $v) = ($ENV{K}, $ENV{V});
130
+ s/("\Q$k\E"\s*:\s*)"(?:[^"\\]|\\.)*"/$1.$v/e;' "$tmp"
131
+ done
132
+ if jq -e -n --slurpfile a "$merged" --slurpfile b "$tmp" '$a[0] == $b[0]' >/dev/null 2>&1; then
133
+ mv "$tmp" "$file" && rm -f "$merged"; echo in-place; return 0
134
+ fi
135
+ rm -f "$tmp"
136
+ fi
137
+ mv "$merged" "$file" && echo rewritten
138
+ }
@@ -21,9 +21,9 @@ vb_level() {
21
21
  local range="$1" log
22
22
  log="$(git -C "$ROOT" log --format='%s%n%b' $range 2>/dev/null || true)"
23
23
  [ -n "$log" ] || { echo none; return; }
24
- if printf '%s\n' "$log" | grep -qE '(^|[[:space:]])BREAKING CHANGE|^[a-z]+(\([^)]*\))?!:'; then echo major; return; fi
25
- if printf '%s\n' "$log" | grep -qE '^feat(\([^)]*\))?:'; then echo minor; return; fi
26
- if printf '%s\n' "$log" | grep -qE '^(fix|perf|refactor|revert)(\([^)]*\))?:'; then echo patch; return; fi
24
+ if grep -qE '(^|[[:space:]])BREAKING CHANGE|^[a-z]+(\([^)]*\))?!:' <<<"$log"; then echo major; return; fi
25
+ if grep -qE '^feat(\([^)]*\))?:' <<<"$log"; then echo minor; return; fi
26
+ if grep -qE '^(fix|perf|refactor|revert)(\([^)]*\))?:' <<<"$log"; then echo patch; return; fi
27
27
  # Only non-functional commits (docs/chore/style/test/ci/build, or untyped) -> no release.
28
28
  echo none
29
29
  }
@@ -0,0 +1,80 @@
1
+ #!/bin/sh
2
+ # wave-result-test.sh — self-test for wave-result.sh under bash AND zsh, plus the wave-worker.sh
3
+ # wrapper that writes the records (E257.6, #263). Hermetic: KIT_STATE_DIR points at a temp dir.
4
+ # Run: bash scripts/lib/wave-result-test.sh
5
+ # errors: strict — a test runner: rc 1 on any failed assertion
6
+
7
+ dir=$(CDPATH='' cd -- "$(dirname -- "$0")" && pwd)
8
+
9
+ if [ -n "${WR_TEST_INNER:-}" ]; then
10
+ tmp="$(mktemp -d)"; trap 'rm -rf "$tmp"' EXIT
11
+ KIT_STATE_DIR="$tmp/state"; export KIT_STATE_DIR
12
+ . "$dir/wave-result.sh"
13
+ fail=0
14
+ t() { if [ "$2" = "$3" ]; then :; else echo "FAIL($WR_TEST_INNER): $1 -> got '[$2]' want '[$3]'"; fail=1; fi; }
15
+ worker="$dir/../wave-worker.sh"
16
+
17
+ # ── the three terminal values come from the exit status alone ───────────────────────────
18
+ t "rc 0 is success" "$(wr_classify_rc 0)" "success"
19
+ t "rc 1 is failure" "$(wr_classify_rc 1)" "failure"
20
+ t "rc 128 is failure" "$(wr_classify_rc 128)" "failure"
21
+ t "rc 130 is interrupted" "$(wr_classify_rc 130)" "interrupted"
22
+ t "rc 137 is interrupted" "$(wr_classify_rc 137)" "interrupted"
23
+ t "a non-numeric rc is failure" "$(wr_classify_rc x)" "failure"
24
+
25
+ # ── records: create, update in place, read ────────────────────────────────────────────
26
+ t "session name is made path-safe" "$(wr_session_name 'my wave/1')" "my_wave_1"
27
+ wr_set "s 1" 7 issue=7 state=launched agent=codex "branch=task/7-a=b"
28
+ t "set + get" "$(wr_get "s 1" 7 state)" "launched"
29
+ t "a value may contain =" "$(wr_get "s 1" 7 branch)" "task/7-a=b"
30
+ wr_set "s 1" 7 state=running pid=1
31
+ t "update replaces the field" "$(wr_get "s 1" 7 state)" "running"
32
+ t "update keeps other fields" "$(wr_get "s 1" 7 agent)" "codex"
33
+ t "one line per field" "$(grep -c '^state' "$(wr_file "s 1" 7)")" "1"
34
+ t "an absent record reads empty" "$(wr_get "s 1" 99 state)" ""
35
+ t "an absent session has no rows" "$(wr_rows nope)" ""
36
+
37
+ # ── a `running` record is only as true as its pid, on the host that wrote it ───────────────
38
+ sh -c 'exit 0' & dead=$!; wait "$dead" 2>/dev/null
39
+ wr_set "s 1" 8 issue=8 state=running "pid=$dead" "host=$(hostname)"
40
+ t "running + dead pid here is interrupted" "$(wr_state "s 1" 8)" "interrupted"
41
+ wr_set "s 1" 9 issue=9 state=running "pid=$dead" host=some-other-host
42
+ t "running + dead pid elsewhere stays running" "$(wr_state "s 1" 9)" "running"
43
+ wr_set "s 1" 10 issue=10 state=running "pid=$$" "host=$(hostname)"
44
+ t "running + live pid stays running" "$(wr_state "s 1" 10)" "running"
45
+ wr_set "s 1" 11 issue=11 state=success rc=0 "pid=$dead" "host=$(hostname)"
46
+ t "a terminal state is never reread from the pid" "$(wr_state "s 1" 11)" "success"
47
+ t "rows are ordered by issue" "$(wr_rows "s 1" | cut -f1 | tr '\n' ' ')" "7 8 9 10 11 "
48
+ t "pending counts launched + running" "$(wr_pending "s 1")" "3"
49
+ wr_clear "s 1"
50
+ t "clear drops the session's records" "$(wr_rows "s 1")" ""
51
+
52
+ # ── the wrapper: it records the agent's own exit, for any command ────────────────────────
53
+ bash "$worker" w 1 -- sh -c 'exit 0'; t "wrapper returns the agent's rc 0" "$?" "0"
54
+ bash "$worker" w 2 -- sh -c 'exit 4'; t "wrapper returns the agent's rc 4" "$?" "4"
55
+ bash "$worker" w 3 -- sh -c 'kill -9 $$' 2>/dev/null; t "wrapper returns a signal rc" "$?" "137"
56
+ t "exit 0 recorded as success" "$(wr_state w 1)/$(wr_get w 1 rc)" "success/0"
57
+ t "exit 4 recorded as failure" "$(wr_state w 2)/$(wr_get w 2 rc)" "failure/4"
58
+ t "SIGKILL recorded as interrupted" "$(wr_state w 3)/$(wr_get w 3 rc)" "interrupted/137"
59
+ wr_set w 4 issue=4 state=launched agent=claude branch=task/4-x
60
+ bash "$worker" w 4 -- sh -c 'printf "%s|" "$@"' argv0 'two words' "it's" > "$tmp/argv"
61
+ t "argv reaches the agent untouched" "$(cat "$tmp/argv")" "two words|it's|"
62
+ t "wrapper keeps the launcher's fields" "$(wr_get w 4 agent)/$(wr_get w 4 branch)" "claude/task/4-x"
63
+ # A TERM to the wrapper: bash defers the trap until the agent returns, then records interrupted
64
+ # even though the agent itself exited 0.
65
+ bash "$worker" w 5 -- sh -c 'kill -TERM "$PPID"; sleep 1' 2>/dev/null
66
+ t "a TERM to the wrapper is rc 143" "$?" "143"
67
+ t "a TERM is recorded as interrupted" "$(wr_state w 5)" "interrupted"
68
+ bash "$worker" w >/dev/null 2>&1; t "wrapper refuses a missing issue" "$?" "2"
69
+ bash "$worker" w 6 -- >/dev/null 2>&1; t "wrapper refuses a missing command" "$?" "2"
70
+
71
+ if [ "$fail" -eq 0 ]; then echo "PASS($WR_TEST_INNER): wave result records + worker wrapper"; fi
72
+ exit "$fail"
73
+ fi
74
+
75
+ rc=0
76
+ for sh in bash zsh; do
77
+ command -v "$sh" >/dev/null 2>&1 || continue
78
+ WR_TEST_INNER="$sh" "$sh" "$0" || rc=1
79
+ done
80
+ exit "$rc"
@@ -0,0 +1,127 @@
1
+ #!/usr/bin/env bash
2
+ # shellcheck shell=bash
3
+ # wave-result.sh — one collected result per worker of an orchestrated wave (E257.6, #263).
4
+ #
5
+ # `cckit orchestrate` used to return as soon as it had typed a command into each pane: nothing
6
+ # recorded how a worker ended, so a captain could not tell a finished worker from a crashed one
7
+ # without reading panes. This is the record. The launcher writes one file per issue before a pane
8
+ # starts, scripts/wave-worker.sh (the process the pane actually runs) updates it, and
9
+ # `cckit orchestrate --results` reads it back.
10
+ #
11
+ # A result is how the worker PROCESS ended, in three distinct terminal values:
12
+ # success the agent exited 0
13
+ # failure the agent exited 1-128
14
+ # interrupted the agent died on a signal (exit > 128), the wrapper caught HUP/INT/TERM, or the
15
+ # record still says `running` while its pid is gone on the host that wrote it — a
16
+ # killed pane or a SIGKILL leaves no chance to write a final state, so a dead pid IS
17
+ # the evidence
18
+ # and three non-terminal ones: `launched` (the pane has not started the worker yet), `running`,
19
+ # and `untracked` (Herdr owns the agent process, so cckit has no exit status to collect).
20
+ #
21
+ # It is the same for every agent kind — claude, codex or any other CLI — because it reads the exit
22
+ # status of a process cckit started, not anything the agent says. What the worker CLAIMS it did is
23
+ # the stage receipt (stage-receipt.sh); the two are separate records and neither replaces the other.
24
+ #
25
+ # Records live under the shared state dir (kit-state.sh), so a worker in its own worktree and a
26
+ # captain in the main checkout read the same file. One `key<TAB>value` line per field.
27
+ #
28
+ # wr_session_name <session> the session name, reduced to a safe directory name
29
+ # wr_dir <session> the session's record directory (does not create it)
30
+ # wr_file <session> <issue> one record's absolute path
31
+ # wr_set <session> <issue> k=v … create or update fields of one record (atomic rename)
32
+ # wr_get <session> <issue> <key> one field ("" when absent)
33
+ # wr_classify_rc <exit-status> success | failure | interrupted
34
+ # wr_state <session> <issue> the effective state (a dead `running` pid -> interrupted)
35
+ # wr_rows <session> one "issue state rc agent runtime branch worktree" TSV row
36
+ # per record, ordered by issue number
37
+ # wr_pending <session> how many records are still launched or running
38
+ # wr_clear <session> drop the session's records (a relaunch starts clean)
39
+ #
40
+ # bash 3.2 + zsh compatible: no arrays, and no glob held in a variable.
41
+ # errors: mixed — the readers are pure and answer "" for an absent record; wr_set returns 1 when
42
+ # the record directory cannot be created or the write fails.
43
+
44
+ _wr_dir="$(CDPATH='' cd -- "$(dirname -- "${BASH_SOURCE[0]:-$0}")" >/dev/null 2>&1 && pwd)"
45
+ # shellcheck source=/dev/null
46
+ command -v kit_state_dir >/dev/null 2>&1 || . "$_wr_dir/kit-state.sh"
47
+
48
+ wr_session_name() {
49
+ local s; s="$(printf '%s' "${1:-orchestrate}" | tr -c 'A-Za-z0-9._-' '_')"
50
+ printf '%s\n' "${s:-orchestrate}"
51
+ }
52
+
53
+ wr_dir() { printf '%s/wave/%s\n' "$(kit_state_dir)" "$(wr_session_name "${1:-}")"; }
54
+
55
+ wr_file() { printf '%s/%s.tsv\n' "$(wr_dir "${1:-}")" "${2:-}"; }
56
+
57
+ wr_set() {
58
+ local session="${1:-}" issue="${2:-}" f d tmp kv
59
+ [ -n "$issue" ] || { echo "wave-result: wr_set needs <session> <issue>" >&2; return 1; }
60
+ shift 2
61
+ f="$(wr_file "$session" "$issue")"; d="$(dirname "$f")"
62
+ mkdir -p "$d" 2>/dev/null || { echo "wave-result: cannot create $d" >&2; return 1; }
63
+ tmp="$f.$$.tmp"
64
+ {
65
+ [ -f "$f" ] && cat "$f"
66
+ for kv in "$@"; do printf '%s\t%s\n' "${kv%%=*}" "${kv#*=}"; done
67
+ } | awk -F'\t' '
68
+ NF < 1 || $1 == "" { next }
69
+ !($1 in seen) { order[++n] = $1 }
70
+ { seen[$1] = 1; v[$1] = $2 }
71
+ END { for (i = 1; i <= n; i++) print order[i] "\t" v[order[i]] }' > "$tmp" \
72
+ && mv "$tmp" "$f" || { rm -f "$tmp"; return 1; }
73
+ }
74
+
75
+ wr_get() {
76
+ local f; f="$(wr_file "${1:-}" "${2:-}")"
77
+ [ -f "$f" ] || return 0
78
+ awk -F'\t' -v k="${3:-}" '$1 == k { print $2; exit }' "$f"
79
+ }
80
+
81
+ wr_classify_rc() {
82
+ case "${1:-}" in
83
+ 0) printf 'success\n' ;;
84
+ ''|*[!0-9]*) printf 'failure\n' ;;
85
+ *) if [ "$1" -gt 128 ]; then printf 'interrupted\n'; else printf 'failure\n'; fi ;;
86
+ esac
87
+ }
88
+
89
+ # A `running` record is only as true as its process. The pid is checked on the host that wrote it
90
+ # and nowhere else: a pid number means nothing on another machine, so a record from a different
91
+ # host stays `running` rather than being declared dead on no evidence (branch-owner.sh, same rule).
92
+ wr_state() {
93
+ local session="${1:-}" issue="${2:-}" st pid host
94
+ st="$(wr_get "$session" "$issue" state)"
95
+ if [ "$st" = "running" ]; then
96
+ pid="$(wr_get "$session" "$issue" pid)"; host="$(wr_get "$session" "$issue" host)"
97
+ case "$pid" in ''|*[!0-9]*) pid="" ;; esac
98
+ if [ -n "$pid" ] && [ "$host" = "$(hostname 2>/dev/null)" ] && ! kill -0 "$pid" 2>/dev/null; then
99
+ st="interrupted"
100
+ fi
101
+ fi
102
+ printf '%s\n' "$st"
103
+ }
104
+
105
+ wr_rows() {
106
+ local session="${1:-}" d f issue
107
+ d="$(wr_dir "$session")"
108
+ [ -d "$d" ] || return 0
109
+ find "$d" -maxdepth 1 -type f -name '*.tsv' 2>/dev/null | while IFS= read -r f; do
110
+ issue="$(basename "$f" .tsv)"
111
+ printf '%s\t%s\t%s\t%s\t%s\t%s\t%s\n' "$issue" "$(wr_state "$session" "$issue")" \
112
+ "$(wr_get "$session" "$issue" rc)" "$(wr_get "$session" "$issue" agent)" \
113
+ "$(wr_get "$session" "$issue" runtime)" "$(wr_get "$session" "$issue" branch)" \
114
+ "$(wr_get "$session" "$issue" worktree)"
115
+ done | sort -n
116
+ }
117
+
118
+ wr_pending() {
119
+ wr_rows "${1:-}" | awk -F'\t' '$2 == "launched" || $2 == "running" { n++ } END { print n + 0 }'
120
+ }
121
+
122
+ wr_clear() {
123
+ local d; d="$(wr_dir "${1:-}")"
124
+ [ -d "$d" ] || return 0
125
+ find "$d" -maxdepth 1 -type f \( -name '*.tsv' -o -name '*.tmp' \) -exec rm -f {} + 2>/dev/null
126
+ return 0
127
+ }
@@ -46,6 +46,11 @@ rc="$(wb_receipt_contract 41)"
46
46
  for f in outcome url gate blocker "next stage"; do
47
47
  yes "the receipt contract declares '$f'" "$rc" "$f:"
48
48
  done
49
+ # The contract's next-stage line is the receipt vocabulary (SR_STAGES, stage-receipt.sh), `qa` included (#299): a
50
+ # worker told a shorter list would have its `next stage: qa` flagged invalid.
51
+ for st in build review design docs qa none; do
52
+ yes "the receipt contract offers next stage '$st'" "$(printf '%s\n' "$rc" | grep 'next stage:')" " $st"
53
+ done
49
54
  yes "the receipt contract names the PR verb" "$rc" "cckit pr 41"
50
55
  yes "the receipt contract names the no-op close" "$rc" "cckit close 41"
51
56
  # The contract must name the verb that PERSISTS it (#322). A prompt that only asks the worker to
@@ -54,7 +54,7 @@ Then RECORD your receipt — this is the only durable record of the run, and you
54
54
  url: <PR or issue URL>
55
55
  gate: pass | fail — <the failing check, if any>
56
56
  blocker: <what stopped you, or: none>
57
- next stage: build | review | design | docs | none
57
+ next stage: build | review | design | docs | qa | none
58
58
  RECEIPT
59
59
 
60
60
  Re-running that with the same five values is safe — it rewrites its own attempt rather than
@@ -175,7 +175,7 @@ wb_compose() {
175
175
  {
176
176
  wb_preamble "$num" "$branch"
177
177
  printf '\n'
178
- printf '%s\n' "$brief" | awk '/^##[[:space:]]/ { exit } { print }'
178
+ printf '%s\n' "$brief" | awk '/^##[[:space:]]/ { past = 1 } !past { print }'
179
179
  } > "$tmp/head"
180
180
  { printf '\n'; wb_receipt_contract "$num"; } > "$tmp/tail"
181
181
  printf '%s\n' "$brief" | awk 'f || /^##[[:space:]]/ { f = 1; print }' \
@@ -44,7 +44,36 @@ if [ -n "${WT_TEST_INNER:-}" ]; then
44
44
  # willing to delete a misnamed live branch — the failure mode this whole lib exists to prevent.
45
45
  check "feat/1604a-parser" "1604" # non-sub kind, suffix still protects
46
46
  check "feat+1604a-parser" "1604" # same, worktree dirname form
47
- [ "$fail" -eq 0 ] && echo "OK($WT_TEST_INNER): 21 cases"
47
+ # wt_issue_state (#330): failed is not empty. A gh that exits non-zero answers `unknown`; a gh
48
+ # that says "no such issue" answers empty; only open/closed pass through.
49
+ tmp=$(mktemp -d)
50
+ mkdir "$tmp/bin" "$tmp/nogh"
51
+ for c in tr grep head; do p_=$(command -v "$c"); [ -n "$p_" ] && ln -sf "$p_" "$tmp/nogh/$c"; done
52
+ state() { # state <label> <want> <gh script body> [transport]
53
+ printf '#!/bin/sh\n%s\n' "$3" > "$tmp/bin/gh"; chmod +x "$tmp/bin/gh"
54
+ got=$(PATH="$tmp/bin:$PATH" CCKIT_GH_TRANSPORT="${4:-graphql}" KIT_REPO=o/r wt_issue_state 41 o/r)
55
+ if [ "$got" != "$2" ]; then
56
+ echo "FAIL($WT_TEST_INNER): wt_issue_state $1 -> '[$got]', want '[$2]'"
57
+ fail=1
58
+ fi
59
+ }
60
+ state "open (graphql)" "open" 'echo OPEN'
61
+ state "closed (rest)" "closed" 'echo closed' rest
62
+ state "gh fails (graphql)" "unknown" 'echo "GraphQL: API rate limit exceeded" >&2; exit 1'
63
+ state "gh fails (rest)" "unknown" 'echo "gh: Server Error (HTTP 502)" >&2; exit 1' rest
64
+ state "no such issue (gql)" "" 'echo "GraphQL: Could not resolve to an Issue with the number of 41." >&2; exit 1'
65
+ state "no such issue (rest)" "" 'echo "gh: Not Found (HTTP 404)" >&2; exit 1' rest
66
+ state "empty success" "" 'exit 0'
67
+ got=$(PATH="$tmp/nogh" wt_issue_state 41 o/r)
68
+ [ "$got" = "unknown" ] || { echo "FAIL($WT_TEST_INNER): wt_issue_state with no gh -> '[$got]', want '[unknown]'"; fail=1; }
69
+ got=$(PATH="$tmp/bin:$PATH" wt_issue_state "" o/r)
70
+ [ -z "$got" ] || { echo "FAIL($WT_TEST_INNER): wt_issue_state with no number -> '[$got]', want '[]'"; fail=1; }
71
+ # An unknown state is not a protection claim — gc reports it as UNKNOWN itself.
72
+ printf '#!/bin/sh\nexit 1\n' > "$tmp/bin/gh"
73
+ got=$(PATH="$tmp/bin:$PATH" CCKIT_GH_TRANSPORT=graphql wt_protected_reason task/41-x o/r)
74
+ [ -z "$got" ] || { echo "FAIL($WT_TEST_INNER): wt_protected_reason on a failed read -> '[$got]', want '[]'"; fail=1; }
75
+ rm -rf "$tmp"
76
+ [ "$fail" -eq 0 ] && echo "OK($WT_TEST_INNER): 31 cases"
48
77
  exit "$fail"
49
78
  fi
50
79
 
@@ -6,6 +6,7 @@
6
6
  # Conventions (see .claude/rules/branch-naming.md):
7
7
  # branch <kind>/<N>-<slug> e.g. feat/173-admin-clerk-signin
8
8
  # worktree dir <kind>+<N>-<slug> e.g. .claude/worktrees/feat+173-admin-clerk-signin
9
+ # light task light/<id>-<slug> e.g. light/t3f9a-spring-newsletter (no issue; wt_task_id)
9
10
  #
10
11
  # Source it: source scripts/lib/worktree-issue.sh
11
12
  # Requires: git; gh (for state lookups — degrades to "unknown" without it).
@@ -23,6 +24,10 @@ if ! command -v cckit_gh_rest >/dev/null 2>&1; then
23
24
  fi
24
25
  command -v cckit_gh_rest >/dev/null 2>&1 || cckit_gh_rest() { return 1; }
25
26
 
27
+ # This file's own directory, resolved at load time (file scope is the one place bash and zsh agree
28
+ # on it). wt_task_state loads task-source.sh from here on first use.
29
+ _WT_ISSUE_LIB_DIR="$(CDPATH='' cd -- "$(dirname -- "${BASH_SOURCE[0]:-$0}")" >/dev/null 2>&1 && pwd)"
30
+
26
31
  # Echo the issue number a branch name / worktree path belongs to (empty if none, e.g. bot branches).
27
32
  # Normalize the numeric segment of a branch/dir name to an issue number.
28
33
  # Accepts "1602" and also the effort SUB form "1604a" — `sub/<N><letter>-<slug>` is the documented
@@ -73,26 +78,91 @@ wt_issue_number() {
73
78
  return 0
74
79
  }
75
80
 
76
- # Echo the issue state ("open" / "closed") for an issue number, lowercased. Empty when unknown
77
- # (no number, no gh, or lookup failed) — callers must treat empty as "don't assume safe to delete".
81
+ # Echo the issue state for an issue number, lowercased. Three answers, and they are not the same
82
+ # thing (#330):
83
+ # open / closed GitHub answered.
84
+ # (empty) there is nothing to ask about: no number, or GitHub says no such issue (404).
85
+ # unknown the read FAILED — no gh, no repo to ask in rest mode, or gh exited non-zero
86
+ # (rate limit, outage, auth). The issue may well be open.
87
+ # A failed read used to be echoed as empty, which made an outage indistinguishable from "no issue"
88
+ # and let gc treat an open issue's branch as unprotected. Callers must treat `unknown` as "do not
89
+ # assume safe to delete". rc 0 always, so a bare `state="$(wt_issue_state …)"` survives `set -e`.
78
90
  wt_issue_state() {
79
- local n="$1" repo="${2:-}"
91
+ local n="$1" repo="${2:-}" out
80
92
  [[ -z "$n" ]] && return 0
81
- command -v gh >/dev/null 2>&1 || return 0
93
+ command -v gh >/dev/null 2>&1 || { printf 'unknown\n'; return 0; }
82
94
  if cckit_gh_rest; then
83
- repo="${repo:-${KIT_REPO:-}}"; [[ -n "$repo" ]] || return 0
84
- gh api "repos/$repo/issues/$n" --jq .state 2>/dev/null | tr '[:upper:]' '[:lower:]'
85
- return 0
95
+ repo="${repo:-${KIT_REPO:-}}"; [[ -n "$repo" ]] || { printf 'unknown\n'; return 0; }
96
+ out="$(gh api "repos/$repo/issues/$n" --jq .state 2>&1)" || { _wt_issue_state_failed "$out"; return 0; }
97
+ else
98
+ local args=(issue view "$n" --json state --jq .state)
99
+ [[ -n "$repo" ]] && args+=(--repo "$repo")
100
+ out="$(gh "${args[@]}" 2>&1)" || { _wt_issue_state_failed "$out"; return 0; }
101
+ fi
102
+ printf '%s\n' "$out" | tr '[:upper:]' '[:lower:]' | grep -E -x 'open|closed' | sed -n 1p
103
+ return 0
104
+ }
105
+
106
+ # _wt_issue_state_failed <gh output> — what a FAILED state read means. gh's own "no such issue"
107
+ # answer (REST 404, GraphQL "Could not resolve to an Issue") is a definite absence and stays empty;
108
+ # every other failure is `unknown`.
109
+ _wt_issue_state_failed() {
110
+ if grep -qiE 'HTTP 404|Could not resolve to an? (Issue|PullRequest)' <<<"$1"; then return 0; fi
111
+ printf 'unknown\n'
112
+ }
113
+
114
+ # ── light tasks (#450): work tracked without a GitHub issue ───────────────────────────────────
115
+ # A light task's branch is `light/<id>-<slug>` and its worktree dir `light+<id>-<slug>`. <id> starts
116
+ # with a lowercase letter (then lowercase letters / digits, 2-12 characters in all), so
117
+ # wt_issue_number answers nothing for it and no GitHub issue is ever asked about. Without the two
118
+ # functions below such a branch would carry no id at all, and a branch with no id gets no
119
+ # protection: gc would call a task in progress LANDED the moment it has no commit beyond base.
120
+
121
+ # Echo the light-task id a branch name / worktree path belongs to (empty if it is not one).
122
+ wt_task_id() {
123
+ local ref="$1" rest id
124
+ case "$ref" in
125
+ light/*) rest="${ref#light/}" ;;
126
+ *) rest="${ref##*/}"
127
+ case "$rest" in light+*) rest="${rest#light+}" ;; *) return 0 ;; esac ;;
128
+ esac
129
+ id="${rest%%-*}"
130
+ [ "$id" != "$rest" ] || return 0 # no "-" after the id
131
+ case "$id" in ''|[!a-z]*|*[!a-z0-9]*) return 0 ;; esac
132
+ [ "${#id}" -ge 2 ] && [ "${#id}" -le 12 ] || return 0
133
+ printf '%s' "$id"
134
+ }
135
+
136
+ # Echo the state of a light task as the task source reports it (task-source.sh): open / closed,
137
+ # empty when there is no such task, `unknown` when the source could not be loaded or read. Same
138
+ # contract as wt_issue_state: callers treat `unknown` as "do not assume safe to delete". rc 0 always.
139
+ wt_task_state() {
140
+ local id="$1" ref="${2:-}" out
141
+ [ -n "$id" ] || return 0
142
+ if ! command -v task_source_call >/dev/null 2>&1 \
143
+ && [ -n "${_WT_ISSUE_LIB_DIR:-}" ] && [ -f "$_WT_ISSUE_LIB_DIR/task-source.sh" ]; then
144
+ # shellcheck source=/dev/null
145
+ . "$_WT_ISSUE_LIB_DIR/task-source.sh"
86
146
  fi
87
- local args=(issue view "$n" --json state --jq .state)
88
- [[ -n "$repo" ]] && args+=(--repo "$repo")
89
- gh "${args[@]}" 2>/dev/null | tr '[:upper:]' '[:lower:]'
147
+ command -v task_source_call >/dev/null 2>&1 || { printf 'unknown\n'; return 0; }
148
+ out="$(task_source_call state "$id" "$ref" 2>/dev/null)" || { printf 'unknown\n'; return 0; }
149
+ printf '%s\n' "$out" | grep -E -x 'open|closed|unknown' | sed -n 1p
150
+ return 0
90
151
  }
91
152
 
92
- # Echo a protection reason if a branch/ref must NOT be garbage-collected because its issue
93
- # is still open; empty string means "no issue-based protection" (other gc rules still apply).
153
+ # Echo a protection reason if a branch/ref must NOT be garbage-collected because its issue — or its
154
+ # light task — is still open; empty string means "no such protection" (other gc rules still apply).
94
155
  wt_protected_reason() {
95
156
  local ref="$1" repo="${2:-}" n state
157
+ n="$(wt_task_id "$ref")"
158
+ if [ -n "$n" ]; then
159
+ state="$(wt_task_state "$n" "$ref")"
160
+ case "$state" in
161
+ open) printf 'light task %s still OPEN' "$n" ;;
162
+ unknown) printf 'light task %s state unknown' "$n" ;;
163
+ esac
164
+ return 0
165
+ fi
96
166
  n="$(wt_issue_number "$ref")"
97
167
  [[ -z "$n" ]] && return 0
98
168
  state="$(wt_issue_state "$n" "$repo")"