Protokoll #14503

ID14503
Zeitstempel2025-12-25 10:43:51.425332
Clientroot
IP
Warning: Undefined array key "request_ip" in /var/www/dev.campus.systemische-tools.de/src/View/protokoll/show.php on line 13

Deprecated: htmlspecialchars(): Passing null to parameter #1 ($string) of type string is deprecated in /var/www/dev.campus.systemische-tools.de/src/View/protokoll/show.php on line 13
Modellclaude-sonnet-4-20250514
Statuscompleted
Tokens2,761 (Input: 0, Output: 0)
Dauer101 ms
Request-Zeit
Warning: Undefined array key "request_timestamp" in /var/www/dev.campus.systemische-tools.de/src/View/protokoll/show.php on line 18
Response-Zeit-

Warning: Undefined array key "error_message" in /var/www/dev.campus.systemische-tools.de/src/View/protokoll/show.php on line 22

Request

{
    "event": "PreToolUse",
    "tool_name": "Read",
    "tool_input": {
        "file_path": "\/var\/www\/tools\/ki-protokoll\/claude-hook\/quality\/post_rules.py"
    }
}

Response

{
    "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\n    # Prüfe auf Multi-Responsibility-Wörter\n    multi_words = r\"\\b(und|sowie|außerdem|also|zusätzlich|and|also|additionally)\\b\"\n    if re.search(multi_words, responsibility_text, re.IGNORECASE):\n        return block(\"P1.1\", f\"@responsibility contains multi-responsibility indicator: '{responsibility_text}'\")\n\n    return None\n\n\ndef p1_2_garbage_names(file_path: str, content: str) -> Optional[dict]:\n    \"\"\"P1.2: Müllhalden-Namen blockieren.\"\"\"\n    if is_in_allowlist(file_path, GLOBAL_ALLOWLIST):\n        return None\n\n    filename = Path(file_path).stem.lower()\n    forbidden = [\"helper\", \"utils\", \"common\", \"misc\", \"base\"]\n\n    for term in forbidden:\n        if term in filename:\n            return block(\"P1.2\", f\"Forbidden name pattern: '{term}' indicates unclear responsibility\")\n\n    return None\n\n\n# =============================================================================\n# PRÜFUNG 2: MVC + CRUD\n# =============================================================================\n\ndef p2_1_no_sql_in_controller(file_path: str, content: str) -> Optional[dict]:\n    \"\"\"P2.1: Keine SQL-Statements in Controller.\"\"\"\n    if \"\/Controller\/\" not in file_path:\n        return None\n    if is_in_allowlist(file_path, GLOBAL_ALLOWLIST):\n        return None\n\n    sql_patterns = [\n        r\"\\bSELECT\\s+.+\\s+FROM\\b\",\n        r\"\\bINSERT\\s+INTO\\b\",\n        r\"\\bUPDATE\\s+\\w+\\s+SET\\b\",\n        r\"\\bDELETE\\s+FROM\\b\",\n    ]\n\n    for pattern in sql_patterns:\n        if re.search(pattern, content, re.IGNORECASE):\n            return block(\"P2.1\", \"SQL statement in Controller. Move to Repository.\")\n\n    return None\n\n\ndef p2_2_no_transactions_in_controller(file_path: str, content: str) -> Optional[dict]:\n    \"\"\"P2.2: Keine Transaktionen in Controller.\"\"\"\n    if \"\/Controller\/\" not in file_path:\n        return None\n    if is_in_allowlist(file_path, GLOBAL_ALLOWLIST):\n        return None\n\n    transaction_patterns = [\n        r\"\\bbeginTransaction\\s*\\(\",\n        r\"\\bcommit\\s*\\(\",\n        r\"\\brollBack\\s*\\(\",\n        r\"\\brollback\\s*\\(\",\n    ]\n\n    for pattern in transaction_patterns:\n        if re.search(pattern, content):\n            return block(\"P2.2\", \"Transaction control in Controller. Move to UseCase or Repository.\")\n\n    return None\n\n\ndef p2_3_no_echo_in_controller(file_path: str, content: str) -> Optional[dict]:\n    \"\"\"P2.3: Kein echo\/print in Controller.\"\"\"\n    if \"\/Controller\/\" not in file_path:\n        return None\n    if is_in_allowlist(file_path, GLOBAL_ALLOWLIST):\n        return None\n\n    output_patterns = [\n        r\"\\becho\\s+\",\n        r\"\\becho\\(\",\n        r\"\\bprint\\s+\",\n        r\"\\bprint\\(\",\n    ]\n\n    for pattern in output_patterns:\n        if re.search(pattern, content):\n            return block(\"P2.3\", \"Direct output (echo\/print) in Controller. Use Response object.\")\n\n    return None\n\n\ndef p2_4_no_db_in_usecases(file_path: str, content: str) -> Optional[dict]:\n    \"\"\"P2.4: Keine DB-Artefakte in UseCases.\"\"\"\n    if \"\/UseCases\/\" not in file_path and \"\/Application\/\" not in file_path:\n        return None\n    if is_in_allowlist(file_path, GLOBAL_ALLOWLIST):\n        return None\n\n    db_patterns = [\n        r\"\\bnew\\s+PDO\\b\",\n        r\"\\bPDO::\",\n        r\"\\bDatabaseFactory::\",\n        r\"\\bSELECT\\s+.+\\s+FROM\\b\",\n        r\"\\bINSERT\\s+INTO\\b\",\n        r\"\\bUPDATE\\s+\\w+\\s+SET\\b\",\n        r\"\\bDELETE\\s+FROM\\b\",\n    ]\n\n    for pattern in db_patterns:\n        if re.search(pattern, content, re.IGNORECASE):\n            return block(\"P2.4\", \"DB artifact in UseCase\/Application. Use Repository interface.\")\n\n    return None\n\n\n# =============================================================================\n# PRÜFUNG 3: PSR + Types\n# =============================================================================\n\ndef p3_1_strict_types(file_path: str, content: str) -> Optional[dict]:\n    \"\"\"P3.1: strict_types erforderlich.\"\"\"\n    if is_in_allowlist(file_path, GLOBAL_ALLOWLIST):\n        return None\n\n    strict_pattern = r\"declare\\s*\\(\\s*strict_types\\s*=\\s*1\\s*\\)\\s*;\"\n    if not re.search(strict_pattern, content):\n        return block(\"P3.1\", \"Missing declare(strict_types=1)\")\n\n    return None\n\n\ndef p3_2_namespace_matches_path(file_path: str, content: str) -> Optional[dict]:\n    \"\"\"P3.2: Namespace muss Pfad entsprechen.\"\"\"\n    if is_in_allowlist(file_path, GLOBAL_ALLOWLIST):\n        return None\n\n    # Namespace-Mapping\n    path_to_namespace = {\n        \"\/src\/Controller\/\": \"Controller\\\\\",\n        \"\/src\/Domain\/\": \"Domain\\\\\",\n        \"\/src\/UseCases\/\": \"UseCases\\\\\",\n        \"\/src\/Application\/\": \"Application\\\\\",\n        \"\/src\/Infrastructure\/\": \"Infrastructure\\\\\",\n        \"\/src\/Framework\/\": \"Framework\\\\\",\n        \"\/app\/\": \"App\\\\\",\n    }\n\n    namespace_match = re.search(r\"namespace\\s+([^;]+);\", content)\n    if not namespace_match:\n        return None  # Kein Namespace = kein Check\n\n    declared_namespace = namespace_match.group(1).strip()\n\n    for path_prefix, ns_prefix in path_to_namespace.items():\n        if path_prefix in file_path:\n            if not declared_namespace.startswith(ns_prefix.rstrip(\"\\\\\")):\n                return block(\"P3.2\", f\"Namespace '{declared_namespace}' does not match path. Expected: '{ns_prefix}...'\")\n            break\n\n    return None\n\n\ndef p3_3_classname_matches_filename(file_path: str, content: str) -> Optional[dict]:\n    \"\"\"P3.3: Klassenname muss Dateiname entsprechen.\"\"\"\n    if is_in_allowlist(file_path, GLOBAL_ALLOWLIST):\n        return None\n\n    class_match = re.search(r\"(?:class|interface|trait|enum)\\s+(\\w+)\", content)\n    if not class_match:\n        return None  # Keine Klasse = kein Check\n\n    class_name = class_match.group(1)\n    expected_name = Path(file_path).stem\n\n    if class_name != expected_name:\n        return block(\"P3.3\", f\"Class '{class_name}' does not match filename '{expected_name}'\")\n\n    return None\n\n\ndef p3_4_public_method_return_type(file_path: str, content: str) -> Optional[dict]:\n    \"\"\"P3.4: Public Methods müssen Return-Type haben.\"\"\"\n    if is_in_allowlist(file_path, GLOBAL_ALLOWLIST):\n        return None\n\n    # Finde public functions\n    public_methods = re.findall(\n        r\"public\\s+function\\s+(\\w+)\\s*\\([^)]*\\)\\s*(?::\\s*\\S+)?\",\n        content\n    )\n\n    for method in public_methods:\n        if method.startswith(\"__\"):\n            continue  # Magic methods überspringen\n\n        # Prüfe ob Return-Type vorhanden\n        pattern = rf\"public\\s+function\\s+{method}\\s*\\([^)]*\\)\\s*:\\s*\\S+\"\n        if not re.search(pattern, content):\n            return block(\"P3.4\", f\"Public method '{method}' missing return type\")\n\n    return None\n\n\n# =============================================================================\n# PRÜFUNG 4: OOP\n# =============================================================================\n\ndef p4_1_no_public_properties_in_domain(file_path: str, content: str) -> Optional[dict]:\n    \"\"\"P4.1: Keine public Properties in Domain.\"\"\"\n    if \"\/Domain\/\" not in file_path:\n        return None\n    if is_in_allowlist(file_path, GLOBAL_ALLOWLIST):\n        return None\n\n    # public readonly ist erlaubt\n    public_props = re.findall(\n        r\"public\\s+(?!readonly|function|const|static\\s+function).*\\$\\w+\",\n        content\n    )\n\n    if public_props:\n        return block(\"P4.1\", \"Public property in Domain. Use getter methods or public readonly.\")\n\n    return None\n\n\n# =============================================================================\n# PRÜFUNG 6: SOLID + DIP\n# =============================================================================\n\ndef p6_1_application_no_infrastructure_import(file_path: str, content: str) -> Optional[dict]:\n    \"\"\"P6.1: UseCases\/Application darf Infrastructure nicht importieren.\"\"\"\n    if \"\/UseCases\/\" not in file_pat... [TRUNCATED-8b8fe0235d9fc756]",
            "numLines": 438,
            "startLine": 1,
            "totalLines": 438
        }
    }
}
← Vorheriger Zur Liste Nächster →