@adhdev/daemon-core 0.9.82-rc.44 → 0.9.82-rc.46

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
@@ -23971,8 +23971,12 @@ function buildInlineMeshTransitGitStatus(node) {
23971
23971
  const probeGitResult = readObjectRecord(probeGit.result);
23972
23972
  const probeDirectStatus = readObjectRecord(probeGit.status);
23973
23973
  const probeNestedStatus = readObjectRecord(probeGitResult.status);
23974
- const status = Object.keys(directStatus).length ? directStatus : Object.keys(nestedStatus).length ? nestedStatus : Object.keys(probeDirectStatus).length ? probeDirectStatus : Object.keys(probeNestedStatus).length ? probeNestedStatus : {};
23975
- return normalizeInlineMeshGitStatus(status, node, { lastCheckedAt: Date.now() });
23974
+ const candidates = [directStatus, nestedStatus, probeDirectStatus, probeNestedStatus];
23975
+ for (const status of candidates) {
23976
+ const normalized = normalizeInlineMeshGitStatus(status, node, { lastCheckedAt: Date.now() });
23977
+ if (normalized) return normalized;
23978
+ }
23979
+ return void 0;
23976
23980
  }
23977
23981
  function recordInlineMeshDirectGitTruth(node, git, source) {
23978
23982
  if (!node || typeof node !== "object" || Array.isArray(node)) return;
@@ -24841,10 +24845,69 @@ var DaemonCommandRouter = class {
24841
24845
  if (typeof structuredClone === "function") return structuredClone(value);
24842
24846
  return JSON.parse(JSON.stringify(value));
24843
24847
  }
24844
- getCachedAggregateMeshStatus(meshId) {
24848
+ hydrateCachedAggregateMeshStatusFromInline(snapshot, mesh, options) {
24849
+ if (!mesh || typeof mesh !== "object" || !Array.isArray(mesh.nodes) || !Array.isArray(snapshot?.nodes)) return snapshot;
24850
+ const inlineNodesById = /* @__PURE__ */ new Map();
24851
+ for (const node of mesh.nodes) {
24852
+ const nodeId = readInlineMeshNodeId(node);
24853
+ if (nodeId) inlineNodesById.set(nodeId, node);
24854
+ }
24855
+ if (!inlineNodesById.size) return snapshot;
24856
+ let changed = false;
24857
+ const unavailableNodeIds = /* @__PURE__ */ new Set();
24858
+ const sourceOfTruth = readObjectRecord(snapshot.sourceOfTruth);
24859
+ const directPeerTruth = readObjectRecord(sourceOfTruth.directPeerTruth);
24860
+ for (const entry of Array.isArray(directPeerTruth.unavailableNodeIds) ? directPeerTruth.unavailableNodeIds : []) {
24861
+ const nodeId = readStringValue(entry);
24862
+ if (nodeId) unavailableNodeIds.add(nodeId);
24863
+ }
24864
+ const nodes = snapshot.nodes.map((statusNode) => {
24865
+ const nodeId = readStringValue(statusNode?.nodeId, statusNode?.id);
24866
+ const inlineNode = nodeId ? inlineNodesById.get(nodeId) : void 0;
24867
+ if (!inlineNode) return statusNode;
24868
+ const liveGit = buildInlineMeshTransitGitStatus(inlineNode);
24869
+ if (!liveGit) return statusNode;
24870
+ const nextStatus = { ...statusNode };
24871
+ nextStatus.git = liveGit;
24872
+ nextStatus.health = deriveMeshNodeHealthFromGit(liveGit);
24873
+ delete nextStatus.gitProbePending;
24874
+ if (readStringValue(nextStatus.error) === "waiting for live peer git snapshot") delete nextStatus.error;
24875
+ if (!readStringValue(nextStatus.machineStatus)) nextStatus.machineStatus = "online";
24876
+ if (nodeId) unavailableNodeIds.delete(nodeId);
24877
+ changed = true;
24878
+ return nextStatus;
24879
+ });
24880
+ if (!changed && !(options?.requireDirectPeerTruth && unavailableNodeIds.size > 0)) return snapshot;
24881
+ const nextSourceOfTruth = {
24882
+ ...sourceOfTruth,
24883
+ ...Object.keys(directPeerTruth).length ? {
24884
+ directPeerTruth: {
24885
+ ...directPeerTruth,
24886
+ satisfied: options?.requireDirectPeerTruth === true ? unavailableNodeIds.size === 0 : directPeerTruth.satisfied,
24887
+ unavailableNodeIds: [...unavailableNodeIds]
24888
+ },
24889
+ ...options?.requireDirectPeerTruth === true ? {
24890
+ coordinatorOwnsLiveTruth: unavailableNodeIds.size === 0,
24891
+ currentStatus: unavailableNodeIds.size === 0 ? "live_git_and_session_probes" : "direct_peer_truth_unavailable"
24892
+ } : {}
24893
+ } : {}
24894
+ };
24895
+ return {
24896
+ ...snapshot,
24897
+ ...options?.requireDirectPeerTruth === true && unavailableNodeIds.size > 0 ? {
24898
+ success: false,
24899
+ code: "mesh_direct_peer_truth_unavailable",
24900
+ error: "Selected coordinator could not confirm direct mesh truth for every remote node yet."
24901
+ } : {},
24902
+ sourceOfTruth: nextSourceOfTruth,
24903
+ nodes
24904
+ };
24905
+ }
24906
+ getCachedAggregateMeshStatus(meshId, mesh, options) {
24845
24907
  const cached = this.aggregateMeshStatusCache.get(meshId);
24846
24908
  if (!cached?.snapshot || cached.snapshot.success !== true || !Array.isArray(cached.snapshot.nodes)) return null;
24847
- const snapshot = this.cloneJsonValue(cached.snapshot);
24909
+ let snapshot = this.cloneJsonValue(cached.snapshot);
24910
+ snapshot = this.hydrateCachedAggregateMeshStatusFromInline(snapshot, mesh, options);
24848
24911
  const ageMs = Math.max(0, Date.now() - cached.builtAt);
24849
24912
  const sourceOfTruth = snapshot.sourceOfTruth && typeof snapshot.sourceOfTruth === "object" ? snapshot.sourceOfTruth : {};
24850
24913
  snapshot.sourceOfTruth = {
@@ -24904,7 +24967,14 @@ var DaemonCommandRouter = class {
24904
24967
  const preferInline = options?.preferInline === true;
24905
24968
  if (preferInline) {
24906
24969
  const cached2 = this.getCachedInlineMesh(meshId);
24907
- if (cached2) return { mesh: cached2, inline: true, source: "inline_cache" };
24970
+ if (cached2) {
24971
+ if (inlineMeshCarriesTransientNodeTruth(inlineMesh)) {
24972
+ const merged = reconcileInlineMeshCache(cached2, inlineMesh);
24973
+ this.inlineMeshCache.set(meshId, sanitizeInlineMesh(merged));
24974
+ return { mesh: merged, inline: true, source: "inline_cache" };
24975
+ }
24976
+ return { mesh: cached2, inline: true, source: "inline_cache" };
24977
+ }
24908
24978
  if (inlineMeshCarriesTransientNodeTruth(inlineMesh)) {
24909
24979
  this.warmInlineMeshCache(meshId, inlineMesh);
24910
24980
  return { mesh: inlineMesh, inline: true, source: "inline_bootstrap" };
@@ -26884,7 +26954,7 @@ ${block}`);
26884
26954
  if (!mesh) return { success: false, error: "Mesh not found" };
26885
26955
  const refreshRequested = args?.refresh === true || args?.forceRefresh === true;
26886
26956
  if (!refreshRequested) {
26887
- const cachedStatus = this.getCachedAggregateMeshStatus(meshId);
26957
+ const cachedStatus = this.getCachedAggregateMeshStatus(meshId, mesh, { requireDirectPeerTruth: args?.requireDirectPeerTruth === true });
26888
26958
  if (cachedStatus) {
26889
26959
  logRepoMeshStatusDebug("return_cached", {
26890
26960
  meshId,
@@ -26919,7 +26989,9 @@ ${block}`);
26919
26989
  peerConfirmedCount: 0,
26920
26990
  unavailableNodeIds: []
26921
26991
  };
26922
- const directTruthSatisfied = meshRecord.source !== "inline_bootstrap" || directTruth.directEvidenceCount > 0;
26992
+ const passivePeerTruthNotAttempted = requireDirectPeerTruth && !refreshRequested && directTruth.directEvidenceCount > 0 && directTruth.peerAttemptedCount === 0;
26993
+ const effectiveDirectTruth = passivePeerTruthNotAttempted ? { ...directTruth, unavailableNodeIds: [] } : directTruth;
26994
+ const directTruthSatisfied = !requireDirectPeerTruth || effectiveDirectTruth.directEvidenceCount > 0 && effectiveDirectTruth.unavailableNodeIds.length === 0;
26923
26995
  if (requireDirectPeerTruth && !directTruthSatisfied) {
26924
26996
  const failureResult = {
26925
26997
  success: false,
@@ -26949,7 +27021,7 @@ ${block}`);
26949
27021
  });
26950
27022
  return failureResult;
26951
27023
  }
26952
- const directTruthUnavailableNodeIds = new Set(directTruth.unavailableNodeIds);
27024
+ const directTruthUnavailableNodeIds = new Set(effectiveDirectTruth.unavailableNodeIds);
26953
27025
  const selectedCoordinatorNodeId = readStringValue(
26954
27026
  mesh.coordinator?.preferredNodeId,
26955
27027
  mesh.nodes?.[0]?.id,
@@ -27142,11 +27214,11 @@ ${block}`);
27142
27214
  directPeerTruth: {
27143
27215
  required: true,
27144
27216
  satisfied: directTruthSatisfied,
27145
- directEvidenceCount: directTruth.directEvidenceCount,
27146
- localConfirmedCount: directTruth.localConfirmedCount,
27147
- peerAttemptedCount: directTruth.peerAttemptedCount,
27148
- peerConfirmedCount: directTruth.peerConfirmedCount,
27149
- unavailableNodeIds: directTruth.unavailableNodeIds
27217
+ directEvidenceCount: effectiveDirectTruth.directEvidenceCount,
27218
+ localConfirmedCount: effectiveDirectTruth.localConfirmedCount,
27219
+ peerAttemptedCount: effectiveDirectTruth.peerAttemptedCount,
27220
+ peerConfirmedCount: effectiveDirectTruth.peerConfirmedCount,
27221
+ unavailableNodeIds: effectiveDirectTruth.unavailableNodeIds
27150
27222
  }
27151
27223
  } : {},
27152
27224
  historicalEvidenceOnly: ["recoveryHints", "ledger.summary", "queue.summary"]