File size: 1,180 Bytes
c2b0d2a | 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 | #!/usr/bin/env python3
"""Auto-reset channel sessions with >50 messages. Run via picoclaw cron."""
import os, json, shutil
sess = os.path.expanduser("~/.picoclaw/workspace/sessions")
backup = sess + "_backup"
os.makedirs(backup, exist_ok=True)
reset = []
if os.path.exists(sess):
for f in os.listdir(sess):
if not f.endswith('.meta.json'):
continue
full = os.path.join(sess, f)
try:
with open(full) as fh:
meta = json.load(fh)
count = meta.get("count", 0)
chat = meta.get("scope", {}).get("values", {}).get("chat", "")
if count > 50 and "channel:" in chat:
base = f.replace('.meta.json', '')
for suffix in ['.meta.json', '.jsonl']:
target = os.path.join(sess, base + suffix)
if os.path.exists(target):
shutil.copy2(target, os.path.join(backup, base + suffix))
os.remove(target)
reset.append(f"{base} (count={count})")
except:
pass
print(f"Auto-reset: {len(reset)} sessions reset")
for r in reset:
print(f" {r}")
|