chat-recall 0.7.39 → 0.7.41

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.
Files changed (55) hide show
  1. package/README.md +22 -14
  2. package/dist/cli.js +698 -410
  3. package/dist/cli.js.map +1 -1
  4. package/dist/install-hooks.d.ts +11 -3
  5. package/dist/install-hooks.d.ts.map +1 -1
  6. package/dist/install-hooks.js +10 -5
  7. package/dist/install-hooks.js.map +1 -1
  8. package/dist/kit-store.d.ts +1 -1
  9. package/dist/kit-store.d.ts.map +1 -1
  10. package/dist/kit-store.js +2 -2
  11. package/dist/kit-store.js.map +1 -1
  12. package/dist/mcp-host.d.ts +50 -0
  13. package/dist/mcp-host.d.ts.map +1 -0
  14. package/dist/mcp-host.js +111 -0
  15. package/dist/mcp-host.js.map +1 -0
  16. package/dist/mcp.js +1023 -981
  17. package/dist/mcp.js.map +1 -1
  18. package/dist/memory-guard.d.ts +41 -0
  19. package/dist/memory-guard.d.ts.map +1 -0
  20. package/dist/memory-guard.js +56 -0
  21. package/dist/memory-guard.js.map +1 -0
  22. package/dist/message-hook.js +1 -1
  23. package/dist/service-installer.js +2 -2
  24. package/dist/service-installer.js.map +1 -1
  25. package/dist/session-exit.d.ts +50 -0
  26. package/dist/session-exit.d.ts.map +1 -0
  27. package/dist/session-exit.js +70 -0
  28. package/dist/session-exit.js.map +1 -0
  29. package/dist/star-nudge.js +1 -1
  30. package/dist/sync-client.d.ts.map +1 -1
  31. package/dist/sync-client.js +5 -6
  32. package/dist/sync-client.js.map +1 -1
  33. package/dist/vendor/mcp-kit/VERSION +1 -0
  34. package/dist/vendor/mcp-kit/host-main.d.ts +2 -0
  35. package/dist/vendor/mcp-kit/host-main.js +3 -0
  36. package/dist/vendor/mcp-kit/host-plain.d.ts +56 -0
  37. package/dist/vendor/mcp-kit/host-plain.js +502 -0
  38. package/dist/vendor/mcp-kit/host.d.ts +32 -0
  39. package/dist/vendor/mcp-kit/host.js +43 -0
  40. package/dist/vendor/mcp-kit/registry.d.ts +79 -0
  41. package/dist/vendor/mcp-kit/registry.js +194 -0
  42. package/dist/watch.js +47 -14
  43. package/package.json +2 -2
  44. package/dist/mcp-relay.d.ts +0 -3
  45. package/dist/mcp-relay.d.ts.map +0 -1
  46. package/dist/mcp-relay.js +0 -472
  47. package/dist/mcp-relay.js.map +0 -1
  48. package/dist/mcp-socket.d.ts +0 -98
  49. package/dist/mcp-socket.d.ts.map +0 -1
  50. package/dist/mcp-socket.js +0 -249
  51. package/dist/mcp-socket.js.map +0 -1
  52. package/dist/relay-lifecycle.d.ts +0 -92
  53. package/dist/relay-lifecycle.d.ts.map +0 -1
  54. package/dist/relay-lifecycle.js +0 -290
  55. package/dist/relay-lifecycle.js.map +0 -1
package/dist/mcp-relay.js DELETED
@@ -1,472 +0,0 @@
1
- #!/usr/bin/env node
2
- import { createRequire as __cr } from 'module'; const require = __cr(import.meta.url);
3
-
4
- // src/mcp-relay.ts
5
- import { connect } from "node:net";
6
- import { spawn } from "node:child_process";
7
- import { openSync } from "node:fs";
8
- import { fileURLToPath } from "node:url";
9
-
10
- // src/mcp-socket.ts
11
- import { createHash } from "node:crypto";
12
- import { tmpdir } from "node:os";
13
- import { join } from "node:path";
14
- import { accessSync, chmodSync, constants, mkdirSync, statSync } from "node:fs";
15
- import { dirname } from "node:path";
16
- var MAX_PATH = 100;
17
- var fits = (dir) => dir.length + 1 + 16 + 5 <= MAX_PATH;
18
- function socketDirCandidates() {
19
- if (process.platform === "win32") {
20
- const out2 = [];
21
- if (process.env.LOCALAPPDATA) out2.push(join(process.env.LOCALAPPDATA, "chat-recall", "run"));
22
- if (process.env.TEMP) out2.push(join(process.env.TEMP, "chat-recall-run"));
23
- out2.push(join(tmpdir(), "chat-recall-run"));
24
- return out2;
25
- }
26
- const out = [];
27
- const xdg = process.env.XDG_RUNTIME_DIR;
28
- if (xdg && xdg.length > 0) {
29
- const p = join(xdg, "chat-recall");
30
- if (fits(p)) out.push(p);
31
- }
32
- const uid = typeof process.getuid === "function" ? process.getuid() : 0;
33
- const named = join(tmpdir(), `chat-recall-${uid}`);
34
- if (fits(named)) out.push(named);
35
- const last = `/tmp/chat-recall-${uid}`;
36
- if (!out.includes(last)) out.push(last);
37
- return out;
38
- }
39
- var MAX_MISSING_LEVELS = 8;
40
- function isDir(path) {
41
- try {
42
- return statSync(path).isDirectory();
43
- } catch {
44
- return false;
45
- }
46
- }
47
- function usableDir(dir) {
48
- if (!isDir(dir)) {
49
- const missing = [];
50
- let cur = dir;
51
- let base = false;
52
- while (missing.length < MAX_MISSING_LEVELS) {
53
- const parent = dirname(cur);
54
- if (parent === cur) break;
55
- missing.push(cur);
56
- if (isDir(parent)) {
57
- base = true;
58
- break;
59
- }
60
- cur = parent;
61
- }
62
- if (!base) return false;
63
- for (let i = missing.length - 1; i >= 0; i--) {
64
- try {
65
- mkdirSync(missing[i]);
66
- } catch {
67
- }
68
- if (!isDir(missing[i])) return false;
69
- }
70
- }
71
- try {
72
- accessSync(dir, constants.W_OK);
73
- return true;
74
- } catch {
75
- return false;
76
- }
77
- }
78
- function privateDir(dir) {
79
- if (process.platform === "win32") return true;
80
- try {
81
- chmodSync(dir, 448);
82
- return (statSync(dir).mode & 63) === 0;
83
- } catch {
84
- return false;
85
- }
86
- }
87
- function ensureSocketDir() {
88
- const candidates = socketDirCandidates();
89
- for (const dir of candidates) {
90
- if (!usableDir(dir)) continue;
91
- if (!privateDir(dir)) continue;
92
- return dir;
93
- }
94
- throw new Error(`no private runtime directory for the MCP daemon (tried ${candidates.join(", ")})`);
95
- }
96
- function socketSlug(version) {
97
- const key = [
98
- process.env.CHAT_RECALL_MCP_PROFILE ?? "",
99
- process.env.CHAT_RECALL_SERVER ?? "",
100
- version
101
- ].join(" ");
102
- return createHash("sha256").update(key).digest("hex").slice(0, 16);
103
- }
104
- function socketPath(dir, version) {
105
- const slug = socketSlug(version);
106
- if (process.platform === "win32") return "\\\\.\\pipe\\chat-recall-" + slug;
107
- return join(dir, `${slug}.sock`);
108
- }
109
- function logPath(dir, version) {
110
- return join(dir, `${socketSlug(version)}.log`);
111
- }
112
- var SOCKET_FLAG = "--socket";
113
- function daemonEnabled() {
114
- const v = process.env.CHAT_RECALL_NO_DAEMON;
115
- if (v === void 0) return true;
116
- const t = v.trim();
117
- return t === "" || t === "0" || t === "false";
118
- }
119
-
120
- // src/channel-detect.ts
121
- import { execFileSync } from "node:child_process";
122
- import { readFileSync } from "node:fs";
123
- var OURS = /* @__PURE__ */ new Set(["server:chat-recall", "chat-recall"]);
124
- var FLAGS = /* @__PURE__ */ new Set(["--channels", "--dangerously-load-development-channels"]);
125
- function listsOurServer(args) {
126
- for (let i = 0; i < args.length; i += 1) {
127
- if (!FLAGS.has(args[i])) continue;
128
- for (let j = i + 1; j < args.length && !args[j].startsWith("-"); j += 1) {
129
- if (OURS.has(args[j])) return true;
130
- }
131
- }
132
- return false;
133
- }
134
- function commandLineOf(pid) {
135
- try {
136
- const parts = readFileSync(`/proc/${pid}/cmdline`, "utf-8").split("\0").filter(Boolean);
137
- if (parts.length) return parts;
138
- } catch {
139
- }
140
- if (process.platform === "win32") return null;
141
- try {
142
- const out = execFileSync("ps", ["-o", "args=", "-p", String(pid)], {
143
- encoding: "utf8",
144
- timeout: 2e3,
145
- stdio: ["ignore", "pipe", "ignore"]
146
- }).trim();
147
- return out ? out.split(/\s+/) : null;
148
- } catch {
149
- return null;
150
- }
151
- }
152
- function parentOf(pid) {
153
- try {
154
- const stat = readFileSync(`/proc/${pid}/stat`, "utf-8");
155
- const ppid = Number(stat.slice(stat.lastIndexOf(")") + 2).split(" ")[1]);
156
- return ppid > 1 ? ppid : null;
157
- } catch {
158
- }
159
- if (process.platform === "win32") return null;
160
- try {
161
- const ppid = Number(execFileSync("ps", ["-o", "ppid=", "-p", String(pid)], {
162
- encoding: "utf8",
163
- timeout: 2e3,
164
- stdio: ["ignore", "pipe", "ignore"]
165
- }).trim());
166
- return Number.isInteger(ppid) && ppid > 1 ? ppid : null;
167
- } catch {
168
- return null;
169
- }
170
- }
171
- function ancestorPids(from = process.ppid, depth = 2) {
172
- const out = [];
173
- let pid = from;
174
- for (let i = 0; i < depth && pid !== null; i += 1) {
175
- out.push(pid);
176
- pid = parentOf(pid);
177
- }
178
- return out;
179
- }
180
- function ancestorCommandLines(pids = ancestorPids()) {
181
- const out = [];
182
- for (const pid of pids) {
183
- const argv = commandLineOf(pid);
184
- if (argv) out.push(argv);
185
- }
186
- return out;
187
- }
188
- function channelDecision(env = process.env, args = process.argv.slice(2), ancestors = ancestorCommandLines) {
189
- const asked = env.CHAT_RECALL_CHANNEL;
190
- if (asked === "0") return { enabled: false, reason: "CHAT_RECALL_CHANNEL=0" };
191
- if (asked === "1") return { enabled: true, reason: "CHAT_RECALL_CHANNEL=1" };
192
- if (asked !== void 0 && asked !== "") return { enabled: false, reason: `CHAT_RECALL_CHANNEL=${asked} is neither 0 nor 1` };
193
- if (listsOurServer(args)) return { enabled: true, reason: "our own --channels flag" };
194
- if (ancestors().some(listsOurServer)) return { enabled: true, reason: "a --channels flag above us" };
195
- return { enabled: false, reason: "no channel flag" };
196
- }
197
-
198
- // src/relay-lifecycle.ts
199
- var PARENT_POLL_MS = 5e3;
200
- function pidAlive(pid) {
201
- try {
202
- process.kill(pid, 0);
203
- return true;
204
- } catch (err) {
205
- return err.code === "EPERM";
206
- }
207
- }
208
- var processProbe = {
209
- ppid: () => process.ppid,
210
- alive: pidAlive
211
- };
212
- function parentGone(originalPpid, probe) {
213
- if (probe.ppid() !== originalPpid) return true;
214
- return !probe.alive(originalPpid);
215
- }
216
- function watchParent(onGone, opts = {}) {
217
- const probe = opts.probe ?? processProbe;
218
- const original = probe.ppid();
219
- if (original <= 1) return () => {
220
- };
221
- const timer = setInterval(() => {
222
- if (!parentGone(original, probe)) return;
223
- clearInterval(timer);
224
- onGone();
225
- }, opts.intervalMs ?? PARENT_POLL_MS);
226
- timer.unref?.();
227
- return () => clearInterval(timer);
228
- }
229
- function onInputFinished(input, onEnd) {
230
- let fired = false;
231
- const fire = () => {
232
- if (fired) return;
233
- fired = true;
234
- onEnd();
235
- };
236
- input.once("end", fire);
237
- input.once("close", fire);
238
- input.once("error", fire);
239
- }
240
- var idKey = (id) => JSON.stringify(id);
241
- function peek(line) {
242
- try {
243
- const m = JSON.parse(line);
244
- return m && typeof m === "object" ? m : null;
245
- } catch {
246
- return null;
247
- }
248
- }
249
- function lineSplitter(onLine) {
250
- const decoder = new TextDecoder("utf-8");
251
- let rest = "";
252
- return (chunk) => {
253
- rest += typeof chunk === "string" ? chunk : decoder.decode(chunk, { stream: true });
254
- let nl = rest.indexOf("\n");
255
- while (nl >= 0) {
256
- const line = rest.slice(0, nl);
257
- rest = rest.slice(nl + 1);
258
- if (line.trim()) onLine(line);
259
- nl = rest.indexOf("\n");
260
- }
261
- };
262
- }
263
- var DAEMON_RESTART_ERROR = "chat-recall restarted while this call ran. Call the tool again.";
264
- function resilientBridge(input, output, first, reconnect, exit, opts = {}) {
265
- let done = false;
266
- let inputEnded = false;
267
- let sock = null;
268
- let queue = [];
269
- let replayId = null;
270
- let initLine = null;
271
- let initializedLine = null;
272
- const pending = /* @__PURE__ */ new Set();
273
- let stopParentWatch = () => {
274
- };
275
- const finish = (code = 0) => {
276
- if (done) return;
277
- done = true;
278
- stopParentWatch();
279
- try {
280
- sock?.destroy();
281
- } catch {
282
- }
283
- exit(code);
284
- };
285
- const toClient = (line) => {
286
- try {
287
- output.write(line + "\n");
288
- } catch {
289
- finish();
290
- }
291
- };
292
- const fromClient = (line) => {
293
- const m = peek(line);
294
- if (m?.method === "initialize") initLine = line;
295
- else if (m?.method === "notifications/initialized") initializedLine = line;
296
- if (m && m.id !== void 0 && typeof m.method === "string") pending.add(idKey(m.id));
297
- if (sock && replayId === null) sock.write(line + "\n");
298
- else queue.push(line);
299
- };
300
- const attach = (s) => {
301
- sock = s;
302
- const onLine = lineSplitter((line) => {
303
- if (s !== sock) return;
304
- const m = peek(line);
305
- const isReply = m && m.id !== void 0 && m.method === void 0;
306
- if (isReply && replayId !== null && idKey(m.id) === replayId) {
307
- replayId = null;
308
- if (initializedLine) s.write(initializedLine + "\n");
309
- const held = queue;
310
- queue = [];
311
- for (const l of held) s.write(l + "\n");
312
- return;
313
- }
314
- if (isReply) pending.delete(idKey(m.id));
315
- toClient(line);
316
- });
317
- s.on("data", onLine);
318
- s.on("error", () => {
319
- });
320
- s.on("close", () => {
321
- if (s === sock) void lost();
322
- });
323
- };
324
- const lost = async () => {
325
- sock = null;
326
- if (done) return;
327
- if (inputEnded) {
328
- finish();
329
- return;
330
- }
331
- for (const key of pending) {
332
- toClient(JSON.stringify({ jsonrpc: "2.0", id: JSON.parse(key), error: { code: -32e3, message: DAEMON_RESTART_ERROR } }));
333
- }
334
- pending.clear();
335
- const next = await reconnect().catch(() => null);
336
- if (done) {
337
- try {
338
- next?.destroy();
339
- } catch {
340
- }
341
- return;
342
- }
343
- if (!next) {
344
- finish(1);
345
- return;
346
- }
347
- if (initLine) {
348
- replayId = idKey(peek(initLine)?.id);
349
- attach(next);
350
- next.write(initLine + "\n");
351
- } else {
352
- attach(next);
353
- const held = queue;
354
- queue = [];
355
- for (const l of held) next.write(l + "\n");
356
- }
357
- };
358
- attach(first);
359
- input.on("data", lineSplitter(fromClient));
360
- output.on("error", () => finish());
361
- onInputFinished(input, () => {
362
- inputEnded = true;
363
- if (!sock) {
364
- finish();
365
- return;
366
- }
367
- try {
368
- sock.end();
369
- } catch {
370
- finish();
371
- return;
372
- }
373
- const t = setTimeout(() => finish(), opts.drainMs ?? 2e3);
374
- t.unref?.();
375
- });
376
- stopParentWatch = watchParent(() => finish(), { probe: opts.probe, intervalMs: opts.parentPollMs });
377
- }
378
-
379
- // src/mcp-relay.ts
380
- var VERSION = true ? "0.7.39" : "0.0.0";
381
- var SERVER_URL = new URL("./mcp.js", import.meta.url);
382
- var SERVER_PATH = fileURLToPath(SERVER_URL);
383
- var START_TIMEOUT_MS = 15e3;
384
- var RETRY_MS = 100;
385
- async function serveInProcess() {
386
- const spec = SERVER_URL.href;
387
- await import(spec);
388
- }
389
- function tryConnect(path) {
390
- return new Promise((resolve) => {
391
- const sock = connect(path);
392
- const give_up = () => {
393
- sock.destroy();
394
- resolve(null);
395
- };
396
- sock.once("connect", () => {
397
- sock.removeListener("error", give_up);
398
- resolve(sock);
399
- });
400
- sock.once("error", give_up);
401
- });
402
- }
403
- function startDaemon(dir, sock) {
404
- try {
405
- let err = "ignore";
406
- try {
407
- err = openSync(logPath(dir, VERSION), "a");
408
- } catch {
409
- }
410
- const child = spawn(process.execPath, [SERVER_PATH, "--daemon", SOCKET_FLAG, sock], {
411
- detached: true,
412
- stdio: ["ignore", "ignore", err],
413
- // The relay no longer gets the heap cap from the tool's configuration (the kit writes the entry with no
414
- // environment), so the cap is set here, on the process that holds the engine.
415
- env: process.env.NODE_OPTIONS?.includes("--max-old-space-size") ? process.env : { ...process.env, NODE_OPTIONS: `${process.env.NODE_OPTIONS ?? ""} --max-old-space-size=1024`.trim() }
416
- });
417
- child.unref();
418
- return child;
419
- } catch {
420
- return null;
421
- }
422
- }
423
- async function connectOrStart(dir, path) {
424
- const existing = await tryConnect(path);
425
- if (existing) return existing;
426
- const child = startDaemon(dir, path);
427
- if (!child) return null;
428
- const deadline = Date.now() + START_TIMEOUT_MS;
429
- while (Date.now() < deadline) {
430
- await sleep(RETRY_MS);
431
- const sock = await tryConnect(path);
432
- if (sock) return sock;
433
- if (child.exitCode !== null || child.signalCode !== null) return tryConnect(path);
434
- }
435
- return null;
436
- }
437
- var sleep = (ms) => new Promise((r) => setTimeout(r, ms));
438
- async function main() {
439
- if (channelDecision().enabled) {
440
- await serveInProcess();
441
- return;
442
- }
443
- if (!daemonEnabled()) {
444
- await serveInProcess();
445
- return;
446
- }
447
- let dir;
448
- let path;
449
- try {
450
- dir = ensureSocketDir();
451
- path = socketPath(dir, VERSION);
452
- } catch {
453
- await serveInProcess();
454
- return;
455
- }
456
- const sock = await connectOrStart(dir, path);
457
- if (!sock) {
458
- console.error("[mcp] no daemon answered; serving this session in-process");
459
- await serveInProcess();
460
- return;
461
- }
462
- resilientBridge(process.stdin, process.stdout, sock, () => connectOrStart(dir, path), (code) => process.exit(code));
463
- }
464
- main().catch(async (err) => {
465
- console.error("[mcp] relay failed, serving in-process:", err?.message ?? err);
466
- try {
467
- await serveInProcess();
468
- } catch (inner) {
469
- console.error("[mcp] could not start the server at all:", inner);
470
- process.exit(1);
471
- }
472
- });
@@ -1 +0,0 @@
1
- {"version":3,"file":"mcp-relay.js","sourceRoot":"","sources":["../src/mcp-relay.ts"],"names":[],"mappings":";AACA;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,EAAE,OAAO,EAAe,MAAM,UAAU,CAAC;AAChD,OAAO,EAAE,KAAK,EAAqB,MAAM,oBAAoB,CAAC;AAC9D,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,eAAe,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AACnG,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAGvD,MAAM,OAAO,GAAG,OAAO,eAAe,KAAK,QAAQ,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,OAAO,CAAC;AAEhF,mDAAmD;AACnD,MAAM,UAAU,GAAG,IAAI,GAAG,CAAC,UAAU,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACxD;;;;;;GAMG;AACH,MAAM,WAAW,GAAG,aAAa,CAAC,UAAU,CAAC,CAAC;AAE9C,+DAA+D;AAC/D,MAAM,gBAAgB,GAAG,MAAM,CAAC;AAChC,MAAM,QAAQ,GAAG,GAAG,CAAC;AAErB;;;;;;GAMG;AACH,KAAK,UAAU,cAAc;IAC3B,MAAM,IAA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IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,0CAA0C,EAAE,KAAK,CAAC,CAAC;QACjE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;AACH,CAAC,CAAC,CAAC"}
@@ -1,98 +0,0 @@
1
- /**
2
- * Every directory the socket and the daemon log may live in, best first.
3
- *
4
- * XDG_RUNTIME_DIR first: it is per-user, mode 0700, and cleared on logout, so a
5
- * socket never outlives the login session that made it. macOS never sets it,
6
- * hence the per-uid directory under TMPDIR — which is also what keeps one
7
- * user's socket out of another's reach on a shared /tmp. `/tmp` itself is the
8
- * last resort: a TMPDIR long enough to break the path limit still leaves it.
9
- *
10
- * This is a LIST, not one answer, because every entry but the last comes from
11
- * the environment. A sandbox, a read-only mount or a stale variable pointing at
12
- * a directory this user cannot write makes the first choice fail, and one
13
- * failed candidate must cost a session nothing: the next one is tried.
14
- */
15
- export declare function socketDirCandidates(): string[];
16
- /**
17
- * Create `dir` if it is missing, and report whether it is a directory this
18
- * process can write afterwards. Never throws: a candidate that cannot be used
19
- * is a reason to try the next one, not a failure.
20
- *
21
- * Deliberately NOT `mkdirSync(dir, { recursive: true })`. Node 23's recursive
22
- * mkdir walks BACK to the parent whenever a component reports ENOENT and
23
- * forward again when one exists — and a path whose parent exists while the
24
- * child still reports ENOENT makes it oscillate between the two forever, at
25
- * 100% of a core. `/proc/anything` does exactly that on Linux: `mkdir
26
- * /proc/x` returns ENOENT, not EACCES. This path comes from XDG_RUNTIME_DIR or
27
- * TMPDIR — the values this program does not control — so it must never be
28
- * handed to that loop. (Verified on Node v23.9.0: the recursive call never
29
- * returns; a single-level `mkdirSync` on the same path throws ENOENT at once.)
30
- *
31
- * This walks up to the deepest ancestor that already exists, bounded, then
32
- * creates forward from there ONE level at a time. It never revisits a level,
33
- * so it cannot spin.
34
- */
35
- export declare function usableDir(dir: string): boolean;
36
- /**
37
- * Make `dir` private to this user, and report whether that took effect.
38
- *
39
- * This is also the OWNERSHIP proof. `usableDir` says yes to anything writable,
40
- * and on a shared /tmp that includes a directory another local user created
41
- * first — our socket would then sit in their directory, theirs to swap out.
42
- * chmod(2) fails with EPERM for anyone but the owner, so a chmod that
43
- * succeeded means we own the directory; the mode check after it catches a
44
- * filesystem that accepts chmod and ignores it (FAT, some FUSE mounts). No
45
- * uid comparison, no window between a stat and a chmod. Windows has no POSIX
46
- * modes; the per-user LOCALAPPDATA path is the protection there.
47
- */
48
- export declare function privateDir(dir: string): boolean;
49
- /**
50
- * The runtime directory for this user: the first candidate that can be used
51
- * AND made private, created on the way. Throws only when NO candidate works,
52
- * which the relay turns into serving the session in-process.
53
- */
54
- export declare function ensureSocketDir(): string;
55
- /**
56
- * Close the socket file itself to other users. connect(2) needs write
57
- * permission on a Unix socket, so 0600 refuses every other uid even if the
58
- * directory were traversable. Named pipes on Windows are not files.
59
- */
60
- export declare function restrictSocket(path: string): void;
61
- /**
62
- * What makes two sessions share a daemon.
63
- *
64
- * The profile decides WHICH TOOLS a server registers — "lean" is 27, "full" is
65
- * all 61 — and that list is fixed when the server object is built. Two sessions
66
- * that asked for different lists therefore cannot share one daemon; keying on it
67
- * gives them one each. The server URL is in the key for the same reason: a
68
- * daemon holds a connection to one backend.
69
- *
70
- * The version is in it because without it an upgraded package would attach to a
71
- * daemon still running the old code — the handshake would succeed and every
72
- * answer would come from the version the user believes they replaced.
73
- */
74
- export declare function socketSlug(version: string): string;
75
- /**
76
- * The address the daemon listens on, inside the runtime directory the caller
77
- * resolved with `ensureSocketDir()`.
78
- *
79
- * Windows gets a named pipe rather than a file. Node's local-domain sockets ARE
80
- * named pipes there, and a path outside the pipe namespace is not a valid one —
81
- * so this is the native equivalent, not a workaround. It also needs no
82
- * directory and leaves nothing behind when the daemon dies.
83
- */
84
- export declare function socketPath(dir: string, version: string): string;
85
- /** Where a daemon's diagnostics go. Never a session's stderr: it outlives it. */
86
- export declare function logPath(dir: string, version: string): string;
87
- /**
88
- * The flag the relay hands the daemon it starts. The relay already resolved a
89
- * directory and is waiting on that exact path, so the daemon binds there rather
90
- * than resolving again — a second resolution could land somewhere else if the
91
- * environment shifted between the two processes.
92
- */
93
- export declare const SOCKET_FLAG = "--socket";
94
- /** The path given with `--socket`, if the process was started with one. */
95
- export declare function socketPathFromArgv(argv: readonly string[]): string | undefined;
96
- /** True unless the user asked to keep everything inside their own session. */
97
- export declare function daemonEnabled(): boolean;
98
- //# sourceMappingURL=mcp-socket.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"mcp-socket.d.ts","sourceRoot":"","sources":["../src/mcp-socket.ts"],"names":[],"mappings":"AAuBA;;;;;;;;;;;;;GAaG;AACH,wBAAgB,mBAAmB,IAAI,MAAM,EAAE,CAoB9C;AAeD;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAmC9C;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAQ/C;AAED;;;;GAIG;AACH,wBAAgB,eAAe,IAAI,MAAM,CAQxC;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAOjD;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAOlD;AAED;;;;;;;;GAQG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAI/D;AAED,iFAAiF;AACjF,wBAAgB,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAE5D;AAED;;;;;GAKG;AACH,eAAO,MAAM,WAAW,aAAa,CAAC;AAEtC,2EAA2E;AAC3E,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,GAAG,SAAS,CAK9E;AAED,8EAA8E;AAC9E,wBAAgB,aAAa,IAAI,OAAO,CAKvC"}