import { VSCodeCheckbox } from "@vscode/webview-ui-toolkit/react" import { useCallback, useState } from "react" import { useExtensionState } from "../../context/ExtensionStateContext" import { vscode } from "../../utils/vscode" interface AutoApproveAction { id: string label: string enabled: boolean shortName: string description: string } interface AutoApproveMenuProps { style?: React.CSSProperties } const AutoApproveMenu = ({ style }: AutoApproveMenuProps) => { const [isExpanded, setIsExpanded] = useState(false) const { alwaysAllowReadOnly, setAlwaysAllowReadOnly, alwaysAllowWrite, setAlwaysAllowWrite, alwaysAllowExecute, setAlwaysAllowExecute, alwaysAllowBrowser, setAlwaysAllowBrowser, alwaysAllowMcp, setAlwaysAllowMcp, alwaysAllowModeSwitch, setAlwaysAllowModeSwitch, alwaysApproveResubmit, setAlwaysApproveResubmit, autoApprovalEnabled, setAutoApprovalEnabled, } = useExtensionState() const actions: AutoApproveAction[] = [ { id: "readFiles", label: "Read files and directories", shortName: "Read", enabled: alwaysAllowReadOnly ?? false, description: "Allows access to read any file on your computer.", }, { id: "editFiles", label: "Edit files", shortName: "Edit", enabled: alwaysAllowWrite ?? false, description: "Allows modification of any files on your computer.", }, { id: "executeCommands", label: "Execute approved commands", shortName: "Commands", enabled: alwaysAllowExecute ?? false, description: "Allows execution of approved terminal commands. You can configure this in the settings panel.", }, { id: "useBrowser", label: "Use the browser", shortName: "Browser", enabled: alwaysAllowBrowser ?? false, description: "Allows ability to launch and interact with any website in a headless browser.", }, { id: "useMcp", label: "Use MCP servers", shortName: "MCP", enabled: alwaysAllowMcp ?? false, description: "Allows use of configured MCP servers which may modify filesystem or interact with APIs.", }, { id: "switchModes", label: "Switch between modes", shortName: "Modes", enabled: alwaysAllowModeSwitch ?? false, description: "Allows automatic switching between different AI modes without requiring approval.", }, { id: "retryRequests", label: "Retry failed requests", shortName: "Retries", enabled: alwaysApproveResubmit ?? false, description: "Automatically retry failed API requests when the provider returns an error response.", }, ] const toggleExpanded = useCallback(() => { setIsExpanded((prev) => !prev) }, []) const enabledActionsList = actions .filter((action) => action.enabled) .map((action) => action.shortName) .join(", ") // Individual checkbox handlers - each one only updates its own state const handleReadOnlyChange = useCallback(() => { const newValue = !(alwaysAllowReadOnly ?? false) setAlwaysAllowReadOnly(newValue) vscode.postMessage({ type: "alwaysAllowReadOnly", bool: newValue }) }, [alwaysAllowReadOnly, setAlwaysAllowReadOnly]) const handleWriteChange = useCallback(() => { const newValue = !(alwaysAllowWrite ?? false) setAlwaysAllowWrite(newValue) vscode.postMessage({ type: "alwaysAllowWrite", bool: newValue }) }, [alwaysAllowWrite, setAlwaysAllowWrite]) const handleExecuteChange = useCallback(() => { const newValue = !(alwaysAllowExecute ?? false) setAlwaysAllowExecute(newValue) vscode.postMessage({ type: "alwaysAllowExecute", bool: newValue }) }, [alwaysAllowExecute, setAlwaysAllowExecute]) const handleBrowserChange = useCallback(() => { const newValue = !(alwaysAllowBrowser ?? false) setAlwaysAllowBrowser(newValue) vscode.postMessage({ type: "alwaysAllowBrowser", bool: newValue }) }, [alwaysAllowBrowser, setAlwaysAllowBrowser]) const handleMcpChange = useCallback(() => { const newValue = !(alwaysAllowMcp ?? false) setAlwaysAllowMcp(newValue) vscode.postMessage({ type: "alwaysAllowMcp", bool: newValue }) }, [alwaysAllowMcp, setAlwaysAllowMcp]) const handleModeSwitchChange = useCallback(() => { const newValue = !(alwaysAllowModeSwitch ?? false) setAlwaysAllowModeSwitch(newValue) vscode.postMessage({ type: "alwaysAllowModeSwitch", bool: newValue }) }, [alwaysAllowModeSwitch, setAlwaysAllowModeSwitch]) const handleRetryChange = useCallback(() => { const newValue = !(alwaysApproveResubmit ?? false) setAlwaysApproveResubmit(newValue) vscode.postMessage({ type: "alwaysApproveResubmit", bool: newValue }) }, [alwaysApproveResubmit, setAlwaysApproveResubmit]) // Map action IDs to their specific handlers const actionHandlers: Record void> = { readFiles: handleReadOnlyChange, editFiles: handleWriteChange, executeCommands: handleExecuteChange, useBrowser: handleBrowserChange, useMcp: handleMcpChange, switchModes: handleModeSwitchChange, retryRequests: handleRetryChange, } return (
e.stopPropagation()}> { const newValue = !(autoApprovalEnabled ?? false) setAutoApprovalEnabled(newValue) vscode.postMessage({ type: "autoApprovalEnabled", bool: newValue }) }} />
Auto-approve: {enabledActionsList || "None"}
{isExpanded && (
Auto-approve allows Roo Code to perform actions without asking for permission. Only enable for actions you fully trust.
{actions.map((action) => (
e.stopPropagation()}> {action.label}
{action.description}
))}
)}
) } export default AutoApproveMenu