Skip to content

The agent that grows with you

fix(desktop): persist confirmed onboarding accents as themes

Ryan Hill86ef4453e958
diff --git a/apps/desktop/src/components/assistant-ui/clarify/setup-pending.test.tsx b/apps/desktop/src/components/assistant-ui/clarify/setup-pending.test.tsx
index 9a8516054b8..bba6990ca6f 100644
--- a/apps/desktop/src/components/assistant-ui/clarify/setup-pending.test.tsx
+++ b/apps/desktop/src/components/assistant-ui/clarify/setup-pending.test.tsx
@@ -1,10 +1,11 @@
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
-import { cleanup, render, screen } from '@testing-library/react'
+import { act, cleanup, fireEvent, render, screen } from '@testing-library/react'
import { atom } from 'nanostores'
import { afterEach, beforeEach, describe, expect, it, type MockInstance, vi } from 'vitest'
import { PRIMARY_SESSION_VIEW, type SessionView, SessionViewProvider } from '@/app/chat/session-view'
import { accentsFor, NOUS_ACCENT } from '@/components/onboarding-chat/options'
+import type { HermesConnection } from '@/global'
import { I18nProvider } from '@/i18n'
import {
answerSetupCard,
@@ -13,21 +14,46 @@ import {
setClarifyRequest,
type SetupChooseSpec
} from '@/store/clarify'
+import { $activeGatewayProfile } from '@/store/profile'
import { rememberServerRequest, resetServerRequestsForTests } from '@/store/server-requests'
+import { $connection } from '@/store/session'
import { $accentOverride } from '@/themes/accent-override'
+import { modePref, skinPref, ThemeProvider, useTheme } from '@/themes/context'
+import { DEFAULT_SKIN_NAME } from '@/themes/presets'
+import { $userThemes } from '@/themes/user-themes'
import { SetupChoosePending } from './setup-pending'
const SESSION = 'setup-session'
+const CONNECTION: HermesConnection = {
+ baseUrl: 'http://localhost:1',
+ isFullscreen: false,
+ nativeOverlayWidth: 0,
+ windowButtonPosition: null,
+ token: '',
+ wsUrl: 'ws://localhost:1',
+ logs: []
+}
+
const view: SessionView = { ...PRIMARY_SESSION_VIEW, $runtimeId: atom(SESSION), $storedId: atom('stored-setup') }
-function renderCard(requestId: string, question: string, kind: SetupChooseSpec['kind']) {
+let theme: ReturnType<typeof useTheme>
+
+function ThemeProbe() {
+ theme = useTheme()
+
+ return null
+}
+
+const primary = () => window.document.documentElement.style.getPropertyValue('--theme-primary')
+
+function renderCard(requestId: string, question: string, kind: SetupChooseSpec['kind'], preselected: string[] = []) {
const request: ClarifyRequest = {
questions: [{ choices: null, multiSelect: false, qid: 'q0', question }],
requestId,
sessionId: SESSION,
- setup: { kind, multiSelect: false, options: null, preselected: [] }
+ setup: { kind, multiSelect: false, options: null, preselected }
}
rememberServerRequest({ fail: vi.fn(), id: requestId, method: 'setup_choose', params: {}, respond: vi.fn() })
@@ -36,9 +62,12 @@ function renderCard(requestId: string, question: string, kind: SetupChooseSpec['
return render(
<QueryClientProvider client={new QueryClient()}>
<I18nProvider configClient={null} initialLocale="en">
- <SessionViewProvider value={view}>
- <SetupChoosePending fromArgs={null} onAnswered={vi.fn()} request={request} undelivered={false} />
- </SessionViewProvider>
+ <ThemeProvider>
+ <ThemeProbe />
+ <SessionViewProvider value={view}>
+ <SetupChoosePending fromArgs={null} onAnswered={vi.fn()} request={request} undelivered={false} />
+ </SessionViewProvider>
+ </ThemeProvider>
</I18nProvider>
</QueryClientProvider>
)
@@ -47,6 +76,10 @@ function renderCard(requestId: string, question: string, kind: SetupChooseSpec['
let consoleError: MockInstance<typeof console.error>
beforeEach(() => {
+ window.localStorage.clear()
+ $userThemes.set({})
+ $activeGatewayProfile.set('default')
+ $connection.set(CONNECTION)
resetServerRequestsForTests()
consoleError = vi.spyOn(console, 'error')
})
@@ -69,15 +102,98 @@ describe('setup cards render without redrawing themselves', () => {
expect(loopErrors()).toEqual([])
})
- it('applies a look typed in the composer the same way a click does', async () => {
+ it('keeps a confirmed accent through cold startup, profile switches, and later theme changes', async () => {
+ skinPref.assign('other', 'ember')
+ skinPref.assign('default', DEFAULT_SKIN_NAME)
+ $activeGatewayProfile.set('setup')
+ modePref.assign('setup', 'light')
renderCard('accent-1', 'Pick an accent', 'accent')
await screen.findByText('Pick an accent')
- const swatch = accentsFor(false).find(({ hex }) => hex !== NOUS_ACCENT)
+ const swatch = accentsFor(false).find(({ name }) => name === 'GitHub green')
expect(swatch).toBeTruthy()
- expect(answerSetupCard(SESSION, swatch!.name)).toBe(true)
- expect($accentOverride.get()).toBe(swatch!.hex)
+ act(() => expect(answerSetupCard(SESSION, swatch!.name)).toBe(true))
+ const selected = theme.themeName
+ const light = primary()
+
+ expect(selected).not.toBe(DEFAULT_SKIN_NAME)
+ expect(skinPref.resolve('setup')).toBe(selected)
+ expect($accentOverride.get()).toBeNull()
+ act(() => theme.setMode('dark'))
+ const dark = primary()
+
+ // Drop every module-level atom, preserving only localStorage as a new renderer does.
+ cleanup()
+ vi.resetModules()
+ const fresh = await import('@/themes/context')
+ expect(primary()).toBe(dark)
+ const { $activeGatewayProfile: profile } = await import('@/store/profile')
+ const { $connection: connection } = await import('@/store/session')
+ let restored: ReturnType<typeof useTheme>
+
+ function RestoredProbe() {
+ restored = fresh.useTheme()
+
+ return null
+ }
+
+ profile.set('setup')
+ connection.set(CONNECTION)
+ render(
+ <fresh.ThemeProvider>
+ <RestoredProbe />
+ </fresh.ThemeProvider>
+ )
+ expect(restored!.themeName).toBe(selected)
+ expect(primary()).toBe(dark)
+ act(() => restored!.setMode('light'))
+ expect(primary()).toBe(light)
+ act(() => profile.set('other'))
+ expect(restored!.themeName).toBe('ember')
+ act(() => profile.set('setup'))
+ expect(restored!.themeName).toBe(selected)
+ expect(primary()).toBe(light)
+ act(() => restored!.setTheme('midnight'))
+ const replacement = primary()
+ cleanup()
+ render(
+ <fresh.ThemeProvider>
+ <RestoredProbe />
+ </fresh.ThemeProvider>
+ )
+ expect(restored!.themeName).toBe('midnight')
+ expect(primary()).toBe(replacement)
expect(loopErrors()).toEqual([])
})
+
+ it('only saves the clicked accent when confirmed and restores skipped previews', async () => {
+ modePref.assign('default', 'light')
+ renderCard('accent-click', 'Pick an accent', 'accent')
+ const original = primary()
+ const swatch = accentsFor(false).find(({ hex }) => hex !== NOUS_ACCENT)!
+
+ fireEvent.click(await screen.findByRole('button', { name: swatch.name }))
+ expect(primary()).not.toBe(original)
+ expect(skinPref.resolve('default')).toBe(DEFAULT_SKIN_NAME)
+ expect(Object.keys($userThemes.get())).toHaveLength(0)
+ act(() => clearClarifyRequest())
+ expect(primary()).toBe(original)
+ cleanup()
+
+ renderCard('accent-confirm', 'Pick an accent', 'accent')
+ fireEvent.click(await screen.findByRole('button', { name: swatch.name }))
+ fireEvent.click(screen.getByRole('button', { name: /confirm/i }))
+ expect(skinPref.resolve('default')).toBe(theme.themeName)
+ expect(theme.themeName).not.toBe(DEFAULT_SKIN_NAME)
+ expect(Object.keys($userThemes.get())).toHaveLength(1)
+ expect($accentOverride.get()).toBeNull()
+ cleanup()
+
+ renderCard('accent-blue', 'Pick an accent', 'accent', [NOUS_ACCENT])
+ fireEvent.click(await screen.findByRole('button', { name: /confirm/i }))
+ expect(theme.themeName).toBe(DEFAULT_SKIN_NAME)
+ expect(primary()).toBe(original)
+ expect(Object.keys($userThemes.get())).toHaveLength(1)
+ })
})
diff --git a/apps/desktop/src/components/assistant-ui/clarify/setup-pending.tsx b/apps/desktop/src/components/assistant-ui/clarify/setup-pending.tsx
index e1c6a59a2ee..80b2f1db4b8 100644
--- a/apps/desktop/src/components/assistant-ui/clarify/setup-pending.tsx
+++ b/apps/desktop/src/components/assistant-ui/clarify/setup-pending.tsx
@@ -70,7 +70,7 @@ export function SetupChoosePending({
const copy = t.assistant.clarify
const setupCopy = t.assistant.setupChoose
const storedId = useStore(useSessionView().$storedId)
- const { mode, setMode } = useTheme()
+ const { mode, setMode, setTheme } = useTheme()
const { kind, pickerKind, ready, requestId, setup, source } = setupChooseSource(request, fromArgs)
const freeText = pickerKind === null
@@ -148,14 +148,23 @@ export function SetupChoosePending({
[kind, mode, question.multiSelect, requestId, setMode]
)
+ const commitLook = useCallback(
+ (ids: string[]) => {
+ if (ids[0]) {
+ LIVE_LOOK[kind]?.commit?.(ids[0], setTheme)
+ }
+ },
+ [kind, setTheme]
+ )
+
// Composer text that names a row picks it through this card, so the typed pick applies its look too.
const liveRequestId = request?.requestId
useEffect(() => {
if (liveRequestId) {
- stageSetupChoose(liveRequestId, { preview: stage })
+ stageSetupChoose(liveRequestId, { commit: commitLook, preview: stage })
}
- }, [liveRequestId, stage])
+ }, [commitLook, liveRequestId, stage])
const toggle = useCallback(
(_question: ClarifyQuestion, choice: string) => {
diff --git a/apps/desktop/src/components/assistant-ui/clarify/setup-rows.ts b/apps/desktop/src/components/assistant-ui/clarify/setup-rows.ts
index f651c0eba62..68a13a1a33c 100644
--- a/apps/desktop/src/components/assistant-ui/clarify/setup-rows.ts
+++ b/apps/desktop/src/components/assistant-ui/clarify/setup-rows.ts
@@ -16,6 +16,9 @@ import { useTheme } from '@/themes'
import { $accentOverride, setAccentOverride } from '@/themes/accent-override'
import { normalizeHex } from '@/themes/color'
import type { ThemeMode } from '@/themes/context'
+import { nousTheme } from '@/themes/presets'
+import { retintTheme } from '@/themes/retint'
+import { installUserTheme } from '@/themes/user-themes'
export type SetupRow = SetupChooseOption
@@ -69,11 +72,34 @@ const APP_LABELS: Record<SetupChooseKind, (id: string, sources: Pick<RowSources,
interface LiveLook {
apply: (id: string, setMode: (mode: ThemeMode) => void) => void
+ commit?: (id: string, setTheme: (name: string) => void) => void
snapshot: (mode: ThemeMode, setMode: (mode: ThemeMode) => void) => () => void
}
export const LIVE_LOOK: Partial<Record<SetupChooseKind, LiveLook>> = {
accent: {
+ commit: (id, setTheme) => {
+ const hex = normalizeHex(id)
+
+ if (!hex) {
+ return
+ }
+
+ // Save the confirmed palette through normal theme persistence. The preview
+ // override is temporary and must not tint later theme or profile selections.
+ const theme =
+ hex === NOUS_ACCENT
+ ? nousTheme
+ : installUserTheme({
+ ...retintTheme(nousTheme, hex),
+ name: `nous-accent-${hex.slice(1)}`,
+ label: `${nousTheme.label} · ${hex}`
+ })
+
+ setTheme(theme.name)
+ setOnboardingAnswers({ accent: hex === NOUS_ACCENT ? null : hex })
+ setAccentOverride(null)
+ },
apply: id => {
const hex = normalizeHex(id)
diff --git a/apps/desktop/src/store/clarify.ts b/apps/desktop/src/store/clarify.ts
index e78b6216361..4457e84cec5 100644
--- a/apps/desktop/src/store/clarify.ts
+++ b/apps/desktop/src/store/clarify.ts
@@ -250,6 +250,8 @@ export function clearClarifyRequest(requestId?: string, sessionId?: string | nul
}
interface SetupChooseStage {
+ /** Persist a confirmed look; clearing or skipping the card only reverts its preview. */
+ commit?: (picked: string[]) => void
draft: string
/**
* The name each row of the card shows, by id: a typed answer still names the rows staged with it, and
@@ -304,18 +306,24 @@ export function stageSetupChoose(requestId: string, patch: Partial<SetupChooseSt
$setupChooseStages.set({ ...$setupChooseStages.get(), [requestId]: { ...current, ...patch } })
}
-export function commitSetupChoose(requestId: string): void {
+function clearSetupChoose(requestId: string): void {
const next = { ...$setupChooseStages.get() }
delete next[requestId]
$setupChooseStages.set(next)
}
+export function commitSetupChoose(requestId: string): void {
+ const stage = setupChooseStage(requestId)
+ clearSetupChoose(requestId)
+ stage.commit?.(stage.picked)
+}
+
$clarifyRequests.listen(requests => {
const live = new Set(Object.values(requests).map(request => request.requestId))
for (const [requestId, stage] of Object.entries($setupChooseStages.get())) {
if (!live.has(requestId)) {
- commitSetupChoose(requestId)
+ clearSetupChoose(requestId)
stage.revert?.()
}
}