Skip to content

fix: allow unlisted commands with confirmation prompt instead of blocking#8

Merged
TuYv merged 2 commits into
TuYv:masterfrom
genni613:fix/invert-permission
Apr 16, 2026
Merged

fix: allow unlisted commands with confirmation prompt instead of blocking#8
TuYv merged 2 commits into
TuYv:masterfrom
genni613:fix/invert-permission

Conversation

@genni613

Copy link
Copy Markdown
Collaborator

Summary

  • 修复命令执行权限逻辑:白名单内命令免审批自动执行,白名单外命令弹窗确认(不再直接 block)
  • 所有命令(无论是否在白名单)统一展示 ExecutionCard,白名单命令自动跳过审批弹窗
  • 提升输出截断上限(stdout 4k→20k,stderr 2k→10k)

Changes

文件 变更
ChatService.kt 重构 executeToolCallWithApproval 审批顺序:先创建卡片 → path check → whitelist check → 仅非白名单才弹审批弹窗
BridgeHandler.kt 新增 notifyExecutionCard() 方法,调用前端 onExecutionCard 回调
CommandExecutionService.kt 输出截断上限从 4000/2000 提升到 20000/10000
bridge.d.ts Bridge 接口新增 onExecutionCard 回调签名
useBridge.ts 接入 onExecutionCard 回调绑定
App.tsx 分离卡片创建(onExecutionCard → 创建 running 卡片)与审批弹窗(onApprovalRequest → 仅更新状态为 waiting + 打开弹窗)
optimization-backlog.md E-01 归档

Test plan

  • 白名单内命令(如 git status)执行时不弹审批弹窗,直接展示 ExecutionCard 并自动执行
  • 白名单外命令执行时弹出审批弹窗,卡片状态显示「等待审批」
  • 审批弹窗中允许执行后,卡片状态变为「执行中」→「完成」
  • 审批弹窗中拒绝后,卡片状态变为「用户拒绝」
  • 勾选「记住此命令」并允许后,下次同类命令不再弹窗
  • 执行输出较长时(>4000字符)不再被截断
  • 路径越界命令仍被 blocked,不弹审批弹窗
  • 现有单元测试 CommandExecutionServiceTest + BridgeHandlerDispatchTest 全部通过

@TuYv TuYv left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. 之前的4k/2k太克制了 但是20k/10k的放大还是有点浪费的 建议折中并且在截断时告知AI 输出被截断 当前仅为前xxxx字符
    2.审批超时没有前端提示

@genni613

genni613 commented Apr 16, 2026

Copy link
Copy Markdown
Collaborator Author

这个 PR 主要修复了命令执行的权限控制流程,核心改动有三点:

1. 白名单外命令从直接 block 改为弹窗确认
之前非白名单命令会直接返回 ExecutionResult.Blocked,模型拿不到任何执行机会。现在改为弹出审批对话框,用户可以选择允许或拒绝,让模型在用户知情的情况下也能执行非白名单命令。

2. 所有命令统一展示 ExecutionCard
无论是否在白名单内,命令执行都会通过 notifyExecutionCard
展示执行卡片。白名单命令自动跳过审批弹窗直接执行,非白名单命令弹窗等待用户决策。体验上更一致。

3. 审批弹窗支持「记住命令」
用户批准时可以勾选将当前命令加入白名单(addToWhitelist),后续相同命令自动跳过审批。Bridge 层和 ChatService 全链路传递了这个标志。

审批超时弹窗逻辑后续放在错误信息弹窗优化一并修复@Lin-wool;另外命令输出的截断策略也存在一些设计问题,单独提了一个 Issue #11 来讨论,避免在这个 PR 里扩大范围。

@genni613 genni613 requested a review from TuYv April 16, 2026 03:32
RickyRicky137

This comment was marked as spam.

@TuYv TuYv left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

@TuYv TuYv left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

@TuYv TuYv merged commit 19ae89d into TuYv:master Apr 16, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants