@jeiemgi/cckit 0.2.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.
Files changed (75) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/AGENTS.md +21 -8
  3. package/README.md +119 -20
  4. package/bin/cckit +42 -16
  5. package/cckit.config.json +1 -1
  6. package/commands/kit-doctor.md +3 -1
  7. package/commands/kit-update.md +9 -4
  8. package/kit.config.schema.json +25 -0
  9. package/package.json +1 -1
  10. package/scripts/annotate-setup.sh +7 -2
  11. package/scripts/capture-project-ids.sh +23 -10
  12. package/scripts/init-upgrade-test.sh +35 -1
  13. package/scripts/init.sh +43 -7
  14. package/scripts/kit-doctor.sh +185 -7
  15. package/scripts/kit-version-check-test.sh +36 -0
  16. package/scripts/kit-version-check.sh +19 -4
  17. package/scripts/kit-wire.sh +4 -1
  18. package/scripts/knowledge-lint.sh +4 -1
  19. package/scripts/lib/board-view-test.sh +54 -0
  20. package/scripts/lib/board-view.sh +80 -0
  21. package/scripts/lib/captain-test.sh +18 -0
  22. package/scripts/lib/captain.sh +92 -5
  23. package/scripts/lib/config-path-test.sh +47 -0
  24. package/scripts/lib/config-path.sh +29 -0
  25. package/scripts/lib/copilot.sh +9 -9
  26. package/scripts/lib/effort-dispatch-test.sh +25 -0
  27. package/scripts/lib/effort-flows-test.sh +55 -0
  28. package/scripts/lib/effort-metrics-test.sh +57 -0
  29. package/scripts/lib/effort-metrics.sh +19 -5
  30. package/scripts/lib/effort-ops-test.sh +110 -3
  31. package/scripts/lib/effort-ops.sh +480 -50
  32. package/scripts/lib/effort-parity-test.sh +128 -0
  33. package/scripts/lib/effort-slug-test.sh +87 -0
  34. package/scripts/lib/effort-slug.sh +104 -0
  35. package/scripts/lib/effort.sh +91 -1
  36. package/scripts/lib/gh-project-test.sh +95 -0
  37. package/scripts/lib/gh-project.sh +22 -7
  38. package/scripts/lib/git-remote-test.sh +57 -0
  39. package/scripts/lib/git-remote.sh +21 -0
  40. package/scripts/lib/kit-config-test.sh +37 -0
  41. package/scripts/lib/kit-config.sh +38 -13
  42. package/scripts/lib/kit-engine-test.sh +9 -0
  43. package/scripts/lib/kit-events.sh +5 -3
  44. package/scripts/lib/kit-gc-test.sh +88 -0
  45. package/scripts/lib/kit-gc.sh +136 -19
  46. package/scripts/lib/kit-local.sh +8 -1
  47. package/scripts/lib/kit-operate.sh +17 -2
  48. package/scripts/lib/next.sh +3 -3
  49. package/scripts/lib/plan-next-test.sh +87 -0
  50. package/scripts/lib/plan-next.sh +212 -0
  51. package/scripts/lib/project-scan.sh +7 -1
  52. package/scripts/lib/worktree-start.sh +12 -3
  53. package/scripts/lib/zsh-safety-test.sh +73 -0
  54. package/scripts/portable-test.sh +62 -20
  55. package/scripts/setup-labels.sh +13 -2
  56. package/scripts/showcase.sh +13 -4
  57. package/scripts/status-test.sh +63 -0
  58. package/scripts/status.sh +12 -4
  59. package/scripts/task-sync.sh +79 -10
  60. package/skills/kit-autopilot/SKILL.md +5 -0
  61. package/skills/{docs-writer → kit-docs-writer}/SKILL.md +2 -2
  62. package/skills/kit-effort-close/SKILL.md +52 -104
  63. package/skills/kit-effort-new/SKILL.md +40 -112
  64. package/skills/kit-effort-pr/SKILL.md +6 -2
  65. package/skills/kit-effort-start/SKILL.md +44 -46
  66. package/skills/kit-next/SKILL.md +4 -0
  67. package/skills/kit-plan-next/SKILL.md +82 -0
  68. package/skills/kit-task-start/SKILL.md +44 -55
  69. package/templates/CLAUDE.md.tmpl +1 -1
  70. package/templates/agents/auto-dev.md +1 -1
  71. package/templates/hooks/mempal_session_start.sh.tmpl +36 -2
  72. package/templates/rules/effort-model.md +43 -6
  73. package/templates/rules/mempalace.md +1 -0
  74. package/templates/rules/plan-next.md +58 -0
  75. package/templates/rules/task-management.md +1 -1
@@ -0,0 +1,63 @@
1
+ #!/usr/bin/env bash
2
+ # shellcheck shell=bash
3
+ # status-test.sh — regression for #142: `cckit status` board counters must be clean integers and
4
+ # never throw "integer expression expected". The bug: status fed `task-sync --llm` (TOON, not JSON)
5
+ # into `jq 'length'`, so the count became a concatenated value like "1\n0" that broke `[ … -gt 8 ]`.
6
+ # Hermetic: a fixture repo + a stubbed gh returning a known issue list. Run: bash scripts/status-test.sh
7
+ set -u
8
+ ROOT="$(cd "$(dirname "$0")/.." && pwd)"
9
+ fail=0
10
+ t() { if [ "$2" = "$3" ]; then echo "ok: $1"; else echo "FAIL: $1 -> got '[$2]' want '[$3]'"; fail=1; fi; }
11
+ has(){ case "$2" in *"$3"*) echo "ok: $1" ;; *) echo "FAIL: $1 -> output lacks '$3'"; fail=1 ;; esac; }
12
+ no() { case "$2" in *"$3"*) echo "FAIL: $1 -> output HAS '$3'"; fail=1 ;; *) echo "ok: $1" ;; esac; }
13
+ command -v jq >/dev/null 2>&1 || { echo "status-test: jq required — skipping"; exit 0; }
14
+ command -v git >/dev/null 2>&1 || { echo "status-test: git required" >&2; exit 1; }
15
+
16
+ tmp="$(mktemp -d)"; trap 'rm -rf "$tmp"' EXIT
17
+ fix="$tmp/proj"; mkdir -p "$fix"; ( cd "$fix" && git init -q )
18
+ printf '{"kitVersion":"9.9.9","project":{"name":"fix"},"github":{"repo":"octo/fixture","owner":"octo","baseBranch":"main"}}' > "$fix/cckit.config.json"
19
+
20
+ # Stub gh: `issue list` returns $GH_ISSUES (a JSON array file); everything else returns [].
21
+ stub="$tmp/bin"; mkdir -p "$stub"
22
+ cat > "$stub/gh" <<'SH'
23
+ #!/usr/bin/env bash
24
+ case "$1 $2" in
25
+ "issue list") cat "$GH_ISSUES" 2>/dev/null || echo '[]' ;;
26
+ *) echo "[]" ;;
27
+ esac
28
+ SH
29
+ chmod +x "$stub/gh"
30
+
31
+ run_status() { # stdout+stderr of `status.sh` against the fixture with the stub gh
32
+ ( cd "$fix" && KIT_CONFIG="$fix/cckit.config.json" PATH="$stub:$PATH" GH_ISSUES="$1" \
33
+ bash "$ROOT/scripts/status.sh" 2>&1 )
34
+ }
35
+
36
+ # 3 open issues, one blocked ("Blocked by" in the body).
37
+ cat > "$tmp/issues3.json" <<'JSON'
38
+ [ {"number":10,"title":"first","body":"plain"},
39
+ {"number":11,"title":"second","body":"Blocked by #10"},
40
+ {"number":12,"title":"third","body":""} ]
41
+ JSON
42
+ out3="$(run_status "$tmp/issues3.json")"
43
+ has "counts open + blocked correctly" "$out3" "open issues: 3 blocked: 1"
44
+ no "no integer-expression error" "$out3" "integer expression"
45
+ no "count is not the concatenated 1\\n0 bug" "$out3" "open issues: 1"
46
+
47
+ # 10 open issues -> the ">8 more" line must render (the integer test path that used to crash).
48
+ printf '[' > "$tmp/issues10.json"
49
+ for i in $(seq 1 10); do printf '%s{"number":%d,"title":"i%d","body":""}' "$([ "$i" -gt 1 ] && echo ,)" "$i" "$i"; done >> "$tmp/issues10.json"
50
+ printf ']' >> "$tmp/issues10.json"
51
+ out10="$(run_status "$tmp/issues10.json")"
52
+ has "counts 10 open" "$out10" "open issues: 10"
53
+ has "renders the '... and N more' line" "$out10" "and 2 more"
54
+ no "no integer-expression error (10)" "$out10" "integer expression"
55
+
56
+ # empty board -> 0/0, still clean.
57
+ echo '[]' > "$tmp/issues0.json"
58
+ out0="$(run_status "$tmp/issues0.json")"
59
+ has "empty board counts 0/0" "$out0" "open issues: 0 blocked: 0"
60
+ no "no integer-expression error (empty)" "$out0" "integer expression"
61
+
62
+ [ "$fail" -eq 0 ] && echo "ALL OK (status)" || echo "status: FAILURES"
63
+ exit "$fail"
package/scripts/status.sh CHANGED
@@ -16,17 +16,25 @@ sec() { if command -v ui_paint >/dev/null 2>&1; then ui_paint '1;36' "$1"; else
16
16
  sec "cckit status - $KIT_REPO (base ${KIT_BASE_BRANCH:-main})"
17
17
  hr
18
18
 
19
- # Board: open issues, blocked count (reuse the read-only board JSON).
19
+ # Board: open issues, blocked count. Fetch the board as a JSON ARRAY directly (#142) — the
20
+ # `task-sync --llm` output is TOON, not JSON, so piping it into `jq 'length'` mis-parses it (the
21
+ # leading `[N]` header reads as a 1-element array, then jq errors and the `|| echo 0` fallback
22
+ # concatenates onto the partial output, yielding a value like "1\n0" that breaks `[ "$open" -gt 8 ]`
23
+ # with "integer expression expected"). A clean JSON array keeps every count a single integer.
20
24
  sec "Board"
21
- board="$(bash "$ROOT/scripts/task-sync.sh" --llm 2>/dev/null || echo '[]')"
22
- if command -v jq >/dev/null 2>&1; then
25
+ if command -v jq >/dev/null 2>&1 && command -v gh >/dev/null 2>&1; then
26
+ board="$(gh issue list --repo "$KIT_REPO" --state open --limit 200 --json number,title,body 2>/dev/null \
27
+ | jq -c '[.[] | {number, title, blocked: ((.body // "") | test("Blocked by"))}]' 2>/dev/null || echo '[]')"
28
+ [ -n "$board" ] || board='[]'
23
29
  open="$(printf '%s' "$board" | jq 'length' 2>/dev/null || echo 0)"
24
30
  blocked="$(printf '%s' "$board" | jq '[.[]|select(.blocked)]|length' 2>/dev/null || echo 0)"
31
+ case "$open" in ''|*[!0-9]*) open=0 ;; esac # never let a non-integer reach the test below
32
+ case "$blocked" in ''|*[!0-9]*) blocked=0 ;; esac
25
33
  echo " open issues: $open blocked: $blocked"
26
34
  printf '%s' "$board" | jq -r '.[:8][] | " #\(.number) \(.title[0:56])"' 2>/dev/null || true
27
35
  [ "$open" -gt 8 ] && echo " ... and $((open - 8)) more (cckit sync)"
28
36
  else
29
- echo " (jq absent - run cckit sync)"
37
+ echo " (jq/gh absent - run cckit sync)"
30
38
  fi
31
39
  hr
32
40
 
@@ -4,6 +4,8 @@
4
4
  # ./scripts/task-sync.sh [--role <Name>] [--milestone <label>]
5
5
  set -euo pipefail
6
6
  source "$(dirname "$0")/lib/kit-config.sh" && load_kit_config
7
+ # Pure board-view render helpers (merge queue, stale flag, not-on-board flag, Project Status).
8
+ source "$(dirname "$0")/lib/board-view.sh"
7
9
 
8
10
  ROLE_FILTER=""; MS_FILTER=""
9
11
  while [[ $# -gt 0 ]]; do
@@ -18,12 +20,50 @@ done
18
20
  ISSUES=$(gh issue list --repo "$KIT_REPO" --state open --limit 200 \
19
21
  --json number,title,labels,milestone,assignees,updatedAt,body)
20
22
 
21
- # Structured output for agents: emit the open board as a JSON array and stop (--llm / CCKIT_OUTPUT).
23
+ # Structured output for agents: emit the open board and stop (--llm / CCKIT_OUTPUT). The board is a
24
+ # uniform list, so it goes out as TOON — far cheaper in tokens than JSON — via the shared encoder,
25
+ # which falls back to JSON for a non-uniform/empty result. labels + assignees are flattened to
26
+ # space-joined strings (and priority is lifted out) so every row is scalar-only and TOON-eligible.
22
27
  if [ "${CCKIT_OUTPUT:-human}" = "json" ]; then
23
- echo "$ISSUES" | jq -c '[.[] | {number, title, labels: [.labels[].name], milestone: (.milestone.title // null), blocked: ((.body // "") | test("Blocked by"))}]'
28
+ board="$(echo "$ISSUES" | jq -c '[.[] | {
29
+ number,
30
+ title,
31
+ priority: ([.labels[].name | select(startswith("priority:")) | sub("priority:";"")][0] // ""),
32
+ labels: ([.labels[].name] | join(" ")),
33
+ milestone: (.milestone.title // ""),
34
+ assignees: ([.assignees[].login] | join(" ")),
35
+ blocked: ((.body // "") | test("Blocked by"))
36
+ }]')"
37
+ # shellcheck source=/dev/null
38
+ . "$(dirname "$0")/lib/toon.sh"
39
+ printf '%s' "$board" | toon_encode
24
40
  exit 0
25
41
  fi
26
42
 
43
+ # Project Status map {"<number>":"<status>"} — from the Projects v2 board when it is enabled, so each
44
+ # issue row shows its board Status and we can flag issues that never got added (no-board-entry). A
45
+ # best-effort, config-guarded read: with projectsV2 off (or any hiccup) the map stays {} and every
46
+ # row shows "—" — the board view still renders, just without Status.
47
+ STATUS_MAP="{}"
48
+ if [ "${KIT_PROJECTS_V2:-false}" = "true" ] && [ -n "${KIT_PROJECT_NUMBER:-}" ] && [ -n "${KIT_OWNER:-}" ]; then
49
+ case "${KIT_PROJECT_OWNER_TYPE:-user}" in org|organization) _ROOT=organization ;; *) _ROOT=user ;; esac
50
+ STATUS_MAP="$(gh api graphql -f query="
51
+ query(\$login:String!,\$number:Int!){
52
+ $_ROOT(login:\$login){ projectV2(number:\$number){ items(first:200){ nodes{
53
+ content{ ... on Issue { number } ... on PullRequest { number } }
54
+ fieldValueByName(name:\"Status\"){ ... on ProjectV2ItemFieldSingleSelectValue { name } }
55
+ }}}}}" -f login="$KIT_OWNER" -F number="$KIT_PROJECT_NUMBER" 2>/dev/null \
56
+ | jq -c "[.data.${_ROOT}.projectV2.items.nodes[]
57
+ | select(.content.number != null)
58
+ | {key:(.content.number|tostring), value:(.fieldValueByName.name // \"—\")}]
59
+ | from_entries" 2>/dev/null || printf '{}')"
60
+ [ -n "$STATUS_MAP" ] || STATUS_MAP="{}"
61
+ fi
62
+
63
+ # Open PRs for the merge queue (fetched once; risk/size labels + draft/review state drive the order).
64
+ PRS_JSON="$(gh pr list --repo "$KIT_REPO" --state open --limit 100 \
65
+ --json number,title,labels,isDraft,headRefName,reviewDecision,mergeable 2>/dev/null || echo '[]')"
66
+
27
67
  echo "## Board — $KIT_REPO"
28
68
  echo ""
29
69
 
@@ -31,18 +71,19 @@ echo ""
31
71
  print_role() {
32
72
  local role="$1" slug rows
33
73
  slug=$(echo "$role" | tr '[:upper:]' '[:lower:]' | tr ' ' '-')
34
- rows=$(echo "$ISSUES" | jq -r --arg slug "role:$slug" --arg ms "$MS_FILTER" '
74
+ rows=$(echo "$ISSUES" | jq -r --arg slug "role:$slug" --arg ms "$MS_FILTER" --argjson st "$STATUS_MAP" '
35
75
  .[] | select(any(.labels[]; .name == $slug))
36
76
  | select($ms == "" or (.milestone.title // "") == $ms)
37
77
  | { n:.number, t:.title,
78
+ s:($st[(.number|tostring)] // "—"),
38
79
  p:([.labels[].name | select(startswith("priority:"))][0] // "—" | sub("priority:";"")),
39
80
  m:(.milestone.title // "—"),
40
81
  blocked:(.body // "" | test("Blocked by")) }
41
- | "| #\(.n) | \(.t) | \(.p) | \(.m) | \(if .blocked then "! blocked" else "—" end) |"')
82
+ | "| #\(.n) | \(.s) | \(.t) | \(.p) | \(.m) | \(if .blocked then "! blocked" else "—" end) |"')
42
83
  [[ -z "$rows" ]] && return
43
84
  echo "### $role"
44
- echo "| # | Title | Pri | Milestone | Flag |"
45
- echo "| - | ----- | --- | --------- | ---- |"
85
+ echo "| # | Status | Title | Pri | Milestone | Flag |"
86
+ echo "| - | ------ | ----- | --- | --------- | ---- |"
46
87
  echo "$rows"
47
88
  echo ""
48
89
  }
@@ -53,7 +94,35 @@ else
53
94
  while IFS= read -r role; do [[ -n "$role" ]] && print_role "$role"; done <<< "$KIT_ROLES"
54
95
  fi
55
96
 
56
- BLOCKED=$(echo "$ISSUES" | jq -r '[.[] | select((.body // "") | test("Blocked by"))] | length')
57
- echo "**Blocked:** ${BLOCKED} item(s)"
58
- STALE=$(echo "$ISSUES" | jq -r '[.[] | .updatedAt] | length')
59
- echo "**Open total:** ${STALE}"
97
+ # ── Flags: blocked / not-on-board / stale ───────────────────────────────────────────────────────
98
+ BLOCKED_LIST=$(echo "$ISSUES" | jq -r '[.[] | select((.body // "") | test("Blocked by")) | "#\(.number)"] | join(" ")')
99
+ NOT_ON_BOARD=$(board_not_on_board "$ISSUES" "$STATUS_MAP")
100
+ STALE_LIST=$(board_stale_list "$ISSUES" 14)
101
+ echo "**Blocked:** ${BLOCKED_LIST:-none ✓}"
102
+ # Only surface no-board-entry when a board is actually configured (otherwise every issue trivially
103
+ # has no entry — noise, not signal).
104
+ if [ "${KIT_PROJECTS_V2:-false}" = "true" ]; then
105
+ echo "**Not on board:** ${NOT_ON_BOARD:-none ✓}"
106
+ fi
107
+ echo "**Stale (>14 days no activity):** ${STALE_LIST:-none ✓}"
108
+ OPEN_TOTAL=$(echo "$ISSUES" | jq -r 'length')
109
+ echo "**Open total:** ${OPEN_TOTAL}"
110
+ echo ""
111
+
112
+ # ── Merge Queue: open PRs ordered ready → draft → blocked (risk asc, size asc) ───────────────────
113
+ board_merge_queue "$PRS_JSON"
114
+
115
+ # ── Optional local-model digest — only when the local endpoint is alive (zero API cost) ──────────
116
+ # A 3–5 line executive read of the board (merge order, blockers, staleness). Best-effort: absent or
117
+ # offline local model → nothing appended, the board view above stands on its own.
118
+ if [ -f "$(dirname "$0")/lib/kit-local.sh" ]; then
119
+ # shellcheck source=/dev/null
120
+ if source "$(dirname "$0")/lib/kit-local.sh" 2>/dev/null && kit_local_alive 2>/dev/null; then
121
+ echo ""
122
+ echo "### Local digest"
123
+ kit_local_chat \
124
+ "You are a release captain. In 3–5 lines, summarize the merge order, blockers, and staleness for a busy maintainer." \
125
+ "Blocked: ${BLOCKED_LIST:-none}. Stale: ${STALE_LIST:-none}. Merge queue follows the ready→draft→blocked order." \
126
+ 2>/dev/null || echo "_(local digest unavailable)_"
127
+ fi
128
+ fi
@@ -15,6 +15,11 @@ scripts; it never reimplements looping or orchestration.
15
15
  | **objective** | one long objective on the current branch | the built-in `/loop` + caps + a stop-check |
16
16
  | **plan** | the planned, file-disjoint set of efforts/flows in parallel | `kit effort plan` + `orchestrate.sh` + `orchestrate-watch.sh` |
17
17
 
18
+ > Need the plan first? `/kit-plan-next` (`cckit plan-next`) proposes what to build next from the
19
+ > kit's current capabilities, then hands a chosen item to `/kit-effort-new` — the effort autopilot
20
+ > later drives. Keep that planner output with the human/orchestrator; never feed it into a monitored
21
+ > agent's context (context-anxiety rule).
22
+
18
23
  ## Established-plan autonomy (the default)
19
24
 
20
25
  **When the plan is already approved, the captain DECIDES + MERGES + CONTINUES — it does not bounce
@@ -1,5 +1,5 @@
1
1
  ---
2
- name: docs-writer
2
+ name: kit-docs-writer
3
3
  description: >
4
4
  Write and edit end-user documentation in the house voice: kind but robust, ADHD-oriented and
5
5
  scannable, ZERO analogies, beginner-inclusive but expert-skippable. Encodes the page template
@@ -15,7 +15,7 @@ metadata:
15
15
  version: 1.0.0
16
16
  ---
17
17
 
18
- # docs-writer — the house voice for human documentation
18
+ # kit-docs-writer — the house voice for human documentation
19
19
 
20
20
  Documentation here is read by people with low software knowledge. It must still be correct and
21
21
  complete for experts. The whole skill is one promise: **a beginner can follow the flow, and an
@@ -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.