Check if a single condition matches. Args: condition: Condition to check tool_name: Tool being used tool_input: Tool input dict input_data: Full hook input data (for Stop events, etc.) Returns: True if condition matches
(self, condition: Condition, tool_name: str,
tool_input: Dict[str, Any], input_data: Dict[str, Any] = None)
| 142 | return tool_name in patterns |
| 143 | |
| 144 | def _check_condition(self, condition: Condition, tool_name: str, |
| 145 | tool_input: Dict[str, Any], input_data: Dict[str, Any] = None) -> bool: |
| 146 | """Check if a single condition matches. |
| 147 | |
| 148 | Args: |
| 149 | condition: Condition to check |
| 150 | tool_name: Tool being used |
| 151 | tool_input: Tool input dict |
| 152 | input_data: Full hook input data (for Stop events, etc.) |
| 153 | |
| 154 | Returns: |
| 155 | True if condition matches |
| 156 | """ |
| 157 | # Extract the field value to check |
| 158 | field_value = self._extract_field(condition.field, tool_name, tool_input, input_data) |
| 159 | if field_value is None: |
| 160 | return False |
| 161 | |
| 162 | # Apply operator |
| 163 | operator = condition.operator |
| 164 | pattern = condition.pattern |
| 165 | |
| 166 | if operator == 'regex_match': |
| 167 | return self._regex_match(pattern, field_value) |
| 168 | elif operator == 'contains': |
| 169 | return pattern in field_value |
| 170 | elif operator == 'equals': |
| 171 | return pattern == field_value |
| 172 | elif operator == 'not_contains': |
| 173 | return pattern not in field_value |
| 174 | elif operator == 'starts_with': |
| 175 | return field_value.startswith(pattern) |
| 176 | elif operator == 'ends_with': |
| 177 | return field_value.endswith(pattern) |
| 178 | else: |
| 179 | # Unknown operator |
| 180 | return False |
| 181 | |
| 182 | def _extract_field(self, field: str, tool_name: str, |
| 183 | tool_input: Dict[str, Any], input_data: Dict[str, Any] = None) -> Optional[str]: |
no test coverage detected