Download hooks/session_auto_reset.py from ameobius/dev-box: direct link, hf CLI and curl.
- Browser
- Download file 1.18 kB
-
https://huggingface.co/spaces/ameobius/dev-box/resolve/main/hooks/session_auto_reset.py
- Command line
-
hf download hf://spaces/ameobius/dev-box/hooks/session_auto_reset.py
-
curl -L -o session_auto_reset.py https://huggingface.co/spaces/ameobius/dev-box/resolve/main/hooks/session_auto_reset.py
1.18 kB
| #!/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}") | |