fix(plugin): skip cross-kind plugins in readV1Plugin detect mode#31552
Open
caniko wants to merge 1 commit into
Open
fix(plugin): skip cross-kind plugins in readV1Plugin detect mode#31552caniko wants to merge 1 commit into
caniko wants to merge 1 commit into
Conversation
When readV1Plugin is called with mode='detect' and kind='server', a
TUI-only plugin (with id and tui fields but no server field) should be
silently skipped instead of throwing TypeError.
The existing detect guard only checks whether ALL of {id, server, tui}
are absent. Add two additional guards that also short-circuit when the
plugin lacks the field for the requested kind.
This fixes the server plugin loader (plugin/index.ts) emitting ERROR
logs for every file-based TUI-only plugin configured via settings.plugin.
Contributor
|
Thanks for your contribution! This PR doesn't have a linked issue. All PRs must reference an existing issue. Please:
See CONTRIBUTING.md for details. |
Contributor
|
This PR doesn't fully meet our contributing guidelines and PR template. What needs to be fixed:
Please edit this PR description to address the above within 2 hours, or it will be automatically closed. If you believe this was flagged incorrectly, please let a maintainer know. |
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.
Issue for this PR
Closes # (no existing issue — this was discovered via canix config investigation)
Type of change
What does this PR do?
The server plugin loader (
packages/opencode/src/plugin/index.ts) callsreadV1Plugin(mod, spec, "server", "detect")for every plugin in the user's config. When a TUI-only plugin (one that exports{ id, tui }but notserver) is configured viasettings.plugin, the existing detect-mode guard only short-circuits when all three fields (id,server,tui) are absent. Sinceidandtuiare present, the function proceeds to the kind-specific check and throws:This error is caught and logged at ERROR level by the server loader, which is both noisy and misleading — the plugin is not a server plugin, it just happens to be configured in the same
pluginarray.The fix adds two short-circuit guards after the existing detect check that also return early when the plugin lacks the field for the requested kind. This is safe because:
serveris correctly skipped whenkind = "tui"(previously it would have been caught by thetui === undefinedcheck)tuiis correctly skipped whenkind = "server"(the crash case being fixed)serverandtuiis still rejected at line 293 (plugins must export one or the other, not both)id,server, nortuistill returns at line 283How did you verify your code works?
bun test test/plugin/shared.test.ts test/plugin/loader-shared.test.ts— 40 pass, 0 fail.kind,server,tui,id) to confirm early-return behavior matches expectations.Screenshots / recordings
N/A — logic-only change.
Checklist