diff options
| author | Claude <noreply@anthropic.com> | 2026-10-20 22:36:29 +0000 |
|---|---|---|
| committer | Claude <noreply@anthropic.com> | 2026-10-20 22:36:29 +0000 |
| commit | 6d4e17c8c4d45de2eba6dce119e56fff18ae43b1 (patch) | |
| tree | 701885afff4bfa63b7dbf1b7c8af7492e9aa90a0 /plugins/security-guidance/hooks/_base.py | |
| parent | d2919136660832d06d5260677b256033c7dbdbda (diff) | |
| parent | beecef224291d252a87f58c5e83df28d15fe3450 (diff) | |
Merge branch 'main' into mhegazy/sg-launcher-probe-timingmhegazy/sg-launcher-probe-timing
Diffstat (limited to 'plugins/security-guidance/hooks/_base.py')
| -rw-r--r-- | plugins/security-guidance/hooks/_base.py | 53 |
1 files changed, 48 insertions, 5 deletions
diff --git a/plugins/security-guidance/hooks/_base.py b/plugins/security-guidance/hooks/_base.py index 0ec54e35..e5959e68 100644 --- a/plugins/security-guidance/hooks/_base.py +++ b/plugins/security-guidance/hooks/_base.py @@ -5,6 +5,7 @@ This module exists so that ``patterns``/``session_state``/``gitutil`` can use ``debug_log`` without importing ``security_reminder_hook`` (which would be a circular import). It must stay free of any other intra-plugin imports. """ +import glob import json import os import re @@ -33,11 +34,53 @@ def state_dir(): """ explicit = os.environ.get("SECURITY_WARNINGS_STATE_DIR") if explicit: - return os.path.expanduser(explicit) - cc_config = os.environ.get("CLAUDE_CONFIG_DIR") - if cc_config: - return os.path.expanduser(os.path.join(cc_config, "security")) - return os.path.expanduser("~/.claude/security") + d = explicit + elif os.environ.get("CLAUDE_CONFIG_DIR"): + d = os.path.join(os.environ["CLAUDE_CONFIG_DIR"], "security") + else: + d = "~/.claude/security" + return os.path.abspath(os.path.expanduser(d)) + + +def llm_reviews_switched_off(): + """True when the environment turns off every review that calls a model: + the kill switch (SECURITY_GUIDANCE_DISABLE=1 / ENABLE_SECURITY_REMINDER=0), + ENABLE_CODE_SECURITY_REVIEW=0, or ENABLE_STOP_REVIEW=0 together with + ENABLE_COMMIT_REVIEW=0. Nothing loads the agent SDK then, so nothing + should install it. Same reading of each variable as + security_reminder_hook.py.""" + env = os.environ.get + if env("SECURITY_GUIDANCE_DISABLE", "").strip().lower() in ("1", "true", "yes", "on"): + return True + if env("ENABLE_SECURITY_REMINDER", "1") == "0": + return True + if env("ENABLE_CODE_SECURITY_REVIEW", "1") == "0": + return True + return env("ENABLE_STOP_REVIEW", "1") == "0" and env("ENABLE_COMMIT_REVIEW", "1") == "0" + + +def agent_sdk_site_dirs(state_dir): + """Directories under the state dir that ensure_agent_sdk.py installs the + agent SDK into and llm.py adds to sys.path: the venv's site-packages + (POSIX `lib/pythonX.Y/site-packages`, Windows `Lib/site-packages`) and + the flat `pip install --target` fallback.""" + venv_root = os.path.join(state_dir, "agent-sdk-venv") + return ( + glob.glob(os.path.join(venv_root, "lib", "python*", "site-packages")) + + glob.glob(os.path.join(venv_root, "Lib", "site-packages")) + + [os.path.join(state_dir, "agent-sdk-libs")] + ) + + +def agent_sdk_installed(state_dir): + """True iff one of those directories holds a finished install of the SDK: + its package and the metadata pip writes once the package is unpacked. A + file check only, no import.""" + return any( + os.path.isfile(os.path.join(d, "claude_agent_sdk", "__init__.py")) + and glob.glob(os.path.join(d, "claude_agent_sdk-*.dist-info")) + for d in agent_sdk_site_dirs(state_dir) + ) # Debug log file. Lives under the plugin state dir (default ~/.claude/security/) |
