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

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
@@ -1630,7 +1630,7 @@ import * as os10 from "os";
1630
1630
  import * as path15 from "path";
1631
1631
  import { DEFAULT_SESSION_HOST_COLS, DEFAULT_SESSION_HOST_ROWS } from "@adhdev/session-host-core";
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,
@@ -1753,8 +1753,9 @@ var init_provider_cli_adapter = __esm({
1753
1753
  init_provider_cli_runtime();
1754
1754
  init_provider_cli_shared();
1755
1755
  ProviderCliAdapter = class _ProviderCliAdapter {
1756
- constructor(provider, workingDir, extraArgs = [], transportFactory = new NodePtyTransportFactory()) {
1756
+ constructor(provider, workingDir, extraArgs = [], extraEnv = {}, transportFactory = new NodePtyTransportFactory()) {
1757
1757
  this.extraArgs = extraArgs;
1758
+ this.extraEnv = extraEnv;
1758
1759
  this.provider = provider;
1759
1760
  this.transportFactory = transportFactory;
1760
1761
  this.cliType = provider.type;
@@ -2070,7 +2071,8 @@ ${lastSnapshot}`;
2070
2071
  provider: this.provider,
2071
2072
  runtimeSettings: this.runtimeSettings,
2072
2073
  workingDir: this.workingDir,
2073
- extraArgs: this.extraArgs
2074
+ extraArgs: this.extraArgs,
2075
+ extraEnv: this.extraEnv
2074
2076
  });
2075
2077
  LOG.info("CLI", `[${this.cliType}] Spawning in ${this.workingDir}`);
2076
2078
  this.resetTraceSession();
@@ -5786,17 +5788,17 @@ function checkPathExists(paths) {
5786
5788
  return null;
5787
5789
  }
5788
5790
  async function detectIDEs(providerLoader) {
5789
- const os21 = platform();
5791
+ const os22 = platform();
5790
5792
  const results = [];
5791
5793
  for (const def of getMergedDefinitions()) {
5792
5794
  const cliPath = findCliCommand(providerLoader?.getIdeCliCommand(def.id, def.cli) || def.cli);
5793
- const appPath = checkPathExists(providerLoader?.getIdePathCandidates(def.id, def.paths[os21] || []) || []);
5795
+ const appPath = checkPathExists(providerLoader?.getIdePathCandidates(def.id, def.paths[os22] || []) || []);
5794
5796
  let resolvedCli = cliPath;
5795
- if (!resolvedCli && appPath && os21 === "darwin") {
5797
+ if (!resolvedCli && appPath && os22 === "darwin") {
5796
5798
  const bundledCli = `${appPath}/Contents/Resources/app/bin/${def.cli}`;
5797
5799
  if (existsSync6(bundledCli)) resolvedCli = bundledCli;
5798
5800
  }
5799
- if (!resolvedCli && appPath && os21 === "win32") {
5801
+ if (!resolvedCli && appPath && os22 === "win32") {
5800
5802
  const { dirname: dirname9 } = await import("path");
5801
5803
  const appDir = dirname9(appPath);
5802
5804
  const candidates = [
@@ -5813,7 +5815,7 @@ async function detectIDEs(providerLoader) {
5813
5815
  }
5814
5816
  }
5815
5817
  }
5816
- const installed = os21 === "darwin" ? !!(resolvedCli || appPath) : !!resolvedCli;
5818
+ const installed = os22 === "darwin" ? !!(resolvedCli || appPath) : !!resolvedCli;
5817
5819
  const version = resolvedCli ? getIdeVersion(resolvedCli) : null;
5818
5820
  results.push({
5819
5821
  id: def.id,
@@ -14746,7 +14748,7 @@ var CliProviderInstance = class {
14746
14748
  this.providerSessionId = options?.providerSessionId;
14747
14749
  this.launchMode = options?.launchMode || "new";
14748
14750
  this.onProviderSessionResolved = options?.onProviderSessionResolved;
14749
- this.adapter = new ProviderCliAdapter(provider, workingDir, cliArgs, transportFactory);
14751
+ this.adapter = new ProviderCliAdapter(provider, workingDir, cliArgs, options?.extraEnv || {}, transportFactory);
14750
14752
  this.monitor = new StatusMonitor();
14751
14753
  this.historyWriter = new ChatHistoryWriter();
14752
14754
  }
@@ -16962,7 +16964,7 @@ var DaemonCliManager = class {
16962
16964
  attachExisting
16963
16965
  }) || void 0;
16964
16966
  }
16965
- createAdapter(cliType, workingDir, cliArgs, runtimeId, providerSessionId, attachExisting = false) {
16967
+ createAdapter(cliType, workingDir, cliArgs, runtimeId, providerSessionId, attachExisting = false, extraEnv) {
16966
16968
  const normalizedType = this.providerLoader.resolveAlias(cliType);
16967
16969
  const provider = this.providerLoader.getMeta(normalizedType);
16968
16970
  if (provider && provider.category === "cli" && provider.patterns && provider.spawn) {
@@ -16976,7 +16978,7 @@ var DaemonCliManager = class {
16976
16978
  providerSessionId,
16977
16979
  attachExisting
16978
16980
  );
16979
- return new ProviderCliAdapter(resolvedProvider, workingDir, cliArgs, transportFactory);
16981
+ return new ProviderCliAdapter(resolvedProvider, workingDir, cliArgs, extraEnv || {}, transportFactory);
16980
16982
  }
16981
16983
  throw new Error(`No CLI provider found for '${cliType}'. Create a provider.js in providers/cli/${cliType}/`);
16982
16984
  }
@@ -17179,6 +17181,7 @@ Run 'adhdev doctor' for detailed diagnostics.`
17179
17181
  {
17180
17182
  providerSessionId: sessionBinding.providerSessionId,
17181
17183
  launchMode: sessionBinding.launchMode,
17184
+ extraEnv: options?.extraEnv,
17182
17185
  onProviderSessionResolved: ({ providerSessionId, providerName, providerType, workspace }) => {
17183
17186
  this.persistRecentActivity({
17184
17187
  kind: "cli",
@@ -17199,7 +17202,8 @@ Run 'adhdev doctor' for detailed diagnostics.`
17199
17202
  resolvedCliArgs,
17200
17203
  key,
17201
17204
  sessionBinding.providerSessionId,
17202
- false
17205
+ false,
17206
+ options?.extraEnv
17203
17207
  );
17204
17208
  try {
17205
17209
  await adapter.spawn();
@@ -17428,7 +17432,7 @@ Run 'adhdev doctor' for detailed diagnostics.`
17428
17432
  dir,
17429
17433
  args?.cliArgs,
17430
17434
  args?.initialModel,
17431
- { resumeSessionId: args?.resumeSessionId, settingsOverride: args?.settings }
17435
+ { resumeSessionId: args?.resumeSessionId, settingsOverride: args?.settings, extraEnv: args?.env }
17432
17436
  );
17433
17437
  return {
17434
17438
  success: true,
@@ -19968,11 +19972,13 @@ cleanOldFiles();
19968
19972
 
19969
19973
  // src/commands/router.ts
19970
19974
  init_logger();
19975
+ import * as yaml from "js-yaml";
19971
19976
 
19972
19977
  // src/commands/mesh-coordinator.ts
19973
19978
  import { existsSync as existsSync15, realpathSync as realpathSync2 } from "fs";
19974
19979
  import { createRequire as createRequire2 } from "module";
19975
- import { dirname as dirname4, join as join18, resolve as resolve13 } from "path";
19980
+ import * as os17 from "os";
19981
+ import { dirname as dirname4, isAbsolute as isAbsolute10, join as join18, resolve as resolve13 } from "path";
19976
19982
  var DEFAULT_SERVER_NAME = "adhdev-mesh";
19977
19983
  var DEFAULT_ADHDEV_MCP_COMMAND = "adhdev-mcp";
19978
19984
  function resolveMeshCoordinatorSetup(options) {
@@ -20011,7 +20017,7 @@ function resolveMeshCoordinatorSetup(options) {
20011
20017
  return {
20012
20018
  kind: "auto_import",
20013
20019
  serverName,
20014
- configPath: join18(workspace, path27),
20020
+ configPath: resolveMcpConfigPath(path27, workspace),
20015
20021
  configFormat: mcpConfig.format,
20016
20022
  mcpServer
20017
20023
  };
@@ -20045,6 +20051,13 @@ function resolveMeshCoordinatorSetup(options) {
20045
20051
  function renderMeshCoordinatorTemplate(template, values) {
20046
20052
  return template.replace(/\{\{\s*(meshId|workspace|serverName|adhdevMcpCommand)\s*\}\}/g, (_, key) => values[key] || "");
20047
20053
  }
20054
+ function resolveMcpConfigPath(configPath, workspace) {
20055
+ const trimmed = configPath.trim();
20056
+ if (trimmed === "~") return os17.homedir();
20057
+ if (trimmed.startsWith("~/")) return join18(os17.homedir(), trimmed.slice(2));
20058
+ if (isAbsolute10(trimmed)) return trimmed;
20059
+ return join18(workspace, trimmed);
20060
+ }
20048
20061
  function resolveAdhdevMcpServerLaunch(options) {
20049
20062
  const entryPath = resolveAdhdevMcpEntryPath(options.adhdevMcpEntryPath);
20050
20063
  if (!entryPath) return null;
@@ -20097,7 +20110,7 @@ function normalizeExistingPath(filePath) {
20097
20110
 
20098
20111
  // src/status/snapshot.ts
20099
20112
  init_config();
20100
- import * as os17 from "os";
20113
+ import * as os18 from "os";
20101
20114
  init_terminal_screen();
20102
20115
  init_logger();
20103
20116
  var READ_DEBUG_ENABLED = process.argv.includes("--dev") || process.env.ADHDEV_READ_DEBUG === "1";
@@ -20152,8 +20165,8 @@ function buildAvailableProviders(providerLoader) {
20152
20165
  }
20153
20166
  function buildMachineInfo(profile = "full") {
20154
20167
  const base = {
20155
- hostname: os17.hostname(),
20156
- platform: os17.platform()
20168
+ hostname: os18.hostname(),
20169
+ platform: os18.platform()
20157
20170
  };
20158
20171
  if (profile === "live") {
20159
20172
  return base;
@@ -20162,23 +20175,23 @@ function buildMachineInfo(profile = "full") {
20162
20175
  const memSnap2 = getHostMemorySnapshot();
20163
20176
  return {
20164
20177
  ...base,
20165
- arch: os17.arch(),
20166
- cpus: os17.cpus().length,
20178
+ arch: os18.arch(),
20179
+ cpus: os18.cpus().length,
20167
20180
  totalMem: memSnap2.totalMem,
20168
- release: os17.release()
20181
+ release: os18.release()
20169
20182
  };
20170
20183
  }
20171
20184
  const memSnap = getHostMemorySnapshot();
20172
20185
  return {
20173
20186
  ...base,
20174
- arch: os17.arch(),
20175
- cpus: os17.cpus().length,
20187
+ arch: os18.arch(),
20188
+ cpus: os18.cpus().length,
20176
20189
  totalMem: memSnap.totalMem,
20177
20190
  freeMem: memSnap.freeMem,
20178
20191
  availableMem: memSnap.availableMem,
20179
- loadavg: os17.loadavg(),
20180
- uptime: os17.uptime(),
20181
- release: os17.release()
20192
+ loadavg: os18.loadavg(),
20193
+ uptime: os18.uptime(),
20194
+ release: os18.release()
20182
20195
  };
20183
20196
  }
20184
20197
  function parseMessageTime(value) {
@@ -20412,11 +20425,11 @@ function buildStatusSnapshot(options) {
20412
20425
  import { execFileSync as execFileSync2 } from "child_process";
20413
20426
  import { spawn as spawn3 } from "child_process";
20414
20427
  import * as fs9 from "fs";
20415
- import * as os18 from "os";
20428
+ import * as os19 from "os";
20416
20429
  import * as path21 from "path";
20417
20430
  var UPGRADE_HELPER_ENV = "ADHDEV_DAEMON_UPGRADE_HELPER";
20418
20431
  function getUpgradeLogPath() {
20419
- const home = os18.homedir();
20432
+ const home = os19.homedir();
20420
20433
  const dir = path21.join(home, ".adhdev");
20421
20434
  fs9.mkdirSync(dir, { recursive: true });
20422
20435
  return path21.join(dir, "daemon-upgrade.log");
@@ -20608,7 +20621,7 @@ async function waitForPidExit(pid, timeoutMs) {
20608
20621
  }
20609
20622
  }
20610
20623
  function stopSessionHostProcesses(appName) {
20611
- const pidFile = path21.join(os18.homedir(), ".adhdev", `${appName}-session-host.pid`);
20624
+ const pidFile = path21.join(os19.homedir(), ".adhdev", `${appName}-session-host.pid`);
20612
20625
  try {
20613
20626
  if (fs9.existsSync(pidFile)) {
20614
20627
  const pid = Number.parseInt(fs9.readFileSync(pidFile, "utf8").trim(), 10);
@@ -20625,7 +20638,7 @@ function stopSessionHostProcesses(appName) {
20625
20638
  }
20626
20639
  }
20627
20640
  function removeDaemonPidFile() {
20628
- const pidFile = path21.join(os18.homedir(), ".adhdev", "daemon.pid");
20641
+ const pidFile = path21.join(os19.homedir(), ".adhdev", "daemon.pid");
20629
20642
  try {
20630
20643
  fs9.unlinkSync(pidFile);
20631
20644
  } catch {
@@ -20763,6 +20776,22 @@ function normalizeReleaseChannel(value) {
20763
20776
  function resolveUpgradeChannel(args) {
20764
20777
  return normalizeReleaseChannel(args?.channel) || normalizeReleaseChannel(args?.updatePolicy?.channel) || normalizeReleaseChannel(args?.npmTag) || normalizeReleaseChannel(loadConfig().updateChannel) || "stable";
20765
20778
  }
20779
+ function loadYamlModule() {
20780
+ return yaml;
20781
+ }
20782
+ function getMcpServersKey(format) {
20783
+ return format === "hermes_config_yaml" ? "mcp_servers" : "mcpServers";
20784
+ }
20785
+ function parseMeshCoordinatorMcpConfig(text, format) {
20786
+ if (!text.trim()) return {};
20787
+ if (format === "claude_mcp_json") return JSON.parse(text);
20788
+ const parsed = loadYamlModule().load(text);
20789
+ return parsed && typeof parsed === "object" && !Array.isArray(parsed) ? parsed : {};
20790
+ }
20791
+ function serializeMeshCoordinatorMcpConfig(config, format) {
20792
+ if (format === "claude_mcp_json") return JSON.stringify(config, null, 2);
20793
+ return loadYamlModule().dump(config, { noRefs: true, lineWidth: 120 });
20794
+ }
20766
20795
  var CHAT_COMMANDS = [
20767
20796
  "send_chat",
20768
20797
  "new_chat",
@@ -21740,7 +21769,8 @@ var DaemonCommandRouter = class {
21740
21769
  meshCoordinatorSetup: coordinatorSetup
21741
21770
  };
21742
21771
  }
21743
- if (coordinatorSetup.configFormat !== "claude_mcp_json") {
21772
+ const configFormat = coordinatorSetup.configFormat;
21773
+ if (configFormat !== "claude_mcp_json" && configFormat !== "hermes_config_yaml") {
21744
21774
  return {
21745
21775
  success: false,
21746
21776
  code: "mesh_coordinator_unsupported",
@@ -21765,15 +21795,23 @@ var DaemonCommandRouter = class {
21765
21795
  workspace
21766
21796
  };
21767
21797
  }
21768
- const { existsSync: existsSync23, readFileSync: readFileSync15, writeFileSync: writeFileSync12, copyFileSync: copyFileSync3 } = await import("fs");
21798
+ const { existsSync: existsSync23, readFileSync: readFileSync15, writeFileSync: writeFileSync12, copyFileSync: copyFileSync3, mkdirSync: mkdirSync14 } = await import("fs");
21799
+ const { dirname: dirname9 } = await import("path");
21769
21800
  const mcpConfigPath = coordinatorSetup.configPath;
21801
+ mkdirSync14(dirname9(mcpConfigPath), { recursive: true });
21770
21802
  const hadExistingMcpConfig = existsSync23(mcpConfigPath);
21771
21803
  let existingMcpConfig = {};
21772
21804
  if (hadExistingMcpConfig) {
21773
21805
  try {
21774
- existingMcpConfig = JSON.parse(readFileSync15(mcpConfigPath, "utf-8"));
21806
+ existingMcpConfig = parseMeshCoordinatorMcpConfig(readFileSync15(mcpConfigPath, "utf-8"), configFormat);
21775
21807
  copyFileSync3(mcpConfigPath, mcpConfigPath + ".backup");
21776
- } catch {
21808
+ } catch (error) {
21809
+ LOG.error("MeshCoordinator", `Failed to parse existing MCP config ${mcpConfigPath}: ${error?.message || error}`);
21810
+ return {
21811
+ success: false,
21812
+ code: "mesh_coordinator_config_parse_failed",
21813
+ error: `Failed to parse existing MCP config at ${mcpConfigPath}`
21814
+ };
21777
21815
  }
21778
21816
  }
21779
21817
  const mcpServerEntry = {
@@ -21786,18 +21824,25 @@ var DaemonCommandRouter = class {
21786
21824
  ADHDEV_MCP_TRANSPORT: "ipc"
21787
21825
  };
21788
21826
  }
21827
+ const mcpServersKey = getMcpServersKey(configFormat);
21828
+ const existingServers = existingMcpConfig[mcpServersKey];
21789
21829
  const mcpConfig = {
21790
21830
  ...existingMcpConfig,
21791
- mcpServers: {
21792
- ...existingMcpConfig.mcpServers || {},
21831
+ [mcpServersKey]: {
21832
+ ...existingServers && typeof existingServers === "object" && !Array.isArray(existingServers) ? existingServers : {},
21793
21833
  [coordinatorSetup.serverName]: mcpServerEntry
21794
21834
  }
21795
21835
  };
21796
- writeFileSync12(mcpConfigPath, JSON.stringify(mcpConfig, null, 2), "utf-8");
21836
+ writeFileSync12(mcpConfigPath, serializeMeshCoordinatorMcpConfig(mcpConfig, configFormat), "utf-8");
21797
21837
  LOG.info("MeshCoordinator", `Wrote ${mcpConfigPath} with ${coordinatorSetup.serverName} server`);
21798
21838
  const cliArgs = [];
21839
+ const launchEnv = {};
21799
21840
  if (systemPrompt) {
21800
- cliArgs.push("--append-system-prompt", systemPrompt);
21841
+ if (configFormat === "hermes_config_yaml") {
21842
+ launchEnv.HERMES_EPHEMERAL_SYSTEM_PROMPT = systemPrompt;
21843
+ } else {
21844
+ cliArgs.push("--append-system-prompt", systemPrompt);
21845
+ }
21801
21846
  }
21802
21847
  if (cliType === "claude-cli") {
21803
21848
  cliArgs.push("--mcp-config", coordinatorSetup.configPath);
@@ -21806,6 +21851,7 @@ var DaemonCommandRouter = class {
21806
21851
  cliType,
21807
21852
  dir: workspace,
21808
21853
  cliArgs: cliArgs.length > 0 ? cliArgs : void 0,
21854
+ env: Object.keys(launchEnv).length > 0 ? launchEnv : void 0,
21809
21855
  settings: {
21810
21856
  meshCoordinatorFor: meshId
21811
21857
  }
@@ -23467,10 +23513,10 @@ var ProviderInstanceManager = class {
23467
23513
  // src/providers/version-archive.ts
23468
23514
  import * as fs11 from "fs";
23469
23515
  import * as path22 from "path";
23470
- import * as os19 from "os";
23516
+ import * as os20 from "os";
23471
23517
  import { execSync as execSync5 } from "child_process";
23472
23518
  import { platform as platform8 } from "os";
23473
- var ARCHIVE_PATH = path22.join(os19.homedir(), ".adhdev", "version-history.json");
23519
+ var ARCHIVE_PATH = path22.join(os20.homedir(), ".adhdev", "version-history.json");
23474
23520
  var MAX_ENTRIES_PER_PROVIDER = 20;
23475
23521
  var VersionArchive = class {
23476
23522
  history = {};
@@ -23573,7 +23619,7 @@ function getVersion(binary, versionCommand) {
23573
23619
  function checkPathExists2(paths) {
23574
23620
  for (const p of paths) {
23575
23621
  if (p.includes("*")) {
23576
- const home = os19.homedir();
23622
+ const home = os20.homedir();
23577
23623
  const resolved = p.replace(/\*/g, home.split(path22.sep).pop() || "");
23578
23624
  if (fs11.existsSync(resolved)) return resolved;
23579
23625
  } else {
@@ -25962,7 +26008,7 @@ async function handleCliRaw(ctx, req, res) {
25962
26008
  // src/daemon/dev-auto-implement.ts
25963
26009
  import * as fs14 from "fs";
25964
26010
  import * as path25 from "path";
25965
- import * as os20 from "os";
26011
+ import * as os21 from "os";
25966
26012
  function getAutoImplPid(ctx) {
25967
26013
  const pid = ctx.autoImplProcess?.pid;
25968
26014
  return typeof pid === "number" && pid > 0 ? pid : null;
@@ -26163,7 +26209,7 @@ async function handleAutoImplement(ctx, type, req, res) {
26163
26209
  });
26164
26210
  const referenceScripts = loadAutoImplReferenceScripts(ctx, resolvedReference);
26165
26211
  const prompt = buildAutoImplPrompt(ctx, type, provider, providerDir, functions, domContext, referenceScripts, comment, resolvedReference, verification);
26166
- const tmpDir = path25.join(os20.tmpdir(), "adhdev-autoimpl");
26212
+ const tmpDir = path25.join(os21.tmpdir(), "adhdev-autoimpl");
26167
26213
  if (!fs14.existsSync(tmpDir)) fs14.mkdirSync(tmpDir, { recursive: true });
26168
26214
  const promptFile = path25.join(tmpDir, `prompt-${type}-${Date.now()}.md`);
26169
26215
  fs14.writeFileSync(promptFile, prompt, "utf-8");
@@ -26318,7 +26364,7 @@ async function handleAutoImplement(ctx, type, req, res) {
26318
26364
  const interactiveFlags = ["--yolo", "--interactive", "-i"];
26319
26365
  const baseArgs = [...spawn4.args || []].filter((a) => !interactiveFlags.includes(a));
26320
26366
  let shellCmd;
26321
- const isWin = os20.platform() === "win32";
26367
+ const isWin = os21.platform() === "win32";
26322
26368
  const escapeArg = (a) => isWin ? `"${a.replace(/"/g, '""')}"` : `'${a.replace(/'/g, "'\\''")}'`;
26323
26369
  const promptMode = autoImpl?.promptMode ?? "stdin";
26324
26370
  const extraArgs = autoImpl?.extraArgs ?? [];
@@ -26357,7 +26403,7 @@ async function handleAutoImplement(ctx, type, req, res) {
26357
26403
  try {
26358
26404
  const pty = __require("node-pty");
26359
26405
  ctx.log(`Auto-implement spawn (PTY): ${shellCmd}`);
26360
- const isWin2 = os20.platform() === "win32";
26406
+ const isWin2 = os21.platform() === "win32";
26361
26407
  child = pty.spawn(isWin2 ? "cmd.exe" : process.env.SHELL || "/bin/zsh", [isWin2 ? "/c" : "-c", shellCmd], {
26362
26408
  name: "xterm-256color",
26363
26409
  cols: 120,