feat(agent): add tool confirmation before execution#409
Open
newcat22 wants to merge 2 commits intobytedance:mainfrom
Open
feat(agent): add tool confirmation before execution#409newcat22 wants to merge 2 commits intobytedance:mainfrom
newcat22 wants to merge 2 commits intobytedance:mainfrom
Conversation
Add user confirmation mechanism for tool calls with prefix-based command matching for bash and per-tool-name matching for others. - Add ToolConfirmationResult enum and get_tool_confirmation() abstract method - Add ToolConfirmationConfig to enable/configure per-tool confirmation - Intercept tool calls in BaseAgent._tool_call_handler before execution - For bash: "always approve" uses command prefix matching (e.g. approving "pip install requests" auto-approves all "pip install *" commands) - For non-bash tools: "always approve" remembers the tool name - Add --confirm-tools CLI flag to run and interactive commands - Add session-scoped allowlist (resets on exit/new task) - Add 17 unit tests for the confirmation feature Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
|
|
Add tests for YAML config parsing, CLI --confirm-tools flag, approved tool execution, approve-all prefix matching, and tool exclusion from confirmation list.
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.
Summary
pip install requestsauto-approves allpip install *commands--confirm-toolsCLI flag or YAML configChanges
trae_agent/utils/cli/cli_console.pyToolConfirmationResultenum andget_tool_confirmation()abstract methodtrae_agent/utils/config.pyToolConfirmationConfigdataclass and YAML parsing supporttrae_agent/agent/base_agent.py_tool_call_handlerwith prefix-based matching for bash and name-based matching for otherstrae_agent/agent/trae_agent.pynew_task()trae_agent/utils/cli/simple_console.pyget_tool_confirmation()with y/n/a prompttrae_agent/utils/cli/rich_console.pyget_tool_confirmation()with y/n/a prompttrae_agent/cli.py--confirm-toolsflag torunandinteractivecommandstrae_config.yaml.exampletool_confirmationconfig exampletests/agent/test_tool_confirmation.pyUsage
CLI flag
trae-cli run "list files" --confirm-tools trae-cli interactive --confirm-toolsYAML config
User interaction
When a tool call requires confirmation:
Test plan
trae-cli run "list files" --confirm-toolsshows confirmation prompts (covered by test_cli_confirm_tools_flag, test_rejected_tool_returns_error_result, test_approved_tool_executes_normally)pip install Xwith "a" auto-approves subsequentpip install Y(covered by test_approve_all_adds_prefix_pattern)tool_confirmation.enabled: trueworks (covered by test_tool_confirmation_from_yaml, test_tool_confirmation_default_when_missing_from_yaml)