@adhdev/daemon-core 0.9.82-rc.371 → 0.9.82-rc.372

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.js CHANGED
@@ -316,10 +316,10 @@ function readInjected(value) {
316
316
  }
317
317
  function getDaemonBuildInfo() {
318
318
  if (cached) return cached;
319
- const commit = readInjected(true ? "0e66043bc2858f114fbdd7b1edeb7774f33bfd2d" : void 0) ?? "unknown";
320
- const commitShort = readInjected(true ? "0e66043b" : void 0) ?? (commit !== "unknown" ? commit.slice(0, 7) : "unknown");
321
- const version = readInjected(true ? "0.9.82-rc.371" : void 0) ?? readInjected(typeof process !== "undefined" ? process.env?.ADHDEV_PKG_VERSION : void 0) ?? "unknown";
322
- const builtAt = readInjected(true ? "2026-06-24T12:30:13.850Z" : void 0);
319
+ const commit = readInjected(true ? "376a56400a2a60c210b7d8a2476b5d2a15604c7e" : void 0) ?? "unknown";
320
+ const commitShort = readInjected(true ? "376a5640" : void 0) ?? (commit !== "unknown" ? commit.slice(0, 7) : "unknown");
321
+ const version = readInjected(true ? "0.9.82-rc.372" : void 0) ?? readInjected(typeof process !== "undefined" ? process.env?.ADHDEV_PKG_VERSION : void 0) ?? "unknown";
322
+ const builtAt = readInjected(true ? "2026-06-24T13:46:48.450Z" : void 0);
323
323
  cached = builtAt ? { commit, commitShort, version, builtAt } : { commit, commitShort, version };
324
324
  return cached;
325
325
  }
@@ -5542,7 +5542,14 @@ var init_mesh_runtime_store = __esm({
5542
5542
  if (candidate.taskMode === "live_debug_readonly") return true;
5543
5543
  return !nodeBusy;
5544
5544
  };
5545
- const entry = candidates.find((candidate) => nodeSatisfiesRequiredTags(candidate.requiredTags, capabilityTags) && dependenciesSatisfied(candidate) && nodeConflictAllows(candidate));
5545
+ const nodeIsWorktree = opts?.nodeIsWorktree === true;
5546
+ const convergenceAllows = (candidate) => candidate.taskMode !== "convergence" || !nodeIsWorktree;
5547
+ const targetMatches = (candidate) => {
5548
+ if (candidate.targetSessionId && candidate.targetSessionId !== sessionId) return false;
5549
+ if (candidate.targetNodeId && candidate.targetNodeId !== nodeId) return false;
5550
+ return true;
5551
+ };
5552
+ const entry = candidates.find((candidate) => nodeSatisfiesRequiredTags(candidate.requiredTags, capabilityTags) && dependenciesSatisfied(candidate) && convergenceAllows(candidate) && targetMatches(candidate) && nodeConflictAllows(candidate));
5546
5553
  if (!entry) return null;
5547
5554
  const now = (/* @__PURE__ */ new Date()).toISOString();
5548
5555
  entry.status = "assigned";
@@ -12746,6 +12753,31 @@ function recoverMeshIdByNodeId(nodeId) {
12746
12753
  }
12747
12754
  return "";
12748
12755
  }
12756
+ function resolveForwardEventMeshId(components, payload) {
12757
+ const direct = readNonEmptyString2(payload.meshId);
12758
+ if (direct) return direct;
12759
+ const workspace = readNonEmptyString2(payload.workspace);
12760
+ const byWorkspace = workspace ? readNonEmptyString2(getCachedMeshByWorkspace(workspace)?.id) : "";
12761
+ if (byWorkspace) return byWorkspace;
12762
+ const byNode = recoverMeshIdByNodeId(readNonEmptyString2(payload.nodeId));
12763
+ if (byNode) return byNode;
12764
+ const sessionId = readNonEmptyString2(payload.targetSessionId) || readNonEmptyString2(payload.sessionId) || readNonEmptyString2(payload.instanceId);
12765
+ if (sessionId) {
12766
+ try {
12767
+ const state = components.instanceManager?.getInstance?.(sessionId)?.getState?.();
12768
+ const settings = state?.settings || {};
12769
+ const meshNodeFor = readNonEmptyString2(settings.meshNodeFor);
12770
+ if (meshNodeFor) return meshNodeFor;
12771
+ const byStamp = recoverMeshIdByNodeId(readNonEmptyString2(settings.meshNodeId));
12772
+ if (byStamp) return byStamp;
12773
+ const sessionWorkspace = readNonEmptyString2(state?.workspace);
12774
+ const bySessionWorkspace = sessionWorkspace ? readNonEmptyString2(getCachedMeshByWorkspace(sessionWorkspace)?.id) : "";
12775
+ if (bySessionWorkspace) return bySessionWorkspace;
12776
+ } catch {
12777
+ }
12778
+ }
12779
+ return "";
12780
+ }
12749
12781
  function __resetIdleAutoFastForwardForTests() {
12750
12782
  idleAutoFastForwardLastAttempt.clear();
12751
12783
  }
@@ -12992,9 +13024,11 @@ function tryAssignQueueTask(components, meshId, nodeId, sessionId, providerType)
12992
13024
  }
12993
13025
  const capabilityTags = buildMeshNodeCapabilityTags(node, providerType);
12994
13026
  const providerMaxParallel = resolveProviderMaxParallel(node?.policy, providerType);
13027
+ const nodeIsWorktree = node?.isLocalWorktree === true;
12995
13028
  const task = claimNextTask(meshId, nodeId, sessionId, capabilityTags, {
12996
13029
  providerType,
12997
- ...providerMaxParallel !== void 0 ? { providerMaxParallel } : {}
13030
+ ...providerMaxParallel !== void 0 ? { providerMaxParallel } : {},
13031
+ nodeIsWorktree
12998
13032
  });
12999
13033
  if (!task) {
13000
13034
  return false;
@@ -13338,6 +13372,7 @@ async function maybeAutoLaunchOneQueueSession(components, meshId, mesh) {
13338
13372
  }
13339
13373
  const candidateNodes = Array.isArray(mesh?.nodes) ? mesh.nodes.filter((node) => {
13340
13374
  if (task.targetNodeId && !meshNodeIdMatches(node, task.targetNodeId)) return false;
13375
+ if (task.taskMode === "convergence" && node?.isLocalWorktree === true) return false;
13341
13376
  if (task.requiredTags?.length) {
13342
13377
  const priorities = normalizeProviderPriority(node?.policy);
13343
13378
  const providerCandidates = priorities.length ? priorities : [void 0];
@@ -14321,6 +14356,8 @@ function forwardUnresolvedDelegateEvent(components, routing, event) {
14321
14356
  nodeId: readNonEmptyString2(routing.nodeId) || readNonEmptyString2(event.meshNodeId) || void 0,
14322
14357
  workspace: readNonEmptyString2(routing.workspace) || readNonEmptyString2(event.workspace) || void 0
14323
14358
  };
14359
+ const resolvedMeshId = resolveForwardEventMeshId(components, payload);
14360
+ if (resolvedMeshId) payload.meshId = resolvedMeshId;
14324
14361
  const selfDaemonIds = resolveCoordinatorDrainDaemonIds(components);
14325
14362
  if (selfDaemonIds.some((self) => daemonIdsEquivalent(self, coordinatorDaemonId))) {
14326
14363
  try {
@@ -14843,7 +14880,10 @@ async function retryUnresolvedDelegateForwards(components) {
14843
14880
  if (!dispatchMeshCommand) return;
14844
14881
  expireStaleUnresolvedDelegateForwards();
14845
14882
  const entries = peekUnresolvedDelegateForwards();
14846
- if (entries.length === 0) return;
14883
+ if (entries.length === 0) {
14884
+ if (unresolvedForwardRejectionCounts.size > 0) unresolvedForwardRejectionCounts.clear();
14885
+ return;
14886
+ }
14847
14887
  const selfIds = resolveCoordinatorDaemonIds(components);
14848
14888
  const isSelfCoordinatorId = (id) => selfIds.some((self) => daemonIdsEquivalent(self, id));
14849
14889
  for (const entry of entries) {
@@ -14862,6 +14902,7 @@ async function retryUnresolvedDelegateForwards(components) {
14862
14902
  LOG.warn("MeshReconcile", `Local route of self-addressed forward to ${entry.coordinatorDaemonId} threw: ${e?.message || e} \u2014 draining anyway to break the retry loop`);
14863
14903
  }
14864
14904
  ackUnresolvedDelegateForward(entry.id);
14905
+ unresolvedForwardRejectionCounts.delete(entry.id);
14865
14906
  if (localResult && localResult.success === false) {
14866
14907
  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`);
14867
14908
  traceMeshEventDrop("self_forward_local_rejected", entryTraceCtx, readNonEmptyString2(localResult.error) || "no reason");
@@ -14870,21 +14911,40 @@ async function retryUnresolvedDelegateForwards(components) {
14870
14911
  }
14871
14912
  continue;
14872
14913
  }
14914
+ let pushPayload = entry.payload;
14915
+ if (!readNonEmptyString2(pushPayload.meshId)) {
14916
+ const recoveredMeshId = resolveForwardEventMeshId(components, pushPayload);
14917
+ if (recoveredMeshId) {
14918
+ pushPayload = { ...pushPayload, meshId: recoveredMeshId };
14919
+ traceMeshEventStage("forward_meshid_recovered", entryTraceCtx, `meshId=${recoveredMeshId}`);
14920
+ }
14921
+ }
14873
14922
  let result;
14874
14923
  try {
14875
14924
  traceMeshEventStage("forward_send", entryTraceCtx, `retry \u2192 ${entry.coordinatorDaemonId}`);
14876
- result = await dispatchMeshCommand(entry.coordinatorDaemonId, "mesh_forward_event", entry.payload);
14925
+ result = await dispatchMeshCommand(entry.coordinatorDaemonId, "mesh_forward_event", pushPayload);
14877
14926
  } catch (e) {
14878
14927
  LOG.warn("MeshReconcile", `Retry forward to coordinator ${entry.coordinatorDaemonId} failed: ${e?.message || e} \u2014 left queued`);
14879
14928
  traceMeshEventDrop("retry_forward_failed", entryTraceCtx, e?.message || String(e));
14880
14929
  continue;
14881
14930
  }
14882
14931
  if (result && result.success === false) {
14883
- LOG.warn("MeshReconcile", `Retry forward to coordinator ${entry.coordinatorDaemonId} rejected (${readNonEmptyString2(result.error) || "no reason"}) \u2014 left queued`);
14884
- traceMeshEventDrop("retry_forward_rejected", entryTraceCtx, readNonEmptyString2(result.error) || "no reason");
14932
+ const rejections = (unresolvedForwardRejectionCounts.get(entry.id) || 0) + 1;
14933
+ unresolvedForwardRejectionCounts.set(entry.id, rejections);
14934
+ const reason = readNonEmptyString2(result.error) || "no reason";
14935
+ if (rejections >= MAX_FORWARD_REJECTIONS) {
14936
+ ackUnresolvedDelegateForward(entry.id);
14937
+ unresolvedForwardRejectionCounts.delete(entry.id);
14938
+ LOG.warn("MeshReconcile", `Retry forward to coordinator ${entry.coordinatorDaemonId} rejected ${rejections}x (${reason}) \u2014 dropping unresolved-delegate ${readNonEmptyString2(entry.payload.event)} (sess=${readNonEmptyString2(entry.payload.targetSessionId) || readNonEmptyString2(entry.payload.sessionId) || "-"}) to stop the retry loop`);
14939
+ traceMeshEventDrop("retry_forward_exhausted", entryTraceCtx, `${reason} (${rejections} rejections)`);
14940
+ } else {
14941
+ LOG.warn("MeshReconcile", `Retry forward to coordinator ${entry.coordinatorDaemonId} rejected (${reason}) \u2014 left queued (attempt ${rejections}/${MAX_FORWARD_REJECTIONS})`);
14942
+ traceMeshEventDrop("retry_forward_rejected", entryTraceCtx, reason);
14943
+ }
14885
14944
  continue;
14886
14945
  }
14887
14946
  ackUnresolvedDelegateForward(entry.id);
14947
+ unresolvedForwardRejectionCounts.delete(entry.id);
14888
14948
  LOG.info("MeshReconcile", `Retried+delivered unresolved-delegate ${readNonEmptyString2(entry.payload.event)} to coordinator ${entry.coordinatorDaemonId}`);
14889
14949
  }
14890
14950
  }
@@ -15110,7 +15170,7 @@ function setupMeshReconcileLoop(components) {
15110
15170
  }
15111
15171
  };
15112
15172
  }
15113
- var DEFAULT_RECONCILE_INTERVAL_MS, DEFAULT_AUTO_PRUNE_MIN_AGE_MS, heldEventLedgerRecorded, ASSIGNED_STRANDED_DEADLINE_MS, STRICT_SESSION_MATCH_TTL_MS;
15173
+ var DEFAULT_RECONCILE_INTERVAL_MS, DEFAULT_AUTO_PRUNE_MIN_AGE_MS, heldEventLedgerRecorded, ASSIGNED_STRANDED_DEADLINE_MS, STRICT_SESSION_MATCH_TTL_MS, unresolvedForwardRejectionCounts, MAX_FORWARD_REJECTIONS;
15114
15174
  var init_mesh_reconcile_loop = __esm({
15115
15175
  "src/mesh/mesh-reconcile-loop.ts"() {
15116
15176
  "use strict";
@@ -15135,6 +15195,8 @@ var init_mesh_reconcile_loop = __esm({
15135
15195
  heldEventLedgerRecorded = /* @__PURE__ */ new Set();
15136
15196
  ASSIGNED_STRANDED_DEADLINE_MS = 5 * 6e4;
15137
15197
  STRICT_SESSION_MATCH_TTL_MS = 6e4;
15198
+ unresolvedForwardRejectionCounts = /* @__PURE__ */ new Map();
15199
+ MAX_FORWARD_REJECTIONS = 5;
15138
15200
  }
15139
15201
  });
15140
15202
 
@@ -42091,7 +42153,7 @@ Run 'adhdev doctor' for detailed diagnostics.`
42091
42153
  const adapter = this.adapters.get(ik);
42092
42154
  if (adapter) return { adapter, key: ik };
42093
42155
  }
42094
- if (opts?.dir) {
42156
+ if (opts?.dir && !opts?.instanceKey) {
42095
42157
  for (const [k, a] of this.adapters) {
42096
42158
  if (a.cliType === agentType && a.workingDir === opts.dir) {
42097
42159
  return { adapter: a, key: k };