chat-recall 0.7.40 → 0.7.42

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.
@@ -1,27 +1,3 @@
1
- /**
2
- * Memory bound for the watch daemon (issue #16).
3
- *
4
- * The daemon is a thin collector with no local index, and its cgroup peak
5
- * reached 1.5 GiB. The measurement of 2026-11-13 showed that no object holds
6
- * the memory: a heap snapshot at 415 MB of resident anon memory held 55 MB of
7
- * live objects. The memory is V8 pages that V8 committed during churn and did
8
- * not return, plus allocator arenas.
9
- *
10
- * Two sources of churn dominate:
11
- * 1. one full listing of the sessions costs about 100 MB, and the daemon
12
- * listed them two or three times on every sync tick;
13
- * 2. the code-intelligence pass collects one workspace at a time and never
14
- * stops, so it adds a workspace on top of an already-full heap.
15
- *
16
- * This module gives the two bounds that stop the growth:
17
- * - `isOverMemoryLimit` stops a heavy pass at a set resident size and lets the
18
- * next tick continue the work, so the memory stays under the bound by
19
- * construction;
20
- * - `releaseMemory` returns the pages after a heavy unit (one workspace, one
21
- * walk target) when the daemon runs with `--expose-gc`.
22
- *
23
- * The limit is `CHAT_RECALL_WATCH_RSS_MAX_MB`, in MiB of resident memory.
24
- */
25
1
  /** Resident-size bound of the daemon, in MiB. */
26
2
  export declare const DEFAULT_RSS_MAX_MB = 512;
27
3
  /** Resident size of this process, in MiB. */
@@ -38,4 +14,19 @@ export declare function isOverMemoryLimit(rss: number, limitMb: number): boolean
38
14
  * which the tests use and the log lines do not.
39
15
  */
40
16
  export declare function releaseMemory(gc?: (() => void) | undefined): boolean;
17
+ /** The cgroup v2 directory of this process, or null when it has none. */
18
+ export declare function cgroupDir(cgroupFile?: string): string | null;
19
+ /** One key of `memory.stat`, in MiB, or null when it cannot be read. */
20
+ export declare function memoryStatMb(dir: string, key: string): number | null;
21
+ /**
22
+ * Ask the kernel to take back the page cache of this cgroup, and keep a floor.
23
+ *
24
+ * The pages are reclaimable, but they count in `memory.current` and in the
25
+ * cgroup peak. After a code-intelligence pass over 50 workspaces the watch unit
26
+ * held 775 MB of file pages, and that page cache was most of a 1.4 GiB peak
27
+ * while the live heap was small. The write needs no privilege when the user owns
28
+ * the cgroup. A failure is not an error: the kernel reclaims under pressure
29
+ * anyway, so this only makes the peak smaller sooner.
30
+ */
31
+ export declare function reclaimCgroup(keepFileMb?: number, dir?: string | null): boolean;
41
32
  //# sourceMappingURL=memory-guard.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"memory-guard.d.ts","sourceRoot":"","sources":["../src/memory-guard.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,iDAAiD;AACjD,eAAO,MAAM,kBAAkB,MAAM,CAAC;AAEtC,6CAA6C;AAC7C,wBAAgB,KAAK,IAAI,MAAM,CAE9B;AAED,+EAA+E;AAC/E,wBAAgB,aAAa,CAAC,GAAG,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAe,GAAG,MAAM,CAK3F;AAED,sDAAsD;AACtD,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAEvE;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,EAAE,GAAE,CAAC,MAAM,IAAI,CAAC,GAAG,SAAkD,GAAG,OAAO,CAI5G"}
1
+ {"version":3,"file":"memory-guard.d.ts","sourceRoot":"","sources":["../src/memory-guard.ts"],"names":[],"mappings":"AA6BA,iDAAiD;AACjD,eAAO,MAAM,kBAAkB,MAAM,CAAC;AAEtC,6CAA6C;AAC7C,wBAAgB,KAAK,IAAI,MAAM,CAE9B;AAED,+EAA+E;AAC/E,wBAAgB,aAAa,CAAC,GAAG,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAe,GAAG,MAAM,CAK3F;AAED,sDAAsD;AACtD,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAEvE;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,EAAE,GAAE,CAAC,MAAM,IAAI,CAAC,GAAG,SAAkD,GAAG,OAAO,CAI5G;AAED,yEAAyE;AACzE,wBAAgB,SAAS,CAAC,UAAU,SAAsB,GAAG,MAAM,GAAG,IAAI,CAMzE;AAED,wEAAwE;AACxE,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAQpE;AAED;;;;;;;;;GASG;AACH,wBAAgB,aAAa,CAAC,UAAU,SAAK,EAAE,GAAG,GAAE,MAAM,GAAG,IAAkB,GAAG,OAAO,CAOxF"}
@@ -18,10 +18,14 @@
18
18
  * next tick continue the work, so the memory stays under the bound by
19
19
  * construction;
20
20
  * - `releaseMemory` returns the pages after a heavy unit (one workspace, one
21
- * walk target) when the daemon runs with `--expose-gc`.
21
+ * walk target) when the daemon runs with `--expose-gc`;
22
+ * - `reclaimCgroup` takes back the page cache of the cgroup when a heavy pass
23
+ * ends, because the page cache of the pass counts in the cgroup peak.
22
24
  *
23
25
  * The limit is `CHAT_RECALL_WATCH_RSS_MAX_MB`, in MiB of resident memory.
24
26
  */
27
+ import { readFileSync, writeFileSync } from 'node:fs';
28
+ import { join } from 'node:path';
25
29
  /** Resident-size bound of the daemon, in MiB. */
26
30
  export const DEFAULT_RSS_MAX_MB = 512;
27
31
  /** Resident size of this process, in MiB. */
@@ -53,4 +57,61 @@ export function releaseMemory(gc = globalThis.gc) {
53
57
  gc();
54
58
  return true;
55
59
  }
60
+ /** The cgroup v2 directory of this process, or null when it has none. */
61
+ export function cgroupDir(cgroupFile = '/proc/self/cgroup') {
62
+ let text;
63
+ try {
64
+ text = readFileSync(cgroupFile, 'utf8');
65
+ }
66
+ catch {
67
+ return null;
68
+ }
69
+ const line = text.split('\n').find((l) => l.startsWith('0::'));
70
+ if (!line)
71
+ return null;
72
+ return `/sys/fs/cgroup${line.slice(3).trim()}`;
73
+ }
74
+ /** One key of `memory.stat`, in MiB, or null when it cannot be read. */
75
+ export function memoryStatMb(dir, key) {
76
+ let text;
77
+ try {
78
+ text = readFileSync(join(dir, 'memory.stat'), 'utf8');
79
+ }
80
+ catch {
81
+ return null;
82
+ }
83
+ for (const line of text.split('\n')) {
84
+ const [name, value] = line.split(' ');
85
+ if (name === key && value)
86
+ return Math.round(Number(value) / 1048576);
87
+ }
88
+ return null;
89
+ }
90
+ /**
91
+ * Ask the kernel to take back the page cache of this cgroup, and keep a floor.
92
+ *
93
+ * The pages are reclaimable, but they count in `memory.current` and in the
94
+ * cgroup peak. After a code-intelligence pass over 50 workspaces the watch unit
95
+ * held 775 MB of file pages, and that page cache was most of a 1.4 GiB peak
96
+ * while the live heap was small. The write needs no privilege when the user owns
97
+ * the cgroup. A failure is not an error: the kernel reclaims under pressure
98
+ * anyway, so this only makes the peak smaller sooner.
99
+ */
100
+ export function reclaimCgroup(keepFileMb = 64, dir = cgroupDir()) {
101
+ if (!dir)
102
+ return false;
103
+ const fileMb = memoryStatMb(dir, 'file');
104
+ if (fileMb === null)
105
+ return false;
106
+ const reclaimMb = Math.floor(fileMb - keepFileMb);
107
+ if (reclaimMb <= 0)
108
+ return false;
109
+ try {
110
+ writeFileSync(join(dir, 'memory.reclaim'), `${reclaimMb}M`);
111
+ return true;
112
+ }
113
+ catch {
114
+ return false;
115
+ }
116
+ }
56
117
  //# sourceMappingURL=memory-guard.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"memory-guard.js","sourceRoot":"","sources":["../src/memory-guard.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,iDAAiD;AACjD,MAAM,CAAC,MAAM,kBAAkB,GAAG,GAAG,CAAC;AAEtC,6CAA6C;AAC7C,MAAM,UAAU,KAAK;IACnB,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC,GAAG,GAAG,OAAO,CAAC,CAAC;AACzD,CAAC;AAED,+EAA+E;AAC/E,MAAM,UAAU,aAAa,CAAC,MAA0C,OAAO,CAAC,GAAG;IACjF,MAAM,GAAG,GAAG,GAAG,CAAC,4BAA4B,CAAC;IAC7C,IAAI,CAAC,GAAG;QAAE,OAAO,kBAAkB,CAAC;IACpC,MAAM,CAAC,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;IACtB,OAAO,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,kBAAkB,CAAC;AAC1E,CAAC;AAED,sDAAsD;AACtD,MAAM,UAAU,iBAAiB,CAAC,GAAW,EAAE,OAAe;IAC5D,OAAO,GAAG,IAAI,OAAO,CAAC;AACxB,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,aAAa,CAAC,KAAgC,UAAkC,CAAC,EAAE;IACjG,IAAI,OAAO,EAAE,KAAK,UAAU;QAAE,OAAO,KAAK,CAAC;IAC3C,EAAE,EAAE,CAAC;IACL,OAAO,IAAI,CAAC;AACd,CAAC"}
1
+ {"version":3,"file":"memory-guard.js","sourceRoot":"","sources":["../src/memory-guard.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACtD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,iDAAiD;AACjD,MAAM,CAAC,MAAM,kBAAkB,GAAG,GAAG,CAAC;AAEtC,6CAA6C;AAC7C,MAAM,UAAU,KAAK;IACnB,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC,GAAG,GAAG,OAAO,CAAC,CAAC;AACzD,CAAC;AAED,+EAA+E;AAC/E,MAAM,UAAU,aAAa,CAAC,MAA0C,OAAO,CAAC,GAAG;IACjF,MAAM,GAAG,GAAG,GAAG,CAAC,4BAA4B,CAAC;IAC7C,IAAI,CAAC,GAAG;QAAE,OAAO,kBAAkB,CAAC;IACpC,MAAM,CAAC,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;IACtB,OAAO,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,kBAAkB,CAAC;AAC1E,CAAC;AAED,sDAAsD;AACtD,MAAM,UAAU,iBAAiB,CAAC,GAAW,EAAE,OAAe;IAC5D,OAAO,GAAG,IAAI,OAAO,CAAC;AACxB,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,aAAa,CAAC,KAAgC,UAAkC,CAAC,EAAE;IACjG,IAAI,OAAO,EAAE,KAAK,UAAU;QAAE,OAAO,KAAK,CAAC;IAC3C,EAAE,EAAE,CAAC;IACL,OAAO,IAAI,CAAC;AACd,CAAC;AAED,yEAAyE;AACzE,MAAM,UAAU,SAAS,CAAC,UAAU,GAAG,mBAAmB;IACxD,IAAI,IAAY,CAAC;IACjB,IAAI,CAAC;QAAC,IAAI,GAAG,YAAY,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;IAAC,CAAC;IAAC,MAAM,CAAC;QAAC,OAAO,IAAI,CAAC;IAAC,CAAC;IACvE,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC;IAC/D,IAAI,CAAC,IAAI;QAAE,OAAO,IAAI,CAAC;IACvB,OAAO,iBAAiB,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC;AACjD,CAAC;AAED,wEAAwE;AACxE,MAAM,UAAU,YAAY,CAAC,GAAW,EAAE,GAAW;IACnD,IAAI,IAAY,CAAC;IACjB,IAAI,CAAC;QAAC,IAAI,GAAG,YAAY,CAAC,IAAI,CAAC,GAAG,EAAE,aAAa,CAAC,EAAE,MAAM,CAAC,CAAC;IAAC,CAAC;IAAC,MAAM,CAAC;QAAC,OAAO,IAAI,CAAC;IAAC,CAAC;IACrF,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC;QACpC,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QACtC,IAAI,IAAI,KAAK,GAAG,IAAI,KAAK;YAAE,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,OAAO,CAAC,CAAC;IACxE,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,aAAa,CAAC,UAAU,GAAG,EAAE,EAAE,MAAqB,SAAS,EAAE;IAC7E,IAAI,CAAC,GAAG;QAAE,OAAO,KAAK,CAAC;IACvB,MAAM,MAAM,GAAG,YAAY,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;IACzC,IAAI,MAAM,KAAK,IAAI;QAAE,OAAO,KAAK,CAAC;IAClC,MAAM,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,UAAU,CAAC,CAAC;IAClD,IAAI,SAAS,IAAI,CAAC;QAAE,OAAO,KAAK,CAAC;IACjC,IAAI,CAAC;QAAC,aAAa,CAAC,IAAI,CAAC,GAAG,EAAE,gBAAgB,CAAC,EAAE,GAAG,SAAS,GAAG,CAAC,CAAC;QAAC,OAAO,IAAI,CAAC;IAAC,CAAC;IAAC,MAAM,CAAC;QAAC,OAAO,KAAK,CAAC;IAAC,CAAC;AAC3G,CAAC"}
package/dist/watch.js CHANGED
@@ -2400,7 +2400,7 @@ var require_thread_stream = __commonJS({
2400
2400
  var { version } = require_package();
2401
2401
  var { EventEmitter } = __require("events");
2402
2402
  var { Worker: Worker2 } = __require("worker_threads");
2403
- var { join: join60 } = __require("path");
2403
+ var { join: join61 } = __require("path");
2404
2404
  var { pathToFileURL } = __require("url");
2405
2405
  var { wait } = require_wait();
2406
2406
  var {
@@ -2443,7 +2443,7 @@ var require_thread_stream = __commonJS({
2443
2443
  function createWorker(stream, opts) {
2444
2444
  const { filename, workerData } = opts;
2445
2445
  const bundlerOverrides = "__bundlerPathsOverrides" in globalThis ? globalThis.__bundlerPathsOverrides : {};
2446
- const toExecute = bundlerOverrides["thread-stream-worker"] || join60(__dirname, "lib", "worker.js");
2446
+ const toExecute = bundlerOverrides["thread-stream-worker"] || join61(__dirname, "lib", "worker.js");
2447
2447
  const worker = new Worker2(toExecute, {
2448
2448
  ...opts.workerOpts,
2449
2449
  trackUnmanagedFds: false,
@@ -2846,7 +2846,7 @@ var require_transport = __commonJS({
2846
2846
  "use strict";
2847
2847
  var { createRequire: createRequire4 } = __require("module");
2848
2848
  var getCallers = require_caller();
2849
- var { join: join60, isAbsolute: isAbsolute5, sep: sep5 } = __require("node:path");
2849
+ var { join: join61, isAbsolute: isAbsolute5, sep: sep5 } = __require("node:path");
2850
2850
  var sleep = require_atomic_sleep();
2851
2851
  var onExit = require_on_exit_leak_free();
2852
2852
  var ThreadStream = require_thread_stream();
@@ -2909,7 +2909,7 @@ var require_transport = __commonJS({
2909
2909
  throw new Error("only one of target or targets can be specified");
2910
2910
  }
2911
2911
  if (targets) {
2912
- target = bundlerOverrides["pino-worker"] || join60(__dirname, "worker.js");
2912
+ target = bundlerOverrides["pino-worker"] || join61(__dirname, "worker.js");
2913
2913
  options.targets = targets.filter((dest) => dest.target).map((dest) => {
2914
2914
  return {
2915
2915
  ...dest,
@@ -2927,7 +2927,7 @@ var require_transport = __commonJS({
2927
2927
  });
2928
2928
  });
2929
2929
  } else if (pipeline) {
2930
- target = bundlerOverrides["pino-worker"] || join60(__dirname, "worker.js");
2930
+ target = bundlerOverrides["pino-worker"] || join61(__dirname, "worker.js");
2931
2931
  options.pipelines = [pipeline.map((dest) => {
2932
2932
  return {
2933
2933
  ...dest,
@@ -2949,7 +2949,7 @@ var require_transport = __commonJS({
2949
2949
  return origin;
2950
2950
  }
2951
2951
  if (origin === "pino/file") {
2952
- return join60(__dirname, "..", "file.js");
2952
+ return join61(__dirname, "..", "file.js");
2953
2953
  }
2954
2954
  let fixTarget2;
2955
2955
  for (const filePath of callers) {
@@ -3938,7 +3938,7 @@ var require_safe_stable_stringify = __commonJS({
3938
3938
  return circularValue;
3939
3939
  }
3940
3940
  let res = "";
3941
- let join60 = ",";
3941
+ let join61 = ",";
3942
3942
  const originalIndentation = indentation;
3943
3943
  if (Array.isArray(value)) {
3944
3944
  if (value.length === 0) {
@@ -3952,7 +3952,7 @@ var require_safe_stable_stringify = __commonJS({
3952
3952
  indentation += spacer;
3953
3953
  res += `
3954
3954
  ${indentation}`;
3955
- join60 = `,
3955
+ join61 = `,
3956
3956
  ${indentation}`;
3957
3957
  }
3958
3958
  const maximumValuesToStringify = Math.min(value.length, maximumBreadth);
@@ -3960,13 +3960,13 @@ ${indentation}`;
3960
3960
  for (; i < maximumValuesToStringify - 1; i++) {
3961
3961
  const tmp2 = stringifyFnReplacer(String(i), value, stack, replacer, spacer, indentation);
3962
3962
  res += tmp2 !== void 0 ? tmp2 : "null";
3963
- res += join60;
3963
+ res += join61;
3964
3964
  }
3965
3965
  const tmp = stringifyFnReplacer(String(i), value, stack, replacer, spacer, indentation);
3966
3966
  res += tmp !== void 0 ? tmp : "null";
3967
3967
  if (value.length - 1 > maximumBreadth) {
3968
3968
  const removedKeys = value.length - maximumBreadth - 1;
3969
- res += `${join60}"... ${getItemCount(removedKeys)} not stringified"`;
3969
+ res += `${join61}"... ${getItemCount(removedKeys)} not stringified"`;
3970
3970
  }
3971
3971
  if (spacer !== "") {
3972
3972
  res += `
@@ -3987,7 +3987,7 @@ ${originalIndentation}`;
3987
3987
  let separator = "";
3988
3988
  if (spacer !== "") {
3989
3989
  indentation += spacer;
3990
- join60 = `,
3990
+ join61 = `,
3991
3991
  ${indentation}`;
3992
3992
  whitespace = " ";
3993
3993
  }
@@ -4001,13 +4001,13 @@ ${indentation}`;
4001
4001
  const tmp = stringifyFnReplacer(key3, value, stack, replacer, spacer, indentation);
4002
4002
  if (tmp !== void 0) {
4003
4003
  res += `${separator}${strEscape(key3)}:${whitespace}${tmp}`;
4004
- separator = join60;
4004
+ separator = join61;
4005
4005
  }
4006
4006
  }
4007
4007
  if (keyLength > maximumBreadth) {
4008
4008
  const removedKeys = keyLength - maximumBreadth;
4009
4009
  res += `${separator}"...":${whitespace}"${getItemCount(removedKeys)} not stringified"`;
4010
- separator = join60;
4010
+ separator = join61;
4011
4011
  }
4012
4012
  if (spacer !== "" && separator.length > 1) {
4013
4013
  res = `
@@ -4048,7 +4048,7 @@ ${originalIndentation}`;
4048
4048
  }
4049
4049
  const originalIndentation = indentation;
4050
4050
  let res = "";
4051
- let join60 = ",";
4051
+ let join61 = ",";
4052
4052
  if (Array.isArray(value)) {
4053
4053
  if (value.length === 0) {
4054
4054
  return "[]";
@@ -4061,7 +4061,7 @@ ${originalIndentation}`;
4061
4061
  indentation += spacer;
4062
4062
  res += `
4063
4063
  ${indentation}`;
4064
- join60 = `,
4064
+ join61 = `,
4065
4065
  ${indentation}`;
4066
4066
  }
4067
4067
  const maximumValuesToStringify = Math.min(value.length, maximumBreadth);
@@ -4069,13 +4069,13 @@ ${indentation}`;
4069
4069
  for (; i < maximumValuesToStringify - 1; i++) {
4070
4070
  const tmp2 = stringifyArrayReplacer(String(i), value[i], stack, replacer, spacer, indentation);
4071
4071
  res += tmp2 !== void 0 ? tmp2 : "null";
4072
- res += join60;
4072
+ res += join61;
4073
4073
  }
4074
4074
  const tmp = stringifyArrayReplacer(String(i), value[i], stack, replacer, spacer, indentation);
4075
4075
  res += tmp !== void 0 ? tmp : "null";
4076
4076
  if (value.length - 1 > maximumBreadth) {
4077
4077
  const removedKeys = value.length - maximumBreadth - 1;
4078
- res += `${join60}"... ${getItemCount(removedKeys)} not stringified"`;
4078
+ res += `${join61}"... ${getItemCount(removedKeys)} not stringified"`;
4079
4079
  }
4080
4080
  if (spacer !== "") {
4081
4081
  res += `
@@ -4088,7 +4088,7 @@ ${originalIndentation}`;
4088
4088
  let whitespace = "";
4089
4089
  if (spacer !== "") {
4090
4090
  indentation += spacer;
4091
- join60 = `,
4091
+ join61 = `,
4092
4092
  ${indentation}`;
4093
4093
  whitespace = " ";
4094
4094
  }
@@ -4097,7 +4097,7 @@ ${indentation}`;
4097
4097
  const tmp = stringifyArrayReplacer(key3, value[key3], stack, replacer, spacer, indentation);
4098
4098
  if (tmp !== void 0) {
4099
4099
  res += `${separator}${strEscape(key3)}:${whitespace}${tmp}`;
4100
- separator = join60;
4100
+ separator = join61;
4101
4101
  }
4102
4102
  }
4103
4103
  if (spacer !== "" && separator.length > 1) {
@@ -4155,20 +4155,20 @@ ${originalIndentation}`;
4155
4155
  indentation += spacer;
4156
4156
  let res2 = `
4157
4157
  ${indentation}`;
4158
- const join61 = `,
4158
+ const join62 = `,
4159
4159
  ${indentation}`;
4160
4160
  const maximumValuesToStringify = Math.min(value.length, maximumBreadth);
4161
4161
  let i = 0;
4162
4162
  for (; i < maximumValuesToStringify - 1; i++) {
4163
4163
  const tmp2 = stringifyIndent(String(i), value[i], stack, spacer, indentation);
4164
4164
  res2 += tmp2 !== void 0 ? tmp2 : "null";
4165
- res2 += join61;
4165
+ res2 += join62;
4166
4166
  }
4167
4167
  const tmp = stringifyIndent(String(i), value[i], stack, spacer, indentation);
4168
4168
  res2 += tmp !== void 0 ? tmp : "null";
4169
4169
  if (value.length - 1 > maximumBreadth) {
4170
4170
  const removedKeys = value.length - maximumBreadth - 1;
4171
- res2 += `${join61}"... ${getItemCount(removedKeys)} not stringified"`;
4171
+ res2 += `${join62}"... ${getItemCount(removedKeys)} not stringified"`;
4172
4172
  }
4173
4173
  res2 += `
4174
4174
  ${originalIndentation}`;
@@ -4184,16 +4184,16 @@ ${originalIndentation}`;
4184
4184
  return '"[Object]"';
4185
4185
  }
4186
4186
  indentation += spacer;
4187
- const join60 = `,
4187
+ const join61 = `,
4188
4188
  ${indentation}`;
4189
4189
  let res = "";
4190
4190
  let separator = "";
4191
4191
  let maximumPropertiesToStringify = Math.min(keyLength, maximumBreadth);
4192
4192
  if (isTypedArrayWithEntries(value)) {
4193
- res += stringifyTypedArray(value, join60, maximumBreadth);
4193
+ res += stringifyTypedArray(value, join61, maximumBreadth);
4194
4194
  keys = keys.slice(value.length);
4195
4195
  maximumPropertiesToStringify -= value.length;
4196
- separator = join60;
4196
+ separator = join61;
4197
4197
  }
4198
4198
  if (deterministic) {
4199
4199
  keys = sort(keys, comparator);
@@ -4204,13 +4204,13 @@ ${indentation}`;
4204
4204
  const tmp = stringifyIndent(key3, value[key3], stack, spacer, indentation);
4205
4205
  if (tmp !== void 0) {
4206
4206
  res += `${separator}${strEscape(key3)}: ${tmp}`;
4207
- separator = join60;
4207
+ separator = join61;
4208
4208
  }
4209
4209
  }
4210
4210
  if (keyLength > maximumBreadth) {
4211
4211
  const removedKeys = keyLength - maximumBreadth;
4212
4212
  res += `${separator}"...": "${getItemCount(removedKeys)} not stringified"`;
4213
- separator = join60;
4213
+ separator = join61;
4214
4214
  }
4215
4215
  if (separator !== "") {
4216
4216
  res = `
@@ -7113,11 +7113,11 @@ async function archiveRawSession(store, sessionId) {
7113
7113
  return await store.putRawSession(sessionId, exp.tool, Math.floor(exp.mtime), gz, size);
7114
7114
  }
7115
7115
  function detectForkPredecessor(sessionPath) {
7116
- const { readFileSync: readFileSync52, readdirSync: readdirSync35 } = requireFs();
7117
- const { dirname: dirname26, join: join60, basename: basename28 } = requirePath();
7116
+ const { readFileSync: readFileSync53, readdirSync: readdirSync35 } = requireFs();
7117
+ const { dirname: dirname26, join: join61, basename: basename28 } = requirePath();
7118
7118
  let text;
7119
7119
  try {
7120
- text = readFileSync52(sessionPath, "utf-8");
7120
+ text = readFileSync53(sessionPath, "utf-8");
7121
7121
  } catch {
7122
7122
  return null;
7123
7123
  }
@@ -7151,7 +7151,7 @@ function detectForkPredecessor(sessionPath) {
7151
7151
  if (!f.endsWith(".jsonl") || f === self || f === "sessions-index.json")
7152
7152
  continue;
7153
7153
  try {
7154
- if (readFileSync52(join60(dir, f), "utf-8").includes(`"uuid":"${headParent}"`)) {
7154
+ if (readFileSync53(join61(dir, f), "utf-8").includes(`"uuid":"${headParent}"`)) {
7155
7155
  return basename28(f, ".jsonl");
7156
7156
  }
7157
7157
  } catch {
@@ -30776,6 +30776,8 @@ var init_sync_client = __esm({
30776
30776
  });
30777
30777
 
30778
30778
  // src/memory-guard.ts
30779
+ import { readFileSync as readFileSync42, writeFileSync as writeFileSync11 } from "node:fs";
30780
+ import { join as join48 } from "node:path";
30779
30781
  function rssMb() {
30780
30782
  return Math.round(process.memoryUsage().rss / 1048576);
30781
30783
  }
@@ -30793,6 +30795,43 @@ function releaseMemory(gc = globalThis.gc) {
30793
30795
  gc();
30794
30796
  return true;
30795
30797
  }
30798
+ function cgroupDir(cgroupFile = "/proc/self/cgroup") {
30799
+ let text;
30800
+ try {
30801
+ text = readFileSync42(cgroupFile, "utf8");
30802
+ } catch {
30803
+ return null;
30804
+ }
30805
+ const line = text.split("\n").find((l) => l.startsWith("0::"));
30806
+ if (!line) return null;
30807
+ return `/sys/fs/cgroup${line.slice(3).trim()}`;
30808
+ }
30809
+ function memoryStatMb(dir, key2) {
30810
+ let text;
30811
+ try {
30812
+ text = readFileSync42(join48(dir, "memory.stat"), "utf8");
30813
+ } catch {
30814
+ return null;
30815
+ }
30816
+ for (const line of text.split("\n")) {
30817
+ const [name, value] = line.split(" ");
30818
+ if (name === key2 && value) return Math.round(Number(value) / 1048576);
30819
+ }
30820
+ return null;
30821
+ }
30822
+ function reclaimCgroup(keepFileMb = 64, dir = cgroupDir()) {
30823
+ if (!dir) return false;
30824
+ const fileMb = memoryStatMb(dir, "file");
30825
+ if (fileMb === null) return false;
30826
+ const reclaimMb = Math.floor(fileMb - keepFileMb);
30827
+ if (reclaimMb <= 0) return false;
30828
+ try {
30829
+ writeFileSync11(join48(dir, "memory.reclaim"), `${reclaimMb}M`);
30830
+ return true;
30831
+ } catch {
30832
+ return false;
30833
+ }
30834
+ }
30796
30835
  var DEFAULT_RSS_MAX_MB;
30797
30836
  var init_memory_guard = __esm({
30798
30837
  "src/memory-guard.ts"() {
@@ -30802,8 +30841,8 @@ var init_memory_guard = __esm({
30802
30841
  });
30803
30842
 
30804
30843
  // ../engine/dist/core/artifact-codec.js
30805
- import { readFileSync as readFileSync42 } from "fs";
30806
- import { basename as basename23, join as join48 } from "path";
30844
+ import { readFileSync as readFileSync43 } from "fs";
30845
+ import { basename as basename23, join as join49 } from "path";
30807
30846
  import { homedir as homedir17 } from "os";
30808
30847
  function parseCommandText(content, format, fallbackName) {
30809
30848
  if (format === "toml") {
@@ -30826,30 +30865,30 @@ function parseAgentText(content, format, fallbackName) {
30826
30865
  return { name: fm.name || fallbackName, description: fm.description || "", tools: fm.tools, body: body.trim() };
30827
30866
  }
30828
30867
  function readCommand(filePath, format) {
30829
- return parseCommandText(readFileSync42(filePath, "utf-8"), format, base2(filePath));
30868
+ return parseCommandText(readFileSync43(filePath, "utf-8"), format, base2(filePath));
30830
30869
  }
30831
30870
  function readAgent(filePath, format) {
30832
- return parseAgentText(readFileSync42(filePath, "utf-8"), format, base2(filePath));
30871
+ return parseAgentText(readFileSync43(filePath, "utf-8"), format, base2(filePath));
30833
30872
  }
30834
30873
  function readInstructions(filePath, name) {
30835
- const content = readFileSync42(filePath, "utf-8");
30874
+ const content = readFileSync43(filePath, "utf-8");
30836
30875
  return { name, description: "", body: content };
30837
30876
  }
30838
30877
  function commandPath(tool, name) {
30839
30878
  switch (tool) {
30840
30879
  case "claude":
30841
- return join48(claudeBackend.commandsDir(), `${name}.md`);
30880
+ return join49(claudeBackend.commandsDir(), `${name}.md`);
30842
30881
  case "agy":
30843
- return join48(join48(agyBackend.homeDir(), "commands"), `${name}.toml`);
30882
+ return join49(join49(agyBackend.homeDir(), "commands"), `${name}.toml`);
30844
30883
  case "opencode":
30845
- return join48(opencodeBackend.commandsDir(), `${name}.md`);
30884
+ return join49(opencodeBackend.commandsDir(), `${name}.md`);
30846
30885
  case "codex":
30847
- return join48(codexBackend.promptsDir(), `${name}.md`);
30886
+ return join49(codexBackend.promptsDir(), `${name}.md`);
30848
30887
  case "cursor":
30849
- return join48(cursorHomeDir(), "commands", `${name}.md`);
30888
+ return join49(cursorHomeDir(), "commands", `${name}.md`);
30850
30889
  // Pi's prompt templates are flat *.md files in the agent dir.
30851
30890
  case "pi":
30852
- return join48(piBackend.promptsDir(), `${name}.md`);
30891
+ return join49(piBackend.promptsDir(), `${name}.md`);
30853
30892
  // Hermes has no command files. copyArtifactToTool refuses this target first.
30854
30893
  case "hermes":
30855
30894
  throw new Error("Hermes has no command files");
@@ -30858,15 +30897,15 @@ function commandPath(tool, name) {
30858
30897
  function agentPath(tool, name) {
30859
30898
  switch (tool) {
30860
30899
  case "claude":
30861
- return join48(claudeBackend.agentsDir(), `${name}.md`);
30900
+ return join49(claudeBackend.agentsDir(), `${name}.md`);
30862
30901
  case "agy":
30863
- return join48(join48(agyBackend.homeDir(), "agents"), `${name}.md`);
30902
+ return join49(join49(agyBackend.homeDir(), "agents"), `${name}.md`);
30864
30903
  case "opencode":
30865
- return join48(opencodeBackend.agentsDir(), `${name}.md`);
30904
+ return join49(opencodeBackend.agentsDir(), `${name}.md`);
30866
30905
  case "codex":
30867
- return join48(codexBackend.agentsDir(), `${name}.toml`);
30906
+ return join49(codexBackend.agentsDir(), `${name}.toml`);
30868
30907
  case "cursor":
30869
- return join48(cursorHomeDir(), "agents", `${name}.md`);
30908
+ return join49(cursorHomeDir(), "agents", `${name}.md`);
30870
30909
  // Pi has no named agent personas. copyArtifactToTool refuses this target first.
30871
30910
  case "pi":
30872
30911
  throw new Error("Pi has no agent files");
@@ -30903,23 +30942,23 @@ function instructionsFilename(tool) {
30903
30942
  function instructionsPath(tool, projectPath) {
30904
30943
  const file = instructionsFilename(tool);
30905
30944
  if (projectPath)
30906
- return join48(projectPath, file);
30945
+ return join49(projectPath, file);
30907
30946
  switch (tool) {
30908
30947
  case "claude":
30909
- return join48(claudeBackend.homeDir(), file);
30948
+ return join49(claudeBackend.homeDir(), file);
30910
30949
  case "agy":
30911
- return join48(agyBackend.homeDir(), file);
30950
+ return join49(agyBackend.homeDir(), file);
30912
30951
  case "codex":
30913
- return join48(codexBackend.homeDir(), file);
30952
+ return join49(codexBackend.homeDir(), file);
30914
30953
  case "opencode":
30915
- return join48(homedir17(), ".config", "opencode", file);
30954
+ return join49(homedir17(), ".config", "opencode", file);
30916
30955
  // Cursor has no single user-scope instructions FILE — user-level guidance
30917
30956
  // is User Rules plus ~/.cursor/rules/*.mdc. AGENTS.md at the home root is
30918
30957
  // the closest equivalent and is what a mirror can actually write.
30919
30958
  case "cursor":
30920
- return join48(cursorHomeDir(), file);
30959
+ return join49(cursorHomeDir(), file);
30921
30960
  case "pi":
30922
- return join48(piBackend.homeDir(), file);
30961
+ return join49(piBackend.homeDir(), file);
30923
30962
  case "hermes":
30924
30963
  throw new Error("Hermes has no instruction file mapping");
30925
30964
  }
@@ -30968,8 +31007,8 @@ var init_artifact_codec = __esm({
30968
31007
  });
30969
31008
 
30970
31009
  // ../engine/dist/core/toolkit-sync.js
30971
- import { existsSync as existsSync44, mkdirSync as mkdirSync12, readFileSync as readFileSync43, readdirSync as readdirSync33, writeFileSync as writeFileSync11, cpSync, rmSync as rmSync8 } from "fs";
30972
- import { dirname as dirname20, join as join49, basename as basename24 } from "path";
31010
+ import { existsSync as existsSync44, mkdirSync as mkdirSync12, readFileSync as readFileSync44, readdirSync as readdirSync33, writeFileSync as writeFileSync12, cpSync, rmSync as rmSync8 } from "fs";
31011
+ import { dirname as dirname20, join as join50, basename as basename24 } from "path";
30973
31012
  import { homedir as homedir18 } from "os";
30974
31013
  function rowFromMemoryItem(type, item) {
30975
31014
  const extra = item.extra || {};
@@ -30990,16 +31029,16 @@ function skillsDirFor(tool) {
30990
31029
  case "claude":
30991
31030
  return claudeBackend.skillsDir();
30992
31031
  case "agy":
30993
- return join49(agyBackend.homeDir(), "skills");
31032
+ return join50(agyBackend.homeDir(), "skills");
30994
31033
  case "opencode":
30995
31034
  return opencodeBackend.skillsDir();
30996
31035
  case "codex":
30997
31036
  return codexBackend.skillsDir();
30998
31037
  // user skills, NOT .system
30999
31038
  case "cursor":
31000
- return join49(cursorHomeDir(), "skills");
31039
+ return join50(cursorHomeDir(), "skills");
31001
31040
  case "hermes":
31002
- return join49(hermesBackend.homeDir(), "skills");
31041
+ return join50(hermesBackend.homeDir(), "skills");
31003
31042
  case "pi":
31004
31043
  return piBackend.skillsDir();
31005
31044
  }
@@ -31007,13 +31046,13 @@ function skillsDirFor(tool) {
31007
31046
  function skillDirsNamed(tool, name) {
31008
31047
  const root = skillsDirFor(tool);
31009
31048
  const found = [];
31010
- if (existsSync44(join49(root, name)))
31011
- found.push(join49(root, name));
31049
+ if (existsSync44(join50(root, name)))
31050
+ found.push(join50(root, name));
31012
31051
  if (tool !== "hermes" || !existsSync44(root))
31013
31052
  return found;
31014
31053
  for (const category of readdirSync33(root)) {
31015
- const candidate = join49(root, category, name);
31016
- if (existsSync44(join49(candidate, "SKILL.md")))
31054
+ const candidate = join50(root, category, name);
31055
+ if (existsSync44(join50(candidate, "SKILL.md")))
31017
31056
  found.push(candidate);
31018
31057
  }
31019
31058
  return found;
@@ -31023,7 +31062,7 @@ function copySkill(row, toTool) {
31023
31062
  if (!existsSync44(skillDir))
31024
31063
  return { ok: false, status: 404, error: `Source dir missing: ${skillDir}` };
31025
31064
  const name = row.extra.skillName || basename24(skillDir);
31026
- const targetDir = join49(skillsDirFor(toTool), name);
31065
+ const targetDir = join50(skillsDirFor(toTool), name);
31027
31066
  const existing = skillDirsNamed(toTool, name);
31028
31067
  if (existing.length)
31029
31068
  return { ok: false, status: 409, error: `Already exists: ${existing[0]}` };
@@ -31040,22 +31079,22 @@ function mcpJsonCandidates(tool) {
31040
31079
  switch (tool) {
31041
31080
  case "claude":
31042
31081
  return [
31043
- { path: join49(home, ".mcp.json"), key: "mcpServers" },
31044
- { path: join49(home, ".claude.json"), key: "mcpServers" }
31082
+ { path: join50(home, ".mcp.json"), key: "mcpServers" },
31083
+ { path: join50(home, ".claude.json"), key: "mcpServers" }
31045
31084
  ];
31046
31085
  case "gemini":
31047
- return [{ path: join49(home, ".gemini", "settings.json"), key: "mcpServers" }];
31086
+ return [{ path: join50(home, ".gemini", "settings.json"), key: "mcpServers" }];
31048
31087
  case "agy":
31049
- return [{ path: join49(home, ".gemini", "config", "mcp_config.json"), key: "mcpServers" }];
31088
+ return [{ path: join50(home, ".gemini", "config", "mcp_config.json"), key: "mcpServers" }];
31050
31089
  case "cursor":
31051
- return [{ path: join49(cursorHomeDir(), "mcp.json"), key: "mcpServers" }];
31090
+ return [{ path: join50(cursorHomeDir(), "mcp.json"), key: "mcpServers" }];
31052
31091
  case "pi":
31053
31092
  return [{ path: piMcpConfigPath(), key: "mcpServers" }];
31054
31093
  case "opencode":
31055
31094
  return [
31056
- { path: join49(home, ".config", "opencode", "opencode.json"), key: "mcp" },
31057
- { path: join49(home, ".config", "opencode", "config.json"), key: "mcp" },
31058
- { path: join49(home, ".opencode", "config.json"), key: "mcp" }
31095
+ { path: join50(home, ".config", "opencode", "opencode.json"), key: "mcp" },
31096
+ { path: join50(home, ".config", "opencode", "config.json"), key: "mcp" },
31097
+ { path: join50(home, ".opencode", "config.json"), key: "mcp" }
31059
31098
  ];
31060
31099
  default:
31061
31100
  return [];
@@ -31063,14 +31102,14 @@ function mcpJsonCandidates(tool) {
31063
31102
  }
31064
31103
  function readMcpEntry(tool, name) {
31065
31104
  if (tool === "codex")
31066
- return readCodexMcpEntry(join49(homedir18(), ".codex", "config.toml"), name);
31105
+ return readCodexMcpEntry(join50(homedir18(), ".codex", "config.toml"), name);
31067
31106
  if (tool === "hermes")
31068
31107
  return readHermesMcpServers()?.[name] ?? null;
31069
31108
  for (const t of mcpJsonCandidates(tool)) {
31070
31109
  if (!existsSync44(t.path))
31071
31110
  continue;
31072
31111
  try {
31073
- const cfg = JSON.parse(readFileSync43(t.path, "utf-8"));
31112
+ const cfg = JSON.parse(readFileSync44(t.path, "utf-8"));
31074
31113
  const block = cfg[t.key] || {};
31075
31114
  if (block[name])
31076
31115
  return block[name];
@@ -31084,7 +31123,7 @@ function readCodexMcpEntry(path, target) {
31084
31123
  return null;
31085
31124
  let content;
31086
31125
  try {
31087
- content = readFileSync43(path, "utf-8");
31126
+ content = readFileSync44(path, "utf-8");
31088
31127
  } catch {
31089
31128
  return null;
31090
31129
  }
@@ -31135,7 +31174,7 @@ function readCodexMcpEntry(path, target) {
31135
31174
  function writeCodexMcpEntry(path, name, entry) {
31136
31175
  let content = "";
31137
31176
  if (existsSync44(path))
31138
- content = readFileSync43(path, "utf-8");
31177
+ content = readFileSync44(path, "utf-8");
31139
31178
  const header = `[mcp_servers.${name}]`;
31140
31179
  if (content.includes(header))
31141
31180
  return false;
@@ -31165,7 +31204,7 @@ function writeCodexMcpEntry(path, name, entry) {
31165
31204
  lines.push(`${k} = ${escape(String(v))}`);
31166
31205
  }
31167
31206
  mkdirSync12(dirname20(path), { recursive: true });
31168
- writeFileSync11(path, content + lines.join("\n") + "\n");
31207
+ writeFileSync12(path, content + lines.join("\n") + "\n");
31169
31208
  return true;
31170
31209
  }
31171
31210
  function writeMcpEntry(toTool, name, entry) {
@@ -31173,7 +31212,7 @@ function writeMcpEntry(toTool, name, entry) {
31173
31212
  return writeHermesMcp(name, entry);
31174
31213
  const home = homedir18();
31175
31214
  if (toTool === "codex") {
31176
- const path2 = join49(home, ".codex", "config.toml");
31215
+ const path2 = join50(home, ".codex", "config.toml");
31177
31216
  if (!writeCodexMcpEntry(path2, name, entry))
31178
31217
  return { ok: false, status: 409, error: `MCP "${name}" already exists in ${path2}.` };
31179
31218
  return { ok: true, targetPath: path2 };
@@ -31181,25 +31220,25 @@ function writeMcpEntry(toTool, name, entry) {
31181
31220
  let path;
31182
31221
  let key2;
31183
31222
  if (toTool === "claude") {
31184
- path = join49(home, ".mcp.json");
31223
+ path = join50(home, ".mcp.json");
31185
31224
  key2 = "mcpServers";
31186
31225
  } else if (toTool === "agy") {
31187
- path = join49(home, ".gemini", "config", "mcp_config.json");
31226
+ path = join50(home, ".gemini", "config", "mcp_config.json");
31188
31227
  key2 = "mcpServers";
31189
31228
  } else if (toTool === "cursor") {
31190
- path = join49(cursorHomeDir(), "mcp.json");
31229
+ path = join50(cursorHomeDir(), "mcp.json");
31191
31230
  key2 = "mcpServers";
31192
31231
  } else if (toTool === "pi") {
31193
31232
  path = piMcpConfigPath();
31194
31233
  key2 = "mcpServers";
31195
31234
  } else {
31196
- path = join49(home, ".config", "opencode", "opencode.json");
31235
+ path = join50(home, ".config", "opencode", "opencode.json");
31197
31236
  key2 = "mcp";
31198
31237
  }
31199
31238
  let cfg = {};
31200
31239
  if (existsSync44(path)) {
31201
31240
  try {
31202
- cfg = JSON.parse(readFileSync43(path, "utf-8"));
31241
+ cfg = JSON.parse(readFileSync44(path, "utf-8"));
31203
31242
  } catch {
31204
31243
  return { ok: false, status: 500, error: `Target config is malformed: ${path}` };
31205
31244
  }
@@ -31231,7 +31270,7 @@ function writeMcpEntry(toTool, name, entry) {
31231
31270
  }
31232
31271
  cfg[key2][name] = normalized;
31233
31272
  try {
31234
- writeFileSync11(path, JSON.stringify(cfg, null, 2));
31273
+ writeFileSync12(path, JSON.stringify(cfg, null, 2));
31235
31274
  return { ok: true, targetPath: path };
31236
31275
  } catch (e) {
31237
31276
  return { ok: false, status: 500, error: e instanceof Error ? e.message : "write failed" };
@@ -31265,7 +31304,7 @@ function copyCommandOrAgent(type, row, toTool) {
31265
31304
  return { ok: false, status: 409, error: `Already exists: ${out.path}` };
31266
31305
  try {
31267
31306
  mkdirSync12(dirname20(out.path), { recursive: true });
31268
- writeFileSync11(out.path, out.content);
31307
+ writeFileSync12(out.path, out.content);
31269
31308
  return { ok: true, targetPath: out.path };
31270
31309
  } catch (e) {
31271
31310
  return { ok: false, status: 500, error: e instanceof Error ? e.message : "write failed" };
@@ -31285,7 +31324,7 @@ function copyInstructions(row, toTool) {
31285
31324
  return { ok: false, status: 409, error: `Already exists: ${out.path}` };
31286
31325
  try {
31287
31326
  mkdirSync12(dirname20(out.path), { recursive: true });
31288
- writeFileSync11(out.path, out.content);
31327
+ writeFileSync12(out.path, out.content);
31289
31328
  return { ok: true, targetPath: out.path };
31290
31329
  } catch (e) {
31291
31330
  return { ok: false, status: 500, error: e instanceof Error ? e.message : "write failed" };
@@ -31298,11 +31337,11 @@ function writeHermesMcp(name, entry) {
31298
31337
  if (!existsSync44(path))
31299
31338
  return { ok: false, status: 404, error: `${path} not found` };
31300
31339
  try {
31301
- const after = addHermesMcpServer(readFileSync43(path, "utf-8"), name, hermesServerEntry(entry));
31340
+ const after = addHermesMcpServer(readFileSync44(path, "utf-8"), name, hermesServerEntry(entry));
31302
31341
  if (after === null)
31303
31342
  return { ok: false, status: 409, error: `MCP "${name}" already exists in ${path}` };
31304
31343
  const backupPaths = [backupToTrash(path, `mcp-hermes-${name}-config.yaml`)];
31305
- writeFileSync11(path, after);
31344
+ writeFileSync12(path, after);
31306
31345
  return { ok: true, targetPath: path, backupPaths };
31307
31346
  } catch (e) {
31308
31347
  return removeFailed(e, "write failed");
@@ -31337,7 +31376,7 @@ async function removeArtifactFromTool(type, name, tool) {
31337
31376
  return removeCommandOrAgent(type, name, tool);
31338
31377
  }
31339
31378
  function backupToTrash(src, label) {
31340
- const dest = join49(getDataDir(), "trash", `${Date.now()}-${label.replace(/[^A-Za-z0-9._-]/g, "_")}`);
31379
+ const dest = join50(getDataDir(), "trash", `${Date.now()}-${label.replace(/[^A-Za-z0-9._-]/g, "_")}`);
31341
31380
  mkdirSync12(dirname20(dest), { recursive: true });
31342
31381
  cpSync(src, dest, { recursive: true });
31343
31382
  return dest;
@@ -31348,7 +31387,7 @@ function removeFailed(e, fallback) {
31348
31387
  function removeSkill(name, tool) {
31349
31388
  const found = skillDirsNamed(tool, name);
31350
31389
  if (found.length === 0)
31351
- return { ok: false, status: 404, error: `Not found: ${join49(skillsDirFor(tool), name)}` };
31390
+ return { ok: false, status: 404, error: `Not found: ${join50(skillsDirFor(tool), name)}` };
31352
31391
  if (found.length > 1)
31353
31392
  return { ok: false, status: 409, error: `${found.length} skills named "${name}" for ${tool}; none removed` };
31354
31393
  const dir = found[0];
@@ -31385,27 +31424,27 @@ function removeMcp(name, tool) {
31385
31424
  if (!existsSync44(path))
31386
31425
  return { ok: false, status: 404, error: `${path} not found` };
31387
31426
  try {
31388
- const after = deleteHermesMcpServer(readFileSync43(path, "utf-8"), name);
31427
+ const after = deleteHermesMcpServer(readFileSync44(path, "utf-8"), name);
31389
31428
  if (after === null)
31390
31429
  return { ok: false, status: 404, error: `MCP "${name}" not found in ${path}` };
31391
31430
  const backupPaths2 = [backupToTrash(path, `mcp-hermes-${name}-config.yaml`)];
31392
- writeFileSync11(path, after);
31431
+ writeFileSync12(path, after);
31393
31432
  return { ok: true, targetPath: path, backupPaths: backupPaths2 };
31394
31433
  } catch (e) {
31395
31434
  return removeFailed(e, "write failed");
31396
31435
  }
31397
31436
  }
31398
31437
  if (tool === "codex") {
31399
- const path = join49(homedir18(), ".codex", "config.toml");
31438
+ const path = join50(homedir18(), ".codex", "config.toml");
31400
31439
  if (!existsSync44(path))
31401
31440
  return { ok: false, status: 404, error: "config.toml not found" };
31402
- const before = readFileSync43(path, "utf-8");
31441
+ const before = readFileSync44(path, "utf-8");
31403
31442
  const after = stripCodexMcpBlock(before, name);
31404
31443
  if (before === after)
31405
31444
  return { ok: false, status: 404, error: `MCP "${name}" not found in ${path}` };
31406
31445
  try {
31407
31446
  const backupPaths2 = [backupToTrash(path, `mcp-codex-${name}`)];
31408
- writeFileSync11(path, after);
31447
+ writeFileSync12(path, after);
31409
31448
  return { ok: true, targetPath: path, backupPaths: backupPaths2 };
31410
31449
  } catch (e) {
31411
31450
  return removeFailed(e, "write failed");
@@ -31417,12 +31456,12 @@ function removeMcp(name, tool) {
31417
31456
  if (!existsSync44(c.path))
31418
31457
  continue;
31419
31458
  try {
31420
- const cfg = JSON.parse(readFileSync43(c.path, "utf-8"));
31459
+ const cfg = JSON.parse(readFileSync44(c.path, "utf-8"));
31421
31460
  if (!cfg[c.key]?.[name])
31422
31461
  continue;
31423
31462
  backupPaths.push(backupToTrash(c.path, `mcp-${tool}-${name}-${basename24(c.path)}`));
31424
31463
  delete cfg[c.key][name];
31425
- writeFileSync11(c.path, JSON.stringify(cfg, null, 2));
31464
+ writeFileSync12(c.path, JSON.stringify(cfg, null, 2));
31426
31465
  if (!removedFrom)
31427
31466
  removedFrom = c.path;
31428
31467
  } catch (e) {
@@ -31595,8 +31634,8 @@ var init_code_task_status = __esm({
31595
31634
  });
31596
31635
 
31597
31636
  // src/project-tasks.ts
31598
- import { existsSync as existsSync45, readFileSync as readFileSync44, writeFileSync as writeFileSync12, mkdirSync as mkdirSync13, statSync as statSync42 } from "node:fs";
31599
- import { join as join50, dirname as dirname21 } from "node:path";
31637
+ import { existsSync as existsSync45, readFileSync as readFileSync45, writeFileSync as writeFileSync13, mkdirSync as mkdirSync13, statSync as statSync42 } from "node:fs";
31638
+ import { join as join51, dirname as dirname21 } from "node:path";
31600
31639
  import { homedir as homedir19 } from "node:os";
31601
31640
  function isTeamTaskStatus(v) {
31602
31641
  return !!v && TEAM_STATUSES.has(v);
@@ -31647,11 +31686,11 @@ function parseTaskFile(content) {
31647
31686
  return out;
31648
31687
  }
31649
31688
  function ledgerPath2() {
31650
- return join50(homedir19(), ".chat-recall", "project-tasks-ledger.json");
31689
+ return join51(homedir19(), ".chat-recall", "project-tasks-ledger.json");
31651
31690
  }
31652
31691
  function readLedger() {
31653
31692
  try {
31654
- return JSON.parse(readFileSync44(ledgerPath2(), "utf8"));
31693
+ return JSON.parse(readFileSync45(ledgerPath2(), "utf8"));
31655
31694
  } catch {
31656
31695
  return {};
31657
31696
  }
@@ -31662,7 +31701,7 @@ function writeLedger(l) {
31662
31701
  } catch {
31663
31702
  }
31664
31703
  try {
31665
- writeFileSync12(ledgerPath2(), JSON.stringify(l));
31704
+ writeFileSync13(ledgerPath2(), JSON.stringify(l));
31666
31705
  } catch {
31667
31706
  }
31668
31707
  }
@@ -31680,7 +31719,7 @@ async function pushProjectTaskStatuses(base3, authHeaders, opts = {}) {
31680
31719
  continue;
31681
31720
  }
31682
31721
  for (const project of projects) {
31683
- const file = join50(project, fk.filename);
31722
+ const file = join51(project, fk.filename);
31684
31723
  if (!existsSync45(file)) continue;
31685
31724
  let mtime;
31686
31725
  try {
@@ -31691,7 +31730,7 @@ async function pushProjectTaskStatuses(base3, authHeaders, opts = {}) {
31691
31730
  if (ledger[file] === mtime) continue;
31692
31731
  let changed;
31693
31732
  try {
31694
- changed = parseTaskFile(readFileSync44(file, "utf8")).filter((t) => t.kind === fk.kind);
31733
+ changed = parseTaskFile(readFileSync45(file, "utf8")).filter((t) => t.kind === fk.kind);
31695
31734
  } catch {
31696
31735
  continue;
31697
31736
  }
@@ -31739,7 +31778,7 @@ var init_project_tasks = __esm({
31739
31778
 
31740
31779
  // ../engine/dist/core/which.js
31741
31780
  import { existsSync as existsSync46, statSync as statSync43, accessSync, constants } from "node:fs";
31742
- import { join as join51, isAbsolute as isAbsolute3, delimiter as delimiter2, sep as sep3 } from "node:path";
31781
+ import { join as join52, isAbsolute as isAbsolute3, delimiter as delimiter2, sep as sep3 } from "node:path";
31743
31782
  function executable(p) {
31744
31783
  try {
31745
31784
  if (!statSync43(p).isFile())
@@ -31778,7 +31817,7 @@ function resolveOnPath(name) {
31778
31817
  if (!dir)
31779
31818
  continue;
31780
31819
  for (const c of candidates(name)) {
31781
- const full = join51(dir, c);
31820
+ const full = join52(dir, c);
31782
31821
  if (existsSync46(full) && executable(full))
31783
31822
  return full;
31784
31823
  }
@@ -31805,8 +31844,8 @@ __export(toolkit_pull_exports, {
31805
31844
  platformRefusal: () => platformRefusal,
31806
31845
  portableCommand: () => portableCommand
31807
31846
  });
31808
- import { existsSync as existsSync47, mkdirSync as mkdirSync14, statSync as statSync44, writeFileSync as writeFileSync13 } from "node:fs";
31809
- import { dirname as dirname22, join as join52, basename as basename25, isAbsolute as isAbsolute4 } from "node:path";
31847
+ import { existsSync as existsSync47, mkdirSync as mkdirSync14, statSync as statSync44, writeFileSync as writeFileSync14 } from "node:fs";
31848
+ import { dirname as dirname22, join as join53, basename as basename25, isAbsolute as isAbsolute4 } from "node:path";
31810
31849
  function isExecutableFile(p) {
31811
31850
  try {
31812
31851
  return statSync44(p).isFile();
@@ -31976,8 +32015,8 @@ function executePull(rows, opts = {}) {
31976
32015
  const outcomes = [];
31977
32016
  for (const { name, body, truncated, redacted, tools } of skills) {
31978
32017
  for (const tool of tools) {
31979
- const dir = join52(skillsDirFor(tool), name);
31980
- const file = join52(dir, "SKILL.md");
32018
+ const dir = join53(skillsDirFor(tool), name);
32019
+ const file = join53(dir, "SKILL.md");
31981
32020
  if (existsSync47(file)) {
31982
32021
  outcomes.push({ type: "skill", name, tool, status: "present" });
31983
32022
  continue;
@@ -31992,7 +32031,7 @@ function executePull(rows, opts = {}) {
31992
32031
  }
31993
32032
  try {
31994
32033
  mkdirSync14(dir, { recursive: true });
31995
- writeFileSync13(file, body);
32034
+ writeFileSync14(file, body);
31996
32035
  outcomes.push({ type: "skill", name, tool, status: "written", path: file, redactedContent: redacted });
31997
32036
  } catch (e) {
31998
32037
  outcomes.push({ type: "skill", name, tool, status: "failed", reason: e instanceof Error ? e.message : "write failed" });
@@ -32033,7 +32072,7 @@ function executePull(rows, opts = {}) {
32033
32072
  }
32034
32073
  try {
32035
32074
  mkdirSync14(dirname22(out.path), { recursive: true });
32036
- writeFileSync13(out.path, out.content);
32075
+ writeFileSync14(out.path, out.content);
32037
32076
  outcomes.push({ type, name, tool, status: "written", path: out.path, redactedContent: redacted });
32038
32077
  } catch (e) {
32039
32078
  outcomes.push({ type, name, tool, status: "failed", reason: e instanceof Error ? e.message : "write failed" });
@@ -32341,8 +32380,8 @@ var init_repair = __esm({
32341
32380
  });
32342
32381
 
32343
32382
  // src/intent-drain.ts
32344
- import { existsSync as existsSync48, readFileSync as readFileSync45, writeFileSync as writeFileSync14, appendFileSync, mkdirSync as mkdirSync15 } from "node:fs";
32345
- import { join as join53 } from "node:path";
32383
+ import { existsSync as existsSync48, readFileSync as readFileSync46, writeFileSync as writeFileSync15, appendFileSync, mkdirSync as mkdirSync15 } from "node:fs";
32384
+ import { join as join54 } from "node:path";
32346
32385
  import { fileURLToPath as fileURLToPath4 } from "node:url";
32347
32386
  import { dirname as dirname23 } from "node:path";
32348
32387
  function instructionTargets(rootPath, isGlobal) {
@@ -32356,17 +32395,17 @@ function instructionTargets(rootPath, isGlobal) {
32356
32395
  const tools = installed.length ? installed : [INSTRUCTION_TOOLS[0]];
32357
32396
  if (isGlobal) return [...new Set(tools.map((t) => instructionsPath(t.id)))];
32358
32397
  if (!rootPath) return [];
32359
- const present = INSTRUCTION_FILENAMES.map((f) => join53(rootPath, f)).filter((p) => existsSync48(p));
32398
+ const present = INSTRUCTION_FILENAMES.map((f) => join54(rootPath, f)).filter((p) => existsSync48(p));
32360
32399
  if (present.length) return present;
32361
- return [...new Set(tools.map((t) => join53(rootPath, instructionsFilename(t.id))))];
32400
+ return [...new Set(tools.map((t) => join54(rootPath, instructionsFilename(t.id))))];
32362
32401
  }
32363
32402
  function applyCodeRecommendation(intent) {
32364
32403
  try {
32365
32404
  const meta = JSON.parse(intent.name || "{}");
32366
32405
  if (intent.artifact_type === "write_tasks_file") {
32367
32406
  if (!meta.rootPath || !meta.content) return { status: "error", result: JSON.stringify({ error: "missing rootPath or content" }) };
32368
- const file = join53(meta.rootPath, meta.filename || "CODE_TASKS.md");
32369
- writeFileSync14(file, meta.content);
32407
+ const file = join54(meta.rootPath, meta.filename || "CODE_TASKS.md");
32408
+ writeFileSync15(file, meta.content);
32370
32409
  return { status: "done", result: JSON.stringify({ wrote: file }) };
32371
32410
  }
32372
32411
  if (intent.artifact_type === "append_claude_md") {
@@ -32384,7 +32423,7 @@ function applyCodeRecommendation(intent) {
32384
32423
  mkdirSync15(dir, { recursive: true });
32385
32424
  } catch {
32386
32425
  }
32387
- const existing = existsSync48(file) ? readFileSync45(file, "utf8") : "";
32426
+ const existing = existsSync48(file) ? readFileSync46(file, "utf8") : "";
32388
32427
  if (existing.includes(text)) {
32389
32428
  skipped.push(file);
32390
32429
  continue;
@@ -32394,7 +32433,7 @@ function applyCodeRecommendation(intent) {
32394
32433
  ${text}
32395
32434
  `;
32396
32435
  if (existing) appendFileSync(file, block);
32397
- else writeFileSync14(file, `# ${meta.rootPath?.split("/").pop() || "Global"} instructions
32436
+ else writeFileSync15(file, `# ${meta.rootPath?.split("/").pop() || "Global"} instructions
32398
32437
  ${block}`);
32399
32438
  appended.push(file);
32400
32439
  }
@@ -32570,7 +32609,7 @@ var init_intent_drain = __esm({
32570
32609
  ownVersion2 = "0.0.0";
32571
32610
  try {
32572
32611
  const dir = dirname23(fileURLToPath4(import.meta.url));
32573
- ownVersion2 = JSON.parse(readFileSync45(join53(dir, "../package.json"), "utf-8")).version || ownVersion2;
32612
+ ownVersion2 = JSON.parse(readFileSync46(join54(dir, "../package.json"), "utf-8")).version || ownVersion2;
32574
32613
  } catch {
32575
32614
  try {
32576
32615
  if (typeof __CLI_VERSION__ === "string") ownVersion2 = __CLI_VERSION__;
@@ -32581,13 +32620,13 @@ var init_intent_drain = __esm({
32581
32620
  });
32582
32621
 
32583
32622
  // src/code-index-cursor.ts
32584
- import { readFileSync as readFileSync46, writeFileSync as writeFileSync15, mkdirSync as mkdirSync16, statSync as statSync45 } from "fs";
32623
+ import { readFileSync as readFileSync47, writeFileSync as writeFileSync16, mkdirSync as mkdirSync16, statSync as statSync45 } from "fs";
32585
32624
  import { execFileSync as execFileSync4 } from "child_process";
32586
32625
  import { createHash as createHash12 } from "crypto";
32587
- import { join as join54, dirname as dirname24 } from "path";
32626
+ import { join as join55, dirname as dirname24 } from "path";
32588
32627
  function readCursor() {
32589
32628
  try {
32590
- const raw = JSON.parse(readFileSync46(cursorPath(), "utf-8"));
32629
+ const raw = JSON.parse(readFileSync47(cursorPath(), "utf-8"));
32591
32630
  if (raw && typeof raw === "object" && !Array.isArray(raw)) {
32592
32631
  const out = {};
32593
32632
  for (const [k, v] of Object.entries(raw)) {
@@ -32607,7 +32646,7 @@ function writeCursor(c) {
32607
32646
  try {
32608
32647
  const p = cursorPath();
32609
32648
  mkdirSync16(dirname24(p), { recursive: true });
32610
- writeFileSync15(p, JSON.stringify(c));
32649
+ writeFileSync16(p, JSON.stringify(c));
32611
32650
  } catch {
32612
32651
  }
32613
32652
  }
@@ -32631,7 +32670,7 @@ function workspaceFingerprint(workspace, collectorVersion) {
32631
32670
  const rel = entry.slice(3);
32632
32671
  let stamp2 = "gone";
32633
32672
  try {
32634
- const s = statSync45(join54(workspace, rel));
32673
+ const s = statSync45(join55(workspace, rel));
32635
32674
  stamp2 = `${s.size}:${Math.floor(s.mtimeMs)}`;
32636
32675
  } catch {
32637
32676
  }
@@ -32666,7 +32705,7 @@ var init_code_index_cursor = __esm({
32666
32705
  "src/code-index-cursor.ts"() {
32667
32706
  "use strict";
32668
32707
  init_paths();
32669
- cursorPath = () => join54(getDataDir(), "code-index-cursor.json");
32708
+ cursorPath = () => join55(getDataDir(), "code-index-cursor.json");
32670
32709
  UNCHANGED_RESEND_MS = 7 * 24 * 3600 * 1e3;
32671
32710
  }
32672
32711
  });
@@ -32784,12 +32823,12 @@ var init_daemon_log = __esm({
32784
32823
 
32785
32824
  // src/self-restart.ts
32786
32825
  import { spawn as spawn2 } from "child_process";
32787
- import { readFileSync as readFileSync47 } from "fs";
32826
+ import { readFileSync as readFileSync48 } from "fs";
32788
32827
  import { createHash as createHash13 } from "crypto";
32789
32828
  function codeFingerprint(entry = process.argv[1]) {
32790
32829
  if (!entry) return null;
32791
32830
  try {
32792
- const buf = readFileSync47(entry);
32831
+ const buf = readFileSync48(entry);
32793
32832
  return {
32794
32833
  path: entry,
32795
32834
  size: buf.byteLength,
@@ -32938,7 +32977,7 @@ __export(shadow_prune_exports, {
32938
32977
  pruneShadow: () => pruneShadow
32939
32978
  });
32940
32979
  import { readdirSync as readdirSync34, statSync as statSync47, unlinkSync as unlinkSync3 } from "fs";
32941
- import { join as join55 } from "path";
32980
+ import { join as join56 } from "path";
32942
32981
  function listShadows(isFullyAcked) {
32943
32982
  const out = [];
32944
32983
  const root = shadowRoot();
@@ -32949,7 +32988,7 @@ function listShadows(isFullyAcked) {
32949
32988
  return out;
32950
32989
  }
32951
32990
  for (const tool of tools) {
32952
- const dir = join55(root, tool);
32991
+ const dir = join56(root, tool);
32953
32992
  let names;
32954
32993
  try {
32955
32994
  names = readdirSync34(dir);
@@ -32959,7 +32998,7 @@ function listShadows(isFullyAcked) {
32959
32998
  for (const name of names) {
32960
32999
  if (!name.endsWith(".gz"))
32961
33000
  continue;
32962
- const path = join55(dir, name);
33001
+ const path = join56(dir, name);
32963
33002
  let st;
32964
33003
  try {
32965
33004
  st = statSync47(path);
@@ -33077,9 +33116,9 @@ var init_code_intel = __esm({
33077
33116
  });
33078
33117
 
33079
33118
  // ../engine/dist/core/companions.js
33080
- import { existsSync as existsSync50, mkdirSync as mkdirSync17, statSync as statSync48, chmodSync as chmodSync5, unlinkSync as unlinkSync4, renameSync as renameSync5, createWriteStream as createWriteStream2, readFileSync as readFileSync48, writeFileSync as writeFileSync16 } from "node:fs";
33119
+ import { existsSync as existsSync50, mkdirSync as mkdirSync17, statSync as statSync48, chmodSync as chmodSync5, unlinkSync as unlinkSync4, renameSync as renameSync5, createWriteStream as createWriteStream2, readFileSync as readFileSync49, writeFileSync as writeFileSync17 } from "node:fs";
33081
33120
  import { homedir as homedir20 } from "node:os";
33082
- import { join as join56 } from "node:path";
33121
+ import { join as join57 } from "node:path";
33083
33122
  import { execSync as execSync3 } from "node:child_process";
33084
33123
  import { createHash as createHash15 } from "node:crypto";
33085
33124
  function expectedCodeindexSha256(artifact) {
@@ -33189,7 +33228,7 @@ async function installCodeindex(opts = {}) {
33189
33228
  if (!expected) {
33190
33229
  throw new Error(`No pinned checksum for ${status.artifactName} \u2014 refusing to install an unverified binary. Add its sha256 to CODEINDEX_SHA256 in companions.ts.`);
33191
33230
  }
33192
- const actual = createHash15("sha256").update(readFileSync48(tmpPath)).digest("hex");
33231
+ const actual = createHash15("sha256").update(readFileSync49(tmpPath)).digest("hex");
33193
33232
  if (actual !== expected) {
33194
33233
  throw new Error(`Checksum mismatch for ${status.artifactName}.
33195
33234
  expected ${expected}
@@ -33223,9 +33262,9 @@ var init_companions = __esm({
33223
33262
  "x86_64-windows": "a96fc8c8949bb399a44cc0615b12e458460a529c69f01e8829cc39a20f45ab29",
33224
33263
  "aarch64-windows": "42620d56272cd9ba9d785569d8d754d6b4a3e80f36f28db3e0c483fd600ed117"
33225
33264
  };
33226
- CODEINDEX_INSTALL_DIR = join56(homedir20(), ".local", "bin");
33265
+ CODEINDEX_INSTALL_DIR = join57(homedir20(), ".local", "bin");
33227
33266
  CODEINDEX_BIN_NAME = process.platform === "win32" ? "codeindex.exe" : "codeindex";
33228
- CODEINDEX_BIN_PATH = join56(CODEINDEX_INSTALL_DIR, CODEINDEX_BIN_NAME);
33267
+ CODEINDEX_BIN_PATH = join57(CODEINDEX_INSTALL_DIR, CODEINDEX_BIN_NAME);
33229
33268
  }
33230
33269
  });
33231
33270
 
@@ -33340,8 +33379,8 @@ __export(collector_exports, {
33340
33379
  });
33341
33380
  import { spawn as spawn3 } from "node:child_process";
33342
33381
  import { execSync as execSync4 } from "node:child_process";
33343
- import { readFileSync as readFileSync49 } from "node:fs";
33344
- import { join as join57, basename as basename26 } from "node:path";
33382
+ import { readFileSync as readFileSync50 } from "node:fs";
33383
+ import { join as join58, basename as basename26 } from "node:path";
33345
33384
  async function resolveCodeindexBin(autoInstall = true) {
33346
33385
  let st = checkCodeindexStatus();
33347
33386
  if (!st.installed && autoInstall)
@@ -33523,7 +33562,7 @@ async function collectCode(opts) {
33523
33562
  }
33524
33563
  const complexity = (r) => {
33525
33564
  try {
33526
- const txt = readFileSync49(join57(ws, r), "utf8");
33565
+ const txt = readFileSync50(join58(ws, r), "utf8");
33527
33566
  if (txt.length > 2e6)
33528
33567
  return 1;
33529
33568
  const m = txt.match(CF_RE);
@@ -34288,15 +34327,15 @@ __export(service_installer_exports, {
34288
34327
  uninstallService: () => uninstallService
34289
34328
  });
34290
34329
  import { execSync as execSync5 } from "child_process";
34291
- import { existsSync as existsSync51, mkdirSync as mkdirSync18, readFileSync as readFileSync50, rmSync as rmSync9, writeFileSync as writeFileSync17 } from "fs";
34330
+ import { existsSync as existsSync51, mkdirSync as mkdirSync18, readFileSync as readFileSync51, rmSync as rmSync9, writeFileSync as writeFileSync18 } from "fs";
34292
34331
  import { homedir as homedir21 } from "os";
34293
- import { join as join58 } from "path";
34332
+ import { join as join59 } from "path";
34294
34333
  import { fileURLToPath as fileURLToPath5 } from "url";
34295
34334
  function resolveDaemonPaths() {
34296
34335
  const watchJs = fileURLToPath5(new URL("./watch.js", import.meta.url));
34297
34336
  const node = process.execPath;
34298
- const dataDir = join58(homedir21(), ".chat-recall");
34299
- const logFile = join58(dataDir, "watch.log");
34337
+ const dataDir = join59(homedir21(), ".chat-recall");
34338
+ const logFile = join59(dataDir, "watch.log");
34300
34339
  return { watchJs, node, logFile, dataDir };
34301
34340
  }
34302
34341
  function tryCmd(cmd) {
@@ -34323,13 +34362,13 @@ function refreshServiceDefinition() {
34323
34362
  if (process.platform !== "linux") return false;
34324
34363
  try {
34325
34364
  const { watchJs, node, logFile } = resolveDaemonPaths();
34326
- const unitPath = join58(homedir21(), ".config", "systemd", "user", "chat-recall-watch.service");
34365
+ const unitPath = join59(homedir21(), ".config", "systemd", "user", "chat-recall-watch.service");
34327
34366
  if (!existsSync51(unitPath)) return false;
34328
- const current = readFileSync50(unitPath, "utf8");
34367
+ const current = readFileSync51(unitPath, "utf8");
34329
34368
  if (!current.includes(watchJs)) return false;
34330
34369
  const wanted = renderSystemdUnit(watchJs, node, logFile);
34331
- if (readFileSync50(unitPath, "utf8") === wanted) return false;
34332
- writeFileSync17(unitPath, wanted);
34370
+ if (readFileSync51(unitPath, "utf8") === wanted) return false;
34371
+ writeFileSync18(unitPath, wanted);
34333
34372
  execSync5("systemctl --user daemon-reload", { stdio: "ignore" });
34334
34373
  return true;
34335
34374
  } catch {
@@ -34354,11 +34393,11 @@ function installService() {
34354
34393
  );
34355
34394
  }
34356
34395
  function installSystemd(watchJs, node, logFile) {
34357
- const unitDir = join58(homedir21(), ".config", "systemd", "user");
34358
- const unitPath = join58(unitDir, "chat-recall-watch.service");
34396
+ const unitDir = join59(homedir21(), ".config", "systemd", "user");
34397
+ const unitPath = join59(unitDir, "chat-recall-watch.service");
34359
34398
  const unit = renderSystemdUnit(watchJs, node, logFile);
34360
34399
  mkdirSync18(unitDir, { recursive: true });
34361
- writeFileSync17(unitPath, unit);
34400
+ writeFileSync18(unitPath, unit);
34362
34401
  try {
34363
34402
  execSync5("systemctl --user daemon-reload && systemctl --user enable chat-recall-watch.service && systemctl --user restart chat-recall-watch.service", { stdio: "inherit" });
34364
34403
  try {
@@ -34440,11 +34479,11 @@ function renderSystemdUnit(watchJs, node, logFile) {
34440
34479
  }
34441
34480
  function installLaunchd(watchJs, node, logFile) {
34442
34481
  const label = "com.chat-recall.watch";
34443
- const plistDir = join58(homedir21(), "Library", "LaunchAgents");
34444
- const plistPath = join58(plistDir, `${label}.plist`);
34482
+ const plistDir = join59(homedir21(), "Library", "LaunchAgents");
34483
+ const plistPath = join59(plistDir, `${label}.plist`);
34445
34484
  const plist = renderLaunchdPlist(watchJs, node, logFile, label);
34446
34485
  mkdirSync18(plistDir, { recursive: true });
34447
- writeFileSync17(plistPath, plist);
34486
+ writeFileSync18(plistPath, plist);
34448
34487
  try {
34449
34488
  try {
34450
34489
  execSync5(`launchctl unload "${plistPath}"`, { stdio: "ignore" });
@@ -34497,7 +34536,7 @@ function uninstallService() {
34497
34536
  removed = true;
34498
34537
  } catch {
34499
34538
  }
34500
- const unitPath = join58(homedir21(), ".config", "systemd", "user", "chat-recall-watch.service");
34539
+ const unitPath = join59(homedir21(), ".config", "systemd", "user", "chat-recall-watch.service");
34501
34540
  if (existsSync51(unitPath)) {
34502
34541
  rmSync9(unitPath, { force: true });
34503
34542
  removed = true;
@@ -34509,7 +34548,7 @@ function uninstallService() {
34509
34548
  return removed;
34510
34549
  }
34511
34550
  if (process.platform === "darwin") {
34512
- const plistPath = join58(homedir21(), "Library", "LaunchAgents", "com.chat-recall.watch.plist");
34551
+ const plistPath = join59(homedir21(), "Library", "LaunchAgents", "com.chat-recall.watch.plist");
34513
34552
  try {
34514
34553
  execSync5(`launchctl unload "${plistPath}" 2>/dev/null`, { stdio: "ignore" });
34515
34554
  } catch {
@@ -34559,9 +34598,9 @@ __export(indexer_exports, {
34559
34598
  noteSyncOutcome: () => noteSyncOutcome
34560
34599
  });
34561
34600
  import chokidar from "chokidar";
34562
- import { dirname as dirname25, basename as basename27, join as join59, resolve as resolve2, sep as sep4 } from "path";
34601
+ import { dirname as dirname25, basename as basename27, join as join60, resolve as resolve2, sep as sep4 } from "path";
34563
34602
  import { homedir as homedir22 } from "os";
34564
- import { existsSync as existsSync52, readFileSync as readFileSync51, statSync as statSync49 } from "fs";
34603
+ import { existsSync as existsSync52, readFileSync as readFileSync52, statSync as statSync49 } from "fs";
34565
34604
  async function shipToServer(trigger) {
34566
34605
  if (syncInFlight) return;
34567
34606
  syncInFlight = true;
@@ -34591,6 +34630,8 @@ async function shipToServer(trigger) {
34591
34630
  for (const server of syncTargetUrls()) noteSyncOutcome(server, false, msg);
34592
34631
  } finally {
34593
34632
  syncInFlight = false;
34633
+ releaseMemory();
34634
+ reclaimCgroup();
34594
34635
  }
34595
34636
  }
34596
34637
  function scheduleSync() {
@@ -34604,7 +34645,7 @@ function scheduleSync() {
34604
34645
  }
34605
34646
  async function onResumeSignal(path) {
34606
34647
  try {
34607
- const txt = readFileSync51(path, "utf-8");
34648
+ const txt = readFileSync52(path, "utf-8");
34608
34649
  const m = /--resume\s+([0-9a-fA-F-]{36})/.exec(txt);
34609
34650
  if (!m) return;
34610
34651
  const id = m[1];
@@ -34790,7 +34831,7 @@ function isCodeWorkspace(p) {
34790
34831
  }
34791
34832
  return WORKSPACE_MARKERS.some((m) => {
34792
34833
  try {
34793
- return existsSync52(join59(p, m));
34834
+ return existsSync52(join60(p, m));
34794
34835
  } catch {
34795
34836
  return false;
34796
34837
  }
@@ -34820,6 +34861,7 @@ async function codeIndexTick() {
34820
34861
  for (const ws of workspaces) {
34821
34862
  const rss = rssMb();
34822
34863
  if (isOverMemoryLimit(rss, rssLimit)) {
34864
+ releaseMemory();
34823
34865
  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
34866
  break;
34825
34867
  }
@@ -34850,6 +34892,8 @@ async function codeIndexTick() {
34850
34892
  releaseMemory();
34851
34893
  }
34852
34894
  if (ok > 0 || unchanged > 0) daemonLog.info(`code intelligence: indexed ${ok}/${workspaces.length} workspace(s), ${unchanged} unchanged`);
34895
+ releaseMemory();
34896
+ reclaimCgroup();
34853
34897
  } finally {
34854
34898
  codeIndexInFlight = false;
34855
34899
  }
@@ -34944,8 +34988,8 @@ var init_indexer = __esm({
34944
34988
  PI_SESSION_DIRS = piBackend.sessionDirs();
34945
34989
  OPENCODE_DB_PATH = opencodeBackend.dbPath();
34946
34990
  OPENCODE_DB_DIR = dirname25(OPENCODE_DB_PATH);
34947
- CURRENT_RESUME_PATH = join59(claudeBackend.homeDir(), "current-resume");
34948
- LAST_CLEANUP_PATH = join59(claudeBackend.homeDir(), ".last-cleanup");
34991
+ CURRENT_RESUME_PATH = join60(claudeBackend.homeDir(), "current-resume");
34992
+ LAST_CLEANUP_PATH = join60(claudeBackend.homeDir(), ".last-cleanup");
34949
34993
  debounceTimer = null;
34950
34994
  ticks = new TickQueue({
34951
34995
  onError: (kind, err) => daemonLog.error(`${kind} tick failed: ${err instanceof Error ? err.message : err}`)
@@ -35110,7 +35154,7 @@ var init_indexer = __esm({
35110
35154
  daemonLog.info(`running bundle ${BOOT_CODE.path} (${BOOT_CODE.size} bytes)`);
35111
35155
  }
35112
35156
  {
35113
- const r = rotateLogIfLarge(join59(getDataDir(), "watch.log"));
35157
+ const r = rotateLogIfLarge(join60(getDataDir(), "watch.log"));
35114
35158
  if (r.rotated) {
35115
35159
  daemonLog.info(`rotated watch.log at ${(r.sizeBefore / 1048576).toFixed(0)}MB \u2192 watch.log.1 (copy+truncate; the path is preserved)`);
35116
35160
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chat-recall",
3
- "version": "0.7.40",
3
+ "version": "0.7.42",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/munhq/chat-recall.git"