openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
119 lines (118 loc) • 5.3 kB
JavaScript
import { t as formatCliCommand } from "./command-format-CqdwUgPk.mjs";
import { n as OPENCLAW_STATE_SCHEMA_VERSION } from "./openclaw-schema-versions-E_10NoI6.mjs";
import "./openclaw-state-db-contract-DfPjvL0M.mjs";
import { t as OpenClawStateLeaseAcquisitionError } from "./openclaw-state-lease-error-Dq51JM59.mjs";
import { m as withExistingOpenClawStateDatabaseReadOnly } from "./openclaw-state-db-readonly-B6YHb1oF.mjs";
import { o as readStateSchemaContentVersion } from "./openclaw-state-db-schema-version-uNbDFl6T.mjs";
import { t as scrubDoctorErrorMessage } from "./doctor-error-message-BWgd1c6H.mjs";
import { r as listHealthChecks } from "./health-check-registry-Cl2vTx8K.mjs";
import { n as healthFindingMeetsSeverity, r as isHealthCheckEnabledByDefault, t as HEALTH_FINDING_SEVERITY_RANK } from "./health-checks-BFk2VaFq.mjs";
//#region src/flows/doctor-lint-flow.ts
const stateSchemaHealthCheck = {
id: "core/doctor/state-schema",
kind: "core",
description: "Shared state migrations require explicit repair.",
async detect(e) {
const [{ readRetainedAgentDeletionsFromDatabase: t }, { readAgentDatabasePreflightTargets: n }] = await Promise.all([import("./agent-deletion-journal.read-C4XW5EvT.mjs"), import("./openclaw-agent-db-registry.read-BXdIvZyG.mjs")]);
const r = withExistingOpenClawStateDatabaseReadOnly(({ db: e, path: r }) => {
const i = t(e, r);
const a = i.status === "present" ? i.held : i.status === "unavailable" ? [...n(e, r), ...i.known?.held ?? []] : [];
return {
version: readStateSchemaContentVersion(e),
path: r,
journal: i,
held: [...new Map(a.map((e) => [JSON.stringify([e.agentId, e.path]), e])).values()]
};
}, { env: e.env });
if (!r) return [];
const i = formatCliCommand("openclaw doctor --fix", e.env);
const a = r.journal.status === "unavailable" ? r.journal : void 0;
const o = {
checkId: "core/doctor/agent-deletion-journal",
severity: "warning",
errorCode: a ? `agent-deletion-journal-${a.cause}` : "agent-deletion-journal-held",
fixHint: `Run ${i} to verify deletion history and ownership, and back up configured stores before restoration; follow its guidance for stores still held.`
};
const s = r.held.map((e) => ({
...o,
target: e.agentId,
path: e.path,
message: `Held agent ${e.agentId} database ${e.path}: ${a?.reason ?? "deletion journal reconstructed"}. The store remains untouched until ownership can be verified.`
}));
if (a && s.length === 0) s.push({
...o,
path: r.path,
message: a.reason
});
if (r.version >= 36) return s;
return [...s, {
checkId: "core/doctor/state-schema",
severity: "warning",
path: r.path,
requirement: "state-schema-migration-pending",
message: `Shared state schema migration pending (${r.version} → ${36}); run ${i}.`,
fixHint: `Run \`${i}\` to migrate the shared state database.`
}];
}
};
/** Runs selected health checks in lint mode and returns sorted findings. */
async function runDoctorLintChecks(e, t = {}) {
const n = t.checks ?? listHealthChecks();
const r = t.skipIds instanceof Set ? t.skipIds : new Set(t.skipIds ?? []);
const i = t.onlyIds instanceof Set ? t.onlyIds : new Set(t.onlyIds ?? []);
const a = new Set(n.map((e) => e.id));
const o = t.includeAllChecks === true;
const s = n.filter((e) => {
if (i.size > 0 && !i.has(e.id)) return false;
if (i.size === 0 && !o && !isHealthCheckEnabledByDefault(e)) return false;
return !r.has(e.id);
});
const c = [];
for (const e of i) {
let t;
if (!a.has(e)) t = `Unknown health check id selected by --only: ${e}.`;
else if (s.length === 0 && r.has(e)) t = `Health check ${e} cannot be selected by --only and excluded by --skip.`;
else continue;
c.push({
checkId: "core/doctor/lint-selection",
severity: "error",
message: t,
path: e
});
}
for (const t of s) try {
const n = await t.detect(e);
for (const e of n) c.push(e);
} catch (e) {
const n = e instanceof OpenClawStateLeaseAcquisitionError && e.outcome.kind === "aborted" ? e.outcome : void 0;
c.push({
checkId: t.id,
severity: n ? "info" : "error",
...n ? { errorCode: "OPENCLAW_STATE_LEASE_ABORTED" } : {},
message: n ? `state lease inspection not performed: aborted after ${n.elapsedMs} ms by the caller's signal` : `health check threw: ${scrubDoctorErrorMessage(e)}`
});
}
c.sort(compareFindings);
return {
findings: c,
checksRun: s.length,
checksSkipped: n.length - s.length
};
}
/** Internal update gate selection; public Doctor lint remains selector-driven. */
function selectUpdateReadinessChecks(e, t) {
return e.filter((e) => "updateReadiness" in e && e.updateReadiness === t);
}
function compareFindings(e, t) {
const n = HEALTH_FINDING_SEVERITY_RANK[t.severity] - HEALTH_FINDING_SEVERITY_RANK[e.severity];
if (n !== 0) return n;
const r = e.checkId.localeCompare(t.checkId);
if (r !== 0) return r;
return (e.path ?? "").localeCompare(t.path ?? "");
}
/** Converts findings to a process exit code using the requested minimum severity. */
function exitCodeFromFindings(e, t = "warning") {
return e.some((e) => healthFindingMeetsSeverity(e, t)) ? 1 : 0;
}
//#endregion
export { stateSchemaHealthCheck as i, runDoctorLintChecks as n, selectUpdateReadinessChecks as r, exitCodeFromFindings as t };