Skip to content

🐛 fix: make precompact-transcript-backup.sh work on stock macOS bash 3.2#3

Merged
u-ichi merged 1 commit into
mainfrom
fix/mapfile-bash3-compat
Jul 5, 2026
Merged

🐛 fix: make precompact-transcript-backup.sh work on stock macOS bash 3.2#3
u-ichi merged 1 commit into
mainfrom
fix/mapfile-bash3-compat

Conversation

@u-ichi

@u-ichi u-ichi commented Jul 5, 2026

Copy link
Copy Markdown
Owner

Summary

hooks/precompact-transcript-backup.sh used mapfile for the rotation step. mapfile is a bash 4+ builtin, and macOS ships /bin/bash 3.2 by default. On a stock Mac the rotation failed every time with mapfile: command not found, and because the script starts with trap 'exit 0' ERR (correct for fail-open behavior) the error was completely silent — the visible symptom was ~/.claude/backups/transcripts/ growing without bound.

Replaced the mapfile + array with a POSIX-compliant find | sort | tail | while IFS= read -r loop that behaves identically on bash 3 / 4 / 5.

This PR also introduces a Version bump policy section in AGENTS.md (adapted from the reviewable-html-workbench convention) and bumps the plugin version 1.0.0 → 1.0.1 per that policy (patch, because this is a bug fix). The policy documents the three version slots that .github/workflows/test.yml already enforces to be equal.

Fixes #2

Changes

  • hooks/precompact-transcript-backup.sh: mapfile -t OLD_BACKUPS < <(...)find ... | ... | while IFS= read -r old; do rm -f ...; done
  • AGENTS.md: new Version bump policy section — semver-based bump table, keeps the three version slots (.claude-plugin/plugin.json version, .claude-plugin/marketplace.json metadata.version, and .claude-plugin/marketplace.json plugins[0].version) in sync as required by the CI Check version consistency step
  • .claude-plugin/plugin.json, .claude-plugin/marketplace.json (both metadata.version and plugins[0].version): 1.0.01.0.1

Test plan

Verified on macOS:

  • /bin/bash (3.2.57): seeded 25 backups for the target session + 3 backups for another session, ran the hook, confirmed the target session was pruned to 20, the other session was untouched, exit=0, no mapfile: command not found
  • Homebrew bash (5.3.12): same setup, same result (25→20, other session unchanged, exit=0) — no regression on bash 4+
  • Grepped the repo for other bash 4+ features (mapfile, readarray, declare -A, ${var^^}, ${var,,}) — none found in the remaining hooks/skills
  • Ran the CI Check version consistency logic locally — all three slots equal 1.0.1

Credits

Reported and diagnosed with a working local fix by @fuuuuuuma in #2. Thanks for the detailed reproduction and root-cause analysis.

🤖 Generated with Claude Code

@u-ichi u-ichi changed the title 🐛 fix: precompact-transcript-backup.sh を macOS 標準 bash 3.2 で動くようにする 🐛 fix: make precompact-transcript-backup.sh work on stock macOS bash 3.2 Jul 5, 2026
@u-ichi u-ichi force-pushed the fix/mapfile-bash3-compat branch from 409bd8c to c4c40cf Compare July 5, 2026 14:50
@u-ichi u-ichi force-pushed the fix/mapfile-bash3-compat branch 2 times, most recently from ebedd72 to 7c0af37 Compare July 5, 2026 14:56
macOS ships /bin/bash 3.2 by default and 3.2 does not have the
mapfile builtin. precompact-transcript-backup.sh starts with
`trap 'exit 0' ERR` for fail-open behavior, which silently swallowed
the `mapfile: command not found` failure. The visible symptom was
that ~/.claude/backups/transcripts/ grew without bound because the
rotation step never actually ran.

Rewrite the rotation as a POSIX `find | sort | tail | while IFS= read -r`
loop so it behaves identically on bash 3 / 4 / 5.

Also introduce a version bump policy in AGENTS.md (adapted from
reviewable-html-workbench) and bump the plugin version 1.0.0 → 1.0.1
per that policy.

Fixes #2

Reported and diagnosed by @fuuuuuuma.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@u-ichi u-ichi force-pushed the fix/mapfile-bash3-compat branch from 7c0af37 to 8fc7df9 Compare July 5, 2026 15:02
@u-ichi u-ichi merged commit ac65e1a into main Jul 5, 2026
2 checks passed
@u-ichi u-ichi deleted the fix/mapfile-bash3-compat branch July 5, 2026 15:03
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.

precompact-transcript-backup.sh: mapfile fails silently on stock macOS bash 3.2

1 participant