Protokoll #16109

ID16109
Zeitstempel2025-12-25 16:59:36.647371
Clientroot
IP145.224.72.140
Modellclaude-sonnet-4-20250514
Statuscompleted
Tokens2,191 (Input: 1,093, Output: 1,098)
Dauer108 ms
Request-Zeit2025-12-25 16:59:36.647371
Response-Zeit2025-12-25 16:59:36.755300

Request

{
    "event": "PreToolUse",
    "tool_name": "Write",
    "tool_input": {
        "file_path": "\/var\/www\/tools\/ki-protokoll\/claude-hook\/quality\/pre_rules_layers.py",
        "content": "#!\/usr\/bin\/env python3\n\"\"\"\nPre-Hook Layer Regeln (BLOCK) - DIP + Architecture Guards.\n\nP6.x Regeln: SOLID + DIP Layer-Violations\nH-Regeln: Legacy Architecture Guards\n\"\"\"\n\nimport re\nfrom typing import Optional\nfrom .rule_base import GLOBAL_ALLOWLIST, is_in_allowlist, block\n\n\n# =============================================================================\n# ALLOWLIST\n# =============================================================================\n\nFACTORY_ALLOWLIST = [\n    \"\/Factory\/\",\n    \"\/Bootstrap\/\",\n]\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_path and \"\/Application\/\" not in file_path:\n        return None\n    if is_in_allowlist(file_path, GLOBAL_ALLOWLIST):\n        return None\n\n    if re.search(r\"use\\s+Infrastructure\\\\\", content):\n        return block(\"P6.1\", \"Application layer must not import Infrastructure directly (DIP)\")\n\n    return None\n\n\ndef p6_2_domain_no_application_import(file_path: str, content: str) -> Optional[dict]:\n    \"\"\"P6.2: Domain darf Application-Layer nicht importieren.\"\"\"\n    if \"\/Domain\/\" not in file_path:\n        return None\n    if is_in_allowlist(file_path, GLOBAL_ALLOWLIST):\n        return None\n\n    if re.search(r\"use\\s+(UseCases|Application)\\\\\", content):\n        return block(\"P6.2\", \"Domain must not import Application layer (layer violation)\")\n\n    return None\n\n\n# =============================================================================\n# LEGACY H-REGELN (aus architecture_guard.py)\n# =============================================================================\n\ndef h2_domain_no_infrastructure(file_path: str, content: str) -> Optional[dict]:\n    \"\"\"H2: Domain ohne Infrastructure.\"\"\"\n    if \"\/Domain\/\" not in file_path:\n        return None\n    if is_in_allowlist(file_path, GLOBAL_ALLOWLIST):\n        return None\n\n    if re.search(r\"use\\s+Infrastructure\\\\\", content):\n        return block(\"H2\", \"Domain must not use Infrastructure\")\n\n    return None\n\n\ndef h3_database_factory_only_in_factory(file_path: str, content: str) -> Optional[dict]:\n    \"\"\"H3: DatabaseFactory nur in Factory.\"\"\"\n    if is_in_allowlist(file_path, GLOBAL_ALLOWLIST + FACTORY_ALLOWLIST):\n        return None\n\n    if re.search(r\"DatabaseFactory::\", content):\n        return block(\"H3\", \"DatabaseFactory only allowed in Factory classes\")\n\n    return None\n\n\ndef h4_no_new_repository_in_controller(file_path: str, content: str) -> Optional[dict]:\n    \"\"\"H4: Kein new Repository 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    if re.search(r\"new\\s+\\w+Repository\\s*\\(\", content):\n        return block(\"H4\", \"new Repository in Controller not allowed. Use DI.\")\n\n    return None\n\n\ndef h5_no_new_infrastructure_in_controller(file_path: str, content: str) -> Optional[dict]:\n    \"\"\"H5: Kein new Infrastructure 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    if re.search(r\"new\\s+Infrastructure\\\\\", content):\n        return block(\"H5\", \"new Infrastructure in Controller not allowed. Use DI.\")\n\n    return None\n\n\n# =============================================================================\n# RULE COLLECTION\n# =============================================================================\n\nRULES = [\n    # Prüfung 6: SOLID + DIP\n    p6_1_application_no_infrastructure_import,\n    p6_2_domain_no_application_import,\n\n    # Legacy H-Regeln\n    h2_domain_no_infrastructure,\n    h3_database_factory_only_in_factory,\n    h4_no_new_repository_in_controller,\n    h5_no_new_infrastructure_in_controller,\n]\n"
    }
}

Response

{
    "tool_response": {
        "type": "create",
        "filePath": "\/var\/www\/tools\/ki-protokoll\/claude-hook\/quality\/pre_rules_layers.py",
        "content": "#!\/usr\/bin\/env python3\n\"\"\"\nPre-Hook Layer Regeln (BLOCK) - DIP + Architecture Guards.\n\nP6.x Regeln: SOLID + DIP Layer-Violations\nH-Regeln: Legacy Architecture Guards\n\"\"\"\n\nimport re\nfrom typing import Optional\nfrom .rule_base import GLOBAL_ALLOWLIST, is_in_allowlist, block\n\n\n# =============================================================================\n# ALLOWLIST\n# =============================================================================\n\nFACTORY_ALLOWLIST = [\n    \"\/Factory\/\",\n    \"\/Bootstrap\/\",\n]\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_path and \"\/Application\/\" not in file_path:\n        return None\n    if is_in_allowlist(file_path, GLOBAL_ALLOWLIST):\n        return None\n\n    if re.search(r\"use\\s+Infrastructure\\\\\", content):\n        return block(\"P6.1\", \"Application layer must not import Infrastructure directly (DIP)\")\n\n    return None\n\n\ndef p6_2_domain_no_application_import(file_path: str, content: str) -> Optional[dict]:\n    \"\"\"P6.2: Domain darf Application-Layer nicht importieren.\"\"\"\n    if \"\/Domain\/\" not in file_path:\n        return None\n    if is_in_allowlist(file_path, GLOBAL_ALLOWLIST):\n        return None\n\n    if re.search(r\"use\\s+(UseCases|Application)\\\\\", content):\n        return block(\"P6.2\", \"Domain must not import Application layer (layer violation)\")\n\n    return None\n\n\n# =============================================================================\n# LEGACY H-REGELN (aus architecture_guard.py)\n# =============================================================================\n\ndef h2_domain_no_infrastructure(file_path: str, content: str) -> Optional[dict]:\n    \"\"\"H2: Domain ohne Infrastructure.\"\"\"\n    if \"\/Domain\/\" not in file_path:\n        return None\n    if is_in_allowlist(file_path, GLOBAL_ALLOWLIST):\n        return None\n\n    if re.search(r\"use\\s+Infrastructure\\\\\", content):\n        return block(\"H2\", \"Domain must not use Infrastructure\")\n\n    return None\n\n\ndef h3_database_factory_only_in_factory(file_path: str, content: str) -> Optional[dict]:\n    \"\"\"H3: DatabaseFactory nur in Factory.\"\"\"\n    if is_in_allowlist(file_path, GLOBAL_ALLOWLIST + FACTORY_ALLOWLIST):\n        return None\n\n    if re.search(r\"DatabaseFactory::\", content):\n        return block(\"H3\", \"DatabaseFactory only allowed in Factory classes\")\n\n    return None\n\n\ndef h4_no_new_repository_in_controller(file_path: str, content: str) -> Optional[dict]:\n    \"\"\"H4: Kein new Repository 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    if re.search(r\"new\\s+\\w+Repository\\s*\\(\", content):\n        return block(\"H4\", \"new Repository in Controller not allowed. Use DI.\")\n\n    return None\n\n\ndef h5_no_new_infrastructure_in_controller(file_path: str, content: str) -> Optional[dict]:\n    \"\"\"H5: Kein new Infrastructure 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    if re.search(r\"new\\s+Infrastructure\\\\\", content):\n        return block(\"H5\", \"new Infrastructure in Controller not allowed. Use DI.\")\n\n    return None\n\n\n# =============================================================================\n# RULE COLLECTION\n# =============================================================================\n\nRULES = [\n    # Prüfung 6: SOLID + DIP\n    p6_1_application_no_infrastructure_import,\n    p6_2_domain_no_application_import,\n\n    # Legacy H-Regeln\n    h2_domain_no_infrastructure,\n    h3_database_factory_only_in_factory,\n    h4_no_new_repository_in_controller,\n    h5_no_new_infrastructure_in_controller,\n]\n",
        "structuredPatch": [],
        "originalFile": null
    }
}
← Vorheriger Zur Liste Nächster →