@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,337 @@
1
+ #!/bin/sh
2
+ # effort-plan-test.sh — self-test for effort-plan.sh, in four parts:
3
+ # 1. the ctx weight scale (#277), under bash AND zsh: S=1 M=2 L=4 XL=8; `?` (no ctx: label) weighs
4
+ # 2 and is explained by the plan header, any other value weighs 2 and warns on stderr.
5
+ # 2. the open-effort read and the "next startable effort per flow" pick that `cckit status`
6
+ # prints (E241.4), under bash AND zsh (kit-status.sh reads them in both); `effort_plan` itself
7
+ # is bash-only and gets one bash smoke case.
8
+ # 3. where `cckit effort plan` reads its rows from (#382): the optional local source named by
9
+ # `effort.planSource`, the fallback to GitHub when that source fails or prints nothing, and
10
+ # the `source:` line that says which one the plan was built from.
11
+ # 4. `effort_plan` end to end on the weights: an XL effort fills a session, `?` is legend-explained.
12
+ # Hermetic: every part stubs gh (the effort list as the JSON `gh issue list --json` returns, each
13
+ # effort's blocked_by as the JSON the dependency API returns), so no network is touched.
14
+ # Run: bash scripts/lib/effort-plan-test.sh
15
+ # errors: strict — a test runner: rc 1 on any failed assertion
16
+
17
+ dir=$(CDPATH='' cd -- "$(dirname -- "$0")" && pwd)
18
+
19
+ if [ -n "${EP_TEST_INNER:-}" ]; then
20
+ fail=0
21
+ eq() { if [ "$2" = "$3" ]; then :; else echo "FAIL($EP_TEST_INNER): $1 -> got '[$2]' want '[$3]'"; fail=1; fi; }
22
+ has() { case "$2" in *"$3"*) : ;; *) echo "FAIL($EP_TEST_INNER): $1 -> '$2' lacks '$3'"; fail=1 ;; esac; }
23
+ no() { case "$2" in *"$3"*) echo "FAIL($EP_TEST_INNER): $1 -> '$2' should not contain '$3'"; fail=1 ;; *) : ;; esac; }
24
+
25
+ # shellcheck source=/dev/null
26
+ . "$dir/effort-plan.sh"
27
+
28
+ # ── 1. the ctx weight scale (no gh, no jq) ──────────────────────────────────────────────────
29
+ eq "weight S" "$(_ep_weight S)" "1"
30
+ eq "weight M" "$(_ep_weight M)" "2"
31
+ eq "weight L" "$(_ep_weight L)" "4"
32
+ eq "weight XL" "$(_ep_weight XL)" "8"
33
+ for c in S M L XL; do eq "weight $c is quiet" "$(_ep_weight "$c" 2>&1 >/dev/null)" ""; done
34
+
35
+ # no label at all: weighs the default, silently here — the plan header carries the legend.
36
+ eq "weight ? (unlabeled)" "$(_ep_weight '?' 2>/dev/null)" "2"
37
+ eq "weight ? is quiet" "$(_ep_weight '?' 2>&1 >/dev/null)" ""
38
+ # a value outside the scale: still the default weight, and stderr names the value + the issue.
39
+ eq "weight XXL falls back to 2" "$(_ep_weight XXL 2>/dev/null)" "2"
40
+ has "weight XXL warns" "$(_ep_weight XXL 41 2>&1 >/dev/null)" "ctx:XXL"
41
+ has "the warning names the issue" "$(_ep_weight XXL 41 2>&1 >/dev/null)" "#41"
42
+ has "the warning names the weight used" "$(_ep_weight XXL 41 2>&1 >/dev/null)" "weighed 2"
43
+ has "lowercase xl is not XL" "$(_ep_weight xl 7 2>&1 >/dev/null)" "ctx:xl"
44
+
45
+ command -v jq >/dev/null 2>&1 || { echo " (jq absent — skipping the effort-plan row tests)"; exit "$fail"; }
46
+
47
+ # ── 2. the open-effort read and the next-per-flow pick ──────────────────────────────────────
48
+ tmp="$(mktemp -d)"
49
+ stub="$tmp/bin"; mkdir -p "$stub" "$tmp/deps"
50
+ # Stub gh: `issue list` -> $GH_EFFORTS (a JSON array file); `api …/issues/<N>/dependencies/blocked_by`
51
+ # -> $GH_DEPS/<N>.json, or [] when the effort has no fixture. GH_FAIL=1 fails every call.
52
+ cat > "$stub/gh" <<'SH'
53
+ #!/bin/sh
54
+ [ -z "${GH_FAIL:-}" ] || exit 1
55
+ case "$1 $2" in
56
+ "issue list") cat "$GH_EFFORTS" ;;
57
+ "api repos/"*)
58
+ n="${2%/dependencies/blocked_by}"; n="${n##*/}"
59
+ if [ -f "$GH_DEPS/$n.json" ]; then cat "$GH_DEPS/$n.json"; else echo '[]'; fi ;;
60
+ *) echo '[]' ;;
61
+ esac
62
+ SH
63
+ chmod +x "$stub/gh"
64
+ GH_EFFORTS="$tmp/efforts.json"; GH_DEPS="$tmp/deps"; export GH_EFFORTS GH_DEPS
65
+ PATH="$stub:$PATH"; export PATH
66
+
67
+ col() { awk -F'\t' -v f="$1" -v c="$2" '$1==f{print $c}'; } # col <flow> <column> < next rows
68
+
69
+ # ── two flows, one effort blocked by another OPEN effort in its flow ────────────────────────
70
+ # core: 10 (p1) and 11 (p1, blocked_by OPEN 10). docs: 20 (unlabelled priority).
71
+ cat > "$GH_EFFORTS" <<'JSON'
72
+ [ {"number":20,"title":"[Effort] 20 · [Docs] cadence page","labels":[{"name":"effort"},{"name":"flow:docs"},{"name":"ctx:S"}]},
73
+ {"number":11,"title":"[Effort] 11 · [Core] second thing","labels":[{"name":"effort"},{"name":"flow:core"},{"name":"ctx:L"},{"name":"priority:p1"}]},
74
+ {"number":10,"title":"[Effort] 10 · [Core] first thing","labels":[{"name":"effort"},{"name":"flow:core"},{"name":"ctx:M"},{"name":"priority:p1"}]} ]
75
+ JSON
76
+ echo '[{"number":10,"state":"open"}]' > "$GH_DEPS/11.json"
77
+
78
+ open_rows="$(effort_open_rows o/r)"; rc=$?
79
+ eq "open rows: rc 0" "$rc" "0"
80
+ eq "open rows: one row per open effort" "$(printf '%s\n' "$open_rows" | grep -c .)" "3"
81
+ eq "open rows: seven fields, none blank" "$(printf '%s\n' "$open_rows" | awk -F'\t' 'NF!=7{bad=1} {for(i=1;i<=NF;i++) if($i=="") bad=1} END{print bad+0}')" "0"
82
+ eq "open rows: 11 lists its blocker" "$(printf '%s\n' "$open_rows" | awk -F'\t' '$1==11{print $5"/"$6}')" "10/10"
83
+ eq "open rows: no blocker reads -" "$(printf '%s\n' "$open_rows" | awk -F'\t' '$1==10{print $5"/"$6}')" "-/-"
84
+ eq "open rows: missing priority reads -" "$(printf '%s\n' "$open_rows" | awk -F'\t' '$1==20{print $4}')" "-"
85
+
86
+ rows="$(effort_next_rows o/r)"; rc=$?
87
+ eq "next: rc 0" "$rc" "0"
88
+ eq "next: exactly one row per flow" "$(printf '%s\n' "$rows" | grep -c .)" "2"
89
+ eq "next: flows are sorted" "$(printf '%s\n' "$rows" | cut -f1 | tr '\n' ' ')" "core docs "
90
+ eq "next: core offers the unblocked one" "$(printf '%s\n' "$rows" | col core 2)" "10"
91
+ eq "next: the blocked effort is never named" "$(printf '%s\n' "$rows" | cut -f2 | grep -c '^11$')" "0"
92
+ eq "next: core counts one waiting" "$(printf '%s\n' "$rows" | col core 5)" "1"
93
+ eq "next: docs offers its only effort" "$(printf '%s\n' "$rows" | col docs 2)" "20"
94
+ eq "next: the ctx rides along" "$(printf '%s\n' "$rows" | col core 3)" "M"
95
+ eq "next: title drops the prefix and tag" "$(printf '%s\n' "$rows" | col core 4)" "first thing"
96
+
97
+ # ── a CLOSED blocker does not block ─────────────────────────────────────────────────────────
98
+ # 10 is gone from the open list (closed); 11 still carries the edge, now pointing at a closed issue.
99
+ cat > "$GH_EFFORTS" <<'JSON'
100
+ [ {"number":11,"title":"[Effort] 11 · [Core] second thing","labels":[{"name":"effort"},{"name":"flow:core"},{"name":"ctx:L"}]} ]
101
+ JSON
102
+ echo '[{"number":10,"state":"closed"}]' > "$GH_DEPS/11.json"
103
+ rows="$(effort_next_rows o/r)"
104
+ eq "closed blocker: the effort is startable" "$(printf '%s\n' "$rows" | col core 2)" "11"
105
+ eq "closed blocker: nothing is waiting" "$(printf '%s\n' "$rows" | col core 5)" "0"
106
+ eq "closed blocker: still listed as a blocker" "$(effort_open_rows o/r | cut -f5,6 | tr '\t' '/')" "10/-"
107
+
108
+ # ── an OPEN blocker in ANOTHER flow blocks ──────────────────────────────────────────────────
109
+ # core 11 is blocked_by docs 20 (open). core has no other effort, so the flow reports none startable.
110
+ cat > "$GH_EFFORTS" <<'JSON'
111
+ [ {"number":20,"title":"[Effort] 20 · [Docs] cadence page","labels":[{"name":"effort"},{"name":"flow:docs"},{"name":"ctx:S"}]},
112
+ {"number":11,"title":"[Effort] 11 · [Core] second thing","labels":[{"name":"effort"},{"name":"flow:core"},{"name":"ctx:L"}]} ]
113
+ JSON
114
+ echo '[{"number":20,"state":"open"}]' > "$GH_DEPS/11.json"
115
+ rows="$(effort_next_rows o/r)"
116
+ eq "cross-flow blocker: core keeps its row" "$(printf '%s\n' "$rows" | grep -c '^core')" "1"
117
+ eq "cross-flow blocker: core names no effort" "$(printf '%s\n' "$rows" | col core 2)" "-"
118
+ eq "cross-flow blocker: core counts it waiting" "$(printf '%s\n' "$rows" | col core 5)" "1"
119
+ eq "cross-flow blocker: docs is unaffected" "$(printf '%s\n' "$rows" | col docs 2)" "20"
120
+
121
+ # ── an OPEN blocker that is not an effort at all (a plain issue) blocks too ──────────────────
122
+ echo '[{"number":999,"state":"open"}]' > "$GH_DEPS/11.json"
123
+ eq "plain-issue blocker: core names no effort" "$(effort_next_rows o/r | col core 2)" "-"
124
+ rm -f "$GH_DEPS/11.json"
125
+
126
+ # ── the pick is pure: priority first (p0 → p3, unlabelled last), then the lowest number ──────
127
+ pick() { printf '%b' "$1" | effort_next_pick | cut -f2; }
128
+ eq "pick: p0 beats p2" "$(pick '7\tcore\tM\tp2\t-\t-\ta\n9\tcore\tM\tp0\t-\t-\tb\n')" "9"
129
+ eq "pick: a label beats no label" "$(pick '3\tcore\tM\t-\t-\t-\ta\n9\tcore\tM\tp3\t-\t-\tb\n')" "9"
130
+ eq "pick: a tie takes the lowest number" "$(pick '9\tcore\tM\tp1\t-\t-\ta\n4\tcore\tM\tp1\t-\t-\tb\n')" "4"
131
+ eq "pick: a blocked p0 never outranks a free p3" \
132
+ "$(pick '1\tcore\tM\tp0\t5\t5\ta\n2\tcore\tM\tp3\t-\t-\tb\n')" "2"
133
+ eq "pick: no input, no rows" "$(printf '' | effort_next_pick | grep -c . )" "0"
134
+
135
+ # ── empty and unreadable are different answers ──────────────────────────────────────────────
136
+ echo '[]' > "$GH_EFFORTS"
137
+ rows="$(effort_next_rows o/r)"; rc=$?
138
+ eq "no open effort: rc 0" "$rc" "0"
139
+ eq "no open effort: no rows" "$rows" ""
140
+ rows="$(GH_FAIL=1 effort_next_rows o/r)"; rc=$?
141
+ eq "gh fails: rc is non-zero" "$([ "$rc" -ne 0 ] && echo yes || echo no)" "yes"
142
+ eq "gh fails: no rows" "$rows" ""
143
+ effort_next_rows "" >/dev/null 2>&1; rc=$?
144
+ eq "no repo: rc is non-zero" "$([ "$rc" -ne 0 ] && echo yes || echo no)" "yes"
145
+
146
+ # ── effort_plan (bash-only) still prints its session plan from the shared read ───────────────
147
+ if [ "$EP_TEST_INNER" = "bash" ]; then
148
+ cat > "$GH_EFFORTS" <<'JSON'
149
+ [ {"number":11,"title":"[Effort] 11 · [Core] second thing","labels":[{"name":"effort"},{"name":"flow:core"},{"name":"ctx:L"}]},
150
+ {"number":10,"title":"[Effort] 10 · [Core] first thing","labels":[{"name":"effort"},{"name":"flow:core"},{"name":"ctx:M"}]} ]
151
+ JSON
152
+ echo '[{"number":10,"state":"open"}]' > "$GH_DEPS/11.json"
153
+ plan="$(EFFORT_REPO=o/r effort_plan 2>&1)"; rc=$?
154
+ eq "plan: rc 0" "$rc" "0"
155
+ has "plan: names the flow" "$plan" "Flow: core"
156
+ has "plan: lists the root effort" "$plan" "#10 [M ] first thing"
157
+ has "plan: the dependent shows its blocker" "$plan" "second thing (after #10) → delegate subs"
158
+ eq "plan: the blocker is ordered first" \
159
+ "$(printf '%s\n' "$plan" | grep -E '^ +#1[01] ' | awk '{print $1}' | tr '\n' ' ')" "#10 #11 "
160
+ eq "plan: a blocker and its dependent do not share a session" \
161
+ "$(printf '%s\n' "$plan" | grep -c 'Session ')" "2"
162
+ echo '[]' > "$GH_EFFORTS"
163
+ plan="$(EFFORT_REPO=o/r effort_plan 2>&1)"; rc=$?
164
+ eq "plan: no efforts is rc 0" "$rc" "0"
165
+ has "plan: no efforts says so" "$plan" "no open efforts found"
166
+ plan="$(GH_FAIL=1 EFFORT_REPO=o/r effort_plan 2>&1)"; rc=$?
167
+ eq "plan: a failed query is rc 1" "$rc" "1"
168
+ has "plan: a failed query says so" "$plan" "gh query failed"
169
+ fi
170
+
171
+ rm -rf "$tmp"
172
+ if [ "$fail" -eq 0 ]; then echo "PASS($EP_TEST_INNER): effort-plan rows + next-per-flow pick"; fi
173
+ exit "$fail"
174
+ fi
175
+
176
+ fail=0
177
+ for sh in bash zsh; do
178
+ command -v "$sh" >/dev/null 2>&1 || { echo "skip: $sh not installed"; continue; }
179
+ if EP_TEST_INNER="$sh" "$sh" "$0"; then echo "ok: effort-plan weights + rows under $sh"; else fail=1; fi
180
+ done
181
+
182
+ # ── 3. the plan source (#382) ─────────────────────────────────────────────────────────────────
183
+ ROOT="$(cd "$(dirname "$0")/../.." && pwd)"
184
+ LIB="$ROOT/scripts/lib"
185
+ t() { if [ "$2" = "$3" ]; then echo "ok: $1"; else echo "FAIL: $1 -> got '[$2]' want '[$3]'"; fail=1; fi; }
186
+ has() { case "$2" in *"$3"*) echo "ok: $1" ;; *) echo "FAIL: $1 -> output lacks '$3'"; echo "$2" | sed 's/^/ | /'; fail=1 ;; esac; }
187
+ lacks() { case "$2" in *"$3"*) echo "FAIL: $1 -> output has '$3'"; fail=1 ;; *) echo "ok: $1" ;; esac; }
188
+
189
+ tmp="$(mktemp -d)"; tmp2=""; trap 'rm -rf "$tmp" "$tmp2"' EXIT
190
+ mkdir -p "$tmp/bin" "$tmp/proj/tools"
191
+ GH_LOG="$tmp/gh.log"
192
+
193
+ # Stub gh: the listing prints the JSON `gh issue list --json number,title,labels` returns; blocked_by
194
+ # answers per issue with the JSON the dependency API returns. Every call is logged.
195
+ cat > "$tmp/bin/gh" <<'STUB'
196
+ #!/usr/bin/env bash
197
+ echo "gh $*" >> "$GH_LOG"
198
+ case "$1 $2" in
199
+ "issue list") cat <<'JSON'
200
+ [ {"number":11,"title":"[Effort] 11 · [Core] gh root","labels":[{"name":"effort"},{"name":"flow:Core"},{"name":"ctx:S"}]},
201
+ {"number":12,"title":"[Effort] 12 · [Core] gh leaf","labels":[{"name":"effort"},{"name":"flow:Core"},{"name":"ctx:M"}]} ]
202
+ JSON
203
+ ;;
204
+ "api "*) case "$2" in */issues/12/dependencies/blocked_by) echo '[{"number":11,"state":"open"}]' ;; *) echo '[]' ;; esac ;;
205
+ esac
206
+ STUB
207
+ chmod +x "$tmp/bin/gh"
208
+
209
+ mk() { printf '%s\n' "$2" > "$tmp/proj/tools/$1"; chmod +x "$tmp/proj/tools/$1"; }
210
+ mk good.sh '#!/usr/bin/env bash
211
+ echo "# age: 2h"
212
+ printf "21\tDocs\tL\t[Effort] 21 · [Docs] stub root\n"
213
+ printf "22\tDocs\tS\t[Effort] 22 · [Docs] stub leaf\t21\n"'
214
+ mk noage.sh '#!/usr/bin/env bash
215
+ printf "31\tDocs\tS\tstub only\n"'
216
+ mk fail.sh '#!/usr/bin/env bash
217
+ printf "41\tDocs\tS\tshould not appear\n"
218
+ exit 3'
219
+ mk empty.sh '#!/usr/bin/env bash
220
+ exit 0'
221
+ mk args.sh '#!/usr/bin/env bash
222
+ printf "51\tDocs\tS\trepo=%s cwd=%s\n" "$1" "$(basename "$PWD")"'
223
+ mk blank.sh '#!/usr/bin/env bash
224
+ printf "61\t\t\tempty flow and ctx\t\n"'
225
+ printf '{"github":{"repo":"o/r"},"effort":{"planSource":"tools/good.sh"}}' > "$tmp/proj/cckit.config.json"
226
+
227
+ # plan [VAR=value …] — run effort_plan in a clean shell; stdout+stderr captured together.
228
+ plan() {
229
+ : > "$GH_LOG"
230
+ ( cd "$tmp/proj" && env -u KIT_CONFIG -u EFFORT_PLAN_SOURCE -u KIT_EFFORT_PLAN_SOURCE \
231
+ PATH="$tmp/bin:$PATH" GH_LOG="$GH_LOG" EFFORT_REPO="o/r" "$@" \
232
+ bash -c "source '$LIB/config-path.sh'; source '$LIB/effort-plan.sh'; effort_plan" 2>&1 )
233
+ }
234
+ # Count calls (one logged line each).
235
+ gh_calls() { grep -c '^gh ' "$GH_LOG" | tr -d ' '; }
236
+
237
+ # ── 1. a working local source: its rows, its blockers, no gh, source + age named ───────────────
238
+ out="$(plan KIT_EFFORT_PLAN_SOURCE=tools/good.sh)"
239
+ has "stub rows are planned" "$out" "#21 "
240
+ has "stub second row is planned" "$out" "stub leaf"
241
+ has "stub blockers are honored" "$out" "(after #21)"
242
+ lacks "GitHub rows are absent" "$out" "gh root"
243
+ t "gh is never called" "$(gh_calls)" "0"
244
+ has "output names the stub as source" "$out" "source: planSource tools/good.sh"
245
+ has "output carries the reported age" "$out" "age 2h"
246
+ # the blocker forces a second session even though L(4)+S(1) alone would already overflow budget 4;
247
+ # prove ordering instead: the blocker is listed before its dependent.
248
+ t "blocker is ordered before its dependent" \
249
+ "$(printf '%s\n' "$out" | grep -oE '#2[12] ' | tr -d '\n')" "#21 #22 "
250
+
251
+ out="$(plan KIT_EFFORT_PLAN_SOURCE=tools/noage.sh)"
252
+ has "a source with no age is still named" "$out" "source: planSource tools/noage.sh"
253
+ lacks "no age is invented" "$out" "age "
254
+
255
+ out="$(plan EFFORT_PLAN_SOURCE=tools/noage.sh KIT_EFFORT_PLAN_SOURCE=tools/good.sh)"
256
+ has "EFFORT_PLAN_SOURCE wins over the config value" "$out" "source: planSource tools/noage.sh"
257
+
258
+ out="$(plan KIT_EFFORT_PLAN_SOURCE="$tmp/proj/tools/args.sh")"
259
+ has "source receives the repo as \$1" "$out" "repo=o/r"
260
+ has "relative source runs from the project root" "$out" "cwd=proj"
261
+
262
+ out="$(plan KIT_EFFORT_PLAN_SOURCE=tools/blank.sh)"
263
+ has "empty flow and ctx columns keep the title in place" "$out" "empty flow and ctx"
264
+ has "empty ctx renders as unknown" "$out" "[? ]"
265
+
266
+ # ── 2. a source that fails, prints nothing, or is not executable falls back to GitHub ──────────
267
+ out="$(plan KIT_EFFORT_PLAN_SOURCE=tools/fail.sh)"
268
+ has "failing source: GitHub rows planned" "$out" "gh root"
269
+ has "failing source: GitHub blockers kept" "$out" "(after #11)"
270
+ lacks "failing source: its rows are dropped" "$out" "should not appear"
271
+ has "failing source: GitHub named" "$out" "source: GitHub (o/r)"
272
+ has "failing source: the fallback is said" "$out" "planSource tools/fail.sh failed (exit 3)"
273
+
274
+ out="$(plan KIT_EFFORT_PLAN_SOURCE=tools/empty.sh)"
275
+ has "empty source: GitHub rows planned" "$out" "gh root"
276
+ has "empty source: GitHub named" "$out" "source: GitHub (o/r)"
277
+ has "empty source: the fallback is said" "$out" "planSource tools/empty.sh printed no rows"
278
+
279
+ out="$(plan KIT_EFFORT_PLAN_SOURCE=tools/missing.sh)"
280
+ has "missing source: GitHub rows planned" "$out" "gh root"
281
+ has "missing source: the fallback is said" "$out" "planSource tools/missing.sh is not executable"
282
+
283
+ # ── 3. planSource unset: the GitHub plan, with the source named and no fallback note ───────────
284
+ out="$(plan)"
285
+ has "unset: GitHub rows planned" "$out" "gh leaf"
286
+ has "unset: GitHub named" "$out" "source: GitHub (o/r)"
287
+ lacks "unset: no fallback note" "$out" "planSource"
288
+ t "unset: one listing + one blocked_by call per effort" "$(gh_calls)" "3"
289
+
290
+ # ── 4. load_kit_config exports the key; the exported value drives the plan end to end ──────────
291
+ if command -v jq >/dev/null 2>&1; then
292
+ out="$( : > "$GH_LOG"; cd "$tmp/proj" && env -u KIT_CONFIG -u EFFORT_PLAN_SOURCE -u KIT_EFFORT_PLAN_SOURCE -u EFFORT_REPO \
293
+ PATH="$tmp/bin:$PATH" GH_LOG="$GH_LOG" \
294
+ bash -c "source '$LIB/kit-config.sh'; load_kit_config >/dev/null 2>&1; source '$LIB/effort-plan.sh'; effort_plan" 2>&1 )"
295
+ has "config key effort.planSource reaches the plan" "$out" "source: planSource tools/good.sh"
296
+ t "config-driven local plan calls no gh" "$(gh_calls)" "0"
297
+ fi
298
+
299
+ # ── 4. effort_plan end to end on the weights (#277) ───────────────────────────────────────────
300
+ # effort_plan end to end against a stub gh: an XL effort fills a session of its own (weight 8, not
301
+ # 2), and an effort with no ctx: label shows as `?` with the header saying what `?` weighs.
302
+ if command -v jq >/dev/null 2>&1 && command -v bash >/dev/null 2>&1; then
303
+ tmp2="$(mktemp -d)"
304
+ mkdir -p "$tmp2/bin"
305
+ cat > "$tmp2/bin/gh" <<'SH'
306
+ #!/bin/sh
307
+ case "$1 $2" in
308
+ "issue list") cat <<'JSON'
309
+ [ {"number":1,"title":"[Effort] 1 · big one","labels":[{"name":"effort"},{"name":"flow:core"},{"name":"ctx:XL"}]},
310
+ {"number":2,"title":"[Effort] 2 · unsized one","labels":[{"name":"effort"},{"name":"flow:core"}]},
311
+ {"number":3,"title":"[Effort] 3 · small one","labels":[{"name":"effort"},{"name":"flow:core"},{"name":"ctx:S"}]} ]
312
+ JSON
313
+ ;;
314
+ *) echo '[]' ;;
315
+ esac
316
+ SH
317
+ chmod +x "$tmp2/bin/gh"
318
+ out="$(PATH="$tmp2/bin:$PATH" KIT_REPO=o/r EFFORT_REPO=o/r KIT_SESSION_BUDGET=4 \
319
+ bash -c ". '$dir/effort-plan.sh'; effort_plan" 2>&1)"
320
+ chk() { if [ -n "$(printf '%s\n' "$out" | grep -E "$2")" ]; then echo "ok: $1"; else echo "FAIL: $1 (no /$2/ in plan output)"; fail=1; fi; }
321
+ chk "the header explains the unlabeled weight" '\? = no ctx: label, weighed 2'
322
+ chk "an unlabeled effort renders as ?" '#2 +\[\? \] unsized one'
323
+ chk "an XL effort is flagged to delegate" '#1 +\[XL\] big one.*delegate subs'
324
+ # XL (8) overflows the budget of 4 on its own, so the ? effort (2) opens Session 2 — were XL
325
+ # weighed 2, XL + ? would share Session 1 and the S effort would open Session 2.
326
+ t_sess="$(printf '%s\n' "$out" | awk '/Session/{s=$2} /#2 /{print s}' | tr -d ':')"
327
+ if [ "$t_sess" = "2" ]; then echo "ok: XL weighs a whole session (next effort opens Session 2)"
328
+ else echo "FAIL: effort after an XL landed in Session '[$t_sess]', want '[2]'"; fail=1; fi
329
+ s3="$(printf '%s\n' "$out" | awk '/Session/{s=$2} /#3 /{print s}' | tr -d ':')"
330
+ if [ "$s3" = "2" ]; then echo "ok: ? (2) + S (1) share Session 2"
331
+ else echo "FAIL: S effort landed in Session '[$s3]', want '[2]'"; fail=1; fi
332
+ else
333
+ echo "skip: jq/bash missing — effort_plan run not exercised"
334
+ fi
335
+
336
+ [ "$fail" -eq 0 ] && echo "ALL OK (effort-plan)" || echo "effort-plan: FAILURES"
337
+ exit "$fail"
@@ -1,7 +1,9 @@
1
1
  #!/usr/bin/env bash
2
2
  # effort-plan.sh — the session-fit view (`kit effort plan` when the project ships the kit CLI).
3
3
  #
4
- # Reads the open efforts (label:effort), groups them by their `flow:` tag, orders each flow by the
4
+ # Reads the open efforts — from GitHub (label:effort), or from the local executable named by
5
+ # `effort.planSource` when one is configured (falling back to GitHub when it fails or prints
6
+ # nothing; the output names the source used) — groups them by their `flow:` tag, orders each flow by the
5
7
  # native `blocked_by` edges, and packs the efforts into session-sized batches under a context budget.
6
8
  # Answers "which efforts fit in one session before the context window fills, and in what order?".
7
9
  #
@@ -11,37 +13,211 @@
11
13
  # in its own context; only a summary returns), which is the real lever that widens a session
12
14
  # (rules/agent-execution-routing.md).
13
15
  #
14
- # Requires: gh, jq. bash 3.2 (no associative arrays — parallel indexed arrays + linear scan; N small).
15
- # errors: strict — refuses to plan without gh + jq
16
+ # Requires: gh, jq for the GitHub read; a local source that answers needs neither. bash 3.2 (no
17
+ # associative arrays — parallel indexed arrays + linear scan; N small).
18
+ # `effort_plan` and the `_ep_*` plan-source helpers are bash-only; effort_open_rows /
19
+ # effort_next_pick / effort_next_rows / effort_cadence_md hold no arrays and run under zsh too,
20
+ # because `cckit status` reads them (scripts/lib/kit-status.sh). Those four always read GitHub —
21
+ # `effort.planSource` feeds `effort_plan` only.
22
+ # errors: strict — refuses to plan from GitHub without gh + jq
16
23
 
17
24
  EFFORT_REPO="${EFFORT_REPO:-${KIT_REPO:-}}"
18
25
 
19
- _ep_weight() { case "$1" in S) echo 1 ;; M) echo 2 ;; L) echo 4 ;; XL) echo 8 ;; *) echo 2 ;; esac; }
26
+ # _ep_weight <ctx> [issue] — session weight of a ctx: value. Anything outside S|M|L|XL weighs
27
+ # EP_UNSIZED_WEIGHT (2), and never silently: `?` (no ctx: label at all) is explained by the legend in
28
+ # the plan header, and any other value (ctx:XXL, ctx:xl) warns on stderr naming the value and issue.
29
+ # The fallback used to be a bare `*) echo 2`, which planned a mislabeled effort as an M.
30
+ EP_UNSIZED_WEIGHT=2
31
+ _ep_weight() {
32
+ case "$1" in
33
+ S) echo 1 ;; M) echo 2 ;; L) echo 4 ;; XL) echo 8 ;;
34
+ '?'|'') echo "$EP_UNSIZED_WEIGHT" ;;
35
+ *) echo "⚠ effort plan: ${2:+#$2 }carries ctx:$1, which is not S|M|L|XL — weighed $EP_UNSIZED_WEIGHT" >&2
36
+ echo "$EP_UNSIZED_WEIGHT" ;;
37
+ esac
38
+ }
39
+
40
+ # effort_open_rows [repo] — one TSV row per OPEN effort (label:effort), the single read both
41
+ # `effort_plan` (its GitHub source, via _ep_rows_github) and `cckit status` build on:
42
+ #
43
+ # number<TAB>flow<TAB>ctx<TAB>priority<TAB>blockers<TAB>open-blockers<TAB>title
44
+ #
45
+ # `blockers` is every native `blocked_by` number, `open-blockers` only the ones whose issue is still
46
+ # OPEN; each is a csv, or `-` when empty (a tab-separated `read` collapses an empty field, so no
47
+ # column is ever left blank). flow falls back to `—`, ctx to `?`, priority to `-`.
48
+ # rc 1 when gh/jq are absent, no repo is known, or the issue query fails — "could not read" must not
49
+ # look like "no efforts". No open effort is rc 0 with no rows. A blocked_by read that fails for one
50
+ # effort degrades to `-` for that effort (the dependency API is optional on older GitHub hosts).
51
+ # Costs one `gh issue list` plus one `gh api` per open effort.
52
+ effort_open_rows() {
53
+ local repo="${1:-${EFFORT_REPO:-${KIT_REPO:-}}}" raw n f c p t b tab
54
+ tab="$(printf '\t')"
55
+ command -v gh >/dev/null 2>&1 && command -v jq >/dev/null 2>&1 || return 1
56
+ [ -n "$repo" ] || return 1
57
+ raw="$(gh issue list --repo "$repo" --label effort --state open --limit 100 --json number,title,labels 2>/dev/null)" || return 1
58
+ raw="$(printf '%s' "$raw" | jq -r '.[] | [ (.number|tostring),
59
+ ([.labels[].name|select(startswith("flow:"))|ltrimstr("flow:")]|first // "—"),
60
+ ([.labels[].name|select(startswith("ctx:"))|ltrimstr("ctx:")]|first // "?"),
61
+ ([.labels[].name|select(startswith("priority:"))|ltrimstr("priority:")]|first // "-"),
62
+ .title ] | @tsv' 2>/dev/null)" || return 1
63
+ [ -n "$raw" ] || return 0
64
+ while IFS="$tab" read -r n f c p t; do
65
+ [ -n "$n" ] || continue
66
+ b="$(gh api "repos/$repo/issues/$n/dependencies/blocked_by" 2>/dev/null \
67
+ | jq -r '[ ([.[].number|tostring]|join(",")),
68
+ ([.[]|select((.state // "open")|ascii_downcase == "open")|.number|tostring]|join(",")) ]
69
+ | map(if . == "" then "-" else . end) | @tsv' 2>/dev/null)"
70
+ [ -n "$b" ] || b="-$tab-"
71
+ printf '%s\t%s\t%s\t%s\t%s\t%s\n' "$n" "$f" "$c" "$p" "$b" "$t"
72
+ done <<EOT
73
+ $raw
74
+ EOT
75
+ }
76
+
77
+ # effort_next_pick — pure. stdin: `effort_open_rows` rows; stdout: ONE row per flow, sorted by flow:
78
+ #
79
+ # flow<TAB>number<TAB>ctx<TAB>title<TAB>waiting
80
+ #
81
+ # `number` is the next effort that can start: among the flow's efforts with NO open blocker, the
82
+ # most urgent `priority:pN` (p0 → p3, unlabeled last), then the lowest issue number. `waiting` counts
83
+ # the flow's efforts that still have an open blocker. A flow where every effort is blocked keeps its
84
+ # row with `-` for number/ctx/title, so a stuck flow is visible instead of silently absent.
85
+ #
86
+ # What blocks: ANY open blocker — an effort in the same flow, an effort in another flow, or a plain
87
+ # issue. A closed blocker does not. (`effort_plan` orders a flow by its in-flow blockers only; that
88
+ # is a layout question. "Can this start now" is stricter: the work it waits on is not done.)
89
+ # The title drops the `[Effort] N · ` prefix and a leading `[Flow] ` tag, as `effort_plan` does.
90
+ effort_next_pick() {
91
+ awk -F'\t' '
92
+ function rank(p) { return (p ~ /^p[0-3]$/) ? substr(p, 2) + 0 : 9 }
93
+ NF >= 7 {
94
+ f = $2; seen[f] = 1
95
+ if ($6 != "-") { waiting[f]++; next }
96
+ r = rank($4); n = $1 + 0
97
+ if (!(f in bn) || r < br[f] || (r == br[f] && n < bn[f])) {
98
+ t = $7; sub(/^\[Effort( [0-9]+)?\] [0-9]+ · ?/, "", t); sub(/^\[[A-Za-z]+\] /, "", t)
99
+ bn[f] = n; br[f] = r; bc[f] = $3; bt[f] = t
100
+ }
101
+ }
102
+ END {
103
+ for (f in seen) {
104
+ if (f in bn) printf "%s\t%s\t%s\t%s\t%d\n", f, bn[f], bc[f], bt[f], waiting[f] + 0
105
+ else printf "%s\t-\t-\t-\t%d\n", f, waiting[f] + 0
106
+ }
107
+ }' | LC_ALL=C sort -t "$(printf '\t')" -k1,1
108
+ }
109
+
110
+ # effort_next_rows [repo] — the next startable effort per flow, from live state. rc 1 when the
111
+ # efforts could not be read (see effort_open_rows); no rows + rc 0 when no open effort exists.
112
+ effort_next_rows() {
113
+ local rows
114
+ rows="$(effort_open_rows "${1:-}")" || return 1
115
+ [ -n "$rows" ] || return 0
116
+ printf '%s\n' "$rows" | effort_next_pick
117
+ }
118
+
119
+ # effort_cadence_md — the weekly cadence as ONE markdown line. `cckit next` and `cckit status` both
120
+ # print this function's output, so the two verbs cannot drift apart on what the cadence is.
121
+ # Every verb named here runs as written. `cckit digest` is deliberately absent: it summarises one
122
+ # <path|url> with a local model, it does not report on the week.
123
+ effort_cadence_md() {
124
+ printf '%s\n' '**Weekly cadence** — Monday: `cckit plan` orders the week · daily: `cckit next` picks up one issue · Friday: `cckit gc` reports what can be pruned.'
125
+ }
126
+
127
+ # Rows travel between the readers and the planner as five fields joined by the ASCII unit
128
+ # separator: number, flow, ctx, title, blockers (comma-separated issue numbers). Not TAB — TAB is
129
+ # IFS whitespace, so `read` collapses two adjacent tabs and an empty column shifts every later one.
130
+ _EP_SEP=$'\037'
131
+
132
+ # _ep_rows_github <repo> — the open efforts from GitHub, in the planner's row format. It is
133
+ # effort_open_rows re-joined: the priority and open-blockers columns are dropped and the `-`
134
+ # empty-blockers placeholder becomes an empty field. rc 1 when the read fails; prints nothing when
135
+ # there are no open efforts.
136
+ _ep_rows_github() {
137
+ local rows
138
+ rows="$(effort_open_rows "$1")" || return 1
139
+ [[ -n "$rows" ]] || return 0
140
+ printf '%s\n' "$rows" | awk -F'\t' -v sep="$_EP_SEP" '
141
+ NF >= 7 { b = ($5 == "-" ? "" : $5); printf "%s%s%s%s%s%s%s%s%s\n", $1, sep, $2, sep, $3, sep, $7, sep, b }'
142
+ }
143
+
144
+ # _ep_project_root — the directory a relative `effort.planSource` resolves against: the project
145
+ # root the config file belongs to (config-path.sh), else the current directory.
146
+ _ep_project_root() {
147
+ local cfg=""
148
+ command -v kit_config_path >/dev/null 2>&1 && cfg="$(kit_config_path 2>/dev/null || true)"
149
+ [[ -n "$cfg" && -f "$cfg" ]] || { pwd; return 0; }
150
+ case "$cfg" in
151
+ */.claude/kit.config.json) (cd "$(dirname "$cfg")/.." 2>/dev/null && pwd) || pwd ;;
152
+ *) (cd "$(dirname "$cfg")" 2>/dev/null && pwd) || pwd ;;
153
+ esac
154
+ }
155
+
156
+ # _ep_source_rows — normalize a plan source's stdout (stdin here) to the internal row format.
157
+ # The source contract (effort.planSource):
158
+ # number<TAB>flow<TAB>ctx<TAB>title[<TAB>blockers] one line per open effort
159
+ # # age: <text> optional, anywhere; how old the snapshot is
160
+ # `blockers` is a comma-separated list of issue numbers (a leading # is accepted). Lines that start
161
+ # with # are metadata, and a line whose first column is not a number is ignored. An empty flow
162
+ # becomes "—" and an empty ctx "?", the same defaults the GitHub reader uses.
163
+ _ep_source_rows() {
164
+ awk -F'\t' -v sep="$_EP_SEP" '
165
+ /^#/ { next }
166
+ $1 ~ /^[0-9]+$/ {
167
+ f = ($2 == "" ? "—" : $2); c = ($3 == "" ? "?" : $3); b = $5; gsub(/[^0-9,]/, "", b)
168
+ printf "%s%s%s%s%s%s%s%s%s\n", $1, sep, f, sep, c, sep, $4, sep, b
169
+ }'
170
+ }
20
171
 
21
172
  effort_plan() {
22
- command -v gh >/dev/null 2>&1 && command -v jq >/dev/null 2>&1 || { echo "effort plan: needs gh + jq" >&2; return 1; }
23
173
  local repo="$EFFORT_REPO" budget="${KIT_SESSION_BUDGET:-4}"
24
174
  [[ -n "$repo" ]] || { echo "effort plan: no repo (set KIT_REPO / EFFORT_REPO)" >&2; return 1; }
25
175
 
26
- # 1. open efforts + their flow:/ctx: labels (one query).
27
- local raw
28
- raw="$(gh issue list --repo "$repo" --label effort --state open --limit 100 \
29
- --json number,title,labels \
30
- --jq '.[] | [ (.number|tostring),
31
- ([.labels[].name|select(startswith("flow:"))|ltrimstr("flow:")]|first // "—"),
32
- ([.labels[].name|select(startswith("ctx:"))|ltrimstr("ctx:")]|first // "?"),
33
- .title ] | @tsv' 2>/dev/null)" \
34
- || { echo "effort plan: gh query failed (check gh auth)" >&2; return 1; }
35
- [[ -n "$raw" ]] || { echo "effort plan: no open efforts found" >&2; return 0; }
176
+ # 1. rows. A configured local source (effort.planSource, or EFFORT_PLAN_SOURCE per invocation)
177
+ # is tried first; if it is not executable, exits non-zero or prints no rows, the plan falls
178
+ # back to GitHub and says so. `srcline` is printed under the header either way — a plan that
179
+ # does not say what it was built from can be stale without anyone noticing.
180
+ local rows="" srcline="" fellback=""
181
+ local src="${EFFORT_PLAN_SOURCE:-${KIT_EFFORT_PLAN_SOURCE:-}}"
182
+ if [[ -n "$src" ]]; then
183
+ local root srcpath srcout src_rc=0 age
184
+ root="$(_ep_project_root)"
185
+ case "$src" in /*) srcpath="$src" ;; *) srcpath="$root/$src" ;; esac
186
+ if [[ ! -x "$srcpath" || -d "$srcpath" ]]; then
187
+ fellback="planSource $src is not executable"
188
+ else
189
+ srcout="$(cd "$root" 2>/dev/null && "$srcpath" "$repo")" || src_rc=$?
190
+ if [[ "$src_rc" -ne 0 ]]; then
191
+ fellback="planSource $src failed (exit $src_rc)"
192
+ else
193
+ rows="$(printf '%s\n' "$srcout" | _ep_source_rows)"
194
+ if [[ -z "$rows" ]]; then
195
+ fellback="planSource $src printed no rows"
196
+ else
197
+ age="$(printf '%s\n' "$srcout" | sed -n 's/^#[[:space:]]*age:[[:space:]]*//p' | sed -n 1p)"
198
+ srcline="planSource $src"
199
+ [[ -n "$age" ]] && srcline="$srcline · age $age"
200
+ fi
201
+ fi
202
+ fi
203
+ [[ -n "$fellback" ]] && echo "effort plan: $fellback — falling back to GitHub" >&2
204
+ fi
205
+ if [[ -z "$srcline" ]]; then
206
+ command -v gh >/dev/null 2>&1 && command -v jq >/dev/null 2>&1 || { echo "effort plan: needs gh + jq" >&2; return 1; }
207
+ srcline="GitHub ($repo)"
208
+ [[ -n "$fellback" ]] && srcline="$srcline — $fellback, fell back"
209
+ rows="$(_ep_rows_github "$repo")" \
210
+ || { echo "effort plan: gh query failed (check gh auth)" >&2; return 1; }
211
+ [[ -n "$rows" ]] || { echo "effort plan: no open efforts found (source: $srcline)" >&2; return 0; }
212
+ fi
36
213
 
37
- # 2. read into parallel arrays + fetch blocked_by per effort (small N).
214
+ # 2. read into parallel arrays.
38
215
  local -a nums=() flows=() ctxs=() titles=() blocks=()
39
- local n f c t
40
- while IFS=$'\t' read -r n f c t; do
216
+ local n f c t bl
217
+ while IFS="$_EP_SEP" read -r n f c t bl; do
41
218
  [[ -n "$n" ]] || continue
42
- nums+=("$n"); flows+=("$f"); ctxs+=("$c"); titles+=("$t")
43
- blocks+=("$(gh api "repos/$repo/issues/$n/dependencies/blocked_by" --jq '[.[].number]|join(",")' 2>/dev/null)")
44
- done <<< "$raw"
219
+ nums+=("$n"); flows+=("$f"); ctxs+=("$c"); titles+=("$t"); blocks+=("$bl")
220
+ done <<< "$rows"
45
221
 
46
222
  # 3. distinct flows, first-seen order.
47
223
  local -a flowlist=()
@@ -49,7 +225,8 @@ effort_plan() {
49
225
  case " ${flowlist[*]-} " in *" $f "*) ;; *) flowlist+=("$f") ;; esac
50
226
  done
51
227
 
52
- printf '\n kit effort plan — session budget %s (ctx S=1 M=2 L=4 XL=8 · L/XL → delegate subs)\n' "$budget"
228
+ printf '\n kit effort plan — session budget %s (ctx S=1 M=2 L=4 XL=8 · ? = no ctx: label, weighed %s · L/XL → delegate subs)\n' "$budget" "$EP_UNSIZED_WEIGHT"
229
+ printf ' source: %s\n' "$srcline"
53
230
 
54
231
  local i j b
55
232
  for f in "${flowlist[@]}"; do
@@ -85,7 +262,7 @@ effort_plan() {
85
262
  local sess=1 load=0 batch=" "
86
263
  printf ' Session %s:\n' "$sess"
87
264
  for i in "${order[@]}"; do
88
- local w; w="$(_ep_weight "${ctxs[$i]}")"
265
+ local w; w="$(_ep_weight "${ctxs[$i]}" "${nums[$i]}")"
89
266
  local neednew=0
90
267
  (( load + w > budget )) && neednew=1
91
268
  for b in ${blocks[$i]//,/ }; do case "$batch" in *" $b "*) neednew=1 ;; esac; done