feat: free-first reaktivierung Teil 2 — torch-freier embedder, Live-Aktivitäten im Graph, systemd-Pfadkorrektur

- src/embedder.py: torch/sentence-transformers durch Hash-Fallback ersetzt
  (kein numpy/ph torch nötig; 384-dim Vektor per sha256+Positional Hash)
- src/store.py: _touch_access() tracked reads für Live-Graph-Aktivität
- fastapi_app.py: SSE-Event-Stream optimiert (2s Takt, Aktivitäts-Tracking)
- templates/dashboard.html: Graph 2.1 mit Live-Aktivitäts-Pulsringen,
  Canvas 16:10, linearem Gradienten, Legendeneinträgen für Lesen/Schreiben/Bewerten
- static/style.css: Grafik-Radius 6px, Activity-Legendenfarben
- openclaw_cron_wrapper.py: CRON_TASKS_DIR ins second-brain-Verzeichnis
- systemd/*.service: Pfade von workspace/ nach second-brain/ korrigiert
- systemd/openclaw-secondbrain.target: neuer Multi-User-Target für Second Brain
- .gitignore: backups/ hinzugefügt

Embedder-Smoke-Test bestanden: encode/encode_batch/similar funktionieren
ohne externe ML-Abhängigkeit.

Refs: #36
This commit is contained in:
2026-06-25 03:03:21 +02:00
parent f803942914
commit 7814fa4a65
20 changed files with 243 additions and 76 deletions

View File

@@ -4,7 +4,7 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<title>🧠 Second Brain</title>
<link rel="stylesheet" href="/static/style.css">
<link rel="stylesheet" href="/static/style.css?v=20260610-live-graph">
</head>
<body>
<div class="app">
@@ -67,7 +67,7 @@
<option value="5000">Nodes: 5000</option>
</select>
<button class="btn" onclick="reloadGraph()">Reload</button>
<span class="graph-mode">Graph 2.0 live</span>
<span class="graph-mode" id="graphMode">Graph 2.1 live</span>
</div>
<canvas id="graphCanvas" width="440" height="520"></canvas>
<div class="graph-hint muted small" id="graphHint">Lade Graph…</div>
@@ -82,6 +82,9 @@
<div class="legend-row"><span class="legend-dot tag"></span> Tag</div>
<div class="legend-row"><span class="legend-dot source"></span> Quelle</div>
<div class="legend-row"><span class="legend-dot match"></span> Match (Suche)</div>
<div class="legend-row"><span class="legend-dot read"></span> Lesen live</div>
<div class="legend-row"><span class="legend-dot write"></span> Schreiben live</div>
<div class="legend-row"><span class="legend-dot review"></span> Bewerten live</div>
</div>
</div>
@@ -430,6 +433,7 @@ let graphState = {
loadedEngrams: 0,
lastModified: null,
liveFeed: [],
activityById: new Map(),
lastFrameAt: 0,
};
@@ -440,10 +444,13 @@ function _graphResizeCanvas() {
const canvas = _graphCanvas();
if (!canvas) return;
const availableW = Math.max(320, canvas.parentElement.clientWidth - 24);
const availableH = Math.max(360, (window.innerHeight || 900) - 250);
const size = Math.max(320, Math.min(availableW, availableH, 920));
canvas.width = size;
canvas.height = size;
const availableH = Math.max(380, (window.innerHeight || 900) - 250);
const width = Math.max(320, Math.min(availableW, 1180));
const height = Math.max(380, Math.min(availableH, Math.round(width * 0.62), 760));
canvas.width = width;
canvas.height = height;
canvas.style.width = `${width}px`;
canvas.style.height = `${height}px`;
}
function _graphResetData() {
@@ -465,6 +472,7 @@ function _graphResetData() {
graphState.totalEngrams = 0;
graphState.loadedEngrams = 0;
graphState.lastModified = null;
graphState.activityById = new Map();
graphState.physicsOn = true;
graphState.panX = 0;
graphState.panY = 0;
@@ -642,6 +650,39 @@ function _graphPushLive(text) {
feed.innerHTML = graphState.liveFeed.map(x => `<div>${escapeHtml(x)}</div>`).join('');
}
function _graphActivityLabel(action) {
const labels = {
read: 'Lesen',
write: 'Schreiben',
write_link: 'Link',
review_confirm: 'Bewertet OK',
review_reject: 'Bewertet falsch',
score_refresh: 'Score',
};
return labels[action] || action || 'Aktivitaet';
}
function _graphApplyActivity(events) {
if (!Array.isArray(events) || !events.length) return;
let changed = false;
for (const ev of events) {
if (!ev || !ev.engram_id) continue;
const ts = Date.parse(ev.ts || '') || Date.now();
const prev = graphState.activityById.get(ev.engram_id);
if (prev && prev.ts >= ts && prev.action === ev.action) continue;
graphState.activityById.set(ev.engram_id, {action: ev.action, ts, detail: ev.detail || ''});
const n = graphState.simById.get(ev.engram_id);
if (n) {
n.activity = ev.action;
n.activityTs = ts;
n.modifiedMs = Math.max(n.modifiedMs || 0, ts);
}
_graphPushLive(`${_graphActivityLabel(ev.action)} ${String(ev.engram_id).slice(0, 8)}${ev.detail ? ' · ' + ev.detail.slice(0, 52) : ''}`);
changed = true;
}
if (changed) _graphDraw();
}
function _graphNodeRadius(n) {
const d = graphState.degree.get(n.id) || 0;
const huge = graphState.sim.length > 20000;
@@ -659,6 +700,14 @@ function _graphVisualRadius(n) {
function _graphNodeFill(n) {
const d = graphState.degree.get(n.id) || 0;
const activity = graphState.activityById.get(n.id);
if (activity && graphState.drawNow - activity.ts < 90000) {
if (activity.action === 'read') return 'rgb(56,189,248)';
if (activity.action === 'write' || activity.action === 'write_link') return 'rgb(74,222,128)';
if (activity.action === 'review_confirm') return 'rgb(167,243,208)';
if (activity.action === 'review_reject') return 'rgb(248,113,113)';
if (activity.action === 'score_refresh') return 'rgb(250,204,21)';
}
const t = Math.max(0, Math.min(0.55, d / 18)); // higher degree -> brighter
const mix = (rgb) => rgb.map(c => Math.round(c + (255 - c) * t));
@@ -1200,17 +1249,10 @@ function _graphDraw() {
const hint = document.getElementById('graphHint');
ctx.clearRect(0,0,canvas.width,canvas.height);
const cx = canvas.width / 2;
const cy = canvas.height / 2;
const viewR = Math.min(canvas.width, canvas.height) / 2 - 3;
ctx.save();
ctx.beginPath();
ctx.arc(cx, cy, viewR, 0, Math.PI * 2);
ctx.clip();
const bg = ctx.createRadialGradient(canvas.width * 0.52, canvas.height * 0.48, 10, cx, cy, viewR);
bg.addColorStop(0, '#121a2b');
bg.addColorStop(0.55, '#070b16');
bg.addColorStop(1, '#02040a');
const bg = ctx.createLinearGradient(0, 0, canvas.width, canvas.height);
bg.addColorStop(0, '#0c1422');
bg.addColorStop(0.48, '#070b16');
bg.addColorStop(1, '#030712');
ctx.fillStyle = bg;
ctx.fillRect(0, 0, canvas.width, canvas.height);
graphState.drawNow = Date.now();
@@ -1243,6 +1285,8 @@ function _graphDraw() {
for (const n of graphState.sim) {
const r = _graphVisualRadius(n);
const isMatch = _graphMatches(n, term);
const activity = graphState.activityById.get(n.id);
const activeAge = activity ? graphState.drawNow - activity.ts : Infinity;
if (isMatch) matches++;
if (isMatch) {
@@ -1262,7 +1306,7 @@ function _graphDraw() {
}
const fill = _graphNodeFill(n);
const important = n.kind !== 'engram' || isMatch || graphState.selectedId === n.id || ((graphState.drawNow - (n.modifiedMs || n.createdMs || 0)) < 10 * 60 * 1000);
const important = n.kind !== 'engram' || isMatch || graphState.selectedId === n.id || activeAge < 90000 || ((graphState.drawNow - (n.modifiedMs || n.createdMs || 0)) < 10 * 60 * 1000);
if (important) {
ctx.save();
ctx.shadowColor = fill;
@@ -1302,17 +1346,23 @@ function _graphDraw() {
ctx.arc(n.x, n.y, r + 0.8, 0, Math.PI*2);
ctx.stroke();
}
if (activity && activeAge < 90000) {
const pulse = 1 + Math.sin(graphState.drawNow / 180) * 0.18;
ctx.beginPath();
ctx.strokeStyle = activity.action === 'read' ? '#38bdf8' : (activity.action && activity.action.startsWith('review') ? '#f7d154' : '#4ade80');
ctx.globalAlpha = Math.max(0.12, 1 - activeAge / 90000);
ctx.lineWidth = 2.2 / graphState.zoom;
ctx.arc(n.x, n.y, r + 6 * pulse, 0, Math.PI*2);
ctx.stroke();
ctx.globalAlpha = 1.0;
}
}
ctx.restore();
ctx.restore();
ctx.save();
ctx.beginPath();
ctx.arc(cx, cy, viewR, 0, Math.PI * 2);
ctx.strokeStyle = 'rgba(34, 211, 238, 0.05)';
ctx.lineWidth = 0.8;
ctx.stroke();
ctx.restore();
ctx.strokeStyle = 'rgba(34, 211, 238, 0.08)';
ctx.lineWidth = 1;
ctx.strokeRect(0.5, 0.5, canvas.width - 1, canvas.height - 1);
const loaded = graphState.totalEngrams ? ` | engrams=${graphState.loadedEngrams}/${graphState.totalEngrams}` : '';
hint.textContent = `nodes=${graphState.nodes.length} edges=${graphState.edges.length}${loaded}` + (term ? ` | match=${matches}` : '');
if (!graphState._lastInsightsAt || graphState.drawNow - graphState._lastInsightsAt > 1500) {
@@ -1393,12 +1443,17 @@ function startEvents() {
if (state.view === 'graph') {
const t = Date.now();
const stats = state.lastEvent.stats || {};
const jobs = state.lastEvent.jobs || {};
_graphPushLive(`Stats total=${stats.total ?? '-'} pending=${stats.pending ?? '-'} jobs=${Array.isArray(jobs.units) ? jobs.units.length : '-'}`);
if (!state._lastGraphDelta || (t - state._lastGraphDelta) > 5000) {
_graphApplyActivity(state.lastEvent.activity || []);
_graphPushLive(`Stats total=${stats.total ?? '-'} pending=${stats.pending ?? '-'}`);
if (!state._lastGraphDelta || (t - state._lastGraphDelta) > 2500) {
state._lastGraphDelta = t;
loadGraphChanges();
}
} else if (state.view === 'cards') {
if (!state._lastCardsEventRefresh || Date.now() - state._lastCardsEventRefresh > 8000) {
state._lastCardsEventRefresh = Date.now();
loadCards();
}
}
} catch (e) {}
};
@@ -1620,12 +1675,10 @@ document.getElementById('filterSelect').addEventListener('change', (e) => {
// ─── Auto Refresh ───────────────────────────────────────────────────────────
setInterval(() => {
if (!state.autoRefresh) return;
loadStats();
loadCards();
const now = new Date();
document.getElementById('lastUpdate').textContent =
`${now.getHours().toString().padStart(2,'0')}:${now.getMinutes().toString().padStart(2,'0')}`;
}, 5000);
}, 15000);
// ─── Init ───────────────────────────────────────────────────────────────────
loadStats();