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

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
@@ -24194,6 +24194,21 @@ function normalizeInlineMeshGitStatus(status, node, options) {
24194
24194
  ...submodules ? { submodules } : {}
24195
24195
  };
24196
24196
  }
24197
+ function scoreInlineMeshGitStatus(git) {
24198
+ if (!git) return Number.NEGATIVE_INFINITY;
24199
+ let score = 0;
24200
+ if (readBooleanValue(git.isGitRepo) === true) score += 50;
24201
+ if (readBooleanValue(git.isGitRepo) === false) score -= 10;
24202
+ if (readStringValue(git.branch)) score += 20;
24203
+ if (readStringValue(git.headCommit)) score += 20;
24204
+ if (readStringValue(git.upstream)) score += 10;
24205
+ if (readStringValue(git.upstreamStatus)) score += 5;
24206
+ if (readNumberValue(git.ahead) !== void 0) score += 2;
24207
+ if (readNumberValue(git.behind) !== void 0) score += 2;
24208
+ if (Array.isArray(git.submodules) && git.submodules.length > 0) score += 4 + git.submodules.length;
24209
+ if (readStringValue(git.error)) score -= 20;
24210
+ return score;
24211
+ }
24197
24212
  function buildInlineMeshTransitGitStatus(node) {
24198
24213
  const rawGit = readObjectRecord(node?.lastGit ?? node?.last_git);
24199
24214
  const gitResult = readObjectRecord(rawGit.result);
@@ -24205,11 +24220,36 @@ function buildInlineMeshTransitGitStatus(node) {
24205
24220
  const probeDirectStatus = readObjectRecord(probeGit.status);
24206
24221
  const probeNestedStatus = readObjectRecord(probeGitResult.status);
24207
24222
  const candidates = [directStatus, nestedStatus, probeDirectStatus, probeNestedStatus];
24223
+ let best = null;
24208
24224
  for (const status of candidates) {
24209
24225
  const normalized = normalizeInlineMeshGitStatus(status, node, { lastCheckedAt: Date.now() });
24210
- if (normalized) return normalized;
24211
- }
24212
- return void 0;
24226
+ if (!normalized) continue;
24227
+ const score = scoreInlineMeshGitStatus(normalized);
24228
+ if (!best || score > best.score) best = { git: normalized, score };
24229
+ }
24230
+ return best?.git;
24231
+ }
24232
+ function shouldRefreshStalePendingAggregate(snapshot, options) {
24233
+ if (options?.requireDirectPeerTruth !== true || !Array.isArray(snapshot?.nodes)) return false;
24234
+ return snapshot.nodes.some((node) => {
24235
+ if (node?.gitProbePending !== true) return false;
24236
+ const git = readObjectRecord(node?.git);
24237
+ return !readBooleanValue(git.isGitRepo) && !readStringValue(git.branch, git.headCommit, git.upstream);
24238
+ });
24239
+ }
24240
+ function buildLivePeerGitConnection(connection, timestamp = (/* @__PURE__ */ new Date()).toISOString()) {
24241
+ const source = readStringValue(connection.source);
24242
+ const transport = readStringValue(connection.transport);
24243
+ return {
24244
+ ...connection,
24245
+ perspective: readStringValue(connection.perspective) ?? "selected_coordinator",
24246
+ source: source && source !== "not_reported" ? source : "mesh_peer_status",
24247
+ state: "connected",
24248
+ transport: transport && transport !== "unknown" ? transport : "direct",
24249
+ reported: true,
24250
+ reason: "Live peer git snapshot reported by the selected coordinator.",
24251
+ lastStateChangeAt: readStringValue(connection.lastStateChangeAt) ?? timestamp
24252
+ };
24213
24253
  }
24214
24254
  function recordInlineMeshDirectGitTruth(node, git, source) {
24215
24255
  if (!node || typeof node !== "object" || Array.isArray(node)) return;
@@ -25103,8 +25143,16 @@ var DaemonCommandRouter = class {
25103
25143
  const nextStatus = { ...statusNode };
25104
25144
  nextStatus.git = liveGit;
25105
25145
  nextStatus.health = deriveMeshNodeHealthFromGit(liveGit);
25146
+ nextStatus.launchReady = readBooleanValue(nextStatus.launchReady) ?? true;
25147
+ const connection = readObjectRecord(nextStatus.connection);
25148
+ const connectionState = readStringValue(connection.state);
25149
+ const connectionReported = readBooleanValue(connection.reported) ?? false;
25150
+ if (!connectionReported || connectionState === "unknown") {
25151
+ nextStatus.connection = buildLivePeerGitConnection(connection);
25152
+ }
25106
25153
  delete nextStatus.gitProbePending;
25107
- if (readStringValue(nextStatus.error) === "waiting for live peer git snapshot") delete nextStatus.error;
25154
+ const error = readStringValue(nextStatus.error);
25155
+ if (error && /pending_git|git probe|live peer git snapshot|no peer git snapshot/i.test(error)) delete nextStatus.error;
25108
25156
  if (!readStringValue(nextStatus.machineStatus)) nextStatus.machineStatus = "online";
25109
25157
  if (nodeId) unavailableNodeIds.delete(nodeId);
25110
25158
  changed = true;
@@ -25141,6 +25189,7 @@ var DaemonCommandRouter = class {
25141
25189
  if (!cached?.snapshot || cached.snapshot.success !== true || !Array.isArray(cached.snapshot.nodes)) return null;
25142
25190
  let snapshot = this.cloneJsonValue(cached.snapshot);
25143
25191
  snapshot = this.hydrateCachedAggregateMeshStatusFromInline(snapshot, mesh, options);
25192
+ if (shouldRefreshStalePendingAggregate(snapshot, options)) return null;
25144
25193
  const ageMs = Math.max(0, Date.now() - cached.builtAt);
25145
25194
  const sourceOfTruth = snapshot.sourceOfTruth && typeof snapshot.sourceOfTruth === "object" ? snapshot.sourceOfTruth : {};
25146
25195
  snapshot.sourceOfTruth = {
@@ -27186,6 +27235,7 @@ ${block}`);
27186
27235
  const mesh = meshRecord?.mesh;
27187
27236
  if (!mesh) return { success: false, error: "Mesh not found" };
27188
27237
  const refreshRequested = args?.refresh === true || args?.forceRefresh === true;
27238
+ const hadAggregateCache = this.aggregateMeshStatusCache.has(meshId);
27189
27239
  if (!refreshRequested) {
27190
27240
  const cachedStatus = this.getCachedAggregateMeshStatus(meshId, mesh, { requireDirectPeerTruth: args?.requireDirectPeerTruth === true });
27191
27241
  if (cachedStatus) {
@@ -27198,7 +27248,7 @@ ${block}`);
27198
27248
  return cachedStatus;
27199
27249
  }
27200
27250
  }
27201
- const refreshReason = refreshRequested ? "explicit_refresh" : "cold_cache_miss";
27251
+ const refreshReason = refreshRequested ? "explicit_refresh" : hadAggregateCache ? "stale_pending_cache_refresh" : "cold_cache_miss";
27202
27252
  const { getMeshQueueStats: getMeshQueueStats2, getQueue: getQueue2 } = await Promise.resolve().then(() => (init_mesh_work_queue(), mesh_work_queue_exports));
27203
27253
  const queue = getQueue2(meshId);
27204
27254
  const queueSummary = getMeshQueueStats2(meshId);
@@ -27349,6 +27399,12 @@ ${block}`);
27349
27399
  if (inlineTransitGit) {
27350
27400
  status.git = inlineTransitGit;
27351
27401
  status.health = inlineTransitGit.isGitRepo ? deriveMeshNodeHealthFromGit(inlineTransitGit) : "degraded";
27402
+ const connection = readObjectRecord(status.connection);
27403
+ const connectionState = readStringValue(connection.state);
27404
+ const connectionReported = readBooleanValue(connection.reported) ?? false;
27405
+ if (!connectionReported || connectionState === "unknown") {
27406
+ status.connection = buildLivePeerGitConnection(connection, refreshedAt);
27407
+ }
27352
27408
  remoteProbeApplied = true;
27353
27409
  } else if (!isSelfNode && daemonId && this.deps.dispatchMeshCommand && !directTruthUnavailableNodeIds.has(nodeId)) {
27354
27410
  try {
@@ -27361,6 +27417,12 @@ ${block}`);
27361
27417
  if (remoteGit) {
27362
27418
  status.git = remoteGit;
27363
27419
  status.health = remoteGit.isGitRepo ? deriveMeshNodeHealthFromGit(remoteGit) : "degraded";
27420
+ const connection = readObjectRecord(status.connection);
27421
+ const connectionState = readStringValue(connection.state);
27422
+ const connectionReported = readBooleanValue(connection.reported) ?? false;
27423
+ if (!connectionReported || connectionState === "unknown") {
27424
+ status.connection = buildLivePeerGitConnection(connection, refreshedAt);
27425
+ }
27364
27426
  recordInlineMeshDirectGitTruth(node, remoteGit, "selected_coordinator_mesh_p2p_git");
27365
27427
  remoteProbeApplied = true;
27366
27428
  }
@@ -27379,6 +27441,12 @@ ${block}`);
27379
27441
  if (remoteGit) {
27380
27442
  status.git = remoteGit;
27381
27443
  status.health = remoteGit.isGitRepo ? deriveMeshNodeHealthFromGit(remoteGit) : "degraded";
27444
+ const connection = readObjectRecord(status.connection);
27445
+ const connectionState = readStringValue(connection.state);
27446
+ const connectionReported = readBooleanValue(connection.reported) ?? false;
27447
+ if (!connectionReported || connectionState === "unknown") {
27448
+ status.connection = buildLivePeerGitConnection(connection, refreshedAt);
27449
+ }
27382
27450
  recordInlineMeshDirectGitTruth(node, remoteGit, "selected_coordinator_mesh_p2p_git");
27383
27451
  remoteProbeApplied = true;
27384
27452
  }