@jeiemgi/cckit 0.1.8 → 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 (68) 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 +77 -12
  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/copilot-loop-test.sh +162 -0
  12. package/scripts/init.sh +22 -4
  13. package/scripts/kit-doctor.sh +185 -7
  14. package/scripts/kit-version-check-test.sh +36 -0
  15. package/scripts/kit-version-check.sh +19 -4
  16. package/scripts/knowledge-lint.sh +4 -1
  17. package/scripts/lib/board-view-test.sh +54 -0
  18. package/scripts/lib/board-view.sh +80 -0
  19. package/scripts/lib/captain-test.sh +76 -0
  20. package/scripts/lib/captain.sh +268 -0
  21. package/scripts/lib/config-path-test.sh +47 -0
  22. package/scripts/lib/config-path.sh +29 -0
  23. package/scripts/lib/copilot-test.sh +30 -0
  24. package/scripts/lib/copilot.sh +101 -0
  25. package/scripts/lib/effort-metrics-test.sh +57 -0
  26. package/scripts/lib/effort-metrics.sh +19 -5
  27. package/scripts/lib/effort-ops-test.sh +51 -2
  28. package/scripts/lib/effort-ops.sh +314 -49
  29. package/scripts/lib/effort-parity-test.sh +128 -0
  30. package/scripts/lib/effort-slug-test.sh +87 -0
  31. package/scripts/lib/effort-slug.sh +104 -0
  32. package/scripts/lib/effort.sh +34 -0
  33. package/scripts/lib/gh-project-test.sh +95 -0
  34. package/scripts/lib/gh-project.sh +22 -7
  35. package/scripts/lib/git-remote-test.sh +57 -0
  36. package/scripts/lib/git-remote.sh +21 -0
  37. package/scripts/lib/kit-config-test.sh +37 -0
  38. package/scripts/lib/kit-config.sh +33 -13
  39. package/scripts/lib/kit-events.sh +5 -3
  40. package/scripts/lib/kit-gc-test.sh +88 -0
  41. package/scripts/lib/kit-gc.sh +136 -19
  42. package/scripts/lib/kit-local.sh +8 -1
  43. package/scripts/lib/next.sh +75 -0
  44. package/scripts/lib/plan-machine-test.sh +72 -0
  45. package/scripts/lib/plan-machine.sh +260 -0
  46. package/scripts/lib/plan-next-test.sh +87 -0
  47. package/scripts/lib/plan-next.sh +212 -0
  48. package/scripts/lib/project-scan.sh +7 -1
  49. package/scripts/lib/render-test.sh +40 -0
  50. package/scripts/lib/render.sh +57 -0
  51. package/scripts/lib/worktree-start.sh +12 -3
  52. package/scripts/lib/zsh-safety-test.sh +73 -0
  53. package/scripts/portable-test.sh +62 -20
  54. package/scripts/setup-labels.sh +13 -2
  55. package/scripts/showcase.sh +13 -4
  56. package/scripts/status-test.sh +63 -0
  57. package/scripts/status.sh +12 -4
  58. package/scripts/task-sync.sh +79 -10
  59. package/skills/kit-autopilot/SKILL.md +5 -0
  60. package/skills/kit-docs-writer/SKILL.md +135 -0
  61. package/skills/kit-effort-new/SKILL.md +39 -111
  62. package/skills/kit-effort-pr/SKILL.md +6 -2
  63. package/skills/kit-next/SKILL.md +58 -0
  64. package/skills/kit-plan-next/SKILL.md +82 -0
  65. package/templates/hooks/mempal_session_start.sh.tmpl +36 -2
  66. package/templates/rules/effort-model.md +26 -6
  67. package/templates/rules/mempalace.md +1 -0
  68. package/templates/rules/plan-next.md +58 -0
@@ -0,0 +1,57 @@
1
+ #!/usr/bin/env bash
2
+ # shellcheck shell=bash
3
+ # effort-metrics-test.sh — covers _em_token_sum's branch ∪ time-window attribution (#124). Token
4
+ # actuals must count sessions that match the effort BRANCH as well as sessions that fall inside the
5
+ # effort's build WINDOW [start,end] — the window recovers sessions logged before the branch field
6
+ # existed or from a detached/worktree checkout. Hermetic: a throwaway repo + a stubbed usage log +
7
+ # stubbed transcripts under a temp HOME. Run: bash scripts/lib/effort-metrics-test.sh
8
+ set -u
9
+ ROOT="$(cd "$(dirname "$0")/../.." && pwd)"
10
+ LIB="$ROOT/scripts/lib"
11
+ fail=0
12
+ t() { if [ "$2" = "$3" ]; then echo "ok: $1"; else echo "FAIL: $1 -> got '[$2]' want '[$3]'"; fi; [ "$2" = "$3" ] || fail=1; }
13
+ command -v jq >/dev/null 2>&1 || { echo "effort-metrics-test: jq required — skipping"; exit 0; }
14
+ command -v git >/dev/null 2>&1 || { echo "effort-metrics-test: git required" >&2; exit 1; }
15
+
16
+ tmp="$(mktemp -d)"; trap 'rm -rf "$tmp"' EXIT
17
+ export HOME="$tmp/home"; mkdir -p "$HOME/.claude/projects"
18
+
19
+ # A repo so git-common-dir resolves; kit-usage.jsonl lives under it.
20
+ cd "$tmp"; git init -q repo; cd repo; git config user.email t@t; git config user.name t
21
+ git commit -q --allow-empty -m init
22
+ GCD="$(git rev-parse --git-common-dir)"; case "$GCD" in /*) : ;; *) GCD="$PWD/$GCD" ;; esac
23
+
24
+ # Usage log: A matches the branch; B matches the window (different branch, ts inside); C matches
25
+ # neither (different branch, ts outside the window).
26
+ START=1000000000; END=1000000900 # a 900s window
27
+ {
28
+ printf '{"session":"AAA","branch":"effort/5-x","ts":"2001-09-09T01:46:20Z"}\n' # branch match (ts irrelevant)
29
+ printf '{"session":"BBB","branch":"other/9-y","ts":"2001-09-09T01:55:00Z"}\n' # ~1000000500 — inside window
30
+ printf '{"session":"CCC","branch":"other/9-z","ts":"2020-01-01T00:00:00Z"}\n' # far outside window
31
+ } > "$GCD/kit-usage.jsonl"
32
+
33
+ # Transcripts: A=100 in, B=50 in, C=999 in. Only A+B should be counted.
34
+ printf '{"message":{"usage":{"input_tokens":100,"output_tokens":10,"cache_read_input_tokens":0,"cache_creation_input_tokens":0}}}\n' > "$HOME/.claude/projects/AAA.jsonl"
35
+ printf '{"message":{"usage":{"input_tokens":50,"output_tokens":5,"cache_read_input_tokens":0,"cache_creation_input_tokens":0}}}\n' > "$HOME/.claude/projects/BBB.jsonl"
36
+ printf '{"message":{"usage":{"input_tokens":999,"output_tokens":99,"cache_read_input_tokens":0,"cache_creation_input_tokens":0}}}\n' > "$HOME/.claude/projects/CCC.jsonl"
37
+
38
+ # shellcheck source=/dev/null
39
+ source "$LIB/effort-metrics.sh"
40
+
41
+ # branch only: counts A (100/10); window given but branch alone would miss B if window absent.
42
+ read -r i o _ _ <<< "$(_em_token_sum 'effort/5-x' 0 0)"
43
+ t "branch-only counts the branch session" "$i $o" "100 10"
44
+
45
+ # branch ∪ window: counts A (branch) + B (window) = 150 in / 15 out; C excluded (outside window).
46
+ read -r i o _ _ <<< "$(_em_token_sum 'effort/5-x' "$START" "$END")"
47
+ t "branch ∪ window counts branch + window sessions" "$i $o" "150 15"
48
+
49
+ # window only (no branch): counts just B (inside window), never C.
50
+ read -r i o _ _ <<< "$(_em_token_sum '' "$START" "$END")"
51
+ t "window-only counts the in-window session" "$i $o" "50 5"
52
+
53
+ # no branch, no window: nothing attributable.
54
+ t "no branch + no window sums to zero" "$(_em_token_sum '' 0 0)" "0 0 0 0"
55
+
56
+ [ "$fail" -eq 0 ] && echo "ALL OK (effort-metrics)" || echo "effort-metrics: FAILURES"
57
+ exit "$fail"
@@ -105,12 +105,26 @@ effort_ctx_bucket() {
105
105
  # ~/.claude/projects/*/. Echoes "in out cache_read cache_write" (0s when unmappable). Going-forward
106
106
  # only — the usage log is empty for the past (backtrace left tokens null, by design).
107
107
  _em_token_sum() {
108
- local branch="$1" gcd ulog sids sid tx tin=0 tout=0 tcr=0 tcw=0 sums
108
+ # <branch> [start-epoch] [end-epoch] — attribute usage sessions to the effort by branch UNION a
109
+ # time window (#124). Branch alone misses sessions logged before the branch field was recorded or
110
+ # from a detached/worktree checkout; the [start,end] window (the effort's build span) recovers them.
111
+ local branch="$1" start="${2:-0}" end="${3:-0}" gcd ulog sids sid tx tin=0 tout=0 tcr=0 tcw=0 sums
109
112
  local IFS=' ' # force space-split for `set --` (ambient IFS may carry a NUL — see ifs landmine)
113
+ [[ "$start" =~ ^[0-9]+$ ]] || start=0; [[ "$end" =~ ^[0-9]+$ ]] || end=0
110
114
  gcd="$(git rev-parse --git-common-dir 2>/dev/null)" || { echo "0 0 0 0"; return 0; }
111
115
  ulog="$gcd/kit-usage.jsonl"
112
- [[ -f "$ulog" && -n "$branch" ]] || { echo "0 0 0 0"; return 0; }
113
- sids="$(jq -r --arg b "$branch" 'select(.branch==$b and .session!="")|.session' "$ulog" 2>/dev/null | sort -u)"
116
+ [[ -f "$ulog" ]] || { echo "0 0 0 0"; return 0; }
117
+ # A session counts when it matches the branch OR falls inside the [start,end] window (when given).
118
+ # `try … catch 0` keeps a malformed .ts row from aborting the whole filter.
119
+ sids="$(jq -r --arg b "$branch" --argjson s "$start" --argjson e "$end" '
120
+ select(.session != "")
121
+ | select(
122
+ ($b != "" and .branch == $b)
123
+ or ($s > 0 and $e > 0
124
+ and (try (.ts | fromdateiso8601) catch 0) >= $s
125
+ and (try (.ts | fromdateiso8601) catch 0) <= $e)
126
+ )
127
+ | .session' "$ulog" 2>/dev/null | sort -u)"
114
128
  [[ -n "$sids" ]] || { echo "0 0 0 0"; return 0; }
115
129
  while IFS= read -r sid; do
116
130
  [[ -n "$sid" ]] || continue
@@ -156,8 +170,8 @@ capture_effort_metrics() {
156
170
  echo "effort-metrics: WARN #$num — capture on '$branch' with an empty diff; run it PRE-close (the effort branch is gone). Recording zeros." >&2
157
171
  fi
158
172
 
159
- # token/cost actuals (#807) — going-forward only.
160
- toks="$(_em_token_sum "$branch")"; read -r tin tout tcr tcw <<< "$toks"
173
+ # token/cost actuals (#807) — attribute by branch UNION the effort's build window [start,now] (#124).
174
+ toks="$(_em_token_sum "$branch" "${start:-0}" "${now:-0}")"; read -r tin tout tcr tcw <<< "$toks"
161
175
  tin=${tin:-0}; tout=${tout:-0}; tcr=${tcr:-0}; tcw=${tcw:-0}
162
176
  if (( tin + tout + tcr + tcw > 0 )); then
163
177
  tokens_real=$(( tin + tout + tcr + tcw ))
@@ -38,6 +38,7 @@ SH
38
38
  chmod +x "$stub/gh"
39
39
  export PATH="$stub:$PATH"
40
40
  export KIT_REPO="o/r" EFFORT_REPO="o/r" KIT_BASE_BRANCH="main"
41
+ export KIT_WT_INSTALL=0 # #119: skip the dependency install during the hermetic worktree bootstrap
41
42
  # shellcheck source=/dev/null
42
43
  source "$LIB/effort.sh" 2>/dev/null
43
44
  # shellcheck source=/dev/null
@@ -63,21 +64,69 @@ t "effort_new creates nothing on a bad title" "$(grep -c 'issue create' "$G
63
64
  && git push -q origin HEAD:main )
64
65
  cd "$tmp/work"
65
66
 
67
+ # #119: a gitignored local env in the root must be copied into the fresh worktree by wt_bootstrap.
68
+ printf 'SECRET=from-root\n' > "$tmp/work/.env.local"
69
+
66
70
  start_out="$(effort_start 99 demo 2>/dev/null)"
67
71
  t "effort_start echoes wt|branch|num" "${start_out##*|}" "99"
68
72
  t "effort_start created the branch" "$(git show-ref --verify --quiet refs/heads/effort/99-demo && echo yes)" "yes"
73
+ # #119: worktree dir follows the kind+N-slug convention (gc-recognizable), not the old effort-N form.
74
+ # (compare the trailing path segments — mktemp's /var may resolve to /private/var on macOS)
75
+ t "effort_start worktree dir is effort+N-slug" \
76
+ "$(printf '%s' "${start_out%%|*}" | sed -E 's#^.*/(\.claude/worktrees/.*)$#\1#')" \
77
+ ".claude/worktrees/effort+99-demo"
78
+ t "effort_start bootstrapped the worktree (.env.local copied)" \
79
+ "$(cat "$tmp/work/.claude/worktrees/effort+99-demo/.env.local" 2>/dev/null)" "SECRET=from-root"
69
80
 
70
81
  # move onto the effort branch (its worktree) for pr/close
71
- cd "$tmp/work/.claude/worktrees/effort-99"
82
+ cd "$tmp/work/.claude/worktrees/effort+99-demo"
72
83
  : > "$GH_LOG"
73
84
  effort_pr 99 >/dev/null 2>&1
74
85
  tc "$GH_LOG" 'pr create .*--base main --head effort/99-demo' "effort_pr opens effort/99 → main"
75
86
 
87
+ # ── effort_close #120: refuse-squash-without-trace backstop ────────────────────────────────────
88
+ # With NO commits on the effort branch, effort_snapshot_subs captures no trace → close must refuse
89
+ # (the squash would erase per-sub history), and must NOT merge.
90
+ : > "$GH_LOG"
91
+ close_out="$(effort_close 99 2>&1)"; rc=$?
92
+ t "effort_close refuses without a trace (rc 1)" "$rc" "1"
93
+ case "$close_out" in *"refusing to squash"*) echo "ok: refuse message explains itself" ;; *) echo "FAIL: refuse message: $close_out"; fail=1 ;; esac
94
+ t "effort_close did NOT merge without a trace" "$(grep -c 'pr merge' "$GH_LOG")" "0"
95
+
96
+ # ── effort_close #120: happy path — commit present → trace captured → full close ────────────────
97
+ # A real commit on the effort branch gives snapshot something to trace; close then proceeds through
98
+ # capture (pre-squash) → merge → judge/sync → close subs+parent → worktree GC.
99
+ echo "work" > file.txt
100
+ git -c user.email=t@t -c user.name=t add file.txt
101
+ git -c user.email=t@t -c user.name=t commit -q -m "feat: do the thing (#101)"
76
102
  : > "$GH_LOG"
77
- effort_close 99 >/dev/null 2>&1
103
+ close_out="$(effort_close 99 2>&1)"; rc=$?
104
+ cd "$tmp/work" # our cwd (the effort worktree) is GC'd by the close — step to the main checkout
105
+ t "effort_close succeeds with a trace (rc 0)" "$rc" "0"
78
106
  tc "$GH_LOG" 'pr merge effort/99-demo .*--squash' "effort_close squash-merges the PR"
79
107
  tc "$GH_LOG" 'issue close 101' "effort_close closes sub #101"
80
108
  tc "$GH_LOG" 'issue close 99 ' "effort_close closes the parent"
109
+ case "$close_out" in *"metrics:"*) echo "ok: capture_effort_metrics composed into close" ;; *) echo "FAIL: no metrics capture in close"; fail=1 ;; esac
110
+ t "effort_close GC removed the effort worktree" \
111
+ "$(git -C "$tmp/work" worktree list --porcelain | grep -c 'effort+99-demo')" "0"
112
+ t "effort_close GC deleted the local branch" \
113
+ "$(git -C "$tmp/work" show-ref --verify --quiet refs/heads/effort/99-demo && echo yes || echo no)" "no"
114
+
115
+ # ── effort_close #120: KIT_FORCE=1 override + config-gated knowledge-ingest hook ───────────────
116
+ # A second effort with no commits: close refuses by default, but KIT_FORCE=1 proceeds to merge. A
117
+ # configured knowledge-ingest hook runs post-close with the effort number (no-op when unset).
118
+ cat > "$stub/khook" <<'SH'
119
+ #!/usr/bin/env bash
120
+ printf 'ingested %s\n' "$1" > "$KHOOK_MARKER"
121
+ SH
122
+ chmod +x "$stub/khook"
123
+ start_out="$(effort_start 88 forced 2>/dev/null)"
124
+ cd "$tmp/work/.claude/worktrees/effort+88-forced"
125
+ : > "$GH_LOG"
126
+ KHOOK_MARKER="$tmp/khook.out" KIT_EFFORT_KNOWLEDGE_HOOK="$stub/khook" KIT_FORCE=1 effort_close 88 >/dev/null 2>&1
127
+ cd "$tmp/work"
128
+ tc "$GH_LOG" 'pr merge effort/88-forced .*--squash' "KIT_FORCE=1 close merges despite no trace"
129
+ t "knowledge-ingest hook ran with the effort number" "$(cat "$tmp/khook.out" 2>/dev/null)" "ingested 88"
81
130
 
82
131
  [ "$fail" -eq 0 ] && echo "ALL OK (effort-ops)" || echo "effort-ops: FAILURES"
83
132
  exit "$fail"
@@ -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
  }