@adhdev/daemon-standalone 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.js CHANGED
@@ -46184,8 +46184,12 @@ ${(0, import_node_path.resolve)(workspace || os17.tmpdir())}`;
46184
46184
  const probeGitResult = readObjectRecord(probeGit.result);
46185
46185
  const probeDirectStatus = readObjectRecord(probeGit.status);
46186
46186
  const probeNestedStatus = readObjectRecord(probeGitResult.status);
46187
- const status = Object.keys(directStatus).length ? directStatus : Object.keys(nestedStatus).length ? nestedStatus : Object.keys(probeDirectStatus).length ? probeDirectStatus : Object.keys(probeNestedStatus).length ? probeNestedStatus : {};
46188
- return normalizeInlineMeshGitStatus(status, node, { lastCheckedAt: Date.now() });
46187
+ const candidates = [directStatus, nestedStatus, probeDirectStatus, probeNestedStatus];
46188
+ for (const status of candidates) {
46189
+ const normalized = normalizeInlineMeshGitStatus(status, node, { lastCheckedAt: Date.now() });
46190
+ if (normalized) return normalized;
46191
+ }
46192
+ return void 0;
46189
46193
  }
46190
46194
  function recordInlineMeshDirectGitTruth(node, git, source) {
46191
46195
  if (!node || typeof node !== "object" || Array.isArray(node)) return;
@@ -47054,10 +47058,69 @@ ${(0, import_node_path.resolve)(workspace || os17.tmpdir())}`;
47054
47058
  if (typeof structuredClone === "function") return structuredClone(value);
47055
47059
  return JSON.parse(JSON.stringify(value));
47056
47060
  }
47057
- getCachedAggregateMeshStatus(meshId) {
47061
+ hydrateCachedAggregateMeshStatusFromInline(snapshot, mesh, options) {
47062
+ if (!mesh || typeof mesh !== "object" || !Array.isArray(mesh.nodes) || !Array.isArray(snapshot?.nodes)) return snapshot;
47063
+ const inlineNodesById = /* @__PURE__ */ new Map();
47064
+ for (const node of mesh.nodes) {
47065
+ const nodeId = readInlineMeshNodeId(node);
47066
+ if (nodeId) inlineNodesById.set(nodeId, node);
47067
+ }
47068
+ if (!inlineNodesById.size) return snapshot;
47069
+ let changed = false;
47070
+ const unavailableNodeIds = /* @__PURE__ */ new Set();
47071
+ const sourceOfTruth = readObjectRecord(snapshot.sourceOfTruth);
47072
+ const directPeerTruth = readObjectRecord(sourceOfTruth.directPeerTruth);
47073
+ for (const entry of Array.isArray(directPeerTruth.unavailableNodeIds) ? directPeerTruth.unavailableNodeIds : []) {
47074
+ const nodeId = readStringValue(entry);
47075
+ if (nodeId) unavailableNodeIds.add(nodeId);
47076
+ }
47077
+ const nodes = snapshot.nodes.map((statusNode) => {
47078
+ const nodeId = readStringValue(statusNode?.nodeId, statusNode?.id);
47079
+ const inlineNode = nodeId ? inlineNodesById.get(nodeId) : void 0;
47080
+ if (!inlineNode) return statusNode;
47081
+ const liveGit = buildInlineMeshTransitGitStatus(inlineNode);
47082
+ if (!liveGit) return statusNode;
47083
+ const nextStatus = { ...statusNode };
47084
+ nextStatus.git = liveGit;
47085
+ nextStatus.health = deriveMeshNodeHealthFromGit(liveGit);
47086
+ delete nextStatus.gitProbePending;
47087
+ if (readStringValue(nextStatus.error) === "waiting for live peer git snapshot") delete nextStatus.error;
47088
+ if (!readStringValue(nextStatus.machineStatus)) nextStatus.machineStatus = "online";
47089
+ if (nodeId) unavailableNodeIds.delete(nodeId);
47090
+ changed = true;
47091
+ return nextStatus;
47092
+ });
47093
+ if (!changed && !(options?.requireDirectPeerTruth && unavailableNodeIds.size > 0)) return snapshot;
47094
+ const nextSourceOfTruth = {
47095
+ ...sourceOfTruth,
47096
+ ...Object.keys(directPeerTruth).length ? {
47097
+ directPeerTruth: {
47098
+ ...directPeerTruth,
47099
+ satisfied: options?.requireDirectPeerTruth === true ? unavailableNodeIds.size === 0 : directPeerTruth.satisfied,
47100
+ unavailableNodeIds: [...unavailableNodeIds]
47101
+ },
47102
+ ...options?.requireDirectPeerTruth === true ? {
47103
+ coordinatorOwnsLiveTruth: unavailableNodeIds.size === 0,
47104
+ currentStatus: unavailableNodeIds.size === 0 ? "live_git_and_session_probes" : "direct_peer_truth_unavailable"
47105
+ } : {}
47106
+ } : {}
47107
+ };
47108
+ return {
47109
+ ...snapshot,
47110
+ ...options?.requireDirectPeerTruth === true && unavailableNodeIds.size > 0 ? {
47111
+ success: false,
47112
+ code: "mesh_direct_peer_truth_unavailable",
47113
+ error: "Selected coordinator could not confirm direct mesh truth for every remote node yet."
47114
+ } : {},
47115
+ sourceOfTruth: nextSourceOfTruth,
47116
+ nodes
47117
+ };
47118
+ }
47119
+ getCachedAggregateMeshStatus(meshId, mesh, options) {
47058
47120
  const cached2 = this.aggregateMeshStatusCache.get(meshId);
47059
47121
  if (!cached2?.snapshot || cached2.snapshot.success !== true || !Array.isArray(cached2.snapshot.nodes)) return null;
47060
- const snapshot = this.cloneJsonValue(cached2.snapshot);
47122
+ let snapshot = this.cloneJsonValue(cached2.snapshot);
47123
+ snapshot = this.hydrateCachedAggregateMeshStatusFromInline(snapshot, mesh, options);
47061
47124
  const ageMs = Math.max(0, Date.now() - cached2.builtAt);
47062
47125
  const sourceOfTruth = snapshot.sourceOfTruth && typeof snapshot.sourceOfTruth === "object" ? snapshot.sourceOfTruth : {};
47063
47126
  snapshot.sourceOfTruth = {
@@ -47117,7 +47180,14 @@ ${(0, import_node_path.resolve)(workspace || os17.tmpdir())}`;
47117
47180
  const preferInline = options?.preferInline === true;
47118
47181
  if (preferInline) {
47119
47182
  const cached22 = this.getCachedInlineMesh(meshId);
47120
- if (cached22) return { mesh: cached22, inline: true, source: "inline_cache" };
47183
+ if (cached22) {
47184
+ if (inlineMeshCarriesTransientNodeTruth(inlineMesh)) {
47185
+ const merged = reconcileInlineMeshCache(cached22, inlineMesh);
47186
+ this.inlineMeshCache.set(meshId, sanitizeInlineMesh(merged));
47187
+ return { mesh: merged, inline: true, source: "inline_cache" };
47188
+ }
47189
+ return { mesh: cached22, inline: true, source: "inline_cache" };
47190
+ }
47121
47191
  if (inlineMeshCarriesTransientNodeTruth(inlineMesh)) {
47122
47192
  this.warmInlineMeshCache(meshId, inlineMesh);
47123
47193
  return { mesh: inlineMesh, inline: true, source: "inline_bootstrap" };
@@ -49097,7 +49167,7 @@ ${block}`);
49097
49167
  if (!mesh) return { success: false, error: "Mesh not found" };
49098
49168
  const refreshRequested = args?.refresh === true || args?.forceRefresh === true;
49099
49169
  if (!refreshRequested) {
49100
- const cachedStatus = this.getCachedAggregateMeshStatus(meshId);
49170
+ const cachedStatus = this.getCachedAggregateMeshStatus(meshId, mesh, { requireDirectPeerTruth: args?.requireDirectPeerTruth === true });
49101
49171
  if (cachedStatus) {
49102
49172
  logRepoMeshStatusDebug("return_cached", {
49103
49173
  meshId,
@@ -49132,7 +49202,9 @@ ${block}`);
49132
49202
  peerConfirmedCount: 0,
49133
49203
  unavailableNodeIds: []
49134
49204
  };
49135
- const directTruthSatisfied = meshRecord.source !== "inline_bootstrap" || directTruth.directEvidenceCount > 0;
49205
+ const passivePeerTruthNotAttempted = requireDirectPeerTruth && !refreshRequested && directTruth.directEvidenceCount > 0 && directTruth.peerAttemptedCount === 0;
49206
+ const effectiveDirectTruth = passivePeerTruthNotAttempted ? { ...directTruth, unavailableNodeIds: [] } : directTruth;
49207
+ const directTruthSatisfied = !requireDirectPeerTruth || effectiveDirectTruth.directEvidenceCount > 0 && effectiveDirectTruth.unavailableNodeIds.length === 0;
49136
49208
  if (requireDirectPeerTruth && !directTruthSatisfied) {
49137
49209
  const failureResult = {
49138
49210
  success: false,
@@ -49162,7 +49234,7 @@ ${block}`);
49162
49234
  });
49163
49235
  return failureResult;
49164
49236
  }
49165
- const directTruthUnavailableNodeIds = new Set(directTruth.unavailableNodeIds);
49237
+ const directTruthUnavailableNodeIds = new Set(effectiveDirectTruth.unavailableNodeIds);
49166
49238
  const selectedCoordinatorNodeId = readStringValue(
49167
49239
  mesh.coordinator?.preferredNodeId,
49168
49240
  mesh.nodes?.[0]?.id,
@@ -49355,11 +49427,11 @@ ${block}`);
49355
49427
  directPeerTruth: {
49356
49428
  required: true,
49357
49429
  satisfied: directTruthSatisfied,
49358
- directEvidenceCount: directTruth.directEvidenceCount,
49359
- localConfirmedCount: directTruth.localConfirmedCount,
49360
- peerAttemptedCount: directTruth.peerAttemptedCount,
49361
- peerConfirmedCount: directTruth.peerConfirmedCount,
49362
- unavailableNodeIds: directTruth.unavailableNodeIds
49430
+ directEvidenceCount: effectiveDirectTruth.directEvidenceCount,
49431
+ localConfirmedCount: effectiveDirectTruth.localConfirmedCount,
49432
+ peerAttemptedCount: effectiveDirectTruth.peerAttemptedCount,
49433
+ peerConfirmedCount: effectiveDirectTruth.peerConfirmedCount,
49434
+ unavailableNodeIds: effectiveDirectTruth.unavailableNodeIds
49363
49435
  }
49364
49436
  } : {},
49365
49437
  historicalEvidenceOnly: ["recoveryHints", "ledger.summary", "queue.summary"]