@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/commands/router.d.ts +6 -0
- package/dist/index.js +64 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +64 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/commands/router.ts +75 -2
|
@@ -87,10 +87,16 @@ export declare class DaemonCommandRouter {
|
|
|
87
87
|
* Allows the MCP server to query mesh data via get_mesh even when
|
|
88
88
|
* the mesh doesn't exist in the local meshes.json file. */
|
|
89
89
|
private inlineMeshCache;
|
|
90
|
+
/** Coordinator-owned whole-mesh aggregate status snapshots. Browser callers read this by default. */
|
|
91
|
+
private aggregateMeshStatusCache;
|
|
90
92
|
constructor(deps: CommandRouterDeps);
|
|
93
|
+
private cloneJsonValue;
|
|
94
|
+
private getCachedAggregateMeshStatus;
|
|
95
|
+
private rememberAggregateMeshStatus;
|
|
91
96
|
getCachedInlineMesh(meshId: string, inlineMesh?: unknown): any | undefined;
|
|
92
97
|
private warmInlineMeshCache;
|
|
93
98
|
private getMeshForCommand;
|
|
99
|
+
private invalidateAggregateMeshStatus;
|
|
94
100
|
private updateInlineMeshNode;
|
|
95
101
|
private removeInlineMeshNode;
|
|
96
102
|
private normalizeMeshSessionCleanupMode;
|
package/dist/index.js
CHANGED
|
@@ -25001,9 +25001,56 @@ var DaemonCommandRouter = class {
|
|
|
25001
25001
|
* Allows the MCP server to query mesh data via get_mesh even when
|
|
25002
25002
|
* the mesh doesn't exist in the local meshes.json file. */
|
|
25003
25003
|
inlineMeshCache = /* @__PURE__ */ new Map();
|
|
25004
|
+
/** Coordinator-owned whole-mesh aggregate status snapshots. Browser callers read this by default. */
|
|
25005
|
+
aggregateMeshStatusCache = /* @__PURE__ */ new Map();
|
|
25004
25006
|
constructor(deps) {
|
|
25005
25007
|
this.deps = deps;
|
|
25006
25008
|
}
|
|
25009
|
+
cloneJsonValue(value) {
|
|
25010
|
+
if (typeof structuredClone === "function") return structuredClone(value);
|
|
25011
|
+
return JSON.parse(JSON.stringify(value));
|
|
25012
|
+
}
|
|
25013
|
+
getCachedAggregateMeshStatus(meshId) {
|
|
25014
|
+
const cached = this.aggregateMeshStatusCache.get(meshId);
|
|
25015
|
+
if (!cached?.snapshot || cached.snapshot.success !== true || !Array.isArray(cached.snapshot.nodes)) return null;
|
|
25016
|
+
const snapshot = this.cloneJsonValue(cached.snapshot);
|
|
25017
|
+
const ageMs = Math.max(0, Date.now() - cached.builtAt);
|
|
25018
|
+
const sourceOfTruth = snapshot.sourceOfTruth && typeof snapshot.sourceOfTruth === "object" ? snapshot.sourceOfTruth : {};
|
|
25019
|
+
snapshot.sourceOfTruth = {
|
|
25020
|
+
...sourceOfTruth,
|
|
25021
|
+
aggregateSnapshot: {
|
|
25022
|
+
...sourceOfTruth.aggregateSnapshot && typeof sourceOfTruth.aggregateSnapshot === "object" ? sourceOfTruth.aggregateSnapshot : {},
|
|
25023
|
+
owner: "coordinator_daemon_memory",
|
|
25024
|
+
cached: true,
|
|
25025
|
+
source: "memory",
|
|
25026
|
+
refreshReason: "memory_cache_hit",
|
|
25027
|
+
ageMs,
|
|
25028
|
+
cachedAt: new Date(cached.builtAt).toISOString(),
|
|
25029
|
+
returnedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
25030
|
+
}
|
|
25031
|
+
};
|
|
25032
|
+
return snapshot;
|
|
25033
|
+
}
|
|
25034
|
+
rememberAggregateMeshStatus(meshId, snapshot, refreshReason) {
|
|
25035
|
+
if (!snapshot || typeof snapshot !== "object" || snapshot.success !== true || !Array.isArray(snapshot.nodes)) return snapshot;
|
|
25036
|
+
const builtAt = Date.now();
|
|
25037
|
+
const next = this.cloneJsonValue(snapshot);
|
|
25038
|
+
const sourceOfTruth = next.sourceOfTruth && typeof next.sourceOfTruth === "object" ? next.sourceOfTruth : {};
|
|
25039
|
+
next.sourceOfTruth = {
|
|
25040
|
+
...sourceOfTruth,
|
|
25041
|
+
aggregateSnapshot: {
|
|
25042
|
+
owner: "coordinator_daemon_memory",
|
|
25043
|
+
cached: false,
|
|
25044
|
+
source: "live_refresh",
|
|
25045
|
+
refreshReason,
|
|
25046
|
+
ageMs: 0,
|
|
25047
|
+
cachedAt: new Date(builtAt).toISOString(),
|
|
25048
|
+
returnedAt: new Date(builtAt).toISOString()
|
|
25049
|
+
}
|
|
25050
|
+
};
|
|
25051
|
+
this.aggregateMeshStatusCache.set(meshId, { builtAt, snapshot: this.cloneJsonValue(next) });
|
|
25052
|
+
return next;
|
|
25053
|
+
}
|
|
25007
25054
|
getCachedInlineMesh(meshId, inlineMesh) {
|
|
25008
25055
|
if (inlineMesh && typeof inlineMesh === "object") {
|
|
25009
25056
|
return this.warmInlineMeshCache(meshId, inlineMesh);
|
|
@@ -25043,6 +25090,9 @@ var DaemonCommandRouter = class {
|
|
|
25043
25090
|
const warmedInline = this.warmInlineMeshCache(meshId, inlineMesh);
|
|
25044
25091
|
return warmedInline ? { mesh: warmedInline, inline: true, source: "inline_bootstrap" } : null;
|
|
25045
25092
|
}
|
|
25093
|
+
invalidateAggregateMeshStatus(meshId) {
|
|
25094
|
+
this.aggregateMeshStatusCache.delete(meshId);
|
|
25095
|
+
}
|
|
25046
25096
|
updateInlineMeshNode(meshId, mesh, node) {
|
|
25047
25097
|
if (!mesh || !Array.isArray(mesh.nodes) || !node?.id) return;
|
|
25048
25098
|
const idx = mesh.nodes.findIndex((entry) => entry?.id === node.id || entry?.nodeId === node.id);
|
|
@@ -25050,6 +25100,7 @@ var DaemonCommandRouter = class {
|
|
|
25050
25100
|
else mesh.nodes.push(node);
|
|
25051
25101
|
mesh.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
25052
25102
|
this.inlineMeshCache.set(meshId, mesh);
|
|
25103
|
+
this.invalidateAggregateMeshStatus(meshId);
|
|
25053
25104
|
}
|
|
25054
25105
|
removeInlineMeshNode(meshId, mesh, nodeId) {
|
|
25055
25106
|
if (!mesh || !Array.isArray(mesh.nodes)) return false;
|
|
@@ -25058,6 +25109,7 @@ var DaemonCommandRouter = class {
|
|
|
25058
25109
|
mesh.nodes.splice(idx, 1);
|
|
25059
25110
|
mesh.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
25060
25111
|
this.inlineMeshCache.set(meshId, mesh);
|
|
25112
|
+
this.invalidateAggregateMeshStatus(meshId);
|
|
25061
25113
|
return true;
|
|
25062
25114
|
}
|
|
25063
25115
|
normalizeMeshSessionCleanupMode(value) {
|
|
@@ -26099,6 +26151,7 @@ var DaemonCommandRouter = class {
|
|
|
26099
26151
|
const mesh = updateMesh2(meshId, patch);
|
|
26100
26152
|
if (!mesh) return { success: false, error: "Mesh not found" };
|
|
26101
26153
|
this.inlineMeshCache.set(meshId, mesh);
|
|
26154
|
+
this.invalidateAggregateMeshStatus(meshId);
|
|
26102
26155
|
return { success: true, mesh };
|
|
26103
26156
|
} catch (e) {
|
|
26104
26157
|
return { success: false, error: e.message };
|
|
@@ -26534,6 +26587,7 @@ var DaemonCommandRouter = class {
|
|
|
26534
26587
|
} else {
|
|
26535
26588
|
const { removeNode: removeNode3 } = await Promise.resolve().then(() => (init_mesh_config(), mesh_config_exports));
|
|
26536
26589
|
removed = removeNode3(meshId, nodeId);
|
|
26590
|
+
if (removed) this.invalidateAggregateMeshStatus(meshId);
|
|
26537
26591
|
}
|
|
26538
26592
|
if (removed) {
|
|
26539
26593
|
try {
|
|
@@ -26612,6 +26666,7 @@ var DaemonCommandRouter = class {
|
|
|
26612
26666
|
policy: { ...sourceNode.policy || {} }
|
|
26613
26667
|
});
|
|
26614
26668
|
if (!node) return { success: false, error: "Failed to register worktree node" };
|
|
26669
|
+
this.invalidateAggregateMeshStatus(meshId);
|
|
26615
26670
|
}
|
|
26616
26671
|
const initSubmodules = sourceNode.policy?.initSubmodulesOnClone !== false;
|
|
26617
26672
|
if (initSubmodules) {
|
|
@@ -26996,6 +27051,12 @@ ${block}`);
|
|
|
26996
27051
|
const meshRecord = await this.getMeshForCommand(meshId, args?.inlineMesh, { preferInline: true });
|
|
26997
27052
|
const mesh = meshRecord?.mesh;
|
|
26998
27053
|
if (!mesh) return { success: false, error: "Mesh not found" };
|
|
27054
|
+
const refreshRequested = args?.refresh === true || args?.forceRefresh === true;
|
|
27055
|
+
if (!refreshRequested) {
|
|
27056
|
+
const cachedStatus = this.getCachedAggregateMeshStatus(meshId);
|
|
27057
|
+
if (cachedStatus) return cachedStatus;
|
|
27058
|
+
}
|
|
27059
|
+
const refreshReason = refreshRequested ? "explicit_refresh" : "cold_cache_miss";
|
|
26999
27060
|
const { getMeshQueueStats: getMeshQueueStats2, getQueue: getQueue2 } = await Promise.resolve().then(() => (init_mesh_work_queue(), mesh_work_queue_exports));
|
|
27000
27061
|
const queue = getQueue2(meshId);
|
|
27001
27062
|
const queueSummary = getMeshQueueStats2(meshId);
|
|
@@ -27219,13 +27280,13 @@ ${block}`);
|
|
|
27219
27280
|
finalizeMeshNodeStatus({ status, node, daemonId, isSelfNode });
|
|
27220
27281
|
nodeStatuses.push(status);
|
|
27221
27282
|
}
|
|
27222
|
-
|
|
27283
|
+
const statusResult = {
|
|
27223
27284
|
success: true,
|
|
27224
27285
|
meshId: mesh.id,
|
|
27225
27286
|
meshName: mesh.name,
|
|
27226
27287
|
repoIdentity: mesh.repoIdentity,
|
|
27227
27288
|
defaultBranch: mesh.defaultBranch,
|
|
27228
|
-
refreshedAt
|
|
27289
|
+
refreshedAt,
|
|
27229
27290
|
sourceOfTruth: {
|
|
27230
27291
|
membership: meshRecord?.source === "inline_cache" ? "coordinator_inline_mesh_cache" : meshRecord?.source === "local_config" ? "local_mesh_config" : "inline_bootstrap_snapshot",
|
|
27231
27292
|
coordinatorOwnsLiveTruth: directTruthSatisfied,
|
|
@@ -27247,6 +27308,7 @@ ${block}`);
|
|
|
27247
27308
|
queue: { tasks: queue, summary: queueSummary },
|
|
27248
27309
|
ledger: { entries: ledgerEntries, summary: ledgerSummary }
|
|
27249
27310
|
};
|
|
27311
|
+
return this.rememberAggregateMeshStatus(meshId, statusResult, refreshReason);
|
|
27250
27312
|
} catch (e) {
|
|
27251
27313
|
return { success: false, error: e.message };
|
|
27252
27314
|
}
|