UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

4 lines • 5.51 kB
import{a as asOptionalRecord}from"./record-coerce-BTbqdJ3-.mjs";import{S as resolveIsConfigReadOnly,p as resolveCanonicalConfigPath}from"./paths-D_FOvGon.mjs";import{t as formatCliCommand}from"./command-format-D7KhNLP0.mjs";import{y as resolveFutureConfigActionBlock}from"./config-env-vars-DCDGIBtT.mjs";import{a as createConfigIoContext}from"./io.recovery-cGJcOWcH.mjs";import{r as createInvalidConfigError}from"./io.invalid-config-B2POcxOa.mjs";import{s as parseConfigJson5}from"./io.read-helpers-B0XuPBY2.mjs";import{a as preserveDeferredPluginMigrationConfig}from"./deferred-plugin-migration-config-D1j_2i5D.mjs";import{s as findLegacyConfigRuleIssues}from"./legacy-tools-by-sender-D6Y_L891.mjs";import{c as recoverConfigFromLastKnownGoodCore,n as prepareConfigRecoveryFromContext,t as createConfigIO}from"./io.factory-y6nIrp_4.mjs";import{_ as recoverConfigFromJsonRootSuffix}from"./io.runtime-BvSeVFIY.mjs";import"./io-Di_yuX3t.mjs";import{a as resolveCronJobsStorePathFromConfig}from"./paths-BFxu7LPC.mjs";import{n as assertNoRetiredStateFiles}from"./state-migrations.retired-files-C6JkM7xQ.mjs";import{t as findRetiredConfigUpgradeRequirement}from"./retired-config-formats-QYugmWuX.mjs";import{t as note}from"./note-e4DtVgg2.mjs";import{t as classifyOtelGrpcMigrationOwnership}from"./include-migration-ownership-KASn2yVx.mjs";import{p as LEGACY_PLUGIN_PROMPT_PERMISSION}from"./legacy-config-migrations-BjWfZbO1.mjs";import{t as applyLegacyDoctorMigrations}from"./legacy-config-compat-BG3tvxTV.mjs";import{t as listRetiredCronStateFiles}from"./state-migrations.retired-cron-files-CObv_AEu.mjs";import path from"node:path"; //!src/commands/doctor-config-preflight-legacy-config.ts const transformDoctorRecoveryCandidate=e=>{const t=classifyOtelGrpcMigrationOwnership({snapshot:{path:e.configPath,includeProvenance:e.includeProvenance},authoredConfig:e.candidate.parsed,resolvedConfig:e.resolvedConfig});if(t&&t.kind!==`direct`)throw createInvalidConfigError(e.configPath,t.kind===`resolved-only`?`candidate migration cannot persist an env-resolved diagnostics.otel.protocol repair`:`candidate migration requires an include-owned diagnostics.otel.protocol repair`);const n=applyLegacyDoctorMigrations(e.candidate.parsed,{sourceConfigBeforeMigrations:e.resolvedConfig,context:{authoredRaw:e.candidate.parsed,resolvedRaw:e.resolvedConfig}});return n.next?preserveDeferredPluginMigrationConfig({sourceConfig:e.candidate.parsed,nextConfig:n.next,pending:e.deferredPluginMigrations}):e.candidate.parsed};async function migrateLegacyDoctorConfig(e){if(!e.enabled||resolveIsConfigReadOnly(process.env))return false;const t=await e.measure(`legacy-config-migration`,maybeMigrateLegacyConfig);if(t.length>0)note(t.map(e=>`- ${e}`).join(` `),`Doctor changes`);return t.length>0}async function prepareDoctorConfigRecovery(e){let t=e.snapshotRead;let n=t.snapshot;const assertSupportedConfig=e=>{const t=findRetiredConfigUpgradeRequirement(e);if(t)throw new Error(`${t.message} ${t.nextAction}`)};assertSupportedConfig(n.sourceConfigBeforeMigrations??n.sourceConfig);const r=n.sourceConfigBeforeMigrations??n.sourceConfig;if(e.enabled&&!e.stateMigrationsRequested&&typeof asOptionalRecord(r?.cron)?.store===`string`)assertNoRetiredStateFiles(`Cron state (state migration is disabled)`,await listRetiredCronStateFiles(resolveCronJobsStorePathFromConfig(r??{})));let i=null;const a=e.enabled&&!resolveFutureConfigActionBlock({action:`recover config`,snapshot:n});if(a&&n.valid&&e.databaseAccess!==`none`){const r=await prepareConfigRecoveryFromContext(createConfigIoContext({configPath:n.path},transformDoctorRecoveryCandidate),n,`doctor-repair`);if(r){await r.apply();t=await e.readSnapshot();n=t.snapshot}}if(a&&n.exists&&!n.valid){i=typeof n.raw===`string`&&parseConfigJson5(n.raw).ok?await e.planRepair(n):null;if(!i&&findLegacyConfigRuleIssues(r,LEGACY_PLUGIN_PROMPT_PERMISSION.legacyRules??[]).length>0)return{snapshotRead:t,activeConfigRepair:i};let a=false;const o=e.databaseAccess===`none`?createConfigIO({configPath:n.path,observe:false,pluginValidation:`core-only`}).recoverConfigFromJsonRootSuffix:recoverConfigFromJsonRootSuffix;if(!i&&await o(n,assertSupportedConfig)){note(`Removed non-JSON prefix from openclaw.json.`,`Config`);a=true}else if(!i&&e.databaseAccess!==`none`){const e=createConfigIoContext({configPath:n.path},transformDoctorRecoveryCandidate);if(await recoverConfigFromLastKnownGoodCore({snapshot:n,reason:`doctor-invalid-config`,deps:e.deps,prepareCandidate:e.prepareRecoveryBackupCandidate})){note(`Restored openclaw.json from last-known-good; original saved as .clobbered.*.`,`Config`);a=true}}if(a){t=await e.readSnapshot();n=t.snapshot}if(e.databaseAccess!==`none`&&!n.valid&&typeof n.raw===`string`&&!parseConfigJson5(n.raw).ok)throw new Error(`Config at ${n.path} is not parseable and cannot be repaired automatically. The file remains unchanged. Inspect the exact parse error with ${formatCliCommand(`openclaw config validate`)}, then hand-edit the file; or move it aside and run ${formatCliCommand(`openclaw onboard`)} to generate a fresh config.`)}return{snapshotRead:t,activeConfigRepair:i}}async function maybeMigrateLegacyConfig(){if(process.env.OPENCLAW_STATE_DIR?.trim()||process.env.OPENCLAW_HOME?.trim()||process.env.OPENCLAW_CONFIG_PATH?.trim())return[];const{renameLegacyConfigFile:e}=await import(`./state-migrations.state-dir-CKjADuh4.mjs`);return e(path.dirname(resolveCanonicalConfigPath()))}export{prepareDoctorConfigRecovery as n,migrateLegacyDoctorConfig as t};