Skip to content

acp: local resource links with file:/ URI are treated as text #60298

Done

Description

@HeZ2z

Description

An ACP resource_link for a local file is treated differently depending on the valid spelling of its file URI. file:/tmp/a.txt and file:///tmp/a.txt resolve to the same local file, but the former becomes a text link instead of a file attachment. The prompt preparation path therefore leaves it out of the attachment list; the model receives a reference rather than the requested file contents.

Reproduction

From packages/cli on dev commit 82666b6612cdb2ba13a7a26e150b21e897a80373:

bun -e 'import { promptContentToParts } from "./src/acp/content.ts"; import { fileURLToPath } from "node:url"; for (const uri of ["file:/tmp/a.txt", "file:///tmp/a.txt"]) console.log(uri, fileURLToPath(uri), JSON.stringify(promptContentToParts([{type:"resource_link",uri,name:"a.txt",mimeType:"text/plain"}])));'

Actual:

file:/tmp/a.txt /tmp/a.txt [{"type":"text","text":"[a.txt](file:/tmp/a.txt)"}]
file:///tmp/a.txt /tmp/a.txt [{"type":"file","url":"file:///tmp/a.txt","filename":"a.txt","mime":"text/plain"}]

Expected: both local file URIs are treated as the same attachment. resourceLinkToPart checks a literal file:// prefix rather than the parsed URI protocol; prepare collects only file parts as attachments. The reproduction exercises the actual content converter, not a full ACP client; I have not established which clients emit the single-slash spelling. The affected source matches the current upstream dev blob.

Activity

  1. opencodejr commented on Oct 29, 2026

    @opencodejr
    Contributor

    Thanks for the clear report. I can confirm this on the latest dev (d3ad3da); the ACP content code hasn't changed since the commit you tested.

    The script below calls promptContentToParts with a resource_link (name: "a.txt", mimeType: "text/plain") under three URI spellings. All three resolve to /tmp/a.txt:

    URI Result
    file:/tmp/a.txt text link [a.txt](file:/tmp/a.txt)
    file:///tmp/a.txt file attachment
    file://localhost/tmp/a.txt file attachment

    As you found, resourceLinkToPart checks for the literal file:// prefix, and prepare only collects file parts as attachments. So the single-slash form reaches the model as a reference, not as the file. I've passed this to the maintainers.

    Reproduction script (repro.ts)
    // Run from packages/cli of an opencode checkout: bun /workspace/repro/repro.ts [/path/to/repo]
    import path from "node:path"
    import { fileURLToPath } from "node:url"
    const repo = process.argv[2] ?? "/workspace/repo"
    const { promptContentToParts } = await import(path.join(repo, "packages/cli/src/acp/content.ts"))
    let bad = false
    for (const uri of ["file:/tmp/a.txt", "file:///tmp/a.txt", "file://localhost/tmp/a.txt"]) {
      const parts = promptContentToParts([{ type: "resource_link", uri, name: "a.txt", mimeType: "text/plain" }])
      console.log(uri, "->", fileURLToPath(uri), JSON.stringify(parts))
      if (parts[0]?.type !== "file") bad = true
    }
    console.log(bad ? "BUG: some local file URIs were not turned into file attachments" : "OK")

    Run it: bun repro.ts

  2. added a commit that references this issue on Oct 29, 2026
    ccd8e60
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions