bug: v2 service discovery misses Nix-packaged OpenCode (writes service-prod.json, plugin reads service.json)
还没有人认领这个 Issue。
评估
调研方向
从 lua/opencode/server/discovery/init.lua 中的 M.registration() 开始,然后使用 issue 中描述的隔离 XDG 状态目录和 Nix 软件包进行复现。验证 discovery 能找到 service-prod.json,同时保留对 service.json 的 discovery,并确认 :checkhealth 不再报告没有注册 service。
由索引模型根据 Issue 内容生成。
描述
Summary
Server discovery only looks for service.json in the XDG state directory, but OpenCode v2 names the registration file after OPENCODE_CHANNEL. The Nix package sets OPENCODE_CHANNEL = "prod", so it writes service-prod.json and the plugin never finds a server.
Why the filename is channel-dependent
packages/cli/src/services/service-config.ts:
export function filename(channel = OPENCODE_CHANNEL) {
if (channel === "latest" || channel === "dev" || channel === "beta" || channel === "next") return "service.json"
return `service-${channel.replace(/[^a-zA-Z0-9._-]/g, "-")}.json`
}
So only latest, dev, beta and next produce the plain name. nix/opencode.nix on v2 builds with env.OPENCODE_CHANNEL = "prod", which is not one of them, so Nix users get service-prod.json.
lua/opencode/server/discovery/init.lua hardcodes the plain name:
local path = vim.fs.joinpath(state_dir, "service.json")
Reproduction
From a Nix-packaged OpenCode v2 (nix build .#opencode), with an isolated state dir:
$ export XDG_STATE_HOME=/tmp/oc/state
export XDG_DATA_HOME=/tmp/oc/data XDG_CACHE_HOME=/tmp/oc/cache XDG_CONFIG_HOME=/tmp/oc/config
$ opencode service start
http://127.0.0.1:49374
$ ls $XDG_STATE_HOME/opencode/
service-prod.json
$ cat $XDG_STATE_HOME/opencode/service.json
cat: .../service.json: No such file or directory
Neovim then reports, in :checkhealth opencode:
No OpenCode background service registered yet. Run
opencodeto start it, or setvim.g.opencode_opts.server.url.
...even though the service is running and reachable, and even after opencode has been launched from the terminal.
For comparison, the same binary built with OPENCODE_CHANNEL=latest writes service.json and discovery works:
$ export XDG_STATE_HOME=/tmp/oc2/state # isolated again
$ opencode service start
http://127.0.0.1:49374
$ cat $XDG_STATE_HOME/opencode/service.json
{"id":"...","version":"2.0.18+dd786c6","url":"http://127.0.0.1:49374","pid":122289,"password":"..."}
Suggested fix
M.registration() should read the channel-suffixed files too, since that is what OpenCode writes. The registration payload is self-describing (url, password, pid, version), so a small glob over the state directory, newest service*.json first, would cover every channel without needing to know the channel name.
This keeps working for the channels that already write service.json, and adds the ones that do not. It also avoids tying the plugin to OpenCode's channel list, which is a separate upstream detail that can change.
Impact
Anyone consuming the Nix package (or any build that sets a channel other than latest/dev/beta/next) cannot use the plugin without hardcoding server.url and exporting OPENCODE_SERVER_PASSWORD by hand, which defeats the point of the background-service model.
Environment
- opencode.nvim
06770e2(main, the v2-supporting default) - OpenCode 2.0.18, Nix package,
x86_64-linux - Neovim 0.11
- 主要语言
- Lua
- 星标
- 3.8k
- 派生
- 161
- 平均合并
- 16 小时 31 分钟
- 30 天内合并 PR
- 4
环境准备
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
nickjvandyke/opencode.nvim 的其他 Issue
-
enhancement
难度 4/5 3-5 天 新手友好度 55/100
nickjvandyke/opencode.nvim#335 · 1 条评论 ·
-
enhancement
难度 5/5 一周以上 新手友好度 45/100
nickjvandyke/opencode.nvim#321 · 2 条评论 · 1 个 reaction ·
-
enhancement
难度 2/5 1-3 小时 新手友好度 52/100
nickjvandyke/opencode.nvim#41 · 1 条评论 · 9 个 reaction ·
查看 nickjvandyke/opencode.nvim 的全部 Issue
相似的 Issue
-
bug
难度 2/5 1-3 小时 新手友好度 68/100
AstroNvim/astrotheme#184 ·
-
难度 2/5 1-3 小时 新手友好度 86/100
-
难度 2/5 1-3 小时 新手友好度 82/100
objectionary/eolang.sty#184 ·
-
bug
难度 2/5 1-3 小时 新手友好度 76/100
维护者通常 1 天内回复
-
feature request
难度 1/5 1 小时以内 新手友好度 86/100
维护者通常 2 天内回复