Uh oh!
There was an error while loading. Please reload this page.
fix(acp): preserve file source location when converting text resource blocks - #32575
fix(acp): preserve file source location when converting text resource blocks#32575adityachaudhary99 wants to merge 1 commit into
Conversation
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
…nomalyco#32558) When an editor (e.g. Zed) sends a code selection over ACP, it uses a `type: "resource"` ContentBlock where `resource.uri` carries the file path (and optional `#L` line range) and `resource.text` carries the selected text. `contentBlockToParts()` extracted only `resource.text` and dropped the uri, so the LLM received bare text with no source context and replays could not trace the snippet back to its file. The text branch now prefixes the content with the resolved file location (`[/path/file.ts:12-15]`) when the resource carries a `file://` uri, mirroring how the `resource_link` and blob branches already use the uri. Non-`file://` uris (and unparseable ones) are left untouched. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
50ff3d5 to
52b3374CompareAutomated PR Cleanup Thank you for contributing to opencode. Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions. This PR was closed because it matched the following cleanup criteria:
PRs created within the last month are not affected by this cleanup. If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate. Thanks again for taking the time to contribute. |
Issue for this PR
Closes#32558
Type of change
What does this PR do?
When an ACP client (e.g. Zed) attaches a selected snippet as a
resourcecontent block with inlinetext, opencode was silently dropping the resource'suri. The snippet arrived as a bare text part with no provenance — the LLM and session replays had no way to trace it back to its source file or line range.This PR adds a
fileSourcePrefixhelper that, when a textresourceblock carries afile://uri, prefixes the text with the resolved file path (and line range when the uri contains a#L12or#L12-15fragment):Non-
file://uris (e.g.https://) and unparseable uris fall through unchanged — the helper returnsundefinedand the original text passes through untouched.The Chat Completions (
/resource_link) path is left unchanged.How did you verify your code works?
Added three focused unit tests to
packages/opencode/test/acp/content.test.ts:#L12-15fragment parses to:12-15in the prefixhttps://uris pass through unchangedTest URIs are constructed via
path.resolve+pathToFileURLso they round-trip correctly on all platforms (Windows and POSIX). All 15 tests in the content suite pass.Screenshots / recordings
N/A — no UI change.
Checklist