The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): pass skin customCSS through to desktop theme context
David Metcalfec60ba751994b
diff --git a/apps/desktop/src/themes/context.tsx b/apps/desktop/src/themes/context.tsxindex f9f2ed1a651..86de74fa750 100644--- a/apps/desktop/src/themes/context.tsx+++ b/apps/desktop/src/themes/context.tsx@@ -316,6 +316,28 @@ function applyTheme(theme: DesktopTheme, mode: 'light' | 'dark', chatFontFamilydocument.head.appendChild(link)INJECTED_FONT_URLS.add(typo.fontUrl)}++ // Inject / clear customCSS from the skin (mirrors web/src/themes/context.tsx).+ // A theme carries the optional customCSS field; we inject/remove a single+ // <style> tag to keep the DOM clean and avoid stale rules on switch.+ const cssId = 'hermes-desktop-custom-css'+ let cssEl = document.getElementById(cssId) as HTMLStyleElement | null+ const customCSS = theme.customCSS?.trim()++ if (!customCSS) {+ if (cssEl) {+ cssEl.remove()+ }+ } else {+ if (!cssEl) {+ cssEl = document.createElement('style')+ cssEl.id = cssId+ cssEl.dataset.hermesSkinCSS = 'true'+ document.head.appendChild(cssEl)+ }++ cssEl.textContent = customCSS+ }}// Pin Electron's nativeTheme to the app's mode so the NATIVE window chromediff --git a/apps/desktop/src/themes/skin.ts b/apps/desktop/src/themes/skin.tsindex abfaebea0eb..db407972876 100644--- a/apps/desktop/src/themes/skin.ts+++ b/apps/desktop/src/themes/skin.ts@@ -113,6 +113,9 @@ export function skinToDesktopTheme(skin: HermesSkin): DesktopTheme | null {// Single palette in both slots: a skin is one-mode, so the light/dark toggle// shouldn't invert it. renderedModeFor still paints `.dark` from luminance.colors: palette,- darkColors: palette+ darkColors: palette,+ // Pass through raw CSS so the desktop can inject it as a scoped <style>+ // tag — users put CSS in their skin YAML instead of hacking app.asar.+ customCSS: skin.customCSS?.trim() || undefined,}}diff --git a/apps/desktop/src/themes/types.ts b/apps/desktop/src/themes/types.tsindex a8e16d71375..08e187468fd 100644--- a/apps/desktop/src/themes/types.ts+++ b/apps/desktop/src/themes/types.ts@@ -98,6 +98,10 @@ export interface DesktopTheme {terminal?: DesktopTerminalPalette/** Dark-variant terminal ANSI palette. Falls back to `terminal`. */darkTerminal?: DesktopTerminalPalette+ /** Raw CSS injected as a scoped <style> tag on theme apply.+ * Persists across updates because it lives in ~/.hermes/skins/,+ * not inside app.asar. */+ customCSS?: string}// The minimal set of color keys a stored theme must carry to be usable. We keepdiff --git a/apps/shared/src/skin.ts b/apps/shared/src/skin.tsindex d5c600da43f..fe120c2b599 100644--- a/apps/shared/src/skin.ts+++ b/apps/shared/src/skin.ts@@ -107,4 +107,8 @@ export interface HermesSkin {banner_hero?: stringtool_prefix?: stringhelp_header?: string+ /** Raw CSS injected as a scoped <style> tag on theme apply.+ * Persists across updates because it lives in ~/.hermes/skins/,+ * not inside app.asar. Clipped to 32 KiB by the Python normaliser. */+ customCSS?: string}diff --git a/hermes_cli/skin_engine.py b/hermes_cli/skin_engine.pyindex 60810455dde..b859fcc8285 100644--- a/hermes_cli/skin_engine.py+++ b/hermes_cli/skin_engine.py@@ -27,6 +27,7 @@ class SkinConfig:tool_emojis: Dict[str, str] = field(default_factory=dict) # per-tool emoji overridesbanner_logo: str = "" # Rich-markup ASCII art logo (replaces HERMES_AGENT_LOGO)banner_hero: str = "" # Rich-markup hero art (replaces HERMES_CADUCEUS)+ custom_css: str = "" # Raw CSS injected as a <style> tag on the desktop GUI (32 KiB cap)def get_color(self, key: str, fallback: str = "") -> str:return self.colors.get(key, fallback)@@ -403,7 +404,8 @@ def _build_skin_config(data: Dict[str, Any]) -> SkinConfig:spinner=merged("spinner"), branding=merged("branding"),tool_prefix=data.get("tool_prefix", default.get("tool_prefix", "┊")),tool_emojis=section("tool_emojis"), banner_logo=data.get("banner_logo", ""),- banner_hero=data.get("banner_hero", ""))+ banner_hero=data.get("banner_hero", ""),+ custom_css=str(data.get("customCSS", "")).strip()[:32768])def list_skins() -> List[Dict[str, str]]:diff --git a/tui_gateway/server.py b/tui_gateway/server.pyindex 26f133a60b0..e263518d57d 100644--- a/tui_gateway/server.py+++ b/tui_gateway/server.py@@ -1428,6 +1428,105 @@ def _env_model_seed() -> str:return (os.environ.get("HERMES_MODEL", "") or os.environ.get("HERMES_INFERENCE_MODEL", "")).strip()++def resolve_skin() -> dict:+ try:+ from hermes_cli.skin_engine import init_skin_from_config, get_active_skin++ init_skin_from_config(_load_cfg())+ skin = get_active_skin()+ return {+ "name": skin.name,+ "colors": skin.colors,+ # Paired palettes: the TUI detects the terminal's polarity and+ # prefers the matching hand-tuned block over adapting `colors`.+ "light_colors": skin.light_colors,+ "dark_colors": skin.dark_colors,+ "branding": skin.branding,+ "banner_logo": skin.banner_logo,+ "banner_hero": skin.banner_hero,+ "tool_prefix": skin.tool_prefix,+ "help_header": (skin.branding or {}).get("help_header", ""),+ "customCSS": skin.custom_css,+ }+ except Exception:+ return {}+++# Signature of the last skin broadcast: (name, active user-file mtime). Lets the+# per-tool reconcile fire ``skin.changed`` on any real move — a name switch OR a+# live color edit to the active skin — and nothing else.+_last_skin_sig: tuple[str, float | None] | None = None+++def _skin_sig() -> tuple[str, float | None]:+ """(active skin name, its user-file mtime). Built-ins have no file, so only+ their name moves; a user skin's mtime lets an in-place color edit repaint too."""+ name = str((_load_cfg().get("display") or {}).get("skin") or "default")+ override = get_hermes_home_override()+ home = override if isinstance(override, str) and override else _hermes_home+ try:+ mtime: float | None = (Path(home) / "skins" / f"{name}.yaml").stat().st_mtime+ except OSError:+ mtime = None+ return name, mtime+++def _note_skin_broadcast() -> None:+ """Sync the reconcile baseline after the /skin RPC emits, so the per-tool+ check doesn't re-broadcast the skin /skin just applied."""+ global _last_skin_sig+ try:+ _last_skin_sig = _skin_sig()+ except Exception:+ pass+++def _broadcast_skin_if_changed() -> None:+ """Emit ``skin.changed`` when the active skin moved — the agent switched it+ (``hermes config set display.skin``) OR edited the active skin's colors in+ place ("I don't like that coral" → tweak the YAML).++ Routes through the SAME live path as ``/skin`` so every surface (TUI + desktop)+ repaints, no slash command. The signature check is a dict lookup + one stat,+ so polling it is ~free.+ """+ global _last_skin_sig+ try:+ sig = _skin_sig()+ except Exception:+ return+ if sig == _last_skin_sig:+ return+ _last_skin_sig = sig+ try:+ _broadcast_global_event("skin.changed", resolve_skin())+ except Exception:+ pass+++_skin_watcher_started = False+++def _ensure_skin_watcher() -> None:+ """Poll the config for skin changes and broadcast ``skin.changed`` — so a skin+ Hermes activates (``hermes config set display.skin``) or recolors goes live on+ every surface within ~half a second, on its own, with no tool-hook or slash+ command in the loop. Idempotent; started at gateway.ready."""+ global _skin_watcher_started+ if _skin_watcher_started:+ return+ _skin_watcher_started = True+ _note_skin_broadcast() # seed the baseline so only a real change repaints++ def _loop() -> None:+ while True:+ time.sleep(0.5)+ _broadcast_skin_if_changed()++ threading.Thread(target=_loop, name="hermes-skin-watcher", daemon=True).start()++def _resolve_model() -> str:if env := _env_model_seed():return env