@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.
@@ -91,6 +91,7 @@ export declare class DaemonCommandRouter {
91
91
  private aggregateMeshStatusCache;
92
92
  constructor(deps: CommandRouterDeps);
93
93
  private cloneJsonValue;
94
+ private hydrateCachedAggregateMeshStatusFromInline;
94
95
  private getCachedAggregateMeshStatus;
95
96
  private rememberAggregateMeshStatus;
96
97
  getCachedInlineMesh(meshId: string, inlineMesh?: unknown): any | undefined;
package/dist/index.js CHANGED
@@ -24204,8 +24204,12 @@ function buildInlineMeshTransitGitStatus(node) {
24204
24204
  const probeGitResult = readObjectRecord(probeGit.result);
24205
24205
  const probeDirectStatus = readObjectRecord(probeGit.status);
24206
24206
  const probeNestedStatus = readObjectRecord(probeGitResult.status);
24207
- const status = Object.keys(directStatus).length ? directStatus : Object.keys(nestedStatus).length ? nestedStatus : Object.keys(probeDirectStatus).length ? probeDirectStatus : Object.keys(probeNestedStatus).length ? probeNestedStatus : {};
24208
- return normalizeInlineMeshGitStatus(status, node, { lastCheckedAt: Date.now() });
24207
+ const candidates = [directStatus, nestedStatus, probeDirectStatus, probeNestedStatus];
24208
+ for (const status of candidates) {
24209
+ const normalized = normalizeInlineMeshGitStatus(status, node, { lastCheckedAt: Date.now() });
24210
+ if (normalized) return normalized;
24211
+ }
24212
+ return void 0;
24209
24213
  }
24210
24214
  function recordInlineMeshDirectGitTruth(node, git, source) {
24211
24215
  if (!node || typeof node !== "object" || Array.isArray(node)) return;
@@ -25074,10 +25078,69 @@ var DaemonCommandRouter = class {
25074
25078
  if (typeof structuredClone === "function") return structuredClone(value);
25075
25079
  return JSON.parse(JSON.stringify(value));
25076
25080
  }
25077
- getCachedAggregateMeshStatus(meshId) {
25081
+ hydrateCachedAggregateMeshStatusFromInline(snapshot, mesh, options) {
25082
+ if (!mesh || typeof mesh !== "object" || !Array.isArray(mesh.nodes) || !Array.isArray(snapshot?.nodes)) return snapshot;
25083
+ const inlineNodesById = /* @__PURE__ */ new Map();
25084
+ for (const node of mesh.nodes) {
25085
+ const nodeId = readInlineMeshNodeId(node);
25086
+ if (nodeId) inlineNodesById.set(nodeId, node);
25087
+ }
25088
+ if (!inlineNodesById.size) return snapshot;
25089
+ let changed = false;
25090
+ const unavailableNodeIds = /* @__PURE__ */ new Set();
25091
+ const sourceOfTruth = readObjectRecord(snapshot.sourceOfTruth);
25092
+ const directPeerTruth = readObjectRecord(sourceOfTruth.directPeerTruth);
25093
+ for (const entry of Array.isArray(directPeerTruth.unavailableNodeIds) ? directPeerTruth.unavailableNodeIds : []) {
25094
+ const nodeId = readStringValue(entry);
25095
+ if (nodeId) unavailableNodeIds.add(nodeId);
25096
+ }
25097
+ const nodes = snapshot.nodes.map((statusNode) => {
25098
+ const nodeId = readStringValue(statusNode?.nodeId, statusNode?.id);
25099
+ const inlineNode = nodeId ? inlineNodesById.get(nodeId) : void 0;
25100
+ if (!inlineNode) return statusNode;
25101
+ const liveGit = buildInlineMeshTransitGitStatus(inlineNode);
25102
+ if (!liveGit) return statusNode;
25103
+ const nextStatus = { ...statusNode };
25104
+ nextStatus.git = liveGit;
25105
+ nextStatus.health = deriveMeshNodeHealthFromGit(liveGit);
25106
+ delete nextStatus.gitProbePending;
25107
+ if (readStringValue(nextStatus.error) === "waiting for live peer git snapshot") delete nextStatus.error;
25108
+ if (!readStringValue(nextStatus.machineStatus)) nextStatus.machineStatus = "online";
25109
+ if (nodeId) unavailableNodeIds.delete(nodeId);
25110
+ changed = true;
25111
+ return nextStatus;
25112
+ });
25113
+ if (!changed && !(options?.requireDirectPeerTruth && unavailableNodeIds.size > 0)) return snapshot;
25114
+ const nextSourceOfTruth = {
25115
+ ...sourceOfTruth,
25116
+ ...Object.keys(directPeerTruth).length ? {
25117
+ directPeerTruth: {
25118
+ ...directPeerTruth,
25119
+ satisfied: options?.requireDirectPeerTruth === true ? unavailableNodeIds.size === 0 : directPeerTruth.satisfied,
25120
+ unavailableNodeIds: [...unavailableNodeIds]
25121
+ },
25122
+ ...options?.requireDirectPeerTruth === true ? {
25123
+ coordinatorOwnsLiveTruth: unavailableNodeIds.size === 0,
25124
+ currentStatus: unavailableNodeIds.size === 0 ? "live_git_and_session_probes" : "direct_peer_truth_unavailable"
25125
+ } : {}
25126
+ } : {}
25127
+ };
25128
+ return {
25129
+ ...snapshot,
25130
+ ...options?.requireDirectPeerTruth === true && unavailableNodeIds.size > 0 ? {
25131
+ success: false,
25132
+ code: "mesh_direct_peer_truth_unavailable",
25133
+ error: "Selected coordinator could not confirm direct mesh truth for every remote node yet."
25134
+ } : {},
25135
+ sourceOfTruth: nextSourceOfTruth,
25136
+ nodes
25137
+ };
25138
+ }
25139
+ getCachedAggregateMeshStatus(meshId, mesh, options) {
25078
25140
  const cached = this.aggregateMeshStatusCache.get(meshId);
25079
25141
  if (!cached?.snapshot || cached.snapshot.success !== true || !Array.isArray(cached.snapshot.nodes)) return null;
25080
- const snapshot = this.cloneJsonValue(cached.snapshot);
25142
+ let snapshot = this.cloneJsonValue(cached.snapshot);
25143
+ snapshot = this.hydrateCachedAggregateMeshStatusFromInline(snapshot, mesh, options);
25081
25144
  const ageMs = Math.max(0, Date.now() - cached.builtAt);
25082
25145
  const sourceOfTruth = snapshot.sourceOfTruth && typeof snapshot.sourceOfTruth === "object" ? snapshot.sourceOfTruth : {};
25083
25146
  snapshot.sourceOfTruth = {
@@ -25137,7 +25200,14 @@ var DaemonCommandRouter = class {
25137
25200
  const preferInline = options?.preferInline === true;
25138
25201
  if (preferInline) {
25139
25202
  const cached2 = this.getCachedInlineMesh(meshId);
25140
- if (cached2) return { mesh: cached2, inline: true, source: "inline_cache" };
25203
+ if (cached2) {
25204
+ if (inlineMeshCarriesTransientNodeTruth(inlineMesh)) {
25205
+ const merged = reconcileInlineMeshCache(cached2, inlineMesh);
25206
+ this.inlineMeshCache.set(meshId, sanitizeInlineMesh(merged));
25207
+ return { mesh: merged, inline: true, source: "inline_cache" };
25208
+ }
25209
+ return { mesh: cached2, inline: true, source: "inline_cache" };
25210
+ }
25141
25211
  if (inlineMeshCarriesTransientNodeTruth(inlineMesh)) {
25142
25212
  this.warmInlineMeshCache(meshId, inlineMesh);
25143
25213
  return { mesh: inlineMesh, inline: true, source: "inline_bootstrap" };
@@ -27117,7 +27187,7 @@ ${block}`);
27117
27187
  if (!mesh) return { success: false, error: "Mesh not found" };
27118
27188
  const refreshRequested = args?.refresh === true || args?.forceRefresh === true;
27119
27189
  if (!refreshRequested) {
27120
- const cachedStatus = this.getCachedAggregateMeshStatus(meshId);
27190
+ const cachedStatus = this.getCachedAggregateMeshStatus(meshId, mesh, { requireDirectPeerTruth: args?.requireDirectPeerTruth === true });
27121
27191
  if (cachedStatus) {
27122
27192
  logRepoMeshStatusDebug("return_cached", {
27123
27193
  meshId,
@@ -27152,7 +27222,9 @@ ${block}`);
27152
27222
  peerConfirmedCount: 0,
27153
27223
  unavailableNodeIds: []
27154
27224
  };
27155
- const directTruthSatisfied = meshRecord.source !== "inline_bootstrap" || directTruth.directEvidenceCount > 0;
27225
+ const passivePeerTruthNotAttempted = requireDirectPeerTruth && !refreshRequested && directTruth.directEvidenceCount > 0 && directTruth.peerAttemptedCount === 0;
27226
+ const effectiveDirectTruth = passivePeerTruthNotAttempted ? { ...directTruth, unavailableNodeIds: [] } : directTruth;
27227
+ const directTruthSatisfied = !requireDirectPeerTruth || effectiveDirectTruth.directEvidenceCount > 0 && effectiveDirectTruth.unavailableNodeIds.length === 0;
27156
27228
  if (requireDirectPeerTruth && !directTruthSatisfied) {
27157
27229
  const failureResult = {
27158
27230
  success: false,
@@ -27182,7 +27254,7 @@ ${block}`);
27182
27254
  });
27183
27255
  return failureResult;
27184
27256
  }
27185
- const directTruthUnavailableNodeIds = new Set(directTruth.unavailableNodeIds);
27257
+ const directTruthUnavailableNodeIds = new Set(effectiveDirectTruth.unavailableNodeIds);
27186
27258
  const selectedCoordinatorNodeId = readStringValue(
27187
27259
  mesh.coordinator?.preferredNodeId,
27188
27260
  mesh.nodes?.[0]?.id,
@@ -27375,11 +27447,11 @@ ${block}`);
27375
27447
  directPeerTruth: {
27376
27448
  required: true,
27377
27449
  satisfied: directTruthSatisfied,
27378
- directEvidenceCount: directTruth.directEvidenceCount,
27379
- localConfirmedCount: directTruth.localConfirmedCount,
27380
- peerAttemptedCount: directTruth.peerAttemptedCount,
27381
- peerConfirmedCount: directTruth.peerConfirmedCount,
27382
- unavailableNodeIds: directTruth.unavailableNodeIds
27450
+ directEvidenceCount: effectiveDirectTruth.directEvidenceCount,
27451
+ localConfirmedCount: effectiveDirectTruth.localConfirmedCount,
27452
+ peerAttemptedCount: effectiveDirectTruth.peerAttemptedCount,
27453
+ peerConfirmedCount: effectiveDirectTruth.peerConfirmedCount,
27454
+ unavailableNodeIds: effectiveDirectTruth.unavailableNodeIds
27383
27455
  }
27384
27456
  } : {},
27385
27457
  historicalEvidenceOnly: ["recoveryHints", "ledger.summary", "queue.summary"]