diff options
| author | Mohamed Hegazy <mhegazy@anthropic.com> | 2026-10-12 19:27:29 +0000 |
|---|---|---|
| committer | Claude <noreply@anthropic.com> | 2026-10-15 22:39:39 +0000 |
| commit | 5a1d326c862f33d05a9e65f30e50a71a4e71d4a5 (patch) | |
| tree | 532cf1018de7e6a6880dfdc8c9175f2bfacd9c09 /plugins/security-guidance/hooks/sg-python.sh | |
| parent | 5ac3c91066c7ec7f36e84348316742f7dd12de6a (diff) | |
security-guidance: report launcher fallback and give-up as metrics
Two count-only metrics, emitted only when nonzero, so the launcher change
can be checked in the field:
- launcher_fallback: the hook ran, but only because the launcher started
the interpreter by its real path (the names on PATH could not read the
plugin files). Added to the hook's and the SessionStart bootstrap's
existing metrics.
- launcher_unreadable: no interpreter could read the hook script. No
Python runs in that case, so the launcher prints the metrics line
itself before exiting 1.
Diffstat (limited to 'plugins/security-guidance/hooks/sg-python.sh')
| -rwxr-xr-x | plugins/security-guidance/hooks/sg-python.sh | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/plugins/security-guidance/hooks/sg-python.sh b/plugins/security-guidance/hooks/sg-python.sh index 4dee3106..7160baa2 100755 --- a/plugins/security-guidance/hooks/sg-python.sh +++ b/plugins/security-guidance/hooks/sg-python.sh @@ -33,6 +33,10 @@ set -e # changing it from inside the interpreter has no effect. export PYTHONUTF8=1 +# Set to 1 below only when the interpreter had to be found by its real path +# (pass 4); the hook reports it as the `launcher_fallback` metric. +unset SG_LAUNCHER_FALLBACK + # Git Bash / MSYS on Windows hands script paths to this shim in POSIX form # (`/c/Users/...`). When we exec a Windows `python.exe` (which we do on # Windows since `python3` is the Microsoft Store stub), python interprets the @@ -173,6 +177,7 @@ for cmd in "python3" "python" "py -3"; do fi sg_candidates+=("$c") done +export SG_LAUNCHER_FALLBACK=1 sg_fallback="" sg_tried="|" for cmd in "${sg_candidates[@]}"; do @@ -198,6 +203,8 @@ if [ -n "$sg_unreadable" ]; then echo " hook script: $SG_TARGET" >&2 echo " on Windows this happens when python, python3 and py are Microsoft Store or Python Install Manager aliases;" >&2 echo " install Python from https://python.org and put it ahead of ...\\Microsoft\\WindowsApps in PATH" >&2 + # No Python to report it, so the launcher emits the metric itself. + echo '{"metrics": {"launcher_unreadable": 1}}' exit 1 fi echo "security-guidance: no working Python 3 interpreter found." >&2 |
