Problem
The current pre-commit hook (.zerg/hooks/pre-commit, 390 lines) is a shell script that duplicates security patterns already defined in the Python pattern registry (security/patterns.py, 1017 lines). This creates two problems:
- Pattern drift — changes to
PATTERN_REGISTRY don't update the shell hook, and vice versa
- Weaker detection — shell hook uses basic grep, missing the AST-aware analysis now available via semgrep integration
Additionally, install_hooks() in security/hooks.py is dead code — it's never called, so the hook isn't even installed automatically.
Proposed Solution
Replace the shell pre-commit hook with a Python entry point that calls the unified scanner:
# .git/hooks/pre-commit (or via .pre-commit-config.yaml)
python -m zerg.security.scanner --pre-commit
Behavior
- Collect staged files via
git diff --cached --name-only
- Call
run_security_scan(files=staged_files) — runs semgrep + regex + CVE scan
- Security findings (severity >= HIGH) → block commit, show findings
- Quality findings (severity < HIGH) → warn, allow commit
- Exit code 0 = pass, exit code 1 = blocked
- Log all findings to
.zerg/security/findings.json
Migration
- Remove
.zerg/hooks/pre-commit shell script (390 lines)
- Remove
HOOK_PATTERNS dict from scanner.py (duplicated patterns)
- Update
security/hooks.py:install_hooks() to install the Python hook
- Actually call
install_hooks() during zerg init
- Add
zerg.security.scanner as a local pre-commit hook in .pre-commit-config.yaml
Files to Modify
| File |
Change |
zerg/security/scanner.py |
Add --pre-commit CLI mode, remove HOOK_PATTERNS |
zerg/security/hooks.py |
Update to install Python hook instead of shell script |
zerg/commands/init.py |
Call install_hooks() during init |
.zerg/hooks/pre-commit |
Delete (replaced by Python entry point) |
.pre-commit-config.yaml |
Add local hook for zerg.security.scanner |
Acceptance Criteria
Depends On
Problem
The current pre-commit hook (
.zerg/hooks/pre-commit, 390 lines) is a shell script that duplicates security patterns already defined in the Python pattern registry (security/patterns.py, 1017 lines). This creates two problems:PATTERN_REGISTRYdon't update the shell hook, and vice versaAdditionally,
install_hooks()insecurity/hooks.pyis dead code — it's never called, so the hook isn't even installed automatically.Proposed Solution
Replace the shell pre-commit hook with a Python entry point that calls the unified scanner:
# .git/hooks/pre-commit (or via .pre-commit-config.yaml) python -m zerg.security.scanner --pre-commitBehavior
git diff --cached --name-onlyrun_security_scan(files=staged_files)— runs semgrep + regex + CVE scan.zerg/security/findings.jsonMigration
.zerg/hooks/pre-commitshell script (390 lines)HOOK_PATTERNSdict fromscanner.py(duplicated patterns)security/hooks.py:install_hooks()to install the Python hookinstall_hooks()duringzerg initzerg.security.scanneras a local pre-commit hook in.pre-commit-config.yamlFiles to Modify
zerg/security/scanner.py--pre-commitCLI mode, removeHOOK_PATTERNSzerg/security/hooks.pyzerg/commands/init.pyinstall_hooks()during init.zerg/hooks/pre-commit.pre-commit-config.yamlzerg.security.scannerAcceptance Criteria
HOOK_PATTERNSremoved from scanner.py (patterns unified in PATTERN_REGISTRY)install_hooks()called duringzerg init.pre-commit-config.yamlhooks still workDepends On