Main entry point for PostToolUse hook.
()
| 28 | |
| 29 | |
| 30 | def main(): |
| 31 | """Main entry point for PostToolUse hook.""" |
| 32 | try: |
| 33 | # Read input from stdin |
| 34 | input_data = json.load(sys.stdin) |
| 35 | |
| 36 | # Determine event type based on tool |
| 37 | tool_name = input_data.get('tool_name', '') |
| 38 | event = None |
| 39 | if tool_name == 'Bash': |
| 40 | event = 'bash' |
| 41 | elif tool_name in ['Edit', 'Write', 'MultiEdit']: |
| 42 | event = 'file' |
| 43 | |
| 44 | # Load rules |
| 45 | rules = load_rules(event=event) |
| 46 | |
| 47 | # Evaluate rules |
| 48 | engine = RuleEngine() |
| 49 | result = engine.evaluate_rules(rules, input_data) |
| 50 | |
| 51 | # Always output JSON (even if empty) |
| 52 | print(json.dumps(result), file=sys.stdout) |
| 53 | |
| 54 | except Exception as e: |
| 55 | error_output = { |
| 56 | "systemMessage": f"Hookify error: {str(e)}" |
| 57 | } |
| 58 | print(json.dumps(error_output), file=sys.stdout) |
| 59 | |
| 60 | finally: |
| 61 | # ALWAYS exit 0 |
| 62 | sys.exit(0) |
| 63 | |
| 64 | |
| 65 | if __name__ == '__main__': |
no test coverage detected