@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.
@@ -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
@@ -24072,6 +24072,70 @@ function readBooleanValue(...values) {
24072
24072
  }
24073
24073
  return void 0;
24074
24074
  }
24075
+ function summarizeRepoMeshDebugGit(git) {
24076
+ const record = readObjectRecord(git);
24077
+ if (!Object.keys(record).length) return null;
24078
+ const submodules = Array.isArray(record.submodules) ? record.submodules.map((entry) => ({
24079
+ path: readStringValue(entry?.path) ?? null,
24080
+ commit: readStringValue(entry?.commit)?.slice(0, 12) ?? null,
24081
+ dirty: readBooleanValue(entry?.dirty) ?? false,
24082
+ outOfSync: readBooleanValue(entry?.outOfSync, entry?.out_of_sync) ?? false
24083
+ })) : [];
24084
+ return {
24085
+ isGitRepo: readBooleanValue(record.isGitRepo),
24086
+ workspace: readStringValue(record.workspace) ?? null,
24087
+ repoRoot: readStringValue(record.repoRoot, record.repo_root) ?? null,
24088
+ branch: readStringValue(record.branch) ?? null,
24089
+ upstream: readStringValue(record.upstream) ?? null,
24090
+ upstreamStatus: readStringValue(record.upstreamStatus, record.upstream_status) ?? null,
24091
+ headCommit: readStringValue(record.headCommit, record.head_commit)?.slice(0, 12) ?? null,
24092
+ ahead: readNumberValue(record.ahead) ?? null,
24093
+ behind: readNumberValue(record.behind) ?? null,
24094
+ dirtyCounts: {
24095
+ staged: readNumberValue(record.staged) ?? 0,
24096
+ modified: readNumberValue(record.modified) ?? 0,
24097
+ untracked: readNumberValue(record.untracked) ?? 0,
24098
+ deleted: readNumberValue(record.deleted) ?? 0,
24099
+ renamed: readNumberValue(record.renamed) ?? 0
24100
+ },
24101
+ lastCheckedAt: readNumberValue(record.lastCheckedAt, record.last_checked_at) ?? null,
24102
+ submoduleCount: submodules.length,
24103
+ submodules
24104
+ };
24105
+ }
24106
+ function summarizeRepoMeshStatusDebug(status) {
24107
+ const nodes = Array.isArray(status?.nodes) ? status.nodes : [];
24108
+ return {
24109
+ success: status?.success,
24110
+ meshId: readStringValue(status?.meshId, status?.mesh_id) ?? null,
24111
+ refreshedAt: readStringValue(status?.refreshedAt, status?.refreshed_at) ?? null,
24112
+ sourceOfTruth: status?.sourceOfTruth ?? null,
24113
+ nodeCount: nodes.length,
24114
+ nodes: nodes.map((node) => ({
24115
+ nodeId: readStringValue(node?.nodeId, node?.id) ?? null,
24116
+ daemonId: readStringValue(node?.daemonId, node?.daemon_id) ?? null,
24117
+ workspace: readStringValue(node?.workspace, node?.git?.workspace) ?? null,
24118
+ health: readStringValue(node?.health) ?? null,
24119
+ machineStatus: readStringValue(node?.machineStatus, node?.machine_status) ?? null,
24120
+ connection: node?.connection && typeof node.connection === "object" ? {
24121
+ state: readStringValue(node.connection.state) ?? null,
24122
+ transport: readStringValue(node.connection.transport) ?? null,
24123
+ source: readStringValue(node.connection.source) ?? null,
24124
+ reported: readBooleanValue(node.connection.reported) ?? null
24125
+ } : null,
24126
+ gitProbePending: node?.gitProbePending === true,
24127
+ launchReady: node?.launchReady === true,
24128
+ git: summarizeRepoMeshDebugGit(node?.git)
24129
+ }))
24130
+ };
24131
+ }
24132
+ function logRepoMeshStatusDebug(event, fields) {
24133
+ try {
24134
+ LOG.info("MeshStatusDebug", `[RepoMeshStatusDebug] ${JSON.stringify({ event, ...fields })}`);
24135
+ } catch {
24136
+ LOG.info("MeshStatusDebug", `[RepoMeshStatusDebug] ${event}`);
24137
+ }
24138
+ }
24075
24139
  function joinRepoPath(root, relativePath) {
24076
24140
  const normalizedRoot = typeof root === "string" ? root.trim().replace(/[\\/]+$/, "") : "";
24077
24141
  const normalizedPath = typeof relativePath === "string" ? relativePath.trim() : "";
@@ -24140,8 +24204,12 @@ function buildInlineMeshTransitGitStatus(node) {
24140
24204
  const probeGitResult = readObjectRecord(probeGit.result);
24141
24205
  const probeDirectStatus = readObjectRecord(probeGit.status);
24142
24206
  const probeNestedStatus = readObjectRecord(probeGitResult.status);
24143
- const status = Object.keys(directStatus).length ? directStatus : Object.keys(nestedStatus).length ? nestedStatus : Object.keys(probeDirectStatus).length ? probeDirectStatus : Object.keys(probeNestedStatus).length ? probeNestedStatus : {};
24144
- 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;
24145
24213
  }
24146
24214
  function recordInlineMeshDirectGitTruth(node, git, source) {
24147
24215
  if (!node || typeof node !== "object" || Array.isArray(node)) return;
@@ -25010,10 +25078,69 @@ var DaemonCommandRouter = class {
25010
25078
  if (typeof structuredClone === "function") return structuredClone(value);
25011
25079
  return JSON.parse(JSON.stringify(value));
25012
25080
  }
25013
- 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) {
25014
25140
  const cached = this.aggregateMeshStatusCache.get(meshId);
25015
25141
  if (!cached?.snapshot || cached.snapshot.success !== true || !Array.isArray(cached.snapshot.nodes)) return null;
25016
- const snapshot = this.cloneJsonValue(cached.snapshot);
25142
+ let snapshot = this.cloneJsonValue(cached.snapshot);
25143
+ snapshot = this.hydrateCachedAggregateMeshStatusFromInline(snapshot, mesh, options);
25017
25144
  const ageMs = Math.max(0, Date.now() - cached.builtAt);
25018
25145
  const sourceOfTruth = snapshot.sourceOfTruth && typeof snapshot.sourceOfTruth === "object" ? snapshot.sourceOfTruth : {};
25019
25146
  snapshot.sourceOfTruth = {
@@ -25073,7 +25200,14 @@ var DaemonCommandRouter = class {
25073
25200
  const preferInline = options?.preferInline === true;
25074
25201
  if (preferInline) {
25075
25202
  const cached2 = this.getCachedInlineMesh(meshId);
25076
- 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
+ }
25077
25211
  if (inlineMeshCarriesTransientNodeTruth(inlineMesh)) {
25078
25212
  this.warmInlineMeshCache(meshId, inlineMesh);
25079
25213
  return { mesh: inlineMesh, inline: true, source: "inline_bootstrap" };
@@ -27053,8 +27187,16 @@ ${block}`);
27053
27187
  if (!mesh) return { success: false, error: "Mesh not found" };
27054
27188
  const refreshRequested = args?.refresh === true || args?.forceRefresh === true;
27055
27189
  if (!refreshRequested) {
27056
- const cachedStatus = this.getCachedAggregateMeshStatus(meshId);
27057
- if (cachedStatus) return cachedStatus;
27190
+ const cachedStatus = this.getCachedAggregateMeshStatus(meshId, mesh, { requireDirectPeerTruth: args?.requireDirectPeerTruth === true });
27191
+ if (cachedStatus) {
27192
+ logRepoMeshStatusDebug("return_cached", {
27193
+ meshId,
27194
+ command: "mesh_status",
27195
+ refreshRequested,
27196
+ summary: summarizeRepoMeshStatusDebug(cachedStatus)
27197
+ });
27198
+ return cachedStatus;
27199
+ }
27058
27200
  }
27059
27201
  const refreshReason = refreshRequested ? "explicit_refresh" : "cold_cache_miss";
27060
27202
  const { getMeshQueueStats: getMeshQueueStats2, getQueue: getQueue2 } = await Promise.resolve().then(() => (init_mesh_work_queue(), mesh_work_queue_exports));
@@ -27080,9 +27222,9 @@ ${block}`);
27080
27222
  peerConfirmedCount: 0,
27081
27223
  unavailableNodeIds: []
27082
27224
  };
27083
- const directTruthSatisfied = meshRecord.source !== "inline_bootstrap" || directTruth.directEvidenceCount > 0;
27225
+ const directTruthSatisfied = !requireDirectPeerTruth || directTruth.directEvidenceCount > 0 && directTruth.unavailableNodeIds.length === 0;
27084
27226
  if (requireDirectPeerTruth && !directTruthSatisfied) {
27085
- return {
27227
+ const failureResult = {
27086
27228
  success: false,
27087
27229
  code: "mesh_direct_peer_truth_unavailable",
27088
27230
  error: "Selected coordinator could not confirm direct mesh truth yet. Bootstrap inventory stays unavailable until direct mesh_status probes succeed.",
@@ -27101,6 +27243,14 @@ ${block}`);
27101
27243
  }
27102
27244
  }
27103
27245
  };
27246
+ logRepoMeshStatusDebug("direct_truth_unavailable", {
27247
+ meshId,
27248
+ command: "mesh_status",
27249
+ refreshRequested,
27250
+ meshSource: meshRecord.source,
27251
+ directTruth
27252
+ });
27253
+ return failureResult;
27104
27254
  }
27105
27255
  const directTruthUnavailableNodeIds = new Set(directTruth.unavailableNodeIds);
27106
27256
  const selectedCoordinatorNodeId = readStringValue(
@@ -27308,7 +27458,17 @@ ${block}`);
27308
27458
  queue: { tasks: queue, summary: queueSummary },
27309
27459
  ledger: { entries: ledgerEntries, summary: ledgerSummary }
27310
27460
  };
27311
- return this.rememberAggregateMeshStatus(meshId, statusResult, refreshReason);
27461
+ const rememberedStatus = this.rememberAggregateMeshStatus(meshId, statusResult, refreshReason);
27462
+ logRepoMeshStatusDebug("return_live", {
27463
+ meshId,
27464
+ command: "mesh_status",
27465
+ refreshRequested,
27466
+ refreshReason,
27467
+ meshSource: meshRecord.source,
27468
+ directTruth,
27469
+ summary: summarizeRepoMeshStatusDebug(rememberedStatus)
27470
+ });
27471
+ return rememberedStatus;
27312
27472
  } catch (e) {
27313
27473
  return { success: false, error: e.message };
27314
27474
  }