The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
feat(desktop): live-preview themes from the palette highlight
ethernet40fccbf082a1
diff --git a/apps/desktop/src/app/command-palette/index.tsx b/apps/desktop/src/app/command-palette/index.tsxindex 4e0997309b1..dc0a1b6d5e6 100644--- a/apps/desktop/src/app/command-palette/index.tsx+++ b/apps/desktop/src/app/command-palette/index.tsx@@ -127,6 +127,11 @@ interface PaletteItem {label: string/** Label shown while ⌘/⌃ is held — previews the modifier-variant action. */modLabel?: string+ /**+ * Runs when the row becomes the cmdk highlight (arrow keys or hover). When+ * a row has no onHighlight, a highlight on it clears the live preview.+ */+ onHighlight?: () => void/*** When set, ⌘/⌃-select (or ⌘-Enter) opens a new tab and ⇧⌘-select pops a* window — matching sidebar session rows. Plain select stays in-place.@@ -549,7 +554,10 @@ function CommandPaletteBody({ onExited }: { onExited: () => void }) {const projectTree = useStore($projectTree)const dismissedAutoProjects = useStore($dismissedAutoProjectIds)const navigate = useNavigate()- const { availableThemes, mode, resolvedMode, setMode, setTheme, themeName } = useTheme()++ const { availableThemes, clearThemePreview, mode, previewTheme, resolvedMode, setMode, setTheme, themeName } =+ useTheme()+const [search, setSearch] = useState('')const [page, setPage] = useState<string | null>(null)const inputRef = useRef<HTMLInputElement>(null)@@ -1100,21 +1108,32 @@ function CommandPaletteBody({ onExited }: { onExited: () => void }) {// can't render the current light/dark mode, flip to the one it supports.result.push({heading: t.settings.appearance.themeTitle,- items: availableThemes.map(theme => ({- active: themeName === theme.name,- icon: Palette,- id: `search-theme-${theme.name}`,- keepOpen: true,- keywords: ['theme', 'appearance', 'color', 'skin', theme.name, theme.description],- label: theme.label,- run: () => {- setTheme(theme.name)-- if (!themeSupportsMode(theme.name, resolvedMode)) {- setMode(resolvedMode === 'dark' ? 'light' : 'dark')+ items: availableThemes.map(theme => {+ // Same mode fixup as run(): if a theme cannot render the current+ // light/dark, preview (and commit) in the one mode it supports.+ const previewMode = themeSupportsMode(theme.name, resolvedMode)+ ? resolvedMode+ : resolvedMode === 'dark'+ ? 'light'+ : 'dark'++ return {+ active: themeName === theme.name,+ icon: Palette,+ id: `search-theme-${theme.name}`,+ keepOpen: true,+ keywords: ['theme', 'appearance', 'color', 'skin', theme.name, theme.description],+ label: theme.label,+ onHighlight: () => previewTheme(theme.name, previewMode),+ run: () => {+ setTheme(theme.name)++ if (!themeSupportsMode(theme.name, resolvedMode)) {+ setMode(previewMode)+ }}}- }))+ })})// Switch light/dark/system directly (typing "dark" shouldn't require the@@ -1210,6 +1229,7 @@ function CommandPaletteBody({ onExited }: { onExited: () => void }) {goSession,mcpServers,mode,+ previewTheme,resolvedMode,search,sessions,@@ -1318,6 +1338,7 @@ function CommandPaletteBody({ onExited }: { onExited: () => void }) {keepOpen: true,keywords: ['theme', 'appearance', 'palette', groupMode, theme.label, theme.description ?? ''],label: theme.label,+ onHighlight: () => previewTheme(theme.name, groupMode),run: () => {setTheme(theme.name)setMode(groupMode)@@ -1365,7 +1386,7 @@ function CommandPaletteBody({ onExited }: { onExited: () => void }) {groups: settingsPageGroups}}),- [availableThemes, mode, resolvedMode, setMode, setTheme, settingsPageGroups, t, themeName]+ [availableThemes, mode, previewTheme, resolvedMode, setMode, setTheme, settingsPageGroups, t, themeName])const activePage = page ? subPages[page] : null@@ -1373,6 +1394,42 @@ function CommandPaletteBody({ onExited }: { onExited: () => void }) {const visibleGroups = useMemo(() => rankGroups(unrankedGroups, search), [unrankedGroups, search])const placeholder = activePage ? activePage.placeholder : t.commandCenter.searchPlaceholder+ // cmdk reports the highlighted row (arrows or hover) via the root's+ // onValueChange. Resolve it back to its PaletteItem so preview-capable rows+ // (the theme pickers) can paint live. Any other highlight clears the preview.+ const itemByValue = useMemo(() => {+ const map = new Map<string, PaletteItem>()++ for (const group of visibleGroups) {+ for (const item of group.items) {+ map.set(paletteValue(item), item)+ }+ }++ return map+ }, [visibleGroups])++ const handleHighlight = useCallback(+ (value: string) => {+ const item = itemByValue.get(value)++ if (item?.onHighlight) {+ item.onHighlight()+ } else {+ clearThemePreview()+ }+ },+ [clearThemePreview, itemByValue]+ )++ // A preview lives only while its rows show. If the page changes or the+ // palette retires, give the paint back to the committed appearance.+ useEffect(() => {+ clearThemePreview()+ }, [page, clearThemePreview])++ useEffect(() => clearThemePreview, [clearThemePreview])+const handleSelect = (item: PaletteItem) => {if (item.to) {setPage(item.to)@@ -1423,7 +1480,7 @@ function CommandPaletteBody({ onExited }: { onExited: () => void }) {}}><DialogPrimitive.Title className="sr-only">{t.commandCenter.paletteTitle}</DialogPrimitive.Title>- <Command className="bg-transparent" loop shouldFilter={false}>+ <Command className="bg-transparent" loop onValueChange={handleHighlight} shouldFilter={false}>{activePage && (<buttonclassName="flex w-full items-center gap-1.5 border-b border-border px-3 py-1.5 text-left text-xs text-muted-foreground transition-colors hover:text-foreground"diff --git a/apps/desktop/src/themes/context.test.tsx b/apps/desktop/src/themes/context.test.tsxindex 860bacfab08..2bc2011833c 100644--- a/apps/desktop/src/themes/context.test.tsx+++ b/apps/desktop/src/themes/context.test.tsx@@ -2,7 +2,8 @@ import { act, cleanup, render } from '@testing-library/react'import { afterEach, beforeEach, describe, expect, it } from 'vitest'import { __resetBackendSkinSync, ingestBackendSkin } from './backend-sync'-import { ThemeProvider } from './context'+import { skinPref, ThemeProvider, useTheme } from './context'+import { midnightTheme } from './presets'// The live-authoring loop: Hermes writes/edits one skin file and every surface// repaints. An in-place edit keeps the NAME — only the palette moves.@@ -68,3 +69,72 @@ describe('ThemeProvider ← backend skin sync', () => {expect(cssVar('--theme-foreground')).toBe('#ff9f0a')})})++describe('ThemeProvider highlight preview', () => {+ beforeEach(() => {+ window.localStorage.clear()+ __resetBackendSkinSync()+ })++ afterEach(cleanup)++ // Read the live context so the tests drive the real provider, not a mock.+ let ctx: ReturnType<typeof useTheme>++ function Probe() {+ ctx = useTheme()++ return null+ }++ const renderProbe = () =>+ render(+ <ThemeProvider>+ <Probe />+ </ThemeProvider>+ )++ it('paints the previewed theme without persisting it', () => {+ renderProbe()++ const committed = ctx.themeName++ act(() => ctx.previewTheme('midnight', 'dark'))++ expect(cssVar('--theme-foreground')).toBe(midnightTheme.colors.foreground)+ // The commit surface does not change. The context name and the stored+ // preference keep their values.+ expect(ctx.themeName).toBe(committed)+ expect(skinPref.resolve('default')).toBe(committed)+ })++ it('clearThemePreview repaints the committed appearance', () => {+ renderProbe()++ act(() => ctx.previewTheme('midnight', 'dark'))+ expect(cssVar('--theme-foreground')).toBe(midnightTheme.colors.foreground)++ act(() => ctx.clearThemePreview())+ expect(cssVar('--theme-foreground')).not.toBe(midnightTheme.colors.foreground)+ })++ it('a commit replaces the preview and persists', () => {+ renderProbe()++ act(() => ctx.previewTheme('midnight', 'dark'))+ act(() => ctx.setTheme('mono'))++ expect(ctx.themeName).toBe('mono')+ expect(skinPref.resolve('default')).toBe('mono')+ expect(cssVar('--theme-foreground')).not.toBe(midnightTheme.colors.foreground)+ })++ it('ignores a preview of an unknown theme', () => {+ renderProbe()++ const painted = cssVar('--theme-foreground')++ act(() => ctx.previewTheme('does-not-exist', 'dark'))+ expect(cssVar('--theme-foreground')).toBe(painted)+ })+})diff --git a/apps/desktop/src/themes/context.tsx b/apps/desktop/src/themes/context.tsxindex 20915938b76..2a575f8d489 100644--- a/apps/desktop/src/themes/context.tsx+++ b/apps/desktop/src/themes/context.tsx@@ -298,6 +298,13 @@ interface ThemeContextValue {availableThemes: Array<{ name: string; label: string; description: string }>setTheme: (name: string) => voidsetMode: (mode: ThemeMode) => void+ /**+ * Paint a theme with an explicit light/dark, without persistence. This is+ * the highlight preview for the palette. A commit (`setTheme`) or+ * `clearThemePreview` repaints the committed appearance.+ */+ previewTheme: (name: string, mode: 'light' | 'dark') => void+ clearThemePreview: () => void}const SKIN_LIST = BUILTIN_THEME_LIST.map(({ name, label, description }) => ({ name, label, description }))@@ -310,7 +317,9 @@ const ThemeContext = createContext<ThemeContextValue>({renderedMode: 'light',availableThemes: SKIN_LIST,setTheme: () => {},- setMode: () => {}+ setMode: () => {},+ previewTheme: () => {},+ clearThemePreview: () => {}})export function ThemeProvider({ children }: { children: ReactNode }) {@@ -378,19 +387,27 @@ export function ThemeProvider({ children }: { children: ReactNode }) {const systemDark = useMediaQuery('(prefers-color-scheme: dark)')const resolvedMode = resolveMode(mode, systemDark)+ // Transient highlight preview (palette theme picker). It is never+ // persisted. A commit or an explicit clear returns the paint to the+ // committed appearance.+ const [preview, setPreview] = useState<{ name: string; mode: 'light' | 'dark' } | null>(null)++ const paintedName = preview ? preview.name : themeName+ const paintedMode = preview ? preview.mode : resolvedMode+const activeTheme = useMemo(- () => deriveTheme(themeName, resolvedMode),+ () => deriveTheme(paintedName, paintedMode),// deriveTheme resolves its seed through the merged registry, so the theme// stores are its reactivity too — an in-place palette edit of the ACTIVE// skin (live theme authoring) must repaint, not just a name switch.// eslint-disable-next-line react-hooks/exhaustive-deps- [themeName, resolvedMode, userThemes, backendThemes, registryVersion]+ [paintedName, paintedMode, userThemes, backendThemes, registryVersion])// What actually gets painted (matches the `.dark` class applyTheme toggles).- const renderedMode = useMemo(() => renderedModeFor(activeTheme.colors, resolvedMode), [activeTheme, resolvedMode])+ const renderedMode = useMemo(() => renderedModeFor(activeTheme.colors, paintedMode), [activeTheme, paintedMode])- useEffect(() => applyTheme(activeTheme, resolvedMode), [activeTheme, resolvedMode])+ useEffect(() => applyTheme(activeTheme, paintedMode), [activeTheme, paintedMode])// Keep the native window appearance pinned to the app theme (vibrancy// material, titlebar, new-window pre-paint background).@@ -402,15 +419,23 @@ export function ThemeProvider({ children }: { children: ReactNode }) {const setTheme = useCallback((name: string) => {const next = normalizeSkin(name)+ setPreview(null)setThemeNameState(next)skinPref.assign(liveProfile(), next)}, [])const setMode = useCallback((next: ThemeMode) => {+ setPreview(null)setModeState(next)modePref.assign(liveProfile(), next)}, [])+ const previewTheme = useCallback((name: string, previewMode: 'light' | 'dark') => {+ setPreview(resolveTheme(name) ? { name, mode: previewMode } : null)+ }, [])++ const clearThemePreview = useCallback(() => setPreview(null), [])+// Drain a backend-driven skin switch (Hermes authoring/activating a skin from a// prompt, or `/skin` on another surface). setTheme persists it per profile, so// the choice sticks like any manual pick.@@ -427,8 +452,30 @@ export function ThemeProvider({ children }: { children: ReactNode }) {// (`appearance.toggleMode`) so it shows up in the hotkey map and is rebindable.const value = useMemo<ThemeContextValue>(- () => ({ theme: activeTheme, themeName, mode, resolvedMode, renderedMode, availableThemes, setTheme, setMode }),- [activeTheme, themeName, mode, resolvedMode, renderedMode, availableThemes, setTheme, setMode]+ () => ({+ theme: activeTheme,+ themeName,+ mode,+ resolvedMode,+ renderedMode,+ availableThemes,+ setTheme,+ setMode,+ previewTheme,+ clearThemePreview+ }),+ [+ activeTheme,+ themeName,+ mode,+ resolvedMode,+ renderedMode,+ availableThemes,+ setTheme,+ setMode,+ previewTheme,+ clearThemePreview+ ])return <ThemeContext.Provider value={value}>{children}</ThemeContext.Provider>