@jeiemgi/cckit 0.6.1 → 0.7.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 (114) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/AGENTS.md +34 -3
  3. package/README.md +86 -5
  4. package/bin/cckit +72 -3
  5. package/cckit.config.json +6 -1
  6. package/kit.config.schema.json +26 -1
  7. package/package.json +1 -1
  8. package/profiles/automation.json +2 -1
  9. package/profiles/content.json +2 -1
  10. package/profiles/minimal.json +2 -1
  11. package/profiles/research.json +2 -1
  12. package/profiles/software.json +2 -1
  13. package/scripts/init.sh +31 -1
  14. package/scripts/lib/board-view-test.sh +1 -0
  15. package/scripts/lib/board-view.sh +1 -0
  16. package/scripts/lib/captain-test.sh +62 -0
  17. package/scripts/lib/captain.sh +105 -17
  18. package/scripts/lib/cckit-output.sh +1 -0
  19. package/scripts/lib/commitlint.sh +1 -0
  20. package/scripts/lib/config-path-test.sh +1 -0
  21. package/scripts/lib/config-path.sh +1 -0
  22. package/scripts/lib/copilot-test.sh +1 -0
  23. package/scripts/lib/copilot.sh +1 -0
  24. package/scripts/lib/effort-dispatch-test.sh +10 -0
  25. package/scripts/lib/effort-flows-test.sh +1 -0
  26. package/scripts/lib/effort-metrics-test.sh +1 -0
  27. package/scripts/lib/effort-metrics.sh +1 -0
  28. package/scripts/lib/effort-ops-test.sh +360 -0
  29. package/scripts/lib/effort-ops.sh +372 -16
  30. package/scripts/lib/effort-parity-test.sh +1 -0
  31. package/scripts/lib/effort-plan.sh +1 -0
  32. package/scripts/lib/effort-slug-test.sh +32 -0
  33. package/scripts/lib/effort-slug.sh +72 -8
  34. package/scripts/lib/effort.sh +1 -0
  35. package/scripts/lib/engine-adapter.sh +1 -0
  36. package/scripts/lib/errors-header-test.sh +86 -0
  37. package/scripts/lib/gh-log.sh +1 -0
  38. package/scripts/lib/gh-project-test.sh +1 -0
  39. package/scripts/lib/gh-project.sh +1 -0
  40. package/scripts/lib/git-remote-test.sh +1 -0
  41. package/scripts/lib/git-remote.sh +1 -0
  42. package/scripts/lib/handoff.sh +23 -2
  43. package/scripts/lib/kit-brief-test.sh +292 -0
  44. package/scripts/lib/kit-brief.sh +376 -0
  45. package/scripts/lib/kit-cli-test.sh +1 -0
  46. package/scripts/lib/kit-cli.sh +1 -0
  47. package/scripts/lib/kit-config-resolve.sh +1 -0
  48. package/scripts/lib/kit-config-test.sh +14 -0
  49. package/scripts/lib/kit-config.sh +7 -0
  50. package/scripts/lib/kit-engine-test.sh +1 -0
  51. package/scripts/lib/kit-events.sh +1 -0
  52. package/scripts/lib/kit-gc-test.sh +125 -0
  53. package/scripts/lib/kit-gc.sh +193 -5
  54. package/scripts/lib/kit-interview-test.sh +1 -0
  55. package/scripts/lib/kit-interview.sh +1 -0
  56. package/scripts/lib/kit-lib-test.sh +226 -0
  57. package/scripts/lib/kit-lib.sh +308 -0
  58. package/scripts/lib/kit-local.sh +1 -0
  59. package/scripts/lib/kit-manifest.sh +1 -0
  60. package/scripts/lib/kit-mode-test.sh +1 -0
  61. package/scripts/lib/kit-mode.sh +1 -0
  62. package/scripts/lib/kit-msg-test.sh +1 -0
  63. package/scripts/lib/kit-msg.sh +1 -0
  64. package/scripts/lib/kit-operate.sh +1 -0
  65. package/scripts/lib/kit-profile-test.sh +1 -0
  66. package/scripts/lib/kit-profile.sh +1 -0
  67. package/scripts/lib/kit-state-test.sh +89 -0
  68. package/scripts/lib/kit-state.sh +61 -0
  69. package/scripts/lib/kit-status-test.sh +233 -0
  70. package/scripts/lib/kit-status.sh +415 -0
  71. package/scripts/lib/kit-task-ops-test.sh +1 -0
  72. package/scripts/lib/kit-task-ops.sh +1 -0
  73. package/scripts/lib/next.sh +1 -0
  74. package/scripts/lib/plan-machine-test.sh +54 -0
  75. package/scripts/lib/plan-machine.sh +86 -25
  76. package/scripts/lib/plan-next-test.sh +1 -0
  77. package/scripts/lib/plan-next.sh +1 -0
  78. package/scripts/lib/pr-evidence-test.sh +259 -0
  79. package/scripts/lib/pr-evidence.sh +220 -35
  80. package/scripts/lib/project-scan.sh +1 -0
  81. package/scripts/lib/react-detect.sh +1 -0
  82. package/scripts/lib/render-test.sh +1 -0
  83. package/scripts/lib/render.sh +1 -0
  84. package/scripts/lib/role-identity.sh +1 -0
  85. package/scripts/lib/secret-guard.sh +21 -1
  86. package/scripts/lib/toon.sh +1 -0
  87. package/scripts/lib/ui.sh +1 -0
  88. package/scripts/lib/version-bump-test.sh +1 -0
  89. package/scripts/lib/version-bump.sh +1 -0
  90. package/scripts/lib/worktree-bootstrap-test.sh +220 -0
  91. package/scripts/lib/worktree-issue-test.sh +15 -1
  92. package/scripts/lib/worktree-issue.sh +23 -8
  93. package/scripts/lib/worktree-start.sh +191 -7
  94. package/scripts/lib/zsh-safety-test.sh +10 -0
  95. package/scripts/portable-test.sh +13 -2
  96. package/scripts/self-install-test.sh +282 -0
  97. package/scripts/setup-labels.sh +1 -0
  98. package/scripts/status.sh +25 -10
  99. package/skills/kit-cleanup/SKILL.md +83 -0
  100. package/skills/kit-effort-close/SKILL.md +3 -0
  101. package/skills/kit-effort-new/SKILL.md +7 -0
  102. package/skills/kit-effort-start/SKILL.md +39 -4
  103. package/skills/kit-gc/SKILL.md +19 -0
  104. package/skills/kit-next/SKILL.md +5 -0
  105. package/skills/kit-status/SKILL.md +92 -0
  106. package/skills/kit-task-start/SKILL.md +7 -1
  107. package/templates/rules/branch-naming.md +20 -1
  108. package/templates/rules/communication-style.md +8 -0
  109. package/templates/rules/delegation-brief.md +38 -4
  110. package/templates/rules/effort-model.md +47 -4
  111. package/templates/rules/naming-and-ids.md +199 -0
  112. package/templates/rules/task-management.md +1 -1
  113. package/templates/skills/concrete/SKILL.md +117 -0
  114. package/templates/skills/karpathy-guidelines/SKILL.md +1 -0
@@ -0,0 +1,220 @@
1
+ #!/bin/sh
2
+ # worktree-bootstrap-test.sh — the bootstrap dependency-install contract (#255), under bash AND zsh.
3
+ #
4
+ # The bug: wt_bootstrap ran `pnpm install` at the worktree ROOT unconditionally. Where the root
5
+ # manifest declares no dependencies (cckit itself is a published bash CLI — zero deps, zero scripts)
6
+ # pnpm resolves nothing but still writes a 9-line `pnpm-lock.yaml` with an empty `.: {}` importer.
7
+ # That stray lockfile then trips the captain's OWN lockfile policy floor and holds the PR for human
8
+ # review — cckit's bootstrap creating a file cckit's gate blocks.
9
+ #
10
+ # The bar: `pnpm install` runs exactly where the project actually declares dependencies — and the
11
+ # decision comes from the manifest, never from a hardcoded layout, because other repos use this kit.
12
+ #
13
+ # Run: bash scripts/lib/worktree-bootstrap-test.sh
14
+ # Without args: re-runs itself under every available shell. With WBT_INNER set: runs the assertions
15
+ # in the current interpreter.
16
+ # errors: strict — a test runner: rc 1 on any failed assertion
17
+
18
+ dir=$(CDPATH='' cd -- "$(dirname -- "$0")" && pwd)
19
+
20
+ if [ -n "${WBT_INNER:-}" ]; then
21
+ . "$dir/worktree-start.sh"
22
+ fail=0
23
+ n=0
24
+ ok() { n=$((n+1)); }
25
+ bad() { n=$((n+1)); echo "FAIL($WBT_INNER): $1"; fail=1; }
26
+
27
+ tmp=$(mktemp -d 2>/dev/null || mktemp -d -t wbt)
28
+ trap 'rm -rf "$tmp"' EXIT INT TERM
29
+
30
+ # A stub `pnpm` that does exactly the one thing that matters here: writes a lockfile in its cwd,
31
+ # the way real pnpm does. Put first on PATH so wt_bootstrap finds it instead of any real pnpm —
32
+ # the test must not depend on a network, a registry, or pnpm being installed at all.
33
+ mkdir -p "$tmp/bin"
34
+ cat > "$tmp/bin/pnpm" <<'STUB'
35
+ #!/bin/sh
36
+ printf "lockfileVersion: '9.0'\n\nimporters:\n\n .: {}\n" > pnpm-lock.yaml
37
+ mkdir -p node_modules
38
+ exit 0
39
+ STUB
40
+ chmod +x "$tmp/bin/pnpm"
41
+ PATH="$tmp/bin:$PATH"; export PATH
42
+
43
+ # fixture <name> <package.json-body> — a bare project dir; echoes its path.
44
+ fixture() {
45
+ d="$tmp/$1"; mkdir -p "$d"; printf '%s\n' "$2" > "$d/package.json"; printf '%s\n' "$d"
46
+ }
47
+
48
+ # targets <dir> — wt_install_targets output as a single space-joined string ('-' when empty), so
49
+ # an assertion reads as one comparison in both shells.
50
+ targets() { out=$(wt_install_targets "$1" | tr '\n' ' ' | sed 's/ *$//'); [ -n "$out" ] || out='-'; printf '%s\n' "$out"; }
51
+
52
+ # ── wt_install_targets: what the manifest says, nothing else ────────────────────────────────
53
+ # 1. A dependency-free root — cckit's own shape. Nothing to install.
54
+ bare=$(fixture bare '{"name":"bare","version":"1.0.0","bin":{"x":"bin/x"}}')
55
+ [ "$(targets "$bare")" = "-" ] || bad "dependency-free root should have no install target, got '$(targets "$bare")'"
56
+ ok
57
+
58
+ # 2. Empty dependency blocks are still no dependencies (pnpm would resolve nothing).
59
+ empty=$(fixture empty '{"name":"empty","dependencies":{},"devDependencies":{}}')
60
+ [ "$(targets "$empty")" = "-" ] || bad "empty dependency blocks should have no install target, got '$(targets "$empty")'"
61
+ ok
62
+
63
+ # 3. A root that DOES declare deps still installs — the fix must not break real projects.
64
+ deps=$(fixture deps '{"name":"deps","dependencies":{"left-pad":"^1.3.0"}}')
65
+ [ "$(targets "$deps")" = "." ] || bad "root with dependencies should install at '.', got '$(targets "$deps")'"
66
+ ok
67
+
68
+ # 4. devDependencies alone are enough.
69
+ dev=$(fixture dev '{"name":"dev","devDependencies":{"vitest":"^1.0.0"}}')
70
+ [ "$(targets "$dev")" = "." ] || bad "root with devDependencies should install at '.', got '$(targets "$dev")'"
71
+ ok
72
+
73
+ # 5. A pnpm workspace root installs even with no deps of its own — the MEMBERS hold them.
74
+ ws=$(fixture ws '{"name":"ws","private":true}')
75
+ printf 'packages:\n - "apps/*"\n' > "$ws/pnpm-workspace.yaml"
76
+ [ "$(targets "$ws")" = "." ] || bad "pnpm workspace root should install at '.', got '$(targets "$ws")'"
77
+ ok
78
+
79
+ # 6. A settings-only pnpm-workspace.yaml (pnpm 10 overrides/onlyBuiltDependencies, no `packages:`)
80
+ # is NOT a member-bearing workspace — cckit's docs-site has exactly this file.
81
+ set_only=$(fixture setonly '{"name":"setonly"}')
82
+ printf 'onlyBuiltDependencies:\n - sharp\noverrides:\n esbuild: ">=0.28.1"\n' > "$set_only/pnpm-workspace.yaml"
83
+ [ "$(targets "$set_only")" = "-" ] || bad "settings-only pnpm-workspace.yaml is not a workspace root, got '$(targets "$set_only")'"
84
+ ok
85
+
86
+ # 7. npm/yarn `workspaces` in package.json counts too.
87
+ nws=$(fixture nws '{"name":"nws","private":true,"workspaces":["packages/*"]}')
88
+ [ "$(targets "$nws")" = "." ] || bad "npm workspaces root should install at '.', got '$(targets "$nws")'"
89
+ ok
90
+
91
+ # ── a workspace declaration with NO MEMBERS is not a workspace root ─────────────────────────
92
+ # The `packages:` KEY alone is not enough. An empty member list leaves pnpm nothing to resolve,
93
+ # so it writes only the empty-importer lockfile — the #255 symptom, re-created through the
94
+ # workspace branch instead of the dependency branch.
95
+ ws0=$(fixture ws0 '{"name":"ws0"}')
96
+ printf 'packages: []\n' > "$ws0/pnpm-workspace.yaml"
97
+ [ "$(targets "$ws0")" = "-" ] || bad "'packages: []' declares no members — should not install, got '$(targets "$ws0")'"
98
+ ok
99
+
100
+ wsb=$(fixture wsb '{"name":"wsb"}')
101
+ printf 'packages:\nonlyBuiltDependencies:\n - sharp\n' > "$wsb/pnpm-workspace.yaml"
102
+ [ "$(targets "$wsb")" = "-" ] || bad "an empty 'packages:' block declares no members, got '$(targets "$wsb")'"
103
+ ok
104
+
105
+ # …but the inline flow-sequence form with a real pattern still counts.
106
+ wsi=$(fixture wsi '{"name":"wsi"}')
107
+ printf 'packages: ["apps/*", "libs/*"]\n' > "$wsi/pnpm-workspace.yaml"
108
+ [ "$(targets "$wsi")" = "." ] || bad "inline 'packages: [\"apps/*\"]' is a workspace root, got '$(targets "$wsi")'"
109
+ ok
110
+
111
+ # The same three empty shapes on the package.json side.
112
+ jw0=$(fixture jw0 '{"name":"jw0","workspaces":[]}')
113
+ [ "$(targets "$jw0")" = "-" ] || bad "'workspaces: []' declares no members, got '$(targets "$jw0")'"
114
+ ok
115
+
116
+ jwo=$(fixture jwo '{"name":"jwo","workspaces":{}}')
117
+ [ "$(targets "$jwo")" = "-" ] || bad "'workspaces: {}' declares no members, got '$(targets "$jwo")'"
118
+ ok
119
+
120
+ jwp=$(fixture jwp '{"name":"jwp","workspaces":{"nohoist":["x"],"packages":[]}}')
121
+ [ "$(targets "$jwp")" = "-" ] || bad "'workspaces.packages: []' declares no members, got '$(targets "$jwp")'"
122
+ ok
123
+
124
+ # …and the yarn object form WITH members still counts.
125
+ jwm=$(fixture jwm '{"name":"jwm","workspaces":{"packages":["packages/*"]}}')
126
+ [ "$(targets "$jwm")" = "." ] || bad "'workspaces.packages: [\"packages/*\"]' is a workspace root, got '$(targets "$jwm")'"
127
+ ok
128
+
129
+ # 8. `.worktree.installPaths` wins outright — the generic knob for repos whose Node project lives
130
+ # in a subdirectory (cckit's own `docs-site/`). No project layout is hardcoded in the kit.
131
+ if command -v jq >/dev/null 2>&1; then
132
+ sub=$(fixture sub '{"name":"sub"}')
133
+ mkdir -p "$sub/.claude" "$sub/docs-site"
134
+ printf '{"worktree":{"installPaths":["docs-site"]}}\n' > "$sub/.claude/kit.config.json"
135
+ printf '{"name":"docs","dependencies":{"astro":"^5"}}\n' > "$sub/docs-site/package.json"
136
+ [ "$(targets "$sub")" = "docs-site" ] || bad "installPaths should scope the install, got '$(targets "$sub")'"
137
+ ok
138
+
139
+ # 8b. An empty installPaths array is an explicit "install nothing".
140
+ none=$(fixture none '{"name":"none","dependencies":{"left-pad":"^1"}}')
141
+ printf '{"worktree":{"installPaths":[]}}\n' > "$none/cckit.config.json"
142
+ [ "$(targets "$none")" = "-" ] || bad "installPaths [] should install nothing, got '$(targets "$none")'"
143
+ ok
144
+
145
+ # ── installPaths must never escape the worktree ────────────────────────────────────────────
146
+ # A worktree sits at <root>/.claude/worktrees/<kind>+<N>-<slug>, three levels under the primary
147
+ # checkout — which is SHARED and may have another session's work parked on it. A `../../..`
148
+ # entry that reached the `cd` would run pnpm in that tree. Config is input; it gets validated.
149
+ mkdir -p "$tmp/victim/inner/esc"
150
+ printf '{"name":"VICTIM","dependencies":{"left-pad":"^1"}}\n' > "$tmp/victim/package.json"
151
+ printf '{"name":"esc"}\n' > "$tmp/victim/inner/esc/package.json"
152
+ mkdir -p "$tmp/victim/inner/esc/.claude"
153
+ esc="$tmp/victim/inner/esc"
154
+
155
+ printf '{"worktree":{"installPaths":["../.."]}}\n' > "$esc/.claude/kit.config.json"
156
+ [ "$(targets "$esc" 2>/dev/null)" = "-" ] || bad "'../..' should be refused, got '$(targets "$esc" 2>/dev/null)'"
157
+ wt_bootstrap "$esc" "$esc" 255 >/dev/null 2>&1
158
+ [ -f "$tmp/victim/pnpm-lock.yaml" ] && bad "traversal escaped the worktree — pnpm ran OUTSIDE it"
159
+ ok; ok
160
+
161
+ # An absolute path is never a worktree-relative target.
162
+ printf '{"worktree":{"installPaths":["%s"]}}\n' "$tmp/victim" > "$esc/.claude/kit.config.json"
163
+ [ "$(targets "$esc" 2>/dev/null)" = "-" ] || bad "an absolute installPaths entry should be refused"
164
+ ok
165
+
166
+ # A path that climbs and comes back is fine — it stays inside. It normalizes on the way out.
167
+ mkdir -p "$esc/docs-site"
168
+ printf '{"name":"d","dependencies":{"astro":"^5"}}\n' > "$esc/docs-site/package.json"
169
+ printf '{"worktree":{"installPaths":["./docs-site/../docs-site/"]}}\n' > "$esc/.claude/kit.config.json"
170
+ [ "$(targets "$esc" 2>/dev/null)" = "docs-site" ] || bad "a contained path should normalize to 'docs-site', got '$(targets "$esc" 2>/dev/null)'"
171
+ ok
172
+
173
+ # A symlink out of the tree is the escape the lexical check alone cannot see.
174
+ if ln -s "$tmp/victim" "$esc/link-out" 2>/dev/null; then
175
+ printf '{"worktree":{"installPaths":["link-out"]}}\n' > "$esc/.claude/kit.config.json"
176
+ [ "$(targets "$esc" 2>/dev/null)" = "-" ] || bad "a symlink pointing outside the worktree should be refused"
177
+ wt_bootstrap "$esc" "$esc" 255 >/dev/null 2>&1
178
+ [ -f "$tmp/victim/pnpm-lock.yaml" ] && bad "symlink escape let pnpm run OUTSIDE the worktree"
179
+ ok; ok
180
+ fi
181
+ fi
182
+
183
+ # ── wt_bootstrap end to end: does a root pnpm-lock.yaml appear? ─────────────────────────────
184
+ # The regression itself. Root and worktree are the same fixture dir: the env-copy step is then a
185
+ # no-op and the install step is what is under test.
186
+ wt_bootstrap "$bare" "$bare" 255 >/dev/null 2>&1
187
+ [ -f "$bare/pnpm-lock.yaml" ] && bad "wt_bootstrap planted a root pnpm-lock.yaml in a dependency-free project (#255)"
188
+ ok
189
+
190
+ # …and the other half of the bar: a project WITH root deps still gets its install.
191
+ wt_bootstrap "$deps" "$deps" 255 >/dev/null 2>&1
192
+ [ -f "$deps/pnpm-lock.yaml" ] || bad "wt_bootstrap skipped the install for a project that DOES declare dependencies"
193
+ ok
194
+
195
+ # The existing escape hatch still wins over everything.
196
+ KIT_WT_INSTALL=0 wt_bootstrap "$dev" "$dev" 255 >/dev/null 2>&1
197
+ [ -f "$dev/pnpm-lock.yaml" ] && bad "KIT_WT_INSTALL=0 no longer skips the install"
198
+ ok
199
+
200
+ # Scoped install lands in the subdirectory and NOT at the root.
201
+ if command -v jq >/dev/null 2>&1; then
202
+ wt_bootstrap "$sub" "$sub" 255 >/dev/null 2>&1
203
+ [ -f "$sub/docs-site/pnpm-lock.yaml" ] || bad "scoped install did not run in docs-site"
204
+ [ -f "$sub/pnpm-lock.yaml" ] && bad "scoped install still planted a ROOT pnpm-lock.yaml"
205
+ ok; ok
206
+ fi
207
+
208
+ [ "$fail" -eq 0 ] && echo "OK($WBT_INNER): $n cases"
209
+ exit "$fail"
210
+ fi
211
+
212
+ rc=0
213
+ ran=0
214
+ for sh in bash zsh; do
215
+ command -v "$sh" >/dev/null 2>&1 || continue
216
+ ran=1
217
+ WBT_INNER="$sh" "$sh" "$0" || rc=1
218
+ done
219
+ [ "$ran" -eq 1 ] || { echo "no bash/zsh found"; exit 1; }
220
+ exit "$rc"
@@ -5,6 +5,7 @@
5
5
  #
6
6
  # Without args: re-runs itself under every available shell. With WT_TEST_INNER set:
7
7
  # runs the assertions in the current interpreter.
8
+ # errors: strict — a test runner: rc 1 on any failed assertion
8
9
 
9
10
  dir=$(CDPATH='' cd -- "$(dirname -- "$0")" && pwd)
10
11
 
@@ -30,7 +31,20 @@ if [ -n "${WT_TEST_INNER:-}" ]; then
30
31
  check "main" "" # base branch
31
32
  check "task/29a3-x" "" # malformed number
32
33
  check "task/293mobbin" "" # missing dash
33
- [ "$fail" -eq 0 ] && echo "OK($WT_TEST_INNER): 12 cases"
34
+ check "sub/1604a-parser" "1604" # effort sub form <N><letter>
35
+ check "sub/1283m-x" "1283" # effort sub, later letter
36
+ check "sub+1604a-parser" "1604" # effort sub worktree dirname
37
+ check "sub/1604a4-x" "" # letter not trailing
38
+ check "sub/16a04-x" "" # letter embedded mid-number
39
+ check "sub/1604A-x" "" # uppercase suffix is not the sub form
40
+ check "sub/a-x" "" # letter with no number
41
+ # The <N><letter> suffix is accepted for EVERY lowercase kind, not just `sub`. Deliberate: a
42
+ # spurious association can only ever ADD issue-open protection (an unrelated #N is either open
43
+ # → keep, or closed/absent → no claim), never remove it. Narrowing this to `sub` would make gc
44
+ # willing to delete a misnamed live branch — the failure mode this whole lib exists to prevent.
45
+ check "feat/1604a-parser" "1604" # non-sub kind, suffix still protects
46
+ check "feat+1604a-parser" "1604" # same, worktree dirname form
47
+ [ "$fail" -eq 0 ] && echo "OK($WT_TEST_INNER): 21 cases"
34
48
  exit "$fail"
35
49
  fi
36
50
 
@@ -12,8 +12,27 @@
12
12
  # Portable: POSIX parameter expansion only — sourceable from bash 3.2+ AND zsh (#307;
13
13
  # BASH_REMATCH stays silently empty in zsh, which switched the gc protection off).
14
14
  # Self-test: bash scripts/lib/worktree-issue-test.sh (runs the cases under bash + zsh)
15
+ # errors: mixed — name parsing is pure; the issue-open check needs gh
15
16
 
16
17
  # Echo the issue number a branch name / worktree path belongs to (empty if none, e.g. bot branches).
18
+ # Normalize the numeric segment of a branch/dir name to an issue number.
19
+ # Accepts "1602" and also the effort SUB form "1604a" — `sub/<N><letter>-<slug>` is the documented
20
+ # sub-branch convention, and rejecting it meant every effort sub-branch parsed to "" and so got NO
21
+ # issue-open protection at all (gc listed live subs of an open effort as SAFE to delete).
22
+ # Exactly one trailing lowercase letter is stripped; anything else is not an issue number.
23
+ _wt_normalize_issue_num() {
24
+ local n="$1" head tail
25
+ case "$n" in
26
+ '') return 0 ;;
27
+ *[!0-9]*) : ;; # has a non-digit — only the sub form survives
28
+ *) printf '%s' "$n"; return 0 ;; # pure digits
29
+ esac
30
+ head="${n%?}"; tail="${n#"$head"}"
31
+ case "$tail" in [a-z]) : ;; *) return 0 ;; esac # last char must be one lowercase letter
32
+ case "$head" in ''|*[!0-9]*) return 0 ;; esac # everything before it must be pure digits
33
+ printf '%s' "$head"
34
+ }
35
+
17
36
  wt_issue_number() {
18
37
  local ref="$1" base kind rest n
19
38
  # branch form: kind/N-slug (kind = lowercase letters only, anchored at start)
@@ -24,10 +43,8 @@ wt_issue_number() {
24
43
  *)
25
44
  n="${rest%%-*}"
26
45
  if [ "$n" != "$rest" ]; then # a "-" follows the number
27
- case "$n" in
28
- ''|*[!0-9]*) : ;;
29
- *) printf '%s' "$n"; return 0 ;;
30
- esac
46
+ n="$(_wt_normalize_issue_num "$n")"
47
+ [ -n "$n" ] && { printf '%s' "$n"; return 0; }
31
48
  fi
32
49
  ;;
33
50
  esac
@@ -41,10 +58,8 @@ wt_issue_number() {
41
58
  esac
42
59
  n="${rest%%-*}"
43
60
  [ "$n" = "$rest" ] && return 0 # no "-" after the number
44
- case "$n" in
45
- ''|*[!0-9]*) : ;;
46
- *) printf '%s' "$n" ;;
47
- esac
61
+ n="$(_wt_normalize_issue_num "$n")"
62
+ [ -n "$n" ] && printf '%s' "$n"
48
63
  fi
49
64
  return 0
50
65
  }
@@ -10,6 +10,7 @@
10
10
  # returns: 0 on success (created or reused), 1 on failure
11
11
  #
12
12
  # Requires: gh, jq, git, scripts/lib/gh-project.sh (board update). bash 3.2 compatible.
13
+ # errors: strict — rc 1 on failure; a half-made worktree is never reported as ready
13
14
 
14
15
  WT_START_REPO="${WT_START_REPO:-${KIT_REPO:-}}"
15
16
 
@@ -50,12 +51,178 @@ wt_assign_ports() {
50
51
  done
51
52
  }
52
53
 
54
+ # ── Where does `pnpm install` actually have work to do? (#255) ────────────────────────────────
55
+ # The bootstrap install used to run unconditionally at the worktree ROOT. In a repo whose root
56
+ # manifest declares no dependencies (a published CLI, a docs-only repo, a shell toolkit), pnpm has
57
+ # nothing to resolve — but it still WRITES a 9-line `pnpm-lock.yaml` with an empty `.: {}` importer.
58
+ # That stray lockfile then trips the captain's own policy floor (captain.sh, lockfile/dependency-
59
+ # graph paths) and HOLDS the PR for human review. The helpers below answer "is there anything to
60
+ # install, and where?" from the project's ACTUAL manifest — never from a hardcoded layout.
61
+
62
+ # _wt_cfg <dir> — path to <dir>'s project config, or nothing. Mirrors config-path.sh's two supported
63
+ # layouts (self-host root `cckit.config.json`, scaffolded `.claude/kit.config.json`) without taking
64
+ # a source-time dependency on it — worktree-start.sh is sourced standalone by effort-ops.sh.
65
+ _wt_cfg() {
66
+ [[ -f "$1/cckit.config.json" ]] && { printf '%s\n' "$1/cckit.config.json"; return 0; }
67
+ [[ -f "$1/.claude/kit.config.json" ]] && { printf '%s\n' "$1/.claude/kit.config.json"; return 0; }
68
+ return 1
69
+ }
70
+
71
+ # _wt_json_has <file> <jq-filter> <fallback-regex> — true when <file> satisfies <jq-filter>. jq is
72
+ # the stated dependency of this lib, but the install decision must stay correct without it, so a
73
+ # whitespace-stripped regex over the raw JSON is the fallback. Never fails the caller.
74
+ _wt_json_has() {
75
+ local file="$1" filter="$2" re="$3"
76
+ [[ -f "$file" ]] || return 1
77
+ if command -v jq >/dev/null 2>&1; then
78
+ jq -e "$filter" "$file" >/dev/null 2>&1
79
+ else
80
+ tr -d ' \n\t' < "$file" 2>/dev/null | grep -qE "$re"
81
+ fi
82
+ }
83
+
84
+ # _wt_manifest_has_deps <dir> — true when <dir>/package.json declares at least ONE dependency in any
85
+ # of the four dependency blocks. An empty block (`"dependencies": {}`) counts as none: pnpm would
86
+ # resolve nothing and write only the empty-importer lockfile.
87
+ _wt_manifest_has_deps() {
88
+ _wt_json_has "$1/package.json" \
89
+ '[(.dependencies,.devDependencies,.optionalDependencies,.peerDependencies)
90
+ | select(type=="object") | length] | add // 0 | . > 0' \
91
+ '"(dependencies|devDependencies|optionalDependencies|peerDependencies)":\{"'
92
+ }
93
+
94
+ # _wt_yaml_has_members <file> — true when a pnpm-workspace.yaml declares at least one ACTUAL member
95
+ # pattern under `packages:`. The KEY alone is not enough: `packages: []` and a `packages:` with an
96
+ # empty block below it declare no members, so pnpm resolves nothing and writes only the empty-
97
+ # importer lockfile — the exact #255 symptom. Handles both YAML sequence forms:
98
+ # packages: ["apps/*"] (inline flow) packages: (block)
99
+ # - "apps/*"
100
+ # Comments are stripped first so `packages: [] # later` and `- # nothing` can't fake a member.
101
+ _wt_yaml_has_members() {
102
+ [[ -f "$1" ]] || return 1
103
+ awk '
104
+ { line = $0; sub(/^[[:space:]]*#.*$/, "", line); sub(/[[:space:]]+#.*$/, "", line) }
105
+ inblock {
106
+ if (line ~ /^[[:space:]]*$/) next
107
+ # a member entry: "- " followed by something real
108
+ if (line ~ /^[[:space:]]*-[[:space:]]*[^[:space:]]/) { found = 1; exit }
109
+ inblock = 0 # any other content ends the block without a member
110
+ }
111
+ !inblock {
112
+ if (line ~ /^[[:space:]]*packages:[[:space:]]*\[/) {
113
+ rest = line; sub(/^[^[]*\[/, "", rest); gsub(/[[:space:]]/, "", rest)
114
+ if (rest !~ /^\]/) { found = 1; exit } # non-empty inline flow sequence
115
+ } else if (line ~ /^[[:space:]]*packages:[[:space:]]*$/) {
116
+ inblock = 1
117
+ }
118
+ }
119
+ END { exit(found ? 0 : 1) }
120
+ ' "$1" 2>/dev/null
121
+ }
122
+
123
+ # _wt_is_workspace_root <dir> — true when <dir> is the root of a package-manager workspace WITH AT
124
+ # LEAST ONE MEMBER. Such a root legitimately declares no dependencies of its own (the members hold
125
+ # them) and its root lockfile is the real one, so `pnpm install` there IS genuine work.
126
+ #
127
+ # A declaration with no members is NOT a workspace root, and this distinction is the whole point:
128
+ # `packages: []`, `"workspaces": []`, `"workspaces": {}` and `"workspaces": {"packages": []}` all
129
+ # leave pnpm with nothing to resolve, so treating them as workspace roots would re-create #255.
130
+ # Likewise a `pnpm-workspace.yaml` carrying only settings (pnpm 10 `overrides:` /
131
+ # `onlyBuiltDependencies:`) with no `packages:` key at all.
132
+ _wt_is_workspace_root() {
133
+ local d="$1" f
134
+ for f in "$d/pnpm-workspace.yaml" "$d/pnpm-workspace.yml"; do
135
+ _wt_yaml_has_members "$f" && return 0
136
+ done
137
+ # package.json `workspaces`: the array form IS the member list; the object form (npm/yarn) keeps
138
+ # it under `.packages` alongside `nohoist`. Either way, count real non-empty patterns.
139
+ _wt_json_has "$d/package.json" \
140
+ 'def members: if type=="array" then . elif type=="object" then (.packages // []) else [] end;
141
+ ((.workspaces // null) | members | map(select(type=="string" and length > 0)) | length) > 0' \
142
+ '"workspaces":(\["|\{[^}]*"packages":\[")'
143
+ }
144
+
145
+ # _wt_safe_target <worktree> <target> — echo the normalized, worktree-relative form of <target> when
146
+ # it is SAFE to install in; nothing + rc 1 otherwise. A target MUST stay inside the worktree.
147
+ #
148
+ # This is not hypothetical: a worktree lives at `<root>/.claude/worktrees/<kind>+<N>-<slug>`, three
149
+ # levels under the primary checkout, so an installPaths entry of `../../..` would run `pnpm install`
150
+ # in the SHARED main checkout — writing node_modules and a pnpm-lock.yaml into whatever another
151
+ # session has parked there. Config is project-controlled input, so it gets validated like input.
152
+ #
153
+ # Two gates, because they catch different escapes:
154
+ # • lexical — reject an absolute path, and resolve `.`/`..` segments, failing if they climb above
155
+ # the worktree. Pure parameter expansion (no `set --`, which zsh does not word-split), so it
156
+ # works on a path that does not exist yet and behaves identically in bash and zsh.
157
+ # • physical — when the directory does exist, compare `pwd -P` against the worktree's, which is
158
+ # the only thing that catches a symlink pointing out of the tree.
159
+ _wt_safe_target() {
160
+ local wt="$1" t="$2" rest seg out="" base abs
161
+ [[ -n "$t" ]] || return 1
162
+ case "$t" in /*) return 1 ;; esac # absolute — never a worktree-relative target
163
+ rest="$t"
164
+ while [[ -n "$rest" ]]; do
165
+ seg="${rest%%/*}"
166
+ if [[ "$seg" == "$rest" ]]; then rest=""; else rest="${rest#*/}"; fi
167
+ case "$seg" in
168
+ ''|'.') continue ;;
169
+ '..')
170
+ [[ -n "$out" ]] || return 1 # climbing above the worktree root
171
+ case "$out" in */*) out="${out%/*}" ;; *) out="" ;; esac ;;
172
+ *) out="${out:+$out/}$seg" ;;
173
+ esac
174
+ done
175
+ out="${out:-.}"
176
+ base="$(cd -P "$wt" 2>/dev/null && pwd -P)" || return 1
177
+ if [[ -d "$wt/$out" ]]; then
178
+ abs="$(cd -P "$wt/$out" 2>/dev/null && pwd -P)" || return 1
179
+ case "$abs" in "$base"|"$base"/*) : ;; *) return 1 ;; esac
180
+ fi
181
+ printf '%s\n' "$out"
182
+ }
183
+
184
+ # wt_install_targets <worktree> — emit one worktree-relative directory per line that the bootstrap
185
+ # should run `pnpm install` in. Every emitted target is validated to live INSIDE the worktree
186
+ # (_wt_safe_target). Empty output means "nothing to install" — the correct answer for a
187
+ # dependency-free root. Decision order:
188
+ # 1. `.worktree.installPaths` in the project config wins outright — explicit project intent for
189
+ # repos whose Node projects live in subdirectories (e.g. ["docs-site"]). `[]` means install
190
+ # nothing. This is the generic escape hatch; the kit hardcodes no project's layout.
191
+ # 2. Otherwise the worktree root ".", but ONLY when its manifest declares dependencies or it is a
192
+ # workspace root.
193
+ # 3. Otherwise nothing.
194
+ wt_install_targets() {
195
+ local wt="$1" cfg paths n i p safe
196
+ if cfg="$(_wt_cfg "$wt")" && command -v jq >/dev/null 2>&1; then
197
+ paths="$(jq -c '.worktree.installPaths // empty' "$cfg" 2>/dev/null)"
198
+ if [[ -n "$paths" && "$paths" != "null" ]]; then
199
+ n="$(jq 'length' <<<"$paths" 2>/dev/null)"; [[ "$n" =~ ^[0-9]+$ ]] || return 0
200
+ i=0
201
+ while [[ "$i" -lt "$n" ]]; do
202
+ p="$(jq -r ".[$i] // empty" <<<"$paths")"
203
+ if [[ -n "$p" ]]; then
204
+ if safe="$(_wt_safe_target "$wt" "$p")"; then
205
+ printf '%s\n' "$safe"
206
+ else
207
+ echo "wt_install_targets: refusing installPaths entry '$p' — outside the worktree" >&2
208
+ fi
209
+ fi
210
+ i=$(( i + 1 ))
211
+ done
212
+ return 0
213
+ fi
214
+ fi
215
+ _wt_manifest_has_deps "$wt" || _wt_is_workspace_root "$wt" || return 0
216
+ printf '.\n'
217
+ }
218
+
53
219
  # wt_bootstrap <root> <worktree> <issue-num> — make a fresh worktree runnable for local dev.
54
220
  # A new worktree inherits no .gitignored local config and no node_modules, and parallel worktrees
55
- # collide on the hardcoded dev port. This copies the local env, installs deps, and assigns a
56
- # per-worktree dev port. Every step is best-effort + idempotent — never fail the start (#773).
221
+ # collide on the hardcoded dev port. This copies the local env, assigns a per-worktree dev port, and
222
+ # installs deps WHERE THERE ARE ANY (wt_install_targets — #255). Every step is best-effort +
223
+ # idempotent — never fail the start (#773).
57
224
  wt_bootstrap() {
58
- local root="$1" wt="$2" num="$3" rel src dst offset
225
+ local root="$1" wt="$2" num="$3" rel src dst offset target where ran
59
226
  [[ -d "$wt" ]] || return 0
60
227
 
61
228
  # 1. Copy gitignored local config the worktree can't inherit: every .env.local* + project ids.
@@ -78,12 +245,29 @@ wt_bootstrap() {
78
245
  wt_assign_ports "$wt" "$num" "$root"
79
246
 
80
247
  # 3. Install deps — node_modules is per-worktree, not shared. Opt out with KIT_WT_INSTALL=0.
248
+ # Runs ONLY where wt_install_targets says there is genuinely something to install. A root
249
+ # manifest with no dependencies is skipped: pnpm would resolve nothing and leave behind an
250
+ # empty `pnpm-lock.yaml` that the captain's lockfile policy floor then holds the PR on (#255).
81
251
  if [[ "${KIT_WT_INSTALL:-1}" != "0" ]] && command -v pnpm >/dev/null 2>&1; then
82
- echo "[#$num] pnpm install (set KIT_WT_INSTALL=0 to skip)..." >&2
83
- ( cd "$wt" && pnpm install --prefer-offline >/dev/null 2>&1 ) \
84
- && echo "[#$num] deps installed" >&2 \
85
- || echo "[#$num] pnpm install failed — run 'pnpm install' in the worktree manually" >&2
252
+ ran=0
253
+ while IFS= read -r target; do
254
+ [[ -n "$target" ]] || continue
255
+ # Re-validate containment at the point of USE, not just where the target was produced: this
256
+ # is the line that actually `cd`s and runs pnpm, so it is the one that must never be talked
257
+ # into stepping outside the worktree (a `../../..` would land in the shared main checkout).
258
+ target="$(_wt_safe_target "$wt" "$target")" || continue
259
+ [[ -d "$wt/$target" && -f "$wt/$target/package.json" ]] || continue
260
+ ran=1
261
+ [[ "$target" == "." ]] && where="" || where=" in $target"
262
+ echo "[#$num] pnpm install$where (set KIT_WT_INSTALL=0 to skip)..." >&2
263
+ ( cd "$wt/$target" && pnpm install --prefer-offline >/dev/null 2>&1 ) \
264
+ && echo "[#$num] deps installed$where" >&2 \
265
+ || echo "[#$num] pnpm install$where failed — run 'pnpm install' there manually" >&2
266
+ done < <(wt_install_targets "$wt")
267
+ [[ "$ran" == "0" ]] \
268
+ && echo "[#$num] no dependencies declared — skipping pnpm install" >&2
86
269
  fi
270
+ return 0
87
271
  }
88
272
 
89
273
  # ── Idle-worktree pool (OPT-IN, KIT_WT_POOL=1) ──────────────────────────────────────────────
@@ -11,6 +11,7 @@
11
11
  #
12
12
  # Skips (rc 0) when zsh is absent, so the gate stays dependency-light (CI installs zsh, so it runs
13
13
  # there). bash 3.2 compatible. Run: bash scripts/lib/zsh-safety-test.sh
14
+ # errors: strict — a test runner: rc 1 on any failed assertion
14
15
  set -u
15
16
  ROOT="$(cd "$(dirname "$0")/../.." && pwd)"
16
17
  LIB="$ROOT/scripts/lib"
@@ -46,6 +47,15 @@ run_zsh "kit-config.sh :: load_kit_config" \
46
47
  run_zsh "kit-gc.sh :: kit_gc_analyze" \
47
48
  "cd '$ROOT'; export KIT_GC_REPO=jeiemgi/cckit; source scripts/lib/kit-config.sh; load_kit_config >/dev/null 2>&1; source scripts/lib/kit-gc.sh; kit_gc_analyze >/dev/null 2>&1"
48
49
 
50
+ # kit-gc.sh — the sibling-lib load itself (#219). `BASH_SOURCE` is bash-only and an interactive zsh
51
+ # echoes the directory after a `cd`, so both the old `${(%):-%x}` and a bare `$(cd … && pwd)` left
52
+ # worktree-issue.sh unsourced — `wt_protected_reason` undefined, so every branch looked SAFE.
53
+ # `unset -f` first: this runs `zsh -i`, which sources the user's init. If that already defined
54
+ # `wt_protected_reason`, `_kit_gc_load_deps` returns early and the case would pass without ever
55
+ # resolving the dir — the exact thing under test.
56
+ run_zsh "kit-gc.sh :: sibling worktree-issue.sh actually loads" \
57
+ "cd '$ROOT'; unset -f wt_protected_reason 2>/dev/null; source scripts/lib/kit-gc.sh; _kit_gc_load_deps >/dev/null 2>&1; command -v wt_protected_reason >/dev/null 2>&1"
58
+
49
59
  # worktree-start.sh — the `path` local in wt_assign_ports (no-op without .worktree.devPorts).
50
60
  run_zsh "worktree-start.sh :: wt_assign_ports" \
51
61
  "cd '$ROOT'; source scripts/lib/worktree-start.sh; wt_assign_ports '$ROOT' 1 '$ROOT' >/dev/null 2>&1"
@@ -70,7 +70,10 @@ t "version is the install version, not the project's" "$got_ver" "$(jq -r '.kitV
70
70
  # ── BY CONSTRUCTION: exercise every read-only verb; none may resolve cckit's OWN repo ─────────────
71
71
  # Read-only board/config verbs that MUST act on the invoking project. Run each from the fixture and
72
72
  # assert the gh call log never mentions cckit's own repo (the leak this whole effort guards against).
73
- EXERCISE="sync status next plan plan-next wave gc scan doctor"
73
+ # `lib` belongs here rather than in SKIP: it is read-only and calls no gh, so the assertion below
74
+ # is the guard that keeps it that way — and running it from the fixture also proves the host-project
75
+ # degradation (a project with no scripts/lib of its own falls back to the cckit install, no crash).
76
+ EXERCISE="sync status next plan plan-next wave gc cleanup scan doctor lib"
74
77
  for v in $EXERCISE; do
75
78
  : > "$GH_REPO_LOG"
76
79
  ( cd "$fix" && PATH="$stub:$PATH" GH_REPO_LOG="$GH_REPO_LOG" "$CCKIT" "$v" --llm >/dev/null 2>&1 )
@@ -80,11 +83,19 @@ done
80
83
  : > "$GH_REPO_LOG"; ( cd "$fix" && PATH="$stub:$PATH" GH_REPO_LOG="$GH_REPO_LOG" "$CCKIT" gc --llm >/dev/null 2>&1 )
81
84
  yes "gc resolves the invoking repo" "$(cat "$GH_REPO_LOG")" "$FIX_REPO"
82
85
 
86
+ # `brief` takes an issue argument, so the generic --llm loop above cannot drive it — but it reads an
87
+ # issue through gh, which is exactly the call that must never resolve cckit's own repo from someone
88
+ # else's checkout. Drive it explicitly with an issue number.
89
+ : > "$GH_REPO_LOG"
90
+ ( cd "$fix" && PATH="$stub:$PATH" GH_REPO_LOG="$GH_REPO_LOG" "$CCKIT" brief 1 >/dev/null 2>&1 )
91
+ no "brief never resolves cckit's own repo from a foreign checkout" "$(cat "$GH_REPO_LOG")" "$OWN_REPO"
92
+ yes "brief resolves the invoking repo" "$(cat "$GH_REPO_LOG")" "$FIX_REPO"
93
+
83
94
  # ── BY CONSTRUCTION: every verb in `cckit commands` is classified (exercised or explicitly skipped) ─
84
95
  # A new verb that is neither exercised nor listed here fails the harness — forcing a coverage
85
96
  # decision. SKIP holds verbs that mutate, need args, read stdin, are interactive, or act on the
86
97
  # install itself (not the invoking project's board) — deliberately not driven here.
87
- SKIP="adopt autopilot bench close commands completions contribute copilot debug digest effort encode-context handoff help init install migrate msg orchestrate pr release render resume start ui update version watch"
98
+ SKIP="adopt autopilot bench brief close commands completions contribute copilot debug digest effort encode-context handoff help init install migrate msg orchestrate pr release render resume start ui update version watch"
88
99
  classified() { case " $EXERCISE $SKIP " in *" $1 "*) return 0 ;; *) return 1 ;; esac; }
89
100
  for v in $("$CCKIT" commands); do
90
101
  classified "$v" || { echo "FAIL: verb '$v' is unclassified — add it to EXERCISE (read-only, assert no own-repo leak) or SKIP in portable-test.sh"; fail=1; }