#!/usr/bin/env python3 import glob, os, sqlite3, sys vec_path = "/app/node_modules/sqlite-vec-linux-x64/vec0.so" for db in sorted(glob.glob("/home/node/.openclaw/agents/*/agent/openclaw-agent.sqlite")): agent = os.path.basename(os.path.dirname(os.path.dirname(db))) if agent == "main": continue try: conn = sqlite3.connect(db, timeout=10.0) if os.path.exists(vec_path): conn.enable_load_extension(True) conn.load_extension(vec_path) cur = conn.cursor() chk = cur.execute("SELECT count(*) FROM memory_index_chunks").fetchone()[0] if chk > 0: print(f"[dedup_subagents] Purging {chk} duplicated vector chunks from agent {agent}...") for t in [ "memory_index_sources", "memory_index_chunks", "memory_index_chunk_recall_metadata", "memory_index_chunk_provenance", "memory_entry_origins", "memory_embedding_cache", "memory_index_chunks_vec" ]: try: cur.execute(f"DELETE FROM {t}") except Exception: pass conn.commit() cur.execute("VACUUM") print(f"[dedup_subagents] Reclaimed disk space for agent {agent}") conn.close() except Exception as e: print(f"[dedup_subagents] Notice for {agent}: {e}", file=sys.stderr)