Skip to content

fix: replace Bun globals with Node fs APIs for OpenCode 1.18 compatibility - #4

Open
Tony-ooo wants to merge 1 commit into
JochenYang:mainfrom
Tony-ooo:fix/bun-undefined-compat
Open

fix: replace Bun globals with Node fs APIs for OpenCode 1.18 compatibility#4
Tony-ooo wants to merge 1 commit into
JochenYang:mainfrom
Tony-ooo:fix/bun-undefined-compat

Conversation

@Tony-ooo

Copy link
Copy Markdown

Problem

On OpenCode 1.18.x the plugin runtime no longer exposes the global Bun object. Both plugins/vision-helper.ts and tools/vision.ts call Bun.file() / Bun.write(), which now throw:

ReferenceError: Bun is not defined

This crashes experimental.chat.messages.transform (logged as prompt_async failed), so pasted images are never saved and the path hint is never injected. Non-vision models then only see the raw Cannot read "image.png" (this model does not support image input) error instead of being guided to the vision tool / subagent.

Fix

Replace all Bun file APIs with standard Node fs APIs:

  • plugins/vision-helper.ts: Bun.file().exists()fs.access(), Bun.write()fs.writeFile()
  • tools/vision.ts: Bun.file()fs.stat() / fs.readFile(), plus a mimeType() helper to infer MIME from the file extension (replacing Bun.file().type)

Verification

  • Pasted images are now saved to the temp dir and the path hint is injected correctly on OpenCode 1.18.18.
  • The image-reader subagent delegation path works end-to-end (verified with a pasted image).
  • Both files pass node --experimental-strip-types --check.

…ility

OpenCode 1.18 no longer exposes the Bun global to plugins, so Bun.file/Bun.write crash with 'ReferenceError: Bun is not defined', breaking pasted-image save/read.

- vision-helper.ts: persist images via fs.access + fs.writeFile
- vision.ts: read images via fs.stat + fs.readFile, derive MIME from extension
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants