summaryrefslogtreecommitdiff
path: root/plugins/security-guidance/hooks/llm.py
diff options
context:
space:
mode:
authorMohamed Hegazy <mhegazy@anthropic.com>2026-05-27 14:50:51 -0700
committerMohamed Hegazy <mhegazy@anthropic.com>2026-05-27 14:50:51 -0700
commit4decd2e3b26f6c17e458fcdcf2dd60aef8566f3e (patch)
treefb67c754e22843ed4f6ecb3b7e3042c1a62e0201 /plugins/security-guidance/hooks/llm.py
parente77ff913adf42724268d1fa22f8f241b51ae7d61 (diff)
Enable agentic commit reviewer on Windows
The agentic reviewer is silently no-op on Windows today. SessionStart bootstrap (ensure_agent_sdk.py) short-circuits with SKIP_WIN32 because the consumer glob in llm.py only matches POSIX venv layout (lib/pythonX.Y/site-packages). On Windows, venvs use Lib/site-packages (capital L, no pythonX.Y subdir), so even if a venv got built the glob wouldn't find its contents. Result: Windows users on default installs (no system-wide claude_agent_sdk) get layer 1 (pattern warnings) and layer 2 (single- shot LLM diff review) but not layer 3 — the cross-file agentic review that catches IDOR, auth-bypass, cross-file SSRF, and other things that need to read related files. Plugin description claims layer 3 but it silently doesn't run. Three changes: 1. llm.py — extend the consumer glob (2 sites: 3P SDK fallback at ~L297, agentic_review fallback at ~L1090) to also match the Windows Lib/site-packages layout, so a venv built on Windows is actually discoverable. 2. ensure_agent_sdk.py — remove the sys.platform == 'win32' early-exit so the SessionStart bootstrap builds the venv on Windows too. Outcome code 4 (formerly SKIP_WIN32) is retired but not reused so pre-fix telemetry rows still decode correctly. 3. ensure_agent_sdk.py — venv_py path now branches on sys.platform: Windows venvs put the interpreter at Scripts\python.exe; POSIX uses bin/python. Previously assumed POSIX, so even with the glob fix, the post-build SDK-importability probe would fail on Windows. Verified locally on macOS: - glob test: both layouts now match (POSIX venv detected, simulated Windows venv also detected via the new Lib/site-packages branch) - both files pass py_compile - POSIX path unchanged (sys.platform != 'win32' so old branch runs) Not verified on Windows in this commit — needs an actual Windows runner to confirm the venv build + SDK import + subprocess plumbing all work end-to-end. The SDK spawns a child claude.exe; Windows process plumbing has its own quirks (shell semantics, path escaping) that may surface separately. Worth a controlled rollout (one-week soak under env-var opt-in before flipping default). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'plugins/security-guidance/hooks/llm.py')
-rw-r--r--plugins/security-guidance/hooks/llm.py18
1 files changed, 12 insertions, 6 deletions
diff --git a/plugins/security-guidance/hooks/llm.py b/plugins/security-guidance/hooks/llm.py
index eff56de7..11ef6ce9 100644
--- a/plugins/security-guidance/hooks/llm.py
+++ b/plugins/security-guidance/hooks/llm.py
@@ -298,9 +298,12 @@ def _call_claude_via_sdk(prompt, output_schema, *, max_tokens=16000, model=None)
"SECURITY_WARNINGS_STATE_DIR",
os.path.expanduser("~/.claude/security"),
)
- for _sp in glob.glob(
- os.path.join(_state_dir, "agent-sdk-venv", "lib",
- "python*", "site-packages")
+ # POSIX venv: lib/pythonX.Y/site-packages
+ # Windows venv: Lib/site-packages (capital L, no pythonX.Y subdir)
+ _venv_root = os.path.join(_state_dir, "agent-sdk-venv")
+ for _sp in (
+ glob.glob(os.path.join(_venv_root, "lib", "python*", "site-packages"))
+ + glob.glob(os.path.join(_venv_root, "Lib", "site-packages"))
):
if os.path.isdir(_sp) and _sp not in sys.path:
sys.path.insert(0, _sp)
@@ -1094,9 +1097,12 @@ def agentic_review(
"SECURITY_WARNINGS_STATE_DIR",
os.path.expanduser("~/.claude/security"),
)
- for _sp in glob.glob(
- os.path.join(_state_dir, "agent-sdk-venv", "lib",
- "python*", "site-packages")
+ # POSIX venv: lib/pythonX.Y/site-packages
+ # Windows venv: Lib/site-packages (capital L, no pythonX.Y subdir)
+ _venv_root = os.path.join(_state_dir, "agent-sdk-venv")
+ for _sp in (
+ glob.glob(os.path.join(_venv_root, "lib", "python*", "site-packages"))
+ + glob.glob(os.path.join(_venv_root, "Lib", "site-packages"))
):
if os.path.isdir(_sp) and _sp not in sys.path:
sys.path.insert(0, _sp)