Skip to content

fix(pstack): make worktree-audit's LAST_CHAT work with GNU stat and date - #707

Open
surlymochan wants to merge 1 commit into
cursor:mainfrom
surlymochan:fix/worktree-audit-gnu-stat
Open

surlymochan wants to merge 1 commit into
cursor:mainfrom
surlymochan:fix/worktree-audit-gnu-stat

Conversation

@surlymochan

@surlymochan surlymochan commented Oct 18, 2026 •

Copy link
Copy Markdown

Why

worktree-audit.sh finds the newest chat transcript for each worktree with stat -f '%m %N' and turns it into a day with date -r <epoch>. Both are BSD spellings. With GNU coreutils (Linux, or macOS with Homebrew's gnubin first on PATH), stat -f prints file system status and date -r expects a file, so LAST_CHAT comes out empty and recent is always no. A worktree a chat used today then lands in review instead of verify-recent-chat, which is the bucket the cleanup playbook treats as "check before deleting".

What changed

  • Probe once with stat -c %Y /. GNU gets stat -c '%Y %n' and date -d "@<epoch>"; otherwise the existing stat -f '%m %N' and date -r <epoch> stay.
  • The two call sites use the probed flags. Nothing else in the script changes.

Scope

Blast Radius

Only the LAST_CHAT column and the verify-recent-chat bucket of a read-only audit. On BSD stat the commands run are the same as before.

Verification

Scratch repo with one extra worktree (one commit) and a fake HOME whose agent-transcripts/chat1.json mentions that worktree path, run with -b main on Linux (coreutils 9.7):

before: 12K  0d  no  clean  no-remote  -              review              .../feat-wt
after:  12K  0d  no  clean  no-remote  -  2026-10-18  verify-recent-chat  .../feat-wt
  • With a stat shim on PATH that rejects -c, the probe falls back to the BSD flags (output matches the old script, as expected on GNU), so macOS keeps its current path.
  • bash -n passes, node scripts/generate-pstack-harness-trees.mjs --check reports the harness tree up to date, node scripts/check-pstack-docs.mjs reports 0 problems, and bun test in poteto-mode/scripts still passes (68/68).

Note

Low Risk
Read-only audit script only; BSD/macOS path is unchanged when the GNU probe fails.

Overview
Fixes LAST_CHAT and the verify-recent-chat bucket on Linux (and macOS when GNU coreutils win on PATH), where BSD-only stat -f and date -r failed to read transcript mtimes.

worktree-audit.sh now probes once with stat -c %Y / and sets shared stat_fmt plus fmt_day for either GNU (stat -c '%Y %n', date -d "@epoch") or BSD (unchanged behavior). The transcript scan uses those instead of hard-coded flags.

Reviewed by Cursor Bugbot for commit a617232. Bugbot is set up for automated code reviews on this repo. Configure here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant