@adhdev/daemon-core 0.9.82-rc.5 → 0.9.82-rc.7
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 +44 -7
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +44 -7
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/commands/router.ts +55 -7
package/package.json
CHANGED
package/src/commands/router.ts
CHANGED
|
@@ -222,26 +222,63 @@ function buildCachedInlineMeshGitStatus(node: any): Record<string, unknown> | un
|
|
|
222
222
|
};
|
|
223
223
|
}
|
|
224
224
|
|
|
225
|
+
function hasGitWorktreeChanges(git: Record<string, unknown> | null | undefined): boolean {
|
|
226
|
+
if (!git) return false;
|
|
227
|
+
return Number(git.staged || 0) + Number(git.modified || 0) + Number(git.untracked || 0) + Number(git.deleted || 0) + Number(git.renamed || 0) > 0;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
function getGitSubmoduleDriftState(git: Record<string, unknown> | null | undefined): { dirty: boolean; outOfSync: boolean } {
|
|
231
|
+
const submodules = Array.isArray(git?.submodules) ? git.submodules : [];
|
|
232
|
+
let dirty = false;
|
|
233
|
+
let outOfSync = false;
|
|
234
|
+
for (const entry of submodules) {
|
|
235
|
+
const submodule = readObjectRecord(entry);
|
|
236
|
+
if (readBooleanValue(submodule.dirty) === true) dirty = true;
|
|
237
|
+
if (readBooleanValue(submodule.outOfSync) === true || !!readStringValue(submodule.error)) outOfSync = true;
|
|
238
|
+
}
|
|
239
|
+
return { dirty, outOfSync };
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
function deriveMeshNodeHealthFromGit(git: Record<string, unknown> | null | undefined): 'online' | 'dirty' | 'degraded' {
|
|
243
|
+
if (!git || readBooleanValue(git.isGitRepo) === false) return 'degraded';
|
|
244
|
+
const branch = readStringValue(git.branch);
|
|
245
|
+
if (!branch) return 'degraded';
|
|
246
|
+
const submoduleDrift = getGitSubmoduleDriftState(git);
|
|
247
|
+
if (submoduleDrift.outOfSync) return 'degraded';
|
|
248
|
+
if (submoduleDrift.dirty || hasGitWorktreeChanges(git)) return 'dirty';
|
|
249
|
+
return 'online';
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
function readCachedInlineMeshActiveSessions(node: any): string[] {
|
|
253
|
+
const cachedStatus = readObjectRecord(node?.cachedStatus);
|
|
254
|
+
const activeSession = readObjectRecord(cachedStatus.activeSession);
|
|
255
|
+
const fallbackSession = Object.keys(activeSession).length
|
|
256
|
+
? activeSession
|
|
257
|
+
: readObjectRecord(node?.activeSession ?? node?.active_session);
|
|
258
|
+
const sessionId = readStringValue(fallbackSession.id, fallbackSession.sessionId, fallbackSession.session_id, node?.activeSessionId, node?.active_session_id, node?.sessionId, node?.session_id);
|
|
259
|
+
return sessionId ? [sessionId] : [];
|
|
260
|
+
}
|
|
261
|
+
|
|
225
262
|
function applyCachedInlineMeshNodeStatus(status: Record<string, unknown>, node: any): boolean {
|
|
226
263
|
const cachedStatus = readObjectRecord(node?.cachedStatus);
|
|
227
264
|
const git = buildCachedInlineMeshGitStatus(node);
|
|
228
265
|
const error = readStringValue(cachedStatus.error, node?.error);
|
|
229
266
|
const health = readStringValue(cachedStatus.health, node?.health);
|
|
230
267
|
const machineStatus = readStringValue(cachedStatus.machineStatus, node?.machineStatus);
|
|
231
|
-
|
|
232
|
-
if (!
|
|
268
|
+
const activeSessions = readCachedInlineMeshActiveSessions(node);
|
|
269
|
+
if (!git && !error && !health && !machineStatus && activeSessions.length === 0) return false;
|
|
233
270
|
if (git) status.git = git;
|
|
234
271
|
if (error) status.error = error;
|
|
272
|
+
if (activeSessions.length > 0) status.activeSessions = activeSessions;
|
|
235
273
|
if (health) {
|
|
236
274
|
status.health = health;
|
|
237
275
|
return true;
|
|
238
276
|
}
|
|
239
277
|
if (git) {
|
|
240
|
-
|
|
241
|
-
status.health = git.isGitRepo === false ? 'degraded' : dirty ? 'dirty' : 'online';
|
|
278
|
+
status.health = deriveMeshNodeHealthFromGit(git);
|
|
242
279
|
return true;
|
|
243
280
|
}
|
|
244
|
-
return
|
|
281
|
+
return activeSessions.length > 0 || !!machineStatus;
|
|
245
282
|
}
|
|
246
283
|
|
|
247
284
|
async function resolveProviderTypeFromPriority(args: {
|
|
@@ -2913,6 +2950,10 @@ export class DaemonCommandRouter {
|
|
|
2913
2950
|
const { readLedgerEntries, getLedgerSummary } = await import('../mesh/mesh-ledger.js');
|
|
2914
2951
|
const ledgerEntries = readLedgerEntries(meshId, { tail: 20 });
|
|
2915
2952
|
const ledgerSummary = getLedgerSummary(meshId);
|
|
2953
|
+
const sessionHostRecords = this.deps.sessionHostControl?.listSessions
|
|
2954
|
+
? await this.deps.sessionHostControl.listSessions().catch(() => [])
|
|
2955
|
+
: [];
|
|
2956
|
+
const liveMeshSessions = partitionSessionHostRecords(Array.isArray(sessionHostRecords) ? sessionHostRecords : []).liveRuntimes;
|
|
2916
2957
|
|
|
2917
2958
|
const nodeStatuses = [];
|
|
2918
2959
|
for (const node of mesh.nodes || []) {
|
|
@@ -2929,6 +2970,14 @@ export class DaemonCommandRouter {
|
|
|
2929
2970
|
providers: node.providers || [],
|
|
2930
2971
|
activeSessions: [],
|
|
2931
2972
|
};
|
|
2973
|
+
const nodeId = String(node.id || node.nodeId || '');
|
|
2974
|
+
const matchedLiveSessions = liveMeshSessions
|
|
2975
|
+
.filter((record) => this.sessionMatchesMeshNode(record, node, nodeId))
|
|
2976
|
+
.map((record: any) => typeof record?.sessionId === 'string' ? record.sessionId : '')
|
|
2977
|
+
.filter(Boolean);
|
|
2978
|
+
if (matchedLiveSessions.length > 0) {
|
|
2979
|
+
status.activeSessions = matchedLiveSessions;
|
|
2980
|
+
}
|
|
2932
2981
|
if (node.workspace && typeof node.workspace === 'string') {
|
|
2933
2982
|
if (!fs.existsSync(node.workspace as string) && applyCachedInlineMeshNodeStatus(status, node)) {
|
|
2934
2983
|
nodeStatuses.push(status);
|
|
@@ -2938,8 +2987,7 @@ export class DaemonCommandRouter {
|
|
|
2938
2987
|
const gitStatus = await getGitRepoStatus(node.workspace as string, { timeoutMs: 10_000 });
|
|
2939
2988
|
status.git = gitStatus;
|
|
2940
2989
|
if (gitStatus.isGitRepo) {
|
|
2941
|
-
|
|
2942
|
-
status.health = gitStatus.branch ? (dirty ? 'dirty' : 'online') : 'degraded';
|
|
2990
|
+
status.health = deriveMeshNodeHealthFromGit(gitStatus as unknown as Record<string, unknown>);
|
|
2943
2991
|
} else {
|
|
2944
2992
|
status.health = 'degraded';
|
|
2945
2993
|
if (gitStatus.error && !status.error) status.error = gitStatus.error;
|