feat: Add auto-approval for mode switching

Implements automatic approval for mode switching operations when enabled, following
existing auto-approval patterns in the codebase.

Implementation:
- Added `alwaysAllowModeSwitch` to state management
- Updated `isAutoApproved` function in ChatView to handle mode switch requests
- Added mode switch option to AutoApproveMenu with appropriate handler
- Integrated with existing auto-approval flow

Tests:
- Added three test cases in ChatView.auto-approve.test.tsx:
  1. Verifies mode switch auto-approval when enabled
  2. Verifies no auto-approval when mode switch setting is disabled
  3. Verifies no auto-approval when global auto-approval is disabled

The implementation follows existing patterns for other auto-approve features
(read, write, browser, etc.) to maintain consistency in the codebase.
This commit is contained in:
MFPires
2025-01-28 01:20:19 -03:00
parent 86d4a10a9a
commit b3be00c050
7 changed files with 201 additions and 2 deletions

View File

@@ -55,6 +55,7 @@ const ChatView = ({ isHidden, showAnnouncement, hideAnnouncement, showHistoryVie
mode,
setMode,
autoApprovalEnabled,
alwaysAllowModeSwitch,
} = useExtensionState()
//const task = messages.length > 0 ? (messages[0].say === "task" ? messages[0] : undefined) : undefined) : undefined
@@ -565,7 +566,10 @@ const ChatView = ({ isHidden, showAnnouncement, hideAnnouncement, showHistoryVie
(alwaysAllowReadOnly && message.ask === "tool" && isReadOnlyToolAction(message)) ||
(alwaysAllowWrite && message.ask === "tool" && isWriteToolAction(message)) ||
(alwaysAllowExecute && message.ask === "command" && isAllowedCommand(message)) ||
(alwaysAllowMcp && message.ask === "use_mcp_server" && isMcpToolAlwaysAllowed(message))
(alwaysAllowMcp && message.ask === "use_mcp_server" && isMcpToolAlwaysAllowed(message)) ||
(alwaysAllowModeSwitch &&
message.ask === "tool" &&
JSON.parse(message.text || "{}")?.tool === "switchMode")
)
},
[
@@ -579,6 +583,7 @@ const ChatView = ({ isHidden, showAnnouncement, hideAnnouncement, showHistoryVie
isAllowedCommand,
alwaysAllowMcp,
isMcpToolAlwaysAllowed,
alwaysAllowModeSwitch,
],
)