@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,706 @@
1
+ #!/usr/bin/env bash
2
+ # shellcheck shell=bash
3
+ # light-task.sh — `cckit task <new|list|next|start|finish|run|share>` (#450): track work without
4
+ # GitHub issues. The records come from a task source (task-source.sh; the `file` source keeps one
5
+ # tracked file per task); this file is the verbs, and it never reads a task any other way.
6
+ #
7
+ # new record a task in this checkout (no branch, no commit)
8
+ # list every open task and its state; --all adds done and dropped
9
+ # next the task to take next + the command that starts it
10
+ # start worktree `.claude/worktrees/light+<id>-<slug>` on branch `light/<id>-<slug>`, cut from
11
+ # the base branch, pushed so the team sees the task is taken (alias: take)
12
+ # finish mark the task done ON ITS BRANCH, commit, push, open the pull request. The task is done
13
+ # when that pull request merges — review stays a pull request (alias: done)
14
+ # default print `light` or `issues`: which list is the project's default (tasks.default)
15
+ # run start + ONE headless objective built from the task record + finish: hands a task to an
16
+ # agent and prints the review link. Never merges (#496). For a page task (kind `page`, or
17
+ # `tasks.design: true` in the config) the objective names the `page-design` skill and the
18
+ # review lists the skills the run loaded (#504)
19
+ # share one pull request that adds this checkout's drafts to the base branch, for a backlog
20
+ # nobody has started yet. The tasks list as `shared` until it merges; run again with no
21
+ # new drafts, it retries a share whose push or pull request failed
22
+ #
23
+ # Branch form: `light/<id>-<slug>`. `light` is not a kind and <id> starts with a letter, so the
24
+ # branch never parses as an issue number; worktree-issue.sh (wt_task_id) parses it instead, and
25
+ # `cckit gc` keeps the branch while the task is not done on the base branch.
26
+ #
27
+ # Never merges, never closes anything, and writes nothing to GitHub but the branch and the PR.
28
+ #
29
+ # lt_cli <sub> [args…] the dispatcher bin/cckit calls; honours --llm (CCKIT_OUTPUT=json)
30
+ # returns: 0 ok · 1 refused or a failed step · 2 usage
31
+ #
32
+ # Requires: git, jq; gh for finish and share. worktree-start.sh (wt_bootstrap) and kit-task-ops.sh
33
+ # (kto_pr_title) when loaded. bash 3.2 compatible; sourceable under zsh.
34
+ # errors: strict — rc 1 on any failed step; nothing is pushed or opened after a failure
35
+ # Runs under the dispatcher's `set -eu`: every read that may fail carries `|| true` or an `if`.
36
+
37
+ _LT_LIB_DIR="$(CDPATH='' cd -- "$(dirname -- "${BASH_SOURCE[0]:-$0}")" >/dev/null 2>&1 && pwd)"
38
+ if ! command -v task_source_call >/dev/null 2>&1; then
39
+ # shellcheck source=task-source.sh
40
+ . "$_LT_LIB_DIR/task-source.sh"
41
+ fi
42
+ if ! command -v wt_task_id >/dev/null 2>&1; then
43
+ # shellcheck source=worktree-issue.sh
44
+ . "$_LT_LIB_DIR/worktree-issue.sh"
45
+ fi
46
+ if ! type cckit_gh_rest >/dev/null 2>&1; then
47
+ # shellcheck source=gh-rest.sh
48
+ [ -f "$_LT_LIB_DIR/gh-rest.sh" ] && . "$_LT_LIB_DIR/gh-rest.sh"
49
+ fi
50
+ type cckit_gh_rest >/dev/null 2>&1 || cckit_gh_rest() { return 1; }
51
+ type cckit_is_json >/dev/null 2>&1 || cckit_is_json() { [ "${CCKIT_OUTPUT:-human}" = "json" ]; }
52
+
53
+ _LT_TAB="$(printf '\t')"
54
+
55
+ # _lt_say <technical> <plain> — one progress line, worded for the reader (#420). With
56
+ # plainLanguage.enabled (KIT_PLAIN_LANGUAGE=true) the plain wording is printed: no worktree, branch
57
+ # or pull request. Only human progress lines go through here; stdout contracts and --llm do not.
58
+ # The plain finish hint names --all: a draft is a file the task created, and without --all
59
+ # `finish` opens the review without it.
60
+ _lt_say() {
61
+ if [ "${KIT_PLAIN_LANGUAGE:-false}" = "true" ]; then printf '%s\n' "$2"; else printf '%s\n' "$1"; fi
62
+ }
63
+
64
+ _lt_usage() {
65
+ cat >&2 <<'EOF'
66
+ cckit task new [--priority p0|p1|p2|p3] [--kind K] [--body B|--body-file F] "<title>"
67
+ cckit task list [--all]
68
+ cckit task next
69
+ cckit task start [--force] [--no-push] <id> (alias: take)
70
+ cckit task finish [<id>] "<summary>" [--all] (alias: done)
71
+ cckit task run <id> [--check "<cmd>"] [--max-iters N] [--max-seconds N] [--agent <cmd>] [--agent-arg <arg>]… [--no-finish]
72
+ cckit task share ["<summary>"]
73
+ a page task: --kind page, or tasks.design: true in the config. `task run` then names the
74
+ page-design skill to the agent, and the review lists the skills the run loaded
75
+ cckit task default light | issues (tasks.default in the config)
76
+ EOF
77
+ }
78
+
79
+ _lt_root() { git worktree list --porcelain 2>/dev/null | awk '/^worktree / && !hit { print substr($0, 10); hit = 1 }'; }
80
+ _lt_top() { git rev-parse --show-toplevel 2>/dev/null; }
81
+ _lt_base() { printf '%s' "${KIT_BASE_BRANCH:-main}"; }
82
+ _lt_repo() { printf '%s' "${KIT_TASK_REPO:-${KIT_REPO:-}}"; }
83
+
84
+ # _lt_worktree_of <root> <branch> — the worktree that has <branch> checked out, or nothing.
85
+ _lt_worktree_of() {
86
+ git -C "$1" worktree list --porcelain 2>/dev/null | awk -v b="refs/heads/$2" '
87
+ /^worktree / { w = substr($0, 10) }
88
+ /^branch / { if (substr($0, 8) == b) { print w; exit } }'
89
+ }
90
+
91
+ _lt_slug() {
92
+ printf '%s' "$1" | tr '[:upper:]' '[:lower:]' | sed -E 's/[^a-z0-9]+/-/g; s/^-+|-+$//g' | cut -c1-40 | sed -E 's/-+$//'
93
+ }
94
+
95
+ # _lt_fetch — refresh the cached refs the source reads. Best-effort: offline still lists.
96
+ _lt_fetch() {
97
+ [ "${KIT_TASK_FETCH:-1}" != "0" ] || return 0
98
+ git remote get-url origin >/dev/null 2>&1 || return 0
99
+ git fetch --quiet --prune origin 2>/dev/null || echo "⚠ could not fetch origin — showing the last fetched state" >&2
100
+ return 0
101
+ }
102
+
103
+ # _lt_rows_json — stdin: TSV rows. stdout: a JSON array.
104
+ _lt_rows_json() {
105
+ jq -R -s -c 'split("\n") | map(select(length > 0) | split("\t")
106
+ | {id: .[0], state: .[1], priority: .[2], kind: .[3], created: .[4],
107
+ branch: (if .[5] == "-" then null else .[5] end), title: .[6]})'
108
+ }
109
+
110
+ _lt_table() {
111
+ local id state prio kind created br title
112
+ printf '%-7s %-7s %-4s %s\n' "ID" "STATE" "PRIO" "TITLE"
113
+ while IFS="$_LT_TAB" read -r id state prio kind created br title; do
114
+ [ -n "$id" ] || continue
115
+ printf '%-7s %-7s %-4s %s\n' "$id" "$state" "$prio" "$title"
116
+ done
117
+ }
118
+
119
+ # ── new ─────────────────────────────────────────────────────────────────────────────────────────
120
+ lt_new() {
121
+ local prio="p2" kind="task" body="" title="" id dir
122
+ while [ "$#" -gt 0 ]; do
123
+ case "$1" in
124
+ --priority) prio="${2:-}"; shift; [ "$#" -gt 0 ] && shift ;;
125
+ --kind) kind="${2:-}"; shift; [ "$#" -gt 0 ] && shift ;;
126
+ --body) body="${2:-}"; shift; [ "$#" -gt 0 ] && shift ;;
127
+ --body-file) body="$(cat "${2:-/dev/null}")"; shift; [ "$#" -gt 0 ] && shift ;;
128
+ -h|--help) _lt_usage; return 0 ;;
129
+ --) shift; title="${title:+$title }$*"; break ;;
130
+ -*) echo "✗ task new: unknown flag '$1'" >&2; _lt_usage; return 2 ;;
131
+ *) title="${title:+$title }$1"; shift ;;
132
+ esac
133
+ done
134
+ [ -n "$title" ] || { echo '✗ task new: a title is required — cckit task new "<title>"' >&2; return 2; }
135
+ case "$prio" in p0|p1|p2|p3) : ;; *) echo "✗ task new: --priority is one of p0 p1 p2 p3 (got '$prio')" >&2; return 2 ;; esac
136
+ case "$kind" in ''|*[!a-z]*) echo "✗ task new: --kind is one lowercase word (got '$kind')" >&2; return 2 ;; esac
137
+ id="$(task_source_call create "$title" "$prio" "$kind" "$body")" || return 1
138
+ dir="$(task_source_dir)"
139
+ if cckit_is_json; then
140
+ cckit_json verb "task new" ok true id "$id" title "$title" file "$dir/$id.md"
141
+ return 0
142
+ fi
143
+ echo "✓ task $id · $title"
144
+ if [ "$(task_source_name)" = "file" ]; then
145
+ _lt_say " file: $dir/$id.md (a draft: only in this checkout until it is started or shared)" \
146
+ " file: $dir/$id.md (only on this computer until you start it or share the list)"
147
+ fi
148
+ echo " start: cckit task start $id"
149
+ }
150
+
151
+ # ── list / next ─────────────────────────────────────────────────────────────────────────────────
152
+ lt_list() {
153
+ local all=0 rows a
154
+ for a in "$@"; do
155
+ case "$a" in
156
+ --all|-a) all=1 ;;
157
+ -h|--help) _lt_usage; return 0 ;;
158
+ *) echo "✗ task list: unknown argument '$a'" >&2; return 2 ;;
159
+ esac
160
+ done
161
+ _lt_fetch
162
+ rows="$(task_source_call list)" || return 1
163
+ if [ "$all" = 0 ]; then rows="$(printf '%s\n' "$rows" | awk -F'\t' '$2 != "done" && $2 != "dropped"')"; fi
164
+ if cckit_is_json; then printf '%s\n' "$rows" | _lt_rows_json; return 0; fi
165
+ if [ -z "$rows" ]; then
166
+ echo '(no open tasks — create one with: cckit task new "<title>")'; return 0
167
+ fi
168
+ printf '%s\n' "$rows" | _lt_table
169
+ # `draft` in the STATE column is about the task record, not about a piece of writing (#487).
170
+ if [ "${KIT_PLAIN_LANGUAGE:-false}" = "true" ] && grep -q "^[^$_LT_TAB]*${_LT_TAB}draft${_LT_TAB}" <<<"$rows"; then
171
+ echo "draft = the task is on this computer only: not started, not on the shared list yet"
172
+ fi
173
+ }
174
+
175
+ lt_next() {
176
+ local row id state prio kind created br title
177
+ _lt_fetch
178
+ row="$(task_source_call list | awk -F'\t' '$2 == "todo" || $2 == "draft"' | sed -n 1p)" || true
179
+ if [ -z "$row" ]; then
180
+ if cckit_is_json; then echo 'null'; else echo '(nothing to take — create a task with: cckit task new "<title>")'; fi
181
+ return 0
182
+ fi
183
+ if cckit_is_json; then printf '%s\n' "$row" | _lt_rows_json | jq -c '.[0] + {start: ("cckit task start " + .[0].id)}'; return 0; fi
184
+ IFS="$_LT_TAB" read -r id state prio kind created br title <<EOF
185
+ $row
186
+ EOF
187
+ echo "next: $id · $title ($prio)"
188
+ echo " start: cckit task start $id"
189
+ }
190
+
191
+ # ── start ───────────────────────────────────────────────────────────────────────────────────────
192
+ # stdout: "<worktree>|<branch>|<id>" (the shape wt_start prints). stderr: progress.
193
+ lt_start() {
194
+ local force="${KIT_FORCE:-0}" push=1 want="" a row id state prio kind created br title
195
+ local root from base base_ref lbr rbr branch wt
196
+ for a in "$@"; do
197
+ case "$a" in
198
+ --force) force=1 ;;
199
+ --no-push) push=0 ;;
200
+ -h|--help) _lt_usage; return 0 ;;
201
+ -*) echo "✗ task start: unknown flag '$a'" >&2; return 2 ;;
202
+ *) if [ -z "$want" ]; then want="$a"; else echo "✗ task start: one task id only" >&2; return 2; fi ;;
203
+ esac
204
+ done
205
+ [ -n "$want" ] || { echo "✗ task start: a task id is required — see 'cckit task list'" >&2; return 2; }
206
+ root="$(_lt_root)"; from="$(_lt_top)"
207
+ [ -n "$root" ] && [ -n "$from" ] || { echo "✗ task start: not inside a git repository" >&2; return 1; }
208
+ base="$(_lt_base)"
209
+ if git -C "$root" remote get-url origin >/dev/null 2>&1; then
210
+ git -C "$root" fetch --quiet origin 2>/dev/null || echo "⚠ could not fetch origin — starting from the last fetched $base" >&2
211
+ fi
212
+
213
+ row="$(task_source_call get "$want")" || return 1
214
+ IFS="$_LT_TAB" read -r id state prio kind created br title <<EOF
215
+ $row
216
+ EOF
217
+ case "$state" in
218
+ done|dropped) echo "✗ task $id is already $state" >&2; return 1 ;;
219
+ shared)
220
+ echo "✗ task $id is waiting in a share pull request ($br) — start it once that merges" >&2
221
+ return 1 ;;
222
+ esac
223
+
224
+ lbr="$(git -C "$root" for-each-ref --format='%(refname:short)' "refs/heads/light/$id-*" 2>/dev/null | sed -n 1p)"
225
+ rbr="$(git -C "$root" for-each-ref --format='%(refname:short)' "refs/remotes/origin/light/$id-*" 2>/dev/null | sed -n 1p)"
226
+ if [ -n "$lbr" ]; then
227
+ branch="$lbr"
228
+ wt="$(_lt_worktree_of "$root" "$branch")"
229
+ if [ -n "$wt" ]; then
230
+ echo "[$id] reusing worktree $wt" >&2
231
+ else
232
+ wt="$root/.claude/worktrees/$(printf '%s' "$branch" | tr '/' '+')"
233
+ git -C "$root" worktree add "$wt" "$branch" >/dev/null 2>&1 \
234
+ || { echo "✗ task start: worktree add failed for the existing branch $branch" >&2; return 1; }
235
+ echo "[$id] created worktree $wt (existing branch $branch)" >&2
236
+ fi
237
+ elif [ -n "$rbr" ]; then
238
+ branch="${rbr#origin/}"
239
+ if [ "$force" != "1" ]; then
240
+ echo "✗ task $id is already taken: origin has $branch" >&2
241
+ echo " 'cckit task start --force $id' continues that branch in a worktree here." >&2
242
+ return 1
243
+ fi
244
+ wt="$root/.claude/worktrees/$(printf '%s' "$branch" | tr '/' '+')"
245
+ git -C "$root" worktree add -b "$branch" "$wt" "$rbr" >/dev/null 2>&1 \
246
+ || { echo "✗ task start: worktree add failed for $branch" >&2; return 1; }
247
+ echo "[$id] ⚠ --force: continuing $branch from origin in $wt" >&2
248
+ else
249
+ if git -C "$root" show-ref --verify --quiet "refs/remotes/origin/$base"; then base_ref="origin/$base"
250
+ elif git -C "$root" show-ref --verify --quiet "refs/heads/$base"; then base_ref="$base"
251
+ else
252
+ # Name the fix (#487): the usual cause is a config whose base branch was never created.
253
+ echo "✗ task start: no base branch '$base' to cut from" >&2
254
+ echo " The project config names '$base' (github.baseBranch) and this repository has no such branch, here or on origin." >&2
255
+ echo " Create it and push it: cckit init --yes (inside $root)" >&2
256
+ echo " Or point the config at a branch that exists: this folder is on '$(git -C "$root" symbolic-ref --short -q HEAD 2>/dev/null || echo "no branch")'." >&2
257
+ return 1
258
+ fi
259
+ branch="light/$id-$(_lt_slug "$title")"
260
+ branch="${branch%-}"
261
+ case "$branch" in "light/$id") branch="light/$id-task" ;; esac
262
+ wt="$root/.claude/worktrees/$(printf '%s' "$branch" | tr '/' '+')"
263
+ git -C "$root" worktree add --no-track -b "$branch" "$wt" "$base_ref" >/dev/null 2>&1 \
264
+ || { echo "✗ task start: worktree add failed for $branch" >&2; return 1; }
265
+ _lt_say "[$id] created worktree $wt (branch $branch from $base_ref)" \
266
+ "[$id] started — the draft lives in $wt" >&2
267
+ if type wt_bootstrap >/dev/null 2>&1; then wt_bootstrap "$root" "$wt" "$id" >&2 || true; fi
268
+ fi
269
+
270
+ task_source_call on_start "$id" "$wt" "$from" || return 1
271
+
272
+ if [ "$push" = 1 ] && git -C "$root" remote get-url origin >/dev/null 2>&1; then
273
+ if KIT_PR_BASE="$base" git -C "$wt" push --quiet -u origin "$branch" >/dev/null 2>&1; then
274
+ _lt_say "[$id] pushed $branch — the team's list now shows the task as doing" \
275
+ "[$id] the team's list now shows this task as in progress" >&2
276
+ else
277
+ _lt_say "[$id] ⚠ could not push $branch; the task shows as doing on this machine only" \
278
+ "[$id] ⚠ could not reach the shared copy; the task shows as in progress on this computer only" >&2
279
+ fi
280
+ fi
281
+ _lt_say "[$id] when the work is ready: cckit task finish $id \"<summary>\"" \
282
+ "[$id] when the draft is ready for review: cckit task finish $id \"<summary>\" --all" >&2
283
+ echo "$wt|$branch|$id"
284
+ }
285
+
286
+ # _lt_pr_title <title> <summary> <kind> <token> — a Conventional Commit subject ending in [<token>].
287
+ _lt_pr_title() {
288
+ local t
289
+ if type kto_pr_title >/dev/null 2>&1; then
290
+ t="$(KIT_PR_TITLE_STYLE=conventional kto_pr_title "$1" "$2" "kind:$3")"
291
+ else
292
+ t="feat: $1"
293
+ fi
294
+ case "$t" in *"[$4]"*) : ;; *) t="$t [$4]" ;; esac
295
+ printf '%s' "$t"
296
+ }
297
+
298
+ # _lt_open_pr <worktree> <branch> <title> <body> — push, then report the open PR or create one.
299
+ # stdout: "✓ <url>".
300
+ _lt_open_pr() {
301
+ local wt="$1" branch="$2" title="$3" body="$4" repo base url="" n
302
+ repo="$(_lt_repo)"; base="$(_lt_base)"
303
+ if ! KIT_PR_BASE="$base" git -C "$wt" push -u origin "$branch" >&2; then
304
+ echo "✗ could not push $branch — the commit is kept in $wt; run the same command again to retry" >&2
305
+ return 1
306
+ fi
307
+ if cckit_gh_rest; then
308
+ n="$(gh_rest_pr_for_head "$repo" "$branch" 2>/dev/null || true)"
309
+ if [ -n "$n" ]; then url="https://github.com/$repo/pull/$n"; fi
310
+ else
311
+ url="$(gh pr list --repo "$repo" --head "$branch" --state open --json url --jq '.[0].url // empty' 2>/dev/null || true)"
312
+ fi
313
+ if [ -n "$url" ]; then
314
+ _lt_say "[task] a pull request is already open for $branch" \
315
+ "[task] this draft is already waiting for review" >&2
316
+ echo "✓ $url"; return 0
317
+ fi
318
+ if cckit_gh_rest; then
319
+ url="$(gh_rest_pr_create "$repo" "$base" "$branch" "$title" "$body" "" "")" || url=""
320
+ else
321
+ url="$(gh pr create --repo "$repo" --base "$base" --head "$branch" \
322
+ --title "$title" --body "$body" --assignee "@me")" || url=""
323
+ fi
324
+ if [ -z "$url" ]; then
325
+ echo "✗ could not open the pull request for $branch — the branch is pushed; run the same command again to retry" >&2
326
+ return 1
327
+ fi
328
+ [ "${KIT_PLAIN_LANGUAGE:-false}" = "true" ] && echo "[task] ready for review — open the link and approve it there" >&2
329
+ echo "✓ $url"
330
+ }
331
+
332
+ # ── finish ──────────────────────────────────────────────────────────────────────────────────────
333
+ lt_finish() {
334
+ local all=0 a p1="" p2="" npos=0 want="" summary="" row id state prio kind created br title
335
+ local root branch wt cur dir pr_title body page_check design
336
+ for a in "$@"; do
337
+ case "$a" in
338
+ --all) all=1 ;;
339
+ -h|--help) _lt_usage; return 0 ;;
340
+ -*) echo "✗ task finish: unknown flag '$a'" >&2; return 2 ;;
341
+ *) npos=$((npos + 1)); case "$npos" in 1) p1="$a" ;; 2) p2="$a" ;; *) echo "✗ task finish: too many arguments" >&2; return 2 ;; esac ;;
342
+ esac
343
+ done
344
+ cur="$(wt_task_id "$(git rev-parse --abbrev-ref HEAD 2>/dev/null || true)")"
345
+ if [ "$npos" -eq 2 ]; then want="$p1"; summary="$p2"
346
+ elif [ "$npos" -eq 1 ] && [ -n "$cur" ] && [ "$p1" != "$cur" ]; then want="$cur"; summary="$p1"
347
+ elif [ "$npos" -eq 1 ]; then want="$p1"
348
+ else want="$cur"; fi
349
+ [ -n "$want" ] || { echo '✗ task finish: which task? — cckit task finish <id> "<summary>"' >&2; return 2; }
350
+ [ -n "$summary" ] || { echo '✗ task finish: a summary is required — cckit task finish <id> "<what was done>"' >&2; return 2; }
351
+
352
+ root="$(_lt_root)"
353
+ [ -n "$root" ] || { echo "✗ task finish: not inside a git repository" >&2; return 1; }
354
+ row="$(task_source_call get "$want")" || return 1
355
+ IFS="$_LT_TAB" read -r id state prio kind created br title <<EOF
356
+ $row
357
+ EOF
358
+ case "$state" in done|dropped) echo "✗ task $id is already $state" >&2; return 1 ;; esac
359
+ branch="$(git -C "$root" for-each-ref --format='%(refname:short)' "refs/heads/light/$id-*" 2>/dev/null | sed -n 1p)"
360
+ [ -n "$branch" ] || { echo "✗ task $id has not been started here — run: cckit task start $id" >&2; return 1; }
361
+ wt="$(_lt_worktree_of "$root" "$branch")"
362
+ [ -n "$wt" ] && [ -d "$wt" ] || { echo "✗ task $id: branch $branch has no worktree — run: cckit task start $id" >&2; return 1; }
363
+
364
+ task_source_call on_finish "$id" "$wt" || return 1
365
+ if [ "$all" = 1 ]; then
366
+ git -C "$wt" add -A
367
+ else
368
+ git -C "$wt" add -u
369
+ if [ -n "$(git -C "$wt" ls-files --others --exclude-standard 2>/dev/null)" ]; then
370
+ echo "task finish: new files NOT included (re-run with --all, or git add the ones that belong):" >&2
371
+ git -C "$wt" ls-files --others --exclude-standard 2>/dev/null | sed 's/^/ /' >&2
372
+ fi
373
+ fi
374
+ pr_title="$(_lt_pr_title "$title" "$summary" "$kind" "$id")"
375
+ if ! git -C "$wt" diff --cached --quiet 2>/dev/null; then
376
+ git -C "$wt" commit -q -m "$pr_title" >&2 || { echo "✗ task finish: the commit failed in $wt" >&2; return 1; }
377
+ fi
378
+
379
+ dir="$(task_source_dir)"
380
+ # A page task (#504): the reviewer is asked to open the page, and the body says which design
381
+ # skills the run loaded.
382
+ page_check=""; design=""
383
+ if _lt_page_task "$kind"; then
384
+ page_check='- [ ] Open the page in a browser and compare it with the design brief'
385
+ design="$(_lt_design_section "$id" "$wt" "$branch")"
386
+ fi
387
+ if type kto_pr_body_style >/dev/null 2>&1 && [ "$(kto_pr_body_style)" = "content" ]; then
388
+ # pr.bodyStyle = content (#418): the reviewer is not a developer — say what approving does and
389
+ # what to check, without "diff".
390
+ body="$(printf '## Task\n\n`%s` · %s\n\n## Summary\n\n%s\n\n## Review\n\n%s\n\nApproving and merging this pull request marks the task done: it changes the task record `%s/%s.md` to `status: done`. No GitHub issue is linked.\n' \
391
+ "$id" "$title" "$summary" "$(kto_content_review_checklist)${page_check:+
392
+ $page_check}" "$dir" "$id")"
393
+ else
394
+ body="$(printf '## Light task\n\n`%s` · %s\n\n## Summary\n\n%s\n\n## Review\n\n%sMerging this pull request is what marks the task done: its diff carries the task record with `status: done` (`%s/%s.md` with the file source). No GitHub issue is linked.\n' \
395
+ "$id" "$title" "$summary" "${page_check:+$page_check
396
+
397
+ }" "$dir" "$id")"
398
+ fi
399
+ if [ -n "$design" ]; then body="$body
400
+
401
+ $design"; fi
402
+ _lt_open_pr "$wt" "$branch" "$pr_title" "$body"
403
+ }
404
+
405
+ # ── run ─────────────────────────────────────────────────────────────────────────────────────────
406
+ # _lt_check_default — `tasks.check` of the project config (the gate `task run` uses with no
407
+ # --check), or nothing. The config is the one kit_config_path resolves.
408
+ _lt_check_default() {
409
+ local cfg
410
+ cfg="$(_lt_config_file)"
411
+ [ -n "$cfg" ] || return 0
412
+ jq -r '.tasks.check // empty | strings' "$cfg" 2>/dev/null || true
413
+ }
414
+
415
+ # _lt_config_file — the project config kit_config_path resolves, or nothing.
416
+ _lt_config_file() {
417
+ local cfg=""
418
+ if ! command -v kit_config_path >/dev/null 2>&1 && [ -f "$_LT_LIB_DIR/config-path.sh" ]; then
419
+ # shellcheck source=config-path.sh
420
+ . "$_LT_LIB_DIR/config-path.sh"
421
+ fi
422
+ if command -v kit_config_path >/dev/null 2>&1; then cfg="$(kit_config_path 2>/dev/null || true)"; fi
423
+ if [ -n "$cfg" ] && [ -f "$cfg" ]; then printf '%s\n' "$cfg"; fi
424
+ return 0
425
+ }
426
+
427
+ # ── page tasks (#504) ───────────────────────────────────────────────────────────────────────────
428
+ # The design skills a page is built with: cckit's own `page-design`, then the three third-party
429
+ # skills it coordinates (integrations/impeccable.json, emil-design-eng.json,
430
+ # web-design-guidelines.json).
431
+ _LT_DESIGN_SKILLS="page-design impeccable emil-design-eng web-design-guidelines"
432
+
433
+ # _lt_page_task <kind> — rc 0 when the task builds or changes a page. The rule is two facts, read
434
+ # from the record and the config, never guessed from the title or the notes:
435
+ # 1. the task's kind is `page` (cckit task new --kind page "<title>"), or
436
+ # 2. `tasks.design` is true in the project config: every task of the project is a page task
437
+ # (the nextjs-shadcn recipe writes it).
438
+ _lt_page_task() {
439
+ local cfg
440
+ [ "${1:-}" = "page" ] && return 0
441
+ cfg="$(_lt_config_file)"
442
+ [ -n "$cfg" ] || return 1
443
+ jq -e '.tasks.design == true' "$cfg" >/dev/null 2>&1
444
+ }
445
+
446
+ # _lt_run_state_file <worktree> <branch> — the state file `cckit autopilot run` keeps for a branch.
447
+ _lt_run_state_file() {
448
+ ( cd "$1" 2>/dev/null && . "$_LT_LIB_DIR/kit-state.sh" && printf '%s/autopilot/%s.json' "$(kit_state_dir)" \
449
+ "$(printf '%s' "$2" | tr -c 'A-Za-z0-9._-' '_')" ) || true
450
+ }
451
+
452
+ # _lt_design_brief <id> — where page-design writes the brief and the self-review of a task.
453
+ _lt_design_brief() { printf 'docs/design/%s.md' "$1"; }
454
+
455
+ # _lt_design_section <id> <worktree> <branch> — the `## Design` section of a page task's review.
456
+ # The skill list is the one the run recorded from the agent CLI's own event output
457
+ # (autopilot-run.sh --record-skills → state `.skills`). It is never taken from the agent's account
458
+ # of itself, and a list this code cannot stand behind is reported as not known, not as empty.
459
+ _lt_design_section() {
460
+ local id="$1" wt="$2" branch="$3" sfile brief
461
+ sfile="$(_lt_run_state_file "$wt" "$branch")"
462
+ brief="$(_lt_design_brief "$id")"
463
+ printf '## Design\n\n'
464
+ if [ -n "$sfile" ] && [ -f "$sfile" ]; then
465
+ jq -r --arg want "$_LT_DESIGN_SKILLS" '
466
+ def base: split(":") | last;
467
+ ($want | split(" ")) as $w
468
+ | if (.skills | type) != "object" then
469
+ "Which skills were loaded is not known: the last run on this task did not record them."
470
+ elif .skills.complete != true then
471
+ "Which skills were loaded is not known: the agent CLI printed no event output in at least one round of the run."
472
+ else
473
+ (.skills.loaded // []) as $l
474
+ | [ $w[] as $x | $l[] | select(base == $x) ] as $d
475
+ | ($w | map(select(. as $x | any($d[]; base == $x) | not))) as $m
476
+ | ($l - $d) as $o
477
+ | (if ($d | length) == 0 then "No design skill was loaded in this run."
478
+ else "Design skills loaded in this run: \($d | join(", "))." end),
479
+ (if ($m | length) > 0 then "Design skills not loaded in this run: \($m | join(", "))." else empty end),
480
+ (if ($o | length) > 0 then "Other skills loaded in this run: \($o | join(", "))." else empty end),
481
+ "Read from the events the agent CLI (\(.skills.source)) printed during the run: a skill is listed when its call returned without an error. What the agent wrote about itself is not used."
482
+ end' "$sfile" 2>/dev/null \
483
+ || printf 'Which skills were loaded is not known: the run record %s could not be read.\n' "$sfile"
484
+ else
485
+ printf 'Which skills were loaded is not known: no `cckit task run` is recorded for this task.\n'
486
+ fi
487
+ printf '\n'
488
+ if [ -f "$wt/$brief" ]; then
489
+ printf 'Design brief and self-review: `%s`.\n' "$brief"
490
+ else
491
+ printf 'No design brief is in this change: `%s` was not written.\n' "$brief"
492
+ fi
493
+ }
494
+
495
+ # lt_run <id> [flags] — delegate ONE task end to end (#496): lt_start (reusing the task's worktree),
496
+ # one `cckit autopilot run` objective built from the task's title and notes, then lt_finish --all.
497
+ # It adds no engine: the three steps are the code paths the separate verbs run.
498
+ # --check "<cmd>" the gate the work must pass before a review opens; else `tasks.check` in the
499
+ # project config; else none
500
+ # --max-iters N · --max-seconds N · --agent <claude|codex> · --agent-arg <arg> (repeatable)
501
+ # passed to the run. The run has no --until, so it is one round;
502
+ # --max-seconds also bounds that round
503
+ # --no-finish stop after the run: nothing is pushed for review, no pull request
504
+ # A stopped earlier run on the task's branch is discarded (--fresh): the task record is the
505
+ # objective, so there is nothing to resume. A task whose branch already says done (state `review`)
506
+ # starts no agent: the open pull request is reported, or opening it is retried.
507
+ # stdout: "✓ <url>" — or "<worktree>|<branch>|<id>" with --no-finish. stderr: progress.
508
+ # returns: the run's exit code (0 done · 2 refused · 3 agent failed · 4 limit · 5 the round changed
509
+ # nothing · 6 gate failed · 130 interrupted) · 7 the review could not be opened · 1 the task
510
+ # could not be started · 2 usage
511
+ lt_run() {
512
+ local want="" check="" check_set=0 iters="" secs="" agent="" finish=1 line id wt branch rest
513
+ local row state prio kind created br title dir body objective rc sfile reason detail summary page=0
514
+ local -a pass
515
+ pass=()
516
+ while [ "$#" -gt 0 ]; do
517
+ case "$1" in
518
+ --check) [ "$#" -ge 2 ] || { echo "✗ task run: --check needs a value" >&2; return 2; }; check="$2"; check_set=1; shift 2 ;;
519
+ --max-iters) [ "$#" -ge 2 ] || { echo "✗ task run: --max-iters needs a value" >&2; return 2; }; iters="$2"; shift 2 ;;
520
+ --max-seconds) [ "$#" -ge 2 ] || { echo "✗ task run: --max-seconds needs a value" >&2; return 2; }; secs="$2"; shift 2 ;;
521
+ --agent) [ "$#" -ge 2 ] || { echo "✗ task run: --agent needs a value" >&2; return 2; }; agent="$2"; shift 2 ;;
522
+ --agent-arg) [ "$#" -ge 2 ] || { echo "✗ task run: --agent-arg needs a value" >&2; return 2; }; pass+=(--agent-arg "$2"); shift 2 ;;
523
+ --no-finish) finish=0; shift ;;
524
+ -h|--help) _lt_usage; return 0 ;;
525
+ -*) echo "✗ task run: unknown flag '$1'" >&2; _lt_usage; return 2 ;;
526
+ *) if [ -z "$want" ]; then want="$1"; shift; else echo "✗ task run: one task id only" >&2; return 2; fi ;;
527
+ esac
528
+ done
529
+ [ -n "$want" ] || { echo "✗ task run: a task id is required — see 'cckit task list'" >&2; return 2; }
530
+ for rest in "$iters" "$secs"; do
531
+ case "$rest" in *[!0-9]*|0) echo "✗ task run: '$rest' is not a positive integer" >&2; return 2 ;; esac
532
+ done
533
+ [ "$check_set" = 1 ] || check="$(_lt_check_default)"
534
+
535
+ line="$(lt_start "$want")" || return 1
536
+ line="$(printf '%s\n' "$line" | tail -n 1)"
537
+ wt="${line%%|*}"; id="${line##*|}"; rest="${line#*|}"; branch="${rest%%|*}"
538
+ [ -n "$wt" ] && [ -d "$wt" ] && [ -n "$id" ] || { echo "✗ task run: the task could not be started" >&2; return 1; }
539
+ [ -z "${_LT_RUN_ID_FILE:-}" ] || printf '%s' "$id" > "$_LT_RUN_ID_FILE"
540
+ row="$(task_source_call get "$id")" || return 1
541
+ IFS="$_LT_TAB" read -r id state prio kind created br title <<EOF
542
+ $row
543
+ EOF
544
+
545
+ if [ "$state" = review ]; then
546
+ # The branch's copy already says done: an earlier run or `task finish` got that far. No round.
547
+ _lt_say "[$id] already finished on $branch — no agent round; reporting its pull request" \
548
+ "[$id] this task was already handed in for review — nothing new was written" >&2
549
+ lt_finish "$id" "$title" --all || return 7
550
+ return 0
551
+ fi
552
+
553
+ dir="$(task_source_dir)"
554
+ if _lt_page_task "$kind"; then
555
+ page=1
556
+ if [ ! -f "$wt/.claude/skills/page-design/SKILL.md" ] && [ ! -f "$wt/.agents/skills/page-design/SKILL.md" ]; then
557
+ echo "⚠ task $id is a page task and the page-design skill is not in this project — add it with: cckit add page-design" >&2
558
+ fi
559
+ fi
560
+ body=""
561
+ if task_source_has body; then body="$(task_source_call body "$id" "$wt" || true)"; fi
562
+ objective="$(printf 'Do this task: %s\n' "$title"
563
+ if [ -n "$body" ]; then printf '\nNotes from the task record:\n%s\n' "$body"; fi
564
+ printf '\nThe task is recorded in %s/%s.md. Leave that file as it is: cckit marks the task done when the work goes to review.\n' "$dir" "$id"
565
+ if [ "$page" = 1 ]; then
566
+ printf '\nThis task builds or changes a page. Before writing any code, load the `page-design` skill (in Claude Code with the Skill tool; otherwise read `.claude/skills/page-design/SKILL.md` or `.agents/skills/page-design/SKILL.md`) and follow it.\n'
567
+ printf 'Write the design brief to %s before the first line of code, and add the self-review to the same file after the build.\n' "$(_lt_design_brief "$id")"
568
+ printf 'This run is unattended: do not start the live mode of `impeccable`, and do not report a skill you could not load as used.\n'
569
+ fi)"
570
+
571
+ pass+=(--objective "$objective" --fresh)
572
+ if [ "$page" = 1 ]; then pass+=(--record-skills); fi
573
+ if [ -n "$check" ]; then pass+=(--check "$check"); fi
574
+ if [ -n "$iters" ]; then pass+=(--max-iters "$iters"); fi
575
+ if [ -n "$secs" ]; then pass+=(--max-seconds "$secs" --round-seconds "$secs"); fi
576
+ if [ -n "$agent" ]; then pass+=(--agent "$agent"); fi
577
+ _lt_say "[$id] running one headless objective in $wt (gate: ${check:-none})" \
578
+ "[$id] the assistant is working on this task now (check before review: ${check:-none})" >&2
579
+ rc=0
580
+ ( cd "$wt" && bash "$_LT_LIB_DIR/../autopilot-run.sh" "${pass[@]}" ) >&2 || rc=$?
581
+
582
+ if [ "$rc" -ne 0 ]; then
583
+ # Say why in one line of our own: the run's "resume with" hint does not apply here, because a
584
+ # re-run of `task run` starts over from the task record.
585
+ reason=""; detail=""
586
+ sfile="$(_lt_run_state_file "$wt" "$branch")"
587
+ if [ -n "$sfile" ] && [ -f "$sfile" ]; then
588
+ reason="$(jq -r '.reason // ""' "$sfile" 2>/dev/null || true)"
589
+ detail="$(jq -r '.detail // ""' "$sfile" 2>/dev/null || true)"
590
+ fi
591
+ echo "✗ task $id: no review was opened — the run stopped with exit $rc${reason:+ (reason=$reason${detail:+: $detail})}. The work so far is kept in $wt; 'cckit task run $id' starts the task over from its record." >&2
592
+ return "$rc"
593
+ fi
594
+
595
+ if [ "$finish" = 0 ]; then
596
+ _lt_say "[$id] the run is done; --no-finish: nothing was sent for review. When ready: cckit task finish $id \"<summary>\" --all" \
597
+ "[$id] the work is written; nothing was sent for review yet. When ready: cckit task finish $id \"<summary>\" --all" >&2
598
+ echo "$wt|$branch|$id"
599
+ return 0
600
+ fi
601
+ summary="Delegated with cckit task run: one headless round; gate: ${check:-none}$([ -n "$check" ] && printf ' (passed)' || true)."
602
+ lt_finish "$id" "$summary" --all || return 7
603
+ }
604
+
605
+ # ── share ───────────────────────────────────────────────────────────────────────────────────────
606
+ # _lt_share_body <ids> <summary> — the share pull request's body.
607
+ _lt_share_body() {
608
+ printf '## Tasks added\n\n%s\n\n## Summary\n\n%s\n\n## Review\n\nMerging adds these tasks to the shared list as `todo`. No work is included.\n' \
609
+ "$(printf '%s\n' "$1" | sed 's/^/- `/; s/$/`/')" "$2"
610
+ }
611
+
612
+ lt_share() {
613
+ local summary="" a root from base base_ref stamp branch wt ids n pr_title body rows
614
+ for a in "$@"; do
615
+ case "$a" in
616
+ -h|--help) _lt_usage; return 0 ;;
617
+ -*) echo "✗ task share: unknown flag '$a'" >&2; return 2 ;;
618
+ *) summary="${summary:+$summary }$a" ;;
619
+ esac
620
+ done
621
+ if ! task_source_has share; then
622
+ echo "✗ task share: the '$(task_source_name)' source has nothing to share — its tasks are not drafts in a checkout" >&2
623
+ return 1
624
+ fi
625
+ root="$(_lt_root)"; from="$(_lt_top)"
626
+ [ -n "$root" ] && [ -n "$from" ] || { echo "✗ task share: not inside a git repository" >&2; return 1; }
627
+ base="$(_lt_base)"
628
+ git -C "$root" fetch --quiet origin "$base" 2>/dev/null || true
629
+ rows="$(task_source_call list)" || return 1
630
+ n="$(printf '%s\n' "$rows" | awk -F'\t' '$2 == "draft"' | grep -c . || true)"
631
+ if [ "$n" -eq 0 ]; then
632
+ # Nothing new. A share branch of this repository whose tasks are not on the base branch yet is
633
+ # an earlier share: its push or its pull request may have failed, so run that step again. An
634
+ # open pull request is reported, not re-created.
635
+ branch="$(printf '%s\n' "$rows" | awk -F'\t' '$2 == "shared" && $6 ~ /^light\/share-/ && !hit { print $6; hit = 1 }')"
636
+ wt=""
637
+ if [ -n "$branch" ]; then wt="$(_lt_worktree_of "$root" "$branch")"; fi
638
+ if [ -z "$wt" ] || [ ! -d "$wt" ]; then echo "(no drafts to share in this checkout)"; return 0; fi
639
+ ids="$(printf '%s\n' "$rows" | awk -F'\t' -v b="$branch" '$2 == "shared" && $6 == b { print $1 }')"
640
+ n="$(printf '%s\n' "$ids" | grep -c . || true)"
641
+ pr_title="$(git -C "$wt" log -1 --format=%s 2>/dev/null || true)"
642
+ echo "[task] no new drafts; $n task(s) already committed on $branch" >&2
643
+ _lt_open_pr "$wt" "$branch" "$pr_title" "$(_lt_share_body "$ids" "${summary:-Adds $n task(s) to the list.}")"
644
+ return $?
645
+ fi
646
+ if git -C "$root" show-ref --verify --quiet "refs/remotes/origin/$base"; then base_ref="origin/$base"
647
+ else echo "✗ task share: origin has no branch '$base'" >&2; return 1; fi
648
+ stamp="$(date +%Y%m%d%H%M%S)"
649
+ branch="light/share-$stamp"
650
+ wt="$root/.claude/worktrees/light+share-$stamp"
651
+ git -C "$root" worktree add --no-track -b "$branch" "$wt" "$base_ref" >/dev/null 2>&1 \
652
+ || { echo "✗ task share: worktree add failed for $branch" >&2; return 1; }
653
+ ids="$(task_source_call share "$wt" "$from")" || true
654
+ n="$(printf '%s\n' "$ids" | grep -c . || true)"
655
+ if [ "$n" -eq 0 ]; then
656
+ git -C "$root" worktree remove --force "$wt" >/dev/null 2>&1 || true
657
+ git -C "$root" branch -D "$branch" >/dev/null 2>&1 || true
658
+ echo "(no drafts to share: the task files here are already tracked by git)"; return 0
659
+ fi
660
+ pr_title="chore(tasks): add $n task$([ "$n" -eq 1 ] || echo s) [share-$stamp]"
661
+ git -C "$wt" commit -q -m "$pr_title" >&2 || { echo "✗ task share: the commit failed in $wt" >&2; return 1; }
662
+ body="$(_lt_share_body "$ids" "${summary:-Adds $n task(s) to the list.}")"
663
+ echo "[task] moved $n draft(s) onto $branch — 'cckit task list' shows them as shared until the pull request merges" >&2
664
+ _lt_open_pr "$wt" "$branch" "$pr_title" "$body"
665
+ }
666
+
667
+ # ── dispatcher ──────────────────────────────────────────────────────────────────────────────────
668
+ # With --llm: list and next print JSON themselves; the action verbs are wrapped into one object.
669
+ lt_cli() {
670
+ local sub="${1:-}" out rc url rid
671
+ [ "$#" -gt 0 ] && shift
672
+ case "$sub" in
673
+ new) lt_new "$@" ;;
674
+ list|ls) lt_list "$@" ;;
675
+ next) lt_next "$@" ;;
676
+ start|take|finish|done|share|run)
677
+ case "$sub" in take) sub="start" ;; done) sub="finish" ;; esac
678
+ if cckit_is_json; then
679
+ _LT_RUN_ID_FILE=""
680
+ if [ "$sub" = run ]; then _LT_RUN_ID_FILE="$(mktemp 2>/dev/null || true)"; fi
681
+ out="$("lt_$sub" "$@" 2>&1)" && rc=0 || rc=$?
682
+ url="$(printf '%s\n' "$out" | grep -oE 'https://[^ ]+/pull/[0-9]+' | tail -1 || true)"
683
+ if [ "$sub" = run ]; then
684
+ rid=""
685
+ if [ -n "$_LT_RUN_ID_FILE" ]; then rid="$(cat "$_LT_RUN_ID_FILE" 2>/dev/null || true)"; rm -f "$_LT_RUN_ID_FILE"; fi
686
+ cckit_json verb "task run" ok "$([ "$rc" -eq 0 ] && echo true || echo false)" \
687
+ id "$rid" url "$url" detail "$(printf '%s\n' "$out" | tail -1)"
688
+ elif [ "$sub" = start ] && [ "$rc" -eq 0 ]; then
689
+ out="$(printf '%s\n' "$out" | tail -1)"
690
+ cckit_json verb "task start" ok true id "${out##*|}" worktree "${out%%|*}" \
691
+ branch "$(printf '%s' "$out" | cut -d'|' -f2)"
692
+ else
693
+ cckit_json verb "task $sub" ok "$([ "$rc" -eq 0 ] && echo true || echo false)" \
694
+ url "$url" detail "$(printf '%s\n' "$out" | tail -1)"
695
+ fi
696
+ return "$rc"
697
+ fi
698
+ "lt_$sub" "$@" ;;
699
+ default)
700
+ # Which list is this project's default (tasks.default). Read-only; no fetch, no gh.
701
+ out="$(task_default_name)"
702
+ if cckit_is_json; then cckit_json verb "task default" ok true default "$out"; else printf '%s\n' "$out"; fi ;;
703
+ -h|--help|help) _lt_usage; return 0 ;;
704
+ *) _lt_usage; return 2 ;;
705
+ esac
706
+ }