@adhdev/daemon-core 0.9.82-rc.286 → 0.9.82-rc.288

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -275,10 +275,10 @@ function readInjected(value) {
275
275
  }
276
276
  function getDaemonBuildInfo() {
277
277
  if (cached) return cached;
278
- const commit = readInjected(true ? "ff6934b27530406c46b2c1835f9f3708f8fa4aba" : void 0) ?? "unknown";
279
- const commitShort = readInjected(true ? "ff6934b2" : void 0) ?? (commit !== "unknown" ? commit.slice(0, 7) : "unknown");
280
- const version = readInjected(true ? "0.9.82-rc.286" : void 0) ?? readInjected(typeof process !== "undefined" ? process.env?.ADHDEV_PKG_VERSION : void 0) ?? "unknown";
281
- const builtAt = readInjected(true ? "2026-06-16T00:50:00.386Z" : void 0);
278
+ const commit = readInjected(true ? "b17916645417b641feddfdaa6e5b249aea09f12a" : void 0) ?? "unknown";
279
+ const commitShort = readInjected(true ? "b1791664" : void 0) ?? (commit !== "unknown" ? commit.slice(0, 7) : "unknown");
280
+ const version = readInjected(true ? "0.9.82-rc.288" : void 0) ?? readInjected(typeof process !== "undefined" ? process.env?.ADHDEV_PKG_VERSION : void 0) ?? "unknown";
281
+ const builtAt = readInjected(true ? "2026-06-16T03:12:06.987Z" : void 0);
282
282
  cached = builtAt ? { commit, commitShort, version, builtAt } : { commit, commitShort, version };
283
283
  return cached;
284
284
  }
@@ -7263,10 +7263,11 @@ function resolveWorkerDelegateRouting(components, instanceId, deps) {
7263
7263
  const sessionId = readNonEmptyString2(instanceId);
7264
7264
  let workspace = "";
7265
7265
  let coordinatorDaemonId = "";
7266
+ let runtimeNodeId = "";
7266
7267
  const reject = (rejectionReason) => ({
7267
7268
  isDelegate: false,
7268
7269
  meshId: "",
7269
- nodeId: "",
7270
+ nodeId: runtimeNodeId,
7270
7271
  nodeLabel: "",
7271
7272
  coordinatorDaemonId,
7272
7273
  workspace,
@@ -7280,6 +7281,7 @@ function resolveWorkerDelegateRouting(components, instanceId, deps) {
7280
7281
  if (!workspace) return reject("no_workspace");
7281
7282
  const settings = readSettings(state);
7282
7283
  coordinatorDaemonId = readNonEmptyString2(settings.meshCoordinatorDaemonId);
7284
+ runtimeNodeId = readNonEmptyString2(settings.meshNodeId);
7283
7285
  const coordinatorMeshId = readNonEmptyString2(settings.meshCoordinatorFor);
7284
7286
  let meshIdFromDirectDispatch = "";
7285
7287
  if (coordinatorMeshId) {
@@ -7300,7 +7302,6 @@ function resolveWorkerDelegateRouting(components, instanceId, deps) {
7300
7302
  const meshId = meshIdFromRuntime || readNonEmptyString2(mesh?.id);
7301
7303
  if (!meshId) return reject("mesh_unresolved");
7302
7304
  const targetNode = mesh?.nodes?.find((n) => n.workspace === workspace);
7303
- const runtimeNodeId = readNonEmptyString2(settings.meshNodeId);
7304
7305
  const nodeId = readNonEmptyString2(targetNode?.id) || runtimeNodeId;
7305
7306
  const nodeLabel = targetNode ? `Node '${targetNode.id}'` : runtimeNodeId ? `Node '${runtimeNodeId}'` : `Agent at ${workspace}`;
7306
7307
  return {
@@ -8466,10 +8467,10 @@ function handleMeshForwardEvent(components, payload) {
8466
8467
  if (!isMeshCoordinatorEvent(eventName)) {
8467
8468
  return { success: false, error: "unsupported mesh event" };
8468
8469
  }
8469
- const meshId = readNonEmptyString2(payload.meshId);
8470
- if (!meshId) return { success: false, error: "meshId required" };
8471
8470
  const nodeId = readNonEmptyString2(payload.nodeId);
8472
8471
  const workspace = readNonEmptyString2(payload.workspace);
8472
+ const meshId = readNonEmptyString2(payload.meshId) || (workspace ? readNonEmptyString2(getCachedMeshByWorkspace(workspace)?.id) : "");
8473
+ if (!meshId) return { success: false, error: "meshId required" };
8473
8474
  const nodeLabel = nodeId ? `Node '${nodeId}'` : workspace ? `Agent at ${workspace}` : "Remote agent";
8474
8475
  const relayModalMessage = readNonEmptyString2(payload.modalMessage);
8475
8476
  const relayModalButtons = Array.isArray(payload.modalButtons) ? payload.modalButtons.filter((b) => typeof b === "string" && b.trim().length > 0) : null;
@@ -8508,6 +8509,24 @@ function handleMeshForwardEvent(components, payload) {
8508
8509
  }
8509
8510
  });
8510
8511
  }
8512
+ function forwardUnresolvedDelegateEvent(components, routing, event) {
8513
+ const coordinatorDaemonId = readNonEmptyString2(routing.coordinatorDaemonId);
8514
+ if (!coordinatorDaemonId) return false;
8515
+ if (!components.dispatchMeshCommand) return false;
8516
+ const eventName = readNonEmptyString2(event.event);
8517
+ if (!eventName) return false;
8518
+ const payload = {
8519
+ ...event,
8520
+ event: eventName,
8521
+ nodeId: readNonEmptyString2(routing.nodeId) || readNonEmptyString2(event.meshNodeId) || void 0,
8522
+ workspace: readNonEmptyString2(routing.workspace) || readNonEmptyString2(event.workspace) || void 0
8523
+ };
8524
+ Promise.resolve(components.dispatchMeshCommand(coordinatorDaemonId, "mesh_forward_event", payload)).catch((e) => {
8525
+ LOG.warn("MeshEvents", `Fallback forward of ${eventName} to coordinator ${coordinatorDaemonId} failed: ${e?.message || e}`);
8526
+ });
8527
+ LOG.info("MeshEvents", `Fallback-forwarded ${eventName} for unresolved-mesh worker at ${routing.workspace || "(no workspace)"} to coordinator daemon ${coordinatorDaemonId}`);
8528
+ return true;
8529
+ }
8511
8530
  function setupMeshEventForwarding(components) {
8512
8531
  components.instanceManager.onEvent((event) => {
8513
8532
  if (event.event === "agent:ready" || event.event === "agent:generating_completed") {
@@ -8557,6 +8576,9 @@ function setupMeshEventForwarding(components) {
8557
8576
  getMeshByWorkspace: (workspace) => getCachedMeshByWorkspace(workspace)
8558
8577
  });
8559
8578
  if (!routing.isDelegate) {
8579
+ if (isUnroutableDelegateRejection(routing) && forwardUnresolvedDelegateEvent(components, routing, event)) {
8580
+ return;
8581
+ }
8560
8582
  recordUnroutableDelegateEvent(routing, event.event);
8561
8583
  return;
8562
8584
  }
@@ -8655,6 +8677,20 @@ function daemonHostsMesh(mesh, daemonIds) {
8655
8677
  if (!hostDaemonId) return true;
8656
8678
  return daemonIds.includes(hostDaemonId);
8657
8679
  }
8680
+ function resolveCoordinatorSelfIds(mesh, drainDaemonIds) {
8681
+ const ids = new Set(drainDaemonIds);
8682
+ for (const node of mesh.nodes) {
8683
+ const nodeDaemonId = readNonEmptyString2(node.daemonId);
8684
+ const nodeMachineId = readNonEmptyString2(node.machineId);
8685
+ const isSelf = nodeDaemonId && drainDaemonIds.includes(nodeDaemonId) || nodeMachineId && drainDaemonIds.includes(nodeMachineId);
8686
+ if (!isSelf) continue;
8687
+ if (nodeDaemonId) ids.add(nodeDaemonId);
8688
+ if (nodeMachineId) ids.add(nodeMachineId);
8689
+ }
8690
+ const hostDaemonId = readNonEmptyString2(mesh.meshHost?.hostDaemonId);
8691
+ if (hostDaemonId && ids.has(hostDaemonId)) ids.add(hostDaemonId);
8692
+ return [...ids];
8693
+ }
8658
8694
  function findLiveCoordinators(components) {
8659
8695
  const out = [];
8660
8696
  for (const inst of components.instanceManager.getByCategory("cli")) {
@@ -8688,9 +8724,10 @@ async function runMeshReconcileTick(components) {
8688
8724
  })();
8689
8725
  if (dispatchMeshCommand) {
8690
8726
  for (const mesh of listMeshes()) {
8691
- if (!daemonHostsMesh(mesh, drainDaemonIds)) continue;
8727
+ const selfIds = resolveCoordinatorSelfIds(mesh, drainDaemonIds);
8728
+ if (!daemonHostsMesh(mesh, selfIds)) continue;
8692
8729
  try {
8693
- await pullRemoteNodeQueues(components, mesh, localDaemonId, drainDaemonIds);
8730
+ await pullRemoteNodeQueues(components, mesh, localDaemonId, selfIds);
8694
8731
  } catch (e) {
8695
8732
  LOG.warn("MeshReconcile", `Remote node pull failed for mesh ${mesh.id}: ${e?.message || e}`);
8696
8733
  }
@@ -8738,15 +8775,16 @@ async function runMeshReconcileTick(components) {
8738
8775
  }
8739
8776
  }
8740
8777
  }
8741
- async function pullRemoteNodeQueues(components, mesh, localDaemonId, drainDaemonIds) {
8778
+ async function pullRemoteNodeQueues(components, mesh, localDaemonId, candidateDaemonIds) {
8742
8779
  const dispatchMeshCommand = components.dispatchMeshCommand;
8743
8780
  if (!dispatchMeshCommand) return;
8744
8781
  const meshId = mesh.id;
8745
- const pulls = drainDaemonIds.length > 0 ? drainDaemonIds.map((id) => ({ meshId, coordinatorDaemonId: id })) : [{ meshId }];
8782
+ const pulls = candidateDaemonIds.length > 0 ? candidateDaemonIds.map((id) => ({ meshId, coordinatorDaemonId: id })) : [{ meshId }];
8746
8783
  for (const node of mesh.nodes) {
8747
8784
  const nodeDaemonId = readNonEmptyString2(node.daemonId);
8748
8785
  if (!nodeDaemonId) continue;
8749
8786
  if (localDaemonId && nodeDaemonId === localDaemonId) continue;
8787
+ if (candidateDaemonIds.includes(nodeDaemonId)) continue;
8750
8788
  for (const pendingEventArgs of pulls) {
8751
8789
  let events;
8752
8790
  try {