[Bug] OpenCode 本地配置无法被识别:WeSight 读取的是 opencode.json,但 OpenCode 实际使用 opencode.jsonc
Bug Description
WeSight 在“更多 Agent 引擎”里检测到 OpenCode CLI 后,仍提示需要配置模型。根本原因是 WeSight 内部把 OpenCode 的配置文件路径硬编码为 ~/.config/opencode/opencode.json,而 OpenCode(v1.17.13)实际创建/使用的是 ~/.config/opencode/opencode.jsonc。
此外,OpenCode 通过 opencode providers login 把登录凭证存在 ~/.local/share/opencode/auth.json,并不会自动写入 opencode.jsonc。WeSight 目前只读 opencode.json 且只解析其中的 model/provider,不会从 auth.json 推断已登录的 provider,所以即使用户已经在 OpenCode 里“配好了模型/Key”,WeSight 仍然看不到。
Steps to Reproduce
- 安装/初始化 OpenCode CLI,执行
opencode providers login登录若干 provider(例如 DeepSeek / Kimi / OpenAI)。 - 确认
~/.config/opencode/opencode.jsonc存在,且~/.local/share/opencode/auth.json已写入凭证。 - 打开 WeSight → 设置 → 更多 Agent 引擎 → 选择 OpenCode。
- 看到提示“下一步:打开设置配置模型,或先运行该 CLI 的本机登录/初始化命令”。
Expected Behavior
WeSight 应能正确读取 OpenCode 当前生效的配置文件(.jsonc),并在 OpenCode 已登录 provider 的情况下识别出可用模型,或至少给出与事实一致的提示。
Actual Behavior
WeSight 找不到 opencode.json,readJsonObject(getOpenCodeConfigPath()) 返回 null,导致数据库 external_agent_providers 中 app_type='opencode' 为空,UI 持续提示需要配置模型。
Environment
- OS: macOS (Apple Silicon)
- WeSight Version: 2026.6.28
- OpenCode Version: 1.17.13
- Node.js Version: 26.3.1
Logs/Screenshots
WeSight main log只显示 CLI 被检测到:
[AgentEngineSnapshot] opencode found at /Users/cong/.local/bin/opencode (1.17.13)
但 external_agent_providers 表中没有 OpenCode 记录:
SELECT * FROM external_agent_providers WHERE app_type='opencode';
-- 0 rows
Code References
src/main/libs/externalAgentProviderStore.ts:212硬编码opencode.jsonsrc/main/libs/externalAgentProviderStore.ts:1213通过readJsonObject(getOpenCodeConfigPath())读取配置src/main/libs/externalAgentEnvironment.ts:1021src/main/libs/externalAgentConfigSync.ts:647
Suggested Fix
- 让
getOpenCodeConfigPath()优先查找opencode.jsonc,回退到opencode.json,与 OpenCode 自身的加载顺序保持一致。 - 当
opencode.json(c)为空但~/.local/share/opencode/auth.json存在时,可考虑从auth.json解析出已登录的 provider,并在 UI 中列出对应模型,避免用户重复配置 Key。
Checklist
- [x] I have searched for existing issues
- [x] I have provided all the requested information
我也遇到这个问题了,其实 opencode 的 key(包括第三方的) 都是在 auth.json 里面的,这 opencode.json 里面的那个配置好像没什么用
The adapter should ask OpenCode where its active config and auth state live, rather than reconstructing that contract from hard-coded filenames. If discovery is unavailable, supporting both JSONC config and a redacted provider-status check is safer than reading credentials directly.
This is the MartinLoop principle we use across coding agents: normalize the tool's real output, preserve provenance, and never assume two versions expose the same shape.
Would you be willing to test WeSight's OpenCode detection against our adapter contract and share the cases that still drift? https://github.com/Keesan12/martin-loop
This issue has been inactive for 60 days. It will be automatically closed in 14 days unless there is new activity.
If this issue is still relevant, please leave a comment or update it to keep it open. Thank you!
Still relevant — please keep this open.
This is being addressed in #83, which is open and has green CI. Both parts of the original report are covered:
-
getOpenCodeConfigPath()now prefersopencode.jsoncand falls back toopencode.json, matching OpenCode's own load order. Applied in all three modules named in the report (externalAgentProviderStore.ts,externalAgentEnvironment.ts,externalAgentConfigSync.ts), and each of them can now parse JSONC rather than only resolve to it. -
Inferring logged-in providers from
~/.local/share/opencode/auth.json— your second suggestion — is handled in #85, together with the related stall reported in #78.
One thing worth noting for anyone hitting this: the .jsonc preference also made WeSight's write path rewrite that file, which silently deleted hand-written comments. That is fixed in #83 as well, so a commented opencode.jsonc now survives a model switch in the UI.
Awaiting maintainer review on #83.
This issue has been inactive for 60 days. It will be automatically closed in 14 days unless there is new activity.
If this issue is still relevant, please leave a comment or update it to keep it open. Thank you!