feat: auto native commands defaults
This commit is contained in:
35
src/config/commands.ts
Normal file
35
src/config/commands.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import type { NativeCommandsSetting } from "./types.js";
|
||||
import { normalizeProviderId } from "../providers/registry.js";
|
||||
import type { ProviderId } from "../providers/plugins/types.js";
|
||||
|
||||
function resolveAutoDefault(providerId?: ProviderId): boolean {
|
||||
const id = normalizeProviderId(providerId);
|
||||
if (!id) return false;
|
||||
if (id === "discord" || id === "telegram") return true;
|
||||
if (id === "slack") return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
export function resolveNativeCommandsEnabled(params: {
|
||||
providerId: ProviderId;
|
||||
providerSetting?: NativeCommandsSetting;
|
||||
globalSetting?: NativeCommandsSetting;
|
||||
}): boolean {
|
||||
const { providerId, providerSetting, globalSetting } = params;
|
||||
const setting =
|
||||
providerSetting === undefined ? globalSetting : providerSetting;
|
||||
if (setting === true) return true;
|
||||
if (setting === false) return false;
|
||||
// auto or undefined -> heuristic
|
||||
return resolveAutoDefault(providerId);
|
||||
}
|
||||
|
||||
export function isNativeCommandsExplicitlyDisabled(params: {
|
||||
providerSetting?: NativeCommandsSetting;
|
||||
globalSetting?: NativeCommandsSetting;
|
||||
}): boolean {
|
||||
const { providerSetting, globalSetting } = params;
|
||||
if (providerSetting === false) return true;
|
||||
if (providerSetting === undefined) return globalSetting === false;
|
||||
return false;
|
||||
}
|
||||
@@ -283,6 +283,12 @@ const FIELD_HELP: Record<string, string> = {
|
||||
"Allow /restart and gateway restart tool actions (default: false).",
|
||||
"commands.useAccessGroups":
|
||||
"Enforce access-group allowlists/policies for commands.",
|
||||
"discord.commands.native":
|
||||
'Override native commands for Discord (bool or "auto").',
|
||||
"telegram.commands.native":
|
||||
'Override native commands for Telegram (bool or "auto").',
|
||||
"slack.commands.native":
|
||||
'Override native commands for Slack (bool or "auto").',
|
||||
"session.agentToAgent.maxPingPongTurns":
|
||||
"Max reply-back turns between requester and target (0–5).",
|
||||
"messages.ackReaction":
|
||||
|
||||
@@ -359,6 +359,8 @@ export type TelegramAccountConfig = {
|
||||
name?: string;
|
||||
/** Optional provider capability tags used for agent/runtime guidance. */
|
||||
capabilities?: string[];
|
||||
/** Override native command registration for Telegram (bool or "auto"). */
|
||||
commands?: ProviderCommandsConfig;
|
||||
/**
|
||||
* Controls how Telegram direct chats (DMs) are handled:
|
||||
* - "pairing" (default): unknown senders get a pairing code; owner must approve
|
||||
@@ -510,6 +512,8 @@ export type DiscordAccountConfig = {
|
||||
name?: string;
|
||||
/** Optional provider capability tags used for agent/runtime guidance. */
|
||||
capabilities?: string[];
|
||||
/** Override native command registration for Discord (bool or "auto"). */
|
||||
commands?: ProviderCommandsConfig;
|
||||
/** If false, do not start this Discord account. Default: true. */
|
||||
enabled?: boolean;
|
||||
token?: string;
|
||||
@@ -621,6 +625,8 @@ export type SlackAccountConfig = {
|
||||
name?: string;
|
||||
/** Optional provider capability tags used for agent/runtime guidance. */
|
||||
capabilities?: string[];
|
||||
/** Override native command registration for Slack (bool or "auto"). */
|
||||
commands?: ProviderCommandsConfig;
|
||||
/** If false, do not start this Slack account. Default: true. */
|
||||
enabled?: boolean;
|
||||
botToken?: string;
|
||||
@@ -1209,9 +1215,11 @@ export type MessagesConfig = {
|
||||
removeAckAfterReply?: boolean;
|
||||
};
|
||||
|
||||
export type NativeCommandsSetting = boolean | "auto";
|
||||
|
||||
export type CommandsConfig = {
|
||||
/** Enable native command registration when supported (default: false). */
|
||||
native?: boolean;
|
||||
/** Enable native command registration when supported (default: "auto"). */
|
||||
native?: NativeCommandsSetting;
|
||||
/** Enable text command parsing (default: true). */
|
||||
text?: boolean;
|
||||
/** Allow /config command (default: false). */
|
||||
@@ -1224,6 +1232,11 @@ export type CommandsConfig = {
|
||||
useAccessGroups?: boolean;
|
||||
};
|
||||
|
||||
export type ProviderCommandsConfig = {
|
||||
/** Override native command registration for this provider (bool or "auto"). */
|
||||
native?: NativeCommandsSetting;
|
||||
};
|
||||
|
||||
export type BridgeBindMode = "auto" | "lan" | "tailnet" | "loopback";
|
||||
|
||||
export type BridgeConfig = {
|
||||
|
||||
@@ -269,6 +269,7 @@ const TelegramAccountSchemaBase = z.object({
|
||||
name: z.string().optional(),
|
||||
capabilities: z.array(z.string()).optional(),
|
||||
enabled: z.boolean().optional(),
|
||||
commands: ProviderCommandsSchema,
|
||||
dmPolicy: DmPolicySchema.optional().default("pairing"),
|
||||
botToken: z.string().optional(),
|
||||
tokenFile: z.string().optional(),
|
||||
@@ -367,6 +368,7 @@ const DiscordAccountSchema = z.object({
|
||||
name: z.string().optional(),
|
||||
capabilities: z.array(z.string()).optional(),
|
||||
enabled: z.boolean().optional(),
|
||||
commands: ProviderCommandsSchema,
|
||||
token: z.string().optional(),
|
||||
allowBots: z.boolean().optional(),
|
||||
groupPolicy: GroupPolicySchema.optional().default("allowlist"),
|
||||
@@ -440,6 +442,7 @@ const SlackAccountSchema = z.object({
|
||||
name: z.string().optional(),
|
||||
capabilities: z.array(z.string()).optional(),
|
||||
enabled: z.boolean().optional(),
|
||||
commands: ProviderCommandsSchema,
|
||||
botToken: z.string().optional(),
|
||||
appToken: z.string().optional(),
|
||||
allowBots: z.boolean().optional(),
|
||||
@@ -709,16 +712,28 @@ const MessagesSchema = z
|
||||
})
|
||||
.optional();
|
||||
|
||||
const NativeCommandsSettingSchema = z.union([
|
||||
z.boolean(),
|
||||
z.literal("auto"),
|
||||
]);
|
||||
|
||||
const ProviderCommandsSchema = z
|
||||
.object({
|
||||
native: NativeCommandsSettingSchema.optional(),
|
||||
})
|
||||
.optional();
|
||||
|
||||
const CommandsSchema = z
|
||||
.object({
|
||||
native: z.boolean().optional(),
|
||||
native: NativeCommandsSettingSchema.optional().default("auto"),
|
||||
text: z.boolean().optional(),
|
||||
config: z.boolean().optional(),
|
||||
debug: z.boolean().optional(),
|
||||
restart: z.boolean().optional(),
|
||||
useAccessGroups: z.boolean().optional(),
|
||||
})
|
||||
.optional();
|
||||
.optional()
|
||||
.default({ native: "auto" });
|
||||
|
||||
const HeartbeatSchema = z
|
||||
.object({
|
||||
|
||||
@@ -51,6 +51,10 @@ import { getReplyFromConfig } from "../auto-reply/reply.js";
|
||||
import type { ReplyPayload } from "../auto-reply/types.js";
|
||||
import type { ClawdbotConfig, ReplyToMode } from "../config/config.js";
|
||||
import { loadConfig } from "../config/config.js";
|
||||
import {
|
||||
isNativeCommandsExplicitlyDisabled,
|
||||
resolveNativeCommandsEnabled,
|
||||
} from "../config/commands.js";
|
||||
import { resolveStorePath, updateLastRoute } from "../config/sessions.js";
|
||||
import { danger, logVerbose, shouldLogVerbose } from "../globals.js";
|
||||
import { formatDurationSeconds } from "../infra/format-duration.js";
|
||||
@@ -403,8 +407,15 @@ export async function monitorDiscordProvider(opts: MonitorDiscordOpts = {}) {
|
||||
const dmPolicy = dmConfig?.policy ?? "pairing";
|
||||
const groupDmEnabled = dmConfig?.groupEnabled ?? false;
|
||||
const groupDmChannels = dmConfig?.groupChannels;
|
||||
const nativeEnabled = cfg.commands?.native === true;
|
||||
const nativeDisabledExplicit = cfg.commands?.native === false;
|
||||
const nativeEnabled = resolveNativeCommandsEnabled({
|
||||
providerId: "discord",
|
||||
providerSetting: discordCfg.commands?.native,
|
||||
globalSetting: cfg.commands?.native,
|
||||
});
|
||||
const nativeDisabledExplicit = isNativeCommandsExplicitlyDisabled({
|
||||
providerSetting: discordCfg.commands?.native,
|
||||
globalSetting: cfg.commands?.native,
|
||||
});
|
||||
const useAccessGroups = cfg.commands?.useAccessGroups !== false;
|
||||
const sessionPrefix = "discord:slash";
|
||||
const ephemeralDefault = true;
|
||||
|
||||
@@ -44,6 +44,7 @@ import type {
|
||||
SlackSlashCommandConfig,
|
||||
} from "../config/config.js";
|
||||
import { loadConfig } from "../config/config.js";
|
||||
import { resolveNativeCommandsEnabled } from "../config/commands.js";
|
||||
import {
|
||||
resolveSessionKey,
|
||||
resolveStorePath,
|
||||
@@ -1944,8 +1945,14 @@ export async function monitorSlackProvider(opts: MonitorSlackOpts = {}) {
|
||||
}
|
||||
};
|
||||
|
||||
const nativeCommands =
|
||||
cfg.commands?.native === true ? listNativeCommandSpecsForConfig(cfg) : [];
|
||||
const nativeEnabled = resolveNativeCommandsEnabled({
|
||||
providerId: "slack",
|
||||
providerSetting: account.config.commands?.native,
|
||||
globalSetting: cfg.commands?.native,
|
||||
});
|
||||
const nativeCommands = nativeEnabled
|
||||
? listNativeCommandSpecsForConfig(cfg)
|
||||
: [];
|
||||
if (nativeCommands.length > 0) {
|
||||
for (const command of nativeCommands) {
|
||||
app.command(
|
||||
|
||||
@@ -35,6 +35,10 @@ import { getReplyFromConfig } from "../auto-reply/reply.js";
|
||||
import type { ReplyPayload } from "../auto-reply/types.js";
|
||||
import type { ClawdbotConfig, ReplyToMode } from "../config/config.js";
|
||||
import { loadConfig } from "../config/config.js";
|
||||
import {
|
||||
isNativeCommandsExplicitlyDisabled,
|
||||
resolveNativeCommandsEnabled,
|
||||
} from "../config/commands.js";
|
||||
import {
|
||||
resolveProviderGroupPolicy,
|
||||
resolveProviderGroupRequireMention,
|
||||
@@ -291,8 +295,15 @@ export function createTelegramBot(opts: TelegramBotOptions) {
|
||||
};
|
||||
const replyToMode = opts.replyToMode ?? telegramCfg.replyToMode ?? "first";
|
||||
const streamMode = resolveTelegramStreamMode(telegramCfg);
|
||||
const nativeEnabled = cfg.commands?.native === true;
|
||||
const nativeDisabledExplicit = cfg.commands?.native === false;
|
||||
const nativeEnabled = resolveNativeCommandsEnabled({
|
||||
providerId: "telegram",
|
||||
providerSetting: telegramCfg.commands?.native,
|
||||
globalSetting: cfg.commands?.native,
|
||||
});
|
||||
const nativeDisabledExplicit = isNativeCommandsExplicitlyDisabled({
|
||||
providerSetting: telegramCfg.commands?.native,
|
||||
globalSetting: cfg.commands?.native,
|
||||
});
|
||||
const useAccessGroups = cfg.commands?.useAccessGroups !== false;
|
||||
const ackReactionScope = cfg.messages?.ackReactionScope ?? "group-mentions";
|
||||
const mediaMaxBytes =
|
||||
|
||||
Reference in New Issue
Block a user