90 lines
3.1 KiB
Python
90 lines
3.1 KiB
Python
#!/usr/bin/env python3
|
|
"""Evaluate all pending Engrams (verdict != confirmed_true/false) and set verdict automatically."""
|
|
|
|
import sys
|
|
import json
|
|
from pathlib import Path
|
|
|
|
BRAIN_DIR = Path("/root/.openclaw/workspace/second-brain")
|
|
sys.path.insert(0, str(BRAIN_DIR))
|
|
from src.store import EngramStore
|
|
|
|
DB_PATH = BRAIN_DIR / "data" / "brain.sqlite"
|
|
store = EngramStore(str(DB_PATH))
|
|
|
|
# Hole alle Engrams, die nicht confirmed_true oder confirmed_false sind
|
|
cursor = store._conn.execute("""
|
|
SELECT id, metadata_json, correctness_json FROM engrams
|
|
WHERE json_extract(correctness_json, '$.verdict') NOT IN ('confirmed_true', 'confirmed_false')
|
|
""")
|
|
rows = cursor.fetchall()
|
|
print(f"Pendings (nicht confirmed_true/false): {len(rows)}")
|
|
|
|
evaluated = 0
|
|
true_count = 0
|
|
false_count = 0
|
|
skipped = 0
|
|
|
|
for eid, meta_json, corr_json in rows:
|
|
try:
|
|
meta = json.loads(meta_json) if meta_json else {}
|
|
corr = json.loads(corr_json) if corr_json else {}
|
|
source = meta.get("source", "")
|
|
tags = meta.get("tags", [])
|
|
if isinstance(tags, str):
|
|
tags = [tags]
|
|
|
|
# Entscheidungsregeln
|
|
verdict = None
|
|
reason = None
|
|
|
|
if source == "worker":
|
|
verdict = "confirmed_true"
|
|
reason = "source=worker (system task)"
|
|
elif source == "memory":
|
|
safe_tags = ["ops", "housekeeping", "sop", "meta", "system", "documentation", "guide"]
|
|
if any(t in safe_tags for t in tags):
|
|
verdict = "confirmed_true"
|
|
reason = f"memory with safe tags"
|
|
else:
|
|
# Memory ohne bedenkliche Tags → tendenziell true
|
|
verdict = "confirmed_true"
|
|
reason = "memory (no negative tags)"
|
|
elif source == "agent":
|
|
verdict = "confirmed_true"
|
|
reason = "source=agent (AI output)"
|
|
else:
|
|
# Prüfe auf Fehler-Tags
|
|
error_tags = ["error", "failure", "exception", "bug", "critical", "issue", "problem"]
|
|
if any(t in error_tags for t in tags):
|
|
verdict = "confirmed_false"
|
|
reason = f"error tags present"
|
|
else:
|
|
# Default: true (dokumentarisch)
|
|
verdict = "confirmed_true"
|
|
reason = "default (no negative indicators)"
|
|
|
|
if verdict:
|
|
eg = store.get(eid)
|
|
if eg is None:
|
|
skipped += 1
|
|
continue
|
|
eg.correctness.verdict = verdict
|
|
if verdict == "confirmed_true":
|
|
eg.correctness.confirmed = True
|
|
true_count += 1
|
|
else:
|
|
eg.correctness.confirmed = False
|
|
false_count += 1
|
|
store.save(eg)
|
|
evaluated += 1
|
|
if evaluated % 100 == 0:
|
|
print(f" ... {evaluated} evaluiert (true={true_count}, false={false_count})")
|
|
except Exception as e:
|
|
print(f"Fehler bei {eid}: {e}")
|
|
|
|
print(f"Evaluierte Engrams: {evaluated}")
|
|
print(f" -> confirmed_true: {true_count}")
|
|
print(f" -> confirmed_false: {false_count}")
|
|
print(f" -> übersprungen: {skipped}")
|