Skip to content

Conversation

@adrozdenko
Copy link

Summary

This PR adds two features to hookify that enable more expressive rules:

  1. not_regex_match operator — Negated regex matching for exclusion patterns
  2. value key in conditions — Alternative to pattern for semantic clarity with non-regex operators

Both features are backward-compatible and minimal in scope.

Problem

1. No way to exclude files with regex

Users need rules like "match .tsx files BUT NOT test/story files":

conditions:
  - field: file_path
    operator: regex_match
    pattern: \.tsx$
  - field: file_path
    operator: not_contains  # This is LITERAL, not regex!
    pattern: (\.test\.|\.stories\.)  # Won't work as expected

The existing not_contains does literal substring matching. There's no way to do regex negation.

2. Semantic confusion with pattern key

For operators like contains and equals, pattern is misleading since these aren't regex:

- field: command
  operator: contains
  pattern: rm -rf  # Actually literal, not regex

Users intuitively try value and it silently fails.

Solution

1. Add not_regex_match operator (2 lines)

if operator == 'regex_match':
    return self._regex_match(pattern, field_value)
elif operator == 'not_regex_match':
    return not self._regex_match(pattern, field_value)

2. Support value as alias (1 line change)

pattern = data.get('pattern') or data.get('value', '')

Files Changed

File Change
plugins/hookify/core/rule_engine.py Add not_regex_match operator
plugins/hookify/core/config_loader.py Support value key
plugins/hookify/README.md Document new features
plugins/hookify/skills/writing-rules/SKILL.md Update operator reference
plugins/hookify/examples/exclude-test-files.local.md Example using not_regex_match

Usage Example

---
name: no-console-in-prod
enabled: true
event: file
conditions:
  - field: file_path
    operator: regex_match
    pattern: \.tsx?$
  - field: file_path
    operator: not_regex_match  # NEW: exclude test/story files
    pattern: (\.test\.|\.spec\.|\.stories\.)
  - field: new_text
    operator: contains
    value: console.log  # NEW: clearer than "pattern"
---

Console.log in production code!

Test Plan

  • Python syntax check passes
  • Manual testing with example rules
  • Verified backward compatibility (existing rules unchanged)

Backward Compatibility

Fully backward compatible - existing rules work unchanged.

@adrozdenko
Copy link
Author

Update: This feature is now available in hookify-plus - a standalone fork with community fixes.

If you don't want to wait for upstream review, you can use hookify-plus today:

# Backup original & install hookify-plus
mv ~/.claude/plugins/cache/claude-code-plugins/hookify/0.1.0{,.bak}
ln -s /path/to/hookify-plus ~/.claude/plugins/cache/claude-code-plugins/hookify/0.1.0

hookify-plus includes:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant