@jeiemgi/cckit 0.2.0 → 0.4.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 (75) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/AGENTS.md +21 -8
  3. package/README.md +119 -20
  4. package/bin/cckit +42 -16
  5. package/cckit.config.json +1 -1
  6. package/commands/kit-doctor.md +3 -1
  7. package/commands/kit-update.md +9 -4
  8. package/kit.config.schema.json +25 -0
  9. package/package.json +1 -1
  10. package/scripts/annotate-setup.sh +7 -2
  11. package/scripts/capture-project-ids.sh +23 -10
  12. package/scripts/init-upgrade-test.sh +35 -1
  13. package/scripts/init.sh +43 -7
  14. package/scripts/kit-doctor.sh +185 -7
  15. package/scripts/kit-version-check-test.sh +36 -0
  16. package/scripts/kit-version-check.sh +19 -4
  17. package/scripts/kit-wire.sh +4 -1
  18. package/scripts/knowledge-lint.sh +4 -1
  19. package/scripts/lib/board-view-test.sh +54 -0
  20. package/scripts/lib/board-view.sh +80 -0
  21. package/scripts/lib/captain-test.sh +18 -0
  22. package/scripts/lib/captain.sh +92 -5
  23. package/scripts/lib/config-path-test.sh +47 -0
  24. package/scripts/lib/config-path.sh +29 -0
  25. package/scripts/lib/copilot.sh +9 -9
  26. package/scripts/lib/effort-dispatch-test.sh +25 -0
  27. package/scripts/lib/effort-flows-test.sh +55 -0
  28. package/scripts/lib/effort-metrics-test.sh +57 -0
  29. package/scripts/lib/effort-metrics.sh +19 -5
  30. package/scripts/lib/effort-ops-test.sh +110 -3
  31. package/scripts/lib/effort-ops.sh +480 -50
  32. package/scripts/lib/effort-parity-test.sh +128 -0
  33. package/scripts/lib/effort-slug-test.sh +87 -0
  34. package/scripts/lib/effort-slug.sh +104 -0
  35. package/scripts/lib/effort.sh +91 -1
  36. package/scripts/lib/gh-project-test.sh +95 -0
  37. package/scripts/lib/gh-project.sh +22 -7
  38. package/scripts/lib/git-remote-test.sh +57 -0
  39. package/scripts/lib/git-remote.sh +21 -0
  40. package/scripts/lib/kit-config-test.sh +37 -0
  41. package/scripts/lib/kit-config.sh +38 -13
  42. package/scripts/lib/kit-engine-test.sh +9 -0
  43. package/scripts/lib/kit-events.sh +5 -3
  44. package/scripts/lib/kit-gc-test.sh +88 -0
  45. package/scripts/lib/kit-gc.sh +136 -19
  46. package/scripts/lib/kit-local.sh +8 -1
  47. package/scripts/lib/kit-operate.sh +17 -2
  48. package/scripts/lib/next.sh +3 -3
  49. package/scripts/lib/plan-next-test.sh +87 -0
  50. package/scripts/lib/plan-next.sh +212 -0
  51. package/scripts/lib/project-scan.sh +7 -1
  52. package/scripts/lib/worktree-start.sh +12 -3
  53. package/scripts/lib/zsh-safety-test.sh +73 -0
  54. package/scripts/portable-test.sh +62 -20
  55. package/scripts/setup-labels.sh +13 -2
  56. package/scripts/showcase.sh +13 -4
  57. package/scripts/status-test.sh +63 -0
  58. package/scripts/status.sh +12 -4
  59. package/scripts/task-sync.sh +79 -10
  60. package/skills/kit-autopilot/SKILL.md +5 -0
  61. package/skills/{docs-writer → kit-docs-writer}/SKILL.md +2 -2
  62. package/skills/kit-effort-close/SKILL.md +52 -104
  63. package/skills/kit-effort-new/SKILL.md +40 -112
  64. package/skills/kit-effort-pr/SKILL.md +6 -2
  65. package/skills/kit-effort-start/SKILL.md +44 -46
  66. package/skills/kit-next/SKILL.md +4 -0
  67. package/skills/kit-plan-next/SKILL.md +82 -0
  68. package/skills/kit-task-start/SKILL.md +44 -55
  69. package/templates/CLAUDE.md.tmpl +1 -1
  70. package/templates/agents/auto-dev.md +1 -1
  71. package/templates/hooks/mempal_session_start.sh.tmpl +36 -2
  72. package/templates/rules/effort-model.md +43 -6
  73. package/templates/rules/mempalace.md +1 -0
  74. package/templates/rules/plan-next.md +58 -0
  75. package/templates/rules/task-management.md +1 -1
@@ -4,78 +4,274 @@
4
4
  # any shell or agent (not only via the effort-* skills). Thin: composes the git-mechanics helpers in
5
5
  # effort.sh (linking, snapshots, title lint) plus gh + git. bash 3.2 compatible. Requires: gh, jq, git.
6
6
  #
7
- # effort_new "<name>" [<sub title> …] parent issue (template) + native sub-issues, all linked
8
- # effort_start <N> [<slug>] effort/<N> branch + worktree from the base branch
9
- # effort_pr [<N>] open the ONE PR effort/<N> → base branch
10
- # effort_close <N> snapshot sub-diffs, squash-merge the PR, close parent + subs
7
+ # effort_new [flags] "<name>" [<sub spec> …] parent (4-section body + labels) + native sub-issues
8
+ # effort_start <slug|N> [<slug>] effort/<N> branch + worktree from the base branch
9
+ # effort_pr [<slug|N>] open the ONE PR effort/<N> → base branch
10
+ # effort_close <slug|N> snapshot sub-diffs, squash-merge the PR, close parent + subs
11
11
  #
12
- # Repo + base branch come from kit.config.json (EFFORT_REPO / KIT_BASE_BRANCH), loaded by effort.sh.
12
+ # effort_new is the SHARED creation core (effort #98): both `cckit effort new` (the verb) and
13
+ # /kit-effort-new (the skill) call it, so they produce structurally identical efforts — one source of
14
+ # truth for body composition + the ctx/kind/priority/role/flow label set + per-sub title lint.
15
+ #
16
+ # Commands accept the human slug as well as the canonical number (#93): a pure-digits arg is a number,
17
+ # anything else is resolved via effort_slug_resolve. Repo + base branch come from kit.config.json
18
+ # (EFFORT_REPO / KIT_BASE_BRANCH), loaded by effort.sh.
19
+
20
+ # Slug layer (#93): _eff_slug, _eff_title_slug, effort_display, effort_slug_resolve. One home in
21
+ # effort-slug.sh; source it here so the lifecycle ops accept `<slug|N>` and render `slug #N`.
22
+ if ! command -v effort_slug_resolve >/dev/null 2>&1; then
23
+ _eo_dir="$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" && pwd)"
24
+ # shellcheck source=/dev/null
25
+ [ -f "$_eo_dir/effort-slug.sh" ] && . "$_eo_dir/effort-slug.sh"
26
+ unset _eo_dir
27
+ fi
13
28
 
14
29
  _eff_repo() { printf '%s' "${EFFORT_REPO:-${KIT_REPO:-}}"; }
15
30
  _eff_base() { printf '%s' "${KIT_BASE_BRANCH:-main}"; }
16
- _eff_slug() { # <text> → a short branch-safe slug (mirrors wt_start)
17
- printf '%s' "$1" | sed -E 's/^\[[^]]+\][[:space:]]*//' | tr '[:upper:]' '[:lower:]' \
18
- | sed -E 's/[^a-z0-9]+/-/g; s/^-+|-+$//g' | cut -c1-40
19
- }
20
31
  _eff_need() { command -v "$1" >/dev/null 2>&1 || { echo "effort: $1 is required" >&2; return 1; }; }
21
32
 
22
- # The parent-issue body template (rules/effort-model.md): the four sections double as the work record.
23
- _eff_parent_body() {
24
- cat <<'EOF'
33
+ # Compose the four-section parent body (rules/effort-model.md): the sections double as the work
34
+ # record. An empty section falls back to its template placeholder so a bare call still yields the
35
+ # full four-heading scaffold; passing content fills it. $5 is an optional pre-built ## Relations block.
36
+ _eff_compose_body() {
37
+ local goal="$1" scope="$2" for_agents="$3" verification="$4" relations="$5"
38
+ cat <<EOF
25
39
  ## Goal
26
- <!-- problem statement: what outcome, in one or two lines -->
40
+ ${goal:-<!-- problem statement: what outcome, in one or two lines -->}
27
41
 
28
42
  ## Scope
29
- <!-- the sub-issue plan; mark each parallel | sequential / dependsOn -->
43
+ ${scope:-<!-- the sub-issue plan; mark each parallel | sequential / dependsOn -->}
30
44
 
31
45
  ## For agents
32
- <!-- exact file paths / entry points a future agent needs -->
46
+ ${for_agents:-<!-- exact file paths / entry points a future agent needs -->}
33
47
 
34
48
  ## Verification
35
- <!-- how we know it's done: commands, checks, acceptance -->
49
+ ${verification:-<!-- how we know it is done: commands, checks, acceptance -->}${relations}
36
50
  EOF
37
51
  }
38
52
 
39
- # effort_new "<name>" [<sub title> …] — create the parent (template) + native sub-issues, linked.
53
+ # _eff_ensure_label <name> <color> <description> — make sure a kit-defined label exists in the repo
54
+ # before `gh issue create --label` uses it (which fails hard on a missing label, #153). Idempotent:
55
+ # creating an existing label is a silent no-op.
56
+ _eff_ensure_label() {
57
+ gh label create "$1" --repo "$(_eff_repo)" --color "$2" \
58
+ --description "$3" >/dev/null 2>&1 || true
59
+ }
60
+
61
+ # Add an issue (by number) to the project board + set Status=Todo and the Role field. Guarded: a
62
+ # no-op unless Projects v2 is on AND the project helpers (gh-project.sh) are already sourced, so the
63
+ # verb can run from any shell with no board config. Mirrors the skill's old inline board block.
64
+ _eff_board_add() {
65
+ local n="$1" role="${2:-}" repo node item ropt
66
+ [ "${KIT_PROJECTS_V2:-}" = "true" ] || return 0
67
+ command -v project_add_item >/dev/null 2>&1 || return 0
68
+ repo="$(_eff_repo)"
69
+ node="$(gh api "repos/$repo/issues/$n" --jq .node_id 2>/dev/null)" || return 0
70
+ item="$(project_add_item "$node" 2>/dev/null)" || return 0
71
+ [ -n "$item" ] || return 0
72
+ [ -n "${STATUS_FIELD_ID:-}" ] && [ -n "${STATUS_OPT_TODO:-}" ] \
73
+ && project_set_single_select "$item" "$STATUS_FIELD_ID" "$STATUS_OPT_TODO" 2>/dev/null || true
74
+ if [ -n "$role" ] && command -v role_option_id >/dev/null 2>&1; then
75
+ ropt="$(role_option_id "$role" 2>/dev/null || echo "")"
76
+ [ -n "$ropt" ] && [ -n "${ROLE_FIELD_ID:-}" ] \
77
+ && project_set_single_select "$item" "$ROLE_FIELD_ID" "$ropt" 2>/dev/null || true
78
+ fi
79
+ return 0
80
+ }
81
+
82
+ # effort_new [flags] "<name>" [<sub spec> …] — the shared creation core (effort #98).
83
+ # Flags (all optional): --flow F --role R --priority p1 --goal G --scope S --for-agents A
84
+ # --verification V --depends-on "#1,#2" --milestone M --slug S. A <sub spec> is "name :: one-line
85
+ # desc" (the desc is optional → just "name"). Fills the four body sections, applies the
86
+ # ctx/kind/priority/role/flow label set, lints the parent + EVERY sub title up front (so a bad sub
87
+ # name aborts before anything is created), links native sub-issues, sets blocked_by edges, adds
88
+ # everything to the board (guarded), and records the human slug handle (#93) as a slug:<slug> label.
89
+ # Echoes the parent number on stdout.
40
90
  effort_new() {
41
91
  _eff_need gh || return 1; _eff_need jq || return 1
42
- local repo name; repo="$(_eff_repo)"; name="${1:-}"; shift || true
92
+ local repo; repo="$(_eff_repo)"
43
93
  [ -n "$repo" ] || { echo "effort_new: no repo (KIT_REPO/EFFORT_REPO unset — run in a kit project)" >&2; return 1; }
44
- [ -n "$name" ] || { echo 'effort_new: usage: effort_new "<name>" [<sub title> …]' >&2; return 1; }
45
- # Validate the name against the title rule BEFORE creating anything (synthetic prefix for the lint).
46
- effort_title_lint "[Effort] 0 · $name" || { echo "effort_new: fix the name and retry" >&2; return 1; }
47
94
 
48
- local url num
49
- url="$(gh issue create --repo "$repo" --title "[Effort] · $name" --body "$(_eff_parent_body)")" \
95
+ local flow="" role="" priority="p1" goal="" scope="" for_agents="" verification="" depends_on="" milestone="" explicit_slug="" par=""
96
+ # Flags are position-INDEPENDENT: recognized --flag [value] pairs are consumed wherever they occur
97
+ # (before the title, between subs, or after them) and the remaining positionals are collected as the
98
+ # title (first) + sub specs (rest). Previously the parser broke at the first positional, so any flag
99
+ # placed after the title was mis-read as a sub-issue spec — creating junk sub-issues. `--` forces
100
+ # everything after it to be treated as positional (for a sub name that starts with a dash).
101
+ local pos=()
102
+ while [ $# -gt 0 ]; do
103
+ case "$1" in
104
+ --flow) flow="${2:-}"; shift 2 ;;
105
+ --role) role="${2:-}"; shift 2 ;;
106
+ --priority) priority="${2:-p1}"; shift 2 ;;
107
+ --goal) goal="${2:-}"; shift 2 ;;
108
+ --scope) scope="${2:-}"; shift 2 ;;
109
+ --for-agents) for_agents="${2:-}"; shift 2 ;;
110
+ --verification) verification="${2:-}"; shift 2 ;;
111
+ --depends-on) depends_on="${2:-}"; shift 2 ;;
112
+ --milestone) milestone="${2:-}"; shift 2 ;;
113
+ --slug) explicit_slug="${2:-}"; shift 2 ;;
114
+ --slug=*) explicit_slug="${1#*=}"; shift ;;
115
+ --par) par="${2:-}"; shift 2 ;;
116
+ --par=*) par="${1#*=}"; shift ;;
117
+ --) shift; while [ $# -gt 0 ]; do pos+=("$1"); shift; done ;;
118
+ --*) echo "effort_new: unknown flag $1" >&2; return 1 ;;
119
+ *) pos+=("$1"); shift ;;
120
+ esac
121
+ done
122
+ set -- "${pos[@]+"${pos[@]}"}"
123
+
124
+ # Parallelism hint label (#121): --par seq | wide | <positive-int> → a par:<value> label on the
125
+ # parent (how the effort's subs are meant to run). Validated before anything is created.
126
+ if [ -n "$par" ]; then
127
+ case "$par" in
128
+ seq|wide) : ;;
129
+ ''|*[!0-9]*) echo "effort_new: --par must be 'seq', 'wide', or a positive integer (got '$par')" >&2; return 1 ;;
130
+ *) : ;;
131
+ esac
132
+ fi
133
+
134
+ local name="${1:-}"; shift || true
135
+ [ -n "$name" ] || { echo 'effort_new: usage: effort_new [flags] "<name>" [<sub spec> …]' >&2; return 1; }
136
+
137
+ # Optional leading [Flow] tag on the board title (validated by effort_title_lint).
138
+ local flow_tag=""; [ -n "$flow" ] && flow_tag="[$flow] "
139
+
140
+ # Guard the parent name against the title rule BEFORE creating anything (synthetic number — the
141
+ # rule is about the NAME, not the not-yet-assigned N).
142
+ effort_title_lint "[Effort] 0 · ${flow_tag}${name}" || { echo "effort_new: fix the name and retry" >&2; return 1; }
143
+
144
+ # Lint EVERY sub title up front too (parity with the skill's intent) so a bad sub name fails the
145
+ # whole op before a half-effort exists. Synthetic parent number 0 for the lint.
146
+ local i=0 spec sub_name sub_title
147
+ for spec in "$@"; do
148
+ i=$((i + 1))
149
+ sub_name="${spec%% :: *}"
150
+ sub_title="[Effort 0] $i · $sub_name"
151
+ effort_title_lint "$sub_title" \
152
+ || { echo "effort_new: fix sub title #$i and retry: $sub_name" >&2; return 1; }
153
+ done
154
+
155
+ # Compose the four-section body + an optional ## Relations chain from --depends-on.
156
+ local relations="" d
157
+ if [ -n "$depends_on" ]; then
158
+ relations="$(printf '\n\n## Relations\n')"
159
+ for d in $(printf '%s' "$depends_on" | tr ',' ' '); do
160
+ d="${d#\#}"; [ -n "$d" ] && relations="$relations$(printf -- '- Depends on #%s\n' "$d")"
161
+ done
162
+ fi
163
+ local body; body="$(_eff_compose_body "$goal" "$scope" "$for_agents" "$verification" "$relations")"
164
+
165
+ # Label set: ctx (session weight from the sub count) + kind + priority + optional role + optional flow.
166
+ local subcount=$#; [ "$subcount" -ge 1 ] || subcount=1
167
+ local ctx="ctx:S"
168
+ command -v effort_ctx_bucket >/dev/null 2>&1 && ctx="$(effort_ctx_bucket 1 "$subcount")"
169
+ # Every kit-defined label is ensured before use — `gh issue create --label` fails hard on a
170
+ # missing label, which aborted the whole parent create on repos without the ctx:* set (#153).
171
+ _eff_ensure_label "$ctx" bfd4f2 "effort session weight"
172
+ _eff_ensure_label "kind:task" d4c5f9 "kit issue kind"
173
+ _eff_ensure_label "priority:$priority" e99695 "kit priority"
174
+ local labels="$ctx,kind:task,priority:$priority"
175
+ if [ -n "$role" ]; then
176
+ _eff_ensure_label "role:$role" 0e8a16 "kit role lane"
177
+ labels="$labels,role:$role"
178
+ fi
179
+ if [ -n "$flow" ]; then
180
+ local flow_lc; flow_lc="$(printf '%s' "$flow" | tr '[:upper:]' '[:lower:]')"
181
+ _eff_ensure_label "flow:$flow_lc" 1d76db "kit flow lane"
182
+ labels="$labels,flow:$flow_lc"
183
+ fi
184
+ if [ -n "$par" ]; then
185
+ _eff_ensure_label "par:$par" c5def5 "effort parallelism hint"
186
+ labels="$labels,par:$par"
187
+ fi
188
+
189
+ local url num slug
190
+ url="$(gh issue create --repo "$repo" --title "[Effort] · ${flow_tag}${name}" --body "$body" \
191
+ --label "$labels" ${milestone:+--milestone "$milestone"})" \
50
192
  || { echo "effort_new: failed to create the parent issue" >&2; return 1; }
51
193
  num="${url##*/}"
52
- gh issue edit "$num" --repo "$repo" --title "[Effort] $num · $name" >/dev/null 2>&1
53
- echo " ✓ effort #$num · $name" >&2
194
+ gh issue edit "$num" --repo "$repo" --title "[Effort] $num · ${flow_tag}${name}" >/dev/null 2>&1
195
+ # The human handle (#93): explicit --slug if given, else derived from the title (number/flow peeled).
196
+ if [ -n "$explicit_slug" ]; then slug="$(_eff_slug "$explicit_slug")"
197
+ else slug="$(_eff_title_slug "[Effort] $num · ${flow_tag}${name}")"; fi
198
+ if [ -n "$slug" ]; then
199
+ gh label create "slug:$slug" --repo "$repo" --color ededed \
200
+ --description "effort slug handle" >/dev/null 2>&1 || true # idempotent: ok if it exists
201
+ gh issue edit "$num" --repo "$repo" --add-label "slug:$slug" >/dev/null 2>&1 || true
202
+ fi
203
+ echo " ✓ effort $(effort_display "$num" "$slug") · ${flow_tag}${name}" >&2
54
204
 
55
- local i=0 sub child
56
- for sub in "$@"; do
205
+ # Native dependency edges (the visible board chain) — guarded on the helper being available.
206
+ if [ -n "$depends_on" ] && command -v effort_set_blocked_by >/dev/null 2>&1; then
207
+ for d in $(printf '%s' "$depends_on" | tr ',' ' '); do
208
+ d="${d#\#}"; [ -n "$d" ] && { effort_set_blocked_by "$num" "$d" || true; }
209
+ done
210
+ fi
211
+
212
+ # Board: add the parent (guarded — no-op when Projects v2 is off / helpers not loaded).
213
+ _eff_board_add "$num" "$role" || true
214
+
215
+ # Create each sub-issue (titles already linted), native-link it, add it to the board.
216
+ local sub_desc child child_num
217
+ i=0
218
+ for spec in "$@"; do
57
219
  i=$((i + 1))
58
- child="$(gh issue create --repo "$repo" --title "[Effort $num] $i · $sub" --body "Parent #$num." )" || continue
59
- effort_link_sub "$num" "${child##*/}" || true
220
+ sub_name="${spec%% :: *}"
221
+ sub_desc="${spec#* :: }"; [ "$sub_desc" = "$spec" ] && sub_desc=""
222
+ sub_title="[Effort $num] $i · $sub_name"
223
+ local sub_labels="kind:task,priority:$priority"
224
+ [ -n "$role" ] && sub_labels="$sub_labels,role:$role"
225
+ child="$(gh issue create --repo "$repo" --title "$sub_title" \
226
+ --body "$(printf '%s\n\nSub-issue of #%s (effort).' "$sub_desc" "$num")" \
227
+ --label "$sub_labels" ${milestone:+--milestone "$milestone"})" || continue
228
+ child_num="${child##*/}"
229
+ effort_link_sub "$num" "$child_num" || true
230
+ _eff_board_add "$child_num" "$role" || true
231
+ echo " ✓ sub #$child_num · $sub_name" >&2
60
232
  done
61
233
  printf '%s\n' "$num"
62
234
  }
63
235
 
64
- # effort_start <N> [<slug>] — create the effort/<N> integration branch + its worktree from the base.
236
+ # _eo_source_wt — lazily source the worktree mechanic (worktree-start.sh) so effort_start gets the
237
+ # SAME full worktree setup as `cckit start`: wt_bootstrap (env-file copy + per-worktree dev port +
238
+ # dependency install) and the _wt_session_owns collision guard. bin/cckit's `effort` verb does not
239
+ # load it, so effort-ops brings it in on demand (#119). No-op if already loaded.
240
+ _eo_source_wt() {
241
+ command -v wt_bootstrap >/dev/null 2>&1 && return 0
242
+ local d; d="$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" && pwd)"
243
+ # shellcheck source=/dev/null
244
+ [ -f "$d/worktree-start.sh" ] && . "$d/worktree-start.sh"
245
+ }
246
+
247
+ # effort_start <slug|N> [<slug>] — create the effort/<N> integration branch + its worktree from base,
248
+ # with the full `cckit start` worktree setup (env copy, per-worktree dev port, dependency install —
249
+ # opt out with KIT_WT_INSTALL=0) and a live-session collision guard.
65
250
  effort_start() {
66
251
  _eff_need git || return 1
67
- local num="${1:-}" slug_override="${2:-}" repo base root title slug branch wt
68
- [ -n "$num" ] || { echo "effort_start: <effort issue #> required" >&2; return 1; }
252
+ local raw="${1:-}" slug_override="${2:-}" num repo base root title slug branch wt
253
+ [ -n "$raw" ] || { echo "effort_start: <slug|effort issue #> required" >&2; return 1; }
254
+ num="$(effort_slug_resolve "$raw")" || { echo "effort_start: could not resolve '$raw' to an effort" >&2; return 1; }
69
255
  repo="$(_eff_repo)"; base="$(_eff_base)"
70
256
  root="$(git worktree list --porcelain 2>/dev/null | awk '/^worktree /{print $2; exit}')"
71
257
  [ -n "$root" ] || { echo "effort_start: not in a git repo" >&2; return 1; }
72
258
 
73
- if [ -n "$slug_override" ]; then slug="$slug_override"
259
+ if [ -n "$slug_override" ]; then slug="$(_eff_slug "$slug_override")"
74
260
  else
75
261
  title="$(gh issue view "$num" --repo "$repo" --json title -q .title 2>/dev/null)"
76
- slug="$(_eff_slug "${title:-effort}")"; [ -n "$slug" ] || slug="effort"
262
+ slug="$(_eff_title_slug "${title:-effort}")"; [ -n "$slug" ] || slug="effort"
263
+ fi
264
+ # Worktree dir follows the kind+N-slug convention (branch-naming.md) so kit-gc's issue-open
265
+ # protection recognizes it by DIRECTORY name too — matching the kit-effort-start skill (#119).
266
+ branch="effort/$num-$slug"; wt="$root/.claude/worktrees/effort+$num-$slug"
267
+
268
+ _eo_source_wt
269
+
270
+ # Session-collision precheck: never disturb a worktree a LIVE session is sitting in (its work may
271
+ # be uncommitted). Guarded on the helper being available.
272
+ if [ -d "$wt" ] && command -v _wt_session_owns >/dev/null 2>&1 && _wt_session_owns "$root" "$wt"; then
273
+ echo "effort_start: a live session owns $wt — refusing to disturb it" >&2; return 1
77
274
  fi
78
- branch="effort/$num-$slug"; wt="$root/.claude/worktrees/effort-$num"
79
275
 
80
276
  git -C "$root" fetch origin "$base" --quiet 2>/dev/null || true
81
277
  if git -C "$root" show-ref --verify --quiet "refs/heads/$branch"; then
@@ -85,48 +281,282 @@ effort_start() {
85
281
  git -C "$root" worktree add -b "$branch" "$wt" "$from" >/dev/null 2>&1 \
86
282
  || { echo "effort_start: failed to create worktree for $branch" >&2; return 1; }
87
283
  fi
88
- echo " ✓ effort #$num → $branch (worktree: $wt)" >&2
284
+
285
+ # Bootstrap the worktree for local dev: copy gitignored env, assign a per-worktree dev port, and
286
+ # install deps (KIT_WT_INSTALL=0 opts out). Best-effort — a hiccup never fails the start.
287
+ command -v wt_bootstrap >/dev/null 2>&1 && wt_bootstrap "$root" "$wt" "$num" || true
288
+
289
+ echo " ✓ effort $(effort_display "$num" "$slug") → $branch (worktree: $wt)" >&2
89
290
  printf '%s|%s|%s\n' "$wt" "$branch" "$num"
90
291
  }
91
292
 
92
- # effort_pr [<N>] — open the single PR effort/<N> → base. N defaults to the current effort branch.
293
+ # effort_pr [<slug|N>] — open the single PR effort/<N> → base. Defaults to the current effort branch.
93
294
  effort_pr() {
94
295
  _eff_need gh || return 1
95
- local num="${1:-}" repo base branch title name
296
+ local raw="${1:-}" num repo base branch title name
96
297
  repo="$(_eff_repo)"; base="$(_eff_base)"
97
298
  branch="$(git rev-parse --abbrev-ref HEAD 2>/dev/null)"
98
- [ -n "$num" ] || num="$(effort_branch_num "$branch")"
99
- [ -n "$num" ] || { echo "effort_pr: not on an effort/<N>-… branch and no <N> given" >&2; return 1; }
299
+ if [ -n "$raw" ]; then
300
+ num="$(effort_slug_resolve "$raw")" || { echo "effort_pr: could not resolve '$raw' to an effort" >&2; return 1; }
301
+ else
302
+ num="$(effort_branch_num "$branch")"
303
+ fi
304
+ [ -n "$num" ] || { echo "effort_pr: not on an effort/<N>-… branch and no <slug|N> given" >&2; return 1; }
100
305
  case "$branch" in effort/"$num"-*) : ;; *) echo "effort_pr: current branch ($branch) is not effort/$num-…" >&2; return 1 ;; esac
101
306
 
102
307
  git push -u origin "$branch" >/dev/null 2>&1 || true
103
308
  title="$(gh issue view "$num" --repo "$repo" --json title -q .title 2>/dev/null)"
104
309
  name="$(printf '%s' "$title" | sed -E 's/^\[Effort\] [0-9]+ · ?//')"
310
+ # ONE shared composer (effort.sh) so the verb + the kit-effort-pr skill title identically, then the
311
+ # mandatory-[#N] check before we ever call gh — refuse rather than open an id-less PR (#121).
312
+ local pr_title; pr_title="$(effort_pr_title "$num" "${name:-effort}")"
313
+ effort_pr_title_check "$pr_title" "$num" || { echo "effort_pr: refusing to open a PR without the [#$num] effort id" >&2; return 1; }
105
314
  gh pr create --repo "$repo" --base "$base" --head "$branch" \
106
- --title "[Effort] $num · ${name:-effort}" \
315
+ --title "$pr_title" \
107
316
  --body "$(printf 'Closes the #%s effort.\n\n## For agents\nSee #%s for the goal, scope, and entry points.\n' "$num" "$num")"
108
317
  }
109
318
 
110
- # effort_close <N> — snapshot per-sub diffs (before squash), squash-merge the PR, close parent + subs.
111
- # Destructive: it merges and closes. Snapshots first so the per-sub work record survives the squash.
319
+ # _eo_source_metrics — lazily source effort-metrics.sh so effort_close can call the shipped
320
+ # capture/judge/sync functions even when only effort-ops is loaded (bin/cckit sources it for the
321
+ # effort verb; this makes the composition robust + testable). No-op if already loaded.
322
+ _eo_source_metrics() {
323
+ command -v capture_effort_metrics >/dev/null 2>&1 && return 0
324
+ local d; d="$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" && pwd)"
325
+ # shellcheck source=/dev/null
326
+ [ -f "$d/effort-metrics.sh" ] && . "$d/effort-metrics.sh"
327
+ }
328
+
329
+ # _eo_source_board — lazily source the board helpers (gh-project.sh) + captured field ids so
330
+ # effort_close can set Status=Done from any shell, with no caller wiring (bin/cckit sources the
331
+ # board helpers only for `effort new`). Guarded: a no-op unless Projects v2 is on; a missing
332
+ # gh-project.sh or ids file degrades to a no-op (the board steps below are themselves guarded).
333
+ _eo_source_board() {
334
+ [ "${KIT_PROJECTS_V2:-}" = "true" ] || return 0
335
+ if ! command -v project_find_item_by_issue >/dev/null 2>&1; then
336
+ local d; d="$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" && pwd)"
337
+ # shellcheck source=/dev/null
338
+ [ -f "$d/gh-project.sh" ] && . "$d/gh-project.sh"
339
+ fi
340
+ if [ -z "${STATUS_FIELD_ID:-}" ] && command -v load_project_ids >/dev/null 2>&1; then
341
+ load_project_ids >/dev/null 2>&1 || true
342
+ fi
343
+ return 0
344
+ }
345
+
346
+ # _eo_board_done <issue #> — set the board Status=Done for one issue. Guarded like _eff_board_add:
347
+ # a no-op unless Projects v2 is on AND the board helpers + field ids are loaded. Best-effort — a
348
+ # board hiccup never fails the close (the merge already landed).
349
+ _eo_board_done() {
350
+ local n="$1" item
351
+ [ "${KIT_PROJECTS_V2:-}" = "true" ] || return 0
352
+ command -v project_find_item_by_issue >/dev/null 2>&1 || return 0
353
+ [ -n "${STATUS_FIELD_ID:-}" ] && [ -n "${STATUS_OPT_DONE:-}" ] || return 0
354
+ item="$(project_find_item_by_issue "$n" 2>/dev/null)" || return 0
355
+ [ -n "$item" ] || { echo " ⚠ #$n not on board — skipped" >&2; return 0; }
356
+ project_set_single_select "$item" "$STATUS_FIELD_ID" "$STATUS_OPT_DONE" 2>/dev/null \
357
+ && echo " ✓ board Done: #$n" >&2 || true
358
+ return 0
359
+ }
360
+
361
+ # Kit-managed paths (the kit ⇄ project sync surface): a change here that is not contributed
362
+ # upstream (/kit-contribute) is a latent regression the next /kit-update can clobber. One place —
363
+ # effort_close's drift check greps against this (was inlined in the kit-effort-close skill, #148).
364
+ _EO_KIT_MANAGED_RE='^(scripts/(lib/|kit$|kit-)|\.claude/(skills|rules|hooks|lib|agents)/)'
365
+
366
+ # _eo_knowledge_ingest <num> <trace_dir> <root> — optional post-close knowledge-ingest hook. Runs a
367
+ # project-configured command (github/effort.knowledgeIngestHook, or KIT_EFFORT_KNOWLEDGE_HOOK) with
368
+ # the effort number + trace dir, so a project can fold the closed effort's work record into its
369
+ # knowledge base. Config-gated: a NO-OP when unset or the hook file is missing/not executable — the
370
+ # kit ships no default hook. Best-effort — a hook failure never fails the close.
371
+ _eo_knowledge_ingest() {
372
+ local num="$1" trace="$2" root="$3" hook="" cfg
373
+ hook="${KIT_EFFORT_KNOWLEDGE_HOOK:-}"
374
+ if [ -z "$hook" ]; then
375
+ cfg="${KIT_CONFIG:-}"; [ -n "$cfg" ] || { [ -f "$root/cckit.config.json" ] && cfg="$root/cckit.config.json" || cfg="$root/.claude/kit.config.json"; }
376
+ [ -f "$cfg" ] && command -v jq >/dev/null 2>&1 \
377
+ && hook="$(jq -r '.effort.knowledgeIngestHook // empty' "$cfg" 2>/dev/null)"
378
+ fi
379
+ [ -n "$hook" ] || return 0
380
+ case "$hook" in /*) : ;; *) hook="$root/$hook" ;; esac # resolve a relative hook against the root
381
+ [ -x "$hook" ] || { echo "effort_close: knowledge-ingest hook '$hook' not executable — skipping" >&2; return 0; }
382
+ echo " → knowledge-ingest hook: $hook $num" >&2
383
+ "$hook" "$num" "$trace" >/dev/null 2>&1 || echo "effort_close: knowledge-ingest hook failed (non-fatal)" >&2
384
+ }
385
+
386
+ # effort_close <N> — the SINGLE close implementation (#148): the /kit-effort-close skill is a thin
387
+ # caller of this function, never a second close. Snapshot per-sub diffs + capture metrics BEFORE the
388
+ # squash (the squash erases the per-sub history), REFUSE to squash if no work trace was captured
389
+ # (KIT_FORCE=1 overrides), squash-merge, judge + sync the metrics, close parent + subs, set the board
390
+ # Status=Done for each (guarded), GC the worktree/branch, run the optional knowledge-ingest hook,
391
+ # and finish with the advisory kit-sync drift check. Destructive: it merges, closes, and prunes.
112
392
  effort_close() {
113
393
  _eff_need gh || return 1; _eff_need jq || return 1
114
- local num="${1:-}" repo base branch
115
- [ -n "$num" ] || { echo "effort_close: <effort issue #> required" >&2; return 1; }
394
+ local raw="${1:-}" num repo base branch root self_wt trace_dir kit_touched
395
+ [ -n "$raw" ] || { echo "effort_close: <slug|effort issue #> required" >&2; return 1; }
396
+ num="$(effort_slug_resolve "$raw")" || { echo "effort_close: could not resolve '$raw' to an effort" >&2; return 1; }
116
397
  repo="$(_eff_repo)"; base="$(_eff_base)"
117
398
  branch="$(git rev-parse --abbrev-ref HEAD 2>/dev/null)"
118
- case "$branch" in effort/"$num"-*) : ;; *) echo "effort_close: run from the effort/$num-… branch" >&2; return 1 ;; esac
399
+ case "$branch" in
400
+ effort/"$num"-*) : ;;
401
+ *)
402
+ # Not on the integration branch. If effort/<num>-… exists (locally or on origin), this is
403
+ # just the wrong cwd — keep the instruction. If it exists NOWHERE, this is a WAVE-style
404
+ # effort (#164): the subs shipped as individual task PRs squash-merged straight to base, so
405
+ # there is no branch to run from — close via the merged sub PRs instead.
406
+ if git branch --list "effort/$num-*" 2>/dev/null | grep -q . \
407
+ || git ls-remote --heads origin "effort/$num-*" 2>/dev/null | grep -q .; then
408
+ echo "effort_close: run from the effort/$num-… branch" >&2; return 1
409
+ fi
410
+ _eo_close_wave "$num" "$repo" "$base"; return $? ;;
411
+ esac
412
+ root="$(git worktree list --porcelain 2>/dev/null | awk '/^worktree /{print $2; exit}')"
413
+ self_wt="$(git rev-parse --show-toplevel 2>/dev/null)"
414
+ _eo_source_metrics
415
+
416
+ # (a) snapshot the per-sub-issue diffs while the unsquashed history still exists (echoes the trace dir).
417
+ trace_dir="$(effort_snapshot_subs "$num" "origin/$base" 2>/dev/null)"
418
+
419
+ # (a2) refuse-squash-without-trace backstop: the squash is irreversible and collapses the per-sub
420
+ # commits that ARE the work record. If nothing was snapshotted, refuse — unless KIT_FORCE=1.
421
+ if [ -z "$trace_dir" ] || ! ls "$trace_dir"/*.diff >/dev/null 2>&1; then
422
+ if [ "${KIT_FORCE:-0}" = "1" ]; then
423
+ echo "effort_close: no per-sub work trace captured — proceeding anyway (KIT_FORCE=1)" >&2
424
+ else
425
+ echo "effort_close: refusing to squash-merge #$num — no per-sub work trace was captured; the squash would erase the per-sub history irrecoverably. Run from the effort branch with its commits present, or set KIT_FORCE=1 to override." >&2
426
+ return 1
427
+ fi
428
+ fi
429
+
430
+ # (b) capture effort metrics PRE-squash (needs the live-branch diff + commit signals).
431
+ command -v capture_effort_metrics >/dev/null 2>&1 && capture_effort_metrics "$num" "origin/$base" || true
119
432
 
120
- # (a) snapshot the per-sub-issue diffs while the unsquashed history still exists.
121
- effort_snapshot_subs "$num" "origin/$base" || true
122
- # (b) squash-merge the effort PR.
433
+ # (b2) record which kit-managed files this effort touched, PRE-squash (the branch is GC'd below,
434
+ # so the live-branch diff is the reliable source). The warning itself is emitted last (step h).
435
+ kit_touched="$(git diff --name-only "origin/$base"...HEAD 2>/dev/null \
436
+ | grep -E "$_EO_KIT_MANAGED_RE" | sort -u || true)"
437
+
438
+ # (c) squash-merge the effort PR.
123
439
  gh pr merge "$branch" --repo "$repo" --squash --delete-branch >/dev/null 2>&1 \
124
440
  || { echo "effort_close: could not squash-merge the PR for $branch (open? mergeable?)" >&2; return 1; }
125
441
  echo " ✓ merged $branch" >&2
126
- # (c) close every native sub-issue, then the parent.
442
+
443
+ # (d) judge + sync the metrics (judge reads the durable trace dir; sync no-ops when the engine is off).
444
+ command -v judge_effort_metrics >/dev/null 2>&1 && judge_effort_metrics "$num" "origin/$base" || true
445
+ command -v sync_effort_metrics >/dev/null 2>&1 && sync_effort_metrics "$num" || true
446
+
447
+ # (e) close every native sub-issue, then the parent — and set the board Status=Done for each
448
+ # (guarded: a no-op when Projects v2 is off or the board helpers/ids are unavailable). Board +
449
+ # issue + record state are owned by this ONE op (effort-model.md) — never a separate "mark done".
450
+ _eo_source_board
127
451
  local sub
128
452
  for sub in $(gh api "repos/$repo/issues/$num/sub_issues" --jq '.[].number' 2>/dev/null); do
129
453
  gh issue close "$sub" --repo "$repo" --reason completed >/dev/null 2>&1 && echo " ✓ closed sub #$sub" >&2
454
+ _eo_board_done "$sub"
130
455
  done
131
456
  gh issue close "$num" --repo "$repo" --reason completed >/dev/null 2>&1 && echo " ✓ closed effort #$num" >&2
457
+ _eo_board_done "$num"
458
+
459
+ # (f) GC: switch the main checkout to base, remove the effort worktree, delete the local branch,
460
+ # prune. The remote branch was deleted by --delete-branch above. All via `git -C "$root"` so the
461
+ # caller's cwd is never moved. Best-effort — a GC hiccup never fails the (already-landed) close.
462
+ if [ -n "$root" ]; then
463
+ git -C "$root" checkout "$base" >/dev/null 2>&1 || true
464
+ git -C "$root" pull origin "$base" --quiet >/dev/null 2>&1 || true
465
+ if [ -n "$self_wt" ] && [ "$self_wt" != "$root" ]; then
466
+ case "$self_wt" in "$root"/.claude/worktrees/*)
467
+ git -C "$root" worktree remove "$self_wt" --force >/dev/null 2>&1 && echo " ✓ removed worktree $self_wt" >&2 ;;
468
+ esac
469
+ fi
470
+ git -C "$root" branch -D "$branch" >/dev/null 2>&1 && echo " ✓ deleted local branch $branch" >&2
471
+ git -C "$root" worktree prune >/dev/null 2>&1 || true
472
+ fi
473
+
474
+ # (g) optional, config-gated knowledge-ingest hook (no-op when absent).
475
+ _eo_knowledge_ingest "$num" "${trace_dir:-}" "$root"
476
+
477
+ # (h) kit-sync drift check — kit ⇄ project stay in sync (#148, moved here from the skill).
478
+ _eo_kit_sync_warn "$kit_touched"
479
+ }
480
+
481
+ # _eo_kit_sync_warn <files> — the advisory kit-sync drift warning, shared by both close styles
482
+ # (#148/#164). If an effort changed kit-managed files they likely belong upstream (/kit-contribute);
483
+ # an un-upstreamed change is a latent regression the next /kit-update can clobber. Never blocks.
484
+ _eo_kit_sync_warn() {
485
+ [ -n "${1:-}" ] || return 0
486
+ {
487
+ echo ""
488
+ echo " ⚠ kit-sync: this effort changed kit-managed files — review for upstream (/kit-contribute):"
489
+ printf '%s\n' "$1" | sed 's/^/ /'
490
+ echo " kit ⇄ project must stay in sync; an un-upstreamed change can be clobbered by /kit-update."
491
+ } >&2
492
+ }
493
+
494
+ # _eo_close_wave <num> <repo> <base> — close a WAVE-style effort (#164): every sub was delivered as
495
+ # its own task PR squash-merged straight to base (`cckit wave` → fan-out → `cckit watch --merge`),
496
+ # so no effort/<N> integration branch ever existed. Verifies every sub is CLOSED with a merged
497
+ # closing PR (refuses and lists the stragglers otherwise), snapshots the work trace from the merged
498
+ # sub PR diffs, then runs the SAME close tail as the branch path: judge + sync metrics, close the
499
+ # parent, board Status=Done for parent + subs, knowledge-ingest hook, kit-sync drift check.
500
+ # capture_effort_metrics is intentionally skipped — there is no live branch diff to measure; the
501
+ # merged PR diffs in the trace are the work record.
502
+ _eo_close_wave() {
503
+ local num="$1" repo="$2" base="$3" root rows bad trace_dir kit_touched sub
504
+ root="$(git worktree list --porcelain 2>/dev/null | awk '/^worktree /{print $2; exit}')"
505
+ _eo_source_metrics
506
+
507
+ # (a) read every sub + the merged PR that closed it, one "sub|state|pr|merge-oid|title" line each
508
+ # (title LAST so a stray "|" in it can't shift the fields awk/read split on).
509
+ rows="$(gh api graphql -f query='
510
+ query($o:String!,$r:String!,$n:Int!){ repository(owner:$o,name:$r){ issue(number:$n){
511
+ subIssues(first:50){ nodes { number state
512
+ closedByPullRequestsReferences(first:10){ nodes { number merged mergeCommit{oid} title } } } } } } }' \
513
+ -F o="${repo%/*}" -F r="${repo#*/}" -F n="$num" --jq '
514
+ .data.repository.issue.subIssues.nodes[]
515
+ | (((.closedByPullRequestsReferences.nodes // []) | map(select(.merged)) | .[0]) // null) as $pr
516
+ | "\(.number)|\(.state)|\($pr.number // "")|\($pr.mergeCommit.oid // "")|\($pr.title // "")"' 2>/dev/null)"
517
+ [ -n "$rows" ] || { echo "effort_close: no effort/$num-… branch and no readable sub-issues — nothing to close (wave-style needs merged subs, #164)" >&2; return 1; }
518
+
519
+ # (b) every sub must be CLOSED with a merged closing PR — otherwise the effort is not done.
520
+ bad="$(printf '%s\n' "$rows" | awk -F'|' '$2 != "CLOSED" || $3 == "" {
521
+ printf " #%s (%s%s)\n", $1, tolower($2), ($3 == "" ? ", no merged PR" : "") }')"
522
+ if [ -n "$bad" ]; then
523
+ echo "effort_close: #$num is not done — these subs are still open or lack a merged PR:" >&2
524
+ printf '%s\n' "$bad" >&2
525
+ return 1
526
+ fi
527
+
528
+ # (c) the work trace, from the merged sub PR diffs (the record the per-sub squashes left behind).
529
+ # Same refuse-without-trace backstop as the branch path (#120) — KIT_FORCE=1 overrides.
530
+ trace_dir="$(effort_snapshot_merged_subs "$num" "$rows" 2>/dev/null)"
531
+ if [ -z "$trace_dir" ] || ! ls "$trace_dir"/*.diff >/dev/null 2>&1; then
532
+ if [ "${KIT_FORCE:-0}" = "1" ]; then
533
+ echo "effort_close: no per-sub work trace captured — proceeding anyway (KIT_FORCE=1)" >&2
534
+ else
535
+ echo "effort_close: refusing to close #$num — could not capture the work trace from the merged sub PRs. Set KIT_FORCE=1 to override." >&2
536
+ return 1
537
+ fi
538
+ fi
539
+
540
+ # (d) judge + sync the metrics off the trace (guarded, best-effort — same as the branch path).
541
+ command -v judge_effort_metrics >/dev/null 2>&1 && judge_effort_metrics "$num" "origin/$base" || true
542
+ command -v sync_effort_metrics >/dev/null 2>&1 && sync_effort_metrics "$num" || true
543
+
544
+ # (e) kit-sync drift source: the union of files across the merged sub PR diffs.
545
+ kit_touched="$(awk '/^diff --git /{print $3}' "$trace_dir"/*.diff 2>/dev/null | sed 's#^a/##' \
546
+ | grep -E "$_EO_KIT_MANAGED_RE" | sort -u || true)"
547
+
548
+ # (f) close the parent + board Status=Done for parent and every sub (subs are already closed).
549
+ _eo_source_board
550
+ for sub in $(printf '%s\n' "$rows" | cut -d'|' -f1); do
551
+ _eo_board_done "$sub"
552
+ done
553
+ gh issue close "$num" --repo "$repo" --reason completed >/dev/null 2>&1 && echo " ✓ closed effort #$num" >&2
554
+ _eo_board_done "$num"
555
+
556
+ # (g) GC: the sub branches/worktrees were GC'd by their own merges — just prune stragglers.
557
+ [ -n "$root" ] && git -C "$root" worktree prune >/dev/null 2>&1 || true
558
+
559
+ # (h) same optional hook + advisory drift check as the branch path.
560
+ _eo_knowledge_ingest "$num" "${trace_dir:-}" "$root"
561
+ _eo_kit_sync_warn "$kit_touched"
132
562
  }