@adhdev/daemon-core 0.9.82-rc.17 → 0.9.82-rc.19
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 +1 -0
- package/dist/index.js +91 -13
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +91 -13
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/commands/router.ts +122 -15
package/dist/index.mjs
CHANGED
|
@@ -23865,6 +23865,36 @@ function summarizeMeshSessionRecord(record) {
|
|
|
23865
23865
|
isCached: false
|
|
23866
23866
|
};
|
|
23867
23867
|
}
|
|
23868
|
+
function readLiveMeshNodeWorkspace(args) {
|
|
23869
|
+
const directNodeWorkspace = args.liveSessionRecords.find((record) => readStringValue(record?.meta?.meshNodeId) === args.nodeId && readStringValue(record?.workspace));
|
|
23870
|
+
if (directNodeWorkspace) {
|
|
23871
|
+
return readStringValue(directNodeWorkspace.workspace) || "";
|
|
23872
|
+
}
|
|
23873
|
+
if (args.allowCoordinatorSession) {
|
|
23874
|
+
const coordinatorWorkspace = args.liveSessionRecords.find((record) => readStringValue(record?.meta?.meshCoordinatorFor) === args.meshId && readStringValue(record?.workspace));
|
|
23875
|
+
if (coordinatorWorkspace) {
|
|
23876
|
+
return readStringValue(coordinatorWorkspace.workspace) || "";
|
|
23877
|
+
}
|
|
23878
|
+
}
|
|
23879
|
+
return "";
|
|
23880
|
+
}
|
|
23881
|
+
function collectLiveMeshSessionRecords(args) {
|
|
23882
|
+
const matches = args.liveSessionRecords.filter((record) => {
|
|
23883
|
+
if (readStringValue(record?.meta?.meshNodeId) === args.nodeId) return true;
|
|
23884
|
+
const recordWorkspace = readStringValue(record?.workspace);
|
|
23885
|
+
const nodeWorkspace = readStringValue(args.node?.workspace);
|
|
23886
|
+
return !!recordWorkspace && !!nodeWorkspace && recordWorkspace === nodeWorkspace;
|
|
23887
|
+
});
|
|
23888
|
+
if (args.allowCoordinatorSession) {
|
|
23889
|
+
for (const record of args.liveSessionRecords) {
|
|
23890
|
+
if (readStringValue(record?.meta?.meshCoordinatorFor) !== args.meshId) continue;
|
|
23891
|
+
const sessionId = readStringValue(record?.sessionId);
|
|
23892
|
+
if (sessionId && matches.some((entry) => readStringValue(entry?.sessionId) === sessionId)) continue;
|
|
23893
|
+
matches.push(record);
|
|
23894
|
+
}
|
|
23895
|
+
}
|
|
23896
|
+
return matches;
|
|
23897
|
+
}
|
|
23868
23898
|
function applyCachedInlineMeshNodeStatus(status, node) {
|
|
23869
23899
|
const cachedStatus = readObjectRecord(node?.cachedStatus);
|
|
23870
23900
|
const git = buildCachedInlineMeshGitStatus(node);
|
|
@@ -24289,25 +24319,35 @@ var DaemonCommandRouter = class {
|
|
|
24289
24319
|
}
|
|
24290
24320
|
getCachedInlineMesh(meshId, inlineMesh) {
|
|
24291
24321
|
if (inlineMesh && typeof inlineMesh === "object") {
|
|
24292
|
-
this.
|
|
24293
|
-
return inlineMesh;
|
|
24322
|
+
return this.warmInlineMeshCache(meshId, inlineMesh);
|
|
24294
24323
|
}
|
|
24295
24324
|
return this.inlineMeshCache.get(meshId);
|
|
24296
24325
|
}
|
|
24326
|
+
warmInlineMeshCache(meshId, inlineMesh) {
|
|
24327
|
+
if (!inlineMesh || typeof inlineMesh !== "object") return void 0;
|
|
24328
|
+
const cached = this.inlineMeshCache.get(meshId);
|
|
24329
|
+
if (cached) return cached;
|
|
24330
|
+
this.inlineMeshCache.set(meshId, inlineMesh);
|
|
24331
|
+
return inlineMesh;
|
|
24332
|
+
}
|
|
24297
24333
|
async getMeshForCommand(meshId, inlineMesh, options) {
|
|
24298
24334
|
const preferInline = options?.preferInline === true;
|
|
24299
24335
|
if (preferInline) {
|
|
24300
|
-
const cached2 = this.getCachedInlineMesh(meshId
|
|
24301
|
-
if (cached2) return { mesh: cached2, inline: true };
|
|
24336
|
+
const cached2 = this.getCachedInlineMesh(meshId);
|
|
24337
|
+
if (cached2) return { mesh: cached2, inline: true, source: "inline_cache" };
|
|
24338
|
+
const warmedInline2 = this.warmInlineMeshCache(meshId, inlineMesh);
|
|
24339
|
+
if (warmedInline2) return { mesh: warmedInline2, inline: true, source: "inline_bootstrap" };
|
|
24302
24340
|
}
|
|
24303
24341
|
try {
|
|
24304
24342
|
const { getMesh: getMesh3 } = await Promise.resolve().then(() => (init_mesh_config(), mesh_config_exports));
|
|
24305
24343
|
const mesh = getMesh3(meshId);
|
|
24306
|
-
if (mesh) return { mesh, inline: false };
|
|
24344
|
+
if (mesh) return { mesh, inline: false, source: "local_config" };
|
|
24307
24345
|
} catch {
|
|
24308
24346
|
}
|
|
24309
|
-
const cached = this.getCachedInlineMesh(meshId
|
|
24310
|
-
|
|
24347
|
+
const cached = this.getCachedInlineMesh(meshId);
|
|
24348
|
+
if (cached) return { mesh: cached, inline: true, source: "inline_cache" };
|
|
24349
|
+
const warmedInline = this.warmInlineMeshCache(meshId, inlineMesh);
|
|
24350
|
+
return warmedInline ? { mesh: warmedInline, inline: true, source: "inline_bootstrap" } : null;
|
|
24311
24351
|
}
|
|
24312
24352
|
updateInlineMeshNode(meshId, mesh, node) {
|
|
24313
24353
|
if (!mesh || !Array.isArray(mesh.nodes) || !node?.id) return;
|
|
@@ -24536,6 +24576,7 @@ var DaemonCommandRouter = class {
|
|
|
24536
24576
|
const deletedSessionIds = [];
|
|
24537
24577
|
const skippedSessionIds = [];
|
|
24538
24578
|
const skippedLiveSessionIds = [];
|
|
24579
|
+
const skippedCoordinatorSessionIds = [];
|
|
24539
24580
|
const deleteUnsupportedSessionIds = [];
|
|
24540
24581
|
const recordsRemainSessionIds = [];
|
|
24541
24582
|
const errors = [];
|
|
@@ -24568,6 +24609,12 @@ var DaemonCommandRouter = class {
|
|
|
24568
24609
|
const completed = this.isCompletedHostedSession(record);
|
|
24569
24610
|
const surfaceKind = getSessionHostSurfaceKind(record);
|
|
24570
24611
|
const liveRuntime = surfaceKind === "live_runtime";
|
|
24612
|
+
const coordinatorSession = readStringValue(record?.meta?.meshCoordinatorFor) === args.meshId;
|
|
24613
|
+
if (!hasExplicitSessionIds && coordinatorSession) {
|
|
24614
|
+
skippedSessionIds.push(sessionId);
|
|
24615
|
+
skippedCoordinatorSessionIds.push(sessionId);
|
|
24616
|
+
continue;
|
|
24617
|
+
}
|
|
24571
24618
|
if (!hasExplicitSessionIds && liveRuntime) {
|
|
24572
24619
|
skippedSessionIds.push(sessionId);
|
|
24573
24620
|
skippedLiveSessionIds.push(sessionId);
|
|
@@ -24633,6 +24680,7 @@ var DaemonCommandRouter = class {
|
|
|
24633
24680
|
deletedSessionIds,
|
|
24634
24681
|
skippedSessionIds,
|
|
24635
24682
|
skippedLiveSessionIds,
|
|
24683
|
+
skippedCoordinatorSessionIds,
|
|
24636
24684
|
...deleteUnsupported ? {
|
|
24637
24685
|
deleteUnsupported: true,
|
|
24638
24686
|
effectiveCleanup: args.mode === "stop_and_delete" ? "stopped_only_records_remain" : "delete_unsupported_records_remain",
|
|
@@ -25817,7 +25865,14 @@ var DaemonCommandRouter = class {
|
|
|
25817
25865
|
cliType
|
|
25818
25866
|
};
|
|
25819
25867
|
}
|
|
25820
|
-
const
|
|
25868
|
+
const sessionHostRecords = this.deps.sessionHostControl?.listSessions ? await this.deps.sessionHostControl.listSessions().catch(() => []) : [];
|
|
25869
|
+
const liveMeshSessions = partitionSessionHostRecords(Array.isArray(sessionHostRecords) ? sessionHostRecords : []).liveRuntimes;
|
|
25870
|
+
const workspace = readLiveMeshNodeWorkspace({
|
|
25871
|
+
meshId,
|
|
25872
|
+
nodeId: String(coordinatorNode.id || coordinatorNode.nodeId || preferredCoordinatorNodeId || ""),
|
|
25873
|
+
liveSessionRecords: liveMeshSessions,
|
|
25874
|
+
allowCoordinatorSession: true
|
|
25875
|
+
}) || (typeof coordinatorNode.workspace === "string" ? coordinatorNode.workspace.trim() : "");
|
|
25821
25876
|
if (!workspace) return { success: false, error: "Coordinator node workspace required", meshId, cliType };
|
|
25822
25877
|
if (!cliType) {
|
|
25823
25878
|
const resolved = await resolveProviderTypeFromPriority({
|
|
@@ -26128,7 +26183,12 @@ ${block}`);
|
|
|
26128
26183
|
const sessionHostRecords = this.deps.sessionHostControl?.listSessions ? await this.deps.sessionHostControl.listSessions().catch(() => []) : [];
|
|
26129
26184
|
const liveMeshSessions = partitionSessionHostRecords(Array.isArray(sessionHostRecords) ? sessionHostRecords : []).liveRuntimes;
|
|
26130
26185
|
const localMachineId = loadConfig().machineId || "";
|
|
26131
|
-
const
|
|
26186
|
+
const selectedCoordinatorNodeId = readStringValue(
|
|
26187
|
+
mesh.coordinator?.preferredNodeId,
|
|
26188
|
+
mesh.nodes?.[0]?.id,
|
|
26189
|
+
mesh.nodes?.[0]?.nodeId
|
|
26190
|
+
);
|
|
26191
|
+
const inlineCoordinatorNodeId = meshRecord?.inline && Array.isArray(mesh.nodes) ? selectedCoordinatorNodeId : void 0;
|
|
26132
26192
|
const refreshedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
26133
26193
|
const nodeStatuses = [];
|
|
26134
26194
|
for (const [nodeIndex, node] of (mesh.nodes || []).entries()) {
|
|
@@ -26187,7 +26247,20 @@ ${block}`);
|
|
|
26187
26247
|
reason: "Node has no daemon id, so mesh transport cannot be reported from the selected coordinator."
|
|
26188
26248
|
};
|
|
26189
26249
|
}
|
|
26190
|
-
const matchedLiveSessionRecords =
|
|
26250
|
+
const matchedLiveSessionRecords = collectLiveMeshSessionRecords({
|
|
26251
|
+
meshId,
|
|
26252
|
+
node,
|
|
26253
|
+
nodeId,
|
|
26254
|
+
liveSessionRecords: liveMeshSessions,
|
|
26255
|
+
allowCoordinatorSession: nodeId === selectedCoordinatorNodeId
|
|
26256
|
+
});
|
|
26257
|
+
const workspace = readLiveMeshNodeWorkspace({
|
|
26258
|
+
meshId,
|
|
26259
|
+
nodeId,
|
|
26260
|
+
liveSessionRecords: matchedLiveSessionRecords,
|
|
26261
|
+
allowCoordinatorSession: nodeId === selectedCoordinatorNodeId
|
|
26262
|
+
}) || (typeof node.workspace === "string" ? node.workspace : "");
|
|
26263
|
+
status.workspace = workspace || node.workspace;
|
|
26191
26264
|
if (matchedLiveSessionRecords.length > 0) {
|
|
26192
26265
|
const sessionIds = matchedLiveSessionRecords.map((record) => typeof record?.sessionId === "string" ? record.sessionId : "").filter(Boolean);
|
|
26193
26266
|
const providerTypes = matchedLiveSessionRecords.map((record) => readStringValue(record?.providerType)).filter(Boolean);
|
|
@@ -26197,14 +26270,14 @@ ${block}`);
|
|
|
26197
26270
|
status.providers = Array.from(/* @__PURE__ */ new Set([...Array.isArray(status.providers) ? status.providers : [], ...providerTypes]));
|
|
26198
26271
|
}
|
|
26199
26272
|
}
|
|
26200
|
-
if (
|
|
26201
|
-
if (!fs10.existsSync(
|
|
26273
|
+
if (workspace) {
|
|
26274
|
+
if (!fs10.existsSync(workspace) && applyCachedInlineMeshNodeStatus(status, node)) {
|
|
26202
26275
|
status.launchReady = !!daemonId && (readStringValue(status.machineStatus) === "online" || isSelfNode);
|
|
26203
26276
|
nodeStatuses.push(status);
|
|
26204
26277
|
continue;
|
|
26205
26278
|
}
|
|
26206
26279
|
try {
|
|
26207
|
-
const gitStatus = await getGitRepoStatus(
|
|
26280
|
+
const gitStatus = await getGitRepoStatus(workspace, { timeoutMs: 1e4, refreshUpstream: true });
|
|
26208
26281
|
status.git = gitStatus;
|
|
26209
26282
|
if (gitStatus.isGitRepo) {
|
|
26210
26283
|
status.health = deriveMeshNodeHealthFromGit(gitStatus);
|
|
@@ -26230,6 +26303,11 @@ ${block}`);
|
|
|
26230
26303
|
repoIdentity: mesh.repoIdentity,
|
|
26231
26304
|
defaultBranch: mesh.defaultBranch,
|
|
26232
26305
|
refreshedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
26306
|
+
sourceOfTruth: {
|
|
26307
|
+
membership: meshRecord?.source === "inline_cache" ? "coordinator_inline_mesh_cache" : meshRecord?.source === "local_config" ? "local_mesh_config" : "inline_bootstrap_snapshot",
|
|
26308
|
+
coordinatorOwnsLiveTruth: meshRecord?.source !== "inline_bootstrap",
|
|
26309
|
+
historicalEvidenceOnly: ["recoveryHints", "ledger.summary", "queue.summary"]
|
|
26310
|
+
},
|
|
26233
26311
|
nodes: nodeStatuses,
|
|
26234
26312
|
queue: { tasks: queue, summary: queueSummary },
|
|
26235
26313
|
ledger: { entries: ledgerEntries, summary: ledgerSummary }
|