Node-based terminal manager for AI coding agents — tmux-backed terminals and parallel agent sessions as draggable nodes on an infinite pan/zoom canvas. macOS, Linux, and a browser Server Edition.
TypeScript adhdagent-orchestrationai-agentscanvasclaude-codecodexcoding-agentsdeveloper-toolselectrongeminilinuxmacosmultiplexeropencodeparallel-agentsterminalterminal-emulatorterminal-multiplexertmuxworkspace-manager
feat(appearance): add wallpaper/glass settings and the glass contrast guarantee
iceclatterWTf2a55d0e0c86
diff --git a/src/renderer/lib/glassContrast.test.ts b/src/renderer/lib/glassContrast.test.tsnew file mode 100644index 000000000..dffdab2d9--- /dev/null+++ b/src/renderer/lib/glassContrast.test.ts@@ -0,0 +1,63 @@+import { describe, expect, it } from 'vitest'+import { TERMINAL_THEMES } from '../terminal/themes'+import {+ GLASS_ALPHA_MAX,+ GLASS_ALPHA_MIN,+ composite,+ contrastRatio,+ glassTintAlpha,+ parseHex+} from './glassContrast'++const WHITE = [255, 255, 255] as const+const BLACK = [0, 0, 0] as const++describe('glassTintAlpha', () => {+ it('hand-checked: #d4d4d4 text on a black tint needs about 0.64', () => {+ // Over white, the composite grey is (1-a)·255; contrast with #d4d4d4 (L≈0.658) reaches 4.5 when+ // the grey's luminance drops to ≈0.107, i.e. an sRGB value of ≈0.361 → a ≈ 0.639.+ const a = glassTintAlpha('#d4d4d4', '#000000')+ expect(a).toBeGreaterThan(0.63)+ expect(a).toBeLessThan(0.65)+ })++ it.each(TERMINAL_THEMES.map((t) => [t.id, t] as const))(+ '%s keeps 4.5:1 (or its own opaque contrast, if lower) over a white AND a black backdrop',+ (_id, t) => {+ const fg = parseHex(t.theme.foreground!)!+ const tint = parseHex(t.theme.background!)!+ const a = glassTintAlpha(t.theme.foreground!, t.theme.background!)+ const floor = Math.min(4.5, contrastRatio(fg, tint))+ expect(a).toBeGreaterThanOrEqual(GLASS_ALPHA_MIN)+ expect(a).toBeLessThanOrEqual(1)+ expect(contrastRatio(fg, composite(tint, WHITE, a))).toBeGreaterThanOrEqual(floor)+ expect(contrastRatio(fg, composite(tint, BLACK, a))).toBeGreaterThanOrEqual(floor)+ }+ )++ it('only the Solarized themes exceed the 0.95 design ceiling, and only Solarized Light is opaque', () => {+ const over = TERMINAL_THEMES.filter(+ (t) => glassTintAlpha(t.theme.foreground!, t.theme.background!) > GLASS_ALPHA_MAX+ ).map((t) => t.id)+ expect(over.sort()).toEqual(['solarized-dark', 'solarized-light'])+ const light = TERMINAL_THEMES.find((t) => t.id === 'solarized-light')!+ // 4.13:1 opaque — no translucent tint can reach 4.5, so glass must not make it any worse.+ expect(contrastRatio(parseHex(light.theme.foreground!)!, parseHex(light.theme.background!)!)).toBeLessThan(4.5)+ expect(glassTintAlpha(light.theme.foreground!, light.theme.background!)).toBe(1)+ })++ it('every alpha above the answer passes too (non-monotonic contrast is handled)', () => {+ const fg = parseHex('#d4d4d4')!+ const tint = parseHex('#000000')!+ const a = glassTintAlpha('#d4d4d4', '#000000')+ for (let x = a; x <= 1; x += 0.01) {+ expect(contrastRatio(fg, composite(tint, WHITE, x))).toBeGreaterThanOrEqual(4.5)+ }+ })++ it('clamps: an easy pair still gets the floor, an impossible pair goes opaque', () => {+ expect(glassTintAlpha('#ffffff', '#000000', 1.5)).toBe(GLASS_ALPHA_MIN)+ expect(glassTintAlpha('#777777', '#808080')).toBe(1)+ expect(glassTintAlpha('nope', '#000000')).toBe(GLASS_ALPHA_MAX)+ })+})diff --git a/src/renderer/lib/glassContrast.ts b/src/renderer/lib/glassContrast.tsnew file mode 100644index 000000000..f9a8f230a--- /dev/null+++ b/src/renderer/lib/glassContrast.ts@@ -0,0 +1,110 @@+/**+ * The contrast guarantee behind glass terminal nodes.+ *+ * A glass node paints the terminal theme's background as a translucent tint over whatever is+ * behind it (a wallpaper, the canvas), so the effective background of every glyph is+ * `tint·a + backdrop·(1−a)`. The backdrop is unknowable — any pixel of any wallpaper — so the alpha+ * is chosen against the two extremes: pure white and pure black. Every other backdrop pixel lies+ * between them channel-wise, and so does its composite.+ *+ * Compositing is in gamma-encoded sRGB, the way the browser blends an rgba() fill; the WCAG+ * relative luminance is computed on the result.+ *+ * Pure and platform-free (no DOM), so it runs under vitest's node environment.+ */++type Rgb = readonly [number, number, number]++/** `#rgb`, `#rrggbb` or `#rrggbbaa` (alpha ignored) → 0..255 channels; null when unparseable. */+export function parseHex(hex: string): Rgb | null {+ const m = /^#([0-9a-f]{3}|[0-9a-f]{6}|[0-9a-f]{8})$/i.exec(hex.trim())+ if (!m) return null+ let h = m[1]+ if (h.length === 3) h = h.replace(/./g, (c) => c + c)+ return [parseInt(h.slice(0, 2), 16), parseInt(h.slice(2, 4), 16), parseInt(h.slice(4, 6), 16)]+}++function channelLuminance(c: number): number {+ const s = c / 255+ return s <= 0.04045 ? s / 12.92 : Math.pow((s + 0.055) / 1.055, 2.4)+}++export function relativeLuminance([r, g, b]: Rgb): number {+ return 0.2126 * channelLuminance(r) + 0.7152 * channelLuminance(g) + 0.0722 * channelLuminance(b)+}++export function contrastRatio(a: Rgb, b: Rgb): number {+ const la = relativeLuminance(a)+ const lb = relativeLuminance(b)+ return (Math.max(la, lb) + 0.05) / (Math.min(la, lb) + 0.05)+}++/** `tint` at `alpha` over `backdrop`, in sRGB (what `background: rgba(...)` renders). */+export function composite(tint: Rgb, backdrop: Rgb, alpha: number): Rgb {+ return [0, 1, 2].map((i) => tint[i] * alpha + backdrop[i] * (1 - alpha)) as unknown as Rgb+}++export const GLASS_ALPHA_MIN = 0.55+export const GLASS_ALPHA_MAX = 0.95+const WHITE: Rgb = [255, 255, 255]+const BLACK: Rgb = [0, 0, 0]+const STEP = 0.005++function passes(fg: Rgb, tint: Rgb, alpha: number, minRatio: number): boolean {+ return (+ contrastRatio(fg, composite(tint, WHITE, alpha)) >= minRatio &&+ contrastRatio(fg, composite(tint, BLACK, alpha)) >= minRatio+ )+}++/**+ * The smallest tint alpha at which `fg` keeps `minRatio` contrast over BOTH a white and a black+ * backdrop, floored at 0.55 so the glass never gets clearer than that.+ *+ * Scanned DOWN from opaque, stopping at the first failure. Contrast is not monotonic in alpha when+ * the fg's luminance lies between the backdrop's and the tint's (light text on a dark tint over+ * white: the composite passes through the text's own grey), so a scan up from 0 could return an+ * alpha whose neighbours above it fail. Scanning down returns the bottom of the contiguous passing+ * range that reaches opaque, so every alpha at or above the answer passes.+ *+ * The design ceiling is 0.95, and for every built-in theme but the two Solarized ones the answer+ * sits under it (measured: 0.62–0.885). The guarantee outranks the ceiling, though — readable text+ * is the load-bearing requirement and "never fully opaque" is a look:+ * - Solarized Dark (opaque contrast 4.75) needs 0.985, and gets it.+ * - Solarized Light is 4.13:1 OPAQUE — under 4.5 before any glass — so no alpha passes. It gets 1:+ * the glass can only match the theme's own contrast, and 1 is the one alpha that never makes it+ * worse. `glassContrast.test.ts` pins both as named exceptions.+ * Unparseable colours get the ceiling.+ */+export function glassTintAlpha(fg: string, tint: string, minRatio = 4.5): number {+ const f = parseHex(fg)+ const t = parseHex(tint)+ if (!f || !t) return GLASS_ALPHA_MAX+ let lowest = Infinity+ for (let i = Math.round(1 / STEP); i >= 0; i--) {+ const a = i * STEP+ if (!passes(f, t, a, minRatio)) break+ lowest = a+ }+ if (lowest === Infinity) return 1+ return Math.max(GLASS_ALPHA_MIN, lowest)+}++export interface GlassTint {+ /** The node's glass fill, `rgba(r, g, b, a)`. */+ background: string+ /** The header's extra layer on top of it — slightly more opaque in total. */+ header: string+}++/** CSS for a theme's glass, or null when its background is not a colour we can parse. */+export function glassTint(theme: { background?: string; foreground?: string }): GlassTint | null {+ const bg = theme.background ? parseHex(theme.background) : null+ if (!bg) return null+ const alpha = glassTintAlpha(theme.foreground ?? '#ffffff', theme.background!)+ const rgb = bg.join(', ')+ return {+ background: `rgba(${rgb}, ${alpha.toFixed(3)})`,+ header: `rgba(${rgb}, 0.35)`+ }+}diff --git a/src/shared/types.ts b/src/shared/types.tsindex 3ff06136d..a596ab5cd 100644--- a/src/shared/types.ts+++ b/src/shared/types.ts@@ -1418,6 +1418,13 @@ export interface Settings {* (settings.json is hand-editable): an unknown id falls back to the default theme, whose* colours reproduce the pre-feature hardcoded `#1e1e1e`/`#e6e6e6` exactly. */terminalTheme: string+ /** Desktop wallpaper behind the canvas (Liquid Glass appearance). Opt-in; `none` draws the+ * canvas exactly as before. Hand-editable: read through `normalizeWallpaper` (shared/wallpaper). */+ desktopWallpaper: import('./wallpaper').DesktopWallpaper+ /** Frosted-glass terminal nodes: translucent tint + backdrop blur, with the tint's opacity+ * computed per terminal theme so text keeps WCAG 4.5:1 over any backdrop+ * (renderer/lib/glassContrast.ts). Terminal nodes only. Opt-in. */+ glassTerminals: boolean/** Weight for normal text. xterm's own default is `normal` (400). */fontWeight: number/** Weight for BOLD text. xterm's own default is `bold` (700). Lowering it is how you keep bold@@ -1851,6 +1858,8 @@ export const DEFAULT_SETTINGS: Settings = {uiScale: 1,windowTitleActiveSession: false,terminalTheme: 'nodeterm-dark',+ desktopWallpaper: { kind: 'none' },+ glassTerminals: false,fontWeight: 400,fontWeightBold: 700,drawBoldTextInBrightColors: true,diff --git a/src/shared/wallpaper.ts b/src/shared/wallpaper.tsnew file mode 100644index 000000000..d740be2e3--- /dev/null+++ b/src/shared/wallpaper.ts@@ -0,0 +1,109 @@+/**+ * Desktop wallpaper behind the canvas (the "Liquid Glass" appearance).+ *+ * Opt-in: the default is `{ kind: 'none' }`, which draws the canvas exactly as before. The value is+ * hand-editable settings.json, so every reader goes through `normalizeWallpaper` and an+ * unrecognised shape degrades to `none`, never to something else.+ *+ * Three kinds of source:+ * - `gradient:<name>` presets are pure CSS (below), so they work on every platform and in the+ * Server Edition with no image file at all.+ * - `mac:<path under /System/Library/Desktop Pictures>` presets are the stock macOS stills, read+ * from disk at runtime and NEVER bundled (they are Apple's). Converted to JPEG by `sips` in+ * core, since Chromium cannot decode HEIC.+ * - `image` is a picture the user chose, COPIED into `<userData>/wallpapers/` on import so moving+ * the original does not break it. `path` names that copy; core refuses to read anything else.+ */+export type DesktopWallpaper =+ | { kind: 'none' }+ | { kind: 'preset'; id: string }+ | { kind: 'image'; path: string }++export const NO_WALLPAPER: DesktopWallpaper = { kind: 'none' }++export interface GradientWallpaper {+ id: string+ label: string+ css: string+}++/** Built-in gradient presets — the cross-platform set (Linux, Windows, Server Edition). */+export const GRADIENT_WALLPAPERS: readonly GradientWallpaper[] = [+ {+ id: 'gradient:dusk',+ label: 'Dusk',+ css: 'linear-gradient(165deg, #1d2b64 0%, #6a3d8f 52%, #f4a6b8 100%)'+ },+ {+ id: 'gradient:aurora',+ label: 'Aurora',+ css:+ 'radial-gradient(ellipse at 22% 18%, rgba(61, 220, 151, 0.75) 0%, transparent 48%), ' ++ 'radial-gradient(ellipse at 78% 30%, rgba(90, 120, 255, 0.7) 0%, transparent 52%), ' ++ 'linear-gradient(180deg, #0b1026 0%, #172a4f 100%)'+ },+ {+ id: 'gradient:ocean',+ label: 'Ocean',+ css: 'linear-gradient(160deg, #00c6ff 0%, #0072ff 55%, #002a5c 100%)'+ },+ {+ id: 'gradient:sunrise',+ label: 'Sunrise',+ css: 'linear-gradient(180deg, #ffe29f 0%, #ffa99f 48%, #ff719a 100%)'+ },+ {+ id: 'gradient:meadow',+ label: 'Meadow',+ css: 'linear-gradient(170deg, #f1fbd8 0%, #a8e063 50%, #3f8f2a 100%)'+ },+ {+ id: 'gradient:graphite',+ label: 'Graphite',+ css: 'linear-gradient(160deg, #4b4b52 0%, #1c1c20 100%)'+ }+]++export function gradientCss(id: string): string | undefined {+ return GRADIENT_WALLPAPERS.find((g) => g.id === id)?.css+}++/** A macOS still as the picker shows it. `thumb` is a data: URL, or null when it could not be made. */+export interface WallpaperStill {+ id: string+ label: string+ thumb: string | null+}++export interface WallpaperApi {+ /** The macOS stills found on the machine that owns the files (empty off macOS). */+ listStills(): Promise<WallpaperStill[]>+ /** A data: URL for a still or an imported image; null when it cannot be read (degrade to none). */+ load(wallpaper: DesktopWallpaper): Promise<string | null>+ /** Copy (converting HEIC) a picked image into the wallpaper cache; resolves the value to store. */+ importImage(sourcePath: string): Promise<DesktopWallpaper>+}++const MAX_FIELD = 4096++/** Re-validate a hand-editable value. Anything unrecognised is `none`. */+export function normalizeWallpaper(v: unknown): DesktopWallpaper {+ if (!v || typeof v !== 'object') return NO_WALLPAPER+ const o = v as Record<string, unknown>+ if (o.kind === 'preset' && typeof o.id === 'string' && o.id.length > 0 && o.id.length < MAX_FIELD) {+ if (o.id.startsWith('gradient:') && !gradientCss(o.id)) return NO_WALLPAPER+ if (!o.id.startsWith('gradient:') && !o.id.startsWith('mac:')) return NO_WALLPAPER+ return { kind: 'preset', id: o.id }+ }+ if (o.kind === 'image' && typeof o.path === 'string' && o.path.length > 0 && o.path.length < MAX_FIELD) {+ return { kind: 'image', path: o.path }+ }+ return NO_WALLPAPER+}++export function sameWallpaper(a: DesktopWallpaper, b: DesktopWallpaper): boolean {+ if (a.kind !== b.kind) return false+ if (a.kind === 'preset') return a.id === (b as { id: string }).id+ if (a.kind === 'image') return a.path === (b as { path: string }).path+ return true+}