The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): trim right-rail scope salvage to the renderer store
teknium1765cb40bb5ec
diff --git a/apps/desktop/electron/main.ts b/apps/desktop/electron/main.tsindex 1c5d4c05253..70fbac573fb 100644--- a/apps/desktop/electron/main.ts+++ b/apps/desktop/electron/main.ts@@ -13562,7 +13562,7 @@ function spawnSecondaryWindow({// covers it. ready-to-show fires after the boot-time paint in// themes/context.tsx, so the window appears already themed.show: false,- webPreferences: chatWindowWebPreferences(PRELOAD_PATH, profile)+ webPreferences: chatWindowWebPreferences(PRELOAD_PATH)})// Chat-surface registration: applyWindowTranslucency swaps this window's@@ -13748,7 +13748,7 @@ function createInstanceWindow(...chatWindowSurfaceOptions(),icon,show: false,- webPreferences: chatWindowWebPreferences(PRELOAD_PATH, route.profile)+ webPreferences: chatWindowWebPreferences(PRELOAD_PATH)})instanceWindows.add(win)diff --git a/apps/desktop/electron/session-windows.ts b/apps/desktop/electron/session-windows.tsindex 647b5832ccf..8785b04d4dc 100644--- a/apps/desktop/electron/session-windows.ts+++ b/apps/desktop/electron/session-windows.ts@@ -46,44 +46,9 @@ const SESSION_WINDOW_MIN_HEIGHT = 620// window while its transcript is streaming. Explicit user actions still call// the main-process window focus paths (session re-open, notification/deep-link,// app activation), preserving intentional raises without background focus theft.-// Per-profile Electron session partition for chat windows.-//-// WHY: the renderer persists its UI state (right-rail preview tabs, sidebar-// order, workspace layout) in localStorage, which is scoped to the Electron-// session — NOT to the profile the window renders. With no partition every-// window shares one store, so a preview tab opened in one agent's chat appears-// in every other agent's chat, and one profile's layout bleeds into another.-// apps/desktop/AGENTS.md states the rule this violates: "Persisted state must-// declare its scope in its own key... Getting the scope wrong is how one-// profile's setting bleeds into another."-//-// Giving each non-primary profile its own partition scopes that localStorage-// per agent, so each agent keeps its own rail and layout.-//-// Two deliberate constraints:-// - The PRIMARY profile keeps the default session (no partition), so existing-// installs keep their saved layout instead of resetting it once.-// - The name is plain ASCII. AGENTS.md warns that a partition name containing-// a character Electron percent-escapes (e.g. ':') produces a cookie-store-// folder name the OS cannot read, silently breaking persistence — so the-// profile key is sanitized to [a-zA-Z0-9._-] before it is interpolated.-function chatWindowPartition(profileKey?: null | string) {- const key = typeof profileKey === 'string' ? profileKey.trim() : ''-- if (!key || key === 'default') {- return undefined- }-- return `persist:hermes-win-${key.replace(/[^a-zA-Z0-9._-]/g, '-')}`-}--function chatWindowWebPreferences(preloadPath: string, profileKey?: null | string) {- const partition = chatWindowPartition(profileKey)-+function chatWindowWebPreferences(preloadPath: string) {return {preload: preloadPath,- // Absent partition = Electron's default session (the primary profile).- ...(partition ? { partition } : {}),contextIsolation: true,webviewTag: true,sandbox: true,@@ -236,7 +201,6 @@ function createSessionWindowRegistry() {export {buildInstanceWindowUrl,buildSessionWindowUrl,- chatWindowPartition,chatWindowWebPreferences,createSessionWindowRegistry,instanceWindowBounds,diff --git a/apps/desktop/src/store/preview-tabs-scope.test.ts b/apps/desktop/src/store/preview-tabs-scope.test.tsindex dfbdfd67a15..9f4024e7524 100644--- a/apps/desktop/src/store/preview-tabs-scope.test.ts+++ b/apps/desktop/src/store/preview-tabs-scope.test.ts@@ -12,14 +12,14 @@// owner and pushes it in via `setPreviewScope`.import { beforeEach, describe, expect, it } from 'vitest'-import { $activeGatewayProfile, normalizeProfileKey } from '@/store/profile'import {$previewTabs,migratePreviewTabsForProfile,openPreview,- setPreviewScope,- type PreviewTarget+ type PreviewTarget,+ setPreviewScope} from '@/store/preview'+import { normalizeProfileKey } from '@/store/profile'const TABS_KEY = 'hermes.desktop.previewTabs.v2'@@ -44,16 +44,15 @@ function storedBuckets(): Record<string, { target: { path?: string } }[]> {describe('right rail follows the chat on screen', () => {beforeEach(() => {window.localStorage.clear()- $activeGatewayProfile.set('default')setPreviewScope('default')$previewTabs.set([])})it('does not show one agent the tabs another agent opened', () => {setPreviewScope('tess')- openPreview(fileTarget('/tmp/tess-model.html'))+ openPreview(fileTarget('/work/tess-model.html'))- expect(paths()).toEqual(['/tmp/tess-model.html'])+ expect(paths()).toEqual(['/work/tess-model.html'])// Reading another agent's chat re-homes the rail.setPreviewScope('default')@@ -63,42 +62,19 @@ describe('right rail follows the chat on screen', () => {// ...and comes back, unchanged, on the way in.setPreviewScope('tess')- expect(paths()).toEqual(['/tmp/tess-model.html'])- })-- it('keeps each agent in its own persisted bucket', () => {- setPreviewScope('tess')- openPreview(fileTarget('/tmp/tess-model.html'))-- setPreviewScope('default')- openPreview(fileTarget('/tmp/vexa-note.md'))-- const buckets = storedBuckets()-- expect(buckets[normalizeProfileKey('tess')]?.map(tab => tab.target.path)).toEqual(['/tmp/tess-model.html'])- expect(buckets[normalizeProfileKey('default')]?.map(tab => tab.target.path)).toEqual(['/tmp/vexa-note.md'])- })-- it('does NOT re-home on a gateway socket change — the bug this guards', () => {- // A focused tab does not swap the socket, so the socket changing must not- // move the rail. Keying off it is what put Tess's model in VEXA's chat.- setPreviewScope('tess')- openPreview(fileTarget('/tmp/tess-model.html'))-- $activeGatewayProfile.set('default')-- expect(paths()).toEqual(['/tmp/tess-model.html'])+ expect(paths()).toEqual(['/work/tess-model.html'])+ expect(Object.keys(storedBuckets())).toEqual([normalizeProfileKey('tess')])})it('moves the rail with a rename instead of stranding it under the old name', () => {setPreviewScope('tess')- openPreview(fileTarget('/tmp/tess-model.html'))+ openPreview(fileTarget('/work/tess-model.html'))migratePreviewTabsForProfile('tess', 'tess-renamed')const buckets = storedBuckets()expect(buckets[normalizeProfileKey('tess')]).toBeUndefined()- expect(buckets[normalizeProfileKey('tess-renamed')]?.map(tab => tab.target.path)).toEqual(['/tmp/tess-model.html'])+ expect(buckets[normalizeProfileKey('tess-renamed')]?.map(tab => tab.target.path)).toEqual(['/work/tess-model.html'])})})diff --git a/apps/desktop/src/store/preview.ts b/apps/desktop/src/store/preview.tsindex 8c77e72bed2..efe5f84fa69 100644--- a/apps/desktop/src/store/preview.ts+++ b/apps/desktop/src/store/preview.ts@@ -1,6 +1,6 @@import { atom, computed } from 'nanostores'-import { readKey, readJson, writeKey } from '@/lib/storage'+import { readJson, readKey, writeKey } from '@/lib/storage'import { normalize } from '@/lib/text'import { $rightRailActiveTabId, type RightRailTabId, selectRightRailTab } from './layout'diff --git a/apps/desktop/src/store/session-states.ts b/apps/desktop/src/store/session-states.tsindex acb55a75814..a86741caecb 100644--- a/apps/desktop/src/store/session-states.ts+++ b/apps/desktop/src/store/session-states.ts@@ -35,9 +35,9 @@ import { stableArray } from '@/lib/stable-array'import { readJson, writeJson } from '@/lib/storage'import type { SessionInfo } from '@/types/hermes'+import { dropPreviewTabsForProfile, migratePreviewTabsForProfile, setPreviewScope } from './preview'import { dropPreviewArtifactsForProfile, migratePreviewArtifactsForProfile } from './preview-status'import { $activeGatewayProfile, normalizeProfileKey } from './profile'-import { dropPreviewTabsForProfile, migratePreviewTabsForProfile, setPreviewScope } from './preview'import { clearAllProviderWaits, clearSessionProviderWait } from './provider-wait'import {$activeSessionId,