remoteclaw 0.1.0-next.b9d22ea → 0.1.0-next.e3d3913

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (26) hide show
  1. package/dist/{accounts-6bE7_6RL.js → accounts-DesSv1wD.js} +1 -1
  2. package/dist/boot/handler.js +29 -29
  3. package/dist/build-info.json +3 -3
  4. package/dist/canvas-host/a2ui/.bundle.hash +1 -1
  5. package/dist/{channel-activity-BZbNMyql.js → channel-activity-hPfValKp.js} +2 -2
  6. package/dist/command-logger/handler.js +1 -1
  7. package/dist/{fetch-BFuS-EfP.js → fetch-DMmdxAp3.js} +1 -1
  8. package/dist/{media-BrtsoHDf.js → media-DHIjuVaq.js} +47 -47
  9. package/dist/{outbound-attachment-DvxfVMMN.js → outbound-attachment-D0PBuR8U.js} +2 -2
  10. package/dist/{retry-D_-vU9CD.js → retry-C81p7BZU.js} +1 -1
  11. package/dist/{secure-random-B7stcuHs.js → secure-random-C8Siev1-.js} +1 -1
  12. package/dist/{send-fmudAAFF.js → send-1l8en2au.js} +3 -3
  13. package/dist/{send-uNEzfw9q.js → send-B8r5IJ7q.js} +6 -6
  14. package/dist/{send-C2BVmzi6.js → send-BdYZ_7sw.js} +7 -7
  15. package/dist/{send-DD5szdZD.js → send-Bt4yJ4_Z.js} +13 -13
  16. package/dist/{send-DIO6FcGs.js → send-DAJqND45.js} +4 -4
  17. package/dist/send-DlK-DVCQ.js +11 -0
  18. package/dist/{store-Bxy7EHAf.js → store-C6xUjjK-.js} +5 -5
  19. package/dist/{subsystem-C_FedsH7.js → subsystem-CDhxwtDd.js} +18 -18
  20. package/dist/{tables-BO6GU4qX.js → tables-DoSY1jjh.js} +1 -1
  21. package/dist/{targets-B-hWtwfx.js → targets-BDsqoJet.js} +3 -3
  22. package/dist/{targets-CMhBAn87.js → targets-JCISV-hS.js} +3 -3
  23. package/dist/{usage-DY7X9Iud.js → usage-BXUxy7CN.js} +56 -56
  24. package/dist/{web-C5EBMd1-.js → web-CmJpHiFE.js} +16 -16
  25. package/package.json +1 -1
  26. package/dist/send-D9zlp5S9.js +0 -11
@@ -1,15 +1,15 @@
1
- import { C as writeConfigFile, N as resolveTelegramAccount, P as isTruthyEnvValue, S as readConfigFileSnapshotForWrite, a as isGifMedia, i as getFileExtension, l as markdownToIR, o as normalizeMimeType, p as resolveMarkdownTableMode, s as mediaKindFromMime, t as loadWebMedia, x as loadConfig } from "./media-BrtsoHDf.js";
2
- import { F as expandHomePrefix, l as CONFIG_DIR, t as createSubsystemLogger, v as danger, y as logVerbose } from "./subsystem-C_FedsH7.js";
3
- import { n as normalizeTelegramLookupTarget, r as parseTelegramTarget, t as normalizeTelegramChatId } from "./targets-CMhBAn87.js";
4
- import { t as resolveFetch } from "./fetch-BFuS-EfP.js";
5
- import "./retry-D_-vU9CD.js";
6
- import { a as formatErrorMessage, i as extractErrorCode, o as formatUncaughtError, r as createTelegramRetryRunner, s as redactSensitiveText, t as recordChannelActivity } from "./channel-activity-BZbNMyql.js";
1
+ import { C as writeConfigFile, N as resolveTelegramAccount, P as isTruthyEnvValue, S as readConfigFileSnapshotForWrite, a as isGifMedia, i as getFileExtension, l as markdownToIR, o as normalizeMimeType, p as resolveMarkdownTableMode, s as mediaKindFromMime, t as loadWebMedia, x as loadConfig } from "./media-DHIjuVaq.js";
2
+ import { F as expandHomePrefix, l as CONFIG_DIR, t as createSubsystemLogger, v as danger, y as logVerbose } from "./subsystem-CDhxwtDd.js";
3
+ import { n as normalizeTelegramLookupTarget, r as parseTelegramTarget, t as normalizeTelegramChatId } from "./targets-JCISV-hS.js";
4
+ import { t as resolveFetch } from "./fetch-DMmdxAp3.js";
5
+ import "./retry-C81p7BZU.js";
6
+ import { a as formatErrorMessage, i as extractErrorCode, o as formatUncaughtError, r as createTelegramRetryRunner, s as redactSensitiveText, t as recordChannelActivity } from "./channel-activity-hPfValKp.js";
7
7
  import { t as renderMarkdownWithMarkers } from "./render-6ahYfPwj.js";
8
8
  import path from "node:path";
9
- import fsSync, { readFileSync } from "node:fs";
9
+ import fs, { readFileSync } from "node:fs";
10
10
  import os from "node:os";
11
11
  import JSON5 from "json5";
12
- import fs from "node:fs/promises";
12
+ import fs$1 from "node:fs/promises";
13
13
  import crypto from "node:crypto";
14
14
  import * as dns from "node:dns";
15
15
  import { Agent, ProxyAgent, fetch, setGlobalDispatcher } from "undici";
@@ -640,7 +640,7 @@ function resolveCronStorePath(storePath) {
640
640
  }
641
641
  async function loadCronStore(storePath) {
642
642
  try {
643
- const raw = await fsSync.promises.readFile(storePath, "utf-8");
643
+ const raw = await fs.promises.readFile(storePath, "utf-8");
644
644
  let parsed;
645
645
  try {
646
646
  parsed = JSON5.parse(raw);
@@ -661,14 +661,14 @@ async function loadCronStore(storePath) {
661
661
  }
662
662
  }
663
663
  async function saveCronStore(storePath, store) {
664
- await fsSync.promises.mkdir(path.dirname(storePath), { recursive: true });
664
+ await fs.promises.mkdir(path.dirname(storePath), { recursive: true });
665
665
  const { randomBytes } = await import("node:crypto");
666
666
  const tmp = `${storePath}.${process.pid}.${randomBytes(8).toString("hex")}.tmp`;
667
667
  const json = JSON.stringify(store, null, 2);
668
- await fsSync.promises.writeFile(tmp, json, "utf-8");
669
- await fsSync.promises.rename(tmp, storePath);
668
+ await fs.promises.writeFile(tmp, json, "utf-8");
669
+ await fs.promises.rename(tmp, storePath);
670
670
  try {
671
- await fsSync.promises.copyFile(storePath, `${storePath}.bak`);
671
+ await fs.promises.copyFile(storePath, `${storePath}.bak`);
672
672
  } catch {}
673
673
  }
674
674
 
@@ -1,7 +1,7 @@
1
- import { b as fetchWithTimeout, c as chunkMarkdownIR, l as markdownToIR, p as resolveMarkdownTableMode, s as mediaKindFromMime, x as loadConfig } from "./media-BrtsoHDf.js";
2
- import { n as resolveSignalAccount, t as generateSecureUuid } from "./secure-random-B7stcuHs.js";
3
- import { t as resolveFetch } from "./fetch-BFuS-EfP.js";
4
- import { t as resolveOutboundAttachmentFromUrl } from "./outbound-attachment-DvxfVMMN.js";
1
+ import { b as fetchWithTimeout, c as chunkMarkdownIR, l as markdownToIR, p as resolveMarkdownTableMode, s as mediaKindFromMime, x as loadConfig } from "./media-DHIjuVaq.js";
2
+ import { n as resolveSignalAccount, t as generateSecureUuid } from "./secure-random-C8Siev1-.js";
3
+ import { t as resolveFetch } from "./fetch-DMmdxAp3.js";
4
+ import { t as resolveOutboundAttachmentFromUrl } from "./outbound-attachment-D0PBuR8U.js";
5
5
 
6
6
  //#region src/signal/format.ts
7
7
  function normalizeUrlForComparison(url) {
@@ -0,0 +1,11 @@
1
+ import "./media-DHIjuVaq.js";
2
+ import "./subsystem-CDhxwtDd.js";
3
+ import "./fetch-DMmdxAp3.js";
4
+ import "./retry-C81p7BZU.js";
5
+ import "./targets-BDsqoJet.js";
6
+ import "./channel-activity-hPfValKp.js";
7
+ import "./render-6ahYfPwj.js";
8
+ import "./tables-DoSY1jjh.js";
9
+ import { n as DiscordSendError, r as fetchChannelPermissionsDiscord, t as sendMessageDiscord } from "./web-CmJpHiFE.js";
10
+
11
+ export { sendMessageDiscord };
@@ -1,7 +1,7 @@
1
- import { n as detectMime, r as extensionForMime } from "./media-BrtsoHDf.js";
2
- import { p as resolveConfigDir } from "./subsystem-C_FedsH7.js";
1
+ import { n as detectMime, r as extensionForMime } from "./media-DHIjuVaq.js";
2
+ import { p as resolveConfigDir } from "./subsystem-CDhxwtDd.js";
3
3
  import path from "node:path";
4
- import fs from "node:fs/promises";
4
+ import fs$1 from "node:fs/promises";
5
5
  import crypto from "node:crypto";
6
6
 
7
7
  //#region src/media/store.ts
@@ -22,7 +22,7 @@ function sanitizeFilename(name) {
22
22
  async function saveMediaBuffer(buffer, contentType, subdir = "inbound", maxBytes = MAX_BYTES, originalFilename) {
23
23
  if (buffer.byteLength > maxBytes) throw new Error(`Media exceeds ${(maxBytes / (1024 * 1024)).toFixed(0)}MB limit`);
24
24
  const dir = path.join(resolveMediaDir(), subdir);
25
- await fs.mkdir(dir, {
25
+ await fs$1.mkdir(dir, {
26
26
  recursive: true,
27
27
  mode: 448
28
28
  });
@@ -40,7 +40,7 @@ async function saveMediaBuffer(buffer, contentType, subdir = "inbound", maxBytes
40
40
  id = sanitized ? `${sanitized}---${uuid}${ext}` : `${uuid}${ext}`;
41
41
  } else id = ext ? `${uuid}${ext}` : uuid;
42
42
  const dest = path.join(dir, id);
43
- await fs.writeFile(dest, buffer, { mode: 384 });
43
+ await fs$1.writeFile(dest, buffer, { mode: 384 });
44
44
  return {
45
45
  id,
46
46
  path: dest,
@@ -1,5 +1,5 @@
1
1
  import path from "node:path";
2
- import fsSync from "node:fs";
2
+ import fs from "node:fs";
3
3
  import os from "node:os";
4
4
  import chalk, { Chalk } from "chalk";
5
5
  import { Logger } from "tslog";
@@ -97,10 +97,10 @@ function resolveStateDir(env = process.env, homedir = envHomedir(env)) {
97
97
  if (override) return resolveUserPath$1(override, env, effectiveHomedir);
98
98
  const newDir = newStateDir(effectiveHomedir);
99
99
  const legacyDirs = legacyStateDirs(effectiveHomedir);
100
- if (fsSync.existsSync(newDir)) return newDir;
100
+ if (fs.existsSync(newDir)) return newDir;
101
101
  const existingLegacy = legacyDirs.find((dir) => {
102
102
  try {
103
- return fsSync.existsSync(dir);
103
+ return fs.existsSync(dir);
104
104
  } catch {
105
105
  return false;
106
106
  }
@@ -139,7 +139,7 @@ function resolveCanonicalConfigPath(env = process.env, stateDir = resolveStateDi
139
139
  function resolveConfigPathCandidate(env = process.env, homedir = envHomedir(env)) {
140
140
  const existing = resolveDefaultConfigCandidates(env, homedir).find((candidate) => {
141
141
  try {
142
- return fsSync.existsSync(candidate);
142
+ return fs.existsSync(candidate);
143
143
  } catch {
144
144
  return false;
145
145
  }
@@ -156,7 +156,7 @@ function resolveConfigPath(env = process.env, stateDir = resolveStateDir(env, en
156
156
  const stateOverride = env.REMOTECLAW_STATE_DIR?.trim();
157
157
  const existing = [path.join(stateDir, CONFIG_FILENAME), ...LEGACY_CONFIG_FILENAMES.map((name) => path.join(stateDir, name))].find((candidate) => {
158
158
  try {
159
- return fsSync.existsSync(candidate);
159
+ return fs.existsSync(candidate);
160
160
  } catch {
161
161
  return false;
162
162
  }
@@ -276,9 +276,9 @@ function isNodeErrorWithCode(err, code) {
276
276
  return typeof err === "object" && err !== null && "code" in err && err.code === code;
277
277
  }
278
278
  function resolvePreferredRemoteClawTmpDir(options = {}) {
279
- const accessSync = options.accessSync ?? fsSync.accessSync;
280
- const lstatSync = options.lstatSync ?? fsSync.lstatSync;
281
- const mkdirSync = options.mkdirSync ?? fsSync.mkdirSync;
279
+ const accessSync = options.accessSync ?? fs.accessSync;
280
+ const lstatSync = options.lstatSync ?? fs.lstatSync;
281
+ const mkdirSync = options.mkdirSync ?? fs.mkdirSync;
282
282
  const getuid = options.getuid ?? (() => {
283
283
  try {
284
284
  return typeof process.getuid === "function" ? process.getuid() : void 0;
@@ -305,7 +305,7 @@ function resolvePreferredRemoteClawTmpDir(options = {}) {
305
305
  const resolvePreferredState = (requireWritableAccess) => {
306
306
  try {
307
307
  if (!isTrustedPreferredDir(lstatSync(POSIX_REMOTECLAW_TMP_DIR))) return "invalid";
308
- if (requireWritableAccess) accessSync(POSIX_REMOTECLAW_TMP_DIR, fsSync.constants.W_OK | fsSync.constants.X_OK);
308
+ if (requireWritableAccess) accessSync(POSIX_REMOTECLAW_TMP_DIR, fs.constants.W_OK | fs.constants.X_OK);
309
309
  return "available";
310
310
  } catch (err) {
311
311
  if (isNodeErrorWithCode(err, "ENOENT")) return "missing";
@@ -316,7 +316,7 @@ function resolvePreferredRemoteClawTmpDir(options = {}) {
316
316
  if (existingPreferredState === "available") return POSIX_REMOTECLAW_TMP_DIR;
317
317
  if (existingPreferredState === "invalid") return fallback();
318
318
  try {
319
- accessSync("/tmp", fsSync.constants.W_OK | fsSync.constants.X_OK);
319
+ accessSync("/tmp", fs.constants.W_OK | fs.constants.X_OK);
320
320
  mkdirSync(POSIX_REMOTECLAW_TMP_DIR, {
321
321
  recursive: true,
322
322
  mode: 448
@@ -333,8 +333,8 @@ function resolvePreferredRemoteClawTmpDir(options = {}) {
333
333
  function readLoggingConfig() {
334
334
  const configPath = resolveConfigPath();
335
335
  try {
336
- if (!fsSync.existsSync(configPath)) return;
337
- const raw = fsSync.readFileSync(configPath, "utf-8");
336
+ if (!fs.existsSync(configPath)) return;
337
+ const raw = fs.readFileSync(configPath, "utf-8");
338
338
  const logging = JSON5.parse(raw)?.logging;
339
339
  if (!logging || typeof logging !== "object" || Array.isArray(logging)) return;
340
340
  return logging;
@@ -469,7 +469,7 @@ function isFileLogLevelEnabled(level) {
469
469
  return levelToMinLevel(level) <= levelToMinLevel(settings.level);
470
470
  }
471
471
  function buildLogger(settings) {
472
- fsSync.mkdirSync(path.dirname(settings.file), { recursive: true });
472
+ fs.mkdirSync(path.dirname(settings.file), { recursive: true });
473
473
  if (isRollingPath(settings.file)) pruneOldRollingLogs(path.dirname(settings.file));
474
474
  let currentFileBytes = getCurrentLogFileBytes(settings.file);
475
475
  let warnedAboutSizeCap = false;
@@ -513,14 +513,14 @@ function resolveMaxLogFileBytes(raw) {
513
513
  }
514
514
  function getCurrentLogFileBytes(file) {
515
515
  try {
516
- return fsSync.statSync(file).size;
516
+ return fs.statSync(file).size;
517
517
  } catch {
518
518
  return 0;
519
519
  }
520
520
  }
521
521
  function appendLogLine(file, line) {
522
522
  try {
523
- fsSync.appendFileSync(file, line, { encoding: "utf8" });
523
+ fs.appendFileSync(file, line, { encoding: "utf8" });
524
524
  return true;
525
525
  } catch {
526
526
  return false;
@@ -559,14 +559,14 @@ function isRollingPath(file) {
559
559
  }
560
560
  function pruneOldRollingLogs(dir) {
561
561
  try {
562
- const entries = fsSync.readdirSync(dir, { withFileTypes: true });
562
+ const entries = fs.readdirSync(dir, { withFileTypes: true });
563
563
  const cutoff = Date.now() - MAX_LOG_AGE_MS;
564
564
  for (const entry of entries) {
565
565
  if (!entry.isFile()) continue;
566
566
  if (!entry.name.startsWith(`${LOG_PREFIX}-`) || !entry.name.endsWith(LOG_SUFFIX)) continue;
567
567
  const fullPath = path.join(dir, entry.name);
568
568
  try {
569
- if (fsSync.statSync(fullPath).mtimeMs < cutoff) fsSync.rmSync(fullPath, { force: true });
569
+ if (fs.statSync(fullPath).mtimeMs < cutoff) fs.rmSync(fullPath, { force: true });
570
570
  } catch {}
571
571
  }
572
572
  } catch {}
@@ -686,7 +686,7 @@ function resolveConfigDir(env = process.env, homedir = os.homedir) {
686
686
  if (override) return resolveUserPath(override);
687
687
  const newDir = path.join(resolveRequiredHomeDir(env, homedir), ".remoteclaw");
688
688
  try {
689
- if (fsSync.existsSync(newDir)) return newDir;
689
+ if (fs.existsSync(newDir)) return newDir;
690
690
  } catch {}
691
691
  return newDir;
692
692
  }
@@ -1,4 +1,4 @@
1
- import { u as markdownToIRWithMeta } from "./media-BrtsoHDf.js";
1
+ import { u as markdownToIRWithMeta } from "./media-DHIjuVaq.js";
2
2
  import { t as renderMarkdownWithMarkers } from "./render-6ahYfPwj.js";
3
3
 
4
4
  //#region src/markdown/tables.ts
@@ -1,7 +1,7 @@
1
- import { R as resolveDiscordAccount, z as normalizeDiscordToken } from "./media-BrtsoHDf.js";
1
+ import { R as resolveDiscordAccount, z as normalizeDiscordToken } from "./media-DHIjuVaq.js";
2
2
  import { i as parseTargetPrefixes, n as ensureTargetId, r as parseTargetMention, t as buildMessagingTarget } from "./targets-BMenhVHg.js";
3
- import { t as resolveFetch } from "./fetch-BFuS-EfP.js";
4
- import { n as retryAsync, t as resolveRetryConfig } from "./retry-D_-vU9CD.js";
3
+ import { t as resolveFetch } from "./fetch-DMmdxAp3.js";
4
+ import { n as retryAsync, t as resolveRetryConfig } from "./retry-C81p7BZU.js";
5
5
 
6
6
  //#region src/discord/api.ts
7
7
  const DISCORD_API_BASE = "https://discord.com/api/v10";
@@ -1,6 +1,6 @@
1
1
  import path from "node:path";
2
- import fsSync from "node:fs";
3
- import fs from "node:fs/promises";
2
+ import fs from "node:fs";
3
+ import fs$1 from "node:fs/promises";
4
4
 
5
5
  //#region src/shared/pid-alive.ts
6
6
  /**
@@ -10,7 +10,7 @@ import fs from "node:fs/promises";
10
10
  function isZombieProcess(pid) {
11
11
  if (process.platform !== "linux") return false;
12
12
  try {
13
- return fsSync.readFileSync(`/proc/${pid}/status`, "utf8").match(/^State:\s+(\S)/m)?.[1] === "Z";
13
+ return fs.readFileSync(`/proc/${pid}/status`, "utf8").match(/^State:\s+(\S)/m)?.[1] === "Z";
14
14
  } catch {
15
15
  return false;
16
16
  }
@@ -1,12 +1,12 @@
1
- import { D as parseByteSize, E as parseDurationMs, F as resolveSlackAccount, H as normalizeChatType, I as resolveSlackReplyToMode, J as normalizeMessageChannel, M as resolveWhatsAppAccount, N as resolveTelegramAccount, O as getChannelPlugin, R as resolveDiscordAccount, U as INTERNAL_MESSAGE_CHANNEL, V as resolveAccountEntry, W as isDeliverableMessageChannel, ct as normalizeAgentId, et as normalizeProviderId$1, ft as normalizeAccountId$1, j as normalizeWhatsAppTarget, lt as normalizeMainKey, mt as deriveSessionChatType, ot as DEFAULT_AGENT_ID, pt as normalizeOptionalAccountId, q as listDeliverableMessageChannels, st as buildAgentMainSessionKey, tt as formatCliCommand, v as parseFenceSpans, x as loadConfig } from "./media-BrtsoHDf.js";
2
- import { F as expandHomePrefix, I as resolveRequiredHomeDir, P as resolveStateDir, a as normalizeAnyChannelId, c as requireActivePluginRegistry, f as normalizeE164, m as resolveUserPath, t as createSubsystemLogger, u as escapeRegExp } from "./subsystem-C_FedsH7.js";
3
- import { a as isPidAlive, i as resolveProcessScopedMap, r as parseTelegramTarget } from "./targets-CMhBAn87.js";
4
- import { t as resolveIMessageAccount } from "./accounts-6bE7_6RL.js";
5
- import { n as resolveSignalAccount } from "./secure-random-B7stcuHs.js";
1
+ import { D as parseByteSize, E as parseDurationMs, F as resolveSlackAccount, H as normalizeChatType, I as resolveSlackReplyToMode, J as normalizeMessageChannel, M as resolveWhatsAppAccount, N as resolveTelegramAccount, O as getChannelPlugin, R as resolveDiscordAccount, U as INTERNAL_MESSAGE_CHANNEL, V as resolveAccountEntry, W as isDeliverableMessageChannel, ct as normalizeAgentId, et as normalizeProviderId$1, ft as normalizeAccountId$1, j as normalizeWhatsAppTarget, lt as normalizeMainKey, mt as deriveSessionChatType, ot as DEFAULT_AGENT_ID, pt as normalizeOptionalAccountId, q as listDeliverableMessageChannels, st as buildAgentMainSessionKey, tt as formatCliCommand, v as parseFenceSpans, x as loadConfig } from "./media-DHIjuVaq.js";
2
+ import { F as expandHomePrefix, I as resolveRequiredHomeDir, P as resolveStateDir, a as normalizeAnyChannelId, c as requireActivePluginRegistry, f as normalizeE164, m as resolveUserPath, t as createSubsystemLogger, u as escapeRegExp } from "./subsystem-CDhxwtDd.js";
3
+ import { a as isPidAlive, i as resolveProcessScopedMap, r as parseTelegramTarget } from "./targets-JCISV-hS.js";
4
+ import { t as resolveIMessageAccount } from "./accounts-DesSv1wD.js";
5
+ import { n as resolveSignalAccount } from "./secure-random-C8Siev1-.js";
6
6
  import path, { join } from "node:path";
7
- import fsSync from "node:fs";
7
+ import fs from "node:fs";
8
8
  import os, { homedir, tmpdir } from "node:os";
9
- import fs, { mkdir, mkdtemp, readFile, readdir, rm, rmdir, writeFile } from "node:fs/promises";
9
+ import fs$1, { mkdir, mkdtemp, readFile, readdir, rm, rmdir, writeFile } from "node:fs/promises";
10
10
  import crypto, { randomUUID } from "node:crypto";
11
11
  import { spawn } from "node:child_process";
12
12
  import { createInterface } from "node:readline";
@@ -31,8 +31,8 @@ const log$4 = createSubsystemLogger("agents/auth-profiles");
31
31
  //#region src/infra/json-file.ts
32
32
  function loadJsonFile(pathname) {
33
33
  try {
34
- if (!fsSync.existsSync(pathname)) return;
35
- const raw = fsSync.readFileSync(pathname, "utf8");
34
+ if (!fs.existsSync(pathname)) return;
35
+ const raw = fs.readFileSync(pathname, "utf8");
36
36
  return JSON.parse(raw);
37
37
  } catch {
38
38
  return;
@@ -40,12 +40,12 @@ function loadJsonFile(pathname) {
40
40
  }
41
41
  function saveJsonFile(pathname, data) {
42
42
  const dir = path.dirname(pathname);
43
- if (!fsSync.existsSync(dir)) fsSync.mkdirSync(dir, {
43
+ if (!fs.existsSync(dir)) fs.mkdirSync(dir, {
44
44
  recursive: true,
45
45
  mode: 448
46
46
  });
47
- fsSync.writeFileSync(pathname, `${JSON.stringify(data, null, 2)}\n`, "utf8");
48
- fsSync.chmodSync(pathname, 384);
47
+ fs.writeFileSync(pathname, `${JSON.stringify(data, null, 2)}\n`, "utf8");
48
+ fs.chmodSync(pathname, 384);
49
49
  }
50
50
 
51
51
  //#endregion
@@ -151,7 +151,7 @@ function loadAuthProfileStoreForAgent(agentDir, _options) {
151
151
  if (shouldWrite && legacy !== null) {
152
152
  const legacyPath = resolveLegacyAuthStorePath(agentDir);
153
153
  try {
154
- fsSync.unlinkSync(legacyPath);
154
+ fs.unlinkSync(legacyPath);
155
155
  } catch (err) {
156
156
  if (err?.code !== "ENOENT") log$4.warn("failed to delete legacy auth.json after migration", {
157
157
  err,
@@ -1211,7 +1211,7 @@ function resolveStructuralSessionFallbackPath(candidateAbsPath, expectedAgentId)
1211
1211
  }
1212
1212
  function safeRealpathSync(filePath) {
1213
1213
  try {
1214
- return fsSync.realpathSync(filePath);
1214
+ return fs.realpathSync(filePath);
1215
1215
  } catch {
1216
1216
  return;
1217
1217
  }
@@ -1484,7 +1484,7 @@ async function releaseHeldLock(normalizedSessionFile, held, opts = {}) {
1484
1484
  await held.handle.close();
1485
1485
  } catch {}
1486
1486
  try {
1487
- await fs.rm(held.lockPath, { force: true });
1487
+ await fs$1.rm(held.lockPath, { force: true });
1488
1488
  } catch {}
1489
1489
  })();
1490
1490
  try {
@@ -1504,7 +1504,7 @@ function releaseAllLocksSync() {
1504
1504
  if (typeof held.handle.close === "function") held.handle.close().catch(() => {});
1505
1505
  } catch {}
1506
1506
  try {
1507
- fsSync.rmSync(held.lockPath, { force: true });
1507
+ fs.rmSync(held.lockPath, { force: true });
1508
1508
  } catch {}
1509
1509
  HELD_LOCKS.delete(sessionFile);
1510
1510
  }
@@ -1563,7 +1563,7 @@ function registerCleanupHandlers() {
1563
1563
  }
1564
1564
  async function readLockPayload(lockPath) {
1565
1565
  try {
1566
- const raw = await fs.readFile(lockPath, "utf8");
1566
+ const raw = await fs$1.readFile(lockPath, "utf8");
1567
1567
  const parsed = JSON.parse(raw);
1568
1568
  const payload = {};
1569
1569
  if (typeof parsed.pid === "number") payload.pid = parsed.pid;
@@ -1600,7 +1600,7 @@ async function shouldReclaimContendedLockFile(lockPath, details, staleMs, nowMs)
1600
1600
  if (!details.stale) return false;
1601
1601
  if (!lockInspectionNeedsMtimeStaleFallback(details)) return true;
1602
1602
  try {
1603
- const stat = await fs.stat(lockPath);
1603
+ const stat = await fs$1.stat(lockPath);
1604
1604
  return Math.max(0, nowMs - stat.mtimeMs) > staleMs;
1605
1605
  } catch (error) {
1606
1606
  return error?.code !== "ENOENT";
@@ -1613,10 +1613,10 @@ async function acquireSessionWriteLock(params) {
1613
1613
  const maxHoldMs = resolvePositiveMs(params.maxHoldMs, DEFAULT_MAX_HOLD_MS);
1614
1614
  const sessionFile = path.resolve(params.sessionFile);
1615
1615
  const sessionDir = path.dirname(sessionFile);
1616
- await fs.mkdir(sessionDir, { recursive: true });
1616
+ await fs$1.mkdir(sessionDir, { recursive: true });
1617
1617
  let normalizedDir = sessionDir;
1618
1618
  try {
1619
- normalizedDir = await fs.realpath(sessionDir);
1619
+ normalizedDir = await fs$1.realpath(sessionDir);
1620
1620
  } catch {}
1621
1621
  const normalizedSessionFile = path.join(normalizedDir, path.basename(sessionFile));
1622
1622
  const lockPath = `${normalizedSessionFile}.lock`;
@@ -1634,7 +1634,7 @@ async function acquireSessionWriteLock(params) {
1634
1634
  attempt += 1;
1635
1635
  let handle = null;
1636
1636
  try {
1637
- handle = await fs.open(lockPath, "wx");
1637
+ handle = await fs$1.open(lockPath, "wx");
1638
1638
  const createdAt = (/* @__PURE__ */ new Date()).toISOString();
1639
1639
  await handle.writeFile(JSON.stringify({
1640
1640
  pid: process.pid,
@@ -1657,14 +1657,14 @@ async function acquireSessionWriteLock(params) {
1657
1657
  await handle.close();
1658
1658
  } catch {}
1659
1659
  try {
1660
- await fs.rm(lockPath, { force: true });
1660
+ await fs$1.rm(lockPath, { force: true });
1661
1661
  } catch {}
1662
1662
  }
1663
1663
  if (err.code !== "EEXIST") throw err;
1664
1664
  const payload = await readLockPayload(lockPath);
1665
1665
  const nowMs = Date.now();
1666
1666
  if (await shouldReclaimContendedLockFile(lockPath, inspectLockPayload(payload, staleMs, nowMs), staleMs, nowMs)) {
1667
- await fs.rm(lockPath, { force: true });
1667
+ await fs$1.rm(lockPath, { force: true });
1668
1668
  continue;
1669
1669
  }
1670
1670
  const delay = Math.min(1e3, 50 * attempt);
@@ -1796,14 +1796,14 @@ function resolveSessionTranscriptCandidates(sessionId, storePath, sessionFile, a
1796
1796
  function canonicalizePathForComparison$1(filePath) {
1797
1797
  const resolved = path.resolve(filePath);
1798
1798
  try {
1799
- return fsSync.realpathSync(resolved);
1799
+ return fs.realpathSync(resolved);
1800
1800
  } catch {
1801
1801
  return resolved;
1802
1802
  }
1803
1803
  }
1804
1804
  function archiveFileOnDisk(filePath, reason) {
1805
1805
  const archived = `${filePath}.${reason}.${formatSessionArchiveTimestamp()}`;
1806
- fsSync.renameSync(filePath, archived);
1806
+ fs.renameSync(filePath, archived);
1807
1807
  return archived;
1808
1808
  }
1809
1809
  /**
@@ -1819,7 +1819,7 @@ function archiveSessionTranscripts(opts) {
1819
1819
  const relative = path.relative(storeDir, candidatePath);
1820
1820
  if (!relative || relative.startsWith("..") || path.isAbsolute(relative)) continue;
1821
1821
  }
1822
- if (!fsSync.existsSync(candidatePath)) continue;
1822
+ if (!fs.existsSync(candidatePath)) continue;
1823
1823
  try {
1824
1824
  archived.push(archiveFileOnDisk(candidatePath, opts.reason));
1825
1825
  } catch {}
@@ -1837,15 +1837,15 @@ async function cleanupArchivedSessionTranscripts(opts) {
1837
1837
  let removed = 0;
1838
1838
  let scanned = 0;
1839
1839
  for (const dir of directories) {
1840
- const entries = await fsSync.promises.readdir(dir).catch(() => []);
1840
+ const entries = await fs.promises.readdir(dir).catch(() => []);
1841
1841
  for (const entry of entries) {
1842
1842
  const timestamp = parseSessionArchiveTimestamp(entry, reason);
1843
1843
  if (timestamp == null) continue;
1844
1844
  scanned += 1;
1845
1845
  if (now - timestamp <= opts.olderThanMs) continue;
1846
1846
  const fullPath = path.join(dir, entry);
1847
- if (!(await fsSync.promises.stat(fullPath).catch(() => null))?.isFile()) continue;
1848
- await fsSync.promises.rm(fullPath).catch(() => void 0);
1847
+ if (!(await fs.promises.stat(fullPath).catch(() => null))?.isFile()) continue;
1848
+ await fs.promises.rm(fullPath).catch(() => void 0);
1849
1849
  removed += 1;
1850
1850
  }
1851
1851
  }
@@ -1951,7 +1951,7 @@ function isCacheEnabled(ttlMs) {
1951
1951
  }
1952
1952
  function getFileMtimeMs(filePath) {
1953
1953
  try {
1954
- return fsSync.statSync(filePath).mtimeMs;
1954
+ return fs.statSync(filePath).mtimeMs;
1955
1955
  } catch {
1956
1956
  return;
1957
1957
  }
@@ -1966,7 +1966,7 @@ const NOOP_LOGGER = {
1966
1966
  function canonicalizePathForComparison(filePath) {
1967
1967
  const resolved = path.resolve(filePath);
1968
1968
  try {
1969
- return fsSync.realpathSync(resolved);
1969
+ return fs.realpathSync(resolved);
1970
1970
  } catch {
1971
1971
  return resolved;
1972
1972
  }
@@ -2024,12 +2024,12 @@ function resolveReferencedSessionTranscriptPaths(params) {
2024
2024
  return referenced;
2025
2025
  }
2026
2026
  async function readSessionsDirFiles(sessionsDir) {
2027
- const dirEntries = await fsSync.promises.readdir(sessionsDir, { withFileTypes: true }).catch(() => []);
2027
+ const dirEntries = await fs.promises.readdir(sessionsDir, { withFileTypes: true }).catch(() => []);
2028
2028
  const files = [];
2029
2029
  for (const dirent of dirEntries) {
2030
2030
  if (!dirent.isFile()) continue;
2031
2031
  const filePath = path.join(sessionsDir, dirent.name);
2032
- const stat = await fsSync.promises.stat(filePath).catch(() => null);
2032
+ const stat = await fs.promises.stat(filePath).catch(() => null);
2033
2033
  if (!stat?.isFile()) continue;
2034
2034
  files.push({
2035
2035
  path: filePath,
@@ -2042,9 +2042,9 @@ async function readSessionsDirFiles(sessionsDir) {
2042
2042
  return files;
2043
2043
  }
2044
2044
  async function removeFileIfExists(filePath) {
2045
- const stat = await fsSync.promises.stat(filePath).catch(() => null);
2045
+ const stat = await fs.promises.stat(filePath).catch(() => null);
2046
2046
  if (!stat?.isFile()) return 0;
2047
- await fsSync.promises.rm(filePath, { force: true }).catch(() => void 0);
2047
+ await fs.promises.rm(filePath, { force: true }).catch(() => void 0);
2048
2048
  return stat.size;
2049
2049
  }
2050
2050
  async function removeFileForBudget(params) {
@@ -2267,7 +2267,7 @@ function loadSessionStore(storePath, opts = {}) {
2267
2267
  const maxReadAttempts = process.platform === "win32" ? 3 : 1;
2268
2268
  const retryBuf = maxReadAttempts > 1 ? new Int32Array(new SharedArrayBuffer(4)) : void 0;
2269
2269
  for (let attempt = 0; attempt < maxReadAttempts; attempt++) try {
2270
- const raw = fsSync.readFileSync(storePath, "utf-8");
2270
+ const raw = fs.readFileSync(storePath, "utf-8");
2271
2271
  if (raw.length === 0 && attempt < maxReadAttempts - 1) {
2272
2272
  Atomics.wait(retryBuf, 0, 0, 50);
2273
2273
  continue;
@@ -2460,7 +2460,7 @@ function capEntryCount(store, overrideMax, opts = {}) {
2460
2460
  }
2461
2461
  async function getSessionFileSize(storePath) {
2462
2462
  try {
2463
- return (await fsSync.promises.stat(storePath)).size;
2463
+ return (await fs.promises.stat(storePath)).size;
2464
2464
  } catch {
2465
2465
  return null;
2466
2466
  }
@@ -2477,7 +2477,7 @@ async function rotateSessionFile(storePath, overrideBytes) {
2477
2477
  if (fileSize <= maxBytes) return false;
2478
2478
  const backupPath = `${storePath}.bak.${Date.now()}`;
2479
2479
  try {
2480
- await fsSync.promises.rename(storePath, backupPath);
2480
+ await fs.promises.rename(storePath, backupPath);
2481
2481
  log$3.info("rotated session store file", {
2482
2482
  backupPath: path.basename(backupPath),
2483
2483
  sizeBytes: fileSize
@@ -2488,11 +2488,11 @@ async function rotateSessionFile(storePath, overrideBytes) {
2488
2488
  try {
2489
2489
  const dir = path.dirname(storePath);
2490
2490
  const baseName = path.basename(storePath);
2491
- const backups = (await fsSync.promises.readdir(dir)).filter((f) => f.startsWith(`${baseName}.bak.`)).toSorted().toReversed();
2491
+ const backups = (await fs.promises.readdir(dir)).filter((f) => f.startsWith(`${baseName}.bak.`)).toSorted().toReversed();
2492
2492
  const maxBackups = 3;
2493
2493
  if (backups.length > maxBackups) {
2494
2494
  const toDelete = backups.slice(maxBackups);
2495
- for (const old of toDelete) await fsSync.promises.unlink(path.join(dir, old)).catch(() => void 0);
2495
+ for (const old of toDelete) await fs.promises.unlink(path.join(dir, old)).catch(() => void 0);
2496
2496
  log$3.info("cleaned up old session store backups", { deleted: toDelete.length });
2497
2497
  }
2498
2498
  } catch {}
@@ -2597,14 +2597,14 @@ async function saveSessionStoreUnlocked(storePath, store, opts) {
2597
2597
  });
2598
2598
  }
2599
2599
  }
2600
- await fsSync.promises.mkdir(path.dirname(storePath), { recursive: true });
2600
+ await fs.promises.mkdir(path.dirname(storePath), { recursive: true });
2601
2601
  const json = JSON.stringify(store, null, 2);
2602
2602
  if (process.platform === "win32") {
2603
2603
  const tmp = `${storePath}.${process.pid}.${crypto.randomUUID()}.tmp`;
2604
2604
  try {
2605
- await fsSync.promises.writeFile(tmp, json, "utf-8");
2605
+ await fs.promises.writeFile(tmp, json, "utf-8");
2606
2606
  for (let i = 0; i < 5; i++) try {
2607
- await fsSync.promises.rename(tmp, storePath);
2607
+ await fs.promises.rename(tmp, storePath);
2608
2608
  break;
2609
2609
  } catch {
2610
2610
  if (i < 4) await new Promise((r) => setTimeout(r, 50 * (i + 1)));
@@ -2614,27 +2614,27 @@ async function saveSessionStoreUnlocked(storePath, store, opts) {
2614
2614
  if ((err && typeof err === "object" && "code" in err ? String(err.code) : null) === "ENOENT") return;
2615
2615
  throw err;
2616
2616
  } finally {
2617
- await fsSync.promises.rm(tmp, { force: true }).catch(() => void 0);
2617
+ await fs.promises.rm(tmp, { force: true }).catch(() => void 0);
2618
2618
  }
2619
2619
  return;
2620
2620
  }
2621
2621
  const tmp = `${storePath}.${process.pid}.${crypto.randomUUID()}.tmp`;
2622
2622
  try {
2623
- await fsSync.promises.writeFile(tmp, json, {
2623
+ await fs.promises.writeFile(tmp, json, {
2624
2624
  mode: 384,
2625
2625
  encoding: "utf-8"
2626
2626
  });
2627
- await fsSync.promises.rename(tmp, storePath);
2628
- await fsSync.promises.chmod(storePath, 384);
2627
+ await fs.promises.rename(tmp, storePath);
2628
+ await fs.promises.chmod(storePath, 384);
2629
2629
  } catch (err) {
2630
2630
  if ((err && typeof err === "object" && "code" in err ? String(err.code) : null) === "ENOENT") {
2631
2631
  try {
2632
- await fsSync.promises.mkdir(path.dirname(storePath), { recursive: true });
2633
- await fsSync.promises.writeFile(storePath, json, {
2632
+ await fs.promises.mkdir(path.dirname(storePath), { recursive: true });
2633
+ await fs.promises.writeFile(storePath, json, {
2634
2634
  mode: 384,
2635
2635
  encoding: "utf-8"
2636
2636
  });
2637
- await fsSync.promises.chmod(storePath, 384);
2637
+ await fs.promises.chmod(storePath, 384);
2638
2638
  } catch (err2) {
2639
2639
  if ((err2 && typeof err2 === "object" && "code" in err2 ? String(err2.code) : null) === "ENOENT") return;
2640
2640
  throw err2;
@@ -2643,7 +2643,7 @@ async function saveSessionStoreUnlocked(storePath, store, opts) {
2643
2643
  }
2644
2644
  throw err;
2645
2645
  } finally {
2646
- await fsSync.promises.rm(tmp, { force: true });
2646
+ await fs.promises.rm(tmp, { force: true });
2647
2647
  }
2648
2648
  }
2649
2649
  async function updateSessionStore(storePath, mutator, opts) {
@@ -2825,8 +2825,8 @@ function resolveMirroredTranscriptText(params) {
2825
2825
  return trimmed ? trimmed : null;
2826
2826
  }
2827
2827
  async function ensureSessionHeader(params) {
2828
- if (fsSync.existsSync(params.sessionFile)) return;
2829
- await fsSync.promises.mkdir(path.dirname(params.sessionFile), { recursive: true });
2828
+ if (fs.existsSync(params.sessionFile)) return;
2829
+ await fs.promises.mkdir(path.dirname(params.sessionFile), { recursive: true });
2830
2830
  const header = {
2831
2831
  type: "session",
2832
2832
  version: CURRENT_SESSION_VERSION,
@@ -2834,7 +2834,7 @@ async function ensureSessionHeader(params) {
2834
2834
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
2835
2835
  cwd: process.cwd()
2836
2836
  };
2837
- await fsSync.promises.writeFile(params.sessionFile, `${JSON.stringify(header)}\n`, {
2837
+ await fs.promises.writeFile(params.sessionFile, `${JSON.stringify(header)}\n`, {
2838
2838
  encoding: "utf-8",
2839
2839
  mode: 384
2840
2840
  });
@@ -2910,7 +2910,7 @@ async function appendAssistantMessageToSessionTranscript(params) {
2910
2910
  timestamp: Date.now()
2911
2911
  }
2912
2912
  };
2913
- await fsSync.promises.appendFile(sessionFile, `${JSON.stringify(line)}\n`, "utf-8");
2913
+ await fs.promises.appendFile(sessionFile, `${JSON.stringify(line)}\n`, "utf-8");
2914
2914
  emitSessionTranscriptUpdate(sessionFile);
2915
2915
  return {
2916
2916
  ok: true,
@@ -2996,7 +2996,7 @@ const DEFAULT_CONTEXT_TOKENS = 2e5;
2996
2996
  //#endregion
2997
2997
  //#region src/agents/workspace.ts
2998
2998
  async function ensureAgentWorkspace(dir) {
2999
- await fs.mkdir(dir, { recursive: true });
2999
+ await fs$1.mkdir(dir, { recursive: true });
3000
3000
  return dir;
3001
3001
  }
3002
3002