@adhdev/daemon-core 0.9.82-rc.140 → 0.9.82-rc.142

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.82-rc.140",
3
+ "version": "0.9.82-rc.142",
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",
@@ -7,7 +7,7 @@ import { detectCLI } from '../detection/cli-detector.js';
7
7
  import { LOG } from '../logging/logger.js';
8
8
  import { appendLedgerEntry, buildTaskCompletionEvidence, getLedgerDir, getSessionRecoveryContext, isIntentionalCleanupStopEntry, readLedgerEntries } from './mesh-ledger.js';
9
9
  import type { MeshLedgerKind, SessionRecoveryContext } from './mesh-ledger.js';
10
- import { claimNextTask, updateSessionTaskStatus, enqueueTask, updateTaskStatus, getQueue, recordTaskAutoLaunch, updateDirectDispatchStatus, cleanupTerminalDirectDispatches } from './mesh-work-queue.js';
10
+ import { claimNextTask, updateSessionTaskStatus, enqueueTask, updateTaskStatus, getQueue, recordTaskAutoLaunch, updateDirectDispatchStatus, cleanupTerminalDirectDispatches, getActiveDirectDispatches } from './mesh-work-queue.js';
11
11
  import { BeadsDB } from './beads-db.js';
12
12
 
13
13
  // ---------------------------------------------------------------------------
@@ -1615,14 +1615,30 @@ export function setupMeshEventForwarding(components: DaemonComponents) {
1615
1615
  if (!workspace) return;
1616
1616
  const settings = state.settings && typeof state.settings === 'object' ? state.settings as Record<string, unknown> : {};
1617
1617
 
1618
- // Coordinator sessions must never inject events into themselves.
1619
- // A coordinator instance carries meshCoordinatorFor but not meshNodeFor/launchedByCoordinator.
1620
- if (readNonEmptyString(settings.meshCoordinatorFor)) return;
1618
+ // Coordinator sessions normally must not inject events into themselves, but a
1619
+ // coordinator session can also be the direct-dispatch target of mesh_send_task
1620
+ // issued by another coordinator (e.g. a remote orchestrator delegated a task to
1621
+ // this local coordinator). In that case the completion event must still flow into
1622
+ // injectMeshSystemMessage so the ledger records task_completed and the *other*
1623
+ // coordinator's pendingCoordinatorEvents queue is populated. Skip only when this
1624
+ // session is purely a coordinator with no in-flight direct dispatch waiting on it.
1625
+ const coordinatorMeshId = readNonEmptyString(settings.meshCoordinatorFor);
1626
+ let meshIdFromDirectDispatch = '';
1627
+ if (coordinatorMeshId) {
1628
+ try {
1629
+ const activeDispatches = getActiveDirectDispatches(coordinatorMeshId);
1630
+ if (activeDispatches.some(d => d.sessionId === instanceId)) {
1631
+ meshIdFromDirectDispatch = coordinatorMeshId;
1632
+ }
1633
+ } catch { /* best-effort */ }
1634
+ if (!meshIdFromDirectDispatch) return;
1635
+ }
1621
1636
 
1622
- const meshIdFromRuntime = readNonEmptyString(settings.meshNodeFor);
1637
+ const meshIdFromRuntime = readNonEmptyString(settings.meshNodeFor) || meshIdFromDirectDispatch;
1623
1638
 
1624
1639
  // Only forward events for sessions that were explicitly launched as mesh-node delegates
1625
- // (meshNodeFor set by mesh_launch_session) or that carry the launchedByCoordinator flag.
1640
+ // (meshNodeFor set by mesh_launch_session), carry the launchedByCoordinator flag, or
1641
+ // have an active direct-dispatch entry (mesh_send_task to a pre-existing session).
1626
1642
  // Do NOT fall back to workspace-based mesh lookup: that would pick up coordinator sessions
1627
1643
  // and any other CLI session that happens to share the same workspace, causing spurious
1628
1644
  // system-message injection into the coordinator's own conversation.