@adhdev/daemon-standalone 0.9.77-rc.24 → 0.9.77-rc.26

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adhdev/daemon-standalone",
3
- "version": "0.9.77-rc.24",
3
+ "version": "0.9.77-rc.26",
4
4
  "description": "ADHDev standalone daemon — embedded HTTP/WS server for local dashboard",
5
5
  "main": "dist/index.js",
6
6
  "bin": {
@@ -26256,13 +26256,18 @@ function formatCompletionMetadata(event) {
26256
26256
  ].filter(Boolean);
26257
26257
  return parts.length > 0 ? ` (${parts.join("; ")})` : "";
26258
26258
  }
26259
+ function getMeshWithCache(components, meshId) {
26260
+ const localMesh = getMesh(meshId);
26261
+ if (localMesh) return localMesh;
26262
+ return components.router?.getCachedInlineMesh(meshId);
26263
+ }
26259
26264
  function tryAssignQueueTask(components, meshId, nodeId, sessionId, providerType) {
26260
26265
  const task = claimNextTask(meshId, nodeId, sessionId);
26261
26266
  if (!task) {
26262
26267
  return false;
26263
26268
  }
26264
26269
  LOG.info("MeshQueue", `Node ${nodeId} (${sessionId}) pulled task ${task.id}`);
26265
- const mesh = getMesh(meshId);
26270
+ const mesh = getMeshWithCache(components, meshId);
26266
26271
  const node = mesh?.nodes.find((n) => n.id === nodeId);
26267
26272
  if (node?.daemonId && components.dispatchMeshCommand) {
26268
26273
  const isLocalNode = components.cliManager.adapters.has(sessionId);
@@ -26291,7 +26296,7 @@ function tryAssignQueueTask(components, meshId, nodeId, sessionId, providerType)
26291
26296
  return true;
26292
26297
  }
26293
26298
  function triggerMeshQueue(components, meshId) {
26294
- const mesh = getMesh(meshId);
26299
+ const mesh = getMeshWithCache(components, meshId);
26295
26300
  if (!mesh) return;
26296
26301
  const cliInstances = components.instanceManager.getByCategory("cli");
26297
26302
  for (const inst of cliInstances) {
@@ -26549,7 +26554,7 @@ function setupMeshEventForwarding(components) {
26549
26554
  const meshIdFromRuntime = readNonEmptyString(settings.meshNodeFor);
26550
26555
  const isMeshDelegate = Boolean(meshIdFromRuntime || settings.launchedByCoordinator);
26551
26556
  if (!isMeshDelegate) return;
26552
- const mesh = meshIdFromRuntime ? getMesh(meshIdFromRuntime) : getMeshByRepo(workspace);
26557
+ const mesh = meshIdFromRuntime ? getMeshWithCache(components, meshIdFromRuntime) : getMeshByRepo(workspace);
26553
26558
  const meshId = meshIdFromRuntime || readNonEmptyString(mesh?.id);
26554
26559
  if (!meshId) return;
26555
26560
  const targetNode = mesh?.nodes?.find((n) => n.workspace === workspace);
@@ -57461,6 +57466,42 @@ function extractGitDiff(value) {
57461
57466
  function extractLaunchPayload(value) {
57462
57467
  return findNestedPayload(value, (payload) => Boolean(payload?.sessionId || payload?.id || payload?.runtimeSessionId));
57463
57468
  }
57469
+ async function ipcDispatchToRemoteAgent(ctx, node, args) {
57470
+ const transport = ctx.transport;
57471
+ const daemonId = node.daemonId;
57472
+ let sessionId = args.session_id?.trim() || "";
57473
+ let resolvedProviderType = args.providerType?.trim() || "";
57474
+ if (!sessionId) {
57475
+ try {
57476
+ const sessionsResult = await transport.meshCommand(daemonId, "get_cli_sessions", {});
57477
+ const payload = unwrapCommandPayload(sessionsResult);
57478
+ const sessions = Array.isArray(payload?.sessions) ? payload.sessions : Array.isArray(sessionsResult?.sessions) ? sessionsResult.sessions : [];
57479
+ const meshSessions = sessions.filter(
57480
+ (s) => s?.settings?.meshNodeFor === ctx.mesh.id || s?.settings?.meshNodeId === node.id || s?.settings?.launchedByCoordinator === true
57481
+ );
57482
+ const targetSession = meshSessions[0] || sessions[0];
57483
+ if (targetSession?.sessionId || targetSession?.id) {
57484
+ sessionId = targetSession.sessionId || targetSession.id;
57485
+ if (!resolvedProviderType) resolvedProviderType = targetSession.providerType || targetSession.cliType || "";
57486
+ }
57487
+ } catch {
57488
+ }
57489
+ }
57490
+ if (!sessionId) {
57491
+ return { success: false, error: `No active session found on remote node '${node.id}'. Use mesh_launch_session first.` };
57492
+ }
57493
+ try {
57494
+ await transport.meshCommand(daemonId, "agent_command", {
57495
+ targetSessionId: sessionId,
57496
+ cliType: resolvedProviderType,
57497
+ action: "send_chat",
57498
+ message: args.message
57499
+ });
57500
+ return { success: true, dispatched: true, sessionId };
57501
+ } catch (e) {
57502
+ return { success: false, error: `P2P dispatch failed: ${e?.message || String(e)}` };
57503
+ }
57504
+ }
57464
57505
  function resolveCoordinatorNode(ctx) {
57465
57506
  const preferredNodeId = typeof ctx.mesh.coordinator?.preferredNodeId === "string" ? ctx.mesh.coordinator.preferredNodeId.trim() : "";
57466
57507
  if (preferredNodeId) {
@@ -57893,6 +57934,19 @@ async function meshEnqueueTask(ctx, args) {
57893
57934
  if (isLocalTransport(ctx.transport)) {
57894
57935
  ctx.transport.command("trigger_mesh_queue", { meshId: ctx.mesh.id }).catch(() => {
57895
57936
  });
57937
+ if (ctx.transport instanceof IpcTransport) {
57938
+ for (const node of ctx.mesh.nodes) {
57939
+ const isLocalNode = ctx.localMachineId && node.machineId === ctx.localMachineId || ctx.localDaemonId && node.daemonId === ctx.localDaemonId;
57940
+ if (!isLocalNode && node.daemonId) {
57941
+ ctx.transport.meshCommand(
57942
+ node.daemonId,
57943
+ "trigger_mesh_queue",
57944
+ { meshId: ctx.mesh.id }
57945
+ ).catch(() => {
57946
+ });
57947
+ }
57948
+ }
57949
+ }
57896
57950
  }
57897
57951
  return JSON.stringify({ success: true, taskId: task.id, status: task.status });
57898
57952
  } catch (e) {
@@ -57921,12 +57975,29 @@ async function meshSendTask(ctx, args) {
57921
57975
  });
57922
57976
  return JSON.stringify(res);
57923
57977
  }
57924
- const task = enqueueTask(ctx.mesh.id, args.message, { targetNodeId: args.node_id });
57925
57978
  const isLocalNode = ctx.localMachineId && node.machineId === ctx.localMachineId || ctx.localDaemonId && node.daemonId === ctx.localDaemonId;
57926
57979
  if (ctx.transport instanceof IpcTransport && node.daemonId && !isLocalNode) {
57927
- ctx.transport.meshCommand(node.daemonId, "trigger_mesh_queue", { meshId: ctx.mesh.id }).catch(() => {
57980
+ const cached2 = meshSessionProviderMetadata.get(meshSessionCacheKey(args.node_id, args.session_id || ""));
57981
+ const result = await ipcDispatchToRemoteAgent(ctx, node, {
57982
+ session_id: args.session_id,
57983
+ message: args.message,
57984
+ providerType: cached2?.providerType
57928
57985
  });
57929
- } else if (isLocalTransport(ctx.transport)) {
57986
+ if (result.success) {
57987
+ try {
57988
+ appendLedgerEntry(ctx.mesh.id, {
57989
+ kind: "task_dispatched",
57990
+ nodeId: args.node_id,
57991
+ sessionId: result.sessionId,
57992
+ payload: { message: args.message, via: "p2p_direct" }
57993
+ });
57994
+ } catch {
57995
+ }
57996
+ }
57997
+ return JSON.stringify({ ...result, nodeId: args.node_id });
57998
+ }
57999
+ const task = enqueueTask(ctx.mesh.id, args.message, { targetNodeId: args.node_id });
58000
+ if (isLocalTransport(ctx.transport)) {
57930
58001
  ctx.transport.command("trigger_mesh_queue", { meshId: ctx.mesh.id }).catch(() => {
57931
58002
  });
57932
58003
  }