diff --git a/CHANGELOG.md b/CHANGELOG.md index d19d8a91..d188019d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ three commits past it), and a bug report can name a release instead of a sha nob Sections dated before 2026-09-19 predate the cycle and stay as they are. ## Unreleased +- fix(bin/wire-company-brain.sh): **a heredoc built inside `$(cat </dev/null + # bash 3.2 does not recognise a heredoc opened inside $(...): it scans the body as + # shell text while hunting for the matching ')', so a stray quote in the body can + # break the parse on macOS's default bash (same trap as bin/wire-company-brain.sh). + # Read the heredoc into a variable first, then pipe it in — no heredoc inside $(...). + IFS= read -r -d '' _ctx_py <<'PY' || true import json, os, sys path = sys.argv[1]; CAP = 8 << 20 def newest(chunk): @@ -116,7 +120,7 @@ try: else: print(0) except Exception: print(0) PY -) + ctx=$(printf '%s' "$_ctx_py" | "$PY" - "$transcript" 2>/dev/null) case "$ctx" in ''|*[!0-9]*) ctx=0 ;; esac printf '%s %s' "$now" "$ctx" > "$cache" 2>/dev/null fi diff --git a/claude-hooks/hooks/context-watch.sh b/claude-hooks/hooks/context-watch.sh index fcae27f5..cbb189d6 100755 --- a/claude-hooks/hooks/context-watch.sh +++ b/claude-hooks/hooks/context-watch.sh @@ -69,7 +69,11 @@ printf '%s' "$now" > "$throttle" 2>/dev/null # here can be 600KB (an inlined screenshot), so a fixed byte tail routinely # slices mid-line and finds no parseable record. Stops at the first usage # record found, or at the cap. -ctx=$("$PY" - "$transcript" <<'PY' 2>/dev/null +# bash 3.2 does not recognise a heredoc opened inside $(...): it scans the body as +# shell text while hunting for the matching ')', so a stray quote in the body can +# break the parse on macOS's default bash (same trap as bin/wire-company-brain.sh). +# Read the heredoc into a variable first, then pipe it in — no heredoc inside $(...). +IFS= read -r -d '' _ctx_py <<'PY' || true import json, os, sys path = sys.argv[1] @@ -111,7 +115,7 @@ try: except Exception: print(0) PY -) +ctx=$(printf '%s' "$_ctx_py" | "$PY" - "$transcript" 2>/dev/null) case "$ctx" in ''|*[!0-9]*) exit 0 ;; esac [ "$ctx" -gt 0 ] || exit 0