Skip to content

fix(acp): inline file content for ResourceContentBlock @-references#20237

Open
evantouchelf wants to merge 1 commit into
NousResearch:mainfrom
evantouchelf:main
Open

fix(acp): inline file content for ResourceContentBlock @-references#20237
evantouchelf wants to merge 1 commit into
NousResearch:mainfrom
evantouchelf:main

Conversation

@evantouchelf

Copy link
Copy Markdown

Problem

When Zed (and other ACP editors) sends a @filename reference to a file, it comes through as a ResourceContentBlock (with a file:// URI) or an EmbeddedResourceContentBlock (with inline content). The ACP adapter's _content_blocks_to_openai_user_content() and _extract_text() functions only handled TextContentBlock and ImageContentBlock — resource blocks were silently dropped.

This meant users could @src/main.rs in Zed and the AI would never see the file content.

Fix

Added handling for three ACP content block types:

ResourceContentBlock (resource_link)

Zed sends the file as a file:// URI with optional line ranges (#L9 or #L9:15). The server now:

  • Parses the file:// URI (supports URL-encoded paths)
  • Extracts #L9:15 line range
  • Reads the file directly on the server side
  • Inlines content as --- File: /path#L9:15 --- ... --- End of /path ---
  • Falls back to [Referenced file: ...] if the file can't be read
  • Caps at 100K characters

EmbeddedResourceContentBlock with TextResourceContents

Inlines resource.text directly (the client already embedded the content).

EmbeddedResourceContentBlock with BlobResourceContents

Decodes base64 for text/* mime types; marks binary content as [Binary content, type: ...].

Testing

  • All 214 existing ACP tests pass unchanged (tests/acp/ + tests/acp_adapter/)
  • Manual test with Zed @-references confirms content is inlined correctly

Related

Fixes a gap where resource content blocks were declared in the function type signature but not handled in the implementation body.

When Zed sends a file:// URI via ACP ResourceContentBlock (e.g. @filename),

the ACP adapter now reads the file content on the server side and inlines it

directly into the prompt, so the AI sees the file contents without needing

an extra read_file tool call.

Supports:

- file:// URIs with #L9 / #L9:15 line ranges

- URL-decoded paths (Chinese characters, spaces)

- EmbeddedResourceContentBlock (text/blob)

- Fallback to [Referenced file: ...] marker on failure

- 100K character truncation

Fixes: ResourceContentBlock and EmbeddedResourceContentBlock were previously

silently dropped in both _extract_text() and _content_blocks_to_openai_user_content().
@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/acp Agent Communication Protocol adapter labels May 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/acp Agent Communication Protocol adapter P2 Medium — degraded but workaround exists type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants