plugin.py 949 B

12345678910111213141516171819202122232425262728293031
  1. """The plugin's fixed names, and its own manifest."""
  2. from __future__ import annotations
  3. import re
  4. from pathlib import Path
  5. from . import strictjson
  6. from .strictjson import is_map, is_str
  7. NAME = "claude-security"
  8. ROOT = Path(__file__).resolve().parents[2]
  9. RUN_DIR_NAME = ".claude-security-run"
  10. MODES = ("scan", "changes", "commit")
  11. REPORT_DIR_PREFIX = "CLAUDE-SECURITY-"
  12. # \Z, not $: `$` also matches before a trailing newline, and this id names product files.
  13. SHA_RE = re.compile(r"^[0-9a-fA-F]{7,64}\Z")
  14. def version() -> str | None:
  15. """The non-blank version string in the plugin's manifest, or None when there is not one."""
  16. try:
  17. manifest = strictjson.load(ROOT / ".claude-plugin" / "plugin.json")
  18. except (OSError, ValueError):
  19. return None
  20. if not is_map(manifest):
  21. return None
  22. declared = manifest.get("version")
  23. if not is_str(declared):
  24. return None
  25. return declared.strip() or None