@jeiemgi/cckit 0.2.0 → 0.3.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 +21 -8
- package/README.md +63 -5
- package/bin/cckit +37 -16
- package/cckit.config.json +1 -1
- package/commands/kit-doctor.md +3 -1
- package/kit.config.schema.json +24 -0
- package/package.json +1 -1
- package/scripts/annotate-setup.sh +7 -2
- package/scripts/capture-project-ids.sh +23 -10
- package/scripts/init.sh +22 -4
- package/scripts/kit-doctor.sh +185 -7
- package/scripts/kit-version-check-test.sh +36 -0
- package/scripts/kit-version-check.sh +19 -4
- package/scripts/knowledge-lint.sh +4 -1
- package/scripts/lib/board-view-test.sh +54 -0
- package/scripts/lib/board-view.sh +80 -0
- package/scripts/lib/captain-test.sh +18 -0
- package/scripts/lib/captain.sh +92 -5
- package/scripts/lib/config-path-test.sh +47 -0
- package/scripts/lib/config-path.sh +29 -0
- package/scripts/lib/copilot.sh +9 -9
- package/scripts/lib/effort-metrics-test.sh +57 -0
- package/scripts/lib/effort-metrics.sh +19 -5
- package/scripts/lib/effort-ops-test.sh +51 -2
- package/scripts/lib/effort-ops.sh +314 -49
- package/scripts/lib/effort-parity-test.sh +128 -0
- package/scripts/lib/effort-slug-test.sh +87 -0
- package/scripts/lib/effort-slug.sh +104 -0
- package/scripts/lib/effort.sh +34 -0
- package/scripts/lib/gh-project-test.sh +95 -0
- package/scripts/lib/gh-project.sh +22 -7
- package/scripts/lib/git-remote-test.sh +57 -0
- package/scripts/lib/git-remote.sh +21 -0
- package/scripts/lib/kit-config-test.sh +37 -0
- package/scripts/lib/kit-config.sh +33 -13
- package/scripts/lib/kit-events.sh +5 -3
- package/scripts/lib/kit-gc-test.sh +88 -0
- package/scripts/lib/kit-gc.sh +136 -19
- package/scripts/lib/kit-local.sh +8 -1
- package/scripts/lib/next.sh +3 -3
- package/scripts/lib/plan-next-test.sh +87 -0
- package/scripts/lib/plan-next.sh +212 -0
- package/scripts/lib/project-scan.sh +7 -1
- package/scripts/lib/worktree-start.sh +12 -3
- package/scripts/lib/zsh-safety-test.sh +73 -0
- package/scripts/portable-test.sh +62 -20
- package/scripts/setup-labels.sh +13 -2
- package/scripts/showcase.sh +13 -4
- package/scripts/status-test.sh +63 -0
- package/scripts/status.sh +12 -4
- package/scripts/task-sync.sh +79 -10
- package/skills/kit-autopilot/SKILL.md +5 -0
- package/skills/{docs-writer → kit-docs-writer}/SKILL.md +2 -2
- package/skills/kit-effort-new/SKILL.md +39 -111
- package/skills/kit-effort-pr/SKILL.md +6 -2
- package/skills/kit-next/SKILL.md +4 -0
- package/skills/kit-plan-next/SKILL.md +82 -0
- package/templates/hooks/mempal_session_start.sh.tmpl +36 -2
- package/templates/rules/effort-model.md +26 -6
- package/templates/rules/mempalace.md +1 -0
- package/templates/rules/plan-next.md +58 -0
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# shellcheck shell=bash
|
|
3
|
+
# kit-gc-test.sh — covers the recover-before-prune contract (#111). A ZOMBIE worktree (working dir
|
|
4
|
+
# gone, admin metadata lingers) can hold staged-but-uncommitted work in its admin index — the sole
|
|
5
|
+
# blob->path map. `git worktree prune` deletes that index, orphaning the blobs (real data loss). gc
|
|
6
|
+
# must (a) detect zombies + staged deltas as their own analysis bucket, (b) recover any staged delta
|
|
7
|
+
# to its branch as a commit BEFORE pruning, and (c) never prune in a dry-run.
|
|
8
|
+
# Hermetic: a throwaway git repo, no network/gh. Run: bash scripts/lib/kit-gc-test.sh
|
|
9
|
+
set -u
|
|
10
|
+
ROOT="$(cd "$(dirname "$0")/../.." && pwd)"
|
|
11
|
+
LIB="$ROOT/scripts/lib"
|
|
12
|
+
fail=0
|
|
13
|
+
t() { if [ "$2" = "$3" ]; then echo "ok: $1"; else echo "FAIL: $1 -> got '[$2]' want '[$3]'"; fail=1; fi; }
|
|
14
|
+
has(){ case "$2" in *"$3"*) echo "ok: $1" ;; *) echo "FAIL: $1 -> '$2' lacks '$3'"; fail=1 ;; esac; }
|
|
15
|
+
command -v git >/dev/null 2>&1 || { echo "kit-gc-test: git required" >&2; exit 1; }
|
|
16
|
+
|
|
17
|
+
tmp="$(mktemp -d)"; trap 'rm -rf "$tmp"' EXIT
|
|
18
|
+
export KIT_GC_REPO="o/r"
|
|
19
|
+
|
|
20
|
+
# ── fabricate a zombie worktree with a staged delta ─────────────────────────────────────────────
|
|
21
|
+
cd "$tmp"
|
|
22
|
+
git init -q main
|
|
23
|
+
cd main
|
|
24
|
+
git config user.email t@t; git config user.name t
|
|
25
|
+
echo "base" > base.txt; git add base.txt; git commit -q -m "init"
|
|
26
|
+
git worktree add -q ../wt -b feat/5-recover >/dev/null 2>&1
|
|
27
|
+
# Stage a NEW file inside the worktree (writes the worktree's admin index; the blob lands in the
|
|
28
|
+
# shared object store and so survives the worktree dir's death).
|
|
29
|
+
echo "precious staged work" > ../wt/keep.txt
|
|
30
|
+
git -C ../wt add keep.txt
|
|
31
|
+
TIP_BEFORE="$(git rev-parse --verify refs/heads/feat/5-recover)"
|
|
32
|
+
# Kill the worktree dir — the crash/ephemeral-mount death that leaves a zombie.
|
|
33
|
+
rm -rf ../wt
|
|
34
|
+
|
|
35
|
+
# shellcheck source=/dev/null
|
|
36
|
+
source "$LIB/kit-gc.sh"
|
|
37
|
+
|
|
38
|
+
# ── (a) detection: the zombie + its staged delta show up as their own bucket ─────────────────────
|
|
39
|
+
z="$(_kit_gc_zombies)"
|
|
40
|
+
has "zombie detected with its branch" "$z" "feat/5-recover"
|
|
41
|
+
case "$z" in *" yes"*) echo "ok: zombie flagged as STAGED" ;; *) echo "FAIL: zombie not flagged staged: $z"; fail=1 ;; esac
|
|
42
|
+
analysis="$(kit_gc_analyze 2>/dev/null)"
|
|
43
|
+
has "analyze lists a zombies bucket" "$analysis" "# zombies"
|
|
44
|
+
has "analyze flags STAGED work in the zombie" "$analysis" "ZOMBIE with STAGED work"
|
|
45
|
+
|
|
46
|
+
# ── (c) dry-run recovers NOTHING (no new commit, admin dir intact) ──────────────────────────────
|
|
47
|
+
kit_gc_recover_zombies 0 >/dev/null 2>&1
|
|
48
|
+
t "dry-run leaves the branch tip unchanged" "$(git rev-parse --verify refs/heads/feat/5-recover)" "$TIP_BEFORE"
|
|
49
|
+
[ -d "$(git rev-parse --git-common-dir)/worktrees/wt" ] && echo "ok: dry-run leaves the admin dir intact" || { echo "FAIL: dry-run removed the admin dir"; fail=1; }
|
|
50
|
+
|
|
51
|
+
# ── (b) recover-before-prune: the staged delta lands as a commit on the branch ──────────────────
|
|
52
|
+
kit_gc_recover_zombies 1 >/dev/null 2>&1
|
|
53
|
+
TIP_AFTER="$(git rev-parse --verify refs/heads/feat/5-recover)"
|
|
54
|
+
[ "$TIP_AFTER" != "$TIP_BEFORE" ] && echo "ok: recovery advanced the branch to a new commit" || { echo "FAIL: branch tip did not advance"; fail=1; }
|
|
55
|
+
t "the recovered commit's parent is the old tip" "$(git rev-parse --verify "${TIP_AFTER}^")" "$TIP_BEFORE"
|
|
56
|
+
# The staged file is present in the recovered commit's tree with its exact content.
|
|
57
|
+
has "recovered commit carries the staged file" "$(git ls-tree -r --name-only "$TIP_AFTER")" "keep.txt"
|
|
58
|
+
t "recovered file content is intact" "$(git show "$TIP_AFTER:keep.txt")" "precious staged work"
|
|
59
|
+
|
|
60
|
+
# ── prune gating: `git worktree prune` only removes the admin dir after recovery ─────────────────
|
|
61
|
+
git worktree prune 2>/dev/null || true
|
|
62
|
+
[ -d "$(git rev-parse --git-common-dir)/worktrees/wt" ] && { echo "FAIL: admin dir survived prune"; fail=1; } || echo "ok: admin dir pruned after the work was recovered"
|
|
63
|
+
|
|
64
|
+
# ── #124: single-call PR index + local lookup ───────────────────────────────────────────────────
|
|
65
|
+
IDX="$(printf 'feat/1-a\tPR#11 MERGED\nfeat/2-b\tPR#22 OPEN')"
|
|
66
|
+
t "pr index lookup finds a branch" "$(_kit_gc_pr_for "$IDX" feat/1-a)" "PR#11 MERGED"
|
|
67
|
+
t "pr index lookup finds another branch" "$(_kit_gc_pr_for "$IDX" feat/2-b)" "PR#22 OPEN"
|
|
68
|
+
t "pr index lookup misses an absent branch" "$(_kit_gc_pr_for "$IDX" feat/9-z)" ""
|
|
69
|
+
|
|
70
|
+
# kit_gc_analyze must issue exactly ONE `gh pr list` regardless of branch count (no per-branch N+1).
|
|
71
|
+
git branch feat/30-x >/dev/null 2>&1; git branch feat/31-y >/dev/null 2>&1; git branch feat/32-z >/dev/null 2>&1
|
|
72
|
+
stub="$tmp/ghbin"; mkdir -p "$stub"
|
|
73
|
+
cat > "$stub/gh" <<'SH'
|
|
74
|
+
#!/usr/bin/env bash
|
|
75
|
+
echo "$*" >> "$GH_CALLS"
|
|
76
|
+
case "$1 $2" in
|
|
77
|
+
"pr list") printf 'feat/30-x\tPR#30 MERGED\n' ;;
|
|
78
|
+
"issue view") echo "open" ;;
|
|
79
|
+
*) : ;;
|
|
80
|
+
esac
|
|
81
|
+
SH
|
|
82
|
+
chmod +x "$stub/gh"
|
|
83
|
+
export GH_CALLS="$tmp/ghcalls"; : > "$GH_CALLS"
|
|
84
|
+
PATH="$stub:$PATH" KIT_GC_REPO="o/r" kit_gc_analyze >/dev/null 2>&1
|
|
85
|
+
t "kit_gc_analyze makes exactly ONE gh pr list call" "$(grep -c '^pr list' "$GH_CALLS")" "1"
|
|
86
|
+
|
|
87
|
+
[ "$fail" -eq 0 ] && echo "ALL OK (kit-gc)" || echo "kit-gc: FAILURES"
|
|
88
|
+
exit "$fail"
|
package/scripts/lib/kit-gc.sh
CHANGED
|
@@ -29,27 +29,47 @@ _kit_gc_load_deps() {
|
|
|
29
29
|
[ -f "$d/worktree-issue.sh" ] && . "$d/worktree-issue.sh"
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
+
# _kit_gc_pr_index [repo] — echo one "<headRefName>\tPR#<num> <STATE>" line per PR in ONE gh call, so
|
|
33
|
+
# branch classification is a local lookup instead of a per-branch `gh pr list --head` — an N+1 that
|
|
34
|
+
# scaled badly exactly when gc matters most (many stale branches). #124.
|
|
35
|
+
_kit_gc_pr_index() {
|
|
36
|
+
local repo="${1:-$KIT_GC_REPO}"
|
|
37
|
+
gh pr list --repo "$repo" --state all --limit 200 --json number,state,headRefName \
|
|
38
|
+
--jq '.[] | "\(.headRefName)\tPR#\(.number) \(.state)"' 2>/dev/null || true
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
# _kit_gc_pr_for <index> <branch> — first PR line matching <branch> as head (mirrors the old `.[0]`).
|
|
42
|
+
_kit_gc_pr_for() {
|
|
43
|
+
printf '%s\n' "$1" | awk -F'\t' -v want="$2" '$1==want{print $2; exit}'
|
|
44
|
+
}
|
|
45
|
+
|
|
32
46
|
# kit_gc_analyze — read-only classification of worktrees, branches, and stashes. Writes NOTHING.
|
|
33
47
|
# Each row is tagged PROTECTED / SAFE / ACTIVE / ORPHAN so a human or UI can decide what to prune.
|
|
34
48
|
kit_gc_analyze() {
|
|
35
49
|
_kit_gc_load_deps
|
|
36
|
-
|
|
50
|
+
# `wtpath`, not `path`: under zsh `path` is tied to PATH (special array), so a bare `path` local
|
|
51
|
+
# here would clobber the command search path on assignment. A namespaced name is inert.
|
|
52
|
+
local repo="$KIT_GC_REPO" b ref wtpath reason pr prot
|
|
37
53
|
git fetch origin --prune --quiet 2>/dev/null || true
|
|
38
54
|
|
|
39
55
|
echo "# worktrees"
|
|
40
56
|
git worktree list --porcelain 2>/dev/null \
|
|
41
57
|
| awk '/^worktree /{w=$2} /^branch /{print w" "$2}' \
|
|
42
|
-
| while read -r
|
|
58
|
+
| while read -r wtpath ref; do
|
|
43
59
|
b="${ref#refs/heads/}"
|
|
44
60
|
reason="$(wt_protected_reason "$b" "$repo" 2>/dev/null || true)"
|
|
45
|
-
if [ -n "$reason" ]; then echo " $
|
|
46
|
-
else echo " $
|
|
61
|
+
if [ -n "$reason" ]; then echo " $wtpath [$b] -> PROTECTED: $reason"
|
|
62
|
+
else echo " $wtpath [$b] -> prunable if PR merged"; fi
|
|
47
63
|
done
|
|
48
64
|
|
|
49
65
|
echo "# branches"
|
|
50
|
-
|
|
66
|
+
# All PRs in ONE call, indexed locally by head branch (#124). while-read (NOT `for b in $(...)`) so
|
|
67
|
+
# branch iteration survives a NUL-polluted IFS.
|
|
68
|
+
local pr_index; pr_index="$(_kit_gc_pr_index "$repo")"
|
|
69
|
+
git branch --format='%(refname:short)' 2>/dev/null | while IFS= read -r b; do
|
|
70
|
+
[ -n "$b" ] || continue
|
|
51
71
|
case "$b" in "${KIT_BASE_BRANCH:-main}"|develop|main) echo " $b -> ACTIVE (base branch)"; continue;; esac
|
|
52
|
-
pr="$(
|
|
72
|
+
pr="$(_kit_gc_pr_for "$pr_index" "$b")"
|
|
53
73
|
prot="$(wt_protected_reason "$b" "$repo" 2>/dev/null || true)"
|
|
54
74
|
if [ -n "$prot" ]; then
|
|
55
75
|
echo " $b -> PROTECTED: $prot"
|
|
@@ -64,6 +84,21 @@ kit_gc_analyze() {
|
|
|
64
84
|
|
|
65
85
|
echo "# stashes"
|
|
66
86
|
git stash list 2>/dev/null | sed 's/^/ /' || true
|
|
87
|
+
|
|
88
|
+
echo "# zombies (worktree dir gone, admin metadata lingers)"
|
|
89
|
+
local zname zbranch zstaged found=0
|
|
90
|
+
while IFS="$(printf '\t')" read -r zname zbranch zstaged; do
|
|
91
|
+
[ -n "$zname" ] || continue
|
|
92
|
+
found=1
|
|
93
|
+
if [ "$zstaged" = yes ]; then
|
|
94
|
+
echo " $zname [$zbranch] -> ZOMBIE with STAGED work — recover-before-prune (gc --prune --yes recovers it to a commit)"
|
|
95
|
+
else
|
|
96
|
+
echo " $zname [$zbranch] -> ZOMBIE (no staged delta) — prunable"
|
|
97
|
+
fi
|
|
98
|
+
done <<EOF
|
|
99
|
+
$(_kit_gc_zombies)
|
|
100
|
+
EOF
|
|
101
|
+
[ "$found" -eq 1 ] || echo " (none)"
|
|
67
102
|
}
|
|
68
103
|
|
|
69
104
|
# kit_gc_has_prunable — rc 0 if at least one branch is SAFE to delete (a merged, unprotected branch).
|
|
@@ -71,6 +106,73 @@ kit_gc_has_prunable() {
|
|
|
71
106
|
kit_gc_analyze 2>/dev/null | grep -q '> SAFE '
|
|
72
107
|
}
|
|
73
108
|
|
|
109
|
+
# _kit_gc_zombies — echo "<name>\t<branch>\t<staged:yes|no>" for each ZOMBIE worktree: its working
|
|
110
|
+
# dir is gone but its admin metadata (<git-common-dir>/worktrees/<name>/) lingers. staged=yes when
|
|
111
|
+
# the admin index holds a tree that differs from the branch tip (staged-but-uncommitted work that
|
|
112
|
+
# `git worktree prune` would orphan). Writes NOTHING. bash 3.2.
|
|
113
|
+
_kit_gc_zombies() {
|
|
114
|
+
local common wdir name gitdir wtpath branch tree tip tiptree staged
|
|
115
|
+
common="$(git rev-parse --git-common-dir 2>/dev/null)" || return 0
|
|
116
|
+
case "$common" in /*) : ;; *) common="$(cd "$common" 2>/dev/null && pwd)" || return 0 ;; esac
|
|
117
|
+
[ -d "$common/worktrees" ] || return 0
|
|
118
|
+
for wdir in "$common"/worktrees/*/; do
|
|
119
|
+
[ -d "$wdir" ] || continue
|
|
120
|
+
gitdir="$(cat "$wdir/gitdir" 2>/dev/null)"; wtpath="${gitdir%/.git}"
|
|
121
|
+
# A zombie: the recorded working-tree path is set but no longer exists on disk.
|
|
122
|
+
[ -n "$wtpath" ] && [ ! -e "$wtpath" ] || continue
|
|
123
|
+
name="$(basename "$wdir")"
|
|
124
|
+
branch="$(sed -n 's#^ref: refs/heads/##p' "$wdir/HEAD" 2>/dev/null)"
|
|
125
|
+
tree=""; [ -f "$wdir/index" ] && tree="$(GIT_INDEX_FILE="$wdir/index" git write-tree 2>/dev/null)"
|
|
126
|
+
tip="$(git rev-parse --verify --quiet "refs/heads/${branch}" 2>/dev/null)"
|
|
127
|
+
tiptree=""; [ -n "$tip" ] && tiptree="$(git rev-parse --verify --quiet "${tip}^{tree}" 2>/dev/null)"
|
|
128
|
+
if [ -n "$tree" ] && [ "$tree" != "$tiptree" ]; then staged=yes; else staged=no; fi
|
|
129
|
+
printf '%s\t%s\t%s\n' "$name" "${branch:-?}" "$staged"
|
|
130
|
+
done
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
# kit_gc_recover_zombies <yes> — the recover-before-prune mechanic (#111). For each ZOMBIE worktree
|
|
134
|
+
# holding staged-but-uncommitted work, recover that delta to its branch via plumbing BEFORE any
|
|
135
|
+
# prune: GIT_INDEX_FILE=<admin>/index git write-tree -> git commit-tree -p <tip> -> update-ref. With
|
|
136
|
+
# <yes>=1 it performs the recovery + sweeps that zombie's stale locks; otherwise it reports what it
|
|
137
|
+
# WOULD recover (dry-run). Never prunes; that stays with the caller (gated on --yes). bash 3.2.
|
|
138
|
+
kit_gc_recover_zombies() {
|
|
139
|
+
local yes="${1:-0}" common wdir name gitdir wtpath branch tree tip tiptree newc msg
|
|
140
|
+
common="$(git rev-parse --git-common-dir 2>/dev/null)" || return 0
|
|
141
|
+
case "$common" in /*) : ;; *) common="$(cd "$common" 2>/dev/null && pwd)" || return 0 ;; esac
|
|
142
|
+
[ -d "$common/worktrees" ] || return 0
|
|
143
|
+
for wdir in "$common"/worktrees/*/; do
|
|
144
|
+
[ -d "$wdir" ] || continue
|
|
145
|
+
gitdir="$(cat "$wdir/gitdir" 2>/dev/null)"; wtpath="${gitdir%/.git}"
|
|
146
|
+
[ -n "$wtpath" ] && [ ! -e "$wtpath" ] || continue # only dead worktrees
|
|
147
|
+
name="$(basename "$wdir")"
|
|
148
|
+
branch="$(sed -n 's#^ref: refs/heads/##p' "$wdir/HEAD" 2>/dev/null)"
|
|
149
|
+
[ -f "$wdir/index" ] || continue
|
|
150
|
+
tree="$(GIT_INDEX_FILE="$wdir/index" git write-tree 2>/dev/null)" || continue
|
|
151
|
+
[ -n "$tree" ] || continue
|
|
152
|
+
tip="$(git rev-parse --verify --quiet "refs/heads/${branch}" 2>/dev/null)"
|
|
153
|
+
tiptree=""; [ -n "$tip" ] && tiptree="$(git rev-parse --verify --quiet "${tip}^{tree}" 2>/dev/null)"
|
|
154
|
+
# No staged delta beyond the tip → nothing to recover; the zombie is safe to prune as-is.
|
|
155
|
+
[ "$tree" = "$tiptree" ] && continue
|
|
156
|
+
[ -n "$branch" ] || { echo " gc: zombie $name is detached with staged work — leaving it for manual recovery" >&2; continue; }
|
|
157
|
+
if [ "$yes" -ne 1 ]; then
|
|
158
|
+
echo " would RECOVER staged work from zombie worktree $name -> a commit on $branch (staged tree $tree)" >&2
|
|
159
|
+
continue
|
|
160
|
+
fi
|
|
161
|
+
msg="kit gc: recovered staged work from zombie worktree $name (recover-before-prune)"
|
|
162
|
+
newc="$(printf '%s\n' "$msg" | GIT_AUTHOR_NAME="${GIT_AUTHOR_NAME:-kit-gc}" GIT_AUTHOR_EMAIL="${GIT_AUTHOR_EMAIL:-kit-gc@localhost}" GIT_COMMITTER_NAME="${GIT_COMMITTER_NAME:-kit-gc}" GIT_COMMITTER_EMAIL="${GIT_COMMITTER_EMAIL:-kit-gc@localhost}" git commit-tree "$tree" ${tip:+-p "$tip"} 2>/dev/null)"
|
|
163
|
+
if [ -n "$newc" ]; then
|
|
164
|
+
# Compare-and-swap on the tip so a concurrent update is never clobbered.
|
|
165
|
+
if git update-ref "refs/heads/$branch" "$newc" ${tip:+"$tip"} 2>/dev/null; then
|
|
166
|
+
echo " RECOVERED staged work from zombie $name -> commit ${newc%% *} on $branch" >&2
|
|
167
|
+
else
|
|
168
|
+
echo " gc: could not update refs/heads/$branch (moved concurrently?) — zombie $name left intact" >&2
|
|
169
|
+
fi
|
|
170
|
+
fi
|
|
171
|
+
# Stale-lock sweep — safe only because this worktree is provably dead.
|
|
172
|
+
rm -f "$wdir/index.lock" "$wdir/HEAD.lock" 2>/dev/null || true
|
|
173
|
+
done
|
|
174
|
+
}
|
|
175
|
+
|
|
74
176
|
# kit_gc_prune [--yes] - remove worktrees + local branches whose PR is MERGED (the SAFE rows).
|
|
75
177
|
# DRY-RUN by default (lists what it WOULD remove); --yes performs the deletions. Never touches a
|
|
76
178
|
# PROTECTED/ACTIVE/ORPHAN branch, and never a DIRTY worktree (recover-before-prune): a worktree with
|
|
@@ -78,35 +180,50 @@ kit_gc_has_prunable() {
|
|
|
78
180
|
# already deleted at merge time (gh pr merge --delete-branch); this cleans up the local side.
|
|
79
181
|
kit_gc_prune() {
|
|
80
182
|
_kit_gc_load_deps
|
|
81
|
-
|
|
183
|
+
# `wtpath`, not `path`: under zsh `path` is tied to PATH (special array), so assigning to a bare
|
|
184
|
+
# `path` local would clobber the command search path. A namespaced name is inert.
|
|
185
|
+
local repo="$KIT_GC_REPO" yes=0 a wtpath ref b pr pr_index
|
|
82
186
|
for a in "$@"; do case "$a" in --yes|-y) yes=1 ;; esac; done
|
|
83
187
|
|
|
188
|
+
# All PRs in ONE call, indexed by head branch (#124) — shared by both loops below instead of a
|
|
189
|
+
# per-branch `gh pr list --head` (the N+1 that scaled badly with many stale branches).
|
|
190
|
+
pr_index="$(_kit_gc_pr_index "$repo")"
|
|
191
|
+
|
|
84
192
|
# Worktrees first - a branch's worktree must be removed before the branch can be deleted.
|
|
85
193
|
git worktree list --porcelain 2>/dev/null \
|
|
86
194
|
| awk '/^worktree /{w=$2} /^branch /{print w" "$2}' \
|
|
87
|
-
| while read -r
|
|
195
|
+
| while read -r wtpath ref; do
|
|
88
196
|
b="${ref#refs/heads/}"
|
|
89
197
|
case "$b" in "${KIT_BASE_BRANCH:-main}"|develop|main|"") continue ;; esac
|
|
90
198
|
[ -n "$(wt_protected_reason "$b" "$repo" 2>/dev/null || true)" ] && continue
|
|
91
|
-
pr="$(
|
|
92
|
-
|
|
93
|
-
if [ -n "$(git -C "$
|
|
94
|
-
echo " SKIP dirty worktree $
|
|
199
|
+
pr="$(_kit_gc_pr_for "$pr_index" "$b")"
|
|
200
|
+
printf '%s' "$pr" | grep -q 'MERGED' || continue
|
|
201
|
+
if [ -n "$(git -C "$wtpath" status --porcelain 2>/dev/null)" ]; then
|
|
202
|
+
echo " SKIP dirty worktree $wtpath [$b] - commit/recover before pruning" >&2; continue
|
|
95
203
|
fi
|
|
96
204
|
if [ "$yes" -eq 1 ]; then
|
|
97
|
-
git worktree remove --force "$
|
|
205
|
+
git worktree remove --force "$wtpath" 2>/dev/null && echo " removed worktree $wtpath [$b]"
|
|
98
206
|
else
|
|
99
|
-
echo " would remove worktree $
|
|
207
|
+
echo " would remove worktree $wtpath [$b] (PR MERGED)"
|
|
100
208
|
fi
|
|
101
209
|
done
|
|
102
|
-
git worktree prune 2>/dev/null || true
|
|
103
210
|
|
|
104
|
-
#
|
|
105
|
-
|
|
211
|
+
# recover-before-prune (#111): a zombie worktree (working dir gone, admin metadata lingers) may
|
|
212
|
+
# hold staged-but-uncommitted work in its admin index — the ONLY blob->path map. `git worktree
|
|
213
|
+
# prune` deletes that index, orphaning the blobs for a later `git gc` to reap — real data loss in a
|
|
214
|
+
# documented incident. Recover any staged delta to its branch FIRST, and gate the prune sweep
|
|
215
|
+
# behind --yes so it NEVER runs in a dry-run (the previous unconditional prune was the hazard).
|
|
216
|
+
kit_gc_recover_zombies "$yes"
|
|
217
|
+
[ "$yes" -eq 1 ] && { git worktree prune 2>/dev/null || true; }
|
|
218
|
+
|
|
219
|
+
# Then local branches whose PR merged (worktree now gone). while-read (NOT `for b in $(...)`) so
|
|
220
|
+
# branch iteration survives a NUL-polluted IFS (#124).
|
|
221
|
+
git branch --format='%(refname:short)' 2>/dev/null | while IFS= read -r b; do
|
|
222
|
+
[ -n "$b" ] || continue
|
|
106
223
|
case "$b" in "${KIT_BASE_BRANCH:-main}"|develop|main) continue ;; esac
|
|
107
224
|
[ -n "$(wt_protected_reason "$b" "$repo" 2>/dev/null || true)" ] && continue
|
|
108
|
-
pr="$(
|
|
109
|
-
|
|
225
|
+
pr="$(_kit_gc_pr_for "$pr_index" "$b")"
|
|
226
|
+
printf '%s' "$pr" | grep -q 'MERGED' || continue
|
|
110
227
|
if [ "$yes" -eq 1 ]; then
|
|
111
228
|
git branch -D "$b" >/dev/null 2>&1 && echo " deleted local branch $b (PR MERGED)"
|
|
112
229
|
else
|
package/scripts/lib/kit-local.sh
CHANGED
|
@@ -16,7 +16,14 @@
|
|
|
16
16
|
# KIT_LOCAL_TIMEOUT (default 90s; hooks should pass lower via env when latency matters).
|
|
17
17
|
# Config: .claude/kit.config.json -> .local {enabled, port, model} (KIT_LOCAL_* env wins).
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
# Resolve config through the ONE shared resolver (config-path.sh, #69): KIT_CONFIG wins, else a root
|
|
20
|
+
# cckit.config.json or a .claude/kit.config.json (walk up). Falls back to the scaffolded path.
|
|
21
|
+
if ! command -v kit_config_path >/dev/null 2>&1; then
|
|
22
|
+
_kl_dir="$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" && pwd)"
|
|
23
|
+
# shellcheck source=/dev/null
|
|
24
|
+
[ -f "$_kl_dir/config-path.sh" ] && . "$_kl_dir/config-path.sh"; unset _kl_dir
|
|
25
|
+
fi
|
|
26
|
+
KIT_LOCAL_CONFIG="$(kit_config_path 2>/dev/null || true)"; [ -n "$KIT_LOCAL_CONFIG" ] || KIT_LOCAL_CONFIG=".claude/kit.config.json"
|
|
20
27
|
|
|
21
28
|
_kit_local_cfg() { # _kit_local_cfg <jq-path> <default>
|
|
22
29
|
local v=""
|
package/scripts/lib/next.sh
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
# next.sh — "what can I pick up right now?" The everyday-dev helper (Effort 75 · #79).
|
|
3
3
|
#
|
|
4
4
|
# Surfaces the unblocked set (wave 0 of the plan machine) and the single recommended next issue with
|
|
5
|
-
# the one command to start it. This is the daily-loop counterpart to
|
|
6
|
-
#
|
|
5
|
+
# the one command to start it. This is the daily-loop counterpart to `cckit wave`: wave fans a whole
|
|
6
|
+
# wave out to subagents; `cckit next` is for a human (or agent) picking up one issue by hand.
|
|
7
7
|
#
|
|
8
8
|
# cckit next the unblocked issues + the top one's start command
|
|
9
9
|
# cckit next --effort <N> scope to effort #N's sub-issues
|
|
@@ -70,6 +70,6 @@ next_issue() {
|
|
|
70
70
|
printf '\n## Pick up #%s — %s\n\n' "$topnum" "$toptitle"
|
|
71
71
|
printf 'Start it in an isolated worktree + branch:\n\n'
|
|
72
72
|
printf '```\ncckit start %s\n```\n\n' "$topnum"
|
|
73
|
-
printf 'Or fan the whole unblocked wave out to subagents with `cckit
|
|
73
|
+
printf 'Or fan the whole unblocked wave out to subagents with `cckit wave%s`.\n' "$([ -n "$effort" ] && echo " --effort $effort")"
|
|
74
74
|
} | cckit_render
|
|
75
75
|
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
#!/bin/sh
|
|
2
|
+
# plan-next-test.sh — self-test for plan-next.sh (Effort 86 · #91).
|
|
3
|
+
# Network-free, filesystem-only: builds a throwaway fixture project and asserts the inventory
|
|
4
|
+
# scanners, the proposal shape (TOON + JSON + human), empty states, the structured error, and the
|
|
5
|
+
# invariant that EVERY plan carries the mandatory docs + README step. The pure scanners + proposals
|
|
6
|
+
# run under bash AND zsh; the full plan_next verb (which sources render/toon via BASH_SOURCE) runs
|
|
7
|
+
# under bash, matching how the dispatcher invokes it. Run: bash scripts/lib/plan-next-test.sh
|
|
8
|
+
|
|
9
|
+
dir=$(CDPATH='' cd -- "$(dirname -- "$0")" && pwd)
|
|
10
|
+
|
|
11
|
+
# _pn_fixture <root> — a small capability tree. docs mention alpha-skill + the 'foo' verb but NOT
|
|
12
|
+
# beta-skill or 'bar', so those two become the coverage-gap proposals.
|
|
13
|
+
_pn_fixture() {
|
|
14
|
+
local r="$1"
|
|
15
|
+
mkdir -p "$r/skills/alpha-skill" "$r/skills/beta-skill" "$r/rules" "$r/docs" "$r/commands"
|
|
16
|
+
: > "$r/skills/alpha-skill/SKILL.md"; : > "$r/skills/beta-skill/SKILL.md"
|
|
17
|
+
: > "$r/rules/r1.md"; : > "$r/rules/r2.md"
|
|
18
|
+
: > "$r/commands/foo.md"; : > "$r/commands/bar.md"
|
|
19
|
+
printf 'see the alpha-skill skill and the foo verb.\n' > "$r/docs/intro.md"
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
if [ -n "${PN_TEST_INNER:-}" ]; then
|
|
23
|
+
. "$dir/plan-next.sh"
|
|
24
|
+
fail=0
|
|
25
|
+
eq() { if [ "$2" != "$3" ]; then echo "FAIL($PN_TEST_INNER): $1 -> '[$2]', want '[$3]'"; fail=1; fi; }
|
|
26
|
+
has() { case "$2" in *"$3"*) ;; *) echo "FAIL($PN_TEST_INNER): $1 missing '[$3]'"; fail=1 ;; esac; }
|
|
27
|
+
no() { case "$2" in *"$3"*) echo "FAIL($PN_TEST_INNER): $1 should NOT contain '[$3]'"; fail=1 ;; esac; }
|
|
28
|
+
|
|
29
|
+
fix="$(mktemp -d)"; _pn_fixture "$fix"
|
|
30
|
+
empty="$(mktemp -d)"
|
|
31
|
+
|
|
32
|
+
# --- pure scanners (bash + zsh) ---
|
|
33
|
+
eq "skills scanner" "$(plan_next_skills "$fix" | tr '\n' ',')" "alpha-skill,beta-skill,"
|
|
34
|
+
eq "verbs scanner (commands fallback)" "$(plan_next_verbs "$fix" | tr '\n' ',')" "bar,foo,"
|
|
35
|
+
eq "rules scanner" "$(plan_next_rules "$fix" | tr '\n' ',')" "r1,r2,"
|
|
36
|
+
eq "docs scanner" "$(plan_next_docs "$fix" | tr '\n' ',')" "intro,"
|
|
37
|
+
eq "empty skills -> nothing" "$(plan_next_skills "$empty")" ""
|
|
38
|
+
|
|
39
|
+
# --- proposals shape (bash + zsh) ---
|
|
40
|
+
props="$(_pn_proposals "$fix")"
|
|
41
|
+
first="$(printf '%s\n' "$props" | head -1)"
|
|
42
|
+
has "rank 1 is docs" "$first" "1 docs"
|
|
43
|
+
has "mandatory docs+README" "$first" "README"
|
|
44
|
+
has "undocumented skill gap" "$props" "beta-skill"
|
|
45
|
+
has "undocumented verb gap" "$props" "bar"
|
|
46
|
+
no "documented skill not flagged as gap" "$props" "Document the alpha-skill"
|
|
47
|
+
# EVERY plan carries the docs + README step — also on a bare project.
|
|
48
|
+
has "empty plan still has docs+README" "$(_pn_proposals "$empty")" "README"
|
|
49
|
+
|
|
50
|
+
# --- full verb (bash only — sources render/toon via BASH_SOURCE) ---
|
|
51
|
+
if [ "$PN_TEST_INNER" = "bash" ]; then
|
|
52
|
+
hum="$(PLAN_NEXT_ROOT="$fix" CCKIT_NO_GLOW=1 CCKIT_OUTPUT=human plan_next)"
|
|
53
|
+
has "human shows capabilities" "$hum" "Current capabilities"
|
|
54
|
+
has "human shows docs+README" "$hum" "README"
|
|
55
|
+
has "human states context rule" "$hum" "context-anxiety"
|
|
56
|
+
|
|
57
|
+
# empty/host project: graceful, exits 0, still carries the docs step.
|
|
58
|
+
eout="$(PLAN_NEXT_ROOT="$empty" CCKIT_NO_GLOW=1 CCKIT_OUTPUT=human plan_next)"; erc=$?
|
|
59
|
+
eq "empty exits 0" "$erc" "0"
|
|
60
|
+
has "empty has graceful banner" "$eout" "No kit capabilities found"
|
|
61
|
+
has "empty still has docs+README" "$eout" "README"
|
|
62
|
+
|
|
63
|
+
if command -v jq >/dev/null 2>&1; then
|
|
64
|
+
llm="$(PLAN_NEXT_ROOT="$fix" CCKIT_OUTPUT=json plan_next --llm)"
|
|
65
|
+
has "TOON header" "$llm" "{rank,area,proposal,next}"
|
|
66
|
+
has "TOON has docs row" "$llm" "README"
|
|
67
|
+
has "TOON has next col" "$llm" "/kit-effort-new"
|
|
68
|
+
# structured error on a bad arg.
|
|
69
|
+
err="$(PLAN_NEXT_ROOT="$fix" CCKIT_OUTPUT=json plan_next --llm --bogus)"; brc=$?
|
|
70
|
+
eq "bad arg rc=2" "$brc" "2"
|
|
71
|
+
has "structured error" "$err" '"error"'
|
|
72
|
+
else
|
|
73
|
+
echo " (jq absent — skipping TOON/JSON assertions)"
|
|
74
|
+
fi
|
|
75
|
+
fi
|
|
76
|
+
|
|
77
|
+
rm -rf "$fix" "$empty"
|
|
78
|
+
if [ "$fail" -eq 0 ]; then echo "PASS($PN_TEST_INNER): plan-next inventory + plan shapes"; fi
|
|
79
|
+
exit "$fail"
|
|
80
|
+
fi
|
|
81
|
+
|
|
82
|
+
rc=0
|
|
83
|
+
for sh in bash zsh; do
|
|
84
|
+
command -v "$sh" >/dev/null 2>&1 || continue
|
|
85
|
+
PN_TEST_INNER="$sh" "$sh" "$0" || rc=1
|
|
86
|
+
done
|
|
87
|
+
exit "$rc"
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# plan-next.sh — the forward planner (Effort 86 · #87/#88). cckit's "given where we are, here is what
|
|
3
|
+
# to build next" triage, productized. It introspects the CURRENT capability surface — skills,
|
|
4
|
+
# commands/verbs, rules, docs — at runtime and proposes concrete next efforts grounded in what the
|
|
5
|
+
# kit can already do. Run against cckit itself (full inventory) or any project the kit is installed
|
|
6
|
+
# in (degrades to whatever capability dirs exist, never crashes).
|
|
7
|
+
#
|
|
8
|
+
# cckit plan-next current capabilities + a proposed forward plan (markdown)
|
|
9
|
+
# cckit plan-next --llm the proposed plan as TOON rows {rank,area,proposal,next} (JSON fallback)
|
|
10
|
+
# cckit plan-next --root <dir> scan <dir> instead of the resolved project/kit root
|
|
11
|
+
#
|
|
12
|
+
# CRITICAL — context-anxiety rule: this output is HUMAN / orchestrator-facing ONLY. It is NEVER to
|
|
13
|
+
# be injected into a monitored model's prompt or context. The planner pre-grounds planning in the
|
|
14
|
+
# current docs/skills/rules so the EXECUTING agent burns fewer tokens rediscovering context — it is
|
|
15
|
+
# not itself agent-context fuel. The verb and the skill both honor this; see rules/plan-next.md.
|
|
16
|
+
#
|
|
17
|
+
# Filesystem-only — needs jq only for --llm (TOON/JSON). bash 3.2 / zsh compatible.
|
|
18
|
+
|
|
19
|
+
# _pn_first_dir <dir> [dir …] — echo the first directory that exists (graceful host-project fallback).
|
|
20
|
+
_pn_first_dir() {
|
|
21
|
+
local d
|
|
22
|
+
for d in "$@"; do [ -n "$d" ] && [ -d "$d" ] && { printf '%s' "$d"; return 0; }; done
|
|
23
|
+
return 1
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
# plan_next_skills_dir / _rules_dir / _docs_dir <root> — resolve the capability dir for one area,
|
|
27
|
+
# trying cckit's own layout first, then the installed-in-a-project layout. Empty when none exist.
|
|
28
|
+
plan_next_skills_dir() { _pn_first_dir "$1/skills" "$1/.claude/skills" 2>/dev/null; }
|
|
29
|
+
plan_next_rules_dir() { _pn_first_dir "$1/rules" "$1/templates/rules" "$1/.claude/rules" 2>/dev/null; }
|
|
30
|
+
plan_next_docs_dir() { _pn_first_dir "$1/docs-site/src/content/docs" "$1/docs" "$1/.claude/docs" 2>/dev/null; }
|
|
31
|
+
|
|
32
|
+
# All scanners use `find` (not shell globs): an unmatched glob errors under zsh's nomatch and stays
|
|
33
|
+
# literal under bash — `find` handles "no matches" cleanly in both, so the lib is shell-portable.
|
|
34
|
+
|
|
35
|
+
# plan_next_skills <root> — one skill name per line (the SKILL.md parent dir basename), sorted.
|
|
36
|
+
plan_next_skills() {
|
|
37
|
+
local dir; dir="$(plan_next_skills_dir "$1")" || return 0
|
|
38
|
+
find "$dir" -mindepth 2 -maxdepth 2 -name SKILL.md -type f 2>/dev/null \
|
|
39
|
+
| while IFS= read -r f; do basename "$(dirname "$f")"; done | sort -u
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
# plan_next_rules <root> — one rule name per line (the .md basename without extension), sorted.
|
|
43
|
+
plan_next_rules() {
|
|
44
|
+
local dir; dir="$(plan_next_rules_dir "$1")" || return 0
|
|
45
|
+
find "$dir" -maxdepth 1 -name '*.md' -type f 2>/dev/null \
|
|
46
|
+
| while IFS= read -r f; do b="$(basename "$f")"; printf '%s\n' "${b%.md}"; done | sort -u
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
# plan_next_verbs <root> — one verb per line. Prefer the cckit dispatcher's own case labels (the
|
|
50
|
+
# single source of truth, same parse as `cckit commands`); fall back to a commands/ listing when run
|
|
51
|
+
# in a host project that has no bin/cckit.
|
|
52
|
+
plan_next_verbs() {
|
|
53
|
+
local root="$1"
|
|
54
|
+
if [ -f "$root/bin/cckit" ]; then
|
|
55
|
+
grep -oE '^ [a-z][a-z|-]*\)' "$root/bin/cckit" \
|
|
56
|
+
| sed 's/[) ]//g' | tr '|' '\n' | grep -vE '^(-|$)' | sort -u
|
|
57
|
+
return 0
|
|
58
|
+
fi
|
|
59
|
+
local dir; dir="$(_pn_first_dir "$root/commands" "$root/.claude/commands" 2>/dev/null)" || return 0
|
|
60
|
+
find "$dir" -maxdepth 1 -name '*.md' -type f 2>/dev/null \
|
|
61
|
+
| while IFS= read -r f; do b="$(basename "$f")"; printf '%s\n' "${b%.md}"; done | sort -u
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
# plan_next_docs <root> — one doc name per line (the .md/.mdx basename without extension), sorted.
|
|
65
|
+
plan_next_docs() {
|
|
66
|
+
local dir; dir="$(plan_next_docs_dir "$1")" || return 0
|
|
67
|
+
find "$dir" -maxdepth 1 \( -name '*.md' -o -name '*.mdx' \) -type f 2>/dev/null \
|
|
68
|
+
| while IFS= read -r f; do b="$(basename "$f")"; b="${b%.mdx}"; printf '%s\n' "${b%.md}"; done | sort -u
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
# _pn_docs_blob <root> — all doc text concatenated + lowercased, for coverage-gap detection.
|
|
72
|
+
_pn_docs_blob() {
|
|
73
|
+
local dir; dir="$(plan_next_docs_dir "$1")" || return 0
|
|
74
|
+
find "$dir" -maxdepth 1 \( -name '*.md' -o -name '*.mdx' \) -type f -exec cat {} + 2>/dev/null \
|
|
75
|
+
| tr '[:upper:]' '[:lower:]'
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
# _pn_root — the directory to scan. PLAN_NEXT_ROOT wins (tests / explicit), else the project root
|
|
79
|
+
# inferred from KIT_CONFIG (parent of a .claude/ config), else $PWD. In cckit this is the cckit repo;
|
|
80
|
+
# in a host project it is that project — so the inventory is always "this project's capabilities".
|
|
81
|
+
_pn_root() {
|
|
82
|
+
if [ -n "${PLAN_NEXT_ROOT:-}" ]; then printf '%s' "$PLAN_NEXT_ROOT"; return 0; fi
|
|
83
|
+
local cfg="${KIT_CONFIG:-}" d
|
|
84
|
+
if [ -n "$cfg" ] && [ -f "$cfg" ]; then
|
|
85
|
+
d="$(cd "$(dirname "$cfg")" 2>/dev/null && pwd)" || d=""
|
|
86
|
+
case "$d" in */.claude) d="$(dirname "$d")" ;; esac
|
|
87
|
+
[ -n "$d" ] && { printf '%s' "$d"; return 0; }
|
|
88
|
+
fi
|
|
89
|
+
printf '%s' "$PWD"
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
# _pn_proposals <root> — the forward plan as TSV rows: rank<TAB>area<TAB>proposal<TAB>next.
|
|
93
|
+
# Deterministic + grounded in the inventory. ALWAYS emits the mandatory docs + README item first
|
|
94
|
+
# (docs-always rule — never dropped, even for a tiny change). Then up to 3 concrete coverage gaps
|
|
95
|
+
# (skills/verbs not referenced anywhere in the docs), then a thinnest-area suggestion so there is
|
|
96
|
+
# always >=1 concrete next effort beyond docs. Capped so the plan stays scannable.
|
|
97
|
+
_pn_proposals() {
|
|
98
|
+
local root="$1" rank=1
|
|
99
|
+
local handoff="/kit-effort-new"
|
|
100
|
+
|
|
101
|
+
# 1. MANDATORY — docs + README. Non-negotiable, always present (asserted by tests).
|
|
102
|
+
printf '%s\tdocs\t%s\t%s\n' "$rank" \
|
|
103
|
+
"Update the docs site + README + AGENTS for the latest work (mandatory, never skipped)" "$handoff"
|
|
104
|
+
rank=$((rank + 1))
|
|
105
|
+
|
|
106
|
+
# 2. Coverage gaps — capabilities not yet mentioned anywhere in the docs (grounded in current state).
|
|
107
|
+
local blob s v added=0
|
|
108
|
+
blob="$(_pn_docs_blob "$root")"
|
|
109
|
+
for s in $(plan_next_skills "$root"); do
|
|
110
|
+
[ "$added" -ge 3 ] && break
|
|
111
|
+
case "$blob" in *"$s"*) ;; *)
|
|
112
|
+
printf '%s\tskills\t%s\t%s\n' "$rank" "Document the $s skill — it is not referenced in any doc page" "$handoff"
|
|
113
|
+
rank=$((rank + 1)); added=$((added + 1)) ;;
|
|
114
|
+
esac
|
|
115
|
+
done
|
|
116
|
+
for v in $(plan_next_verbs "$root"); do
|
|
117
|
+
[ "$added" -ge 3 ] && break
|
|
118
|
+
case "$blob" in *"$v"*) ;; *)
|
|
119
|
+
printf '%s\tcommands\t%s\t%s\n' "$rank" "Add the '$v' verb to the CLI reference — it ships but is undocumented" "$handoff"
|
|
120
|
+
rank=$((rank + 1)); added=$((added + 1)) ;;
|
|
121
|
+
esac
|
|
122
|
+
done
|
|
123
|
+
|
|
124
|
+
# 3. Thinnest-area suggestion — guarantees a concrete non-docs proposal even when coverage is clean.
|
|
125
|
+
local cs cv cr thin tn
|
|
126
|
+
cs="$(plan_next_skills "$root" | grep -c .)"
|
|
127
|
+
cv="$(plan_next_verbs "$root" | grep -c .)"
|
|
128
|
+
cr="$(plan_next_rules "$root" | grep -c .)"
|
|
129
|
+
thin="skills"; tn="$cs"
|
|
130
|
+
[ "$cv" -lt "$tn" ] && { thin="commands"; tn="$cv"; }
|
|
131
|
+
[ "$cr" -lt "$tn" ] && { thin="rules"; tn="$cr"; }
|
|
132
|
+
printf '%s\t%s\t%s\t%s\n' "$rank" "$thin" \
|
|
133
|
+
"Deepen the thinnest area '$thin' ($tn entries) — propose one new capability there" "$handoff"
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
# plan_next — the verb body. Human markdown by default; TOON/JSON under --llm. Never injects into
|
|
137
|
+
# any agent context (context-anxiety rule).
|
|
138
|
+
plan_next() {
|
|
139
|
+
local out="${CCKIT_OUTPUT:-human}" root=""
|
|
140
|
+
while [ "$#" -gt 0 ]; do
|
|
141
|
+
case "$1" in
|
|
142
|
+
--llm|--output=json) out="json"; shift ;;
|
|
143
|
+
--root) root="$2"; shift 2 ;;
|
|
144
|
+
--root=*) root="${1#*=}"; shift ;;
|
|
145
|
+
-h|--help) sed -n '8,11p' "${BASH_SOURCE[0]}" | sed 's/^# \{0,1\}//'; return 0 ;;
|
|
146
|
+
*) if [ "$out" = "json" ]; then _pn_err "unknown arg '$1'"; else echo "plan-next: unknown arg '$1'" >&2; fi; return 2 ;;
|
|
147
|
+
esac
|
|
148
|
+
done
|
|
149
|
+
[ -n "$root" ] && PLAN_NEXT_ROOT="$root"
|
|
150
|
+
root="$(_pn_root)"
|
|
151
|
+
|
|
152
|
+
# --llm needs jq for valid TOON/JSON — emit a structured error rather than malformed output.
|
|
153
|
+
if [ "$out" = "json" ] && ! command -v jq >/dev/null 2>&1; then
|
|
154
|
+
printf '{"error":"plan-next: jq is required for --llm output"}\n'; return 1
|
|
155
|
+
fi
|
|
156
|
+
|
|
157
|
+
local skills verbs rules docs cs cv cr cd total
|
|
158
|
+
skills="$(plan_next_skills "$root")"; cs="$(printf '%s' "$skills" | grep -c .)"
|
|
159
|
+
verbs="$(plan_next_verbs "$root")"; cv="$(printf '%s' "$verbs" | grep -c .)"
|
|
160
|
+
rules="$(plan_next_rules "$root")"; cr="$(printf '%s' "$rules" | grep -c .)"
|
|
161
|
+
docs="$(plan_next_docs "$root")"; cd="$(printf '%s' "$docs" | grep -c .)"
|
|
162
|
+
total=$((cs + cv + cr + cd))
|
|
163
|
+
|
|
164
|
+
local proposals; proposals="$(_pn_proposals "$root")"
|
|
165
|
+
|
|
166
|
+
if [ "$out" = "json" ]; then
|
|
167
|
+
# TOON rows {rank,area,proposal,next}. Always >=1 row (the mandatory docs item), so the plan is
|
|
168
|
+
# never empty; the explicit empty state is the capability inventory being bare (total==0), which
|
|
169
|
+
# the human view surfaces and the rule documents. The 'next' field carries the next-step handoff.
|
|
170
|
+
local here json; here="$(dirname "${BASH_SOURCE[0]}")"
|
|
171
|
+
json="$(printf '%s\n' "$proposals" \
|
|
172
|
+
| jq -R -s '[ split("\n")[] | select(length>0) | split("\t")
|
|
173
|
+
| {rank:(.[0]|tonumber), area:.[1], proposal:.[2], next:.[3]} ]')"
|
|
174
|
+
# shellcheck source=/dev/null
|
|
175
|
+
. "$here/toon.sh"
|
|
176
|
+
printf '%s' "$json" | toon_encode
|
|
177
|
+
return 0
|
|
178
|
+
fi
|
|
179
|
+
|
|
180
|
+
# human: current capabilities + the proposed plan, through the rendering seam (#82). Leads with
|
|
181
|
+
# human-meaningful names; no `--llm` decoration in the prose (house presentation rule).
|
|
182
|
+
local here; here="$(dirname "${BASH_SOURCE[0]}")"
|
|
183
|
+
# shellcheck source=/dev/null
|
|
184
|
+
. "$here/render.sh" 2>/dev/null || true
|
|
185
|
+
local name; name="$(basename "$root")"
|
|
186
|
+
_pn_human() {
|
|
187
|
+
printf '# Plan next — %s\n\n' "$name"
|
|
188
|
+
if [ "$total" -eq 0 ]; then
|
|
189
|
+
printf '> No kit capabilities found here — this looks like a host project with no skills, verbs,\n'
|
|
190
|
+
printf '> rules, or docs yet. The plan below still carries the mandatory docs + README step; run\n'
|
|
191
|
+
printf '> from the cckit repo (or scaffold with `cckit init`) for a full forward plan.\n\n'
|
|
192
|
+
fi
|
|
193
|
+
printf '## Current capabilities\n\n'
|
|
194
|
+
printf '| area | count | sample |\n| --- | --- | --- |\n'
|
|
195
|
+
printf '| skills | %s | %s |\n' "$cs" "$(printf '%s' "$skills" | head -3 | tr '\n' ' ' | sed 's/ $//')"
|
|
196
|
+
printf '| commands | %s | %s |\n' "$cv" "$(printf '%s' "$verbs" | head -3 | tr '\n' ' ' | sed 's/ $//')"
|
|
197
|
+
printf '| rules | %s | %s |\n' "$cr" "$(printf '%s' "$rules" | head -3 | tr '\n' ' ' | sed 's/ $//')"
|
|
198
|
+
printf '| docs | %s | %s |\n' "$cd" "$(printf '%s' "$docs" | head -3 | tr '\n' ' ' | sed 's/ $//')"
|
|
199
|
+
printf '\n## Proposed next — grounded in the above\n\n'
|
|
200
|
+
printf '| rank | area | proposal |\n| --- | --- | --- |\n'
|
|
201
|
+
printf '%s\n' "$proposals" | awk -F'\t' 'NF>=3 { printf "| %s | %s | %s |\n", $1, $2, $3 }'
|
|
202
|
+
printf '\n## Next step\n\n'
|
|
203
|
+
printf 'Pick an item and scope it into an effort with `/kit-plan-next` (conversational), or directly:\n\n'
|
|
204
|
+
printf '```\n/kit-effort-new\n```\n\n'
|
|
205
|
+
printf '> This plan is human / orchestrator-facing only — never paste it into a monitored agent'\''s\n'
|
|
206
|
+
printf '> context (context-anxiety rule). See rules/plan-next.md.\n'
|
|
207
|
+
}
|
|
208
|
+
if command -v cckit_render >/dev/null 2>&1; then _pn_human | cckit_render; else _pn_human; fi
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
# _pn_err — structured error for --llm mode (mirrors the other verbs' failure shape).
|
|
212
|
+
_pn_err() { printf '{"error":"plan-next: %s"}\n' "$1"; }
|