Skip to content

feat(tui): /model lists the current provider's live models - #490

Merged
dimetron merged 3 commits into
mainfrom
feat/model-switch-provider
Nov 23, 2026
Merged

dimetron merged 3 commits into
mainfrom
feat/model-switch-provider

Conversation

@dimetron

Copy link
Copy Markdown
Owner

Summary

Bare /model only listed configured roles, so a config with a single default role opened a one-row picker. It now shows the roles followed by every model the current provider serves.

  • /model — roles first, then the current provider's live model list (fetched async, filterable, opens on the active model). Falls back to the roles-only picker, with the error, when the listing fails.
  • /model switch [provider] — one provider's models; the current provider by default.
  • /model provider — pick a configured provider (current first), then one of its models.

Provider selection follows pi's and opencode's selectors, which both offer models across configured providers. Against agentgateway the list already spans every upstream (866 models: openrouter, openai, ollama, mistral, gemini, anthropic, xai, …).

Routing fix

A listed ID must reach its provider verbatim. Resolution strips known <provider>/ prefixes, so picking openai/gpt-5 on agentgateway resolved to gpt-5 and hit the wrong route. buildSwitchedLLMForProvider now prefixes the provider when needed (routedModelName); the RPC/ACP switcher shares it. TestResolveWithoutRoutingPrefixCutsGatewayID pins the bug.

Refactors

  • applySwitchedModel holds the rebuild/persist/report tail shared by role and provider switches.
  • configuredListProviders and sortModelsNewestFirst are extracted from pi model list and reused.
  • openSearchPopupItems opens the popup over caller-built rows; popupCmd lets a popup selection start an async command.

Test plan

  • make build, make test, make lint, go vet
  • Unit tests for bare /model, /model switch, /model provider, role rows, failures, and routing through resolveSwitchedModel
  • Live TUI against local agentgateway: /model shows Models · agentgateway (867), typing deepseek filters to 48
  • Not verified live: chatting after switching to a picked model

Known, not in this PR

  • The / command popup captures typed text in its own search field (prompt stays /, space and Enter-on-no-match swallowed, description matches). Separate fix.
  • After an openrouter switch, the persisted name is re-resolved wrongly on restart (pre-existing).

Bare /model only listed configured roles, so a config with just a default
role opened a one-row picker. It now shows the roles followed by every model
the current provider serves, fetched asynchronously, and falls back to the
roles-only picker when the listing fails.

- /model switch [provider] lists one provider's models (current by default).
- /model provider picks a configured provider, then one of its models.
- Listed IDs keep their routing prefix when switching: agentgateway and
  openrouter serve IDs like openai/gpt-5, which resolution would otherwise cut
  to gpt-5 and send to the wrong route. The RPC switcher shares the fix.

Signed-off-by: pi <dimetron@me.com>
@codecov

codecov Bot commented Nov 22, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.25%. Comparing base (6d236a5) to head (c7281d2).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #490      +/-   ##
==========================================
+ Coverage   92.21%   92.25%   +0.03%     
==========================================
  Files         426      427       +1     
  Lines       57744    57912     +168     
==========================================
+ Hits        53251    53427     +176     
+ Misses       4487     4479       -8     
  Partials        6        6              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Move the TUI's four /model hooks into applyModelSwitching so they can be
driven against a stub gateway, and cover the provider/model popup rendering,
row descriptions and switch guards.

Signed-off-by: pi <dimetron@me.com>

@dimetron dimetron left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codex review of git diff origin/main...HEAD: 7 findings (6 medium, 1 low) — stale async listing results, routing of listed IDs (openrouter namespaces, gemma on gemini, ollama cloud via RPC), openrouter persistence, and initial scroll position.

— Codex review

Comment thread internal/tui/model_switch.go Resolved
Comment thread internal/tui/model_switch.go Resolved
Comment thread internal/cli/interactive.go Resolved
Comment thread internal/cli/interactive.go Resolved
Comment thread internal/cli/interactive.go Resolved
Comment thread internal/cli/cli.go Resolved
Comment thread internal/tui/model_switch.go Resolved
- Drop a listing result superseded by a newer /model, or arriving after a
  run started or another popup opened; remove only its own placeholder.
- Open the picker scrolled so the active model is visible.
- Always prefix listed IDs for routing providers, so openrouter/auto keeps
  its namespace; leave ollama unprefixed so cloud models stay off localhost,
  and restore the RPC switcher's previous name handling.
- With a provider named, fall back to it when detection does not know the
  name (gemma on Gemini, llama3 on Ollama) and let catalog validation decide.
- Save OpenRouter models with their routing prefix so they resolve on restart.

Signed-off-by: pi <dimetron@me.com>
@dimetron

Copy link
Copy Markdown
Owner Author

make vulncheck (after review, on c7281d2)

Pass — no findings with an available fix.

  • Scanner: govulncheck@v1.10.0, Go go1.27.4
  • DB: https://vuln.go.dev, updated 2026-11-11 02:51:11 UTC

9 findings with no fixed version, reported and not failing, all in github.com/ollama/ollama: GO-2025-3557, GO-2025-3558, GO-2025-3559, GO-2025-3582, GO-2025-3689, GO-2025-3695, GO-2025-3824, GO-2025-4251, GO-2026-5750. This PR adds no dependencies.

@dimetron
dimetron merged commit 660b916 into main Nov 23, 2026
15 checks passed
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