@cratis/pi 8.1.0 → 8.2.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/package/corpus/harnesses/copilot/instructions/local-work-artifacts.instructions.md +4 -1
- package/package/corpus/hooks/README.md +12 -1
- package/package/corpus/hooks/scripts/cratis-cleanup-worktrees.sh +109 -6
- package/package/corpus/hooks/scripts/cratis-guard-shell-writes.sh +1 -1
- package/package/corpus/rules/local-work-artifacts.md +4 -1
- package/package/corpus/skills/cratis-orchestration-lanes/references/worktrees.md +1 -0
- package/package.json +1 -1
|
@@ -49,7 +49,10 @@ dumps, and similar coordination files. These are **work records, not documentati
|
|
|
49
49
|
pushed is not merged — and never forces. It keeps worktrees with non-empty `.ai-work/`
|
|
50
50
|
directories; manual `--include-work-records=<path>` lifts that for that worktree only;
|
|
51
51
|
hooks never opt in. Ignored or untracked files, a live process using it, or a failed holder
|
|
52
|
-
check keep a worktree. `git worktree lock <path>` pins one: locked worktrees are always kept.
|
|
52
|
+
check keep a worktree. `git worktree lock <path>` pins one: locked worktrees are always kept.
|
|
53
|
+
A worktree costs its build output (gigabytes of `bin/obj`, `node_modules`): one per deliverable task,
|
|
54
|
+
reuse idle ones, build only what you changed. The script also deletes idle worktrees' build output
|
|
55
|
+
(`--no-reclaim` opts out). Do not hand-remove worktrees
|
|
53
56
|
or `git branch -D` a delivered branch when the script can; `gh pr merge --delete-branch`
|
|
54
57
|
inside a worktree leaves the worktree and branch behind. If the branch must outlive the task
|
|
55
58
|
unmerged, leave the worktree and say so in the handoff. Never `--force` a removal; a
|
|
@@ -94,7 +94,7 @@ program (conservative: `$1 > 5` is refused); a word-leading `*` or `?` glob is a
|
|
|
94
94
|
option can still change what those print, never what they write; and exactly
|
|
95
95
|
`node .cratis/ai/hooks/scripts/cratis-check-pr.mjs` (options `--body-file`, `--label`, `--add-label`,
|
|
96
96
|
`--remove-label`, `--pr`, `--base`, `--repo` with a plain value, and `--strict`) and
|
|
97
|
-
`bash .cratis/ai/hooks/scripts/cratis-cleanup-worktrees.sh` (`--dry-run`, `--quiet`, `--no-fetch`) may
|
|
97
|
+
`bash .cratis/ai/hooks/scripts/cratis-cleanup-worktrees.sh` (`--dry-run`, `--quiet`, `--no-fetch`, `--reclaim`, `--no-reclaim`) may
|
|
98
98
|
run: the path must match as one literal word (no `./`, `..`, absolute, variable or glob spelling), nothing
|
|
99
99
|
is admitted after a `cd`, and writes to those files stay refused. The working directory decides which
|
|
100
100
|
copy runs. A write-target word with expansion syntax (`$`, backtick, `~`, parentheses or braces) is judged by every
|
|
@@ -347,6 +347,17 @@ first. Non-empty `.ai-work/` directories, even when tracked, are additionally ke
|
|
|
347
347
|
no GitHub call, abort, or failed-attempt marker.
|
|
348
348
|
- **Pin a long-lived worktree.** Use `git worktree lock <path>` to keep it out of cleanup; release the
|
|
349
349
|
pin with `git worktree unlock <path>` when ready.
|
|
350
|
+
- **Reclaiming build output.** A worktree's weight is its build output (`bin/` and `obj/` per .NET project, `node_modules`,
|
|
351
|
+
`dist`), not its source, and that output used to pin worktrees forever as "has ignored/untracked files". Now (1) a
|
|
352
|
+
delivered worktree has its regenerable output deleted so it can be removed, and (2) with `--reclaim` (the default for
|
|
353
|
+
manual runs and `SessionStart`; the per-command `PostToolUse` hook skips it) the same output is deleted from every other
|
|
354
|
+
linked worktree that is **idle** (no file or git metadata changed for `CRATIS_RECLAIM_IDLE_MINUTES`, default 60),
|
|
355
|
+
unlocked, and not held by a live process, even when its work is undelivered. Only directories that are git-ignored, fully
|
|
356
|
+
untracked, not symlinks and named `bin`, `obj`, `node_modules`, `dist`, `build`, `out`, `coverage`, `TestResults`,
|
|
357
|
+
`target`, `_build`, `.vite`, `.next`, `.nuxt`, `.turbo`, `.nx`, `.angular`, `.parcel-cache`, `.gradle`, `.venv` or
|
|
358
|
+
`__pycache__` are deleted. Source, commits, branches, work records, `.env` and any other ignored file stay; the next
|
|
359
|
+
build recreates the output. `--dry-run` reports the megabytes reclaimable; `--no-reclaim` or
|
|
360
|
+
`CRATIS_HOOKS_SKIP_RECLAIM=1` disables it; a hook run stops starting new worktrees after about 45 seconds.
|
|
350
361
|
- **Self-test.** `--self-test` plants delivered, dirty, unmerged, brand-new, work-record and locked cases
|
|
351
362
|
(including detached locks), checks manual opt-in and hook protection, and fails if any is handled wrongly.
|
|
352
363
|
- **Opt out.** `CRATIS_HOOKS_SKIP_CLEANUP=1`.
|
|
@@ -20,8 +20,20 @@
|
|
|
20
20
|
# Missing, failed, unparseable or ambiguous checks keep the worktree (including shared-inode names).
|
|
21
21
|
# `git worktree remove` is never given --force.
|
|
22
22
|
#
|
|
23
|
+
# Disk is reclaimed in two ways, because a worktree's weight is its build output, not its source:
|
|
24
|
+
# * A delivered worktree whose only ignored files are regenerable build output (bin, obj,
|
|
25
|
+
# node_modules, dist, ...) has that output deleted first, so it can then be removed. Without this
|
|
26
|
+
# step every worktree that was ever built was kept forever as "has ignored/untracked files".
|
|
27
|
+
# * With --reclaim (the default for manual runs and SessionStart) the same regenerable output is
|
|
28
|
+
# deleted from every OTHER linked worktree that is idle, unlocked and not held by a live process,
|
|
29
|
+
# including worktrees whose work is not delivered. Source, commits, branches, stashes, work
|
|
30
|
+
# records and every non-regenerable ignored file stay; the next build recreates the output.
|
|
31
|
+
# Idle = nothing touched in CRATIS_RECLAIM_IDLE_MINUTES (default 60). Only ignored, untracked
|
|
32
|
+
# directories with a well-known build-output name are ever deleted. Opt out: --no-reclaim or
|
|
33
|
+
# CRATIS_HOOKS_SKIP_RECLAIM=1.
|
|
34
|
+
#
|
|
23
35
|
# Usage:
|
|
24
|
-
# cratis-cleanup-worktrees.sh [--dry-run] [--quiet] [--no-fetch] [--include-work-records=<path>]...
|
|
36
|
+
# cratis-cleanup-worktrees.sh [--dry-run] [--quiet] [--no-fetch] [--no-reclaim] [--include-work-records=<path>]...
|
|
25
37
|
# run in the repository (any worktree)
|
|
26
38
|
# --include-work-records=<path> bypass record preservation for this
|
|
27
39
|
# exact worktree only; repeatable, manual
|
|
@@ -37,10 +49,10 @@
|
|
|
37
49
|
# shellcheck disable=SC2016 # the self-test checks are single-quoted on purpose: they are eval-ed later
|
|
38
50
|
set -uo pipefail
|
|
39
51
|
|
|
40
|
-
DRY=0; QUIET=0; FETCH=1; HOOK=0; SELFTEST=0; WORK_RECORD_PATHS=()
|
|
52
|
+
DRY=0; QUIET=0; FETCH=1; HOOK=0; SELFTEST=0; RECLAIM=''; WORK_RECORD_PATHS=()
|
|
41
53
|
for a in "$@"; do
|
|
42
54
|
case "$a" in
|
|
43
|
-
--dry-run) DRY=1 ;; --quiet) QUIET=1 ;; --no-fetch) FETCH=0 ;;
|
|
55
|
+
--dry-run) DRY=1 ;; --quiet) QUIET=1 ;; --no-fetch) FETCH=0 ;; --reclaim) RECLAIM=1 ;; --no-reclaim) RECLAIM=0 ;;
|
|
44
56
|
--hook) HOOK=1; QUIET=1 ;; --self-test) SELFTEST=1 ;;
|
|
45
57
|
--include-work-records|--include-work-records=)
|
|
46
58
|
echo "cratis-cleanup-worktrees: --include-work-records requires an explicit worktree path (--include-work-records=<path>)" >&2; exit 2 ;;
|
|
@@ -71,6 +83,14 @@ if [ "$HOOK" = 1 ]; then
|
|
|
71
83
|
if [ -n "$cwd" ] && [ -d "$cwd" ]; then cd "$cwd" || exit 0; fi
|
|
72
84
|
fi
|
|
73
85
|
[ "${CRATIS_HOOKS_SKIP_CLEANUP:-}" = 1 ] && [ "$SELFTEST" = 0 ] && exit 0
|
|
86
|
+
# Reclaiming build output from idle worktrees costs a process scan per candidate: manual runs and
|
|
87
|
+
# SessionStart do it, the per-command PostToolUse hook does not.
|
|
88
|
+
if [ -z "$RECLAIM" ]; then
|
|
89
|
+
if [ "$HOOK" = 1 ] && [ "$EVENT" != "SessionStart" ]; then RECLAIM=0; else RECLAIM=1; fi
|
|
90
|
+
fi
|
|
91
|
+
[ "${CRATIS_HOOKS_SKIP_RECLAIM:-}" = 1 ] && RECLAIM=0
|
|
92
|
+
IDLE_MINUTES=${CRATIS_RECLAIM_IDLE_MINUTES:-60}
|
|
93
|
+
[[ "$IDLE_MINUTES" =~ ^[0-9]+$ ]] || IDLE_MINUTES=60
|
|
74
94
|
|
|
75
95
|
# ── Self-test ─────────────────────────────────────────────────────────────────
|
|
76
96
|
if [ "$SELFTEST" = 1 ]; then
|
|
@@ -88,8 +108,9 @@ if [ "$SELFTEST" = 1 ]; then
|
|
|
88
108
|
mk delivered; (cd "$t/wt-delivered" && echo d > d && git add d && git commit -qm d)
|
|
89
109
|
mk dirty; (cd "$t/wt-dirty" && echo x > x && git add x && git commit -qm x)
|
|
90
110
|
mk unmerged; (cd "$t/wt-unmerged" && echo u > u && git add u && git commit -qm u)
|
|
111
|
+
(cd "$t/wt-unmerged" && mkdir obj && echo k > obj/keep && git add -f obj/keep && git commit -qm keep)
|
|
91
112
|
mk fresh # brand new, no commits: must survive
|
|
92
|
-
for b in records empty-records locked locked-detached tracked-records scoped-records ignored live-holder; do
|
|
113
|
+
for b in built records empty-records locked locked-detached tracked-records scoped-records ignored live-holder; do
|
|
93
114
|
mk "$b"; (cd "$t/wt-$b" && echo "$b" > "$b" && git add "$b" && git commit -qm "$b")
|
|
94
115
|
case "$b" in
|
|
95
116
|
tracked-records|scoped-records)
|
|
@@ -99,7 +120,10 @@ if [ "$SELFTEST" = 1 ]; then
|
|
|
99
120
|
git merge -q --no-ff "$b" -m "merge $b"
|
|
100
121
|
done
|
|
101
122
|
mkdir "$t/wt-records/.ai-work" "$t/wt-empty-records/.ai-work"
|
|
102
|
-
printf '.ai-work/\nignored-output\n' >> "$t/repo/.git/info/exclude"
|
|
123
|
+
printf '.ai-work/\nignored-output\nbin/\nobj/\nnode_modules/\n' >> "$t/repo/.git/info/exclude"
|
|
124
|
+
mkdir -p "$t/wt-built/bin/Debug" "$t/wt-unmerged/bin" "$t/wt-unmerged/node_modules/pkg" "$t/wt-unmerged/obj" "$t/wt-live-holder/bin" "$t/repo/bin"
|
|
125
|
+
echo b > "$t/wt-built/bin/Debug/a.dll"; echo o > "$t/wt-unmerged/bin/o.dll"; echo n > "$t/wt-unmerged/node_modules/pkg/i.js"
|
|
126
|
+
echo j > "$t/wt-unmerged/obj/junk"; echo h > "$t/wt-live-holder/bin/h.dll"; echo m > "$t/repo/bin/m.dll"
|
|
103
127
|
echo handoff > "$t/wt-records/.ai-work/.handoff"
|
|
104
128
|
echo build > "$t/wt-ignored/ignored-output"
|
|
105
129
|
(cd "$t/wt-live-holder" && exec sleep 120) & holder=$!
|
|
@@ -133,8 +157,24 @@ if [ "$SELFTEST" = 1 ]; then
|
|
|
133
157
|
chk "locked detached reported" 'grep -Fq "worktree $t/wt-locked-detached (detached): locked" <<<"$out"'
|
|
134
158
|
chk "live holder kept" '[ -d "$t/wt-live-holder" ]'
|
|
135
159
|
chk "live holder reason reported" 'grep -F "worktree $t/wt-live-holder (live-holder):" <<<"$out" | grep -E ": (live holder|live process)" >/dev/null'
|
|
160
|
+
chk "built delivered worktree removed" '[ ! -d "$t/wt-built" ]'
|
|
161
|
+
chk "built delivered branch removed" '! git rev-parse -q --verify refs/heads/built >/dev/null'
|
|
162
|
+
chk "fresh worktree output kept" '[ -f "$t/wt-unmerged/bin/o.dll" ] && [ -f "$t/wt-unmerged/node_modules/pkg/i.js" ]'
|
|
136
163
|
chk "ignored file kept" '[ -f "$t/wt-ignored/ignored-output" ]'
|
|
137
164
|
chk "ignored file reason" 'grep -Fq "has ignored/untracked files; archive or remove them first" <<<"$out"'
|
|
165
|
+
out=$(CRATIS_RECLAIM_IDLE_MINUTES=0 "$self" --no-fetch --dry-run 2>&1) || { echo "FAIL: reclaim dry-run exit $?"; echo "$out"; exit 1; }
|
|
166
|
+
chk "reclaim dry-run reports" 'grep -Fq "would reclaim" <<<"$out"'
|
|
167
|
+
chk "reclaim dry-run deletes none" '[ -f "$t/wt-unmerged/bin/o.dll" ]'
|
|
168
|
+
out=$(CRATIS_RECLAIM_IDLE_MINUTES=0 "$self" --no-fetch --no-reclaim 2>&1) || { echo "FAIL: no-reclaim exit $?"; echo "$out"; exit 1; }
|
|
169
|
+
chk "no-reclaim deletes none" '[ -f "$t/wt-unmerged/bin/o.dll" ]'
|
|
170
|
+
out=$(CRATIS_RECLAIM_IDLE_MINUTES=0 "$self" --no-fetch 2>&1) || { echo "FAIL: reclaim exit $?"; echo "$out"; exit 1; }
|
|
171
|
+
chk "idle build output reclaimed" '[ ! -d "$t/wt-unmerged/bin" ] && [ ! -d "$t/wt-unmerged/node_modules" ]'
|
|
172
|
+
chk "reclaim keeps source" '[ -f "$t/wt-unmerged/u" ] && [ -d "$t/wt-unmerged" ]'
|
|
173
|
+
chk "reclaim keeps tracked output" '[ -f "$t/wt-unmerged/obj/keep" ]'
|
|
174
|
+
chk "reclaim keeps main output" '[ -f "$t/repo/bin/m.dll" ]'
|
|
175
|
+
chk "reclaim skips live holder" '[ -f "$t/wt-live-holder/bin/h.dll" ]'
|
|
176
|
+
chk "reclaim keeps other ignored" '[ -f "$t/wt-ignored/ignored-output" ]'
|
|
177
|
+
chk "reclaim is reported" 'grep -Fq "reclaimed $t/wt-unmerged" <<<"$out"'
|
|
138
178
|
out=$("$self" --no-fetch --dry-run 2>&1) || { echo "FAIL: dry-run exit $?"; echo "$out"; exit 1; }
|
|
139
179
|
chk "dry-run reports live holder" 'grep -F "kept worktree $t/wt-live-holder (live-holder):" <<<"$out" | grep -E ": (live holder|live process)" >/dev/null'
|
|
140
180
|
out=$(printf '%s' '{"hook_event_name":"SessionStart"}' | "$self" --no-fetch "--include-work-records=$t/wt-tracked-records" --hook 2>&1) || { echo "FAIL: hook exit $?"; echo "$out"; exit 1; }
|
|
@@ -450,6 +490,45 @@ worktree_clean() {
|
|
|
450
490
|
if [ -n "$status" ]; then note_kept "worktree $wt ($name): delivered but has uncommitted changes"; return 1; fi
|
|
451
491
|
return 0
|
|
452
492
|
}
|
|
493
|
+
# ── Reclaim regenerable build output ──────────────────────────────────────────
|
|
494
|
+
# Only directories that are git-ignored, untracked in full, not symlinks and named like build output.
|
|
495
|
+
RECLAIM_NAMES='^(bin|obj|node_modules|dist|build|out|coverage|TestResults|_build|target|\.vite|\.next|\.nuxt|\.turbo|\.nx|\.angular|\.parcel-cache|\.gradle|\.venv|__pycache__)$'
|
|
496
|
+
RECLAIM_HELD=0; RECLAIMED=(); RECLAIMED_KB=0; RECLAIMED_PATHS=$'\n'
|
|
497
|
+
RECLAIM_DEADLINE=$(( $(date +%s) + $([ "$HOOK" = 1 ] && echo 45 || echo 900) ))
|
|
498
|
+
# Idle: no git metadata and no file outside node_modules changed within the window. Build output counts
|
|
499
|
+
# as activity, so a worktree someone just built or tested in is left alone.
|
|
500
|
+
worktree_idle() {
|
|
501
|
+
local w="$1" gd
|
|
502
|
+
[ "$IDLE_MINUTES" -gt 0 ] || return 0
|
|
503
|
+
gd=$(git -C "$w" rev-parse --absolute-git-dir 2>/dev/null) || return 1
|
|
504
|
+
[ -z "$(find "$gd/HEAD" "$gd/index" "$gd/logs/HEAD" -mmin "-$IDLE_MINUTES" -print -quit 2>/dev/null)" ] || return 1
|
|
505
|
+
[ -z "$(find "$w" -name node_modules -prune -o -type f -mmin "-$IDLE_MINUTES" -print -quit 2>/dev/null)" ]
|
|
506
|
+
}
|
|
507
|
+
reclaim_worktree() {
|
|
508
|
+
local w="$1" label="$2" force="${3:-0}" p kb total=0 names='' dirs=() abs
|
|
509
|
+
[ "$RECLAIM" = 1 ] && [ -d "$w" ] || return 0
|
|
510
|
+
case "$RECLAIMED_PATHS" in *$'\n'"$w"$'\n'*) return 0 ;; esac
|
|
511
|
+
[ "$(date +%s)" -lt "$RECLAIM_DEADLINE" ] || return 0
|
|
512
|
+
[ "$force" = 1 ] || worktree_idle "$w" || return 0
|
|
513
|
+
while IFS= read -r -d '' p; do
|
|
514
|
+
p=${p%/}
|
|
515
|
+
[[ -n "$p" && "${p##*/}" =~ $RECLAIM_NAMES ]] || continue
|
|
516
|
+
abs="$w/$p"
|
|
517
|
+
[ -d "$abs" ] && [ ! -L "$abs" ] || continue
|
|
518
|
+
[ -z "$(git -C "$w" ls-files -- "$p" 2>/dev/null | head -n 1)" ] || continue
|
|
519
|
+
dirs+=("$p")
|
|
520
|
+
done < <(git -C "$w" ls-files -z --others --ignored --exclude-standard --directory 2>/dev/null)
|
|
521
|
+
[ "${#dirs[@]}" -gt 0 ] || return 0
|
|
522
|
+
if ! check_holders "$w"; then RECLAIM_HELD=1; return 0; fi
|
|
523
|
+
for p in "${dirs[@]}"; do
|
|
524
|
+
kb=$(du -sk "$w/$p" 2>/dev/null | awk '{print $1}'); total=$((total + ${kb:-0}))
|
|
525
|
+
case "$names " in *" ${p##*/} "*) ;; *) names="$names ${p##*/}" ;; esac
|
|
526
|
+
done
|
|
527
|
+
RECLAIMED_PATHS="$RECLAIMED_PATHS$w"$'\n'
|
|
528
|
+
if [ "$DRY" = 1 ]; then RECLAIMED+=("$w ($label): would reclaim $((total / 1024)) MB (${#dirs[@]} dirs:$names)"); RECLAIMED_KB=$((RECLAIMED_KB + total)); return 0; fi
|
|
529
|
+
for p in "${dirs[@]}"; do rm -rf -- "${w:?}/$p" 2>/dev/null; done
|
|
530
|
+
RECLAIMED_KB=$((RECLAIMED_KB + total)); RECLAIMED+=("$w ($label): $((total / 1024)) MB build output (${#dirs[@]} dirs:$names)")
|
|
531
|
+
}
|
|
453
532
|
execute_worktree() {
|
|
454
533
|
local name="${br:-detached}" ev="$1" current
|
|
455
534
|
current=$(git -C "$wt" rev-parse HEAD 2>/dev/null) || return 0
|
|
@@ -461,6 +540,8 @@ execute_worktree() {
|
|
|
461
540
|
fi
|
|
462
541
|
if [ -n "$records" ]; then note_kept "worktree $wt ($name): has work records (.ai-work/)"; return 0; fi
|
|
463
542
|
fi
|
|
543
|
+
RECLAIM_HELD=0; reclaim_worktree "$wt" "$name" 1
|
|
544
|
+
if [ "$RECLAIM_HELD" = 1 ]; then note_kept "worktree $wt ($name): $HOLDER_REASON"; return 0; fi
|
|
464
545
|
worktree_clean || return 0
|
|
465
546
|
local kb; kb=$(du -sk "$wt" 2>/dev/null | awk '{print $1}')
|
|
466
547
|
if ! check_holders "$wt"; then note_kept "worktree $wt ($name): $HOLDER_REASON"; return 0; fi
|
|
@@ -524,12 +605,33 @@ for ((i=0; i<${#PLAN_KIND[@]}; i++)); do
|
|
|
524
605
|
else note_kept "branch $br: git refused to delete it"; fi
|
|
525
606
|
done
|
|
526
607
|
|
|
608
|
+
# ── Reclaim build output from the worktrees that stay ─────────────────────────
|
|
609
|
+
reclaim_entry() {
|
|
610
|
+
[ -n "$rwt" ] || return 0
|
|
611
|
+
if [ "$rfirst" = 1 ]; then rfirst=0; return 0; fi
|
|
612
|
+
[ "$rlocked" = 0 ] || return 0
|
|
613
|
+
case "$here/" in "$rwt"/*) return 0 ;; esac
|
|
614
|
+
reclaim_worktree "$rwt" "$rbr" 0
|
|
615
|
+
}
|
|
616
|
+
if [ "$RECLAIM" = 1 ]; then
|
|
617
|
+
rwt=''; rbr=''; rlocked=0; rfirst=1
|
|
618
|
+
while IFS= read -r line; do
|
|
619
|
+
case "$line" in
|
|
620
|
+
"worktree "*) reclaim_entry; rwt=${line#worktree }; rbr=''; rlocked=0 ;;
|
|
621
|
+
"branch "*) rbr=${line#branch refs/heads/} ;;
|
|
622
|
+
"locked"*) rlocked=1 ;;
|
|
623
|
+
esac
|
|
624
|
+
done < <(git worktree list --porcelain; echo)
|
|
625
|
+
reclaim_entry
|
|
626
|
+
fi
|
|
627
|
+
|
|
527
628
|
# ── Report ────────────────────────────────────────────────────────────────────
|
|
528
629
|
summary="cratis-cleanup-worktrees: ${#REMOVED[@]} removed, ${#KEPT[@]} kept"
|
|
529
630
|
[ "$FREED_KB" -gt 0 ] && summary="$summary, $((FREED_KB / 1024)) MB freed"
|
|
631
|
+
[ "${#RECLAIMED[@]}" -gt 0 ] && summary="$summary, $((RECLAIMED_KB / 1024)) MB build output $([ "$DRY" = 1 ] && echo reclaimable || echo reclaimed) from ${#RECLAIMED[@]} worktrees"
|
|
530
632
|
[ "${LOG_NOFETCH:-0}" = 1 ] && summary="$summary (fetch failed: compared against the last fetched $default)"
|
|
531
633
|
if [ "$HOOK" = 1 ]; then
|
|
532
|
-
[ "${#REMOVED[@]}" -gt 0 ] || { [ "$EVENT" = "SessionStart" ] && [ "${#KEPT[@]}" -gt 0 ]; } || exit 0
|
|
634
|
+
[ "${#REMOVED[@]}" -gt 0 ] || [ "${#RECLAIMED[@]}" -gt 0 ] || { [ "$EVENT" = "SessionStart" ] && [ "${#KEPT[@]}" -gt 0 ]; } || exit 0
|
|
533
635
|
msg="$summary."
|
|
534
636
|
[ "${#KEPT[@]}" -gt 0 ] && msg="$msg Kept (not delivered or not safe to remove): $(printf '%s; ' "${KEPT[@]}")"
|
|
535
637
|
command -v jq >/dev/null 2>&1 && jq -nc --arg m "$msg" --arg e "$EVENT" '{systemMessage:$m,hookSpecificOutput:{hookEventName:$e,additionalContext:$m}}' || printf '%s\n' "$msg" >&2
|
|
@@ -538,6 +640,7 @@ fi
|
|
|
538
640
|
if [ "$QUIET" = 0 ]; then
|
|
539
641
|
echo "$summary"
|
|
540
642
|
for r in "${REMOVED[@]+"${REMOVED[@]}"}"; do echo " removed $r"; done
|
|
643
|
+
for r in "${RECLAIMED[@]+"${RECLAIMED[@]}"}"; do echo " reclaimed $r"; done
|
|
541
644
|
for k in "${KEPT[@]+"${KEPT[@]}"}"; do echo " kept $k"; done
|
|
542
645
|
fi
|
|
543
646
|
exit 0
|
|
@@ -517,7 +517,7 @@ function managed_script( i) {
|
|
|
517
517
|
return 1
|
|
518
518
|
}
|
|
519
519
|
if (W[1] == "bash" && W[2] == ".cratis/ai/hooks/scripts/cratis-cleanup-worktrees.sh") {
|
|
520
|
-
for (i = 3; i <= argc; i++) if (W[i] !~ /^--(dry-run|quiet|no-fetch)$/) return 0
|
|
520
|
+
for (i = 3; i <= argc; i++) if (W[i] !~ /^--(dry-run|quiet|no-fetch|reclaim|no-reclaim)$/) return 0
|
|
521
521
|
return 1
|
|
522
522
|
}
|
|
523
523
|
return 0
|
|
@@ -48,7 +48,10 @@ dumps, and similar coordination files. These are **work records, not documentati
|
|
|
48
48
|
pushed is not merged — and never forces. It keeps worktrees with non-empty `.ai-work/`
|
|
49
49
|
directories; manual `--include-work-records=<path>` lifts that for that worktree only;
|
|
50
50
|
hooks never opt in. Ignored or untracked files, a live process using it, or a failed holder
|
|
51
|
-
check keep a worktree. `git worktree lock <path>` pins one: locked worktrees are always kept.
|
|
51
|
+
check keep a worktree. `git worktree lock <path>` pins one: locked worktrees are always kept.
|
|
52
|
+
A worktree costs its build output (gigabytes of `bin/obj`, `node_modules`): one per deliverable task,
|
|
53
|
+
reuse idle ones, build only what you changed. The script also deletes idle worktrees' build output
|
|
54
|
+
(`--no-reclaim` opts out). Do not hand-remove worktrees
|
|
52
55
|
or `git branch -D` a delivered branch when the script can; `gh pr merge --delete-branch`
|
|
53
56
|
inside a worktree leaves the worktree and branch behind. If the branch must outlive the task
|
|
54
57
|
unmerged, leave the worktree and say so in the handoff. Never `--force` a removal; a
|
|
@@ -7,4 +7,5 @@
|
|
|
7
7
|
notes under `<work-root>` (the ignored `.ai-work` directory or a folder inside it).
|
|
8
8
|
- Never rewrite history, force-remove a worktree or delete another lane's
|
|
9
9
|
branch.
|
|
10
|
+
- A worktree costs its build output, not its source (gigabytes of `bin`, `obj`, `node_modules`). Build only the projects the lane changed, and let `cratis-cleanup-worktrees.sh` reclaim an idle lane's output.
|
|
10
11
|
- Run builds and tests only through the gate command in the brief.
|