openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
6 lines • 2.88 kB
JavaScript
import{s as hasFlag,x as isDoctorMachineOutput}from"./argv-BgC5-KlV.mjs";import{o as writeRuntimeJson,r as defaultRuntime}from"./runtime-DIcLIHcp.mjs";import{t as formatErrorMessage}from"./errors-D37BJTfI.mjs";import{i as formatInvalidConfigDetails}from"./io.invalid-config-B2POcxOa.mjs";import{i as withConfigWriteLock}from"./write-lock-BXv5IgVt.mjs";import{t as note}from"./note-e4DtVgg2.mjs";import{r as sanitizeDoctorNote}from"./emit-notes-DCY5wFZF.mjs";import{t as runWithLocalStateOwner}from"./local-state-owner-fjzTarAw.mjs";import{d as showDoctorOutro,u as showDoctorIntro}from"./doctor-health-startup-WrxcBhpP.mjs";import{n as prepareDoctorConfigRecovery}from"./doctor-config-preflight-legacy-config-DmfCeqni.mjs";import{a as formatDoctorLintFailure}from"./doctor-lint-output-BaL-hIUO.mjs";
//!src/commands/doctor-engine-selection.ts
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)})}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(`
`));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(`
`));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(`
`),`Config`);for(const e of a)note(i,e);showDoctorOutro(`Doctor blocked. Database checks remain unknown; no state migrations were performed.`)}export{prepareDoctorEngineSelection,reportDoctorUnresolvedEngine};