Skip to content

fix(core): expose local attachment paths - #41789

Merged
kitlangton merged 5 commits into
v2from
attachment-source-paths
Aug 12, 2026
Merged

fix(core): expose local attachment paths#41789
kitlangton merged 5 commits into
v2from
attachment-source-paths

Conversation

@kitlangton

@kitlangton kitlangton commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

What

Expose the resolved filesystem location of explicitly attached local images and directories to the model. This restores V2 agents' ability to operate on selected image files and reference checkouts.

Closes #41443
Closes #41454

Before / After

Before: V2 admission materialized local attachments and durably retained their file: source URI, but message lowering only sent a directory alias or binary media filename. Provider-visible content omitted the resolved path, so an agent could see an image or reference root listing without knowing where to read it.

After: canonical message lowering decodes local file: source URIs. Directory context identifies the resolved directory, and local image media is preceded by one Attached file: <path> text part. The binary media payload and filename are unchanged.

How

packages/core/src/session/runner/to-llm-message.ts shares a local attachment-location formatter across directory and image lowering. It only emits locations for file: URIs and decodes the host-native URI produced when the attachment was admitted. Tests generate those URIs with pathToFileURL, matching production on POSIX and Windows.

packages/core/test/session-runner-message.test.ts covers a reference-like directory alias, a local image with durable source metadata, unchanged media bytes/filename, and the absence of added text for non-local media.

Scope

This is V2-only and does not modify legacy packages/opencode.

Inline attachments and non-local URI sources keep their existing provider content. Text attachment formatting and unsupported binary MIME handling are unchanged.

Testing

  • bun run test test/session-prompt.test.ts test/session-runner-message.test.ts from packages/core: 61 pass
  • Focused rerun after the Windows fix, bun run test test/session-runner-message.test.ts: 20 pass
  • bun typecheck from packages/core: pass
  • Push hook workspace bun turbo typecheck --concurrency=3: 33 tasks pass
  • bun run lint -- packages/core/src/session/runner/to-llm-message.ts packages/core/test/session-runner-message.test.ts: 0 errors; 3 pre-existing warnings
  • bunx prettier --check src/session/runner/to-llm-message.ts test/session-runner-message.test.ts: pass
  • git diff --check: pass
  • Previous Windows CI failures came from POSIX-only test URIs. Commit 4e0438edb2 makes the fixtures host-native and keeps production decoding aligned with attachment admission.

Demo

The focused provider-boundary tests are the exact evidence for this non-visual change: they verify admitted source.uri metadata becomes model-visible local paths while binary media remains intact. OpenCode Drive was not used because a provider-backed run would be less deterministic than asserting canonical messages directly.

# ------------------------ >8 ------------------------
# Do not modify or remove the line above.
# Everything below it will be ignored.
#
# Conflicts:
#	packages/core/src/session/runner/to-llm-message.ts
@Robin1987China

Copy link
Copy Markdown
Contributor

Complementary: my open PR #41723 covers the other half of the attachment lowering gap — image mimes outside the provider-supported set (image/avif, image/tiff) currently fall through attachmentContent and are silently dropped, while the TUI still labels them [Image N]. Once this lands, rebasing #41723 keeps the two paths consistent (supported images get the Attached file: path prefix, unsupported ones get an explicit text notice instead of vanishing).

@kitlangton
kitlangton marked this pull request as ready for review August 12, 2026 03:32
@kitlangton
kitlangton merged commit 90b6fa0 into v2 Aug 12, 2026
8 checks passed
@kitlangton
kitlangton deleted the attachment-source-paths branch August 12, 2026 03:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants