Skip to content

The agent that grows with you

refactor(desktop): replace every window.confirm with the shared dialog

Brooklyn Nicholsona662d08f37ee
diff --git a/apps/desktop/DESIGN.md b/apps/desktop/DESIGN.md
index e2f3614022a..485073200d8 100644
--- a/apps/desktop/DESIGN.md
+++ b/apps/desktop/DESIGN.md
@@ -190,6 +190,15 @@ Notes:
- **Empty:** `EmptyState` for plain page bodies; `PanelEmpty` for overlay
master/detail empties with an icon and action. Don't hand-roll a third
centered empty.
+- **Confirmation:** `ConfirmDialog` is the only way we ask "are you sure". It
+ opens focused on Confirm, so `Enter` confirms and `Esc` cancels, and it owns
+ the pending → done → close beat and the inline error — a call site passes an
+ async `onConfirm` and nothing else. A third way out (e.g. "Remove from
+ sidebar" beside "Delete worktree") goes in the one `secondaryAction` slot.
+ Never `window.confirm`: it's an unstyled blocking Chromium modal. A handler
+ that wants the answer inline instead of a mounted dialog calls `confirm()`
+ from `src/store/confirm.ts`, which renders this same primitive through the
+ single `ConfirmHost` at the shell — the way `notify()` backs notifications.
## Chat, tools & boot surfaces
@@ -315,7 +324,8 @@ The detailed state contract lives in the scoped
## Before you add something — checklist
- [ ] Reuse a primitive (`Button`, `SearchField`, `SegmentedControl`,
- `ListRow`, `Loader`, `ErrorState`, `LogView`) instead of forking one?
+ `ListRow`, `Loader`, `ErrorState`, `LogView`, `ConfirmDialog`) instead of
+ forking one?
- [ ] Tokens (`--ui-*`, `shadow-nous`, `--stroke-nous`) — zero raw colors /
one-off shadows?
- [ ] No `className` overriding a primitive's padding / size / radius / chrome?
diff --git a/apps/desktop/src/app/chat/sidebar/cron-jobs-section.tsx b/apps/desktop/src/app/chat/sidebar/cron-jobs-section.tsx
index 8be72aba34b..9d4d54b9aff 100644
--- a/apps/desktop/src/app/chat/sidebar/cron-jobs-section.tsx
+++ b/apps/desktop/src/app/chat/sidebar/cron-jobs-section.tsx
@@ -13,6 +13,7 @@ import { deleteCronJob, getCronJobRuns, pauseCronJob, resumeCronJob, type Sessio
import { useI18n } from '@/i18n'
import { fmtDayTime, relativeTime } from '@/lib/time'
import { cn } from '@/lib/utils'
+import { confirm } from '@/store/confirm'
import { updateCronJobs } from '@/store/cron'
import { $changeEventsAvailable, $cronChangeTick } from '@/store/live-sync'
import { notify, notifyError } from '@/store/notifications'
@@ -259,7 +260,14 @@ function CronJobSidebarRow({
}
const remove = async () => {
- if (!window.confirm(`${c.deleteDescPrefix}${label}${c.deleteDescSuffix}`)) {
+ const ok = await confirm({
+ confirmLabel: t.common.delete,
+ description: `${c.deleteDescPrefix}${label}${c.deleteDescSuffix}`,
+ destructive: true,
+ title: c.deleteTitle
+ })
+
+ if (!ok) {
return
}
diff --git a/apps/desktop/src/app/command-center/maintenance.tsx b/apps/desktop/src/app/command-center/maintenance.tsx
index e8ee2f0e4e6..d603bfc7fdd 100644
--- a/apps/desktop/src/app/command-center/maintenance.tsx
+++ b/apps/desktop/src/app/command-center/maintenance.tsx
@@ -23,6 +23,7 @@ import { useI18n } from '@/i18n'
import { AlertCircle } from '@/lib/icons'
import { cn } from '@/lib/utils'
import { upsertDesktopActionTask } from '@/store/activity'
+import { confirm } from '@/store/confirm'
import { notify, notifyError } from '@/store/notifications'
import type { ActionStatusResponse } from '@/types/hermes'
@@ -169,7 +170,7 @@ export function MaintenancePanel() {
const doResetMemory = useCallback(
async (target: 'all' | 'memory' | 'user', label: string) => {
- if (!window.confirm(mm.resetConfirm(label))) {
+ if (!(await confirm({ destructive: true, title: mm.resetConfirm(label) }))) {
return
}
diff --git a/apps/desktop/src/app/settings/config-settings.tsx b/apps/desktop/src/app/settings/config-settings.tsx
index 77d501b7316..c44dd8b6a72 100644
--- a/apps/desktop/src/app/settings/config-settings.tsx
+++ b/apps/desktop/src/app/settings/config-settings.tsx
@@ -9,6 +9,7 @@ import { Input } from '@/components/ui/input'
import { getElevenLabsVoices, getHermesConfigSchema, saveHermesConfig } from '@/hermes'
import { useI18n } from '@/i18n'
import { triggerHaptic } from '@/lib/haptics'
+import { confirm } from '@/store/confirm'
import {
$dataUrlReadMaxMb,
clampDataUrlReadMaxMb,
@@ -213,19 +214,29 @@ function ConfigSettingsInner({
// eslint-disable-next-line react-hooks/exhaustive-deps -- copy is stable; avoid re-scheduling autosave on locale change
}, [config, onConfigSaved, saveVersion])
+ const applyConfig = (next: HermesConfigRecord) => {
+ saveVersionRef.current += 1
+ setConfig(next)
+ setSaveVersion(saveVersionRef.current)
+ }
+
const updateConfig = (next: HermesConfigRecord) => {
// Guard the single most destructive config edit: clearing the entire
// "Enabled Toolsets" list silently disables memory, terminal, web search,
// delegation, and most tools, and a stray select-all + Backspace can do it.
// Auto-save is debounced with no undo, so confirm a non-empty → empty
// transition before applying it. Every other edit passes through untouched.
- if (config && clearsEnabledToolsets(config, next) && !window.confirm(c.toolsetsWipeConfirm)) {
+ if (config && clearsEnabledToolsets(config, next)) {
+ void confirm({ destructive: true, title: c.toolsetsWipeConfirm }).then(ok => {
+ if (ok) {
+ applyConfig(next)
+ }
+ })
+
return
}
- saveVersionRef.current += 1
- setConfig(next)
- setSaveVersion(saveVersionRef.current)
+ applyConfig(next)
}
const sectionFields = useMemo(() => {
diff --git a/apps/desktop/src/app/settings/custom-endpoints-settings.tsx b/apps/desktop/src/app/settings/custom-endpoints-settings.tsx
index b74b30a2909..d78a4e0017e 100644
--- a/apps/desktop/src/app/settings/custom-endpoints-settings.tsx
+++ b/apps/desktop/src/app/settings/custom-endpoints-settings.tsx
@@ -13,6 +13,7 @@ import {
import { triggerHaptic } from '@/lib/haptics'
import { Check, Globe, Loader2, Plus, Save, Trash2, Zap } from '@/lib/icons'
import { cn } from '@/lib/utils'
+import { confirm } from '@/store/confirm'
import { notify, notifyError } from '@/store/notifications'
import type { CustomEndpoint, CustomEndpointUpdate } from '@/types/hermes'
@@ -195,7 +196,8 @@ export function CustomEndpointsSettings({ onConfigSaved, onMainModelChanged }: C
}
async function handleDelete(endpoint: CustomEndpoint) {
- if (!window.confirm(`Delete ${endpoint.name}?`)) {
+ // This panel is not internationalized at all — keep the literal it had.
+ if (!(await confirm({ destructive: true, title: `Delete ${endpoint.name}?` }))) {
return
}
diff --git a/apps/desktop/src/app/settings/env-credentials.tsx b/apps/desktop/src/app/settings/env-credentials.tsx
index 1a69d39a6db..0b4daf8e2c8 100644
--- a/apps/desktop/src/app/settings/env-credentials.tsx
+++ b/apps/desktop/src/app/settings/env-credentials.tsx
@@ -3,6 +3,7 @@ import { useEffect, useState } from 'react'
import { deleteEnvVar, getEnvVars, revealEnvVar, setEnvVar } from '@/hermes'
import { useI18n } from '@/i18n'
import { type IconComponent } from '@/lib/icons'
+import { confirm } from '@/store/confirm'
import { notify, notifyError } from '@/store/notifications'
import type { EnvVarInfo } from '@/types/hermes'
@@ -142,7 +143,7 @@ export function useEnvCredentials(profile: null | string = null): UseEnvCredenti
}
async function handleClear(key: string) {
- if (!window.confirm(toolsets.removeConfirm(key))) {
+ if (!(await confirm({ destructive: true, title: toolsets.removeConfirm(key) }))) {
return
}
diff --git a/apps/desktop/src/app/settings/index.tsx b/apps/desktop/src/app/settings/index.tsx
index dddfe741728..82cc8a01473 100644
--- a/apps/desktop/src/app/settings/index.tsx
+++ b/apps/desktop/src/app/settings/index.tsx
@@ -29,6 +29,7 @@ import { isEditableTarget } from '@/lib/keybinds/combo'
import { typeToFocusChar } from '@/lib/keybinds/composer-focus-keys'
import { cn } from '@/lib/utils'
import { $commandPaletteOpen, openCommandPalettePage } from '@/store/command-palette'
+import { confirm } from '@/store/confirm'
import { bindingsFor } from '@/store/keybinds'
import { notifyError } from '@/store/notifications'
@@ -147,7 +148,13 @@ export function SettingsView({ onClose, onConfigSaved, onMainModelChanged }: Set
}
const resetConfig = async () => {
- if (!window.confirm(t.settings.resetConfirm)) {
+ const ok = await confirm({
+ confirmLabel: t.settings.resetToDefaults,
+ destructive: true,
+ title: t.settings.resetConfirm
+ })
+
+ if (!ok) {
return
}
diff --git a/apps/desktop/src/app/settings/providers-settings.test.tsx b/apps/desktop/src/app/settings/providers-settings.test.tsx
index 0a1da7c4544..634158ff26c 100644
--- a/apps/desktop/src/app/settings/providers-settings.test.tsx
+++ b/apps/desktop/src/app/settings/providers-settings.test.tsx
@@ -2,6 +2,8 @@ import { act, cleanup, fireEvent, render, screen, waitFor } from '@testing-libra
import { atom } from 'nanostores'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
+import { ConfirmHost } from '@/components/confirm-host'
+import { $confirmRequest } from '@/store/confirm'
import type { EnvVarInfo, OAuthProvider } from '@/types/hermes'
const listOAuthProviders = vi.fn()
@@ -64,20 +66,27 @@ beforeEach(() => {
listOAuthProviders.mockResolvedValue({
providers: [provider('nous', true), provider('minimax-oauth', false)]
})
- vi.spyOn(window, 'confirm').mockReturnValue(true)
})
afterEach(() => {
cleanup()
+ $confirmRequest.set(null)
vi.restoreAllMocks()
vi.clearAllMocks()
})
+// Removal goes through confirm() from @/store/confirm, so the host has to be
+// mounted for the prompt to render — same as in the real app shell.
async function renderProvidersSettings() {
const { ProvidersSettings } = await import('./providers-settings')
let result: ReturnType<typeof render>
await act(async () => {
- result = render(<ProvidersSettings onClose={vi.fn()} onViewChange={vi.fn()} view="accounts" />)
+ result = render(
+ <>
+ <ProvidersSettings onClose={vi.fn()} onViewChange={vi.fn()} view="accounts" />
+ <ConfirmHost />
+ </>
+ )
})
return result!
@@ -92,10 +101,32 @@ describe('ProvidersSettings', () => {
fireEvent.click(remove)
})
+ // Removal is confirmed first — nothing has been disconnected yet.
+ expect(await screen.findByRole('dialog')).toBeTruthy()
+ expect(disconnectOAuthProvider).not.toHaveBeenCalled()
+
+ await act(async () => {
+ fireEvent.click(screen.getByRole('button', { name: 'Disconnect' }))
+ })
+
await waitFor(() => expect(disconnectOAuthProvider).toHaveBeenCalledWith('nous'))
expect(listOAuthProviders).toHaveBeenCalledTimes(2)
})
+ it('leaves the account connected when the removal prompt is dismissed', async () => {
+ await renderProvidersSettings()
+
+ await act(async () => {
+ fireEvent.click(await screen.findByRole('button', { name: 'Remove Nous Portal' }))
+ })
+
+ await act(async () => {
+ fireEvent.click(await screen.findByRole('button', { name: 'Cancel' }))
+ })
+
+ expect(disconnectOAuthProvider).not.toHaveBeenCalled()
+ })
+
it('keeps provider selection separate from account removal', async () => {
await renderProvidersSettings()
diff --git a/apps/desktop/src/app/settings/providers-settings.tsx b/apps/desktop/src/app/settings/providers-settings.tsx
index 9fb69784ec4..982b39b6ceb 100644
--- a/apps/desktop/src/app/settings/providers-settings.tsx
+++ b/apps/desktop/src/app/settings/providers-settings.tsx
@@ -20,6 +20,7 @@ import { useI18n } from '@/i18n'
import { Check, ChevronDown, ChevronRight, KeyRound, Loader2, Terminal, Trash2 } from '@/lib/icons'
import { normalize } from '@/lib/text'
import { cn } from '@/lib/utils'
+import { confirm } from '@/store/confirm'
import { notify, notifyError } from '@/store/notifications'
import { $desktopOnboarding, startManualLocalEndpoint, startManualProviderOAuth } from '@/store/onboarding'
import type { EnvVarInfo, OAuthProvider } from '@/types/hermes'
@@ -382,7 +383,7 @@ export function ProvidersSettings({
// Hermes never deletes creds another tool owns behind a silent API call.
// Instead we run the documented removal command in the embedded terminal so
// the user sees exactly what executes, then return them to chat to watch it.
- function handleTerminalDisconnect(provider: OAuthProvider) {
+ async function handleTerminalDisconnect(provider: OAuthProvider) {
const command = provider.disconnect_command
if (!command) {
@@ -391,7 +392,13 @@ export function ProvidersSettings({
const name = providerTitle(provider)
- if (!window.confirm(t.settings.providers.removeTerminalConfirm(name, command))) {
+ const ok = await confirm({
+ confirmLabel: t.settings.providers.disconnect,
+ destructive: true,
+ title: t.settings.providers.removeTerminalConfirm(name, command)
+ })
+
+ if (!ok) {
return
}
@@ -408,7 +415,13 @@ export function ProvidersSettings({
async function handleDisconnect(provider: OAuthProvider) {
const name = providerTitle(provider)
- if (!window.confirm(t.settings.providers.removeConfirm(name))) {
+ const ok = await confirm({
+ confirmLabel: t.settings.providers.disconnect,
+ destructive: true,
+ title: t.settings.providers.removeConfirm(name)
+ })
+
+ if (!ok) {
return
}
@@ -499,7 +512,7 @@ export function ProvidersSettings({
<OAuthPicker
disconnecting={disconnecting}
onDisconnect={provider => void handleDisconnect(provider)}
- onTerminalDisconnect={handleTerminalDisconnect}
+ onTerminalDisconnect={provider => void handleTerminalDisconnect(provider)}
onWantApiKey={() => onViewChange('keys')}
providers={oauthProviders}
/>
diff --git a/apps/desktop/src/app/settings/sessions-settings.tsx b/apps/desktop/src/app/settings/sessions-settings.tsx
index 6218bce7ead..e990557e7a4 100644
--- a/apps/desktop/src/app/settings/sessions-settings.tsx
+++ b/apps/desktop/src/app/settings/sessions-settings.tsx
@@ -15,6 +15,7 @@ import { sessionTitle } from '@/lib/chat-runtime'
import { pathLeaf } from '@/lib/display-path'
import { triggerHaptic } from '@/lib/haptics'
import { Archive, ArchiveOff, FolderOpen, Loader2, Trash2 } from '@/lib/icons'
+import { confirm } from '@/store/confirm'
import { notify, notifyError } from '@/store/notifications'
import { untombstoneSessions } from '@/store/projects'
import { applyConfiguredDefaultProjectDir, ensureDefaultWorkspaceCwd, setSessions } from '@/store/session'
@@ -76,7 +77,13 @@ export function SessionsSettings() {
const remove = useCallback(
async (session: SessionInfo) => {
- if (!window.confirm(s.deleteConfirm(sessionTitle(session)))) {
+ const ok = await confirm({
+ confirmLabel: s.deletePermanently,
+ destructive: true,
+ title: s.deleteConfirm(sessionTitle(session))
+ })
+
+ if (!ok) {
return
}
diff --git a/apps/desktop/src/app/settings/toolset-config-panel.tsx b/apps/desktop/src/app/settings/toolset-config-panel.tsx
index 0a1cff18540..8f5ae815404 100644
--- a/apps/desktop/src/app/settings/toolset-config-panel.tsx
+++ b/apps/desktop/src/app/settings/toolset-config-panel.tsx
@@ -22,6 +22,7 @@ import { useI18n } from '@/i18n'
import { Check, Loader2, Save, Terminal } from '@/lib/icons'
import { cn } from '@/lib/utils'
import { upsertDesktopActionTask } from '@/store/activity'
+import { confirm } from '@/store/confirm'
import { notify, notifyError } from '@/store/notifications'
import type {
ActionStatusResponse,
@@ -141,7 +142,7 @@ function EnvVarField({ envVar, isSet, onSaved, onCleared, profile }: EnvVarField
}
async function handleClear() {
- if (!window.confirm(copy.removeConfirm(envVar.key))) {
+ if (!(await confirm({ destructive: true, title: copy.removeConfirm(envVar.key) }))) {
return
}