feat(desktop): add model picker to workspace create dialog

Merged
SV
4mo ago
+471-44

Description

Adds a model dropdown next to the agent picker in the v2 new-workspace dialog so a session can start on a specific model (e.g. claude --model sonnet) without touching the agent's CLI config.

  • The dropdown appears only for agents that support model selection: claude, codex, gemini, copilot, cursor-agent, opencode (via their --model flag) plus the built-in Superset chat agent (via the existing metadata.model → harness.switchModel path). Agents without known model support (amp, pi, droid, mastracode) show no dropdown.
  • First option is Default → no --model flag is passed, the CLI keeps its own default.
  • The last selected model is remembered per agent preset (localStorage map keyed by presetId, so it survives host switches); stale model ids fall back to Default.

Implementation:

  • packages/shared/src/agent-models.ts — curated, hand-maintained per-preset model registry (AGENT_MODEL_SUPPORT, getAgentModelSupport, buildAgentModelArgs) shared by the renderer (dropdown options) and host-service (flag injection).
  • packages/host-service — optional model field on the workspaces.create agent-launch sugar and agents.run; buildAgentCommandString inserts the model args between the base args and the prompt, covering both argv and stdin/heredoc transports, shell-quoted. Unknown preset/model degrades to no flag rather than a broken launch.
  • apps/desktop — new AgentModelSelect pill component (same @superset/ui/select pattern as AgentSelect) and a useAgentModelPreference hook, wired into the dialog's PromptGroup and useSubmitWorkspace. The renderer type for the new field flows automatically from the host router's inferred input type.

Related Issues

Closes #5247

Type of Change

  • Bug fix
  • New feature
  • Documentation
  • Refactor
  • Other (please describe):

Testing

  • Unit tests added: packages/shared/src/agent-models.test.ts (registry validity, arg building) and packages/host-service/src/trpc/router/agents/agents.test.ts (buildAgentCommandString with model args for argv transport, stdin/heredoc transport, empty model args unchanged, shell-quoting of hostile values). Full bun test suites for both packages pass.
  • turbo typecheck green for @superset/shared, @superset/host-service, @superset/desktop; bun run lint exits 0.
  • Manually tested against the local Docker dev stack (setup.local.sh + bun run dev:desktop): Claude + Sonnet launches the terminal with claude --dangerously-skip-permissions --model sonnet '<prompt>'; Default passes no flag; Amp shows no dropdown; the Superset chat agent starts on the selected model; the per-agent choice is restored when reopening the dialog.

Additional Notes

The model lists are intentionally curated and hand-maintained in a single file (agent-models.ts); they will drift with CLI releases and are easy to update. Claude uses the stable opus/sonnet/haiku CLI aliases to minimize drift. Happy to adjust scope, model lists, or placement based on review.


Summary by cubic

Adds a model picker to the new workspace dialog so sessions can start on a specific model without editing CLI configs. Also centralizes the Superset chat model catalog in @superset/shared/agent-models so the picker and chat.getModels stay in sync.

  • New Features

    • Desktop: Added AgentModelSelect next to the agent picker; shown for claude, codex, gemini, copilot, cursor-agent, opencode, and the built-in Superset chat agent. “Default” passes no flag.
    • Preference: Remembers the last selected model per agent preset in localStorage; stale or out‑of‑registry model IDs fall back to Default.
    • Shared (@superset/shared/agent-models): Curated registry and helpers (AGENT_MODEL_SUPPORT, getAgentModelSupport, buildAgentModelArgs) for supported models and CLI flags.
    • Host Service (@superset/host-service): Optional model on workspaces.create and agents.run. For terminal agents, inserts model args between base args and the prompt (argv and stdin/heredoc, shell-quoted). For the Superset chat agent, sets metadata.model.
  • Bug Fixes

    • Rejects model ids outside the curated registry in buildAgentModelArgs, degrading to no flag instead of a broken launch.
    • Guards localStorage writes in the preference hook; quota/security errors only skip persistence.

Open in Stage

Summary by CodeRabbit

  • New Features
    • Added an AI model picker to the new workspace flow, including a “Default” option, and forward the chosen model when launching agents.
    • Persist the last-selected model per preset and restore it on subsequent workspace creations.
    • Enable model-aware agent runs for both chat and terminal executions.
  • Tests
    • Added coverage for curated model support catalogs, model-to-CLI argument construction, and safe model injection/quoting behavior.