@jeiemgi/cckit 0.7.0 → 0.8.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 +15 -4
  3. package/README.md +11 -3
  4. package/bin/cckit +86 -7
  5. package/cckit.config.json +1 -1
  6. package/kit.config.schema.json +43 -2
  7. package/package.json +1 -1
  8. package/scripts/autopilot-test.sh +68 -0
  9. package/scripts/autopilot.sh +16 -10
  10. package/scripts/check.sh +14 -1
  11. package/scripts/copilot-loop-test.sh +3 -0
  12. package/scripts/guard-raw-git-ops-test.sh +65 -0
  13. package/scripts/init.sh +68 -8
  14. package/scripts/lib/agent-profile-test.sh +151 -0
  15. package/scripts/lib/agent-profile.sh +195 -0
  16. package/scripts/lib/agent-resolve-test.sh +156 -0
  17. package/scripts/lib/agent-resolve.sh +177 -0
  18. package/scripts/lib/branch-owner-test.sh +99 -0
  19. package/scripts/lib/branch-owner.sh +194 -0
  20. package/scripts/lib/captain-test.sh +86 -0
  21. package/scripts/lib/captain.sh +142 -7
  22. package/scripts/lib/contribute-root-test.sh +40 -0
  23. package/scripts/lib/contribute-root.sh +22 -0
  24. package/scripts/lib/effort-ops-test.sh +42 -2
  25. package/scripts/lib/effort-ops.sh +157 -14
  26. package/scripts/lib/effort-parity-test.sh +5 -3
  27. package/scripts/lib/effort.sh +38 -14
  28. package/scripts/lib/hook-refresh-test.sh +65 -0
  29. package/scripts/lib/hook-refresh.sh +62 -0
  30. package/scripts/lib/kit-config.sh +6 -0
  31. package/scripts/lib/kit-gc-test.sh +178 -1
  32. package/scripts/lib/kit-gc.sh +233 -55
  33. package/scripts/lib/kit-task-ops-test.sh +15 -0
  34. package/scripts/lib/kit-task-ops.sh +65 -21
  35. package/scripts/lib/kto-task-pr-merge-test.sh +72 -0
  36. package/scripts/lib/kto-task-pr-test.sh +59 -0
  37. package/scripts/lib/orchestration-runtime-test.sh +142 -0
  38. package/scripts/lib/orchestration-runtime.sh +171 -0
  39. package/scripts/lib/review-stage-test.sh +241 -0
  40. package/scripts/lib/review-stage.sh +259 -0
  41. package/scripts/lib/stage-receipt-test.sh +252 -0
  42. package/scripts/lib/stage-receipt.sh +442 -0
  43. package/scripts/lib/test-env-test.sh +25 -0
  44. package/scripts/lib/test-env.sh +30 -0
  45. package/scripts/lib/worker-brief-test.sh +120 -0
  46. package/scripts/lib/worker-brief.sh +185 -0
  47. package/scripts/lib/worktree-ports-test.sh +146 -0
  48. package/scripts/lib/worktree-start.sh +137 -7
  49. package/scripts/lib/zsh-safety-test.sh +67 -0
  50. package/scripts/orchestrate.sh +124 -22
  51. package/scripts/portable-test.sh +22 -1
  52. package/scripts/review-lint-baseline.txt +28 -0
  53. package/scripts/review-lint-test.sh +271 -0
  54. package/scripts/review-lint.sh +259 -0
  55. package/scripts/review-rules.conf +55 -0
  56. package/scripts/setup-labels.sh +21 -1
  57. package/scripts/skill-frontmatter-baseline.txt +24 -0
  58. package/scripts/skill-frontmatter-lint-test.sh +156 -0
  59. package/scripts/skill-frontmatter-lint.sh +182 -0
  60. package/scripts/task-sync.sh +8 -0
  61. package/scripts/test.sh +10 -1
  62. package/skills/kit-autopilot/SKILL.md +13 -1
  63. package/skills/kit-cleanup/SKILL.md +5 -3
  64. package/skills/kit-contribute/SKILL.md +6 -5
  65. package/skills/kit-effort-close/SKILL.md +8 -3
  66. package/skills/kit-effort-pr/SKILL.md +16 -95
  67. package/skills/kit-gc/SKILL.md +15 -10
  68. package/skills/kit-security-sweep/SKILL.md +4 -6
  69. package/skills/kit-ship/SKILL.md +1 -1
  70. package/skills/kit-task-pr/SKILL.md +2 -0
  71. package/templates/hooks/guard-raw-git-ops.sh.tmpl +180 -0
  72. package/templates/rules/branch-naming.md +6 -0
  73. package/templates/rules/effort-model.md +3 -0
  74. package/templates/rules/naming-and-ids.md +4 -1
  75. package/templates/settings/settings.json.tmpl +4 -2
@@ -0,0 +1,182 @@
1
+ #!/usr/bin/env bash
2
+ # skill-frontmatter-lint.sh — context-budget guardrail for skill frontmatter (kit-owned).
3
+ #
4
+ # WHY: Claude Code concatenates a skill's `description` + `when_to_use` into the always-loaded
5
+ # skill listing. Both fields sit in every session's context whether or not the skill is ever
6
+ # invoked — only the SKILL.md *body* is lazy. Unbudgeted, these fields grow into second bodies:
7
+ # the listing text is rent paid on every turn, and past a harness cap the tail is silently
8
+ # truncated, so an over-long field costs tokens while delivering nothing.
9
+ #
10
+ # WHAT: measures description + when_to_use per skill and enforces a RATCHET, not a hard cap —
11
+ # today's over-budget skills are recorded in a baseline and allowed to stay as they are, but
12
+ # nothing may grow past its recorded size and no NEW skill may land over budget. That stops
13
+ # regrowth without forcing a rewrite of existing skills.
14
+ #
15
+ # scripts/skill-frontmatter-lint.sh lint against the baseline (the gate)
16
+ # scripts/skill-frontmatter-lint.sh --report print every skill's cost, sorted; never fails
17
+ # scripts/skill-frontmatter-lint.sh --update rewrite the baseline from current sizes
18
+ #
19
+ # Baseline: scripts/skill-frontmatter-baseline.txt ("<skill> <bytes>" per line; # comments ok)
20
+ # bash 3.2 compatible (no associative arrays, no mapfile).
21
+ set -uo pipefail
22
+
23
+ # LOCALE — pinned, because the measurement changes with it. `${#s}` counts CHARACTERS under a UTF-8
24
+ # locale and BYTES under C/POSIX, and skill descriptions are full of em-dashes and `·`. A baseline
25
+ # generated under one and checked under the other makes the ratchet fire on skills nobody touched:
26
+ # under LC_ALL=C this repo's UTF-8 baseline reported 15 skills as "grown". CI only looked green
27
+ # because ubuntu-latest happens to export LANG=C.UTF-8, which test.yml never pins.
28
+ #
29
+ # Bytes win: every environment can produce them, and no locale needs to be installed to reproduce a
30
+ # number. The budget is therefore a byte budget, and an em-dash costs the three bytes it occupies.
31
+ LC_ALL=C
32
+ export LC_ALL
33
+
34
+ ROOT="$(cd "$(dirname "$0")/.." && pwd)"
35
+ cd "$ROOT"
36
+
37
+ # SKILL ROOTS — both layouts, because this lint SHIPS to consumer projects. The kit's own skills
38
+ # live in `skills/`; `init.sh` scaffolds a project's to `.claude/skills/<name>/SKILL.md`. Hard-coding
39
+ # `skills` made the installed copy a permanent no-op: it exited 0 with "nothing to lint" in every
40
+ # project it was ever shipped to, so the context budget was enforced only in the kit's own repo.
41
+ SKILL_ROOTS=""
42
+ for _root in skills .claude/skills; do
43
+ [ -d "$_root" ] && SKILL_ROOTS="$SKILL_ROOTS $_root"
44
+ done
45
+ BASELINE="scripts/skill-frontmatter-baseline.txt"
46
+
47
+ # Budgets in bytes (see the LC_ALL note above). A skill at or under LISTING_BUDGET is always fine; above it, the skill
48
+ # must be baselined and must not have grown. Chosen from the observed distribution: the terse
49
+ # task verbs (kit-task-pr, kit-task-pr-merge, kit-task-new) all land comfortably under 300.
50
+ LISTING_BUDGET="${KIT_SKILL_LISTING_BUDGET:-500}"
51
+
52
+ FAIL=0
53
+ err() { echo "x $1"; FAIL=1; }
54
+ ok() { echo "ok $1"; }
55
+ note() { echo " $1"; }
56
+
57
+ # ---- frontmatter field extraction ------------------------------------------
58
+ # Prints the value of a top-level frontmatter field, including folded/block-scalar continuation
59
+ # lines (`when_to_use: |`), stopping at the next top-level key or the closing `---`.
60
+ fm_field() {
61
+ awk -v key="$2" '
62
+ NR == 1 && $0 == "---" { infm = 1; next }
63
+ !infm { exit }
64
+ $0 == "---" { exit }
65
+ {
66
+ if (index($0, key ":") == 1) {
67
+ grab = 1
68
+ sub("^" key ":[ \t]*", "")
69
+ if (length($0)) print
70
+ next
71
+ }
72
+ if (grab && $0 ~ /^[A-Za-z_][A-Za-z0-9_-]*:/) { grab = 0 }
73
+ if (grab) { sub(/^[ \t]+/, ""); sub(/[ \t]+$/, ""); print }
74
+ }
75
+ ' "$1"
76
+ }
77
+
78
+ # Listing cost = the bytes the harness actually keeps resident, newlines collapsed.
79
+ listing_chars() {
80
+ local f="$1" d w
81
+ d="$(fm_field "$f" description | tr -d '\n')"
82
+ w="$(fm_field "$f" when_to_use | tr -d '\n')"
83
+ printf '%s' "${#d} ${#w} $(( ${#d} + ${#w} ))"
84
+ }
85
+
86
+ baseline_for() {
87
+ [ -f "$BASELINE" ] || { echo ""; return; }
88
+ grep -v '^[[:space:]]*#' "$BASELINE" 2>/dev/null \
89
+ | awk -v s="$1" '$1 == s { print $2; exit }'
90
+ }
91
+
92
+ MODE="${1:-lint}"
93
+
94
+ # The one place the baseline filename is spelled. init.sh asks for it rather than reconstructing
95
+ # it — it used to guess "<lint>-baseline.txt", which for this lint is a file that never exists, so
96
+ # its "seed once, never regenerate" guard never matched and every upgrade silently re-baselined.
97
+ if [ "$MODE" = "--baseline-path" ]; then
98
+ printf '%s\n' "$BASELINE"
99
+ exit 0
100
+ fi
101
+
102
+ if [ -z "$SKILL_ROOTS" ]; then
103
+ echo "skill-frontmatter-lint: no skills/ or .claude/skills/ directory — nothing to lint"
104
+ exit 0
105
+ fi
106
+
107
+ # ---- collect ----------------------------------------------------------------
108
+ rows="" # "<total> <desc> <when> <skill>" per line
109
+ total_all=0
110
+ count=0
111
+ while IFS= read -r f; do
112
+ [ -n "$f" ] || continue
113
+ skill="$(basename "$(dirname "$f")")"
114
+ set -- $(listing_chars "$f")
115
+ d="$1"; w="$2"; t="$3"
116
+ rows="${rows}${t} ${d} ${w} ${skill}
117
+ "
118
+ total_all=$(( total_all + t ))
119
+ count=$(( count + 1 ))
120
+ done < <(find $SKILL_ROOTS -mindepth 2 -maxdepth 2 -name 'SKILL.md' 2>/dev/null | sort)
121
+
122
+ if [ "$count" -eq 0 ]; then
123
+ echo "skill-frontmatter-lint: no SKILL.md found under$SKILL_ROOTS"
124
+ exit 0
125
+ fi
126
+
127
+ # ---- --report ---------------------------------------------------------------
128
+ if [ "$MODE" = "--report" ]; then
129
+ printf '%-26s %7s %12s %8s\n' skill description when_to_use total
130
+ printf '%s' "$rows" | sort -rn | while read -r t d w s; do
131
+ flag=""; [ "$t" -gt "$LISTING_BUDGET" ] && flag=" <- over ${LISTING_BUDGET}"
132
+ printf '%-26s %7s %12s %8s%s\n' "$s" "$d" "$w" "$t" "$flag"
133
+ done
134
+ echo
135
+ echo "$count skills, ${total_all} bytes resident (~$(( total_all / 4 )) tokens every turn)"
136
+ exit 0
137
+ fi
138
+
139
+ # ---- --update ---------------------------------------------------------------
140
+ if [ "$MODE" = "--update" ]; then
141
+ {
142
+ echo "# skill-frontmatter-baseline.txt — generated by scripts/skill-frontmatter-lint.sh --update"
143
+ echo "# Skills whose description+when_to_use exceed the ${LISTING_BUDGET}-byte listing budget."
144
+ echo "# These are GRANDFATHERED: allowed to stay, but may never grow. Shrink them and re-run"
145
+ echo "# --update to tighten the ratchet. A skill that drops under budget leaves this file."
146
+ echo "#"
147
+ echo "# <skill> <bytes>"
148
+ printf '%s' "$rows" | sort -rn | while read -r t d w s; do
149
+ [ "$t" -gt "$LISTING_BUDGET" ] && printf '%s %s\n' "$s" "$t"
150
+ done
151
+ } > "$BASELINE"
152
+ echo "ok wrote $BASELINE ($(grep -cv '^[[:space:]]*#' "$BASELINE") grandfathered)"
153
+ exit 0
154
+ fi
155
+
156
+ # ---- lint (the gate) --------------------------------------------------------
157
+ over=0
158
+ while read -r t d w s; do
159
+ [ -n "$s" ] || continue
160
+ if [ "$t" -le "$LISTING_BUDGET" ]; then
161
+ # Under budget. If it was baselined, it has been fixed — nudge to tighten the ratchet.
162
+ if [ -n "$(baseline_for "$s")" ]; then
163
+ note "$s is now under budget (${t}) — run --update to drop it from the baseline"
164
+ fi
165
+ continue
166
+ fi
167
+ over=$(( over + 1 ))
168
+ base="$(baseline_for "$s")"
169
+ if [ -z "$base" ]; then
170
+ err "$s: description+when_to_use is ${t} bytes, over the ${LISTING_BUDGET}-byte listing budget"
171
+ note "this text is resident in EVERY session. Move detail into the SKILL.md body (lazy-loaded),"
172
+ note "or accept it deliberately with: scripts/skill-frontmatter-lint.sh --update"
173
+ elif [ "$t" -gt "$base" ]; then
174
+ err "$s: grew to ${t} bytes (baseline ${base}) — always-resident context may not grow"
175
+ note "trim it back to ${base} or below, or re-baseline deliberately with --update"
176
+ fi
177
+ done < <(printf '%s' "$rows" | sort -rn)
178
+
179
+ if [ "$FAIL" -eq 0 ]; then
180
+ ok "skill frontmatter within budget ($count skills, ~$(( total_all / 4 )) tokens resident; $over grandfathered)"
181
+ fi
182
+ exit "$FAIL"
@@ -2,6 +2,7 @@
2
2
  # Read-only board status, grouped by role. Pure gh + jq. bash 3.2 compatible.
3
3
  # Reads repo from .claude/kit.config.json. Run from project root.
4
4
  # ./scripts/task-sync.sh [--role <Name>] [--milestone <label>]
5
+ # --raw-json: original issue objects for shell consumers; --llm stays TOON-first.
5
6
  set -euo pipefail
6
7
  source "$(dirname "$0")/lib/kit-config.sh" && load_kit_config
7
8
  # Pure board-view render helpers (merge queue, stale flag, not-on-board flag, Project Status).
@@ -17,6 +18,7 @@ while [[ $# -gt 0 ]]; do
17
18
  --role) ROLE_FILTER="$2"; shift 2 ;;
18
19
  --milestone) MS_FILTER="$2"; shift 2 ;;
19
20
  --llm|--output=json) CCKIT_OUTPUT=json; shift ;;
21
+ --raw-json) CCKIT_OUTPUT=raw-json; shift ;;
20
22
  *) echo "unknown flag: $1" >&2; exit 1 ;;
21
23
  esac
22
24
  done
@@ -24,6 +26,12 @@ done
24
26
  ISSUES=$(gh issue list --repo "$KIT_REPO" --state open --limit 200 \
25
27
  --json number,title,labels,milestone,assignees,updatedAt,body)
26
28
 
29
+ # Keep shell consumers out of the agent-oriented TOON encoding and flattened label shape.
30
+ if [ "${CCKIT_OUTPUT:-human}" = "raw-json" ]; then
31
+ printf '%s\n' "$ISSUES"
32
+ exit 0
33
+ fi
34
+
27
35
  # Structured output for agents: emit the open board and stop (--llm / CCKIT_OUTPUT). The board is a
28
36
  # uniform list, so it goes out as TOON — far cheaper in tokens than JSON — via the shared encoder,
29
37
  # which falls back to JSON for a non-uniform/empty result. labels + assignees are flattened to
package/scripts/test.sh CHANGED
@@ -27,9 +27,18 @@ if [ "${#tests[@]}" -eq 0 ]; then
27
27
  fi
28
28
 
29
29
  note "==> cckit tests — ${#tests[@]} file(s)${PATTERN:+ (filter: $PATTERN)}"
30
+ # Seal every test from the caller's kit environment (#369): a shell that ran load_kit_config, or set
31
+ # KIT_CONFIG, exports KIT_*/CCKIT_*/EFFORT_* that would point a test at the developer's project
32
+ # instead of its own fixture. Each test still sets whatever it needs itself.
33
+ # shellcheck source=/dev/null
34
+ . scripts/lib/test-env.sh
35
+ seal=()
36
+ while IFS= read -r a; do [ -n "$a" ] && seal+=("$a"); done < <(test_env_unset_args)
37
+ [ "${#seal[@]}" -eq 0 ] || note "==> sealed $(( ${#seal[@]} / 2 )) inherited KIT_*/CCKIT_*/EFFORT_* variable(s)"
38
+
30
39
  pass=0; failn=0; failed=""
31
40
  for t in "${tests[@]}"; do
32
- out="$(bash "$t" 2>&1)"; rc=$?
41
+ out="$(env ${seal[@]+"${seal[@]}"} bash "$t" 2>&1)"; rc=$?
33
42
  if [ "$rc" -eq 0 ]; then
34
43
  pass=$((pass+1)); note " ok $t"
35
44
  else
@@ -6,6 +6,17 @@ when_to_use: When delegating work to run unattended — a single capped objectiv
6
6
 
7
7
  # kit-autopilot — capped, hands-off execution
8
8
 
9
+ ## Current implementation limit
10
+
11
+ The current `cckit autopilot` CLI launches issue flows through `orchestrate.sh`. It accepts
12
+ issue numbers, `--cap`, `--agent`, `--dry-run`, `--no-seed`, `--force`, and `--session`.
13
+ The objective, `--plan`, `--max-tokens`, `--max-iters`, `--until`, and `--notify` examples below
14
+ are workflow requirements, not implemented CLI flags. Do not invoke them as working commands.
15
+ Before accepting an unattended objective, verify that the selected runtime actually enforces each
16
+ requested limit. If it cannot, report the unsupported limit and do not start that bounded run.
17
+ A prompt asking an agent to stay under a token budget does not enforce that budget.
18
+ Implementation and cross-runtime verification are tracked in cckit effort #257, sub-issue #264.
19
+
9
20
  One skill, two modes — both delegate work that runs **autonomously to a verifiable stop, under hard
10
21
  caps**. It is a **thin wrapper**: it composes the built-in `/loop` and the kit's `orchestrate`
11
22
  scripts; it never reimplements looping or orchestration.
@@ -34,7 +45,8 @@ build a wave → merge its PRs → close subs+parent → gc → launch the next
34
45
  (`risk-tiered-review.md`) govern **ad-hoc** PRs, **not** execution of an approved plan.
35
46
  - **The permission is shipped, not improvised.** `cckit init` scaffolds a **versioned**
36
47
  `.claude/settings.json` (from `templates/settings/settings.json.tmpl`) whose explicit
37
- `Bash(gh pr merge:*)` allow pre-authorizes the wave-merge — checked in, so it travels to every
48
+ `Bash(cckit merge:*)` / `Bash(cckit watch:*)` allow pre-authorizes the wave-merge (a raw
49
+ `gh pr merge` is blocked by the guard hook, #364) — checked in, so it travels to every
38
50
  worktree and collaborator (the gitignored `settings.local.json` does not). A captain merge that
39
51
  still prompts means the project predates the template: re-run `cckit init --upgrade`.
40
52
 
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: kit-cleanup
3
- description: Run the ONE guided destructive sweep over the repo — present the gc plan (SAFE / ZOMBIE / ORPHAN / PROTECTED / stashes), then delete only the SAFE rows and prune the listed ZOMBIE metadata after the user confirms. Orphan branches, open-issue branches, and stashes are surfaced and left alone.
3
+ description: Run the ONE guided destructive sweep over the repo — present the gc plan (SAFE / LANDED / ZOMBIE / ORPHAN / PROTECTED / stashes), then delete the SAFE + LANDED rows and prune the listed ZOMBIE metadata once the user confirms. Orphan, open-issue branches and stashes are surfaced, kept.
4
4
  when_to_use: When `cckit gc` (or the SessionStart hygiene hook) reports merged branches and worktrees piling up and you want them gone in one pass. Use this instead of hand-rolling `git branch -D` + `git push origin --delete` loops. For the read-only report alone, use `/kit-gc`.
5
5
  ---
6
6
 
@@ -32,7 +32,8 @@ KIT_GC_REPO="$KIT_REPO" source "${CLAUDE_PLUGIN_ROOT}/scripts/lib/kit-gc.sh"
32
32
  kit_gc_cleanup # plan only — deletes no branch, worktree, remote ref or stash
33
33
  ```
34
34
 
35
- Or through the CLI: `cckit cleanup` (add `--llm` for JSON counts).
35
+ Or through the CLI: `cckit cleanup` (add `--llm` for JSON counts: `safe`, `landed`, `worktrees`,
36
+ `zombie`, `orphan`, `protected`, `stash`, `remote_failed`, `applied`).
36
37
 
37
38
  ### 2. Present it and ask
38
39
 
@@ -42,8 +43,9 @@ veto per-bucket — if they want the orphans looked at first, do that before del
42
43
  | Bucket | Rule | `--yes` does |
43
44
  | --- | --- | --- |
44
45
  | **SAFE** | PR `MERGED`, issue closed/absent, unprotected | **deletes** the worktree, the local branch, and the remote ref *if* the branch was level with it |
46
+ | **LANDED** | **no PR of its own**, work already on base — by content (every file it changed since its merge base matches `origin/<base>`) or by lineage (`sub/<N>…`, `effort/<N>…`, or a `[#N]` commit subject names an issue closed with a merged PR). Effort subs after `effort close`, `effort/<N>` branches whose remote is gone, Claude Code Agent-tool `worktree-agent-<hash>` isolation worktrees | **deletes** exactly like SAFE — worktree, local branch, level remote ref — under the same guards: a dirty worktree or a branch ahead of its remote is skipped with a warning. The plan prints the block with each row's reason, before ORPHAN |
45
47
  | **PROTECTED** | associated issue **still OPEN** | **keeps** — close the issue first |
46
- | **ORPHAN** | local commits not on the base branch's remote, no merged PR | **keeps** — offer to recover into a PR (step 4) |
48
+ | **ORPHAN** | fails both LANDED checks: commits whose content is not on the base branch's remote, no merged PR | **keeps** — offer to recover into a PR (step 4) |
47
49
  | **ZOMBIE** | worktree dir gone, admin metadata lingers | **recovers** any staged delta to a commit on its branch, **then prunes** the metadata |
48
50
  | **stashes** | any stash entry | **keeps** — irreversible; drop only after showing each diff |
49
51
 
@@ -113,11 +113,12 @@ Check permission: `gh repo view OWNER/REPO --json viewerPermission -q .viewerPer
113
113
 
114
114
  **This is public + outward-facing — confirm with the user before opening it.**
115
115
 
116
- - Artifact PR: `gh pr create --repo OWNER/REPO --base main` — from a fork the head is
117
- `<your-login>:<branch>`. Title summarizes the contribution; body states **what it adds, why, and how
118
- it was tested/linted**.
119
- - Pure request, no artifact: `gh issue create --repo OWNER/REPO` with the **Problem · Proposal · Scope
120
- · Why** body instead.
116
+ - Artifact PR: `cckit contribute "<summary>"` — runs `scripts/check.sh`, pushes, opens the PR.
117
+ From a fork to another owner's repo, `KIT_ALLOW_RAW=1 gh pr create --repo OWNER/REPO --base main`
118
+ (the head is `<your-login>:<branch>`); the guard hook records the bypass. Title summarizes the
119
+ contribution; body states **what it adds, why, and how it was tested/linted**.
120
+ - Pure request, no artifact, to another repo: `KIT_ALLOW_RAW=1 gh issue create --repo OWNER/REPO`
121
+ with the **Problem · Proposal · Scope · Why** body instead.
121
122
  - Print the resulting URL.
122
123
 
123
124
  ## 7. Report
@@ -24,8 +24,13 @@ The effort lifecycle's terminal op. Board state, issue state, and the work recor
24
24
  4. **Judge + sync** the metrics (reads the durable trace dir; no-ops when the engine is off).
25
25
  5. **Close the parent + ALL native sub-issues** and set the **board Status=Done** for each
26
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).
27
+ 6. **GC**: base branch checked out + pulled in the main checkout; then the effort's **`sub/<N>…`
28
+ worktrees and branches** are collected through `kit_gc_prune --only '^sub/<N>[a-z]-'` — the
29
+ squash just put their work on base, so they classify **LANDED** (no PR of their own, content or
30
+ lineage on base) and go under the same recover-before-prune guards as `cckit cleanup` (a dirty
31
+ sub worktree, or a sub ahead of its remote, stays and is reported). Then the effort worktree is
32
+ removed, its local branch deleted, pruned (the remote branch is deleted by the merge). A sub
33
+ that fails both LANDED checks is left for `cckit gc` to show as ORPHAN.
29
34
  7. **Knowledge-ingest hook** (optional, config-gated via `effort.knowledgeIngestHook`).
30
35
  8. **Kit-sync drift check** — advisory warning when the effort touched kit-managed files that
31
36
  belong upstream (/kit-contribute).
@@ -84,7 +89,7 @@ effort_close "$NUM"
84
89
  - Pre-squash trace dir (`<git-common-dir>/traces/effort-<N>/` + `index.jsonl`) + captured metrics
85
90
  - PR squash-merged; parent + all native sub-issues closed
86
91
  - Board Status=Done for parent + every sub (if Projects v2 is on)
87
- - Main checkout on the base branch, up to date; effort worktree + local/remote branch removed and pruned
92
+ - Main checkout on the base branch, up to date; effort worktree + local/remote branch removed and pruned, and every LANDED `sub/<N>…` worktree + branch with them (`✓ sub gc:` lines)
88
93
  - Knowledge-ingest hook ran (if configured); a kit-sync warning if the effort touched kit-managed files
89
94
 
90
95
  ## Rules
@@ -6,9 +6,10 @@ when_to_use: When an effort branch is ready for review (all its sub-issues built
6
6
 
7
7
  # kit-effort-pr
8
8
 
9
- Plugin-direct skill — runs straight from `${CLAUDE_PLUGIN_ROOT}` (no per-project `scripts/` checkout
10
- needed). Helpers (config, role identity, board) are sourced from the plugin (kit-engine-boundary
11
- #1/#2). Respects `KIT_BASE_BRANCH` (default `main`) and the `KIT_PROJECTS_V2` board toggle.
9
+ Thin caller of the verb **`cckit effort pr`** (`effort_pr` in `scripts/lib/effort-ops.sh`), the ONE
10
+ implementation (kit-engine-boundary #1/#2, #363). This skill used to carry its own inline copy of the
11
+ logic; agents copied that script by hand and the copy drifted (a PR missing from the board, a mangled
12
+ body). Never re-implement it here, and never paste it into a shell.
12
13
 
13
14
  Opens the **single** PR for an effort. The PR carries the human-facing review write-up + a
14
15
  `## For agents` section (retrieval context / the work record). The parent issue holds the plan;
@@ -26,101 +27,21 @@ this PR is where humans review the result. The title carries `[#N]` (the effort
26
27
 
27
28
  ## Execution
28
29
 
29
- ```bash
30
- source "${CLAUDE_PLUGIN_ROOT}/scripts/lib/kit-config.sh" && load_kit_config
31
- [[ "$KIT_PROJECTS_V2" == "true" ]] && { source "${CLAUDE_PLUGIN_ROOT}/scripts/lib/gh-project.sh"; load_project_ids; }
32
- source "${CLAUDE_PLUGIN_ROOT}/scripts/lib/role-identity.sh" 2>/dev/null || true
33
- source "${CLAUDE_PLUGIN_ROOT}/scripts/lib/effort.sh" # effort_pr_title + effort_pr_title_check (the shared composer)
34
- BASE="${KIT_BASE_BRANCH:-main}"
35
-
36
- # 1. Parse the parent effort number from the branch (effort/<N>-<slug>).
37
- BRANCH=$(git rev-parse --abbrev-ref HEAD)
38
- NUM="${INPUT_NUM:-}"
39
- [[ -z "$NUM" ]] && NUM=$(echo "$BRANCH" | sed -nE 's#^effort/([0-9]+)-.*#\1#p')
40
- [[ -z "$NUM" ]] && { echo "✗ Branch $BRANCH is not an effort branch (effort/<N>-<slug>)"; exit 1; }
41
-
42
- # 2. Pull parent issue metadata.
43
- META=$(gh issue view "$NUM" --repo "$KIT_REPO" --json title,labels,milestone)
44
- TITLE=$(echo "$META" | jq -r .title)
45
- LABELS=$(echo "$META" | jq -r '[.labels[].name] | join(",")')
46
- MILESTONE=$(echo "$META" | jq -r '.milestone.title // ""')
47
- ROLE=$(echo "$LABELS" | tr ',' '\n' | grep '^role:' | head -1 | cut -d: -f2)
48
- ROLE_DISPLAY=$(role_display "$ROLE" 2>/dev/null || echo ""); [[ -z "$ROLE_DISPLAY" ]] && ROLE_DISPLAY="Tech Lead"
49
-
50
- # 3. Commit any pending changes — role identity is a Co-authored-by TRAILER, never the git author
51
- # (some deploy providers refuse commits whose author email matches no account).
52
- COMMIT_MSG="${COMMIT_MSG:-$ROLE: $TITLE}"
53
- if [[ -n "$(git status --porcelain)" ]]; then
54
- git add -A
55
- AUTHOR=$(role_git_author "$ROLE" 2>/dev/null || echo "")
56
- if [[ -n "$AUTHOR" ]]; then
57
- git commit -m "$COMMIT_MSG" -m "Co-authored-by: ${AUTHOR%%|*} <${AUTHOR##*|}>"
58
- else
59
- git commit -m "$COMMIT_MSG"
60
- fi
61
- fi
62
-
63
- # 4. Push.
64
- git push -u origin "$BRANCH"
65
-
66
- # 5. Compose the PR body — rich human review + the agent-facing retrieval block.
67
- PR_BODY=$(cat <<EOF
68
- ## For the orchestrator
69
-
70
- Effort #$NUM — one PR for the whole effort. Review: the summary below + the diff.
71
-
72
- Closes #$NUM
73
-
74
- ## Summary
30
+ From the effort worktree (branch `effort/<N>-<slug>`):
75
31
 
76
- $SUMMARY
77
-
78
- ## For agents
79
-
80
- $FOR_AGENTS
81
-
82
- ## Verification
83
-
84
- - [ ] Each sub-issue change is present in the diff
85
- - [ ] No unrelated files in the diff
86
- - [ ] Labels + milestone match the parent issue
87
- - [ ] Local lint/typecheck pass
88
-
89
- $(role_signature "$ROLE" 2>/dev/null || true)
90
- EOF
91
- )
92
-
93
- # 6. Create the PR. Title composed by the ONE shared composer (same as `cckit effort pr`), then the
94
- # mandatory-[#N] check — refuse rather than open an id-less PR.
95
- PR_TITLE=$(effort_pr_title "$NUM" "$TITLE" "$ROLE_DISPLAY")
96
- effort_pr_title_check "$PR_TITLE" "$NUM" || { echo "✗ PR title lacks the [#$NUM] effort id — aborting"; exit 1; }
97
- URL=$(gh pr create --repo "$KIT_REPO" \
98
- --base "$BASE" \
99
- --head "$BRANCH" \
100
- --title "$PR_TITLE" \
101
- --body "$PR_BODY" \
102
- ${LABELS:+--label "$LABELS"} \
103
- ${MILESTONE:+--milestone "$MILESTONE"} \
104
- --assignee "@me")
105
- echo "✓ $URL"
32
+ ```bash
33
+ cckit effort pr <N> --summary-file <summary.md> --for-agents-file <for-agents.md>
34
+ # short form: cckit effort pr <N> --summary "<what + why>" --for-agents "<paths>"
35
+ # a repo with its own PR-title convention: add --title "<title carrying [#N]>"
36
+ ```
106
37
 
107
- # 7. Board (if Projects v2): add the PR (In Review) + inherit Role; move the parent issue to In Review.
108
- if [[ "$KIT_PROJECTS_V2" == "true" ]]; then
109
- PR_NUM=$(basename "$URL")
110
- PR_NODE=$(gh api "repos/$KIT_REPO/pulls/$PR_NUM" --jq .node_id)
111
- PR_ITEM=$(project_add_item "$PR_NODE" 2>/dev/null || echo "")
112
- if [[ -n "$PR_ITEM" ]]; then
113
- ROLE_OPT=$(role_option_id "$ROLE" 2>/dev/null || echo "")
114
- [[ -n "$ROLE_OPT" ]] && project_set_single_select "$PR_ITEM" "$ROLE_FIELD_ID" "$ROLE_OPT"
115
- project_set_single_select "$PR_ITEM" "$STATUS_FIELD_ID" "$STATUS_OPT_IN_REVIEW"
116
- fi
117
- # Parent issue → In Review (the finder paginates the whole board, not just the first page).
118
- PARENT_ITEM=$(project_find_item_by_issue "$NUM")
119
- [[ -n "$PARENT_ITEM" ]] && project_set_single_select "$PARENT_ITEM" "$STATUS_FIELD_ID" "$STATUS_OPT_IN_REVIEW"
120
- fi
38
+ What the verb does, in order: commits pending **tracked** changes (role identity as a
39
+ `Co-authored-by` trailer; untracked files are listed, never swept in) → pushes → reads the parent's
40
+ title, labels and milestone → composes the title with `effort_pr_title` and refuses one without
41
+ `[#N]` → opens the PR with the body below → adds the PR to the board at In Review (+ Role) and moves
42
+ the parent to In Review. A failed board add prints a warning; it is never silent.
121
43
 
122
- echo " Next: review, then /kit-effort-close $NUM"
123
- ```
44
+ Body: `## For the orchestrator` (+ `Closes #N`) · `## Summary` · `## For agents` · `## Verification`.
124
45
 
125
46
  ## Output
126
47
 
@@ -51,7 +51,7 @@ branch's remote** (orphan work is surfaced, never auto-deleted).
51
51
  # scripts/lib/kit-gc.sh :: kit_gc_analyze (also what `kit gc` + the kit-ui cockpit run)
52
52
  source "${CLAUDE_PLUGIN_ROOT}/scripts/lib/kit-config.sh" && load_kit_config
53
53
  KIT_GC_REPO="$KIT_REPO" source "${CLAUDE_PLUGIN_ROOT}/scripts/lib/kit-gc.sh"
54
- kit_gc_analyze # worktrees / branches / stashes, each tagged PROTECTED/SAFE/ACTIVE/ORPHAN
54
+ kit_gc_analyze # worktrees / branches / stashes, each tagged PROTECTED/SAFE/ACTIVE/LANDED/ORPHAN
55
55
  ```
56
56
 
57
57
  Classify every branch/worktree (issue-open protection wins over everything except an explicit force):
@@ -61,9 +61,10 @@ Classify every branch/worktree (issue-open protection wins over everything excep
61
61
  | **Protected (open issue)** | `wt_protected_reason` non-empty — associated issue **#N still OPEN** | **keep** — never prune, even with no PR / merged PR |
62
62
  | **Safe to delete** | PR `MERGED`, level with its remote (no unpushed commits), **and** issue closed/absent | prune |
63
63
  | **Active** | open PR, or the base branch, or a worktree branch with an open PR | keep |
64
- | **Orphan** | local commits **not on the base branch's remote** and no merged PR | **surface, never auto-delete** — offer to open a recovery PR |
64
+ | **Landed** | **no PR of its own**, but its work is already on base — either check suffices: (a) *content*: every file it changed since its merge base has the same content on `origin/<base>`; (b) *lineage*: its name (`sub/<N>…`, `effort/<N>…`) or a `[#N]` / `(#N)` in a commit subject names an issue that is **closed with a merged PR** — found in the 200-PR index by head `<kind>/<N>-…`, or, when that PR has scrolled out of the window, through the issue's own `closedByPullRequestsReferences`; a sub-issue with no closing PR (subs close through `effort close`) is resolved once through its **parent**'s closing PR (sub-issues API). One lookup per issue per run, cached | prune, under the same dirty-worktree / unpushed guards as SAFE |
65
+ | **Orphan** | fails both LANDED checks: commits whose content is **not on the base branch's remote** and no merged PR | **surface, never auto-delete** — offer to open a recovery PR |
65
66
 
66
- For squash-merged branches, `--is-ancestor` is unreliable — trust the **PR state**, then verify the branch is level with its remote (`git rev-list --count origin/<b>..<b>` = 0) before deleting.
67
+ For squash-merged branches, `--is-ancestor` and `git cherry` are unreliable (a squash rewrites the patch ids) — trust the **PR state** for a branch with its own PR, and the two LANDED checks for one without: an effort's `sub/<N><letter>` (merged into `effort/<N>`, then squashed), an `effort/<N>` whose remote ref is gone, and a Claude Code Agent-tool isolation worktree (`worktree-agent-<hash>`, which no verb creates). Then verify the branch is level with its remote (`git rev-list --count origin/<b>..<b>` = 0) before deleting. The LANDED row carries its reason (`content on origin/develop`, `issue #50 closed, its PR merged`; agent worktrees are named as such).
67
68
 
68
69
  ### 2. Present the plan
69
70
 
@@ -71,18 +72,21 @@ Print a table: worktrees to remove, branches to delete (local + remote), orphans
71
72
 
72
73
  ### 3. Execute (after confirmation)
73
74
 
75
+ Every deletion goes through the verb — the raw `git worktree remove` / `git branch -D` loop this
76
+ section used to document is what the base-branch guard exists to prevent, and it skipped the
77
+ recover-before-prune checks. `/kit-cleanup` prints the same plan, then acts on it:
78
+
74
79
  ```bash
75
- # Worktrees whose PR merged
76
- git worktree remove <path> --force && git worktree prune
77
- # Merged branches — local then remote
78
- git branch -D <branch>
79
- git push origin --delete <branch>
80
+ cckit cleanup --yes # deletes the SAFE + LANDED rows (worktree, local branch, level remote ref), prunes listed ZOMBIE metadata
80
81
  # Stale-open issues (PR already merged)
81
- gh issue close <n> --repo "$KIT_REPO" --reason completed --comment "Delivered via PR #<pr>."
82
- # Stashes — only after showing each diff and getting an explicit OK
82
+ cckit close <n> "Delivered via PR #<pr>." # board Done + close; raw gh issue close is blocked (#364)
83
+ # Stashes — the one step that stays by hand, only after showing each diff and getting an explicit OK
83
84
  git stash drop 'stash@{n}' # or: git stash clear
84
85
  ```
85
86
 
87
+ A branch that `cleanup` leaves as ORPHAN is one whose work is **not** on base by either check: do not
88
+ reach for `git branch -D` — step 4.
89
+
86
90
  ### 4. Orphan handling
87
91
 
88
92
  For each orphan branch with unique unpushed work: **do not delete**. Recover it
@@ -95,5 +99,6 @@ into a clean PR off the base branch (branch from `$BASE`, `git checkout <orphan>
95
99
  - **Never** delete the base branch (`main`/`develop`) or an open-PR branch/worktree.
96
100
  - **Never** remove a worktree/branch whose **associated issue is still open** (`wt_protected_reason` non-empty) — close the issue first, or pass an explicit per-item override.
97
101
  - **Never** drop a stash or delete an orphan branch without explicit per-item consent (stashes and unpushed commits are irreversible).
102
+ - **Delete through `cckit cleanup --yes`**, never a raw `git worktree remove` / `git branch -D` — the verb is the only path that applies the recover-before-prune guards to every row it touches.
98
103
  - Verify a branch is **level with its remote** before deleting — an "ahead" branch may hold orphan work.
99
104
  - Prefer enabling GitHub **"Automatically delete head branches"** so remote pruning stops being a manual step.
@@ -31,12 +31,10 @@ Ask it to output findings grouped by severity + a flat "Issues to file" list at
31
31
  For each finding, create a GitHub issue on the project repo (`KIT_REPO` from kit.config):
32
32
 
33
33
  ```bash
34
- source "${CLAUDE_PLUGIN_ROOT}/scripts/lib/kit-config.sh" && load_kit_config
35
- gh issue create --repo "$KIT_REPO" \
36
- --title "<finding title>" \
37
- --label "role:security,kind:security,priority:<critical|p1|p2|p3>" \
38
- --body "<risk / evidence / fix>"
39
- # add --milestone "<Security milestone>" when the project has one
34
+ cckit new --role security --kind security --priority <critical|p1|p2|p3> \
35
+ --body-file <finding.md> "<finding title>"
36
+ # add --milestone "<Security milestone>" when the project has one. The verb adds the issue to the
37
+ # board; raw gh issue create is blocked by the guard hook (#364).
40
38
  ```
41
39
 
42
40
  ### Phase 3 — Roadmap (Tech Lead)
@@ -29,7 +29,7 @@ resolve from `${CLAUDE_PLUGIN_ROOT}`.
29
29
  | 5 | **PR** | `/kit-task-pr <N>` — commit, push, open PR to the base branch, mirror labels/milestone, add to board, move issue **In Review**. |
30
30
  | 6 | **Wait for CI** | If the project has a required check, poll until it's not pending (background `until` loop). **Pending ≠ failing — wait; never force-merge.** |
31
31
  | 7 | **Merge** | `/kit-task-pr-merge` once green — squash to the base, switch to base, pull, delete local+remote branch + worktree. |
32
- | 8 | **Close** | `gh issue close <N>` + set board **Done**. **Required** when `Closes #N` does NOT auto-fire (PRs that merge to a non-default branch don't trigger GitHub auto-close). |
32
+ | 8 | **Close** | `cckit close <N> "<summary>"` — closes the issue and sets board **Done**. **Required** when `Closes #N` does NOT auto-fire (PRs that merge to a non-default branch don't trigger GitHub auto-close). |
33
33
  | 9 | **Update kit (only if the change touched the plugin source)** | bump version (`/kit-dev ship`) + `/plugin update`. |
34
34
 
35
35
  Report at the end: issue state, PR number + merged status, branch cleaned, board reflects Done.
@@ -40,4 +40,6 @@ The function prints `✓ <PR-URL>`.
40
40
  - Never open a PR for a branch off the `<kind>/<N>-<slug>` convention — the op aborts with instructions
41
41
  - Never invent a Summary — ask if missing (the op refuses an empty Summary) · never push to the base branch directly
42
42
  - PR mirrors issue labels · if no milestone, the op omits it (no block)
43
+ - Commits **tracked** changes only; untracked files are listed and left alone (`git add` them first if they belong), so a copied `.env.local` never reaches a PR
44
+ - Title and body follow `pr.titleStyle` and `pr.orchestratorSection` in the config (`config-and-permissions` docs)
43
45
  - If `gh pr create` fails because the branch hasn't diverged, the op surfaces the error verbatim (likely forgot to commit)