@adhdev/daemon-core 0.9.82-rc.45 → 0.9.82-rc.47
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 +82 -12
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +82 -12
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/commands/router.ts +95 -11
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);
|
|
@@ -3902,8 +3959,17 @@ export class DaemonCommandRouter {
|
|
|
3902
3959
|
peerConfirmedCount: 0,
|
|
3903
3960
|
unavailableNodeIds: [] as string[],
|
|
3904
3961
|
};
|
|
3962
|
+
// Default/cached loads may not attempt a remote peer probe yet; do not surface that as
|
|
3963
|
+
// a direct mesh truth failure until an explicit probe attempt actually fails.
|
|
3964
|
+
const passivePeerTruthNotAttempted = requireDirectPeerTruth
|
|
3965
|
+
&& !refreshRequested
|
|
3966
|
+
&& directTruth.directEvidenceCount > 0
|
|
3967
|
+
&& directTruth.peerAttemptedCount === 0;
|
|
3968
|
+
const effectiveDirectTruth = passivePeerTruthNotAttempted
|
|
3969
|
+
? { ...directTruth, unavailableNodeIds: [] as string[] }
|
|
3970
|
+
: directTruth;
|
|
3905
3971
|
const directTruthSatisfied = !requireDirectPeerTruth
|
|
3906
|
-
|| (
|
|
3972
|
+
|| (effectiveDirectTruth.directEvidenceCount > 0 && effectiveDirectTruth.unavailableNodeIds.length === 0);
|
|
3907
3973
|
if (requireDirectPeerTruth && !directTruthSatisfied) {
|
|
3908
3974
|
const failureResult = {
|
|
3909
3975
|
success: false,
|
|
@@ -3937,7 +4003,7 @@ export class DaemonCommandRouter {
|
|
|
3937
4003
|
});
|
|
3938
4004
|
return failureResult;
|
|
3939
4005
|
}
|
|
3940
|
-
const directTruthUnavailableNodeIds = new Set(
|
|
4006
|
+
const directTruthUnavailableNodeIds = new Set(effectiveDirectTruth.unavailableNodeIds);
|
|
3941
4007
|
const selectedCoordinatorNodeId = readStringValue(
|
|
3942
4008
|
mesh.coordinator?.preferredNodeId,
|
|
3943
4009
|
(mesh.nodes?.[0] as any)?.id,
|
|
@@ -4041,6 +4107,12 @@ export class DaemonCommandRouter {
|
|
|
4041
4107
|
status.health = inlineTransitGit.isGitRepo
|
|
4042
4108
|
? deriveMeshNodeHealthFromGit(inlineTransitGit as unknown as Record<string, unknown>)
|
|
4043
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
|
+
}
|
|
4044
4116
|
remoteProbeApplied = true;
|
|
4045
4117
|
} else if (!isSelfNode && daemonId && this.deps.dispatchMeshCommand && !directTruthUnavailableNodeIds.has(nodeId)) {
|
|
4046
4118
|
try {
|
|
@@ -4055,6 +4127,12 @@ export class DaemonCommandRouter {
|
|
|
4055
4127
|
status.health = remoteGit.isGitRepo
|
|
4056
4128
|
? deriveMeshNodeHealthFromGit(remoteGit as unknown as Record<string, unknown>)
|
|
4057
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
|
+
}
|
|
4058
4136
|
recordInlineMeshDirectGitTruth(node, remoteGit, 'selected_coordinator_mesh_p2p_git');
|
|
4059
4137
|
remoteProbeApplied = true;
|
|
4060
4138
|
}
|
|
@@ -4075,6 +4153,12 @@ export class DaemonCommandRouter {
|
|
|
4075
4153
|
status.health = remoteGit.isGitRepo
|
|
4076
4154
|
? deriveMeshNodeHealthFromGit(remoteGit as unknown as Record<string, unknown>)
|
|
4077
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
|
+
}
|
|
4078
4162
|
recordInlineMeshDirectGitTruth(node, remoteGit, 'selected_coordinator_mesh_p2p_git');
|
|
4079
4163
|
remoteProbeApplied = true;
|
|
4080
4164
|
}
|
|
@@ -4158,11 +4242,11 @@ export class DaemonCommandRouter {
|
|
|
4158
4242
|
directPeerTruth: {
|
|
4159
4243
|
required: true,
|
|
4160
4244
|
satisfied: directTruthSatisfied,
|
|
4161
|
-
directEvidenceCount:
|
|
4162
|
-
localConfirmedCount:
|
|
4163
|
-
peerAttemptedCount:
|
|
4164
|
-
peerConfirmedCount:
|
|
4165
|
-
unavailableNodeIds:
|
|
4245
|
+
directEvidenceCount: effectiveDirectTruth.directEvidenceCount,
|
|
4246
|
+
localConfirmedCount: effectiveDirectTruth.localConfirmedCount,
|
|
4247
|
+
peerAttemptedCount: effectiveDirectTruth.peerAttemptedCount,
|
|
4248
|
+
peerConfirmedCount: effectiveDirectTruth.peerConfirmedCount,
|
|
4249
|
+
unavailableNodeIds: effectiveDirectTruth.unavailableNodeIds,
|
|
4166
4250
|
},
|
|
4167
4251
|
} : {}),
|
|
4168
4252
|
historicalEvidenceOnly: ['recoveryHints', 'ledger.summary', 'queue.summary'],
|