Compare commits
25 Commits
v0.3.1
...
a261f5b9e1
| Author | SHA1 | Date | |
|---|---|---|---|
| a261f5b9e1 | |||
| e6e8eba8f6 | |||
| 20098a3253 | |||
| fa2ba11b66 | |||
| 7dfd9c4228 | |||
| 6d99c520e6 | |||
| f10a5b9f19 | |||
| 6232f25cc9 | |||
| 6b0cf5889f | |||
| 021fd0e328 | |||
| d52e3a7f74 | |||
| 1635ee8b03 | |||
| f8ac0af869 | |||
| 9dd5e49e2a | |||
| b158b19208 | |||
| 095e6a33f8 | |||
| e5061b317f | |||
| ec8870ea40 | |||
| 8f47151a48 | |||
| 83b85cb760 | |||
| e1640071e4 | |||
| 29bc45d623 | |||
| a5d5b2f2ec | |||
| 4e0f5e7e9a | |||
| 2436460b27 |
1
.streamlit/secrets.toml
Normal file
1
.streamlit/secrets.toml
Normal file
@@ -0,0 +1 @@
|
|||||||
|
[default]
|
||||||
23
README.md
23
README.md
@@ -8,7 +8,28 @@ An embeddable, offline-first memory system for AI agents with correctness tracki
|
|||||||
- **ChromaDB Vector Store** (`src/chroma_store.py`) — Semantic similarity search
|
- **ChromaDB Vector Store** (`src/chroma_store.py`) — Semantic similarity search
|
||||||
- **Neural Confidence Scorer** (`src/neural_scorer.py`) — PyTorch RL net, trains on confirm/reject feedback
|
- **Neural Confidence Scorer** (`src/neural_scorer.py`) — PyTorch RL net, trains on confirm/reject feedback
|
||||||
- **Hybrid Retrieval** (`src/retriever.py`) — Keyword + Semantic + Neural fusion
|
- **Hybrid Retrieval** (`src/retriever.py`) — Keyword + Semantic + Neural fusion
|
||||||
- **Streamlit Dashboard** (`src/app_dashboard.py`) — Search, confirm/reject, neural training UI
|
- **FastAPI Dashboard** (`fastapi_app.py`) — Lightweight web UI (search + confirm/reject) and JSON API
|
||||||
|
- **Streamlit Dashboard** (`src/app_dashboard.py`) — (optional) richer UI for neural training, etc.
|
||||||
- **Graph Visualization** (`src/graph_view.py`) — Interactive Cytoscape.js graph with confidence colors
|
- **Graph Visualization** (`src/graph_view.py`) — Interactive Cytoscape.js graph with confidence colors
|
||||||
|
|
||||||
## Architecture
|
## Architecture
|
||||||
|
|
||||||
|
## Obsidian
|
||||||
|
|
||||||
|
Setup and timers: `second-brain/docs/OBSIDIAN.md`
|
||||||
|
|
||||||
|
## Quickstart (Dashboard)
|
||||||
|
|
||||||
|
Install minimal dashboard deps:
|
||||||
|
|
||||||
|
`python3 -m pip install -r requirements-dashboard.txt`
|
||||||
|
|
||||||
|
Run:
|
||||||
|
|
||||||
|
`SECOND_BRAIN_WORKSPACE="$(pwd)" python3 fastapi_app.py`
|
||||||
|
|
||||||
|
Then open: `http://localhost:8501/`
|
||||||
|
|
||||||
|
Port is configurable via `SECOND_BRAIN_PORT` (or `PORT`), e.g.:
|
||||||
|
|
||||||
|
`SECOND_BRAIN_WORKSPACE="$(pwd)" SECOND_BRAIN_PORT=8502 python3 fastapi_app.py`
|
||||||
|
|||||||
99
RUNBOOK.md
Normal file
99
RUNBOOK.md
Normal file
@@ -0,0 +1,99 @@
|
|||||||
|
# Second-Brain 2.0 (Grundversion) — Runbook
|
||||||
|
|
||||||
|
This is the operational quick-reference for the shipped systemd timers/services and the optional FastAPI dashboard backend.
|
||||||
|
|
||||||
|
Repository root (on host): `/root/.openclaw/workspace/second-brain`
|
||||||
|
|
||||||
|
Integration + orchestration docs live in the workspace repo:
|
||||||
|
|
||||||
|
- `/root/.openclaw/workspace/docs/SECOND_BRAIN.md`
|
||||||
|
- `/root/.openclaw/workspace/docs/GITEA.md`
|
||||||
|
|
||||||
|
## Systemd units (cron jobs)
|
||||||
|
|
||||||
|
Unit files are shipped in `systemd/` (this repo). Install them into `/etc/systemd/system/` (symlink or copy), then reload:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo ln -sf /root/.openclaw/workspace/second-brain/systemd/openclaw-secondbrain-*.service /etc/systemd/system/
|
||||||
|
sudo ln -sf /root/.openclaw/workspace/second-brain/systemd/openclaw-secondbrain-*.timer /etc/systemd/system/
|
||||||
|
sudo ln -sf /root/.openclaw/workspace/second-brain/systemd/openclaw-memory-archive.* /etc/systemd/system/
|
||||||
|
sudo systemctl daemon-reload
|
||||||
|
```
|
||||||
|
|
||||||
|
Optional (verification hardening):
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo ln -sf /root/.openclaw/workspace/second-brain/systemd/openclaw-secondbrain-verify-pending.* /etc/systemd/system/
|
||||||
|
sudo systemctl daemon-reload
|
||||||
|
sudo systemctl enable --now openclaw-secondbrain-verify-pending.timer
|
||||||
|
```
|
||||||
|
|
||||||
|
Enable timers:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo systemctl enable --now openclaw-secondbrain-ingest-memory.timer
|
||||||
|
sudo systemctl enable --now openclaw-secondbrain-index-vectors.timer
|
||||||
|
sudo systemctl enable --now openclaw-secondbrain-review.timer
|
||||||
|
sudo systemctl enable --now openclaw-secondbrain-backup.timer
|
||||||
|
sudo systemctl enable --now openclaw-secondbrain-heartbeat.timer
|
||||||
|
sudo systemctl enable --now openclaw-secondbrain-proactive-search.timer
|
||||||
|
sudo systemctl enable --now openclaw-memory-archive.timer
|
||||||
|
|
||||||
|
# Optional (Obsidian coupling)
|
||||||
|
sudo systemctl enable --now openclaw-secondbrain-ingest-obsidian.timer
|
||||||
|
sudo systemctl enable --now openclaw-secondbrain-export-obsidian.timer
|
||||||
|
```
|
||||||
|
|
||||||
|
Verify scheduling:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo systemctl list-timers --all | grep -E 'openclaw-(secondbrain|memory-archive)' || true
|
||||||
|
```
|
||||||
|
|
||||||
|
Run a job once:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo systemctl start openclaw-secondbrain-ingest-memory.service
|
||||||
|
sudo systemctl status openclaw-secondbrain-ingest-memory.service --no-pager
|
||||||
|
sudo journalctl -u openclaw-secondbrain-ingest-memory.service -n 200 --no-pager
|
||||||
|
```
|
||||||
|
|
||||||
|
Wrapper logs:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
tail -n 200 /root/.openclaw/workspace/cron_wrapper.log
|
||||||
|
```
|
||||||
|
|
||||||
|
## FastAPI dashboard (manual start)
|
||||||
|
|
||||||
|
FastAPI entrypoint:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cd /root/.openclaw/workspace
|
||||||
|
python3 -m pip install -r second-brain/requirements-dashboard.txt
|
||||||
|
SECOND_BRAIN_WORKSPACE="/root/.openclaw/workspace/second-brain" python3 second-brain/fastapi_app.py
|
||||||
|
```
|
||||||
|
|
||||||
|
Default port is `8501` (same as Streamlit default). You can override via `SECOND_BRAIN_PORT` (or `PORT`) when starting manually.
|
||||||
|
|
||||||
|
Endpoint smoke tests:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -fsS http://127.0.0.1:8501/api/stats
|
||||||
|
curl -fsS "http://127.0.0.1:8501/api/engrams?limit=1&offset=0"
|
||||||
|
curl -fsS "http://127.0.0.1:8501/api/search?q=test&limit=1"
|
||||||
|
```
|
||||||
|
|
||||||
|
## DB quick check
|
||||||
|
|
||||||
|
```bash
|
||||||
|
python3 - <<'PY'
|
||||||
|
import sqlite3
|
||||||
|
db="/root/.openclaw/workspace/second-brain/data/brain.sqlite"
|
||||||
|
con=sqlite3.connect(db)
|
||||||
|
cur=con.cursor()
|
||||||
|
print(cur.execute("PRAGMA integrity_check").fetchone()[0])
|
||||||
|
print("engrams:", cur.execute("SELECT COUNT(*) FROM engrams").fetchone()[0])
|
||||||
|
con.close()
|
||||||
|
PY
|
||||||
|
```
|
||||||
119
chat_autosave.py
Normal file
119
chat_autosave.py
Normal file
@@ -0,0 +1,119 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
"""
|
||||||
|
Chat-Auto-Save: Wertvolle User-Nachrichten → Engramm.
|
||||||
|
Wird am Ende jeder Main-Session-Antwort aufgerufen.
|
||||||
|
"""
|
||||||
|
|
||||||
|
import sys
|
||||||
|
import json
|
||||||
|
import hashlib
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
BRAIN_DIR = Path("/root/.openclaw/workspace/second-brain")
|
||||||
|
sys.path.insert(0, str(BRAIN_DIR))
|
||||||
|
|
||||||
|
from src.engram import Engram, Grounding
|
||||||
|
from src.store import EngramStore
|
||||||
|
|
||||||
|
DB_PATH = BRAIN_DIR / "data" / "brain.sqlite"
|
||||||
|
|
||||||
|
|
||||||
|
def _hash(text: str) -> str:
|
||||||
|
return hashlib.sha256(text.encode("utf-8")).hexdigest()[:12]
|
||||||
|
|
||||||
|
|
||||||
|
def is_fluff(content: str) -> bool:
|
||||||
|
"""Prüft ob Inhalt nur Floskel ist."""
|
||||||
|
lower = content.lower().strip().rstrip(".?!")
|
||||||
|
short_fluff = [
|
||||||
|
"hallo", "hi", "hey", "guten tag", "guten morgen", "guten abend",
|
||||||
|
"danke", "ok", "okay", "ja", "nein", "bitte", "gerne", "tschüss",
|
||||||
|
"bis später", "bis morgen", "alles klar", "in ordnung",
|
||||||
|
]
|
||||||
|
if lower in short_fluff:
|
||||||
|
return True
|
||||||
|
if len(content) < 10 and all(c in " ?,!.;:-" for c in content):
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def save_if_worthy(content: str, source: str = "user", tags: list = None,
|
||||||
|
confidence: float = 0.7, session_id: str = None,
|
||||||
|
reasoning: str = None) -> dict:
|
||||||
|
"""
|
||||||
|
Speichert Nachricht als Engramm wenn sie Wert hat.
|
||||||
|
Wird in jeder Antwort aufgerufen.
|
||||||
|
"""
|
||||||
|
|
||||||
|
if is_fluff(content):
|
||||||
|
return {"saved": False, "reason": "fluff"}
|
||||||
|
|
||||||
|
store = EngramStore(str(DB_PATH))
|
||||||
|
content_hash = _hash(content)
|
||||||
|
recent = store.get_all(limit=200)
|
||||||
|
for eg in recent:
|
||||||
|
if _hash(eg.content) == content_hash:
|
||||||
|
return {"saved": False, "reason": "duplicate", "id": str(eg.id)}
|
||||||
|
|
||||||
|
eg = Engram.create(
|
||||||
|
content=content,
|
||||||
|
source=source,
|
||||||
|
tags=tags or ["auto-save", "chat"],
|
||||||
|
session_id=session_id,
|
||||||
|
confidence=confidence,
|
||||||
|
grounding=Grounding.ASSUMPTION,
|
||||||
|
)
|
||||||
|
store.save(eg)
|
||||||
|
|
||||||
|
return {
|
||||||
|
"saved": True,
|
||||||
|
"id": str(eg.id),
|
||||||
|
"confidence": eg.compute_confidence(),
|
||||||
|
"first8": str(eg.id)[:8],
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def enrich_prompt(topic: str, limit: int = 3) -> str:
|
||||||
|
"""
|
||||||
|
Holt relevante bestätigte Engramme für Kontext-Anreicherung.
|
||||||
|
Wird VOR jeder Antwort aufgerufen.
|
||||||
|
"""
|
||||||
|
store = EngramStore(str(DB_PATH))
|
||||||
|
recent = store.get_all(limit=100)
|
||||||
|
|
||||||
|
# Einfache Text-Suche (kein FTS wegen Satzzeichen)
|
||||||
|
topic_lower = topic.lower()
|
||||||
|
matches = []
|
||||||
|
for eg in recent:
|
||||||
|
if eg.correctness.confirmed and topic_lower in eg.content.lower():
|
||||||
|
matches.append(eg)
|
||||||
|
elif len(matches) < limit and any(t in topic_lower for t in [t.lower() for t in eg.metadata.get("tags", [])]):
|
||||||
|
matches.append(eg)
|
||||||
|
if len(matches) >= limit:
|
||||||
|
break
|
||||||
|
|
||||||
|
if not matches:
|
||||||
|
return ""
|
||||||
|
|
||||||
|
lines = ["\n📚 Relevantes Wissen:"]
|
||||||
|
for eg in matches[:limit]:
|
||||||
|
lines.append(f" • [{eg.compute_confidence():.0%}] {eg.content[:120]}")
|
||||||
|
|
||||||
|
return "\n".join(lines)
|
||||||
|
|
||||||
|
|
||||||
|
def check_pending(session_id: str = None) -> list:
|
||||||
|
"""Gibt unbestätigte Engramme zurück."""
|
||||||
|
store = EngramStore(str(DB_PATH))
|
||||||
|
egs = store.get_all(limit=50)
|
||||||
|
pending = [eg for eg in egs if not eg.correctness.confirmed]
|
||||||
|
return pending
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
import sys
|
||||||
|
if len(sys.argv) > 1:
|
||||||
|
result = save_if_worthy(sys.argv[1])
|
||||||
|
print(json.dumps(result, indent=2))
|
||||||
|
else:
|
||||||
|
print("Usage: python3 chat_autosave.py 'Nachricht'")
|
||||||
22
cron_tasks/backup_secondbrain.py
Normal file
22
cron_tasks/backup_secondbrain.py
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
"""Backup-Task für Second Brain - isoliert, persistent."""
|
||||||
|
import json, os, sys
|
||||||
|
from pathlib import Path
|
||||||
|
from datetime import datetime, timezone
|
||||||
|
|
||||||
|
BRAIN_DIR = Path("/root/.openclaw/workspace/second-brain")
|
||||||
|
sys.path.insert(0, str(BRAIN_DIR))
|
||||||
|
from src.store import EngramStore
|
||||||
|
|
||||||
|
def main():
|
||||||
|
brain_db = os.environ.get("BRAIN_DB", str(BRAIN_DIR / "data" / "brain.sqlite"))
|
||||||
|
store = EngramStore(brain_db)
|
||||||
|
ts = datetime.now(timezone.utc).strftime("%Y%m%d_%H%M%S")
|
||||||
|
backup_path = Path(brain_db).parent / f"backup_{ts}.jsonl"
|
||||||
|
count = store.export_jsonl(str(backup_path))
|
||||||
|
result = {"timestamp": datetime.now(timezone.utc).isoformat(), "backup_path": str(backup_path), "count": count, "success": True}
|
||||||
|
print(f"BACKUP: {count} Engramme -> {backup_path}")
|
||||||
|
return 0
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
sys.exit(main())
|
||||||
53
cron_tasks/brain_rules.py
Normal file
53
cron_tasks/brain_rules.py
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
#!/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}")
|
||||||
47
cron_tasks/heartbeat_secondbrain.py
Normal file
47
cron_tasks/heartbeat_secondbrain.py
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
"""
|
||||||
|
Heartbeat-Task für Second Brain - isoliert, persistent.
|
||||||
|
"""
|
||||||
|
|
||||||
|
import json
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
from pathlib import Path
|
||||||
|
from datetime import datetime, timezone
|
||||||
|
|
||||||
|
BRAIN_DIR = Path("/root/.openclaw/workspace/second-brain")
|
||||||
|
sys.path.insert(0, str(BRAIN_DIR))
|
||||||
|
|
||||||
|
from src.engram import Engram, Grounding
|
||||||
|
from src.store import EngramStore
|
||||||
|
|
||||||
|
def main():
|
||||||
|
output_file = os.environ.get("CRON_OUTPUT_FILE", "/tmp/heartbeat_result.json")
|
||||||
|
brain_db = os.environ.get("BRAIN_DB", str(BRAIN_DIR / "data" / "brain.sqlite"))
|
||||||
|
store = EngramStore(brain_db)
|
||||||
|
|
||||||
|
egs = store.get_all(limit=50)
|
||||||
|
unconfirmed = [eg for eg in egs if not eg.correctness.confirmed and eg.compute_confidence() > 0.5][:5]
|
||||||
|
errors = store.search_tag("error", limit=5)
|
||||||
|
|
||||||
|
result = {
|
||||||
|
"timestamp": datetime.now(timezone.utc).isoformat(),
|
||||||
|
"total_engrams": len(egs),
|
||||||
|
"unconfirmed_count": len(unconfirmed),
|
||||||
|
"error_count": len(errors),
|
||||||
|
"has_action": bool(unconfirmed) or len(errors) >= 3,
|
||||||
|
"message": None,
|
||||||
|
}
|
||||||
|
|
||||||
|
if unconfirmed:
|
||||||
|
contents = "\n".join([f" - {eg.content[:80]}" for eg in unconfirmed])
|
||||||
|
result["message"] = f"🧠 Unbestätigte Engramme:\n{contents}"
|
||||||
|
elif len(errors) >= 3:
|
||||||
|
result["message"] = f"⚠️ {len(errors)} Fehler-Engramme gespeichert."
|
||||||
|
|
||||||
|
Path(output_file).write_text(json.dumps(result, indent=2))
|
||||||
|
print(f"HEARTBEAT: {result['unconfirmed_count']} unconfirmed, {result['error_count']} errors")
|
||||||
|
return 0
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
sys.exit(main())
|
||||||
160
cron_tasks/ingest_transcript_to_db.py
Normal file
160
cron_tasks/ingest_transcript_to_db.py
Normal file
@@ -0,0 +1,160 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
"""
|
||||||
|
Ingest OpenClaw session transcript JSONL directly into the Second-Brain DB.
|
||||||
|
|
||||||
|
State is tracked with byte offsets per transcript file.
|
||||||
|
Sources are configured via workspace/memory/session_sources.json.
|
||||||
|
"""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import json
|
||||||
|
import os
|
||||||
|
from dataclasses import dataclass
|
||||||
|
from datetime import datetime, timezone
|
||||||
|
from pathlib import Path
|
||||||
|
from typing import Any, Dict, Iterable, List
|
||||||
|
from uuid import NAMESPACE_URL, uuid5
|
||||||
|
|
||||||
|
WORKSPACE = Path("/root/.openclaw/workspace")
|
||||||
|
MEMORY_DIR = WORKSPACE / "memory"
|
||||||
|
SOURCES_PATH = MEMORY_DIR / "session_sources.json"
|
||||||
|
STATE_PATH = MEMORY_DIR / "session_db_ingest_state.json"
|
||||||
|
|
||||||
|
BRAIN_DIR = WORKSPACE / "second-brain"
|
||||||
|
DB_PATH = Path(os.environ.get("BRAIN_DB", str(BRAIN_DIR / "data" / "brain.sqlite")))
|
||||||
|
|
||||||
|
import sys
|
||||||
|
|
||||||
|
sys.path.insert(0, str(BRAIN_DIR))
|
||||||
|
from src.engram import Engram, Grounding # type: ignore
|
||||||
|
from src.store import EngramStore # type: ignore
|
||||||
|
|
||||||
|
|
||||||
|
def _now() -> str:
|
||||||
|
return datetime.now(timezone.utc).isoformat()
|
||||||
|
|
||||||
|
|
||||||
|
def _load_json(path: Path, default: Any) -> Any:
|
||||||
|
try:
|
||||||
|
if not path.exists():
|
||||||
|
return default
|
||||||
|
return json.loads(path.read_text(encoding="utf-8"))
|
||||||
|
except Exception:
|
||||||
|
return default
|
||||||
|
|
||||||
|
|
||||||
|
def _save_json(path: Path, payload: Any) -> None:
|
||||||
|
path.parent.mkdir(parents=True, exist_ok=True)
|
||||||
|
path.write_text(json.dumps(payload, indent=2, ensure_ascii=False) + "\n", encoding="utf-8")
|
||||||
|
|
||||||
|
|
||||||
|
def _extract_text(content: Any) -> str:
|
||||||
|
if isinstance(content, str):
|
||||||
|
return content.strip()
|
||||||
|
if isinstance(content, list):
|
||||||
|
parts: List[str] = []
|
||||||
|
for c in content:
|
||||||
|
if isinstance(c, dict) and c.get("type") == "text" and isinstance(c.get("text"), str):
|
||||||
|
parts.append(c["text"])
|
||||||
|
elif isinstance(c, str):
|
||||||
|
parts.append(c)
|
||||||
|
return "\n".join(p.strip() for p in parts if p and p.strip()).strip()
|
||||||
|
if isinstance(content, dict) and isinstance(content.get("text"), str):
|
||||||
|
return content["text"].strip()
|
||||||
|
return str(content).strip()
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class Source:
|
||||||
|
label: str
|
||||||
|
transcript_path: Path
|
||||||
|
|
||||||
|
|
||||||
|
def _load_sources() -> List[Source]:
|
||||||
|
payload = _load_json(SOURCES_PATH, {"sources": []})
|
||||||
|
sources: List[Source] = []
|
||||||
|
for item in payload.get("sources", []) if isinstance(payload, dict) else []:
|
||||||
|
if not isinstance(item, dict):
|
||||||
|
continue
|
||||||
|
label = str(item.get("label") or "session")
|
||||||
|
p = item.get("path")
|
||||||
|
if not isinstance(p, str) or not p:
|
||||||
|
continue
|
||||||
|
sources.append(Source(label=label, transcript_path=Path(p)))
|
||||||
|
return sources
|
||||||
|
|
||||||
|
|
||||||
|
def _iter_new_lines(path: Path, *, start_offset: int) -> Iterable[tuple[int, str]]:
|
||||||
|
with open(path, "rb") as f:
|
||||||
|
f.seek(max(0, int(start_offset)))
|
||||||
|
while True:
|
||||||
|
raw = f.readline()
|
||||||
|
if not raw:
|
||||||
|
break
|
||||||
|
line = raw.decode("utf-8", errors="ignore").strip()
|
||||||
|
if not line:
|
||||||
|
continue
|
||||||
|
yield (f.tell(), line)
|
||||||
|
|
||||||
|
|
||||||
|
def run() -> Dict[str, Any]:
|
||||||
|
if not DB_PATH.exists():
|
||||||
|
return {"success": False, "time": _now(), "error": f"db missing: {DB_PATH}"}
|
||||||
|
|
||||||
|
sources = _load_sources()
|
||||||
|
state = _load_json(STATE_PATH, {"offsets": {}})
|
||||||
|
offsets: Dict[str, int] = state.get("offsets", {}) if isinstance(state, dict) else {}
|
||||||
|
|
||||||
|
store = EngramStore(str(DB_PATH))
|
||||||
|
out = {"success": True, "time": _now(), "sources": len(sources), "messages_saved": 0, "messages_skipped": 0, "errors": []}
|
||||||
|
|
||||||
|
for src in sources:
|
||||||
|
try:
|
||||||
|
if not src.transcript_path.exists():
|
||||||
|
continue
|
||||||
|
key = str(src.transcript_path)
|
||||||
|
start = int(offsets.get(key, 0))
|
||||||
|
for new_off, line in _iter_new_lines(src.transcript_path, start_offset=start):
|
||||||
|
offsets[key] = new_off
|
||||||
|
obj = json.loads(line)
|
||||||
|
if not isinstance(obj, dict) or obj.get("type") != "message":
|
||||||
|
continue
|
||||||
|
msg = obj.get("message") if isinstance(obj.get("message"), dict) else {}
|
||||||
|
role = str(msg.get("role") or "unknown")
|
||||||
|
content = _extract_text(msg.get("content"))
|
||||||
|
if len(content.strip()) < 5:
|
||||||
|
continue
|
||||||
|
mid = str(obj.get("id") or msg.get("id") or msg.get("messageId") or msg.get("message_id") or "")
|
||||||
|
if not mid:
|
||||||
|
mid = str(uuid5(NAMESPACE_URL, f"openclaw-transcript:{src.label}:{role}:{content[:200]}"))
|
||||||
|
eid = str(uuid5(NAMESPACE_URL, f"openclaw-transcript:{src.label}:{mid}"))
|
||||||
|
if store.get(eid):
|
||||||
|
out["messages_skipped"] += 1
|
||||||
|
continue
|
||||||
|
eg = Engram.create(
|
||||||
|
content=f"[transcript:{src.label}] [{role}] [{mid}]\n\n{content}"[:4000],
|
||||||
|
source="session",
|
||||||
|
tags=["session", "openclaw", "transcript", f"role:{role}"],
|
||||||
|
session_id=src.label,
|
||||||
|
confidence=0.55,
|
||||||
|
grounding=Grounding.ASSUMPTION,
|
||||||
|
)
|
||||||
|
eg.id = uuid5(NAMESPACE_URL, eid)
|
||||||
|
eg.metadata["source"] = "session"
|
||||||
|
eg.metadata["session_id"] = src.label
|
||||||
|
eg.metadata["role"] = role
|
||||||
|
eg.metadata["message_id"] = mid
|
||||||
|
store.save(eg)
|
||||||
|
out["messages_saved"] += 1
|
||||||
|
except Exception as e:
|
||||||
|
out["success"] = False
|
||||||
|
out["errors"].append(f"{src.transcript_path}: {e}")
|
||||||
|
|
||||||
|
_save_json(STATE_PATH, {"offsets": offsets, "updated_at": out["time"]})
|
||||||
|
return out
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
print(json.dumps(run(), ensure_ascii=False, indent=2))
|
||||||
|
|
||||||
213
cron_tasks/ingest_transcript_to_memory.py
Normal file
213
cron_tasks/ingest_transcript_to_memory.py
Normal file
@@ -0,0 +1,213 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
"""
|
||||||
|
Tail OpenClaw session transcript JSONL files and append new messages into
|
||||||
|
workspace/memory/YYYY-MM-DD.md so the existing ingest_memory pipeline can pick
|
||||||
|
them up.
|
||||||
|
|
||||||
|
Why: when chat_autosave hooks are missed/aborted, the "memory/*.md -> DB" ingest
|
||||||
|
doesn't see the latest conversation. This bridges transcript -> memory.
|
||||||
|
|
||||||
|
Safety: read-only access to transcript files; state stored in workspace/memory/.
|
||||||
|
"""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import json
|
||||||
|
import os
|
||||||
|
from dataclasses import dataclass
|
||||||
|
from datetime import datetime, timezone
|
||||||
|
from pathlib import Path
|
||||||
|
from typing import Any, Dict, Iterable, List, Optional
|
||||||
|
|
||||||
|
try:
|
||||||
|
from zoneinfo import ZoneInfo # py3.9+
|
||||||
|
except Exception: # pragma: no cover
|
||||||
|
ZoneInfo = None # type: ignore
|
||||||
|
|
||||||
|
|
||||||
|
WORKSPACE = Path("/root/.openclaw/workspace")
|
||||||
|
MEMORY_DIR = WORKSPACE / "memory"
|
||||||
|
SOURCES_PATH = MEMORY_DIR / "session_sources.json"
|
||||||
|
STATE_PATH = MEMORY_DIR / "session_ingest_state.json"
|
||||||
|
|
||||||
|
|
||||||
|
def _local_tz():
|
||||||
|
tz = os.environ.get("TZ") or "Europe/Berlin"
|
||||||
|
if ZoneInfo:
|
||||||
|
try:
|
||||||
|
return ZoneInfo(tz)
|
||||||
|
except Exception:
|
||||||
|
return timezone.utc
|
||||||
|
return timezone.utc
|
||||||
|
|
||||||
|
|
||||||
|
def _load_json(path: Path, default: Any) -> Any:
|
||||||
|
try:
|
||||||
|
if not path.exists():
|
||||||
|
return default
|
||||||
|
return json.loads(path.read_text(encoding="utf-8"))
|
||||||
|
except Exception:
|
||||||
|
return default
|
||||||
|
|
||||||
|
|
||||||
|
def _save_json(path: Path, payload: Any) -> None:
|
||||||
|
path.parent.mkdir(parents=True, exist_ok=True)
|
||||||
|
path.write_text(json.dumps(payload, indent=2, ensure_ascii=False) + "\n", encoding="utf-8")
|
||||||
|
|
||||||
|
|
||||||
|
def _iso_to_dt(ts: str) -> Optional[datetime]:
|
||||||
|
try:
|
||||||
|
if ts.endswith("Z"):
|
||||||
|
ts = ts[:-1] + "+00:00"
|
||||||
|
return datetime.fromisoformat(ts)
|
||||||
|
except Exception:
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def _ms_to_dt(ms: int) -> datetime:
|
||||||
|
return datetime.fromtimestamp(ms / 1000, tz=timezone.utc)
|
||||||
|
|
||||||
|
|
||||||
|
def _extract_text(content: Any) -> str:
|
||||||
|
if isinstance(content, str):
|
||||||
|
return content.strip()
|
||||||
|
if isinstance(content, list):
|
||||||
|
parts: List[str] = []
|
||||||
|
for c in content:
|
||||||
|
if isinstance(c, dict) and c.get("type") == "text" and isinstance(c.get("text"), str):
|
||||||
|
parts.append(c["text"])
|
||||||
|
elif isinstance(c, str):
|
||||||
|
parts.append(c)
|
||||||
|
return "\n".join(p.strip() for p in parts if p and p.strip()).strip()
|
||||||
|
if isinstance(content, dict):
|
||||||
|
if isinstance(content.get("text"), str):
|
||||||
|
return content["text"].strip()
|
||||||
|
return str(content).strip()
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class Source:
|
||||||
|
label: str
|
||||||
|
transcript_path: Path
|
||||||
|
|
||||||
|
|
||||||
|
def _load_sources() -> List[Source]:
|
||||||
|
"""
|
||||||
|
Sources file format:
|
||||||
|
{
|
||||||
|
"sources": [
|
||||||
|
{ "label": "telegram:263887248", "path": "/root/.openclaw/agents/main/sessions/<id>.jsonl" }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
payload = _load_json(SOURCES_PATH, {"sources": []})
|
||||||
|
sources: List[Source] = []
|
||||||
|
for item in payload.get("sources", []) if isinstance(payload, dict) else []:
|
||||||
|
if not isinstance(item, dict):
|
||||||
|
continue
|
||||||
|
label = str(item.get("label") or "session")
|
||||||
|
p = item.get("path")
|
||||||
|
if not isinstance(p, str) or not p:
|
||||||
|
continue
|
||||||
|
sources.append(Source(label=label, transcript_path=Path(p)))
|
||||||
|
return sources
|
||||||
|
|
||||||
|
|
||||||
|
def _memory_path_for(dt: datetime) -> Path:
|
||||||
|
tz = _local_tz()
|
||||||
|
local = dt.astimezone(tz)
|
||||||
|
MEMORY_DIR.mkdir(parents=True, exist_ok=True)
|
||||||
|
return MEMORY_DIR / f"{local.date().isoformat()}.md"
|
||||||
|
|
||||||
|
|
||||||
|
def _append_memory(dt: datetime, label: str, role: str, text: str) -> None:
|
||||||
|
if not text.strip():
|
||||||
|
return
|
||||||
|
tz = _local_tz()
|
||||||
|
local = dt.astimezone(tz)
|
||||||
|
mem = _memory_path_for(dt)
|
||||||
|
if not mem.exists():
|
||||||
|
mem.write_text(f"# {local.date().isoformat()}\n\n", encoding="utf-8")
|
||||||
|
|
||||||
|
header = f"## {local.strftime('%H:%M:%S')} - {label} ({role})"
|
||||||
|
body = text.strip()
|
||||||
|
mem.write_text(mem.read_text(encoding="utf-8") + f"{header}\n\n{body}\n\n", encoding="utf-8")
|
||||||
|
|
||||||
|
|
||||||
|
def _iter_new_lines(path: Path, *, start_offset: int) -> Iterable[tuple[int, str]]:
|
||||||
|
with open(path, "rb") as f:
|
||||||
|
f.seek(max(0, int(start_offset)))
|
||||||
|
while True:
|
||||||
|
raw = f.readline()
|
||||||
|
if not raw:
|
||||||
|
break
|
||||||
|
try:
|
||||||
|
line = raw.decode("utf-8", errors="ignore").strip()
|
||||||
|
except Exception:
|
||||||
|
line = ""
|
||||||
|
if not line:
|
||||||
|
continue
|
||||||
|
yield (f.tell(), line)
|
||||||
|
|
||||||
|
|
||||||
|
def run() -> Dict[str, Any]:
|
||||||
|
sources = _load_sources()
|
||||||
|
state = _load_json(STATE_PATH, {"offsets": {}})
|
||||||
|
offsets: Dict[str, int] = state.get("offsets", {}) if isinstance(state, dict) else {}
|
||||||
|
|
||||||
|
out = {
|
||||||
|
"success": True,
|
||||||
|
"time": datetime.now(timezone.utc).isoformat(),
|
||||||
|
"sources": len(sources),
|
||||||
|
"messages_appended": 0,
|
||||||
|
"errors": [],
|
||||||
|
}
|
||||||
|
|
||||||
|
for src in sources:
|
||||||
|
try:
|
||||||
|
if not src.transcript_path.exists():
|
||||||
|
continue
|
||||||
|
key = str(src.transcript_path)
|
||||||
|
start = int(offsets.get(key, 0))
|
||||||
|
for new_off, line in _iter_new_lines(src.transcript_path, start_offset=start):
|
||||||
|
try:
|
||||||
|
obj = json.loads(line)
|
||||||
|
except Exception:
|
||||||
|
offsets[key] = new_off
|
||||||
|
continue
|
||||||
|
|
||||||
|
if not isinstance(obj, dict) or obj.get("type") != "message":
|
||||||
|
offsets[key] = new_off
|
||||||
|
continue
|
||||||
|
|
||||||
|
msg = obj.get("message") if isinstance(obj.get("message"), dict) else {}
|
||||||
|
role = str(msg.get("role") or "unknown")
|
||||||
|
content = msg.get("content")
|
||||||
|
text = _extract_text(content)
|
||||||
|
|
||||||
|
dt = None
|
||||||
|
if isinstance(msg.get("timestamp"), (int, float)):
|
||||||
|
dt = _ms_to_dt(int(msg["timestamp"]))
|
||||||
|
elif isinstance(obj.get("timestamp"), str):
|
||||||
|
dt = _iso_to_dt(obj["timestamp"])
|
||||||
|
if dt is None:
|
||||||
|
dt = datetime.now(timezone.utc)
|
||||||
|
|
||||||
|
if len(text.strip()) < 5:
|
||||||
|
offsets[key] = new_off
|
||||||
|
continue
|
||||||
|
|
||||||
|
_append_memory(dt, src.label, role, text)
|
||||||
|
out["messages_appended"] += 1
|
||||||
|
offsets[key] = new_off
|
||||||
|
except Exception as e:
|
||||||
|
out["success"] = False
|
||||||
|
out["errors"].append(f"{src.transcript_path}: {e}")
|
||||||
|
|
||||||
|
_save_json(STATE_PATH, {"offsets": offsets, "updated_at": out["time"]})
|
||||||
|
return out
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
res = run()
|
||||||
|
print(json.dumps(res, ensure_ascii=False, indent=2))
|
||||||
141
cron_tasks/verify_pending_external.py
Executable file
141
cron_tasks/verify_pending_external.py
Executable file
@@ -0,0 +1,141 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
"""
|
||||||
|
Verify pending (unconfirmed) engrams using lightweight external checks.
|
||||||
|
|
||||||
|
Policy (conservative):
|
||||||
|
- `openclaw-memory` is treated as internal ground-truth and is auto-confirmed
|
||||||
|
by the review job (see `cron_tasks/review_brain.py` in the workspace runtime).
|
||||||
|
- For `source=web`, confirm if the grounded URL responds with HTTP 2xx, reject on
|
||||||
|
4xx/5xx, and keep pending on timeouts/unknown.
|
||||||
|
- Reject obvious low-signal placeholders (e.g. session summary stubs).
|
||||||
|
"""
|
||||||
|
|
||||||
|
import json
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
from pathlib import Path
|
||||||
|
from datetime import datetime, timezone
|
||||||
|
from typing import Any, Optional
|
||||||
|
|
||||||
|
|
||||||
|
WORKSPACE = Path(os.environ.get("SECOND_BRAIN_WORKSPACE", "/root/.openclaw/workspace/second-brain"))
|
||||||
|
DB_PATH = Path(os.environ.get("BRAIN_DB", str(WORKSPACE / "data" / "brain.sqlite"))).resolve()
|
||||||
|
|
||||||
|
sys.path.insert(0, str(WORKSPACE))
|
||||||
|
from src.store import EngramStore
|
||||||
|
from src.engram import ReviewEntry
|
||||||
|
|
||||||
|
OUTPUT_FILE = os.environ.get("CRON_OUTPUT_FILE", "/tmp/verify_pending_external.json")
|
||||||
|
|
||||||
|
|
||||||
|
def _now() -> str:
|
||||||
|
return datetime.now(timezone.utc).isoformat()
|
||||||
|
|
||||||
|
|
||||||
|
def _get_url(meta: dict[str, Any]) -> Optional[str]:
|
||||||
|
url = meta.get("url")
|
||||||
|
if isinstance(url, str) and url.startswith(("http://", "https://")):
|
||||||
|
return url
|
||||||
|
grounding = meta.get("grounding")
|
||||||
|
if isinstance(grounding, dict):
|
||||||
|
g_url = grounding.get("url")
|
||||||
|
if isinstance(g_url, str) and g_url.startswith(("http://", "https://")):
|
||||||
|
return g_url
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def _http_status(url: str, timeout_s: float = 6.0) -> Optional[int]:
|
||||||
|
try:
|
||||||
|
import urllib.request
|
||||||
|
|
||||||
|
req = urllib.request.Request(
|
||||||
|
url,
|
||||||
|
method="GET",
|
||||||
|
headers={"User-Agent": "openclaw-secondbrain/verify_pending_external"},
|
||||||
|
)
|
||||||
|
with urllib.request.urlopen(req, timeout=timeout_s) as resp:
|
||||||
|
return int(getattr(resp, "status", 200))
|
||||||
|
except Exception:
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def main() -> int:
|
||||||
|
if not DB_PATH.exists():
|
||||||
|
out = {"success": False, "error": f"db missing: {DB_PATH}", "time": _now()}
|
||||||
|
Path(OUTPUT_FILE).write_text(json.dumps(out, indent=2))
|
||||||
|
print(out["error"])
|
||||||
|
return 1
|
||||||
|
|
||||||
|
store = EngramStore(str(DB_PATH))
|
||||||
|
all_egs = []
|
||||||
|
offset = 0
|
||||||
|
while True:
|
||||||
|
batch = store.get_all(limit=2000, offset=offset)
|
||||||
|
if not batch:
|
||||||
|
break
|
||||||
|
all_egs.extend(batch)
|
||||||
|
offset += len(batch)
|
||||||
|
pending = [
|
||||||
|
eg
|
||||||
|
for eg in all_egs
|
||||||
|
if (not eg.correctness.is_final())
|
||||||
|
]
|
||||||
|
|
||||||
|
confirmed = 0
|
||||||
|
rejected = 0
|
||||||
|
still_pending = 0
|
||||||
|
checked = 0
|
||||||
|
|
||||||
|
for eg in pending:
|
||||||
|
checked += 1
|
||||||
|
src = eg.metadata.get("source")
|
||||||
|
content = (eg.content or "").strip()
|
||||||
|
|
||||||
|
if src == "session" and (
|
||||||
|
content.startswith("Session Summary (sess_") or content.startswith("Please remember ")
|
||||||
|
):
|
||||||
|
eg.correctness.reject("verify-pending", "Auto-reject: session placeholder")
|
||||||
|
store.save(eg)
|
||||||
|
rejected += 1
|
||||||
|
continue
|
||||||
|
|
||||||
|
if src == "web":
|
||||||
|
url = _get_url(eg.metadata)
|
||||||
|
if not url:
|
||||||
|
still_pending += 1
|
||||||
|
continue
|
||||||
|
status = _http_status(url)
|
||||||
|
if status is None:
|
||||||
|
still_pending += 1
|
||||||
|
continue
|
||||||
|
if 200 <= status < 300:
|
||||||
|
eg.correctness.confirm("verify-pending", f"Auto-confirm: web url ok ({status}) {url}")
|
||||||
|
store.save(eg)
|
||||||
|
confirmed += 1
|
||||||
|
else:
|
||||||
|
eg.correctness.reject("verify-pending", f"Auto-reject: web url status={status} {url}")
|
||||||
|
store.save(eg)
|
||||||
|
rejected += 1
|
||||||
|
continue
|
||||||
|
|
||||||
|
still_pending += 1
|
||||||
|
|
||||||
|
out = {
|
||||||
|
"success": True,
|
||||||
|
"time": _now(),
|
||||||
|
"total": len(all_egs),
|
||||||
|
"pending_before": len(pending),
|
||||||
|
"checked": checked,
|
||||||
|
"confirmed": confirmed,
|
||||||
|
"rejected": rejected,
|
||||||
|
"still_pending": still_pending,
|
||||||
|
}
|
||||||
|
Path(OUTPUT_FILE).write_text(json.dumps(out, indent=2))
|
||||||
|
print(
|
||||||
|
f"VERIFY: pending_before={out['pending_before']} confirmed={confirmed} rejected={rejected} still_pending={still_pending}"
|
||||||
|
)
|
||||||
|
return 0
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
raise SystemExit(main())
|
||||||
75
docs/OBSIDIAN.md
Normal file
75
docs/OBSIDIAN.md
Normal file
@@ -0,0 +1,75 @@
|
|||||||
|
# Obsidian Coupling (Second-Brain 2.0)
|
||||||
|
|
||||||
|
This integrates an Obsidian vault with Second-Brain via two cron tasks:
|
||||||
|
|
||||||
|
- `cron_tasks/ingest_obsidian.py` (vault → Second-Brain)
|
||||||
|
- `cron_tasks/export_obsidian.py` (Second-Brain → vault)
|
||||||
|
|
||||||
|
All settings live in `second-brain/data/obsidian_config.json`.
|
||||||
|
|
||||||
|
## 1) Install / Sync the vault to the server
|
||||||
|
|
||||||
|
You need a local folder on the server that contains an Obsidian vault (it must contain a `.obsidian/` directory), e.g.:
|
||||||
|
|
||||||
|
- `/srv/obsidian/MyVault`
|
||||||
|
- `/data/obsidian/MyVault`
|
||||||
|
- `/root/Obsidian/MyVault`
|
||||||
|
|
||||||
|
How you sync it is up to you (Syncthing, rsync, SMB mount, etc.).
|
||||||
|
|
||||||
|
## 2) Set `vault_path` in config (auto or manual)
|
||||||
|
|
||||||
|
### Auto-discover (only writes if unambiguous)
|
||||||
|
|
||||||
|
```bash
|
||||||
|
python3 second-brain/scripts/discover_obsidian_vault.py
|
||||||
|
python3 second-brain/scripts/discover_obsidian_vault.py --write
|
||||||
|
```
|
||||||
|
|
||||||
|
If multiple vaults are detected, it prints them and refuses to write.
|
||||||
|
|
||||||
|
### Manual
|
||||||
|
|
||||||
|
Edit `second-brain/data/obsidian_config.json` and set:
|
||||||
|
|
||||||
|
- `vault_path` to the vault directory (the parent of `.obsidian/`)
|
||||||
|
|
||||||
|
## 3) Enable ingest/export
|
||||||
|
|
||||||
|
In `second-brain/data/obsidian_config.json`:
|
||||||
|
|
||||||
|
- Set `enabled.ingest` to `true` to ingest vault markdown into Second-Brain
|
||||||
|
- Set `enabled.export` to `true` to export Second-Brain engrams into the vault
|
||||||
|
|
||||||
|
## 4) Enable timers (systemd)
|
||||||
|
|
||||||
|
This repo ships unit files in `systemd/`:
|
||||||
|
|
||||||
|
- `systemd/openclaw-secondbrain-ingest-obsidian.service`
|
||||||
|
- `systemd/openclaw-secondbrain-ingest-obsidian.timer`
|
||||||
|
- `systemd/openclaw-secondbrain-export-obsidian.service`
|
||||||
|
- `systemd/openclaw-secondbrain-export-obsidian.timer`
|
||||||
|
|
||||||
|
Install them (copy or symlink) to `/etc/systemd/system/`, then:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo systemctl daemon-reload
|
||||||
|
sudo systemctl enable --now openclaw-secondbrain-ingest-obsidian.timer
|
||||||
|
sudo systemctl enable --now openclaw-secondbrain-export-obsidian.timer
|
||||||
|
```
|
||||||
|
|
||||||
|
## 5) Verify
|
||||||
|
|
||||||
|
Run once manually:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
python3 openclaw_cron_wrapper.py ingest_obsidian
|
||||||
|
python3 openclaw_cron_wrapper.py export_obsidian
|
||||||
|
```
|
||||||
|
|
||||||
|
What to expect:
|
||||||
|
|
||||||
|
- If `vault_path` is missing/invalid, both tasks **skip** safely (no writes to random paths).
|
||||||
|
- Ingest creates/updates `second-brain/data/obsidian_ingest_state.json`.
|
||||||
|
- Export writes markdown files to `<vault_path>/<export.subdir>/` (default: `SecondBrain/`) and tracks state in `second-brain/data/obsidian_export_state.json`.
|
||||||
|
|
||||||
113
docs/RELEASE_CHECKLIST.md
Normal file
113
docs/RELEASE_CHECKLIST.md
Normal file
@@ -0,0 +1,113 @@
|
|||||||
|
# Second-Brain 2.0 — Release Checklist (Grundversion + FastAPI)
|
||||||
|
|
||||||
|
Scope: OpenClaw workspace at `/root/.openclaw/workspace` with `second-brain/` and the shipped `second-brain/systemd/` unit files.
|
||||||
|
|
||||||
|
This checklist is copy/paste friendly. Run as a user with `sudo` (systemd commands need it).
|
||||||
|
|
||||||
|
## 0) Preconditions (one-time per host)
|
||||||
|
|
||||||
|
### Repo + Python sanity
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cd /root/.openclaw/workspace
|
||||||
|
test -d second-brain || { echo "missing: second-brain/"; exit 1; }
|
||||||
|
python3 --version
|
||||||
|
```
|
||||||
|
|
||||||
|
### Ensure systemd units are installed (copy/symlink)
|
||||||
|
|
||||||
|
```bash
|
||||||
|
ls -la /etc/systemd/system/openclaw-secondbrain-*.timer /etc/systemd/system/openclaw-secondbrain-*.service 2>/dev/null || true
|
||||||
|
ls -la /etc/systemd/system/openclaw-memory-archive.* 2>/dev/null || true
|
||||||
|
```
|
||||||
|
|
||||||
|
If missing, install them (symlink is fine; copy is fine too):
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo ln -sf /root/.openclaw/workspace/second-brain/systemd/openclaw-secondbrain-*.service /etc/systemd/system/
|
||||||
|
sudo ln -sf /root/.openclaw/workspace/second-brain/systemd/openclaw-secondbrain-*.timer /etc/systemd/system/
|
||||||
|
sudo ln -sf /root/.openclaw/workspace/second-brain/systemd/openclaw-memory-archive.* /etc/systemd/system/
|
||||||
|
sudo ln -sf /root/.openclaw/workspace/second-brain/systemd/openclaw-secondbrain-dashboard.service /etc/systemd/system/
|
||||||
|
sudo systemctl daemon-reload
|
||||||
|
```
|
||||||
|
|
||||||
|
Optional (verification hardening):
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo ln -sf /root/.openclaw/workspace/second-brain/systemd/openclaw-secondbrain-verify-pending.* /etc/systemd/system/
|
||||||
|
sudo systemctl daemon-reload
|
||||||
|
sudo systemctl enable --now openclaw-secondbrain-verify-pending.timer
|
||||||
|
```
|
||||||
|
|
||||||
|
### Enable timers
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo systemctl enable --now openclaw-secondbrain-backup.timer
|
||||||
|
sudo systemctl enable --now openclaw-secondbrain-ingest-memory.timer
|
||||||
|
sudo systemctl enable --now openclaw-secondbrain-index-vectors.timer
|
||||||
|
sudo systemctl enable --now openclaw-secondbrain-review.timer
|
||||||
|
sudo systemctl enable --now openclaw-secondbrain-heartbeat.timer
|
||||||
|
sudo systemctl enable --now openclaw-secondbrain-proactive-search.timer
|
||||||
|
sudo systemctl enable --now openclaw-memory-archive.timer
|
||||||
|
```
|
||||||
|
|
||||||
|
## 1) Release QA — systemd status + timers
|
||||||
|
|
||||||
|
### Verify timers are active and scheduled
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo systemctl list-timers --all | grep -E 'openclaw-(secondbrain|memory-archive)' || true
|
||||||
|
sudo systemctl --failed --no-pager || true
|
||||||
|
```
|
||||||
|
|
||||||
|
### Verify the oneshot services can run successfully (manual trigger)
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo systemctl start openclaw-secondbrain-ingest-memory.service
|
||||||
|
sudo systemctl start openclaw-secondbrain-index-vectors.service
|
||||||
|
sudo systemctl start openclaw-secondbrain-review.service
|
||||||
|
sudo systemctl start openclaw-secondbrain-backup.service
|
||||||
|
sudo systemctl start openclaw-secondbrain-heartbeat.service
|
||||||
|
sudo systemctl start openclaw-secondbrain-proactive-search.service
|
||||||
|
sudo systemctl start openclaw-memory-archive.service
|
||||||
|
```
|
||||||
|
|
||||||
|
Logs:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
tail -n 200 /root/.openclaw/workspace/cron_wrapper.log
|
||||||
|
sudo journalctl -u openclaw-secondbrain-review.service -n 200 --no-pager
|
||||||
|
```
|
||||||
|
|
||||||
|
## 2) Release QA — data + DB invariants
|
||||||
|
|
||||||
|
```bash
|
||||||
|
ls -la /root/.openclaw/workspace/second-brain/data/brain.sqlite
|
||||||
|
python3 - <<'PY'
|
||||||
|
import sqlite3
|
||||||
|
db="/root/.openclaw/workspace/second-brain/data/brain.sqlite"
|
||||||
|
con=sqlite3.connect(db)
|
||||||
|
cur=con.cursor()
|
||||||
|
print("integrity_check:", cur.execute("PRAGMA integrity_check").fetchone()[0])
|
||||||
|
print("engrams:", cur.execute("SELECT COUNT(*) FROM engrams").fetchone()[0])
|
||||||
|
con.close()
|
||||||
|
PY
|
||||||
|
```
|
||||||
|
|
||||||
|
## 3) Release QA — FastAPI (HTTP endpoints + logs)
|
||||||
|
|
||||||
|
FastAPI service:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo systemctl enable --now openclaw-secondbrain-dashboard.service
|
||||||
|
sudo systemctl status openclaw-secondbrain-dashboard.service --no-pager
|
||||||
|
```
|
||||||
|
|
||||||
|
Endpoint checks:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -fsS http://127.0.0.1:8501/healthz && echo
|
||||||
|
curl -fsS http://127.0.0.1:8501/api/config
|
||||||
|
curl -fsS http://127.0.0.1:8501/api/stats
|
||||||
|
curl -fsS "http://127.0.0.1:8501/api/engrams?limit=1&offset=0"
|
||||||
|
```
|
||||||
215
docs/dashboard-ui-ux-design.md
Normal file
215
docs/dashboard-ui-ux-design.md
Normal file
@@ -0,0 +1,215 @@
|
|||||||
|
# Second-Brain Dashboard UI/UX Design Plan (mobile-first)
|
||||||
|
|
||||||
|
Basis: `second-brain/templates/dashboard.html`, `second-brain/static/style.css` (aktueller Stand) + neue Graph-Controls aus `/tmp/second-brain-staging/`.
|
||||||
|
|
||||||
|
## 1) Konkreter Design-Plan
|
||||||
|
|
||||||
|
### Ziele (UX)
|
||||||
|
- **Schnelles Triaging unterwegs:** Pending/Errors sofort sichtbar, 1-Hand-Bedienung.
|
||||||
|
- **Konsistentes Design-System:** einheitliche Buttons/Inputs/Panels statt Einzellösungen.
|
||||||
|
- **Graph als Diagnose-Tool:** klare Controls, Legende, nachvollziehbares Feedback (Loading/Empty/Errors).
|
||||||
|
|
||||||
|
### Farbschema (Dark, high-contrast, "indigo + emerald")
|
||||||
|
- **Background:** sehr dunkel (nahe #0f1117) für weniger Blendung.
|
||||||
|
- **Surface (Cards/Panels):** abgestufte Flächen (Surface-1, Surface-2) für Hierarchie.
|
||||||
|
- **Primary:** Indigo/Blue für interaktive Elemente und Highlights (bisher #6c8af5 bleibt als Basis).
|
||||||
|
- **Success:** Emerald für Confirm/OK (bisher #3a7d3a → etwas heller/satter).
|
||||||
|
- **Danger:** Red für Errors/Reject.
|
||||||
|
- **Warning:** Amber für Pending/Match/Attention.
|
||||||
|
- **Text:** fast-weiß, sekundär gedimmt.
|
||||||
|
|
||||||
|
### Typografie
|
||||||
|
- Systemfont-Stack (schnell, gut lesbar): `ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Arial`.
|
||||||
|
- Skala (mobile-first):
|
||||||
|
- `text-xs` 12px (Labels, Meta)
|
||||||
|
- `text-sm` 13–14px (secondary)
|
||||||
|
- `text-md` 15–16px (Body)
|
||||||
|
- `text-lg` 18–20px (Titles)
|
||||||
|
- **Ziffern:** optional `font-variant-numeric: tabular-nums;` für Stats.
|
||||||
|
|
||||||
|
### Spacing/Rhythm
|
||||||
|
- 4px Grid; Standard-Gaps: 8/12/16.
|
||||||
|
- Container-Padding: 12px (mobile), 16–20px (>=768px).
|
||||||
|
- Border-radius: 12–16px (Cards/Modals), 10px (Inputs/Buttons), 999px (Pills).
|
||||||
|
|
||||||
|
### Komponenten (konkret)
|
||||||
|
|
||||||
|
#### A) Tabs
|
||||||
|
- Tabs bleiben als 3 Buttons, aber:
|
||||||
|
- **Active State** deutlicher (background + border + subtle glow).
|
||||||
|
- **Touch target** min. 44px Höhe.
|
||||||
|
- Sticky bleibt, aber mit leichter **Backdrop-Blurring** (wenn möglich) oder solid surface.
|
||||||
|
|
||||||
|
#### B) Search
|
||||||
|
- Search-Row wird als **kompakte Toolbar** gestaltet:
|
||||||
|
- Input + Filter in einer Zeile.
|
||||||
|
- Optional Quick-Chips darunter: `All / Pending / Confirmed / Errors` (klickbar) als Alternative zum Select.
|
||||||
|
- Clear-Button (×) im Input (per CSS `::-webkit-search-cancel-button` oder eigener Button) für Mobile.
|
||||||
|
|
||||||
|
#### C) Cards
|
||||||
|
- Karte als 3 Zonen: Header (badges/tags/date), Body (content), Footer (actions).
|
||||||
|
- Status wird stärker codiert:
|
||||||
|
- left-border + kleine **Status-Pill** (OK/Pending/Error) mit eindeutiger Farbe.
|
||||||
|
- Body: bessere Lesbarkeit via `line-height: 1.55` und max-height/clamp optional.
|
||||||
|
|
||||||
|
#### D) Modal
|
||||||
|
- Modal als **Bottom Sheet** auf Mobile (>=50vh) + klassisches Center-Modal auf Desktop.
|
||||||
|
- Close-Button größer + Tap-Area.
|
||||||
|
- Inhalt in Tabs/Sections (History/Meta/Content) optional später.
|
||||||
|
|
||||||
|
#### E) Graph + Controls (aus Staging)
|
||||||
|
- Controls als **Control Bar** oberhalb Canvas:
|
||||||
|
- Primary: Physics toggle.
|
||||||
|
- Secondary: Fit, Reset, Reload.
|
||||||
|
- Text labels kurz (z.B. `Physics` statt `Physics: off`, state als Badge).
|
||||||
|
- Canvas passt sich an Viewport an:
|
||||||
|
- `width: min(100%, 560px)`; Height: `min(65vh, 560px)` (CSS statt fester HTML Attribute, wenn möglich).
|
||||||
|
- Legende als einklappbares Panel (`Details`/`summary`) oder leichtes Panel unter Canvas.
|
||||||
|
|
||||||
|
#### F) Status Panels
|
||||||
|
- Status-View nutzt vorhandene `.panel`/`.kv-*`:
|
||||||
|
- Gruppen: System, Storage, Jobs, Insights, Pending Queue.
|
||||||
|
- Jede Gruppe als Panel mit klarer Title Row.
|
||||||
|
- Kritische Werte (Errors/Pending/Queue) farblich markieren.
|
||||||
|
|
||||||
|
## 2) CSS-Variablen (Theme-Tokens) + Mapping
|
||||||
|
|
||||||
|
### Token-Vorschlag (`:root`)
|
||||||
|
```css
|
||||||
|
:root {
|
||||||
|
/* typography */
|
||||||
|
--font-sans: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
|
||||||
|
|
||||||
|
/* colors */
|
||||||
|
--bg: #0f1117;
|
||||||
|
--surface-1: #14151d;
|
||||||
|
--surface-2: #1a1b26;
|
||||||
|
--border: #2a2d3a;
|
||||||
|
|
||||||
|
--text: #e8e8ee;
|
||||||
|
--text-muted: #8b90a3;
|
||||||
|
--text-dim: #5c6276;
|
||||||
|
|
||||||
|
--primary: #6c8af5; /* existing */
|
||||||
|
--primary-2: #8aa1ff;
|
||||||
|
--success: #2fbf71;
|
||||||
|
--danger: #ef4444;
|
||||||
|
--warning: #f7d154; /* existing-ish */
|
||||||
|
|
||||||
|
/* shadows */
|
||||||
|
--shadow-1: 0 1px 0 rgba(0,0,0,.25), 0 8px 24px rgba(0,0,0,.35);
|
||||||
|
|
||||||
|
/* radius */
|
||||||
|
--r-sm: 10px;
|
||||||
|
--r-md: 14px;
|
||||||
|
--r-lg: 16px;
|
||||||
|
|
||||||
|
/* spacing */
|
||||||
|
--s-1: 4px;
|
||||||
|
--s-2: 8px;
|
||||||
|
--s-3: 12px;
|
||||||
|
--s-4: 16px;
|
||||||
|
--s-5: 20px;
|
||||||
|
|
||||||
|
/* control sizes */
|
||||||
|
--tap: 44px;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Mapping auf existierende Selektoren
|
||||||
|
- `body`/`.app`
|
||||||
|
- `background: var(--bg)` statt `#141419`
|
||||||
|
- `font-family: var(--font-sans)`
|
||||||
|
- `color: var(--text)`
|
||||||
|
- `.stats-bar`, `.tabs-bar`, `.search-box`
|
||||||
|
- `background: var(--surface-1)` (Stats ggf. Gradient bleibt, aber auf Tokens)
|
||||||
|
- `border-bottom: 1px solid var(--border)`
|
||||||
|
- `.panel`, `.card`, `.modal-content`, `.graph-legend`
|
||||||
|
- `background: var(--surface-2)`
|
||||||
|
- `border: 1px solid var(--border)`
|
||||||
|
- `border-radius: var(--r-md)`
|
||||||
|
- `.stat-num`, `#pageNum`, `.tab-btn.active`, `#searchInput:focus`
|
||||||
|
- `color/border-color: var(--primary)`
|
||||||
|
- `.muted`, `.stat-label`, `.kv-key`, `.date`
|
||||||
|
- `color: var(--text-muted)` bzw. `var(--text-dim)`
|
||||||
|
- Buttons
|
||||||
|
- vereinheitlichen über `.btn` + Modifier: `.btn.primary`, `.btn.danger`, `.btn.success`, `.btn.ghost`
|
||||||
|
- `min-height: var(--tap)` für Touch
|
||||||
|
|
||||||
|
## 3) 5–10 priorisierte UI-Änderungen (mit Begründung)
|
||||||
|
|
||||||
|
1) **Design Tokens (CSS vars) einführen** → reduziert Farbmix, erleichtert spätere Themes/Anpassungen.
|
||||||
|
2) **Einheitliche Button-Komponente (`.btn`)** (inkl. `:active`, `:disabled`, `min-height`) → bessere Touch-UX, konsistente Interaktion.
|
||||||
|
3) **Graph-Controls + Legende aus Staging in den Main-Template-Stand ziehen** → Graph wird tatsächlich bedienbar/selbsterklärend.
|
||||||
|
4) **Responsive Graph-Canvas (CSS gesteuert)** statt fixer `width/height` → bessere Nutzung auf Phones, weniger Scroll.
|
||||||
|
5) **Search als Toolbar + Clear-Action** → schnelleres Filtern unterwegs, weniger Friktion.
|
||||||
|
6) **Modal als Bottom-Sheet auf Mobile** → angenehmer für längeren Content + History, weniger „winziges Fenster“.
|
||||||
|
7) **Status/Health Werte farblich akzentuieren** (pending/errors/warn) → schnelleres Erkennen von Problemen.
|
||||||
|
8) **Cards: Status-Pill + typografische Lesbarkeit** (line-height, spacing) → weniger „Textblock“, bessere Scanbarkeit.
|
||||||
|
9) **Accessibility-Basics**: Focus-Rings, Kontrast, `prefers-reduced-motion` → weniger „invisible focus“ und bessere Bedienbarkeit.
|
||||||
|
10) **Top-level Layout Max-Width für Desktop** (z.B. 560–720px) → verhindert „zu breite“ Zeilen.
|
||||||
|
|
||||||
|
## 4) Optionale Patch-Vorschläge (Diff-Snippets, NICHT anwenden)
|
||||||
|
|
||||||
|
> Hinweis: Snippets sind bewusst klein gehalten. Gesamt < 120 Zeilen.
|
||||||
|
|
||||||
|
### Snippet A — Tokens + Button-System (style.css)
|
||||||
|
```diff
|
||||||
|
--- a/second-brain/static/style.css
|
||||||
|
+++ b/second-brain/static/style.css
|
||||||
|
@@
|
||||||
|
+:root {
|
||||||
|
+ --font-sans: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
|
||||||
|
+ --bg:#0f1117; --surface-1:#14151d; --surface-2:#1a1b26; --border:#2a2d3a;
|
||||||
|
+ --text:#e8e8ee; --text-muted:#8b90a3; --text-dim:#5c6276;
|
||||||
|
+ --primary:#6c8af5; --success:#2fbf71; --danger:#ef4444; --warning:#f7d154;
|
||||||
|
+ --r-sm:10px; --r-md:14px; --r-lg:16px;
|
||||||
|
+ --s-2:8px; --s-3:12px; --s-4:16px;
|
||||||
|
+ --tap:44px;
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
+body { font-family: var(--font-sans); background: var(--bg); color: var(--text); }
|
||||||
|
+
|
||||||
|
+.btn{
|
||||||
|
+ min-height: var(--tap);
|
||||||
|
+ background: #1e1e28;
|
||||||
|
+ border: 1px solid var(--border);
|
||||||
|
+ border-radius: var(--r-sm);
|
||||||
|
+ padding: 8px 12px;
|
||||||
|
+ color: #cfd3ff;
|
||||||
|
+ font-weight: 700;
|
||||||
|
+}
|
||||||
|
+.btn.primary{ border-color: var(--primary); box-shadow: 0 0 0 1px rgba(108,138,245,0.18) inset; }
|
||||||
|
+.btn.success{ background: rgba(47,191,113,.18); border-color: rgba(47,191,113,.35); }
|
||||||
|
+.btn.danger{ background: rgba(239,68,68,.16); border-color: rgba(239,68,68,.35); }
|
||||||
|
+.btn:active{ transform: scale(.98); }
|
||||||
|
+.btn:disabled{ opacity: .45; }
|
||||||
|
```
|
||||||
|
|
||||||
|
### Snippet B — Graph Controls + Legend übernehmen (dashboard.html)
|
||||||
|
```diff
|
||||||
|
--- a/second-brain/templates/dashboard.html
|
||||||
|
+++ b/second-brain/templates/dashboard.html
|
||||||
|
@@
|
||||||
|
- <div class="graph" id="graph" style="display:none;">
|
||||||
|
- <canvas id="graphCanvas" width="440" height="520"></canvas>
|
||||||
|
- <div class="muted small" id="graphHint">Lade Graph…</div>
|
||||||
|
- </div>
|
||||||
|
+ <div class="graph" id="graph" style="display:none;">
|
||||||
|
+ <div class="graph-controls">
|
||||||
|
+ <button class="btn primary" id="btnGraphPhysics" onclick="toggleGraphPhysics()">Physics</button>
|
||||||
|
+ <button class="btn" onclick="resetGraphView()">Reset</button>
|
||||||
|
+ <button class="btn" onclick="fitGraphView()">Fit</button>
|
||||||
|
+ <button class="btn" onclick="reloadGraph()">Reload</button>
|
||||||
|
+ </div>
|
||||||
|
+ <canvas id="graphCanvas" width="440" height="520"></canvas>
|
||||||
|
+ <div class="graph-hint muted small" id="graphHint">Lade Graph…</div>
|
||||||
|
+ <div class="graph-legend">
|
||||||
|
+ <div><strong>Graph</strong>: Zoom (Wheel/Pinch), Pan (Drag). Klick auf Engram öffnet Details, Klick auf Tag setzt Suche.</div>
|
||||||
|
+ <div class="legend-row"><span class="legend-dot engram"></span> Engram</div>
|
||||||
|
+ <div class="legend-row"><span class="legend-dot tag"></span> Tag</div>
|
||||||
|
+ <div class="legend-row"><span class="legend-dot match"></span> Match</div>
|
||||||
|
+ </div>
|
||||||
|
+ </div>
|
||||||
|
```
|
||||||
|
|
||||||
1025
fastapi_app.py
Normal file
1025
fastapi_app.py
Normal file
File diff suppressed because it is too large
Load Diff
102
openclaw_cron_wrapper.py
Normal file
102
openclaw_cron_wrapper.py
Normal file
@@ -0,0 +1,102 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
"""
|
||||||
|
OpenClaw Cron Isolation Wrapper - Updatesicherer Workaround.
|
||||||
|
Persistent: Tasks und Logs liegen im Workspace, nicht in /tmp.
|
||||||
|
"""
|
||||||
|
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
import json
|
||||||
|
import subprocess
|
||||||
|
import tempfile
|
||||||
|
from pathlib import Path
|
||||||
|
from datetime import datetime, timezone
|
||||||
|
|
||||||
|
# --- Konfiguration (persistent) ---
|
||||||
|
WORKSPACE = Path("/root/.openclaw/workspace")
|
||||||
|
CRON_TASKS_DIR = WORKSPACE / "cron_tasks"
|
||||||
|
LOG_FILE = WORKSPACE / "cron_wrapper.log"
|
||||||
|
BRAIN_DIR = WORKSPACE / "second-brain"
|
||||||
|
|
||||||
|
|
||||||
|
def log(msg: str):
|
||||||
|
ts = datetime.now(timezone.utc).strftime("%Y-%m-%d %H:%M:%S")
|
||||||
|
line = f"[{ts}] {msg}\n"
|
||||||
|
with open(LOG_FILE, "a") as f:
|
||||||
|
f.write(line)
|
||||||
|
print(line.strip())
|
||||||
|
|
||||||
|
|
||||||
|
def run_isolated(task_name: str, task_args: dict = None) -> dict:
|
||||||
|
"""
|
||||||
|
Führt einen Task in echt isolierter Umgebung aus.
|
||||||
|
Kein Zugriff auf Session-Files, nur stdout/stderr.
|
||||||
|
"""
|
||||||
|
CRON_TASKS_DIR.mkdir(parents=True, exist_ok=True)
|
||||||
|
task_script = CRON_TASKS_DIR / f"{task_name}.py"
|
||||||
|
if not task_script.exists():
|
||||||
|
return {"success": False, "error": f"Task nicht gefunden: {task_script}"}
|
||||||
|
|
||||||
|
# Temp-Verzeichnis für Output (flüchtig ist OK, Ergebnis kommt via stdout)
|
||||||
|
temp_dir = tempfile.mkdtemp(prefix=f"cron_{task_name}_")
|
||||||
|
output_file = Path(temp_dir) / "output.json"
|
||||||
|
|
||||||
|
# Saubere Env: Keine OpenClaw-Session-Variablen
|
||||||
|
env = os.environ.copy()
|
||||||
|
for key in list(env.keys()):
|
||||||
|
if "OPENCLAW" in key.upper() or "SESSION" in key.upper():
|
||||||
|
del env[key]
|
||||||
|
|
||||||
|
env["CRON_TASK_NAME"] = task_name
|
||||||
|
env["CRON_OUTPUT_FILE"] = str(output_file)
|
||||||
|
env["BRAIN_DB"] = str(BRAIN_DIR / "data" / "brain.sqlite")
|
||||||
|
|
||||||
|
try:
|
||||||
|
result = subprocess.run(
|
||||||
|
[sys.executable, str(task_script)] + ([json.dumps(task_args)] if task_args else []),
|
||||||
|
capture_output=True,
|
||||||
|
text=True,
|
||||||
|
timeout=300,
|
||||||
|
cwd=str(temp_dir),
|
||||||
|
env=env,
|
||||||
|
)
|
||||||
|
|
||||||
|
stdout = result.stdout.strip()
|
||||||
|
stderr = result.stderr.strip()
|
||||||
|
|
||||||
|
output_data = {}
|
||||||
|
if output_file.exists():
|
||||||
|
try:
|
||||||
|
output_data = json.loads(output_file.read_text())
|
||||||
|
except Exception:
|
||||||
|
output_data = {"raw": output_file.read_text()}
|
||||||
|
|
||||||
|
return {
|
||||||
|
"success": result.returncode == 0,
|
||||||
|
"returncode": result.returncode,
|
||||||
|
"stdout": stdout[-2000:] if stdout else "",
|
||||||
|
"stderr": stderr[-1000:] if stderr else "",
|
||||||
|
"output": output_data,
|
||||||
|
}
|
||||||
|
except subprocess.TimeoutExpired:
|
||||||
|
return {"success": False, "error": "Timeout nach 300s"}
|
||||||
|
except Exception as e:
|
||||||
|
return {"success": False, "error": str(e)}
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
import argparse
|
||||||
|
parser = argparse.ArgumentParser(description="OpenClaw Cron Isolation Wrapper")
|
||||||
|
parser.add_argument("task", help="Task-Name aus cron_tasks/")
|
||||||
|
parser.add_argument("--args", help="JSON-Args für den Task")
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
task_args = json.loads(args.args) if args.args else None
|
||||||
|
result = run_isolated(args.task, task_args)
|
||||||
|
|
||||||
|
print(json.dumps(result, indent=2, default=str))
|
||||||
|
return 0 if result["success"] else 1
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
sys.exit(main())
|
||||||
4696
reports/pending_engrams_20260529_213522.txt
Normal file
4696
reports/pending_engrams_20260529_213522.txt
Normal file
File diff suppressed because it is too large
Load Diff
4
requirements-dashboard.txt
Normal file
4
requirements-dashboard.txt
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
fastapi>=0.110
|
||||||
|
uvicorn[standard]>=0.23
|
||||||
|
jinja2>=3.1
|
||||||
|
python-multipart>=0.0.9
|
||||||
159
scripts/discover_obsidian_vault.py
Normal file
159
scripts/discover_obsidian_vault.py
Normal file
@@ -0,0 +1,159 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
"""
|
||||||
|
Auto-discover an Obsidian vault on this server and (optionally) write it into:
|
||||||
|
second-brain/data/obsidian_config.json
|
||||||
|
|
||||||
|
Safety:
|
||||||
|
- Only writes when exactly one vault is detected (unambiguous).
|
||||||
|
- A "vault" is a directory that contains a `.obsidian/` folder.
|
||||||
|
"""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import argparse
|
||||||
|
import json
|
||||||
|
import os
|
||||||
|
from pathlib import Path
|
||||||
|
from typing import Iterable
|
||||||
|
|
||||||
|
|
||||||
|
WORKSPACE = Path("/root/.openclaw/workspace")
|
||||||
|
BRAIN_DIR = WORKSPACE / "second-brain"
|
||||||
|
CONFIG_PATH = BRAIN_DIR / "data" / "obsidian_config.json"
|
||||||
|
|
||||||
|
|
||||||
|
def _iter_common_candidates() -> Iterable[Path]:
|
||||||
|
env = os.environ.get("OBSIDIAN_VAULT_PATH")
|
||||||
|
if env:
|
||||||
|
yield Path(env).expanduser()
|
||||||
|
|
||||||
|
home = Path.home()
|
||||||
|
for p in [
|
||||||
|
home / "Obsidian",
|
||||||
|
home / "ObsidianVault",
|
||||||
|
home / "Vault",
|
||||||
|
home / "Vaults",
|
||||||
|
home / "Documents" / "Obsidian",
|
||||||
|
home / "Documents" / "Vaults",
|
||||||
|
home / "Syncthing" / "Obsidian",
|
||||||
|
Path("/srv/obsidian"),
|
||||||
|
Path("/srv/Obsidian"),
|
||||||
|
Path("/data/obsidian"),
|
||||||
|
Path("/data/Obsidian"),
|
||||||
|
WORKSPACE / "obsidian",
|
||||||
|
WORKSPACE / "vault",
|
||||||
|
WORKSPACE / "vaults",
|
||||||
|
]:
|
||||||
|
yield p
|
||||||
|
|
||||||
|
|
||||||
|
def _is_vault_dir(p: Path) -> bool:
|
||||||
|
try:
|
||||||
|
return p.exists() and p.is_dir() and (p / ".obsidian").exists() and (p / ".obsidian").is_dir()
|
||||||
|
except Exception:
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def _bounded_find_obsidian_dirs(root: Path, *, max_depth: int) -> list[Path]:
|
||||||
|
"""
|
||||||
|
Find `.obsidian` directories below root, limited by depth to keep runtime bounded.
|
||||||
|
"""
|
||||||
|
results: list[Path] = []
|
||||||
|
try:
|
||||||
|
root = root.resolve()
|
||||||
|
except Exception:
|
||||||
|
return results
|
||||||
|
|
||||||
|
if not root.exists() or not root.is_dir():
|
||||||
|
return results
|
||||||
|
|
||||||
|
def depth_of(path: Path) -> int:
|
||||||
|
try:
|
||||||
|
return len(path.relative_to(root).parts)
|
||||||
|
except Exception:
|
||||||
|
return 9999
|
||||||
|
|
||||||
|
# Breadth-first-ish scan with pruning
|
||||||
|
queue = [root]
|
||||||
|
while queue:
|
||||||
|
current = queue.pop(0)
|
||||||
|
if depth_of(current) > max_depth:
|
||||||
|
continue
|
||||||
|
try:
|
||||||
|
entries = list(current.iterdir())
|
||||||
|
except Exception:
|
||||||
|
continue
|
||||||
|
|
||||||
|
for e in entries:
|
||||||
|
name = e.name
|
||||||
|
if name in (".git", "node_modules", "__pycache__", ".cache", ".venv", "venv", "tmp", "proc", "sys", "dev"):
|
||||||
|
continue
|
||||||
|
if name.startswith(".") and name not in (".obsidian",):
|
||||||
|
continue
|
||||||
|
if name == ".obsidian" and e.is_dir():
|
||||||
|
results.append(e)
|
||||||
|
continue
|
||||||
|
if e.is_dir() and not e.is_symlink():
|
||||||
|
queue.append(e)
|
||||||
|
|
||||||
|
return results
|
||||||
|
|
||||||
|
|
||||||
|
def discover(*, roots: list[Path], max_depth: int) -> list[Path]:
|
||||||
|
vaults: set[Path] = set()
|
||||||
|
|
||||||
|
for p in _iter_common_candidates():
|
||||||
|
if _is_vault_dir(p):
|
||||||
|
vaults.add(p.resolve())
|
||||||
|
|
||||||
|
for root in roots:
|
||||||
|
for obsidian_dir in _bounded_find_obsidian_dirs(root, max_depth=max_depth):
|
||||||
|
vaults.add(obsidian_dir.parent.resolve())
|
||||||
|
|
||||||
|
return sorted(vaults)
|
||||||
|
|
||||||
|
|
||||||
|
def main() -> int:
|
||||||
|
ap = argparse.ArgumentParser(description="Discover Obsidian vault and optionally write config")
|
||||||
|
ap.add_argument("--write", action="store_true", help="Write detected vault_path into obsidian_config.json")
|
||||||
|
ap.add_argument(
|
||||||
|
"--roots",
|
||||||
|
nargs="*",
|
||||||
|
default=[str(Path.home()), "/srv", "/data", "/mnt", str(WORKSPACE)],
|
||||||
|
help="Roots to scan (bounded). Default: home,/srv,/data,/mnt,workspace",
|
||||||
|
)
|
||||||
|
ap.add_argument("--max-depth", type=int, default=4, help="Max directory depth to scan under each root")
|
||||||
|
args = ap.parse_args()
|
||||||
|
|
||||||
|
roots = [Path(r).expanduser() for r in args.roots]
|
||||||
|
vaults = discover(roots=roots, max_depth=int(args.max_depth))
|
||||||
|
|
||||||
|
if not vaults:
|
||||||
|
print("No Obsidian vault found (no `.obsidian/` directories detected).")
|
||||||
|
return 1
|
||||||
|
|
||||||
|
if len(vaults) > 1:
|
||||||
|
print("Multiple Obsidian vaults found; refusing to write config:")
|
||||||
|
for v in vaults:
|
||||||
|
print(f"- {v}")
|
||||||
|
return 2
|
||||||
|
|
||||||
|
vault = vaults[0]
|
||||||
|
print(f"Detected Obsidian vault: {vault}")
|
||||||
|
|
||||||
|
if not args.write:
|
||||||
|
return 0
|
||||||
|
|
||||||
|
if not CONFIG_PATH.exists():
|
||||||
|
raise SystemExit(f"Missing config file: {CONFIG_PATH}")
|
||||||
|
|
||||||
|
cfg = json.loads(CONFIG_PATH.read_text(encoding="utf-8"))
|
||||||
|
cfg["vault_path"] = str(vault)
|
||||||
|
CONFIG_PATH.write_text(json.dumps(cfg, indent=2, ensure_ascii=False) + "\n", encoding="utf-8")
|
||||||
|
print(f"Wrote vault_path to: {CONFIG_PATH}")
|
||||||
|
return 0
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
raise SystemExit(main())
|
||||||
|
|
||||||
191
scripts/import_web_design_markers.py
Normal file
191
scripts/import_web_design_markers.py
Normal file
@@ -0,0 +1,191 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
import argparse
|
||||||
|
import json
|
||||||
|
import hashlib
|
||||||
|
from datetime import datetime, timezone
|
||||||
|
from pathlib import Path
|
||||||
|
from typing import Any, Dict, Iterable, List, Optional, Tuple
|
||||||
|
|
||||||
|
from src.engram import Engram, Grounding
|
||||||
|
from src.store import EngramStore
|
||||||
|
|
||||||
|
|
||||||
|
def _now_utc_iso() -> str:
|
||||||
|
return datetime.now(timezone.utc).isoformat()
|
||||||
|
|
||||||
|
|
||||||
|
def _hash16(text: str) -> str:
|
||||||
|
return hashlib.sha256(text.encode("utf-8")).hexdigest()[:16]
|
||||||
|
|
||||||
|
|
||||||
|
def _iter_jsonl(path: Path) -> Iterable[Dict[str, Any]]:
|
||||||
|
with path.open("r", encoding="utf-8") as f:
|
||||||
|
for line_no, line in enumerate(f, start=1):
|
||||||
|
line = line.strip()
|
||||||
|
if not line:
|
||||||
|
continue
|
||||||
|
try:
|
||||||
|
obj = json.loads(line)
|
||||||
|
except Exception:
|
||||||
|
raise SystemExit(f"Invalid JSON at {path}:{line_no}")
|
||||||
|
if not isinstance(obj, dict):
|
||||||
|
continue
|
||||||
|
yield obj
|
||||||
|
|
||||||
|
|
||||||
|
def _marker_to_content(marker_obj: Dict[str, Any]) -> Tuple[str, List[Dict[str, Any]]]:
|
||||||
|
marker = str(marker_obj.get("marker", "")).strip()
|
||||||
|
details = str(marker_obj.get("details", "")).strip()
|
||||||
|
checks = marker_obj.get("checks") or []
|
||||||
|
sources = marker_obj.get("sources") or []
|
||||||
|
|
||||||
|
if not marker:
|
||||||
|
raise ValueError("missing marker")
|
||||||
|
|
||||||
|
evidence: List[Dict[str, Any]] = []
|
||||||
|
for src in sources:
|
||||||
|
if not isinstance(src, dict):
|
||||||
|
continue
|
||||||
|
url = (src.get("url") or "").strip()
|
||||||
|
title = (src.get("title") or "").strip()
|
||||||
|
if not url:
|
||||||
|
continue
|
||||||
|
evidence.append({"url": url, "title": title})
|
||||||
|
|
||||||
|
lines: List[str] = []
|
||||||
|
lines.append(f"WEBDEV_MARKER: {marker}")
|
||||||
|
if details:
|
||||||
|
lines.append("")
|
||||||
|
lines.append(f"Details: {details}")
|
||||||
|
if isinstance(checks, list) and checks:
|
||||||
|
lines.append("")
|
||||||
|
lines.append("Checks:")
|
||||||
|
for c in checks[:8]:
|
||||||
|
c = str(c).strip()
|
||||||
|
if c:
|
||||||
|
lines.append(f"- {c}")
|
||||||
|
if evidence:
|
||||||
|
lines.append("")
|
||||||
|
lines.append("Sources:")
|
||||||
|
for ev in evidence[:12]:
|
||||||
|
title = (ev.get("title") or "").strip()
|
||||||
|
url = (ev.get("url") or "").strip()
|
||||||
|
if title:
|
||||||
|
lines.append(f"- {title}: {url}")
|
||||||
|
else:
|
||||||
|
lines.append(f"- {url}")
|
||||||
|
return "\n".join(lines).strip(), evidence
|
||||||
|
|
||||||
|
|
||||||
|
def _tags_for(marker_obj: Dict[str, Any]) -> List[str]:
|
||||||
|
tags = ["web_design", "web_development", "mobile"]
|
||||||
|
area = str(marker_obj.get("area", "")).strip()
|
||||||
|
if area:
|
||||||
|
tags.append(area)
|
||||||
|
return tags
|
||||||
|
|
||||||
|
|
||||||
|
def import_markers(
|
||||||
|
db_path: Path,
|
||||||
|
jsonl_paths: List[Path],
|
||||||
|
source: str,
|
||||||
|
verdict: str,
|
||||||
|
agent_id: str,
|
||||||
|
dry_run: bool,
|
||||||
|
) -> Dict[str, int]:
|
||||||
|
store = EngramStore(str(db_path))
|
||||||
|
|
||||||
|
stats = {"seen": 0, "imported": 0, "skipped_dup": 0, "skipped_invalid": 0}
|
||||||
|
seen_hashes: set[str] = set()
|
||||||
|
|
||||||
|
# Preload existing hashes (fast-ish; avoids duplicate spam).
|
||||||
|
existing_hashes: set[str] = set()
|
||||||
|
try:
|
||||||
|
cur = store._conn.execute("SELECT metadata_json FROM engrams") # noqa: SLF001
|
||||||
|
for row in cur.fetchall():
|
||||||
|
try:
|
||||||
|
meta = json.loads(row["metadata_json"])
|
||||||
|
h = meta.get("hash")
|
||||||
|
if isinstance(h, str) and h:
|
||||||
|
existing_hashes.add(h)
|
||||||
|
except Exception:
|
||||||
|
continue
|
||||||
|
except Exception:
|
||||||
|
# If this fails (schema mismatch), proceed without preload.
|
||||||
|
existing_hashes = set()
|
||||||
|
|
||||||
|
for path in jsonl_paths:
|
||||||
|
for marker_obj in _iter_jsonl(path):
|
||||||
|
if (marker_obj.get("kind") or "") != "web_design_marker":
|
||||||
|
continue
|
||||||
|
stats["seen"] += 1
|
||||||
|
try:
|
||||||
|
content, evidence = _marker_to_content(marker_obj)
|
||||||
|
except Exception:
|
||||||
|
stats["skipped_invalid"] += 1
|
||||||
|
continue
|
||||||
|
|
||||||
|
h = _hash16(content)
|
||||||
|
if h in seen_hashes or h in existing_hashes:
|
||||||
|
stats["skipped_dup"] += 1
|
||||||
|
continue
|
||||||
|
seen_hashes.add(h)
|
||||||
|
|
||||||
|
eg = Engram.create(
|
||||||
|
content=content,
|
||||||
|
source=source,
|
||||||
|
confidence=0.75,
|
||||||
|
tags=_tags_for(marker_obj),
|
||||||
|
session_id=None,
|
||||||
|
agent_id=agent_id or str(marker_obj.get("agent_id") or ""),
|
||||||
|
grounding=Grounding.SOURCED,
|
||||||
|
)
|
||||||
|
# Overwrite hash to exactly match our content representation.
|
||||||
|
eg.metadata["hash"] = h
|
||||||
|
eg.metadata["modified"] = _now_utc_iso()
|
||||||
|
eg.metadata["created"] = marker_obj.get("created_at") or eg.metadata["created"]
|
||||||
|
|
||||||
|
eg.correctness.set_verdict(
|
||||||
|
by=agent_id or "importer",
|
||||||
|
verdict=verdict,
|
||||||
|
note=f"Imported from {path.name}",
|
||||||
|
evidence=evidence,
|
||||||
|
)
|
||||||
|
|
||||||
|
if not dry_run:
|
||||||
|
store.save(eg)
|
||||||
|
stats["imported"] += 1
|
||||||
|
|
||||||
|
return stats
|
||||||
|
|
||||||
|
|
||||||
|
def main() -> None:
|
||||||
|
p = argparse.ArgumentParser(description="Import web_design_marker JSONL files into brain.sqlite")
|
||||||
|
p.add_argument("--db", default="second-brain/data/brain.sqlite", help="Path to brain.sqlite")
|
||||||
|
p.add_argument("--glob", default="/tmp/web_design_markers_*.jsonl", help="Glob for marker JSONL files")
|
||||||
|
p.add_argument("--source", default="web_research", help="Engram source")
|
||||||
|
p.add_argument("--verdict", default="probable_true", help="Correctness verdict")
|
||||||
|
p.add_argument("--agent-id", default="web_research_import", help="Agent id to record")
|
||||||
|
p.add_argument("--dry-run", action="store_true", help="Parse/dedupe but do not write to DB")
|
||||||
|
args = p.parse_args()
|
||||||
|
|
||||||
|
db_path = Path(args.db)
|
||||||
|
jsonl_paths = sorted(Path("/").glob(args.glob.lstrip("/"))) if args.glob.startswith("/") else sorted(Path(".").glob(args.glob))
|
||||||
|
if not jsonl_paths:
|
||||||
|
raise SystemExit(f"No files match glob: {args.glob}")
|
||||||
|
|
||||||
|
stats = import_markers(
|
||||||
|
db_path=db_path,
|
||||||
|
jsonl_paths=jsonl_paths,
|
||||||
|
source=args.source,
|
||||||
|
verdict=args.verdict,
|
||||||
|
agent_id=args.agent_id,
|
||||||
|
dry_run=bool(args.dry_run),
|
||||||
|
)
|
||||||
|
|
||||||
|
print(json.dumps({"db": str(db_path), "files": [str(p) for p in jsonl_paths], "stats": stats}, ensure_ascii=False, indent=2))
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
|
|
||||||
163
scripts/process_pending_engrams.py
Normal file
163
scripts/process_pending_engrams.py
Normal file
@@ -0,0 +1,163 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
"""
|
||||||
|
Process pending second brain engrams.
|
||||||
|
- For unconfirmed, unrejected engrams: evaluate confidence
|
||||||
|
- If confidence > 0.8: confirm
|
||||||
|
- If confidence < 0.3: reject
|
||||||
|
- Otherwise: mark for review (leave as is)
|
||||||
|
- Check for stale topics and archive if needed
|
||||||
|
- Produce summary report
|
||||||
|
"""
|
||||||
|
|
||||||
|
import sys
|
||||||
|
import json
|
||||||
|
from datetime import datetime, timezone
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
# Add src to path and set PYTHONPATH for proper module resolution
|
||||||
|
base_dir = Path(__file__).parent.parent
|
||||||
|
sys.path.insert(0, str(base_dir / "src"))
|
||||||
|
|
||||||
|
# Import using absolute module paths
|
||||||
|
from src.store import EngramStore
|
||||||
|
from src.engram import Engram, Grounding
|
||||||
|
|
||||||
|
DB_PATH = Path(__file__).parent.parent / "data" / "brain.sqlite"
|
||||||
|
|
||||||
|
|
||||||
|
def is_stale(engram: Engram, days_threshold: int = 90) -> bool:
|
||||||
|
"""Check if an engram is stale (old and rarely accessed)."""
|
||||||
|
created = engram.metadata.get("created", "")
|
||||||
|
access_count = engram.metadata.get("access_count", 0)
|
||||||
|
last_accessed = engram.metadata.get("last_accessed", created)
|
||||||
|
|
||||||
|
try:
|
||||||
|
created_dt = datetime.fromisoformat(created.replace("Z", "+00:00"))
|
||||||
|
last_accessed_dt = datetime.fromisoformat(last_accessed.replace("Z", "+00:00"))
|
||||||
|
age_days = (datetime.now(timezone.utc) - created_dt).total_seconds() / 86400
|
||||||
|
days_since_access = (datetime.now(timezone.utc) - last_accessed_dt).total_seconds() / 86400
|
||||||
|
|
||||||
|
# Stale if: old (>90 days) AND rarely accessed (<3 times) AND not accessed recently (>60 days)
|
||||||
|
if age_days > days_threshold and access_count < 3 and days_since_access > 60:
|
||||||
|
return True
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def process_pending_engrams():
|
||||||
|
"""Main processing function."""
|
||||||
|
store = EngramStore(str(DB_PATH))
|
||||||
|
|
||||||
|
# Get all engrams
|
||||||
|
all_engrams = store.get_all(limit=10000)
|
||||||
|
print(f"Total engrams in database: {len(all_engrams)}")
|
||||||
|
|
||||||
|
# Filter pending (unconfirmed and unrejected)
|
||||||
|
# Unconfirmed: not confirmed_true, not confirmed_false
|
||||||
|
pending = []
|
||||||
|
for eg in all_engrams:
|
||||||
|
verdict = eg.correctness.verdict
|
||||||
|
if verdict not in ("confirmed_true", "confirmed_false"):
|
||||||
|
pending.append(eg)
|
||||||
|
|
||||||
|
print(f"Pending engrams (unconfirmed/unrejected): {len(pending)}")
|
||||||
|
|
||||||
|
actions = {
|
||||||
|
"confirmed": 0,
|
||||||
|
"rejected": 0,
|
||||||
|
"left_for_review": 0,
|
||||||
|
"archived_stale": 0,
|
||||||
|
"errors": 0
|
||||||
|
}
|
||||||
|
|
||||||
|
details = []
|
||||||
|
|
||||||
|
for eg in pending:
|
||||||
|
try:
|
||||||
|
confidence = eg.compute_confidence()
|
||||||
|
engram_id = str(eg.id)
|
||||||
|
content_preview = eg.content[:80] + ("..." if len(eg.content) > 80 else "")
|
||||||
|
|
||||||
|
# Check if stale and should be archived
|
||||||
|
if is_stale(eg):
|
||||||
|
# For stale engrams, we'll mark them in metadata for archiving
|
||||||
|
# Instead of deleting, we'll add an "archived" tag and lower their priority
|
||||||
|
tags = eg.metadata.get("tags", [])
|
||||||
|
if "archived" not in tags:
|
||||||
|
tags.append("archived")
|
||||||
|
eg.metadata["tags"] = tags
|
||||||
|
eg.metadata["archived_at"] = datetime.now(timezone.utc).isoformat()
|
||||||
|
store.save(eg)
|
||||||
|
actions["archived_stale"] += 1
|
||||||
|
details.append(f"📦 Archived stale: [{engram_id[:8]}] {content_preview} (conf: {confidence:.2f})")
|
||||||
|
# Even if stale, we still evaluate confidence for reporting
|
||||||
|
# But we don't confirm/reject stale ones automatically unless confidence is extreme
|
||||||
|
# Actually, the task says to check for stale topics and archive if needed. We've done that.
|
||||||
|
# We still need to apply confidence thresholds to non-stale or all pending?
|
||||||
|
# Let's continue to evaluate all pending, including stale, but maybe skip confirm/reject for stale?
|
||||||
|
# The task: "For each pending engram... evaluate... If >0.8 confirm, <0.3 reject, otherwise mark for review"
|
||||||
|
# It doesn't say to skip stale ones. So we'll still apply thresholds.
|
||||||
|
# But we already archived it. We can still confirm/reject it if confidence is extreme.
|
||||||
|
# Let's continue.
|
||||||
|
|
||||||
|
# Apply confidence thresholds
|
||||||
|
if confidence > 0.8:
|
||||||
|
eg.correctness.confirm(by="auto_processor", note=f"Auto-confirmed: confidence {confidence:.2f}")
|
||||||
|
store.save(eg)
|
||||||
|
actions["confirmed"] += 1
|
||||||
|
details.append(f"✅ Confirmed: [{engram_id[:8]}] {content_preview} (conf: {confidence:.2f})")
|
||||||
|
elif confidence < 0.3:
|
||||||
|
eg.correctness.reject(by="auto_processor", note=f"Auto-rejected: confidence {confidence:.2f}")
|
||||||
|
store.save(eg)
|
||||||
|
actions["rejected"] += 1
|
||||||
|
details.append(f"❌ Rejected: [{engram_id[:8]}] {content_preview} (conf: {confidence:.2f})")
|
||||||
|
else:
|
||||||
|
actions["left_for_review"] += 1
|
||||||
|
details.append(f"⏳ Review later: [{engram_id[:8]}] {content_preview} (conf: {confidence:.2f})")
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
actions["errors"] += 1
|
||||||
|
details.append(f"⚠️ Error processing engram: {str(e)}")
|
||||||
|
|
||||||
|
# Generate summary report
|
||||||
|
report_lines = []
|
||||||
|
report_lines.append("=" * 60)
|
||||||
|
report_lines.append("PENDING ENGRAMS PROCESSING REPORT")
|
||||||
|
report_lines.append("=" * 60)
|
||||||
|
report_lines.append(f"Timestamp: {datetime.now(timezone.utc).isoformat()}")
|
||||||
|
report_lines.append(f"Total engrams: {len(all_engrams)}")
|
||||||
|
report_lines.append(f"Pending engrams processed: {len(pending)}")
|
||||||
|
report_lines.append("")
|
||||||
|
report_lines.append("ACTIONS TAKEN:")
|
||||||
|
report_lines.append(f" ✅ Auto-confirmed (confidence > 0.8): {actions['confirmed']}")
|
||||||
|
report_lines.append(f" ❌ Auto-rejected (confidence < 0.3): {actions['rejected']}")
|
||||||
|
report_lines.append(f" ⏳ Left for review (0.3 ≤ confidence ≤ 0.8): {actions['left_for_review']}")
|
||||||
|
report_lines.append(f" 📦 Archived stale topics: {actions['archived_stale']}")
|
||||||
|
report_lines.append(f" ⚠️ Errors: {actions['errors']}")
|
||||||
|
report_lines.append("")
|
||||||
|
report_lines.append("DETAILS:")
|
||||||
|
report_lines.extend(details)
|
||||||
|
report_lines.append("")
|
||||||
|
report_lines.append("=" * 60)
|
||||||
|
|
||||||
|
report = "\n".join(report_lines)
|
||||||
|
|
||||||
|
# Print to stdout
|
||||||
|
print("\n" + report)
|
||||||
|
|
||||||
|
# Save report to file
|
||||||
|
report_dir = Path(__file__).parent.parent / "reports"
|
||||||
|
report_dir.mkdir(parents=True, exist_ok=True)
|
||||||
|
report_file = report_dir / f"pending_engrams_{datetime.now().strftime('%Y%m%d_%H%M%S')}.txt"
|
||||||
|
report_file.write_text(report, encoding="utf-8")
|
||||||
|
print(f"\n📄 Report saved to: {report_file}")
|
||||||
|
|
||||||
|
store.close()
|
||||||
|
return actions
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
result = process_pending_engrams()
|
||||||
|
print("\nProcessing complete.")
|
||||||
20
scripts/smoke_dashboard.sh
Executable file
20
scripts/smoke_dashboard.sh
Executable file
@@ -0,0 +1,20 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
HOST="${SECOND_BRAIN_HOST:-127.0.0.1}"
|
||||||
|
PORT="${SECOND_BRAIN_PORT:-${PORT:-8501}}"
|
||||||
|
BASE_URL="http://${HOST}:${PORT}"
|
||||||
|
|
||||||
|
if command -v systemctl >/dev/null 2>&1; then
|
||||||
|
if ! systemctl is-active --quiet openclaw-secondbrain-dashboard.service; then
|
||||||
|
echo "ERROR: openclaw-secondbrain-dashboard.service is not active" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
curl -fsS "${BASE_URL}/healthz" >/dev/null
|
||||||
|
|
||||||
|
stats_json="$(curl -fsS "${BASE_URL}/api/stats")"
|
||||||
|
python3 -c 'import json,sys; json.load(sys.stdin)' <<<"$stats_json"
|
||||||
|
|
||||||
|
echo "OK: dashboard smoke test passed (${BASE_URL})"
|
||||||
@@ -1,8 +1,14 @@
|
|||||||
"""Second Brain - Gedächtnissystem für OpenClaw."""
|
"""Second Brain - Gedächtnissystem für OpenClaw."""
|
||||||
|
|
||||||
from .engram import Engram, Grounding, Correctness, ReviewEntry
|
try:
|
||||||
from .store import EngramStore
|
from .engram import Engram, Grounding, Correctness, ReviewEntry
|
||||||
from .retriever import Retriever
|
from .store import EngramStore
|
||||||
|
from .retriever import Retriever
|
||||||
|
except ImportError:
|
||||||
|
# Fallback: ChromaDB optional, SQLite-core funktioniert immer
|
||||||
|
from .engram import Engram, Grounding, Correctness, ReviewEntry
|
||||||
|
from .store import EngramStore
|
||||||
|
Retriever = None
|
||||||
|
|
||||||
__version__ = "0.1.0"
|
__version__ = "0.1.0"
|
||||||
__all__ = ["Engram", "Grounding", "Correctness", "ReviewEntry", "EngramStore", "Retriever"]
|
__all__ = ["Engram", "Grounding", "Correctness", "ReviewEntry", "EngramStore", "Retriever"]
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ Seiten: Übersicht, Engramme, Suche, Graph, Heal-Log, Neural Scorer.
|
|||||||
|
|
||||||
import json
|
import json
|
||||||
import sys
|
import sys
|
||||||
|
import os
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
import streamlit as st
|
import streamlit as st
|
||||||
@@ -25,33 +26,22 @@ _DEFAULT_DB = _root / "data" / "brain.sqlite"
|
|||||||
|
|
||||||
|
|
||||||
@st.cache_resource
|
@st.cache_resource
|
||||||
class _LazyDB:
|
def _store():
|
||||||
"""Lazy-Initialisierung damit st.secrets erst bei Bedarf gelesen wird."""
|
return EngramStore(str(_DEFAULT_DB))
|
||||||
_store = None
|
|
||||||
_chroma = None
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def store():
|
|
||||||
if _LazyDB._store is None:
|
|
||||||
db = str(_DEFAULT_DB)
|
|
||||||
try:
|
|
||||||
db = st.secrets.get("db_path", str(_DEFAULT_DB))
|
|
||||||
except Exception:
|
|
||||||
pass
|
|
||||||
_LazyDB._store = EngramStore(db)
|
|
||||||
return _LazyDB._store
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def chroma():
|
|
||||||
if _LazyDB._chroma is None:
|
|
||||||
p = Path(str(_DEFAULT_DB)).parent / "chroma"
|
|
||||||
_LazyDB._chroma = ChromaStore(str(p))
|
|
||||||
return _LazyDB._chroma
|
|
||||||
|
|
||||||
|
|
||||||
@st.cache_resource
|
@st.cache_resource
|
||||||
|
def _chroma():
|
||||||
|
p = Path(str(_DEFAULT_DB)).parent / "chroma"
|
||||||
|
return ChromaStore(str(p))
|
||||||
|
|
||||||
|
|
||||||
|
_retriever_cache = None
|
||||||
def _retriever():
|
def _retriever():
|
||||||
return Retriever(_LazyDB.store(), _LazyDB.chroma())
|
global _retriever_cache
|
||||||
|
if _retriever_cache is None:
|
||||||
|
_retriever_cache = Retriever(_store(), _chroma())
|
||||||
|
return _retriever_cache
|
||||||
|
|
||||||
|
|
||||||
@st.cache_resource
|
@st.cache_resource
|
||||||
@@ -61,18 +51,18 @@ def _scorer():
|
|||||||
|
|
||||||
@st.cache_resource
|
@st.cache_resource
|
||||||
def _healer():
|
def _healer():
|
||||||
return ErrorHealer(_LazyDB.store())
|
return ErrorHealer(_store())
|
||||||
|
|
||||||
|
|
||||||
st.set_page_config(page_title="Second Brain Dashboard", layout="wide")
|
st.set_page_config(page_title="Second Brain Dashboard", layout="wide")
|
||||||
st.title("🧠 2.Brain v0.3.0")
|
st.title("🧠 2.Brain v0.3.1")
|
||||||
|
|
||||||
page = st.sidebar.radio("Seite", ["Übersicht", "Engramme", "Suche", "Graph", "Heal-Log", "Neural Scorer"])
|
page = st.sidebar.radio("Seite", ["Übersicht", "Engramme", "Suche", "Graph", "Heal-Log", "Neural Scorer"])
|
||||||
|
|
||||||
|
|
||||||
if page == "Übersicht":
|
if page == "Übersicht":
|
||||||
store = _LazyDB.store()
|
store = _store()
|
||||||
engrams = store.get_all(limit=1000)
|
engrams = store.get_all(limit=10000)
|
||||||
confirmed = sum(1 for e in engrams if e.correctness.confirmed)
|
confirmed = sum(1 for e in engrams if e.correctness.confirmed)
|
||||||
unconfirmed = len(engrams) - confirmed
|
unconfirmed = len(engrams) - confirmed
|
||||||
avg_conf = sum(e.compute_confidence() for e in engrams) / max(1, len(engrams))
|
avg_conf = sum(e.compute_confidence() for e in engrams) / max(1, len(engrams))
|
||||||
@@ -100,12 +90,12 @@ if page == "Übersicht":
|
|||||||
if st.button("Auto-Fix", key=f"af_{eg.id}"):
|
if st.button("Auto-Fix", key=f"af_{eg.id}"):
|
||||||
eg.auto_fix_grounding()
|
eg.auto_fix_grounding()
|
||||||
store.save(eg)
|
store.save(eg)
|
||||||
st.success("Fixed!")
|
st.experimental_rerun()
|
||||||
|
|
||||||
|
|
||||||
elif page == "Engramme":
|
elif page == "Engramme":
|
||||||
store = _LazyDB.store()
|
store = _store()
|
||||||
st.subheader("Alle Engramme")
|
st.subheader("Alle Engramme (max 1000)")
|
||||||
tag_filter = st.text_input("Filter tags")
|
tag_filter = st.text_input("Filter tags")
|
||||||
source_filter = st.selectbox("Source", ["alle", "user", "agent", "web", "file", "system"])
|
source_filter = st.selectbox("Source", ["alle", "user", "agent", "web", "file", "system"])
|
||||||
for eg in store.get_all(limit=1000):
|
for eg in store.get_all(limit=1000):
|
||||||
@@ -135,34 +125,37 @@ elif page == "Engramme":
|
|||||||
|
|
||||||
elif page == "Suche":
|
elif page == "Suche":
|
||||||
st.subheader("Hybrid Search (Semantic + Keyword)")
|
st.subheader("Hybrid Search (Semantic + Keyword)")
|
||||||
query = st.text_input("Query")
|
query = st.text_input("Query", placeholder="Suchbegriff eingeben...")
|
||||||
mode = st.radio("Modus", ["Hybrid", "Keyword", "Semantic"], horizontal=True)
|
mode = st.radio("Modus", ["Hybrid", "Keyword", "Semantic"], horizontal=True)
|
||||||
if st.button("Suchen") and query:
|
if st.button("Suchen") and query:
|
||||||
ret = _retriever()
|
ret = _retriever()
|
||||||
results = ret.hybrid_retrieve(query, limit=10) if mode == "Hybrid" else \
|
results = ret.hybrid_retrieve(query, limit=10) if mode == "Hybrid" else \
|
||||||
ret.semantic_retrieve(query, limit=10) if mode == "Semantic" else \
|
ret.semantic_retrieve(query, limit=10) if mode == "Semantic" else \
|
||||||
ret.retrieve(query, limit=10)
|
ret.retrieve(query, limit=10)
|
||||||
|
if not results:
|
||||||
|
st.info("Keine Ergebnisse gefunden.")
|
||||||
for r in results:
|
for r in results:
|
||||||
eg = r["engram"]
|
eg = r["engram"]
|
||||||
with st.container():
|
with st.container():
|
||||||
st.markdown(f"**{eg.content[:200]}...**")
|
st.markdown(f"**{eg.content[:200]}...**")
|
||||||
st.write(f"Score: {r['score']:.3f} | Match: {r['match_type']} | Conf: {eg.compute_confidence():.2f}")
|
st.write(f"Score: `{r['score']:.3f}` | Match: `{r['match_type']}` | Conf: `{eg.compute_confidence():.2f}`")
|
||||||
c1, c2 = st.columns(2)
|
c1, c2 = st.columns(2)
|
||||||
if c1.button("✅ Confirm", key=f"sc_{eg.id}"):
|
if c1.button("✅ Confirm", key=f"sc_{eg.id}"):
|
||||||
eg.correctness.confirm("user")
|
eg.correctness.confirm("user")
|
||||||
_LazyDB.store().save(eg)
|
_store().save(eg)
|
||||||
c1.success("Confirmed")
|
st.success("Confirmed")
|
||||||
if c2.button("❌ Reject", key=f"sr_{eg.id}"):
|
if c2.button("❌ Reject", key=f"sr_{eg.id}"):
|
||||||
eg.correctness.reject("user")
|
eg.correctness.reject("user")
|
||||||
_LazyDB.store().save(eg)
|
_store().save(eg)
|
||||||
c2.warning("Rejected")
|
st.warning("Rejected")
|
||||||
|
|
||||||
|
|
||||||
elif page == "Graph":
|
elif page == "Graph":
|
||||||
st.subheader("Graph-Visualisierung")
|
st.subheader("Graph-Visualisierung")
|
||||||
graph_html_path = Path(str(_DEFAULT_DB)).parent / "graph_view.html"
|
graph_html_path = Path(str(_DEFAULT_DB)).parent / "graph_view.html"
|
||||||
if st.button("Graph neu generieren"):
|
if st.button("Graph neu generieren"):
|
||||||
path = generate_graph_html(_LazyDB.store(), str(graph_html_path))
|
with st.spinner("Generiere Graph..."):
|
||||||
|
path = generate_graph_html(_store(), str(graph_html_path))
|
||||||
st.success(f"Graph generiert: {path}")
|
st.success(f"Graph generiert: {path}")
|
||||||
if graph_html_path.exists():
|
if graph_html_path.exists():
|
||||||
with open(graph_html_path, "r", encoding="utf-8") as f:
|
with open(graph_html_path, "r", encoding="utf-8") as f:
|
||||||
@@ -199,7 +192,7 @@ elif page == "Heal-Log":
|
|||||||
elif page == "Neural Scorer":
|
elif page == "Neural Scorer":
|
||||||
st.subheader("Neural Scorer Training")
|
st.subheader("Neural Scorer Training")
|
||||||
scorer = _scorer()
|
scorer = _scorer()
|
||||||
store = _LazyDB.store()
|
store = _store()
|
||||||
engrams = store.get_all(limit=10000)
|
engrams = store.get_all(limit=10000)
|
||||||
labeled = [e for e in engrams if e.correctness.confirmed or e.correctness.rejections > 0]
|
labeled = [e for e in engrams if e.correctness.confirmed or e.correctness.rejections > 0]
|
||||||
st.write(f"Labelled Engramme: **{len(labeled)}**")
|
st.write(f"Labelled Engramme: **{len(labeled)}**")
|
||||||
@@ -207,7 +200,7 @@ elif page == "Neural Scorer":
|
|||||||
if len(labeled) < 2:
|
if len(labeled) < 2:
|
||||||
st.error("Mindestens 2 labelierte Engramme nötig (confirm + reject).")
|
st.error("Mindestens 2 labelierte Engramme nötig (confirm + reject).")
|
||||||
else:
|
else:
|
||||||
with st.spinner("Training..."):
|
with st.spinner("Training läuft..."):
|
||||||
result = scorer.train(labeled, epochs=30)
|
result = scorer.train(labeled, epochs=30)
|
||||||
st.json(result)
|
st.json(result)
|
||||||
st.success("Training abgeschlossen!")
|
st.success("Training abgeschlossen!")
|
||||||
|
|||||||
149
src/dashboard.py
149
src/dashboard.py
@@ -13,12 +13,23 @@ import argparse
|
|||||||
import http.server
|
import http.server
|
||||||
import socketserver
|
import socketserver
|
||||||
import webbrowser
|
import webbrowser
|
||||||
|
import sys
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from uuid import UUID
|
from uuid import UUID
|
||||||
|
|
||||||
from .store import EngramStore
|
# Insert project root so `python3 src/dashboard.py` works without `-m`
|
||||||
from .engram import Engram, Grounding
|
project_root = str(Path(__file__).parent.parent)
|
||||||
from .retriever import Retriever
|
if project_root not in sys.path:
|
||||||
|
sys.path.insert(0, project_root)
|
||||||
|
|
||||||
|
from src.store import EngramStore
|
||||||
|
from src.engram import Engram, Grounding
|
||||||
|
|
||||||
|
# Retriever: optional – im venv verfügbar, sonst Fallback
|
||||||
|
try:
|
||||||
|
from src.retriever import Retriever
|
||||||
|
except ImportError:
|
||||||
|
Retriever = None
|
||||||
|
|
||||||
DB_PATH = Path(__file__).parent.parent / "data" / "brain.sqlite"
|
DB_PATH = Path(__file__).parent.parent / "data" / "brain.sqlite"
|
||||||
HTML_PATH = Path(__file__).parent.parent / "data" / "dashboard.html"
|
HTML_PATH = Path(__file__).parent.parent / "data" / "dashboard.html"
|
||||||
@@ -27,10 +38,30 @@ HTML_PATH = Path(__file__).parent.parent / "data" / "dashboard.html"
|
|||||||
def generate_dashboard() -> str:
|
def generate_dashboard() -> str:
|
||||||
"""Generiert HTML-Dashboard aus aktuellem Brain-Stand."""
|
"""Generiert HTML-Dashboard aus aktuellem Brain-Stand."""
|
||||||
store = EngramStore(str(DB_PATH))
|
store = EngramStore(str(DB_PATH))
|
||||||
ret = Retriever(store)
|
|
||||||
stats = ret.stats()
|
|
||||||
egs = store.get_all(limit=100)
|
egs = store.get_all(limit=100)
|
||||||
|
|
||||||
|
# Stats: mit Retriever (venv) oder manuell berechnen
|
||||||
|
if Retriever:
|
||||||
|
ret = Retriever(store)
|
||||||
|
stats = ret.stats()
|
||||||
|
errors = store.search_tag("error", limit=100)
|
||||||
|
stats["errors"] = len(errors)
|
||||||
|
else:
|
||||||
|
from src.engram import Correctness
|
||||||
|
all_egs = store.get_all(limit=10000)
|
||||||
|
confirmed = sum(1 for e in all_egs if e.correctness.confirmed)
|
||||||
|
errors = store.search_tag("error", limit=100)
|
||||||
|
confidences = [e.compute_confidence() for e in all_egs]
|
||||||
|
stats = {
|
||||||
|
"total_engrams": len(all_egs),
|
||||||
|
"confirmed": confirmed,
|
||||||
|
"unconfirmed": len(all_egs) - confirmed,
|
||||||
|
"sources": {},
|
||||||
|
"db_size_bytes": 0,
|
||||||
|
"avg_confidence": sum(confidences) / len(confidences) if confidences else 0.0,
|
||||||
|
"errors": len(errors),
|
||||||
|
}
|
||||||
|
|
||||||
# Farbe nach Confidence
|
# Farbe nach Confidence
|
||||||
def color(conf):
|
def color(conf):
|
||||||
if conf > 0.7: return "#2ecc71"
|
if conf > 0.7: return "#2ecc71"
|
||||||
@@ -48,95 +79,81 @@ def generate_dashboard() -> str:
|
|||||||
except:
|
except:
|
||||||
return "UNKNOWN"
|
return "UNKNOWN"
|
||||||
|
|
||||||
# Liste der Engramme
|
# Karten-Ansicht für Mobil
|
||||||
rows = []
|
card_rows = []
|
||||||
for eg in egs:
|
for eg in egs:
|
||||||
conf = eg.compute_confidence()
|
conf = eg.compute_confidence()
|
||||||
rows.append(f"""
|
card_rows.append(f"""
|
||||||
<tr>
|
<div class="card">
|
||||||
<td><span style="color:{color(conf)};font-size:1.2em">{marker(conf)}</span></td>
|
<div class="card-header">
|
||||||
<td><code>{str(eg.id)[:8]}</code></td>
|
<span>{marker(conf)} {str(eg.id)[:8]}</span>
|
||||||
<td>{eg.content[:100]}{'...' if len(eg.content) > 100 else ''}</td>
|
<span class="badge" style="background:rgba({int((1-conf)*200+55)},{int(conf*200+55)},100,0.3)">{conf:.2f}</span>
|
||||||
<td><span class="badge">{grounding_name(eg.metadata.get('grounding', 0))}</span></td>
|
</div>
|
||||||
<td><span class="badge">{eg.metadata.get('source', '?')}</span></td>
|
<div class="card-content">{eg.content[:150]}{'...' if len(eg.content) > 150 else ''}</div>
|
||||||
<td>{conf:.2f}</td>
|
<div class="card-meta">
|
||||||
<td>{eg.correctness.confirmations}/{eg.correctness.rejections}</td>
|
<span class="badge">{grounding_name(eg.metadata.get('grounding', 0))}</span>
|
||||||
<td>{eg.metadata.get('access_count', 0)}</td>
|
<span class="badge">{eg.metadata.get('source', '?')}</span>
|
||||||
<td>{', '.join(eg.metadata.get('tags', [])[:3])}</td>
|
<span class="badge">✓{eg.correctness.confirmations}/✗{eg.correctness.rejections}</span>
|
||||||
</tr>
|
{' '.join([f'<span class="badge">{t}</span>' for t in eg.metadata.get('tags', [])[:3]])}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
""")
|
""")
|
||||||
|
|
||||||
html = f"""<!DOCTYPE html>
|
html = f"""<!DOCTYPE html>
|
||||||
<html lang="de">
|
<html lang="de">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
|
||||||
<title>🧠 Second Brain Dashboard</title>
|
<title>🧠 Second Brain</title>
|
||||||
<style>
|
<style>
|
||||||
:root {{ --bg: #1a1a2e; --card: #16213e; --text: #eee; --accent: #0f4c75; }}
|
:root {{ --bg: #1a1a2e; --card: #16213e; --text: #eee; --accent: #0f4c75; }}
|
||||||
body {{ font-family: -apple-system, BlinkMacSystemFont, sans-serif; background: var(--bg); color: var(--text); margin: 0; padding: 20px; }}
|
body {{ font-family: -apple-system, BlinkMacSystemFont, sans-serif; background: var(--bg); color: var(--text); margin: 0; padding: 10px; font-size: 14px; }}
|
||||||
h1 {{ margin: 0 0 10px; font-size: 1.8em; }}
|
h1 {{ margin: 0 0 8px; font-size: 1.3em; text-align: center; }}
|
||||||
.stats {{ display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 15px; margin-bottom: 25px; }}
|
.stats {{ display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin-bottom: 15px; }}
|
||||||
.stat-card {{ background: var(--card); border-radius: 12px; padding: 15px; text-align: center; }}
|
.stat-card {{ background: var(--card); border-radius: 10px; padding: 10px; text-align: center; }}
|
||||||
.stat-card .num {{ font-size: 2em; font-weight: bold; color: #4fc3f7; }}
|
.stat-card .num {{ font-size: 1.5em; font-weight: bold; color: #4fc3f7; }}
|
||||||
.stat-card .lbl {{ font-size: 0.85em; opacity: 0.7; }}
|
.stat-card .lbl {{ font-size: 0.75em; opacity: 0.7; }}
|
||||||
table {{ width: 100%; border-collapse: collapse; background: var(--card); border-radius: 12px; overflow: hidden; }}
|
.search {{ margin-bottom: 10px; }}
|
||||||
th {{ text-align: left; padding: 10px; background: var(--accent); font-size: 0.85em; text-transform: uppercase; }}
|
.search input {{ width: 100%; box-sizing: border-box; padding: 12px; border-radius: 8px; border: 1px solid rgba(255,255,255,0.1); background: var(--card); color: var(--text); font-size: 16px; }}
|
||||||
td {{ padding: 8px 10px; border-bottom: 1px solid rgba(255,255,255,0.05); font-size: 0.9em; vertical-align: top; }}
|
.card {{ background: var(--card); border-radius: 12px; padding: 12px; margin-bottom: 10px; }}
|
||||||
tr:hover td {{ background: rgba(255,255,255,0.03); }}
|
.card-header {{ display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }}
|
||||||
.badge {{ display: inline-block; padding: 2px 8px; border-radius: 12px; background: rgba(79,195,247,0.2); font-size: 0.75em; }}
|
.card-id {{ font-size: 0.75em; opacity: 0.6; }}
|
||||||
.search {{ margin-bottom: 20px; }}
|
.card-content {{ font-size: 0.9em; line-height: 1.4; margin-bottom: 8px; word-break: break-word; }}
|
||||||
.search input {{ width: 100%; max-width: 400px; padding: 10px 15px; border-radius: 8px; border: 1px solid rgba(255,255,255,0.1); background: var(--card); color: var(--text); font-size: 1em; }}
|
.card-meta {{ display: flex; flex-wrap: wrap; gap: 6px; font-size: 0.75em; }}
|
||||||
.refresh {{ position: fixed; top: 20px; right: 20px; background: #2ecc71; color: #000; border: none; padding: 10px 20px; border-radius: 8px; cursor: pointer; font-weight: bold; }}
|
.badge {{ display: inline-block; padding: 3px 8px; border-radius: 12px; background: rgba(79,195,247,0.2); }}
|
||||||
.footer {{ margin-top: 30px; text-align: center; opacity: 0.5; font-size: 0.8em; }}
|
.refresh {{ position: fixed; bottom: 15px; right: 15px; background: #2ecc71; color: #000; border: none; padding: 12px 16px; border-radius: 50%; cursor: pointer; font-weight: bold; font-size: 1.2em; box-shadow: 0 2px 8px rgba(0,0,0,0.4); }}
|
||||||
|
.footer {{ margin-top: 20px; text-align: center; opacity: 0.5; font-size: 0.7em; padding-bottom: 60px; }}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1>🧠 Second Brain Dashboard</h1>
|
<h1>🧠 Second Brain</h1>
|
||||||
<button class="refresh" onclick="location.reload()">🔄 Aktualisieren</button>
|
<button class="refresh" onclick="location.reload()">↻</button>
|
||||||
|
|
||||||
<div class="stats">
|
<div class="stats">
|
||||||
<div class="stat-card"><div class="num">{stats['total_engrams']}</div><div class="lbl">Engramme</div></div>
|
<div class="stat-card"><div class="num">{stats['total_engrams']}</div><div class="lbl">Engramme</div></div>
|
||||||
<div class="stat-card"><div class="num">{stats['confirmed']}</div><div class="lbl">Bestätigt</div></div>
|
<div class="stat-card"><div class="num">{stats['confirmed']}</div><div class="lbl">Bestätigt</div></div>
|
||||||
<div class="stat-card"><div class="num">{stats['unconfirmed']}</div><div class="lbl">Unbestätigt</div></div>
|
<div class="stat-card"><div class="num">{stats['unconfirmed']}</div><div class="lbl">Unbestätigt</div></div>
|
||||||
<div class="stat-card"><div class="num">{len(stats.get('sources', dict()))}</div><div class="lbl">Quellen</div></div>
|
<div class="stat-card"><div class="num">{stats['errors']}</div><div class="lbl">Fehler</div></div>
|
||||||
<div class="stat-card"><div class="num">{stats['db_size_bytes']/1024:.0f}</div><div class="lbl">KB Größe</div></div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="search">
|
<div class="search">
|
||||||
<input type="text" placeholder="🔍 Suche nach Engrammen..." id="searchInput" onkeyup="filterTable()">
|
<input type="text" placeholder="🔍 Suche..." id="searchInput" onkeyup="filterCards()">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<table id="engramTable">
|
<div id="cards">
|
||||||
<thead>
|
{''.join(card_rows)}
|
||||||
<tr>
|
</div>
|
||||||
<th>Status</th>
|
|
||||||
<th>ID</th>
|
|
||||||
<th>Inhalt</th>
|
|
||||||
<th>Grounding</th>
|
|
||||||
<th>Quelle</th>
|
|
||||||
<th>Confidence</th>
|
|
||||||
<th>Feedback</th>
|
|
||||||
<th>Zugriffe</th>
|
|
||||||
<th>Tags</th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
{''.join(rows)}
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
|
|
||||||
<div class="footer">Generated {__import__('datetime').datetime.now().isoformat()}</div>
|
<div class="footer">Generated {__import__('datetime').datetime.now().strftime('%H:%M')}</div>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
function filterTable() {{
|
function filterCards() {{
|
||||||
var input = document.getElementById('searchInput');
|
var input = document.getElementById('searchInput');
|
||||||
var filter = input.value.toLowerCase();
|
var filter = input.value.toLowerCase();
|
||||||
var table = document.getElementById('engramTable');
|
var cards = document.getElementById('cards').getElementsByClassName('card');
|
||||||
var rows = table.getElementsByTagName('tr');
|
for (var i=0; i<cards.length; i++) {{
|
||||||
for (var i=1; i<rows.length; i++) {{
|
var txt = cards[i].textContent || cards[i].innerText;
|
||||||
var txt = rows[i].textContent || rows[i].innerText;
|
cards[i].style.display = txt.toLowerCase().indexOf(filter) > -1 ? '' : 'none';
|
||||||
rows[i].style.display = txt.toLowerCase().indexOf(filter) > -1 ? '' : 'none';
|
|
||||||
}}
|
}}
|
||||||
}}
|
}}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -40,48 +40,110 @@ class ReviewEntry:
|
|||||||
@dataclass
|
@dataclass
|
||||||
class Correctness:
|
class Correctness:
|
||||||
"""Verfolgt die Korrektheit eines Engramms über Zeit."""
|
"""Verfolgt die Korrektheit eines Engramms über Zeit."""
|
||||||
|
# verdict model (not only binary confirm/reject)
|
||||||
|
# Values:
|
||||||
|
# - unknown
|
||||||
|
# - probable_true / probable_false
|
||||||
|
# - confirmed_true / confirmed_false
|
||||||
|
verdict: str = "unknown"
|
||||||
|
evidence: List[Dict[str, Any]] = field(default_factory=list)
|
||||||
confirmed: bool = False
|
confirmed: bool = False
|
||||||
confirmations: int = 0
|
confirmations: int = 0
|
||||||
rejections: int = 0
|
rejections: int = 0
|
||||||
last_reviewed: Optional[str] = None
|
last_reviewed: Optional[str] = None
|
||||||
review_history: List[ReviewEntry] = field(default_factory=list)
|
review_history: List[ReviewEntry] = field(default_factory=list)
|
||||||
|
|
||||||
|
def is_final(self) -> bool:
|
||||||
|
return self.verdict in ("confirmed_true", "confirmed_false")
|
||||||
|
|
||||||
|
def set_verdict(self, by: str, verdict: str, note: str = "", evidence: Optional[List[Dict[str, Any]]] = None) -> None:
|
||||||
|
verdict = (verdict or "").strip()
|
||||||
|
if verdict not in ("unknown", "probable_true", "probable_false", "confirmed_true", "confirmed_false"):
|
||||||
|
verdict = "unknown"
|
||||||
|
self.verdict = verdict
|
||||||
|
# Keep backward-compatible boolean in sync:
|
||||||
|
# historically, confirmed=True meant "this statement is correct".
|
||||||
|
self.confirmed = verdict == "confirmed_true"
|
||||||
|
self.last_reviewed = _now()
|
||||||
|
if evidence:
|
||||||
|
try:
|
||||||
|
self.evidence.extend([e for e in evidence if isinstance(e, dict)])
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
self.review_history.append(ReviewEntry(by, "set_verdict", self.last_reviewed, f"{verdict}: {note}".strip()))
|
||||||
|
|
||||||
def confirm(self, by: str, note: str = "") -> None:
|
def confirm(self, by: str, note: str = "") -> None:
|
||||||
self.confirmations += 1
|
self.confirmations += 1
|
||||||
self.confirmed = True
|
self.set_verdict(by, "confirmed_true", note)
|
||||||
self.last_reviewed = _now()
|
# Preserve historic action tag too
|
||||||
self.review_history.append(ReviewEntry(by, "confirm", self.last_reviewed, note))
|
self.review_history.append(ReviewEntry(by, "confirm", self.last_reviewed, note))
|
||||||
|
|
||||||
def reject(self, by: str, note: str = "") -> None:
|
def reject(self, by: str, note: str = "") -> None:
|
||||||
self.rejections += 1
|
self.rejections += 1
|
||||||
self.confirmed = False
|
self.set_verdict(by, "confirmed_false", note)
|
||||||
self.last_reviewed = _now()
|
|
||||||
self.review_history.append(ReviewEntry(by, "reject", self.last_reviewed, note))
|
self.review_history.append(ReviewEntry(by, "reject", self.last_reviewed, note))
|
||||||
|
|
||||||
def score(self) -> float:
|
def score(self) -> float:
|
||||||
"""Confidence-Score aus Korrekturhistorie."""
|
"""Confidence-Score aus Korrekturhistorie."""
|
||||||
|
# verdict-first scoring (explicit, non-binary)
|
||||||
|
if self.verdict == "confirmed_true":
|
||||||
|
return 1.0
|
||||||
|
if self.verdict == "confirmed_false":
|
||||||
|
return 0.0
|
||||||
|
if self.verdict == "probable_true":
|
||||||
|
return 0.75
|
||||||
|
if self.verdict == "probable_false":
|
||||||
|
return 0.25
|
||||||
total = self.confirmations + self.rejections
|
total = self.confirmations + self.rejections
|
||||||
if total == 0:
|
if total == 0:
|
||||||
return 0.5 # Unbestimmt
|
return 0.5 # Unbestimmt
|
||||||
return self.confirmations / total
|
return self.confirmations / total
|
||||||
|
|
||||||
def to_dict(self) -> dict:
|
def to_dict(self) -> dict:
|
||||||
|
# Backwards/robustness: older code paths may have appended raw dicts.
|
||||||
|
review_history: List[dict] = []
|
||||||
|
for entry in self.review_history:
|
||||||
|
if isinstance(entry, dict):
|
||||||
|
review_history.append(entry)
|
||||||
|
else:
|
||||||
|
review_history.append(entry.to_dict())
|
||||||
return {
|
return {
|
||||||
|
"verdict": self.verdict,
|
||||||
|
"evidence": self.evidence,
|
||||||
"confirmed": self.confirmed,
|
"confirmed": self.confirmed,
|
||||||
"confirmations": self.confirmations,
|
"confirmations": self.confirmations,
|
||||||
"rejections": self.rejections,
|
"rejections": self.rejections,
|
||||||
"last_reviewed": self.last_reviewed,
|
"last_reviewed": self.last_reviewed,
|
||||||
"review_history": [r.to_dict() for r in self.review_history],
|
"review_history": review_history,
|
||||||
}
|
}
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_dict(cls, d: dict) -> "Correctness":
|
def from_dict(cls, d: dict) -> "Correctness":
|
||||||
c = cls()
|
c = cls()
|
||||||
|
verdict = d.get("verdict")
|
||||||
|
if isinstance(verdict, str) and verdict.strip():
|
||||||
|
c.verdict = verdict.strip()
|
||||||
c.confirmed = d.get("confirmed", False)
|
c.confirmed = d.get("confirmed", False)
|
||||||
c.confirmations = d.get("confirmations", 0)
|
c.confirmations = d.get("confirmations", 0)
|
||||||
c.rejections = d.get("rejections", 0)
|
c.rejections = d.get("rejections", 0)
|
||||||
c.last_reviewed = d.get("last_reviewed")
|
c.last_reviewed = d.get("last_reviewed")
|
||||||
|
ev = d.get("evidence", [])
|
||||||
|
if isinstance(ev, list):
|
||||||
|
c.evidence = [e for e in ev if isinstance(e, dict)]
|
||||||
c.review_history = [ReviewEntry.from_dict(r) for r in d.get("review_history", [])]
|
c.review_history = [ReviewEntry.from_dict(r) for r in d.get("review_history", [])]
|
||||||
|
# Backfill verdict if missing/invalid.
|
||||||
|
if c.verdict not in ("unknown", "probable_true", "probable_false", "confirmed_true", "confirmed_false"):
|
||||||
|
if c.confirmed:
|
||||||
|
c.verdict = "confirmed_true"
|
||||||
|
elif c.rejections > 0:
|
||||||
|
c.verdict = "confirmed_false"
|
||||||
|
else:
|
||||||
|
c.verdict = "unknown"
|
||||||
|
# Ensure boolean stays consistent for older mixed data.
|
||||||
|
if c.verdict == "confirmed_true":
|
||||||
|
c.confirmed = True
|
||||||
|
elif c.verdict == "confirmed_false":
|
||||||
|
c.confirmed = False
|
||||||
return c
|
return c
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -134,11 +134,19 @@ def _node_size(access_count: int) -> float:
|
|||||||
|
|
||||||
def generate_graph_html(store: EngramStore, output_path: str) -> str:
|
def generate_graph_html(store: EngramStore, output_path: str) -> str:
|
||||||
"""Generiert interaktive HTML-Graph-Visualisierung."""
|
"""Generiert interaktive HTML-Graph-Visualisierung."""
|
||||||
engrams = store.get_all()
|
# store.get_all() defaults to 1000; paginate so the graph can include all nodes.
|
||||||
|
engrams = []
|
||||||
|
offset = 0
|
||||||
|
while True:
|
||||||
|
batch = store.get_all(limit=2000, offset=offset)
|
||||||
|
if not batch:
|
||||||
|
break
|
||||||
|
engrams.extend(batch)
|
||||||
|
offset += len(batch)
|
||||||
|
|
||||||
nodes = []
|
nodes = []
|
||||||
edges = []
|
edges = []
|
||||||
node_ids = set()
|
node_ids = set(str(e.id) for e in engrams)
|
||||||
|
|
||||||
for eg in engrams:
|
for eg in engrams:
|
||||||
eid = str(eg.id)
|
eid = str(eg.id)
|
||||||
@@ -156,22 +164,19 @@ def generate_graph_html(store: EngramStore, output_path: str) -> str:
|
|||||||
"size": size,
|
"size": size,
|
||||||
"confidence": conf,
|
"confidence": conf,
|
||||||
"confirmed": eg.correctness.confirmed,
|
"confirmed": eg.correctness.confirmed,
|
||||||
|
"verdict": getattr(eg.correctness, "verdict", "unknown"),
|
||||||
"source": eg.metadata.get("source", "?"),
|
"source": eg.metadata.get("source", "?"),
|
||||||
"tags": tags,
|
"tags": tags,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
node_ids.add(eid)
|
|
||||||
|
|
||||||
|
# Add edges after all nodes are known (otherwise early nodes miss links).
|
||||||
|
for eg in engrams:
|
||||||
|
eid = str(eg.id)
|
||||||
for lid in eg.links:
|
for lid in eg.links:
|
||||||
lid_s = str(lid)
|
lid_s = str(lid)
|
||||||
if lid_s in node_ids:
|
if lid_s in node_ids:
|
||||||
edges.append({
|
edges.append({"data": {"id": f"{eid}_{lid_s}", "source": eid, "target": lid_s}})
|
||||||
"data": {
|
|
||||||
"id": f"{eid}_{lid_s}",
|
|
||||||
"source": eid,
|
|
||||||
"target": lid_s,
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
elements = {"nodes": nodes, "edges": edges}
|
elements = {"nodes": nodes, "edges": edges}
|
||||||
html = _HTML_TEMPLATE.format(elements_json=json.dumps(elements, ensure_ascii=False))
|
html = _HTML_TEMPLATE.format(elements_json=json.dumps(elements, ensure_ascii=False))
|
||||||
|
|||||||
@@ -12,19 +12,82 @@ import os
|
|||||||
import sys
|
import sys
|
||||||
import json
|
import json
|
||||||
import traceback
|
import traceback
|
||||||
|
import re
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from datetime import datetime, timezone
|
from datetime import datetime, timezone
|
||||||
from typing import Optional, List, Dict, Any
|
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
|
# Second Brain Import
|
||||||
from .store import EngramStore
|
from src.engram import Engram, Grounding
|
||||||
from .engram import Engram, Grounding
|
from src.store import EngramStore
|
||||||
from .retriever import Retriever
|
|
||||||
|
# Retriever: optional (braucht chromadb)
|
||||||
|
try:
|
||||||
|
from src.retriever import Retriever
|
||||||
|
except ImportError:
|
||||||
|
Retriever = None
|
||||||
|
|
||||||
|
# Chroma: optional (braucht chromadb)
|
||||||
|
try:
|
||||||
|
from src.chroma_store import ChromaStore
|
||||||
|
except Exception:
|
||||||
|
ChromaStore = None
|
||||||
|
|
||||||
|
|
||||||
# --- Konfiguration ---
|
# --- Konfiguration ---
|
||||||
BRAIN_DB = Path(__file__).parent.parent / "data" / "brain.sqlite"
|
BRAIN_DB = Path(__file__).parent.parent / "data" / "brain.sqlite"
|
||||||
|
|
||||||
|
_UUID_RE = re.compile(r"\b[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\b", re.I)
|
||||||
|
_SHORT_ID_RE = re.compile(r"\b[0-9a-f]{8}\b", re.I)
|
||||||
|
|
||||||
|
|
||||||
|
def _detect_feedback(content: str) -> dict | None:
|
||||||
|
"""
|
||||||
|
Heuristik: erkennt kurze Korrektur-/Feedback-Nachrichten in Chats.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
{"kind":"confirm"|"reject"|"stop", "target": <id or short-id or None>, "raw": <normalized>}
|
||||||
|
"""
|
||||||
|
if not isinstance(content, str):
|
||||||
|
return None
|
||||||
|
raw = content.strip()
|
||||||
|
if not raw:
|
||||||
|
return None
|
||||||
|
norm = raw.lower().strip()
|
||||||
|
|
||||||
|
target = None
|
||||||
|
m = _UUID_RE.search(raw)
|
||||||
|
if m:
|
||||||
|
target = m.group(0)
|
||||||
|
else:
|
||||||
|
m2 = _SHORT_ID_RE.search(raw)
|
||||||
|
if m2:
|
||||||
|
target = m2.group(0)
|
||||||
|
|
||||||
|
if norm in {"stop", "stopp", "halt"}:
|
||||||
|
return {"kind": "stop", "target": target, "raw": norm}
|
||||||
|
if norm in {"nein", "no", "falsch", "wrong"}:
|
||||||
|
return {"kind": "reject", "target": target, "raw": norm}
|
||||||
|
if norm in {"ja", "yes", "richtig", "korrekt", "stimmt"}:
|
||||||
|
return {"kind": "confirm", "target": target, "raw": norm}
|
||||||
|
if norm.startswith(("korrigiert", "korrektur", "correction")):
|
||||||
|
if "richtig" in norm or "korrekt" in norm:
|
||||||
|
return {"kind": "confirm", "target": target, "raw": norm}
|
||||||
|
return {"kind": "reject", "target": target, "raw": norm}
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
def get_brain() -> EngramStore:
|
def get_brain() -> EngramStore:
|
||||||
"""Gibt initialisierten Brain-Store."""
|
"""Gibt initialisierten Brain-Store."""
|
||||||
@@ -54,14 +117,43 @@ def save_session_learned(
|
|||||||
)
|
)
|
||||||
"""
|
"""
|
||||||
store = get_brain()
|
store = get_brain()
|
||||||
|
tags = tags or []
|
||||||
|
|
||||||
|
fb = _detect_feedback(content) if source == "session" else None
|
||||||
|
fb_target_id: str | None = None
|
||||||
|
if fb:
|
||||||
|
tags = list(dict.fromkeys(tags + ["feedback", fb["kind"]]))
|
||||||
|
confidence = min(confidence, 0.2)
|
||||||
|
grounding = Grounding.ASSUMPTION
|
||||||
|
if session_id:
|
||||||
|
recent = store.get_latest_by_session_id(session_id, limit=10, exclude_tags=["feedback"])
|
||||||
|
if recent:
|
||||||
|
fb_target_id = str(recent[0].id)
|
||||||
|
|
||||||
eg = Engram.create(
|
eg = Engram.create(
|
||||||
content=content,
|
content=content,
|
||||||
source=source,
|
source=source,
|
||||||
tags=tags or [],
|
tags=tags,
|
||||||
session_id=session_id,
|
session_id=session_id,
|
||||||
confidence=confidence,
|
confidence=confidence,
|
||||||
grounding=grounding,
|
grounding=grounding,
|
||||||
)
|
)
|
||||||
|
if fb and fb_target_id:
|
||||||
|
target = store.get(fb_target_id)
|
||||||
|
if target:
|
||||||
|
try:
|
||||||
|
# Link both ways for graphing/traceability
|
||||||
|
eg.links.append(target.id)
|
||||||
|
if eg.id not in target.links:
|
||||||
|
target.links.append(eg.id)
|
||||||
|
|
||||||
|
# Lock target so auto-review does not keep "re-deciding" after a correction signal.
|
||||||
|
target.metadata["predict_locked"] = True
|
||||||
|
target.metadata["predict_locked_reason"] = f"feedback:{fb['raw']}"
|
||||||
|
target.metadata["predict_locked_at"] = datetime.now(timezone.utc).isoformat()
|
||||||
|
store.save(target)
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
store.save(eg)
|
store.save(eg)
|
||||||
return eg
|
return eg
|
||||||
|
|
||||||
@@ -75,11 +167,6 @@ def heartbeat_check() -> Optional[str]:
|
|||||||
Rückgabe: Nachricht für den User, oder None wenn nichts zu tun.
|
Rückgabe: Nachricht für den User, oder None wenn nichts zu tun.
|
||||||
"""
|
"""
|
||||||
store = get_brain()
|
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
|
# Prüfe auf wichtige unbestätigte Engramme
|
||||||
egs = store.get_all(limit=50)
|
egs = store.get_all(limit=50)
|
||||||
@@ -89,8 +176,7 @@ def heartbeat_check() -> Optional[str]:
|
|||||||
][:5]
|
][:5]
|
||||||
|
|
||||||
if unconfirmed:
|
if unconfirmed:
|
||||||
ids = ", ".join([str(eg.id)[:8] for eg in unconfirmed])
|
contents = "\n".join([f" - {eg.content[:80]}" for eg in unconfirmed])
|
||||||
contents = "\n".join([f" - {eg.content[:80]}" for eg in unconfimed])
|
|
||||||
return (
|
return (
|
||||||
f"🧠 Second Brain Heartbeat\n"
|
f"🧠 Second Brain Heartbeat\n"
|
||||||
f"Unbestätigte Engramme mit gutem Confidence-Score:\n{contents}\n"
|
f"Unbestätigte Engramme mit gutem Confidence-Score:\n{contents}\n"
|
||||||
@@ -195,8 +281,39 @@ def enrich_context(topic: str, limit: int = 3) -> str:
|
|||||||
# memory_context in das Prompt einbauen
|
# memory_context in das Prompt einbauen
|
||||||
"""
|
"""
|
||||||
store = get_brain()
|
store = get_brain()
|
||||||
ret = Retriever(store)
|
|
||||||
results = ret.retrieve(topic, limit=limit, min_confidence=0.3)
|
# Versuche Hybrid-Retrieval (FTS + optional Vector), fallback auf Textsuche
|
||||||
|
if Retriever:
|
||||||
|
chroma = None
|
||||||
|
if ChromaStore:
|
||||||
|
try:
|
||||||
|
chroma = ChromaStore(path=str(Path(__file__).parent.parent / "data" / "chroma"))
|
||||||
|
except Exception:
|
||||||
|
chroma = None
|
||||||
|
ret = Retriever(store, chroma=chroma)
|
||||||
|
try:
|
||||||
|
results = ret.hybrid_retrieve(topic, limit=limit * 3, min_confidence=0.3)
|
||||||
|
except Exception:
|
||||||
|
results = ret.retrieve(topic, limit=limit * 3, min_confidence=0.3)
|
||||||
|
|
||||||
|
# confirmed-first ranking
|
||||||
|
def _rank(r):
|
||||||
|
eg = r["engram"]
|
||||||
|
confirmed = 1 if getattr(eg.correctness, "confirmed", False) else 0
|
||||||
|
return (confirmed, float(r.get("score", 0.0)))
|
||||||
|
|
||||||
|
results.sort(key=_rank, reverse=True)
|
||||||
|
|
||||||
|
# If we have confirmed results, show only confirmed up to limit
|
||||||
|
confirmed_only = [r for r in results if r["engram"].correctness.confirmed]
|
||||||
|
if confirmed_only:
|
||||||
|
results = confirmed_only[:limit]
|
||||||
|
else:
|
||||||
|
results = results[:limit]
|
||||||
|
else:
|
||||||
|
results_raw = store.search_text(topic, limit=limit)
|
||||||
|
results = [{"engram": eg, "score": 0.5} for eg in results_raw]
|
||||||
|
|
||||||
if not results:
|
if not results:
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
|
|||||||
165
src/proactive_search.py
Normal file
165
src/proactive_search.py
Normal file
@@ -0,0 +1,165 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
"""
|
||||||
|
proactive_search.py - Proaktive Websuche für Second Brain.
|
||||||
|
Sucht relevante Themen, speichert Ergebnisse als Engramme.
|
||||||
|
Stoppt wenn neue Aufgaben erkannt werden.
|
||||||
|
"""
|
||||||
|
|
||||||
|
import sys
|
||||||
|
import json
|
||||||
|
from pathlib import Path
|
||||||
|
from datetime import datetime, timezone, timedelta
|
||||||
|
from typing import List, Dict, Any, Optional
|
||||||
|
|
||||||
|
sys.path.insert(0, str(Path(__file__).resolve().parent))
|
||||||
|
|
||||||
|
from src.store import EngramStore
|
||||||
|
from src.engram import Engram, Grounding
|
||||||
|
from src.retriever import Retriever
|
||||||
|
from src.embedder import encode
|
||||||
|
from src.chroma_store import ChromaStore
|
||||||
|
|
||||||
|
DB_PATH = Path(__file__).resolve().parent.parent / "data" / "brain.sqlite"
|
||||||
|
CHROMA_PATH = Path(__file__).resolve().parent.parent / "data" / "chroma"
|
||||||
|
|
||||||
|
# Themen die relevant sind für den Benutzer
|
||||||
|
INTEREST_TOPICS = [
|
||||||
|
"OpenClaw AI Agent",
|
||||||
|
"Künstliche Intelligenz Trends 2025",
|
||||||
|
"Second Brain Memory System",
|
||||||
|
"Automation DIY Projects",
|
||||||
|
"Smart Home IoT",
|
||||||
|
"Raspberry Pi Projects",
|
||||||
|
"Deutschland Tech News",
|
||||||
|
"AI Agent Frameworks",
|
||||||
|
"Workflow Automation",
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
def get_store():
|
||||||
|
return EngramStore(str(DB_PATH))
|
||||||
|
|
||||||
|
|
||||||
|
def load_state() -> Dict[str, Any]:
|
||||||
|
"""Lädt den Such-Zustand."""
|
||||||
|
state_path = Path(__file__).resolve().parent.parent / "data" / "search_state.json"
|
||||||
|
if state_path.exists():
|
||||||
|
with open(state_path, "r", encoding="utf-8") as f:
|
||||||
|
return json.load(f)
|
||||||
|
return {
|
||||||
|
"last_search": None,
|
||||||
|
"searched_topics": [],
|
||||||
|
"new_tasks_detected": False,
|
||||||
|
"paused_until": None,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def save_state(state: Dict[str, Any]):
|
||||||
|
state_path = Path(__file__).resolve().parent.parent / "data" / "search_state.json"
|
||||||
|
with open(state_path, "w", encoding="utf-8") as f:
|
||||||
|
json.dump(state, f, ensure_ascii=False)
|
||||||
|
|
||||||
|
|
||||||
|
def check_for_new_tasks(store: EngramStore) -> bool:
|
||||||
|
"""Prüft ob in letzten 2h neue Aufgaben-Artige Engramme erstellt wurden."""
|
||||||
|
now = datetime.now(timezone.utc)
|
||||||
|
recent = now - timedelta(hours=2)
|
||||||
|
egs = store.get_all(limit=1000)
|
||||||
|
for eg in egs:
|
||||||
|
created_str = eg.metadata.get("created", "")
|
||||||
|
if not created_str:
|
||||||
|
continue
|
||||||
|
try:
|
||||||
|
eg_time = datetime.fromisoformat(created_str)
|
||||||
|
if eg_time.tzinfo is None:
|
||||||
|
eg_time = eg_time.replace(tzinfo=timezone.utc)
|
||||||
|
if eg_time > recent:
|
||||||
|
tags = eg.metadata.get("tags", [])
|
||||||
|
if "task" in tags or "aufgabe" in tags or "todo" in tags:
|
||||||
|
return True
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def try_web_search(topic: str) -> Optional[List[Dict[str, str]]]:
|
||||||
|
"""Web-Suche via OpenClaw."""
|
||||||
|
try:
|
||||||
|
import subprocess
|
||||||
|
result = subprocess.run(
|
||||||
|
["python3", "-c", f"""
|
||||||
|
import sys
|
||||||
|
sys.path.insert(0, '/root/.openclaw/workspace/second-brain/src')
|
||||||
|
from src.retriever import Retriever
|
||||||
|
from src.store import EngramStore
|
||||||
|
store = EngramStore('data/brain.sqlite')
|
||||||
|
ret = Retriever(store)
|
||||||
|
results = ret.retrieve('{topic}')
|
||||||
|
print('FOUND ' + str(len(results)))
|
||||||
|
"""],
|
||||||
|
capture_output=True,
|
||||||
|
text=True,
|
||||||
|
timeout=30,
|
||||||
|
cwd="/root/.openclaw/workspace/second-brain",
|
||||||
|
)
|
||||||
|
# Actually do web search
|
||||||
|
print(f"[search] Would search: {topic}")
|
||||||
|
return None # Placeholder: real search would be here
|
||||||
|
except Exception as e:
|
||||||
|
print(f"[search] Error: {e}")
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def run_proactive_search():
|
||||||
|
"""Haupt-Funktion für proaktive Suche."""
|
||||||
|
store = get_store()
|
||||||
|
state = load_state()
|
||||||
|
now = datetime.now(timezone.utc)
|
||||||
|
|
||||||
|
# Check: Neue Aufgaben?
|
||||||
|
if check_for_new_tasks(store):
|
||||||
|
state["new_tasks_detected"] = True
|
||||||
|
state["paused_until"] = (now + timedelta(hours=4)).isoformat()
|
||||||
|
save_state(state)
|
||||||
|
print("🛑 Neue Aufgaben erkannt. Suche pausiert für 4h.")
|
||||||
|
return
|
||||||
|
|
||||||
|
# Check: Pausiert?
|
||||||
|
if state.get("paused_until"):
|
||||||
|
paused = datetime.fromisoformat(state["paused_until"])
|
||||||
|
if now < paused:
|
||||||
|
print(f"⏸️ Suche pausiert bis {state['paused_until']}")
|
||||||
|
return
|
||||||
|
else:
|
||||||
|
state["paused_until"] = None
|
||||||
|
state["new_tasks_detected"] = False
|
||||||
|
|
||||||
|
# Thema auswählen (Round-Robin)
|
||||||
|
searched = set(state.get("searched_topics", []))
|
||||||
|
remaining = [t for t in INTEREST_TOPICS if t not in searched]
|
||||||
|
if not remaining:
|
||||||
|
remaining = INTEREST_TOPICS
|
||||||
|
searched = set()
|
||||||
|
|
||||||
|
topic = remaining[0]
|
||||||
|
print(f"🔍 Suche: {topic}")
|
||||||
|
|
||||||
|
# Als Engramm speichern (als "Suchanfrage", nicht als Faktum)
|
||||||
|
eg = Engram.create(
|
||||||
|
content=f"Proaktive Web-Suche: {topic}\nStatus: Geplant",
|
||||||
|
source="agent",
|
||||||
|
tags=["proactive", "search", "planned"],
|
||||||
|
confidence=0.3,
|
||||||
|
grounding=Grounding.ASSUMPTION,
|
||||||
|
)
|
||||||
|
store.save(eg)
|
||||||
|
|
||||||
|
state["last_search"] = now.isoformat()
|
||||||
|
state["searched_topics"] = list(searched | {topic})
|
||||||
|
save_state(state)
|
||||||
|
|
||||||
|
print(f"✅ Such-Engramm gespeichert: {eg.id}")
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
run_proactive_search()
|
||||||
@@ -7,12 +7,10 @@ Phase 2: + Embedding + Fusion.
|
|||||||
from typing import List, Dict, Any, Optional
|
from typing import List, Dict, Any, Optional
|
||||||
from .engram import Engram
|
from .engram import Engram
|
||||||
from .store import EngramStore
|
from .store import EngramStore
|
||||||
from .chroma_store import ChromaStore
|
|
||||||
from .embedder import encode
|
|
||||||
|
|
||||||
|
|
||||||
class Retriever:
|
class Retriever:
|
||||||
def __init__(self, store: EngramStore, chroma: Optional[ChromaStore] = None):
|
def __init__(self, store: EngramStore, chroma: Optional[object] = None):
|
||||||
self.store = store
|
self.store = store
|
||||||
self.chroma = chroma
|
self.chroma = chroma
|
||||||
|
|
||||||
@@ -50,7 +48,6 @@ class Retriever:
|
|||||||
if not self.chroma:
|
if not self.chroma:
|
||||||
return []
|
return []
|
||||||
chroma_results = self.chroma.query(query, top_k=limit * 3)
|
chroma_results = self.chroma.query(query, top_k=limit * 3)
|
||||||
eids = [r["id"] for r in chroma_results]
|
|
||||||
results = []
|
results = []
|
||||||
for r in chroma_results:
|
for r in chroma_results:
|
||||||
eg = self.store.get(r["id"])
|
eg = self.store.get(r["id"])
|
||||||
|
|||||||
49
src/store.py
49
src/store.py
@@ -6,6 +6,7 @@ Keine externen Abhängigkeiten außer sqlite3 (stdlib).
|
|||||||
import json
|
import json
|
||||||
import sqlite3
|
import sqlite3
|
||||||
import os
|
import os
|
||||||
|
import re
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import List, Optional, Dict, Any
|
from typing import List, Optional, Dict, Any
|
||||||
from uuid import UUID
|
from uuid import UUID
|
||||||
@@ -127,6 +128,40 @@ class EngramStore:
|
|||||||
).fetchall()
|
).fetchall()
|
||||||
return [self._row_to_engram(r) for r in rows]
|
return [self._row_to_engram(r) for r in rows]
|
||||||
|
|
||||||
|
def get_modified_since(self, iso_ts: str, limit: int = 5000) -> List[Engram]:
|
||||||
|
"""Gibt Engramme zurück, deren `modified_at` nach `iso_ts` liegt."""
|
||||||
|
rows = self._conn.execute(
|
||||||
|
"SELECT * FROM engrams WHERE modified_at > ? ORDER BY modified_at ASC LIMIT ?",
|
||||||
|
(iso_ts, limit),
|
||||||
|
).fetchall()
|
||||||
|
return [self._row_to_engram(r) for r in rows]
|
||||||
|
|
||||||
|
def get_latest_by_session_id(
|
||||||
|
self,
|
||||||
|
session_id: str,
|
||||||
|
*,
|
||||||
|
limit: int = 5,
|
||||||
|
exclude_tags: Optional[List[str]] = None,
|
||||||
|
) -> List[Engram]:
|
||||||
|
"""
|
||||||
|
Lädt die neuesten Engramme für eine OpenClaw-Session-ID.
|
||||||
|
|
||||||
|
Hinweis: session_id liegt im `metadata_json`; wir nutzen eine robuste
|
||||||
|
LIKE-Suche, damit auch Legacy-Records gefunden werden.
|
||||||
|
"""
|
||||||
|
if not session_id:
|
||||||
|
return []
|
||||||
|
rows = self._conn.execute(
|
||||||
|
"SELECT * FROM engrams WHERE metadata_json LIKE ? ORDER BY created_at DESC LIMIT ?",
|
||||||
|
(f'%"session_id": "{session_id}"%', limit),
|
||||||
|
).fetchall()
|
||||||
|
engrams = [self._row_to_engram(r) for r in rows]
|
||||||
|
if exclude_tags:
|
||||||
|
ex = set(t for t in exclude_tags if isinstance(t, str))
|
||||||
|
if ex:
|
||||||
|
engrams = [e for e in engrams if not (ex & set(e.metadata.get("tags", []) or []))]
|
||||||
|
return engrams
|
||||||
|
|
||||||
def delete(self, engram_id: str) -> bool:
|
def delete(self, engram_id: str) -> bool:
|
||||||
"""Löscht ein Engramm und alle Verknüpfungen."""
|
"""Löscht ein Engramm und alle Verknüpfungen."""
|
||||||
rowid = self._conn.execute(
|
rowid = self._conn.execute(
|
||||||
@@ -150,7 +185,12 @@ class EngramStore:
|
|||||||
def search_text(self, query: str, limit: int = 10) -> List[Engram]:
|
def search_text(self, query: str, limit: int = 10) -> List[Engram]:
|
||||||
"""Full-Text-Suche über Engramm-Inhalt via SQLite FTS5 (OR-Verknüpfung)."""
|
"""Full-Text-Suche über Engramm-Inhalt via SQLite FTS5 (OR-Verknüpfung)."""
|
||||||
# FTS5-Syntax: Wörter mit OR verbinden für bessere Ergebnisse
|
# FTS5-Syntax: Wörter mit OR verbinden für bessere Ergebnisse
|
||||||
words = [w.strip() for w in query.replace("'", "''").split() if w.strip()]
|
words = []
|
||||||
|
for word in query.split():
|
||||||
|
# Nur alphanumerische Zeichen als FTS5-Tokens akzeptieren
|
||||||
|
clean_word = re.sub(r'[^a-zA-Z0-9]+', '', word)
|
||||||
|
if clean_word:
|
||||||
|
words.append(clean_word)
|
||||||
safe_query = " OR ".join(words) if len(words) > 1 else (words[0] if words else "*")
|
safe_query = " OR ".join(words) if len(words) > 1 else (words[0] if words else "*")
|
||||||
sql = """
|
sql = """
|
||||||
SELECT e.* FROM engrams e
|
SELECT e.* FROM engrams e
|
||||||
@@ -239,6 +279,13 @@ class EngramStore:
|
|||||||
"links": json.loads(row["links_json"]),
|
"links": json.loads(row["links_json"]),
|
||||||
"hierarchy": json.loads(row["hierarchy_json"]),
|
"hierarchy": json.loads(row["hierarchy_json"]),
|
||||||
}
|
}
|
||||||
|
# Keep Engram metadata timestamps aligned with DB columns so downstream
|
||||||
|
# consumers (e.g. vector indexing watermarks) can rely on them.
|
||||||
|
try:
|
||||||
|
d["metadata"]["created"] = row["created_at"]
|
||||||
|
d["metadata"]["modified"] = row["modified_at"]
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
emb = row["embedding_json"]
|
emb = row["embedding_json"]
|
||||||
if emb:
|
if emb:
|
||||||
d["embedding"] = json.loads(emb)
|
d["embedding"] = json.loads(emb)
|
||||||
|
|||||||
457
static/style.css
Normal file
457
static/style.css
Normal file
@@ -0,0 +1,457 @@
|
|||||||
|
/* ─── Reset & Base ────────────────────────────────────────────────────────── */
|
||||||
|
* { margin: 0; padding: 0; box-sizing: border-box; }
|
||||||
|
html { font-size: 14px; }
|
||||||
|
body {
|
||||||
|
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
|
||||||
|
background: #0f0f12;
|
||||||
|
color: #e8e8ee;
|
||||||
|
-webkit-font-smoothing: antialiased;
|
||||||
|
overscroll-behavior-y: contain;
|
||||||
|
}
|
||||||
|
|
||||||
|
.app {
|
||||||
|
max-width: 480px;
|
||||||
|
margin: 0 auto;
|
||||||
|
min-height: 100vh;
|
||||||
|
background: #141419;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ─── Stats Bar ───────────────────────────────────────────────────────────── */
|
||||||
|
.stats-bar {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-around;
|
||||||
|
padding: 10px 8px;
|
||||||
|
background: linear-gradient(180deg, #1a1a22 0%, #131318 100%);
|
||||||
|
border-bottom: 1px solid #252530;
|
||||||
|
position: sticky;
|
||||||
|
top: 0;
|
||||||
|
z-index: 50;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tabs-bar{
|
||||||
|
display:flex;
|
||||||
|
gap:8px;
|
||||||
|
padding:8px 12px 10px;
|
||||||
|
background:#141419;
|
||||||
|
border-bottom:1px solid #252530;
|
||||||
|
position: sticky;
|
||||||
|
top: 52px;
|
||||||
|
z-index: 45;
|
||||||
|
}
|
||||||
|
.tabs-bar .tab-btn{
|
||||||
|
flex:1;
|
||||||
|
background:#1e1e28;
|
||||||
|
border:1px solid #2a2a3a;
|
||||||
|
border-radius: 12px;
|
||||||
|
padding:10px 10px;
|
||||||
|
color:#cfd3ff;
|
||||||
|
font-weight:700;
|
||||||
|
font-size:0.82rem;
|
||||||
|
}
|
||||||
|
.tabs-bar .tab-btn.active{
|
||||||
|
border-color:#6c8af5;
|
||||||
|
box-shadow:0 0 0 1px rgba(108,138,245,0.22) inset;
|
||||||
|
}
|
||||||
|
.stat {
|
||||||
|
text-align: center;
|
||||||
|
min-width: 60px;
|
||||||
|
}
|
||||||
|
.stat-num {
|
||||||
|
display: block;
|
||||||
|
font-size: 1.3rem;
|
||||||
|
font-weight: 700;
|
||||||
|
color: #6c8af5;
|
||||||
|
line-height: 1.2;
|
||||||
|
}
|
||||||
|
.stat-label {
|
||||||
|
display: block;
|
||||||
|
font-size: 0.65rem;
|
||||||
|
color: #888899;
|
||||||
|
text-transform: uppercase;
|
||||||
|
letter-spacing: 0.5px;
|
||||||
|
margin-top: 2px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ─── Search ──────────────────────────────────────────────────────────────── */
|
||||||
|
.search-box {
|
||||||
|
display: flex;
|
||||||
|
gap: 8px;
|
||||||
|
padding: 10px 12px;
|
||||||
|
background: #141419;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* tab buttons styled via .tabs-bar */
|
||||||
|
|
||||||
|
/* ─── Panels (Graph/Status) ──────────────────────────────────────────────── */
|
||||||
|
.panel {
|
||||||
|
margin: 8px 12px;
|
||||||
|
background: #1a1a24;
|
||||||
|
border: 1px solid #252533;
|
||||||
|
border-radius: 14px;
|
||||||
|
padding: 10px 12px;
|
||||||
|
}
|
||||||
|
.panel-title {
|
||||||
|
font-size: 0.8rem;
|
||||||
|
text-transform: uppercase;
|
||||||
|
letter-spacing: 0.5px;
|
||||||
|
color: #9aa3d9;
|
||||||
|
margin-bottom: 8px;
|
||||||
|
}
|
||||||
|
.kv-row {
|
||||||
|
display: flex;
|
||||||
|
gap: 10px;
|
||||||
|
padding: 6px 0;
|
||||||
|
border-bottom: 1px solid #20202a;
|
||||||
|
}
|
||||||
|
.kv-row:last-child { border-bottom: none; }
|
||||||
|
.kv-key {
|
||||||
|
width: 110px;
|
||||||
|
color: #888899;
|
||||||
|
font-size: 0.78rem;
|
||||||
|
}
|
||||||
|
.kv-val {
|
||||||
|
flex: 1;
|
||||||
|
color: #e8e8ee;
|
||||||
|
font-size: 0.85rem;
|
||||||
|
word-break: break-word;
|
||||||
|
}
|
||||||
|
.pill {
|
||||||
|
display: inline-block;
|
||||||
|
margin: 2px 4px 2px 0;
|
||||||
|
padding: 2px 8px;
|
||||||
|
border-radius: 999px;
|
||||||
|
background: #2a2a3a;
|
||||||
|
color: #8a9aff;
|
||||||
|
font-size: 0.72rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.verdict-pill{
|
||||||
|
display:inline-block;
|
||||||
|
margin: 2px 6px 2px 0;
|
||||||
|
padding: 2px 8px;
|
||||||
|
border-radius: 999px;
|
||||||
|
font-size: 0.72rem;
|
||||||
|
font-weight: 800;
|
||||||
|
letter-spacing: 0.4px;
|
||||||
|
border: 1px solid #2a2a3a;
|
||||||
|
background: #1e1e28;
|
||||||
|
color: #cfd3ff;
|
||||||
|
}
|
||||||
|
.verdict-pill.v-true{ border-color:#2f6b3f; color:#aaf0b6; }
|
||||||
|
.verdict-pill.v-false{ border-color:#7a2c2c; color:#ffb3b3; }
|
||||||
|
.verdict-pill.v-prob-true{ border-color:#6c8af5; color:#cfd9ff; }
|
||||||
|
.verdict-pill.v-prob-false{ border-color:#b08a2a; color:#ffe2a3; }
|
||||||
|
.verdict-pill.v-unknown{ border-color:#3a3a55; color:#b9b9c9; }
|
||||||
|
.muted {
|
||||||
|
color: #888899;
|
||||||
|
font-size: 0.8rem;
|
||||||
|
margin-top: 6px;
|
||||||
|
}
|
||||||
|
.small { font-size: 0.75rem; }
|
||||||
|
|
||||||
|
/* Graph canvas */
|
||||||
|
#graphCanvas{
|
||||||
|
display:block;
|
||||||
|
margin: 8px auto 0;
|
||||||
|
background:#12121a;
|
||||||
|
border:1px solid #252533;
|
||||||
|
border-radius: 14px;
|
||||||
|
touch-action: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.graph-controls{
|
||||||
|
display:flex;
|
||||||
|
gap:8px;
|
||||||
|
padding: 10px 12px 0;
|
||||||
|
align-items:center;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
}
|
||||||
|
.graph-controls .btn{
|
||||||
|
background:#1e1e28;
|
||||||
|
border:1px solid #2a2a3a;
|
||||||
|
border-radius: 10px;
|
||||||
|
padding: 8px 10px;
|
||||||
|
color:#cfd3ff;
|
||||||
|
font-weight:700;
|
||||||
|
font-size:0.82rem;
|
||||||
|
}
|
||||||
|
.graph-controls .btn.primary{
|
||||||
|
border-color:#6c8af5;
|
||||||
|
box-shadow:0 0 0 1px rgba(108,138,245,0.18) inset;
|
||||||
|
}
|
||||||
|
.graph-legend{
|
||||||
|
margin: 8px 12px 0;
|
||||||
|
padding: 10px 12px;
|
||||||
|
background:#1a1a24;
|
||||||
|
border:1px solid #252533;
|
||||||
|
border-radius: 14px;
|
||||||
|
color:#b9b9c9;
|
||||||
|
font-size:0.8rem;
|
||||||
|
line-height:1.4;
|
||||||
|
}
|
||||||
|
.legend-row{ display:flex; align-items:center; gap:8px; margin-top:6px; }
|
||||||
|
.legend-dot{ width:10px; height:10px; border-radius:50%; display:inline-block; }
|
||||||
|
.legend-dot.engram{ background:#6c8af5; }
|
||||||
|
.legend-dot.tag{ background:#8a9aff; }
|
||||||
|
.legend-dot.match{ background:#f7d154; }
|
||||||
|
.graph-hint{ padding: 4px 12px 10px; }
|
||||||
|
#searchInput {
|
||||||
|
flex: 1;
|
||||||
|
background: #1e1e28;
|
||||||
|
border: 1px solid #2a2a3a;
|
||||||
|
border-radius: 10px;
|
||||||
|
padding: 10px 14px;
|
||||||
|
color: #e8e8ee;
|
||||||
|
font-size: 0.95rem;
|
||||||
|
outline: none;
|
||||||
|
}
|
||||||
|
#searchInput:focus { border-color: #6c8af5; }
|
||||||
|
#filterSelect {
|
||||||
|
background: #1e1e28;
|
||||||
|
border: 1px solid #2a2a3a;
|
||||||
|
border-radius: 10px;
|
||||||
|
padding: 10px;
|
||||||
|
color: #e8e8ee;
|
||||||
|
font-size: 0.85rem;
|
||||||
|
outline: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ─── New Engram ──────────────────────────────────────────────────────────── */
|
||||||
|
.new-engram {
|
||||||
|
padding: 0 12px 8px;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 6px;
|
||||||
|
}
|
||||||
|
.new-engram textarea {
|
||||||
|
background: #1e1e28;
|
||||||
|
border: 1px solid #2a2a3a;
|
||||||
|
border-radius: 10px;
|
||||||
|
padding: 10px;
|
||||||
|
color: #e8e8ee;
|
||||||
|
font-size: 0.9rem;
|
||||||
|
resize: vertical;
|
||||||
|
min-height: 50px;
|
||||||
|
}
|
||||||
|
.new-engram input {
|
||||||
|
background: #1e1e28;
|
||||||
|
border: 1px solid #2a2a3a;
|
||||||
|
border-radius: 10px;
|
||||||
|
padding: 8px 10px;
|
||||||
|
color: #e8e8ee;
|
||||||
|
font-size: 0.85rem;
|
||||||
|
}
|
||||||
|
.new-engram button {
|
||||||
|
background: #3a7d3a;
|
||||||
|
border: none;
|
||||||
|
border-radius: 10px;
|
||||||
|
padding: 10px;
|
||||||
|
color: #fff;
|
||||||
|
font-weight: 600;
|
||||||
|
font-size: 0.95rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ─── Cards ───────────────────────────────────────────────────────────────── */
|
||||||
|
.cards {
|
||||||
|
padding: 4px 12px;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 10px;
|
||||||
|
}
|
||||||
|
.card {
|
||||||
|
background: #1a1a24;
|
||||||
|
border: 1px solid #252533;
|
||||||
|
border-radius: 14px;
|
||||||
|
overflow: hidden;
|
||||||
|
transition: transform 0.15s ease, border-color 0.2s ease;
|
||||||
|
touch-action: manipulation;
|
||||||
|
}
|
||||||
|
.card:active { transform: scale(0.985); }
|
||||||
|
.card.confirmed { border-left: 4px solid #3a7d3a; }
|
||||||
|
.card.rejected { border-left: 4px solid #8a3a3a; }
|
||||||
|
|
||||||
|
.card-header {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 8px;
|
||||||
|
padding: 10px 12px 6px;
|
||||||
|
border-bottom: 1px solid #20202a;
|
||||||
|
}
|
||||||
|
.conf-badge {
|
||||||
|
font-size: 0.75rem;
|
||||||
|
font-weight: 700;
|
||||||
|
color: #fff;
|
||||||
|
padding: 2px 8px;
|
||||||
|
border-radius: 20px;
|
||||||
|
min-width: 36px;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
.tags {
|
||||||
|
flex: 1;
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
gap: 4px;
|
||||||
|
}
|
||||||
|
.tag {
|
||||||
|
background: #2a2a3a;
|
||||||
|
color: #8a9aff;
|
||||||
|
font-size: 0.68rem;
|
||||||
|
padding: 2px 8px;
|
||||||
|
border-radius: 12px;
|
||||||
|
text-transform: uppercase;
|
||||||
|
letter-spacing: 0.3px;
|
||||||
|
}
|
||||||
|
.date {
|
||||||
|
font-size: 0.65rem;
|
||||||
|
color: #666677;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.card-body {
|
||||||
|
padding: 10px 12px;
|
||||||
|
font-size: 0.9rem;
|
||||||
|
line-height: 1.45;
|
||||||
|
color: #ccccdd;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.card-footer {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 8px;
|
||||||
|
padding: 8px 12px 10px;
|
||||||
|
border-top: 1px solid #20202a;
|
||||||
|
}
|
||||||
|
.reason-input {
|
||||||
|
flex: 1;
|
||||||
|
background: #14141a;
|
||||||
|
border: 1px solid #2a2a3a;
|
||||||
|
border-radius: 8px;
|
||||||
|
padding: 6px 10px;
|
||||||
|
color: #b0b0c0;
|
||||||
|
font-size: 0.8rem;
|
||||||
|
}
|
||||||
|
.actions {
|
||||||
|
display: flex;
|
||||||
|
gap: 6px;
|
||||||
|
}
|
||||||
|
.actions button {
|
||||||
|
width: 34px;
|
||||||
|
height: 34px;
|
||||||
|
border-radius: 50%;
|
||||||
|
border: none;
|
||||||
|
font-size: 1rem;
|
||||||
|
cursor: pointer;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
transition: transform 0.1s;
|
||||||
|
}
|
||||||
|
.actions button:active { transform: scale(0.9); }
|
||||||
|
.btn-ok { background: #2a5a2a; }
|
||||||
|
.btn-no { background: #5a2a2a; }
|
||||||
|
.btn-archive { background: #2a2a4a; }
|
||||||
|
|
||||||
|
/* ─── Pagination ──────────────────────────────────────────────────────────── */
|
||||||
|
.pagination {
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
gap: 16px;
|
||||||
|
padding: 14px;
|
||||||
|
}
|
||||||
|
.pagination button {
|
||||||
|
background: #252535;
|
||||||
|
border: none;
|
||||||
|
border-radius: 10px;
|
||||||
|
width: 40px;
|
||||||
|
height: 40px;
|
||||||
|
color: #e8e8ee;
|
||||||
|
font-size: 1.1rem;
|
||||||
|
}
|
||||||
|
.pagination button:disabled {
|
||||||
|
opacity: 0.3;
|
||||||
|
}
|
||||||
|
#pageNum {
|
||||||
|
font-weight: 700;
|
||||||
|
color: #6c8af5;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ─── Footer ──────────────────────────────────────────────────────────────── */
|
||||||
|
.footer {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
padding: 10px 16px 20px;
|
||||||
|
color: #555566;
|
||||||
|
font-size: 0.75rem;
|
||||||
|
}
|
||||||
|
.refresh-btn {
|
||||||
|
background: #252535;
|
||||||
|
border: none;
|
||||||
|
border-radius: 50%;
|
||||||
|
width: 36px;
|
||||||
|
height: 36px;
|
||||||
|
color: #8888aa;
|
||||||
|
font-size: 1.2rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ─── Modal ───────────────────────────────────────────────────────────────── */
|
||||||
|
.modal {
|
||||||
|
display: none;
|
||||||
|
position: fixed;
|
||||||
|
inset: 0;
|
||||||
|
background: rgba(0,0,0,0.85);
|
||||||
|
z-index: 100;
|
||||||
|
overflow-y: auto;
|
||||||
|
padding: 20px 16px;
|
||||||
|
}
|
||||||
|
.modal.open { display: block; }
|
||||||
|
.modal-content {
|
||||||
|
background: #1a1a24;
|
||||||
|
border: 1px solid #333344;
|
||||||
|
border-radius: 16px;
|
||||||
|
padding: 20px 16px;
|
||||||
|
max-width: 480px;
|
||||||
|
margin: 0 auto;
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
.close-btn {
|
||||||
|
position: absolute;
|
||||||
|
top: 10px;
|
||||||
|
right: 14px;
|
||||||
|
background: none;
|
||||||
|
border: none;
|
||||||
|
color: #8888aa;
|
||||||
|
font-size: 1.5rem;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
.history {
|
||||||
|
list-style: none;
|
||||||
|
font-size: 0.8rem;
|
||||||
|
color: #9999aa;
|
||||||
|
}
|
||||||
|
.history li {
|
||||||
|
padding: 4px 0;
|
||||||
|
border-bottom: 1px solid #20202a;
|
||||||
|
}
|
||||||
|
.detail-content {
|
||||||
|
background: #14141a;
|
||||||
|
border-radius: 10px;
|
||||||
|
padding: 12px;
|
||||||
|
font-size: 0.88rem;
|
||||||
|
line-height: 1.5;
|
||||||
|
margin: 8px 0;
|
||||||
|
max-height: 40vh;
|
||||||
|
overflow-y: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ─── Scrollbar ───────────────────────────────────────────────────────────── */
|
||||||
|
::-webkit-scrollbar { width: 4px; }
|
||||||
|
::-webkit-scrollbar-track { background: transparent; }
|
||||||
|
::-webkit-scrollbar-thumb { background: #333344; border-radius: 4px; }
|
||||||
|
|
||||||
|
/* ─── Touch fix ───────────────────────────────────────────────────────────── */
|
||||||
|
@media (pointer: coarse) {
|
||||||
|
button, .card { -webkit-tap-highlight-color: transparent; }
|
||||||
|
}
|
||||||
9
systemd/openclaw-memory-archive.service
Normal file
9
systemd/openclaw-memory-archive.service
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=OpenClaw archive memory/*.md older than 7 days
|
||||||
|
OnFailure=openclaw-secondbrain-notify@%n.service
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=oneshot
|
||||||
|
WorkingDirectory=/root/.openclaw/workspace
|
||||||
|
ExecStart=/bin/bash -lc 'flock -n /tmp/%n.lock /usr/bin/python3 /root/.openclaw/workspace/openclaw_cron_wrapper.py archive_memory_md'
|
||||||
|
|
||||||
10
systemd/openclaw-memory-archive.timer
Normal file
10
systemd/openclaw-memory-archive.timer
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=OpenClaw archive memory/*.md daily
|
||||||
|
|
||||||
|
[Timer]
|
||||||
|
OnCalendar=*-*-* 03:30:00
|
||||||
|
Persistent=true
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=timers.target
|
||||||
|
|
||||||
8
systemd/openclaw-secondbrain-backup.service
Normal file
8
systemd/openclaw-secondbrain-backup.service
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=OpenClaw Second-Brain backup_secondbrain
|
||||||
|
OnFailure=openclaw-secondbrain-notify@%n.service
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=oneshot
|
||||||
|
WorkingDirectory=/root/.openclaw/workspace
|
||||||
|
ExecStart=/bin/bash -lc 'flock -n /tmp/%n.lock /usr/bin/python3 /root/.openclaw/workspace/openclaw_cron_wrapper.py backup_secondbrain'
|
||||||
10
systemd/openclaw-secondbrain-backup.timer
Normal file
10
systemd/openclaw-secondbrain-backup.timer
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=OpenClaw Second-Brain backup_secondbrain (daily 02:00)
|
||||||
|
|
||||||
|
[Timer]
|
||||||
|
OnCalendar=*-*-* 02:00:00
|
||||||
|
Persistent=true
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=timers.target
|
||||||
|
|
||||||
15
systemd/openclaw-secondbrain-dashboard.service
Normal file
15
systemd/openclaw-secondbrain-dashboard.service
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=OpenClaw Second-Brain Dashboard (FastAPI)
|
||||||
|
After=network.target
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=simple
|
||||||
|
WorkingDirectory=/root/.openclaw/workspace/second-brain
|
||||||
|
Environment=SECOND_BRAIN_WORKSPACE=/root/.openclaw/workspace/second-brain
|
||||||
|
Environment=SECOND_BRAIN_PORT=8501
|
||||||
|
ExecStart=/root/.openclaw/workspace/second-brain/.venv/bin/uvicorn fastapi_app:app --host 0.0.0.0 --port 8501
|
||||||
|
Restart=always
|
||||||
|
RestartSec=2
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
||||||
8
systemd/openclaw-secondbrain-export-obsidian.service
Normal file
8
systemd/openclaw-secondbrain-export-obsidian.service
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=OpenClaw Second-Brain export_obsidian
|
||||||
|
OnFailure=openclaw-secondbrain-notify@%n.service
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=oneshot
|
||||||
|
WorkingDirectory=/root/.openclaw/workspace
|
||||||
|
ExecStart=/bin/bash -lc 'flock -n /tmp/%n.lock /usr/bin/python3 /root/.openclaw/workspace/openclaw_cron_wrapper.py export_obsidian'
|
||||||
10
systemd/openclaw-secondbrain-export-obsidian.timer
Normal file
10
systemd/openclaw-secondbrain-export-obsidian.timer
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=OpenClaw Second-Brain export_obsidian (hourly)
|
||||||
|
|
||||||
|
[Timer]
|
||||||
|
OnCalendar=hourly
|
||||||
|
Persistent=true
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=timers.target
|
||||||
|
|
||||||
8
systemd/openclaw-secondbrain-heartbeat.service
Normal file
8
systemd/openclaw-secondbrain-heartbeat.service
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=OpenClaw Second-Brain heartbeat_secondbrain
|
||||||
|
OnFailure=openclaw-secondbrain-notify@%n.service
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=oneshot
|
||||||
|
WorkingDirectory=/root/.openclaw/workspace
|
||||||
|
ExecStart=/bin/bash -lc 'flock -n /tmp/%n.lock /usr/bin/python3 /root/.openclaw/workspace/openclaw_cron_wrapper.py heartbeat_secondbrain'
|
||||||
11
systemd/openclaw-secondbrain-heartbeat.timer
Normal file
11
systemd/openclaw-secondbrain-heartbeat.timer
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=OpenClaw Second-Brain heartbeat_secondbrain (every 6h)
|
||||||
|
|
||||||
|
[Timer]
|
||||||
|
OnCalendar=*-*-* 00,06,12,18:00:00
|
||||||
|
RandomizedDelaySec=300
|
||||||
|
Persistent=true
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=timers.target
|
||||||
|
|
||||||
10
systemd/openclaw-secondbrain-index-vectors.service
Normal file
10
systemd/openclaw-secondbrain-index-vectors.service
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=OpenClaw Second-Brain index_vectors
|
||||||
|
OnFailure=openclaw-secondbrain-notify@%n.service
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=oneshot
|
||||||
|
WorkingDirectory=/root/.openclaw/workspace
|
||||||
|
Environment=HF_HOME=/root/.openclaw/workspace/second-brain/data/hf_cache
|
||||||
|
Environment=SENTENCE_TRANSFORMERS_HOME=/root/.openclaw/workspace/second-brain/data/st_cache
|
||||||
|
ExecStart=/bin/bash -lc 'flock -n /tmp/%n.lock /usr/bin/python3 /root/.openclaw/workspace/openclaw_cron_wrapper.py index_vectors'
|
||||||
10
systemd/openclaw-secondbrain-index-vectors.timer
Normal file
10
systemd/openclaw-secondbrain-index-vectors.timer
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=OpenClaw Second-Brain index_vectors (every 30 min)
|
||||||
|
|
||||||
|
[Timer]
|
||||||
|
OnCalendar=*:0/30
|
||||||
|
Persistent=true
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=timers.target
|
||||||
|
|
||||||
8
systemd/openclaw-secondbrain-ingest-memory.service
Normal file
8
systemd/openclaw-secondbrain-ingest-memory.service
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=OpenClaw Second-Brain ingest_memory
|
||||||
|
OnFailure=openclaw-secondbrain-notify@%n.service
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=oneshot
|
||||||
|
WorkingDirectory=/root/.openclaw/workspace
|
||||||
|
ExecStart=/bin/bash -lc 'flock -n /tmp/%n.lock /usr/bin/python3 /root/.openclaw/workspace/openclaw_cron_wrapper.py ingest_memory'
|
||||||
9
systemd/openclaw-secondbrain-ingest-memory.timer
Normal file
9
systemd/openclaw-secondbrain-ingest-memory.timer
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=OpenClaw Second-Brain ingest_memory (every 5 min)
|
||||||
|
|
||||||
|
[Timer]
|
||||||
|
OnCalendar=*:0/5
|
||||||
|
Persistent=true
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=timers.target
|
||||||
8
systemd/openclaw-secondbrain-ingest-obsidian.service
Normal file
8
systemd/openclaw-secondbrain-ingest-obsidian.service
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=OpenClaw Second-Brain ingest_obsidian
|
||||||
|
OnFailure=openclaw-secondbrain-notify@%n.service
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=oneshot
|
||||||
|
WorkingDirectory=/root/.openclaw/workspace
|
||||||
|
ExecStart=/bin/bash -lc 'flock -n /tmp/%n.lock /usr/bin/python3 /root/.openclaw/workspace/openclaw_cron_wrapper.py ingest_obsidian'
|
||||||
10
systemd/openclaw-secondbrain-ingest-obsidian.timer
Normal file
10
systemd/openclaw-secondbrain-ingest-obsidian.timer
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=OpenClaw Second-Brain ingest_obsidian (every 15 min)
|
||||||
|
|
||||||
|
[Timer]
|
||||||
|
OnCalendar=*:0/15
|
||||||
|
Persistent=true
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=timers.target
|
||||||
|
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=OpenClaw Second-Brain ingest transcript -> DB
|
||||||
|
OnFailure=openclaw-secondbrain-notify@%n.service
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=oneshot
|
||||||
|
WorkingDirectory=/root/.openclaw/workspace
|
||||||
|
ExecStart=/bin/bash -lc 'flock -n /tmp/%n.lock /usr/bin/python3 /root/.openclaw/workspace/openclaw_cron_wrapper.py ingest_transcript_to_db'
|
||||||
|
|
||||||
12
systemd/openclaw-secondbrain-ingest-transcript-to-db.timer
Normal file
12
systemd/openclaw-secondbrain-ingest-transcript-to-db.timer
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=OpenClaw Second-Brain ingest transcript -> DB (every 5 min)
|
||||||
|
|
||||||
|
[Timer]
|
||||||
|
OnBootSec=90s
|
||||||
|
OnUnitActiveSec=300s
|
||||||
|
Unit=openclaw-secondbrain-ingest-transcript-to-db.service
|
||||||
|
Persistent=true
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=timers.target
|
||||||
|
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=OpenClaw Second-Brain ingest transcript -> memory/*.md
|
||||||
|
OnFailure=openclaw-secondbrain-notify@%n.service
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=oneshot
|
||||||
|
WorkingDirectory=/root/.openclaw/workspace
|
||||||
|
ExecStart=/bin/bash -lc 'flock -n /tmp/%n.lock /usr/bin/python3 /root/.openclaw/workspace/second-brain/cron_tasks/ingest_transcript_to_memory.py'
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=OpenClaw Second-Brain ingest transcript -> memory (every 1 min)
|
||||||
|
|
||||||
|
[Timer]
|
||||||
|
OnBootSec=30s
|
||||||
|
OnUnitActiveSec=60s
|
||||||
|
Unit=openclaw-secondbrain-ingest-transcript-to-memory.service
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=timers.target
|
||||||
|
|
||||||
8
systemd/openclaw-secondbrain-notify@.service
Normal file
8
systemd/openclaw-secondbrain-notify@.service
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=OpenClaw Second-Brain failure notify (%i)
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=oneshot
|
||||||
|
WorkingDirectory=/root/.openclaw/workspace
|
||||||
|
ExecStart=/bin/bash -lc '/root/.openclaw/workspace/notify-telegram.sh "❌ Second-Brain job failed: %i. Check: journalctl -u %i -n 50 --no-pager"'
|
||||||
|
|
||||||
10
systemd/openclaw-secondbrain-proactive-search.service
Normal file
10
systemd/openclaw-secondbrain-proactive-search.service
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=OpenClaw Second-Brain proactive_search_wrapper
|
||||||
|
Wants=network-online.target
|
||||||
|
After=network-online.target
|
||||||
|
OnFailure=openclaw-secondbrain-notify@%n.service
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=oneshot
|
||||||
|
WorkingDirectory=/root/.openclaw/workspace
|
||||||
|
ExecStart=/bin/bash -lc 'flock -n /tmp/%n.lock /usr/bin/python3 /root/.openclaw/workspace/openclaw_cron_wrapper.py proactive_search_wrapper'
|
||||||
11
systemd/openclaw-secondbrain-proactive-search.timer
Normal file
11
systemd/openclaw-secondbrain-proactive-search.timer
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=OpenClaw Second-Brain proactive_search_wrapper (every 4h)
|
||||||
|
|
||||||
|
[Timer]
|
||||||
|
OnCalendar=*-*-* 01,05,09,13,17,21:10:00
|
||||||
|
RandomizedDelaySec=600
|
||||||
|
Persistent=true
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=timers.target
|
||||||
|
|
||||||
8
systemd/openclaw-secondbrain-review.service
Normal file
8
systemd/openclaw-secondbrain-review.service
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=OpenClaw Second-Brain review_brain
|
||||||
|
OnFailure=openclaw-secondbrain-notify@%n.service
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=oneshot
|
||||||
|
WorkingDirectory=/root/.openclaw/workspace
|
||||||
|
ExecStart=/bin/bash -lc 'flock -n /tmp/%n.lock /usr/bin/python3 /root/.openclaw/workspace/openclaw_cron_wrapper.py review_brain'
|
||||||
9
systemd/openclaw-secondbrain-review.timer
Normal file
9
systemd/openclaw-secondbrain-review.timer
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=OpenClaw Second-Brain review_brain (every 5 min)
|
||||||
|
|
||||||
|
[Timer]
|
||||||
|
OnCalendar=*:0/5
|
||||||
|
Persistent=true
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=timers.target
|
||||||
13
systemd/openclaw-secondbrain-task@.service
Normal file
13
systemd/openclaw-secondbrain-task@.service
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=OpenClaw Second-Brain task (%i)
|
||||||
|
Wants=network-online.target
|
||||||
|
After=network-online.target
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=oneshot
|
||||||
|
WorkingDirectory=/root/.openclaw/workspace
|
||||||
|
ExecStart=/usr/bin/python3 /root/.openclaw/workspace/openclaw_cron_wrapper.py %i
|
||||||
|
Nice=10
|
||||||
|
IOSchedulingClass=best-effort
|
||||||
|
IOSchedulingPriority=6
|
||||||
|
|
||||||
9
systemd/openclaw-secondbrain-verify-pending.service
Normal file
9
systemd/openclaw-secondbrain-verify-pending.service
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=OpenClaw Second-Brain verify_pending_external
|
||||||
|
OnFailure=openclaw-secondbrain-notify@%n.service
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=oneshot
|
||||||
|
WorkingDirectory=/root/.openclaw/workspace
|
||||||
|
ExecStart=/bin/bash -lc 'flock -n /tmp/%n.lock /usr/bin/python3 /root/.openclaw/workspace/openclaw_cron_wrapper.py verify_pending_external'
|
||||||
|
|
||||||
10
systemd/openclaw-secondbrain-verify-pending.timer
Normal file
10
systemd/openclaw-secondbrain-verify-pending.timer
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=OpenClaw Second-Brain periodic verify_pending_external
|
||||||
|
|
||||||
|
[Timer]
|
||||||
|
OnBootSec=2min
|
||||||
|
OnUnitActiveSec=5min
|
||||||
|
Persistent=true
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=timers.target
|
||||||
1119
templates/dashboard.html
Normal file
1119
templates/dashboard.html
Normal file
File diff suppressed because it is too large
Load Diff
@@ -4,16 +4,11 @@
|
|||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
import tempfile
|
import tempfile
|
||||||
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "src"))
|
sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
|
||||||
|
|
||||||
try:
|
from src.engram import Engram, Grounding, Correctness
|
||||||
from src.engram import Engram, Grounding, Correctness
|
from src.store import EngramStore
|
||||||
from src.store import EngramStore
|
from src.retriever import Retriever
|
||||||
from src.retriever import Retriever
|
|
||||||
except ImportError:
|
|
||||||
from engram import Engram, Grounding, Correctness
|
|
||||||
from store import EngramStore
|
|
||||||
from retriever import Retriever
|
|
||||||
|
|
||||||
|
|
||||||
def test_engram_creation():
|
def test_engram_creation():
|
||||||
|
|||||||
Reference in New Issue
Block a user