#!/usr/bin/env python3 """ Brain-Regeln - Automatische Bestaetigungs- und Archivierungslogik. Wird von Cron und Agent aufgerufen. """ import sys sys.path.insert(0, "/root/.openclaw/workspace/second-brain") from src.engram import Engram, Grounding from src.store import EngramStore DB = "/root/.openclaw/workspace/second-brain/data/brain.sqlite" def apply_rules(): store = EngramStore(DB) egs = store.get_all(limit=1000) actions = [] for eg in egs: conf = eg.compute_confidence() age_days = eg._age_days(eg.metadata.get("created", "")) correct = eg.correctness # Regel 1: Triple-Confirm → Auto-Verifiziert if not correct.confirmed and correct.confirmations >= 3: correct.confirmed = True correct.confirmations += 1 store.save(eg) actions.append(f"Auto-Confirm: {str(eg.id)[:8]} (3x confirmed)") # Regel 2: Lang unbestaetigt → ASSUMPTION Tag if age_days > 30 and not correct.confirmed and "archiviert" not in eg.metadata.get("tags", []): eg.metadata.setdefault("tags", []).append("archiviert") eg.metadata["archivgrund"] = f"Unbestaetigt seit {age_days} Tagen" store.save(eg) actions.append(f"Archiviert: {str(eg.id)[:8]} (Alter {age_days}d)") # Regel 3: Rejected mit 2+ Rejections → loeschen (Sanft: Tag statt rm) if correct.rejections >= 2: eg.metadata.setdefault("tags", []).append("deleted") store.save(eg) actions.append(f"Deleted-Tag: {str(eg.id)[:8]} ({correct.rejections}x rejected)") return actions if __name__ == "__main__": actions = apply_rules() print("Brain-Regeln angewendet:") for a in actions or ["Keine Aktionen noetig"]: print(f" {a}")