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 picture this chat made is found by its path on disk too (D5)

purple0fe0193e2a75
diff --git a/src/lib/__tests__/chat-picture-by-its-path.test.ts b/src/lib/__tests__/chat-picture-by-its-path.test.ts
new file mode 100644
index 00000000..4b144cf5
--- /dev/null
+++ b/src/lib/__tests__/chat-picture-by-its-path.test.ts
@@ -0,0 +1,42 @@
+/**
+ * D5 (Discord 07.11.2026): an agent in its sandbox saw the picture it had made
+ * in the chat, found the file on disk and passed its full path as inputImage.
+ * Every path was refused ("ComfyUI cannot read it from disk"), so the picture
+ * could not be used again; only a folder workspace on ComfyUI's output got
+ * around it. A path whose file is a picture of this chat is now that result.
+ *
+ * Run: npx vitest run src/lib/__tests__/chat-picture-by-its-path.test.ts
+ */
+import { describe, expect, it } from 'vitest'
+import { resolveChatInputRef } from '../chat-media-refs'
+
+const call = (toolName: string, result: string) => ({
+ role: 'assistant',
+ agentBlocks: [{ id: 'b', phase: 'tool_call' as const, content: '', timestamp: 1, toolCalls: [{ id: 'x', toolName, args: {}, status: 'completed' as const, timestamp: 1, result }] }],
+})
+const VIEW = 'http://127.0.0.1:8188/view?filename=ComfyUI_00012_.png&subfolder=&type=output'
+const pic = call('image_generate', `Image generated: ComfyUI_00012_.png (prompt: "a red fox")\n${VIEW}`)
+const clip = call('video_generate', 'Video generated: LU_00003_.webp (prompt: "b")\nhttp://127.0.0.1:8188/view?filename=LU_00003_.webp&subfolder=&type=output')
+
+describe('D5: the picture this chat made, passed by its path on disk', () => {
+ for (const path of [
+ 'C:\\Users\\a\\ComfyUI\\output\\ComfyUI_00012_.png',
+ 'C:/Users/a/ComfyUI/output/ComfyUI_00012_.png',
+ '/home/a/ComfyUI/output/ComfyUI_00012_.png',
+ 'file:///C:/Users/a/ComfyUI/output/ComfyUI_00012_.png',
+ 'file:///Users/a/Library/Application%20Support/lu/output/comfyui_00012_.PNG',
+ ]) {
+ it(`"${path}" is the result of this chat, read by its own address`, () => {
+ expect(resolveChatInputRef(path, [pic])).toEqual({ kind: 'result', media: { kind: 'image', name: 'ComfyUI_00012_.png', url: VIEW } })
+ })
+ }
+
+ it('a clip of this chat by its path is still refused as a clip', () => {
+ expect(resolveChatInputRef('C:\\ComfyUI\\output\\LU_00003_.webp', [clip])).toMatchObject({ kind: 'error', error: expect.stringMatching(/video clip/) })
+ })
+
+ it('a path to any other file is still a path, and so still refused by the tool', () => {
+ expect(resolveChatInputRef('C:\\Users\\a\\Pictures\\holiday.png', [pic])).toEqual({ kind: 'path', path: 'C:\\Users\\a\\Pictures\\holiday.png' })
+ expect(resolveChatInputRef('/etc/passwd', [pic])).toEqual({ kind: 'path', path: '/etc/passwd' })
+ })
+})
diff --git a/src/lib/chat-media-refs.ts b/src/lib/chat-media-refs.ts
index 0ba55c83..387dcbf2 100644
--- a/src/lib/chat-media-refs.ts
+++ b/src/lib/chat-media-refs.ts
@@ -129,18 +129,20 @@ export function resolveChatInputRef(ref: string, messages: readonly ChatMessageL
if (picked) return { kind: 'attachment', entry: picked.entry }
if (/^file:\/\//i.test(raw)) {
+ let path: string
try {
- return { kind: 'path', path: decodeURI(raw.replace(/^file:\/\//i, '')) }
+ path = decodeURI(raw.replace(/^file:\/\//i, ''))
} catch {
return { kind: 'error', error: `inputImage "${raw}" is not a readable file address.` }
}
+ return ownResultAt(path, results) ?? { kind: 'path', path }
}
// An address this chat produced is matched to its result, so a clip is
// known as one even where its file name ends in .webp.
const sameUrl = results.slice().reverse().find((r) => r.url === raw)
if (sameUrl) return sameUrl.kind === 'video' ? { kind: 'error', error: clipError(sameUrl.name) } : { kind: 'result', media: sameUrl }
if (/^(?:https?:\/\/|\/(?:comfyui\/)?view\?)/i.test(raw)) return { kind: 'url', url: raw }
- if (/^(?:\/|[a-z]:[\\/])/i.test(raw) && /[\\/]/.test(raw.slice(1))) return { kind: 'path', path: raw }
+ if (/^(?:\/|[a-z]:[\\/])/i.test(raw) && /[\\/]/.test(raw.slice(1))) return ownResultAt(raw, results) ?? { kind: 'path', path: raw }
const base = raw.replace(/^.*[\\/]/, '')
if (!base) return { kind: 'error', error: `inputImage is empty. ${chatChoicesLine(attachments, results)}` }
@@ -152,6 +154,24 @@ export function resolveChatInputRef(ref: string, messages: readonly ChatMessageL
return { kind: 'unknown', name: base }
}
+/**
+ * D5 (Discord 07.11.2026): a path on disk whose file is a picture this chat
+ * made is that result. An agent in its sandbox saw the picture in the chat,
+ * found the file on disk (file_list, a folder workspace, the address in the
+ * result) and passed the full path; the tool refused every path as "ComfyUI
+ * cannot read it from disk", so the picture it had just made could not be
+ * used again. The result's own address is what ComfyUI and the Mac read.
+ * A path to anything else is still refused, so no file of the computer goes
+ * into a render by this route.
+ */
+function ownResultAt(path: string, results: readonly ChatResultMedia[]): ChatInputRef | null {
+ const base = path.replace(/^.*[\\/]/, '').toLowerCase()
+ if (!base) return null
+ const hit = results.slice().reverse().find((r) => r.name.toLowerCase() === base)
+ if (!hit) return null
+ return hit.kind === 'video' ? { kind: 'error', error: clipError(hit.name) } : { kind: 'result', media: hit }
+}
+
/** A "could not find input image" from ComfyUI's folders, with the pictures
* this chat has, so the model can retry with one that is there. */
export function withChatChoices(result: string, messages: readonly ChatMessageLike[]): string {