fix(shared): pass the OpenCode model through OPENCODE_CONFIG_CONTENT

SA
6h ago
+59-26

What & why

Fixes #9913 (the launch failure; the hand-kept model list part was handled by #10035).

Picking any model for OpenCode made the launch fail with ERROR Unrecognized flag: --model in command opencode. OpenCode 2's top-level (TUI) command no longer has --model; only run and mini do. Paradev put --model <provider/model> straight after opencode.

OpenCode 1.x and 2.x both read OPENCODE_CONFIG_CONTENT and layer it over the user's own config. So the OpenCode preset now uses the existing modelEnv path (the one Vibe uses) instead of modelFlag:

OPENCODE_CONFIG_CONTENT='{"model":"anthropic/claude-sonnet-4-6"}' opencode
  • AgentModelSupport gets an optional modelEnvValue to build the env value from the model id (bare id by default, so Vibe is unchanged).
  • buildAgentModelEnv now uses isLaunchableAgentModel, the same check as buildAgentModelArgs, so models OpenCode lists itself (discovered since #10035) still launch. For Vibe this is the same as before.

One behaviour to know: if a user set their own OPENCODE_CONFIG_CONTENT in the agent's env and also picks a model, the picked model's value wins for that launch. "Default" passes nothing, as before.

How I tested it

  • bun test packages/shared/src/agent-models.test.ts: 94 pass. New test: OpenCode gets no --model arg and gets the config overlay instead. Existing OpenCode assertions moved from --model to the env.
  • Ran the old command against OpenCode 2.0.20: exit 1, Unrecognized flag: --model in command opencode (same as the report).
  • Generated the new launch prefix from this branch's code and ran <prefix> opencode debug config on 2.0.20 and 1.19.6: both list the overlay with anthropic/claude-sonnet-4-6 on top of the user config.
  • Not done: a full interactive launch with a signed-in provider.

No UI changes, so no screenshots.

Checklist

  • PR title follows conventional commits (type(scope): subject)
  • bun run lint passes; tsc --noEmit passes for packages/shared (full bun run typecheck not run)
  • "Allow edits from maintainers" is checked on fork PRs
  • I have signed the CLA

Summary by cubic

Fixes the OpenCode launch failure when picking a model, which used to crash with ERROR Unrecognized flag: --model in command opencode.

OpenCode's TUI no longer accepts --model, so the model now travels through the OPENCODE_CONFIG_CONTENT env var as a JSON overlay ({"model":"provider/model"}) instead. This keeps OpenCode 1.x and 2.x working, and buildAgentModelEnv now uses the same launchability check as buildAgentModelArgs, so models OpenCode discovers on its own still launch.

  • Adds an optional modelEnvValue to AgentModelSupport to shape the env value from the model id; Vibe's behavior is unchanged.
  • If a user sets their own OPENCODE_CONFIG_CONTENT and also picks a model, the picked model wins for that launch.

Summary by CodeRabbit

  • New Features
    • OpenCode now uses the selected model when launching, including supported models beyond the curated model list.
  • Bug Fixes
    • Improved model selection compatibility so launchable models can be passed through to OpenCode without requiring an exact match in the curated catalog.