Protokoll #24056

ID24056
Zeitstempel2025-12-27 15:45:11.535540
Clientroot
IP145.224.72.140
Modellclaude-sonnet-4-20250514
Statuspending
Tokens1,102 (Input: 1,102, Output: 0)
Dauer-
Request-Zeit2025-12-27 15:45:11.535540
Response-Zeit-

Request

{
    "event": "PostToolUse",
    "tool_name": "Read",
    "tool_response": {
        "type": "text",
        "file": {
            "filePath": "\/var\/www\/tools\/ki-protokoll\/claude-hook\/quality\/rule_base.py",
            "content": "#!\/usr\/bin\/env python3\n\"\"\"\nBasis-Klasse für Quality-Gate-Regeln.\nStellt gemeinsame Funktionalität für alle Regel-Module bereit.\n\"\"\"\n\nimport re\nfrom pathlib import Path\nfrom typing import List, Callable\n\n\n# =============================================================================\n# ALLOWLIST DEFINITIONS\n# =============================================================================\n\nGLOBAL_ALLOWLIST = [\n    \"\/vendor\/\",\n    \"\/tests\/\",\n    \"\/Test\/\",\n]\n\nDTO_ALLOWLIST = [\n    \"\/Infrastructure\/DTO\/\",\n    \"\/DTO\/\",\n]\n\nMIGRATION_ALLOWLIST = [\n    \"\/migrations\/\",\n    \"\/Migration\/\",\n]\n\n\n# =============================================================================\n# COMMON NUMBERS - Erlaubte Magic Numbers\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# =============================================================================\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 count_non_empty_lines(content: str) -> int:\n    \"\"\"Zählt nicht-leere Zeilen.\"\"\"\n    return len([line for line in content.split('\\n') if line.strip()])\n\n\ndef block(rule_id: str, message: str) -> dict:\n    \"\"\"Erzeugt Block-Response für Pre-Hooks.\"\"\"\n    return {\n        \"allowed\": False,\n        \"message\": f\"QUALITY VIOLATION [{rule_id}]: {message}\"\n    }\n\n\ndef allow() -> dict:\n    \"\"\"Erzeugt Allow-Response für Pre-Hooks.\"\"\"\n    return {\"allowed\": True}\n\n\n# =============================================================================\n# RULE BASE CLASS\n# =============================================================================\n\nclass Rule:\n    \"\"\"\n    Basis-Klasse für alle Quality-Gate-Regeln.\n\n    Jede Regel ist eine Callable-Klasse die file_path und content nimmt\n    und eine Liste von Warnings zurückgibt.\n    \"\"\"\n\n    def __init__(self, allowlist: List[str] = None):\n        \"\"\"\n        Args:\n            allowlist: Zusätzliche Allowlist-Pfade für diese Regel\n        \"\"\"\n        self.allowlist = allowlist or []\n\n    def should_skip(self, file_path: str) -> bool:\n        \"\"\"\n        Prüft ob diese Datei übersprungen werden soll.\n\n        Args:\n            file_path: Pfad zur zu prüfenden Datei\n\n        Returns:\n            True wenn Datei übersprungen werden soll\n        \"\"\"\n        return is_in_allowlist(file_path, GLOBAL_ALLOWLIST + self.allowlist)\n\n    def check(self, file_path: str, content: str) -> List[str]:\n        \"\"\"\n        Führt die Regel-Prüfung aus.\n\n        Args:\n            file_path: Pfad zur zu prüfenden Datei\n            content: Dateiinhalt\n\n        Returns:\n            Liste von Warning-Messages\n        \"\"\"\n        raise NotImplementedError(\"Subclasses must implement check()\")\n\n    def __call__(self, file_path: str, content: str) -> List[str]:\n        \"\"\"\n        Macht die Regel-Klasse callable.\n\n        Args:\n            file_path: Pfad zur zu prüfenden Datei\n            content: Dateiinhalt\n\n        Returns:\n            Liste von Warning-Messages\n        \"\"\"\n        if self.should_skip(file_path):\n            return []\n        return self.check(file_path, content)\n\n\n# =============================================================================\n# RULE COLLECTION\n# =============================================================================\n\ndef collect_rules(rule_list: List[Callable]) -> List[Callable]:\n    \"\"\"\n    Sammelt alle Regeln aus einem Modul.\n\n    Args:\n        rule_list: Liste von Regel-Funktionen oder Regel-Klassen\n\n    Returns:\n        Liste von callables\n    \"\"\"\n    return rule_list\n",
            "numLines": 151,
            "startLine": 1,
            "totalLines": 151
        }
    }
}

Response

-
← Vorheriger Zur Liste Nächster →