fix(plugin): 拆分 server/tui 入口兼容 OpenCode v1 插件规范#15
Merged
Conversation
OpenCode v1 插件加载器按 package.json exports 的 ./server 和 ./tui
分别解析 server 与 TUI 插件,且要求两者互斥(PluginModule.tui 为
never)。本插件为纯 TUI 插件,但 package.json 暴露了 main 指向
dist/index.js(仅导出 { id, tui }),当用户经 Ctrl+P install plugin
将包写入 opencode.json 的 server 通道时,加载器以 kind=server 解析
该模块并抛出 must default export an object with server()。
修复方式:
- 删除 main 字段,移除 exports[.] 通用入口,切断 server 通道对
TUI 模块的 fallback 解析路径。
- 新增 exports[./server] 指向 dist/server.js,导出空 server
({ id, server: async () => ({}) }),使 server 通道加载到合法
的 PluginModule 而非报错,TUI 功能仍由 ./tui 入口承载。
- 新增 src/server.ts 作为空 server 入口源文件。
同 opencode-subagent-magazine issue #8 的根因与修复方式。
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.
问题
经
Ctrl+P → install plugin安装本插件后,部分用户遇到 OpenCode 启动报错并退出:根因
Ctrl+P → install plugin会根据package.json的exports和main字段判定插件具备哪些 target(install.ts的packageTargets):exports["./server"]不存在,但main存在 → 推入{ kind: "server" }exports["./tui"]存在 → 推入{ kind: "tui" }因此插件被同时写入
opencode.json(server 通道)和tui.json(TUI 通道)。本插件是纯 TUI 插件,
dist/index.js(main指向的文件)只导出{ id, tui },没有server键。OpenCode v1 加载器readV1Plugin以kind=server解析该模块时,因server键为undefined而抛错。TUI 通道从
exports["./tui"]加载dist/tui.js,始终正常——所以 TUI 功能能显示,server 通道的报错在某些 OpenCode 版本下被吞为日志,在另一些版本下直接导致退出。修复方式
按 OpenCode v1 规范,
./server和./tui应为分离的 target-only 模块,互斥导出(PluginModule.tui为never)。main字段,移除exports["."]通用入口——切断 server 通道对 TUI 模块的 fallback 解析路径。exports["./server"]指向dist/server.js,导出空 server({ id, server: async () => ({}) })——server 通道加载到合法的PluginModule,不注册任何 hook,完全静默。src/server.ts作为空 server 入口源文件。./tui入口承载,不受影响。生效机制
两个通道各取各的入口,互不干扰。
Ctrl+P → install plugin同时写两个文件都不出问题。