@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.
@@ -0,0 +1,220 @@
1
+ #!/usr/bin/env bash
2
+ # shellcheck shell=bash
3
+ # kit-msg.sh — session mail (#175): a MACHINE-GLOBAL filesystem mailbox so parallel sessions reach
4
+ # each other mid-flight — across projects or within one — instead of waiting for a resume.
5
+ # Delivery is hook-driven (see templates/hooks/kit-mail-check.sh.tmpl): PostToolUse injects unread
6
+ # mail between a working session's tool calls (the steer), UserPromptSubmit/SessionStart cover
7
+ # human-driven and cold-start delivery, and Stop blocks a finishing session ONLY for unread
8
+ # --steer messages.
9
+ #
10
+ # msg_send <target> [--steer] <text…> target: <branch> | all (this project)
11
+ # <owner/repo>:<branch> | <owner/repo>:all
12
+ # msg_read [--peek] print + consume this session's unread mail
13
+ # msg_list inventory of every mailbox on this machine
14
+ # msg_hook_check <event> hook driver: emit the event's JSON (silent = no mail)
15
+ #
16
+ # Identity: a session is (project, branch) — project from the git remote slug (owner/repo, the
17
+ # git-remote.sh resolver), branch from HEAD. State lives at ~/.cckit/mail/<project>/<branch>
18
+ # (override root with KIT_MAIL_DIR; "/" encoded as "+" — the worktree-dir precedent). A direct
19
+ # message is read-ONCE (new/ → read/); a broadcast (`all`) is project-scoped, hits each session
20
+ # exactly once via a per-branch seen ledger, and expires after 7 days.
21
+
22
+ # Lazily bring in the shared remote-slug resolver (no-op if the caller already sourced it).
23
+ _msg_source_remote() {
24
+ command -v git_remote_slug >/dev/null 2>&1 && return 0
25
+ local d; d="$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" && pwd)"
26
+ # shellcheck source=/dev/null
27
+ [ -f "$d/git-remote.sh" ] && . "$d/git-remote.sh"
28
+ }
29
+
30
+ _msg_home() { printf '%s' "${KIT_MAIL_DIR:-$HOME/.cckit/mail}"; }
31
+ _msg_encode() { printf '%s' "$1" | tr '/' '+'; }
32
+
33
+ # The invoking session's project id: the remote slug (owner/repo), else the toplevel dir name.
34
+ _msg_proj() {
35
+ _msg_source_remote
36
+ local s=""
37
+ command -v git_remote_slug >/dev/null 2>&1 && s="$(git_remote_slug "$PWD" 2>/dev/null || true)"
38
+ [ -n "$s" ] || s="$(basename "$(git rev-parse --show-toplevel 2>/dev/null || echo no-project)")"
39
+ printf '%s' "$s"
40
+ }
41
+ _msg_branch() { git rev-parse --abbrev-ref HEAD 2>/dev/null; }
42
+
43
+ # _msg_parse <target> — split "[project:]branch-or-all" into PROJ + BOX (current project default).
44
+ _msg_parse() {
45
+ case "$1" in
46
+ *:*) _MSG_PROJ="${1%%:*}"; _MSG_BOX="${1#*:}" ;;
47
+ *) _MSG_PROJ="$(_msg_proj)"; _MSG_BOX="$1" ;;
48
+ esac
49
+ [ -n "$_MSG_PROJ" ] && [ -n "$_MSG_BOX" ]
50
+ }
51
+
52
+ # msg_send <target> [--steer] <text…>
53
+ msg_send() {
54
+ local target="${1:-}"; shift || true
55
+ local steer=0
56
+ [ "${1:-}" = "--steer" ] && { steer=1; shift; }
57
+ local text="$*"
58
+ [ -n "$target" ] && [ -n "$text" ] || { echo 'msg_send: usage: cckit msg send <branch|all|project:branch|project:all> [--steer] "<text>"' >&2; return 1; }
59
+ _msg_parse "$target" || { echo "msg_send: bad target '$target'" >&2; return 1; }
60
+ local from_proj from_branch
61
+ from_proj="$(_msg_proj)"; from_branch="$(_msg_branch)"; from_branch="${from_branch:-unknown}"
62
+ local box="$(_msg_home)/$(_msg_encode "$_MSG_PROJ")/$(_msg_encode "$_MSG_BOX")/new"
63
+ # A typo'd target would silently create a dead mailbox (hcom hard-fails here; we warn) — flag a
64
+ # first-time mailbox so a misaddressed steer doesn't just vanish.
65
+ [ -d "$(dirname "$box")" ] || [ "$_MSG_BOX" = "all" ] \
66
+ || echo " ⚠ new mailbox $_MSG_PROJ:$_MSG_BOX — no session has mail here yet; check the target if you expected one (cckit msg list)" >&2
67
+ mkdir -p "$box" || return 1
68
+ local kind="note"; [ "$steer" = 1 ] && kind="steer"
69
+ # epoch-$$ alone collides for two sends in the same second from one shell — the second message
70
+ # would silently OVERWRITE the first. $RANDOM + an existence check makes the name unique.
71
+ local f
72
+ while :; do
73
+ f="$box/$(date +%s)-$$-${RANDOM}-$kind-from-$(_msg_encode "$from_proj")~$(_msg_encode "$from_branch").md"
74
+ [ -e "$f" ] || break
75
+ done
76
+ {
77
+ printf -- '---\nfrom: %s (%s)\nto: %s:%s\nkind: %s\nsent: %s\n---\n' \
78
+ "$from_branch" "$from_proj" "$_MSG_PROJ" "$_MSG_BOX" "$kind" "$(date -u +%Y-%m-%dT%H:%M:%SZ)"
79
+ printf '%s\n' "$text"
80
+ } > "$f" || return 1
81
+ echo " ✓ mail → $_MSG_PROJ:$_MSG_BOX ($kind): $(printf '%.60s' "$text")" >&2
82
+ }
83
+
84
+ # _msg_gc — prune this project's broadcasts older than 7 days (stale ledger entries are harmless).
85
+ _msg_gc() {
86
+ local d="$(_msg_home)/$(_msg_encode "$(_msg_proj)")/all/new"
87
+ [ -d "$d" ] || return 0
88
+ find "$d" -name '*.md' -type f -mtime +7 -delete 2>/dev/null || true
89
+ }
90
+
91
+ # _msg_unread — this session's unread message files (direct new/ + unseen broadcasts), one path
92
+ # per line, oldest first. Consuming is the caller's job (_msg_consume).
93
+ _msg_unread() {
94
+ _msg_gc
95
+ local proj branch pdir seen f base
96
+ proj="$(_msg_encode "$(_msg_proj)")"; branch="$(_msg_encode "$(_msg_branch)")"
97
+ [ -n "$branch" ] || return 0
98
+ pdir="$(_msg_home)/$proj"
99
+ [ -d "$pdir" ] || return 0
100
+ # direct
101
+ ls "$pdir/$branch/new"/*.md 2>/dev/null
102
+ # broadcast: anything in all/new not yet in this branch's seen ledger
103
+ seen="$pdir/.seen/$branch"
104
+ for f in "$pdir/all/new"/*.md; do
105
+ [ -f "$f" ] || continue
106
+ base="$(basename "$f")"
107
+ [ -f "$seen" ] && grep -qxF "$base" "$seen" && continue
108
+ printf '%s\n' "$f"
109
+ done
110
+ }
111
+
112
+ # _msg_consume <file> — mark one message delivered: direct → moved to read/, broadcast → ledgered.
113
+ _msg_consume() {
114
+ local f="$1" pdir branch
115
+ pdir="$(_msg_home)/$(_msg_encode "$(_msg_proj)")"; branch="$(_msg_encode "$(_msg_branch)")"
116
+ case "$f" in
117
+ "$pdir/all/new/"*)
118
+ mkdir -p "$pdir/.seen"
119
+ printf '%s\n' "$(basename "$f")" >> "$pdir/.seen/$branch" ;;
120
+ *)
121
+ mkdir -p "$(dirname "$f")/../read"
122
+ mv "$f" "$(dirname "$f")/../read/" 2>/dev/null || true ;;
123
+ esac
124
+ }
125
+
126
+ # msg_read [--peek] — print unread mail; consume unless --peek.
127
+ msg_read() {
128
+ local peek=0; [ "${1:-}" = "--peek" ] && peek=1
129
+ local any=0 f
130
+ while IFS= read -r f; do
131
+ [ -n "$f" ] || continue
132
+ any=1
133
+ echo "── $(basename "$f")"
134
+ cat "$f"
135
+ [ "$peek" = 1 ] || _msg_consume "$f"
136
+ done <<EOF_UNREAD
137
+ $(_msg_unread)
138
+ EOF_UNREAD
139
+ [ "$any" = 1 ] || echo "no mail for $(_msg_proj):$(_msg_branch)"
140
+ }
141
+
142
+ # msg_list — machine-wide inventory (unread counts per project:mailbox).
143
+ msg_list() {
144
+ local home d n proj
145
+ home="$(_msg_home)"
146
+ [ -d "$home" ] || { echo "no mail yet"; return 0; }
147
+ for d in "$home"/*/*/new; do
148
+ [ -d "$d" ] || continue
149
+ n="$(ls "$d"/*.md 2>/dev/null | wc -l | tr -d ' ')"
150
+ proj="$(basename "$(dirname "$(dirname "$d")")")"
151
+ [ "$n" -gt 0 ] && echo " $proj:$(basename "$(dirname "$d")"): $n unread"
152
+ done
153
+ return 0
154
+ }
155
+
156
+ # _msg_json_escape — minimal JSON string escaping (jq when present, sed fallback).
157
+ _msg_json_escape() {
158
+ if command -v jq >/dev/null 2>&1; then jq -Rs . ; else
159
+ sed -e 's/\\/\\\\/g' -e 's/"/\\"/g' | awk 'BEGIN{printf "\""} {printf "%s\\n", $0} END{printf "\""}'
160
+ fi
161
+ }
162
+
163
+ # msg_hook_check <event> — the hook driver. Silent (exit 0, no output) when there is no mail, so
164
+ # the hook adds zero noise on the hot path. With mail, emits the event's JSON:
165
+ # PostToolUse | UserPromptSubmit | SessionStart | PreToolUse → hookSpecificOutput.additionalContext
166
+ # Stop → decision:block with the mail as reason — ONLY for steer-marked mail (a note never traps
167
+ # a finishing session). KIT_MAIL_STOP_POLL=<seconds> (default 0) makes the Stop pass WAIT
168
+ # that long for a steer to arrive before letting the session end — near-real-time steering
169
+ # of an idle session, no daemon (the hcom long-poll trick, opt-in).
170
+ # Ordering: the JSON is emitted BEFORE the mail is consumed — a hook killed mid-run redelivers
171
+ # instead of losing the message (at-least-once, like hcom's two-phase ack). Delivery is capped at
172
+ # KIT_MAIL_MAX_PER_DELIVERY (default 20) messages per injection; the rest ride the next hook fire.
173
+ msg_hook_check() {
174
+ local event="${1:-}" f body="" steer_only=0 count=0 max="${KIT_MAIL_MAX_PER_DELIVERY:-20}"
175
+ [ -n "$event" ] || { echo "msg_hook_check: <event> required" >&2; return 1; }
176
+ [ "$event" = "Stop" ] && steer_only=1
177
+
178
+ _msg_hook_pick() { # fill _MSG_PICKED + body from current unread (respects steer filter + cap)
179
+ _MSG_PICKED=""
180
+ while IFS= read -r f; do
181
+ [ -n "$f" ] || continue
182
+ [ "$count" -lt "$max" ] || break
183
+ if [ "$steer_only" = 1 ]; then
184
+ case "$(basename "$f")" in *-steer-from-*) : ;; *) continue ;; esac
185
+ fi
186
+ body="$body$(cat "$f")
187
+ "
188
+ _MSG_PICKED="$_MSG_PICKED$f
189
+ "
190
+ count=$((count + 1))
191
+ done <<EOF_UNREAD
192
+ $(_msg_unread)
193
+ EOF_UNREAD
194
+ }
195
+
196
+ _msg_hook_pick
197
+ # Opt-in Stop long-poll: no steer yet → wait up to KIT_MAIL_STOP_POLL seconds for one to land.
198
+ if [ "$count" -eq 0 ] && [ "$event" = "Stop" ] && [ "${KIT_MAIL_STOP_POLL:-0}" -gt 0 ] 2>/dev/null; then
199
+ local waited=0
200
+ while [ "$count" -eq 0 ] && [ "$waited" -lt "${KIT_MAIL_STOP_POLL}" ]; do
201
+ sleep 1; waited=$((waited + 1)); _msg_hook_pick
202
+ done
203
+ fi
204
+ [ "$count" -gt 0 ] || return 0
205
+
206
+ local msg="SESSION MAIL (cckit msg): a parallel session sent you the message(s) below. If one is kind: steer, act on it BEFORE continuing your current plan.
207
+ $body"
208
+ local esc; esc="$(printf '%s' "$msg" | _msg_json_escape)"
209
+ if [ "$event" = "Stop" ]; then
210
+ printf '{"decision":"block","reason":%s}\n' "$esc"
211
+ else
212
+ printf '{"hookSpecificOutput":{"hookEventName":"%s","additionalContext":%s}}\n' "$event" "$esc"
213
+ fi
214
+ # consume AFTER emit (see header) — read the picked list back without a subshell.
215
+ while IFS= read -r f; do
216
+ [ -n "$f" ] && _msg_consume "$f"
217
+ done <<EOF_PICKED
218
+ $_MSG_PICKED
219
+ EOF_PICKED
220
+ }
@@ -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
@@ -0,0 +1,42 @@
1
+ #!/usr/bin/env bash
2
+ # shellcheck shell=bash
3
+ # version-bump-test.sh — #173: version-bump.sh --write is the ONE version stamper, and every
4
+ # version surface it owns must agree. The release path (publish.sh) used an inline jq that wrote
5
+ # only cckit.config.json.kitVersion, shipping releases whose .claude-plugin/plugin.json and
6
+ # package.json lagged behind. Guards: (1) vb_write stamps all four files, (2) publish.sh calls the
7
+ # shared bumper (no second implementation), (3) the repo's four version files currently agree.
8
+ # Run: bash scripts/lib/version-bump-test.sh
9
+ set -u
10
+ ROOT="$(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 "version-bump-test: jq required" >&2; exit 1; }
14
+
15
+ # (1) vb_write stamps every surface — exercised against a throwaway copy of the four files.
16
+ tmp="$(mktemp -d)"; trap 'rm -rf "$tmp"' EXIT
17
+ mkdir -p "$tmp/.claude-plugin" "$tmp/docs-site" "$tmp/scripts/lib"
18
+ echo '{"kitVersion":"0.0.1"}' > "$tmp/cckit.config.json"
19
+ echo '{"version":"0.0.1"}' > "$tmp/.claude-plugin/plugin.json"
20
+ echo '{"version":"0.0.1"}' > "$tmp/package.json"
21
+ echo '{"version":"0.0.1"}' > "$tmp/docs-site/package.json"
22
+ cp "$ROOT/scripts/lib/version-bump.sh" "$tmp/scripts/lib/version-bump.sh"
23
+ (cd "$tmp" && bash scripts/lib/version-bump.sh --write 9.9.9 >/dev/null 2>&1)
24
+ t "vb_write stamps cckit.config.json" "$(jq -r .kitVersion "$tmp/cckit.config.json")" "9.9.9"
25
+ t "vb_write stamps plugin.json" "$(jq -r .version "$tmp/.claude-plugin/plugin.json")" "9.9.9"
26
+ t "vb_write stamps package.json" "$(jq -r .version "$tmp/package.json")" "9.9.9"
27
+ t "vb_write stamps docs-site/package.json" "$(jq -r .version "$tmp/docs-site/package.json")" "9.9.9"
28
+
29
+ # (2) publish.sh delegates to the shared bumper — a reintroduced inline kitVersion jq is the drift.
30
+ t "publish.sh calls version-bump.sh --write" \
31
+ "$(grep -c 'version-bump.sh. --write' "$ROOT/scripts/publish.sh")" "1"
32
+ t "publish.sh has no inline kitVersion bump" \
33
+ "$(grep -c 'kitVersion=' "$ROOT/scripts/publish.sh")" "0"
34
+
35
+ # (3) the repo's four version surfaces agree RIGHT NOW (catches a drifted release after the fact).
36
+ v="$(jq -r .kitVersion "$ROOT/cckit.config.json")"
37
+ t "plugin.json matches kitVersion ($v)" "$(jq -r .version "$ROOT/.claude-plugin/plugin.json")" "$v"
38
+ t "package.json matches kitVersion ($v)" "$(jq -r .version "$ROOT/package.json")" "$v"
39
+ t "docs-site/package.json matches kitVersion ($v)" "$(jq -r .version "$ROOT/docs-site/package.json")" "$v"
40
+
41
+ [ "$fail" -eq 0 ] && echo "ALL OK (version-bump)"
42
+ exit "$fail"
@@ -84,7 +84,7 @@ yes "gc resolves the invoking repo" "$(cat "$GH_REPO_LOG")" "$FIX_REPO"
84
84
  # A new verb that is neither exercised nor listed here fails the harness — forcing a coverage
85
85
  # decision. SKIP holds verbs that mutate, need args, read stdin, are interactive, or act on the
86
86
  # install itself (not the invoking project's board) — deliberately not driven here.
87
- SKIP="adopt autopilot close commands completions contribute copilot debug digest effort encode-context handoff help init install migrate orchestrate pr release render resume start ui update version watch"
87
+ SKIP="adopt autopilot close commands completions contribute copilot debug digest effort encode-context handoff help init install migrate msg orchestrate pr release render resume start ui update version watch"
88
88
  classified() { case " $EXERCISE $SKIP " in *" $1 "*) return 0 ;; *) return 1 ;; esac; }
89
89
  for v in $("$CCKIT" commands); do
90
90
  classified "$v" || { echo "FAIL: verb '$v' is unclassified — add it to EXERCISE (read-only, assert no own-repo leak) or SKIP in portable-test.sh"; fail=1; }
@@ -40,12 +40,17 @@ if [ "$PUBLISH" = 1 ]; then
40
40
  command -v gh >/dev/null || { echo "x gh required" >&2; exit 1; }
41
41
  fi
42
42
 
43
- # 1. Stamp version, tag, and cut the GitHub release (creates the tarball).
44
- run bash -c "cd '$root' && command -v jq >/dev/null && jq '.kitVersion=\"$VERSION\"' cckit.config.json > .v.tmp && mv .v.tmp cckit.config.json || true"
43
+ # 1. Stamp the version on ALL FOUR version surfaces via the ONE shared bumper (#173 — an inline jq
44
+ # here used to write only cckit.config.json.kitVersion, shipping releases whose
45
+ # .claude-plugin/plugin.json and package.json lagged behind and made `cckit update` report a
46
+ # version drift on a fully current install), then tag and cut the GitHub release.
47
+ run bash "$root/scripts/lib/version-bump.sh" --write "$VERSION"
45
48
  run git -C "$root" add -A
46
49
  run git -C "$root" commit -m "release: $tag"
47
- run git -C "$root" tag "$tag"
48
- run git -C "$root" push origin main --tags
50
+ # -m makes the tag annotated, which also satisfies tag.gpgsign=true configs — a bare `git tag`
51
+ # aborts there with "fatal: no tag message?" and kills the publish mid-run (#167).
52
+ run git -C "$root" tag -m "$tag" "$tag"
53
+ run git -C "$root" push origin main "$tag"
49
54
  run gh release create "$tag" --repo "$repo" --title "$tag" --generate-notes
50
55
 
51
56
  # 2. Compute the tarball sha256 for the stable Homebrew formula.
@@ -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` |