From a1640ece666dcf6c08bda52e613d3e7848fb59b8 Mon Sep 17 00:00:00 2001 From: Kaitian Xie Date: Wed, 18 Nov 2026 19:02:02 +0800 Subject: [PATCH 1/3] fix: preserve full paths in the Codex worktree audit --- .../poteto-mode/scripts/worktree-audit.sh | 44 ++++++++------- .github/workflows/plugin-install.yml | 4 ++ COMPATIBILITY.md | 7 +++ tests/test_worktree_audit.py | 54 +++++++++++++++++++ 4 files changed, 89 insertions(+), 20 deletions(-) create mode 100644 COMPATIBILITY.md create mode 100644 tests/test_worktree_audit.py diff --git a/.agents/skills/poteto-mode/scripts/worktree-audit.sh b/.agents/skills/poteto-mode/scripts/worktree-audit.sh index 11a410f..fd47e84 100755 --- a/.agents/skills/poteto-mode/scripts/worktree-audit.sh +++ b/.agents/skills/poteto-mode/scripts/worktree-audit.sh @@ -27,9 +27,6 @@ repo="${1:-$(git rev-parse --show-toplevel 2>/dev/null)}" 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}') - 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; } @@ -50,15 +47,17 @@ git rev-parse --verify --quiet "$base^{commit}" >/dev/null 2>&1 || { echo "error # GNU coreutils (Linux, Homebrew gnubin) reads `stat -f` as file system status # and `date -r` as a file, so pick the stat and date flags once. if stat -c %Y / >/dev/null 2>&1; then - stat_fmt=(-c '%Y %n'); fmt_day() { date -d "@$1" '+%Y-%m-%d'; } + stat_fmt=(-c '%Y'); fmt_day() { date -d "@$1" '+%Y-%m-%d'; } else - stat_fmt=(-f '%m %N'); fmt_day() { date -r "$1" '+%Y-%m-%d'; } + stat_fmt=(-f '%m'); fmt_day() { date -r "$1" '+%Y-%m-%d'; } fi -# PR state by branch, fetched once as [{number, state, head}] with a lowercase -# state. Origin when its CLI can read this repo's PRs, otherwise gh. Empty when -# neither can. -prs=$(mktemp) +audit_tmp=$(mktemp -d) || exit 1 +trap 'rm -rf "$audit_tmp"' EXIT +git worktree list --porcelain -z > "$audit_tmp/worktrees" || exit 1 + +# Look up PR state once, using Origin when available and gh otherwise. +prs="$audit_tmp/prs" if command -v origin >/dev/null 2>&1 \ && raw=$(origin pr list --author "@me" --state all --limit 1000 \ --json number,status,headRef 2>/dev/null); then @@ -76,8 +75,12 @@ 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 - [ "$wt" = "$main_wt" ] && continue +# Git lists the main worktree first. Keep the full path from each NUL-delimited field. +first=true +while IFS= read -r -d '' field; do + [[ $field == 'worktree '* ]] || continue + if [ "$first" = true ]; then first=false; continue; fi + wt=${field#worktree } size=$(du -sh "$wt" 2>/dev/null | awk '{print $1}') head=$(git -C "$wt" rev-parse HEAD 2>/dev/null) @@ -89,8 +92,8 @@ git worktree list --porcelain | awk '/^worktree /{print $2}' | while read -r wt; 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) - if [ -z "$porcelain" ]; then dirty=clean + if ! porcelain=$(git -C "$wt" status --porcelain 2>/dev/null); then dirty=unknown + elif [ -z "$porcelain" ]; then dirty=clean elif printf '%s\n' "$porcelain" | grep -qv '^??'; then dirty="wip:$(printf '%s\n' "$porcelain" | grep -cv '^??')" else dirty="scratch:$(printf '%s\n' "$porcelain" | grep -c '^??')"; fi @@ -111,14 +114,15 @@ git worktree list --porcelain | awk '/^worktree /{print $2}' | while read -r wt; # followed by "/" or a quote so glint-482 does not match glint-482-r37. last="-"; last_ts=0 if [ -d "$transcripts" ]; then - f=$(rg -l -e "${wt}/" -e "${wt}\"" "$transcripts" 2>/dev/null \ - | xargs stat "${stat_fmt[@]}" 2>/dev/null | sort -rn | head -1) - if [ -n "$f" ]; then last_ts=$(echo "$f" | awk '{print $1}') + timestamp=$(rg -l -0 -F -e "${wt}/" -e "${wt}\"" "$transcripts" 2>/dev/null \ + | while IFS= read -r -d '' file; do stat "${stat_fmt[@]}" "$file" 2>/dev/null; done \ + | sort -rn | head -1) + if [ -n "$timestamp" ]; then last_ts=$timestamp last=$(fmt_day "$last_ts" 2>/dev/null); fi fi recent=$([ "$last_ts" -gt 0 ] 2>/dev/null && [ $(( (now - last_ts) / 86400 )) -le 4 ] && echo yes || echo no) - case "$dirty" in wip:*) bucket=hold-wip ;; *) + case "$dirty" in unknown) bucket=review ;; wip:*) bucket=hold-wip ;; *) case "$pr" in */open|*/draft) bucket=hold-open-pr ;; *) if [ "$recent" = yes ]; then bucket=verify-recent-chat elif [ "$merged" = YES ] || [ "$pr" != "-" ]; then bucket=safe @@ -126,8 +130,8 @@ git worktree list --porcelain | awk '/^worktree /{print $2}' | while read -r wt; esac ;; esac + # Keep one TSV row even for paths containing a tab or newline. + [[ $wt == *[$'\t\r\n']* ]] && printf -v wt '%q' "$wt" printf "%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n" \ "$size" "$age" "$merged" "$dirty" "$remote" "$pr" "$last" "$bucket" "$wt" -done | sort -t$'\t' -k1,1 -rh - -rm -f "$prs" +done < "$audit_tmp/worktrees" | sort -t$'\t' -k1,1 -rh diff --git a/.github/workflows/plugin-install.yml b/.github/workflows/plugin-install.yml index 86bbd84..a7d751d 100644 --- a/.github/workflows/plugin-install.yml +++ b/.github/workflows/plugin-install.yml @@ -16,6 +16,10 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 + - name: Check worktree audit classifications + run: | + command -v rg >/dev/null || sudo apt-get install -y ripgrep + python3 tests/test_worktree_audit.py - uses: actions/setup-node@v4 with: node-version: 22 diff --git a/COMPATIBILITY.md b/COMPATIBILITY.md new file mode 100644 index 0000000..127b5f0 --- /dev/null +++ b/COMPATIBILITY.md @@ -0,0 +1,7 @@ +# Codex worktree audit + +The [pinned upstream script](https://github.com/cursor/plugins/blob/2f87c854fe3e2fcda44ca86b46ede35aad3c46b7/pstack/skills/poteto-mode/scripts/worktree-audit.sh) splits Git’s worktree paths on whitespace. A path such as `feature branch` can be truncated to `feature`, causing the audit to inspect the wrong directory and report uncommitted work as clean. + +The [Codex script](.agents/skills/poteto-mode/scripts/worktree-audit.sh) reads NUL-delimited paths from Git. If Git cannot report a worktree’s status, the audit marks it `unknown` and sends it to `review`. + +Upstream looks for chat history in Cursor’s project directory. For Codex, set `PSTACK_TRANSCRIPTS_DIR` to a directory of transcripts already scoped to the repository. When it is unset, the audit omits chat recency. diff --git a/tests/test_worktree_audit.py b/tests/test_worktree_audit.py new file mode 100644 index 0000000..497fec7 --- /dev/null +++ b/tests/test_worktree_audit.py @@ -0,0 +1,54 @@ +import os +from pathlib import Path +import subprocess +import tempfile +import unittest + + +AUDIT = Path(__file__).resolve().parents[1] / ".agents/skills/poteto-mode/scripts/worktree-audit.sh" + + +class WorktreeAuditTest(unittest.TestCase): + def test_audit_uses_the_full_worktree_path(self): + with tempfile.TemporaryDirectory() as temp: + root = Path(temp).resolve() + repo = root / "main checkout" + subprocess.run(["git", "init", "-q", str(repo)], check=True) + + def git(*args): + subprocess.run(["git", "-C", str(repo), *args], check=True) + + (repo / "tracked").write_text("initial\n") + git("add", "tracked") + git("-c", "user.name=Test", "-c", "user.email=test@example.org", + "-c", "commit.gpgsign=false", "commit", "-qm", "initial") + clean = root / "feature" + dirty = root / "feature branch" + recent = root / "feature [review]" + missing = root / "missing" + for tree in (clean, dirty, recent, missing): + git("worktree", "add", "--detach", "-q", str(tree)) + (dirty / "tracked").write_text("uncommitted\n") + missing.rename(root / "moved") + transcripts = root / "transcripts" + transcripts.mkdir() + (transcripts / "session notes.jsonl").write_text(f'"{recent}/tracked"\n') + + result = subprocess.run( + [str(AUDIT), "-b", "HEAD", str(dirty)], check=True, + env={**os.environ, "PSTACK_TRANSCRIPTS_DIR": str(transcripts)}, + capture_output=True, text=True, + ) + rows = [line.split("\t") for line in result.stdout.splitlines()[2:]] + self.assertCountEqual( + [Path(row[8]) for row in rows], [clean, dirty, recent, missing], + ) + classifications = {row[8]: (row[3], row[7]) for row in rows} + self.assertEqual(classifications[str(clean)], ("clean", "safe")) + self.assertEqual(classifications[str(dirty)], ("wip:1", "hold-wip")) + self.assertEqual(classifications[str(recent)], ("clean", "verify-recent-chat")) + self.assertEqual(classifications[str(missing)], ("unknown", "review")) + + +if __name__ == "__main__": + unittest.main() From 41c8f82b56339d1ef1cf6cadf59d2b12109091f5 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Wed, 18 Nov 2026 11:12:40 +0000 Subject: [PATCH 2/3] fix: keep only the NUL-delimited worktree path read The audit passes each full path from git worktree list --porcelain -z. UPSTREAM.md records that carried patch until cursor/plugins ships its own fix for the split. Co-authored-by: Kaitian Xie --- .../poteto-mode/scripts/worktree-audit.sh | 47 ++++++++-------- .github/workflows/plugin-install.yml | 4 -- COMPATIBILITY.md | 7 --- UPSTREAM.md | 4 ++ tests/test_worktree_audit.py | 54 ------------------- 5 files changed, 27 insertions(+), 89 deletions(-) delete mode 100644 COMPATIBILITY.md delete mode 100644 tests/test_worktree_audit.py diff --git a/.agents/skills/poteto-mode/scripts/worktree-audit.sh b/.agents/skills/poteto-mode/scripts/worktree-audit.sh index fd47e84..dc328a9 100755 --- a/.agents/skills/poteto-mode/scripts/worktree-audit.sh +++ b/.agents/skills/poteto-mode/scripts/worktree-audit.sh @@ -27,6 +27,11 @@ repo="${1:-$(git rev-parse --show-toplevel 2>/dev/null)}" 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 -z | while IFS= read -r -d '' field; do + case "$field" in "worktree "*) printf '%s' "${field#worktree }"; break ;; esac +done) + 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; } @@ -47,17 +52,15 @@ git rev-parse --verify --quiet "$base^{commit}" >/dev/null 2>&1 || { echo "error # GNU coreutils (Linux, Homebrew gnubin) reads `stat -f` as file system status # and `date -r` as a file, so pick the stat and date flags once. if stat -c %Y / >/dev/null 2>&1; then - stat_fmt=(-c '%Y'); fmt_day() { date -d "@$1" '+%Y-%m-%d'; } + stat_fmt=(-c '%Y %n'); fmt_day() { date -d "@$1" '+%Y-%m-%d'; } else - stat_fmt=(-f '%m'); fmt_day() { date -r "$1" '+%Y-%m-%d'; } + stat_fmt=(-f '%m %N'); fmt_day() { date -r "$1" '+%Y-%m-%d'; } fi -audit_tmp=$(mktemp -d) || exit 1 -trap 'rm -rf "$audit_tmp"' EXIT -git worktree list --porcelain -z > "$audit_tmp/worktrees" || exit 1 - -# Look up PR state once, using Origin when available and gh otherwise. -prs="$audit_tmp/prs" +# PR state by branch, fetched once as [{number, state, head}] with a lowercase +# state. Origin when its CLI can read this repo's PRs, otherwise gh. Empty when +# neither can. +prs=$(mktemp) if command -v origin >/dev/null 2>&1 \ && raw=$(origin pr list --author "@me" --state all --limit 1000 \ --json number,status,headRef 2>/dev/null); then @@ -75,12 +78,9 @@ now=$(date +%s) echo "# base: $base" printf "SIZE\tAGE\tMERGED\tDIRTY\tREMOTE\tPR\tLAST_CHAT\tBUCKET\tWORKTREE\n" -# Git lists the main worktree first. Keep the full path from each NUL-delimited field. -first=true -while IFS= read -r -d '' field; do - [[ $field == 'worktree '* ]] || continue - if [ "$first" = true ]; then first=false; continue; fi - wt=${field#worktree } +git worktree list --porcelain -z | while IFS= read -r -d '' field; do + case "$field" in "worktree "*) wt=${field#worktree } ;; *) continue ;; esac + [ "$wt" = "$main_wt" ] && continue size=$(du -sh "$wt" 2>/dev/null | awk '{print $1}') head=$(git -C "$wt" rev-parse HEAD 2>/dev/null) @@ -92,8 +92,8 @@ while IFS= read -r -d '' field; do git merge-base --is-ancestor "$head" "$base" 2>/dev/null && merged=YES || merged=no # Distinguish real WIP (tracked edits) from disposable untracked scratch. - if ! porcelain=$(git -C "$wt" status --porcelain 2>/dev/null); then dirty=unknown - elif [ -z "$porcelain" ]; then dirty=clean + porcelain=$(git -C "$wt" status --porcelain 2>/dev/null) + if [ -z "$porcelain" ]; then dirty=clean elif printf '%s\n' "$porcelain" | grep -qv '^??'; then dirty="wip:$(printf '%s\n' "$porcelain" | grep -cv '^??')" else dirty="scratch:$(printf '%s\n' "$porcelain" | grep -c '^??')"; fi @@ -114,15 +114,14 @@ while IFS= read -r -d '' field; do # followed by "/" or a quote so glint-482 does not match glint-482-r37. last="-"; last_ts=0 if [ -d "$transcripts" ]; then - timestamp=$(rg -l -0 -F -e "${wt}/" -e "${wt}\"" "$transcripts" 2>/dev/null \ - | while IFS= read -r -d '' file; do stat "${stat_fmt[@]}" "$file" 2>/dev/null; done \ - | sort -rn | head -1) - if [ -n "$timestamp" ]; then last_ts=$timestamp + f=$(rg -l -e "${wt}/" -e "${wt}\"" "$transcripts" 2>/dev/null \ + | xargs stat "${stat_fmt[@]}" 2>/dev/null | sort -rn | head -1) + if [ -n "$f" ]; then last_ts=$(echo "$f" | awk '{print $1}') last=$(fmt_day "$last_ts" 2>/dev/null); fi fi recent=$([ "$last_ts" -gt 0 ] 2>/dev/null && [ $(( (now - last_ts) / 86400 )) -le 4 ] && echo yes || echo no) - case "$dirty" in unknown) bucket=review ;; wip:*) bucket=hold-wip ;; *) + case "$dirty" in wip:*) bucket=hold-wip ;; *) case "$pr" in */open|*/draft) bucket=hold-open-pr ;; *) if [ "$recent" = yes ]; then bucket=verify-recent-chat elif [ "$merged" = YES ] || [ "$pr" != "-" ]; then bucket=safe @@ -130,8 +129,8 @@ while IFS= read -r -d '' field; do esac ;; esac - # Keep one TSV row even for paths containing a tab or newline. - [[ $wt == *[$'\t\r\n']* ]] && printf -v wt '%q' "$wt" printf "%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n" \ "$size" "$age" "$merged" "$dirty" "$remote" "$pr" "$last" "$bucket" "$wt" -done < "$audit_tmp/worktrees" | sort -t$'\t' -k1,1 -rh +done | sort -t$'\t' -k1,1 -rh + +rm -f "$prs" diff --git a/.github/workflows/plugin-install.yml b/.github/workflows/plugin-install.yml index a7d751d..86bbd84 100644 --- a/.github/workflows/plugin-install.yml +++ b/.github/workflows/plugin-install.yml @@ -16,10 +16,6 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - name: Check worktree audit classifications - run: | - command -v rg >/dev/null || sudo apt-get install -y ripgrep - python3 tests/test_worktree_audit.py - uses: actions/setup-node@v4 with: node-version: 22 diff --git a/COMPATIBILITY.md b/COMPATIBILITY.md deleted file mode 100644 index 127b5f0..0000000 --- a/COMPATIBILITY.md +++ /dev/null @@ -1,7 +0,0 @@ -# Codex worktree audit - -The [pinned upstream script](https://github.com/cursor/plugins/blob/2f87c854fe3e2fcda44ca86b46ede35aad3c46b7/pstack/skills/poteto-mode/scripts/worktree-audit.sh) splits Git’s worktree paths on whitespace. A path such as `feature branch` can be truncated to `feature`, causing the audit to inspect the wrong directory and report uncommitted work as clean. - -The [Codex script](.agents/skills/poteto-mode/scripts/worktree-audit.sh) reads NUL-delimited paths from Git. If Git cannot report a worktree’s status, the audit marks it `unknown` and sends it to `review`. - -Upstream looks for chat history in Cursor’s project directory. For Codex, set `PSTACK_TRANSCRIPTS_DIR` to a directory of transcripts already scoped to the repository. When it is unset, the audit omits chat recency. diff --git a/UPSTREAM.md b/UPSTREAM.md index cb23224..ad839c7 100644 --- a/UPSTREAM.md +++ b/UPSTREAM.md @@ -11,4 +11,8 @@ The port moves skills to `.agents/skills/`, replaces the manifests with `.codex- Future upstream syncs must skip the Benny automation pack (`pstack/automations/benny/`). +`.agents/skills/poteto-mode/scripts/worktree-audit.sh` carries a patch over the pin. The patch reads worktree paths with `git worktree list --porcelain -z` and passes each full path to git. The pinned script splits those paths on whitespace. Keep the patch until cursor/plugins ships its own fix for that split. On that sync, take upstream's script verbatim and remove the patch and this note. + +The script reads Codex transcripts from `PSTACK_TRANSCRIPTS_DIR` instead of `~/.cursor/projects//agent-transcripts`. + This repository targets Codex only. It does not register Cursor or Claude Code compatibility layouts. External Slack/tracker integrations, event runners, and repository-specific verification tools remain prerequisites for the workflows that use them. diff --git a/tests/test_worktree_audit.py b/tests/test_worktree_audit.py deleted file mode 100644 index 497fec7..0000000 --- a/tests/test_worktree_audit.py +++ /dev/null @@ -1,54 +0,0 @@ -import os -from pathlib import Path -import subprocess -import tempfile -import unittest - - -AUDIT = Path(__file__).resolve().parents[1] / ".agents/skills/poteto-mode/scripts/worktree-audit.sh" - - -class WorktreeAuditTest(unittest.TestCase): - def test_audit_uses_the_full_worktree_path(self): - with tempfile.TemporaryDirectory() as temp: - root = Path(temp).resolve() - repo = root / "main checkout" - subprocess.run(["git", "init", "-q", str(repo)], check=True) - - def git(*args): - subprocess.run(["git", "-C", str(repo), *args], check=True) - - (repo / "tracked").write_text("initial\n") - git("add", "tracked") - git("-c", "user.name=Test", "-c", "user.email=test@example.org", - "-c", "commit.gpgsign=false", "commit", "-qm", "initial") - clean = root / "feature" - dirty = root / "feature branch" - recent = root / "feature [review]" - missing = root / "missing" - for tree in (clean, dirty, recent, missing): - git("worktree", "add", "--detach", "-q", str(tree)) - (dirty / "tracked").write_text("uncommitted\n") - missing.rename(root / "moved") - transcripts = root / "transcripts" - transcripts.mkdir() - (transcripts / "session notes.jsonl").write_text(f'"{recent}/tracked"\n') - - result = subprocess.run( - [str(AUDIT), "-b", "HEAD", str(dirty)], check=True, - env={**os.environ, "PSTACK_TRANSCRIPTS_DIR": str(transcripts)}, - capture_output=True, text=True, - ) - rows = [line.split("\t") for line in result.stdout.splitlines()[2:]] - self.assertCountEqual( - [Path(row[8]) for row in rows], [clean, dirty, recent, missing], - ) - classifications = {row[8]: (row[3], row[7]) for row in rows} - self.assertEqual(classifications[str(clean)], ("clean", "safe")) - self.assertEqual(classifications[str(dirty)], ("wip:1", "hold-wip")) - self.assertEqual(classifications[str(recent)], ("clean", "verify-recent-chat")) - self.assertEqual(classifications[str(missing)], ("unknown", "review")) - - -if __name__ == "__main__": - unittest.main() From 8744663862c9343839c3baf5464861ce383715d1 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Wed, 18 Nov 2026 11:20:27 +0000 Subject: [PATCH 3/3] Drop the transcript directory sentence from UPSTREAM.md The Codex transcript directory is already described in the adapter. Co-authored-by: Kaitian Xie --- UPSTREAM.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/UPSTREAM.md b/UPSTREAM.md index ad839c7..e242849 100644 --- a/UPSTREAM.md +++ b/UPSTREAM.md @@ -13,6 +13,4 @@ Future upstream syncs must skip the Benny automation pack (`pstack/automations/b `.agents/skills/poteto-mode/scripts/worktree-audit.sh` carries a patch over the pin. The patch reads worktree paths with `git worktree list --porcelain -z` and passes each full path to git. The pinned script splits those paths on whitespace. Keep the patch until cursor/plugins ships its own fix for that split. On that sync, take upstream's script verbatim and remove the patch and this note. -The script reads Codex transcripts from `PSTACK_TRANSCRIPTS_DIR` instead of `~/.cursor/projects//agent-transcripts`. - This repository targets Codex only. It does not register Cursor or Claude Code compatibility layouts. External Slack/tracker integrations, event runners, and repository-specific verification tools remain prerequisites for the workflows that use them.