From 91e2d261334f1355593128afdaf7a653b15cf19d Mon Sep 17 00:00:00 2001 From: iris Date: Sun, 22 Nov 2026 16:43:49 +0100 Subject: [PATCH] frontend: remove the stylix overlay and add hyperhive and Catppuccin light and dark themes --- docs/4-implementation/networking/gateway.md | 6 +- docs/4-implementation/web-ui/css-vars.md | 92 ++--- docs/4-implementation/web-ui/swarm-ui.md | 7 + docs/5-project/web-ui/design-guide.md | 17 +- frontend/packages/agent/src/colors.css | 4 +- frontend/packages/dashboard/src/colors.css | 4 +- frontend/packages/shared/package.json | 1 + frontend/packages/shared/src/badge/Badge.css | 8 +- frontend/packages/shared/src/colors.css | 323 +++++++++++------- .../shared/src/settings/SettingsMenu.tsx | 16 +- .../shared/src/settings/theme-apply.ts | 58 ++-- .../packages/shared/src/settings/themes.ts | 54 +++ frontend/packages/swarm-ui/build.mjs | 7 +- frontend/packages/swarm-ui/src/colors.css | 4 +- frontend/packages/swarm-ui/src/sw.js | 2 +- frontend/packages/swarm-ui/src/theme-boot.js | 19 +- .../swarm-ui/test/theme-boot.test.mjs | 49 ++- .../packages/swarm-ui/test/themes.test.mjs | 36 ++ nix/host-modules/hive-c0re/default.nix | 4 +- nix/host-modules/hive-c0re/environment.nix | 2 +- nix/host-modules/hive-c0re/options.nix | 4 +- nix/host-modules/hive-c0re/theme.nix | 58 ---- nix/host-modules/hive-c0re/vhosts.nix | 2 +- nix/host-modules/stylix-theme.nix | 59 ---- nix/host-modules/swarm-ui.nix | 52 +-- nix/module-eval/core-toggle.nix | 1 - nix/packages/swagger-ui-theme.nix | 2 +- swagger-ui-theme/hyperhive-theme.css | 4 +- swagger-ui-theme/index.html | 4 +- 29 files changed, 486 insertions(+), 413 deletions(-) create mode 100644 frontend/packages/shared/src/settings/themes.ts create mode 100644 frontend/packages/swarm-ui/test/themes.test.mjs delete mode 100644 nix/host-modules/hive-c0re/theme.nix delete mode 100644 nix/host-modules/stylix-theme.nix diff --git a/docs/4-implementation/networking/gateway.md b/docs/4-implementation/networking/gateway.md index f082e2cc2..c23ea2cd0 100644 --- a/docs/4-implementation/networking/gateway.md +++ b/docs/4-implementation/networking/gateway.md @@ -28,7 +28,7 @@ A service module declares its vhost as `services.hyperhive.gateway.vhosts. | URL | upstream | when | | --- | --- | --- | -| `.hives./` | dashboard dist (static, from `servedFrontend`), behind authelia | always | +| `.hives./` | dashboard dist (static, from `frontend`), behind authelia | always | | `.hives./api/` | hive-c0re (`7000`), behind authelia | always | | `.hives./health/` | hive-c0re (`7000`) | always | | `.hives./api/docs/` | themed Swagger UI dist (static), behind authelia | always | @@ -278,7 +278,7 @@ hive-c0re serves exactly two prefixes, so the dashboard routes by **path** — d - `location /api/` → hive-c0re (`7000`): all dashboard data, actions, and the SSE stream (`/api/dashboard/stream`). `proxy_buffering off` and a 1d read timeout keep the stream live. - `location /health/` → hive-c0re: liveness and readiness. -- `location /` → the dashboard dist (from the `servedFrontend` nix-store path) with `try_files $uri /index.html`. +- `location /` → the dashboard dist (from the `frontend` nix-store path) with `try_files $uri /index.html`. The gateway static-serves the dist while hive-c0re stays API-only, so a frontend-only change doesn't restart the core daemon. A new top-level c0re route prefix needs a matching `location` on the dashboard vhost (`hive-c0re/vhosts.nix`). @@ -343,7 +343,7 @@ c0re process never leaves a partial or unparseable file behind. ### Per-agent static frontend split hive-c0re's environment sets `HIVE_AGENT_FRONTEND_DIR` to the `agent/` -subdirectory of `services.hyperhive.deploy.hive-controller.servedFrontend`. +subdirectory of `services.hyperhive.deploy.hive-controller.frontend`. The nginx include generator (`gateway_nginx::write`) reads this variable and, when set, emits split location blocks per agent instead of a single proxy block. diff --git a/docs/4-implementation/web-ui/css-vars.md b/docs/4-implementation/web-ui/css-vars.md index e7df3896b..0164c34bf 100644 --- a/docs/4-implementation/web-ui/css-vars.md +++ b/docs/4-implementation/web-ui/css-vars.md @@ -1,15 +1,13 @@ # CSS custom properties (theme variables) -Colour variables live in **two standalone stylesheets**, split so a theme -swap touches only the first: +Colour variables live in **two standalone stylesheets**, split so a new theme +touches only the first: 1. **`colors.css`** — the 16 `--base00`…`--base0F` base16 slots. **This is - the entire theme swap contract.** A generator (for example one fed a stylix - base16 scheme, which is natively base00–base0F) replaces _only this - file_. + the whole theme contract.** A theme is 16 colours here and nothing else. 2. **`theme.css`** — the semantic layer: `--bg`, `--fg`, `--purple`, … _derived_ from the base16 slots (`--bg: var(--base00)` etc.). This is - what the app references and it **never changes on a swap**. + what the app references and it **doesn't change per theme**. Both files live in `frontend/packages/shared/src/`. Per-page stylesheets (`common.css`, `dashboard.css`, `agent.css`) @@ -17,23 +15,35 @@ reference the **semantic** names and must **not** redeclare them or reach for the raw `--baseNN` slots directly. (`base.css` holds only the shared `body` typography — it references the palette but no longer defines it.) -`colors.css` declares each palette's 16 hex values exactly once — -`--mocha-baseNN` (dark, Catppuccin Mocha) and `--latte-baseNN` (light, -Catppuccin-Latte-derived; `base08`-`base0F` run darker than stock -Latte to actually clear WCAG AA against how this app uses them — real -contrast failures found in review, see the comment above those -declarations in `colors.css` for the numbers and why). Everything else -in the file just points the active `--baseNN` slot at one of those two -raw palettes via `var()`, never a second copy of a hex value: an -unconditional default (Mocha), a row gated behind `@media -(prefers-color-scheme: light)` (Latte, the OS/browser-level default), -and two `:root[data-theme='light'|'dark']` blocks a per-user override -sets (swarm-ui's `SettingsMenu`) — an attribute selector always -outranks the plain `:root` inside the media query, so the override wins -regardless of the actual OS preference. Absent an override, the media -query decides; that's what a client with no more specific theme -decision gets (see "Theme swapping" below for how a stylix deployment -supersedes all of this at once). +`colors.css` declares each theme's 16 hex values exactly once, as +`---baseNN`, for five themes that are each light or dark: + +| Theme | Id | Scheme | Palette | +| ---------------------- | ------------------------ | ------ | ------------------------------------------------------------------ | +| hyperhive light | `hyperhive-light` | light | Latte's neutrals, accents darker than stock to clear WCAG AA | +| hyperhive dark | `hyperhive-dark` | dark | Mocha's neutrals, the light accents' hues lifted to suit a dark bg | +| catppuccin latte mauve | `catppuccin-latte-mauve` | light | Catppuccin Latte as published | +| catppuccin mocha mauve | `catppuccin-mocha-mauve` | dark | Catppuccin Mocha as published | +| catppuccin mocha mara | `catppuccin-mocha-mara` | dark | Mocha with the accents mara picked | + +The hyperhive light accents (`base08`-`base0F`) run darker than stock Latte +because the stock ones fail contrast as badge text and as plain text; the +comment above them in `colors.css` has the numbers. The hyperhive dark +accents keep those hues and saturations and raise the lightness until each +clears 6:1 against `base02`. + +Everything else in the file points the active `--baseNN` slots at one of +those raw palettes via `var()`, never a second copy of a hex value: an +unconditional default (hyperhive dark), a block gated behind +`@media (prefers-color-scheme: light)` (hyperhive light, the OS-level +default), and one `:root[data-theme='']` block per theme, which the +settings menu's theme select sets. An attribute selector always outranks +the plain `:root` inside the media query, so a picked theme wins whatever +the OS prefers. The select's **auto** choice sets no `data-theme`, so the +media query decides. +`frontend/packages/shared/src/settings/themes.ts` lists the ids, labels and +schemes; adding a theme is one entry there and one palette plus one block in +`colors.css`. Both are deliberately standalone, not `@import`ed into the page bundles: each package re-exports them (`src/{colors,theme}.css` → @@ -139,26 +149,22 @@ color: var(--amber); /* warning / running */ color: var(--green); /* ok */ ``` -## Theme swapping — the base16 contract +## Themes — the base16 contract -**The swap interface is `colors.css` — the 16 base16 slots, not the -semantic names.** A theme generator (for example one reading a stylix base16 -scheme) overrides only `colors.css`; the semantic layer in `theme.css` -derives everything else, so the whole UI re-themes with nothing else to -template or regenerate. The base16 slot → semantic mapping is _internal_ -to `theme.css` (the "Derives from" column above) — a generator never -needs to know the semantic var names, and `theme.css` + the page bundles stay -untouched. +**The theme interface is `colors.css` — the 16 base16 slots, not the +semantic names.** The semantic layer in `theme.css` derives everything +else, so a new theme needs nothing else to template or regenerate. The +base16 slot → semantic mapping is _internal_ to `theme.css` (the "Derives +from" column above): a theme never needs the semantic var names, and +`theme.css` and the page bundles stay untouched. -**Two palettes, one contract.** `colors.css` ships both a dark default -(Catppuccin Mocha, unconditional) and a light default (Catppuccin Latte, -behind `@media (prefers-color-scheme: light)`), plus a per-user override -path (`:root[data-theme]`) — a theme generator that overrides the file -wholesale (for example the stylix path, which writes a single unconditional -`:root` block with no media query, no `--mocha-*`/`--latte-*` vars, no -`[data-theme]` blocks) supersedes all of it at once, same as today. +**Five palettes, one contract.** `colors.css` ships the five themes in the +table above, each light or dark, with hyperhive dark as the unconditional +default and hyperhive light behind `@media (prefers-color-scheme: light)`. +Each theme's block also sets `color-scheme` and the contrast shares of +`theme.css` (`--muted-share` and friends) for its scheme. -`colors.css` base16 slot defaults (Catppuccin Mocha, dark default): +`colors.css` base16 slots in the dark palettes (the values are Catppuccin Mocha's; hyperhive dark differs in `base08`-`base0F`): | Slot | Default | Standard base16 role | Mapped to | | -------- | --------- | -------------------- | ---------------------------------------------------------- | @@ -187,10 +193,8 @@ Notes for theme authors: `--muted`/`--subtext0` = `base05`↔`base00` blends). They still track a swap automatically; no generator action needed. - A standard Catppuccin base16 scheme uses **teal** for `base0C`; - `colors.css` defaults it to **sky** (`#89dceb`) to preserve the historical - accent. A - stylix Catppuccin scheme will shift `--cyan` to teal — that's the - operator's chosen scheme, working as intended. + `colors.css` uses **sky** (`#89dceb` in Mocha) to keep the historical + accent. - `base04`/`base06`/`base07` aren't consumed by a semantic var today; they're kept at their standard values so the 16-slot contract is complete (a partial scheme override still works). diff --git a/docs/4-implementation/web-ui/swarm-ui.md b/docs/4-implementation/web-ui/swarm-ui.md index 2e8673353..99bbf168d 100644 --- a/docs/4-implementation/web-ui/swarm-ui.md +++ b/docs/4-implementation/web-ui/swarm-ui.md @@ -240,6 +240,13 @@ stream with an error status, the browser gives up and the badge reads **disconnected**. The **reconnect** button beside it opens the stream again, and the stream replays the rows. The message log card works the same way. +The settings menu in the header has a **theme** select: **auto**, which follows +the OS and picks hyperhive light or hyperhive dark, then hyperhive light, +hyperhive dark, catppuccin latte mauve, catppuccin mocha mauve and catppuccin +mocha mara. Each theme is light or +dark, and a pick beats the OS preference. The browser remembers the choice, and +hyperhive dark applies until a user picks one. The hive dashboard's menu has the same select. + The settings menu in the header has a **hide developer details** toggle. It drops the muted debug rows (coalesced ticks, harness chatter) from every terminal, the preview and the tabs, and rows already on screen hide or show as diff --git a/docs/5-project/web-ui/design-guide.md b/docs/5-project/web-ui/design-guide.md index 82ef74ca8..4221624fe 100644 --- a/docs/5-project/web-ui/design-guide.md +++ b/docs/5-project/web-ui/design-guide.md @@ -39,7 +39,7 @@ repeated here. generation, mainly for shape/elevation ideas. Colour is dynamic too — autoderived shades (mixing, lighter/darker) are fair game, same as Material's own approach — but every derived colour still traces back - to the base16/stylix contract below, never an independent source. + to the base16 contract below, never an independent source. ## Motion @@ -64,17 +64,16 @@ The mechanical contract (base16 slots, semantic vars, what a page's CSS is and isn't allowed to reference) lives in `docs/4-implementation/web-ui/css-vars.md` — read that for the how. This section is the _policy_ layered on top: -- **User-theming compatible by construction.** The whole point of the - base16/`colors.css` swap contract is that a user's own theme (stylix - today) takes over with zero swarm-ui code changes. Don't build +- **Theme-agnostic by construction.** The whole point of the + base16/`colors.css` contract is that a new theme is 16 colours with zero + swarm-ui code changes. Don't build anything that assumes a specific palette's exact colours (contrast ratios, "this accent is always purple") beyond what the semantic var names promise. -- **stylix wins outright when it's active, no in-between state.** When - an operator has stylix supplying swarm-ui's palette, that palette is - authoritative — swarm-ui's own light/dark preference (below) doesn't - override it. This is a deliberate simplification, not a limitation to - fix: a stylix-using operator has already made their choice. +- **Every theme is light or dark.** A theme declares its scheme, so the + browser's own controls, scrollbars and dialog backdrops follow it. The + user's pick wins over the OS preference; **auto** follows the OS and + chooses hyperhive light or hyperhive dark. - **Light theme is accessibility, not a cosmetic extra.** Some people need light for contrast/low-vision reasons, others need dark for photosensitivity — there's no universally correct default. The OS diff --git a/frontend/packages/agent/src/colors.css b/frontend/packages/agent/src/colors.css index ef910c147..f3935e6d9 100644 --- a/frontend/packages/agent/src/colors.css +++ b/frontend/packages/agent/src/colors.css @@ -1,6 +1,6 @@ /* Standalone base16 palette — re-exports the shared base16 slots so esbuild emits its own `dist/static/colors.css`, linked first by every - agent page (before theme.css). This is the theme swap contract: a - stylix-generated variant replaces only this file. See + agent page (before theme.css). This is the theme contract: the + themes' palettes live in this one file. See @hive/shared/colors.css + docs/4-implementation/web-ui/css-vars.md. */ @import "@hive/shared/colors.css"; diff --git a/frontend/packages/dashboard/src/colors.css b/frontend/packages/dashboard/src/colors.css index 3c94c1cdd..d3f62d136 100644 --- a/frontend/packages/dashboard/src/colors.css +++ b/frontend/packages/dashboard/src/colors.css @@ -1,6 +1,6 @@ /* Standalone base16 palette — re-exports the shared base16 slots so esbuild emits its own `dist/static/colors.css`, linked first by every - dashboard page (before theme.css). This is the theme swap contract: a - stylix-generated variant replaces only this file. See + dashboard page (before theme.css). This is the theme contract: the + themes' palettes live in this one file. See @hive/shared/colors.css + docs/4-implementation/web-ui/css-vars.md. */ @import "@hive/shared/colors.css"; diff --git a/frontend/packages/shared/package.json b/frontend/packages/shared/package.json index b1c127e5b..5f15047bf 100644 --- a/frontend/packages/shared/package.json +++ b/frontend/packages/shared/package.json @@ -53,6 +53,7 @@ "./icons.js": "./src/icons.tsx", "./settings-storage.js": "./src/settings/settings-storage.ts", "./theme-apply.js": "./src/settings/theme-apply.ts", + "./themes.js": "./src/settings/themes.ts", "./motion-apply.js": "./src/settings/motion-apply.ts", "./settings-menu.js": "./src/settings/SettingsMenu.tsx", "./hide-debug-setting.js": "./src/settings/HideDebugSetting.tsx", diff --git a/frontend/packages/shared/src/badge/Badge.css b/frontend/packages/shared/src/badge/Badge.css index 8b80b14a7..9bf85f89f 100644 --- a/frontend/packages/shared/src/badge/Badge.css +++ b/frontend/packages/shared/src/badge/Badge.css @@ -77,11 +77,11 @@ /* Fixes badge with emoji having different size. */ line-height: 1; } -/* Blended with `--fg`, not the raw accent — a stylix-fed scheme can pick +/* Blended with `--fg`, not the raw accent — a theme can pick any hue/lightness for `--green`/`--amber`/etc., and nothing guarantees - an arbitrary accent clears 4.5:1 against `--purple-dim` the way the two - bundled palettes were hand-tuned to (see colors.css's comment above - `--latte-base08..0F`). `--fg` is the one color the base16 contract + an arbitrary accent clears 4.5:1 against `--purple-dim` the way the + hyperhive palettes were hand-tuned to (see colors.css's comment above + `--hh-light-base08..0F`). `--fg` is the one color the base16 contract already guarantees is legible on every surface in the theme, so mixing toward it gives every accent a contrast floor without trying to compute/fix an operator's own theme (mara, on the low-contrast-badges diff --git a/frontend/packages/shared/src/colors.css b/frontend/packages/shared/src/colors.css index cea5f08b6..27152eabf 100644 --- a/frontend/packages/shared/src/colors.css +++ b/frontend/packages/shared/src/colors.css @@ -1,25 +1,83 @@ /* base16 palette — THE THEME CONTRACT. - These 16 slots are the entire swap interface. A theme generator (e.g. - one fed a stylix base16 scheme, which is natively base00–base0F) - overrides *only this file*; `theme.css` derives every semantic var - (`--bg`, `--purple`, …) from these slots, so the whole UI re-themes - with nothing else to regenerate. + These 16 slots are the entire palette interface: `theme.css` derives every + semantic var (`--bg`, `--purple`, …) from them, so a theme is 16 colours and + nothing else to write. See docs/4-implementation/web-ui/css-vars.md. - Kept as its own standalone stylesheet (not @import-ed into theme.css) - so a swap replaces just this file — `theme.css` and the page bundles - stay untouched. Every page links this BEFORE `theme.css`. See - docs/4-implementation/web-ui/css-vars.md. + Kept as its own standalone stylesheet (not @import-ed into theme.css). Every + page links this BEFORE `theme.css`. - Two raw palettes, one declaration each — `--mocha-baseNN` (dark, - Catppuccin Mocha) and `--latte-baseNN` (light, Catppuccin-Latte- - derived; base08-0F are darkened from stock Latte, see the comment - above those declarations for why). The four blocks below this one - never restate a hex value — each just points the active `--baseNN` - slot at one of these two raw palettes via `var()`, so "which theme is - active" and "what a theme's colours are" can't drift apart the way a - hand-duplicated copy could. */ + Five themes, each light or dark, declared once as raw `---baseNN` + palettes: `hh-light` and `hh-dark` (the hyperhive themes: Catppuccin's + neutrals with the hyperhive accents), `latte` and `mocha` (Catppuccin + Latte and Mocha as published, mauve accent), and `mara` (Mocha with the + accents mara picked). The blocks below the palettes + never restate a hex value: each points the active `--baseNN` slots at one + raw palette via `var()`, so "which theme is active" and "what a theme's + colours are" can't drift apart. The registry of theme ids and labels is + `settings/themes.ts`; `data-theme` on (set by `settings/theme-apply.ts`) + names the active one. With none set, hyperhive dark applies, and hyperhive + light under a light OS preference ("auto"). */ :root { + --hh-light-base00: #eff1f5; /* default bg */ + --hh-light-base01: #e6e9ef; /* lighter bg (elevated surfaces) */ + --hh-light-base02: #ccd0da; /* selection / surface — borders */ + --hh-light-base03: #bcc0cc; /* comments / dim surface */ + --hh-light-base04: #acb0be; /* dark foreground */ + --hh-light-base05: #4c4f69; /* default foreground */ + --hh-light-base06: #dc8a78; /* light foreground */ + --hh-light-base07: #7287fd; /* lightest */ + --hh-light-base08: #9c0b2a; /* red */ + --hh-light-base09: #883201; /* orange / peach */ + --hh-light-base0A: #6d450e; /* yellow */ + --hh-light-base0B: #235818; /* green */ + --hh-light-base0C: #025374; /* cyan */ + --hh-light-base0D: #0843b8; /* blue */ + --hh-light-base0E: #6311ce; /* magenta / mauve */ + --hh-light-base0F: #8f166e; /* extra accent — pink */ + /* base08-0F: darkened from stock Catppuccin Latte's accents (same hue and + saturation, lower HSL lightness). The stock ones fail as badge text on + base03 (1.4:1 to 3:1, need 4.5:1) and as plain text on base00 (2.3:1 to + 4.8:1): Latte's accents are tuned for its near-white base, not a mid-gray + surface. `latte` below keeps the stock hexes. */ + + --hh-dark-base00: #1e1e2e; /* default bg */ + --hh-dark-base01: #181825; /* lighter bg (elevated surfaces) */ + --hh-dark-base02: #313244; /* selection / surface — borders */ + --hh-dark-base03: #45475a; /* comments / dim surface */ + --hh-dark-base04: #585b70; /* dark foreground */ + --hh-dark-base05: #cdd6f4; /* default foreground */ + --hh-dark-base06: #f5e0dc; /* light foreground */ + --hh-dark-base07: #b4befe; /* lightest */ + --hh-dark-base08: #f89db1; /* red */ + --hh-dark-base09: #fe9f6a; /* orange / peach */ + --hh-dark-base0A: #e9ab56; /* yellow */ + --hh-dark-base0B: #61ce4b; /* green */ + --hh-dark-base0C: #39c3fc; /* cyan */ + --hh-dark-base0D: #96b8fa; /* blue */ + --hh-dark-base0E: #cba8f8; /* magenta / mauve */ + --hh-dark-base0F: #f09cd9; /* extra accent — pink */ + /* hh-dark's base00-07 are Mocha's. base08-0F keep the hue and saturation of + hh-light's accents at the HSL lightness where each reaches a 6.2:1 contrast + against base02, about what Mocha's own accents have. */ + + --latte-base00: #eff1f5; /* default bg */ + --latte-base01: #e6e9ef; /* lighter bg (elevated surfaces) */ + --latte-base02: #ccd0da; /* selection / surface — borders */ + --latte-base03: #bcc0cc; /* comments / dim surface */ + --latte-base04: #acb0be; /* dark foreground */ + --latte-base05: #4c4f69; /* default foreground */ + --latte-base06: #dc8a78; /* light foreground */ + --latte-base07: #7287fd; /* lightest */ + --latte-base08: #d20f39; /* red */ + --latte-base09: #fe640b; /* orange / peach */ + --latte-base0A: #df8e1d; /* yellow */ + --latte-base0B: #40a02b; /* green */ + --latte-base0C: #04a5e5; /* cyan */ + --latte-base0D: #1e66f5; /* blue */ + --latte-base0E: #8839ef; /* magenta / mauve */ + --latte-base0F: #ea76cb; /* extra accent — pink */ + --mocha-base00: #1e1e2e; /* default bg */ --mocha-base01: #181825; /* lighter bg (elevated surfaces) */ --mocha-base02: #313244; /* selection / surface — borders */ @@ -32,128 +90,118 @@ --mocha-base09: #fab387; /* orange / peach */ --mocha-base0A: #f9e2af; /* yellow */ --mocha-base0B: #a6e3a1; /* green */ - --mocha-base0C: #89dceb; /* cyan (our sky — note: Catppuccin's base0C is teal) */ + --mocha-base0C: #89dceb; /* cyan */ --mocha-base0D: #89b4fa; /* blue */ --mocha-base0E: #cba6f7; /* magenta / mauve */ --mocha-base0F: #f5c2e7; /* extra accent — pink */ - --latte-base00: #eff1f5; /* default bg */ - --latte-base01: #e6e9ef; /* lighter bg (elevated surfaces) */ - --latte-base02: #ccd0da; /* selection / surface — borders */ - --latte-base03: #bcc0cc; /* comments / dim surface */ - --latte-base04: #acb0be; /* dark foreground */ - --latte-base05: #4c4f69; /* default foreground */ - --latte-base06: #dc8a78; /* light foreground */ - --latte-base07: #7287fd; /* lightest */ - /* base08-0F: darkened from stock Catppuccin Latte's own accent hexes - (same hue/saturation, lower HSL lightness), not a literal upstream - port like base00-07 above. A review round computed real WCAG - contrast ratios and found the literal Latte accents fail badly as - `Badge`/chip fill-text (green/amber/red/yellow on - `--purple-dim`/base03: 1.4:1-3:1, need 4.5:1) and even as plain - text on `--bg`/base00 in the agent/dashboard packages that also - consume this same file (2.3:1-4.8:1). Root cause: Latte's own - accent colors are calibrated against Latte's near-white - `base`/`crust`, not against a mid-gray `surface1` — the Mocha - palette doesn't have this problem because Mocha's pastel accents - are already *light*, so they contrast fine against a *dark* - surface1; Latte's saturated-but-mid-brightness accents don't have - the equivalent headroom against Latte's own (much lighter) - surface1. Each value below was picked by holding the stock Latte - hue+saturation fixed and binary-searching HSL lightness down to - the point real contrast against base03 clears 4.5:1 with a small - margin (also verified against base00: all land above 7:1 there) — - same hue identity, same base16 role, just dark/saturated enough to - actually be legible as filled-chip or plain text either way. - Yellow and peach read closer to olive/brown than a bright - yellow/orange once darkened this far — an inherent property of - darkening a warm hue in sRGB (Bezold-Brücke shift), not a mapping - mistake; boosting saturation further didn't rescue it (verified). */ - --latte-base08: #9c0b2a; /* red */ - --latte-base09: #883201; /* orange / peach */ - --latte-base0A: #6d450e; /* yellow */ - --latte-base0B: #235818; /* green */ - --latte-base0C: #025374; /* cyan (our sky — note: Catppuccin's base0C is teal) */ - --latte-base0D: #0843b8; /* blue */ - --latte-base0E: #6311ce; /* magenta / mauve */ - --latte-base0F: #8f166e; /* extra accent — pink */ + --mara-base00: #1e1e2e; /* default bg */ + --mara-base01: #313244; /* lighter bg (elevated surfaces) */ + --mara-base02: #45475a; /* selection / surface — borders */ + --mara-base03: #6c7086; /* comments / dim surface */ + --mara-base04: #a6adc8; /* dark foreground */ + --mara-base05: #cdd6f4; /* default foreground */ + --mara-base06: #f5e0dc; /* light foreground */ + --mara-base07: #b4befe; /* lightest */ + --mara-base08: #f38ba8; /* red */ + --mara-base09: #6f9dff; /* orange / peach */ + --mara-base0A: #d162a4; /* yellow */ + --mara-base0B: #a8c9ff; /* green */ + --mara-base0C: #a30262; /* cyan */ + --mara-base0D: #89b4fa; /* blue */ + --mara-base0E: #cba6f7; /* magenta / mauve */ + --mara-base0F: #f2cdcd; /* extra accent — pink */ + /* mara: Catppuccin Mocha with the accents mara picked (base09-base0C). */ +} - /* Default activation: Mocha, unless the media query below or a - per-user override (further below) says otherwise. */ - --base00: var(--mocha-base00); - --base01: var(--mocha-base01); - --base02: var(--mocha-base02); - --base03: var(--mocha-base03); - --base04: var(--mocha-base04); - --base05: var(--mocha-base05); - --base06: var(--mocha-base06); - --base07: var(--mocha-base07); - --base08: var(--mocha-base08); - --base09: var(--mocha-base09); - --base0A: var(--mocha-base0A); - --base0B: var(--mocha-base0B); - --base0C: var(--mocha-base0C); - --base0D: var(--mocha-base0D); - --base0E: var(--mocha-base0E); - --base0F: var(--mocha-base0F); - /* The browser's own controls, scrollbars and dialog backdrops follow the - palette, so a forced theme does not leave them on the OS's. */ +/* hyperhive dark: the default, and the dark half of "auto". */ +:root, +:root[data-theme="hyperhive-dark"] { + --base00: var(--hh-dark-base00); + --base01: var(--hh-dark-base01); + --base02: var(--hh-dark-base02); + --base03: var(--hh-dark-base03); + --base04: var(--hh-dark-base04); + --base05: var(--hh-dark-base05); + --base06: var(--hh-dark-base06); + --base07: var(--hh-dark-base07); + --base08: var(--hh-dark-base08); + --base09: var(--hh-dark-base09); + --base0A: var(--hh-dark-base0A); + --base0B: var(--hh-dark-base0B); + --base0C: var(--hh-dark-base0C); + --base0D: var(--hh-dark-base0D); + --base0E: var(--hh-dark-base0E); + --base0F: var(--hh-dark-base0F); + /* A dark pick over a light OS preference: the media query's shares must not + carry over, so a dark palette sets its own, the defaults of theme.css. */ + --muted-share: 58%; + --subtext0-share: 77.7%; + --code-bg-share: 58%; + --palette-glass-clear: initial; + --palette-glass-filter: initial; color-scheme: dark; } -/* OS/browser-level light-mode default. This is a *default*, not a user - preference store: it only applies when nothing more specific has - already decided the palette. A stylix-generated colors.css - (nix/host-modules/hive-c0re/theme.nix) replaces this entire file - wholesale — a fixed, unconditional `:root` block with no media query - in it at all — so a stylix-themed deployment is naturally unaffected - by, and never fights, this block. Some people need light for - low-vision/contrast reasons, others need dark for photosensitivity, - so respect the OS/browser signal by default the same way - `prefers-reduced-motion` already is elsewhere — rather than always - forcing the bundled dark palette on a client with no stylix session - of its own (e.g. a phone browser hitting swarm-ui directly). */ +/* "auto" under a light OS preference. An explicit theme below outranks it: + an attribute selector always beats the plain `:root`. */ @media (prefers-color-scheme: light) { :root { - --base00: var(--latte-base00); - --base01: var(--latte-base01); - --base02: var(--latte-base02); - --base03: var(--latte-base03); - --base04: var(--latte-base04); - --base05: var(--latte-base05); - --base06: var(--latte-base06); - --base07: var(--latte-base07); - --base08: var(--latte-base08); - --base09: var(--latte-base09); - --base0A: var(--latte-base0A); - --base0B: var(--latte-base0B); - --base0C: var(--latte-base0C); - --base0D: var(--latte-base0D); - --base0E: var(--latte-base0E); - --base0F: var(--latte-base0F); - /* Dimmed text on the light palette: see `--muted-share` in theme.css. */ + --base00: var(--hh-light-base00); + --base01: var(--hh-light-base01); + --base02: var(--hh-light-base02); + --base03: var(--hh-light-base03); + --base04: var(--hh-light-base04); + --base05: var(--hh-light-base05); + --base06: var(--hh-light-base06); + --base07: var(--hh-light-base07); + --base08: var(--hh-light-base08); + --base09: var(--hh-light-base09); + --base0A: var(--hh-light-base0A); + --base0B: var(--hh-light-base0B); + --base0C: var(--hh-light-base0C); + --base0D: var(--hh-light-base0D); + --base0E: var(--hh-light-base0E); + --base0F: var(--hh-light-base0F); + /* Dimmed text on a light palette: see `--muted-share` in theme.css. */ --muted-share: 85%; --subtext0-share: 93%; --code-bg-share: 95%; - /* No frosted glass on the light palette: see `--glass-clear` in theme.css. */ + /* No frosted glass on a light palette: see `--glass-clear` in theme.css. */ --palette-glass-clear: 0; --palette-glass-filter: none; color-scheme: light; } } -/* Per-user override (`SettingsMenu` and `settings/theme-apply.ts` - set `data-theme` on ``; unset/`"system"` removes the - attribute and lets the media query above decide, same as before this - existed). `:root[data-theme='light']` has higher specificity than - the plain `:root` inside the media query above (an attribute - selector always outranks none), so this wins regardless of the - actual OS preference or source order — no `!important`, no inline - style, and critically no second copy of either palette's hex values: - both blocks below just re-point at the same `--mocha-baseNN` / - `--latte-baseNN` custom properties declared once at the top of this - file. */ -:root[data-theme="light"] { +:root[data-theme="hyperhive-light"] { + --base00: var(--hh-light-base00); + --base01: var(--hh-light-base01); + --base02: var(--hh-light-base02); + --base03: var(--hh-light-base03); + --base04: var(--hh-light-base04); + --base05: var(--hh-light-base05); + --base06: var(--hh-light-base06); + --base07: var(--hh-light-base07); + --base08: var(--hh-light-base08); + --base09: var(--hh-light-base09); + --base0A: var(--hh-light-base0A); + --base0B: var(--hh-light-base0B); + --base0C: var(--hh-light-base0C); + --base0D: var(--hh-light-base0D); + --base0E: var(--hh-light-base0E); + --base0F: var(--hh-light-base0F); + /* Dimmed text on a light palette: see `--muted-share` in theme.css. */ + --muted-share: 85%; + --subtext0-share: 93%; + --code-bg-share: 95%; + /* No frosted glass on a light palette: see `--glass-clear` in theme.css. */ + --palette-glass-clear: 0; + --palette-glass-filter: none; + color-scheme: light; +} + +:root[data-theme="catppuccin-latte-mauve"] { --base00: var(--latte-base00); --base01: var(--latte-base01); --base02: var(--latte-base02); @@ -170,15 +218,17 @@ --base0D: var(--latte-base0D); --base0E: var(--latte-base0E); --base0F: var(--latte-base0F); - /* Dimmed text on the light palette: see `--muted-share` in theme.css. */ + /* Dimmed text on a light palette: see `--muted-share` in theme.css. */ --muted-share: 85%; --subtext0-share: 93%; --code-bg-share: 95%; + /* No frosted glass on a light palette: see `--glass-clear` in theme.css. */ --palette-glass-clear: 0; --palette-glass-filter: none; color-scheme: light; } -:root[data-theme="dark"] { + +:root[data-theme="catppuccin-mocha-mauve"] { --base00: var(--mocha-base00); --base01: var(--mocha-base01); --base02: var(--mocha-base02); @@ -196,7 +246,34 @@ --base0E: var(--mocha-base0E); --base0F: var(--mocha-base0F); /* A dark pick over a light OS preference: the media query's shares must not - carry over, so the dark palette sets its own, the defaults of theme.css. */ + carry over, so a dark palette sets its own, the defaults of theme.css. */ + --muted-share: 58%; + --subtext0-share: 77.7%; + --code-bg-share: 58%; + --palette-glass-clear: initial; + --palette-glass-filter: initial; + color-scheme: dark; +} + +:root[data-theme="catppuccin-mocha-mara"] { + --base00: var(--mara-base00); + --base01: var(--mara-base01); + --base02: var(--mara-base02); + --base03: var(--mara-base03); + --base04: var(--mara-base04); + --base05: var(--mara-base05); + --base06: var(--mara-base06); + --base07: var(--mara-base07); + --base08: var(--mara-base08); + --base09: var(--mara-base09); + --base0A: var(--mara-base0A); + --base0B: var(--mara-base0B); + --base0C: var(--mara-base0C); + --base0D: var(--mara-base0D); + --base0E: var(--mara-base0E); + --base0F: var(--mara-base0F); + /* A dark pick over a light OS preference: the media query's shares must not + carry over, so a dark palette sets its own, the defaults of theme.css. */ --muted-share: 58%; --subtext0-share: 77.7%; --code-bg-share: 58%; diff --git a/frontend/packages/shared/src/settings/SettingsMenu.tsx b/frontend/packages/shared/src/settings/SettingsMenu.tsx index 40f9c8072..1689f9a3e 100644 --- a/frontend/packages/shared/src/settings/SettingsMenu.tsx +++ b/frontend/packages/shared/src/settings/SettingsMenu.tsx @@ -28,11 +28,15 @@ import type { ComponentChildren } from "preact"; import { IconButton } from "../icon-button/IconButton.js"; import { GearIcon } from "../icons.js"; import { useDismiss } from "../use-dismiss.js"; -import { useThemeOverride, type ThemeOverride } from "./theme-apply.js"; +import { useThemeOverride } from "./theme-apply.js"; +import { AUTO_THEME, THEMES } from "./themes.js"; import { useMotionOverride, type MotionOverride } from "./motion-apply.js"; import "./SettingsMenu.css"; -const THEME_OPTIONS: ThemeOverride[] = ["system", "light", "dark"]; +const THEME_OPTIONS = [ + { id: AUTO_THEME, label: "auto" }, + ...THEMES.map((t) => ({ id: t.id, label: t.label })), +]; const MOTION_OPTIONS: MotionOverride[] = ["system", "allow", "reduce"]; export interface SettingsMenuProps { @@ -85,13 +89,11 @@ export function SettingsMenu({ theme diff --git a/frontend/packages/shared/src/settings/theme-apply.ts b/frontend/packages/shared/src/settings/theme-apply.ts index f8f6449b9..9564f386d 100644 --- a/frontend/packages/shared/src/settings/theme-apply.ts +++ b/frontend/packages/shared/src/settings/theme-apply.ts @@ -1,46 +1,46 @@ -// Applies a stored theme override by setting `data-theme="light"|"dark"` -// on ``, cleared when the override is "system" (letting the -// `prefers-color-scheme` media query in `./colors.css` resume control). -// No palette values live here — `colors.css`'s own -// `:root[data-theme='light']` / `:root[data-theme='dark']` blocks are -// what actually apply the colours. +// Applies the stored theme choice by setting `data-theme=""` on +// ``, cleared for `auto` (so the `prefers-color-scheme` media query in +// `../colors.css` picks hyperhive light or dark). No palette values live +// here: `colors.css`'s `:root[data-theme=""]` blocks apply the colours, +// and `./themes.ts` lists the ids. // -// Callers own their own storage key (kept in their own small constant, -// not derived here) so two pages never silently share one browser-local -// setting by accident. `fallback` defaults to `'dark'`: `prefers-color- -// scheme` has no real "unset" value the way `prefers-reduced-motion` -// does, so a browser with no explicit dark-mode toggle reports `light` -// — `'system'` as a default silently reads as light-by-default for most -// first-time visitors (mara: "light mode seems to be default"). Still -// fully overridable per caller if a page ever wants a different default. +// Callers own their own storage key (kept in their own small constant, not +// derived here) so two pages never silently share one browser-local setting +// by accident. The stored value is read through `themeChoice`, so a value +// from before themes existed (`system`, `light`, `dark`) still works. The +// default is hyperhive dark: `prefers-color-scheme` has no real "unset" value +// the way `prefers-reduced-motion` does, so a browser with no explicit +// dark-mode toggle reports `light`, and `auto` as a default read as +// light-by-default for most first-time visitors (mara: "light mode seems to be +// default"). import { useEffect } from "preact/hooks"; import { useLocalSetting } from "./settings-storage.js"; +import { AUTO_THEME, DEFAULT_THEME, themeChoice } from "./themes.js"; -export type ThemeOverride = "system" | "light" | "dark"; - +/** `[choice, setChoice]`: `auto` or a theme id from `./themes.ts`. */ export function useThemeOverride( key: string, - fallback: ThemeOverride = "dark", -) { - return useLocalSetting(key, fallback); + fallback: string = DEFAULT_THEME, +): [string, (choice: string) => void] { + const [stored, setStored] = useLocalSetting(key, fallback); + return [themeChoice(stored, fallback), setStored]; } -// Mounted once, high in the tree — one mount point applies the override -// regardless of what else is rendering, and `useLocalSetting`'s -// same-tab subscription means `SettingsMenu` changing the value re-runs -// this effect without either component needing to know about the other -// directly. +// Mounted once, high in the tree — one mount point applies the choice +// regardless of what else is rendering, and `useLocalSetting`'s same-tab +// subscription means `SettingsMenu` changing the value re-runs this effect +// without either component needing to know about the other directly. export function useApplyThemeOverride( key: string, - fallback: ThemeOverride = "dark", + fallback: string = DEFAULT_THEME, ): void { - const [override] = useThemeOverride(key, fallback); + const [choice] = useThemeOverride(key, fallback); useEffect(() => { const root = document.documentElement; - if (override === "system") { + if (choice === AUTO_THEME) { delete root.dataset.theme; } else { - root.dataset.theme = override; + root.dataset.theme = choice; } - }, [override]); + }, [choice]); } diff --git a/frontend/packages/shared/src/settings/themes.ts b/frontend/packages/shared/src/settings/themes.ts new file mode 100644 index 000000000..4f73be8d2 --- /dev/null +++ b/frontend/packages/shared/src/settings/themes.ts @@ -0,0 +1,54 @@ +// The themes a user can pick, apart from how they are applied. The palettes are +// in `../colors.css`, one `:root[data-theme=""]` block per id here; a new +// theme is one entry here and one palette there. Each theme is light or dark. +// `auto` is not a theme: it leaves `data-theme` off, and the OS preference +// picks hyperhive light or hyperhive dark. + +export type ThemeScheme = "light" | "dark"; + +export interface ThemeDef { + id: string; + label: string; + scheme: ThemeScheme; +} + +export const THEMES: readonly ThemeDef[] = [ + { id: "hyperhive-light", label: "hyperhive light", scheme: "light" }, + { id: "hyperhive-dark", label: "hyperhive dark", scheme: "dark" }, + { + id: "catppuccin-latte-mauve", + label: "catppuccin latte mauve", + scheme: "light", + }, + { + id: "catppuccin-mocha-mauve", + label: "catppuccin mocha mauve", + scheme: "dark", + }, + { + id: "catppuccin-mocha-mara", + label: "catppuccin mocha mara", + scheme: "dark", + }, +]; + +/** The stored choice that follows the OS preference. */ +export const AUTO_THEME = "auto"; + +/** What a page uses until the user has picked. */ +export const DEFAULT_THEME = "hyperhive-dark"; + +/** + * The choice a stored value stands for. The values from before themes existed + * map to their successors (`system` to `auto`, `light` and `dark` to the + * hyperhive themes); anything unknown is `fallback`. + */ +export function themeChoice( + stored: unknown, + fallback: string = DEFAULT_THEME, +): string { + if (stored === AUTO_THEME || stored === "system") return AUTO_THEME; + if (stored === "light") return "hyperhive-light"; + if (stored === "dark") return "hyperhive-dark"; + return THEMES.some((t) => t.id === stored) ? (stored as string) : fallback; +} diff --git a/frontend/packages/swarm-ui/build.mjs b/frontend/packages/swarm-ui/build.mjs index 964c42842..8810f2a6a 100644 --- a/frontend/packages/swarm-ui/build.mjs +++ b/frontend/packages/swarm-ui/build.mjs @@ -7,10 +7,9 @@ // sync with the actual build steps. // // `colors.css` is the ONE static asset deliberately left UNHASHED, at a -// fixed `dist/static/colors.css`: nix/host-modules/swarm-ui.nix's stylix -// theming swaps that exact path via an `= /static/colors.css` nginx -// location override, no npm/esbuild rebuild involved. Hashing it would -// silently break that swap. See `colors.css`'s own top comment. +// fixed `dist/static/colors.css`: nix/host-modules/swarm-ui.nix serves that +// exact path through an `= /static/colors.css` nginx location that +// revalidates it, and the swagger page links the same file. // // `dist/sw.js` keeps its own fixed/unhashed filename too — the browser // polls this exact URL to detect a SW update, hashing it would make diff --git a/frontend/packages/swarm-ui/src/colors.css b/frontend/packages/swarm-ui/src/colors.css index 69cbb6ef7..af919e33b 100644 --- a/frontend/packages/swarm-ui/src/colors.css +++ b/frontend/packages/swarm-ui/src/colors.css @@ -1,6 +1,6 @@ /* Standalone base16 palette — re-exports the shared base16 slots so esbuild emits its own `dist/static/colors.css`, linked first by every - swarm-ui page (before theme.css). This is the theme swap contract: a - stylix-generated variant replaces only this file. See + swarm-ui page (before theme.css). This is the theme contract: the + themes' palettes live in this one file. See @hive/shared/colors.css + docs/4-implementation/web-ui/css-vars.md. */ @import "@hive/shared/colors.css"; diff --git a/frontend/packages/swarm-ui/src/sw.js b/frontend/packages/swarm-ui/src/sw.js index 1e6c1b595..5e1af7cd2 100644 --- a/frontend/packages/swarm-ui/src/sw.js +++ b/frontend/packages/swarm-ui/src/sw.js @@ -10,7 +10,7 @@ // Network-first for the shell, not cache-first: most assets below are // content-hashed (a fresh URL per deploy, so a normal visit always gets // the current bundle regardless of this SW), but `colors.css` stays -// deliberately unhashed for the host-side stylix theme swap, so this +// unhashed (the swagger page links it by its fixed name), so this // SW's own cached copy of it can only ever refresh via a real network // round-trip. This SW only ever serves its cache on a FAILED fetch // (offline/flaky network), never in preference to a live response. diff --git a/frontend/packages/swarm-ui/src/theme-boot.js b/frontend/packages/swarm-ui/src/theme-boot.js index b3f921ece..2b1b7fdff 100644 --- a/frontend/packages/swarm-ui/src/theme-boot.js +++ b/frontend/packages/swarm-ui/src/theme-boot.js @@ -3,8 +3,10 @@ // `useApplyMotionOverride`), but that is after the page has painted, so a light // OS showed a light flash before the dark default took over. This runs from a // blocking script in the head, as the page's policy allows no inline script. The -// keys and the fallbacks ("dark" for the theme, "system" for motion) are those of -// `shell/Shell.tsx`; `test/theme-boot.test.mjs` keeps them in step. +// keys and the fallbacks (hyperhive dark for the theme, "system" for motion) are +// those of `shell/Shell.tsx`, and the theme ids and the values from before +// themes existed are those of `@hive/shared`'s `settings/themes.ts`; +// `test/theme-boot.test.mjs` keeps them in step. (function () { function read(key, fallback) { try { @@ -15,8 +17,17 @@ } } var root = document.documentElement; - var theme = read("swarm-ui:theme-override", "dark"); - if (theme === "light" || theme === "dark") root.dataset.theme = theme; + var themes = [ + "hyperhive-light", + "hyperhive-dark", + "catppuccin-latte-mauve", + "catppuccin-mocha-mauve", + "catppuccin-mocha-mara", + ]; + var theme = read("swarm-ui:theme-override", "hyperhive-dark"); + if (theme === "light") theme = "hyperhive-light"; + if (theme === "dark") theme = "hyperhive-dark"; + if (themes.indexOf(theme) >= 0) root.dataset.theme = theme; var motion = read("swarm-ui:motion-override", "system"); if (motion === "reduce" || motion === "allow") root.dataset.motion = motion; })(); diff --git a/frontend/packages/swarm-ui/test/theme-boot.test.mjs b/frontend/packages/swarm-ui/test/theme-boot.test.mjs index ee96b654e..06b23fb8f 100644 --- a/frontend/packages/swarm-ui/test/theme-boot.test.mjs +++ b/frontend/packages/swarm-ui/test/theme-boot.test.mjs @@ -27,25 +27,36 @@ function boot(stored) { return dataset; } -test("nothing stored sets the dark default and leaves motion to the system", () => { - assert.deepEqual(boot({}), { theme: "dark" }); +test("nothing stored sets the hyperhive dark default and leaves motion to the system", () => { + assert.deepEqual(boot({}), { theme: "hyperhive-dark" }); }); -test("a stored light theme and a motion override are set", () => { +test("a stored theme and a motion override are set", () => { const set = boot({ "swarm-ui:theme-override": '"light"', "swarm-ui:motion-override": '"reduce"', }); - assert.deepEqual(set, { theme: "light", motion: "reduce" }); + assert.deepEqual(set, { theme: "hyperhive-light", motion: "reduce" }); + assert.deepEqual( + boot({ "swarm-ui:theme-override": '"catppuccin-mocha-mauve"' }), + { theme: "catppuccin-mocha-mauve" }, + ); }); -test("system leaves the attribute off, so the media query decides", () => { +test("a stored dark, from before themes existed, is hyperhive dark", () => { + assert.deepEqual(boot({ "swarm-ui:theme-override": '"dark"' }), { + theme: "hyperhive-dark", + }); +}); + +test("auto, and system from before themes existed, leave the attribute off, so the media query decides", () => { + assert.deepEqual(boot({ "swarm-ui:theme-override": '"auto"' }), {}); assert.deepEqual(boot({ "swarm-ui:theme-override": '"system"' }), {}); }); test("a value that is not JSON, or not one of the choices, is ignored", () => { assert.deepEqual(boot({ "swarm-ui:theme-override": "light" }), { - theme: "dark", + theme: "hyperhive-dark", }); assert.deepEqual(boot({ "swarm-ui:theme-override": '"blue"' }), {}); }); @@ -60,7 +71,31 @@ test("storage that throws behaves as if nothing were stored", () => { }, document: { documentElement: { dataset } }, }); - assert.deepEqual(dataset, { theme: "dark" }); + assert.deepEqual(dataset, { theme: "hyperhive-dark" }); +}); + +test("the theme ids are the registry's", () => { + const registry = readFileSync( + new URL("../../shared/src/settings/themes.ts", import.meta.url), + "utf8", + ); + const ids = (text) => + [...text.matchAll(/"((?:hyperhive|catppuccin)-[a-z-]+)"/g)].map( + (m) => m[1], + ); + const listed = script.slice( + script.indexOf("var themes"), + script.indexOf("];"), + ); + assert.deepEqual( + ids(listed), + ids( + registry.slice( + registry.indexOf("THEMES"), + registry.indexOf("AUTO_THEME"), + ), + ).filter((id, i, all) => all.indexOf(id) === i), + ); }); test("the keys are the shell's", () => { diff --git a/frontend/packages/swarm-ui/test/themes.test.mjs b/frontend/packages/swarm-ui/test/themes.test.mjs new file mode 100644 index 000000000..6e6c642e9 --- /dev/null +++ b/frontend/packages/swarm-ui/test/themes.test.mjs @@ -0,0 +1,36 @@ +// The theme registry and how a stored choice reads. Run by `npm test`, which +// imports the `.ts` module as it is. +import assert from "node:assert/strict"; +import { test } from "node:test"; +import { + AUTO_THEME, + DEFAULT_THEME, + THEMES, + themeChoice, +} from "../../shared/src/settings/themes.ts"; + +test("the default is one of the themes", () => { + assert.ok(THEMES.some((t) => t.id === DEFAULT_THEME)); +}); + +test("every theme is light or dark, and the ids and labels are distinct", () => { + for (const t of THEMES) assert.ok(["light", "dark"].includes(t.scheme)); + assert.equal(new Set(THEMES.map((t) => t.id)).size, THEMES.length); + assert.equal(new Set(THEMES.map((t) => t.label)).size, THEMES.length); +}); + +test("a theme id and auto read as themselves", () => { + assert.equal(themeChoice("catppuccin-mocha-mauve"), "catppuccin-mocha-mauve"); + assert.equal(themeChoice(AUTO_THEME), AUTO_THEME); +}); + +test("the values from before themes existed read as their successors", () => { + assert.equal(themeChoice("system"), AUTO_THEME); + assert.equal(themeChoice("light"), "hyperhive-light"); + assert.equal(themeChoice("dark"), "hyperhive-dark"); +}); + +test("an unknown value reads as the fallback", () => { + assert.equal(themeChoice("blue"), DEFAULT_THEME); + assert.equal(themeChoice(undefined, "hyperhive-light"), "hyperhive-light"); +}); diff --git a/nix/host-modules/hive-c0re/default.nix b/nix/host-modules/hive-c0re/default.nix index 5b6a0e466..4c2c9b89d 100644 --- a/nix/host-modules/hive-c0re/default.nix +++ b/nix/host-modules/hive-c0re/default.nix @@ -1,7 +1,6 @@ # The hive-c0re coordinator daemon (runs as the unprivileged # `hive-core` user), socket-activated at /run/hyperhive/host.sock. -# Layout: ./options.nix (option declarations), ./theme.nix (stylix -# frontend theming → `servedFrontend`), ./vhosts.nix (its gateway vhosts), +# Layout: ./options.nix (option declarations), ./vhosts.nix (its gateway vhosts), # ./environment.nix (the daemon unit's env attrset). The root privileged # helper it delegates to is its own module (../hive-priv.nix). { @@ -102,7 +101,6 @@ in { imports = [ ./options.nix - ./theme.nix ./vhosts.nix # Hive-CA trust for this daemon's outbound TLS. The swarm services it # reaches over https serve a leaf chaining to the store's pki root — diff --git a/nix/host-modules/hive-c0re/environment.nix b/nix/host-modules/hive-c0re/environment.nix index 5102eadaf..50b98505b 100644 --- a/nix/host-modules/hive-c0re/environment.nix +++ b/nix/host-modules/hive-c0re/environment.nix @@ -62,7 +62,7 @@ in # nix store directly; dynamic API paths still proxied to the # agent daemon. nginx runs on the host, which is where this # store path already is, so it is reachable as written. - HIVE_AGENT_FRONTEND_DIR = "${controllerCfg.servedFrontend}/agent"; + HIVE_AGENT_FRONTEND_DIR = "${controllerCfg.frontend}/agent"; } // { # Identity env vars threaded into c0re's own service env and diff --git a/nix/host-modules/hive-c0re/options.nix b/nix/host-modules/hive-c0re/options.nix index 91596d976..2fd22630a 100644 --- a/nix/host-modules/hive-c0re/options.nix +++ b/nix/host-modules/hive-c0re/options.nix @@ -3,9 +3,7 @@ # own outputs (they carry no in-module defaults; see ../../../flake.nix) # live under `services.hyperhive.deploy.hive-controller`, alongside the # values the meta-flake render hands the hive's agents. The flake-source -# option the swarm builder also reads is `services.hyperhive.deploy.hyperhiveFlake`. The read-only -# `servedFrontend` option lives in ./theme.nix with the stylix wiring -# that computes it. +# option the swarm builder also reads is `services.hyperhive.deploy.hyperhiveFlake`. { lib, ... diff --git a/nix/host-modules/hive-c0re/theme.nix b/nix/host-modules/hive-c0re/theme.nix deleted file mode 100644 index 5f903edcd..000000000 --- a/nix/host-modules/hive-c0re/theme.nix +++ /dev/null @@ -1,58 +0,0 @@ -# Stylix theme integration (zero-op auto-detect). When the operator's -# host config has stylix enabled, generate a base16 `colors.css` from -# its palette and overlay it onto the bundled frontend dist so the -# dashboard re-themes with no operator action and no npm/esbuild -# rebuild (a pure file-copy over the prebuilt dist). `colors.css` is -# the entire swap contract — `theme.css` derives every semantic var -# from the 16 base16 slots (see docs/4-implementation/web-ui/css-vars.md). The guarded -# access makes this a clean no-op when stylix isn't imported into the -# host config. Exposed as the read-only `deploy.hive-controller.servedFrontend` option. -# -# Detection + CSS-generation itself lives in `../stylix-theme.nix` -# (shared with `swarm-ui.nix`) — this file is the c0re-specific overlay -# consumer (which subtrees, which option). -{ - pkgs, - lib, - config, - ... -}: -let - cfg = config.services.hyperhive.deploy.hive-controller; - stylixTheme = import ../stylix-theme.nix { inherit lib config pkgs; }; - inherit (stylixTheme) stylixThemeColors themedColorsCss; - # Overlay the generated colors.css onto both dist subtrees. Both the - # dashboard (served by hive-c0re via HIVE_STATIC_DIR) and the agent UIs - # (served by the gateway from HIVE_AGENT_FRONTEND_DIR — static files - # straight from the store) read their colors.css from this host-side - # tree, so swapping both re-themes both surfaces. - # - # Not covered here: an agent reached directly on its own harness web - # server (no gateway) serves from its per-agent `mergedDist`, built in - # the agent's own nixosSystem with no access to the host's stylix - # colours — theming that path needs the base16 palette forwarded - # host→agent, tracked separately. - themedFrontend = - c: - pkgs.runCommand "hyperhive-frontend-themed" { } '' - cp -r ${cfg.frontend} $out - chmod -R u+w $out - install -m644 ${themedColorsCss c} $out/dashboard/static/colors.css - install -m644 ${themedColorsCss c} $out/agent/static/colors.css - ''; -in -{ - options.services.hyperhive.deploy.hive-controller.servedFrontend = lib.mkOption { - type = lib.types.package; - internal = true; - readOnly = true; - default = if stylixThemeColors != null then themedFrontend stylixThemeColors else cfg.frontend; - defaultText = lib.literalExpression ""; - description = '' - Internal, read-only: `frontend` re-themed with the active stylix - palette (or `frontend` verbatim when unthemed); has `dashboard/` - and `agent/`. Exposed so the hive-gateway module can static-serve - `dashboard/` as an nginx root instead of proxying to hive-c0re. - ''; - }; -} diff --git a/nix/host-modules/hive-c0re/vhosts.nix b/nix/host-modules/hive-c0re/vhosts.nix index 5085e4e4e..d4550f24e 100644 --- a/nix/host-modules/hive-c0re/vhosts.nix +++ b/nix/host-modules/hive-c0re/vhosts.nix @@ -17,7 +17,7 @@ let inherit (gatewayCfg.lib) errorPages; # Dashboard SPA dist, static-served by nginx. - dashboardDist = "${hyperhiveCfg.deploy.hive-controller.servedFrontend}/dashboard"; + dashboardDist = "${hyperhiveCfg.deploy.hive-controller.frontend}/dashboard"; # `/agent/` catch-all 404 + the two internal error-page targets it # points at. Per-agent `location /agent//` blocks live in the diff --git a/nix/host-modules/stylix-theme.nix b/nix/host-modules/stylix-theme.nix deleted file mode 100644 index 8220af599..000000000 --- a/nix/host-modules/stylix-theme.nix +++ /dev/null @@ -1,59 +0,0 @@ -# Shared stylix theming helper: detects an active stylix palette on the -# host and renders it as a base16 `colors.css` overlay file. `colors.css` -# is the entire theme-swap contract for every frontend bundle in this -# project (`theme.css` derives every semantic var from these 16 slots — -# see docs/4-implementation/web-ui/css-vars.md), so "apply the operator's stylix palette" -# always reduces to "write this one file over the prebuilt dist's own -# `colors.css`" — no npm/esbuild rebuild needed. -# -# Two consumers today: `hive-c0re/theme.nix` (dashboard + agent -# frontend), `swarm-ui.nix` (the swarm-level UI). Factored out here -# rather than duplicated in both — same "one source, not a copy that -# agrees by inspection" reasoning `hive-gateway/vhost-lib.nix` gives for -# its own split. Both callers `import` this directly (not published via -# an option): unlike the gateway's vhost kit, this needs no per-service -# knowledge to construct, it's a pure read of the host's own top-level -# `config` — an option indirection would add a layer with nothing to -# publish through it. -# -# Guarded access makes `stylixThemeColors` a clean `null` when stylix -# isn't imported into the host config at all, so every caller's own -# `if stylixThemeColors != null then ... else ` -# stays a zero-op when the operator hasn't opted in. -{ - lib, - config, - pkgs, -}: -let - stylixThemeColors = - if (config.stylix.enable or false) && ((config.lib.stylix or { }) ? colors) then - config.lib.stylix.colors.withHashtag - else - null; - themedColorsCss = - c: - pkgs.writeText "hyperhive-colors.css" '' - :root { - --base00: ${c.base00}; - --base01: ${c.base01}; - --base02: ${c.base02}; - --base03: ${c.base03}; - --base04: ${c.base04}; - --base05: ${c.base05}; - --base06: ${c.base06}; - --base07: ${c.base07}; - --base08: ${c.base08}; - --base09: ${c.base09}; - --base0A: ${c.base0A}; - --base0B: ${c.base0B}; - --base0C: ${c.base0C}; - --base0D: ${c.base0D}; - --base0E: ${c.base0E}; - --base0F: ${c.base0F}; - } - ''; -in -{ - inherit stylixThemeColors themedColorsCss; -} diff --git a/nix/host-modules/swarm-ui.nix b/nix/host-modules/swarm-ui.nix index 8c1f45118..af0c385a0 100644 --- a/nix/host-modules/swarm-ui.nix +++ b/nix/host-modules/swarm-ui.nix @@ -17,26 +17,6 @@ let gatewayCfg = config.services.hyperhive.gateway; autheliaCfg = config.services.hyperhive.swarm.authelia; - # Same stylix auto-theming `hive-c0re/theme.nix` gives the dashboard — - # this UI was left out of that overlay entirely (an operator with a - # stylix-themed host saw the dashboard in their own colours but this - # UI still on the default Catppuccin palette), because nothing here - # ever served a themed `colors.css` in place of `deployCfg.swarm-controller.ui.package`'s own. - # Detection + CSS-generation is shared (`./stylix-theme.nix`). - # - # No package-copy derivation: this vhost has exactly one location - # serving `deployCfg.swarm-controller.ui.package` (unlike hive-c0re's `servedFrontend`, which - # backs both the dashboard root AND every per-agent gateway route, so - # a single swapped tree covers both) — an `= /static/colors.css` - # exact-match location overriding just that one file, same idiom - # every other single-path override on this vhost already uses - # (`/api/whoami`, `/api/docs`), is simpler than copying the whole - # static tree to change one file inside it. mara, on review: "i - # thought we just swap a css file via nginx config?" — yes, and this - # is that. - stylixTheme = import ./stylix-theme.nix { inherit lib config pkgs; }; - inherit (stylixTheme) stylixThemeColors themedColorsCss; - # Repeated verbatim by every location that should be operator-gated # (`/`, `/api/docs/`; `/api/` takes `authRequest` with its own 401 # handler) rather than set once on the server: @@ -78,7 +58,7 @@ let # The cache rule has no `always`, so an error answer (a 404 for a hash that # is gone) is never marked cacheable. # Everything else the page loads by a fixed name (the entry document, - # `sw.js`, the manifest, `colors.css`, which the theme swaps) must be + # `sw.js`, the manifest, `colors.css`, which holds the palettes) must be # revalidated, or a deploy can leave a browser on an old document that points # at scripts that no longer exist. staticHeaders = cache: '' @@ -282,26 +262,16 @@ in try_files $uri =404; ''; }; - # The one unhashed file under `/static/`: the theme swaps it (see the - # stylix note above), so it is revalidated, not immutable. - "= /static/colors.css" = - if stylixThemeColors != null then - { - alias = "${themedColorsCss stylixThemeColors}"; - extraConfig = '' - ${swarmAuthRequest} - ${staticHeaders revalidate} - ''; - } - else - { - root = "${deployCfg.swarm-controller.ui.package}"; - extraConfig = '' - ${swarmAuthRequest} - ${staticHeaders revalidate} - try_files $uri =404; - ''; - }; + # The one unhashed file under `/static/`, so it is revalidated, not + # immutable. + "= /static/colors.css" = { + root = "${deployCfg.swarm-controller.ui.package}"; + extraConfig = '' + ${swarmAuthRequest} + ${staticHeaders revalidate} + try_files $uri =404; + ''; + }; } // lib.optionalAttrs servesMatrixDiscovery { # Same JSON, headers and `:443` as the hive-domain copy in diff --git a/nix/module-eval/core-toggle.nix b/nix/module-eval/core-toggle.nix index 74da1cc96..1f240a92b 100644 --- a/nix/module-eval/core-toggle.nix +++ b/nix/module-eval/core-toggle.nix @@ -2251,7 +2251,6 @@ let && path c.frontend == path pkgs.coreutils && path c.assets == path pkgs.gnused && path c.xdgIcons == path pkgs.gnugrep - && path c.servedFrontend == path pkgs.coreutils && c.hyperhiveRev == "abc123" && c.agentCpuQuota == "300%" && c.agentMemoryMax == "8G" diff --git a/nix/packages/swagger-ui-theme.nix b/nix/packages/swagger-ui-theme.nix index 91413c66a..e429f1e5a 100644 --- a/nix/packages/swagger-ui-theme.nix +++ b/nix/packages/swagger-ui-theme.nix @@ -12,7 +12,7 @@ # nix/host-modules/hive-c0re/vhosts.nix). # # Output layout: every file from `swagger-ui-dist`, with 3 replaced: -# index.html adds colors.css (live stylix theme) + +# index.html adds colors.css (the palettes) + # hyperhive-theme.css s # hyperhive-theme.css new; the re-theme, consumes --baseNN vars # swagger-initializer.js hardcodes `url: "/api/openapi.json"` — diff --git a/swagger-ui-theme/hyperhive-theme.css b/swagger-ui-theme/hyperhive-theme.css index 992284588..e4b537bc8 100644 --- a/swagger-ui-theme/hyperhive-theme.css +++ b/swagger-ui-theme/hyperhive-theme.css @@ -8,8 +8,8 @@ cascade without `!important`, except where noted below. `--baseNN` values come from `/static/colors.css` (linked in - index.html, same origin as the dashboard) — this follows the - operator's live stylix theme, not a hardcoded copy. See + index.html, same origin as the dashboard), so it follows the + palettes there rather than a hardcoded copy. See frontend/packages/shared/src/colors.css for the base16 contract. */ /* Page chrome */ diff --git a/swagger-ui-theme/index.html b/swagger-ui-theme/index.html index e158045c7..146660499 100644 --- a/swagger-ui-theme/index.html +++ b/swagger-ui-theme/index.html @@ -5,8 +5,8 @@ vhosts.nix's `swaggerUiLocations` serves at /api/docs/, wholesale, with NO hive-c0re fallback for any file in the tree. Byte-identical to the vendored Swagger UI's dist/index.html except two added - s: `colors.css` (same origin as the dashboard — so this - resolves the operator's live stylix theme, not a frozen copy) and + s: `colors.css` (same origin as the dashboard, so it carries + the palettes, not a frozen copy) and hyperhive-theme.css, which consumes its `--baseNN` vars. -->