fix: export only the plugin factory from the plugin entry point - #100
Open
vtemian wants to merge 1 commit into
Open
fix: export only the plugin factory from the plugin entry point#100vtemian wants to merge 1 commit into
vtemian wants to merge 1 commit into
Conversation
opencode calls every exported function in a plugin module as a plugin factory and installs each return value as hooks. src/index.ts exported four helpers alongside the plugin, so mergePluginAgents was being invoked as (input, undefined) and threw on Object.entries, which opencode swallowed while still exiting 0: failed to load plugin ... Object.entries requires that input parameter not be null or undefined Hook registration survived only because ESM namespace keys sort alphabetically and OpenCodeConfigPlugin starts with a capital letter, placing it ahead of the throw. Renaming that export, or adding one sorting earlier, would have silently dropped every hook. Move the helpers to plugin-config.ts and leave the entry point exporting the plugin alone.
|
Bugbot is not enabled for your account, so this pull request was not reviewed. Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs. |
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.
Found while researching an e2e harness: micode currently logs a plugin load error on every opencode start, and only registers its hooks by luck.
What opencode actually does
It calls every exported function in a plugin module as a plugin factory, and installs each return value as hooks:
src/index.tsexported four helpers alongside the plugin. Invoked as(input, options),mergePluginAgentsreceivesoptions === undefinedand throws:opencode swallows that error and still exits
0, so nothing surfaced it.Why it worked anyway, and why that is not reassuring
ESM namespace keys are sorted alphabetically, not by declaration order.
OpenCodeConfigPluginstarts with a capitalO(charCode 79), which sorts ahead of lowercaseb(98), so the real plugin registered its hooks before the throw.Rename that export to something lowercase, or add any export sorting in
A–N, and every micode hook disappears silently with a clean exit code.Verified against the shipped bundle before the fix:
Note the non-throwing helpers were not harmless either.
buildMcpServers(ctx, undefined)returns a map of MCP servers, which opencode would then install as a hooks object.Fix
Move the four helpers to
src/plugin-config.ts. The entry point now exports the plugin alone:Tests import them from their new home; no behaviour changed.
Verification
489 tests pass. A new guard asserts the module's callable surface is exactly
["OpenCodeConfigPlugin"], which is the invariant rather than a proxy for it, since a helper that returns rather than throws is equally wrong.Mutation-checked: re-exporting a single helper from
src/index.tsfails the guard.The guard deliberately does not invoke the factories. Doing so loads the PTY library and probes for
btca, which leaks output into the reporter and takes 20x longer.