The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): mirror the Appearance switches on connect, not just on change
Brooklyn Nicholsonc42daab67b8c
diff --git a/apps/desktop/src/store/display-toggles.test.ts b/apps/desktop/src/store/display-toggles.test.tsnew file mode 100644index 00000000000..ac0e0b83259--- /dev/null+++ b/apps/desktop/src/store/display-toggles.test.ts@@ -0,0 +1,51 @@+import { atom } from 'nanostores'+import { beforeEach, describe, expect, it, vi } from 'vitest'++const $gateway = atom<unknown>(null)+const request = vi.fn(async () => undefined)++vi.mock('@/store/gateway', () => ({+ $gateway,+ activeGateway: () => ({ request })+}))++const { mirrorDisplayToggle } = await import('./display-toggles')++const STORAGE_KEY = 'hermes.desktop.test-toggle.v1'++const $enabled = atom(true)++mirrorDisplayToggle('display.test_toggle', STORAGE_KEY, $enabled)++const sets = () => request.mock.calls.filter(([method]) => method === 'config.set').map(([, params]) => params)++beforeEach(() => {+ localStorage.clear()+ request.mockClear()+ $enabled.set(true)+ request.mockClear()+})++describe('display toggle mirror', () => {+ it('sends the user answer to the gateway when it changes', () => {+ $enabled.set(false)++ expect(sets()).toEqual([{ key: 'display.test_toggle', value: 'false' }])+ })++ it('re-sends a touched setting to a gateway that has never seen it', () => {+ localStorage.setItem(STORAGE_KEY, 'false')+ $enabled.set(false)+ request.mockClear()++ $gateway.set({})++ expect(sets()).toEqual([{ key: 'display.test_toggle', value: 'false' }])+ })++ it('leaves an untouched setting alone, so a hand-edited config.yaml wins', () => {+ $gateway.set({})++ expect(sets()).toEqual([])+ })+})diff --git a/apps/desktop/src/store/display-toggles.ts b/apps/desktop/src/store/display-toggles.tsnew file mode 100644index 00000000000..011fc52c5d5--- /dev/null+++ b/apps/desktop/src/store/display-toggles.ts@@ -0,0 +1,68 @@+/**+ * Appearance switches the BACKEND also has to know about.+ *+ * Most of what Settings → Appearance controls is the renderer's own business.+ * A few switches aren't: they decide whether a tool is in the model's schema at+ * all (`react_to_message`, `tip`, `tour`), and that decision is made where the+ * agent runs. So the value has to travel to whichever gateway the app is+ * actually talking to — local, SSH, plain URL, or cloud — which is why this is+ * `config.set` on the live connection and not an env var on some process.+ *+ * Two moments matter, and shipping only the first is why the reactions toggle+ * has never worked end to end:+ *+ * - **On change**, because that is the user answering.+ * - **On connect**, because a gateway the app has never spoken to holds no+ * answer at all — and for a switch that defaults ON, silence reads as consent+ * to exactly the thing the user turned off.+ *+ * The connect push is deliberately narrow: only settings the user has actually+ * touched (a stored value exists) are re-sent. Otherwise a fresh install would+ * broadcast its defaults over a `config.yaml` somebody hand-edited on the+ * server, which is a worse failure than the one being fixed.+ */++import type { ReadableAtom } from 'nanostores'++import { readKey } from '@/lib/storage'+import { $gateway, activeGateway } from '@/store/gateway'++interface Mirror {+ configKey: string+ read: () => boolean+ storageKey: string+}++const mirrors: Mirror[] = []++function push(mirror: Mirror): void {+ void activeGateway()+ ?.request('config.set', { key: mirror.configKey, value: mirror.read() ? 'true' : 'false' })+ .catch(() => {+ // Not connected, or a gateway too old to know the key. The next toggle+ // and the next connection both try again.+ })+}++/** Keep `display.<configKey>` on the live gateway in step with a renderer atom. */+export function mirrorDisplayToggle(configKey: string, storageKey: string, $enabled: ReadableAtom<boolean>): void {+ if (typeof window === 'undefined') {+ return+ }++ const mirror: Mirror = { configKey, read: () => $enabled.get(), storageKey }++ mirrors.push(mirror)+ // listen, not subscribe: fire on CHANGE only. Module init must not write.+ $enabled.listen(() => push(mirror))+}++if (typeof window !== 'undefined') {+ $gateway.listen(() => {+ for (const mirror of mirrors) {+ if (readKey(mirror.storageKey) !== null) {+ push(mirror)+ }+ }+ })+}diff --git a/apps/desktop/src/store/reactions-enabled.ts b/apps/desktop/src/store/reactions-enabled.tsindex 66870760651..5adea9a4e3d 100644--- a/apps/desktop/src/store/reactions-enabled.ts+++ b/apps/desktop/src/store/reactions-enabled.ts@@ -13,7 +13,7 @@import { atom } from 'nanostores'import { persistString, storedString } from '@/lib/storage'-import { activeGateway } from '@/store/gateway'+import { mirrorDisplayToggle } from '@/store/display-toggles'const KEY = 'hermes.desktop.reactions.v1'@@ -24,17 +24,9 @@ export function setReactionsEnabled(enabled: boolean): void {}if (typeof window !== 'undefined') {- // listen, not subscribe: fire on CHANGE only, so app startup doesn't write- // config.set (or clobber a profile's setting with another window's default).- $reactionsEnabled.listen(enabled => {- persistString(KEY, enabled ? 'on' : 'off')- // Mirror into gateway config: the backend gates the agent's- // react_to_message tool and the model-context annotation on- // display.message_reactions, so the renderer toggle is the one lever.- void activeGateway()- ?.request('config.set', { key: 'display.message_reactions', value: enabled ? 'true' : 'false' })- .catch(() => {- // Not connected yet — the next toggle (or default-off) still holds.- })- })+ $reactionsEnabled.listen(enabled => persistString(KEY, enabled ? 'on' : 'off'))}++// The backend gates the agent's react_to_message tool and the model-context+// annotation on display.message_reactions, so this toggle is the one lever.+mirrorDisplayToggle('display.message_reactions', KEY, $reactionsEnabled)diff --git a/apps/desktop/src/store/tips.ts b/apps/desktop/src/store/tips.tsindex e09d605b2a7..1003e100d1d 100644--- a/apps/desktop/src/store/tips.ts+++ b/apps/desktop/src/store/tips.ts@@ -8,8 +8,9 @@* default: minutes into a launch at the earliest, then six hours, which is a* nicety rather than the nag that would owe you an opt-in.* - It covers Hermes too. "Off" from someone who has just closed a bubble means- * no bubbles, not "no bubbles unless the agent sends one", so an agent tip is- * dropped at the bridge like a rotation tip is skipped here.+ * no bubbles, not "no bubbles unless the agent sends one" — so the switch is+ * mirrored to the gateway, where it takes the `tip` tool out of the model's+ * schema, and the bridge drops a stray tip on top of that.* - `$retiredTips` is the hard-close ledger for the rotation. A tip the user ✕'d* never comes back on its own; Settings → Reset is the only way, and that is* the whole contract behind the ✕ being a heavier gesture than letting the@@ -26,6 +27,7 @@ import { atom } from 'nanostores'import { Codecs, persistentAtom } from '@/lib/persisted'import type { TipSide } from '@/lib/tips/catalog'+import { mirrorDisplayToggle } from '@/store/display-toggles'/** Hours, not minutes. The catalog is ten tips and it should take weeks. */const COOLDOWN_MS = 6 * 60 * 60_000@@ -47,7 +49,9 @@ export interface ActiveTip {// Key still says `rotation` from when the switch only covered that half.// Renaming it would read as unset for anyone who had already turned tips off,// and silently turning them back on is the one outcome worth avoiding here.-export const $tipsEnabled = persistentAtom('hermes.desktop.tips.rotation.v1', true, Codecs.bool)+const ENABLED_KEY = 'hermes.desktop.tips.rotation.v1'++export const $tipsEnabled = persistentAtom(ENABLED_KEY, true, Codecs.bool)export const $retiredTips = persistentAtom<string[]>('hermes.desktop.tips.retired.v1', [], Codecs.stringArray)export const $lastTipId = persistentAtom<null | string>('hermes.desktop.tips.last.v1', null, Codecs.nullableText)export const $nextTipAt = persistentAtom<null | number>(@@ -57,6 +61,10 @@ export const $nextTipAt = persistentAtom<null | number>()export const $activeTip = atom<ActiveTip | null>(null)+// Off has to reach the agent, not just the renderer: the `tip` tool leaves the+// model's schema entirely rather than staying on offer and being dropped.+mirrorDisplayToggle('display.in_app_tips', ENABLED_KEY, $tipsEnabled)+export function setTipsEnabled(enabled: boolean): void {if (!enabled) {// Including whichever one is up: the switch is answering a bubble ondiff --git a/apps/desktop/src/store/tours.ts b/apps/desktop/src/store/tours.tsindex 44d82c101a3..f7a15185bff 100644--- a/apps/desktop/src/store/tours.ts+++ b/apps/desktop/src/store/tours.ts@@ -12,8 +12,15 @@*/import { Codecs, persistentAtom } from '@/lib/persisted'+import { mirrorDisplayToggle } from '@/store/display-toggles'-export const $toursEnabled = persistentAtom('hermes.desktop.tours.v1', true, Codecs.bool)+const KEY = 'hermes.desktop.tours.v1'++export const $toursEnabled = persistentAtom(KEY, true, Codecs.bool)++// Off has to reach the agent, not just the renderer: the `tour` tool leaves the+// model's schema entirely rather than staying on offer and failing.+mirrorDisplayToggle('display.in_app_tours', KEY, $toursEnabled)export function setToursEnabled(enabled: boolean): void {$toursEnabled.set(enabled)