From a06a17b6ee5b7924b249cb653b255359e7e1bfc0 Mon Sep 17 00:00:00 2001 From: Kaylee <65376239+KayleeWilliams@users.noreply.github.com> Date: Tue, 30 Jun 2026 01:02:44 +0100 Subject: [PATCH] Improve toast layout and dev tools (#6782) Restyle shared Sonner toasts (wrapping, bottom-chrome clearance with mobileOffset, custom delete-failure footer) and add a dev-only Dev Tools settings pane gated behind import.meta.env.DEV. Removes dead devToolsSearch locale keys, aligns toast description opacity/width with sibling toasts, and uses a distinct nav icon for Dev Tools. --- src/renderer/src/assets/main.css | 46 ++++ .../src/components/settings/DevToolsPane.tsx | 248 ++++++++++++++++++ .../src/components/settings/Settings.tsx | 33 ++- .../delete-worktree-failure-toast.test.tsx | 119 +++++++++ .../sidebar/delete-worktree-failure-toast.tsx | 88 +++++++ .../sidebar/delete-worktree-flow.test.ts | 14 +- .../sidebar/delete-worktree-flow.ts | 121 ++++----- .../local-base-ref-suggestion-toast.tsx | 5 +- src/renderer/src/components/ui/sonner.tsx | 10 +- .../useSettingsNavigationMetadata.test.ts | 16 +- .../hooks/useSettingsNavigationMetadata.ts | 49 ++++ src/renderer/src/i18n/locales/en.json | 46 +++- src/renderer/src/i18n/locales/es.json | 46 +++- src/renderer/src/i18n/locales/ja.json | 46 +++- src/renderer/src/i18n/locales/ko.json | 46 +++- src/renderer/src/i18n/locales/zh.json | 46 +++- .../src/lib/settings-navigation-types.ts | 1 + 17 files changed, 893 insertions(+), 87 deletions(-) create mode 100644 src/renderer/src/components/settings/DevToolsPane.tsx create mode 100644 src/renderer/src/components/sidebar/delete-worktree-failure-toast.test.tsx create mode 100644 src/renderer/src/components/sidebar/delete-worktree-failure-toast.tsx diff --git a/src/renderer/src/assets/main.css b/src/renderer/src/assets/main.css index 2a9bde599..c26cd144a 100644 --- a/src/renderer/src/assets/main.css +++ b/src/renderer/src/assets/main.css @@ -295,6 +295,52 @@ --linear-priority-bar-inactive-fill: color-mix(in srgb, lch(39.576 1.25 282) 62%, transparent); } +[data-sonner-toaster] { + font-family: var(--font-sans); +} + +[data-sonner-toaster] [data-sonner-toast][data-styled='true'] { + align-items: flex-start; + flex-wrap: wrap; + gap: 10px; + padding: 14px 16px; + box-shadow: 0 10px 24px rgb(0 0 0 / 0.18); +} + +[data-sonner-toaster] [data-sonner-toast][data-styled='true'] [data-icon] { + margin-top: 2px; +} + +[data-sonner-toaster] [data-sonner-toast][data-styled='true'] [data-content] { + min-width: 0; + flex: 1 1 calc(100% - 30px); + gap: 6px; +} + +[data-sonner-toaster] [data-sonner-toast][data-styled='true'] [data-button] { + /* Why: Sonner's native action slots otherwise share the copy row and squeeze + long notices; indent the wrapped footer to align with text after the icon. */ + margin-top: 2px; + margin-left: 26px; + margin-right: 0; +} + +[data-sonner-toaster] [data-sonner-toast][data-styled='true'] [data-button] ~ [data-button] { + margin-left: 0; +} + +[data-sonner-toaster] [data-sonner-toast][data-styled='true'] [data-title] { + line-height: 1.35; +} + +[data-sonner-toaster] [data-sonner-toast][data-styled='true'] [data-description] { + /* Why: match the 80% body-copy opacity used by the custom-React toast bodies + (delete-worktree-failure, local-base-ref-suggestion) so string and JSX + descriptions read at the same weight. */ + color: color-mix(in srgb, var(--popover-foreground) 80%, transparent); + line-height: 1.45; +} + [data-sonner-toaster] [data-sonner-toast][data-styled='true'] [data-close-button] { /* Why: Sonner's dark-theme defaults can resolve the close icon and button background to the same color; keep the X readable on both Orca themes. */ diff --git a/src/renderer/src/components/settings/DevToolsPane.tsx b/src/renderer/src/components/settings/DevToolsPane.tsx new file mode 100644 index 000000000..f22b5823e --- /dev/null +++ b/src/renderer/src/components/settings/DevToolsPane.tsx @@ -0,0 +1,248 @@ +import { toast } from 'sonner' +import { Bell, Info, OctagonX, Sparkles, Trash2 } from 'lucide-react' +import { Button } from '../ui/button' +import { Badge } from '../ui/badge' +import { SettingsSubsectionHeader } from './SettingsFormControls' +import { showDeleteWorktreeFailureToast } from '../sidebar/delete-worktree-failure-toast' +import { showLocalBaseRefUpdateSuggestionToast } from '../sidebar/local-base-ref-suggestion-toast' +import { translate } from '@/i18n/i18n' +import type { AppState } from '@/store/types' + +const LONG_WORKSPACE_NAME = 'feature/dev-toast-layout-with-a-long-workspace-name' +const DEV_TOAST_DESCRIPTION = + 'This is intentionally long copy for checking width, line wrapping, icon alignment, action placement, and close-button overlap in the shared toast frame.' + +type DevToastAction = { + title: string + description: string + icon: React.ReactNode + onClick: () => void +} + +function DevToastActionButton({ action }: { action: DevToastAction }): React.JSX.Element { + return ( + + ) +} + +function showNativeActionToast(): void { + toast.info( + translate( + 'auto.components.settings.DevToolsPane.nativeActionLayoutCheck', + 'Native action layout check' + ), + { + description: DEV_TOAST_DESCRIPTION, + duration: 10000, + cancel: { + label: translate('auto.components.settings.DevToolsPane.secondary', 'Secondary'), + onClick: () => + toast.message( + translate( + 'auto.components.settings.DevToolsPane.secondaryActionClicked', + 'Secondary action clicked' + ) + ) + }, + action: { + label: translate('auto.components.settings.DevToolsPane.primaryAction', 'Primary action'), + onClick: () => + toast.success( + translate( + 'auto.components.settings.DevToolsPane.primaryActionClicked', + 'Primary action clicked' + ) + ) + } + } + ) +} + +function showBehindBaseRefToast(): void { + let enabled = false + showLocalBaseRefUpdateSuggestionToast( + { + baseRef: 'origin/canary', + localBranch: 'canary', + behind: 2 + }, + { + updateSettings: async (updates) => { + enabled = updates.refreshLocalBaseRefOnWorktreeCreate === true + }, + getSettings: () => + ({ + refreshLocalBaseRefOnWorktreeCreate: enabled + }) as AppState['settings'], + openSettingsPage: () => {}, + openSettingsTarget: () => {} + } + ) +} + +function showDeleteFailureToast(): void { + showDeleteWorktreeFailureToast({ + error: translate( + 'auto.components.settings.DevToolsPane.branchHasChanges', + 'branch has changes' + ), + canForceDelete: true, + onViewChanges: () => + toast.message( + translate( + 'auto.components.settings.DevToolsPane.viewChangesClicked', + 'View Changes clicked' + ) + ), + onForceDelete: () => + toast.error( + translate( + 'auto.components.settings.DevToolsPane.forceDeleteClicked', + 'Force Delete clicked' + ), + { + description: translate( + 'auto.components.settings.DevToolsPane.devOnlyCallback', + 'Dev-only callback.' + ) + } + ), + worktreeId: 'dev-toast-worktree', + worktreeName: LONG_WORKSPACE_NAME + }) +} + +export function DevToolsPane(): React.JSX.Element { + const actions: DevToastAction[] = [ + { + title: translate('auto.components.settings.DevToolsPane.infoToast', 'Info toast'), + description: translate( + 'auto.components.settings.DevToolsPane.infoToastDescription', + 'Long informational copy with no explicit action.' + ), + icon: , + onClick: () => + toast.info( + translate( + 'auto.components.settings.DevToolsPane.localCanaryBehind', + 'Local canary is behind origin/canary' + ), + { + description: DEV_TOAST_DESCRIPTION, + duration: 10000 + } + ) + }, + { + title: translate('auto.components.settings.DevToolsPane.successToast', 'Success toast'), + description: translate( + 'auto.components.settings.DevToolsPane.successToastDescription', + 'Short confirmation state.' + ), + icon: , + onClick: () => + toast.success( + translate('auto.components.settings.DevToolsPane.settingsSaved', 'Settings saved'), + { + description: translate( + 'auto.components.settings.DevToolsPane.shortSuccessCopy', + 'Short success copy.' + ) + } + ) + }, + { + title: translate('auto.components.settings.DevToolsPane.errorToast', 'Error toast'), + description: translate( + 'auto.components.settings.DevToolsPane.errorToastDescription', + 'Long error copy without recovery actions.' + ), + icon: , + onClick: () => + toast.error( + translate( + 'auto.components.settings.DevToolsPane.failedToSyncWorkspaceMetadata', + 'Failed to sync workspace metadata' + ), + { + description: DEV_TOAST_DESCRIPTION, + duration: 10000 + } + ) + }, + { + title: translate( + 'auto.components.settings.DevToolsPane.nativeActionToast', + 'Native action toast' + ), + description: translate( + 'auto.components.settings.DevToolsPane.nativeActionToastDescription', + 'Uses Sonner action and cancel slots.' + ), + icon: , + onClick: showNativeActionToast + }, + { + title: translate( + 'auto.components.settings.DevToolsPane.deleteFailureToast', + 'Delete failure toast' + ), + description: translate( + 'auto.components.settings.DevToolsPane.deleteFailureToastDescription', + 'Custom footer with View and Force Delete.' + ), + icon: , + onClick: showDeleteFailureToast + }, + { + title: translate( + 'auto.components.settings.DevToolsPane.behindBaseRefToast', + 'Behind base ref toast' + ), + description: translate( + 'auto.components.settings.DevToolsPane.behindBaseRefToastDescription', + 'Persistent prompt with an inline Settings link and footer action.' + ), + icon: , + onClick: showBehindBaseRefToast + } + ] + + return ( +
+
+ + + {translate('auto.components.settings.DevToolsPane.devOnly', 'Dev only')} + +
+ +
+ {actions.map((action) => ( + + ))} +
+
+ ) +} diff --git a/src/renderer/src/components/settings/Settings.tsx b/src/renderer/src/components/settings/Settings.tsx index de80f3ed5..92c4a35b2 100644 --- a/src/renderer/src/components/settings/Settings.tsx +++ b/src/renderer/src/components/settings/Settings.tsx @@ -1,5 +1,14 @@ /* eslint-disable max-lines */ -import { useCallback, useEffect, useMemo, useRef, useState, type MutableRefObject } from 'react' +import { + lazy, + Suspense, + useCallback, + useEffect, + useMemo, + useRef, + useState, + type MutableRefObject +} from 'react' import { toast } from 'sonner' import type { GlobalSettings, OrcaHooks } from '../../../../shared/types' import type { SpeechModelState } from '../../../../shared/speech-types' @@ -91,6 +100,10 @@ import { import { translate } from '@/i18n/i18n' import { getProjectHostSetupProjectionFromState } from '../../store/selectors' +const DevToolsPane = import.meta.env.DEV + ? lazy(() => import('./DevToolsPane').then((module) => ({ default: module.DevToolsPane }))) + : null + const SETTINGS_NAV_GROUPS = [ { id: 'capabilities', @@ -1564,6 +1577,24 @@ function Settings(): React.JSX.Element { ) : null} + {showDesktopOnlySettings && import.meta.env.DEV ? ( + + {DevToolsPane && isSectionMounted('dev') ? ( + + + + ) : null} + + ) : null} + ({ + toast: { + error: vi.fn(), + info: vi.fn(), + dismiss: vi.fn() + } +})) + +const mountedRoots: Root[] = [] + +function renderToastBody(method: 'error' | 'info'): HTMLElement { + const description = vi.mocked(toast[method]).mock.calls.at(-1)?.[1] + ?.description as React.ReactElement + const container = document.createElement('div') + document.body.appendChild(container) + const root = createRoot(container) + mountedRoots.push(root) + act(() => { + root.render(description) + }) + return container +} + +function clickButton(container: HTMLElement, label: string): void { + const button = [...container.querySelectorAll('button')].find( + (el) => el.textContent?.trim() === label + ) + if (!button) { + throw new Error(`button "${label}" not found`) + } + act(() => { + button.dispatchEvent(new MouseEvent('click', { bubbles: true })) + }) +} + +afterEach(() => { + mountedRoots.splice(0).forEach((root) => act(() => root.unmount())) + document.body.innerHTML = '' + vi.clearAllMocks() +}) + +describe('showDeleteWorktreeFailureToast', () => { + it('uses a persistent in-body action footer when force delete is available', () => { + const onViewChanges = vi.fn() + const onForceDelete = vi.fn() + + showDeleteWorktreeFailureToast({ + error: 'branch has changes', + canForceDelete: true, + onViewChanges, + onForceDelete, + worktreeId: 'wt-1', + worktreeName: 'feature/foo' + }) + + expect(toast.info).toHaveBeenCalledWith( + 'Failed to delete workspace feature/foo', + expect.objectContaining({ + id: 'delete-worktree-failure:wt-1', + dismissible: true, + duration: Infinity + }) + ) + const options = vi.mocked(toast.info).mock.calls.at(-1)?.[1] as + | { action?: unknown; cancel?: unknown } + | undefined + expect(options?.action).toBeUndefined() + expect(options?.cancel).toBeUndefined() + + const body = renderToastBody('info') + expect(body.textContent).toContain('It has changed files.') + + clickButton(body, 'View') + expect(toast.dismiss).toHaveBeenCalledWith('delete-worktree-failure:wt-1') + expect(onViewChanges).toHaveBeenCalled() + + clickButton(body, 'Force Delete') + expect(toast.dismiss).toHaveBeenCalledWith('delete-worktree-failure:wt-1') + expect(onForceDelete).toHaveBeenCalled() + }) + + it('keeps non-forceable failures destructive without a force action', () => { + const onViewChanges = vi.fn() + + showDeleteWorktreeFailureToast({ + error: 'permission denied', + canForceDelete: false, + onViewChanges, + onForceDelete: vi.fn(), + worktreeId: 'wt-2', + worktreeName: 'feature/bar' + }) + + expect(toast.error).toHaveBeenCalledWith( + 'Failed to delete workspace feature/bar', + expect.objectContaining({ + id: 'delete-worktree-failure:wt-2', + dismissible: true, + duration: 10000 + }) + ) + + const body = renderToastBody('error') + expect(body.textContent).toContain('permission denied') + expect(body.textContent).not.toContain('Force Delete') + + clickButton(body, 'View') + expect(toast.dismiss).toHaveBeenCalledWith('delete-worktree-failure:wt-2') + expect(onViewChanges).toHaveBeenCalled() + }) +}) diff --git a/src/renderer/src/components/sidebar/delete-worktree-failure-toast.tsx b/src/renderer/src/components/sidebar/delete-worktree-failure-toast.tsx new file mode 100644 index 000000000..ab073fe13 --- /dev/null +++ b/src/renderer/src/components/sidebar/delete-worktree-failure-toast.tsx @@ -0,0 +1,88 @@ +import { toast } from 'sonner' +import { Button } from '../ui/button' +import { getDeleteWorktreeToastCopy } from './delete-worktree-toast' +import { translate } from '@/i18n/i18n' + +type DeleteWorktreeFailureToastOptions = { + error: string + canForceDelete: boolean + onViewChanges: () => void + onForceDelete: () => void + worktreeId: string + worktreeName: string +} + +function deleteWorktreeFailureToastId(worktreeId: string): string { + return `delete-worktree-failure:${worktreeId}` +} + +function DeleteWorktreeFailureToastBody({ + description, + canForceDelete, + onViewChanges, + onForceDelete, + toastId +}: { + description?: string + canForceDelete: boolean + onViewChanges: () => void + onForceDelete: () => void + toastId: string +}): React.JSX.Element { + const viewChanges = (): void => { + toast.dismiss(toastId) + onViewChanges() + } + const forceDelete = (): void => { + toast.dismiss(toastId) + onForceDelete() + } + + return ( +
+ {description ? ( +

{description}

+ ) : null} +
+ + {canForceDelete ? ( + + ) : null} +
+
+ ) +} + +export function showDeleteWorktreeFailureToast({ + error, + canForceDelete, + onViewChanges, + onForceDelete, + worktreeId, + worktreeName +}: DeleteWorktreeFailureToastOptions): void { + const toastCopy = getDeleteWorktreeToastCopy(worktreeName, canForceDelete, error) + const showToast = toastCopy.isDestructive ? toast.error : toast.info + const id = deleteWorktreeFailureToastId(worktreeId) + + // Why: Sonner's native action/cancel slots share the title row and squeeze + // multi-line delete errors. Custom content gives the copy its own line. + showToast(toastCopy.title, { + id, + description: ( + + ), + duration: canForceDelete ? Infinity : 10000, + dismissible: true + }) +} diff --git a/src/renderer/src/components/sidebar/delete-worktree-flow.test.ts b/src/renderer/src/components/sidebar/delete-worktree-flow.test.ts index aba39b5f8..337140731 100644 --- a/src/renderer/src/components/sidebar/delete-worktree-flow.test.ts +++ b/src/renderer/src/components/sidebar/delete-worktree-flow.test.ts @@ -60,7 +60,12 @@ vi.mock('sonner', () => ({ } })) +vi.mock('./delete-worktree-failure-toast', () => ({ + showDeleteWorktreeFailureToast: vi.fn() +})) + import { toast } from 'sonner' +import { showDeleteWorktreeFailureToast } from './delete-worktree-failure-toast' import { runWorktreeBatchDelete, runWorktreeDelete } from './delete-worktree-flow' function setWorktrees( @@ -100,6 +105,7 @@ describe('runWorktreeBatchDelete', () => { mocks.state.repos = [] vi.mocked(toast.error).mockClear() vi.mocked(toast.info).mockClear() + vi.mocked(showDeleteWorktreeFailureToast).mockClear() setWorktrees([]) }) @@ -178,11 +184,9 @@ describe('runWorktreeBatchDelete', () => { expect(runWorktreeBatchDelete(['wt-1'], { onDeleted })).toBe(true) - await vi.waitFor(() => expect(toast.info).toHaveBeenCalled()) - const toastOptions = vi.mocked(toast.info).mock.calls[0]?.[1] as - | { action?: { onClick?: () => void } } - | undefined - toastOptions?.action?.onClick?.() + await vi.waitFor(() => expect(showDeleteWorktreeFailureToast).toHaveBeenCalled()) + const toastOptions = vi.mocked(showDeleteWorktreeFailureToast).mock.calls[0]?.[0] + toastOptions?.onForceDelete() await vi.waitFor(() => { expect(mocks.state.removeWorktree).toHaveBeenNthCalledWith(2, 'wt-1', true) diff --git a/src/renderer/src/components/sidebar/delete-worktree-flow.ts b/src/renderer/src/components/sidebar/delete-worktree-flow.ts index ae9d61216..dc81f9a22 100644 --- a/src/renderer/src/components/sidebar/delete-worktree-flow.ts +++ b/src/renderer/src/components/sidebar/delete-worktree-flow.ts @@ -3,7 +3,7 @@ import { useAppStore } from '@/store' import { getWorktreeMapFromState } from '@/store/selectors' import { activateAndRevealWorktree } from '@/lib/worktree-activation' import { prepareActiveWorktreeFocusAfterDelete } from './active-worktree-focus-after-delete' -import { getDeleteWorktreeToastCopy } from './delete-worktree-toast' +import { showDeleteWorktreeFailureToast } from './delete-worktree-failure-toast' import { getWorkspaceDeleteLineage } from './workspace-delete-lineage' import { isPathInsideOrEqual, @@ -145,73 +145,62 @@ export function runWorktreeDeleteWithToast( } const state = useAppStore.getState().deleteStateByWorktreeId[worktreeId] const canForceDelete = state?.canForceDelete ?? false - const toastCopy = getDeleteWorktreeToastCopy(worktreeName, canForceDelete, result.error) - const showToast = toastCopy.isDestructive ? toast.error : toast.info - showToast(toastCopy.title, { - description: toastCopy.description, - duration: 10000, - cancel: { - label: translate('auto.components.sidebar.delete.worktree.flow.7488ed8711', 'View'), - onClick: () => viewWorktreeDiff(worktreeId) - }, - action: canForceDelete - ? { - label: translate( - 'auto.components.sidebar.delete.worktree.flow.2b20ce87b3', - 'Force Delete' - ), - onClick: () => { - // Why: recapture at click time — the user may have navigated away - // while the failed-delete toast was open, so focus only hands off - // when this is still the workspace they are viewing. - const commitForceFocus = prepareActiveWorktreeFocusAfterDelete(worktreeId) - useAppStore - .getState() - .removeWorktree(worktreeId, true) - .then((forceResult) => { - if (!forceResult.ok) { - toast.error( - translate( - 'auto.components.sidebar.delete.worktree.flow.4f3876c0f5', - 'Force delete failed' - ), - { - description: forceResult.error, - action: { - label: translate( - 'auto.components.sidebar.delete.worktree.flow.7488ed8711', - 'View' - ), - onClick: () => viewWorktreeDiff(worktreeId) - } - } - ) - return - } - commitForceFocus() - options.onForceDeleted?.(worktreeId) - }) - .catch((err: unknown) => { - toast.error( - translate( - 'auto.components.sidebar.delete.worktree.flow.ae57cbf6e4', - 'Failed to delete workspace' + showDeleteWorktreeFailureToast({ + error: result.error, + canForceDelete, + onViewChanges: () => viewWorktreeDiff(worktreeId), + onForceDelete: () => { + // Why: recapture at click time — the user may have navigated away + // while the failed-delete toast was open, so focus only hands off + // when this is still the workspace they are viewing. + const commitForceFocus = prepareActiveWorktreeFocusAfterDelete(worktreeId) + useAppStore + .getState() + .removeWorktree(worktreeId, true) + .then((forceResult) => { + if (!forceResult.ok) { + toast.error( + translate( + 'auto.components.sidebar.delete.worktree.flow.4f3876c0f5', + 'Force delete failed' + ), + { + description: forceResult.error, + action: { + label: translate( + 'auto.components.sidebar.delete.worktree.flow.7488ed8711', + 'View' ), - { - description: err instanceof Error ? err.message : String(err), - action: { - label: translate( - 'auto.components.sidebar.delete.worktree.flow.7488ed8711', - 'View' - ), - onClick: () => viewWorktreeDiff(worktreeId) - } - } - ) - }) + onClick: () => viewWorktreeDiff(worktreeId) + } + } + ) + return } - } - : undefined + commitForceFocus() + options.onForceDeleted?.(worktreeId) + }) + .catch((err: unknown) => { + toast.error( + translate( + 'auto.components.sidebar.delete.worktree.flow.ae57cbf6e4', + 'Failed to delete workspace' + ), + { + description: err instanceof Error ? err.message : String(err), + action: { + label: translate( + 'auto.components.sidebar.delete.worktree.flow.7488ed8711', + 'View' + ), + onClick: () => viewWorktreeDiff(worktreeId) + } + } + ) + }) + }, + worktreeId, + worktreeName }) return false }) diff --git a/src/renderer/src/components/sidebar/local-base-ref-suggestion-toast.tsx b/src/renderer/src/components/sidebar/local-base-ref-suggestion-toast.tsx index 1396c4875..97bd71e19 100644 --- a/src/renderer/src/components/sidebar/local-base-ref-suggestion-toast.tsx +++ b/src/renderer/src/components/sidebar/local-base-ref-suggestion-toast.tsx @@ -87,8 +87,8 @@ function SuggestionToastBody({ } return ( -
-

+

+

{translate( 'auto.components.sidebar.local.base.ref.suggestion.toast.f15fd80989', 'Your new worktree is current, but local {{value0}} is {{value1}} {{value2}} behind, so AI diffs may compare to stale history. Let Orca keep it up to date automatically. Change this anytime in', @@ -109,7 +109,6 @@ function SuggestionToastBody({ { value0: keepLocalMainUpToDateTitle } )} - .

{/* No explicit Dismiss: the toast is persistent and sonner's close (X) diff --git a/src/renderer/src/components/ui/sonner.tsx b/src/renderer/src/components/ui/sonner.tsx index 33b6a678d..3096b4882 100644 --- a/src/renderer/src/components/ui/sonner.tsx +++ b/src/renderer/src/components/ui/sonner.tsx @@ -15,6 +15,13 @@ const Toaster = ({ ...props }: ToasterProps) => { , @@ -28,7 +35,8 @@ const Toaster = ({ ...props }: ToasterProps) => { '--normal-bg': 'var(--popover)', '--normal-text': 'var(--popover-foreground)', '--normal-border': 'var(--border)', - '--border-radius': 'var(--radius)' + '--border-radius': 'var(--radius)', + '--width': 'min(26rem, calc(100vw - 2rem))' } as React.CSSProperties } {...props} diff --git a/src/renderer/src/hooks/useSettingsNavigationMetadata.test.ts b/src/renderer/src/hooks/useSettingsNavigationMetadata.test.ts index 5b6b3c201..c59a9857b 100644 --- a/src/renderer/src/hooks/useSettingsNavigationMetadata.test.ts +++ b/src/renderer/src/hooks/useSettingsNavigationMetadata.test.ts @@ -13,11 +13,14 @@ const repo = { addedAt: 0 } satisfies Repo -function ids(args: { isMac?: boolean; isWindows?: boolean; isWebClient?: boolean } = {}): string[] { +function ids( + args: { isMac?: boolean; isWindows?: boolean; isWebClient?: boolean; isDev?: boolean } = {} +): string[] { return buildSettingsNavigationMetadata({ isMac: args.isMac ?? false, isWindows: args.isWindows ?? false, isWebClient: args.isWebClient ?? false, + isDev: args.isDev ?? false, repos: [repo] }).map((section) => section.id) } @@ -149,6 +152,17 @@ describe('settings navigation metadata', () => { expect(desktopIds.indexOf('privacy')).toBeLessThan(desktopIds.indexOf('advanced')) }) + // Note: this exercises the isDev parameter and isWebClient branches only. + // Production safety rests on the hard `import.meta.env.DEV` term in the + // builder, which is compile-time-inlined per build and cannot be flipped from + // a test (vitest always runs with DEV=true) — don't mistake this for full + // prod-gate coverage. The bundle exclusion is what guarantees prod safety. + it('shows Dev tools only in desktop development metadata', () => { + expect(ids()).not.toContain('dev') + expect(ids({ isDev: true })).toContain('dev') + expect(ids({ isDev: true, isWebClient: true })).not.toContain('dev') + }) + it('keeps macOS permissions mac-only', () => { expect(ids({ isMac: false })).not.toContain('developer-permissions') expect(ids({ isMac: true })).toContain('developer-permissions') diff --git a/src/renderer/src/hooks/useSettingsNavigationMetadata.ts b/src/renderer/src/hooks/useSettingsNavigationMetadata.ts index a07d8162c..a53e95202 100644 --- a/src/renderer/src/hooks/useSettingsNavigationMetadata.ts +++ b/src/renderer/src/hooks/useSettingsNavigationMetadata.ts @@ -9,6 +9,7 @@ import { Bell, Blocks, Bot, + Bug, Cable, FlaskConical, GitBranch, @@ -80,17 +81,44 @@ import { translate } from '@/i18n/i18n' export { isWebClientLocation } from '@/lib/web-client-location' +function getDevToolsPaneSearchEntries(): SettingsNavSection['searchEntries'] { + return [ + { + title: translate( + 'auto.hooks.useSettingsNavigationMetadata.devSearchNotificationPlayground', + 'Notification playground' + ), + description: translate( + 'auto.hooks.useSettingsNavigationMetadata.devSearchNotificationPlaygroundDescription', + 'Trigger representative toast and notification UI states.' + ), + keywords: [ + translate('auto.hooks.useSettingsNavigationMetadata.devSearchKeywordDev', 'dev'), + translate('auto.hooks.useSettingsNavigationMetadata.devSearchKeywordToast', 'toast'), + translate('auto.hooks.useSettingsNavigationMetadata.devSearchKeywordSonner', 'sonner'), + translate('auto.hooks.useSettingsNavigationMetadata.devSearchKeywordError', 'error'), + translate( + 'auto.hooks.useSettingsNavigationMetadata.devSearchKeywordNotification', + 'notification' + ) + ] + } + ] +} + export function buildSettingsNavigationMetadata({ isMac, isWindows, isWindowsTerminalHost = isWindows, isWebClient, + isDev = import.meta.env.DEV, repos }: { isMac: boolean isWindows: boolean isWindowsTerminalHost?: boolean isWebClient: boolean + isDev?: boolean repos: readonly Repo[] }): SettingsNavSection[] { const showDesktopOnlySettings = !isWebClient @@ -478,6 +506,26 @@ export function buildSettingsNavigationMetadata({ } ] : []), + // Why: dev tooling must not be reachable from packaged/web builds even if + // this pure metadata builder is called manually with isDev=true. + ...(showDesktopOnlySettings && import.meta.env.DEV && isDev + ? [ + { + id: 'dev', + title: translate('auto.hooks.useSettingsNavigationMetadata.dev', 'Dev Tools'), + description: translate( + 'auto.hooks.useSettingsNavigationMetadata.devDescription', + 'Dev-only tools for exercising UI states.' + ), + // Why: distinct from the sibling Advanced section's Wrench so the two + // entries in the same 'advanced' group stay visually distinguishable. + icon: Bug, + searchEntries: getDevToolsPaneSearchEntries(), + group: 'advanced', + badge: translate('auto.hooks.useSettingsNavigationMetadata.devBadge', 'Dev') + } + ] + : []), { id: 'experimental', title: translate('auto.hooks.useSettingsNavigationMetadata.225071c560', 'Experimental'), @@ -533,6 +581,7 @@ export function useSettingsNavigationMetadata(): SettingsNavSection[] { isWindows, isWindowsTerminalHost, isWebClient, + isDev: import.meta.env.DEV, repos }), [isMac, isWindows, isWindowsTerminalHost, isWebClient, repos] diff --git a/src/renderer/src/i18n/locales/en.json b/src/renderer/src/i18n/locales/en.json index f844973eb..fb5db079a 100644 --- a/src/renderer/src/i18n/locales/en.json +++ b/src/renderer/src/i18n/locales/en.json @@ -638,7 +638,17 @@ "b1c2f8b0ac": "Optional account switching for Claude, Codex, Gemini, and OpenCode Go.", "f70ac54d38": "AI Provider Accounts", "4121f7a0a2": "Manage AI agents, set a default, and customize commands.", - "b49abbd2f7": "Agents" + "b49abbd2f7": "Agents", + "dev": "Dev Tools", + "devDescription": "Dev-only tools for exercising UI states.", + "devBadge": "Dev", + "devSearchNotificationPlayground": "Notification playground", + "devSearchNotificationPlaygroundDescription": "Trigger representative toast and notification UI states.", + "devSearchKeywordDev": "dev", + "devSearchKeywordToast": "toast", + "devSearchKeywordSonner": "sonner", + "devSearchKeywordError": "error", + "devSearchKeywordNotification": "notification" }, "useAppMenuPaste": { "pasteTooLarge": "Paste is too large." @@ -6084,7 +6094,9 @@ "9abb9be3bc": "Set Up", "23c6874fdf": "AI Capabilities", "2309068a6f": "destructive", - "65358016ea": "Discard" + "65358016ea": "Discard", + "dev": "Dev Tools", + "devDescription": "Dev-only tools for exercising UI states." }, "SettingsFormControls": { "42a4d15a30": "No matching fonts.", @@ -8512,6 +8524,36 @@ }, "AppearanceAdvancedDisclosure": { "advanced": "Advanced" + }, + "DevToolsPane": { + "nativeActionLayoutCheck": "Native action layout check", + "secondary": "Secondary", + "secondaryActionClicked": "Secondary action clicked", + "primaryAction": "Primary action", + "primaryActionClicked": "Primary action clicked", + "branchHasChanges": "branch has changes", + "viewChangesClicked": "View Changes clicked", + "forceDeleteClicked": "Force Delete clicked", + "devOnlyCallback": "Dev-only callback.", + "infoToast": "Info toast", + "infoToastDescription": "Long informational copy with no explicit action.", + "localCanaryBehind": "Local canary is behind origin/canary", + "successToast": "Success toast", + "successToastDescription": "Short confirmation state.", + "settingsSaved": "Settings saved", + "shortSuccessCopy": "Short success copy.", + "errorToast": "Error toast", + "errorToastDescription": "Long error copy without recovery actions.", + "failedToSyncWorkspaceMetadata": "Failed to sync workspace metadata", + "nativeActionToast": "Native action toast", + "nativeActionToastDescription": "Uses Sonner action and cancel slots.", + "deleteFailureToast": "Delete failure toast", + "deleteFailureToastDescription": "Custom footer with View and Force Delete.", + "behindBaseRefToast": "Behind base ref toast", + "behindBaseRefToastDescription": "Persistent prompt with an inline Settings link and footer action.", + "notificationPlayground": "Notification playground", + "notificationPlaygroundDescription": "Dev-only triggers for checking toast layout, recovery actions, and long-copy wrapping.", + "devOnly": "Dev only" } }, "right": { diff --git a/src/renderer/src/i18n/locales/es.json b/src/renderer/src/i18n/locales/es.json index a7438a454..f55c638ce 100644 --- a/src/renderer/src/i18n/locales/es.json +++ b/src/renderer/src/i18n/locales/es.json @@ -638,7 +638,17 @@ "b1c2f8b0ac": "Cambio de cuenta opcional para Claude, Codex, Gemini y OpenCode Go.", "f70ac54d38": "Cuentas de proveedores de IA", "4121f7a0a2": "Administre agents de IA, establezca un valor predeterminado y personalice comandos.", - "b49abbd2f7": "Agentes" + "b49abbd2f7": "Agentes", + "dev": "Dev Tools", + "devDescription": "Dev-only tools for exercising UI states.", + "devBadge": "Dev", + "devSearchNotificationPlayground": "Notification playground", + "devSearchNotificationPlaygroundDescription": "Trigger representative toast and notification UI states.", + "devSearchKeywordDev": "dev", + "devSearchKeywordToast": "toast", + "devSearchKeywordSonner": "sonner", + "devSearchKeywordError": "error", + "devSearchKeywordNotification": "notification" }, "useAppMenuPaste": { "pasteTooLarge": "El contenido pegado es demasiado grande." @@ -6047,7 +6057,9 @@ "9abb9be3bc": "Configuración", "23c6874fdf": "Capacidades de IA", "2309068a6f": "destructivo", - "65358016ea": "Desechar" + "65358016ea": "Desechar", + "dev": "Dev Tools", + "devDescription": "Dev-only tools for exercising UI states." }, "SettingsFormControls": { "42a4d15a30": "No hay fuentes coincidentes.", @@ -8512,6 +8524,36 @@ }, "AppearanceAdvancedDisclosure": { "advanced": "Avanzado" + }, + "DevToolsPane": { + "nativeActionLayoutCheck": "Native action layout check", + "secondary": "Secondary", + "secondaryActionClicked": "Secondary action clicked", + "primaryAction": "Primary action", + "primaryActionClicked": "Primary action clicked", + "branchHasChanges": "branch has changes", + "viewChangesClicked": "View Changes clicked", + "forceDeleteClicked": "Force Delete clicked", + "devOnlyCallback": "Dev-only callback.", + "infoToast": "Info toast", + "infoToastDescription": "Long informational copy with no explicit action.", + "localCanaryBehind": "Local canary is behind origin/canary", + "successToast": "Success toast", + "successToastDescription": "Short confirmation state.", + "settingsSaved": "Settings saved", + "shortSuccessCopy": "Short success copy.", + "errorToast": "Error toast", + "errorToastDescription": "Long error copy without recovery actions.", + "failedToSyncWorkspaceMetadata": "Failed to sync workspace metadata", + "nativeActionToast": "Native action toast", + "nativeActionToastDescription": "Uses Sonner action and cancel slots.", + "deleteFailureToast": "Delete failure toast", + "deleteFailureToastDescription": "Custom footer with View and Force Delete.", + "behindBaseRefToast": "Behind base ref toast", + "behindBaseRefToastDescription": "Persistent prompt with an inline Settings link and footer action.", + "notificationPlayground": "Notification playground", + "notificationPlaygroundDescription": "Dev-only triggers for checking toast layout, recovery actions, and long-copy wrapping.", + "devOnly": "Dev only" } }, "right": { diff --git a/src/renderer/src/i18n/locales/ja.json b/src/renderer/src/i18n/locales/ja.json index 9254ee062..436e982e1 100644 --- a/src/renderer/src/i18n/locales/ja.json +++ b/src/renderer/src/i18n/locales/ja.json @@ -638,7 +638,17 @@ "b1c2f8b0ac": "Claude、Codex、Gemini、OpenCode Go のオプションのアカウント切り替え。", "f70ac54d38": "AI プロバイダー アカウント", "4121f7a0a2": "AI agents を管理し、デフォルトを設定し、コマンドをカスタマイズします。", - "b49abbd2f7": "エージェント" + "b49abbd2f7": "エージェント", + "dev": "Dev Tools", + "devDescription": "Dev-only tools for exercising UI states.", + "devBadge": "Dev", + "devSearchNotificationPlayground": "Notification playground", + "devSearchNotificationPlaygroundDescription": "Trigger representative toast and notification UI states.", + "devSearchKeywordDev": "dev", + "devSearchKeywordToast": "toast", + "devSearchKeywordSonner": "sonner", + "devSearchKeywordError": "error", + "devSearchKeywordNotification": "notification" }, "useAppMenuPaste": { "pasteTooLarge": "貼り付け内容が大きすぎます。" @@ -6069,7 +6079,9 @@ "9abb9be3bc": "セットアップ", "23c6874fdf": "AI 機能", "2309068a6f": "破壊的な", - "65358016ea": "破棄" + "65358016ea": "破棄", + "dev": "Dev Tools", + "devDescription": "Dev-only tools for exercising UI states." }, "SettingsFormControls": { "42a4d15a30": "一致するフォントがありません。", @@ -8512,6 +8524,36 @@ }, "AppearanceAdvancedDisclosure": { "advanced": "詳細設定" + }, + "DevToolsPane": { + "nativeActionLayoutCheck": "Native action layout check", + "secondary": "Secondary", + "secondaryActionClicked": "Secondary action clicked", + "primaryAction": "Primary action", + "primaryActionClicked": "Primary action clicked", + "branchHasChanges": "branch has changes", + "viewChangesClicked": "View Changes clicked", + "forceDeleteClicked": "Force Delete clicked", + "devOnlyCallback": "Dev-only callback.", + "infoToast": "Info toast", + "infoToastDescription": "Long informational copy with no explicit action.", + "localCanaryBehind": "Local canary is behind origin/canary", + "successToast": "Success toast", + "successToastDescription": "Short confirmation state.", + "settingsSaved": "Settings saved", + "shortSuccessCopy": "Short success copy.", + "errorToast": "Error toast", + "errorToastDescription": "Long error copy without recovery actions.", + "failedToSyncWorkspaceMetadata": "Failed to sync workspace metadata", + "nativeActionToast": "Native action toast", + "nativeActionToastDescription": "Uses Sonner action and cancel slots.", + "deleteFailureToast": "Delete failure toast", + "deleteFailureToastDescription": "Custom footer with View and Force Delete.", + "behindBaseRefToast": "Behind base ref toast", + "behindBaseRefToastDescription": "Persistent prompt with an inline Settings link and footer action.", + "notificationPlayground": "Notification playground", + "notificationPlaygroundDescription": "Dev-only triggers for checking toast layout, recovery actions, and long-copy wrapping.", + "devOnly": "Dev only" } }, "right": { diff --git a/src/renderer/src/i18n/locales/ko.json b/src/renderer/src/i18n/locales/ko.json index 928aacac8..62c9961cc 100644 --- a/src/renderer/src/i18n/locales/ko.json +++ b/src/renderer/src/i18n/locales/ko.json @@ -638,7 +638,17 @@ "b1c2f8b0ac": "Claude, Codex, Gemini 및 OpenCode Go에 대한 선택적 계정 전환.", "f70ac54d38": "AI 제공업체 계정", "4121f7a0a2": "AI agents를 관리하고, 기본값을 설정하고, 명령을 사용자 정의하세요.", - "b49abbd2f7": "에이전트" + "b49abbd2f7": "에이전트", + "dev": "Dev Tools", + "devDescription": "Dev-only tools for exercising UI states.", + "devBadge": "Dev", + "devSearchNotificationPlayground": "Notification playground", + "devSearchNotificationPlaygroundDescription": "Trigger representative toast and notification UI states.", + "devSearchKeywordDev": "dev", + "devSearchKeywordToast": "toast", + "devSearchKeywordSonner": "sonner", + "devSearchKeywordError": "error", + "devSearchKeywordNotification": "notification" }, "useAppMenuPaste": { "pasteTooLarge": "붙여넣기 내용이 너무 큽니다." @@ -6032,7 +6042,9 @@ "9abb9be3bc": "설정 시작", "23c6874fdf": "AI 기능", "2309068a6f": "파괴적", - "65358016ea": "버리기" + "65358016ea": "버리기", + "dev": "Dev Tools", + "devDescription": "Dev-only tools for exercising UI states." }, "SettingsFormControls": { "42a4d15a30": "일치하는 글꼴이 없습니다.", @@ -8512,6 +8524,36 @@ }, "AppearanceAdvancedDisclosure": { "advanced": "고급" + }, + "DevToolsPane": { + "nativeActionLayoutCheck": "Native action layout check", + "secondary": "Secondary", + "secondaryActionClicked": "Secondary action clicked", + "primaryAction": "Primary action", + "primaryActionClicked": "Primary action clicked", + "branchHasChanges": "branch has changes", + "viewChangesClicked": "View Changes clicked", + "forceDeleteClicked": "Force Delete clicked", + "devOnlyCallback": "Dev-only callback.", + "infoToast": "Info toast", + "infoToastDescription": "Long informational copy with no explicit action.", + "localCanaryBehind": "Local canary is behind origin/canary", + "successToast": "Success toast", + "successToastDescription": "Short confirmation state.", + "settingsSaved": "Settings saved", + "shortSuccessCopy": "Short success copy.", + "errorToast": "Error toast", + "errorToastDescription": "Long error copy without recovery actions.", + "failedToSyncWorkspaceMetadata": "Failed to sync workspace metadata", + "nativeActionToast": "Native action toast", + "nativeActionToastDescription": "Uses Sonner action and cancel slots.", + "deleteFailureToast": "Delete failure toast", + "deleteFailureToastDescription": "Custom footer with View and Force Delete.", + "behindBaseRefToast": "Behind base ref toast", + "behindBaseRefToastDescription": "Persistent prompt with an inline Settings link and footer action.", + "notificationPlayground": "Notification playground", + "notificationPlaygroundDescription": "Dev-only triggers for checking toast layout, recovery actions, and long-copy wrapping.", + "devOnly": "Dev only" } }, "right": { diff --git a/src/renderer/src/i18n/locales/zh.json b/src/renderer/src/i18n/locales/zh.json index 1e4c46ca7..aa67a7cda 100644 --- a/src/renderer/src/i18n/locales/zh.json +++ b/src/renderer/src/i18n/locales/zh.json @@ -638,7 +638,17 @@ "b1c2f8b0ac": "Claude、Codex、Gemini 和 OpenCode Go 的可选账户切换。", "f70ac54d38": "AI 提供商账户", "4121f7a0a2": "管理 AI 智能体、设置默认值并自定义命令。", - "b49abbd2f7": "智能体" + "b49abbd2f7": "智能体", + "dev": "Dev Tools", + "devDescription": "Dev-only tools for exercising UI states.", + "devBadge": "Dev", + "devSearchNotificationPlayground": "Notification playground", + "devSearchNotificationPlaygroundDescription": "Trigger representative toast and notification UI states.", + "devSearchKeywordDev": "dev", + "devSearchKeywordToast": "toast", + "devSearchKeywordSonner": "sonner", + "devSearchKeywordError": "error", + "devSearchKeywordNotification": "notification" }, "useAppMenuPaste": { "pasteTooLarge": "粘贴内容过大。" @@ -6032,7 +6042,9 @@ "9abb9be3bc": "初始设置", "23c6874fdf": "AI 能力", "2309068a6f": "destructive", - "65358016ea": "放弃" + "65358016ea": "放弃", + "dev": "Dev Tools", + "devDescription": "Dev-only tools for exercising UI states." }, "SettingsFormControls": { "42a4d15a30": "没有匹配的字体。", @@ -8512,6 +8524,36 @@ }, "AppearanceAdvancedDisclosure": { "advanced": "高级" + }, + "DevToolsPane": { + "nativeActionLayoutCheck": "Native action layout check", + "secondary": "Secondary", + "secondaryActionClicked": "Secondary action clicked", + "primaryAction": "Primary action", + "primaryActionClicked": "Primary action clicked", + "branchHasChanges": "branch has changes", + "viewChangesClicked": "View Changes clicked", + "forceDeleteClicked": "Force Delete clicked", + "devOnlyCallback": "Dev-only callback.", + "infoToast": "Info toast", + "infoToastDescription": "Long informational copy with no explicit action.", + "localCanaryBehind": "Local canary is behind origin/canary", + "successToast": "Success toast", + "successToastDescription": "Short confirmation state.", + "settingsSaved": "Settings saved", + "shortSuccessCopy": "Short success copy.", + "errorToast": "Error toast", + "errorToastDescription": "Long error copy without recovery actions.", + "failedToSyncWorkspaceMetadata": "Failed to sync workspace metadata", + "nativeActionToast": "Native action toast", + "nativeActionToastDescription": "Uses Sonner action and cancel slots.", + "deleteFailureToast": "Delete failure toast", + "deleteFailureToastDescription": "Custom footer with View and Force Delete.", + "behindBaseRefToast": "Behind base ref toast", + "behindBaseRefToastDescription": "Persistent prompt with an inline Settings link and footer action.", + "notificationPlayground": "Notification playground", + "notificationPlaygroundDescription": "Dev-only triggers for checking toast layout, recovery actions, and long-copy wrapping.", + "devOnly": "Dev only" } }, "right": { diff --git a/src/renderer/src/lib/settings-navigation-types.ts b/src/renderer/src/lib/settings-navigation-types.ts index 649d0f4c0..765940ffe 100644 --- a/src/renderer/src/lib/settings-navigation-types.ts +++ b/src/renderer/src/lib/settings-navigation-types.ts @@ -22,6 +22,7 @@ export type SettingsNavTarget = | 'developer-permissions' | 'privacy' | 'advanced' + | 'dev' | 'voice' | 'shortcuts' | 'stats'