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(agent): Arbeitsordner sichtbar, abgelehnte Datei sagt den Ausweg

purple3fe76a7b0e48
diff --git a/src/api/agents/error-hints.ts b/src/api/agents/error-hints.ts
index 1eaee355..d67d5aab 100644
--- a/src/api/agents/error-hints.ts
+++ b/src/api/agents/error-hints.ts
@@ -17,8 +17,21 @@
* - Hints are plain text, no code fencing, no Markdown headers.
*/
+import { OUTSIDE_WORKSPACE } from '../../lib/workspace-refusal'
+
type HintRule = { pattern: RegExp; hint: string }
+/**
+ * The file tools only work inside the chat's working folder (the Sandbox or a
+ * picked folder, commands/filesystem.rs). The bare refusal left a small model
+ * with "I can't access your files" (Discord 2026-09-28, xambran). Worded for
+ * both surfaces, the Agent chat and the Code tab, and checked first.
+ */
+const OUTSIDE_WORKSPACE_HINT: HintRule = {
+ pattern: OUTSIDE_WORKSPACE,
+ hint: 'Outside this chat\'s working folder. Ask the user to choose the folder that holds it as the working folder, then try again.',
+}
+
/** Shared across any tool — checked last as a catch-all. */
const GENERIC_HINTS: HintRule[] = [
{ pattern: /ECONNREFUSED|fetch failed|network/i, hint: 'Network unreachable. Check connectivity or retry once.' },
@@ -29,27 +42,34 @@ const GENERIC_HINTS: HintRule[] = [
/** Per-tool hint rules. Order matters: first match wins within a tool. */
const TOOL_HINTS: Record<string, HintRule[]> = {
file_read: [
+ OUTSIDE_WORKSPACE_HINT,
{ pattern: /ENOENT|no such file|not found|does not exist/i, hint: 'Path not found. Use file_list first to discover existing paths.' },
- { pattern: /EACCES|EPERM|permission denied|access is denied/i, hint: 'Permission denied. Try a path inside the user home or agent workspace.' },
+ { pattern: /EACCES|EPERM|permission denied|access is denied/i, hint: 'Permission denied. Try a path inside the chat\'s working folder.' },
{ pattern: /EISDIR|is a directory/i, hint: 'Path is a directory, not a file. Use file_list on it instead.' },
{ pattern: /file too large|large file/i, hint: 'File too large to read whole. Use file_search for targeted grep instead.' },
],
file_write: [
+ OUTSIDE_WORKSPACE_HINT,
{ pattern: /EACCES|EPERM|permission denied|access is denied/i, hint: 'Permission denied. Pick a writable directory, e.g. the agent workspace.' },
{ pattern: /ENOSPC|no space left/i, hint: 'Disk full. Cannot write. Surface this to the user and stop.' },
{ pattern: /EROFS|read-only/i, hint: 'Filesystem is read-only. Choose a different path.' },
{ pattern: /ENOTDIR|not a directory/i, hint: 'Parent path exists but is not a directory. Pick a different path.' },
],
file_list: [
+ OUTSIDE_WORKSPACE_HINT,
{ pattern: /ENOENT|no such file|not found/i, hint: 'Directory does not exist. Check the parent with file_list.' },
{ pattern: /ENOTDIR|not a directory/i, hint: 'Path is a file, not a directory. Use file_read instead.' },
- { pattern: /EACCES|EPERM|permission denied/i, hint: 'Permission denied to list. Try a path inside your home or workspace.' },
+ { pattern: /EACCES|EPERM|permission denied/i, hint: 'Permission denied to list. Try a path inside the chat\'s working folder.' },
],
file_search: [
+ OUTSIDE_WORKSPACE_HINT,
{ pattern: /ENOENT|no such file|not found/i, hint: 'Search root does not exist. Check the path with file_list.' },
{ pattern: /invalid regex|parse error|unmatched/i, hint: 'Regex pattern is invalid. Escape special characters or simplify.' },
{ pattern: /max results|too many matches/i, hint: 'Too many matches. Narrow the pattern or search a subtree.' },
],
+ file_edit: [
+ OUTSIDE_WORKSPACE_HINT,
+ ],
shell_execute: [
{ pattern: /not recognized|command not found|No such file or directory/i, hint: 'Command is not installed or not on PATH. Try a different tool or surface this to the user.' },
{ pattern: /timed out/i, hint: 'Command timed out. Either break into smaller steps or raise the timeout.' },
diff --git a/src/components/chat/AgentWorkspaceBadge.tsx b/src/components/chat/AgentWorkspaceBadge.tsx
index 3ecdd1df..e0aa5721 100644
--- a/src/components/chat/AgentWorkspaceBadge.tsx
+++ b/src/components/chat/AgentWorkspaceBadge.tsx
@@ -3,6 +3,7 @@ import { Folder, Shield, X } from 'lucide-react'
import { useAgentModeStore } from '../../stores/agentModeStore'
import { useChatStore } from '../../stores/chatStore'
import { useSettingsStore } from '../../stores/settingsStore'
+import { useChatNoticeStore } from '../../stores/chatNoticeStore'
import { AgentWorkspaceDialog } from './AgentWorkspaceDialog'
import type { AgentWorkspace } from '../../types/agent-workspace'
@@ -11,8 +12,9 @@ import type { AgentWorkspace } from '../../types/agent-workspace'
* operates: "Sandbox" or the basename of the picked folder. Click to
* change — re-opens AgentWorkspaceDialog so the user can swap mid-chat.
*
- * Renders nothing unless agent mode is enabled for the active chat AND
- * a workspace has been chosen. The initial-choice flow is owned by
+ * Renders whenever agent mode is enabled for the active chat, and shows the
+ * place the run really works in: the chat's own pick, else the remembered
+ * default, else "Sandbox". The initial-choice flow is owned by
* AgentModeToggle.
*/
export function AgentWorkspaceBadge() {
@@ -35,6 +37,8 @@ export function AgentWorkspaceBadge() {
const handleChoose = (next: AgentWorkspace) => {
useAgentModeStore.getState().setWorkspace(activeId, next)
+ // The line about a refused file has done its job once a folder is chosen.
+ useChatNoticeStore.getState().dismiss('agent-outside-workspace')
setDialogOpen(false)
setLeftInto(null)
}
@@ -70,18 +74,27 @@ export function AgentWorkspaceBadge() {
)
}
- if (!isActive || !workspace) return null
+ if (!isActive) return null
- const extras = workspace.kind === 'folder' ? workspace.extraPaths ?? [] : []
+ // Discord 28.09.2026 (xambran: alles auf Auto und trotzdem kein Zugriff auf
+ // die eigenen Dateien). Wer den Ordnerdialog wegklickte oder den Ordner mit
+ // dem x verliess, arbeitete still in der Sandbox des Chats, und die Plakette
+ // verschwand: nichts zeigte, wo der Agent arbeitet, und es gab keinen Klick,
+ // der das aendert. Sie zeigt jetzt den Ort, an dem der Lauf wirklich
+ // arbeitet, in derselben Reihenfolge wie resolveWorkspace in useAgentChat
+ // (dieser Chat, dann der Vorgabeordner, sonst die Sandbox), und ein Klick
+ // oeffnet den Dialog mit "Pick a folder…".
+ const shown: AgentWorkspace = workspace ?? defaultWorkspace ?? { kind: 'sandbox' }
+ const extras = shown.kind === 'folder' ? shown.extraPaths ?? [] : []
const label =
- workspace.kind === 'folder'
+ shown.kind === 'folder'
? extras.length > 0
- ? `${basename(workspace.path)} +${extras.length}`
- : basename(workspace.path)
+ ? `${basename(shown.path)} +${extras.length}`
+ : basename(shown.path)
: 'Sandbox'
- const Icon = workspace.kind === 'folder' ? Folder : Shield
+ const Icon = shown.kind === 'folder' ? Folder : Shield
const tone =
- workspace.kind === 'folder'
+ shown.kind === 'folder'
// Picked folder = neutral / no colour (David 2026-06-06). The amber read
// as an alert. Text + Folder icon inherit this gray. Sandbox stays green.
? 'text-gray-500 dark:text-gray-400 border-gray-200 dark:border-white/10'
@@ -92,25 +105,31 @@ export function AgentWorkspaceBadge() {
<span className={`flex items-center rounded border transition-colors text-[0.55rem] ${tone}`}>
<button
onClick={() => setDialogOpen(true)}
+ data-testid="agent-workspace-pill"
title={
- workspace.kind === 'folder'
- ? `Agent working in ${workspace.path}. Click to change.`
- : 'Agent working in a separate folder with a file tool path jail, not a container. Click to change.'
+ shown.kind === 'folder'
+ ? `Agent working in ${shown.path}. Click to change.`
+ : 'Agent working in its own sandbox folder, not in your files. Click to pick a folder.'
}
className="flex items-center gap-1 px-1.5 py-0.5 bg-transparent hover:bg-white/5"
>
<Icon size={10} />
<span className="font-mono max-w-[120px] truncate">{label}</span>
</button>
- <button
- onClick={handleLeave}
- title="Leave this workspace. The agent asks again before it works anywhere."
- aria-label="Leave this workspace"
- data-testid="agent-workspace-leave"
- className="px-1 py-0.5 bg-transparent hover:bg-white/5"
- >
- <X size={9} />
- </button>
+ {/* Verlassen gibt es nur fuer einen Ordner, den dieser Chat selbst
+ gewaehlt hat: die Sandbox ist schon der Ausgangszustand, und den
+ Vorgabeordner vergisst der Dialog ("Forget it"). */}
+ {workspace && (
+ <button
+ onClick={handleLeave}
+ title="Leave this folder. The agent then works in its sandbox until you pick one."
+ aria-label="Leave this workspace"
+ data-testid="agent-workspace-leave"
+ className="px-1 py-0.5 bg-transparent hover:bg-white/5"
+ >
+ <X size={9} />
+ </button>
+ )}
</span>
{dialogOpen && (
diff --git a/src/components/chat/ChatNotices.tsx b/src/components/chat/ChatNotices.tsx
index be113b99..921efd95 100644
--- a/src/components/chat/ChatNotices.tsx
+++ b/src/components/chat/ChatNotices.tsx
@@ -11,7 +11,7 @@
* fuer Anmerkungen und Fehler vorschreibt: eine Zeile, kein Kasten, ruhiges
* Grau oder Rot, und ein x, das sie wegnimmt.
*/
-import { ImageOff, Images, Paperclip } from 'lucide-react'
+import { FolderOpen, ImageOff, Images, Paperclip } from 'lucide-react'
import { Hinweis } from '../ui/Hinweis'
import { useChatNoticeStore, type ChatNoticeId } from '../../stores/chatNoticeStore'
import { COMPOSER_MAX_W } from './composer-width'
@@ -21,6 +21,7 @@ const ICON: Record<ChatNoticeId, typeof Paperclip> = {
'attachment-is-not-an-image': Paperclip,
'model-cannot-see-images': ImageOff,
'image-attach': Images,
+ 'agent-outside-workspace': FolderOpen,
}
interface Props {
diff --git a/src/components/chat/__tests__/agent-workspace-sichtbar.test.tsx b/src/components/chat/__tests__/agent-workspace-sichtbar.test.tsx
new file mode 100644
index 00000000..1e605819
--- /dev/null
+++ b/src/components/chat/__tests__/agent-workspace-sichtbar.test.tsx
@@ -0,0 +1,74 @@
+// @vitest-environment jsdom
+/**
+ * Discord 28.09.2026, xambran: "I still can't get my models to access my
+ * files", mit jeder Agent-Berechtigung auf Auto. Wer den Ordnerdialog
+ * wegklickte, arbeitete still in der Sandbox des Chats, und die Plakette neben
+ * dem Agent-Schalter verschwand: kein Hinweis, wo der Agent arbeitet, und kein
+ * Klick, der das aendert. Die Plakette zeigt jetzt immer den Ort, an dem der
+ * Lauf wirklich arbeitet, und ein Klick fuehrt zu "Pick a folder…".
+ */
+import { beforeEach, describe, expect, it } from 'vitest'
+import { cleanup, fireEvent, render, screen, within } from '@testing-library/react'
+import { AgentWorkspaceBadge } from '../AgentWorkspaceBadge'
+import { useAgentModeStore } from '../../../stores/agentModeStore'
+import { useChatStore } from '../../../stores/chatStore'
+import { useSettingsStore } from '../../../stores/settingsStore'
+import { useChatNoticeStore } from '../../../stores/chatNoticeStore'
+import { OUTSIDE_WORKSPACE_NOTICE } from '../../../lib/workspace-refusal'
+
+const CONV = 'conv-x'
+
+beforeEach(() => {
+ cleanup()
+ useChatStore.setState({ activeConversationId: CONV })
+ useAgentModeStore.setState({ agentModeActive: { [CONV]: true }, workspaces: {} })
+ useSettingsStore.getState().updateSettings({ defaultWorkspace: null })
+ useChatNoticeStore.getState().clear()
+})
+
+describe('the pill shows where the agent really works', () => {
+ it('nothing chosen: it says Sandbox, and a click opens the folder choice', () => {
+ render(<AgentWorkspaceBadge />)
+ const pill = screen.getByTestId('agent-workspace-pill')
+ expect(pill.textContent).toContain('Sandbox')
+ // Nothing of this chat's own to leave, so no x.
+ expect(screen.queryByTestId('agent-workspace-leave')).toBeNull()
+ fireEvent.click(pill)
+ const options = screen.getByTestId('agent-workspace-options')
+ expect(within(options).getByText('Pick a folder…')).toBeTruthy()
+ })
+
+ it('a remembered default folder is what the run uses, so that is what it shows', () => {
+ useSettingsStore.getState().updateSettings({ defaultWorkspace: { kind: 'folder', path: 'C:\\Users\\x\\Documents\\notes' } })
+ render(<AgentWorkspaceBadge />)
+ expect(screen.getByTestId('agent-workspace-pill').textContent).toContain('notes')
+ })
+
+ it('agent mode off: no pill at all', () => {
+ useAgentModeStore.setState({ agentModeActive: { [CONV]: false }, workspaces: {} })
+ render(<AgentWorkspaceBadge />)
+ expect(screen.queryByTestId('agent-workspace-pill')).toBeNull()
+ })
+
+ it('choosing a place clears the line about the refused file', () => {
+ useChatNoticeStore.getState().show('agent-outside-workspace', OUTSIDE_WORKSPACE_NOTICE)
+ render(<AgentWorkspaceBadge />)
+ fireEvent.click(screen.getByTestId('agent-workspace-pill'))
+ fireEvent.click(within(screen.getByTestId('agent-workspace-options')).getByText('Sandbox'))
+ expect(useAgentModeStore.getState().workspaces[CONV]).toEqual({ kind: 'sandbox' })
+ expect(useChatNoticeStore.getState().notices.map((n) => n.id)).not.toContain('agent-outside-workspace')
+ })
+})
+
+describe('the refusal reaches the user whatever the model says', () => {
+ it('the agent chat raises the line from the applied call, file_edit included', async () => {
+ const { readFileSync } = await import('node:fs')
+ const { join } = await import('node:path')
+ const src = readFileSync(join(__dirname, '..', '..', '..', 'hooks', 'useAgentChat.ts'), 'utf8')
+ expect(src).toContain("isOutsideWorkspaceRefusal(entry.ac.toolName, entry.ac.error)")
+ expect(src).toContain("show('agent-outside-workspace', OUTSIDE_WORKSPACE_NOTICE)")
+ // After applyResultToToolCall, which is what turns file_edit's text into a failure.
+ expect(src.indexOf("isOutsideWorkspaceRefusal(entry.ac.toolName"))
+ .toBeGreaterThan(src.indexOf('applyResultToToolCall(entry.ac, result)'))
+ })
+})
diff --git a/src/components/settings/PermissionSettings.tsx b/src/components/settings/PermissionSettings.tsx
index b0f278a5..04902f3e 100644
--- a/src/components/settings/PermissionSettings.tsx
+++ b/src/components/settings/PermissionSettings.tsx
@@ -24,7 +24,11 @@ const CATEGORIES: {
}[] = [
{ key: 'web', label: 'Web Access', description: 'Search & fetch web pages', icon: Globe, risk: 'low' },
{ key: 'system', label: 'System Info', description: 'OS info, process list', icon: Cpu, risk: 'low' },
- { key: 'filesystem', label: 'Filesystem', description: 'Read, write, search files anywhere', icon: FolderOpen, risk: 'medium' },
+ // "anywhere" stimmte nie: die Dateiwerkzeuge bleiben im Arbeitsordner des
+ // Chats, der Sandbox oder dem Ordner aus dem Dialog (resolve_path in
+ // commands/filesystem.rs). Discord 28.09.2026, xambran: alles auf Auto und
+ // trotzdem kein Zugriff auf die eigenen Dateien.
+ { key: 'filesystem', label: 'Filesystem', description: "Read, write, search files in the chat's working folder", icon: FolderOpen, risk: 'medium' },
{ key: 'image', label: 'Image Generation', description: 'Generate images', icon: Image, risk: 'medium' },
{ key: 'video', label: 'Video Generation', description: 'Generate video', icon: Film, risk: 'medium' },
{ key: 'workflow', label: 'Workflows', description: 'Execute saved agent workflows', icon: GitBranch, risk: 'medium' },
diff --git a/src/hooks/useAgentChat.ts b/src/hooks/useAgentChat.ts
index b61902de..e8df8068 100644
--- a/src/hooks/useAgentChat.ts
+++ b/src/hooks/useAgentChat.ts
@@ -91,6 +91,8 @@ import { executeParallel, applyResultToToolCall, type ExecutionRequest } from '.
import { useToolAuditStore } from '../stores/toolAuditStore'
import { makeInTurnCacheLookup } from '../api/agents/in-turn-cache'
import { explainError as explainToolError } from '../api/agents/error-hints'
+import { isOutsideWorkspaceRefusal, OUTSIDE_WORKSPACE_NOTICE } from '../lib/workspace-refusal'
+import { useChatNoticeStore } from '../stores/chatNoticeStore'
import { settleThinking } from '../lib/thinking-stripper'
import { openPlanGap, planReconcileSteer, PLAN_RECONCILE_BUDGET } from '../lib/plan-reconcile'
import { PlanStaleness, planStalenessSteer } from '../lib/plan-staleness'
@@ -2493,6 +2495,15 @@ export function useAgentChat() {
const result = results.find((r) => r.id === entry.ac.id)
if (!result) continue
applyResultToToolCall(entry.ac, result)
+ // Discord 2026-09-28 (xambran): a file outside the chat's folder was
+ // refused in a collapsed tool block, and the model alone was left to
+ // explain it. The user gets the way out above the chat, whatever the
+ // model makes of the refusal (lib/workspace-refusal.ts).
+ // Read off the applied call: file_edit returns its refusal as text,
+ // and only applyResultToToolCall turns that into a failure.
+ if (entry.ac.status === 'failed' && isOutsideWorkspaceRefusal(entry.ac.toolName, entry.ac.error)) {
+ useChatNoticeStore.getState().show('agent-outside-workspace', OUTSIDE_WORKSPACE_NOTICE)
+ }
// Over-loop accounting (David 2026-06-04): remember every executed call
// (so an identical repeat is skipped) and count successful media gens
// against the per-turn cap that stops "13× the same cat".
diff --git a/src/lib/__tests__/workspace-refusal.test.ts b/src/lib/__tests__/workspace-refusal.test.ts
new file mode 100644
index 00000000..20573eaf
--- /dev/null
+++ b/src/lib/__tests__/workspace-refusal.test.ts
@@ -0,0 +1,70 @@
+/**
+ * Discord 2026-09-28 (xambran): every agent permission on Auto, and the model
+ * still could not open the user's files. The file tools only work inside the
+ * chat's working folder; the refusal for anything else is recognised here, so
+ * the user gets the way out above the chat and the model a hint it can pass on.
+ */
+import { readFileSync } from 'node:fs'
+import { join } from 'node:path'
+import { describe, expect, it } from 'vitest'
+import { isOutsideWorkspaceRefusal, OUTSIDE_WORKSPACE_NOTICE } from '../workspace-refusal'
+import { explainError } from '../../api/agents/error-hints'
+
+const root = join(__dirname, '..', '..', '..')
+const read = (p: string) => readFileSync(join(root, p), 'utf8')
+
+// The two refusals as the jail words them (commands/filesystem.rs).
+const ESCAPE = 'Path escapes the allowed workspace.\n workspace root: C:\\Users\\x\\agent-workspace\\chat\n requested path: C:\\Users\\x\\Documents\\report.txt'
+const NOT_A_ROOT = 'Not an allowed workspace folder (a home or mount container is not a workspace): C:\\Users\\x'
+
+describe('the refusal is recognised', () => {
+ it('in the wording the Rust jail and its dev-server mirror really use', () => {
+ for (const file of ['src-tauri/src/commands/filesystem.rs', 'src/lib/dev-fs-jail.ts']) {
+ const src = read(file)
+ expect(src, file).toContain('Path escapes the allowed workspace.')
+ expect(src, file).toContain('Not an allowed workspace folder (')
+ }
+ })
+
+ it.each(['file_read', 'file_write', 'file_edit', 'file_list', 'file_search'])('for %s', (tool) => {
+ expect(isOutsideWorkspaceRefusal(tool, ESCAPE)).toBe(true)
+ expect(isOutsideWorkspaceRefusal(tool, NOT_A_ROOT)).toBe(true)
+ // file_edit hands its refusal back as text, and the call's error is the first line.
+ expect(isOutsideWorkspaceRefusal(tool, `Error: file_edit could not read C:\\x.txt: ${ESCAPE.split('\n')[0]}`)).toBe(true)
+ })
+
+ it('and nothing else', () => {
+ expect(isOutsideWorkspaceRefusal('file_read', 'File not found: C:\\x.txt')).toBe(false)
+ expect(isOutsideWorkspaceRefusal('file_read', undefined)).toBe(false)
+ expect(isOutsideWorkspaceRefusal('shell_execute', ESCAPE)).toBe(false)
+ expect(isOutsideWorkspaceRefusal('web_fetch', ESCAPE)).toBe(false)
+ })
+})
+
+describe('what the user is told', () => {
+ it('names the buttons that exist, in their own words', () => {
+ expect(read('src/components/chat/AgentWorkspaceDialog.tsx')).toContain("'Pick a folder…'")
+ expect(read('src/components/chat/AgentWorkspaceBadge.tsx')).toContain(": 'Sandbox'")
+ expect(read('src/components/chat/AgentModeToggle.tsx')).toContain('<span>Agent</span>')
+ expect(OUTSIDE_WORKSPACE_NOTICE).toContain('"Pick a folder…"')
+ expect(OUTSIDE_WORKSPACE_NOTICE).toContain('Sandbox')
+ expect(OUTSIDE_WORKSPACE_NOTICE).toContain('next to Agent')
+ })
+
+ it('carries no dash the house style forbids', () => {
+ expect(OUTSIDE_WORKSPACE_NOTICE).not.toMatch(/[\u2013\u2014]/)
+ })
+})
+
+describe('what the model is told', () => {
+ it.each(['file_read', 'file_write', 'file_edit', 'file_list', 'file_search'])('%s gets the working-folder hint first', (tool) => {
+ expect(explainError(tool, ESCAPE)).toMatch(/working folder/)
+ expect(explainError(tool, NOT_A_ROOT)).toMatch(/working folder/)
+ })
+
+ it('never sends the model to the user home, which the jail refuses', () => {
+ for (const tool of ['file_read', 'file_list']) {
+ expect(explainError(tool, 'EACCES: permission denied')).not.toMatch(/home/i)
+ }
+ })
+})
diff --git a/src/lib/workspace-refusal.ts b/src/lib/workspace-refusal.ts
new file mode 100644
index 00000000..14bdf621
--- /dev/null
+++ b/src/lib/workspace-refusal.ts
@@ -0,0 +1,29 @@
+// ─── A file the agent may not open, and what the user can do about it ───
+//
+// Discord 2026-09-28 (xambran: "I've tried configuring this every possible
+// way, but I still can't get my models to access my files"). Every agent
+// permission stood on Auto, and it did not help: the file tools only ever work
+// inside the chat's working folder, the Sandbox or a folder picked in LU's
+// dialog, and the refusal for anything else reached the user as a grey line
+// inside a collapsed tool block. The model got the raw sentence without a
+// hint, and a small one answered "I can't access your files".
+//
+// The refusal comes from the folder jail in commands/filesystem.rs
+// (`contain_within`, `check_workspace_root`), mirrored for the dev server in
+// lib/dev-fs-jail.ts. Its wording is pinned there; this only recognises it.
+
+/** Both jail refusals: a path that leaves the working folder, and a working
+ * folder the jail does not accept at all. */
+export const OUTSIDE_WORKSPACE = /escapes the allowed workspace|Not an allowed workspace folder/i
+
+/** The tools that go through the jail. */
+const FILE_TOOLS = new Set(['file_read', 'file_write', 'file_edit', 'file_list', 'file_search'])
+
+/** Did a file tool fail because the path is outside the chat's folder? */
+export function isOutsideWorkspaceRefusal(toolName: string, error: string | null | undefined): boolean {
+ return FILE_TOOLS.has(toolName) && !!error && OUTSIDE_WORKSPACE.test(error)
+}
+
+/** The line above the chat, in the words of the buttons the user sees. */
+export const OUTSIDE_WORKSPACE_NOTICE =
+ 'The agent can only open files in this chat\'s folder. To let it use yours, click the Sandbox or folder button next to Agent, choose "Pick a folder…" and select the folder that holds them, then ask again.'
diff --git a/src/stores/chatNoticeStore.ts b/src/stores/chatNoticeStore.ts
index c36fe4f2..3262eed4 100644
--- a/src/stores/chatNoticeStore.ts
+++ b/src/stores/chatNoticeStore.ts
@@ -33,7 +33,7 @@ import type { HinweisTon } from '../lib/hinweis'
/** Die Zeilen, die es gibt. Kein freier Schluessel: eine Aufzaehlung laesst
* sich nachzaehlen, ein String-Schluessel waechst unbemerkt. */
-export type ChatNoticeId = 'attachment-is-not-an-image' | 'model-cannot-see-images' | 'image-attach'
+export type ChatNoticeId = 'attachment-is-not-an-image' | 'model-cannot-see-images' | 'image-attach' | 'agent-outside-workspace'
export interface ChatNotice {
id: ChatNoticeId