@adhdev/daemon-core 0.9.82-rc.46 → 0.9.82-rc.48
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 +73 -5
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +73 -5
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/commands/router.ts +79 -4
package/package.json
CHANGED
package/src/commands/router.ts
CHANGED
|
@@ -253,6 +253,22 @@ function normalizeInlineMeshGitStatus(
|
|
|
253
253
|
};
|
|
254
254
|
}
|
|
255
255
|
|
|
256
|
+
function scoreInlineMeshGitStatus(git: Record<string, unknown> | undefined): number {
|
|
257
|
+
if (!git) return Number.NEGATIVE_INFINITY;
|
|
258
|
+
let score = 0;
|
|
259
|
+
if (readBooleanValue(git.isGitRepo) === true) score += 50;
|
|
260
|
+
if (readBooleanValue(git.isGitRepo) === false) score -= 10;
|
|
261
|
+
if (readStringValue(git.branch)) score += 20;
|
|
262
|
+
if (readStringValue(git.headCommit)) score += 20;
|
|
263
|
+
if (readStringValue(git.upstream)) score += 10;
|
|
264
|
+
if (readStringValue(git.upstreamStatus)) score += 5;
|
|
265
|
+
if (readNumberValue(git.ahead) !== undefined) score += 2;
|
|
266
|
+
if (readNumberValue(git.behind) !== undefined) score += 2;
|
|
267
|
+
if (Array.isArray(git.submodules) && git.submodules.length > 0) score += 4 + git.submodules.length;
|
|
268
|
+
if (readStringValue(git.error)) score -= 20;
|
|
269
|
+
return score;
|
|
270
|
+
}
|
|
271
|
+
|
|
256
272
|
function buildInlineMeshTransitGitStatus(node: any): Record<string, unknown> | undefined {
|
|
257
273
|
const rawGit = readObjectRecord(node?.lastGit ?? node?.last_git);
|
|
258
274
|
const gitResult = readObjectRecord(rawGit.result);
|
|
@@ -264,11 +280,38 @@ function buildInlineMeshTransitGitStatus(node: any): Record<string, unknown> | u
|
|
|
264
280
|
const probeDirectStatus = readObjectRecord(probeGit.status);
|
|
265
281
|
const probeNestedStatus = readObjectRecord(probeGitResult.status);
|
|
266
282
|
const candidates = [directStatus, nestedStatus, probeDirectStatus, probeNestedStatus];
|
|
283
|
+
let best: { git: Record<string, unknown>; score: number } | null = null;
|
|
267
284
|
for (const status of candidates) {
|
|
268
285
|
const normalized = normalizeInlineMeshGitStatus(status, node, { lastCheckedAt: Date.now() });
|
|
269
|
-
if (normalized)
|
|
286
|
+
if (!normalized) continue;
|
|
287
|
+
const score = scoreInlineMeshGitStatus(normalized);
|
|
288
|
+
if (!best || score > best.score) best = { git: normalized, score };
|
|
270
289
|
}
|
|
271
|
-
return
|
|
290
|
+
return best?.git;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
function shouldRefreshStalePendingAggregate(snapshot: any, options?: { requireDirectPeerTruth?: boolean }): boolean {
|
|
294
|
+
if (options?.requireDirectPeerTruth !== true || !Array.isArray(snapshot?.nodes)) return false;
|
|
295
|
+
return snapshot.nodes.some((node: any) => {
|
|
296
|
+
if (node?.gitProbePending !== true) return false;
|
|
297
|
+
const git = readObjectRecord(node?.git);
|
|
298
|
+
return !readBooleanValue(git.isGitRepo) && !readStringValue(git.branch, git.headCommit, git.upstream);
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
function buildLivePeerGitConnection(connection: Record<string, unknown>, timestamp = new Date().toISOString()): Record<string, unknown> {
|
|
303
|
+
const source = readStringValue(connection.source);
|
|
304
|
+
const transport = readStringValue(connection.transport);
|
|
305
|
+
return {
|
|
306
|
+
...connection,
|
|
307
|
+
perspective: readStringValue(connection.perspective) ?? 'selected_coordinator',
|
|
308
|
+
source: source && source !== 'not_reported' ? source : 'mesh_peer_status',
|
|
309
|
+
state: 'connected',
|
|
310
|
+
transport: transport && transport !== 'unknown' ? transport : 'direct',
|
|
311
|
+
reported: true,
|
|
312
|
+
reason: 'Live peer git snapshot reported by the selected coordinator.',
|
|
313
|
+
lastStateChangeAt: readStringValue(connection.lastStateChangeAt) ?? timestamp,
|
|
314
|
+
};
|
|
272
315
|
}
|
|
273
316
|
|
|
274
317
|
function recordInlineMeshDirectGitTruth(
|
|
@@ -1468,8 +1511,16 @@ export class DaemonCommandRouter {
|
|
|
1468
1511
|
const nextStatus = { ...statusNode };
|
|
1469
1512
|
nextStatus.git = liveGit;
|
|
1470
1513
|
nextStatus.health = deriveMeshNodeHealthFromGit(liveGit);
|
|
1514
|
+
nextStatus.launchReady = readBooleanValue(nextStatus.launchReady) ?? true;
|
|
1515
|
+
const connection = readObjectRecord(nextStatus.connection);
|
|
1516
|
+
const connectionState = readStringValue(connection.state);
|
|
1517
|
+
const connectionReported = readBooleanValue(connection.reported) ?? false;
|
|
1518
|
+
if (!connectionReported || connectionState === 'unknown') {
|
|
1519
|
+
nextStatus.connection = buildLivePeerGitConnection(connection);
|
|
1520
|
+
}
|
|
1471
1521
|
delete nextStatus.gitProbePending;
|
|
1472
|
-
|
|
1522
|
+
const error = readStringValue(nextStatus.error);
|
|
1523
|
+
if (error && /pending_git|git probe|live peer git snapshot|no peer git snapshot/i.test(error)) delete nextStatus.error;
|
|
1473
1524
|
if (!readStringValue(nextStatus.machineStatus)) nextStatus.machineStatus = 'online';
|
|
1474
1525
|
if (nodeId) unavailableNodeIds.delete(nodeId);
|
|
1475
1526
|
changed = true;
|
|
@@ -1508,6 +1559,7 @@ export class DaemonCommandRouter {
|
|
|
1508
1559
|
if (!cached?.snapshot || cached.snapshot.success !== true || !Array.isArray(cached.snapshot.nodes)) return null;
|
|
1509
1560
|
let snapshot = this.cloneJsonValue(cached.snapshot);
|
|
1510
1561
|
snapshot = this.hydrateCachedAggregateMeshStatusFromInline(snapshot, mesh, options);
|
|
1562
|
+
if (shouldRefreshStalePendingAggregate(snapshot, options)) return null;
|
|
1511
1563
|
const ageMs = Math.max(0, Date.now() - cached.builtAt);
|
|
1512
1564
|
const sourceOfTruth = snapshot.sourceOfTruth && typeof snapshot.sourceOfTruth === 'object'
|
|
1513
1565
|
? snapshot.sourceOfTruth
|
|
@@ -3859,6 +3911,7 @@ export class DaemonCommandRouter {
|
|
|
3859
3911
|
if (!mesh) return { success: false, error: 'Mesh not found' };
|
|
3860
3912
|
|
|
3861
3913
|
const refreshRequested = args?.refresh === true || args?.forceRefresh === true;
|
|
3914
|
+
const hadAggregateCache = this.aggregateMeshStatusCache.has(meshId);
|
|
3862
3915
|
if (!refreshRequested) {
|
|
3863
3916
|
const cachedStatus = this.getCachedAggregateMeshStatus(meshId, mesh, { requireDirectPeerTruth: args?.requireDirectPeerTruth === true });
|
|
3864
3917
|
if (cachedStatus) {
|
|
@@ -3871,7 +3924,11 @@ export class DaemonCommandRouter {
|
|
|
3871
3924
|
return cachedStatus;
|
|
3872
3925
|
}
|
|
3873
3926
|
}
|
|
3874
|
-
const refreshReason = refreshRequested
|
|
3927
|
+
const refreshReason = refreshRequested
|
|
3928
|
+
? 'explicit_refresh'
|
|
3929
|
+
: hadAggregateCache
|
|
3930
|
+
? 'stale_pending_cache_refresh'
|
|
3931
|
+
: 'cold_cache_miss';
|
|
3875
3932
|
|
|
3876
3933
|
const { getMeshQueueStats, getQueue } = await import('../mesh/mesh-work-queue.js');
|
|
3877
3934
|
const queue = getQueue(meshId);
|
|
@@ -4050,6 +4107,12 @@ export class DaemonCommandRouter {
|
|
|
4050
4107
|
status.health = inlineTransitGit.isGitRepo
|
|
4051
4108
|
? deriveMeshNodeHealthFromGit(inlineTransitGit as unknown as Record<string, unknown>)
|
|
4052
4109
|
: 'degraded';
|
|
4110
|
+
const connection = readObjectRecord(status.connection);
|
|
4111
|
+
const connectionState = readStringValue(connection.state);
|
|
4112
|
+
const connectionReported = readBooleanValue(connection.reported) ?? false;
|
|
4113
|
+
if (!connectionReported || connectionState === 'unknown') {
|
|
4114
|
+
status.connection = buildLivePeerGitConnection(connection, refreshedAt);
|
|
4115
|
+
}
|
|
4053
4116
|
remoteProbeApplied = true;
|
|
4054
4117
|
} else if (!isSelfNode && daemonId && this.deps.dispatchMeshCommand && !directTruthUnavailableNodeIds.has(nodeId)) {
|
|
4055
4118
|
try {
|
|
@@ -4064,6 +4127,12 @@ export class DaemonCommandRouter {
|
|
|
4064
4127
|
status.health = remoteGit.isGitRepo
|
|
4065
4128
|
? deriveMeshNodeHealthFromGit(remoteGit as unknown as Record<string, unknown>)
|
|
4066
4129
|
: 'degraded';
|
|
4130
|
+
const connection = readObjectRecord(status.connection);
|
|
4131
|
+
const connectionState = readStringValue(connection.state);
|
|
4132
|
+
const connectionReported = readBooleanValue(connection.reported) ?? false;
|
|
4133
|
+
if (!connectionReported || connectionState === 'unknown') {
|
|
4134
|
+
status.connection = buildLivePeerGitConnection(connection, refreshedAt);
|
|
4135
|
+
}
|
|
4067
4136
|
recordInlineMeshDirectGitTruth(node, remoteGit, 'selected_coordinator_mesh_p2p_git');
|
|
4068
4137
|
remoteProbeApplied = true;
|
|
4069
4138
|
}
|
|
@@ -4084,6 +4153,12 @@ export class DaemonCommandRouter {
|
|
|
4084
4153
|
status.health = remoteGit.isGitRepo
|
|
4085
4154
|
? deriveMeshNodeHealthFromGit(remoteGit as unknown as Record<string, unknown>)
|
|
4086
4155
|
: 'degraded';
|
|
4156
|
+
const connection = readObjectRecord(status.connection);
|
|
4157
|
+
const connectionState = readStringValue(connection.state);
|
|
4158
|
+
const connectionReported = readBooleanValue(connection.reported) ?? false;
|
|
4159
|
+
if (!connectionReported || connectionState === 'unknown') {
|
|
4160
|
+
status.connection = buildLivePeerGitConnection(connection, refreshedAt);
|
|
4161
|
+
}
|
|
4087
4162
|
recordInlineMeshDirectGitTruth(node, remoteGit, 'selected_coordinator_mesh_p2p_git');
|
|
4088
4163
|
remoteProbeApplied = true;
|
|
4089
4164
|
}
|