mirror of
https://github.com/openclaw/openclaw.git
synced 2026-06-22 23:48:10 +00:00
Allow an explicit canonical ClickClack enable/setup selection to record ClickClack in a nonempty plugin allowlist, while preserving unrelated allowlist rejection, denylist authority, and global plugin disablement.
Validated at source head 24af9d8e75 with focused regressions, built-CLI disposable-config E2E, security checks, and autoreview. Merged under owner authorization despite the two documented untouched-main agent-core baseline failures.
70 lines
2.3 KiB
TypeScript
70 lines
2.3 KiB
TypeScript
// Resolves plugin enablement state from config and channel context.
|
|
import { normalizeChatChannelId } from "../channels/ids.js";
|
|
import { ensurePluginAllowlisted } from "../config/plugins-allowlist.js";
|
|
import type { OpenClawConfig } from "../config/types.openclaw.js";
|
|
import { setPluginEnabledInConfig } from "./toggle-config.js";
|
|
|
|
type PluginEnableOptions = {
|
|
updateChannelConfig?: boolean;
|
|
};
|
|
|
|
/** Result of enabling a plugin in config. */
|
|
export type PluginEnableResult = {
|
|
config: OpenClawConfig;
|
|
enabled: boolean;
|
|
pluginId: string;
|
|
reason?: string;
|
|
};
|
|
|
|
/** Enables a plugin in config unless global, denylist, or allowlist policy blocks it. */
|
|
export function enablePluginInConfig(
|
|
cfg: OpenClawConfig,
|
|
pluginId: string,
|
|
options: PluginEnableOptions = {},
|
|
): PluginEnableResult {
|
|
const builtInChannelId = normalizeChatChannelId(pluginId);
|
|
const resolvedId = builtInChannelId ?? pluginId;
|
|
if (cfg.plugins?.enabled === false) {
|
|
return { config: cfg, enabled: false, pluginId: resolvedId, reason: "plugins disabled" };
|
|
}
|
|
if (cfg.plugins?.deny?.includes(pluginId) || cfg.plugins?.deny?.includes(resolvedId)) {
|
|
return { config: cfg, enabled: false, pluginId: resolvedId, reason: "blocked by denylist" };
|
|
}
|
|
const allow = cfg.plugins?.allow;
|
|
if (
|
|
Array.isArray(allow) &&
|
|
allow.length > 0 &&
|
|
!allow.includes(pluginId) &&
|
|
!allow.includes(resolvedId)
|
|
) {
|
|
return { config: cfg, enabled: false, pluginId: resolvedId, reason: "blocked by allowlist" };
|
|
}
|
|
return {
|
|
config: setPluginEnabledInConfig(cfg, resolvedId, true, options),
|
|
enabled: true,
|
|
pluginId: resolvedId,
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Enables a plugin selected through an explicit user action.
|
|
*
|
|
* ClickClack is bundled without a separate install trust record, so selecting
|
|
* it is the trust gesture that materializes its id in a restrictive allowlist.
|
|
*/
|
|
export function enableExplicitlySelectedPluginInConfig(
|
|
cfg: OpenClawConfig,
|
|
pluginId: string,
|
|
options: PluginEnableOptions = {},
|
|
): PluginEnableResult {
|
|
const result = enablePluginInConfig(cfg, pluginId, options);
|
|
if (result.reason !== "blocked by allowlist" || result.pluginId !== "clickclack") {
|
|
return result;
|
|
}
|
|
return enablePluginInConfig(
|
|
ensurePluginAllowlisted(cfg, result.pluginId),
|
|
result.pluginId,
|
|
options,
|
|
);
|
|
}
|