error-occurred.sh reads its two python helpers' stdin with `<<<`, a bash
here-string. dash has no such operator, so the script is a parse error, not a
runtime error: `sh error-occurred.sh` dies at line 32 with "Syntax error:
redirection unexpected" before any line runs.
tests/test_planning_disabled_optout.py runs every Copilot hook through
`["sh", str(script)]`, which ignores the `#!/bin/bash` shebang. On Ubuntu
/bin/sh is dash, so the hook exits 2 and the enabled-run assertion at line 200
fails. That is the whole of the current master CI failure; macOS and Windows
stay green because their /bin/sh parses `<<<`.
The four sibling hooks already pipe stdin instead, so this is the last `<<<`
under .github/. They pipe with `echo`, which is not safe to copy here: dash's
builtin echo expands backslash escapes, and $INPUT is raw JSON from Copilot,
so an escaped \n inside an error message becomes a real control character and
json.load rejects the payload. The hook then reports {} and the error is
dropped. `printf '%s\n'` never touches the escapes, which is the same reason
3c78c3c moved the output side of these hooks off echo.
Scoped to .github/hooks/scripts/. The four .gemini/hooks copies use `<<<`
too, but nothing invokes them through sh and settings.json runs them by path,
so their shebang applies and they are not part of this failure.
43 lines
1.4 KiB
Bash
43 lines
1.4 KiB
Bash
#!/bin/bash
|
|
# planning-with-files: Error hook for GitHub Copilot
|
|
# Logs errors to task_plan.md when the agent encounters an error.
|
|
# Always exits 0 — outputs JSON to stdout.
|
|
|
|
# Read stdin (required — Copilot pipes JSON to stdin)
|
|
INPUT=$(cat)
|
|
|
|
[ "${PLANNING_DISABLED:-}" = "1" ] && { echo '{}'; exit 0; }
|
|
|
|
PLAN_FILE="task_plan.md"
|
|
|
|
if [ ! -f "$PLAN_FILE" ]; then
|
|
echo '{}'
|
|
exit 0
|
|
fi
|
|
|
|
# Extract error message from input JSON
|
|
PYTHON=""
|
|
for _p in /usr/bin/python3 /usr/local/bin/python3 /opt/homebrew/bin/python3; do
|
|
[ -x "$_p" ] && { PYTHON="$_p"; break; }
|
|
done
|
|
[ -z "$PYTHON" ] && PYTHON=$(command -v python3 2>/dev/null || command -v python 2>/dev/null)
|
|
ERROR_MSG=$(printf '%s\n' "$INPUT" | $PYTHON -c "
|
|
import sys, json
|
|
try:
|
|
data = json.load(sys.stdin)
|
|
msg = data.get('error', {}).get('message', '') if isinstance(data.get('error'), dict) else str(data.get('error', ''))
|
|
print(msg[:200])
|
|
except:
|
|
print('')
|
|
" 2>/dev/null || echo "")
|
|
|
|
if [ -n "$ERROR_MSG" ]; then
|
|
CONTEXT="[planning-with-files] Error detected: ${ERROR_MSG}. Log this error in task_plan.md under Errors Encountered with the attempt number and resolution."
|
|
ESCAPED=$(printf '%s\n' "$CONTEXT" | $PYTHON -c "import sys,json; print(json.dumps(sys.stdin.read(), ensure_ascii=False))" 2>/dev/null || echo "\"\"")
|
|
printf '%s\n' "{\"hookSpecificOutput\":{\"hookEventName\":\"ErrorOccurred\",\"additionalContext\":$ESCAPED}}"
|
|
else
|
|
echo '{}'
|
|
fi
|
|
|
|
exit 0
|