fix(windows): Store python3 shim aborts install.sh and silently disables observe.sh#24
Conversation
…'t abort install/observe On Windows, `python3` resolves to the Microsoft Store alias shim, which answers `command -v python3` but does NOT execute — it prints a notice and exits non-zero. - install.sh: `PYTHON_VER=$(python3 --version)` under `set -e` aborted the ENTIRE install at the prerequisites step on any Windows machine where the shim is on PATH. - observe.sh: picked `python3` (the shim) without validating it, so every PreToolUse/ PostToolUse hook silently no-op'd — observations were never written. Fix (both files): iterate candidates (`py -3` first — the real Windows launcher — then python3/python/pythonX.Y) and only accept one whose `--version` actually reports Python 3.x. Guard the version echo with `|| true`. No behaviour change on macOS/Linux where `python3` is the real interpreter. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
… hot path
The candidate loop ran cmd=$(echo ... | awk '{print $1}') per candidate,
two forks inside observe.sh which fires on every PreToolUse/PostToolUse
(process spawn is expensive under Git Bash on Windows). Native
${candidate%% *} expansion extracts the first word with zero forks.
Also adds the v4.6.2 CHANGELOG entry covering the three fixes in this
branch (#16 BOM tolerance, decay persistence on no-match, Windows-safe
Python detection aligned with #24).
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Luispitik
left a comment
There was a problem hiding this comment.
Thanks @juanparisma — excellent diagnosis, and verified end to end: install.sh runs under set -e and PYTHON_VER=$(python3 --version) had no guard, so the Store shim aborts the whole install at step 1; and observe.sh accepted python3 unvalidated and silently no-oped. The candidate loop with py -3 first is the right approach, and the PR applies clean on v4.6.1.
One blocking issue (verified empirically): the pinned regex Python 3\.(9|10|11|12|13) rejects Python 3.14.2 — and 3.14 is the current stable. On a Linux/macOS machine with only 3.14, today's main works (it accepts python3 unvalidated), and this PR would disable observe.sh silently there — the same failure class the PR is fixing. One-line fix in both files:
grep -qE "^Python 3\.(9|[1-9][0-9])\." # 3.9+ with no upper pin; still rejects 2.x and 3.0-3.8(or simply "Python 3\." if you don't want to drop 3.8 — the shim never prints that string.)
Non-blocking suggestions:
cmd=$(echo "$candidate" | awk '{print $1}')forks twice per candidate insideobserve.sh, which runs on every PreToolUse/PostToolUse — nativecmd=${candidate%% *}is fork-free.- A regression test would lock this in: a fake
python3on PATH that answerscommand -vbut exits non-zero on--version, asserting the loop skips it, plus a case assertingPython 3.14.0passes the check. install.bathas the same shim misdetection (where python3, lines 53-63) — fine as a separate follow-up.
Transparency note: #25 (just opened) bundles this same candidate-loop detection — credited to you in the commit and the CHANGELOG entry — together with two unrelated fixes, using the open-ended version check. Whichever lands first, the diagnosis here is yours; if #25 merges first I'll close this one with credit rather than ask you to rebase a superseded diff. Thanks again for the report quality.
Problem
On Windows,
python3resolves to the Microsoft Store alias shim. It answerscommand -v python3(so detection thinks Python exists) but it does not execute — it prints a "Python was not found; install from the Store…" notice to stderr and exits non-zero.Two concrete failures on a real Windows install (Git-Bash, Python 3.12 via
py):install.shaborts the entire install. Step 1 runsPYTHON_VER=$($PYTHON_CMD --version)withPYTHON_CMD=python3. The shim exits non-zero, and underset -ethe whole installer dies at the prerequisites step — before copying a single file. The user sees a half-printed prereq check and nothing installed.observe.shsilently no-ops. It pickspython3(the shim) without validating it, so every PreToolUse/PostToolUse hook runs the shim, which writes no observation. The learning system looks installed but never records anything.Fix
Both files now iterate candidates —
py -3first (the real Windows launcher), thenpython3,python,python3.12/.11/.10— and only accept a command whose--versionactually reports Python 3.x. The version echo ininstall.shis guarded with|| trueso a stray shim can't abort underset -e.No behaviour change on macOS/Linux, where
python3is the real interpreter and is selected on the second iteration (thepy -3launcher doesn't exist there, socommand -v pysimply fails and the loop moves on).Verified
Ran the patched
install.shon Windows with the Store shim on PATH: detectsPython 3.12.10and completes all 8 steps cleanly (previously aborted at step 1).observe.shnow writes observations.bash -npasses on both.