Skip to content

fix(core): discover local plugin packages - #41784

Merged
kitlangton merged 3 commits into
v2from
plugin-package-discovery
Aug 11, 2026
Merged

kitlangton merged 3 commits into
v2from
plugin-package-discovery

Conversation

@kitlangton

@kitlangton kitlangton commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor

Closes #41530

What

Discover local plugin packages placed as immediate child directories under .opencode/plugin/ or .opencode/plugins/, matching the documented V2 local discovery behavior.

Before / After

Before: OpenCode scanned only direct .ts and .js children. A directory such as .opencode/plugins/reviewer/ was silently skipped even when package.json exposed "exports": "./entry.ts" or the directory contained index.ts / index.js.

After: OpenCode enumerates each discovery directory once and loads immediate child packages in deterministic code-unit order. It resolves the first existing contained entrypoint from string exports, module, main, index.ts, then index.js, while preserving direct-file and symlink discovery.

How

  • packages/core/src/config/plugin/source.ts uses FSUtil.readDirectoryEntries to classify immediate files, directories, and symlinks without overlapping globs.
  • Package metadata is schema-decoded, candidate entrypoints must remain inside their package directory after real-path resolution, and the first existing candidate wins.
  • packages/core/test/config/plugin.test.ts covers string exports, fallback through missing exports to module, fallback through missing module to main, index.js, lexical traversal rejection, and symlink escape rejection.

Scope

  • Does not recursively walk package contents or discover nested plugin packages.
  • Does not add conditional/object exports or extensionless Node resolution; the documented and reported case is a string path to an existing entrypoint.
  • Does not change explicit plugin configuration or npm package installation.

Testing

  • bun run test test/config/plugin.test.ts from packages/core (15 passed)
  • bun typecheck from packages/core
  • bunx prettier --check packages/core/src/config/plugin/source.ts packages/core/test/config/plugin.test.ts
  • git diff --check
  • Push hook: bun turbo typecheck --concurrency=3 (33 tasks passed)
  • Exact issue reproduction: started the worktree V2 server with isolated OPENCODE_CONFIG_DIR, queried /api/plugin, and observed both repro.direct-file and repro.directory-package after catalog initialization

@kitlangton
kitlangton marked this pull request as ready for review August 11, 2026 17:14
@kitlangton
kitlangton merged commit 17536a9 into v2 Aug 11, 2026
12 checks passed
@kitlangton
kitlangton deleted the plugin-package-discovery branch August 11, 2026 17:14
jinhuang712 pushed a commit to jinhuang712/opencode that referenced this pull request Sep 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant