From e618245a7ead840de14326d760d08d9fffff8c2a Mon Sep 17 00:00:00 2001 From: Christian Bager Bach Houmann Date: Sat, 7 Nov 2026 22:50:58 +0100 Subject: [PATCH 1/6] test(worktree-audit): shadowed origin/* refs and a newer closed PR read as safe A local branch or tag named origin/main makes unmerged work read MERGED and safe, and one named origin/ makes an unpushed commit read pushed. A newer closed or merged PR listed before an older open one buckets the worktree safe. These tests fail on 2.2.7. --- tests/worktree-audit.test.mjs | 61 ++++++++++++++++++++++++++++++++++- 1 file changed, 60 insertions(+), 1 deletion(-) diff --git a/tests/worktree-audit.test.mjs b/tests/worktree-audit.test.mjs index a94b54d5..471362fc 100644 --- a/tests/worktree-audit.test.mjs +++ b/tests/worktree-audit.test.mjs @@ -80,7 +80,7 @@ function runAudit({ root, repo, bin }, ...args) { .map((line) => line.split("\t")) .map((cells) => [ cells[8].split("/").at(-1), - { merged: cells[2], dirty: cells[3], pr: cells[5], lastChat: cells[6], bucket: cells[7] }, + { merged: cells[2], dirty: cells[3], remote: cells[4], pr: cells[5], lastChat: cells[6], bucket: cells[7] }, ]), ); } @@ -115,6 +115,65 @@ printf '%s' '[{"number":7,"state":"MERGED","headRefName":"shipped"},{"number":8, }); }); +// gh and Origin both list a branch's PRs newest first, so a newer closed or +// merged PR comes before an older one that is still open. gh reports a draft +// as OPEN, and Origin reports it as draft. +for (const [cli, open] of [["gh", "open"], ["origin", "draft"]]) { + test(`an older ${open} PR from ${cli} holds its worktree when a newer closed PR comes first`, () => { + const fixture = createFixture(); + for (const branch of ["reopened", "superseded"]) commit(addWorktree(fixture, branch), branch); + const records = [ + [14, "closed", "reopened"], + [13, "merged", "superseded"], + [12, open, "reopened"], + [11, "closed", "superseded"], + ].map(([number, state, head]) => + cli === "gh" + ? { number, state: state.toUpperCase(), headRefName: head } + : { number, status: state, headRef: head }, + ); + writeFileSync(join(fixture.bin, cli), `#!/bin/sh\nprintf '%s' '${JSON.stringify(records)}'\n`); + chmodSync(join(fixture.bin, cli), 0o755); + const rows = runAudit(fixture); + expect([rows.reopened.pr, rows.reopened.bucket]).toEqual([`#12/${open}`, "hold-open-pr"]); + expect([rows.superseded.pr, rows.superseded.bucket]).toEqual(["#13/merged", "safe"]); + }); +} + +for (const kind of ["branch", "tag"]) { + test(`a local ${kind} named origin/main cannot make unmerged work read as merged`, () => { + const fixture = createFixture(); + commit(addWorktree(fixture, "topic"), "unmerged"); + git(fixture.repo, kind, "origin/main", "topic"); + for (const args of [[], ["-b", "origin/main"]]) { + const { topic } = runAudit(fixture, ...args); + expect([topic.merged, topic.bucket]).toEqual(["no", "review"]); + } + git(fixture.repo, "remote", "set-head", "origin", "main"); + const { topic } = runAudit(fixture); + expect([topic.merged, topic.bucket]).toEqual(["no", "review"]); + }); +} + +test("a local branch named origin/ cannot make an unpushed commit read as pushed", () => { + const fixture = createFixture(); + const topic = addWorktree(fixture, "topic"); + commit(topic, "pushed"); + git(topic, "push", "-q", "origin", "topic"); + commit(topic, "local only"); + git(fixture.repo, "branch", "origin/topic", "topic"); + expect(runAudit(fixture).topic.remote).toBe("ahead1"); +}); + +test("-b takes a local branch as the base", () => { + const fixture = createFixture(); + commit(addWorktree(fixture, "landed"), "landed"); + commit(addWorktree(fixture, "unmerged"), "unmerged"); + git(fixture.repo, "merge", "-q", "--ff-only", "landed"); + const rows = runAudit(fixture, "-b", "main"); + expect([rows.landed.merged, rows.unmerged.merged]).toEqual(["YES", "no"]); +}); + test("lists every worktree when the checkout and its worktrees sit under a path with spaces", () => { const fixture = createFixture("worktree audit "); writeFileSync(join(addWorktree(fixture, "notes"), "notes.md"), "run log\n"); From ceaac2738f9a259eac7b4e8f40ba9a05c8487972 Mon Sep 17 00:00:00 2001 From: Christian Bager Bach Houmann Date: Sat, 7 Nov 2026 22:58:27 +0100 Subject: [PATCH 2/6] fix(worktree-audit): read origin refs by full name, prefer a branch's open PR A local branch or tag named origin/main won git's shorthand lookup over refs/remotes/origin/main, so the MERGED check could read unmerged work as merged and safe. An origin/* base and origin/ are now read by their refs/remotes/ names. A -b that names a local ref works as before. gh and Origin list a branch's PRs newest first, and the audit took the first, so a newer closed or merged PR hid an older open one and the worktree read safe. The audit now takes the first open or draft record, else the first. Same fixes as Michael Denyer's pstack-claude #423 and #424. --- .../poteto-mode/scripts/worktree-audit.sh | 23 ++++++++++++------- tools/forks.json | 2 +- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/plugins/pstack/skills/poteto-mode/scripts/worktree-audit.sh b/plugins/pstack/skills/poteto-mode/scripts/worktree-audit.sh index f72e4fd6..980107bd 100755 --- a/plugins/pstack/skills/poteto-mode/scripts/worktree-audit.sh +++ b/plugins/pstack/skills/poteto-mode/scripts/worktree-audit.sh @@ -39,8 +39,9 @@ git rev-parse --git-dir >/dev/null 2>&1 || { echo "error: not a git repo: $repo" main_wt=$(git worktree list --porcelain | awk '/^worktree /{print substr($0, 10); exit}') 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; } + origin_head=$(git symbolic-ref --quiet refs/remotes/origin/HEAD 2>/dev/null) + for cand in "${origin_head#refs/remotes/}" origin/main origin/master; do + [ -n "$cand" ] && git rev-parse --verify --quiet "refs/remotes/$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 " >&2; exit 1; } echo "warn: no -b given; MERGED checks against $base" >&2 @@ -55,7 +56,10 @@ if [ -n "$fetch" ]; then || echo "warn: could not fetch $base; merged column may be stale" >&2 ;; esac fi -git rev-parse --verify --quiet "$base^{commit}" >/dev/null 2>&1 \ +# A local branch or tag named origin/main wins git's shorthand lookup over +# refs/remotes/origin/main, so every origin/* ref is read by its full name. +case "$base" in origin/*) base_ref="refs/remotes/$base" ;; *) base_ref="$base" ;; esac +git rev-parse --verify --quiet "$base_ref^{commit}" >/dev/null 2>&1 \ || { echo "error: base ref not found: $base; --fetch fetches an origin/* base" >&2; exit 1; } disposable='(\.build|\.cache|\.dart_tool|\.DS_Store|\.gradle|\.lake|\.lycheecache|\.mypy_cache|\.next|\.nuxt' @@ -106,7 +110,7 @@ git worktree list --porcelain | awk '/^worktree /{print substr($0, 10)}' | while # 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" "$base" 2>/dev/null && merged=YES || merged=no + git merge-base --is-ancestor "$head" "$base_ref" 2>/dev/null && merged=YES || merged=no # `git worktree remove` deletes ignored files without asking, and a .env or # .claude/settings.local.json may exist nowhere else. An explicit @@ -134,13 +138,16 @@ git worktree list --porcelain | awk '/^worktree /{print substr($0, 10)}' | while branch=$(git -C "$wt" symbolic-ref --quiet --short HEAD 2>/dev/null || echo "") if [ -z "$branch" ]; then remote=detached elif git -C "$wt" show-ref --verify --quiet "refs/remotes/origin/$branch"; then - [ "$(git -C "$wt" rev-parse "origin/$branch" 2>/dev/null)" = "$head" ] \ + [ "$(git -C "$wt" rev-parse "refs/remotes/origin/$branch" 2>/dev/null)" = "$head" ] \ && remote=pushed \ - || remote="ahead$(git -C "$wt" rev-list --count "origin/$branch..HEAD" 2>/dev/null)" + || remote="ahead$(git -C "$wt" rev-list --count "refs/remotes/origin/$branch..HEAD" 2>/dev/null)" else remote=no-remote; fi - pr=$([ -n "$branch" ] && jq -r --arg b "$branch" \ - '.[] | select(.head==$b) | "#\(.number)/\(.state)"' "$prs" 2>/dev/null | head -1) + # PRs come newest first, so a newer closed or merged PR for the branch + # would hide an older one that is still open. An open record wins. + pr=$([ -n "$branch" ] && jq -r --arg b "$branch" '[.[] | select(.head==$b)] + | (map(select(.state=="open" or .state=="draft")) + .)[0] // empty + | "#\(.number)/\(.state)"' "$prs" 2>/dev/null) [ -z "$pr" ] && pr="-" # Most recent chat whose transcript operated in this worktree. Match path diff --git a/tools/forks.json b/tools/forks.json index 84bf33af..dc46320c 100644 --- a/tools/forks.json +++ b/tools/forks.json @@ -86,7 +86,7 @@ }, "plugins/pstack/skills/poteto-mode/scripts/worktree-audit.sh": { "kind": "policy", - "why": "Holds a worktree with untracked scratch, with an ignored file whose last component is not a named build or cache directory, with a commit only HEAD or its reflog reaches, or that git cannot read, the ignored and reflog checks ported from Michael Denyer's pstack-claude #277, passes --untracked-files so a status.showUntrackedFiles=no config hides nothing, fetches the base only under --fetch, sets GIT_OPTIONAL_LOCKS=0 so its git status never rewrites a worktree's index, and reads each worktree path whole, so a path with a space is not cut at the space.", + "why": "Holds a worktree with untracked scratch, with an ignored file whose last component is not a named build or cache directory, with a commit only HEAD or its reflog reaches, or that git cannot read, the ignored and reflog checks ported from Michael Denyer's pstack-claude #277, passes --untracked-files so a status.showUntrackedFiles=no config hides nothing, fetches the base only under --fetch, sets GIT_OPTIONAL_LOCKS=0 so its git status never rewrites a worktree's index, reads each worktree path whole, so a path with a space is not cut at the space, reads an origin/* base and origin/ by their full refs/remotes/ names, so a local branch or tag named origin/main cannot make unmerged work read as merged, and takes a branch's open PR over a newer closed or merged one, the last two fixes from Michael Denyer's pstack-claude #423 and #424.", "since": "2.0.0-rc.7", "upstream": "https://github.com/cursor/plugins/issues/449" }, From 5f4da364082268025964bcff30124474ef4d704e Mon Sep 17 00:00:00 2001 From: Christian Bager Bach Houmann Date: Sat, 7 Nov 2026 22:58:27 +0100 Subject: [PATCH 3/6] release: 2.2.8 --- .claude-plugin/marketplace.json | 2 +- CHANGES.md | 12 ++++++++++++ README.md | 4 ++-- VERSION | 2 +- package.json | 2 +- plugins/pstack/.claude-plugin/plugin.json | 2 +- plugins/pstack/.codex-plugin/plugin.json | 2 +- 7 files changed, 19 insertions(+), 7 deletions(-) diff --git a/.claude-plugin/marketplace.json b/.claude-plugin/marketplace.json index 24191f48..42ce84d6 100644 --- a/.claude-plugin/marketplace.json +++ b/.claude-plugin/marketplace.json @@ -10,7 +10,7 @@ "name": "t3-pstack", "source": "./plugins/pstack", "description": "pstack for T3 Code: rigorous agent workflows whose panels and fan-outs run across model families through T3. Original pstack by Lauren Tan (poteto).", - "version": "2.2.7" + "version": "2.2.8" } ] } diff --git a/CHANGES.md b/CHANGES.md index 7102cea8..8821266c 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -2,6 +2,18 @@ This file is the release changelog, with one `## - ` entry per release, newest first. The Cursor-to-T3 rewrite rules live in [`tools/substitutions.json`](tools/substitutions.json), and the [sync boundary](CONTRIBUTING.md#the-sync-boundary) in `CONTRIBUTING.md` defines how a change to upstream's skill content is declared. +## 2.2.8 - The worktree audit reads origin refs by their full name and holds a branch's open PR + +The worktree audit marks a worktree `safe` to prune when its HEAD is merged into the base or its branch has a PR that is not open. Two lookups could read unmerged or open work as safe. + +**A local ref named `origin/main` decided the merge check.** The `MERGED` column ran `git merge-base --is-ancestor` against the base by its short name, such as `origin/main`, `origin/master`, or a `-b origin/<branch>`. Git resolves a short name through `refs/tags/` and `refs/heads/` before `refs/remotes/`, so a local branch or tag named `origin/main` won over the remote-tracking ref. In a throwaway repository with one unpushed commit on a worktree branch `topic`, 2.2.7 read that worktree `no` and `review`. After `git branch origin/main topic`, or `git tag origin/main topic`, it read `YES` and `safe`, with or without `-b origin/main`, while `git merge-base --is-ancestor topic refs/remotes/origin/main` said no. A clone sets `origin/HEAD`, and for a shadowed name `git symbolic-ref --short` printed `remotes/origin/main`, which these refs do not shadow. So the default base was exposed when `origin/HEAD` was missing, and `-b origin/<branch>` always was. The audit now reads an `origin/*` base by its `refs/remotes/` name, and the same repository reads `no` and `review`. A `-b` that names a local ref, such as `-b main`, works as before. The `REMOTE` column made the same lookup for `origin/<branch>`, so a local branch named `origin/topic` at the worktree's HEAD read `pushed` for a commit that was never pushed. It now reads `ahead1`. `REMOTE` does not change the bucket. + +**A newer closed PR hid an older open one.** The audit reads PR state once from `gh pr list --state all`, or from Origin's CLI when it can, and both list newest first. For each branch it took the first record, so a newer closed or merged PR for the same branch hid an older open one, as when one branch has PRs against two bases. With a stub `gh` on `PATH` that lists `#12` closed and then `#11` open for `topic`, 2.2.7 printed `#12/closed` and bucketed the worktree `safe`. The audit now takes the first record whose state is `open` or `draft`, Origin's state for a draft PR, which the bucket already holds. Without one it keeps the first record, as before. The same repository prints `#11/open` and `hold-open-pr`, through `gh` and through a stub Origin CLI alike. + +Ethan found and fixed both in the JavaScript audit of Michael Denyer's pstack-claude, in [#423](https://github.com/michael-denyer/pstack-claude/pull/423) and [#424](https://github.com/michael-denyer/pstack-claude/pull/424). This release makes the same fixes in the port's bash script, which `tools/forks.json` declares as a fork of Lauren's. Lauren's script has both lookups, at the pin and at cursor/plugins `main` as of `6b03002`. `tests/worktree-audit.test.mjs` adds six tests. A local branch and a local tag named `origin/main` each leave unmerged work `no` and `review`, with the default base, with `-b origin/main`, and with `origin/HEAD` set. A local branch named `origin/topic` leaves an unpushed commit `ahead1`. An older open PR from `gh` and an older draft PR from Origin each hold their worktree behind a newer closed PR, beside a branch whose newest PR is merged and stays `safe`. `-b main` checks against the local branch. All but the last fail on 2.2.7. + +This release syncs nothing from Lauren's pstack, so all three components stay pinned at cursor/plugins `c742dd6`. At that pin each component's dry run reports no undeclared fork and no substitution that matches nothing. Neither hooks file changes. This is a patch release, and no setting or workflow has to change. On Codex, run `npx -y github:chhoumann/t3-pstack update` after it, as after every release. + ## 2.2.7 - An Autopilot-full owner's brief says it is not a leaf, so the owner starts its own reviewers 2.2.6 made each Autopilot-full PR owner a `delegate_task` child, and it made every `delegate_task` child a leaf, which does the work itself and starts no subagent unless its brief names one. Step 2 said only that the owner's brief "lets the owner delegate as the playbooks say", which names no subagent. In a run of 2.2.6 on this Mac's T3, the root read the leaf rule and wrote "You are a leaf. Do all the work yourself and start no subagents." into the owner's brief. The owner then ran `/no-comments` in its own thread where that skill starts Comment Sicko, and skipped show-me-your-work's cross-model review of its trail. Both times its reason was that it starts no subagents. diff --git a/README.md b/README.md index b0dbc69a..62232a9d 100644 --- a/README.md +++ b/README.md @@ -14,9 +14,9 @@ npx -y github:chhoumann/t3-pstack update npx -y github:chhoumann/t3-pstack doctor ``` -`npx -y github:chhoumann/t3-pstack` runs the installer from the latest commit on `main`. Each Claude Code home's marketplace auto-updates from `main` too, and each Codex home's marketplace stays on the release tag the installer pinned. To run one release's installer, name its tag, as in `npx -y github:chhoumann/t3-pstack#v2.2.7 doctor`. +`npx -y github:chhoumann/t3-pstack` runs the installer from the latest commit on `main`. Each Claude Code home's marketplace auto-updates from `main` too, and each Codex home's marketplace stays on the release tag the installer pinned. To run one release's installer, name its tag, as in `npx -y github:chhoumann/t3-pstack#v2.2.8 doctor`. -`install` and `update` are the same command, and a second run changes nothing. With Node 20 or later, it installs or updates the `t3-pstack@t3-pstack` plugin in every Claude Code and Codex config home T3 can run: `~/.claude` and `~/.codex`, `$CLAUDE_CONFIG_DIR` and `$CODEX_HOME`, and the home of each `claudeAgent` and `codex` instance in T3's settings, disabled ones included. Name any other home with `--claude-home <dir>` or `--codex-home <dir>`. Each home's `t3-pstack` marketplace must come from `chhoumann/t3-pstack`, or from `--source <owner/repo|git URL|dir>` on the same run, and a home whose marketplace has another source is left as it is. A run never switches a home's source, so a home already on `chhoumann/t3-pstack` stays on it under another `--source`, and `doctor` warns and prints the commands that move it. A local directory needs a path such as `./t3-pstack`, since `owner/repo` always means GitHub. On Codex it also trusts t3-pstack's session-start hook, once its hooks file is the one this release pins. Codex runs a plugin's hook only once it is trusted, and T3's Codex sessions never ask, so without this step the hook never runs. Codex 0.164 and later tie that trust to every file in the installed plugin, so each release turns the hook off until the installer trusts it again. So the installer pins each Codex home's `t3-pstack` marketplace to the release's tag, such as `v2.2.7`, and Codex's own auto-upgrade leaves that tag where it is. A release reaches a Codex home only when `update` runs, and that run trusts the hook again. A local directory has no tag, so a marketplace from one stays unpinned. Run `update` after each release. +`install` and `update` are the same command, and a second run changes nothing. With Node 20 or later, it installs or updates the `t3-pstack@t3-pstack` plugin in every Claude Code and Codex config home T3 can run: `~/.claude` and `~/.codex`, `$CLAUDE_CONFIG_DIR` and `$CODEX_HOME`, and the home of each `claudeAgent` and `codex` instance in T3's settings, disabled ones included. Name any other home with `--claude-home <dir>` or `--codex-home <dir>`. Each home's `t3-pstack` marketplace must come from `chhoumann/t3-pstack`, or from `--source <owner/repo|git URL|dir>` on the same run, and a home whose marketplace has another source is left as it is. A run never switches a home's source, so a home already on `chhoumann/t3-pstack` stays on it under another `--source`, and `doctor` warns and prints the commands that move it. A local directory needs a path such as `./t3-pstack`, since `owner/repo` always means GitHub. On Codex it also trusts t3-pstack's session-start hook, once its hooks file is the one this release pins. Codex runs a plugin's hook only once it is trusted, and T3's Codex sessions never ask, so without this step the hook never runs. Codex 0.164 and later tie that trust to every file in the installed plugin, so each release turns the hook off until the installer trusts it again. So the installer pins each Codex home's `t3-pstack` marketplace to the release's tag, such as `v2.2.8`, and Codex's own auto-upgrade leaves that tag where it is. A release reaches a Codex home only when `update` runs, and that run trusts the hook again. A local directory has no tag, so a marketplace from one stays unpinned. Run `update` after each release. `doctor` reports on the same homes and changes nothing itself: each marketplace's source, each Codex marketplace's pin, the installed version, whether its files are all there, whether it is enabled, the Codex hook's trust, Claude Code records that pin an old version, plain copies of the plugin's skills, and the model sheet. It exits 1 on any problem and prints a fix for each. diff --git a/VERSION b/VERSION index 5bc1cc43..23a63f52 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -2.2.7 +2.2.8 diff --git a/package.json b/package.json index 92a994a3..9c492435 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "t3-pstack", "private": true, - "version": "2.2.7", + "version": "2.2.8", "description": "The installer and development tooling for t3-pstack, Lauren Tan's pstack rewritten in place for T3 Code. The plugin itself lives in plugins/pstack.", "author": { "name": "Christian Bager Bach Houmann", diff --git a/plugins/pstack/.claude-plugin/plugin.json b/plugins/pstack/.claude-plugin/plugin.json index 79a67de7..8f7ec8db 100644 --- a/plugins/pstack/.claude-plugin/plugin.json +++ b/plugins/pstack/.claude-plugin/plugin.json @@ -1,7 +1,7 @@ { "name": "t3-pstack", "displayName": "t3-pstack (pstack for T3 Code)", - "version": "2.2.7", + "version": "2.2.8", "description": "pstack for T3 Code: Lauren Tan's pstack with its Cursor mechanics rewritten in place for T3, so subagents, panels, schedules, and PR watches dispatch through T3's orchestration and panels mix Claude, GPT, and Grok.", "author": { "name": "Christian Bager Bach Houmann", diff --git a/plugins/pstack/.codex-plugin/plugin.json b/plugins/pstack/.codex-plugin/plugin.json index f2aaf160..94cdd777 100644 --- a/plugins/pstack/.codex-plugin/plugin.json +++ b/plugins/pstack/.codex-plugin/plugin.json @@ -1,6 +1,6 @@ { "name": "t3-pstack", - "version": "2.2.7", + "version": "2.2.8", "description": "pstack for T3 Code on a Codex host: Lauren Tan's pstack with its Cursor mechanics rewritten in place for T3, so subagents, panels, schedules, and PR watches dispatch through T3's orchestration.", "author": { "name": "Christian Bager Bach Houmann", From ead2c1c25150fb6ef349bbd1f9df5097bc1fc0c4 Mon Sep 17 00:00:00 2001 From: Christian Bager Bach Houmann <christian@bagerbach.com> Date: Sat, 7 Nov 2026 23:03:17 +0100 Subject: [PATCH 4/6] test(worktree-audit): a shadowed upstream/* base and a tag named like the branch A local ref named upstream/main still decides -b upstream/main, and an origin/HEAD that points at refs/remotes/upstream/main reaches the same short name. A tag named like the worktree's branch makes symbolic-ref --short print heads/<branch>, so no PR matches and an open PR reads safe. --- tests/worktree-audit.test.mjs | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/tests/worktree-audit.test.mjs b/tests/worktree-audit.test.mjs index 471362fc..1c22f13a 100644 --- a/tests/worktree-audit.test.mjs +++ b/tests/worktree-audit.test.mjs @@ -140,18 +140,37 @@ for (const [cli, open] of [["gh", "open"], ["origin", "draft"]]) { }); } +test("a tag named like the branch does not hide the branch's open PR", () => { + const fixture = createFixture(); + commit(addWorktree(fixture, "topic"), "landed"); + git(fixture.repo, "merge", "-q", "--ff-only", "topic"); + git(fixture.repo, "push", "-q", "origin", "main"); + git(fixture.repo, "tag", "topic", "topic"); + writeFileSync( + join(fixture.bin, "gh"), + `#!/bin/sh\nprintf '%s' '[{"number":11,"state":"OPEN","headRefName":"topic"}]'\n`, + ); + chmodSync(join(fixture.bin, "gh"), 0o755); + const { topic } = runAudit(fixture); + expect([topic.merged, topic.pr, topic.bucket]).toEqual(["YES", "#11/open", "hold-open-pr"]); +}); + for (const kind of ["branch", "tag"]) { - test(`a local ${kind} named origin/main cannot make unmerged work read as merged`, () => { + test(`a local ${kind} named like a remote-tracking base cannot make unmerged work read as merged`, () => { const fixture = createFixture(); commit(addWorktree(fixture, "topic"), "unmerged"); - git(fixture.repo, kind, "origin/main", "topic"); - for (const args of [[], ["-b", "origin/main"]]) { + git(fixture.repo, "remote", "add", "upstream", join(fixture.root, "remote.git")); + git(fixture.repo, "fetch", "-q", "upstream"); + for (const name of ["origin/main", "upstream/main"]) git(fixture.repo, kind, name, "topic"); + for (const args of [[], ["-b", "origin/main"], ["-b", "upstream/main"]]) { const { topic } = runAudit(fixture, ...args); expect([topic.merged, topic.bucket]).toEqual(["no", "review"]); } - git(fixture.repo, "remote", "set-head", "origin", "main"); - const { topic } = runAudit(fixture); - expect([topic.merged, topic.bucket]).toEqual(["no", "review"]); + for (const target of ["refs/remotes/origin/main", "refs/remotes/upstream/main"]) { + git(fixture.repo, "symbolic-ref", "refs/remotes/origin/HEAD", target); + const { topic } = runAudit(fixture); + expect([topic.merged, topic.bucket]).toEqual(["no", "review"]); + } }); } From 14a701b548c4b529f1f0e1f80f8d1e971b84c9a1 Mon Sep 17 00:00:00 2001 From: Christian Bager Bach Houmann <christian@bagerbach.com> Date: Sat, 7 Nov 2026 23:05:11 +0100 Subject: [PATCH 5/6] fix(worktree-audit): read any remote's base and the branch by full ref A local ref named upstream/main still decided -b upstream/main. A base that starts with a configured remote's name is now read under refs/remotes/. The branch name comes from symbolic-ref without --short, which prints heads/<name> when a tag shares the name, so a tag no longer hides the branch's PR. --- .../skills/poteto-mode/scripts/worktree-audit.sh | 11 ++++++++--- tools/forks.json | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/plugins/pstack/skills/poteto-mode/scripts/worktree-audit.sh b/plugins/pstack/skills/poteto-mode/scripts/worktree-audit.sh index 980107bd..c1f8caaa 100755 --- a/plugins/pstack/skills/poteto-mode/scripts/worktree-audit.sh +++ b/plugins/pstack/skills/poteto-mode/scripts/worktree-audit.sh @@ -57,8 +57,12 @@ if [ -n "$fetch" ]; then esac fi # A local branch or tag named origin/main wins git's shorthand lookup over -# refs/remotes/origin/main, so every origin/* ref is read by its full name. -case "$base" in origin/*) base_ref="refs/remotes/$base" ;; *) base_ref="$base" ;; esac +# refs/remotes/origin/main, so a base under a remote's name is read by its +# full name. +base_ref="$base" +while IFS= read -r name; do + case "$base" in "$name"/*) base_ref="refs/remotes/$base" ;; esac +done < <(git remote) git rev-parse --verify --quiet "$base_ref^{commit}" >/dev/null 2>&1 \ || { echo "error: base ref not found: $base; --fetch fetches an origin/* base" >&2; exit 1; } @@ -135,7 +139,8 @@ git worktree list --porcelain | awk '/^worktree /{print substr($0, 10)}' | while [ "$reflog_only" != 0 ] && dirty="${dirty:+$dirty,}reflog:$reflog_only" [ -z "$dirty" ] && dirty=clean - branch=$(git -C "$wt" symbolic-ref --quiet --short HEAD 2>/dev/null || echo "") + branch=$(git -C "$wt" symbolic-ref --quiet HEAD 2>/dev/null || echo "") + branch=${branch#refs/heads/} if [ -z "$branch" ]; then remote=detached elif git -C "$wt" show-ref --verify --quiet "refs/remotes/origin/$branch"; then [ "$(git -C "$wt" rev-parse "refs/remotes/origin/$branch" 2>/dev/null)" = "$head" ] \ diff --git a/tools/forks.json b/tools/forks.json index dc46320c..037778d8 100644 --- a/tools/forks.json +++ b/tools/forks.json @@ -86,7 +86,7 @@ }, "plugins/pstack/skills/poteto-mode/scripts/worktree-audit.sh": { "kind": "policy", - "why": "Holds a worktree with untracked scratch, with an ignored file whose last component is not a named build or cache directory, with a commit only HEAD or its reflog reaches, or that git cannot read, the ignored and reflog checks ported from Michael Denyer's pstack-claude #277, passes --untracked-files so a status.showUntrackedFiles=no config hides nothing, fetches the base only under --fetch, sets GIT_OPTIONAL_LOCKS=0 so its git status never rewrites a worktree's index, reads each worktree path whole, so a path with a space is not cut at the space, reads an origin/* base and origin/<branch> by their full refs/remotes/ names, so a local branch or tag named origin/main cannot make unmerged work read as merged, and takes a branch's open PR over a newer closed or merged one, the last two fixes from Michael Denyer's pstack-claude #423 and #424.", + "why": "Holds a worktree with untracked scratch, with an ignored file whose last component is not a named build or cache directory, with a commit only HEAD or its reflog reaches, or that git cannot read, the ignored and reflog checks ported from Michael Denyer's pstack-claude #277, passes --untracked-files so a status.showUntrackedFiles=no config hides nothing, fetches the base only under --fetch, sets GIT_OPTIONAL_LOCKS=0 so its git status never rewrites a worktree's index, reads each worktree path whole, so a path with a space is not cut at the space, reads a base under a remote's name and origin/<branch> by their full refs/remotes/ names, so a local branch or tag named origin/main cannot make unmerged work read as merged, takes a branch's open PR over a newer closed or merged one, both fixes from Michael Denyer's pstack-claude #423 and #424, and names the branch from its full ref, so a tag of the same name cannot hide its PR.", "since": "2.0.0-rc.7", "upstream": "https://github.com/cursor/plugins/issues/449" }, From e5ad5c72a0ad6c293a5b05f143a02f46c2657e55 Mon Sep 17 00:00:00 2001 From: Christian Bager Bach Houmann <christian@bagerbach.com> Date: Sat, 7 Nov 2026 23:05:11 +0100 Subject: [PATCH 6/6] release: 2.2.8 notes cover the review's findings --- CHANGES.md | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 8821266c..0c486643 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -2,15 +2,19 @@ This file is the release changelog, with one `## <version> - <title>` entry per release, newest first. The Cursor-to-T3 rewrite rules live in [`tools/substitutions.json`](tools/substitutions.json), and the [sync boundary](CONTRIBUTING.md#the-sync-boundary) in `CONTRIBUTING.md` defines how a change to upstream's skill content is declared. -## 2.2.8 - The worktree audit reads origin refs by their full name and holds a branch's open PR +## 2.2.8 - The worktree audit reads git refs by their full name and holds a branch's open PR -The worktree audit marks a worktree `safe` to prune when its HEAD is merged into the base or its branch has a PR that is not open. Two lookups could read unmerged or open work as safe. +The worktree audit marks a worktree `safe` to prune when its HEAD is merged into the base or its branch has a PR that is not open. Three lookups could read unmerged or open work as safe. -**A local ref named `origin/main` decided the merge check.** The `MERGED` column ran `git merge-base --is-ancestor` against the base by its short name, such as `origin/main`, `origin/master`, or a `-b origin/<branch>`. Git resolves a short name through `refs/tags/` and `refs/heads/` before `refs/remotes/`, so a local branch or tag named `origin/main` won over the remote-tracking ref. In a throwaway repository with one unpushed commit on a worktree branch `topic`, 2.2.7 read that worktree `no` and `review`. After `git branch origin/main topic`, or `git tag origin/main topic`, it read `YES` and `safe`, with or without `-b origin/main`, while `git merge-base --is-ancestor topic refs/remotes/origin/main` said no. A clone sets `origin/HEAD`, and for a shadowed name `git symbolic-ref --short` printed `remotes/origin/main`, which these refs do not shadow. So the default base was exposed when `origin/HEAD` was missing, and `-b origin/<branch>` always was. The audit now reads an `origin/*` base by its `refs/remotes/` name, and the same repository reads `no` and `review`. A `-b` that names a local ref, such as `-b main`, works as before. The `REMOTE` column made the same lookup for `origin/<branch>`, so a local branch named `origin/topic` at the worktree's HEAD read `pushed` for a commit that was never pushed. It now reads `ahead1`. `REMOTE` does not change the bucket. +**A local ref named `origin/main` decided the merge check.** The `MERGED` column ran `git merge-base --is-ancestor` against the base by its short name, such as `origin/main`, `origin/master`, or a `-b origin/<branch>`. Git resolves a short name through `refs/tags/` and `refs/heads/` before `refs/remotes/`, so a local branch or tag named `origin/main` won over the remote-tracking ref. In a throwaway repository with one unpushed commit on a worktree branch `topic`, 2.2.7 read that worktree `no` and `review`. After `git branch origin/main topic`, or `git tag origin/main topic`, it read `YES` and `safe`, with or without `-b origin/main`, while `git merge-base --is-ancestor topic refs/remotes/origin/main` said no. A clone sets `origin/HEAD`, and for a shadowed name `git symbolic-ref --short` printed `remotes/origin/main`, which these refs do not shadow. So the default base was exposed when `origin/HEAD` was missing, and `-b origin/<branch>` always was, as was `-b upstream/main` with a local ref named `upstream/main`. The audit now reads a base that starts with a remote's name by its `refs/remotes/` name, and the same repository reads `no` and `review`. A `-b` that names a local ref, such as `-b main`, works as before. The `REMOTE` column made the same lookup for `origin/<branch>`, so a local branch named `origin/topic` at the worktree's HEAD read `pushed` for a commit that was never pushed. It now reads `ahead1`. `REMOTE` does not change the bucket. **A newer closed PR hid an older open one.** The audit reads PR state once from `gh pr list --state all`, or from Origin's CLI when it can, and both list newest first. For each branch it took the first record, so a newer closed or merged PR for the same branch hid an older open one, as when one branch has PRs against two bases. With a stub `gh` on `PATH` that lists `#12` closed and then `#11` open for `topic`, 2.2.7 printed `#12/closed` and bucketed the worktree `safe`. The audit now takes the first record whose state is `open` or `draft`, Origin's state for a draft PR, which the bucket already holds. Without one it keeps the first record, as before. The same repository prints `#11/open` and `hold-open-pr`, through `gh` and through a stub Origin CLI alike. -Ethan found and fixed both in the JavaScript audit of Michael Denyer's pstack-claude, in [#423](https://github.com/michael-denyer/pstack-claude/pull/423) and [#424](https://github.com/michael-denyer/pstack-claude/pull/424). This release makes the same fixes in the port's bash script, which `tools/forks.json` declares as a fork of Lauren's. Lauren's script has both lookups, at the pin and at cursor/plugins `main` as of `6b03002`. `tests/worktree-audit.test.mjs` adds six tests. A local branch and a local tag named `origin/main` each leave unmerged work `no` and `review`, with the default base, with `-b origin/main`, and with `origin/HEAD` set. A local branch named `origin/topic` leaves an unpushed commit `ahead1`. An older open PR from `gh` and an older draft PR from Origin each hold their worktree behind a newer closed PR, beside a branch whose newest PR is merged and stays `safe`. `-b main` checks against the local branch. All but the last fail on 2.2.7. +**A tag named like the branch hid its PR.** The audit named each worktree's branch with `git symbolic-ref --short HEAD`, which prints `heads/topic` when a tag `topic` also exists. No PR record has that head, so a merged branch with an open PR read `-` and `safe`. It now strips `refs/heads/` from the full name and reads `#11/open` and `hold-open-pr`. + +Ethan found the first two in the JavaScript audit of Michael Denyer's pstack-claude and fixed them there in [#423](https://github.com/michael-denyer/pstack-claude/pull/423) and [#424](https://github.com/michael-denyer/pstack-claude/pull/424). This release makes the same fixes in the port's bash script, which `tools/forks.json` declares as a fork of Lauren's, and a review of this change found the third and the `upstream/main` case. Lauren's script has all three lookups, at the pin and at cursor/plugins `main` as of `6b03002`. `tests/worktree-audit.test.mjs` adds seven tests. A local branch and a local tag named `origin/main` and `upstream/main` each leave unmerged work `no` and `review`, with the default base, with `-b origin/main`, with `-b upstream/main`, and with `origin/HEAD` set. A local branch named `origin/topic` leaves an unpushed commit `ahead1`. An older open PR from `gh` and an older draft PR from Origin each hold their worktree behind a newer closed PR, beside a branch whose newest PR is merged and stays `safe`. A tag named like a merged branch leaves its open PR holding the worktree. `-b main` checks against the local branch. All but the last fail on 2.2.7. + +The audit still asks for at most 1,000 PRs, so an open PR older than the author's 1,000 newest in the repository goes unread. This release syncs nothing from Lauren's pstack, so all three components stay pinned at cursor/plugins `c742dd6`. At that pin each component's dry run reports no undeclared fork and no substitution that matches nothing. Neither hooks file changes. This is a patch release, and no setting or workflow has to change. On Codex, run `npx -y github:chhoumann/t3-pstack update` after it, as after every release.