The all-in-one local AI studio for your desktop: chat, image and video generation and a coding agent in one free, open source app. Windows and Linux. No Docker, no terminal, no cloud required.
TypeScript agentai-chatai-studioall-in-onecoding-agentdesktop-appfluximage-generationlinuxllmlocal-ailocal-llmopen-sourceprivacyself-hostedstable-diffusionuncensoreduncensored-aivideo-generationwindows
fix(code): a Code conversation opens in the Code tab, and the Code button goes back to it
purplef8bc6173b87f
diff --git a/e2e/code-conversation-stays-in-code.spec.ts b/e2e/code-conversation-stays-in-code.spec.tsnew file mode 100644index 00000000..17d0de10--- /dev/null+++ b/e2e/code-conversation-stays-in-code.spec.ts@@ -0,0 +1,73 @@+import { test, expect, type Page } from '@playwright/test'+import { tauriMockInit, DEFAULT_ASSISTANT_REPLY, DEFAULT_MODEL_NAME } from './support/tauri-mock'+import { seedOnboardingDone } from './support/cloud-mock'+import { openNewChat } from './support/ui'++/**+ * Gegenprobe on the real Windows build, 30.09.2026, two findings:+ *+ * 1. With a Code run in flight, Chat and then Code in the rail landed on the+ * empty Code start page. The running conversation had to be found in the+ * list.+ * 2. After a restart the last Code conversation opened in the CHAT tab, with+ * Agent off. The customer's "continue" typed there went out without tools.+ *+ * The app still starts in the Chat tab (codexStore, product decision); it now+ * starts on the empty chat instead of a Code conversation in disguise, and the+ * Code button returns to the Code conversation worked on last.+ */++const MARKE = 'Zeile aus dem Code-Verlauf, die nur im Code-Reiter stehen darf'++async function bootCode(page: Page): Promise<void> {+ await page.setViewportSize({ width: 1280, height: 800 })+ await page.addInitScript(tauriMockInit, { assistantReply: DEFAULT_ASSISTANT_REPLY, modelName: DEFAULT_MODEL_NAME })+ await seedOnboardingDone(page)+ await page.goto('/')+ await page.getByRole('button', { name: 'Code', exact: true }).click()+ await openNewChat(page)+}++/** A Code conversation with one exchange, written the way the store writes it, then flushed to disk. */+async function codeVerlauf(page: Page): Promise<void> {+ await page.evaluate(async (marke) => {+ const chatPath = '/src/stores/chatStore.ts'+ const chat = await import(/* @vite-ignore */ chatPath) as typeof import('../src/stores/chatStore')+ const aktiv = chat.useChatStore.getState().activeConversationId+ if (!aktiv) throw new Error('no active Code conversation')+ const conv = chat.useChatStore.getState().conversations.find((c) => c.id === aktiv)+ if (conv?.mode !== 'codex') throw new Error(`active conversation is ${conv?.mode}, not codex`)+ chat.useChatStore.getState().addMessage(aktiv, { id: 'u1', role: 'user', content: 'build the page', timestamp: Date.now() })+ chat.useChatStore.getState().addMessage(aktiv, { id: 'a1', role: 'assistant', content: marke, timestamp: Date.now() + 1 })+ await chat.flushChatPersist()+ }, MARKE)+}++test('the Code button goes back to the Code conversation, not to an empty start page', async ({ page }) => {+ await bootCode(page)+ await codeVerlauf(page)+ await expect(page.getByTestId('codex-transcript').getByText(MARKE)).toBeVisible()++ // The rail's Chat button, not the Chat tab in the top bar.+ await page.locator('button[title="Chat"][aria-label="Chat"]').first().click()+ await expect(page.getByText(MARKE)).toHaveCount(0)++ await page.getByRole('button', { name: 'Code', exact: true }).click()+ await expect(page.getByTestId('codex-transcript').getByText(MARKE)).toBeVisible()+})++test('after a restart a Code conversation is not shown as a chat', async ({ page }) => {+ await bootCode(page)+ await codeVerlauf(page)+ await expect(page.getByTestId('codex-transcript').getByText(MARKE)).toBeVisible()++ await page.reload()+ // The app starts in the Chat tab, on the empty chat.+ await expect(page.locator('textarea').first()).toBeVisible()+ await expect(page.getByTestId('codex-transcript')).toHaveCount(0)+ await expect(page.getByText(MARKE)).toHaveCount(0)++ // One click and the Code conversation is back, in the Code tab.+ await page.getByRole('button', { name: 'Code', exact: true }).click()+ await expect(page.getByTestId('codex-transcript').getByText(MARKE)).toBeVisible()+})diff --git a/src/components/layout/Sidebar.tsx b/src/components/layout/Sidebar.tsxindex 1d8f6863..3ecd7d6c 100644--- a/src/components/layout/Sidebar.tsx+++ b/src/components/layout/Sidebar.tsx@@ -2,6 +2,7 @@ import { useDeferredValue, useEffect, useMemo, useRef, useState } from 'react'import { motion, AnimatePresence } from 'framer-motion'import { Plus, Search, Trash2, Edit3, Check, X, MessageSquare, Code, Radio, Copy, RefreshCw, Square, Wifi, Globe, QrCode, PanelLeftOpen, PanelLeftClose } from 'lucide-react'import { useChatStore } from '../../stores/chatStore'+import { latestConversationOfMode } from '../../lib/conversation-mode'import { useUIStore } from '../../stores/uiStore'import { useCompareStore } from '../../stores/compareStore'import { useModelStore } from '../../stores/modelStore'@@ -440,7 +441,7 @@ export function Sidebar() {<MessageSquare size={15} /></button><button- onClick={() => { setChatMode('codex'); setActiveConversation(null); setView('chat'); setDispatchPicker(false) }}+ onClick={() => { setChatMode('codex'); setActiveConversation(latestConversationOfMode(useChatStore.getState().conversations, 'codex')); setView('chat'); setDispatchPicker(false) }}title="Code"aria-label="Code"className={railBtn(isCodingMode)}@@ -604,7 +605,7 @@ export function Sidebar() {{/* Code tab — direct switch to the coding agent (no dropdown).Internal mode value 'codex' is kept for storage back-compat. */}<button- onClick={() => { setChatMode('codex'); setActiveConversation(null); setView('chat'); setDispatchPicker(false) }}+ onClick={() => { setChatMode('codex'); setActiveConversation(latestConversationOfMode(useChatStore.getState().conversations, 'codex')); setView('chat'); setDispatchPicker(false) }}title="Code"aria-label="Code"className={`flex items-center gap-1.25 justify-center px-2.5 h-[var(--control-h-md)] rounded-[5px] font-medium transition-all flex-1 min-w-0 ${diff --git a/src/lib/__tests__/conversation-opens-in-its-own-tab.test.ts b/src/lib/__tests__/conversation-opens-in-its-own-tab.test.tsnew file mode 100644index 00000000..825c139e--- /dev/null+++ b/src/lib/__tests__/conversation-opens-in-its-own-tab.test.ts@@ -0,0 +1,44 @@+import { describe, it, expect } from 'vitest'+import { activeConversationAtStart, latestConversationOfMode } from '../conversation-mode'++// Gegenprobe on the real build, 30.09.2026: after a restart the last Code+// conversation opened in the Chat tab with Agent off, and "continue" went out+// without tools. And the Code button always landed on the empty start page,+// even with a run in flight.++const convs = [+ { id: 'chat-old', mode: 'lu' as const, updatedAt: 1 },+ { id: 'legacy', updatedAt: 2 },+ { id: 'code-old', mode: 'codex' as const, updatedAt: 3 },+ { id: 'code-new', mode: 'codex' as const, updatedAt: 5 },+ { id: 'remote', mode: 'remote' as const, updatedAt: 6 },+]++describe('activeConversationAtStart', () => {+ it('drops a Code conversation, the app starts in the Chat tab', () => {+ expect(activeConversationAtStart(convs, 'code-new')).toBeNull()+ })+ it('drops any conversation of another tab', () => {+ expect(activeConversationAtStart(convs, 'remote')).toBeNull()+ })+ it('keeps a chat, also one saved before conversations had a mode', () => {+ expect(activeConversationAtStart(convs, 'chat-old')).toBe('chat-old')+ expect(activeConversationAtStart(convs, 'legacy')).toBe('legacy')+ })+ it('drops an id that no longer exists', () => {+ expect(activeConversationAtStart(convs, 'gone')).toBeNull()+ expect(activeConversationAtStart(convs, null)).toBeNull()+ })+})++describe('latestConversationOfMode', () => {+ it('returns the Code conversation worked on last', () => {+ expect(latestConversationOfMode(convs, 'codex')).toBe('code-new')+ })+ it('counts a conversation without a mode as a chat', () => {+ expect(latestConversationOfMode(convs, 'lu')).toBe('legacy')+ })+ it('is null when there is none', () => {+ expect(latestConversationOfMode([{ id: 'a', mode: 'lu', updatedAt: 1 }], 'codex')).toBeNull()+ })+})diff --git a/src/lib/conversation-mode.ts b/src/lib/conversation-mode.tsindex 4edf07e8..df2a9ee3 100644--- a/src/lib/conversation-mode.ts+++ b/src/lib/conversation-mode.ts@@ -32,3 +32,41 @@ export function conversationMode(): NonNullable<Conversation['mode']> {return conv?.mode ?? 'lu'}++/**+ * The conversation that may stay active when the app starts.+ *+ * The app always starts in the Chat tab (codexStore resets chatMode to 'lu'+ * on every rehydrate, a product decision), while the active conversation id+ * is persisted. When the last conversation was a Code one, the Chat tab+ * rendered it as a plain chat with Agent off, and a "continue" typed there+ * went out without any tools (Gegenprobe on the real build, 30.09.2026). A+ * conversation that belongs to another tab therefore does not survive the+ * start; the app opens on the empty chat, as it does for a newcomer.+ */+export function activeConversationAtStart(+ conversations: ReadonlyArray<{ id: string } & ConversationModeSource>,+ activeId: string | null | undefined,+): string | null {+ if (!activeId) return null+ const conv = conversations.find((c) => c.id === activeId)+ return conv && conversationMode(conv) === 'lu' ? activeId : null+}++/**+ * The Code conversation the Code button returns to: the one worked on last.+ * The button used to clear the active conversation, so going to Chat and+ * back to Code while a run was in flight landed on the empty start page and+ * the running conversation had to be found in the list.+ */+export function latestConversationOfMode(+ conversations: ReadonlyArray<{ id: string; updatedAt?: number } & ConversationModeSource>,+ mode: NonNullable<Conversation['mode']>,+): string | null {+ let best: { id: string; updatedAt?: number } | null = null+ for (const c of conversations) {+ if (conversationMode(c) !== mode) continue+ if (!best || (c.updatedAt ?? 0) > (best.updatedAt ?? 0)) best = c+ }+ return best?.id ?? null+}diff --git a/src/stores/chatStore.ts b/src/stores/chatStore.tsindex 6f7b856f..107db604 100644--- a/src/stores/chatStore.ts+++ b/src/stores/chatStore.ts@@ -20,6 +20,7 @@ import { useCodexStore } from './codexStore'import { useAgentTaskStore } from './agentTaskStore'import { log } from '../lib/logger'import { isRecord, prop } from '../types/json-guards'+import { activeConversationAtStart } from '../lib/conversation-mode'/*** Rehydration migration for Phase 1 (v2.4.0) — wraps legacy@@ -678,7 +679,9 @@ export const useChatStore = create<ChatState>()(// buy nothing and cost a reset on every downgrade.merge: (persistedState, currentState) => {const migrated = migratePersistedChat(persistedState)- return { ...currentState, ...(isRecord(migrated) ? migrated : {}) }+ const merged = { ...currentState, ...(isRecord(migrated) ? migrated : {}) }+ // The app starts in the Chat tab; see activeConversationAtStart.+ return { ...merged, activeConversationId: activeConversationAtStart(merged.conversations, merged.activeConversationId) }},})