@adhdev/daemon-core 0.9.76-rc.11 → 0.9.76-rc.13

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.
@@ -21,6 +21,7 @@ export { normalizeCliProviderForRuntime, type CliApprovalInput, type CliChatMess
21
21
  export declare function appendBoundedText(current: string, chunk: string, maxChars: number): string;
22
22
  export declare class ProviderCliAdapter implements CliAdapter {
23
23
  private extraArgs;
24
+ private extraEnv;
24
25
  readonly cliType: string;
25
26
  readonly cliName: string;
26
27
  workingDir: string;
@@ -126,7 +127,7 @@ export declare class ProviderCliAdapter implements CliAdapter {
126
127
  private readonly submitStrategy;
127
128
  private readonly requirePromptEchoBeforeSubmit;
128
129
  private static readonly SCRIPT_STATUS_DEBOUNCE_MS;
129
- constructor(provider: CliProviderModule, workingDir: string, extraArgs?: string[], transportFactory?: PtyTransportFactory);
130
+ constructor(provider: CliProviderModule, workingDir: string, extraArgs?: string[], extraEnv?: Record<string, string>, transportFactory?: PtyTransportFactory);
130
131
  /** Inject CLI scripts after construction (e.g. when resolved by ProviderLoader) */
131
132
  setCliScripts(scripts: CliScripts): void;
132
133
  /** Refresh provider scripts/config used by this adapter without restarting the PTY runtime. */
@@ -15,6 +15,7 @@ export declare function resolveCliSpawnPlan(options: {
15
15
  runtimeSettings: Record<string, any>;
16
16
  workingDir: string;
17
17
  extraArgs: string[];
18
+ extraEnv?: Record<string, string>;
18
19
  }): CliSpawnPlan;
19
20
  export declare function buildCliLoginShellRetry(plan: Pick<CliSpawnPlan, 'binaryPath' | 'allArgs'>): {
20
21
  shellCmd: string;
@@ -58,6 +58,11 @@ type CliSessionBinding = {
58
58
  providerSessionId?: string;
59
59
  launchMode: CliLaunchMode;
60
60
  };
61
+ type CliStartOptions = {
62
+ resumeSessionId?: string;
63
+ settingsOverride?: Record<string, any>;
64
+ extraEnv?: Record<string, string>;
65
+ };
61
66
  export declare function supportsExplicitSessionResume(resume?: ProviderResumeCapability): boolean;
62
67
  export declare function resolveCliSessionBinding(provider: ProviderModule | undefined, normalizedType: string, cliArgs?: string[], requestedResumeSessionId?: string): CliSessionBinding;
63
68
  export declare class DaemonCliManager {
@@ -73,10 +78,7 @@ export declare class DaemonCliManager {
73
78
  private createAdapter;
74
79
  private startCliExitMonitor;
75
80
  private registerCliInstance;
76
- startSession(cliType: string, workingDir: string, cliArgs?: string[], initialModel?: string, options?: {
77
- resumeSessionId?: string;
78
- settingsOverride?: Record<string, any>;
79
- }): Promise<{
81
+ startSession(cliType: string, workingDir: string, cliArgs?: string[], initialModel?: string, options?: CliStartOptions): Promise<{
80
82
  runtimeSessionId: string;
81
83
  providerSessionId?: string;
82
84
  }>;
package/dist/index.js CHANGED
@@ -1630,7 +1630,7 @@ var init_provider_cli_config = __esm({
1630
1630
 
1631
1631
  // src/cli-adapters/provider-cli-runtime.ts
1632
1632
  function resolveCliSpawnPlan(options) {
1633
- const { provider, runtimeSettings, workingDir, extraArgs } = options;
1633
+ const { provider, runtimeSettings, workingDir, extraArgs, extraEnv } = options;
1634
1634
  const { spawn: spawnConfig } = provider;
1635
1635
  const configuredCommand = typeof runtimeSettings.executablePath === "string" && runtimeSettings.executablePath.trim() ? runtimeSettings.executablePath.trim() : spawnConfig.command;
1636
1636
  const binaryPath = findBinary(configuredCommand);
@@ -1654,7 +1654,7 @@ function resolveCliSpawnPlan(options) {
1654
1654
  shellCmd = binaryPath;
1655
1655
  shellArgs = allArgs;
1656
1656
  }
1657
- const env = buildCliSpawnEnv(process.env, spawnConfig.env);
1657
+ const env = buildCliSpawnEnv(process.env, { ...spawnConfig.env || {}, ...extraEnv || {} });
1658
1658
  env.TERMINAL_CWD = workingDir;
1659
1659
  return {
1660
1660
  binaryPath,
@@ -1757,8 +1757,9 @@ var init_provider_cli_adapter = __esm({
1757
1757
  init_provider_cli_runtime();
1758
1758
  init_provider_cli_shared();
1759
1759
  ProviderCliAdapter = class _ProviderCliAdapter {
1760
- constructor(provider, workingDir, extraArgs = [], transportFactory = new NodePtyTransportFactory()) {
1760
+ constructor(provider, workingDir, extraArgs = [], extraEnv = {}, transportFactory = new NodePtyTransportFactory()) {
1761
1761
  this.extraArgs = extraArgs;
1762
+ this.extraEnv = extraEnv;
1762
1763
  this.provider = provider;
1763
1764
  this.transportFactory = transportFactory;
1764
1765
  this.cliType = provider.type;
@@ -2074,7 +2075,8 @@ ${lastSnapshot}`;
2074
2075
  provider: this.provider,
2075
2076
  runtimeSettings: this.runtimeSettings,
2076
2077
  workingDir: this.workingDir,
2077
- extraArgs: this.extraArgs
2078
+ extraArgs: this.extraArgs,
2079
+ extraEnv: this.extraEnv
2078
2080
  });
2079
2081
  LOG.info("CLI", `[${this.cliType}] Spawning in ${this.workingDir}`);
2080
2082
  this.resetTraceSession();
@@ -5983,17 +5985,17 @@ function checkPathExists(paths) {
5983
5985
  return null;
5984
5986
  }
5985
5987
  async function detectIDEs(providerLoader) {
5986
- const os21 = (0, import_os2.platform)();
5988
+ const os22 = (0, import_os2.platform)();
5987
5989
  const results = [];
5988
5990
  for (const def of getMergedDefinitions()) {
5989
5991
  const cliPath = findCliCommand(providerLoader?.getIdeCliCommand(def.id, def.cli) || def.cli);
5990
- const appPath = checkPathExists(providerLoader?.getIdePathCandidates(def.id, def.paths[os21] || []) || []);
5992
+ const appPath = checkPathExists(providerLoader?.getIdePathCandidates(def.id, def.paths[os22] || []) || []);
5991
5993
  let resolvedCli = cliPath;
5992
- if (!resolvedCli && appPath && os21 === "darwin") {
5994
+ if (!resolvedCli && appPath && os22 === "darwin") {
5993
5995
  const bundledCli = `${appPath}/Contents/Resources/app/bin/${def.cli}`;
5994
5996
  if ((0, import_fs4.existsSync)(bundledCli)) resolvedCli = bundledCli;
5995
5997
  }
5996
- if (!resolvedCli && appPath && os21 === "win32") {
5998
+ if (!resolvedCli && appPath && os22 === "win32") {
5997
5999
  const { dirname: dirname9 } = await import("path");
5998
6000
  const appDir = dirname9(appPath);
5999
6001
  const candidates = [
@@ -6010,7 +6012,7 @@ async function detectIDEs(providerLoader) {
6010
6012
  }
6011
6013
  }
6012
6014
  }
6013
- const installed = os21 === "darwin" ? !!(resolvedCli || appPath) : !!resolvedCli;
6015
+ const installed = os22 === "darwin" ? !!(resolvedCli || appPath) : !!resolvedCli;
6014
6016
  const version = resolvedCli ? getIdeVersion(resolvedCli) : null;
6015
6017
  results.push({
6016
6018
  id: def.id,
@@ -14943,7 +14945,7 @@ var CliProviderInstance = class {
14943
14945
  this.providerSessionId = options?.providerSessionId;
14944
14946
  this.launchMode = options?.launchMode || "new";
14945
14947
  this.onProviderSessionResolved = options?.onProviderSessionResolved;
14946
- this.adapter = new ProviderCliAdapter(provider, workingDir, cliArgs, transportFactory);
14948
+ this.adapter = new ProviderCliAdapter(provider, workingDir, cliArgs, options?.extraEnv || {}, transportFactory);
14947
14949
  this.monitor = new StatusMonitor();
14948
14950
  this.historyWriter = new ChatHistoryWriter();
14949
14951
  }
@@ -17154,7 +17156,7 @@ var DaemonCliManager = class {
17154
17156
  attachExisting
17155
17157
  }) || void 0;
17156
17158
  }
17157
- createAdapter(cliType, workingDir, cliArgs, runtimeId, providerSessionId, attachExisting = false) {
17159
+ createAdapter(cliType, workingDir, cliArgs, runtimeId, providerSessionId, attachExisting = false, extraEnv) {
17158
17160
  const normalizedType = this.providerLoader.resolveAlias(cliType);
17159
17161
  const provider = this.providerLoader.getMeta(normalizedType);
17160
17162
  if (provider && provider.category === "cli" && provider.patterns && provider.spawn) {
@@ -17168,7 +17170,7 @@ var DaemonCliManager = class {
17168
17170
  providerSessionId,
17169
17171
  attachExisting
17170
17172
  );
17171
- return new ProviderCliAdapter(resolvedProvider, workingDir, cliArgs, transportFactory);
17173
+ return new ProviderCliAdapter(resolvedProvider, workingDir, cliArgs, extraEnv || {}, transportFactory);
17172
17174
  }
17173
17175
  throw new Error(`No CLI provider found for '${cliType}'. Create a provider.js in providers/cli/${cliType}/`);
17174
17176
  }
@@ -17371,6 +17373,7 @@ Run 'adhdev doctor' for detailed diagnostics.`
17371
17373
  {
17372
17374
  providerSessionId: sessionBinding.providerSessionId,
17373
17375
  launchMode: sessionBinding.launchMode,
17376
+ extraEnv: options?.extraEnv,
17374
17377
  onProviderSessionResolved: ({ providerSessionId, providerName, providerType, workspace }) => {
17375
17378
  this.persistRecentActivity({
17376
17379
  kind: "cli",
@@ -17391,7 +17394,8 @@ Run 'adhdev doctor' for detailed diagnostics.`
17391
17394
  resolvedCliArgs,
17392
17395
  key,
17393
17396
  sessionBinding.providerSessionId,
17394
- false
17397
+ false,
17398
+ options?.extraEnv
17395
17399
  );
17396
17400
  try {
17397
17401
  await adapter.spawn();
@@ -17620,7 +17624,7 @@ Run 'adhdev doctor' for detailed diagnostics.`
17620
17624
  dir,
17621
17625
  args?.cliArgs,
17622
17626
  args?.initialModel,
17623
- { resumeSessionId: args?.resumeSessionId, settingsOverride: args?.settings }
17627
+ { resumeSessionId: args?.resumeSessionId, settingsOverride: args?.settings, extraEnv: args?.env }
17624
17628
  );
17625
17629
  return {
17626
17630
  success: true,
@@ -20159,11 +20163,14 @@ function getRecentCommands(count = 50) {
20159
20163
  cleanOldFiles();
20160
20164
 
20161
20165
  // src/commands/router.ts
20166
+ var yaml = __toESM(require("js-yaml"));
20162
20167
  init_logger();
20163
20168
 
20164
20169
  // src/commands/mesh-coordinator.ts
20170
+ var import_node_child_process3 = require("child_process");
20165
20171
  var import_node_fs3 = require("fs");
20166
20172
  var import_node_module2 = require("module");
20173
+ var os17 = __toESM(require("os"));
20167
20174
  var import_node_path = require("path");
20168
20175
  var DEFAULT_SERVER_NAME = "adhdev-mesh";
20169
20176
  var DEFAULT_ADHDEV_MCP_COMMAND = "adhdev-mcp";
@@ -20197,13 +20204,13 @@ function resolveMeshCoordinatorSetup(options) {
20197
20204
  if (!mcpServer) {
20198
20205
  return {
20199
20206
  kind: "unsupported",
20200
- reason: "Could not resolve the ADHDev MCP server entrypoint without relying on a PATH bin shim"
20207
+ reason: "Could not resolve the ADHDev MCP server entrypoint and a Node runtime with WebSocket support for daemon IPC mode"
20201
20208
  };
20202
20209
  }
20203
20210
  return {
20204
20211
  kind: "auto_import",
20205
20212
  serverName,
20206
- configPath: (0, import_node_path.join)(workspace, path27),
20213
+ configPath: resolveMcpConfigPath(path27, workspace),
20207
20214
  configFormat: mcpConfig.format,
20208
20215
  mcpServer
20209
20216
  };
@@ -20237,14 +20244,85 @@ function resolveMeshCoordinatorSetup(options) {
20237
20244
  function renderMeshCoordinatorTemplate(template, values) {
20238
20245
  return template.replace(/\{\{\s*(meshId|workspace|serverName|adhdevMcpCommand)\s*\}\}/g, (_, key) => values[key] || "");
20239
20246
  }
20247
+ function resolveMcpConfigPath(configPath, workspace) {
20248
+ const trimmed = configPath.trim();
20249
+ if (trimmed === "~") return os17.homedir();
20250
+ if (trimmed.startsWith("~/")) return (0, import_node_path.join)(os17.homedir(), trimmed.slice(2));
20251
+ if ((0, import_node_path.isAbsolute)(trimmed)) return trimmed;
20252
+ return (0, import_node_path.join)(workspace, trimmed);
20253
+ }
20240
20254
  function resolveAdhdevMcpServerLaunch(options) {
20241
20255
  const entryPath = resolveAdhdevMcpEntryPath(options.adhdevMcpEntryPath);
20242
20256
  if (!entryPath) return null;
20257
+ const nodeExecutable = resolveMcpNodeExecutable(options.nodeExecutable);
20258
+ if (!nodeExecutable) return null;
20243
20259
  return {
20244
- command: options.nodeExecutable?.trim() || process.execPath,
20260
+ command: nodeExecutable,
20245
20261
  args: [entryPath, "--mode", "ipc", "--repo-mesh", options.meshId]
20246
20262
  };
20247
20263
  }
20264
+ function resolveMcpNodeExecutable(explicitExecutable) {
20265
+ const explicit = explicitExecutable?.trim();
20266
+ if (explicit) return explicit;
20267
+ const candidates = [];
20268
+ const addCandidate = (candidate) => {
20269
+ const trimmed = candidate?.trim();
20270
+ if (!trimmed) return;
20271
+ const normalized = normalizeExistingPath(trimmed) || trimmed;
20272
+ if (!candidates.includes(normalized)) candidates.push(normalized);
20273
+ };
20274
+ addCandidate(process.env.ADHDEV_MCP_NODE_EXECUTABLE);
20275
+ addCandidate(process.env.ADHDEV_NODE_EXECUTABLE);
20276
+ addCandidate(process.env.npm_node_execpath);
20277
+ addNodeCandidatesFromPath(process.env.PATH, addCandidate);
20278
+ addNodeCandidatesFromNvm(os17.homedir(), addCandidate);
20279
+ addCandidate("/opt/homebrew/bin/node");
20280
+ addCandidate("/usr/local/bin/node");
20281
+ addCandidate("/usr/bin/node");
20282
+ addCandidate(process.execPath);
20283
+ for (const candidate of candidates) {
20284
+ if (nodeRuntimeSupportsWebSocket(candidate)) return candidate;
20285
+ }
20286
+ return null;
20287
+ }
20288
+ function addNodeCandidatesFromPath(pathValue, addCandidate) {
20289
+ for (const entry of (pathValue || "").split(":")) {
20290
+ const dir = entry.trim();
20291
+ if (!dir) continue;
20292
+ addCandidate((0, import_node_path.join)(dir, "node"));
20293
+ }
20294
+ }
20295
+ function addNodeCandidatesFromNvm(homeDir, addCandidate) {
20296
+ const versionsDir = (0, import_node_path.join)(homeDir, ".nvm", "versions", "node");
20297
+ try {
20298
+ const versionDirs = (0, import_node_fs3.readdirSync)(versionsDir, { withFileTypes: true }).filter((entry) => entry.isDirectory()).map((entry) => entry.name).sort(compareNodeVersionNamesDescending);
20299
+ for (const versionDir of versionDirs) {
20300
+ addCandidate((0, import_node_path.join)(versionsDir, versionDir, "bin", "node"));
20301
+ }
20302
+ } catch {
20303
+ }
20304
+ }
20305
+ function compareNodeVersionNamesDescending(a, b) {
20306
+ const parse = (value) => value.replace(/^v/, "").split(".").map((part) => Number.parseInt(part, 10) || 0);
20307
+ const left = parse(a);
20308
+ const right = parse(b);
20309
+ for (let i = 0; i < Math.max(left.length, right.length); i++) {
20310
+ const diff = (right[i] || 0) - (left[i] || 0);
20311
+ if (diff !== 0) return diff;
20312
+ }
20313
+ return b.localeCompare(a);
20314
+ }
20315
+ function nodeRuntimeSupportsWebSocket(nodeExecutable) {
20316
+ try {
20317
+ (0, import_node_child_process3.execFileSync)(nodeExecutable, ["-e", "process.exit(typeof WebSocket === 'function' ? 0 : 42)"], {
20318
+ stdio: "ignore",
20319
+ timeout: 3e3
20320
+ });
20321
+ return true;
20322
+ } catch {
20323
+ return false;
20324
+ }
20325
+ }
20248
20326
  function resolveAdhdevMcpEntryPath(explicitPath) {
20249
20327
  const explicit = explicitPath?.trim();
20250
20328
  if (explicit) return normalizeExistingPath(explicit) || explicit;
@@ -20288,7 +20366,7 @@ function normalizeExistingPath(filePath) {
20288
20366
  }
20289
20367
 
20290
20368
  // src/status/snapshot.ts
20291
- var os17 = __toESM(require("os"));
20369
+ var os18 = __toESM(require("os"));
20292
20370
  init_config();
20293
20371
  init_terminal_screen();
20294
20372
  init_logger();
@@ -20344,8 +20422,8 @@ function buildAvailableProviders(providerLoader) {
20344
20422
  }
20345
20423
  function buildMachineInfo(profile = "full") {
20346
20424
  const base = {
20347
- hostname: os17.hostname(),
20348
- platform: os17.platform()
20425
+ hostname: os18.hostname(),
20426
+ platform: os18.platform()
20349
20427
  };
20350
20428
  if (profile === "live") {
20351
20429
  return base;
@@ -20354,23 +20432,23 @@ function buildMachineInfo(profile = "full") {
20354
20432
  const memSnap2 = getHostMemorySnapshot();
20355
20433
  return {
20356
20434
  ...base,
20357
- arch: os17.arch(),
20358
- cpus: os17.cpus().length,
20435
+ arch: os18.arch(),
20436
+ cpus: os18.cpus().length,
20359
20437
  totalMem: memSnap2.totalMem,
20360
- release: os17.release()
20438
+ release: os18.release()
20361
20439
  };
20362
20440
  }
20363
20441
  const memSnap = getHostMemorySnapshot();
20364
20442
  return {
20365
20443
  ...base,
20366
- arch: os17.arch(),
20367
- cpus: os17.cpus().length,
20444
+ arch: os18.arch(),
20445
+ cpus: os18.cpus().length,
20368
20446
  totalMem: memSnap.totalMem,
20369
20447
  freeMem: memSnap.freeMem,
20370
20448
  availableMem: memSnap.availableMem,
20371
- loadavg: os17.loadavg(),
20372
- uptime: os17.uptime(),
20373
- release: os17.release()
20449
+ loadavg: os18.loadavg(),
20450
+ uptime: os18.uptime(),
20451
+ release: os18.release()
20374
20452
  };
20375
20453
  }
20376
20454
  function parseMessageTime(value) {
@@ -20604,11 +20682,11 @@ function buildStatusSnapshot(options) {
20604
20682
  var import_child_process8 = require("child_process");
20605
20683
  var import_child_process9 = require("child_process");
20606
20684
  var fs9 = __toESM(require("fs"));
20607
- var os18 = __toESM(require("os"));
20685
+ var os19 = __toESM(require("os"));
20608
20686
  var path21 = __toESM(require("path"));
20609
20687
  var UPGRADE_HELPER_ENV = "ADHDEV_DAEMON_UPGRADE_HELPER";
20610
20688
  function getUpgradeLogPath() {
20611
- const home = os18.homedir();
20689
+ const home = os19.homedir();
20612
20690
  const dir = path21.join(home, ".adhdev");
20613
20691
  fs9.mkdirSync(dir, { recursive: true });
20614
20692
  return path21.join(dir, "daemon-upgrade.log");
@@ -20800,7 +20878,7 @@ async function waitForPidExit(pid, timeoutMs) {
20800
20878
  }
20801
20879
  }
20802
20880
  function stopSessionHostProcesses(appName) {
20803
- const pidFile = path21.join(os18.homedir(), ".adhdev", `${appName}-session-host.pid`);
20881
+ const pidFile = path21.join(os19.homedir(), ".adhdev", `${appName}-session-host.pid`);
20804
20882
  try {
20805
20883
  if (fs9.existsSync(pidFile)) {
20806
20884
  const pid = Number.parseInt(fs9.readFileSync(pidFile, "utf8").trim(), 10);
@@ -20817,7 +20895,7 @@ function stopSessionHostProcesses(appName) {
20817
20895
  }
20818
20896
  }
20819
20897
  function removeDaemonPidFile() {
20820
- const pidFile = path21.join(os18.homedir(), ".adhdev", "daemon.pid");
20898
+ const pidFile = path21.join(os19.homedir(), ".adhdev", "daemon.pid");
20821
20899
  try {
20822
20900
  fs9.unlinkSync(pidFile);
20823
20901
  } catch {
@@ -20955,6 +21033,22 @@ function normalizeReleaseChannel(value) {
20955
21033
  function resolveUpgradeChannel(args) {
20956
21034
  return normalizeReleaseChannel(args?.channel) || normalizeReleaseChannel(args?.updatePolicy?.channel) || normalizeReleaseChannel(args?.npmTag) || normalizeReleaseChannel(loadConfig().updateChannel) || "stable";
20957
21035
  }
21036
+ function loadYamlModule() {
21037
+ return yaml;
21038
+ }
21039
+ function getMcpServersKey(format) {
21040
+ return format === "hermes_config_yaml" ? "mcp_servers" : "mcpServers";
21041
+ }
21042
+ function parseMeshCoordinatorMcpConfig(text, format) {
21043
+ if (!text.trim()) return {};
21044
+ if (format === "claude_mcp_json") return JSON.parse(text);
21045
+ const parsed = loadYamlModule().load(text);
21046
+ return parsed && typeof parsed === "object" && !Array.isArray(parsed) ? parsed : {};
21047
+ }
21048
+ function serializeMeshCoordinatorMcpConfig(config, format) {
21049
+ if (format === "claude_mcp_json") return JSON.stringify(config, null, 2);
21050
+ return loadYamlModule().dump(config, { noRefs: true, lineWidth: 120 });
21051
+ }
20958
21052
  var CHAT_COMMANDS = [
20959
21053
  "send_chat",
20960
21054
  "new_chat",
@@ -21932,7 +22026,8 @@ var DaemonCommandRouter = class {
21932
22026
  meshCoordinatorSetup: coordinatorSetup
21933
22027
  };
21934
22028
  }
21935
- if (coordinatorSetup.configFormat !== "claude_mcp_json") {
22029
+ const configFormat = coordinatorSetup.configFormat;
22030
+ if (configFormat !== "claude_mcp_json" && configFormat !== "hermes_config_yaml") {
21936
22031
  return {
21937
22032
  success: false,
21938
22033
  code: "mesh_coordinator_unsupported",
@@ -21957,15 +22052,23 @@ var DaemonCommandRouter = class {
21957
22052
  workspace
21958
22053
  };
21959
22054
  }
21960
- const { existsSync: existsSync23, readFileSync: readFileSync15, writeFileSync: writeFileSync12, copyFileSync: copyFileSync3 } = await import("fs");
22055
+ const { existsSync: existsSync23, readFileSync: readFileSync15, writeFileSync: writeFileSync12, copyFileSync: copyFileSync3, mkdirSync: mkdirSync14 } = await import("fs");
22056
+ const { dirname: dirname9 } = await import("path");
21961
22057
  const mcpConfigPath = coordinatorSetup.configPath;
22058
+ mkdirSync14(dirname9(mcpConfigPath), { recursive: true });
21962
22059
  const hadExistingMcpConfig = existsSync23(mcpConfigPath);
21963
22060
  let existingMcpConfig = {};
21964
22061
  if (hadExistingMcpConfig) {
21965
22062
  try {
21966
- existingMcpConfig = JSON.parse(readFileSync15(mcpConfigPath, "utf-8"));
22063
+ existingMcpConfig = parseMeshCoordinatorMcpConfig(readFileSync15(mcpConfigPath, "utf-8"), configFormat);
21967
22064
  copyFileSync3(mcpConfigPath, mcpConfigPath + ".backup");
21968
- } catch {
22065
+ } catch (error) {
22066
+ LOG.error("MeshCoordinator", `Failed to parse existing MCP config ${mcpConfigPath}: ${error?.message || error}`);
22067
+ return {
22068
+ success: false,
22069
+ code: "mesh_coordinator_config_parse_failed",
22070
+ error: `Failed to parse existing MCP config at ${mcpConfigPath}`
22071
+ };
21969
22072
  }
21970
22073
  }
21971
22074
  const mcpServerEntry = {
@@ -21978,18 +22081,25 @@ var DaemonCommandRouter = class {
21978
22081
  ADHDEV_MCP_TRANSPORT: "ipc"
21979
22082
  };
21980
22083
  }
22084
+ const mcpServersKey = getMcpServersKey(configFormat);
22085
+ const existingServers = existingMcpConfig[mcpServersKey];
21981
22086
  const mcpConfig = {
21982
22087
  ...existingMcpConfig,
21983
- mcpServers: {
21984
- ...existingMcpConfig.mcpServers || {},
22088
+ [mcpServersKey]: {
22089
+ ...existingServers && typeof existingServers === "object" && !Array.isArray(existingServers) ? existingServers : {},
21985
22090
  [coordinatorSetup.serverName]: mcpServerEntry
21986
22091
  }
21987
22092
  };
21988
- writeFileSync12(mcpConfigPath, JSON.stringify(mcpConfig, null, 2), "utf-8");
22093
+ writeFileSync12(mcpConfigPath, serializeMeshCoordinatorMcpConfig(mcpConfig, configFormat), "utf-8");
21989
22094
  LOG.info("MeshCoordinator", `Wrote ${mcpConfigPath} with ${coordinatorSetup.serverName} server`);
21990
22095
  const cliArgs = [];
22096
+ const launchEnv = {};
21991
22097
  if (systemPrompt) {
21992
- cliArgs.push("--append-system-prompt", systemPrompt);
22098
+ if (configFormat === "hermes_config_yaml") {
22099
+ launchEnv.HERMES_EPHEMERAL_SYSTEM_PROMPT = systemPrompt;
22100
+ } else {
22101
+ cliArgs.push("--append-system-prompt", systemPrompt);
22102
+ }
21993
22103
  }
21994
22104
  if (cliType === "claude-cli") {
21995
22105
  cliArgs.push("--mcp-config", coordinatorSetup.configPath);
@@ -21998,6 +22108,7 @@ var DaemonCommandRouter = class {
21998
22108
  cliType,
21999
22109
  dir: workspace,
22000
22110
  cliArgs: cliArgs.length > 0 ? cliArgs : void 0,
22111
+ env: Object.keys(launchEnv).length > 0 ? launchEnv : void 0,
22001
22112
  settings: {
22002
22113
  meshCoordinatorFor: meshId
22003
22114
  }
@@ -23659,10 +23770,10 @@ var ProviderInstanceManager = class {
23659
23770
  // src/providers/version-archive.ts
23660
23771
  var fs11 = __toESM(require("fs"));
23661
23772
  var path22 = __toESM(require("path"));
23662
- var os19 = __toESM(require("os"));
23773
+ var os20 = __toESM(require("os"));
23663
23774
  var import_child_process10 = require("child_process");
23664
23775
  var import_os3 = require("os");
23665
- var ARCHIVE_PATH = path22.join(os19.homedir(), ".adhdev", "version-history.json");
23776
+ var ARCHIVE_PATH = path22.join(os20.homedir(), ".adhdev", "version-history.json");
23666
23777
  var MAX_ENTRIES_PER_PROVIDER = 20;
23667
23778
  var VersionArchive = class {
23668
23779
  history = {};
@@ -23765,7 +23876,7 @@ function getVersion(binary, versionCommand) {
23765
23876
  function checkPathExists2(paths) {
23766
23877
  for (const p of paths) {
23767
23878
  if (p.includes("*")) {
23768
- const home = os19.homedir();
23879
+ const home = os20.homedir();
23769
23880
  const resolved = p.replace(/\*/g, home.split(path22.sep).pop() || "");
23770
23881
  if (fs11.existsSync(resolved)) return resolved;
23771
23882
  } else {
@@ -26154,7 +26265,7 @@ async function handleCliRaw(ctx, req, res) {
26154
26265
  // src/daemon/dev-auto-implement.ts
26155
26266
  var fs14 = __toESM(require("fs"));
26156
26267
  var path25 = __toESM(require("path"));
26157
- var os20 = __toESM(require("os"));
26268
+ var os21 = __toESM(require("os"));
26158
26269
  function getAutoImplPid(ctx) {
26159
26270
  const pid = ctx.autoImplProcess?.pid;
26160
26271
  return typeof pid === "number" && pid > 0 ? pid : null;
@@ -26355,7 +26466,7 @@ async function handleAutoImplement(ctx, type, req, res) {
26355
26466
  });
26356
26467
  const referenceScripts = loadAutoImplReferenceScripts(ctx, resolvedReference);
26357
26468
  const prompt = buildAutoImplPrompt(ctx, type, provider, providerDir, functions, domContext, referenceScripts, comment, resolvedReference, verification);
26358
- const tmpDir = path25.join(os20.tmpdir(), "adhdev-autoimpl");
26469
+ const tmpDir = path25.join(os21.tmpdir(), "adhdev-autoimpl");
26359
26470
  if (!fs14.existsSync(tmpDir)) fs14.mkdirSync(tmpDir, { recursive: true });
26360
26471
  const promptFile = path25.join(tmpDir, `prompt-${type}-${Date.now()}.md`);
26361
26472
  fs14.writeFileSync(promptFile, prompt, "utf-8");
@@ -26510,7 +26621,7 @@ async function handleAutoImplement(ctx, type, req, res) {
26510
26621
  const interactiveFlags = ["--yolo", "--interactive", "-i"];
26511
26622
  const baseArgs = [...spawn4.args || []].filter((a) => !interactiveFlags.includes(a));
26512
26623
  let shellCmd;
26513
- const isWin = os20.platform() === "win32";
26624
+ const isWin = os21.platform() === "win32";
26514
26625
  const escapeArg = (a) => isWin ? `"${a.replace(/"/g, '""')}"` : `'${a.replace(/'/g, "'\\''")}'`;
26515
26626
  const promptMode = autoImpl?.promptMode ?? "stdin";
26516
26627
  const extraArgs = autoImpl?.extraArgs ?? [];
@@ -26549,7 +26660,7 @@ async function handleAutoImplement(ctx, type, req, res) {
26549
26660
  try {
26550
26661
  const pty = require("node-pty");
26551
26662
  ctx.log(`Auto-implement spawn (PTY): ${shellCmd}`);
26552
- const isWin2 = os20.platform() === "win32";
26663
+ const isWin2 = os21.platform() === "win32";
26553
26664
  child = pty.spawn(isWin2 ? "cmd.exe" : process.env.SHELL || "/bin/zsh", [isWin2 ? "/c" : "-c", shellCmd], {
26554
26665
  name: "xterm-256color",
26555
26666
  cols: 120,