@adhdev/daemon-standalone 0.9.77-rc.25 → 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.25",
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": {
@@ -57466,6 +57466,42 @@ 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
+ 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
+ }
57469
57505
  function resolveCoordinatorNode(ctx) {
57470
57506
  const preferredNodeId = typeof ctx.mesh.coordinator?.preferredNodeId === "string" ? ctx.mesh.coordinator.preferredNodeId.trim() : "";
57471
57507
  if (preferredNodeId) {
@@ -57898,6 +57934,19 @@ async function meshEnqueueTask(ctx, args) {
57898
57934
  if (isLocalTransport(ctx.transport)) {
57899
57935
  ctx.transport.command("trigger_mesh_queue", { meshId: ctx.mesh.id }).catch(() => {
57900
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
+ }
57901
57950
  }
57902
57951
  return JSON.stringify({ success: true, taskId: task.id, status: task.status });
57903
57952
  } catch (e) {
@@ -57926,12 +57975,29 @@ async function meshSendTask(ctx, args) {
57926
57975
  });
57927
57976
  return JSON.stringify(res);
57928
57977
  }
57929
- const task = enqueueTask(ctx.mesh.id, args.message, { targetNodeId: args.node_id });
57930
57978
  const isLocalNode = ctx.localMachineId && node.machineId === ctx.localMachineId || ctx.localDaemonId && node.daemonId === ctx.localDaemonId;
57931
57979
  if (ctx.transport instanceof IpcTransport && node.daemonId && !isLocalNode) {
57932
- 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
57933
57985
  });
57934
- } 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)) {
57935
58001
  ctx.transport.command("trigger_mesh_queue", { meshId: ctx.mesh.id }).catch(() => {
57936
58002
  });
57937
58003
  }