Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(desktop): r4-b1 resume the last active chat on re-entry to chats
Diego Zacariasb68947480c0a
diff --git a/desktop-app/ui/src/hooks/domain/__tests__/useNavigationController.test.ts b/desktop-app/ui/src/hooks/domain/__tests__/useNavigationController.test.tsindex d9489d12c..f357facde 100644--- a/desktop-app/ui/src/hooks/domain/__tests__/useNavigationController.test.ts+++ b/desktop-app/ui/src/hooks/domain/__tests__/useNavigationController.test.ts@@ -2,7 +2,12 @@import { describe, expect, it } from 'vitest'import { act, renderHook } from '@testing-library/react'import { AGENT_WORKSPACE_ROUTES, DESKTOP_ROUTES } from '../../../constants/navigation'-import { closeWorkspaceTab, openChatTab } from '../../../lib/workspaceTabs'+import {+ closeWorkspaceTab,+ openChatTab,+ openFilesTab,+ selectWorkspaceTab,+} from '../../../lib/workspaceTabs'import { useNavigationController } from '../useNavigationController'describe('useNavigationController — agent-centric navigation (Fase 2)', () => {@@ -60,6 +65,40 @@ describe('useNavigationController — agent-centric navigation (Fase 2)', () =>expect(result.current.lastActiveChatTabId).toBeNull()})+ it('resumes the last active chat, not the last chat by array order, on re-entry (§1, R4-B1)', () => {+ const { result } = renderHook(() => useNavigationController())+ // Build [blank chat, files, A, B] with all real store producers, then leave+ // A as the last active chat while B sits after it in array order.+ act(() => result.current.handleNavSelect(DESKTOP_ROUTES.files))+ act(() =>+ result.current.setWorkspaceTabs(state =>+ openChatTab(state, { id: 'chat-a', agentRef: 'alpha', chatId: 'c1' })+ )+ )+ act(() =>+ result.current.setWorkspaceTabs(state =>+ openChatTab(state, { id: 'chat-b', agentRef: 'beta', chatId: 'c2' })+ )+ )+ // Re-activate A so it is the LAST ACTIVE chat while B is the last by order.+ act(() => result.current.setWorkspaceTabs(state => selectWorkspaceTab(state, 'chat-a')))+ expect(result.current.lastActiveChatTabId).toBe('chat-a')++ // Leave the chat section for files (the "return to Chats later" scenario).+ act(() => result.current.setWorkspaceTabs(state => openFilesTab(state, { id: 'files-2' })))+ expect(result.current.activeTab?.kind).toBe('files')+ expect(result.current.lastActiveChatTabId).toBe('chat-a')++ // Re-entering Chats must resume A (the chat the user left), not B (the last+ // chat by array order that the pre-fix precedence would pick).+ let focused: { agentRef: string; chatId: string } | null = null+ act(() => {+ focused = result.current.handleNavSelect(DESKTOP_ROUTES.chat)+ })+ expect(result.current.activeTab?.id).toBe('chat-a')+ expect(focused).toEqual({ agentRef: 'alpha', chatId: 'c1' })+ })+it('no longer exposes the removed context/teams handlers or state', () => {const { result } = renderHook(() => useNavigationController())const controller = result.current as Record<string, unknown>diff --git a/desktop-app/ui/src/hooks/domain/useNavigationController.ts b/desktop-app/ui/src/hooks/domain/useNavigationController.tsindex 1fae40d43..c6506595e 100644--- a/desktop-app/ui/src/hooks/domain/useNavigationController.ts+++ b/desktop-app/ui/src/hooks/domain/useNavigationController.ts@@ -60,6 +60,10 @@ export function useNavigationController() {return prev})}, [activeTab, workspaceTabs])+ // Mirror of `lastActiveChatTabId` for the synchronous read in `focusChatSection`+ // (it runs against `workspaceTabsRef.current`, not the render's snapshot).+ const lastActiveChatTabIdRef = useRef(lastActiveChatTabId)+ lastActiveChatTabIdRef.current = lastActiveChatTabIdconst clearAppsPicker = useCallback(() => setAppsPickerActive(false), [])@@ -84,10 +88,20 @@ export function useNavigationController() {setAppsPickerActive(false)const current = workspaceTabsRef.currentconst active = activeWorkspaceTab(current)+ // Precedence (mini-spec 08 §1): the active chat wins (no re-homing); else+ // RESUME the last active chat tab the user left — validated live against the+ // store so a not-yet-reflected close cannot resurrect a stale id — rather than+ // the last chat by array order; else the last chat by order (first boot, no+ // last-active); else seed a blank.+ const lastActiveId = lastActiveChatTabIdRef.current+ const resumeTarget =+ lastActiveId !== null+ ? current.tabs.find(tab => tab.id === lastActiveId && tab.kind === 'chat')+ : undefinedconst target =active?.kind === 'chat'? active- : [...current.tabs].reverse().find(tab => tab.kind === 'chat')+ : (resumeTarget ?? [...current.tabs].reverse().find(tab => tab.kind === 'chat'))if (target) {setWorkspaceTabs(state =>state.activeTabId === target.id ? state : { ...state, activeTabId: target.id }