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

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-core",
3
- "version": "0.9.77-rc.22",
3
+ "version": "0.9.77-rc.23",
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",
@@ -5,6 +5,19 @@ import { appendLedgerEntry, getSessionRecoveryContext } from './mesh-ledger.js';
5
5
  import type { MeshLedgerKind, SessionRecoveryContext } from './mesh-ledger.js';
6
6
  import { claimNextTask, updateSessionTaskStatus, enqueueTask, updateTaskStatus } from './mesh-work-queue.js';
7
7
 
8
+ // ---------------------------------------------------------------------------
9
+ // Remote Node Idle Session Tracking
10
+ // ---------------------------------------------------------------------------
11
+ // Tracks remote sessions that emitted 'agent:ready' so triggerMeshQueue
12
+ // can assign tasks to them.
13
+ // ---------------------------------------------------------------------------
14
+ interface RemoteIdleSession {
15
+ nodeId: string;
16
+ sessionId: string;
17
+ providerType: string;
18
+ }
19
+ const remoteIdleSessions = new Map<string, RemoteIdleSession>(); // key: `${nodeId}:${sessionId}`
20
+
8
21
  // ---------------------------------------------------------------------------
9
22
  // MCP coordinator pending-event queue
10
23
  // ---------------------------------------------------------------------------
@@ -141,6 +154,18 @@ export function triggerMeshQueue(components: DaemonComponents, meshId: string) {
141
154
  tryAssignQueueTask(components, meshId, nodeId, sessionId, providerType);
142
155
  }
143
156
  }
157
+
158
+ // Also check known idle remote sessions
159
+ for (const [key, idle] of remoteIdleSessions.entries()) {
160
+ // Find if this node is in the same mesh
161
+ const node = mesh.nodes.find((n: any) => n.id === idle.nodeId);
162
+ if (node) {
163
+ const assigned = tryAssignQueueTask(components, meshId, idle.nodeId, idle.sessionId, idle.providerType);
164
+ if (assigned) {
165
+ remoteIdleSessions.delete(key);
166
+ }
167
+ }
168
+ }
144
169
  }
145
170
 
146
171
  function buildMeshSystemMessage(args: {
@@ -216,12 +241,26 @@ function injectMeshSystemMessage(components: DaemonComponents, args: {
216
241
  const providerType = readNonEmptyString(args.metadataEvent.providerType);
217
242
 
218
243
  if (sessionId && nodeId && providerType) {
244
+ remoteIdleSessions.set(`${nodeId}:${sessionId}`, { nodeId, sessionId, providerType });
219
245
  setTimeout(() => {
220
- tryAssignQueueTask(components, args.meshId, nodeId, sessionId, providerType);
246
+ const assigned = tryAssignQueueTask(components, args.meshId, nodeId, sessionId, providerType);
247
+ if (assigned) {
248
+ remoteIdleSessions.delete(`${nodeId}:${sessionId}`);
249
+ }
221
250
  }, 500);
222
251
  }
252
+ } else if (args.event === 'agent:generating_started') {
253
+ const sessionId = readNonEmptyString(args.metadataEvent.targetSessionId);
254
+ const nodeId = readNonEmptyString(args.nodeId) || readNonEmptyString(args.metadataEvent.meshNodeId);
255
+ if (sessionId && nodeId) {
256
+ remoteIdleSessions.delete(`${nodeId}:${sessionId}`);
257
+ }
223
258
  } else if (args.event === 'agent:stopped') {
224
259
  const sessionId = readNonEmptyString(args.metadataEvent.targetSessionId);
260
+ const nodeId = readNonEmptyString(args.nodeId) || readNonEmptyString(args.metadataEvent.meshNodeId);
261
+ if (sessionId && nodeId) {
262
+ remoteIdleSessions.delete(`${nodeId}:${sessionId}`);
263
+ }
225
264
  if (sessionId) {
226
265
  updateSessionTaskStatus(args.meshId, sessionId, 'failed');
227
266
  }