diff --git a/hooks/scripts/session-orient.sh b/hooks/scripts/session-orient.sh index 05cd652..46caa21 100755 --- a/hooks/scripts/session-orient.sh +++ b/hooks/scripts/session-orient.sh @@ -139,13 +139,25 @@ fi # Methodology staleness check (Rule Zero) if [ -d ops/methodology ] && [ -f ops/config.yaml ]; then - CONFIG_MTIME=$(stat -f %m ops/config.yaml 2>/dev/null || stat -c %Y ops/config.yaml 2>/dev/null || echo 0) + # Detect platform for stat syntax: Linux uses -c %Y, macOS uses -f %m. + # Must try Linux first — on Linux, stat -f means "filesystem stats" and + # succeeds with wrong output instead of failing, breaking the || fallback. + if stat -c %Y ops/config.yaml &>/dev/null 2>&1; then + _STAT_FMT() { stat -c %Y "$1" 2>/dev/null || echo 0; } + elif stat -f %m ops/config.yaml &>/dev/null 2>&1; then + _STAT_FMT() { stat -f %m "$1" 2>/dev/null || echo 0; } + else + _STAT_FMT() { echo 0; } + fi + + CONFIG_MTIME=$(_STAT_FMT ops/config.yaml) NEWEST_METH=$(ls -t ops/methodology/*.md 2>/dev/null | head -1) if [ -n "$NEWEST_METH" ]; then - METH_MTIME=$(stat -f %m "$NEWEST_METH" 2>/dev/null || stat -c %Y "$NEWEST_METH" 2>/dev/null || echo 0) + METH_MTIME=$(_STAT_FMT "$NEWEST_METH") DAYS_STALE=$(( (CONFIG_MTIME - METH_MTIME) / 86400 )) if [ "$DAYS_STALE" -ge 30 ]; then echo "CONDITION: Methodology notes are ${DAYS_STALE}+ days behind config changes. Consider /rethink drift." fi fi + unset -f _STAT_FMT fi diff --git a/skill-sources/rethink/SKILL.md b/skill-sources/rethink/SKILL.md index 76c4257..93fee41 100644 --- a/skill-sources/rethink/SKILL.md +++ b/skill-sources/rethink/SKILL.md @@ -86,9 +86,10 @@ Read: ```bash # Compare config.yaml modification time vs newest methodology note -CONFIG_MTIME=$(stat -f %m ops/config.yaml 2>/dev/null || stat -c %Y ops/config.yaml 2>/dev/null || echo 0) +# Linux stat -f means filesystem stats (not file), so try -c first +CONFIG_MTIME=$(stat -c %Y ops/config.yaml 2>/dev/null || stat -f %m ops/config.yaml 2>/dev/null || echo 0) NEWEST_METH=$(ls -t ops/methodology/*.md 2>/dev/null | head -1) -METH_MTIME=$(stat -f %m "$NEWEST_METH" 2>/dev/null || stat -c %Y "$NEWEST_METH" 2>/dev/null || echo 0) +METH_MTIME=$(stat -c %Y "$NEWEST_METH" 2>/dev/null || stat -f %m "$NEWEST_METH" 2>/dev/null || echo 0) ``` If `CONFIG_MTIME > METH_MTIME`: config has changed since methodology was last updated. Flag as staleness drift. diff --git a/skills/health/SKILL.md b/skills/health/SKILL.md index 7c72862..7c37e4e 100644 --- a/skills/health/SKILL.md +++ b/skills/health/SKILL.md @@ -407,7 +407,8 @@ for f in {vocabulary.notes}/*.md; do basename=$(basename "$f" .md) # Last modified (days ago) - mod_days=$(( ($(date +%s) - $(stat -f %m "$f" 2>/dev/null || stat -c %Y "$f" 2>/dev/null)) / 86400 )) + # Linux stat -f means filesystem stats (not file), so try -c first + mod_days=$(( ($(date +%s) - $(stat -c %Y "$f" 2>/dev/null || stat -f %m "$f" 2>/dev/null || echo 0)) / 86400 )) # Incoming link count incoming=$(rg -l "\[\[$basename\]\]" --glob '*.md' | grep -v "$f" | wc -l | tr -d ' ')