The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): keep the selected chat's workspace when entering a project
brooklyn!1bdc455139eb
diff --git a/apps/desktop/src/app/chat/sidebar/chat-sidebar.integration.test.tsx b/apps/desktop/src/app/chat/sidebar/chat-sidebar.integration.test.tsxindex b3d23686cc2..9778efe5897 100644--- a/apps/desktop/src/app/chat/sidebar/chat-sidebar.integration.test.tsx+++ b/apps/desktop/src/app/chat/sidebar/chat-sidebar.integration.test.tsx@@ -7,7 +7,9 @@ import { group, split } from '@/components/pane-shell/tree/model'import { $layoutTree, noteActiveTreeGroup } from '@/components/pane-shell/tree/store'import { SidebarProvider } from '@/components/ui/sidebar'import { registry } from '@/contrib/registry'-import { $selectedStoredSessionId, $sessions } from '@/store/session'+import { setSidebarAgentsGrouped } from '@/store/layout'+import { $projectScope, $projectTree, ALL_PROJECTS } from '@/store/projects'+import { $currentCwd, $selectedStoredSessionId, $sessions, $workspaceCwdOwner } from '@/store/session'import { $removedSessionIds } from '@/store/session-removal'import { makeSessionInfo } from '@/test/session-info'@@ -162,3 +164,53 @@ describe('ChatSidebar navigation activity', () => {expectOnlySelectedSession(null)})})++// Entering a project is a scope switch: the conversation main is showing keeps+// its workspace, so Files/Review and the composer's Git context can't drift to+// the project while the transcript stays on the old chat (#72772).+describe('ChatSidebar project entry', () => {+ const project = {+ id: '/repos/new-project',+ label: 'new-project',+ path: '/repos/new-project',+ repos: [],+ sessionCount: 0+ }++ beforeEach(() => {+ setSidebarAgentsGrouped(true)+ $projectTree.set([project])+ $currentCwd.set('/repos/old-project')+ })++ afterEach(() => {+ cleanup()+ $projectScope.set(ALL_PROJECTS)+ $projectTree.set([])+ setSidebarAgentsGrouped(false)+ $currentCwd.set('')+ $selectedStoredSessionId.set(null)+ $workspaceCwdOwner.set(null)+ $sessions.set([])+ })++ it("leaves a stored conversation's workspace alone", () => {+ $sessions.set(sessionRows)+ $selectedStoredSessionId.set('tile-one')+ $workspaceCwdOwner.set('tile-one')+ $projectScope.set(project.id)++ renderSidebar('/tile-one', 'chat')++ expect($currentCwd.get()).toBe('/repos/old-project')+ expect($workspaceCwdOwner.get()).toBe('tile-one')+ })++ it('re-homes a fresh draft into the entered project', () => {+ $projectScope.set(project.id)++ renderSidebar('/', 'chat')++ expect($currentCwd.get()).toBe(project.path)+ })+})diff --git a/apps/desktop/src/app/chat/sidebar/index.tsx b/apps/desktop/src/app/chat/sidebar/index.tsxindex ab11cfda7f7..fc7e005c7c8 100644--- a/apps/desktop/src/app/chat/sidebar/index.tsx+++ b/apps/desktop/src/app/chat/sidebar/index.tsx@@ -96,6 +96,7 @@ import {ALL_PROJECTS,enterProject,exitProjectScope,+ followEnteredProjectCwd,openProjectCreate,refreshProjects,refreshProjectTree,@@ -113,7 +114,6 @@ import {import { openRouteTile } from '@/store/route-tiles'import {$cronSessions,- $currentCwd,$gatewayState,$messagingPlatformTotals,$messagingSessions,@@ -123,8 +123,7 @@ import {$sessionsLoading,$unreadFinishedSessionIds,markAllSessionsRead,- sessionPinId,- setCurrentCwd+ sessionPinId} from '@/store/session'import { $sessionDotStateById, sessionStatusBucket } from '@/store/session-dot-state'import { $unconfirmedPinWrites } from '@/store/session-pin-sync'@@ -522,7 +521,6 @@ export function ChatSidebar({const reposScanning = useStore($reposScanning)const activeProjectId = useStore($activeProjectId)const projectScope = useStore($projectScope)- const currentCwd = useStore($currentCwd)const gatewayState = useStore($gatewayState)const dismissedAutoProjects = useStore($dismissedAutoProjectIds)const newSessionCombo = useStore($bindings)['session.new']?.[0]@@ -1166,16 +1164,13 @@ export function ChatSidebar({const lastProjectCwdSyncRef = useRef<null | string>(null)- const syncProjectCwd = useCallback(- (project: SidebarProjectTree) => {- const target = projectTreeCwd(project)+ const syncProjectCwd = useCallback((project: SidebarProjectTree) => {+ const target = projectTreeCwd(project)- if (target && target !== currentCwd) {- setCurrentCwd(target)- }- },- [currentCwd]- )+ if (target) {+ followEnteredProjectCwd(target)+ }+ }, [])// eslint-disable-next-line no-restricted-syntax -- legitimate non-atom ref write (see eslint rule comment)useEffect(() => {diff --git a/apps/desktop/src/store/projects.ts b/apps/desktop/src/store/projects.tsindex 62fda9a46d1..3234abeb4b7 100644--- a/apps/desktop/src/store/projects.ts+++ b/apps/desktop/src/store/projects.ts@@ -27,9 +27,11 @@ import {requestFreshSession} from '@/store/profile'import {+ $currentCwd,$selectedStoredSessionId,$sessions,sessionMatchesStoredId,+ setCurrentCwd,setSessions,workspaceCwdForNewSession} from '@/store/session'@@ -175,6 +177,23 @@ export function resolveNewSessionCwd(): string {return workspaceCwdForNewSession()}+// Entering a project moves the live workspace only when main holds a fresh+// draft: the draft has no folder of its own yet, and the project root is where+// its first message should run. A stored conversation keeps its cwd — entering+// is a scope switch, and moving the workspace under the selected chat re-pointed+// Files/Review and the composer's Git context at the project while the+// transcript stayed on the old session (#72772). The next new chat still lands+// in the project through resolveNewSessionCwd.+export function followEnteredProjectCwd(cwd: string): void {+ const target = cwd.trim()++ if (!target || $selectedStoredSessionId.get() || target === $currentCwd.get()) {+ return+ }++ setCurrentCwd(target)+}+// The project (explicit or auto) that owns `cwd`, by longest path match across// the live tree. Null when no project covers it (it'll surface as a fresh// auto-project on the next tree refresh).