Protokoll #16025

ID16025
Zeitstempel2025-12-25 16:58:45.752661
Clientroot
IP145.224.72.140
Modellclaude-sonnet-4-20250514
Statuscompleted
Tokens1,570 (Input: 209, Output: 1,361)
Dauer134 ms
Request-Zeit2025-12-25 16:58:45.752661
Response-Zeit2025-12-25 16:58:45.887149

Request

{
    "event": "PreToolUse",
    "tool_name": "Edit",
    "tool_input": {
        "file_path": "\/var\/www\/tools\/ki-protokoll\/claude-hook\/quality\/rule_base.py",
        "old_string": "def 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()])",
        "new_string": "def 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}"
    }
}

Response

{
    "tool_response": {
        "filePath": "\/var\/www\/tools\/ki-protokoll\/claude-hook\/quality\/rule_base.py",
        "oldString": "def 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()])",
        "newString": "def 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}",
        "originalFile": "#!\/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\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",
        "structuredPatch": [
            {
                "oldStart": 60,
                "oldLines": 6,
                "newStart": 60,
                "newLines": 19,
                "lines": [
                    "     return len([line for line in content.split('\\n') if line.strip()])",
                    " ",
                    " ",
                    "+def block(rule_id: str, message: str) -> dict:",
                    "+    \"\"\"Erzeugt Block-Response für Pre-Hooks.\"\"\"",
                    "+    return {",
                    "+        \"allowed\": False,",
                    "+        \"message\": f\"QUALITY VIOLATION [{rule_id}]: {message}\"",
                    "+    }",
                    "+",
                    "+",
                    "+def allow() -> dict:",
                    "+    \"\"\"Erzeugt Allow-Response für Pre-Hooks.\"\"\"",
                    "+    return {\"allowed\": True}",
                    "+",
                    "+",
                    " # =============================================================================",
                    " # RULE BASE CLASS",
                    " # ============================================================================="
                ]
            }
        ],
        "userModified": false,
        "replaceAll": false
    }
}
← Vorheriger Zur Liste Nächster →