Skip to content

The agent that grows with you

feat(desktop): the boot-failure notice wears the Hermes wordmark and theme colours

dokterdokee987d9885d9
diff --git a/apps/desktop/src/lib/boot-failure.test.ts b/apps/desktop/src/lib/boot-failure.test.ts
index 87526850bc5..6092caddd1a 100644
--- a/apps/desktop/src/lib/boot-failure.test.ts
+++ b/apps/desktop/src/lib/boot-failure.test.ts
@@ -1,3 +1,4 @@
+import collapseBold from '@nous-research/ui/fonts/Collapse-Bold.woff2?url'
import { within } from '@testing-library/dom'
import { afterEach, beforeEach, expect, it, vi } from 'vitest'
@@ -5,8 +6,12 @@ import { showBootFailure } from './boot-failure'
import { bootRenderer } from './ui-preferences/boot'
let root: HTMLDivElement
+const fontsDescriptor = Object.getOwnPropertyDescriptor(document, 'fonts')
beforeEach(() => {
+ localStorage.clear()
+ vi.stubGlobal('FontFace', undefined)
+ Object.defineProperty(document, 'fonts', { configurable: true, value: undefined })
root = document.createElement('div')
root.id = 'root'
document.body.append(root)
@@ -17,6 +22,13 @@ afterEach(() => {
root.remove()
window.history.replaceState(null, '', '/')
vi.restoreAllMocks()
+ vi.unstubAllGlobals()
+
+ if (fontsDescriptor) {
+ Object.defineProperty(document, 'fonts', fontsDescriptor)
+ } else {
+ Reflect.deleteProperty(document, 'fonts')
+ }
})
it('shows a rejected loader’s cause and reloads only when the user clicks Reload', async () => {
@@ -27,7 +39,9 @@ it('shows a rejected loader’s cause and reloads only when the user clicks Relo
expect(console.error).toHaveBeenCalledWith('Hermes failed to load', error)
expect(within(root).getByRole('heading', { level: 1 }).textContent).toBe('Hermes couldn’t load')
- expect(within(root).getByRole('alert').textContent).toContain('Part of the app didn’t load; reloading usually fixes it.')
+ expect(within(root).getByRole('alert').textContent).toContain(
+ 'Part of the app didn’t load; reloading usually fixes it.'
+ )
// The notice stays the page's main landmark; only its message is the alert.
expect(within(root).getByRole('main').contains(within(root).getByRole('alert'))).toBe(true)
@@ -62,18 +76,177 @@ it('uses no inline handler attributes under script-src-attr none', () => {
}
})
-it.each(['hud', 'overlay', 'quick', 'wake'])('only logs in the transparent %s window, which cannot show a notice', kind => {
- window.history.replaceState(null, '', `/?win=${kind}`)
- const error = new Error('Overlay chunk failed')
+it.each(['hud', 'overlay', 'quick', 'wake'])(
+ 'only logs in the transparent %s window, which cannot show a notice',
+ kind => {
+ window.history.replaceState(null, '', `/?win=${kind}`)
+ const error = new Error('Overlay chunk failed')
- showBootFailure(error, vi.fn())
+ showBootFailure(error, vi.fn())
- expect(root.childNodes).toHaveLength(0)
- expect(console.error).toHaveBeenCalledWith('Hermes failed to load', error)
-})
+ expect(root.childNodes).toHaveLength(0)
+ expect(console.error).toHaveBeenCalledWith('Hermes failed to load', error)
+ }
+)
it('shows the notice in an opaque secondary window', () => {
window.history.replaceState(null, '', '/?win=secondary')
showBootFailure(new Error('Session window chunk failed'), vi.fn())
expect(within(root).getByRole('button', { name: 'Reload' })).toBeTruthy()
})
+
+it('shows a decorative wordmark above the accessible heading without app CSS', () => {
+ showBootFailure(new Error('CSS failed'), vi.fn())
+
+ const wordmark = within(root).getByText('HERMES AGENT')
+ const heading = within(root).getByRole('heading', { level: 1, name: 'Hermes couldn’t load' })
+ const alert = within(root).getByRole('alert')
+ expect(wordmark.tagName).toBe('P')
+ expect(wordmark.getAttribute('aria-hidden')).toBe('true')
+ expect(wordmark.nextElementSibling).toBe(alert)
+ expect(alert.contains(heading)).toBe(true)
+ expect(within(root).getByRole('main').getAttribute('lang')).toBe('en')
+ expect(wordmark.style.fontFamily).toBe('Collapse, system-ui, sans-serif')
+ expect(wordmark.style.fontWeight).toBe('700')
+ expect(wordmark.style.letterSpacing).toBe('0.08em')
+ expect(wordmark.style.lineHeight).toBe('0.9')
+ expect(wordmark.style.textTransform).toBe('uppercase')
+ expect(wordmark.style.marginBottom).toBe('24px')
+ expect(heading.style.fontSize).toBe('1.125rem')
+ expect(heading.style.fontWeight).toBe('600')
+ const message = within(alert).getByText('Part of the app didn’t load; reloading usually fixes it.')
+ expect(message.style.fontSize).toBe('0.875rem')
+ expect(message.style.opacity).toBe('0.7')
+ const button = within(root).getByRole('button', { name: 'Reload' })
+ expect(button.style.borderRadius).toBe('2.5px')
+ expect(button.style.padding).toBe('8px 20px')
+ expect(button.style.fontWeight).toBe('500')
+ expect(button.style.fontSize).toBe('0.875rem')
+ expect(button.style.lineHeight).toBe('1.25rem')
+})
+
+const palette = {
+ background: 'rgb(13, 17, 23)',
+ foreground: 'rgb(230, 237, 243)',
+ accent: 'rgb(88, 166, 255)',
+ accentForeground: 'rgb(13, 17, 23)'
+}
+
+it('paints its own background and ink from the theme snapshot, whatever the page behind it shows', () => {
+ localStorage.setItem('hermes-boot-palette', JSON.stringify(palette))
+ // The app's stylesheet loaded without the theme (its JS failed) and painted a light page.
+ document.body.style.background = 'rgb(248, 249, 254)'
+ showBootFailure(new Error('JS chunk failed'), vi.fn())
+
+ const notice = within(root).getByRole('main')
+ expect(notice.style.backgroundColor).toBe(palette.background)
+ expect(notice.style.color).toBe(palette.foreground)
+ expect(notice.style.position).toBe('fixed')
+ expect(notice.style.inset).toBe('0px')
+ expect(within(root).getByText('HERMES AGENT').style.color).toBe(palette.accent)
+ const button = within(root).getByRole('button', { name: 'Reload' })
+ expect(button.style.backgroundColor).toBe(palette.accent)
+ expect(button.style.color).toBe(palette.accentForeground)
+ expect(getComputedStyle(button).borderTopStyle).toBe('none')
+ document.body.style.removeProperty('background')
+})
+
+it.each([
+ ['no snapshot', null],
+ ['a malformed snapshot', '{"background":'],
+ ['a snapshot missing its ink', JSON.stringify({ ...palette, accentForeground: '' })],
+ ['an unresolved var() accent', JSON.stringify({ ...palette, accent: 'var(--theme-primary)' })],
+ ['throwing storage', 'throw']
+])('inherits the page colours and keeps an outlined button with %s', (_case, stored) => {
+ if (stored === 'throw') {
+ vi.stubGlobal('localStorage', {
+ getItem() {
+ throw new Error('Storage unavailable')
+ }
+ })
+ } else if (stored !== null) {
+ localStorage.setItem('hermes-boot-palette', stored)
+ }
+
+ expect(() => showBootFailure(new Error('CSS failed'), vi.fn())).not.toThrow()
+ const notice = within(root).getByRole('main')
+ expect(notice.style.backgroundColor).toBe('')
+ expect(notice.style.color).toBe('')
+ expect(notice.style.position).toBe('')
+ expect(within(root).getByText('HERMES AGENT').style.color).toBe('currentcolor')
+ const button = within(root).getByRole('button', { name: 'Reload' })
+ expect(button.style.backgroundColor).toBe('transparent')
+ expect(button.style.color).toBe('inherit')
+ expect(button.style.borderTopWidth).toBe('1px')
+ expect(button.style.borderTopStyle).toBe('solid')
+ expect(button.style.borderTopColor).toBe('currentcolor')
+})
+
+it('registers the bundled Collapse face without waiting to show recovery', () => {
+ const face = { load: vi.fn(() => new Promise(() => {})) }
+
+ const FontFace = vi.fn(function () {
+ return face
+ })
+
+ const add = vi.fn()
+ vi.stubGlobal('FontFace', FontFace)
+ Object.defineProperty(document, 'fonts', { configurable: true, value: { add } })
+
+ showBootFailure(new Error('CSS failed'), vi.fn())
+
+ expect(FontFace).toHaveBeenCalledWith('Collapse', `url("${collapseBold}")`, { weight: '700', display: 'swap' })
+ expect(add).toHaveBeenCalledWith(face)
+ expect(face.load).toHaveBeenCalledOnce()
+ expect(within(root).getByRole('button', { name: 'Reload' })).toBeTruthy()
+})
+
+it.each(['FontFace', 'document.fonts'])('shows recovery when %s is unavailable', missing => {
+ const FontFace = vi.fn()
+ const add = vi.fn()
+ vi.stubGlobal('FontFace', missing === 'FontFace' ? undefined : FontFace)
+ Object.defineProperty(document, 'fonts', {
+ configurable: true,
+ value: missing === 'document.fonts' ? undefined : { add }
+ })
+
+ expect(() => showBootFailure(new Error('CSS failed'), vi.fn())).not.toThrow()
+ expect(FontFace).not.toHaveBeenCalled()
+ expect(add).not.toHaveBeenCalled()
+ expect(within(root).getByText('HERMES AGENT').style.fontFamily).toContain('system-ui')
+})
+
+it.each(['constructor', 'load', 'rejection'])('keeps recovery usable after a font %s failure', async failure => {
+ const error = new Error('Font unavailable')
+
+ const face = {
+ load: vi.fn(() => {
+ if (failure === 'load') {
+ throw error
+ }
+
+ return Promise.reject(error)
+ })
+ }
+
+ vi.stubGlobal(
+ 'FontFace',
+ vi.fn(function () {
+ if (failure === 'constructor') {
+ throw error
+ }
+
+ return face
+ })
+ )
+ Object.defineProperty(document, 'fonts', { configurable: true, value: { add: vi.fn() } })
+ const reload = vi.fn()
+
+ showBootFailure(new Error('CSS failed'), reload)
+ // Let a rejected font request settle; Vitest also fails on unhandled rejections.
+ await new Promise(resolve => setTimeout(resolve, 0))
+
+ expect(reload).not.toHaveBeenCalled()
+ within(root).getByRole('button', { name: 'Reload' }).click()
+ expect(reload).toHaveBeenCalledOnce()
+})
diff --git a/apps/desktop/src/lib/boot-failure.ts b/apps/desktop/src/lib/boot-failure.ts
index dd3d9c62c30..b5952ac1683 100644
--- a/apps/desktop/src/lib/boot-failure.ts
+++ b/apps/desktop/src/lib/boot-failure.ts
@@ -1,5 +1,42 @@
+import collapseBold from '@nous-research/ui/fonts/Collapse-Bold.woff2?url'
+
import { isTransparentWindow } from './transparent-windows'
+type BootPalette = Record<'accent' | 'accentForeground' | 'background' | 'foreground', string>
+
+/** The theme's snapshot that themes/boot-palette.ts writes, or null. Kept here rather than
+ * imported, so the renderer entry never needs another chunk before it can show this notice. */
+export function readBootPalette(): BootPalette | null {
+ try {
+ const value: unknown = JSON.parse(localStorage.getItem('hermes-boot-palette') ?? 'null')
+ const fields = ['accent', 'accentForeground', 'background', 'foreground'] as const
+
+ const standalone = (field: (typeof fields)[number]) => {
+ const color: unknown = (value as Partial<BootPalette>)[field]
+
+ return typeof color === 'string' && color.trim() !== '' && !/var\(/i.test(color)
+ }
+
+ return typeof value === 'object' && value !== null && fields.every(standalone) ? (value as BootPalette) : null
+ } catch {
+ return null
+ }
+}
+
+async function loadWordmarkFont(): Promise<void> {
+ if (typeof FontFace === 'undefined' || !document.fonts) {
+ return
+ }
+
+ try {
+ const face = new FontFace('Collapse', `url("${collapseBold}")`, { weight: '700', display: 'swap' })
+ document.fonts.add(face)
+ await face.load()
+ } catch {
+ // The font is optional: a failed request must leave the system lettering usable.
+ }
+}
+
// Keep this independent of the app graph: its JavaScript or CSS may have failed to load.
export function showBootFailure(error: unknown, reload: () => void = () => location.reload()): void {
console.error('Hermes failed to load', error)
@@ -12,9 +49,20 @@ export function showBootFailure(error: unknown, reload: () => void = () => locat
return
}
+ // With the theme's snapshot the notice paints its own background as well as its ink, so the
+ // pair holds whatever the app's stylesheet did or did not paint behind it. Without one it
+ // inherits the page's colours.
+ const palette = readBootPalette()
const notice = document.createElement('main')
notice.lang = 'en'
Object.assign(notice.style, {
+ ...(palette && {
+ background: palette.background,
+ color: palette.foreground,
+ inset: '0',
+ overflow: 'auto',
+ position: 'fixed'
+ }),
alignItems: 'center',
boxSizing: 'border-box',
colorScheme: 'inherit',
@@ -27,25 +75,47 @@ export function showBootFailure(error: unknown, reload: () => void = () => locat
textAlign: 'center'
})
+ const wordmark = document.createElement('p')
+ wordmark.textContent = 'HERMES AGENT'
+ wordmark.setAttribute('aria-hidden', 'true')
+ Object.assign(wordmark.style, {
+ color: palette?.accent ?? 'currentColor',
+ fontFamily: 'Collapse, system-ui, sans-serif',
+ fontSize: 'clamp(2.5rem, 9vw, 6rem)',
+ fontWeight: '700',
+ letterSpacing: '0.08em',
+ lineHeight: '0.9',
+ margin: '0 0 24px',
+ textTransform: 'uppercase'
+ })
+
// English is intentional: i18n lives in the app graph that failed to load.
const heading = document.createElement('h1')
heading.textContent = 'Hermes couldn’t load'
- heading.style.cssText = 'font-size: 1.5em; margin: 0'
+ heading.style.cssText = 'color: inherit; font-size: 1.125rem; font-weight: 600; margin: 0'
const message = document.createElement('p')
message.textContent = 'Part of the app didn’t load; reloading usually fixes it.'
- message.style.cssText = 'margin: 16px 0; max-width: 36em'
+ message.style.cssText = 'font-size: 0.875rem; opacity: 0.7; margin: 16px 0; max-width: 36em'
const button = document.createElement('button')
button.type = 'button'
button.textContent = 'Reload'
- button.style.cssText =
- 'font: inherit; color: inherit; background: transparent; border: 1px solid currentColor; padding: 8px 16px; cursor: pointer'
+ Object.assign(button.style, {
+ font: '500 0.875rem/1.25rem system-ui, sans-serif',
+ color: palette?.accentForeground ?? 'inherit',
+ background: palette?.accent ?? 'transparent',
+ border: palette ? 'none' : '1px solid currentColor',
+ borderRadius: '2.5px',
+ padding: '8px 20px',
+ cursor: 'pointer'
+ })
button.addEventListener('click', () => reload())
const alert = document.createElement('div')
alert.setAttribute('role', 'alert')
alert.append(heading, message)
- notice.append(alert, button)
+ notice.append(wordmark, alert, button)
root.append(notice)
+ void loadWordmarkFont()
}
diff --git a/apps/desktop/src/themes/boot-palette.test.ts b/apps/desktop/src/themes/boot-palette.test.ts
new file mode 100644
index 00000000000..c75323a7c76
--- /dev/null
+++ b/apps/desktop/src/themes/boot-palette.test.ts
@@ -0,0 +1,50 @@
+import { afterEach, beforeEach, expect, it, vi } from 'vitest'
+
+import { readBootPalette } from '../lib/boot-failure'
+
+import { writeBootPalette } from './boot-palette'
+
+const palette = { background: '#0d1117', foreground: '#e6edf3', accent: '#58a6ff', accentForeground: '#0d1117' }
+
+beforeEach(() => localStorage.clear())
+afterEach(() => {
+ vi.restoreAllMocks()
+ vi.unstubAllGlobals()
+})
+
+it('writes the palette as one snapshot and reads it back', () => {
+ writeBootPalette(palette)
+ expect(JSON.parse(localStorage.getItem('hermes-boot-palette')!)).toEqual(palette)
+ expect(readBootPalette()).toEqual(palette)
+})
+
+it.each([
+ ['an unresolved var()', { ...palette, accent: 'var(--theme-primary)' }],
+ ['a var() inside a colour function', { ...palette, background: 'color-mix(in srgb, var(--x) 50%, white)' }],
+ ['an empty colour', { ...palette, foreground: ' ' }]
+])('drops the previous snapshot instead of storing %s', (_case, next) => {
+ writeBootPalette(palette)
+ writeBootPalette(next)
+ expect(localStorage.getItem('hermes-boot-palette')).toBeNull()
+ expect(readBootPalette()).toBeNull()
+})
+
+it('drops the previous snapshot when the new one cannot be written', () => {
+ // A stand-in storage, so the failing write does not depend on the environment's Storage.
+ const items = new Map([['hermes-boot-palette', JSON.stringify(palette)]])
+ vi.stubGlobal('localStorage', {
+ getItem: (key: string) => items.get(key) ?? null,
+ removeItem: (key: string) => items.delete(key),
+ setItem: () => {
+ throw new DOMException('Quota exceeded', 'QuotaExceededError')
+ }
+ })
+ writeBootPalette({ ...palette, background: '#ffffff', foreground: '#1f2328' })
+ expect(items.has('hermes-boot-palette')).toBe(false)
+})
+
+it('keeps self-contained colour functions', () => {
+ const functional = { ...palette, accent: 'oklch(0.7 0.15 250)', background: 'color-mix(in srgb, #000 90%, white)' }
+ writeBootPalette(functional)
+ expect(readBootPalette()).toEqual(functional)
+})
diff --git a/apps/desktop/src/themes/boot-palette.ts b/apps/desktop/src/themes/boot-palette.ts
new file mode 100644
index 00000000000..4a81c7752ec
--- /dev/null
+++ b/apps/desktop/src/themes/boot-palette.ts
@@ -0,0 +1,30 @@
+// The theme colours the boot-failure notice (src/lib/boot-failure.ts) paints itself with when
+// the app could not load. Written as one snapshot, so a failed write can never pair one theme's
+// background with another's ink, and only when each colour stands alone: a `var()` resolves to
+// nothing without the app's styles. The notice reads the same key with its own copy of this
+// check, so the renderer entry never fetches theme code; boot-palette.test.ts round-trips them.
+const KEY = 'hermes-boot-palette'
+
+export interface BootPalette {
+ background: string
+ foreground: string
+ accent: string
+ accentForeground: string
+}
+
+export function writeBootPalette(palette: BootPalette): void {
+ try {
+ if (Object.values(palette).every(value => value.trim() !== '' && !/var\(/i.test(value))) {
+ localStorage.setItem(KEY, JSON.stringify(palette))
+ } else {
+ localStorage.removeItem(KEY)
+ }
+ } catch {
+ // A write that failed must not leave an older theme's snapshot behind.
+ try {
+ localStorage.removeItem(KEY)
+ } catch {
+ // Storage is unavailable: the notice stays neutral.
+ }
+ }
+}
diff --git a/apps/desktop/src/themes/context.test.tsx b/apps/desktop/src/themes/context.test.tsx
index db40de13fae..36626e59347 100644
--- a/apps/desktop/src/themes/context.test.tsx
+++ b/apps/desktop/src/themes/context.test.tsx
@@ -2,6 +2,7 @@ import { act, cleanup, render } from '@testing-library/react'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { $backendThemes, __resetBackendSkinSync, ingestBackendSkin } from './backend-sync'
+import { readableInk } from './color'
import { skinPref, ThemeProvider, useTheme } from './context'
import { everforestTheme, midnightTheme } from './presets'
import type { DesktopTheme } from './types'
@@ -413,3 +414,59 @@ function ThemeProbe({ onReady }: { onReady: (ctx: ReturnType<typeof useTheme>) =
return null
}
+
+describe('ThemeProvider boot-failure palette', () => {
+ beforeEach(() => {
+ window.localStorage.clear()
+ __resetBackendSkinSync()
+ })
+
+ afterEach(cleanup)
+
+ it.each([true, false])('persists the resolved colours with explicit midground tokens: %s', explicit => {
+ const colors = {
+ ...midnightTheme.colors,
+ foreground: '#123456',
+ ring: '#eeeeee',
+ midground: explicit ? '#234567' : undefined,
+ midgroundForeground: explicit ? '#fedcba' : undefined
+ }
+
+ installUserTheme({ ...midnightTheme, name: 'boot-palette', colors, darkColors: colors })
+ let ctx: ReturnType<typeof useTheme>
+ render(
+ <ThemeProvider>
+ <ThemeProbe onReady={value => (ctx = value)} />
+ </ThemeProvider>
+ )
+
+ act(() => ctx!.setTheme('boot-palette'))
+
+ const midground = colors.midground ?? colors.ring
+ const snapshot = JSON.parse(window.localStorage.getItem('hermes-boot-palette')!)
+ expect(snapshot).toEqual({
+ background: window.localStorage.getItem('hermes-boot-background'),
+ foreground: colors.foreground,
+ accent: midground,
+ accentForeground: colors.midgroundForeground ?? readableInk(midground)
+ })
+ expect(snapshot.accentForeground).toBe(cssVar('--dt-midground-foreground'))
+ })
+
+ it('stores no snapshot for a theme whose accent is a var() the notice could not resolve', () => {
+ window.localStorage.setItem('hermes-boot-palette', '{"stale":true}')
+ const colors = { ...midnightTheme.colors, midground: 'var(--theme-primary)', midgroundForeground: '#161616' }
+ installUserTheme({ ...midnightTheme, name: 'boot-palette-var', colors, darkColors: colors })
+ let ctx: ReturnType<typeof useTheme>
+ render(
+ <ThemeProvider>
+ <ThemeProbe onReady={value => (ctx = value)} />
+ </ThemeProvider>
+ )
+
+ act(() => ctx!.setTheme('boot-palette-var'))
+
+ expect(window.localStorage.getItem('hermes-boot-palette')).toBeNull()
+ expect(window.localStorage.getItem('hermes-boot-background')).not.toBeNull()
+ })
+})
diff --git a/apps/desktop/src/themes/context.tsx b/apps/desktop/src/themes/context.tsx
index c3422a9b01b..d8fb990816b 100644
--- a/apps/desktop/src/themes/context.tsx
+++ b/apps/desktop/src/themes/context.tsx
@@ -29,6 +29,7 @@ import {
localDisplaySkinName,
localDisplaySkinProfile
} from './backend-sync'
+import { writeBootPalette } from './boot-palette'
import { $chatFontFamily, resolveChatFontFamily } from './chat-font'
import { harmonize, normalizeHex, readableInk } from './color'
import { BUILTIN_THEME_LIST, DEFAULT_SKIN_NAME, DEFAULT_TYPOGRAPHY, nousTheme, RETIRED_SKINS } from './presets'
@@ -409,6 +410,13 @@ function applyTheme(theme: DesktopTheme, mode: 'light' | 'dark', chatFontFamily
// falls back to prefers-color-scheme.
}
+ writeBootPalette({
+ background: chromeBg,
+ foreground: c.foreground,
+ accent: midground,
+ accentForeground: palette['--dt-midground-foreground']
+ })
+
if (typo.fontUrl && !INJECTED_FONT_URLS.has(typo.fontUrl)) {
const link = document.createElement('link')
link.rel = 'stylesheet'