@adhdev/daemon-core 0.9.82-rc.43 → 0.9.82-rc.45

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
@@ -23839,6 +23839,70 @@ function readBooleanValue(...values) {
23839
23839
  }
23840
23840
  return void 0;
23841
23841
  }
23842
+ function summarizeRepoMeshDebugGit(git) {
23843
+ const record = readObjectRecord(git);
23844
+ if (!Object.keys(record).length) return null;
23845
+ const submodules = Array.isArray(record.submodules) ? record.submodules.map((entry) => ({
23846
+ path: readStringValue(entry?.path) ?? null,
23847
+ commit: readStringValue(entry?.commit)?.slice(0, 12) ?? null,
23848
+ dirty: readBooleanValue(entry?.dirty) ?? false,
23849
+ outOfSync: readBooleanValue(entry?.outOfSync, entry?.out_of_sync) ?? false
23850
+ })) : [];
23851
+ return {
23852
+ isGitRepo: readBooleanValue(record.isGitRepo),
23853
+ workspace: readStringValue(record.workspace) ?? null,
23854
+ repoRoot: readStringValue(record.repoRoot, record.repo_root) ?? null,
23855
+ branch: readStringValue(record.branch) ?? null,
23856
+ upstream: readStringValue(record.upstream) ?? null,
23857
+ upstreamStatus: readStringValue(record.upstreamStatus, record.upstream_status) ?? null,
23858
+ headCommit: readStringValue(record.headCommit, record.head_commit)?.slice(0, 12) ?? null,
23859
+ ahead: readNumberValue(record.ahead) ?? null,
23860
+ behind: readNumberValue(record.behind) ?? null,
23861
+ dirtyCounts: {
23862
+ staged: readNumberValue(record.staged) ?? 0,
23863
+ modified: readNumberValue(record.modified) ?? 0,
23864
+ untracked: readNumberValue(record.untracked) ?? 0,
23865
+ deleted: readNumberValue(record.deleted) ?? 0,
23866
+ renamed: readNumberValue(record.renamed) ?? 0
23867
+ },
23868
+ lastCheckedAt: readNumberValue(record.lastCheckedAt, record.last_checked_at) ?? null,
23869
+ submoduleCount: submodules.length,
23870
+ submodules
23871
+ };
23872
+ }
23873
+ function summarizeRepoMeshStatusDebug(status) {
23874
+ const nodes = Array.isArray(status?.nodes) ? status.nodes : [];
23875
+ return {
23876
+ success: status?.success,
23877
+ meshId: readStringValue(status?.meshId, status?.mesh_id) ?? null,
23878
+ refreshedAt: readStringValue(status?.refreshedAt, status?.refreshed_at) ?? null,
23879
+ sourceOfTruth: status?.sourceOfTruth ?? null,
23880
+ nodeCount: nodes.length,
23881
+ nodes: nodes.map((node) => ({
23882
+ nodeId: readStringValue(node?.nodeId, node?.id) ?? null,
23883
+ daemonId: readStringValue(node?.daemonId, node?.daemon_id) ?? null,
23884
+ workspace: readStringValue(node?.workspace, node?.git?.workspace) ?? null,
23885
+ health: readStringValue(node?.health) ?? null,
23886
+ machineStatus: readStringValue(node?.machineStatus, node?.machine_status) ?? null,
23887
+ connection: node?.connection && typeof node.connection === "object" ? {
23888
+ state: readStringValue(node.connection.state) ?? null,
23889
+ transport: readStringValue(node.connection.transport) ?? null,
23890
+ source: readStringValue(node.connection.source) ?? null,
23891
+ reported: readBooleanValue(node.connection.reported) ?? null
23892
+ } : null,
23893
+ gitProbePending: node?.gitProbePending === true,
23894
+ launchReady: node?.launchReady === true,
23895
+ git: summarizeRepoMeshDebugGit(node?.git)
23896
+ }))
23897
+ };
23898
+ }
23899
+ function logRepoMeshStatusDebug(event, fields) {
23900
+ try {
23901
+ LOG.info("MeshStatusDebug", `[RepoMeshStatusDebug] ${JSON.stringify({ event, ...fields })}`);
23902
+ } catch {
23903
+ LOG.info("MeshStatusDebug", `[RepoMeshStatusDebug] ${event}`);
23904
+ }
23905
+ }
23842
23906
  function joinRepoPath(root, relativePath) {
23843
23907
  const normalizedRoot = typeof root === "string" ? root.trim().replace(/[\\/]+$/, "") : "";
23844
23908
  const normalizedPath = typeof relativePath === "string" ? relativePath.trim() : "";
@@ -23907,8 +23971,12 @@ function buildInlineMeshTransitGitStatus(node) {
23907
23971
  const probeGitResult = readObjectRecord(probeGit.result);
23908
23972
  const probeDirectStatus = readObjectRecord(probeGit.status);
23909
23973
  const probeNestedStatus = readObjectRecord(probeGitResult.status);
23910
- const status = Object.keys(directStatus).length ? directStatus : Object.keys(nestedStatus).length ? nestedStatus : Object.keys(probeDirectStatus).length ? probeDirectStatus : Object.keys(probeNestedStatus).length ? probeNestedStatus : {};
23911
- 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;
23912
23980
  }
23913
23981
  function recordInlineMeshDirectGitTruth(node, git, source) {
23914
23982
  if (!node || typeof node !== "object" || Array.isArray(node)) return;
@@ -24777,10 +24845,69 @@ var DaemonCommandRouter = class {
24777
24845
  if (typeof structuredClone === "function") return structuredClone(value);
24778
24846
  return JSON.parse(JSON.stringify(value));
24779
24847
  }
24780
- 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) {
24781
24907
  const cached = this.aggregateMeshStatusCache.get(meshId);
24782
24908
  if (!cached?.snapshot || cached.snapshot.success !== true || !Array.isArray(cached.snapshot.nodes)) return null;
24783
- const snapshot = this.cloneJsonValue(cached.snapshot);
24909
+ let snapshot = this.cloneJsonValue(cached.snapshot);
24910
+ snapshot = this.hydrateCachedAggregateMeshStatusFromInline(snapshot, mesh, options);
24784
24911
  const ageMs = Math.max(0, Date.now() - cached.builtAt);
24785
24912
  const sourceOfTruth = snapshot.sourceOfTruth && typeof snapshot.sourceOfTruth === "object" ? snapshot.sourceOfTruth : {};
24786
24913
  snapshot.sourceOfTruth = {
@@ -24840,7 +24967,14 @@ var DaemonCommandRouter = class {
24840
24967
  const preferInline = options?.preferInline === true;
24841
24968
  if (preferInline) {
24842
24969
  const cached2 = this.getCachedInlineMesh(meshId);
24843
- 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
+ }
24844
24978
  if (inlineMeshCarriesTransientNodeTruth(inlineMesh)) {
24845
24979
  this.warmInlineMeshCache(meshId, inlineMesh);
24846
24980
  return { mesh: inlineMesh, inline: true, source: "inline_bootstrap" };
@@ -26820,8 +26954,16 @@ ${block}`);
26820
26954
  if (!mesh) return { success: false, error: "Mesh not found" };
26821
26955
  const refreshRequested = args?.refresh === true || args?.forceRefresh === true;
26822
26956
  if (!refreshRequested) {
26823
- const cachedStatus = this.getCachedAggregateMeshStatus(meshId);
26824
- if (cachedStatus) return cachedStatus;
26957
+ const cachedStatus = this.getCachedAggregateMeshStatus(meshId, mesh, { requireDirectPeerTruth: args?.requireDirectPeerTruth === true });
26958
+ if (cachedStatus) {
26959
+ logRepoMeshStatusDebug("return_cached", {
26960
+ meshId,
26961
+ command: "mesh_status",
26962
+ refreshRequested,
26963
+ summary: summarizeRepoMeshStatusDebug(cachedStatus)
26964
+ });
26965
+ return cachedStatus;
26966
+ }
26825
26967
  }
26826
26968
  const refreshReason = refreshRequested ? "explicit_refresh" : "cold_cache_miss";
26827
26969
  const { getMeshQueueStats: getMeshQueueStats2, getQueue: getQueue2 } = await Promise.resolve().then(() => (init_mesh_work_queue(), mesh_work_queue_exports));
@@ -26847,9 +26989,9 @@ ${block}`);
26847
26989
  peerConfirmedCount: 0,
26848
26990
  unavailableNodeIds: []
26849
26991
  };
26850
- const directTruthSatisfied = meshRecord.source !== "inline_bootstrap" || directTruth.directEvidenceCount > 0;
26992
+ const directTruthSatisfied = !requireDirectPeerTruth || directTruth.directEvidenceCount > 0 && directTruth.unavailableNodeIds.length === 0;
26851
26993
  if (requireDirectPeerTruth && !directTruthSatisfied) {
26852
- return {
26994
+ const failureResult = {
26853
26995
  success: false,
26854
26996
  code: "mesh_direct_peer_truth_unavailable",
26855
26997
  error: "Selected coordinator could not confirm direct mesh truth yet. Bootstrap inventory stays unavailable until direct mesh_status probes succeed.",
@@ -26868,6 +27010,14 @@ ${block}`);
26868
27010
  }
26869
27011
  }
26870
27012
  };
27013
+ logRepoMeshStatusDebug("direct_truth_unavailable", {
27014
+ meshId,
27015
+ command: "mesh_status",
27016
+ refreshRequested,
27017
+ meshSource: meshRecord.source,
27018
+ directTruth
27019
+ });
27020
+ return failureResult;
26871
27021
  }
26872
27022
  const directTruthUnavailableNodeIds = new Set(directTruth.unavailableNodeIds);
26873
27023
  const selectedCoordinatorNodeId = readStringValue(
@@ -27075,7 +27225,17 @@ ${block}`);
27075
27225
  queue: { tasks: queue, summary: queueSummary },
27076
27226
  ledger: { entries: ledgerEntries, summary: ledgerSummary }
27077
27227
  };
27078
- return this.rememberAggregateMeshStatus(meshId, statusResult, refreshReason);
27228
+ const rememberedStatus = this.rememberAggregateMeshStatus(meshId, statusResult, refreshReason);
27229
+ logRepoMeshStatusDebug("return_live", {
27230
+ meshId,
27231
+ command: "mesh_status",
27232
+ refreshRequested,
27233
+ refreshReason,
27234
+ meshSource: meshRecord.source,
27235
+ directTruth,
27236
+ summary: summarizeRepoMeshStatusDebug(rememberedStatus)
27237
+ });
27238
+ return rememberedStatus;
27079
27239
  } catch (e) {
27080
27240
  return { success: false, error: e.message };
27081
27241
  }