UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

81 lines (80 loc) • 3.47 kB
import { s as hasFlag, x as isDoctorMachineOutput } from "./argv-CbnKpH-r.mjs"; import { o as writeRuntimeJson, r as defaultRuntime } from "./runtime-B-SLYP-m.mjs"; import { t as formatErrorMessage } from "./errors-BKzCeTYb.mjs"; import { i as formatInvalidConfigDetails } from "./io.invalid-config-DK-BYZ4Y.mjs"; import { i as withConfigWriteLock } from "./write-lock-Bg9nHsHM.mjs"; import { t as note } from "./note-CnLgHvug.mjs"; import { r as sanitizeDoctorNote } from "./emit-notes-llcc2fq-.mjs"; import { t as runWithLocalStateOwner } from "./local-state-owner-DTl7OHpC.mjs"; import { l as showDoctorIntro, u as showDoctorOutro } from "./doctor-health-startup-KiSUu3WC.mjs"; import { n as prepareDoctorConfigRecovery } from "./doctor-config-preflight-legacy-config-MGYWYBIt.mjs"; import { a as formatDoctorLintFailure } from "./doctor-lint-output-Bx6KW9dE.mjs"; //#region src/commands/doctor-engine-selection.ts /** Recovery may repair file bytes; an unresolved target must never reach stateful Doctor. */ async function prepareDoctorEngineSelection(e) { if (!(!hasFlag(e.argv, "--lint") && !hasFlag(e.argv, "--json") && [ "--fix", "--repair", "--yes" ].some((t) => hasFlag(e.argv, t)))) return e.snapshot; return runWithLocalStateOwner({ method: "doctor.config.recover", target: e.snapshot.path, params: {}, databaseAccess: "none", onForeignOwner: "refuse", runLocal: ({ env: t, assertCurrent: n }) => withConfigWriteLock(e.snapshot.path, async () => { const t = await e.readSnapshot(); n(); return (await prepareDoctorConfigRecovery({ enabled: true, databaseAccess: "none", stateMigrationsRequested: false, snapshotRead: { snapshot: t }, planRepair: async () => null, readSnapshot: async () => ({ snapshot: await e.readSnapshot() }) })).snapshotRead.snapshot; }, t, n) }); } /** Report uninspected storage truthfully, without entering bootstrap, maintenance or plugins. */ function reportDoctorUnresolvedEngine(e, t, n) { const r = e.issues.some((e) => e.errorCode === "CONFIG_SOURCE_INVALID"); const i = r ? "unknown: config could not be parsed; fix config (or run `openclaw doctor --fix`), then rerun" : "unknown: database target could not be resolved; fix database settings or credentials, then rerun"; const a = [ "Shared state", "Agent state", "Sessions", "Credentials", "Cron" ]; const o = sanitizeDoctorNote([formatInvalidConfigDetails(e.issues), n ? formatErrorMessage(n) : ""].filter(Boolean).join("\n")); const s = r ? "Run `openclaw config validate` to inspect the parse error." : "Fix database settings or supply the referenced credentials, then rerun `openclaw doctor`."; const c = hasFlag(t, "--lint"); process.exitCode = 2; const l = isDoctorMachineOutput({ argv: t, stdoutIsTTY: process.stdout.isTTY }); if (c || l) { const e = new Error([ i, o, s ].filter(Boolean).join("\n")); if (l) writeRuntimeJson(defaultRuntime, formatDoctorLintFailure(e)); else defaultRuntime.error(e.message); return; } showDoctorIntro("OpenClaw doctor"); note([ r ? "Config invalid; doctor will run with best-effort config." : "Config recovered; the database target remains unresolved.", e.path, o, s ].join("\n"), "Config"); for (const e of a) note(i, e); showDoctorOutro("Doctor blocked. Database checks remain unknown; no state migrations were performed."); } //#endregion export { prepareDoctorEngineSelection, reportDoctorUnresolvedEngine };