-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrevert_memory_chain.py
More file actions
50 lines (44 loc) · 1.46 KB
/
revert_memory_chain.py
File metadata and controls
50 lines (44 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env python3
# @bigd-hook-meta
# name: revert_memory_chain
# fires_on: PostToolUse
# relevant_intents: [git, memory]
# irrelevant_intents: [bigd, pm, telegram, docx, x_tweet, vps, sync, debug]
# cost_score: 1
# always_fire: false
"""PostToolUse hook: after git revert or 'remove:' commit, remind to update memory."""
import io
import json
import re
import sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).parent))
from hook_base import run_hook
def check(tool_name, tool_input, input_data):
if tool_name != "Bash":
return False
cmd = tool_input.get("command", "")
return bool(re.search(
r"git\s+revert|"
r'git\s+commit.*["\'](remove|revert|undo|rollback)',
cmd, re.IGNORECASE
))
def action(tool_name, tool_input, input_data):
return (
"📋 **Revert detected.** Update memory to mark this as tried+rejected:\n"
"1. Find the relevant memory file\n"
"2. Add: what was tried, why it was reverted, what to do instead\n"
"3. This prevents re-proposing the same approach in future sessions"
)
if __name__ == "__main__":
_raw = sys.stdin.read()
try:
_prompt = json.loads(_raw).get("prompt", "") if _raw else ""
except Exception:
_prompt = ""
from _semantic_router import should_fire
if not should_fire(__file__, _prompt):
print("{}")
sys.exit(0)
sys.stdin = io.StringIO(_raw)
run_hook(check, action, "revert_memory_chain")