Repository navigation
feat(permissions): canTalkDaemonCommands — 把选定 daemon 命令从 canOperate 降到 canTalk - #547
Merged
deepcoldy merged 2 commits intoJul 26, 2026
Merged
Conversation
…cted daemon commands from canOperate to canTalk Adds a per-bot bots.json field `canTalkDaemonCommands: string[]`. Listed daemon commands (e.g. /status, /help) become available to any sender who passes canTalk (oncall members, allowedChatGroups, chat/global grants, p2pOpen DMs) instead of being owner-only. Unset → behavior unchanged. - bot-registry: parse + normalize (lowercase, auto-slash, dedupe, keep only DAEMON_COMMANDS entries) - event-dispatcher: canRunDaemonCommand() = canOperate ∪ (listed ∧ canTalk); chatType omitted → p2pOpen leg stays fail-closed - daemon: both unified DAEMON_COMMANDS gates (new-topic + thread-reply) switch to canRunDaemonCommand; /vc-auth and /term special-cases and handler-internal owner gates (/card /insight /land) intentionally unaffected — internal gates remain the final authority - bot-config-store: /botconfig key with dedicated parser (the default stringList parser rejects daemon commands, which would silently drop all valid input for this field) Co-Authored-By: Claude Fable 5 <[email protected]>
…arn on dropped canTalkDaemonCommands entries codex review findings on the canTalkDaemonCommands PR: - /botconfig set <stringList field> hardcoded parseCustomPassthroughInput, ignoring the field's parseList — for canTalkDaemonCommands that parser rejects every daemon command, so all valid input was silently dropped as 'value required' (also fixes the same latent bug for startupCommands). Now mirrors the card/config-store coerce path: spec.parseList ?? default. - bot-registry parse now warns when entries are dropped from canTalkDaemonCommands (fail-closed but no longer silent). - Field doc: spell out the restrictGrantCommands interaction (that switch fires earlier in routing and blocks grant-leg users regardless of list). Co-Authored-By: Claude Fable 5 <[email protected]>
deepcoldy
approved these changes
Jul 26, 2026
deepcoldy
left a comment
Owner
There was a problem hiding this comment.
✅ 建议合并
本地复核:pnpm build 绿;PR 新增 2 套测试 + 相邻 4 套(bot-registry / bot-config-store / event-dispatcher / grant-gates)全绿。
代码质量
- 统一闸
canRunDaemonCommand = canOperate ∪ (cmd∈名单 ∧ canTalk),两条路由(new-topic / thread-reply)一致改用;参数顺序对齐canTalk签名,unionId / chatType 传递正确。 - p2pOpen 腿在 chatType 省略时 fail-closed,与既有语义一致。
- 顺带修复的
/botconfigstringList 文字命令路径 bug(默认parseCustomPassthroughInput会把本字段合法输入静默滤空,并潜伏影响startupCommands)是真 bug,修法正确且有回归测试。 - 归一化只认
DAEMON_COMMANDS、丢弃非法条目并 warn,语义清晰。
非阻塞提醒
字段接受全部 daemon 命令,包括 /cd /restart /close /rename /oncall 这类状态变更命令,而 /rename /cd /restart 内部没有第二道 owner 闸(不像 /botconfig /card /term)。即 owner 若显式把 /restart 写入名单,canTalk 用户就能重启 bot。这符合 opt-in 设计且已文档化 fail-closed 例外,但字段 hint 举例仅「低危 /status /help」——建议后续在文档/hint 更醒目提示「降级 /cd /restart 等会放开状态变更权」,或引入「推荐可降级」子集。不影响本次合并。
🤖 Reviewed with Claude Code
deepcoldy
added a commit
to xiaoxueSunn/botmux
that referenced
this pull request
Jul 26, 2026
## 动机 PR deepcoldy#547 把 canTalkDaemonCommands 打通了后端字段 + CLI 热配置,但只能靠 /botconfig 文字命令或手改 bots.json 配置。用户希望在 Dashboard 全局配置里 可视化地配「哪些 slash 命令透传给 CLI」「哪些 daemon 命令 canTalk 可用」。 ## 方案 复用现有 per-bot 配置的单一事实源(bot-config-store 的 CONFIG_FIELDS),把两个 stringList immediate 字段接进 Dashboard bot-defaults 页新增的「Slash 命令权限」区块: - customPassthroughCommands:额外透传给底层 CLI 的 slash 命令 - canTalkDaemonCommands:把选定 daemon 命令从 canOperate 降到 canTalk(deepcoldy#547 引入) ## 实现(沿用 startupCommands 的成熟链路) - **dashboard-ipc-server**:bots payload 新增两字段(space-joined 字符串);新增两条 PUT 路由 /api/bot-custom-passthrough、/api/bot-cantalk-daemon-commands,走 coerceConfigValue(尊重字段自带 parseList,与 deepcoldy#547 修的口径一致)+ applyConfigField (写盘 + 内存热更新),空串=清除回默认 - **dashboard.ts**:两条代理路由 /api/bots/:appId/custom-passthrough、/cantalk-daemon-commands - **bot-payload / bot-defaults**:payload 解析 + BotDefaultsRow 类型补两字段 - **bot-defaults-page**:新增 SlashCommandPermissionsSection 组件(两个 textarea + 独立保存按钮),渲染在 GrantSection 旁。两个子编辑器用**独立** useEffect,避免保存 一个字段触发重渲染时清空另一个的未保存草稿 - **i18n**:中英文标签 + help 文案;canTalk 字段 help 醒目提示「/cd /restart /rename 等会改状态,降级须谨慎,建议只放 /status /help 低危命令」(呼应 deepcoldy#547 review 的提醒) ## 影响面 纯 Dashboard 读写路径 + IPC,未触碰权限闸判定逻辑本身(canRunDaemonCommand 不变)。 字段过滤/归一化沿用 deepcoldy#547 已有的 parseList,安全语义不变(canTalk 只认 daemon 命令、 passthrough 拒绝 daemon 命令)。不影响其它 CLI / 后端 / 会话类型。 ## 测试 - pnpm build 绿;dashboard-bot-payload 新增用例(两字段字符串投影 + 缺省空串 + 非字符串兜底) - 相关套件全绿:dashboard-bot-payload / dashboard-ipc / dashboard-i18n / bot-config-store / can-talk-daemon-commands / command-handler - 全量非 e2e 单测通过(仅 3 个 v3-* 进程/PID-namespace 环境相关用例失败,已对照 stash 确认为 master 基线自带、与本改动无关) - live 验证:switch:here + daemon:restart 后实测两条 PUT 端点返回正确过滤结果 (canTalk 丢弃 /compact,passthrough 丢弃 daemon /status),持久化到 bots.json 并读回; 修复了初版「保存一个字段清空另一个草稿」的 UX bug(附截图) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
动机
daemon 命令目前一刀切 owner-only(canOperate),但像
/status/help这类低危命令,bot 主人常希望开放给能对话的人(oncall 群成员、被授权人、p2pOpen 私聊用户)。此前没有中间态:要么把人塞进allowedUsers(全权限),要么完全不配名单(open 模式人人 admin)。方案
新增 per-bot 配置
canTalkDaemonCommands: string[]:列出的 daemon 命令权限闸从 canOperate 降到 canTalk。未配置时行为与现状完全一致。{ "canTalkDaemonCommands": ["/status", "/help"] }也支持热配置:
/botconfig set canTalkDaemonCommands /status /help(immediate 生效)。实现
/、去重、仅接受 DAEMON_COMMANDS 内的命令,丢弃条目打 warn)canRunDaemonCommand()= canOperate ∪(cmd ∈ 名单 ∧ canTalk);chatType 省略时 p2pOpen 腿保持 fail-closedcanRunDaemonCommand,各自传入正确的 unionId 与 chatType/botconfig的 stringList 文字命令路径改为尊重字段自带的parseList(默认解析器parseCustomPassthroughInput刻意拒绝 daemon 命令,硬编码会把本字段的合法输入静默滤光;此修顺带修复startupCommands在同一路径的同款潜伏 bug),并为本字段提供专用解析器parseCanTalkDaemonCommandsInput(反向过滤:只留 daemon 命令)刻意保守的边界(fail-closed)
/vc-auth、/term在统一闸之前特判,不受名单影响,仍 owner-only/card/insight/land等 handler 内部自带第二道 owner 闸的命令:即使列入名单,内部闸仍是最终权威restrictGrantCommands: true时,chatGrant/globalGrant 被授权人被更早的限制闸挡下,本名单对他们不生效(其余 canTalk 腿不受影响)——已写进字段文档已知次要行为(记录在案,未改)
/status)会走既有的 pre-create 路径产生一个worker:null会话记录(会话列表污染,无权限影响)——既有路由行为,改 SESSIONLESS 集合影响面大于收益daemon.cmd_allowed_users_only("仅限 allowedUsers"),对配了名单的 bot 严格说不完全精确,但触发场景极窄(连 canTalk 都没过的发送者)测试
test/can-talk-daemon-commands.test.ts:13 用例覆盖解析归一化(大小写/补斜杠/非 daemon 条目丢弃/去重/空值)、闸逻辑(owner 恒通过/名单内+canTalk 通过/名单外拒绝/无 canTalk 拒绝/未配置等价 canOperate)、p2p fail-closed、/botconfig输入解析器command-handler.test.ts新增/botconfig set canTalkDaemonCommands文字命令路径回归测试(修复前红、修复后绿)🤖 Generated with Claude Code