diff --git a/src/components/conversations/conversation-detail-panel.tsx b/src/components/conversations/conversation-detail-panel.tsx index 8d92dd3..9cf8474 100644 --- a/src/components/conversations/conversation-detail-panel.tsx +++ b/src/components/conversations/conversation-detail-panel.tsx @@ -694,6 +694,12 @@ const ConversationTabView = memo(function ConversationTabView({ setDraftAgentType(nextAgentType) setModeId(null) setAgentConnectError(null) + + // If not yet connected, just update state — auto-connect will use the + // new agentType once canAutoConnect is satisfied. + const s = connStatusRef.current + if (!s || s === "disconnected" || s === "error") return + connDisconnect() .catch((e) => console.error("[ConversationTabView] disconnect old agent:", e) @@ -1090,7 +1096,7 @@ export function ConversationDetailPanel() { const handleNewConversation = useCallback(() => { if (!folder) return - openNewConversationTab("codex", folder.path) + openNewConversationTab(folder.path) }, [folder, openNewConversationTab]) const handleCloseActiveTab = useCallback(() => { @@ -1103,18 +1109,9 @@ export function ConversationDetailPanel() { if (!folder) return if (hasNoTabs) { - openNewConversationTab( - newConversation?.agentType ?? "codex", - newConversation?.workingDir ?? folder.path - ) + openNewConversationTab(newConversation?.workingDir ?? folder.path) } - }, [ - folder, - hasNoTabs, - newConversation?.agentType, - newConversation?.workingDir, - openNewConversationTab, - ]) + }, [folder, hasNoTabs, newConversation?.workingDir, openNewConversationTab]) const canTile = isTileMode && tabs.length > 1 diff --git a/src/components/conversations/sidebar-conversation-list.tsx b/src/components/conversations/sidebar-conversation-list.tsx index c0b9adf..3dd43ee 100644 --- a/src/components/conversations/sidebar-conversation-list.tsx +++ b/src/components/conversations/sidebar-conversation-list.tsx @@ -373,7 +373,7 @@ export function SidebarConversationList({ const handleNewConversation = useCallback(() => { if (!folder) return - openNewConversationTab("codex", folder.path) + openNewConversationTab(folder.path) }, [folder, openNewConversationTab]) const handleImport = useCallback(async () => { diff --git a/src/components/layout/folder-title-bar.tsx b/src/components/layout/folder-title-bar.tsx index 5af6fc5..eeb616c 100644 --- a/src/components/layout/folder-title-bar.tsx +++ b/src/components/layout/folder-title-bar.tsx @@ -151,7 +151,7 @@ export function FolderTitleBar() { if (matchShortcutEvent(e, shortcuts.new_conversation)) { if (!folderPath) return e.preventDefault() - openNewConversationTab("codex", folderPath) + openNewConversationTab(folderPath) return } if (matchShortcutEvent(e, shortcuts.open_folder)) { diff --git a/src/components/layout/sidebar.tsx b/src/components/layout/sidebar.tsx index a0014d2..1479fcb 100644 --- a/src/components/layout/sidebar.tsx +++ b/src/components/layout/sidebar.tsx @@ -21,7 +21,7 @@ export function Sidebar() { const handleNewConversation = useCallback(() => { if (!folder) return - openNewConversationTab("codex", folder.path) + openNewConversationTab(folder.path) }, [folder, openNewConversationTab]) if (!isOpen) return null diff --git a/src/contexts/tab-context.tsx b/src/contexts/tab-context.tsx index d1e0e5c..41d985e 100644 --- a/src/contexts/tab-context.tsx +++ b/src/contexts/tab-context.tsx @@ -19,6 +19,7 @@ import type { ConversationStatus, OpenedConversation, } from "@/lib/types" +import { AGENT_DISPLAY_ORDER } from "@/lib/types" interface TabItemInternal { id: string @@ -54,7 +55,7 @@ interface TabContextValue { switchTab: (tabId: string) => void pinTab: (tabId: string) => void toggleTileMode: () => void - openNewConversationTab: (agentType: AgentType, workingDir: string) => void + openNewConversationTab: (workingDir: string) => void bindConversationTab: ( tabId: string, conversationId: number, @@ -419,7 +420,7 @@ export function TabProvider({ children }: TabProviderProps) { id: makeNewConversationTabId(), kind: "conversation", conversationId: null, - agentType: preferred?.agentType ?? "codex", + agentType: AGENT_DISPLAY_ORDER[0], title: t("newConversation"), isPinned: true, workingDir: preferred?.workingDir ?? folder?.path, @@ -553,18 +554,27 @@ export function TabProvider({ children }: TabProviderProps) { ) const openNewConversationTab = useCallback( - (agentType: AgentType, workingDir: string) => { + (workingDir: string) => { const existingTab = rawTabsRef.current.find( - (t) => t.conversationId == null && t.agentType === agentType + (t) => t.conversationId == null ) if (existingTab) { + // Update workingDir if it differs from the request + if (existingTab.workingDir !== workingDir) { + setTabs((prev) => + prev.map((t) => + t.id === existingTab.id ? { ...t, workingDir } : t + ) + ) + } setActiveTabId(existingTab.id) syncFolderContext(existingTab) activateConversationPane() return } + const agentType = AGENT_DISPLAY_ORDER[0] const tabId = makeNewConversationTabId() const newTab: TabItemInternal = { id: tabId,