@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,309 @@
1
+ #!/usr/bin/env bash
2
+ # shellcheck shell=bash
3
+ # task-source-file.sh — the `file` task source (#450): one tracked file per light task.
4
+ #
5
+ # <tasks.dir>/<id>.md (tasks.dir defaults to `tasks`, at the checkout root)
6
+ #
7
+ # id: t3f9a
8
+ # title: Write the spring newsletter
9
+ # status: todo
10
+ # priority: p2
11
+ # kind: task
12
+ # created: 2026-11-12
13
+ #
14
+ # Free-form notes after the first blank line.
15
+ #
16
+ # The header is one `key: value` per line up to the first blank line. `status` is `todo`, `done`
17
+ # or `dropped` (set `dropped` by hand to abandon a task); anything else reads as `todo`.
18
+ #
19
+ # ONE FILE PER TASK, because two branches that each add a task must merge without a conflict. Two
20
+ # appends to one shared file land on the same lines and conflict in git; two new files never touch.
21
+ # Finishing a task rewrites one line (`status:`) of one file.
22
+ #
23
+ # STATE IS DERIVED from where the file is and what it says — there is no second record to keep in
24
+ # step. For a task id, in this order:
25
+ # done / dropped the base branch's copy says so (the pull request that finished it merged)
26
+ # review a `light/<id>-<slug>` branch exists and its copy says `done`
27
+ # doing a `light/<id>-<slug>` branch exists
28
+ # todo the base branch has the file
29
+ # shared a `light/share-<stamp>` branch has the file and the base branch does not yet:
30
+ # `cckit task share` committed it and its pull request has not merged
31
+ # draft only this checkout has the file (not committed anywhere a teammate can see)
32
+ # The base branch is read as `origin/<base>` when that ref exists, else the local `<base>`.
33
+ # Branches are local heads first, then the cached `origin/light/*` refs. No op here uses the
34
+ # network; the verbs fetch before they list.
35
+ #
36
+ # Implements the interface in task-source.sh; called only through task_source_call.
37
+ # Requires: git. bash 3.2 + zsh (no glob held in a variable, no `status`/`path` variable names).
38
+ # errors: mixed — reads are forgiving (a missing file is an absent task); writes return 1
39
+
40
+ _tsf_top() { git rev-parse --show-toplevel 2>/dev/null; }
41
+
42
+ _tsf_base_ref() {
43
+ local base="${KIT_BASE_BRANCH:-main}"
44
+ if git show-ref --verify --quiet "refs/remotes/origin/$base" 2>/dev/null; then printf 'origin/%s' "$base"
45
+ elif git show-ref --verify --quiet "refs/heads/$base" 2>/dev/null; then printf '%s' "$base"
46
+ fi
47
+ }
48
+
49
+ # _tsf_field <key> — stdin: a task file. Print the header value of <key>, or nothing.
50
+ _tsf_field() {
51
+ awk -v k="$1" '
52
+ NF == 0 { exit }
53
+ { i = index($0, ":")
54
+ if (i && substr($0, 1, i - 1) == k) {
55
+ v = substr($0, i + 1); sub(/^[ \t]+/, "", v); sub(/[ \t\r]+$/, "", v); print v; exit
56
+ } }'
57
+ }
58
+
59
+ # _tsf_branch <id> — the task's branch as a ref git can read: a local `light/<id>-…` head, else a
60
+ # cached `origin/light/<id>-…`. Nothing when the task has no branch.
61
+ _tsf_branch() {
62
+ local b
63
+ b="$(git for-each-ref --format='%(refname:short)' "refs/heads/light/$1-*" 2>/dev/null | sed -n 1p)"
64
+ [ -n "$b" ] || b="$(git for-each-ref --format='%(refname:short)' "refs/remotes/origin/light/$1-*" 2>/dev/null | sed -n 1p)"
65
+ printf '%s' "$b"
66
+ }
67
+
68
+ _tsf_closed() { case "$1" in done|dropped) return 0 ;; esac; return 1; }
69
+
70
+ # _tsf_share_refs — every `light/share-<stamp>` ref: local heads first, then the cached origin ones.
71
+ _tsf_share_refs() {
72
+ git for-each-ref --format='%(refname:short)' 'refs/heads/light/share-*' \
73
+ 'refs/remotes/origin/light/share-*' 2>/dev/null
74
+ }
75
+
76
+ # _tsf_share_ref <id> — the first share ref whose tree carries the task's file, or nothing.
77
+ _tsf_share_ref() {
78
+ local top dir r
79
+ top="$(_tsf_top)" || return 0
80
+ [ -n "$top" ] || return 0
81
+ dir="$(task_source_dir)"
82
+ _tsf_share_refs | while IFS= read -r r; do
83
+ if git -C "$top" cat-file -e "$r:$dir/$1.md" 2>/dev/null; then printf '%s' "$r"; break; fi
84
+ done
85
+ }
86
+
87
+ # _tsf_ids — every task id visible from this checkout: its tasks dir, the base branch, the
88
+ # `light/*` branches, and the files a `light/share-*` branch carries.
89
+ _tsf_ids() {
90
+ local top dir base r
91
+ top="$(_tsf_top)" || return 0
92
+ [ -n "$top" ] || return 0
93
+ dir="$(task_source_dir)"; base="$(_tsf_base_ref)"
94
+ {
95
+ if [ -d "$top/$dir" ]; then ls "$top/$dir" 2>/dev/null | grep '\.md$' | sed 's/\.md$//'; fi
96
+ if [ -n "$base" ]; then
97
+ git -C "$top" ls-tree --name-only "$base" "$dir/" 2>/dev/null | grep '\.md$' | sed 's|.*/||; s/\.md$//'
98
+ fi
99
+ _tsf_share_refs | while IFS= read -r r; do
100
+ git -C "$top" ls-tree --name-only "$r" "$dir/" 2>/dev/null || true
101
+ done | grep '\.md$' | sed 's|.*/||; s/\.md$//'
102
+ git for-each-ref --format='%(refname)' refs/heads/light/ refs/remotes/origin/light/ 2>/dev/null \
103
+ | sed -E 's#^refs/(heads|remotes/origin)/light/##; s/-.*$//'
104
+ } | while IFS= read -r id; do
105
+ if task_id_valid "$id"; then printf '%s\n' "$id"; fi
106
+ done | sort -u
107
+ }
108
+
109
+ # _tsf_row <id> — the task's TSV row; rc 1 when no copy of the file can be read.
110
+ _tsf_row() {
111
+ local id="$1" top dir base rel br="" c_base="" c_br="" c_wt="" content state s sr=""
112
+ top="$(_tsf_top)" || return 1
113
+ [ -n "$top" ] || return 1
114
+ dir="$(task_source_dir)"; base="$(_tsf_base_ref)"; rel="$dir/$id.md"
115
+ if [ -n "$base" ]; then c_base="$(git -C "$top" show "$base:$rel" 2>/dev/null || true)"; fi
116
+ br="$(_tsf_branch "$id")"
117
+ if [ -n "$br" ]; then c_br="$(git -C "$top" show "$br:$rel" 2>/dev/null || true)"; fi
118
+ if [ -f "$top/$rel" ]; then c_wt="$(cat "$top/$rel" 2>/dev/null || true)"; fi
119
+
120
+ s="$(printf '%s\n' "$c_base" | _tsf_field status)"
121
+ if [ -n "$c_base" ] && _tsf_closed "$s"; then
122
+ state="$s"; content="$c_base"
123
+ elif [ -n "$br" ] && [ -n "${c_br:-$c_base$c_wt}" ]; then
124
+ content="${c_br:-${c_base:-$c_wt}}"
125
+ if [ "$(printf '%s\n' "$c_br" | _tsf_field status)" = "done" ]; then state="review"; else state="doing"; fi
126
+ elif [ -n "$c_base" ]; then
127
+ state="todo"; content="$c_base"
128
+ elif sr="$(_tsf_share_ref "$id")" && [ -n "$sr" ]; then
129
+ state="shared"; br="$sr"; content="$(git -C "$top" show "$sr:$rel" 2>/dev/null || true)"
130
+ elif [ -n "$c_wt" ]; then
131
+ content="$c_wt"; s="$(printf '%s\n' "$c_wt" | _tsf_field status)"
132
+ if _tsf_closed "$s"; then state="$s"; else state="draft"; fi
133
+ else
134
+ return 1
135
+ fi
136
+
137
+ local title prio kind created
138
+ title="$(printf '%s\n' "$content" | _tsf_field title)"
139
+ prio="$(printf '%s\n' "$content" | _tsf_field priority)"
140
+ kind="$(printf '%s\n' "$content" | _tsf_field kind)"
141
+ created="$(printf '%s\n' "$content" | _tsf_field created)"
142
+ printf '%s\t%s\t%s\t%s\t%s\t%s\t%s\n' "$id" "$state" "${prio:-p2}" "${kind:-task}" "${created:--}" \
143
+ "${br:--}" "$(printf '%s' "${title:-(untitled)}" | tr '\t' ' ')"
144
+ }
145
+
146
+ # task_file_list — every task, ordered: doing, review, todo, draft, shared, done, dropped; inside a state
147
+ # by priority, then creation date, then id.
148
+ task_file_list() {
149
+ local id
150
+ _tsf_ids | while IFS= read -r id; do
151
+ [ -n "$id" ] || continue
152
+ _tsf_row "$id" || true
153
+ done | awk -F'\t' '
154
+ BEGIN { r["doing"] = 1; r["review"] = 2; r["todo"] = 3; r["draft"] = 4; r["shared"] = 5; r["done"] = 8; r["dropped"] = 9 }
155
+ { print (($2 in r) ? r[$2] : 7) "\t" $3 "\t" $5 "\t" $1 "\t" $0 }' \
156
+ | sort -t "$(printf '\t')" -k1,1n -k2,2 -k3,3 -k4,4 | cut -f5-
157
+ }
158
+
159
+ # task_file_get <id|prefix> — the one row whose id is <id>, else the one whose id starts with it.
160
+ task_file_get() {
161
+ local want="${1:-}" rows n
162
+ [ -n "$want" ] || { echo "✗ a task id is required" >&2; return 1; }
163
+ if task_id_valid "$want" && rows="$(_tsf_row "$want")" && [ -n "$rows" ]; then
164
+ printf '%s\n' "$rows"; return 0
165
+ fi
166
+ rows="$(task_file_list | awk -F'\t' -v w="$want" 'index($1, w) == 1')"
167
+ n="$(printf '%s\n' "$rows" | grep -c . || true)"
168
+ if [ "$n" -eq 0 ]; then
169
+ echo "✗ no task '$want' — see 'cckit task list --all'" >&2; return 1
170
+ elif [ "$n" -gt 1 ]; then
171
+ echo "✗ '$want' matches $n tasks: $(printf '%s\n' "$rows" | cut -f1 | tr '\n' ' ')" >&2; return 3
172
+ fi
173
+ printf '%s\n' "$rows"
174
+ }
175
+
176
+ _tsf_exists() {
177
+ local id="$1" top dir base
178
+ top="$(_tsf_top)"; dir="$(task_source_dir)"; base="$(_tsf_base_ref)"
179
+ [ -f "$top/$dir/$id.md" ] && return 0
180
+ [ -n "$base" ] && git -C "$top" cat-file -e "$base:$dir/$id.md" 2>/dev/null && return 0
181
+ [ -n "$(_tsf_branch "$id")" ] && return 0
182
+ [ -n "$(_tsf_share_ref "$id")" ] && return 0
183
+ return 1
184
+ }
185
+
186
+ # _tsf_new_id <seed> — `t` + 4 hex digits not used by any task this checkout can see. Not a
187
+ # counter: two branches that each took "the next number" would both create task 7.
188
+ _tsf_new_id() {
189
+ local seed="$1" i=0 h id
190
+ while [ "$i" -lt 64 ]; do
191
+ h="$(printf '%s|%s|%s|%s|%s' "$seed" "$$" "$(date +%s 2>/dev/null)" "${RANDOM:-0}" "$i" \
192
+ | git hash-object --stdin 2>/dev/null | cut -c1-4)"
193
+ id="t$h"
194
+ if [ -n "$h" ] && ! _tsf_exists "$id"; then printf '%s' "$id"; return 0; fi
195
+ i=$((i + 1))
196
+ done
197
+ return 1
198
+ }
199
+
200
+ # task_file_create <title> <priority> <kind> <body> — write the task file into THIS checkout and
201
+ # print the id. Nothing is committed: the file travels with the branch that starts or shares it.
202
+ task_file_create() {
203
+ local title="$1" prio="${2:-p2}" kind="${3:-task}" body="${4:-}" top dir id f
204
+ top="$(_tsf_top)"
205
+ [ -n "$top" ] || { echo "✗ not inside a git repository" >&2; return 1; }
206
+ dir="$(task_source_dir)"
207
+ title="$(printf '%s' "$title" | tr '\n\t' ' ' | sed -E 's/^ +| +$//g')"
208
+ [ -n "$title" ] || { echo "✗ a title is required" >&2; return 1; }
209
+ id="$(_tsf_new_id "$title")" || { echo "✗ could not allocate a task id" >&2; return 1; }
210
+ mkdir -p "$top/$dir" || return 1
211
+ f="$top/$dir/$id.md"
212
+ {
213
+ printf 'id: %s\ntitle: %s\nstatus: todo\npriority: %s\nkind: %s\ncreated: %s\n' \
214
+ "$id" "$title" "$prio" "$kind" "$(date +%Y-%m-%d)"
215
+ if [ -n "$body" ]; then printf '\n%s\n' "$body"; fi
216
+ } > "$f" || return 1
217
+ printf '%s\n' "$id"
218
+ }
219
+
220
+ # _tsf_untracked <checkout> <rel> — rc 0 when <rel> exists there and git does not track it.
221
+ _tsf_untracked() {
222
+ [ -f "$1/$2" ] && ! git -C "$1" ls-files --error-unmatch -- "$2" >/dev/null 2>&1
223
+ }
224
+
225
+ # task_file_on_start <id> <worktree> <from-checkout> — make sure the task file is committed on the
226
+ # task's branch. When the base branch does not have it yet (a draft), it is copied from the checkout
227
+ # the start was run in and committed; an untracked original is then removed, because a file left
228
+ # untracked there blocks the pull that later brings the merged copy.
229
+ task_file_on_start() {
230
+ local id="$1" wt="$2" from="$3" dir rel
231
+ dir="$(task_source_dir)"; rel="$dir/$id.md"
232
+ if git -C "$wt" cat-file -e "HEAD:$rel" 2>/dev/null; then return 0; fi
233
+ if [ ! -f "$wt/$rel" ]; then
234
+ [ -f "$from/$rel" ] || { echo "✗ task $id has no file at $rel" >&2; return 1; }
235
+ mkdir -p "$wt/$dir" && cp "$from/$rel" "$wt/$rel" || return 1
236
+ fi
237
+ git -C "$wt" add -- "$rel" >/dev/null 2>&1 \
238
+ && git -C "$wt" commit -q -m "chore(tasks): add $id" -- "$rel" >/dev/null 2>&1 \
239
+ || { echo "✗ could not commit $rel on the task branch" >&2; return 1; }
240
+ if [ "$from" != "$wt" ] && _tsf_untracked "$from" "$rel"; then
241
+ rm -f "$from/$rel"; rmdir "$from/$dir" 2>/dev/null || true
242
+ echo "[$id] moved $rel onto the task branch" >&2
243
+ fi
244
+ return 0
245
+ }
246
+
247
+ # task_file_on_finish <id> <worktree> — set `status: done` in the worktree's copy and stage the
248
+ # tasks dir (so a task created in this worktree ships with it). The mark reaches the base branch
249
+ # when the pull request merges, which is what makes the task done.
250
+ task_file_on_finish() {
251
+ local id="$1" wt="$2" dir rel tmp
252
+ dir="$(task_source_dir)"; rel="$dir/$id.md"
253
+ [ -f "$wt/$rel" ] || { echo "✗ task $id has no file at $rel in $wt" >&2; return 1; }
254
+ tmp="$(mktemp)" || return 1
255
+ if [ -n "$(_tsf_field status < "$wt/$rel")" ]; then
256
+ awk 'BEGIN { h = 1 } h && NF == 0 { h = 0 }
257
+ h && !d && /^status:/ { print "status: done"; d = 1; next } { print }' "$wt/$rel" > "$tmp"
258
+ else
259
+ { printf 'status: done\n'; cat "$wt/$rel"; } > "$tmp"
260
+ fi
261
+ cat "$tmp" > "$wt/$rel" && rm -f "$tmp" || { rm -f "$tmp"; return 1; }
262
+ git -C "$wt" add -- "$dir" >/dev/null 2>&1 || return 1
263
+ }
264
+
265
+ # task_file_body <id> <worktree> — the free-form notes of the task: everything after the header's
266
+ # first blank line in <worktree>'s copy. Nothing when the task has no notes.
267
+ task_file_body() {
268
+ local f; f="$2/$(task_source_dir)/$1.md"
269
+ [ -f "$f" ] || return 0
270
+ awk 'b { print; next } NF == 0 { b = 1 }' "$f"
271
+ }
272
+
273
+ # task_file_state <id> [<branch>] — what gc asks before it offers a `light/<id>-…` branch for
274
+ # deletion. `closed` only when the base branch's copy says done or dropped. `open` when the base
275
+ # copy says otherwise, or when only the branch (or this checkout) has the file: the work exists
276
+ # nowhere else. Empty when no copy exists. `unknown` when there is no base ref to read.
277
+ task_file_state() {
278
+ local id="$1" br="${2:-}" top dir base rel c
279
+ top="$(_tsf_top)"
280
+ [ -n "$top" ] || { printf 'unknown\n'; return 0; }
281
+ base="$(_tsf_base_ref)"
282
+ [ -n "$base" ] || { printf 'unknown\n'; return 0; }
283
+ dir="$(task_source_dir)"; rel="$dir/$id.md"
284
+ c="$(git -C "$top" show "$base:$rel" 2>/dev/null || true)"
285
+ if [ -n "$c" ]; then
286
+ if _tsf_closed "$(printf '%s\n' "$c" | _tsf_field status)"; then printf 'closed\n'; else printf 'open\n'; fi
287
+ return 0
288
+ fi
289
+ if [ -n "$br" ] && git -C "$top" cat-file -e "$br:$rel" 2>/dev/null; then printf 'open\n'; return 0; fi
290
+ if [ -f "$top/$rel" ]; then printf 'open\n'; fi
291
+ return 0
292
+ }
293
+
294
+ # task_file_share <worktree> <from-checkout> — move every draft (a task file the from-checkout has
295
+ # untracked and no branch or base copy carries) into <worktree> and stage it. Prints the ids moved.
296
+ task_file_share() {
297
+ local wt="$1" from="$2" dir id state rest
298
+ dir="$(task_source_dir)"
299
+ task_file_list | while IFS="$(printf '\t')" read -r id state rest; do
300
+ [ "$state" = draft ] || continue
301
+ _tsf_untracked "$from" "$dir/$id.md" || continue
302
+ mkdir -p "$wt/$dir" && cp "$from/$dir/$id.md" "$wt/$dir/$id.md" || continue
303
+ git -C "$wt" add -- "$dir/$id.md" >/dev/null 2>&1 || continue
304
+ rm -f "$from/$dir/$id.md"
305
+ printf '%s\n' "$id"
306
+ done
307
+ rmdir "$from/$dir" 2>/dev/null || true
308
+ return 0
309
+ }
@@ -0,0 +1,130 @@
1
+ #!/usr/bin/env bash
2
+ # shellcheck shell=bash
3
+ # task-source.sh — the task-source interface for light tasks (#450).
4
+ #
5
+ # A light task is a unit of work that is NOT a GitHub issue. Where its record lives is a SOURCE, and
6
+ # every reader and writer (the `cckit task` verbs in light-task.sh, the gc protection in
7
+ # worktree-issue.sh) reaches it through task_source_call — never through a source's own functions.
8
+ # One source ships: `file` (task-source-file.sh), one tracked file per task.
9
+ #
10
+ # Selecting a source: `tasks.source` in the project config (default `file`); KIT_TASKS_SOURCE in the
11
+ # environment wins per invocation.
12
+ #
13
+ # `tasks.default` is a different question — whether the project's DEFAULT list is this one (`light`)
14
+ # or GitHub issues (`issues`, the default). task_default_name answers it.
15
+ #
16
+ # Adding a source `<name>` (lowercase letters, digits, `_`): add scripts/lib/task-source-<name>.sh
17
+ # defining the functions below, then set `tasks.source` to `<name>`. Nothing else changes: the verbs,
18
+ # the branch form and the gc protection are source-independent.
19
+ #
20
+ # task_<name>_list every task, one TSV row each (format below)
21
+ # task_<name>_get <id|prefix> the one matching row; rc 1 none, rc 3 ambiguous
22
+ # task_<name>_create <title> <priority> <kind> <body> record a new task; print its id
23
+ # task_<name>_on_start <id> <worktree> <from-checkout> work begins in <worktree>
24
+ # task_<name>_on_finish <id> <worktree> work is ready for review
25
+ # task_<name>_state <id> [<branch>] open | closed | unknown | (empty: no such task). rc 0
26
+ # always. gc keeps a branch on `open` and on `unknown`.
27
+ # task_<name>_body <id> <worktree> OPTIONAL: the task's notes, as text. `cckit task run`
28
+ # builds its objective from the title alone without it.
29
+ # task_<name>_share <worktree> <from-checkout> OPTIONAL: move every not-yet-shared task into
30
+ # <worktree>; print one id per line. `cckit task share`
31
+ # refuses when the source does not define it.
32
+ #
33
+ # TSV row: <id>\t<state>\t<priority>\t<kind>\t<created>\t<branch>\t<title>
34
+ # state draft (only in this checkout) · todo · doing · review · done · dropped ·
35
+ # shared (committed by `cckit task share`, its pull request not merged yet)
36
+ # branch the task's `light/<id>-<slug>` ref; for `shared`, the `light/share-<stamp>` ref that
37
+ # carries it; else `-`
38
+ # No field is ever empty (`-` is the absent marker): tab is IFS whitespace, so an empty field would
39
+ # shift the rest. The title is last and may hold spaces.
40
+ #
41
+ # An id is a lowercase letter followed by 1-11 lowercase letters or digits. The leading letter is
42
+ # what keeps a light branch from parsing as an issue number (worktree-issue.sh, wt_issue_number).
43
+ #
44
+ # Requires: git; jq for the config read (without it the defaults apply). bash 3.2 + zsh.
45
+ # errors: mixed — the dispatcher returns 2 for an unknown source or op; each op states its own
46
+
47
+ _TASK_SOURCE_LIB_DIR="$(CDPATH='' cd -- "$(dirname -- "${BASH_SOURCE[0]:-$0}")" >/dev/null 2>&1 && pwd)"
48
+
49
+ # _task_source_cfg <jq-filter> <default> — one key of the project config, or the default.
50
+ _task_source_cfg() {
51
+ local cfg="${KIT_CONFIG:-}" top v=""
52
+ if [ -z "$cfg" ] || [ ! -f "$cfg" ]; then
53
+ top="$(git rev-parse --show-toplevel 2>/dev/null || true)"
54
+ if [ -n "$top" ] && [ -f "$top/cckit.config.json" ]; then cfg="$top/cckit.config.json"
55
+ elif [ -n "$top" ] && [ -f "$top/.claude/kit.config.json" ]; then cfg="$top/.claude/kit.config.json"
56
+ else cfg=""; fi
57
+ fi
58
+ if [ -n "$cfg" ] && command -v jq >/dev/null 2>&1; then
59
+ v="$(jq -r "$1 // empty" "$cfg" 2>/dev/null || true)"
60
+ fi
61
+ printf '%s' "${v:-$2}"
62
+ }
63
+
64
+ # task_source_name — the selected source.
65
+ task_source_name() {
66
+ if [ -n "${KIT_TASKS_SOURCE:-}" ]; then printf '%s' "$KIT_TASKS_SOURCE"; return 0; fi
67
+ _task_source_cfg '.tasks.source' file
68
+ }
69
+
70
+ # task_default_name — which task list is this project's default: `light` (the `cckit task` list) or
71
+ # `issues` (GitHub issues). `tasks.default` in the project config; anything else, or no key, is
72
+ # `issues`, with a warning for a value that is neither. `cckit next` and the campaign skill read it
73
+ # to pick their lane; both lists stay usable whatever it says.
74
+ task_default_name() {
75
+ local v; v="$(_task_source_cfg '.tasks.default' issues)"
76
+ case "$v" in
77
+ light|issues) printf '%s' "$v" ;;
78
+ *) echo "⚠ tasks.default '$v' is neither 'light' nor 'issues' — using 'issues'" >&2; printf 'issues' ;;
79
+ esac
80
+ }
81
+
82
+ # task_source_dir — the tracked directory the file source keeps tasks in, relative to the checkout
83
+ # root (`tasks.dir`, default `tasks`; KIT_TASKS_DIR wins). A value that is absolute or climbs out
84
+ # of the checkout is ignored with a warning.
85
+ task_source_dir() {
86
+ local d="${KIT_TASKS_DIR:-}"
87
+ [ -n "$d" ] || d="$(_task_source_cfg '.tasks.dir' tasks)"
88
+ d="${d%/}"
89
+ case "$d" in
90
+ ''|/*|..|../*|*/..|*/../*)
91
+ echo "⚠ tasks.dir '$d' is not a path inside the project — using 'tasks'" >&2; d="tasks" ;;
92
+ esac
93
+ printf '%s' "$d"
94
+ }
95
+
96
+ # task_id_valid <id> — rc 0 for a usable task id. `share` is reserved: `light/share-<stamp>` is the
97
+ # branch `cckit task share` opens its pull request from.
98
+ task_id_valid() {
99
+ case "${1:-}" in ''|[!a-z]*|*[!a-z0-9]*|share) return 1 ;; esac
100
+ [ "${#1}" -ge 2 ] && [ "${#1}" -le 12 ]
101
+ }
102
+
103
+ # task_source_has <op> — rc 0 when the selected source defines <op>.
104
+ task_source_has() {
105
+ local src fn
106
+ src="$(task_source_name)"
107
+ case "$src" in ''|*[!a-z0-9_]*) return 1 ;; esac
108
+ fn="task_${src}_$1"
109
+ if ! command -v "$fn" >/dev/null 2>&1 && [ -f "$_TASK_SOURCE_LIB_DIR/task-source-$src.sh" ]; then
110
+ # shellcheck source=/dev/null
111
+ . "$_TASK_SOURCE_LIB_DIR/task-source-$src.sh"
112
+ fi
113
+ command -v "$fn" >/dev/null 2>&1
114
+ }
115
+
116
+ # task_source_call <op> [args…] — run <op> on the selected source. rc 2 when the source name is not
117
+ # a name, or the source does not define the op.
118
+ task_source_call() {
119
+ local op="${1:-}" src
120
+ [ "$#" -gt 0 ] && shift
121
+ src="$(task_source_name)"
122
+ case "$src" in
123
+ ''|*[!a-z0-9_]*) echo "✗ tasks.source '$src' is not a source name (lowercase letters, digits, _)" >&2; return 2 ;;
124
+ esac
125
+ if ! task_source_has "$op"; then
126
+ echo "✗ task source '$src' has no '$op' (expected task_${src}_$op in scripts/lib/task-source-$src.sh)" >&2
127
+ return 2
128
+ fi
129
+ "task_${src}_$op" "$@"
130
+ }
@@ -7,16 +7,16 @@ LIB="$(cd "$(dirname "$0")" && pwd)"
7
7
  fail=0
8
8
  t() { if [ "$2" = "$3" ]; then echo "ok: $1"; else echo "FAIL: $1 -> got '[$2]' want '[$3]'"; fail=1; fi; }
9
9
 
10
- out="$(KIT_CONFIG=/nonexistent CCKIT_OUTPUT=json EFFORT_REPO=x/y KEEP_ME=1 bash -c '
10
+ out="$(KIT_CONFIG=/nonexistent CCKIT_OUTPUT=json EFFORT_REPO=x/y CLAUDE_CODE_REMOTE=true KEEP_ME=1 bash -c '
11
11
  . "$1/test-env.sh"
12
12
  test_env_unset_args | paste -sd" " -
13
13
  test_env_seal
14
- echo "${KIT_CONFIG-unset} ${CCKIT_OUTPUT-unset} ${EFFORT_REPO-unset} ${KEEP_ME-unset}"' _ "$LIB")"
14
+ echo "${KIT_CONFIG-unset} ${CCKIT_OUTPUT-unset} ${EFFORT_REPO-unset} ${CLAUDE_CODE_REMOTE-unset} ${KEEP_ME-unset}"' _ "$LIB")"
15
15
  args="$(printf '%s\n' "$out" | sed -n 1p)"
16
16
  after="$(printf '%s\n' "$out" | sed -n 2p)"
17
17
  case " $args " in *" -u KIT_CONFIG "*) echo "ok: unset args name KIT_CONFIG" ;; *) echo "FAIL: unset args: $args"; fail=1 ;; esac
18
18
  case " $args " in *" -u KEEP_ME "*) echo "FAIL: unset args name a non-kit variable: $args"; fail=1 ;; *) echo "ok: unset args leave other variables alone" ;; esac
19
- t "seal unsets KIT_*, CCKIT_*, EFFORT_* and keeps the rest" "$after" "unset unset unset 1"
19
+ t "seal unsets KIT_*, CCKIT_*, EFFORT_*, CLAUDE_CODE_REMOTE and keeps the rest" "$after" "unset unset unset unset 1"
20
20
 
21
21
  # The runner seals too: a test run under scripts/test.sh never sees the caller's KIT_CONFIG.
22
22
  if [ -n "${KIT_CONFIG:-}" ]; then echo "FAIL: KIT_CONFIG leaked into this test"; fail=1; else echo "ok: no KIT_CONFIG reached this test"; fi
@@ -4,10 +4,13 @@
4
4
  #
5
5
  # A developer shell that has run `load_kit_config` (or set KIT_CONFIG by hand) exports KIT_*,
6
6
  # CCKIT_* and EFFORT_* variables. A test that inherits them reads the developer's project instead
7
- # of its own fixture: KIT_CONFIG=/elsewhere made five suites fail. Source this first, then call
8
- # test_env_seal before the test sets its own variables.
7
+ # of its own fixture: KIT_CONFIG=/elsewhere made five suites fail. CLAUDE_CODE_REMOTE is sealed too:
8
+ # in a cloud session it switches the GitHub transport to REST (#396), and the suites that stub the
9
+ # gh subcommands expect the default. Source this first, then call test_env_seal before the test sets
10
+ # its own variables.
9
11
  #
10
- # test_env_seal unset every exported KIT_* / CCKIT_* / EFFORT_* variable in this shell
12
+ # test_env_seal unset every exported KIT_* / CCKIT_* / EFFORT_* variable (and
13
+ # CLAUDE_CODE_REMOTE) in this shell
11
14
  # test_env_unset_args print `-u NAME` pairs for env(1), one per line (the runner uses these)
12
15
  #
13
16
  # scripts/test.sh scrubs the same set before it runs each test; this covers a test run directly.
@@ -15,7 +18,7 @@
15
18
  # bash 3.2 + zsh compatible.
16
19
 
17
20
  _test_env_names() {
18
- env | sed -n 's/^\(KIT_[A-Za-z0-9_]*\)=.*/\1/p; s/^\(CCKIT_[A-Za-z0-9_]*\)=.*/\1/p; s/^\(EFFORT_[A-Za-z0-9_]*\)=.*/\1/p'
21
+ env | sed -n 's/^\(KIT_[A-Za-z0-9_]*\)=.*/\1/p; s/^\(CCKIT_[A-Za-z0-9_]*\)=.*/\1/p; s/^\(EFFORT_[A-Za-z0-9_]*\)=.*/\1/p; s/^\(CLAUDE_CODE_REMOTE\)=.*/\1/p'
19
22
  }
20
23
 
21
24
  test_env_seal() {
@@ -0,0 +1,120 @@
1
+ #!/usr/bin/env bash
2
+ # shellcheck shell=bash
3
+ # upgrade-report-test.sh — unit tests for scripts/lib/upgrade-report.sh (#448). Runs under bash AND zsh.
4
+ #
5
+ # upgrade_snapshot / upgrade_changes the before/after measurement `cckit init --upgrade` prints
6
+ # json_write_minimal a JSON write that changes as few lines as the change needs
7
+ #
8
+ # The end-to-end use of both is scripts/update-path-test.sh. Everything lives under one mktemp dir.
9
+ # Run: bash scripts/lib/upgrade-report-test.sh
10
+ # errors: strict — a test runner: rc 1 on any failed assertion
11
+ ROOT=$(CDPATH='' cd -- "$(dirname -- "$0")/../.." && pwd)
12
+
13
+ if [ -n "${UPGRADE_REPORT_TEST_INNER:-}" ]; then
14
+ set -u
15
+ sh_name="$UPGRADE_REPORT_TEST_INNER"
16
+ fail=0
17
+ t() { if [ "$2" = "$3" ]; then echo "ok($sh_name): $1"; else echo "FAIL($sh_name): $1 -> got '[$2]' want '[$3]'"; fail=1; fi; }
18
+ # shellcheck source=/dev/null
19
+ . "$ROOT/scripts/lib/upgrade-report.sh"
20
+ tmp="$(mktemp -d)"; trap 'rm -rf "$tmp"' EXIT
21
+ p="$tmp/proj"; mkdir -p "$p/.claude/rules" "$p/.claude/worktrees/other/.claude" "$p/scripts/node_modules/x" "$p/src"
22
+
23
+ # ── snapshot + changes ───────────────────────────────────────────────────────────────────────
24
+ printf 'one\n' > "$p/.claude/rules/a.md"
25
+ printf 'keep\n' > "$p/.claude/rules/with space.md"
26
+ printf 'x\n' > "$p/CLAUDE.md"
27
+ printf 'x\n' > "$p/scripts/run.sh"
28
+ printf 'x\n' > "$p/.claude/worktrees/other/.claude/in-another-checkout.md"
29
+ printf 'x\n' > "$p/scripts/node_modules/x/index.js"
30
+ printf 'x\n' > "$p/src/app.js"
31
+ upgrade_snapshot "$p" > "$tmp/before"
32
+ t "snapshot lists the kit-managed files, by path" "$(cut -f1 "$tmp/before" | tr '\n' '|')" \
33
+ ".claude/rules/a.md|.claude/rules/with space.md|CLAUDE.md|scripts/run.sh|"
34
+ t "snapshot of a directory with none of the paths is empty, rc 0" "$(upgrade_snapshot "$tmp"; echo "rc=$?")" "rc=0"
35
+
36
+ printf 'two\n' > "$p/.claude/rules/a.md" # modified
37
+ printf 'new\n' > "$p/.claude/rules/b.md" # added
38
+ mkdir -p "$p/knowledge"; printf 'n\n' > "$p/knowledge/INDEX.md" # added, a root that was absent
39
+ rm -f "$p/scripts/run.sh" # deleted
40
+ printf 'y\n' > "$p/src/app.js" # outside the managed paths
41
+ printf 'y\n' > "$p/.claude/worktrees/other/.claude/in-another-checkout.md"
42
+ upgrade_snapshot "$p" > "$tmp/after"
43
+ upgrade_changes "$tmp/before" "$tmp/after" > "$tmp/changes"
44
+ t "changes: A / M / D by path, nothing else" "$(tr '\t\n' ' |' < "$tmp/changes")" \
45
+ "M .claude/rules/a.md|A .claude/rules/b.md|A knowledge/INDEX.md|D scripts/run.sh|"
46
+ t "print: heading carries the counts" "$(upgrade_changes_print "$tmp/changes" "Changed on disk" | sed -n 1p)" \
47
+ " Changed on disk (2 added, 1 modified, 1 deleted):"
48
+ t "print: one row per change" "$(upgrade_changes_print "$tmp/changes" "Changed on disk" | sed -n 2p)" " M .claude/rules/a.md"
49
+ : > "$tmp/none"
50
+ t "print: no change says so" "$(upgrade_changes_print "$tmp/none" "Would change" | tr '\n' '|')" \
51
+ " Would change (0 added, 0 modified):| (nothing)|"
52
+
53
+ # ── json_write_minimal ───────────────────────────────────────────────────────────────────────
54
+ # The project's own formatting: inline arrays, its own key order.
55
+ orig() {
56
+ cat > "$tmp/cfg.json" <<'JSON'
57
+ {
58
+ "kitVersion": "0.7.1",
59
+ "roles": ["PM", "Generalist"],
60
+ "review": { "bots": ["one", "two"] },
61
+ "note": "a \"quoted\" kitVersion: 0.7.1",
62
+ "milestones": ["Backlog", "Doing", "Done"]
63
+ }
64
+ JSON
65
+ }
66
+ changed_lines() { diff "$tmp/cfg.orig" "$tmp/cfg.json" | grep -c '^[<>]'; }
67
+
68
+ orig; cp "$tmp/cfg.json" "$tmp/cfg.orig"
69
+ jq '.kitVersion = "0.9.0"' "$tmp/cfg.json" > "$tmp/m.json"
70
+ t "one string key differs -> in-place" "$(json_write_minimal "$tmp/m.json" "$tmp/cfg.json")" "in-place"
71
+ t "…one line removed, one added" "$(changed_lines)" "2"
72
+ t "…the value is the merged one" "$(jq -c . "$tmp/cfg.json")" "$(jq -c '.kitVersion = "0.9.0"' "$tmp/cfg.orig")"
73
+ t "…the merged temp file is consumed" "$([ -e "$tmp/m.json" ] && echo left || echo gone)" "gone"
74
+
75
+ orig
76
+ jq . "$tmp/cfg.json" > "$tmp/m.json"
77
+ t "same value, different formatting -> unchanged" "$(json_write_minimal "$tmp/m.json" "$tmp/cfg.json")" "unchanged"
78
+ t "…the file is byte-identical" "$(cmp -s "$tmp/cfg.orig" "$tmp/cfg.json" && echo same || echo differs)" "same"
79
+
80
+ orig
81
+ jq '.kitVersion = "0.9.0" | .knowledge = {dir: "knowledge"}' "$tmp/cfg.json" > "$tmp/m.json"
82
+ t "a key is added -> rewritten" "$(json_write_minimal "$tmp/m.json" "$tmp/cfg.json")" "rewritten"
83
+ t "…and holds the merged value" "$(jq -r '.knowledge.dir + " " + .kitVersion' "$tmp/cfg.json")" "knowledge 0.9.0"
84
+
85
+ orig
86
+ jq '.review.bots = ["one"]' "$tmp/cfg.json" > "$tmp/m.json"
87
+ t "a nested value differs -> rewritten" "$(json_write_minimal "$tmp/m.json" "$tmp/cfg.json")" "rewritten"
88
+ t "…and holds the merged value" "$(jq -c '.review.bots' "$tmp/cfg.json")" '["one"]'
89
+
90
+ # A value with characters a careless substitution would mangle.
91
+ orig
92
+ jq '.note = "back\\slash $1 & \"q\" /"' "$tmp/cfg.json" > "$tmp/m.json"
93
+ t "a string with quotes, backslash, \$1 and & -> in-place" "$(json_write_minimal "$tmp/m.json" "$tmp/cfg.json")" "in-place"
94
+ t "…and it round-trips" "$(jq -r .note "$tmp/cfg.json")" 'back\slash $1 & "q" /'
95
+ t "…one line removed, one added" "$(changed_lines)" "2"
96
+
97
+ # The first textual match is not the top-level key: the in-place result fails its own check and
98
+ # the write falls back to the whole document. The file never ends up holding a wrong value.
99
+ printf '{\n "inner": { "kitVersion": "nested" },\n "kitVersion": "0.7.1"\n}\n' > "$tmp/cfg.json"
100
+ jq '.kitVersion = "0.9.0"' "$tmp/cfg.json" > "$tmp/m.json"
101
+ t "a nested key of the same name comes first -> rewritten, not mis-edited" "$(json_write_minimal "$tmp/m.json" "$tmp/cfg.json")" "rewritten"
102
+ t "…both values are right" "$(jq -r '.inner.kitVersion + " " + .kitVersion' "$tmp/cfg.json")" "nested 0.9.0"
103
+
104
+ rm -f "$tmp/cfg.json"
105
+ printf '{"a":1}\n' > "$tmp/m.json"
106
+ t "no file yet -> rewritten (created)" "$(json_write_minimal "$tmp/m.json" "$tmp/cfg.json")" "rewritten"
107
+ t "…created with the merged value" "$(jq -c . "$tmp/cfg.json")" '{"a":1}'
108
+
109
+ [ "$fail" = "0" ] && echo "ALL OK($sh_name)" || { echo "upgrade-report($sh_name): FAILURES"; exit 1; }
110
+ exit 0
111
+ fi
112
+
113
+ command -v jq >/dev/null 2>&1 || { echo "upgrade-report-test: jq absent — skipping"; exit 0; }
114
+ rc=0
115
+ for sh in bash zsh; do
116
+ command -v "$sh" >/dev/null 2>&1 || { echo "--- $sh --- (not installed, skipped)"; continue; }
117
+ echo "--- $sh ---"
118
+ UPGRADE_REPORT_TEST_INNER="$sh" "$sh" "$0" || rc=1
119
+ done
120
+ exit "$rc"