@jeiemgi/cckit 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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
@@ -48,6 +48,21 @@ kit_op_write() {
48
48
 
49
49
  # conffiles guard: tracked + user-modified => never silent overwrite
50
50
  local verdict; verdict="$(kit_manifest_verify "$dest" 2>/dev/null || true)"
51
+
52
+ # conffiles hard rule (#149): an EXISTING file with DIFFERENT content that the kit cannot
53
+ # prove it owns intact — user-edited (modified) or never recorded (untracked) — is only
54
+ # overwritten on an explicit interactive yes. KIT_ASSUME_YES does not consent on the user's
55
+ # behalf (mirrors kit_op_remove): non-interactive runs (init --upgrade, kit-update, CI)
56
+ # keep the user's version. Fixes the statusline-shim clobber on every /kit-update.
57
+ local guarded=0
58
+ if [ -f "$dest" ] && ! cmp -s "$src" "$dest" 2>/dev/null; then
59
+ case "$verdict" in modified|untracked) guarded=1;; esac
60
+ fi
61
+ if [ "$guarded" -eq 1 ] && { [ -n "${KIT_ASSUME_YES:-}" ] || _kit_op_dry; }; then
62
+ _kit_op_say "= kept your version ($verdict — never auto-overwritten): $dest"
63
+ return 10
64
+ fi
65
+
51
66
  _kit_op_say "propose: $dest (tier $tier, $op, current=$verdict)"
52
67
  _kit_op_diff "$src" "$dest"
53
68
 
@@ -57,8 +72,8 @@ kit_op_write() {
57
72
  return 0
58
73
  fi
59
74
 
60
- if [ "$verdict" = "modified" ]; then
61
- if ! _kit_op_confirm " $dest was edited by you — overwrite?"; then
75
+ if [ "$guarded" -eq 1 ]; then
76
+ if ! _kit_op_confirm " $dest was edited by you (or is not kit-tracked) — overwrite?"; then
62
77
  _kit_op_say " skip (kept your version): $dest"; return 10
63
78
  fi
64
79
  elif ! _kit_op_confirm " apply?"; then
@@ -1,19 +1,34 @@
1
1
  ---
2
2
  name: kit-effort-close
3
- description: Close an effort in ONE op — snapshot each sub-issue's diff BEFORE squash (work record), squash-merge the effort PR, close the parent + ALL native sub-issues, set the board Status=Done for the parent and every sub, then garbage-collect (switch to the base branch, pull, remove the effort worktree, delete local+remote branch, prune). Finally, flag any kit-managed files the effort touched for upstream contribution.
3
+ description: Close an effort in ONE op — snapshot each sub-issue's diff BEFORE squash (work record), capture/judge/sync effort metrics, squash-merge the effort PR, close the parent + ALL native sub-issues, set the board Status=Done for each, garbage-collect the worktree/branch, run the optional knowledge-ingest hook, and finish with the kit-sync drift check.
4
4
  when_to_use: When the effort PR has been reviewed and is ready to land. This is the single close op for the effort lifecycle (effort-model.md) — board + record state are correct by construction. Replaces the separate merge / close / mark-done / gc steps.
5
5
  ---
6
6
 
7
7
  # kit-effort-close
8
8
 
9
- Plugin-direct skill — runs straight from `${CLAUDE_PLUGIN_ROOT}` (no per-project `scripts/` checkout
10
- needed). The verb logic (`effort_branch_num`, `effort_snapshot_subs`) lives in
11
- `scripts/lib/effort.sh`, never re-authored inline (kit-engine-boundary #1/#2). Respects
12
- `KIT_BASE_BRANCH` (default `main`) and the `KIT_PROJECTS_V2` board toggle.
9
+ Plugin-direct skill — runs straight from `${CLAUDE_PLUGIN_ROOT}` (no per-project `scripts/`
10
+ checkout needed). It is a **thin caller** of the single close implementation `effort_close`
11
+ (`scripts/lib/effort-ops.sh`) — the exact function `cckit effort close <N>` runs — so the skill
12
+ and the verb close an effort identically (#148, the #121 single-implementation precedent). No
13
+ close logic is re-authored inline (kit-engine-boundary #1/#2). Respects `KIT_BASE_BRANCH`
14
+ (default `main`) and the `KIT_PROJECTS_V2` board toggle.
13
15
 
14
16
  The effort lifecycle's terminal op. Board state, issue state, and the work record are correct
15
- **by construction** — this op owns them. Order matters: **snapshot before squash** (squash destroys
16
- the per-sub-issue commit pairs that ARE the per-unit work record — effort-model.md "Trace hard rules").
17
+ **by construction** — the core op owns them, in this order:
18
+
19
+ 1. **Snapshot sub-diffs BEFORE squash** (squash destroys the per-sub-issue commit pairs that ARE
20
+ the work record — effort-model.md "Trace hard rules"), with a **refuse-squash-without-trace**
21
+ backstop (`KIT_FORCE=1` overrides).
22
+ 2. **Capture effort metrics** pre-squash (telemetry: live-branch diff + commit signals).
23
+ 3. **Squash-merge** the effort PR.
24
+ 4. **Judge + sync** the metrics (reads the durable trace dir; no-ops when the engine is off).
25
+ 5. **Close the parent + ALL native sub-issues** and set the **board Status=Done** for each
26
+ (guarded — a no-op when Projects v2 is off).
27
+ 6. **GC**: base branch checked out + pulled in the main checkout, effort worktree removed,
28
+ local branch deleted, pruned (the remote branch is deleted by the merge).
29
+ 7. **Knowledge-ingest hook** (optional, config-gated via `effort.knowledgeIngestHook`).
30
+ 8. **Kit-sync drift check** — advisory warning when the effort touched kit-managed files that
31
+ belong upstream (/kit-contribute).
17
32
 
18
33
  ## Preconditions
19
34
 
@@ -26,20 +41,28 @@ If not, abort and route to `/kit-effort-pr` first.
26
41
 
27
42
  | Field | Required | Notes |
28
43
  | ------------ | -------- | ------------------------------------------------------- |
29
- | Issue number | optional | Parent #N — derived from `effort/<N>-<slug>` if omitted |
30
- | PR number | optional | Defaults to the open PR for the effort branch |
44
+ | Issue number | optional | Parent #N or slug — derived from `effort/<N>-<slug>` if omitted |
31
45
 
32
46
  ## Execution
33
47
 
48
+ This skill is a **thin caller** of `effort_close` (`scripts/lib/effort-ops.sh`) — the SAME
49
+ function `cckit effort close` runs. The core owns the pre-squash snapshot + trace backstop,
50
+ telemetry capture/judge/sync, the squash-merge, issue closes, board Done, GC, the
51
+ knowledge-ingest hook, and the kit-sync drift check. There is no second implementation here.
52
+
53
+ The core handles both effort styles (#164): run from the `effort/<N>-…` branch it squash-merges
54
+ the integration PR; run from anywhere else with an explicit `#N`, and if no `effort/<N>` branch
55
+ exists anywhere (a **wave-driven** effort — subs merged as individual task PRs), it verifies every
56
+ sub is closed with a merged PR, traces from the merged PR diffs, and runs the same close tail.
57
+
34
58
  ```bash
35
59
  source "${CLAUDE_PLUGIN_ROOT}/scripts/lib/kit-config.sh" && load_kit_config
36
- [[ "$KIT_PROJECTS_V2" == "true" ]] && { source "${CLAUDE_PLUGIN_ROOT}/scripts/lib/gh-project.sh"; load_project_ids; }
37
60
  source "${CLAUDE_PLUGIN_ROOT}/scripts/lib/effort.sh"
38
- BASE="${KIT_BASE_BRANCH:-main}"
61
+ source "${CLAUDE_PLUGIN_ROOT}/scripts/lib/effort-ops.sh" # effort_close — the single close op
39
62
 
40
63
  BRANCH=$(git rev-parse --abbrev-ref HEAD)
41
64
 
42
- # 0. Resolve parent #N + the effort PR.
65
+ # Resolve the parent #N (accepts a slug too — effort_slug_resolve); default to the branch.
43
66
  NUM="${INPUT_NUM:-}"
44
67
  [[ -z "$NUM" ]] && NUM=$(effort_branch_num "$BRANCH")
45
68
  [[ -z "$NUM" ]] && { echo "✗ Not on an effort branch (effort/<N>-<slug>) and no #N passed"; exit 1; }
@@ -48,109 +71,34 @@ if [[ -n "$(git status --porcelain)" ]]; then
48
71
  echo "✗ Working tree dirty — commit via /kit-effort-pr first"; exit 1
49
72
  fi
50
73
 
51
- PR_NUM="${INPUT_PR:-}"
52
- [[ -z "$PR_NUM" ]] && PR_NUM=$(gh pr list --repo "$KIT_REPO" --head "$BRANCH" --state open --json number --jq '.[0].number // empty')
53
- [[ -z "$PR_NUM" ]] && { echo "✗ No open PR for $BRANCH — run /kit-effort-pr $NUM"; exit 1; }
54
- echo "→ effort #$NUM · PR #$PR_NUM · branch $BRANCH"
55
-
56
- # ── (a) SNAPSHOT SUB-DIFFS *BEFORE* SQUASH ───────────────────────────────────────────────
57
- # Squash collapses the per-sub-issue commits; capture each commit's diff + its sub-issue pairing
58
- # NOW, to a durable trace dir under the shared git-common-dir (survives the worktree prune below).
59
- TRACE_DIR=$(effort_snapshot_subs "$NUM" "origin/$BASE")
60
- echo " trace: ${TRACE_DIR:-<none>}"
61
-
62
- # ── (b) SQUASH-MERGE THE EFFORT PR ───────────────────────────────────────────────────────
63
- MERGE_INFO=$(gh pr view "$PR_NUM" --repo "$KIT_REPO" --json mergeable,isDraft --jq '{m:.mergeable,d:.isDraft}')
64
- [[ "$(echo "$MERGE_INFO" | jq -r .d)" == "true" ]] && { echo "✗ PR #$PR_NUM is a draft — undraft first"; exit 1; }
65
- if [[ "$(echo "$MERGE_INFO" | jq -r .m)" == "CONFLICTING" ]]; then
66
- echo "→ Conflicts — rebasing onto $BASE..."
67
- git fetch origin "$BASE" && git rebase "origin/$BASE" \
68
- && git push --force-with-lease origin "$BRANCH" \
69
- || { echo "✗ Rebase conflicts need manual resolution"; git rebase --abort 2>/dev/null; exit 1; }
70
- sleep 3
71
- fi
72
- gh pr merge "$PR_NUM" --repo "$KIT_REPO" --squash || { echo "✗ Merge failed — see https://github.com/$KIT_REPO/pull/$PR_NUM"; exit 1; }
73
- echo "✓ PR #$PR_NUM squash-merged"
74
-
75
- # ── (c) CLOSE PARENT + ALL NATIVE SUB-ISSUES ─────────────────────────────────────────────
76
- # Native sub-issues (GitHub parent/child). Collect them via GraphQL subIssues.
77
- SUBS=$(gh api graphql -f query='
78
- query($o:String!,$r:String!,$n:Int!){repository(owner:$o,name:$r){issue(number:$n){
79
- subIssues(first:50){nodes{number state}}}}}' \
80
- -F o="${KIT_REPO%/*}" -F r="${KIT_REPO#*/}" -F n="$NUM" \
81
- --jq '.data.repository.issue.subIssues.nodes[]?.number' 2>/dev/null)
82
-
83
- # The parent auto-closes on merge to the default branch via `Closes #N`; ensure it, plus close every sub.
84
- for N in $NUM $SUBS; do
85
- STATE=$(gh issue view "$N" --repo "$KIT_REPO" --json state --jq .state 2>/dev/null)
86
- if [[ "$STATE" == "OPEN" ]]; then
87
- gh issue close "$N" --repo "$KIT_REPO" \
88
- --comment "Closed on merge of effort PR #$PR_NUM (parent #$NUM) — /kit-effort-close." \
89
- && echo "✓ closed #$N"
90
- else
91
- echo " #$N already ${STATE:-unknown} — skipped"
92
- fi
93
- done
94
-
95
- # ── (d) BOARD: STATUS=DONE FOR PARENT + ALL SUBS ─────────────────────────────────────────
96
- # project_find_item_by_issue paginates the WHOLE board and fails loudly instead of returning empty.
97
- if [[ "$KIT_PROJECTS_V2" == "true" ]]; then
98
- for N in $NUM $SUBS; do
99
- ITEM=$(project_find_item_by_issue "$N") || { echo " ⚠ board lookup failed for #$N (see stderr)"; continue; }
100
- if [[ -n "$ITEM" ]]; then
101
- project_set_single_select "$ITEM" "$STATUS_FIELD_ID" "$STATUS_OPT_DONE" && echo "✓ board Done: #$N"
102
- else
103
- echo " ⚠ #$N not on board — skipped"
104
- fi
105
- done
106
- fi
107
-
108
- # ── (e) GC: trunk + prune the effort worktree/branch ─────────────────────────────────────
109
- WT=$(git worktree list --porcelain | awk -v b="refs/heads/$BRANCH" '/^worktree /{p=$2} /^branch /{if($2==b) print p}')
110
- MAIN_WT=$(git worktree list --porcelain | awk '/^worktree /{print $2; exit}')
111
- git -C "$MAIN_WT" checkout "$BASE" 2>/dev/null || git checkout "$BASE"
112
- git -C "$MAIN_WT" pull origin "$BASE" 2>/dev/null || git pull origin "$BASE"
113
- if [[ -n "$WT" && "$WT" != "$MAIN_WT" ]]; then
114
- git worktree remove "$WT" --force && echo "✓ removed worktree $WT"
115
- fi
116
- git branch -D "$BRANCH" 2>/dev/null && echo "✓ deleted local branch $BRANCH"
117
- git push origin --delete "$BRANCH" 2>/dev/null && echo "✓ deleted remote branch $BRANCH" || echo " (remote branch already gone)"
118
- git worktree prune
119
-
120
- # ── (f) KIT-SYNC DRIFT CHECK — kit ⇄ project stay in sync ─────────────────────────────────
121
- # If this effort changed kit-managed files, they likely belong upstream (/kit-contribute) — a
122
- # future /kit-update could otherwise clobber un-upstreamed fixes. Advisory; never blocks the close.
123
- KIT_TOUCHED=$(git -C "$MAIN_WT" show --name-only --pretty=format: HEAD 2>/dev/null \
124
- | grep -E '^(scripts/(lib/|kit$|kit-)|\.claude/(skills|rules|hooks|lib|agents)/)' | sort -u || true)
125
- if [[ -n "$KIT_TOUCHED" ]]; then
126
- echo ""
127
- echo "⚠ kit-sync: this effort changed kit-managed files — review for upstream (/kit-contribute):"
128
- printf ' %s\n' $KIT_TOUCHED
129
- echo " kit ⇄ project must stay in sync; an un-upstreamed change can be clobbered by /kit-update."
130
- fi
131
-
132
- echo "✓ effort #$NUM closed — merged, parent+subs Done, trace at ${TRACE_DIR:-<none>}, worktree pruned"
74
+ # The single close op — identical to `cckit effort close $NUM`.
75
+ effort_close "$NUM"
133
76
  ```
134
77
 
78
+ > The block above is intentionally short: all close logic lives in `effort_close`. If you need to
79
+ > change what a close does (trace, telemetry, board, GC, hooks, drift check), change the core —
80
+ > both the skill and the verb move together.
81
+
135
82
  ## Output
136
83
 
137
- - Pre-squash trace dir (`<git-common-dir>/traces/effort-<N>/` + `index.jsonl`)
84
+ - Pre-squash trace dir (`<git-common-dir>/traces/effort-<N>/` + `index.jsonl`) + captured metrics
138
85
  - PR squash-merged; parent + all native sub-issues closed
139
86
  - Board Status=Done for parent + every sub (if Projects v2 is on)
140
- - On the base branch, up to date; effort worktree + local/remote branch removed and pruned
141
- - A kit-sync warning if the effort touched kit-managed files
87
+ - Main checkout on the base branch, up to date; effort worktree + local/remote branch removed and pruned
88
+ - Knowledge-ingest hook ran (if configured); a kit-sync warning if the effort touched kit-managed files
142
89
 
143
90
  ## Rules
144
91
 
145
- - **Snapshot BEFORE squash — absolute** (step a). Squash destroys the per-sub-issue commit pairs
146
- that ARE the per-unit work record. Never reorder a/b. The trace lives under the **shared
147
- git-common-dir** so it survives the worktree prune in step e.
92
+ - **One close implementation** — `effort_close` in `scripts/lib/effort-ops.sh`. Never re-author
93
+ merge/close/board/GC steps inline here (#148; the #121 PR-title precedent).
94
+ - **Snapshot BEFORE squash — absolute.** Squash destroys the per-sub-issue commit pairs that ARE
95
+ the per-unit work record; the core refuses to squash when no trace was captured (`KIT_FORCE=1`
96
+ overrides). The trace lives under the **shared git-common-dir** so it survives the worktree prune.
148
97
  - **One op owns board + issue + record state** — never rely on a separate, skippable "mark done"
149
- (effort-model.md). All subs go Done here.
150
- - Never merge a draft PR — abort with instructions to undraft.
98
+ (effort-model.md). All subs go Done in the core.
151
99
  - recover-before-prune (branch-naming.md): never remove a worktree with a staged-but-uncommitted
152
100
  delta — the working tree must be clean (precondition) before this op proceeds.
153
101
  - Scrub secrets from the trace if any commit diff could contain them (trace hygiene).
154
102
  - Never force-push to trunk; never delete the default branch.
155
- - **Heed step (f):** a kit-managed change that isn't contributed upstream is a latent regression
156
- the next `/kit-update` can revert. Treat the warning as a to-do.
103
+ - **Heed the kit-sync warning:** a kit-managed change that isn't contributed upstream is a latent
104
+ regression the next `/kit-update` can revert. Treat the warning as a to-do.
@@ -23,7 +23,7 @@ truth — the parent issue IS the plan (no separate plan file).
23
23
  | ------------ | -------- | ------------------------------------------------------------------------------------------- |
24
24
  | Title | ✓ | The human **name only** (no `[Effort]`/number prefix) — the skill composes the board title. Concise, no jargon (`effort_title_lint`) |
25
25
  | Role | ✓ | `tech-lead` / `frontend` / … → `role:<role>` label + board Role field |
26
- | Flow | optional | Controlled-vocab flow (`EFFORT_FLOWS`) → `[Flow]` title tag + `flow:<flow>` label |
26
+ | Flow | optional | Controlled-vocab flow (`effort.flows` in the project config; `EFFORT_FLOWS` env overrides) → `[Flow]` title tag + `flow:<flow>` label |
27
27
  | Goal | ✓ | 1–2 lines — `## Goal` |
28
28
  | Scope | ✓ | The sub-issue DAG — `## Scope` (mark each parallel \| sequential) |
29
29
  | For agents | ✓ | Exact file paths / entry points — `## For agents` |