feat(plugins): refresh registry after plugin mutations

This commit is contained in:
Vincent Koc
2026-04-25 04:30:21 -07:00
parent 53c3c949d0
commit 0cc2b0e283
5 changed files with 72 additions and 0 deletions

View File

@@ -36,6 +36,7 @@ import {
import { setPluginEnabledInConfig } from "./plugins-config.js";
import { runPluginInstallCommand } from "./plugins-install-command.js";
import { formatPluginLine } from "./plugins-list-format.js";
import { refreshPluginRegistryAfterConfigMutation } from "./plugins-registry-refresh.js";
import { resolvePluginUninstallId } from "./plugins-uninstall-selection.js";
import { runPluginUpdateCommand } from "./plugins-update-command.js";
import { promptYesNo } from "./prompt.js";
@@ -498,6 +499,13 @@ export function registerPluginsCli(program: Command) {
nextConfig: next,
...(snapshot.hash !== undefined ? { baseHash: snapshot.hash } : {}),
});
await refreshPluginRegistryAfterConfigMutation({
config: next,
reason: "policy-changed",
logger: {
warn: (message) => defaultRuntime.log(theme.warn(message)),
},
});
logSlotWarnings(slotResult.warnings);
if (enableResult.enabled) {
defaultRuntime.log(`Enabled plugin "${id}". Restart the gateway to apply.`);
@@ -522,6 +530,13 @@ export function registerPluginsCli(program: Command) {
nextConfig: next,
...(snapshot.hash !== undefined ? { baseHash: snapshot.hash } : {}),
});
await refreshPluginRegistryAfterConfigMutation({
config: next,
reason: "policy-changed",
logger: {
warn: (message) => defaultRuntime.log(theme.warn(message)),
},
});
defaultRuntime.log(`Disabled plugin "${id}". Restart the gateway to apply.`);
});
@@ -645,6 +660,13 @@ export function registerPluginsCli(program: Command) {
nextConfig: result.config,
...(snapshot.hash !== undefined ? { baseHash: snapshot.hash } : {}),
});
await refreshPluginRegistryAfterConfigMutation({
config: result.config,
reason: "source-changed",
logger: {
warn: (message) => defaultRuntime.log(theme.warn(message)),
},
});
const removed: string[] = [];
if (result.actions.entry) {

View File

@@ -11,6 +11,7 @@ import {
logHookPackRestartHint,
logSlotWarnings,
} from "./plugins-command-helpers.js";
import { refreshPluginRegistryAfterConfigMutation } from "./plugins-registry-refresh.js";
function addInstalledPluginToAllowlist(cfg: OpenClawConfig, pluginId: string): OpenClawConfig {
const allow = cfg.plugins?.allow;
@@ -48,6 +49,13 @@ export async function persistPluginInstall(params: {
nextConfig: next,
...(params.baseHash !== undefined ? { baseHash: params.baseHash } : {}),
});
await refreshPluginRegistryAfterConfigMutation({
config: next,
reason: "source-changed",
logger: {
warn: (message) => defaultRuntime.log(theme.warn(message)),
},
});
logSlotWarnings(slotResult.warnings);
if (params.warningMessage) {
defaultRuntime.log(theme.warn(params.warningMessage));

View File

@@ -0,0 +1,27 @@
import type { OpenClawConfig } from "../config/types.openclaw.js";
import { formatErrorMessage } from "../infra/errors.js";
import type { InstalledPluginIndexRefreshReason } from "../plugins/installed-plugin-index.js";
import { refreshPluginRegistry } from "../plugins/plugin-registry.js";
export type PluginRegistryRefreshLogger = {
warn?: (message: string) => void;
};
export async function refreshPluginRegistryAfterConfigMutation(params: {
config: OpenClawConfig;
reason: InstalledPluginIndexRefreshReason;
workspaceDir?: string;
env?: NodeJS.ProcessEnv;
logger?: PluginRegistryRefreshLogger;
}): Promise<void> {
try {
await refreshPluginRegistry({
config: params.config,
reason: params.reason,
...(params.workspaceDir ? { workspaceDir: params.workspaceDir } : {}),
...(params.env ? { env: params.env } : {}),
});
} catch (error) {
params.logger?.warn?.(`Plugin registry refresh failed: ${formatErrorMessage(error)}`);
}
}

View File

@@ -3,6 +3,7 @@ import { updateNpmInstalledHookPacks } from "../hooks/update.js";
import { updateNpmInstalledPlugins } from "../plugins/update.js";
import { defaultRuntime } from "../runtime.js";
import { theme } from "../terminal/theme.js";
import { refreshPluginRegistryAfterConfigMutation } from "./plugins-registry-refresh.js";
import {
resolveHookPackUpdateSelection,
resolvePluginUpdateSelection,
@@ -112,6 +113,13 @@ export async function runPluginUpdateCommand(params: {
nextConfig: hookResult.config,
baseHash: (await sourceSnapshotPromise)?.hash,
});
if (pluginResult.changed) {
await refreshPluginRegistryAfterConfigMutation({
config: hookResult.config,
reason: "source-changed",
logger,
});
}
defaultRuntime.log("Restart the gateway to load plugins and hooks.");
}
}

View File

@@ -57,6 +57,7 @@ import {
terminateStaleGatewayPids,
waitForGatewayHealthyRestart,
} from "../daemon-cli/restart-health.js";
import { refreshPluginRegistryAfterConfigMutation } from "../plugins-registry-refresh.js";
import { createUpdateProgress, printResult } from "./progress.js";
import { prepareRestartScript, runRestartScript } from "./restart-helper.js";
import {
@@ -619,6 +620,12 @@ async function updatePluginsAfterCoreUpdate(params: {
nextConfig: pluginConfig,
baseHash: params.configSnapshot.hash,
});
await refreshPluginRegistryAfterConfigMutation({
config: pluginConfig,
reason: "source-changed",
workspaceDir: params.root,
logger: pluginLogger,
});
}
if (params.opts.json) {