openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
135 lines (134 loc) • 5.09 kB
JavaScript
import { t as createSubsystemLogger } from "./subsystem-BHJiy01V.mjs";
import { h as normalizeUpdatePostInstallDoctorWarnings } from "./update-doctor-result-DwaI51On.mjs";
import { i as resolveDoctorWorkspaceDir } from "./doctor-health-contribution-utils-vPLdl3Wb.mjs";
//#region src/flows/doctor-health-contribution.ts
function legacyOwnedRepair(e, t) {
return async (n) => {
const r = await e(n);
return n.dryRun === true ? {
status: "repaired",
changes: [],
effects: r
} : {
status: "skipped",
reason: t,
changes: [],
effects: r
};
};
}
function createDoctorHealthContribution(e, t, n) {
const r = typeof n === "function" ? { run: n } : n;
const i = r.healthChecks;
let a = [];
if (i !== void 0) {
const t = Array.isArray(i) ? i : [i];
const n = e.startsWith("doctor:") ? `core/doctor/${e.slice(7)}` : `core/doctor/${e}`;
a = t.map((r) => {
const i = r.id ?? (t.length === 1 ? n : void 0);
if (i === void 0) throw new Error(`doctor contribution ${e} must specify health check ids when it declares multiple healthChecks`);
return Object.assign({}, r, {
id: i,
kind: "core",
source: "doctor"
});
});
}
const o = r.healthCheckIds ?? a.map((e) => e.id);
if (r.run === void 0 && a.length === 0) throw new Error(`doctor contribution ${e} must define run or healthChecks`);
return {
id: e,
label: t,
healthChecks: a,
healthCheckIds: o,
...r.required ? { required: true } : {},
...r.updateWork ? { updateWork: r.updateWork } : {},
run: r.run ?? (async (e) => {
const { runDoctorHealthRepairs: t } = await import("./doctor-repair-flow-C7dpUUxf.mjs");
const n = resolveDoctorWorkspaceDir(e.cfg, e.env);
const r = !e.prompter.shouldRepair;
const i = JSON.stringify(e.cfg);
const o = await t({
mode: "fix",
runtime: e.runtime,
cfg: e.cfg,
env: e.env,
cwd: n,
configPath: e.configPath,
dryRun: r,
allowExecSecretRefs: e.options.allowExec === true,
agentDatabaseRefusals: e.agentDatabaseRefusals
}, {
checks: a,
dryRun: r,
progress: e.options.json !== true
});
e.cfg = o.config;
renderStructuredHealthFindings(e, r ? o.findings : o.remainingFindings);
recordDoctorHealthWarnings(e, r ? o.findings : o.remainingFindings, o.warnings);
for (const t of o.warnings) e.runtime.error(t);
if (i !== JSON.stringify(o.config)) e.configResult.pendingChangePanels = [...e.configResult.pendingChangePanels ?? [], ...o.changes];
else for (const t of o.changes) e.runtime.log(t);
})
};
}
function recordDoctorHealthWarnings(e, t, n = [], r) {
const i = e.updateWarnings ?? [];
const a = [...t.filter((e) => e.severity === "warning").map((e) => `${e.checkId}${e.errorCode ? ` [${e.errorCode}]` : ""}: ${e.message}`), ...n];
e.updateWarnings = normalizeUpdatePostInstallDoctorWarnings(r?.prepend ? [...a, ...i] : [...i, ...a]);
}
function reportDoctorHealthFinding(e, t) {
recordDoctorHealthWarnings(e, [t], t.severity === "error" ? [`${t.checkId}: ${t.message}`] : []);
renderStructuredHealthFindings(e, [t]);
}
function renderStructuredHealthFindings(e, t) {
e.healthFindings ??= [];
e.healthFindings.push(...t);
}
function showDoctorHealthSummary(e) {
const t = e.healthFindings?.splice(0) ?? [];
const n = createSubsystemLogger("doctor");
for (const e of t) n.debug("Doctor finding", {
...e,
consoleMessage: JSON.stringify(e)
});
const r = t.filter((e) => e.severity === "error" || e.severity === "warning" && (e.category ?? "fix-now") === "fix-now");
if (r.length === 0) return;
e.runtime.log("Fix now:");
for (const t of r) {
(t.severity === "error" ? e.runtime.error : e.runtime.log)(`- ${t.message}`);
if (t.path !== void 0) {
const n = t.line !== void 0 ? `:${t.line}` : "";
e.runtime.log(` Location: ${t.path}${n}`);
}
if (t.fixHint !== void 0) e.runtime.log(` Next step: ${t.fixHint}`);
e.runtime.log(` Docs: ${t.docsUrl ?? "https://docs.openclaw.ai/cli/doctor/running#understanding-findings"}`);
}
}
/** Preserve priority order in the updater receipt independently of summary rendering. */
function collectDoctorHealthResultWarnings(e) {
const t = [...e.healthContext?.updateWarnings ?? [], ...e.startupWarnings ?? []];
const n = e.healthContext?.updateBudget?.deferred.size ?? 0;
return normalizeUpdatePostInstallDoctorWarnings([
...t.slice(0, n),
...e.resultWarnings ?? [],
...(e.maintenanceWarnings ?? []).filter((t) => !e.resultWarnings?.includes(t)),
...t.slice(n)
]);
}
/** Startup repairs may report before the full health context exists. */
function createDoctorHealthFindingBuffer(e) {
const t = {
runtime: e,
healthFindings: []
};
return {
buffer: t,
reportFindings(e, n) {
t.healthFindings.push(...e);
recordDoctorHealthWarnings(t, n ? [] : e, n);
}
};
}
//#endregion
export { recordDoctorHealthWarnings as a, showDoctorHealthSummary as c, legacyOwnedRepair as i, createDoctorHealthContribution as n, renderStructuredHealthFindings as o, createDoctorHealthFindingBuffer as r, reportDoctorHealthFinding as s, collectDoctorHealthResultWarnings as t };