mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-30 11:21:07 +00:00
fix(plugins): enforce minimum host versions for installable plugins (#52094)
* fix(plugins): enforce min host versions * fix(plugins): tighten min host version validation * chore(plugins): trim dead min host version code * fix(plugins): handle malformed min host metadata * fix(plugins): key manifest cache by host version
This commit is contained in:
@@ -31,12 +31,15 @@ import { validateRegistryNpmSpec } from "../infra/npm-registry-spec.js";
|
||||
import { extensionUsesSkippedScannerPath, isPathInside } from "../security/scan-paths.js";
|
||||
import * as skillScanner from "../security/skill-scanner.js";
|
||||
import { CONFIG_DIR, resolveUserPath } from "../utils.js";
|
||||
import { resolveRuntimeServiceVersion } from "../version.js";
|
||||
import { detectBundleManifestFormat, loadBundleManifest } from "./bundle-manifest.js";
|
||||
import {
|
||||
getPackageManifestMetadata,
|
||||
loadPluginManifest,
|
||||
resolvePackageExtensionEntries,
|
||||
type PackageManifest as PluginPackageManifest,
|
||||
} from "./manifest.js";
|
||||
import { checkMinHostVersion } from "./min-host-version.js";
|
||||
|
||||
type PluginInstallLogger = {
|
||||
info?: (message: string) => void;
|
||||
@@ -52,6 +55,9 @@ const MISSING_EXTENSIONS_ERROR =
|
||||
|
||||
export const PLUGIN_INSTALL_ERROR_CODE = {
|
||||
INVALID_NPM_SPEC: "invalid_npm_spec",
|
||||
INVALID_MIN_HOST_VERSION: "invalid_min_host_version",
|
||||
UNKNOWN_HOST_VERSION: "unknown_host_version",
|
||||
INCOMPATIBLE_HOST_VERSION: "incompatible_host_version",
|
||||
MISSING_OPENCLAW_EXTENSIONS: "missing_openclaw_extensions",
|
||||
EMPTY_OPENCLAW_EXTENSIONS: "empty_openclaw_extensions",
|
||||
NPM_PACKAGE_NOT_FOUND: "npm_package_not_found",
|
||||
@@ -525,6 +531,33 @@ async function installPluginFromPackageDir(
|
||||
);
|
||||
}
|
||||
|
||||
const packageMetadata = getPackageManifestMetadata(manifest);
|
||||
const minHostVersionCheck = checkMinHostVersion({
|
||||
currentVersion: resolveRuntimeServiceVersion(),
|
||||
minHostVersion: packageMetadata?.install?.minHostVersion,
|
||||
});
|
||||
if (!minHostVersionCheck.ok) {
|
||||
if (minHostVersionCheck.kind === "invalid") {
|
||||
return {
|
||||
ok: false,
|
||||
error: `invalid package.json openclaw.install.minHostVersion: ${minHostVersionCheck.error}`,
|
||||
code: PLUGIN_INSTALL_ERROR_CODE.INVALID_MIN_HOST_VERSION,
|
||||
};
|
||||
}
|
||||
if (minHostVersionCheck.kind === "unknown_host_version") {
|
||||
return {
|
||||
ok: false,
|
||||
error: `plugin "${pluginId}" requires OpenClaw >=${minHostVersionCheck.requirement.minimumLabel}, but this host version could not be determined. Re-run from a released build or set OPENCLAW_VERSION and retry.`,
|
||||
code: PLUGIN_INSTALL_ERROR_CODE.UNKNOWN_HOST_VERSION,
|
||||
};
|
||||
}
|
||||
return {
|
||||
ok: false,
|
||||
error: `plugin "${pluginId}" requires OpenClaw >=${minHostVersionCheck.requirement.minimumLabel}, but this host is ${minHostVersionCheck.currentVersion}. Upgrade OpenClaw and retry.`,
|
||||
code: PLUGIN_INSTALL_ERROR_CODE.INCOMPATIBLE_HOST_VERSION,
|
||||
};
|
||||
}
|
||||
|
||||
const packageDir = path.resolve(params.packageDir);
|
||||
const forcedScanEntries: string[] = [];
|
||||
for (const entry of extensions) {
|
||||
|
||||
Reference in New Issue
Block a user