@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/dist/index.js
CHANGED
|
@@ -24194,6 +24194,21 @@ function normalizeInlineMeshGitStatus(status, node, options) {
|
|
|
24194
24194
|
...submodules ? { submodules } : {}
|
|
24195
24195
|
};
|
|
24196
24196
|
}
|
|
24197
|
+
function scoreInlineMeshGitStatus(git) {
|
|
24198
|
+
if (!git) return Number.NEGATIVE_INFINITY;
|
|
24199
|
+
let score = 0;
|
|
24200
|
+
if (readBooleanValue(git.isGitRepo) === true) score += 50;
|
|
24201
|
+
if (readBooleanValue(git.isGitRepo) === false) score -= 10;
|
|
24202
|
+
if (readStringValue(git.branch)) score += 20;
|
|
24203
|
+
if (readStringValue(git.headCommit)) score += 20;
|
|
24204
|
+
if (readStringValue(git.upstream)) score += 10;
|
|
24205
|
+
if (readStringValue(git.upstreamStatus)) score += 5;
|
|
24206
|
+
if (readNumberValue(git.ahead) !== void 0) score += 2;
|
|
24207
|
+
if (readNumberValue(git.behind) !== void 0) score += 2;
|
|
24208
|
+
if (Array.isArray(git.submodules) && git.submodules.length > 0) score += 4 + git.submodules.length;
|
|
24209
|
+
if (readStringValue(git.error)) score -= 20;
|
|
24210
|
+
return score;
|
|
24211
|
+
}
|
|
24197
24212
|
function buildInlineMeshTransitGitStatus(node) {
|
|
24198
24213
|
const rawGit = readObjectRecord(node?.lastGit ?? node?.last_git);
|
|
24199
24214
|
const gitResult = readObjectRecord(rawGit.result);
|
|
@@ -24205,11 +24220,36 @@ function buildInlineMeshTransitGitStatus(node) {
|
|
|
24205
24220
|
const probeDirectStatus = readObjectRecord(probeGit.status);
|
|
24206
24221
|
const probeNestedStatus = readObjectRecord(probeGitResult.status);
|
|
24207
24222
|
const candidates = [directStatus, nestedStatus, probeDirectStatus, probeNestedStatus];
|
|
24223
|
+
let best = null;
|
|
24208
24224
|
for (const status of candidates) {
|
|
24209
24225
|
const normalized = normalizeInlineMeshGitStatus(status, node, { lastCheckedAt: Date.now() });
|
|
24210
|
-
if (normalized)
|
|
24211
|
-
|
|
24212
|
-
|
|
24226
|
+
if (!normalized) continue;
|
|
24227
|
+
const score = scoreInlineMeshGitStatus(normalized);
|
|
24228
|
+
if (!best || score > best.score) best = { git: normalized, score };
|
|
24229
|
+
}
|
|
24230
|
+
return best?.git;
|
|
24231
|
+
}
|
|
24232
|
+
function shouldRefreshStalePendingAggregate(snapshot, options) {
|
|
24233
|
+
if (options?.requireDirectPeerTruth !== true || !Array.isArray(snapshot?.nodes)) return false;
|
|
24234
|
+
return snapshot.nodes.some((node) => {
|
|
24235
|
+
if (node?.gitProbePending !== true) return false;
|
|
24236
|
+
const git = readObjectRecord(node?.git);
|
|
24237
|
+
return !readBooleanValue(git.isGitRepo) && !readStringValue(git.branch, git.headCommit, git.upstream);
|
|
24238
|
+
});
|
|
24239
|
+
}
|
|
24240
|
+
function buildLivePeerGitConnection(connection, timestamp = (/* @__PURE__ */ new Date()).toISOString()) {
|
|
24241
|
+
const source = readStringValue(connection.source);
|
|
24242
|
+
const transport = readStringValue(connection.transport);
|
|
24243
|
+
return {
|
|
24244
|
+
...connection,
|
|
24245
|
+
perspective: readStringValue(connection.perspective) ?? "selected_coordinator",
|
|
24246
|
+
source: source && source !== "not_reported" ? source : "mesh_peer_status",
|
|
24247
|
+
state: "connected",
|
|
24248
|
+
transport: transport && transport !== "unknown" ? transport : "direct",
|
|
24249
|
+
reported: true,
|
|
24250
|
+
reason: "Live peer git snapshot reported by the selected coordinator.",
|
|
24251
|
+
lastStateChangeAt: readStringValue(connection.lastStateChangeAt) ?? timestamp
|
|
24252
|
+
};
|
|
24213
24253
|
}
|
|
24214
24254
|
function recordInlineMeshDirectGitTruth(node, git, source) {
|
|
24215
24255
|
if (!node || typeof node !== "object" || Array.isArray(node)) return;
|
|
@@ -25103,8 +25143,16 @@ var DaemonCommandRouter = class {
|
|
|
25103
25143
|
const nextStatus = { ...statusNode };
|
|
25104
25144
|
nextStatus.git = liveGit;
|
|
25105
25145
|
nextStatus.health = deriveMeshNodeHealthFromGit(liveGit);
|
|
25146
|
+
nextStatus.launchReady = readBooleanValue(nextStatus.launchReady) ?? true;
|
|
25147
|
+
const connection = readObjectRecord(nextStatus.connection);
|
|
25148
|
+
const connectionState = readStringValue(connection.state);
|
|
25149
|
+
const connectionReported = readBooleanValue(connection.reported) ?? false;
|
|
25150
|
+
if (!connectionReported || connectionState === "unknown") {
|
|
25151
|
+
nextStatus.connection = buildLivePeerGitConnection(connection);
|
|
25152
|
+
}
|
|
25106
25153
|
delete nextStatus.gitProbePending;
|
|
25107
|
-
|
|
25154
|
+
const error = readStringValue(nextStatus.error);
|
|
25155
|
+
if (error && /pending_git|git probe|live peer git snapshot|no peer git snapshot/i.test(error)) delete nextStatus.error;
|
|
25108
25156
|
if (!readStringValue(nextStatus.machineStatus)) nextStatus.machineStatus = "online";
|
|
25109
25157
|
if (nodeId) unavailableNodeIds.delete(nodeId);
|
|
25110
25158
|
changed = true;
|
|
@@ -25141,6 +25189,7 @@ var DaemonCommandRouter = class {
|
|
|
25141
25189
|
if (!cached?.snapshot || cached.snapshot.success !== true || !Array.isArray(cached.snapshot.nodes)) return null;
|
|
25142
25190
|
let snapshot = this.cloneJsonValue(cached.snapshot);
|
|
25143
25191
|
snapshot = this.hydrateCachedAggregateMeshStatusFromInline(snapshot, mesh, options);
|
|
25192
|
+
if (shouldRefreshStalePendingAggregate(snapshot, options)) return null;
|
|
25144
25193
|
const ageMs = Math.max(0, Date.now() - cached.builtAt);
|
|
25145
25194
|
const sourceOfTruth = snapshot.sourceOfTruth && typeof snapshot.sourceOfTruth === "object" ? snapshot.sourceOfTruth : {};
|
|
25146
25195
|
snapshot.sourceOfTruth = {
|
|
@@ -27186,6 +27235,7 @@ ${block}`);
|
|
|
27186
27235
|
const mesh = meshRecord?.mesh;
|
|
27187
27236
|
if (!mesh) return { success: false, error: "Mesh not found" };
|
|
27188
27237
|
const refreshRequested = args?.refresh === true || args?.forceRefresh === true;
|
|
27238
|
+
const hadAggregateCache = this.aggregateMeshStatusCache.has(meshId);
|
|
27189
27239
|
if (!refreshRequested) {
|
|
27190
27240
|
const cachedStatus = this.getCachedAggregateMeshStatus(meshId, mesh, { requireDirectPeerTruth: args?.requireDirectPeerTruth === true });
|
|
27191
27241
|
if (cachedStatus) {
|
|
@@ -27198,7 +27248,7 @@ ${block}`);
|
|
|
27198
27248
|
return cachedStatus;
|
|
27199
27249
|
}
|
|
27200
27250
|
}
|
|
27201
|
-
const refreshReason = refreshRequested ? "explicit_refresh" : "cold_cache_miss";
|
|
27251
|
+
const refreshReason = refreshRequested ? "explicit_refresh" : hadAggregateCache ? "stale_pending_cache_refresh" : "cold_cache_miss";
|
|
27202
27252
|
const { getMeshQueueStats: getMeshQueueStats2, getQueue: getQueue2 } = await Promise.resolve().then(() => (init_mesh_work_queue(), mesh_work_queue_exports));
|
|
27203
27253
|
const queue = getQueue2(meshId);
|
|
27204
27254
|
const queueSummary = getMeshQueueStats2(meshId);
|
|
@@ -27222,7 +27272,9 @@ ${block}`);
|
|
|
27222
27272
|
peerConfirmedCount: 0,
|
|
27223
27273
|
unavailableNodeIds: []
|
|
27224
27274
|
};
|
|
27225
|
-
const
|
|
27275
|
+
const passivePeerTruthNotAttempted = requireDirectPeerTruth && !refreshRequested && directTruth.directEvidenceCount > 0 && directTruth.peerAttemptedCount === 0;
|
|
27276
|
+
const effectiveDirectTruth = passivePeerTruthNotAttempted ? { ...directTruth, unavailableNodeIds: [] } : directTruth;
|
|
27277
|
+
const directTruthSatisfied = !requireDirectPeerTruth || effectiveDirectTruth.directEvidenceCount > 0 && effectiveDirectTruth.unavailableNodeIds.length === 0;
|
|
27226
27278
|
if (requireDirectPeerTruth && !directTruthSatisfied) {
|
|
27227
27279
|
const failureResult = {
|
|
27228
27280
|
success: false,
|
|
@@ -27252,7 +27304,7 @@ ${block}`);
|
|
|
27252
27304
|
});
|
|
27253
27305
|
return failureResult;
|
|
27254
27306
|
}
|
|
27255
|
-
const directTruthUnavailableNodeIds = new Set(
|
|
27307
|
+
const directTruthUnavailableNodeIds = new Set(effectiveDirectTruth.unavailableNodeIds);
|
|
27256
27308
|
const selectedCoordinatorNodeId = readStringValue(
|
|
27257
27309
|
mesh.coordinator?.preferredNodeId,
|
|
27258
27310
|
mesh.nodes?.[0]?.id,
|
|
@@ -27347,6 +27399,12 @@ ${block}`);
|
|
|
27347
27399
|
if (inlineTransitGit) {
|
|
27348
27400
|
status.git = inlineTransitGit;
|
|
27349
27401
|
status.health = inlineTransitGit.isGitRepo ? deriveMeshNodeHealthFromGit(inlineTransitGit) : "degraded";
|
|
27402
|
+
const connection = readObjectRecord(status.connection);
|
|
27403
|
+
const connectionState = readStringValue(connection.state);
|
|
27404
|
+
const connectionReported = readBooleanValue(connection.reported) ?? false;
|
|
27405
|
+
if (!connectionReported || connectionState === "unknown") {
|
|
27406
|
+
status.connection = buildLivePeerGitConnection(connection, refreshedAt);
|
|
27407
|
+
}
|
|
27350
27408
|
remoteProbeApplied = true;
|
|
27351
27409
|
} else if (!isSelfNode && daemonId && this.deps.dispatchMeshCommand && !directTruthUnavailableNodeIds.has(nodeId)) {
|
|
27352
27410
|
try {
|
|
@@ -27359,6 +27417,12 @@ ${block}`);
|
|
|
27359
27417
|
if (remoteGit) {
|
|
27360
27418
|
status.git = remoteGit;
|
|
27361
27419
|
status.health = remoteGit.isGitRepo ? deriveMeshNodeHealthFromGit(remoteGit) : "degraded";
|
|
27420
|
+
const connection = readObjectRecord(status.connection);
|
|
27421
|
+
const connectionState = readStringValue(connection.state);
|
|
27422
|
+
const connectionReported = readBooleanValue(connection.reported) ?? false;
|
|
27423
|
+
if (!connectionReported || connectionState === "unknown") {
|
|
27424
|
+
status.connection = buildLivePeerGitConnection(connection, refreshedAt);
|
|
27425
|
+
}
|
|
27362
27426
|
recordInlineMeshDirectGitTruth(node, remoteGit, "selected_coordinator_mesh_p2p_git");
|
|
27363
27427
|
remoteProbeApplied = true;
|
|
27364
27428
|
}
|
|
@@ -27377,6 +27441,12 @@ ${block}`);
|
|
|
27377
27441
|
if (remoteGit) {
|
|
27378
27442
|
status.git = remoteGit;
|
|
27379
27443
|
status.health = remoteGit.isGitRepo ? deriveMeshNodeHealthFromGit(remoteGit) : "degraded";
|
|
27444
|
+
const connection = readObjectRecord(status.connection);
|
|
27445
|
+
const connectionState = readStringValue(connection.state);
|
|
27446
|
+
const connectionReported = readBooleanValue(connection.reported) ?? false;
|
|
27447
|
+
if (!connectionReported || connectionState === "unknown") {
|
|
27448
|
+
status.connection = buildLivePeerGitConnection(connection, refreshedAt);
|
|
27449
|
+
}
|
|
27380
27450
|
recordInlineMeshDirectGitTruth(node, remoteGit, "selected_coordinator_mesh_p2p_git");
|
|
27381
27451
|
remoteProbeApplied = true;
|
|
27382
27452
|
}
|
|
@@ -27445,11 +27515,11 @@ ${block}`);
|
|
|
27445
27515
|
directPeerTruth: {
|
|
27446
27516
|
required: true,
|
|
27447
27517
|
satisfied: directTruthSatisfied,
|
|
27448
|
-
directEvidenceCount:
|
|
27449
|
-
localConfirmedCount:
|
|
27450
|
-
peerAttemptedCount:
|
|
27451
|
-
peerConfirmedCount:
|
|
27452
|
-
unavailableNodeIds:
|
|
27518
|
+
directEvidenceCount: effectiveDirectTruth.directEvidenceCount,
|
|
27519
|
+
localConfirmedCount: effectiveDirectTruth.localConfirmedCount,
|
|
27520
|
+
peerAttemptedCount: effectiveDirectTruth.peerAttemptedCount,
|
|
27521
|
+
peerConfirmedCount: effectiveDirectTruth.peerConfirmedCount,
|
|
27522
|
+
unavailableNodeIds: effectiveDirectTruth.unavailableNodeIds
|
|
27453
27523
|
}
|
|
27454
27524
|
} : {},
|
|
27455
27525
|
historicalEvidenceOnly: ["recoveryHints", "ledger.summary", "queue.summary"]
|