Skip to content

The agent that grows with you

fix(desktop): persistStore lives in its own module so storage mocks keep working

Teknium76a60bf87b46
diff --git a/apps/desktop/src/lib/persist-store.ts b/apps/desktop/src/lib/persist-store.ts
new file mode 100644
index 00000000000..9230725819d
--- /dev/null
+++ b/apps/desktop/src/lib/persist-store.ts
@@ -0,0 +1,14 @@
+import type { WriteOptions } from '@/lib/storage'
+
+/** Persist a store: the value it loads with (its default, or a heal of what
+ * was stored) as provisional, every later change as the user's. */
+export function persistStore<T>(
+ store: { subscribe(listener: (value: T) => void): () => void },
+ persist: (value: T, options: WriteOptions) => void
+): () => void {
+ let loading = true
+ const stop = store.subscribe(value => persist(value, { provisional: loading }))
+ loading = false
+
+ return stop
+}
diff --git a/apps/desktop/src/lib/storage.ts b/apps/desktop/src/lib/storage.ts
index bf025b08da4..6a3bb9663c3 100644
--- a/apps/desktop/src/lib/storage.ts
+++ b/apps/desktop/src/lib/storage.ts
@@ -131,18 +131,6 @@ export function writeKey(key: string, value: null | string, { provisional = fals
emitPersistence({ key, op: value === null ? 'remove' : 'write', value, ...(provisional && { provisional }) })
}
-/** Persist a store: the value it loads with (its default, or a heal of what
- * was stored) as provisional, every later change as the user's. */
-export function persistStore<T>(
- store: { subscribe(listener: (value: T) => void): () => void },
- persist: (value: T, options: WriteOptions) => void
-): () => void {
- let loading = true
- const stop = store.subscribe(value => persist(value, { provisional: loading }))
- loading = false
-
- return stop
-}
/** Parsed JSON read. Returns null on absence, unavailable storage, OR malformed
* JSON — callers layer their own shape validation on the parsed value. */
diff --git a/apps/desktop/src/store/backdrop.ts b/apps/desktop/src/store/backdrop.ts
index 2419095d1be..5d8472b356a 100644
--- a/apps/desktop/src/store/backdrop.ts
+++ b/apps/desktop/src/store/backdrop.ts
@@ -1,6 +1,7 @@
import { atom } from 'nanostores'
-import { persistBoolean, persistStore, storedBoolean } from '@/lib/storage'
+import { persistStore } from '@/lib/persist-store'
+import { persistBoolean, storedBoolean } from '@/lib/storage'
import { recordFeatureToggle } from './desktop-metrics'
diff --git a/apps/desktop/src/store/completion-sound.ts b/apps/desktop/src/store/completion-sound.ts
index df53605584f..5e8c7b4f65f 100644
--- a/apps/desktop/src/store/completion-sound.ts
+++ b/apps/desktop/src/store/completion-sound.ts
@@ -1,6 +1,7 @@
import { atom } from 'nanostores'
-import { persistStore, persistString, storedString } from '@/lib/storage'
+import { persistStore } from '@/lib/persist-store'
+import { persistString, storedString } from '@/lib/storage'
const STORAGE_KEY = 'hermes.desktop.completionSoundVariantId'
diff --git a/apps/desktop/src/store/external-links.ts b/apps/desktop/src/store/external-links.ts
index 88c1e50fee3..00775be9a84 100644
--- a/apps/desktop/src/store/external-links.ts
+++ b/apps/desktop/src/store/external-links.ts
@@ -13,7 +13,8 @@
import { atom } from 'nanostores'
-import { persistBoolean, persistStore, storedBoolean } from '@/lib/storage'
+import { persistStore } from '@/lib/persist-store'
+import { persistBoolean, storedBoolean } from '@/lib/storage'
const KEY = 'hermes.desktop.alwaysExternalLinks.v1'
diff --git a/apps/desktop/src/store/haptics.ts b/apps/desktop/src/store/haptics.ts
index f5031f1c178..1421b0b194c 100644
--- a/apps/desktop/src/store/haptics.ts
+++ b/apps/desktop/src/store/haptics.ts
@@ -1,6 +1,7 @@
import { atom } from 'nanostores'
-import { persistBoolean, persistStore, storedBoolean } from '@/lib/storage'
+import { persistStore } from '@/lib/persist-store'
+import { persistBoolean, storedBoolean } from '@/lib/storage'
const HAPTICS_MUTED_STORAGE_KEY = 'hermes.desktop.hapticsMuted'
diff --git a/apps/desktop/src/store/keybinds.ts b/apps/desktop/src/store/keybinds.ts
index e035dd0abfa..a71cf455a52 100644
--- a/apps/desktop/src/store/keybinds.ts
+++ b/apps/desktop/src/store/keybinds.ts
@@ -3,7 +3,8 @@ import { atom, computed } from 'nanostores'
import { $registryVersion } from '@/contrib/registry'
import { allKeybindActions, defaultBindings, keybindAction, type KeybindBindings } from '@/lib/keybinds/actions'
import { canonicalizeCombo } from '@/lib/keybinds/combo'
-import { arraysEqual, persistStore, persistString, storedString, type WriteOptions } from '@/lib/storage'
+import { persistStore } from '@/lib/persist-store'
+import { arraysEqual, persistString, storedString, type WriteOptions } from '@/lib/storage'
const STORAGE_KEY = 'hermes.desktop.keybinds'
diff --git a/apps/desktop/src/store/profile.ts b/apps/desktop/src/store/profile.ts
index bacc09cf686..71be99153cf 100644
--- a/apps/desktop/src/store/profile.ts
+++ b/apps/desktop/src/store/profile.ts
@@ -3,19 +3,11 @@ import { atom, batch, computed } from 'nanostores'
import type { HermesConnection } from '@/global'
import { getProfiles, hermesApi, setApiRequestProfile, STARTUP_REQUEST_TIMEOUT_MS } from '@/hermes'
+import { persistStore } from '@/lib/persist-store'
import { initialGatewayProfile, isBrowserHostedDesktop } from '@/lib/platform'
import { sortByProfileOrder as sortProfilesByOrder } from '@/lib/profile-order'
import { invalidateProfileScopedQueries } from '@/lib/query-client'
-import {
- arraysEqual,
- persistBoolean,
- persistStore,
- persistStringArray,
- persistStringRecord,
- storedBoolean,
- storedStringArray,
- storedStringRecord
-} from '@/lib/storage'
+import { arraysEqual, persistBoolean, persistStringArray, persistStringRecord, storedBoolean, storedStringArray, storedStringRecord } from '@/lib/storage'
import { withTimeout } from '@/lib/with-timeout'
import { registryConnectionKind } from '@/store/connection-registry-state'
import {
diff --git a/apps/desktop/src/store/reasoning-disclosure.ts b/apps/desktop/src/store/reasoning-disclosure.ts
index cbaca97b7ac..44c0a718655 100644
--- a/apps/desktop/src/store/reasoning-disclosure.ts
+++ b/apps/desktop/src/store/reasoning-disclosure.ts
@@ -1,6 +1,7 @@
import { atom } from 'nanostores'
-import { persistBoolean, persistStore, storedBoolean } from '@/lib/storage'
+import { persistStore } from '@/lib/persist-store'
+import { persistBoolean, storedBoolean } from '@/lib/storage'
import { modeBound } from '@/store/interface-mode'
import type { HermesConfig } from '@/types/hermes'
diff --git a/apps/desktop/src/store/thread-timeline.ts b/apps/desktop/src/store/thread-timeline.ts
index 740b68ad900..a28898629c1 100644
--- a/apps/desktop/src/store/thread-timeline.ts
+++ b/apps/desktop/src/store/thread-timeline.ts
@@ -1,6 +1,7 @@
import { atom } from 'nanostores'
-import { persistBoolean, persistStore, storedBoolean } from '@/lib/storage'
+import { persistStore } from '@/lib/persist-store'
+import { persistBoolean, storedBoolean } from '@/lib/storage'
import { recordFeatureToggle } from './desktop-metrics'
diff --git a/apps/desktop/src/store/tool-view.ts b/apps/desktop/src/store/tool-view.ts
index 08c5d244b3c..346f768d756 100644
--- a/apps/desktop/src/store/tool-view.ts
+++ b/apps/desktop/src/store/tool-view.ts
@@ -1,6 +1,7 @@
import { atom, computed, onStop, type ReadableAtom } from 'nanostores'
-import { persistBoolean, persistStore, storedBoolean } from '@/lib/storage'
+import { persistStore } from '@/lib/persist-store'
+import { persistBoolean, storedBoolean } from '@/lib/storage'
import { modeBound } from '@/store/interface-mode'
export type ToolViewMode = 'product' | 'technical'