Skip to content

The all-in-one local AI studio for your desktop: chat, image and video generation and a coding agent in one free, open source app. Windows and Linux. No Docker, no terminal, no cloud required.

fix(settings): per-tab Reset-to-Defaults with confirm + feedback (#59)

purple714f3b1bfbbe
diff --git a/src/components/settings/SettingsPage.tsx b/src/components/settings/SettingsPage.tsx
index 3987732e..3eab9405 100644
--- a/src/components/settings/SettingsPage.tsx
+++ b/src/components/settings/SettingsPage.tsx
@@ -1,7 +1,9 @@
import { useState, useEffect, useRef, type ReactNode, type ChangeEvent } from 'react'
import { ArrowLeft, RotateCcw, Sun, Moon, Volume2, Check, X, Loader2, Shield, ChevronRight, GraduationCap, Lock, Sliders, Plug, Bot, Phone, User, Download, Mic } from 'lucide-react'
import { motion, AnimatePresence } from 'framer-motion'
+import { SETTINGS_TAB_RESET_KEYS, type SettingsTab } from '../../lib/settings-reset'
import { useSettingsStore } from '../../stores/settingsStore'
+import { usePermissionStore } from '../../stores/permissionStore'
import { useUIStore } from '../../stores/uiStore'
import { SliderControl } from './SliderControl'
import { PersonaPanel } from '../personas/PersonaPanel'
@@ -664,7 +666,6 @@ function CodexAgentSettings() {
//
// Tab choice is persisted in localStorage so the user's last-used view
// survives reloads.
-type SettingsTab = 'general' | 'backends' | 'agent' | 'voice-remote'
const SETTINGS_TAB_KEY = 'lu-settings-tab'
const SETTINGS_TABS: { id: SettingsTab; label: string; icon: ReactNode }[] = [
{ id: 'general', label: 'General', icon: <Sliders size={11} /> },
@@ -673,8 +674,89 @@ const SETTINGS_TABS: { id: SettingsTab; label: string; icon: ReactNode }[] = [
{ id: 'voice-remote', label: 'Voice & Remote', icon: <Phone size={11} /> },
]
+// GitHub #59 — the old single "Reset to Defaults" button fired silently with
+// no confirm and no feedback, so users reported it as "does nothing". Now:
+// arm-then-confirm (second click within 4s), per-tab scope, and an explicit
+// success line after the reset.
+function ResetSection({ tab }: { tab: SettingsTab }) {
+ const resetSettingsKeys = useSettingsStore((s) => s.resetSettingsKeys)
+ const resetSettings = useSettingsStore((s) => s.resetSettings)
+ const resetVoiceDefaults = useVoiceStore((s) => s.resetVoiceDefaults)
+ const resetPermissions = usePermissionStore((s) => s.resetToDefaults)
+ const [armed, setArmed] = useState<'section' | 'all' | null>(null)
+ const [done, setDone] = useState<string | null>(null)
+ const armTimer = useRef<number | null>(null)
+ const doneTimer = useRef<number | null>(null)
+
+ const tabLabel = SETTINGS_TABS.find((t) => t.id === tab)?.label ?? 'section'
+
+ // Switching tabs while armed must disarm — otherwise a click armed on
+ // General would confirm-fire on Agent.
+ useEffect(() => { setArmed(null) }, [tab])
+ useEffect(() => () => {
+ if (armTimer.current) window.clearTimeout(armTimer.current)
+ if (doneTimer.current) window.clearTimeout(doneTimer.current)
+ }, [])
+
+ const handleClick = (which: 'section' | 'all') => {
+ if (armed !== which) {
+ setArmed(which)
+ if (armTimer.current) window.clearTimeout(armTimer.current)
+ armTimer.current = window.setTimeout(() => setArmed(null), 4000)
+ return
+ }
+ if (armTimer.current) window.clearTimeout(armTimer.current)
+ setArmed(null)
+ if (which === 'all') {
+ resetSettings()
+ resetVoiceDefaults()
+ resetPermissions()
+ setDone('All settings restored to defaults')
+ } else {
+ resetSettingsKeys(SETTINGS_TAB_RESET_KEYS[tab])
+ if (tab === 'agent') resetPermissions()
+ if (tab === 'voice-remote') resetVoiceDefaults()
+ setDone(`${tabLabel} settings restored to defaults`)
+ }
+ if (doneTimer.current) window.clearTimeout(doneTimer.current)
+ doneTimer.current = window.setTimeout(() => setDone(null), 3000)
+ }
+
+ return (
+ <div className="pt-3 pb-6 space-y-1.5">
+ <div className="flex items-center gap-3">
+ <button
+ onClick={() => handleClick('section')}
+ className={`flex items-center gap-1.5 text-[0.65rem] transition-colors ${
+ armed === 'section' ? 'text-red-400 font-medium' : 'text-gray-500 hover:text-red-400'
+ }`}
+ >
+ <RotateCcw size={11} />
+ {armed === 'section' ? `Click again to reset ${tabLabel}` : `Reset ${tabLabel} to defaults`}
+ </button>
+ <button
+ onClick={() => handleClick('all')}
+ className={`flex items-center gap-1.5 text-[0.6rem] transition-colors ${
+ armed === 'all' ? 'text-red-400 font-medium' : 'text-gray-600 dark:text-gray-600 hover:text-red-400'
+ }`}
+ >
+ {armed === 'all' ? 'Click again to reset everything' : 'Reset all settings'}
+ </button>
+ </div>
+ {done && (
+ <div className="flex items-center gap-1.5 text-[0.6rem] text-emerald-500">
+ <Check size={11} /> {done}
+ </div>
+ )}
+ <div className="text-[0.55rem] text-gray-500 dark:text-gray-600 leading-snug">
+ Personas, memories, conversations, workflows and MCP servers are kept.
+ </div>
+ </div>
+ )
+}
+
export function SettingsPage() {
- const { settings, updateSettings, resetSettings } = useSettingsStore()
+ const { settings, updateSettings } = useSettingsStore()
const { setView } = useUIStore()
const voiceSettings = useVoiceStore()
const [whisperStatus, setWhisperStatus] = useState<{ available: boolean; backend: string | null; error?: string } | null>(null)
@@ -1220,15 +1302,8 @@ export function SettingsPage() {
</Section>
</>)}
- {/* ── Reset ──────────────────────────────────── */}
- <div className="pt-3 pb-6">
- <button
- onClick={resetSettings}
- className="flex items-center gap-1.5 text-[0.65rem] text-gray-500 hover:text-red-400 transition-colors"
- >
- <RotateCcw size={11} /> Reset to Defaults
- </button>
- </div>
+ {/* ── Reset (GitHub #59: per-tab scope + confirm + feedback) ── */}
+ <ResetSection tab={tab} />
</div>
</div>
)
diff --git a/src/lib/__tests__/settings-reset.test.ts b/src/lib/__tests__/settings-reset.test.ts
new file mode 100644
index 00000000..5d8c45d4
--- /dev/null
+++ b/src/lib/__tests__/settings-reset.test.ts
@@ -0,0 +1,69 @@
+import { describe, it, expect } from 'vitest'
+import { SETTINGS_TAB_RESET_KEYS } from '../settings-reset'
+import { DEFAULT_SETTINGS } from '../constants'
+import { useVoiceStore } from '../../stores/voiceStore'
+
+// GitHub #59 — per-tab reset scope. These tests pin the contract: every key
+// in the map is a real Settings key, no key is double-owned by two tabs, and
+// the lifecycle marker onboardingDone is never part of a section reset.
+describe('SETTINGS_TAB_RESET_KEYS (#59)', () => {
+ const allKeys = Object.values(SETTINGS_TAB_RESET_KEYS).flat()
+
+ it('every mapped key exists in DEFAULT_SETTINGS', () => {
+ for (const k of allKeys) {
+ expect(Object.prototype.hasOwnProperty.call(DEFAULT_SETTINGS, k), `unknown settings key: ${String(k)}`).toBe(true)
+ }
+ })
+
+ it('no key is owned by two tabs', () => {
+ const seen = new Set<string>()
+ for (const k of allKeys) {
+ expect(seen.has(String(k)), `key mapped twice: ${String(k)}`).toBe(false)
+ seen.add(String(k))
+ }
+ })
+
+ it('never includes onboardingDone (lifecycle marker, not a preference)', () => {
+ expect(allKeys.includes('onboardingDone')).toBe(false)
+ })
+
+ it('general tab covers the visible General sections (appearance, generation, hardware, timeouts)', () => {
+ const g = SETTINGS_TAB_RESET_KEYS.general
+ for (const k of ['theme', 'temperature', 'topP', 'topK', 'maxTokens', 'contextWindowOverride', 'gpuVendor', 'gpuIndices', 'imageGenTimeoutMinutes', 'videoGenTimeoutMinutes'] as const) {
+ expect(g, `general tab missing ${k}`).toContain(k)
+ }
+ })
+
+ it('agent tab covers codex + search-provider + budget keys', () => {
+ const a = SETTINGS_TAB_RESET_KEYS.agent
+ for (const k of ['searchProvider', 'braveApiKey', 'tavilyApiKey', 'codexStageMode', 'codexReviewMode', 'agentMaxToolCalls', 'agentMaxIterations'] as const) {
+ expect(a, `agent tab missing ${k}`).toContain(k)
+ }
+ })
+})
+
+describe('voiceStore.resetVoiceDefaults (#59)', () => {
+ it('restores persisted voice settings and leaves availability probes alone', () => {
+ useVoiceStore.setState({
+ sttEnabled: true,
+ ttsEnabled: true,
+ piperVoice: 'en_GB-alba-medium',
+ ttsVoice: 'Microsoft Zira',
+ ttsRate: 1.6,
+ ttsPitch: 0.4,
+ sttAvailable: true,
+ ttsAvailable: true,
+ })
+ useVoiceStore.getState().resetVoiceDefaults()
+ const s = useVoiceStore.getState()
+ expect(s.sttEnabled).toBe(false)
+ expect(s.ttsEnabled).toBe(false)
+ expect(s.piperVoice).toBe('en_US-lessac-medium')
+ expect(s.ttsVoice).toBe('')
+ expect(s.ttsRate).toBe(1.0)
+ expect(s.ttsPitch).toBe(1.0)
+ // Probe state reflects what's installed on disk — reset must not lie about it.
+ expect(s.sttAvailable).toBe(true)
+ expect(s.ttsAvailable).toBe(true)
+ })
+})
diff --git a/src/lib/settings-reset.ts b/src/lib/settings-reset.ts
new file mode 100644
index 00000000..d12b4d5a
--- /dev/null
+++ b/src/lib/settings-reset.ts
@@ -0,0 +1,31 @@
+import type { Settings } from '../types/settings'
+
+/** Settings page top-level tabs. Kept here (UI-free) so the per-tab reset
+ * scope can be unit-tested without pulling the whole SettingsPage in. */
+export type SettingsTab = 'general' | 'backends' | 'agent' | 'voice-remote'
+
+// GitHub #59 (hussam) — which settings keys each tab's reset restores.
+// Only PREFERENCES are listed: user CONTENT (custom personas, memories,
+// conversations, agent workflows, MCP server entries) is never touched by a
+// settings reset — those have their own delete/clear flows with their own
+// confirms. Voice lives in voiceStore (reset separately); Remote Access has
+// no persisted settings (runtime server state only). onboardingDone is a
+// lifecycle marker and is excluded everywhere (resetSettingsKeys also guards
+// against it).
+export const SETTINGS_TAB_RESET_KEYS: Record<SettingsTab, (keyof Settings)[]> = {
+ general: [
+ 'theme', 'userAvatarDataUrl',
+ 'temperature', 'topP', 'topK', 'maxTokens', 'contextWindowOverride',
+ 'gpuVendor', 'gpuIndices',
+ 'imageGenTimeoutMinutes', 'videoGenTimeoutMinutes',
+ ],
+ backends: ['apiEndpoint', 'hfDownloadPathOverride', 'exclusiveVramMode'],
+ agent: [
+ 'personasEnabled', 'defaultWorkspace',
+ 'agentMaxToolCalls', 'agentMaxIterations',
+ 'searchProvider', 'braveApiKey', 'tavilyApiKey',
+ 'codexArchitectMode', 'codexArchitectModel', 'codexArchitectAllowCloud',
+ 'codexRepoMapEnabled', 'codexRepoMapLimit', 'codexStageMode', 'codexReviewMode',
+ ],
+ 'voice-remote': [],
+}
diff --git a/src/stores/__tests__/settingsStore.test.ts b/src/stores/__tests__/settingsStore.test.ts
index 76e201d3..30144bed 100644
--- a/src/stores/__tests__/settingsStore.test.ts
+++ b/src/stores/__tests__/settingsStore.test.ts
@@ -72,6 +72,46 @@ describe('settingsStore', () => {
})
})
+ // ── resetSettingsKeys (GitHub #59 per-section reset) ───────
+
+ describe('resetSettingsKeys', () => {
+ it('resets only the listed keys to defaults', () => {
+ useSettingsStore.getState().updateSettings({ temperature: 0.1, theme: 'light', apiEndpoint: 'http://10.0.0.5:1234' })
+ useSettingsStore.getState().resetSettingsKeys(['temperature', 'theme'])
+ const s = useSettingsStore.getState().settings
+ expect(s.temperature).toBe(DEFAULT_SETTINGS.temperature)
+ expect(s.theme).toBe(DEFAULT_SETTINGS.theme)
+ // Not in the list → untouched
+ expect(s.apiEndpoint).toBe('http://10.0.0.5:1234')
+ })
+
+ it('never resets onboardingDone even when listed', () => {
+ useSettingsStore.getState().updateSettings({ onboardingDone: true })
+ useSettingsStore.getState().resetSettingsKeys(['onboardingDone', 'temperature'])
+ expect(useSettingsStore.getState().settings.onboardingDone).toBe(true)
+ })
+
+ it('is a no-op for an empty key list', () => {
+ useSettingsStore.getState().updateSettings({ topK: 7 })
+ useSettingsStore.getState().resetSettingsKeys([])
+ expect(useSettingsStore.getState().settings.topK).toBe(7)
+ })
+
+ it('does not touch personas', () => {
+ useSettingsStore.getState().addPersona(makePersona('keep-me'))
+ useSettingsStore.getState().resetSettingsKeys(['temperature', 'searchProvider', 'braveApiKey'])
+ expect(useSettingsStore.getState().personas.find(p => p.id === 'keep-me')).toBeDefined()
+ })
+
+ it('resets array/object-valued keys by default value (gpuIndices, defaultWorkspace)', () => {
+ useSettingsStore.getState().updateSettings({ gpuIndices: [1, 2], defaultWorkspace: { path: 'C:/tmp', label: 'tmp' } as any })
+ useSettingsStore.getState().resetSettingsKeys(['gpuIndices', 'defaultWorkspace'])
+ const s = useSettingsStore.getState().settings
+ expect(s.gpuIndices).toEqual(DEFAULT_SETTINGS.gpuIndices)
+ expect(s.defaultWorkspace).toBe(DEFAULT_SETTINGS.defaultWorkspace)
+ })
+ })
+
// ── addPersona ─────────────────────────────────────────────
describe('addPersona', () => {
diff --git a/src/stores/settingsStore.ts b/src/stores/settingsStore.ts
index 94040d80..36565b30 100644
--- a/src/stores/settingsStore.ts
+++ b/src/stores/settingsStore.ts
@@ -26,6 +26,9 @@ interface SettingsState {
_version: number
updateSettings: (partial: Partial<Settings>) => void
resetSettings: () => void
+ /** GitHub #59 — reset only the given settings keys to their defaults
+ * (per-section reset; leaves everything else untouched). */
+ resetSettingsKeys: (keys: (keyof Settings)[]) => void
addPersona: (persona: Persona) => void
removePersona: (id: string) => void
updatePersona: (id: string, partial: Partial<Persona>) => void
@@ -46,6 +49,18 @@ export const useSettingsStore = create<SettingsState>()(
resetSettings: () => set((state) => ({ settings: { ...DEFAULT_SETTINGS, onboardingDone: state.settings.onboardingDone } })),
+ resetSettingsKeys: (keys) =>
+ set((state) => {
+ const next = { ...state.settings }
+ for (const k of keys) {
+ // onboardingDone is a lifecycle marker, not a preference — never
+ // reset it (same guard the full resetSettings applies).
+ if (k === 'onboardingDone') continue
+ ;(next as Record<string, unknown>)[k] = DEFAULT_SETTINGS[k]
+ }
+ return { settings: next }
+ }),
+
addPersona: (persona) =>
set((state) => ({ personas: [...state.personas, persona] })),
diff --git a/src/stores/voiceStore.ts b/src/stores/voiceStore.ts
index 96dbd817..f4d80b6d 100644
--- a/src/stores/voiceStore.ts
+++ b/src/stores/voiceStore.ts
@@ -44,6 +44,10 @@ interface VoiceState {
}>
) => void;
resetTransient: () => void;
+ /** GitHub #59 — restore the persisted voice settings to factory defaults.
+ * Transient probe state (sttAvailable/ttsAvailable) is left alone: it
+ * reflects what is installed on disk, not a preference. */
+ resetVoiceDefaults: () => void;
}
export const useVoiceStore = create<VoiceState>()(
@@ -88,6 +92,16 @@ export const useVoiceStore = create<VoiceState>()(
isSpeaking: false,
transcript: "",
}),
+
+ resetVoiceDefaults: () =>
+ set({
+ sttEnabled: false,
+ ttsEnabled: false,
+ piperVoice: "en_US-lessac-medium",
+ ttsVoice: "",
+ ttsRate: 1.0,
+ ttsPitch: 1.0,
+ }),
}),
{
name: "locally-uncensored-voice",