Skip to content

feat(ai): discover models from installed tools instead of hand-maintained lists - #1593

Merged
backnotprop merged 3 commits into
mainfrom
feat/discovered-model-catalog
Sep 22, 2026
Merged

backnotprop merged 3 commits into
mainfrom
feat/discovered-model-catalog

Conversation

@backnotprop

@backnotprop backnotprop commented Sep 22, 2026 •

Copy link
Copy Markdown
Owner

Problem

The Claude and Codex model lists were maintained by hand and had gone stale. Opus 5.5 (claude-opus-5-5) and Fable 5.1 (claude-fable-5-1) could not be picked in Ask AI or in the code-review agent launcher. The review default was still claude-opus-5. The Codex launchers used their own hand list, which did not include gpt-6-astra, the model Codex currently marks as its default. Claude effort levels were offered for every model, including Haiku, which takes none. Saved launcher choices were never checked, so a stale id was launched anyway.

Design

  • The installed tool supplies the list. Claude's list comes from the Agent SDK's supportedModels(), run against the user's installed claude. Codex's list comes from the existing app-server model/list. Cursor, OpenCode, Pi, and Copilot were already discovered and are unchanged.

  • Discovery is lazy. Claude discovery sits behind the same deferred provider initializer Codex and OpenCode already use (/api/ai/capabilities?activate=<id>, or the first session). It never runs at server startup or on page load. It is capped (Claude 10s, Codex 6s) and keeps the fallback list on any failure. A success is kept for the life of the process; a failure may be retried by a later activation after 60s, so a transient failure does not pin the fallback and a broken CLI is not re-spawned on every session. Both Bun and Pi runtimes register it the same way. No new endpoint was added.

  • One list per provider. A single shape, CatalogModel in @plannotator/core/model-catalog, carries id, label, efforts with a default effort, fast-mode support, and resolvedId. Ask AI and the launchers read the same answer. The launchers get it through the new useModelCatalogs hook, which fetches the same ?activate= response for the one engine the launcher is set to, and only when that CLI is installed. Opening the Agents panel set to Claude starts only claude. Viewing a saved guide loads nothing unless the guide is outdated and offers Regenerate. A successful fetch is shared across the page; a failed one is retried the next time a surface asks.

  • The Claude catalog. It is built from supportedModels(). Alias rows name the model and version they resolve to today: "Opus 5.5 (latest)", "Opus 5.5 1M (latest)", "Sonnet 5 (latest)", "Fable 5.1 (latest)", "Haiku 4.5 (latest)". The version comes from the SDK's resolvedModel, parsed by claudeModelVersion (for example claude-haiku-4-5-20251001 gives 4.5). The SDK's displayName carries no version ("Opus (1M context)", "Sonnet" against claude 2.1.280), so resolvedModel is the source. An unparseable or missing id keeps the plain label ("Sonnet (latest)"). Every picker, Ask AI, and the job cards read this same label. Pinned ids keep the model name from the description, marked when they are 1M-context ("Fable 5.1 (1M)"). The SDK's default row is dropped because it points at another model rather than being one. A bare latest alias (opus, sonnet, fable, haiku) is added for each family the tool offers, with the same efforts and fast-mode support as that family's first row. The aliases are added so the launcher defaults are always pickable.

  • Defaults come from the tool. Claude review defaults to opus; tour and guide keep sonnet. Codex surfaces default to '', which means the model Codex's own list marks as default. Ask AI's Claude default is sonnet.

  • One resolver for every surface. resolveModelChoice in core is used by the launchers, by Ask AI's client (aiProvider.ts), and by the AI session endpoint. A saved pick resolves in this order:

    1. The pick itself, when the list offers it.
    2. The alias whose resolvedId covers it (claude-sonnet-5 becomes sonnet).
    3. The same family's alias (claude-opus-5 or claude-opus-5-5 becomes opus; claude-sonnet-4-6 becomes sonnet; claude-fable-5 becomes fable).
    4. The surface default, then the list's default.

    A saved Claude pin therefore never silently switches model family. Resolution also never moves a pick onto a [1m] id unless the pick itself was one: claude-fable-5-1 becomes fable, not claude-fable-5-1[1m]. Saved picks are resolved when read; the cookie is never rewritten. Efforts are clamped to the model's own levels, and a model with no efforts sends none. Fast mode is shown only for models that offer it. When resolution replaces a saved Codex model with a different one, fast mode is turned off: a retired pick saved with fast on does not launch its replacement with service_tier=fast. A saved '' (Codex's own default) is not a replacement, so it keeps fast mode. Claude and Codex launches are disabled until the catalog settles, and a "Loading models…" row replaces the picker meanwhile, so a launch never uses a pick that has not been resolved. The catalog always settles, on the fallback list if discovery fails. Job cards take their model labels from the discovered list.

  • Ask AI Claude effort. Ask AI now forwards the chosen effort to the Claude SDK (effort). The AI endpoint forwards an effort only when the resolved model lists it.

  • One small fallback per provider. Claude: opus, sonnet, fable, haiku, claude-fable-5-1, claude-opus-5-5, claude-sonnet-5, claude-haiku-4-5. Codex: gpt-5.6-sol, gpt-5.5.

SDK verification (measured before building)

  • Uses the installed CLI. With pathToClaudeCodeExecutable set (the AI runtime already passes Bun.which("claude")), the list matches the installed claude 2.1.280: opus resolves to claude-opus-5-5. The SDK's bundled 2.1.260 copy returns an older mapping (claude-opus-5), so using the installed CLI matters.
  • Cost. One throwaway claude process, no prompt, closed after the initialize handshake. It took about 0.5s per run over 3 runs, with settingSources: [] and strictMcpConfig: true. With default settings it took about 1s and ran the user's SessionStart hook and loaded MCP servers, which is why discovery passes those two options. The process is gone afterwards (checked with pgrep).
  • Side effects (known and accepted):
    • The discovery spawn writes .claude.json in the Claude config dir, as any claude start does.
    • settingSources: [] suppresses user and project settings, but not managed-policy hooks. An enterprise policy hook would still run once per discovery.
    • Bedrock env set only in settings.json is not visible to discovery. This is harmless because the ids it returns are aliases, which the Bedrock path already maps.
  • No auth needed. With an empty CLAUDE_CONFIG_DIR it returned in about 0.2s. A missing executable fails in milliseconds and keeps the fallback list; a test covers this.
  • Current models. Returned: default, opus[1m], claude-fable-5-1[1m], sonnet, haiku. I confirmed that the CLI accepts --model opus (gives claude-opus-5-5), --model claude-fable-5-1, and --model default.
  • Codex. model/list took about 25–470ms and returned gpt-6-astra (default), gpt-5.6-sol, gpt-5.6-terra, gpt-5.6-luna, and gpt-5.5. Each entry includes its efforts and default effort, and fast support through additionalSpeedTiers.

Removed

  • packages/ui/utils/codexModels.ts: the hand-maintained Codex catalog and its effort ladders.
  • Breaking @plannotator/ui 0.46.0 export changes for hosts (also listed in packages/ui/HANDOFF.md):
    • Module utils/codexModels removed (CODEX_MODELS, CODEX_EFFORT_LABELS, codexReasoningOptions, clampCodexReasoning).
    • CLAUDE_MODELS, CLAUDE_EFFORT, TOUR_CLAUDE_MODELS, CODEX_MODELS, and codexReasoningOptions removed from components/AgentsTab.
    • sanitizeCodexPerModel and migrateCodexSection removed from hooks/useAgentSettings.
    • DEFAULT_CODEX_MODEL (and the tour/guide Codex defaults) are now '', meaning Codex's own default. DEFAULT_CLAUDE_MODEL is now 'opus'.
    • AIProviderModel is now an alias of CatalogModel.
  • The Claude Agent SDK provider's static model list.
  • The Codex RENAMED_CODEX_MODELS / RETIRED_CODEX_MODELS maps and sanitizeCodexPerModel / migrateCodexSection. Removing them is safe: read-time resolution and effort clamping cover every case they handled (retired or renamed ids fall back to the default; none/minimal efforts clamp to the model's default). Launch is blocked until the catalog settles, so an unresolved value can never reach the CLI.
  • The tests that pinned those hand lists (AgentsTab.test.ts and most of useAgentSettings.test.ts).
  • Docs no longer list models. They say the pickers show what the installed tools offer.

Versions: @plannotator/core 0.25.6 (new ./model-catalog subpath), @plannotator/ui 0.46.0. The Pi vendor step now copies model-catalog.ts into generated/ai/.

Test evidence

  • bash apps/pi-extension/vendor.sh: OK
  • bun run typecheck: clean
  • bun run --cwd packages/ui smoke:package: @plannotator/[email protected] installs externally with @plannotator/[email protected]
  • bun test (latest commit): 5000 pass, 1186 skip, 0 fail (6186 tests, 539 files)
  • DOM steps: file browser 6 pass; diff renderer 11 pass; UI seam + DOM (--isolate, 173 files, including the new useModelCatalogs.dom.test.tsx) 1269 pass, 0 fail; allowlist guard 1 pass
  • Version labels: claudeModelVersion parses major.minor and ignores date and [1m] suffixes; alias labels match the measured SDK payload; unparseable ids keep the plain label.
  • Codex fast mode: a replaced pick drops fast; the saved model itself and the tool default keep it.
  • Headless check on the latest build:
    • The Claude picker lists Opus 5.5 (latest), Fable 5.1 (latest), Opus 5.5 1M (latest), Fable 5.1 (1M), Sonnet 5 (latest), Haiku 4.5 (latest).
    • Ask AI shows Claude · Sonnet 5 (latest) · High.
    • With Codex 0.155.1, the picker lists GPT-6-Sol (default), GPT-6-Astra, GPT-6-Luna, GPT-5.6-Sol, GPT-5.6-Terra, GPT-5.6-Luna, and GPT-5.5.
    • A saved gpt-5.3-codex with fast on resolves to GPT-6-Sol, with fast mode off.
  • guides.show viewer rebuilt and manifest synced: no change (the viewer bundle is not affected)
  • New tests, all stubbed with no network:
    • Claude catalog mapping on the measured SDK payload: pointer row dropped, aliases added, labels, per-model efforts, single default
    • Codex model/list mapping
    • resolveModelChoice / resolveEffortChoice
    • The fallback lists are well formed
    • A failing claude keeps the fallback and does not throw
    • Both runtimes keep Claude discovery behind the initializer (source check)
    • The AI endpoint forwards only efforts the model accepts
    • The launcher catalog fetch: single request, provider lookup, fallback on failure
    • Launcher resolution: no reconciling while the catalog is loading; stale picks resolve and efforts clamp once it settles
    • The shared resolver keeps family (claude-opus-5-5 becomes opus, claude-sonnet-4-6 becomes sonnet) and never crosses the [1m] boundary
    • Ask AI's client uses the same resolver
    • The once-wrapper retries only after its cooldown
    • A failed client fetch is retried on the next request
    • A launcher fetches only its selected engine's catalog (DOM test)
  • Manual end-to-end run with the real CLIs and headless Chromium against plannotator review from source (temp data dir, no browser opened):
    • Page load makes no ?activate= requests.
    • Opening Review Agents makes exactly one each for Claude and Codex.
    • The Claude picker shows Opus (latest), Fable (latest), Opus 5.5 with 1M context, Fable 5.1, Sonnet 5, and Haiku 4.5, with High as the default effort. Haiku shows no effort control.
    • The Codex picker defaults to GPT-6-Astra, with Low through Ultra and Fast mode.
    • Ask AI shows Claude · Sonnet 5 · High.
    • A real Ask AI session ran on Haiku with no effort and on Sonnet with effort low.
    • After the fixes, with a saved review pick of claude-fable-5-1: page load makes no activation requests. Opening Agents (set to Claude) makes exactly one request, ?activate=claude-agent-sdk, and no Codex request. The picker shows "Loading models…", then Fable (latest).

Risks

  • Existing launcher picks move to the latest model of their family. A saved id the installed CLI no longer lists moves to its family's latest alias; for example, the old claude-opus-5 default becomes opus, which is Opus 5.5 today. It never moves to another family or to a 1M-context variant. Only ids with no recognizable family fall back to the surface default.
  • Codex's default is now its own pick. A user who never chose a Codex model gets the model Codex marks default. Cookies written by older builds that stored gpt-5.5 keep gpt-5.5.
  • A slow first launch waits briefly. If the tool is broken, the first launch waits for discovery (Claude up to 10s, then the fallback list). Normally this takes about 0.5s.
  • Bedrock/Vertex. Discovery reflects what the CLI reports in that environment. resolveSDKModel still maps family aliases for Ask AI; claude-fable-5-1[1m] has no family env var there and falls back to ANTHROPIC_MODEL, as before.
  • SDK/CLI protocol drift. A future CLI whose initialize handshake an older SDK cannot read would fall back to the static list, not break anything.
  • Publishing. Publish @plannotator/core 0.25.6 before @plannotator/ui 0.46.0.

…ined lists

Claude models come from the Agent SDK's supportedModels() against the
installed claude; Codex models from the app-server model/list. Discovery is
lazy (first picker or session), bounded, cached per process, and falls back
to one small static list per provider in @plannotator/core/model-catalog.

Ask AI and the review / Code Tour / Guided Review launchers now share that
one list. Launchers resolve saved picks against it at read time, offer only
the efforts (and fast mode) the selected model supports, and default to the
opus/sonnet aliases (Claude) and the model Codex marks default. Removes the
hand-maintained Claude/Codex launcher catalogs and the Codex rename/retire
migrations. core 0.25.6, ui 0.46.0.
…ntext window

- resolveModelChoice (core) is now the only resolver: launchers, Ask AI's
  client and the AI session endpoint all use it. Order: exact id, the alias
  whose resolvedId covers it, the same family's alias, the surface default,
  the catalog default. It never moves a pick onto a [1m] id unless the pick
  was one.
- Failed discovery is retried: providers' fetchModels reject on failure and
  createBestEffortOnce allows a retry after 60s; the client forgets a failed
  catalog fetch.
- Launchers fetch only the selected engine's catalog; viewing a saved guide
  loads nothing unless it offers Regenerate.
- Job cards label models from the discovered catalog; aliases read
  '<Family> (latest)'; a loading row replaces the empty picker.
- Dedupe the deferred-discovery wiring in both ai-runtimes; drop the
  redundant modelsLoaded flags.
- HANDOFF.md lists the ui 0.46.0 breaking export removals.
… replaced Codex pick

- Alias rows name the model they resolve to today ("Opus 5.5 (latest)",
  "Sonnet 5 (latest)", "Opus 5.5 1M (latest)"), parsed from the SDK's
  resolvedModel by claudeModelVersion (the displayName carries no version);
  unparseable ids keep the plain label. Every picker, Ask AI and job cards
  read the same catalog label.
- When resolution replaces a saved Codex model with a different one, fast
  mode is off: a retired pick saved with fast on no longer launches the
  replacement with service_tier=fast.
@backnotprop
backnotprop merged commit e42e0e3 into main Sep 22, 2026
19 checks passed
@backnotprop
backnotprop deleted the feat/discovered-model-catalog branch September 22, 2026 21:18
backnotprop added a commit that referenced this pull request Sep 22, 2026
…1595)

* fix: v0.27.18 QA regressions in PR drafts and discovered model catalogs

- review: a comment on a PR whose snapshot the page has not seen (after a
  reload) posts inline again; only anchor-checked comments get the Outdated
  label (#1592)
- review: restoring a draft after a push no longer re-marks changed files
  Viewed; the platform-path status post carries draftGeneration
- catalog: always offer opus/sonnet/haiku, reading the default row's family
  and version, so Claude Code 2.1.141 no longer drops Opus (#1593)
- settings: Codex Fast/reasoning re-key to the shown model when the saved one
  was replaced
- codex: read fast mode from serviceTiers (priority/fast)
- ai: Claude sessions no longer wait on model discovery (Bun + Pi share
  createDeferredModelDiscovery); capabilities mark modelsSource so the client
  retries a fallback answer

* fix(ai): wait for discovery when the fallback lacks the requested Claude model

A first Claude session resolved opus[1m] / claude-fable-5-1[1m] onto the
fallback's opus / fable (another context window and billing than later
sessions). In session mode the session now waits for discovery when the list
is still the fallback and does not offer the pick; picks the fallback offers
stay instant. Also stop reading a context size ("Opus 1M context") as the
default row's version.
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