@adhdev/daemon-core 0.9.82-rc.358 → 0.9.82-rc.359

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
@@ -311,10 +311,10 @@ function readInjected(value) {
311
311
  }
312
312
  function getDaemonBuildInfo() {
313
313
  if (cached) return cached;
314
- const commit = readInjected(true ? "7210e80591d8d9ab378ee786ffb233027437461a" : void 0) ?? "unknown";
315
- const commitShort = readInjected(true ? "7210e805" : void 0) ?? (commit !== "unknown" ? commit.slice(0, 7) : "unknown");
316
- const version = readInjected(true ? "0.9.82-rc.358" : void 0) ?? readInjected(typeof process !== "undefined" ? process.env?.ADHDEV_PKG_VERSION : void 0) ?? "unknown";
317
- const builtAt = readInjected(true ? "2026-06-23T01:40:53.249Z" : void 0);
314
+ const commit = readInjected(true ? "56a1f2a986ab2c2bb7888189d9b027d6067f2317" : void 0) ?? "unknown";
315
+ const commitShort = readInjected(true ? "56a1f2a9" : void 0) ?? (commit !== "unknown" ? commit.slice(0, 7) : "unknown");
316
+ const version = readInjected(true ? "0.9.82-rc.359" : void 0) ?? readInjected(typeof process !== "undefined" ? process.env?.ADHDEV_PKG_VERSION : void 0) ?? "unknown";
317
+ const builtAt = readInjected(true ? "2026-06-23T05:03:11.133Z" : void 0);
318
318
  cached = builtAt ? { commit, commitShort, version, builtAt } : { commit, commitShort, version };
319
319
  return cached;
320
320
  }
@@ -13012,9 +13012,7 @@ function isLocalAutoLaunchNode(node) {
13012
13012
  const machineId = readNonEmptyString2(node?.machineId);
13013
13013
  const appConfig = loadConfig();
13014
13014
  const localMachineId = readNonEmptyString2(appConfig.machineId) || readNonEmptyString2(appConfig.registeredMachineId);
13015
- const cloudDaemonId = localMachineId ? `daemon_${localMachineId}` : "";
13016
- const standaloneDaemonId = localMachineId ? `standalone_${localMachineId}` : "";
13017
- const daemonMatchesLocal = !daemonId || daemonId === cloudDaemonId || daemonId === standaloneDaemonId;
13015
+ const daemonMatchesLocal = !daemonId || daemonIdsEquivalent(daemonId, localMachineId);
13018
13016
  const machineMatchesLocal = !machineId || !!localMachineId && machineId === localMachineId;
13019
13017
  if (node?.isLocalWorktree === true) {
13020
13018
  return daemonMatchesLocal && machineMatchesLocal;
@@ -13950,7 +13948,7 @@ function injectMeshSystemMessage(components, args) {
13950
13948
  targetNodeId: autoNodeId
13951
13949
  });
13952
13950
  LOG.info("MeshRecovery", `Auto-requeued failed task: ${task.id} for node ${autoNodeId}`);
13953
- const node = mesh?.nodes.find((n) => n.id === autoNodeId);
13951
+ const node = mesh?.nodes.find((n) => meshNodeIdMatches(n, autoNodeId));
13954
13952
  if (node) {
13955
13953
  components.cliManager.handleCliCommand("launch_cli", {
13956
13954
  cliType: recoveryContext.failedProviderType,
@@ -14679,7 +14677,7 @@ async function pullRemoteNodeQueues(components, mesh, localDaemonId, candidateDa
14679
14677
  for (const node of mesh.nodes) {
14680
14678
  const nodeDaemonId = readNonEmptyString2(node.daemonId);
14681
14679
  if (!nodeDaemonId) continue;
14682
- if (localDaemonId && nodeDaemonId === localDaemonId) continue;
14680
+ if (daemonIdsEquivalent(nodeDaemonId, localDaemonId)) continue;
14683
14681
  if (candidateDaemonIds.includes(nodeDaemonId)) continue;
14684
14682
  for (const pendingEventArgs of pulls) {
14685
14683
  let events;
@@ -14736,7 +14734,7 @@ async function reconcileUnterminatedDirectDispatches(components, mesh, selfIds,
14736
14734
  if (!sessionId || !nodeId || !taskId) continue;
14737
14735
  const node = nodeById.get(nodeId);
14738
14736
  const nodeDaemonId = readNonEmptyString2(node?.daemonId);
14739
- const isLocalNode = !nodeDaemonId || selfIds.includes(nodeDaemonId) || localDaemonId !== void 0 && nodeDaemonId === localDaemonId || !!components.instanceManager.getInstance(sessionId);
14737
+ const isLocalNode = !nodeDaemonId || selfIds.includes(nodeDaemonId) || daemonIdsEquivalent(nodeDaemonId, localDaemonId) || !!components.instanceManager.getInstance(sessionId);
14740
14738
  const providerType = readNonEmptyString2(dispatch.providerType);
14741
14739
  const readArgs = {
14742
14740
  sessionId,
@@ -14811,7 +14809,7 @@ async function collectLiveNodesWithSessions(components, mesh, selfIds, localDaem
14811
14809
  const dispatchMeshCommand = components.dispatchMeshCommand;
14812
14810
  return Promise.all(mesh.nodes.map(async (node) => {
14813
14811
  const nodeDaemonId = readNonEmptyString2(node.daemonId);
14814
- const isLocalNode = !nodeDaemonId || selfIds.includes(nodeDaemonId) || localDaemonId !== void 0 && nodeDaemonId === localDaemonId;
14812
+ const isLocalNode = !nodeDaemonId || selfIds.includes(nodeDaemonId) || daemonIdsEquivalent(nodeDaemonId, localDaemonId);
14815
14813
  let statusResult;
14816
14814
  try {
14817
14815
  if (isLocalNode) {
@@ -44509,6 +44507,7 @@ function buildInstallEnvWithNodeOnPath(baseEnv = process.env) {
44509
44507
  const pathKey = Object.keys(env).find((k) => k.toLowerCase() === "path") || "PATH";
44510
44508
  const current = env[pathKey] || "";
44511
44509
  env[pathKey] = current ? `${nodeBinDir};${current}` : nodeBinDir;
44510
+ env.ADHDEV_BOOTSTRAP = "1";
44512
44511
  return env;
44513
44512
  }
44514
44513
  function getNpmExecOptions(platform10 = process.platform) {
@@ -44618,6 +44617,94 @@ async function stopSessionHostProcesses(appName) {
44618
44617
  await waitForPidExit(killedPid, 15e3);
44619
44618
  }
44620
44619
  }
44620
+ var LOCKED_NATIVE_ADDON_BASENAMES = ["conpty.node", "ghostty-vt.dll"];
44621
+ function listForeignNativeAddonHolders(packageRoot) {
44622
+ if (process.platform !== "win32" || !packageRoot) return [];
44623
+ const rootLower = packageRoot.replace(/\//g, "\\").replace(/'/g, "''").toLowerCase();
44624
+ const endsWithChecks = LOCKED_NATIVE_ADDON_BASENAMES.map((name) => `$lf.EndsWith('${name}')`).join(" -or ");
44625
+ const script = [
44626
+ `$root = '${rootLower}'`,
44627
+ `Get-Process node -ErrorAction SilentlyContinue | ForEach-Object {`,
44628
+ ` $p = $_`,
44629
+ ` try {`,
44630
+ ` foreach ($m in $p.Modules) {`,
44631
+ ` $fn = $m.FileName`,
44632
+ ` if ($fn) {`,
44633
+ ` $lf = $fn.ToLower()`,
44634
+ ` if ($lf.StartsWith($root) -and (${endsWithChecks})) { $p.Id; break }`,
44635
+ ` }`,
44636
+ ` }`,
44637
+ ` } catch {}`,
44638
+ `}`
44639
+ ].join("\n");
44640
+ let out = "";
44641
+ try {
44642
+ out = String(execFileSync5("powershell.exe", [
44643
+ "-NoProfile",
44644
+ "-NonInteractive",
44645
+ "-ExecutionPolicy",
44646
+ "Bypass",
44647
+ "-Command",
44648
+ script
44649
+ ], { encoding: "utf8", timeout: 8e3, stdio: ["ignore", "pipe", "ignore"], windowsHide: true })).trim();
44650
+ } catch {
44651
+ return [];
44652
+ }
44653
+ const selfPid = process.pid;
44654
+ const seen = /* @__PURE__ */ new Set();
44655
+ const holders = [];
44656
+ for (const line of out.split(/\r?\n/)) {
44657
+ const pid = Number.parseInt(line.trim(), 10);
44658
+ if (!Number.isFinite(pid) || pid <= 0 || pid === selfPid || seen.has(pid)) continue;
44659
+ seen.add(pid);
44660
+ holders.push({ pid, commandLine: getProcessCommandLine(pid) });
44661
+ }
44662
+ return holders;
44663
+ }
44664
+ async function stopForeignNativeAddonHolders(packageRoot, options = {}) {
44665
+ if (process.platform !== "win32" || !packageRoot) return [];
44666
+ const parentPid = Number.isFinite(options.parentPid) ? Number(options.parentPid) : -1;
44667
+ const holders = listForeignNativeAddonHolders(packageRoot);
44668
+ const results = [];
44669
+ for (const holder of holders) {
44670
+ if (holder.pid === parentPid) continue;
44671
+ appendUpgradeLog(
44672
+ `Foreign native-addon holder found: pid ${holder.pid}${holder.commandLine ? ` \u2014 ${holder.commandLine}` : ""}`
44673
+ );
44674
+ const killed = killPid(holder.pid);
44675
+ if (killed) {
44676
+ await waitForPidExit(holder.pid, 15e3);
44677
+ appendUpgradeLog(`Terminated foreign native-addon holder pid ${holder.pid}`);
44678
+ } else {
44679
+ appendUpgradeLog(`Failed to terminate foreign native-addon holder pid ${holder.pid}`);
44680
+ }
44681
+ results.push({ ...holder, killed });
44682
+ }
44683
+ return results;
44684
+ }
44685
+ function getUpgradeFailureNoticePath() {
44686
+ const home = os27.homedir();
44687
+ const dir = path36.join(home, ".adhdev");
44688
+ try {
44689
+ fs25.mkdirSync(dir, { recursive: true });
44690
+ } catch {
44691
+ }
44692
+ return path36.join(dir, "daemon-upgrade-last-error.txt");
44693
+ }
44694
+ function buildManualRecoveryCommand(installCommand) {
44695
+ return [installCommand.command, ...installCommand.args].map((part) => /\s/.test(part) ? `"${part}"` : part).join(" ");
44696
+ }
44697
+ function emitUpgradeFailureNotice(lines) {
44698
+ const body = lines.join("\n");
44699
+ appendUpgradeLog(`Upgrade blocked \u2014 user action required:
44700
+ ${body}`);
44701
+ try {
44702
+ fs25.writeFileSync(getUpgradeFailureNoticePath(), `[${(/* @__PURE__ */ new Date()).toISOString()}]
44703
+ ${body}
44704
+ `, "utf8");
44705
+ } catch {
44706
+ }
44707
+ }
44621
44708
  function isRetriableInstallLockError(error) {
44622
44709
  const code = error?.code;
44623
44710
  if (code === "EBUSY" || code === "EPERM") return true;
@@ -44704,6 +44791,7 @@ async function runDaemonUpgradeHelper(payload) {
44704
44791
  }
44705
44792
  await stopSessionHostProcesses(sessionHostAppName);
44706
44793
  removeDaemonPidFile();
44794
+ await stopForeignNativeAddonHolders(installCommand.surface.packageRoot, { parentPid: payload.parentPid });
44707
44795
  cleanupStaleGlobalInstallDirs(payload.packageName, installCommand.surface);
44708
44796
  const spec = `${payload.packageName}@${payload.targetVersion || "latest"}`;
44709
44797
  appendUpgradeLog(`Installing ${spec}`);
@@ -44725,11 +44813,30 @@ async function runDaemonUpgradeHelper(payload) {
44725
44813
  break;
44726
44814
  } catch (error) {
44727
44815
  if (attempt < maxInstallAttempts && isRetriableInstallLockError(error)) {
44728
- appendUpgradeLog(`Install attempt ${attempt} hit a file lock (${error?.code || "lock"}); cleaning staging and retrying after backoff`);
44816
+ appendUpgradeLog(`Install attempt ${attempt} hit a file lock (${error?.code || "lock"}); clearing holders + staging and retrying after backoff`);
44817
+ await stopForeignNativeAddonHolders(installCommand.surface.packageRoot, { parentPid: payload.parentPid });
44729
44818
  cleanupStaleGlobalInstallDirs(payload.packageName, installCommand.surface);
44730
44819
  await new Promise((resolve24) => setTimeout(resolve24, attempt * 1500));
44731
44820
  continue;
44732
44821
  }
44822
+ if (isRetriableInstallLockError(error)) {
44823
+ const blockers = listForeignNativeAddonHolders(installCommand.surface.packageRoot);
44824
+ const notice = [
44825
+ `adhdev ${spec} could not be installed: a file lock (${error?.code || "EBUSY/EPERM"}) is blocking the native addon.`
44826
+ ];
44827
+ if (blockers.length > 0) {
44828
+ notice.push("Processes still holding the lock:");
44829
+ for (const b of blockers) {
44830
+ notice.push(` pid ${b.pid}${b.commandLine ? ` \u2014 ${b.commandLine}` : ""}`);
44831
+ }
44832
+ notice.push("To recover, stop them and reinstall:");
44833
+ notice.push(` Stop-Process -Id ${blockers.map((b) => b.pid).join(",")} -Force`);
44834
+ } else {
44835
+ notice.push("To recover, reinstall manually:");
44836
+ }
44837
+ notice.push(` ${buildManualRecoveryCommand(installCommand)}`);
44838
+ emitUpgradeFailureNotice(notice);
44839
+ }
44733
44840
  throw error;
44734
44841
  }
44735
44842
  }
@@ -47396,7 +47503,7 @@ var DaemonCommandRouter = class {
47396
47503
  return sanitizedInlineMesh;
47397
47504
  }
47398
47505
  async getMeshForCommand(meshId, inlineMesh, options) {
47399
- const preferInline = options?.preferInline === true;
47506
+ const preferInline = options?.preferInline !== false;
47400
47507
  if (preferInline) {
47401
47508
  const cached4 = this.getCachedInlineMesh(meshId);
47402
47509
  if (cached4) {
@@ -51755,7 +51862,7 @@ ${ptyResult.output.slice(-2e3)}`);
51755
51862
  workspace
51756
51863
  };
51757
51864
  }
51758
- const { existsSync: existsSync46, readFileSync: readFileSync37, writeFileSync: writeFileSync23, copyFileSync: copyFileSync4, mkdirSync: mkdirSync21 } = await import("fs");
51865
+ const { existsSync: existsSync46, readFileSync: readFileSync37, writeFileSync: writeFileSync24, copyFileSync: copyFileSync4, mkdirSync: mkdirSync21 } = await import("fs");
51759
51866
  const { dirname: dirname17 } = await import("path");
51760
51867
  const mcpConfigPath = coordinatorSetup.configPath;
51761
51868
  const hermesManualFallback = cliType === "hermes-cli" && configFormat === "hermes_config_yaml" ? createHermesManualMeshCoordinatorSetup(meshId, workspace) : null;
@@ -51828,7 +51935,7 @@ ${ptyResult.output.slice(-2e3)}`);
51828
51935
  }
51829
51936
  };
51830
51937
  try {
51831
- writeFileSync23(mcpConfigPath, serializeMeshCoordinatorMcpConfig(mcpConfig, configFormat), "utf-8");
51938
+ writeFileSync24(mcpConfigPath, serializeMeshCoordinatorMcpConfig(mcpConfig, configFormat), "utf-8");
51832
51939
  } catch (error) {
51833
51940
  const message = `Could not write MCP config for automatic setup: ${error?.message || error}`;
51834
51941
  LOG.error("MeshCoordinator", message);