@cratis/pi 8.10.0 → 8.10.2

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.
@@ -297,13 +297,13 @@ workflows; this slice neither provides full hook parity nor completes Codex inte
297
297
 
298
298
  ## Cleanup of delivered work
299
299
 
300
- `scripts/cratis-cleanup-worktrees.sh` is the one place that removes linked worktrees and local
301
- branches after their work shipped; worktrees pile up otherwise (`gh pr merge --delete-branch`
302
- cannot delete a branch that a worktree still has checked out, so the pair is left behind) and eat disk.
300
+ `scripts/cratis-cleanup-worktrees.sh` removes linked worktrees after their work ships. It reports
301
+ local branches but keeps them because it cannot exclude a concurrent checkout during deletion.
303
302
  It removes only on **evidence of delivery**, never on a guess: the tip is merged into `origin/<default>`
304
303
  and was integrated rather than merely sitting on the default branch's first-parent history (where a
305
304
  brand-new empty branch sits), or it is merged and its upstream is gone, or GitHub reports a merged pull
306
- request whose head is exactly that tip. It never forces: a dirty, locked, current or live-held worktree
305
+ request with that exact head ref and tip, the default branch as its base, and a merge commit reachable
306
+ from the local `origin/<default>` ref. It never forces: a dirty, locked, current or live-held worktree
307
307
  is kept, as is anything undelivered, and every kept item is reported with its reason. Before removal
308
308
  (including dry-run), it checks for live processes with a cwd or open file under the worktree, preferring
309
309
  validated `pi-holders --json` results with `jq`, falling back to `lsof` when either is unavailable.
@@ -323,7 +323,8 @@ first. Non-empty `.ai-work/` directories, even when tracked, are additionally ke
323
323
  Harnesses with no hook wiring (Copilot, Cursor, OpenCode) rely on the **ship-changes** prompt, whose
324
324
  final step runs the same script, and on running it by hand.
325
325
  - **By hand.** `bash .cratis/ai/hooks/scripts/cratis-cleanup-worktrees.sh [--dry-run]` from any worktree;
326
- run from the main checkout to also collect the worktree you are standing in. Add
326
+ run from the main checkout to also collect the worktree you are standing in. A dry run uses existing
327
+ refs without fetching, pruning, or changing refs or worktree metadata. Add
327
328
  `--include-work-records=<path>` only after preserving any records you still need. It bypasses the
328
329
  record-preservation check for that exact worktree only (repeat for multiple paths), permitting clean
329
330
  tracked `.ai-work/` content to go with it, never ignored/untracked files. Bare `--include-work-records`
@@ -332,13 +333,14 @@ first. Non-empty `.ai-work/` directories, even when tracked, are additionally ke
332
333
  - **GitHub lookups.** The complete worktree and branch sweep is planned before any removal. Git
333
334
  ancestry is checked first; only a plan needing more evidence triggers the single REST batch. It
334
335
  reads the latest 100 closed pull requests, so older merged branches absent from that page are simply
335
- kept. Only merged entries with the exact branch and head commit qualify. Hook runs share an atomic
336
- stamp and cache under the Git common directory, with at most one request per repository every
337
- 15 minutes, including failed attempts. A fresh successful cache is reused. A failed request, invalid
338
- response, or unavailable lock without a fresh successful cache aborts **all** removals in that sweep,
339
- including ancestry-proven worktrees and branches, with a one-line notice. Failed attempts are marked
340
- for the full window: later plans needing GitHub also abort all removals without retrying, while plans
341
- needing only ancestry evidence proceed without GitHub. Locks older than 15 minutes can be reclaimed.
336
+ kept. A merge commit missing locally or not reachable from the local default ref is not evidence.
337
+ Hook runs share an atomic stamp and cache under the Git common directory, with at most one request
338
+ per repository every 15 minutes, including failed attempts. A fresh successful cache is reused.
339
+ A failed request, invalid response, or unavailable lock without a fresh successful cache aborts
340
+ **all** removals in that sweep, including ancestry-proven worktrees, with a one-line notice.
341
+ Failed attempts are marked for the full window: later plans needing GitHub also abort all removals
342
+ without retrying, while plans needing only ancestry evidence proceed without GitHub. Locks older
343
+ than 15 minutes can be reclaimed.
342
344
  Manual runs are not throttled, but also use at most one request per run and abort all removals if
343
345
  that request fails.
344
346
  - **Disable GitHub only.** Set `CRATIS_CLEANUP_NO_GH=1` to avoid all GitHub lookups while keeping
@@ -10,7 +10,8 @@
10
10
  # 1. its tip is merged into origin/<default> AND was integrated (it is not simply sitting on the
11
11
  # default branch's first-parent history, which is where a brand-new, empty branch sits), or
12
12
  # 2. its tip is merged into origin/<default> and its upstream is gone (the PR branch was deleted), or
13
- # 3. GitHub reports a merged pull request whose head commit is exactly this tip.
13
+ # 3. GitHub reports a pull request for this exact head ref and tip merged into the default branch,
14
+ # and its merge commit is reachable from the locally known origin/<default>.
14
15
  # Anything else is KEPT and reported with the reason. Nothing is ever forced: a dirty, locked,
15
16
  # current or live-held worktree is kept. Ignored/untracked files must be archived or removed first,
16
17
  # including .ai-work/. A non-empty .ai-work/ is also preserved when tracked, unless opted in below.
@@ -35,6 +36,8 @@
35
36
  # Usage:
36
37
  # cratis-cleanup-worktrees.sh [--dry-run] [--quiet] [--no-fetch] [--no-reclaim] [--include-work-records=<path>]...
37
38
  # run in the repository (any worktree)
39
+ # --dry-run use existing refs without fetching,
40
+ # pruning or updating worktree metadata
38
41
  # --include-work-records=<path> bypass record preservation for this
39
42
  # exact worktree only; repeatable, manual
40
43
  # only, ignored in hook mode. It permits
@@ -194,13 +197,15 @@ if [ "$SELFTEST" = 1 ]; then
194
197
  fi
195
198
 
196
199
  # ── Locate the repository ─────────────────────────────────────────────────────
200
+ # Read-only checks must not refresh worktree indexes or fetch missing objects in partial clones.
201
+ if [ "$DRY" = 1 ]; then export GIT_OPTIONAL_LOCKS=0 GIT_NO_LAZY_FETCH=1; fi
197
202
  git rev-parse --git-dir >/dev/null 2>&1 || { [ "$QUIET" = 1 ] || echo "cratis-cleanup-worktrees: not in a git repository" >&2; exit "$([ "$HOOK" = 1 ] && echo 0 || echo 2)"; }
198
203
  here=$(pwd -P)
199
204
  main_wt=$(git worktree list --porcelain | awk 'NR==1 && $1=="worktree"{sub(/^worktree /,""); print; exit}')
200
205
  if [ ! -d "$main_wt" ]; then echo "cratis-cleanup-worktrees: cannot find the main worktree" >&2; exit 2; fi
201
206
  cd "$main_wt" || exit 2
202
207
 
203
- if [ "$FETCH" = 1 ]; then git fetch --prune --quiet origin >/dev/null 2>&1 || LOG_NOFETCH=1; fi
208
+ if [ "$DRY" = 0 ] && [ "$FETCH" = 1 ]; then git fetch --prune --quiet origin >/dev/null 2>&1 || LOG_NOFETCH=1; fi
204
209
  default=$(git symbolic-ref --quiet --short refs/remotes/origin/HEAD 2>/dev/null || true)
205
210
  [ -n "$default" ] || { for c in origin/main origin/master; do git rev-parse -q --verify "refs/remotes/$c" >/dev/null && default=$c && break; done; }
206
211
  [ -n "$default" ] || { [ "$QUIET" = 1 ] || echo "cratis-cleanup-worktrees: no origin default branch; nothing to compare against" >&2; exit "$([ "$HOOK" = 1 ] && echo 0 || echo 2)"; }
@@ -218,7 +223,10 @@ GH_PULLS=''
218
223
  valid_pulls() {
219
224
  jq -e -s 'length == 1 and (.[0] | type == "array" and all(.[];
220
225
  type == "object" and has("merged_at") and (.merged_at == null or (.merged_at | type == "string")) and
221
- (.head | type == "object" and (.ref | type == "string") and (.sha | type == "string"))))' "$1" >/dev/null 2>&1
226
+ (.head | type == "object" and (.ref | type == "string") and (.sha | type == "string")) and
227
+ (.base | type == "object" and (.ref | type == "string" and length > 0)) and
228
+ has("merge_commit_sha") and ((.merged_at == null and .merge_commit_sha == null) or
229
+ (.merge_commit_sha | type == "string" and test("\\A([a-f0-9]{40}|[a-f0-9]{64})\\z")))))' "$1" >/dev/null 2>&1
222
230
  }
223
231
  lock_stat() { stat -c '%i %Y' "$1" 2>/dev/null || stat -f '%i %m' "$1" 2>/dev/null; }
224
232
  fresh_stamp() {
@@ -308,8 +316,16 @@ ancestry_delivered() {
308
316
  return 1
309
317
  }
310
318
  github_delivered() {
311
- printf '%s' "$GH_PULLS" | jq -e --arg br "$1" --arg sha "$2" \
312
- 'any(.[]; .merged_at != null and .head.ref == $br and .head.sha == $sha)' >/dev/null 2>&1
319
+ local merges merge
320
+ merges=$(printf '%s' "$GH_PULLS" | jq -r --arg br "$1" --arg sha "$2" --arg base "$default_local" \
321
+ '.[] | select(.merged_at != null and .head.ref == $br and .head.sha == $sha and .base.ref == $base)
322
+ | .merge_commit_sha' 2>/dev/null) || return 2
323
+ while IFS= read -r merge; do
324
+ [ -n "$merge" ] || continue
325
+ [ "$(GIT_NO_LAZY_FETCH=1 git rev-parse --verify "$merge^{commit}" 2>/dev/null)" = "$merge" ] || continue
326
+ if GIT_NO_LAZY_FETCH=1 git merge-base --is-ancestor "$merge" "refs/remotes/$default" 2>/dev/null; then return 0; fi
327
+ done <<< "$merges"
328
+ return 1
313
329
  }
314
330
  PLAN_KIND=(); PLAN_PATH=(); PLAN_SHA=(); PLAN_BRANCH=(); PLAN_EVIDENCE=(); NEEDS_GH=0
315
331
  plan_item() {
@@ -610,7 +626,7 @@ report_branch() {
610
626
  }
611
627
 
612
628
  # ── Execute the resolved plan, rechecking tips and worktree safety ─────────────
613
- git worktree prune >/dev/null 2>&1
629
+ if [ "$DRY" = 0 ]; then git worktree prune >/dev/null 2>&1; fi
614
630
  for ((i=0; i<${#PLAN_KIND[@]}; i++)); do
615
631
  kind=${PLAN_KIND[i]}; path=${PLAN_PATH[i]}; sha=${PLAN_SHA[i]}; br=${PLAN_BRANCH[i]}; ev=${PLAN_EVIDENCE[i]}
616
632
  if [ "$kind" = branch ]; then report_branch "$br" "$sha" "$ev"; continue; fi
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cratis/pi",
3
- "version": "8.10.0",
3
+ "version": "8.10.2",
4
4
  "description": "Configuration-aware Cratis AI integration for Pi",
5
5
  "type": "module",
6
6
  "files": [