From a617232f249ba6ec135cc603aa19adab40fb1fa4 Mon Sep 17 00:00:00 2001 From: Chao Chen <209239467+surlymochan@users.noreply.github.com> Date: Sun, 18 Oct 2026 12:42:33 +0800 Subject: [PATCH] fix(pstack): read transcript mtimes with GNU stat and date in worktree-audit --- .../skills/poteto-mode/scripts/worktree-audit.sh | 12 ++++++++++-- pstack/skills/poteto-mode/scripts/worktree-audit.sh | 12 ++++++++++-- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/harness/pstack/claude-code/skills/poteto-mode/scripts/worktree-audit.sh b/harness/pstack/claude-code/skills/poteto-mode/scripts/worktree-audit.sh index 743c4e925..47e08919d 100755 --- a/harness/pstack/claude-code/skills/poteto-mode/scripts/worktree-audit.sh +++ b/harness/pstack/claude-code/skills/poteto-mode/scripts/worktree-audit.sh @@ -47,6 +47,14 @@ origin/*) git fetch origin "+refs/heads/${base#origin/}:refs/remotes/$base" --qu esac git rev-parse --verify --quiet "$base^{commit}" >/dev/null 2>&1 || { echo "error: base ref not found: $base" >&2; exit 1; } +# 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'; } +else + stat_fmt=(-f '%m %N'); 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. @@ -105,9 +113,9 @@ git worktree list --porcelain | awk '/^worktree /{print $2}' | while read -r wt; last="-"; last_ts=0 if [ -d "$transcripts" ]; then f=$(rg -l -e "${wt}/" -e "${wt}\"" "$transcripts" 2>/dev/null \ - | xargs stat -f '%m %N' 2>/dev/null | sort -rn | head -1) + | xargs stat "${stat_fmt[@]}" 2>/dev/null | sort -rn | head -1) if [ -n "$f" ]; then last_ts=$(echo "$f" | awk '{print $1}') - last=$(date -r "$last_ts" '+%Y-%m-%d' 2>/dev/null); fi + 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) diff --git a/pstack/skills/poteto-mode/scripts/worktree-audit.sh b/pstack/skills/poteto-mode/scripts/worktree-audit.sh index 743c4e925..47e08919d 100755 --- a/pstack/skills/poteto-mode/scripts/worktree-audit.sh +++ b/pstack/skills/poteto-mode/scripts/worktree-audit.sh @@ -47,6 +47,14 @@ origin/*) git fetch origin "+refs/heads/${base#origin/}:refs/remotes/$base" --qu esac git rev-parse --verify --quiet "$base^{commit}" >/dev/null 2>&1 || { echo "error: base ref not found: $base" >&2; exit 1; } +# 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'; } +else + stat_fmt=(-f '%m %N'); 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. @@ -105,9 +113,9 @@ git worktree list --porcelain | awk '/^worktree /{print $2}' | while read -r wt; last="-"; last_ts=0 if [ -d "$transcripts" ]; then f=$(rg -l -e "${wt}/" -e "${wt}\"" "$transcripts" 2>/dev/null \ - | xargs stat -f '%m %N' 2>/dev/null | sort -rn | head -1) + | xargs stat "${stat_fmt[@]}" 2>/dev/null | sort -rn | head -1) if [ -n "$f" ]; then last_ts=$(echo "$f" | awk '{print $1}') - last=$(date -r "$last_ts" '+%Y-%m-%d' 2>/dev/null); fi + 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)