@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
|
@@ -87,6 +87,7 @@ export declare class DaemonCommandRouter {
|
|
|
87
87
|
private inlineMeshCache;
|
|
88
88
|
constructor(deps: CommandRouterDeps);
|
|
89
89
|
getCachedInlineMesh(meshId: string, inlineMesh?: unknown): any | undefined;
|
|
90
|
+
private warmInlineMeshCache;
|
|
90
91
|
private getMeshForCommand;
|
|
91
92
|
private updateInlineMeshNode;
|
|
92
93
|
private removeInlineMeshNode;
|
package/dist/index.js
CHANGED
|
@@ -24098,6 +24098,36 @@ function summarizeMeshSessionRecord(record) {
|
|
|
24098
24098
|
isCached: false
|
|
24099
24099
|
};
|
|
24100
24100
|
}
|
|
24101
|
+
function readLiveMeshNodeWorkspace(args) {
|
|
24102
|
+
const directNodeWorkspace = args.liveSessionRecords.find((record) => readStringValue(record?.meta?.meshNodeId) === args.nodeId && readStringValue(record?.workspace));
|
|
24103
|
+
if (directNodeWorkspace) {
|
|
24104
|
+
return readStringValue(directNodeWorkspace.workspace) || "";
|
|
24105
|
+
}
|
|
24106
|
+
if (args.allowCoordinatorSession) {
|
|
24107
|
+
const coordinatorWorkspace = args.liveSessionRecords.find((record) => readStringValue(record?.meta?.meshCoordinatorFor) === args.meshId && readStringValue(record?.workspace));
|
|
24108
|
+
if (coordinatorWorkspace) {
|
|
24109
|
+
return readStringValue(coordinatorWorkspace.workspace) || "";
|
|
24110
|
+
}
|
|
24111
|
+
}
|
|
24112
|
+
return "";
|
|
24113
|
+
}
|
|
24114
|
+
function collectLiveMeshSessionRecords(args) {
|
|
24115
|
+
const matches = args.liveSessionRecords.filter((record) => {
|
|
24116
|
+
if (readStringValue(record?.meta?.meshNodeId) === args.nodeId) return true;
|
|
24117
|
+
const recordWorkspace = readStringValue(record?.workspace);
|
|
24118
|
+
const nodeWorkspace = readStringValue(args.node?.workspace);
|
|
24119
|
+
return !!recordWorkspace && !!nodeWorkspace && recordWorkspace === nodeWorkspace;
|
|
24120
|
+
});
|
|
24121
|
+
if (args.allowCoordinatorSession) {
|
|
24122
|
+
for (const record of args.liveSessionRecords) {
|
|
24123
|
+
if (readStringValue(record?.meta?.meshCoordinatorFor) !== args.meshId) continue;
|
|
24124
|
+
const sessionId = readStringValue(record?.sessionId);
|
|
24125
|
+
if (sessionId && matches.some((entry) => readStringValue(entry?.sessionId) === sessionId)) continue;
|
|
24126
|
+
matches.push(record);
|
|
24127
|
+
}
|
|
24128
|
+
}
|
|
24129
|
+
return matches;
|
|
24130
|
+
}
|
|
24101
24131
|
function applyCachedInlineMeshNodeStatus(status, node) {
|
|
24102
24132
|
const cachedStatus = readObjectRecord(node?.cachedStatus);
|
|
24103
24133
|
const git = buildCachedInlineMeshGitStatus(node);
|
|
@@ -24522,25 +24552,35 @@ var DaemonCommandRouter = class {
|
|
|
24522
24552
|
}
|
|
24523
24553
|
getCachedInlineMesh(meshId, inlineMesh) {
|
|
24524
24554
|
if (inlineMesh && typeof inlineMesh === "object") {
|
|
24525
|
-
this.
|
|
24526
|
-
return inlineMesh;
|
|
24555
|
+
return this.warmInlineMeshCache(meshId, inlineMesh);
|
|
24527
24556
|
}
|
|
24528
24557
|
return this.inlineMeshCache.get(meshId);
|
|
24529
24558
|
}
|
|
24559
|
+
warmInlineMeshCache(meshId, inlineMesh) {
|
|
24560
|
+
if (!inlineMesh || typeof inlineMesh !== "object") return void 0;
|
|
24561
|
+
const cached = this.inlineMeshCache.get(meshId);
|
|
24562
|
+
if (cached) return cached;
|
|
24563
|
+
this.inlineMeshCache.set(meshId, inlineMesh);
|
|
24564
|
+
return inlineMesh;
|
|
24565
|
+
}
|
|
24530
24566
|
async getMeshForCommand(meshId, inlineMesh, options) {
|
|
24531
24567
|
const preferInline = options?.preferInline === true;
|
|
24532
24568
|
if (preferInline) {
|
|
24533
|
-
const cached2 = this.getCachedInlineMesh(meshId
|
|
24534
|
-
if (cached2) return { mesh: cached2, inline: true };
|
|
24569
|
+
const cached2 = this.getCachedInlineMesh(meshId);
|
|
24570
|
+
if (cached2) return { mesh: cached2, inline: true, source: "inline_cache" };
|
|
24571
|
+
const warmedInline2 = this.warmInlineMeshCache(meshId, inlineMesh);
|
|
24572
|
+
if (warmedInline2) return { mesh: warmedInline2, inline: true, source: "inline_bootstrap" };
|
|
24535
24573
|
}
|
|
24536
24574
|
try {
|
|
24537
24575
|
const { getMesh: getMesh3 } = await Promise.resolve().then(() => (init_mesh_config(), mesh_config_exports));
|
|
24538
24576
|
const mesh = getMesh3(meshId);
|
|
24539
|
-
if (mesh) return { mesh, inline: false };
|
|
24577
|
+
if (mesh) return { mesh, inline: false, source: "local_config" };
|
|
24540
24578
|
} catch {
|
|
24541
24579
|
}
|
|
24542
|
-
const cached = this.getCachedInlineMesh(meshId
|
|
24543
|
-
|
|
24580
|
+
const cached = this.getCachedInlineMesh(meshId);
|
|
24581
|
+
if (cached) return { mesh: cached, inline: true, source: "inline_cache" };
|
|
24582
|
+
const warmedInline = this.warmInlineMeshCache(meshId, inlineMesh);
|
|
24583
|
+
return warmedInline ? { mesh: warmedInline, inline: true, source: "inline_bootstrap" } : null;
|
|
24544
24584
|
}
|
|
24545
24585
|
updateInlineMeshNode(meshId, mesh, node) {
|
|
24546
24586
|
if (!mesh || !Array.isArray(mesh.nodes) || !node?.id) return;
|
|
@@ -24769,6 +24809,7 @@ var DaemonCommandRouter = class {
|
|
|
24769
24809
|
const deletedSessionIds = [];
|
|
24770
24810
|
const skippedSessionIds = [];
|
|
24771
24811
|
const skippedLiveSessionIds = [];
|
|
24812
|
+
const skippedCoordinatorSessionIds = [];
|
|
24772
24813
|
const deleteUnsupportedSessionIds = [];
|
|
24773
24814
|
const recordsRemainSessionIds = [];
|
|
24774
24815
|
const errors = [];
|
|
@@ -24801,6 +24842,12 @@ var DaemonCommandRouter = class {
|
|
|
24801
24842
|
const completed = this.isCompletedHostedSession(record);
|
|
24802
24843
|
const surfaceKind = getSessionHostSurfaceKind(record);
|
|
24803
24844
|
const liveRuntime = surfaceKind === "live_runtime";
|
|
24845
|
+
const coordinatorSession = readStringValue(record?.meta?.meshCoordinatorFor) === args.meshId;
|
|
24846
|
+
if (!hasExplicitSessionIds && coordinatorSession) {
|
|
24847
|
+
skippedSessionIds.push(sessionId);
|
|
24848
|
+
skippedCoordinatorSessionIds.push(sessionId);
|
|
24849
|
+
continue;
|
|
24850
|
+
}
|
|
24804
24851
|
if (!hasExplicitSessionIds && liveRuntime) {
|
|
24805
24852
|
skippedSessionIds.push(sessionId);
|
|
24806
24853
|
skippedLiveSessionIds.push(sessionId);
|
|
@@ -24866,6 +24913,7 @@ var DaemonCommandRouter = class {
|
|
|
24866
24913
|
deletedSessionIds,
|
|
24867
24914
|
skippedSessionIds,
|
|
24868
24915
|
skippedLiveSessionIds,
|
|
24916
|
+
skippedCoordinatorSessionIds,
|
|
24869
24917
|
...deleteUnsupported ? {
|
|
24870
24918
|
deleteUnsupported: true,
|
|
24871
24919
|
effectiveCleanup: args.mode === "stop_and_delete" ? "stopped_only_records_remain" : "delete_unsupported_records_remain",
|
|
@@ -26050,7 +26098,14 @@ var DaemonCommandRouter = class {
|
|
|
26050
26098
|
cliType
|
|
26051
26099
|
};
|
|
26052
26100
|
}
|
|
26053
|
-
const
|
|
26101
|
+
const sessionHostRecords = this.deps.sessionHostControl?.listSessions ? await this.deps.sessionHostControl.listSessions().catch(() => []) : [];
|
|
26102
|
+
const liveMeshSessions = partitionSessionHostRecords(Array.isArray(sessionHostRecords) ? sessionHostRecords : []).liveRuntimes;
|
|
26103
|
+
const workspace = readLiveMeshNodeWorkspace({
|
|
26104
|
+
meshId,
|
|
26105
|
+
nodeId: String(coordinatorNode.id || coordinatorNode.nodeId || preferredCoordinatorNodeId || ""),
|
|
26106
|
+
liveSessionRecords: liveMeshSessions,
|
|
26107
|
+
allowCoordinatorSession: true
|
|
26108
|
+
}) || (typeof coordinatorNode.workspace === "string" ? coordinatorNode.workspace.trim() : "");
|
|
26054
26109
|
if (!workspace) return { success: false, error: "Coordinator node workspace required", meshId, cliType };
|
|
26055
26110
|
if (!cliType) {
|
|
26056
26111
|
const resolved = await resolveProviderTypeFromPriority({
|
|
@@ -26361,7 +26416,12 @@ ${block}`);
|
|
|
26361
26416
|
const sessionHostRecords = this.deps.sessionHostControl?.listSessions ? await this.deps.sessionHostControl.listSessions().catch(() => []) : [];
|
|
26362
26417
|
const liveMeshSessions = partitionSessionHostRecords(Array.isArray(sessionHostRecords) ? sessionHostRecords : []).liveRuntimes;
|
|
26363
26418
|
const localMachineId = loadConfig().machineId || "";
|
|
26364
|
-
const
|
|
26419
|
+
const selectedCoordinatorNodeId = readStringValue(
|
|
26420
|
+
mesh.coordinator?.preferredNodeId,
|
|
26421
|
+
mesh.nodes?.[0]?.id,
|
|
26422
|
+
mesh.nodes?.[0]?.nodeId
|
|
26423
|
+
);
|
|
26424
|
+
const inlineCoordinatorNodeId = meshRecord?.inline && Array.isArray(mesh.nodes) ? selectedCoordinatorNodeId : void 0;
|
|
26365
26425
|
const refreshedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
26366
26426
|
const nodeStatuses = [];
|
|
26367
26427
|
for (const [nodeIndex, node] of (mesh.nodes || []).entries()) {
|
|
@@ -26420,7 +26480,20 @@ ${block}`);
|
|
|
26420
26480
|
reason: "Node has no daemon id, so mesh transport cannot be reported from the selected coordinator."
|
|
26421
26481
|
};
|
|
26422
26482
|
}
|
|
26423
|
-
const matchedLiveSessionRecords =
|
|
26483
|
+
const matchedLiveSessionRecords = collectLiveMeshSessionRecords({
|
|
26484
|
+
meshId,
|
|
26485
|
+
node,
|
|
26486
|
+
nodeId,
|
|
26487
|
+
liveSessionRecords: liveMeshSessions,
|
|
26488
|
+
allowCoordinatorSession: nodeId === selectedCoordinatorNodeId
|
|
26489
|
+
});
|
|
26490
|
+
const workspace = readLiveMeshNodeWorkspace({
|
|
26491
|
+
meshId,
|
|
26492
|
+
nodeId,
|
|
26493
|
+
liveSessionRecords: matchedLiveSessionRecords,
|
|
26494
|
+
allowCoordinatorSession: nodeId === selectedCoordinatorNodeId
|
|
26495
|
+
}) || (typeof node.workspace === "string" ? node.workspace : "");
|
|
26496
|
+
status.workspace = workspace || node.workspace;
|
|
26424
26497
|
if (matchedLiveSessionRecords.length > 0) {
|
|
26425
26498
|
const sessionIds = matchedLiveSessionRecords.map((record) => typeof record?.sessionId === "string" ? record.sessionId : "").filter(Boolean);
|
|
26426
26499
|
const providerTypes = matchedLiveSessionRecords.map((record) => readStringValue(record?.providerType)).filter(Boolean);
|
|
@@ -26430,14 +26503,14 @@ ${block}`);
|
|
|
26430
26503
|
status.providers = Array.from(/* @__PURE__ */ new Set([...Array.isArray(status.providers) ? status.providers : [], ...providerTypes]));
|
|
26431
26504
|
}
|
|
26432
26505
|
}
|
|
26433
|
-
if (
|
|
26434
|
-
if (!fs10.existsSync(
|
|
26506
|
+
if (workspace) {
|
|
26507
|
+
if (!fs10.existsSync(workspace) && applyCachedInlineMeshNodeStatus(status, node)) {
|
|
26435
26508
|
status.launchReady = !!daemonId && (readStringValue(status.machineStatus) === "online" || isSelfNode);
|
|
26436
26509
|
nodeStatuses.push(status);
|
|
26437
26510
|
continue;
|
|
26438
26511
|
}
|
|
26439
26512
|
try {
|
|
26440
|
-
const gitStatus = await getGitRepoStatus(
|
|
26513
|
+
const gitStatus = await getGitRepoStatus(workspace, { timeoutMs: 1e4, refreshUpstream: true });
|
|
26441
26514
|
status.git = gitStatus;
|
|
26442
26515
|
if (gitStatus.isGitRepo) {
|
|
26443
26516
|
status.health = deriveMeshNodeHealthFromGit(gitStatus);
|
|
@@ -26463,6 +26536,11 @@ ${block}`);
|
|
|
26463
26536
|
repoIdentity: mesh.repoIdentity,
|
|
26464
26537
|
defaultBranch: mesh.defaultBranch,
|
|
26465
26538
|
refreshedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
26539
|
+
sourceOfTruth: {
|
|
26540
|
+
membership: meshRecord?.source === "inline_cache" ? "coordinator_inline_mesh_cache" : meshRecord?.source === "local_config" ? "local_mesh_config" : "inline_bootstrap_snapshot",
|
|
26541
|
+
coordinatorOwnsLiveTruth: meshRecord?.source !== "inline_bootstrap",
|
|
26542
|
+
historicalEvidenceOnly: ["recoveryHints", "ledger.summary", "queue.summary"]
|
|
26543
|
+
},
|
|
26466
26544
|
nodes: nodeStatuses,
|
|
26467
26545
|
queue: { tasks: queue, summary: queueSummary },
|
|
26468
26546
|
ledger: { entries: ledgerEntries, summary: ledgerSummary }
|