@adhdev/daemon-core 0.9.82-rc.17 → 0.9.82-rc.18
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.js +61 -6
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +61 -6
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/commands/router.ts +86 -7
package/package.json
CHANGED
package/src/commands/router.ts
CHANGED
|
@@ -328,6 +328,59 @@ function summarizeMeshSessionRecord(record: any): Record<string, unknown> {
|
|
|
328
328
|
};
|
|
329
329
|
}
|
|
330
330
|
|
|
331
|
+
function readLiveMeshNodeWorkspace(args: {
|
|
332
|
+
meshId: string;
|
|
333
|
+
nodeId: string;
|
|
334
|
+
liveSessionRecords: any[];
|
|
335
|
+
allowCoordinatorSession?: boolean;
|
|
336
|
+
}): string {
|
|
337
|
+
const directNodeWorkspace = args.liveSessionRecords.find((record) => (
|
|
338
|
+
readStringValue(record?.meta?.meshNodeId) === args.nodeId
|
|
339
|
+
&& readStringValue(record?.workspace)
|
|
340
|
+
));
|
|
341
|
+
if (directNodeWorkspace) {
|
|
342
|
+
return readStringValue(directNodeWorkspace.workspace) || '';
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
if (args.allowCoordinatorSession) {
|
|
346
|
+
const coordinatorWorkspace = args.liveSessionRecords.find((record) => (
|
|
347
|
+
readStringValue(record?.meta?.meshCoordinatorFor) === args.meshId
|
|
348
|
+
&& readStringValue(record?.workspace)
|
|
349
|
+
));
|
|
350
|
+
if (coordinatorWorkspace) {
|
|
351
|
+
return readStringValue(coordinatorWorkspace.workspace) || '';
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
return '';
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
function collectLiveMeshSessionRecords(args: {
|
|
359
|
+
meshId: string;
|
|
360
|
+
node: any;
|
|
361
|
+
nodeId: string;
|
|
362
|
+
liveSessionRecords: any[];
|
|
363
|
+
allowCoordinatorSession?: boolean;
|
|
364
|
+
}): any[] {
|
|
365
|
+
const matches = args.liveSessionRecords.filter((record) => {
|
|
366
|
+
if (readStringValue(record?.meta?.meshNodeId) === args.nodeId) return true;
|
|
367
|
+
const recordWorkspace = readStringValue(record?.workspace);
|
|
368
|
+
const nodeWorkspace = readStringValue(args.node?.workspace);
|
|
369
|
+
return !!recordWorkspace && !!nodeWorkspace && recordWorkspace === nodeWorkspace;
|
|
370
|
+
});
|
|
371
|
+
|
|
372
|
+
if (args.allowCoordinatorSession) {
|
|
373
|
+
for (const record of args.liveSessionRecords) {
|
|
374
|
+
if (readStringValue(record?.meta?.meshCoordinatorFor) !== args.meshId) continue;
|
|
375
|
+
const sessionId = readStringValue(record?.sessionId);
|
|
376
|
+
if (sessionId && matches.some((entry) => readStringValue(entry?.sessionId) === sessionId)) continue;
|
|
377
|
+
matches.push(record);
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
return matches;
|
|
382
|
+
}
|
|
383
|
+
|
|
331
384
|
function applyCachedInlineMeshNodeStatus(status: Record<string, unknown>, node: any): boolean {
|
|
332
385
|
const cachedStatus = readObjectRecord(node?.cachedStatus);
|
|
333
386
|
const git = buildCachedInlineMeshGitStatus(node);
|
|
@@ -2669,7 +2722,16 @@ export class DaemonCommandRouter {
|
|
|
2669
2722
|
cliType,
|
|
2670
2723
|
};
|
|
2671
2724
|
}
|
|
2672
|
-
const
|
|
2725
|
+
const sessionHostRecords = this.deps.sessionHostControl?.listSessions
|
|
2726
|
+
? await this.deps.sessionHostControl.listSessions().catch(() => [])
|
|
2727
|
+
: [];
|
|
2728
|
+
const liveMeshSessions = partitionSessionHostRecords(Array.isArray(sessionHostRecords) ? sessionHostRecords : []).liveRuntimes;
|
|
2729
|
+
const workspace = readLiveMeshNodeWorkspace({
|
|
2730
|
+
meshId,
|
|
2731
|
+
nodeId: String(coordinatorNode.id || coordinatorNode.nodeId || preferredCoordinatorNodeId || ''),
|
|
2732
|
+
liveSessionRecords: liveMeshSessions,
|
|
2733
|
+
allowCoordinatorSession: true,
|
|
2734
|
+
}) || (typeof coordinatorNode.workspace === 'string' ? coordinatorNode.workspace.trim() : '');
|
|
2673
2735
|
if (!workspace) return { success: false, error: 'Coordinator node workspace required', meshId, cliType };
|
|
2674
2736
|
if (!cliType) {
|
|
2675
2737
|
const resolved = await resolveProviderTypeFromPriority({
|
|
@@ -3028,8 +3090,13 @@ export class DaemonCommandRouter {
|
|
|
3028
3090
|
const liveMeshSessions = partitionSessionHostRecords(Array.isArray(sessionHostRecords) ? sessionHostRecords : []).liveRuntimes;
|
|
3029
3091
|
|
|
3030
3092
|
const localMachineId = loadConfig().machineId || '';
|
|
3093
|
+
const selectedCoordinatorNodeId = readStringValue(
|
|
3094
|
+
mesh.coordinator?.preferredNodeId,
|
|
3095
|
+
(mesh.nodes?.[0] as any)?.id,
|
|
3096
|
+
(mesh.nodes?.[0] as any)?.nodeId,
|
|
3097
|
+
);
|
|
3031
3098
|
const inlineCoordinatorNodeId = meshRecord?.inline && Array.isArray(mesh.nodes)
|
|
3032
|
-
?
|
|
3099
|
+
? selectedCoordinatorNodeId
|
|
3033
3100
|
: undefined;
|
|
3034
3101
|
const refreshedAt = new Date().toISOString();
|
|
3035
3102
|
const nodeStatuses = [];
|
|
@@ -3089,8 +3156,20 @@ export class DaemonCommandRouter {
|
|
|
3089
3156
|
reason: 'Node has no daemon id, so mesh transport cannot be reported from the selected coordinator.',
|
|
3090
3157
|
};
|
|
3091
3158
|
}
|
|
3092
|
-
const matchedLiveSessionRecords =
|
|
3093
|
-
|
|
3159
|
+
const matchedLiveSessionRecords = collectLiveMeshSessionRecords({
|
|
3160
|
+
meshId,
|
|
3161
|
+
node,
|
|
3162
|
+
nodeId,
|
|
3163
|
+
liveSessionRecords: liveMeshSessions,
|
|
3164
|
+
allowCoordinatorSession: nodeId === selectedCoordinatorNodeId,
|
|
3165
|
+
});
|
|
3166
|
+
const workspace = readLiveMeshNodeWorkspace({
|
|
3167
|
+
meshId,
|
|
3168
|
+
nodeId,
|
|
3169
|
+
liveSessionRecords: matchedLiveSessionRecords,
|
|
3170
|
+
allowCoordinatorSession: nodeId === selectedCoordinatorNodeId,
|
|
3171
|
+
}) || (typeof node.workspace === 'string' ? node.workspace : '');
|
|
3172
|
+
status.workspace = workspace || node.workspace;
|
|
3094
3173
|
if (matchedLiveSessionRecords.length > 0) {
|
|
3095
3174
|
const sessionIds = matchedLiveSessionRecords
|
|
3096
3175
|
.map((record: any) => typeof record?.sessionId === 'string' ? record.sessionId : '')
|
|
@@ -3104,14 +3183,14 @@ export class DaemonCommandRouter {
|
|
|
3104
3183
|
status.providers = Array.from(new Set([...(Array.isArray(status.providers) ? status.providers as string[] : []), ...providerTypes]));
|
|
3105
3184
|
}
|
|
3106
3185
|
}
|
|
3107
|
-
if (
|
|
3108
|
-
if (!fs.existsSync(
|
|
3186
|
+
if (workspace) {
|
|
3187
|
+
if (!fs.existsSync(workspace) && applyCachedInlineMeshNodeStatus(status, node)) {
|
|
3109
3188
|
status.launchReady = !!daemonId && (readStringValue(status.machineStatus) === 'online' || isSelfNode);
|
|
3110
3189
|
nodeStatuses.push(status);
|
|
3111
3190
|
continue;
|
|
3112
3191
|
}
|
|
3113
3192
|
try {
|
|
3114
|
-
const gitStatus = await getGitRepoStatus(
|
|
3193
|
+
const gitStatus = await getGitRepoStatus(workspace, { timeoutMs: 10_000, refreshUpstream: true });
|
|
3115
3194
|
status.git = gitStatus;
|
|
3116
3195
|
if (gitStatus.isGitRepo) {
|
|
3117
3196
|
status.health = deriveMeshNodeHealthFromGit(gitStatus as unknown as Record<string, unknown>);
|