Skip to content

refactor: unify model selection with the TUI - #387

Merged
chriswritescode-dev merged 1 commit into
feat/session-fusion-and-walkthroughsfrom
refactor/unify-model-picker
Oct 7, 2026
Merged

chriswritescode-dev merged 1 commit into
feat/session-fusion-and-walkthroughsfrom
refactor/unify-model-picker

Conversation

@chriswritescode-dev

@chriswritescode-dev chriswritescode-dev commented Oct 7, 2026 •

Copy link
Copy Markdown
Owner

Summary

Aligns the manager's model selection with the OpenCode TUI so every surface - chat, schedules, agents, and the goal auditor - reads and writes the same model preferences.

  • Shared TUI-compatible model-preference module; the backend model.json store now matches the TUI format and owns the effective default and variants.
  • One frontend provider catalog (array Provider), one availability check, one model-ref formatter, and one variant-persistence path replace the previous per-surface implementations.
  • A shared useModelSections hook and buildModelSections drive the model lists in chat, schedules, agents, and the goal auditor with TUI ordering; the chat ModelQuickSelect lists models the TUI way.
  • A shared ModelCombobox (taller list) is used by schedules and the agent editor.
  • Adds a shared isRecord util and model-selection comparison helpers.

Type of Change

  • Bug fix
  • New feature
  • Refactor
  • Documentation

Checklist

  • Code follows project style (no comments, named imports)
  • TypeScript types are properly defined
  • Tests added/updated (80% coverage target)
  • pnpm lint passes locally
  • pnpm typecheck passes locally

pnpm typecheck passes for cli, frontend and backend. pnpm lint reports 0 errors (41 pre-existing no-explicit-any warnings, plus one pre-existing exhaustive-deps warning in ChangesWalkthroughDialog). Focused suites pass: backend providers, opencode-model-state, opencode-model-preference, opencode-model-ref (92 tests) and frontend model/combobox/providers/schedules/agent/session suites (359 tests).

Summary by CodeRabbit

  • New Features
    • Added model selection across provider catalogs, including model variants, favorites, recents, and server-default options.
    • Added searchable model pickers for sessions, agents, schedules, and automation settings.
    • Model choices now adapt to the selected session and agent, with clearer defaults and provider labels in search results.
  • Bug Fixes
    • Prevented prompt submission when the selected model is not ready.
    • Improved model and agent switching so session selections stay in sync.
    • Preserved model preference data when saving variants or favorites.

Align the manager's model selection with the OpenCode TUI: one
model.json-backed preference store, one provider catalog, one ordering
and default-ownership rule, and one set of availability, ref-formatting
and variant helpers shared across chat, schedules, agents and the goal
auditor.

- Add a shared TUI-compatible model-preference module and make the
  backend model.json store match its format.
- Consolidate the frontend provider catalog, availability check, model
  ref formatter and variant persistence into single owners.
- Drive chat, schedule, agent and goal-auditor model lists from a shared
  useModelSections hook and buildModelSections, following TUI ordering.
- Extract a shared ModelCombobox with a taller list, and list models the
  TUI way in ModelQuickSelect.
- Add a shared isRecord util and model-selection comparison helpers.
@coderabbitai

coderabbitai Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 8fecdb2c-0bc8-411b-9180-46df7007886b
📥 Commits

Reviewing files that changed from the base of the PR and between 3d14356 and 65b72e5.

📒 Files selected for processing (82)
  • backend/src/routes/providers.test.ts
  • backend/src/routes/providers.ts
  • backend/src/services/opencode-model-state.ts
  • backend/src/services/opencode-models.ts
  • backend/test/services/opencode-model-state.test.ts
  • backend/test/shared/opencode-model-preference.test.ts
  • backend/test/shared/opencode-model-ref.test.ts
  • frontend/src/api/providers.test.ts
  • frontend/src/api/providers.ts
  • frontend/src/components/message/MessageThread.tsx
  • frontend/src/components/message/PromptInput.command.test.tsx
  • frontend/src/components/message/PromptInput.goal.test.tsx
  • frontend/src/components/message/PromptInput.mention.test.tsx
  • frontend/src/components/message/PromptInput.stt.test.tsx
  • frontend/src/components/message/PromptInput.tsx
  • frontend/src/components/model/ApiKeyDialog.test.tsx
  • frontend/src/components/model/ApiKeyDialog.tsx
  • frontend/src/components/model/ModelCombobox.test.tsx
  • frontend/src/components/model/ModelCombobox.tsx
  • frontend/src/components/model/ModelQuickSelect.test.tsx
  • frontend/src/components/model/ModelQuickSelect.tsx
  • frontend/src/components/repo/FuseRunDialog.test.tsx
  • frontend/src/components/repo/FuseRunDialog.tsx
  • frontend/src/components/repo/ModelCheckboxList.tsx
  • frontend/src/components/repo/MultiRunDialog.test.tsx
  • frontend/src/components/repo/MultiRunDialog.tsx
  • frontend/src/components/schedules/GeneralTab.tsx
  • frontend/src/components/schedules/JobDetailTab.tsx
  • frontend/src/components/schedules/ScheduleJobDialog.assistant.test.tsx
  • frontend/src/components/schedules/ScheduleJobDialog.loading.test.tsx
  • frontend/src/components/schedules/ScheduleJobDialog.mcp.test.tsx
  • frontend/src/components/schedules/ScheduleJobDialog.model.test.tsx
  • frontend/src/components/schedules/ScheduleJobDialog.permissions.test.tsx
  • frontend/src/components/schedules/ScheduleJobDialog.providers.test.tsx
  • frontend/src/components/schedules/ScheduleJobDialog.tsx
  • frontend/src/components/settings/AgentDialog.test.tsx
  • frontend/src/components/settings/AgentDialog.tsx
  • frontend/src/components/settings/GeneralSettings.test.tsx
  • frontend/src/components/settings/ProviderSettings.test.tsx
  • frontend/src/components/settings/ProviderSettings.tsx
  • frontend/src/components/settings/SessionAutomationSettings.test.tsx
  • frontend/src/components/settings/SessionAutomationSettings.tsx
  • frontend/src/components/ui/combobox.test.tsx
  • frontend/src/components/ui/combobox.tsx
  • frontend/src/contexts/EventContext.test.tsx
  • frontend/src/hooks/useContextUsage.ts
  • frontend/src/hooks/useModelSections.test.ts
  • frontend/src/hooks/useModelSections.ts
  • frontend/src/hooks/useModelSelection.test.tsx
  • frontend/src/hooks/useModelSelection.ts
  • frontend/src/hooks/useOpenCode.ts
  • frontend/src/hooks/useProviders.ts
  • frontend/src/hooks/useProvidersWithModels.test.tsx
  • frontend/src/hooks/useProvidersWithModels.ts
  • frontend/src/hooks/useRemoveMessage.test.ts
  • frontend/src/hooks/useScheduleModels.ts
  • frontend/src/hooks/useSendPrompt.test.ts
  • frontend/src/hooks/useSessionAgent.ts
  • frontend/src/hooks/useVariants.test.tsx
  • frontend/src/hooks/useVariants.ts
  • frontend/src/lib/modelCatalog.test.ts
  • frontend/src/lib/modelCatalog.ts
  • frontend/src/lib/modelSections.test.ts
  • frontend/src/lib/modelSections.ts
  • frontend/src/lib/queryInvalidation.test.ts
  • frontend/src/lib/queryInvalidation.ts
  • frontend/src/lib/schedules/schedule-model.test.ts
  • frontend/src/lib/schedules/schedule-model.ts
  • frontend/src/pages/SessionDetail.tsx
  • frontend/src/pages/__tests__/SessionDetail.assistant-loading.test.tsx
  • frontend/src/pages/__tests__/SessionDetail.commands.test.tsx
  • frontend/src/pages/__tests__/SessionDetail.form-prompt.test.tsx
  • frontend/src/pages/__tests__/SessionDetail.polling.test.tsx
  • frontend/src/pages/__tests__/SessionDetail.scroll-floating.test.tsx
  • frontend/src/stores/modelStore.test.ts
  • frontend/src/stores/modelStore.ts
  • shared/src/opencode/index.ts
  • shared/src/opencode/mcp.ts
  • shared/src/opencode/modelPreference.ts
  • shared/src/opencode/modelRef.ts
  • shared/src/utils/index.ts
  • shared/src/utils/record.ts
💤 Files with no reviewable changes (4)
  • frontend/src/lib/queryInvalidation.ts
  • frontend/src/hooks/useProvidersWithModels.test.tsx
  • frontend/src/components/schedules/ScheduleJobDialog.providers.test.tsx
  • frontend/src/hooks/useProvidersWithModels.ts

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.


📝 Walkthrough

Walkthrough

The change centralizes model preferences and reference handling in shared OpenCode utilities. It updates backend model-state routes, replaces the provider catalog shape, adds session-aware model selection, and integrates the catalog and selection controls into model pickers, settings, schedules, and prompt submission.

Changes

Model preferences and catalog

Layer / File(s) Summary
Shared preference rules and backend persistence
shared/src/opencode/*, shared/src/utils/*, backend/src/routes/providers.ts, backend/src/services/opencode-model-state.ts, backend/src/services/opencode-models.ts, backend/test/shared/*, backend/test/services/opencode-model-state.test.ts, backend/src/routes/providers.test.ts
Shared helpers now decode and update recent models, favorites, variants, and model references. Backend reads and updates use the shared preference types. The route accepts variant updates, and model resolution uses shared lookup and selection helpers.
Provider catalog and model sections
frontend/src/api/providers.ts, frontend/src/api/providers.test.ts, frontend/src/lib/modelCatalog.ts, frontend/src/lib/modelSections.ts, frontend/src/hooks/useModelSections.ts, frontend/src/hooks/useProviders.ts, frontend/src/lib/queryInvalidation.ts, frontend/src/contexts/EventContext.test.tsx, frontend/src/lib/*test.ts, frontend/src/hooks/useModelSections.test.ts
The provider API returns sorted provider and model arrays, configured and server-default model references, and variant-saving support. Shared section helpers build default, favorite, recent, and provider sections, and filter catalog results.
Session selection and variant state
frontend/src/stores/modelStore.ts, frontend/src/hooks/useModelSelection.ts, frontend/src/hooks/useVariants.ts, frontend/src/hooks/useOpenCode.ts, frontend/src/hooks/useSessionAgent.ts, frontend/src/stores/modelStore.test.ts, frontend/src/hooks/useModelSelection.test.tsx, frontend/src/hooks/useVariants.test.tsx, frontend/src/hooks/useRemoveMessage.test.ts, frontend/src/hooks/useSendPrompt.test.ts
The store keeps new-session and per-session agent picks. Hooks resolve catalog-backed selections and variants, record recent models, and update preferences. Session synchronization switches the agent before the model.
Model selection controls
frontend/src/components/model/ModelCombobox.tsx, frontend/src/components/model/ModelQuickSelect.tsx, frontend/src/components/ui/combobox.tsx, frontend/src/components/model/*test.tsx, frontend/src/components/ui/combobox.test.tsx
ModelCombobox maps model sections to combobox options. ModelQuickSelect uses catalog sections for browsing and search. Combobox adds custom filtering and list styling, and commits custom values only while the user is typing.
Application integrations
frontend/src/components/message/*, frontend/src/components/repo/*, frontend/src/components/schedules/*, frontend/src/components/settings/*, frontend/src/pages/SessionDetail.tsx, frontend/src/hooks/useContextUsage.ts, frontend/src/hooks/useScheduleModels.ts
Prompt and session flows use the resolved model reference and session selection. Repository dialogs, schedules, and settings use the provider catalog and model controls. Schedule resolution checks model availability against catalog entries.

Priority: ➖ Normal

Estimated code review effort: 5 (Critical) | ~120 minutes

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant PromptInput
  participant useModelSelection
  participant modelStore
  participant useSendPrompt
  participant useOpenCode
  PromptInput->>useModelSelection: passes session and active agent
  useModelSelection->>modelStore: reads session and new-session picks
  modelStore-->>useModelSelection: returns stored picks
  useModelSelection-->>PromptInput: returns resolved model reference
  PromptInput->>useSendPrompt: submits the selected model
  useSendPrompt->>useOpenCode: synchronizes agent and model
Loading

Merge Risk: ⚪ Minimal · up to 65b72

This refactor unifies model selection across chat, schedules, agents, and the goal auditor. No concrete defect was established in the changed code, and the change appears ready to merge after normal checks.

🚥 Pre-merge checks | ✅ 4 | ❓ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ❓ Inconclusive Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 62 functions across 50 files. (28 skipped:… Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: aligning model selection with the TUI.
Description check ✅ Passed The description follows the template and includes a clear summary, change type, completed checklist, and test results.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 62 functions across 50 files. (28 skipped: 28 over the file limit.)

✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@chriswritescode-dev
chriswritescode-dev merged commit a81c0be into main Oct 7, 2026
2 checks passed
@chriswritescode-dev
chriswritescode-dev deleted the refactor/unify-model-picker branch October 7, 2026 02:07
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