adhdev 0.9.82-rc.46 → 0.9.82-rc.47

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
@@ -45772,6 +45772,21 @@ function normalizeInlineMeshGitStatus(status, node, options) {
45772
45772
  ...submodules ? { submodules } : {}
45773
45773
  };
45774
45774
  }
45775
+ function scoreInlineMeshGitStatus(git) {
45776
+ if (!git) return Number.NEGATIVE_INFINITY;
45777
+ let score = 0;
45778
+ if (readBooleanValue(git.isGitRepo) === true) score += 50;
45779
+ if (readBooleanValue(git.isGitRepo) === false) score -= 10;
45780
+ if (readStringValue(git.branch)) score += 20;
45781
+ if (readStringValue(git.headCommit)) score += 20;
45782
+ if (readStringValue(git.upstream)) score += 10;
45783
+ if (readStringValue(git.upstreamStatus)) score += 5;
45784
+ if (readNumberValue(git.ahead) !== void 0) score += 2;
45785
+ if (readNumberValue(git.behind) !== void 0) score += 2;
45786
+ if (Array.isArray(git.submodules) && git.submodules.length > 0) score += 4 + git.submodules.length;
45787
+ if (readStringValue(git.error)) score -= 20;
45788
+ return score;
45789
+ }
45775
45790
  function buildInlineMeshTransitGitStatus(node) {
45776
45791
  const rawGit = readObjectRecord(node?.lastGit ?? node?.last_git);
45777
45792
  const gitResult = readObjectRecord(rawGit.result);
@@ -45783,11 +45798,36 @@ function buildInlineMeshTransitGitStatus(node) {
45783
45798
  const probeDirectStatus = readObjectRecord(probeGit.status);
45784
45799
  const probeNestedStatus = readObjectRecord(probeGitResult.status);
45785
45800
  const candidates = [directStatus, nestedStatus, probeDirectStatus, probeNestedStatus];
45801
+ let best = null;
45786
45802
  for (const status of candidates) {
45787
45803
  const normalized = normalizeInlineMeshGitStatus(status, node, { lastCheckedAt: Date.now() });
45788
- if (normalized) return normalized;
45789
- }
45790
- return void 0;
45804
+ if (!normalized) continue;
45805
+ const score = scoreInlineMeshGitStatus(normalized);
45806
+ if (!best || score > best.score) best = { git: normalized, score };
45807
+ }
45808
+ return best?.git;
45809
+ }
45810
+ function shouldRefreshStalePendingAggregate(snapshot, options) {
45811
+ if (options?.requireDirectPeerTruth !== true || !Array.isArray(snapshot?.nodes)) return false;
45812
+ return snapshot.nodes.some((node) => {
45813
+ if (node?.gitProbePending !== true) return false;
45814
+ const git = readObjectRecord(node?.git);
45815
+ return !readBooleanValue(git.isGitRepo) && !readStringValue(git.branch, git.headCommit, git.upstream);
45816
+ });
45817
+ }
45818
+ function buildLivePeerGitConnection(connection, timestamp2 = (/* @__PURE__ */ new Date()).toISOString()) {
45819
+ const source = readStringValue(connection.source);
45820
+ const transport = readStringValue(connection.transport);
45821
+ return {
45822
+ ...connection,
45823
+ perspective: readStringValue(connection.perspective) ?? "selected_coordinator",
45824
+ source: source && source !== "not_reported" ? source : "mesh_peer_status",
45825
+ state: "connected",
45826
+ transport: transport && transport !== "unknown" ? transport : "direct",
45827
+ reported: true,
45828
+ reason: "Live peer git snapshot reported by the selected coordinator.",
45829
+ lastStateChangeAt: readStringValue(connection.lastStateChangeAt) ?? timestamp2
45830
+ };
45791
45831
  }
45792
45832
  function recordInlineMeshDirectGitTruth(node, git, source) {
45793
45833
  if (!node || typeof node !== "object" || Array.isArray(node)) return;
@@ -46718,8 +46758,16 @@ var init_router = __esm({
46718
46758
  const nextStatus = { ...statusNode };
46719
46759
  nextStatus.git = liveGit;
46720
46760
  nextStatus.health = deriveMeshNodeHealthFromGit(liveGit);
46761
+ nextStatus.launchReady = readBooleanValue(nextStatus.launchReady) ?? true;
46762
+ const connection = readObjectRecord(nextStatus.connection);
46763
+ const connectionState = readStringValue(connection.state);
46764
+ const connectionReported = readBooleanValue(connection.reported) ?? false;
46765
+ if (!connectionReported || connectionState === "unknown") {
46766
+ nextStatus.connection = buildLivePeerGitConnection(connection);
46767
+ }
46721
46768
  delete nextStatus.gitProbePending;
46722
- if (readStringValue(nextStatus.error) === "waiting for live peer git snapshot") delete nextStatus.error;
46769
+ const error48 = readStringValue(nextStatus.error);
46770
+ if (error48 && /pending_git|git probe|live peer git snapshot|no peer git snapshot/i.test(error48)) delete nextStatus.error;
46723
46771
  if (!readStringValue(nextStatus.machineStatus)) nextStatus.machineStatus = "online";
46724
46772
  if (nodeId) unavailableNodeIds.delete(nodeId);
46725
46773
  changed = true;
@@ -46756,6 +46804,7 @@ var init_router = __esm({
46756
46804
  if (!cached2?.snapshot || cached2.snapshot.success !== true || !Array.isArray(cached2.snapshot.nodes)) return null;
46757
46805
  let snapshot = this.cloneJsonValue(cached2.snapshot);
46758
46806
  snapshot = this.hydrateCachedAggregateMeshStatusFromInline(snapshot, mesh, options);
46807
+ if (shouldRefreshStalePendingAggregate(snapshot, options)) return null;
46759
46808
  const ageMs = Math.max(0, Date.now() - cached2.builtAt);
46760
46809
  const sourceOfTruth = snapshot.sourceOfTruth && typeof snapshot.sourceOfTruth === "object" ? snapshot.sourceOfTruth : {};
46761
46810
  snapshot.sourceOfTruth = {
@@ -48801,6 +48850,7 @@ ${block}`);
48801
48850
  const mesh = meshRecord?.mesh;
48802
48851
  if (!mesh) return { success: false, error: "Mesh not found" };
48803
48852
  const refreshRequested = args?.refresh === true || args?.forceRefresh === true;
48853
+ const hadAggregateCache = this.aggregateMeshStatusCache.has(meshId);
48804
48854
  if (!refreshRequested) {
48805
48855
  const cachedStatus = this.getCachedAggregateMeshStatus(meshId, mesh, { requireDirectPeerTruth: args?.requireDirectPeerTruth === true });
48806
48856
  if (cachedStatus) {
@@ -48813,7 +48863,7 @@ ${block}`);
48813
48863
  return cachedStatus;
48814
48864
  }
48815
48865
  }
48816
- const refreshReason = refreshRequested ? "explicit_refresh" : "cold_cache_miss";
48866
+ const refreshReason = refreshRequested ? "explicit_refresh" : hadAggregateCache ? "stale_pending_cache_refresh" : "cold_cache_miss";
48817
48867
  const { getMeshQueueStats: getMeshQueueStats2, getQueue: getQueue2 } = await Promise.resolve().then(() => (init_mesh_work_queue(), mesh_work_queue_exports));
48818
48868
  const queue = getQueue2(meshId);
48819
48869
  const queueSummary = getMeshQueueStats2(meshId);
@@ -48964,6 +49014,12 @@ ${block}`);
48964
49014
  if (inlineTransitGit) {
48965
49015
  status.git = inlineTransitGit;
48966
49016
  status.health = inlineTransitGit.isGitRepo ? deriveMeshNodeHealthFromGit(inlineTransitGit) : "degraded";
49017
+ const connection = readObjectRecord(status.connection);
49018
+ const connectionState = readStringValue(connection.state);
49019
+ const connectionReported = readBooleanValue(connection.reported) ?? false;
49020
+ if (!connectionReported || connectionState === "unknown") {
49021
+ status.connection = buildLivePeerGitConnection(connection, refreshedAt);
49022
+ }
48967
49023
  remoteProbeApplied = true;
48968
49024
  } else if (!isSelfNode && daemonId && this.deps.dispatchMeshCommand && !directTruthUnavailableNodeIds.has(nodeId)) {
48969
49025
  try {
@@ -48976,6 +49032,12 @@ ${block}`);
48976
49032
  if (remoteGit) {
48977
49033
  status.git = remoteGit;
48978
49034
  status.health = remoteGit.isGitRepo ? deriveMeshNodeHealthFromGit(remoteGit) : "degraded";
49035
+ const connection = readObjectRecord(status.connection);
49036
+ const connectionState = readStringValue(connection.state);
49037
+ const connectionReported = readBooleanValue(connection.reported) ?? false;
49038
+ if (!connectionReported || connectionState === "unknown") {
49039
+ status.connection = buildLivePeerGitConnection(connection, refreshedAt);
49040
+ }
48979
49041
  recordInlineMeshDirectGitTruth(node, remoteGit, "selected_coordinator_mesh_p2p_git");
48980
49042
  remoteProbeApplied = true;
48981
49043
  }
@@ -48994,6 +49056,12 @@ ${block}`);
48994
49056
  if (remoteGit) {
48995
49057
  status.git = remoteGit;
48996
49058
  status.health = remoteGit.isGitRepo ? deriveMeshNodeHealthFromGit(remoteGit) : "degraded";
49059
+ const connection = readObjectRecord(status.connection);
49060
+ const connectionState = readStringValue(connection.state);
49061
+ const connectionReported = readBooleanValue(connection.reported) ?? false;
49062
+ if (!connectionReported || connectionState === "unknown") {
49063
+ status.connection = buildLivePeerGitConnection(connection, refreshedAt);
49064
+ }
48997
49065
  recordInlineMeshDirectGitTruth(node, remoteGit, "selected_coordinator_mesh_p2p_git");
48998
49066
  remoteProbeApplied = true;
48999
49067
  }
@@ -68138,7 +68206,7 @@ var init_adhdev_daemon = __esm({
68138
68206
  init_version();
68139
68207
  init_src();
68140
68208
  init_runtime_defaults();
68141
- pkgVersion = resolvePackageVersion({ injectedVersion: "0.9.82-rc.46" });
68209
+ pkgVersion = resolvePackageVersion({ injectedVersion: "0.9.82-rc.47" });
68142
68210
  AdhdevDaemon = class _AdhdevDaemon {
68143
68211
  localHttpServer = null;
68144
68212
  localWss = null;