knowmind 0.1.29 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +23 -0
- package/README.md +7 -0
- package/bin/knowmind.js +40 -0
- package/package.json +1 -1
- package/src/init.js +62 -3
- package/src/status.js +240 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,28 @@
|
|
|
1
1
|
# Knowmind CLI — Änderungen
|
|
2
2
|
|
|
3
|
+
## 0.3.0 (2026-07-16)
|
|
4
|
+
|
|
5
|
+
**`knowmind status`: Sitzungs-Zähler + sichtbares Flackern**
|
|
6
|
+
- Die Statusline zeigt jetzt, wie viele Erinnerungen in der laufenden Sitzung
|
|
7
|
+
abgerufen wurden — als eigenes, farblich hervorgehobenes Lebenszeichen.
|
|
8
|
+
- Die grüne LED flackert bei Aktivität jetzt sichtbar: `knowmind init --client
|
|
9
|
+
claude-code` richtet die Statusleiste mit periodischem Neuzeichnen ein
|
|
10
|
+
(Claude Code ab v2.1.97). Ohne das rendert Claude Code die Statusleiste nur
|
|
11
|
+
bei Ereignissen, sodass eine Animation nicht sichtbar würde.
|
|
12
|
+
|
|
13
|
+
## 0.2.0 (2026-07-16)
|
|
14
|
+
|
|
15
|
+
**Neu: `knowmind status` — sichtbares Lebenszeichen des Gedächtnisses**
|
|
16
|
+
- `knowmind status` zeigt einen kurzen Erreichbarkeits-Report (erreichbar,
|
|
17
|
+
Anzahl Erinnerungen und Beziehungen, Antwortzeit).
|
|
18
|
+
- `knowmind status --line` gibt eine einzeilige Statusline für Ihr KI-Werkzeug
|
|
19
|
+
aus: ruhig grün, wenn erreichbar; grünes Flackern wie eine Festplatten-LED,
|
|
20
|
+
während knowmind arbeitet; rot bei Ausfall (mit Selbst-Erholung). Die Anzeige
|
|
21
|
+
blockiert nie — Erreichbarkeit und Zahl werden gecacht, im Hintergrund
|
|
22
|
+
aufgefrischt.
|
|
23
|
+
- `knowmind init --client claude-code` bindet die Statusline automatisch ein.
|
|
24
|
+
Eine bereits vorhandene eigene Statusline bleibt unangetastet.
|
|
25
|
+
|
|
3
26
|
## 0.1.29 (2026-07-16)
|
|
4
27
|
|
|
5
28
|
- Verbesserungen der Stabilität und allgemeine Fehlerbehebungen.
|
package/README.md
CHANGED
|
@@ -40,9 +40,16 @@ knowmind search "Wo läuft die OKR-App?"
|
|
|
40
40
|
knowmind upload notizen.md --title "Meeting Notizen 2026-05-12"
|
|
41
41
|
knowmind stats
|
|
42
42
|
knowmind health
|
|
43
|
+
knowmind status Lebenszeichen des Gedächtnisses (Report)
|
|
44
|
+
knowmind status --line Einzeilige Statusline für Ihr KI-Werkzeug
|
|
43
45
|
knowmind config
|
|
44
46
|
```
|
|
45
47
|
|
|
48
|
+
Die Statusline (`knowmind status --line`) zeigt knowmind als grüne Lampe direkt in Ihrem
|
|
49
|
+
KI-Werkzeug: ruhig grün, wenn erreichbar, grünes Flackern wie eine Festplatten-LED, während
|
|
50
|
+
knowmind arbeitet, rot bei Ausfall. `knowmind init --client claude-code` bindet sie
|
|
51
|
+
automatisch ein (eine bereits vorhandene eigene Statusline bleibt unangetastet).
|
|
52
|
+
|
|
46
53
|
## Automatische Pflege einrichten (`knowmind init`)
|
|
47
54
|
|
|
48
55
|
Damit Ihre KI knowmind selbsttätig pflegt — **Recall vor jeder Aufgabe**, **Sichern nach
|
package/bin/knowmind.js
CHANGED
|
@@ -25,6 +25,7 @@ import { runStdioServer } from "../src/mcp-stdio.js";
|
|
|
25
25
|
import { syncDirectory } from "../src/sync.js";
|
|
26
26
|
import { runInit } from "../src/init.js";
|
|
27
27
|
import { runInstall } from "../src/install.js";
|
|
28
|
+
import { renderLine, renderFull, probe } from "../src/status.js";
|
|
28
29
|
|
|
29
30
|
const args = process.argv.slice(2);
|
|
30
31
|
const cmd = args[0];
|
|
@@ -65,6 +66,11 @@ Befehle:
|
|
|
65
66
|
Content-Hash, Manifest in <dir>/.knowmind-manifest.json.
|
|
66
67
|
knowmind stats Memory- und Edge-Counter des Tenants
|
|
67
68
|
knowmind health Health-Check der Plattform
|
|
69
|
+
knowmind status [--line]
|
|
70
|
+
Lebenszeichen des Gedächtnisses. Ohne Flag: Report.
|
|
71
|
+
--line: einzeilige Statusline (grüne HDD-LED, flackert
|
|
72
|
+
bei Aktivität, rot bei Ausfall) — für die Statusline
|
|
73
|
+
eines KI-Werkzeugs, z. B. Claude Code.
|
|
68
74
|
knowmind mcp Stdio-MCP-Server für lokale AI-Clients
|
|
69
75
|
knowmind install <ide> [--project] [--print] [--token T] [--api URL]
|
|
70
76
|
knowmind als MCP-Server in eine IDE eintragen
|
|
@@ -233,6 +239,37 @@ async function runConfig() {
|
|
|
233
239
|
console.log(`Token: ${c.token ? c.token.slice(0, 12) + "…" : "(keiner)"}`);
|
|
234
240
|
}
|
|
235
241
|
|
|
242
|
+
async function runStatus() {
|
|
243
|
+
// --probe: interner Hintergrund-Refresh der Status-Caches (nicht blockierend
|
|
244
|
+
// für die Statusline). --line: einzeilige, gefärbte Ausgabe für die Statusline
|
|
245
|
+
// eines KI-Werkzeugs. Ohne Flag: menschenlesbarer Mehrzeilen-Report.
|
|
246
|
+
if (args.includes("--probe")) {
|
|
247
|
+
await probe();
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
250
|
+
if (args.includes("--line")) {
|
|
251
|
+
// Claude Code reicht der Statusline ein JSON per stdin (u. a. session_id).
|
|
252
|
+
// Non-blocking mit kurzem Timeout lesen — bei manuellem Aufruf ohne stdin
|
|
253
|
+
// darf nichts hängen. session_id ergibt den Sitzungs-Recall-Zähler.
|
|
254
|
+
let sessionId = "";
|
|
255
|
+
try {
|
|
256
|
+
const raw = await Promise.race([
|
|
257
|
+
readStdin(),
|
|
258
|
+
new Promise((r) => setTimeout(() => r(""), 80)),
|
|
259
|
+
]);
|
|
260
|
+
if (raw && raw.trim().startsWith("{")) {
|
|
261
|
+
const d = JSON.parse(raw);
|
|
262
|
+
sessionId = d.session_id || d.sessionId || "";
|
|
263
|
+
}
|
|
264
|
+
} catch {
|
|
265
|
+
/* kein/kaputtes stdin — ohne Session weiter */
|
|
266
|
+
}
|
|
267
|
+
process.stdout.write(renderLine(sessionId));
|
|
268
|
+
return;
|
|
269
|
+
}
|
|
270
|
+
console.log(await renderFull());
|
|
271
|
+
}
|
|
272
|
+
|
|
236
273
|
async function runInitCmd() {
|
|
237
274
|
const client = parseFlag("--client", "auto");
|
|
238
275
|
const dryRun = args.includes("--dry-run");
|
|
@@ -294,6 +331,9 @@ try {
|
|
|
294
331
|
case "health":
|
|
295
332
|
await runHealth();
|
|
296
333
|
break;
|
|
334
|
+
case "status":
|
|
335
|
+
await runStatus();
|
|
336
|
+
break;
|
|
297
337
|
case "mcp":
|
|
298
338
|
await runStdioServer();
|
|
299
339
|
break;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "knowmind",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"mcpName": "io.github.Schubeler-Consulting/knowmind",
|
|
5
5
|
"description": "Knowmind — das Agentengehirn aus Deutschland: CLI + MCP-Server (Langzeitgedächtnis & Wissensgraph für Ihre KI, Server in Deutschland).",
|
|
6
6
|
"type": "module",
|
package/src/init.js
CHANGED
|
@@ -154,10 +154,43 @@ function autoRecallHookSource() {
|
|
|
154
154
|
// npx-Kaltstart; und es gibt KEINE Command-Injection, weil die Nutzer-Frage als
|
|
155
155
|
// JSON-Body und nicht als Shell-Argument übergeben wird. Fail-open: jeder
|
|
156
156
|
// Fehler / fehlendes Token -> exit 0 ohne Ausgabe, blockiert nie.
|
|
157
|
-
import { readFileSync } from "node:fs";
|
|
157
|
+
import { readFileSync, writeFileSync, mkdirSync, readdirSync, statSync, unlinkSync } from "node:fs";
|
|
158
158
|
import { homedir } from "node:os";
|
|
159
159
|
import { join } from "node:path";
|
|
160
160
|
|
|
161
|
+
// Stempelt den Aktivitäts-Zeitpunkt für die knowmind-Statusline (grüne
|
|
162
|
+
// HDD-LED). Best-effort, darf den Recall nie brechen.
|
|
163
|
+
function markActivity() {
|
|
164
|
+
try {
|
|
165
|
+
mkdirSync(join(homedir(), ".knowmind"), { recursive: true });
|
|
166
|
+
writeFileSync(join(homedir(), ".knowmind", "activity"), String(Date.now()));
|
|
167
|
+
} catch {}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// Zählt pro Claude-Code-Session die abgerufenen Erinnerungen. Die Statusline
|
|
171
|
+
// zeigt „N abgerufen" für die laufende Sitzung. Best-effort.
|
|
172
|
+
function bumpSessionRecalls(sessionId, hits) {
|
|
173
|
+
if (!sessionId || !(hits > 0)) return;
|
|
174
|
+
try {
|
|
175
|
+
const d = join(homedir(), ".knowmind", "sessions");
|
|
176
|
+
mkdirSync(d, { recursive: true });
|
|
177
|
+
const now = Date.now();
|
|
178
|
+
for (const fn of readdirSync(d)) {
|
|
179
|
+
try {
|
|
180
|
+
if (now - statSync(join(d, fn)).mtimeMs > 86400000) unlinkSync(join(d, fn));
|
|
181
|
+
} catch {}
|
|
182
|
+
}
|
|
183
|
+
const safe = String(sessionId).replace(/[^a-zA-Z0-9_-]/g, "").slice(0, 80);
|
|
184
|
+
const p = join(d, safe + ".json");
|
|
185
|
+
let cur = {};
|
|
186
|
+
try { cur = JSON.parse(readFileSync(p, "utf-8")); } catch {}
|
|
187
|
+
cur.recalls = (cur.recalls || 0) + 1;
|
|
188
|
+
cur.memories = (cur.memories || 0) + hits;
|
|
189
|
+
cur.updated = now;
|
|
190
|
+
writeFileSync(p, JSON.stringify(cur));
|
|
191
|
+
} catch {}
|
|
192
|
+
}
|
|
193
|
+
|
|
161
194
|
const TRIVIAL = new Set([
|
|
162
195
|
"ok","okay","go","ja","nein","weiter","stop","danke","thanks","thx",
|
|
163
196
|
"yes","no","yep","nope","perfekt","passt","super","gut",
|
|
@@ -237,14 +270,17 @@ async function main() {
|
|
|
237
270
|
process.stdin.setEncoding("utf-8");
|
|
238
271
|
for await (const c of process.stdin) raw += c;
|
|
239
272
|
let prompt = "";
|
|
273
|
+
let sessionId = "";
|
|
240
274
|
try {
|
|
241
275
|
const data = raw ? JSON.parse(raw) : {};
|
|
242
276
|
prompt = data.prompt || data.user_prompt || data.user_message || "";
|
|
277
|
+
sessionId = data.session_id || data.sessionId || "";
|
|
243
278
|
} catch { return; }
|
|
244
279
|
if (!shouldRecall(prompt)) return;
|
|
245
280
|
|
|
246
281
|
const { apiUrl, token } = loadCreds();
|
|
247
282
|
if (!token) return;
|
|
283
|
+
markActivity();
|
|
248
284
|
const query = prompt.trim().slice(0, 500);
|
|
249
285
|
|
|
250
286
|
const ctrl = new AbortController();
|
|
@@ -269,6 +305,7 @@ async function main() {
|
|
|
269
305
|
|
|
270
306
|
const hits = formatHits(rpc);
|
|
271
307
|
if (!hits) return;
|
|
308
|
+
bumpSessionRecalls(sessionId, (hits.match(/^• /gm) || []).length);
|
|
272
309
|
|
|
273
310
|
process.stdout.write(
|
|
274
311
|
"═════════ knowmind RECALL (auto) ═════════\\n" +
|
|
@@ -492,11 +529,33 @@ function planClaudeCode(cwd) {
|
|
|
492
529
|
const relCapture = ".claude/hooks/knowmind_capture.mjs";
|
|
493
530
|
const m1 = ensureClaudeHookEntry(settings, "UserPromptSubmit", relRecall);
|
|
494
531
|
const m2 = ensureClaudeHookEntry(settings, "Stop", relCapture);
|
|
532
|
+
// Statusline: knowmind-Lebenszeichen (grüne HDD-LED). NUR setzen, wenn
|
|
533
|
+
// keine existiert oder sie bereits auf knowmind zeigt — eine fremde
|
|
534
|
+
// Statusline des Nutzers wird NIE gekapert.
|
|
535
|
+
// refreshInterval: Claude Code rendert die Statusline sonst nur bei
|
|
536
|
+
// Ereignissen — damit die grüne LED bei Aktivität sichtbar flackert, muss
|
|
537
|
+
// sie periodisch neu gezeichnet werden (Claude Code >= 2.1.97, Min. 500 ms).
|
|
538
|
+
const km = { type: "command", command: "knowmind status --line", refreshInterval: 500 };
|
|
539
|
+
let m3 = false;
|
|
540
|
+
const existing = settings.statusLine;
|
|
541
|
+
const isKnowmind =
|
|
542
|
+
existing && typeof existing.command === "string" && existing.command.includes("knowmind status");
|
|
543
|
+
if (!existing) {
|
|
544
|
+
settings.statusLine = km;
|
|
545
|
+
m3 = true;
|
|
546
|
+
} else if (isKnowmind && (existing.command !== km.command || existing.refreshInterval !== 500)) {
|
|
547
|
+
settings.statusLine = km;
|
|
548
|
+
m3 = true;
|
|
549
|
+
}
|
|
495
550
|
actions.push({
|
|
496
|
-
label: "Claude-Code settings.json (
|
|
551
|
+
label: "Claude-Code settings.json (Hooks + Statusline)",
|
|
497
552
|
path: settingsPath,
|
|
498
|
-
action: m1 || m2 ? (existsSync(settingsPath) ? "patch" : "create") : "unchanged",
|
|
553
|
+
action: m1 || m2 || m3 ? (existsSync(settingsPath) ? "patch" : "create") : "unchanged",
|
|
499
554
|
content: JSON.stringify(settings, null, 2) + "\n",
|
|
555
|
+
_note:
|
|
556
|
+
existing && !isKnowmind
|
|
557
|
+
? "Eigene Statusline erkannt — nicht überschrieben. Manuell einbinden: knowmind status --line"
|
|
558
|
+
: undefined,
|
|
500
559
|
});
|
|
501
560
|
}
|
|
502
561
|
|
package/src/status.js
ADDED
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* knowmind status — sichtbares Lebenszeichen des Gedächtnisses.
|
|
3
|
+
*
|
|
4
|
+
* Zwei Ausgaben:
|
|
5
|
+
* renderFull() → mehrzeilig, menschenlesbar (`knowmind status`)
|
|
6
|
+
* renderLine() → einzeilig, gefärbt, für die Statusline eines KI-Werkzeugs
|
|
7
|
+
* (`knowmind status --line`, z. B. Claude-Code statusLine)
|
|
8
|
+
*
|
|
9
|
+
* Die Statusline wird oft gerendert und darf NIE blockieren. Deshalb:
|
|
10
|
+
* - Erreichbarkeit + Erinnerungszahl liegen in Cache-Dateien unter ~/.knowmind.
|
|
11
|
+
* - Ist der Cache abgelaufen, wird ein LOSGELÖSTER Hintergrund-Probe gestartet
|
|
12
|
+
* (`knowmind status --probe`), der den Cache auffrischt (stale-while-revalidate).
|
|
13
|
+
* - Läuft knowmind gerade (Recall in den letzten Sekunden — der init-Recall-Hook
|
|
14
|
+
* stempelt ~/.knowmind/activity), blinkt die Anzeige.
|
|
15
|
+
*/
|
|
16
|
+
import { spawn } from "node:child_process";
|
|
17
|
+
import { existsSync, readFileSync, writeFileSync, statSync, mkdirSync } from "node:fs";
|
|
18
|
+
import { homedir } from "node:os";
|
|
19
|
+
import { join, dirname } from "node:path";
|
|
20
|
+
import { fileURLToPath } from "node:url";
|
|
21
|
+
import { loadConfig } from "./config.js";
|
|
22
|
+
import { health, stats } from "./client.js";
|
|
23
|
+
|
|
24
|
+
const KM_DIR = join(homedir(), ".knowmind");
|
|
25
|
+
const HEALTH_CACHE = join(KM_DIR, "status-health.json");
|
|
26
|
+
const COUNT_CACHE = join(KM_DIR, "status-count.json");
|
|
27
|
+
const ACTIVITY = join(KM_DIR, "activity");
|
|
28
|
+
|
|
29
|
+
const HEALTH_TTL_OK = 30_000; // erreichbar → alle 30 s neu prüfen
|
|
30
|
+
const HEALTH_TTL_FAIL = 15_000; // gestört → alle 15 s (schnellere Erholung)
|
|
31
|
+
const PROBE_GUARD = 12_000; // kein zweiter Hintergrund-Probe innerhalb 12 s
|
|
32
|
+
const COUNT_TTL = 900_000; // Erinnerungszahl: 15 min
|
|
33
|
+
const ACTIVE_MS = 15_000; // Recall jünger als 15 s → „arbeitet"
|
|
34
|
+
|
|
35
|
+
// ANSI (dezent). NO_COLOR respektieren.
|
|
36
|
+
const useColor = !process.env.NO_COLOR;
|
|
37
|
+
const c = (code, s) => (useColor ? `[${code}m${s}[0m` : s);
|
|
38
|
+
const green = (s) => c("32", s);
|
|
39
|
+
const brightGreen = (s) => c("92", s);
|
|
40
|
+
const dimGreen = (s) => c("2;32", s);
|
|
41
|
+
const red = (s) => c("31", s);
|
|
42
|
+
const dim = (s) => c("2", s);
|
|
43
|
+
const kmBlue = (s) => c("38;5;111", s); // ≈ knowmind-Blau #6ea8ff (Session-Akzent)
|
|
44
|
+
|
|
45
|
+
/** Abgerufene Erinnerungen in DIESER Claude-Code-Session (null wenn keine). */
|
|
46
|
+
function sessionRecalls(sessionId) {
|
|
47
|
+
if (!sessionId) return null;
|
|
48
|
+
const safe = String(sessionId).replace(/[^a-zA-Z0-9_-]/g, "").slice(0, 80);
|
|
49
|
+
const data = readJson(join(KM_DIR, "sessions", safe + ".json"));
|
|
50
|
+
return data && data.memories > 0 ? data.memories : null;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Grüne Festplatten-LED: bei Aktivität flackert das ●-Zeichen unregelmäßig
|
|
55
|
+
* zwischen hell- und dunkelgrün (nicht im gleichmäßigen Takt). Die Statusline
|
|
56
|
+
* wird bei Arbeit häufig neu gerendert — das bit-gemischte Zeit-Muster erzeugt
|
|
57
|
+
* dabei das nervöse HDD-Flackern statt eines sauberen Blinkens.
|
|
58
|
+
*/
|
|
59
|
+
function flickerLed() {
|
|
60
|
+
const t = Date.now();
|
|
61
|
+
const on = (((t >> 6) ^ (t >> 4) ^ (t >> 8)) & 1) === 1;
|
|
62
|
+
return on ? brightGreen("●") : dimGreen("●");
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function readJson(path) {
|
|
66
|
+
try {
|
|
67
|
+
return JSON.parse(readFileSync(path, "utf-8"));
|
|
68
|
+
} catch {
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function writeJson(path, obj) {
|
|
74
|
+
try {
|
|
75
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
76
|
+
writeFileSync(path, JSON.stringify(obj), "utf-8");
|
|
77
|
+
} catch {
|
|
78
|
+
/* best effort */
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function fmtCount(n) {
|
|
83
|
+
return String(n).replace(/\B(?=(\d{3})+(?!\d))/g, ".");
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** Sekunden-genaue mtime von ~/.knowmind/activity (0 wenn nicht vorhanden). */
|
|
87
|
+
function activityAgeMs() {
|
|
88
|
+
try {
|
|
89
|
+
return Date.now() - statSync(ACTIVITY).mtimeMs;
|
|
90
|
+
} catch {
|
|
91
|
+
return Infinity;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** Stempelt den Aktivitäts-Zeitpunkt. Wird vom Recall-Hook aufgerufen. */
|
|
96
|
+
export function markActivity() {
|
|
97
|
+
try {
|
|
98
|
+
mkdirSync(KM_DIR, { recursive: true });
|
|
99
|
+
writeFileSync(ACTIVITY, String(Date.now()), "utf-8");
|
|
100
|
+
} catch {
|
|
101
|
+
/* best effort */
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** Interner Probe-Modus: Health + Zahl frisch holen, Cache schreiben. */
|
|
106
|
+
export async function probe() {
|
|
107
|
+
const t0 = Date.now();
|
|
108
|
+
try {
|
|
109
|
+
const h = await health();
|
|
110
|
+
const ok = String(h?.status ?? "").toLowerCase() === "ok";
|
|
111
|
+
const prev = readJson(HEALTH_CACHE) || {};
|
|
112
|
+
writeJson(HEALTH_CACHE, {
|
|
113
|
+
ts: Date.now(),
|
|
114
|
+
ok,
|
|
115
|
+
latencyMs: Date.now() - t0,
|
|
116
|
+
downSince: ok ? null : prev.downSince || Date.now(),
|
|
117
|
+
probing: 0,
|
|
118
|
+
});
|
|
119
|
+
if (ok) {
|
|
120
|
+
try {
|
|
121
|
+
const s = await stats();
|
|
122
|
+
const n = s?.memories ?? s?.memory_count ?? s?.count ?? null;
|
|
123
|
+
if (n != null) writeJson(COUNT_CACHE, { ts: Date.now(), count: Number(n) });
|
|
124
|
+
} catch {
|
|
125
|
+
/* Zahl ist optional */
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
} catch {
|
|
129
|
+
const prev = readJson(HEALTH_CACHE) || {};
|
|
130
|
+
writeJson(HEALTH_CACHE, {
|
|
131
|
+
ts: Date.now(),
|
|
132
|
+
ok: false,
|
|
133
|
+
latencyMs: 0,
|
|
134
|
+
downSince: prev.downSince || Date.now(),
|
|
135
|
+
probing: 0,
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/** Losgelösten Hintergrund-Probe starten (blockiert die Statusline nie). */
|
|
141
|
+
function spawnProbe() {
|
|
142
|
+
try {
|
|
143
|
+
const self = fileURLToPath(new URL("../bin/knowmind.js", import.meta.url));
|
|
144
|
+
const child = spawn(process.execPath, [self, "status", "--probe"], {
|
|
145
|
+
detached: true,
|
|
146
|
+
stdio: "ignore",
|
|
147
|
+
});
|
|
148
|
+
child.unref();
|
|
149
|
+
} catch {
|
|
150
|
+
/* best effort */
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/** Erreichbarkeits-Zustand aus Cache; stößt bei Ablauf einen Refresh an. */
|
|
155
|
+
function healthState() {
|
|
156
|
+
const cache = readJson(HEALTH_CACHE);
|
|
157
|
+
const now = Date.now();
|
|
158
|
+
if (!cache) {
|
|
159
|
+
// Allererster Aufruf: einmal im Hintergrund prüfen, vorerst „unbekannt".
|
|
160
|
+
spawnProbe();
|
|
161
|
+
return { ok: null, ts: 0 };
|
|
162
|
+
}
|
|
163
|
+
const ttl = cache.ok ? HEALTH_TTL_OK : HEALTH_TTL_FAIL;
|
|
164
|
+
if (now - (cache.ts || 0) > ttl && now - (cache.probing || 0) > PROBE_GUARD) {
|
|
165
|
+
cache.probing = now;
|
|
166
|
+
writeJson(HEALTH_CACHE, cache);
|
|
167
|
+
spawnProbe();
|
|
168
|
+
}
|
|
169
|
+
return cache;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
function hhmm(ts) {
|
|
173
|
+
try {
|
|
174
|
+
return new Date(ts).toLocaleTimeString("de-DE", { hour: "2-digit", minute: "2-digit" });
|
|
175
|
+
} catch {
|
|
176
|
+
return "?";
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/** Einzeilige Statusline-Ausgabe. Flackert bei Aktivität, erholt sich selbst.
|
|
181
|
+
* sessionId (optional): zeigt „N abgerufen" für die laufende Claude-Code-Sitzung. */
|
|
182
|
+
export function renderLine(sessionId) {
|
|
183
|
+
if (!loadConfig().token && !process.env.KNOWMIND_TOKEN) {
|
|
184
|
+
return dim("○ knowmind · nicht angemeldet");
|
|
185
|
+
}
|
|
186
|
+
const h = healthState();
|
|
187
|
+
const sep = " " + dim("·") + " ";
|
|
188
|
+
|
|
189
|
+
if (h.ok === false) {
|
|
190
|
+
const since = h.downSince ? ` (seit ${hhmm(h.downSince)})` : "";
|
|
191
|
+
return `${red("●")} ${dim(`knowmind · nicht erreichbar${since}`)}`;
|
|
192
|
+
}
|
|
193
|
+
if (h.ok == null) {
|
|
194
|
+
return `${dimGreen("●")} ${dim("knowmind · prüfe …")}`;
|
|
195
|
+
}
|
|
196
|
+
// Session-Zähler = Lebenszeichen dieser Sitzung (knowmind-Blau, auffällig).
|
|
197
|
+
const sess = sessionRecalls(sessionId);
|
|
198
|
+
const sessTxt = sess ? kmBlue(`${fmtCount(sess)} abgerufen`) : null;
|
|
199
|
+
|
|
200
|
+
// erreichbar: bei Aktivität grünes HDD-Flackern, sonst ruhig leuchtend grün
|
|
201
|
+
if (activityAgeMs() <= ACTIVE_MS) {
|
|
202
|
+
return `${flickerLed()} ${dim("knowmind arbeitet")}` + (sessTxt ? sep + sessTxt : "");
|
|
203
|
+
}
|
|
204
|
+
let tail = sessTxt;
|
|
205
|
+
if (!tail) {
|
|
206
|
+
const cnt = readJson(COUNT_CACHE);
|
|
207
|
+
tail = cnt?.count != null ? dim(`${fmtCount(cnt.count)} gespeichert`) : null;
|
|
208
|
+
}
|
|
209
|
+
return `${green("●")} ${dim("knowmind")}` + (tail ? sep + tail : "");
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/** Mehrzeilige, menschenlesbare Ausgabe (`knowmind status`). */
|
|
213
|
+
export async function renderFull() {
|
|
214
|
+
if (!loadConfig().token && !process.env.KNOWMIND_TOKEN) {
|
|
215
|
+
return "knowmind: nicht angemeldet — `knowmind login --token kmt_…` ausführen.";
|
|
216
|
+
}
|
|
217
|
+
const t0 = Date.now();
|
|
218
|
+
try {
|
|
219
|
+
const h = await health();
|
|
220
|
+
const ok = String(h?.status ?? "").toLowerCase() === "ok";
|
|
221
|
+
const ms = Date.now() - t0;
|
|
222
|
+
if (!ok) return red("● knowmind nicht erreichbar.");
|
|
223
|
+
let line = green("● knowmind erreichbar") + dim(` · ${ms} ms`);
|
|
224
|
+
try {
|
|
225
|
+
const s = await stats();
|
|
226
|
+
const n = s?.memories ?? s?.memory_count ?? s?.count;
|
|
227
|
+
const e = s?.edges;
|
|
228
|
+
if (n != null) line += `\n Erinnerungen: ${fmtCount(Number(n))}`;
|
|
229
|
+
if (e != null) line += `\n Beziehungen: ${fmtCount(Number(e))}`;
|
|
230
|
+
if (s?.memoryLimit != null) line += dim(`\n Tarif-Limit: ${fmtCount(Number(s.memoryLimit))}`);
|
|
231
|
+
} catch {
|
|
232
|
+
/* Zahl optional */
|
|
233
|
+
}
|
|
234
|
+
// Cache gleich mitschreiben, damit die Statusline sofort frisch ist.
|
|
235
|
+
await probe();
|
|
236
|
+
return line;
|
|
237
|
+
} catch (e) {
|
|
238
|
+
return red(`● knowmind nicht erreichbar: ${e.message}`);
|
|
239
|
+
}
|
|
240
|
+
}
|