@@ -30,8 +30,8 @@ import { normalizePath } from '@/shared/utils/pathUtils';
3030// ==================== Store State Types ====================
3131
3232interface CanvasStoreState {
33- /** Live content scope, committed with workspace swaps and excluded from snapshots. */
34- workspaceKey ?: string ;
33+ /** Live content scope, committed with scope swaps and excluded from snapshots. */
34+ scopeKey ?: string ;
3535 primaryGroup : EditorGroupState ;
3636 secondaryGroup : EditorGroupState ;
3737 tertiaryGroup : EditorGroupState ;
@@ -159,7 +159,7 @@ type CanvasStore = CanvasStoreState & CanvasStoreActions;
159159// ==================== Initial State ====================
160160
161161const initialState : CanvasStoreState = {
162- workspaceKey : undefined ,
162+ scopeKey : undefined ,
163163 primaryGroup : createEditorGroupState ( ) ,
164164 secondaryGroup : createEditorGroupState ( ) ,
165165 tertiaryGroup : createEditorGroupState ( ) ,
@@ -1169,15 +1169,15 @@ export const useAgentCanvasStore = createCanvasStoreHook();
11691169export const useGitCanvasStore = createCanvasStoreHook ( ) ;
11701170export const useBottomTerminalCanvasStore = createCanvasStoreHook ( ) ;
11711171
1172- // ==================== Agent canvas: per-workspace snapshots (AuxPane / Session scene) ====================
1173- // Switching active workspace saves the current agent canvas under the previous workspace id and restores
1174- // the snapshot for the next id, so remote/local tabs coexist across workspace switches .
1172+ // ==================== Agent canvas: per-scope snapshots (AuxPane / Session scene) ====================
1173+ // The agent canvas is scoped to the active session. Leaving a session saves its canvas under that
1174+ // session id and entering another one restores its own tabs, so two sessions never share content .
11751175
1176- const AGENT_CANVAS_SNAPSHOT_MAX = 12 ;
1177- const agentWorkspaceSnapshots = new Map < string , CanvasStoreState > ( ) ;
1176+ const AGENT_CANVAS_SNAPSHOT_MAX = 24 ;
1177+ const agentScopeSnapshots = new Map < string , CanvasStoreState > ( ) ;
11781178const agentSnapshotLruOrder : string [ ] = [ ] ;
11791179
1180- function normalizeAgentWorkspaceKey ( id : string | null | undefined ) : string {
1180+ function normalizeAgentScopeKey ( id : string | null | undefined ) : string {
11811181 return id ?? '__none__' ;
11821182}
11831183
@@ -1200,20 +1200,20 @@ function rememberAgentSnapshot(key: string, snapshot: CanvasStoreState): void {
12001200 const clone = structuredClone ( snapshot ) ;
12011201 clone . draggingTabId = null ;
12021202 clone . draggingFromGroupId = null ;
1203- agentWorkspaceSnapshots . set ( key , clone ) ;
1203+ agentScopeSnapshots . set ( key , clone ) ;
12041204 const idx = agentSnapshotLruOrder . indexOf ( key ) ;
12051205 if ( idx >= 0 ) agentSnapshotLruOrder . splice ( idx , 1 ) ;
12061206 agentSnapshotLruOrder . push ( key ) ;
1207- while ( agentWorkspaceSnapshots . size > AGENT_CANVAS_SNAPSHOT_MAX ) {
1207+ while ( agentScopeSnapshots . size > AGENT_CANVAS_SNAPSHOT_MAX ) {
12081208 const evict = agentSnapshotLruOrder . shift ( ) ;
12091209 if ( ! evict ) break ;
1210- agentWorkspaceSnapshots . delete ( evict ) ;
1210+ agentScopeSnapshots . delete ( evict ) ;
12111211 }
12121212}
12131213
1214- function applyEmptyAgentCanvas ( workspaceKey ?: string ) : void {
1214+ function applyEmptyAgentCanvas ( scopeKey ?: string ) : void {
12151215 useAgentCanvasStore . setState ( {
1216- workspaceKey ,
1216+ scopeKey ,
12171217 primaryGroup : createEditorGroupState ( ) ,
12181218 secondaryGroup : createEditorGroupState ( ) ,
12191219 tertiaryGroup : createEditorGroupState ( ) ,
@@ -1227,29 +1227,26 @@ function applyEmptyAgentCanvas(workspaceKey?: string): void {
12271227 } ) ;
12281228}
12291229
1230- /** Clear agent canvas workspace snapshots when entering/exiting Peer Device Mode. */
1230+ /** Clear agent canvas snapshots when entering/exiting Peer Device Mode. */
12311231export function clearAgentCanvasForPeerSwitch ( ) : void {
1232- agentWorkspaceSnapshots . clear ( ) ;
1232+ agentScopeSnapshots . clear ( ) ;
12331233 agentSnapshotLruOrder . length = 0 ;
12341234 applyEmptyAgentCanvas ( ) ;
12351235 useGitCanvasStore . getState ( ) . reset ( ) ;
12361236 useBottomTerminalCanvasStore . getState ( ) . reset ( ) ;
12371237}
12381238
12391239/**
1240- * The store owns its live workspace . A later host mount or stale caller cannot
1241- * overwrite content already committed for the target workspace .
1240+ * The store owns its live scope . A later host mount or stale caller cannot
1241+ * overwrite content already committed for the target scope .
12421242 */
1243- export function switchAgentCanvasWorkspace (
1244- _prevWorkspaceId : string | null | undefined ,
1245- nextWorkspaceId : string | null | undefined
1246- ) : void {
1247- const from = useAgentCanvasStore . getState ( ) . workspaceKey ;
1248- const to = normalizeAgentWorkspaceKey ( nextWorkspaceId ) ;
1243+ export function switchAgentCanvasScope ( nextScopeId : string | null | undefined ) : void {
1244+ const from = useAgentCanvasStore . getState ( ) . scopeKey ;
1245+ const to = normalizeAgentScopeKey ( nextScopeId ) ;
12491246
12501247 if ( from === to ) return ;
12511248
1252- const rawNext = agentWorkspaceSnapshots . get ( to ) ;
1249+ const rawNext = agentScopeSnapshots . get ( to ) ;
12531250 const nextSnapshotClone = rawNext ? structuredClone ( rawNext ) : null ;
12541251
12551252 if ( from !== undefined ) {
@@ -1259,7 +1256,7 @@ export function switchAgentCanvasWorkspace(
12591256
12601257 if ( nextSnapshotClone ) {
12611258 useAgentCanvasStore . setState ( {
1262- workspaceKey : to ,
1259+ scopeKey : to ,
12631260 primaryGroup : nextSnapshotClone . primaryGroup ,
12641261 secondaryGroup : nextSnapshotClone . secondaryGroup ,
12651262 tertiaryGroup : nextSnapshotClone . tertiaryGroup ,
@@ -1277,14 +1274,6 @@ export function switchAgentCanvasWorkspace(
12771274
12781275}
12791276
1280- /** Drop cached canvas for a closed workspace (does not touch the live canvas unless user switches back). */
1281- export function removeAgentCanvasSnapshot ( workspaceId : string ) : void {
1282- const key = normalizeAgentWorkspaceKey ( workspaceId ) ;
1283- agentWorkspaceSnapshots . delete ( key ) ;
1284- const idx = agentSnapshotLruOrder . indexOf ( key ) ;
1285- if ( idx >= 0 ) agentSnapshotLruOrder . splice ( idx , 1 ) ;
1286- }
1287-
12881277const selectWholeCanvasStore = ( state : CanvasStore ) => state ;
12891278
12901279export function useCanvasStore ( ) : CanvasStore ;
@@ -1340,8 +1329,8 @@ export const useDragging = () => {
13401329 } ) ) ;
13411330} ;
13421331
1343- /** Includes suspended workspace snapshots so unmounting a view does not discard its document. */
1332+ /** Includes suspended scope snapshots so unmounting a view does not discard its document. */
13441333export function hasRetainedCanvasTab ( tabId : string ) : boolean {
1345- const states = [ useAgentCanvasStore . getState ( ) , useGitCanvasStore . getState ( ) , useBottomTerminalCanvasStore . getState ( ) , ...agentWorkspaceSnapshots . values ( ) ] ;
1334+ const states = [ useAgentCanvasStore . getState ( ) , useGitCanvasStore . getState ( ) , useBottomTerminalCanvasStore . getState ( ) , ...agentScopeSnapshots . values ( ) ] ;
13461335 return states . some ( state => [ state . primaryGroup , state . secondaryGroup , state . tertiaryGroup ] . some ( group => group . tabs . some ( tab => tab . id === tabId ) ) ) ;
13471336}
0 commit comments