Skip to content

The agent that grows with you

refactor(desktop): import the focused-session atoms from session-focus, drop the re-export shim

teknium1cb60c05506c4
diff --git a/apps/desktop/src/app/chat/close-tab.test.ts b/apps/desktop/src/app/chat/close-tab.test.ts
index 3dba05d1274..093aaba6125 100644
--- a/apps/desktop/src/app/chat/close-tab.test.ts
+++ b/apps/desktop/src/app/chat/close-tab.test.ts
@@ -25,11 +25,7 @@ vi.mock('@/components/pane-shell/tree/store', () => ({
vi.mock('@/store/session-states', () => ({
closeSessionTile: (...args: unknown[]) => closeSessionTile(...args),
- nextSessionTileForWorkspace: () => nextSessionTileForWorkspace(),
- // preview.ts reads the focused session when stamping/deriving tabs; this
- // suite drives the writable $selectedStoredSessionId instead, so a static
- // null stub is enough.
- $focusedStoredSessionId: atom<string | null>(null)
+ nextSessionTileForWorkspace: () => nextSessionTileForWorkspace()
}))
vi.mock('@/store/profile', () => ({
diff --git a/apps/desktop/src/app/chat/index.tsx b/apps/desktop/src/app/chat/index.tsx
index f75d44ea69b..f01f2adefd6 100644
--- a/apps/desktop/src/app/chat/index.tsx
+++ b/apps/desktop/src/app/chat/index.tsx
@@ -49,7 +49,8 @@ import {
sessionPinId,
shouldMigrateComposerScope
} from '@/store/session'
-import { $focusedStoredSessionId, $sessionStates, sessionTileDelegate } from '@/store/session-states'
+import { $focusedStoredSessionId } from '@/store/session-focus'
+import { $sessionStates, sessionTileDelegate } from '@/store/session-states'
import { $transcriptTailBySessionId, transcriptTailState } from '@/store/transcript-tail'
import { isAuxiliaryWindow, isWatchWindow } from '@/store/windows'
diff --git a/apps/desktop/src/app/chat/sidebar/index.tsx b/apps/desktop/src/app/chat/sidebar/index.tsx
index cca843d5bf5..47ea46cf814 100644
--- a/apps/desktop/src/app/chat/sidebar/index.tsx
+++ b/apps/desktop/src/app/chat/sidebar/index.tsx
@@ -128,9 +128,10 @@ import {
sessionPinId
} from '@/store/session'
import { $sessionDotStateById, sessionStatusBucket } from '@/store/session-dot-state'
+import { $focusedSessionIsTile, $focusedStoredSessionId } from '@/store/session-focus'
import { $unconfirmedPinWrites } from '@/store/session-pin-sync'
import { $removedSessionIds } from '@/store/session-removal'
-import { $focusedSessionIsTile, $focusedStoredSessionId, $workingSessionIds } from '@/store/session-states'
+import { $workingSessionIds } from '@/store/session-states'
import { ackAllSessionsRead } from '@/store/session-unread'
import { markSessionUnread } from '@/store/session-unread-remote'
import { $archivedSessions, loadArchivedSessions } from '@/store/sidebar-archive'
diff --git a/apps/desktop/src/app/contrib/session-rpc-dispatcher.ts b/apps/desktop/src/app/contrib/session-rpc-dispatcher.ts
index b9f61b2445d..ec94658adb7 100644
--- a/apps/desktop/src/app/contrib/session-rpc-dispatcher.ts
+++ b/apps/desktop/src/app/contrib/session-rpc-dispatcher.ts
@@ -37,14 +37,10 @@ import { resolveSessionOwner } from '@/app/session/hooks/use-session-actions/uti
import type { ClientSessionState } from '@/app/types'
import { isSessionGoneForBackgroundPolling } from '@/store/runtime-gone'
import { getSessionOwnerHint, knownSessionOwner, ownerLookupSessionRows, requestSessionResume } from '@/store/session'
+import { $focusedStoredSessionId } from '@/store/session-focus'
import { assertSessionOwnerResolved } from '@/store/session-owner-resolution'
import { requestForSessionProfile, type SessionOwnerScope } from '@/store/session-request-router'
-import {
- $focusedStoredSessionId,
- runtimeSessionOwner,
- sessionTileOwnerRoute,
- storedSessionIdForRuntimeId
-} from '@/store/session-states'
+import { runtimeSessionOwner, sessionTileOwnerRoute, storedSessionIdForRuntimeId } from '@/store/session-states'
import { findStoredIdForRuntimeId, resolveRoutingSessionId, resolveSessionRpcOwner } from './wiring-routing'
diff --git a/apps/desktop/src/app/hooks/use-keybinds.ts b/apps/desktop/src/app/hooks/use-keybinds.ts
index c94ff9c2fbf..2b7f6ee4c3c 100644
--- a/apps/desktop/src/app/hooks/use-keybinds.ts
+++ b/apps/desktop/src/app/hooks/use-keybinds.ts
@@ -71,7 +71,8 @@ import {
setCurrentReasoningEffort,
setModelPickerOpen
} from '@/store/session'
-import { $focusedStoredSessionId, reopenLastClosedTile } from '@/store/session-states'
+import { $focusedStoredSessionId } from '@/store/session-focus'
+import { reopenLastClosedTile } from '@/store/session-states'
import {
$switcherOpen,
closeSwitcher,
diff --git a/apps/desktop/src/app/model-picker-overlay.tsx b/apps/desktop/src/app/model-picker-overlay.tsx
index d5c0e122c5b..f8ac0f45815 100644
--- a/apps/desktop/src/app/model-picker-overlay.tsx
+++ b/apps/desktop/src/app/model-picker-overlay.tsx
@@ -18,8 +18,9 @@ import {
$selectedStoredSessionId,
setModelPickerOpen
} from '@/store/session'
+import { $focusedStoredSessionId } from '@/store/session-focus'
import { requestForSessionProfile } from '@/store/session-request-router'
-import { $focusedRuntimeId, $focusedSessionState, $focusedStoredSessionId, $sessionTiles } from '@/store/session-states'
+import { $focusedRuntimeId, $focusedSessionState, $sessionTiles } from '@/store/session-states'
interface ModelPickerOverlayProps {
gateway?: HermesGateway
diff --git a/apps/desktop/src/app/session/hooks/use-preview-routing.ts b/apps/desktop/src/app/session/hooks/use-preview-routing.ts
index c4cb767e946..22ef477e532 100644
--- a/apps/desktop/src/app/session/hooks/use-preview-routing.ts
+++ b/apps/desktop/src/app/session/hooks/use-preview-routing.ts
@@ -15,12 +15,8 @@ import {
requestPreviewReload
} from '@/store/preview'
import { $activeSessionId, $currentCwd } from '@/store/session'
-import {
- $focusedRuntimeId,
- $focusedStoredSessionId,
- $sessionTiles,
- storedSessionIdForRuntimeId
-} from '@/store/session-states'
+import { $focusedStoredSessionId } from '@/store/session-focus'
+import { $focusedRuntimeId, $sessionTiles, storedSessionIdForRuntimeId } from '@/store/session-states'
type EventHandler = (event: GatewayEvent) => void
diff --git a/apps/desktop/src/app/session/hooks/wrong-session-closeout.test.tsx b/apps/desktop/src/app/session/hooks/wrong-session-closeout.test.tsx
index 9dca1168446..ddbc35d25e7 100644
--- a/apps/desktop/src/app/session/hooks/wrong-session-closeout.test.tsx
+++ b/apps/desktop/src/app/session/hooks/wrong-session-closeout.test.tsx
@@ -34,7 +34,8 @@ import {
setSelectedStoredSessionId,
setSessions
} from '@/store/session'
-import { $focusedStoredSessionId, $sessionTiles, clearAllSessionStates } from '@/store/session-states'
+import { $focusedStoredSessionId } from '@/store/session-focus'
+import { $sessionTiles, clearAllSessionStates } from '@/store/session-states'
import type { SessionInfo } from '@/types/hermes'
import { useSessionActions } from './use-session-actions'
diff --git a/apps/desktop/src/app/shell/hooks/use-statusbar-items.tsx b/apps/desktop/src/app/shell/hooks/use-statusbar-items.tsx
index 7e33f3c3126..79073ca375b 100644
--- a/apps/desktop/src/app/shell/hooks/use-statusbar-items.tsx
+++ b/apps/desktop/src/app/shell/hooks/use-statusbar-items.tsx
@@ -60,13 +60,8 @@ import {
idsShareLineage,
sessionMatchesStoredId
} from '@/store/session'
-import {
- $focusedRuntimeId,
- $focusedSessionState,
- $focusedStoredSessionId,
- $sessionTiles,
- isSessionRemote
-} from '@/store/session-states'
+import { $focusedStoredSessionId } from '@/store/session-focus'
+import { $focusedRuntimeId, $focusedSessionState, $sessionTiles, isSessionRemote } from '@/store/session-states'
import { $statusbarHiddenIds } from '@/store/statusbar-prefs'
import { $subagentsBySession, activeSubagentCount, failedSubagentCount } from '@/store/subagents'
import { $gatewayRestarting } from '@/store/system-actions'
diff --git a/apps/desktop/src/debug/watched-atoms.ts b/apps/desktop/src/debug/watched-atoms.ts
index ebcb2724b78..bc3957b49e5 100644
--- a/apps/desktop/src/debug/watched-atoms.ts
+++ b/apps/desktop/src/debug/watched-atoms.ts
@@ -21,11 +21,11 @@ import {
$sessions,
$sessionsLoading
} from '@/store/session'
+import { $focusedStoredSessionId } from '@/store/session-focus'
import {
$attentionSessionIds,
$focusedRuntimeId,
$focusedSessionState,
- $focusedStoredSessionId,
$sessionStates,
$sessionTiles,
$stalledSessionIds,
diff --git a/apps/desktop/src/sdk/index.ts b/apps/desktop/src/sdk/index.ts
index e49e7317f0b..020568b4710 100644
--- a/apps/desktop/src/sdk/index.ts
+++ b/apps/desktop/src/sdk/index.ts
@@ -93,10 +93,10 @@ import {
setResumeExhaustedSessionId,
setSessionOwnerHint
} from '@/store/session'
+import { $focusedStoredSessionId } from '@/store/session-focus'
import {
$focusedRuntimeId,
$focusedSessionState,
- $focusedStoredSessionId,
$sessionStates,
$sessionTiles,
dropTilesForProfile,
diff --git a/apps/desktop/src/sdk/open-session-refresh-in-place.test.ts b/apps/desktop/src/sdk/open-session-refresh-in-place.test.ts
index f0a442da50e..1c6748bb365 100644
--- a/apps/desktop/src/sdk/open-session-refresh-in-place.test.ts
+++ b/apps/desktop/src/sdk/open-session-refresh-in-place.test.ts
@@ -79,7 +79,6 @@ vi.mock('@/store/session-states', async () => {
$draftSessionIds: atom([]),
$focusedRuntimeId: atom(null),
$focusedSessionState: atom(null),
- $focusedStoredSessionId: atom(null),
$sessionTiles: atom([]),
$sessionStates: atom({}),
$stalledSessionIds: atom([]),
diff --git a/apps/desktop/src/sdk/profile-routing.test.ts b/apps/desktop/src/sdk/profile-routing.test.ts
index c7b6e1c0d42..78142d5121b 100644
--- a/apps/desktop/src/sdk/profile-routing.test.ts
+++ b/apps/desktop/src/sdk/profile-routing.test.ts
@@ -53,6 +53,13 @@ vi.mock('@/store/session', async () => {
setResumeExhaustedSessionId: vi.fn()
}
})
+// The focused session is driven directly; everything else in session-focus
+// stays real.
+vi.mock('@/store/session-focus', async importOriginal => {
+ const { atom } = await import('nanostores')
+
+ return { ...(await importOriginal<Record<string, unknown>>()), $focusedStoredSessionId: atom(null) }
+})
vi.mock('@/store/session-states', async () => {
const { atom } = await import('nanostores')
@@ -61,7 +68,6 @@ vi.mock('@/store/session-states', async () => {
$draftSessionIds: atom([]),
$focusedRuntimeId: atom(null),
$focusedSessionState: atom(null),
- $focusedStoredSessionId: atom(null),
$sessionTiles: atom([]),
$sessionStates: atom({}),
$stalledSessionIds: atom([]),
@@ -155,14 +161,10 @@ const {
setShowAllProfiles
} = await import('@/store/profile')
-const {
- $focusedRuntimeId,
- $focusedSessionState,
- $focusedStoredSessionId,
- $sessionStates,
- $sessionTiles,
- sessionTileDelegate
-} = await import('@/store/session-states')
+const { $focusedRuntimeId, $focusedSessionState, $sessionStates, $sessionTiles, sessionTileDelegate } =
+ await import('@/store/session-states')
+
+const { $focusedStoredSessionId } = await import('@/store/session-focus')
const { dropTilesForProfile } = await import('@/store/session-states')
diff --git a/apps/desktop/src/store/session-sidebar-focus.test.ts b/apps/desktop/src/store/session-sidebar-focus.test.ts
index a5df99e7c55..3b1e3129b93 100644
--- a/apps/desktop/src/store/session-sidebar-focus.test.ts
+++ b/apps/desktop/src/store/session-sidebar-focus.test.ts
@@ -1,3 +1,7 @@
+// Loaded for its primary-follow wiring: a new primary selection re-fronts the
+// workspace, which the last case asserts through the focus derivation.
+import '@/store/session-states'
+
import { afterEach, beforeEach, describe, expect, it } from 'vitest'
import { group, split } from '@/components/pane-shell/tree/model'
@@ -9,7 +13,7 @@ import {
} from '@/components/pane-shell/tree/store'
import { setWorkspaceScope } from '@/components/pane-shell/workspace-scope'
import { $selectedStoredSessionId } from '@/store/session'
-import { $focusedStoredSessionId } from '@/store/session-states'
+import { $focusedStoredSessionId } from '@/store/session-focus'
const pane = (id: string) => `session-tile:${id}`
diff --git a/apps/desktop/src/store/session-states.test.ts b/apps/desktop/src/store/session-states.test.ts
index 23d752a53ae..a80792302a6 100644
--- a/apps/desktop/src/store/session-states.test.ts
+++ b/apps/desktop/src/store/session-states.test.ts
@@ -22,11 +22,11 @@ import {
setSessionOwnerHint,
setSessions
} from '@/store/session'
+import { $focusedStoredSessionId } from '@/store/session-focus'
import type { SessionProfileRoute } from '@/store/session-request-router'
import type { SessionTile } from '@/store/session-states'
import type * as SessionStatesModule from '@/store/session-states'
import {
- $focusedStoredSessionId,
$focusedWorkspaceCwd,
$sessionStates,
$sessionTiles,
@@ -1350,6 +1350,7 @@ describe('reopenLastClosedTile focuses the restored tab', () => {
const { registry } = await import('@/contrib/registry')
const session = await import('@/store/session')
const states = await import('@/store/session-states')
+ const { $focusedStoredSessionId } = await import('@/store/session-focus')
registry.register({
area: 'panes',
@@ -1381,11 +1382,11 @@ describe('reopenLastClosedTile focuses the restored tab', () => {
tree.noteActiveTreeGroup('grp-main')
expect(findGroupOfPane(tree.$layoutTree.get()!, tilePane('closed'))?.active).toBe(tilePane('closed'))
- return { states, tree }
+ return { $focusedStoredSessionId, states, tree }
}
it('restores the live strip slot after reordering and retains the exact owner', async () => {
- const { states, tree } = await setup()
+ const { $focusedStoredSessionId, states, tree } = await setup()
states.openSessionTile('after', 'center', 'workspace')
tree.moveTreePane(tilePane('closed'), { groupId: 'grp-main', pos: 'center', before: 'workspace' })
const order = findGroupOfPane(tree.$layoutTree.get()!, 'workspace')!.panes
@@ -1395,17 +1396,17 @@ describe('reopenLastClosedTile focuses the restored tab', () => {
tree.noteActiveTreeGroup(null)
states.reopenLastClosedTile()
expect(findGroupOfPane(tree.$layoutTree.get()!, 'workspace')!.panes).toEqual(order)
- expect(states.$focusedStoredSessionId.get()).toBe('closed')
+ expect($focusedStoredSessionId.get()).toBe('closed')
expect(states.sessionTileOwnerRoute('closed')).toEqual(ownerRoute)
})
it('fronts a palette-opened tab from sidebar focus without replacing main', async () => {
- const { states, tree } = await setup()
+ const { $focusedStoredSessionId, tree } = await setup()
const { openSession } = await import('@/app/open-session')
const navigate = vi.fn()
tree.noteActiveTreeGroup('sidebar')
openSession('palette-result', navigate, 'stack')
- expect(states.$focusedStoredSessionId.get()).toBe('palette-result')
+ expect($focusedStoredSessionId.get()).toBe('palette-result')
expect(findGroupOfPane(tree.$layoutTree.get()!, 'workspace')!.active).toBe(tilePane('palette-result'))
expect(navigate).not.toHaveBeenCalled()
})
diff --git a/apps/desktop/src/store/session-states.ts b/apps/desktop/src/store/session-states.ts
index bdc8f292140..8139f8cb333 100644
--- a/apps/desktop/src/store/session-states.ts
+++ b/apps/desktop/src/store/session-states.ts
@@ -78,7 +78,7 @@ import {
setTurnStartedAt
} from './session'
import { secondaryProfileOwnerForEvent } from './session-event-provenance'
-import { $focusedSessionIsTile, $focusedStoredSessionId, TILE_PANE_PREFIX } from './session-focus'
+import { $focusedStoredSessionId, TILE_PANE_PREFIX } from './session-focus'
import { assertSessionOwnerResolved } from './session-owner-resolution'
import {
isSessionOwnerRoute,
@@ -3044,18 +3044,12 @@ export function reopenLastClosedTile(): void {
// ---------------------------------------------------------------------------
// The FOCUSED session — one derivation, not another hand-maintained
-// "$activeSession" sibling. session-focus resolves the interacted content zone,
-// retaining it while the Sessions sidebar owns keyboard focus. Its active
-// pane names the session: a `session-tile:<storedId>` pane IS that session,
-// anything else falls back to the route-driven primary. Chrome that should
-// follow the user between tiles (titlebar session title, statusbar context /
-// timer / model) reads these instead of the primary-only atoms.
+// "$activeSession" sibling: `$focusedStoredSessionId` (session-focus.ts).
+// Chrome that should follow the user between tiles (titlebar session title,
+// statusbar context / timer / model) reads it and the derivations below
+// instead of the primary-only atoms.
// ---------------------------------------------------------------------------
-// Re-exported from session-focus.ts so existing consumers keep their import
-// path; the definitions live there (see the note on that module).
-export { $focusedSessionIsTile, $focusedStoredSessionId }
-
/** Every session currently OPEN as a surface: the primary's selection plus
* every tile's stored id. The sidebar highlights all of them (the focused one
* at full strength, the rest dimmed) so a multi-pane workspace shows which