@jeiemgi/cckit 0.3.0 → 0.4.1

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.
@@ -25,10 +25,15 @@ case "$1 $2" in
25
25
  "issue edit"|"issue close"|"pr merge") exit 0 ;;
26
26
  "issue view") echo "[Effort] 99 · demo effort" ;; # --json title -q .title
27
27
  "pr create") echo "https://github.com/o/r/pull/7" ;;
28
+ "pr diff") # a merged sub PR's diff (wave-style close, #164): one kit-managed + one app file
29
+ printf 'diff --git a/.claude/skills/demo.md b/.claude/skills/demo.md\n+kit\ndiff --git a/src/app.ts b/src/app.ts\n+app\n' ;;
28
30
  "api "*|"api")
29
31
  case "$*" in
30
32
  *"--method POST"*"/sub_issues"*) exit 0 ;; # link a sub
31
33
  *"/sub_issues"*".[].number"*) printf '101\n102\n' ;; # list subs (for close)
34
+ # wave-style close (#164): per-sub "sub|state|pr|merge-oid|title" rows by parent number
35
+ *closedByPullRequestsReferences*n=77*) printf '301|CLOSED|501|abc1234def|first sub\n302|CLOSED|502|bcd2345eab|second sub\n' ;;
36
+ *closedByPullRequestsReferences*n=78*) printf '201|CLOSED|401|abc1234def|done sub\n202|OPEN|||still open sub\n' ;;
32
37
  *".id"*) echo "55501" ;; # issue db id
33
38
  *) exit 0 ;;
34
39
  esac ;;
@@ -46,11 +51,16 @@ source "$LIB/effort-ops.sh"
46
51
 
47
52
  # ── effort_new ────────────────────────────────────────────────────────────────────────────────
48
53
  : > "$GH_LOG"
49
- parent="$(effort_new "[Core] demo effort" "first sub" "second sub" 2>/dev/null)"
54
+ parent="$(effort_new --flow Core "demo effort" "first sub" "second sub" 2>/dev/null)"
50
55
  t "effort_new returns the parent number" "$parent" "1"
51
56
  t "effort_new creates parent + 2 subs (3 issues)" "$(grep -c 'issue create' "$GH_LOG")" "3"
52
57
  t "effort_new links 2 native sub-issues" "$(grep -c 'method POST .*sub_issues' "$GH_LOG")" "2"
53
58
  tc "$GH_LOG" 'issue create .*--title \[Effort\] · \[Core\] demo effort' "effort_new titles the parent"
59
+ # every kit-defined label is ensured (created idempotently) BEFORE the issue create uses it (#153)
60
+ tc "$GH_LOG" 'label create ctx:' "effort_new ensures the ctx:* label exists"
61
+ tc "$GH_LOG" 'label create kind:task' "effort_new ensures the kind label exists"
62
+ tc "$GH_LOG" 'label create priority:p1' "effort_new ensures the priority label exists"
63
+ tc "$GH_LOG" 'label create flow:core' "effort_new ensures the flow label exists"
54
64
  # a jargon/long name is rejected before any issue is created
55
65
  : > "$GH_LOG"
56
66
  effort_new "refactor the whole scripts/kit wiring layer" >/dev/null 2>&1 && rc=0 || rc=1
@@ -95,18 +105,36 @@ t "effort_close did NOT merge without a trace" "$(grep -c 'pr merge' "$GH_LOG")
95
105
 
96
106
  # ── effort_close #120: happy path — commit present → trace captured → full close ────────────────
97
107
  # 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.
108
+ # capture (pre-squash) → merge → judge/sync → close subs+parent → board Done → worktree GC →
109
+ # kit-sync drift check (#148: board Done + drift check moved into the verb from the skill).
99
110
  echo "work" > file.txt
100
- git -c user.email=t@t -c user.name=t add file.txt
111
+ mkdir -p .claude/skills
112
+ echo "kit-managed" > .claude/skills/demo.md # a kit-managed path → the drift check must fire (#148)
113
+ git -c user.email=t@t -c user.name=t add file.txt .claude/skills/demo.md
101
114
  git -c user.email=t@t -c user.name=t commit -q -m "feat: do the thing (#101)"
115
+
116
+ # #148: the VERB sets board Status=Done (guarded). Stub the board helpers + captured ids in-shell —
117
+ # _eo_source_board must see them and skip sourcing the real gh-project.sh.
118
+ BOARD_LOG="$tmp/board.log"; : > "$BOARD_LOG"
119
+ project_find_item_by_issue() { echo "ITEM-$1"; }
120
+ project_set_single_select() { echo "$*" >> "$BOARD_LOG"; }
121
+ export KIT_PROJECTS_V2="true" STATUS_FIELD_ID="SF1" STATUS_OPT_DONE="OPT_DONE"
122
+
102
123
  : > "$GH_LOG"
103
124
  close_out="$(effort_close 99 2>&1)"; rc=$?
125
+ export KIT_PROJECTS_V2="false"
104
126
  cd "$tmp/work" # our cwd (the effort worktree) is GC'd by the close — step to the main checkout
105
127
  t "effort_close succeeds with a trace (rc 0)" "$rc" "0"
106
128
  tc "$GH_LOG" 'pr merge effort/99-demo .*--squash' "effort_close squash-merges the PR"
107
129
  tc "$GH_LOG" 'issue close 101' "effort_close closes sub #101"
108
130
  tc "$GH_LOG" 'issue close 99 ' "effort_close closes the parent"
109
131
  case "$close_out" in *"metrics:"*) echo "ok: capture_effort_metrics composed into close" ;; *) echo "FAIL: no metrics capture in close"; fail=1 ;; esac
132
+ # #148: board Status=Done for the parent + EVERY sub, set by the verb (was skill-only before)
133
+ tc "$BOARD_LOG" 'ITEM-99 SF1 OPT_DONE' "effort_close sets board Done for the parent"
134
+ tc "$BOARD_LOG" 'ITEM-101 SF1 OPT_DONE' "effort_close sets board Done for sub #101"
135
+ tc "$BOARD_LOG" 'ITEM-102 SF1 OPT_DONE' "effort_close sets board Done for sub #102"
136
+ # #148: kit-sync drift check moved into the verb — a kit-managed path in the diff → advisory warning
137
+ case "$close_out" in *"kit-sync"*".claude/skills/demo.md"*) echo "ok: kit-sync drift check warns on kit-managed files" ;; *) echo "FAIL: no kit-sync warning in close output"; fail=1 ;; esac
110
138
  t "effort_close GC removed the effort worktree" \
111
139
  "$(git -C "$tmp/work" worktree list --porcelain | grep -c 'effort+99-demo')" "0"
112
140
  t "effort_close GC deleted the local branch" \
@@ -123,10 +151,40 @@ chmod +x "$stub/khook"
123
151
  start_out="$(effort_start 88 forced 2>/dev/null)"
124
152
  cd "$tmp/work/.claude/worktrees/effort+88-forced"
125
153
  : > "$GH_LOG"
126
- KHOOK_MARKER="$tmp/khook.out" KIT_EFFORT_KNOWLEDGE_HOOK="$stub/khook" KIT_FORCE=1 effort_close 88 >/dev/null 2>&1
154
+ forced_out="$(KHOOK_MARKER="$tmp/khook.out" KIT_EFFORT_KNOWLEDGE_HOOK="$stub/khook" KIT_FORCE=1 effort_close 88 2>&1)"
127
155
  cd "$tmp/work"
128
156
  tc "$GH_LOG" 'pr merge effort/88-forced .*--squash' "KIT_FORCE=1 close merges despite no trace"
129
157
  t "knowledge-ingest hook ran with the effort number" "$(cat "$tmp/khook.out" 2>/dev/null)" "ingested 88"
158
+ # #148: no kit-managed file touched → the drift check stays silent
159
+ case "$forced_out" in *"kit-sync"*) echo "FAIL: kit-sync warning fired with no kit-managed change"; fail=1 ;; *) echo "ok: drift check silent when no kit-managed file changed" ;; esac
160
+
161
+ # ── effort_close #164: WAVE-style close — subs merged as individual task PRs, no effort branch ──
162
+ # Run from the main checkout on a non-effort branch with NO effort/<N>-* branch anywhere: the close
163
+ # must dispatch to the wave path instead of demanding the integration branch.
164
+
165
+ # refuse: a sub still open / lacking a merged PR → list the stragglers, close nothing
166
+ : > "$GH_LOG"
167
+ close_out="$(effort_close 78 2>&1)"; rc=$?
168
+ t "wave close refuses while a sub is open (rc 1)" "$rc" "1"
169
+ case "$close_out" in *"not done"*"#202"*) echo "ok: wave refuse lists the straggler sub" ;; *) echo "FAIL: wave refuse output: $close_out"; fail=1 ;; esac
170
+ t "wave refuse closes nothing" "$(grep -c 'issue close' "$GH_LOG")" "0"
171
+
172
+ # happy: every sub CLOSED with a merged PR → trace from the PR diffs → parent closed, board Done
173
+ # for parent + subs, drift check fires off the union of the merged PR diffs
174
+ : > "$BOARD_LOG"
175
+ export KIT_PROJECTS_V2="true"
176
+ : > "$GH_LOG"
177
+ close_out="$(effort_close 77 2>&1)"; rc=$?
178
+ export KIT_PROJECTS_V2="false"
179
+ t "wave close succeeds when all subs merged (rc 0)" "$rc" "0"
180
+ tc "$GH_LOG" 'pr diff 501' "wave close snapshots the merged sub PR diffs"
181
+ tc "$GH_LOG" 'issue close 77 ' "wave close closes the parent"
182
+ t "wave close closes ONLY the parent (subs already closed)" "$(grep -c 'issue close' "$GH_LOG")" "1"
183
+ t "wave close never squash-merges anything" "$(grep -c 'pr merge' "$GH_LOG")" "0"
184
+ tc "$BOARD_LOG" 'ITEM-77 SF1 OPT_DONE' "wave close sets board Done for the parent"
185
+ tc "$BOARD_LOG" 'ITEM-301 SF1 OPT_DONE' "wave close sets board Done for sub #301"
186
+ tc "$BOARD_LOG" 'ITEM-302 SF1 OPT_DONE' "wave close sets board Done for sub #302"
187
+ case "$close_out" in *"kit-sync"*".claude/skills/demo.md"*) echo "ok: wave drift check reads the merged PR diffs" ;; *) echo "FAIL: no kit-sync warning in wave close output"; fail=1 ;; esac
130
188
 
131
189
  [ "$fail" -eq 0 ] && echo "ALL OK (effort-ops)" || echo "effort-ops: FAILURES"
132
190
  exit "$fail"
@@ -50,6 +50,14 @@ ${verification:-<!-- how we know it is done: commands, checks, acceptance -->}${
50
50
  EOF
51
51
  }
52
52
 
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
+
53
61
  # Add an issue (by number) to the project board + set Status=Todo and the Role field. Guarded: a
54
62
  # no-op unless Projects v2 is on AND the project helpers (gh-project.sh) are already sourced, so the
55
63
  # verb can run from any shell with no board config. Mirrors the skill's old inline board block.
@@ -158,13 +166,23 @@ effort_new() {
158
166
  local subcount=$#; [ "$subcount" -ge 1 ] || subcount=1
159
167
  local ctx="ctx:S"
160
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"
161
174
  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:]')"
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
164
184
  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
185
+ _eff_ensure_label "par:$par" c5def5 "effort parallelism hint"
168
186
  labels="$labels,par:$par"
169
187
  fi
170
188
 
@@ -308,6 +326,43 @@ _eo_source_metrics() {
308
326
  [ -f "$d/effort-metrics.sh" ] && . "$d/effort-metrics.sh"
309
327
  }
310
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
+
311
366
  # _eo_knowledge_ingest <num> <trace_dir> <root> — optional post-close knowledge-ingest hook. Runs a
312
367
  # project-configured command (github/effort.knowledgeIngestHook, or KIT_EFFORT_KNOWLEDGE_HOOK) with
313
368
  # the effort number + trace dir, so a project can fold the closed effort's work record into its
@@ -328,18 +383,32 @@ _eo_knowledge_ingest() {
328
383
  "$hook" "$num" "$trace" >/dev/null 2>&1 || echo "effort_close: knowledge-ingest hook failed (non-fatal)" >&2
329
384
  }
330
385
 
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.
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.
335
392
  effort_close() {
336
393
  _eff_need gh || return 1; _eff_need jq || return 1
337
- local raw="${1:-}" num repo base branch root self_wt trace_dir
394
+ local raw="${1:-}" num repo base branch root self_wt trace_dir kit_touched
338
395
  [ -n "$raw" ] || { echo "effort_close: <slug|effort issue #> required" >&2; return 1; }
339
396
  num="$(effort_slug_resolve "$raw")" || { echo "effort_close: could not resolve '$raw' to an effort" >&2; return 1; }
340
397
  repo="$(_eff_repo)"; base="$(_eff_base)"
341
398
  branch="$(git rev-parse --abbrev-ref HEAD 2>/dev/null)"
342
- 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
343
412
  root="$(git worktree list --porcelain 2>/dev/null | awk '/^worktree /{print $2; exit}')"
344
413
  self_wt="$(git rev-parse --show-toplevel 2>/dev/null)"
345
414
  _eo_source_metrics
@@ -361,6 +430,11 @@ effort_close() {
361
430
  # (b) capture effort metrics PRE-squash (needs the live-branch diff + commit signals).
362
431
  command -v capture_effort_metrics >/dev/null 2>&1 && capture_effort_metrics "$num" "origin/$base" || true
363
432
 
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
+
364
438
  # (c) squash-merge the effort PR.
365
439
  gh pr merge "$branch" --repo "$repo" --squash --delete-branch >/dev/null 2>&1 \
366
440
  || { echo "effort_close: could not squash-merge the PR for $branch (open? mergeable?)" >&2; return 1; }
@@ -370,12 +444,17 @@ effort_close() {
370
444
  command -v judge_effort_metrics >/dev/null 2>&1 && judge_effort_metrics "$num" "origin/$base" || true
371
445
  command -v sync_effort_metrics >/dev/null 2>&1 && sync_effort_metrics "$num" || true
372
446
 
373
- # (e) close every native sub-issue, then the parent.
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
374
451
  local sub
375
452
  for sub in $(gh api "repos/$repo/issues/$num/sub_issues" --jq '.[].number' 2>/dev/null); do
376
453
  gh issue close "$sub" --repo "$repo" --reason completed >/dev/null 2>&1 && echo " ✓ closed sub #$sub" >&2
454
+ _eo_board_done "$sub"
377
455
  done
378
456
  gh issue close "$num" --repo "$repo" --reason completed >/dev/null 2>&1 && echo " ✓ closed effort #$num" >&2
457
+ _eo_board_done "$num"
379
458
 
380
459
  # (f) GC: switch the main checkout to base, remove the effort worktree, delete the local branch,
381
460
  # prune. The remote branch was deleted by --delete-branch above. All via `git -C "$root"` so the
@@ -394,4 +473,90 @@ effort_close() {
394
473
 
395
474
  # (g) optional, config-gated knowledge-ingest hook (no-op when absent).
396
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"
397
562
  }
@@ -106,6 +106,43 @@ effort_snapshot_subs() {
106
106
  printf '%s' "$dir"
107
107
  }
108
108
 
109
+ # effort_snapshot_merged_subs <parent> <rows> — the WAVE-style trace (#164): the subs were delivered
110
+ # as individual task PRs squash-merged to base, so there is no effort branch whose commits
111
+ # effort_snapshot_subs could walk. Snapshot each sub's merged PR diff instead. <rows> is the wave
112
+ # close's per-sub read, one "sub|state|pr|merge-oid|title" line each. Same layout as
113
+ # effort_snapshot_subs — $traces/effort-<N>/<seq>-<key>.{diff,meta} + index.jsonl — so exporters
114
+ # and the judge read both styles identically.
115
+ effort_snapshot_merged_subs() {
116
+ local parent="$1" rows="$2" dir seq=0
117
+ [[ -n "$parent" && -n "$rows" ]] || { echo "effort_snapshot_merged_subs: parent + sub rows required" >&2; return 1; }
118
+ dir="$(effort_trace_dir "$parent")" || { echo "effort_snapshot_merged_subs: could not create trace dir" >&2; return 1; }
119
+
120
+ local index="$dir/index.jsonl"
121
+ : > "$index"
122
+
123
+ local sub state pr oid title stub short
124
+ while IFS='|' read -r sub state pr oid title; do
125
+ [[ -n "$pr" ]] || continue
126
+ seq=$((seq + 1))
127
+ short="$(printf '%.7s' "$oid")"; [[ -n "$short" ]] || short="pr$pr"
128
+ stub="$(printf '%02d-%s' "$seq" "$short")"
129
+ gh pr diff "$pr" --repo "$EFFORT_REPO" > "$dir/$stub.diff" 2>/dev/null || rm -f "$dir/$stub.diff"
130
+ [[ -s "$dir/$stub.diff" ]] || { rm -f "$dir/$stub.diff"; seq=$((seq - 1)); continue; }
131
+ jq -n --arg parent "$parent" --arg sub "${sub:-}" --arg sha "${oid:-}" \
132
+ --arg subject "$title" --arg pr "$pr" --arg file "$stub.diff" \
133
+ '{parent:($parent|tonumber), sub_issue:(if $sub=="" then null else ($sub|tonumber) end),
134
+ commit:(if $sha=="" then null else $sha end), pr:($pr|tonumber), subject:$subject,
135
+ branch:null, diff_file:$file, outcome:"merged"}' \
136
+ > "$dir/$stub.meta"
137
+ cat "$dir/$stub.meta" >> "$index"
138
+ done <<EOF_ROWS
139
+ $rows
140
+ EOF_ROWS
141
+
142
+ echo " ✓ snapshotted $seq merged sub PR diff(s) to $dir (index.jsonl)" >&2
143
+ printf '%s' "$dir"
144
+ }
145
+
109
146
  # ── Effort PR title — ONE composer shared by the verb + the skill (#121) ────────────────────────
110
147
  # `cckit effort pr` (the verb) and /kit-effort-pr (the skill) previously composed different PR
111
148
  # titles; they now both call effort_pr_title so an effort PR is titled identically no matter who
@@ -146,7 +183,26 @@ effort_pr_title_check() {
146
183
  # controlled vocabulary — never internal jargon, glyphs, code identifiers, parentheticals, em-dash
147
184
  # sub-clauses, or >6 words (detail goes in the body). See rules/effort-model.md § Titles.
148
185
 
149
- # Controlled flow vocabulary for the optional leading [Flow] title tag. Projects override via EFFORT_FLOWS.
186
+ # Controlled flow vocabulary for the optional leading [Flow] title tag. Resolution order (#150):
187
+ # 1. an explicit EFFORT_FLOWS env var always wins (per-invocation override)
188
+ # 2. the project config `effort.flows[]` — via KIT_EFFORT_FLOWS (exported by load_kit_config) or
189
+ # read straight from the config file, so a configured vocabulary works even for callers that
190
+ # never loaded the config
191
+ # 3. the built-in default.
192
+ _effort_flows_from_config() {
193
+ if [[ -n "${KIT_EFFORT_FLOWS:-}" ]]; then printf '%s' "$KIT_EFFORT_FLOWS"; return 0; fi
194
+ command -v jq >/dev/null 2>&1 || return 1
195
+ # Locate the project config through the ONE shared resolver (config-path.sh sits next to this lib).
196
+ if ! command -v kit_config_path >/dev/null 2>&1; then
197
+ local _ef_dir; _ef_dir="$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" 2>/dev/null && pwd)"
198
+ # shellcheck source=/dev/null
199
+ [[ -n "$_ef_dir" && -f "$_ef_dir/config-path.sh" ]] && . "$_ef_dir/config-path.sh"
200
+ fi
201
+ command -v kit_config_path >/dev/null 2>&1 || return 1
202
+ local _ef_cfg; _ef_cfg="$(kit_config_path 2>/dev/null)" && [[ -f "$_ef_cfg" ]] || return 1
203
+ jq -r '[.effort.flows[]? | tostring] | join(" ")' "$_ef_cfg" 2>/dev/null
204
+ }
205
+ if [[ -z "${EFFORT_FLOWS:-}" ]]; then EFFORT_FLOWS="$(_effort_flows_from_config 2>/dev/null || true)"; fi
150
206
  EFFORT_FLOWS="${EFFORT_FLOWS:-Core UI API Docs Infra Auth Data Web App}"
151
207
  # Jargon denylist — internal terms that read as noise on the board. Override via EFFORT_TITLE_JARGON.
152
208
  EFFORT_TITLE_JARGON="${EFFORT_TITLE_JARGON:-chrome seam contract claim rescue stash teardown scaffolding shim boilerplate refactor wiring}"
@@ -76,6 +76,10 @@ load_kit_config() {
76
76
  KIT_MILESTONES="$(jq -r '.milestones[]? // empty' "$cfg")"
77
77
  export KIT_ROLES KIT_MILESTONES
78
78
 
79
+ # Effort flow vocabulary (effort.flows[]) — space-joined so effort.sh can resolve EFFORT_FLOWS
80
+ # from the project config (#150). Empty when unconfigured (effort.sh keeps its built-in default).
81
+ export KIT_EFFORT_FLOWS="$(jq -r '[.effort.flows[]? | tostring] | join(" ")' "$cfg")"
82
+
79
83
  # Apply per-folder .claudekit/ overrides (no-op when none exist).
80
84
  _kit_apply_claudekit_overlays "$cfg"
81
85
  }
@@ -109,5 +113,6 @@ _kit_apply_claudekit_overlays() {
109
113
  export KIT_ANNOTATE_ENABLED="$(_kit_cfg_get '.annotate.enabled // false')"
110
114
  export KIT_ANNOTATE_BACKEND="$(_kit_cfg_get '.annotate.backend // ""')"
111
115
  export KIT_ANNOTATE_FRAMEWORK="$(_kit_cfg_get '.annotate.framework // ""')"
116
+ export KIT_EFFORT_FLOWS="$(_kit_cfg_get '[.effort.flows[]? | tostring] | join(" ")')"
112
117
  export KIT_EFFECTIVE_CONFIG="$merged"
113
118
  }
@@ -80,6 +80,15 @@ if [ -n "${KIT_ENGINE_TEST_INNER:-}" ]; then
80
80
  printf 'USER EDIT\n' > dst.txt
81
81
  KIT_ASSUME_YES= kit_op_write src.txt dst.txt A wire </dev/null >/dev/null 2>&1
82
82
  t "conffiles keeps edit" "$(cat dst.txt)" "USER EDIT"
83
+ # conffiles hard rule (#149): KIT_ASSUME_YES never consents to clobbering an edited file
84
+ KIT_ASSUME_YES=1 kit_op_write src.txt dst.txt A wire >/dev/null 2>&1
85
+ t "assume-yes keeps edit (rc)" "$?" "10"
86
+ t "assume-yes keeps edit" "$(cat dst.txt)" "USER EDIT"
87
+ # ...nor an UNTRACKED pre-existing file with different content (never touch what we don't own)
88
+ printf 'PRE-EXISTING\n' > pre.txt
89
+ KIT_ASSUME_YES=1 kit_op_write src.txt pre.txt A wire >/dev/null 2>&1
90
+ t "untracked existing kept (rc)" "$?" "10"
91
+ t "untracked existing kept" "$(cat pre.txt)" "PRE-EXISTING"
83
92
  # remove untracked refuses
84
93
  printf 'z\n' > untracked2.txt
85
94
  KIT_ASSUME_YES=1 kit_op_remove untracked2.txt >/dev/null 2>&1
@@ -0,0 +1,149 @@
1
+ #!/usr/bin/env bash
2
+ # shellcheck shell=bash
3
+ # kit-msg-test.sh — #175: session mail. Hermetic: KIT_MAIL_DIR pins the mailbox root; two
4
+ # throwaway repos (with remotes) stand in for two PROJECTS, worktrees for sessions. Covers:
5
+ # send/read-once, CROSS-PROJECT addressing (project:branch), broadcast seen-ledger (each
6
+ # recipient exactly once, project-scoped), steer marking, and the hook driver's per-event JSON
7
+ # (additionalContext events vs the Stop block that fires ONLY for steer mail and never twice).
8
+ # Run: bash scripts/lib/kit-msg-test.sh
9
+ set -u
10
+ LIB="$(cd "$(dirname "$0")" && pwd)"
11
+ fail=0
12
+ t() { if [ "$2" = "$3" ]; then echo "ok: $1"; else echo "FAIL: $1 -> got '[$2]' want '[$3]'"; fail=1; fi; }
13
+ command -v jq >/dev/null 2>&1 || { echo "kit-msg-test: jq required" >&2; exit 1; }
14
+
15
+ tmp="$(mktemp -d)"; trap 'rm -rf "$tmp"' EXIT
16
+ export KIT_MAIL_DIR="$tmp/mail"
17
+
18
+ mkrepo() { # mkrepo <dir> <owner/name>
19
+ git -C "$tmp" init -q -b main "$1"
20
+ git -C "$tmp/$1" -c user.email=t@t -c user.name=t commit -q --allow-empty -m init
21
+ git -C "$tmp/$1" remote add origin "git@github.com:$2.git"
22
+ }
23
+ mkrepo appA "acme/app-a"
24
+ mkrepo appB "acme/app-b"
25
+ git -C "$tmp/appA" worktree add -q -b task/9-fix "$tmp/appA-fix" main >/dev/null 2>&1
26
+ git -C "$tmp/appA" worktree add -q -b docs/site "$tmp/appA-docs" main >/dev/null 2>&1
27
+
28
+ # shellcheck source=/dev/null
29
+ . "$LIB/kit-msg.sh"
30
+
31
+ # ── same-project: send (from main) → read-once (in task/9-fix) ─────────────────────────────────
32
+ cd "$tmp/appA"
33
+ msg_send "task/9-fix" "rebase onto main" >/dev/null 2>&1
34
+ t "mailbox is keyed project/branch (encoded)" \
35
+ "$(ls "$KIT_MAIL_DIR/acme+app-a/task+9-fix/new" | wc -l | tr -d ' ')" "1"
36
+
37
+ cd "$tmp/appA-fix"
38
+ out="$(msg_read)"
39
+ case "$out" in *"rebase onto main"*) echo "ok: recipient reads the message" ;; *) echo "FAIL: read output: $out"; fail=1 ;; esac
40
+ t "direct mail is read-ONCE (moved to read/)" "$(msg_read)" "no mail for acme/app-a:task/9-fix"
41
+ t "consumed mail is archived, not lost" \
42
+ "$(ls "$KIT_MAIL_DIR/acme+app-a/task+9-fix/read" | wc -l | tr -d ' ')" "1"
43
+
44
+ # ── cross-project: appB steers appA's docs session by project:branch ────────────────────────────
45
+ cd "$tmp/appB"
46
+ msg_send "acme/app-a:docs/site" "app-b broke your API fixture" >/dev/null 2>&1
47
+ cd "$tmp/appA-docs"
48
+ out="$(msg_read)"
49
+ case "$out" in *"app-b broke your API fixture"*) echo "ok: cross-project mail delivered" ;; *) echo "FAIL: cross-project: $out"; fail=1 ;; esac
50
+ case "$out" in *"from: main (acme/app-b)"*) echo "ok: sender carries its project identity" ;; *) echo "FAIL: sender header: $out"; fail=1 ;; esac
51
+
52
+ # ── broadcast: project-scoped, each session exactly once ────────────────────────────────────────
53
+ cd "$tmp/appA"
54
+ msg_send all "v0.4.0 released" >/dev/null 2>&1
55
+ cd "$tmp/appA-fix"; out1="$(msg_read)"
56
+ cd "$tmp/appA-docs"; out2="$(msg_read)"
57
+ case "$out1" in *"v0.4.0 released"*) echo "ok: broadcast reaches session 1" ;; *) echo "FAIL: bcast s1: $out1"; fail=1 ;; esac
58
+ case "$out2" in *"v0.4.0 released"*) echo "ok: broadcast reaches session 2" ;; *) echo "FAIL: bcast s2: $out2"; fail=1 ;; esac
59
+ t "broadcast is once per session" "$(msg_read)" "no mail for acme/app-a:docs/site"
60
+ cd "$tmp/appB"
61
+ t "broadcast is project-scoped (app-b unaffected)" "$(msg_read)" "no mail for acme/app-b:main"
62
+
63
+ # ── hook driver: additionalContext events ───────────────────────────────────────────────────────
64
+ cd "$tmp/appA"
65
+ msg_send "docs/site" "please hold merges" >/dev/null 2>&1
66
+ cd "$tmp/appA-docs"
67
+ hj="$(msg_hook_check PostToolUse)"
68
+ t "PostToolUse JSON names the event" "$(printf '%s' "$hj" | jq -r '.hookSpecificOutput.hookEventName')" "PostToolUse"
69
+ case "$(printf '%s' "$hj" | jq -r '.hookSpecificOutput.additionalContext')" in
70
+ *"please hold merges"*) echo "ok: mail rides additionalContext" ;;
71
+ *) echo "FAIL: additionalContext: $hj"; fail=1 ;;
72
+ esac
73
+ t "hook is SILENT with no mail" "$(msg_hook_check PostToolUse)" ""
74
+
75
+ # ── Stop: blocks only for steer mail, consumed so it can never block twice ─────────────────────
76
+ cd "$tmp/appA"
77
+ msg_send "docs/site" "fyi only" >/dev/null 2>&1
78
+ cd "$tmp/appA-docs"
79
+ t "Stop ignores a plain note" "$(msg_hook_check Stop)" ""
80
+ cd "$tmp/appB"
81
+ msg_send "acme/app-a:docs/site" --steer "stop and rebase first" >/dev/null 2>&1
82
+ cd "$tmp/appA-docs"
83
+ sj="$(msg_hook_check Stop)"
84
+ t "Stop blocks for steer mail (cross-project too)" "$(printf '%s' "$sj" | jq -r '.decision')" "block"
85
+ case "$(printf '%s' "$sj" | jq -r '.reason')" in
86
+ *"stop and rebase first"*) echo "ok: steer text is the block reason" ;;
87
+ *) echo "FAIL: stop reason: $sj"; fail=1 ;;
88
+ esac
89
+ t "a consumed steer never blocks twice" "$(msg_hook_check Stop)" ""
90
+ # the plain note from above is still queued for a context event
91
+ case "$(msg_hook_check UserPromptSubmit)" in
92
+ *"fyi only"*) echo "ok: note still delivered on the next context event" ;;
93
+ *) echo "FAIL: note lost after Stop pass"; fail=1 ;;
94
+ esac
95
+
96
+ # ── hcom-informed hardening (#175): cap, typo warning, opt-in Stop long-poll ────────────────────
97
+ # delivery cap: excess mail rides the NEXT hook fire, nothing is lost
98
+ cd "$tmp/appA"
99
+ msg_send "docs/site" "one" >/dev/null 2>&1
100
+ msg_send "docs/site" "two" >/dev/null 2>&1
101
+ cd "$tmp/appA-docs"
102
+ # order within one second is filename-random — assert counts and the union, not sequence
103
+ h1="$(KIT_MAIL_MAX_PER_DELIVERY=1 msg_hook_check PostToolUse | jq -r '.hookSpecificOutput.additionalContext')"
104
+ h2="$(KIT_MAIL_MAX_PER_DELIVERY=1 msg_hook_check PostToolUse | jq -r '.hookSpecificOutput.additionalContext')"
105
+ t "cap: first delivery carries exactly one message" "$(printf '%s' "$h1" | grep -c '^kind: note')" "1"
106
+ t "cap: second delivery carries exactly one message" "$(printf '%s' "$h2" | grep -c '^kind: note')" "1"
107
+ case "$h1$h2" in
108
+ *one*two*|*two*one*) echo "ok: capped-out mail rides the next hook fire (nothing lost)" ;;
109
+ *) echo "FAIL: cap lost mail: [$h1] [$h2]"; fail=1 ;;
110
+ esac
111
+
112
+ # typo'd target → loud warning about a brand-new mailbox
113
+ cd "$tmp/appA"
114
+ warn="$(msg_send "task/9-fxi" "typo target" 2>&1 >/dev/null)"
115
+ case "$warn" in *"new mailbox"*) echo "ok: unknown target warns instead of silently dropping" ;; *) echo "FAIL: no new-mailbox warning: $warn"; fail=1 ;; esac
116
+ warn="$(msg_send "task/9-fix" "known target" 2>&1 >/dev/null)"
117
+ case "$warn" in *"new mailbox"*) echo "FAIL: warned on an existing mailbox"; fail=1 ;; *) echo "ok: existing mailbox does not warn" ;; esac
118
+
119
+ # opt-in Stop long-poll: steer sent DURING the wait is still delivered (near-real-time idle steer)
120
+ cd "$tmp/appA-docs"
121
+ ( sleep 1; cd "$tmp/appA" && . "$LIB/kit-msg.sh" && msg_send "docs/site" --steer "late steer" >/dev/null 2>&1 ) &
122
+ pj="$(KIT_MAIL_STOP_POLL=4 msg_hook_check Stop)"
123
+ wait
124
+ case "$(printf '%s' "$pj" | jq -r '.reason' 2>/dev/null)" in
125
+ *"late steer"*) echo "ok: Stop long-poll catches a steer that lands mid-wait" ;;
126
+ *) echo "FAIL: long-poll missed the steer: $pj"; fail=1 ;;
127
+ esac
128
+ t "long-poll consumed the steer (no double block)" "$(msg_hook_check Stop)" ""
129
+
130
+ # ── hook script resolution (#179): the project's own bin/cckit beats a stale PATH cckit ─────────
131
+ HOOK="$LIB/../../templates/hooks/kit-mail-check.sh.tmpl"
132
+ mkdir -p "$tmp/appA/bin" "$tmp/stalebin"
133
+ cat > "$tmp/appA/bin/cckit" <<'SH'
134
+ #!/usr/bin/env bash
135
+ [ "$1 $2" = "msg hook-check" ] && echo "PROJECT-BIN-DELIVERED $3"
136
+ SH
137
+ cat > "$tmp/stalebin/cckit" <<'SH'
138
+ #!/usr/bin/env bash
139
+ echo "cckit: unknown command '$1'" >&2; exit 2
140
+ SH
141
+ chmod +x "$tmp/appA/bin/cckit" "$tmp/stalebin/cckit"
142
+ hout="$(printf '{"hook_event_name":"PostToolUse","cwd":"%s"}' "$tmp/appA" | PATH="$tmp/stalebin:$PATH" bash "$HOOK")"
143
+ t "hook prefers the project's own bin/cckit over a stale PATH cckit" "$hout" "PROJECT-BIN-DELIVERED PostToolUse"
144
+ rm -rf "$tmp/appA/bin"
145
+ hout="$(printf '{"hook_event_name":"Stop","cwd":"%s"}' "$tmp/appA" | PATH="$tmp/stalebin:$PATH" bash "$HOOK"; echo "rc=$?")"
146
+ t "hook stays a silent no-op when only a broken PATH cckit exists" "$hout" "rc=0"
147
+
148
+ [ "$fail" -eq 0 ] && echo "ALL OK (kit-msg)"
149
+ exit "$fail"