feat(agents): discover runtime models and filter model pickers

Merged
KI
2d ago
+2156-213

What & why

Model pickers used bundled lists, so new models an agent supports could be missing and a launch could reject their ids. The host now asks the agent itself for its models, and the pickers show that list.

  • Discovery. agents.models on the host returns an agent's models, its default model and its default effort. Sources: the chat runtime for Claude, Codex, OpenCode, Pi and pdev; OpenCode ACP, codex app-server and cursor-agent --list-models for terminal launches; the bundled list for every other agent and as the fallback when discovery fails.
  • Picker. Each agent has a tab. The first row is "Default", with the model and effort it resolves to when the agent reports them ("Default Opus 5.5", "Default High"). Search and provider filters apply; models that cannot run coding tasks sit behind a "Show all models" row. While a list loads, the bundled list shows with a small "Loading..." row at the bottom.
  • Remembered picks. A remembered model stays selected while the list loads and is dropped once the host has answered without it. Desktop and mobile.
  • Launch. Codex, OpenCode and Cursor list their own models, so a terminal launch passes any well-formed model id to the CLI and the CLI decides. Every other agent keeps the bundled-list check. Launches do not run a discovery.
  • Failure. A failed discovery, an agent with no listing, and a host that predates agents.models all show the bundled list, with no warning.
  • Limits. Each discovery has a 20 second deadline; results are cached for 60 seconds and concurrent callers share one probe.
  • Chat adapter. A chat session started with a model the agent does not offer refuses to prompt until a model is chosen, instead of silently running the default.
  • Mastracode is left out of the agent list on desktop and mobile.

Audit, architecture and earlier screenshots.

Behaviour change

A mistyped or retired model id for Codex, OpenCode or Cursor is no longer rejected by the host with "Unsupported model". It reaches the CLI, which fails in the terminal. This also applies to launches from the CLI and automations.

Known gaps

  • Each OpenCode discovery leaves an empty session in the user's OpenCode history.
  • OpenCode and Cursor list models the account cannot run; picking one fails in the agent (seen: OpenCode "not supported when using Codex with a ChatGPT account", Cursor "Model unavailable on Free").
  • Cursor reports every effort and speed variant as its own model, so its tab has 284 rows.
  • Pi needs the current @earendil-works/pi-coding-agent package. With the old @mariozechner package the bundled pi-acp never gets an answer, so the tab shows only "Default" after 20 seconds and a Pi chat hangs. This predates the PR.
  • Codex names read "6.1 Sol" in chat and "GPT-6.1 Sol" in a terminal.
  • For Codex, OpenCode and Cursor the "Unsupported model" error for a malformed id still says "Choose one of" followed by the bundled list.
  • Discovery spawns a saved agent command as one program name and does not pass saved arguments, so an agent saved as codex --profile work falls back to the bundled list.
  • discoverModels returns as soon as session/new lists any option; an agent that announces its model option later would fall back to the bundled list. None of the five chat agents does this.

How I tested it

Desktop dev app driven over CDP, with chat on and with chat off:

  • Host API: agents.models for all 23 presets on both surfaces; launches with unknown, malformed and over-long model ids rejected; an unlisted well-formed Codex id passed to the CLI.
  • Picker walk over all 20 visible agents in both modes; search, provider chips, favorites, "Show all models".
  • Chat launches with a picked model for Claude, Codex, OpenCode and Pi, each replying on that model; model switch inside a running session for Claude, Codex and Pi.
  • Terminal launches with the command line read from the process: Claude, Codex, OpenCode, Cursor, Gemini, Copilot. OpenCode and Cursor used models that exist only in the discovered list.
  • Codex inside a project, as chat and as terminal.
  • A remembered pick across a reload and across a chat on/off change.
  • A host that does not answer agents.models: bundled lists, no error.

Mobile on the iOS simulator: model sheet and pinned releases with chat off, launch ran claude --model claude-sonnet-5-5; Codex sheet with its default hint with chat on, chat launch replied; Mastracode absent from the agent list.

Not run: the mobile edge pass (cold start, offline, large text, other locales); the last mobile change (dropping a stale remembered model) on the simulator, which is typechecked only; the on-screen message for an invalid model on a chat launch (unit test only); Android; remote hosts and cloud workspaces.

Checklist

  • PR title follows conventional commits (type(scope): subject)
  • bun run lint and bun run typecheck pass
  • "Allow edits from maintainers" is checked on fork PRs (same-repository branch)
  • I have signed the CLA

Summary by CodeRabbit

  • New Features
    • Model choices can reflect live availability from supported agents, with search, provider filters, loading status, refresh controls, and an option to show all models.
    • Newly discovered models can be selected and used to launch agents. Active chat sessions can also provide model options.
    • Desktop and mobile model preferences retain saved selections even when they’re not in the bundled model list.
  • Improvements
    • Model catalogs fall back to bundled choices when discovery is unavailable, and favorites are shown only when their models are available.
    • Default model labels now read “Default.”
    • Added localized labels and availability messages across supported languages.