@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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cckit",
3
- "version": "0.7.0",
3
+ "version": "0.8.0",
4
4
  "installationPreference": "beta",
5
5
  "description": "cckit — a project operating system for coding agents. The full GitHub work lifecycle (start/pr/close/sync, efforts, worktrees, orchestrate, gc) as agents + skills + rules, drivable by Claude Code and any other agent. Driven from cckit.config.json; no org or repo hardcoded.",
6
6
  "author": {
package/AGENTS.md CHANGED
@@ -63,10 +63,10 @@ the same commit.
63
63
  | `cckit effort chain <a> <b> [<c> …]` | wire 2+ issues into a linear order: `b` `blocked_by` `a`, `c` `blocked_by` `b`, plus a `- Depends on #<predecessor>` line in each successor's `## Relations` section. These are the edges `cckit plan` layers into waves. Idempotent (an edge or line already there is skipped); pre-existing blockers are kept, never replaced. Validates everything first — fewer than two numbers, a non-numeric arg, an issue that does not exist, a repeated number, or an edge that would close a cycle refuses the whole chain and writes nothing | — |
64
64
  | `cckit effort start [--force] <slug\|N> [slug]` | effort branch + bootstrapped worktree, **WIP-limited**: refuses a NEW effort once `effort.wipLimit` (default 2) are already in progress. In progress = an `effort/<N>-<slug>` branch exists as a local head **or** on origin, read with `git ls-remote` rather than the cached `refs/remotes` (which is wrong both ways: it misses a branch pushed since the last fetch and keeps one deleted on origin until a prune). At the limit refuses; only strictly under it starts. Re-starting an effort that is already in progress is never gated. The check runs before the fetch/branch/worktree/bootstrap, so a refusal makes no branch, no worktree and no board change — it is not read-free (it queries origin, and a `<slug>` arg was resolved first, which can run `gh issue list`). `0` refuses every ordinary start; `--force` still starts. A non-integer value is ignored with a warning and the default 2 is used; `EFFORT_WIP_LIMIT` overrides the config per invocation. `EFFORT_WIP_REMOTE=0` — or an unreachable origin, which warns and proceeds — counts the cached refs instead. Does **not** gate `cckit start <issue>` | `--force`, or `KIT_FORCE=1` |
65
65
  | `cckit effort plan` | session-fit effort plan | `--llm` → JSON |
66
- | `cckit orchestrate <a> <b> …` | run N flows in parallel worktrees | — (use `--dry-run`) |
67
- | `cckit autopilot [<a> …]` | unattended multi-flow: drive (or auto-pick) issues under a cap | — (use `--dry-run`) |
68
- | `cckit gc` | report prunable branches + worktrees — never one whose issue is still open; aborts if the protection helper is missing | `--llm` → JSON counts |
69
- | `cckit cleanup [--yes]` | the guided destructive sweep over that report: plan first, delete only the SAFE rows and prune the listed ZOMBIE metadata (staged work recovered to its branch first); ORPHAN / PROTECTED / stashes are never deletable | `--llm` → JSON counts + `applied` |
66
+ | `cckit orchestrate <a> <b> …` | run N flows in parallel worktrees, in tmux or Herdr | — (use `--dry-run`) |
67
+ | `cckit autopilot [<a> …]` | select work, then call `orchestrate --detach` under a cap | — (use `--dry-run`) |
68
+ | `cckit gc` | report prunable branches + worktrees — SAFE (own PR merged) and LANDED (no PR of its own, work already on base: effort subs, `worktree-agent-*` isolation worktrees) — never one whose issue is still open; aborts if the protection helper is missing | `--llm` → JSON counts (`safe`, `landed`, `protected`, `orphan`) |
69
+ | `cckit cleanup [--yes]` | the guided destructive sweep over that report: plan first, delete only the SAFE + LANDED rows and prune the listed ZOMBIE metadata (staged work recovered to its branch first); ORPHAN / PROTECTED / stashes are never deletable | `--llm` → JSON counts + `applied` |
70
70
  | `cckit render` | stdin markdown → rich (glow on a TTY; verbatim when piped) | — |
71
71
  | `cckit version` | the installed cckit version | `--llm` |
72
72
 
@@ -102,6 +102,8 @@ Every operation an unattended run needs is reachable through the one CLI:
102
102
  | `--dry-run` | resolve + print the launch plan; create no worktrees, start nothing |
103
103
  | `--cap <N>` | concurrency cap (default 4); flows past the cap are queued + reported |
104
104
  | `--agent <cmd>` | per-pane agent command (default `claude`, or `CCKIT_AGENT=`) — drive any CLI agent |
105
+ | `--profile <name>` | run a declared agent profile (or `CCKIT_PROFILE=`): its `kind` becomes the agent and its `args` are passed to the CLI. Unset picks the cheapest-tier profile; `--agent` overrides and skips profiles entirely. A project that declares none is unaffected |
106
+ | `--runtime <tmux\|herdr>` | terminal owner (default `tmux`, or `CCKIT_RUNTIME=`); Herdr requires a supported agent kind such as `codex` or `claude` |
105
107
  | `--force` | launch even if an issue is `blocked_by` an OPEN issue (the gate is on by default) |
106
108
  | `--no-seed` | start the agent without an auto-prompt |
107
109
 
@@ -119,6 +121,15 @@ cckit shells out to whatever agent invokes it; it does not embed a model. For ve
119
121
  text (digests, ingest), the model endpoint is configurable via environment — see the docs site (
120
122
  [cckit.dev](https://cckit.dev).
121
123
 
124
+ **Agent profiles** (`agents.profiles` in the config) carry a spend `tier`, a permission policy and
125
+ extra CLI argv. **cckit never names a model** — you spell your own flags in `args`, and the
126
+ cheapest-tier profile runs when `agents.default` is unset, so the inexpensive path is the default
127
+ by construction. A profile also declares the `stages` it may run at and whether it may
128
+ `write` to a branch; a profile with no `stages` is allowed nowhere, and `write` defaults to false.
129
+ Validation refuses an undeclared profile, a missing `kind`, an unknown stage, or a dangling
130
+ `agents.default` **before** a worktree or pane exists. See
131
+ [Agent profiles](https://cckit.dev/config-and-permissions/#agent-profiles).
132
+
122
133
  ## Paste-ready agent prompt
123
134
 
124
135
  Drop this verbatim into your agent's system prompt (or the first message of a session) to make it
package/README.md CHANGED
@@ -104,7 +104,7 @@ cckit pr 42 "what changed" # commit, push, open the PR
104
104
  cckit sync # board state, what's unblocked
105
105
  cckit handoff "resume note" # save a handoff — bare `cckit` prints it next session
106
106
  cckit gc # report prunable branches + worktrees (deletes nothing)
107
- cckit cleanup [--yes] # act on that report: delete the SAFE rows, prune listed zombies, keep orphans/stashes
107
+ cckit cleanup [--yes] # act on that report: delete the SAFE + LANDED rows, prune listed zombies, keep orphans/stashes
108
108
  ```
109
109
 
110
110
  Adopting cckit in a repo that already has history? `cckit scan` detects the stack, `cckit adopt`
@@ -205,13 +205,21 @@ that gate and merge themselves. This is the part that turns one keyboard into a
205
205
  ```bash
206
206
  cckit plan # the wave plan: deps-ordered, p0-first inside a wave, file-disjoint
207
207
  cckit wave # a Task-subagent fan-out brief Claude Code enacts (proposes the next wave)
208
- cckit orchestrate 12 14 17 # run N flows in parallel worktrees (--dry-run / --cap / --agent)
208
+ cckit orchestrate 12 14 17 # run N flows in parallel worktrees (tmux by default)
209
+ cckit orchestrate --runtime herdr --agent codex 12 14 17 # persistent, state-aware agent terminals
209
210
  cckit watch --merge # the captain: gate open PRs, squash-merge the CLEAN ones, advance
210
211
  # (policy floors hold PRs touching CI, lockfiles, or secrets for review)
211
212
  cckit watch --loop # self-pace gate/merge passes until steady state
212
- cckit autopilot # unattended multi-flow: drive (or auto-pick) issues under a cap
213
+ cckit autopilot # select unblocked work, then call orchestrate --detach under a cap
213
214
  ```
214
215
 
216
+ Set `review.command` in your config and the captain sends every PR it would merge to an agent
217
+ reviewer first, records the verdict as a stage receipt, and refuses to merge on a `fail`. You name
218
+ the command that runs the reviewer — cckit pipes it a brief on stdin and reads the report off
219
+ stdout, so it asserts nothing about any agent's flags. A PR with **no** verdict recorded reads
220
+ `verify`, never merges silently: absence of evidence is not a pass. Off until you configure it.
221
+ → [the agent review stage](https://cckit.dev/config-and-permissions/#the-agent-review-stage)
222
+
215
223
  ## Driven by agents
216
224
 
217
225
  cckit is meant to be operated by an agent loop, not only a human. See [`AGENTS.md`](AGENTS.md) for
package/bin/cckit CHANGED
@@ -11,7 +11,11 @@
11
11
  # cckit start <issue> [slug] isolated worktree + branch for an issue
12
12
  # cckit pr <issue> <summary> commit + push + open the PR
13
13
  # cckit close <issue> <summary> close issue + mark done
14
+ # cckit new [--role R --kind K --priority P --milestone M --blocked-by "#1" --body B|--body-file F] "<title>"
15
+ # file ONE issue: labels + board (Todo) in one step (never raw gh issue create)
16
+ # cckit merge [<pr>] squash-merge the PR (rebases on conflict), close its issues, GC the branch
14
17
  # cckit contribute "<summary>" open a contribution PR to cckit, gated on scripts/check.sh
18
+ # (from the cckit checkout or worktree you are in; else the installed one)
15
19
  # cckit sync [--llm] board state / what's unblocked
16
20
  # cckit plan [--llm] [--effort N] wave plan: deps-ordered, p0-first in a wave, file-disjoint (TOON --llm)
17
21
  # cckit plan-next [--llm] forward plan: current skills/verbs/rules/docs -> what to build next
@@ -27,13 +31,15 @@
27
31
  # EFFORT_WIP_REMOTE=0 or an unreachable origin uses the cache and still starts). Refuses
28
32
  # before writing anything; --force (or KIT_FORCE=1) starts anyway, at limit 0 too.
29
33
  # `cckit start <issue>` is not affected.
30
- # cckit orchestrate <a> <b> … run N flows in parallel worktrees (--dry-run/--cap/--agent)
34
+ # effort pr [<N>] [--summary S|--summary-file F] [--for-agents A|--for-agents-file F] [--title T]
35
+ # the ONE effort PR: inherits labels + milestone, rich body, board In Review
36
+ # cckit orchestrate <a> <b> … run N flows in parallel worktrees (--runtime tmux|herdr)
31
37
  # cckit autopilot [<a> …] unattended multi-flow: drive (or auto-pick) issues under a cap
32
38
  # cckit watch [--merge] [--loop] captain: gate open PRs, squash-merge CLEAN, advance the wave
33
39
  # cckit next [--effort N] everyday helper: the unblocked set + how to start the top issue
34
40
  # cckit wave [--effort N] read open efforts, propose incoming waves: fan-out + captain drive
35
41
  # cckit msg <send|read|list> session mail across projects: steer a live session (--steer)
36
- # cckit gc [--prune [--yes]] report (default) or prune merged branches + worktrees
42
+ # cckit gc [--prune [--yes]] report (default) or prune merged + landed branches and worktrees
37
43
  # cckit cleanup [--yes] guided destructive sweep over the gc report (plan first)
38
44
  # cckit status thin dashboard: board + worktrees + resume handoff
39
45
  # cckit scan [--llm] detect this repo's stack + kit state (JSON)
@@ -51,6 +57,7 @@
51
57
  # cckit commands [--llm] list every verb (the command catalog)
52
58
  # cckit lib [--llm] [--all] list every scripts/lib helper: functions, purpose, error contract
53
59
  # cckit brief <issue> the delegation brief for an issue, from real state
60
+ # cckit receipt <issue> … record/read one stage receipt (a worker's durable report)
54
61
  # cckit completions [bash|zsh] print a shell-completion script to source
55
62
  # cckit help
56
63
  set -eu
@@ -141,7 +148,12 @@ case "$cmd" in
141
148
  effort_new "$@" ;;
142
149
  chain) effort_chain "$@" ;;
143
150
  start) effort_start "$@" ;;
144
- pr) effort_pr "$@" ;;
151
+ pr)
152
+ # role-identity gives the PR its role title, commit trailer and signature; the board
153
+ # helpers load lazily inside effort_pr (_eo_source_board).
154
+ # shellcheck source=/dev/null
155
+ source "$LIB/role-identity.sh" 2>/dev/null || true
156
+ effort_pr "$@" ;;
145
157
  close) effort_close "$@" ;;
146
158
  plan) source "$LIB/effort-plan.sh"; effort_plan "$@" ;;
147
159
  *) echo "cckit effort <new|chain|start|pr|close|plan>" >&2; exit 2 ;;
@@ -182,6 +194,53 @@ case "$cmd" in
182
194
  close) kto_task_close "$@" ;;
183
195
  esac
184
196
  ;;
197
+ new)
198
+ # File ONE issue through kto_task_new (labels + board add + Role/Status fields). This verb is why
199
+ # an agent never needs raw `gh issue create`, which skips the board (#361). Multi-part work is
200
+ # `cckit effort new`. Defaults: kind task, priority p2; role from --role or KIT_DEFAULT_ROLE.
201
+ # shellcheck source=/dev/null
202
+ source "$LIB/kit-config.sh" && load_kit_config
203
+ # shellcheck source=/dev/null
204
+ source "$LIB/role-identity.sh"; source "$LIB/gh-project.sh"; source "$LIB/kit-task-ops.sh"
205
+ n_role="${KIT_DEFAULT_ROLE:-}"; n_kind="task"; n_prio="p2"; n_ms=""; n_plan=""; n_blocked=""; n_body=""; n_title=""
206
+ while [ $# -gt 0 ]; do
207
+ case "$1" in
208
+ --role) n_role="${2:-}"; shift 2 ;;
209
+ --kind) n_kind="${2:-}"; shift 2 ;;
210
+ --priority) n_prio="${2:-}"; shift 2 ;;
211
+ --milestone) n_ms="${2:-}"; shift 2 ;;
212
+ --plan) n_plan="${2:-}"; shift 2 ;;
213
+ --blocked-by) n_blocked="${2:-}"; shift 2 ;;
214
+ --body) n_body="${2:-}"; shift 2 ;;
215
+ --body-file) n_body="$(cat "${2:-/dev/null}")"; shift 2 ;;
216
+ -h|--help) echo 'cckit new [--role R --kind K --priority P --milestone M --plan L --blocked-by "#1" --body B|--body-file F] "<title>"'; exit 0 ;;
217
+ --) shift; n_title="${n_title:+$n_title }$*"; break ;;
218
+ -*) echo "cckit new: unknown flag $1" >&2; exit 2 ;;
219
+ *) n_title="${n_title:+$n_title }$1"; shift ;;
220
+ esac
221
+ done
222
+ [ -n "$n_title" ] || { echo 'cckit new: a title is required — cckit new --role R "<title>"' >&2; exit 2; }
223
+ [ -n "$n_role" ] || { echo 'cckit new: --role is required (or set KIT_DEFAULT_ROLE)' >&2; exit 2; }
224
+ if cckit_is_json; then
225
+ rc=0; out="$(kto_task_new "$n_title" "$n_role" "$n_kind" "$n_prio" "$n_ms" "$n_plan" "$n_blocked" "$n_body" 2>&1)" || rc=$?
226
+ url="$(printf '%s' "$out" | grep -oE 'https://[^ ]+/issues/[0-9]+' | tail -1)"
227
+ cckit_json verb new issue "$(basename "${url:-x}")" ok "$([ "$rc" -eq 0 ] && echo true || echo false)" \
228
+ url "$url" detail "$(printf '%s' "$out" | tail -1)"
229
+ exit "$rc"
230
+ fi
231
+ kto_task_new "$n_title" "$n_role" "$n_kind" "$n_prio" "$n_ms" "$n_plan" "$n_blocked" "$n_body"; echo
232
+ ;;
233
+ merge)
234
+ # Squash-merge through kto_task_pr_merge: rebase on conflict, close the PR's linked issues (native
235
+ # auto-close only fires on the default branch), then clean the branch + worktree. The verb behind
236
+ # every raw `gh pr merge` (#361). An effort's PR merges with `cckit effort close <N>`.
237
+ # shellcheck source=/dev/null
238
+ source "$LIB/kit-config.sh" && load_kit_config
239
+ # shellcheck source=/dev/null
240
+ source "$LIB/role-identity.sh"; source "$LIB/gh-project.sh"; source "$LIB/kit-task-ops.sh"
241
+ case "${1:-}" in -h|--help) echo 'cckit merge [<pr>] squash-merge (rebases on conflict), close linked issues, GC branch + worktree'; exit 0 ;; esac
242
+ kto_task_pr_merge "$@"
243
+ ;;
185
244
  sync) exec "$ROOT/scripts/task-sync.sh" "$@" ;;
186
245
  plan)
187
246
  # Wave plan over the board (deps-ordered, file-disjoint, session-fit). Runs in the invoking
@@ -217,6 +276,7 @@ case "$cmd" in
217
276
  out="$(kit_gc_cleanup "$@" 2>"$cleanup_err")" || cleanup_rc=$?
218
277
  safe="$(printf '%s\n' "$out" | awk '/^ SAFE branches/{print $3}')"
219
278
  wt="$(printf '%s\n' "$out" | awk '/^ SAFE worktrees/{print $3}')"
279
+ landed="$(printf '%s\n' "$out" | awk '/^ LANDED branches/{print $3}')"
220
280
  orphan="$(printf '%s\n' "$out" | awk '/^ ORPHAN kept/{print $3}')"
221
281
  protected="$(printf '%s\n' "$out" | awk '/^ PROTECTED kept/{print $3}')"
222
282
  stash="$(printf '%s\n' "$out" | awk '/^ stashes kept/{print $3}')"
@@ -225,7 +285,7 @@ case "$cmd" in
225
285
  applied=no
226
286
  if [ "$cleanup_rc" -eq 0 ]; then case " $* " in *" --yes "*|*" -y "*) applied=yes ;; esac; fi
227
287
  err="$(tr '\n' ' ' < "$cleanup_err" | sed 's/[[:space:]]*$//')"; rm -f "$cleanup_err"
228
- cckit_json verb cleanup safe "${safe:-0}" worktrees "${wt:-0}" orphan "${orphan:-0}" \
288
+ cckit_json verb cleanup safe "${safe:-0}" landed "${landed:-0}" worktrees "${wt:-0}" orphan "${orphan:-0}" \
229
289
  protected "${protected:-0}" stash "${stash:-0}" zombie "${zombie:-0}" applied "$applied" \
230
290
  remote_failed "${rfail:-0}" rc "$cleanup_rc" error "$err"
231
291
  [ "$cleanup_rc" -eq 0 ] || exit "$cleanup_rc"
@@ -240,16 +300,18 @@ case "$cmd" in
240
300
  source "$LIB/kit-gc.sh"
241
301
  case " $* " in
242
302
  *" --prune "*|*" prune "*)
243
- # Remove worktrees + local branches whose PR merged. Dry-run unless --yes.
303
+ # Remove worktrees + local branches whose PR merged (SAFE) or whose work is already on base
304
+ # with no PR of their own (LANDED, #388). Dry-run unless --yes.
244
305
  kit_gc_prune "$@"
245
306
  ;;
246
307
  *)
247
308
  if cckit_is_json; then
248
309
  out="$(kit_gc_analyze 2>/dev/null || true)"
249
310
  safe="$(printf '%s\n' "$out" | grep -c '> SAFE ' || true)"
311
+ landed="$(printf '%s\n' "$out" | grep -c '> LANDED ' || true)"
250
312
  protected="$(printf '%s\n' "$out" | grep -c 'PROTECTED:' || true)"
251
313
  orphan="$(printf '%s\n' "$out" | grep -c 'ORPHAN' || true)"
252
- cckit_json verb gc safe "$safe" protected "$protected" orphan "$orphan"
314
+ cckit_json verb gc safe "$safe" landed "$landed" protected "$protected" orphan "$orphan"
253
315
  else
254
316
  kit_gc_analyze "$@"
255
317
  fi
@@ -325,7 +387,14 @@ case "$cmd" in
325
387
  encode-context) source "$LIB/toon.sh"; toon_encode ;;
326
388
  render) source "$LIB/render.sh"; cckit_render ;;
327
389
  debug) exec "$ROOT/scripts/debug.sh" "$@" ;;
328
- contribute) cd "$ROOT"; exec "$ROOT/scripts/contribute.sh" "$@" ;;
390
+ contribute)
391
+ # The cckit checkout containing cwd (a worktree, per the rules) wins over the installed one, so
392
+ # the gate runs on — and the PR opens from — the branch being worked on (#368).
393
+ # shellcheck source=/dev/null
394
+ source "$LIB/contribute-root.sh"
395
+ croot="$(contribute_root "$PWD" "$ROOT")"
396
+ [ "$croot" = "$ROOT" ] || echo "contribute: using the checkout at $croot" >&2
397
+ cd "$croot"; exec "$croot/scripts/contribute.sh" "$@" ;;
329
398
  status|ui) exec "$ROOT/scripts/status.sh" "$@" ;;
330
399
  resume) source "$LIB/handoff.sh"; handoff_read ;;
331
400
  handoff) source "$LIB/handoff.sh"; handoff_write "$@" ;;
@@ -373,6 +442,16 @@ case "$cmd" in
373
442
  source "$LIB/kit-brief.sh"
374
443
  CCKIT_ROOT="$ROOT" kit_brief "$@"
375
444
  ;;
445
+
446
+ receipt)
447
+ # One durable record per stage attempt (#322). The WORKER calls this itself: cckit never reads
448
+ # pane output, because #326 requires that pane history — off by default, and able to hold
449
+ # secrets — is never a dependency. The report arrives on stdin in the shape `cckit brief`'s
450
+ # receipt contract asked for, so the prompt and this parser cannot drift apart.
451
+ # shellcheck source=/dev/null
452
+ source "$LIB/stage-receipt.sh"
453
+ sr_cli "$@"
454
+ ;;
376
455
  completions)
377
456
  case "${1:-bash}" in
378
457
  bash) cat "$ROOT/completions/cckit.bash" ;;
package/cckit.config.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "$schema": "./kit.config.schema.json",
3
- "kitVersion": "0.7.0",
3
+ "kitVersion": "0.8.0",
4
4
  "project": {
5
5
  "name": "cckit",
6
6
  "slug": "cckit",
@@ -64,6 +64,14 @@
64
64
  }
65
65
  },
66
66
  "milestones": { "type": "array", "items": { "type": "string" } },
67
+ "pr": {
68
+ "type": "object",
69
+ "additionalProperties": true,
70
+ "properties": {
71
+ "titleStyle": { "type": "string", "enum": ["conventional", "issue-title"], "default": "conventional", "description": "How `cckit pr` titles a single-issue PR. conventional (default): a Conventional Commits subject derived from the kind label, which release-please and a commitlint gate read. issue-title: the issue title, verbatim." },
72
+ "orchestratorSection": { "type": "boolean", "default": false, "description": "When true, `cckit pr` opens the PR body with a two-line `## For the orchestrator` section: the issue number and what to review." }
73
+ }
74
+ },
67
75
  "effort": {
68
76
  "type": "object",
69
77
  "additionalProperties": true,
@@ -73,6 +81,33 @@
73
81
  "wipLimit": { "type": "integer", "minimum": 0, "description": "How many efforts may be in progress at once before `cckit effort start` refuses a NEW effort (default 2). In progress = an `effort/<N>-<slug>` branch exists as a local head or on origin (read with `git ls-remote`, not the cached refs/remotes; EFFORT_WIP_REMOTE=0 or an unreachable origin counts the cached refs instead). Refusal happens before anything is written; `--force` (or KIT_FORCE=1) starts anyway. 0 refuses every ordinary start of a NEW effort but not a forced one, and not a re-start of an effort already in progress (that adds no WIP, so it is never gated); a non-integer value is ignored with a warning and the default is used. An explicit EFFORT_WIP_LIMIT env var wins per invocation. Does not affect `cckit start <issue>`." }
74
82
  }
75
83
  },
84
+ "agents": {
85
+ "type": "object",
86
+ "additionalProperties": true,
87
+ "description": "Named agent profiles and the stage vocabulary they are allowed at. A profile declares a SPEND POSTURE (`tier`) and the CLI arguments to run (`args`) — cckit never names a model, so it cannot push you onto an expensive one. Resolution precedence is command override > issue metadata > parent effort metadata > `agents.default` (see `cckit effort`/orchestration docs).",
88
+ "properties": {
89
+ "default": { "type": "string", "description": "Profile name used when nothing more specific resolves. Must name a key of `agents.profiles`; a `default` that names no declared profile is a validation error, not a silent fallback. OMIT IT to get the lowest-tier declared profile, which is the recommended setting: naming an expensive profile here makes every unlabelled issue expensive." },
90
+ "stages": { "type": "array", "items": { "type": "string" }, "description": "Controlled stage vocabulary a profile's `stages` entries are checked against. Replaces the built-in default (build review design docs); an explicit CCKIT_AGENT_STAGES env var wins per invocation." },
91
+ "profiles": {
92
+ "type": "object",
93
+ "additionalProperties": {
94
+ "type": "object",
95
+ "additionalProperties": true,
96
+ "required": ["kind"],
97
+ "properties": {
98
+ "kind": { "type": "string", "description": "The agent CLI/provider this profile runs, e.g. `claude` or `codex`. Must be a kind the selected runtime can start — the Herdr runtime validates it before any worktree is created." },
99
+ "tier": { "type": "string", "enum": ["low", "mid", "high"], "description": "How much this profile is expected to COST to run, relative to the others. cckit never names a model: the spend posture lives here and the actual flags live in `args`. `low` is assumed when unstated, and the lowest-tier profile is what runs when `agents.default` is not set — so the cheap path is the default by construction rather than by discipline." },
100
+ "args": { "type": "array", "items": { "type": "string" }, "description": "Extra CLI arguments appended to the launch command, as an argv array (never a shell string, so nothing is re-parsed by a shell). The project spells its own flags here — including any model selection — so no vendor CLI syntax and no model id lives in kit code." },
101
+ "permissions": { "type": "string", "description": "Permission/sandbox policy this profile runs under, forwarded to the CLI that implements it. Recorded in the stage receipt so a run's effective policy is auditable after the fact." },
102
+ "stages": { "type": "array", "items": { "type": "string" }, "description": "Stages this profile may run at, each a value from `agents.stages`. A profile selected for a stage it does not list is refused before a worktree or pane exists." },
103
+ "write": { "type": "boolean", "description": "Whether this profile may write to a branch (default false). One writer owns a branch at a time; review profiles stay read-only until ownership is explicitly transferred." },
104
+ "contextBudget": { "type": "integer", "minimum": 0, "description": "Upper bound, in BYTES, on the whole prompt a worker of this profile receives. Whole `## ` sections are dropped from the end of the brief until it fits, and the prompt then names which ones were dropped and how to read them — a truncated brief must read as truncated. Four things are never dropped: the headless framing, the brief's own metadata (worktree, branch, seed freshness, gate command), the truncation notice itself, and the receipt contract. A budget too small to hold those emits them anyway and warns on stderr, because a worker with no receipt contract reports in a shape nothing can parse. Unset, 0, or non-numeric means unbounded. The board and prior conversations are never included at any budget." }
105
+ }
106
+ },
107
+ "description": "Map of profile name to its declaration. Profile names are stable cckit policy referenced by issue and effort metadata; the vendor model id and CLI arguments inside each are project-owned."
108
+ }
109
+ }
110
+ },
76
111
  "captain": {
77
112
  "type": "object",
78
113
  "additionalProperties": true,
@@ -139,15 +174,21 @@
139
174
  },
140
175
  "devPorts": {
141
176
  "type": "array",
142
- "description": "Per-app dev PORT lanes. Each entry assigns PORT = base + (issue % 40) * <count> into that app's .env.local, so parallel worktrees never fight for a port.",
177
+ "description": "Per-app dev PORT lanes. Each entry writes PORT = base + <slot> * <devPortStride> into that app's .env.local, so parallel worktrees never fight for a port. <slot> is ALLOCATED and recorded per issue under the git-common-dir (kit-portslots.tsv), not hashed from the issue number: an issue keeps its slot while its worktree exists, and the slot is reclaimed once that worktree is gone. Best-effort: it only takes effect for an app that actually reads the file. `next dev -p ${PORT:-3003}` is expanded by the npm-script shell, which never reads .env.local, so the value is inert for it. cckit does not rely on this — whatever cckit launches itself receives its port explicitly.",
143
178
  "items": {
144
179
  "type": "object",
145
180
  "additionalProperties": true,
146
181
  "properties": {
147
182
  "path": { "type": "string", "description": "Repo-relative path to the app's .env.local file." },
148
- "base": { "type": "integer", "description": "Base port for this app's lane." }
183
+ "base": { "type": "integer", "description": "Base port for this app's lane. Every app's base must sit inside ONE devPortStride-wide window (e.g. 3001/3003/3004 with stride 10); a wider spread lets two worktrees' blocks overlap, and cckit warns when it sees one." }
149
184
  }
150
185
  }
186
+ },
187
+ "devPortStride": {
188
+ "type": "integer",
189
+ "minimum": 1,
190
+ "default": 10,
191
+ "description": "Distance between one worktree's port block and the next (default 10 — room for up to 10 services). It must NOT be the number of services: with stride == count, two bases congruent mod count hand the SAME port to two different worktrees (bases 3001/3003/3004 with count 3 gave worktree slot k+1's admin port to slot k's api). Widen it when a project declares more devPorts entries than the stride, or when its bases span further than one stride."
151
192
  }
152
193
  }
153
194
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jeiemgi/cckit",
3
- "version": "0.7.0",
3
+ "version": "0.8.0",
4
4
  "private": false,
5
5
  "license": "MIT OR Apache-2.0",
6
6
  "description": "cckit — a project operating system for coding agents (CLI + Claude Code plugin).",
@@ -0,0 +1,68 @@
1
+ #!/usr/bin/env bash
2
+ # Verify board selection and failure propagation through a non-git installed copy.
3
+ # errors: strict — fixture failures exit nonzero
4
+ set -euo pipefail
5
+ ROOT="$(cd "$(dirname "$0")/.." && pwd)"
6
+ TMP="$(mktemp -d)"; trap 'rm -rf "$TMP"' EXIT
7
+ mkdir -p "$TMP/install" "$TMP/project" "$TMP/bin"
8
+ cp -R "$ROOT/scripts" "$TMP/install/scripts"
9
+ git -C "$TMP/project" init -q
10
+ printf '%s\n' '{"github":{"repo":"fixture/project","baseBranch":"develop","projectsV2":false}}' > "$TMP/project/cckit.config.json"
11
+ export KIT_CONFIG="$TMP/project/cckit.config.json"
12
+ export FIXTURE_BOARD="$TMP/board.json"
13
+ cat > "$FIXTURE_BOARD" <<'JSON'
14
+ [
15
+ {"number":1,"title":"[Effort] 1 parent","labels":[],"assignees":[]},
16
+ {"number":2,"title":"label parent","labels":[{"name":"effort"}],"assignees":[]},
17
+ {"number":3,"title":"[Effort 1] 1 child","labels":[{"name":"role:tech-lead"}],"assignees":[]},
18
+ {"number":4,"title":"ordinary task","labels":[],"assignees":[]}
19
+ ]
20
+ JSON
21
+ cat > "$TMP/bin/gh" <<'STUB'
22
+ #!/usr/bin/env bash
23
+ case "$1 $2" in
24
+ 'issue list') [ "${FAIL_BOARD:-0}" = 0 ] || exit 1; cat "$FIXTURE_BOARD" ;;
25
+ 'api '*)
26
+ [ "${FAIL_DEPS:-0}" = 0 ] || exit 1
27
+ [ "${BLOCKER_STATE:-}" = '' ] || echo 99
28
+ exit 0 ;;
29
+ 'issue view') echo "${BLOCKER_STATE:-OPEN}" ;;
30
+ *) echo "unexpected gh call: $*" >&2; exit 1 ;;
31
+ esac
32
+ STUB
33
+ chmod +x "$TMP/bin/gh"
34
+ export PATH="$TMP/bin:$PATH"
35
+ cd "$TMP/project"
36
+ run() { bash "$TMP/install/scripts/autopilot.sh" --dry-run "$@"; }
37
+ has() { case "$1" in *"$2"*) : ;; *) echo "FAIL missing: $2"; exit 1 ;; esac; }
38
+ fails() { if "$@" > "$TMP/failure" 2>&1; then echo 'FAIL expected nonzero exit'; exit 1; fi; }
39
+ for agent in claude codex; do
40
+ out="$(run --agent "$agent")"
41
+ has "$out" 'would launch 2 flow(s): 3 4'
42
+ has "$out" "agent '$agent'"
43
+ done
44
+ out="$(run --cap 1)"; has "$out" 'would launch 1 flow(s): 3'; has "$out" 'queued past cap (run a later wave): 4'
45
+ out="$(BLOCKER_STATE=CLOSED run 3)"; has "$out" 'would launch 1 flow(s): 3'
46
+ export BLOCKER_STATE=OPEN
47
+ fails run 3
48
+ unset BLOCKER_STATE
49
+ export FAIL_DEPS=1
50
+ fails run 3
51
+ has "$(cat "$TMP/failure")" 'could not read blockers'
52
+ unset FAIL_DEPS
53
+ export FAIL_BOARD=1
54
+ fails run
55
+ has "$(cat "$TMP/failure")" 'could not read the board'
56
+ unset FAIL_BOARD
57
+ printf '%s\n' 'invalid JSON' > "$FIXTURE_BOARD"
58
+ fails run
59
+ has "$(cat "$TMP/failure")" 'invalid board data'
60
+ printf '%s\n' '[]' > "$FIXTURE_BOARD"
61
+ has "$(run 2>&1)" 'nothing open to drive'
62
+ fails run --cap 0 3
63
+ # The agent-facing format remains TOON for multiple rows; raw mode preserves label objects.
64
+ printf '%s\n' '[{"number":3,"title":"a","labels":[{"name":"effort"}],"assignees":[]},{"number":4,"title":"b","labels":[],"assignees":[]}]' > "$FIXTURE_BOARD"
65
+ raw="$(bash "$TMP/install/scripts/task-sync.sh" --raw-json)"
66
+ [ "$(printf '%s' "$raw" | jq -r '.[0].labels[0].name')" = effort ]
67
+ has "$(bash "$TMP/install/scripts/task-sync.sh" --llm)" '[2]{number,title,priority,labels,milestone,assignees,blocked}:'
68
+ echo 'PASS autopilot selection and failures for Claude and Codex launchers'
@@ -11,6 +11,8 @@
11
11
  # cckit autopilot 6 7 8 # drive exactly these issues
12
12
  # cckit autopilot --cap 3 # cap concurrent flows (passed through to orchestrate)
13
13
  # cckit autopilot --agent codex # drive a different agent CLI
14
+ # cckit autopilot --profile build # drive a declared agent profile (kind + argv)
15
+ # cckit autopilot --runtime herdr # run the selected agents in Herdr
14
16
  # cckit autopilot --dry-run # print the plan, launch nothing
15
17
  set -euo pipefail
16
18
 
@@ -18,17 +20,16 @@ PASS=() # flags forwarded to orchestrate
18
20
  ISSUES=()
19
21
  while [ "$#" -gt 0 ]; do
20
22
  case "$1" in
21
- --cap|--agent) PASS+=("$1" "$2"); shift 2 ;;
22
- --cap=*|--agent=*|--dry-run|--no-seed|--force|--session=*) PASS+=("$1"); shift ;;
23
- -h|--help) sed -n '2,17p' "$0" | sed 's/^# \{0,1\}//'; exit 0 ;;
23
+ --cap|--agent|--profile|--runtime) PASS+=("$1" "$2"); shift 2 ;;
24
+ --cap=*|--agent=*|--profile=*|--runtime=*|--dry-run|--no-seed|--force|--session=*) PASS+=("$1"); shift ;;
25
+ -h|--help) sed -n '2,16p' "$0" | sed 's/^# \{0,1\}//'; exit 0 ;;
24
26
  [0-9]*) ISSUES+=("$1"); shift ;;
25
27
  *) echo "autopilot: unknown arg '$1'" >&2; exit 2 ;;
26
28
  esac
27
29
  done
28
30
 
29
31
  SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
30
- ROOT="$(git -C "$SCRIPT_DIR" worktree list --porcelain | awk '/^worktree /{print $2; exit}')"
31
- [ -n "$ROOT" ] || { echo "autopilot: not in a git repo" >&2; exit 1; }
32
+ ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
32
33
 
33
34
  # No explicit issues -> auto-select from the board: open issues, minus effort PARENTS (the
34
35
  # "[Effort] N ..." umbrella issues that decompose into subs, identified by label:effort OR the
@@ -36,13 +37,18 @@ ROOT="$(git -C "$SCRIPT_DIR" worktree list --porcelain | awk '/^worktree /{print
36
37
  # blocked_by gate at launch; this is the coarse pre-filter so the board drives the wave.
37
38
  if [ "${#ISSUES[@]}" -eq 0 ]; then
38
39
  echo "autopilot: no issues passed - auto-selecting unblocked open issues from the board"
39
- board="$(bash "$ROOT/scripts/task-sync.sh" --llm)"
40
+ board="$(bash "$ROOT/scripts/task-sync.sh" --raw-json)" || {
41
+ echo "autopilot: could not read the board" >&2; exit 1;
42
+ }
43
+ # Capture the parser status before reading rows. Process substitution hides its failures.
44
+ selected="$(printf '%s' "$board" | jq -r '
45
+ if type != "array" then error("expected an issue array") else . end
46
+ | .[]
47
+ | select((any(.labels[]; .name == "effort")) or (.title | test("^\\[Effort\\] ")) | not)
48
+ | .number')" || { echo "autopilot: invalid board data" >&2; exit 1; }
40
49
  while IFS= read -r n; do
41
50
  [ -n "$n" ] && ISSUES+=("$n")
42
- done < <(printf '%s' "$board" | jq -r '
43
- .[]
44
- | select((any(.labels[]; . == "effort")) or (.title | test("^\\[Effort\\] ")) | not)
45
- | .number')
51
+ done <<< "$selected"
46
52
  [ "${#ISSUES[@]}" -ge 1 ] || { echo "autopilot: nothing open to drive" >&2; exit 0; }
47
53
  fi
48
54
 
package/scripts/check.sh CHANGED
@@ -58,7 +58,20 @@ if [ -f scripts/lib/secret-guard.sh ]; then
58
58
  secret_guard_scan || fail=1
59
59
  fi
60
60
 
61
- # 5. Behavioral tests - run every *-test.sh through the test runner.
61
+ # 5. Skill frontmatter context budget. `description` + `when_to_use` are concatenated into the
62
+ # always-loaded skill listing - resident in every session whether or not the skill is invoked.
63
+ # Ratchet, not a hard cap: today's over-budget skills are grandfathered in the baseline file and
64
+ # only *growth* (or a new over-budget skill) fails the gate.
65
+ note "==> skill frontmatter context budget"
66
+ bash scripts/skill-frontmatter-lint.sh || fail=1
67
+
68
+ # 6. Codified review findings. Mechanical defect classes caught in past reviews, encoded as rules
69
+ # in scripts/review-rules.conf so the same bug cannot land twice. Per-file ratchet: today's hits are
70
+ # grandfathered in the baseline, only new or grown hits fail. Rules needing intent stay with review.
71
+ note "==> codified review findings"
72
+ bash scripts/review-lint.sh || fail=1
73
+
74
+ # 7. Behavioral tests - run every *-test.sh through the test runner.
62
75
  note "==> behavioral tests"
63
76
  bash scripts/test.sh || fail=1
64
77
 
@@ -8,6 +8,9 @@
8
8
  # stop — with no open PRs the captain stops cleanly
9
9
  set -u
10
10
  ROOT="$(cd "$(dirname "$0")/.." && pwd)"
11
+ # Sealed from the caller's KIT_*/CCKIT_*/EFFORT_* (#369): this suite builds its own fixture.
12
+ # shellcheck source=/dev/null
13
+ . "$ROOT/scripts/lib/test-env.sh" && test_env_seal
11
14
  command -v jq >/dev/null 2>&1 || { echo "copilot-loop-test: jq required" >&2; exit 1; }
12
15
  fail=0
13
16
  ok() { if [ "$1" = "$2" ]; then echo "ok: $3"; else echo "FAIL: $3 -> got '[$1]' want '[$2]'"; fail=1; fi; }
@@ -0,0 +1,65 @@
1
+ #!/usr/bin/env bash
2
+ # guard-raw-git-ops-test.sh — end-to-end test of the raw-git guard hook (#364): feed it the
3
+ # PreToolUse JSON Claude Code sends, in a throwaway cckit repo and a non-cckit repo.
4
+ # Run: bash scripts/guard-raw-git-ops-test.sh
5
+ # errors: strict — a test runner: rc 1 on any failed assertion
6
+ set -u
7
+ ROOT="$(cd "$(dirname "$0")/.." && pwd)"
8
+ HOOK="$ROOT/templates/hooks/guard-raw-git-ops.sh.tmpl"
9
+ fail=0
10
+ t() { if [ "$2" = "$3" ]; then echo "ok: $1"; else echo "FAIL: $1 -> got '[$2]' want '[$3]'"; fail=1; fi; }
11
+ command -v jq >/dev/null 2>&1 || { echo "guard-raw-git-ops-test: jq required" >&2; exit 1; }
12
+
13
+ bash "$HOOK" --selftest >/dev/null || { echo "FAIL: classifier self-test (run: bash $HOOK --selftest)"; fail=1; }
14
+
15
+ tmp="$(mktemp -d)"; trap 'rm -rf "$tmp"' EXIT
16
+ kit="$tmp/kit"; plain="$tmp/plain"
17
+ for r in "$kit" "$plain"; do
18
+ git init -q -b develop "$r" && git -C "$r" -c user.email=t@t -c user.name=t commit -q --allow-empty -m init
19
+ done
20
+ mkdir -p "$kit/.claude"; printf '{"github":{"baseBranch":"develop"}}\n' > "$kit/.claude/kit.config.json"
21
+
22
+ run() { # <cwd> <command> -> echoes the hook's exit code
23
+ jq -n --arg c "$2" --arg d "$1" '{tool_input:{command:$c},cwd:$d}' | bash "$HOOK" >/dev/null 2>&1
24
+ echo $?
25
+ }
26
+
27
+ t "blocks gh issue create in a cckit repo" "$(run "$kit" 'gh issue create -t x -b y')" 2
28
+ t "blocks gh pr create in a cckit repo" "$(run "$kit" 'gh pr create --fill')" 2
29
+ t "blocks gh pr merge in a cckit repo" "$(run "$kit" 'gh pr merge 3 --squash')" 2
30
+ t "blocks gh issue close in a cckit repo" "$(run "$kit" 'gh issue close 3')" 2
31
+ t "blocks git checkout -b on the base branch" "$(run "$kit" 'git checkout -b feat/1-x')" 2
32
+ t "allows read-only gh" "$(run "$kit" 'gh pr view 3 --json body')" 0
33
+ t "allows the verbs" "$(run "$kit" 'cckit pr 3 "summary"')" 0
34
+ t "ignores a repo with no cckit config" "$(run "$plain" 'gh pr create --fill')" 0
35
+ t "resolves the repo from cd <dir>" "$(run "$plain" "cd $kit && gh pr create --fill")" 2
36
+
37
+ git -C "$kit" checkout -q -b feat/1-x
38
+ t "allows a branch cut off a non-base branch" "$(run "$kit" 'git checkout -b scratch')" 0
39
+ git -C "$kit" checkout -q develop
40
+
41
+ out="$(jq -n --arg c 'gh issue create -t x' --arg d "$kit" '{tool_input:{command:$c},cwd:$d}' | bash "$HOOK" 2>&1)"
42
+ case "$out" in *"cckit new --role"*) echo "ok: the block names the verb to run" ;; *) echo "FAIL: no verb hint in: $out"; fail=1 ;; esac
43
+
44
+ t "KIT_ALLOW_RAW=1 lets one command through" "$(run "$kit" 'KIT_ALLOW_RAW=1 gh pr create --fill')" 0
45
+ t "the bypass is recorded" "$(grep -c 'pr-create' "$kit/.git/cckit/raw-bypass.log" 2>/dev/null)" 1
46
+
47
+ # ── init / init --upgrade wire the guard into the TRACKED settings.json, once ─────────────────
48
+ proj="$tmp/proj"
49
+ git init -q "$proj" && git -C "$proj" -c user.email=t@t -c user.name=t commit -q --allow-empty -m init
50
+ mkdir -p "$proj/.claude"
51
+ printf '{"kitVersion":"0.0.1","profile":"software","project":{"name":"G","slug":"g"},"github":{"repo":"e/g","owner":"e","projectsV2":false}}\n' > "$proj/.claude/kit.config.json"
52
+ # a project's own PreToolUse hooks must survive the merge
53
+ printf '{"hooks":{"PreToolUse":[{"matcher":"Bash","hooks":[{"type":"command","command":"own-guard.sh"}]}]}}\n' > "$proj/.claude/settings.json"
54
+ for _ in 1 2; do
55
+ CLAUDE_PLUGIN_ROOT="$ROOT" bash "$ROOT/scripts/init.sh" --upgrade --target "$proj" --force >/dev/null 2>&1 \
56
+ || { echo "FAIL: init.sh --upgrade exited non-zero"; fail=1; }
57
+ done
58
+ S="$proj/.claude/settings.json"
59
+ t "init --upgrade copies the hook" "$([ -x "$proj/.claude/hooks/guard-raw-git-ops.sh" ] && echo yes)" yes
60
+ t "the guard is wired exactly once (2 upgrades)" "$(jq '[.hooks.PreToolUse[].hooks[] | select(.command | endswith("guard-raw-git-ops.sh"))] | length' "$S")" 1
61
+ t "the wiring uses \$CLAUDE_PROJECT_DIR" "$(jq -r '[.hooks.PreToolUse[].hooks[].command | select(endswith("guard-raw-git-ops.sh"))][0]' "$S")" '$CLAUDE_PROJECT_DIR/.claude/hooks/guard-raw-git-ops.sh'
62
+ t "the project's own hook is kept" "$(jq '[.hooks.PreToolUse[].hooks[] | select(.command == "own-guard.sh")] | length' "$S")" 1
63
+
64
+ [ "$fail" -eq 0 ] && echo "guard-raw-git-ops: all passed" || echo "guard-raw-git-ops: FAILURES"
65
+ exit "$fail"