wesight icon indicating copy to clipboard operation
wesight copied to clipboard

[Bug] OpenCode 本地配置无法被识别:WeSight 读取的是 opencode.json,但 OpenCode 实际使用 opencode.jsonc

Open stephenlzc opened this issue 5 months ago • 5 comments

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

  1. 安装/初始化 OpenCode CLI,执行 opencode providers login 登录若干 provider(例如 DeepSeek / Kimi / OpenAI)。
  2. 确认 ~/.config/opencode/opencode.jsonc 存在,且 ~/.local/share/opencode/auth.json 已写入凭证。
  3. 打开 WeSight → 设置 → 更多 Agent 引擎 → 选择 OpenCode。
  4. 看到提示“下一步:打开设置配置模型,或先运行该 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.json
  • src/main/libs/externalAgentProviderStore.ts:1213 通过 readJsonObject(getOpenCodeConfigPath()) 读取配置
  • src/main/libs/externalAgentEnvironment.ts:1021
  • src/main/libs/externalAgentConfigSync.ts:647

Suggested Fix

  1. 让 getOpenCodeConfigPath() 优先查找 opencode.jsonc,回退到 opencode.json,与 OpenCode 自身的加载顺序保持一致。
  2. 当 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

stephenlzc avatar Jul 06 '26 01:07 stephenlzc

我也遇到这个问题了,其实 opencode 的 key(包括第三方的) 都是在 auth.json 里面的,这 opencode.json 里面的那个配置好像没什么用

zcqshine avatar Jul 18 '26 15:07 zcqshine

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

Keesan12 avatar Jul 21 '26 20:07 Keesan12

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!

github-actions[bot] avatar Sep 20 '26 01:09 github-actions[bot]

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:

  1. getOpenCodeConfigPath() now prefers opencode.jsonc and falls back to opencode.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.

  2. 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.

yan-6 avatar Sep 21 '26 01:09 yan-6

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!

github-actions[bot] avatar Nov 21 '26 01:11 github-actions[bot]