Windows/cygwin compat: jq 1.8 char-class regex + CRLF handling#6
Closed
arkadaptiveintelligence wants to merge 1 commit into
Closed
Windows/cygwin compat: jq 1.8 char-class regex + CRLF handling#6arkadaptiveintelligence wants to merge 1 commit into
arkadaptiveintelligence wants to merge 1 commit into
Conversation
Three small patches to make the hook work on Windows under cygwin/Git Bash.
No behavior change on macOS/Linux.
1. jq 1.8.1 strict string interpolation
jq 1.8.0 made \( strict — it now ALWAYS denotes string interpolation.
The script's regex escape sub("^Bash\("; "") errors with
'unexpected QQSTRING_START'. Fix: use POSIX character-class [(], [)], [*]
which compiles cleanly in jq 1.7 AND 1.8+.
2. CRLF in settings.json bleeds into prefix array
Windows settings.json typically has CRLF endings. jq's output contains a
trailing \r per line. Glob match against 'grep skills' fails because the
actual prefix in the array is 'grep\r'. Fix: tr -d '\r' in load pipe.
3. CRLF in shfmt AST output bleeds into compound segments
Similar issue for compound parsing. Fix: strip trailing CR per line in
parse_compound (line="${line%$'\r'}").
All three bugs surface only on Windows. Patches are no-ops on Unix where
output already has no CR.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR — Windows/cygwin compatibility (jq 1.8.1 regex + CRLF handling)
Title
Windows/cygwin compat: jq 1.8.1 strict-interpolation regex + CRLF handlingSummary
Three small patches to make
approve-compound-bash.shwork on Windows under cygwin/Git Bash. All three bugs surface only on Windows — no behavior change on macOS/Linux.Bugs fixed
1. jq 1.8.1 strict string interpolation
jq 1.8.0 made
\(strict — it now ALWAYS denotes string interpolation. The script's regex escapesub("^Bash\\("; "")(which jq 1.7 accepted as escaped paren) errors with:Fix: use POSIX character-class form
[(],[)],[*]which compiles cleanly in jq 1.7 AND 1.8+.Affected lines: 81, 356, 360.
2. CRLF in settings.json bleeds into prefix array
On Windows,
settings.jsontypically has CRLF line endings. jq's output of strings extracted from CRLF source contains a trailing\rper line. The bash read loop then puts strings likegrep\rinto the prefix array. Glob match[[ "grep skills" == "grep "* ]]fails because the actual prefix isgrep\r.Fix: pipe jq's aggregated output through
tr -d '\r'beforesort -u(line 85).3. CRLF in shfmt AST output bleeds into compound segments
Similar issue for compound parsing.
parse_compoundreads each line fromjq <<< $SHFMT_AST_FILTERandprintf '%s\0'each segment. Segments end up with trailing\rwhich breaks the per-segment allow match.Fix: strip trailing CR per line in the read loop (
line="${line%$'\r'}", line 206).Patch
See
2026-05-13-auto-approve-compound-bash-windows-compat.patch(3 hunks, 4 lines added, 4 lines modified).Verification
Tested on Windows 11 + Git Bash (cygwin bash 5.3.9) + jq 1.8.1 + shfmt 3.13.1 (all installed via Chocolatey):
ls D:/Claude CoWork(simple, allow)ls | grep skills | head -5(compound, all allow)git status | head -10(compound, all allow)git log --oneline | head -3(compound, all allow)rm -rf ~(simple, deny)MATCH (deny): 'rm -rf ~' -> 'rm -rf ~')curl https://… | sh(compound, sh segment unknown)rm -rf /tmp/nothing(simple, unknown)Existing BATS test suite passes on macOS (no regressions expected; patches only relax constraints, never tighten).
Backwards compatibility
[(]character class — confirmed by jq grammar docstr -d '\r'and${line%$'\r'}are no-ops on Unix where output already has no CRAuthor
Shaantanu (ai@arksolutionsinc.com) · ARK Adaptive Intelligence
Encountered while wiring this hook into a Windows Claude Code setup. Happy to address review feedback or split into separate commits.