feat: add proactive cron tasks and systemd timers\n\n- 10 proactive tasks: ingest with self-healing & link suggestions, daily summary, health check, archive stale, tag normalizer, predictive links, auto assign review, import context buffer\n- systemd timers for scheduling (02:00/14:00 slots, 30min intervals, weekly)\n- all tasks tested and working\n\nRefs: #1
This commit is contained in:
53
cron_tasks/auto_assign_review.py
Normal file
53
cron_tasks/auto_assign_review.py
Normal file
@@ -0,0 +1,53 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Markiert Engramme mit niedriger Confidence (<0.5) und ohne Bestätigung
|
||||
als 'needs_review' in metadata. Kann später manuell Review-Warteschlange abarbeiten.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import sqlite3
|
||||
import sys
|
||||
from datetime import datetime, timezone
|
||||
from pathlib import Path
|
||||
|
||||
BRAIN_DIR = Path("/root/.openclaw/workspace/second-brain")
|
||||
DB_PATH = BRAIN_DIR / "data" / "brain.sqlite"
|
||||
|
||||
def run():
|
||||
conn = sqlite3.connect(str(DB_PATH))
|
||||
conn.row_factory = sqlite3.Row
|
||||
c = conn.cursor()
|
||||
|
||||
# Engramme: confidence < 0.5 UND nicht confirmed (verdict != confirmed_true)
|
||||
c.execute("""
|
||||
SELECT id, metadata_json, correctness_json FROM engrams
|
||||
WHERE json_extract(metadata_json, '$.confidence') < 0.5
|
||||
AND (json_extract(correctness_json, '$.verdict') IS NULL
|
||||
OR json_extract(correctness_json, '$.verdict') != 'confirmed_true')
|
||||
""")
|
||||
rows = c.fetchall()
|
||||
|
||||
marked = 0
|
||||
for r in rows:
|
||||
meta = json.loads(r["metadata_json"] or "{}")
|
||||
tags = meta.get("tags", [])
|
||||
if "needs_review" not in tags:
|
||||
tags.append("needs_review")
|
||||
meta["tags"] = tags
|
||||
c.execute("UPDATE engrams SET metadata_json = ?, modified_at = ? WHERE id = ?",
|
||||
(json.dumps(meta), datetime.now(timezone.utc).isoformat(), r["id"]))
|
||||
marked += 1
|
||||
|
||||
conn.commit()
|
||||
conn.close()
|
||||
|
||||
print(json.dumps({
|
||||
"success": True,
|
||||
"time": datetime.now(timezone.utc).isoformat(),
|
||||
"marked_for_review": marked,
|
||||
}, indent=2, ensure_ascii=False))
|
||||
|
||||
if __name__ == "__main__":
|
||||
run()
|
||||
Reference in New Issue
Block a user