Skip to content

The agent that grows with you

feat(desktop): expose typed plugin settings gateway

Jony748f0398e3dd
diff --git a/apps/desktop/src/sdk/index.ts b/apps/desktop/src/sdk/index.ts
index 26a77a56bc5..6a883783936 100644
--- a/apps/desktop/src/sdk/index.ts
+++ b/apps/desktop/src/sdk/index.ts
@@ -108,6 +108,9 @@ import type { PaginatedSessions, UsageStats } from '@/types/hermes'
import { composerHost } from './composer'
import { planPluginOpenSession } from './plugin-open-session-plan'
+import { desktopSettings } from './settings'
+
+export type { DesktopSettingKey, DesktopSettingValues } from './settings'
// -- state: readonly views over the app's live atoms -------------------------
@@ -693,6 +696,9 @@ export const host = {
viewport: readonlyAtom<ViewportRect>($viewport)
},
+ /** Read, update, and observe the allowlisted Desktop appearance preferences. */
+ settings: desktopSettings,
+
/** Toast into the app's notification stack. */
notify,
notifyError,
diff --git a/apps/desktop/src/sdk/settings.test.ts b/apps/desktop/src/sdk/settings.test.ts
new file mode 100644
index 00000000000..a941845b31c
--- /dev/null
+++ b/apps/desktop/src/sdk/settings.test.ts
@@ -0,0 +1,108 @@
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
+
+import { onPersistenceEvent } from '@/lib/storage'
+import { host } from '@/sdk'
+import { $backdrop, setBackdrop } from '@/store/backdrop'
+import { $composerPopoutGesturesEnabled, setComposerPopoutGesturesEnabled } from '@/store/composer-popout'
+import { $introSplash, setIntroSplash } from '@/store/intro-splash'
+import { $reasoningCollapsedByDefault, setReasoningCollapsedByDefault } from '@/store/reasoning-disclosure'
+import { $sessionListDensity, setSessionListDensity } from '@/store/session-list-density'
+import { $tabStripDefault, setTabStripDefault } from '@/store/tabstrip-prefs'
+
+const resetSettings = () => {
+ setSessionListDensity('compact')
+ setTabStripDefault('auto')
+ setBackdrop(false)
+ setIntroSplash(true)
+ setReasoningCollapsedByDefault(false)
+ setComposerPopoutGesturesEnabled(true)
+}
+
+describe('host.settings', () => {
+ beforeEach(() => {
+ resetSettings()
+ })
+
+ afterEach(resetSettings)
+
+ it('reads and writes the allowlisted typed preferences through their owning stores', () => {
+ host.settings.set('sessionListDensity', 'detailed')
+ host.settings.set('tabStripDefault', 'always')
+ host.settings.set('backdrop.v1', true)
+ host.settings.set('intro-splash.v1', false)
+ host.settings.set('reasoning.collapsedByDefault', true)
+ host.settings.set('composerPopout.gesturesEnabled', false)
+
+ expect(host.settings.get('sessionListDensity')).toBe('detailed')
+ expect(host.settings.get('tabStripDefault')).toBe('always')
+ expect(host.settings.get('backdrop.v1')).toBe(true)
+ expect(host.settings.get('intro-splash.v1')).toBe(false)
+ expect(host.settings.get('reasoning.collapsedByDefault')).toBe(true)
+ expect(host.settings.get('composerPopout.gesturesEnabled')).toBe(false)
+
+ expect($sessionListDensity.get()).toBe('detailed')
+ expect($tabStripDefault.get()).toBe('always')
+ expect($backdrop.get()).toBe(true)
+ expect($introSplash.get()).toBe(false)
+ expect($reasoningCollapsedByDefault.get()).toBe(true)
+ expect($composerPopoutGesturesEnabled.get()).toBe(false)
+ })
+
+ it('preserves the stores existing persistence schema', () => {
+ const writes: Array<[string, null | string]> = []
+
+ const unsubscribe = onPersistenceEvent(event => {
+ if (event.op !== 'read') {
+ writes.push([event.key, event.value])
+ }
+ })
+
+ host.settings.set('sessionListDensity', 'detailed')
+ host.settings.set('tabStripDefault', 'never')
+ host.settings.set('backdrop.v1', true)
+ host.settings.set('intro-splash.v1', false)
+ host.settings.set('reasoning.collapsedByDefault', true)
+ host.settings.set('composerPopout.gesturesEnabled', false)
+
+ unsubscribe()
+
+ expect(writes).toEqual(
+ expect.arrayContaining([
+ ['hermes.desktop.sessionListDensity', 'detailed'],
+ ['hermes.desktop.tabStripDefault', 'never'],
+ ['hermes.desktop.backdrop.v1', 'true'],
+ ['hermes.desktop.intro-splash.v1', 'false'],
+ ['hermes.desktop.reasoning.collapsedByDefault', 'true'],
+ ['hermes.desktop.composerPopout.gesturesEnabled', 'false']
+ ])
+ )
+ })
+
+ it('subscribes immediately and follows changes from the native settings surface', () => {
+ const listener = vi.fn()
+ const unsubscribe = host.settings.subscribe('backdrop.v1', listener)
+
+ expect(listener).toHaveBeenLastCalledWith(false)
+
+ setBackdrop(true)
+
+ expect(listener).toHaveBeenLastCalledWith(true)
+ expect(listener).toHaveBeenCalledTimes(2)
+
+ unsubscribe()
+ setBackdrop(false)
+
+ expect(listener).toHaveBeenCalledTimes(2)
+ })
+
+ it('rejects keys and values outside the public allowlist', () => {
+ expect(() => (host.settings.get as (key: string) => unknown)('pluginDecisions.v2')).toThrow(
+ 'Unsupported desktop setting: pluginDecisions.v2'
+ )
+ expect(() => (host.settings.set as (key: string, value: unknown) => void)('backdrop.v1', 'on')).toThrow(
+ 'Invalid value for desktop setting: backdrop.v1'
+ )
+
+ expect($backdrop.get()).toBe(false)
+ })
+})
diff --git a/apps/desktop/src/sdk/settings.ts b/apps/desktop/src/sdk/settings.ts
new file mode 100644
index 00000000000..8d00ff65448
--- /dev/null
+++ b/apps/desktop/src/sdk/settings.ts
@@ -0,0 +1,90 @@
+import type { ReadableAtom } from 'nanostores'
+
+import { $backdrop, setBackdrop } from '@/store/backdrop'
+import { $composerPopoutGesturesEnabled, setComposerPopoutGesturesEnabled } from '@/store/composer-popout'
+import { $introSplash, setIntroSplash } from '@/store/intro-splash'
+import { $reasoningCollapsedByDefault, setReasoningCollapsedByDefault } from '@/store/reasoning-disclosure'
+import { $sessionListDensity, type SessionListDensity, setSessionListDensity } from '@/store/session-list-density'
+import { $tabStripDefault, setTabStripDefault, type TabStripDefault } from '@/store/tabstrip-prefs'
+
+export interface DesktopSettingValues {
+ 'backdrop.v1': boolean
+ 'composerPopout.gesturesEnabled': boolean
+ 'intro-splash.v1': boolean
+ 'reasoning.collapsedByDefault': boolean
+ sessionListDensity: SessionListDensity
+ tabStripDefault: TabStripDefault
+}
+
+export type DesktopSettingKey = keyof DesktopSettingValues
+
+interface SettingBinding<T> {
+ accepts(value: unknown): value is T
+ get(): T
+ set(value: T): void
+ subscribe(listener: (value: T) => void): () => void
+}
+
+const bindSetting = <T>(
+ $value: ReadableAtom<T>,
+ set: (value: T) => void,
+ accepts: (value: unknown) => value is T
+): SettingBinding<T> => ({
+ accepts,
+ get: () => $value.get(),
+ set,
+ subscribe: listener => $value.subscribe(value => listener(value))
+})
+
+const isBoolean = (value: unknown): value is boolean => typeof value === 'boolean'
+
+const isSessionListDensity = (value: unknown): value is SessionListDensity =>
+ value === 'compact' || value === 'comfortable' || value === 'detailed'
+
+const isTabStripDefault = (value: unknown): value is TabStripDefault =>
+ value === 'auto' || value === 'always' || value === 'never'
+
+const settingBindings = {
+ 'backdrop.v1': bindSetting($backdrop, setBackdrop, isBoolean),
+ 'composerPopout.gesturesEnabled': bindSetting(
+ $composerPopoutGesturesEnabled,
+ setComposerPopoutGesturesEnabled,
+ isBoolean
+ ),
+ 'intro-splash.v1': bindSetting($introSplash, setIntroSplash, isBoolean),
+ 'reasoning.collapsedByDefault': bindSetting($reasoningCollapsedByDefault, setReasoningCollapsedByDefault, isBoolean),
+ sessionListDensity: bindSetting($sessionListDensity, setSessionListDensity, isSessionListDensity),
+ tabStripDefault: bindSetting($tabStripDefault, setTabStripDefault, isTabStripDefault)
+} satisfies { [Key in DesktopSettingKey]: SettingBinding<DesktopSettingValues[Key]> }
+
+const bindingsByKey = settingBindings as unknown as Record<string, SettingBinding<unknown>>
+
+const bindingFor = (key: string): SettingBinding<unknown> => {
+ const binding = bindingsByKey[key]
+
+ if (!binding) {
+ throw new Error(`Unsupported desktop setting: ${key}`)
+ }
+
+ return binding
+}
+
+export const desktopSettings = {
+ get<Key extends DesktopSettingKey>(key: Key): DesktopSettingValues[Key] {
+ return bindingFor(key).get() as DesktopSettingValues[Key]
+ },
+
+ set<Key extends DesktopSettingKey>(key: Key, value: DesktopSettingValues[Key]): void {
+ const binding = bindingFor(key)
+
+ if (!binding.accepts(value)) {
+ throw new Error(`Invalid value for desktop setting: ${key}`)
+ }
+
+ binding.set(value)
+ },
+
+ subscribe<Key extends DesktopSettingKey>(key: Key, listener: (value: DesktopSettingValues[Key]) => void): () => void {
+ return bindingFor(key).subscribe(value => listener(value as DesktopSettingValues[Key]))
+ }
+}
diff --git a/website/docs/developer-guide/desktop-plugin-sdk.md b/website/docs/developer-guide/desktop-plugin-sdk.md
index bb267f8d757..bdc7509c5aa 100644
--- a/website/docs/developer-guide/desktop-plugin-sdk.md
+++ b/website/docs/developer-guide/desktop-plugin-sdk.md
@@ -629,6 +629,41 @@ host.requestProfile<T>(profile, method, params?) // legacy v1/local overload
host.request<T>(method, params?) // active-gateway JSON-RPC — the real power
```
+### Desktop appearance settings
+
+`host.settings` is the supported door for the small set of Desktop-local
+appearance preferences plugins may share with the native Settings page. Writes
+take effect immediately and persist through the preference's existing storage
+schema; `subscribe` immediately emits the current value, follows later native
+or plugin writes, and returns a disposer.
+
+```ts
+host.settings.get('sessionListDensity')
+host.settings.set('sessionListDensity', 'detailed')
+
+const dispose = host.settings.subscribe('backdrop.v1', enabled => {
+ // Runs now with the current boolean, then after each change.
+})
+```
+
+The allowlist and value types are:
+
+| Key | Value |
+|-----|-------|
+| `sessionListDensity` | `'compact' \| 'comfortable' \| 'detailed'` |
+| `tabStripDefault` | `'auto' \| 'always' \| 'never'` |
+| `backdrop.v1` | `boolean` |
+| `intro-splash.v1` | `boolean` |
+| `reasoning.collapsedByDefault` | `boolean` |
+| `composerPopout.gesturesEnabled` | `boolean` |
+
+Unsupported keys and values throw synchronously instead of writing arbitrary
+app storage. Keybinds are contributed through `KEYBINDS_AREA`; theme definitions
+use `THEMES_AREA`. Their maps and the active theme/mode record are intentionally
+not settings-gateway keys because they have separate late-contribution and
+profile/window ownership semantics. Feature-detect `host.settings` when
+supporting older Desktop builds.
+
`host.request` is the same JSON-RPC the app itself uses (sessions, config, skills,
cron, kanban, …). `host.requestProfile` accepts a descriptor from
`host.profileRoutes()` and routes that RPC through its exact registry source and
@@ -1051,7 +1086,7 @@ pipeline as a trust boundary.
| Category | Exports |
|----------|---------|
-| Host | `host` (`.state.*`, `.notify`, `.notifyError`, `.navigate`, `.onEvent`, `.logs`, `.status`, `.restartGateway`, `.request`, `.composer`) |
+| Host | `host` (`.state.*`, `.settings`, `.notify`, `.notifyError`, `.navigate`, `.onEvent`, `.logs`, `.status`, `.restartGateway`, `.request`, `.composer`) |
| Plugin contract | `HermesPlugin`, `PluginContext`, `PluginContribution`, `PluginStorage`, `PluginOs`, `PluginRestOptions`, `PluginNativeNotificationInput`, `PluginNotificationAction`, `HermesOpenTarget`, `Contribution` |
| Area constants | `PANES_AREA`, `ROUTES_AREA`, `SIDEBAR_NAV_AREA`, `STATUSBAR_AREAS`, `TITLEBAR_AREAS`, `WORKSPACE_PAGE_HEADER_AREA`, `PALETTE_AREA`, `KEYBINDS_AREA`, `THEMES_AREA`, `COMPOSER_AREAS` |
| Area payloads | `RouteContribution`, `SidebarNavContribution`, `StatusbarItem`, `TitlebarTool`, `PaletteContribution`, `KeybindContribution`, `ComposerMiddleware`, `ComposerAttachmentProvider` |