freestylefly / freestylefly/wesight

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

Open
#60 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
923
Forks
206
Avg merge
24m
Merged PRs (30d)
2

Description

### 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 记录:
```sql
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

Contributor guide

No contributing guide indexed for this repository

Research direction

Start in src/main/libs/externalAgentProviderStore.ts at getOpenCodeConfigPath() around line 212 and the readJsonObject() call around line 1213, then trace the related logic in externalAgentEnvironment.ts:1021 and externalAgentConfigSync.ts:647. Reproduce with opencode.jsonc and auth.json present, and verify that external_agent_providers receives the expected OpenCode data and the setup prompt is no longer misleading.

Written by the indexing model from the issue text.

Assessment

Tech stack
electron, typescript
Domain
backend, desktop
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
64/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.