@adhdev/daemon-core 0.9.82-rc.296 → 0.9.82-rc.298

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.296",
3
+ "version": "0.9.82-rc.298",
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",
@@ -46,7 +46,7 @@
46
46
  "author": "vilmire",
47
47
  "license": "AGPL-3.0-or-later",
48
48
  "dependencies": {
49
- "@adhdev/mesh-shared": "0.9.82-rc.296",
49
+ "@adhdev/mesh-shared": "0.9.82-rc.298",
50
50
  "@adhdev/session-host-core": "*",
51
51
  "@agentclientprotocol/sdk": "^0.16.1",
52
52
  "ajv": "^8.20.0",
@@ -15,7 +15,7 @@ import type { PendingMeshCoordinatorEvent } from './mesh-events-pending.js';
15
15
  import { resolveWorkerDelegateRouting, recordUnroutableDelegateEvent, isUnroutableDelegateRejection } from './mesh-routing.js';
16
16
  import { enqueueUnresolvedDelegateForward, peekUnresolvedDelegateForwards, ackUnresolvedDelegateForward } from './mesh-unresolved-forward-outbox.js';
17
17
  import { resolveDelegatedWorkerAutoApprove } from '../repo-mesh-types.js';
18
- import { normalizeMeshNodeId, meshNodeIdMatches } from '@adhdev/mesh-shared';
18
+ import { normalizeMeshNodeId, meshNodeIdMatches, type MeshNodeIdentified } from '@adhdev/mesh-shared';
19
19
  import {
20
20
  findRecentTerminalLedgerEvidence,
21
21
  hasDispatchAfterTerminal,
@@ -109,7 +109,10 @@ function hasRecentIntentionalCleanupStop(meshId: string, sessionId?: string, nod
109
109
  if (!Number.isNaN(timestamp) && timestamp < cutoff) break;
110
110
  if (!isIntentionalCleanupStopEntry(entry)) continue;
111
111
  if (sessionId && entry.sessionId === sessionId) return true;
112
- if (!sessionId && nodeId && entry.nodeId === nodeId) return true;
112
+ // Normalized node-id match (P4): the cleanup-stop entry's node id may be stored as
113
+ // `nodeId` or `node_id` and the `nodeId` arg can be in either form — a raw `===`
114
+ // would miss a genuine intentional-cleanup entry and fail to suppress the stop event.
115
+ if (!sessionId && nodeId && meshNodeIdMatches(entry as unknown as MeshNodeIdentified, nodeId)) return true;
113
116
  }
114
117
  return false;
115
118
  }
@@ -4,6 +4,7 @@ import { updateDirectDispatchStatus, cleanupTerminalDirectDispatches } from './m
4
4
  import { markSessionDeliveriesTerminal } from './mesh-delivery-policy.js';
5
5
  import { queuePendingMeshCoordinatorEvent } from './mesh-events-pending.js';
6
6
  import { readNonEmptyString, readRecord, resolveEventSessionId, readWorkerResultMetadata } from './mesh-events-utils.js';
7
+ import { meshNodeIdMatches, type MeshNodeIdentified } from '@adhdev/mesh-shared';
7
8
 
8
9
  // ---------------------------------------------------------------------------
9
10
  // Stale direct-dispatch detection & transcript reconciliation
@@ -25,7 +26,13 @@ export function findRecentTerminalLedgerEvidence(args: {
25
26
  if (args.sessionId && entry.sessionId === args.sessionId) {
26
27
  return { id: entry.id, kind: entry.kind, payload: entry.payload || {}, timestamp: entry.timestamp };
27
28
  }
28
- if (!args.sessionId && args.nodeId && entry.nodeId === args.nodeId) {
29
+ // Normalized node-id match (P4): a ledger entry may store its node id as `nodeId`
30
+ // (runtime form) or `node_id` (DB column form leaked onto the object). A raw `===`
31
+ // against args.nodeId drops the entry when the entry's stored form differs from the
32
+ // form the caller passes, so a valid terminal completion goes unfound. meshNodeIdMatches
33
+ // normalizes the entry across all 3 forms before comparing. (The entry's typed shape
34
+ // omits the open index signature MeshNodeIdentified declares, hence the cast.)
35
+ if (!args.sessionId && args.nodeId && meshNodeIdMatches(entry as unknown as MeshNodeIdentified, args.nodeId)) {
29
36
  return { id: entry.id, kind: entry.kind, payload: entry.payload || {}, timestamp: entry.timestamp };
30
37
  }
31
38
  }
@@ -4,6 +4,7 @@ import { hasUnterminalDirectDispatchLedgerEntry } from './mesh-events-stale.js';
4
4
  import { appendLedgerEntry, readLedgerEntries } from './mesh-ledger.js';
5
5
  import { LOG } from '../logging/logger.js';
6
6
  import { readNonEmptyString } from './mesh-events-utils.js';
7
+ import { meshNodeIdMatches } from '@adhdev/mesh-shared';
7
8
 
8
9
  // ---------------------------------------------------------------------------
9
10
  // R1: single-source coordinator routing resolution
@@ -141,13 +142,28 @@ export function resolveWorkerDelegateRouting(
141
142
  const meshId = meshIdFromRuntime || readNonEmptyString(mesh?.id);
142
143
  if (!meshId) return reject('mesh_unresolved');
143
144
 
144
- const targetNode = mesh?.nodes?.find((n: any) => n.workspace === workspace);
145
- const nodeId = readNonEmptyString(targetNode?.id) || runtimeNodeId;
146
- const nodeLabel = targetNode
147
- ? `Node '${targetNode.id}'`
148
- : runtimeNodeId
149
- ? `Node '${runtimeNodeId}'`
150
- : `Agent at ${workspace}`;
145
+ // Node resolution authority: the runtime stamp (meshNodeId) is the worker's
146
+ // own identity, set when the coordinator dispatched/launched it. Trust it FIRST,
147
+ // matched against mesh.nodes with the 3-form normalizer (id / nodeId / node_id).
148
+ // Workspace lookup is only a fallback for workers that never carried a node stamp.
149
+ //
150
+ // This is the P1 fix: a worktree clone and its base node can share the same
151
+ // `workspace`, or a freshly-cloned node may not yet be in mesh.nodes — in either
152
+ // case `.find(n => n.workspace === workspace)` would match the BASE node (or
153
+ // undefined) and stamp the completion event with the wrong/absent nodeId, so the
154
+ // event fails post-hoc node matching and the coordinator never sees the completion.
155
+ // The stamped meshNodeId splits base vs worktree correctly even on shared workspace.
156
+ const stampedNode = runtimeNodeId
157
+ ? mesh?.nodes?.find((n: any) => meshNodeIdMatches(n, runtimeNodeId))
158
+ : undefined;
159
+ const targetNode = stampedNode || mesh?.nodes?.find((n: any) => n.workspace === workspace);
160
+ const nodeId = runtimeNodeId || readNonEmptyString(targetNode?.id);
161
+ // Label off the resolved nodeId (which now prefers the stamp) so a node matched
162
+ // by its `nodeId`/`node_id` form — where `targetNode.id` may be absent — never
163
+ // renders as `Node 'undefined'`.
164
+ const nodeLabel = nodeId
165
+ ? `Node '${nodeId}'`
166
+ : `Agent at ${workspace}`;
151
167
 
152
168
  return {
153
169
  isDelegate: true,
@@ -433,12 +433,21 @@ export function buildClaudeInteractiveTuiAnswerSteps(
433
433
  const treatAsMultiSelect = question.multiSelect || answer.selectedLabels.length > 1;
434
434
 
435
435
  if (treatAsMultiSelect) {
436
- // Multi-select: Claude TUI renders each option as a checkbox and the
437
- // footer reads "Space to select". A numeric digit jumps the cursor to
438
- // that option; Space toggles its checkbox. So for every selected label
439
- // emit `[digit, ' ']` to land on it and toggle it on. After toggling all
440
- // boxes for this question, Enter advances to the next question (or to the
441
- // final confirm screen for the last question).
436
+ // Multi-select: Claude TUI renders each option as a checkbox. The
437
+ // keystroke model here was reverse-engineered live against claude-cli
438
+ // v2.1.170 (do not "simplify" from the screen text it lies):
439
+ //
440
+ // * A numeric digit key TOGGLES that option's checkbox directly and
441
+ // does NOT move the cursor. So a digit alone checks the option.
442
+ // * Space toggles whatever row the cursor is sitting on (the digit
443
+ // never moved it), so a trailing Space would spuriously toggle the
444
+ // cursor's row (usually option 1) — NEVER pair digit+Space here.
445
+ // * Enter does NOT advance the page; it toggles the cursor's row too.
446
+ // The ONLY key that commits this question and advances (to the next
447
+ // question, or to the final "Review your answers" screen for the
448
+ // last question) is Tab.
449
+ //
450
+ // So: one digit per selected label, then a single Tab to advance.
442
451
  const labels = answer.selectedLabels;
443
452
  if (labels.length === 0) {
444
453
  throw new Error(`Expected at least one selected label for ${question.questionId}`);
@@ -447,12 +456,11 @@ export function buildClaudeInteractiveTuiAnswerSteps(
447
456
  const selectedIndex = question.options.findIndex(option => option.label === label);
448
457
  if (selectedIndex < 0) throw new Error(`Unknown option for ${question.questionId}: ${label}`);
449
458
  steps.push(String(selectedIndex + 1));
450
- steps.push(' ');
451
459
  }
452
- // Confirm this question's checked set and move on. Unlike single-select
453
- // (where the digit auto-advances), multi-select stays on the page until an
454
- // explicit Enter so the user can toggle multiple boxes.
455
- steps.push('\r');
460
+ // Tab commits this question's checked set and advances. (Unlike
461
+ // single-select, where the digit auto-advances, a multi-select page
462
+ // stays put under digit input so the user can toggle multiple boxes.)
463
+ steps.push('\t');
456
464
  } else if (freeformText) {
457
465
  // Freeform: select the "Type something." option (always the last visible
458
466
  // option before "Chat about this"), then type the text and confirm.