Repository navigation
fix(plugin): serve bundled SDK to loose plugin files on Bun - #49097
Closed
rekram1-node wants to merge 1 commit into
Closed
rekram1-node wants to merge 1 commit into
rekram1-node wants to merge 1 commit into
Conversation
Loose plugin files under .opencode/plugins or configured by path have no node_modules, so the compiled Bun executable failed to resolve @opencode/plugin. Register the host's own SDK modules as Bun virtual modules when a plugin loads, matching the module hooks the Node executable already registers in its bundle prelude.
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.
Problem
A loose plugin file (
.opencode/plugins/foo.ts,~/.config/opencode/plugins/foo.ts, or"/abs/path/plugin.ts"inplugins) that doesimport { Plugin } from "@opencode/plugin"fails in the shipped Bun executable:Bun resolves the bare specifier from the plugin file's own location, there is no
node_modulesthere, and compiled executables do not auto-install. The docs example (Plugin.definefrom@opencode/pluginin a loose file) therefore did not work.The Node executable already handles this: its bundle prelude (
packages/cli/vite.node.config.ts) registersmodule.registerHooksthat map@opencode/plugin*to the bundled SDK viaglobalThis[Symbol.for("opencode.plugin.v2.*")](added in #36309). The TUI does the same for@opencode/plugin/tuithrough OpenTUI's runtime plugin. Only the Bun server side was missing it, most likely because V1 plugins only ever imported the SDK for types and V2'sPlugin.defineis the first runtime value import.Fix
packages/plugin/src/runtime.bun.ts: register the host's own@opencode/plugin,/effect,/promise/plugin,/promise/tool,/effect/plugin,/effect/toolas Bun virtual modules (build.module,loader: "object") once, so plugins share one module identity with the host.packages/plugin/src/runtime.node.ts: no-op; the Node prelude already covers it.Host.loadensures the shim is installed before importing the entrypoint, so every loader (core, TUI,plugin add/list) gets it.#plugin-runtimeconditional import, same pattern as the existing#plugin-source.Verification
Host.loadtest loads a loose.tsfrom a temp dir with nonode_modules, importing all three specifier shapes, and asserts identity with the host's modules.service-smoke.tsnow writes a plugin that imports@opencode/plugin, so CI exercises the compiled executable path. Ran it locally against a--singleBun build: passes..opencode/plugins/acme/{index.ts,tui.ts}wheretui.tsimports both@opencode/plugin/tuiand@opencode/plugin;/pluginsshows bothacme.serverandacme.tuiactive, confirming coexistence with OpenTUI's runtime plugin.bun typecheckinpackages/plugin,packages/core,packages/cli,packages/tui.Docs updated to state that
@opencode/pluginresolves at runtime and an install is only needed for editor types.Notes
node_modules/@opencode/pluginnext to a plugin, matching the Node prelude's behavior. This is intentional: the SDK must match the running host, and it keepsinstanceof/brand checks consistent.Agent, Command, ..., Skill) has drifted from the root index, which now also exportsLocation,Mcp,PersistentPty,Rpc,Vcs,WebSearch,Worktree. Not addressed here; the Bun shim hands over the full namespace so it cannot drift.