77 lines
2.3 KiB
Bash
Executable file
77 lines
2.3 KiB
Bash
Executable file
#!/bin/bash
|
|
# Stop-Hook: Chat-Snapshot nach jeder Antwort — NUR für Claude_desktop Projekt
|
|
|
|
CWD_CHECK="${CLAUDE_PROJECT_DIR:-$PWD}"
|
|
if [[ "$CWD_CHECK" != *"Claude_desktop"* ]]; then
|
|
exit 0
|
|
fi
|
|
|
|
PROJECT_DIR="/Users/matthiaskoerner/Library/Mobile Documents/com~apple~CloudDocs/Claude_desktop"
|
|
STATUS_MD="$PROJECT_DIR/status.md"
|
|
JSONL_DIR="/Users/matthiaskoerner/.claude/projects/-Users-matthiaskoerner-Library-Mobile-Documents-com-apple-CloudDocs-Claude-desktop"
|
|
|
|
JSONL=$(ls -t "$JSONL_DIR"/*.jsonl 2>/dev/null | head -1)
|
|
[ -z "$JSONL" ] && exit 0
|
|
|
|
python3 - "$JSONL" "$STATUS_MD" << 'PYEOF'
|
|
import sys, json, os
|
|
from datetime import datetime
|
|
|
|
jsonl_path, out_path = sys.argv[1], sys.argv[2]
|
|
|
|
lines = []
|
|
try:
|
|
with open(jsonl_path) as f:
|
|
lines = f.readlines()
|
|
except:
|
|
sys.exit(0)
|
|
|
|
msgs = []
|
|
for line in lines[-60:]:
|
|
try:
|
|
entry = json.loads(line)
|
|
if entry.get("type") == "user":
|
|
msg = entry.get("message", {})
|
|
txt = ""
|
|
if isinstance(msg.get("content"), str):
|
|
txt = msg["content"]
|
|
elif isinstance(msg.get("content"), list):
|
|
for c in msg["content"]:
|
|
if isinstance(c, dict) and c.get("type") == "text":
|
|
txt += c.get("text", "")
|
|
if txt.strip():
|
|
msgs.append(("Bär", txt.strip()[:600]))
|
|
elif entry.get("type") == "assistant":
|
|
msg = entry.get("message", {})
|
|
txt = ""
|
|
if isinstance(msg.get("content"), list):
|
|
for c in msg["content"]:
|
|
if isinstance(c, dict) and c.get("type") == "text":
|
|
txt += c.get("text", "")
|
|
if txt.strip():
|
|
msgs.append(("Barby", txt.strip()[:1000]))
|
|
except:
|
|
continue
|
|
|
|
if not msgs:
|
|
sys.exit(0)
|
|
|
|
existing = ""
|
|
if os.path.exists(out_path):
|
|
with open(out_path) as f:
|
|
existing = f.read()
|
|
|
|
last_txt = msgs[-1][1] if msgs else ""
|
|
if last_txt and last_txt[:80] in existing[-3000:]:
|
|
sys.exit(0) # kein Duplikat
|
|
|
|
ts = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
|
content = f"\n---\n### {ts}\n"
|
|
for role, text in msgs[-4:]:
|
|
icon = "🧔" if role == "Bär" else "🤖"
|
|
content += f"**{icon} {role}:** {text}\n\n"
|
|
|
|
with open(out_path, "a") as f:
|
|
f.write(content)
|
|
PYEOF
|