openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
136 lines (135 loc) • 5.05 kB
JavaScript
import { r as formatCliJsonFailure } from "./failure-output-DVVDqwuu.mjs";
import { f as isUpdateDoctorLintPass } from "./update-phase-YdZvaQsy.mjs";
import { r as formatUpdateDoctorLintFinding } from "./update-doctor-lint-DBj8vlYP.mjs";
import { t as scrubDoctorErrorMessage } from "./doctor-error-message-BWgd1c6H.mjs";
import { n as healthFindingMeetsSeverity } from "./health-checks-BFk2VaFq.mjs";
import { t as exitCodeFromFindings } from "./doctor-lint-flow-BvruTNfX.mjs";
//#region src/commands/doctor-lint-output.ts
const DOCTOR_LINT_JSON_SCHEMA_VERSION = 1;
function formatJsonResult(e) {
return {
schemaVersion: DOCTOR_LINT_JSON_SCHEMA_VERSION,
ok: e.ok,
checksRun: e.checksRun,
checksSkipped: e.checksSkipped,
findings: e.findings.map(toJsonFinding),
...e.databaseStores ? { databaseStores: e.databaseStores } : {},
...e.recoveryCopies ? { recoveryCopies: e.recoveryCopies } : {},
...e.warnings?.length ? { warnings: e.warnings.map(toJsonFinding) } : {}
};
}
function writeJsonResult(e) {
process.stdout.write(JSON.stringify(formatJsonResult(e)) + "\n");
if (isUpdateDoctorLintPass(process.env)) for (const t of [...e.warnings ?? [], ...e.findings].toSorted((e, t) => Number(e.severity === "error") - Number(t.severity === "error"))) process.stderr.write(`${formatUpdateDoctorLintFinding(t)}\n`);
}
/** Shipped updaters parse failed lint output too; retain its readiness envelope. */
function formatDoctorLintFailure(e) {
const t = formatCliJsonFailure(e);
return {
...t,
status: "blocked",
...formatJsonResult({
ok: false,
checksRun: 0,
checksSkipped: 0,
findings: [{
checkId: "core/doctor/lint-inspection",
severity: "error",
source: "doctor",
message: t.error.message,
fixHint: "Resolve this inspection error, then rerun `openclaw doctor --lint`."
}]
})
};
}
function toJsonFinding(e) {
return {
checkId: e.checkId,
severity: e.severity,
message: e.message,
...e.source !== void 0 ? { source: e.source } : {},
...e.errorCode !== void 0 ? { errorCode: e.errorCode } : {},
...e.path !== void 0 ? { path: e.path } : {},
...e.line !== void 0 ? { line: e.line } : {},
...e.column !== void 0 ? { column: e.column } : {},
...e.ocPath !== void 0 ? { ocPath: e.ocPath } : {},
...e.target !== void 0 ? { target: e.target } : {},
...e.requirement !== void 0 ? { requirement: e.requirement } : {},
...e.fixHint !== void 0 ? { fixHint: e.fixHint } : {},
...e.details !== void 0 ? { details: e.details } : {}
};
}
function detectDoctorLintOutputMode(e) {
return e.json === true || !process.stdout.isTTY ? "json" : "human";
}
/** Rehearsal lint deferred by the update budget: no checks ran, and the deferral is the report. */
function createDeferredInspectionExecution(e, t, n) {
return {
checksRun: 0,
checksSkipped: 0,
exitCode: 0,
findings: n,
writeOutput() {
if (detectDoctorLintOutputMode(t) === "json") writeJsonResult({
ok: true,
checksRun: 0,
checksSkipped: 0,
findings: [],
warnings: n
});
else for (const t of n) {
e.log(`[warning] ${t.checkId} [${t.errorCode}]: ${t.message}`);
e.log(t.fixHint ?? "Run `openclaw doctor` after activation.");
}
}
};
}
function createStateSnapshotFailureFinding(e) {
return {
checkId: "core/doctor/lint-state-inspection",
severity: "error",
source: "doctor",
target: "plugin-state",
requirement: "read-only-plugin-state-inspection",
message: `Doctor lint could not inspect plugin state without mutating the live state database (${scrubDoctorErrorMessage(e.cause ?? e)}).`,
fixHint: "Keep the current Gateway running, resolve the state database inspection error, then rerun this check."
};
}
async function createStateSnapshotFailureExecution(e, t, n, r, i) {
const { collectNodeRuntimeFindings: a } = await import("./node-runtime-diagnostics-C4MzJK1U.mjs");
const o = [createStateSnapshotFailureFinding(r), ...i ? [] : await a()].filter((e) => healthFindingMeetsSeverity(e, n));
const s = [...i?.findings ?? [], ...o];
const c = i?.checksRun ?? 0;
const l = i?.checksSkipped ?? 0;
return {
checksRun: c,
checksSkipped: l,
exitCode: exitCodeFromFindings(s, n),
findings: s,
cleanupWarnings: i?.cleanupWarnings,
databaseStores: i?.databaseStores,
recoveryCopies: i?.recoveryCopies,
warnings: i?.warnings,
writeOutput() {
if (detectDoctorLintOutputMode(t) === "json") {
writeJsonResult({
ok: false,
checksRun: c,
checksSkipped: l,
findings: s,
databaseStores: i?.databaseStores,
recoveryCopies: i?.recoveryCopies,
warnings: [...i?.warnings ?? [], ...i?.cleanupWarnings ?? []]
});
return;
}
i?.writeOutput();
for (const t of o) {
e.error(`doctor --lint: ${t.message}`);
if (t.fixHint) e.error(`fix: ${t.fixHint}`);
}
}
};
}
//#endregion
export { formatDoctorLintFailure as a, detectDoctorLintOutputMode as i, createStateSnapshotFailureExecution as n, writeJsonResult as o, createStateSnapshotFailureFinding as r, createDeferredInspectionExecution as t };