@jeiemgi/cckit 0.7.1 → 0.9.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 +15 -4
- package/README.md +25 -3
- package/bin/cckit +91 -8
- package/cckit.config.json +1 -1
- package/kit.config.schema.json +43 -2
- package/package.json +1 -1
- package/scripts/autopilot-test.sh +68 -0
- package/scripts/autopilot.sh +16 -10
- package/scripts/check.sh +14 -1
- package/scripts/copilot-loop-test.sh +3 -0
- package/scripts/guard-raw-git-ops-test.sh +73 -0
- package/scripts/init.sh +68 -8
- package/scripts/lib/agent-profile-test.sh +151 -0
- package/scripts/lib/agent-profile.sh +195 -0
- package/scripts/lib/agent-resolve-test.sh +156 -0
- package/scripts/lib/agent-resolve.sh +177 -0
- package/scripts/lib/branch-owner-test.sh +99 -0
- package/scripts/lib/branch-owner.sh +194 -0
- package/scripts/lib/captain-test.sh +86 -0
- package/scripts/lib/captain.sh +142 -7
- package/scripts/lib/contribute-root-test.sh +40 -0
- package/scripts/lib/contribute-root.sh +22 -0
- package/scripts/lib/effort-metrics.sh +14 -1
- package/scripts/lib/effort-ops-test.sh +54 -2
- package/scripts/lib/effort-ops.sh +243 -23
- package/scripts/lib/effort-parity-test.sh +5 -3
- package/scripts/lib/effort-slug.sh +16 -2
- package/scripts/lib/effort.sh +49 -15
- package/scripts/lib/gh-project.sh +14 -0
- package/scripts/lib/gh-rest-test.sh +301 -0
- package/scripts/lib/gh-rest.sh +289 -0
- package/scripts/lib/hook-refresh-test.sh +65 -0
- package/scripts/lib/hook-refresh.sh +62 -0
- package/scripts/lib/kit-config.sh +6 -0
- package/scripts/lib/kit-gc-test.sh +178 -1
- package/scripts/lib/kit-gc.sh +251 -55
- package/scripts/lib/kit-task-ops-test.sh +15 -0
- package/scripts/lib/kit-task-ops.sh +231 -58
- package/scripts/lib/kto-task-close-test.sh +83 -0
- package/scripts/lib/kto-task-pr-merge-test.sh +129 -0
- package/scripts/lib/kto-task-pr-test.sh +59 -0
- package/scripts/lib/orchestration-runtime-test.sh +142 -0
- package/scripts/lib/orchestration-runtime.sh +171 -0
- package/scripts/lib/review-stage-test.sh +241 -0
- package/scripts/lib/review-stage.sh +259 -0
- package/scripts/lib/stage-receipt-test.sh +252 -0
- package/scripts/lib/stage-receipt.sh +442 -0
- package/scripts/lib/test-env-test.sh +25 -0
- package/scripts/lib/test-env.sh +33 -0
- package/scripts/lib/worker-brief-test.sh +120 -0
- package/scripts/lib/worker-brief.sh +185 -0
- package/scripts/lib/worktree-issue.sh +14 -0
- package/scripts/lib/worktree-ports-test.sh +146 -0
- package/scripts/lib/worktree-start.sh +153 -8
- package/scripts/lib/zsh-safety-test.sh +67 -0
- package/scripts/orchestrate.sh +124 -22
- package/scripts/portable-test.sh +22 -1
- package/scripts/review-lint-baseline.txt +28 -0
- package/scripts/review-lint-test.sh +271 -0
- package/scripts/review-lint.sh +259 -0
- package/scripts/review-rules.conf +55 -0
- package/scripts/setup-labels.sh +21 -1
- package/scripts/skill-frontmatter-baseline.txt +24 -0
- package/scripts/skill-frontmatter-lint-test.sh +156 -0
- package/scripts/skill-frontmatter-lint.sh +182 -0
- package/scripts/task-sync.sh +8 -0
- package/scripts/test.sh +10 -1
- package/skills/kit-autopilot/SKILL.md +13 -1
- package/skills/kit-cleanup/SKILL.md +5 -3
- package/skills/kit-contribute/SKILL.md +6 -5
- package/skills/kit-effort-close/SKILL.md +8 -3
- package/skills/kit-effort-pr/SKILL.md +16 -95
- package/skills/kit-gc/SKILL.md +15 -10
- package/skills/kit-security-sweep/SKILL.md +4 -6
- package/skills/kit-ship/SKILL.md +1 -1
- package/skills/kit-task-pr/SKILL.md +2 -0
- package/templates/hooks/guard-raw-git-ops.sh.tmpl +193 -0
- package/templates/rules/branch-naming.md +6 -0
- package/templates/rules/effort-model.md +3 -0
- package/templates/rules/naming-and-ids.md +4 -1
- package/templates/settings/settings.json.tmpl +4 -2
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# shellcheck shell=bash
|
|
3
|
+
# gh-rest.sh — the GitHub transport switch and the REST forms of the lifecycle calls (#396).
|
|
4
|
+
#
|
|
5
|
+
# Cloud agent sessions reach GitHub through a proxy that refuses every GraphQL request (403), and
|
|
6
|
+
# `gh pr …` / `gh issue …` are GraphQL underneath. REST calls to the attached repo still work. So the
|
|
7
|
+
# lifecycle verbs (pr, merge, close, new, effort new|pr|close) pick a transport here:
|
|
8
|
+
#
|
|
9
|
+
# CCKIT_GH_TRANSPORT=rest|graphql forces it
|
|
10
|
+
# CLAUDE_CODE_REMOTE=true defaults it to rest (a cloud session)
|
|
11
|
+
# otherwise graphql — the gh subcommands, unchanged
|
|
12
|
+
#
|
|
13
|
+
# In rest mode every call is `gh api repos/<owner>/<repo>/…`, endpoint first. Projects v2 is
|
|
14
|
+
# GraphQL-only, so board steps are skipped with ONE notice line (exit 0, never a failure).
|
|
15
|
+
#
|
|
16
|
+
# cckit_gh_rest rc 0 iff the transport is rest
|
|
17
|
+
# cckit_gh_transport echo rest|graphql
|
|
18
|
+
# cckit_board_skipped rc 0 iff board steps are skipped (prints the notice once)
|
|
19
|
+
# gh_rest_closing_refs stdin: a PR body → the issue #s it closes (pure)
|
|
20
|
+
# gh_rest_issue_json <repo> <n> {number,title,body,state,labels[{name}],milestone{title,number}}
|
|
21
|
+
# gh_rest_issue_state <repo> <n> OPEN | CLOSED
|
|
22
|
+
# gh_rest_issue_create <repo> <title> <body> <labels-csv> [milestone-title] [assign 1|0] → html_url
|
|
23
|
+
# gh_rest_issue_close <repo> <n> <completed|not_planned|duplicate> [comment]
|
|
24
|
+
# gh_rest_issue_edit_title <repo> <n> <title>
|
|
25
|
+
# gh_rest_issue_set_body <repo> <n> <body>
|
|
26
|
+
# gh_rest_issue_add_labels <repo> <n> <labels-csv>
|
|
27
|
+
# gh_rest_label_create <repo> <name> <color> <description> (idempotent)
|
|
28
|
+
# gh_rest_milestone_number <repo> <title>
|
|
29
|
+
# gh_rest_pr_create <repo> <base> <head> <title> <body> <labels-csv> [milestone-title] → html_url
|
|
30
|
+
# gh_rest_pr_for_head <repo> <branch> the open PR number for a head branch
|
|
31
|
+
# gh_rest_pr_json <repo> <pr> {mergeable,mergeStateStatus,baseRefName,headRefName,body,state}
|
|
32
|
+
# gh_rest_pr_merge <repo> <pr> <squash|merge|rebase>
|
|
33
|
+
# gh_rest_pr_closing_issues <repo> <pr>
|
|
34
|
+
# gh_rest_pr_diff <repo> <pr>
|
|
35
|
+
# gh_rest_sub_issue_numbers <repo> <n>
|
|
36
|
+
# gh_rest_issue_numbers_by_label <repo> <label> open issues only
|
|
37
|
+
# gh_rest_open_issue_titles <repo> "<n>\t<title>" for every open issue
|
|
38
|
+
# gh_rest_issue_closing_prs <repo> <n> merged PRs that close <n> by keyword (timeline)
|
|
39
|
+
# gh_rest_wave_rows <repo> <parent> "sub|STATE|pr|merge-sha|pr-title" per sub (wave close)
|
|
40
|
+
#
|
|
41
|
+
# Not reachable over REST in the cloud: Projects v2 (skipped), and remote branch deletion (the proxy
|
|
42
|
+
# rejects DELETE git/refs) — callers keep the branch and say so.
|
|
43
|
+
# bash 3.2 + zsh compatible. Requires gh, jq.
|
|
44
|
+
# errors: mixed — creates, closes and merges propagate; labels/milestone/assignee are best-effort
|
|
45
|
+
|
|
46
|
+
CCKIT_BOARD_SKIP_NOTICE="cckit: board step skipped (GraphQL unavailable; the project's built-in workflows move the card)"
|
|
47
|
+
|
|
48
|
+
# rc 0 iff the transport is rest. An unknown CCKIT_GH_TRANSPORT warns once and falls to the default.
|
|
49
|
+
cckit_gh_rest() {
|
|
50
|
+
case "${CCKIT_GH_TRANSPORT:-}" in
|
|
51
|
+
rest) return 0 ;;
|
|
52
|
+
graphql) return 1 ;;
|
|
53
|
+
'') : ;;
|
|
54
|
+
*)
|
|
55
|
+
if [ -z "${_CCKIT_TRANSPORT_WARNED:-}" ]; then
|
|
56
|
+
printf "cckit: CCKIT_GH_TRANSPORT must be rest or graphql (got '%s') — using the default\n" \
|
|
57
|
+
"$CCKIT_GH_TRANSPORT" >&2
|
|
58
|
+
_CCKIT_TRANSPORT_WARNED=1
|
|
59
|
+
fi ;;
|
|
60
|
+
esac
|
|
61
|
+
[ "${CLAUDE_CODE_REMOTE:-}" = "true" ]
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
cckit_gh_transport() {
|
|
65
|
+
if cckit_gh_rest; then printf 'rest'; else printf 'graphql'; fi
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
# rc 0 when board steps are skipped (rest mode). Prints the notice at most once per process.
|
|
69
|
+
cckit_board_skipped() {
|
|
70
|
+
cckit_gh_rest || return 1
|
|
71
|
+
if [ -z "${_CCKIT_BOARD_NOTICE_DONE:-}" ]; then
|
|
72
|
+
printf '%s\n' "$CCKIT_BOARD_SKIP_NOTICE" >&2
|
|
73
|
+
_CCKIT_BOARD_NOTICE_DONE=1
|
|
74
|
+
fi
|
|
75
|
+
return 0
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
# --- pure ----------------------------------------------------------------------------------------
|
|
79
|
+
|
|
80
|
+
# A PR body on stdin → the issue numbers it closes, one per line, sorted. REST has no
|
|
81
|
+
# closingIssuesReferences, so the keywords are read from the body (the same regex the graphql path
|
|
82
|
+
# falls back to).
|
|
83
|
+
gh_rest_closing_refs() {
|
|
84
|
+
grep -ioE '(close[sd]?|fix(e[sd])?|resolve[sd]?) +#[0-9]+' | grep -oE '[0-9]+' | sort -un
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
# Split a comma list into `-f <key>[]=<item>` args on stdout, one arg per line (callers read them
|
|
88
|
+
# back with a while loop: no word splitting, so a label with a space survives).
|
|
89
|
+
_ghr_array_args() {
|
|
90
|
+
local key="$1" item
|
|
91
|
+
printf '%s\n' "$2" | tr ',' '\n' | while IFS= read -r item; do
|
|
92
|
+
item="$(printf '%s' "$item" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
|
|
93
|
+
[ -n "$item" ] && printf -- '-f\n%s[]=%s\n' "$key" "$item"
|
|
94
|
+
done
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
# `gh api …` for a read. On failure gh prints the error JSON to stdout and skips --jq, so the output
|
|
98
|
+
# is kept only on rc 0: a failed read is no data (rc 1), never an error body taken as a value.
|
|
99
|
+
_ghr_read() {
|
|
100
|
+
local out
|
|
101
|
+
out="$(gh api "$@")" || return 1
|
|
102
|
+
[ -n "$out" ] && printf '%s\n' "$out"
|
|
103
|
+
return 0
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
# --- issues --------------------------------------------------------------------------------------
|
|
107
|
+
|
|
108
|
+
gh_rest_issue_json() {
|
|
109
|
+
_ghr_read "repos/$1/issues/$2" --jq '{number, title, body: (.body // ""), state: (.state | ascii_upcase),
|
|
110
|
+
labels: [.labels[]? | {name}],
|
|
111
|
+
milestone: (if .milestone then {title: .milestone.title, number: .milestone.number} else null end)}'
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
gh_rest_issue_state() {
|
|
115
|
+
_ghr_read "repos/$1/issues/$2" --jq '.state | ascii_upcase'
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
gh_rest_milestone_number() {
|
|
119
|
+
local tab n t; tab="$(printf '\t')"
|
|
120
|
+
_ghr_read "repos/$1/milestones" -X GET -f state=all -f per_page=100 \
|
|
121
|
+
--jq '.[] | "\(.number)\t\(.title)"' 2>/dev/null \
|
|
122
|
+
| while IFS="$tab" read -r n t; do [ "$t" = "$2" ] && { printf '%s' "$n"; break; }; done
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
# Create an issue with labels + milestone, then assign it to its author (the REST form of
|
|
126
|
+
# `gh issue create --assignee @me`: the token's own login is the author). <assign> 0 skips that.
|
|
127
|
+
# Echoes the html_url.
|
|
128
|
+
gh_rest_issue_create() {
|
|
129
|
+
local repo="$1" title="$2" body="$3" labels="${4:-}" ms="${5:-}" assign="${6:-1}" msnum="" out num url login a
|
|
130
|
+
local tab; tab="$(printf '\t')"
|
|
131
|
+
set -- -f "title=$title" -f "body=$body"
|
|
132
|
+
while IFS= read -r a; do [ -n "$a" ] && set -- "$@" "$a"; done <<EOF
|
|
133
|
+
$(_ghr_array_args labels "$labels")
|
|
134
|
+
EOF
|
|
135
|
+
if [ -n "$ms" ]; then
|
|
136
|
+
msnum="$(gh_rest_milestone_number "$repo" "$ms")"
|
|
137
|
+
if [ -n "$msnum" ]; then set -- "$@" -F "milestone=$msnum"
|
|
138
|
+
else echo "cckit: milestone '$ms' not found in $repo — issue created without it" >&2; fi
|
|
139
|
+
fi
|
|
140
|
+
out="$(gh api "repos/$repo/issues" -X POST "$@" \
|
|
141
|
+
--jq '"\(.number)\t\(.html_url)\t\(.user.login // "")"')" || return 1
|
|
142
|
+
IFS="$tab" read -r num url login <<EOF
|
|
143
|
+
$out
|
|
144
|
+
EOF
|
|
145
|
+
[ -n "$num" ] || return 1
|
|
146
|
+
if [ "$assign" = 1 ] && [ -n "$login" ]; then
|
|
147
|
+
gh api "repos/$repo/issues/$num/assignees" -X POST -f "assignees[]=$login" >/dev/null 2>&1 \
|
|
148
|
+
|| echo "cckit: #$num created but not assigned to $login" >&2
|
|
149
|
+
fi
|
|
150
|
+
printf '%s\n' "$url"
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
# Close with a GitHub state_reason (completed | not_planned | duplicate); the comment goes first,
|
|
154
|
+
# as `gh issue close --comment` does.
|
|
155
|
+
gh_rest_issue_close() {
|
|
156
|
+
local repo="$1" n="$2" reason="${3:-completed}" comment="${4:-}"
|
|
157
|
+
reason="$(printf '%s' "$reason" | tr ' -' '__')"
|
|
158
|
+
if [ -n "$comment" ]; then
|
|
159
|
+
gh api "repos/$repo/issues/$n/comments" -X POST -f "body=$comment" >/dev/null || return 1
|
|
160
|
+
fi
|
|
161
|
+
gh api "repos/$repo/issues/$n" -X PATCH -f state=closed -f "state_reason=$reason" >/dev/null
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
gh_rest_issue_edit_title() {
|
|
165
|
+
gh api "repos/$1/issues/$2" -X PATCH -f "title=$3" >/dev/null
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
gh_rest_issue_set_body() {
|
|
169
|
+
gh api "repos/$1/issues/$2" -X PATCH -f "body=$3" >/dev/null
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
gh_rest_issue_add_labels() {
|
|
173
|
+
local repo="$1" n="$2" labels="${3:-}" a
|
|
174
|
+
set --
|
|
175
|
+
while IFS= read -r a; do [ -n "$a" ] && set -- "$@" "$a"; done <<EOF
|
|
176
|
+
$(_ghr_array_args labels "$labels")
|
|
177
|
+
EOF
|
|
178
|
+
[ $# -gt 0 ] || return 0
|
|
179
|
+
gh api "repos/$repo/issues/$n/labels" -X POST "$@" >/dev/null
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
# Idempotent: an existing label answers 422, which is fine.
|
|
183
|
+
gh_rest_label_create() {
|
|
184
|
+
gh api "repos/$1/labels" -X POST -f "name=$2" -f "color=$3" -f "description=$4" >/dev/null 2>&1 || true
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
gh_rest_sub_issue_numbers() {
|
|
188
|
+
_ghr_read "repos/$1/issues/$2/sub_issues" -X GET -f per_page=100 --jq '.[].number'
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
gh_rest_issue_numbers_by_label() {
|
|
192
|
+
_ghr_read "repos/$1/issues" -X GET -f state=open -f "labels=$2" -f per_page=100 \
|
|
193
|
+
--jq '.[] | select(.pull_request | not) | .number'
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
gh_rest_open_issue_titles() {
|
|
197
|
+
_ghr_read "repos/$1/issues" -X GET -f state=open -f per_page=100 --paginate \
|
|
198
|
+
--jq '.[] | select(.pull_request | not) | "\(.number)\t\(.title)"'
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
# --- pull requests -------------------------------------------------------------------------------
|
|
202
|
+
|
|
203
|
+
# Open a PR, then set labels, milestone and assignee (its author — `--assignee @me`) in one PATCH.
|
|
204
|
+
# The PR is the failure that matters; the decoration is best-effort and says so. Echoes the html_url.
|
|
205
|
+
gh_rest_pr_create() {
|
|
206
|
+
local repo="$1" base="$2" head="$3" title="$4" body="$5" labels="${6:-}" ms="${7:-}" msnum out num url login a
|
|
207
|
+
local tab; tab="$(printf '\t')"
|
|
208
|
+
out="$(gh api "repos/$repo/pulls" -X POST -f "title=$title" -f "head=$head" -f "base=$base" -f "body=$body" \
|
|
209
|
+
--jq '"\(.number)\t\(.html_url)\t\(.user.login // "")"')" || return 1
|
|
210
|
+
IFS="$tab" read -r num url login <<EOF
|
|
211
|
+
$out
|
|
212
|
+
EOF
|
|
213
|
+
[ -n "$num" ] || return 1
|
|
214
|
+
set --
|
|
215
|
+
while IFS= read -r a; do [ -n "$a" ] && set -- "$@" "$a"; done <<EOF
|
|
216
|
+
$(_ghr_array_args labels "$labels")
|
|
217
|
+
EOF
|
|
218
|
+
[ -n "$login" ] && set -- "$@" -f "assignees[]=$login"
|
|
219
|
+
if [ -n "$ms" ]; then
|
|
220
|
+
msnum="$(gh_rest_milestone_number "$repo" "$ms")"
|
|
221
|
+
if [ -n "$msnum" ]; then set -- "$@" -F "milestone=$msnum"
|
|
222
|
+
else echo "cckit: milestone '$ms' not found in $repo — PR opened without it" >&2; fi
|
|
223
|
+
fi
|
|
224
|
+
if [ $# -gt 0 ]; then
|
|
225
|
+
gh api "repos/$repo/issues/$num" -X PATCH "$@" >/dev/null 2>&1 \
|
|
226
|
+
|| echo "cckit: PR #$num opened, but its labels/milestone/assignee were not set" >&2
|
|
227
|
+
fi
|
|
228
|
+
printf '%s\n' "$url"
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
gh_rest_pr_for_head() {
|
|
232
|
+
_ghr_read "repos/$1/pulls" -X GET -f "head=${1%%/*}:$2" -f state=open --jq '.[0].number // empty'
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
# The fields the merge path reads, in the graphql vocabulary: mergeable MERGEABLE|CONFLICTING|UNKNOWN
|
|
236
|
+
# (REST true|false|null — null while GitHub computes it), mergeStateStatus = REST mergeable_state.
|
|
237
|
+
gh_rest_pr_json() {
|
|
238
|
+
_ghr_read "repos/$1/pulls/$2" --jq '{
|
|
239
|
+
mergeable: (if .mergeable == true then "MERGEABLE" elif .mergeable == false then "CONFLICTING" else "UNKNOWN" end),
|
|
240
|
+
mergeStateStatus: ((.mergeable_state // "unknown") | ascii_upcase),
|
|
241
|
+
baseRefName: .base.ref, headRefName: .head.ref, body: (.body // ""),
|
|
242
|
+
state: (if .merged_at then "MERGED" else (.state | ascii_upcase) end)}'
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
gh_rest_pr_merge() {
|
|
246
|
+
gh api "repos/$1/pulls/$2/merge" -X PUT -f "merge_method=${3:-squash}" >/dev/null
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
gh_rest_pr_closing_issues() {
|
|
250
|
+
_ghr_read "repos/$1/pulls/$2" --jq '.body // ""' 2>/dev/null | gh_rest_closing_refs
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
gh_rest_pr_diff() {
|
|
254
|
+
_ghr_read "repos/$1/pulls/$2" -H 'Accept: application/vnd.github.v3.diff'
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
# The merged PRs that close issue <n> (graphql: closedByPullRequestsReferences, merged only). REST has
|
|
258
|
+
# no such link, so: the PRs in <n>'s timeline that cross-reference it, are merged, live in this repo,
|
|
259
|
+
# and close it by keyword. One number per line, timeline order.
|
|
260
|
+
gh_rest_issue_closing_prs() {
|
|
261
|
+
local repo="$1" n="$2"
|
|
262
|
+
_ghr_read "repos/$repo/issues/$n/timeline" -X GET -f per_page=100 --jq "
|
|
263
|
+
.[] | select(.event == \"cross-referenced\") | .source.issue // empty
|
|
264
|
+
| select(.pull_request.merged_at != null)
|
|
265
|
+
| select((.repository_url // \"\") | endswith(\"/repos/$repo\"))
|
|
266
|
+
| select((.body // \"\") | test(\"(?i)(close[sd]?|fix(e[sd])?|resolve[sd]?) +#$n([^0-9]|\$)\"))
|
|
267
|
+
| .number"
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
# The wave close's per-sub read (graphql: subIssues + closedByPullRequestsReferences): each sub from
|
|
271
|
+
# sub_issues, its first merged closing PR, then that PR's merge commit and title. A failed read leaves
|
|
272
|
+
# the field empty, so the close refuses (fails closed, as the graphql path does).
|
|
273
|
+
gh_rest_wave_rows() {
|
|
274
|
+
local repo="$1" parent="$2" tab sub state pr oid title
|
|
275
|
+
tab="$(printf '\t')"
|
|
276
|
+
_ghr_read "repos/$repo/issues/$parent/sub_issues" -X GET -f per_page=100 \
|
|
277
|
+
--jq '.[] | "\(.number)\t\(.state | ascii_upcase)"' 2>/dev/null \
|
|
278
|
+
| while IFS="$tab" read -r sub state; do
|
|
279
|
+
[ -n "$sub" ] || continue
|
|
280
|
+
oid="" title=""
|
|
281
|
+
pr="$(gh_rest_issue_closing_prs "$repo" "$sub" 2>/dev/null | head -1)"
|
|
282
|
+
if [ -n "$pr" ]; then
|
|
283
|
+
IFS="$tab" read -r oid title <<EOF
|
|
284
|
+
$(_ghr_read "repos/$repo/pulls/$pr" --jq '"\(.merge_commit_sha // "")\t\(.title // "")"' 2>/dev/null)
|
|
285
|
+
EOF
|
|
286
|
+
fi
|
|
287
|
+
printf '%s|%s|%s|%s|%s\n' "$sub" "$state" "$pr" "$oid" "$title"
|
|
288
|
+
done
|
|
289
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# hook-refresh-test.sh — `init --upgrade` refreshes an unmodified kit hook and reports a customized
|
|
3
|
+
# one without touching it (#370). Part 1 drives hook_refresh_state against a fixture kit repo with
|
|
4
|
+
# two template versions in its history; part 2 runs the real init.sh --upgrade on a scratch project.
|
|
5
|
+
# Run: bash scripts/lib/hook-refresh-test.sh
|
|
6
|
+
# errors: strict — a test runner: rc 1 on any failed assertion
|
|
7
|
+
set -u
|
|
8
|
+
ROOT="$(cd "$(dirname "$0")/../.." && pwd)"
|
|
9
|
+
fail=0
|
|
10
|
+
t() { if [ "$2" = "$3" ]; then echo "ok: $1"; else echo "FAIL: $1 -> got '[$2]' want '[$3]'"; fail=1; fi; }
|
|
11
|
+
command -v jq >/dev/null 2>&1 || { echo "hook-refresh-test: jq required" >&2; exit 1; }
|
|
12
|
+
# shellcheck source=/dev/null
|
|
13
|
+
. "$ROOT/scripts/lib/hook-refresh.sh"
|
|
14
|
+
|
|
15
|
+
tmp="$(mktemp -d)"; trap 'rm -rf "$tmp"' EXIT
|
|
16
|
+
g() { git -C "$1" -c user.email=t@t -c user.name=t "${@:2}"; }
|
|
17
|
+
|
|
18
|
+
# ── part 1: the verdicts, against a fixture kit with template history v1 → v2 ─────────────────
|
|
19
|
+
kit="$tmp/kit"; git init -q "$kit"; mkdir -p "$kit/templates/hooks"
|
|
20
|
+
tpl="$kit/templates/hooks/h.sh.tmpl"
|
|
21
|
+
printf '#!/usr/bin/env bash\necho v1\n' > "$tpl"; g "$kit" add -A; g "$kit" commit -q -m v1
|
|
22
|
+
printf '#!/usr/bin/env bash\necho v2\n' > "$tpl"; g "$kit" commit -qam v2
|
|
23
|
+
inst="$tmp/installed.sh"
|
|
24
|
+
|
|
25
|
+
printf '#!/usr/bin/env bash\necho v2\n' > "$inst"
|
|
26
|
+
t "the current template is current" "$(hook_refresh_state "$inst" "$tpl" "$kit")" current
|
|
27
|
+
printf '#!/usr/bin/env bash\necho v1\n' > "$inst"
|
|
28
|
+
t "an older shipped version is refreshable" "$(hook_refresh_state "$inst" "$tpl" "$kit")" refresh
|
|
29
|
+
printf '#!/usr/bin/env bash\necho v1\n# mine\n' > "$inst"
|
|
30
|
+
t "a customized copy is drifted" "$(hook_refresh_state "$inst" "$tpl" "$kit")" drifted
|
|
31
|
+
t "no kit history (npm/brew): drifted" "$(hook_refresh_state "$inst" "$tpl" "$tmp/no-git")" drifted
|
|
32
|
+
mf="$tmp/kit.manifest.json"
|
|
33
|
+
printf '{"schema":1,"entries":{".claude/hooks/h.sh":{"hash":"%s"}}}\n' "$(_hr_hash_file "$inst")" > "$mf"
|
|
34
|
+
t "the manifest hash proves it unmodified" "$(hook_refresh_state "$inst" "$tpl" "$tmp/no-git" "$mf" .claude/hooks/h.sh)" refresh
|
|
35
|
+
t "a missing hook is missing" "$(hook_refresh_state "$tmp/nope" "$tpl" "$kit")" missing
|
|
36
|
+
g "$kit" mv templates/hooks/h.sh.tmpl templates/hooks/renamed.sh.tmpl; g "$kit" commit -qm rename
|
|
37
|
+
t "history follows a renamed template" "$(hook_refresh_state "$inst" "$kit/templates/hooks/renamed.sh.tmpl" "$kit" 2>/dev/null; printf '#!/usr/bin/env bash\necho v1\n' > "$inst"; hook_refresh_state "$inst" "$kit/templates/hooks/renamed.sh.tmpl" "$kit")" "drifted
|
|
38
|
+
refresh"
|
|
39
|
+
|
|
40
|
+
# ── part 2: the real init.sh --upgrade ───────────────────────────────────────────────────────────
|
|
41
|
+
proj="$tmp/proj"; git init -q "$proj"; g "$proj" commit -q --allow-empty -m init
|
|
42
|
+
mkdir -p "$proj/.claude/hooks"
|
|
43
|
+
printf '{"kitVersion":"0.0.1","profile":"software","project":{"name":"H","slug":"h"},"github":{"repo":"e/h","owner":"e","projectsV2":false}}\n' > "$proj/.claude/kit.config.json"
|
|
44
|
+
up() { CLAUDE_PLUGIN_ROOT="$ROOT" bash "$ROOT/scripts/init.sh" --upgrade --target "$proj" --force 2>&1; }
|
|
45
|
+
up >/dev/null || { echo "FAIL: first init.sh --upgrade"; fail=1; }
|
|
46
|
+
|
|
47
|
+
old="$proj/.claude/hooks/guard-base-branch-commit.sh" # unmodified, but an OLDER kit version
|
|
48
|
+
own="$proj/.claude/hooks/repo-hygiene.sh" # customized by the project
|
|
49
|
+
printf '#!/usr/bin/env bash\n# an older kit version of this hook\nexit 0\n' > "$old"
|
|
50
|
+
( cd "$proj" && KIT_MANIFEST="$proj/.claude/kit.manifest.json" bash -c '
|
|
51
|
+
. "$1/scripts/lib/kit-manifest.sh"; kit_manifest_init; kit_manifest_record .claude/hooks/guard-base-branch-commit.sh B init >/dev/null' _ "$ROOT" )
|
|
52
|
+
printf '\n# project-specific tweak\n' >> "$own"
|
|
53
|
+
own_before="$(cat "$own")"
|
|
54
|
+
|
|
55
|
+
# A template fix ships with a new kit version: rewind kitVersion so the upgrade runs again.
|
|
56
|
+
jq '.kitVersion = "0.0.1"' "$proj/.claude/kit.config.json" > "$tmp/cfg" && mv "$tmp/cfg" "$proj/.claude/kit.config.json"
|
|
57
|
+
out="$(up)"
|
|
58
|
+
t "the unmodified hook now equals the template" "$(cmp -s "$old" "$ROOT/templates/hooks/guard-base-branch-commit.sh.tmpl" && echo same || echo differs)" same
|
|
59
|
+
case "$out" in *"~ .claude/hooks/guard-base-branch-commit.sh"*) echo "ok: the refresh is reported" ;; *) echo "FAIL: refresh not reported"; fail=1 ;; esac
|
|
60
|
+
t "the customized hook is untouched" "$(cat "$own")" "$own_before"
|
|
61
|
+
case "$out" in *"! .claude/hooks/repo-hygiene.sh"*) echo "ok: the customized hook is reported as drifted" ;; *) echo "FAIL: drift not reported"; fail=1 ;; esac
|
|
62
|
+
case "$out" in *"= .claude/hooks/guard-raw-git-ops.sh"*) echo "ok: a current hook is just preserved" ;; *) echo "FAIL: current hook not listed as preserved"; fail=1 ;; esac
|
|
63
|
+
|
|
64
|
+
[ "$fail" -eq 0 ] && echo "hook-refresh: all passed" || echo "hook-refresh: FAILURES"
|
|
65
|
+
exit "$fail"
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# shellcheck shell=bash
|
|
3
|
+
# hook-refresh.sh — tell an unmodified kit hook from a customized one, so `init --upgrade` can
|
|
4
|
+
# refresh the first and only report the second (#370).
|
|
5
|
+
#
|
|
6
|
+
# `init --upgrade` preserves every existing file. That protects a customized hook, but it also
|
|
7
|
+
# froze unmodified ones: a hook installed from a template never received later template fixes.
|
|
8
|
+
#
|
|
9
|
+
# hook_refresh_state <installed> <template> <kit-root> [manifest] [rel]
|
|
10
|
+
# prints one word:
|
|
11
|
+
# current the installed hook already equals the template
|
|
12
|
+
# refresh it equals an EARLIER version of the template (from <kit-root>'s git history,
|
|
13
|
+
# following renames), or the hash the manifest recorded for <rel> — unmodified,
|
|
14
|
+
# safe to overwrite
|
|
15
|
+
# drifted it matches no version the kit shipped — the repo customized it; keep it, report it
|
|
16
|
+
# missing no installed file
|
|
17
|
+
#
|
|
18
|
+
# Templates with {{VARS}} or IF blocks are rendered per project, so their history cannot be
|
|
19
|
+
# compared byte for byte; for those only the manifest can prove a file unmodified.
|
|
20
|
+
# Requires git, plus shasum or sha256sum.
|
|
21
|
+
# errors: pure — prints a verdict, rc 0
|
|
22
|
+
# bash 3.2 + zsh compatible.
|
|
23
|
+
|
|
24
|
+
_hr_hash_file() {
|
|
25
|
+
if command -v shasum >/dev/null 2>&1; then shasum -a 256 < "$1" | awk '{print $1}'
|
|
26
|
+
else sha256sum < "$1" | awk '{print $1}'; fi
|
|
27
|
+
}
|
|
28
|
+
_hr_hash_stdin() {
|
|
29
|
+
if command -v shasum >/dev/null 2>&1; then shasum -a 256 | awk '{print $1}'
|
|
30
|
+
else sha256sum | awk '{print $1}'; fi
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
# _hr_history_hashes <kit-root> <template> — the hash of every committed version of <template>,
|
|
34
|
+
# one per line, following renames. Prints nothing when <kit-root> is not a git checkout (an npm or
|
|
35
|
+
# Homebrew install), which leaves only the manifest as evidence.
|
|
36
|
+
_hr_history_hashes() {
|
|
37
|
+
local root="$1" tpl="$2" rel line c=""
|
|
38
|
+
rel="${tpl#"$root"/}"
|
|
39
|
+
git -C "$root" rev-parse --git-dir >/dev/null 2>&1 || return 0
|
|
40
|
+
git -C "$root" log --follow --format='C %H' --name-only -- "$rel" 2>/dev/null | while IFS= read -r line; do
|
|
41
|
+
case "$line" in
|
|
42
|
+
"C "*) c="${line#C }" ;;
|
|
43
|
+
"") : ;;
|
|
44
|
+
*) [ -n "$c" ] && git -C "$root" show "$c:$line" 2>/dev/null | _hr_hash_stdin ;;
|
|
45
|
+
esac
|
|
46
|
+
done
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
hook_refresh_state() {
|
|
50
|
+
local inst="$1" tpl="$2" root="$3" mf="${4:-}" rel="${5:-}" cur h
|
|
51
|
+
[ -f "$inst" ] || { echo missing; return 0; }
|
|
52
|
+
cur="$(_hr_hash_file "$inst")"
|
|
53
|
+
if [ "$cur" = "$(_hr_hash_file "$tpl")" ]; then echo current; return 0; fi
|
|
54
|
+
if [ -n "$mf" ] && [ -n "$rel" ] && [ -f "$mf" ] && command -v jq >/dev/null 2>&1; then
|
|
55
|
+
h="$(jq -r --arg r "$rel" '.entries[$r].hash // empty' "$mf" 2>/dev/null)"
|
|
56
|
+
[ -n "$h" ] && [ "$h" = "$cur" ] && { echo refresh; return 0; }
|
|
57
|
+
fi
|
|
58
|
+
if ! grep -qE '\{\{[A-Za-z_]+\}\}|<!-- IF:' "$tpl" 2>/dev/null; then
|
|
59
|
+
if _hr_history_hashes "$root" "$tpl" | grep -qx "$cur"; then echo refresh; return 0; fi
|
|
60
|
+
fi
|
|
61
|
+
echo drifted
|
|
62
|
+
}
|
|
@@ -86,6 +86,12 @@ load_kit_config() {
|
|
|
86
86
|
# back to its built-in default of 2. An EFFORT_WIP_LIMIT env var still wins per invocation.
|
|
87
87
|
export KIT_EFFORT_WIP_LIMIT="$(jq -r 'if (.effort.wipLimit | type) == "null" then "" else (.effort.wipLimit | tostring) end' "$cfg")"
|
|
88
88
|
|
|
89
|
+
# PR conventions (#361). pr.titleStyle: "conventional" (default — release-please + commitlint read
|
|
90
|
+
# the squash subject) or "issue-title" (the PR title is the issue title, verbatim).
|
|
91
|
+
# pr.orchestratorSection: true adds a 2-line `## For the orchestrator` section to `cckit pr` bodies.
|
|
92
|
+
export KIT_PR_TITLE_STYLE="$(jq -r '.pr.titleStyle // "conventional"' "$cfg")"
|
|
93
|
+
export KIT_PR_ORCHESTRATOR_SECTION="$(jq -r '.pr.orchestratorSection // false' "$cfg")"
|
|
94
|
+
|
|
89
95
|
# Apply per-folder .claudekit/ overrides (no-op when none exist).
|
|
90
96
|
_kit_apply_claudekit_overlays "$cfg"
|
|
91
97
|
}
|
|
@@ -107,7 +107,10 @@ t "kit_gc_prune refuses without worktree-issue.sh (rc)" "$rc" "1"
|
|
|
107
107
|
# commits and no PR is ORPHAN. Only the first may ever be deleted, and never without --yes.
|
|
108
108
|
git branch task/40-merged >/dev/null 2>&1
|
|
109
109
|
git branch task/41-open >/dev/null 2>&1
|
|
110
|
-
|
|
110
|
+
# The orphan carries ONE commit base never received — a branch level with base would be LANDED (#388).
|
|
111
|
+
git checkout -q -b task/42-orphan
|
|
112
|
+
echo "only here" > orphan.txt; git add orphan.txt; git commit -qm "orphan work"
|
|
113
|
+
git checkout -q "$init_branch"
|
|
111
114
|
cat > "$stub/gh" <<'SH'
|
|
112
115
|
#!/usr/bin/env bash
|
|
113
116
|
echo "$*" >> "$GH_CALLS"
|
|
@@ -209,5 +212,179 @@ out="$(PATH="$stub:$PATH" KIT_GC_REPO="o/r" kit_gc_prune --yes 2>&1)"
|
|
|
209
212
|
t "merged-but-ahead branch survives prune --yes" "$(git branch --list task/43-ahead | wc -l | tr -d ' ')" "1"
|
|
210
213
|
has "prune says why it skipped it" "$out" "unpushed commits"
|
|
211
214
|
|
|
215
|
+
# ── #388: LANDED — no PR of its own, work already on base ──────────────────────────────────────
|
|
216
|
+
# A squash merge rewrites the patch ids, so neither `git cherry` nor `--is-ancestor` can see that
|
|
217
|
+
# a sub branch's work reached base. gc must classify these rows LANDED (not ORPHAN), the plan must
|
|
218
|
+
# list them as their own block, and --yes must delete them — worktree included — while a true
|
|
219
|
+
# orphan (one commit whose content base never received) stays untouched.
|
|
220
|
+
export KIT_BASE_BRANCH="$init_branch"
|
|
221
|
+
# Earlier fixtures that are level with base read as LANDED now (ancestor of base); drop them so the
|
|
222
|
+
# counts below are this section's alone (task/41-open stays PROTECTED, the others ORPHAN).
|
|
223
|
+
git branch -D task/44-behind feat/30-x feat/31-y feat/32-z >/dev/null 2>&1
|
|
224
|
+
git update-ref -d refs/remotes/origin/task/44-behind 2>/dev/null
|
|
225
|
+
# (1) an effort sub, squash-landed: sub/50a commits sub.txt; "the effort PR" lands the same content
|
|
226
|
+
# on base as ONE new commit — check (a), content.
|
|
227
|
+
git checkout -q -b sub/50a-part
|
|
228
|
+
echo "sub work" > sub.txt; git add sub.txt; git commit -qm "sub: part"
|
|
229
|
+
git checkout -q "$init_branch"
|
|
230
|
+
git checkout -q sub/50a-part -- sub.txt; git commit -qm "feat(effort): squash of effort 50"
|
|
231
|
+
# (2) a Claude Code Agent-tool isolation worktree (`worktree-agent-<hash>`), squash-landed too.
|
|
232
|
+
git worktree add -q ../agentwt -b worktree-agent-abc123 >/dev/null 2>&1
|
|
233
|
+
echo "agent work" > ../agentwt/agent.txt; git -C ../agentwt add agent.txt; git -C ../agentwt commit -qm "agent: part"
|
|
234
|
+
git checkout -q worktree-agent-abc123 -- agent.txt; git commit -qm "feat: squash of the agent's work"
|
|
235
|
+
# (3) a second sub whose file base has since CHANGED — content check fails, so only lineage (check
|
|
236
|
+
# b: issue #50 closed + effort/50 PR merged) can land it.
|
|
237
|
+
git checkout -q -b sub/50b-other
|
|
238
|
+
echo "v1" > other.txt; git add other.txt; git commit -qm "sub: other"
|
|
239
|
+
git checkout -q "$init_branch"
|
|
240
|
+
git checkout -q sub/50b-other -- other.txt; git commit -qm "feat(effort): squash of sub 50b"
|
|
241
|
+
echo "v2" > other.txt; git add other.txt; git commit -qm "later change on base"
|
|
242
|
+
# (4) a true orphan: issue #51 is closed but nothing with its content ever reached base.
|
|
243
|
+
git checkout -q -b task/51-orphan
|
|
244
|
+
echo "never landed" > lost.txt; git add lost.txt; git commit -qm "orphan"
|
|
245
|
+
git checkout -q "$init_branch"
|
|
246
|
+
# (5) an agent worktree whose work landed but whose tree is DIRTY — recover-before-prune keeps it.
|
|
247
|
+
git worktree add -q ../agentwt2 -b worktree-agent-def456 >/dev/null 2>&1
|
|
248
|
+
echo "agent two" > ../agentwt2/agent2.txt; git -C ../agentwt2 add agent2.txt; git -C ../agentwt2 commit -qm "agent: two"
|
|
249
|
+
git checkout -q worktree-agent-def456 -- agent2.txt; git commit -qm "feat: squash of agent two"
|
|
250
|
+
echo "uncommitted" > ../agentwt2/scratch.txt
|
|
251
|
+
|
|
252
|
+
cat > "$stub/gh" <<'SH'
|
|
253
|
+
#!/usr/bin/env bash
|
|
254
|
+
case "$1 $2" in
|
|
255
|
+
"pr list") printf 'effort/50-thing\tPR#55 MERGED\n' ;;
|
|
256
|
+
"issue view")
|
|
257
|
+
for a in "$@"; do case "$a" in 41) echo open; exit 0 ;; esac; done
|
|
258
|
+
echo closed ;;
|
|
259
|
+
*) : ;;
|
|
260
|
+
esac
|
|
261
|
+
SH
|
|
262
|
+
chmod +x "$stub/gh"
|
|
263
|
+
|
|
264
|
+
analysis="$(PATH="$stub:$PATH" KIT_GC_REPO="o/r" kit_gc_analyze 2>/dev/null)"
|
|
265
|
+
row() { printf '%s\n' "$analysis" | awk -v b="$1" '$1==b && $2=="->"{sub(/^ [^ ]+ -> /, ""); print; exit}'; }
|
|
266
|
+
has "squash-landed sub is LANDED by content" "$(row sub/50a-part)" "LANDED (content on $init_branch)"
|
|
267
|
+
has "agent worktree branch is LANDED and named" "$(row worktree-agent-abc123)" "LANDED (agent worktree; content on $init_branch)"
|
|
268
|
+
has "sub with later base change is LANDED by lineage" "$(row sub/50b-other)" "LANDED (issue #50 closed, its PR merged)"
|
|
269
|
+
has "true orphan stays ORPHAN" "$(row task/51-orphan)" "ORPHAN"
|
|
270
|
+
has "dirty agent worktree's branch is still LANDED" "$(row worktree-agent-def456)" "LANDED"
|
|
271
|
+
t "has_prunable sees a LANDED row" "$(PATH="$stub:$PATH" KIT_GC_REPO="o/r" kit_gc_has_prunable && echo yes || echo no)" "yes"
|
|
272
|
+
|
|
273
|
+
plan="$(PATH="$stub:$PATH" KIT_GC_REPO="o/r" kit_gc_cleanup 2>&1)"
|
|
274
|
+
has "plan has a LANDED block" "$plan" "LANDED branches"
|
|
275
|
+
t "plan counts the four LANDED rows" \
|
|
276
|
+
"$(printf '%s\n' "$plan" | awk '/^ LANDED branches/{print $3}')" "4"
|
|
277
|
+
has "plan names the sub with its reason" "$plan" "sub/50a-part (content on $init_branch)"
|
|
278
|
+
has "plan names the agent worktree as a worktree" "$plan" "agentwt [worktree-agent-abc123]"
|
|
279
|
+
has "plan flags the dirty agent worktree" "$plan" "agentwt2 [worktree-agent-def456] (DIRTY"
|
|
280
|
+
has "plan keeps the orphan" "$plan" "task/51-orphan"
|
|
281
|
+
# The LANDED block prints BEFORE the ORPHAN block.
|
|
282
|
+
t "LANDED block precedes ORPHAN block" \
|
|
283
|
+
"$(printf '%s\n' "$plan" | awk '/^ LANDED branches/{l=NR} /^ ORPHAN kept/{o=NR} END{print (l<o)?"yes":"no"}')" "yes"
|
|
284
|
+
t "plan-only kept the sub branch" "$(git branch --list sub/50a-part | wc -l | tr -d ' ')" "1"
|
|
285
|
+
[ -d ../agentwt ] && echo "ok: plan-only kept the agent worktree" || { echo "FAIL: plan-only removed the agent worktree"; fail=1; }
|
|
286
|
+
|
|
287
|
+
# kit_gc_prune --only: the scope effort_close uses to collect ONE effort's subs (#388) — the agent
|
|
288
|
+
# branch is also LANDED but outside the glob, so it must survive this pass.
|
|
289
|
+
out="$(PATH="$stub:$PATH" KIT_GC_REPO="o/r" kit_gc_prune --yes --only '^sub/50[a-z]-' 2>&1)"
|
|
290
|
+
t "--only deleted the content-landed sub" "$(git branch --list sub/50a-part | wc -l | tr -d ' ')" "0"
|
|
291
|
+
t "--only deleted the lineage-landed sub" "$(git branch --list sub/50b-other | wc -l | tr -d ' ')" "0"
|
|
292
|
+
t "--only left the agent branch alone" "$(git branch --list worktree-agent-abc123 | wc -l | tr -d ' ')" "1"
|
|
293
|
+
has "prune says why the sub went" "$out" "deleted local branch sub/50a-part (LANDED"
|
|
294
|
+
|
|
295
|
+
applied="$(PATH="$stub:$PATH" KIT_GC_REPO="o/r" kit_gc_cleanup --yes 2>&1)"
|
|
296
|
+
t "--yes deleted the agent branch" "$(git branch --list worktree-agent-abc123 | wc -l | tr -d ' ')" "0"
|
|
297
|
+
[ -d ../agentwt ] && { echo "FAIL: --yes left the agent worktree dir"; fail=1; } || echo "ok: --yes removed the agent worktree"
|
|
298
|
+
t "--yes KEPT the true orphan" "$(git branch --list task/51-orphan | wc -l | tr -d ' ')" "1"
|
|
299
|
+
t "--yes KEPT the dirty agent worktree's branch" "$(git branch --list worktree-agent-def456 | wc -l | tr -d ' ')" "1"
|
|
300
|
+
[ -d ../agentwt2 ] && echo "ok: --yes skipped the dirty agent worktree" || { echo "FAIL: --yes destroyed a dirty worktree"; fail=1; }
|
|
301
|
+
has "cleanup said why it skipped the dirty one" "$applied" "SKIP dirty worktree"
|
|
302
|
+
has "cleanup counts what it landed" "$applied" "landed deleted"
|
|
303
|
+
|
|
304
|
+
# ── lineage when the closing PR is OUTSIDE the 200-PR index window ─────────────────────────────
|
|
305
|
+
# Measured on a consuming repo: the effort PR that closed the issue sat at position 254 of `gh pr list --state all`, so the
|
|
306
|
+
# index never carried it and 21 `worktree-agent-*` branches with `[#2165]` subjects stayed ORPHAN
|
|
307
|
+
# while base had changed their files again (content check fails too). The issue itself knows which
|
|
308
|
+
# PR closed it (`closedByPullRequestsReferences`), exact and not window-bound. Cached per issue: the
|
|
309
|
+
# two branches below both name #60 and must cost ONE `issue view … closedBy` call.
|
|
310
|
+
git checkout -q -b sub/60a-old
|
|
311
|
+
echo "old sub" > old.txt; git add old.txt; git commit -qm "sub: old"
|
|
312
|
+
git checkout -q "$init_branch"
|
|
313
|
+
git checkout -q sub/60a-old -- old.txt; git commit -qm "feat(effort): squash of effort 60"
|
|
314
|
+
echo "changed again" > old.txt; git add old.txt; git commit -qm "later change on base"
|
|
315
|
+
git checkout -q -b worktree-agent-old777
|
|
316
|
+
echo "agent old" > agentold.txt; git add agentold.txt; git commit -qm "feat: agent part [#60]"
|
|
317
|
+
git checkout -q "$init_branch"
|
|
318
|
+
git checkout -q worktree-agent-old777 -- agentold.txt; git commit -qm "squash of the agent's part"
|
|
319
|
+
echo "changed again" > agentold.txt; git add agentold.txt; git commit -qm "later change on base"
|
|
320
|
+
cat > "$stub/gh" <<'SH'
|
|
321
|
+
#!/usr/bin/env bash
|
|
322
|
+
echo "$*" >> "$GH_CALLS"
|
|
323
|
+
case "$1 $2" in
|
|
324
|
+
"pr list") printf 'effort/50-thing\tPR#55 MERGED\n' ;; # nothing for #60: scrolled out
|
|
325
|
+
"issue view")
|
|
326
|
+
case "$*" in
|
|
327
|
+
*closedByPullRequestsReferences*) for a in "$@"; do case "$a" in 60) echo 61; exit 0 ;; esac; done ;;
|
|
328
|
+
*) echo closed ;;
|
|
329
|
+
esac ;;
|
|
330
|
+
"pr view") for a in "$@"; do case "$a" in 61) echo MERGED; exit 0 ;; esac; done; echo CLOSED ;;
|
|
331
|
+
*) : ;;
|
|
332
|
+
esac
|
|
333
|
+
SH
|
|
334
|
+
chmod +x "$stub/gh"
|
|
335
|
+
: > "$GH_CALLS"
|
|
336
|
+
analysis="$(PATH="$stub:$PATH" KIT_GC_REPO="o/r" kit_gc_analyze 2>/dev/null)"
|
|
337
|
+
has "sub landed via the issue's closing PR" "$(row sub/60a-old)" "LANDED (issue #60 closed by merged PR#61)"
|
|
338
|
+
has "agent branch with [#60] subject landed too" "$(row worktree-agent-old777)" "LANDED (agent worktree; issue #60 closed by merged PR#61)"
|
|
339
|
+
t "the closedBy lookup ran ONCE for #60 across both branches" \
|
|
340
|
+
"$(grep -c 'issue view 60 .*closedByPullRequestsReferences' "$GH_CALLS")" "1"
|
|
341
|
+
t "the PR state was confirmed ONCE" "$(grep -c '^pr view 61' "$GH_CALLS")" "1"
|
|
342
|
+
# A fresh run must not trust the previous run's cache (the issue could have been reopened).
|
|
343
|
+
: > "$GH_CALLS"
|
|
344
|
+
PATH="$stub:$PATH" KIT_GC_REPO="o/r" kit_gc_prune >/dev/null 2>&1
|
|
345
|
+
t "a new run looks the issue up again" "$(grep -c 'issue view 60 .*closedByPullRequestsReferences' "$GH_CALLS")" "1"
|
|
346
|
+
|
|
347
|
+
# ── `(#N)` subjects + a sub-issue closed through its parent's PR ──────────────────────────────
|
|
348
|
+
# Measured on a consuming repo: agent branches whose subjects end in `(#N)` — GitHub's own trailing ref,
|
|
349
|
+
# not the kit's `[#N]` — where #2077 is a sub-issue: CLOSED, no closing PR (subs close through
|
|
350
|
+
# `effort close`), parent #2075 closed by merged PR 2130. One climb to the parent lands it.
|
|
351
|
+
# effort/1711: closed NOT_PLANNED, no PR, no parent — must stay ORPHAN.
|
|
352
|
+
git checkout -q -b worktree-agent-sub70
|
|
353
|
+
echo "ontology" > onto.txt; git add onto.txt; git commit -qm "Root vocabulary: classes and predicates (#70)"
|
|
354
|
+
git checkout -q "$init_branch"
|
|
355
|
+
git checkout -q worktree-agent-sub70 -- onto.txt; git commit -qm "squash of the ontology effort"
|
|
356
|
+
echo "changed again" > onto.txt; git add onto.txt; git commit -qm "later change on base"
|
|
357
|
+
git checkout -q -b effort/80-not-planned
|
|
358
|
+
echo "abandoned" > np.txt; git add np.txt; git commit -qm "[Effort 80] 1 · never landed"
|
|
359
|
+
git checkout -q "$init_branch"
|
|
360
|
+
cat > "$stub/gh" <<'SH'
|
|
361
|
+
#!/usr/bin/env bash
|
|
362
|
+
echo "$*" >> "$GH_CALLS"
|
|
363
|
+
case "$1 $2" in
|
|
364
|
+
"pr list") printf 'effort/50-thing\tPR#55 MERGED\n' ;;
|
|
365
|
+
"issue view")
|
|
366
|
+
case "$*" in
|
|
367
|
+
*closedByPullRequestsReferences*) for a in "$@"; do case "$a" in 75) echo 76; exit 0 ;; esac; done ;; # 70, 80: nothing
|
|
368
|
+
*) echo closed ;;
|
|
369
|
+
esac ;;
|
|
370
|
+
"pr view") for a in "$@"; do case "$a" in 76) echo MERGED; exit 0 ;; esac; done; echo CLOSED ;;
|
|
371
|
+
"api repos/o/r/issues/70/parent") echo 75 ;;
|
|
372
|
+
"api repos/o/r/issues/80/parent") echo "gh: Not Found (HTTP 404)" >&2; exit 1 ;;
|
|
373
|
+
*) : ;;
|
|
374
|
+
esac
|
|
375
|
+
SH
|
|
376
|
+
chmod +x "$stub/gh"
|
|
377
|
+
: > "$GH_CALLS"
|
|
378
|
+
analysis="$(PATH="$stub:$PATH" KIT_GC_REPO="o/r" kit_gc_analyze 2>/dev/null)"
|
|
379
|
+
has "(#N) subject lands through the parent's merged PR" "$(row worktree-agent-sub70)" \
|
|
380
|
+
"LANDED (agent worktree; issue #70 closed, parent #75 closed by merged PR#76)"
|
|
381
|
+
has "closed NOT_PLANNED with no PR and no parent stays ORPHAN" "$(row effort/80-not-planned)" "ORPHAN"
|
|
382
|
+
t "the parent was climbed once for #70" "$(grep -c '^api repos/o/r/issues/70/parent' "$GH_CALLS")" "1"
|
|
383
|
+
t "the parent lookup for #80 ran once and was cached as a miss" "$(grep -c '^api repos/o/r/issues/80/parent' "$GH_CALLS")" "1"
|
|
384
|
+
applied="$(PATH="$stub:$PATH" KIT_GC_REPO="o/r" kit_gc_prune --yes --only '^(worktree-agent-sub70|effort/80-)' 2>&1)"
|
|
385
|
+
t "--yes deleted the parent-landed agent branch" "$(git branch --list worktree-agent-sub70 | wc -l | tr -d ' ')" "0"
|
|
386
|
+
t "--yes KEPT the not-planned effort branch" "$(git branch --list effort/80-not-planned | wc -l | tr -d ' ')" "1"
|
|
387
|
+
unset KIT_BASE_BRANCH
|
|
388
|
+
|
|
212
389
|
[ "$fail" -eq 0 ] && echo "ALL OK (kit-gc)" || echo "kit-gc: FAILURES"
|
|
213
390
|
exit "$fail"
|