An agentic browser harness: an AI side panel & orb in your own logged-in Chrome, Edge, Arc, Brave or even Firefox run by the agent/subscription you already use (Claude Code, Codex, Antigravity). Free, open source, no API key. Also an MCP server.
TypeScript agentic-browseragentic-browsingagy-cliaiai-agentai-browser-extensionai-toolsbrave-extensionbrowser-agentbrowser-automationbrowser-extensionbrowser-usebrowserskillchrome-extensionclaude-codecodexfirefox-addonmcp-servernanobrowserweb-automation
feat(panel): pick a theme for the panel, the popup and the rail
Shahriar11f376df6aec
diff --git a/docs/guide/configuration.md b/docs/guide/configuration.mdindex cb984bf..e2c3f57 100644--- a/docs/guide/configuration.md+++ b/docs/guide/configuration.md@@ -109,6 +109,17 @@ ceiling is clamped; a value that is not a number ≥ 1 falls back to the default---+## Appearance++The panel's theme is not in this file. It is a row of tiles in the side panel's **Settings** tab —+**Ember** (warm near-black, cyan), **Midnight** (cool blue-black, violet), **Phosphor** (a green+CRT) and **Daylight** (ink on paper) — and one click repaints the panel and the popup together.+Each tile is drawn in the theme it offers, so the preview is the thing itself.++The choice is stored in the browser, never sent to the daemon, and needs nothing paired to work.++---+## Things that are not configurableCompiled-in ceilings, listed here so you do not go looking for a key that does not exist:diff --git a/docs/internals/extension.md b/docs/internals/extension.mdindex 0ff1069..5cd8acb 100644--- a/docs/internals/extension.md+++ b/docs/internals/extension.md@@ -52,10 +52,34 @@ learned, which is what keeps the strip from flapping between two fits at one panpractice five labels want ~485 px and one wants ~225 px, so a side panel at its usual size lands onthe middle fit.-**Settings** is the only tab whose state lives on the daemon rather than in extension storage. It-reads and writes `~/.browsentic/config.json` through two bridge ops, `guardrails` and-`setGuardrail`, which forward to the socket frames of the same name. The extension holds no copy:-every write returns the daemon's fresh view, which is what the panel then renders.+**Settings** is two halves with nothing in common. **Guardrails** is the only panel state that+lives on the daemon rather than in extension storage: it reads and writes `~/.browsentic/config.json`+through two bridge ops, `guardrails` and `setGuardrail`, which forward to the socket frames of the+same name. The extension holds no copy — every write returns the daemon's fresh view, which is what+the panel then renders, and the whole half is empty until the daemon is up. **Appearance** never+leaves the browser, which is why it sits above and renders whether or not anything is paired.++### Themes++A theme is one block of raw tokens in `globals.css` — grounds, inks, lines, the six named colours,+and four dials (`--wash`, `--grain`, `--neon`, `--glow`) that the utilities read instead of naming a+colour themselves. `daylight` sets `--grain` and `--neon` to nothing because film grain and a neon+halo are effects that only exist on black. The semantic tokens the shadcn primitives read are mapped+once, afterwards, from whichever block won, so a theme is that block and no more.++The blocks hang off `[data-theme]` rather than `:root`, and the attribute is **scoped rather than+global**. Put it on a swatch and that subtree renders in the theme it advertises, which is how the+picker draws four live previews with no second copy of the palette. Only raw tokens re-resolve that+way (`bg-ground`, `bg-brand`); the semantic ones (`bg-background`, `border-border`) are computed at+`:root` and inherit, so a scoped preview must not use them.++`browser.storage.local` under `browsentic/theme` is the truth, read by `useTheme()`. It answers a+tick after the page has already painted, though, which on a light theme is a dark flash every time+the popup opens — so `mountTheme()` applies a `localStorage` mirror of the same id synchronously+before React mounts, and lets storage correct it a moment later. `index.html` carries+`data-theme="ember"` and an inline ground so the frame before the stylesheet is neither white nor+unpainted; `applyTheme` clears that inline colour, since an inline colour outranks every rule and+would otherwise pin `<html>` to a dark ground under a light theme.## Minimizing: the rail lives in the page@@ -67,7 +91,7 @@ can size.| | || --- | --- |-| `src/lib/rail/events.ts` | The channel, the `RailView` the background computes, the tab list with its Lucide paths copied out, and the palette spelled in `oklch` |+| `src/lib/rail/events.ts` | The channel, the `RailView` the background computes, the tab list with its Lucide paths copied out, and one palette per theme spelled in `oklch` || `src/lib/rail/host.ts` | `exposeRail()` in the content script — builds the rail in a **closed** shadow root on `documentElement` || `src/lib/bridge/rail.ts` | `serveRail()` and `syncRail()` in the background — what to paint, and when || `src/lib/bridge/panel-view.ts` | `browsentic/panelCollapsed` and `browsentic/panelTab`, read by `use-panel-view.ts` in the panel |@@ -75,6 +99,17 @@ can size.The content script carries no React and no icon package, which is why the paths and colours arecopied rather than imported — `src/extension/components/` would drag the whole panel bundle onto every page.+**Which is also why the rail is the one place a theme is spelled twice.** It has no stylesheet to+read `globals.css` from, so `RAIL_PALETTES` and `RAIL_TONES` carry an entry per `[data-theme]`+block, `RailView` carries the id, and `describeRail()` reads `browsentic/theme` alongside everything+else — the same `storage.local.onChanged` listener that repaints the rail on a tab change repaints+it on a theme change.++Both records are `Record<ThemeId, …>`, so a new id that forgets them fails `yarn compile` rather+than stranding an ember rail on every page. The two halves it cannot check are the `[data-theme]`+block itself and the entry in `THEMES` — a theme missing either is a theme the picker offers and+the stylesheet ignores, or the reverse.+**A closed shadow root on `documentElement` is load-bearing.** It keeps the rail out of`body.innerText` (so `extractText` never returns it), out of the page's `querySelectorAll`, and outof any page stylesheet. The host element has no layout footprint; the rail inside it isdiff --git a/src/extension/assets/globals.css b/src/extension/assets/globals.cssindex f4be95c..4a6fbc7 100644--- a/src/extension/assets/globals.css+++ b/src/extension/assets/globals.css@@ -5,12 +5,21 @@/** Browsentic — the landing page’s palette, at panel scale.- * Warm near-black ground, cyan brand, ember counter-accent, one committed- * dark look. Semantic tokens feed the shadcn primitives; the named colours- * below are the same ramp the website ships.+ * A theme is one block of raw tokens: four grounds, three inks, two lines, six+ * named colours, and the four dials (wash, grain, neon, glow) the utilities read.+ * Nothing below this section names a colour, so a theme is that block and no more.+ * The semantic tokens the shadcn primitives read are mapped once, afterwards,+ * from whichever block won. The attribute is scoped rather than global — put it+ * on a swatch and that subtree previews the theme, which is how the picker+ * draws itself, and index.html carries Ember so the first paint has a palette.*/:root {--radius: 0.75rem;+}++/* Warm near-black under a cyan brand — the look Browsentic ships. */+[data-theme='ember'] {+ color-scheme: dark;--ground: oklch(0.152 0.016 52);--ground-2: oklch(0.183 0.018 50);@@ -30,7 +39,107 @@--magenta: oklch(0.7 0.21 335);--lime: oklch(0.84 0.18 150);--amber: oklch(0.84 0.15 85);+ --danger: oklch(0.645 0.205 25);++ --wash: oklch(0.98 0.01 60);+ --grain: 0.03;+ --neon: 55%;+ --glow: 72%;+}++/* Cool blue-black under a violet brand. */+[data-theme='midnight'] {+ color-scheme: dark;++ --ground: oklch(0.158 0.024 264);+ --ground-2: oklch(0.192 0.028 264);+ --surface: oklch(0.228 0.032 264);+ --surface-2: oklch(0.272 0.036 264);++ --ink: oklch(0.958 0.012 268);+ --ink-dim: oklch(0.742 0.022 266);+ --ink-faint: oklch(0.585 0.026 265);++ --line: oklch(0.97 0.02 268 / 11%);+ --line-strong: oklch(0.97 0.02 268 / 19%);++ --brand: oklch(0.79 0.15 288);+ --brand-deep: oklch(0.6 0.16 288);+ --ember: oklch(0.75 0.16 22);+ --magenta: oklch(0.72 0.2 330);+ --lime: oklch(0.85 0.17 165);+ --amber: oklch(0.86 0.14 82);+ --danger: oklch(0.66 0.21 20);++ --wash: oklch(0.97 0.02 268);+ --grain: 0.03;+ --neon: 55%;+ --glow: 72%;+}++/* A green CRT: the grain and the glow both run hotter here on purpose. */+[data-theme='phosphor'] {+ color-scheme: dark;++ --ground: oklch(0.142 0.022 152);+ --ground-2: oklch(0.176 0.026 152);+ --surface: oklch(0.208 0.03 150);+ --surface-2: oklch(0.25 0.034 150);++ --ink: oklch(0.945 0.06 150);+ --ink-dim: oklch(0.755 0.075 150);+ --ink-faint: oklch(0.6 0.062 150);++ --line: oklch(0.9 0.12 150 / 14%);+ --line-strong: oklch(0.9 0.12 150 / 24%);++ --brand: oklch(0.86 0.2 152);+ --brand-deep: oklch(0.66 0.17 152);+ --ember: oklch(0.79 0.16 48);+ --magenta: oklch(0.74 0.2 338);+ --lime: oklch(0.9 0.2 122);+ --amber: oklch(0.87 0.16 92);+ --danger: oklch(0.66 0.2 28);++ --wash: oklch(0.92 0.1 150);+ --grain: 0.045;+ --neon: 68%;+ --glow: 85%;+}++/* Ink on paper. The inks and the named colours darken to carry on a light+ ground, the wash inverts so a card still reads as raised, and the grain+ and the neon halo — both of which only work on black — go to nothing. */+[data-theme='daylight'] {+ color-scheme: light;++ --ground: oklch(0.988 0.004 88);+ --ground-2: oklch(0.968 0.006 84);+ --surface: oklch(0.945 0.008 80);+ --surface-2: oklch(0.9 0.011 78);++ --ink: oklch(0.265 0.018 58);+ --ink-dim: oklch(0.455 0.02 56);+ --ink-faint: oklch(0.556 0.02 55);++ --line: oklch(0.3 0.02 58 / 13%);+ --line-strong: oklch(0.3 0.02 58 / 24%);++ --brand: oklch(0.514 0.12 214);+ --brand-deep: oklch(0.42 0.11 218);+ --ember: oklch(0.552 0.17 40);+ --magenta: oklch(0.53 0.2 335);+ --lime: oklch(0.52 0.14 148);+ --amber: oklch(0.562 0.13 68);+ --danger: oklch(0.54 0.2 26);++ --wash: oklch(0.32 0.02 58);+ --grain: 0;+ --neon: 0%;+ --glow: 26%;+}+:root {--background: var(--ground);--foreground: var(--ink);--card: var(--ground-2);@@ -45,7 +154,7 @@--muted-foreground: var(--ink-dim);--accent: var(--surface-2);--accent-foreground: var(--ink);- --destructive: oklch(0.645 0.205 25);+ --destructive: var(--danger);--border: var(--line);--input: var(--line-strong);--ring: var(--brand);@@ -111,6 +220,10 @@@apply border-border outline-ring/50;}+ html {+ background-color: var(--background);+ }+body {@apply bg-background text-foreground font-sans antialiased;font-feature-settings: "cv02", "cv03", "cv04", "ss01";@@ -131,7 +244,7 @@inset: 0;z-index: 100;pointer-events: none;- opacity: 0.03;+ opacity: var(--grain);background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3'/%3E%3C/filter%3E%3Crect width='160' height='160' filter='url(%23n)'/%3E%3C/svg%3E");}@@ -160,43 +273,51 @@@utility panel-card {background: linear-gradient(180deg,- oklch(0.98 0.01 60 / 4.5%),- oklch(0.98 0.01 60 / 1.5%)+ color-mix(in oklch, var(--wash) 4.5%, transparent),+ color-mix(in oklch, var(--wash) 1.5%, transparent));border: 1px solid var(--line);}/* Neon halo around text, taken from the element’s current color. */@utility neon-text {- text-shadow: 0 0 12px color-mix(in oklch, currentColor 55%, transparent);+ text-shadow: 0 0 12px color-mix(in oklch, currentColor var(--neon), transparent);}/* Glow for small indicators (status dots); color follows text color. */@utility glow-dot {- box-shadow: 0 0 8px 1px color-mix(in oklch, currentColor 75%, transparent);+ box-shadow: 0 0 8px 1px color-mix(in oklch, currentColor var(--glow), transparent);}@utility glow-brand {- box-shadow: 0 6px 26px -10px color-mix(in oklch, var(--brand) 70%, transparent);+ box-shadow: 0 6px 26px -10px color-mix(in oklch, var(--brand) var(--glow), transparent);}@utility glow-destructive {box-shadow:- 0 6px 26px -10px color-mix(in oklch, var(--destructive) 70%, transparent);+ 0 6px 26px -10px color-mix(in oklch, var(--destructive) var(--glow), transparent);}/* Backdrops for empty states and headers. */@utility dot-grid {background-image: radial-gradient(circle at 1px 1px,- oklch(0.98 0.01 60 / 9%) 1px,+ color-mix(in oklch, var(--wash) 9%, transparent) 1px,transparent 0);background-size: 22px 22px;}@utility line-grid {background-image:- linear-gradient(to right, oklch(0.98 0.01 60 / 5%) 1px, transparent 1px),- linear-gradient(to bottom, oklch(0.98 0.01 60 / 5%) 1px, transparent 1px);+ linear-gradient(+ to right,+ color-mix(in oklch, var(--wash) 5%, transparent) 1px,+ transparent 1px+ ),+ linear-gradient(+ to bottom,+ color-mix(in oklch, var(--wash) 5%, transparent) 1px,+ transparent 1px+ );background-size: 48px 48px;}@@ -309,7 +430,7 @@vertical-align: -0.12em;border-radius: 1px;background: var(--brand);- box-shadow: 0 0 10px color-mix(in oklch, var(--brand) 70%, transparent);+ box-shadow: 0 0 10px color-mix(in oklch, var(--brand) var(--glow), transparent);animation: browsentic-caret 1.05s steps(1, end) infinite;}diff --git a/src/extension/components/settings-panel.tsx b/src/extension/components/settings-panel.tsxindex c3891a6..4c5d21d 100644--- a/src/extension/components/settings-panel.tsx+++ b/src/extension/components/settings-panel.tsx@@ -2,9 +2,11 @@ import { useCallback, useEffect, useState } from 'react';import { Loader2, Lock, RefreshCw, ShieldCheck } from 'lucide-react';import { browser } from 'wxt/browser';+import { ThemePicker } from '@/extension/components/theme-picker';import { Switch } from '@/extension/components/ui/switch';import { BRIDGE_CHANNEL, type ActionResult } from '@/lib/actions/protocol';import { useDaemonState } from '@/lib/bridge/use-daemon-state';+import { useTheme } from '@/lib/bridge/use-theme';import {EFFECT_LABEL,FENCE_SETTING,@@ -19,6 +21,17 @@ import { cn } from '@/lib/utils';const EFFECTS: RuleEffect[] = ['allow', 'confirm', 'deny'];export function SettingsPanel() {+ const [theme, setTheme] = useTheme();++ return (+ <div className="space-y-6 px-3 pb-6">+ <ThemePicker theme={theme} onSelect={setTheme} />+ <Guardrails />+ </div>+ );+}++function Guardrails() {const daemon = useDaemonState();const connected = daemon?.connected ?? false;const [settings, setSettings] = useState<GuardrailSettings | null>(null);@@ -54,7 +67,7 @@ export function SettingsPanel() {}return (- <div className="space-y-5 px-3 pb-6">+ <div className="space-y-5"><header className="space-y-1.5"><div className="flex items-center justify-between gap-2"><h2 className="font-mono text-[10px] tracking-[0.14em] text-ink-faint uppercase">Guardrails</h2>@@ -262,5 +275,5 @@ function Segmented<T extends string | boolean>({}function Empty({ children }: { children: React.ReactNode }) {- return <p className="px-4 py-8 text-center text-[11px] leading-relaxed text-ink-faint">{children}</p>;+ return <p className="px-1 py-6 text-center text-[11px] leading-relaxed text-ink-faint">{children}</p>;}diff --git a/src/extension/components/theme-picker.tsx b/src/extension/components/theme-picker.tsxnew file mode 100644index 0000000..2c7cc56--- /dev/null+++ b/src/extension/components/theme-picker.tsx@@ -0,0 +1,59 @@+import { Check } from 'lucide-react';++import { THEMES, type ThemeId } from '@/lib/bridge/theme';+import { cn } from '@/lib/utils';++const ACCENTS = ['bg-brand', 'bg-ember', 'bg-lime', 'bg-amber'];++export function ThemePicker({ theme, onSelect }: { theme: ThemeId; onSelect: (theme: ThemeId) => void }) {+ return (+ <section className="space-y-2">+ <h3 className="font-mono text-[10px] tracking-[0.14em] text-ink-faint uppercase">Appearance</h3>+ <p className="text-[11px] leading-relaxed text-ink-faint">+ One click repaints the panel and the popup. Each tile is drawn in the theme it offers, so what you see is+ what you get.+ </p>++ <div className="grid grid-cols-2 gap-1.5">+ {THEMES.map(({ id, name, note }) => {+ const active = id === theme;+ return (+ <button+ key={id}+ type="button"+ data-theme={id}+ onClick={() => onSelect(id)}+ aria-pressed={active}+ className={cn(+ 'rounded-lg border bg-ground p-2 text-left transition-colors',+ active ? 'border-brand/60' : 'border-line hover:border-line-strong',+ )}+ >+ <div className="flex items-start gap-1.5">+ <div className="min-w-0 flex-1 space-y-1 rounded-md bg-surface px-1.5 py-1.5">+ <div className="h-1 w-9/12 rounded-full bg-ink/75" />+ <div className="h-1 w-6/12 rounded-full bg-ink/30" />+ <div className="flex gap-1 pt-1">+ {ACCENTS.map((accent) => (+ <span key={accent} className={cn('size-2 rounded-full', accent)} />+ ))}+ </div>+ </div>+ <span+ className={cn(+ 'mt-0.5 flex size-3.5 shrink-0 items-center justify-center rounded-full',+ active ? 'bg-brand text-ground' : 'border border-line-strong',+ )}+ >+ {active && <Check className="size-2.5" strokeWidth={3} />}+ </span>+ </div>+ <p className="mt-1.5 text-[11px] font-medium text-ink">{name}</p>+ <p className="text-[10px] leading-snug text-ink-faint">{note}</p>+ </button>+ );+ })}+ </div>+ </section>+ );+}diff --git a/src/extension/entrypoints/popup/index.html b/src/extension/entrypoints/popup/index.htmlindex 9eb1896..a54d7a3 100644--- a/src/extension/entrypoints/popup/index.html+++ b/src/extension/entrypoints/popup/index.html@@ -1,5 +1,5 @@<!doctype html>-<html lang="en" class="dark" style="background-color: #1a1512">+<html lang="en" data-theme="ember" style="background-color: #1a1512"><head><meta charset="UTF-8" /><meta name="color-scheme" content="dark" />diff --git a/src/extension/entrypoints/popup/main.tsx b/src/extension/entrypoints/popup/main.tsxindex 3d40648..0026177 100644--- a/src/extension/entrypoints/popup/main.tsx+++ b/src/extension/entrypoints/popup/main.tsx@@ -1,8 +1,11 @@import React from 'react';import ReactDOM from 'react-dom/client';import App from './App';+import { mountTheme } from '@/lib/bridge/theme';import '@/extension/assets/globals.css';+mountTheme();+ReactDOM.createRoot(document.getElementById('root')!).render(<React.StrictMode><App />diff --git a/src/extension/entrypoints/sidepanel/index.html b/src/extension/entrypoints/sidepanel/index.htmlindex 67d9200..f52ad00 100644--- a/src/extension/entrypoints/sidepanel/index.html+++ b/src/extension/entrypoints/sidepanel/index.html@@ -1,5 +1,5 @@<!doctype html>-<html lang="en" class="dark" style="background-color: #1a1512">+<html lang="en" data-theme="ember" style="background-color: #1a1512"><head><meta charset="UTF-8" /><meta name="color-scheme" content="dark" />diff --git a/src/extension/entrypoints/sidepanel/main.tsx b/src/extension/entrypoints/sidepanel/main.tsxindex 3d40648..0026177 100644--- a/src/extension/entrypoints/sidepanel/main.tsx+++ b/src/extension/entrypoints/sidepanel/main.tsx@@ -1,8 +1,11 @@import React from 'react';import ReactDOM from 'react-dom/client';import App from './App';+import { mountTheme } from '@/lib/bridge/theme';import '@/extension/assets/globals.css';+mountTheme();+ReactDOM.createRoot(document.getElementById('root')!).render(<React.StrictMode><App />diff --git a/src/lib/bridge/rail.ts b/src/lib/bridge/rail.tsindex 05e8d96..922ced4 100644--- a/src/lib/bridge/rail.ts+++ b/src/lib/bridge/rail.ts@@ -9,6 +9,7 @@ import { listRecordings } from './recording-store';import { listSessions } from './session-store';import { listSkillMeta } from './skill-store';import { PANEL_COLLAPSED_KEY, PANEL_TAB_KEY, readPanelCollapsed, readPanelTab } from './panel-view';+import { THEME_KEY, readTheme } from './theme';import { openSidePanel } from './side-panel';import { readTabSessions } from './tab-sessions';import type { DaemonState } from './socket';@@ -82,7 +83,7 @@ function post(tabId: number | undefined, discarded: boolean | undefined, command}async function describeRail(): Promise<RailView> {- const [daemon, sessions, skills, recordings, tabSessions, tab, side] = await Promise.all([+ const [daemon, sessions, skills, recordings, tabSessions, tab, side, theme] = await Promise.all([readDaemon(),listSessions(),listSkillMeta(),@@ -90,6 +91,7 @@ async function describeRail(): Promise<RailView> {readTabSessions(),readPanelTab(),readSide(),+ readTheme(),]);const live = Object.values(tabSessions).filter((session) => session.runId).length;@@ -97,6 +99,7 @@ async function describeRail(): Promise<RailView> {return {tab,+ theme,side,running: live,tone: status.tone,@@ -155,7 +158,7 @@ export function serveRail(): void {if (changed.status === 'complete') void paintTab(tabId);});browser.storage.local.onChanged.addListener((changes) => {- if (PANEL_COLLAPSED_KEY in changes || PANEL_TAB_KEY in changes) void syncRail();+ if (PANEL_COLLAPSED_KEY in changes || PANEL_TAB_KEY in changes || THEME_KEY in changes) void syncRail();});browser.storage.session.onChanged.addListener((changes) => {if (DAEMON_KEY in changes) void syncRail();diff --git a/src/lib/bridge/theme.ts b/src/lib/bridge/theme.tsnew file mode 100644index 0000000..94013a6--- /dev/null+++ b/src/lib/bridge/theme.ts@@ -0,0 +1,50 @@+import { browser } from 'wxt/browser';++export type ThemeId = 'ember' | 'midnight' | 'phosphor' | 'daylight';++export const THEMES: { id: ThemeId; name: string; note: string }[] = [+ { id: 'ember', name: 'Ember', note: 'Warm near-black, cyan brand.' },+ { id: 'midnight', name: 'Midnight', note: 'Cool blue-black, violet brand.' },+ { id: 'phosphor', name: 'Phosphor', note: 'A green CRT, grain turned up.' },+ { id: 'daylight', name: 'Daylight', note: 'Ink on paper, for a bright room.' },+];++export const DEFAULT_THEME: ThemeId = 'ember';+export const THEME_KEY = 'browsentic/theme';++/* storage.local answers a tick after the page has already painted, which on a+ light theme is a dark flash every time the popup opens. The chosen id is+ mirrored here — the one store a document can read before its first frame —+ and storage.local stays the truth that corrects it. */+const PAINT_HINT = 'browsentic/theme.paint';++export function asTheme(value: unknown): ThemeId {+ return THEMES.some((theme) => theme.id === value) ? (value as ThemeId) : DEFAULT_THEME;+}++/* index.html paints an inline ground so the frame before the stylesheet is not+ white; an inline colour outranks every rule, so hand it back to the sheet. */+export async function readTheme(): Promise<ThemeId> {+ return asTheme((await browser.storage.local.get(THEME_KEY))[THEME_KEY]);+}++export function applyTheme(theme: ThemeId) {+ document.documentElement.dataset.theme = theme;+ document.documentElement.style.backgroundColor = '';+ localStorage.setItem(PAINT_HINT, theme);+}++export async function writeTheme(theme: ThemeId) {+ applyTheme(theme);+ await browser.storage.local.set({ [THEME_KEY]: theme });+}++export function mountTheme() {+ applyTheme(asTheme(localStorage.getItem(PAINT_HINT)));++ void readTheme().then(applyTheme);++ browser.storage.local.onChanged.addListener((changes) => {+ if (THEME_KEY in changes) applyTheme(asTheme(changes[THEME_KEY].newValue));+ });+}diff --git a/src/lib/bridge/use-theme.ts b/src/lib/bridge/use-theme.tsnew file mode 100644index 0000000..57d43e5--- /dev/null+++ b/src/lib/bridge/use-theme.ts@@ -0,0 +1,31 @@+import { useCallback, useEffect, useState } from 'react';+import { browser } from 'wxt/browser';++import { asTheme, THEME_KEY, writeTheme, type ThemeId } from './theme';++export function useTheme(): [ThemeId, (theme: ThemeId) => void] {+ const [theme, setTheme] = useState<ThemeId>(() => asTheme(document.documentElement.dataset.theme));++ useEffect(() => {+ let live = true;+ void browser.storage.local+ .get(THEME_KEY)+ .then((stored) => live && setTheme(asTheme(stored[THEME_KEY])));++ const listener = (changes: Record<string, { newValue?: unknown }>) => {+ if (THEME_KEY in changes) setTheme(asTheme(changes[THEME_KEY].newValue));+ };+ browser.storage.local.onChanged.addListener(listener);+ return () => {+ live = false;+ browser.storage.local.onChanged.removeListener(listener);+ };+ }, []);++ const select = useCallback((next: ThemeId) => {+ setTheme(next);+ void writeTheme(next);+ }, []);++ return [theme, select];+}diff --git a/src/lib/rail/events.ts b/src/lib/rail/events.tsindex 371bb6b..c90aaac 100644--- a/src/lib/rail/events.ts+++ b/src/lib/rail/events.ts@@ -1,11 +1,24 @@+import type { ThemeId } from '@/lib/bridge/theme';+export const RAIL_CHANNEL = 'browsentic/rail';export type PanelTab = 'chat' | 'history' | 'skills' | 'recordings' | 'settings';export type RailTone = 'off' | 'pending' | 'live' | 'busy' | 'listening' | 'warn';+export type RailPaletteKey =+ | 'ground'+ | 'ground2'+ | 'surface'+ | 'ink'+ | 'inkDim'+ | 'inkFaint'+ | 'line'+ | 'brand';+export interface RailView {tab: PanelTab;+ theme: ThemeId;side: 'left' | 'right';running: number;tone: RailTone;@@ -83,23 +96,82 @@ export const RAIL_TABS: { id: PanelTab; label: string; paths: string[] }[] = [},];-/** The panel's tokens, spelled out — a content script has no stylesheet to read them from. */-export const RAIL_PALETTE = {- ground: 'oklch(0.152 0.016 52)',- ground2: 'oklch(0.183 0.018 50)',- surface: 'oklch(0.213 0.019 48)',- ink: 'oklch(0.958 0.012 70)',- inkDim: 'oklch(0.735 0.018 60)',- inkFaint: 'oklch(0.575 0.02 55)',- line: 'oklch(0.98 0.01 60 / 12%)',- brand: 'oklch(0.83 0.13 195)',-} as const;+/** The panel's tokens, spelled out — a content script has no stylesheet to read them+ * from. One entry per block in globals.css; a new theme there needs one here. */+export const RAIL_PALETTES: Record<ThemeId, Record<RailPaletteKey, string>> = {+ ember: {+ ground: 'oklch(0.152 0.016 52)',+ ground2: 'oklch(0.183 0.018 50)',+ surface: 'oklch(0.213 0.019 48)',+ ink: 'oklch(0.958 0.012 70)',+ inkDim: 'oklch(0.735 0.018 60)',+ inkFaint: 'oklch(0.575 0.02 55)',+ line: 'color-mix(in oklch, oklch(0.98 0.01 60) 12%, transparent)',+ brand: 'oklch(0.83 0.13 195)',+ },+ midnight: {+ ground: 'oklch(0.158 0.024 264)',+ ground2: 'oklch(0.192 0.028 264)',+ surface: 'oklch(0.228 0.032 264)',+ ink: 'oklch(0.958 0.012 268)',+ inkDim: 'oklch(0.742 0.022 266)',+ inkFaint: 'oklch(0.585 0.026 265)',+ line: 'color-mix(in oklch, oklch(0.97 0.02 268) 12%, transparent)',+ brand: 'oklch(0.79 0.15 288)',+ },+ phosphor: {+ ground: 'oklch(0.142 0.022 152)',+ ground2: 'oklch(0.176 0.026 152)',+ surface: 'oklch(0.208 0.03 150)',+ ink: 'oklch(0.945 0.06 150)',+ inkDim: 'oklch(0.755 0.075 150)',+ inkFaint: 'oklch(0.6 0.062 150)',+ line: 'color-mix(in oklch, oklch(0.92 0.1 150) 12%, transparent)',+ brand: 'oklch(0.86 0.2 152)',+ },+ daylight: {+ ground: 'oklch(0.988 0.004 88)',+ ground2: 'oklch(0.968 0.006 84)',+ surface: 'oklch(0.945 0.008 80)',+ ink: 'oklch(0.265 0.018 58)',+ inkDim: 'oklch(0.455 0.02 56)',+ inkFaint: 'oklch(0.556 0.02 55)',+ line: 'color-mix(in oklch, oklch(0.32 0.02 58) 12%, transparent)',+ brand: 'oklch(0.514 0.12 214)',+ },+};-export const RAIL_TONES: Record<RailTone, string> = {- off: 'oklch(0.575 0.02 55 / 50%)',- pending: 'oklch(0.84 0.15 85)',- live: 'oklch(0.84 0.18 150)',- busy: 'oklch(0.83 0.13 195)',- listening: 'oklch(0.7 0.21 335)',- warn: 'oklch(0.735 0.168 42)',+export const RAIL_TONES: Record<ThemeId, Record<RailTone, string>> = {+ ember: {+ off: 'color-mix(in oklch, oklch(0.575 0.02 55) 50%, transparent)',+ pending: 'oklch(0.84 0.15 85)',+ live: 'oklch(0.84 0.18 150)',+ busy: 'oklch(0.83 0.13 195)',+ listening: 'oklch(0.7 0.21 335)',+ warn: 'oklch(0.735 0.168 42)',+ },+ midnight: {+ off: 'color-mix(in oklch, oklch(0.585 0.026 265) 50%, transparent)',+ pending: 'oklch(0.86 0.14 82)',+ live: 'oklch(0.85 0.17 165)',+ busy: 'oklch(0.79 0.15 288)',+ listening: 'oklch(0.72 0.2 330)',+ warn: 'oklch(0.75 0.16 22)',+ },+ phosphor: {+ off: 'color-mix(in oklch, oklch(0.6 0.062 150) 50%, transparent)',+ pending: 'oklch(0.87 0.16 92)',+ live: 'oklch(0.9 0.2 122)',+ busy: 'oklch(0.86 0.2 152)',+ listening: 'oklch(0.74 0.2 338)',+ warn: 'oklch(0.79 0.16 48)',+ },+ daylight: {+ off: 'color-mix(in oklch, oklch(0.556 0.02 55) 50%, transparent)',+ pending: 'oklch(0.562 0.13 68)',+ live: 'oklch(0.52 0.14 148)',+ busy: 'oklch(0.514 0.12 214)',+ listening: 'oklch(0.53 0.2 335)',+ warn: 'oklch(0.552 0.17 40)',+ },};diff --git a/src/lib/rail/host.ts b/src/lib/rail/host.tsindex 25c56d6..a6a5b25 100644--- a/src/lib/rail/host.ts+++ b/src/lib/rail/host.ts@@ -1,7 +1,7 @@import { browser } from 'wxt/browser';import {RAIL_CHANNEL,- RAIL_PALETTE,+ RAIL_PALETTES,RAIL_TABS,RAIL_TONES,isRailCommand,@@ -116,6 +116,8 @@ function escape(text: string): string {function styles(view: RailView): string {const edge = view.side === 'left' ? 'left: 12px' : 'right: 12px';+ const palette = RAIL_PALETTES[view.theme];+ const tone = RAIL_TONES[view.theme][view.tone];return `:host { all: initial; }* { box-sizing: border-box; margin: 0; padding: 0; }@@ -131,12 +133,12 @@ function styles(view: RailView): string {gap: 4px;width: 44px;padding: 6px 0;- border: 1px solid ${RAIL_PALETTE.line};+ border: 1px solid ${palette.line};border-radius: 16px;- background: ${RAIL_PALETTE.ground2};+ background: ${palette.ground2};box-shadow: 0 10px 34px -12px rgb(0 0 0 / 70%), 0 0 0 1px rgb(0 0 0 / 25%);font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;- ${view.running > 0 ? `outline: 1px solid color-mix(in oklch, ${RAIL_PALETTE.brand} 45%, transparent); outline-offset: -1px;` : ''}+ ${view.running > 0 ? `outline: 1px solid color-mix(in oklch, ${palette.brand} 45%, transparent); outline-offset: -1px;` : ''}}.tab {position: relative;@@ -148,12 +150,12 @@ function styles(view: RailView): string {border: 0;border-radius: 11px;background: transparent;- color: ${RAIL_PALETTE.inkFaint};+ color: ${palette.inkFaint};cursor: pointer;transition: background-color 150ms, color 150ms;}- .tab:hover { background: ${RAIL_PALETTE.surface}; color: ${RAIL_PALETTE.ink}; }- .tab.active { background: color-mix(in oklch, ${RAIL_PALETTE.brand} 14%, transparent); color: ${RAIL_PALETTE.brand}; }+ .tab:hover { background: ${palette.surface}; color: ${palette.ink}; }+ .tab.active { background: color-mix(in oklch, ${palette.brand} 14%, transparent); color: ${palette.brand}; }.tab svg { width: 17px; height: 17px; display: block; }.mark {position: absolute;@@ -162,20 +164,20 @@ function styles(view: RailView): string {width: 6px;height: 6px;border-radius: 999px;- background: ${RAIL_PALETTE.inkFaint};+ background: ${palette.inkFaint};}.mark.busy {- background: ${RAIL_PALETTE.brand};- box-shadow: 0 0 8px 1px color-mix(in oklch, ${RAIL_PALETTE.brand} 75%, transparent);+ background: ${palette.brand};+ box-shadow: 0 0 8px 1px color-mix(in oklch, ${palette.brand} 75%, transparent);animation: browsentic-rail-pulse 1.4s ease-in-out infinite;}- .sep { width: 20px; height: 1px; background: ${RAIL_PALETTE.line}; margin: 3px 0; }+ .sep { width: 20px; height: 1px; background: ${palette.line}; margin: 3px 0; }.runs { display: flex; align-items: center; gap: 2px; flex-wrap: wrap; justify-content: center; width: 32px; }.runs i {width: 4px;height: 4px;border-radius: 999px;- background: ${RAIL_PALETTE.brand};+ background: ${palette.brand};animation: browsentic-rail-think 1.2s ease-in-out infinite;}.runs i:nth-child(2) { animation-delay: 0.16s; }@@ -184,7 +186,7 @@ function styles(view: RailView): string {width: 100%;text-align: center;font: 600 9px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace;- color: ${RAIL_PALETTE.brand};+ color: ${palette.brand};font-variant-numeric: tabular-nums;}.status {@@ -192,8 +194,8 @@ function styles(view: RailView): string {height: 7px;margin: 2px 0 1px;border-radius: 999px;- background: ${RAIL_TONES[view.tone]};- box-shadow: 0 0 8px 1px color-mix(in oklch, ${RAIL_TONES[view.tone]} 70%, transparent);+ background: ${tone};+ box-shadow: 0 0 8px 1px color-mix(in oklch, ${tone} 70%, transparent);}@keyframes browsentic-rail-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }@keyframes browsentic-rail-think {