@jeiemgi/cckit 0.10.0 → 0.12.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 (193) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/AGENTS.md +136 -127
  3. package/README.md +66 -43
  4. package/bin/cckit +151 -181
  5. package/cckit.config.json +1 -4
  6. package/package.json +1 -1
  7. package/scripts/advisor-test.sh +55 -0
  8. package/scripts/autopilot-run-test.sh +20 -12
  9. package/scripts/autopilot-run.sh +9 -1
  10. package/scripts/autopilot-test.sh +29 -13
  11. package/scripts/autopilot.sh +4 -4
  12. package/scripts/benchmark/verb-timings-test.sh +4 -0
  13. package/scripts/benchmark/verb-timings.sh +16 -5
  14. package/scripts/capture-project-ids.sh +23 -1
  15. package/scripts/check.sh +25 -0
  16. package/scripts/content-skills-test.sh +1 -1
  17. package/scripts/contribute.sh +8 -3
  18. package/scripts/copilot-loop-test.sh +66 -81
  19. package/scripts/exec-targets-test.sh +20 -0
  20. package/scripts/force-push-fence-test.sh +44 -0
  21. package/scripts/force-push-fence.baseline +1 -0
  22. package/scripts/force-push-fence.sh +51 -0
  23. package/scripts/forge-fence-test.sh +69 -0
  24. package/scripts/forge-fence.baseline +2 -0
  25. package/scripts/forge-fence.sh +76 -0
  26. package/scripts/forge-report-test.sh +100 -0
  27. package/scripts/forge-report.sh +176 -0
  28. package/scripts/init-guided-test.sh +94 -82
  29. package/scripts/init.sh +12 -7
  30. package/scripts/install-test.sh +26 -0
  31. package/scripts/install.sh +7 -0
  32. package/scripts/instruction-budget-baseline.txt +1 -1
  33. package/scripts/kit-doctor-test.sh +60 -12
  34. package/scripts/kit-doctor.sh +170 -77
  35. package/scripts/lib/agent-resolve-test.sh +2 -0
  36. package/scripts/lib/agent-resolve.sh +15 -8
  37. package/scripts/lib/board-view.sh +3 -3
  38. package/scripts/lib/captain.sh +37 -8
  39. package/scripts/lib/content-kinds-gc-test.sh +22 -21
  40. package/scripts/lib/copilot-test.sh +20 -11
  41. package/scripts/lib/copilot.sh +19 -13
  42. package/scripts/lib/effort-close-subs-test.sh +96 -0
  43. package/scripts/lib/effort-dispatch-test.sh +5 -3
  44. package/scripts/lib/effort-metrics-test.sh +7 -12
  45. package/scripts/lib/effort-metrics.sh +17 -46
  46. package/scripts/lib/effort-ops-test.sh +261 -167
  47. package/scripts/lib/effort-ops.sh +449 -171
  48. package/scripts/lib/effort-parity-test.sh +57 -62
  49. package/scripts/lib/effort-plan-test.sh +56 -54
  50. package/scripts/lib/effort-plan.sh +14 -7
  51. package/scripts/lib/effort-review-test.sh +107 -0
  52. package/scripts/lib/effort-review.sh +93 -0
  53. package/scripts/lib/effort-slug-test.sh +34 -14
  54. package/scripts/lib/effort-slug.sh +13 -13
  55. package/scripts/lib/effort.sh +58 -80
  56. package/scripts/lib/forge-github.sh +260 -0
  57. package/scripts/lib/forge-none.sh +24 -0
  58. package/scripts/lib/forge-test.sh +186 -0
  59. package/scripts/lib/forge.sh +133 -0
  60. package/scripts/lib/gh-board-add-test.sh +118 -0
  61. package/scripts/lib/gh-project-test.sh +151 -31
  62. package/scripts/lib/gh-project.sh +139 -11
  63. package/scripts/lib/gh-rest-test.sh +63 -118
  64. package/scripts/lib/gh-rest.sh +275 -52
  65. package/scripts/lib/git-core-test.sh +128 -0
  66. package/scripts/lib/grill-record-test.sh +49 -0
  67. package/scripts/lib/grill-record.sh +88 -0
  68. package/scripts/lib/handoff.sh +1 -1
  69. package/scripts/lib/init-github.sh +38 -13
  70. package/scripts/lib/kinds-test.sh +13 -16
  71. package/scripts/lib/kit-brief-test.sh +51 -10
  72. package/scripts/lib/kit-brief.sh +103 -18
  73. package/scripts/lib/kit-gc-test.sh +90 -109
  74. package/scripts/lib/kit-gc.sh +19 -22
  75. package/scripts/lib/kit-hotfix.sh +18 -16
  76. package/scripts/lib/kit-interview.sh +6 -0
  77. package/scripts/lib/kit-lib-test.sh +1 -1
  78. package/scripts/lib/kit-lib.sh +7 -7
  79. package/scripts/lib/kit-msg.sh +3 -3
  80. package/scripts/lib/kit-status.sh +19 -14
  81. package/scripts/lib/kit-task-ops-test.sh +20 -1
  82. package/scripts/lib/kit-task-ops.sh +177 -94
  83. package/scripts/lib/kto-hotfix-test.sh +53 -58
  84. package/scripts/lib/kto-task-close-test.sh +28 -27
  85. package/scripts/lib/kto-task-new-test.sh +55 -48
  86. package/scripts/lib/kto-task-pr-merge-test.sh +77 -41
  87. package/scripts/lib/kto-task-pr-test.sh +30 -34
  88. package/scripts/lib/light-task-run-test.sh +19 -15
  89. package/scripts/lib/light-task-test.sh +34 -29
  90. package/scripts/lib/light-task.sh +24 -13
  91. package/scripts/lib/loose-issues.sh +65 -0
  92. package/scripts/lib/naming-test.sh +112 -0
  93. package/scripts/lib/naming-verbs-test.sh +126 -0
  94. package/scripts/lib/naming.sh +172 -0
  95. package/scripts/lib/next-test.sh +27 -22
  96. package/scripts/lib/next.sh +13 -7
  97. package/scripts/lib/orchestration-runtime-test.sh +11 -8
  98. package/scripts/lib/plan-machine.sh +22 -16
  99. package/scripts/lib/plan-next.sh +4 -4
  100. package/scripts/lib/pr-evidence-test.sh +63 -74
  101. package/scripts/lib/pr-evidence.sh +15 -12
  102. package/scripts/lib/qa-lane-test.sh +59 -27
  103. package/scripts/lib/qa-lane.sh +14 -6
  104. package/scripts/lib/review-page-test.sh +34 -25
  105. package/scripts/lib/review-page.sh +10 -4
  106. package/scripts/lib/spec-lint-test.sh +63 -0
  107. package/scripts/lib/spec-lint.sh +95 -0
  108. package/scripts/lib/sprint-test.sh +96 -0
  109. package/scripts/lib/sprint.sh +216 -0
  110. package/scripts/lib/stage-receipt-test.sh +169 -19
  111. package/scripts/lib/stage-receipt.sh +195 -10
  112. package/scripts/lib/test-forge-shim.sh +115 -0
  113. package/scripts/lib/verbs.sh +105 -0
  114. package/scripts/lib/verbs.tsv +92 -0
  115. package/scripts/lib/version-bump-test.sh +20 -0
  116. package/scripts/lib/version-bump.sh +4 -2
  117. package/scripts/lib/worker-brief-test.sh +1 -1
  118. package/scripts/lib/worker-brief.sh +1 -1
  119. package/scripts/lib/worktree-issue-test.sh +24 -19
  120. package/scripts/lib/worktree-issue.sh +10 -10
  121. package/scripts/lib/worktree-start-test.sh +13 -16
  122. package/scripts/lib/worktree-start.sh +57 -7
  123. package/scripts/loose-issues-test.sh +102 -0
  124. package/scripts/loose-issues.baseline +5 -0
  125. package/scripts/marketing-walkthrough-test.sh +25 -30
  126. package/scripts/night-grant.sh +14 -8
  127. package/scripts/night-run.mjs +1 -1
  128. package/scripts/orchestrate-test.sh +27 -31
  129. package/scripts/orchestrate.sh +9 -3
  130. package/scripts/portable-test.sh +37 -36
  131. package/scripts/publish.sh +9 -3
  132. package/scripts/setup-labels.sh +23 -12
  133. package/scripts/setup-milestones.sh +8 -2
  134. package/scripts/status-test.sh +39 -33
  135. package/scripts/status.sh +12 -6
  136. package/scripts/task-sync-test.sh +75 -32
  137. package/scripts/task-sync.sh +97 -6
  138. package/scripts/terms-check-test.sh +191 -0
  139. package/scripts/terms-check.sh +242 -0
  140. package/scripts/verbs-gen.sh +43 -0
  141. package/scripts/verbs-help-test.sh +61 -0
  142. package/scripts/verbs-ratchet-test.sh +69 -0
  143. package/scripts/verbs-ratchet.sh +34 -0
  144. package/scripts/verbs-test.sh +120 -0
  145. package/scripts/verbs.baseline +5 -0
  146. package/skills/kit-add/SKILL.md +2 -1
  147. package/skills/kit-advisor/SKILL.md +75 -0
  148. package/skills/kit-advisor/references/close.md +53 -0
  149. package/skills/kit-advisor/references/grill.md +69 -0
  150. package/skills/kit-advisor/references/orchestrate.md +56 -0
  151. package/skills/kit-advisor/references/plan.md +64 -0
  152. package/skills/kit-advisor/references/review.md +47 -0
  153. package/skills/kit-advisor/references/step-report.md +61 -0
  154. package/skills/kit-annotate/SKILL.md +1 -0
  155. package/skills/kit-autopilot/SKILL.md +2 -1
  156. package/skills/kit-cleanup/SKILL.md +3 -2
  157. package/skills/kit-contribute/SKILL.md +1 -0
  158. package/skills/kit-customize/SKILL.md +1 -0
  159. package/skills/kit-dev/SKILL.md +1 -0
  160. package/skills/kit-digest/SKILL.md +1 -0
  161. package/skills/kit-docs-writer/SKILL.md +4 -3
  162. package/skills/kit-effort-close/SKILL.md +18 -9
  163. package/skills/kit-effort-new/SKILL.md +12 -8
  164. package/skills/kit-effort-pr/SKILL.md +8 -7
  165. package/skills/kit-effort-start/SKILL.md +1 -0
  166. package/skills/kit-gc/SKILL.md +1 -0
  167. package/skills/kit-next/SKILL.md +8 -7
  168. package/skills/kit-onboard/SKILL.md +1 -0
  169. package/skills/kit-page/SKILL.md +1 -0
  170. package/skills/kit-plan-next/SKILL.md +11 -11
  171. package/skills/kit-security-sweep/SKILL.md +1 -0
  172. package/skills/kit-ship/SKILL.md +1 -0
  173. package/skills/kit-status/SKILL.md +6 -5
  174. package/skills/kit-task-close/SKILL.md +1 -0
  175. package/skills/kit-task-new/SKILL.md +1 -0
  176. package/skills/kit-task-pr/SKILL.md +1 -0
  177. package/skills/kit-task-pr-auto/SKILL.md +2 -1
  178. package/skills/kit-task-pr-merge/SKILL.md +4 -3
  179. package/skills/kit-task-start/SKILL.md +1 -0
  180. package/skills/kit-task-sync/SKILL.md +3 -0
  181. package/skills/kit-ux-audit/SKILL.md +1 -0
  182. package/skills/routing.yaml +124 -0
  183. package/templates/hooks/kit-mail-check.sh.tmpl +1 -1
  184. package/templates/instructions.md.tmpl +3 -3
  185. package/templates/rules/authoring.md +7 -3
  186. package/templates/rules/delegation-brief.md +4 -0
  187. package/templates/rules/effort-model.md +34 -31
  188. package/templates/rules/gate-and-review.md +1 -1
  189. package/templates/rules/merge-safety.md +9 -7
  190. package/templates/rules/naming-and-ids.md +20 -24
  191. package/templates/rules/plan-next.md +5 -5
  192. package/templates/skills/campaign/SKILL.md +2 -2
  193. package/scripts/lib/engine-adapter.sh +0 -93
@@ -4,11 +4,16 @@
4
4
  # from any shell or agent (not only via the effort-* skills). Thin: composes the git-mechanics helpers
5
5
  # in effort.sh (linking, snapshots, title lint) plus gh + git. bash 3.2 compatible. Requires: gh, jq, git.
6
6
  #
7
- # effort_new [flags] "<name>" [<sub spec> …] parent (4-section body + labels) + native sub-issues
7
+ # effort_new [flags] "<name>" [<sub spec> …] parent (5-section body + labels) + native sub-issues;
8
+ # --grilling[-file] appends a linted `## Grilling` record;
9
+ # --sprint[=YYYY-MM-DD] files it into that week's sprint
10
+ # effort_sub <slug|N> "<name>" [--kind K] add one sub-issue, titled [E<N>.<step>] <name>
11
+ # effort_retitle [<slug|N>] [--apply] rename legacy [Effort] titles (dry run by default)
8
12
  # effort_chain <a> <b> [<c> …] wire N issues into a linear blocked_by chain (#243)
9
13
  # effort_start [--force] <slug|N> [<slug>] effort/<N> branch + worktree from base, WIP-limited (#244)
10
14
  # effort_pr [<slug|N>] open the ONE PR effort/<N> → base branch
11
- # effort_close <slug|N> snapshot sub-diffs, squash-merge the PR, close parent + subs
15
+ # effort_close <slug|N> [--no-spec-check] check the Spec, snapshot sub-diffs, squash-merge, close the
16
+ # parent + finished subs (unfinished stay open, listed)
12
17
  #
13
18
  # effort_new is the SHARED creation core (effort #98): both `cckit effort new` (the verb) and
14
19
  # /kit-effort-new (the skill) call it, so they produce structurally identical efforts — one source of
@@ -21,6 +26,12 @@
21
26
 
22
27
  # Slug layer (#93): _eff_slug, _eff_title_slug, effort_display, effort_slug_resolve. One home in
23
28
  # effort-slug.sh; source it here so the lifecycle ops accept `<slug|N>` and render `slug #N`.
29
+ # The forge port (E537): every GitHub call goes through forge_* / gh_rest_* (scripts/lib/gh-rest.sh).
30
+ if ! command -v gh_rest_issue_json >/dev/null 2>&1; then
31
+ # shellcheck source=/dev/null
32
+ . "$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" && pwd)/gh-rest.sh"
33
+ fi
34
+
24
35
  if ! command -v effort_slug_resolve >/dev/null 2>&1; then
25
36
  _eo_dir="$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" && pwd)"
26
37
  # shellcheck source=/dev/null
@@ -28,6 +39,40 @@ if ! command -v effort_slug_resolve >/dev/null 2>&1; then
28
39
  unset _eo_dir
29
40
  fi
30
41
 
42
+ # The one title convention (naming.sh, E546.1): every title effort_new / effort_sub / effort_pr
43
+ # writes is linted there first, and every title read back is stripped there.
44
+ if ! command -v naming_title_lint >/dev/null 2>&1; then
45
+ _eo_dir="$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" && pwd)"
46
+ # shellcheck source=/dev/null
47
+ [ -f "$_eo_dir/naming.sh" ] && . "$_eo_dir/naming.sh"
48
+ unset _eo_dir
49
+ fi
50
+
51
+ # The `## Spec` check (spec-lint.sh, E546.5): effort_new lints the body it composed, effort_close
52
+ # the body it reads back.
53
+ if ! command -v spec_lint >/dev/null 2>&1; then
54
+ _eo_dir="$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" && pwd)"
55
+ # shellcheck source=/dev/null
56
+ [ -f "$_eo_dir/spec-lint.sh" ] && . "$_eo_dir/spec-lint.sh"
57
+ unset _eo_dir
58
+ fi
59
+
60
+ # The `## Grilling` record check (grill-record.sh, E547.2): effort_new lints --grilling before writing.
61
+ if ! command -v grill_record_lint >/dev/null 2>&1; then
62
+ _eo_dir="$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" && pwd)"
63
+ # shellcheck source=/dev/null
64
+ [ -f "$_eo_dir/grill-record.sh" ] && . "$_eo_dir/grill-record.sh"
65
+ unset _eo_dir
66
+ fi
67
+
68
+ # The sprint (sprint.sh, #570): effort_new --sprint files the effort into the current week's sprint.
69
+ if ! command -v sprint_name >/dev/null 2>&1; then
70
+ _eo_dir="$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" && pwd)"
71
+ # shellcheck source=/dev/null
72
+ [ -f "$_eo_dir/sprint.sh" ] && . "$_eo_dir/sprint.sh"
73
+ unset _eo_dir
74
+ fi
75
+
31
76
  # The closed kind: vocabulary (KIT_KINDS / kit_kind_valid) — what `effort new --kind` accepts.
32
77
  if ! command -v kit_kind_valid >/dev/null 2>&1; then
33
78
  _eo_dir="$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" && pwd)"
@@ -36,7 +81,7 @@ if ! command -v kit_kind_valid >/dev/null 2>&1; then
36
81
  unset _eo_dir
37
82
  fi
38
83
 
39
- # The GitHub transport switch (#396): in rest mode the lifecycle calls below are `gh api repos/…`.
84
+ # The GitHub transport switch (#396): in rest mode the lifecycle calls below are `forge_rest repos/…`.
40
85
  if ! command -v cckit_gh_rest >/dev/null 2>&1; then
41
86
  _eo_dir="$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" && pwd)"
42
87
  # shellcheck source=/dev/null
@@ -49,17 +94,24 @@ command -v cckit_board_skipped >/dev/null 2>&1 || cckit_board_skipped() { return
49
94
  _eff_repo() { printf '%s' "${EFFORT_REPO:-${KIT_REPO:-}}"; }
50
95
  _eff_base() { printf '%s' "${KIT_BASE_BRANCH:-main}"; }
51
96
  _eff_need() { command -v "$1" >/dev/null 2>&1 || { echo "effort: $1 is required" >&2; return 1; }; }
97
+ # _eff_forge — rc 0 with a forge; without one, forge_need's one line (naming the verb), rc 1.
98
+ _eff_forge() { forge_need; }
52
99
 
53
- # Compose the four-section parent body (rules/effort-model.md): the sections double as the work
100
+ # Compose the five-section parent body (rules/effort-model.md): the sections double as the work
54
101
  # record. An empty section falls back to its template placeholder so a bare call still yields the
55
- # full four-heading scaffold; passing content fills it. The `## Relations` chain is NOT composed
56
- # here — it is layered on afterwards by _eff_relations_add (one formatter, #243).
102
+ # full scaffold; passing content fills it. The Spec is built by spec_section (plain lines become
103
+ # bullets); an empty one keeps only its hint, which spec_lint refuses. The `## Relations` chain is
104
+ # NOT composed here — it is layered on afterwards by _eff_relations_add (one formatter, #243).
57
105
  _eff_compose_body() {
58
- local goal="$1" scope="$2" for_agents="$3" verification="$4"
106
+ local goal="$1" scope="$2" for_agents="$3" verification="$4" spec="${5:-}" spec_md
107
+ if [ -n "$spec" ]; then spec_md="$(spec_section "$spec")"
108
+ else spec_md="$(printf '## Spec\n<!-- what done means: a checkable list, one item per line -->')"; fi
59
109
  cat <<EOF
60
110
  ## Goal
61
111
  ${goal:-<!-- problem statement: what outcome, in one or two lines -->}
62
112
 
113
+ ${spec_md}
114
+
63
115
  ## Scope
64
116
  ${scope:-<!-- the sub-issue plan; mark each parallel | sequential / dependsOn -->}
65
117
 
@@ -114,9 +166,7 @@ _eff_relations_add() {
114
166
  # before `gh issue create --label` uses it (which fails hard on a missing label, #153). Idempotent:
115
167
  # creating an existing label is a silent no-op.
116
168
  _eff_ensure_label() {
117
- if cckit_gh_rest; then gh_rest_label_create "$(_eff_repo)" "$1" "$2" "$3"; return 0; fi
118
- gh label create "$1" --repo "$(_eff_repo)" --color "$2" \
119
- --description "$3" >/dev/null 2>&1 || true
169
+ gh_rest_label_create "$(_eff_repo)" "$1" "$2" "$3"; return 0
120
170
  }
121
171
 
122
172
  # Add an issue (by number) to the project board + set Status=Todo and the Role field. Guarded: a
@@ -128,8 +178,8 @@ _eff_board_add() {
128
178
  cckit_board_skipped && return 0
129
179
  command -v project_add_item >/dev/null 2>&1 || return 0
130
180
  repo="$(_eff_repo)"
131
- node="$(gh api "repos/$repo/issues/$n" --jq .node_id 2>/dev/null)" || return 0
132
- item="$(project_add_item "$node" 2>/dev/null)" || return 0
181
+ node="$(forge_rest "repos/$repo/issues/$n" --jq .node_id 2>/dev/null)" || return 0
182
+ item="$(project_add_item "$node" "$repo" "$n" Issue 2>/dev/null)" || return 0
133
183
  [ -n "$item" ] || return 0
134
184
  [ -n "${STATUS_FIELD_ID:-}" ] && [ -n "${STATUS_OPT_TODO:-}" ] \
135
185
  && project_set_single_select "$item" "$STATUS_FIELD_ID" "$STATUS_OPT_TODO" 2>/dev/null || true
@@ -142,19 +192,20 @@ _eff_board_add() {
142
192
  }
143
193
 
144
194
  # effort_new [flags] "<name>" [<sub spec> …] — the shared creation core (effort #98).
145
- # Flags (all optional): --flow F --role R --priority p1 --goal G --scope S --for-agents A
195
+ # Flags: --spec T | --spec-file F (required: what done means, checked by spec_lint before any forge
196
+ # write); optional --flow F --role R --priority p1 --goal G --scope S --for-agents A
146
197
  # --verification V --depends-on "#1,#2" --milestone M --slug S. A <sub spec> is "name :: one-line
147
- # desc" (the desc is optional → just "name"). Fills the four body sections, applies the
198
+ # desc" (the desc is optional → just "name"). Fills the five body sections, applies the
148
199
  # ctx/kind/priority/role/flow label set, lints the parent + EVERY sub title up front (so a bad sub
149
200
  # name aborts before anything is created), links native sub-issues, sets blocked_by edges, adds
150
201
  # everything to the board (guarded), and records the human slug handle (#93) as a slug:<slug> label.
151
202
  # Echoes the parent number on stdout.
152
203
  effort_new() {
153
- _eff_need gh || return 1; _eff_need jq || return 1
204
+ _eff_forge || return 1; _eff_need jq || return 1
154
205
  local repo; repo="$(_eff_repo)"
155
206
  [ -n "$repo" ] || { echo "effort_new: no repo (KIT_REPO/EFFORT_REPO unset — run in a kit project)" >&2; return 1; }
156
207
 
157
- local flow="" role="" priority="p1" goal="" scope="" for_agents="" verification="" depends_on="" milestone="" explicit_slug="" kind="task"
208
+ local flow="" role="" priority="p1" goal="" scope="" for_agents="" verification="" depends_on="" milestone="" explicit_slug="" kind="task" spec_text="" grilling="" sprint_day=""
158
209
  # Flags are position-INDEPENDENT: recognized --flag [value] pairs are consumed wherever they occur
159
210
  # (before the title, between subs, or after them) and the remaining positionals are collected as the
160
211
  # title (first) + sub specs (rest). Previously the parser broke at the first positional, so any flag
@@ -170,6 +221,17 @@ effort_new() {
170
221
  --scope) scope="${2:-}"; shift 2 ;;
171
222
  --for-agents) for_agents="${2:-}"; shift 2 ;;
172
223
  --verification) verification="${2:-}"; shift 2 ;;
224
+ --spec) spec_text="${2:-}"; shift 2 ;;
225
+ --spec=*) spec_text="${1#*=}"; shift ;;
226
+ --spec-file)
227
+ [ -r "${2:-}" ] || { echo "effort_new: --spec-file: cannot read '${2:-}'" >&2; return 1; }
228
+ spec_text="$(cat "$2")"; shift 2 ;;
229
+ --grilling) grilling="${2:-}"; shift 2 ;;
230
+ --grilling-file)
231
+ [ -r "${2:-}" ] || { echo "effort_new: --grilling-file: cannot read '${2:-}'" >&2; return 1; }
232
+ grilling="$(cat "$2")"; shift 2 ;;
233
+ --sprint) sprint_day="today"; shift ;;
234
+ --sprint=*) sprint_day="${1#*=}"; shift ;;
173
235
  --depends-on) depends_on="${2:-}"; shift 2 ;;
174
236
  --milestone) milestone="${2:-}"; shift 2 ;;
175
237
  --slug) explicit_slug="${2:-}"; shift 2 ;;
@@ -194,29 +256,49 @@ effort_new() {
194
256
  local name="${1:-}"; shift || true
195
257
  [ -n "$name" ] || { echo 'effort_new: usage: effort_new [flags] "<name>" [<sub spec> …]' >&2; return 1; }
196
258
 
197
- # Optional leading [Flow] tag on the board title (validated by effort_title_lint).
198
- local flow_tag=""; [ -n "$flow" ] && flow_tag="[$flow] "
199
-
200
- # Guard the parent name against the title rule BEFORE creating anything (synthetic number — the
201
- # rule is about the NAME, not the not-yet-assigned N).
202
- effort_title_lint "[Effort] 0 · ${flow_tag}${name}" || { echo "effort_new: fix the name and retry" >&2; return 1; }
259
+ # The title is `[E<n>] <name>` (rules/naming-and-ids.md, E546.1): the flow lives in the flow:
260
+ # label, so no [Flow] tag is written into the title any more. Lint the parent name BEFORE creating
261
+ # anything (synthetic number 0: the rule is about the NAME, not the not-yet-assigned N).
262
+ naming_title_lint effort "$(naming_effort_title 0 "$name")" || { echo "effort_new: fix the name and retry" >&2; return 1; }
203
263
 
204
- # Lint EVERY sub title up front too (parity with the skill's intent) so a bad sub name fails the
205
- # whole op before a half-effort exists. Synthetic parent number 0 for the lint.
264
+ # Lint EVERY sub title up front too, so a bad sub name fails the whole op before a half-effort
265
+ # exists. Synthetic parent number 0 for the lint.
206
266
  local i=0 spec sub_name sub_title
207
267
  for spec in "$@"; do
208
268
  i=$((i + 1))
209
269
  sub_name="${spec%% :: *}"
210
- sub_title="[Effort 0] $i · $sub_name"
211
- effort_title_lint "$sub_title" \
270
+ sub_title="$(naming_sub_title 0 "$i" "$sub_name")"
271
+ naming_title_lint sub "$sub_title" \
212
272
  || { echo "effort_new: fix sub title #$i and retry: $sub_name" >&2; return 1; }
213
273
  done
214
274
 
215
- # Compose the four-section body, then layer the ## Relations chain from --depends-on through the
275
+ # Compose the five-section body, then layer the ## Relations chain from --depends-on through the
216
276
  # ONE formatter (#243) — the same one `effort_chain` uses, so both write identical lines. (It was
217
277
  # built inline here before, and `$( … )` ate every newline: the section shipped as the single
218
278
  # mangled line `## Relations- Depends on #1- Depends on #2`.)
219
- local body d; body="$(_eff_compose_body "$goal" "$scope" "$for_agents" "$verification")"
279
+ local body d; body="$(_eff_compose_body "$goal" "$scope" "$for_agents" "$verification" "$spec_text")"
280
+ # The Spec (E546.5): checked on the composed body, before any label or issue is written.
281
+ spec_lint "$body" || { echo 'effort_new: say what done means with --spec "<item>" or --spec-file F, and retry' >&2; return 1; }
282
+ # The Grilling record (E547.2): optional, but a record that is passed must be one — linted here,
283
+ # before any forge write, then appended as the body's `## Grilling` section.
284
+ if [ -n "$grilling" ]; then
285
+ grill_record_lint "$grilling" || { echo 'effort_new: fix the --grilling record and retry' >&2; return 1; }
286
+ body="$body"$'\n\n'"$(grill_record_section "$grilling")"
287
+ fi
288
+ # The sprint (#570): --sprint names the week the effort is planned into, in the body and as the
289
+ # milestone of the parent and every sub. The milestone is opened when it does not exist yet.
290
+ local sprint="" sprint_start="" sprint_end=""
291
+ if [ -n "$sprint_day" ]; then
292
+ [ "$sprint_day" = today ] && sprint_day="$(_sprint_today)"
293
+ sprint="$(sprint_name "$sprint_day")" || { echo "effort_new: --sprint=YYYY-MM-DD names a day of the sprint" >&2; return 1; }
294
+ IFS="$(printf '\t')" read -r sprint_start sprint_end <<EOF_SB
295
+ $(sprint_bounds "$sprint_day")
296
+ EOF_SB
297
+ [ -z "$milestone" ] || [ "$milestone" = "$sprint" ] \
298
+ || { echo "effort_new: --sprint and --milestone name different milestones ($sprint, $milestone)" >&2; return 1; }
299
+ milestone="$sprint"
300
+ body="$body"$'\n\n'"$(printf '## Sprint\n%s · Monday %s to Monday %s' "$sprint" "$sprint_start" "$sprint_end")"
301
+ fi
220
302
  if [ -n "$depends_on" ]; then
221
303
  for d in $(printf '%s' "$depends_on" | tr ',' ' '); do
222
304
  d="${d#\#}"; [ -n "$d" ] && body="$(_eff_relations_add "$body" "$d")"
@@ -249,30 +331,27 @@ effort_new() {
249
331
  labels="$labels,flow:$flow_lc"
250
332
  fi
251
333
 
334
+ if [ -n "$sprint" ]; then
335
+ sprint_open --date "$sprint_day" >/dev/null 2>&1 \
336
+ || echo "effort_new: could not open the sprint milestone $sprint — the effort is filed without it" >&2
337
+ fi
338
+
252
339
  local url num slug
253
- if cckit_gh_rest; then
254
- url="$(gh_rest_issue_create "$repo" "[Effort] · ${flow_tag}${name}" "$body" "$labels" "$milestone" 0)" \
255
- || { echo "effort_new: failed to create the parent issue" >&2; return 1; }
256
- else
257
- url="$(gh issue create --repo "$repo" --title "[Effort] · ${flow_tag}${name}" --body "$body" \
258
- --label "$labels" ${milestone:+--milestone "$milestone"})" \
340
+ # The number is assigned by the create, so the parent is filed under its plain name and renamed
341
+ # to `[E<n>] <name>` at once. The `effort` label marks it as an effort in between.
342
+ url="$(gh_rest_issue_create "$repo" "$name" "$body" "$labels" "$milestone" 0)" \
259
343
  || { echo "effort_new: failed to create the parent issue" >&2; return 1; }
260
- fi
261
344
  num="${url##*/}"
262
- if cckit_gh_rest; then gh_rest_issue_edit_title "$repo" "$num" "[Effort] $num · ${flow_tag}${name}" >/dev/null 2>&1
263
- else gh issue edit "$num" --repo "$repo" --title "[Effort] $num · ${flow_tag}${name}" >/dev/null 2>&1; fi
264
- # The human handle (#93): explicit --slug if given, else derived from the title (number/flow peeled).
345
+ gh_rest_issue_edit_title "$repo" "$num" "$(naming_effort_title "$num" "$name")" >/dev/null 2>&1 \
346
+ || echo "effort_new: #$num was created but not renamed to $(naming_effort_title "$num" "$name") — run: cckit effort retitle $num --apply" >&2
347
+ # The human handle (#93): explicit --slug if given, else derived from the name.
265
348
  if [ -n "$explicit_slug" ]; then slug="$(_eff_slug "$explicit_slug")"
266
- else slug="$(_eff_title_slug "[Effort] $num · ${flow_tag}${name}")"; fi
267
- if [ -n "$slug" ] && cckit_gh_rest; then
349
+ else slug="$(_eff_title_slug "$(naming_effort_title "$num" "$name")")"; fi
350
+ if [ -n "$slug" ]; then
268
351
  gh_rest_label_create "$repo" "slug:$slug" ededed "effort slug handle"
269
352
  gh_rest_issue_add_labels "$repo" "$num" "slug:$slug" >/dev/null 2>&1 || true
270
- elif [ -n "$slug" ]; then
271
- gh label create "slug:$slug" --repo "$repo" --color ededed \
272
- --description "effort slug handle" >/dev/null 2>&1 || true # idempotent: ok if it exists
273
- gh issue edit "$num" --repo "$repo" --add-label "slug:$slug" >/dev/null 2>&1 || true
274
353
  fi
275
- echo " ✓ effort $(effort_display "$num" "$slug") · ${flow_tag}${name}" >&2
354
+ echo " ✓ effort $(effort_display "$num" "$slug") · ${name}" >&2
276
355
 
277
356
  # Native dependency edges (the visible board chain) — guarded on the helper being available.
278
357
  if [ -n "$depends_on" ] && command -v effort_set_blocked_by >/dev/null 2>&1; then
@@ -291,17 +370,11 @@ effort_new() {
291
370
  i=$((i + 1))
292
371
  sub_name="${spec%% :: *}"
293
372
  sub_desc="${spec#* :: }"; [ "$sub_desc" = "$spec" ] && sub_desc=""
294
- sub_title="[Effort $num] $i · $sub_name"
373
+ sub_title="$(naming_sub_title "$num" "$i" "$sub_name")"
295
374
  local sub_labels="kind:$kind,priority:$priority"
296
375
  [ -n "$role" ] && sub_labels="$sub_labels,role:$role"
297
- if cckit_gh_rest; then
298
- child="$(gh_rest_issue_create "$repo" "$sub_title" \
299
- "$(printf '%s\n\nSub-issue of #%s (effort).' "$sub_desc" "$num")" "$sub_labels" "$milestone" 0)" || continue
300
- else
301
- child="$(gh issue create --repo "$repo" --title "$sub_title" \
302
- --body "$(printf '%s\n\nSub-issue of #%s (effort).' "$sub_desc" "$num")" \
303
- --label "$sub_labels" ${milestone:+--milestone "$milestone"})" || continue
304
- fi
376
+ child="$(gh_rest_issue_create "$repo" "$sub_title" \
377
+ "$(printf '%s\n\nSub-issue of #%s (effort).' "$sub_desc" "$num")" "$sub_labels" "$milestone" 0)" || continue
305
378
  child_num="${child##*/}"
306
379
  effort_link_sub "$num" "$child_num" || true
307
380
  _eff_board_add "$child_num" "$role" || true
@@ -310,6 +383,144 @@ effort_new() {
310
383
  printf '%s\n' "$num"
311
384
  }
312
385
 
386
+ # effort_sub <slug|N> "<name>" [--kind K] [--body B] [--spec T] — add ONE sub-issue to an effort
387
+ # (E546.1). The title is `[E<N>.<step>] <name>`, step = the effort's current native sub count + 1; it
388
+ # is linted before any forge write. The sub takes the parent's priority, role and milestone, and
389
+ # the kind:<k> label (--kind, else the parent's kind, else task), as effort_new's subs do; it is
390
+ # linked natively under the parent and added to the board. --spec adds an optional `## Spec` section
391
+ # (E546.5), linted like the parent's when given; a sub needs none. Echoes the new sub's number.
392
+ effort_sub() {
393
+ _eff_forge || return 1; _eff_need jq || return 1
394
+ local raw="" name="" kind="" body_in="" spec="" pos=()
395
+ while [ $# -gt 0 ]; do
396
+ case "$1" in
397
+ --kind) kind="${2:-}"; shift 2 ;;
398
+ --kind=*) kind="${1#*=}"; shift ;;
399
+ --body) body_in="${2:-}"; shift 2 ;;
400
+ --body=*) body_in="${1#*=}"; shift ;;
401
+ --spec) spec="${2:-}"; shift 2 ;;
402
+ --spec=*) spec="${1#*=}"; shift ;;
403
+ --) shift; while [ $# -gt 0 ]; do pos+=("$1"); shift; done ;;
404
+ -*) echo "effort_sub: unknown flag $1" >&2; return 2 ;;
405
+ *) pos+=("$1"); shift ;;
406
+ esac
407
+ done
408
+ set -- "${pos[@]+"${pos[@]}"}"
409
+ raw="${1:-}"; name="${2:-}"
410
+ [ -n "$raw" ] && [ -n "$name" ] || { echo 'effort_sub: usage: cckit effort sub <N> "<name>" [--kind K] [--body B] [--spec T]' >&2; return 2; }
411
+ # The rule is about the NAME: lint it first, with a synthetic token, before any forge read or write.
412
+ naming_title_lint sub "$(naming_sub_title 0 1 "$name")" || { echo "effort_sub: fix the name and retry" >&2; return 1; }
413
+ if [ -n "$spec" ]; then
414
+ if [ -n "$body_in" ]; then body_in="$(printf '%s\n\n%s' "$body_in" "$(spec_section "$spec")")"
415
+ else body_in="$(spec_section "$spec")"; fi
416
+ spec_lint "$body_in" || { echo "effort_sub: fix the --spec and retry" >&2; return 1; }
417
+ fi
418
+ if [ -n "$kind" ] && command -v kit_kind_label_valid >/dev/null 2>&1 && ! kit_kind_label_valid "$kind"; then
419
+ echo "effort_sub: --kind must be one of: $KIT_KINDS $KIT_CONTENT_KINDS (got '$kind')" >&2; return 1
420
+ fi
421
+ local repo num meta labels milestone priority role count step title child child_num sub_labels
422
+ repo="$(_eff_repo)"
423
+ [ -n "$repo" ] || { echo "effort_sub: no repo (KIT_REPO/EFFORT_REPO unset — run in a kit project)" >&2; return 1; }
424
+ num="$(effort_slug_resolve "$raw")" || { echo "effort_sub: could not resolve '$raw' to an effort" >&2; return 1; }
425
+ meta="$(gh_rest_issue_json "$repo" "$num" 2>/dev/null)" || { echo "effort_sub: effort #$num not found" >&2; return 1; }
426
+ labels="$(printf '%s' "$meta" | jq -r '[.labels[]?.name] | join(",")' 2>/dev/null)"
427
+ case ",$labels," in *,effort,*) : ;; *)
428
+ echo "effort_sub: #$num is not an effort (no 'effort' label) — file a standalone issue with cckit new" >&2; return 1 ;;
429
+ esac
430
+ milestone="$(printf '%s' "$meta" | jq -r '.milestone.title // ""' 2>/dev/null)"
431
+ priority="$(printf '%s' "$labels" | tr ',' '\n' | sed -n 's/^priority://p' | sed -n 1p)"; priority="${priority:-p1}"
432
+ role="$(printf '%s' "$labels" | tr ',' '\n' | sed -n 's/^role://p' | sed -n 1p)"
433
+ [ -n "$kind" ] || kind="$(printf '%s' "$labels" | tr ',' '\n' | sed -n 's/^kind://p' | sed -n 1p)"
434
+ kind="${kind:-task}"
435
+ count="$(forge_rest "repos/$repo/issues/$num/sub_issues" -X GET -f per_page=100 --jq 'length' 2>/dev/null)" \
436
+ || { echo "effort_sub: could not read the sub-issues of #$num" >&2; return 1; }
437
+ step=$(( ${count:-0} + 1 ))
438
+ title="$(naming_sub_title "$num" "$step" "$name")"
439
+ naming_title_lint sub "$title" || return 1
440
+ _eff_ensure_label "kind:$kind" d4c5f9 "kit issue kind"
441
+ _eff_ensure_label "priority:$priority" e99695 "kit priority"
442
+ sub_labels="kind:$kind,priority:$priority"
443
+ [ -n "$role" ] && sub_labels="$sub_labels,role:$role"
444
+ child="$(gh_rest_issue_create "$repo" "$title" \
445
+ "$(printf '%s\n\nSub-issue of #%s (effort).' "$body_in" "$num")" "$sub_labels" "$milestone" 0)" \
446
+ || { echo "effort_sub: failed to create the sub-issue" >&2; return 1; }
447
+ child_num="${child##*/}"
448
+ effort_link_sub "$num" "$child_num" || true
449
+ _eff_board_add "$child_num" "$role" || true
450
+ echo " ✓ sub #$child_num · $title" >&2
451
+ printf '%s\n' "$child_num"
452
+ }
453
+
454
+ # _eff_retitle_rows <N> — the legacy titles of effort N and its open subs, one "num<TAB>old<TAB>new"
455
+ # row each. A title already in the new form, or one with no prefix at all, gives no row.
456
+ _eff_retitle_rows() {
457
+ local repo num title new tab subs s_num s_title tok
458
+ repo="$(_eff_repo)"; num="$1"; tab="$(printf '\t')"
459
+ title="$(forge_rest "repos/$repo/issues/$num" --jq '.title // ""' 2>/dev/null)" || return 1
460
+ case "$title" in
461
+ "[Effort] "*)
462
+ new="$(naming_effort_title "$num" "$(naming_strip_prefix "$title")")"
463
+ printf '%s\t%s\t%s\n' "$num" "$title" "$new" ;;
464
+ esac
465
+ subs="$(forge_rest "repos/$repo/issues/$num/sub_issues" -X GET -f per_page=100 \
466
+ --jq '.[] | select((.state // "open") == "open") | "\(.number)\t\(.title // "")"' 2>/dev/null)" || return 0
467
+ while IFS="$tab" read -r s_num s_title; do
468
+ [ -n "$s_num" ] || continue
469
+ case "$s_title" in "[Effort "[0-9]*) : ;; *) continue ;; esac
470
+ tok="$(naming_title_token "$s_title")" || continue
471
+ new="$(naming_sub_title "$num" "${tok#*.}" "$(naming_strip_prefix "$s_title")")"
472
+ printf '%s\t%s\t%s\n' "$s_num" "$s_title" "$new"
473
+ done <<EOF_SUBS
474
+ $subs
475
+ EOF_SUBS
476
+ }
477
+
478
+ # effort_retitle [<slug|N>] [--apply] — rename legacy `[Effort] N · ` / `[Effort N] M · ` titles to
479
+ # `[E<n>] ` / `[E<n>.<step>] ` (E546.1). Without <N>: every open effort (label `effort`) and its open
480
+ # subs. A dry run by default: it lists each old title and the new one and writes nothing. --apply
481
+ # edits the titles through the forge. A [Flow] tag is dropped: the flow lives in the flow: label.
482
+ effort_retitle() {
483
+ _eff_forge || return 1; _eff_need jq || return 1
484
+ local raw="" apply=0 a repo nums n rows="" tab line r_num r_old r_new count=0 failed=0
485
+ for a in "$@"; do
486
+ case "$a" in
487
+ --apply) apply=1 ;;
488
+ -*) echo "effort_retitle: unknown flag $a — usage: cckit effort retitle [<N>] [--apply]" >&2; return 2 ;;
489
+ *) [ -z "$raw" ] && raw="$a" ;;
490
+ esac
491
+ done
492
+ repo="$(_eff_repo)"; tab="$(printf '\t')"
493
+ [ -n "$repo" ] || { echo "effort_retitle: no repo (KIT_REPO/EFFORT_REPO unset — run in a kit project)" >&2; return 1; }
494
+ if [ -n "$raw" ]; then
495
+ nums="$(effort_slug_resolve "$raw")" || { echo "effort_retitle: could not resolve '$raw' to an effort" >&2; return 1; }
496
+ else
497
+ nums="$(gh_rest_issue_numbers_by_label "$repo" effort)" || { echo "effort_retitle: could not list the open efforts" >&2; return 1; }
498
+ fi
499
+ while IFS= read -r n; do
500
+ [ -n "$n" ] || continue
501
+ line="$(_eff_retitle_rows "$n")" || { echo "effort_retitle: could not read #$n" >&2; failed=1; continue; }
502
+ [ -n "$line" ] && rows="${rows:+$rows
503
+ }$line"
504
+ done <<EOF_NUMS
505
+ $nums
506
+ EOF_NUMS
507
+ if [ -z "$rows" ]; then echo "(no legacy titles: every effort and sub already reads [E<n>] / [E<n>.<step>])"; return "$failed"; fi
508
+ while IFS="$tab" read -r r_num r_old r_new; do
509
+ [ -n "$r_num" ] || continue
510
+ count=$((count + 1))
511
+ printf '#%s %s\n -> %s\n' "$r_num" "$r_old" "$r_new"
512
+ if [ "$apply" = 1 ]; then
513
+ gh_rest_issue_edit_title "$repo" "$r_num" "$r_new" >/dev/null 2>&1 \
514
+ || { echo " ✗ #$r_num not renamed" >&2; failed=1; }
515
+ fi
516
+ done <<EOF_ROWS
517
+ $rows
518
+ EOF_ROWS
519
+ if [ "$apply" = 1 ]; then echo "renamed $count title(s)"
520
+ else echo "dry run: $count title(s) would change — run again with --apply to rename them"; fi
521
+ return "$failed"
522
+ }
523
+
313
524
  # _eo_source_effort — lazily source the git-mechanics lib (effort.sh) so the ops that need
314
525
  # effort_set_blocked_by work when effort-ops.sh is sourced on its own. No-op if already loaded.
315
526
  _eo_source_effort() {
@@ -321,19 +532,13 @@ _eo_source_effort() {
321
532
 
322
533
  # _eff_issue_body <repo> <n> / _eff_issue_set_body <repo> <n> <body> — read and replace an issue
323
534
  # body on the chosen transport (#396). A failed read returns non-zero, never an empty body.
324
- _eff_issue_body() {
325
- if cckit_gh_rest; then gh api "repos/$1/issues/$2" --jq '.body // ""'
326
- else gh issue view "$2" --repo "$1" --json body --jq .body; fi
327
- }
328
- _eff_issue_set_body() {
329
- if cckit_gh_rest; then gh_rest_issue_set_body "$1" "$2" "$3"
330
- else gh issue edit "$2" --repo "$1" --body "$3"; fi
331
- }
535
+ _eff_issue_body() { forge_rest "repos/$1/issues/$2" --jq '.body // ""'; }
536
+ _eff_issue_set_body() { gh_rest_issue_set_body "$1" "$2" "$3"; }
332
537
 
333
538
  # _eff_blockers <issue> — echo the issue's CURRENT blocked_by numbers, one per line. Empty when the
334
539
  # issue has no edges or the API call fails (the caller treats that as "no known edge").
335
540
  _eff_blockers() {
336
- gh api "repos/$(_eff_repo)/issues/$1/dependencies/blocked_by" --jq '.[].number' 2>/dev/null || true
541
+ forge_rest "repos/$(_eff_repo)/issues/$1/dependencies/blocked_by" --jq '.[].number' 2>/dev/null || true
337
542
  }
338
543
 
339
544
  # _eff_chain_reaches <from> <target> <pending> — is <target> reachable from <from> by following
@@ -361,7 +566,7 @@ _eff_chain_reaches() {
361
566
 
362
567
  # effort_chain <a> <b> [<c> …] — wire N issues into a LINEAR dependency chain (#243): B becomes
363
568
  # blocked_by A, C blocked_by B, and so on, and each issue after the first gets a `- Depends on #<its
364
- # predecessor>` line in its `## Relations` section. This is the verb that FEEDS `cckit plan` — the
569
+ # predecessor>` line in its `## Relations` section. This is the verb that FEEDS `cckit effort plan --issues` — the
365
570
  # wave layering in plan-machine.sh reads exactly these `blocked_by` edges, so a chained set lands
366
571
  # one issue per wave, in the order given.
367
572
  #
@@ -375,7 +580,7 @@ _eff_chain_reaches() {
375
580
  # chain. Nothing is written.
376
581
  # cycles a repeated number (`chain 1 2 1`) is refused — the chain would revisit a node. So
377
582
  # is a chain whose new edge closes a loop through edges GitHub ALREADY holds (the
378
- # pre-flight walks the combined graph). `cckit plan` cannot layer a cyclic graph into
583
+ # pre-flight walks the combined graph). `cckit effort plan --issues` cannot layer a cyclic graph into
379
584
  # waves, so a cycle is refused rather than written. Nothing is written.
380
585
  # pre-existing an issue already blocked by something else KEEPS that blocker: blocked_by is a set,
381
586
  # blockers and this only ever ADDS its edge. The issue ends up with both.
@@ -386,7 +591,7 @@ _eff_chain_reaches() {
386
591
  # Progress goes to stderr; rc 0 only when every link of the chain is in place.
387
592
  effort_chain() {
388
593
  [ -n "${ZSH_VERSION:-}" ] && setopt local_options ksh_arrays sh_word_split 2>/dev/null
389
- _eff_need gh || return 1
594
+ _eff_forge || return 1
390
595
  _eo_source_effort
391
596
  local repo; repo="$(_eff_repo)"
392
597
  [ -n "$repo" ] || { echo "effort_chain: no repo (KIT_REPO/EFFORT_REPO unset — run in a kit project)" >&2; return 1; }
@@ -408,7 +613,7 @@ effort_chain() {
408
613
 
409
614
  # 2. every issue must exist before a single edge is written.
410
615
  for n in $list; do
411
- gh api "repos/$repo/issues/$n" --jq .number >/dev/null 2>&1 \
616
+ forge_rest "repos/$repo/issues/$n" --jq .number >/dev/null 2>&1 \
412
617
  || { echo "effort_chain: #$n does not exist in $repo — nothing written" >&2; return 1; }
413
618
  done
414
619
 
@@ -663,8 +868,7 @@ effort_start() {
663
868
  # `set -e` a bare failed assignment did exactly that, rc 1 with no output. Failed is told apart
664
869
  # from empty by gh's exit code, and said on stderr.
665
870
  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
871
+ title="$(forge_rest "repos/$repo/issues/$num" --jq .title 2>/dev/null)" || title_rc=$?
668
872
  slug=""
669
873
  if [ "$title_rc" -ne 0 ]; then
670
874
  title=""
@@ -713,13 +917,15 @@ effort_start() {
713
917
  }
714
918
 
715
919
  # effort_pr [<slug|N>] — open the single PR effort/<N> → base. Defaults to the current effort branch.
920
+ _EO_PR_USAGE='cckit effort pr [<slug|N>] [--summary S|--summary-file F] [--for-agents A|--for-agents-file F] [--message M] [--title T] [--type T] open the ONE PR effort/<N> → base'
716
921
  effort_pr() {
717
922
  # The ONE effort-PR implementation (#363). The kit-effort-pr skill calls this; before, the skill
718
923
  # carried its own inline copy, so agents hand-copied the script and the copy drifted (a PR missing
719
924
  # from the board, a mangled body). Args: [<slug|N>] [--summary S|--summary-file F]
720
925
  # [--for-agents A|--for-agents-file F] [--message M] [--title T]. SUMMARY / FOR_AGENTS / COMMIT_MSG env are
721
926
  # honoured as fallbacks.
722
- _eff_need gh || return 1
927
+ case "${1:-}" in -h|--help) echo "$_EO_PR_USAGE"; return 0 ;; esac
928
+ _eff_forge || return 1
723
929
  local raw="" summary="${SUMMARY:-}" for_agents="${FOR_AGENTS:-}" msg="${COMMIT_MSG:-}" title_override="" ctype=""
724
930
  while [ $# -gt 0 ]; do
725
931
  case "$1" in
@@ -730,6 +936,7 @@ effort_pr() {
730
936
  --message|-m) msg="${2:-}"; shift 2 ;;
731
937
  --title) title_override="${2:-}"; shift 2 ;;
732
938
  --type) ctype="${2:-}"; shift 2 ;;
939
+ -h|--help) echo "$_EO_PR_USAGE"; return 0 ;;
733
940
  *) [ -z "$raw" ] && raw="$1"; shift ;;
734
941
  esac
735
942
  done
@@ -745,8 +952,7 @@ effort_pr() {
745
952
  case "$branch" in effort/"$num"-*) : ;; *) echo "effort_pr: current branch ($branch) is not effort/$num-…" >&2; return 1 ;; esac
746
953
 
747
954
  # Parent metadata: the PR inherits its labels + milestone, and the role names the title.
748
- if cckit_gh_rest; then meta="$(gh_rest_issue_json "$repo" "$num" 2>/dev/null)"
749
- else meta="$(gh issue view "$num" --repo "$repo" --json title,labels,milestone 2>/dev/null)"; fi
955
+ meta="$(gh_rest_issue_json "$repo" "$num" 2>/dev/null)"
750
956
  title="$(printf '%s' "$meta" | jq -r '.title // ""' 2>/dev/null)"
751
957
  labels="$(printf '%s' "$meta" | jq -r '[.labels[]?.name] | join(",")' 2>/dev/null)"
752
958
  milestone="$(printf '%s' "$meta" | jq -r '.milestone.title // ""' 2>/dev/null)"
@@ -755,7 +961,18 @@ effort_pr() {
755
961
  if [ -n "$role" ] && command -v role_display >/dev/null 2>&1; then
756
962
  role_disp="$(role_display "$role" 2>/dev/null || true)"
757
963
  fi
758
- name="$(printf '%s' "$title" | sed -E 's/^\[Effort\] [0-9]+ · ?//')"
964
+ name="$(naming_strip_structural "$title")"
965
+
966
+ # ONE shared composer (effort.sh) so every surface titles identically, then the naming rule and
967
+ # the effort-token check before the commit, the push or any forge write — refuse rather than open
968
+ # an id-less PR (#121).
969
+ # --title replaces the composed title; it must still carry the effort's token, checked below.
970
+ pr_title="${title_override:-$(effort_pr_title "$num" "${name:-effort}" "$labels" "$ctype" "$role_disp")}"
971
+ effort_pr_title_check "$pr_title" "$num" || { echo "effort_pr: refusing to open a PR without the [E$num] effort token" >&2; return 1; }
972
+ # #237 + E546.1: under pr.titleStyle = conventional (the default) the title becomes the squash
973
+ # commit the commitlint gate checks, so naming_title_lint pr holds it to the Conventional Commit
974
+ # form with a trailing token. issue-title repos run no such gate; the lint passes them through.
975
+ naming_title_lint pr "$pr_title" || { echo "effort_pr: refusing to open a PR whose title breaks the naming rule (pass --type <type> or --title, or set pr.titleStyle to issue-title)" >&2; return 1; }
759
976
 
760
977
  # Commit pending changes. Role identity is a Co-authored-by TRAILER, never the git author (some
761
978
  # deploy providers refuse commits whose author email matches no account). TRACKED changes only:
@@ -779,45 +996,9 @@ effort_pr() {
779
996
  fi
780
997
  git push -u origin "$branch" >/dev/null 2>&1 || echo "effort_pr: push of $branch failed — continuing (the PR may already be current)" >&2
781
998
 
782
- # ONE shared composer (effort.sh) so every surface titles identically, then the mandatory-[#N]
783
- # check before we ever call gh — refuse rather than open an id-less PR (#121).
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")}"
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
802
999
  body="$(_eff_pr_body "$num" "$summary" "$for_agents" "$role")"
803
1000
 
804
- # Four explicit forms, not ${x:+--flag "$x"}: that idiom word-splits under zsh, and this file is
805
- # sourced from zsh too.
806
- if cckit_gh_rest; then
807
- url="$(gh_rest_pr_create "$repo" "$base" "$branch" "$pr_title" "$body" "$labels" "$milestone")" || return 1
808
- elif [ -n "$labels" ] && [ -n "$milestone" ]; then
809
- url="$(gh pr create --repo "$repo" --base "$base" --head "$branch" --title "$pr_title" --body "$body" \
810
- --label "$labels" --milestone "$milestone" --assignee "@me")" || return 1
811
- elif [ -n "$labels" ]; then
812
- url="$(gh pr create --repo "$repo" --base "$base" --head "$branch" --title "$pr_title" --body "$body" \
813
- --label "$labels" --assignee "@me")" || return 1
814
- elif [ -n "$milestone" ]; then
815
- url="$(gh pr create --repo "$repo" --base "$base" --head "$branch" --title "$pr_title" --body "$body" \
816
- --milestone "$milestone" --assignee "@me")" || return 1
817
- else
818
- url="$(gh pr create --repo "$repo" --base "$base" --head "$branch" --title "$pr_title" --body "$body" \
819
- --assignee "@me")" || return 1
820
- fi
1001
+ url="$(gh_rest_pr_create "$repo" "$base" "$branch" "$pr_title" "$body" "$labels" "$milestone")" || return 1
821
1002
  echo "✓ $url"
822
1003
  _eff_pr_board "$num" "$url" "$role"
823
1004
  }
@@ -857,9 +1038,9 @@ _eff_pr_board() {
857
1038
  _eo_source_board
858
1039
  command -v project_add_item >/dev/null 2>&1 || return 0
859
1040
  repo="$(_eff_repo)"; pr_num="${url##*/}"
860
- node="$(gh api "repos/$repo/pulls/$pr_num" --jq .node_id 2>/dev/null)" || node=""
1041
+ node="$(forge_rest "repos/$repo/pulls/$pr_num" --jq .node_id 2>/dev/null)" || node=""
861
1042
  item=""
862
- [ -n "$node" ] && item="$(project_add_item "$node" 2>/dev/null || true)"
1043
+ [ -n "$node" ] && item="$(project_add_item "$node" "$repo" "$pr_num" PullRequest 2>/dev/null || true)"
863
1044
  if [ -z "$item" ]; then
864
1045
  echo "⚠ PR #$pr_num was opened but NOT added to the board — add it by hand" >&2
865
1046
  else
@@ -917,10 +1098,7 @@ _eo_source_board() {
917
1098
  }
918
1099
 
919
1100
  # _eo_issue_close_completed <repo> <n> — close as completed on the chosen transport (#396), quietly.
920
- _eo_issue_close_completed() {
921
- if cckit_gh_rest; then gh_rest_issue_close "$1" "$2" completed >/dev/null 2>&1
922
- else gh issue close "$2" --repo "$1" --reason completed >/dev/null 2>&1; fi
923
- }
1101
+ _eo_issue_close_completed() { gh_rest_issue_close "$1" "$2" completed >/dev/null 2>&1; }
924
1102
 
925
1103
  # _eo_board_done <issue #> — set the board Status=Done for one issue. Guarded like _eff_board_add:
926
1104
  # a no-op unless Projects v2 is on AND the board helpers + field ids are loaded. Best-effort — a
@@ -995,13 +1173,14 @@ _eo_dependent_prs() {
995
1173
  # close, because either one means a PR would be closed by the delete.
996
1174
  _eo_retarget_dependents() {
997
1175
  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)" \
1176
+ json="$(forge_rest "repos/$repo/pulls" -X GET -f base="$branch" -f state=open -f per_page=100 \
1177
+ --jq '[.[] | {number, baseRefName: .base.ref}]' 2>/dev/null)" \
999
1178
  && 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; }
1179
+ || { echo "effort_close: could not list the open PRs based on $branch — deleting it would close any that exist. Rerun when GitHub answers (nothing was merged)" >&2; return 1; }
1001
1180
  while IFS= read -r dep; do
1002
1181
  [ -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; }
1182
+ forge_rest "repos/$repo/pulls/$dep" -X PATCH -f base="$base" >/dev/null 2>&1 \
1183
+ || { echo "effort_close: PR $dep is based on $branch and could not be re-targeted to $base — deleting the branch would close it. Change its base to $base on GitHub, then rerun (nothing was merged)" >&2; return 1; }
1005
1184
  echo " ↻ PR $dep re-targeted to $base" >&2
1006
1185
  done <<EOF_DEPS
1007
1186
  $deps
@@ -1030,7 +1209,7 @@ _eo_pre_close_hook() {
1030
1209
  echo "effort_close: pre-close hook '$hook' skipped (KIT_FORCE=1)" >&2; return 0
1031
1210
  fi
1032
1211
  [ -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)"
1212
+ [ "$#" -ge 5 ] || subs="$(forge_rest "repos/$repo/issues/$num/sub_issues" --jq '.[].number' 2>/dev/null)"
1034
1213
  set -- "$num"
1035
1214
  while IFS= read -r sub; do
1036
1215
  [ -n "$sub" ] && set -- "$@" "$sub"
@@ -1047,15 +1226,28 @@ EOF_SUBS
1047
1226
  # effort_close <N> — the SINGLE close implementation (#148): the /kit-effort-close skill is a thin
1048
1227
  # caller of this function, never a second close. Snapshot per-sub diffs + capture metrics BEFORE the
1049
1228
  # squash (the squash erases the per-sub history), REFUSE to squash if no work trace was captured
1050
- # (KIT_FORCE=1 overrides), squash-merge, judge + sync the metrics, close parent + subs, set the board
1229
+ # (KIT_FORCE=1 overrides), squash-merge, judge the metrics, close parent + finished subs, set the board
1051
1230
  # Status=Done for each (guarded), GC the worktree/branch, run the optional knowledge-ingest hook,
1052
1231
  # and finish with the advisory kit-sync drift check. Destructive: it merges, closes, and prunes.
1232
+ # First of all it re-reads the parent body and refuses an effort whose `## Spec` fails spec_lint
1233
+ # (E546.5); --no-spec-check skips that one check and says so on stderr.
1234
+ _EO_CLOSE_USAGE='cckit effort close <slug|N> [--no-spec-check] squash-merge the effort PR, close the parent and its finished subs (unfinished subs stay open, linked, and are listed), GC'
1053
1235
  effort_close() {
1054
- _eff_need gh || return 1; _eff_need jq || return 1
1055
- local raw="${1:-}" num repo base branch root self_wt trace_dir kit_touched
1236
+ case "${1:-}" in -h|--help) echo "$_EO_CLOSE_USAGE"; return 0 ;; esac
1237
+ _eff_forge || return 1; _eff_need jq || return 1
1238
+ local raw="" spec_check=1 num repo base branch root self_wt trace_dir kit_touched
1239
+ while [ $# -gt 0 ]; do
1240
+ case "$1" in
1241
+ -h|--help) echo "$_EO_CLOSE_USAGE"; return 0 ;;
1242
+ --no-spec-check) spec_check=0; shift ;;
1243
+ -*) echo "effort_close: unknown flag $1" >&2; return 2 ;;
1244
+ *) [ -z "$raw" ] && raw="$1"; shift ;;
1245
+ esac
1246
+ done
1056
1247
  [ -n "$raw" ] || { echo "effort_close: <slug|effort issue #> required" >&2; return 1; }
1057
1248
  num="$(effort_slug_resolve "$raw")" || { echo "effort_close: could not resolve '$raw' to an effort" >&2; return 1; }
1058
1249
  repo="$(_eff_repo)"; base="$(_eff_base)"
1250
+ _eo_spec_check "$repo" "$num" "$spec_check" || return 1
1059
1251
  branch="$(git rev-parse --abbrev-ref HEAD 2>/dev/null)"
1060
1252
  case "$branch" in
1061
1253
  effort/"$num"-*) : ;;
@@ -1098,26 +1290,16 @@ effort_close() {
1098
1290
  # (a2) refuse a conflicting PR before anything is written (#394). The capture below appends a
1099
1291
  # records.jsonl row and consumes the effort's start marker, so a merge that fails after it leaves a
1100
1292
  # row the retry duplicates with build_seconds null. UNKNOWN (GitHub still computing) proceeds.
1101
- local rest_pr="" mergeable
1102
- if cckit_gh_rest; then
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)"
1113
- else
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
- }
1120
- fi
1293
+ local rest_pr="" rest_meta="" mergeable
1294
+ # A failed read, or no open PR, must stop here (#330): carrying on let the capture write its row
1295
+ # and consume the start marker before the merge failed.
1296
+ rest_pr="$(gh_rest_pr_for_head "$repo" "$branch" 2>/dev/null)" || rest_pr=""
1297
+ [ -n "$rest_pr" ] && rest_meta="$(gh_rest_pr_json "$repo" "$rest_pr" 2>/dev/null)" || rest_meta=""
1298
+ [ -n "$rest_meta" ] || {
1299
+ echo "effort_close: could not read the PR for $branch from GitHub (no PR, or the API is unavailable) — rerun when it answers (nothing was written)" >&2
1300
+ return 1
1301
+ }
1302
+ mergeable="$(printf '%s' "$rest_meta" | jq -r .mergeable)"
1121
1303
  if [ "$mergeable" = "CONFLICTING" ]; then
1122
1304
  echo "effort_close: the PR for $branch conflicts with $base — merge or rebase $base into it, then rerun (nothing was written)" >&2
1123
1305
  return 1
@@ -1125,8 +1307,9 @@ effort_close() {
1125
1307
 
1126
1308
  # (a3) re-target the open PRs based on this branch before the squash deletes it (#358). Here, not
1127
1309
  # 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
1310
+ # a records.jsonl row the retry duplicates. In the cloud the remote branch is kept (the proxy
1311
+ # rejects branch deletion), so nothing can close a dependent PR there and the step is skipped.
1312
+ if ! cckit_in_cloud; then
1130
1313
  _eo_retarget_dependents "$repo" "$branch" "$base" || return 1
1131
1314
  fi
1132
1315
 
@@ -1138,38 +1321,64 @@ effort_close() {
1138
1321
  kit_touched="$(git diff --name-only "origin/$base"...HEAD 2>/dev/null \
1139
1322
  | grep -E "$_EO_KIT_MANAGED_RE" | sort -u || true)"
1140
1323
 
1141
- # (c) squash-merge the effort PR. Over REST the remote branch stays: the cloud proxy rejects branch
1142
- # deletion (#396).
1143
- if cckit_gh_rest; then
1144
- { [ -n "$rest_pr" ] && gh_rest_pr_merge "$repo" "$rest_pr" squash >/dev/null 2>&1; } \
1145
- || { echo "effort_close: could not squash-merge the PR for $branch (open? mergeable?)" >&2; return 1; }
1146
- echo " ✓ merged $branch" >&2
1147
- echo " (remote branch $branch kept — branch deletion is unavailable here; delete it on GitHub)" >&2
1148
- else
1149
- gh pr merge "$branch" --repo "$repo" --squash --delete-branch >/dev/null 2>&1 \
1324
+ # (b3) which subs are finished (#565, decision 52), read PRE-squash while the effort branch's
1325
+ # commits still exist. A sub is finished when it is already closed, or a commit on this branch
1326
+ # delivers it (_eo_delivered_refs). Unfinished subs are NOT closed and NOT detached: they stay
1327
+ # open under the parent and are listed in the close comment and in this command's output.
1328
+ local sub_rows delivered sub_split done_subs="" open_subs="" open_lines=""
1329
+ sub_rows="$(forge_rest "repos/$repo/issues/$num/sub_issues" \
1330
+ --jq '.[] | "\(.number)|\(.state)|\(.title // "")"' 2>/dev/null)" || sub_rows=""
1331
+ delivered="$(_eo_delivered_refs "origin/$base")"
1332
+ sub_split="$(printf '%s\n' "$sub_rows" | _eo_partition_subs "$num" "$delivered")"
1333
+ done_subs="$(printf '%s\n' "$sub_split" | awk -F'|' '$1 == "done" {print $2 "|" $3}')"
1334
+ open_subs="$(printf '%s\n' "$sub_split" | awk -F'|' '$1 == "open" {print $2}')"
1335
+ open_lines="$(printf '%s\n' "$sub_split" | awk -F'|' '$1 == "open" {t=$0; sub(/^[^|]*\|[^|]*\|/, "", t); print "- #" $2 (t == "" ? "" : " " t)}')"
1336
+
1337
+ # (c) squash-merge the effort PR, then delete the remote branch (git, not the API). In a cloud
1338
+ # session the proxy rejects the deletion (#396): the branch is kept and the close says so.
1339
+ { [ -n "$rest_pr" ] && gh_rest_pr_merge "$repo" "$rest_pr" squash >/dev/null 2>&1; } \
1150
1340
  || { echo "effort_close: could not squash-merge the PR for $branch (open? mergeable?)" >&2; return 1; }
1151
1341
  echo " ✓ merged $branch" >&2
1342
+ if cckit_in_cloud; then
1343
+ echo " (remote branch $branch kept — branch deletion is unavailable here; delete it on GitHub)" >&2
1344
+ else
1345
+ git -C "${root:-.}" push origin --delete "$branch" >/dev/null 2>&1 && echo " ✓ deleted remote branch $branch" >&2 \
1346
+ || echo " (remote branch $branch not deleted — delete it on GitHub)" >&2
1152
1347
  fi
1153
1348
 
1154
- # (d) judge + sync the metrics (judge reads the durable trace dir; sync no-ops when the engine is off).
1349
+ # (d) judge the metrics (reads the durable trace dir; the record stays in the local buffer).
1155
1350
  command -v judge_effort_metrics >/dev/null 2>&1 && judge_effort_metrics "$num" "origin/$base" || true
1156
- command -v sync_effort_metrics >/dev/null 2>&1 && sync_effort_metrics "$num" || true
1157
1351
 
1158
- # (e) close every native sub-issue, then the parent — and set the board Status=Done for each
1159
- # (guarded: a no-op when Projects v2 is off or the board helpers/ids are unavailable). Board +
1160
- # issue + record state are owned by this ONE op (effort-model.md) — never a separate "mark done".
1352
+ # (e) close the FINISHED sub-issues (#565), then the parent — and set the board Status=Done for
1353
+ # each (guarded: a no-op when Projects v2 is off or the board helpers/ids are unavailable). A sub
1354
+ # already closed keeps its own close reason (no second PATCH). An unfinished sub stays open and
1355
+ # linked; the close comment on the parent lists it. Board + issue + record state are owned by
1356
+ # this ONE op (effort-model.md) — never a separate "mark done".
1161
1357
  _eo_source_board
1162
- local sub
1163
- while IFS= read -r sub; do
1358
+ local sub sstate done_list="" comment
1359
+ while IFS='|' read -r sub sstate; do
1164
1360
  [ -n "$sub" ] || continue
1165
- _eo_issue_close_completed "$repo" "$sub" && echo " ✓ closed sub #$sub" >&2
1361
+ if [ "$sstate" = closed ]; then
1362
+ echo " ✓ sub #$sub already closed" >&2
1363
+ else
1364
+ _eo_issue_close_completed "$repo" "$sub" && echo " ✓ closed sub #$sub" >&2
1365
+ fi
1166
1366
  _eo_board_done "$sub"
1167
- done < <(gh api "repos/$repo/issues/$num/sub_issues" --jq '.[].number' 2>/dev/null)
1168
- _eo_issue_close_completed "$repo" "$num" && echo " ✓ closed effort #$num" >&2
1367
+ done_list="${done_list:+$done_list, }#$sub"
1368
+ done <<EOF_DONE
1369
+ $done_subs
1370
+ EOF_DONE
1371
+ while IFS= read -r sub; do
1372
+ [ -n "$sub" ] && echo " ⚠ left open: sub #$sub — unfinished, still linked under #$num" >&2
1373
+ done <<EOF_OPEN
1374
+ $open_subs
1375
+ EOF_OPEN
1376
+ comment="$(_eo_close_comment "$branch" "$done_list" "$open_lines")"
1377
+ gh_rest_issue_close "$repo" "$num" completed "$comment" >/dev/null 2>&1 && echo " ✓ closed effort #$num" >&2
1169
1378
  _eo_board_done "$num"
1170
1379
 
1171
1380
  # (f) GC: switch the main checkout to base, remove the effort worktree, delete the local branch,
1172
- # prune. The remote branch was deleted by --delete-branch above. All via `git -C "$root"` so the
1381
+ # prune. The remote branch was deleted in step (c). All via `git -C "$root"` so the
1173
1382
  # caller's cwd is never moved. Best-effort — a GC hiccup never fails the (already-landed) close.
1174
1383
  if [ -n "$root" ]; then
1175
1384
  git -C "$root" checkout "$base" >/dev/null 2>&1 || true
@@ -1198,6 +1407,76 @@ effort_close() {
1198
1407
 
1199
1408
  # (h) kit-sync drift check — kit ⇄ project stay in sync (#148, moved here from the skill).
1200
1409
  _eo_kit_sync_warn "$kit_touched"
1410
+
1411
+ # (i) the report's last word: the subs this close left open (#565).
1412
+ if [ -n "$open_lines" ]; then
1413
+ echo "" >&2
1414
+ echo " ⚠ #$num closed with unfinished sub-issues still open (linked under it):" >&2
1415
+ printf '%s\n' "$open_lines" | sed 's/^/ /' >&2
1416
+ fi
1417
+ return 0
1418
+ }
1419
+
1420
+ # _eo_delivered_refs <base_ref> — what the commits in <base_ref>..HEAD deliver, one token per line:
1421
+ # `#N` for an issue number, `E<n>.<k>` for a sub step id. A commit delivers (1) the LAST `#N` it
1422
+ # mentions — the same commit→sub pairing effort_snapshot_subs writes to the trace, (2) every `#N`
1423
+ # after a closing keyword (close/fix/resolve and their forms), and (3) every `[E<n>.<k>]` step tag.
1424
+ # Pure git; prints nothing when there are no commits.
1425
+ _eo_delivered_refs() {
1426
+ local sha msg
1427
+ git rev-list "$1..HEAD" 2>/dev/null | while IFS= read -r sha; do
1428
+ [ -n "$sha" ] || continue
1429
+ msg="$(git log -1 --format='%s%n%b' "$sha" 2>/dev/null)"
1430
+ printf '%s\n' "$msg" | grep -oE '#[0-9]+' | tail -1
1431
+ printf '%s\n' "$msg" | grep -oiE '(close[sd]?|fix(e[sd])?|resolve[sd]?):?[[:space:]]+#[0-9]+' | grep -oE '#[0-9]+'
1432
+ printf '%s\n' "$msg" | grep -oE '\[E[0-9]+\.[0-9]+\]' | tr -d '[]'
1433
+ done | sort -u
1434
+ }
1435
+
1436
+ # _eo_partition_subs <effort#> <delivered-refs> — stdin: "<sub#>|<state>|<title>" rows (state as the
1437
+ # REST API spells it). stdout: "done|<sub#>|<state>" or "open|<sub#>|<title>", one per sub. A sub is
1438
+ # done when it is already closed, its `#N` is in <delivered-refs>, or its title carries a step id
1439
+ # `[E<effort>.<k>]` that a commit tagged. Pure: no forge, no git.
1440
+ _eo_partition_subs() {
1441
+ local eff="$1" refs="$2" n st title step
1442
+ while IFS='|' read -r n st title; do
1443
+ [ -n "$n" ] || continue
1444
+ st="$(printf '%s' "$st" | tr '[:upper:]' '[:lower:]')"
1445
+ if [ "$st" = closed ]; then echo "done|$n|closed"; continue; fi
1446
+ if grep -qxF "#$n" <<<"$refs"; then echo "done|$n|$st"; continue; fi
1447
+ step="$(grep -oE "\[E$eff\.[0-9]+\]" <<<"$title" | sed -n 1p | tr -d '[]')"
1448
+ if [ -n "$step" ] && grep -qxF "$step" <<<"$refs"; then echo "done|$n|$st"; continue; fi
1449
+ echo "open|$n|$title"
1450
+ done
1451
+ }
1452
+
1453
+ # _eo_close_comment <branch> <done-list> <open-lines> — the comment effort_close posts on the parent
1454
+ # as it closes it: which subs closed with it and which stay open, linked (#565).
1455
+ _eo_close_comment() {
1456
+ printf 'Closed by `cckit effort close` (merged `%s`).\n\n' "$1"
1457
+ printf 'Finished sub-issues: %s\n' "${2:-none}"
1458
+ if [ -n "${3:-}" ]; then
1459
+ printf '\nLeft open, still linked under this effort (no commit on the effort branch delivers them):\n%s\n' "$3"
1460
+ fi
1461
+ }
1462
+
1463
+ # _eo_spec_check <repo> <num> <1|0> — the close-time Spec check (E546.5), shared by both close
1464
+ # styles because it runs before they split. 1: read the parent body and refuse, with spec_lint's
1465
+ # reasons, when it has no checkable `## Spec`; a failed read refuses too, since an unread body is not
1466
+ # a checked one. 0 (--no-spec-check): skip, and print one line recording that the check was skipped.
1467
+ _eo_spec_check() {
1468
+ local repo="$1" num="$2" body
1469
+ if [ "${3:-1}" = 0 ]; then
1470
+ echo "effort_close: Spec check skipped for #$num (--no-spec-check) — the close does not confirm what done means" >&2
1471
+ return 0
1472
+ fi
1473
+ body="$(_eff_issue_body "$repo" "$num" 2>/dev/null)" || {
1474
+ echo "effort_close: could not read #$num's body to check its Spec — rerun when GitHub answers, or pass --no-spec-check (nothing was written)" >&2
1475
+ return 1
1476
+ }
1477
+ spec_lint "$body" && return 0
1478
+ echo "effort_close: refusing to close #$num — add a '## Spec' list to its body (what done means), or pass --no-spec-check (nothing was written)" >&2
1479
+ return 1
1201
1480
  }
1202
1481
 
1203
1482
  # _eo_kit_sync_warn <files> — the advisory kit-sync drift warning, shared by both close styles
@@ -1214,10 +1493,10 @@ _eo_kit_sync_warn() {
1214
1493
  }
1215
1494
 
1216
1495
  # _eo_close_wave <num> <repo> <base> — close a WAVE-style effort (#164): every sub was delivered as
1217
- # its own task PR squash-merged straight to base (`cckit wave` → fan-out → `cckit watch --merge`),
1496
+ # its own task PR squash-merged straight to base (`cckit effort plan --wave` → fan-out → `cckit watch --merge`),
1218
1497
  # so no effort/<N> integration branch ever existed. Verifies every sub is CLOSED with a merged
1219
1498
  # closing PR (refuses and lists the stragglers otherwise), snapshots the work trace from the merged
1220
- # sub PR diffs, then runs the SAME close tail as the branch path: judge + sync metrics, close the
1499
+ # sub PR diffs, then runs the SAME close tail as the branch path: judge the metrics, close the
1221
1500
  # parent, board Status=Done for parent + subs, knowledge-ingest hook, kit-sync drift check.
1222
1501
  # capture_effort_metrics is intentionally skipped — there is no live branch diff to measure; the
1223
1502
  # merged PR diffs in the trace are the work record.
@@ -1231,7 +1510,7 @@ _eo_close_wave() {
1231
1510
  if cckit_gh_rest; then
1232
1511
  rows="$(gh_rest_wave_rows "$repo" "$num" 2>/dev/null)"
1233
1512
  else
1234
- rows="$(gh api graphql -f query='
1513
+ rows="$(forge_rest graphql -f query='
1235
1514
  query($o:String!,$r:String!,$n:Int!){ repository(owner:$o,name:$r){ issue(number:$n){
1236
1515
  subIssues(first:50){ nodes { number state
1237
1516
  closedByPullRequestsReferences(first:10){ nodes { number merged mergeCommit{oid} title } } } } } } }' \
@@ -1268,9 +1547,8 @@ _eo_close_wave() {
1268
1547
  fi
1269
1548
  fi
1270
1549
 
1271
- # (d) judge + sync the metrics off the trace (guarded, best-effort — same as the branch path).
1550
+ # (d) judge the metrics off the trace (guarded, best-effort — same as the branch path).
1272
1551
  command -v judge_effort_metrics >/dev/null 2>&1 && judge_effort_metrics "$num" "origin/$base" || true
1273
- command -v sync_effort_metrics >/dev/null 2>&1 && sync_effort_metrics "$num" || true
1274
1552
 
1275
1553
  # (e) kit-sync drift source: the union of files across the merged sub PR diffs.
1276
1554
  kit_touched="$(awk '/^diff --git /{print $3}' "$trace_dir"/*.diff 2>/dev/null | sed 's#^a/##' \