The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
feat(desktop): change the focused chat's working directory from the statusbar
Brooklyn Nicholson63ed3caa4ba2
diff --git a/apps/desktop/src/app/contrib/surfaces.tsx b/apps/desktop/src/app/contrib/surfaces.tsxindex 69030626005..ed2258a7f30 100644--- a/apps/desktop/src/app/contrib/surfaces.tsx+++ b/apps/desktop/src/app/contrib/surfaces.tsx@@ -94,6 +94,7 @@ export const StatusbarSurface = memo(function StatusbarSurface({const { leftStatusbarItems, statusbarItems } = useStatusbarItems({agentsOpen,+ changeSessionCwd: actions.changeSessionCwd,chatOpen,commandCenterOpen,extraLeftItems,diff --git a/apps/desktop/src/app/contrib/types.ts b/apps/desktop/src/app/contrib/types.tsindex cfdd5a554d1..b7baf0f3720 100644--- a/apps/desktop/src/app/contrib/types.ts+++ b/apps/desktop/src/app/contrib/types.ts@@ -61,6 +61,8 @@ export type ChatActions = Pick<* the latest closure.*/export interface WiringActions extends SidebarActions, ChatActions {+ /** Re-home a chat's workspace: the primary's, or `sessionId` (a focused tile's runtime id). */+ changeSessionCwd: (cwd: string, sessionId?: string) => Promise<void>followDefaultModel: () => void/** Imperative access to the live gateway for controller-owned callbacks.* Rendered surfaces subscribe to the active `$gateway` atom directly. */diff --git a/apps/desktop/src/app/contrib/wiring.tsx b/apps/desktop/src/app/contrib/wiring.tsxindex 35ba636524b..a65264f3f5d 100644--- a/apps/desktop/src/app/contrib/wiring.tsx+++ b/apps/desktop/src/app/contrib/wiring.tsx@@ -414,26 +414,19 @@ export function ContribWiring({ children }: { children: ReactNode }) {const { loadMoreMessagingForPlatform, loadMoreSessions, refreshCronJobs, refreshMessagingSessions, refreshSessions } =useSessionListActions({ profileScope })- const updateActiveSessionRuntimeInfo = useCallback(- (info: { branch?: string; cwd?: string }) => {- const sessionId = activeSessionIdRef.current-- if (!sessionId) {- return- }-+ const updateSessionRuntimeInfo = useCallback(+ (sessionId: string, info: { branch?: string; cwd?: string }) =>updateSessionState(sessionId, state => ({...state,branch: info.branch ?? state.branch,cwd: info.cwd ?? state.cwd- }))- },- [activeSessionIdRef, updateSessionState]+ })),+ [updateSessionState])- const { refreshProjectBranch } = useCwdActions({+ const { changeSessionCwd, refreshProjectBranch } = useCwdActions({activeSessionIdRef,- onSessionRuntimeInfo: updateActiveSessionRuntimeInfo,+ onSessionRuntimeInfo: updateSessionRuntimeInfo,requestGateway})@@ -1158,6 +1151,7 @@ export function ContribWiring({ children }: { children: ReactNode }) {.then(() => undefined).catch(() => undefined),followDefaultModel,+ changeSessionCwd,getGateway: () => gatewayRef.current,openAgents,openCommandCenterSection,diff --git a/apps/desktop/src/app/right-sidebar/terminal/reveal-focus.test.ts b/apps/desktop/src/app/right-sidebar/terminal/reveal-focus.test.tsindex 8dc324520f7..686cab72c05 100644--- a/apps/desktop/src/app/right-sidebar/terminal/reveal-focus.test.ts+++ b/apps/desktop/src/app/right-sidebar/terminal/reveal-focus.test.ts@@ -167,6 +167,7 @@ function statusbarSelect() {() =>useStatusbarItems({agentsOpen: false,+ changeSessionCwd: async () => {},chatOpen: true,commandCenterOpen: false,extraLeftItems: [],diff --git a/apps/desktop/src/app/session/hooks/use-cwd-actions.test.tsx b/apps/desktop/src/app/session/hooks/use-cwd-actions.test.tsxindex 964fe142f89..c938ef9aea0 100644--- a/apps/desktop/src/app/session/hooks/use-cwd-actions.test.tsx+++ b/apps/desktop/src/app/session/hooks/use-cwd-actions.test.tsx@@ -40,6 +40,56 @@ function Harness({return null}+describe('useCwdActions session target', () => {+ afterEach(() => {+ cleanup()+ setCurrentCwd('')+ setCurrentBranch('')+ })++ it('re-homes the named tile, not the primary, and leaves the primary readout alone', async () => {+ const requestGateway = vi.fn(async () => ({ branch: 'dev', cwd: '/opt/data/profiles/austin' }) as never)+ const onSessionRuntimeInfo = vi.fn()+ const activeSessionIdRef: MutableRefObject<string | null> = { current: 'primary-rt' }+ let handle: CwdActionsHandle | null = null+ setCurrentCwd('/primary-workspace')++ function TargetHarness() {+ const actions = useCwdActions({ activeSessionIdRef, onSessionRuntimeInfo, requestGateway })++ useEffect(() => {+ handle = actions+ }, [actions])++ return null+ }++ render(<TargetHarness />)+ await waitFor(() => expect(handle).not.toBeNull())++ await act(async () => {+ await handle!.changeSessionCwd('/opt/data/profiles/austin', 'tile-rt')+ })++ expect(requestGateway).toHaveBeenCalledWith('session.cwd.set', {+ cwd: '/opt/data/profiles/austin',+ session_id: 'tile-rt'+ })+ expect(onSessionRuntimeInfo).toHaveBeenCalledWith('tile-rt', { branch: 'dev', cwd: '/opt/data/profiles/austin' })+ expect($currentCwd.get()).toBe('/primary-workspace')++ await act(async () => {+ await handle!.changeSessionCwd('/opt/data/profiles/austin')+ })++ expect(requestGateway).toHaveBeenLastCalledWith('session.cwd.set', {+ cwd: '/opt/data/profiles/austin',+ session_id: 'primary-rt'+ })+ expect($currentCwd.get()).toBe('/opt/data/profiles/austin')+ })+})+describe('useCwdActions draft workspace target', () => {beforeEach(() => {setCurrentCwd('')diff --git a/apps/desktop/src/app/session/hooks/use-cwd-actions.ts b/apps/desktop/src/app/session/hooks/use-cwd-actions.tsindex 1474cf192d7..e70497f3b6c 100644--- a/apps/desktop/src/app/session/hooks/use-cwd-actions.ts+++ b/apps/desktop/src/app/session/hooks/use-cwd-actions.ts@@ -14,7 +14,7 @@ import type { SessionRuntimeInfo } from '@/types/hermes'interface CwdActionsOptions {activeSessionIdRef: MutableRefObject<string | null>- onSessionRuntimeInfo?: (info: Pick<SessionRuntimeInfo, 'branch' | 'cwd'>) => void+ onSessionRuntimeInfo?: (sessionId: string, info: Pick<SessionRuntimeInfo, 'branch' | 'cwd'>) => voidrequestGateway: <T = unknown>(method: string, params?: Record<string, unknown>) => Promise<T>}@@ -47,18 +47,22 @@ export function useCwdActions({ activeSessionIdRef, onSessionRuntimeInfo, reques)const changeSessionCwd = useCallback(- async (cwd: string) => {+ async (cwd: string, targetSessionId?: string) => {const trimmed = cwd.trim()if (!trimmed) {return}- // Ref, not the closure-captured prop: this hook's consumers are memoized- // on a stable actions object, so the prop can still name the previously- // focused chat. Re-anchoring the wrong session's workspace would point- // that agent's terminal/file tools at another conversation's project.- const sessionId = activeSessionIdRef.current+ // A focused tile names its own runtime id. Otherwise the ref, not the+ // closure-captured prop: this hook's consumers are memoized on a stable+ // actions object, so the prop can still name the previously focused+ // chat. Re-anchoring the wrong session's workspace would point that+ // agent's terminal/file tools at another conversation's project.+ const sessionId = targetSessionId || activeSessionIdRef.current+ // The primary-scoped readouts ($currentCwd/$currentBranch) follow only+ // the primary chat; a tile's own state arrives via onSessionRuntimeInfo.+ const primary = sessionId === activeSessionIdRef.currentif (!sessionId) {setCurrentCwd(trimmed)@@ -100,9 +104,12 @@ export function useCwdActions({ activeSessionIdRef, onSessionRuntimeInfo, requescwd: trimmed})- setCurrentCwd(info.cwd || trimmed)- setCurrentBranch(info.branch || '')- onSessionRuntimeInfo?.({ branch: info.branch || '', cwd: info.cwd || trimmed })+ if (primary) {+ setCurrentCwd(info.cwd || trimmed)+ setCurrentBranch(info.branch || '')+ }++ onSessionRuntimeInfo?.(sessionId, { branch: info.branch || '', cwd: info.cwd || trimmed })} catch (err) {const message = err instanceof Error ? err.message : String(err)@@ -112,8 +119,11 @@ export function useCwdActions({ activeSessionIdRef, onSessionRuntimeInfo, requesreturn}- setCurrentCwd(trimmed)- setCurrentBranch('')+ if (primary) {+ setCurrentCwd(trimmed)+ setCurrentBranch('')+ }+notify({kind: 'warning',title: copy.cwdStagedTitle,diff --git a/apps/desktop/src/app/shell/hooks/use-statusbar-items.lifecycle.test.tsx b/apps/desktop/src/app/shell/hooks/use-statusbar-items.lifecycle.test.tsxindex 099ceeb0485..00bc9530a7a 100644--- a/apps/desktop/src/app/shell/hooks/use-statusbar-items.lifecycle.test.tsx+++ b/apps/desktop/src/app/shell/hooks/use-statusbar-items.lifecycle.test.tsx@@ -47,6 +47,7 @@ function mountStatusbar() {const options = {agentsOpen: false,+ changeSessionCwd: async () => {},chatOpen: true,commandCenterOpen: false,extraLeftItems: [],diff --git a/apps/desktop/src/app/shell/hooks/use-statusbar-items.test.tsx b/apps/desktop/src/app/shell/hooks/use-statusbar-items.test.tsxindex 3aa6beede2d..446af4ad21a 100644--- a/apps/desktop/src/app/shell/hooks/use-statusbar-items.test.tsx+++ b/apps/desktop/src/app/shell/hooks/use-statusbar-items.test.tsx@@ -7,6 +7,7 @@ import { afterEach, describe, expect, it, vi } from 'vitest'import { group } from '@/components/pane-shell/tree/model'import { $layoutTree, noteActiveTreeGroup } from '@/components/pane-shell/tree/store'import { createClientSessionState } from '@/lib/chat-runtime'+import type * as DesktopFs from '@/lib/desktop-fs'import { $freeTierStatus } from '@/store/free-tier'import { INTERFACE_MODES, setInterfaceMode } from '@/store/interface-mode'import { $onboardingGate } from '@/store/onboarding-gate'@@ -29,6 +30,13 @@ import { useStatusbarItems } from './use-statusbar-items'// The mock above replaces the computed store with a writable atom.const $focusedTreePaneId = $focusedTreePaneIdMock as unknown as WritableAtom<null | string>+const selectDesktopPaths = vi.hoisted(() => vi.fn<(options?: unknown) => Promise<string[]>>())++vi.mock('@/lib/desktop-fs', async importOriginal => ({+ ...(await importOriginal<typeof DesktopFs>()),+ selectDesktopPaths+}))+// The focused pane is derived from the layout tree; a settable atom stands in// so a test can focus a tile without building a pane tree.vi.mock('@/store/session-focus', async () => {@@ -73,11 +81,12 @@ function focusPane(storedId: null | string): void {const wrapper = ({ children }: { children: ReactNode }) => <MemoryRouter>{children}</MemoryRouter>-function renderStatusbarItems() {+function renderStatusbarItems(changeSessionCwd: (cwd: string, sessionId?: string) => Promise<void> = async () => {}) {const { result } = renderHook(() =>useStatusbarItems({agentsOpen: false,+ changeSessionCwd,chatOpen: true,commandCenterOpen: false,extraLeftItems: [],@@ -97,10 +106,14 @@ function renderStatusbarItems() {return result.current}-function workspaceMenuIds(): string[] {- const workspace = renderStatusbarItems().leftStatusbarItems.find(item => item.id === 'workspace-cwd')+function workspaceMenu(changeSessionCwd?: (cwd: string, sessionId?: string) => Promise<void>) {+ const workspace = renderStatusbarItems(changeSessionCwd).leftStatusbarItems.find(item => item.id === 'workspace-cwd')- return (workspace?.menuItems ?? []).map(item => item.id)+ return (workspace?.menuItems ?? []).filter(item => !item.hidden)+}++function workspaceMenuIds(): string[] {+ return workspaceMenu().map(item => item.id)}afterEach(() => {@@ -145,8 +158,51 @@ describe('statusbar workspace menu — "Open containing folder"', () => {})})+describe('statusbar workspace menu — change working directory', () => {+ it('re-homes the primary chat through the picker', async () => {+ const changeSessionCwd = vi.fn(async () => {})+ selectDesktopPaths.mockResolvedValueOnce(['/opt/data/profiles/austin'])+ $currentCwd.set('/opt/data')++ const item = workspaceMenu(changeSessionCwd).find(menuItem => menuItem.id === 'change-workspace-path')+ item?.onSelect?.()++ await vi.waitFor(() => expect(changeSessionCwd).toHaveBeenCalledWith('/opt/data/profiles/austin', undefined))+ expect(selectDesktopPaths).toHaveBeenCalledWith(expect.objectContaining({ defaultPath: '/opt/data', directories: true }))+ })++ it("targets a focused tile's own runtime, and is absent for a cold tile or another gateway's tile", async () => {+ const changeSessionCwd = vi.fn(async () => {})+ selectDesktopPaths.mockResolvedValueOnce(['/srv/bot'])+ $selectedStoredSessionId.set('primary')+ $sessions.set([{ cwd: '/opt/data', id: 'tile' }] as never)+ $sessionTiles.set([+ { ownerRoute: { connectionId: null, mode: 'local', profile: 'austin' }, storedSessionId: 'tile' }+ ] as never)+ focusPane('tile')++ expect(workspaceMenuIds()).not.toContain('change-workspace-path')++ $sessionTiles.set([+ {+ ownerRoute: { connectionId: null, mode: 'local', profile: 'austin' },+ runtimeId: 'tile-rt',+ storedSessionId: 'tile'+ }+ ] as never)+ workspaceMenu(changeSessionCwd)+ .find(menuItem => menuItem.id === 'change-workspace-path')+ ?.onSelect?.()+ await vi.waitFor(() => expect(changeSessionCwd).toHaveBeenCalledWith('/srv/bot', 'tile-rt'))++ $sessions.set([{ connection_id: 'conn-remote', cwd: '/opt/data', id: 'tile' }] as never)+ expect(workspaceMenuIds()).not.toContain('change-workspace-path')+ })+})+const statusbarOptions = {agentsOpen: false,+ changeSessionCwd: async () => {},chatOpen: true,commandCenterOpen: false,extraLeftItems: [],diff --git a/apps/desktop/src/app/shell/hooks/use-statusbar-items.tsx b/apps/desktop/src/app/shell/hooks/use-statusbar-items.tsxindex 55c7fe59d68..dcd20576b91 100644--- a/apps/desktop/src/app/shell/hooks/use-statusbar-items.tsx+++ b/apps/desktop/src/app/shell/hooks/use-statusbar-items.tsx@@ -16,6 +16,7 @@ import { Badge } from '@/components/ui/badge'import { Codicon } from '@/components/ui/codicon'import { GlyphSpinner } from '@/components/ui/glyph-spinner'import { useI18n } from '@/i18n'+import { selectDesktopPaths } from '@/lib/desktop-fs'import { displayPath, pathLeaf } from '@/lib/display-path'import { statusBarGatewayHealth } from '@/lib/gateway-health-pill'import {@@ -82,6 +83,7 @@ const EMPTY_USAGE: UsageStats = { calls: 0, input: 0, output: 0, total: 0 }interface StatusbarItemsOptions {agentsOpen: boolean+ changeSessionCwd: (cwd: string, sessionId?: string) => Promise<void>chatOpen: booleancommandCenterOpen: booleanextraLeftItems: readonly StatusbarItem[]@@ -98,6 +100,7 @@ interface StatusbarItemsOptions {export function useStatusbarItems({agentsOpen,+ changeSessionCwd,chatOpen,commandCenterOpen,extraLeftItems,@@ -114,6 +117,7 @@ export function useStatusbarItems({const copy = t.shell.statusbarconst freeTierCopy = t.freeTierconst fileMenu = t.fileMenu+ const changeCwdLabel = t.rightSidebar.changeCwdTitleconst primaryActiveSessionId = useStore($activeSessionId)const activeGatewayProfile = useStore($activeGatewayProfile)// What the button paints and flips is whether the terminal is ON SCREEN —@@ -284,6 +288,27 @@ export function useStatusbarItems({const projectTree = useStore($projectTree)const projectName = useMemo(() => projectNameForCwd(currentCwd), [currentCwd, projectTree])+ // Re-home the FOCUSED chat's workspace: the recovery path for a chat that+ // started in the wrong folder, Bot Chats included (they never reach the+ // sidebar's move-to-project). The picker is remote-aware, so a remote+ // gateway browses its own filesystem. A cold tile has no runtime to re-home,+ // and a tile on another gateway would be browsed on the wrong machine.+ const workspaceTargetId = primaryFocused ? undefined : focusedRuntimeId || null+ const offerChangeWorkspace = workspaceTargetId !== null && !focusedRowConnectionId++ const changeWorkspace = useCallback(async () => {+ const [dir] = await selectDesktopPaths({+ defaultPath: currentCwd,+ directories: true,+ multiple: false,+ title: changeCwdLabel+ })++ if (dir) {+ await changeSessionCwd(dir, workspaceTargetId ?? undefined)+ }+ }, [changeSessionCwd, currentCwd, changeCwdLabel, workspaceTargetId])+const sessionStartedAt = resolveSessionTimerSince({focusedStoredSessionId,primaryFocused,@@ -566,6 +591,14 @@ export function useStatusbarItems({label: projectName || (currentCwd ? pathLeaf(currentCwd) : undefined),menuItems: currentCwd? [+ {+ disabled: busy,+ hidden: !offerChangeWorkspace,+ id: 'change-workspace-path',+ label: changeCwdLabel,+ onSelect: () => void changeWorkspace(),+ title: displayPath(currentCwd)+ },{id: 'copy-workspace-path',label: fileMenu.copyPath,@@ -644,6 +677,9 @@ export function useStatusbarItems({[agentsOpen,botsShowing,+ busy,+ changeCwdLabel,+ changeWorkspace,commandCenterOpen,copy,currentCwd,@@ -652,6 +688,7 @@ export function useStatusbarItems({fileMenu.copyPath,fileMenu.revealFileManager,fileMenu.revealInSidebar,+ offerChangeWorkspace,offerLocalReveal,freeTier?.model,freeTierSignInOpen,