openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
3 lines • 4.94 kB
JavaScript
import{l as isRecord}from"./record-coerce-BTbqdJ3-.mjs";import"./manifest-D8YdMedM.mjs";import{r as resolvePackageExtensionEntries}from"./package-manifest-CMy2j7Hf.mjs";import{t as hasErrnoCode}from"./errno-DUBt6SQQ.mjs";import{r as resolveInstalledPluginIndexInstallOwner}from"./installed-plugin-index-install-owner-iRSOvGid.mjs";import{i as writeConsoleDiagnosticWarning}from"./json-console-line-C76Rgjbb.mjs";import{t as VERSION}from"./version-DrZ9Nfde.mjs";import{f as isOptionalPluginManifestFile}from"./installed-plugin-index-B04a42mO.mjs";import{i as validatePackageExtensionEntriesForInstall}from"./package-entry-resolution-CtQS-t-Q.mjs";import{r as readPersistedInstalledPluginIndex}from"./installed-plugin-index-store-CP6OETa6.mjs";import{a as resolvePluginVersionDriftTargets,i as resolvePluginVersionDriftRegistryLag,o as resolvePluginVersionDriftUpdateCommand,t as detectPluginVersionDrift}from"./plugin-version-drift-DzQF-2yn.mjs";import fs from"node:fs";import path from"node:path";import crypto from"node:crypto";import fs$1 from"node:fs/promises";
//!src/commands/doctor-post-upgrade.ts
const POST_UPGRADE_PROBE_CODES=[`plugin.index_unavailable`,`plugin.entry_unresolved`,`plugin.manifest_unavailable`,`plugin.manifest_drift`,`plugin.version_drift`];function buildReport(e){return{probesRun:[...POST_UPGRADE_PROBE_CODES],findings:e}}function isBundledSourceCheckoutPluginRoot(e){let t=path.resolve(e);while(true){const e=path.dirname(t);if(path.basename(e)===`extensions`){const t=path.dirname(e);return[`.git`,`pnpm-workspace.yaml`,`src`].every(e=>fs.existsSync(path.join(t,e)))}if(e===t)return false;t=e}}async function runPostUpgradeProbes(e){const t=[];const n=await readPersistedInstalledPluginIndex();if(!n){t.push({level:`error`,code:`plugin.index_unavailable`,message:"Installed plugin index is missing, unreadable, or malformed. Run `openclaw plugins registry --refresh` to rebuild it before post-upgrade validation."});return buildReport(t)}const r=n.plugins.filter(e=>e.enabled);const i=Object.fromEntries(Object.entries(n.installRecords).filter(([e])=>r.some(t=>t.pluginId===e||resolveInstalledPluginIndexInstallOwner(t)===e)));const a=await resolvePluginVersionDriftTargets(detectPluginVersionDrift({gatewayVersion:VERSION,installRecords:i,config:{update:{channel:e}}}));for(const e of a.drifts){const n=resolvePluginVersionDriftRegistryLag(e);const r=resolvePluginVersionDriftUpdateCommand(e);const i=n?`The registry already serves ${n.registryVersion}; no release reaches ${n.expectedVersion} yet, so no update applies.`:r?`Run \`${r}\`, then restart the Gateway.`:`No confirmed repair target is available; check registry availability and rerun this command.`;t.push({level:`warn`,code:`plugin.version_drift`,plugin:e.pluginId,message:`Plugin ${e.pluginId} is ${e.installedVersion}, but OpenClaw is ${VERSION}. ${i}`})}for(const e of r){const addError=(n,r,i)=>t.push({level:`error`,code:n,message:`Plugin ${e.pluginId}: ${r}`,plugin:e.pluginId,...i?{entry:i}:{}});const n=e.packageJson?.path??await fs$1.access(path.join(e.rootDir,`package.json`)).then(()=>`package.json`,()=>void 0);if(n){let t;try{const r=JSON.parse(await fs$1.readFile(path.join(e.rootDir,n),`utf-8`));if(!isRecord(r))throw new Error(`package.json must contain a JSON object`);t=r}catch(t){const r=t instanceof Error?t.message:String(t);const i=`[doctor-post-upgrade] could not read package.json for ${e.pluginId} at ${e.rootDir}: ${r}`;writeConsoleDiagnosticWarning(i);addError(`plugin.entry_unresolved`,`could not read package.json (${n}): ${r}. Reinstall the plugin or run \`openclaw plugins registry --refresh\`.`,n);continue}const r=resolvePackageExtensionEntries(t);if(r.status===`invalid`)addError(`plugin.entry_unresolved`,`${r.error}. Reinstall the plugin or run \`openclaw plugins registry --refresh\`.`,n);else if(r.status===`ok`){const n=r.entries;const i=await validatePackageExtensionEntriesForInstall({packageDir:e.rootDir,extensions:[...n],manifest:t,allowSourceTypeScriptEntries:e.origin===`workspace`||e.origin===`config`||e.origin===`bundled`&&isBundledSourceCheckoutPluginRoot(e.rootDir)});if(!i.ok){const e=n.find(e=>i.error.includes(e));addError(`plugin.entry_unresolved`,i.error,e)}}}if(e.manifestPath){let n;try{const t=await fs$1.readFile(e.manifestPath);n=crypto.createHash(`sha256`).update(t).digest(`hex`)}catch(t){if(hasErrnoCode(t,`ENOENT`)&&isOptionalPluginManifestFile(e))continue;const n=t instanceof Error?t.message:String(t);addError(`plugin.manifest_unavailable`,`could not read indexed manifest (${e.manifestPath}): ${n}. Reinstall the plugin or run \`openclaw plugins registry --refresh\`.`);continue}if(e.manifestHash&&n!==e.manifestHash)t.push({level:`warn`,code:`plugin.manifest_drift`,message:`Plugin ${e.pluginId} manifest hash drifted from the installed plugin index. Run \`openclaw plugins registry --refresh\` to re-sync.`,plugin:e.pluginId})}}return buildReport(t)}export{runPostUpgradeProbes};