@adhdev/daemon-core 0.9.82-rc.46 → 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 +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/dist/index.mjs
CHANGED
|
@@ -23961,6 +23961,21 @@ function normalizeInlineMeshGitStatus(status, node, options) {
|
|
|
23961
23961
|
...submodules ? { submodules } : {}
|
|
23962
23962
|
};
|
|
23963
23963
|
}
|
|
23964
|
+
function scoreInlineMeshGitStatus(git) {
|
|
23965
|
+
if (!git) return Number.NEGATIVE_INFINITY;
|
|
23966
|
+
let score = 0;
|
|
23967
|
+
if (readBooleanValue(git.isGitRepo) === true) score += 50;
|
|
23968
|
+
if (readBooleanValue(git.isGitRepo) === false) score -= 10;
|
|
23969
|
+
if (readStringValue(git.branch)) score += 20;
|
|
23970
|
+
if (readStringValue(git.headCommit)) score += 20;
|
|
23971
|
+
if (readStringValue(git.upstream)) score += 10;
|
|
23972
|
+
if (readStringValue(git.upstreamStatus)) score += 5;
|
|
23973
|
+
if (readNumberValue(git.ahead) !== void 0) score += 2;
|
|
23974
|
+
if (readNumberValue(git.behind) !== void 0) score += 2;
|
|
23975
|
+
if (Array.isArray(git.submodules) && git.submodules.length > 0) score += 4 + git.submodules.length;
|
|
23976
|
+
if (readStringValue(git.error)) score -= 20;
|
|
23977
|
+
return score;
|
|
23978
|
+
}
|
|
23964
23979
|
function buildInlineMeshTransitGitStatus(node) {
|
|
23965
23980
|
const rawGit = readObjectRecord(node?.lastGit ?? node?.last_git);
|
|
23966
23981
|
const gitResult = readObjectRecord(rawGit.result);
|
|
@@ -23972,11 +23987,36 @@ function buildInlineMeshTransitGitStatus(node) {
|
|
|
23972
23987
|
const probeDirectStatus = readObjectRecord(probeGit.status);
|
|
23973
23988
|
const probeNestedStatus = readObjectRecord(probeGitResult.status);
|
|
23974
23989
|
const candidates = [directStatus, nestedStatus, probeDirectStatus, probeNestedStatus];
|
|
23990
|
+
let best = null;
|
|
23975
23991
|
for (const status of candidates) {
|
|
23976
23992
|
const normalized = normalizeInlineMeshGitStatus(status, node, { lastCheckedAt: Date.now() });
|
|
23977
|
-
if (normalized)
|
|
23978
|
-
|
|
23979
|
-
|
|
23993
|
+
if (!normalized) continue;
|
|
23994
|
+
const score = scoreInlineMeshGitStatus(normalized);
|
|
23995
|
+
if (!best || score > best.score) best = { git: normalized, score };
|
|
23996
|
+
}
|
|
23997
|
+
return best?.git;
|
|
23998
|
+
}
|
|
23999
|
+
function shouldRefreshStalePendingAggregate(snapshot, options) {
|
|
24000
|
+
if (options?.requireDirectPeerTruth !== true || !Array.isArray(snapshot?.nodes)) return false;
|
|
24001
|
+
return snapshot.nodes.some((node) => {
|
|
24002
|
+
if (node?.gitProbePending !== true) return false;
|
|
24003
|
+
const git = readObjectRecord(node?.git);
|
|
24004
|
+
return !readBooleanValue(git.isGitRepo) && !readStringValue(git.branch, git.headCommit, git.upstream);
|
|
24005
|
+
});
|
|
24006
|
+
}
|
|
24007
|
+
function buildLivePeerGitConnection(connection, timestamp = (/* @__PURE__ */ new Date()).toISOString()) {
|
|
24008
|
+
const source = readStringValue(connection.source);
|
|
24009
|
+
const transport = readStringValue(connection.transport);
|
|
24010
|
+
return {
|
|
24011
|
+
...connection,
|
|
24012
|
+
perspective: readStringValue(connection.perspective) ?? "selected_coordinator",
|
|
24013
|
+
source: source && source !== "not_reported" ? source : "mesh_peer_status",
|
|
24014
|
+
state: "connected",
|
|
24015
|
+
transport: transport && transport !== "unknown" ? transport : "direct",
|
|
24016
|
+
reported: true,
|
|
24017
|
+
reason: "Live peer git snapshot reported by the selected coordinator.",
|
|
24018
|
+
lastStateChangeAt: readStringValue(connection.lastStateChangeAt) ?? timestamp
|
|
24019
|
+
};
|
|
23980
24020
|
}
|
|
23981
24021
|
function recordInlineMeshDirectGitTruth(node, git, source) {
|
|
23982
24022
|
if (!node || typeof node !== "object" || Array.isArray(node)) return;
|
|
@@ -24870,8 +24910,16 @@ var DaemonCommandRouter = class {
|
|
|
24870
24910
|
const nextStatus = { ...statusNode };
|
|
24871
24911
|
nextStatus.git = liveGit;
|
|
24872
24912
|
nextStatus.health = deriveMeshNodeHealthFromGit(liveGit);
|
|
24913
|
+
nextStatus.launchReady = readBooleanValue(nextStatus.launchReady) ?? true;
|
|
24914
|
+
const connection = readObjectRecord(nextStatus.connection);
|
|
24915
|
+
const connectionState = readStringValue(connection.state);
|
|
24916
|
+
const connectionReported = readBooleanValue(connection.reported) ?? false;
|
|
24917
|
+
if (!connectionReported || connectionState === "unknown") {
|
|
24918
|
+
nextStatus.connection = buildLivePeerGitConnection(connection);
|
|
24919
|
+
}
|
|
24873
24920
|
delete nextStatus.gitProbePending;
|
|
24874
|
-
|
|
24921
|
+
const error = readStringValue(nextStatus.error);
|
|
24922
|
+
if (error && /pending_git|git probe|live peer git snapshot|no peer git snapshot/i.test(error)) delete nextStatus.error;
|
|
24875
24923
|
if (!readStringValue(nextStatus.machineStatus)) nextStatus.machineStatus = "online";
|
|
24876
24924
|
if (nodeId) unavailableNodeIds.delete(nodeId);
|
|
24877
24925
|
changed = true;
|
|
@@ -24908,6 +24956,7 @@ var DaemonCommandRouter = class {
|
|
|
24908
24956
|
if (!cached?.snapshot || cached.snapshot.success !== true || !Array.isArray(cached.snapshot.nodes)) return null;
|
|
24909
24957
|
let snapshot = this.cloneJsonValue(cached.snapshot);
|
|
24910
24958
|
snapshot = this.hydrateCachedAggregateMeshStatusFromInline(snapshot, mesh, options);
|
|
24959
|
+
if (shouldRefreshStalePendingAggregate(snapshot, options)) return null;
|
|
24911
24960
|
const ageMs = Math.max(0, Date.now() - cached.builtAt);
|
|
24912
24961
|
const sourceOfTruth = snapshot.sourceOfTruth && typeof snapshot.sourceOfTruth === "object" ? snapshot.sourceOfTruth : {};
|
|
24913
24962
|
snapshot.sourceOfTruth = {
|
|
@@ -26953,6 +27002,7 @@ ${block}`);
|
|
|
26953
27002
|
const mesh = meshRecord?.mesh;
|
|
26954
27003
|
if (!mesh) return { success: false, error: "Mesh not found" };
|
|
26955
27004
|
const refreshRequested = args?.refresh === true || args?.forceRefresh === true;
|
|
27005
|
+
const hadAggregateCache = this.aggregateMeshStatusCache.has(meshId);
|
|
26956
27006
|
if (!refreshRequested) {
|
|
26957
27007
|
const cachedStatus = this.getCachedAggregateMeshStatus(meshId, mesh, { requireDirectPeerTruth: args?.requireDirectPeerTruth === true });
|
|
26958
27008
|
if (cachedStatus) {
|
|
@@ -26965,7 +27015,7 @@ ${block}`);
|
|
|
26965
27015
|
return cachedStatus;
|
|
26966
27016
|
}
|
|
26967
27017
|
}
|
|
26968
|
-
const refreshReason = refreshRequested ? "explicit_refresh" : "cold_cache_miss";
|
|
27018
|
+
const refreshReason = refreshRequested ? "explicit_refresh" : hadAggregateCache ? "stale_pending_cache_refresh" : "cold_cache_miss";
|
|
26969
27019
|
const { getMeshQueueStats: getMeshQueueStats2, getQueue: getQueue2 } = await Promise.resolve().then(() => (init_mesh_work_queue(), mesh_work_queue_exports));
|
|
26970
27020
|
const queue = getQueue2(meshId);
|
|
26971
27021
|
const queueSummary = getMeshQueueStats2(meshId);
|
|
@@ -27116,6 +27166,12 @@ ${block}`);
|
|
|
27116
27166
|
if (inlineTransitGit) {
|
|
27117
27167
|
status.git = inlineTransitGit;
|
|
27118
27168
|
status.health = inlineTransitGit.isGitRepo ? deriveMeshNodeHealthFromGit(inlineTransitGit) : "degraded";
|
|
27169
|
+
const connection = readObjectRecord(status.connection);
|
|
27170
|
+
const connectionState = readStringValue(connection.state);
|
|
27171
|
+
const connectionReported = readBooleanValue(connection.reported) ?? false;
|
|
27172
|
+
if (!connectionReported || connectionState === "unknown") {
|
|
27173
|
+
status.connection = buildLivePeerGitConnection(connection, refreshedAt);
|
|
27174
|
+
}
|
|
27119
27175
|
remoteProbeApplied = true;
|
|
27120
27176
|
} else if (!isSelfNode && daemonId && this.deps.dispatchMeshCommand && !directTruthUnavailableNodeIds.has(nodeId)) {
|
|
27121
27177
|
try {
|
|
@@ -27128,6 +27184,12 @@ ${block}`);
|
|
|
27128
27184
|
if (remoteGit) {
|
|
27129
27185
|
status.git = remoteGit;
|
|
27130
27186
|
status.health = remoteGit.isGitRepo ? deriveMeshNodeHealthFromGit(remoteGit) : "degraded";
|
|
27187
|
+
const connection = readObjectRecord(status.connection);
|
|
27188
|
+
const connectionState = readStringValue(connection.state);
|
|
27189
|
+
const connectionReported = readBooleanValue(connection.reported) ?? false;
|
|
27190
|
+
if (!connectionReported || connectionState === "unknown") {
|
|
27191
|
+
status.connection = buildLivePeerGitConnection(connection, refreshedAt);
|
|
27192
|
+
}
|
|
27131
27193
|
recordInlineMeshDirectGitTruth(node, remoteGit, "selected_coordinator_mesh_p2p_git");
|
|
27132
27194
|
remoteProbeApplied = true;
|
|
27133
27195
|
}
|
|
@@ -27146,6 +27208,12 @@ ${block}`);
|
|
|
27146
27208
|
if (remoteGit) {
|
|
27147
27209
|
status.git = remoteGit;
|
|
27148
27210
|
status.health = remoteGit.isGitRepo ? deriveMeshNodeHealthFromGit(remoteGit) : "degraded";
|
|
27211
|
+
const connection = readObjectRecord(status.connection);
|
|
27212
|
+
const connectionState = readStringValue(connection.state);
|
|
27213
|
+
const connectionReported = readBooleanValue(connection.reported) ?? false;
|
|
27214
|
+
if (!connectionReported || connectionState === "unknown") {
|
|
27215
|
+
status.connection = buildLivePeerGitConnection(connection, refreshedAt);
|
|
27216
|
+
}
|
|
27149
27217
|
recordInlineMeshDirectGitTruth(node, remoteGit, "selected_coordinator_mesh_p2p_git");
|
|
27150
27218
|
remoteProbeApplied = true;
|
|
27151
27219
|
}
|