fix(cron): Session-Takeover-Workaround, mobil-Dashboard, Import-Fix standalone

- feat(isolation): Cron-Wrapper (subprocess, /workspace/cron_tasks)
- fix(dashboard): mobil-optimierte Karten statt Tabelle
- fix(imports): sys.path + venv auto-activation
- chore: Lasse flüchtiges /tmp hinter mir

Closes-Bug: Session-Takeover bei isolated Cron
Engramme-bestaetigt: Standalone-Import-OK, Wrapper-getestet
This commit is contained in:
2026-05-25 22:08:52 +02:00
parent 4e0f5e7e9a
commit a5d5b2f2ec
3 changed files with 122 additions and 81 deletions

View File

@@ -16,10 +16,27 @@ from pathlib import Path
from datetime import datetime, timezone
from typing import Optional, List, Dict, Any
# Ensure project root is on sys.path for standalone usage
project_root = str(Path(__file__).parent.parent)
if project_root not in sys.path:
sys.path.insert(0, project_root)
# Activate virtualenv if available (for chromadb etc.)
venv_path = Path(__file__).parent.parent / ".venv"
if venv_path.exists():
venv_site_packages = list((venv_path / "lib").glob("python3.*/site-packages"))
if venv_site_packages and str(venv_site_packages[0]) not in sys.path:
sys.path.insert(0, str(venv_site_packages[0]))
# Second Brain Import
from .store import EngramStore
from .engram import Engram, Grounding
from .retriever import Retriever
from src.engram import Engram, Grounding
from src.store import EngramStore
# Retriever: optional (braucht chromadb)
try:
from src.retriever import Retriever
except ImportError:
Retriever = None
# --- Konfiguration ---
@@ -75,11 +92,6 @@ def heartbeat_check() -> Optional[str]:
Rückgabe: Nachricht für den User, oder None wenn nichts zu tun.
"""
store = get_brain()
ret = Retriever(store)
# A: Unbestätigte Engramme die seit längerem nicht geprüft wurden
# B: Hohe-Prioritäts-Themen (tags wie "wichtig", "dringend")
# C: Fehler-Engramme die repeating sind
# Prüfe auf wichtige unbestätigte Engramme
egs = store.get_all(limit=50)
@@ -89,8 +101,7 @@ def heartbeat_check() -> Optional[str]:
][:5]
if unconfirmed:
ids = ", ".join([str(eg.id)[:8] for eg in unconfirmed])
contents = "\n".join([f" - {eg.content[:80]}" for eg in unconfimed])
contents = "\n".join([f" - {eg.content[:80]}" for eg in unconfirmed])
return (
f"🧠 Second Brain Heartbeat\n"
f"Unbestätigte Engramme mit gutem Confidence-Score:\n{contents}\n"
@@ -195,8 +206,15 @@ def enrich_context(topic: str, limit: int = 3) -> str:
# memory_context in das Prompt einbauen
"""
store = get_brain()
ret = Retriever(store)
results = ret.retrieve(topic, limit=limit, min_confidence=0.3)
# Versuche Retriever (mit Embeddings), fallback auf einfache Textsuche
if Retriever:
ret = Retriever(store)
results = ret.retrieve(topic, limit=limit, min_confidence=0.3)
else:
results_raw = store.search_text(topic, limit=limit)
results = [{"engram": eg, "score": 0.5} for eg in results_raw]
if not results:
return ""