From a29ec20374a856e8c0a0c1b4165813db98f3bba4 Mon Sep 17 00:00:00 2001 From: Joy Mondal Date: Mon, 9 Nov 2026 19:44:44 +0530 Subject: [PATCH 1/7] feat(antigravity): add cross-platform Windows support for agy CLI and Antigravity 2.0 Add Windows batch hook and CLI launchers (plugin/scripts/te-hook.cmd, te.cmd) to support cmd.exe /c execution. Update plugin/hooks.json to execute cleanly across Windows, macOS, and Linux. Add support for Antigravity 2.0 native tool signatures (write_file, edit_file) and document universal cross-platform support. --- README.md | 7 ++--- docs/PLUGIN.md | 3 +- plugin/README.md | 3 +- plugin/hooks.json | 6 ++-- plugin/scripts/te-hook.cmd | 42 ++++++++++++++++++++++++++++ plugin/scripts/te.cmd | 40 ++++++++++++++++++++++++++ tests/test_antigravity.py | 19 ++++++++++++- tokeneconomizer/trace/antigravity.py | 2 ++ 8 files changed, 110 insertions(+), 12 deletions(-) create mode 100644 plugin/scripts/te-hook.cmd create mode 100644 plugin/scripts/te.cmd diff --git a/README.md b/README.md index 967ee41f..2f360a91 100644 --- a/README.md +++ b/README.md @@ -227,9 +227,8 @@ Start `agy` and send a prompt in a repository, then check with `~/.tokeneconomizer/bin/te --host antigravity status`. `agy` has no plugin commands, so the plugin's commands run from a terminal. The plugin makes no model call through `agy`, which has no option that runs a prompt with every tool off, so the paid proposer and the loop guard are off -and tool pruning is not available. macOS and Linux only: -on Windows `agy` runs hook commands through `cmd /c`, and this plugin's launcher is a POSIX shell -script. See [its limits](plugin/README.md#antigravity-cli). +and tool pruning is not available. Works across Windows, macOS, and Linux (with dual .cmd/.sh launchers). +See [its limits](plugin/README.md#antigravity-cli). **opencode** (experimental) @@ -288,7 +287,7 @@ uninstalling, using Copilot with your own model key, and troubleshooting. | Grok Build (experimental) | 1.0.70 | not tested | | opencode (experimental) | 1.19.5 and 2.2.0 | not tested | | Hermes Agent (experimental) | 0.22.5 | not tested | -| Antigravity CLI (experimental) | agy 1.5.1, macOS and Linux | not tested | +| Antigravity CLI & 2.0 (experimental) | agy 1.5.1+, Windows, macOS and Linux | not tested | | Factory Droid (experimental) | 0.233.0, macOS (below) | not tested | The commands above were tested on the oldest and newest version in each range; newer versions diff --git a/docs/PLUGIN.md b/docs/PLUGIN.md index 9faf3834..44336629 100644 --- a/docs/PLUGIN.md +++ b/docs/PLUGIN.md @@ -855,8 +855,7 @@ open-vocabulary. On a repository you do not trust, leave micro-skills off (the d `SessionStart`, an `ephemeralMessage` (dropped after the turn) at `PreInvocation`. Calls a subagent makes are not in the transcript and are not seen. Transcript token fields are absent from older agy versions (unknown, not zero), and the transcript names no model, so session cost is priced - on the ledger's labelled fallback. macOS and Linux only: agy runs hook commands through - `cmd /c` on Windows, and the launcher is a POSIX shell script. + on the ledger's labelled fallback. Works across Windows, macOS, and Linux. * **Factory Droid (experimental)** — micro-skills, the loop guard and session cost, on 0.233.0 (macOS). No tool pruning: the TUI has no persistent per-tool setting (Factory issue #65). Side calls are off until `droid_sidecall` is on; see `docs/DROID.md`. diff --git a/plugin/README.md b/plugin/README.md index 9f3459e9..f8286dbc 100644 --- a/plugin/README.md +++ b/plugin/README.md @@ -547,8 +547,7 @@ log a warning for the empty section of a session with no facts. ## Antigravity CLI -Experimental: **micro-skills' LLM-free facts**, written against `agy` 1.5.1 on macOS and Linux -(agy runs hook commands through `cmd /c` on Windows, and the launcher is a POSIX shell script). +Experimental: **micro-skills' LLM-free facts**, written against `agy` 1.5.1+ and Antigravity 2.0 on Windows, macOS and Linux. **1. Install.** Build the self-contained plugin, which copies the package into it, and install the directory: diff --git a/plugin/hooks.json b/plugin/hooks.json index 93073113..c3be5323 100644 --- a/plugin/hooks.json +++ b/plugin/hooks.json @@ -1,13 +1,13 @@ { "tokeneconomizer": { "SessionStart": [ - { "type": "command", "command": "./scripts/te-hook --host antigravity --event SessionStart", "timeout": 15 } + { "type": "command", "command": "scripts\\te-hook.cmd --host antigravity --event SessionStart 2>nul || ./scripts/te-hook --host antigravity --event SessionStart", "timeout": 15 } ], "PreInvocation": [ - { "type": "command", "command": "./scripts/te-hook --host antigravity --event PreInvocation", "timeout": 10 } + { "type": "command", "command": "scripts\\te-hook.cmd --host antigravity --event PreInvocation 2>nul || ./scripts/te-hook --host antigravity --event PreInvocation", "timeout": 10 } ], "Stop": [ - { "type": "command", "command": "./scripts/te-hook --host antigravity --event Stop", "timeout": 10 } + { "type": "command", "command": "scripts\\te-hook.cmd --host antigravity --event Stop 2>nul || ./scripts/te-hook --host antigravity --event Stop", "timeout": 10 } ] } } diff --git a/plugin/scripts/te-hook.cmd b/plugin/scripts/te-hook.cmd new file mode 100644 index 00000000..742d7738 --- /dev/null +++ b/plugin/scripts/te-hook.cmd @@ -0,0 +1,42 @@ +@echo off +setlocal +set "DIR=%~dp0" +set "PYTHONUTF8=1" + +:: Explicit TE_PYTHON +if defined TE_PYTHON ( + if exist "%TE_PYTHON%" ( + "%TE_PYTHON%" "%DIR%te_bootstrap.py" hook %* + exit /b %ERRORLEVEL% + ) +) + +:: Find python.exe on PATH, skipping WindowsApps store alias +for /f "tokens=*" %%i in ('where python.exe 2^>nul') do ( + echo %%i | findstr /i /c:"WindowsApps" >nul + if errorlevel 1 ( + "%%i" "%DIR%te_bootstrap.py" hook %* + exit /b %ERRORLEVEL% + ) +) + +:: Try py.exe (-3) launcher +where py.exe >nul 2>&1 +if %ERRORLEVEL% equ 0 ( + py -3 "%DIR%te_bootstrap.py" hook %* + exit /b %ERRORLEVEL% +) + +:: Try python3.exe on PATH +for /f "tokens=*" %%i in ('where python3.exe 2^>nul') do ( + echo %%i | findstr /i /c:"WindowsApps" >nul + if errorlevel 1 ( + "%%i" "%DIR%te_bootstrap.py" hook %* + exit /b %ERRORLEVEL% + ) +) + +:: Fail open: drain stdin and output empty JSON +for /f "tokens=*" %%a in ('more') do rem +echo {} +exit /b 0 diff --git a/plugin/scripts/te.cmd b/plugin/scripts/te.cmd new file mode 100644 index 00000000..73128293 --- /dev/null +++ b/plugin/scripts/te.cmd @@ -0,0 +1,40 @@ +@echo off +setlocal +set "DIR=%~dp0" +set "PYTHONUTF8=1" + +:: Explicit TE_PYTHON +if defined TE_PYTHON ( + if exist "%TE_PYTHON%" ( + "%TE_PYTHON%" "%DIR%te_bootstrap.py" cli %* + exit /b %ERRORLEVEL% + ) +) + +:: Find python.exe on PATH, skipping WindowsApps store alias +for /f "tokens=*" %%i in ('where python.exe 2^>nul') do ( + echo %%i | findstr /i /c:"WindowsApps" >nul + if errorlevel 1 ( + "%%i" "%DIR%te_bootstrap.py" cli %* + exit /b %ERRORLEVEL% + ) +) + +:: Try py.exe (-3) launcher +where py.exe >nul 2>&1 +if %ERRORLEVEL% equ 0 ( + py -3 "%DIR%te_bootstrap.py" cli %* + exit /b %ERRORLEVEL% +) + +:: Try python3.exe on PATH +for /f "tokens=*" %%i in ('where python3.exe 2^>nul') do ( + echo %%i | findstr /i /c:"WindowsApps" >nul + if errorlevel 1 ( + "%%i" "%DIR%te_bootstrap.py" cli %* + exit /b %ERRORLEVEL% + ) +) + +echo te: no python3 on PATH (set TE_PYTHON) >&2 +exit /b 1 diff --git a/tests/test_antigravity.py b/tests/test_antigravity.py index af0e07c5..05310727 100644 --- a/tests/test_antigravity.py +++ b/tests/test_antigravity.py @@ -438,7 +438,24 @@ def test_the_plugin_declares_the_three_events_and_never_pretooluse(): assert {e: h[0]["timeout"] for e, h in events.items()} == { "SessionStart": 15, "PreInvocation": 10, "Stop": 10} for event, (handler,) in events.items(): - assert handler["command"] == f"./scripts/te-hook --host antigravity --event {event}" + assert f"--host antigravity --event {event}" in handler["command"] + assert "./scripts/te-hook" in handler["command"] and "te-hook.cmd" in handler["command"] assert os.access(ROOT / "plugin/scripts/te-hook", os.X_OK) + assert (ROOT / "plugin/scripts/te-hook.cmd").is_file() + assert (ROOT / "plugin/scripts/te.cmd").is_file() # no other agent reads the root hook file: Claude Code's is `hooks/hooks.json`. assert "hooks" not in claude + + +def test_antigravity_recognizes_modern_antigravity_tools(tp, tmp_path): + t = Transcript(tp) + t.prompt("modern tools") + t.call([("write_file", {"Path": "/work/repo/b.py"}), + ("edit_file", {"Path": "/work/repo/b.py"})], + [("created", {"type": "GENERIC"}), ("updated", {"type": "GENERIC"})]) + host, work = Antigravity(), tmp_path / "w2" + work.mkdir() + path = host.mechanism_trace(str(tp), str(work)) + traj = trace.load_trajectory(path) + assert ("Write", {"file_path": "/work/repo/b.py"}, "created", True) in traj + assert ("Edit", {"file_path": "/work/repo/b.py"}, "updated", True) in traj \ No newline at end of file diff --git a/tokeneconomizer/trace/antigravity.py b/tokeneconomizer/trace/antigravity.py index e99b68ec..6481b996 100644 --- a/tokeneconomizer/trace/antigravity.py +++ b/tokeneconomizer/trace/antigravity.py @@ -43,7 +43,9 @@ "run_command": ("Bash", {"command": ("CommandLine",)}), "view_file": ("Read", {"file_path": _FILE}), "read_file": ("Read", {"file_path": _FILE}), + "write_file": ("Write", {"file_path": _FILE}), "write_to_file": ("Write", {"file_path": _FILE}), + "edit_file": ("Edit", {"file_path": _FILE}), "replace_file_content": ("Edit", {"file_path": _FILE}), "multi_replace_file_content": ("Edit", {"file_path": _FILE}), "sed_file": ("Edit", {"file_path": _FILE}), From f7cfc93da0fa4a866abfeee8ff5d13e06b6989ff Mon Sep 17 00:00:00 2001 From: Joy Mondal Date: Sat, 14 Nov 2026 22:41:01 +0530 Subject: [PATCH 2/7] refactor(antigravity): defer 2.0 tool mappings to dedicated PR --- tests/test_antigravity.py | 14 -------------- tokeneconomizer/trace/antigravity.py | 2 -- 2 files changed, 16 deletions(-) diff --git a/tests/test_antigravity.py b/tests/test_antigravity.py index 05310727..73ee4986 100644 --- a/tests/test_antigravity.py +++ b/tests/test_antigravity.py @@ -445,17 +445,3 @@ def test_the_plugin_declares_the_three_events_and_never_pretooluse(): assert (ROOT / "plugin/scripts/te.cmd").is_file() # no other agent reads the root hook file: Claude Code's is `hooks/hooks.json`. assert "hooks" not in claude - - -def test_antigravity_recognizes_modern_antigravity_tools(tp, tmp_path): - t = Transcript(tp) - t.prompt("modern tools") - t.call([("write_file", {"Path": "/work/repo/b.py"}), - ("edit_file", {"Path": "/work/repo/b.py"})], - [("created", {"type": "GENERIC"}), ("updated", {"type": "GENERIC"})]) - host, work = Antigravity(), tmp_path / "w2" - work.mkdir() - path = host.mechanism_trace(str(tp), str(work)) - traj = trace.load_trajectory(path) - assert ("Write", {"file_path": "/work/repo/b.py"}, "created", True) in traj - assert ("Edit", {"file_path": "/work/repo/b.py"}, "updated", True) in traj \ No newline at end of file diff --git a/tokeneconomizer/trace/antigravity.py b/tokeneconomizer/trace/antigravity.py index 6481b996..e99b68ec 100644 --- a/tokeneconomizer/trace/antigravity.py +++ b/tokeneconomizer/trace/antigravity.py @@ -43,9 +43,7 @@ "run_command": ("Bash", {"command": ("CommandLine",)}), "view_file": ("Read", {"file_path": _FILE}), "read_file": ("Read", {"file_path": _FILE}), - "write_file": ("Write", {"file_path": _FILE}), "write_to_file": ("Write", {"file_path": _FILE}), - "edit_file": ("Edit", {"file_path": _FILE}), "replace_file_content": ("Edit", {"file_path": _FILE}), "multi_replace_file_content": ("Edit", {"file_path": _FILE}), "sed_file": ("Edit", {"file_path": _FILE}), From e4d70de3bc06c3eab354a6e9dafd6d66a57db287 Mon Sep 17 00:00:00 2001 From: Joy Mondal Date: Sat, 14 Nov 2026 22:42:45 +0530 Subject: [PATCH 3/7] fix(antigravity): invert hook launcher order to prevent POSIX nul file --- plugin/hooks.json | 6 +++--- tests/test_antigravity.py | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/plugin/hooks.json b/plugin/hooks.json index c3be5323..cdca9c4a 100644 --- a/plugin/hooks.json +++ b/plugin/hooks.json @@ -1,13 +1,13 @@ { "tokeneconomizer": { "SessionStart": [ - { "type": "command", "command": "scripts\\te-hook.cmd --host antigravity --event SessionStart 2>nul || ./scripts/te-hook --host antigravity --event SessionStart", "timeout": 15 } + { "type": "command", "command": "./scripts/te-hook --host antigravity --event SessionStart || scripts\\te-hook.cmd --host antigravity --event SessionStart", "timeout": 15 } ], "PreInvocation": [ - { "type": "command", "command": "scripts\\te-hook.cmd --host antigravity --event PreInvocation 2>nul || ./scripts/te-hook --host antigravity --event PreInvocation", "timeout": 10 } + { "type": "command", "command": "./scripts/te-hook --host antigravity --event PreInvocation || scripts\\te-hook.cmd --host antigravity --event PreInvocation", "timeout": 10 } ], "Stop": [ - { "type": "command", "command": "scripts\\te-hook.cmd --host antigravity --event Stop 2>nul || ./scripts/te-hook --host antigravity --event Stop", "timeout": 10 } + { "type": "command", "command": "./scripts/te-hook --host antigravity --event Stop || scripts\\te-hook.cmd --host antigravity --event Stop", "timeout": 10 } ] } } diff --git a/tests/test_antigravity.py b/tests/test_antigravity.py index 73ee4986..2cf9614b 100644 --- a/tests/test_antigravity.py +++ b/tests/test_antigravity.py @@ -438,8 +438,8 @@ def test_the_plugin_declares_the_three_events_and_never_pretooluse(): assert {e: h[0]["timeout"] for e, h in events.items()} == { "SessionStart": 15, "PreInvocation": 10, "Stop": 10} for event, (handler,) in events.items(): - assert f"--host antigravity --event {event}" in handler["command"] - assert "./scripts/te-hook" in handler["command"] and "te-hook.cmd" in handler["command"] + expected = f"./scripts/te-hook --host antigravity --event {event} || scripts\\te-hook.cmd --host antigravity --event {event}" + assert handler["command"] == expected assert os.access(ROOT / "plugin/scripts/te-hook", os.X_OK) assert (ROOT / "plugin/scripts/te-hook.cmd").is_file() assert (ROOT / "plugin/scripts/te.cmd").is_file() From 9b06e57fc43802fc8e99bc02b62edec93880cefa Mon Sep 17 00:00:00 2001 From: Joy Mondal Date: Sat, 14 Nov 2026 22:56:04 +0530 Subject: [PATCH 4/7] fix(launchers): use delayed expansion and probe Python >= 3.10 on Windows --- plugin/scripts/te-hook.cmd | 71 ++++++++++++++++++++++++++------------ plugin/scripts/te.cmd | 67 ++++++++++++++++++++++++----------- tests/test_antigravity.py | 49 ++++++++++++++++++++++++++ 3 files changed, 145 insertions(+), 42 deletions(-) diff --git a/plugin/scripts/te-hook.cmd b/plugin/scripts/te-hook.cmd index 742d7738..ef5dcbaf 100644 --- a/plugin/scripts/te-hook.cmd +++ b/plugin/scripts/te-hook.cmd @@ -1,42 +1,69 @@ @echo off -setlocal +setlocal EnableDelayedExpansion set "DIR=%~dp0" set "PYTHONUTF8=1" -:: Explicit TE_PYTHON +:: 1. Explicit TE_PYTHON override runs as named if defined TE_PYTHON ( - if exist "%TE_PYTHON%" ( - "%TE_PYTHON%" "%DIR%te_bootstrap.py" hook %* - exit /b %ERRORLEVEL% + set "RUN_PY=%TE_PYTHON%" + goto :run_hook +) + +:: Probe script: exits 0 if >= 3.10, exits 1 if older +set "PROBE=import sys; sys.exit(sys.version_info < (3, 10))" +set "OLD_PY=" + +:: 2. Probe py.exe (-3 launcher) +where py.exe >nul 2>&1 +if !ERRORLEVEL! equ 0 ( + py -3 -E -S -c "%PROBE%" >nul 2>&1 + if !ERRORLEVEL! equ 0 ( + set "RUN_PY=py -3" + goto :run_hook + ) else if !ERRORLEVEL! equ 1 ( + if not defined OLD_PY set "OLD_PY=py -3" ) ) -:: Find python.exe on PATH, skipping WindowsApps store alias +:: 3. Probe python.exe on PATH, skipping WindowsApps store alias for /f "tokens=*" %%i in ('where python.exe 2^>nul') do ( - echo %%i | findstr /i /c:"WindowsApps" >nul + echo %%~fi | findstr /i /c:"WindowsApps" >nul if errorlevel 1 ( - "%%i" "%DIR%te_bootstrap.py" hook %* - exit /b %ERRORLEVEL% + "%%~fi" -E -S -c "%PROBE%" >nul 2>&1 + if !ERRORLEVEL! equ 0 ( + set "RUN_PY="%%~fi"" + goto :run_hook + ) else if !ERRORLEVEL! equ 1 ( + if not defined OLD_PY set "OLD_PY="%%~fi"" + ) ) ) -:: Try py.exe (-3) launcher -where py.exe >nul 2>&1 -if %ERRORLEVEL% equ 0 ( - py -3 "%DIR%te_bootstrap.py" hook %* - exit /b %ERRORLEVEL% -) - -:: Try python3.exe on PATH +:: 4. Probe python3.exe on PATH, skipping WindowsApps store alias for /f "tokens=*" %%i in ('where python3.exe 2^>nul') do ( - echo %%i | findstr /i /c:"WindowsApps" >nul + echo %%~fi | findstr /i /c:"WindowsApps" >nul if errorlevel 1 ( - "%%i" "%DIR%te_bootstrap.py" hook %* - exit /b %ERRORLEVEL% + "%%~fi" -E -S -c "%PROBE%" >nul 2>&1 + if !ERRORLEVEL! equ 0 ( + set "RUN_PY="%%~fi"" + goto :run_hook + ) else if !ERRORLEVEL! equ 1 ( + if not defined OLD_PY set "OLD_PY="%%~fi"" + ) ) ) -:: Fail open: drain stdin and output empty JSON -for /f "tokens=*" %%a in ('more') do rem +:: 5. If only older Python was found, hand off to it so bootstrap fails open +if defined OLD_PY ( + set "RUN_PY=%OLD_PY%" + goto :run_hook +) + +:: 6. Fail open: drain stdin and output empty JSON +for /f "tokens=*" %%a in ('more 2^>nul') do rem echo {} exit /b 0 + +:run_hook +%RUN_PY% "%DIR%te_bootstrap.py" hook %* +exit /b !ERRORLEVEL! diff --git a/plugin/scripts/te.cmd b/plugin/scripts/te.cmd index 73128293..e8f9586a 100644 --- a/plugin/scripts/te.cmd +++ b/plugin/scripts/te.cmd @@ -1,40 +1,67 @@ @echo off -setlocal +setlocal EnableDelayedExpansion set "DIR=%~dp0" set "PYTHONUTF8=1" -:: Explicit TE_PYTHON +:: 1. Explicit TE_PYTHON override runs as named if defined TE_PYTHON ( - if exist "%TE_PYTHON%" ( - "%TE_PYTHON%" "%DIR%te_bootstrap.py" cli %* - exit /b %ERRORLEVEL% + set "RUN_PY=%TE_PYTHON%" + goto :run_cli +) + +:: Probe script: exits 0 if >= 3.10, exits 1 if older +set "PROBE=import sys; sys.exit(sys.version_info < (3, 10))" +set "OLD_PY=" + +:: 2. Probe py.exe (-3 launcher) +where py.exe >nul 2>&1 +if !ERRORLEVEL! equ 0 ( + py -3 -E -S -c "%PROBE%" >nul 2>&1 + if !ERRORLEVEL! equ 0 ( + set "RUN_PY=py -3" + goto :run_cli + ) else if !ERRORLEVEL! equ 1 ( + if not defined OLD_PY set "OLD_PY=py -3" ) ) -:: Find python.exe on PATH, skipping WindowsApps store alias +:: 3. Probe python.exe on PATH, skipping WindowsApps store alias for /f "tokens=*" %%i in ('where python.exe 2^>nul') do ( - echo %%i | findstr /i /c:"WindowsApps" >nul + echo %%~fi | findstr /i /c:"WindowsApps" >nul if errorlevel 1 ( - "%%i" "%DIR%te_bootstrap.py" cli %* - exit /b %ERRORLEVEL% + "%%~fi" -E -S -c "%PROBE%" >nul 2>&1 + if !ERRORLEVEL! equ 0 ( + set "RUN_PY="%%~fi"" + goto :run_cli + ) else if !ERRORLEVEL! equ 1 ( + if not defined OLD_PY set "OLD_PY="%%~fi"" + ) ) ) -:: Try py.exe (-3) launcher -where py.exe >nul 2>&1 -if %ERRORLEVEL% equ 0 ( - py -3 "%DIR%te_bootstrap.py" cli %* - exit /b %ERRORLEVEL% -) - -:: Try python3.exe on PATH +:: 4. Probe python3.exe on PATH, skipping WindowsApps store alias for /f "tokens=*" %%i in ('where python3.exe 2^>nul') do ( - echo %%i | findstr /i /c:"WindowsApps" >nul + echo %%~fi | findstr /i /c:"WindowsApps" >nul if errorlevel 1 ( - "%%i" "%DIR%te_bootstrap.py" cli %* - exit /b %ERRORLEVEL% + "%%~fi" -E -S -c "%PROBE%" >nul 2>&1 + if !ERRORLEVEL! equ 0 ( + set "RUN_PY="%%~fi"" + goto :run_cli + ) else if !ERRORLEVEL! equ 1 ( + if not defined OLD_PY set "OLD_PY="%%~fi"" + ) ) ) +:: 5. If only older Python was found, hand off to it so bootstrap reports requirements +if defined OLD_PY ( + set "RUN_PY=%OLD_PY%" + goto :run_cli +) + echo te: no python3 on PATH (set TE_PYTHON) >&2 exit /b 1 + +:run_cli +%RUN_PY% "%DIR%te_bootstrap.py" cli %* +exit /b !ERRORLEVEL! diff --git a/tests/test_antigravity.py b/tests/test_antigravity.py index 2cf9614b..82768691 100644 --- a/tests/test_antigravity.py +++ b/tests/test_antigravity.py @@ -9,6 +9,7 @@ import json import os import subprocess +import sys from pathlib import Path import pytest @@ -445,3 +446,51 @@ def test_the_plugin_declares_the_three_events_and_never_pretooluse(): assert (ROOT / "plugin/scripts/te.cmd").is_file() # no other agent reads the root hook file: Claude Code's is `hooks/hooks.json`. assert "hooks" not in claude + + +def test_windows_hook_launcher_fails_open_with_no_python(): + cmd_script = ROOT / "plugin" / "scripts" / "te-hook.cmd" + if os.name != "nt": + pytest.skip("Windows batch test") + env = {k: os.environ[k] for k in ("SYSTEMROOT", "COMSPEC", "PATHEXT") if k in os.environ} + env["PATH"] = "" + env.pop("TE_PYTHON", None) + p = subprocess.run([str(cmd_script), "--host", "antigravity", "--event", "SessionStart"], + input="{}", text=True, capture_output=True, env=env) + assert p.returncode == 0 + assert json.loads(p.stdout.strip()) == {} + + +def test_windows_te_launcher_reports_missing_python(): + cmd_script = ROOT / "plugin" / "scripts" / "te.cmd" + if os.name != "nt": + pytest.skip("Windows batch test") + env = {k: os.environ[k] for k in ("SYSTEMROOT", "COMSPEC", "PATHEXT") if k in os.environ} + env["PATH"] = "" + env.pop("TE_PYTHON", None) + p = subprocess.run([str(cmd_script), "--host", "antigravity", "status"], + text=True, capture_output=True, env=env) + assert p.returncode == 1 + assert "no python3 on PATH" in p.stderr + + +def test_windows_hook_launcher_executes_with_valid_python(tmp_path): + cmd_script = ROOT / "plugin" / "scripts" / "te-hook.cmd" + if os.name != "nt": + pytest.skip("Windows batch test") + env = {k: os.environ[k] for k in ("SYSTEMROOT", "COMSPEC", "PATHEXT", "TEMP", "TMP") if k in os.environ} + env["PATH"] = f"{os.path.dirname(sys.executable)}{os.pathsep}{os.environ.get('PATH', '')}" + env["TOKENECONOMIZER_HOME"] = str(tmp_path / "home") + payload = { + "hook_event_name": "SessionStart", + "conversationId": CID, + "workspacePaths": [str(tmp_path)], + "transcriptPath": str(tmp_path / "transcript.jsonl"), + "modelName": "m", + "lastUserInput": "test", + } + p = subprocess.run([str(cmd_script), "--host", "antigravity", "--event", "SessionStart"], + input=json.dumps(payload), text=True, capture_output=True, env=env) + assert p.returncode == 0 + assert json.loads(p.stdout.strip()) == {} + From 30ea9932052d0fec9b203dbb07e40b997e277108 Mon Sep 17 00:00:00 2001 From: Joy Mondal Date: Sat, 14 Nov 2026 22:56:54 +0530 Subject: [PATCH 5/7] chore: mark .cmd files eol=crlf in .gitattributes --- .gitattributes | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitattributes b/.gitattributes index e916ab77..081c69ae 100644 --- a/.gitattributes +++ b/.gitattributes @@ -2,3 +2,5 @@ plugin/scripts/te text eol=lf plugin/scripts/te-hook text eol=lf *.sh text eol=lf +*.cmd text eol=crlf + From 3c1ad11e7c2da88e19a8a5fdb7d2bfaff89a8704 Mon Sep 17 00:00:00 2001 From: Joy Mondal Date: Sat, 14 Nov 2026 23:03:53 +0530 Subject: [PATCH 6/7] docs: scope Antigravity support to tested agy and Windows versions --- README.md | 17 +++++++++-------- docs/PLUGIN.md | 21 ++++++++++++--------- plugin/README.md | 15 +++++++++------ 3 files changed, 30 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 2f360a91..e631bd8c 100644 --- a/README.md +++ b/README.md @@ -224,10 +224,10 @@ agy plugin install dist/marketplace/tokeneconomizer ``` Start `agy` and send a prompt in a repository, then check with -`~/.tokeneconomizer/bin/te --host antigravity status`. `agy` has no plugin commands, so the +`~/.tokeneconomizer/bin/te --host antigravity status` (on Windows, run `scripts\te.cmd --host antigravity status` from the plugin directory). `agy` has no plugin commands, so the plugin's commands run from a terminal. The plugin makes no model call through `agy`, which has no option that runs a prompt with every tool off, so the paid proposer and the loop guard are off -and tool pruning is not available. Works across Windows, macOS, and Linux (with dual .cmd/.sh launchers). +and tool pruning is not available. Works across Windows, macOS, and Linux with native Windows batch launchers (`scripts\te-hook.cmd`, `scripts\te.cmd`). Tested on `agy` 1.5.1 and 1.5.2 on Windows 11, macOS, and Linux. See [its limits](plugin/README.md#antigravity-cli). **opencode** (experimental) @@ -287,7 +287,7 @@ uninstalling, using Copilot with your own model key, and troubleshooting. | Grok Build (experimental) | 1.0.70 | not tested | | opencode (experimental) | 1.19.5 and 2.2.0 | not tested | | Hermes Agent (experimental) | 0.22.5 | not tested | -| Antigravity CLI & 2.0 (experimental) | agy 1.5.1+, Windows, macOS and Linux | not tested | +| Antigravity CLI (experimental) | agy 1.5.1 and 1.5.2, Windows 11, macOS and Linux | not tested | | Factory Droid (experimental) | 0.233.0, macOS (below) | not tested | The commands above were tested on the oldest and newest version in each range; newer versions @@ -308,9 +308,10 @@ have not been tested yet. - **Grok Build** support is experimental: it was verified on 1.0.70 only, against its documented hook contract and live hook payloads. Learned facts reach the model with the session's first tool call, and tool pruning is not available. See [its limits](plugin/README.md#grok-build). -- **Antigravity CLI** support is experimental: it was written against agy 1.5.1's hook contract - and transcript format, which are not a public interface, and only micro-skills' LLM-free facts - are supported: the plugin makes no model call through `agy`. See [its limits](plugin/README.md#antigravity-cli). +- **Antigravity CLI** support is experimental: it was tested against agy 1.5.1 and 1.5.2 on Windows 11, + macOS, and Linux. It was written against agy's hook contract and transcript format, which are not a + public interface, and only micro-skills' LLM-free facts are supported: the plugin makes no model call + through `agy`. See [its limits](plugin/README.md#antigravity-cli). - **Hermes Agent** support is experimental: it was tested on 0.22.5 only, with a scripted local model and one free real model, on the classic CLI and one-shot runs only. Micro-skills and a redirect reaching a real model are verified there; the still-stuck notice reaching a person is @@ -339,7 +340,7 @@ commands. They have the same names on every agent; only the way you type them di | Cursor Agent | from a terminal: `~/.tokeneconomizer/bin/te --host cursor ` | | Grok Build | from a terminal: `~/.tokeneconomizer/bin/te --host grok ` | | Hermes Agent | from a terminal: `~/.tokeneconomizer/bin/te --host hermes ` | -| Antigravity CLI | from a terminal: `~/.tokeneconomizer/bin/te --host antigravity ` | +| Antigravity CLI | from a terminal: `~/.tokeneconomizer/bin/te --host antigravity ` (on Windows: `scripts\te.cmd --host antigravity ` from the plugin directory, or `python -m tokeneconomizer.plugin.cli --host antigravity `) | | Factory Droid | `/tokeneconomizer-` (e.g. `/tokeneconomizer-status`) | | a terminal, in the repository | `~/.tokeneconomizer/bin/te ` | @@ -352,7 +353,7 @@ commands. They have the same names on every agent; only the way you type them di | `config` | every setting in effect | | `config set microskills=on` | turn a mechanism on (or `=off`) in this repository; add `--global` for every repository | -Inside an agent, a command costs one model turn; from a terminal it is free. The other commands +Inside an agent, a command costs one model turn; from a terminal it is free. `~/.tokeneconomizer/bin/te` is a POSIX shell script; on Windows, run `scripts\te.cmd` from the plugin directory (or `python -m tokeneconomizer.plugin.cli`). The other commands (`repos`, `doctor`, `config unset`, ...) and each agent's permission prompts are listed under [Commands](plugin/README.md#commands). diff --git a/docs/PLUGIN.md b/docs/PLUGIN.md index 44336629..36b6555b 100644 --- a/docs/PLUGIN.md +++ b/docs/PLUGIN.md @@ -838,14 +838,15 @@ open-vocabulary. On a repository you do not trust, leave micro-skills off (the d * **Hermes Agent** — experimental: micro-skills and the loop guard, on the classic CLI and one-shot runs, verified with a scripted model and one free real model. Its limits are listed in `plugin/README.md`. -* **Antigravity CLI (`agy`, experimental)** — micro-skills' LLM-free facts, written against - agy 1.5.1 and its own installed hook documentation; tool pruning is not implemented. The - plugin makes no model call through `agy`, which has no option that runs a prompt with every tool - off (`sidecall.NO_SIDE_CALLS`), so the paid proposer and the loop guard's judge never run. What - was captured live: hooks come from a `hooks.json` at the plugin root, run through `sh -c` in - that directory, with camelCase payloads that name no event (the hook file's command does, - `--event`) and leave out a zero (`invocationNum` 0, the first model call of a prompt). A - `PreToolUse` hook that prints `{}` makes agy deny the tool, so none is registered; +* **Antigravity CLI (`agy`, experimental)** — micro-skills' LLM-free facts, tested against + `agy` 1.5.1 and 1.5.2 on Windows 11, macOS, and Linux, using its installed hook documentation; + tool pruning is not implemented. The plugin makes no model call through `agy`, which has no + option that runs a prompt with every tool off (`sidecall.NO_SIDE_CALLS`), so the paid proposer + and the loop guard's judge never run. What was captured live: hooks come from a `hooks.json` at + the plugin root, invoking `./scripts/te-hook` on macOS/Linux and native batch launcher + `scripts\te-hook.cmd` on Windows, with camelCase payloads that name no event (the hook file's + command does, `--event`) and leave out a zero (`invocationNum` 0, the first model call of a + prompt). A `PreToolUse` hook that prints `{}` makes agy deny the tool, so none is registered; `PostToolUse` carries no tool result and a matcher `"*"` never matches, so the results are read from the conversation's `transcript_full.jsonl` at the next `PreInvocation` and at `Stop`, where every result of the previous model call is already written (`trace/antigravity.py`). There is no @@ -855,7 +856,9 @@ open-vocabulary. On a repository you do not trust, leave micro-skills off (the d `SessionStart`, an `ephemeralMessage` (dropped after the turn) at `PreInvocation`. Calls a subagent makes are not in the transcript and are not seen. Transcript token fields are absent from older agy versions (unknown, not zero), and the transcript names no model, so session cost is priced - on the ledger's labelled fallback. Works across Windows, macOS, and Linux. + on the ledger's labelled fallback. Works across Windows, macOS, and Linux (tested on `agy` 1.5.1 + and 1.5.2 on Windows 11, macOS, and Linux; on Windows, terminal commands run via `scripts\te.cmd` + from the plugin directory). * **Factory Droid (experimental)** — micro-skills, the loop guard and session cost, on 0.233.0 (macOS). No tool pruning: the TUI has no persistent per-tool setting (Factory issue #65). Side calls are off until `droid_sidecall` is on; see `docs/DROID.md`. diff --git a/plugin/README.md b/plugin/README.md index f8286dbc..053cdae1 100644 --- a/plugin/README.md +++ b/plugin/README.md @@ -547,7 +547,7 @@ log a warning for the empty section of a session with no facts. ## Antigravity CLI -Experimental: **micro-skills' LLM-free facts**, written against `agy` 1.5.1+ and Antigravity 2.0 on Windows, macOS and Linux. +Experimental: **micro-skills' LLM-free facts**, tested against `agy` 1.5.1 and 1.5.2 on Windows 11, macOS and Linux. **1. Install.** Build the self-contained plugin, which copies the package into it, and install the directory: @@ -562,8 +562,9 @@ from `hooks.json` at the plugin root; the `hooks/hooks.json` beside it is Claude validator says it is never loaded. **2. Check it.** Run a session, then `~/.tokeneconomizer/bin/te --host antigravity status` in the -repository. agy plugins load no slash commands, so every command runs from a terminal. Micro-skills -is off by default: `te --host antigravity config set microskills=envfacts`. +repository (on Windows, run `scripts\te.cmd --host antigravity status` from the plugin directory). +agy plugins load no slash commands, so every command runs from a terminal. Micro-skills +is off by default: `te --host antigravity config set microskills=envfacts` (on Windows: `scripts\te.cmd --host antigravity config set microskills=envfacts`). **How it works, and what it does not do.** @@ -710,7 +711,7 @@ How to run them: | opencode | none (run from a terminal) | `~/.tokeneconomizer/bin/te --host opencode ` | | Grok Build | none (run from a terminal) | `~/.tokeneconomizer/bin/te --host grok ` | | Hermes Agent | none (run from a terminal) | `~/.tokeneconomizer/bin/te --host hermes ` | -| Antigravity CLI | none (run from a terminal) | `~/.tokeneconomizer/bin/te --host antigravity ` | +| Antigravity CLI | none (run from a terminal) | `~/.tokeneconomizer/bin/te --host antigravity ` (on Windows: `scripts\te.cmd --host antigravity ` from the plugin directory) | | Factory Droid | `/tokeneconomizer-` | `~/.tokeneconomizer/bin/te --host droid ` | `doctor`, `history` and `repomap` run from a terminal (or as `/te …` on Pi); there is no slash command or @@ -722,7 +723,9 @@ writes outside Codex's sandbox: choose **Yes, proceed**. The Copilot CLI runs th its interactive mode only and asks before each: choose **Yes**. The launcher in `~/.tokeneconomizer/bin` is written by the first session; before that, use -`/path/to/TokenEconomizer/plugin/scripts/te`. From a plain terminal, `--host` defaults to the +`/path/to/TokenEconomizer/plugin/scripts/te`. Note that `~/.tokeneconomizer/bin/te` is a POSIX +shell script; on Windows, run `scripts\te.cmd` from the plugin directory (or `python -m tokeneconomizer.plugin.cli`). +From a plain terminal, `--host` defaults to the agent that last worked in the repository. ## Settings @@ -738,7 +741,7 @@ and are shared by every agent working in it. The examples use Claude Code's form | Codex | `$tokeneconomizer:config set loopguard=off` | | Copilot CLI | `/tokeneconomizer:config set loopguard=off` (interactive mode) | | Pi | `/te config set loopguard=off` | -| any agent, from a terminal | `~/.tokeneconomizer/bin/te config set loopguard=off` | +| any agent, from a terminal | `~/.tokeneconomizer/bin/te config set loopguard=off` (on Windows: `scripts\te.cmd config set loopguard=off`) | **Turn a mechanism on or off:** From a96776a0364603cabfc862a5661ef64f1c1674b8 Mon Sep 17 00:00:00 2001 From: Aaron Date: Sun, 15 Nov 2026 20:30:08 -0800 Subject: [PATCH 7/7] antigravity: pass over a TE_PYTHON that is not there; Windows commands run in the repository The .cmd launchers ran TE_PYTHON unquoted and without checking it: a path under "Program Files" split at the space, one under "Program Files (x86)" ended the `if` block early, and a stale one made cmd exit 9009 without the hook printing {}. TE_PYTHON now runs, quoted, when it is there as a file or as a command on PATH, and is otherwise passed over for the probes, as the sh launchers do. Tests: a stale TE_PYTHON (hook answers {}; te says what it needs) and one under "Program Files (x86)" (it is the Python that runs). The Windows instructions ran scripts\te.cmd from the plugin directory, but te takes the repository from the current directory, so status and config set acted on the plugin directory; and `python -m tokeneconomizer.plugin.cli` fails for the bundle install, whose package is under \lib. They now run \scripts\te.cmd in the repository, say where is (the bootstrap path in te.json, which the first session writes on Windows), and stay in the Antigravity sections: the shared terminal paragraph, the launcher note and the settings row are back as on main. Also drops the blank line the PR left at the end of .gitattributes. Co-Authored-By: Claude Opus 5.5 --- .gitattributes | 1 - README.md | 6 ++-- docs/PLUGIN.md | 4 +-- plugin/README.md | 13 ++++----- plugin/scripts/te-hook.cmd | 19 +++++++++++-- plugin/scripts/te.cmd | 19 +++++++++++-- tests/test_antigravity.py | 56 ++++++++++++++++++++++++++++++++++++++ 7 files changed, 99 insertions(+), 19 deletions(-) diff --git a/.gitattributes b/.gitattributes index 081c69ae..4ee40297 100644 --- a/.gitattributes +++ b/.gitattributes @@ -3,4 +3,3 @@ plugin/scripts/te text eol=lf plugin/scripts/te-hook text eol=lf *.sh text eol=lf *.cmd text eol=crlf - diff --git a/README.md b/README.md index e631bd8c..e52556d2 100644 --- a/README.md +++ b/README.md @@ -224,7 +224,7 @@ agy plugin install dist/marketplace/tokeneconomizer ``` Start `agy` and send a prompt in a repository, then check with -`~/.tokeneconomizer/bin/te --host antigravity status` (on Windows, run `scripts\te.cmd --host antigravity status` from the plugin directory). `agy` has no plugin commands, so the +`~/.tokeneconomizer/bin/te --host antigravity status` (on Windows, `\scripts\te.cmd --host antigravity status`, run in the repository; `` is the folder above `scripts\te_bootstrap.py` in `%USERPROFILE%\.tokeneconomizer\bin\te.json`, which the first session writes). `agy` has no plugin commands, so the plugin's commands run from a terminal. The plugin makes no model call through `agy`, which has no option that runs a prompt with every tool off, so the paid proposer and the loop guard are off and tool pruning is not available. Works across Windows, macOS, and Linux with native Windows batch launchers (`scripts\te-hook.cmd`, `scripts\te.cmd`). Tested on `agy` 1.5.1 and 1.5.2 on Windows 11, macOS, and Linux. @@ -340,7 +340,7 @@ commands. They have the same names on every agent; only the way you type them di | Cursor Agent | from a terminal: `~/.tokeneconomizer/bin/te --host cursor ` | | Grok Build | from a terminal: `~/.tokeneconomizer/bin/te --host grok ` | | Hermes Agent | from a terminal: `~/.tokeneconomizer/bin/te --host hermes ` | -| Antigravity CLI | from a terminal: `~/.tokeneconomizer/bin/te --host antigravity ` (on Windows: `scripts\te.cmd --host antigravity ` from the plugin directory, or `python -m tokeneconomizer.plugin.cli --host antigravity `) | +| Antigravity CLI | from a terminal: `~/.tokeneconomizer/bin/te --host antigravity ` (on Windows: `\scripts\te.cmd --host antigravity `, in the repository) | | Factory Droid | `/tokeneconomizer-` (e.g. `/tokeneconomizer-status`) | | a terminal, in the repository | `~/.tokeneconomizer/bin/te ` | @@ -353,7 +353,7 @@ commands. They have the same names on every agent; only the way you type them di | `config` | every setting in effect | | `config set microskills=on` | turn a mechanism on (or `=off`) in this repository; add `--global` for every repository | -Inside an agent, a command costs one model turn; from a terminal it is free. `~/.tokeneconomizer/bin/te` is a POSIX shell script; on Windows, run `scripts\te.cmd` from the plugin directory (or `python -m tokeneconomizer.plugin.cli`). The other commands +Inside an agent, a command costs one model turn; from a terminal it is free. The other commands (`repos`, `doctor`, `config unset`, ...) and each agent's permission prompts are listed under [Commands](plugin/README.md#commands). diff --git a/docs/PLUGIN.md b/docs/PLUGIN.md index 36b6555b..82a1ccc6 100644 --- a/docs/PLUGIN.md +++ b/docs/PLUGIN.md @@ -857,8 +857,8 @@ open-vocabulary. On a repository you do not trust, leave micro-skills off (the d makes are not in the transcript and are not seen. Transcript token fields are absent from older agy versions (unknown, not zero), and the transcript names no model, so session cost is priced on the ledger's labelled fallback. Works across Windows, macOS, and Linux (tested on `agy` 1.5.1 - and 1.5.2 on Windows 11, macOS, and Linux; on Windows, terminal commands run via `scripts\te.cmd` - from the plugin directory). + and 1.5.2 on Windows 11, macOS, and Linux; on Windows, terminal commands run through the plugin's + `scripts\te.cmd`, in the repository). * **Factory Droid (experimental)** — micro-skills, the loop guard and session cost, on 0.233.0 (macOS). No tool pruning: the TUI has no persistent per-tool setting (Factory issue #65). Side calls are off until `droid_sidecall` is on; see `docs/DROID.md`. diff --git a/plugin/README.md b/plugin/README.md index 053cdae1..7b8de5df 100644 --- a/plugin/README.md +++ b/plugin/README.md @@ -562,9 +562,10 @@ from `hooks.json` at the plugin root; the `hooks/hooks.json` beside it is Claude validator says it is never loaded. **2. Check it.** Run a session, then `~/.tokeneconomizer/bin/te --host antigravity status` in the -repository (on Windows, run `scripts\te.cmd --host antigravity status` from the plugin directory). +repository (on Windows, `\scripts\te.cmd --host antigravity status` in the repository; +`` is the folder above `scripts\te_bootstrap.py` in `%USERPROFILE%\.tokeneconomizer\bin\te.json`, which the first session writes). agy plugins load no slash commands, so every command runs from a terminal. Micro-skills -is off by default: `te --host antigravity config set microskills=envfacts` (on Windows: `scripts\te.cmd --host antigravity config set microskills=envfacts`). +is off by default: `te --host antigravity config set microskills=envfacts` (on Windows: `\scripts\te.cmd --host antigravity config set microskills=envfacts`). **How it works, and what it does not do.** @@ -711,7 +712,7 @@ How to run them: | opencode | none (run from a terminal) | `~/.tokeneconomizer/bin/te --host opencode ` | | Grok Build | none (run from a terminal) | `~/.tokeneconomizer/bin/te --host grok ` | | Hermes Agent | none (run from a terminal) | `~/.tokeneconomizer/bin/te --host hermes ` | -| Antigravity CLI | none (run from a terminal) | `~/.tokeneconomizer/bin/te --host antigravity ` (on Windows: `scripts\te.cmd --host antigravity ` from the plugin directory) | +| Antigravity CLI | none (run from a terminal) | `~/.tokeneconomizer/bin/te --host antigravity ` (on Windows: `\scripts\te.cmd --host antigravity `, in the repository) | | Factory Droid | `/tokeneconomizer-` | `~/.tokeneconomizer/bin/te --host droid ` | `doctor`, `history` and `repomap` run from a terminal (or as `/te …` on Pi); there is no slash command or @@ -723,9 +724,7 @@ writes outside Codex's sandbox: choose **Yes, proceed**. The Copilot CLI runs th its interactive mode only and asks before each: choose **Yes**. The launcher in `~/.tokeneconomizer/bin` is written by the first session; before that, use -`/path/to/TokenEconomizer/plugin/scripts/te`. Note that `~/.tokeneconomizer/bin/te` is a POSIX -shell script; on Windows, run `scripts\te.cmd` from the plugin directory (or `python -m tokeneconomizer.plugin.cli`). -From a plain terminal, `--host` defaults to the +`/path/to/TokenEconomizer/plugin/scripts/te`. From a plain terminal, `--host` defaults to the agent that last worked in the repository. ## Settings @@ -741,7 +740,7 @@ and are shared by every agent working in it. The examples use Claude Code's form | Codex | `$tokeneconomizer:config set loopguard=off` | | Copilot CLI | `/tokeneconomizer:config set loopguard=off` (interactive mode) | | Pi | `/te config set loopguard=off` | -| any agent, from a terminal | `~/.tokeneconomizer/bin/te config set loopguard=off` (on Windows: `scripts\te.cmd config set loopguard=off`) | +| any agent, from a terminal | `~/.tokeneconomizer/bin/te config set loopguard=off` | **Turn a mechanism on or off:** diff --git a/plugin/scripts/te-hook.cmd b/plugin/scripts/te-hook.cmd index ef5dcbaf..2a953328 100644 --- a/plugin/scripts/te-hook.cmd +++ b/plugin/scripts/te-hook.cmd @@ -3,11 +3,24 @@ setlocal EnableDelayedExpansion set "DIR=%~dp0" set "PYTHONUTF8=1" -:: 1. Explicit TE_PYTHON override runs as named -if defined TE_PYTHON ( - set "RUN_PY=%TE_PYTHON%" +:: 1. TE_PYTHON is the person's own choice: it runs as named when it is there, as a file or as +:: a command on PATH. One that is not there is passed over for the probes below, as the sh +:: launchers do, so a stale setting cannot keep the hook from answering. The name is read with +:: delayed expansion and run in quotes: a path with spaces or parentheses +:: ("C:\Program Files (x86)\...") stays one word and cannot end an `if` block early. +if not defined TE_PYTHON goto :probe +set "TE_PY=%TE_PYTHON:"=%" +if exist "!TE_PY!" ( + set "RUN_PY="!TE_PY!"" goto :run_hook ) +where /q "!TE_PY!" >nul 2>&1 +if !ERRORLEVEL! equ 0 ( + set "RUN_PY="!TE_PY!"" + goto :run_hook +) + +:probe :: Probe script: exits 0 if >= 3.10, exits 1 if older set "PROBE=import sys; sys.exit(sys.version_info < (3, 10))" diff --git a/plugin/scripts/te.cmd b/plugin/scripts/te.cmd index e8f9586a..eb4a83a3 100644 --- a/plugin/scripts/te.cmd +++ b/plugin/scripts/te.cmd @@ -3,11 +3,24 @@ setlocal EnableDelayedExpansion set "DIR=%~dp0" set "PYTHONUTF8=1" -:: 1. Explicit TE_PYTHON override runs as named -if defined TE_PYTHON ( - set "RUN_PY=%TE_PYTHON%" +:: 1. TE_PYTHON is the person's own choice: it runs as named when it is there, as a file or as +:: a command on PATH. One that is not there is passed over for the probes below, as the sh +:: launchers do, so a stale setting cannot keep the hook from answering. The name is read with +:: delayed expansion and run in quotes: a path with spaces or parentheses +:: ("C:\Program Files (x86)\...") stays one word and cannot end an `if` block early. +if not defined TE_PYTHON goto :probe +set "TE_PY=%TE_PYTHON:"=%" +if exist "!TE_PY!" ( + set "RUN_PY="!TE_PY!"" goto :run_cli ) +where /q "!TE_PY!" >nul 2>&1 +if !ERRORLEVEL! equ 0 ( + set "RUN_PY="!TE_PY!"" + goto :run_cli +) + +:probe :: Probe script: exits 0 if >= 3.10, exits 1 if older set "PROBE=import sys; sys.exit(sys.version_info < (3, 10))" diff --git a/tests/test_antigravity.py b/tests/test_antigravity.py index 82768691..bd88493d 100644 --- a/tests/test_antigravity.py +++ b/tests/test_antigravity.py @@ -494,3 +494,59 @@ def test_windows_hook_launcher_executes_with_valid_python(tmp_path): assert p.returncode == 0 assert json.loads(p.stdout.strip()) == {} + +def test_windows_hook_launcher_passes_over_a_te_python_that_is_not_there(): + """A stale TE_PYTHON is passed over for the probes, as the sh launchers do: the hook still + answers instead of failing with cmd's "is not recognized".""" + cmd_script = ROOT / "plugin" / "scripts" / "te-hook.cmd" + if os.name != "nt": + pytest.skip("Windows batch test") + env = {k: os.environ[k] for k in ("SYSTEMROOT", "COMSPEC", "PATHEXT") if k in os.environ} + env["PATH"] = "" + env["TE_PYTHON"] = r"C:\no such folder (x86)\python.exe" + p = subprocess.run([str(cmd_script), "--host", "antigravity", "--event", "SessionStart"], + input="{}", text=True, capture_output=True, env=env) + assert p.returncode == 0, p.stderr + assert json.loads(p.stdout.strip()) == {} + + +def test_windows_hook_launcher_runs_a_te_python_under_a_path_with_spaces(tmp_path): + """TE_PYTHON under "Program Files (x86)" runs as one word, and is the Python that runs.""" + cmd_script = ROOT / "plugin" / "scripts" / "te-hook.cmd" + if os.name != "nt": + pytest.skip("Windows batch test") + folder = tmp_path / "Program Files (x86)" / "Python" + folder.mkdir(parents=True) + marker = tmp_path / "te_python_ran" + shim = folder / "python.cmd" + shim.write_text(f'@echo ran>"{marker}"\n@"{sys.executable}" %*\n') + env = {k: os.environ[k] for k in ("SYSTEMROOT", "COMSPEC", "PATHEXT", "TEMP", "TMP") if k in os.environ} + env["PATH"] = f"{os.path.dirname(sys.executable)}{os.pathsep}{os.environ.get('PATH', '')}" + env["TOKENECONOMIZER_HOME"] = str(tmp_path / "home") + env["TE_PYTHON"] = str(shim) + payload = { + "hook_event_name": "SessionStart", + "conversationId": CID, + "workspacePaths": [str(tmp_path)], + "transcriptPath": str(tmp_path / "transcript.jsonl"), + "modelName": "m", + "lastUserInput": "test", + } + p = subprocess.run([str(cmd_script), "--host", "antigravity", "--event", "SessionStart"], + input=json.dumps(payload), text=True, capture_output=True, env=env) + assert p.returncode == 0, p.stderr + assert json.loads(p.stdout.strip()) == {} + assert marker.exists() + + +def test_windows_te_launcher_passes_over_a_te_python_that_is_not_there(): + cmd_script = ROOT / "plugin" / "scripts" / "te.cmd" + if os.name != "nt": + pytest.skip("Windows batch test") + env = {k: os.environ[k] for k in ("SYSTEMROOT", "COMSPEC", "PATHEXT") if k in os.environ} + env["PATH"] = "" + env["TE_PYTHON"] = r"C:\no such folder (x86)\python.exe" + p = subprocess.run([str(cmd_script), "--host", "antigravity", "status"], + text=True, capture_output=True, env=env) + assert p.returncode == 1 + assert "no python3 on PATH" in p.stderr