refactor(channels): centralize runtime group policy handling

This commit is contained in:
Peter Steinberger
2026-02-22 12:35:02 +01:00
parent a4607277a9
commit 85e5ed3f78
34 changed files with 345 additions and 300 deletions

View File

@@ -4,7 +4,7 @@ import {
formatPairingApproveHint,
getChatChannelMeta,
PAIRING_APPROVED_MESSAGE,
resolveRuntimeGroupPolicy,
resolveAllowlistProviderRuntimeGroupPolicy,
setAccountEnabledInConfigSection,
deleteAccountFromConfigSection,
type ChannelPlugin,
@@ -136,12 +136,10 @@ export const ircPlugin: ChannelPlugin<ResolvedIrcAccount, IrcProbe> = {
collectWarnings: ({ account, cfg }) => {
const warnings: string[] = [];
const defaultGroupPolicy = cfg.channels?.defaults?.groupPolicy;
const { groupPolicy } = resolveRuntimeGroupPolicy({
const { groupPolicy } = resolveAllowlistProviderRuntimeGroupPolicy({
providerConfigPresent: cfg.channels?.irc !== undefined,
groupPolicy: account.config.groupPolicy,
defaultGroupPolicy,
configuredFallbackPolicy: "allowlist",
missingProviderFallbackPolicy: "allowlist",
});
if (groupPolicy === "open") {
warnings.push(

View File

@@ -2,7 +2,8 @@ import {
createReplyPrefixOptions,
logInboundDrop,
resolveControlCommandGate,
resolveRuntimeGroupPolicy,
resolveAllowlistProviderRuntimeGroupPolicy,
warnMissingProviderGroupPolicyFallbackOnce,
type OpenClawConfig,
type RuntimeEnv,
} from "openclaw/plugin-sdk";
@@ -20,7 +21,6 @@ import { sendMessageIrc } from "./send.js";
import type { CoreConfig, IrcInboundMessage } from "./types.js";
const CHANNEL_ID = "irc" as const;
const warnedMissingProviderGroupPolicy = new Set<string>();
const escapeIrcRegexLiteral = (value: string) => value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
@@ -87,19 +87,19 @@ export async function handleIrcInbound(params: {
const dmPolicy = account.config.dmPolicy ?? "pairing";
const defaultGroupPolicy = config.channels?.defaults?.groupPolicy;
const { groupPolicy, providerMissingFallbackApplied } = resolveRuntimeGroupPolicy({
providerConfigPresent: config.channels?.irc !== undefined,
groupPolicy: account.config.groupPolicy,
defaultGroupPolicy,
configuredFallbackPolicy: "allowlist",
missingProviderFallbackPolicy: "allowlist",
const { groupPolicy, providerMissingFallbackApplied } =
resolveAllowlistProviderRuntimeGroupPolicy({
providerConfigPresent: config.channels?.irc !== undefined,
groupPolicy: account.config.groupPolicy,
defaultGroupPolicy,
});
warnMissingProviderGroupPolicyFallbackOnce({
providerMissingFallbackApplied,
providerKey: "irc",
accountId: account.accountId,
blockedLabel: "channel messages",
log: (message) => runtime.log?.(message),
});
if (providerMissingFallbackApplied && !warnedMissingProviderGroupPolicy.has(account.accountId)) {
warnedMissingProviderGroupPolicy.add(account.accountId);
runtime.log?.(
'irc: channels.irc is missing; defaulting groupPolicy to "allowlist" (channel messages blocked until explicitly configured).',
);
}
const configAllowFrom = normalizeIrcAllowlist(account.config.allowFrom);
const configGroupAllowFrom = normalizeIrcAllowlist(account.config.groupAllowFrom);