{
"event": "PreToolUse",
"tool_name": "Bash",
"tool_input": {
"command": "# Full test with verbose output\npython3 << 'EOF'\nimport json\nimport re\nimport sys\n\nHARD_RULES = [\n {\n \"id\": \"H1\",\n \"name\": \"strict_types_required\",\n \"pattern\": r\"declare\\s*\\(\\s*strict_types\\s*=\\s*1\\s*\\)\",\n \"must_match\": True,\n \"applies_to\": \"all\",\n \"message\": \"Missing declare(strict_types=1). Add at top of file after <?php\"\n }\n]\n\nALLOWED_PATHS = [\"\/Factory\/\", \"\/Bootstrap\/\", \"\/tests\/\", \"\/Test\/\", \"\/vendor\/\"]\n\ndef is_allowed_path(file_path):\n for allowed in ALLOWED_PATHS:\n if allowed in file_path:\n return True\n return False\n\ndef rule_applies(rule, file_path):\n if \"applies_to\" in rule:\n if rule[\"applies_to\"] == \"all\":\n return True\n return rule[\"applies_to\"] in file_path\n if \"applies_to_not\" in rule:\n return rule[\"applies_to_not\"] not in file_path\n return True\n\ndef check_rule(rule, content):\n match = re.search(rule[\"pattern\"], content)\n if rule[\"must_match\"]:\n return match is None\n else:\n return match is not None\n\ndef check_all_rules(file_path, content):\n if not file_path.endswith(\".php\"):\n return {\"allowed\": True}\n if is_allowed_path(file_path):\n return {\"allowed\": True}\n \n for rule in HARD_RULES:\n if not rule_applies(rule, file_path):\n continue\n if check_rule(rule, content):\n return {\n \"allowed\": False,\n \"message\": f\"ARCHITECTURE VIOLATION [{rule['id']}]: {rule['message']}\"\n }\n return {\"allowed\": True}\n\n# Test\nfile_path = \"\/var\/www\/dev\/src\/Service\/TestService.php\"\ncontent = \"<?php\\n\\nnamespace Service;\\n\\nclass TestService {}\"\n\nresult = check_all_rules(file_path, content)\nprint(json.dumps(result))\nEOF\n",
"description": "Test full logic inline"
}
}
{
"tool_response": {
"stdout": "{\"allowed\": false, \"message\": \"ARCHITECTURE VIOLATION [H1]: Missing declare(strict_types=1). Add at top of file after <?php\"}",
"stderr": "",
"interrupted": false,
"isImage": false
}
}