The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
refactor(desktop): keep the statusbar and wiring hooks inside main's size caps
Brooklyn Nicholson79fe8472856f
diff --git a/apps/desktop/src/app/contrib/wiring.tsx b/apps/desktop/src/app/contrib/wiring.tsxindex a65264f3f5d..9f5655f491f 100644--- a/apps/desktop/src/app/contrib/wiring.tsx+++ b/apps/desktop/src/app/contrib/wiring.tsx@@ -414,19 +414,13 @@ export function ContribWiring({ children }: { children: ReactNode }) {const { loadMoreMessagingForPlatform, loadMoreSessions, refreshCronJobs, refreshMessagingSessions, refreshSessions } =useSessionListActions({ profileScope })- const updateSessionRuntimeInfo = useCallback(- (sessionId: string, info: { branch?: string; cwd?: string }) =>- updateSessionState(sessionId, state => ({- ...state,- branch: info.branch ?? state.branch,- cwd: info.cwd ?? state.cwd- })),- [updateSessionState]- )-const { changeSessionCwd, refreshProjectBranch } = useCwdActions({activeSessionIdRef,- onSessionRuntimeInfo: updateSessionRuntimeInfo,+ onSessionRuntimeInfo: useCallback(+ (sessionId: string, { branch, cwd }: { branch?: string; cwd?: string }) =>+ updateSessionState(sessionId, state => ({ ...state, branch: branch ?? state.branch, cwd: cwd ?? state.cwd })),+ [updateSessionState]+ ),requestGateway})diff --git a/apps/desktop/src/app/shell/hooks/use-change-workspace.ts b/apps/desktop/src/app/shell/hooks/use-change-workspace.tsnew file mode 100644index 00000000000..4231dcba151--- /dev/null+++ b/apps/desktop/src/app/shell/hooks/use-change-workspace.ts@@ -0,0 +1,52 @@+import { useCallback, useMemo } from 'react'++import { useI18n } from '@/i18n'+import { selectDesktopPaths } from '@/lib/desktop-fs'+import { displayPath } from '@/lib/display-path'++import type { StatusbarMenuItem } from '../statusbar-controls'++interface FocusedTarget {+ focusedRowConnectionId: string+ focusedRuntimeId: null | string+ primaryFocused: boolean+}++/**+ * The workspace menu's "Change working directory" item: re-homes the FOCUSED+ * chat, 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, so the item is hidden for both. Disabled while a turn+ * runs: the backend refuses `session.cwd.set` then.+ */+export function useChangeWorkspaceItem(+ changeSessionCwd: (cwd: string, sessionId?: string) => Promise<void>,+ currentCwd: string,+ busy: boolean,+ { focusedRowConnectionId, focusedRuntimeId, primaryFocused }: FocusedTarget+): StatusbarMenuItem {+ const title = useI18n().t.rightSidebar.changeCwdTitle+ const targetId = primaryFocused ? undefined : focusedRuntimeId || null++ const changeWorkspace = useCallback(async () => {+ const [dir] = await selectDesktopPaths({ defaultPath: currentCwd, directories: true, multiple: false, title })++ if (dir) {+ await changeSessionCwd(dir, targetId ?? undefined)+ }+ }, [changeSessionCwd, currentCwd, targetId, title])++ return useMemo(+ () => ({+ disabled: busy,+ hidden: targetId === null || Boolean(focusedRowConnectionId),+ id: 'change-workspace-path',+ label: title,+ onSelect: () => void changeWorkspace(),+ title: displayPath(currentCwd)+ }),+ [busy, changeWorkspace, currentCwd, focusedRowConnectionId, targetId, title]+ )+}diff --git a/apps/desktop/src/app/shell/hooks/use-focused-session-row.ts b/apps/desktop/src/app/shell/hooks/use-focused-session-row.tsnew file mode 100644index 00000000000..5fc9d6bd20f--- /dev/null+++ b/apps/desktop/src/app/shell/hooks/use-focused-session-row.ts@@ -0,0 +1,21 @@+import { useStoreSelector } from '@/lib/use-session-slice'+import { $sessions, sessionMatchesStoredId } from '@/store/session'++/**+ * The focused session's stored row scalars: its cold/fallback start time and+ * cwd, and the gateway it runs on (a Connections-tagged row names its gateway;+ * an untagged one is the window's primary, which decides whether the OS file+ * manager on this computer can show its workspace at all). Each is selected on+ * its own, so a session-list write (title updates, poll refreshes, archives)+ * re-renders the statusbar only when one of these answers flips.+ */+export function useFocusedSessionRow(focusedStoredSessionId: null | string) {+ const row = (sessions: ReturnType<typeof $sessions.get>) =>+ focusedStoredSessionId ? sessions.find(s => sessionMatchesStoredId(s, focusedStoredSessionId)) : undefined++ return {+ focusedRowConnectionId: useStoreSelector($sessions, sessions => row(sessions)?.connection_id?.trim() || ''),+ focusedRowCwd: useStoreSelector($sessions, sessions => row(sessions)?.cwd?.trim() || ''),+ focusedRowStartedAt: useStoreSelector($sessions, sessions => row(sessions)?.started_at ?? null)+ }+}diff --git a/apps/desktop/src/app/shell/hooks/use-statusbar-items.tsx b/apps/desktop/src/app/shell/hooks/use-statusbar-items.tsxindex dcd20576b91..37266e67192 100644--- a/apps/desktop/src/app/shell/hooks/use-statusbar-items.tsx+++ b/apps/desktop/src/app/shell/hooks/use-statusbar-items.tsx@@ -9,14 +9,15 @@ import { toggleTerminalPane } from '@/app/right-sidebar/terminal/reveal-focus'import { useApprovalModeStatusbarItem } from '@/app/shell/approval-mode-menu'import { ContextMeterDetail, ContextUsagePanel } from '@/app/shell/context-usage-panel'import { GatewayMenuPanel } from '@/app/shell/gateway-menu-panel'+import { useChangeWorkspaceItem } from '@/app/shell/hooks/use-change-workspace'import { useContextBreakdown } from '@/app/shell/hooks/use-context-breakdown'+import { useFocusedSessionRow } from '@/app/shell/hooks/use-focused-session-row'import { useSystemResourcesStatusbarItem } from '@/app/shell/system-resources-statusbar'import { $paneVisible } from '@/components/pane-shell/tree/store'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 {@@ -58,8 +59,7 @@ import {$sessionStartedAt,$tileSessionFocusStartedAt,$turnStartedAt,- idsShareLineage,- sessionMatchesStoredId+ idsShareLineage} from '@/store/session'import { $focusedStoredSessionId } from '@/store/session-focus'import { $focusedRuntimeId, $focusedSessionState, $sessionTiles, isSessionRemote } from '@/store/session-states'@@ -117,7 +117,6 @@ 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 —@@ -218,34 +217,8 @@ export function useStatusbarItems({const turnStartedAt = primaryFocused ? primaryTurnStartedAt : focusedTurnStartedAt- // A tile's stored row supplies the cold/fallback session-start and cwd when- // no focused runtime value is available. Only these scalars are read off- // `$sessions`, so select them — a whole-list `useStore` re-ran this hook on- // every session-list write (title updates, poll refreshes, archives).- const focusedRowStartedAt = useStoreSelector($sessions, sessions =>- focusedStoredSessionId- ? (sessions.find(s => sessionMatchesStoredId(s, focusedStoredSessionId))?.started_at ?? null)- : null- )-- const focusedRowCwd = useStoreSelector($sessions, sessions => {- if (!focusedStoredSessionId) {- return ''- }-- const row = sessions.find(s => sessionMatchesStoredId(s, focusedStoredSessionId))-- return row?.cwd?.trim() || ''- })-- // Which backend the focused row runs on: a Connections-tagged row names its- // gateway; an untagged one is the window's primary. Decides whether the OS- // file manager on this computer can show its workspace at all.- const focusedRowConnectionId = useStoreSelector($sessions, sessions =>- focusedStoredSessionId- ? sessions.find(s => sessionMatchesStoredId(s, focusedStoredSessionId))?.connection_id?.trim() || ''- : ''- )+ // A tile's stored row: cold/fallback start and cwd, and which backend it runs on.+ const { focusedRowConnectionId, focusedRowCwd, focusedRowStartedAt } = useFocusedSessionRow(focusedStoredSessionId)const offerLocalReveal = shouldOfferLocalReveal(focusedRowConnectionId, connection?.mode === 'remote')@@ -288,26 +261,11 @@ 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 changeWorkspaceItem = useChangeWorkspaceItem(changeSessionCwd, currentCwd, busy, {+ focusedRowConnectionId,+ focusedRuntimeId,+ primaryFocused+ })const sessionStartedAt = resolveSessionTimerSince({focusedStoredSessionId,@@ -591,14 +549,7 @@ 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)- },+ changeWorkspaceItem,{id: 'copy-workspace-path',label: fileMenu.copyPath,@@ -677,9 +628,7 @@ export function useStatusbarItems({[agentsOpen,botsShowing,- busy,- changeCwdLabel,- changeWorkspace,+ changeWorkspaceItem,commandCenterOpen,copy,currentCwd,@@ -688,7 +637,6 @@ export function useStatusbarItems({fileMenu.copyPath,fileMenu.revealFileManager,fileMenu.revealInSidebar,- offerChangeWorkspace,offerLocalReveal,freeTier?.model,freeTierSignInOpen,diff --git a/tests/tui_gateway/test_profile_resume_cwd.py b/tests/tui_gateway/test_profile_resume_cwd.pyindex 2322ffc7c5a..4a826d895f9 100644--- a/tests/tui_gateway/test_profile_resume_cwd.py+++ b/tests/tui_gateway/test_profile_resume_cwd.py@@ -10,7 +10,7 @@ from __future__ import annotationsimport pytest-import tui_gateway.server as server+from tui_gateway import serverfrom hermes_state import SessionDBfrom tests.tui_gateway.test_tui_gateway_server import _write_profile_cfg