chat-recall 0.7.43 → 0.7.47

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/dist/watch.js CHANGED
@@ -9648,16 +9648,23 @@ var init_opencode_v2 = __esm({
9648
9648
  // ../engine/dist/core/backends/opencode.js
9649
9649
  var opencode_exports = {};
9650
9650
  __export(opencode_exports, {
9651
+ DEFAULT_DUMP_MAX_BYTES: () => DEFAULT_DUMP_MAX_BYTES,
9651
9652
  OpencodeBackend: () => OpencodeBackend,
9653
+ dumpMaxBytes: () => dumpMaxBytes,
9652
9654
  opencodeBackend: () => opencodeBackend
9653
9655
  });
9654
9656
  import { existsSync as existsSync11 } from "fs";
9655
9657
  import { homedir as homedir5 } from "os";
9656
9658
  import { dirname as dirname9, join as join13 } from "path";
9659
+ function dumpMaxBytes(env = process.env) {
9660
+ const raw = env.CHAT_RECALL_OPENCODE_DUMP_MAX_BYTES;
9661
+ const parsed = raw === void 0 ? Number.NaN : Number(raw);
9662
+ return Number.isFinite(parsed) && parsed > 0 ? Math.floor(parsed) : DEFAULT_DUMP_MAX_BYTES;
9663
+ }
9657
9664
  function openReadonly(path) {
9658
9665
  return openOpencodeDb(path);
9659
9666
  }
9660
- var PREFIX, OpencodeBackend, opencodeBackend;
9667
+ var DEFAULT_DUMP_MAX_BYTES, PREFIX, OpencodeBackend, opencodeBackend;
9661
9668
  var init_opencode = __esm({
9662
9669
  "../engine/dist/core/backends/opencode.js"() {
9663
9670
  "use strict";
@@ -9667,6 +9674,7 @@ var init_opencode = __esm({
9667
9674
  init_session_git();
9668
9675
  init_generic_engine();
9669
9676
  init_flat_string();
9677
+ DEFAULT_DUMP_MAX_BYTES = 64 * 1024 * 1024;
9670
9678
  PREFIX = "opencode_";
9671
9679
  OpencodeBackend = class {
9672
9680
  id = "opencode";
@@ -10181,10 +10189,23 @@ var init_opencode = __esm({
10181
10189
  WHERE p.session_id = ?
10182
10190
  ORDER BY p.time_created ASC, p.id ASC
10183
10191
  `);
10192
+ const budget = dumpMaxBytes();
10184
10193
  const chunks = [Buffer.from(`${JSON.stringify({ kind: "session", row: session })}
10185
10194
  `, "utf-8")];
10195
+ let used = chunks[0].length;
10196
+ let skipped = 0;
10186
10197
  for (const r of rows.iterate(realId, realId)) {
10187
- chunks.push(Buffer.from(`${JSON.stringify({ kind: "part", row: r })}
10198
+ const encoded = Buffer.from(`${JSON.stringify({ kind: "part", row: r })}
10199
+ `, "utf-8");
10200
+ if (used + encoded.length > budget) {
10201
+ skipped++;
10202
+ continue;
10203
+ }
10204
+ used += encoded.length;
10205
+ chunks.push(encoded);
10206
+ }
10207
+ if (skipped > 0) {
10208
+ chunks.push(Buffer.from(`${JSON.stringify({ kind: "truncated", skipped_rows: skipped, limit_bytes: budget })}
10188
10209
  `, "utf-8"));
10189
10210
  }
10190
10211
  const mtime = session.time_updated || session.time_created || Date.now();
@@ -13879,6 +13900,98 @@ var init_collector_health = __esm({
13879
13900
  }
13880
13901
  });
13881
13902
 
13903
+ // src/memory-guard.ts
13904
+ import { readFileSync as readFileSync16, writeFileSync as writeFileSync5 } from "node:fs";
13905
+ import { join as join21 } from "node:path";
13906
+ function rssMb() {
13907
+ return Math.round(process.memoryUsage().rss / 1048576);
13908
+ }
13909
+ function memoryLimitMb(env = process.env) {
13910
+ const raw = env.CHAT_RECALL_WATCH_RSS_MAX_MB;
13911
+ if (!raw) return DEFAULT_RSS_MAX_MB;
13912
+ const n = Number(raw);
13913
+ return Number.isFinite(n) && n > 0 ? Math.round(n) : DEFAULT_RSS_MAX_MB;
13914
+ }
13915
+ function growthLimitMb(env = process.env) {
13916
+ const raw = env.CHAT_RECALL_WATCH_GROWTH_MAX_MB;
13917
+ if (!raw) return DEFAULT_GROWTH_MAX_MB;
13918
+ const n = Number(raw);
13919
+ return Number.isFinite(n) && n > 0 ? Math.round(n) : DEFAULT_GROWTH_MAX_MB;
13920
+ }
13921
+ function releaseMemory(gc = globalThis.gc) {
13922
+ if (typeof gc !== "function") return false;
13923
+ gc();
13924
+ return true;
13925
+ }
13926
+ function cgroupDir(cgroupFile = "/proc/self/cgroup") {
13927
+ let text;
13928
+ try {
13929
+ text = readFileSync16(cgroupFile, "utf8");
13930
+ } catch {
13931
+ return null;
13932
+ }
13933
+ const line = text.split("\n").find((l) => l.startsWith("0::"));
13934
+ if (!line) return null;
13935
+ return `/sys/fs/cgroup${line.slice(3).trim()}`;
13936
+ }
13937
+ function memoryStatMb(dir, key2) {
13938
+ let text;
13939
+ try {
13940
+ text = readFileSync16(join21(dir, "memory.stat"), "utf8");
13941
+ } catch {
13942
+ return null;
13943
+ }
13944
+ for (const line of text.split("\n")) {
13945
+ const [name, value] = line.split(" ");
13946
+ if (name === key2 && value) return Math.round(Number(value) / 1048576);
13947
+ }
13948
+ return null;
13949
+ }
13950
+ function reclaimCgroup(keepFileMb = 64, dir = cgroupDir()) {
13951
+ if (!dir) return false;
13952
+ const fileMb = memoryStatMb(dir, "file");
13953
+ if (fileMb === null) return false;
13954
+ const reclaimMb = Math.floor(fileMb - keepFileMb);
13955
+ if (reclaimMb <= 0) return false;
13956
+ try {
13957
+ writeFileSync5(join21(dir, "memory.reclaim"), `${reclaimMb}M`);
13958
+ return true;
13959
+ } catch {
13960
+ return false;
13961
+ }
13962
+ }
13963
+ function shouldReclaim(fileMb, limitMb = DEFAULT_RECLAIM_FILE_MB) {
13964
+ return fileMb !== null && limitMb >= 0 && fileMb > limitMb;
13965
+ }
13966
+ function cgroupCurrentMb(dir = cgroupDir()) {
13967
+ if (!dir) return null;
13968
+ try {
13969
+ const n = Number(readFileSync16(join21(dir, "memory.current"), "utf8").trim());
13970
+ return Number.isFinite(n) ? Math.round(n / 1048576) : null;
13971
+ } catch {
13972
+ return null;
13973
+ }
13974
+ }
13975
+ function usedMb(rss = rssMb(), cgroup = cgroupCurrentMb()) {
13976
+ return cgroup !== null && cgroup > rss ? cgroup : rss;
13977
+ }
13978
+ function startBudget(used = usedMb(), env = process.env) {
13979
+ return { baselineMb: used, growthMb: growthLimitMb(env), hardMb: memoryLimitMb(env) };
13980
+ }
13981
+ function shouldPause(used, budget, unitsDone) {
13982
+ if (unitsDone <= 0) return false;
13983
+ return used >= budget.hardMb || used - budget.baselineMb >= budget.growthMb;
13984
+ }
13985
+ var DEFAULT_RSS_MAX_MB, DEFAULT_GROWTH_MAX_MB, DEFAULT_RECLAIM_FILE_MB;
13986
+ var init_memory_guard = __esm({
13987
+ "src/memory-guard.ts"() {
13988
+ "use strict";
13989
+ DEFAULT_RSS_MAX_MB = 896;
13990
+ DEFAULT_GROWTH_MAX_MB = 256;
13991
+ DEFAULT_RECLAIM_FILE_MB = 128;
13992
+ }
13993
+ });
13994
+
13882
13995
  // ../engine/dist/core/secret-redactor.js
13883
13996
  import { statSync as statSync15 } from "fs";
13884
13997
  function secretOf(rule, m) {
@@ -14288,7 +14401,7 @@ var init_secret_redactor = __esm({
14288
14401
  // ../engine/dist/core/source-discovery.js
14289
14402
  import { createHash as createHash5 } from "crypto";
14290
14403
  import { existsSync as existsSync17, readdirSync as readdirSync13, statSync as statSync16 } from "fs";
14291
- import { join as join21 } from "path";
14404
+ import { join as join22 } from "path";
14292
14405
  function sourceId(path) {
14293
14406
  return "src_" + createHash5("sha256").update(path).digest("hex").slice(0, 12);
14294
14407
  }
@@ -14329,7 +14442,7 @@ function countTranscripts(root, tool) {
14329
14442
  return;
14330
14443
  }
14331
14444
  for (const e of entries) {
14332
- const full = join21(dir, e.name);
14445
+ const full = join22(dir, e.name);
14333
14446
  if (e.isDirectory()) {
14334
14447
  walk(full, depth + 1);
14335
14448
  continue;
@@ -14400,9 +14513,9 @@ var init_source_discovery = __esm({
14400
14513
 
14401
14514
  // ../engine/dist/core/home-discovery.js
14402
14515
  import { execFileSync as execFileSync2 } from "child_process";
14403
- import { existsSync as existsSync18, readdirSync as readdirSync14, readFileSync as readFileSync16, realpathSync as realpathSync3, statSync as statSync17 } from "fs";
14516
+ import { existsSync as existsSync18, readdirSync as readdirSync14, readFileSync as readFileSync17, realpathSync as realpathSync3, statSync as statSync17 } from "fs";
14404
14517
  import { homedir as homedir6, platform as osPlatform } from "os";
14405
- import { basename as basename12, join as join22 } from "path";
14518
+ import { basename as basename12, join as join23 } from "path";
14406
14519
  function candidateRoots(plat = osPlatform(), env = process.env) {
14407
14520
  const home = homedir6();
14408
14521
  const roots = [home];
@@ -14415,11 +14528,11 @@ function candidateRoots(plat = osPlatform(), env = process.env) {
14415
14528
  add(env.LOCALAPPDATA);
14416
14529
  add(env.USERPROFILE);
14417
14530
  } else if (plat === "darwin") {
14418
- add(join22(home, "Library", "Application Support"));
14531
+ add(join23(home, "Library", "Application Support"));
14419
14532
  add(env.XDG_CONFIG_HOME);
14420
14533
  } else {
14421
- add(env.XDG_CONFIG_HOME || join22(home, ".config"));
14422
- add(env.XDG_DATA_HOME || join22(home, ".local", "share"));
14534
+ add(env.XDG_CONFIG_HOME || join23(home, ".config"));
14535
+ add(env.XDG_DATA_HOME || join23(home, ".local", "share"));
14423
14536
  }
14424
14537
  return roots.filter((r) => existsSync18(r));
14425
14538
  }
@@ -14432,14 +14545,14 @@ function piRootOf(home) {
14432
14545
  return piSessionDirForHome(home);
14433
14546
  }
14434
14547
  function identifyHome(dir) {
14435
- const has = (...parts) => existsSync18(join22(dir, ...parts));
14436
- if (has("projects") && dirHasTranscript(join22(dir, "projects"), (f) => f.endsWith(".jsonl"), 2))
14548
+ const has = (...parts) => existsSync18(join23(dir, ...parts));
14549
+ if (has("projects") && dirHasTranscript(join23(dir, "projects"), (f) => f.endsWith(".jsonl"), 2))
14437
14550
  return "claude";
14438
- if (has("sessions") && dirHasTranscript(join22(dir, "sessions"), (f) => f.startsWith("rollout-") && f.endsWith(".jsonl"), 4))
14551
+ if (has("sessions") && dirHasTranscript(join23(dir, "sessions"), (f) => f.startsWith("rollout-") && f.endsWith(".jsonl"), 4))
14439
14552
  return "codex";
14440
- if (has("brain") && dirHasTranscript(join22(dir, "brain"), (f) => f.endsWith(".jsonl"), 4))
14553
+ if (has("brain") && dirHasTranscript(join23(dir, "brain"), (f) => f.endsWith(".jsonl"), 4))
14441
14554
  return "agy";
14442
- if (has("chats") && dirHasTranscript(join22(dir, "chats"), (f) => f === "store.db", 3))
14555
+ if (has("chats") && dirHasTranscript(join23(dir, "chats"), (f) => f === "store.db", 3))
14443
14556
  return "cursor";
14444
14557
  if (has("opencode.db"))
14445
14558
  return "opencode";
@@ -14464,7 +14577,7 @@ function dirHasTranscript(root, match, depth) {
14464
14577
  continue;
14465
14578
  if (e.isFile() && match(e.name))
14466
14579
  return true;
14467
- if (e.isDirectory() && dirHasTranscript(join22(root, e.name), match, depth - 1))
14580
+ if (e.isDirectory() && dirHasTranscript(join23(root, e.name), match, depth - 1))
14468
14581
  return true;
14469
14582
  }
14470
14583
  return false;
@@ -14485,7 +14598,7 @@ function countSessions(dir, tool) {
14485
14598
  if (SKIP.has(e.name))
14486
14599
  continue;
14487
14600
  if (e.isDirectory()) {
14488
- walk2(join22(d, e.name), depth - 1);
14601
+ walk2(join23(d, e.name), depth - 1);
14489
14602
  continue;
14490
14603
  }
14491
14604
  if (isPiTranscriptName(e.name))
@@ -14522,12 +14635,12 @@ function countSessions(dir, tool) {
14522
14635
  if (SKIP.has(e.name))
14523
14636
  continue;
14524
14637
  if (e.isDirectory())
14525
- walk(join22(d, e.name), depth - 1);
14638
+ walk(join23(d, e.name), depth - 1);
14526
14639
  else if (s.match(e.name))
14527
14640
  n++;
14528
14641
  }
14529
14642
  };
14530
- walk(join22(dir, s.sub), s.depth);
14643
+ walk(join23(dir, s.sub), s.depth);
14531
14644
  return n;
14532
14645
  }
14533
14646
  function declaredHomes(env = process.env, plat = osPlatform()) {
@@ -14565,11 +14678,11 @@ function declaredHomes(env = process.env, plat = osPlatform()) {
14565
14678
  return out;
14566
14679
  }
14567
14680
  const home = homedir6();
14568
- const rcs = [".bashrc", ".bash_profile", ".zshrc", ".zprofile", ".profile"].map((f) => join22(home, f)).concat([join22(home, ".config", "fish", "config.fish")]);
14681
+ const rcs = [".bashrc", ".bash_profile", ".zshrc", ".zprofile", ".profile"].map((f) => join23(home, f)).concat([join23(home, ".config", "fish", "config.fish")]);
14569
14682
  for (const rc of rcs) {
14570
14683
  let text;
14571
14684
  try {
14572
- text = readFileSync16(rc, "utf-8");
14685
+ text = readFileSync17(rc, "utf-8");
14573
14686
  } catch {
14574
14687
  continue;
14575
14688
  }
@@ -14580,7 +14693,7 @@ function declaredHomes(env = process.env, plat = osPlatform()) {
14580
14693
  add(d);
14581
14694
  }
14582
14695
  }
14583
- return out.map((p) => p.startsWith("~") ? join22(home, p.slice(1)) : p);
14696
+ return out.map((p) => p.startsWith("~") ? join23(home, p.slice(1)) : p);
14584
14697
  }
14585
14698
  function runningToolHomes(plat = osPlatform()) {
14586
14699
  const out = [];
@@ -14594,7 +14707,7 @@ function runningToolHomes(plat = osPlatform()) {
14594
14707
  for (const pid of pids) {
14595
14708
  let env;
14596
14709
  try {
14597
- env = readFileSync16(`/proc/${pid}/environ`, "utf-8");
14710
+ env = readFileSync17(`/proc/${pid}/environ`, "utf-8");
14598
14711
  } catch {
14599
14712
  continue;
14600
14713
  }
@@ -14651,9 +14764,9 @@ function discoverHomes(opts = {}) {
14651
14764
  found.set(real, { tool, path: real, via, sessions: countSessions(real, tool) });
14652
14765
  if (tool === "hermes") {
14653
14766
  try {
14654
- for (const e of readdirSync14(join22(real, "profiles"), { withFileTypes: true })) {
14767
+ for (const e of readdirSync14(join23(real, "profiles"), { withFileTypes: true })) {
14655
14768
  if (e.isDirectory())
14656
- consider(join22(real, "profiles", e.name), via);
14769
+ consider(join23(real, "profiles", e.name), via);
14657
14770
  }
14658
14771
  } catch {
14659
14772
  }
@@ -14683,7 +14796,7 @@ function walkForHomes(dir, depth, visit) {
14683
14796
  for (const e of entries) {
14684
14797
  if (!e.isDirectory() || SKIP.has(e.name))
14685
14798
  continue;
14686
- const child = join22(dir, e.name);
14799
+ const child = join23(dir, e.name);
14687
14800
  visit(child);
14688
14801
  walkForHomes(child, depth - 1, visit);
14689
14802
  }
@@ -14726,20 +14839,20 @@ var init_home_discovery = __esm({
14726
14839
 
14727
14840
  // ../engine/dist/core/detector-install.js
14728
14841
  import { createHash as createHash6 } from "crypto";
14729
- import { existsSync as existsSync19, mkdirSync as mkdirSync6, mkdtempSync, chmodSync as chmodSync3, renameSync as renameSync3, rmSync as rmSync2, writeFileSync as writeFileSync5, readFileSync as readFileSync17, statSync as statSync18, copyFileSync as copyFileSync2 } from "fs";
14730
- import { join as join23 } from "path";
14842
+ import { existsSync as existsSync19, mkdirSync as mkdirSync6, mkdtempSync, chmodSync as chmodSync3, renameSync as renameSync3, rmSync as rmSync2, writeFileSync as writeFileSync6, readFileSync as readFileSync18, statSync as statSync18, copyFileSync as copyFileSync2 } from "fs";
14843
+ import { join as join24 } from "path";
14731
14844
  function managedDetectorPath(name) {
14732
- return join23(getDetectorBinDir(), name + exeSuffix());
14845
+ return join24(getDetectorBinDir(), name + exeSuffix());
14733
14846
  }
14734
14847
  function receiptPath(name) {
14735
- return join23(getDetectorBinDir(), `${name}.receipt.json`);
14848
+ return join24(getDetectorBinDir(), `${name}.receipt.json`);
14736
14849
  }
14737
14850
  function sha256File(path) {
14738
- return createHash6("sha256").update(readFileSync17(path)).digest("hex");
14851
+ return createHash6("sha256").update(readFileSync18(path)).digest("hex");
14739
14852
  }
14740
14853
  function readReceipt(name) {
14741
14854
  try {
14742
- return JSON.parse(readFileSync17(receiptPath(name), "utf-8"));
14855
+ return JSON.parse(readFileSync18(receiptPath(name), "utf-8"));
14743
14856
  } catch {
14744
14857
  return null;
14745
14858
  }
@@ -14765,7 +14878,7 @@ function configuredDir() {
14765
14878
  function resolveDetector(name) {
14766
14879
  const dir = configuredDir();
14767
14880
  if (dir) {
14768
- const p2 = join23(dir, name + exeSuffix());
14881
+ const p2 = join24(dir, name + exeSuffix());
14769
14882
  if (existsSync19(p2))
14770
14883
  return { path: p2, version: "operator-supplied", source: "configured" };
14771
14884
  return { error: "not-installed" };
@@ -14830,9 +14943,9 @@ var init_detector_install = __esm({
14830
14943
 
14831
14944
  // ../engine/dist/core/secret-scanner.js
14832
14945
  import { spawnSync as spawnSync2 } from "child_process";
14833
- import { existsSync as existsSync20, unlinkSync, readFileSync as readFileSync18, mkdtempSync as mkdtempSync2, rmSync as rmSync3 } from "fs";
14946
+ import { existsSync as existsSync20, unlinkSync, readFileSync as readFileSync19, mkdtempSync as mkdtempSync2, rmSync as rmSync3 } from "fs";
14834
14947
  import { tmpdir } from "os";
14835
- import { join as join24 } from "path";
14948
+ import { join as join25 } from "path";
14836
14949
  function mask(s) {
14837
14950
  if (!s)
14838
14951
  return "";
@@ -14860,7 +14973,7 @@ function whichDetector(bin) {
14860
14973
  return null;
14861
14974
  }
14862
14975
  function spawnScoped(binary, args, opts) {
14863
- const scratch = mkdtempSync2(join24(tmpdir(), "cr-scan-tmp-"));
14976
+ const scratch = mkdtempSync2(join25(tmpdir(), "cr-scan-tmp-"));
14864
14977
  try {
14865
14978
  return spawnSync2(binary, args, {
14866
14979
  ...opts,
@@ -14891,7 +15004,7 @@ function runGitleaks(binary, filePath) {
14891
15004
  return [];
14892
15005
  let parsed = [];
14893
15006
  try {
14894
- parsed = JSON.parse(readFileSync18(reportPath, "utf-8")) || [];
15007
+ parsed = JSON.parse(readFileSync19(reportPath, "utf-8")) || [];
14895
15008
  } catch {
14896
15009
  }
14897
15010
  try {
@@ -14955,7 +15068,7 @@ function runGitleaksDir(binary, dir) {
14955
15068
  }
14956
15069
  let parsed = [];
14957
15070
  try {
14958
- parsed = JSON.parse(readFileSync18(reportPath, "utf-8")) || [];
15071
+ parsed = JSON.parse(readFileSync19(reportPath, "utf-8")) || [];
14959
15072
  } catch {
14960
15073
  }
14961
15074
  try {
@@ -15046,7 +15159,7 @@ function scanFileForSecrets(filePath, opts = {}) {
15046
15159
  out.push({ detector: "trufflehog", ...f });
15047
15160
  if (opts.tenantRules && opts.tenantRules.length > 0) {
15048
15161
  try {
15049
- const text = readFileSync18(filePath, "utf-8");
15162
+ const text = readFileSync19(filePath, "utf-8");
15050
15163
  out.push(...scanTenantRules(text, opts.tenantRules));
15051
15164
  } catch {
15052
15165
  }
@@ -15459,10 +15572,10 @@ var init_transcript = __esm({
15459
15572
  // ../engine/dist/core/project-resolver.js
15460
15573
  import { execSync } from "child_process";
15461
15574
  import { createHash as createHash7 } from "crypto";
15462
- import { existsSync as existsSync21, readFileSync as readFileSync19, realpathSync as realpathSync4, readdirSync as readdirSync15, statSync as statSync20 } from "fs";
15463
- import { basename as basename13, dirname as dirname14, isAbsolute as isAbsolute2, join as join25, resolve, sep } from "path";
15575
+ import { existsSync as existsSync21, readFileSync as readFileSync20, realpathSync as realpathSync4, readdirSync as readdirSync15, statSync as statSync20 } from "fs";
15576
+ import { basename as basename13, dirname as dirname14, isAbsolute as isAbsolute2, join as join26, resolve, sep } from "path";
15464
15577
  function getProjectsConfigPath() {
15465
- return join25(getDataDir(), "projects.json");
15578
+ return join26(getDataDir(), "projects.json");
15466
15579
  }
15467
15580
  function loadProjectsConfig() {
15468
15581
  if (cachedConfig && cachedConfig.mtime === Number.MAX_SAFE_INTEGER) {
@@ -15477,7 +15590,7 @@ function loadProjectsConfig() {
15477
15590
  if (cachedConfig && cachedConfig.mtime === mtime)
15478
15591
  return cachedConfig.cfg;
15479
15592
  try {
15480
- const raw = readFileSync19(path, "utf-8");
15593
+ const raw = readFileSync20(path, "utf-8");
15481
15594
  const cfg = JSON.parse(raw);
15482
15595
  cachedConfig = { mtime, cfg };
15483
15596
  return cfg;
@@ -15574,7 +15687,7 @@ function matchDeclaredProject(realPath, projects) {
15574
15687
  function matchChild(realPath, parentRoot, children) {
15575
15688
  const sorted = [...children].sort((a, b) => b.path.length - a.path.length);
15576
15689
  for (const c of sorted) {
15577
- const childRoot = safeRealpath(join25(parentRoot, c.path));
15690
+ const childRoot = safeRealpath(join26(parentRoot, c.path));
15578
15691
  if (isInside(realPath, childRoot))
15579
15692
  return c;
15580
15693
  }
@@ -15609,7 +15722,7 @@ function findGitToplevel(realPath) {
15609
15722
  let cur = realPath;
15610
15723
  let last = "";
15611
15724
  while (cur && cur !== last) {
15612
- if (existsSync21(join25(cur, ".git")))
15725
+ if (existsSync21(join26(cur, ".git")))
15613
15726
  return cur;
15614
15727
  last = cur;
15615
15728
  cur = dirname14(cur);
@@ -15676,7 +15789,7 @@ function resolveAutoWorkspace(realPath, minRepos) {
15676
15789
  let last = "";
15677
15790
  let depth = 0;
15678
15791
  while (cur && cur !== last && depth < AUTO_WORKSPACE_MAX_DEPTH) {
15679
- if (!existsSync21(join25(cur, ".git"))) {
15792
+ if (!existsSync21(join26(cur, ".git"))) {
15680
15793
  const cached = workspaceCache.get(cur);
15681
15794
  let qualifies;
15682
15795
  if (cached === void 0) {
@@ -15707,12 +15820,12 @@ function countGitChildren(dir) {
15707
15820
  for (const name of entries) {
15708
15821
  if (name.startsWith("."))
15709
15822
  continue;
15710
- const child = join25(dir, name);
15823
+ const child = join26(dir, name);
15711
15824
  try {
15712
15825
  const st = statSync20(child);
15713
15826
  if (!st.isDirectory())
15714
15827
  continue;
15715
- if (existsSync21(join25(child, ".git")))
15828
+ if (existsSync21(join26(child, ".git")))
15716
15829
  count++;
15717
15830
  } catch {
15718
15831
  }
@@ -16422,7 +16535,7 @@ var init_source_registry = __esm({
16422
16535
  // ../engine/dist/core/utils.js
16423
16536
  import { existsSync as existsSync22, readdirSync as readdirSync16 } from "fs";
16424
16537
  import { homedir as homedir7 } from "os";
16425
- import { join as join26 } from "path";
16538
+ import { join as join27 } from "path";
16426
16539
  function splitByHeaders(markdown) {
16427
16540
  const lines = markdown.split("\n");
16428
16541
  const sections = [];
@@ -16465,17 +16578,17 @@ function getClaudeDirs() {
16465
16578
  for (const d of process.env.CLAUDE_DIRS.split(",")) {
16466
16579
  const trimmed = d.trim();
16467
16580
  if (trimmed) {
16468
- add(trimmed.startsWith("~/") ? join26(home, trimmed.slice(2)) : trimmed);
16581
+ add(trimmed.startsWith("~/") ? join27(home, trimmed.slice(2)) : trimmed);
16469
16582
  }
16470
16583
  }
16471
16584
  }
16472
- add(join26(home, ".claude"));
16585
+ add(join27(home, ".claude"));
16473
16586
  try {
16474
16587
  const entries = readdirSync16(home, { withFileTypes: true });
16475
16588
  for (const entry of entries) {
16476
16589
  if (entry.isDirectory() && entry.name.startsWith(".claude-") && entry.name !== ".claude-code") {
16477
- const candidate = join26(home, entry.name);
16478
- if (existsSync22(join26(candidate, "projects"))) {
16590
+ const candidate = join27(home, entry.name);
16591
+ if (existsSync22(join27(candidate, "projects"))) {
16479
16592
  add(candidate);
16480
16593
  }
16481
16594
  }
@@ -16487,12 +16600,12 @@ function getClaudeDirs() {
16487
16600
  function discoverSubdirs(subdir) {
16488
16601
  const result = [];
16489
16602
  for (const claudeDir of getClaudeDirs()) {
16490
- const path = join26(claudeDir, subdir);
16603
+ const path = join27(claudeDir, subdir);
16491
16604
  if (existsSync22(path)) {
16492
16605
  result.push(path);
16493
16606
  }
16494
16607
  }
16495
- return result.length > 0 ? result : [join26(homedir7(), ".claude", subdir)];
16608
+ return result.length > 0 ? result : [join27(homedir7(), ".claude", subdir)];
16496
16609
  }
16497
16610
  var init_utils = __esm({
16498
16611
  "../engine/dist/core/utils.js"() {
@@ -16501,9 +16614,9 @@ var init_utils = __esm({
16501
16614
  });
16502
16615
 
16503
16616
  // ../engine/dist/parsers/plan-source.js
16504
- import { existsSync as existsSync23, readdirSync as readdirSync17, readFileSync as readFileSync20, statSync as statSync22 } from "fs";
16617
+ import { existsSync as existsSync23, readdirSync as readdirSync17, readFileSync as readFileSync21, statSync as statSync22 } from "fs";
16505
16618
  import { homedir as homedir8 } from "os";
16506
- import { join as join27, basename as basename14 } from "path";
16619
+ import { join as join28, basename as basename14 } from "path";
16507
16620
  function parseFrontmatter(content) {
16508
16621
  if (!content.startsWith("---"))
16509
16622
  return { body: content };
@@ -16598,12 +16711,12 @@ var init_plan_source = __esm({
16598
16711
  if (seenClaude.has(file))
16599
16712
  continue;
16600
16713
  seenClaude.add(file);
16601
- const filePath = join27(plansDir, file);
16714
+ const filePath = join28(plansDir, file);
16602
16715
  try {
16603
16716
  const stat3 = statSync22(filePath);
16604
16717
  const planName = basename14(file, ".md");
16605
16718
  const isAgentPlan = planName.includes("-agent-");
16606
- const content = readFileSync20(filePath, "utf-8");
16719
+ const content = readFileSync21(filePath, "utf-8");
16607
16720
  const fm = parseFrontmatter(content);
16608
16721
  const body = fm.body;
16609
16722
  const firstLine = body.split("\n").find((l) => l.trim())?.replace(/^#+\s*/, "").trim() || planName;
@@ -16642,10 +16755,10 @@ var init_plan_source = __esm({
16642
16755
  return;
16643
16756
  }
16644
16757
  for (const file of files) {
16645
- const filePath = join27(plansDir, file);
16758
+ const filePath = join28(plansDir, file);
16646
16759
  try {
16647
16760
  const stat3 = statSync22(filePath);
16648
- const content = readFileSync20(filePath, "utf-8");
16761
+ const content = readFileSync21(filePath, "utf-8");
16649
16762
  const firstLine = content.split("\n").find((l) => l.trim())?.replace(/^#+\s*/, "").trim() || file;
16650
16763
  const planName = `${opencodeBackend.idPrefix}plan_${basename14(file, ".md")}`;
16651
16764
  const projectPath = this.extractProjectPath(content);
@@ -16673,7 +16786,7 @@ var init_plan_source = __esm({
16673
16786
  for (const match of content.matchAll(fullPathPattern)) {
16674
16787
  let path = (match[1] || "").trim();
16675
16788
  if (path.startsWith("~/")) {
16676
- path = join27(homedir8(), path.slice(2));
16789
+ path = join28(homedir8(), path.slice(2));
16677
16790
  }
16678
16791
  for (const projectDir of knownProjects) {
16679
16792
  if (path.startsWith(projectDir)) {
@@ -16722,7 +16835,7 @@ var init_plan_source = __esm({
16722
16835
  async parse(item) {
16723
16836
  if (!existsSync23(item.filePath))
16724
16837
  return [];
16725
- const content = readFileSync20(item.filePath, "utf-8");
16838
+ const content = readFileSync21(item.filePath, "utf-8");
16726
16839
  const chunks = [];
16727
16840
  const { body } = parseFrontmatter(content);
16728
16841
  const sections = splitByHeaders(body);
@@ -16758,9 +16871,9 @@ var init_plan_source = __esm({
16758
16871
  const map = /* @__PURE__ */ new Map();
16759
16872
  const root = claudeBackend.projectsDir();
16760
16873
  for (const proj of safeReaddir(root)) {
16761
- const projPath = join27(root, proj);
16874
+ const projPath = join28(root, proj);
16762
16875
  for (const sessionEntry of safeReaddir(projPath)) {
16763
- const subDir = join27(projPath, sessionEntry, "subagents");
16876
+ const subDir = join28(projPath, sessionEntry, "subagents");
16764
16877
  if (!existsSync23(subDir))
16765
16878
  continue;
16766
16879
  for (const f of safeReaddir(subDir)) {
@@ -16835,7 +16948,7 @@ var init_plan_source = __esm({
16835
16948
  return links;
16836
16949
  }
16837
16950
  async *discoverAgyPlans() {
16838
- const brainDir = join27(agyBackend.homeDir(), "brain");
16951
+ const brainDir = join28(agyBackend.homeDir(), "brain");
16839
16952
  if (!existsSync23(brainDir))
16840
16953
  return;
16841
16954
  let sessionDirs;
@@ -16845,7 +16958,7 @@ var init_plan_source = __esm({
16845
16958
  return;
16846
16959
  }
16847
16960
  for (const rawId of sessionDirs) {
16848
- const sessionPath = join27(brainDir, rawId);
16961
+ const sessionPath = join28(brainDir, rawId);
16849
16962
  try {
16850
16963
  if (!statSync22(sessionPath).isDirectory())
16851
16964
  continue;
@@ -16859,10 +16972,10 @@ var init_plan_source = __esm({
16859
16972
  continue;
16860
16973
  }
16861
16974
  for (const file of files) {
16862
- const filePath = join27(sessionPath, file);
16975
+ const filePath = join28(sessionPath, file);
16863
16976
  try {
16864
16977
  const stat3 = statSync22(filePath);
16865
- const content = readFileSync20(filePath, "utf-8");
16978
+ const content = readFileSync21(filePath, "utf-8");
16866
16979
  const firstLine = content.split("\n").find((l) => l.trim())?.replace(/^#+\s*/, "").trim() || file;
16867
16980
  const sessionLoc = agyBackend.findSession(rawId);
16868
16981
  const projectPath = sessionLoc?.projectPath || this.extractProjectPath(content);
@@ -16891,8 +17004,8 @@ var init_plan_source = __esm({
16891
17004
  });
16892
17005
 
16893
17006
  // ../engine/dist/parsers/task-source.js
16894
- import { existsSync as existsSync24, readdirSync as readdirSync18, readFileSync as readFileSync21, statSync as statSync23 } from "fs";
16895
- import { join as join28 } from "path";
17007
+ import { existsSync as existsSync24, readdirSync as readdirSync18, readFileSync as readFileSync22, statSync as statSync23 } from "fs";
17008
+ import { join as join29 } from "path";
16896
17009
  var MAX_CHUNK_CHARS2, TaskSource;
16897
17010
  var init_task_source = __esm({
16898
17011
  "../engine/dist/parsers/task-source.js"() {
@@ -16930,7 +17043,7 @@ var init_task_source = __esm({
16930
17043
  return;
16931
17044
  }
16932
17045
  for (const file of files) {
16933
- const filePath = join28(todosDir, file);
17046
+ const filePath = join29(todosDir, file);
16934
17047
  let stat3;
16935
17048
  try {
16936
17049
  stat3 = statSync23(filePath);
@@ -16941,7 +17054,7 @@ var init_task_source = __esm({
16941
17054
  continue;
16942
17055
  let parsed;
16943
17056
  try {
16944
- const raw = readFileSync21(filePath, "utf-8");
17057
+ const raw = readFileSync22(filePath, "utf-8");
16945
17058
  parsed = JSON.parse(raw);
16946
17059
  if (!Array.isArray(parsed) || parsed.length === 0)
16947
17060
  continue;
@@ -16979,7 +17092,7 @@ var init_task_source = __esm({
16979
17092
  if (!entry.isDirectory())
16980
17093
  continue;
16981
17094
  const sessionUuid = entry.name;
16982
- const taskDir = join28(tasksDir, sessionUuid);
17095
+ const taskDir = join29(tasksDir, sessionUuid);
16983
17096
  try {
16984
17097
  const stat3 = statSync23(taskDir);
16985
17098
  const taskFiles = readdirSync18(taskDir).filter((f) => f.endsWith(".json"));
@@ -17054,7 +17167,7 @@ ${task.description}`.slice(0, MAX_CHUNK_CHARS2);
17054
17167
  text,
17055
17168
  chunkType: "task_detail",
17056
17169
  projectPath: item.projectPath,
17057
- filePath: join28(taskDir, `${task.id}.json`),
17170
+ filePath: join29(taskDir, `${task.id}.json`),
17058
17171
  mtime: item.mtime
17059
17172
  });
17060
17173
  }
@@ -17079,7 +17192,7 @@ ${task.description}`.slice(0, MAX_CHUNK_CHARS2);
17079
17192
  return [];
17080
17193
  let parsed;
17081
17194
  try {
17082
- parsed = JSON.parse(readFileSync21(item.filePath, "utf-8"));
17195
+ parsed = JSON.parse(readFileSync22(item.filePath, "utf-8"));
17083
17196
  } catch {
17084
17197
  return [];
17085
17198
  }
@@ -17111,7 +17224,7 @@ ${task.description}`.slice(0, MAX_CHUNK_CHARS2);
17111
17224
  });
17112
17225
  for (const file of sorted) {
17113
17226
  try {
17114
- const content = readFileSync21(join28(taskDir, file), "utf-8");
17227
+ const content = readFileSync22(join29(taskDir, file), "utf-8");
17115
17228
  const task = JSON.parse(content);
17116
17229
  if (task.subject) {
17117
17230
  tasks.push(task);
@@ -17127,9 +17240,9 @@ ${task.description}`.slice(0, MAX_CHUNK_CHARS2);
17127
17240
  });
17128
17241
 
17129
17242
  // ../engine/dist/parsers/claude-md-source.js
17130
- import { existsSync as existsSync25, readFileSync as readFileSync22, readdirSync as readdirSync19, statSync as statSync24 } from "fs";
17243
+ import { existsSync as existsSync25, readFileSync as readFileSync23, readdirSync as readdirSync19, statSync as statSync24 } from "fs";
17131
17244
  import { homedir as homedir9 } from "os";
17132
- import { join as join29, basename as basename15, dirname as dirname15 } from "path";
17245
+ import { join as join30, basename as basename15, dirname as dirname15 } from "path";
17133
17246
  import { createHash as createHash8 } from "crypto";
17134
17247
  function discoverProjectDirs(claudeDir) {
17135
17248
  const dirs = [];
@@ -17155,7 +17268,7 @@ function discoverProjectDirs(claudeDir) {
17155
17268
  }
17156
17269
  };
17157
17270
  if (claudeDir) {
17158
- scanProjectsDir(join29(claudeDir, "projects"));
17271
+ scanProjectsDir(join30(claudeDir, "projects"));
17159
17272
  return dirs;
17160
17273
  }
17161
17274
  const home = homedir9();
@@ -17163,7 +17276,7 @@ function discoverProjectDirs(claudeDir) {
17163
17276
  try {
17164
17277
  for (const entry of readdirSync19(home, { withFileTypes: true })) {
17165
17278
  if (entry.isDirectory() && entry.name.startsWith(".claude-") && entry.name !== ".claude-code") {
17166
- scanProjectsDir(join29(home, entry.name, "projects"));
17279
+ scanProjectsDir(join30(home, entry.name, "projects"));
17167
17280
  }
17168
17281
  }
17169
17282
  } catch {
@@ -17171,7 +17284,7 @@ function discoverProjectDirs(claudeDir) {
17171
17284
  const gemProjects = agyBackend.sharedProjectsJson();
17172
17285
  if (existsSync25(gemProjects)) {
17173
17286
  try {
17174
- const data = JSON.parse(readFileSync22(gemProjects, "utf-8"));
17287
+ const data = JSON.parse(readFileSync23(gemProjects, "utf-8"));
17175
17288
  for (const path of Object.keys(data.projects || {}))
17176
17289
  addProject(path);
17177
17290
  } catch {
@@ -17227,7 +17340,7 @@ var init_claude_md_source = __esm({
17227
17340
  const seen = /* @__PURE__ */ new Set();
17228
17341
  const seenKey = (path, tool) => `${tool}:${path}`;
17229
17342
  for (const note of NOTE_FILES) {
17230
- const p = join29(homedir9(), note.filename);
17343
+ const p = join30(homedir9(), note.filename);
17231
17344
  const key2 = seenKey(p, note.tool);
17232
17345
  if (existsSync25(p) && !seen.has(key2)) {
17233
17346
  seen.add(key2);
@@ -17239,7 +17352,7 @@ var init_claude_md_source = __esm({
17239
17352
  const projectDirs = discoverProjectDirs(this.claudeDir);
17240
17353
  for (const projectDir of projectDirs) {
17241
17354
  for (const note of NOTE_FILES) {
17242
- const p = join29(projectDir, note.filename);
17355
+ const p = join30(projectDir, note.filename);
17243
17356
  const key2 = seenKey(p, note.tool);
17244
17357
  if (existsSync25(p) && !seen.has(key2)) {
17245
17358
  seen.add(key2);
@@ -17253,7 +17366,7 @@ var init_claude_md_source = __esm({
17253
17366
  if (!existsSync25(searchDir))
17254
17367
  continue;
17255
17368
  for (const note of NOTE_FILES) {
17256
- const directPath = join29(searchDir, note.filename);
17369
+ const directPath = join30(searchDir, note.filename);
17257
17370
  const key2 = seenKey(directPath, note.tool);
17258
17371
  if (existsSync25(directPath) && !seen.has(key2)) {
17259
17372
  seen.add(key2);
@@ -17268,7 +17381,7 @@ var init_claude_md_source = __esm({
17268
17381
  if (!entry.isDirectory())
17269
17382
  continue;
17270
17383
  for (const note of NOTE_FILES) {
17271
- const p = join29(searchDir, entry.name, note.filename);
17384
+ const p = join30(searchDir, entry.name, note.filename);
17272
17385
  const key2 = seenKey(p, note.tool);
17273
17386
  if (existsSync25(p) && !seen.has(key2)) {
17274
17387
  seen.add(key2);
@@ -17286,7 +17399,7 @@ var init_claude_md_source = __esm({
17286
17399
  async parse(item) {
17287
17400
  if (!existsSync25(item.filePath))
17288
17401
  return [];
17289
- const content = readFileSync22(item.filePath, "utf-8");
17402
+ const content = readFileSync23(item.filePath, "utf-8");
17290
17403
  const chunks = [];
17291
17404
  const sections = splitByHeaders(content);
17292
17405
  for (let i = 0; i < sections.length; i++) {
@@ -17328,7 +17441,7 @@ var init_claude_md_source = __esm({
17328
17441
  const projectDir = dirname15(filePath);
17329
17442
  const projectName = basename15(projectDir);
17330
17443
  const projectPath = projectDir;
17331
- const content = readFileSync22(filePath, "utf-8");
17444
+ const content = readFileSync23(filePath, "utf-8");
17332
17445
  const firstLine = content.split("\n").find((l) => l.trim() && !l.startsWith("#"))?.trim()?.slice(0, 200) || `${filename} for ${projectName}`;
17333
17446
  const id = tool === "claude" ? projectName : `${projectName}_${tool}`;
17334
17447
  return {
@@ -17353,9 +17466,9 @@ var init_claude_md_source = __esm({
17353
17466
  });
17354
17467
 
17355
17468
  // ../engine/dist/parsers/agent-memory-source.js
17356
- import { existsSync as existsSync26, readFileSync as readFileSync23, readdirSync as readdirSync20, statSync as statSync25 } from "fs";
17469
+ import { existsSync as existsSync26, readFileSync as readFileSync24, readdirSync as readdirSync20, statSync as statSync25 } from "fs";
17357
17470
  import { homedir as homedir10 } from "os";
17358
- import { join as join30, basename as basename16 } from "path";
17471
+ import { join as join31, basename as basename16 } from "path";
17359
17472
  function parseFrontmatter2(content) {
17360
17473
  const fm = {};
17361
17474
  let body = content;
@@ -17397,7 +17510,7 @@ function discoverMemoryDirs() {
17397
17510
  try {
17398
17511
  for (const entry of readdirSync20(home, { withFileTypes: true })) {
17399
17512
  if (entry.isDirectory() && entry.name.startsWith(".claude-") && entry.name !== ".claude-code") {
17400
- claudeRoots.push(join30(home, entry.name, "projects"));
17513
+ claudeRoots.push(join31(home, entry.name, "projects"));
17401
17514
  }
17402
17515
  }
17403
17516
  } catch {
@@ -17409,7 +17522,7 @@ function discoverMemoryDirs() {
17409
17522
  for (const entry of readdirSync20(projectsDir, { withFileTypes: true })) {
17410
17523
  if (!entry.isDirectory() || entry.name.startsWith("."))
17411
17524
  continue;
17412
- add(join30(projectsDir, entry.name, "memory"), entry.name);
17525
+ add(join31(projectsDir, entry.name, "memory"), entry.name);
17413
17526
  }
17414
17527
  } catch {
17415
17528
  }
@@ -17438,7 +17551,7 @@ var init_agent_memory_source = __esm({
17438
17551
  for (const entry of readdirSync20(memoryDir, { withFileTypes: true })) {
17439
17552
  if (!entry.isFile() || !entry.name.endsWith(".md"))
17440
17553
  continue;
17441
- const filePath = join30(memoryDir, entry.name);
17554
+ const filePath = join31(memoryDir, entry.name);
17442
17555
  if (seen.has(filePath))
17443
17556
  continue;
17444
17557
  seen.add(filePath);
@@ -17454,7 +17567,7 @@ var init_agent_memory_source = __esm({
17454
17567
  async parse(item) {
17455
17568
  if (!existsSync26(item.filePath))
17456
17569
  return [];
17457
- const content = readFileSync23(item.filePath, "utf-8");
17570
+ const content = readFileSync24(item.filePath, "utf-8");
17458
17571
  const { body } = parseFrontmatter2(content);
17459
17572
  const chunks = [];
17460
17573
  const sections = splitByHeaders(body);
@@ -17507,7 +17620,7 @@ var init_agent_memory_source = __esm({
17507
17620
  fileToItem(filePath, filename, projectPath, _projectHash) {
17508
17621
  try {
17509
17622
  const stat3 = statSync25(filePath);
17510
- const content = readFileSync23(filePath, "utf-8");
17623
+ const content = readFileSync24(filePath, "utf-8");
17511
17624
  const { fm } = parseFrontmatter2(content);
17512
17625
  const stem = filename.replace(/\.md$/, "");
17513
17626
  const idBase = fm.name || stem;
@@ -17542,7 +17655,7 @@ import { existsSync as existsSync27, readdirSync as readdirSync21, statSync as s
17542
17655
  import { createReadStream as createReadStream3 } from "fs";
17543
17656
  import { createInterface as createInterface2 } from "readline";
17544
17657
  import { homedir as homedir11 } from "os";
17545
- import { join as join31 } from "path";
17658
+ import { join as join32 } from "path";
17546
17659
  var MAX_CHUNK_CHARS5, HistorySource;
17547
17660
  var init_history_source = __esm({
17548
17661
  "../engine/dist/parsers/history-source.js"() {
@@ -17567,12 +17680,12 @@ var init_history_source = __esm({
17567
17680
  try {
17568
17681
  for (const entry of readdirSync21(home, { withFileTypes: true })) {
17569
17682
  if (entry.isDirectory() && entry.name.startsWith(".claude-") && entry.name !== ".claude-code") {
17570
- tryAdd(join31(home, entry.name, "history.jsonl"));
17683
+ tryAdd(join32(home, entry.name, "history.jsonl"));
17571
17684
  }
17572
17685
  }
17573
17686
  } catch {
17574
17687
  }
17575
- this.historyPaths = paths.length > 0 ? paths : [join31(home, ".claude", "history.jsonl")];
17688
+ this.historyPaths = paths.length > 0 ? paths : [join32(home, ".claude", "history.jsonl")];
17576
17689
  }
17577
17690
  }
17578
17691
  async *discover() {
@@ -17722,9 +17835,9 @@ var init_history_source = __esm({
17722
17835
  });
17723
17836
 
17724
17837
  // ../engine/dist/parsers/paste-source.js
17725
- import { existsSync as existsSync28, readdirSync as readdirSync22, readFileSync as readFileSync24, statSync as statSync27 } from "fs";
17838
+ import { existsSync as existsSync28, readdirSync as readdirSync22, readFileSync as readFileSync25, statSync as statSync27 } from "fs";
17726
17839
  import { homedir as homedir12 } from "os";
17727
- import { join as join32, basename as basename17 } from "path";
17840
+ import { join as join33, basename as basename17 } from "path";
17728
17841
  var MAX_CHUNK_CHARS6, MAX_FILE_SIZE, PasteSource;
17729
17842
  var init_paste_source = __esm({
17730
17843
  "../engine/dist/parsers/paste-source.js"() {
@@ -17750,7 +17863,7 @@ var init_paste_source = __esm({
17750
17863
  try {
17751
17864
  for (const entry of readdirSync22(home, { withFileTypes: true })) {
17752
17865
  if (entry.isDirectory() && entry.name.startsWith(".claude-") && entry.name !== ".claude-code") {
17753
- tryAdd(join32(home, entry.name, "paste-cache"));
17866
+ tryAdd(join33(home, entry.name, "paste-cache"));
17754
17867
  }
17755
17868
  }
17756
17869
  } catch {
@@ -17770,7 +17883,7 @@ var init_paste_source = __esm({
17770
17883
  if (seen.has(file))
17771
17884
  continue;
17772
17885
  seen.add(file);
17773
- const filePath = join32(cacheDir, file);
17886
+ const filePath = join33(cacheDir, file);
17774
17887
  try {
17775
17888
  const stat3 = statSync27(filePath);
17776
17889
  if (stat3.size > MAX_FILE_SIZE)
@@ -17778,7 +17891,7 @@ var init_paste_source = __esm({
17778
17891
  if (stat3.size < 10)
17779
17892
  continue;
17780
17893
  const hash = basename17(file, ".txt");
17781
- const content = readFileSync24(filePath, "utf-8");
17894
+ const content = readFileSync25(filePath, "utf-8");
17782
17895
  const firstLine = content.split("\n").find((l) => l.trim().length > 5)?.trim()?.slice(0, 100) || `Paste ${hash.slice(0, 8)}`;
17783
17896
  yield {
17784
17897
  id: hash,
@@ -17799,7 +17912,7 @@ var init_paste_source = __esm({
17799
17912
  async parse(item) {
17800
17913
  if (!existsSync28(item.filePath))
17801
17914
  return [];
17802
- const content = readFileSync24(item.filePath, "utf-8");
17915
+ const content = readFileSync25(item.filePath, "utf-8");
17803
17916
  if (content.trim().length < 20)
17804
17917
  return [];
17805
17918
  return [{
@@ -17822,8 +17935,8 @@ var init_paste_source = __esm({
17822
17935
  });
17823
17936
 
17824
17937
  // ../engine/dist/parsers/antigravity-brain-source.js
17825
- import { existsSync as existsSync29, readdirSync as readdirSync23, readFileSync as readFileSync25, statSync as statSync28 } from "fs";
17826
- import { join as join33 } from "path";
17938
+ import { existsSync as existsSync29, readdirSync as readdirSync23, readFileSync as readFileSync26, statSync as statSync28 } from "fs";
17939
+ import { join as join34 } from "path";
17827
17940
  var MAX_CHUNK_CHARS7, AntigravityBrainSource;
17828
17941
  var init_antigravity_brain_source = __esm({
17829
17942
  "../engine/dist/parsers/antigravity-brain-source.js"() {
@@ -17847,22 +17960,22 @@ var init_antigravity_brain_source = __esm({
17847
17960
  for (const entry of sessions) {
17848
17961
  if (!entry.isDirectory())
17849
17962
  continue;
17850
- const sessionDir = join33(this.brainDir, entry.name);
17963
+ const sessionDir = join34(this.brainDir, entry.name);
17851
17964
  const files = readdirSync23(sessionDir).filter((f) => f.endsWith(".md") && !f.includes(".resolved") && !f.includes(".metadata"));
17852
17965
  if (files.length === 0)
17853
17966
  continue;
17854
17967
  for (const file of files) {
17855
- const filePath = join33(sessionDir, file);
17968
+ const filePath = join34(sessionDir, file);
17856
17969
  try {
17857
17970
  const stat3 = statSync28(filePath);
17858
- const content = readFileSync25(filePath, "utf-8");
17971
+ const content = readFileSync26(filePath, "utf-8");
17859
17972
  const firstLine = content.split("\n").find((l) => l.trim() && !l.startsWith("#"))?.trim() || "";
17860
17973
  const heading = content.split("\n").find((l) => l.startsWith("#"))?.replace(/^#+\s*/, "").trim() || file;
17861
17974
  const metaPath = `${filePath}.metadata.json`;
17862
17975
  let metaSummary = "";
17863
17976
  if (existsSync29(metaPath)) {
17864
17977
  try {
17865
- const meta = JSON.parse(readFileSync25(metaPath, "utf-8"));
17978
+ const meta = JSON.parse(readFileSync26(metaPath, "utf-8"));
17866
17979
  metaSummary = meta.summary || "";
17867
17980
  } catch {
17868
17981
  }
@@ -17893,7 +18006,7 @@ var init_antigravity_brain_source = __esm({
17893
18006
  async parse(item) {
17894
18007
  if (!existsSync29(item.filePath))
17895
18008
  return [];
17896
- const content = readFileSync25(item.filePath, "utf-8");
18009
+ const content = readFileSync26(item.filePath, "utf-8");
17897
18010
  const chunks = [];
17898
18011
  const sections = splitByHeaders(content);
17899
18012
  for (let i = 0; i < sections.length; i++) {
@@ -18236,8 +18349,8 @@ var init_opencode_todo_source = __esm({
18236
18349
  });
18237
18350
 
18238
18351
  // ../engine/dist/parsers/codex-session-source.js
18239
- import { existsSync as existsSync32, readdirSync as readdirSync24, readFileSync as readFileSync26, statSync as statSync29 } from "fs";
18240
- import { join as join34, basename as basename18 } from "path";
18352
+ import { existsSync as existsSync32, readdirSync as readdirSync24, readFileSync as readFileSync27, statSync as statSync29 } from "fs";
18353
+ import { join as join35, basename as basename18 } from "path";
18241
18354
  function getCodexSessionsDir() {
18242
18355
  return codexBackend.sessionsDir();
18243
18356
  }
@@ -18264,7 +18377,7 @@ function extractReasoningText(event) {
18264
18377
  return "";
18265
18378
  }
18266
18379
  function readJsonlLines(filePath) {
18267
- const text = readFileSync26(filePath, "utf-8");
18380
+ const text = readFileSync27(filePath, "utf-8");
18268
18381
  const lines = text.split("\n");
18269
18382
  const events = [];
18270
18383
  for (const line of lines) {
@@ -18299,7 +18412,7 @@ var init_codex_session_source = __esm({
18299
18412
  for (const filePath of jsonlFiles) {
18300
18413
  try {
18301
18414
  const stat3 = statSync29(filePath);
18302
- const lines = readFileSync26(filePath, "utf-8").split("\n");
18415
+ const lines = readFileSync27(filePath, "utf-8").split("\n");
18303
18416
  const firstLine = lines.find((l) => l.trim());
18304
18417
  if (!firstLine)
18305
18418
  continue;
@@ -18458,7 +18571,7 @@ var init_codex_session_source = __esm({
18458
18571
  if (!existsSync32(dir))
18459
18572
  return results;
18460
18573
  for (const entry of readdirSync24(dir, { withFileTypes: true })) {
18461
- const fullPath = join34(dir, entry.name);
18574
+ const fullPath = join35(dir, entry.name);
18462
18575
  if (entry.isDirectory()) {
18463
18576
  results.push(...this.collectJsonlFiles(fullPath));
18464
18577
  } else if (entry.isFile() && entry.name.startsWith("rollout-") && entry.name.endsWith(".jsonl")) {
@@ -18472,8 +18585,8 @@ var init_codex_session_source = __esm({
18472
18585
  });
18473
18586
 
18474
18587
  // ../engine/dist/parsers/diary-source.js
18475
- import { existsSync as existsSync33, mkdirSync as mkdirSync7, readdirSync as readdirSync25, readFileSync as readFileSync27, writeFileSync as writeFileSync6, statSync as statSync30 } from "fs";
18476
- import { join as join35, basename as basename19 } from "path";
18588
+ import { existsSync as existsSync33, mkdirSync as mkdirSync7, readdirSync as readdirSync25, readFileSync as readFileSync28, writeFileSync as writeFileSync7, statSync as statSync30 } from "fs";
18589
+ import { join as join36, basename as basename19 } from "path";
18477
18590
  var MAX_CHUNK_CHARS10, DiarySource;
18478
18591
  var init_diary_source = __esm({
18479
18592
  "../engine/dist/parsers/diary-source.js"() {
@@ -18492,13 +18605,13 @@ var init_diary_source = __esm({
18492
18605
  return;
18493
18606
  const agents = readdirSync25(this.diaryDir, { withFileTypes: true }).filter((d) => d.isDirectory());
18494
18607
  for (const agentDir of agents) {
18495
- const agentPath2 = join35(this.diaryDir, agentDir.name);
18608
+ const agentPath2 = join36(this.diaryDir, agentDir.name);
18496
18609
  const files = readdirSync25(agentPath2).filter((f) => f.endsWith(".json"));
18497
18610
  for (const file of files) {
18498
- const filePath = join35(agentPath2, file);
18611
+ const filePath = join36(agentPath2, file);
18499
18612
  try {
18500
18613
  const stat3 = statSync30(filePath);
18501
- const raw = readFileSync27(filePath, "utf-8");
18614
+ const raw = readFileSync28(filePath, "utf-8");
18502
18615
  const entry = JSON.parse(raw);
18503
18616
  const entryId = basename19(file, ".json");
18504
18617
  const title = `[${entry.agent}] ${entry.topic}: ${entry.content.slice(0, 80)}`;
@@ -18525,7 +18638,7 @@ var init_diary_source = __esm({
18525
18638
  async parse(item) {
18526
18639
  if (!existsSync33(item.filePath))
18527
18640
  return [];
18528
- const raw = readFileSync27(item.filePath, "utf-8");
18641
+ const raw = readFileSync28(item.filePath, "utf-8");
18529
18642
  const entry = JSON.parse(raw);
18530
18643
  if (!entry.content || entry.content.trim().length < 10)
18531
18644
  return [];
@@ -18562,18 +18675,18 @@ var init_diary_source = __esm({
18562
18675
  */
18563
18676
  static write(entry, diaryDir) {
18564
18677
  const dir = diaryDir || getDiaryDir();
18565
- const agentDir = join35(dir, entry.agent.toLowerCase().replace(/[^a-z0-9_-]/g, "_"));
18678
+ const agentDir = join36(dir, entry.agent.toLowerCase().replace(/[^a-z0-9_-]/g, "_"));
18566
18679
  if (!existsSync33(agentDir)) {
18567
18680
  mkdirSync7(agentDir, { recursive: true });
18568
18681
  }
18569
18682
  const ts = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-");
18570
18683
  const entryId = `diary_${entry.agent.toLowerCase()}_${ts}`;
18571
- const filePath = join35(agentDir, `${entryId}.json`);
18684
+ const filePath = join36(agentDir, `${entryId}.json`);
18572
18685
  const full = {
18573
18686
  ...entry,
18574
18687
  timestamp: entry.timestamp || (/* @__PURE__ */ new Date()).toISOString()
18575
18688
  };
18576
- writeFileSync6(filePath, JSON.stringify(full, null, 2), "utf-8");
18689
+ writeFileSync7(filePath, JSON.stringify(full, null, 2), "utf-8");
18577
18690
  return entryId;
18578
18691
  }
18579
18692
  /**
@@ -18581,14 +18694,14 @@ var init_diary_source = __esm({
18581
18694
  */
18582
18695
  static read(agentName, lastN = 10, diaryDir) {
18583
18696
  const dir = diaryDir || getDiaryDir();
18584
- const agentDir = join35(dir, agentName.toLowerCase().replace(/[^a-z0-9_-]/g, "_"));
18697
+ const agentDir = join36(dir, agentName.toLowerCase().replace(/[^a-z0-9_-]/g, "_"));
18585
18698
  if (!existsSync33(agentDir))
18586
18699
  return [];
18587
18700
  const files = readdirSync25(agentDir).filter((f) => f.endsWith(".json")).sort().reverse().slice(0, lastN);
18588
18701
  const entries = [];
18589
18702
  for (const file of files) {
18590
18703
  try {
18591
- const raw = readFileSync27(join35(agentDir, file), "utf-8");
18704
+ const raw = readFileSync28(join36(agentDir, file), "utf-8");
18592
18705
  entries.push(JSON.parse(raw));
18593
18706
  } catch {
18594
18707
  continue;
@@ -18633,9 +18746,9 @@ var init_redact_inline = __esm({
18633
18746
  });
18634
18747
 
18635
18748
  // ../engine/dist/parsers/skills-source.js
18636
- import { existsSync as existsSync34, readdirSync as readdirSync26, readFileSync as readFileSync28, statSync as statSync31 } from "fs";
18749
+ import { existsSync as existsSync34, readdirSync as readdirSync26, readFileSync as readFileSync29, statSync as statSync31 } from "fs";
18637
18750
  import { homedir as homedir13 } from "os";
18638
- import { join as join36 } from "path";
18751
+ import { join as join37 } from "path";
18639
18752
  function rebuildBody(content) {
18640
18753
  const { text, redacted } = redactInlineSecrets(content);
18641
18754
  const out = {};
@@ -18653,31 +18766,31 @@ function resolveRoots() {
18653
18766
  const home = homedir13();
18654
18767
  const all = [];
18655
18768
  if (isSourceEnabled("shared", "skills")) {
18656
- all.push({ path: join36(home, ".agents", "skills"), tool: "shared" });
18769
+ all.push({ path: join37(home, ".agents", "skills"), tool: "shared" });
18657
18770
  }
18658
18771
  if (isSourceEnabled("claude", "skills")) {
18659
18772
  all.push({ path: claudeBackend.skillsDir(), tool: "claude" });
18660
18773
  }
18661
18774
  if (isSourceEnabled("hermes", "skills")) {
18662
- all.push({ path: join36(hermesBackend.homeDir(), "skills"), tool: "hermes", nested: true });
18775
+ all.push({ path: join37(hermesBackend.homeDir(), "skills"), tool: "hermes", nested: true });
18663
18776
  }
18664
18777
  if (isSourceEnabled("pi", "skills")) {
18665
18778
  all.push({ path: piBackend.skillsDir(), tool: "pi" });
18666
18779
  }
18667
18780
  if (isSourceEnabled("agy", "skills")) {
18668
- all.push({ path: join36(agyBackend.homeDir(), "skills"), tool: "agy" });
18781
+ all.push({ path: join37(agyBackend.homeDir(), "skills"), tool: "agy" });
18669
18782
  all.push({ path: agyBackend.sharedSkillsDir(), tool: "agy" });
18670
18783
  }
18671
18784
  if (isSourceEnabled("opencode", "skills")) {
18672
- all.push({ path: join36(home, ".config", "opencode", "skills"), tool: "opencode" }, { path: join36(home, ".config", "opencode", "skill"), tool: "opencode" }, { path: join36(home, ".opencode", "skill"), tool: "opencode" }, { path: join36(home, ".opencode", "skills"), tool: "opencode" });
18785
+ all.push({ path: join37(home, ".config", "opencode", "skills"), tool: "opencode" }, { path: join37(home, ".config", "opencode", "skill"), tool: "opencode" }, { path: join37(home, ".opencode", "skill"), tool: "opencode" }, { path: join37(home, ".opencode", "skills"), tool: "opencode" });
18673
18786
  }
18674
18787
  if (isSourceEnabled("codex", "skills")) {
18675
18788
  all.push({ path: codexBackend.skillsDir(), tool: "codex", skipChildren: [".system"] });
18676
18789
  all.push({ path: codexBackend.skillsSystemDir(), tool: "codex", readonly: true });
18677
18790
  }
18678
18791
  if (isSourceEnabled("cursor", "skills")) {
18679
- all.push({ path: join36(cursorHomeDir(), "skills"), tool: "cursor" });
18680
- all.push({ path: join36(cursorHomeDir(), "skills-cursor"), tool: "cursor", readonly: true });
18792
+ all.push({ path: join37(cursorHomeDir(), "skills"), tool: "cursor" });
18793
+ all.push({ path: join37(cursorHomeDir(), "skills-cursor"), tool: "cursor", readonly: true });
18681
18794
  }
18682
18795
  return all.filter((r) => existsSync34(r.path));
18683
18796
  }
@@ -18722,7 +18835,7 @@ var init_skills_source = __esm({
18722
18835
  if (!isSourceEnabled("codex", "skills"))
18723
18836
  return;
18724
18837
  for (const { name: pluginName, dir } of codexBackend.installedPluginDirs()) {
18725
- const skillsDir = join36(dir, "skills");
18838
+ const skillsDir = join37(dir, "skills");
18726
18839
  if (!existsSync34(skillsDir))
18727
18840
  continue;
18728
18841
  yield* this.fromSkillRoot({ path: skillsDir, tool: "codex" }, pluginName);
@@ -18738,7 +18851,7 @@ var init_skills_source = __esm({
18738
18851
  for (const name of entries) {
18739
18852
  if (root.skipChildren?.includes(name))
18740
18853
  continue;
18741
- const skillDir = join36(root.path, name);
18854
+ const skillDir = join37(root.path, name);
18742
18855
  let st;
18743
18856
  try {
18744
18857
  st = statSync31(skillDir);
@@ -18747,7 +18860,7 @@ var init_skills_source = __esm({
18747
18860
  }
18748
18861
  if (!st.isDirectory())
18749
18862
  continue;
18750
- const skillMd = join36(skillDir, "SKILL.md");
18863
+ const skillMd = join37(skillDir, "SKILL.md");
18751
18864
  if (!existsSync34(skillMd)) {
18752
18865
  if (root.nested)
18753
18866
  yield* this.fromSkillRoot({ ...root, path: skillDir, nested: false });
@@ -18755,7 +18868,7 @@ var init_skills_source = __esm({
18755
18868
  }
18756
18869
  let content;
18757
18870
  try {
18758
- content = readFileSync28(skillMd, "utf-8");
18871
+ content = readFileSync29(skillMd, "utf-8");
18759
18872
  } catch {
18760
18873
  continue;
18761
18874
  }
@@ -18769,7 +18882,7 @@ var init_skills_source = __esm({
18769
18882
  const subdirs = {};
18770
18883
  try {
18771
18884
  for (const sub of readdirSync26(skillDir)) {
18772
- const subPath = join36(skillDir, sub);
18885
+ const subPath = join37(skillDir, sub);
18773
18886
  try {
18774
18887
  const ss = statSync31(subPath);
18775
18888
  if (ss.isDirectory()) {
@@ -18818,7 +18931,7 @@ var init_skills_source = __esm({
18818
18931
  async parse(item) {
18819
18932
  if (!existsSync34(item.filePath))
18820
18933
  return [];
18821
- const content = readFileSync28(item.filePath, "utf-8");
18934
+ const content = readFileSync29(item.filePath, "utf-8");
18822
18935
  if (!content.trim())
18823
18936
  return [];
18824
18937
  return [{
@@ -26171,16 +26284,16 @@ var require_dist = __commonJS({
26171
26284
  });
26172
26285
 
26173
26286
  // ../engine/dist/core/hermes-config.js
26174
- import { existsSync as existsSync35, readFileSync as readFileSync29 } from "fs";
26175
- import { join as join37 } from "path";
26287
+ import { existsSync as existsSync35, readFileSync as readFileSync30 } from "fs";
26288
+ import { join as join38 } from "path";
26176
26289
  function hermesConfigPath() {
26177
- return join37(hermesHomeDir(), "config.yaml");
26290
+ return join38(hermesHomeDir(), "config.yaml");
26178
26291
  }
26179
26292
  function readHermesMcpServers(path = hermesConfigPath()) {
26180
26293
  if (!existsSync35(path))
26181
26294
  return null;
26182
26295
  try {
26183
- const cfg = (0, import_yaml.parse)(readFileSync29(path, "utf-8"));
26296
+ const cfg = (0, import_yaml.parse)(readFileSync30(path, "utf-8"));
26184
26297
  return cfg?.mcp_servers && typeof cfg.mcp_servers === "object" ? cfg.mcp_servers : null;
26185
26298
  } catch {
26186
26299
  return null;
@@ -26230,14 +26343,14 @@ var init_hermes_config = __esm({
26230
26343
  });
26231
26344
 
26232
26345
  // ../engine/dist/parsers/mcps-source.js
26233
- import { existsSync as existsSync36, readFileSync as readFileSync30, statSync as statSync32 } from "fs";
26346
+ import { existsSync as existsSync36, readFileSync as readFileSync31, statSync as statSync32 } from "fs";
26234
26347
  import { homedir as homedir14 } from "os";
26235
- import { join as join38 } from "path";
26348
+ import { join as join39 } from "path";
26236
26349
  function readJson(path) {
26237
26350
  if (!existsSync36(path))
26238
26351
  return null;
26239
26352
  try {
26240
- const raw = readFileSync30(path, "utf-8");
26353
+ const raw = readFileSync31(path, "utf-8");
26241
26354
  const stripped = path.endsWith(".jsonc") ? raw.replace(/\/\*[\s\S]*?\*\//g, "").replace(/(^|[^:])\/\/.*$/gm, "$1").replace(/,(\s*[}\]])/g, "$1") : raw;
26242
26355
  return JSON.parse(stripped);
26243
26356
  } catch {
@@ -26299,23 +26412,23 @@ var init_mcps_source = __esm({
26299
26412
  if (!isSourceEnabled("common", "mcps"))
26300
26413
  return;
26301
26414
  const home = homedir14();
26302
- yield* this.fromObject(readJson(join38(home, ".mcp.json"))?.mcpServers, {
26415
+ yield* this.fromObject(readJson(join39(home, ".mcp.json"))?.mcpServers, {
26303
26416
  tool: "claude",
26304
- filePath: join38(home, ".mcp.json"),
26417
+ filePath: join39(home, ".mcp.json"),
26305
26418
  scope: "global"
26306
26419
  });
26307
- yield* this.fromObject(readJson(join38(home, ".claude.json"))?.mcpServers, {
26420
+ yield* this.fromObject(readJson(join39(home, ".claude.json"))?.mcpServers, {
26308
26421
  tool: "claude",
26309
- filePath: join38(home, ".claude.json"),
26422
+ filePath: join39(home, ".claude.json"),
26310
26423
  scope: "user"
26311
26424
  });
26312
26425
  for (const path of [
26313
- join38(home, ".config", "opencode", "opencode.json"),
26314
- join38(home, ".config", "opencode", "opencode.jsonc"),
26315
- join38(home, ".config", "opencode", "config.json"),
26316
- join38(home, ".opencode", "opencode.json"),
26317
- join38(home, ".opencode", "opencode.jsonc"),
26318
- join38(home, ".opencode", "config.json")
26426
+ join39(home, ".config", "opencode", "opencode.json"),
26427
+ join39(home, ".config", "opencode", "opencode.jsonc"),
26428
+ join39(home, ".config", "opencode", "config.json"),
26429
+ join39(home, ".opencode", "opencode.json"),
26430
+ join39(home, ".opencode", "opencode.jsonc"),
26431
+ join39(home, ".opencode", "config.json")
26319
26432
  ]) {
26320
26433
  yield* this.fromObject(readJson(path)?.mcp, {
26321
26434
  tool: "opencode",
@@ -26330,7 +26443,7 @@ var init_mcps_source = __esm({
26330
26443
  filePath: geminiSettings,
26331
26444
  scope: "user"
26332
26445
  });
26333
- const cursorMcp = join38(cursorHomeDir(), "mcp.json");
26446
+ const cursorMcp = join39(cursorHomeDir(), "mcp.json");
26334
26447
  yield* this.fromObject(readJson(cursorMcp)?.mcpServers, {
26335
26448
  tool: "cursor",
26336
26449
  filePath: cursorMcp,
@@ -26348,7 +26461,7 @@ var init_mcps_source = __esm({
26348
26461
  filePath: piMcp,
26349
26462
  scope: "user"
26350
26463
  });
26351
- const agyMcp = join38(home, ".gemini", "config", "mcp_config.json");
26464
+ const agyMcp = join39(home, ".gemini", "config", "mcp_config.json");
26352
26465
  yield* this.fromObject(readJson(agyMcp)?.mcpServers, {
26353
26466
  tool: "agy",
26354
26467
  filePath: agyMcp,
@@ -26356,7 +26469,7 @@ var init_mcps_source = __esm({
26356
26469
  });
26357
26470
  yield* this.fromCodexToml(codexBackend.configToml());
26358
26471
  for (const { dir } of codexBackend.installedPluginDirs()) {
26359
- const mcpPath = join38(dir, ".mcp.json");
26472
+ const mcpPath = join39(dir, ".mcp.json");
26360
26473
  yield* this.fromObject(readJson(mcpPath)?.mcpServers, {
26361
26474
  tool: "codex",
26362
26475
  filePath: mcpPath,
@@ -26414,7 +26527,7 @@ var init_mcps_source = __esm({
26414
26527
  return;
26415
26528
  let content;
26416
26529
  try {
26417
- content = readFileSync30(path, "utf-8");
26530
+ content = readFileSync31(path, "utf-8");
26418
26531
  } catch {
26419
26532
  return;
26420
26533
  }
@@ -26583,8 +26696,8 @@ var init_toolkit_format = __esm({
26583
26696
  });
26584
26697
 
26585
26698
  // ../engine/dist/parsers/slash-commands-source.js
26586
- import { existsSync as existsSync37, readdirSync as readdirSync27, readFileSync as readFileSync31, statSync as statSync33 } from "fs";
26587
- import { join as join39, basename as basename20 } from "path";
26699
+ import { existsSync as existsSync37, readdirSync as readdirSync27, readFileSync as readFileSync32, statSync as statSync33 } from "fs";
26700
+ import { join as join40, basename as basename20 } from "path";
26588
26701
  function rebuildBody2(content) {
26589
26702
  const { text, redacted } = redactInlineSecrets(content);
26590
26703
  const out = {};
@@ -26643,7 +26756,7 @@ var init_slash_commands_source = __esm({
26643
26756
  if (!entry.isDirectory() || entry.name.startsWith("."))
26644
26757
  continue;
26645
26758
  const projectPath = resolveProjectDirName(entry.name);
26646
- const cmdDir = join39(projectPath, ".claude", "commands");
26759
+ const cmdDir = join40(projectPath, ".claude", "commands");
26647
26760
  if (existsSync37(cmdDir))
26648
26761
  roots.push({ path: cmdDir, tool: "claude", scope: "project", projectPath, format: "md" });
26649
26762
  }
@@ -26652,7 +26765,7 @@ var init_slash_commands_source = __esm({
26652
26765
  }
26653
26766
  }
26654
26767
  if (isSourceEnabled("agy", "commands")) {
26655
- roots.push({ path: join39(agyBackend.homeDir(), "commands"), tool: "agy", scope: "user", projectPath: "", format: "toml" });
26768
+ roots.push({ path: join40(agyBackend.homeDir(), "commands"), tool: "agy", scope: "user", projectPath: "", format: "toml" });
26656
26769
  roots.push({ path: agyBackend.sharedCommandsDir(), tool: "agy", scope: "user", projectPath: "", format: "toml" });
26657
26770
  }
26658
26771
  if (isSourceEnabled("opencode", "commands")) {
@@ -26662,7 +26775,7 @@ var init_slash_commands_source = __esm({
26662
26775
  roots.push({ path: codexBackend.promptsDir(), tool: "codex", scope: "user", projectPath: "", format: "md" });
26663
26776
  }
26664
26777
  if (isSourceEnabled("cursor", "commands")) {
26665
- roots.push({ path: join39(cursorHomeDir(), "commands"), tool: "cursor", scope: "user", projectPath: "", format: "md" });
26778
+ roots.push({ path: join40(cursorHomeDir(), "commands"), tool: "cursor", scope: "user", projectPath: "", format: "md" });
26666
26779
  }
26667
26780
  if (isSourceEnabled("pi", "commands")) {
26668
26781
  roots.push({ path: piBackend.promptsDir(), tool: "pi", scope: "user", projectPath: "", format: "md" });
@@ -26679,10 +26792,10 @@ var init_slash_commands_source = __esm({
26679
26792
  continue;
26680
26793
  }
26681
26794
  for (const file of files) {
26682
- const filePath = join39(root.path, file);
26795
+ const filePath = join40(root.path, file);
26683
26796
  try {
26684
26797
  const stat3 = statSync33(filePath);
26685
- const content = readFileSync31(filePath, "utf-8");
26798
+ const content = readFileSync32(filePath, "utf-8");
26686
26799
  const parsed = parseCommand(content, basename20(file, ext), root.format);
26687
26800
  yield {
26688
26801
  id: `${root.tool}_cmd_${root.scope}_${parsed.name}`,
@@ -26711,7 +26824,7 @@ var init_slash_commands_source = __esm({
26711
26824
  async parse(item) {
26712
26825
  if (!existsSync37(item.filePath))
26713
26826
  return [];
26714
- const content = readFileSync31(item.filePath, "utf-8");
26827
+ const content = readFileSync32(item.filePath, "utf-8");
26715
26828
  if (!content.trim())
26716
26829
  return [];
26717
26830
  return [{
@@ -26734,8 +26847,8 @@ var init_slash_commands_source = __esm({
26734
26847
  });
26735
26848
 
26736
26849
  // ../engine/dist/parsers/subagents-source.js
26737
- import { existsSync as existsSync38, readdirSync as readdirSync28, readFileSync as readFileSync32, statSync as statSync34 } from "fs";
26738
- import { join as join40, basename as basename21 } from "path";
26850
+ import { existsSync as existsSync38, readdirSync as readdirSync28, readFileSync as readFileSync33, statSync as statSync34 } from "fs";
26851
+ import { join as join41, basename as basename21 } from "path";
26739
26852
  function rebuildBody3(content) {
26740
26853
  const { text, redacted } = redactInlineSecrets(content);
26741
26854
  const out = {};
@@ -26795,7 +26908,7 @@ var init_subagents_source = __esm({
26795
26908
  if (!entry.isDirectory() || entry.name.startsWith("."))
26796
26909
  continue;
26797
26910
  const projectPath = resolveProjectDirName(entry.name);
26798
- const agentDir = join40(projectPath, ".claude", "agents");
26911
+ const agentDir = join41(projectPath, ".claude", "agents");
26799
26912
  if (existsSync38(agentDir))
26800
26913
  roots.push({ path: agentDir, tool: "claude", scope: "project", projectPath, format: "md" });
26801
26914
  }
@@ -26804,7 +26917,7 @@ var init_subagents_source = __esm({
26804
26917
  }
26805
26918
  }
26806
26919
  if (isSourceEnabled("agy", "agents")) {
26807
- roots.push({ path: join40(agyBackend.homeDir(), "agents"), tool: "agy", scope: "user", projectPath: "", format: "md" });
26920
+ roots.push({ path: join41(agyBackend.homeDir(), "agents"), tool: "agy", scope: "user", projectPath: "", format: "md" });
26808
26921
  roots.push({ path: agyBackend.sharedAgentsDir(), tool: "agy", scope: "user", projectPath: "", format: "md" });
26809
26922
  }
26810
26923
  if (isSourceEnabled("opencode", "agents")) {
@@ -26814,7 +26927,7 @@ var init_subagents_source = __esm({
26814
26927
  roots.push({ path: codexBackend.agentsDir(), tool: "codex", scope: "user", projectPath: "", format: "toml" });
26815
26928
  }
26816
26929
  if (isSourceEnabled("cursor", "agents")) {
26817
- roots.push({ path: join40(cursorHomeDir(), "agents"), tool: "cursor", scope: "user", projectPath: "", format: "md" });
26930
+ roots.push({ path: join41(cursorHomeDir(), "agents"), tool: "cursor", scope: "user", projectPath: "", format: "md" });
26818
26931
  }
26819
26932
  return roots;
26820
26933
  }
@@ -26828,10 +26941,10 @@ var init_subagents_source = __esm({
26828
26941
  continue;
26829
26942
  }
26830
26943
  for (const file of files) {
26831
- const filePath = join40(root.path, file);
26944
+ const filePath = join41(root.path, file);
26832
26945
  try {
26833
26946
  const stat3 = statSync34(filePath);
26834
- const content = readFileSync32(filePath, "utf-8");
26947
+ const content = readFileSync33(filePath, "utf-8");
26835
26948
  const parsed = parseAgent(content, basename21(file, ext), root.format);
26836
26949
  yield {
26837
26950
  id: `${root.tool}_agent_${root.scope}_${parsed.name}`,
@@ -26861,7 +26974,7 @@ var init_subagents_source = __esm({
26861
26974
  async parse(item) {
26862
26975
  if (!existsSync38(item.filePath))
26863
26976
  return [];
26864
- const content = readFileSync32(item.filePath, "utf-8");
26977
+ const content = readFileSync33(item.filePath, "utf-8");
26865
26978
  if (!content.trim())
26866
26979
  return [];
26867
26980
  return [{
@@ -26884,13 +26997,13 @@ var init_subagents_source = __esm({
26884
26997
  });
26885
26998
 
26886
26999
  // ../engine/dist/parsers/hooks-source.js
26887
- import { existsSync as existsSync39, readFileSync as readFileSync33, readdirSync as readdirSync29, statSync as statSync35 } from "fs";
26888
- import { join as join41 } from "path";
27000
+ import { existsSync as existsSync39, readFileSync as readFileSync34, readdirSync as readdirSync29, statSync as statSync35 } from "fs";
27001
+ import { join as join42 } from "path";
26889
27002
  function readJson2(path) {
26890
27003
  if (!existsSync39(path))
26891
27004
  return null;
26892
27005
  try {
26893
- return JSON.parse(readFileSync33(path, "utf-8"));
27006
+ return JSON.parse(readFileSync34(path, "utf-8"));
26894
27007
  } catch {
26895
27008
  return null;
26896
27009
  }
@@ -26915,7 +27028,7 @@ var init_hooks_source = __esm({
26915
27028
  if (!entry.isDirectory() || entry.name.startsWith("."))
26916
27029
  continue;
26917
27030
  const projectPath = resolveProjectDirName(entry.name);
26918
- const settingsPath2 = join41(projectPath, ".claude", "settings.json");
27031
+ const settingsPath2 = join42(projectPath, ".claude", "settings.json");
26919
27032
  if (existsSync39(settingsPath2)) {
26920
27033
  yield* this.fromSettings(settingsPath2, "project", projectPath);
26921
27034
  }
@@ -27007,14 +27120,14 @@ var init_hooks_source = __esm({
27007
27120
  });
27008
27121
 
27009
27122
  // ../engine/dist/parsers/plugins-source.js
27010
- import { existsSync as existsSync40, readFileSync as readFileSync34, readdirSync as readdirSync30, statSync as statSync36 } from "fs";
27123
+ import { existsSync as existsSync40, readFileSync as readFileSync35, readdirSync as readdirSync30, statSync as statSync36 } from "fs";
27011
27124
  import { homedir as homedir15 } from "os";
27012
- import { join as join42 } from "path";
27125
+ import { join as join43 } from "path";
27013
27126
  function readJson3(path) {
27014
27127
  if (!existsSync40(path))
27015
27128
  return null;
27016
27129
  try {
27017
- return JSON.parse(readFileSync34(path, "utf-8"));
27130
+ return JSON.parse(readFileSync35(path, "utf-8"));
27018
27131
  } catch {
27019
27132
  return null;
27020
27133
  }
@@ -27074,7 +27187,7 @@ var init_plugins_source = __esm({
27074
27187
  entries = [];
27075
27188
  }
27076
27189
  for (const name of entries) {
27077
- const dir = join42(gemRoot, name);
27190
+ const dir = join43(gemRoot, name);
27078
27191
  let st;
27079
27192
  try {
27080
27193
  st = statSync36(dir);
@@ -27083,7 +27196,7 @@ var init_plugins_source = __esm({
27083
27196
  }
27084
27197
  if (!st.isDirectory())
27085
27198
  continue;
27086
- const manifestPath = join42(dir, "gemini-extension.json");
27199
+ const manifestPath = join43(dir, "gemini-extension.json");
27087
27200
  const manifest = readJson3(manifestPath);
27088
27201
  if (!manifest || typeof manifest !== "object")
27089
27202
  continue;
@@ -27123,11 +27236,11 @@ var init_plugins_source = __esm({
27123
27236
  }
27124
27237
  if (!st.isDirectory())
27125
27238
  continue;
27126
- const appJson = readJson3(join42(pluginDir, ".codex-plugin", ".app.json"));
27127
- const pluginJson = readJson3(join42(pluginDir, ".codex-plugin", "plugin.json"));
27239
+ const appJson = readJson3(join43(pluginDir, ".codex-plugin", ".app.json"));
27240
+ const pluginJson = readJson3(join43(pluginDir, ".codex-plugin", "plugin.json"));
27128
27241
  const manifest = pluginJson || appJson || {};
27129
27242
  let mcpServers = [];
27130
- const mcpJson = readJson3(join42(pluginDir, ".mcp.json"));
27243
+ const mcpJson = readJson3(join43(pluginDir, ".mcp.json"));
27131
27244
  if (mcpJson?.mcpServers)
27132
27245
  mcpServers = Object.keys(mcpJson.mcpServers);
27133
27246
  yield {
@@ -27135,7 +27248,7 @@ var init_plugins_source = __esm({
27135
27248
  sourceType: "plugin",
27136
27249
  title: manifest.name || name,
27137
27250
  projectPath: "",
27138
- filePath: join42(pluginDir, ".codex-plugin"),
27251
+ filePath: join43(pluginDir, ".codex-plugin"),
27139
27252
  mtime: st.mtimeMs,
27140
27253
  contentPreview: (manifest.description || "").slice(0, 300),
27141
27254
  extra: {
@@ -27307,8 +27420,8 @@ __export(sync_ledger_exports, {
27307
27420
  syncMode: () => syncMode,
27308
27421
  unackedCursorAttemptCount: () => unackedCursorAttemptCount
27309
27422
  });
27310
- import { readFileSync as readFileSync35, writeFileSync as writeFileSync7, renameSync as renameSync4, mkdirSync as mkdirSync8, statSync as statSync37 } from "node:fs";
27311
- import { join as join43, dirname as dirname16 } from "node:path";
27423
+ import { readFileSync as readFileSync36, writeFileSync as writeFileSync8, renameSync as renameSync4, mkdirSync as mkdirSync8, statSync as statSync37 } from "node:fs";
27424
+ import { join as join44, dirname as dirname16 } from "node:path";
27312
27425
  function toRow(entry) {
27313
27426
  if (entry === void 0) return void 0;
27314
27427
  return typeof entry === "number" ? { m: entry, v: 0 } : entry;
@@ -27326,7 +27439,7 @@ function stampOf(path) {
27326
27439
  }
27327
27440
  function readDisk(path) {
27328
27441
  try {
27329
- const parsed = JSON.parse(readFileSync35(path, "utf-8"));
27442
+ const parsed = JSON.parse(readFileSync36(path, "utf-8"));
27330
27443
  return parsed && typeof parsed === "object" ? parsed : {};
27331
27444
  } catch {
27332
27445
  return {};
@@ -27390,7 +27503,7 @@ function persistNow() {
27390
27503
  mkdirSync8(dirname16(path), { recursive: true });
27391
27504
  load();
27392
27505
  const tmp = `${path}.tmp-${process.pid}`;
27393
- writeFileSync7(tmp, JSON.stringify(cache3 ?? {}));
27506
+ writeFileSync8(tmp, JSON.stringify(cache3 ?? {}));
27394
27507
  renameSync4(tmp, path);
27395
27508
  base = snapshot(cache3 ?? {});
27396
27509
  diskStamp = stampOf(path);
@@ -27427,10 +27540,10 @@ function pruneLedgerTargets(configuredServers) {
27427
27540
  try {
27428
27541
  let prior = {};
27429
27542
  try {
27430
- prior = JSON.parse(readFileSync35(side, "utf-8"));
27543
+ prior = JSON.parse(readFileSync36(side, "utf-8"));
27431
27544
  } catch {
27432
27545
  }
27433
- writeFileSync7(side, JSON.stringify({ ...prior, ...orphans }));
27546
+ writeFileSync8(side, JSON.stringify({ ...prior, ...orphans }));
27434
27547
  } catch {
27435
27548
  for (const n of names) data[n] = orphans[n];
27436
27549
  return 0;
@@ -27451,7 +27564,7 @@ function flushLedger() {
27451
27564
  function loadItemVersionsAll() {
27452
27565
  if (itemVersionsCache) return itemVersionsCache;
27453
27566
  try {
27454
- const parsed = JSON.parse(readFileSync35(itemVersionsPath(), "utf-8"));
27567
+ const parsed = JSON.parse(readFileSync36(itemVersionsPath(), "utf-8"));
27455
27568
  itemVersionsCache = parsed && typeof parsed === "object" ? parsed : {};
27456
27569
  } catch {
27457
27570
  itemVersionsCache = {};
@@ -27467,12 +27580,12 @@ function saveItemVersions(server, versions) {
27467
27580
  const path = itemVersionsPath();
27468
27581
  mkdirSync8(dirname16(path), { recursive: true });
27469
27582
  const tmp = `${path}.tmp`;
27470
- writeFileSync7(tmp, JSON.stringify(all));
27583
+ writeFileSync8(tmp, JSON.stringify(all));
27471
27584
  renameSync4(tmp, path);
27472
27585
  }
27473
27586
  function loadInventoryHashes(server) {
27474
27587
  try {
27475
- const parsed = JSON.parse(readFileSync35(inventoryPath(), "utf-8"));
27588
+ const parsed = JSON.parse(readFileSync36(inventoryPath(), "utf-8"));
27476
27589
  return { ...(parsed && typeof parsed === "object" ? parsed[server] : null) || {} };
27477
27590
  } catch {
27478
27591
  return {};
@@ -27481,7 +27594,7 @@ function loadInventoryHashes(server) {
27481
27594
  function saveInventoryHashes(server, hashes) {
27482
27595
  let all = {};
27483
27596
  try {
27484
- all = JSON.parse(readFileSync35(inventoryPath(), "utf-8"));
27597
+ all = JSON.parse(readFileSync36(inventoryPath(), "utf-8"));
27485
27598
  } catch {
27486
27599
  }
27487
27600
  if (!all || typeof all !== "object") all = {};
@@ -27489,7 +27602,7 @@ function saveInventoryHashes(server, hashes) {
27489
27602
  const path = inventoryPath();
27490
27603
  mkdirSync8(dirname16(path), { recursive: true });
27491
27604
  const tmp = `${path}.tmp`;
27492
- writeFileSync7(tmp, JSON.stringify(all));
27605
+ writeFileSync8(tmp, JSON.stringify(all));
27493
27606
  renameSync4(tmp, path);
27494
27607
  }
27495
27608
  function getSyncedMtimes(server) {
@@ -27575,7 +27688,7 @@ function markFieldCoverage(server, field, rows) {
27575
27688
  function loadReconcile() {
27576
27689
  if (reconcileCache) return reconcileCache;
27577
27690
  try {
27578
- const parsed = JSON.parse(readFileSync35(reconcilePath(), "utf-8"));
27691
+ const parsed = JSON.parse(readFileSync36(reconcilePath(), "utf-8"));
27579
27692
  reconcileCache = parsed && typeof parsed === "object" ? parsed : {};
27580
27693
  } catch {
27581
27694
  reconcileCache = {};
@@ -27586,7 +27699,7 @@ function persistReconcile(data) {
27586
27699
  const path = reconcilePath();
27587
27700
  mkdirSync8(dirname16(path), { recursive: true });
27588
27701
  const tmp = `${path}.tmp`;
27589
- writeFileSync7(tmp, JSON.stringify(data));
27702
+ writeFileSync8(tmp, JSON.stringify(data));
27590
27703
  renameSync4(tmp, path);
27591
27704
  }
27592
27705
  function stateFor(server) {
@@ -27661,7 +27774,7 @@ var init_sync_ledger = __esm({
27661
27774
  "use strict";
27662
27775
  init_paths();
27663
27776
  init_extractor_version();
27664
- ledgerPath = () => join43(getDataDir(), "sync-ledger.json");
27777
+ ledgerPath = () => join44(getDataDir(), "sync-ledger.json");
27665
27778
  cache3 = null;
27666
27779
  base = /* @__PURE__ */ new Map();
27667
27780
  diskStamp = null;
@@ -27669,11 +27782,11 @@ var init_sync_ledger = __esm({
27669
27782
  LEDGER_FLUSH_MS = 2e3;
27670
27783
  pendingWrite = false;
27671
27784
  flushTimer = null;
27672
- itemVersionsPath = () => join43(getDataDir(), "item-versions.json");
27785
+ itemVersionsPath = () => join44(getDataDir(), "item-versions.json");
27673
27786
  itemVersionsCache = null;
27674
- inventoryPath = () => join43(getDataDir(), "toolkit-inventory.json");
27787
+ inventoryPath = () => join44(getDataDir(), "toolkit-inventory.json");
27675
27788
  unackedCursorAttempts = 0;
27676
- reconcilePath = () => join43(getDataDir(), "sync-field-reconcile.json");
27789
+ reconcilePath = () => join44(getDataDir(), "sync-field-reconcile.json");
27677
27790
  reconcileCache = null;
27678
27791
  SETTLE_QUIET_MS = 2 * 60 * 60 * 1e3;
27679
27792
  }
@@ -27705,8 +27818,8 @@ var init_sync_fields = __esm({
27705
27818
  });
27706
27819
 
27707
27820
  // ../engine/dist/core/index-lock.js
27708
- import { existsSync as existsSync41, mkdirSync as mkdirSync9, openSync as openSync9, writeFileSync as writeFileSync8, readFileSync as readFileSync36, rmSync as rmSync4, statSync as statSync38, closeSync as closeSync9 } from "fs";
27709
- import { dirname as dirname17, join as join44 } from "path";
27821
+ import { existsSync as existsSync41, mkdirSync as mkdirSync9, openSync as openSync9, writeFileSync as writeFileSync9, readFileSync as readFileSync37, rmSync as rmSync4, statSync as statSync38, closeSync as closeSync9 } from "fs";
27822
+ import { dirname as dirname17, join as join45 } from "path";
27710
27823
  function acquireIndexLock(opts) {
27711
27824
  const lockPath = lockFilePath(opts.file);
27712
27825
  mkdirSync9(dirname17(lockPath), { recursive: true });
@@ -27725,7 +27838,7 @@ function acquireIndexLock(opts) {
27725
27838
  }
27726
27839
  const holder = { pid: process.pid, kind: opts.kind, startedAt: Date.now() };
27727
27840
  try {
27728
- writeFileSync8(fd, JSON.stringify(holder));
27841
+ writeFileSync9(fd, JSON.stringify(holder));
27729
27842
  } finally {
27730
27843
  closeSync9(fd);
27731
27844
  }
@@ -27737,7 +27850,7 @@ function acquireIndexLock(opts) {
27737
27850
  return;
27738
27851
  released = true;
27739
27852
  try {
27740
- const current = JSON.parse(readFileSync36(lockPath, "utf-8"));
27853
+ const current = JSON.parse(readFileSync37(lockPath, "utf-8"));
27741
27854
  if (current.pid !== holder.pid || current.startedAt !== holder.startedAt)
27742
27855
  return;
27743
27856
  } catch {
@@ -27751,7 +27864,7 @@ function acquireIndexLock(opts) {
27751
27864
  };
27752
27865
  }
27753
27866
  function lockFilePath(file = ".compact.lock") {
27754
- return join44(getIndexDir(), file);
27867
+ return join45(getIndexDir(), file);
27755
27868
  }
27756
27869
  function stealStaleLock(lockPath, staleAfterMs) {
27757
27870
  try {
@@ -27759,7 +27872,7 @@ function stealStaleLock(lockPath, staleAfterMs) {
27759
27872
  const age = Date.now() - s.mtimeMs;
27760
27873
  let payload;
27761
27874
  try {
27762
- payload = JSON.parse(readFileSync36(lockPath, "utf-8"));
27875
+ payload = JSON.parse(readFileSync37(lockPath, "utf-8"));
27763
27876
  } catch {
27764
27877
  rmSync4(lockPath, { force: true });
27765
27878
  return true;
@@ -27797,7 +27910,7 @@ var init_index_lock = __esm({
27797
27910
  });
27798
27911
 
27799
27912
  // src/http.ts
27800
- import { readFileSync as readFileSync37 } from "node:fs";
27913
+ import { readFileSync as readFileSync38 } from "node:fs";
27801
27914
  function clientHeaders() {
27802
27915
  return {
27803
27916
  "x-chat-recall-cli": CLI_VERSION,
@@ -27815,7 +27928,7 @@ var init_http = __esm({
27815
27928
  "use strict";
27816
27929
  CLI_VERSION = "0.0.0";
27817
27930
  try {
27818
- CLI_VERSION = JSON.parse(readFileSync37(new URL("../package.json", import.meta.url), "utf-8")).version || CLI_VERSION;
27931
+ CLI_VERSION = JSON.parse(readFileSync38(new URL("../package.json", import.meta.url), "utf-8")).version || CLI_VERSION;
27819
27932
  } catch {
27820
27933
  try {
27821
27934
  if (typeof __CLI_VERSION__ === "string") CLI_VERSION = __CLI_VERSION__;
@@ -27944,7 +28057,7 @@ var WORKER_HEAP_MB, ScanPool, shared;
27944
28057
  var init_scan_pool = __esm({
27945
28058
  "src/scan-pool.ts"() {
27946
28059
  "use strict";
27947
- WORKER_HEAP_MB = Number(process.env.CHAT_RECALL_SCAN_WORKER_HEAP_MB) || 768;
28060
+ WORKER_HEAP_MB = Number(process.env.CHAT_RECALL_SCAN_WORKER_HEAP_MB) || 256;
27948
28061
  ScanPool = class {
27949
28062
  constructor(size = poolSize()) {
27950
28063
  this.size = size;
@@ -28325,11 +28438,11 @@ var init_telemetry = __esm({
28325
28438
  // src/raw-archive-parts.ts
28326
28439
  import { createReadStream as createReadStream4, createWriteStream, openSync as openSync10, readSync as readSync9, closeSync as closeSync10, rmSync as rmSync5, statSync as statSync39 } from "node:fs";
28327
28440
  import { tmpdir as tmpdir2 } from "node:os";
28328
- import { join as join45 } from "node:path";
28441
+ import { join as join46 } from "node:path";
28329
28442
  import { randomBytes } from "node:crypto";
28330
28443
  import { createGzip as createGzip2 } from "node:zlib";
28331
28444
  import { once } from "node:events";
28332
- import { readFileSync as readFileSync38 } from "node:fs";
28445
+ import { readFileSync as readFileSync39 } from "node:fs";
28333
28446
  async function* fileLines(path) {
28334
28447
  let rest = "";
28335
28448
  const decoder = new TextDecoder("utf-8");
@@ -28355,7 +28468,7 @@ function* textLines(text) {
28355
28468
  }
28356
28469
  }
28357
28470
  async function writeArchiveFile(source, meta, redact, dir = tmpdir2()) {
28358
- const path = join45(dir, `cr-archive-${randomBytes(8).toString("hex")}.json.gz`);
28471
+ const path = join46(dir, `cr-archive-${randomBytes(8).toString("hex")}.json.gz`);
28359
28472
  const gzip = createGzip2({ level: 6 });
28360
28473
  const out = createWriteStream(path, { mode: 384 });
28361
28474
  const done = once(out, "finish");
@@ -28369,7 +28482,7 @@ async function writeArchiveFile(source, meta, redact, dir = tmpdir2()) {
28369
28482
  await write(`{"v":1,"tool":${JSON.stringify(meta.tool)},"mtime":${Math.floor(meta.mtime)},"files":[`);
28370
28483
  for (const [i, f] of source.files.entries()) {
28371
28484
  await write(`${i ? "," : ""}{"name":${JSON.stringify(f.name)},"text":"`);
28372
- const whole = () => source.kind === "memory" ? f.text : readFileSync38(f.path, "utf-8");
28485
+ const whole = () => source.kind === "memory" ? f.text : readFileSync39(f.path, "utf-8");
28373
28486
  if (!f.name.endsWith(".jsonl")) {
28374
28487
  await write(escapeJson(redact(whole())));
28375
28488
  } else {
@@ -28609,7 +28722,7 @@ __export(client_events_exports, {
28609
28722
  isTelemetryEnabled: () => isTelemetryEnabled,
28610
28723
  reportClientEvent: () => reportClientEvent
28611
28724
  });
28612
- import { readFileSync as readFileSync39 } from "node:fs";
28725
+ import { readFileSync as readFileSync40 } from "node:fs";
28613
28726
  function scrub(msg) {
28614
28727
  if (!msg) return "";
28615
28728
  const noHome = msg.replace(/\/(?:home|Users)\/[^/\s]+/g, "~");
@@ -28662,7 +28775,7 @@ var init_client_events = __esm({
28662
28775
  init_secret_redactor();
28663
28776
  CLI_VERSION2 = "0.0.0";
28664
28777
  try {
28665
- CLI_VERSION2 = JSON.parse(readFileSync39(new URL("../package.json", import.meta.url), "utf-8")).version || CLI_VERSION2;
28778
+ CLI_VERSION2 = JSON.parse(readFileSync40(new URL("../package.json", import.meta.url), "utf-8")).version || CLI_VERSION2;
28666
28779
  } catch {
28667
28780
  }
28668
28781
  }
@@ -28692,10 +28805,10 @@ __export(auto_update_exports, {
28692
28805
  tarballUrl: () => tarballUrl
28693
28806
  });
28694
28807
  import { execSync as execSync2, execFileSync as execFileSync3 } from "node:child_process";
28695
- import { readFileSync as readFileSync40, existsSync as existsSync43 } from "node:fs";
28808
+ import { readFileSync as readFileSync41, existsSync as existsSync43 } from "node:fs";
28696
28809
  import { fileURLToPath as fileURLToPath2 } from "node:url";
28697
- import { writeFileSync as writeFileSync9, mkdtempSync as mkdtempSync3, rmSync as rmSync6, readdirSync as readdirSync31, statSync as statSync40, mkdirSync as mkdirSync10 } from "node:fs";
28698
- import { join as join46, dirname as dirname18, sep as sep2, posix as pathPosix, win32 as pathWin32 } from "node:path";
28810
+ import { writeFileSync as writeFileSync10, mkdtempSync as mkdtempSync3, rmSync as rmSync6, readdirSync as readdirSync31, statSync as statSync40, mkdirSync as mkdirSync10 } from "node:fs";
28811
+ import { join as join47, dirname as dirname18, sep as sep2, posix as pathPosix, win32 as pathWin32 } from "node:path";
28699
28812
  import { tmpdir as tmpdir3, homedir as homedir16 } from "node:os";
28700
28813
  import { createHash as createHash9 } from "node:crypto";
28701
28814
  function compareVersions(a, b) {
@@ -28720,7 +28833,7 @@ function newerOf(a, b) {
28720
28833
  function installedVersion() {
28721
28834
  try {
28722
28835
  const here = dirname18(fileURLToPath2(import.meta.url));
28723
- const raw = readFileSync40(join46(here, "..", "package.json"), "utf-8");
28836
+ const raw = readFileSync41(join47(here, "..", "package.json"), "utf-8");
28724
28837
  return JSON.parse(raw).version || null;
28725
28838
  } catch {
28726
28839
  return null;
@@ -28745,7 +28858,7 @@ function sweepStaleStaging(root = tmpdir3(), now = Date.now()) {
28745
28858
  }
28746
28859
  for (const name of entries) {
28747
28860
  if (!MKDTEMP_SUFFIX.test(name)) continue;
28748
- const dir = join46(root, name);
28861
+ const dir = join47(root, name);
28749
28862
  try {
28750
28863
  const st = statSync40(dir);
28751
28864
  if (!st.isDirectory() || now - st.mtimeMs < COLD_MS) continue;
@@ -28774,15 +28887,15 @@ async function executeAutoUpdate(plan, deps) {
28774
28887
  }
28775
28888
  const got = createHash9("sha256").update(buf).digest("hex");
28776
28889
  if (got !== plan.sha256) return { updated: false, reason: `checksum mismatch (expected ${plan.sha256.slice(0, 12)}\u2026, got ${got.slice(0, 12)}\u2026) \u2014 NOT installing` };
28777
- const dir = mkdtempSync3(join46(tmpdir3(), "cr-update-"));
28890
+ const dir = mkdtempSync3(join47(tmpdir3(), "cr-update-"));
28778
28891
  const discardStaging = () => {
28779
28892
  try {
28780
28893
  rmSync6(dir, { recursive: true, force: true });
28781
28894
  } catch {
28782
28895
  }
28783
28896
  };
28784
- const tgz = join46(dir, "chat-recall.tgz");
28785
- writeFileSync9(tgz, buf);
28897
+ const tgz = join47(dir, "chat-recall.tgz");
28898
+ writeFileSync10(tgz, buf);
28786
28899
  if (deps.stopping?.()) {
28787
28900
  discardStaging();
28788
28901
  return { updated: false, reason: STOPPING_REASON };
@@ -28861,7 +28974,7 @@ function realInstall(tgz) {
28861
28974
  try {
28862
28975
  npmInstall(npm, ["install", "-g", tgz]);
28863
28976
  } catch {
28864
- npmInstall(npm, ["install", "-g", "--prefix", join46(homedir16(), ".local"), tgz]);
28977
+ npmInstall(npm, ["install", "-g", "--prefix", join47(homedir16(), ".local"), tgz]);
28865
28978
  }
28866
28979
  }
28867
28980
  function acquireUpdateLock() {
@@ -28878,12 +28991,12 @@ function realRestart(platform2) {
28878
28991
  if (c) execSync2(c.cmd, { stdio: "ignore", ...c.shell ? { shell: c.shell } : {} });
28879
28992
  }
28880
28993
  function updateStatePath() {
28881
- const dir = process.env.CHAT_RECALL_DATA_DIR || join46(homedir16(), ".chat-recall");
28882
- return join46(dir, "auto-update-state.json");
28994
+ const dir = process.env.CHAT_RECALL_DATA_DIR || join47(homedir16(), ".chat-recall");
28995
+ return join47(dir, "auto-update-state.json");
28883
28996
  }
28884
28997
  function readUpdateState() {
28885
28998
  try {
28886
- return JSON.parse(readFileSync40(updateStatePath(), "utf8"));
28999
+ return JSON.parse(readFileSync41(updateStatePath(), "utf8"));
28887
29000
  } catch {
28888
29001
  return {};
28889
29002
  }
@@ -28892,7 +29005,7 @@ function writeUpdateState(st) {
28892
29005
  try {
28893
29006
  const p = updateStatePath();
28894
29007
  mkdirSync10(dirname18(p), { recursive: true });
28895
- writeFileSync9(p, JSON.stringify(st), "utf8");
29008
+ writeFileSync10(p, JSON.stringify(st), "utf8");
28896
29009
  } catch {
28897
29010
  }
28898
29011
  }
@@ -28990,8 +29103,8 @@ var init_auto_update = __esm({
28990
29103
  });
28991
29104
 
28992
29105
  // src/sync-client.ts
28993
- import { join as join47, dirname as dirname19, basename as basename22 } from "node:path";
28994
- import { readFileSync as readFileSync41, writeFileSync as writeFileSync10, mkdirSync as mkdirSync11, mkdtempSync as mkdtempSync4, rmSync as rmSync7, chmodSync as chmodSync4, unlinkSync as unlinkSync2, readdirSync as readdirSync32, statSync as statSync41 } from "node:fs";
29106
+ import { join as join48, dirname as dirname19, basename as basename22 } from "node:path";
29107
+ import { readFileSync as readFileSync42, writeFileSync as writeFileSync11, mkdirSync as mkdirSync11, mkdtempSync as mkdtempSync4, rmSync as rmSync7, chmodSync as chmodSync4, unlinkSync as unlinkSync2, readdirSync as readdirSync32, statSync as statSync41 } from "node:fs";
28995
29108
  import { tmpdir as tmpdir4, hostname as hostname2 } from "node:os";
28996
29109
  import { createHash as createHash10 } from "node:crypto";
28997
29110
  import { fileURLToPath as fileURLToPath3 } from "node:url";
@@ -29032,7 +29145,7 @@ function loadAllCredentials() {
29032
29145
  const fromEnv = envCredentials();
29033
29146
  if (fromEnv) return [{ serverUrl: fromEnv.serverUrl, token: fromEnv.token }];
29034
29147
  try {
29035
- const parsed = JSON.parse(readFileSync41(credPath(), "utf-8"));
29148
+ const parsed = JSON.parse(readFileSync42(credPath(), "utf-8"));
29036
29149
  if (Array.isArray(parsed?.targets)) {
29037
29150
  return parsed.targets.filter((t) => t?.serverUrl).map((t) => {
29038
29151
  const secret = t.secret;
@@ -29096,11 +29209,11 @@ async function fetchTenantSecurityConfig(cred) {
29096
29209
  }
29097
29210
  }
29098
29211
  function syncConfigCachePath() {
29099
- return join47(getDataDir(), "sync-config-cache.json");
29212
+ return join48(getDataDir(), "sync-config-cache.json");
29100
29213
  }
29101
29214
  function readPersistedSyncConfigs() {
29102
29215
  try {
29103
- return JSON.parse(readFileSync41(syncConfigCachePath(), "utf-8"));
29216
+ return JSON.parse(readFileSync42(syncConfigCachePath(), "utf-8"));
29104
29217
  } catch {
29105
29218
  return {};
29106
29219
  }
@@ -29110,7 +29223,7 @@ function persistSyncConfig(base3, config) {
29110
29223
  const all = readPersistedSyncConfigs();
29111
29224
  all[base3] = { fetchedAt: Date.now(), config };
29112
29225
  mkdirSync11(dirname19(syncConfigCachePath()), { recursive: true });
29113
- writeFileSync10(syncConfigCachePath(), JSON.stringify(all, null, 2));
29226
+ writeFileSync11(syncConfigCachePath(), JSON.stringify(all, null, 2));
29114
29227
  } catch {
29115
29228
  }
29116
29229
  }
@@ -29309,11 +29422,11 @@ async function syncSessions(opts = {}) {
29309
29422
  return { ...agg, perTarget };
29310
29423
  }
29311
29424
  function walkStatePath() {
29312
- return join47(getDataDir(), "walk-state.json");
29425
+ return join48(getDataDir(), "walk-state.json");
29313
29426
  }
29314
29427
  function readWalkState() {
29315
29428
  try {
29316
- const raw = JSON.parse(readFileSync41(walkStatePath(), "utf-8"));
29429
+ const raw = JSON.parse(readFileSync42(walkStatePath(), "utf-8"));
29317
29430
  return raw && typeof raw === "object" ? raw : {};
29318
29431
  } catch {
29319
29432
  return {};
@@ -29324,7 +29437,7 @@ function noteWalkSuccess(serverUrl) {
29324
29437
  const state2 = readWalkState();
29325
29438
  state2[serverUrl.replace(/\/+$/, "")] = Date.now();
29326
29439
  mkdirSync11(getDataDir(), { recursive: true });
29327
- writeFileSync10(walkStatePath(), JSON.stringify(state2));
29440
+ writeFileSync11(walkStatePath(), JSON.stringify(state2));
29328
29441
  } catch {
29329
29442
  }
29330
29443
  }
@@ -29390,7 +29503,7 @@ function reapStaleScanDirs(dir = tmpdir4(), maxAgeMs = 6 * 36e5, now = Date.now(
29390
29503
  }
29391
29504
  for (const name of names) {
29392
29505
  if (!name.startsWith("cr-batchscan-")) continue;
29393
- const p = join47(dir, name);
29506
+ const p = join48(dir, name);
29394
29507
  try {
29395
29508
  if (now - statSync41(p).mtimeMs < maxAgeMs) continue;
29396
29509
  rmSync7(p, { recursive: true, force: true });
@@ -29407,7 +29520,7 @@ function batchScanExternal(items, opts = {}) {
29407
29520
  let scanned = 0, slices = 0, scanMs = 0;
29408
29521
  if (items.length === 0) return { findings, scanned, slices, scanMs };
29409
29522
  reapStaleScanDirs();
29410
- let scanDir = mkdtempSync4(join47(tmpdir4(), "cr-batchscan-"));
29523
+ let scanDir = mkdtempSync4(join48(tmpdir4(), "cr-batchscan-"));
29411
29524
  let safeToId = /* @__PURE__ */ new Map();
29412
29525
  let bytesInDir = 0;
29413
29526
  const flushSlice = () => {
@@ -29438,13 +29551,13 @@ function batchScanExternal(items, opts = {}) {
29438
29551
  if (raw === null) continue;
29439
29552
  const safe = item.id.replace(/[^A-Za-z0-9_-]/g, "");
29440
29553
  safeToId.set(safe, item.id);
29441
- writeFileSync10(join47(scanDir, `${safe}.txt`), raw);
29554
+ writeFileSync11(join48(scanDir, `${safe}.txt`), raw);
29442
29555
  bytesInDir += Buffer.byteLength(raw);
29443
29556
  } catch {
29444
29557
  }
29445
29558
  if (bytesInDir >= maxBytes) {
29446
29559
  flushSlice();
29447
- scanDir = mkdtempSync4(join47(tmpdir4(), "cr-batchscan-"));
29560
+ scanDir = mkdtempSync4(join48(tmpdir4(), "cr-batchscan-"));
29448
29561
  }
29449
29562
  }
29450
29563
  flushSlice();
@@ -29901,10 +30014,19 @@ async function syncToTargetInScope(cred, opts = {}) {
29901
30014
  reportWalkProgress({ done: 0, total: slice.length, startedAt: walkStartedAt, complete: false, first: firstWalk });
29902
30015
  walkProgressForUpload = { done: 0, total: slice.length, complete: false };
29903
30016
  let traceN = 0;
30017
+ const memBudget = startBudget();
30018
+ let sessionsBuilt = 0;
29904
30019
  let considered = 0;
29905
30020
  for (const ref of slice) {
29906
30021
  await new Promise((resolve3) => setImmediate(resolve3));
29907
30022
  considered++;
30023
+ const usedNow = usedMb();
30024
+ if (shouldPause(usedNow, memBudget, sessionsBuilt)) {
30025
+ releaseMemory();
30026
+ reclaimCgroup();
30027
+ console.error(`[sync] walk paused at the memory bound (used=${usedNow}MB, started at ${memBudget.baselineMb}MB) after ${sessionsBuilt} build(s) and ${considered - 1} of ${slice.length} session(s) \u2014 the next tick continues`);
30028
+ break;
30029
+ }
29908
30030
  const walkDone = considered >= slice.length;
29909
30031
  reportWalkProgress({ done: considered, total: slice.length, startedAt: walkStartedAt, complete: walkDone, first: firstWalk });
29910
30032
  walkProgressForUpload = { done: considered, total: slice.length, complete: walkDone };
@@ -29915,6 +30037,7 @@ async function syncToTargetInScope(cred, opts = {}) {
29915
30037
  skipped++;
29916
30038
  continue;
29917
30039
  }
30040
+ sessionsBuilt++;
29918
30041
  const layout = backendFor(ref)?.sourceLayout?.(ref.prefixedId) ?? "";
29919
30042
  if (layout) shippedLayout.set(ref.prefixedId, layout);
29920
30043
  else shippedLayout.delete(ref.prefixedId);
@@ -30036,6 +30159,7 @@ async function syncToTargetInScope(cred, opts = {}) {
30036
30159
  } catch {
30037
30160
  }
30038
30161
  walked++;
30162
+ releaseMemory();
30039
30163
  if (walked % 250 === 0) console.error(`[sync] ${walked}/${slice.length} sessions\u2026`);
30040
30164
  }
30041
30165
  const itemVersions = loadItemVersions(base3);
@@ -30459,8 +30583,8 @@ async function buildConversationSync(ref, mtime, opts = {}) {
30459
30583
  } else if (opts.scanSecrets) {
30460
30584
  let tmp = null;
30461
30585
  try {
30462
- tmp = join47(tmpdir4(), `cr-scan-${ref.prefixedId.replace(/[^A-Za-z0-9_-]/g, "")}-${mtime}.txt`);
30463
- writeFileSync10(tmp, rawText);
30586
+ tmp = join48(tmpdir4(), `cr-scan-${ref.prefixedId.replace(/[^A-Za-z0-9_-]/g, "")}-${mtime}.txt`);
30587
+ writeFileSync11(tmp, rawText);
30464
30588
  for (const f of scanFileForSecrets(tmp, { verifyOnly: opts.verifySecrets, tenantRules: opts.tenantRules })) {
30465
30589
  const verifiedAt = f.verified ? (/* @__PURE__ */ new Date()).toISOString() : null;
30466
30590
  findings.push({ session_id: ref.prefixedId, detector: f.detector, rule: f.rule, line: f.line, preview: f.preview, verified_at: verifiedAt });
@@ -30695,6 +30819,7 @@ var ownVersion, ERROR_CLASS, STANDING_FAILURE, walkProgressForUpload, lastServer
30695
30819
  var init_sync_client = __esm({
30696
30820
  "src/sync-client.ts"() {
30697
30821
  "use strict";
30822
+ init_memory_guard();
30698
30823
  init_claude_prompt_origin();
30699
30824
  init_credentials_env();
30700
30825
  init_stored_token();
@@ -30738,7 +30863,7 @@ var init_sync_client = __esm({
30738
30863
  ownVersion = "0.0.0";
30739
30864
  try {
30740
30865
  const dir = dirname19(fileURLToPath3(import.meta.url));
30741
- ownVersion = JSON.parse(readFileSync41(join47(dir, "../package.json"), "utf-8")).version || ownVersion;
30866
+ ownVersion = JSON.parse(readFileSync42(join48(dir, "../package.json"), "utf-8")).version || ownVersion;
30742
30867
  } catch {
30743
30868
  try {
30744
30869
  if (typeof __CLI_VERSION__ === "string") ownVersion = __CLI_VERSION__;
@@ -30753,7 +30878,7 @@ var init_sync_client = __esm({
30753
30878
  ]);
30754
30879
  walkProgressForUpload = null;
30755
30880
  lastServerPackSpec = null;
30756
- credPath = () => join47(getDataDir(), "credentials.json");
30881
+ credPath = () => join48(getDataDir(), "credentials.json");
30757
30882
  _securityConfigCache = /* @__PURE__ */ new Map();
30758
30883
  SECURITY_CONFIG_TTL_MS = 5 * 60 * 1e3;
30759
30884
  _syncConfigCache = /* @__PURE__ */ new Map();
@@ -30775,83 +30900,6 @@ var init_sync_client = __esm({
30775
30900
  }
30776
30901
  });
30777
30902
 
30778
- // src/memory-guard.ts
30779
- import { readFileSync as readFileSync42, writeFileSync as writeFileSync11 } from "node:fs";
30780
- import { join as join48 } from "node:path";
30781
- function rssMb() {
30782
- return Math.round(process.memoryUsage().rss / 1048576);
30783
- }
30784
- function memoryLimitMb(env = process.env) {
30785
- const raw = env.CHAT_RECALL_WATCH_RSS_MAX_MB;
30786
- if (!raw) return DEFAULT_RSS_MAX_MB;
30787
- const n = Number(raw);
30788
- return Number.isFinite(n) && n > 0 ? Math.round(n) : DEFAULT_RSS_MAX_MB;
30789
- }
30790
- function isOverMemoryLimit(rss, limitMb) {
30791
- return rss >= limitMb;
30792
- }
30793
- function releaseMemory(gc = globalThis.gc) {
30794
- if (typeof gc !== "function") return false;
30795
- gc();
30796
- return true;
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
- }
30835
- function cgroupCurrentMb(dir = cgroupDir()) {
30836
- if (!dir) return null;
30837
- try {
30838
- const n = Number(readFileSync42(join48(dir, "memory.current"), "utf8").trim());
30839
- return Number.isFinite(n) ? Math.round(n / 1048576) : null;
30840
- } catch {
30841
- return null;
30842
- }
30843
- }
30844
- function usedMb(rss = rssMb(), cgroup = cgroupCurrentMb()) {
30845
- return cgroup !== null && cgroup > rss ? cgroup : rss;
30846
- }
30847
- var DEFAULT_RSS_MAX_MB;
30848
- var init_memory_guard = __esm({
30849
- "src/memory-guard.ts"() {
30850
- "use strict";
30851
- DEFAULT_RSS_MAX_MB = 512;
30852
- }
30853
- });
30854
-
30855
30903
  // ../engine/dist/core/artifact-codec.js
30856
30904
  import { readFileSync as readFileSync43 } from "fs";
30857
30905
  import { basename as basename23, join as join49 } from "path";
@@ -34869,13 +34917,13 @@ async function codeIndexTick() {
34869
34917
  }
34870
34918
  let ok = 0, unchanged = 0;
34871
34919
  const cursor = readCursor();
34872
- const rssLimit = memoryLimitMb();
34920
+ const memBudget = startBudget(usedMb(rssMb()));
34873
34921
  for (const ws of workspaces) {
34874
34922
  const used = usedMb(rssMb());
34875
- if (isOverMemoryLimit(used, rssLimit)) {
34923
+ if (shouldPause(used, memBudget, ok)) {
34876
34924
  releaseMemory();
34877
34925
  reclaimCgroup();
34878
- daemonLog.info(`code intelligence: paused at the memory bound (used=${used}MB \u2265 ${rssLimit}MB) \u2014 ${workspaces.length - ok - unchanged} workspace(s) wait for the next pass`);
34926
+ daemonLog.info(`code intelligence: paused at the memory bound (used=${used}MB, started at ${memBudget.baselineMb}MB) \u2014 ${workspaces.length - ok - unchanged} workspace(s) wait for the next pass`);
34879
34927
  break;
34880
34928
  }
34881
34929
  const fp = workspaceFingerprint(ws, COLLECTOR_VERSION2);
@@ -34912,6 +34960,15 @@ async function codeIndexTick() {
34912
34960
  codeIndexInFlight = false;
34913
34961
  }
34914
34962
  }
34963
+ function residentTick() {
34964
+ const dir = cgroupDir();
34965
+ const fileMb = dir ? memoryStatMb(dir, "file") : null;
34966
+ if (shouldReclaim(fileMb)) {
34967
+ reclaimCgroup(DEFAULT_RECLAIM_FILE_MB);
34968
+ daemonLog.info(`resident: returned the page cache above ${DEFAULT_RECLAIM_FILE_MB}MB (file=${fileMb}MB)`);
34969
+ }
34970
+ releaseMemory();
34971
+ }
34915
34972
  async function autoUpdateTick() {
34916
34973
  for (const cred of loadAllCredentials()) {
34917
34974
  const base3 = cred.serverUrl.replace(/\/+$/, "");
@@ -35232,6 +35289,8 @@ var init_indexer = __esm({
35232
35289
  }, 9e4);
35233
35290
  daemonLog.info(` Code intelligence: AUTO \u2014 discovers your repos & indexes them (every ${CODE_INDEX_MS / 6e4}m \xB7 ${CODE_INDEX_WINDOW_DAYS}d window \xB7 max ${CODE_INDEX_MAX})`);
35234
35291
  }
35292
+ setInterval(residentTick, 3e4).unref();
35293
+ setTimeout(residentTick, 45e3);
35235
35294
  try {
35236
35295
  const { refreshServiceDefinition: refreshServiceDefinition2 } = await Promise.resolve().then(() => (init_service_installer(), service_installer_exports));
35237
35296
  if (refreshServiceDefinition2()) daemonLog.info("service definition refreshed to this version");