chat-recall 0.7.38 → 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.
- package/README.md +22 -14
- package/dist/cli.js +833 -425
- package/dist/cli.js.map +1 -1
- package/dist/install-hooks.d.ts +11 -3
- package/dist/install-hooks.d.ts.map +1 -1
- package/dist/install-hooks.js +10 -5
- package/dist/install-hooks.js.map +1 -1
- package/dist/kit-store.d.ts +5 -4
- package/dist/kit-store.d.ts.map +1 -1
- package/dist/kit-store.js +6 -6
- package/dist/kit-store.js.map +1 -1
- package/dist/mcp-host.d.ts +50 -0
- package/dist/mcp-host.d.ts.map +1 -0
- package/dist/mcp-host.js +111 -0
- package/dist/mcp-host.js.map +1 -0
- package/dist/mcp.js +1057 -993
- package/dist/mcp.js.map +1 -1
- package/dist/memory-guard.d.ts +41 -0
- package/dist/memory-guard.d.ts.map +1 -0
- package/dist/memory-guard.js +56 -0
- package/dist/memory-guard.js.map +1 -0
- package/dist/message-hook.js +1 -1
- package/dist/scan-worker.js +8 -5
- package/dist/service-installer.d.ts +13 -0
- package/dist/service-installer.d.ts.map +1 -1
- package/dist/service-installer.js +19 -7
- package/dist/service-installer.js.map +1 -1
- package/dist/session-exit.d.ts +50 -0
- package/dist/session-exit.d.ts.map +1 -0
- package/dist/session-exit.js +70 -0
- package/dist/session-exit.js.map +1 -0
- package/dist/star-nudge.js +1 -1
- package/dist/sync-client.d.ts +16 -2
- package/dist/sync-client.d.ts.map +1 -1
- package/dist/sync-client.js +47 -10
- package/dist/sync-client.js.map +1 -1
- package/dist/vendor/mcp-kit/VERSION +1 -0
- package/dist/vendor/mcp-kit/host-main.d.ts +2 -0
- package/dist/vendor/mcp-kit/host-main.js +3 -0
- package/dist/vendor/mcp-kit/host-plain.d.ts +56 -0
- package/dist/vendor/mcp-kit/host-plain.js +502 -0
- package/dist/vendor/mcp-kit/host.d.ts +32 -0
- package/dist/vendor/mcp-kit/host.js +43 -0
- package/dist/vendor/mcp-kit/registry.d.ts +79 -0
- package/dist/vendor/mcp-kit/registry.js +194 -0
- package/dist/watch.js +78 -26
- package/package.json +2 -2
- package/dist/mcp-relay.d.ts +0 -3
- package/dist/mcp-relay.d.ts.map +0 -1
- package/dist/mcp-relay.js +0 -472
- package/dist/mcp-relay.js.map +0 -1
- package/dist/mcp-socket.d.ts +0 -98
- package/dist/mcp-socket.d.ts.map +0 -1
- package/dist/mcp-socket.js +0 -249
- package/dist/mcp-socket.js.map +0 -1
- package/dist/relay-lifecycle.d.ts +0 -92
- package/dist/relay-lifecycle.d.ts.map +0 -1
- package/dist/relay-lifecycle.js +0 -290
- package/dist/relay-lifecycle.js.map +0 -1
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import type { Host } from "./host.js";
|
|
2
|
+
/** One server of this machine, as the file holds it. The shape is plain JSON: the file outlives the code. */
|
|
3
|
+
export interface ServerSpec {
|
|
4
|
+
name: string;
|
|
5
|
+
command: string;
|
|
6
|
+
args?: string[];
|
|
7
|
+
env?: Record<string, string>;
|
|
8
|
+
cwd?: string;
|
|
9
|
+
}
|
|
10
|
+
/** The address and the port that the file holds when no product names another. */
|
|
11
|
+
export declare const DEFAULT_PORT = 7717;
|
|
12
|
+
export declare const LOOPBACK = "127.0.0.1";
|
|
13
|
+
/** The file that lists the servers of this machine. */
|
|
14
|
+
export interface HostConfig {
|
|
15
|
+
port: number;
|
|
16
|
+
host: string;
|
|
17
|
+
servers: ServerSpec[];
|
|
18
|
+
}
|
|
19
|
+
/** The name of the one service per machine, on Linux and on a Mac. */
|
|
20
|
+
export declare const HOST_UNIT = "mcp-kit-host";
|
|
21
|
+
export declare const HOST_LABEL = "com.munhq.mcp-kit-host";
|
|
22
|
+
/** The file of the config, under the home of the machine. */
|
|
23
|
+
export declare function configPath(home: string): string;
|
|
24
|
+
/** The config, or an empty one on a machine that has none. A file that is not JSON throws, so a person sees it. */
|
|
25
|
+
export declare function readConfig(home: string, read: Host["read"]): HostConfig;
|
|
26
|
+
/**
|
|
27
|
+
* Add one server to the file of this machine.
|
|
28
|
+
*
|
|
29
|
+
* A server of the same name is replaced when its command, arguments or environment differ, and left alone
|
|
30
|
+
* when they are the same, so that a second install writes nothing and restarts nothing.
|
|
31
|
+
*/
|
|
32
|
+
export declare function addServer(h: Host, spec: ServerSpec): {
|
|
33
|
+
config: HostConfig;
|
|
34
|
+
changed: boolean;
|
|
35
|
+
};
|
|
36
|
+
/** The files that keep the host loaded. A Mac uses LaunchAgents, Linux uses the user systemd. */
|
|
37
|
+
export interface HostPaths {
|
|
38
|
+
file: string;
|
|
39
|
+
log: string;
|
|
40
|
+
unit: string;
|
|
41
|
+
label: string;
|
|
42
|
+
}
|
|
43
|
+
export declare function hostPaths(home: string, platform?: NodeJS.Platform): HostPaths;
|
|
44
|
+
/** The command of the host: the Node that runs this code, the program of the host, and the file of the config. */
|
|
45
|
+
export declare function hostArgv(args: {
|
|
46
|
+
node: string;
|
|
47
|
+
main: string;
|
|
48
|
+
config: string;
|
|
49
|
+
}): string[];
|
|
50
|
+
/** The text of the systemd user unit. It holds the command and the log, no token. */
|
|
51
|
+
export declare function unitText(argv: string[], log: string): string;
|
|
52
|
+
/** The text of the launchd plist. It holds the command and the log, no token. */
|
|
53
|
+
export declare function plistText(argv: string[], log: string, label?: string): string;
|
|
54
|
+
/** What the install did, so a caller can print one line. */
|
|
55
|
+
export interface InstallResult {
|
|
56
|
+
/** The files written; empty when the machine was ready. */
|
|
57
|
+
written: string[];
|
|
58
|
+
/** The program that loads the service, and its arguments, or none on a platform this module does not know. */
|
|
59
|
+
load?: string[];
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Keep the host loaded on this machine.
|
|
63
|
+
*
|
|
64
|
+
* A service that is already running is restarted only when the text of its unit changed, because a
|
|
65
|
+
* restart drops the sessions of the clients of this machine for a moment.
|
|
66
|
+
*/
|
|
67
|
+
export declare function installHost(h: Host, args: {
|
|
68
|
+
argv: string[];
|
|
69
|
+
platform?: NodeJS.Platform;
|
|
70
|
+
}): InstallResult;
|
|
71
|
+
/** Is the host loaded on this machine? `disabled` means the unit is not there at all. */ export declare function hostStatus(h: Host, platform?: NodeJS.Platform): "running" | "stopped" | "disabled";
|
|
72
|
+
/**
|
|
73
|
+
* Restart the host, so that a server that a product added a moment ago is up.
|
|
74
|
+
*
|
|
75
|
+
* Only a host that runs is restarted. A machine with no service keeps the new entry until `installHost` starts one,
|
|
76
|
+
* and a client that calls the host before that gets the 404 that names the missing server.
|
|
77
|
+
*/
|
|
78
|
+
export declare function restartHost(h: Host, platform?: NodeJS.Platform): boolean;
|
|
79
|
+
/** Remove the host from this machine. The config stays, because it belongs to the products, not to the service. */ export declare function uninstallHost(h: Host, platform?: NodeJS.Platform): string[];
|
|
@@ -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, "&")
|
|
82
|
+
.replace(/</g, "<")
|
|
83
|
+
.replace(/>/g, ">")
|
|
84
|
+
.replace(/"/g, """)
|
|
85
|
+
.replace(/'/g, "'");
|
|
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
|
@@ -10180,15 +10180,18 @@ var init_opencode = __esm({
|
|
|
10180
10180
|
FROM part p JOIN (SELECT id, data FROM message WHERE session_id = ?) m ON p.message_id = m.id
|
|
10181
10181
|
WHERE p.session_id = ?
|
|
10182
10182
|
ORDER BY p.time_created ASC, p.id ASC
|
|
10183
|
-
`)
|
|
10184
|
-
const
|
|
10185
|
-
|
|
10186
|
-
|
|
10183
|
+
`);
|
|
10184
|
+
const chunks = [Buffer.from(`${JSON.stringify({ kind: "session", row: session })}
|
|
10185
|
+
`, "utf-8")];
|
|
10186
|
+
for (const r of rows.iterate(realId, realId)) {
|
|
10187
|
+
chunks.push(Buffer.from(`${JSON.stringify({ kind: "part", row: r })}
|
|
10188
|
+
`, "utf-8"));
|
|
10189
|
+
}
|
|
10187
10190
|
const mtime = session.time_updated || session.time_created || Date.now();
|
|
10188
10191
|
return {
|
|
10189
10192
|
tool: "opencode",
|
|
10190
10193
|
mtime: Number(mtime),
|
|
10191
|
-
files: [{ name: `${realId}.dump.jsonl`, bytes: Buffer.
|
|
10194
|
+
files: [{ name: `${realId}.dump.jsonl`, bytes: Buffer.concat(chunks) }]
|
|
10192
10195
|
};
|
|
10193
10196
|
} catch {
|
|
10194
10197
|
return null;
|
|
@@ -27815,7 +27818,7 @@ var init_http = __esm({
|
|
|
27815
27818
|
CLI_VERSION = JSON.parse(readFileSync37(new URL("../package.json", import.meta.url), "utf-8")).version || CLI_VERSION;
|
|
27816
27819
|
} catch {
|
|
27817
27820
|
try {
|
|
27818
|
-
if (
|
|
27821
|
+
if (typeof __CLI_VERSION__ === "string") CLI_VERSION = __CLI_VERSION__;
|
|
27819
27822
|
} catch {
|
|
27820
27823
|
}
|
|
27821
27824
|
}
|
|
@@ -28309,7 +28312,7 @@ var init_telemetry = __esm({
|
|
|
28309
28312
|
init_sync_client();
|
|
28310
28313
|
cliVersion = () => {
|
|
28311
28314
|
try {
|
|
28312
|
-
return
|
|
28315
|
+
return typeof __CLI_VERSION__ === "string" ? __CLI_VERSION__ : "dev";
|
|
28313
28316
|
} catch {
|
|
28314
28317
|
return "dev";
|
|
28315
28318
|
}
|
|
@@ -29845,13 +29848,10 @@ async function syncToTargetInScope(cred, opts = {}) {
|
|
|
29845
29848
|
try {
|
|
29846
29849
|
await reconcileFieldsForTarget(
|
|
29847
29850
|
cred,
|
|
29848
|
-
|
|
29849
|
-
|
|
29850
|
-
|
|
29851
|
-
|
|
29852
|
-
return [];
|
|
29853
|
-
}
|
|
29854
|
-
}),
|
|
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,
|
|
29855
29855
|
{ convRefs: slice }
|
|
29856
29856
|
);
|
|
29857
29857
|
} catch (e) {
|
|
@@ -30229,6 +30229,10 @@ async function syncToTargetInScope(cred, opts = {}) {
|
|
|
30229
30229
|
scanMs: Math.round(scanMs)
|
|
30230
30230
|
};
|
|
30231
30231
|
}
|
|
30232
|
+
function exportByteLength(exp) {
|
|
30233
|
+
if (!exp) return 0;
|
|
30234
|
+
return exp.files.reduce((n, f) => n + f.bytes.length, 0);
|
|
30235
|
+
}
|
|
30232
30236
|
async function scanTranscriptFindingsChunked(ref, tenantRules) {
|
|
30233
30237
|
const backend = getBackendForId(ref.prefixedId);
|
|
30234
30238
|
const findings = [];
|
|
@@ -30299,7 +30303,20 @@ async function buildConversationSync(ref, mtime, opts = {}) {
|
|
|
30299
30303
|
const backend = getBackendForId(ref.prefixedId) ?? getBackend("claude");
|
|
30300
30304
|
const exp = backend.exportRawSession(ref.prefixedId);
|
|
30301
30305
|
let built;
|
|
30302
|
-
|
|
30306
|
+
const exportBytes = exportByteLength(exp);
|
|
30307
|
+
const overCeiling = exportBytes > FULL_BUILD_MAX_BYTES;
|
|
30308
|
+
if (exp && overCeiling) {
|
|
30309
|
+
console.error(`[sync] ${ref.prefixedId} export is ${(exportBytes / 1048576).toFixed(0)}MB (over the ${(FULL_BUILD_MAX_BYTES / 1048576).toFixed(0)}MB ceiling) \u2014 parsing it in place, no container copy, no shadow merge, no raw archive`);
|
|
30310
|
+
record({
|
|
30311
|
+
kind: "oversized_session",
|
|
30312
|
+
mb: Math.round(exportBytes / 1048576),
|
|
30313
|
+
tool: ref.toolId,
|
|
30314
|
+
dedupeKey: stableMark(ref.prefixedId)
|
|
30315
|
+
});
|
|
30316
|
+
includeRaw = false;
|
|
30317
|
+
includeMeta = false;
|
|
30318
|
+
}
|
|
30319
|
+
if (exp && !overCeiling) {
|
|
30303
30320
|
try {
|
|
30304
30321
|
built = buildRawContainer(exp);
|
|
30305
30322
|
srcHash = containerSrcHash(built);
|
|
@@ -30323,7 +30340,7 @@ async function buildConversationSync(ref, mtime, opts = {}) {
|
|
|
30323
30340
|
includeMeta = false;
|
|
30324
30341
|
}
|
|
30325
30342
|
}
|
|
30326
|
-
const shadow = updateShadow(ref.rawId, exp, built);
|
|
30343
|
+
const shadow = overCeiling ? { container: null, status: "skipped", recovered: 0 } : updateShadow(ref.rawId, exp, built);
|
|
30327
30344
|
if (shadow.container) {
|
|
30328
30345
|
fullestContainer = shadow.container;
|
|
30329
30346
|
if (shadow.status === "rewrite-merged" && shadow.recovered > 0) {
|
|
@@ -30724,7 +30741,7 @@ var init_sync_client = __esm({
|
|
|
30724
30741
|
ownVersion = JSON.parse(readFileSync41(join47(dir, "../package.json"), "utf-8")).version || ownVersion;
|
|
30725
30742
|
} catch {
|
|
30726
30743
|
try {
|
|
30727
|
-
if (
|
|
30744
|
+
if (typeof __CLI_VERSION__ === "string") ownVersion = __CLI_VERSION__;
|
|
30728
30745
|
} catch {
|
|
30729
30746
|
}
|
|
30730
30747
|
}
|
|
@@ -30758,6 +30775,32 @@ var init_sync_client = __esm({
|
|
|
30758
30775
|
}
|
|
30759
30776
|
});
|
|
30760
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
|
+
|
|
30761
30804
|
// ../engine/dist/core/artifact-codec.js
|
|
30762
30805
|
import { readFileSync as readFileSync42 } from "fs";
|
|
30763
30806
|
import { basename as basename23, join as join48 } from "path";
|
|
@@ -32530,7 +32573,7 @@ var init_intent_drain = __esm({
|
|
|
32530
32573
|
ownVersion2 = JSON.parse(readFileSync45(join53(dir, "../package.json"), "utf-8")).version || ownVersion2;
|
|
32531
32574
|
} catch {
|
|
32532
32575
|
try {
|
|
32533
|
-
if (
|
|
32576
|
+
if (typeof __CLI_VERSION__ === "string") ownVersion2 = __CLI_VERSION__;
|
|
32534
32577
|
} catch {
|
|
32535
32578
|
}
|
|
32536
32579
|
}
|
|
@@ -34234,6 +34277,7 @@ var init_collector = __esm({
|
|
|
34234
34277
|
var service_installer_exports = {};
|
|
34235
34278
|
__export(service_installer_exports, {
|
|
34236
34279
|
ServiceInstallError: () => ServiceInstallError,
|
|
34280
|
+
WATCH_HEAP_MB: () => WATCH_HEAP_MB,
|
|
34237
34281
|
installService: () => installService,
|
|
34238
34282
|
isServiceRunning: () => isServiceRunning,
|
|
34239
34283
|
platformName: () => platformName,
|
|
@@ -34344,9 +34388,8 @@ function renderSystemdUnit(watchJs, node, logFile) {
|
|
|
34344
34388
|
// Bounded heap: the daemon does bursty batch work (transcript parse,
|
|
34345
34389
|
// base64 payloads); V8's default old-space on a big-RAM box is ~4GB and
|
|
34346
34390
|
// GC only gets aggressive near the ceiling — observed as a multi-GB RSS
|
|
34347
|
-
// sawtooth.
|
|
34348
|
-
|
|
34349
|
-
`ExecStart=${node} --max-old-space-size=1536 ${watchJs}`,
|
|
34391
|
+
// sawtooth. The ceiling below is measured, not guessed: see WATCH_HEAP_MB.
|
|
34392
|
+
`ExecStart=${node} --max-old-space-size=${WATCH_HEAP_MB} --expose-gc ${watchJs}`,
|
|
34350
34393
|
// ALWAYS: the collector never ends its own work, so any exit systemd did
|
|
34351
34394
|
// not ask for is a fault. Under on-failure a clean exit left it dead: on
|
|
34352
34395
|
// 2026-09-16 the unit went "inactive (dead) … status=0/SUCCESS" and stayed
|
|
@@ -34419,7 +34462,7 @@ function renderLaunchdPlist(watchJs, node, logFile, label = "com.chat-recall.wat
|
|
|
34419
34462
|
'<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">',
|
|
34420
34463
|
'<plist version="1.0"><dict>',
|
|
34421
34464
|
` <key>Label</key><string>${label}</string>`,
|
|
34422
|
-
` <key>ProgramArguments</key><array><string>${node}</string><string>--max-old-space-size
|
|
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>`,
|
|
34423
34466
|
" <key>RunAtLoad</key><true/>",
|
|
34424
34467
|
" <key>KeepAlive</key><true/>",
|
|
34425
34468
|
` <key>StandardOutPath</key><string>${logFile}</string>`,
|
|
@@ -34430,7 +34473,7 @@ function renderLaunchdPlist(watchJs, node, logFile, label = "com.chat-recall.wat
|
|
|
34430
34473
|
}
|
|
34431
34474
|
function installWindowsTask(watchJs, node, logFile) {
|
|
34432
34475
|
const taskName = "chat-recall-watch";
|
|
34433
|
-
const tr = `cmd /c \\"\\"${node}\\" --max-old-space-size
|
|
34476
|
+
const tr = `cmd /c \\"\\"${node}\\" --max-old-space-size=${WATCH_HEAP_MB} \\"${watchJs}\\" >> \\"${logFile}\\" 2>&1\\"`;
|
|
34434
34477
|
try {
|
|
34435
34478
|
execSync5(`schtasks /create /tn "${taskName}" /tr "${tr}" /sc onlogon /rl LIMITED /f`, { stdio: "inherit" });
|
|
34436
34479
|
try {
|
|
@@ -34443,7 +34486,7 @@ function installWindowsTask(watchJs, node, logFile) {
|
|
|
34443
34486
|
return { definitionPath: null, logFile };
|
|
34444
34487
|
}
|
|
34445
34488
|
function renderWindowsTaskCommand(watchJs, node, taskName = "chat-recall-watch", logFile) {
|
|
34446
|
-
const tr = logFile ? `cmd /c \\"\\"${node}\\" --max-old-space-size
|
|
34489
|
+
const tr = logFile ? `cmd /c \\"\\"${node}\\" --max-old-space-size=${WATCH_HEAP_MB} \\"${watchJs}\\" >> \\"${logFile}\\" 2>&1\\"` : `\\"${node}\\" --max-old-space-size=${WATCH_HEAP_MB} \\"${watchJs}\\"`;
|
|
34447
34490
|
return `schtasks /create /tn "${taskName}" /tr "${tr}" /sc onlogon /rl LIMITED /f`;
|
|
34448
34491
|
}
|
|
34449
34492
|
function uninstallService() {
|
|
@@ -34494,10 +34537,11 @@ function platformName() {
|
|
|
34494
34537
|
if (process.platform === "win32") return "Scheduled Task";
|
|
34495
34538
|
return process.platform;
|
|
34496
34539
|
}
|
|
34497
|
-
var ServiceInstallError;
|
|
34540
|
+
var WATCH_HEAP_MB, ServiceInstallError;
|
|
34498
34541
|
var init_service_installer = __esm({
|
|
34499
34542
|
"src/service-installer.ts"() {
|
|
34500
34543
|
"use strict";
|
|
34544
|
+
WATCH_HEAP_MB = 640;
|
|
34501
34545
|
ServiceInstallError = class extends Error {
|
|
34502
34546
|
hint;
|
|
34503
34547
|
constructor(message, hint) {
|
|
@@ -34772,7 +34816,13 @@ async function codeIndexTick() {
|
|
|
34772
34816
|
}
|
|
34773
34817
|
let ok = 0, unchanged = 0;
|
|
34774
34818
|
const cursor = readCursor();
|
|
34819
|
+
const rssLimit = memoryLimitMb();
|
|
34775
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
|
+
}
|
|
34776
34826
|
const fp = workspaceFingerprint(ws, COLLECTOR_VERSION2);
|
|
34777
34827
|
if (isUnchangedSinceIndexed(ws, fp, cursor)) {
|
|
34778
34828
|
unchanged++;
|
|
@@ -34797,6 +34847,7 @@ async function codeIndexTick() {
|
|
|
34797
34847
|
}
|
|
34798
34848
|
noteIndexed(ws, Date.now(), fp);
|
|
34799
34849
|
ok++;
|
|
34850
|
+
releaseMemory();
|
|
34800
34851
|
}
|
|
34801
34852
|
if (ok > 0 || unchanged > 0) daemonLog.info(`code intelligence: indexed ${ok}/${workspaces.length} workspace(s), ${unchanged} unchanged`);
|
|
34802
34853
|
} finally {
|
|
@@ -34869,6 +34920,7 @@ var init_indexer = __esm({
|
|
|
34869
34920
|
init_settings();
|
|
34870
34921
|
init_sync_client();
|
|
34871
34922
|
init_walk_budget();
|
|
34923
|
+
init_memory_guard();
|
|
34872
34924
|
init_http();
|
|
34873
34925
|
init_intent_drain();
|
|
34874
34926
|
init_sync_client();
|
|
@@ -34882,7 +34934,7 @@ var init_indexer = __esm({
|
|
|
34882
34934
|
init_collector_migrate();
|
|
34883
34935
|
init_sync_ledger();
|
|
34884
34936
|
init_collector_health();
|
|
34885
|
-
CLI_VERSION3 =
|
|
34937
|
+
CLI_VERSION3 = typeof __CLI_VERSION__ === "string" ? __CLI_VERSION__ : "0.0.0";
|
|
34886
34938
|
DEBOUNCE_MS = 5e3;
|
|
34887
34939
|
PLANS_DIR = claudeBackend.plansDir();
|
|
34888
34940
|
TASKS_DIR = claudeBackend.tasksDir();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "chat-recall",
|
|
3
|
-
"version": "0.7.
|
|
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
|
|
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
|
},
|
package/dist/mcp-relay.d.ts
DELETED
package/dist/mcp-relay.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"mcp-relay.d.ts","sourceRoot":"","sources":["../src/mcp-relay.ts"],"names":[],"mappings":""}
|