fix: discover OpenCode Desktop's bundled CLI for model catalogs
Refs #857
[!IMPORTANT]
AI-generated contribution. This entire patch was written by an AI coding assistant (DeepSeek V4.1 Flash via OpenCode), not by a human. It works on the reporter's Windows machine, but it has not been reviewed by a person and it was not fully compiled locally: the Dashboard Rust change was checked with rustfmt only because this machine has no MSVC build tools. Please treat CI as the first real Rust compile and review the logic critically.
Problem
On Windows, OpenCode Desktop 2.2.5 was the running host, while opencode on PATH was a stale npm opencode-ai@1.2.15. The user's config uses the OpenCode 2 shape (mcp.servers), which the v1 CLI rejects with Invalid input mcp.servers; opencode models therefore returned no catalog.
Consequences:
magic-context setupshowed No models found and fell back to free-text entry, so there was no autocomplete.- The Dashboard model dropdown was empty and could not suggest or validate any model.
magic-context doctoralways warned that the model catalog was unreadable.
There were two separate Windows gaps in Magic Context:
- Model discovery never probed the runnable
opencode-clisidecar that OpenCode Desktop downloads under<userData>/<appId>/cli/<version>-<arch>/. - Doctor spawned bare
opencodewithspawnSync. On Windows that cannot run an npm.cmdshim (ENOENT, no PATHEXT resolution), even though the rest of the CLI already had a.cmd-aware invocation helper.
Changes
packages/cli/src/lib/opencode-detect.ts- Adds Desktop's bundled
opencode-clisidecar to the installation ladder, newest version first, for all three Desktop channels. - Adds an injectable
readdirseam for hermetic tests.
- Adds Desktop's bundled
packages/cli/src/commands/setup-opencode.ts- Probes every detected CLI installation until one returns a catalog, instead of trusting only the first PATH entry.
- Uses the CLI that produced the catalog to select the OpenCode 1/2 config key.
packages/cli/src/commands/doctor-opencode.ts- Routes the catalog probe through
getOpenCodeCommandInvocation, so a detected.cmdshim is launched correctly on Windows.
- Routes the catalog probe through
packages/dashboard/src-tauri/src/commands.rs- Adds Desktop-bundled CLI candidates to model discovery.
- Extracts the shared Desktop userData lookup and sorts sidecar versions numerically (
2.2.10above2.2.9).
- Tests
- CLI detector: Windows sidecar discovery, newest-first ordering, non-executable filtering.
- Doctor: Windows
.cmdshim catalog probe. - Dashboard Rust: sidecar version ordering and missing-binary filtering (tests added; not compiled locally).
Verification
bun run --cwd packages/cli typecheck— passed.bun test src/commands/setup-opencode.test.ts— 25/25 pass.bun test src/commands/doctor-opencode.test.ts— 55 pass; one unrelated pre-existing Windows-only expectation incollectNpmReleaseAgeWarningsfails because the helper sanitizes the username to<USER>.bun test src/lib/opencode-detect.test.ts— new sidecar tests pass.bunx biome checkon every changed TypeScript file — clean.rustfmt --check packages/dashboard/src-tauri/src/commands.rs— clean.- Manual check on the reporter's machine: published setup dry-run discovered 73 models; the Dashboard cached all 73; the patched doctor reported
PASS 21 / WARN 0 / FAIL 0.
Harness coverage (required)
- OpenCode 1: covered — the detector and doctor invocation changes apply to v1 installs; no v1 behavior was removed.
- OpenCode 2: covered — Desktop's sidecar is a v2 host; setup uses its version to choose the v2 config key, and the Dashboard discovers it.
- Pi: not applicable — no
packages/pi-pluginfiles are touched. - OMP: not applicable — no OMP surface is touched.
- Rust module: covered for Dashboard discovery;
rustfmt-checked, not compiled locally.
Notes
- The commit message carries the same AI-generation notice.
- The reporter's global CLI was updated separately to
@opencode/cli@2.2.5; this PR does not change package versions or installation state. - No local config, credentials, logs, or machine paths are included in the diff.
Summary by cubic
Fixes Windows model discovery so OpenCode Desktop's bundled opencode-cli sidecar is used for catalogs, and doctor can run .cmd shims. Previously, a stale npm 1.x CLI on PATH could block catalog discovery even when a fresher Desktop sidecar existed.
- Setup probes every detected CLI installation until one returns a catalog, not just the first PATH entry, and uses that CLI's version to select the OpenCode 1/2 config key.
- Doctor routes catalog probes through the existing
.cmd-aware invocation helper instead of spawning bareopencodeon Windows. - Dashboard adds Desktop-bundled CLI candidates to discovery, sorting sidecar versions numerically.
- Desktop installs without a runnable sidecar still count as an install and fall back to manual model entry.