Skip to content

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.

fix(workspace): the primary folder can be changed, swapped and removed (GH #223)

purple8770d254e534
diff --git a/src/components/chat/AgentWorkspaceDialog.tsx b/src/components/chat/AgentWorkspaceDialog.tsx
index ebbc14cc..178fb2da 100644
--- a/src/components/chat/AgentWorkspaceDialog.tsx
+++ b/src/components/chat/AgentWorkspaceDialog.tsx
@@ -162,6 +162,54 @@ export function AgentWorkspaceDialog({
})
}
+ // GH #223 (07.11.2026): wer einmal einen Ordner gewaehlt hatte, kam an den
+ // Hauptordner nicht mehr heran. Der Dialog sprang beim Wiederoeffnen in die
+ // Zusatzordner, und dort liessen sich nur Extras hinzufuegen und entfernen.
+ // Jetzt laesst sich der Hauptordner tauschen, ein Extra zum Hauptordner
+ // machen und der Hauptordner entfernen.
+ const handleChangePrimary = async () => {
+ setPicking(true)
+ setError(null)
+ try {
+ const res = await backendCall<string | null>('pick_folder', { asWorkspace: true })
+ if (!res) return
+ setDraft((d) => {
+ if (!d || d.kind !== 'folder') return d
+ const key = pathKey(res)
+ // Der neue Hauptordner stand vielleicht schon als Extra da: dann nicht doppelt.
+ return { ...d, path: res, extraPaths: (d.extraPaths ?? []).filter((p) => pathKey(p) !== key) }
+ })
+ } catch (e) {
+ setError(
+ e instanceof Error ? e.message : 'Folder picker unavailable (bridge offline?)',
+ )
+ } finally {
+ setPicking(false)
+ }
+ }
+
+ /** Tauscht: das Extra wird Hauptordner, der bisherige Hauptordner ein Extra. */
+ const handleMakePrimary = (path: string) => {
+ setDraft((d) => {
+ if (!d || d.kind !== 'folder') return d
+ const rest = (d.extraPaths ?? []).filter((p) => p !== path)
+ return { ...d, path, extraPaths: d.path ? [d.path, ...rest] : rest }
+ })
+ }
+
+ /**
+ * Gibt es Extras, rueckt das erste nach. Ohne Extras geht es zurueck zur
+ * Auswahl (Sandbox, letzter Ordner, anderer Ordner); Abbrechen laesst dann
+ * alles, wie es war.
+ */
+ const handleRemovePrimary = () => {
+ setDraft((d) => {
+ if (!d || d.kind !== 'folder') return d
+ const [next, ...rest] = d.extraPaths ?? []
+ return next ? { ...d, path: next, extraPaths: rest } : null
+ })
+ }
+
const handleSave = () => {
if (!draft) return
if (rememberAsDefault && draft.kind === 'folder' && draft.path) {
@@ -173,13 +221,13 @@ export function AgentWorkspaceDialog({
const phase: 'pick' | 'extras' = draft ? 'extras' : 'pick'
return (
- <Modal open={open} onClose={onClose} title={phase === 'pick' ? 'Where should the agent work?' : 'Add more repos?'} ariaLabel="Agent workspace">
+ <Modal open={open} onClose={onClose} title={phase === 'pick' ? 'Where should the agent work?' : 'Workspace folders'} ariaLabel="Agent workspace">
<div className="space-y-4">
<div className="space-y-1">
<p className="text-[0.7rem] text-gray-500">
{phase === 'pick'
? 'Pick a folder to edit your real files, or use a separate workspace for this chat. You can change this later.'
- : 'Primary anchors relative paths. Extras give the agent absolute access, perfect for "sync the API in repo-A with the client in repo-B".'}
+ : 'Primary anchors relative paths, change or remove it here. Extras give the agent absolute access, perfect for "sync the API in repo-A with the client in repo-B".'}
</p>
<p className="text-[0.7rem] text-gray-500" data-testid="workspace-security-boundary">
Workspace protection is a folder path jail, not a container or virtual machine.
@@ -231,13 +279,35 @@ export function AgentWorkspaceDialog({
durch die Beschriftung, nicht durch die Farbe. */}
{phase === 'extras' && draft?.kind === 'folder' && (
<div className="space-y-2" data-testid="agent-workspace-extras">
- <div className="rounded-lg border border-gray-200 dark:border-white/10 px-3 py-2">
- <div className={`text-[0.55rem] uppercase tracking-widest ${HINWEIS_TEXT.ruhig} mb-0.5`}>
- Primary
- </div>
- <div className="text-[0.7rem] font-mono text-gray-800 dark:text-gray-200 truncate">
- {draft.path}
+ <div className="flex items-center justify-between gap-2 rounded-lg border border-gray-200 dark:border-white/10 px-3 py-2" data-testid="agent-workspace-primary">
+ <div className="flex-1 min-w-0">
+ <div className={`text-[0.55rem] uppercase tracking-widest ${HINWEIS_TEXT.ruhig} mb-0.5`}>
+ Primary
+ </div>
+ <div className="text-[0.7rem] font-mono text-gray-800 dark:text-gray-200 truncate">
+ {draft.path}
+ </div>
</div>
+ <button
+ type="button"
+ onClick={handleChangePrimary}
+ disabled={picking}
+ className="shrink-0 t-micro text-gray-500 underline hover:text-gray-800 dark:hover:text-white disabled:opacity-50"
+ data-testid="agent-workspace-change-primary"
+ >
+ Change…
+ </button>
+ <button
+ type="button"
+ onClick={handleRemovePrimary}
+ disabled={picking}
+ title="Remove"
+ aria-label="Remove primary folder"
+ className="p-1 rounded hover:bg-red-500/10 text-red-500 disabled:opacity-50"
+ data-testid="agent-workspace-remove-primary"
+ >
+ <X size={11} />
+ </button>
</div>
{(draft.extraPaths ?? []).map((p) => (
@@ -248,6 +318,14 @@ export function AgentWorkspaceDialog({
<span className="text-[0.7rem] font-mono text-gray-700 dark:text-gray-300 truncate flex-1 min-w-0">
{p}
</span>
+ <button
+ type="button"
+ onClick={() => handleMakePrimary(p)}
+ className="shrink-0 t-micro text-gray-500 underline hover:text-gray-800 dark:hover:text-white"
+ data-testid="agent-workspace-make-primary"
+ >
+ Make primary
+ </button>
<button
onClick={() => handleRemoveExtra(p)}
title="Remove"
diff --git a/src/components/chat/__tests__/der-hauptordner-laesst-sich-wechseln.test.tsx b/src/components/chat/__tests__/der-hauptordner-laesst-sich-wechseln.test.tsx
new file mode 100644
index 00000000..eb7e3a2d
--- /dev/null
+++ b/src/components/chat/__tests__/der-hauptordner-laesst-sich-wechseln.test.tsx
@@ -0,0 +1,105 @@
+// @vitest-environment jsdom
+/**
+ * GH #223 (07.11.2026): "when I select a workspace folder, I can't change it".
+ * Der Ordnerdialog sprang beim Wiederoeffnen gleich zu den Zusatzordnern. Dort
+ * liessen sich Extras hinzufuegen und entfernen, der Hauptordner aber stand fest.
+ * Derselbe Dialog sitzt in Voice, in der Agent-Plakette und im Umschalter.
+ *
+ * Jetzt: Hauptordner wechseln, ein Extra zum Hauptordner machen, den
+ * Hauptordner entfernen (ein Extra rueckt nach, ohne Extras geht es zurueck
+ * zur Auswahl).
+ *
+ * Lauf: npx vitest run src/components/chat/__tests__/der-hauptordner-laesst-sich-wechseln.test.tsx
+ */
+import { beforeEach, describe, expect, it, vi } from 'vitest'
+import { cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react'
+
+vi.mock('../../../api/backend', async (orig) => ({
+ ...(await orig<Record<string, unknown>>()),
+ backendCall: vi.fn(),
+ isTauri: () => true,
+}))
+
+import { AgentWorkspaceDialog } from '../AgentWorkspaceDialog'
+import { backendCall } from '../../../api/backend'
+import { useAgentModeStore } from '../../../stores/agentModeStore'
+import type { AgentWorkspace } from '../../../types/agent-workspace'
+
+const call = vi.mocked(backendCall)
+const A = 'C:\\Users\\jade\\random'
+const B = 'D:\\code\\project'
+const C = 'D:\\code\\other'
+
+beforeEach(() => {
+ cleanup()
+ call.mockReset()
+ useAgentModeStore.setState({ lastFolder: null, workspaces: {} })
+})
+
+function openOn(initial: AgentWorkspace) {
+ const onChoose = vi.fn()
+ render(
+ <AgentWorkspaceDialog open conversationId="voice" initialWorkspace={initial} onChoose={onChoose} onClose={() => {}} />,
+ )
+ return onChoose
+}
+
+const primaryText = () => screen.getByTestId('agent-workspace-primary').textContent ?? ''
+
+describe('the primary workspace folder can be changed and removed', () => {
+ it('Change… picks a new primary and saves it', async () => {
+ call.mockResolvedValueOnce(B)
+ const onChoose = openOn({ kind: 'folder', path: A, extraPaths: [] })
+ fireEvent.click(screen.getByTestId('agent-workspace-change-primary'))
+ await waitFor(() => expect(primaryText()).toContain(B))
+ expect(call).toHaveBeenCalledWith('pick_folder', { asWorkspace: true })
+ fireEvent.click(screen.getByTestId('agent-workspace-save'))
+ expect(onChoose).toHaveBeenCalledWith({ kind: 'folder', path: B, extraPaths: [] })
+ })
+
+ it('a cancelled picker keeps the primary', async () => {
+ call.mockResolvedValueOnce(null)
+ const onChoose = openOn({ kind: 'folder', path: A, extraPaths: [B] })
+ fireEvent.click(screen.getByTestId('agent-workspace-change-primary'))
+ await waitFor(() => expect(screen.getByTestId('agent-workspace-change-primary').hasAttribute('disabled')).toBe(false))
+ fireEvent.click(screen.getByTestId('agent-workspace-save'))
+ expect(onChoose).toHaveBeenCalledWith({ kind: 'folder', path: A, extraPaths: [B] })
+ })
+
+ it('picking an extra as the new primary does not list it twice', async () => {
+ call.mockResolvedValueOnce('d:/CODE/project/')
+ const onChoose = openOn({ kind: 'folder', path: A, extraPaths: [B, C] })
+ fireEvent.click(screen.getByTestId('agent-workspace-change-primary'))
+ await waitFor(() => expect(primaryText()).toContain('d:/CODE/project/'))
+ fireEvent.click(screen.getByTestId('agent-workspace-save'))
+ expect(onChoose).toHaveBeenCalledWith({ kind: 'folder', path: 'd:/CODE/project/', extraPaths: [C] })
+ })
+
+ it('Make primary swaps an extra with the primary, and the old one can then go', () => {
+ const onChoose = openOn({ kind: 'folder', path: A, extraPaths: [B, C] })
+ fireEvent.click(screen.getAllByTestId('agent-workspace-make-primary')[0])
+ expect(primaryText()).toContain(B)
+ // The old primary is now the first extra; remove it like any extra.
+ fireEvent.click(screen.getAllByTitle('Remove').find((el) => el.getAttribute('data-testid') !== 'agent-workspace-remove-primary')!)
+ fireEvent.click(screen.getByTestId('agent-workspace-save'))
+ expect(onChoose).toHaveBeenCalledWith({ kind: 'folder', path: B, extraPaths: [C] })
+ })
+
+ it('removing the primary moves the first extra up', () => {
+ const onChoose = openOn({ kind: 'folder', path: A, extraPaths: [B, C] })
+ fireEvent.click(screen.getByTestId('agent-workspace-remove-primary'))
+ expect(primaryText()).toContain(B)
+ fireEvent.click(screen.getByTestId('agent-workspace-save'))
+ expect(onChoose).toHaveBeenCalledWith({ kind: 'folder', path: B, extraPaths: [C] })
+ })
+
+ it('removing the only folder goes back to the choices, where Sandbox clears it', () => {
+ const onChoose = openOn({ kind: 'folder', path: A, extraPaths: [] })
+ fireEvent.click(screen.getByTestId('agent-workspace-remove-primary'))
+ expect(screen.queryByTestId('agent-workspace-extras')).toBeNull()
+ expect(screen.getByTestId('agent-workspace-options')).toBeTruthy()
+ expect(onChoose).not.toHaveBeenCalled()
+ fireEvent.click(screen.getByText('Sandbox'))
+ expect(onChoose).toHaveBeenCalledWith({ kind: 'sandbox' })
+ })
+})