@adhdev/daemon-core 0.9.50 → 0.9.52

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/index.js CHANGED
@@ -1340,11 +1340,11 @@ function loadNodePty() {
1340
1340
  }
1341
1341
  return cachedPty;
1342
1342
  }
1343
- var os7, cachedPty, NodePtyRuntimeTransport, NodePtyTransportFactory;
1343
+ var os8, cachedPty, NodePtyRuntimeTransport, NodePtyTransportFactory;
1344
1344
  var init_pty_transport = __esm({
1345
1345
  "src/cli-adapters/pty-transport.ts"() {
1346
1346
  "use strict";
1347
- os7 = __toESM(require("os"));
1347
+ os8 = __toESM(require("os"));
1348
1348
  init_spawn_env();
1349
1349
  NodePtyRuntimeTransport = class {
1350
1350
  constructor(handle) {
@@ -1381,11 +1381,11 @@ var init_pty_transport = __esm({
1381
1381
  let cwd = options.cwd;
1382
1382
  if (cwd) {
1383
1383
  try {
1384
- const fs15 = require("fs");
1385
- const stat = fs15.statSync(cwd);
1386
- if (!stat.isDirectory()) cwd = os7.homedir();
1384
+ const fs16 = require("fs");
1385
+ const stat = fs16.statSync(cwd);
1386
+ if (!stat.isDirectory()) cwd = os8.homedir();
1387
1387
  } catch {
1388
- cwd = os7.homedir();
1388
+ cwd = os8.homedir();
1389
1389
  }
1390
1390
  }
1391
1391
  const handle = pty.spawn(command, args, {
@@ -1465,11 +1465,11 @@ function buildCliScreenSnapshot(text) {
1465
1465
  function findBinary(name) {
1466
1466
  const trimmed = String(name || "").trim();
1467
1467
  if (!trimmed) return trimmed;
1468
- const expanded = trimmed.startsWith("~") ? path9.join(os8.homedir(), trimmed.slice(1)) : trimmed;
1469
- if (path9.isAbsolute(expanded) || expanded.includes("/") || expanded.includes("\\")) {
1470
- return path9.isAbsolute(expanded) ? expanded : path9.resolve(expanded);
1468
+ const expanded = trimmed.startsWith("~") ? path10.join(os9.homedir(), trimmed.slice(1)) : trimmed;
1469
+ if (path10.isAbsolute(expanded) || expanded.includes("/") || expanded.includes("\\")) {
1470
+ return path10.isAbsolute(expanded) ? expanded : path10.resolve(expanded);
1471
1471
  }
1472
- const isWin = os8.platform() === "win32";
1472
+ const isWin = os9.platform() === "win32";
1473
1473
  try {
1474
1474
  const cmd = isWin ? `where ${trimmed}` : `which ${trimmed}`;
1475
1475
  return (0, import_child_process4.execSync)(cmd, {
@@ -1483,14 +1483,14 @@ function findBinary(name) {
1483
1483
  }
1484
1484
  }
1485
1485
  function isScriptBinary(binaryPath) {
1486
- if (!path9.isAbsolute(binaryPath)) return false;
1486
+ if (!path10.isAbsolute(binaryPath)) return false;
1487
1487
  try {
1488
- const fs15 = require("fs");
1489
- const resolved = fs15.realpathSync(binaryPath);
1488
+ const fs16 = require("fs");
1489
+ const resolved = fs16.realpathSync(binaryPath);
1490
1490
  const head = Buffer.alloc(8);
1491
- const fd = fs15.openSync(resolved, "r");
1492
- fs15.readSync(fd, head, 0, 8, 0);
1493
- fs15.closeSync(fd);
1491
+ const fd = fs16.openSync(resolved, "r");
1492
+ fs16.readSync(fd, head, 0, 8, 0);
1493
+ fs16.closeSync(fd);
1494
1494
  let i = 0;
1495
1495
  if (head[0] === 239 && head[1] === 187 && head[2] === 191) i = 3;
1496
1496
  return head[i] === 35 && head[i + 1] === 33;
@@ -1499,14 +1499,14 @@ function isScriptBinary(binaryPath) {
1499
1499
  }
1500
1500
  }
1501
1501
  function looksLikeMachOOrElf(filePath) {
1502
- if (!path9.isAbsolute(filePath)) return false;
1502
+ if (!path10.isAbsolute(filePath)) return false;
1503
1503
  try {
1504
- const fs15 = require("fs");
1505
- const resolved = fs15.realpathSync(filePath);
1504
+ const fs16 = require("fs");
1505
+ const resolved = fs16.realpathSync(filePath);
1506
1506
  const buf = Buffer.alloc(8);
1507
- const fd = fs15.openSync(resolved, "r");
1508
- fs15.readSync(fd, buf, 0, 8, 0);
1509
- fs15.closeSync(fd);
1507
+ const fd = fs16.openSync(resolved, "r");
1508
+ fs16.readSync(fd, buf, 0, 8, 0);
1509
+ fs16.closeSync(fd);
1510
1510
  let i = 0;
1511
1511
  if (buf[0] === 239 && buf[1] === 187 && buf[2] === 191) i = 3;
1512
1512
  const b = buf.subarray(i);
@@ -1522,7 +1522,7 @@ function looksLikeMachOOrElf(filePath) {
1522
1522
  }
1523
1523
  function shSingleQuote(arg) {
1524
1524
  if (/^[a-zA-Z0-9@%_+=:,./-]+$/.test(arg)) return arg;
1525
- if (os8.platform() === "win32") {
1525
+ if (os9.platform() === "win32") {
1526
1526
  return `"${arg.replace(/"/g, '""')}"`;
1527
1527
  }
1528
1528
  return `'${arg.replace(/'/g, `'\\''`)}'`;
@@ -1649,12 +1649,12 @@ function normalizeCliProviderForRuntime(raw) {
1649
1649
  }
1650
1650
  };
1651
1651
  }
1652
- var os8, path9, import_child_process4, buildCliSpawnEnv, COMMON_COMPARABLE_WRAP_WORDS;
1652
+ var os9, path10, import_child_process4, buildCliSpawnEnv, COMMON_COMPARABLE_WRAP_WORDS;
1653
1653
  var init_provider_cli_shared = __esm({
1654
1654
  "src/cli-adapters/provider-cli-shared.ts"() {
1655
1655
  "use strict";
1656
- os8 = __toESM(require("os"));
1657
- path9 = __toESM(require("path"));
1656
+ os9 = __toESM(require("os"));
1657
+ path10 = __toESM(require("path"));
1658
1658
  import_child_process4 = require("child_process");
1659
1659
  init_spawn_env();
1660
1660
  buildCliSpawnEnv = import_session_host_core.sanitizeSpawnEnv;
@@ -1967,13 +1967,13 @@ function resolveCliSpawnPlan(options) {
1967
1967
  const { spawn: spawnConfig } = provider;
1968
1968
  const configuredCommand = typeof runtimeSettings.executablePath === "string" && runtimeSettings.executablePath.trim() ? runtimeSettings.executablePath.trim() : spawnConfig.command;
1969
1969
  const binaryPath = findBinary(configuredCommand);
1970
- const isWin = os9.platform() === "win32";
1970
+ const isWin = os10.platform() === "win32";
1971
1971
  const allArgs = [...spawnConfig.args, ...extraArgs];
1972
1972
  let shellCmd;
1973
1973
  let shellArgs;
1974
- const useShellUnix = !isWin && (!!spawnConfig.shell || !path10.isAbsolute(binaryPath) || isScriptBinary(binaryPath) || !looksLikeMachOOrElf(binaryPath));
1974
+ const useShellUnix = !isWin && (!!spawnConfig.shell || !path11.isAbsolute(binaryPath) || isScriptBinary(binaryPath) || !looksLikeMachOOrElf(binaryPath));
1975
1975
  const isCmdShim = isWin && /\.(cmd|bat)$/i.test(binaryPath);
1976
- const useShellWin = !!spawnConfig.shell || isCmdShim || !path10.isAbsolute(binaryPath) || isScriptBinary(binaryPath);
1976
+ const useShellWin = !!spawnConfig.shell || isCmdShim || !path11.isAbsolute(binaryPath) || isScriptBinary(binaryPath);
1977
1977
  const useShell = isWin ? useShellWin : useShellUnix;
1978
1978
  if (useShell) {
1979
1979
  shellCmd = isWin ? "cmd.exe" : process.env.SHELL || "/bin/zsh";
@@ -2049,12 +2049,12 @@ function respondToCliTerminalQueries(options) {
2049
2049
  }
2050
2050
  return "";
2051
2051
  }
2052
- var os9, path10, import_session_host_core2;
2052
+ var os10, path11, import_session_host_core2;
2053
2053
  var init_provider_cli_runtime = __esm({
2054
2054
  "src/cli-adapters/provider-cli-runtime.ts"() {
2055
2055
  "use strict";
2056
- os9 = __toESM(require("os"));
2057
- path10 = __toESM(require("path"));
2056
+ os10 = __toESM(require("os"));
2057
+ path11 = __toESM(require("path"));
2058
2058
  import_session_host_core2 = require("@adhdev/session-host-core");
2059
2059
  init_provider_cli_shared();
2060
2060
  }
@@ -2176,11 +2176,11 @@ function trimLastAssistantEchoForCliMessages(messages, prompt) {
2176
2176
  return;
2177
2177
  }
2178
2178
  }
2179
- var os10, COMMITTED_ACTIVITY_PREFIX_BLOCK_RE, ProviderCliAdapter;
2179
+ var os11, COMMITTED_ACTIVITY_PREFIX_BLOCK_RE, ProviderCliAdapter;
2180
2180
  var init_provider_cli_adapter = __esm({
2181
2181
  "src/cli-adapters/provider-cli-adapter.ts"() {
2182
2182
  "use strict";
2183
- os10 = __toESM(require("os"));
2183
+ os11 = __toESM(require("os"));
2184
2184
  init_logger();
2185
2185
  init_debug_config();
2186
2186
  init_terminal_screen();
@@ -2200,7 +2200,7 @@ var init_provider_cli_adapter = __esm({
2200
2200
  this.transportFactory = transportFactory;
2201
2201
  this.cliType = provider.type;
2202
2202
  this.cliName = provider.name;
2203
- this.workingDir = workingDir.startsWith("~") ? workingDir.replace(/^~/, os10.homedir()) : workingDir;
2203
+ this.workingDir = workingDir.startsWith("~") ? workingDir.replace(/^~/, os11.homedir()) : workingDir;
2204
2204
  const resolvedConfig = resolveCliAdapterConfig(provider);
2205
2205
  this.timeouts = resolvedConfig.timeouts;
2206
2206
  this.approvalKeys = resolvedConfig.approvalKeys;
@@ -5275,17 +5275,17 @@ function checkPathExists(paths) {
5275
5275
  return null;
5276
5276
  }
5277
5277
  async function detectIDEs(providerLoader) {
5278
- const os20 = (0, import_os2.platform)();
5278
+ const os21 = (0, import_os2.platform)();
5279
5279
  const results = [];
5280
5280
  for (const def of getMergedDefinitions()) {
5281
5281
  const cliPath = findCliCommand(providerLoader?.getIdeCliCommand(def.id, def.cli) || def.cli);
5282
- const appPath = checkPathExists(providerLoader?.getIdePathCandidates(def.id, def.paths[os20] || []) || []);
5282
+ const appPath = checkPathExists(providerLoader?.getIdePathCandidates(def.id, def.paths[os21] || []) || []);
5283
5283
  let resolvedCli = cliPath;
5284
- if (!resolvedCli && appPath && os20 === "darwin") {
5284
+ if (!resolvedCli && appPath && os21 === "darwin") {
5285
5285
  const bundledCli = `${appPath}/Contents/Resources/app/bin/${def.cli}`;
5286
5286
  if ((0, import_fs3.existsSync)(bundledCli)) resolvedCli = bundledCli;
5287
5287
  }
5288
- if (!resolvedCli && appPath && os20 === "win32") {
5288
+ if (!resolvedCli && appPath && os21 === "win32") {
5289
5289
  const { dirname: dirname7 } = await import("path");
5290
5290
  const appDir = dirname7(appPath);
5291
5291
  const candidates = [
@@ -5302,7 +5302,7 @@ async function detectIDEs(providerLoader) {
5302
5302
  }
5303
5303
  }
5304
5304
  }
5305
- const installed = os20 === "darwin" ? !!(resolvedCli || appPath) : !!resolvedCli;
5305
+ const installed = os21 === "darwin" ? !!(resolvedCli || appPath) : !!resolvedCli;
5306
5306
  const version = resolvedCli ? getIdeVersion(resolvedCli) : null;
5307
5307
  results.push({
5308
5308
  id: def.id,
@@ -10466,6 +10466,10 @@ function resolveLegacyProviderScript(fn, scriptName, params) {
10466
10466
  }
10467
10467
 
10468
10468
  // src/commands/chat-commands.ts
10469
+ var fs4 = __toESM(require("fs"));
10470
+ var os6 = __toESM(require("os"));
10471
+ var path8 = __toESM(require("path"));
10472
+ var import_node_crypto = require("crypto");
10469
10473
  init_contracts();
10470
10474
 
10471
10475
  // src/providers/provider-input-support.ts
@@ -11155,6 +11159,50 @@ function buildDebugBundleText(bundle) {
11155
11159
  "```"
11156
11160
  ].join("\n");
11157
11161
  }
11162
+ function getChatDebugBundleDir() {
11163
+ const override = typeof process.env.ADHDEV_DEBUG_BUNDLE_DIR === "string" ? process.env.ADHDEV_DEBUG_BUNDLE_DIR.trim() : "";
11164
+ return override || path8.join(os6.homedir(), ".adhdev", "debug-bundles", "chat");
11165
+ }
11166
+ function safeBundleIdSegment(value, fallback) {
11167
+ const normalized = String(value || fallback).trim().replace(/[^A-Za-z0-9_.-]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 80);
11168
+ return normalized || fallback;
11169
+ }
11170
+ function createChatDebugBundleId(targetSessionId) {
11171
+ const timestamp = (/* @__PURE__ */ new Date()).toISOString().replace(/[-:.]/g, "").replace("T", "T").replace("Z", "Z");
11172
+ const sessionSegment = safeBundleIdSegment(targetSessionId, "unknown-session");
11173
+ return `chat-debug-${timestamp}-${sessionSegment}-${(0, import_node_crypto.randomUUID)().slice(0, 8)}`;
11174
+ }
11175
+ function buildChatDebugBundleSummary(bundle) {
11176
+ const target = bundle.target && typeof bundle.target === "object" ? bundle.target : {};
11177
+ const readChat = bundle.readChat && typeof bundle.readChat === "object" ? bundle.readChat : {};
11178
+ const cli = bundle.cli && typeof bundle.cli === "object" ? bundle.cli : null;
11179
+ const frontend = bundle.frontend && typeof bundle.frontend === "object" ? bundle.frontend : null;
11180
+ return {
11181
+ createdAt: bundle.createdAt,
11182
+ targetSessionId: target.targetSessionId,
11183
+ providerType: target.providerType,
11184
+ transport: target.transport,
11185
+ readChatSuccess: readChat.success,
11186
+ readChatStatus: readChat.status,
11187
+ readChatTotalMessages: readChat.totalMessages,
11188
+ cliStatus: cli?.status,
11189
+ cliMessageCount: cli?.messageCount,
11190
+ hasFrontendSnapshot: !!frontend
11191
+ };
11192
+ }
11193
+ function storeChatDebugBundleOnDaemon(bundle, targetSessionId) {
11194
+ const bundleId = createChatDebugBundleId(targetSessionId);
11195
+ const dir = getChatDebugBundleDir();
11196
+ fs4.mkdirSync(dir, { recursive: true });
11197
+ const savedPath = path8.join(dir, `${bundleId}.json`);
11198
+ const json = `${JSON.stringify(bundle, null, 2)}
11199
+ `;
11200
+ fs4.writeFileSync(savedPath, json, { encoding: "utf8", mode: 384 });
11201
+ return { bundleId, savedPath, sizeBytes: Buffer.byteLength(json, "utf8") };
11202
+ }
11203
+ function isDaemonFileDebugDelivery(args) {
11204
+ return args?.delivery === "daemon_file" || args?.delivery === "file";
11205
+ }
11158
11206
  async function handleGetChatDebugBundle(h, args) {
11159
11207
  const targetSessionId = typeof args?.targetSessionId === "string" ? args.targetSessionId.trim() : "";
11160
11208
  if (!targetSessionId && !h.currentSession) {
@@ -11266,6 +11314,20 @@ async function handleGetChatDebugBundle(h, args) {
11266
11314
  recentDebugTrace: getRecentDebugTrace({ limit: 120 })
11267
11315
  };
11268
11316
  const bundle = sanitizeDebugBundleValue(rawBundle);
11317
+ if (isDaemonFileDebugDelivery(args)) {
11318
+ const summary = buildChatDebugBundleSummary(bundle);
11319
+ const stored = storeChatDebugBundleOnDaemon(bundle, targetSessionId || String(summary.targetSessionId || "unknown-session"));
11320
+ LOG.info("Command", `[get_chat_debug_bundle] saved daemon_file bundle id=${stored.bundleId} path=${stored.savedPath} sizeBytes=${stored.sizeBytes} targetSessionId=${summary.targetSessionId || ""} providerType=${summary.providerType || ""} transport=${summary.transport || ""}`);
11321
+ return {
11322
+ success: true,
11323
+ delivery: "daemon_file",
11324
+ bundleId: stored.bundleId,
11325
+ savedPath: stored.savedPath,
11326
+ sizeBytes: stored.sizeBytes,
11327
+ createdAt: bundle.createdAt,
11328
+ summary
11329
+ };
11330
+ }
11269
11331
  return {
11270
11332
  success: true,
11271
11333
  bundle,
@@ -12247,9 +12309,9 @@ async function handleResolveAction(h, args) {
12247
12309
  }
12248
12310
 
12249
12311
  // src/commands/cdp-commands.ts
12250
- var fs4 = __toESM(require("fs"));
12251
- var path8 = __toESM(require("path"));
12252
- var os6 = __toESM(require("os"));
12312
+ var fs5 = __toESM(require("fs"));
12313
+ var path9 = __toESM(require("path"));
12314
+ var os7 = __toESM(require("os"));
12253
12315
  var KEY_TO_VK = {
12254
12316
  Backspace: 8,
12255
12317
  Tab: 9,
@@ -12503,27 +12565,27 @@ function normalizeWindowsRequestedPath(requestedPath) {
12503
12565
  function resolveSafePath(requestedPath) {
12504
12566
  const rawPath = typeof requestedPath === "string" ? requestedPath.trim() : "";
12505
12567
  const inputPath = rawPath || ".";
12506
- const home = os6.homedir();
12568
+ const home = os7.homedir();
12507
12569
  if (inputPath.startsWith("~")) {
12508
- return path8.resolve(path8.join(home, inputPath.slice(1)));
12570
+ return path9.resolve(path9.join(home, inputPath.slice(1)));
12509
12571
  }
12510
12572
  if (process.platform === "win32") {
12511
12573
  const normalized = normalizeWindowsRequestedPath(inputPath);
12512
- if (path8.win32.isAbsolute(normalized)) {
12513
- return path8.win32.normalize(normalized);
12574
+ if (path9.win32.isAbsolute(normalized)) {
12575
+ return path9.win32.normalize(normalized);
12514
12576
  }
12515
- return path8.win32.resolve(normalized);
12577
+ return path9.win32.resolve(normalized);
12516
12578
  }
12517
- if (path8.isAbsolute(inputPath)) {
12518
- return path8.normalize(inputPath);
12579
+ if (path9.isAbsolute(inputPath)) {
12580
+ return path9.normalize(inputPath);
12519
12581
  }
12520
- return path8.resolve(inputPath);
12582
+ return path9.resolve(inputPath);
12521
12583
  }
12522
12584
  function listDirectoryEntriesSafe(dirPath) {
12523
- const entries = fs4.readdirSync(dirPath, { withFileTypes: true });
12585
+ const entries = fs5.readdirSync(dirPath, { withFileTypes: true });
12524
12586
  const files = [];
12525
12587
  for (const entry of entries) {
12526
- const entryPath = path8.join(dirPath, entry.name);
12588
+ const entryPath = path9.join(dirPath, entry.name);
12527
12589
  try {
12528
12590
  if (entry.isDirectory()) {
12529
12591
  files.push({ name: entry.name, type: "directory" });
@@ -12532,14 +12594,14 @@ function listDirectoryEntriesSafe(dirPath) {
12532
12594
  if (entry.isFile()) {
12533
12595
  let size;
12534
12596
  try {
12535
- size = fs4.statSync(entryPath).size;
12597
+ size = fs5.statSync(entryPath).size;
12536
12598
  } catch {
12537
12599
  size = void 0;
12538
12600
  }
12539
12601
  files.push({ name: entry.name, type: "file", size });
12540
12602
  continue;
12541
12603
  }
12542
- const stat = fs4.statSync(entryPath);
12604
+ const stat = fs5.statSync(entryPath);
12543
12605
  files.push({
12544
12606
  name: entry.name,
12545
12607
  type: stat.isDirectory() ? "directory" : "file",
@@ -12557,7 +12619,7 @@ function listWindowsDriveEntries(excludePath) {
12557
12619
  const letter = String.fromCharCode(code);
12558
12620
  const root = `${letter}:\\`;
12559
12621
  try {
12560
- if (!fs4.existsSync(root)) continue;
12622
+ if (!fs5.existsSync(root)) continue;
12561
12623
  if (excluded && root.toLowerCase() === excluded) continue;
12562
12624
  drives.push({ name: `${letter}:`, type: "directory", path: root });
12563
12625
  } catch {
@@ -12568,7 +12630,7 @@ function listWindowsDriveEntries(excludePath) {
12568
12630
  async function handleFileRead(h, args) {
12569
12631
  try {
12570
12632
  const filePath = resolveSafePath(args?.path);
12571
- const content = fs4.readFileSync(filePath, "utf-8");
12633
+ const content = fs5.readFileSync(filePath, "utf-8");
12572
12634
  return { success: true, content, path: filePath };
12573
12635
  } catch (e) {
12574
12636
  return { success: false, error: e.message };
@@ -12577,8 +12639,8 @@ async function handleFileRead(h, args) {
12577
12639
  async function handleFileWrite(h, args) {
12578
12640
  try {
12579
12641
  const filePath = resolveSafePath(args?.path);
12580
- fs4.mkdirSync(path8.dirname(filePath), { recursive: true });
12581
- fs4.writeFileSync(filePath, args?.content || "", "utf-8");
12642
+ fs5.mkdirSync(path9.dirname(filePath), { recursive: true });
12643
+ fs5.writeFileSync(filePath, args?.content || "", "utf-8");
12582
12644
  return { success: true, path: filePath };
12583
12645
  } catch (e) {
12584
12646
  return { success: false, error: e.message };
@@ -12811,12 +12873,13 @@ async function handleSetProviderSourceConfig(h, args) {
12811
12873
  });
12812
12874
  loader.reload();
12813
12875
  loader.registerToDetector();
12876
+ const refreshedInstances = h.ctx.instanceManager ? h.ctx.instanceManager.refreshProviderDefinitions((providerType) => loader.resolve(providerType)) : 0;
12814
12877
  await h.ctx.onProviderSourceConfigChanged?.();
12815
12878
  LOG.info(
12816
12879
  "Command",
12817
12880
  `[set_provider_source_config] mode=${sourceConfig.sourceMode} explicitProviderDir=${sourceConfig.explicitProviderDir || "-"} userDir=${sourceConfig.userDir}`
12818
12881
  );
12819
- return { success: true, reloaded: true, ...sourceConfig };
12882
+ return { success: true, reloaded: true, refreshedInstances, ...sourceConfig };
12820
12883
  }
12821
12884
  function normalizeProviderScriptArgs(args, scriptName) {
12822
12885
  const normalizedArgs = { ...args || {} };
@@ -13679,8 +13742,8 @@ var DaemonCommandHandler = class {
13679
13742
  };
13680
13743
 
13681
13744
  // src/commands/cli-manager.ts
13682
- var os12 = __toESM(require("os"));
13683
- var path12 = __toESM(require("path"));
13745
+ var os13 = __toESM(require("os"));
13746
+ var path13 = __toESM(require("path"));
13684
13747
  var crypto4 = __toESM(require("crypto"));
13685
13748
  var import_fs5 = require("fs");
13686
13749
  var import_child_process6 = require("child_process");
@@ -13689,10 +13752,10 @@ init_provider_cli_adapter();
13689
13752
  init_config();
13690
13753
 
13691
13754
  // src/providers/cli-provider-instance.ts
13692
- var os11 = __toESM(require("os"));
13693
- var path11 = __toESM(require("path"));
13755
+ var os12 = __toESM(require("os"));
13756
+ var path12 = __toESM(require("path"));
13694
13757
  var crypto3 = __toESM(require("crypto"));
13695
- var fs5 = __toESM(require("fs"));
13758
+ var fs6 = __toESM(require("fs"));
13696
13759
  var import_node_module = require("module");
13697
13760
  init_contracts();
13698
13761
  init_provider_cli_adapter();
@@ -13751,7 +13814,7 @@ function buildIncrementalHistoryAppendMessages(previousMessages, currentMessages
13751
13814
  var CachedDatabaseSync = null;
13752
13815
  function getDatabaseSync() {
13753
13816
  if (CachedDatabaseSync) return CachedDatabaseSync;
13754
- const requireFn = typeof require === "function" ? require : (0, import_node_module.createRequire)(path11.join(process.cwd(), "__adhdev_sqlite_loader__.js"));
13817
+ const requireFn = typeof require === "function" ? require : (0, import_node_module.createRequire)(path12.join(process.cwd(), "__adhdev_sqlite_loader__.js"));
13755
13818
  const sqliteModule = requireFn(`node:${"sqlite"}`);
13756
13819
  CachedDatabaseSync = sqliteModule.DatabaseSync;
13757
13820
  if (!CachedDatabaseSync) {
@@ -13901,10 +13964,10 @@ var CliProviderInstance = class {
13901
13964
  * Replaces the previously duplicated probeOpenCode/Codex/Goose functions.
13902
13965
  */
13903
13966
  probeSessionIdFromConfig(probe) {
13904
- const resolvedDbPath = probe.dbPath.replace(/^~/, os11.homedir());
13967
+ const resolvedDbPath = probe.dbPath.replace(/^~/, os12.homedir());
13905
13968
  const now = Date.now();
13906
13969
  if (this.cachedSqliteDbMissingUntil > now) return null;
13907
- if (!fs5.existsSync(resolvedDbPath)) {
13970
+ if (!fs6.existsSync(resolvedDbPath)) {
13908
13971
  this.cachedSqliteDbMissingUntil = now + 1e4;
13909
13972
  return null;
13910
13973
  }
@@ -14636,7 +14699,7 @@ ${effect.notification.body || ""}`.trim();
14636
14699
  };
14637
14700
  addDir(this.workingDir);
14638
14701
  try {
14639
- addDir(fs5.realpathSync.native(this.workingDir));
14702
+ addDir(fs6.realpathSync.native(this.workingDir));
14640
14703
  } catch {
14641
14704
  }
14642
14705
  return Array.from(dirs);
@@ -15835,11 +15898,11 @@ function shouldRestoreHostedRuntime(record, managerTag) {
15835
15898
  // src/commands/cli-manager.ts
15836
15899
  function isExplicitCommand(command) {
15837
15900
  const trimmed = command.trim();
15838
- return path12.isAbsolute(trimmed) || trimmed.includes("/") || trimmed.includes("\\") || trimmed.startsWith("~");
15901
+ return path13.isAbsolute(trimmed) || trimmed.includes("/") || trimmed.includes("\\") || trimmed.startsWith("~");
15839
15902
  }
15840
15903
  function expandExecutable(command) {
15841
15904
  const trimmed = command.trim();
15842
- return trimmed.startsWith("~") ? path12.join(os12.homedir(), trimmed.slice(1)) : trimmed;
15905
+ return trimmed.startsWith("~") ? path13.join(os13.homedir(), trimmed.slice(1)) : trimmed;
15843
15906
  }
15844
15907
  function commandExists(command) {
15845
15908
  const trimmed = command.trim();
@@ -16120,7 +16183,7 @@ var DaemonCliManager = class {
16120
16183
  async startSession(cliType, workingDir, cliArgs, initialModel, options) {
16121
16184
  const trimmed = (workingDir || "").trim();
16122
16185
  if (!trimmed) throw new Error("working directory required");
16123
- const resolvedDir = trimmed.startsWith("~") ? trimmed.replace(/^~/, os12.homedir()) : path12.resolve(trimmed);
16186
+ const resolvedDir = trimmed.startsWith("~") ? trimmed.replace(/^~/, os13.homedir()) : path13.resolve(trimmed);
16124
16187
  const normalizedType = this.providerLoader.resolveAlias(cliType);
16125
16188
  const rawProvider = this.providerLoader.getByAlias(cliType);
16126
16189
  const provider = rawProvider ? this.providerLoader.resolve(normalizedType) || rawProvider : void 0;
@@ -16620,13 +16683,13 @@ Run 'adhdev doctor' for detailed diagnostics.`
16620
16683
  // src/launch.ts
16621
16684
  var import_child_process7 = require("child_process");
16622
16685
  var net = __toESM(require("net"));
16623
- var os14 = __toESM(require("os"));
16624
- var path14 = __toESM(require("path"));
16686
+ var os15 = __toESM(require("os"));
16687
+ var path15 = __toESM(require("path"));
16625
16688
 
16626
16689
  // src/providers/provider-loader.ts
16627
- var fs6 = __toESM(require("fs"));
16628
- var path13 = __toESM(require("path"));
16629
- var os13 = __toESM(require("os"));
16690
+ var fs7 = __toESM(require("fs"));
16691
+ var path14 = __toESM(require("path"));
16692
+ var os14 = __toESM(require("os"));
16630
16693
  var chokidar = __toESM(require("chokidar"));
16631
16694
  init_logger();
16632
16695
 
@@ -16888,9 +16951,9 @@ var ProviderLoader = class _ProviderLoader {
16888
16951
  static siblingStderrLogged = /* @__PURE__ */ new Set();
16889
16952
  static looksLikeProviderRoot(candidate) {
16890
16953
  try {
16891
- if (!fs6.existsSync(candidate) || !fs6.statSync(candidate).isDirectory()) return false;
16954
+ if (!fs7.existsSync(candidate) || !fs7.statSync(candidate).isDirectory()) return false;
16892
16955
  return ["ide", "extension", "cli", "acp"].some(
16893
- (category) => fs6.existsSync(path13.join(candidate, category))
16956
+ (category) => fs7.existsSync(path14.join(candidate, category))
16894
16957
  );
16895
16958
  } catch {
16896
16959
  return false;
@@ -16898,20 +16961,20 @@ var ProviderLoader = class _ProviderLoader {
16898
16961
  }
16899
16962
  static hasProviderRootMarker(candidate) {
16900
16963
  try {
16901
- return fs6.existsSync(path13.join(candidate, _ProviderLoader.SIBLING_MARKER_FILE));
16964
+ return fs7.existsSync(path14.join(candidate, _ProviderLoader.SIBLING_MARKER_FILE));
16902
16965
  } catch {
16903
16966
  return false;
16904
16967
  }
16905
16968
  }
16906
16969
  detectDefaultUserDir() {
16907
- const fallback = path13.join(os13.homedir(), ".adhdev", "providers");
16970
+ const fallback = path14.join(os14.homedir(), ".adhdev", "providers");
16908
16971
  const envOptIn = process.env[_ProviderLoader.SIBLING_ENV_VAR] === "1";
16909
16972
  const visited = /* @__PURE__ */ new Set();
16910
16973
  for (const start of this.probeStarts) {
16911
- let current = path13.resolve(start);
16974
+ let current = path14.resolve(start);
16912
16975
  while (!visited.has(current)) {
16913
16976
  visited.add(current);
16914
- const siblingCandidate = path13.join(path13.dirname(current), _ProviderLoader.REPO_PROVIDER_DIRNAME);
16977
+ const siblingCandidate = path14.join(path14.dirname(current), _ProviderLoader.REPO_PROVIDER_DIRNAME);
16915
16978
  if (_ProviderLoader.looksLikeProviderRoot(siblingCandidate)) {
16916
16979
  const hasMarker = _ProviderLoader.hasProviderRootMarker(siblingCandidate);
16917
16980
  if (envOptIn || hasMarker) {
@@ -16933,7 +16996,7 @@ var ProviderLoader = class _ProviderLoader {
16933
16996
  return { path: siblingCandidate, source };
16934
16997
  }
16935
16998
  }
16936
- const parent = path13.dirname(current);
16999
+ const parent = path14.dirname(current);
16937
17000
  if (parent === current) break;
16938
17001
  current = parent;
16939
17002
  }
@@ -16943,11 +17006,11 @@ var ProviderLoader = class _ProviderLoader {
16943
17006
  constructor(options) {
16944
17007
  this.logFn = options?.logFn || LOG.forComponent("Provider").asLogFn();
16945
17008
  this.probeStarts = options?.probeStarts ?? [process.cwd(), __dirname];
16946
- this.defaultProvidersDir = path13.join(os13.homedir(), ".adhdev", "providers");
17009
+ this.defaultProvidersDir = path14.join(os14.homedir(), ".adhdev", "providers");
16947
17010
  const detected = this.detectDefaultUserDir();
16948
17011
  this.userDir = detected.path;
16949
17012
  this.userDirSource = detected.source;
16950
- this.upstreamDir = path13.join(this.defaultProvidersDir, ".upstream");
17013
+ this.upstreamDir = path14.join(this.defaultProvidersDir, ".upstream");
16951
17014
  this.disableUpstream = false;
16952
17015
  this.applySourceConfig({
16953
17016
  userDir: options?.userDir,
@@ -17006,7 +17069,7 @@ var ProviderLoader = class _ProviderLoader {
17006
17069
  this.userDir = detected.path;
17007
17070
  this.userDirSource = detected.source;
17008
17071
  }
17009
- this.upstreamDir = path13.join(this.defaultProvidersDir, ".upstream");
17072
+ this.upstreamDir = path14.join(this.defaultProvidersDir, ".upstream");
17010
17073
  this.disableUpstream = this.sourceMode === "no-upstream";
17011
17074
  if (this.explicitProviderDir) {
17012
17075
  this.log(`Config 'providerDir' applied: ${this.userDir}`);
@@ -17020,7 +17083,7 @@ var ProviderLoader = class _ProviderLoader {
17020
17083
  * Canonical provider directory shape for a given root.
17021
17084
  */
17022
17085
  getProviderDir(root, category, type) {
17023
- return path13.join(root, category, type);
17086
+ return path14.join(root, category, type);
17024
17087
  }
17025
17088
  /**
17026
17089
  * Canonical user override directory for a provider.
@@ -17047,7 +17110,7 @@ var ProviderLoader = class _ProviderLoader {
17047
17110
  resolveProviderFile(type, ...segments) {
17048
17111
  const dir = this.findProviderDirInternal(type);
17049
17112
  if (!dir) return null;
17050
- return path13.join(dir, ...segments);
17113
+ return path14.join(dir, ...segments);
17051
17114
  }
17052
17115
  /**
17053
17116
  * Load all providers (3-tier priority)
@@ -17060,7 +17123,7 @@ var ProviderLoader = class _ProviderLoader {
17060
17123
  this.providers.clear();
17061
17124
  this.providerAvailability.clear();
17062
17125
  let upstreamCount = 0;
17063
- if (!this.disableUpstream && fs6.existsSync(this.upstreamDir)) {
17126
+ if (!this.disableUpstream && fs7.existsSync(this.upstreamDir)) {
17064
17127
  upstreamCount = this.loadDir(this.upstreamDir);
17065
17128
  if (upstreamCount > 0) {
17066
17129
  this.log(`Loaded ${upstreamCount} upstream providers (auto-updated)`);
@@ -17068,7 +17131,7 @@ var ProviderLoader = class _ProviderLoader {
17068
17131
  } else if (this.disableUpstream) {
17069
17132
  this.log("Upstream loading disabled (sourceMode=no-upstream)");
17070
17133
  }
17071
- if (fs6.existsSync(this.userDir)) {
17134
+ if (fs7.existsSync(this.userDir)) {
17072
17135
  const userCount = this.loadDir(this.userDir, [".upstream"]);
17073
17136
  if (userCount > 0) {
17074
17137
  this.log(`Loaded ${userCount} user custom providers (never auto-updated)`);
@@ -17083,10 +17146,10 @@ var ProviderLoader = class _ProviderLoader {
17083
17146
  * Check if upstream directory exists and has providers.
17084
17147
  */
17085
17148
  hasUpstream() {
17086
- if (!fs6.existsSync(this.upstreamDir)) return false;
17149
+ if (!fs7.existsSync(this.upstreamDir)) return false;
17087
17150
  try {
17088
- return fs6.readdirSync(this.upstreamDir).some(
17089
- (d) => fs6.statSync(path13.join(this.upstreamDir, d)).isDirectory()
17151
+ return fs7.readdirSync(this.upstreamDir).some(
17152
+ (d) => fs7.statSync(path14.join(this.upstreamDir, d)).isDirectory()
17090
17153
  );
17091
17154
  } catch {
17092
17155
  return false;
@@ -17583,8 +17646,8 @@ var ProviderLoader = class _ProviderLoader {
17583
17646
  resolved._resolvedScriptDir = entry.scriptDir;
17584
17647
  resolved._resolvedScriptsSource = `compatibility:${entry.ideVersion}`;
17585
17648
  if (providerDir) {
17586
- const fullDir = path13.join(providerDir, entry.scriptDir);
17587
- resolved._resolvedScriptsPath = fs6.existsSync(path13.join(fullDir, "scripts.js")) ? path13.join(fullDir, "scripts.js") : fullDir;
17649
+ const fullDir = path14.join(providerDir, entry.scriptDir);
17650
+ resolved._resolvedScriptsPath = fs7.existsSync(path14.join(fullDir, "scripts.js")) ? path14.join(fullDir, "scripts.js") : fullDir;
17588
17651
  }
17589
17652
  matched = true;
17590
17653
  }
@@ -17599,8 +17662,8 @@ var ProviderLoader = class _ProviderLoader {
17599
17662
  resolved._resolvedScriptDir = base.defaultScriptDir;
17600
17663
  resolved._resolvedScriptsSource = "defaultScriptDir:version_miss";
17601
17664
  if (providerDir) {
17602
- const fullDir = path13.join(providerDir, base.defaultScriptDir);
17603
- resolved._resolvedScriptsPath = fs6.existsSync(path13.join(fullDir, "scripts.js")) ? path13.join(fullDir, "scripts.js") : fullDir;
17665
+ const fullDir = path14.join(providerDir, base.defaultScriptDir);
17666
+ resolved._resolvedScriptsPath = fs7.existsSync(path14.join(fullDir, "scripts.js")) ? path14.join(fullDir, "scripts.js") : fullDir;
17604
17667
  }
17605
17668
  }
17606
17669
  resolved._versionWarning = `Version ${currentVersion} not in compatibility matrix. Using default scripts.`;
@@ -17617,8 +17680,8 @@ var ProviderLoader = class _ProviderLoader {
17617
17680
  resolved._resolvedScriptDir = dirOverride;
17618
17681
  resolved._resolvedScriptsSource = `versions:${range}`;
17619
17682
  if (providerDir) {
17620
- const fullDir = path13.join(providerDir, dirOverride);
17621
- resolved._resolvedScriptsPath = fs6.existsSync(path13.join(fullDir, "scripts.js")) ? path13.join(fullDir, "scripts.js") : fullDir;
17683
+ const fullDir = path14.join(providerDir, dirOverride);
17684
+ resolved._resolvedScriptsPath = fs7.existsSync(path14.join(fullDir, "scripts.js")) ? path14.join(fullDir, "scripts.js") : fullDir;
17622
17685
  }
17623
17686
  }
17624
17687
  } else if (override.scripts) {
@@ -17634,8 +17697,8 @@ var ProviderLoader = class _ProviderLoader {
17634
17697
  resolved._resolvedScriptDir = base.defaultScriptDir;
17635
17698
  resolved._resolvedScriptsSource = "defaultScriptDir:no_version";
17636
17699
  if (providerDir) {
17637
- const fullDir = path13.join(providerDir, base.defaultScriptDir);
17638
- resolved._resolvedScriptsPath = fs6.existsSync(path13.join(fullDir, "scripts.js")) ? path13.join(fullDir, "scripts.js") : fullDir;
17700
+ const fullDir = path14.join(providerDir, base.defaultScriptDir);
17701
+ resolved._resolvedScriptsPath = fs7.existsSync(path14.join(fullDir, "scripts.js")) ? path14.join(fullDir, "scripts.js") : fullDir;
17639
17702
  }
17640
17703
  }
17641
17704
  }
@@ -17667,15 +17730,15 @@ var ProviderLoader = class _ProviderLoader {
17667
17730
  this.log(` [loadScriptsFromDir] ${type}: providerDir not found`);
17668
17731
  return null;
17669
17732
  }
17670
- const dir = path13.join(providerDir, scriptDir);
17671
- if (!fs6.existsSync(dir)) {
17733
+ const dir = path14.join(providerDir, scriptDir);
17734
+ if (!fs7.existsSync(dir)) {
17672
17735
  this.log(` [loadScriptsFromDir] ${type}: dir not found: ${dir}`);
17673
17736
  return null;
17674
17737
  }
17675
17738
  const cached = this.scriptsCache.get(dir);
17676
17739
  if (cached) return cached;
17677
- const scriptsJs = path13.join(dir, "scripts.js");
17678
- if (fs6.existsSync(scriptsJs)) {
17740
+ const scriptsJs = path14.join(dir, "scripts.js");
17741
+ if (fs7.existsSync(scriptsJs)) {
17679
17742
  try {
17680
17743
  delete require.cache[require.resolve(scriptsJs)];
17681
17744
  const loaded = require(scriptsJs);
@@ -17696,9 +17759,9 @@ var ProviderLoader = class _ProviderLoader {
17696
17759
  watch() {
17697
17760
  this.stopWatch();
17698
17761
  const watchDir = (dir) => {
17699
- if (!fs6.existsSync(dir)) {
17762
+ if (!fs7.existsSync(dir)) {
17700
17763
  try {
17701
- fs6.mkdirSync(dir, { recursive: true });
17764
+ fs7.mkdirSync(dir, { recursive: true });
17702
17765
  } catch {
17703
17766
  return;
17704
17767
  }
@@ -17716,7 +17779,7 @@ var ProviderLoader = class _ProviderLoader {
17716
17779
  return;
17717
17780
  }
17718
17781
  if (filePath.endsWith(".js") || filePath.endsWith(".json")) {
17719
- this.log(`File changed: ${path13.basename(filePath)}, reloading...`);
17782
+ this.log(`File changed: ${path14.basename(filePath)}, reloading...`);
17720
17783
  this.reload();
17721
17784
  }
17722
17785
  };
@@ -17771,12 +17834,12 @@ var ProviderLoader = class _ProviderLoader {
17771
17834
  }
17772
17835
  const https = require("https");
17773
17836
  const { execSync: execSync7 } = require("child_process");
17774
- const metaPath = path13.join(this.upstreamDir, _ProviderLoader.META_FILE);
17837
+ const metaPath = path14.join(this.upstreamDir, _ProviderLoader.META_FILE);
17775
17838
  let prevEtag = "";
17776
17839
  let prevTimestamp = 0;
17777
17840
  try {
17778
- if (fs6.existsSync(metaPath)) {
17779
- const meta = JSON.parse(fs6.readFileSync(metaPath, "utf-8"));
17841
+ if (fs7.existsSync(metaPath)) {
17842
+ const meta = JSON.parse(fs7.readFileSync(metaPath, "utf-8"));
17780
17843
  prevEtag = meta.etag || "";
17781
17844
  prevTimestamp = meta.timestamp || 0;
17782
17845
  }
@@ -17831,39 +17894,39 @@ var ProviderLoader = class _ProviderLoader {
17831
17894
  return { updated: false };
17832
17895
  }
17833
17896
  this.log("Downloading latest providers from GitHub...");
17834
- const tmpTar = path13.join(os13.tmpdir(), `adhdev-providers-${Date.now()}.tar.gz`);
17835
- const tmpExtract = path13.join(os13.tmpdir(), `adhdev-providers-extract-${Date.now()}`);
17897
+ const tmpTar = path14.join(os14.tmpdir(), `adhdev-providers-${Date.now()}.tar.gz`);
17898
+ const tmpExtract = path14.join(os14.tmpdir(), `adhdev-providers-extract-${Date.now()}`);
17836
17899
  await this.downloadFile(_ProviderLoader.GITHUB_TARBALL_URL, tmpTar);
17837
- fs6.mkdirSync(tmpExtract, { recursive: true });
17900
+ fs7.mkdirSync(tmpExtract, { recursive: true });
17838
17901
  execSync7(`tar -xzf "${tmpTar}" -C "${tmpExtract}"`, { timeout: 3e4 });
17839
- const extracted = fs6.readdirSync(tmpExtract);
17902
+ const extracted = fs7.readdirSync(tmpExtract);
17840
17903
  const rootDir = extracted.find(
17841
- (d) => fs6.statSync(path13.join(tmpExtract, d)).isDirectory() && d.startsWith("adhdev-providers")
17904
+ (d) => fs7.statSync(path14.join(tmpExtract, d)).isDirectory() && d.startsWith("adhdev-providers")
17842
17905
  );
17843
17906
  if (!rootDir) throw new Error("Unexpected tarball structure");
17844
- const sourceDir = path13.join(tmpExtract, rootDir);
17907
+ const sourceDir = path14.join(tmpExtract, rootDir);
17845
17908
  const backupDir = this.upstreamDir + ".bak";
17846
- if (fs6.existsSync(this.upstreamDir)) {
17847
- if (fs6.existsSync(backupDir)) fs6.rmSync(backupDir, { recursive: true, force: true });
17848
- fs6.renameSync(this.upstreamDir, backupDir);
17909
+ if (fs7.existsSync(this.upstreamDir)) {
17910
+ if (fs7.existsSync(backupDir)) fs7.rmSync(backupDir, { recursive: true, force: true });
17911
+ fs7.renameSync(this.upstreamDir, backupDir);
17849
17912
  }
17850
17913
  try {
17851
17914
  this.copyDirRecursive(sourceDir, this.upstreamDir);
17852
17915
  this.writeMeta(metaPath, etag || `ts-${Date.now()}`, Date.now());
17853
- if (fs6.existsSync(backupDir)) fs6.rmSync(backupDir, { recursive: true, force: true });
17916
+ if (fs7.existsSync(backupDir)) fs7.rmSync(backupDir, { recursive: true, force: true });
17854
17917
  } catch (e) {
17855
- if (fs6.existsSync(backupDir)) {
17856
- if (fs6.existsSync(this.upstreamDir)) fs6.rmSync(this.upstreamDir, { recursive: true, force: true });
17857
- fs6.renameSync(backupDir, this.upstreamDir);
17918
+ if (fs7.existsSync(backupDir)) {
17919
+ if (fs7.existsSync(this.upstreamDir)) fs7.rmSync(this.upstreamDir, { recursive: true, force: true });
17920
+ fs7.renameSync(backupDir, this.upstreamDir);
17858
17921
  }
17859
17922
  throw e;
17860
17923
  }
17861
17924
  try {
17862
- fs6.rmSync(tmpTar, { force: true });
17925
+ fs7.rmSync(tmpTar, { force: true });
17863
17926
  } catch {
17864
17927
  }
17865
17928
  try {
17866
- fs6.rmSync(tmpExtract, { recursive: true, force: true });
17929
+ fs7.rmSync(tmpExtract, { recursive: true, force: true });
17867
17930
  } catch {
17868
17931
  }
17869
17932
  const upstreamCount = this.countProviders(this.upstreamDir);
@@ -17895,7 +17958,7 @@ var ProviderLoader = class _ProviderLoader {
17895
17958
  reject(new Error(`HTTP ${res.statusCode}`));
17896
17959
  return;
17897
17960
  }
17898
- const ws = fs6.createWriteStream(destPath);
17961
+ const ws = fs7.createWriteStream(destPath);
17899
17962
  res.pipe(ws);
17900
17963
  ws.on("finish", () => {
17901
17964
  ws.close();
@@ -17914,22 +17977,22 @@ var ProviderLoader = class _ProviderLoader {
17914
17977
  }
17915
17978
  /** Recursive directory copy */
17916
17979
  copyDirRecursive(src, dest) {
17917
- fs6.mkdirSync(dest, { recursive: true });
17918
- for (const entry of fs6.readdirSync(src, { withFileTypes: true })) {
17919
- const srcPath = path13.join(src, entry.name);
17920
- const destPath = path13.join(dest, entry.name);
17980
+ fs7.mkdirSync(dest, { recursive: true });
17981
+ for (const entry of fs7.readdirSync(src, { withFileTypes: true })) {
17982
+ const srcPath = path14.join(src, entry.name);
17983
+ const destPath = path14.join(dest, entry.name);
17921
17984
  if (entry.isDirectory()) {
17922
17985
  this.copyDirRecursive(srcPath, destPath);
17923
17986
  } else {
17924
- fs6.copyFileSync(srcPath, destPath);
17987
+ fs7.copyFileSync(srcPath, destPath);
17925
17988
  }
17926
17989
  }
17927
17990
  }
17928
17991
  /** .meta.json save */
17929
17992
  writeMeta(metaPath, etag, timestamp) {
17930
17993
  try {
17931
- fs6.mkdirSync(path13.dirname(metaPath), { recursive: true });
17932
- fs6.writeFileSync(metaPath, JSON.stringify({
17994
+ fs7.mkdirSync(path14.dirname(metaPath), { recursive: true });
17995
+ fs7.writeFileSync(metaPath, JSON.stringify({
17933
17996
  etag,
17934
17997
  timestamp,
17935
17998
  lastCheck: new Date(timestamp).toISOString(),
@@ -17940,12 +18003,12 @@ var ProviderLoader = class _ProviderLoader {
17940
18003
  }
17941
18004
  /** Count provider files (provider.js or provider.json) */
17942
18005
  countProviders(dir) {
17943
- if (!fs6.existsSync(dir)) return 0;
18006
+ if (!fs7.existsSync(dir)) return 0;
17944
18007
  let count = 0;
17945
18008
  const scan = (d) => {
17946
18009
  try {
17947
- for (const entry of fs6.readdirSync(d, { withFileTypes: true })) {
17948
- if (entry.isDirectory()) scan(path13.join(d, entry.name));
18010
+ for (const entry of fs7.readdirSync(d, { withFileTypes: true })) {
18011
+ if (entry.isDirectory()) scan(path14.join(d, entry.name));
17949
18012
  else if (entry.name === "provider.json") count++;
17950
18013
  }
17951
18014
  } catch {
@@ -18171,19 +18234,19 @@ var ProviderLoader = class _ProviderLoader {
18171
18234
  const cat = provider.category;
18172
18235
  const searchRoots = this.getProviderRoots();
18173
18236
  for (const root of searchRoots) {
18174
- if (!fs6.existsSync(root)) continue;
18237
+ if (!fs7.existsSync(root)) continue;
18175
18238
  const candidate = this.getProviderDir(root, cat, type);
18176
- if (fs6.existsSync(path13.join(candidate, "provider.json"))) return candidate;
18177
- const catDir = path13.join(root, cat);
18178
- if (fs6.existsSync(catDir)) {
18239
+ if (fs7.existsSync(path14.join(candidate, "provider.json"))) return candidate;
18240
+ const catDir = path14.join(root, cat);
18241
+ if (fs7.existsSync(catDir)) {
18179
18242
  try {
18180
- for (const entry of fs6.readdirSync(catDir, { withFileTypes: true })) {
18243
+ for (const entry of fs7.readdirSync(catDir, { withFileTypes: true })) {
18181
18244
  if (!entry.isDirectory()) continue;
18182
- const jsonPath = path13.join(catDir, entry.name, "provider.json");
18183
- if (fs6.existsSync(jsonPath)) {
18245
+ const jsonPath = path14.join(catDir, entry.name, "provider.json");
18246
+ if (fs7.existsSync(jsonPath)) {
18184
18247
  try {
18185
- const data = JSON.parse(fs6.readFileSync(jsonPath, "utf-8"));
18186
- if (data.type === type) return path13.join(catDir, entry.name);
18248
+ const data = JSON.parse(fs7.readFileSync(jsonPath, "utf-8"));
18249
+ if (data.type === type) return path14.join(catDir, entry.name);
18187
18250
  } catch {
18188
18251
  }
18189
18252
  }
@@ -18200,8 +18263,8 @@ var ProviderLoader = class _ProviderLoader {
18200
18263
  * (template substitution is NOT applied here — scripts.js handles that)
18201
18264
  */
18202
18265
  buildScriptWrappersFromDir(dir) {
18203
- const scriptsJs = path13.join(dir, "scripts.js");
18204
- if (fs6.existsSync(scriptsJs)) {
18266
+ const scriptsJs = path14.join(dir, "scripts.js");
18267
+ if (fs7.existsSync(scriptsJs)) {
18205
18268
  try {
18206
18269
  delete require.cache[require.resolve(scriptsJs)];
18207
18270
  return require(scriptsJs);
@@ -18211,13 +18274,13 @@ var ProviderLoader = class _ProviderLoader {
18211
18274
  const toCamel = (name) => name.replace(/_([a-z])/g, (_, c) => c.toUpperCase());
18212
18275
  const result = {};
18213
18276
  try {
18214
- for (const file of fs6.readdirSync(dir)) {
18277
+ for (const file of fs7.readdirSync(dir)) {
18215
18278
  if (!file.endsWith(".js")) continue;
18216
18279
  const scriptName = toCamel(file.replace(".js", ""));
18217
- const filePath = path13.join(dir, file);
18280
+ const filePath = path14.join(dir, file);
18218
18281
  result[scriptName] = (...args) => {
18219
18282
  try {
18220
- let content = fs6.readFileSync(filePath, "utf-8");
18283
+ let content = fs7.readFileSync(filePath, "utf-8");
18221
18284
  if (args[0] && typeof args[0] === "object") {
18222
18285
  for (const [key, val] of Object.entries(args[0])) {
18223
18286
  let v = val;
@@ -18263,20 +18326,20 @@ var ProviderLoader = class _ProviderLoader {
18263
18326
  * Structure: dir/category/agent-name/provider.{json,js}
18264
18327
  */
18265
18328
  loadDir(dir, excludeDirs) {
18266
- if (!fs6.existsSync(dir)) return 0;
18329
+ if (!fs7.existsSync(dir)) return 0;
18267
18330
  let count = 0;
18268
18331
  const scan = (d) => {
18269
18332
  let entries;
18270
18333
  try {
18271
- entries = fs6.readdirSync(d, { withFileTypes: true });
18334
+ entries = fs7.readdirSync(d, { withFileTypes: true });
18272
18335
  } catch {
18273
18336
  return;
18274
18337
  }
18275
18338
  const hasJson = entries.some((e) => e.name === "provider.json");
18276
18339
  if (hasJson) {
18277
- const jsonPath = path13.join(d, "provider.json");
18340
+ const jsonPath = path14.join(d, "provider.json");
18278
18341
  try {
18279
- const raw = fs6.readFileSync(jsonPath, "utf-8");
18342
+ const raw = fs7.readFileSync(jsonPath, "utf-8");
18280
18343
  const mod = JSON.parse(raw);
18281
18344
  if (typeof mod.extensionIdPattern === "string") {
18282
18345
  const flags = mod.extensionIdPattern_flags || "";
@@ -18295,8 +18358,8 @@ var ProviderLoader = class _ProviderLoader {
18295
18358
  this.log(`\u26A0 Invalid provider at ${jsonPath}: ${validation.errors.join("; ")}`);
18296
18359
  } else {
18297
18360
  const hasCompatibility = Array.isArray(normalizedProvider.compatibility);
18298
- const scriptsPath = path13.join(d, "scripts.js");
18299
- if (!hasCompatibility && fs6.existsSync(scriptsPath)) {
18361
+ const scriptsPath = path14.join(d, "scripts.js");
18362
+ if (!hasCompatibility && fs7.existsSync(scriptsPath)) {
18300
18363
  try {
18301
18364
  delete require.cache[require.resolve(scriptsPath)];
18302
18365
  const scripts = require(scriptsPath);
@@ -18321,7 +18384,7 @@ var ProviderLoader = class _ProviderLoader {
18321
18384
  if (!entry.isDirectory()) continue;
18322
18385
  if (entry.name.startsWith("_") || entry.name.startsWith(".")) continue;
18323
18386
  if (excludeDirs && d === dir && excludeDirs.includes(entry.name)) continue;
18324
- scan(path13.join(d, entry.name));
18387
+ scan(path14.join(d, entry.name));
18325
18388
  }
18326
18389
  }
18327
18390
  };
@@ -18511,7 +18574,7 @@ async function isCdpActive(port) {
18511
18574
  });
18512
18575
  }
18513
18576
  async function killIdeProcess(ideId) {
18514
- const plat = os14.platform();
18577
+ const plat = os15.platform();
18515
18578
  const appName = getMacAppIdentifiers()[ideId];
18516
18579
  const winProcesses = getWinProcessNames()[ideId];
18517
18580
  try {
@@ -18572,7 +18635,7 @@ async function killIdeProcess(ideId) {
18572
18635
  }
18573
18636
  }
18574
18637
  function isIdeRunning(ideId) {
18575
- const plat = os14.platform();
18638
+ const plat = os15.platform();
18576
18639
  try {
18577
18640
  if (plat === "darwin") {
18578
18641
  const appName = getMacAppIdentifiers()[ideId];
@@ -18627,7 +18690,7 @@ function isIdeRunning(ideId) {
18627
18690
  }
18628
18691
  }
18629
18692
  function detectCurrentWorkspace(ideId) {
18630
- const plat = os14.platform();
18693
+ const plat = os15.platform();
18631
18694
  if (plat === "darwin") {
18632
18695
  try {
18633
18696
  const appName = getMacAppIdentifiers()[ideId];
@@ -18642,17 +18705,17 @@ function detectCurrentWorkspace(ideId) {
18642
18705
  }
18643
18706
  } else if (plat === "win32") {
18644
18707
  try {
18645
- const fs15 = require("fs");
18708
+ const fs16 = require("fs");
18646
18709
  const appNameMap = getMacAppIdentifiers();
18647
18710
  const appName = appNameMap[ideId];
18648
18711
  if (appName) {
18649
- const storagePath = path14.join(
18650
- process.env.APPDATA || path14.join(os14.homedir(), "AppData", "Roaming"),
18712
+ const storagePath = path15.join(
18713
+ process.env.APPDATA || path15.join(os15.homedir(), "AppData", "Roaming"),
18651
18714
  appName,
18652
18715
  "storage.json"
18653
18716
  );
18654
- if (fs15.existsSync(storagePath)) {
18655
- const data = JSON.parse(fs15.readFileSync(storagePath, "utf-8"));
18717
+ if (fs16.existsSync(storagePath)) {
18718
+ const data = JSON.parse(fs16.readFileSync(storagePath, "utf-8"));
18656
18719
  const workspaces = data?.openedPathsList?.workspaces3 || data?.openedPathsList?.entries || [];
18657
18720
  if (workspaces.length > 0) {
18658
18721
  const recent = workspaces[0];
@@ -18669,7 +18732,7 @@ function detectCurrentWorkspace(ideId) {
18669
18732
  return void 0;
18670
18733
  }
18671
18734
  async function launchWithCdp(options = {}) {
18672
- const platform10 = os14.platform();
18735
+ const platform10 = os15.platform();
18673
18736
  let targetIde;
18674
18737
  const ides = await detectIDEs(getProviderLoader());
18675
18738
  if (options.ideId) {
@@ -18824,14 +18887,14 @@ init_config();
18824
18887
  init_logger();
18825
18888
 
18826
18889
  // src/logging/command-log.ts
18827
- var fs7 = __toESM(require("fs"));
18828
- var path15 = __toESM(require("path"));
18829
- var os15 = __toESM(require("os"));
18830
- var LOG_DIR2 = process.platform === "win32" ? path15.join(process.env.LOCALAPPDATA || process.env.APPDATA || path15.join(os15.homedir(), "AppData", "Local"), "adhdev", "logs") : process.platform === "darwin" ? path15.join(os15.homedir(), "Library", "Logs", "adhdev") : path15.join(os15.homedir(), ".local", "share", "adhdev", "logs");
18890
+ var fs8 = __toESM(require("fs"));
18891
+ var path16 = __toESM(require("path"));
18892
+ var os16 = __toESM(require("os"));
18893
+ var LOG_DIR2 = process.platform === "win32" ? path16.join(process.env.LOCALAPPDATA || process.env.APPDATA || path16.join(os16.homedir(), "AppData", "Local"), "adhdev", "logs") : process.platform === "darwin" ? path16.join(os16.homedir(), "Library", "Logs", "adhdev") : path16.join(os16.homedir(), ".local", "share", "adhdev", "logs");
18831
18894
  var MAX_FILE_SIZE = 5 * 1024 * 1024;
18832
18895
  var MAX_DAYS = 7;
18833
18896
  try {
18834
- fs7.mkdirSync(LOG_DIR2, { recursive: true });
18897
+ fs8.mkdirSync(LOG_DIR2, { recursive: true });
18835
18898
  } catch {
18836
18899
  }
18837
18900
  var SENSITIVE_KEYS = /* @__PURE__ */ new Set([
@@ -18865,19 +18928,19 @@ function getDateStr2() {
18865
18928
  return (/* @__PURE__ */ new Date()).toISOString().slice(0, 10);
18866
18929
  }
18867
18930
  var currentDate2 = getDateStr2();
18868
- var currentFile = path15.join(LOG_DIR2, `commands-${currentDate2}.jsonl`);
18931
+ var currentFile = path16.join(LOG_DIR2, `commands-${currentDate2}.jsonl`);
18869
18932
  var writeCount2 = 0;
18870
18933
  function checkRotation() {
18871
18934
  const today = getDateStr2();
18872
18935
  if (today !== currentDate2) {
18873
18936
  currentDate2 = today;
18874
- currentFile = path15.join(LOG_DIR2, `commands-${currentDate2}.jsonl`);
18937
+ currentFile = path16.join(LOG_DIR2, `commands-${currentDate2}.jsonl`);
18875
18938
  cleanOldFiles();
18876
18939
  }
18877
18940
  }
18878
18941
  function cleanOldFiles() {
18879
18942
  try {
18880
- const files = fs7.readdirSync(LOG_DIR2).filter((f) => f.startsWith("commands-") && f.endsWith(".jsonl"));
18943
+ const files = fs8.readdirSync(LOG_DIR2).filter((f) => f.startsWith("commands-") && f.endsWith(".jsonl"));
18881
18944
  const cutoff = /* @__PURE__ */ new Date();
18882
18945
  cutoff.setDate(cutoff.getDate() - MAX_DAYS);
18883
18946
  const cutoffStr = cutoff.toISOString().slice(0, 10);
@@ -18885,7 +18948,7 @@ function cleanOldFiles() {
18885
18948
  const dateMatch = file.match(/commands-(\d{4}-\d{2}-\d{2})/);
18886
18949
  if (dateMatch && dateMatch[1] < cutoffStr) {
18887
18950
  try {
18888
- fs7.unlinkSync(path15.join(LOG_DIR2, file));
18951
+ fs8.unlinkSync(path16.join(LOG_DIR2, file));
18889
18952
  } catch {
18890
18953
  }
18891
18954
  }
@@ -18895,14 +18958,14 @@ function cleanOldFiles() {
18895
18958
  }
18896
18959
  function checkSize() {
18897
18960
  try {
18898
- const stat = fs7.statSync(currentFile);
18961
+ const stat = fs8.statSync(currentFile);
18899
18962
  if (stat.size > MAX_FILE_SIZE) {
18900
18963
  const backup = currentFile.replace(".jsonl", ".1.jsonl");
18901
18964
  try {
18902
- fs7.unlinkSync(backup);
18965
+ fs8.unlinkSync(backup);
18903
18966
  } catch {
18904
18967
  }
18905
- fs7.renameSync(currentFile, backup);
18968
+ fs8.renameSync(currentFile, backup);
18906
18969
  }
18907
18970
  } catch {
18908
18971
  }
@@ -18935,14 +18998,14 @@ function logCommand(entry) {
18935
18998
  ...entry.error ? { err: entry.error } : {},
18936
18999
  ...entry.durationMs !== void 0 ? { ms: entry.durationMs } : {}
18937
19000
  });
18938
- fs7.appendFileSync(currentFile, line + "\n");
19001
+ fs8.appendFileSync(currentFile, line + "\n");
18939
19002
  } catch {
18940
19003
  }
18941
19004
  }
18942
19005
  function getRecentCommands(count = 50) {
18943
19006
  try {
18944
- if (!fs7.existsSync(currentFile)) return [];
18945
- const content = fs7.readFileSync(currentFile, "utf-8");
19007
+ if (!fs8.existsSync(currentFile)) return [];
19008
+ const content = fs8.readFileSync(currentFile, "utf-8");
18946
19009
  const lines = content.trim().split("\n").filter(Boolean);
18947
19010
  return lines.slice(-count).map((line) => {
18948
19011
  try {
@@ -18971,7 +19034,7 @@ cleanOldFiles();
18971
19034
  init_logger();
18972
19035
 
18973
19036
  // src/status/snapshot.ts
18974
- var os16 = __toESM(require("os"));
19037
+ var os17 = __toESM(require("os"));
18975
19038
  init_config();
18976
19039
  init_terminal_screen();
18977
19040
  init_logger();
@@ -19026,8 +19089,8 @@ function buildAvailableProviders(providerLoader) {
19026
19089
  }
19027
19090
  function buildMachineInfo(profile = "full") {
19028
19091
  const base = {
19029
- hostname: os16.hostname(),
19030
- platform: os16.platform()
19092
+ hostname: os17.hostname(),
19093
+ platform: os17.platform()
19031
19094
  };
19032
19095
  if (profile === "live") {
19033
19096
  return base;
@@ -19036,23 +19099,23 @@ function buildMachineInfo(profile = "full") {
19036
19099
  const memSnap2 = getHostMemorySnapshot();
19037
19100
  return {
19038
19101
  ...base,
19039
- arch: os16.arch(),
19040
- cpus: os16.cpus().length,
19102
+ arch: os17.arch(),
19103
+ cpus: os17.cpus().length,
19041
19104
  totalMem: memSnap2.totalMem,
19042
- release: os16.release()
19105
+ release: os17.release()
19043
19106
  };
19044
19107
  }
19045
19108
  const memSnap = getHostMemorySnapshot();
19046
19109
  return {
19047
19110
  ...base,
19048
- arch: os16.arch(),
19049
- cpus: os16.cpus().length,
19111
+ arch: os17.arch(),
19112
+ cpus: os17.cpus().length,
19050
19113
  totalMem: memSnap.totalMem,
19051
19114
  freeMem: memSnap.freeMem,
19052
19115
  availableMem: memSnap.availableMem,
19053
- loadavg: os16.loadavg(),
19054
- uptime: os16.uptime(),
19055
- release: os16.release()
19116
+ loadavg: os17.loadavg(),
19117
+ uptime: os17.uptime(),
19118
+ release: os17.release()
19056
19119
  };
19057
19120
  }
19058
19121
  function parseMessageTime(value) {
@@ -19279,42 +19342,42 @@ function buildStatusSnapshot(options) {
19279
19342
  // src/commands/upgrade-helper.ts
19280
19343
  var import_child_process8 = require("child_process");
19281
19344
  var import_child_process9 = require("child_process");
19282
- var fs8 = __toESM(require("fs"));
19283
- var os17 = __toESM(require("os"));
19284
- var path16 = __toESM(require("path"));
19345
+ var fs9 = __toESM(require("fs"));
19346
+ var os18 = __toESM(require("os"));
19347
+ var path17 = __toESM(require("path"));
19285
19348
  var UPGRADE_HELPER_ENV = "ADHDEV_DAEMON_UPGRADE_HELPER";
19286
19349
  function getUpgradeLogPath() {
19287
- const home = os17.homedir();
19288
- const dir = path16.join(home, ".adhdev");
19289
- fs8.mkdirSync(dir, { recursive: true });
19290
- return path16.join(dir, "daemon-upgrade.log");
19350
+ const home = os18.homedir();
19351
+ const dir = path17.join(home, ".adhdev");
19352
+ fs9.mkdirSync(dir, { recursive: true });
19353
+ return path17.join(dir, "daemon-upgrade.log");
19291
19354
  }
19292
19355
  function appendUpgradeLog(message) {
19293
19356
  const line = `[${(/* @__PURE__ */ new Date()).toISOString()}] ${message}
19294
19357
  `;
19295
19358
  try {
19296
- fs8.appendFileSync(getUpgradeLogPath(), line, "utf8");
19359
+ fs9.appendFileSync(getUpgradeLogPath(), line, "utf8");
19297
19360
  } catch {
19298
19361
  }
19299
19362
  }
19300
19363
  function resolveSiblingNpmInvocation(nodeExecutable, platform10 = process.platform) {
19301
- const binDir = path16.dirname(nodeExecutable);
19364
+ const binDir = path17.dirname(nodeExecutable);
19302
19365
  if (platform10 === "win32") {
19303
- const npmCliPath = path16.join(binDir, "node_modules", "npm", "bin", "npm-cli.js");
19304
- if (fs8.existsSync(npmCliPath)) {
19366
+ const npmCliPath = path17.join(binDir, "node_modules", "npm", "bin", "npm-cli.js");
19367
+ if (fs9.existsSync(npmCliPath)) {
19305
19368
  return { executable: nodeExecutable, argsPrefix: [npmCliPath], execOptions: getNpmExecOptions(platform10) };
19306
19369
  }
19307
19370
  for (const candidate of ["npm.exe", "npm"]) {
19308
- const candidatePath = path16.join(binDir, candidate);
19309
- if (fs8.existsSync(candidatePath)) {
19371
+ const candidatePath = path17.join(binDir, candidate);
19372
+ if (fs9.existsSync(candidatePath)) {
19310
19373
  return { executable: candidatePath, argsPrefix: [], execOptions: getNpmExecOptions(platform10) };
19311
19374
  }
19312
19375
  }
19313
19376
  return { executable: nodeExecutable, argsPrefix: [npmCliPath], execOptions: getNpmExecOptions(platform10) };
19314
19377
  }
19315
19378
  for (const candidate of ["npm"]) {
19316
- const candidatePath = path16.join(binDir, candidate);
19317
- if (fs8.existsSync(candidatePath)) {
19379
+ const candidatePath = path17.join(binDir, candidate);
19380
+ if (fs9.existsSync(candidatePath)) {
19318
19381
  return { executable: candidatePath, argsPrefix: [], execOptions: getNpmExecOptions(platform10) };
19319
19382
  }
19320
19383
  }
@@ -19324,22 +19387,22 @@ function findCurrentPackageRoot(currentCliPath, packageName) {
19324
19387
  if (!currentCliPath) return null;
19325
19388
  let resolvedPath = currentCliPath;
19326
19389
  try {
19327
- resolvedPath = fs8.realpathSync.native(currentCliPath);
19390
+ resolvedPath = fs9.realpathSync.native(currentCliPath);
19328
19391
  } catch {
19329
19392
  }
19330
19393
  let currentDir = resolvedPath;
19331
19394
  try {
19332
- if (fs8.statSync(resolvedPath).isFile()) {
19333
- currentDir = path16.dirname(resolvedPath);
19395
+ if (fs9.statSync(resolvedPath).isFile()) {
19396
+ currentDir = path17.dirname(resolvedPath);
19334
19397
  }
19335
19398
  } catch {
19336
- currentDir = path16.dirname(resolvedPath);
19399
+ currentDir = path17.dirname(resolvedPath);
19337
19400
  }
19338
19401
  while (true) {
19339
- const packageJsonPath = path16.join(currentDir, "package.json");
19402
+ const packageJsonPath = path17.join(currentDir, "package.json");
19340
19403
  try {
19341
- if (fs8.existsSync(packageJsonPath)) {
19342
- const parsed = JSON.parse(fs8.readFileSync(packageJsonPath, "utf8"));
19404
+ if (fs9.existsSync(packageJsonPath)) {
19405
+ const parsed = JSON.parse(fs9.readFileSync(packageJsonPath, "utf8"));
19343
19406
  if (parsed?.name === packageName) {
19344
19407
  const normalized = currentDir.replace(/\\/g, "/");
19345
19408
  return normalized.includes("/node_modules/") ? currentDir : null;
@@ -19347,7 +19410,7 @@ function findCurrentPackageRoot(currentCliPath, packageName) {
19347
19410
  }
19348
19411
  } catch {
19349
19412
  }
19350
- const parentDir = path16.dirname(currentDir);
19413
+ const parentDir = path17.dirname(currentDir);
19351
19414
  if (parentDir === currentDir) {
19352
19415
  return null;
19353
19416
  }
@@ -19355,13 +19418,13 @@ function findCurrentPackageRoot(currentCliPath, packageName) {
19355
19418
  }
19356
19419
  }
19357
19420
  function resolveInstallPrefixFromPackageRoot(packageRoot, packageName) {
19358
- const nodeModulesDir = packageName.startsWith("@") ? path16.dirname(path16.dirname(packageRoot)) : path16.dirname(packageRoot);
19359
- if (path16.basename(nodeModulesDir) !== "node_modules") {
19421
+ const nodeModulesDir = packageName.startsWith("@") ? path17.dirname(path17.dirname(packageRoot)) : path17.dirname(packageRoot);
19422
+ if (path17.basename(nodeModulesDir) !== "node_modules") {
19360
19423
  return null;
19361
19424
  }
19362
- const maybeLibDir = path16.dirname(nodeModulesDir);
19363
- if (path16.basename(maybeLibDir) === "lib") {
19364
- return path16.dirname(maybeLibDir);
19425
+ const maybeLibDir = path17.dirname(nodeModulesDir);
19426
+ if (path17.basename(maybeLibDir) === "lib") {
19427
+ return path17.dirname(maybeLibDir);
19365
19428
  }
19366
19429
  return maybeLibDir;
19367
19430
  }
@@ -19476,10 +19539,10 @@ async function waitForPidExit(pid, timeoutMs) {
19476
19539
  }
19477
19540
  }
19478
19541
  function stopSessionHostProcesses(appName) {
19479
- const pidFile = path16.join(os17.homedir(), ".adhdev", `${appName}-session-host.pid`);
19542
+ const pidFile = path17.join(os18.homedir(), ".adhdev", `${appName}-session-host.pid`);
19480
19543
  try {
19481
- if (fs8.existsSync(pidFile)) {
19482
- const pid = Number.parseInt(fs8.readFileSync(pidFile, "utf8").trim(), 10);
19544
+ if (fs9.existsSync(pidFile)) {
19545
+ const pid = Number.parseInt(fs9.readFileSync(pidFile, "utf8").trim(), 10);
19483
19546
  if (Number.isFinite(pid) && pid !== process.pid && isManagedSessionHostPid(pid)) {
19484
19547
  killPid(pid);
19485
19548
  }
@@ -19487,15 +19550,15 @@ function stopSessionHostProcesses(appName) {
19487
19550
  } catch {
19488
19551
  } finally {
19489
19552
  try {
19490
- fs8.unlinkSync(pidFile);
19553
+ fs9.unlinkSync(pidFile);
19491
19554
  } catch {
19492
19555
  }
19493
19556
  }
19494
19557
  }
19495
19558
  function removeDaemonPidFile() {
19496
- const pidFile = path16.join(os17.homedir(), ".adhdev", "daemon.pid");
19559
+ const pidFile = path17.join(os18.homedir(), ".adhdev", "daemon.pid");
19497
19560
  try {
19498
- fs8.unlinkSync(pidFile);
19561
+ fs9.unlinkSync(pidFile);
19499
19562
  } catch {
19500
19563
  }
19501
19564
  }
@@ -19504,7 +19567,7 @@ function cleanupStaleGlobalInstallDirs(pkgName, surface) {
19504
19567
  const npmRoot = String(execNpmCommandSync(["root", "-g", ...prefixArgs], { encoding: "utf8" }, surface)).trim();
19505
19568
  if (!npmRoot) return;
19506
19569
  const npmPrefix = surface.installPrefix || String(execNpmCommandSync(["prefix", "-g", ...prefixArgs], { encoding: "utf8" }, surface)).trim();
19507
- const binDir = process.platform === "win32" ? npmPrefix : path16.join(npmPrefix, "bin");
19570
+ const binDir = process.platform === "win32" ? npmPrefix : path17.join(npmPrefix, "bin");
19508
19571
  const packageBaseName = pkgName.startsWith("@") ? pkgName.split("/")[1] : pkgName;
19509
19572
  const binNames = /* @__PURE__ */ new Set([packageBaseName]);
19510
19573
  if (pkgName === "@adhdev/daemon-standalone") {
@@ -19512,25 +19575,25 @@ function cleanupStaleGlobalInstallDirs(pkgName, surface) {
19512
19575
  }
19513
19576
  if (pkgName.startsWith("@")) {
19514
19577
  const [scope, name] = pkgName.split("/");
19515
- const scopeDir = path16.join(npmRoot, scope);
19516
- if (!fs8.existsSync(scopeDir)) return;
19517
- for (const entry of fs8.readdirSync(scopeDir)) {
19578
+ const scopeDir = path17.join(npmRoot, scope);
19579
+ if (!fs9.existsSync(scopeDir)) return;
19580
+ for (const entry of fs9.readdirSync(scopeDir)) {
19518
19581
  if (!entry.startsWith(`.${name}-`)) continue;
19519
- fs8.rmSync(path16.join(scopeDir, entry), { recursive: true, force: true });
19520
- appendUpgradeLog(`Removed stale scoped staging dir: ${path16.join(scopeDir, entry)}`);
19582
+ fs9.rmSync(path17.join(scopeDir, entry), { recursive: true, force: true });
19583
+ appendUpgradeLog(`Removed stale scoped staging dir: ${path17.join(scopeDir, entry)}`);
19521
19584
  }
19522
19585
  } else {
19523
- for (const entry of fs8.readdirSync(npmRoot)) {
19586
+ for (const entry of fs9.readdirSync(npmRoot)) {
19524
19587
  if (!entry.startsWith(`.${pkgName}-`)) continue;
19525
- fs8.rmSync(path16.join(npmRoot, entry), { recursive: true, force: true });
19526
- appendUpgradeLog(`Removed stale staging dir: ${path16.join(npmRoot, entry)}`);
19588
+ fs9.rmSync(path17.join(npmRoot, entry), { recursive: true, force: true });
19589
+ appendUpgradeLog(`Removed stale staging dir: ${path17.join(npmRoot, entry)}`);
19527
19590
  }
19528
19591
  }
19529
- if (fs8.existsSync(binDir)) {
19530
- for (const entry of fs8.readdirSync(binDir)) {
19592
+ if (fs9.existsSync(binDir)) {
19593
+ for (const entry of fs9.readdirSync(binDir)) {
19531
19594
  if (!Array.from(binNames).some((name) => entry.startsWith(`.${name}-`))) continue;
19532
- fs8.rmSync(path16.join(binDir, entry), { recursive: true, force: true });
19533
- appendUpgradeLog(`Removed stale bin staging entry: ${path16.join(binDir, entry)}`);
19595
+ fs9.rmSync(path17.join(binDir, entry), { recursive: true, force: true });
19596
+ appendUpgradeLog(`Removed stale bin staging entry: ${path17.join(binDir, entry)}`);
19534
19597
  }
19535
19598
  }
19536
19599
  }
@@ -19615,7 +19678,7 @@ async function maybeRunDaemonUpgradeHelperFromEnv() {
19615
19678
  }
19616
19679
 
19617
19680
  // src/commands/router.ts
19618
- var fs9 = __toESM(require("fs"));
19681
+ var fs10 = __toESM(require("fs"));
19619
19682
  var CHAT_COMMANDS = [
19620
19683
  "send_chat",
19621
19684
  "new_chat",
@@ -19851,8 +19914,8 @@ var DaemonCommandRouter = class {
19851
19914
  if (sinceTs > 0) {
19852
19915
  return { success: true, logs: [], totalBuffered: 0 };
19853
19916
  }
19854
- if (fs9.existsSync(LOG_PATH)) {
19855
- const content = fs9.readFileSync(LOG_PATH, "utf-8");
19917
+ if (fs10.existsSync(LOG_PATH)) {
19918
+ const content = fs10.readFileSync(LOG_PATH, "utf-8");
19856
19919
  const allLines = content.split("\n");
19857
19920
  const recent = allLines.slice(-count).join("\n");
19858
19921
  return { success: true, logs: recent, totalLines: allLines.length };
@@ -22007,12 +22070,12 @@ init_io_contracts();
22007
22070
  init_chat_message_normalization();
22008
22071
 
22009
22072
  // src/providers/version-archive.ts
22010
- var fs10 = __toESM(require("fs"));
22011
- var path17 = __toESM(require("path"));
22012
- var os18 = __toESM(require("os"));
22073
+ var fs11 = __toESM(require("fs"));
22074
+ var path18 = __toESM(require("path"));
22075
+ var os19 = __toESM(require("os"));
22013
22076
  var import_child_process10 = require("child_process");
22014
22077
  var import_os3 = require("os");
22015
- var ARCHIVE_PATH = path17.join(os18.homedir(), ".adhdev", "version-history.json");
22078
+ var ARCHIVE_PATH = path18.join(os19.homedir(), ".adhdev", "version-history.json");
22016
22079
  var MAX_ENTRIES_PER_PROVIDER = 20;
22017
22080
  var VersionArchive = class {
22018
22081
  history = {};
@@ -22021,8 +22084,8 @@ var VersionArchive = class {
22021
22084
  }
22022
22085
  load() {
22023
22086
  try {
22024
- if (fs10.existsSync(ARCHIVE_PATH)) {
22025
- this.history = JSON.parse(fs10.readFileSync(ARCHIVE_PATH, "utf-8"));
22087
+ if (fs11.existsSync(ARCHIVE_PATH)) {
22088
+ this.history = JSON.parse(fs11.readFileSync(ARCHIVE_PATH, "utf-8"));
22026
22089
  }
22027
22090
  } catch {
22028
22091
  this.history = {};
@@ -22059,8 +22122,8 @@ var VersionArchive = class {
22059
22122
  }
22060
22123
  save() {
22061
22124
  try {
22062
- fs10.mkdirSync(path17.dirname(ARCHIVE_PATH), { recursive: true });
22063
- fs10.writeFileSync(ARCHIVE_PATH, JSON.stringify(this.history, null, 2));
22125
+ fs11.mkdirSync(path18.dirname(ARCHIVE_PATH), { recursive: true });
22126
+ fs11.writeFileSync(ARCHIVE_PATH, JSON.stringify(this.history, null, 2));
22064
22127
  } catch {
22065
22128
  }
22066
22129
  }
@@ -22115,19 +22178,19 @@ function getVersion(binary, versionCommand) {
22115
22178
  function checkPathExists2(paths) {
22116
22179
  for (const p of paths) {
22117
22180
  if (p.includes("*")) {
22118
- const home = os18.homedir();
22119
- const resolved = p.replace(/\*/g, home.split(path17.sep).pop() || "");
22120
- if (fs10.existsSync(resolved)) return resolved;
22181
+ const home = os19.homedir();
22182
+ const resolved = p.replace(/\*/g, home.split(path18.sep).pop() || "");
22183
+ if (fs11.existsSync(resolved)) return resolved;
22121
22184
  } else {
22122
- if (fs10.existsSync(p)) return p;
22185
+ if (fs11.existsSync(p)) return p;
22123
22186
  }
22124
22187
  }
22125
22188
  return null;
22126
22189
  }
22127
22190
  function getMacAppVersion(appPath) {
22128
22191
  if ((0, import_os3.platform)() !== "darwin" || !appPath.endsWith(".app")) return null;
22129
- const plistPath = path17.join(appPath, "Contents", "Info.plist");
22130
- if (!fs10.existsSync(plistPath)) return null;
22192
+ const plistPath = path18.join(appPath, "Contents", "Info.plist");
22193
+ if (!fs11.existsSync(plistPath)) return null;
22131
22194
  const raw = runCommand(`/usr/libexec/PlistBuddy -c "Print CFBundleShortVersionString" "${plistPath}"`);
22132
22195
  return raw || null;
22133
22196
  }
@@ -22152,8 +22215,8 @@ async function detectAllVersions(loader, archive) {
22152
22215
  const cliBin = provider.cli ? findBinary2(provider.cli) : null;
22153
22216
  let resolvedBin = cliBin;
22154
22217
  if (!resolvedBin && appPath && currentOs === "darwin") {
22155
- const bundled = path17.join(appPath, "Contents", "Resources", "app", "bin", provider.cli || "");
22156
- if (provider.cli && fs10.existsSync(bundled)) resolvedBin = bundled;
22218
+ const bundled = path18.join(appPath, "Contents", "Resources", "app", "bin", provider.cli || "");
22219
+ if (provider.cli && fs11.existsSync(bundled)) resolvedBin = bundled;
22157
22220
  }
22158
22221
  info.installed = !!(appPath || resolvedBin);
22159
22222
  info.path = appPath || null;
@@ -22192,8 +22255,8 @@ async function detectAllVersions(loader, archive) {
22192
22255
 
22193
22256
  // src/daemon/dev-server.ts
22194
22257
  var http2 = __toESM(require("http"));
22195
- var fs14 = __toESM(require("fs"));
22196
- var path21 = __toESM(require("path"));
22258
+ var fs15 = __toESM(require("fs"));
22259
+ var path22 = __toESM(require("path"));
22197
22260
  init_config();
22198
22261
 
22199
22262
  // src/daemon/scaffold-template.ts
@@ -22543,8 +22606,8 @@ async (params) => {
22543
22606
  init_logger();
22544
22607
 
22545
22608
  // src/daemon/dev-cdp-handlers.ts
22546
- var fs11 = __toESM(require("fs"));
22547
- var path18 = __toESM(require("path"));
22609
+ var fs12 = __toESM(require("fs"));
22610
+ var path19 = __toESM(require("path"));
22548
22611
  init_logger();
22549
22612
  async function handleCdpEvaluate(ctx, req, res) {
22550
22613
  const body = await ctx.readBody(req);
@@ -22723,18 +22786,18 @@ async function handleScriptHints(ctx, type, _req, res) {
22723
22786
  return;
22724
22787
  }
22725
22788
  let scriptsPath = "";
22726
- const directScripts = path18.join(dir, "scripts.js");
22727
- if (fs11.existsSync(directScripts)) {
22789
+ const directScripts = path19.join(dir, "scripts.js");
22790
+ if (fs12.existsSync(directScripts)) {
22728
22791
  scriptsPath = directScripts;
22729
22792
  } else {
22730
- const scriptsDir = path18.join(dir, "scripts");
22731
- if (fs11.existsSync(scriptsDir)) {
22732
- const versions = fs11.readdirSync(scriptsDir).filter((d) => {
22733
- return fs11.statSync(path18.join(scriptsDir, d)).isDirectory();
22793
+ const scriptsDir = path19.join(dir, "scripts");
22794
+ if (fs12.existsSync(scriptsDir)) {
22795
+ const versions = fs12.readdirSync(scriptsDir).filter((d) => {
22796
+ return fs12.statSync(path19.join(scriptsDir, d)).isDirectory();
22734
22797
  }).sort().reverse();
22735
22798
  for (const ver of versions) {
22736
- const p = path18.join(scriptsDir, ver, "scripts.js");
22737
- if (fs11.existsSync(p)) {
22799
+ const p = path19.join(scriptsDir, ver, "scripts.js");
22800
+ if (fs12.existsSync(p)) {
22738
22801
  scriptsPath = p;
22739
22802
  break;
22740
22803
  }
@@ -22746,7 +22809,7 @@ async function handleScriptHints(ctx, type, _req, res) {
22746
22809
  return;
22747
22810
  }
22748
22811
  try {
22749
- const source = fs11.readFileSync(scriptsPath, "utf-8");
22812
+ const source = fs12.readFileSync(scriptsPath, "utf-8");
22750
22813
  const hints = {};
22751
22814
  const funcRegex = /module\.exports\.(\w+)\s*=\s*function\s+\w+\s*\(params\)/g;
22752
22815
  let match;
@@ -23561,8 +23624,8 @@ async function handleDomContext(ctx, type, req, res) {
23561
23624
  }
23562
23625
 
23563
23626
  // src/daemon/dev-cli-debug.ts
23564
- var fs12 = __toESM(require("fs"));
23565
- var path19 = __toESM(require("path"));
23627
+ var fs13 = __toESM(require("fs"));
23628
+ var path20 = __toESM(require("path"));
23566
23629
  function slugifyFixtureName(value) {
23567
23630
  const normalized = String(value || "").trim().toLowerCase().replace(/[^a-z0-9._-]+/g, "-").replace(/^-+|-+$/g, "");
23568
23631
  return normalized || `fixture-${Date.now()}`;
@@ -23572,15 +23635,15 @@ function getCliFixtureDir(ctx, type) {
23572
23635
  if (!providerDir) {
23573
23636
  throw new Error(`Provider directory not found for '${type}'`);
23574
23637
  }
23575
- return path19.join(providerDir, "fixtures");
23638
+ return path20.join(providerDir, "fixtures");
23576
23639
  }
23577
23640
  function readCliFixture(ctx, type, name) {
23578
23641
  const fixtureDir = getCliFixtureDir(ctx, type);
23579
- const filePath = path19.join(fixtureDir, `${name}.json`);
23580
- if (!fs12.existsSync(filePath)) {
23642
+ const filePath = path20.join(fixtureDir, `${name}.json`);
23643
+ if (!fs13.existsSync(filePath)) {
23581
23644
  throw new Error(`Fixture not found: ${filePath}`);
23582
23645
  }
23583
- return JSON.parse(fs12.readFileSync(filePath, "utf-8"));
23646
+ return JSON.parse(fs13.readFileSync(filePath, "utf-8"));
23584
23647
  }
23585
23648
  function getExerciseTranscriptText(result) {
23586
23649
  const parts = [];
@@ -24316,7 +24379,7 @@ async function handleCliFixtureCapture(ctx, req, res) {
24316
24379
  return;
24317
24380
  }
24318
24381
  const fixtureDir = getCliFixtureDir(ctx, type);
24319
- fs12.mkdirSync(fixtureDir, { recursive: true });
24382
+ fs13.mkdirSync(fixtureDir, { recursive: true });
24320
24383
  const name = slugifyFixtureName(String(body?.name || `${type}-${Date.now()}`));
24321
24384
  const result = await runCliExerciseInternal(ctx, { ...request, type });
24322
24385
  const fixture = {
@@ -24343,8 +24406,8 @@ async function handleCliFixtureCapture(ctx, req, res) {
24343
24406
  },
24344
24407
  notes: typeof body?.notes === "string" ? body.notes : void 0
24345
24408
  };
24346
- const filePath = path19.join(fixtureDir, `${name}.json`);
24347
- fs12.writeFileSync(filePath, JSON.stringify(fixture, null, 2));
24409
+ const filePath = path20.join(fixtureDir, `${name}.json`);
24410
+ fs13.writeFileSync(filePath, JSON.stringify(fixture, null, 2));
24348
24411
  ctx.json(res, 200, {
24349
24412
  saved: true,
24350
24413
  name,
@@ -24362,14 +24425,14 @@ async function handleCliFixtureCapture(ctx, req, res) {
24362
24425
  async function handleCliFixtureList(ctx, type, _req, res) {
24363
24426
  try {
24364
24427
  const fixtureDir = getCliFixtureDir(ctx, type);
24365
- if (!fs12.existsSync(fixtureDir)) {
24428
+ if (!fs13.existsSync(fixtureDir)) {
24366
24429
  ctx.json(res, 200, { fixtures: [], count: 0 });
24367
24430
  return;
24368
24431
  }
24369
- const fixtures = fs12.readdirSync(fixtureDir).filter((file) => file.endsWith(".json")).sort((a, b) => b.localeCompare(a, void 0, { numeric: true, sensitivity: "base" })).map((file) => {
24370
- const fullPath = path19.join(fixtureDir, file);
24432
+ const fixtures = fs13.readdirSync(fixtureDir).filter((file) => file.endsWith(".json")).sort((a, b) => b.localeCompare(a, void 0, { numeric: true, sensitivity: "base" })).map((file) => {
24433
+ const fullPath = path20.join(fixtureDir, file);
24371
24434
  try {
24372
- const raw = JSON.parse(fs12.readFileSync(fullPath, "utf-8"));
24435
+ const raw = JSON.parse(fs13.readFileSync(fullPath, "utf-8"));
24373
24436
  return {
24374
24437
  name: raw.name || file.replace(/\.json$/i, ""),
24375
24438
  path: fullPath,
@@ -24502,9 +24565,9 @@ async function handleCliRaw(ctx, req, res) {
24502
24565
  }
24503
24566
 
24504
24567
  // src/daemon/dev-auto-implement.ts
24505
- var fs13 = __toESM(require("fs"));
24506
- var path20 = __toESM(require("path"));
24507
- var os19 = __toESM(require("os"));
24568
+ var fs14 = __toESM(require("fs"));
24569
+ var path21 = __toESM(require("path"));
24570
+ var os20 = __toESM(require("os"));
24508
24571
  function getAutoImplPid(ctx) {
24509
24572
  const pid = ctx.autoImplProcess?.pid;
24510
24573
  return typeof pid === "number" && pid > 0 ? pid : null;
@@ -24550,38 +24613,38 @@ function resolveAutoImplReference(ctx, category, requestedReference, targetType)
24550
24613
  return fallback?.type || null;
24551
24614
  }
24552
24615
  function getLatestScriptVersionDir(scriptsDir) {
24553
- if (!fs13.existsSync(scriptsDir)) return null;
24554
- const versions = fs13.readdirSync(scriptsDir).filter((d) => {
24616
+ if (!fs14.existsSync(scriptsDir)) return null;
24617
+ const versions = fs14.readdirSync(scriptsDir).filter((d) => {
24555
24618
  try {
24556
- return fs13.statSync(path20.join(scriptsDir, d)).isDirectory();
24619
+ return fs14.statSync(path21.join(scriptsDir, d)).isDirectory();
24557
24620
  } catch {
24558
24621
  return false;
24559
24622
  }
24560
24623
  }).sort((a, b) => b.localeCompare(a, void 0, { numeric: true, sensitivity: "base" }));
24561
24624
  if (versions.length === 0) return null;
24562
- return path20.join(scriptsDir, versions[0]);
24625
+ return path21.join(scriptsDir, versions[0]);
24563
24626
  }
24564
24627
  function resolveAutoImplWritableProviderDir(ctx, category, type, requestedDir) {
24565
- const canonicalUserDir = path20.resolve(ctx.providerLoader.getUserProviderDir(category, type));
24566
- const desiredDir = requestedDir ? path20.resolve(requestedDir) : canonicalUserDir;
24567
- const upstreamRoot = path20.resolve(ctx.providerLoader.getUpstreamDir());
24568
- if (desiredDir === upstreamRoot || desiredDir.startsWith(`${upstreamRoot}${path20.sep}`)) {
24628
+ const canonicalUserDir = path21.resolve(ctx.providerLoader.getUserProviderDir(category, type));
24629
+ const desiredDir = requestedDir ? path21.resolve(requestedDir) : canonicalUserDir;
24630
+ const upstreamRoot = path21.resolve(ctx.providerLoader.getUpstreamDir());
24631
+ if (desiredDir === upstreamRoot || desiredDir.startsWith(`${upstreamRoot}${path21.sep}`)) {
24569
24632
  return { dir: null, reason: `Refusing to write into upstream provider directory: ${desiredDir}` };
24570
24633
  }
24571
- if (path20.basename(desiredDir) !== type) {
24634
+ if (path21.basename(desiredDir) !== type) {
24572
24635
  return { dir: null, reason: `Requested writable provider directory must end with '${type}': ${desiredDir}` };
24573
24636
  }
24574
24637
  const sourceDir = ctx.findProviderDir(type);
24575
24638
  if (!sourceDir) {
24576
24639
  return { dir: null, reason: `Provider source directory not found for '${type}'` };
24577
24640
  }
24578
- if (!fs13.existsSync(desiredDir)) {
24579
- fs13.mkdirSync(path20.dirname(desiredDir), { recursive: true });
24580
- fs13.cpSync(sourceDir, desiredDir, { recursive: true });
24641
+ if (!fs14.existsSync(desiredDir)) {
24642
+ fs14.mkdirSync(path21.dirname(desiredDir), { recursive: true });
24643
+ fs14.cpSync(sourceDir, desiredDir, { recursive: true });
24581
24644
  ctx.log(`Auto-implement writable copy created: ${desiredDir}`);
24582
24645
  }
24583
- const providerJson = path20.join(desiredDir, "provider.json");
24584
- if (!fs13.existsSync(providerJson)) {
24646
+ const providerJson = path21.join(desiredDir, "provider.json");
24647
+ if (!fs14.existsSync(providerJson)) {
24585
24648
  return { dir: null, reason: `provider.json not found in writable provider directory: ${desiredDir}` };
24586
24649
  }
24587
24650
  return { dir: desiredDir };
@@ -24589,15 +24652,15 @@ function resolveAutoImplWritableProviderDir(ctx, category, type, requestedDir) {
24589
24652
  function loadAutoImplReferenceScripts(ctx, referenceType) {
24590
24653
  if (!referenceType) return {};
24591
24654
  const refDir = ctx.findProviderDir(referenceType);
24592
- if (!refDir || !fs13.existsSync(refDir)) return {};
24655
+ if (!refDir || !fs14.existsSync(refDir)) return {};
24593
24656
  const referenceScripts = {};
24594
- const scriptsDir = path20.join(refDir, "scripts");
24657
+ const scriptsDir = path21.join(refDir, "scripts");
24595
24658
  const latestDir = getLatestScriptVersionDir(scriptsDir);
24596
24659
  if (!latestDir) return referenceScripts;
24597
- for (const file of fs13.readdirSync(latestDir)) {
24660
+ for (const file of fs14.readdirSync(latestDir)) {
24598
24661
  if (!file.endsWith(".js")) continue;
24599
24662
  try {
24600
- referenceScripts[file] = fs13.readFileSync(path20.join(latestDir, file), "utf-8");
24663
+ referenceScripts[file] = fs14.readFileSync(path21.join(latestDir, file), "utf-8");
24601
24664
  } catch {
24602
24665
  }
24603
24666
  }
@@ -24705,16 +24768,16 @@ async function handleAutoImplement(ctx, type, req, res) {
24705
24768
  });
24706
24769
  const referenceScripts = loadAutoImplReferenceScripts(ctx, resolvedReference);
24707
24770
  const prompt = buildAutoImplPrompt(ctx, type, provider, providerDir, functions, domContext, referenceScripts, comment, resolvedReference, verification);
24708
- const tmpDir = path20.join(os19.tmpdir(), "adhdev-autoimpl");
24709
- if (!fs13.existsSync(tmpDir)) fs13.mkdirSync(tmpDir, { recursive: true });
24710
- const promptFile = path20.join(tmpDir, `prompt-${type}-${Date.now()}.md`);
24711
- fs13.writeFileSync(promptFile, prompt, "utf-8");
24771
+ const tmpDir = path21.join(os20.tmpdir(), "adhdev-autoimpl");
24772
+ if (!fs14.existsSync(tmpDir)) fs14.mkdirSync(tmpDir, { recursive: true });
24773
+ const promptFile = path21.join(tmpDir, `prompt-${type}-${Date.now()}.md`);
24774
+ fs14.writeFileSync(promptFile, prompt, "utf-8");
24712
24775
  ctx.log(`Auto-implement prompt written to ${promptFile} (${prompt.length} chars)`);
24713
24776
  const agentProvider = ctx.providerLoader.resolve(agent) || ctx.providerLoader.getMeta(agent);
24714
24777
  const spawn4 = agentProvider?.spawn;
24715
24778
  if (!spawn4?.command) {
24716
24779
  try {
24717
- fs13.unlinkSync(promptFile);
24780
+ fs14.unlinkSync(promptFile);
24718
24781
  } catch {
24719
24782
  }
24720
24783
  ctx.json(res, 400, { error: `Agent '${agent}' has no spawn config. Select a CLI provider with a spawn configuration.` });
@@ -24816,7 +24879,7 @@ async function handleAutoImplement(ctx, type, req, res) {
24816
24879
  } catch {
24817
24880
  }
24818
24881
  try {
24819
- fs13.unlinkSync(promptFile);
24882
+ fs14.unlinkSync(promptFile);
24820
24883
  } catch {
24821
24884
  }
24822
24885
  ctx.log(`Auto-implement (ACP) ${success ? "completed" : "failed"}: ${type} (exit: ${code})`);
@@ -24860,7 +24923,7 @@ async function handleAutoImplement(ctx, type, req, res) {
24860
24923
  const interactiveFlags = ["--yolo", "--interactive", "-i"];
24861
24924
  const baseArgs = [...spawn4.args || []].filter((a) => !interactiveFlags.includes(a));
24862
24925
  let shellCmd;
24863
- const isWin = os19.platform() === "win32";
24926
+ const isWin = os20.platform() === "win32";
24864
24927
  const escapeArg = (a) => isWin ? `"${a.replace(/"/g, '""')}"` : `'${a.replace(/'/g, "'\\''")}'`;
24865
24928
  const promptMode = autoImpl?.promptMode ?? "stdin";
24866
24929
  const extraArgs = autoImpl?.extraArgs ?? [];
@@ -24899,7 +24962,7 @@ async function handleAutoImplement(ctx, type, req, res) {
24899
24962
  try {
24900
24963
  const pty = require("node-pty");
24901
24964
  ctx.log(`Auto-implement spawn (PTY): ${shellCmd}`);
24902
- const isWin2 = os19.platform() === "win32";
24965
+ const isWin2 = os20.platform() === "win32";
24903
24966
  child = pty.spawn(isWin2 ? "cmd.exe" : process.env.SHELL || "/bin/zsh", [isWin2 ? "/c" : "-c", shellCmd], {
24904
24967
  name: "xterm-256color",
24905
24968
  cols: 120,
@@ -25042,7 +25105,7 @@ async function handleAutoImplement(ctx, type, req, res) {
25042
25105
  }
25043
25106
  });
25044
25107
  try {
25045
- fs13.unlinkSync(promptFile);
25108
+ fs14.unlinkSync(promptFile);
25046
25109
  } catch {
25047
25110
  }
25048
25111
  ctx.log(`Auto-implement ${success ? "completed" : "failed"}: ${type} (exit: ${code})${verificationSummary ? ` verify=${verificationSummary.pass ? "pass" : "fail"}` : ""}`);
@@ -25139,7 +25202,7 @@ function buildAutoImplPrompt(ctx, type, provider, providerDir, functions, domCon
25139
25202
  setMode: "set_mode.js"
25140
25203
  };
25141
25204
  const targetFileNames = new Set(functions.map((fn) => funcToFile[fn]).filter(Boolean));
25142
- const scriptsDir = path20.join(providerDir, "scripts");
25205
+ const scriptsDir = path21.join(providerDir, "scripts");
25143
25206
  const latestScriptsDir = getLatestScriptVersionDir(scriptsDir);
25144
25207
  if (latestScriptsDir) {
25145
25208
  lines.push(`Scripts version directory: \`${latestScriptsDir}\``);
@@ -25147,10 +25210,10 @@ function buildAutoImplPrompt(ctx, type, provider, providerDir, functions, domCon
25147
25210
  lines.push("## \u270F\uFE0F Target Files (EDIT THESE)");
25148
25211
  lines.push("These are the ONLY files you are allowed to modify. Replace the TODO stubs with working implementations.");
25149
25212
  lines.push("");
25150
- for (const file of fs13.readdirSync(latestScriptsDir)) {
25213
+ for (const file of fs14.readdirSync(latestScriptsDir)) {
25151
25214
  if (file.endsWith(".js") && targetFileNames.has(file)) {
25152
25215
  try {
25153
- const content = fs13.readFileSync(path20.join(latestScriptsDir, file), "utf-8");
25216
+ const content = fs14.readFileSync(path21.join(latestScriptsDir, file), "utf-8");
25154
25217
  lines.push(`### \`${file}\` \u270F\uFE0F EDIT`);
25155
25218
  lines.push("```javascript");
25156
25219
  lines.push(content);
@@ -25160,14 +25223,14 @@ function buildAutoImplPrompt(ctx, type, provider, providerDir, functions, domCon
25160
25223
  }
25161
25224
  }
25162
25225
  }
25163
- const refFiles = fs13.readdirSync(latestScriptsDir).filter((f) => f.endsWith(".js") && !targetFileNames.has(f));
25226
+ const refFiles = fs14.readdirSync(latestScriptsDir).filter((f) => f.endsWith(".js") && !targetFileNames.has(f));
25164
25227
  if (refFiles.length > 0) {
25165
25228
  lines.push("## \u{1F512} Other Scripts (REFERENCE ONLY \u2014 DO NOT EDIT)");
25166
25229
  lines.push("These files are shown for context only. Do NOT modify them under any circumstances.");
25167
25230
  lines.push("");
25168
25231
  for (const file of refFiles) {
25169
25232
  try {
25170
- const content = fs13.readFileSync(path20.join(latestScriptsDir, file), "utf-8");
25233
+ const content = fs14.readFileSync(path21.join(latestScriptsDir, file), "utf-8");
25171
25234
  lines.push(`### \`${file}\` \u{1F512}`);
25172
25235
  lines.push("```javascript");
25173
25236
  lines.push(content);
@@ -25208,11 +25271,11 @@ function buildAutoImplPrompt(ctx, type, provider, providerDir, functions, domCon
25208
25271
  lines.push("");
25209
25272
  }
25210
25273
  }
25211
- const docsDir = path20.join(providerDir, "../../docs");
25274
+ const docsDir = path21.join(providerDir, "../../docs");
25212
25275
  const loadGuide = (name) => {
25213
25276
  try {
25214
- const p = path20.join(docsDir, name);
25215
- if (fs13.existsSync(p)) return fs13.readFileSync(p, "utf-8");
25277
+ const p = path21.join(docsDir, name);
25278
+ if (fs14.existsSync(p)) return fs14.readFileSync(p, "utf-8");
25216
25279
  } catch {
25217
25280
  }
25218
25281
  return null;
@@ -25448,7 +25511,7 @@ function buildCliAutoImplPrompt(ctx, type, provider, providerDir, functions, ref
25448
25511
  parseApproval: "parse_approval.js"
25449
25512
  };
25450
25513
  const targetFileNames = new Set(functions.map((fn) => funcToFile[fn]).filter(Boolean));
25451
- const scriptsDir = path20.join(providerDir, "scripts");
25514
+ const scriptsDir = path21.join(providerDir, "scripts");
25452
25515
  const latestScriptsDir = getLatestScriptVersionDir(scriptsDir);
25453
25516
  if (latestScriptsDir) {
25454
25517
  lines.push(`Scripts version directory: \`${latestScriptsDir}\``);
@@ -25456,11 +25519,11 @@ function buildCliAutoImplPrompt(ctx, type, provider, providerDir, functions, ref
25456
25519
  lines.push("## \u270F\uFE0F Target Files (EDIT THESE)");
25457
25520
  lines.push("These are the ONLY files you are allowed to modify. Replace TODO or heuristic-only logic with working PTY-aware implementations.");
25458
25521
  lines.push("");
25459
- for (const file of fs13.readdirSync(latestScriptsDir)) {
25522
+ for (const file of fs14.readdirSync(latestScriptsDir)) {
25460
25523
  if (!file.endsWith(".js")) continue;
25461
25524
  if (!targetFileNames.has(file)) continue;
25462
25525
  try {
25463
- const content = fs13.readFileSync(path20.join(latestScriptsDir, file), "utf-8");
25526
+ const content = fs14.readFileSync(path21.join(latestScriptsDir, file), "utf-8");
25464
25527
  lines.push(`### \`${file}\` \u270F\uFE0F EDIT`);
25465
25528
  lines.push("```javascript");
25466
25529
  lines.push(content);
@@ -25469,14 +25532,14 @@ function buildCliAutoImplPrompt(ctx, type, provider, providerDir, functions, ref
25469
25532
  } catch {
25470
25533
  }
25471
25534
  }
25472
- const refFiles = fs13.readdirSync(latestScriptsDir).filter((f) => f.endsWith(".js") && !targetFileNames.has(f));
25535
+ const refFiles = fs14.readdirSync(latestScriptsDir).filter((f) => f.endsWith(".js") && !targetFileNames.has(f));
25473
25536
  if (refFiles.length > 0) {
25474
25537
  lines.push("## \u{1F512} Other Scripts (REFERENCE ONLY \u2014 DO NOT EDIT)");
25475
25538
  lines.push("These files are shown for context only. Do NOT modify them under any circumstances.");
25476
25539
  lines.push("");
25477
25540
  for (const file of refFiles) {
25478
25541
  try {
25479
- const content = fs13.readFileSync(path20.join(latestScriptsDir, file), "utf-8");
25542
+ const content = fs14.readFileSync(path21.join(latestScriptsDir, file), "utf-8");
25480
25543
  lines.push(`### \`${file}\` \u{1F512}`);
25481
25544
  lines.push("```javascript");
25482
25545
  lines.push(content);
@@ -25509,11 +25572,11 @@ function buildCliAutoImplPrompt(ctx, type, provider, providerDir, functions, ref
25509
25572
  lines.push("");
25510
25573
  }
25511
25574
  }
25512
- const docsDir = path20.join(providerDir, "../../docs");
25575
+ const docsDir = path21.join(providerDir, "../../docs");
25513
25576
  const loadGuide = (name) => {
25514
25577
  try {
25515
- const p = path20.join(docsDir, name);
25516
- if (fs13.existsSync(p)) return fs13.readFileSync(p, "utf-8");
25578
+ const p = path21.join(docsDir, name);
25579
+ if (fs14.existsSync(p)) return fs14.readFileSync(p, "utf-8");
25517
25580
  } catch {
25518
25581
  }
25519
25582
  return null;
@@ -25959,8 +26022,8 @@ var DevServer = class _DevServer {
25959
26022
  }
25960
26023
  getEndpointList() {
25961
26024
  return this.routes.map((r) => {
25962
- const path22 = typeof r.pattern === "string" ? r.pattern : r.pattern.source.replace(/\\\//g, "/").replace(/\(\[.*?\]\+\)/g, ":type").replace(/[\^$]/g, "");
25963
- return `${r.method.padEnd(5)} ${path22}`;
26025
+ const path23 = typeof r.pattern === "string" ? r.pattern : r.pattern.source.replace(/\\\//g, "/").replace(/\(\[.*?\]\+\)/g, ":type").replace(/[\^$]/g, "");
26026
+ return `${r.method.padEnd(5)} ${path23}`;
25964
26027
  });
25965
26028
  }
25966
26029
  async start(port = DEV_SERVER_PORT) {
@@ -26248,12 +26311,12 @@ var DevServer = class _DevServer {
26248
26311
  // ─── DevConsole SPA ───
26249
26312
  getConsoleDistDir() {
26250
26313
  const candidates = [
26251
- path21.resolve(__dirname, "../../web-devconsole/dist"),
26252
- path21.resolve(__dirname, "../../../web-devconsole/dist"),
26253
- path21.join(process.cwd(), "packages/web-devconsole/dist")
26314
+ path22.resolve(__dirname, "../../web-devconsole/dist"),
26315
+ path22.resolve(__dirname, "../../../web-devconsole/dist"),
26316
+ path22.join(process.cwd(), "packages/web-devconsole/dist")
26254
26317
  ];
26255
26318
  for (const dir of candidates) {
26256
- if (fs14.existsSync(path21.join(dir, "index.html"))) return dir;
26319
+ if (fs15.existsSync(path22.join(dir, "index.html"))) return dir;
26257
26320
  }
26258
26321
  return null;
26259
26322
  }
@@ -26263,9 +26326,9 @@ var DevServer = class _DevServer {
26263
26326
  this.json(res, 500, { error: "DevConsole not found. Run: npm run build -w packages/web-devconsole" });
26264
26327
  return;
26265
26328
  }
26266
- const htmlPath = path21.join(distDir, "index.html");
26329
+ const htmlPath = path22.join(distDir, "index.html");
26267
26330
  try {
26268
- const html = fs14.readFileSync(htmlPath, "utf-8");
26331
+ const html = fs15.readFileSync(htmlPath, "utf-8");
26269
26332
  res.writeHead(200, { "Content-Type": "text/html; charset=utf-8" });
26270
26333
  res.end(html);
26271
26334
  } catch (e) {
@@ -26288,15 +26351,15 @@ var DevServer = class _DevServer {
26288
26351
  this.json(res, 404, { error: "Not found" });
26289
26352
  return;
26290
26353
  }
26291
- const safePath = path21.normalize(pathname).replace(/^\.\.\//, "");
26292
- const filePath = path21.join(distDir, safePath);
26354
+ const safePath = path22.normalize(pathname).replace(/^\.\.\//, "");
26355
+ const filePath = path22.join(distDir, safePath);
26293
26356
  if (!filePath.startsWith(distDir)) {
26294
26357
  this.json(res, 403, { error: "Forbidden" });
26295
26358
  return;
26296
26359
  }
26297
26360
  try {
26298
- const content = fs14.readFileSync(filePath);
26299
- const ext = path21.extname(filePath);
26361
+ const content = fs15.readFileSync(filePath);
26362
+ const ext = path22.extname(filePath);
26300
26363
  const contentType = _DevServer.MIME_MAP[ext] || "application/octet-stream";
26301
26364
  res.writeHead(200, { "Content-Type": contentType, "Cache-Control": "public, max-age=31536000, immutable" });
26302
26365
  res.end(content);
@@ -26404,14 +26467,14 @@ var DevServer = class _DevServer {
26404
26467
  const files = [];
26405
26468
  const scan = (d, prefix) => {
26406
26469
  try {
26407
- for (const entry of fs14.readdirSync(d, { withFileTypes: true })) {
26470
+ for (const entry of fs15.readdirSync(d, { withFileTypes: true })) {
26408
26471
  if (entry.name.startsWith(".") || entry.name.endsWith(".bak")) continue;
26409
26472
  const rel = prefix ? `${prefix}/${entry.name}` : entry.name;
26410
26473
  if (entry.isDirectory()) {
26411
26474
  files.push({ path: rel, size: 0, type: "dir" });
26412
- scan(path21.join(d, entry.name), rel);
26475
+ scan(path22.join(d, entry.name), rel);
26413
26476
  } else {
26414
- const stat = fs14.statSync(path21.join(d, entry.name));
26477
+ const stat = fs15.statSync(path22.join(d, entry.name));
26415
26478
  files.push({ path: rel, size: stat.size, type: "file" });
26416
26479
  }
26417
26480
  }
@@ -26434,16 +26497,16 @@ var DevServer = class _DevServer {
26434
26497
  this.json(res, 404, { error: `Provider directory not found: ${type}` });
26435
26498
  return;
26436
26499
  }
26437
- const fullPath = path21.resolve(dir, path21.normalize(filePath));
26500
+ const fullPath = path22.resolve(dir, path22.normalize(filePath));
26438
26501
  if (!fullPath.startsWith(dir)) {
26439
26502
  this.json(res, 403, { error: "Forbidden" });
26440
26503
  return;
26441
26504
  }
26442
- if (!fs14.existsSync(fullPath) || fs14.statSync(fullPath).isDirectory()) {
26505
+ if (!fs15.existsSync(fullPath) || fs15.statSync(fullPath).isDirectory()) {
26443
26506
  this.json(res, 404, { error: `File not found: ${filePath}` });
26444
26507
  return;
26445
26508
  }
26446
- const content = fs14.readFileSync(fullPath, "utf-8");
26509
+ const content = fs15.readFileSync(fullPath, "utf-8");
26447
26510
  this.json(res, 200, { type, path: filePath, content, lines: content.split("\n").length });
26448
26511
  }
26449
26512
  /** POST /api/providers/:type/file — write a file { path, content } */
@@ -26459,15 +26522,15 @@ var DevServer = class _DevServer {
26459
26522
  this.json(res, 404, { error: `Provider directory not found: ${type}` });
26460
26523
  return;
26461
26524
  }
26462
- const fullPath = path21.resolve(dir, path21.normalize(filePath));
26525
+ const fullPath = path22.resolve(dir, path22.normalize(filePath));
26463
26526
  if (!fullPath.startsWith(dir)) {
26464
26527
  this.json(res, 403, { error: "Forbidden" });
26465
26528
  return;
26466
26529
  }
26467
26530
  try {
26468
- if (fs14.existsSync(fullPath)) fs14.copyFileSync(fullPath, fullPath + ".bak");
26469
- fs14.mkdirSync(path21.dirname(fullPath), { recursive: true });
26470
- fs14.writeFileSync(fullPath, content, "utf-8");
26531
+ if (fs15.existsSync(fullPath)) fs15.copyFileSync(fullPath, fullPath + ".bak");
26532
+ fs15.mkdirSync(path22.dirname(fullPath), { recursive: true });
26533
+ fs15.writeFileSync(fullPath, content, "utf-8");
26471
26534
  this.log(`File saved: ${fullPath} (${content.length} chars)`);
26472
26535
  this.providerLoader.reload();
26473
26536
  this.json(res, 200, { saved: true, path: filePath, chars: content.length });
@@ -26483,9 +26546,9 @@ var DevServer = class _DevServer {
26483
26546
  return;
26484
26547
  }
26485
26548
  for (const name of ["scripts.js", "provider.json"]) {
26486
- const p = path21.join(dir, name);
26487
- if (fs14.existsSync(p)) {
26488
- const source = fs14.readFileSync(p, "utf-8");
26549
+ const p = path22.join(dir, name);
26550
+ if (fs15.existsSync(p)) {
26551
+ const source = fs15.readFileSync(p, "utf-8");
26489
26552
  this.json(res, 200, { type, path: p, source, lines: source.split("\n").length });
26490
26553
  return;
26491
26554
  }
@@ -26504,11 +26567,11 @@ var DevServer = class _DevServer {
26504
26567
  this.json(res, 404, { error: `Provider not found: ${type}` });
26505
26568
  return;
26506
26569
  }
26507
- const target = fs14.existsSync(path21.join(dir, "scripts.js")) ? "scripts.js" : "provider.json";
26508
- const targetPath = path21.join(dir, target);
26570
+ const target = fs15.existsSync(path22.join(dir, "scripts.js")) ? "scripts.js" : "provider.json";
26571
+ const targetPath = path22.join(dir, target);
26509
26572
  try {
26510
- if (fs14.existsSync(targetPath)) fs14.copyFileSync(targetPath, targetPath + ".bak");
26511
- fs14.writeFileSync(targetPath, source, "utf-8");
26573
+ if (fs15.existsSync(targetPath)) fs15.copyFileSync(targetPath, targetPath + ".bak");
26574
+ fs15.writeFileSync(targetPath, source, "utf-8");
26512
26575
  this.log(`Saved provider: ${targetPath} (${source.length} chars)`);
26513
26576
  this.providerLoader.reload();
26514
26577
  this.json(res, 200, { saved: true, path: targetPath, chars: source.length });
@@ -26652,21 +26715,21 @@ var DevServer = class _DevServer {
26652
26715
  }
26653
26716
  let targetDir;
26654
26717
  targetDir = this.providerLoader.getUserProviderDir(category, type);
26655
- const jsonPath = path21.join(targetDir, "provider.json");
26656
- if (fs14.existsSync(jsonPath)) {
26718
+ const jsonPath = path22.join(targetDir, "provider.json");
26719
+ if (fs15.existsSync(jsonPath)) {
26657
26720
  this.json(res, 409, { error: `Provider already exists at ${targetDir}`, path: targetDir });
26658
26721
  return;
26659
26722
  }
26660
26723
  try {
26661
26724
  const result = generateFiles(type, name, category, { cdpPorts, cli, processName, installPath, binary, extensionId, version, osPaths, processNames });
26662
- fs14.mkdirSync(targetDir, { recursive: true });
26663
- fs14.writeFileSync(jsonPath, result["provider.json"], "utf-8");
26725
+ fs15.mkdirSync(targetDir, { recursive: true });
26726
+ fs15.writeFileSync(jsonPath, result["provider.json"], "utf-8");
26664
26727
  const createdFiles = ["provider.json"];
26665
26728
  if (result.files) {
26666
26729
  for (const [relPath, content] of Object.entries(result.files)) {
26667
- const fullPath = path21.join(targetDir, relPath);
26668
- fs14.mkdirSync(path21.dirname(fullPath), { recursive: true });
26669
- fs14.writeFileSync(fullPath, content, "utf-8");
26730
+ const fullPath = path22.join(targetDir, relPath);
26731
+ fs15.mkdirSync(path22.dirname(fullPath), { recursive: true });
26732
+ fs15.writeFileSync(fullPath, content, "utf-8");
26670
26733
  createdFiles.push(relPath);
26671
26734
  }
26672
26735
  }
@@ -26715,38 +26778,38 @@ var DevServer = class _DevServer {
26715
26778
  }
26716
26779
  // ─── Phase 2: Auto-Implement Backend ───
26717
26780
  getLatestScriptVersionDir(scriptsDir) {
26718
- if (!fs14.existsSync(scriptsDir)) return null;
26719
- const versions = fs14.readdirSync(scriptsDir).filter((d) => {
26781
+ if (!fs15.existsSync(scriptsDir)) return null;
26782
+ const versions = fs15.readdirSync(scriptsDir).filter((d) => {
26720
26783
  try {
26721
- return fs14.statSync(path21.join(scriptsDir, d)).isDirectory();
26784
+ return fs15.statSync(path22.join(scriptsDir, d)).isDirectory();
26722
26785
  } catch {
26723
26786
  return false;
26724
26787
  }
26725
26788
  }).sort((a, b) => b.localeCompare(a, void 0, { numeric: true, sensitivity: "base" }));
26726
26789
  if (versions.length === 0) return null;
26727
- return path21.join(scriptsDir, versions[0]);
26790
+ return path22.join(scriptsDir, versions[0]);
26728
26791
  }
26729
26792
  resolveAutoImplWritableProviderDir(category, type, requestedDir) {
26730
- const canonicalUserDir = path21.resolve(this.providerLoader.getUserProviderDir(category, type));
26731
- const desiredDir = requestedDir ? path21.resolve(requestedDir) : canonicalUserDir;
26732
- const upstreamRoot = path21.resolve(this.providerLoader.getUpstreamDir());
26733
- if (desiredDir === upstreamRoot || desiredDir.startsWith(`${upstreamRoot}${path21.sep}`)) {
26793
+ const canonicalUserDir = path22.resolve(this.providerLoader.getUserProviderDir(category, type));
26794
+ const desiredDir = requestedDir ? path22.resolve(requestedDir) : canonicalUserDir;
26795
+ const upstreamRoot = path22.resolve(this.providerLoader.getUpstreamDir());
26796
+ if (desiredDir === upstreamRoot || desiredDir.startsWith(`${upstreamRoot}${path22.sep}`)) {
26734
26797
  return { dir: null, reason: `Refusing to write into upstream provider directory: ${desiredDir}` };
26735
26798
  }
26736
- if (path21.basename(desiredDir) !== type) {
26799
+ if (path22.basename(desiredDir) !== type) {
26737
26800
  return { dir: null, reason: `Requested writable provider directory must end with '${type}': ${desiredDir}` };
26738
26801
  }
26739
26802
  const sourceDir = this.findProviderDir(type);
26740
26803
  if (!sourceDir) {
26741
26804
  return { dir: null, reason: `Provider source directory not found for '${type}'` };
26742
26805
  }
26743
- if (!fs14.existsSync(desiredDir)) {
26744
- fs14.mkdirSync(path21.dirname(desiredDir), { recursive: true });
26745
- fs14.cpSync(sourceDir, desiredDir, { recursive: true });
26806
+ if (!fs15.existsSync(desiredDir)) {
26807
+ fs15.mkdirSync(path22.dirname(desiredDir), { recursive: true });
26808
+ fs15.cpSync(sourceDir, desiredDir, { recursive: true });
26746
26809
  this.log(`Auto-implement writable copy created: ${desiredDir}`);
26747
26810
  }
26748
- const providerJson = path21.join(desiredDir, "provider.json");
26749
- if (!fs14.existsSync(providerJson)) {
26811
+ const providerJson = path22.join(desiredDir, "provider.json");
26812
+ if (!fs15.existsSync(providerJson)) {
26750
26813
  return { dir: null, reason: `provider.json not found in writable provider directory: ${desiredDir}` };
26751
26814
  }
26752
26815
  return { dir: desiredDir };
@@ -26781,7 +26844,7 @@ var DevServer = class _DevServer {
26781
26844
  setMode: "set_mode.js"
26782
26845
  };
26783
26846
  const targetFileNames = new Set(functions.map((fn) => funcToFile[fn]).filter(Boolean));
26784
- const scriptsDir = path21.join(providerDir, "scripts");
26847
+ const scriptsDir = path22.join(providerDir, "scripts");
26785
26848
  const latestScriptsDir = this.getLatestScriptVersionDir(scriptsDir);
26786
26849
  if (latestScriptsDir) {
26787
26850
  lines.push(`Scripts version directory: \`${latestScriptsDir}\``);
@@ -26789,10 +26852,10 @@ var DevServer = class _DevServer {
26789
26852
  lines.push("## \u270F\uFE0F Target Files (EDIT THESE)");
26790
26853
  lines.push("These are the ONLY files you are allowed to modify. Replace the TODO stubs with working implementations.");
26791
26854
  lines.push("");
26792
- for (const file of fs14.readdirSync(latestScriptsDir)) {
26855
+ for (const file of fs15.readdirSync(latestScriptsDir)) {
26793
26856
  if (file.endsWith(".js") && targetFileNames.has(file)) {
26794
26857
  try {
26795
- const content = fs14.readFileSync(path21.join(latestScriptsDir, file), "utf-8");
26858
+ const content = fs15.readFileSync(path22.join(latestScriptsDir, file), "utf-8");
26796
26859
  lines.push(`### \`${file}\` \u270F\uFE0F EDIT`);
26797
26860
  lines.push("```javascript");
26798
26861
  lines.push(content);
@@ -26802,14 +26865,14 @@ var DevServer = class _DevServer {
26802
26865
  }
26803
26866
  }
26804
26867
  }
26805
- const refFiles = fs14.readdirSync(latestScriptsDir).filter((f) => f.endsWith(".js") && !targetFileNames.has(f));
26868
+ const refFiles = fs15.readdirSync(latestScriptsDir).filter((f) => f.endsWith(".js") && !targetFileNames.has(f));
26806
26869
  if (refFiles.length > 0) {
26807
26870
  lines.push("## \u{1F512} Other Scripts (REFERENCE ONLY \u2014 DO NOT EDIT)");
26808
26871
  lines.push("These files are shown for context only. Do NOT modify them under any circumstances.");
26809
26872
  lines.push("");
26810
26873
  for (const file of refFiles) {
26811
26874
  try {
26812
- const content = fs14.readFileSync(path21.join(latestScriptsDir, file), "utf-8");
26875
+ const content = fs15.readFileSync(path22.join(latestScriptsDir, file), "utf-8");
26813
26876
  lines.push(`### \`${file}\` \u{1F512}`);
26814
26877
  lines.push("```javascript");
26815
26878
  lines.push(content);
@@ -26850,11 +26913,11 @@ var DevServer = class _DevServer {
26850
26913
  lines.push("");
26851
26914
  }
26852
26915
  }
26853
- const docsDir = path21.join(providerDir, "../../docs");
26916
+ const docsDir = path22.join(providerDir, "../../docs");
26854
26917
  const loadGuide = (name) => {
26855
26918
  try {
26856
- const p = path21.join(docsDir, name);
26857
- if (fs14.existsSync(p)) return fs14.readFileSync(p, "utf-8");
26919
+ const p = path22.join(docsDir, name);
26920
+ if (fs15.existsSync(p)) return fs15.readFileSync(p, "utf-8");
26858
26921
  } catch {
26859
26922
  }
26860
26923
  return null;
@@ -27027,7 +27090,7 @@ var DevServer = class _DevServer {
27027
27090
  parseApproval: "parse_approval.js"
27028
27091
  };
27029
27092
  const targetFileNames = new Set(functions.map((fn) => funcToFile[fn]).filter(Boolean));
27030
- const scriptsDir = path21.join(providerDir, "scripts");
27093
+ const scriptsDir = path22.join(providerDir, "scripts");
27031
27094
  const latestScriptsDir = this.getLatestScriptVersionDir(scriptsDir);
27032
27095
  if (latestScriptsDir) {
27033
27096
  lines.push(`Scripts version directory: \`${latestScriptsDir}\``);
@@ -27035,11 +27098,11 @@ var DevServer = class _DevServer {
27035
27098
  lines.push("## \u270F\uFE0F Target Files (EDIT THESE)");
27036
27099
  lines.push("These are the ONLY files you are allowed to modify. Replace TODO or heuristic-only logic with working PTY-aware implementations.");
27037
27100
  lines.push("");
27038
- for (const file of fs14.readdirSync(latestScriptsDir)) {
27101
+ for (const file of fs15.readdirSync(latestScriptsDir)) {
27039
27102
  if (!file.endsWith(".js")) continue;
27040
27103
  if (!targetFileNames.has(file)) continue;
27041
27104
  try {
27042
- const content = fs14.readFileSync(path21.join(latestScriptsDir, file), "utf-8");
27105
+ const content = fs15.readFileSync(path22.join(latestScriptsDir, file), "utf-8");
27043
27106
  lines.push(`### \`${file}\` \u270F\uFE0F EDIT`);
27044
27107
  lines.push("```javascript");
27045
27108
  lines.push(content);
@@ -27048,14 +27111,14 @@ var DevServer = class _DevServer {
27048
27111
  } catch {
27049
27112
  }
27050
27113
  }
27051
- const refFiles = fs14.readdirSync(latestScriptsDir).filter((f) => f.endsWith(".js") && !targetFileNames.has(f));
27114
+ const refFiles = fs15.readdirSync(latestScriptsDir).filter((f) => f.endsWith(".js") && !targetFileNames.has(f));
27052
27115
  if (refFiles.length > 0) {
27053
27116
  lines.push("## \u{1F512} Other Scripts (REFERENCE ONLY \u2014 DO NOT EDIT)");
27054
27117
  lines.push("These files are shown for context only. Do NOT modify them under any circumstances.");
27055
27118
  lines.push("");
27056
27119
  for (const file of refFiles) {
27057
27120
  try {
27058
- const content = fs14.readFileSync(path21.join(latestScriptsDir, file), "utf-8");
27121
+ const content = fs15.readFileSync(path22.join(latestScriptsDir, file), "utf-8");
27059
27122
  lines.push(`### \`${file}\` \u{1F512}`);
27060
27123
  lines.push("```javascript");
27061
27124
  lines.push(content);
@@ -27088,11 +27151,11 @@ var DevServer = class _DevServer {
27088
27151
  lines.push("");
27089
27152
  }
27090
27153
  }
27091
- const docsDir = path21.join(providerDir, "../../docs");
27154
+ const docsDir = path22.join(providerDir, "../../docs");
27092
27155
  const loadGuide = (name) => {
27093
27156
  try {
27094
- const p = path21.join(docsDir, name);
27095
- if (fs14.existsSync(p)) return fs14.readFileSync(p, "utf-8");
27157
+ const p = path22.join(docsDir, name);
27158
+ if (fs15.existsSync(p)) return fs15.readFileSync(p, "utf-8");
27096
27159
  } catch {
27097
27160
  }
27098
27161
  return null;
@@ -27967,8 +28030,8 @@ async function installExtension(ide, extension) {
27967
28030
  const res = await fetch(extension.vsixUrl);
27968
28031
  if (res.ok) {
27969
28032
  const buffer = Buffer.from(await res.arrayBuffer());
27970
- const fs15 = await import("fs");
27971
- fs15.writeFileSync(vsixPath, buffer);
28033
+ const fs16 = await import("fs");
28034
+ fs16.writeFileSync(vsixPath, buffer);
27972
28035
  return new Promise((resolve12) => {
27973
28036
  const cmd = `"${ide.cliCommand}" --install-extension "${vsixPath}" --force`;
27974
28037
  (0, import_child_process11.exec)(cmd, { timeout: 6e4 }, (error, _stdout, stderr) => {