@adhdev/daemon-core 0.9.82-rc.366 → 0.9.82-rc.368

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/dist/index.mjs CHANGED
@@ -311,10 +311,10 @@ function readInjected(value) {
311
311
  }
312
312
  function getDaemonBuildInfo() {
313
313
  if (cached) return cached;
314
- const commit = readInjected(true ? "c2224ab0c9d05e85b4cbf88e4fc696f3733ec397" : void 0) ?? "unknown";
315
- const commitShort = readInjected(true ? "c2224ab0" : void 0) ?? (commit !== "unknown" ? commit.slice(0, 7) : "unknown");
316
- const version = readInjected(true ? "0.9.82-rc.366" : void 0) ?? readInjected(typeof process !== "undefined" ? process.env?.ADHDEV_PKG_VERSION : void 0) ?? "unknown";
317
- const builtAt = readInjected(true ? "2026-06-24T02:22:36.214Z" : void 0);
314
+ const commit = readInjected(true ? "8cb6cfc5399f55c6b625095bacc9a27e1741df17" : void 0) ?? "unknown";
315
+ const commitShort = readInjected(true ? "8cb6cfc5" : void 0) ?? (commit !== "unknown" ? commit.slice(0, 7) : "unknown");
316
+ const version = readInjected(true ? "0.9.82-rc.368" : void 0) ?? readInjected(typeof process !== "undefined" ? process.env?.ADHDEV_PKG_VERSION : void 0) ?? "unknown";
317
+ const builtAt = readInjected(true ? "2026-06-24T06:14:32.255Z" : void 0);
318
318
  cached = builtAt ? { commit, commitShort, version, builtAt } : { commit, commitShort, version };
319
319
  return cached;
320
320
  }
@@ -2897,6 +2897,16 @@ function meshNodeIdMatches(node, candidateId) {
2897
2897
  if (!trimmed) return false;
2898
2898
  return normalizeMeshNodeId(node) === trimmed;
2899
2899
  }
2900
+ function normalizeMeshWorkspaceForCompare(dir) {
2901
+ if (typeof dir !== "string") return "";
2902
+ return dir.trim().replace(/[\\/]+/g, "/").replace(/\/+$/, "").toLowerCase();
2903
+ }
2904
+ function meshWorkspacesEquivalent(a, b) {
2905
+ const left = normalizeMeshWorkspaceForCompare(a);
2906
+ const right = normalizeMeshWorkspaceForCompare(b);
2907
+ if (!left || !right) return false;
2908
+ return left === right;
2909
+ }
2900
2910
  function machineCoreFromDaemonId(id) {
2901
2911
  const trimmed = readString3(id);
2902
2912
  if (!trimmed) return void 0;
@@ -12852,21 +12862,29 @@ function deliverTaskToSession(dispatchThunk, ctx) {
12852
12862
  }
12853
12863
  });
12854
12864
  }
12855
- function normalizeMeshWorkspaceForCompare(dir) {
12856
- if (typeof dir !== "string") return "";
12857
- return dir.trim().replace(/[\\/]+/g, "/").replace(/\/+$/, "").toLowerCase();
12858
- }
12859
12865
  function tryAssignQueueTask(components, meshId, nodeId, sessionId, providerType) {
12860
12866
  const mesh = getMeshWithCache(components, meshId);
12861
12867
  const node = mesh?.nodes.find((n) => readMeshNodeId(n) === nodeId);
12862
12868
  const localClaimAdapter = components.cliManager?.adapters?.get(sessionId);
12863
- if (localClaimAdapter) {
12864
- const sessionWorkspace = normalizeMeshWorkspaceForCompare(localClaimAdapter.workingDir);
12865
- const nodeWorkspace = normalizeMeshWorkspaceForCompare(readNonEmptyString2(node?.workspace));
12866
- if (sessionWorkspace && nodeWorkspace && sessionWorkspace !== nodeWorkspace) {
12867
- LOG.info("MeshQueue", `WTCLAIM: refusing claim for node ${nodeId} (${sessionId}) \u2014 session workspace "${sessionWorkspace}" \u2260 node workspace "${nodeWorkspace}" (cross-workspace dispatch blocked)`);
12869
+ let claimInstanceWorkspace = "";
12870
+ let claimStampedNodeId = "";
12871
+ try {
12872
+ const claimState = components.instanceManager?.getInstance?.(sessionId)?.getState?.();
12873
+ claimInstanceWorkspace = readNonEmptyString2(claimState?.workspace);
12874
+ const claimSettings = claimState?.settings || {};
12875
+ claimStampedNodeId = readNonEmptyString2(claimSettings.meshNodeId);
12876
+ } catch {
12877
+ }
12878
+ const nodeWorkspaceRaw = readNonEmptyString2(node?.workspace);
12879
+ const sessionWorkspaceRaw = readNonEmptyString2(localClaimAdapter?.workingDir) || claimInstanceWorkspace;
12880
+ if (claimStampedNodeId && nodeId) {
12881
+ if (!meshNodeIdMatches({ id: claimStampedNodeId }, nodeId)) {
12882
+ LOG.info("MeshQueue", `WTDISPATCH: refusing claim for node ${nodeId} (${sessionId}) \u2014 session is bound to node "${claimStampedNodeId}" (cross-node claim blocked)`);
12868
12883
  return false;
12869
12884
  }
12885
+ } else if (sessionWorkspaceRaw && nodeWorkspaceRaw && !meshWorkspacesEquivalent(sessionWorkspaceRaw, nodeWorkspaceRaw)) {
12886
+ LOG.info("MeshQueue", `WTCLAIM: refusing claim for node ${nodeId} (${sessionId}) \u2014 session workspace "${normalizeMeshWorkspaceForCompare(sessionWorkspaceRaw)}" \u2260 node workspace "${normalizeMeshWorkspaceForCompare(nodeWorkspaceRaw)}" (cross-workspace dispatch blocked)`);
12887
+ return false;
12870
12888
  }
12871
12889
  const capabilityTags = buildMeshNodeCapabilityTags(node, providerType);
12872
12890
  const providerMaxParallel = resolveProviderMaxParallel(node?.policy, providerType);
@@ -13707,7 +13725,10 @@ function injectMeshSystemMessage(components, args) {
13707
13725
  if (terminal?.kind === "task_completed" && !sessionHasActiveAssignment(args.meshId, eventSessionId)) {
13708
13726
  const newDispatchAfterTerminal = hasDispatchAfterTerminal(args.meshId, eventSessionId, terminal.id);
13709
13727
  const supersedesWeakTerminal = isWeakTerminalLedgerPayload(terminal.payload) && isGenuineCompletionEvidence(args.metadataEvent);
13710
- if (!newDispatchAfterTerminal && !supersedesWeakTerminal) {
13728
+ const terminalTaskId = readNonEmptyString2(terminal.payload.taskId);
13729
+ const eventTaskId = readNonEmptyString2(args.metadataEvent.taskId);
13730
+ const distinctTaskCompletion = !!eventTaskId && !!terminalTaskId && eventTaskId !== terminalTaskId;
13731
+ if (!newDispatchAfterTerminal && !supersedesWeakTerminal && !distinctTaskCompletion) {
13711
13732
  const terminalProviderSessionId = readNonEmptyString2(terminal.payload.providerSessionId);
13712
13733
  const terminalFinalSummary = readNonEmptyString2(terminal.payload.finalSummary);
13713
13734
  const eventProviderSessionId = readNonEmptyString2(args.metadataEvent.providerSessionId);
@@ -14141,6 +14162,25 @@ function handleMeshForwardEvent(components, payload) {
14141
14162
  metadataEvent: buildRelayMetadataEvent(payload)
14142
14163
  });
14143
14164
  }
14165
+ function enqueueCoordinatorForwardPush(coordinatorDaemonId, run) {
14166
+ let lane = coordinatorForwardLanes.get(coordinatorDaemonId);
14167
+ if (!lane) {
14168
+ lane = { tail: Promise.resolve(), depth: 0 };
14169
+ coordinatorForwardLanes.set(coordinatorDaemonId, lane);
14170
+ }
14171
+ const wasIdle = lane.depth === 0;
14172
+ lane.depth += 1;
14173
+ const dec = () => {
14174
+ lane.depth -= 1;
14175
+ };
14176
+ if (wasIdle) {
14177
+ lane.tail = Promise.resolve(run()).catch(() => {
14178
+ }).then(dec, dec);
14179
+ } else {
14180
+ lane.tail = lane.tail.then(() => run()).catch(() => {
14181
+ }).then(dec, dec);
14182
+ }
14183
+ }
14144
14184
  function forwardUnresolvedDelegateEvent(components, routing, event) {
14145
14185
  const coordinatorDaemonId = readNonEmptyString2(routing.coordinatorDaemonId);
14146
14186
  if (!coordinatorDaemonId) return false;
@@ -14153,6 +14193,16 @@ function forwardUnresolvedDelegateEvent(components, routing, event) {
14153
14193
  nodeId: readNonEmptyString2(routing.nodeId) || readNonEmptyString2(event.meshNodeId) || void 0,
14154
14194
  workspace: readNonEmptyString2(routing.workspace) || readNonEmptyString2(event.workspace) || void 0
14155
14195
  };
14196
+ const selfDaemonIds = resolveCoordinatorDrainDaemonIds(components);
14197
+ if (selfDaemonIds.some((self) => daemonIdsEquivalent(self, coordinatorDaemonId))) {
14198
+ try {
14199
+ handleMeshForwardEvent(components, payload);
14200
+ LOG.info("MeshEvents", `Self-addressed unresolved-delegate ${eventName} routed via local router (coordinator ${coordinatorDaemonId} is self) \u2014 outbox skipped`);
14201
+ } catch (e) {
14202
+ LOG.warn("MeshEvents", `Local route of self-addressed unresolved-delegate ${eventName} failed: ${e?.message || e}`);
14203
+ }
14204
+ return true;
14205
+ }
14156
14206
  const persisted = enqueueUnresolvedDelegateForward(coordinatorDaemonId, eventName, payload);
14157
14207
  const fwdTraceCtx = {
14158
14208
  taskId: payload.taskId,
@@ -14162,7 +14212,8 @@ function forwardUnresolvedDelegateEvent(components, routing, event) {
14162
14212
  };
14163
14213
  traceMeshEventStage("outbox_enqueue", fwdTraceCtx, `coordinatorDaemon=${coordinatorDaemonId} meshId=absent`);
14164
14214
  traceMeshEventStage("forward_send", fwdTraceCtx, "immediate push");
14165
- Promise.resolve(components.dispatchMeshCommand(coordinatorDaemonId, "mesh_forward_event", payload)).then((result) => {
14215
+ const dispatchMeshCommand = components.dispatchMeshCommand;
14216
+ enqueueCoordinatorForwardPush(coordinatorDaemonId, () => Promise.resolve(dispatchMeshCommand(coordinatorDaemonId, "mesh_forward_event", payload)).then((result) => {
14166
14217
  if (result && result.success === false) {
14167
14218
  LOG.warn("MeshEvents", `Immediate forward of ${eventName} to coordinator ${coordinatorDaemonId} rejected (${readNonEmptyString2(result.error) || "no reason"}) \u2014 left queued for retry`);
14168
14219
  traceMeshEventDrop("immediate_forward_rejected", fwdTraceCtx, readNonEmptyString2(result.error) || "no reason");
@@ -14171,7 +14222,7 @@ function forwardUnresolvedDelegateEvent(components, routing, event) {
14171
14222
  if (persisted) ackUnresolvedDelegateForwardByFingerprint(coordinatorDaemonId, eventName, payload);
14172
14223
  }).catch((e) => {
14173
14224
  LOG.warn("MeshEvents", `Immediate forward of ${eventName} to coordinator ${coordinatorDaemonId} failed: ${e?.message || e} \u2014 left queued for retry`);
14174
- });
14225
+ }));
14175
14226
  LOG.info("MeshEvents", `Durably forwarded ${eventName} for unresolved-mesh worker at ${routing.workspace || "(no workspace)"} to coordinator daemon ${coordinatorDaemonId}`);
14176
14227
  return true;
14177
14228
  }
@@ -14254,7 +14305,7 @@ function setupMeshEventForwarding(components) {
14254
14305
  });
14255
14306
  });
14256
14307
  }
14257
- var REMOTE_IDLE_SESSION_TTL_MS, meshByWorkspaceCache, MESH_WORKSPACE_CACHE_TTL_MS, IDLE_AUTO_FAST_FORWARD_THROTTLE_MS, idleAutoFastForwardLastAttempt, INTENTIONAL_CLEANUP_STOP_SUPPRESSION_MS, RECENT_COMPLETION_FINGERPRINT_TTL_MS, DISPATCH_CONFIRM_TIMEOUT_MS, autoLaunchInProgress, autoLaunchCooldownUntil, AUTO_LAUNCH_COOLDOWN_MS, AUTO_LAUNCH_AWAIT_CLAIM_MS, lastAutoLaunchLedgerKey, AUTO_LAUNCH_LEDGER_DEDUP_MAX, MESH_COORDINATOR_EVENTS, EVENT_TO_LEDGER_KIND, MESH_FORCE_INJECT_EVENTS;
14308
+ var REMOTE_IDLE_SESSION_TTL_MS, meshByWorkspaceCache, MESH_WORKSPACE_CACHE_TTL_MS, IDLE_AUTO_FAST_FORWARD_THROTTLE_MS, idleAutoFastForwardLastAttempt, INTENTIONAL_CLEANUP_STOP_SUPPRESSION_MS, RECENT_COMPLETION_FINGERPRINT_TTL_MS, DISPATCH_CONFIRM_TIMEOUT_MS, autoLaunchInProgress, autoLaunchCooldownUntil, AUTO_LAUNCH_COOLDOWN_MS, AUTO_LAUNCH_AWAIT_CLAIM_MS, lastAutoLaunchLedgerKey, AUTO_LAUNCH_LEDGER_DEDUP_MAX, MESH_COORDINATOR_EVENTS, EVENT_TO_LEDGER_KIND, MESH_FORCE_INJECT_EVENTS, coordinatorForwardLanes;
14258
14309
  var init_mesh_events_coordinator = __esm({
14259
14310
  "src/mesh/mesh-events-coordinator.ts"() {
14260
14311
  "use strict";
@@ -14318,6 +14369,7 @@ var init_mesh_events_coordinator = __esm({
14318
14369
  "worktree_bootstrap_complete",
14319
14370
  "worktree_bootstrap_failed"
14320
14371
  ]);
14372
+ coordinatorForwardLanes = /* @__PURE__ */ new Map();
14321
14373
  }
14322
14374
  });
14323
14375
 
@@ -14660,6 +14712,8 @@ async function retryUnresolvedDelegateForwards(components) {
14660
14712
  expireStaleUnresolvedDelegateForwards();
14661
14713
  const entries = peekUnresolvedDelegateForwards();
14662
14714
  if (entries.length === 0) return;
14715
+ const selfIds = resolveCoordinatorDaemonIds(components);
14716
+ const isSelfCoordinatorId = (id) => selfIds.some((self) => daemonIdsEquivalent(self, id));
14663
14717
  for (const entry of entries) {
14664
14718
  const entryTraceCtx = {
14665
14719
  taskId: entry.payload.taskId,
@@ -14667,6 +14721,23 @@ async function retryUnresolvedDelegateForwards(components) {
14667
14721
  nodeId: readNonEmptyString2(entry.payload.nodeId),
14668
14722
  event: readNonEmptyString2(entry.payload.event)
14669
14723
  };
14724
+ if (isSelfCoordinatorId(entry.coordinatorDaemonId)) {
14725
+ let localResult;
14726
+ try {
14727
+ traceMeshEventStage("forward_send", entryTraceCtx, `self \u2192 local router (${entry.coordinatorDaemonId})`);
14728
+ localResult = handleMeshForwardEvent(components, entry.payload);
14729
+ } catch (e) {
14730
+ LOG.warn("MeshReconcile", `Local route of self-addressed forward to ${entry.coordinatorDaemonId} threw: ${e?.message || e} \u2014 draining anyway to break the retry loop`);
14731
+ }
14732
+ ackUnresolvedDelegateForward(entry.id);
14733
+ if (localResult && localResult.success === false) {
14734
+ LOG.warn("MeshReconcile", `Self-addressed unresolved-delegate ${readNonEmptyString2(entry.payload.event)} rejected by local router (${readNonEmptyString2(localResult.error) || "no reason"}) \u2014 drained to break the self-forward retry loop`);
14735
+ traceMeshEventDrop("self_forward_local_rejected", entryTraceCtx, readNonEmptyString2(localResult.error) || "no reason");
14736
+ } else {
14737
+ LOG.info("MeshReconcile", `Self-addressed unresolved-delegate ${readNonEmptyString2(entry.payload.event)} routed via local router (coordinator ${entry.coordinatorDaemonId} is self) \u2014 drained`);
14738
+ }
14739
+ continue;
14740
+ }
14670
14741
  let result;
14671
14742
  try {
14672
14743
  traceMeshEventStage("forward_send", entryTraceCtx, `retry \u2192 ${entry.coordinatorDaemonId}`);
@@ -27858,6 +27929,7 @@ var CHAT_SOURCE_REGISTRY = new ChatSourceRegistry();
27858
27929
 
27859
27930
  // src/commands/chat-commands.ts
27860
27931
  init_chat_message_normalization();
27932
+ init_dist();
27861
27933
  var RECENT_SEND_WINDOW_MS = 1200;
27862
27934
  var READ_CHAT_PROVIDER_EVAL_TIMEOUT_MS = 25e3;
27863
27935
  var HOT_TAIL_MIN_LIMIT = 60;
@@ -28419,6 +28491,24 @@ function normalizeComparableWorkspace(value) {
28419
28491
  if (!text) return "";
28420
28492
  return path16.resolve(text);
28421
28493
  }
28494
+ function evaluateReadChatNodeWorkspaceScope(args) {
28495
+ const targetSessionId = typeof args.targetSessionId === "string" ? args.targetSessionId.trim() : "";
28496
+ if (!targetSessionId) return { scoped: false };
28497
+ const intended = normalizeMeshWorkspaceForCompare(args.intendedWorkspace);
28498
+ const actual = normalizeMeshWorkspaceForCompare(args.sessionWorkspace);
28499
+ if (!intended || !actual) return { scoped: false };
28500
+ if (intended === actual) return { scoped: false };
28501
+ return { scoped: true, intended, actual };
28502
+ }
28503
+ function resolveTargetSessionActualWorkspace(h, targetSessionId) {
28504
+ const registryWorkspace = h.ctx?.sessionRegistry?.get?.(targetSessionId)?.workspace;
28505
+ if (typeof registryWorkspace === "string" && registryWorkspace.trim()) return registryWorkspace;
28506
+ const adapter = h.getCliAdapter?.(targetSessionId);
28507
+ if (adapter && typeof adapter.workingDir === "string" && adapter.workingDir.trim()) return adapter.workingDir;
28508
+ const instanceWorkspace = getTargetInstance(h, { targetSessionId })?.getState?.()?.workspace;
28509
+ if (typeof instanceWorkspace === "string" && instanceWorkspace.trim()) return instanceWorkspace;
28510
+ return "";
28511
+ }
28422
28512
  function isCurrentRuntimePtySafelyAttributed(args) {
28423
28513
  if (args.adapter.cliType !== "codex-cli") return false;
28424
28514
  if (!Array.isArray(args.ptyMessages) || args.ptyMessages.length === 0) return false;
@@ -29233,6 +29323,24 @@ async function handleChatHistory(h, args) {
29233
29323
  }
29234
29324
  }
29235
29325
  async function handleReadChat(h, args) {
29326
+ {
29327
+ const guardSessionId = typeof args?.targetSessionId === "string" ? args.targetSessionId.trim() : "";
29328
+ if (guardSessionId && typeof args?.workspace === "string" && args.workspace.trim()) {
29329
+ const verdict = evaluateReadChatNodeWorkspaceScope({
29330
+ targetSessionId: guardSessionId,
29331
+ intendedWorkspace: args.workspace,
29332
+ sessionWorkspace: resolveTargetSessionActualWorkspace(h, guardSessionId)
29333
+ });
29334
+ if (verdict.scoped) {
29335
+ LOG.info("Command", `[read_chat] node scope mismatch: session ${guardSessionId} workspace "${verdict.actual}" \u2260 requested node workspace "${verdict.intended}" \u2014 refusing cross-worktree transcript`);
29336
+ return {
29337
+ success: false,
29338
+ code: "read_chat_session_node_scope_mismatch",
29339
+ error: `Session ${guardSessionId} belongs to a different worktree (workspace "${verdict.actual}") than the requested node (workspace "${verdict.intended}"). Refusing to return a cross-worktree transcript \u2014 target the node that owns this session.`
29340
+ };
29341
+ }
29342
+ }
29343
+ }
29236
29344
  let providerHint = args?.agentType || args?.providerType;
29237
29345
  if (!providerHint) {
29238
29346
  const targetSessionId = typeof args?.targetSessionId === "string" ? args.targetSessionId.trim() : "";
@@ -29621,10 +29729,19 @@ async function handleReadChat(h, args) {
29621
29729
  ptyStatusApprovalOnly: false
29622
29730
  });
29623
29731
  if (supportsNative && !decision.nativeSelected) {
29732
+ LOG.debug("Command", `[read_chat] soft pending: no live adapter and native history not safely mappable target=${String(args?.targetSessionId || "")} provider=${agentStr} reason=native_history_not_safely_available`);
29624
29733
  return {
29625
- success: false,
29734
+ success: true,
29735
+ pending: true,
29736
+ // Both signals are true here: we reached the history-only path
29737
+ // because no live adapter was found (`live_adapter_not_found`),
29738
+ // and native history is not safely mappable
29739
+ // (`native_history_not_safely_available`).
29740
+ reason: "native_history_not_safely_available",
29741
+ reasons: ["live_adapter_not_found", "native_history_not_safely_available"],
29626
29742
  code: "native_history_not_safely_available",
29627
- error: "Provider-native history was not safely available for the requested CLI session.",
29743
+ messages: [],
29744
+ status: "idle",
29628
29745
  providerSessionId: historyProviderSessionId,
29629
29746
  messageSource: decision.messageSource,
29630
29747
  transcriptProvenance: decision.messageSource
@@ -41089,6 +41206,18 @@ var DaemonCliManager = class {
41089
41206
  throw new Error(`Failed to start ${provider.displayName || provider.name || cliType}: ${spawnErr?.message}`);
41090
41207
  }
41091
41208
  this.adapters.set(key, cliInstance.getAdapter());
41209
+ const launchMeshNodeId = typeof settings?.meshNodeId === "string" ? settings.meshNodeId.trim() : "";
41210
+ const launchMeshNodeFor = typeof settings?.meshNodeFor === "string" ? settings.meshNodeFor.trim() : "";
41211
+ if (launchMeshNodeId || launchMeshNodeFor) {
41212
+ try {
41213
+ cliInstance.getAdapter().updateRuntimeMeta?.({
41214
+ ...launchMeshNodeId ? { meshNodeId: launchMeshNodeId } : {},
41215
+ ...launchMeshNodeFor ? { meshNodeFor: launchMeshNodeFor } : {},
41216
+ ...settings?.launchedByCoordinator === true ? { launchedByCoordinator: true } : {}
41217
+ });
41218
+ } catch {
41219
+ }
41220
+ }
41092
41221
  this.startCliExitMonitor(key, cliType);
41093
41222
  }
41094
41223
  // ─── Session start/management ──────────────────────────────
@@ -49129,6 +49258,7 @@ function readMeshTimeoutEnvMs(name, defaultMs) {
49129
49258
  }
49130
49259
  var MESH_DIRECT_PROBE_TIMEOUT_MS = readMeshTimeoutEnvMs("MESH_DIRECT_PROBE_TIMEOUT_MS", 25e3);
49131
49260
  var MESH_DIRECT_PROBE_RETRY_TIMEOUT_MS = readMeshTimeoutEnvMs("MESH_DIRECT_PROBE_RETRY_TIMEOUT_MS", 25e3);
49261
+ var MESH_DIRECT_PROBE_CONNECT_TIMEOUT_MS = readMeshTimeoutEnvMs("MESH_DIRECT_PROBE_CONNECT_TIMEOUT_MS", 45e3);
49132
49262
  var MESH_DIRECT_PROBE_REUSE_MS = readMeshTimeoutEnvMs("MESH_DIRECT_PROBE_REUSE_MS", 12e3);
49133
49263
  var MeshGitProbeCache = class {
49134
49264
  constructor(reuseMs, now = Date.now) {
@@ -49166,12 +49296,73 @@ var MeshGitProbeCache = class {
49166
49296
  }
49167
49297
  }
49168
49298
  };
49299
+ function awaitWithWarmupDeadline(work, opts) {
49300
+ const pollMs = Math.max(1, Math.min(opts.pollIntervalMs ?? 200, opts.connectTimeoutMs));
49301
+ return new Promise((resolve24, reject) => {
49302
+ let done = false;
49303
+ let poll;
49304
+ let responseTimer;
49305
+ const startedAt = Date.now();
49306
+ const cleanup = () => {
49307
+ if (poll) {
49308
+ clearInterval(poll);
49309
+ poll = void 0;
49310
+ }
49311
+ if (responseTimer) {
49312
+ clearTimeout(responseTimer);
49313
+ responseTimer = void 0;
49314
+ }
49315
+ };
49316
+ const settle = (fn) => {
49317
+ if (done) return;
49318
+ done = true;
49319
+ cleanup();
49320
+ fn();
49321
+ };
49322
+ const armResponse = () => {
49323
+ if (responseTimer || done) return;
49324
+ responseTimer = setTimeout(
49325
+ () => settle(() => reject(new Error("timeout"))),
49326
+ opts.responseTimeoutMs
49327
+ );
49328
+ if (typeof responseTimer.unref === "function") responseTimer.unref();
49329
+ };
49330
+ const onPoll = () => {
49331
+ if (done) return;
49332
+ if (opts.isConnected()) {
49333
+ if (poll) {
49334
+ clearInterval(poll);
49335
+ poll = void 0;
49336
+ }
49337
+ armResponse();
49338
+ return;
49339
+ }
49340
+ if (Date.now() - startedAt >= opts.connectTimeoutMs) {
49341
+ settle(() => reject(new Error("timeout")));
49342
+ }
49343
+ };
49344
+ if (opts.isConnected()) {
49345
+ armResponse();
49346
+ } else {
49347
+ poll = setInterval(onPoll, pollMs);
49348
+ if (typeof poll.unref === "function") poll.unref();
49349
+ }
49350
+ work.then(
49351
+ (val) => settle(() => resolve24(val)),
49352
+ (err) => settle(() => reject(err))
49353
+ );
49354
+ });
49355
+ }
49169
49356
  async function probeRemoteMeshGitStatus(args) {
49170
49357
  if (!args.dispatchMeshCommand) return null;
49171
- const remoteResult = await Promise.race([
49172
- args.dispatchMeshCommand(args.daemonId, "git_status", { workspace: args.workspace, refreshUpstream: true }),
49173
- new Promise((_, reject) => setTimeout(() => reject(new Error("timeout")), args.timeoutMs))
49174
- ]);
49358
+ const dispatch = args.dispatchMeshCommand(args.daemonId, "git_status", { workspace: args.workspace, refreshUpstream: true });
49359
+ const getConnection = args.getConnection;
49360
+ const isConnected = getConnection ? () => readMeshConnectionState(getConnection(args.daemonId)) === "connected" : () => true;
49361
+ const remoteResult = await awaitWithWarmupDeadline(dispatch, {
49362
+ isConnected,
49363
+ connectTimeoutMs: args.connectTimeoutMs,
49364
+ responseTimeoutMs: args.responseTimeoutMs
49365
+ });
49175
49366
  const remoteGit = remoteResult?.status ?? remoteResult?.git ?? remoteResult;
49176
49367
  if (!remoteGit || typeof remoteGit !== "object" || typeof remoteGit.isGitRepo !== "boolean") return null;
49177
49368
  const reporterPlatform = readStringValue(remoteResult?.reporterPlatform);
@@ -49206,7 +49397,9 @@ async function probeRemoteMeshGitStatusWithRetry(args) {
49206
49397
  dispatchMeshCommand: args.dispatchMeshCommand,
49207
49398
  daemonId: args.daemonId,
49208
49399
  workspace: args.workspace,
49209
- timeoutMs: attempt === 0 ? args.timeoutMs : args.retryTimeoutMs ?? args.timeoutMs
49400
+ responseTimeoutMs: attempt === 0 ? args.timeoutMs : args.retryTimeoutMs ?? args.timeoutMs,
49401
+ connectTimeoutMs: args.connectTimeoutMs ?? MESH_DIRECT_PROBE_CONNECT_TIMEOUT_MS,
49402
+ getConnection: args.getConnection
49210
49403
  });
49211
49404
  if (remoteGit) return remoteGit;
49212
49405
  } catch {
@@ -49289,6 +49482,7 @@ async function hydrateInlineMeshDirectTruth(args) {
49289
49482
  workspace,
49290
49483
  timeoutMs: MESH_DIRECT_PROBE_TIMEOUT_MS,
49291
49484
  retryTimeoutMs: MESH_DIRECT_PROBE_RETRY_TIMEOUT_MS,
49485
+ connectTimeoutMs: MESH_DIRECT_PROBE_CONNECT_TIMEOUT_MS,
49292
49486
  getConnection: args.getMeshPeerConnectionStatus
49293
49487
  });
49294
49488
  const remoteGit = args.probeCache ? await args.probeCache.probe(daemonId, workspace, runProbe) : await runProbe();
@@ -49340,13 +49534,13 @@ function liveSessionRecordMatchesMeshNode(record, meshId, nodeId, nodeWorkspace
49340
49534
  if (!recordNodeId || recordNodeId !== nodeId) return false;
49341
49535
  if (nodeIsMissingLocalWorktree) return false;
49342
49536
  const recordWorkspace = readStringValue(record?.workspace);
49343
- if (nodeWorkspace && recordWorkspace && recordWorkspace !== nodeWorkspace) return false;
49537
+ if (nodeWorkspace && recordWorkspace && !meshWorkspacesEquivalent(recordWorkspace, nodeWorkspace)) return false;
49344
49538
  const recordMeshId = readStringValue(record?.meta?.meshNodeFor);
49345
49539
  return !recordMeshId || recordMeshId === meshId;
49346
49540
  }
49347
49541
  function liveSessionRecordMatchesMeshWorkspace(record, meshId, workspace) {
49348
49542
  const recordWorkspace = readStringValue(record?.workspace);
49349
- if (!recordWorkspace || !workspace || recordWorkspace !== workspace) return false;
49543
+ if (!recordWorkspace || !workspace || !meshWorkspacesEquivalent(recordWorkspace, workspace)) return false;
49350
49544
  const recordMeshId = readStringValue(record?.meta?.meshNodeFor);
49351
49545
  if (recordMeshId) return recordMeshId === meshId;
49352
49546
  return record?.meta?.launchedByCoordinator === true || !!readStringValue(record?.meta?.meshNodeId);