Protokoll #14489
| ID | 14489 |
|---|---|
| Zeitstempel | 2025-12-25 10:42:29.234371 |
| Client | root |
| 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 |
| Modell | claude-sonnet-4-20250514 |
| Status | completed |
| Tokens | 1,916 (Input: 0, Output: 0) |
| Dauer | 105 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": "Edit",
"tool_input": {
"file_path": "\/var\/www\/tools\/ki-protokoll\/claude-hook\/hook_dispatcher.py",
"old_string": " # Nur für Write\/Edit auf PHP-Dateien\n file_path = tool_input.get(\"file_path\", \"\")\n content = tool_input.get(\"content\", \"\")\n\n if not file_path.endswith(\".php\"):",
"new_string": " # Nur für Write\/Edit auf PHP-Dateien\n file_path = tool_input.get(\"file_path\", \"\")\n\n # Für Edit: Simuliere vollständigen Datei-Inhalt nach dem Edit\n if tool_name == \"Edit\":\n old_string = tool_input.get(\"old_string\", \"\")\n new_string = tool_input.get(\"new_string\", \"\")\n try:\n with open(file_path, \"r\", encoding=\"utf-8\") as f:\n full_content = f.read()\n # Simuliere den Edit\n content = full_content.replace(old_string, new_string, 1)\n except (OSError, IOError):\n content = new_string # Fallback bei Lesefehler\n else:\n content = tool_input.get(\"content\", \"\")\n\n if not file_path.endswith(\".php\"):"
}
}
Response
{
"tool_response": {
"filePath": "\/var\/www\/tools\/ki-protokoll\/claude-hook\/hook_dispatcher.py",
"oldString": " # Nur für Write\/Edit auf PHP-Dateien\n file_path = tool_input.get(\"file_path\", \"\")\n content = tool_input.get(\"content\", \"\")\n\n if not file_path.endswith(\".php\"):",
"newString": " # Nur für Write\/Edit auf PHP-Dateien\n file_path = tool_input.get(\"file_path\", \"\")\n\n # Für Edit: Simuliere vollständigen Datei-Inhalt nach dem Edit\n if tool_name == \"Edit\":\n old_string = tool_input.get(\"old_string\", \"\")\n new_string = tool_input.get(\"new_string\", \"\")\n try:\n with open(file_path, \"r\", encoding=\"utf-8\") as f:\n full_content = f.read()\n # Simuliere den Edit\n content = full_content.replace(old_string, new_string, 1)\n except (OSError, IOError):\n content = new_string # Fallback bei Lesefehler\n else:\n content = tool_input.get(\"content\", \"\")\n\n if not file_path.endswith(\".php\"):",
"originalFile": "#!\/opt\/mcp-servers\/mcp-db\/venv\/bin\/python\n\"\"\"\nHook Dispatcher - Stabiler Einstiegspunkt für Claude Code Hooks.\n\nNIEMALS ÄNDERN. Änderungen an Regeln nur in quality\/*.py\n\nUsage:\n hook_dispatcher.py pre # PreToolUse (BLOCK)\n hook_dispatcher.py post # PostToolUse (WARN)\n\"\"\"\n\nimport json\nimport sys\nimport importlib.util\nimport os\nfrom pathlib import Path\n\n# DB-Password aus .env laden\nenv_path = Path(__file__).parent \/ \".env\"\nif env_path.exists():\n with open(env_path) as f:\n for line in f:\n if \"=\" in line and not line.startswith(\"#\"):\n key, value = line.strip().split(\"=\", 1)\n os.environ[key] = value\n\n\ndef load_module(name: str):\n \"\"\"Lädt ein Python-Modul dynamisch.\"\"\"\n module_path = Path(__file__).parent \/ \"quality\" \/ f\"{name}.py\"\n if not module_path.exists():\n return None\n\n spec = importlib.util.spec_from_file_location(name, module_path)\n module = importlib.util.module_from_spec(spec)\n spec.loader.exec_module(module)\n return module\n\n\ndef main():\n if len(sys.argv) < 2:\n print(json.dumps({\"error\": \"Usage: hook_dispatcher.py pre|post\"}))\n sys.exit(1)\n\n mode = sys.argv[1]\n\n # Hook-Input von stdin lesen\n try:\n hook_input = json.load(sys.stdin)\n except json.JSONDecodeError:\n print(json.dumps({\"allowed\": True})) # Bei Fehler durchlassen\n sys.exit(0)\n\n # Tool-Daten extrahieren\n tool_name = hook_input.get(\"tool_name\", \"\")\n tool_input = hook_input.get(\"tool_input\", {})\n\n # Nur für Write\/Edit auf PHP-Dateien\n file_path = tool_input.get(\"file_path\", \"\")\n content = tool_input.get(\"content\", \"\")\n\n if not file_path.endswith(\".php\"):\n # Nicht-PHP: durchlassen ohne Output (implizit allow)\n sys.exit(0)\n\n # Modul laden und ausführen\n if mode == \"pre\":\n module = load_module(\"pre_rules\")\n if module and hasattr(module, \"check\"):\n result = module.check(file_path, content)\n if not result.get(\"allowed\", True):\n # Task für Violation erstellen\n try:\n task_creator = load_module(\"task_creator\")\n if task_creator:\n # Parse Rule-ID aus Message\n msg = result.get(\"message\", \"\")\n rule_id = \"UNKNOWN\"\n if \"[\" in msg and \"]\" in msg:\n rule_id = msg.split(\"[\")[1].split(\"]\")[0]\n task_creator.create_violation_task(\n file_path, rule_id, msg, \"block\"\n )\n except Exception:\n pass # Task-Erstellung darf Hook nicht crashen\n\n # BLOCK: Korrektes Claude Code Format\n output = {\n \"hookSpecificOutput\": {\n \"hookEventName\": \"PreToolUse\",\n \"permissionDecision\": \"deny\",\n \"permissionDecisionReason\": result.get(\"message\", \"Quality check failed\")\n }\n }\n print(json.dumps(output))\n # Bei allow: kein Output nötig (implizit allow)\n\n elif mode == \"post\":\n module = load_module(\"post_rules\")\n if module and hasattr(module, \"check\"):\n result = module.check(file_path, content)\n # Post-Hook gibt Warnungen aus, blockiert nicht\n if result.get(\"warnings\"):\n # Tasks für Warnungen erstellen\n try:\n task_creator = load_module(\"task_creator\")\n if task_creator:\n task_creator.create_tasks_for_warnings(\n file_path, result[\"warnings\"]\n )\n except Exception:\n pass # Task-Erstellung darf Hook nicht crashen\n\n for warning in result[\"warnings\"]:\n print(f\"[QUALITY] {warning}\", file=sys.stderr)\n # Post-Hook blockiert nie\n\n else:\n print(json.dumps({\"error\": f\"Unknown mode: {mode}\"}))\n sys.exit(1)\n\n\nif __name__ == \"__main__\":\n main()\n",
"structuredPatch": [
{
"oldStart": 57,
"oldLines": 8,
"newStart": 57,
"newLines": 21,
"lines": [
" ",
" # Nur für Write\/Edit auf PHP-Dateien",
" file_path = tool_input.get(\"file_path\", \"\")",
"- content = tool_input.get(\"content\", \"\")",
" ",
"+ # Für Edit: Simuliere vollständigen Datei-Inhalt nach dem Edit",
"+ if tool_name == \"Edit\":",
"+ old_string = tool_input.get(\"old_string\", \"\")",
"+ new_string = tool_input.get(\"new_string\", \"\")",
"+ try:",
"+ with open(file_path, \"r\", encoding=\"utf-8\") as f:",
"+ full_content = f.read()",
"+ # Simuliere den Edit",
"+ content = full_content.replace(old_string, new_string, 1)",
"+ except (OSError, IOError):",
"+ content = new_string # Fallback bei Lesefehler",
"+ else:",
"+ content = tool_input.get(\"content\", \"\")",
"+",
" if not file_path.endswith(\".php\"):",
" # Nicht-PHP: durchlassen ohne Output (implizit allow)",
" sys.exit(0)"
]
}
],
"userModified": false,
"replaceAll": false
}
}