knowmind 0.1.20 → 0.1.22

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 CHANGED
@@ -1,5 +1,36 @@
1
1
  # Knowmind CLI — Änderungen
2
2
 
3
+ ## 0.1.22 (2026-06-11)
4
+
5
+ **Discovery-Modus ohne Token (Introspection-fähig)**
6
+ - Ist KEIN Token konfiguriert, beantwortet `knowmind mcp` jetzt `initialize`,
7
+ `tools/list` und `prompts/list` über die ÖFFENTLICHE Server-Discovery
8
+ (`GET /api/mcp/v1` — liefert Name, Version und alle Tool-Definitionen ohne
9
+ Auth). Vorher schlugen ohne Token ALLE Requests inkl. `initialize` mit
10
+ `-32001` fehl — Verzeichnis-Crawler (z. B. Glama) konnten den Server nicht
11
+ inspizieren.
12
+ - `tools/call` verlangt weiterhin einen Token und verweist klar auf
13
+ `knowmind login`. Ein konfigurierter, aber ungültiger Token führt unverändert
14
+ zum harten Verbindungsfehler (kein falsches „connected ✓").
15
+ - Neu: `Dockerfile` im Repo (node:20-alpine, `knowmind mcp` als Entrypoint) —
16
+ für Container-basierte Inspection/Nutzung.
17
+
18
+ ## 0.1.21 (2026-06-10)
19
+
20
+ **Bugfix: `knowmind init`-Recall-Hook funktioniert jetzt auf Windows**
21
+ - Der von `knowmind init --client claude-code` erzeugte Recall-Hook rief die Plattform
22
+ bisher über einen Subprozess auf (`spawnSync("npx.cmd", …)`). Auf Windows mit Node
23
+ ≥ 18.20.2/20.12/21.6/22 wirft das `EINVAL` (Node-Härtung CVE-2024-27980 gegen das
24
+ direkte Spawnen von `.cmd`/`.bat` ohne Shell) — der Hook feuerte dort nie. Gefunden im
25
+ echten Claude-Code-Realtest.
26
+ - Fix: Der Hook ruft die Plattform jetzt per **direktem HTTPS-Call** (`fetch` gegen
27
+ `/api/mcp/v1`, `tools/call knowmind_recall`) auf — kein Subprozess, kein npx-Kaltstart
28
+ (Timeout 6 s, schneller), und **keine Command-Injection** mehr, weil die Nutzer-Frage
29
+ als JSON-Body statt als Shell-Argument übergeben wird. Token/apiUrl aus ENV oder
30
+ `~/.knowmind/config.json`. Treffer werden lesbar verdichtet ausgegeben (Titel + Score +
31
+ Auszug). Weiterhin fail-open (jeder Fehler/kein Token → exit 0). SSE- und Plain-JSON-
32
+ Antworten werden robust geparst.
33
+
3
34
  ## 0.1.20 (2026-06-10)
4
35
 
5
36
  **MCP-`instructions` erreichen jetzt den Client (initialize wird durchgereicht)**
package/package.json CHANGED
@@ -1,61 +1,61 @@
1
- {
2
- "name": "knowmind",
3
- "version": "0.1.20",
4
- "mcpName": "io.github.Schubeler-Consulting/knowmind",
5
- "description": "Knowmind — das Agentengehirn aus Deutschland: CLI + MCP-Server (Langzeitgedächtnis & Wissensgraph für Ihre KI, Server in Deutschland).",
6
- "type": "module",
7
- "license": "Apache-2.0",
8
- "homepage": "https://knowmind.de",
9
- "repository": {
10
- "type": "git",
11
- "url": "git+https://github.com/Schubeler-Consulting/knowmind.git"
12
- },
13
- "bugs": {
14
- "url": "https://knowmind.de/support",
15
- "email": "info@schuebeler-consulting.de"
16
- },
17
- "author": {
18
- "name": "Knowmind",
19
- "email": "info@schuebeler-consulting.de",
20
- "url": "https://knowmind.de"
21
- },
22
- "engines": {
23
- "node": ">=20"
24
- },
25
- "bin": {
26
- "knowmind": "bin/knowmind.js"
27
- },
28
- "files": [
29
- "bin",
30
- "src",
31
- "!src/*.test.js",
32
- "README.md",
33
- "CHANGELOG.md",
34
- "LICENSE"
35
- ],
36
- "scripts": {
37
- "test": "node --test src/*.test.js"
38
- },
39
- "dependencies": {
40
- "@huggingface/transformers": "^3.5.0"
41
- },
42
- "overrides": {
43
- "global-agent": "^4.1.3"
44
- },
45
- "keywords": [
46
- "knowmind",
47
- "mcp",
48
- "model-context-protocol",
49
- "knowledge-graph",
50
- "recall",
51
- "memory",
52
- "rag",
53
- "claude",
54
- "openai",
55
- "anthropic",
56
- "ai"
57
- ],
58
- "publishConfig": {
59
- "access": "public"
60
- }
61
- }
1
+ {
2
+ "name": "knowmind",
3
+ "version": "0.1.22",
4
+ "mcpName": "io.github.Schubeler-Consulting/knowmind",
5
+ "description": "Knowmind — das Agentengehirn aus Deutschland: CLI + MCP-Server (Langzeitgedächtnis & Wissensgraph für Ihre KI, Server in Deutschland).",
6
+ "type": "module",
7
+ "license": "Apache-2.0",
8
+ "homepage": "https://knowmind.de",
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/Schubeler-Consulting/knowmind.git"
12
+ },
13
+ "bugs": {
14
+ "url": "https://knowmind.de/support",
15
+ "email": "info@schuebeler-consulting.de"
16
+ },
17
+ "author": {
18
+ "name": "Knowmind",
19
+ "email": "info@schuebeler-consulting.de",
20
+ "url": "https://knowmind.de"
21
+ },
22
+ "engines": {
23
+ "node": ">=20"
24
+ },
25
+ "bin": {
26
+ "knowmind": "bin/knowmind.js"
27
+ },
28
+ "files": [
29
+ "bin",
30
+ "src",
31
+ "!src/*.test.js",
32
+ "README.md",
33
+ "CHANGELOG.md",
34
+ "LICENSE"
35
+ ],
36
+ "scripts": {
37
+ "test": "node --test src/*.test.js"
38
+ },
39
+ "dependencies": {
40
+ "@huggingface/transformers": "^3.5.0"
41
+ },
42
+ "overrides": {
43
+ "global-agent": "^4.1.3"
44
+ },
45
+ "keywords": [
46
+ "knowmind",
47
+ "mcp",
48
+ "model-context-protocol",
49
+ "knowledge-graph",
50
+ "recall",
51
+ "memory",
52
+ "rag",
53
+ "claude",
54
+ "openai",
55
+ "anthropic",
56
+ "ai"
57
+ ],
58
+ "publishConfig": {
59
+ "access": "public"
60
+ }
61
+ }
package/src/init.js CHANGED
@@ -148,8 +148,15 @@ function autoRecallHookSource() {
148
148
  // Erzeugt von: knowmind init. Idempotent ersetzbar (trägt diesen Marker).
149
149
  //
150
150
  // Ruft vor jeder echten Frage knowmind_recall auf und injiziert die Top-Treffer
151
- // als zusätzlichen Kontext (stdout). Fail-open: jeder Fehler -> exit 0 ohne Block.
152
- import { spawnSync } from "node:child_process";
151
+ // als zusätzlichen Kontext (stdout). Direkter HTTPS-Call gegen die Plattform —
152
+ // KEIN Subprozess/npx: das vermeidet den Windows-.cmd-Spawn-Fehler (EINVAL bei
153
+ // spawn von npx.cmd ohne Shell, Node-Härtung CVE-2024-27980) und den langsamen
154
+ // npx-Kaltstart; und es gibt KEINE Command-Injection, weil die Nutzer-Frage als
155
+ // JSON-Body und nicht als Shell-Argument übergeben wird. Fail-open: jeder
156
+ // Fehler / fehlendes Token -> exit 0 ohne Ausgabe, blockiert nie.
157
+ import { readFileSync } from "node:fs";
158
+ import { homedir } from "node:os";
159
+ import { join } from "node:path";
153
160
 
154
161
  const TRIVIAL = new Set([
155
162
  "ok","okay","go","ja","nein","weiter","stop","danke","thanks","thx",
@@ -171,6 +178,60 @@ function shouldRecall(p) {
171
178
  return s.length >= 40;
172
179
  }
173
180
 
181
+ // Token + apiUrl: ENV hat Vorrang, sonst ~/.knowmind/config.json (gleiche
182
+ // Reihenfolge wie die CLI). Kein Token -> kein Recall (fail-open).
183
+ function loadCreds() {
184
+ let file = {};
185
+ try {
186
+ file = JSON.parse(readFileSync(join(homedir(), ".knowmind", "config.json"), "utf-8"));
187
+ } catch { /* keine/kaputte Config -> ENV/Default */ }
188
+ let apiUrl = process.env.KNOWMIND_API_URL || file.apiUrl || "https://knowmind.de";
189
+ if (apiUrl.endsWith("/")) apiUrl = apiUrl.slice(0, -1);
190
+ return { apiUrl, token: process.env.KNOWMIND_TOKEN || file.token || null };
191
+ }
192
+
193
+ // Antwort von /api/mcp/v1 ist Standard-SSE (data:-Frames) ODER plain JSON.
194
+ // Beides robust auf das JSON-RPC-Objekt mit result/error reduzieren.
195
+ function parseBody(raw) {
196
+ raw = (raw || "").trim();
197
+ if (!raw) return null;
198
+ if (raw.startsWith("{")) { try { return JSON.parse(raw); } catch { return null; } }
199
+ let found = null;
200
+ for (const lineRaw of raw.split("\\n")) {
201
+ const line = lineRaw.trim();
202
+ if (line.indexOf("data:") !== 0) continue;
203
+ try {
204
+ const obj = JSON.parse(line.slice(5).trim());
205
+ if (obj && (obj.result || obj.error)) found = obj;
206
+ } catch { /* nicht-JSON data-Zeile überspringen */ }
207
+ }
208
+ return found;
209
+ }
210
+
211
+ // knowmind_recall liefert result.content[].text = JSON-String mit hits[].
212
+ // Lesbar verdichten; bei Parse-Fehler den Rohtext durchreichen.
213
+ function formatHits(rpc) {
214
+ const c = rpc && rpc.result && rpc.result.content;
215
+ const text = Array.isArray(c)
216
+ ? c.filter((b) => b && b.type === "text" && b.text).map((b) => b.text).join("\\n").trim()
217
+ : "";
218
+ if (!text) return "";
219
+ try {
220
+ const o = JSON.parse(text);
221
+ if (Array.isArray(o.hits)) {
222
+ if (o.hits.length === 0) return "";
223
+ return o.hits.slice(0, 5).map((h, i) => {
224
+ const m = h.metadata || {};
225
+ const title = m.title || m.name || h.source || ("Treffer " + (i + 1));
226
+ const score = typeof h.score === "number" ? " (" + h.score.toFixed(2) + ")" : "";
227
+ const snip = String(h.content || "").replace(/\\s+/g, " ").trim().slice(0, 280);
228
+ return "• " + title + score + ": " + snip;
229
+ }).join("\\n");
230
+ }
231
+ } catch { /* kein hits-JSON -> Rohtext */ }
232
+ return text;
233
+ }
234
+
174
235
  async function main() {
175
236
  let raw = "";
176
237
  process.stdin.setEncoding("utf-8");
@@ -182,18 +243,36 @@ async function main() {
182
243
  } catch { return; }
183
244
  if (!shouldRecall(prompt)) return;
184
245
 
246
+ const { apiUrl, token } = loadCreds();
247
+ if (!token) return;
185
248
  const query = prompt.trim().slice(0, 500);
186
- const r = spawnSync(
187
- process.platform === "win32" ? "npx.cmd" : "npx",
188
- ["-y", "knowmind", "search", query, "-k", "5", "--hops", "2"],
189
- { encoding: "utf-8", timeout: 8000, env: process.env }
190
- );
191
- const out = (r.stdout || "").trim();
192
- if (!out || /Keine Treffer/.test(out)) return;
249
+
250
+ const ctrl = new AbortController();
251
+ const timer = setTimeout(() => ctrl.abort(), 6000);
252
+ let rpc = null;
253
+ try {
254
+ const res = await fetch(apiUrl + "/api/mcp/v1", {
255
+ method: "POST",
256
+ headers: {
257
+ "Authorization": "Bearer " + token,
258
+ "Content-Type": "application/json",
259
+ "Accept": "application/json, text/event-stream",
260
+ },
261
+ body: JSON.stringify({
262
+ jsonrpc: "2.0", id: 1, method: "tools/call",
263
+ params: { name: "knowmind_recall", arguments: { query, k: 5, hops: 2 } },
264
+ }),
265
+ signal: ctrl.signal,
266
+ });
267
+ rpc = parseBody(await res.text());
268
+ } catch { return; } finally { clearTimeout(timer); }
269
+
270
+ const hits = formatHits(rpc);
271
+ if (!hits) return;
193
272
 
194
273
  process.stdout.write(
195
274
  "═════════ knowmind RECALL (auto) ═════════\\n" +
196
- out + "\\n" +
275
+ hits + "\\n" +
197
276
  "Diese Treffer wurden automatisch vor deiner Antwort abgerufen.\\n" +
198
277
  "Erst hier prüfen, dann Dateien lesen / Web suchen.\\n" +
199
278
  "══════════════════════════════════════════\\n"
package/src/mcp-stdio.js CHANGED
@@ -19,6 +19,15 @@
19
19
  * tatsächlichen serverInfo/capabilities den Client erreichen. Bei Server-
20
20
  * Fehler/Offline fällt der Proxy auf einen lokalen Default zurück.
21
21
  *
22
+ * Seit 0.1.22 gibt es einen DISCOVERY-MODUS: Ist KEIN Token konfiguriert,
23
+ * beantwortet der Proxy `initialize`, `tools/list` und `prompts/list` über die
24
+ * ÖFFENTLICHE Server-Discovery (GET {apiUrl}/api/mcp/v1 — liefert Name, Version
25
+ * und alle Tool-Definitionen ohne Auth). Damit funktioniert Introspection
26
+ * (z. B. Verzeichnis-Crawler wie Glama) ohne Account; erst `tools/call`
27
+ * verlangt einen Token und verweist klar auf `knowmind login`. Ein
28
+ * konfigurierter, aber UNGÜLTIGER Token führt weiterhin zum harten
29
+ * Verbindungsfehler, damit MCP-Clients nicht fälschlich „connected" anzeigen.
30
+ *
22
31
  * Protokoll: stdio mit zeilenweise JSON (NDJSON-Style). Jedes Frame ist ein
23
32
  * vollständiges JSON-RPC-Objekt.
24
33
  */
@@ -75,6 +84,20 @@ function write(obj) {
75
84
  process.stdout.write(JSON.stringify(obj) + "\n");
76
85
  }
77
86
 
87
+ /**
88
+ * Öffentliche Server-Discovery (kein Auth nötig): GET {apiUrl}/api/mcp/v1
89
+ * liefert { name, version, protocolVersion, tools: [...] }. Grundlage des
90
+ * Discovery-Modus ohne Token.
91
+ */
92
+ async function fetchPublicDiscovery() {
93
+ const { apiUrl } = loadConfig();
94
+ const r = await fetch(`${apiUrl}/api/mcp/v1`, {
95
+ headers: { accept: "application/json" },
96
+ });
97
+ if (!r.ok) throw new Error(`Knowmind-Server: HTTP ${r.status}`);
98
+ return await r.json();
99
+ }
100
+
78
101
  /**
79
102
  * Probiert den konfigurierten Token gegen den Server. Liefert
80
103
  * { ok: true } oder { ok: false, reason: "..." }. Wird in der
@@ -142,10 +165,30 @@ async function probeAuth() {
142
165
  }
143
166
 
144
167
  export async function runStdioServer() {
145
- // Auth einmal am Start prüfen. Das Ergebnis cachen — der MCP-Client
146
- // soll sofort beim initialize wissen, ob die Verbindung wirklich steht.
147
- const auth = await probeAuth();
148
- if (!auth.ok) {
168
+ // Kein Token konfiguriert → Discovery-Modus: initialize/tools/list laufen
169
+ // über die öffentliche Server-Discovery, tools/call verlangt Login.
170
+ let discoveryMode = false;
171
+ try {
172
+ discoveryMode = !loadConfig().token;
173
+ } catch {
174
+ discoveryMode = true;
175
+ }
176
+
177
+ // Auth einmal am Start prüfen (nur wenn ein Token vorhanden ist). Das
178
+ // Ergebnis cachen — der MCP-Client soll sofort beim initialize wissen,
179
+ // ob die Verbindung wirklich steht.
180
+ const auth = discoveryMode
181
+ ? {
182
+ ok: false,
183
+ reason:
184
+ "Kein Knowmind-Token konfiguriert. Bitte `knowmind login` im Terminal ausführen.",
185
+ }
186
+ : await probeAuth();
187
+ if (discoveryMode) {
188
+ process.stderr.write(
189
+ "[knowmind] Kein Token — Discovery-Modus: initialize/tools/list öffentlich, tools/call erfordert `knowmind login`.\n",
190
+ );
191
+ } else if (!auth.ok) {
149
192
  process.stderr.write(`[knowmind] AUTH-FEHLER: ${auth.reason}\n`);
150
193
  }
151
194
 
@@ -169,6 +212,65 @@ export async function runStdioServer() {
169
212
  const isNotification = req.id === undefined && typeof req.method === "string" && req.method.startsWith("notifications/");
170
213
  if (isNotification) continue;
171
214
 
215
+ if (discoveryMode) {
216
+ if (req.method === "ping") {
217
+ write({ jsonrpc: "2.0", id: req.id ?? null, result: {} });
218
+ continue;
219
+ }
220
+ if (req.method === "initialize") {
221
+ // serverInfo/protocolVersion möglichst aus der öffentlichen
222
+ // Discovery übernehmen; bei Fehler lokaler Default.
223
+ const initResult = localInitializeResult();
224
+ try {
225
+ const pub = await fetchPublicDiscovery();
226
+ if (pub && typeof pub === "object") {
227
+ if (typeof pub.protocolVersion === "string")
228
+ initResult.protocolVersion = pub.protocolVersion;
229
+ initResult.serverInfo = {
230
+ name: "knowmind",
231
+ version:
232
+ typeof pub.version === "string" ? pub.version : VERSION,
233
+ };
234
+ }
235
+ } catch {
236
+ // offline → lokaler Default reicht für initialize.
237
+ }
238
+ write({ jsonrpc: "2.0", id: req.id ?? null, result: initResult });
239
+ continue;
240
+ }
241
+ if (req.method === "tools/list") {
242
+ try {
243
+ const pub = await fetchPublicDiscovery();
244
+ const tools = Array.isArray(pub?.tools) ? pub.tools : [];
245
+ write({ jsonrpc: "2.0", id: req.id ?? null, result: { tools } });
246
+ } catch (e) {
247
+ write({
248
+ jsonrpc: "2.0",
249
+ id: req.id ?? null,
250
+ error: {
251
+ code: -32000,
252
+ message: `Knowmind-Discovery nicht erreichbar: ${e instanceof Error ? e.message : String(e)}`,
253
+ },
254
+ });
255
+ }
256
+ continue;
257
+ }
258
+ if (req.method === "prompts/list") {
259
+ write({ jsonrpc: "2.0", id: req.id ?? null, result: { prompts: [] } });
260
+ continue;
261
+ }
262
+ // tools/call & Co. brauchen einen Token → klare Fehlermeldung.
263
+ write({
264
+ jsonrpc: "2.0",
265
+ id: req.id ?? null,
266
+ error: {
267
+ code: -32001,
268
+ message: `Knowmind: ${auth.reason}`,
269
+ },
270
+ });
271
+ continue;
272
+ }
273
+
172
274
  if (!auth.ok && req.method !== "ping") {
173
275
  // Initialize (und alles weitere) FEHLSCHLAGEN lassen, damit der
174
276
  // MCP-Client „connected" nicht fälschlich anzeigt. Claude Code,