chat-recall 0.7.39 → 0.7.40

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 +45 -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
@@ -0,0 +1,194 @@
1
+ /**
2
+ * The servers of one machine, and the one host that serves them.
3
+ *
4
+ * A product does not start its own host. It adds its server to the file this module keeps, installs the
5
+ * service once when the machine has none, and writes its client entries as `http://127.0.0.1:<port>/<name>`.
6
+ * The host then starts each server once and gives every session its own streamable-HTTP transport.
7
+ *
8
+ * The file holds no token. The command of a server may read its own secret at start, and that is the whole
9
+ * of its environment: nothing from the caller of `installHost` reaches the host process.
10
+ */
11
+ import { dirname, join } from "node:path";
12
+ /** The address and the port that the file holds when no product names another. */
13
+ export const DEFAULT_PORT = 7717;
14
+ export const LOOPBACK = "127.0.0.1";
15
+ /** The name of the one service per machine, on Linux and on a Mac. */
16
+ export const HOST_UNIT = "mcp-kit-host";
17
+ export const HOST_LABEL = "com.munhq.mcp-kit-host";
18
+ /** The file of the config, under the home of the machine. */
19
+ export function configPath(home) {
20
+ return join(home, ".config", "mcp-kit", "host.json");
21
+ }
22
+ /** The config, or an empty one on a machine that has none. A file that is not JSON throws, so a person sees it. */
23
+ export function readConfig(home, read) {
24
+ const text = read(configPath(home));
25
+ if (text === undefined || text.trim() === "")
26
+ return { port: DEFAULT_PORT, host: LOOPBACK, servers: [] };
27
+ const parsed = JSON.parse(text);
28
+ return {
29
+ port: typeof parsed.port === "number" && parsed.port >= 0 ? parsed.port : DEFAULT_PORT,
30
+ host: typeof parsed.host === "string" && parsed.host !== "" ? parsed.host : LOOPBACK,
31
+ servers: Array.isArray(parsed.servers) ? parsed.servers.filter(usable) : [],
32
+ };
33
+ }
34
+ function usable(spec) {
35
+ return typeof spec?.name === "string" && spec.name !== "" && typeof spec.command === "string" && spec.command !== "";
36
+ }
37
+ /**
38
+ * Add one server to the file of this machine.
39
+ *
40
+ * A server of the same name is replaced when its command, arguments or environment differ, and left alone
41
+ * when they are the same, so that a second install writes nothing and restarts nothing.
42
+ */
43
+ export function addServer(h, spec) {
44
+ if (!usable(spec))
45
+ throw new Error(`a server needs a name and a command: ${JSON.stringify(spec)}`);
46
+ const config = readConfig(h.home, h.read);
47
+ const at = config.servers.findIndex((s) => s.name === spec.name);
48
+ const same = at >= 0 && JSON.stringify(config.servers[at]) === JSON.stringify(spec);
49
+ if (same)
50
+ return { config, changed: false };
51
+ const servers = at >= 0 ? config.servers.map((s, i) => (i === at ? spec : s)) : [...config.servers, spec];
52
+ const next = { ...config, servers };
53
+ h.write(configPath(h.home), `${JSON.stringify(next, null, 2)}\n`, { mode: 0o600, dirMode: 0o700 });
54
+ return { config: next, changed: true };
55
+ }
56
+ export function hostPaths(home, platform = process.platform) {
57
+ if (platform === "darwin") {
58
+ return {
59
+ file: join(home, "Library", "LaunchAgents", `${HOST_LABEL}.plist`),
60
+ log: join(home, "Library", "Logs", `${HOST_UNIT}.log`),
61
+ unit: HOST_UNIT,
62
+ label: HOST_LABEL,
63
+ };
64
+ }
65
+ return {
66
+ file: join(home, ".config", "systemd", "user", `${HOST_UNIT}.service`),
67
+ log: join(home, ".local", "state", HOST_UNIT, "host.log"),
68
+ unit: HOST_UNIT,
69
+ label: HOST_LABEL,
70
+ };
71
+ }
72
+ /** The command of the host: the Node that runs this code, the program of the host, and the file of the config. */
73
+ export function hostArgv(args) {
74
+ return [args.node, args.main, "--config", args.config];
75
+ }
76
+ function unitQuote(value) {
77
+ return `"${value.replace(/\\/g, "\\\\").replace(/"/g, '\\"').replace(/\$/g, "$$$$").replace(/%/g, "%%")}"`;
78
+ }
79
+ function xml(value) {
80
+ return value
81
+ .replace(/&/g, "&amp;")
82
+ .replace(/</g, "&lt;")
83
+ .replace(/>/g, "&gt;")
84
+ .replace(/"/g, "&quot;")
85
+ .replace(/'/g, "&apos;");
86
+ }
87
+ /** The text of the systemd user unit. It holds the command and the log, no token. */
88
+ export function unitText(argv, log) {
89
+ return [
90
+ "[Unit]",
91
+ "Description=MCP host: the local servers of this machine on the loopback address",
92
+ "After=network.target",
93
+ "",
94
+ "[Service]",
95
+ `ExecStart=${argv.map(unitQuote).join(" ")}`,
96
+ "Restart=always",
97
+ "RestartSec=2",
98
+ `StandardOutput=append:${log}`,
99
+ `StandardError=append:${log}`,
100
+ "",
101
+ "[Install]",
102
+ "WantedBy=default.target",
103
+ "",
104
+ ].join("\n");
105
+ }
106
+ /** The text of the launchd plist. It holds the command and the log, no token. */
107
+ export function plistText(argv, log, label = HOST_LABEL) {
108
+ return [
109
+ '<?xml version="1.0" encoding="UTF-8"?>',
110
+ '<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">',
111
+ '<plist version="1.0">',
112
+ "<dict>",
113
+ ` <key>Label</key><string>${xml(label)}</string>`,
114
+ " <key>ProgramArguments</key>",
115
+ " <array>",
116
+ ...argv.map((a) => ` <string>${xml(a)}</string>`),
117
+ " </array>",
118
+ " <key>RunAtLoad</key><true/>",
119
+ " <key>KeepAlive</key><true/>",
120
+ ` <key>StandardOutPath</key><string>${xml(log)}</string>`,
121
+ ` <key>StandardErrorPath</key><string>${xml(log)}</string>`,
122
+ "</dict>",
123
+ "</plist>",
124
+ "",
125
+ ].join("\n");
126
+ }
127
+ /**
128
+ * Keep the host loaded on this machine.
129
+ *
130
+ * A service that is already running is restarted only when the text of its unit changed, because a
131
+ * restart drops the sessions of the clients of this machine for a moment.
132
+ */
133
+ export function installHost(h, args) {
134
+ const platform = args.platform ?? process.platform;
135
+ if (platform !== "linux" && platform !== "darwin")
136
+ return { written: [] };
137
+ const paths = hostPaths(h.home, platform);
138
+ // systemd makes the log file, but not its folder: a missing folder stops the service with 209/STDOUT before the host
139
+ // starts, and the service then restarts for ever. Make the folder first, so the first install runs on the first try.
140
+ h.run("mkdir", ["-p", dirname(paths.log)]);
141
+ const text = platform === "darwin" ? plistText(args.argv, paths.log, paths.label) : unitText(args.argv, paths.log);
142
+ const written = [];
143
+ if (h.read(paths.file) !== text) {
144
+ h.write(paths.file, text);
145
+ written.push(paths.file);
146
+ }
147
+ if (platform === "darwin") {
148
+ h.run("launchctl", ["unload", paths.file]);
149
+ h.run("launchctl", ["load", "-w", paths.file]);
150
+ return { written, load: ["launchctl", "load", "-w", paths.file] };
151
+ }
152
+ if (written.length > 0)
153
+ h.run("systemctl", ["--user", "daemon-reload"]);
154
+ const enabled = h.run("systemctl", ["--user", "enable", "--now", `${paths.unit}.service`]);
155
+ return { written, load: enabled.code === 0 ? undefined : ["systemctl", "--user", "enable", "--now", `${paths.unit}.service`] };
156
+ }
157
+ /** Is the host loaded on this machine? `disabled` means the unit is not there at all. */ export function hostStatus(h, platform = process.platform) {
158
+ if (platform !== "linux" && platform !== "darwin")
159
+ return "disabled";
160
+ const paths = hostPaths(h.home, platform);
161
+ if (h.read(paths.file) === undefined)
162
+ return "disabled";
163
+ const got = platform === "darwin" ? h.run("launchctl", ["list", paths.label]) : h.run("systemctl", ["--user", "is-active", `${paths.unit}.service`]);
164
+ return got.code === 0 ? "running" : "stopped";
165
+ }
166
+ /**
167
+ * Restart the host, so that a server that a product added a moment ago is up.
168
+ *
169
+ * Only a host that runs is restarted. A machine with no service keeps the new entry until `installHost` starts one,
170
+ * and a client that calls the host before that gets the 404 that names the missing server.
171
+ */
172
+ export function restartHost(h, platform = process.platform) {
173
+ if (hostStatus(h, platform) !== "running")
174
+ return false;
175
+ const paths = hostPaths(h.home, platform);
176
+ if (platform === "darwin") {
177
+ h.run("launchctl", ["unload", paths.file]);
178
+ return h.run("launchctl", ["load", "-w", paths.file]).code === 0;
179
+ }
180
+ return h.run("systemctl", ["--user", "restart", `${paths.unit}.service`]).code === 0;
181
+ }
182
+ /** Remove the host from this machine. The config stays, because it belongs to the products, not to the service. */ export function uninstallHost(h, platform = process.platform) {
183
+ if (platform !== "linux" && platform !== "darwin")
184
+ return [];
185
+ const paths = hostPaths(h.home, platform);
186
+ if (h.read(paths.file) === undefined)
187
+ return [];
188
+ if (platform === "darwin")
189
+ h.run("launchctl", ["unload", paths.file]);
190
+ else
191
+ h.run("systemctl", ["--user", "disable", "--now", `${paths.unit}.service`]);
192
+ h.write(paths.file, "");
193
+ return [paths.file];
194
+ }
package/dist/watch.js CHANGED
@@ -27818,7 +27818,7 @@ var init_http = __esm({
27818
27818
  CLI_VERSION = JSON.parse(readFileSync37(new URL("../package.json", import.meta.url), "utf-8")).version || CLI_VERSION;
27819
27819
  } catch {
27820
27820
  try {
27821
- if (true) CLI_VERSION = "0.7.39";
27821
+ if (typeof __CLI_VERSION__ === "string") CLI_VERSION = __CLI_VERSION__;
27822
27822
  } catch {
27823
27823
  }
27824
27824
  }
@@ -28312,7 +28312,7 @@ var init_telemetry = __esm({
28312
28312
  init_sync_client();
28313
28313
  cliVersion = () => {
28314
28314
  try {
28315
- return true ? "0.7.39" : "dev";
28315
+ return typeof __CLI_VERSION__ === "string" ? __CLI_VERSION__ : "dev";
28316
28316
  } catch {
28317
28317
  return "dev";
28318
28318
  }
@@ -29848,13 +29848,10 @@ async function syncToTargetInScope(cred, opts = {}) {
29848
29848
  try {
29849
29849
  await reconcileFieldsForTarget(
29850
29850
  cred,
29851
- () => listAvailableBackends().flatMap((b) => {
29852
- try {
29853
- return b.listSessions({ previews: false });
29854
- } catch {
29855
- return [];
29856
- }
29857
- }),
29851
+ // Reuse the listing this sync already made. A second full listing of
29852
+ // every backend cost about 100 MB of committed heap on every tick
29853
+ // (issue #16).
29854
+ () => refs,
29858
29855
  { convRefs: slice }
29859
29856
  );
29860
29857
  } catch (e) {
@@ -30744,7 +30741,7 @@ var init_sync_client = __esm({
30744
30741
  ownVersion = JSON.parse(readFileSync41(join47(dir, "../package.json"), "utf-8")).version || ownVersion;
30745
30742
  } catch {
30746
30743
  try {
30747
- if (true) ownVersion = "0.7.39";
30744
+ if (typeof __CLI_VERSION__ === "string") ownVersion = __CLI_VERSION__;
30748
30745
  } catch {
30749
30746
  }
30750
30747
  }
@@ -30778,6 +30775,32 @@ var init_sync_client = __esm({
30778
30775
  }
30779
30776
  });
30780
30777
 
30778
+ // src/memory-guard.ts
30779
+ function rssMb() {
30780
+ return Math.round(process.memoryUsage().rss / 1048576);
30781
+ }
30782
+ function memoryLimitMb(env = process.env) {
30783
+ const raw = env.CHAT_RECALL_WATCH_RSS_MAX_MB;
30784
+ if (!raw) return DEFAULT_RSS_MAX_MB;
30785
+ const n = Number(raw);
30786
+ return Number.isFinite(n) && n > 0 ? Math.round(n) : DEFAULT_RSS_MAX_MB;
30787
+ }
30788
+ function isOverMemoryLimit(rss, limitMb) {
30789
+ return rss >= limitMb;
30790
+ }
30791
+ function releaseMemory(gc = globalThis.gc) {
30792
+ if (typeof gc !== "function") return false;
30793
+ gc();
30794
+ return true;
30795
+ }
30796
+ var DEFAULT_RSS_MAX_MB;
30797
+ var init_memory_guard = __esm({
30798
+ "src/memory-guard.ts"() {
30799
+ "use strict";
30800
+ DEFAULT_RSS_MAX_MB = 512;
30801
+ }
30802
+ });
30803
+
30781
30804
  // ../engine/dist/core/artifact-codec.js
30782
30805
  import { readFileSync as readFileSync42 } from "fs";
30783
30806
  import { basename as basename23, join as join48 } from "path";
@@ -32550,7 +32573,7 @@ var init_intent_drain = __esm({
32550
32573
  ownVersion2 = JSON.parse(readFileSync45(join53(dir, "../package.json"), "utf-8")).version || ownVersion2;
32551
32574
  } catch {
32552
32575
  try {
32553
- if (true) ownVersion2 = "0.7.39";
32576
+ if (typeof __CLI_VERSION__ === "string") ownVersion2 = __CLI_VERSION__;
32554
32577
  } catch {
32555
32578
  }
32556
32579
  }
@@ -34366,7 +34389,7 @@ function renderSystemdUnit(watchJs, node, logFile) {
34366
34389
  // base64 payloads); V8's default old-space on a big-RAM box is ~4GB and
34367
34390
  // GC only gets aggressive near the ceiling — observed as a multi-GB RSS
34368
34391
  // sawtooth. The ceiling below is measured, not guessed: see WATCH_HEAP_MB.
34369
- `ExecStart=${node} --max-old-space-size=${WATCH_HEAP_MB} ${watchJs}`,
34392
+ `ExecStart=${node} --max-old-space-size=${WATCH_HEAP_MB} --expose-gc ${watchJs}`,
34370
34393
  // ALWAYS: the collector never ends its own work, so any exit systemd did
34371
34394
  // not ask for is a fault. Under on-failure a clean exit left it dead: on
34372
34395
  // 2026-09-16 the unit went "inactive (dead) … status=0/SUCCESS" and stayed
@@ -34439,7 +34462,7 @@ function renderLaunchdPlist(watchJs, node, logFile, label = "com.chat-recall.wat
34439
34462
  '<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">',
34440
34463
  '<plist version="1.0"><dict>',
34441
34464
  ` <key>Label</key><string>${label}</string>`,
34442
- ` <key>ProgramArguments</key><array><string>${node}</string><string>--max-old-space-size=${WATCH_HEAP_MB}</string><string>${watchJs}</string></array>`,
34465
+ ` <key>ProgramArguments</key><array><string>${node}</string><string>--max-old-space-size=${WATCH_HEAP_MB}</string><string>--expose-gc</string><string>${watchJs}</string></array>`,
34443
34466
  " <key>RunAtLoad</key><true/>",
34444
34467
  " <key>KeepAlive</key><true/>",
34445
34468
  ` <key>StandardOutPath</key><string>${logFile}</string>`,
@@ -34793,7 +34816,13 @@ async function codeIndexTick() {
34793
34816
  }
34794
34817
  let ok = 0, unchanged = 0;
34795
34818
  const cursor = readCursor();
34819
+ const rssLimit = memoryLimitMb();
34796
34820
  for (const ws of workspaces) {
34821
+ const rss = rssMb();
34822
+ if (isOverMemoryLimit(rss, rssLimit)) {
34823
+ daemonLog.info(`code intelligence: paused at the memory bound (rss=${rss}MB \u2265 ${rssLimit}MB) \u2014 ${workspaces.length - ok - unchanged} workspace(s) wait for the next pass`);
34824
+ break;
34825
+ }
34797
34826
  const fp = workspaceFingerprint(ws, COLLECTOR_VERSION2);
34798
34827
  if (isUnchangedSinceIndexed(ws, fp, cursor)) {
34799
34828
  unchanged++;
@@ -34818,6 +34847,7 @@ async function codeIndexTick() {
34818
34847
  }
34819
34848
  noteIndexed(ws, Date.now(), fp);
34820
34849
  ok++;
34850
+ releaseMemory();
34821
34851
  }
34822
34852
  if (ok > 0 || unchanged > 0) daemonLog.info(`code intelligence: indexed ${ok}/${workspaces.length} workspace(s), ${unchanged} unchanged`);
34823
34853
  } finally {
@@ -34890,6 +34920,7 @@ var init_indexer = __esm({
34890
34920
  init_settings();
34891
34921
  init_sync_client();
34892
34922
  init_walk_budget();
34923
+ init_memory_guard();
34893
34924
  init_http();
34894
34925
  init_intent_drain();
34895
34926
  init_sync_client();
@@ -34903,7 +34934,7 @@ var init_indexer = __esm({
34903
34934
  init_collector_migrate();
34904
34935
  init_sync_ledger();
34905
34936
  init_collector_health();
34906
- CLI_VERSION3 = true ? "0.7.39" : "0.0.0";
34937
+ CLI_VERSION3 = typeof __CLI_VERSION__ === "string" ? __CLI_VERSION__ : "0.0.0";
34907
34938
  DEBOUNCE_MS = 5e3;
34908
34939
  PLANS_DIR = claudeBackend.plansDir();
34909
34940
  TASKS_DIR = claudeBackend.tasksDir();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chat-recall",
3
- "version": "0.7.39",
3
+ "version": "0.7.40",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/munhq/chat-recall.git"
@@ -43,7 +43,7 @@
43
43
  "license": "Elastic-2.0",
44
44
  "bin": {
45
45
  "chat-recall": "dist/cli.js",
46
- "chat-recall-mcp": "dist/mcp-relay.js",
46
+ "chat-recall-mcp": "dist/mcp.js",
47
47
  "chat-recall-watch": "dist/watch.js",
48
48
  "chat-recall-mcp-server": "dist/mcp.js"
49
49
  },
@@ -1,3 +0,0 @@
1
- #!/usr/bin/env node
2
- export {};
3
- //# sourceMappingURL=mcp-relay.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"mcp-relay.d.ts","sourceRoot":"","sources":["../src/mcp-relay.ts"],"names":[],"mappings":""}