{
"event": "PreToolUse",
"tool_name": "Read",
"tool_input": {
"file_path": "\/var\/www\/tools\/ki-protokoll\/claude-hook\/quality\/pre_rules.py",
"limit": 80
}
}
{
"tool_response": {
"type": "text",
"file": {
"filePath": "\/var\/www\/tools\/ki-protokoll\/claude-hook\/quality\/pre_rules.py",
"content": "#!\/usr\/bin\/env python3\n\"\"\"\nPre-Hook Regeln (BLOCK) - Beliebig erweiterbar ohne Claude-Neustart.\n\nAlle P-Regeln aus dem Quality Gate Plan.\n\"\"\"\n\nimport re\nfrom pathlib import Path\nfrom typing import Optional\n\n# =============================================================================\n# ALLOWLIST - Pfade die von allen Prüfungen ausgenommen sind\n# =============================================================================\n\nGLOBAL_ALLOWLIST = [\n \"\/vendor\/\",\n \"\/tests\/\",\n \"\/Test\/\",\n]\n\nFACTORY_ALLOWLIST = [\n \"\/Factory\/\",\n \"\/Bootstrap\/\",\n]\n\n# =============================================================================\n# COMMON NUMBERS - Erlaubte Magic Numbers (für W5.2, hier zur Referenz)\n# =============================================================================\n\nCOMMON_NUMBERS = {\n '0', '1', '2',\n '10', '100', '1000',\n '60', '24', '365',\n '30', '31', '28', '29',\n '12', '52', '7',\n '200', '201', '204',\n '301', '302', '304',\n '400', '401', '403', '404', '500',\n}\n\n# =============================================================================\n# HELPER FUNCTIONS\n# =============================================================================\n\ndef is_in_allowlist(file_path: str, allowlist: list) -> bool:\n \"\"\"Prüft ob Pfad in Allowlist ist.\"\"\"\n return any(allowed in file_path for allowed in allowlist)\n\n\ndef block(rule_id: str, message: str) -> dict:\n \"\"\"Erzeugt Block-Response.\"\"\"\n return {\n \"allowed\": False,\n \"message\": f\"QUALITY VIOLATION [{rule_id}]: {message}\"\n }\n\n\ndef allow() -> dict:\n \"\"\"Erzeugt Allow-Response.\"\"\"\n return {\"allowed\": True}\n\n\n# =============================================================================\n# PRÜFUNG 1: SRP + KISS\n# =============================================================================\n\ndef p1_1_responsibility_header(file_path: str, content: str) -> Optional[dict]:\n \"\"\"P1.1: @responsibility Header erforderlich.\"\"\"\n if is_in_allowlist(file_path, GLOBAL_ALLOWLIST):\n return None\n\n header_pattern = r\"\/\/\\s*@responsibility:\\s*(.+)\"\n match = re.search(header_pattern, content)\n\n if not match:\n return block(\"P1.1\", \"Missing @responsibility header. Add: \/\/ @responsibility: <single-responsibility>\")\n\n responsibility_text = match.group(1).strip()\n",
"numLines": 80,
"startLine": 1,
"totalLines": 438
}
}
}