Skip to content

morph_edit uses Bun.file/Bun.write but OpenCode Desktop plugin runtime may not expose global Bun #29

Description

@leytonblackler

Summary

In OpenCode Desktop 1.17.12, the Morph OpenCode plugin morph_edit tool can fail with Bun is not defined because the plugin implementation reads/writes files through global Bun.file / Bun.write.

A minimal local compatibility patch replacing only that file I/O with Node fs/promises (readFile / writeFile) fixed the Desktop active-workflow smoke test while preserving the Morph SDK calls, tool names, WarpGrep tools, and compaction hooks.

Environment

  • OpenCode Desktop: 1.17.12
  • OpenCode CLI after alignment: 1.17.12
  • Node: v24.16.0
  • Plugin: @morphllm/opencode-morph-plugin@2.0.16
  • Shell did not have a user-installed bun binary on PATH, but installing Bun alone is not expected to inject a global Bun into an Electron/Node plugin process.

Reproduction

  1. Configure a valid MORPH_API_KEY for OpenCode Desktop.
  2. Restart OpenCode Desktop.
  3. Run morph_edit against an existing scratch file.

Observed error before patch:

Error reading file ...: Bun is not defined

Expected

morph_edit should work in OpenCode Desktop plugin runtimes that do not expose a global Bun, or the plugin/runtime requirement should be documented clearly.

Minimal fix tested locally

Replace the direct Bun file I/O calls in morph_edit with portable Node APIs:

import { readFile, writeFile } from "node:fs/promises";

originalCode = await readFile(filepath, "utf8");
await writeFile(filepath, normalizedCodeEdit, "utf8");
await writeFile(filepath, mergedCode, "utf8");

After this contained change was loaded as a local OpenCode plugin, Desktop active-workflow smoke tests passed for:

  • existing-file morph_edit edit
  • missing target file creation without lazy markers
  • missing target file with lazy markers returning the expected safe error
  • local WarpGrep
  • public repo WarpGrep against vercel/next.js
  • /morph compact slash-command interception

No Bun is not defined errors occurred after the patch.

Notes

This report is only about the OpenCode plugin Desktop compatibility surface. Generic Morph SDK/API usage is not the issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions