The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
refactor(desktop): move accent persistence into persistAccent
alt-glitchb88515b18528
diff --git a/apps/desktop/src/components/assistant-ui/clarify/setup-pending.tsx b/apps/desktop/src/components/assistant-ui/clarify/setup-pending.tsxindex 80b2f1db4b8..e5ba732889d 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.clarifyconst setupCopy = t.assistant.setupChooseconst storedId = useStore(useSessionView().$storedId)- const { mode, setMode, setTheme } = useTheme()+ const { mode, setMode } = useTheme()const { kind, pickerKind, ready, requestId, setup, source } = setupChooseSource(request, fromArgs)const freeText = pickerKind === null@@ -151,10 +151,10 @@ export function SetupChoosePending({const commitLook = useCallback((ids: string[]) => {if (ids[0]) {- LIVE_LOOK[kind]?.commit?.(ids[0], setTheme)+ LIVE_LOOK[kind]?.commit?.(ids[0])}},- [kind, setTheme]+ [kind])// Composer text that names a row picks it through this card, so the typed pick applies its look too.diff --git a/apps/desktop/src/components/assistant-ui/clarify/setup-rows.ts b/apps/desktop/src/components/assistant-ui/clarify/setup-rows.tsindex 68a13a1a33c..c61c613c40a 100644--- a/apps/desktop/src/components/assistant-ui/clarify/setup-rows.ts+++ b/apps/desktop/src/components/assistant-ui/clarify/setup-rows.ts@@ -16,9 +16,7 @@ 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'+import { persistAccent } from '@/themes/persist-accent'export type SetupRow = SetupChooseOption@@ -72,33 +70,19 @@ 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+ commit?: (id: string) => voidsnapshot: (mode: ThemeMode, setMode: (mode: ThemeMode) => void) => () => void}export const LIVE_LOOK: Partial<Record<SetupChooseKind, LiveLook>> = {accent: {- commit: (id, setTheme) => {+ commit: id => {const hex = normalizeHex(id)- if (!hex) {- return+ if (hex) {+ setOnboardingAnswers({ accent: hex === NOUS_ACCENT ? null : hex })+ persistAccent(hex)}-- // 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/themes/persist-accent.test.tsx b/apps/desktop/src/themes/persist-accent.test.tsxnew file mode 100644index 00000000000..2bd30e82909--- /dev/null+++ b/apps/desktop/src/themes/persist-accent.test.tsx@@ -0,0 +1,56 @@+import { act, cleanup, render } from '@testing-library/react'+import { afterEach, beforeEach, describe, expect, it } from 'vitest'++import { $activeGatewayProfile } from '@/store/profile'++import { $accentOverride, setAccentOverride } from './accent-override'+import { skinPref, ThemeProvider, useTheme } from './context'+import { persistAccent } from './persist-accent'+import { nousTheme } from './presets'+import { $userThemes } from './user-themes'++let theme: ReturnType<typeof useTheme>++function ThemeProbe() {+ theme = useTheme()++ return null+}++beforeEach(() => {+ window.localStorage.clear()+ $userThemes.set({})+ $activeGatewayProfile.set('default')+})++afterEach(() => {+ cleanup()+ setAccentOverride(null)+})++describe('persistAccent', () => {+ it('saves an accent as the profile theme and returns to Nous on null', () => {+ render(+ <ThemeProvider>+ <ThemeProbe />+ </ThemeProvider>+ )++ act(() => {+ setAccentOverride('#8a2be2')+ persistAccent('#8a2be2')+ })+ const saved = theme.themeName++ expect(saved).not.toBe(nousTheme.name)+ expect(skinPref.resolve('default')).toBe(saved)+ expect($accentOverride.get()).toBeNull()++ act(() => persistAccent('not a colour'))+ expect(theme.themeName).toBe(saved)++ act(() => persistAccent(null))+ expect(theme.themeName).toBe(nousTheme.name)+ expect(skinPref.resolve('default')).toBe(nousTheme.name)+ })+})diff --git a/apps/desktop/src/themes/persist-accent.ts b/apps/desktop/src/themes/persist-accent.tsnew file mode 100644index 00000000000..f58eacd8568--- /dev/null+++ b/apps/desktop/src/themes/persist-accent.ts@@ -0,0 +1,31 @@+import { setAccentOverride } from './accent-override'+import { normalizeHex } from './color'+import { nousTheme } from './presets'+import { requestTheme } from './request'+import { retintTheme } from './retint'+import { installUserTheme } from './user-themes'++/**+ * Save an accent as the live profile's theme: a Nous copy retinted to `accent`, installed as a user theme.+ * `null` or Nous blue returns to the built-in Nous theme. Clears the unsaved `$accentOverride` preview.+ * An unparseable colour changes nothing.+ */+export function persistAccent(accent: null | string): void {+ const hex = accent === null ? null : normalizeHex(accent)++ if (accent !== null && !hex) {+ return+ }++ const theme =+ hex === null || hex === normalizeHex(nousTheme.colors.primary)+ ? nousTheme+ : installUserTheme({+ ...retintTheme(nousTheme, hex),+ name: `nous-accent-${hex.slice(1)}`,+ label: `${nousTheme.label} · ${hex}`+ })++ requestTheme(theme.name)+ setAccentOverride(null)+}