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>
This commit is contained in:
David Kaya
2026-03-24 20:14:14 +01:00
co-authored by Copilot
parent d5c538eed9
commit 4b7409368f
5 changed files with 223 additions and 1 deletions
+7
View File
@@ -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}
+123 -1
View File
@@ -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({
)}
</div>
</div>
{/* ── Auto-approval overrides section ──────────────── */}
<div className="mb-4">
<SectionHeader>
<ShieldCheck className="size-3" />
<span>Auto-Approval</span>
{approvalDisabled && (
<span className="ml-auto text-[9px] font-medium normal-case tracking-normal text-zinc-600">
{projectIsScratchpad ? 'Scratchpad' : 'Running'}
</span>
)}
</SectionHeader>
<div className="rounded-lg border border-zinc-800 bg-zinc-900/40 px-3 py-2.5">
{projectIsScratchpad ? (
<p className="text-[11px] leading-relaxed text-zinc-600">
Tool auto-approval does not apply to scratchpad sessions.
</p>
) : approvalTools.length === 0 ? (
<p className="text-[11px] leading-relaxed text-zinc-600">
Add MCP servers or LSP profiles in Settings to configure tool auto-approvals.
</p>
) : (
<>
{/* Override state badge + reset action */}
<div className="mb-2 flex items-center gap-2">
<span className={`rounded-full px-2 py-0.5 text-[9px] font-semibold uppercase tracking-wider ${
isOverridden
? 'bg-amber-500/15 text-amber-400'
: 'bg-zinc-800 text-zinc-500'
}`}>
{isOverridden ? 'Custom for this session' : 'Inheriting pattern defaults'}
</span>
{isOverridden && (
<button
className="flex items-center gap-1 rounded-full px-2 py-0.5 text-[9px] font-medium text-zinc-500 transition hover:bg-zinc-800 hover:text-zinc-300 disabled:cursor-not-allowed disabled:opacity-50"
disabled={approvalDisabled}
onClick={() => onUpdateSessionApprovalSettings({})}
type="button"
>
<RotateCcw className="size-2.5" />
Reset to pattern
</button>
)}
</div>
<div className="space-y-0.5">
{approvalTools.map((tool) => (
<ApprovalOverrideRow
disabled={approvalDisabled}
enabled={effectiveAutoApproved.has(tool.id)}
key={tool.id}
onToggle={() => {
const next = new Set(effectiveAutoApproved);
if (next.has(tool.id)) {
next.delete(tool.id);
} else {
next.add(tool.id);
}
onUpdateSessionApprovalSettings({
autoApprovedToolNames: [...next],
});
}}
tool={tool}
/>
))}
</div>
</>
)}
</div>
</div>
</div>
</div>
);
@@ -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 (
<button
className={`flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left transition ${
disabled ? 'cursor-not-allowed opacity-50' : 'hover:bg-zinc-800/60'
}`}
disabled={disabled}
onClick={onToggle}
type="button"
>
<ShieldCheck className={`size-3 shrink-0 ${enabled ? 'text-indigo-400' : 'text-zinc-600'}`} />
<div className="min-w-0 flex-1">
<div className="flex items-center gap-1.5">
<span className="truncate text-[12px] font-medium text-zinc-300">{tool.label}</span>
<span className="shrink-0 rounded-full bg-zinc-800 px-1.5 py-0.5 text-[8px] font-semibold uppercase tracking-wider text-zinc-500">
{kindBadge}
</span>
</div>
</div>
<ToggleSwitch enabled={enabled} />
</button>
);
}
+4
View File
@@ -262,6 +262,7 @@ function ApprovalBanner({
{/* Agent / permission context */}
<div className="mt-1 flex flex-wrap items-center gap-2 text-[11px] text-zinc-400">
{approval.agentName && <span>Agent: <span className="text-zinc-300">{approval.agentName}</span></span>}
{approval.toolName && <span>Tool: <span className="text-zinc-300">{approval.toolName}</span></span>}
{approval.permissionKind && <span>Permission: <span className="text-zinc-300">{approval.permissionKind}</span></span>}
</div>
@@ -355,6 +356,9 @@ function QueuedApprovalsList({ approvals }: { approvals: PendingApprovalRecord[]
<span className="shrink-0 rounded-full bg-zinc-800 px-1.5 py-0.5 text-[8px] font-semibold uppercase tracking-wider text-zinc-500">
{kindLabel}
</span>
{approval.toolName && (
<span className="shrink-0 text-[10px] text-zinc-500">{approval.toolName}</span>
)}
{approval.agentName && (
<span className="shrink-0 text-[10px] text-zinc-600">{approval.agentName}</span>
)}
+88
View File
@@ -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<ModelDefinition>;
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 (
<div className="flex h-full flex-col">
{/* Header — consistent ← navigation */}
@@ -530,6 +553,37 @@ export function PatternEditor({
/>
</div>
</section>
{/* Tool auto-approval defaults */}
<section className="space-y-4">
<h4 className="text-[12px] font-semibold uppercase tracking-wider text-zinc-500">
Tool Auto-Approval Defaults
</h4>
<p className="text-[11px] leading-relaxed text-zinc-600">
When tool-call approval is enabled, these tools will be auto-approved without manual review.
Sessions can override these defaults from the Activity panel.
</p>
<div className="rounded-xl border border-zinc-800 bg-zinc-900/50 px-4 py-3">
{approvalTools.length === 0 ? (
<p className="py-2 text-center text-[11px] text-zinc-600">
No tools available. Add MCP servers or LSP profiles in Settings to configure auto-approvals.
</p>
) : (
<div className="space-y-0.5">
{approvalTools.map((tool) => (
<ToolApprovalToggleRow
enabled={autoApprovedSet.has(tool.id)}
key={tool.id}
onToggle={() => toggleToolAutoApproval(tool.id)}
tool={tool}
/>
))}
</div>
)}
</div>
</section>
</div>
</div>
</div>
@@ -652,4 +706,38 @@ function ApprovalCheckpointRow({
)}
</div>
);
}
/* ── 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 (
<button
className="flex w-full items-center gap-2.5 rounded-lg px-2 py-1.5 text-left transition hover:bg-zinc-800/60"
onClick={onToggle}
type="button"
>
<div className="min-w-0 flex-1">
<div className="flex items-center gap-2">
<span className="truncate text-[12px] font-medium text-zinc-300">{tool.label}</span>
<span className="shrink-0 rounded-full bg-zinc-800 px-1.5 py-0.5 text-[8px] font-semibold uppercase tracking-wider text-zinc-500">
{kindBadge}
</span>
</div>
{tool.providerNames.length > 0 && (
<div className="truncate text-[10px] text-zinc-600">{tool.providerNames.join(', ')}</div>
)}
</div>
<ToggleSwitch enabled={enabled} onToggle={onToggle} />
</button>
);
}
@@ -132,6 +132,7 @@ export function SettingsPanel({
setEditingPattern(null);
}}
pattern={editingPattern}
toolingSettings={toolingSettings}
/>
</div>
);