Skip to content

The agent that grows with you

fix(desktop): carry customCSS for built-in-named user skins

David Metcalfec5c27188fa79
diff --git a/apps/desktop/src/themes/backend-sync.ts b/apps/desktop/src/themes/backend-sync.ts
index cc00d6cdcd4..9260fd651c9 100644
--- a/apps/desktop/src/themes/backend-sync.ts
+++ b/apps/desktop/src/themes/backend-sync.ts
@@ -21,7 +21,8 @@ import { atom } from 'nanostores'
import { readJson, writeJson } from '@/lib/storage'
-import { BUILTIN_THEMES } from './presets'
+import { BUILTIN_THEMES, DEFAULT_SKIN_NAME } from './presets'
+
import { skinToDesktopTheme } from './skin'
import { type DesktopTheme, isValidTheme } from './types'
@@ -51,6 +52,13 @@ export const $backendThemes = atom<Record<string, DesktopTheme>>(typeof window =
$backendThemes.listen(themes => writeJson(BACKEND_THEMES_KEY, themes))
+/** Custom CSS carried by a user skin whose name is `default` or a desktop
+ * built-in. The palette policy keeps built-in palettes (a user `mono.yaml`
+ * must not shadow the desktop's hand-tuned mono), but the user's CSS is still
+ * the skin file's truth — keyed by the name the desktop resolves the skin
+ * under (`default` → `nous`). Merged into the active theme in context.tsx. */
+export const $backendCustomCSS = atom<Record<string, string>>({})
+
/** One-shot skin name the ThemeProvider should switch to (it clears this). */
export const $pendingSkinApply = atom<string | null>(null)
@@ -67,6 +75,7 @@ export function __resetBackendSkinSync(): void {
lastSynced = null
$backendThemes.set({})
$pendingSkinApply.set(null)
+ $backendCustomCSS.set({})
}
/**
@@ -100,6 +109,25 @@ export function ingestBackendSkin(skin: HermesSkin | undefined | null, { apply }
if (JSON.stringify(current[name]) !== JSON.stringify(theme)) {
$backendThemes.set({ ...current, [name]: theme })
}
+ } else {
+ // Built-in/default-named user skins never shadow the desktop palette, but
+ // their customCSS still belongs to the user's skin file (user skins take
+ // precedence over built-ins with the same name). Carry it separately so
+ // applyTheme can inject it on top of the built-in palette; dropping the
+ // field from the YAML clears the entry so stale rules don't linger.
+ const css = skin?.customCSS?.trim() ?? ''
+ const cssKey = name === 'default' ? DEFAULT_SKIN_NAME : name
+ const current = $backendCustomCSS.get()
+
+ if (css) {
+ if (current[cssKey] !== css) {
+ $backendCustomCSS.set({ ...current, [cssKey]: css })
+ }
+ } else if (current[cssKey]) {
+ const next = { ...current }
+ delete next[cssKey]
+ $backendCustomCSS.set(next)
+ }
}
if (!apply) {
diff --git a/apps/desktop/src/themes/context.tsx b/apps/desktop/src/themes/context.tsx
index 86de74fa750..4a8143f0f20 100644
--- a/apps/desktop/src/themes/context.tsx
+++ b/apps/desktop/src/themes/context.tsx
@@ -21,9 +21,10 @@ import { $connection } from '@/store/session'
import { setAppearance } from '@/store/translucency'
import { $accentOverride } from './accent-override'
-import { $backendThemes, $pendingSkinApply, localDisplaySkinName, localDisplaySkinProfile } from './backend-sync'
+import { $backendCustomCSS, $backendThemes, $pendingSkinApply, localDisplaySkinName, localDisplaySkinProfile } from './backend-sync'
import { $chatFontFamily, resolveChatFontFamily } from './chat-font'
import { harmonize, readableInk } from './color'
+
import { BUILTIN_THEME_LIST, DEFAULT_SKIN_NAME, DEFAULT_TYPOGRAPHY, nousTheme } from './presets'
import { retintTheme } from './retint'
import type { DesktopTheme, DesktopThemeColors } from './types'
@@ -167,7 +168,12 @@ function deriveTheme(skinName: string, mode: 'light' | 'dark'): DesktopTheme {
name: `${skinName}-${mode}`,
label: `${seed.label} ${mode === 'light' ? 'Light' : 'Dark'}`,
description: `${seed.label} ${mode} palette`,
- colors: getBaseColors(skinName, mode)
+ colors: getBaseColors(skinName, mode),
+ // A backend skin named `default`/`mono`/… keeps the desktop's own palette
+ // (never shadowed — see ingestBackendSkin), but its customCSS is carried
+ // separately in $backendCustomCSS. The seed's own customCSS (non-built-in
+ // backend skins) wins when both exist.
+ customCSS: seed.customCSS ?? $backendCustomCSS.get()[skinName]
}
}
@@ -416,6 +422,7 @@ export function ThemeProvider({ children }: { children: ReactNode }) {
// grid, and `/skin` without a reload.
const userThemes = useStore($userThemes)
const backendThemes = useStore($backendThemes)
+ const backendCustomCSS = useStore($backendCustomCSS)
const registryVersion = useStore($registryVersion)
const availableThemes = useMemo(
@@ -491,9 +498,10 @@ export function ThemeProvider({ children }: { children: ReactNode }) {
() => 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.
+ // skin (live theme authoring) must repaint, not just a name switch. The
+ // backend CSS store matters the same way for built-in-named user skins.
// eslint-disable-next-line react-hooks/exhaustive-deps
- [paintedName, paintedMode, userThemes, backendThemes, registryVersion]
+ [paintedName, paintedMode, userThemes, backendThemes, backendCustomCSS, registryVersion]
)
// Dev-only accent retint. `null` (always, in production) returns the theme