Repository navigation
feat(hook): 终端权限确认框桥接到飞书(PermissionRequest → 允许/拒绝卡片,超时自动拒绝) - #1656
Merged
deepcoldy merged 1 commit intoOct 3, 2026
Merged
Conversation
bypassPermissions 下 Claude Code 仍会为内置安全检查(如 "Dangerous rm operation on possibly-empty variable path")弹终端确认框。飞书侧看不到这个框,会话表现为 静默卡死,只有进终端手工点 Yes 才能继续。 - installer:Claude settings 追加 hooks.PermissionRequest(无 matcher,timeout 900s), 复用同一条 `botmux hook <cliId>` 命令;幂等替换旧的 botmux 条目 - claude adapter:parsePermissionRequest 把工具名/说明/命令转成一问两选 (允许执行 / 拒绝);AskUserQuestion 仍走原提问卡片 - runHook:权限确认默认等 10 分钟(BOTMUX_PERMISSION_TIMEOUT_MS 可调,钳在 840s 内); 允许 → allow;拒绝 / 话题内文字回复 / 超时 / 卡片失效 / 投递失败 → deny,并把原因 回给模型,让它改用不需确认的写法继续。非 botmux 会话与 workflow 子 agent 保持空输出 - daemon 侧不改:直接复用现有 ask broker、卡片与回调 Co-Authored-By: Claude Opus 5.5 <[email protected]>
xu4wang
requested review from
47seek,
LucasIcarus,
deepcoldy,
xiaoxueSunn and
xiongz-c
as code owners
September 30, 2026 13:59
Owner
|
你好 @xu4wang,我们已经为这个 PR 建了飞书评审群,首次评审正在进行中。 由于你是飞书外部成员,无法被直接拉入内部群,请点击下面的一年有效链接自行申请加入,后续评审结论和需要你修改的地方都会在群里同步: 也可以把你的 GitHub 账号和飞书信息补录到作者名单文档,之后的 PR 评审群会自动拉你:https://bytedance.larkoffice.com/wiki/WJ1nwWbtxi89erkNGNbcgkt9nUe (这是自动评审流程的提示消息,最终结论以维护者审阅为准。) |
Contributor
Author
|
说明一下相关 PR:#1679 用识别屏幕的方式发提醒,和本 PR 是互补关系。两者怎么分工、同时合入时要协调的那一处冲突,写在这条评论里:#1679 (comment) |
|
🚀 Released in v3.34.0 |
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.
问题
bypassPermissions 模式下,Claude Code 仍会为内置安全检查弹出终端确认框,例如:
飞书侧看不到这个确认框,会话就表现为静默卡住。只有进 Web 终端手动点 Yes 才能继续,而且不看终端根本不知道它卡住了。目前 botmux 只在消息投递失败时扫一次屏幕,轮次进行中弹出的确认框完全感知不到。
方案
Claude Code 在弹出确认框时会触发
PermissionRequesthook,payload 带tool_name、tool_input、permission_mode。hook 可以通过decision.behavior = allow | deny直接给出裁决。本 PR 复用现有的 AskUserQuestion 桥接,daemon 侧零改动:hooks.PermissionRequest(不写 matcher,timeout 900s),复用同一条botmux hook <cliId>命令;重复安装幂等,会替换掉旧的 botmux 条目。parsePermissionRequest/formatPermissionDecision。前者把工具名、说明、命令(截断后)转成一问两选:「允许执行 / 拒绝」。AskUserQuestion的 PermissionRequest 仍按原逻辑走提问卡片。BOTMUX_PERMISSION_TIMEOUT_MS调整,上限钳在 840s,保证 hook 客户端先于 Claude 的进程超时给出裁决。各结果的处理:allowdeny,并在message里告诉模型原因和不需要确认的改写方式(比如用字面路径或${VAR:?})设计上的取舍:确认请求一旦路由进 botmux 会话,任何「没拿到人工裁决」的结局都按拒绝处理。原因是 passthrough 会让终端确认框照样弹出来,而那正是这个 PR 要消除的静默卡死。
验证
test/permission-request-hook.test.ts,共 14 个用例:adapter 解析、各种裁决结局、超时默认值与上限、非 botmux / workflow / codex 路径。更新了hook-installer.test.ts的 (d),新增 (e) 覆盖幂等。b820c7dcc)是同一批,都是时序敏感的集成测试,单独跑两边都是全绿。Allowed by PermissionRequest hook,命令执行成功。Denied by PermissionRequest hook。模型读到 deny message 后,自己改用字面路径完成了任务,全程没有卡住。已知行为(请维护者判断)
AskUserQuestion的形状走了原有的提问卡片(24h 超时)。这类框以前同样会让会话静默卡住,所以本 PR 保持现状。但要注意,其中 "Switch automatically" 这类选项会改全局配置,是否要对这类系统框单独处理(比如只提醒、不允许在飞书里作答),留给维护者决定。answererOpenId或 operate 判定。🤖 Generated with Claude Code