@adhdev/daemon-core 0.9.49 → 0.9.51

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.mjs CHANGED
@@ -1328,7 +1328,7 @@ var init_spawn_env = __esm({
1328
1328
  });
1329
1329
 
1330
1330
  // src/cli-adapters/pty-transport.ts
1331
- import * as os7 from "os";
1331
+ import * as os8 from "os";
1332
1332
  function loadNodePty() {
1333
1333
  if (cachedPty !== void 0) return cachedPty;
1334
1334
  try {
@@ -1379,11 +1379,11 @@ var init_pty_transport = __esm({
1379
1379
  let cwd = options.cwd;
1380
1380
  if (cwd) {
1381
1381
  try {
1382
- const fs15 = __require("fs");
1383
- const stat = fs15.statSync(cwd);
1384
- if (!stat.isDirectory()) cwd = os7.homedir();
1382
+ const fs16 = __require("fs");
1383
+ const stat = fs16.statSync(cwd);
1384
+ if (!stat.isDirectory()) cwd = os8.homedir();
1385
1385
  } catch {
1386
- cwd = os7.homedir();
1386
+ cwd = os8.homedir();
1387
1387
  }
1388
1388
  }
1389
1389
  const handle = pty.spawn(command, args, {
@@ -1400,8 +1400,8 @@ var init_pty_transport = __esm({
1400
1400
  });
1401
1401
 
1402
1402
  // src/cli-adapters/provider-cli-shared.ts
1403
- import * as os8 from "os";
1404
- import * as path9 from "path";
1403
+ import * as os9 from "os";
1404
+ import * as path10 from "path";
1405
1405
  import { execSync as execSync3 } from "child_process";
1406
1406
  function stripAnsi(str) {
1407
1407
  return str.replace(/\x1B\][^\x07]*\x07/g, "").replace(/\x1B\][\s\S]*?\x1B\\/g, "").replace(/\x1B[P^_X][\s\S]*?(?:\x07|\x1B\\)/g, "").replace(/\x1B\[\d*[A-HJKSTfG]/g, " ").replace(/\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])/g, "").replace(/ +/g, " ");
@@ -1466,11 +1466,11 @@ function buildCliScreenSnapshot(text) {
1466
1466
  function findBinary(name) {
1467
1467
  const trimmed = String(name || "").trim();
1468
1468
  if (!trimmed) return trimmed;
1469
- const expanded = trimmed.startsWith("~") ? path9.join(os8.homedir(), trimmed.slice(1)) : trimmed;
1470
- if (path9.isAbsolute(expanded) || expanded.includes("/") || expanded.includes("\\")) {
1471
- return path9.isAbsolute(expanded) ? expanded : path9.resolve(expanded);
1469
+ const expanded = trimmed.startsWith("~") ? path10.join(os9.homedir(), trimmed.slice(1)) : trimmed;
1470
+ if (path10.isAbsolute(expanded) || expanded.includes("/") || expanded.includes("\\")) {
1471
+ return path10.isAbsolute(expanded) ? expanded : path10.resolve(expanded);
1472
1472
  }
1473
- const isWin = os8.platform() === "win32";
1473
+ const isWin = os9.platform() === "win32";
1474
1474
  try {
1475
1475
  const cmd = isWin ? `where ${trimmed}` : `which ${trimmed}`;
1476
1476
  return execSync3(cmd, {
@@ -1484,14 +1484,14 @@ function findBinary(name) {
1484
1484
  }
1485
1485
  }
1486
1486
  function isScriptBinary(binaryPath) {
1487
- if (!path9.isAbsolute(binaryPath)) return false;
1487
+ if (!path10.isAbsolute(binaryPath)) return false;
1488
1488
  try {
1489
- const fs15 = __require("fs");
1490
- const resolved = fs15.realpathSync(binaryPath);
1489
+ const fs16 = __require("fs");
1490
+ const resolved = fs16.realpathSync(binaryPath);
1491
1491
  const head = Buffer.alloc(8);
1492
- const fd = fs15.openSync(resolved, "r");
1493
- fs15.readSync(fd, head, 0, 8, 0);
1494
- fs15.closeSync(fd);
1492
+ const fd = fs16.openSync(resolved, "r");
1493
+ fs16.readSync(fd, head, 0, 8, 0);
1494
+ fs16.closeSync(fd);
1495
1495
  let i = 0;
1496
1496
  if (head[0] === 239 && head[1] === 187 && head[2] === 191) i = 3;
1497
1497
  return head[i] === 35 && head[i + 1] === 33;
@@ -1500,14 +1500,14 @@ function isScriptBinary(binaryPath) {
1500
1500
  }
1501
1501
  }
1502
1502
  function looksLikeMachOOrElf(filePath) {
1503
- if (!path9.isAbsolute(filePath)) return false;
1503
+ if (!path10.isAbsolute(filePath)) return false;
1504
1504
  try {
1505
- const fs15 = __require("fs");
1506
- const resolved = fs15.realpathSync(filePath);
1505
+ const fs16 = __require("fs");
1506
+ const resolved = fs16.realpathSync(filePath);
1507
1507
  const buf = Buffer.alloc(8);
1508
- const fd = fs15.openSync(resolved, "r");
1509
- fs15.readSync(fd, buf, 0, 8, 0);
1510
- fs15.closeSync(fd);
1508
+ const fd = fs16.openSync(resolved, "r");
1509
+ fs16.readSync(fd, buf, 0, 8, 0);
1510
+ fs16.closeSync(fd);
1511
1511
  let i = 0;
1512
1512
  if (buf[0] === 239 && buf[1] === 187 && buf[2] === 191) i = 3;
1513
1513
  const b = buf.subarray(i);
@@ -1523,7 +1523,7 @@ function looksLikeMachOOrElf(filePath) {
1523
1523
  }
1524
1524
  function shSingleQuote(arg) {
1525
1525
  if (/^[a-zA-Z0-9@%_+=:,./-]+$/.test(arg)) return arg;
1526
- if (os8.platform() === "win32") {
1526
+ if (os9.platform() === "win32") {
1527
1527
  return `"${arg.replace(/"/g, '""')}"`;
1528
1528
  }
1529
1529
  return `'${arg.replace(/'/g, `'\\''`)}'`;
@@ -1960,21 +1960,21 @@ var init_provider_cli_config = __esm({
1960
1960
  });
1961
1961
 
1962
1962
  // src/cli-adapters/provider-cli-runtime.ts
1963
- import * as os9 from "os";
1964
- import * as path10 from "path";
1963
+ import * as os10 from "os";
1964
+ import * as path11 from "path";
1965
1965
  import { DEFAULT_SESSION_HOST_COLS, DEFAULT_SESSION_HOST_ROWS } from "@adhdev/session-host-core";
1966
1966
  function resolveCliSpawnPlan(options) {
1967
1967
  const { provider, runtimeSettings, workingDir, extraArgs } = options;
1968
1968
  const { spawn: spawnConfig } = provider;
1969
1969
  const configuredCommand = typeof runtimeSettings.executablePath === "string" && runtimeSettings.executablePath.trim() ? runtimeSettings.executablePath.trim() : spawnConfig.command;
1970
1970
  const binaryPath = findBinary(configuredCommand);
1971
- const isWin = os9.platform() === "win32";
1971
+ const isWin = os10.platform() === "win32";
1972
1972
  const allArgs = [...spawnConfig.args, ...extraArgs];
1973
1973
  let shellCmd;
1974
1974
  let shellArgs;
1975
- const useShellUnix = !isWin && (!!spawnConfig.shell || !path10.isAbsolute(binaryPath) || isScriptBinary(binaryPath) || !looksLikeMachOOrElf(binaryPath));
1975
+ const useShellUnix = !isWin && (!!spawnConfig.shell || !path11.isAbsolute(binaryPath) || isScriptBinary(binaryPath) || !looksLikeMachOOrElf(binaryPath));
1976
1976
  const isCmdShim = isWin && /\.(cmd|bat)$/i.test(binaryPath);
1977
- const useShellWin = !!spawnConfig.shell || isCmdShim || !path10.isAbsolute(binaryPath) || isScriptBinary(binaryPath);
1977
+ const useShellWin = !!spawnConfig.shell || isCmdShim || !path11.isAbsolute(binaryPath) || isScriptBinary(binaryPath);
1978
1978
  const useShell = isWin ? useShellWin : useShellUnix;
1979
1979
  if (useShell) {
1980
1980
  shellCmd = isWin ? "cmd.exe" : process.env.SHELL || "/bin/zsh";
@@ -2066,7 +2066,7 @@ __export(provider_cli_adapter_exports, {
2066
2066
  sanitizeCliStandardMessageContent: () => sanitizeCliStandardMessageContent,
2067
2067
  trimLastAssistantEchoForCliMessages: () => trimLastAssistantEchoForCliMessages
2068
2068
  });
2069
- import * as os10 from "os";
2069
+ import * as os11 from "os";
2070
2070
  function normalizeComparableTranscriptText(value) {
2071
2071
  return sanitizeTerminalText(String(value || "")).replace(/\s+/g, " ").trim();
2072
2072
  }
@@ -2197,7 +2197,7 @@ var init_provider_cli_adapter = __esm({
2197
2197
  this.transportFactory = transportFactory;
2198
2198
  this.cliType = provider.type;
2199
2199
  this.cliName = provider.name;
2200
- this.workingDir = workingDir.startsWith("~") ? workingDir.replace(/^~/, os10.homedir()) : workingDir;
2200
+ this.workingDir = workingDir.startsWith("~") ? workingDir.replace(/^~/, os11.homedir()) : workingDir;
2201
2201
  const resolvedConfig = resolveCliAdapterConfig(provider);
2202
2202
  this.timeouts = resolvedConfig.timeouts;
2203
2203
  this.approvalKeys = resolvedConfig.approvalKeys;
@@ -5120,17 +5120,17 @@ function checkPathExists(paths) {
5120
5120
  return null;
5121
5121
  }
5122
5122
  async function detectIDEs(providerLoader) {
5123
- const os20 = platform();
5123
+ const os21 = platform();
5124
5124
  const results = [];
5125
5125
  for (const def of getMergedDefinitions()) {
5126
5126
  const cliPath = findCliCommand(providerLoader?.getIdeCliCommand(def.id, def.cli) || def.cli);
5127
- const appPath = checkPathExists(providerLoader?.getIdePathCandidates(def.id, def.paths[os20] || []) || []);
5127
+ const appPath = checkPathExists(providerLoader?.getIdePathCandidates(def.id, def.paths[os21] || []) || []);
5128
5128
  let resolvedCli = cliPath;
5129
- if (!resolvedCli && appPath && os20 === "darwin") {
5129
+ if (!resolvedCli && appPath && os21 === "darwin") {
5130
5130
  const bundledCli = `${appPath}/Contents/Resources/app/bin/${def.cli}`;
5131
5131
  if (existsSync4(bundledCli)) resolvedCli = bundledCli;
5132
5132
  }
5133
- if (!resolvedCli && appPath && os20 === "win32") {
5133
+ if (!resolvedCli && appPath && os21 === "win32") {
5134
5134
  const { dirname: dirname7 } = await import("path");
5135
5135
  const appDir = dirname7(appPath);
5136
5136
  const candidates = [
@@ -5147,7 +5147,7 @@ async function detectIDEs(providerLoader) {
5147
5147
  }
5148
5148
  }
5149
5149
  }
5150
- const installed = os20 === "darwin" ? !!(resolvedCli || appPath) : !!resolvedCli;
5150
+ const installed = os21 === "darwin" ? !!(resolvedCli || appPath) : !!resolvedCli;
5151
5151
  const version = resolvedCli ? getIdeVersion(resolvedCli) : null;
5152
5152
  results.push({
5153
5153
  id: def.id,
@@ -10312,6 +10312,10 @@ function resolveLegacyProviderScript(fn, scriptName, params) {
10312
10312
 
10313
10313
  // src/commands/chat-commands.ts
10314
10314
  init_contracts();
10315
+ import * as fs4 from "fs";
10316
+ import * as os6 from "os";
10317
+ import * as path8 from "path";
10318
+ import { randomUUID as randomUUID4 } from "crypto";
10315
10319
 
10316
10320
  // src/providers/provider-input-support.ts
10317
10321
  var VALID_INPUT_MEDIA_TYPES = /* @__PURE__ */ new Set(["text", "image", "audio", "video", "resource"]);
@@ -11000,10 +11004,57 @@ function buildDebugBundleText(bundle) {
11000
11004
  "```"
11001
11005
  ].join("\n");
11002
11006
  }
11007
+ function getChatDebugBundleDir() {
11008
+ const override = typeof process.env.ADHDEV_DEBUG_BUNDLE_DIR === "string" ? process.env.ADHDEV_DEBUG_BUNDLE_DIR.trim() : "";
11009
+ return override || path8.join(os6.homedir(), ".adhdev", "debug-bundles", "chat");
11010
+ }
11011
+ function safeBundleIdSegment(value, fallback) {
11012
+ const normalized = String(value || fallback).trim().replace(/[^A-Za-z0-9_.-]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 80);
11013
+ return normalized || fallback;
11014
+ }
11015
+ function createChatDebugBundleId(targetSessionId) {
11016
+ const timestamp = (/* @__PURE__ */ new Date()).toISOString().replace(/[-:.]/g, "").replace("T", "T").replace("Z", "Z");
11017
+ const sessionSegment = safeBundleIdSegment(targetSessionId, "unknown-session");
11018
+ return `chat-debug-${timestamp}-${sessionSegment}-${randomUUID4().slice(0, 8)}`;
11019
+ }
11020
+ function buildChatDebugBundleSummary(bundle) {
11021
+ const target = bundle.target && typeof bundle.target === "object" ? bundle.target : {};
11022
+ const readChat = bundle.readChat && typeof bundle.readChat === "object" ? bundle.readChat : {};
11023
+ const cli = bundle.cli && typeof bundle.cli === "object" ? bundle.cli : null;
11024
+ const frontend = bundle.frontend && typeof bundle.frontend === "object" ? bundle.frontend : null;
11025
+ return {
11026
+ createdAt: bundle.createdAt,
11027
+ targetSessionId: target.targetSessionId,
11028
+ providerType: target.providerType,
11029
+ transport: target.transport,
11030
+ readChatSuccess: readChat.success,
11031
+ readChatStatus: readChat.status,
11032
+ readChatTotalMessages: readChat.totalMessages,
11033
+ cliStatus: cli?.status,
11034
+ cliMessageCount: cli?.messageCount,
11035
+ hasFrontendSnapshot: !!frontend
11036
+ };
11037
+ }
11038
+ function storeChatDebugBundleOnDaemon(bundle, targetSessionId) {
11039
+ const bundleId = createChatDebugBundleId(targetSessionId);
11040
+ const dir = getChatDebugBundleDir();
11041
+ fs4.mkdirSync(dir, { recursive: true });
11042
+ const savedPath = path8.join(dir, `${bundleId}.json`);
11043
+ const json = `${JSON.stringify(bundle, null, 2)}
11044
+ `;
11045
+ fs4.writeFileSync(savedPath, json, { encoding: "utf8", mode: 384 });
11046
+ return { bundleId, savedPath, sizeBytes: Buffer.byteLength(json, "utf8") };
11047
+ }
11048
+ function isDaemonFileDebugDelivery(args) {
11049
+ return args?.delivery === "daemon_file" || args?.delivery === "file";
11050
+ }
11003
11051
  async function handleGetChatDebugBundle(h, args) {
11052
+ const targetSessionId = typeof args?.targetSessionId === "string" ? args.targetSessionId.trim() : "";
11053
+ if (!targetSessionId && !h.currentSession) {
11054
+ return { success: false, error: "No targetSessionId specified \u2014 cannot route command" };
11055
+ }
11004
11056
  const provider = h.getProvider(args?.agentType);
11005
11057
  const transport = getTargetTransport(h, provider);
11006
- const targetSessionId = typeof args?.targetSessionId === "string" ? args.targetSessionId.trim() : "";
11007
11058
  const providerType = provider?.type || getCurrentProviderType(h, args?.agentType || "");
11008
11059
  const adapter = isCliLikeTransport(transport) ? getTargetedCliAdapter(h, args, provider?.type) : null;
11009
11060
  const targetInstance = getTargetInstance(h, args);
@@ -11108,6 +11159,20 @@ async function handleGetChatDebugBundle(h, args) {
11108
11159
  recentDebugTrace: getRecentDebugTrace({ limit: 120 })
11109
11160
  };
11110
11161
  const bundle = sanitizeDebugBundleValue(rawBundle);
11162
+ if (isDaemonFileDebugDelivery(args)) {
11163
+ const summary = buildChatDebugBundleSummary(bundle);
11164
+ const stored = storeChatDebugBundleOnDaemon(bundle, targetSessionId || String(summary.targetSessionId || "unknown-session"));
11165
+ 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 || ""}`);
11166
+ return {
11167
+ success: true,
11168
+ delivery: "daemon_file",
11169
+ bundleId: stored.bundleId,
11170
+ savedPath: stored.savedPath,
11171
+ sizeBytes: stored.sizeBytes,
11172
+ createdAt: bundle.createdAt,
11173
+ summary
11174
+ };
11175
+ }
11111
11176
  return {
11112
11177
  success: true,
11113
11178
  bundle,
@@ -12089,9 +12154,9 @@ async function handleResolveAction(h, args) {
12089
12154
  }
12090
12155
 
12091
12156
  // src/commands/cdp-commands.ts
12092
- import * as fs4 from "fs";
12093
- import * as path8 from "path";
12094
- import * as os6 from "os";
12157
+ import * as fs5 from "fs";
12158
+ import * as path9 from "path";
12159
+ import * as os7 from "os";
12095
12160
  var KEY_TO_VK = {
12096
12161
  Backspace: 8,
12097
12162
  Tab: 9,
@@ -12345,27 +12410,27 @@ function normalizeWindowsRequestedPath(requestedPath) {
12345
12410
  function resolveSafePath(requestedPath) {
12346
12411
  const rawPath = typeof requestedPath === "string" ? requestedPath.trim() : "";
12347
12412
  const inputPath = rawPath || ".";
12348
- const home = os6.homedir();
12413
+ const home = os7.homedir();
12349
12414
  if (inputPath.startsWith("~")) {
12350
- return path8.resolve(path8.join(home, inputPath.slice(1)));
12415
+ return path9.resolve(path9.join(home, inputPath.slice(1)));
12351
12416
  }
12352
12417
  if (process.platform === "win32") {
12353
12418
  const normalized = normalizeWindowsRequestedPath(inputPath);
12354
- if (path8.win32.isAbsolute(normalized)) {
12355
- return path8.win32.normalize(normalized);
12419
+ if (path9.win32.isAbsolute(normalized)) {
12420
+ return path9.win32.normalize(normalized);
12356
12421
  }
12357
- return path8.win32.resolve(normalized);
12422
+ return path9.win32.resolve(normalized);
12358
12423
  }
12359
- if (path8.isAbsolute(inputPath)) {
12360
- return path8.normalize(inputPath);
12424
+ if (path9.isAbsolute(inputPath)) {
12425
+ return path9.normalize(inputPath);
12361
12426
  }
12362
- return path8.resolve(inputPath);
12427
+ return path9.resolve(inputPath);
12363
12428
  }
12364
12429
  function listDirectoryEntriesSafe(dirPath) {
12365
- const entries = fs4.readdirSync(dirPath, { withFileTypes: true });
12430
+ const entries = fs5.readdirSync(dirPath, { withFileTypes: true });
12366
12431
  const files = [];
12367
12432
  for (const entry of entries) {
12368
- const entryPath = path8.join(dirPath, entry.name);
12433
+ const entryPath = path9.join(dirPath, entry.name);
12369
12434
  try {
12370
12435
  if (entry.isDirectory()) {
12371
12436
  files.push({ name: entry.name, type: "directory" });
@@ -12374,14 +12439,14 @@ function listDirectoryEntriesSafe(dirPath) {
12374
12439
  if (entry.isFile()) {
12375
12440
  let size;
12376
12441
  try {
12377
- size = fs4.statSync(entryPath).size;
12442
+ size = fs5.statSync(entryPath).size;
12378
12443
  } catch {
12379
12444
  size = void 0;
12380
12445
  }
12381
12446
  files.push({ name: entry.name, type: "file", size });
12382
12447
  continue;
12383
12448
  }
12384
- const stat = fs4.statSync(entryPath);
12449
+ const stat = fs5.statSync(entryPath);
12385
12450
  files.push({
12386
12451
  name: entry.name,
12387
12452
  type: stat.isDirectory() ? "directory" : "file",
@@ -12399,7 +12464,7 @@ function listWindowsDriveEntries(excludePath) {
12399
12464
  const letter = String.fromCharCode(code);
12400
12465
  const root = `${letter}:\\`;
12401
12466
  try {
12402
- if (!fs4.existsSync(root)) continue;
12467
+ if (!fs5.existsSync(root)) continue;
12403
12468
  if (excluded && root.toLowerCase() === excluded) continue;
12404
12469
  drives.push({ name: `${letter}:`, type: "directory", path: root });
12405
12470
  } catch {
@@ -12410,7 +12475,7 @@ function listWindowsDriveEntries(excludePath) {
12410
12475
  async function handleFileRead(h, args) {
12411
12476
  try {
12412
12477
  const filePath = resolveSafePath(args?.path);
12413
- const content = fs4.readFileSync(filePath, "utf-8");
12478
+ const content = fs5.readFileSync(filePath, "utf-8");
12414
12479
  return { success: true, content, path: filePath };
12415
12480
  } catch (e) {
12416
12481
  return { success: false, error: e.message };
@@ -12419,8 +12484,8 @@ async function handleFileRead(h, args) {
12419
12484
  async function handleFileWrite(h, args) {
12420
12485
  try {
12421
12486
  const filePath = resolveSafePath(args?.path);
12422
- fs4.mkdirSync(path8.dirname(filePath), { recursive: true });
12423
- fs4.writeFileSync(filePath, args?.content || "", "utf-8");
12487
+ fs5.mkdirSync(path9.dirname(filePath), { recursive: true });
12488
+ fs5.writeFileSync(filePath, args?.content || "", "utf-8");
12424
12489
  return { success: true, path: filePath };
12425
12490
  } catch (e) {
12426
12491
  return { success: false, error: e.message };
@@ -13263,6 +13328,7 @@ var DaemonCommandHandler = class {
13263
13328
  this.logCommandStart(cmd, args);
13264
13329
  const sessionScopedCommands = /* @__PURE__ */ new Set([
13265
13330
  "read_chat",
13331
+ "get_chat_debug_bundle",
13266
13332
  "send_chat",
13267
13333
  "list_chats",
13268
13334
  "new_chat",
@@ -13521,8 +13587,8 @@ var DaemonCommandHandler = class {
13521
13587
 
13522
13588
  // src/commands/cli-manager.ts
13523
13589
  init_provider_cli_adapter();
13524
- import * as os12 from "os";
13525
- import * as path12 from "path";
13590
+ import * as os13 from "os";
13591
+ import * as path13 from "path";
13526
13592
  import * as crypto4 from "crypto";
13527
13593
  import { existsSync as existsSync10 } from "fs";
13528
13594
  import { execFileSync } from "child_process";
@@ -13531,10 +13597,10 @@ init_config();
13531
13597
 
13532
13598
  // src/providers/cli-provider-instance.ts
13533
13599
  init_contracts();
13534
- import * as os11 from "os";
13535
- import * as path11 from "path";
13600
+ import * as os12 from "os";
13601
+ import * as path12 from "path";
13536
13602
  import * as crypto3 from "crypto";
13537
- import * as fs5 from "fs";
13603
+ import * as fs6 from "fs";
13538
13604
  import { createRequire } from "module";
13539
13605
  init_provider_cli_adapter();
13540
13606
  init_logger();
@@ -13592,7 +13658,7 @@ function buildIncrementalHistoryAppendMessages(previousMessages, currentMessages
13592
13658
  var CachedDatabaseSync = null;
13593
13659
  function getDatabaseSync() {
13594
13660
  if (CachedDatabaseSync) return CachedDatabaseSync;
13595
- const requireFn = typeof __require === "function" ? __require : createRequire(path11.join(process.cwd(), "__adhdev_sqlite_loader__.js"));
13661
+ const requireFn = typeof __require === "function" ? __require : createRequire(path12.join(process.cwd(), "__adhdev_sqlite_loader__.js"));
13596
13662
  const sqliteModule = requireFn(`node:${"sqlite"}`);
13597
13663
  CachedDatabaseSync = sqliteModule.DatabaseSync;
13598
13664
  if (!CachedDatabaseSync) {
@@ -13742,10 +13808,10 @@ var CliProviderInstance = class {
13742
13808
  * Replaces the previously duplicated probeOpenCode/Codex/Goose functions.
13743
13809
  */
13744
13810
  probeSessionIdFromConfig(probe) {
13745
- const resolvedDbPath = probe.dbPath.replace(/^~/, os11.homedir());
13811
+ const resolvedDbPath = probe.dbPath.replace(/^~/, os12.homedir());
13746
13812
  const now = Date.now();
13747
13813
  if (this.cachedSqliteDbMissingUntil > now) return null;
13748
- if (!fs5.existsSync(resolvedDbPath)) {
13814
+ if (!fs6.existsSync(resolvedDbPath)) {
13749
13815
  this.cachedSqliteDbMissingUntil = now + 1e4;
13750
13816
  return null;
13751
13817
  }
@@ -14477,7 +14543,7 @@ ${effect.notification.body || ""}`.trim();
14477
14543
  };
14478
14544
  addDir(this.workingDir);
14479
14545
  try {
14480
- addDir(fs5.realpathSync.native(this.workingDir));
14546
+ addDir(fs6.realpathSync.native(this.workingDir));
14481
14547
  } catch {
14482
14548
  }
14483
14549
  return Array.from(dirs);
@@ -15681,11 +15747,11 @@ function shouldRestoreHostedRuntime(record, managerTag) {
15681
15747
  // src/commands/cli-manager.ts
15682
15748
  function isExplicitCommand(command) {
15683
15749
  const trimmed = command.trim();
15684
- return path12.isAbsolute(trimmed) || trimmed.includes("/") || trimmed.includes("\\") || trimmed.startsWith("~");
15750
+ return path13.isAbsolute(trimmed) || trimmed.includes("/") || trimmed.includes("\\") || trimmed.startsWith("~");
15685
15751
  }
15686
15752
  function expandExecutable(command) {
15687
15753
  const trimmed = command.trim();
15688
- return trimmed.startsWith("~") ? path12.join(os12.homedir(), trimmed.slice(1)) : trimmed;
15754
+ return trimmed.startsWith("~") ? path13.join(os13.homedir(), trimmed.slice(1)) : trimmed;
15689
15755
  }
15690
15756
  function commandExists(command) {
15691
15757
  const trimmed = command.trim();
@@ -15966,7 +16032,7 @@ var DaemonCliManager = class {
15966
16032
  async startSession(cliType, workingDir, cliArgs, initialModel, options) {
15967
16033
  const trimmed = (workingDir || "").trim();
15968
16034
  if (!trimmed) throw new Error("working directory required");
15969
- const resolvedDir = trimmed.startsWith("~") ? trimmed.replace(/^~/, os12.homedir()) : path12.resolve(trimmed);
16035
+ const resolvedDir = trimmed.startsWith("~") ? trimmed.replace(/^~/, os13.homedir()) : path13.resolve(trimmed);
15970
16036
  const normalizedType = this.providerLoader.resolveAlias(cliType);
15971
16037
  const rawProvider = this.providerLoader.getByAlias(cliType);
15972
16038
  const provider = rawProvider ? this.providerLoader.resolve(normalizedType) || rawProvider : void 0;
@@ -16466,13 +16532,13 @@ Run 'adhdev doctor' for detailed diagnostics.`
16466
16532
  // src/launch.ts
16467
16533
  import { execSync as execSync4, spawn as spawn2 } from "child_process";
16468
16534
  import * as net from "net";
16469
- import * as os14 from "os";
16470
- import * as path14 from "path";
16535
+ import * as os15 from "os";
16536
+ import * as path15 from "path";
16471
16537
 
16472
16538
  // src/providers/provider-loader.ts
16473
- import * as fs6 from "fs";
16474
- import * as path13 from "path";
16475
- import * as os13 from "os";
16539
+ import * as fs7 from "fs";
16540
+ import * as path14 from "path";
16541
+ import * as os14 from "os";
16476
16542
  import * as chokidar from "chokidar";
16477
16543
  init_logger();
16478
16544
 
@@ -16734,9 +16800,9 @@ var ProviderLoader = class _ProviderLoader {
16734
16800
  static siblingStderrLogged = /* @__PURE__ */ new Set();
16735
16801
  static looksLikeProviderRoot(candidate) {
16736
16802
  try {
16737
- if (!fs6.existsSync(candidate) || !fs6.statSync(candidate).isDirectory()) return false;
16803
+ if (!fs7.existsSync(candidate) || !fs7.statSync(candidate).isDirectory()) return false;
16738
16804
  return ["ide", "extension", "cli", "acp"].some(
16739
- (category) => fs6.existsSync(path13.join(candidate, category))
16805
+ (category) => fs7.existsSync(path14.join(candidate, category))
16740
16806
  );
16741
16807
  } catch {
16742
16808
  return false;
@@ -16744,20 +16810,20 @@ var ProviderLoader = class _ProviderLoader {
16744
16810
  }
16745
16811
  static hasProviderRootMarker(candidate) {
16746
16812
  try {
16747
- return fs6.existsSync(path13.join(candidate, _ProviderLoader.SIBLING_MARKER_FILE));
16813
+ return fs7.existsSync(path14.join(candidate, _ProviderLoader.SIBLING_MARKER_FILE));
16748
16814
  } catch {
16749
16815
  return false;
16750
16816
  }
16751
16817
  }
16752
16818
  detectDefaultUserDir() {
16753
- const fallback = path13.join(os13.homedir(), ".adhdev", "providers");
16819
+ const fallback = path14.join(os14.homedir(), ".adhdev", "providers");
16754
16820
  const envOptIn = process.env[_ProviderLoader.SIBLING_ENV_VAR] === "1";
16755
16821
  const visited = /* @__PURE__ */ new Set();
16756
16822
  for (const start of this.probeStarts) {
16757
- let current = path13.resolve(start);
16823
+ let current = path14.resolve(start);
16758
16824
  while (!visited.has(current)) {
16759
16825
  visited.add(current);
16760
- const siblingCandidate = path13.join(path13.dirname(current), _ProviderLoader.REPO_PROVIDER_DIRNAME);
16826
+ const siblingCandidate = path14.join(path14.dirname(current), _ProviderLoader.REPO_PROVIDER_DIRNAME);
16761
16827
  if (_ProviderLoader.looksLikeProviderRoot(siblingCandidate)) {
16762
16828
  const hasMarker = _ProviderLoader.hasProviderRootMarker(siblingCandidate);
16763
16829
  if (envOptIn || hasMarker) {
@@ -16779,7 +16845,7 @@ var ProviderLoader = class _ProviderLoader {
16779
16845
  return { path: siblingCandidate, source };
16780
16846
  }
16781
16847
  }
16782
- const parent = path13.dirname(current);
16848
+ const parent = path14.dirname(current);
16783
16849
  if (parent === current) break;
16784
16850
  current = parent;
16785
16851
  }
@@ -16789,11 +16855,11 @@ var ProviderLoader = class _ProviderLoader {
16789
16855
  constructor(options) {
16790
16856
  this.logFn = options?.logFn || LOG.forComponent("Provider").asLogFn();
16791
16857
  this.probeStarts = options?.probeStarts ?? [process.cwd(), __dirname];
16792
- this.defaultProvidersDir = path13.join(os13.homedir(), ".adhdev", "providers");
16858
+ this.defaultProvidersDir = path14.join(os14.homedir(), ".adhdev", "providers");
16793
16859
  const detected = this.detectDefaultUserDir();
16794
16860
  this.userDir = detected.path;
16795
16861
  this.userDirSource = detected.source;
16796
- this.upstreamDir = path13.join(this.defaultProvidersDir, ".upstream");
16862
+ this.upstreamDir = path14.join(this.defaultProvidersDir, ".upstream");
16797
16863
  this.disableUpstream = false;
16798
16864
  this.applySourceConfig({
16799
16865
  userDir: options?.userDir,
@@ -16852,7 +16918,7 @@ var ProviderLoader = class _ProviderLoader {
16852
16918
  this.userDir = detected.path;
16853
16919
  this.userDirSource = detected.source;
16854
16920
  }
16855
- this.upstreamDir = path13.join(this.defaultProvidersDir, ".upstream");
16921
+ this.upstreamDir = path14.join(this.defaultProvidersDir, ".upstream");
16856
16922
  this.disableUpstream = this.sourceMode === "no-upstream";
16857
16923
  if (this.explicitProviderDir) {
16858
16924
  this.log(`Config 'providerDir' applied: ${this.userDir}`);
@@ -16866,7 +16932,7 @@ var ProviderLoader = class _ProviderLoader {
16866
16932
  * Canonical provider directory shape for a given root.
16867
16933
  */
16868
16934
  getProviderDir(root, category, type) {
16869
- return path13.join(root, category, type);
16935
+ return path14.join(root, category, type);
16870
16936
  }
16871
16937
  /**
16872
16938
  * Canonical user override directory for a provider.
@@ -16893,7 +16959,7 @@ var ProviderLoader = class _ProviderLoader {
16893
16959
  resolveProviderFile(type, ...segments) {
16894
16960
  const dir = this.findProviderDirInternal(type);
16895
16961
  if (!dir) return null;
16896
- return path13.join(dir, ...segments);
16962
+ return path14.join(dir, ...segments);
16897
16963
  }
16898
16964
  /**
16899
16965
  * Load all providers (3-tier priority)
@@ -16906,7 +16972,7 @@ var ProviderLoader = class _ProviderLoader {
16906
16972
  this.providers.clear();
16907
16973
  this.providerAvailability.clear();
16908
16974
  let upstreamCount = 0;
16909
- if (!this.disableUpstream && fs6.existsSync(this.upstreamDir)) {
16975
+ if (!this.disableUpstream && fs7.existsSync(this.upstreamDir)) {
16910
16976
  upstreamCount = this.loadDir(this.upstreamDir);
16911
16977
  if (upstreamCount > 0) {
16912
16978
  this.log(`Loaded ${upstreamCount} upstream providers (auto-updated)`);
@@ -16914,7 +16980,7 @@ var ProviderLoader = class _ProviderLoader {
16914
16980
  } else if (this.disableUpstream) {
16915
16981
  this.log("Upstream loading disabled (sourceMode=no-upstream)");
16916
16982
  }
16917
- if (fs6.existsSync(this.userDir)) {
16983
+ if (fs7.existsSync(this.userDir)) {
16918
16984
  const userCount = this.loadDir(this.userDir, [".upstream"]);
16919
16985
  if (userCount > 0) {
16920
16986
  this.log(`Loaded ${userCount} user custom providers (never auto-updated)`);
@@ -16929,10 +16995,10 @@ var ProviderLoader = class _ProviderLoader {
16929
16995
  * Check if upstream directory exists and has providers.
16930
16996
  */
16931
16997
  hasUpstream() {
16932
- if (!fs6.existsSync(this.upstreamDir)) return false;
16998
+ if (!fs7.existsSync(this.upstreamDir)) return false;
16933
16999
  try {
16934
- return fs6.readdirSync(this.upstreamDir).some(
16935
- (d) => fs6.statSync(path13.join(this.upstreamDir, d)).isDirectory()
17000
+ return fs7.readdirSync(this.upstreamDir).some(
17001
+ (d) => fs7.statSync(path14.join(this.upstreamDir, d)).isDirectory()
16936
17002
  );
16937
17003
  } catch {
16938
17004
  return false;
@@ -17429,8 +17495,8 @@ var ProviderLoader = class _ProviderLoader {
17429
17495
  resolved._resolvedScriptDir = entry.scriptDir;
17430
17496
  resolved._resolvedScriptsSource = `compatibility:${entry.ideVersion}`;
17431
17497
  if (providerDir) {
17432
- const fullDir = path13.join(providerDir, entry.scriptDir);
17433
- resolved._resolvedScriptsPath = fs6.existsSync(path13.join(fullDir, "scripts.js")) ? path13.join(fullDir, "scripts.js") : fullDir;
17498
+ const fullDir = path14.join(providerDir, entry.scriptDir);
17499
+ resolved._resolvedScriptsPath = fs7.existsSync(path14.join(fullDir, "scripts.js")) ? path14.join(fullDir, "scripts.js") : fullDir;
17434
17500
  }
17435
17501
  matched = true;
17436
17502
  }
@@ -17445,8 +17511,8 @@ var ProviderLoader = class _ProviderLoader {
17445
17511
  resolved._resolvedScriptDir = base.defaultScriptDir;
17446
17512
  resolved._resolvedScriptsSource = "defaultScriptDir:version_miss";
17447
17513
  if (providerDir) {
17448
- const fullDir = path13.join(providerDir, base.defaultScriptDir);
17449
- resolved._resolvedScriptsPath = fs6.existsSync(path13.join(fullDir, "scripts.js")) ? path13.join(fullDir, "scripts.js") : fullDir;
17514
+ const fullDir = path14.join(providerDir, base.defaultScriptDir);
17515
+ resolved._resolvedScriptsPath = fs7.existsSync(path14.join(fullDir, "scripts.js")) ? path14.join(fullDir, "scripts.js") : fullDir;
17450
17516
  }
17451
17517
  }
17452
17518
  resolved._versionWarning = `Version ${currentVersion} not in compatibility matrix. Using default scripts.`;
@@ -17463,8 +17529,8 @@ var ProviderLoader = class _ProviderLoader {
17463
17529
  resolved._resolvedScriptDir = dirOverride;
17464
17530
  resolved._resolvedScriptsSource = `versions:${range}`;
17465
17531
  if (providerDir) {
17466
- const fullDir = path13.join(providerDir, dirOverride);
17467
- resolved._resolvedScriptsPath = fs6.existsSync(path13.join(fullDir, "scripts.js")) ? path13.join(fullDir, "scripts.js") : fullDir;
17532
+ const fullDir = path14.join(providerDir, dirOverride);
17533
+ resolved._resolvedScriptsPath = fs7.existsSync(path14.join(fullDir, "scripts.js")) ? path14.join(fullDir, "scripts.js") : fullDir;
17468
17534
  }
17469
17535
  }
17470
17536
  } else if (override.scripts) {
@@ -17480,8 +17546,8 @@ var ProviderLoader = class _ProviderLoader {
17480
17546
  resolved._resolvedScriptDir = base.defaultScriptDir;
17481
17547
  resolved._resolvedScriptsSource = "defaultScriptDir:no_version";
17482
17548
  if (providerDir) {
17483
- const fullDir = path13.join(providerDir, base.defaultScriptDir);
17484
- resolved._resolvedScriptsPath = fs6.existsSync(path13.join(fullDir, "scripts.js")) ? path13.join(fullDir, "scripts.js") : fullDir;
17549
+ const fullDir = path14.join(providerDir, base.defaultScriptDir);
17550
+ resolved._resolvedScriptsPath = fs7.existsSync(path14.join(fullDir, "scripts.js")) ? path14.join(fullDir, "scripts.js") : fullDir;
17485
17551
  }
17486
17552
  }
17487
17553
  }
@@ -17513,15 +17579,15 @@ var ProviderLoader = class _ProviderLoader {
17513
17579
  this.log(` [loadScriptsFromDir] ${type}: providerDir not found`);
17514
17580
  return null;
17515
17581
  }
17516
- const dir = path13.join(providerDir, scriptDir);
17517
- if (!fs6.existsSync(dir)) {
17582
+ const dir = path14.join(providerDir, scriptDir);
17583
+ if (!fs7.existsSync(dir)) {
17518
17584
  this.log(` [loadScriptsFromDir] ${type}: dir not found: ${dir}`);
17519
17585
  return null;
17520
17586
  }
17521
17587
  const cached = this.scriptsCache.get(dir);
17522
17588
  if (cached) return cached;
17523
- const scriptsJs = path13.join(dir, "scripts.js");
17524
- if (fs6.existsSync(scriptsJs)) {
17589
+ const scriptsJs = path14.join(dir, "scripts.js");
17590
+ if (fs7.existsSync(scriptsJs)) {
17525
17591
  try {
17526
17592
  delete __require.cache[__require.resolve(scriptsJs)];
17527
17593
  const loaded = __require(scriptsJs);
@@ -17542,9 +17608,9 @@ var ProviderLoader = class _ProviderLoader {
17542
17608
  watch() {
17543
17609
  this.stopWatch();
17544
17610
  const watchDir = (dir) => {
17545
- if (!fs6.existsSync(dir)) {
17611
+ if (!fs7.existsSync(dir)) {
17546
17612
  try {
17547
- fs6.mkdirSync(dir, { recursive: true });
17613
+ fs7.mkdirSync(dir, { recursive: true });
17548
17614
  } catch {
17549
17615
  return;
17550
17616
  }
@@ -17562,7 +17628,7 @@ var ProviderLoader = class _ProviderLoader {
17562
17628
  return;
17563
17629
  }
17564
17630
  if (filePath.endsWith(".js") || filePath.endsWith(".json")) {
17565
- this.log(`File changed: ${path13.basename(filePath)}, reloading...`);
17631
+ this.log(`File changed: ${path14.basename(filePath)}, reloading...`);
17566
17632
  this.reload();
17567
17633
  }
17568
17634
  };
@@ -17617,12 +17683,12 @@ var ProviderLoader = class _ProviderLoader {
17617
17683
  }
17618
17684
  const https = __require("https");
17619
17685
  const { execSync: execSync7 } = __require("child_process");
17620
- const metaPath = path13.join(this.upstreamDir, _ProviderLoader.META_FILE);
17686
+ const metaPath = path14.join(this.upstreamDir, _ProviderLoader.META_FILE);
17621
17687
  let prevEtag = "";
17622
17688
  let prevTimestamp = 0;
17623
17689
  try {
17624
- if (fs6.existsSync(metaPath)) {
17625
- const meta = JSON.parse(fs6.readFileSync(metaPath, "utf-8"));
17690
+ if (fs7.existsSync(metaPath)) {
17691
+ const meta = JSON.parse(fs7.readFileSync(metaPath, "utf-8"));
17626
17692
  prevEtag = meta.etag || "";
17627
17693
  prevTimestamp = meta.timestamp || 0;
17628
17694
  }
@@ -17677,39 +17743,39 @@ var ProviderLoader = class _ProviderLoader {
17677
17743
  return { updated: false };
17678
17744
  }
17679
17745
  this.log("Downloading latest providers from GitHub...");
17680
- const tmpTar = path13.join(os13.tmpdir(), `adhdev-providers-${Date.now()}.tar.gz`);
17681
- const tmpExtract = path13.join(os13.tmpdir(), `adhdev-providers-extract-${Date.now()}`);
17746
+ const tmpTar = path14.join(os14.tmpdir(), `adhdev-providers-${Date.now()}.tar.gz`);
17747
+ const tmpExtract = path14.join(os14.tmpdir(), `adhdev-providers-extract-${Date.now()}`);
17682
17748
  await this.downloadFile(_ProviderLoader.GITHUB_TARBALL_URL, tmpTar);
17683
- fs6.mkdirSync(tmpExtract, { recursive: true });
17749
+ fs7.mkdirSync(tmpExtract, { recursive: true });
17684
17750
  execSync7(`tar -xzf "${tmpTar}" -C "${tmpExtract}"`, { timeout: 3e4 });
17685
- const extracted = fs6.readdirSync(tmpExtract);
17751
+ const extracted = fs7.readdirSync(tmpExtract);
17686
17752
  const rootDir = extracted.find(
17687
- (d) => fs6.statSync(path13.join(tmpExtract, d)).isDirectory() && d.startsWith("adhdev-providers")
17753
+ (d) => fs7.statSync(path14.join(tmpExtract, d)).isDirectory() && d.startsWith("adhdev-providers")
17688
17754
  );
17689
17755
  if (!rootDir) throw new Error("Unexpected tarball structure");
17690
- const sourceDir = path13.join(tmpExtract, rootDir);
17756
+ const sourceDir = path14.join(tmpExtract, rootDir);
17691
17757
  const backupDir = this.upstreamDir + ".bak";
17692
- if (fs6.existsSync(this.upstreamDir)) {
17693
- if (fs6.existsSync(backupDir)) fs6.rmSync(backupDir, { recursive: true, force: true });
17694
- fs6.renameSync(this.upstreamDir, backupDir);
17758
+ if (fs7.existsSync(this.upstreamDir)) {
17759
+ if (fs7.existsSync(backupDir)) fs7.rmSync(backupDir, { recursive: true, force: true });
17760
+ fs7.renameSync(this.upstreamDir, backupDir);
17695
17761
  }
17696
17762
  try {
17697
17763
  this.copyDirRecursive(sourceDir, this.upstreamDir);
17698
17764
  this.writeMeta(metaPath, etag || `ts-${Date.now()}`, Date.now());
17699
- if (fs6.existsSync(backupDir)) fs6.rmSync(backupDir, { recursive: true, force: true });
17765
+ if (fs7.existsSync(backupDir)) fs7.rmSync(backupDir, { recursive: true, force: true });
17700
17766
  } catch (e) {
17701
- if (fs6.existsSync(backupDir)) {
17702
- if (fs6.existsSync(this.upstreamDir)) fs6.rmSync(this.upstreamDir, { recursive: true, force: true });
17703
- fs6.renameSync(backupDir, this.upstreamDir);
17767
+ if (fs7.existsSync(backupDir)) {
17768
+ if (fs7.existsSync(this.upstreamDir)) fs7.rmSync(this.upstreamDir, { recursive: true, force: true });
17769
+ fs7.renameSync(backupDir, this.upstreamDir);
17704
17770
  }
17705
17771
  throw e;
17706
17772
  }
17707
17773
  try {
17708
- fs6.rmSync(tmpTar, { force: true });
17774
+ fs7.rmSync(tmpTar, { force: true });
17709
17775
  } catch {
17710
17776
  }
17711
17777
  try {
17712
- fs6.rmSync(tmpExtract, { recursive: true, force: true });
17778
+ fs7.rmSync(tmpExtract, { recursive: true, force: true });
17713
17779
  } catch {
17714
17780
  }
17715
17781
  const upstreamCount = this.countProviders(this.upstreamDir);
@@ -17741,7 +17807,7 @@ var ProviderLoader = class _ProviderLoader {
17741
17807
  reject(new Error(`HTTP ${res.statusCode}`));
17742
17808
  return;
17743
17809
  }
17744
- const ws = fs6.createWriteStream(destPath);
17810
+ const ws = fs7.createWriteStream(destPath);
17745
17811
  res.pipe(ws);
17746
17812
  ws.on("finish", () => {
17747
17813
  ws.close();
@@ -17760,22 +17826,22 @@ var ProviderLoader = class _ProviderLoader {
17760
17826
  }
17761
17827
  /** Recursive directory copy */
17762
17828
  copyDirRecursive(src, dest) {
17763
- fs6.mkdirSync(dest, { recursive: true });
17764
- for (const entry of fs6.readdirSync(src, { withFileTypes: true })) {
17765
- const srcPath = path13.join(src, entry.name);
17766
- const destPath = path13.join(dest, entry.name);
17829
+ fs7.mkdirSync(dest, { recursive: true });
17830
+ for (const entry of fs7.readdirSync(src, { withFileTypes: true })) {
17831
+ const srcPath = path14.join(src, entry.name);
17832
+ const destPath = path14.join(dest, entry.name);
17767
17833
  if (entry.isDirectory()) {
17768
17834
  this.copyDirRecursive(srcPath, destPath);
17769
17835
  } else {
17770
- fs6.copyFileSync(srcPath, destPath);
17836
+ fs7.copyFileSync(srcPath, destPath);
17771
17837
  }
17772
17838
  }
17773
17839
  }
17774
17840
  /** .meta.json save */
17775
17841
  writeMeta(metaPath, etag, timestamp) {
17776
17842
  try {
17777
- fs6.mkdirSync(path13.dirname(metaPath), { recursive: true });
17778
- fs6.writeFileSync(metaPath, JSON.stringify({
17843
+ fs7.mkdirSync(path14.dirname(metaPath), { recursive: true });
17844
+ fs7.writeFileSync(metaPath, JSON.stringify({
17779
17845
  etag,
17780
17846
  timestamp,
17781
17847
  lastCheck: new Date(timestamp).toISOString(),
@@ -17786,12 +17852,12 @@ var ProviderLoader = class _ProviderLoader {
17786
17852
  }
17787
17853
  /** Count provider files (provider.js or provider.json) */
17788
17854
  countProviders(dir) {
17789
- if (!fs6.existsSync(dir)) return 0;
17855
+ if (!fs7.existsSync(dir)) return 0;
17790
17856
  let count = 0;
17791
17857
  const scan = (d) => {
17792
17858
  try {
17793
- for (const entry of fs6.readdirSync(d, { withFileTypes: true })) {
17794
- if (entry.isDirectory()) scan(path13.join(d, entry.name));
17859
+ for (const entry of fs7.readdirSync(d, { withFileTypes: true })) {
17860
+ if (entry.isDirectory()) scan(path14.join(d, entry.name));
17795
17861
  else if (entry.name === "provider.json") count++;
17796
17862
  }
17797
17863
  } catch {
@@ -18017,19 +18083,19 @@ var ProviderLoader = class _ProviderLoader {
18017
18083
  const cat = provider.category;
18018
18084
  const searchRoots = this.getProviderRoots();
18019
18085
  for (const root of searchRoots) {
18020
- if (!fs6.existsSync(root)) continue;
18086
+ if (!fs7.existsSync(root)) continue;
18021
18087
  const candidate = this.getProviderDir(root, cat, type);
18022
- if (fs6.existsSync(path13.join(candidate, "provider.json"))) return candidate;
18023
- const catDir = path13.join(root, cat);
18024
- if (fs6.existsSync(catDir)) {
18088
+ if (fs7.existsSync(path14.join(candidate, "provider.json"))) return candidate;
18089
+ const catDir = path14.join(root, cat);
18090
+ if (fs7.existsSync(catDir)) {
18025
18091
  try {
18026
- for (const entry of fs6.readdirSync(catDir, { withFileTypes: true })) {
18092
+ for (const entry of fs7.readdirSync(catDir, { withFileTypes: true })) {
18027
18093
  if (!entry.isDirectory()) continue;
18028
- const jsonPath = path13.join(catDir, entry.name, "provider.json");
18029
- if (fs6.existsSync(jsonPath)) {
18094
+ const jsonPath = path14.join(catDir, entry.name, "provider.json");
18095
+ if (fs7.existsSync(jsonPath)) {
18030
18096
  try {
18031
- const data = JSON.parse(fs6.readFileSync(jsonPath, "utf-8"));
18032
- if (data.type === type) return path13.join(catDir, entry.name);
18097
+ const data = JSON.parse(fs7.readFileSync(jsonPath, "utf-8"));
18098
+ if (data.type === type) return path14.join(catDir, entry.name);
18033
18099
  } catch {
18034
18100
  }
18035
18101
  }
@@ -18046,8 +18112,8 @@ var ProviderLoader = class _ProviderLoader {
18046
18112
  * (template substitution is NOT applied here — scripts.js handles that)
18047
18113
  */
18048
18114
  buildScriptWrappersFromDir(dir) {
18049
- const scriptsJs = path13.join(dir, "scripts.js");
18050
- if (fs6.existsSync(scriptsJs)) {
18115
+ const scriptsJs = path14.join(dir, "scripts.js");
18116
+ if (fs7.existsSync(scriptsJs)) {
18051
18117
  try {
18052
18118
  delete __require.cache[__require.resolve(scriptsJs)];
18053
18119
  return __require(scriptsJs);
@@ -18057,13 +18123,13 @@ var ProviderLoader = class _ProviderLoader {
18057
18123
  const toCamel = (name) => name.replace(/_([a-z])/g, (_, c) => c.toUpperCase());
18058
18124
  const result = {};
18059
18125
  try {
18060
- for (const file of fs6.readdirSync(dir)) {
18126
+ for (const file of fs7.readdirSync(dir)) {
18061
18127
  if (!file.endsWith(".js")) continue;
18062
18128
  const scriptName = toCamel(file.replace(".js", ""));
18063
- const filePath = path13.join(dir, file);
18129
+ const filePath = path14.join(dir, file);
18064
18130
  result[scriptName] = (...args) => {
18065
18131
  try {
18066
- let content = fs6.readFileSync(filePath, "utf-8");
18132
+ let content = fs7.readFileSync(filePath, "utf-8");
18067
18133
  if (args[0] && typeof args[0] === "object") {
18068
18134
  for (const [key, val] of Object.entries(args[0])) {
18069
18135
  let v = val;
@@ -18109,20 +18175,20 @@ var ProviderLoader = class _ProviderLoader {
18109
18175
  * Structure: dir/category/agent-name/provider.{json,js}
18110
18176
  */
18111
18177
  loadDir(dir, excludeDirs) {
18112
- if (!fs6.existsSync(dir)) return 0;
18178
+ if (!fs7.existsSync(dir)) return 0;
18113
18179
  let count = 0;
18114
18180
  const scan = (d) => {
18115
18181
  let entries;
18116
18182
  try {
18117
- entries = fs6.readdirSync(d, { withFileTypes: true });
18183
+ entries = fs7.readdirSync(d, { withFileTypes: true });
18118
18184
  } catch {
18119
18185
  return;
18120
18186
  }
18121
18187
  const hasJson = entries.some((e) => e.name === "provider.json");
18122
18188
  if (hasJson) {
18123
- const jsonPath = path13.join(d, "provider.json");
18189
+ const jsonPath = path14.join(d, "provider.json");
18124
18190
  try {
18125
- const raw = fs6.readFileSync(jsonPath, "utf-8");
18191
+ const raw = fs7.readFileSync(jsonPath, "utf-8");
18126
18192
  const mod = JSON.parse(raw);
18127
18193
  if (typeof mod.extensionIdPattern === "string") {
18128
18194
  const flags = mod.extensionIdPattern_flags || "";
@@ -18141,8 +18207,8 @@ var ProviderLoader = class _ProviderLoader {
18141
18207
  this.log(`\u26A0 Invalid provider at ${jsonPath}: ${validation.errors.join("; ")}`);
18142
18208
  } else {
18143
18209
  const hasCompatibility = Array.isArray(normalizedProvider.compatibility);
18144
- const scriptsPath = path13.join(d, "scripts.js");
18145
- if (!hasCompatibility && fs6.existsSync(scriptsPath)) {
18210
+ const scriptsPath = path14.join(d, "scripts.js");
18211
+ if (!hasCompatibility && fs7.existsSync(scriptsPath)) {
18146
18212
  try {
18147
18213
  delete __require.cache[__require.resolve(scriptsPath)];
18148
18214
  const scripts = __require(scriptsPath);
@@ -18167,7 +18233,7 @@ var ProviderLoader = class _ProviderLoader {
18167
18233
  if (!entry.isDirectory()) continue;
18168
18234
  if (entry.name.startsWith("_") || entry.name.startsWith(".")) continue;
18169
18235
  if (excludeDirs && d === dir && excludeDirs.includes(entry.name)) continue;
18170
- scan(path13.join(d, entry.name));
18236
+ scan(path14.join(d, entry.name));
18171
18237
  }
18172
18238
  }
18173
18239
  };
@@ -18357,7 +18423,7 @@ async function isCdpActive(port) {
18357
18423
  });
18358
18424
  }
18359
18425
  async function killIdeProcess(ideId) {
18360
- const plat = os14.platform();
18426
+ const plat = os15.platform();
18361
18427
  const appName = getMacAppIdentifiers()[ideId];
18362
18428
  const winProcesses = getWinProcessNames()[ideId];
18363
18429
  try {
@@ -18418,7 +18484,7 @@ async function killIdeProcess(ideId) {
18418
18484
  }
18419
18485
  }
18420
18486
  function isIdeRunning(ideId) {
18421
- const plat = os14.platform();
18487
+ const plat = os15.platform();
18422
18488
  try {
18423
18489
  if (plat === "darwin") {
18424
18490
  const appName = getMacAppIdentifiers()[ideId];
@@ -18473,7 +18539,7 @@ function isIdeRunning(ideId) {
18473
18539
  }
18474
18540
  }
18475
18541
  function detectCurrentWorkspace(ideId) {
18476
- const plat = os14.platform();
18542
+ const plat = os15.platform();
18477
18543
  if (plat === "darwin") {
18478
18544
  try {
18479
18545
  const appName = getMacAppIdentifiers()[ideId];
@@ -18488,17 +18554,17 @@ function detectCurrentWorkspace(ideId) {
18488
18554
  }
18489
18555
  } else if (plat === "win32") {
18490
18556
  try {
18491
- const fs15 = __require("fs");
18557
+ const fs16 = __require("fs");
18492
18558
  const appNameMap = getMacAppIdentifiers();
18493
18559
  const appName = appNameMap[ideId];
18494
18560
  if (appName) {
18495
- const storagePath = path14.join(
18496
- process.env.APPDATA || path14.join(os14.homedir(), "AppData", "Roaming"),
18561
+ const storagePath = path15.join(
18562
+ process.env.APPDATA || path15.join(os15.homedir(), "AppData", "Roaming"),
18497
18563
  appName,
18498
18564
  "storage.json"
18499
18565
  );
18500
- if (fs15.existsSync(storagePath)) {
18501
- const data = JSON.parse(fs15.readFileSync(storagePath, "utf-8"));
18566
+ if (fs16.existsSync(storagePath)) {
18567
+ const data = JSON.parse(fs16.readFileSync(storagePath, "utf-8"));
18502
18568
  const workspaces = data?.openedPathsList?.workspaces3 || data?.openedPathsList?.entries || [];
18503
18569
  if (workspaces.length > 0) {
18504
18570
  const recent = workspaces[0];
@@ -18515,7 +18581,7 @@ function detectCurrentWorkspace(ideId) {
18515
18581
  return void 0;
18516
18582
  }
18517
18583
  async function launchWithCdp(options = {}) {
18518
- const platform10 = os14.platform();
18584
+ const platform10 = os15.platform();
18519
18585
  let targetIde;
18520
18586
  const ides = await detectIDEs(getProviderLoader());
18521
18587
  if (options.ideId) {
@@ -18670,14 +18736,14 @@ init_config();
18670
18736
  init_logger();
18671
18737
 
18672
18738
  // src/logging/command-log.ts
18673
- import * as fs7 from "fs";
18674
- import * as path15 from "path";
18675
- import * as os15 from "os";
18676
- 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");
18739
+ import * as fs8 from "fs";
18740
+ import * as path16 from "path";
18741
+ import * as os16 from "os";
18742
+ 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");
18677
18743
  var MAX_FILE_SIZE = 5 * 1024 * 1024;
18678
18744
  var MAX_DAYS = 7;
18679
18745
  try {
18680
- fs7.mkdirSync(LOG_DIR2, { recursive: true });
18746
+ fs8.mkdirSync(LOG_DIR2, { recursive: true });
18681
18747
  } catch {
18682
18748
  }
18683
18749
  var SENSITIVE_KEYS = /* @__PURE__ */ new Set([
@@ -18711,19 +18777,19 @@ function getDateStr2() {
18711
18777
  return (/* @__PURE__ */ new Date()).toISOString().slice(0, 10);
18712
18778
  }
18713
18779
  var currentDate2 = getDateStr2();
18714
- var currentFile = path15.join(LOG_DIR2, `commands-${currentDate2}.jsonl`);
18780
+ var currentFile = path16.join(LOG_DIR2, `commands-${currentDate2}.jsonl`);
18715
18781
  var writeCount2 = 0;
18716
18782
  function checkRotation() {
18717
18783
  const today = getDateStr2();
18718
18784
  if (today !== currentDate2) {
18719
18785
  currentDate2 = today;
18720
- currentFile = path15.join(LOG_DIR2, `commands-${currentDate2}.jsonl`);
18786
+ currentFile = path16.join(LOG_DIR2, `commands-${currentDate2}.jsonl`);
18721
18787
  cleanOldFiles();
18722
18788
  }
18723
18789
  }
18724
18790
  function cleanOldFiles() {
18725
18791
  try {
18726
- const files = fs7.readdirSync(LOG_DIR2).filter((f) => f.startsWith("commands-") && f.endsWith(".jsonl"));
18792
+ const files = fs8.readdirSync(LOG_DIR2).filter((f) => f.startsWith("commands-") && f.endsWith(".jsonl"));
18727
18793
  const cutoff = /* @__PURE__ */ new Date();
18728
18794
  cutoff.setDate(cutoff.getDate() - MAX_DAYS);
18729
18795
  const cutoffStr = cutoff.toISOString().slice(0, 10);
@@ -18731,7 +18797,7 @@ function cleanOldFiles() {
18731
18797
  const dateMatch = file.match(/commands-(\d{4}-\d{2}-\d{2})/);
18732
18798
  if (dateMatch && dateMatch[1] < cutoffStr) {
18733
18799
  try {
18734
- fs7.unlinkSync(path15.join(LOG_DIR2, file));
18800
+ fs8.unlinkSync(path16.join(LOG_DIR2, file));
18735
18801
  } catch {
18736
18802
  }
18737
18803
  }
@@ -18741,14 +18807,14 @@ function cleanOldFiles() {
18741
18807
  }
18742
18808
  function checkSize() {
18743
18809
  try {
18744
- const stat = fs7.statSync(currentFile);
18810
+ const stat = fs8.statSync(currentFile);
18745
18811
  if (stat.size > MAX_FILE_SIZE) {
18746
18812
  const backup = currentFile.replace(".jsonl", ".1.jsonl");
18747
18813
  try {
18748
- fs7.unlinkSync(backup);
18814
+ fs8.unlinkSync(backup);
18749
18815
  } catch {
18750
18816
  }
18751
- fs7.renameSync(currentFile, backup);
18817
+ fs8.renameSync(currentFile, backup);
18752
18818
  }
18753
18819
  } catch {
18754
18820
  }
@@ -18781,14 +18847,14 @@ function logCommand(entry) {
18781
18847
  ...entry.error ? { err: entry.error } : {},
18782
18848
  ...entry.durationMs !== void 0 ? { ms: entry.durationMs } : {}
18783
18849
  });
18784
- fs7.appendFileSync(currentFile, line + "\n");
18850
+ fs8.appendFileSync(currentFile, line + "\n");
18785
18851
  } catch {
18786
18852
  }
18787
18853
  }
18788
18854
  function getRecentCommands(count = 50) {
18789
18855
  try {
18790
- if (!fs7.existsSync(currentFile)) return [];
18791
- const content = fs7.readFileSync(currentFile, "utf-8");
18856
+ if (!fs8.existsSync(currentFile)) return [];
18857
+ const content = fs8.readFileSync(currentFile, "utf-8");
18792
18858
  const lines = content.trim().split("\n").filter(Boolean);
18793
18859
  return lines.slice(-count).map((line) => {
18794
18860
  try {
@@ -18818,7 +18884,7 @@ init_logger();
18818
18884
 
18819
18885
  // src/status/snapshot.ts
18820
18886
  init_config();
18821
- import * as os16 from "os";
18887
+ import * as os17 from "os";
18822
18888
  init_terminal_screen();
18823
18889
  init_logger();
18824
18890
  var READ_DEBUG_ENABLED = process.argv.includes("--dev") || process.env.ADHDEV_READ_DEBUG === "1";
@@ -18872,8 +18938,8 @@ function buildAvailableProviders(providerLoader) {
18872
18938
  }
18873
18939
  function buildMachineInfo(profile = "full") {
18874
18940
  const base = {
18875
- hostname: os16.hostname(),
18876
- platform: os16.platform()
18941
+ hostname: os17.hostname(),
18942
+ platform: os17.platform()
18877
18943
  };
18878
18944
  if (profile === "live") {
18879
18945
  return base;
@@ -18882,23 +18948,23 @@ function buildMachineInfo(profile = "full") {
18882
18948
  const memSnap2 = getHostMemorySnapshot();
18883
18949
  return {
18884
18950
  ...base,
18885
- arch: os16.arch(),
18886
- cpus: os16.cpus().length,
18951
+ arch: os17.arch(),
18952
+ cpus: os17.cpus().length,
18887
18953
  totalMem: memSnap2.totalMem,
18888
- release: os16.release()
18954
+ release: os17.release()
18889
18955
  };
18890
18956
  }
18891
18957
  const memSnap = getHostMemorySnapshot();
18892
18958
  return {
18893
18959
  ...base,
18894
- arch: os16.arch(),
18895
- cpus: os16.cpus().length,
18960
+ arch: os17.arch(),
18961
+ cpus: os17.cpus().length,
18896
18962
  totalMem: memSnap.totalMem,
18897
18963
  freeMem: memSnap.freeMem,
18898
18964
  availableMem: memSnap.availableMem,
18899
- loadavg: os16.loadavg(),
18900
- uptime: os16.uptime(),
18901
- release: os16.release()
18965
+ loadavg: os17.loadavg(),
18966
+ uptime: os17.uptime(),
18967
+ release: os17.release()
18902
18968
  };
18903
18969
  }
18904
18970
  function parseMessageTime(value) {
@@ -19125,42 +19191,42 @@ function buildStatusSnapshot(options) {
19125
19191
  // src/commands/upgrade-helper.ts
19126
19192
  import { execFileSync as execFileSync2 } from "child_process";
19127
19193
  import { spawn as spawn3 } from "child_process";
19128
- import * as fs8 from "fs";
19129
- import * as os17 from "os";
19130
- import * as path16 from "path";
19194
+ import * as fs9 from "fs";
19195
+ import * as os18 from "os";
19196
+ import * as path17 from "path";
19131
19197
  var UPGRADE_HELPER_ENV = "ADHDEV_DAEMON_UPGRADE_HELPER";
19132
19198
  function getUpgradeLogPath() {
19133
- const home = os17.homedir();
19134
- const dir = path16.join(home, ".adhdev");
19135
- fs8.mkdirSync(dir, { recursive: true });
19136
- return path16.join(dir, "daemon-upgrade.log");
19199
+ const home = os18.homedir();
19200
+ const dir = path17.join(home, ".adhdev");
19201
+ fs9.mkdirSync(dir, { recursive: true });
19202
+ return path17.join(dir, "daemon-upgrade.log");
19137
19203
  }
19138
19204
  function appendUpgradeLog(message) {
19139
19205
  const line = `[${(/* @__PURE__ */ new Date()).toISOString()}] ${message}
19140
19206
  `;
19141
19207
  try {
19142
- fs8.appendFileSync(getUpgradeLogPath(), line, "utf8");
19208
+ fs9.appendFileSync(getUpgradeLogPath(), line, "utf8");
19143
19209
  } catch {
19144
19210
  }
19145
19211
  }
19146
19212
  function resolveSiblingNpmInvocation(nodeExecutable, platform10 = process.platform) {
19147
- const binDir = path16.dirname(nodeExecutable);
19213
+ const binDir = path17.dirname(nodeExecutable);
19148
19214
  if (platform10 === "win32") {
19149
- const npmCliPath = path16.join(binDir, "node_modules", "npm", "bin", "npm-cli.js");
19150
- if (fs8.existsSync(npmCliPath)) {
19215
+ const npmCliPath = path17.join(binDir, "node_modules", "npm", "bin", "npm-cli.js");
19216
+ if (fs9.existsSync(npmCliPath)) {
19151
19217
  return { executable: nodeExecutable, argsPrefix: [npmCliPath], execOptions: getNpmExecOptions(platform10) };
19152
19218
  }
19153
19219
  for (const candidate of ["npm.exe", "npm"]) {
19154
- const candidatePath = path16.join(binDir, candidate);
19155
- if (fs8.existsSync(candidatePath)) {
19220
+ const candidatePath = path17.join(binDir, candidate);
19221
+ if (fs9.existsSync(candidatePath)) {
19156
19222
  return { executable: candidatePath, argsPrefix: [], execOptions: getNpmExecOptions(platform10) };
19157
19223
  }
19158
19224
  }
19159
19225
  return { executable: nodeExecutable, argsPrefix: [npmCliPath], execOptions: getNpmExecOptions(platform10) };
19160
19226
  }
19161
19227
  for (const candidate of ["npm"]) {
19162
- const candidatePath = path16.join(binDir, candidate);
19163
- if (fs8.existsSync(candidatePath)) {
19228
+ const candidatePath = path17.join(binDir, candidate);
19229
+ if (fs9.existsSync(candidatePath)) {
19164
19230
  return { executable: candidatePath, argsPrefix: [], execOptions: getNpmExecOptions(platform10) };
19165
19231
  }
19166
19232
  }
@@ -19170,22 +19236,22 @@ function findCurrentPackageRoot(currentCliPath, packageName) {
19170
19236
  if (!currentCliPath) return null;
19171
19237
  let resolvedPath = currentCliPath;
19172
19238
  try {
19173
- resolvedPath = fs8.realpathSync.native(currentCliPath);
19239
+ resolvedPath = fs9.realpathSync.native(currentCliPath);
19174
19240
  } catch {
19175
19241
  }
19176
19242
  let currentDir = resolvedPath;
19177
19243
  try {
19178
- if (fs8.statSync(resolvedPath).isFile()) {
19179
- currentDir = path16.dirname(resolvedPath);
19244
+ if (fs9.statSync(resolvedPath).isFile()) {
19245
+ currentDir = path17.dirname(resolvedPath);
19180
19246
  }
19181
19247
  } catch {
19182
- currentDir = path16.dirname(resolvedPath);
19248
+ currentDir = path17.dirname(resolvedPath);
19183
19249
  }
19184
19250
  while (true) {
19185
- const packageJsonPath = path16.join(currentDir, "package.json");
19251
+ const packageJsonPath = path17.join(currentDir, "package.json");
19186
19252
  try {
19187
- if (fs8.existsSync(packageJsonPath)) {
19188
- const parsed = JSON.parse(fs8.readFileSync(packageJsonPath, "utf8"));
19253
+ if (fs9.existsSync(packageJsonPath)) {
19254
+ const parsed = JSON.parse(fs9.readFileSync(packageJsonPath, "utf8"));
19189
19255
  if (parsed?.name === packageName) {
19190
19256
  const normalized = currentDir.replace(/\\/g, "/");
19191
19257
  return normalized.includes("/node_modules/") ? currentDir : null;
@@ -19193,7 +19259,7 @@ function findCurrentPackageRoot(currentCliPath, packageName) {
19193
19259
  }
19194
19260
  } catch {
19195
19261
  }
19196
- const parentDir = path16.dirname(currentDir);
19262
+ const parentDir = path17.dirname(currentDir);
19197
19263
  if (parentDir === currentDir) {
19198
19264
  return null;
19199
19265
  }
@@ -19201,13 +19267,13 @@ function findCurrentPackageRoot(currentCliPath, packageName) {
19201
19267
  }
19202
19268
  }
19203
19269
  function resolveInstallPrefixFromPackageRoot(packageRoot, packageName) {
19204
- const nodeModulesDir = packageName.startsWith("@") ? path16.dirname(path16.dirname(packageRoot)) : path16.dirname(packageRoot);
19205
- if (path16.basename(nodeModulesDir) !== "node_modules") {
19270
+ const nodeModulesDir = packageName.startsWith("@") ? path17.dirname(path17.dirname(packageRoot)) : path17.dirname(packageRoot);
19271
+ if (path17.basename(nodeModulesDir) !== "node_modules") {
19206
19272
  return null;
19207
19273
  }
19208
- const maybeLibDir = path16.dirname(nodeModulesDir);
19209
- if (path16.basename(maybeLibDir) === "lib") {
19210
- return path16.dirname(maybeLibDir);
19274
+ const maybeLibDir = path17.dirname(nodeModulesDir);
19275
+ if (path17.basename(maybeLibDir) === "lib") {
19276
+ return path17.dirname(maybeLibDir);
19211
19277
  }
19212
19278
  return maybeLibDir;
19213
19279
  }
@@ -19322,10 +19388,10 @@ async function waitForPidExit(pid, timeoutMs) {
19322
19388
  }
19323
19389
  }
19324
19390
  function stopSessionHostProcesses(appName) {
19325
- const pidFile = path16.join(os17.homedir(), ".adhdev", `${appName}-session-host.pid`);
19391
+ const pidFile = path17.join(os18.homedir(), ".adhdev", `${appName}-session-host.pid`);
19326
19392
  try {
19327
- if (fs8.existsSync(pidFile)) {
19328
- const pid = Number.parseInt(fs8.readFileSync(pidFile, "utf8").trim(), 10);
19393
+ if (fs9.existsSync(pidFile)) {
19394
+ const pid = Number.parseInt(fs9.readFileSync(pidFile, "utf8").trim(), 10);
19329
19395
  if (Number.isFinite(pid) && pid !== process.pid && isManagedSessionHostPid(pid)) {
19330
19396
  killPid(pid);
19331
19397
  }
@@ -19333,15 +19399,15 @@ function stopSessionHostProcesses(appName) {
19333
19399
  } catch {
19334
19400
  } finally {
19335
19401
  try {
19336
- fs8.unlinkSync(pidFile);
19402
+ fs9.unlinkSync(pidFile);
19337
19403
  } catch {
19338
19404
  }
19339
19405
  }
19340
19406
  }
19341
19407
  function removeDaemonPidFile() {
19342
- const pidFile = path16.join(os17.homedir(), ".adhdev", "daemon.pid");
19408
+ const pidFile = path17.join(os18.homedir(), ".adhdev", "daemon.pid");
19343
19409
  try {
19344
- fs8.unlinkSync(pidFile);
19410
+ fs9.unlinkSync(pidFile);
19345
19411
  } catch {
19346
19412
  }
19347
19413
  }
@@ -19350,7 +19416,7 @@ function cleanupStaleGlobalInstallDirs(pkgName, surface) {
19350
19416
  const npmRoot = String(execNpmCommandSync(["root", "-g", ...prefixArgs], { encoding: "utf8" }, surface)).trim();
19351
19417
  if (!npmRoot) return;
19352
19418
  const npmPrefix = surface.installPrefix || String(execNpmCommandSync(["prefix", "-g", ...prefixArgs], { encoding: "utf8" }, surface)).trim();
19353
- const binDir = process.platform === "win32" ? npmPrefix : path16.join(npmPrefix, "bin");
19419
+ const binDir = process.platform === "win32" ? npmPrefix : path17.join(npmPrefix, "bin");
19354
19420
  const packageBaseName = pkgName.startsWith("@") ? pkgName.split("/")[1] : pkgName;
19355
19421
  const binNames = /* @__PURE__ */ new Set([packageBaseName]);
19356
19422
  if (pkgName === "@adhdev/daemon-standalone") {
@@ -19358,25 +19424,25 @@ function cleanupStaleGlobalInstallDirs(pkgName, surface) {
19358
19424
  }
19359
19425
  if (pkgName.startsWith("@")) {
19360
19426
  const [scope, name] = pkgName.split("/");
19361
- const scopeDir = path16.join(npmRoot, scope);
19362
- if (!fs8.existsSync(scopeDir)) return;
19363
- for (const entry of fs8.readdirSync(scopeDir)) {
19427
+ const scopeDir = path17.join(npmRoot, scope);
19428
+ if (!fs9.existsSync(scopeDir)) return;
19429
+ for (const entry of fs9.readdirSync(scopeDir)) {
19364
19430
  if (!entry.startsWith(`.${name}-`)) continue;
19365
- fs8.rmSync(path16.join(scopeDir, entry), { recursive: true, force: true });
19366
- appendUpgradeLog(`Removed stale scoped staging dir: ${path16.join(scopeDir, entry)}`);
19431
+ fs9.rmSync(path17.join(scopeDir, entry), { recursive: true, force: true });
19432
+ appendUpgradeLog(`Removed stale scoped staging dir: ${path17.join(scopeDir, entry)}`);
19367
19433
  }
19368
19434
  } else {
19369
- for (const entry of fs8.readdirSync(npmRoot)) {
19435
+ for (const entry of fs9.readdirSync(npmRoot)) {
19370
19436
  if (!entry.startsWith(`.${pkgName}-`)) continue;
19371
- fs8.rmSync(path16.join(npmRoot, entry), { recursive: true, force: true });
19372
- appendUpgradeLog(`Removed stale staging dir: ${path16.join(npmRoot, entry)}`);
19437
+ fs9.rmSync(path17.join(npmRoot, entry), { recursive: true, force: true });
19438
+ appendUpgradeLog(`Removed stale staging dir: ${path17.join(npmRoot, entry)}`);
19373
19439
  }
19374
19440
  }
19375
- if (fs8.existsSync(binDir)) {
19376
- for (const entry of fs8.readdirSync(binDir)) {
19441
+ if (fs9.existsSync(binDir)) {
19442
+ for (const entry of fs9.readdirSync(binDir)) {
19377
19443
  if (!Array.from(binNames).some((name) => entry.startsWith(`.${name}-`))) continue;
19378
- fs8.rmSync(path16.join(binDir, entry), { recursive: true, force: true });
19379
- appendUpgradeLog(`Removed stale bin staging entry: ${path16.join(binDir, entry)}`);
19444
+ fs9.rmSync(path17.join(binDir, entry), { recursive: true, force: true });
19445
+ appendUpgradeLog(`Removed stale bin staging entry: ${path17.join(binDir, entry)}`);
19380
19446
  }
19381
19447
  }
19382
19448
  }
@@ -19461,7 +19527,7 @@ async function maybeRunDaemonUpgradeHelperFromEnv() {
19461
19527
  }
19462
19528
 
19463
19529
  // src/commands/router.ts
19464
- import * as fs9 from "fs";
19530
+ import * as fs10 from "fs";
19465
19531
  var CHAT_COMMANDS = [
19466
19532
  "send_chat",
19467
19533
  "new_chat",
@@ -19697,8 +19763,8 @@ var DaemonCommandRouter = class {
19697
19763
  if (sinceTs > 0) {
19698
19764
  return { success: true, logs: [], totalBuffered: 0 };
19699
19765
  }
19700
- if (fs9.existsSync(LOG_PATH)) {
19701
- const content = fs9.readFileSync(LOG_PATH, "utf-8");
19766
+ if (fs10.existsSync(LOG_PATH)) {
19767
+ const content = fs10.readFileSync(LOG_PATH, "utf-8");
19702
19768
  const allLines = content.split("\n");
19703
19769
  const recent = allLines.slice(-count).join("\n");
19704
19770
  return { success: true, logs: recent, totalLines: allLines.length };
@@ -19840,6 +19906,8 @@ var DaemonCommandRouter = class {
19840
19906
  const wantsAll = args?.all === true;
19841
19907
  const offset = wantsAll ? 0 : Math.max(0, Number(args?.offset) || 0);
19842
19908
  const limit = wantsAll ? Number.MAX_SAFE_INTEGER : Math.max(1, Math.min(100, Number(args?.limit) || 30));
19909
+ const requestedWorkspace = typeof args?.workspace === "string" ? args.workspace.trim() : "";
19910
+ const requestedProviderSessionId = typeof args?.providerSessionId === "string" ? args.providerSessionId.trim() : typeof args?.activeProviderSessionId === "string" ? args.activeProviderSessionId.trim() : "";
19843
19911
  const providerMeta = this.deps.providerLoader.resolve?.(providerType) || this.deps.providerLoader.getMeta(providerType);
19844
19912
  const { sessions: historySessions, hasMore, source } = listProviderHistorySessions(providerType, {
19845
19913
  canonicalHistory: providerMeta?.canonicalHistory,
@@ -19859,6 +19927,7 @@ var DaemonCommandRouter = class {
19859
19927
  sessions: historySessions.map((session) => {
19860
19928
  const saved = savedSessionById.get(session.historySessionId);
19861
19929
  const recent = recentSessionById.get(session.historySessionId);
19930
+ const workspace = saved?.workspace || recent?.workspace || session.workspace || (requestedWorkspace && requestedProviderSessionId === session.historySessionId ? requestedWorkspace : void 0);
19862
19931
  return {
19863
19932
  id: session.historySessionId,
19864
19933
  providerSessionId: session.historySessionId,
@@ -19866,13 +19935,13 @@ var DaemonCommandRouter = class {
19866
19935
  providerName: saved?.providerName || recent?.providerName || providerType,
19867
19936
  kind: saved?.kind || recent?.kind || kind,
19868
19937
  title: saved?.title || recent?.title || session.sessionTitle || session.preview || providerType,
19869
- workspace: saved?.workspace || recent?.workspace || session.workspace,
19938
+ workspace,
19870
19939
  summaryMetadata: saved?.summaryMetadata || recent?.summaryMetadata,
19871
19940
  preview: session.preview,
19872
19941
  messageCount: session.messageCount,
19873
19942
  firstMessageAt: session.firstMessageAt,
19874
19943
  lastMessageAt: session.lastMessageAt,
19875
- canResume: !!(saved?.workspace || recent?.workspace || session.workspace) && canResumeById,
19944
+ canResume: !!workspace && canResumeById,
19876
19945
  historySource: session.source,
19877
19946
  sourcePath: session.sourcePath,
19878
19947
  sourceMtimeMs: session.sourceMtimeMs
@@ -21850,12 +21919,12 @@ init_io_contracts();
21850
21919
  init_chat_message_normalization();
21851
21920
 
21852
21921
  // src/providers/version-archive.ts
21853
- import * as fs10 from "fs";
21854
- import * as path17 from "path";
21855
- import * as os18 from "os";
21922
+ import * as fs11 from "fs";
21923
+ import * as path18 from "path";
21924
+ import * as os19 from "os";
21856
21925
  import { execSync as execSync5 } from "child_process";
21857
21926
  import { platform as platform8 } from "os";
21858
- var ARCHIVE_PATH = path17.join(os18.homedir(), ".adhdev", "version-history.json");
21927
+ var ARCHIVE_PATH = path18.join(os19.homedir(), ".adhdev", "version-history.json");
21859
21928
  var MAX_ENTRIES_PER_PROVIDER = 20;
21860
21929
  var VersionArchive = class {
21861
21930
  history = {};
@@ -21864,8 +21933,8 @@ var VersionArchive = class {
21864
21933
  }
21865
21934
  load() {
21866
21935
  try {
21867
- if (fs10.existsSync(ARCHIVE_PATH)) {
21868
- this.history = JSON.parse(fs10.readFileSync(ARCHIVE_PATH, "utf-8"));
21936
+ if (fs11.existsSync(ARCHIVE_PATH)) {
21937
+ this.history = JSON.parse(fs11.readFileSync(ARCHIVE_PATH, "utf-8"));
21869
21938
  }
21870
21939
  } catch {
21871
21940
  this.history = {};
@@ -21902,8 +21971,8 @@ var VersionArchive = class {
21902
21971
  }
21903
21972
  save() {
21904
21973
  try {
21905
- fs10.mkdirSync(path17.dirname(ARCHIVE_PATH), { recursive: true });
21906
- fs10.writeFileSync(ARCHIVE_PATH, JSON.stringify(this.history, null, 2));
21974
+ fs11.mkdirSync(path18.dirname(ARCHIVE_PATH), { recursive: true });
21975
+ fs11.writeFileSync(ARCHIVE_PATH, JSON.stringify(this.history, null, 2));
21907
21976
  } catch {
21908
21977
  }
21909
21978
  }
@@ -21958,19 +22027,19 @@ function getVersion(binary, versionCommand) {
21958
22027
  function checkPathExists2(paths) {
21959
22028
  for (const p of paths) {
21960
22029
  if (p.includes("*")) {
21961
- const home = os18.homedir();
21962
- const resolved = p.replace(/\*/g, home.split(path17.sep).pop() || "");
21963
- if (fs10.existsSync(resolved)) return resolved;
22030
+ const home = os19.homedir();
22031
+ const resolved = p.replace(/\*/g, home.split(path18.sep).pop() || "");
22032
+ if (fs11.existsSync(resolved)) return resolved;
21964
22033
  } else {
21965
- if (fs10.existsSync(p)) return p;
22034
+ if (fs11.existsSync(p)) return p;
21966
22035
  }
21967
22036
  }
21968
22037
  return null;
21969
22038
  }
21970
22039
  function getMacAppVersion(appPath) {
21971
22040
  if (platform8() !== "darwin" || !appPath.endsWith(".app")) return null;
21972
- const plistPath = path17.join(appPath, "Contents", "Info.plist");
21973
- if (!fs10.existsSync(plistPath)) return null;
22041
+ const plistPath = path18.join(appPath, "Contents", "Info.plist");
22042
+ if (!fs11.existsSync(plistPath)) return null;
21974
22043
  const raw = runCommand(`/usr/libexec/PlistBuddy -c "Print CFBundleShortVersionString" "${plistPath}"`);
21975
22044
  return raw || null;
21976
22045
  }
@@ -21995,8 +22064,8 @@ async function detectAllVersions(loader, archive) {
21995
22064
  const cliBin = provider.cli ? findBinary2(provider.cli) : null;
21996
22065
  let resolvedBin = cliBin;
21997
22066
  if (!resolvedBin && appPath && currentOs === "darwin") {
21998
- const bundled = path17.join(appPath, "Contents", "Resources", "app", "bin", provider.cli || "");
21999
- if (provider.cli && fs10.existsSync(bundled)) resolvedBin = bundled;
22067
+ const bundled = path18.join(appPath, "Contents", "Resources", "app", "bin", provider.cli || "");
22068
+ if (provider.cli && fs11.existsSync(bundled)) resolvedBin = bundled;
22000
22069
  }
22001
22070
  info.installed = !!(appPath || resolvedBin);
22002
22071
  info.path = appPath || null;
@@ -22035,8 +22104,8 @@ async function detectAllVersions(loader, archive) {
22035
22104
 
22036
22105
  // src/daemon/dev-server.ts
22037
22106
  import * as http2 from "http";
22038
- import * as fs14 from "fs";
22039
- import * as path21 from "path";
22107
+ import * as fs15 from "fs";
22108
+ import * as path22 from "path";
22040
22109
  init_config();
22041
22110
 
22042
22111
  // src/daemon/scaffold-template.ts
@@ -22387,8 +22456,8 @@ init_logger();
22387
22456
 
22388
22457
  // src/daemon/dev-cdp-handlers.ts
22389
22458
  init_logger();
22390
- import * as fs11 from "fs";
22391
- import * as path18 from "path";
22459
+ import * as fs12 from "fs";
22460
+ import * as path19 from "path";
22392
22461
  async function handleCdpEvaluate(ctx, req, res) {
22393
22462
  const body = await ctx.readBody(req);
22394
22463
  const { expression, timeout, ideType } = body;
@@ -22566,18 +22635,18 @@ async function handleScriptHints(ctx, type, _req, res) {
22566
22635
  return;
22567
22636
  }
22568
22637
  let scriptsPath = "";
22569
- const directScripts = path18.join(dir, "scripts.js");
22570
- if (fs11.existsSync(directScripts)) {
22638
+ const directScripts = path19.join(dir, "scripts.js");
22639
+ if (fs12.existsSync(directScripts)) {
22571
22640
  scriptsPath = directScripts;
22572
22641
  } else {
22573
- const scriptsDir = path18.join(dir, "scripts");
22574
- if (fs11.existsSync(scriptsDir)) {
22575
- const versions = fs11.readdirSync(scriptsDir).filter((d) => {
22576
- return fs11.statSync(path18.join(scriptsDir, d)).isDirectory();
22642
+ const scriptsDir = path19.join(dir, "scripts");
22643
+ if (fs12.existsSync(scriptsDir)) {
22644
+ const versions = fs12.readdirSync(scriptsDir).filter((d) => {
22645
+ return fs12.statSync(path19.join(scriptsDir, d)).isDirectory();
22577
22646
  }).sort().reverse();
22578
22647
  for (const ver of versions) {
22579
- const p = path18.join(scriptsDir, ver, "scripts.js");
22580
- if (fs11.existsSync(p)) {
22648
+ const p = path19.join(scriptsDir, ver, "scripts.js");
22649
+ if (fs12.existsSync(p)) {
22581
22650
  scriptsPath = p;
22582
22651
  break;
22583
22652
  }
@@ -22589,7 +22658,7 @@ async function handleScriptHints(ctx, type, _req, res) {
22589
22658
  return;
22590
22659
  }
22591
22660
  try {
22592
- const source = fs11.readFileSync(scriptsPath, "utf-8");
22661
+ const source = fs12.readFileSync(scriptsPath, "utf-8");
22593
22662
  const hints = {};
22594
22663
  const funcRegex = /module\.exports\.(\w+)\s*=\s*function\s+\w+\s*\(params\)/g;
22595
22664
  let match;
@@ -23404,8 +23473,8 @@ async function handleDomContext(ctx, type, req, res) {
23404
23473
  }
23405
23474
 
23406
23475
  // src/daemon/dev-cli-debug.ts
23407
- import * as fs12 from "fs";
23408
- import * as path19 from "path";
23476
+ import * as fs13 from "fs";
23477
+ import * as path20 from "path";
23409
23478
  function slugifyFixtureName(value) {
23410
23479
  const normalized = String(value || "").trim().toLowerCase().replace(/[^a-z0-9._-]+/g, "-").replace(/^-+|-+$/g, "");
23411
23480
  return normalized || `fixture-${Date.now()}`;
@@ -23415,15 +23484,15 @@ function getCliFixtureDir(ctx, type) {
23415
23484
  if (!providerDir) {
23416
23485
  throw new Error(`Provider directory not found for '${type}'`);
23417
23486
  }
23418
- return path19.join(providerDir, "fixtures");
23487
+ return path20.join(providerDir, "fixtures");
23419
23488
  }
23420
23489
  function readCliFixture(ctx, type, name) {
23421
23490
  const fixtureDir = getCliFixtureDir(ctx, type);
23422
- const filePath = path19.join(fixtureDir, `${name}.json`);
23423
- if (!fs12.existsSync(filePath)) {
23491
+ const filePath = path20.join(fixtureDir, `${name}.json`);
23492
+ if (!fs13.existsSync(filePath)) {
23424
23493
  throw new Error(`Fixture not found: ${filePath}`);
23425
23494
  }
23426
- return JSON.parse(fs12.readFileSync(filePath, "utf-8"));
23495
+ return JSON.parse(fs13.readFileSync(filePath, "utf-8"));
23427
23496
  }
23428
23497
  function getExerciseTranscriptText(result) {
23429
23498
  const parts = [];
@@ -24159,7 +24228,7 @@ async function handleCliFixtureCapture(ctx, req, res) {
24159
24228
  return;
24160
24229
  }
24161
24230
  const fixtureDir = getCliFixtureDir(ctx, type);
24162
- fs12.mkdirSync(fixtureDir, { recursive: true });
24231
+ fs13.mkdirSync(fixtureDir, { recursive: true });
24163
24232
  const name = slugifyFixtureName(String(body?.name || `${type}-${Date.now()}`));
24164
24233
  const result = await runCliExerciseInternal(ctx, { ...request, type });
24165
24234
  const fixture = {
@@ -24186,8 +24255,8 @@ async function handleCliFixtureCapture(ctx, req, res) {
24186
24255
  },
24187
24256
  notes: typeof body?.notes === "string" ? body.notes : void 0
24188
24257
  };
24189
- const filePath = path19.join(fixtureDir, `${name}.json`);
24190
- fs12.writeFileSync(filePath, JSON.stringify(fixture, null, 2));
24258
+ const filePath = path20.join(fixtureDir, `${name}.json`);
24259
+ fs13.writeFileSync(filePath, JSON.stringify(fixture, null, 2));
24191
24260
  ctx.json(res, 200, {
24192
24261
  saved: true,
24193
24262
  name,
@@ -24205,14 +24274,14 @@ async function handleCliFixtureCapture(ctx, req, res) {
24205
24274
  async function handleCliFixtureList(ctx, type, _req, res) {
24206
24275
  try {
24207
24276
  const fixtureDir = getCliFixtureDir(ctx, type);
24208
- if (!fs12.existsSync(fixtureDir)) {
24277
+ if (!fs13.existsSync(fixtureDir)) {
24209
24278
  ctx.json(res, 200, { fixtures: [], count: 0 });
24210
24279
  return;
24211
24280
  }
24212
- const fixtures = fs12.readdirSync(fixtureDir).filter((file) => file.endsWith(".json")).sort((a, b) => b.localeCompare(a, void 0, { numeric: true, sensitivity: "base" })).map((file) => {
24213
- const fullPath = path19.join(fixtureDir, file);
24281
+ const fixtures = fs13.readdirSync(fixtureDir).filter((file) => file.endsWith(".json")).sort((a, b) => b.localeCompare(a, void 0, { numeric: true, sensitivity: "base" })).map((file) => {
24282
+ const fullPath = path20.join(fixtureDir, file);
24214
24283
  try {
24215
- const raw = JSON.parse(fs12.readFileSync(fullPath, "utf-8"));
24284
+ const raw = JSON.parse(fs13.readFileSync(fullPath, "utf-8"));
24216
24285
  return {
24217
24286
  name: raw.name || file.replace(/\.json$/i, ""),
24218
24287
  path: fullPath,
@@ -24345,9 +24414,9 @@ async function handleCliRaw(ctx, req, res) {
24345
24414
  }
24346
24415
 
24347
24416
  // src/daemon/dev-auto-implement.ts
24348
- import * as fs13 from "fs";
24349
- import * as path20 from "path";
24350
- import * as os19 from "os";
24417
+ import * as fs14 from "fs";
24418
+ import * as path21 from "path";
24419
+ import * as os20 from "os";
24351
24420
  function getAutoImplPid(ctx) {
24352
24421
  const pid = ctx.autoImplProcess?.pid;
24353
24422
  return typeof pid === "number" && pid > 0 ? pid : null;
@@ -24393,38 +24462,38 @@ function resolveAutoImplReference(ctx, category, requestedReference, targetType)
24393
24462
  return fallback?.type || null;
24394
24463
  }
24395
24464
  function getLatestScriptVersionDir(scriptsDir) {
24396
- if (!fs13.existsSync(scriptsDir)) return null;
24397
- const versions = fs13.readdirSync(scriptsDir).filter((d) => {
24465
+ if (!fs14.existsSync(scriptsDir)) return null;
24466
+ const versions = fs14.readdirSync(scriptsDir).filter((d) => {
24398
24467
  try {
24399
- return fs13.statSync(path20.join(scriptsDir, d)).isDirectory();
24468
+ return fs14.statSync(path21.join(scriptsDir, d)).isDirectory();
24400
24469
  } catch {
24401
24470
  return false;
24402
24471
  }
24403
24472
  }).sort((a, b) => b.localeCompare(a, void 0, { numeric: true, sensitivity: "base" }));
24404
24473
  if (versions.length === 0) return null;
24405
- return path20.join(scriptsDir, versions[0]);
24474
+ return path21.join(scriptsDir, versions[0]);
24406
24475
  }
24407
24476
  function resolveAutoImplWritableProviderDir(ctx, category, type, requestedDir) {
24408
- const canonicalUserDir = path20.resolve(ctx.providerLoader.getUserProviderDir(category, type));
24409
- const desiredDir = requestedDir ? path20.resolve(requestedDir) : canonicalUserDir;
24410
- const upstreamRoot = path20.resolve(ctx.providerLoader.getUpstreamDir());
24411
- if (desiredDir === upstreamRoot || desiredDir.startsWith(`${upstreamRoot}${path20.sep}`)) {
24477
+ const canonicalUserDir = path21.resolve(ctx.providerLoader.getUserProviderDir(category, type));
24478
+ const desiredDir = requestedDir ? path21.resolve(requestedDir) : canonicalUserDir;
24479
+ const upstreamRoot = path21.resolve(ctx.providerLoader.getUpstreamDir());
24480
+ if (desiredDir === upstreamRoot || desiredDir.startsWith(`${upstreamRoot}${path21.sep}`)) {
24412
24481
  return { dir: null, reason: `Refusing to write into upstream provider directory: ${desiredDir}` };
24413
24482
  }
24414
- if (path20.basename(desiredDir) !== type) {
24483
+ if (path21.basename(desiredDir) !== type) {
24415
24484
  return { dir: null, reason: `Requested writable provider directory must end with '${type}': ${desiredDir}` };
24416
24485
  }
24417
24486
  const sourceDir = ctx.findProviderDir(type);
24418
24487
  if (!sourceDir) {
24419
24488
  return { dir: null, reason: `Provider source directory not found for '${type}'` };
24420
24489
  }
24421
- if (!fs13.existsSync(desiredDir)) {
24422
- fs13.mkdirSync(path20.dirname(desiredDir), { recursive: true });
24423
- fs13.cpSync(sourceDir, desiredDir, { recursive: true });
24490
+ if (!fs14.existsSync(desiredDir)) {
24491
+ fs14.mkdirSync(path21.dirname(desiredDir), { recursive: true });
24492
+ fs14.cpSync(sourceDir, desiredDir, { recursive: true });
24424
24493
  ctx.log(`Auto-implement writable copy created: ${desiredDir}`);
24425
24494
  }
24426
- const providerJson = path20.join(desiredDir, "provider.json");
24427
- if (!fs13.existsSync(providerJson)) {
24495
+ const providerJson = path21.join(desiredDir, "provider.json");
24496
+ if (!fs14.existsSync(providerJson)) {
24428
24497
  return { dir: null, reason: `provider.json not found in writable provider directory: ${desiredDir}` };
24429
24498
  }
24430
24499
  return { dir: desiredDir };
@@ -24432,15 +24501,15 @@ function resolveAutoImplWritableProviderDir(ctx, category, type, requestedDir) {
24432
24501
  function loadAutoImplReferenceScripts(ctx, referenceType) {
24433
24502
  if (!referenceType) return {};
24434
24503
  const refDir = ctx.findProviderDir(referenceType);
24435
- if (!refDir || !fs13.existsSync(refDir)) return {};
24504
+ if (!refDir || !fs14.existsSync(refDir)) return {};
24436
24505
  const referenceScripts = {};
24437
- const scriptsDir = path20.join(refDir, "scripts");
24506
+ const scriptsDir = path21.join(refDir, "scripts");
24438
24507
  const latestDir = getLatestScriptVersionDir(scriptsDir);
24439
24508
  if (!latestDir) return referenceScripts;
24440
- for (const file of fs13.readdirSync(latestDir)) {
24509
+ for (const file of fs14.readdirSync(latestDir)) {
24441
24510
  if (!file.endsWith(".js")) continue;
24442
24511
  try {
24443
- referenceScripts[file] = fs13.readFileSync(path20.join(latestDir, file), "utf-8");
24512
+ referenceScripts[file] = fs14.readFileSync(path21.join(latestDir, file), "utf-8");
24444
24513
  } catch {
24445
24514
  }
24446
24515
  }
@@ -24548,16 +24617,16 @@ async function handleAutoImplement(ctx, type, req, res) {
24548
24617
  });
24549
24618
  const referenceScripts = loadAutoImplReferenceScripts(ctx, resolvedReference);
24550
24619
  const prompt = buildAutoImplPrompt(ctx, type, provider, providerDir, functions, domContext, referenceScripts, comment, resolvedReference, verification);
24551
- const tmpDir = path20.join(os19.tmpdir(), "adhdev-autoimpl");
24552
- if (!fs13.existsSync(tmpDir)) fs13.mkdirSync(tmpDir, { recursive: true });
24553
- const promptFile = path20.join(tmpDir, `prompt-${type}-${Date.now()}.md`);
24554
- fs13.writeFileSync(promptFile, prompt, "utf-8");
24620
+ const tmpDir = path21.join(os20.tmpdir(), "adhdev-autoimpl");
24621
+ if (!fs14.existsSync(tmpDir)) fs14.mkdirSync(tmpDir, { recursive: true });
24622
+ const promptFile = path21.join(tmpDir, `prompt-${type}-${Date.now()}.md`);
24623
+ fs14.writeFileSync(promptFile, prompt, "utf-8");
24555
24624
  ctx.log(`Auto-implement prompt written to ${promptFile} (${prompt.length} chars)`);
24556
24625
  const agentProvider = ctx.providerLoader.resolve(agent) || ctx.providerLoader.getMeta(agent);
24557
24626
  const spawn4 = agentProvider?.spawn;
24558
24627
  if (!spawn4?.command) {
24559
24628
  try {
24560
- fs13.unlinkSync(promptFile);
24629
+ fs14.unlinkSync(promptFile);
24561
24630
  } catch {
24562
24631
  }
24563
24632
  ctx.json(res, 400, { error: `Agent '${agent}' has no spawn config. Select a CLI provider with a spawn configuration.` });
@@ -24659,7 +24728,7 @@ async function handleAutoImplement(ctx, type, req, res) {
24659
24728
  } catch {
24660
24729
  }
24661
24730
  try {
24662
- fs13.unlinkSync(promptFile);
24731
+ fs14.unlinkSync(promptFile);
24663
24732
  } catch {
24664
24733
  }
24665
24734
  ctx.log(`Auto-implement (ACP) ${success ? "completed" : "failed"}: ${type} (exit: ${code})`);
@@ -24703,7 +24772,7 @@ async function handleAutoImplement(ctx, type, req, res) {
24703
24772
  const interactiveFlags = ["--yolo", "--interactive", "-i"];
24704
24773
  const baseArgs = [...spawn4.args || []].filter((a) => !interactiveFlags.includes(a));
24705
24774
  let shellCmd;
24706
- const isWin = os19.platform() === "win32";
24775
+ const isWin = os20.platform() === "win32";
24707
24776
  const escapeArg = (a) => isWin ? `"${a.replace(/"/g, '""')}"` : `'${a.replace(/'/g, "'\\''")}'`;
24708
24777
  const promptMode = autoImpl?.promptMode ?? "stdin";
24709
24778
  const extraArgs = autoImpl?.extraArgs ?? [];
@@ -24742,7 +24811,7 @@ async function handleAutoImplement(ctx, type, req, res) {
24742
24811
  try {
24743
24812
  const pty = __require("node-pty");
24744
24813
  ctx.log(`Auto-implement spawn (PTY): ${shellCmd}`);
24745
- const isWin2 = os19.platform() === "win32";
24814
+ const isWin2 = os20.platform() === "win32";
24746
24815
  child = pty.spawn(isWin2 ? "cmd.exe" : process.env.SHELL || "/bin/zsh", [isWin2 ? "/c" : "-c", shellCmd], {
24747
24816
  name: "xterm-256color",
24748
24817
  cols: 120,
@@ -24885,7 +24954,7 @@ async function handleAutoImplement(ctx, type, req, res) {
24885
24954
  }
24886
24955
  });
24887
24956
  try {
24888
- fs13.unlinkSync(promptFile);
24957
+ fs14.unlinkSync(promptFile);
24889
24958
  } catch {
24890
24959
  }
24891
24960
  ctx.log(`Auto-implement ${success ? "completed" : "failed"}: ${type} (exit: ${code})${verificationSummary ? ` verify=${verificationSummary.pass ? "pass" : "fail"}` : ""}`);
@@ -24982,7 +25051,7 @@ function buildAutoImplPrompt(ctx, type, provider, providerDir, functions, domCon
24982
25051
  setMode: "set_mode.js"
24983
25052
  };
24984
25053
  const targetFileNames = new Set(functions.map((fn) => funcToFile[fn]).filter(Boolean));
24985
- const scriptsDir = path20.join(providerDir, "scripts");
25054
+ const scriptsDir = path21.join(providerDir, "scripts");
24986
25055
  const latestScriptsDir = getLatestScriptVersionDir(scriptsDir);
24987
25056
  if (latestScriptsDir) {
24988
25057
  lines.push(`Scripts version directory: \`${latestScriptsDir}\``);
@@ -24990,10 +25059,10 @@ function buildAutoImplPrompt(ctx, type, provider, providerDir, functions, domCon
24990
25059
  lines.push("## \u270F\uFE0F Target Files (EDIT THESE)");
24991
25060
  lines.push("These are the ONLY files you are allowed to modify. Replace the TODO stubs with working implementations.");
24992
25061
  lines.push("");
24993
- for (const file of fs13.readdirSync(latestScriptsDir)) {
25062
+ for (const file of fs14.readdirSync(latestScriptsDir)) {
24994
25063
  if (file.endsWith(".js") && targetFileNames.has(file)) {
24995
25064
  try {
24996
- const content = fs13.readFileSync(path20.join(latestScriptsDir, file), "utf-8");
25065
+ const content = fs14.readFileSync(path21.join(latestScriptsDir, file), "utf-8");
24997
25066
  lines.push(`### \`${file}\` \u270F\uFE0F EDIT`);
24998
25067
  lines.push("```javascript");
24999
25068
  lines.push(content);
@@ -25003,14 +25072,14 @@ function buildAutoImplPrompt(ctx, type, provider, providerDir, functions, domCon
25003
25072
  }
25004
25073
  }
25005
25074
  }
25006
- const refFiles = fs13.readdirSync(latestScriptsDir).filter((f) => f.endsWith(".js") && !targetFileNames.has(f));
25075
+ const refFiles = fs14.readdirSync(latestScriptsDir).filter((f) => f.endsWith(".js") && !targetFileNames.has(f));
25007
25076
  if (refFiles.length > 0) {
25008
25077
  lines.push("## \u{1F512} Other Scripts (REFERENCE ONLY \u2014 DO NOT EDIT)");
25009
25078
  lines.push("These files are shown for context only. Do NOT modify them under any circumstances.");
25010
25079
  lines.push("");
25011
25080
  for (const file of refFiles) {
25012
25081
  try {
25013
- const content = fs13.readFileSync(path20.join(latestScriptsDir, file), "utf-8");
25082
+ const content = fs14.readFileSync(path21.join(latestScriptsDir, file), "utf-8");
25014
25083
  lines.push(`### \`${file}\` \u{1F512}`);
25015
25084
  lines.push("```javascript");
25016
25085
  lines.push(content);
@@ -25051,11 +25120,11 @@ function buildAutoImplPrompt(ctx, type, provider, providerDir, functions, domCon
25051
25120
  lines.push("");
25052
25121
  }
25053
25122
  }
25054
- const docsDir = path20.join(providerDir, "../../docs");
25123
+ const docsDir = path21.join(providerDir, "../../docs");
25055
25124
  const loadGuide = (name) => {
25056
25125
  try {
25057
- const p = path20.join(docsDir, name);
25058
- if (fs13.existsSync(p)) return fs13.readFileSync(p, "utf-8");
25126
+ const p = path21.join(docsDir, name);
25127
+ if (fs14.existsSync(p)) return fs14.readFileSync(p, "utf-8");
25059
25128
  } catch {
25060
25129
  }
25061
25130
  return null;
@@ -25291,7 +25360,7 @@ function buildCliAutoImplPrompt(ctx, type, provider, providerDir, functions, ref
25291
25360
  parseApproval: "parse_approval.js"
25292
25361
  };
25293
25362
  const targetFileNames = new Set(functions.map((fn) => funcToFile[fn]).filter(Boolean));
25294
- const scriptsDir = path20.join(providerDir, "scripts");
25363
+ const scriptsDir = path21.join(providerDir, "scripts");
25295
25364
  const latestScriptsDir = getLatestScriptVersionDir(scriptsDir);
25296
25365
  if (latestScriptsDir) {
25297
25366
  lines.push(`Scripts version directory: \`${latestScriptsDir}\``);
@@ -25299,11 +25368,11 @@ function buildCliAutoImplPrompt(ctx, type, provider, providerDir, functions, ref
25299
25368
  lines.push("## \u270F\uFE0F Target Files (EDIT THESE)");
25300
25369
  lines.push("These are the ONLY files you are allowed to modify. Replace TODO or heuristic-only logic with working PTY-aware implementations.");
25301
25370
  lines.push("");
25302
- for (const file of fs13.readdirSync(latestScriptsDir)) {
25371
+ for (const file of fs14.readdirSync(latestScriptsDir)) {
25303
25372
  if (!file.endsWith(".js")) continue;
25304
25373
  if (!targetFileNames.has(file)) continue;
25305
25374
  try {
25306
- const content = fs13.readFileSync(path20.join(latestScriptsDir, file), "utf-8");
25375
+ const content = fs14.readFileSync(path21.join(latestScriptsDir, file), "utf-8");
25307
25376
  lines.push(`### \`${file}\` \u270F\uFE0F EDIT`);
25308
25377
  lines.push("```javascript");
25309
25378
  lines.push(content);
@@ -25312,14 +25381,14 @@ function buildCliAutoImplPrompt(ctx, type, provider, providerDir, functions, ref
25312
25381
  } catch {
25313
25382
  }
25314
25383
  }
25315
- const refFiles = fs13.readdirSync(latestScriptsDir).filter((f) => f.endsWith(".js") && !targetFileNames.has(f));
25384
+ const refFiles = fs14.readdirSync(latestScriptsDir).filter((f) => f.endsWith(".js") && !targetFileNames.has(f));
25316
25385
  if (refFiles.length > 0) {
25317
25386
  lines.push("## \u{1F512} Other Scripts (REFERENCE ONLY \u2014 DO NOT EDIT)");
25318
25387
  lines.push("These files are shown for context only. Do NOT modify them under any circumstances.");
25319
25388
  lines.push("");
25320
25389
  for (const file of refFiles) {
25321
25390
  try {
25322
- const content = fs13.readFileSync(path20.join(latestScriptsDir, file), "utf-8");
25391
+ const content = fs14.readFileSync(path21.join(latestScriptsDir, file), "utf-8");
25323
25392
  lines.push(`### \`${file}\` \u{1F512}`);
25324
25393
  lines.push("```javascript");
25325
25394
  lines.push(content);
@@ -25352,11 +25421,11 @@ function buildCliAutoImplPrompt(ctx, type, provider, providerDir, functions, ref
25352
25421
  lines.push("");
25353
25422
  }
25354
25423
  }
25355
- const docsDir = path20.join(providerDir, "../../docs");
25424
+ const docsDir = path21.join(providerDir, "../../docs");
25356
25425
  const loadGuide = (name) => {
25357
25426
  try {
25358
- const p = path20.join(docsDir, name);
25359
- if (fs13.existsSync(p)) return fs13.readFileSync(p, "utf-8");
25427
+ const p = path21.join(docsDir, name);
25428
+ if (fs14.existsSync(p)) return fs14.readFileSync(p, "utf-8");
25360
25429
  } catch {
25361
25430
  }
25362
25431
  return null;
@@ -25802,8 +25871,8 @@ var DevServer = class _DevServer {
25802
25871
  }
25803
25872
  getEndpointList() {
25804
25873
  return this.routes.map((r) => {
25805
- const path22 = typeof r.pattern === "string" ? r.pattern : r.pattern.source.replace(/\\\//g, "/").replace(/\(\[.*?\]\+\)/g, ":type").replace(/[\^$]/g, "");
25806
- return `${r.method.padEnd(5)} ${path22}`;
25874
+ const path23 = typeof r.pattern === "string" ? r.pattern : r.pattern.source.replace(/\\\//g, "/").replace(/\(\[.*?\]\+\)/g, ":type").replace(/[\^$]/g, "");
25875
+ return `${r.method.padEnd(5)} ${path23}`;
25807
25876
  });
25808
25877
  }
25809
25878
  async start(port = DEV_SERVER_PORT) {
@@ -26091,12 +26160,12 @@ var DevServer = class _DevServer {
26091
26160
  // ─── DevConsole SPA ───
26092
26161
  getConsoleDistDir() {
26093
26162
  const candidates = [
26094
- path21.resolve(__dirname, "../../web-devconsole/dist"),
26095
- path21.resolve(__dirname, "../../../web-devconsole/dist"),
26096
- path21.join(process.cwd(), "packages/web-devconsole/dist")
26163
+ path22.resolve(__dirname, "../../web-devconsole/dist"),
26164
+ path22.resolve(__dirname, "../../../web-devconsole/dist"),
26165
+ path22.join(process.cwd(), "packages/web-devconsole/dist")
26097
26166
  ];
26098
26167
  for (const dir of candidates) {
26099
- if (fs14.existsSync(path21.join(dir, "index.html"))) return dir;
26168
+ if (fs15.existsSync(path22.join(dir, "index.html"))) return dir;
26100
26169
  }
26101
26170
  return null;
26102
26171
  }
@@ -26106,9 +26175,9 @@ var DevServer = class _DevServer {
26106
26175
  this.json(res, 500, { error: "DevConsole not found. Run: npm run build -w packages/web-devconsole" });
26107
26176
  return;
26108
26177
  }
26109
- const htmlPath = path21.join(distDir, "index.html");
26178
+ const htmlPath = path22.join(distDir, "index.html");
26110
26179
  try {
26111
- const html = fs14.readFileSync(htmlPath, "utf-8");
26180
+ const html = fs15.readFileSync(htmlPath, "utf-8");
26112
26181
  res.writeHead(200, { "Content-Type": "text/html; charset=utf-8" });
26113
26182
  res.end(html);
26114
26183
  } catch (e) {
@@ -26131,15 +26200,15 @@ var DevServer = class _DevServer {
26131
26200
  this.json(res, 404, { error: "Not found" });
26132
26201
  return;
26133
26202
  }
26134
- const safePath = path21.normalize(pathname).replace(/^\.\.\//, "");
26135
- const filePath = path21.join(distDir, safePath);
26203
+ const safePath = path22.normalize(pathname).replace(/^\.\.\//, "");
26204
+ const filePath = path22.join(distDir, safePath);
26136
26205
  if (!filePath.startsWith(distDir)) {
26137
26206
  this.json(res, 403, { error: "Forbidden" });
26138
26207
  return;
26139
26208
  }
26140
26209
  try {
26141
- const content = fs14.readFileSync(filePath);
26142
- const ext = path21.extname(filePath);
26210
+ const content = fs15.readFileSync(filePath);
26211
+ const ext = path22.extname(filePath);
26143
26212
  const contentType = _DevServer.MIME_MAP[ext] || "application/octet-stream";
26144
26213
  res.writeHead(200, { "Content-Type": contentType, "Cache-Control": "public, max-age=31536000, immutable" });
26145
26214
  res.end(content);
@@ -26247,14 +26316,14 @@ var DevServer = class _DevServer {
26247
26316
  const files = [];
26248
26317
  const scan = (d, prefix) => {
26249
26318
  try {
26250
- for (const entry of fs14.readdirSync(d, { withFileTypes: true })) {
26319
+ for (const entry of fs15.readdirSync(d, { withFileTypes: true })) {
26251
26320
  if (entry.name.startsWith(".") || entry.name.endsWith(".bak")) continue;
26252
26321
  const rel = prefix ? `${prefix}/${entry.name}` : entry.name;
26253
26322
  if (entry.isDirectory()) {
26254
26323
  files.push({ path: rel, size: 0, type: "dir" });
26255
- scan(path21.join(d, entry.name), rel);
26324
+ scan(path22.join(d, entry.name), rel);
26256
26325
  } else {
26257
- const stat = fs14.statSync(path21.join(d, entry.name));
26326
+ const stat = fs15.statSync(path22.join(d, entry.name));
26258
26327
  files.push({ path: rel, size: stat.size, type: "file" });
26259
26328
  }
26260
26329
  }
@@ -26277,16 +26346,16 @@ var DevServer = class _DevServer {
26277
26346
  this.json(res, 404, { error: `Provider directory not found: ${type}` });
26278
26347
  return;
26279
26348
  }
26280
- const fullPath = path21.resolve(dir, path21.normalize(filePath));
26349
+ const fullPath = path22.resolve(dir, path22.normalize(filePath));
26281
26350
  if (!fullPath.startsWith(dir)) {
26282
26351
  this.json(res, 403, { error: "Forbidden" });
26283
26352
  return;
26284
26353
  }
26285
- if (!fs14.existsSync(fullPath) || fs14.statSync(fullPath).isDirectory()) {
26354
+ if (!fs15.existsSync(fullPath) || fs15.statSync(fullPath).isDirectory()) {
26286
26355
  this.json(res, 404, { error: `File not found: ${filePath}` });
26287
26356
  return;
26288
26357
  }
26289
- const content = fs14.readFileSync(fullPath, "utf-8");
26358
+ const content = fs15.readFileSync(fullPath, "utf-8");
26290
26359
  this.json(res, 200, { type, path: filePath, content, lines: content.split("\n").length });
26291
26360
  }
26292
26361
  /** POST /api/providers/:type/file — write a file { path, content } */
@@ -26302,15 +26371,15 @@ var DevServer = class _DevServer {
26302
26371
  this.json(res, 404, { error: `Provider directory not found: ${type}` });
26303
26372
  return;
26304
26373
  }
26305
- const fullPath = path21.resolve(dir, path21.normalize(filePath));
26374
+ const fullPath = path22.resolve(dir, path22.normalize(filePath));
26306
26375
  if (!fullPath.startsWith(dir)) {
26307
26376
  this.json(res, 403, { error: "Forbidden" });
26308
26377
  return;
26309
26378
  }
26310
26379
  try {
26311
- if (fs14.existsSync(fullPath)) fs14.copyFileSync(fullPath, fullPath + ".bak");
26312
- fs14.mkdirSync(path21.dirname(fullPath), { recursive: true });
26313
- fs14.writeFileSync(fullPath, content, "utf-8");
26380
+ if (fs15.existsSync(fullPath)) fs15.copyFileSync(fullPath, fullPath + ".bak");
26381
+ fs15.mkdirSync(path22.dirname(fullPath), { recursive: true });
26382
+ fs15.writeFileSync(fullPath, content, "utf-8");
26314
26383
  this.log(`File saved: ${fullPath} (${content.length} chars)`);
26315
26384
  this.providerLoader.reload();
26316
26385
  this.json(res, 200, { saved: true, path: filePath, chars: content.length });
@@ -26326,9 +26395,9 @@ var DevServer = class _DevServer {
26326
26395
  return;
26327
26396
  }
26328
26397
  for (const name of ["scripts.js", "provider.json"]) {
26329
- const p = path21.join(dir, name);
26330
- if (fs14.existsSync(p)) {
26331
- const source = fs14.readFileSync(p, "utf-8");
26398
+ const p = path22.join(dir, name);
26399
+ if (fs15.existsSync(p)) {
26400
+ const source = fs15.readFileSync(p, "utf-8");
26332
26401
  this.json(res, 200, { type, path: p, source, lines: source.split("\n").length });
26333
26402
  return;
26334
26403
  }
@@ -26347,11 +26416,11 @@ var DevServer = class _DevServer {
26347
26416
  this.json(res, 404, { error: `Provider not found: ${type}` });
26348
26417
  return;
26349
26418
  }
26350
- const target = fs14.existsSync(path21.join(dir, "scripts.js")) ? "scripts.js" : "provider.json";
26351
- const targetPath = path21.join(dir, target);
26419
+ const target = fs15.existsSync(path22.join(dir, "scripts.js")) ? "scripts.js" : "provider.json";
26420
+ const targetPath = path22.join(dir, target);
26352
26421
  try {
26353
- if (fs14.existsSync(targetPath)) fs14.copyFileSync(targetPath, targetPath + ".bak");
26354
- fs14.writeFileSync(targetPath, source, "utf-8");
26422
+ if (fs15.existsSync(targetPath)) fs15.copyFileSync(targetPath, targetPath + ".bak");
26423
+ fs15.writeFileSync(targetPath, source, "utf-8");
26355
26424
  this.log(`Saved provider: ${targetPath} (${source.length} chars)`);
26356
26425
  this.providerLoader.reload();
26357
26426
  this.json(res, 200, { saved: true, path: targetPath, chars: source.length });
@@ -26495,21 +26564,21 @@ var DevServer = class _DevServer {
26495
26564
  }
26496
26565
  let targetDir;
26497
26566
  targetDir = this.providerLoader.getUserProviderDir(category, type);
26498
- const jsonPath = path21.join(targetDir, "provider.json");
26499
- if (fs14.existsSync(jsonPath)) {
26567
+ const jsonPath = path22.join(targetDir, "provider.json");
26568
+ if (fs15.existsSync(jsonPath)) {
26500
26569
  this.json(res, 409, { error: `Provider already exists at ${targetDir}`, path: targetDir });
26501
26570
  return;
26502
26571
  }
26503
26572
  try {
26504
26573
  const result = generateFiles(type, name, category, { cdpPorts, cli, processName, installPath, binary, extensionId, version, osPaths, processNames });
26505
- fs14.mkdirSync(targetDir, { recursive: true });
26506
- fs14.writeFileSync(jsonPath, result["provider.json"], "utf-8");
26574
+ fs15.mkdirSync(targetDir, { recursive: true });
26575
+ fs15.writeFileSync(jsonPath, result["provider.json"], "utf-8");
26507
26576
  const createdFiles = ["provider.json"];
26508
26577
  if (result.files) {
26509
26578
  for (const [relPath, content] of Object.entries(result.files)) {
26510
- const fullPath = path21.join(targetDir, relPath);
26511
- fs14.mkdirSync(path21.dirname(fullPath), { recursive: true });
26512
- fs14.writeFileSync(fullPath, content, "utf-8");
26579
+ const fullPath = path22.join(targetDir, relPath);
26580
+ fs15.mkdirSync(path22.dirname(fullPath), { recursive: true });
26581
+ fs15.writeFileSync(fullPath, content, "utf-8");
26513
26582
  createdFiles.push(relPath);
26514
26583
  }
26515
26584
  }
@@ -26558,38 +26627,38 @@ var DevServer = class _DevServer {
26558
26627
  }
26559
26628
  // ─── Phase 2: Auto-Implement Backend ───
26560
26629
  getLatestScriptVersionDir(scriptsDir) {
26561
- if (!fs14.existsSync(scriptsDir)) return null;
26562
- const versions = fs14.readdirSync(scriptsDir).filter((d) => {
26630
+ if (!fs15.existsSync(scriptsDir)) return null;
26631
+ const versions = fs15.readdirSync(scriptsDir).filter((d) => {
26563
26632
  try {
26564
- return fs14.statSync(path21.join(scriptsDir, d)).isDirectory();
26633
+ return fs15.statSync(path22.join(scriptsDir, d)).isDirectory();
26565
26634
  } catch {
26566
26635
  return false;
26567
26636
  }
26568
26637
  }).sort((a, b) => b.localeCompare(a, void 0, { numeric: true, sensitivity: "base" }));
26569
26638
  if (versions.length === 0) return null;
26570
- return path21.join(scriptsDir, versions[0]);
26639
+ return path22.join(scriptsDir, versions[0]);
26571
26640
  }
26572
26641
  resolveAutoImplWritableProviderDir(category, type, requestedDir) {
26573
- const canonicalUserDir = path21.resolve(this.providerLoader.getUserProviderDir(category, type));
26574
- const desiredDir = requestedDir ? path21.resolve(requestedDir) : canonicalUserDir;
26575
- const upstreamRoot = path21.resolve(this.providerLoader.getUpstreamDir());
26576
- if (desiredDir === upstreamRoot || desiredDir.startsWith(`${upstreamRoot}${path21.sep}`)) {
26642
+ const canonicalUserDir = path22.resolve(this.providerLoader.getUserProviderDir(category, type));
26643
+ const desiredDir = requestedDir ? path22.resolve(requestedDir) : canonicalUserDir;
26644
+ const upstreamRoot = path22.resolve(this.providerLoader.getUpstreamDir());
26645
+ if (desiredDir === upstreamRoot || desiredDir.startsWith(`${upstreamRoot}${path22.sep}`)) {
26577
26646
  return { dir: null, reason: `Refusing to write into upstream provider directory: ${desiredDir}` };
26578
26647
  }
26579
- if (path21.basename(desiredDir) !== type) {
26648
+ if (path22.basename(desiredDir) !== type) {
26580
26649
  return { dir: null, reason: `Requested writable provider directory must end with '${type}': ${desiredDir}` };
26581
26650
  }
26582
26651
  const sourceDir = this.findProviderDir(type);
26583
26652
  if (!sourceDir) {
26584
26653
  return { dir: null, reason: `Provider source directory not found for '${type}'` };
26585
26654
  }
26586
- if (!fs14.existsSync(desiredDir)) {
26587
- fs14.mkdirSync(path21.dirname(desiredDir), { recursive: true });
26588
- fs14.cpSync(sourceDir, desiredDir, { recursive: true });
26655
+ if (!fs15.existsSync(desiredDir)) {
26656
+ fs15.mkdirSync(path22.dirname(desiredDir), { recursive: true });
26657
+ fs15.cpSync(sourceDir, desiredDir, { recursive: true });
26589
26658
  this.log(`Auto-implement writable copy created: ${desiredDir}`);
26590
26659
  }
26591
- const providerJson = path21.join(desiredDir, "provider.json");
26592
- if (!fs14.existsSync(providerJson)) {
26660
+ const providerJson = path22.join(desiredDir, "provider.json");
26661
+ if (!fs15.existsSync(providerJson)) {
26593
26662
  return { dir: null, reason: `provider.json not found in writable provider directory: ${desiredDir}` };
26594
26663
  }
26595
26664
  return { dir: desiredDir };
@@ -26624,7 +26693,7 @@ var DevServer = class _DevServer {
26624
26693
  setMode: "set_mode.js"
26625
26694
  };
26626
26695
  const targetFileNames = new Set(functions.map((fn) => funcToFile[fn]).filter(Boolean));
26627
- const scriptsDir = path21.join(providerDir, "scripts");
26696
+ const scriptsDir = path22.join(providerDir, "scripts");
26628
26697
  const latestScriptsDir = this.getLatestScriptVersionDir(scriptsDir);
26629
26698
  if (latestScriptsDir) {
26630
26699
  lines.push(`Scripts version directory: \`${latestScriptsDir}\``);
@@ -26632,10 +26701,10 @@ var DevServer = class _DevServer {
26632
26701
  lines.push("## \u270F\uFE0F Target Files (EDIT THESE)");
26633
26702
  lines.push("These are the ONLY files you are allowed to modify. Replace the TODO stubs with working implementations.");
26634
26703
  lines.push("");
26635
- for (const file of fs14.readdirSync(latestScriptsDir)) {
26704
+ for (const file of fs15.readdirSync(latestScriptsDir)) {
26636
26705
  if (file.endsWith(".js") && targetFileNames.has(file)) {
26637
26706
  try {
26638
- const content = fs14.readFileSync(path21.join(latestScriptsDir, file), "utf-8");
26707
+ const content = fs15.readFileSync(path22.join(latestScriptsDir, file), "utf-8");
26639
26708
  lines.push(`### \`${file}\` \u270F\uFE0F EDIT`);
26640
26709
  lines.push("```javascript");
26641
26710
  lines.push(content);
@@ -26645,14 +26714,14 @@ var DevServer = class _DevServer {
26645
26714
  }
26646
26715
  }
26647
26716
  }
26648
- const refFiles = fs14.readdirSync(latestScriptsDir).filter((f) => f.endsWith(".js") && !targetFileNames.has(f));
26717
+ const refFiles = fs15.readdirSync(latestScriptsDir).filter((f) => f.endsWith(".js") && !targetFileNames.has(f));
26649
26718
  if (refFiles.length > 0) {
26650
26719
  lines.push("## \u{1F512} Other Scripts (REFERENCE ONLY \u2014 DO NOT EDIT)");
26651
26720
  lines.push("These files are shown for context only. Do NOT modify them under any circumstances.");
26652
26721
  lines.push("");
26653
26722
  for (const file of refFiles) {
26654
26723
  try {
26655
- const content = fs14.readFileSync(path21.join(latestScriptsDir, file), "utf-8");
26724
+ const content = fs15.readFileSync(path22.join(latestScriptsDir, file), "utf-8");
26656
26725
  lines.push(`### \`${file}\` \u{1F512}`);
26657
26726
  lines.push("```javascript");
26658
26727
  lines.push(content);
@@ -26693,11 +26762,11 @@ var DevServer = class _DevServer {
26693
26762
  lines.push("");
26694
26763
  }
26695
26764
  }
26696
- const docsDir = path21.join(providerDir, "../../docs");
26765
+ const docsDir = path22.join(providerDir, "../../docs");
26697
26766
  const loadGuide = (name) => {
26698
26767
  try {
26699
- const p = path21.join(docsDir, name);
26700
- if (fs14.existsSync(p)) return fs14.readFileSync(p, "utf-8");
26768
+ const p = path22.join(docsDir, name);
26769
+ if (fs15.existsSync(p)) return fs15.readFileSync(p, "utf-8");
26701
26770
  } catch {
26702
26771
  }
26703
26772
  return null;
@@ -26870,7 +26939,7 @@ var DevServer = class _DevServer {
26870
26939
  parseApproval: "parse_approval.js"
26871
26940
  };
26872
26941
  const targetFileNames = new Set(functions.map((fn) => funcToFile[fn]).filter(Boolean));
26873
- const scriptsDir = path21.join(providerDir, "scripts");
26942
+ const scriptsDir = path22.join(providerDir, "scripts");
26874
26943
  const latestScriptsDir = this.getLatestScriptVersionDir(scriptsDir);
26875
26944
  if (latestScriptsDir) {
26876
26945
  lines.push(`Scripts version directory: \`${latestScriptsDir}\``);
@@ -26878,11 +26947,11 @@ var DevServer = class _DevServer {
26878
26947
  lines.push("## \u270F\uFE0F Target Files (EDIT THESE)");
26879
26948
  lines.push("These are the ONLY files you are allowed to modify. Replace TODO or heuristic-only logic with working PTY-aware implementations.");
26880
26949
  lines.push("");
26881
- for (const file of fs14.readdirSync(latestScriptsDir)) {
26950
+ for (const file of fs15.readdirSync(latestScriptsDir)) {
26882
26951
  if (!file.endsWith(".js")) continue;
26883
26952
  if (!targetFileNames.has(file)) continue;
26884
26953
  try {
26885
- const content = fs14.readFileSync(path21.join(latestScriptsDir, file), "utf-8");
26954
+ const content = fs15.readFileSync(path22.join(latestScriptsDir, file), "utf-8");
26886
26955
  lines.push(`### \`${file}\` \u270F\uFE0F EDIT`);
26887
26956
  lines.push("```javascript");
26888
26957
  lines.push(content);
@@ -26891,14 +26960,14 @@ var DevServer = class _DevServer {
26891
26960
  } catch {
26892
26961
  }
26893
26962
  }
26894
- const refFiles = fs14.readdirSync(latestScriptsDir).filter((f) => f.endsWith(".js") && !targetFileNames.has(f));
26963
+ const refFiles = fs15.readdirSync(latestScriptsDir).filter((f) => f.endsWith(".js") && !targetFileNames.has(f));
26895
26964
  if (refFiles.length > 0) {
26896
26965
  lines.push("## \u{1F512} Other Scripts (REFERENCE ONLY \u2014 DO NOT EDIT)");
26897
26966
  lines.push("These files are shown for context only. Do NOT modify them under any circumstances.");
26898
26967
  lines.push("");
26899
26968
  for (const file of refFiles) {
26900
26969
  try {
26901
- const content = fs14.readFileSync(path21.join(latestScriptsDir, file), "utf-8");
26970
+ const content = fs15.readFileSync(path22.join(latestScriptsDir, file), "utf-8");
26902
26971
  lines.push(`### \`${file}\` \u{1F512}`);
26903
26972
  lines.push("```javascript");
26904
26973
  lines.push(content);
@@ -26931,11 +27000,11 @@ var DevServer = class _DevServer {
26931
27000
  lines.push("");
26932
27001
  }
26933
27002
  }
26934
- const docsDir = path21.join(providerDir, "../../docs");
27003
+ const docsDir = path22.join(providerDir, "../../docs");
26935
27004
  const loadGuide = (name) => {
26936
27005
  try {
26937
- const p = path21.join(docsDir, name);
26938
- if (fs14.existsSync(p)) return fs14.readFileSync(p, "utf-8");
27006
+ const p = path22.join(docsDir, name);
27007
+ if (fs15.existsSync(p)) return fs15.readFileSync(p, "utf-8");
26939
27008
  } catch {
26940
27009
  }
26941
27010
  return null;
@@ -27815,8 +27884,8 @@ async function installExtension(ide, extension) {
27815
27884
  const res = await fetch(extension.vsixUrl);
27816
27885
  if (res.ok) {
27817
27886
  const buffer = Buffer.from(await res.arrayBuffer());
27818
- const fs15 = await import("fs");
27819
- fs15.writeFileSync(vsixPath, buffer);
27887
+ const fs16 = await import("fs");
27888
+ fs16.writeFileSync(vsixPath, buffer);
27820
27889
  return new Promise((resolve12) => {
27821
27890
  const cmd = `"${ide.cliCommand}" --install-extension "${vsixPath}" --force`;
27822
27891
  exec2(cmd, { timeout: 6e4 }, (error, _stdout, stderr) => {