From 4b7409368f9b7e92b0e73ae8a9bb97944a67e6f4 Mon Sep 17 00:00:00 2001 From: David Kaya Date: Tue, 24 Mar 2026 20:14:14 +0100 Subject: [PATCH] feat: add tool auto-approval UX in pattern editor and activity panel - PatternEditor: tool auto-approval defaults section with toggles per tool - ActivityPanel: per-session override section with inherited/custom state and reset action - ChatPane: surface toolName in approval banner and queued approval list - Disable controls while running; scratchpad non-interactive explanation - Use listApprovalToolDefinitions() exclusively for tool identity Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- src/renderer/App.tsx | 7 ++ src/renderer/components/ActivityPanel.tsx | 124 +++++++++++++++++++++- src/renderer/components/ChatPane.tsx | 4 + src/renderer/components/PatternEditor.tsx | 88 +++++++++++++++ src/renderer/components/SettingsPanel.tsx | 1 + 5 files changed, 223 insertions(+), 1 deletion(-) diff --git a/src/renderer/App.tsx b/src/renderer/App.tsx index ce7d4dc..1c46e50 100644 --- a/src/renderer/App.tsx +++ b/src/renderer/App.tsx @@ -274,6 +274,7 @@ export default function App() { activity={activityForSession} lspProfiles={workspace.settings.tooling.lspProfiles} mcpServers={workspace.settings.tooling.mcpServers} + toolingSettings={workspace.settings.tooling} onJumpToMessage={jumpToMessage} onUpdateSessionTooling={(selection) => { void api.updateSessionTooling({ @@ -282,6 +283,12 @@ export default function App() { enabledLspProfileIds: selection.enabledLspProfileIds, }); }} + onUpdateSessionApprovalSettings={(settings) => { + void api.updateSessionApprovalSettings({ + sessionId: selectedSession.id, + autoApprovedToolNames: settings.autoApprovedToolNames, + }); + }} pattern={patternForSession} projectIsScratchpad={isScratchpadProject(projectForSession)} session={selectedSession} diff --git a/src/renderer/components/ActivityPanel.tsx b/src/renderer/components/ActivityPanel.tsx index e674fd4..e7d988d 100644 --- a/src/renderer/components/ActivityPanel.tsx +++ b/src/renderer/components/ActivityPanel.tsx @@ -1,5 +1,5 @@ import { useMemo, type ReactNode } from 'react'; -import { Activity, Clock, Server, Code, ShieldAlert, Sparkles, Users } from 'lucide-react'; +import { Activity, Clock, RotateCcw, Server, Code, ShieldAlert, ShieldCheck, Sparkles, Users } from 'lucide-react'; import { buildAgentActivityRows, @@ -20,7 +20,10 @@ import type { LspProfileDefinition, McpServerDefinition, SessionToolingSelection, + WorkspaceToolingSettings, } from '@shared/domain/tooling'; +import { listApprovalToolDefinitions, type ApprovalToolDefinition } from '@shared/domain/tooling'; +import type { SessionApprovalSettings } from '@shared/domain/approval'; import { ProviderIcon } from './ProviderIcons'; /* ── Mode accent colours ───────────────────────────────────── */ @@ -159,8 +162,10 @@ interface ActivityPanelProps { activity?: SessionActivityState; lspProfiles: LspProfileDefinition[]; mcpServers: McpServerDefinition[]; + toolingSettings: WorkspaceToolingSettings; onJumpToMessage?: (messageId: string) => void; onUpdateSessionTooling: (selection: SessionToolingSelection) => void; + onUpdateSessionApprovalSettings: (settings: { autoApprovedToolNames?: string[] }) => void; pattern: PatternDefinition; projectIsScratchpad: boolean; session: SessionRecord; @@ -170,8 +175,10 @@ export function ActivityPanel({ activity, lspProfiles, mcpServers, + toolingSettings, onJumpToMessage, onUpdateSessionTooling, + onUpdateSessionApprovalSettings, pattern, projectIsScratchpad, session, @@ -181,12 +188,21 @@ export function ActivityPanel({ [activity, pattern.agents], ); const selection = useMemo(() => resolveSessionToolingSelection(session), [session]); + const approvalTools = useMemo(() => listApprovalToolDefinitions(toolingSettings), [toolingSettings]); + + const isOverridden = session.approvalSettings !== undefined; + const effectiveAutoApproved = new Set( + isOverridden + ? session.approvalSettings!.autoApprovedToolNames + : pattern.approvalPolicy?.autoApprovedToolNames ?? [], + ); const isBusy = session.status === 'running'; const hasPendingApproval = session.pendingApproval?.status === 'pending'; const queuedCount = (session.pendingApprovalQueue ?? []).filter((a) => a.status === 'pending').length; const totalApprovalCount = (hasPendingApproval ? 1 : 0) + queuedCount; const toolsDisabled = isBusy || projectIsScratchpad; + const approvalDisabled = isBusy || projectIsScratchpad; const accent = modeAccent[pattern.mode] ?? modeAccent.single; const hasTools = mcpServers.length > 0 || lspProfiles.length > 0; @@ -317,6 +333,77 @@ export function ActivityPanel({ )} + + {/* ── Auto-approval overrides section ──────────────── */} +
+ + + Auto-Approval + {approvalDisabled && ( + + {projectIsScratchpad ? 'Scratchpad' : 'Running'} + + )} + + +
+ {projectIsScratchpad ? ( +

+ Tool auto-approval does not apply to scratchpad sessions. +

+ ) : approvalTools.length === 0 ? ( +

+ Add MCP servers or LSP profiles in Settings to configure tool auto-approvals. +

+ ) : ( + <> + {/* Override state badge + reset action */} +
+ + {isOverridden ? 'Custom for this session' : 'Inheriting pattern defaults'} + + {isOverridden && ( + + )} +
+ +
+ {approvalTools.map((tool) => ( + { + const next = new Set(effectiveAutoApproved); + if (next.has(tool.id)) { + next.delete(tool.id); + } else { + next.add(tool.id); + } + onUpdateSessionApprovalSettings({ + autoApprovedToolNames: [...next], + }); + }} + tool={tool} + /> + ))} +
+ + )} +
+
); @@ -379,3 +466,38 @@ function toggleId(current: string[], id: string): string[] { ? current.filter((currentId) => currentId !== id) : [...current, id]; } + +function ApprovalOverrideRow({ + tool, + enabled, + disabled, + onToggle, +}: { + tool: ApprovalToolDefinition; + enabled: boolean; + disabled: boolean; + onToggle: () => void; +}) { + const kindBadge = tool.kind === 'lsp' ? 'LSP' : tool.kind === 'mcp' ? 'MCP' : 'Mixed'; + return ( + + ); +} diff --git a/src/renderer/components/ChatPane.tsx b/src/renderer/components/ChatPane.tsx index c3024e8..265ebbe 100644 --- a/src/renderer/components/ChatPane.tsx +++ b/src/renderer/components/ChatPane.tsx @@ -262,6 +262,7 @@ function ApprovalBanner({ {/* Agent / permission context */}
{approval.agentName && Agent: {approval.agentName}} + {approval.toolName && Tool: {approval.toolName}} {approval.permissionKind && Permission: {approval.permissionKind}}
@@ -355,6 +356,9 @@ function QueuedApprovalsList({ approvals }: { approvals: PendingApprovalRecord[] {kindLabel} + {approval.toolName && ( + {approval.toolName} + )} {approval.agentName && ( {approval.agentName} )} diff --git a/src/renderer/components/PatternEditor.tsx b/src/renderer/components/PatternEditor.tsx index 374231f..6598fe3 100644 --- a/src/renderer/components/PatternEditor.tsx +++ b/src/renderer/components/PatternEditor.tsx @@ -29,6 +29,11 @@ import { type PatternDefinition, type PatternAgentDefinition, } from '@shared/domain/pattern'; +import { + listApprovalToolDefinitions, + type ApprovalToolDefinition, + type WorkspaceToolingSettings, +} from '@shared/domain/tooling'; import { ModelSelect, ReasoningEffortSelect } from './AgentConfigFields'; @@ -36,6 +41,7 @@ interface PatternEditorProps { availableModels: ReadonlyArray; pattern: PatternDefinition; isBuiltin: boolean; + toolingSettings: WorkspaceToolingSettings; onChange: (pattern: PatternDefinition) => void; onDelete?: () => void; onSave: () => void; @@ -202,6 +208,7 @@ export function PatternEditor({ availableModels, pattern, isBuiltin, + toolingSettings, onChange, onDelete, onSave, @@ -255,6 +262,22 @@ export function PatternEditor({ }); } + const approvalTools = listApprovalToolDefinitions(toolingSettings); + const autoApprovedSet = new Set(pattern.approvalPolicy?.autoApprovedToolNames ?? []); + + function toggleToolAutoApproval(toolId: string) { + const current = new Set(pattern.approvalPolicy?.autoApprovedToolNames ?? []); + if (current.has(toolId)) { + current.delete(toolId); + } else { + current.add(toolId); + } + updateApprovalPolicy((policy) => ({ + rules: policy?.rules ?? [], + autoApprovedToolNames: current.size > 0 ? [...current] : undefined, + })); + } + return (
{/* Header — consistent ← navigation */} @@ -530,6 +553,37 @@ export function PatternEditor({ />
+ + {/* Tool auto-approval defaults */} +
+

+ Tool Auto-Approval Defaults +

+ +

+ When tool-call approval is enabled, these tools will be auto-approved without manual review. + Sessions can override these defaults from the Activity panel. +

+ +
+ {approvalTools.length === 0 ? ( +

+ No tools available. Add MCP servers or LSP profiles in Settings to configure auto-approvals. +

+ ) : ( +
+ {approvalTools.map((tool) => ( + toggleToolAutoApproval(tool.id)} + tool={tool} + /> + ))} +
+ )} +
+
@@ -652,4 +706,38 @@ function ApprovalCheckpointRow({ )} ); +} + +/* ── Tool auto-approval toggle row ─────────────────────────── */ + +function ToolApprovalToggleRow({ + tool, + enabled, + onToggle, +}: { + tool: ApprovalToolDefinition; + enabled: boolean; + onToggle: () => void; +}) { + const kindBadge = tool.kind === 'lsp' ? 'LSP' : tool.kind === 'mcp' ? 'MCP' : 'Mixed'; + return ( + + ); } \ No newline at end of file diff --git a/src/renderer/components/SettingsPanel.tsx b/src/renderer/components/SettingsPanel.tsx index d9e4e37..83effda 100644 --- a/src/renderer/components/SettingsPanel.tsx +++ b/src/renderer/components/SettingsPanel.tsx @@ -132,6 +132,7 @@ export function SettingsPanel({ setEditingPattern(null); }} pattern={editingPattern} + toolingSettings={toolingSettings} /> );