Skip to content

feat: filter /switch-model to show only authenticated models#1776

Closed
singbong wants to merge 4 commits intocode-yeongyu:devfrom
singbong:feat/model-switcher
Closed

feat: filter /switch-model to show only authenticated models#1776
singbong wants to merge 4 commits intocode-yeongyu:devfrom
singbong:feat/model-switcher

Conversation

@singbong
Copy link

@singbong singbong commented Feb 11, 2026

Problem

Currently, the /switch-model command displays all available models from model_candidates configuration, regardless of whether they are connected via auth login or not.

This causes confusion and potential issues:

  1. Users may try to use models that aren't connected/authenticated
  2. No indication of which models are actually available in current session
  3. Security/privacy concern: showing models from different providers

Solution

Add authentication-aware filtering to /switch-model command to only show and allow switching to models that are connected/authenticated in the current OpenCode session.

Implementation Plan

  1. Add OpenCode client API call

    • Use OpenCode SDK to get connected providers/models
    • Filter model_candidates based on availability
  2. Update /switch-model template

    • Show indicator for models that are connected/authenticated
    • Display warning for models that are not available
    • Prevent switching to unavailable models
  3. Add utility functions

    • getAvailableModels(agentName: string): Filter candidates by availability
    • filterAvailableModels(candidates: string[]): Get only available models from list

Usage

/switch-model sisyphus
# Shows only models that are connected/authenticated
# Example output:
# sisyphus (✓ 2 models available)
#   1. zai-coding-plan/glm-4.7 (active)
#   2. google/antigravity-claude-opus-4-6-thinking (connected)
#   3. cursor-acp/gpt-5.2 (not connected) ⚠

Breaking Changes

None. This adds filtering only; existing functionality remains unchanged.

Technical Notes

  • Need to check OpenCode SDK for authentication/status APIs
  • May need to use getConnectedProviders() or similar
  • Consider caching availability status for performance

Summary by cubic

Add session-scoped model switching with a new /switch-model command and runtime overrides, so agents can switch to valid, configured models without touching config files.

  • New Features

    • Added /switch-model command: list current assignments, show candidates per agent, and switch when the model is in that agent’s model_candidates.
    • Runtime model switcher state: getActiveModel, setActiveModel, getCandidates, getCurrentModelInfo.
    • Integrated overrides into Sisyphus, Hephaestus, and Atlas; they auto-use the active session model.
    • Config: added model_candidates to agent overrides; JSON schema updated; backward compatible.
    • Included unit tests for the model switcher.
  • Dependencies

    • Bumped oh-my-opencode platform binaries to 3.5.2 in bun.lock.
    • Updated schema build to use Zod 4’s toJSONSchema.

Written for commit 530a571. Summary will update on new commits.

- Added model_candidates: z.array(z.string()).optional() to AgentOverrideConfigSchema
- Updated JSON schema generation (build-schema.ts uses correct Zod 4 method)
- Maintains backward compatibility (field is optional)
- JSON schema now includes model_candidates field

Preparation for Task 3: Runtime state management module
…l override

- createSisyphusAgent: add agentName?: string parameter
- createHephaestusAgent: add agentName?: string parameter
- createAtlasAgent: add agentName to OrchestratorContext
- Each create function uses getActiveModel(agentName) for override
- Builtin-agents pass agentName when creating agents

This enables runtime model switching for Sisyphus, Hephaestus, and Atlas
through getActiveModel() integration with the model-switcher state module.
- Add switch-model command template with model switching instructions
- Update BuiltinCommandName type to include 'switch-model'
- Update BuiltinCommandNameSchema enum to include 'switch-model'
- Add switch-model to BUILTIN_COMMAND_DEFINITIONS with argumentHint

The command provides:
- Current model assignments display for all agents
- Model candidates listing for specific agents
- Model switching instructions
- Validation for model candidates
- Clear error messages for invalid models

Template includes detailed instructions for parsing arguments,
getting current model info, validating inputs, and performing
model switches using model-switcher APIs.
- Test loadCandidates() parsing with/without/empty model_candidates
- Test setActiveModel() and getActiveModel() override functionality
- Test getCandidates() and getCurrentModelInfo() state queries
- Test backward compatibility (config without model_candidates)
- Test invalid agent name handling
- 12 test cases all passing

Tests use unique agent names to avoid singleton state interference
between test cases.
@github-actions
Copy link
Contributor

Thank you for your contribution! Before we can merge this PR, we need you to sign our Contributor License Agreement (CLA).

To sign the CLA, please comment on this PR with:

I have read the CLA Document and I hereby sign the CLA

This is a one-time requirement. Once signed, all your future contributions will be automatically accepted.


I have read the CLA Document and I hereby sign the CLA


You can retrigger this bot by commenting recheck in this Pull Request. Posted by the CLA Assistant Lite bot.

Copy link

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

1 issue found across 25 files

Confidence score: 4/5

  • This PR looks safe to merge, with the main risk coming from test reliability rather than production behavior.
  • Shared mutable state in src/features/model-switcher/model-switcher.test.ts could cause flaky or order-dependent tests if run in parallel or with other suites.
  • Pay close attention to src/features/model-switcher/model-switcher.test.ts - shared mutable state without isolation or cleanup.
Prompt for AI agents (all issues)

Check if these issues are valid — if so, understand the root cause of each and fix them.


<file name="src/features/model-switcher/model-switcher.test.ts">

<violation number="1" location="src/features/model-switcher/model-switcher.test.ts:1">
P2: Shared mutable state in tests without isolation or cleanup mechanism</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

@@ -0,0 +1,169 @@
import { describe, expect, test } from "bun:test"
Copy link

@cubic-dev-ai cubic-dev-ai bot Feb 11, 2026

Choose a reason for hiding this comment

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

P2: Shared mutable state in tests without isolation or cleanup mechanism

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At src/features/model-switcher/model-switcher.test.ts:

<comment>Shared mutable state in tests without isolation or cleanup mechanism</comment>

<file context>
@@ -0,0 +1,169 @@
+import { describe, expect, test } from "bun:test"
+import type { AgentOverrides } from "../../agents/types"
+
+import {
+  getCurrentModelInfo,
+  getCandidates,
+  getActiveModel,
+  setActiveModel,
+  loadCandidates,
</file context>
Fix with Cubic

@singbong singbong closed this Feb 11, 2026
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