Plugins: allowlist plugins when enabling from CLI

This commit is contained in:
Vignesh Natarajan
2026-02-21 19:37:26 -08:00
parent 483c464b62
commit 8920e281cc
3 changed files with 50 additions and 33 deletions

View File

@@ -6,6 +6,7 @@ import type { OpenClawConfig } from "../config/config.js";
import { loadConfig, writeConfigFile } from "../config/config.js";
import { resolveStateDir } from "../config/paths.js";
import { resolveArchiveKind } from "../infra/archive.js";
import { enablePluginInConfig } from "../plugins/enable.js";
import { installPluginFromNpmSpec, installPluginFromPath } from "../plugins/install.js";
import { recordPluginInstall } from "../plugins/installs.js";
import { clearPluginManifestRegistryCache } from "../plugins/manifest-registry.js";
@@ -135,22 +136,6 @@ function createPluginInstallLogger(): { info: (msg: string) => void; warn: (msg:
};
}
function enablePluginInConfig(config: OpenClawConfig, pluginId: string): OpenClawConfig {
return {
...config,
plugins: {
...config.plugins,
entries: {
...config.plugins?.entries,
[pluginId]: {
...(config.plugins?.entries?.[pluginId] as object | undefined),
enabled: true,
},
},
},
};
}
function logSlotWarnings(warnings: string[]) {
if (warnings.length === 0) {
return;
@@ -352,24 +337,21 @@ export function registerPluginsCli(program: Command) {
.argument("<id>", "Plugin id")
.action(async (id: string) => {
const cfg = loadConfig();
let next: OpenClawConfig = {
...cfg,
plugins: {
...cfg.plugins,
entries: {
...cfg.plugins?.entries,
[id]: {
...(cfg.plugins?.entries as Record<string, { enabled?: boolean }> | undefined)?.[id],
enabled: true,
},
},
},
};
const enableResult = enablePluginInConfig(cfg, id);
let next: OpenClawConfig = enableResult.config;
const slotResult = applySlotSelectionForPlugin(next, id);
next = slotResult.config;
await writeConfigFile(next);
logSlotWarnings(slotResult.warnings);
defaultRuntime.log(`Enabled plugin "${id}". Restart the gateway to apply.`);
if (enableResult.enabled) {
defaultRuntime.log(`Enabled plugin "${id}". Restart the gateway to apply.`);
return;
}
defaultRuntime.log(
theme.warn(
`Plugin "${id}" could not be enabled (${enableResult.reason ?? "unknown reason"}).`,
),
);
});
plugins
@@ -568,7 +550,7 @@ export function registerPluginsCli(program: Command) {
},
},
probe.pluginId,
);
).config;
next = recordPluginInstall(next, {
pluginId: probe.pluginId,
source: "path",
@@ -597,7 +579,7 @@ export function registerPluginsCli(program: Command) {
// force a rescan so config validation sees the freshly installed plugin.
clearPluginManifestRegistryCache();
let next = enablePluginInConfig(cfg, result.pluginId);
let next = enablePluginInConfig(cfg, result.pluginId).config;
const source: "archive" | "path" = resolveArchiveKind(resolved) ? "archive" : "path";
next = recordPluginInstall(next, {
pluginId: result.pluginId,
@@ -648,7 +630,7 @@ export function registerPluginsCli(program: Command) {
// Ensure config validation sees newly installed plugin(s) even if the cache was warmed at startup.
clearPluginManifestRegistryCache();
let next = enablePluginInConfig(cfg, result.pluginId);
let next = enablePluginInConfig(cfg, result.pluginId).config;
const resolvedSpec = result.npmResolution?.resolvedSpec;
const recordSpec = opts.pin && resolvedSpec ? resolvedSpec : raw;
if (opts.pin && !resolvedSpec) {