Skip to content

The agent that grows with you

refactor(desktop): accent swatches move to themes/accents.ts

alt-glitch1c578b43875b
diff --git a/apps/desktop/src/components/assistant-ui/clarify/setup-pending.test.tsx b/apps/desktop/src/components/assistant-ui/clarify/setup-pending.test.tsx
index bba6990ca6f..6dfac90674a 100644
--- a/apps/desktop/src/components/assistant-ui/clarify/setup-pending.test.tsx
+++ b/apps/desktop/src/components/assistant-ui/clarify/setup-pending.test.tsx
@@ -4,7 +4,6 @@ import { atom } from 'nanostores'
import { afterEach, beforeEach, describe, expect, it, type MockInstance, vi } from 'vitest'
import { PRIMARY_SESSION_VIEW, type SessionView, SessionViewProvider } from '@/app/chat/session-view'
-import { accentsFor, NOUS_ACCENT } from '@/components/onboarding-chat/options'
import type { HermesConnection } from '@/global'
import { I18nProvider } from '@/i18n'
import {
@@ -18,6 +17,7 @@ import { $activeGatewayProfile } from '@/store/profile'
import { rememberServerRequest, resetServerRequestsForTests } from '@/store/server-requests'
import { $connection } from '@/store/session'
import { $accentOverride } from '@/themes/accent-override'
+import { accentsFor, NOUS_ACCENT } from '@/themes/accents'
import { modePref, skinPref, ThemeProvider, useTheme } from '@/themes/context'
import { DEFAULT_SKIN_NAME } from '@/themes/presets'
import { $userThemes } from '@/themes/user-themes'
diff --git a/apps/desktop/src/components/assistant-ui/clarify/setup-pickers.tsx b/apps/desktop/src/components/assistant-ui/clarify/setup-pickers.tsx
index e01ad5bf4c7..3ba2c92fba1 100644
--- a/apps/desktop/src/components/assistant-ui/clarify/setup-pickers.tsx
+++ b/apps/desktop/src/components/assistant-ui/clarify/setup-pickers.tsx
@@ -7,7 +7,8 @@ import { type CSSProperties, type FC, type ReactNode, useId, useState } from 're
import { useSessionView } from '@/app/chat/session-view'
import { Chip } from '@/components/onboarding-chat/chip'
-import { AccentSwatch, LayoutPreviewCard, LAYOUTS, NOUS_ACCENT } from '@/components/onboarding-chat/options'
+import { LayoutPreviewCard, LAYOUTS } from '@/components/onboarding-chat/options'
+import { AccentSwatch } from '@/components/ui/accent-swatch'
import { ConnectorLogo } from '@/components/ui/connector-logo'
import { FadeScroll } from '@/components/ui/fade-scroll'
import { SearchField } from '@/components/ui/search-field'
@@ -17,6 +18,7 @@ import { cn } from '@/lib/utils'
import type { ClarifyQuestion } from '@/store/clarify'
import { pluginNeedsApp, useOnboardingPluginList } from '@/store/onboarding-plugins'
import { useTheme } from '@/themes'
+import { NOUS_ACCENT } from '@/themes/accents'
import { getBaseColors } from '@/themes/context'
import { ChoiceLabel } from './core/choice-row'
diff --git a/apps/desktop/src/components/assistant-ui/clarify/setup-rows.ts b/apps/desktop/src/components/assistant-ui/clarify/setup-rows.ts
index c61c613c40a..76a390bf9c0 100644
--- a/apps/desktop/src/components/assistant-ui/clarify/setup-rows.ts
+++ b/apps/desktop/src/components/assistant-ui/clarify/setup-rows.ts
@@ -3,7 +3,7 @@ import { useMemo } from 'react'
import { MODE_OPTIONS } from '@/app/settings/constants'
import { $chatLayoutPicked, assembleChatOnboarding, snapshotChatLayout } from '@/components/onboarding-chat/assembly'
-import { accentsFor, LAYOUTS, NOUS_ACCENT, orderConnectorPicks } from '@/components/onboarding-chat/options'
+import { LAYOUTS, orderConnectorPicks } from '@/components/onboarding-chat/options'
import type { LayoutNode } from '@/components/pane-shell/tree/model'
import { registry } from '@/contrib/registry'
import { useI18n } from '@/i18n'
@@ -14,6 +14,7 @@ import { $onboardingAnswers, setOnboardingAnswers } from '@/store/onboarding-ans
import { type OnboardingPlugin, useOnboardingPluginList } from '@/store/onboarding-plugins'
import { useTheme } from '@/themes'
import { $accentOverride, setAccentOverride } from '@/themes/accent-override'
+import { accentsFor, NOUS_ACCENT } from '@/themes/accents'
import { normalizeHex } from '@/themes/color'
import type { ThemeMode } from '@/themes/context'
import { persistAccent } from '@/themes/persist-accent'
diff --git a/apps/desktop/src/components/onboarding-chat/options.tsx b/apps/desktop/src/components/onboarding-chat/options.tsx
index d9022e30a92..b6bd9c5af08 100644
--- a/apps/desktop/src/components/onboarding-chat/options.tsx
+++ b/apps/desktop/src/components/onboarding-chat/options.tsx
@@ -1,12 +1,9 @@
import type { CSSProperties } from 'react'
import { selectableClass } from '@/components/onboarding-chat/chip'
-import { Codicon } from '@/components/ui/codicon'
-import { Tip } from '@/components/ui/tooltip'
import { IS_MAC } from '@/lib/keybinds/combo'
import { cn } from '@/lib/utils'
import type { InterfaceMode } from '@/store/interface-mode'
-import { readableInk } from '@/themes/color'
const CONNECTOR_LEAD_ORDER = [
'gmail',
@@ -38,71 +35,6 @@ export function orderConnectorPicks<T extends { connector: string; enabled?: boo
})
}
-export const NOUS_ACCENT = '#0053fd'
-
-export const accentsFor = (dark: boolean): Array<{ hex: string; name: string }> => [
- { hex: dark ? '#ffffff' : '#000000', name: 'Mono' },
- { hex: '#2ea043', name: 'GitHub green' },
- { hex: '#00d5ff', name: 'Cyber cyan' },
- { hex: NOUS_ACCENT, name: 'Nous blue' },
- { hex: '#8a2be2', name: 'Ultraviolet' },
- { hex: '#e0218a', name: 'Barbie pink' },
- { hex: '#ff073a', name: 'Electric red' },
- { hex: '#ff6a00', name: 'Safety orange' }
-]
-
-export function AccentSwatch({
- active,
- hex,
- name,
- onColorChange,
- onPick
-}: {
- active: boolean
- hex: string
- name: string
- onColorChange?: (hex: string) => void
- onPick?: () => void
-}) {
- const className = cn(
- 'relative inline-flex size-9 items-center justify-center rounded-full border border-foreground/15 transition-transform duration-150',
- !active && 'hover:scale-105'
- )
-
- const style = {
- background: hex,
- boxShadow: active ? `0 0 0 2px var(--dt-background), 0 0 0 4px ${hex}` : undefined
- }
-
- return (
- <Tip label={name}>
- {onColorChange ? (
- <label className={cn(className, 'focus-within:outline-2 focus-within:outline-ring')} style={style}>
- <span className="flex" style={{ color: readableInk(hex) }}>
- <Codicon name="add" size="1rem" />
- </span>
- <input
- aria-label={name}
- className="absolute inset-0 size-full cursor-pointer opacity-0"
- onChange={event => onColorChange(event.target.value)}
- type="color"
- value={hex}
- />
- </label>
- ) : (
- <button
- aria-label={name}
- aria-pressed={active}
- className={className}
- onClick={onPick}
- style={style}
- type="button"
- />
- )}
- </Tip>
- )
-}
-
type MiniNode = 1 | { dir: 'column' | 'row'; children: MiniNode[]; weights: number[] }
const ELITE_LAYOUT_ID = 'terminal-deck'
diff --git a/apps/desktop/src/components/ui/accent-swatch.tsx b/apps/desktop/src/components/ui/accent-swatch.tsx
new file mode 100644
index 00000000000..98c41c01809
--- /dev/null
+++ b/apps/desktop/src/components/ui/accent-swatch.tsx
@@ -0,0 +1,57 @@
+import { Codicon } from '@/components/ui/codicon'
+import { Tip } from '@/components/ui/tooltip'
+import { cn } from '@/lib/utils'
+import { readableInk } from '@/themes/color'
+
+/** One accent colour as a round swatch; with `onColorChange` it is the custom-colour well. */
+export function AccentSwatch({
+ active,
+ hex,
+ name,
+ onColorChange,
+ onPick
+}: {
+ active: boolean
+ hex: string
+ name: string
+ onColorChange?: (hex: string) => void
+ onPick?: () => void
+}) {
+ const className = cn(
+ 'relative inline-flex size-9 items-center justify-center rounded-full border border-foreground/15 transition-transform duration-150',
+ !active && 'hover:scale-105'
+ )
+
+ const style = {
+ background: hex,
+ boxShadow: active ? `0 0 0 2px var(--dt-background), 0 0 0 4px ${hex}` : undefined
+ }
+
+ return (
+ <Tip label={name}>
+ {onColorChange ? (
+ <label className={cn(className, 'focus-within:outline-2 focus-within:outline-ring')} style={style}>
+ <span className="flex" style={{ color: readableInk(hex) }}>
+ <Codicon name="add" size="1rem" />
+ </span>
+ <input
+ aria-label={name}
+ className="absolute inset-0 size-full cursor-pointer opacity-0"
+ onChange={event => onColorChange(event.target.value)}
+ type="color"
+ value={hex}
+ />
+ </label>
+ ) : (
+ <button
+ aria-label={name}
+ aria-pressed={active}
+ className={className}
+ onClick={onPick}
+ style={style}
+ type="button"
+ />
+ )}
+ </Tip>
+ )
+}
diff --git a/apps/desktop/src/themes/accents.ts b/apps/desktop/src/themes/accents.ts
new file mode 100644
index 00000000000..b649f54bbd5
--- /dev/null
+++ b/apps/desktop/src/themes/accents.ts
@@ -0,0 +1,77 @@
+/**
+ * Accent swatches and the ids the agent and the picker use for them.
+ *
+ * A swatch can paint differently per surface (Mono is black on light, white on
+ * dark), so callers resolve an id against the rendered mode at the moment of
+ * the pick. `custom:#rrggbb` names a colour that is not a swatch.
+ */
+
+export const NOUS_ACCENT = '#0053fd'
+
+export const CUSTOM_ACCENT_PREFIX = 'custom:'
+
+interface Swatch {
+ dark: string
+ id: string
+ light: string
+ name: string
+}
+
+const SWATCHES: readonly Swatch[] = [
+ { id: 'mono', name: 'Mono', light: '#000000', dark: '#ffffff' },
+ { id: 'green', name: 'GitHub green', light: '#2ea043', dark: '#2ea043' },
+ { id: 'cyan', name: 'Cyber cyan', light: '#00d5ff', dark: '#00d5ff' },
+ { id: 'nous', name: 'Nous blue', light: NOUS_ACCENT, dark: NOUS_ACCENT },
+ { id: 'violet', name: 'Ultraviolet', light: '#8a2be2', dark: '#8a2be2' },
+ { id: 'pink', name: 'Barbie pink', light: '#e0218a', dark: '#e0218a' },
+ { id: 'red', name: 'Electric red', light: '#ff073a', dark: '#ff073a' },
+ { id: 'orange', name: 'Safety orange', light: '#ff6a00', dark: '#ff6a00' }
+]
+
+export const ACCENT_SWATCH_IDS: readonly string[] = SWATCHES.map(swatch => swatch.id)
+
+export interface AccentSwatchSpec {
+ hex: string
+ id: string
+ name: string
+}
+
+export const accentsFor = (dark: boolean): AccentSwatchSpec[] =>
+ SWATCHES.map(({ dark: onDark, id, light, name }) => ({ hex: dark ? onDark : light, id, name }))
+
+/** A pick the agent or a card names: its hex on this surface and the id reported back (`null` = the theme's own). */
+export interface ResolvedAccent {
+ hex: null | string
+ id: null | string
+}
+
+/**
+ * Resolve `theme`, a swatch id, `#rrggbb` or `custom:#rrggbb` to what gets painted. Nous blue is the default
+ * skin's accent, so it resolves to the theme's own (`null`), the same as `theme`. Unknown input → `undefined`.
+ */
+export function resolveAccentPick(value: string, dark: boolean): ResolvedAccent | undefined {
+ if (value === 'theme' || value === 'nous') {
+ return { hex: null, id: null }
+ }
+
+ const swatch = accentsFor(dark).find(candidate => candidate.id === value)
+
+ if (swatch) {
+ return { hex: swatch.hex, id: swatch.id }
+ }
+
+ const raw = value.startsWith(CUSTOM_ACCENT_PREFIX) ? value.slice(CUSTOM_ACCENT_PREFIX.length) : value
+
+ if (!/^#[0-9a-f]{6}$/i.test(raw)) {
+ return undefined
+ }
+
+ const hex = raw.toLowerCase()
+
+ return hex === NOUS_ACCENT ? { hex: null, id: null } : { hex, id: `${CUSTOM_ACCENT_PREFIX}${hex}` }
+}
+
+/** The name a settled card shows for a reported accent id. */
+export function accentName(id: string): string {
+ return SWATCHES.find(swatch => swatch.id === id)?.name ?? id.replace(CUSTOM_ACCENT_PREFIX, '')
+}