diff --git a/.claude/scripts/check-messages.sh b/.claude/scripts/check-messages.sh index b553afa..31a1bc3 100644 --- a/.claude/scripts/check-messages.sh +++ b/.claude/scripts/check-messages.sh @@ -22,19 +22,38 @@ if [ -f "$IDENTITY_FILE" ]; then USER_ALIAS=$(jq -r '.user // empty' "$IDENTITY_FILE" 2>/dev/null) fi +# Resolve a Python interpreter for the JSON sanitizer. Prefer the value in +# identity.json (.python.command — set during machine onboarding); fall back +# to a PATH lookup. On ACG Windows boxes the Microsoft Store `python3` alias +# is disabled and `py` is the canonical launcher, so an unconditional +# `python3` call would silently fail and cause every coord message to be +# dropped. If no Python is available at all, the sanitizer falls back to +# `tr -d` (lossy on real \n/\t in string fields but keeps messages visible). +PY="" +if [ -f "$IDENTITY_FILE" ]; then + PY=$(jq -r '.python.command // empty' "$IDENTITY_FILE" 2>/dev/null) +fi +if [ -z "$PY" ]; then + PY=$(command -v python3 || command -v py || command -v python) +fi + # Sanitize JSON: the coord API sometimes returns message bodies with unescaped # control chars (U+0000-U+001F) — invalid JSON per RFC 8259, which makes jq # abort with "Invalid string: control characters ... must be escaped". Round- # trip through python's json.loads(strict=False) (which accepts them) and # re-emit properly escaped JSON so jq downstream works on every payload. sanitize_json() { - python3 -c ' + if [ -n "$PY" ]; then + "$PY" -c ' import json, sys try: print(json.dumps(json.loads(sys.stdin.read(), strict=False))) except Exception: pass ' 2>/dev/null + else + tr -d '\000-\037' + fi } # --- Unread messages ---------------------------------------------------------