-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpivot_detect.py
More file actions
54 lines (43 loc) · 1.42 KB
/
pivot_detect.py
File metadata and controls
54 lines (43 loc) · 1.42 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
51
52
53
54
#!/usr/bin/env python3
# @bigd-hook-meta
# name: pivot_detect
# fires_on: UserPromptSubmit
# always_fire: true
# cost_score: 1
"""Pivot-detection hook — runs on every UserPromptSubmit, logs HIGH-tier pivots.
Logs to ~/.claude/state/pivot-log.jsonl. /s --pivot or manual review of this
log feeds survival guide §0.0 snapshot updates.
Silent on LOG/LOW; logs MED+HIGH; never blocks.
"""
import json
import sys
import time
from pathlib import Path
sys.path.insert(0, str(Path(__file__).parent))
from _safe_hook import safe_run
sys.path.insert(0, str(Path.home() / ".claude" / "scripts" / "pivot"))
from detect import detect
LOG_PATH = Path.home() / ".claude" / "state" / "pivot-log.jsonl"
LOG_PATH.parent.mkdir(parents=True, exist_ok=True)
def main() -> None:
payload = json.load(sys.stdin)
prompt = payload.get("prompt", "")
if not prompt:
print("{}")
return
result = detect(prompt)
tier = result.get("tier", "LOG")
if tier in ("HIGH", "MED"):
entry = {
"ts": int(time.time()),
"tier": tier,
"matches": result.get("matches", []),
"reasoning": result.get("reasoning", ""),
"session_id": payload.get("session_id", ""),
"prompt_excerpt": prompt[:200],
}
with open(LOG_PATH, "a") as f:
f.write(json.dumps(entry) + "\n")
print("{}")
if __name__ == "__main__":
safe_run(main, "pivot_detect")