perf(config): avoid duplicate plugin auto-enable channel probes

This commit is contained in:
Peter Steinberger
2026-05-06 10:17:27 +01:00
parent 34dc7f6ea6
commit a24d5fe790
2 changed files with 32 additions and 18 deletions

View File

@@ -1,7 +1,7 @@
import type { PluginManifestRegistry } from "../plugins/manifest-registry.js";
import {
configMayNeedPluginAutoEnable,
resolveConfiguredPluginAutoEnableCandidates,
resolvePluginAutoEnableReadiness,
resolvePluginAutoEnableManifestRegistry,
} from "./plugin-auto-enable.shared.js";
import type { PluginAutoEnableCandidate } from "./plugin-auto-enable.types.js";
@@ -14,7 +14,8 @@ export function detectPluginAutoEnableCandidates(params: {
}): PluginAutoEnableCandidate[] {
const env = params.env ?? process.env;
const config = params.config ?? ({} as OpenClawConfig);
if (!configMayNeedPluginAutoEnable(config, env)) {
const readiness = resolvePluginAutoEnableReadiness(config, env);
if (!readiness.mayNeedAutoEnable) {
return [];
}
const registry = resolvePluginAutoEnableManifestRegistry({
@@ -26,5 +27,6 @@ export function detectPluginAutoEnableCandidates(params: {
config,
env,
registry,
configuredChannelIds: readiness.configuredChannelIds,
});
}

View File

@@ -482,38 +482,48 @@ export function configMayNeedPluginAutoEnable(
cfg: OpenClawConfig,
env: NodeJS.ProcessEnv,
): boolean {
return resolvePluginAutoEnableReadiness(cfg, env).mayNeedAutoEnable;
}
export function resolvePluginAutoEnableReadiness(
cfg: OpenClawConfig,
env: NodeJS.ProcessEnv,
): { mayNeedAutoEnable: boolean; configuredChannelIds: string[] } {
if (arePluginsGloballyDisabled(cfg)) {
return false;
return { mayNeedAutoEnable: false, configuredChannelIds: [] };
}
if (hasPluginAllowlistWithMaterialEntries(cfg)) {
return true;
return { mayNeedAutoEnable: true, configuredChannelIds: [] };
}
if (hasConfiguredPluginConfigEntry(cfg)) {
return true;
return { mayNeedAutoEnable: true, configuredChannelIds: [] };
}
if (collectConfiguredChannelIds(cfg, env).length > 0) {
return true;
const configuredChannelIds = collectConfiguredChannelIds(cfg, env);
if (configuredChannelIds.length > 0) {
return { mayNeedAutoEnable: true, configuredChannelIds };
}
if (hasConfiguredProviderModelOrHarness(cfg, env)) {
return true;
return { mayNeedAutoEnable: true, configuredChannelIds };
}
if (
hasConfiguredWebSearchProviderSelection(cfg) ||
hasConfiguredWebSearchPluginEntry(cfg) ||
hasConfiguredWebFetchPluginEntry(cfg)
) {
return true;
return { mayNeedAutoEnable: true, configuredChannelIds };
}
if (!hasSetupAutoEnableRelevantConfig(cfg)) {
return false;
return { mayNeedAutoEnable: false, configuredChannelIds };
}
return (
resolvePluginSetupAutoEnableReasons({
config: cfg,
env,
pluginIds: resolveRelevantSetupAutoEnablePluginIds(cfg),
}).length > 0
);
return {
mayNeedAutoEnable:
resolvePluginSetupAutoEnableReasons({
config: cfg,
env,
pluginIds: resolveRelevantSetupAutoEnablePluginIds(cfg),
}).length > 0,
configuredChannelIds,
};
}
export function resolvePluginAutoEnableCandidateReason(
@@ -548,9 +558,11 @@ export function resolveConfiguredPluginAutoEnableCandidates(params: {
config: OpenClawConfig;
env: NodeJS.ProcessEnv;
registry: PluginManifestRegistry;
configuredChannelIds?: readonly string[];
}): PluginAutoEnableCandidate[] {
const changes: PluginAutoEnableCandidate[] = [];
for (const channelId of collectConfiguredChannelIds(params.config, params.env)) {
for (const channelId of params.configuredChannelIds ??
collectConfiguredChannelIds(params.config, params.env)) {
for (const pluginId of collectPluginIdsForConfiguredChannel(channelId, params.registry)) {
changes.push({ pluginId, kind: "channel-configured", channelId });
}