fix(acp): preserve file source location when converting text resource blocks - #32575
Closed
adityachaudhary99 wants to merge 1 commit into
Closed
fix(acp): preserve file source location when converting text resource blocks#32575adityachaudhary99 wants to merge 1 commit into
adityachaudhary99 wants to merge 1 commit into
Conversation
Contributor
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
3 tasks
…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>
adityachaudhary99
force-pushed
the
fix/acp-resource-uri-32558
branch
from
July 9, 2026 15:29
50ff3d5 to
52b3374
Compare
Contributor
|
Automated 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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