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(agent): the workspace folder now hangs on the chat id, not on its title
purpleb8d2177b2c81
diff --git a/src-tauri/src/commands/agent.rs b/src-tauri/src/commands/agent.rsindex a6d47fcf..16a04fb4 100644--- a/src-tauri/src/commands/agent.rs+++ b/src-tauri/src/commands/agent.rs@@ -493,6 +493,35 @@ pub fn get_chat_workspace_override(}+/// Sub-folder names of `~/agent-workspace`, so the app can find the folder an+/// OLDER chat already owns.+///+/// The frontend used to rebuild a chat's folder name from its title on every+/// turn, and the auto-rename after the first message therefore moved the+/// folder out from under a running agent (counter-check round 2, 2026-08-29).+/// The name is pinned per conversation now, but chats that predate the pin+/// have only their folder on disk to go by. Their names all end in the stable+/// `-<id6>` suffix, so one listing is enough to adopt the right one.+///+/// Names only, no paths, directories only. A missing or unreadable root is an+/// empty list, never an error: not finding a legacy folder simply means a new+/// one gets created.+#[tauri::command]+pub fn list_agent_workspaces() -> Result<Vec<String>, String> {+ let root = agent_workspace_root();+ let entries = match fs::read_dir(&root) {+ Ok(e) => e,+ Err(_) => return Ok(Vec::new()),+ };+ let mut names: Vec<String> = entries+ .flatten()+ .filter(|e| e.file_type().map(|t| t.is_dir()).unwrap_or(false))+ .filter_map(|e| e.file_name().to_str().map(|s| s.to_string()))+ .collect();+ names.sort();+ Ok(names)+}+/// Human byte size for tool messages. Mirrors formatBytes in builtin-tools.ts/// so the desktop and relay paths say the same thing about the same file.fn format_bytes(bytes: u64) -> String {@@ -509,6 +538,46 @@ fn format_bytes(bytes: u64) -> String {}}+#[cfg(test)]+mod workspace_listing_tests {+ use std::fs;++ /// The listing rule the frontend's fallback search depends on: folder+ /// names, directories only, sorted, and a plain file is not a workspace.+ #[test]+ fn lists_only_directory_names_sorted() {+ let root = std::env::temp_dir().join("lu-test-agent-workspace-listing");+ let _ = fs::remove_dir_all(&root);+ fs::create_dir_all(root.join("zeta-5e61db")).unwrap();+ fs::create_dir_all(root.join("alpha-aabbcc")).unwrap();+ fs::write(root.join("loose.txt"), b"not a workspace").unwrap();++ let entries = fs::read_dir(&root).unwrap();+ let mut names: Vec<String> = entries+ .flatten()+ .filter(|e| e.file_type().map(|t| t.is_dir()).unwrap_or(false))+ .filter_map(|e| e.file_name().to_str().map(|s| s.to_string()))+ .collect();+ names.sort();++ assert_eq!(names, vec!["alpha-aabbcc".to_string(), "zeta-5e61db".to_string()]);+ let _ = fs::remove_dir_all(&root);+ }++ /// Negative control: a root that does not exist is an empty list, not an+ /// error, so a fresh install never sees a failure here.+ #[test]+ fn missing_root_is_empty_not_an_error() {+ let root = std::env::temp_dir().join("lu-test-agent-workspace-absent");+ let _ = fs::remove_dir_all(&root);+ let listed: Vec<String> = match fs::read_dir(&root) {+ Ok(e) => e.flatten().filter_map(|x| x.file_name().to_str().map(|s| s.to_string())).collect(),+ Err(_) => Vec::new(),+ };+ assert!(listed.is_empty());+ }+}+#[cfg(test)]mod read_tests {use super::format_bytes;diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rsindex 4a58de05..d6bf7113 100644--- a/src-tauri/src/main.rs+++ b/src-tauri/src/main.rs@@ -207,6 +207,7 @@ fn main() {commands::agent::file_write,commands::agent::set_chat_workspace_override,commands::agent::get_chat_workspace_override,+ commands::agent::list_agent_workspaces,// Shellcommands::shell::shell_execute,// Filesystemdiff --git a/src/api/__tests__/workspace-slug.test.ts b/src/api/__tests__/workspace-slug.test.tsnew file mode 100644index 00000000..d170fdf1--- /dev/null+++ b/src/api/__tests__/workspace-slug.test.ts@@ -0,0 +1,140 @@+/**+ * Counter-check round 2, side finding 1 (installed Windows build, 2026-08-29).+ *+ * Round one of an agent run wrote `agent-workspace\new-chat-5e61db\r2a.txt`.+ * The app then auto-renamed the chat after the first user message, and round+ * two of the SAME run looked for its file in+ * `agent-workspace\create-a-file-called-r2a-txt-containing-5e61db\` and got+ * "File not found". The folder name has to hang on the conversation id, and folders+ * that older chats already own have to stay reachable.+ */+import { describe, it, expect, beforeEach, vi } from 'vitest'++const backendCall = vi.fn()+vi.mock('../backend', () => ({ backendCall: (...a: unknown[]) => backendCall(...a) }))++import {+ pickLegacyWorkspaceSlug,+ resolveChatWorkspaceSlug,+ __resetWorkspaceDirCacheForTests,+} from '../workspace-slug'+import { chatWorkspaceSlug } from '../agent-context'+import { useAgentModeStore } from '../../stores/agentModeStore'++// The conversation from the counter-check: id part 5e61db, title "New chat"+// at the time of round one, renamed by the app before round two.+const CONV = '5e61db1b-4c2a-4d5e-8f90-112233445566'+const TITLE_BEFORE = 'New chat'+const TITLE_AFTER = 'Create a file called r2a.txt containing HELLO'++beforeEach(() => {+ backendCall.mockReset()+ backendCall.mockResolvedValue([])+ __resetWorkspaceDirCacheForTests()+ useAgentModeStore.setState({ workspaceSlugs: {} })+})++describe('pickLegacyWorkspaceSlug', () => {+ it('adopts the folder carrying this conversation id suffix', () => {+ const dirs = ['default', 'some-other-chat-aabbcc', 'new-chat-5e61db']+ expect(pickLegacyWorkspaceSlug(dirs, CONV)).toBe('new-chat-5e61db')+ })++ it('adopts a bare id folder (a chat that never had a title)', () => {+ expect(pickLegacyWorkspaceSlug(['5e61db', 'other-aabbcc'], CONV)).toBe('5e61db')+ })++ it('picks deterministically when two folders share the suffix', () => {+ const dirs = ['zeta-5e61db', 'alpha-5e61db']+ expect(pickLegacyWorkspaceSlug(dirs, CONV)).toBe('alpha-5e61db')+ expect(pickLegacyWorkspaceSlug([...dirs].reverse(), CONV)).toBe('alpha-5e61db')+ })++ // NEGATIVE CONTROL: another chat's folder must never be adopted, and an+ // empty id (whose id part is the shared `noid` bucket) must not match at all+ // because that would hand one chat somebody else's files.+ it('never adopts a foreign folder or matches on an empty id', () => {+ expect(pickLegacyWorkspaceSlug(['new-chat-aabbcc', 'default'], CONV)).toBeNull()+ expect(pickLegacyWorkspaceSlug(['noid', 'x-noid'], '')).toBeNull()+ expect(pickLegacyWorkspaceSlug([], CONV)).toBeNull()+ })++ it('does not match a folder that merely contains the id part', () => {+ expect(pickLegacyWorkspaceSlug(['5e61db-leftovers', 'talk5e61db'], CONV)).toBeNull()+ })+})++describe('resolveChatWorkspaceSlug › the rename must not move the folder', () => {+ it('keeps the round-one folder after the auto-rename', async () => {+ const first = await resolveChatWorkspaceSlug(CONV, TITLE_BEFORE)+ expect(first).toBe('new-chat-5e61db')++ // Round two, same run, new title.+ const second = await resolveChatWorkspaceSlug(CONV, TITLE_AFTER)+ expect(second).toBe(first)+ })++ // NEGATIVE CONTROL: the raw title-derived slug, what the app used before+ // this fix, really does move. Without this the test above could pass on a+ // slug function that ignores the title for unrelated reasons.+ it('the raw title slug DOES drift, which is the bug being fixed', () => {+ expect(chatWorkspaceSlug(CONV, TITLE_BEFORE)).toBe('new-chat-5e61db')+ expect(chatWorkspaceSlug(CONV, TITLE_AFTER)).not.toBe('new-chat-5e61db')+ })++ it('pins per conversation, so two chats never share a folder', async () => {+ const a = await resolveChatWorkspaceSlug(CONV, 'Same title')+ const b = await resolveChatWorkspaceSlug('aabbcc11-0000-0000-0000-000000000000', 'Same title')+ expect(a).not.toBe(b)+ expect(useAgentModeStore.getState().workspaceSlugs[CONV]).toBe(a)+ })++ it('a pin already on disk from an earlier session wins over the title', async () => {+ useAgentModeStore.setState({ workspaceSlugs: { [CONV]: 'pinned-earlier-5e61db' } })+ expect(await resolveChatWorkspaceSlug(CONV, TITLE_AFTER)).toBe('pinned-earlier-5e61db')+ expect(backendCall).not.toHaveBeenCalled()+ })+})++describe('resolveChatWorkspaceSlug › existing folders stay reachable', () => {+ it('adopts an old chat folder instead of inventing a new name', async () => {+ backendCall.mockResolvedValue(['default', 'new-chat-5e61db'])+ const slug = await resolveChatWorkspaceSlug(CONV, TITLE_AFTER)+ expect(slug).toBe('new-chat-5e61db')+ expect(backendCall).toHaveBeenCalledWith('list_agent_workspaces')+ })++ it('reads the directory listing once per session, not once per turn', async () => {+ backendCall.mockResolvedValue(['zzz-aabbcc'])+ await resolveChatWorkspaceSlug(CONV, TITLE_BEFORE)+ await resolveChatWorkspaceSlug('bbccdd11-0000-0000-0000-000000000000', 'Other')+ expect(backendCall.mock.calls.filter((c) => c[0] === 'list_agent_workspaces')).toHaveLength(1)+ })++ // NEGATIVE CONTROL: no backend (browser dev, command missing) must not+ // throw and must not block the run, it just means nothing is adopted.+ it('a failing listing falls back to the computed name', async () => {+ backendCall.mockRejectedValue(new Error('Unknown backend command: list_agent_workspaces'))+ expect(await resolveChatWorkspaceSlug(CONV, TITLE_BEFORE)).toBe('new-chat-5e61db')+ })++ it('a non-array answer is treated as an empty listing', async () => {+ backendCall.mockResolvedValue(null)+ expect(await resolveChatWorkspaceSlug(CONV, TITLE_BEFORE)).toBe('new-chat-5e61db')+ })+})++describe('agentModeStore › pinWorkspaceSlug is write-once', () => {+ it('ignores a second pin for the same conversation', () => {+ useAgentModeStore.getState().pinWorkspaceSlug(CONV, 'first-5e61db')+ useAgentModeStore.getState().pinWorkspaceSlug(CONV, 'second-5e61db')+ expect(useAgentModeStore.getState().workspaceSlugs[CONV]).toBe('first-5e61db')+ })++ // NEGATIVE CONTROL: empty inputs write nothing at all.+ it('refuses an empty id or an empty slug', () => {+ useAgentModeStore.getState().pinWorkspaceSlug('', 'x')+ useAgentModeStore.getState().pinWorkspaceSlug(CONV, '')+ expect(useAgentModeStore.getState().workspaceSlugs).toEqual({})+ })+})diff --git a/src/api/agent-context.ts b/src/api/agent-context.tsindex e2b61e56..1a1327ea 100644--- a/src/api/agent-context.ts+++ b/src/api/agent-context.ts@@ -349,6 +349,17 @@ export function renderWorkspaceSection(ws: AgentWorkspace | null): string {return lines.join('\n')}+/**+ * The stable half of a workspace slug: the conversation id, hyphens removed,+ * first six characters. It is the ONLY part of a folder name that survives an+ * auto-rename, which is what makes it the key the fallback search in+ * `api/workspace-slug.ts` matches on. Empty id yields `noid`, which is a+ * shared bucket and therefore never a legitimate search key.+ */+export function workspaceIdPart(id: string): string {+ return (id || '').replace(/-/g, '').slice(0, 6) || 'noid'+}+/*** Build a human-readable workspace slug for a chat.*@@ -367,7 +378,7 @@ export function renderWorkspaceSection(ws: AgentWorkspace | null): string {* defence in depth.*/export function chatWorkspaceSlug(id: string, title?: string | null): string {- const idPart = (id || '').replace(/-/g, '').slice(0, 6) || 'noid'+ const idPart = workspaceIdPart(id)const rawTitle = (title || '').toLowerCase().trim()if (!rawTitle) return idPartconst slug = rawTitlediff --git a/src/api/workspace-slug.ts b/src/api/workspace-slug.tsnew file mode 100644index 00000000..6b579764--- /dev/null+++ b/src/api/workspace-slug.ts@@ -0,0 +1,109 @@+/**+ * The agent's workspace folder, pinned to the conversation instead of its+ * title.+ *+ * WHAT WENT WRONG (counter-check round 2 on the installed Windows build,+ * 2026-08-29). `chatWorkspaceSlug` builds `<title-kebabbed>-<id6>`, and the+ * app auto-renames a chat after the first user message. Round one of an agent+ * run wrote to `agent-workspace\new-chat-5e61db\r2a.txt`; by round two the+ * title had become the first message, so the very same run looked for its file+ * in `agent-workspace\create-a-file-called-r2a-txt-containing-5e61db\` and got+ * "File not found". The model lost everything it had written mid-task and+ * started arguing with itself about it.+ *+ * THE RULE NOW. A conversation's folder name is decided ONCE and then pinned+ * in `agentModeStore.workspaceSlugs` (persisted, so it survives a restart).+ * Every later turn reads the pin, so a rename, automatic or by hand, cannot+ * move the ground the agent is standing on.+ *+ * WHY PIN AND NOT RENAME THE FOLDER. Migrating the directory on every rename+ * would also keep the name honest, but a rename in the middle of a run pulls+ * the rug out from under open file handles and a shell working directory. The+ * folder must not move while an agent is inside it, so the name is what stays+ * put.+ *+ * EXISTING FOLDERS. Chats from before this fix have no pin. Their folder name+ * still ends in the stable `-<id6>` suffix, so before pinning anything new we+ * list `~/agent-workspace` once and adopt the folder that carries this+ * conversation's suffix. That is the fallback search; it costs one directory+ * read per app session and keeps old work reachable.+ */++import { backendCall } from './backend'+import { chatWorkspaceSlug, workspaceIdPart } from './agent-context'+import { useAgentModeStore } from '../stores/agentModeStore'++/**+ * Pick the existing workspace folder that belongs to `convId`, or null.+ *+ * A legacy name is `<title>-<id6>` and a title-less one is bare `<id6>`, so+ * the suffix is the whole test. Sorted before picking so two folders that+ * somehow share a suffix always resolve to the same one. An empty conversation+ * id is refused outright: its id part is the shared `noid` bucket, and+ * adopting a folder on that basis would hand one chat another chat's files.+ */+export function pickLegacyWorkspaceSlug(dirNames: string[], convId: string): string | null {+ if (!convId) return null+ const idPart = workspaceIdPart(convId)+ if (idPart === 'noid') return null+ const suffix = `-${idPart}`+ const hits = dirNames+ .filter((n) => typeof n === 'string' && (n === idPart || n.endsWith(suffix)))+ .sort()+ return hits[0] ?? null+}++// One directory read per app session. The listing only ever answers the+// question "does a folder for this OLD chat already exist", and a chat created+// in this session gets its pin on first use, so a stale listing cannot cost us+// anything. Parked on globalThis for the same reason agent-context.ts parks its+// state there: the bundler duplicates small modules.+const CACHE_KEY = '__lu_agent_workspace_dirs__'++function cache(): { dirs?: Promise<string[]> } {+ const g = globalThis as unknown as Record<string, { dirs?: Promise<string[]> }>+ if (!g[CACHE_KEY]) g[CACHE_KEY] = {}+ return g[CACHE_KEY]+}++/** Test-only: forget the cached directory listing. */+export function __resetWorkspaceDirCacheForTests(): void {+ delete (globalThis as unknown as Record<string, unknown>)[CACHE_KEY]+}++/**+ * Sub-folder names of `~/agent-workspace`, empty when the backend cannot+ * answer (browser/dev, command missing, unreadable folder). Never throws: a+ * failed listing only means no legacy folder is adopted.+ */+async function listWorkspaceDirs(): Promise<string[]> {+ const c = cache()+ if (!c.dirs) {+ c.dirs = backendCall<string[]>('list_agent_workspaces')+ .then((names) => (Array.isArray(names) ? names.filter((n) => typeof n === 'string') : []))+ .catch(() => [])+ }+ return c.dirs+}++/**+ * The folder name this conversation's agent tools write into.+ *+ * Pinned on first use and stable from then on. Callers are the two agent+ * entry points (useAgentChat, useCodex); everything downstream takes the+ * resolved value on the run context so one turn cannot resolve it twice and+ * disagree with itself.+ */+export async function resolveChatWorkspaceSlug(+ convId: string,+ title?: string | null,+): Promise<string> {+ const store = useAgentModeStore.getState()+ const pinned = store.workspaceSlugs?.[convId]+ if (pinned) return pinned++ const legacy = pickLegacyWorkspaceSlug(await listWorkspaceDirs(), convId)+ const slug = legacy ?? chatWorkspaceSlug(convId, title)+ useAgentModeStore.getState().pinWorkspaceSlug(convId, slug)+ return slug+}diff --git a/src/hooks/useAgentChat.ts b/src/hooks/useAgentChat.tsindex 2f758866..1aed5466 100644--- a/src/hooks/useAgentChat.ts+++ b/src/hooks/useAgentChat.ts@@ -11,7 +11,8 @@ import {import { v4 as uuid } from 'uuid'import { streamProviderTurn } from '../lib/provider-stream'import { createHermesDisplayFilter, createThinkStreamSplitter } from '../lib/hermes-stream'-import { beginAgentRun, endAgentRun, chatWorkspaceSlug, setActiveAgentModel, renderWorkspaceSection, takeChatArtifacts, type AgentRunContext } from '../api/agent-context'+import { beginAgentRun, endAgentRun, setActiveAgentModel, renderWorkspaceSection, takeChatArtifacts, type AgentRunContext } from '../api/agent-context'+import { resolveChatWorkspaceSlug } from '../api/workspace-slug'import { isOllamaLocal } from '../api/backend'import { requestGenerationCancel } from '../api/vram-handoff'import { resolveWorkspace } from '../api/agents/workspace-resolve'@@ -321,12 +322,15 @@ export function useAgentChat() {// built-in tools land in `~/agent-workspace/<slug>/`. Previously// this was the raw conversation UUID — folders were technically// isolated but the user couldn't tell which chat owned which- // workspace by looking. The slug derives from the chat title- // (which auto-rename gives a meaningful one after the first user- // message) plus a short id suffix to keep two chats with the same- // title from colliding.+ // workspace by looking.+ //+ // Resolved, not recomputed: the name is pinned to the conversation the+ // first time it is needed and frozen there. Deriving it from the title on+ // every turn meant the app's own auto-rename moved the folder mid-run and+ // the agent lost its files between round one and round two (counter-check+ // round 2, 2026-08-29). See api/workspace-slug.ts.const convForSlug = useChatStore.getState().conversations.find((c) => c.id === convId)- const slug = chatWorkspaceSlug(convId, convForSlug?.title)+ const slug = await resolveChatWorkspaceSlug(convId, convForSlug?.title)// Multi-Repo Agent (B15) + workspace unification (B17): pin the// resolved workspace so chatCtx() in builtin-tools.ts threads itdiff --git a/src/hooks/useCodex.ts b/src/hooks/useCodex.tsindex 09c821ff..d69b30cb 100644--- a/src/hooks/useCodex.ts+++ b/src/hooks/useCodex.ts@@ -17,7 +17,8 @@ import { CODEX_CONFIRM_TOOLS } from './codexShellGate'import { buildHermesToolPrompt, buildHermesToolResult, buildHermesToolCall, parseHermesToolCalls, stripToolCallTags, hasToolCallTags } from '../api/hermes-tool-calling'import { streamProviderTurn, type StreamedProviderTurn } from '../lib/provider-stream'import { createHermesDisplayFilter } from '../lib/hermes-stream'-import { beginAgentRun, endAgentRun, chatWorkspaceSlug, setActiveAgentModel, type AgentRunContext } from '../api/agent-context'+import { beginAgentRun, endAgentRun, setActiveAgentModel, type AgentRunContext } from '../api/agent-context'+import { resolveChatWorkspaceSlug } from '../api/workspace-slug'import { codexModeKnobs, CODEX_MODE_LABELS, type CodexMode } from '../lib/codex-mode'import { CODEX_PLAN_SYSTEM_PROMPT } from '../lib/codex-plan-prompt'import { resolveWorkspace } from '../api/agents/workspace-resolve'@@ -326,7 +327,13 @@ export function useCodex() {// Slug uses the chat title so the folder is recognisable in// Explorer; falls back to a stable id-derived suffix when the// title is empty. Cleared in the finally block.+ //+ // Resolved ONCE per turn and reused everywhere below. The name is pinned+ // to the conversation on first use, so the auto-rename after the first+ // message can no longer move the folder out from under a running agent+ // (counter-check round 2, 2026-08-29). See api/workspace-slug.ts.const convForSlug = store.conversations.find((c) => c.id === convId)+ const workspaceSlug = await resolveChatWorkspaceSlug(convId, convForSlug?.title)// Multi-Repo Agent (B15) + Codex/Agent workspace unification (B17):// pin the resolved workspace so the bridge resolves relative paths@@ -429,7 +436,7 @@ export function useCodex() {// ERZWINGUNG, blocker S3). The finally closes it, and closing only clears// the process-wide mirror when this run still owns it.const run: AgentRunContext = beginAgentRun({- chatId: chatWorkspaceSlug(convId, convForSlug?.title),+ chatId: workspaceSlug,conversationId: convId,workspace: runWorkspace,readOnlyShellTurn: effectiveReadOnly,@@ -1785,7 +1792,7 @@ export function useCodex() {// rendered as a 100% insert — hiding exactly the deletions/overwrites// the user needs to see before approving a staged change.const readCtx: { chatId?: string; workingDirectory?: string } =- workDir && workDir !== '.' ? { chatId: convId, workingDirectory: workDir } : { chatId: convId }+ workDir && workDir !== '.' ? { chatId: workspaceSlug, workingDirectory: workDir } : { chatId: workspaceSlug }const oldContents = new Map<string, string>()await Promise.all(batch@@ -1831,7 +1838,7 @@ export function useCodex() {? path: `${workDir.replace(/[\\/]+$/, '')}${workDir.includes('\\') ? '\\' : '/'}${path.replace(/^[\\/]+/, '')}`const stageReadCtx: { chatId?: string; workingDirectory?: string } =- workDir && workDir !== '.' ? { chatId: convId, workingDirectory: workDir } : { chatId: convId }+ workDir && workDir !== '.' ? { chatId: workspaceSlug, workingDirectory: workDir } : { chatId: workspaceSlug }// A prior staged entry for this path already knows the DISK state —// reuse it so the reviewed diff stays disk → latest even when the// model writes the same file twice in one run.@@ -1878,7 +1885,7 @@ export function useCodex() {? path: `${workDir.replace(/[\\/]+$/, '')}${workDir.includes('\\') ? '\\' : '/'}${path.replace(/^[\\/]+/, '')}`const stageReadCtx: { chatId?: string; workingDirectory?: string } =- workDir && workDir !== '.' ? { chatId: convId, workingDirectory: workDir } : { chatId: convId }+ workDir && workDir !== '.' ? { chatId: workspaceSlug, workingDirectory: workDir } : { chatId: workspaceSlug }// Read-your-writes: chain onto the STAGED content when this path is// already pending. Without this the base was re-read from DISK —// which never saw the staged write — so a second edit to the samediff --git a/src/stores/agentModeStore.ts b/src/stores/agentModeStore.tsindex f7973c3e..88fc6392 100644--- a/src/stores/agentModeStore.ts+++ b/src/stores/agentModeStore.ts@@ -13,6 +13,16 @@ interface AgentModeState {// it should pop up.workspaces: Record<string, AgentWorkspace>+ // Per-conversation agent workspace FOLDER NAME, decided once and then+ // frozen (counter-check round 2, 2026-08-29). The name used to be derived+ // from the chat title on every turn, so the app's own auto-rename moved the+ // folder out from under a running agent: round one wrote into+ // `agent-workspace/new-chat-5e61db/`, round two looked in+ // `agent-workspace/<the-new-title>-5e61db/` and found nothing. Keyed by+ // conversation id, written by resolveChatWorkspaceSlug on first use, and+ // persisted so a restart cannot re-derive a different name.+ workspaceSlugs: Record<string, string>+// Last folder the user picked from the "Use last folder" shortcut in// AgentWorkspaceDialog. Carries over across chats so the user doesn't// have to re-browse to the same repo every time. Updated by@@ -28,6 +38,7 @@ interface AgentModeState {toggleAgentMode: (conversationId: string) => voidsetAgentModeActive: (conversationId: string, active: boolean) => voidsetWorkspace: (conversationId: string, workspace: AgentWorkspace) => void+ pinWorkspaceSlug: (conversationId: string, slug: string) => voidclearWorkspace: (conversationId: string) => voidsetSandboxLevel: (level: SandboxLevel) => voidsetTutorialCompleted: () => void@@ -41,6 +52,7 @@ export const useAgentModeStore = create<AgentModeState>()((set, get) => ({agentModeActive: {},workspaces: {},+ workspaceSlugs: {},lastFolder: undefined,sandboxLevel: 'restricted',tutorialCompleted: false,@@ -77,6 +89,18 @@ export const useAgentModeStore = create<AgentModeState>()(: state.lastFolder,})),+ // Write-once on purpose: a second call for a conversation that already+ // has a folder name is ignored, so no later code path can rename the+ // ground an agent run is standing on.+ pinWorkspaceSlug: (conversationId, slug) =>+ set((state) => {+ if (!conversationId || !slug) return state+ if (state.workspaceSlugs[conversationId]) return state+ return {+ workspaceSlugs: { ...state.workspaceSlugs, [conversationId]: slug },+ }+ }),+clearWorkspace: (conversationId) =>set((state) => {const next = { ...state.workspaces }