Hook-System Python-Erweiterung

Status: ✅ IMPLEMENTIERT (2025-12-28)
Task: #506

Problem

Das Claude Code Hook-System (/var/www/tools/ki-protokoll/claude-hook/) prüfte nur PHP-Dateien. Python-Dateien in der Pipeline (/var/www/scripts/pipeline/) wurden nicht validiert.

Root Cause

# hook_dispatcher.py Zeile 78-80 (vorher)
if not file_path.endswith(".php"):
    sys.exit(0)

Implementierung

Phase 1: Dispatcher (hook_dispatcher.py)

ALLOWED_EXTENSIONS = {".php", ".py"}
PYTHON_CHECK_PATHS = ["/var/www/scripts/pipeline/"]
SKIP_PATHS = ["/venv/", "/__pycache__/", "/tests/", "/vendor/"]

def should_check(file_path: str) -> bool:
    if any(skip in file_path for skip in SKIP_PATHS):
        return False
    ext = Path(file_path).suffix
    if ext not in ALLOWED_EXTENSIONS:
        return False
    if ext == ".php":
        return True
    if ext == ".py":
        return any(file_path.startswith(p) for p in PYTHON_CHECK_PATHS)
    return False

Phase 2: Python-Regeln (pre_rules_python.py)

PP1.1: Hardcoded Model-Namen blockieren

PP1.2: Hardcoded Pipeline-IDs blockieren

Phase 3: Integration (pre_rules.py)

# Regelfilterung nach Dateityp
if file_path.endswith(".php"):
    rules = PHP_RULES
elif file_path.endswith(".py"):
    rules = PYTHON_RULES
else:
    return allow()

Testmatrix (7/7 bestanden)

TestSzenarioErwartetErgebnis
1PP1.1 default="mistral"DENY
2PP1.1 get_pipeline_model()ALLOW
3PP1.1 DEFAULT_MODEL = "mistral"ALLOW
4PP1.2 pipeline_id = 5DENY
5PP1.2 DEFAULT_PIPELINE_ID = 5ALLOW
6Skip /venv/ PfadeALLOW
7PHP P1.1 @responsibilityDENY

Dateien

DateiAktion
hook_dispatcher.pyMODIFIZIERT
quality/pre_rules_python.pyNEU
quality/pre_rules.pyMODIFIZIERT