@jeiemgi/cckit 0.2.0 → 0.3.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 (62) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/AGENTS.md +21 -8
  3. package/README.md +63 -5
  4. package/bin/cckit +37 -16
  5. package/cckit.config.json +1 -1
  6. package/commands/kit-doctor.md +3 -1
  7. package/kit.config.schema.json +24 -0
  8. package/package.json +1 -1
  9. package/scripts/annotate-setup.sh +7 -2
  10. package/scripts/capture-project-ids.sh +23 -10
  11. package/scripts/init.sh +22 -4
  12. package/scripts/kit-doctor.sh +185 -7
  13. package/scripts/kit-version-check-test.sh +36 -0
  14. package/scripts/kit-version-check.sh +19 -4
  15. package/scripts/knowledge-lint.sh +4 -1
  16. package/scripts/lib/board-view-test.sh +54 -0
  17. package/scripts/lib/board-view.sh +80 -0
  18. package/scripts/lib/captain-test.sh +18 -0
  19. package/scripts/lib/captain.sh +92 -5
  20. package/scripts/lib/config-path-test.sh +47 -0
  21. package/scripts/lib/config-path.sh +29 -0
  22. package/scripts/lib/copilot.sh +9 -9
  23. package/scripts/lib/effort-metrics-test.sh +57 -0
  24. package/scripts/lib/effort-metrics.sh +19 -5
  25. package/scripts/lib/effort-ops-test.sh +51 -2
  26. package/scripts/lib/effort-ops.sh +314 -49
  27. package/scripts/lib/effort-parity-test.sh +128 -0
  28. package/scripts/lib/effort-slug-test.sh +87 -0
  29. package/scripts/lib/effort-slug.sh +104 -0
  30. package/scripts/lib/effort.sh +34 -0
  31. package/scripts/lib/gh-project-test.sh +95 -0
  32. package/scripts/lib/gh-project.sh +22 -7
  33. package/scripts/lib/git-remote-test.sh +57 -0
  34. package/scripts/lib/git-remote.sh +21 -0
  35. package/scripts/lib/kit-config-test.sh +37 -0
  36. package/scripts/lib/kit-config.sh +33 -13
  37. package/scripts/lib/kit-events.sh +5 -3
  38. package/scripts/lib/kit-gc-test.sh +88 -0
  39. package/scripts/lib/kit-gc.sh +136 -19
  40. package/scripts/lib/kit-local.sh +8 -1
  41. package/scripts/lib/next.sh +3 -3
  42. package/scripts/lib/plan-next-test.sh +87 -0
  43. package/scripts/lib/plan-next.sh +212 -0
  44. package/scripts/lib/project-scan.sh +7 -1
  45. package/scripts/lib/worktree-start.sh +12 -3
  46. package/scripts/lib/zsh-safety-test.sh +73 -0
  47. package/scripts/portable-test.sh +62 -20
  48. package/scripts/setup-labels.sh +13 -2
  49. package/scripts/showcase.sh +13 -4
  50. package/scripts/status-test.sh +63 -0
  51. package/scripts/status.sh +12 -4
  52. package/scripts/task-sync.sh +79 -10
  53. package/skills/kit-autopilot/SKILL.md +5 -0
  54. package/skills/{docs-writer → kit-docs-writer}/SKILL.md +2 -2
  55. package/skills/kit-effort-new/SKILL.md +39 -111
  56. package/skills/kit-effort-pr/SKILL.md +6 -2
  57. package/skills/kit-next/SKILL.md +4 -0
  58. package/skills/kit-plan-next/SKILL.md +82 -0
  59. package/templates/hooks/mempal_session_start.sh.tmpl +36 -2
  60. package/templates/rules/effort-model.md +26 -6
  61. package/templates/rules/mempalace.md +1 -0
  62. package/templates/rules/plan-next.md +58 -0
@@ -4,78 +4,256 @@
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
+ # Add an issue (by number) to the project board + set Status=Todo and the Role field. Guarded: a
54
+ # no-op unless Projects v2 is on AND the project helpers (gh-project.sh) are already sourced, so the
55
+ # verb can run from any shell with no board config. Mirrors the skill's old inline board block.
56
+ _eff_board_add() {
57
+ local n="$1" role="${2:-}" repo node item ropt
58
+ [ "${KIT_PROJECTS_V2:-}" = "true" ] || return 0
59
+ command -v project_add_item >/dev/null 2>&1 || return 0
60
+ repo="$(_eff_repo)"
61
+ node="$(gh api "repos/$repo/issues/$n" --jq .node_id 2>/dev/null)" || return 0
62
+ item="$(project_add_item "$node" 2>/dev/null)" || return 0
63
+ [ -n "$item" ] || return 0
64
+ [ -n "${STATUS_FIELD_ID:-}" ] && [ -n "${STATUS_OPT_TODO:-}" ] \
65
+ && project_set_single_select "$item" "$STATUS_FIELD_ID" "$STATUS_OPT_TODO" 2>/dev/null || true
66
+ if [ -n "$role" ] && command -v role_option_id >/dev/null 2>&1; then
67
+ ropt="$(role_option_id "$role" 2>/dev/null || echo "")"
68
+ [ -n "$ropt" ] && [ -n "${ROLE_FIELD_ID:-}" ] \
69
+ && project_set_single_select "$item" "$ROLE_FIELD_ID" "$ropt" 2>/dev/null || true
70
+ fi
71
+ return 0
72
+ }
73
+
74
+ # effort_new [flags] "<name>" [<sub spec> …] — the shared creation core (effort #98).
75
+ # Flags (all optional): --flow F --role R --priority p1 --goal G --scope S --for-agents A
76
+ # --verification V --depends-on "#1,#2" --milestone M --slug S. A <sub spec> is "name :: one-line
77
+ # desc" (the desc is optional → just "name"). Fills the four body sections, applies the
78
+ # ctx/kind/priority/role/flow label set, lints the parent + EVERY sub title up front (so a bad sub
79
+ # name aborts before anything is created), links native sub-issues, sets blocked_by edges, adds
80
+ # everything to the board (guarded), and records the human slug handle (#93) as a slug:<slug> label.
81
+ # Echoes the parent number on stdout.
40
82
  effort_new() {
41
83
  _eff_need gh || return 1; _eff_need jq || return 1
42
- local repo name; repo="$(_eff_repo)"; name="${1:-}"; shift || true
84
+ local repo; repo="$(_eff_repo)"
43
85
  [ -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
86
 
48
- local url num
49
- url="$(gh issue create --repo "$repo" --title "[Effort] · $name" --body "$(_eff_parent_body)")" \
87
+ local flow="" role="" priority="p1" goal="" scope="" for_agents="" verification="" depends_on="" milestone="" explicit_slug="" par=""
88
+ # Flags are position-INDEPENDENT: recognized --flag [value] pairs are consumed wherever they occur
89
+ # (before the title, between subs, or after them) and the remaining positionals are collected as the
90
+ # title (first) + sub specs (rest). Previously the parser broke at the first positional, so any flag
91
+ # placed after the title was mis-read as a sub-issue spec — creating junk sub-issues. `--` forces
92
+ # everything after it to be treated as positional (for a sub name that starts with a dash).
93
+ local pos=()
94
+ while [ $# -gt 0 ]; do
95
+ case "$1" in
96
+ --flow) flow="${2:-}"; shift 2 ;;
97
+ --role) role="${2:-}"; shift 2 ;;
98
+ --priority) priority="${2:-p1}"; shift 2 ;;
99
+ --goal) goal="${2:-}"; shift 2 ;;
100
+ --scope) scope="${2:-}"; shift 2 ;;
101
+ --for-agents) for_agents="${2:-}"; shift 2 ;;
102
+ --verification) verification="${2:-}"; shift 2 ;;
103
+ --depends-on) depends_on="${2:-}"; shift 2 ;;
104
+ --milestone) milestone="${2:-}"; shift 2 ;;
105
+ --slug) explicit_slug="${2:-}"; shift 2 ;;
106
+ --slug=*) explicit_slug="${1#*=}"; shift ;;
107
+ --par) par="${2:-}"; shift 2 ;;
108
+ --par=*) par="${1#*=}"; shift ;;
109
+ --) shift; while [ $# -gt 0 ]; do pos+=("$1"); shift; done ;;
110
+ --*) echo "effort_new: unknown flag $1" >&2; return 1 ;;
111
+ *) pos+=("$1"); shift ;;
112
+ esac
113
+ done
114
+ set -- "${pos[@]+"${pos[@]}"}"
115
+
116
+ # Parallelism hint label (#121): --par seq | wide | <positive-int> → a par:<value> label on the
117
+ # parent (how the effort's subs are meant to run). Validated before anything is created.
118
+ if [ -n "$par" ]; then
119
+ case "$par" in
120
+ seq|wide) : ;;
121
+ ''|*[!0-9]*) echo "effort_new: --par must be 'seq', 'wide', or a positive integer (got '$par')" >&2; return 1 ;;
122
+ *) : ;;
123
+ esac
124
+ fi
125
+
126
+ local name="${1:-}"; shift || true
127
+ [ -n "$name" ] || { echo 'effort_new: usage: effort_new [flags] "<name>" [<sub spec> …]' >&2; return 1; }
128
+
129
+ # Optional leading [Flow] tag on the board title (validated by effort_title_lint).
130
+ local flow_tag=""; [ -n "$flow" ] && flow_tag="[$flow] "
131
+
132
+ # Guard the parent name against the title rule BEFORE creating anything (synthetic number — the
133
+ # rule is about the NAME, not the not-yet-assigned N).
134
+ effort_title_lint "[Effort] 0 · ${flow_tag}${name}" || { echo "effort_new: fix the name and retry" >&2; return 1; }
135
+
136
+ # Lint EVERY sub title up front too (parity with the skill's intent) so a bad sub name fails the
137
+ # whole op before a half-effort exists. Synthetic parent number 0 for the lint.
138
+ local i=0 spec sub_name sub_title
139
+ for spec in "$@"; do
140
+ i=$((i + 1))
141
+ sub_name="${spec%% :: *}"
142
+ sub_title="[Effort 0] $i · $sub_name"
143
+ effort_title_lint "$sub_title" \
144
+ || { echo "effort_new: fix sub title #$i and retry: $sub_name" >&2; return 1; }
145
+ done
146
+
147
+ # Compose the four-section body + an optional ## Relations chain from --depends-on.
148
+ local relations="" d
149
+ if [ -n "$depends_on" ]; then
150
+ relations="$(printf '\n\n## Relations\n')"
151
+ for d in $(printf '%s' "$depends_on" | tr ',' ' '); do
152
+ d="${d#\#}"; [ -n "$d" ] && relations="$relations$(printf -- '- Depends on #%s\n' "$d")"
153
+ done
154
+ fi
155
+ local body; body="$(_eff_compose_body "$goal" "$scope" "$for_agents" "$verification" "$relations")"
156
+
157
+ # Label set: ctx (session weight from the sub count) + kind + priority + optional role + optional flow.
158
+ local subcount=$#; [ "$subcount" -ge 1 ] || subcount=1
159
+ local ctx="ctx:S"
160
+ command -v effort_ctx_bucket >/dev/null 2>&1 && ctx="$(effort_ctx_bucket 1 "$subcount")"
161
+ local labels="$ctx,kind:task,priority:$priority"
162
+ [ -n "$role" ] && labels="$labels,role:$role"
163
+ [ -n "$flow" ] && labels="$labels,flow:$(printf '%s' "$flow" | tr '[:upper:]' '[:lower:]')"
164
+ if [ -n "$par" ]; then
165
+ # par:* is a kit-defined label; ensure it exists so `gh issue create --label` doesn't fail.
166
+ gh label create "par:$par" --repo "$repo" --color c5def5 \
167
+ --description "effort parallelism hint" >/dev/null 2>&1 || true
168
+ labels="$labels,par:$par"
169
+ fi
170
+
171
+ local url num slug
172
+ url="$(gh issue create --repo "$repo" --title "[Effort] · ${flow_tag}${name}" --body "$body" \
173
+ --label "$labels" ${milestone:+--milestone "$milestone"})" \
50
174
  || { echo "effort_new: failed to create the parent issue" >&2; return 1; }
51
175
  num="${url##*/}"
52
- gh issue edit "$num" --repo "$repo" --title "[Effort] $num · $name" >/dev/null 2>&1
53
- echo " ✓ effort #$num · $name" >&2
176
+ gh issue edit "$num" --repo "$repo" --title "[Effort] $num · ${flow_tag}${name}" >/dev/null 2>&1
177
+ # The human handle (#93): explicit --slug if given, else derived from the title (number/flow peeled).
178
+ if [ -n "$explicit_slug" ]; then slug="$(_eff_slug "$explicit_slug")"
179
+ else slug="$(_eff_title_slug "[Effort] $num · ${flow_tag}${name}")"; fi
180
+ if [ -n "$slug" ]; then
181
+ gh label create "slug:$slug" --repo "$repo" --color ededed \
182
+ --description "effort slug handle" >/dev/null 2>&1 || true # idempotent: ok if it exists
183
+ gh issue edit "$num" --repo "$repo" --add-label "slug:$slug" >/dev/null 2>&1 || true
184
+ fi
185
+ echo " ✓ effort $(effort_display "$num" "$slug") · ${flow_tag}${name}" >&2
186
+
187
+ # Native dependency edges (the visible board chain) — guarded on the helper being available.
188
+ if [ -n "$depends_on" ] && command -v effort_set_blocked_by >/dev/null 2>&1; then
189
+ for d in $(printf '%s' "$depends_on" | tr ',' ' '); do
190
+ d="${d#\#}"; [ -n "$d" ] && { effort_set_blocked_by "$num" "$d" || true; }
191
+ done
192
+ fi
193
+
194
+ # Board: add the parent (guarded — no-op when Projects v2 is off / helpers not loaded).
195
+ _eff_board_add "$num" "$role" || true
54
196
 
55
- local i=0 sub child
56
- for sub in "$@"; do
197
+ # Create each sub-issue (titles already linted), native-link it, add it to the board.
198
+ local sub_desc child child_num
199
+ i=0
200
+ for spec in "$@"; do
57
201
  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
202
+ sub_name="${spec%% :: *}"
203
+ sub_desc="${spec#* :: }"; [ "$sub_desc" = "$spec" ] && sub_desc=""
204
+ sub_title="[Effort $num] $i · $sub_name"
205
+ local sub_labels="kind:task,priority:$priority"
206
+ [ -n "$role" ] && sub_labels="$sub_labels,role:$role"
207
+ child="$(gh issue create --repo "$repo" --title "$sub_title" \
208
+ --body "$(printf '%s\n\nSub-issue of #%s (effort).' "$sub_desc" "$num")" \
209
+ --label "$sub_labels" ${milestone:+--milestone "$milestone"})" || continue
210
+ child_num="${child##*/}"
211
+ effort_link_sub "$num" "$child_num" || true
212
+ _eff_board_add "$child_num" "$role" || true
213
+ echo " ✓ sub #$child_num · $sub_name" >&2
60
214
  done
61
215
  printf '%s\n' "$num"
62
216
  }
63
217
 
64
- # effort_start <N> [<slug>] — create the effort/<N> integration branch + its worktree from the base.
218
+ # _eo_source_wt — lazily source the worktree mechanic (worktree-start.sh) so effort_start gets the
219
+ # SAME full worktree setup as `cckit start`: wt_bootstrap (env-file copy + per-worktree dev port +
220
+ # dependency install) and the _wt_session_owns collision guard. bin/cckit's `effort` verb does not
221
+ # load it, so effort-ops brings it in on demand (#119). No-op if already loaded.
222
+ _eo_source_wt() {
223
+ command -v wt_bootstrap >/dev/null 2>&1 && return 0
224
+ local d; d="$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" && pwd)"
225
+ # shellcheck source=/dev/null
226
+ [ -f "$d/worktree-start.sh" ] && . "$d/worktree-start.sh"
227
+ }
228
+
229
+ # effort_start <slug|N> [<slug>] — create the effort/<N> integration branch + its worktree from base,
230
+ # with the full `cckit start` worktree setup (env copy, per-worktree dev port, dependency install —
231
+ # opt out with KIT_WT_INSTALL=0) and a live-session collision guard.
65
232
  effort_start() {
66
233
  _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; }
234
+ local raw="${1:-}" slug_override="${2:-}" num repo base root title slug branch wt
235
+ [ -n "$raw" ] || { echo "effort_start: <slug|effort issue #> required" >&2; return 1; }
236
+ num="$(effort_slug_resolve "$raw")" || { echo "effort_start: could not resolve '$raw' to an effort" >&2; return 1; }
69
237
  repo="$(_eff_repo)"; base="$(_eff_base)"
70
238
  root="$(git worktree list --porcelain 2>/dev/null | awk '/^worktree /{print $2; exit}')"
71
239
  [ -n "$root" ] || { echo "effort_start: not in a git repo" >&2; return 1; }
72
240
 
73
- if [ -n "$slug_override" ]; then slug="$slug_override"
241
+ if [ -n "$slug_override" ]; then slug="$(_eff_slug "$slug_override")"
74
242
  else
75
243
  title="$(gh issue view "$num" --repo "$repo" --json title -q .title 2>/dev/null)"
76
- slug="$(_eff_slug "${title:-effort}")"; [ -n "$slug" ] || slug="effort"
244
+ slug="$(_eff_title_slug "${title:-effort}")"; [ -n "$slug" ] || slug="effort"
245
+ fi
246
+ # Worktree dir follows the kind+N-slug convention (branch-naming.md) so kit-gc's issue-open
247
+ # protection recognizes it by DIRECTORY name too — matching the kit-effort-start skill (#119).
248
+ branch="effort/$num-$slug"; wt="$root/.claude/worktrees/effort+$num-$slug"
249
+
250
+ _eo_source_wt
251
+
252
+ # Session-collision precheck: never disturb a worktree a LIVE session is sitting in (its work may
253
+ # be uncommitted). Guarded on the helper being available.
254
+ if [ -d "$wt" ] && command -v _wt_session_owns >/dev/null 2>&1 && _wt_session_owns "$root" "$wt"; then
255
+ echo "effort_start: a live session owns $wt — refusing to disturb it" >&2; return 1
77
256
  fi
78
- branch="effort/$num-$slug"; wt="$root/.claude/worktrees/effort-$num"
79
257
 
80
258
  git -C "$root" fetch origin "$base" --quiet 2>/dev/null || true
81
259
  if git -C "$root" show-ref --verify --quiet "refs/heads/$branch"; then
@@ -85,48 +263,135 @@ effort_start() {
85
263
  git -C "$root" worktree add -b "$branch" "$wt" "$from" >/dev/null 2>&1 \
86
264
  || { echo "effort_start: failed to create worktree for $branch" >&2; return 1; }
87
265
  fi
88
- echo " ✓ effort #$num → $branch (worktree: $wt)" >&2
266
+
267
+ # Bootstrap the worktree for local dev: copy gitignored env, assign a per-worktree dev port, and
268
+ # install deps (KIT_WT_INSTALL=0 opts out). Best-effort — a hiccup never fails the start.
269
+ command -v wt_bootstrap >/dev/null 2>&1 && wt_bootstrap "$root" "$wt" "$num" || true
270
+
271
+ echo " ✓ effort $(effort_display "$num" "$slug") → $branch (worktree: $wt)" >&2
89
272
  printf '%s|%s|%s\n' "$wt" "$branch" "$num"
90
273
  }
91
274
 
92
- # effort_pr [<N>] — open the single PR effort/<N> → base. N defaults to the current effort branch.
275
+ # effort_pr [<slug|N>] — open the single PR effort/<N> → base. Defaults to the current effort branch.
93
276
  effort_pr() {
94
277
  _eff_need gh || return 1
95
- local num="${1:-}" repo base branch title name
278
+ local raw="${1:-}" num repo base branch title name
96
279
  repo="$(_eff_repo)"; base="$(_eff_base)"
97
280
  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; }
281
+ if [ -n "$raw" ]; then
282
+ num="$(effort_slug_resolve "$raw")" || { echo "effort_pr: could not resolve '$raw' to an effort" >&2; return 1; }
283
+ else
284
+ num="$(effort_branch_num "$branch")"
285
+ fi
286
+ [ -n "$num" ] || { echo "effort_pr: not on an effort/<N>-… branch and no <slug|N> given" >&2; return 1; }
100
287
  case "$branch" in effort/"$num"-*) : ;; *) echo "effort_pr: current branch ($branch) is not effort/$num-…" >&2; return 1 ;; esac
101
288
 
102
289
  git push -u origin "$branch" >/dev/null 2>&1 || true
103
290
  title="$(gh issue view "$num" --repo "$repo" --json title -q .title 2>/dev/null)"
104
291
  name="$(printf '%s' "$title" | sed -E 's/^\[Effort\] [0-9]+ · ?//')"
292
+ # ONE shared composer (effort.sh) so the verb + the kit-effort-pr skill title identically, then the
293
+ # mandatory-[#N] check before we ever call gh — refuse rather than open an id-less PR (#121).
294
+ local pr_title; pr_title="$(effort_pr_title "$num" "${name:-effort}")"
295
+ effort_pr_title_check "$pr_title" "$num" || { echo "effort_pr: refusing to open a PR without the [#$num] effort id" >&2; return 1; }
105
296
  gh pr create --repo "$repo" --base "$base" --head "$branch" \
106
- --title "[Effort] $num · ${name:-effort}" \
297
+ --title "$pr_title" \
107
298
  --body "$(printf 'Closes the #%s effort.\n\n## For agents\nSee #%s for the goal, scope, and entry points.\n' "$num" "$num")"
108
299
  }
109
300
 
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.
301
+ # _eo_source_metrics — lazily source effort-metrics.sh so effort_close can call the shipped
302
+ # capture/judge/sync functions even when only effort-ops is loaded (bin/cckit sources it for the
303
+ # effort verb; this makes the composition robust + testable). No-op if already loaded.
304
+ _eo_source_metrics() {
305
+ command -v capture_effort_metrics >/dev/null 2>&1 && return 0
306
+ local d; d="$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" && pwd)"
307
+ # shellcheck source=/dev/null
308
+ [ -f "$d/effort-metrics.sh" ] && . "$d/effort-metrics.sh"
309
+ }
310
+
311
+ # _eo_knowledge_ingest <num> <trace_dir> <root> — optional post-close knowledge-ingest hook. Runs a
312
+ # project-configured command (github/effort.knowledgeIngestHook, or KIT_EFFORT_KNOWLEDGE_HOOK) with
313
+ # the effort number + trace dir, so a project can fold the closed effort's work record into its
314
+ # knowledge base. Config-gated: a NO-OP when unset or the hook file is missing/not executable — the
315
+ # kit ships no default hook. Best-effort — a hook failure never fails the close.
316
+ _eo_knowledge_ingest() {
317
+ local num="$1" trace="$2" root="$3" hook="" cfg
318
+ hook="${KIT_EFFORT_KNOWLEDGE_HOOK:-}"
319
+ if [ -z "$hook" ]; then
320
+ cfg="${KIT_CONFIG:-}"; [ -n "$cfg" ] || { [ -f "$root/cckit.config.json" ] && cfg="$root/cckit.config.json" || cfg="$root/.claude/kit.config.json"; }
321
+ [ -f "$cfg" ] && command -v jq >/dev/null 2>&1 \
322
+ && hook="$(jq -r '.effort.knowledgeIngestHook // empty' "$cfg" 2>/dev/null)"
323
+ fi
324
+ [ -n "$hook" ] || return 0
325
+ case "$hook" in /*) : ;; *) hook="$root/$hook" ;; esac # resolve a relative hook against the root
326
+ [ -x "$hook" ] || { echo "effort_close: knowledge-ingest hook '$hook' not executable — skipping" >&2; return 0; }
327
+ echo " → knowledge-ingest hook: $hook $num" >&2
328
+ "$hook" "$num" "$trace" >/dev/null 2>&1 || echo "effort_close: knowledge-ingest hook failed (non-fatal)" >&2
329
+ }
330
+
331
+ # effort_close <N> — the single close op. Snapshot per-sub diffs + capture metrics BEFORE the squash
332
+ # (the squash erases the per-sub history), REFUSE to squash if no work trace was captured (KIT_FORCE=1
333
+ # overrides), squash-merge, judge + sync the metrics, close parent + subs, GC the worktree/branch, and
334
+ # run the optional knowledge-ingest hook. Destructive: it merges, closes, and prunes.
112
335
  effort_close() {
113
336
  _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; }
337
+ local raw="${1:-}" num repo base branch root self_wt trace_dir
338
+ [ -n "$raw" ] || { echo "effort_close: <slug|effort issue #> required" >&2; return 1; }
339
+ num="$(effort_slug_resolve "$raw")" || { echo "effort_close: could not resolve '$raw' to an effort" >&2; return 1; }
116
340
  repo="$(_eff_repo)"; base="$(_eff_base)"
117
341
  branch="$(git rev-parse --abbrev-ref HEAD 2>/dev/null)"
118
342
  case "$branch" in effort/"$num"-*) : ;; *) echo "effort_close: run from the effort/$num-… branch" >&2; return 1 ;; esac
343
+ root="$(git worktree list --porcelain 2>/dev/null | awk '/^worktree /{print $2; exit}')"
344
+ self_wt="$(git rev-parse --show-toplevel 2>/dev/null)"
345
+ _eo_source_metrics
346
+
347
+ # (a) snapshot the per-sub-issue diffs while the unsquashed history still exists (echoes the trace dir).
348
+ trace_dir="$(effort_snapshot_subs "$num" "origin/$base" 2>/dev/null)"
349
+
350
+ # (a2) refuse-squash-without-trace backstop: the squash is irreversible and collapses the per-sub
351
+ # commits that ARE the work record. If nothing was snapshotted, refuse — unless KIT_FORCE=1.
352
+ if [ -z "$trace_dir" ] || ! ls "$trace_dir"/*.diff >/dev/null 2>&1; then
353
+ if [ "${KIT_FORCE:-0}" = "1" ]; then
354
+ echo "effort_close: no per-sub work trace captured — proceeding anyway (KIT_FORCE=1)" >&2
355
+ else
356
+ 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
357
+ return 1
358
+ fi
359
+ fi
119
360
 
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.
361
+ # (b) capture effort metrics PRE-squash (needs the live-branch diff + commit signals).
362
+ command -v capture_effort_metrics >/dev/null 2>&1 && capture_effort_metrics "$num" "origin/$base" || true
363
+
364
+ # (c) squash-merge the effort PR.
123
365
  gh pr merge "$branch" --repo "$repo" --squash --delete-branch >/dev/null 2>&1 \
124
366
  || { echo "effort_close: could not squash-merge the PR for $branch (open? mergeable?)" >&2; return 1; }
125
367
  echo " ✓ merged $branch" >&2
126
- # (c) close every native sub-issue, then the parent.
368
+
369
+ # (d) judge + sync the metrics (judge reads the durable trace dir; sync no-ops when the engine is off).
370
+ command -v judge_effort_metrics >/dev/null 2>&1 && judge_effort_metrics "$num" "origin/$base" || true
371
+ command -v sync_effort_metrics >/dev/null 2>&1 && sync_effort_metrics "$num" || true
372
+
373
+ # (e) close every native sub-issue, then the parent.
127
374
  local sub
128
375
  for sub in $(gh api "repos/$repo/issues/$num/sub_issues" --jq '.[].number' 2>/dev/null); do
129
376
  gh issue close "$sub" --repo "$repo" --reason completed >/dev/null 2>&1 && echo " ✓ closed sub #$sub" >&2
130
377
  done
131
378
  gh issue close "$num" --repo "$repo" --reason completed >/dev/null 2>&1 && echo " ✓ closed effort #$num" >&2
379
+
380
+ # (f) GC: switch the main checkout to base, remove the effort worktree, delete the local branch,
381
+ # prune. The remote branch was deleted by --delete-branch above. All via `git -C "$root"` so the
382
+ # caller's cwd is never moved. Best-effort — a GC hiccup never fails the (already-landed) close.
383
+ if [ -n "$root" ]; then
384
+ git -C "$root" checkout "$base" >/dev/null 2>&1 || true
385
+ git -C "$root" pull origin "$base" --quiet >/dev/null 2>&1 || true
386
+ if [ -n "$self_wt" ] && [ "$self_wt" != "$root" ]; then
387
+ case "$self_wt" in "$root"/.claude/worktrees/*)
388
+ git -C "$root" worktree remove "$self_wt" --force >/dev/null 2>&1 && echo " ✓ removed worktree $self_wt" >&2 ;;
389
+ esac
390
+ fi
391
+ git -C "$root" branch -D "$branch" >/dev/null 2>&1 && echo " ✓ deleted local branch $branch" >&2
392
+ git -C "$root" worktree prune >/dev/null 2>&1 || true
393
+ fi
394
+
395
+ # (g) optional, config-gated knowledge-ingest hook (no-op when absent).
396
+ _eo_knowledge_ingest "$num" "${trace_dir:-}" "$root"
132
397
  }
@@ -0,0 +1,128 @@
1
+ #!/usr/bin/env bash
2
+ # shellcheck shell=bash
3
+ # effort-parity-test.sh — effort #98: the verb (`cckit effort new`) and the skill (/kit-effort-new)
4
+ # create structurally IDENTICAL efforts because both call the one shared core `effort_new`. This test
5
+ # drives that core with the full skill-shaped inputs and asserts the parity contract:
6
+ # - the four body sections are FILLED (no `<!--` template placeholder left)
7
+ # - the ctx/kind/priority/role/flow label set is applied to the parent
8
+ # - sub-issues carry kind/priority/role labels and are native-linked
9
+ # - every sub title is linted UP FRONT (a bad sub name aborts before anything is created)
10
+ # Hermetic: stubs gh (no network/auth). Run: bash scripts/lib/effort-parity-test.sh
11
+ set -u
12
+ ROOT="$(cd "$(dirname "$0")/../.." && pwd)"
13
+ LIB="$ROOT/scripts/lib"
14
+ fail=0
15
+ t() { if [ "$2" = "$3" ]; then echo "ok: $1"; else echo "FAIL: $1 -> got '[$2]' want '[$3]'"; fail=1; fi; }
16
+ tc() { if grep -qE "$2" "$1"; then echo "ok: $3"; else echo "FAIL: $3 (no /$2/ in gh log)"; fail=1; fi; }
17
+ tn() { if grep -qE "$2" "$1"; then echo "FAIL: $3 (unexpected /$2/ in gh log)"; fail=1; else echo "ok: $3"; fi; }
18
+ command -v jq >/dev/null 2>&1 || { echo "effort-parity-test: jq required" >&2; exit 1; }
19
+
20
+ tmp="$(mktemp -d)"; trap 'rm -rf "$tmp"' EXIT
21
+ export GH_LOG="$tmp/gh.log"; export GH_N="$tmp/n"; : > "$GH_LOG"
22
+
23
+ # Stub gh: log every call as ONE physical line (newlines in the multi-line --body flattened to spaces
24
+ # so a single-line grep can see --label, which follows --body), return canned output.
25
+ stub="$tmp/bin"; mkdir -p "$stub"
26
+ cat > "$stub/gh" <<'SH'
27
+ #!/usr/bin/env bash
28
+ echo "$*" | tr '\n' ' ' >> "$GH_LOG"; echo >> "$GH_LOG"
29
+ case "$1 $2" in
30
+ "issue create") n=$(( $(cat "$GH_N" 2>/dev/null || echo 0) + 1 )); echo "$n" > "$GH_N"
31
+ echo "https://github.com/o/r/issues/$n" ;;
32
+ "issue edit") exit 0 ;;
33
+ "api "*|"api")
34
+ case "$*" in
35
+ *"--method POST"*"/sub_issues"*) exit 0 ;;
36
+ *".id"*) echo "55501" ;;
37
+ *) exit 0 ;;
38
+ esac ;;
39
+ *) exit 0 ;;
40
+ esac
41
+ SH
42
+ chmod +x "$stub/gh"
43
+ export PATH="$stub:$PATH"
44
+ export KIT_REPO="o/r" EFFORT_REPO="o/r" KIT_BASE_BRANCH="main" KIT_PROJECTS_V2="false"
45
+ # shellcheck source=/dev/null
46
+ source "$LIB/effort.sh" 2>/dev/null
47
+ # shellcheck source=/dev/null
48
+ source "$LIB/effort-metrics.sh" 2>/dev/null # effort_ctx_bucket — so ctx is sized, not the fallback
49
+ # shellcheck source=/dev/null
50
+ source "$LIB/effort-ops.sh"
51
+
52
+ # ── Full skill-shaped inputs through the shared core ─────────────────────────────────────────────
53
+ : > "$GH_LOG"
54
+ parent="$(effort_new \
55
+ --flow Core --role tech-lead --priority p2 \
56
+ --goal "Close the parity gap between the verb and the skill." \
57
+ --scope "1. share core | 2. verb fills body | 3. skill delegates" \
58
+ --for-agents "scripts/lib/effort-ops.sh and skills/kit-effort-new/SKILL.md" \
59
+ --verification "the verb and skill produce identical issues" \
60
+ "demo parity effort" "share core :: factor the logic" "fill the body :: verb wiring")"
61
+
62
+ t "core returns the parent number" "$parent" "1"
63
+ t "core creates parent + 2 subs (3 issues)" "$(grep -c 'issue create' "$GH_LOG")" "3"
64
+ t "core links 2 native sub-issues" "$(grep -c 'method POST .*sub_issues' "$GH_LOG")" "2"
65
+
66
+ # Body is FILLED — every section heading present AND the placeholder comments are gone.
67
+ tc "$GH_LOG" 'Close the parity gap between the verb' "body fills ## Goal"
68
+ tc "$GH_LOG" '1\. share core \| 2\. verb fills body' "body fills ## Scope"
69
+ tc "$GH_LOG" 'scripts/lib/effort-ops\.sh and skills' "body fills ## For agents"
70
+ tc "$GH_LOG" 'the verb and skill produce identical' "body fills ## Verification"
71
+ tn "$GH_LOG" '<!--' "no template placeholder left in a filled body"
72
+
73
+ # Label set on the parent: ctx + kind + priority + role + flow (flow lowercased).
74
+ tc "$GH_LOG" 'issue create .*--label ctx:[SMLX]+,kind:task,priority:p2,role:tech-lead,flow:core' \
75
+ "parent carries ctx/kind/priority/role/flow labels"
76
+ # Flow tag on the composed title.
77
+ tc "$GH_LOG" 'issue edit 1 .*--title \[Effort\] 1 · \[Core\] demo parity effort' \
78
+ "parent title carries the [Core] flow tag + injected number"
79
+ # Sub labels: kind/priority/role (no ctx/flow on subs — those are parent-level).
80
+ tc "$GH_LOG" 'issue create .*--title \[Effort 1\] 1 · share core.*--label kind:task,priority:p2,role:tech-lead' \
81
+ "sub #1 carries kind/priority/role labels + a proper [Effort N] M title"
82
+
83
+ # ── A bad sub title aborts the whole op BEFORE anything is created (parity contract) ─────────────
84
+ : > "$GH_LOG"; printf '0' > "$GH_N"
85
+ effort_new --role tech-lead --goal G --scope S --for-agents A --verification V \
86
+ "clean parent name" "refactor the whole wiring layer thing now" >/dev/null 2>&1 && rc=0 || rc=1
87
+ t "core rejects a bad sub title" "$rc" "1"
88
+ t "core creates nothing on a bad sub title" "$(grep -c 'issue create' "$GH_LOG")" "0"
89
+
90
+ # ── A bare verb-style call (no body flags) still yields the 4-section scaffold ───────────────────
91
+ : > "$GH_LOG"; printf '0' > "$GH_N"
92
+ effort_new "minimal effort name" >/dev/null 2>&1
93
+ tc "$GH_LOG" '## Goal' "bare call still emits ## Goal"
94
+ tc "$GH_LOG" '## Verification' "bare call still emits ## Verification"
95
+ tc "$GH_LOG" '<!--' "bare call leaves the template placeholders (nothing to fill)"
96
+
97
+ # ── #121: the ONE shared effort-PR title composer + the mandatory-[#N] check ─────────────────────
98
+ t "effort_pr_title composes [#N] name" "$(effort_pr_title 115 'adoption hardening')" "[#115] adoption hardening"
99
+ t "effort_pr_title with a role prefix" "$(effort_pr_title 115 'adoption hardening' 'Tech Lead')" "[Tech Lead] [#115] adoption hardening"
100
+ t "effort_pr_title peels an [Effort] prefix" "$(effort_pr_title 115 '[Effort] 115 · [Core] adoption hardening')" "[#115] [Core] adoption hardening"
101
+ t "effort_pr_title tolerates a #-prefixed num" "$(effort_pr_title '#42' 'x')" "[#42] x"
102
+ effort_pr_title_check "[Tech Lead] [#115] adoption hardening" 115; t "check accepts a title carrying [#N]" "$?" "0"
103
+ effort_pr_title_check "[Effort] 115 · adoption hardening" 115 2>/dev/null; t "check refuses a title lacking [#N]" "$?" "1"
104
+ effort_pr_title_check "[#7] anything" 2>/dev/null; t "check accepts any [#N] when no num given" "$?" "0"
105
+
106
+ # ── #121: --par applies a par:<value> label on the parent; bad values are rejected up front ───────
107
+ : > "$GH_LOG"; printf '0' > "$GH_N"
108
+ effort_new --flow Core --par wide "parallel wide effort" "a :: x" "b :: y" >/dev/null 2>&1
109
+ tc "$GH_LOG" 'issue create .*--label [^ ]*,par:wide' "--par wide adds a par:wide label to the parent"
110
+ tc "$GH_LOG" 'label create par:wide' "--par creates the par:wide label idempotently"
111
+ : > "$GH_LOG"; printf '0' > "$GH_N"
112
+ effort_new --par 3 "parallel three effort" >/dev/null 2>&1
113
+ tc "$GH_LOG" 'issue create .*--label [^ ]*,par:3' "--par 3 adds a par:3 label"
114
+ : > "$GH_LOG"; printf '0' > "$GH_N"
115
+ effort_new --par nonsense "bad par effort" >/dev/null 2>&1 && rc=0 || rc=1
116
+ t "--par rejects a non seq/wide/int value" "$rc" "1"
117
+ t "--par creates nothing on a bad value" "$(grep -c 'issue create' "$GH_LOG")" "0"
118
+
119
+ # ── #121: flags are position-INDEPENDENT — trailing --flow/--role no longer become junk sub-issues ─
120
+ : > "$GH_LOG"; printf '0' > "$GH_N"
121
+ effort_new "flags after title effort" "real sub :: desc" --flow Docs --role docs >/dev/null 2>&1
122
+ t "trailing flags do NOT create junk subs (parent + 1 real sub)" "$(grep -c 'issue create' "$GH_LOG")" "2"
123
+ tc "$GH_LOG" 'issue create .*--label [^ ]*,flow:docs' "trailing --flow is honored (flow:docs label)"
124
+ tc "$GH_LOG" 'issue create .*--title \[Effort 1\] 1 · real sub' "the one real sub is created from the positional"
125
+ tn "$GH_LOG" 'issue create .*--title \[Effort 1\] [0-9]+ · --flow' "no '--flow' junk sub-issue created"
126
+
127
+ [ "$fail" -eq 0 ] && echo "ALL OK (effort-parity)" || echo "effort-parity: FAILURES"
128
+ exit "$fail"