@adhdev/daemon-core 0.9.82-rc.370 → 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.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 ? "84d52e533859a9dd3c3bc8bc11a2541911f7bd0c" : void 0) ?? "unknown";
315
- const commitShort = readInjected(true ? "84d52e53" : void 0) ?? (commit !== "unknown" ? commit.slice(0, 7) : "unknown");
316
- const version = readInjected(true ? "0.9.82-rc.370" : void 0) ?? readInjected(typeof process !== "undefined" ? process.env?.ADHDEV_PKG_VERSION : void 0) ?? "unknown";
317
- const builtAt = readInjected(true ? "2026-06-24T10:07:48.772Z" : void 0);
314
+ const commit = readInjected(true ? "376a56400a2a60c210b7d8a2476b5d2a15604c7e" : void 0) ?? "unknown";
315
+ const commitShort = readInjected(true ? "376a5640" : void 0) ?? (commit !== "unknown" ? commit.slice(0, 7) : "unknown");
316
+ const version = readInjected(true ? "0.9.82-rc.372" : void 0) ?? readInjected(typeof process !== "undefined" ? process.env?.ADHDEV_PKG_VERSION : void 0) ?? "unknown";
317
+ const builtAt = readInjected(true ? "2026-06-24T13:46:48.450Z" : void 0);
318
318
  cached = builtAt ? { commit, commitShort, version, builtAt } : { commit, commitShort, version };
319
319
  return cached;
320
320
  }
@@ -5535,7 +5535,14 @@ var init_mesh_runtime_store = __esm({
5535
5535
  if (candidate.taskMode === "live_debug_readonly") return true;
5536
5536
  return !nodeBusy;
5537
5537
  };
5538
- const entry = candidates.find((candidate) => nodeSatisfiesRequiredTags(candidate.requiredTags, capabilityTags) && dependenciesSatisfied(candidate) && nodeConflictAllows(candidate));
5538
+ const nodeIsWorktree = opts?.nodeIsWorktree === true;
5539
+ const convergenceAllows = (candidate) => candidate.taskMode !== "convergence" || !nodeIsWorktree;
5540
+ const targetMatches = (candidate) => {
5541
+ if (candidate.targetSessionId && candidate.targetSessionId !== sessionId) return false;
5542
+ if (candidate.targetNodeId && candidate.targetNodeId !== nodeId) return false;
5543
+ return true;
5544
+ };
5545
+ const entry = candidates.find((candidate) => nodeSatisfiesRequiredTags(candidate.requiredTags, capabilityTags) && dependenciesSatisfied(candidate) && convergenceAllows(candidate) && targetMatches(candidate) && nodeConflictAllows(candidate));
5539
5546
  if (!entry) return null;
5540
5547
  const now = (/* @__PURE__ */ new Date()).toISOString();
5541
5548
  entry.status = "assigned";
@@ -12742,6 +12749,31 @@ function recoverMeshIdByNodeId(nodeId) {
12742
12749
  }
12743
12750
  return "";
12744
12751
  }
12752
+ function resolveForwardEventMeshId(components, payload) {
12753
+ const direct = readNonEmptyString2(payload.meshId);
12754
+ if (direct) return direct;
12755
+ const workspace = readNonEmptyString2(payload.workspace);
12756
+ const byWorkspace = workspace ? readNonEmptyString2(getCachedMeshByWorkspace(workspace)?.id) : "";
12757
+ if (byWorkspace) return byWorkspace;
12758
+ const byNode = recoverMeshIdByNodeId(readNonEmptyString2(payload.nodeId));
12759
+ if (byNode) return byNode;
12760
+ const sessionId = readNonEmptyString2(payload.targetSessionId) || readNonEmptyString2(payload.sessionId) || readNonEmptyString2(payload.instanceId);
12761
+ if (sessionId) {
12762
+ try {
12763
+ const state = components.instanceManager?.getInstance?.(sessionId)?.getState?.();
12764
+ const settings = state?.settings || {};
12765
+ const meshNodeFor = readNonEmptyString2(settings.meshNodeFor);
12766
+ if (meshNodeFor) return meshNodeFor;
12767
+ const byStamp = recoverMeshIdByNodeId(readNonEmptyString2(settings.meshNodeId));
12768
+ if (byStamp) return byStamp;
12769
+ const sessionWorkspace = readNonEmptyString2(state?.workspace);
12770
+ const bySessionWorkspace = sessionWorkspace ? readNonEmptyString2(getCachedMeshByWorkspace(sessionWorkspace)?.id) : "";
12771
+ if (bySessionWorkspace) return bySessionWorkspace;
12772
+ } catch {
12773
+ }
12774
+ }
12775
+ return "";
12776
+ }
12745
12777
  function __resetIdleAutoFastForwardForTests() {
12746
12778
  idleAutoFastForwardLastAttempt.clear();
12747
12779
  }
@@ -12988,9 +13020,11 @@ function tryAssignQueueTask(components, meshId, nodeId, sessionId, providerType)
12988
13020
  }
12989
13021
  const capabilityTags = buildMeshNodeCapabilityTags(node, providerType);
12990
13022
  const providerMaxParallel = resolveProviderMaxParallel(node?.policy, providerType);
13023
+ const nodeIsWorktree = node?.isLocalWorktree === true;
12991
13024
  const task = claimNextTask(meshId, nodeId, sessionId, capabilityTags, {
12992
13025
  providerType,
12993
- ...providerMaxParallel !== void 0 ? { providerMaxParallel } : {}
13026
+ ...providerMaxParallel !== void 0 ? { providerMaxParallel } : {},
13027
+ nodeIsWorktree
12994
13028
  });
12995
13029
  if (!task) {
12996
13030
  return false;
@@ -13334,6 +13368,7 @@ async function maybeAutoLaunchOneQueueSession(components, meshId, mesh) {
13334
13368
  }
13335
13369
  const candidateNodes = Array.isArray(mesh?.nodes) ? mesh.nodes.filter((node) => {
13336
13370
  if (task.targetNodeId && !meshNodeIdMatches(node, task.targetNodeId)) return false;
13371
+ if (task.taskMode === "convergence" && node?.isLocalWorktree === true) return false;
13337
13372
  if (task.requiredTags?.length) {
13338
13373
  const priorities = normalizeProviderPriority(node?.policy);
13339
13374
  const providerCandidates = priorities.length ? priorities : [void 0];
@@ -14317,6 +14352,8 @@ function forwardUnresolvedDelegateEvent(components, routing, event) {
14317
14352
  nodeId: readNonEmptyString2(routing.nodeId) || readNonEmptyString2(event.meshNodeId) || void 0,
14318
14353
  workspace: readNonEmptyString2(routing.workspace) || readNonEmptyString2(event.workspace) || void 0
14319
14354
  };
14355
+ const resolvedMeshId = resolveForwardEventMeshId(components, payload);
14356
+ if (resolvedMeshId) payload.meshId = resolvedMeshId;
14320
14357
  const selfDaemonIds = resolveCoordinatorDrainDaemonIds(components);
14321
14358
  if (selfDaemonIds.some((self) => daemonIdsEquivalent(self, coordinatorDaemonId))) {
14322
14359
  try {
@@ -14838,7 +14875,10 @@ async function retryUnresolvedDelegateForwards(components) {
14838
14875
  if (!dispatchMeshCommand) return;
14839
14876
  expireStaleUnresolvedDelegateForwards();
14840
14877
  const entries = peekUnresolvedDelegateForwards();
14841
- if (entries.length === 0) return;
14878
+ if (entries.length === 0) {
14879
+ if (unresolvedForwardRejectionCounts.size > 0) unresolvedForwardRejectionCounts.clear();
14880
+ return;
14881
+ }
14842
14882
  const selfIds = resolveCoordinatorDaemonIds(components);
14843
14883
  const isSelfCoordinatorId = (id) => selfIds.some((self) => daemonIdsEquivalent(self, id));
14844
14884
  for (const entry of entries) {
@@ -14857,6 +14897,7 @@ async function retryUnresolvedDelegateForwards(components) {
14857
14897
  LOG.warn("MeshReconcile", `Local route of self-addressed forward to ${entry.coordinatorDaemonId} threw: ${e?.message || e} \u2014 draining anyway to break the retry loop`);
14858
14898
  }
14859
14899
  ackUnresolvedDelegateForward(entry.id);
14900
+ unresolvedForwardRejectionCounts.delete(entry.id);
14860
14901
  if (localResult && localResult.success === false) {
14861
14902
  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`);
14862
14903
  traceMeshEventDrop("self_forward_local_rejected", entryTraceCtx, readNonEmptyString2(localResult.error) || "no reason");
@@ -14865,21 +14906,40 @@ async function retryUnresolvedDelegateForwards(components) {
14865
14906
  }
14866
14907
  continue;
14867
14908
  }
14909
+ let pushPayload = entry.payload;
14910
+ if (!readNonEmptyString2(pushPayload.meshId)) {
14911
+ const recoveredMeshId = resolveForwardEventMeshId(components, pushPayload);
14912
+ if (recoveredMeshId) {
14913
+ pushPayload = { ...pushPayload, meshId: recoveredMeshId };
14914
+ traceMeshEventStage("forward_meshid_recovered", entryTraceCtx, `meshId=${recoveredMeshId}`);
14915
+ }
14916
+ }
14868
14917
  let result;
14869
14918
  try {
14870
14919
  traceMeshEventStage("forward_send", entryTraceCtx, `retry \u2192 ${entry.coordinatorDaemonId}`);
14871
- result = await dispatchMeshCommand(entry.coordinatorDaemonId, "mesh_forward_event", entry.payload);
14920
+ result = await dispatchMeshCommand(entry.coordinatorDaemonId, "mesh_forward_event", pushPayload);
14872
14921
  } catch (e) {
14873
14922
  LOG.warn("MeshReconcile", `Retry forward to coordinator ${entry.coordinatorDaemonId} failed: ${e?.message || e} \u2014 left queued`);
14874
14923
  traceMeshEventDrop("retry_forward_failed", entryTraceCtx, e?.message || String(e));
14875
14924
  continue;
14876
14925
  }
14877
14926
  if (result && result.success === false) {
14878
- LOG.warn("MeshReconcile", `Retry forward to coordinator ${entry.coordinatorDaemonId} rejected (${readNonEmptyString2(result.error) || "no reason"}) \u2014 left queued`);
14879
- traceMeshEventDrop("retry_forward_rejected", entryTraceCtx, readNonEmptyString2(result.error) || "no reason");
14927
+ const rejections = (unresolvedForwardRejectionCounts.get(entry.id) || 0) + 1;
14928
+ unresolvedForwardRejectionCounts.set(entry.id, rejections);
14929
+ const reason = readNonEmptyString2(result.error) || "no reason";
14930
+ if (rejections >= MAX_FORWARD_REJECTIONS) {
14931
+ ackUnresolvedDelegateForward(entry.id);
14932
+ unresolvedForwardRejectionCounts.delete(entry.id);
14933
+ 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`);
14934
+ traceMeshEventDrop("retry_forward_exhausted", entryTraceCtx, `${reason} (${rejections} rejections)`);
14935
+ } else {
14936
+ LOG.warn("MeshReconcile", `Retry forward to coordinator ${entry.coordinatorDaemonId} rejected (${reason}) \u2014 left queued (attempt ${rejections}/${MAX_FORWARD_REJECTIONS})`);
14937
+ traceMeshEventDrop("retry_forward_rejected", entryTraceCtx, reason);
14938
+ }
14880
14939
  continue;
14881
14940
  }
14882
14941
  ackUnresolvedDelegateForward(entry.id);
14942
+ unresolvedForwardRejectionCounts.delete(entry.id);
14883
14943
  LOG.info("MeshReconcile", `Retried+delivered unresolved-delegate ${readNonEmptyString2(entry.payload.event)} to coordinator ${entry.coordinatorDaemonId}`);
14884
14944
  }
14885
14945
  }
@@ -15105,7 +15165,7 @@ function setupMeshReconcileLoop(components) {
15105
15165
  }
15106
15166
  };
15107
15167
  }
15108
- var DEFAULT_RECONCILE_INTERVAL_MS, DEFAULT_AUTO_PRUNE_MIN_AGE_MS, heldEventLedgerRecorded, ASSIGNED_STRANDED_DEADLINE_MS, STRICT_SESSION_MATCH_TTL_MS;
15168
+ 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;
15109
15169
  var init_mesh_reconcile_loop = __esm({
15110
15170
  "src/mesh/mesh-reconcile-loop.ts"() {
15111
15171
  "use strict";
@@ -15130,6 +15190,8 @@ var init_mesh_reconcile_loop = __esm({
15130
15190
  heldEventLedgerRecorded = /* @__PURE__ */ new Set();
15131
15191
  ASSIGNED_STRANDED_DEADLINE_MS = 5 * 6e4;
15132
15192
  STRICT_SESSION_MATCH_TTL_MS = 6e4;
15193
+ unresolvedForwardRejectionCounts = /* @__PURE__ */ new Map();
15194
+ MAX_FORWARD_REJECTIONS = 5;
15133
15195
  }
15134
15196
  });
15135
15197
 
@@ -41723,7 +41785,7 @@ Run 'adhdev doctor' for detailed diagnostics.`
41723
41785
  const adapter = this.adapters.get(ik);
41724
41786
  if (adapter) return { adapter, key: ik };
41725
41787
  }
41726
- if (opts?.dir) {
41788
+ if (opts?.dir && !opts?.instanceKey) {
41727
41789
  for (const [k, a] of this.adapters) {
41728
41790
  if (a.cliType === agentType && a.workingDir === opts.dir) {
41729
41791
  return { adapter: a, key: k };
@@ -47330,6 +47392,52 @@ var fastForwardHandlers = {
47330
47392
  }
47331
47393
  };
47332
47394
 
47395
+ // src/commands/med-family/mesh-restart.ts
47396
+ init_dist();
47397
+ var RESTART_BLOCKING_STATES = /* @__PURE__ */ new Set(["generating", "waiting_approval", "starting"]);
47398
+ function hasBlockingSessions(ctx) {
47399
+ const states = ctx.deps.instanceManager.collectAllStates();
47400
+ for (const state of states) {
47401
+ if (RESTART_BLOCKING_STATES.has(String(state.status || ""))) return true;
47402
+ const childStates = "extensions" in state && Array.isArray(state.extensions) ? state.extensions : [];
47403
+ for (const child of childStates) {
47404
+ if (RESTART_BLOCKING_STATES.has(String(child?.status || ""))) return true;
47405
+ }
47406
+ }
47407
+ return false;
47408
+ }
47409
+ var meshRestartHandlers = {
47410
+ restart_daemon_node: async (ctx, args) => {
47411
+ const meshId = typeof args?.meshId === "string" ? args.meshId.trim() : "";
47412
+ const nodeId = typeof args?.nodeId === "string" ? args.nodeId.trim() : "";
47413
+ let nodeDaemonId;
47414
+ if (meshId && nodeId) {
47415
+ const meshRecord = await ctx.getMeshForCommand(meshId, args?.inlineMesh, { preferInline: true });
47416
+ const node = meshRecord?.mesh?.nodes?.find((n) => meshNodeIdMatches(n, nodeId));
47417
+ nodeDaemonId = typeof node?.daemonId === "string" ? node.daemonId.trim() : void 0;
47418
+ }
47419
+ const selfDaemonId = ctx.deps.statusInstanceId;
47420
+ const isRemote = nodeDaemonId && selfDaemonId && !daemonIdsEquivalent(nodeDaemonId, selfDaemonId);
47421
+ if (isRemote && ctx.deps.dispatchMeshCommand && !args?._meshDirectDispatch) {
47422
+ const forwarded = await ctx.deps.dispatchMeshCommand(nodeDaemonId, "restart_daemon_node", {
47423
+ ...typeof args === "object" && args !== null ? args : {},
47424
+ _meshDirectDispatch: true
47425
+ });
47426
+ return forwarded ?? { success: false, error: "no response from remote node" };
47427
+ }
47428
+ if (hasBlockingSessions(ctx)) {
47429
+ return {
47430
+ success: false,
47431
+ restarted: false,
47432
+ code: "blocking_sessions",
47433
+ reason: "Daemon has an active session (generating / waiting_approval / starting); restart refused to avoid interrupting in-flight work. Retry when the node is idle."
47434
+ };
47435
+ }
47436
+ const result = await daemonLifecycleHandlers.daemon_upgrade({ deps: ctx.deps }, args);
47437
+ return { ...result, restarted: result?.restarting === true };
47438
+ }
47439
+ };
47440
+
47333
47441
  // src/commands/med-family/index.ts
47334
47442
  var medFamilyRegistry = new Map(
47335
47443
  Object.entries({
@@ -47338,7 +47446,8 @@ var medFamilyRegistry = new Map(
47338
47446
  ...meshCrudHandlers,
47339
47447
  ...meshHostPairingHandlers,
47340
47448
  ...meshQueueHandlers,
47341
- ...fastForwardHandlers
47449
+ ...fastForwardHandlers,
47450
+ ...meshRestartHandlers
47342
47451
  })
47343
47452
  );
47344
47453
 
@@ -61550,6 +61659,7 @@ export {
61550
61659
  MESH_CONVERGE_FAST_FORWARD_TAG,
61551
61660
  MESH_CONVERGE_REFINE_TAG,
61552
61661
  MESH_MISSION_STATUSES,
61662
+ MESH_NODE_LIVE_TRUTH_MARKER,
61553
61663
  MESH_REFINE_CONFIG_LOCATIONS,
61554
61664
  MESH_REFINE_CONFIG_SCHEMA,
61555
61665
  MESH_SCHEDULING_STRATEGIES,
@@ -61596,6 +61706,7 @@ export {
61596
61706
  buildMeshLedgerReconciliationEvidence,
61597
61707
  buildMeshLedgerReplicaEvidence,
61598
61708
  buildMeshNodeCapabilityTags,
61709
+ buildMeshNodeDataFreshness,
61599
61710
  buildMissionPromptSection,
61600
61711
  buildP2pRelayFailurePayload,
61601
61712
  buildPinnedGlobalInstallCommand,