@jeiemgi/cckit 0.5.0 → 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.
- package/.claude-plugin/plugin.json +1 -1
- package/AGENTS.md +34 -3
- package/README.md +95 -6
- package/bin/cckit +90 -3
- package/cckit.config.json +7 -2
- package/kit.config.schema.json +26 -1
- package/package.json +1 -1
- package/profiles/automation.json +2 -1
- package/profiles/content.json +2 -1
- package/profiles/minimal.json +2 -1
- package/profiles/research.json +2 -1
- package/profiles/software.json +2 -1
- package/scripts/benchmark/benchmark-test.sh +83 -0
- package/scripts/benchmark/gate.sh +55 -0
- package/scripts/benchmark/lib/bench-common.sh +70 -0
- package/scripts/benchmark/lib/model.sh +116 -0
- package/scripts/benchmark/report.sh +105 -0
- package/scripts/benchmark/run-quality.sh +102 -0
- package/scripts/benchmark/run.sh +166 -0
- package/scripts/benchmark/stop-check.sh +83 -0
- package/scripts/commitlint-test.sh +58 -0
- package/scripts/init.sh +57 -1
- package/scripts/kit-self-update.sh +55 -0
- package/scripts/lib/board-view-test.sh +1 -0
- package/scripts/lib/board-view.sh +1 -0
- package/scripts/lib/captain-test.sh +62 -0
- package/scripts/lib/captain.sh +105 -17
- package/scripts/lib/cckit-output.sh +1 -0
- package/scripts/lib/commitlint.sh +54 -0
- package/scripts/lib/config-path-test.sh +1 -0
- package/scripts/lib/config-path.sh +1 -0
- package/scripts/lib/copilot-test.sh +1 -0
- package/scripts/lib/copilot.sh +1 -0
- package/scripts/lib/effort-dispatch-test.sh +10 -0
- package/scripts/lib/effort-flows-test.sh +1 -0
- package/scripts/lib/effort-metrics-test.sh +1 -0
- package/scripts/lib/effort-metrics.sh +1 -0
- package/scripts/lib/effort-ops-test.sh +360 -0
- package/scripts/lib/effort-ops.sh +372 -16
- package/scripts/lib/effort-parity-test.sh +1 -0
- package/scripts/lib/effort-plan.sh +1 -0
- package/scripts/lib/effort-slug-test.sh +32 -0
- package/scripts/lib/effort-slug.sh +72 -8
- package/scripts/lib/effort.sh +1 -0
- package/scripts/lib/engine-adapter.sh +1 -0
- package/scripts/lib/errors-header-test.sh +86 -0
- package/scripts/lib/gh-log.sh +1 -0
- package/scripts/lib/gh-project-test.sh +1 -0
- package/scripts/lib/gh-project.sh +1 -0
- package/scripts/lib/git-remote-test.sh +1 -0
- package/scripts/lib/git-remote.sh +1 -0
- package/scripts/lib/handoff.sh +23 -2
- package/scripts/lib/kit-brief-test.sh +292 -0
- package/scripts/lib/kit-brief.sh +376 -0
- package/scripts/lib/kit-cli-test.sh +1 -0
- package/scripts/lib/kit-cli.sh +1 -0
- package/scripts/lib/kit-config-resolve.sh +1 -0
- package/scripts/lib/kit-config-test.sh +14 -0
- package/scripts/lib/kit-config.sh +7 -0
- package/scripts/lib/kit-engine-test.sh +1 -0
- package/scripts/lib/kit-events.sh +1 -0
- package/scripts/lib/kit-gc-test.sh +125 -0
- package/scripts/lib/kit-gc.sh +193 -5
- package/scripts/lib/kit-interview-test.sh +1 -0
- package/scripts/lib/kit-interview.sh +1 -0
- package/scripts/lib/kit-lib-test.sh +226 -0
- package/scripts/lib/kit-lib.sh +308 -0
- package/scripts/lib/kit-local.sh +1 -0
- package/scripts/lib/kit-manifest.sh +1 -0
- package/scripts/lib/kit-mode-test.sh +1 -0
- package/scripts/lib/kit-mode.sh +1 -0
- package/scripts/lib/kit-msg-test.sh +1 -0
- package/scripts/lib/kit-msg.sh +1 -0
- package/scripts/lib/kit-operate.sh +1 -0
- package/scripts/lib/kit-profile-test.sh +1 -0
- package/scripts/lib/kit-profile.sh +1 -0
- package/scripts/lib/kit-state-test.sh +89 -0
- package/scripts/lib/kit-state.sh +61 -0
- package/scripts/lib/kit-status-test.sh +233 -0
- package/scripts/lib/kit-status.sh +415 -0
- package/scripts/lib/kit-task-ops-test.sh +22 -0
- package/scripts/lib/kit-task-ops.sh +51 -2
- package/scripts/lib/next.sh +1 -0
- package/scripts/lib/plan-machine-test.sh +54 -0
- package/scripts/lib/plan-machine.sh +86 -25
- package/scripts/lib/plan-next-test.sh +1 -0
- package/scripts/lib/plan-next.sh +1 -0
- package/scripts/lib/pr-evidence-test.sh +259 -0
- package/scripts/lib/pr-evidence.sh +220 -35
- package/scripts/lib/project-scan.sh +1 -0
- package/scripts/lib/react-detect.sh +1 -0
- package/scripts/lib/render-test.sh +1 -0
- package/scripts/lib/render.sh +1 -0
- package/scripts/lib/role-identity.sh +1 -0
- package/scripts/lib/secret-guard.sh +21 -1
- package/scripts/lib/toon.sh +1 -0
- package/scripts/lib/ui.sh +1 -0
- package/scripts/lib/version-bump-test.sh +1 -0
- package/scripts/lib/version-bump.sh +1 -0
- package/scripts/lib/worktree-bootstrap-test.sh +220 -0
- package/scripts/lib/worktree-issue-test.sh +15 -1
- package/scripts/lib/worktree-issue.sh +23 -8
- package/scripts/lib/worktree-start.sh +191 -7
- package/scripts/lib/zsh-safety-test.sh +10 -0
- package/scripts/orchestrate.sh +8 -1
- package/scripts/portable-test.sh +13 -2
- package/scripts/self-install-test.sh +282 -0
- package/scripts/setup-labels.sh +1 -0
- package/scripts/status.sh +68 -40
- package/scripts/task-sync.sh +13 -0
- package/scripts/ux-a11y-scan.sh +96 -0
- package/scripts/ux-ds-audit.sh +146 -0
- package/scripts/ux-graph-scan.sh +188 -0
- package/skills/kit-autopilot/SKILL.md +6 -1
- package/skills/kit-cleanup/SKILL.md +83 -0
- package/skills/kit-effort-close/SKILL.md +3 -0
- package/skills/kit-effort-new/SKILL.md +7 -0
- package/skills/kit-effort-start/SKILL.md +39 -4
- package/skills/kit-gc/SKILL.md +19 -0
- package/skills/kit-next/SKILL.md +5 -0
- package/skills/kit-status/SKILL.md +92 -0
- package/skills/kit-task-start/SKILL.md +7 -1
- package/skills/kit-ux-audit/SKILL.md +241 -0
- package/skills/kit-ux-audit/references/a11y.md +79 -0
- package/skills/kit-ux-audit/references/consistency.md +106 -0
- package/skills/kit-ux-audit/references/graph-model.md +92 -0
- package/skills/kit-ux-audit/references/heuristics.md +157 -0
- package/skills/kit-ux-audit/references/report.md +172 -0
- package/templates/agents/ux.md +89 -0
- package/templates/benchmarks/SCHEMA.md +75 -0
- package/templates/benchmarks/abstain.jsonl +8 -0
- package/templates/benchmarks/adversarial.jsonl +8 -0
- package/templates/benchmarks/benchmark.config.json +14 -0
- package/templates/benchmarks/quality.jsonl +8 -0
- package/templates/benchmarks/retrieval.jsonl +7 -0
- package/templates/rules/branch-naming.md +20 -1
- package/templates/rules/communication-style.md +8 -0
- package/templates/rules/delegation-brief.md +38 -4
- package/templates/rules/effort-model.md +47 -4
- package/templates/rules/naming-and-ids.md +199 -0
- package/templates/rules/task-management.md +1 -1
- package/templates/settings/settings.json.tmpl +9 -0
- package/templates/skills/concrete/SKILL.md +117 -0
- package/templates/skills/karpathy-guidelines/SKILL.md +1 -0
package/scripts/lib/kit-gc.sh
CHANGED
|
@@ -16,17 +16,45 @@
|
|
|
16
16
|
#
|
|
17
17
|
# Requires: git; gh (degrades to "unknown" issue/PR state without it); scripts/lib/worktree-issue.sh.
|
|
18
18
|
# Portable: bash 3.2+ AND zsh.
|
|
19
|
+
# errors: mixed — kit_gc_analyze is read-only and forgiving; the prune path propagates
|
|
19
20
|
|
|
20
21
|
KIT_GC_REPO="${KIT_GC_REPO:-${KIT_REPO:-}}"
|
|
21
22
|
|
|
22
23
|
_kit_gc_root() { git worktree list --porcelain 2>/dev/null | awk '/^worktree /{print $2; exit}'; }
|
|
23
24
|
|
|
24
|
-
#
|
|
25
|
+
# This file's own directory, resolved ONCE at load time — the only point where both shells agree.
|
|
26
|
+
# `BASH_SOURCE` is bash-only; inside a zsh *function* it is unset and `$0` is the function name, so
|
|
27
|
+
# the old per-call resolution fell back to `$0`="zsh", worktree-issue.sh was never sourced,
|
|
28
|
+
# `wt_protected_reason` stayed undefined, and every call site's `2>/dev/null || true` turned the
|
|
29
|
+
# resulting "command not found" into an empty reason — i.e. an open issue's branch classified as
|
|
30
|
+
# SAFE to delete. At FILE scope zsh sets `$0` to the sourced file's path, so one expansion covers
|
|
31
|
+
# bash (source or direct exec) and zsh (interactive or not) with no shell-specific syntax. Prompt
|
|
32
|
+
# expansion (`${(%):-%x}`) is deliberately avoided: it is zsh-only, needs `eval` to stay parseable
|
|
33
|
+
# under bash, and is unreliable in an INTERACTIVE zsh — the kit's own shell.
|
|
34
|
+
#
|
|
35
|
+
# `cd`'s own stdout is discarded, not just its stderr: an interactive zsh ECHOES the new directory
|
|
36
|
+
# (tilde-abbreviated) after a `cd`, so the bare `$(cd … && pwd)` idiom captured TWO lines and the
|
|
37
|
+
# resulting path never existed. `pwd` still writes to the substitution.
|
|
38
|
+
_KIT_GC_LIB_DIR="$(CDPATH='' cd -- "$(dirname -- "${BASH_SOURCE[0]:-$0}")" >/dev/null 2>&1 && pwd)"
|
|
39
|
+
|
|
40
|
+
# Source worktree-issue.sh (wt_issue_number / wt_protected_reason) from the lib dir we live in.
|
|
25
41
|
_kit_gc_load_deps() {
|
|
26
42
|
command -v wt_protected_reason >/dev/null 2>&1 && return 0
|
|
27
|
-
local d; d="$(CDPATH='' cd -- "$(dirname -- "${BASH_SOURCE[0]:-$0}")" && pwd)"
|
|
28
43
|
# shellcheck source=/dev/null
|
|
29
|
-
[ -
|
|
44
|
+
[ -n "${_KIT_GC_LIB_DIR:-}" ] && [ -f "$_KIT_GC_LIB_DIR/worktree-issue.sh" ] \
|
|
45
|
+
&& . "$_KIT_GC_LIB_DIR/worktree-issue.sh"
|
|
46
|
+
command -v wt_protected_reason >/dev/null 2>&1
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
# Fail LOUD if the protection helper could not be loaded. Without it every issue-open check
|
|
50
|
+
# silently returns empty and gc would offer to delete in-progress work — a wrong "safe" is far
|
|
51
|
+
# worse than a refusal, so callers must not proceed on a degraded analysis.
|
|
52
|
+
_kit_gc_require_deps() {
|
|
53
|
+
_kit_gc_load_deps || : # never let a load failure abort a `set -e` caller before the FATAL prints
|
|
54
|
+
command -v wt_protected_reason >/dev/null 2>&1 && return 0
|
|
55
|
+
echo "kit-gc: FATAL — worktree-issue.sh not loaded; issue-open protection is unavailable." >&2
|
|
56
|
+
echo "kit-gc: refusing to classify branches: everything would look SAFE to delete." >&2
|
|
57
|
+
return 1
|
|
30
58
|
}
|
|
31
59
|
|
|
32
60
|
# _kit_gc_pr_index [repo] — echo one "<headRefName>\tPR#<num> <STATE>" line per PR in ONE gh call, so
|
|
@@ -46,7 +74,7 @@ _kit_gc_pr_for() {
|
|
|
46
74
|
# kit_gc_analyze — read-only classification of worktrees, branches, and stashes. Writes NOTHING.
|
|
47
75
|
# Each row is tagged PROTECTED / SAFE / ACTIVE / ORPHAN so a human or UI can decide what to prune.
|
|
48
76
|
kit_gc_analyze() {
|
|
49
|
-
|
|
77
|
+
_kit_gc_require_deps || return 1
|
|
50
78
|
# `wtpath`, not `path`: under zsh `path` is tied to PATH (special array), so a bare `path` local
|
|
51
79
|
# here would clobber the command search path on assignment. A namespaced name is inert.
|
|
52
80
|
local repo="$KIT_GC_REPO" b ref wtpath reason pr prot
|
|
@@ -173,13 +201,34 @@ kit_gc_recover_zombies() {
|
|
|
173
201
|
done
|
|
174
202
|
}
|
|
175
203
|
|
|
204
|
+
# _kit_gc_has_unpushed <branch> — rc 0 when the LOCAL branch holds commits its remote does not, i.e.
|
|
205
|
+
# deleting it locally would destroy the only copy. A missing remote ref is NOT unpushed work: the
|
|
206
|
+
# branch's PR merged, so the commits reached the base branch and the remote was deleted at merge.
|
|
207
|
+
# `git branch -D` is a force delete, so this is the guard that makes it safe (kit-gc SKILL: "verify a
|
|
208
|
+
# branch is level with its remote before deleting — an 'ahead' branch may hold orphan work").
|
|
209
|
+
_kit_gc_has_unpushed() {
|
|
210
|
+
local b="$1"
|
|
211
|
+
git show-ref --verify --quiet "refs/remotes/origin/$b" 2>/dev/null || return 1
|
|
212
|
+
[ "$(git rev-list --count "origin/$b..$b" 2>/dev/null || echo 1)" != "0" ]
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
# _kit_gc_remote_ahead <branch> — rc 0 when the REMOTE holds commits the local branch does not.
|
|
216
|
+
# Containment in one direction is not equality: `origin/<b>..<b>` = 0 only proves local ⊆ remote, so
|
|
217
|
+
# a remote-ahead branch would otherwise pass the level check and lose remote-only history on delete.
|
|
218
|
+
# Remote deletion requires BOTH directions empty.
|
|
219
|
+
_kit_gc_remote_ahead() {
|
|
220
|
+
local b="$1"
|
|
221
|
+
git show-ref --verify --quiet "refs/remotes/origin/$b" 2>/dev/null || return 1
|
|
222
|
+
[ "$(git rev-list --count "$b..origin/$b" 2>/dev/null || echo 1)" != "0" ]
|
|
223
|
+
}
|
|
224
|
+
|
|
176
225
|
# kit_gc_prune [--yes] - remove worktrees + local branches whose PR is MERGED (the SAFE rows).
|
|
177
226
|
# DRY-RUN by default (lists what it WOULD remove); --yes performs the deletions. Never touches a
|
|
178
227
|
# PROTECTED/ACTIVE/ORPHAN branch, and never a DIRTY worktree (recover-before-prune): a worktree with
|
|
179
228
|
# staged/unstaged/untracked changes is skipped with a warning, not destroyed. The remote branch is
|
|
180
229
|
# already deleted at merge time (gh pr merge --delete-branch); this cleans up the local side.
|
|
181
230
|
kit_gc_prune() {
|
|
182
|
-
|
|
231
|
+
_kit_gc_require_deps || return 1
|
|
183
232
|
# `wtpath`, not `path`: under zsh `path` is tied to PATH (special array), so assigning to a bare
|
|
184
233
|
# `path` local would clobber the command search path. A namespaced name is inert.
|
|
185
234
|
local repo="$KIT_GC_REPO" yes=0 a wtpath ref b pr pr_index
|
|
@@ -224,6 +273,11 @@ kit_gc_prune() {
|
|
|
224
273
|
[ -n "$(wt_protected_reason "$b" "$repo" 2>/dev/null || true)" ] && continue
|
|
225
274
|
pr="$(_kit_gc_pr_for "$pr_index" "$b")"
|
|
226
275
|
printf '%s' "$pr" | grep -q 'MERGED' || continue
|
|
276
|
+
# A merged PR is not on its own sufficient: the local ref may carry commits that were never
|
|
277
|
+
# pushed, and `git branch -D` would be their last rites.
|
|
278
|
+
if _kit_gc_has_unpushed "$b"; then
|
|
279
|
+
echo " SKIP $b — ahead of origin/$b (unpushed commits); recover before pruning" >&2; continue
|
|
280
|
+
fi
|
|
227
281
|
if [ "$yes" -eq 1 ]; then
|
|
228
282
|
git branch -D "$b" >/dev/null 2>&1 && echo " deleted local branch $b (PR MERGED)"
|
|
229
283
|
else
|
|
@@ -232,3 +286,137 @@ kit_gc_prune() {
|
|
|
232
286
|
done
|
|
233
287
|
[ "$yes" -eq 1 ] && echo "gc prune: done" || echo "gc prune: DRY RUN - pass --yes to delete"
|
|
234
288
|
}
|
|
289
|
+
|
|
290
|
+
# _kit_gc_names <analysis> <section> <verdict-regex> — echo one bare name per matching row inside a
|
|
291
|
+
# `# <section>` block of a kit_gc_analyze dump. The analysis is the SINGLE classifier (Family 1):
|
|
292
|
+
# cleanup reads its verdicts rather than re-deriving them, so the two can never disagree about what
|
|
293
|
+
# is safe to delete — the failure mode #219 was about.
|
|
294
|
+
_kit_gc_names() {
|
|
295
|
+
printf '%s\n' "$1" | awk -v sect="$2" -v want="$3" '
|
|
296
|
+
/^# / { in_s = ($0 == "# " sect); next }
|
|
297
|
+
!in_s { next }
|
|
298
|
+
$0 ~ want { sub(/^ /, ""); sub(/ ->.*/, ""); print }
|
|
299
|
+
'
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
# kit_gc_cleanup [--yes] — the ONE guided destructive sweep over the gc analysis.
|
|
303
|
+
#
|
|
304
|
+
# PLAN FIRST, always: print every bucket with its counts and names, then execute only the SAFE rows,
|
|
305
|
+
# and only with --yes. Without --yes nothing is written — the plan IS the output. Every row the plan
|
|
306
|
+
# omits is a deletion the user did not get to veto, so the plan must name EVERYTHING --yes can touch:
|
|
307
|
+
# worktrees as well as branches.
|
|
308
|
+
#
|
|
309
|
+
# What --yes deletes: merged worktrees, merged local branches (via kit_gc_prune, which also runs the
|
|
310
|
+
# recover-before-prune zombie pass), and the REMOTE ref of a merged branch that is exactly level with
|
|
311
|
+
# it. What it NEVER deletes: an ORPHAN branch (local commits not on the base remote), a PROTECTED
|
|
312
|
+
# branch (its issue is still open), or a stash. Those three are irreversible or hold the only copy of
|
|
313
|
+
# work, so they are surfaced BY NAME for a human and left exactly where they are.
|
|
314
|
+
#
|
|
315
|
+
# NOTE: the underlying kit_gc_analyze refreshes remote-tracking refs (`git fetch --prune`) so the
|
|
316
|
+
# classification is not made against a stale view of the remote. That is the only write a plan-only
|
|
317
|
+
# run performs, and it touches no branch, worktree, stash, or commit of yours.
|
|
318
|
+
kit_gc_cleanup() {
|
|
319
|
+
_kit_gc_require_deps || return 1
|
|
320
|
+
local repo="$KIT_GC_REPO" yes=0 a out b n_safe n_orphan n_prot n_stash n_wt rc=0 n_rfail=0
|
|
321
|
+
local zname zbranch zstaged
|
|
322
|
+
local safe_list orphan_list prot_list stash_list wt_list zomb_list level_ok n_zomb
|
|
323
|
+
for a in "$@"; do case "$a" in --yes|-y) yes=1 ;; esac; done
|
|
324
|
+
|
|
325
|
+
out="$(kit_gc_analyze)" || return 1
|
|
326
|
+
safe_list="$(_kit_gc_names "$out" branches ' -> SAFE ')"
|
|
327
|
+
orphan_list="$(_kit_gc_names "$out" branches ' -> ORPHAN')"
|
|
328
|
+
prot_list="$(_kit_gc_names "$out" branches ' -> PROTECTED:')"
|
|
329
|
+
stash_list="$(printf '%s\n' "$out" | awk '/^# /{in_s=($0=="# stashes"); next} in_s && NF' | sed 's/^ //')"
|
|
330
|
+
|
|
331
|
+
# Worktrees kit_gc_prune would remove: the ones whose branch is itself SAFE (same condition prune
|
|
332
|
+
# applies — unprotected + PR MERGED). Derived from the SAFE list so the two cannot diverge.
|
|
333
|
+
wt_list="$(git worktree list --porcelain 2>/dev/null \
|
|
334
|
+
| awk '/^worktree /{w=$2} /^branch /{print w" "$2}' \
|
|
335
|
+
| while read -r wtpath ref; do
|
|
336
|
+
b="${ref#refs/heads/}"
|
|
337
|
+
printf '%s\n' "$safe_list" | grep -qxF "$b" || continue
|
|
338
|
+
if [ -n "$(git -C "$wtpath" status --porcelain 2>/dev/null)" ]; then
|
|
339
|
+
echo "$wtpath [$b] (DIRTY — will be skipped, not destroyed)"
|
|
340
|
+
else
|
|
341
|
+
echo "$wtpath [$b]"
|
|
342
|
+
fi
|
|
343
|
+
done)"
|
|
344
|
+
|
|
345
|
+
# ZOMBIE worktrees (dir gone, admin metadata lingers). kit_gc_prune --yes acts on these two ways
|
|
346
|
+
# — kit_gc_recover_zombies commits any staged delta to the branch, then `git worktree prune`
|
|
347
|
+
# drops the metadata — so the plan MUST name them or --yes would touch a row nobody approved
|
|
348
|
+
# (#227 review). Same helper as the analyze report, so the two cannot diverge.
|
|
349
|
+
zomb_list="$(while IFS="$(printf '\t')" read -r zname zbranch zstaged; do
|
|
350
|
+
[ -n "$zname" ] || continue
|
|
351
|
+
if [ "$zstaged" = yes ]; then
|
|
352
|
+
echo "$zname [$zbranch] (STAGED work — recovered to a commit on $zbranch, then metadata pruned)"
|
|
353
|
+
else
|
|
354
|
+
echo "$zname [$zbranch] (no staged delta — metadata pruned)"
|
|
355
|
+
fi
|
|
356
|
+
done <<ZEOF
|
|
357
|
+
$(_kit_gc_zombies)
|
|
358
|
+
ZEOF
|
|
359
|
+
)"
|
|
360
|
+
|
|
361
|
+
n_safe="$(printf '%s' "$safe_list" | grep -c . || true)"
|
|
362
|
+
n_orphan="$(printf '%s' "$orphan_list" | grep -c . || true)"
|
|
363
|
+
n_prot="$(printf '%s' "$prot_list" | grep -c . || true)"
|
|
364
|
+
n_stash="$(printf '%s' "$stash_list" | grep -c . || true)"
|
|
365
|
+
n_wt="$(printf '%s' "$wt_list" | grep -c . || true)"
|
|
366
|
+
n_zomb="$(printf '%s' "$zomb_list" | grep -c . || true)"
|
|
367
|
+
|
|
368
|
+
echo "# cleanup plan"
|
|
369
|
+
printf ' SAFE branches %3s merged PR, issue closed/absent\n' "$n_safe"
|
|
370
|
+
printf '%s\n' "$safe_list" | grep . | sed 's/^/ /' || true
|
|
371
|
+
printf ' SAFE worktrees %3s removed with their branch\n' "$n_wt"
|
|
372
|
+
printf '%s\n' "$wt_list" | grep . | sed 's/^/ /' || true
|
|
373
|
+
printf ' ZOMBIE worktrees %3s staged work recovered to its branch, then metadata pruned\n' "$n_zomb"
|
|
374
|
+
printf '%s\n' "$zomb_list" | grep . | sed 's/^/ /' || true
|
|
375
|
+
printf ' ORPHAN kept %3s commits not on the base remote — never auto-deleted\n' "$n_orphan"
|
|
376
|
+
printf '%s\n' "$orphan_list" | grep . | sed 's/^/ /' || true
|
|
377
|
+
printf ' PROTECTED kept %3s issue still OPEN\n' "$n_prot"
|
|
378
|
+
printf '%s\n' "$prot_list" | grep . | sed 's/^/ /' || true
|
|
379
|
+
printf ' stashes kept %3s irreversible — drop by hand after reading each diff\n' "$n_stash"
|
|
380
|
+
printf '%s\n' "$stash_list" | grep . | sed 's/^/ /' || true
|
|
381
|
+
|
|
382
|
+
if [ "$yes" -ne 1 ]; then
|
|
383
|
+
echo "cleanup: PLAN ONLY — nothing deleted. Pass --yes to delete the SAFE rows and prune the ZOMBIE rows."
|
|
384
|
+
return 0
|
|
385
|
+
fi
|
|
386
|
+
[ "$n_safe" -eq 0 ] && [ "$n_wt" -eq 0 ] && [ "$n_zomb" -eq 0 ] && { echo "cleanup: nothing SAFE to delete."; return 0; }
|
|
387
|
+
|
|
388
|
+
# Which SAFE branches may have their REMOTE deleted — decided BEFORE the local prune, because once
|
|
389
|
+
# the local ref is gone there is nothing left to compare. Requires exact equality in BOTH
|
|
390
|
+
# directions: local ⊆ remote alone would let a remote-ahead branch lose remote-only history.
|
|
391
|
+
level_ok=""
|
|
392
|
+
while IFS= read -r b; do
|
|
393
|
+
[ -n "$b" ] || continue
|
|
394
|
+
git show-ref --verify --quiet "refs/remotes/origin/$b" 2>/dev/null || continue
|
|
395
|
+
_kit_gc_has_unpushed "$b" && { echo " SKIP remote $b — local is ahead of origin/$b" >&2; continue; }
|
|
396
|
+
_kit_gc_remote_ahead "$b" && { echo " SKIP remote $b — origin/$b is ahead of local" >&2; continue; }
|
|
397
|
+
level_ok="$level_ok$b
|
|
398
|
+
"
|
|
399
|
+
done <<EOF
|
|
400
|
+
$safe_list
|
|
401
|
+
EOF
|
|
402
|
+
|
|
403
|
+
kit_gc_prune --yes || rc=1
|
|
404
|
+
|
|
405
|
+
# Remote side last: only branches proven exactly level above, so nothing unpushed or remote-only
|
|
406
|
+
# is dropped. A failed delete is reported AND counted (this loop is heredoc-fed, not piped, so it
|
|
407
|
+
# runs in the current shell and the counter survives), never retried blindly.
|
|
408
|
+
while IFS= read -r b; do
|
|
409
|
+
[ -n "$b" ] || continue
|
|
410
|
+
if git push origin --delete "$b" >/dev/null 2>&1; then
|
|
411
|
+
echo " deleted remote branch $b"
|
|
412
|
+
else
|
|
413
|
+
echo " SKIP remote $b — delete failed (protected ref or already gone)" >&2
|
|
414
|
+
n_rfail=$((n_rfail + 1)); rc=1
|
|
415
|
+
fi
|
|
416
|
+
done <<EOF
|
|
417
|
+
$level_ok
|
|
418
|
+
EOF
|
|
419
|
+
printf ' remote deletes failed %3s\n' "$n_rfail"
|
|
420
|
+
echo "cleanup: done — $n_zomb zombie pruned / $n_orphan orphan / $n_prot protected / $n_stash stash left untouched."
|
|
421
|
+
return "$rc"
|
|
422
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env bash
|
|
2
2
|
# kit-interview-test.sh — self-test for kit-interview (#372). Runs under bash AND zsh.
|
|
3
3
|
# Run: bash scripts/lib/kit-interview-test.sh
|
|
4
|
+
# errors: strict — a test runner: rc 1 on any failed assertion
|
|
4
5
|
dir=$(CDPATH='' cd -- "$(dirname -- "$0")" && pwd)
|
|
5
6
|
|
|
6
7
|
if [ -n "${KIT_IV_TEST_INNER:-}" ]; then
|
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
# kit-interview.sh --render TIER [--dir DIR]
|
|
19
19
|
# kit-interview.sh --apply TIER --answers FILE [--base FILE]
|
|
20
20
|
# Requires: jq.
|
|
21
|
+
# errors: pure — the deriving half: catalog, context, render, apply — no side effects
|
|
21
22
|
|
|
22
23
|
_kit_iv_dir="$(CDPATH='' cd -- "$(dirname -- "${BASH_SOURCE[0]:-$0}")" && pwd)"
|
|
23
24
|
# shellcheck source=/dev/null
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
#!/bin/sh
|
|
2
|
+
# kit-lib-test.sh — self-test for kit-lib.sh, the helper catalog (Effort 220 · #222).
|
|
3
|
+
# Network-free and repo-free: every parser assertion runs against fixture .sh files written into a
|
|
4
|
+
# temp dir, so the test never depends on what scripts/lib happens to contain today. The pure
|
|
5
|
+
# parsers run under bash AND zsh; the full kit_lib verb (which sources render/toon via BASH_SOURCE)
|
|
6
|
+
# runs under bash, matching how the dispatcher invokes it.
|
|
7
|
+
# Run: bash scripts/lib/kit-lib-test.sh
|
|
8
|
+
# errors: strict — a test runner: rc 1 on any failed assertion
|
|
9
|
+
|
|
10
|
+
dir=$(CDPATH='' cd -- "$(dirname -- "$0")" && pwd)
|
|
11
|
+
|
|
12
|
+
# _kl_fixture <dir> — a small library covering every parse case the catalog has to survive:
|
|
13
|
+
# alpha.sh em-dash header, `strict`, one public + one private + one nested function
|
|
14
|
+
# beta.sh hyphen header, `mixed` (the reason is load-bearing), `function name()` form
|
|
15
|
+
# gamma.sh NO `# errors:` header at all — must degrade, not fail
|
|
16
|
+
# delta.sh `# shellcheck` directive before the header; a pipe char in the purpose
|
|
17
|
+
# epsilon.sh no functions at all (constants only)
|
|
18
|
+
# omega-test.sh a test runner — excluded from the catalog by default
|
|
19
|
+
_kl_fixture() {
|
|
20
|
+
r="$1"
|
|
21
|
+
mkdir -p "$r"
|
|
22
|
+
cat > "$r/alpha.sh" <<'EOF'
|
|
23
|
+
#!/usr/bin/env bash
|
|
24
|
+
# alpha.sh — does the alpha thing for a caller.
|
|
25
|
+
# errors: strict — a failed dependency propagates
|
|
26
|
+
alpha_go() { _alpha_priv; }
|
|
27
|
+
_alpha_priv() {
|
|
28
|
+
alpha_nested() { :; }
|
|
29
|
+
}
|
|
30
|
+
EOF
|
|
31
|
+
cat > "$r/beta.sh" <<'EOF'
|
|
32
|
+
#!/usr/bin/env bash
|
|
33
|
+
# beta.sh - the beta half.
|
|
34
|
+
# errors: mixed — beta_pure is pure; beta_net needs gh
|
|
35
|
+
beta_pure() { :; }
|
|
36
|
+
function beta_net() { :; }
|
|
37
|
+
EOF
|
|
38
|
+
cat > "$r/gamma.sh" <<'EOF'
|
|
39
|
+
#!/usr/bin/env bash
|
|
40
|
+
# gamma.sh — predates the header convention.
|
|
41
|
+
gamma_run() { :; }
|
|
42
|
+
EOF
|
|
43
|
+
cat > "$r/delta.sh" <<'EOF'
|
|
44
|
+
#!/usr/bin/env bash
|
|
45
|
+
# shellcheck shell=bash
|
|
46
|
+
# delta.sh — takes a | pipe in its purpose line.
|
|
47
|
+
# errors: best-effort — warns and returns 0
|
|
48
|
+
delta_do() { :; }
|
|
49
|
+
EOF
|
|
50
|
+
cat > "$r/epsilon.sh" <<'EOF'
|
|
51
|
+
#!/usr/bin/env bash
|
|
52
|
+
# epsilon.sh — constants only, no callable surface.
|
|
53
|
+
# errors: pure — no I/O
|
|
54
|
+
EPSILON=1
|
|
55
|
+
EOF
|
|
56
|
+
cat > "$r/omega-test.sh" <<'EOF'
|
|
57
|
+
#!/usr/bin/env bash
|
|
58
|
+
# omega-test.sh — a runner.
|
|
59
|
+
# errors: strict — a test runner: rc 1 on any failed assertion
|
|
60
|
+
t() { :; }
|
|
61
|
+
EOF
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if [ -n "${KL_TEST_INNER:-}" ]; then
|
|
65
|
+
. "$dir/kit-lib.sh"
|
|
66
|
+
fail=0
|
|
67
|
+
eq() { if [ "$2" != "$3" ]; then echo "FAIL($KL_TEST_INNER): $1 -> '[$2]', want '[$3]'"; fail=1; fi; }
|
|
68
|
+
has() { case "$2" in *"$3"*) ;; *) echo "FAIL($KL_TEST_INNER): $1 missing '[$3]'"; fail=1 ;; esac; }
|
|
69
|
+
no() { case "$2" in *"$3"*) echo "FAIL($KL_TEST_INNER): $1 should NOT contain '[$3]'"; fail=1 ;; esac; }
|
|
70
|
+
|
|
71
|
+
fix="$(mktemp -d)"; _kl_fixture "$fix"
|
|
72
|
+
empty="$(mktemp -d)"
|
|
73
|
+
|
|
74
|
+
# ── purpose: derived from the file's own header, never invented ────────────────────────────
|
|
75
|
+
eq "purpose (em dash)" "$(kit_lib_purpose "$fix/alpha.sh")" "does the alpha thing for a caller."
|
|
76
|
+
eq "purpose (hyphen)" "$(kit_lib_purpose "$fix/beta.sh")" "the beta half."
|
|
77
|
+
eq "purpose skips shellcheck" "$(kit_lib_purpose "$fix/delta.sh")" "takes a / pipe in its purpose line."
|
|
78
|
+
eq "purpose of a missing file" "$(kit_lib_purpose "$fix/nope.sh")" "unknown"
|
|
79
|
+
# a header-less file still yields its first comment rather than a fabricated sentence
|
|
80
|
+
printf '#!/usr/bin/env bash\nfoo() { :; }\n' > "$fix/bare.sh"
|
|
81
|
+
eq "purpose with no header" "$(kit_lib_purpose "$fix/bare.sh")" "unknown"
|
|
82
|
+
rm -f "$fix/bare.sh"
|
|
83
|
+
|
|
84
|
+
# only the FIRST sentence: a lib header's opening line is usually "<claim>. <elaboration…>".
|
|
85
|
+
printf '#!/usr/bin/env bash\n# two.sh — the claim itself, stated once. Then a long elaboration nobody needs here.\n' > "$fix/two.sh"
|
|
86
|
+
eq "purpose keeps one sentence" "$(kit_lib_purpose "$fix/two.sh")" "the claim itself, stated once."
|
|
87
|
+
# a period too early is an abbreviation, not a sentence end — keep the line
|
|
88
|
+
printf '#!/usr/bin/env bash\n# ab.sh — e.g. the whole line survives because that cut would be absurd.\n' > "$fix/ab.sh"
|
|
89
|
+
has "purpose ignores an early period" "$(kit_lib_purpose "$fix/ab.sh")" "the whole line survives"
|
|
90
|
+
# no sentence end at all and over the cap -> truncated at a word boundary, marked with an ellipsis
|
|
91
|
+
printf '#!/usr/bin/env bash\n# long.sh — %s tail\n' \
|
|
92
|
+
"aaaa bbbb cccc dddd eeee ffff gggg hhhh iiii jjjj kkkk llll mmmm nnnn oooo pppp qqqq rrrr ssss tttt uuuu" > "$fix/long.sh"
|
|
93
|
+
lp="$(kit_lib_purpose "$fix/long.sh")"
|
|
94
|
+
has "over-long purpose is elided" "$lp" "…"
|
|
95
|
+
no "elision drops the tail" "$lp" "tail"
|
|
96
|
+
rm -f "$fix/two.sh" "$fix/ab.sh" "$fix/long.sh"
|
|
97
|
+
|
|
98
|
+
# ── public functions: `_`-prefixed and nested definitions are not API ─────────────────────
|
|
99
|
+
eq "public functions only" "$(kit_lib_functions "$fix/alpha.sh")" "alpha_go"
|
|
100
|
+
eq "the 'function' keyword form" "$(kit_lib_functions "$fix/beta.sh")" "beta_net beta_pure"
|
|
101
|
+
eq "no functions -> empty" "$(kit_lib_functions "$fix/epsilon.sh")" ""
|
|
102
|
+
|
|
103
|
+
# ── error contract: read, never guessed; missing is `unknown`, not fatal ──────────────────
|
|
104
|
+
eq "errors strict" "$(kit_lib_errors "$fix/alpha.sh")" "strict"
|
|
105
|
+
eq "errors mixed" "$(kit_lib_errors "$fix/beta.sh")" "mixed"
|
|
106
|
+
eq "errors best-effort" "$(kit_lib_errors "$fix/delta.sh")" "best-effort"
|
|
107
|
+
eq "missing header -> unknown" "$(kit_lib_errors "$fix/gamma.sh")" "unknown"
|
|
108
|
+
eq "mixed reason" "$(kit_lib_errors_reason "$fix/beta.sh")" "beta_pure is pure; beta_net needs gh"
|
|
109
|
+
eq "no header -> no reason" "$(kit_lib_errors_reason "$fix/gamma.sh")" ""
|
|
110
|
+
|
|
111
|
+
# ── file listing: test runners are not part of the library ───────────────────────────────
|
|
112
|
+
eq "runners excluded" "$(kit_lib_files "$fix" | while IFS= read -r p; do basename "$p"; done | tr '\n' ',')" \
|
|
113
|
+
"alpha.sh,beta.sh,delta.sh,epsilon.sh,gamma.sh,"
|
|
114
|
+
has "runners included with all=1" "$(kit_lib_files "$fix" 1 | tr '\n' ' ')" "omega-test.sh"
|
|
115
|
+
eq "empty dir -> nothing" "$(kit_lib_files "$empty")" ""
|
|
116
|
+
eq "missing dir -> nothing" "$(kit_lib_files "$fix/nope")" ""
|
|
117
|
+
|
|
118
|
+
# ── rows: one TSV row per helper, four fields, table-safe ─────────────────────────────────
|
|
119
|
+
rows="$(kit_lib_rows "$fix")"
|
|
120
|
+
eq "one row per helper" "$(printf '%s\n' "$rows" | grep -c .)" "5"
|
|
121
|
+
eq "four fields per row" "$(printf '%s\n' "$rows" | awk -F'\t' 'NF!=4' | grep -c .)" "0"
|
|
122
|
+
no "no pipe leaks into a cell" "$rows" "|"
|
|
123
|
+
has "mixed row carries its reason" "$rows" "mixed — beta_pure is pure"
|
|
124
|
+
no "non-mixed reason hidden by default" "$rows" "a failed dependency propagates"
|
|
125
|
+
has "unknown contract is reported" "$rows" "gamma.sh unknown"
|
|
126
|
+
has "a surface-less helper shows a dash" "$rows" "epsilon.sh pure —"
|
|
127
|
+
has "--reasons exposes every reason" "$(kit_lib_rows "$fix" 0 1)" "strict — a failed dependency propagates"
|
|
128
|
+
# the function list is NEVER elided — an agent came here to find a name, not an ellipsis
|
|
129
|
+
printf '#!/usr/bin/env bash\n# many.sh — lots of surface.\n# errors: pure — no I/O\n' > "$fix/many.sh"
|
|
130
|
+
i=1; while [ "$i" -le 12 ]; do printf 'many_function_number_%02d() { :; }\n' "$i" >> "$fix/many.sh"; i=$((i + 1)); done
|
|
131
|
+
has "long function lists keep the last name" "$(kit_lib_rows "$fix")" "many_function_number_12"
|
|
132
|
+
no "long function lists are not elided" "$(kit_lib_functions "$fix/many.sh")" "…"
|
|
133
|
+
rm -f "$fix/many.sh"
|
|
134
|
+
eq "empty dir -> no rows" "$(kit_lib_rows "$empty")" ""
|
|
135
|
+
|
|
136
|
+
# ── dir resolution: an explicit root, and never a crash ──────────────────────────────────
|
|
137
|
+
mkdir -p "$fix/proj/scripts/lib"
|
|
138
|
+
eq "--root prefers scripts/lib" "$(KIT_LIB_DIR= kit_lib_dir "$fix/proj")" "$fix/proj/scripts/lib"
|
|
139
|
+
eq "--root falls back to the dir itself" "$(KIT_LIB_DIR= kit_lib_dir "$fix")" "$fix"
|
|
140
|
+
if (KIT_LIB_DIR= kit_lib_dir "$fix/nope" >/dev/null 2>&1); then
|
|
141
|
+
echo "FAIL($KL_TEST_INNER): a nonexistent --root should be rc 1"; fail=1
|
|
142
|
+
fi
|
|
143
|
+
|
|
144
|
+
# ── the full verb (bash only — sources render/toon via BASH_SOURCE) ───────────────────────
|
|
145
|
+
if [ "$KL_TEST_INNER" = "bash" ]; then
|
|
146
|
+
hum="$(KIT_LIB_DIR="$fix" CCKIT_NO_GLOW=1 CCKIT_OUTPUT=human kit_lib)"
|
|
147
|
+
has "human has the table header" "$hum" "| file | errors | public functions | purpose |"
|
|
148
|
+
has "human lists a helper" "$hum" '`alpha.sh`'
|
|
149
|
+
has "human explains the contract" "$hum" "declared failure contract"
|
|
150
|
+
has "human shows how to source" "$hum" "source $fix/<file>"
|
|
151
|
+
has "human states the exclusion" "$hum" "runner(s) are excluded"
|
|
152
|
+
no "human omits runners" "$hum" '`omega-test.sh`'
|
|
153
|
+
|
|
154
|
+
aout="$(KIT_LIB_DIR="$fix" CCKIT_NO_GLOW=1 CCKIT_OUTPUT=human kit_lib --all)"
|
|
155
|
+
has "--all includes runners" "$aout" '`omega-test.sh`'
|
|
156
|
+
|
|
157
|
+
# an empty library is a legitimate answer, not a crash
|
|
158
|
+
eout="$(KIT_LIB_DIR="$empty" CCKIT_NO_GLOW=1 CCKIT_OUTPUT=human kit_lib)"; erc=$?
|
|
159
|
+
eq "empty exits 0" "$erc" "0"
|
|
160
|
+
has "empty has a graceful state" "$eout" 'no `.sh` helpers'
|
|
161
|
+
|
|
162
|
+
eq "help lists the flags" "$(KIT_LIB_DIR="$fix" kit_lib --help | grep -c '^cckit lib')" "5"
|
|
163
|
+
|
|
164
|
+
if command -v jq >/dev/null 2>&1; then
|
|
165
|
+
llm="$(KIT_LIB_DIR="$fix" CCKIT_OUTPUT=json kit_lib --llm)"
|
|
166
|
+
has "TOON header" "$llm" "{file,errors,functions,purpose}"
|
|
167
|
+
has "TOON row" "$llm" '"alpha.sh"'
|
|
168
|
+
has "TOON keeps unknown" "$llm" '"unknown"'
|
|
169
|
+
eq "TOON row count" "$(printf '%s\n' "$llm" | head -1)" "[5]{file,errors,functions,purpose}:"
|
|
170
|
+
# an empty catalog is [] — never an error
|
|
171
|
+
eq "empty catalog is []" "$(KIT_LIB_DIR="$empty" CCKIT_OUTPUT=json kit_lib --llm)" "[]"
|
|
172
|
+
err="$(KIT_LIB_DIR="$fix" CCKIT_OUTPUT=json kit_lib --llm --bogus)"; brc=$?
|
|
173
|
+
eq "bad arg rc=2" "$brc" "2"
|
|
174
|
+
has "structured error" "$err" '"error"'
|
|
175
|
+
else
|
|
176
|
+
echo " (jq absent — skipping TOON/JSON assertions)"
|
|
177
|
+
fi
|
|
178
|
+
fi
|
|
179
|
+
|
|
180
|
+
# ── the header bound (#230 review) ───────────────────────────────────────────────────────────
|
|
181
|
+
# The `# errors:` declaration is part of the file's LEADING comment block. A `# errors:` line that
|
|
182
|
+
# appears in the BODY — a comment quoting this very convention — must never be read as the
|
|
183
|
+
# contract, and a header that runs long must still be found (two shipped libs carry headers past
|
|
184
|
+
# line 25, which is why the bound is structural and not a line window).
|
|
185
|
+
hdr="$(mktemp -d)"
|
|
186
|
+
cat > "$hdr/decoy.sh" <<'EOF'
|
|
187
|
+
#!/usr/bin/env bash
|
|
188
|
+
# decoy.sh — the header declares strict.
|
|
189
|
+
# errors: strict — the real declaration
|
|
190
|
+
main() { :; }
|
|
191
|
+
# errors: pure — a comment in the body quoting the convention, NOT the contract
|
|
192
|
+
EOF
|
|
193
|
+
eq "the body declaration is ignored" "$(kit_lib_errors "$hdr/decoy.sh")" "strict"
|
|
194
|
+
has "the reason comes from the header too" "$(kit_lib_errors_reason "$hdr/decoy.sh")" "the real declaration"
|
|
195
|
+
|
|
196
|
+
# A long header (blank comment lines, a shellcheck directive, 30+ lines) must still be read.
|
|
197
|
+
{ echo '#!/usr/bin/env bash'
|
|
198
|
+
echo '# shellcheck shell=bash'
|
|
199
|
+
echo '# long.sh — a helper with a long header.'
|
|
200
|
+
i=1; while [ "$i" -le 30 ]; do echo "# filler line $i"; i=$((i + 1)); done
|
|
201
|
+
echo '#'
|
|
202
|
+
echo '# errors: best-effort — declared on line 35'
|
|
203
|
+
echo 'main() { :; }'
|
|
204
|
+
} > "$hdr/long.sh"
|
|
205
|
+
eq "a header past line 25 is still found" "$(kit_lib_errors "$hdr/long.sh")" "best-effort"
|
|
206
|
+
|
|
207
|
+
# A file with no header at all reports unknown, never a guess from its body.
|
|
208
|
+
printf 'main() { :; }\n# errors: pure — body only\n' > "$hdr/none.sh"
|
|
209
|
+
eq "no header reports unknown" "$(kit_lib_errors "$hdr/none.sh")" "unknown"
|
|
210
|
+
|
|
211
|
+
# `--root` with no value must reject cleanly (bash aborts on `shift 2` with one arg left).
|
|
212
|
+
KIT_LIB_DIR="" kit_lib --root >/dev/null 2>&1; rrc=$?
|
|
213
|
+
eq "--root with no value is rc 2" "$rrc" "2"
|
|
214
|
+
|
|
215
|
+
rm -rf "$hdr"
|
|
216
|
+
rm -rf "$fix" "$empty"
|
|
217
|
+
if [ "$fail" -eq 0 ]; then echo "PASS($KL_TEST_INNER): kit-lib catalog parsers + verb shapes"; fi
|
|
218
|
+
exit "$fail"
|
|
219
|
+
fi
|
|
220
|
+
|
|
221
|
+
rc=0
|
|
222
|
+
for sh in bash zsh; do
|
|
223
|
+
command -v "$sh" >/dev/null 2>&1 || continue
|
|
224
|
+
KL_TEST_INNER="$sh" "$sh" "$0" || rc=1
|
|
225
|
+
done
|
|
226
|
+
exit "$rc"
|