@jeiemgi/cckit 0.6.1 → 0.7.1
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 +86 -5
- package/bin/cckit +72 -3
- package/cckit.config.json +6 -1
- 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/init.sh +31 -1
- 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 +1 -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 +1 -0
- package/scripts/lib/kit-task-ops.sh +1 -0
- 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/portable-test.sh +13 -2
- package/scripts/self-install-test.sh +282 -0
- package/scripts/setup-labels.sh +1 -0
- package/scripts/status.sh +25 -10
- 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/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/skills/concrete/SKILL.md +117 -0
- package/templates/skills/karpathy-guidelines/SKILL.md +1 -0
|
@@ -0,0 +1,376 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# shellcheck shell=bash
|
|
3
|
+
# kit-brief.sh — generate an issue's delegation brief from real repo state (Effort 220 · #221).
|
|
4
|
+
# errors: mixed — the parsers are pure; kit_brief propagates a gh failure
|
|
5
|
+
#
|
|
6
|
+
# A hand-written delegation brief drops whatever its author forgot, and what gets forgotten is the
|
|
7
|
+
# part the agent then rediscovers by hand — the worktree it should work in, the base tip that says
|
|
8
|
+
# whether its seed is stale, the helper that already does the thing it is about to reimplement.
|
|
9
|
+
# This verb reads all of that out of the repo instead: `gh` for the issue, `git worktree list` for
|
|
10
|
+
# the isolation, `origin/<base>` for the seed, `kit_lib_rows` (#222) for the helpers, and the
|
|
11
|
+
# project's own delegation-brief rule for the standing gotchas + the durable-prose (`concrete`)
|
|
12
|
+
# mandate. Nothing here is remembered.
|
|
13
|
+
#
|
|
14
|
+
# Source it: source scripts/lib/kit-brief.sh
|
|
15
|
+
# Depends on: kit-lib.sh (the helper catalog), and for the verb body: gh, git, the project config.
|
|
16
|
+
|
|
17
|
+
# ── pure parsers (no gh, no git; every one is unit-tested against fixture text) ─────────────────
|
|
18
|
+
|
|
19
|
+
# _kb_rtrim — drop leading AND trailing blank lines from stdin, so a section lifted out of a
|
|
20
|
+
# markdown body drops straight into the brief without a stray gap. awk, not the sed label idiom,
|
|
21
|
+
# because BSD sed (macOS) and GNU sed disagree about `{$d;N;ba}` inside -e fragments.
|
|
22
|
+
_kb_rtrim() {
|
|
23
|
+
awk '{ a[NR] = $0 }
|
|
24
|
+
END {
|
|
25
|
+
first = 0; last = 0
|
|
26
|
+
for (i = 1; i <= NR; i++) if (a[i] !~ /^[[:space:]]*$/) { if (!first) first = i; last = i }
|
|
27
|
+
for (i = first; i <= last; i++) print a[i]
|
|
28
|
+
}'
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
# kit_brief_section <heading> — stdin is an issue body; echo the lines under `## <heading>` up to
|
|
32
|
+
# the next `## ` heading (the heading line itself excluded), trailing blanks trimmed. Empty output
|
|
33
|
+
# means the section is absent, which is a fact the brief reports rather than papering over.
|
|
34
|
+
kit_brief_section() {
|
|
35
|
+
local want="$1"
|
|
36
|
+
awk -v want="$want" '
|
|
37
|
+
/^##[[:space:]]/ {
|
|
38
|
+
line = $0; sub(/^##[[:space:]]*/, "", line)
|
|
39
|
+
# compare case-insensitively without gawk-only tolower() on both sides being a problem
|
|
40
|
+
in_s = (tolower(line) == tolower(want)) ? 1 : 0
|
|
41
|
+
next
|
|
42
|
+
}
|
|
43
|
+
in_s { print }
|
|
44
|
+
' | _kb_rtrim
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
# kit_brief_files — stdin is any issue text; echo one repo-relative path per line, sorted, unique.
|
|
48
|
+
# Recognises both shapes the kit's own issues use: an `## For agents` prose section that names
|
|
49
|
+
# paths, and the `Files: a, b, c` line `cckit effort new` writes into a sub-issue. A token counts
|
|
50
|
+
# as a path when it has a known source/doc extension, ends in `/` (a directory the issue owns), or
|
|
51
|
+
# is a slash-bearing extensionless token — `bin/cckit`, the kit's own entry point, has no extension.
|
|
52
|
+
# Being permissive here is safe because the verb resolves every token against the repo and drops an
|
|
53
|
+
# extensionless one that does not exist, so prose like `and/or` never reaches the brief.
|
|
54
|
+
# Surrounding backticks, quotes and trailing sentence punctuation are stripped. Pure.
|
|
55
|
+
kit_brief_files() {
|
|
56
|
+
tr -s ' \t,;()<>"' '\n' \
|
|
57
|
+
| sed -e 's/^`*//' -e 's/`*$//' -e "s/^'*//" -e "s/'*$//" -e 's/[.:]*$//' \
|
|
58
|
+
| grep -E '^[A-Za-z0-9_][A-Za-z0-9_./-]*(\.(sh|md|mdx|json|jsonc|ya?ml|ts|tsx|js|jsx|css|html|bash|zsh)|/|/[A-Za-z0-9_-]+)$' \
|
|
59
|
+
| grep -v '^https\?:' \
|
|
60
|
+
| sort -u
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
# kit_brief_sourced <file>… — echo the helper basenames those files actually `source`, sorted and
|
|
64
|
+
# unique. Basenames, not paths, because the kit's own source lines go through a variable
|
|
65
|
+
# (`source "$LIB/kit-config.sh"`) — matching a literal `lib/` prefix would find none of them. Derived from the source lines in the files themselves, so the brief names the helpers the
|
|
66
|
+
# work genuinely sits on top of rather than guessing from a filename. Missing files are skipped.
|
|
67
|
+
kit_brief_sourced() {
|
|
68
|
+
local f
|
|
69
|
+
for f in "$@"; do
|
|
70
|
+
[ -f "$f" ] || continue
|
|
71
|
+
# Two anchored greps, not one sed: BSD sed (macOS) has no `\|` alternation in a basic regex, so
|
|
72
|
+
# the single-expression form silently matched nothing there. Anchoring `source` / `.` to the
|
|
73
|
+
# line start also keeps a prose line that merely mentions a helper out of the result.
|
|
74
|
+
grep -E '^[[:space:]]*(source|\.)[[:space:]]' "$f" 2>/dev/null \
|
|
75
|
+
| grep -Eo '[A-Za-z0-9_.-]+\.sh'
|
|
76
|
+
done | sort -u
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
# kit_brief_rule_section <heading-regex> [root] — echo one `## ` block of the project's own
|
|
80
|
+
# delegation-brief rule (`.claude/rules/delegation-brief.md`), falling back to the kit's template.
|
|
81
|
+
# The blocks are transferable instruction the project already maintains; re-typing them into a
|
|
82
|
+
# brief is how they go stale. <heading-regex> is an ERE matched against the whole heading line, so
|
|
83
|
+
# it must tolerate the heading's own suffixes ("Standing gotchas (transferable — …)"). Echoes
|
|
84
|
+
# nothing when no rule file exists — the caller says so.
|
|
85
|
+
# The FIRST file that exists wins for every section, so a project that owns the rule owns all of it.
|
|
86
|
+
kit_brief_rule_section() {
|
|
87
|
+
local want="$1" root="${2:-.}" f
|
|
88
|
+
for f in "$root/.claude/rules/delegation-brief.md" \
|
|
89
|
+
"$root/templates/rules/delegation-brief.md" \
|
|
90
|
+
"${CCKIT_ROOT:-$root}/templates/rules/delegation-brief.md"; do
|
|
91
|
+
[ -f "$f" ] || continue
|
|
92
|
+
awk -v want="$want" '
|
|
93
|
+
/^##[[:space:]]/ { in_s = ($0 ~ want) ? 1 : 0; next }
|
|
94
|
+
in_s { print }
|
|
95
|
+
' "$f" | _kb_rtrim
|
|
96
|
+
return 0
|
|
97
|
+
done
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
# kit_brief_gotchas [root] — the "Standing gotchas" block. Thin caller of kit_brief_rule_section.
|
|
101
|
+
kit_brief_gotchas() { kit_brief_rule_section '[Ss]tanding gotchas' "${1:-.}"; }
|
|
102
|
+
|
|
103
|
+
# kit_brief_durable_prose [root] — the "Durable prose" block: the instruction that an agent about to
|
|
104
|
+
# write a durable artifact (issue body, PR body, commit message, rule, ADR, knowledge doc) applies
|
|
105
|
+
# the `concrete` catalogue first. It is in the GENERATED brief, not only in the rule, because a
|
|
106
|
+
# sub-agent applies a skill only when it is told to — an installed skill no brief mentions does not
|
|
107
|
+
# fire (that is why `concrete` shipped in PR 247 and no body records a pass; see #283).
|
|
108
|
+
kit_brief_durable_prose() { kit_brief_rule_section '[Dd]urable prose' "${1:-.}"; }
|
|
109
|
+
|
|
110
|
+
# ── real-state lookups ─────────────────────────────────────────────────────────────────────────
|
|
111
|
+
|
|
112
|
+
# kit_brief_worktree <issue> — echo "<path>\t<branch>" for the worktree that belongs to this issue,
|
|
113
|
+
# or nothing. The association is DERIVED from the branch name via wt_issue_number (worktree-issue.sh),
|
|
114
|
+
# the same rule gc uses to decide what is protected, so the brief and gc can never disagree about
|
|
115
|
+
# which worktree an issue owns. best-effort: no git, no output.
|
|
116
|
+
kit_brief_worktree() {
|
|
117
|
+
local want="$1" wtpath ref b n
|
|
118
|
+
command -v git >/dev/null 2>&1 || return 0
|
|
119
|
+
command -v wt_issue_number >/dev/null 2>&1 || return 0
|
|
120
|
+
git worktree list --porcelain 2>/dev/null \
|
|
121
|
+
| awk '/^worktree /{w=$2} /^branch /{print w"\t"$2}' \
|
|
122
|
+
| while IFS="$(printf '\t')" read -r wtpath ref; do
|
|
123
|
+
b="${ref#refs/heads/}"
|
|
124
|
+
n="$(wt_issue_number "$b")"
|
|
125
|
+
[ "$n" = "$want" ] || continue
|
|
126
|
+
printf '%s\t%s\n' "$wtpath" "$b"
|
|
127
|
+
done | head -1
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
# kit_brief_resolve <token> — echo the repo path a token refers to, plus a tab and a status word:
|
|
131
|
+
# `here` (the path exists), `new` (it does not), or `ambiguous` (a bare basename matching several
|
|
132
|
+
# tracked files — the brief prints the count instead of picking one). A bare basename is resolved
|
|
133
|
+
# against `git ls-files` so a token lifted from prose ("captain-test.sh") is not reported as a new
|
|
134
|
+
# file when it plainly exists under scripts/lib. best-effort: without git only literal paths resolve.
|
|
135
|
+
kit_brief_resolve() {
|
|
136
|
+
local tok="$1" root="${2:-.}" hits n
|
|
137
|
+
case "$tok" in
|
|
138
|
+
*/*) if [ -e "$root/$tok" ]; then printf '%s\there' "$tok"; else printf '%s\tnew' "$tok"; fi; return 0 ;;
|
|
139
|
+
esac
|
|
140
|
+
if [ -e "$root/$tok" ]; then printf '%s\there' "$tok"; return 0; fi
|
|
141
|
+
command -v git >/dev/null 2>&1 || { printf '%s\tnew' "$tok"; return 0; }
|
|
142
|
+
hits="$(git -C "$root" ls-files 2>/dev/null | grep -E "(^|/)$(printf '%s' "$tok" | sed 's/[.[\*^$]/\\&/g')$" | head -5)"
|
|
143
|
+
n="$(printf '%s' "$hits" | grep -c . || true)"
|
|
144
|
+
case "$n" in
|
|
145
|
+
0) printf '%s\tnew' "$tok" ;;
|
|
146
|
+
1) printf '%s\there' "$hits" ;;
|
|
147
|
+
*) printf '%s\tambiguous %s' "$tok" "$n" ;;
|
|
148
|
+
esac
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
# kit_brief_seed <branch> <base> — echo "fresh <tip>" when origin/<base> is already an ancestor of
|
|
152
|
+
# <branch>, "stale <tip>" when it is not (the branch was seeded from an older commit and needs a
|
|
153
|
+
# rebase before anyone trusts a green check on it), or "unknown" when either ref is missing. This
|
|
154
|
+
# is the check a hand-written brief always omits and the one that silently wastes a whole session.
|
|
155
|
+
kit_brief_seed() {
|
|
156
|
+
local branch="$1" base="$2" tip
|
|
157
|
+
command -v git >/dev/null 2>&1 || { printf '%s' "unknown"; return 0; }
|
|
158
|
+
tip="$(git rev-parse --short "origin/$base" 2>/dev/null)" || tip=""
|
|
159
|
+
[ -n "$tip" ] || { printf '%s' "unknown"; return 0; }
|
|
160
|
+
git rev-parse --verify --quiet "refs/heads/$branch" >/dev/null 2>&1 \
|
|
161
|
+
|| { printf '%s' "unknown"; return 0; }
|
|
162
|
+
if git merge-base --is-ancestor "origin/$base" "$branch" 2>/dev/null; then
|
|
163
|
+
printf 'fresh %s' "$tip"
|
|
164
|
+
else
|
|
165
|
+
printf 'stale %s' "$tip"
|
|
166
|
+
fi
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
# _kb_rows <libdir> <names> — the catalog rows for a newline-separated set of helper basenames, in
|
|
170
|
+
# catalog order. One implementation for both halves of the helpers table.
|
|
171
|
+
_kb_rows() {
|
|
172
|
+
local libdir="$1" want="$2" row _e _fn _p
|
|
173
|
+
[ -n "$want" ] || return 0
|
|
174
|
+
kit_lib_rows "$libdir" | while IFS="$(printf '\t')" read -r row _e _fn _p; do
|
|
175
|
+
printf '%s\n' "$want" | grep -qxF "$row" || continue
|
|
176
|
+
printf '| `%s` | %s | %s |\n' "$row" "$_e" "$_p"
|
|
177
|
+
done
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
# ── the verb ───────────────────────────────────────────────────────────────────────────────────
|
|
181
|
+
|
|
182
|
+
# kit_brief <issue> — print the delegation brief for an issue as markdown. strict about its one
|
|
183
|
+
# hard dependency: a gh failure (no auth, no such issue) propagates rather than yielding a brief
|
|
184
|
+
# with an empty issue in it. Every other section degrades to an explicit "not found" line, because
|
|
185
|
+
# a brief that silently omits a section is the failure mode this verb exists to remove.
|
|
186
|
+
kit_brief() {
|
|
187
|
+
local n="${1:-}" root base repo body title state labels foragents files files_from wt wtpath wtbranch
|
|
188
|
+
local seed gotchas prose libdir row f gate
|
|
189
|
+
case "$n" in
|
|
190
|
+
''|--*) echo "usage: cckit brief <issue>" >&2; return 2 ;;
|
|
191
|
+
esac
|
|
192
|
+
n="${n#\#}"
|
|
193
|
+
command -v gh >/dev/null 2>&1 || { echo "cckit brief: gh is required" >&2; return 1; }
|
|
194
|
+
command -v jq >/dev/null 2>&1 || { echo "cckit brief: jq is required" >&2; return 1; }
|
|
195
|
+
|
|
196
|
+
root="$(git rev-parse --show-toplevel 2>/dev/null || pwd)"
|
|
197
|
+
base="${KIT_BASE_BRANCH:-main}"
|
|
198
|
+
repo="${KIT_REPO:-}"
|
|
199
|
+
|
|
200
|
+
# The one strict dependency. Fetch title/state/labels/body in a single call.
|
|
201
|
+
local issue_json
|
|
202
|
+
if [ -n "$repo" ]; then
|
|
203
|
+
issue_json="$(gh issue view "$n" --repo "$repo" --json title,state,labels,body 2>&1)" || {
|
|
204
|
+
printf 'cckit brief: could not read issue #%s from %s\n%s\n' "$n" "$repo" "$issue_json" >&2
|
|
205
|
+
return 1
|
|
206
|
+
}
|
|
207
|
+
else
|
|
208
|
+
issue_json="$(gh issue view "$n" --json title,state,labels,body 2>&1)" || {
|
|
209
|
+
printf 'cckit brief: could not read issue #%s\n%s\n' "$n" "$issue_json" >&2
|
|
210
|
+
return 1
|
|
211
|
+
}
|
|
212
|
+
fi
|
|
213
|
+
title="$(printf '%s' "$issue_json" | jq -r '.title // ""')"
|
|
214
|
+
state="$(printf '%s' "$issue_json" | jq -r '.state // ""' | tr 'A-Z' 'a-z')"
|
|
215
|
+
labels="$(printf '%s' "$issue_json" | jq -r '[.labels[]?.name] | join(" · ")')"
|
|
216
|
+
body="$(printf '%s' "$issue_json" | jq -r '.body // ""')"
|
|
217
|
+
|
|
218
|
+
foragents="$(printf '%s\n' "$body" | kit_brief_section "For agents")"
|
|
219
|
+
# Paths come from the `## For agents` section when the issue has one; otherwise from the whole
|
|
220
|
+
# body (a sub-issue carries a `Files:` line instead). The brief states which, so a thin file list
|
|
221
|
+
# is legible as "the issue said little", not as "the verb missed something".
|
|
222
|
+
files=""; files_from="body"
|
|
223
|
+
if [ -n "$foragents" ]; then
|
|
224
|
+
files="$(printf '%s\n' "$foragents" | kit_brief_files)"
|
|
225
|
+
[ -n "$files" ] && files_from="for-agents"
|
|
226
|
+
fi
|
|
227
|
+
# A `## For agents` section that names no paths is common (it often carries build ORDER, not
|
|
228
|
+
# files). Fall back to the whole issue rather than reporting "no paths" when the issue clearly
|
|
229
|
+
# lists some elsewhere — and say which source the list came from either way.
|
|
230
|
+
[ -n "$files" ] || files="$(printf '%s\n' "$body" | kit_brief_files)"
|
|
231
|
+
[ -n "$files" ] || files_from="none"
|
|
232
|
+
|
|
233
|
+
echo "# Delegation brief — #$n"
|
|
234
|
+
echo
|
|
235
|
+
printf '**%s**\n' "${title:-(untitled)}"
|
|
236
|
+
printf '\n- issue: `#%s` · %s%s\n' "$n" "${state:-unknown}" "${labels:+ · $labels}"
|
|
237
|
+
[ -n "$repo" ] && printf -- '- repo: `%s` · base branch `%s`\n' "$repo" "$base"
|
|
238
|
+
|
|
239
|
+
# ── where the work happens
|
|
240
|
+
wt="$(kit_brief_worktree "$n")"
|
|
241
|
+
wtpath="${wt%% *}"; wtbranch="${wt##* }"
|
|
242
|
+
if [ -n "$wt" ]; then
|
|
243
|
+
printf -- '- worktree: `%s`\n- branch: `%s`\n' "$wtpath" "$wtbranch"
|
|
244
|
+
seed="$(kit_brief_seed "$wtbranch" "$base")"
|
|
245
|
+
case "$seed" in
|
|
246
|
+
fresh*) printf -- '- seed: **fresh** — `origin/%s` (%s) is already in this branch\n' "$base" "${seed#fresh }" ;;
|
|
247
|
+
stale*) printf -- '- seed: **STALE** — `origin/%s` (%s) is NOT in this branch; rebase before trusting a green check\n' "$base" "${seed#stale }" ;;
|
|
248
|
+
*) printf -- '- seed: unknown — could not compare against `origin/%s`\n' "$base" ;;
|
|
249
|
+
esac
|
|
250
|
+
else
|
|
251
|
+
printf -- '- worktree: none yet — run `cckit start %s` first; never work in the shared checkout\n' "$n"
|
|
252
|
+
fi
|
|
253
|
+
gate="$([ -f "$root/scripts/check.sh" ] && echo 'bash scripts/check.sh' || echo 'the project gate (no scripts/check.sh found)')"
|
|
254
|
+
printf -- '- gate: `%s` must pass before the PR\n' "$gate"
|
|
255
|
+
|
|
256
|
+
# ── the files this issue owns
|
|
257
|
+
echo
|
|
258
|
+
echo "## Files this issue owns"
|
|
259
|
+
echo
|
|
260
|
+
if [ -n "$files" ]; then
|
|
261
|
+
case "$files_from" in
|
|
262
|
+
for-agents) echo "_From the issue's \`## For agents\` section._" ;;
|
|
263
|
+
*) if [ -n "$foragents" ]; then
|
|
264
|
+
echo "_The issue's \`## For agents\` section names no paths — these are every path named elsewhere in the issue._"
|
|
265
|
+
else
|
|
266
|
+
echo "_No \`## For agents\` section — these are every path named anywhere in the issue._"
|
|
267
|
+
fi ;;
|
|
268
|
+
esac
|
|
269
|
+
echo
|
|
270
|
+
# Resolve first, THEN dedupe: two tokens in one issue ("pr-evidence.sh" in prose and
|
|
271
|
+
# "scripts/lib/pr-evidence.sh" in a Files: line) resolve to one path and must print once.
|
|
272
|
+
local resolved_rows
|
|
273
|
+
resolved_rows="$(while IFS= read -r f; do
|
|
274
|
+
[ -n "$f" ] || continue
|
|
275
|
+
kit_brief_resolve "$f" "$root"
|
|
276
|
+
printf '\n'
|
|
277
|
+
done <<EOF
|
|
278
|
+
$files
|
|
279
|
+
EOF
|
|
280
|
+
)"
|
|
281
|
+
printf '%s\n' "$resolved_rows" | grep . | awk -F'\t' '!seen[$1]++' \
|
|
282
|
+
| while IFS="$(printf '\t')" read -r rpath rstate; do
|
|
283
|
+
# An extensionless token that resolves to nothing is prose ("and/or"), not a file the
|
|
284
|
+
# issue owns — the parser is permissive so `bin/cckit` survives; this is where the
|
|
285
|
+
# false positives go.
|
|
286
|
+
case "${rpath##*/}" in
|
|
287
|
+
*.*) : ;;
|
|
288
|
+
*) [ "$rstate" = "new" ] && continue ;;
|
|
289
|
+
esac
|
|
290
|
+
case "$rstate" in
|
|
291
|
+
here) printf -- '- `%s`\n' "$rpath" ;;
|
|
292
|
+
new) printf -- '- `%s` — does not exist yet (new file)\n' "$rpath" ;;
|
|
293
|
+
*) printf -- '- `%s` — %s tracked files match this name; confirm which one\n' "$rpath" "${rstate#ambiguous }" ;;
|
|
294
|
+
esac
|
|
295
|
+
done
|
|
296
|
+
else
|
|
297
|
+
echo "_The issue names no paths. Ask for them before starting; do not guess._"
|
|
298
|
+
fi
|
|
299
|
+
|
|
300
|
+
# ── the helpers that work sits on
|
|
301
|
+
echo
|
|
302
|
+
echo "## Helpers you already have"
|
|
303
|
+
echo
|
|
304
|
+
libdir="$(command -v kit_lib_dir >/dev/null 2>&1 && kit_lib_dir "$root" || echo "$root/scripts/lib")"
|
|
305
|
+
if [ -d "$libdir" ] && command -v kit_lib_rows >/dev/null 2>&1; then
|
|
306
|
+
# Two derived sources: helpers the issue OWNS, and helpers its existing files actually source.
|
|
307
|
+
local owned_libs sourced_libs want_libs table
|
|
308
|
+
owned_libs="$(printf '%s\n' "$files" | sed -n 's#.*/\([A-Za-z0-9_.-]*\.sh\)$#\1#p')"
|
|
309
|
+
# `if`, not `[ -f … ] &&`: a while loop's rc is its LAST iteration's, so a trailing non-file
|
|
310
|
+
# token (`templates/skills/` — the parser keeps directory tokens) made this assignment rc 1 and
|
|
311
|
+
# `bin/cckit`'s `set -eu` killed the brief right here. Every section below — the helpers table,
|
|
312
|
+
# the standing gotchas, the durable-prose mandate — was silently missing from every generated
|
|
313
|
+
# brief. An `if` with no else always returns 0, so the loop's rc no longer depends on the input.
|
|
314
|
+
sourced_libs="$(while IFS= read -r f; do
|
|
315
|
+
[ -n "$f" ] || continue
|
|
316
|
+
if [ -f "$root/$f" ]; then kit_brief_sourced "$root/$f" || true; fi
|
|
317
|
+
done <<EOF
|
|
318
|
+
$files
|
|
319
|
+
EOF
|
|
320
|
+
)"
|
|
321
|
+
# OWNED helpers first (the ones this issue edits), then the ones its files merely source, and
|
|
322
|
+
# only up to a cap: an issue that owns `bin/cckit` sources every helper in the kit, and a
|
|
323
|
+
# 40-row table is not a brief. The overflow is counted, never silently dropped.
|
|
324
|
+
local sourced_only cap shown_owned shown_src n_src n_over
|
|
325
|
+
sourced_only="$(printf '%s\n' "$sourced_libs" | grep . | sort -u \
|
|
326
|
+
| { if [ -n "$owned_libs" ]; then grep -vxF -f <(printf '%s\n' "$owned_libs" | grep .) || true; else cat; fi; })"
|
|
327
|
+
cap="${KIT_BRIEF_MAX_HELPERS:-10}"
|
|
328
|
+
shown_owned="$(_kb_rows "$libdir" "$(printf '%s\n' "$owned_libs" | grep . | sort -u)")"
|
|
329
|
+
n_src="$(printf '%s' "$shown_owned" | grep -c . || true)"
|
|
330
|
+
shown_src="$(_kb_rows "$libdir" "$sourced_only" | head -n "$((cap > n_src ? cap - n_src : 0))")"
|
|
331
|
+
# `|| true`, never `|| echo 0`: `grep -c` on empty input already PRINTS 0 and exits 1, so the
|
|
332
|
+
# `echo 0` fallback appends a SECOND zero and the arithmetic below sees "0\n0". Same bug class
|
|
333
|
+
# as the #142 board-counter regression.
|
|
334
|
+
local n_all n_shown
|
|
335
|
+
n_all="$(_kb_rows "$libdir" "$sourced_only" | grep -c . || true)"
|
|
336
|
+
n_shown="$(printf '%s' "$shown_src" | grep -c . || true)"
|
|
337
|
+
n_over="$(( ${n_all:-0} - ${n_shown:-0} ))"
|
|
338
|
+
if [ -n "$shown_owned$shown_src" ]; then
|
|
339
|
+
echo "| helper | errors | purpose |"
|
|
340
|
+
echo "| --- | --- | --- |"
|
|
341
|
+
printf '%s\n' "$shown_owned" | grep . || true
|
|
342
|
+
printf '%s\n' "$shown_src" | grep . || true
|
|
343
|
+
[ "$n_over" -gt 0 ] && printf -- '\n_+%s more helper(s) these files source — `cckit lib` lists them._\n' "$n_over"
|
|
344
|
+
else
|
|
345
|
+
echo "_None of the issue's files are helpers or source one._"
|
|
346
|
+
fi
|
|
347
|
+
echo
|
|
348
|
+
printf -- '_Full catalog: `cckit lib` (%s helpers). Do not reimplement what it already lists._\n' \
|
|
349
|
+
"$(kit_lib_files "$libdir" | grep -c . || true)"
|
|
350
|
+
else
|
|
351
|
+
echo "_No helper catalog here — `cckit lib` is unavailable in this project._"
|
|
352
|
+
fi
|
|
353
|
+
|
|
354
|
+
# ── standing gotchas, from the project's own rule
|
|
355
|
+
echo
|
|
356
|
+
echo "## Standing gotchas"
|
|
357
|
+
echo
|
|
358
|
+
gotchas="$(kit_brief_gotchas "$root")"
|
|
359
|
+
if [ -n "$gotchas" ]; then
|
|
360
|
+
printf '%s\n' "$gotchas"
|
|
361
|
+
else
|
|
362
|
+
echo "_No \`delegation-brief.md\` rule found — add one so this section stops being empty._"
|
|
363
|
+
fi
|
|
364
|
+
|
|
365
|
+
# ── durable prose, from the same rule. An agent applies a skill only when it is told to, so the
|
|
366
|
+
# concrete mandate has to reach the brief; stating it in communication-style.md alone never fired.
|
|
367
|
+
echo
|
|
368
|
+
echo "## Durable prose"
|
|
369
|
+
echo
|
|
370
|
+
prose="$(kit_brief_durable_prose "$root")"
|
|
371
|
+
if [ -n "$prose" ]; then
|
|
372
|
+
printf '%s\n' "$prose"
|
|
373
|
+
else
|
|
374
|
+
echo "_No \`Durable prose\` section in \`delegation-brief.md\` — add one so an agent writing an issue body, a PR body or a commit message is told to run the \`concrete\` pass first._"
|
|
375
|
+
fi
|
|
376
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env bash
|
|
2
2
|
# kit-cli-test.sh — self-test for kit-cli (#383). Runs under bash AND zsh.
|
|
3
3
|
# Run: bash scripts/lib/kit-cli-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_CLI_TEST_INNER:-}" ]; then
|
package/scripts/lib/kit-cli.sh
CHANGED
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
# verified for execute-vs-source in both. MUST be called from the consumer's
|
|
15
15
|
# top level (so the bash frame BASH_SOURCE[1] is the consumer itself).
|
|
16
16
|
# kit_say / kit_warn / kit_die stderr output helpers (stdout stays clean for pipeable data).
|
|
17
|
+
# errors: pure — zero-dep shell helpers
|
|
17
18
|
|
|
18
19
|
# True (rc 0) iff the script that sourced this lib is the one being executed directly.
|
|
19
20
|
# zsh: inside a function, ZSH_EVAL_CONTEXT is "toplevel:shfunc" when the caller was executed
|
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
# Source it: source scripts/lib/kit-config-resolve.sh
|
|
23
23
|
# CLI: scripts/lib/kit-config-resolve.sh [--dir DIR] [--explain JQPATH] [--layers] [--get JQPATH]
|
|
24
24
|
# Requires: jq.
|
|
25
|
+
# errors: strict — refuses to resolve a cascade without jq
|
|
25
26
|
|
|
26
27
|
KIT_CONFIG_NAMES="${KIT_CONFIG_NAMES:-kit.workspace.json kit.config.json}"
|
|
27
28
|
KIT_MERGE_MODE="${KIT_MERGE_MODE:-replace}" # replace | concat (see header)
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
# integration-branch fallback chain (#117) — a host project that names its integration branch under
|
|
5
5
|
# an alternate key (integrationBranch / flow) must still resolve, not silently fall back to "main".
|
|
6
6
|
# Hermetic: throwaway config files pointed at via KIT_CONFIG. Run: bash scripts/lib/kit-config-test.sh
|
|
7
|
+
# errors: strict — a test runner: rc 1 on any failed assertion
|
|
7
8
|
set -u
|
|
8
9
|
ROOT="$(cd "$(dirname "$0")/../.." && pwd)"
|
|
9
10
|
LIB="$ROOT/scripts/lib"
|
|
@@ -33,5 +34,18 @@ t "flow fallback" \
|
|
|
33
34
|
t "default main when unset" \
|
|
34
35
|
"$(base_branch_for '{"github":{}}')" "main"
|
|
35
36
|
|
|
37
|
+
# ── #244 · effort.wipLimit is exported as KIT_EFFORT_WIP_LIMIT ────────────────────────────────
|
|
38
|
+
# The effort WIP gate reads this env var when EFFORT_WIP_LIMIT is unset. An UNSET key must export
|
|
39
|
+
# an EMPTY string (not the literal "null"), because effort-ops treats non-empty as "configured" and
|
|
40
|
+
# would otherwise reject "null" as a bad value on every repo that never set the key.
|
|
41
|
+
wip_for() {
|
|
42
|
+
local json="$1" d; d="$(mktemp -d "$tmp/wip.XXXXXX")"
|
|
43
|
+
printf '%s' "$json" > "$d/cckit.config.json"
|
|
44
|
+
KIT_CONFIG="$d/cckit.config.json" bash -c "source '$LIB/kit-config.sh'; load_kit_config >/dev/null 2>&1; printf '%s' \"\$KIT_EFFORT_WIP_LIMIT\""
|
|
45
|
+
}
|
|
46
|
+
t "effort.wipLimit is exported" "$(wip_for '{"github":{},"effort":{"wipLimit":3}}')" "3"
|
|
47
|
+
t "effort.wipLimit 0 survives export" "$(wip_for '{"github":{},"effort":{"wipLimit":0}}')" "0"
|
|
48
|
+
t "unset effort.wipLimit exports ''" "$(wip_for '{"github":{}}')" ""
|
|
49
|
+
|
|
36
50
|
[ "$fail" -eq 0 ] && echo "ALL OK (kit-config)" || echo "kit-config: FAILURES"
|
|
37
51
|
exit "$fail"
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
#
|
|
6
6
|
# Per-folder overrides: any .claudekit/config.json in an ancestor directory is deep-merged over the
|
|
7
7
|
# project config, nearest-wins (like .editorconfig). Projects with no .claudekit/ behave unchanged.
|
|
8
|
+
# errors: strict — refuses to load config without jq
|
|
8
9
|
|
|
9
10
|
# Source the ONE shared config-path resolver (config-path.sh, #69). Self-locate portably: BASH_SOURCE
|
|
10
11
|
# is bash-only (empty under zsh, where dirname "" -> CWD and the lib is sought in the wrong dir), so
|
|
@@ -80,6 +81,11 @@ load_kit_config() {
|
|
|
80
81
|
# from the project config (#150). Empty when unconfigured (effort.sh keeps its built-in default).
|
|
81
82
|
export KIT_EFFORT_FLOWS="$(jq -r '[.effort.flows[]? | tostring] | join(" ")' "$cfg")"
|
|
82
83
|
|
|
84
|
+
# Concurrent-effort WIP limit (effort.wipLimit) — how many efforts may be in progress at once
|
|
85
|
+
# before `cckit effort start` refuses (#244). Empty when unconfigured; effort-ops.sh then falls
|
|
86
|
+
# back to its built-in default of 2. An EFFORT_WIP_LIMIT env var still wins per invocation.
|
|
87
|
+
export KIT_EFFORT_WIP_LIMIT="$(jq -r 'if (.effort.wipLimit | type) == "null" then "" else (.effort.wipLimit | tostring) end' "$cfg")"
|
|
88
|
+
|
|
83
89
|
# Apply per-folder .claudekit/ overrides (no-op when none exist).
|
|
84
90
|
_kit_apply_claudekit_overlays "$cfg"
|
|
85
91
|
}
|
|
@@ -114,5 +120,6 @@ _kit_apply_claudekit_overlays() {
|
|
|
114
120
|
export KIT_ANNOTATE_BACKEND="$(_kit_cfg_get '.annotate.backend // ""')"
|
|
115
121
|
export KIT_ANNOTATE_FRAMEWORK="$(_kit_cfg_get '.annotate.framework // ""')"
|
|
116
122
|
export KIT_EFFORT_FLOWS="$(_kit_cfg_get '[.effort.flows[]? | tostring] | join(" ")')"
|
|
123
|
+
export KIT_EFFORT_WIP_LIMIT="$(_kit_cfg_get 'if (.effort.wipLimit | type) == "null" then "" else (.effort.wipLimit | tostring) end')"
|
|
117
124
|
export KIT_EFFECTIVE_CONFIG="$merged"
|
|
118
125
|
}
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
# Libs are sourced into whatever shell the session runs (zsh on macOS), so they must behave
|
|
4
4
|
# identically under bash AND zsh. Run: bash scripts/lib/kit-engine-test.sh
|
|
5
5
|
# Re-runs itself under every available shell; set KIT_ENGINE_TEST_INNER to run assertions in-process.
|
|
6
|
+
# errors: strict — a test runner: rc 1 on any failed assertion
|
|
6
7
|
|
|
7
8
|
set -u
|
|
8
9
|
dir=$(CDPATH='' cd -- "$(dirname -- "$0")" && pwd)
|
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
# kit_events_path -> prints the absolute path to kit-events.jsonl
|
|
23
23
|
#
|
|
24
24
|
# Always non-fatal: a failure to emit (no jq, unwritable dir) never breaks the caller.
|
|
25
|
+
# errors: best-effort — the event bus never breaks the op that emits
|
|
25
26
|
|
|
26
27
|
# Resolve the durable, absolute path to the event log.
|
|
27
28
|
# git-common-dir may be relative (".git") — resolve it against the repo root.
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
# must (a) detect zombies + staged deltas as their own analysis bucket, (b) recover any staged delta
|
|
7
7
|
# to its branch as a commit BEFORE pruning, and (c) never prune in a dry-run.
|
|
8
8
|
# Hermetic: a throwaway git repo, no network/gh. Run: bash scripts/lib/kit-gc-test.sh
|
|
9
|
+
# errors: strict — a test runner: rc 1 on any failed assertion
|
|
9
10
|
set -u
|
|
10
11
|
ROOT="$(cd "$(dirname "$0")/../.." && pwd)"
|
|
11
12
|
LIB="$ROOT/scripts/lib"
|
|
@@ -23,6 +24,7 @@ git init -q main
|
|
|
23
24
|
cd main
|
|
24
25
|
git config user.email t@t; git config user.name t
|
|
25
26
|
echo "base" > base.txt; git add base.txt; git commit -q -m "init"
|
|
27
|
+
init_branch="$(git rev-parse --abbrev-ref HEAD)" # master or main, per the host git config
|
|
26
28
|
git worktree add -q ../wt -b feat/5-recover >/dev/null 2>&1
|
|
27
29
|
# Stage a NEW file inside the worktree (writes the worktree's admin index; the blob lands in the
|
|
28
30
|
# shared object store and so survives the worktree dir's death).
|
|
@@ -84,5 +86,128 @@ export GH_CALLS="$tmp/ghcalls"; : > "$GH_CALLS"
|
|
|
84
86
|
PATH="$stub:$PATH" KIT_GC_REPO="o/r" kit_gc_analyze >/dev/null 2>&1
|
|
85
87
|
t "kit_gc_analyze makes exactly ONE gh pr list call" "$(grep -c '^pr list' "$GH_CALLS")" "1"
|
|
86
88
|
|
|
89
|
+
# ── the protection helper is MANDATORY (#219) ───────────────────────────────────────────────────
|
|
90
|
+
# With worktree-issue.sh absent, `wt_protected_reason` is undefined and every issue-open check would
|
|
91
|
+
# return empty — i.e. the whole repo classifies as SAFE to delete. Both entry points must FATAL out
|
|
92
|
+
# instead of emitting a deletion plan. Copy kit-gc.sh ALONE into a dir so the sibling cannot load.
|
|
93
|
+
lone="$tmp/lone"; mkdir -p "$lone"; cp "$LIB/kit-gc.sh" "$lone/kit-gc.sh"
|
|
94
|
+
out="$(bash -c "unset -f wt_protected_reason 2>/dev/null; . '$lone/kit-gc.sh'; kit_gc_analyze" 2>&1)"; rc=$?
|
|
95
|
+
t "kit_gc_analyze refuses without worktree-issue.sh (rc)" "$rc" "1"
|
|
96
|
+
has "kit_gc_analyze says why it refused" "$out" "FATAL"
|
|
97
|
+
# and it must stop BEFORE the table. `kit_gc_analyze` prints `# <section>` headers and indented
|
|
98
|
+
# ` <name> -> <VERDICT>` rows, so match THOSE — an assertion aimed at the wrong shape passes
|
|
99
|
+
# vacuously no matter what the refusal prints.
|
|
100
|
+
t "refusal emits no section header" "$(printf '%s\n' "$out" | grep -cE '^# ')" "0"
|
|
101
|
+
t "refusal emits no classification row" "$(printf '%s\n' "$out" | grep -cE ' -> ')" "0"
|
|
102
|
+
out="$(bash -c ". '$lone/kit-gc.sh'; kit_gc_prune" 2>&1)"; rc=$?
|
|
103
|
+
t "kit_gc_prune refuses without worktree-issue.sh (rc)" "$rc" "1"
|
|
104
|
+
|
|
105
|
+
# ── kit_gc_cleanup: plan first, and the three irreversible buckets survive --yes (#226) ─────────
|
|
106
|
+
# A merged branch is SAFE; a branch whose issue is still OPEN is PROTECTED; a branch with local
|
|
107
|
+
# commits and no PR is ORPHAN. Only the first may ever be deleted, and never without --yes.
|
|
108
|
+
git branch task/40-merged >/dev/null 2>&1
|
|
109
|
+
git branch task/41-open >/dev/null 2>&1
|
|
110
|
+
git branch task/42-orphan >/dev/null 2>&1
|
|
111
|
+
cat > "$stub/gh" <<'SH'
|
|
112
|
+
#!/usr/bin/env bash
|
|
113
|
+
echo "$*" >> "$GH_CALLS"
|
|
114
|
+
case "$1 $2" in
|
|
115
|
+
"pr list") printf 'task/40-merged\tPR#40 MERGED\n' ;;
|
|
116
|
+
"issue view")
|
|
117
|
+
for a in "$@"; do case "$a" in 41) echo open; exit 0 ;; esac; done
|
|
118
|
+
echo closed ;;
|
|
119
|
+
*) : ;;
|
|
120
|
+
esac
|
|
121
|
+
SH
|
|
122
|
+
chmod +x "$stub/gh"
|
|
123
|
+
|
|
124
|
+
plan="$(PATH="$stub:$PATH" KIT_GC_REPO="o/r" kit_gc_cleanup 2>&1)"
|
|
125
|
+
has "cleanup prints a plan" "$plan" "# cleanup plan"
|
|
126
|
+
has "cleanup says it deleted nothing" "$plan" "PLAN ONLY"
|
|
127
|
+
has "cleanup counts the merged branch as SAFE" "$plan" "task/40-merged"
|
|
128
|
+
# Findings from review: the plan must NAME the kept buckets, not just count them — a user cannot
|
|
129
|
+
# veto what they cannot see.
|
|
130
|
+
has "plan names the protected branch" "$plan" "task/41-open"
|
|
131
|
+
has "plan names the orphan branch" "$plan" "task/42-orphan"
|
|
132
|
+
has "plan has a SAFE worktrees bucket" "$plan" "SAFE worktrees"
|
|
133
|
+
# The ZOMBIE bucket (#227 review): --yes recovers a zombie's staged delta to its branch and then
|
|
134
|
+
# prunes its metadata, so the plan MUST name those rows too — otherwise --yes acts on a row the
|
|
135
|
+
# user never saw. Needs its OWN zombie: the one fabricated at the top of this file was already
|
|
136
|
+
# pruned by the "prune gating" step above.
|
|
137
|
+
git worktree add -q ../wt2 -b feat/6-zombie2 >/dev/null 2>&1
|
|
138
|
+
echo "staged in the second zombie" > ../wt2/keep2.txt
|
|
139
|
+
git -C ../wt2 add keep2.txt
|
|
140
|
+
Z2_TIP_BEFORE="$(git rev-parse --verify refs/heads/feat/6-zombie2)"
|
|
141
|
+
rm -rf ../wt2
|
|
142
|
+
zplan="$(PATH="$stub:$PATH" KIT_GC_REPO="o/r" kit_gc_cleanup 2>&1)"
|
|
143
|
+
has "plan has a ZOMBIE worktrees bucket" "$zplan" "ZOMBIE worktrees"
|
|
144
|
+
has "plan names the zombie worktree" "$zplan" "wt2 [feat/6-zombie2]"
|
|
145
|
+
has "plan says the staged work is recovered first" "$zplan" "STAGED work — recovered to a commit"
|
|
146
|
+
t "zombie counted in the plan" \
|
|
147
|
+
"$(printf '%s\n' "$zplan" | awk '/^ ZOMBIE worktrees/{print $3}')" "1"
|
|
148
|
+
# Still plan-only: neither the metadata nor the branch tip may move.
|
|
149
|
+
if [ -d "$(git rev-parse --git-common-dir)/worktrees/wt2" ]; then
|
|
150
|
+
echo "ok: plan-only left the zombie metadata intact"
|
|
151
|
+
else
|
|
152
|
+
echo "FAIL: plan-only pruned the zombie metadata"; fail=1
|
|
153
|
+
fi
|
|
154
|
+
t "plan-only left the zombie branch tip alone" \
|
|
155
|
+
"$(git rev-parse --verify refs/heads/feat/6-zombie2)" "$Z2_TIP_BEFORE"
|
|
156
|
+
|
|
157
|
+
applied="$(PATH="$stub:$PATH" KIT_GC_REPO="o/r" kit_gc_cleanup --yes 2>&1)"
|
|
158
|
+
t "--yes deleted the merged branch" "$(git branch --list task/40-merged | wc -l | tr -d ' ')" "0"
|
|
159
|
+
t "--yes KEPT the open-issue branch" "$(git branch --list task/41-open | wc -l | tr -d ' ')" "1"
|
|
160
|
+
t "--yes KEPT the orphan branch" "$(git branch --list task/42-orphan | wc -l | tr -d ' ')" "1"
|
|
161
|
+
has "cleanup reports what it left" "$applied" "left untouched"
|
|
162
|
+
# --yes is where the zombie metadata is allowed to go — but only AFTER its staged work is a commit.
|
|
163
|
+
if [ -d "$(git rev-parse --git-common-dir)/worktrees/wt2" ]; then
|
|
164
|
+
echo "FAIL: --yes left the zombie metadata behind"; fail=1
|
|
165
|
+
else
|
|
166
|
+
echo "ok: --yes pruned the zombie metadata it listed"
|
|
167
|
+
fi
|
|
168
|
+
Z2_TIP_AFTER="$(git rev-parse --verify refs/heads/feat/6-zombie2)"
|
|
169
|
+
if [ "$Z2_TIP_AFTER" != "$Z2_TIP_BEFORE" ]; then
|
|
170
|
+
echo "ok: --yes recovered the zombie's staged work before pruning"
|
|
171
|
+
else
|
|
172
|
+
echo "FAIL: zombie metadata pruned without recovering its staged work"; fail=1
|
|
173
|
+
fi
|
|
174
|
+
has "the recovered commit carries the staged file" "$(git ls-tree -r --name-only "$Z2_TIP_AFTER")" "keep2.txt"
|
|
175
|
+
has "cleanup counts the zombies it pruned" "$applied" "zombie pruned"
|
|
176
|
+
# The failed-remote-delete count must be a real number the plan prints, not just an exit status —
|
|
177
|
+
# the skill promises it and `--llm` serializes it as `remote_failed`.
|
|
178
|
+
t "cleanup prints a remote-failure count" \
|
|
179
|
+
"$(printf '%s\n' "$applied" | awk '/^ remote deletes failed/{print $4}')" "0"
|
|
180
|
+
|
|
181
|
+
# ── ref-comparison guards: a merged PR alone must NEVER authorize a force delete (#226 review) ──
|
|
182
|
+
# `git branch -D` destroys unpushed commits, and one-directional containment does not prove equality.
|
|
183
|
+
git checkout -q -b task/43-ahead 2>/dev/null
|
|
184
|
+
echo ahead > ahead.txt; git add ahead.txt; git commit -qm "unpushed work"
|
|
185
|
+
# Fabricate a remote-tracking ref that does NOT contain this commit, so the branch is "ahead".
|
|
186
|
+
git update-ref "refs/remotes/origin/task/43-ahead" "$(git rev-parse HEAD~1)"
|
|
187
|
+
git checkout -q "$init_branch"
|
|
188
|
+
|
|
189
|
+
t "_kit_gc_has_unpushed sees the ahead branch" "$(_kit_gc_has_unpushed task/43-ahead && echo yes || echo no)" "yes"
|
|
190
|
+
t "_kit_gc_has_unpushed clears a level branch" "$(_kit_gc_has_unpushed task/42-orphan && echo yes || echo no)" "no"
|
|
191
|
+
# Remote-ahead is the OTHER direction: local ⊆ remote passes the level check but the remote holds
|
|
192
|
+
# history the local does not, so deleting the remote would lose it.
|
|
193
|
+
git update-ref "refs/remotes/origin/task/44-behind" "$(git rev-parse task/43-ahead)"
|
|
194
|
+
git branch task/44-behind "$(git rev-parse task/43-ahead~1)" 2>/dev/null
|
|
195
|
+
t "_kit_gc_remote_ahead sees remote-only history" "$(_kit_gc_remote_ahead task/44-behind && echo yes || echo no)" "yes"
|
|
196
|
+
t "_kit_gc_has_unpushed clears it (local ⊆ remote)" "$(_kit_gc_has_unpushed task/44-behind && echo yes || echo no)" "no"
|
|
197
|
+
|
|
198
|
+
# End to end: a MERGED PR on a branch with unpushed commits must survive --yes.
|
|
199
|
+
cat > "$stub/gh" <<'SH'
|
|
200
|
+
#!/usr/bin/env bash
|
|
201
|
+
case "$1 $2" in
|
|
202
|
+
"pr list") printf 'task/43-ahead\tPR#43 MERGED\n' ;;
|
|
203
|
+
"issue view") echo closed ;;
|
|
204
|
+
*) : ;;
|
|
205
|
+
esac
|
|
206
|
+
SH
|
|
207
|
+
chmod +x "$stub/gh"
|
|
208
|
+
out="$(PATH="$stub:$PATH" KIT_GC_REPO="o/r" kit_gc_prune --yes 2>&1)"
|
|
209
|
+
t "merged-but-ahead branch survives prune --yes" "$(git branch --list task/43-ahead | wc -l | tr -d ' ')" "1"
|
|
210
|
+
has "prune says why it skipped it" "$out" "unpushed commits"
|
|
211
|
+
|
|
87
212
|
[ "$fail" -eq 0 ] && echo "ALL OK (kit-gc)" || echo "kit-gc: FAILURES"
|
|
88
213
|
exit "$fail"
|