#!/usr/bin/env python3 """ Markiert Engramme mit access_count=0, die älter als 7 Tage sind, als 'archived'. Reduziert Graph-Clutter und verbessert Performance. """ from __future__ import annotations import json import sqlite3 import sys from datetime import datetime, timezone, timedelta from pathlib import Path BRAIN_DIR = Path("/root/.openclaw/workspace/second-brain") DB_PATH = BRAIN_DIR / "data" / "brain.sqlite" def run(): now = datetime.now(timezone.utc) cutoff = now - timedelta(days=7) conn = sqlite3.connect(str(DB_PATH)) conn.row_factory = sqlite3.Row c = conn.cursor() # Engramme finden: access_count=0 UND created_at älter als 7 Tage c.execute(""" SELECT id, metadata_json FROM engrams WHERE json_extract(metadata_json, '$.access_count') = 0 AND created_at < ? """, (cutoff.isoformat(),)) rows = c.fetchall() archived = 0 for r in rows: meta = json.loads(r["metadata_json"] or "{}") tags = meta.get("tags", []) if "archived" not in tags: tags.append("archived") meta["tags"] = tags c.execute("UPDATE engrams SET metadata_json = ?, modified_at = ? WHERE id = ?", (json.dumps(meta), now.isoformat(), r["id"])) archived += 1 conn.commit() conn.close() print(json.dumps({ "success": True, "time": now.isoformat(), "archived_count": archived, "cutoff_date": cutoff.isoformat(), }, indent=2, ensure_ascii=False)) if __name__ == "__main__": run()