Cursor plugin specification and official plugins
TypeScript
fix(pstack): worktree-audit checks MERGED against the default branch, not origin/main (#574)
laurencf9a111eaf1e
diff --git a/pstack/skills/poteto-mode/playbooks/worktree-cleanup.md b/pstack/skills/poteto-mode/playbooks/worktree-cleanup.mdindex ae3379ba..c767ac09 100644--- a/pstack/skills/poteto-mode/playbooks/worktree-cleanup.md+++ b/pstack/skills/poteto-mode/playbooks/worktree-cleanup.md@@ -1,6 +1,6 @@### Worktree and simulator cleanup-1. Snapshot and audit. Record `df -h /`, then run `scripts/worktree-audit.sh` (principle-build-the-lever). It reads paths from `git worktree list`, never hand-typed, since a hand-typed `myrepo-worktrees/x` misses one that lives at `.cursor/worktrees/myrepo/x` (principle-encode-lessons-in-structure). It classifies each worktree by size, age, merge state, uncommitted work, PR state, and the newest chat that touched it, then suggests a bucket. The transcript scan is slow, so background it.+1. Snapshot and audit. Record `df -h /`, then run `scripts/worktree-audit.sh [-b <pr-base-ref>] [repo-path]` (principle-build-the-lever). Without `-b` it checks `MERGED` against `origin/HEAD`, so pass `-b origin/<branch>` when PRs target another branch. It reads paths from `git worktree list`, never hand-typed, since a hand-typed `myrepo-worktrees/x` misses one that lives at `.cursor/worktrees/myrepo/x` (principle-encode-lessons-in-structure). It classifies each worktree by size, age, merge state, uncommitted work, PR state, and the newest chat that touched it, then suggests a bucket. The transcript scan is slow, so background it.2. The bucket is advice, not permission. The pinned and active chats are the real artifact (principle-prove-it-works). Get that set from the user or sidebar and cross-check every candidate. The lever has marked `safe` a worktree the user had pinned, so the pinned set wins.3. Verify usage before deleting. For every `verify-recent-chat` row, or anything you doubt, fan subagents out to read the transcripts and report whether the chat is pinned or ongoing and which worktrees it touches (principle-guard-the-context-window, transcripts are bulk). A pinned chat spawns arena and repro trees into sibling worktrees via background subagents, and those are in use even when their names never hit the sidebar.4. Pause on irreversible loss. `wip:N` is N tracked uncommitted edits. Show the diff and get a decision first, since removing a clean worktree is recoverable from its branch but uncommitted work is gone. `scratch:N` is untracked throwaway, safe to drop, but name the files. Per Autonomy, clean and merged and not-in-use proceeds. `wip` and in-use pause.diff --git a/pstack/skills/poteto-mode/scripts/worktree-audit.sh b/pstack/skills/poteto-mode/scripts/worktree-audit.shindex b9af0816..b2d11921 100755--- a/pstack/skills/poteto-mode/scripts/worktree-audit.sh+++ b/pstack/skills/poteto-mode/scripts/worktree-audit.sh@@ -4,18 +4,48 @@# operated in it. Emits a table sorted by size with a suggested bucket. Never# deletes anything; deletion stays a human-gated step in the playbook.#-# Usage: worktree-audit.sh [repo-path] (defaults to the current repo)+# Usage: worktree-audit.sh [-b|--base <ref>] [repo-path]+# repo-path defaults to the current repo.+# -b sets the ref the MERGED column checks against (e.g. origin/integration).+# Without it the base is origin/HEAD, then origin/main, then origin/master.+# origin/HEAD is the remote's default branch, not necessarily the branch PRs+# merge into; pass -b when they differ.set -u+base=""+while [ $# -gt 0 ]; do+ case "$1" in+ -b|--base) [ $# -ge 2 ] || { echo "error: $1 needs a ref" >&2; exit 2; }; base="$2"; shift 2 ;;+ -h|--help) sed -n '2,/^set -u/p' "$0" | sed '$d; s/^# \{0,1\}//'; exit 0 ;;+ -*) echo "error: unknown option: $1" >&2; exit 2 ;;+ *) break ;;+ esac+done+repo="${1:-$(git rev-parse --show-toplevel 2>/dev/null)}"[ -z "$repo" ] && { echo "not in a git repo; pass a repo path" >&2; exit 1; }cd "$repo" || exit 1+git rev-parse --git-dir >/dev/null 2>&1 || { echo "error: not a git repo: $repo" >&2; exit 1; }# Main worktree is the first entry; everything else is a candidate.main_wt=$(git worktree list --porcelain | awk '/^worktree /{print $2; exit}')-# origin/main drives the merge check. Best-effort; stale is fine for a first pass.-git fetch origin main --quiet 2>/dev/null || echo "warn: could not fetch origin/main; merged column may be stale" >&2+if [ -z "$base" ]; then+ for cand in "$(git symbolic-ref --short refs/remotes/origin/HEAD 2>/dev/null)" origin/main origin/master; do+ [ -n "$cand" ] && git rev-parse --verify --quiet "$cand^{commit}" >/dev/null && { base="$cand"; break; }+ done+ [ -z "$base" ] && { echo "error: no base ref (origin/HEAD, origin/main, origin/master all missing); pass -b <ref>" >&2; exit 1; }+ echo "warn: no -b given; MERGED checks against $base" >&2+fi++# The base drives the merge check. The fetch is best-effort (stale is fine for+# a first pass) and runs before the check, since -b may name a branch not+# fetched yet. The explicit refspec creates it even in a single-branch clone.+case "$base" in+origin/*) git fetch origin "+refs/heads/${base#origin/}:refs/remotes/$base" --quiet 2>/dev/null \+ || echo "warn: could not fetch $base; merged column may be stale" >&2 ;;+esac+git rev-parse --verify --quiet "$base^{commit}" >/dev/null 2>&1 || { echo "error: base ref not found: $base" >&2; exit 1; }# PR state by branch, fetched once. Empty if gh is unavailable.prs=$(mktemp)@@ -27,6 +57,7 @@ slug=$(printf '%s' "$main_wt" | sed 's#^/##; s#/#-#g')transcripts="$HOME/.cursor/projects/$slug/agent-transcripts"now=$(date +%s)+echo "# base: $base"printf "SIZE\tAGE\tMERGED\tDIRTY\tREMOTE\tPR\tLAST_CHAT\tBUCKET\tWORKTREE\n"git worktree list --porcelain | awk '/^worktree /{print $2}' | while read -r wt; do@@ -37,9 +68,9 @@ git worktree list --porcelain | awk '/^worktree /{print $2}' | while read -r wt;head_ts=$(git -C "$wt" log -1 --format='%ct' HEAD 2>/dev/null || echo 0)age=$([ "$head_ts" -gt 0 ] 2>/dev/null && echo "$(( (now - head_ts) / 86400 ))d" || echo "?")- # Squash-merged branches are not ancestors of main, so PR state is the+ # Squash-merged branches are not ancestors of the base, so PR state is the# real signal; merge-base only catches fast-forward/rebase merges.- git merge-base --is-ancestor "$head" origin/main 2>/dev/null && merged=YES || merged=no+ git merge-base --is-ancestor "$head" "$base" 2>/dev/null && merged=YES || merged=no# Distinguish real WIP (tracked edits) from disposable untracked scratch.porcelain=$(git -C "$wt" status --porcelain 2>/dev/null)