Channels: add per-group tool policies

This commit is contained in:
Adam Holt
2026-01-24 15:35:05 +13:00
committed by Peter Steinberger
parent e51bf46abe
commit c07949a99c
47 changed files with 512 additions and 11 deletions

View File

@@ -1,11 +1,13 @@
import type { ChannelId } from "../channels/plugins/types.js";
import { normalizeAccountId } from "../routing/session-key.js";
import type { ClawdbotConfig } from "./config.js";
import type { GroupToolPolicyConfig } from "./types.tools.js";
export type GroupPolicyChannel = ChannelId;
export type ChannelGroupConfig = {
requireMention?: boolean;
tools?: GroupToolPolicyConfig;
};
export type ChannelGroupPolicy = {
@@ -91,3 +93,15 @@ export function resolveChannelGroupRequireMention(params: {
}
return true;
}
export function resolveChannelGroupToolsPolicy(params: {
cfg: ClawdbotConfig;
channel: GroupPolicyChannel;
groupId?: string | null;
accountId?: string | null;
}): GroupToolPolicyConfig | undefined {
const { groupConfig, defaultConfig } = resolveChannelGroupPolicy(params);
if (groupConfig?.tools) return groupConfig.tools;
if (defaultConfig?.tools) return defaultConfig.tools;
return undefined;
}

View File

@@ -7,6 +7,7 @@ import type {
ReplyToMode,
} from "./types.base.js";
import type { DmConfig, ProviderCommandsConfig } from "./types.messages.js";
import type { GroupToolPolicyConfig } from "./types.tools.js";
export type DiscordDmConfig = {
/** If false, ignore all incoming Discord DMs. Default: true. */
@@ -24,6 +25,8 @@ export type DiscordDmConfig = {
export type DiscordGuildChannelConfig = {
allow?: boolean;
requireMention?: boolean;
/** Optional tool policy overrides for this channel. */
tools?: GroupToolPolicyConfig;
/** If specified, only load these skills for this channel. Omit = all skills; empty = no skills. */
skills?: string[];
/** If false, disable the bot for this channel. */
@@ -39,6 +42,8 @@ export type DiscordReactionNotificationMode = "off" | "own" | "all" | "allowlist
export type DiscordGuildEntry = {
slug?: string;
requireMention?: boolean;
/** Optional tool policy overrides for this guild (used when channel override is missing). */
tools?: GroupToolPolicyConfig;
/** Reaction notification mode (off|own|all|allowlist). Default: own. */
reactionNotifications?: DiscordReactionNotificationMode;
users?: Array<string | number>;

View File

@@ -5,6 +5,7 @@ import type {
MarkdownConfig,
} from "./types.base.js";
import type { DmConfig } from "./types.messages.js";
import type { GroupToolPolicyConfig } from "./types.tools.js";
export type IMessageAccountConfig = {
/** Optional display name for this account (used in CLI/UI lists). */
@@ -59,6 +60,7 @@ export type IMessageAccountConfig = {
string,
{
requireMention?: boolean;
tools?: GroupToolPolicyConfig;
}
>;
};

View File

@@ -5,6 +5,7 @@ import type {
MarkdownConfig,
} from "./types.base.js";
import type { DmConfig } from "./types.messages.js";
import type { GroupToolPolicyConfig } from "./types.tools.js";
export type MSTeamsWebhookConfig = {
/** Port for the webhook server. Default: 3978. */
@@ -20,6 +21,8 @@ export type MSTeamsReplyStyle = "thread" | "top-level";
export type MSTeamsChannelConfig = {
/** Require @mention to respond. Default: true. */
requireMention?: boolean;
/** Optional tool policy overrides for this channel. */
tools?: GroupToolPolicyConfig;
/** Reply style: "thread" replies to the message, "top-level" posts a new message. */
replyStyle?: MSTeamsReplyStyle;
};
@@ -28,6 +31,8 @@ export type MSTeamsChannelConfig = {
export type MSTeamsTeamConfig = {
/** Default requireMention for channels in this team. */
requireMention?: boolean;
/** Default tool policy for channels in this team. */
tools?: GroupToolPolicyConfig;
/** Default reply style for channels in this team. */
replyStyle?: MSTeamsReplyStyle;
/** Per-channel overrides. Key is conversation ID (e.g., "19:...@thread.tacv2"). */

View File

@@ -6,6 +6,7 @@ import type {
ReplyToMode,
} from "./types.base.js";
import type { DmConfig, ProviderCommandsConfig } from "./types.messages.js";
import type { GroupToolPolicyConfig } from "./types.tools.js";
export type SlackDmConfig = {
/** If false, ignore all incoming Slack DMs. Default: true. */
@@ -29,6 +30,8 @@ export type SlackChannelConfig = {
allow?: boolean;
/** Require mentioning the bot to trigger replies. */
requireMention?: boolean;
/** Optional tool policy overrides for this channel. */
tools?: GroupToolPolicyConfig;
/** Allow bot-authored messages to trigger replies (default: false). */
allowBots?: boolean;
/** Allowlist of users that can invoke the bot in this channel. */

View File

@@ -8,6 +8,7 @@ import type {
ReplyToMode,
} from "./types.base.js";
import type { DmConfig, ProviderCommandsConfig } from "./types.messages.js";
import type { GroupToolPolicyConfig } from "./types.tools.js";
export type TelegramActionConfig = {
reactions?: boolean;
@@ -128,6 +129,8 @@ export type TelegramTopicConfig = {
export type TelegramGroupConfig = {
requireMention?: boolean;
/** Optional tool policy overrides for this group. */
tools?: GroupToolPolicyConfig;
/** If specified, only load these skills for this group (when no topic). Omit = all skills; empty = no skills. */
skills?: string[];
/** Per-topic configuration (key is message_thread_id as string) */

View File

@@ -120,6 +120,11 @@ export type ToolPolicyConfig = {
profile?: ToolProfileId;
};
export type GroupToolPolicyConfig = {
allow?: string[];
deny?: string[];
};
export type ExecToolConfig = {
/** Exec host routing (default: sandbox). */
host?: "sandbox" | "gateway" | "node";

View File

@@ -5,6 +5,7 @@ import type {
MarkdownConfig,
} from "./types.base.js";
import type { DmConfig } from "./types.messages.js";
import type { GroupToolPolicyConfig } from "./types.tools.js";
export type WhatsAppActionConfig = {
reactions?: boolean;
@@ -65,6 +66,7 @@ export type WhatsAppConfig = {
string,
{
requireMention?: boolean;
tools?: GroupToolPolicyConfig;
}
>;
/** Acknowledgment reaction sent immediately upon message receipt. */
@@ -125,6 +127,7 @@ export type WhatsAppAccountConfig = {
string,
{
requireMention?: boolean;
tools?: GroupToolPolicyConfig;
}
>;
/** Acknowledgment reaction sent immediately upon message receipt. */

View File

@@ -14,6 +14,7 @@ import {
RetryConfigSchema,
requireOpenAllowFrom,
} from "./zod-schema.core.js";
import { ToolPolicySchema } from "./zod-schema.agent-runtime.js";
import {
normalizeTelegramCommandDescription,
normalizeTelegramCommandName,
@@ -44,6 +45,7 @@ export const TelegramTopicSchema = z
export const TelegramGroupSchema = z
.object({
requireMention: z.boolean().optional(),
tools: ToolPolicySchema,
skills: z.array(z.string()).optional(),
enabled: z.boolean().optional(),
allowFrom: z.array(z.union([z.string(), z.number()])).optional(),
@@ -173,6 +175,7 @@ export const DiscordGuildChannelSchema = z
.object({
allow: z.boolean().optional(),
requireMention: z.boolean().optional(),
tools: ToolPolicySchema,
skills: z.array(z.string()).optional(),
enabled: z.boolean().optional(),
users: z.array(z.union([z.string(), z.number()])).optional(),
@@ -185,6 +188,7 @@ export const DiscordGuildSchema = z
.object({
slug: z.string().optional(),
requireMention: z.boolean().optional(),
tools: ToolPolicySchema,
reactionNotifications: z.enum(["off", "own", "all", "allowlist"]).optional(),
users: z.array(z.union([z.string(), z.number()])).optional(),
channels: z.record(z.string(), DiscordGuildChannelSchema.optional()).optional(),
@@ -270,6 +274,7 @@ export const SlackChannelSchema = z
enabled: z.boolean().optional(),
allow: z.boolean().optional(),
requireMention: z.boolean().optional(),
tools: ToolPolicySchema,
allowBots: z.boolean().optional(),
users: z.array(z.union([z.string(), z.number()])).optional(),
skills: z.array(z.string()).optional(),
@@ -466,6 +471,7 @@ export const IMessageAccountSchemaBase = z
z
.object({
requireMention: z.boolean().optional(),
tools: ToolPolicySchema,
})
.strict()
.optional(),
@@ -520,6 +526,7 @@ const BlueBubblesActionSchema = z
const BlueBubblesGroupConfigSchema = z
.object({
requireMention: z.boolean().optional(),
tools: ToolPolicySchema,
})
.strict();
@@ -576,6 +583,7 @@ export const BlueBubblesConfigSchema = BlueBubblesAccountSchemaBase.extend({
export const MSTeamsChannelSchema = z
.object({
requireMention: z.boolean().optional(),
tools: ToolPolicySchema,
replyStyle: MSTeamsReplyStyleSchema.optional(),
})
.strict();
@@ -583,6 +591,7 @@ export const MSTeamsChannelSchema = z
export const MSTeamsTeamSchema = z
.object({
requireMention: z.boolean().optional(),
tools: ToolPolicySchema,
replyStyle: MSTeamsReplyStyleSchema.optional(),
channels: z.record(z.string(), MSTeamsChannelSchema.optional()).optional(),
})

View File

@@ -7,6 +7,7 @@ import {
GroupPolicySchema,
MarkdownConfigSchema,
} from "./zod-schema.core.js";
import { ToolPolicySchema } from "./zod-schema.agent-runtime.js";
export const WhatsAppAccountSchema = z
.object({
@@ -37,6 +38,7 @@ export const WhatsAppAccountSchema = z
z
.object({
requireMention: z.boolean().optional(),
tools: ToolPolicySchema,
})
.strict()
.optional(),
@@ -98,6 +100,7 @@ export const WhatsAppConfigSchema = z
z
.object({
requireMention: z.boolean().optional(),
tools: ToolPolicySchema,
})
.strict()
.optional(),