Skip to content

fix(plugin): skip mismatched kind in readV1Plugin detect mode - #40426

Open
Thatgfsj wants to merge 1 commit into
anomalyco:devfrom
Thatgfsj:fix/plugin-read-v1-detect-mode
Open

fix(plugin): skip mismatched kind in readV1Plugin detect mode#40426
Thatgfsj wants to merge 1 commit into
anomalyco:devfrom
Thatgfsj:fix/plugin-read-v1-detect-mode

Conversation

@Thatgfsj

@Thatgfsj Thatgfsj commented Aug 4, 2026

Copy link
Copy Markdown

Issue for this PR

Closes #31610

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

In readV1Plugin (packages/opencode/src/plugin/shared.ts), when the
server plugin loader calls it with mode="detect" and kind="server",
a plugin module that exports only tui falls through to the
kind-specific check and throws TypeError: Plugin ... must default export an object with server(). The error is caught and logged at
ERROR level on every startup for users with TUI-only plugins, which
is noisy and misleading.

The existing "all fields missing" guard does not fire because id
and tui are present. The fix mirrors that guard with two new
per-kind short-circuits so detect mode silently skips plugins that
don't expose the requested kind's entrypoint. The mirror for
kind === "tui" is included for symmetry even though the bug report
only mentioned the server path.

Strict mode is unchanged: a TUI-only plugin supplied as a server
plugin under strict mode still throws, which is the desired behavior.

How did you verify your code works?

Added a regression test (test/plugin/read-v1-plugin.test.ts) with
four cases:

  • TUI-only plugin scanned by server loader in detect mode -> returns undefined
  • server-only plugin scanned by TUI loader in detect mode -> returns undefined
  • plugin that exposes the requested kind -> returns the value
  • strict mode still throws for mismatched kinds (unchanged behavior)

bun test packages/opencode/test/plugin/read-v1-plugin.test.ts -> 4/4 pass.

Screenshots / recordings

Not applicable (no UI change).

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

When the server plugin loader scans modules with mode="detect",
a plugin that exports only `tui` (and no `server`) currently falls
through to the kind-specific check and throws a misleading
"must default export an object with server()" error. The error is
caught and logged, polluting startup logs for legitimate TUI-only
plugins.

Mirror the existing all-fields-missing guard with per-kind
short-circuits so detect mode silently skips plugins that don't
expose the requested kind's entrypoint.

Adds a regression test covering TUI-only and server-only detection.

Fixes anomalyco#31610
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.

readV1Plugin detect mode throws TypeError for TUI-only plugins loaded as server plugins

1 participant