@adhdev/daemon-core 0.9.77-rc.21 → 0.9.77-rc.22

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.
@@ -8,17 +8,12 @@ export interface PendingMeshCoordinatorEvent {
8
8
  }
9
9
  /** Drain and return all pending coordinator events, clearing the queue. */
10
10
  export declare function drainPendingMeshCoordinatorEvents(): PendingMeshCoordinatorEvent[];
11
- export declare function tryAssignQueueTask(components: {
12
- cliManager: any;
13
- }, meshId: string, nodeId: string, sessionId: string, providerType: string): boolean;
11
+ export declare function tryAssignQueueTask(components: DaemonComponents, meshId: string, nodeId: string, sessionId: string, providerType: string): boolean;
14
12
  /**
15
13
  * Triggers a queue check for all nodes in the mesh.
16
14
  * Called when a new task is enqueued, in case nodes are already idle.
17
15
  */
18
- export declare function triggerMeshQueue(components: {
19
- instanceManager: any;
20
- cliManager: any;
21
- }, meshId: string): void;
16
+ export declare function triggerMeshQueue(components: DaemonComponents, meshId: string): void;
22
17
  export declare function handleMeshForwardEvent(components: DaemonComponents, payload: Record<string, unknown>): {
23
18
  success: boolean;
24
19
  forwarded: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adhdev/daemon-core",
3
- "version": "0.9.77-rc.21",
3
+ "version": "0.9.77-rc.22",
4
4
  "description": "ADHDev daemon core — CDP, IDE detection, providers, command execution",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -83,6 +83,9 @@ export interface DaemonInitConfig {
83
83
 
84
84
  /** Fired before send_chat is dispatched — used for turn snapshot hooks */
85
85
  onBeforeSendChat?: (params: { workspace: string; sessionId: string }) => void;
86
+
87
+ /** Relays a command to a remote mesh node daemon */
88
+ dispatchMeshCommand?: (daemonId: string, command: string, args: Record<string, unknown>) => Promise<any>;
86
89
  }
87
90
 
88
91
  // ─── Result ───
@@ -100,6 +103,7 @@ export interface DaemonComponents {
100
103
  sessionRegistry: SessionRegistry;
101
104
  detectedIdes: { value: IDEInfo[] };
102
105
  refreshProviderAvailability: (providerType?: string) => Promise<void>;
106
+ dispatchMeshCommand?: (daemonId: string, command: string, args: Record<string, unknown>) => Promise<any>;
103
107
  }
104
108
 
105
109
  export interface DaemonDevSupportOptions {
@@ -331,6 +335,7 @@ export async function initDaemonComponents(config: DaemonInitConfig): Promise<Da
331
335
  sessionRegistry,
332
336
  detectedIdes: detectedIdesRef,
333
337
  refreshProviderAvailability,
338
+ dispatchMeshCommand: config.dispatchMeshCommand,
334
339
  };
335
340
 
336
341
  // 11. Setup Mesh Event Forwarding
@@ -3,7 +3,7 @@ import { getMesh, getMeshByRepo } from '../config/mesh-config.js';
3
3
  import { LOG } from '../logging/logger.js';
4
4
  import { appendLedgerEntry, getSessionRecoveryContext } from './mesh-ledger.js';
5
5
  import type { MeshLedgerKind, SessionRecoveryContext } from './mesh-ledger.js';
6
- import { claimNextTask, updateSessionTaskStatus, enqueueTask } from './mesh-work-queue.js';
6
+ import { claimNextTask, updateSessionTaskStatus, enqueueTask, updateTaskStatus } from './mesh-work-queue.js';
7
7
 
8
8
  // ---------------------------------------------------------------------------
9
9
  // MCP coordinator pending-event queue
@@ -62,7 +62,7 @@ function formatCompletionMetadata(event: Record<string, unknown>): string {
62
62
  }
63
63
 
64
64
  export function tryAssignQueueTask(
65
- components: { cliManager: any },
65
+ components: DaemonComponents,
66
66
  meshId: string,
67
67
  nodeId: string,
68
68
  sessionId: string,
@@ -74,14 +74,37 @@ export function tryAssignQueueTask(
74
74
  }
75
75
 
76
76
  LOG.info('MeshQueue', `Node ${nodeId} (${sessionId}) pulled task ${task.id}`);
77
+
78
+ // Check if the node is remote
79
+ const mesh = getMesh(meshId);
80
+ const node = mesh?.nodes.find((n: any) => n.id === nodeId);
77
81
 
82
+ // If the node is explicitly remote and we have a dispatch mechanism, route via P2P
83
+ if (node?.daemonId && components.dispatchMeshCommand) {
84
+ const isLocalNode = components.cliManager.adapters.has(sessionId);
85
+ if (!isLocalNode) {
86
+ components.dispatchMeshCommand(node.daemonId, 'agent_command', {
87
+ targetSessionId: sessionId,
88
+ cliType: providerType,
89
+ action: 'send_chat',
90
+ message: task.message,
91
+ }).catch((e: any) => {
92
+ LOG.error('MeshQueue', `Failed to dispatch task via P2P to remote node ${nodeId}: ${e?.message}`);
93
+ updateTaskStatus(meshId, task.id, 'failed');
94
+ });
95
+ return true;
96
+ }
97
+ }
98
+
99
+ // Local routing
78
100
  components.cliManager.handleCliCommand('agent_command', {
79
101
  targetSessionId: sessionId,
80
102
  cliType: providerType,
81
103
  action: 'send_chat',
82
104
  message: task.message,
83
105
  }).catch((e: any) => {
84
- LOG.error('MeshQueue', `Failed to dispatch task to node ${nodeId}: ${e?.message}`);
106
+ LOG.error('MeshQueue', `Failed to dispatch task locally to node ${nodeId}: ${e?.message}`);
107
+ updateTaskStatus(meshId, task.id, 'failed');
85
108
  });
86
109
 
87
110
  return true;
@@ -91,7 +114,7 @@ export function tryAssignQueueTask(
91
114
  * Triggers a queue check for all nodes in the mesh.
92
115
  * Called when a new task is enqueued, in case nodes are already idle.
93
116
  */
94
- export function triggerMeshQueue(components: { instanceManager: any; cliManager: any }, meshId: string) {
117
+ export function triggerMeshQueue(components: DaemonComponents, meshId: string) {
95
118
  const mesh = getMesh(meshId);
96
119
  if (!mesh) return;
97
120