@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
@@ -28,6 +28,14 @@ if ! command -v effort_slug_resolve >/dev/null 2>&1; then
28
28
  unset _eo_dir
29
29
  fi
30
30
 
31
+ # The closed kind: vocabulary (KIT_KINDS / kit_kind_valid) — what `effort new --kind` accepts.
32
+ if ! command -v kit_kind_valid >/dev/null 2>&1; then
33
+ _eo_dir="$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" && pwd)"
34
+ # shellcheck source=/dev/null
35
+ [ -f "$_eo_dir/kinds.sh" ] && . "$_eo_dir/kinds.sh"
36
+ unset _eo_dir
37
+ fi
38
+
31
39
  # The GitHub transport switch (#396): in rest mode the lifecycle calls below are `gh api repos/…`.
32
40
  if ! command -v cckit_gh_rest >/dev/null 2>&1; then
33
41
  _eo_dir="$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" && pwd)"
@@ -125,8 +133,8 @@ _eff_board_add() {
125
133
  [ -n "$item" ] || return 0
126
134
  [ -n "${STATUS_FIELD_ID:-}" ] && [ -n "${STATUS_OPT_TODO:-}" ] \
127
135
  && project_set_single_select "$item" "$STATUS_FIELD_ID" "$STATUS_OPT_TODO" 2>/dev/null || true
128
- if [ -n "$role" ] && command -v role_option_id >/dev/null 2>&1; then
129
- ropt="$(role_option_id "$role" 2>/dev/null || echo "")"
136
+ if [ -n "$role" ] && [ -n "${ROLE_FIELD_ID:-}" ] && command -v role_option_id >/dev/null 2>&1; then
137
+ ropt="$(role_option_id "$role" || echo "")"
130
138
  [ -n "$ropt" ] && [ -n "${ROLE_FIELD_ID:-}" ] \
131
139
  && project_set_single_select "$item" "$ROLE_FIELD_ID" "$ropt" 2>/dev/null || true
132
140
  fi
@@ -146,7 +154,7 @@ effort_new() {
146
154
  local repo; repo="$(_eff_repo)"
147
155
  [ -n "$repo" ] || { echo "effort_new: no repo (KIT_REPO/EFFORT_REPO unset — run in a kit project)" >&2; return 1; }
148
156
 
149
- local flow="" role="" priority="p1" goal="" scope="" for_agents="" verification="" depends_on="" milestone="" explicit_slug="" par=""
157
+ local flow="" role="" priority="p1" goal="" scope="" for_agents="" verification="" depends_on="" milestone="" explicit_slug="" kind="task"
150
158
  # Flags are position-INDEPENDENT: recognized --flag [value] pairs are consumed wherever they occur
151
159
  # (before the title, between subs, or after them) and the remaining positionals are collected as the
152
160
  # title (first) + sub specs (rest). Previously the parser broke at the first positional, so any flag
@@ -166,8 +174,8 @@ effort_new() {
166
174
  --milestone) milestone="${2:-}"; shift 2 ;;
167
175
  --slug) explicit_slug="${2:-}"; shift 2 ;;
168
176
  --slug=*) explicit_slug="${1#*=}"; shift ;;
169
- --par) par="${2:-}"; shift 2 ;;
170
- --par=*) par="${1#*=}"; shift ;;
177
+ --kind) kind="${2:-}"; shift 2 ;;
178
+ --kind=*) kind="${1#*=}"; shift ;;
171
179
  --) shift; while [ $# -gt 0 ]; do pos+=("$1"); shift; done ;;
172
180
  --*) echo "effort_new: unknown flag $1" >&2; return 1 ;;
173
181
  *) pos+=("$1"); shift ;;
@@ -175,15 +183,13 @@ effort_new() {
175
183
  done
176
184
  set -- "${pos[@]+"${pos[@]}"}"
177
185
 
178
- # Parallelism hint label (#121): --par seq | wide | <positive-int> → a par:<value> label on the
179
- # parent (how the effort's subs are meant to run). Validated before anything is created.
180
- if [ -n "$par" ]; then
181
- case "$par" in
182
- seq|wide) : ;;
183
- ''|*[!0-9]*) echo "effort_new: --par must be 'seq', 'wide', or a positive integer (got '$par')" >&2; return 1 ;;
184
- *) : ;;
185
- esac
186
+ # --kind picks the kind:<k> label on the parent and every sub (default task). It is validated
187
+ # against the closed set (kinds.sh) before anything is created: `cckit start` turns the label into
188
+ # the branch prefix, so a value outside the set would yield a branch the hygiene hook rejects.
189
+ if command -v kit_kind_label_valid >/dev/null 2>&1 && ! kit_kind_label_valid "$kind"; then
190
+ echo "effort_new: --kind must be one of: $KIT_KINDS $KIT_CONTENT_KINDS (got '$kind')" >&2; return 1
186
191
  fi
192
+ [ -n "$kind" ] || { echo "effort_new: --kind needs a value" >&2; return 1; }
187
193
 
188
194
  local name="${1:-}"; shift || true
189
195
  [ -n "$name" ] || { echo 'effort_new: usage: effort_new [flags] "<name>" [<sub spec> …]' >&2; return 1; }
@@ -224,7 +230,7 @@ effort_new() {
224
230
  # Every kit-defined label is ensured before use — `gh issue create --label` fails hard on a
225
231
  # missing label, which aborted the whole parent create on repos without the ctx:* set (#153).
226
232
  _eff_ensure_label "$ctx" bfd4f2 "effort session weight"
227
- _eff_ensure_label "kind:task" d4c5f9 "kit issue kind"
233
+ _eff_ensure_label "kind:$kind" d4c5f9 "kit issue kind"
228
234
  _eff_ensure_label "priority:$priority" e99695 "kit priority"
229
235
  # `effort` is what marks the parent AS an effort, and it is the label `effort_plan` queries
230
236
  # (`gh issue list --label effort`, effort-plan.sh). It was read and never written: the label did
@@ -232,7 +238,7 @@ effort_new() {
232
238
  # every effort ever created here. A label something reads and nothing writes is the same defect
233
239
  # as one something writes and nothing reads — see rules/naming-and-ids.md § Labels.
234
240
  _eff_ensure_label "effort" 5319e7 "an effort parent issue"
235
- local labels="effort,$ctx,kind:task,priority:$priority"
241
+ local labels="effort,$ctx,kind:$kind,priority:$priority"
236
242
  if [ -n "$role" ]; then
237
243
  _eff_ensure_label "role:$role" 0e8a16 "kit role lane"
238
244
  labels="$labels,role:$role"
@@ -242,10 +248,6 @@ effort_new() {
242
248
  _eff_ensure_label "flow:$flow_lc" 1d76db "kit flow lane"
243
249
  labels="$labels,flow:$flow_lc"
244
250
  fi
245
- if [ -n "$par" ]; then
246
- _eff_ensure_label "par:$par" c5def5 "effort parallelism hint"
247
- labels="$labels,par:$par"
248
- fi
249
251
 
250
252
  local url num slug
251
253
  if cckit_gh_rest; then
@@ -290,7 +292,7 @@ effort_new() {
290
292
  sub_name="${spec%% :: *}"
291
293
  sub_desc="${spec#* :: }"; [ "$sub_desc" = "$spec" ] && sub_desc=""
292
294
  sub_title="[Effort $num] $i · $sub_name"
293
- local sub_labels="kind:task,priority:$priority"
295
+ local sub_labels="kind:$kind,priority:$priority"
294
296
  [ -n "$role" ] && sub_labels="$sub_labels,role:$role"
295
297
  if cckit_gh_rest; then
296
298
  child="$(gh_rest_issue_create "$repo" "$sub_title" \
@@ -440,7 +442,7 @@ effort_chain() {
440
442
  # wipe the issue. Only a successful read is edited.
441
443
  if ! body="$(_eff_issue_body "$repo" "$next" 2>/dev/null)"; then
442
444
  echo " ✗ could not read #$next's body — 'Depends on #$prev' not recorded" >&2; rc=1
443
- elif printf '%s\n' "$body" | grep -qE "^[[:space:]]*- Depends on #${prev}[[:space:]]*$"; then
445
+ elif grep -qE "^[[:space:]]*- Depends on #${prev}[[:space:]]*$" <<<"$body"; then
444
446
  echo " · #$next already records 'Depends on #$prev'" >&2
445
447
  else
446
448
  newbody="$(_eff_relations_add "$body" "$prev")"
@@ -648,7 +650,7 @@ effort_start() {
648
650
  [ -n "$raw" ] || { echo "effort_start: <slug|effort issue #> required" >&2; return 1; }
649
651
  num="$(effort_slug_resolve "$raw")" || { echo "effort_start: could not resolve '$raw' to an effort" >&2; return 1; }
650
652
  repo="$(_eff_repo)"; base="$(_eff_base)"
651
- root="$(git worktree list --porcelain 2>/dev/null | awk '/^worktree /{print $2; exit}')"
653
+ root="$(git worktree list --porcelain 2>/dev/null | awk '/^worktree / && !hit {print $2; hit=1}')"
652
654
  [ -n "$root" ] || { echo "effort_start: not in a git repo" >&2; return 1; }
653
655
 
654
656
  # WIP gate (#244) — BEFORE the fetch, the branch, the worktree and the bootstrap, so a refusal
@@ -657,9 +659,22 @@ effort_start() {
657
659
 
658
660
  if [ -n "$slug_override" ]; then slug="$(_eff_slug "$slug_override")"
659
661
  else
660
- if cckit_gh_rest; then title="$(gh api "repos/$repo/issues/$num" --jq .title 2>/dev/null)" || title=""
661
- else title="$(gh issue view "$num" --repo "$repo" --json title -q .title 2>/dev/null)"; fi
662
- slug="$(_eff_title_slug "${title:-effort}")"; [ -n "$slug" ] || slug="effort"
662
+ # A soft read (#330): the slug has a fallback, so a failed gh must not end the op — and under
663
+ # `set -e` a bare failed assignment did exactly that, rc 1 with no output. Failed is told apart
664
+ # from empty by gh's exit code, and said on stderr.
665
+ local title_rc=0
666
+ if cckit_gh_rest; then title="$(gh api "repos/$repo/issues/$num" --jq .title 2>/dev/null)" || title_rc=$?
667
+ else title="$(gh issue view "$num" --repo "$repo" --json title -q .title 2>/dev/null)" || title_rc=$?; fi
668
+ slug=""
669
+ if [ "$title_rc" -ne 0 ]; then
670
+ title=""
671
+ # An effort already started keeps its branch: a re-start during an outage must land on
672
+ # effort/<N>-<its slug>, not cut a second branch named after the fallback.
673
+ slug="$(git -C "$root" for-each-ref --format='%(refname:short)' "refs/heads/effort/$num-*" 2>/dev/null | sed -n 1p)"
674
+ slug="${slug#effort/"$num"-}"
675
+ echo "effort_start: could not read the title of issue #$num from GitHub (gh exited $title_rc) — continuing with the slug '${slug:-effort}'. To choose the slug: effort start $num <slug>" >&2
676
+ fi
677
+ [ -n "$slug" ] || slug="$(_eff_title_slug "${title:-effort}")"; [ -n "$slug" ] || slug="effort"
663
678
  fi
664
679
  # Worktree dir follows the kind+N-slug convention (branch-naming.md) so kit-gc's issue-open
665
680
  # protection recognizes it by DIRECTORY name too — matching the kit-effort-start skill (#119).
@@ -680,6 +695,13 @@ effort_start() {
680
695
  local from="origin/$base"; git -C "$root" rev-parse --verify --quiet "$from" >/dev/null 2>&1 || from="$base"
681
696
  git -C "$root" worktree add -b "$branch" "$wt" "$from" >/dev/null 2>&1 \
682
697
  || { echo "effort_start: failed to create worktree for $branch" >&2; return 1; }
698
+ # Stamp the effort's start (#453): `effort close` subtracts it for build_seconds. Only here,
699
+ # where the branch is created — a re-start of an effort begun earlier would stamp a start that
700
+ # is too late, and capture falls back to the branch's oldest commit instead. Best-effort.
701
+ _eo_source_metrics
702
+ if command -v record_effort_start >/dev/null 2>&1; then
703
+ ( cd "$root" && record_effort_start "$num" ) >/dev/null 2>&1 || true
704
+ fi
683
705
  fi
684
706
 
685
707
  # Bootstrap the worktree for local dev: copy gitignored env, assign a per-worktree dev port, and
@@ -698,7 +720,7 @@ effort_pr() {
698
720
  # [--for-agents A|--for-agents-file F] [--message M] [--title T]. SUMMARY / FOR_AGENTS / COMMIT_MSG env are
699
721
  # honoured as fallbacks.
700
722
  _eff_need gh || return 1
701
- local raw="" summary="${SUMMARY:-}" for_agents="${FOR_AGENTS:-}" msg="${COMMIT_MSG:-}" title_override=""
723
+ local raw="" summary="${SUMMARY:-}" for_agents="${FOR_AGENTS:-}" msg="${COMMIT_MSG:-}" title_override="" ctype=""
702
724
  while [ $# -gt 0 ]; do
703
725
  case "$1" in
704
726
  --summary) summary="${2:-}"; shift 2 ;;
@@ -707,6 +729,7 @@ effort_pr() {
707
729
  --for-agents-file) for_agents="$(cat "${2:-/dev/null}")"; shift 2 ;;
708
730
  --message|-m) msg="${2:-}"; shift 2 ;;
709
731
  --title) title_override="${2:-}"; shift 2 ;;
732
+ --type) ctype="${2:-}"; shift 2 ;;
710
733
  *) [ -z "$raw" ] && raw="$1"; shift ;;
711
734
  esac
712
735
  done
@@ -727,7 +750,7 @@ effort_pr() {
727
750
  title="$(printf '%s' "$meta" | jq -r '.title // ""' 2>/dev/null)"
728
751
  labels="$(printf '%s' "$meta" | jq -r '[.labels[]?.name] | join(",")' 2>/dev/null)"
729
752
  milestone="$(printf '%s' "$meta" | jq -r '.milestone.title // ""' 2>/dev/null)"
730
- role="$(printf '%s' "$labels" | tr ',' '\n' | sed -n 's/^role://p' | head -1)"
753
+ role="$(printf '%s' "$labels" | tr ',' '\n' | sed -n 's/^role://p' | sed -n 1p)"
731
754
  role_disp=""
732
755
  if [ -n "$role" ] && command -v role_display >/dev/null 2>&1; then
733
756
  role_disp="$(role_display "$role" 2>/dev/null || true)"
@@ -758,10 +781,24 @@ effort_pr() {
758
781
 
759
782
  # ONE shared composer (effort.sh) so every surface titles identically, then the mandatory-[#N]
760
783
  # check before we ever call gh — refuse rather than open an id-less PR (#121).
761
- # --title serves a repo whose PR titles follow another convention (Conventional Commits under a
762
- # commitlint gate); it must still carry the [#N] id, checked below.
763
- pr_title="${title_override:-$(effort_pr_title "$num" "${name:-effort}" "$role_disp")}"
784
+ # --title replaces the composed title; it must still carry the [#N] id, checked below.
785
+ pr_title="${title_override:-$(effort_pr_title "$num" "${name:-effort}" "$labels" "$ctype" "$role_disp")}"
764
786
  effort_pr_title_check "$pr_title" "$num" || { echo "effort_pr: refusing to open a PR without the [#$num] effort id" >&2; return 1; }
787
+ # #237: under pr.titleStyle = conventional (the default) the title becomes the squash commit the
788
+ # commitlint gate checks, so a title that gate rejects — composed (a bad --type) or passed with
789
+ # --title — is refused here, before gh. issue-title repos run no such gate and skip the check.
790
+ if [ "${KIT_PR_TITLE_STYLE:-conventional}" != "issue-title" ]; then
791
+ if ! command -v commitlint_check >/dev/null 2>&1; then
792
+ local _cl_dir; _cl_dir="$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" 2>/dev/null && pwd)"
793
+ # shellcheck source=/dev/null
794
+ [ -f "$_cl_dir/commitlint.sh" ] && . "$_cl_dir/commitlint.sh"
795
+ fi
796
+ if command -v commitlint_check >/dev/null 2>&1; then
797
+ commitlint_check "$pr_title" || { echo "effort_pr: refusing to open a PR whose title is not a Conventional Commit subject (pass --type <type> or --title, or set pr.titleStyle to issue-title)" >&2; return 1; }
798
+ else
799
+ echo "effort_pr: commitlint.sh not found — the PR title was not checked against Conventional Commits" >&2
800
+ fi
801
+ fi
765
802
  body="$(_eff_pr_body "$num" "$summary" "$for_agents" "$role")"
766
803
 
767
804
  # Four explicit forms, not ${x:+--flag "$x"}: that idiom word-splits under zsh, and this file is
@@ -793,6 +830,16 @@ _eff_pr_body() {
793
830
  if [ -n "$role" ] && command -v role_signature >/dev/null 2>&1; then
794
831
  sig="$(role_signature "$role" 2>/dev/null || true)"
795
832
  fi
833
+ # pr.bodyStyle = content (KIT_PR_BODY_STYLE, #418): draft-and-review wording for content work.
834
+ # `Closes #N`, the Summary and the For agents block are the same in both styles.
835
+ if [ "${KIT_PR_BODY_STYLE:-code}" = "content" ]; then
836
+ printf '## For the orchestrator\n\nEffort #%s — one PR for the whole effort. Review: the summary below and the changed files.\n\nCloses #%s\n\n' "$num" "$num"
837
+ printf '## Summary\n\n%s\n\n' "${summary:-_(no summary given — pass --summary)_}"
838
+ printf '## For agents\n\n%s\n\n' "${for_agents:-See #$num for the goal, scope, and entry points.}"
839
+ printf '## Review\n\n- [ ] Every piece the summary lists is in the changed files\n- [ ] Facts, names, numbers and links are checked\n- [ ] The voice matches the brand guide\n- [ ] Only the files for this work changed\n- [ ] Labels + milestone match the parent issue\n'
840
+ [ -n "$sig" ] && printf '\n%s\n' "$sig"
841
+ return 0
842
+ fi
796
843
  printf '## For the orchestrator\n\nEffort #%s — one PR for the whole effort. Review: the summary below + the diff.\n\nCloses #%s\n\n' "$num" "$num"
797
844
  printf '## Summary\n\n%s\n\n' "${summary:-_(no summary given — pass --summary)_}"
798
845
  printf '## For agents\n\n%s\n\n' "${for_agents:-See #$num for the goal, scope, and entry points.}"
@@ -810,7 +857,7 @@ _eff_pr_board() {
810
857
  _eo_source_board
811
858
  command -v project_add_item >/dev/null 2>&1 || return 0
812
859
  repo="$(_eff_repo)"; pr_num="${url##*/}"
813
- node="$(gh api "repos/$repo/pulls/$pr_num" --jq .node_id 2>/dev/null)"
860
+ node="$(gh api "repos/$repo/pulls/$pr_num" --jq .node_id 2>/dev/null)" || node=""
814
861
  item=""
815
862
  [ -n "$node" ] && item="$(project_add_item "$node" 2>/dev/null || true)"
816
863
  if [ -z "$item" ]; then
@@ -820,7 +867,7 @@ _eff_pr_board() {
820
867
  project_set_single_select "$item" "$STATUS_FIELD_ID" "$STATUS_OPT_IN_REVIEW" >/dev/null 2>&1 || true
821
868
  fi
822
869
  if [ -n "$role" ] && [ -n "${ROLE_FIELD_ID:-}" ] && command -v role_option_id >/dev/null 2>&1; then
823
- ropt="$(role_option_id "$role" 2>/dev/null || true)"
870
+ ropt="$(role_option_id "$role" || true)"
824
871
  [ -n "$ropt" ] && { project_set_single_select "$item" "$ROLE_FIELD_ID" "$ropt" >/dev/null 2>&1 || true; }
825
872
  fi
826
873
  fi
@@ -893,19 +940,36 @@ _eo_board_done() {
893
940
 
894
941
  # Kit-managed paths (the kit ⇄ project sync surface): a change here that is not contributed
895
942
  # upstream (/kit-contribute) is a latent regression the next /kit-update can clobber. One place —
896
- # effort_close's drift check greps against this (was inlined in the kit-effort-close skill, #148).
897
- _EO_KIT_MANAGED_RE='^(scripts/(lib/|kit$|kit-)|\.claude/(skills|rules|hooks|lib|agents)/)'
943
+ # effort_close's drift check greps against this (was inlined in the kit-effort-close skill, #148),
944
+ # and so does the task-merge drift check in the kit-task-pr-merge skill.
945
+ # .claude/rules/ is matched by BASENAME, not as a directory (#218): init.sh writes a rule only from
946
+ # templates/rules/<name>.md, so any other file there is the project's own and no /kit-update can
947
+ # touch it. The list is the templates/rules basenames; effort-ops-test.sh fails when they differ.
948
+ _EO_KIT_MANAGED_RE='^(scripts/(lib/|kit$|kit-)|\.claude/(skills|hooks|lib|agents)/|\.claude/rules/(authoring|branch-naming|code-retrieval|communication-style|delegation-brief|design-routing|effort-model|gate-and-review|issue-lifecycle|knowledge-base|mempalace|merge-safety|naming-and-ids|plain-language|plan-next|plan-output-format|react-annotate|review-pages|risk-tiered-review|shared-checkout|skill-gaps|task-management)\.md$)'
898
949
 
899
950
  # _eo_knowledge_ingest <num> <trace_dir> <root> — optional post-close knowledge-ingest hook. Runs a
900
951
  # project-configured command (github/effort.knowledgeIngestHook, or KIT_EFFORT_KNOWLEDGE_HOOK) with
901
952
  # the effort number + trace dir, so a project can fold the closed effort's work record into its
902
953
  # knowledge base. Config-gated: a NO-OP when unset or the hook file is missing/not executable — the
903
954
  # kit ships no default hook. Best-effort — a hook failure never fails the close.
955
+ #
956
+ # The config is read AFTER the close removed the effort worktree, and bin/cckit exports KIT_CONFIG as
957
+ # the copy inside that worktree (#518). So a KIT_CONFIG that no longer exists falls back to the main
958
+ # checkout's config; when that is missing too the close says so — a config that vanished is not the
959
+ # same as a project with no hook. The hook's stdout + stderr go to stderr, like the pre-close hook's.
904
960
  _eo_knowledge_ingest() {
905
961
  local num="$1" trace="$2" root="$3" hook="" cfg
906
962
  hook="${KIT_EFFORT_KNOWLEDGE_HOOK:-}"
907
963
  if [ -z "$hook" ]; then
908
- cfg="${KIT_CONFIG:-}"; [ -n "$cfg" ] || { [ -f "$root/cckit.config.json" ] && cfg="$root/cckit.config.json" || cfg="$root/.claude/kit.config.json"; }
964
+ cfg="${KIT_CONFIG:-}"
965
+ if [ -z "$cfg" ] || [ ! -f "$cfg" ]; then
966
+ if [ -f "$root/cckit.config.json" ]; then cfg="$root/cckit.config.json"
967
+ elif [ -f "$root/.claude/kit.config.json" ]; then cfg="$root/.claude/kit.config.json"
968
+ elif [ -n "$cfg" ]; then
969
+ echo "effort_close: project config '$cfg' went away with the worktree and the main checkout has none — post-close hook not read" >&2
970
+ return 0
971
+ fi
972
+ fi
909
973
  [ -f "$cfg" ] && command -v jq >/dev/null 2>&1 \
910
974
  && hook="$(jq -r '.effort.knowledgeIngestHook // empty' "$cfg" 2>/dev/null)"
911
975
  fi
@@ -915,7 +979,69 @@ _eo_knowledge_ingest() {
915
979
  echo " → knowledge-ingest hook: $hook $num" >&2
916
980
  # Run it from the main checkout (#371): the close has just removed the worktree it was invoked from,
917
981
  # so the inherited cwd no longer exists and a hook's relative paths / bare git calls would fail.
918
- ( cd "${root:-/}" && "$hook" "$num" "$trace" ) >/dev/null 2>&1 || echo "effort_close: knowledge-ingest hook failed (non-fatal)" >&2
982
+ ( cd "${root:-/}" && "$hook" "$num" "$trace" ) 1>&2 || echo "effort_close: knowledge-ingest hook failed (non-fatal)" >&2
983
+ }
984
+
985
+ # _eo_dependent_prs <branch> — pure selector (#358): `gh pr list --json number,baseRefName` on stdin,
986
+ # the numbers of the PRs whose base is exactly <branch> on stdout, one per line. Empty stdin prints
987
+ # nothing; input that is not a JSON array is rc 1, so the caller can tell "none" from "unreadable".
988
+ _eo_dependent_prs() {
989
+ jq -r --arg b "$1" 'if type == "array" then .[] | select(.baseRefName == $b) | .number else error("not a list") end' 2>/dev/null
990
+ }
991
+
992
+ # _eo_retarget_dependents <repo> <branch> <base> — re-target every open PR based on <branch> to
993
+ # <base> (#358). GitHub closes a PR, unmerged, the moment its base branch is deleted, and the squash
994
+ # below deletes <branch>. rc 1 when the list cannot be read or an edit fails: the caller refuses the
995
+ # close, because either one means a PR would be closed by the delete.
996
+ _eo_retarget_dependents() {
997
+ local repo="$1" branch="$2" base="$3" json deps dep
998
+ json="$(gh pr list --repo "$repo" --base "$branch" --state open --limit 200 --json number,baseRefName 2>/dev/null)" \
999
+ && deps="$(printf '%s' "$json" | _eo_dependent_prs "$branch")" \
1000
+ || { echo "effort_close: could not list the open PRs based on $branch — deleting it would close any that exist. Rerun when 'gh pr list --base $branch' works (nothing was merged)" >&2; return 1; }
1001
+ while IFS= read -r dep; do
1002
+ [ -n "$dep" ] || continue
1003
+ gh pr edit "$dep" --repo "$repo" --base "$base" >/dev/null 2>&1 \
1004
+ || { echo "effort_close: PR $dep is based on $branch and could not be re-targeted to $base — deleting the branch would close it. Run 'gh pr edit $dep --base $base', then rerun (nothing was merged)" >&2; return 1; }
1005
+ echo " ↻ PR $dep re-targeted to $base" >&2
1006
+ done <<EOF_DEPS
1007
+ $deps
1008
+ EOF_DEPS
1009
+ }
1010
+
1011
+ # _eo_pre_close_hook <num> <repo> <root> <cwd> [<subs>] — optional project gate that runs BEFORE the
1012
+ # close writes anything (#380). Runs a project-configured command (effort.preCloseHook, or
1013
+ # KIT_EFFORT_PRE_CLOSE_HOOK) as `<hook> <effort#> <sub#…>` with cwd = <cwd> (the effort worktree; the
1014
+ # checkout the close was run from on the wave path). <subs> is a newline-separated sub list; when
1015
+ # omitted the native sub-issues are read from GitHub. Returns 1 — the caller refuses the close —
1016
+ # when the hook exits non-zero, or is configured but not executable: a gate that cannot run must not
1017
+ # pass. The hook's stdout + stderr go to stderr. KIT_FORCE=1 skips the hook and says so. A NO-OP
1018
+ # (rc 0, no GitHub read) when no hook is configured — the kit ships no default hook.
1019
+ _eo_pre_close_hook() {
1020
+ local num="$1" repo="$2" root="$3" cwd="$4" subs="${5:-}" hook="" cfg sub rc
1021
+ hook="${KIT_EFFORT_PRE_CLOSE_HOOK:-}"
1022
+ if [ -z "$hook" ]; then
1023
+ cfg="${KIT_CONFIG:-}"; [ -n "$cfg" ] || { [ -f "$root/cckit.config.json" ] && cfg="$root/cckit.config.json" || cfg="$root/.claude/kit.config.json"; }
1024
+ [ -f "$cfg" ] && command -v jq >/dev/null 2>&1 \
1025
+ && hook="$(jq -r '.effort.preCloseHook // empty' "$cfg" 2>/dev/null)"
1026
+ fi
1027
+ [ -n "$hook" ] || return 0
1028
+ case "$hook" in /*) : ;; *) hook="$root/$hook" ;; esac # resolve a relative hook against the root
1029
+ if [ "${KIT_FORCE:-0}" = "1" ]; then
1030
+ echo "effort_close: pre-close hook '$hook' skipped (KIT_FORCE=1)" >&2; return 0
1031
+ fi
1032
+ [ -x "$hook" ] || { echo "effort_close: pre-close hook '$hook' is configured but not executable — refusing to close #$num (nothing was written). Fix effort.preCloseHook, or set KIT_FORCE=1 to skip it." >&2; return 1; }
1033
+ [ "$#" -ge 5 ] || subs="$(gh api "repos/$repo/issues/$num/sub_issues" --jq '.[].number' 2>/dev/null)"
1034
+ set -- "$num"
1035
+ while IFS= read -r sub; do
1036
+ [ -n "$sub" ] && set -- "$@" "$sub"
1037
+ done <<EOF_SUBS
1038
+ $subs
1039
+ EOF_SUBS
1040
+ echo " → pre-close hook: $hook $*" >&2
1041
+ ( cd "${cwd:-.}" && "$hook" "$@" ) 1>&2; rc=$?
1042
+ [ "$rc" -eq 0 ] && return 0
1043
+ echo "effort_close: pre-close hook exited $rc — refusing to close #$num (nothing was written). Fix what it reports, or set KIT_FORCE=1 to skip it." >&2
1044
+ return 1
919
1045
  }
920
1046
 
921
1047
  # effort_close <N> — the SINGLE close implementation (#148): the /kit-effort-close skill is a thin
@@ -938,16 +1064,20 @@ effort_close() {
938
1064
  # just the wrong cwd — keep the instruction. If it exists NOWHERE, this is a WAVE-style
939
1065
  # effort (#164): the subs shipped as individual task PRs squash-merged straight to base, so
940
1066
  # there is no branch to run from — close via the merged sub PRs instead.
941
- if git branch --list "effort/$num-*" 2>/dev/null | grep -q . \
942
- || git ls-remote --heads origin "effort/$num-*" 2>/dev/null | grep -q .; then
1067
+ if [ -n "$(git branch --list "effort/$num-*" 2>/dev/null)" ] \
1068
+ || [ -n "$(git ls-remote --heads origin "effort/$num-*" 2>/dev/null)" ]; then
943
1069
  echo "effort_close: run from the effort/$num-… branch" >&2; return 1
944
1070
  fi
945
1071
  _eo_close_wave "$num" "$repo" "$base"; return $? ;;
946
1072
  esac
947
- root="$(git worktree list --porcelain 2>/dev/null | awk '/^worktree /{print $2; exit}')"
1073
+ root="$(git worktree list --porcelain 2>/dev/null | awk '/^worktree / && !hit {print $2; hit=1}')"
948
1074
  self_wt="$(git rev-parse --show-toplevel 2>/dev/null)"
949
1075
  _eo_source_metrics
950
1076
 
1077
+ # (pre) optional project gate (effort.preCloseHook, #380) — before the snapshot, so a refusal
1078
+ # writes nothing: no trace, no metrics row, no merge.
1079
+ _eo_pre_close_hook "$num" "$repo" "$root" "$self_wt" || return 1
1080
+
951
1081
  # (a) snapshot the per-sub-issue diffs while the unsquashed history still exists (echoes the trace dir).
952
1082
  trace_dir="$(effort_snapshot_subs "$num" "origin/$base" 2>/dev/null)"
953
1083
 
@@ -970,16 +1100,36 @@ effort_close() {
970
1100
  # row the retry duplicates with build_seconds null. UNKNOWN (GitHub still computing) proceeds.
971
1101
  local rest_pr="" mergeable
972
1102
  if cckit_gh_rest; then
973
- rest_pr="$(gh_rest_pr_for_head "$repo" "$branch" 2>/dev/null)"
974
- mergeable=""; [ -n "$rest_pr" ] && mergeable="$(gh_rest_pr_json "$repo" "$rest_pr" 2>/dev/null | jq -r .mergeable)"
1103
+ # Same refusal as the graphql branch below (#330): a failed read, or no open PR, must stop here.
1104
+ # Carrying on let the capture write its row and consume the start marker before the merge failed.
1105
+ local rest_meta=""
1106
+ rest_pr="$(gh_rest_pr_for_head "$repo" "$branch" 2>/dev/null)" || rest_pr=""
1107
+ [ -n "$rest_pr" ] && rest_meta="$(gh_rest_pr_json "$repo" "$rest_pr" 2>/dev/null)" || rest_meta=""
1108
+ [ -n "$rest_meta" ] || {
1109
+ echo "effort_close: could not read the PR for $branch from GitHub (gh failed: no PR, or the API is unavailable) — rerun when it answers (nothing was written)" >&2
1110
+ return 1
1111
+ }
1112
+ mergeable="$(printf '%s' "$rest_meta" | jq -r .mergeable)"
975
1113
  else
976
- mergeable="$(gh pr view "$branch" --repo "$repo" --json mergeable -q .mergeable 2>/dev/null)"
1114
+ # A failed read is not "mergeable" (#330). Under `set -e` this bare assignment ended the close
1115
+ # with rc 1 and no output; refusing by name keeps the nothing-written guarantee this step is for.
1116
+ mergeable="$(gh pr view "$branch" --repo "$repo" --json mergeable -q .mergeable 2>/dev/null)" || {
1117
+ echo "effort_close: could not read the PR for $branch from GitHub (gh failed: no PR, or the API is unavailable) — rerun when it answers (nothing was written)" >&2
1118
+ return 1
1119
+ }
977
1120
  fi
978
1121
  if [ "$mergeable" = "CONFLICTING" ]; then
979
1122
  echo "effort_close: the PR for $branch conflicts with $base — merge or rebase $base into it, then rerun (nothing was written)" >&2
980
1123
  return 1
981
1124
  fi
982
1125
 
1126
+ # (a3) re-target the open PRs based on this branch before the squash deletes it (#358). Here, not
1127
+ # next to the merge, for the same reason as the conflict check: a refusal after the capture leaves
1128
+ # a records.jsonl row the retry duplicates. Skipped over REST, where the remote branch is kept.
1129
+ if ! cckit_gh_rest; then
1130
+ _eo_retarget_dependents "$repo" "$branch" "$base" || return 1
1131
+ fi
1132
+
983
1133
  # (b) capture effort metrics PRE-squash (needs the live-branch diff + commit signals).
984
1134
  command -v capture_effort_metrics >/dev/null 2>&1 && capture_effort_metrics "$num" "origin/$base" || true
985
1135
 
@@ -1073,7 +1223,7 @@ _eo_kit_sync_warn() {
1073
1223
  # merged PR diffs in the trace are the work record.
1074
1224
  _eo_close_wave() {
1075
1225
  local num="$1" repo="$2" base="$3" root rows bad trace_dir kit_touched sub
1076
- root="$(git worktree list --porcelain 2>/dev/null | awk '/^worktree /{print $2; exit}')"
1226
+ root="$(git worktree list --porcelain 2>/dev/null | awk '/^worktree / && !hit {print $2; hit=1}')"
1077
1227
  _eo_source_metrics
1078
1228
 
1079
1229
  # (a) read every sub + the merged PR that closed it, one "sub|state|pr|merge-oid|title" line each
@@ -1101,6 +1251,11 @@ _eo_close_wave() {
1101
1251
  return 1
1102
1252
  fi
1103
1253
 
1254
+ # (pre) the same optional project gate as the branch path (#380), before the trace is written.
1255
+ # There is no effort worktree here, so it runs from the checkout the close was invoked in.
1256
+ _eo_pre_close_hook "$num" "$repo" "$root" "$(git rev-parse --show-toplevel 2>/dev/null)" \
1257
+ "$(printf '%s\n' "$rows" | cut -d'|' -f1)" || return 1
1258
+
1104
1259
  # (c) the work trace, from the merged sub PR diffs (the record the per-sub squashes left behind).
1105
1260
  # Same refuse-without-trace backstop as the branch path (#120) — KIT_FORCE=1 overrides.
1106
1261
  trace_dir="$(effort_snapshot_merged_subs "$num" "$rows" 2>/dev/null)"
@@ -98,26 +98,62 @@ tc "$GH_LOG" '## Verification' "bare call still emits ## Verification"
98
98
  tc "$GH_LOG" '<!--' "bare call leaves the template placeholders (nothing to fill)"
99
99
 
100
100
  # ── #121: the ONE shared effort-PR title composer + the mandatory-[#N] check ─────────────────────
101
- t "effort_pr_title composes [#N] name" "$(effort_pr_title 115 'adoption hardening')" "[#115] adoption hardening"
102
- t "effort_pr_title with a role prefix" "$(effort_pr_title 115 'adoption hardening' 'Tech Lead')" "[Tech Lead] [#115] adoption hardening"
103
- t "effort_pr_title peels an [Effort] prefix" "$(effort_pr_title 115 '[Effort] 115 · [Core] adoption hardening')" "[#115] [Core] adoption hardening"
104
- t "effort_pr_title tolerates a #-prefixed num" "$(effort_pr_title '#42' 'x')" "[#42] x"
101
+ # #237: the composed title is a Conventional Commit subject carrying [#N] — the form the
102
+ # commitlint gate accepts — so `effort pr` never opens a PR its own CI rejects.
103
+ # shellcheck source=/dev/null
104
+ source "$LIB/commitlint.sh"
105
+ unset KIT_PR_TITLE_STYLE
106
+ t "effort_pr_title composes type: name [#N]" "$(effort_pr_title 115 'adoption hardening')" "feat: adoption hardening [#115]"
107
+ t "effort_pr_title takes the scope from flow:" "$(effort_pr_title 115 'adoption hardening' 'role:tech-lead,kind:task,flow:core')" "feat(core): adoption hardening [#115]"
108
+ t "effort_pr_title peels [Effort] + uses [Flow] as scope" "$(effort_pr_title 115 '[Effort] 115 · [Core] adoption hardening')" "feat(core): adoption hardening [#115]"
109
+ t "effort_pr_title flow: label wins over the [Flow] tag" "$(effort_pr_title 115 '[Effort] 115 · [Core] adoption hardening' 'flow:docs')" "feat(docs): adoption hardening [#115]"
110
+ t "effort_pr_title drops a tag that is no valid scope" "$(effort_pr_title 115 '[¡Hola!] adoption hardening')" "feat: adoption hardening [#115]"
111
+ t "effort_pr_title tolerates a #-prefixed num" "$(effort_pr_title '#42' 'x')" "feat: x [#42]"
112
+ t "effort_pr_title derives the type from kind:" "$(effort_pr_title 115 'x' 'kind:chore,flow:core')" "chore(core): x [#115]"
113
+ t "effort_pr_title maps a bug label to fix" "$(effort_pr_title 115 'x' 'bug,kind:task')" "fix: x [#115]"
114
+ t "effort_pr_title explicit type wins" "$(effort_pr_title 115 'x' 'kind:chore' fix)" "fix: x [#115]"
115
+ t "effort_pr_title issue-title style keeps [Role] [#N] name" "$(KIT_PR_TITLE_STYLE=issue-title effort_pr_title 115 '[Effort] 115 · [Core] adoption hardening' 'flow:core' '' 'Tech Lead')" "[Tech Lead] [#115] [Core] adoption hardening"
116
+ t "effort_pr_title issue-title style without a role" "$(KIT_PR_TITLE_STYLE=issue-title effort_pr_title 115 'adoption hardening')" "[#115] adoption hardening"
117
+ _t237="$(effort_pr_title 220 '[Effort] 220 · [Core] agents cannot see what cckit provides' 'flow:core,kind:task,role:tech-lead')"
118
+ t "the #237 reproduction composes the conventional form" "$_t237" "feat(core): agents cannot see what cckit provides [#220]"
119
+ commitlint_check "$_t237" 2>/dev/null; t "the generated title passes commitlint_check" "$?" "0"
120
+ effort_pr_title_check "$_t237" 220 2>/dev/null; t "the generated title carries the [#N] id" "$?" "0"
105
121
  effort_pr_title_check "[Tech Lead] [#115] adoption hardening" 115; t "check accepts a title carrying [#N]" "$?" "0"
106
122
  effort_pr_title_check "[Effort] 115 · adoption hardening" 115 2>/dev/null; t "check refuses a title lacking [#N]" "$?" "1"
107
123
  effort_pr_title_check "[#7] anything" 2>/dev/null; t "check accepts any [#N] when no num given" "$?" "0"
108
124
 
109
- # ── #121: --par applies a par:<value> label on the parent; bad values are rejected up front ───────
125
+ # ── #277: --kind picks the kind: label (parent + subs) from the closed set; --par is gone ──────────
126
+ : > "$GH_LOG"; printf '0' > "$GH_N"
127
+ effort_new --flow Core --kind fix "kind fix effort" "a :: x" >/dev/null 2>&1
128
+ tc "$GH_LOG" 'issue create .*--title \[Effort\] · .*--label effort,ctx:[SMLX]+,kind:fix,' "--kind fix labels the parent kind:fix"
129
+ tc "$GH_LOG" 'issue create .*--title \[Effort 1\] 1 · a.*--label kind:fix,' "--kind fix labels every sub kind:fix"
130
+ tc "$GH_LOG" 'label create kind:fix' "--kind ensures the kind label exists"
131
+ tn "$GH_LOG" 'kind:task' "--kind fix leaves no kind:task behind"
110
132
  : > "$GH_LOG"; printf '0' > "$GH_N"
111
- effort_new --flow Core --par wide "parallel wide effort" "a :: x" "b :: y" >/dev/null 2>&1
112
- tc "$GH_LOG" 'issue create .*--label [^ ]*,par:wide' "--par wide adds a par:wide label to the parent"
113
- tc "$GH_LOG" 'label create par:wide' "--par creates the par:wide label idempotently"
133
+ effort_new --kind=chore "kind chore effort" >/dev/null 2>&1
134
+ tc "$GH_LOG" 'issue create .*--label effort,ctx:[SMLX]+,kind:chore,' "--kind=chore (equals form) is accepted"
135
+ for k in $KIT_KINDS; do
136
+ : > "$GH_LOG"; printf '0' > "$GH_N"
137
+ effort_new --kind "$k" "kind vocabulary effort" >/dev/null 2>&1 && rc=0 || rc=1
138
+ t "--kind $k is accepted" "$rc" "0"
139
+ done
140
+ for k in $KIT_CONTENT_KINDS; do
141
+ : > "$GH_LOG"; printf '0' > "$GH_N"
142
+ effort_new --kind "$k" "content kind effort" >/dev/null 2>&1 && rc=0 || rc=1
143
+ t "--kind $k (content kind) is accepted" "$rc" "0"
144
+ tc "$GH_LOG" "issue create .*--label effort,ctx:[SMLX]+,kind:$k," "--kind $k labels the parent kind:$k"
145
+ done
146
+ t "effort_pr_title: a content kind titles as docs" "$(effort_pr_title 115 'spring launch' 'kind:campaign')" "docs: spring launch [#115]"
114
147
  : > "$GH_LOG"; printf '0' > "$GH_N"
115
- effort_new --par 3 "parallel three effort" >/dev/null 2>&1
116
- tc "$GH_LOG" 'issue create .*--label [^ ]*,par:3' "--par 3 adds a par:3 label"
148
+ err="$(effort_new --kind bug "bad kind effort" 2>&1 >/dev/null)" && rc=0 || rc=1
149
+ t "--kind rejects a value outside the closed set" "$rc" "1"
150
+ t "--kind creates nothing on a bad value" "$(grep -c 'issue create' "$GH_LOG")" "0"
151
+ t "the refusal lists the accepted set" "$(printf '%s' "$err" | grep -c "must be one of: $KIT_KINDS")" "1"
117
152
  : > "$GH_LOG"; printf '0' > "$GH_N"
118
- effort_new --par nonsense "bad par effort" >/dev/null 2>&1 && rc=0 || rc=1
119
- t "--par rejects a non seq/wide/int value" "$rc" "1"
120
- t "--par creates nothing on a bad value" "$(grep -c 'issue create' "$GH_LOG")" "0"
153
+ effort_new --par wide "parallel wide effort" >/dev/null 2>&1 && rc=0 || rc=1
154
+ t "--par is no longer a flag (rc 1)" "$rc" "1"
155
+ t "--par creates nothing" "$(grep -c . "$GH_LOG")" "0"
156
+ t "nothing in effort-ops.sh writes a par: label" "$(grep -c 'par:' "$LIB/effort-ops.sh" | tr -d ' ')" "0"
121
157
 
122
158
  # ── #121: flags are position-INDEPENDENT — trailing --flow/--role no longer become junk sub-issues ─
123
159
  : > "$GH_LOG"; printf '0' > "$GH_N"