Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions plugins/hookify/core/rule_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from typing import List, Dict, Any, Optional

# Import from local module
from hookify.core.config_loader import Rule, Condition
from core.config_loader import Rule, Condition


# Cache compiled regexes (max 128 patterns)
Expand Down Expand Up @@ -275,7 +275,7 @@ def _regex_match(self, pattern: str, text: str) -> bool:

# For testing
if __name__ == '__main__':
from hookify.core.config_loader import Condition, Rule
from core.config_loader import Condition, Rule

# Test rule evaluation
rule = Rule(
Expand Down
17 changes: 7 additions & 10 deletions plugins/hookify/hooks/posttooluse.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,15 @@
import sys
import json

# CRITICAL: Add plugin root to Python path for imports
PLUGIN_ROOT = os.environ.get('CLAUDE_PLUGIN_ROOT')
if PLUGIN_ROOT:
parent_dir = os.path.dirname(PLUGIN_ROOT)
if parent_dir not in sys.path:
sys.path.insert(0, parent_dir)
if PLUGIN_ROOT not in sys.path:
sys.path.insert(0, PLUGIN_ROOT)
# Derive plugin root from this file's location (hooks/ -> plugin root)
SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
PLUGIN_ROOT = os.path.dirname(SCRIPT_DIR)
if PLUGIN_ROOT not in sys.path:
sys.path.insert(0, PLUGIN_ROOT)

try:
from hookify.core.config_loader import load_rules
from hookify.core.rule_engine import RuleEngine
from core.config_loader import load_rules
from core.rule_engine import RuleEngine
except ImportError as e:
error_msg = {"systemMessage": f"Hookify import error: {e}"}
print(json.dumps(error_msg), file=sys.stdout)
Expand Down
24 changes: 10 additions & 14 deletions plugins/hookify/hooks/pretooluse.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,18 @@
import sys
import json

# CRITICAL: Add plugin root to Python path for imports
# We need to add the parent of the plugin directory so Python can find "hookify" package
PLUGIN_ROOT = os.environ.get('CLAUDE_PLUGIN_ROOT')
if PLUGIN_ROOT:
# Add the parent directory of the plugin
parent_dir = os.path.dirname(PLUGIN_ROOT)
if parent_dir not in sys.path:
sys.path.insert(0, parent_dir)

# Also add PLUGIN_ROOT itself in case we have other scripts
if PLUGIN_ROOT not in sys.path:
sys.path.insert(0, PLUGIN_ROOT)
# Derive plugin root from this file's location (hooks/ -> plugin root)
# This is reliable regardless of whether CLAUDE_PLUGIN_ROOT is set,
# and avoids the broken "hookify" package assumption caused by the
# version directory in the plugin cache path.
SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
PLUGIN_ROOT = os.path.dirname(SCRIPT_DIR)
if PLUGIN_ROOT not in sys.path:
sys.path.insert(0, PLUGIN_ROOT)

try:
from hookify.core.config_loader import load_rules
from hookify.core.rule_engine import RuleEngine
from core.config_loader import load_rules
from core.rule_engine import RuleEngine
except ImportError as e:
# If imports fail, allow operation and log error
error_msg = {"systemMessage": f"Hookify import error: {e}"}
Expand Down
17 changes: 7 additions & 10 deletions plugins/hookify/hooks/stop.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,15 @@
import sys
import json

# CRITICAL: Add plugin root to Python path for imports
PLUGIN_ROOT = os.environ.get('CLAUDE_PLUGIN_ROOT')
if PLUGIN_ROOT:
parent_dir = os.path.dirname(PLUGIN_ROOT)
if parent_dir not in sys.path:
sys.path.insert(0, parent_dir)
if PLUGIN_ROOT not in sys.path:
sys.path.insert(0, PLUGIN_ROOT)
# Derive plugin root from this file's location (hooks/ -> plugin root)
SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
PLUGIN_ROOT = os.path.dirname(SCRIPT_DIR)
if PLUGIN_ROOT not in sys.path:
sys.path.insert(0, PLUGIN_ROOT)

try:
from hookify.core.config_loader import load_rules
from hookify.core.rule_engine import RuleEngine
from core.config_loader import load_rules
from core.rule_engine import RuleEngine
except ImportError as e:
error_msg = {"systemMessage": f"Hookify import error: {e}"}
print(json.dumps(error_msg), file=sys.stdout)
Expand Down
17 changes: 7 additions & 10 deletions plugins/hookify/hooks/userpromptsubmit.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,15 @@
import sys
import json

# CRITICAL: Add plugin root to Python path for imports
PLUGIN_ROOT = os.environ.get('CLAUDE_PLUGIN_ROOT')
if PLUGIN_ROOT:
parent_dir = os.path.dirname(PLUGIN_ROOT)
if parent_dir not in sys.path:
sys.path.insert(0, parent_dir)
if PLUGIN_ROOT not in sys.path:
sys.path.insert(0, PLUGIN_ROOT)
# Derive plugin root from this file's location (hooks/ -> plugin root)
SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
PLUGIN_ROOT = os.path.dirname(SCRIPT_DIR)
if PLUGIN_ROOT not in sys.path:
sys.path.insert(0, PLUGIN_ROOT)

try:
from hookify.core.config_loader import load_rules
from hookify.core.rule_engine import RuleEngine
from core.config_loader import load_rules
from core.rule_engine import RuleEngine
except ImportError as e:
error_msg = {"systemMessage": f"Hookify import error: {e}"}
print(json.dumps(error_msg), file=sys.stdout)
Expand Down