@adhdev/daemon-core 0.9.82-rc.39 → 0.9.82-rc.40

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
@@ -24768,9 +24768,56 @@ var DaemonCommandRouter = class {
24768
24768
  * Allows the MCP server to query mesh data via get_mesh even when
24769
24769
  * the mesh doesn't exist in the local meshes.json file. */
24770
24770
  inlineMeshCache = /* @__PURE__ */ new Map();
24771
+ /** Coordinator-owned whole-mesh aggregate status snapshots. Browser callers read this by default. */
24772
+ aggregateMeshStatusCache = /* @__PURE__ */ new Map();
24771
24773
  constructor(deps) {
24772
24774
  this.deps = deps;
24773
24775
  }
24776
+ cloneJsonValue(value) {
24777
+ if (typeof structuredClone === "function") return structuredClone(value);
24778
+ return JSON.parse(JSON.stringify(value));
24779
+ }
24780
+ getCachedAggregateMeshStatus(meshId) {
24781
+ const cached = this.aggregateMeshStatusCache.get(meshId);
24782
+ if (!cached?.snapshot || cached.snapshot.success !== true || !Array.isArray(cached.snapshot.nodes)) return null;
24783
+ const snapshot = this.cloneJsonValue(cached.snapshot);
24784
+ const ageMs = Math.max(0, Date.now() - cached.builtAt);
24785
+ const sourceOfTruth = snapshot.sourceOfTruth && typeof snapshot.sourceOfTruth === "object" ? snapshot.sourceOfTruth : {};
24786
+ snapshot.sourceOfTruth = {
24787
+ ...sourceOfTruth,
24788
+ aggregateSnapshot: {
24789
+ ...sourceOfTruth.aggregateSnapshot && typeof sourceOfTruth.aggregateSnapshot === "object" ? sourceOfTruth.aggregateSnapshot : {},
24790
+ owner: "coordinator_daemon_memory",
24791
+ cached: true,
24792
+ source: "memory",
24793
+ refreshReason: "memory_cache_hit",
24794
+ ageMs,
24795
+ cachedAt: new Date(cached.builtAt).toISOString(),
24796
+ returnedAt: (/* @__PURE__ */ new Date()).toISOString()
24797
+ }
24798
+ };
24799
+ return snapshot;
24800
+ }
24801
+ rememberAggregateMeshStatus(meshId, snapshot, refreshReason) {
24802
+ if (!snapshot || typeof snapshot !== "object" || snapshot.success !== true || !Array.isArray(snapshot.nodes)) return snapshot;
24803
+ const builtAt = Date.now();
24804
+ const next = this.cloneJsonValue(snapshot);
24805
+ const sourceOfTruth = next.sourceOfTruth && typeof next.sourceOfTruth === "object" ? next.sourceOfTruth : {};
24806
+ next.sourceOfTruth = {
24807
+ ...sourceOfTruth,
24808
+ aggregateSnapshot: {
24809
+ owner: "coordinator_daemon_memory",
24810
+ cached: false,
24811
+ source: "live_refresh",
24812
+ refreshReason,
24813
+ ageMs: 0,
24814
+ cachedAt: new Date(builtAt).toISOString(),
24815
+ returnedAt: new Date(builtAt).toISOString()
24816
+ }
24817
+ };
24818
+ this.aggregateMeshStatusCache.set(meshId, { builtAt, snapshot: this.cloneJsonValue(next) });
24819
+ return next;
24820
+ }
24774
24821
  getCachedInlineMesh(meshId, inlineMesh) {
24775
24822
  if (inlineMesh && typeof inlineMesh === "object") {
24776
24823
  return this.warmInlineMeshCache(meshId, inlineMesh);
@@ -24810,6 +24857,9 @@ var DaemonCommandRouter = class {
24810
24857
  const warmedInline = this.warmInlineMeshCache(meshId, inlineMesh);
24811
24858
  return warmedInline ? { mesh: warmedInline, inline: true, source: "inline_bootstrap" } : null;
24812
24859
  }
24860
+ invalidateAggregateMeshStatus(meshId) {
24861
+ this.aggregateMeshStatusCache.delete(meshId);
24862
+ }
24813
24863
  updateInlineMeshNode(meshId, mesh, node) {
24814
24864
  if (!mesh || !Array.isArray(mesh.nodes) || !node?.id) return;
24815
24865
  const idx = mesh.nodes.findIndex((entry) => entry?.id === node.id || entry?.nodeId === node.id);
@@ -24817,6 +24867,7 @@ var DaemonCommandRouter = class {
24817
24867
  else mesh.nodes.push(node);
24818
24868
  mesh.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
24819
24869
  this.inlineMeshCache.set(meshId, mesh);
24870
+ this.invalidateAggregateMeshStatus(meshId);
24820
24871
  }
24821
24872
  removeInlineMeshNode(meshId, mesh, nodeId) {
24822
24873
  if (!mesh || !Array.isArray(mesh.nodes)) return false;
@@ -24825,6 +24876,7 @@ var DaemonCommandRouter = class {
24825
24876
  mesh.nodes.splice(idx, 1);
24826
24877
  mesh.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
24827
24878
  this.inlineMeshCache.set(meshId, mesh);
24879
+ this.invalidateAggregateMeshStatus(meshId);
24828
24880
  return true;
24829
24881
  }
24830
24882
  normalizeMeshSessionCleanupMode(value) {
@@ -25866,6 +25918,7 @@ var DaemonCommandRouter = class {
25866
25918
  const mesh = updateMesh2(meshId, patch);
25867
25919
  if (!mesh) return { success: false, error: "Mesh not found" };
25868
25920
  this.inlineMeshCache.set(meshId, mesh);
25921
+ this.invalidateAggregateMeshStatus(meshId);
25869
25922
  return { success: true, mesh };
25870
25923
  } catch (e) {
25871
25924
  return { success: false, error: e.message };
@@ -26301,6 +26354,7 @@ var DaemonCommandRouter = class {
26301
26354
  } else {
26302
26355
  const { removeNode: removeNode3 } = await Promise.resolve().then(() => (init_mesh_config(), mesh_config_exports));
26303
26356
  removed = removeNode3(meshId, nodeId);
26357
+ if (removed) this.invalidateAggregateMeshStatus(meshId);
26304
26358
  }
26305
26359
  if (removed) {
26306
26360
  try {
@@ -26379,6 +26433,7 @@ var DaemonCommandRouter = class {
26379
26433
  policy: { ...sourceNode.policy || {} }
26380
26434
  });
26381
26435
  if (!node) return { success: false, error: "Failed to register worktree node" };
26436
+ this.invalidateAggregateMeshStatus(meshId);
26382
26437
  }
26383
26438
  const initSubmodules = sourceNode.policy?.initSubmodulesOnClone !== false;
26384
26439
  if (initSubmodules) {
@@ -26763,6 +26818,12 @@ ${block}`);
26763
26818
  const meshRecord = await this.getMeshForCommand(meshId, args?.inlineMesh, { preferInline: true });
26764
26819
  const mesh = meshRecord?.mesh;
26765
26820
  if (!mesh) return { success: false, error: "Mesh not found" };
26821
+ const refreshRequested = args?.refresh === true || args?.forceRefresh === true;
26822
+ if (!refreshRequested) {
26823
+ const cachedStatus = this.getCachedAggregateMeshStatus(meshId);
26824
+ if (cachedStatus) return cachedStatus;
26825
+ }
26826
+ const refreshReason = refreshRequested ? "explicit_refresh" : "cold_cache_miss";
26766
26827
  const { getMeshQueueStats: getMeshQueueStats2, getQueue: getQueue2 } = await Promise.resolve().then(() => (init_mesh_work_queue(), mesh_work_queue_exports));
26767
26828
  const queue = getQueue2(meshId);
26768
26829
  const queueSummary = getMeshQueueStats2(meshId);
@@ -26986,13 +27047,13 @@ ${block}`);
26986
27047
  finalizeMeshNodeStatus({ status, node, daemonId, isSelfNode });
26987
27048
  nodeStatuses.push(status);
26988
27049
  }
26989
- return {
27050
+ const statusResult = {
26990
27051
  success: true,
26991
27052
  meshId: mesh.id,
26992
27053
  meshName: mesh.name,
26993
27054
  repoIdentity: mesh.repoIdentity,
26994
27055
  defaultBranch: mesh.defaultBranch,
26995
- refreshedAt: (/* @__PURE__ */ new Date()).toISOString(),
27056
+ refreshedAt,
26996
27057
  sourceOfTruth: {
26997
27058
  membership: meshRecord?.source === "inline_cache" ? "coordinator_inline_mesh_cache" : meshRecord?.source === "local_config" ? "local_mesh_config" : "inline_bootstrap_snapshot",
26998
27059
  coordinatorOwnsLiveTruth: directTruthSatisfied,
@@ -27014,6 +27075,7 @@ ${block}`);
27014
27075
  queue: { tasks: queue, summary: queueSummary },
27015
27076
  ledger: { entries: ledgerEntries, summary: ledgerSummary }
27016
27077
  };
27078
+ return this.rememberAggregateMeshStatus(meshId, statusResult, refreshReason);
27017
27079
  } catch (e) {
27018
27080
  return { success: false, error: e.message };
27019
27081
  }