@adhdev/daemon-standalone 0.9.77-rc.25 → 0.9.77-rc.27

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.25",
3
+ "version": "0.9.77-rc.27",
4
4
  "description": "ADHDev standalone daemon — embedded HTTP/WS server for local dashboard",
5
5
  "main": "dist/index.js",
6
6
  "bin": {
@@ -57466,6 +57466,49 @@ function extractGitDiff(value) {
57466
57466
  function extractLaunchPayload(value) {
57467
57467
  return findNestedPayload(value, (payload) => Boolean(payload?.sessionId || payload?.id || payload?.runtimeSessionId));
57468
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
+ const providerPriorityList = Array.isArray(node.policy?.providerPriority) ? node.policy.providerPriority : [];
57474
+ let resolvedProviderType = args.providerType?.trim() || providerPriorityList[0] || "";
57475
+ if (!sessionId) {
57476
+ try {
57477
+ const statusResult = await transport.meshCommand(daemonId, "get_status_metadata", {});
57478
+ const payload = unwrapCommandPayload(statusResult);
57479
+ const sessions = Array.isArray(payload?.sessions) ? payload.sessions : Array.isArray(payload?.status?.sessions) ? payload.status.sessions : [];
57480
+ const meshSessions = sessions.filter(
57481
+ (s) => s?.settings?.meshNodeFor === ctx.mesh.id || s?.settings?.meshNodeId === node.id || s?.settings?.launchedByCoordinator === true
57482
+ );
57483
+ const targetSession = meshSessions[0] || sessions.find(
57484
+ (s) => !resolvedProviderType || s?.providerType === resolvedProviderType || s?.cliType === resolvedProviderType
57485
+ ) || sessions[0];
57486
+ if (targetSession?.id || targetSession?.sessionId) {
57487
+ sessionId = targetSession.id || targetSession.sessionId;
57488
+ if (!resolvedProviderType) {
57489
+ resolvedProviderType = targetSession.providerType || targetSession.cliType || "";
57490
+ }
57491
+ }
57492
+ } catch {
57493
+ }
57494
+ }
57495
+ if (!resolvedProviderType) {
57496
+ return { success: false, error: `Cannot dispatch to remote node '${node.id}': providerType unknown. Set providerPriority on the node policy or call mesh_launch_session first.` };
57497
+ }
57498
+ try {
57499
+ await transport.meshCommand(daemonId, "agent_command", {
57500
+ // Precise match when sessionId known, fuzzy type match otherwise
57501
+ ...sessionId ? { targetSessionId: sessionId } : {},
57502
+ agentType: resolvedProviderType,
57503
+ cliType: resolvedProviderType,
57504
+ action: "send_chat",
57505
+ message: args.message
57506
+ });
57507
+ return { success: true, dispatched: true, sessionId: sessionId || resolvedProviderType };
57508
+ } catch (e) {
57509
+ return { success: false, error: `P2P dispatch failed: ${e?.message || String(e)}` };
57510
+ }
57511
+ }
57469
57512
  function resolveCoordinatorNode(ctx) {
57470
57513
  const preferredNodeId = typeof ctx.mesh.coordinator?.preferredNodeId === "string" ? ctx.mesh.coordinator.preferredNodeId.trim() : "";
57471
57514
  if (preferredNodeId) {
@@ -57898,6 +57941,19 @@ async function meshEnqueueTask(ctx, args) {
57898
57941
  if (isLocalTransport(ctx.transport)) {
57899
57942
  ctx.transport.command("trigger_mesh_queue", { meshId: ctx.mesh.id }).catch(() => {
57900
57943
  });
57944
+ if (ctx.transport instanceof IpcTransport) {
57945
+ for (const node of ctx.mesh.nodes) {
57946
+ const isLocalNode = ctx.localMachineId && node.machineId === ctx.localMachineId || ctx.localDaemonId && node.daemonId === ctx.localDaemonId;
57947
+ if (!isLocalNode && node.daemonId) {
57948
+ ctx.transport.meshCommand(
57949
+ node.daemonId,
57950
+ "trigger_mesh_queue",
57951
+ { meshId: ctx.mesh.id }
57952
+ ).catch(() => {
57953
+ });
57954
+ }
57955
+ }
57956
+ }
57901
57957
  }
57902
57958
  return JSON.stringify({ success: true, taskId: task.id, status: task.status });
57903
57959
  } catch (e) {
@@ -57926,12 +57982,29 @@ async function meshSendTask(ctx, args) {
57926
57982
  });
57927
57983
  return JSON.stringify(res);
57928
57984
  }
57929
- const task = enqueueTask(ctx.mesh.id, args.message, { targetNodeId: args.node_id });
57930
57985
  const isLocalNode = ctx.localMachineId && node.machineId === ctx.localMachineId || ctx.localDaemonId && node.daemonId === ctx.localDaemonId;
57931
57986
  if (ctx.transport instanceof IpcTransport && node.daemonId && !isLocalNode) {
57932
- ctx.transport.meshCommand(node.daemonId, "trigger_mesh_queue", { meshId: ctx.mesh.id }).catch(() => {
57987
+ const cached2 = meshSessionProviderMetadata.get(meshSessionCacheKey(args.node_id, args.session_id || ""));
57988
+ const result = await ipcDispatchToRemoteAgent(ctx, node, {
57989
+ session_id: args.session_id,
57990
+ message: args.message,
57991
+ providerType: cached2?.providerType
57933
57992
  });
57934
- } else if (isLocalTransport(ctx.transport)) {
57993
+ if (result.success) {
57994
+ try {
57995
+ appendLedgerEntry(ctx.mesh.id, {
57996
+ kind: "task_dispatched",
57997
+ nodeId: args.node_id,
57998
+ sessionId: result.sessionId,
57999
+ payload: { message: args.message, via: "p2p_direct" }
58000
+ });
58001
+ } catch {
58002
+ }
58003
+ }
58004
+ return JSON.stringify({ ...result, nodeId: args.node_id });
58005
+ }
58006
+ const task = enqueueTask(ctx.mesh.id, args.message, { targetNodeId: args.node_id });
58007
+ if (isLocalTransport(ctx.transport)) {
57935
58008
  ctx.transport.command("trigger_mesh_queue", { meshId: ctx.mesh.id }).catch(() => {
57936
58009
  });
57937
58010
  }