Evaluate all rules and return combined results. Checks all rules and accumulates matches. Blocking rules take priority over warning rules. All matching rule messages are combined. Args: rules: List of Rule objects to evaluate input_data: Hook input J
(self, rules: List[Rule], input_data: Dict[str, Any])
| 33 | pass |
| 34 | |
| 35 | def evaluate_rules(self, rules: List[Rule], input_data: Dict[str, Any]) -> Dict[str, Any]: |
| 36 | """Evaluate all rules and return combined results. |
| 37 | |
| 38 | Checks all rules and accumulates matches. Blocking rules take priority |
| 39 | over warning rules. All matching rule messages are combined. |
| 40 | |
| 41 | Args: |
| 42 | rules: List of Rule objects to evaluate |
| 43 | input_data: Hook input JSON (tool_name, tool_input, etc.) |
| 44 | |
| 45 | Returns: |
| 46 | Response dict with systemMessage, hookSpecificOutput, etc. |
| 47 | Empty dict {} if no rules match. |
| 48 | """ |
| 49 | hook_event = input_data.get('hook_event_name', '') |
| 50 | blocking_rules = [] |
| 51 | warning_rules = [] |
| 52 | |
| 53 | for rule in rules: |
| 54 | if self._rule_matches(rule, input_data): |
| 55 | if rule.action == 'block': |
| 56 | blocking_rules.append(rule) |
| 57 | else: |
| 58 | warning_rules.append(rule) |
| 59 | |
| 60 | # If any blocking rules matched, block the operation |
| 61 | if blocking_rules: |
| 62 | messages = [f"**[{r.name}]**\n{r.message}" for r in blocking_rules] |
| 63 | combined_message = "\n\n".join(messages) |
| 64 | |
| 65 | # Use appropriate blocking format based on event type |
| 66 | if hook_event == 'Stop': |
| 67 | return { |
| 68 | "decision": "block", |
| 69 | "reason": combined_message, |
| 70 | "systemMessage": combined_message |
| 71 | } |
| 72 | elif hook_event in ['PreToolUse', 'PostToolUse']: |
| 73 | return { |
| 74 | "hookSpecificOutput": { |
| 75 | "hookEventName": hook_event, |
| 76 | "permissionDecision": "deny" |
| 77 | }, |
| 78 | "systemMessage": combined_message |
| 79 | } |
| 80 | else: |
| 81 | # For other events, just show message |
| 82 | return { |
| 83 | "systemMessage": combined_message |
| 84 | } |
| 85 | |
| 86 | # If only warnings, show them but allow operation |
| 87 | if warning_rules: |
| 88 | messages = [f"**[{r.name}]**\n{r.message}" for r in warning_rules] |
| 89 | return { |
| 90 | "systemMessage": "\n\n".join(messages) |
| 91 | } |
| 92 |
no test coverage detected