Skip to content

fix(configure): seed the chosen model into the agents' saved selection - #229

Merged
quickbeard merged 1 commit into
mainfrom
seed-recent-model
Jul 31, 2026
Merged

fix(configure): seed the chosen model into the agents' saved selection#229
quickbeard merged 1 commit into
mainfrom
seed-recent-model

Conversation

@quickbeard

Copy link
Copy Markdown
Owner

Problem

#221 dropped the top-level model pin from the OpenCode/CoDev Code configs so in-CLI /models switches would stop reverting on restart, relying on the chosen model leading the models map to carry the first-launch default. That assumption never held: the map's order isn't read anywhere. With no pin and no saved selection, the OpenCode-family TUI falls back to the first provider in its list — upstream's hosted Zen provider, which self-registers (its free models need no auth) ahead of config-only providers — so a fresh codevhub install started on Big Pickle · OpenCode Zen instead of the gateway. And even within the right provider, the server's own model sort decides, not the map order (which is why a netgate fallback lands on the id-sort winner, not the wizard's choice).

Fix

configureOpenCodeKind now writes the install-time choice where the TUI actually reads it: the agent's XDG state dir model.json recent list (~/.local/state/{opencode,codev}/model.json) — the TUI's highest-priority startup source once the config carries no pin. A later in-CLI switch simply displaces it.

Guardrails:

  • Seeds only when the recents list is empty or absent. This writer also runs on every gateway-key auto-refresh (refresh.ts) and codevhub model; a non-empty list is a selection the user already made and must keep winning (the exact behavior fix(configure): stop pinning a default model for OpenCode and CoDev Code #221 was protecting).
  • Favorites/variants and unknown fields are carried over; a corrupt state file is replaced (the agent ignores one anyway), matching the config writer's recovery policy.
  • Entirely best-effort: a filesystem failure never fails the Configure step.
  • The stale comments claiming "ordering is what carries the choice" are corrected.

Tests

7 new tests in tests/lib/configure.test.ts: fresh seed for both kinds (correct per-app state dir), XDG_STATE_HOME honored, non-empty recents never overridden, empty-recents seed preserves favorites/variants, corrupt file replaced, manual-path provider id used. Shared setup now clears XDG_STATE_HOME so a host exporting it can't leak test writes into a real state dir. pnpm fix / typecheck / test (1292 passed) / build + Node smoke all green.

Relation to codev-code#144

Counterpart to codev-code#144, which fixes the TUI-side fallback to skip the Zen registration. Either alone fixes the visible Zen default; this one additionally makes the wizard's chosen model actually stick as the first-launch default.

🤖 Generated with Claude Code

Dropping the top-level `model` pin (#221) relied on the chosen model
leading the models map, but map order never carried the choice: with no
pin and no saved selection the OpenCode-family TUI falls back to the
first provider in its list — upstream's hosted Zen provider, which
self-registers ahead of config providers — so a fresh install started on
"Big Pickle · OpenCode Zen" instead of the gateway (and, within a
provider, the server's own sort picks the model, not the map).

Write the install-time choice where the TUI actually reads it: the
state dir's model.json `recent` list, its highest-priority startup
source after a config pin. Seed only when the recents list is empty or
absent — this writer also runs on every gateway-key auto-refresh and
`codevhub model`, and a non-empty list is a selection the user already
made that must keep winning. Favorites/variants are carried over, a
corrupt state file is replaced, and any filesystem failure is swallowed
(the seed is a nicety; the config write already succeeded).

Counterpart to codev-code#144, which fixes the TUI-side fallback to
skip the Zen registration; either alone fixes the visible default, this
one additionally makes the wizard's chosen model stick.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@quickbeard
quickbeard merged commit f58009d into main Jul 31, 2026
4 checks passed
@quickbeard
quickbeard deleted the seed-recent-model branch July 31, 2026 08:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant