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): a new file outside the folder is written inside it

purpledf3f75a0ef1b
diff --git a/src/api/agents/error-hints.ts b/src/api/agents/error-hints.ts
index d67d5aab..40a8ad66 100644
--- a/src/api/agents/error-hints.ts
+++ b/src/api/agents/error-hints.ts
@@ -32,6 +32,16 @@ const OUTSIDE_WORKSPACE_HINT: HintRule = {
hint: 'Outside this chat\'s working folder. Ask the user to choose the folder that holds it as the working folder, then try again.',
}
+/**
+ * A NEW file has no reason to live outside the folder. Asked to write
+ * C:\Users\Public\Desktop\poem.txt, Mistral asked the user for another path
+ * and wrote nothing (3.0.4 box run). The customer wanted the poem.
+ */
+const OUTSIDE_WORKSPACE_WRITE_HINT: HintRule = {
+ pattern: /escapes the allowed workspace/i,
+ hint: 'Outside this chat\'s working folder. Write the file inside it instead, same name as a relative path (e.g. poem.txt), and tell the user.',
+}
+
/** 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.' },
@@ -49,6 +59,7 @@ const TOOL_HINTS: Record<string, HintRule[]> = {
{ 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_WRITE_HINT,
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.' },
diff --git a/src/lib/__tests__/workspace-refusal.test.ts b/src/lib/__tests__/workspace-refusal.test.ts
index 20573eaf..05aa540c 100644
--- a/src/lib/__tests__/workspace-refusal.test.ts
+++ b/src/lib/__tests__/workspace-refusal.test.ts
@@ -62,6 +62,14 @@ describe('what the model is told', () => {
expect(explainError(tool, NOT_A_ROOT)).toMatch(/working folder/)
})
+ it('a NEW file outside the folder: write it inside instead of asking for a path (3.0.4 box run)', () => {
+ expect(explainError('file_write', ESCAPE)).toMatch(/Write the file inside it instead/)
+ // NEGATIVE CONTROL: a refused working folder is not fixed by writing inside it,
+ // and a read of a file that lives elsewhere still needs the user's folder.
+ expect(explainError('file_write', NOT_A_ROOT)).not.toMatch(/Write the file inside it instead/)
+ expect(explainError('file_read', ESCAPE)).not.toMatch(/Write the file inside it instead/)
+ })
+
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
index 2404176a..2f15e1ef 100644
--- a/src/lib/workspace-refusal.ts
+++ b/src/lib/workspace-refusal.ts
@@ -37,4 +37,4 @@ export function hasUnrecoveredOutsideRefusal(
/** 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.'
+ 'The agent can only work with files in this chat\'s folder. To let it use another place, click the Sandbox or folder button next to Agent, choose "Pick a folder…" and select that folder, then ask again.'