fix: resolve ACP model ID mismatch and promote ACP agents as default (#404)
This commit is contained in:
@@ -89,6 +89,7 @@ const (
|
||||
// Model describes a single model available for an agent.
|
||||
type Model struct {
|
||||
ID string `json:"id"`
|
||||
ACPID string `json:"acp_id,omitempty"` // ACP protocol model ID (if different from ID)
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description,omitempty"`
|
||||
Provider string `json:"provider"`
|
||||
@@ -97,6 +98,26 @@ type Model struct {
|
||||
Source string `json:"source,omitempty"` // "static" or "dynamic"
|
||||
}
|
||||
|
||||
// ACPModelID returns the model ID for ACP SetModel. Falls back to ID if ACPID is not set.
|
||||
func (m Model) ACPModelID() string {
|
||||
if m.ACPID != "" {
|
||||
return m.ACPID
|
||||
}
|
||||
return m.ID
|
||||
}
|
||||
|
||||
// ResolveACPModelID finds the ACP model ID for a given profile model ID.
|
||||
// Searches the model list for a matching ID and returns its ACPID.
|
||||
// Returns the original ID if no ACPID mapping exists.
|
||||
func ResolveACPModelID(models []Model, profileModel string) string {
|
||||
for _, m := range models {
|
||||
if m.ID == profileModel && m.ACPID != "" {
|
||||
return m.ACPID
|
||||
}
|
||||
}
|
||||
return profileModel
|
||||
}
|
||||
|
||||
// ToInferenceModel converts a Model to an InferenceModel.
|
||||
func (m Model) ToInferenceModel() InferenceModel {
|
||||
return InferenceModel{
|
||||
|
||||
@@ -49,7 +49,7 @@ func (a *Amp) DisplayName() string { return "Amp" }
|
||||
func (a *Amp) Description() string {
|
||||
return "Sourcegraph Amp CLI-powered autonomous coding agent using stream-json protocol."
|
||||
}
|
||||
func (a *Amp) Enabled() bool { return true }
|
||||
func (a *Amp) Enabled() bool { return false }
|
||||
func (a *Amp) DisplayOrder() int { return 7 }
|
||||
|
||||
func (a *Amp) Logo(v LogoVariant) []byte {
|
||||
|
||||
@@ -47,12 +47,12 @@ func NewAmpACP() *AmpACP {
|
||||
|
||||
func (a *AmpACP) ID() string { return "amp-acp" }
|
||||
func (a *AmpACP) Name() string { return "Amp ACP Agent" }
|
||||
func (a *AmpACP) DisplayName() string { return "Amp (ACP)" }
|
||||
func (a *AmpACP) DisplayName() string { return "Amp" }
|
||||
func (a *AmpACP) Description() string {
|
||||
return "Sourcegraph Amp coding agent using the ACP protocol via the community bridge."
|
||||
}
|
||||
func (a *AmpACP) Enabled() bool { return true }
|
||||
func (a *AmpACP) DisplayOrder() int { return 8 }
|
||||
func (a *AmpACP) DisplayOrder() int { return 7 }
|
||||
|
||||
func (a *AmpACP) Logo(v LogoVariant) []byte {
|
||||
if v == LogoDark {
|
||||
|
||||
@@ -81,7 +81,7 @@ func (a *Auggie) IsInstalled(ctx context.Context) (*DiscoveryResult, error) {
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (a *Auggie) DefaultModel() string { return "sonnet4.5" }
|
||||
func (a *Auggie) DefaultModel() string { return "sonnet4.6" }
|
||||
|
||||
func (a *Auggie) ListModels(ctx context.Context) (*ModelList, error) {
|
||||
models, err := execAndParse(ctx, 30*time.Second, auggieParseModels, "auggie", "model", "list")
|
||||
@@ -181,12 +181,16 @@ var auggiePermSettings = map[string]PermissionSetting{
|
||||
|
||||
func auggieStaticModels() []Model {
|
||||
return []Model{
|
||||
{ID: "sonnet4.5", Name: "Sonnet 4.5", Description: "Great for everyday tasks", Provider: "anthropic", ContextWindow: 200000, IsDefault: true, Source: "static"},
|
||||
{ID: "opus4.5", Name: "Claude Opus 4.5", Description: "Best for complex tasks", Provider: "anthropic", ContextWindow: 200000, Source: "static"},
|
||||
{ID: "haiku4.5", Name: "Haiku 4.5", Description: "Fast and efficient responses", Provider: "anthropic", ContextWindow: 200000, Source: "static"},
|
||||
{ID: "sonnet4", Name: "Sonnet 4", Description: "Legacy model", Provider: "anthropic", ContextWindow: 200000, Source: "static"},
|
||||
{ID: "gpt5.1", Name: "GPT-5.1", Description: "Strong reasoning and planning", Provider: "openai", ContextWindow: 128000, Source: "static"},
|
||||
{ID: "gpt5", Name: "GPT-5", Description: "OpenAI GPT-5 legacy", Provider: "openai", ContextWindow: 128000, Source: "static"},
|
||||
{ID: "sonnet4.6", ACPID: "claude-sonnet-4-6", Name: "Sonnet 4.6", Description: "Latest Sonnet model with improved capabilities", Provider: "anthropic", ContextWindow: 200000, IsDefault: true, Source: "static"},
|
||||
{ID: "sonnet4.5", ACPID: "claude-sonnet-4-5", Name: "Sonnet 4.5", Description: "Great for everyday tasks", Provider: "anthropic", ContextWindow: 200000, Source: "static"},
|
||||
{ID: "opus4.6", ACPID: "claude-opus-4-6", Name: "Opus 4.6", Description: "Best for complex tasks", Provider: "anthropic", ContextWindow: 200000, Source: "static"},
|
||||
{ID: "opus4.5", ACPID: "claude-opus-4-5", Name: "Opus 4.5", Description: "Best for complex tasks", Provider: "anthropic", ContextWindow: 200000, Source: "static"},
|
||||
{ID: "haiku4.5", ACPID: "claude-haiku-4-5", Name: "Haiku 4.5", Description: "Fast and efficient responses", Provider: "anthropic", ContextWindow: 200000, Source: "static"},
|
||||
{ID: "sonnet4", ACPID: "claude-sonnet-4", Name: "Sonnet 4", Description: "Legacy model", Provider: "anthropic", ContextWindow: 200000, Source: "static"},
|
||||
{ID: "gpt5.4", ACPID: "gpt-5-4", Name: "GPT-5.4", Description: "Strong reasoning and planning (free for a limited time)", Provider: "openai", ContextWindow: 128000, Source: "static"},
|
||||
{ID: "gpt5.2", ACPID: "gpt-5-2", Name: "GPT-5.2", Description: "Smarter but slower and more expensive than GPT-5.1", Provider: "openai", ContextWindow: 128000, Source: "static"},
|
||||
{ID: "gpt5.1", ACPID: "gpt-5-1", Name: "GPT-5.1", Description: "Strong reasoning and planning", Provider: "openai", ContextWindow: 128000, Source: "static"},
|
||||
{ID: "gpt5", ACPID: "gpt-5", Name: "GPT-5", Description: "OpenAI GPT-5 legacy", Provider: "openai", ContextWindow: 128000, Source: "static"},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -203,7 +207,7 @@ var auggieModelLineRe = regexp.MustCompile(`^\s*-\s+(.+?)\s+\[(\S+)\]\s*$`)
|
||||
func auggieParseModels(output string) ([]Model, error) {
|
||||
lines := strings.Split(output, "\n")
|
||||
models := make([]Model, 0)
|
||||
defaultModel := "sonnet4.5"
|
||||
defaultModel := "sonnet4.6"
|
||||
|
||||
for i := 0; i < len(lines); i++ {
|
||||
m := auggieModelLineRe.FindStringSubmatch(lines[i])
|
||||
|
||||
@@ -39,20 +39,20 @@ func TestAuggieParseModels(t *testing.T) {
|
||||
Fast and efficient responses
|
||||
- Claude Opus 4.5 [opus4.5]
|
||||
Best for complex tasks
|
||||
- Sonnet 4.5 [sonnet4.5]
|
||||
Great for everyday tasks`,
|
||||
- Sonnet 4.6 [sonnet4.6]
|
||||
Latest Sonnet model`,
|
||||
wantLen: 3,
|
||||
wantIDs: []string{"haiku4.5", "opus4.5", "sonnet4.5"},
|
||||
wantDef: "sonnet4.5",
|
||||
wantIDs: []string{"haiku4.5", "opus4.5", "sonnet4.6"},
|
||||
wantDef: "sonnet4.6",
|
||||
},
|
||||
{
|
||||
name: "models without descriptions",
|
||||
input: `Available models:
|
||||
- Haiku 4.5 [haiku4.5]
|
||||
- Sonnet 4.5 [sonnet4.5]`,
|
||||
- Sonnet 4.6 [sonnet4.6]`,
|
||||
wantLen: 2,
|
||||
wantIDs: []string{"haiku4.5", "sonnet4.5"},
|
||||
wantDef: "sonnet4.5",
|
||||
wantIDs: []string{"haiku4.5", "sonnet4.6"},
|
||||
wantDef: "sonnet4.6",
|
||||
},
|
||||
{
|
||||
name: "empty output returns empty slice",
|
||||
@@ -83,10 +83,10 @@ Another random line`,
|
||||
name: "default model gets IsDefault true",
|
||||
input: ` - Other [other-id]
|
||||
Some model
|
||||
- Sonnet 4.5 [sonnet4.5]
|
||||
- Sonnet 4.6 [sonnet4.6]
|
||||
Default model`,
|
||||
wantLen: 2,
|
||||
wantDef: "sonnet4.5",
|
||||
wantDef: "sonnet4.6",
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@@ -49,12 +49,12 @@ func NewClaudeACP() *ClaudeACP {
|
||||
|
||||
func (a *ClaudeACP) ID() string { return "claude-acp" }
|
||||
func (a *ClaudeACP) Name() string { return "Claude ACP Agent" }
|
||||
func (a *ClaudeACP) DisplayName() string { return "Claude (ACP)" }
|
||||
func (a *ClaudeACP) DisplayName() string { return "Claude" }
|
||||
func (a *ClaudeACP) Description() string {
|
||||
return "Anthropic Claude coding agent using the ACP protocol via the Zed Industries bridge."
|
||||
}
|
||||
func (a *ClaudeACP) Enabled() bool { return true }
|
||||
func (a *ClaudeACP) DisplayOrder() int { return 2 }
|
||||
func (a *ClaudeACP) DisplayOrder() int { return 1 }
|
||||
|
||||
func (a *ClaudeACP) Logo(v LogoVariant) []byte {
|
||||
if v == LogoDark {
|
||||
|
||||
@@ -51,7 +51,7 @@ func (a *ClaudeCode) DisplayName() string { return "Claude" }
|
||||
func (a *ClaudeCode) Description() string {
|
||||
return "Anthropic Claude Code CLI-powered autonomous coding agent using the stream-json protocol."
|
||||
}
|
||||
func (a *ClaudeCode) Enabled() bool { return true }
|
||||
func (a *ClaudeCode) Enabled() bool { return false }
|
||||
func (a *ClaudeCode) DisplayOrder() int { return 1 }
|
||||
|
||||
func (a *ClaudeCode) Logo(v LogoVariant) []byte {
|
||||
@@ -192,10 +192,10 @@ var claudeCodePermSettings = map[string]PermissionSetting{
|
||||
|
||||
func claudeCodeStaticModels() []Model {
|
||||
return []Model{
|
||||
{ID: "claude-sonnet-4-6", Name: "Sonnet 4.6", Description: "Latest Sonnet model for coding and everyday tasks", Provider: "anthropic", ContextWindow: 200000, IsDefault: true, Source: "static"},
|
||||
{ID: "claude-sonnet-4-5", Name: "Sonnet 4.5", Description: "Previous Sonnet generation with strong reasoning", Provider: "anthropic", ContextWindow: 200000, Source: "static"},
|
||||
{ID: "claude-opus-4-6", Name: "Opus 4.6", Description: "Latest and most capable model for complex tasks", Provider: "anthropic", ContextWindow: 200000, Source: "static"},
|
||||
{ID: "claude-opus-4-5", Name: "Opus 4.5", Description: "Most capable model for complex tasks", Provider: "anthropic", ContextWindow: 200000, Source: "static"},
|
||||
{ID: "claude-haiku-4-5", Name: "Haiku 4.5", Description: "Fast and affordable model for simple tasks", Provider: "anthropic", ContextWindow: 200000, Source: "static"},
|
||||
{ID: "claude-sonnet-4-6", ACPID: "sonnet", Name: "Sonnet 4.6", Description: "Latest Sonnet model for coding and everyday tasks", Provider: "anthropic", ContextWindow: 200000, IsDefault: true, Source: "static"},
|
||||
{ID: "claude-sonnet-4-5", ACPID: "sonnet", Name: "Sonnet 4.5", Description: "Previous Sonnet generation with strong reasoning", Provider: "anthropic", ContextWindow: 200000, Source: "static"},
|
||||
{ID: "claude-opus-4-6", ACPID: "default", Name: "Opus 4.6", Description: "Latest and most capable model for complex tasks", Provider: "anthropic", ContextWindow: 200000, Source: "static"},
|
||||
{ID: "claude-opus-4-5", ACPID: "default", Name: "Opus 4.5", Description: "Most capable model for complex tasks", Provider: "anthropic", ContextWindow: 200000, Source: "static"},
|
||||
{ID: "claude-haiku-4-5", ACPID: "haiku", Name: "Haiku 4.5", Description: "Fast and affordable model for simple tasks", Provider: "anthropic", ContextWindow: 200000, Source: "static"},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ func (a *Codex) DisplayName() string { return "Codex" }
|
||||
func (a *Codex) Description() string {
|
||||
return "OpenAI Codex CLI-powered autonomous coding agent using the Codex app-server protocol."
|
||||
}
|
||||
func (a *Codex) Enabled() bool { return true }
|
||||
func (a *Codex) Enabled() bool { return false }
|
||||
func (a *Codex) DisplayOrder() int { return 2 }
|
||||
|
||||
func (a *Codex) Logo(v LogoVariant) []byte {
|
||||
|
||||
@@ -47,12 +47,12 @@ func NewCodexACP() *CodexACP {
|
||||
|
||||
func (a *CodexACP) ID() string { return "codex-acp" }
|
||||
func (a *CodexACP) Name() string { return "Codex ACP Agent" }
|
||||
func (a *CodexACP) DisplayName() string { return "Codex (ACP)" }
|
||||
func (a *CodexACP) DisplayName() string { return "Codex" }
|
||||
func (a *CodexACP) Description() string {
|
||||
return "OpenAI Codex coding agent using the ACP protocol via the Zed Industries bridge."
|
||||
}
|
||||
func (a *CodexACP) Enabled() bool { return true }
|
||||
func (a *CodexACP) DisplayOrder() int { return 3 }
|
||||
func (a *CodexACP) DisplayOrder() int { return 2 }
|
||||
|
||||
func (a *CodexACP) Logo(v LogoVariant) []byte {
|
||||
if v == LogoDark {
|
||||
|
||||
@@ -51,7 +51,7 @@ func (a *Copilot) DisplayName() string { return "Copilot" }
|
||||
func (a *Copilot) Description() string {
|
||||
return "GitHub Copilot CLI-powered autonomous coding agent using the Copilot SDK protocol."
|
||||
}
|
||||
func (a *Copilot) Enabled() bool { return true }
|
||||
func (a *Copilot) Enabled() bool { return false }
|
||||
func (a *Copilot) DisplayOrder() int { return 6 }
|
||||
|
||||
func (a *Copilot) Logo(v LogoVariant) []byte {
|
||||
@@ -83,7 +83,7 @@ func (a *Copilot) IsInstalled(ctx context.Context) (*DiscoveryResult, error) {
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (a *Copilot) DefaultModel() string { return "gpt-4.1" }
|
||||
func (a *Copilot) DefaultModel() string { return "gpt-5-mini" }
|
||||
|
||||
func (a *Copilot) ListModels(ctx context.Context) (*ModelList, error) {
|
||||
return &ModelList{Models: copilotStaticModels(), SupportsDynamic: false}, nil
|
||||
@@ -149,19 +149,22 @@ var copilotPermSettings = map[string]PermissionSetting{
|
||||
|
||||
func copilotStaticModels() []Model {
|
||||
return []Model{
|
||||
{ID: "gpt-4.1", Name: "GPT-4.1", Description: "OpenAI GPT-4.1", Provider: "openai", Source: "static"},
|
||||
{ID: "claude-sonnet-4", Name: "Claude Sonnet 4", Description: "Anthropic Claude Sonnet 4", Provider: "anthropic", Source: "static"},
|
||||
{ID: "claude-sonnet-4.5", Name: "Claude Sonnet 4.5", Description: "Anthropic Claude Sonnet 4.5", Provider: "anthropic", Source: "static"},
|
||||
{ID: "claude-opus-4.5", Name: "Claude Opus 4.5", Description: "Anthropic Claude Opus 4.5", Provider: "anthropic", Source: "static"},
|
||||
{ID: "claude-haiku-4.5", Name: "Claude Haiku 4.5", Description: "Anthropic Claude Haiku 4.5", Provider: "anthropic", Source: "static"},
|
||||
{ID: "gpt-5.2-codex", Name: "GPT-5.2 Codex", Description: "OpenAI GPT-5.2 Codex", Provider: "openai", Source: "static"},
|
||||
{ID: "gpt-5.2", Name: "GPT-5.2", Description: "OpenAI GPT-5.2", Provider: "openai", Source: "static"},
|
||||
{ID: "gpt-5.1-codex-max", Name: "GPT-5.1 Codex Max", Description: "OpenAI GPT-5.1 Codex Max", Provider: "openai", Source: "static"},
|
||||
{ID: "gpt-5.1-codex", Name: "GPT-5.1 Codex", Description: "OpenAI GPT-5.1 Codex", Provider: "openai", Source: "static"},
|
||||
{ID: "gpt-5.1", Name: "GPT-5.1", Description: "OpenAI GPT-5.1", Provider: "openai", Source: "static"},
|
||||
{ID: "gpt-5", Name: "GPT-5", Description: "OpenAI GPT-5", Provider: "openai", Source: "static"},
|
||||
{ID: "gpt-5.1-codex-mini", Name: "GPT-5.1 Codex Mini", Description: "OpenAI GPT-5.1 Codex Mini", Provider: "openai", Source: "static"},
|
||||
{ID: "gpt-5-mini", Name: "GPT-5 Mini", Description: "OpenAI GPT-5 Mini", Provider: "openai", Source: "static", IsDefault: true},
|
||||
{ID: "gemini-3-pro-preview", Name: "Gemini 3 Pro Preview", Description: "Google Gemini 3 Pro Preview", Provider: "google", Source: "static"},
|
||||
{ID: "claude-sonnet-4.6", Name: "Claude Sonnet 4.6", Provider: "anthropic", Source: "static"},
|
||||
{ID: "claude-sonnet-4.5", Name: "Claude Sonnet 4.5", Provider: "anthropic", Source: "static"},
|
||||
{ID: "claude-opus-4.6", Name: "Claude Opus 4.6", Provider: "anthropic", Source: "static"},
|
||||
{ID: "claude-opus-4.5", Name: "Claude Opus 4.5", Provider: "anthropic", Source: "static"},
|
||||
{ID: "claude-haiku-4.5", Name: "Claude Haiku 4.5", Provider: "anthropic", Source: "static"},
|
||||
{ID: "claude-sonnet-4", Name: "Claude Sonnet 4", Provider: "anthropic", Source: "static"},
|
||||
{ID: "gemini-3-pro-preview", Name: "Gemini 3 Pro (Preview)", Provider: "google", Source: "static"},
|
||||
{ID: "gpt-5.4", Name: "GPT-5.4", Provider: "openai", Source: "static"},
|
||||
{ID: "gpt-5.3-codex", Name: "GPT-5.3-Codex", Provider: "openai", Source: "static"},
|
||||
{ID: "gpt-5.2-codex", Name: "GPT-5.2-Codex", Provider: "openai", Source: "static"},
|
||||
{ID: "gpt-5.2", Name: "GPT-5.2", Provider: "openai", Source: "static"},
|
||||
{ID: "gpt-5.1-codex-max", Name: "GPT-5.1-Codex-Max", Provider: "openai", Source: "static"},
|
||||
{ID: "gpt-5.1-codex", Name: "GPT-5.1-Codex", Provider: "openai", Source: "static"},
|
||||
{ID: "gpt-5.1", Name: "GPT-5.1", Provider: "openai", Source: "static"},
|
||||
{ID: "gpt-5.1-codex-mini", Name: "GPT-5.1-Codex-Mini", Provider: "openai", Source: "static"},
|
||||
{ID: "gpt-5-mini", Name: "GPT-5 Mini", Provider: "openai", Source: "static", IsDefault: true},
|
||||
{ID: "gpt-4.1", Name: "GPT-4.1", Provider: "openai", Source: "static"},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,12 +49,12 @@ func NewCopilotACP() *CopilotACP {
|
||||
|
||||
func (a *CopilotACP) ID() string { return "copilot-acp" }
|
||||
func (a *CopilotACP) Name() string { return "Copilot ACP Agent" }
|
||||
func (a *CopilotACP) DisplayName() string { return "Copilot (ACP)" }
|
||||
func (a *CopilotACP) DisplayName() string { return "Copilot" }
|
||||
func (a *CopilotACP) Description() string {
|
||||
return "GitHub Copilot coding agent using the ACP protocol over stdin/stdout."
|
||||
}
|
||||
func (a *CopilotACP) Enabled() bool { return true }
|
||||
func (a *CopilotACP) DisplayOrder() int { return 7 }
|
||||
func (a *CopilotACP) DisplayOrder() int { return 6 }
|
||||
|
||||
func (a *CopilotACP) Logo(v LogoVariant) []byte {
|
||||
if v == LogoDark {
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
package agents
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestACPModelID(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
model Model
|
||||
want string
|
||||
}{
|
||||
{
|
||||
name: "returns ACPID when set",
|
||||
model: Model{ID: "claude-opus-4-6", ACPID: "default"},
|
||||
want: "default",
|
||||
},
|
||||
{
|
||||
name: "falls back to ID when ACPID empty",
|
||||
model: Model{ID: "gpt-5-1"},
|
||||
want: "gpt-5-1",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if got := tt.model.ACPModelID(); got != tt.want {
|
||||
t.Errorf("ACPModelID() = %q, want %q", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestResolveACPModelID(t *testing.T) {
|
||||
models := []Model{
|
||||
{ID: "claude-sonnet-4-6", ACPID: "sonnet"},
|
||||
{ID: "claude-opus-4-6", ACPID: "default"},
|
||||
{ID: "claude-haiku-4-5", ACPID: "haiku"},
|
||||
{ID: "gpt-5-1"}, // no ACPID
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
profileModel string
|
||||
want string
|
||||
}{
|
||||
{
|
||||
name: "resolves to ACPID when mapping exists",
|
||||
profileModel: "claude-opus-4-6",
|
||||
want: "default",
|
||||
},
|
||||
{
|
||||
name: "resolves sonnet mapping",
|
||||
profileModel: "claude-sonnet-4-6",
|
||||
want: "sonnet",
|
||||
},
|
||||
{
|
||||
name: "returns original ID when no ACPID",
|
||||
profileModel: "gpt-5-1",
|
||||
want: "gpt-5-1",
|
||||
},
|
||||
{
|
||||
name: "returns original ID when model not in list",
|
||||
profileModel: "unknown-model",
|
||||
want: "unknown-model",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if got := ResolveACPModelID(models, tt.profileModel); got != tt.want {
|
||||
t.Errorf("ResolveACPModelID() = %q, want %q", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestResolveACPModelID_EmptyList(t *testing.T) {
|
||||
got := ResolveACPModelID(nil, "claude-opus-4-6")
|
||||
if got != "claude-opus-4-6" {
|
||||
t.Errorf("ResolveACPModelID(nil) = %q, want %q", got, "claude-opus-4-6")
|
||||
}
|
||||
}
|
||||
@@ -52,7 +52,7 @@ func (a *OpenCode) DisplayName() string { return "OpenCode" }
|
||||
func (a *OpenCode) Description() string {
|
||||
return "OpenCode CLI-powered autonomous coding agent using REST/SSE protocol."
|
||||
}
|
||||
func (a *OpenCode) Enabled() bool { return true }
|
||||
func (a *OpenCode) Enabled() bool { return false }
|
||||
func (a *OpenCode) DisplayOrder() int { return 4 }
|
||||
|
||||
func (a *OpenCode) Logo(v LogoVariant) []byte {
|
||||
|
||||
@@ -40,12 +40,12 @@ func NewOpenCodeACP() *OpenCodeACP {
|
||||
|
||||
func (a *OpenCodeACP) ID() string { return "opencode-acp" }
|
||||
func (a *OpenCodeACP) Name() string { return "OpenCode AI Agent (ACP)" }
|
||||
func (a *OpenCodeACP) DisplayName() string { return "OpenCode (ACP)" }
|
||||
func (a *OpenCodeACP) DisplayName() string { return "OpenCode" }
|
||||
func (a *OpenCodeACP) Description() string {
|
||||
return "OpenCode coding agent using ACP protocol over stdin/stdout."
|
||||
}
|
||||
func (a *OpenCodeACP) Enabled() bool { return true }
|
||||
func (a *OpenCodeACP) DisplayOrder() int { return 5 }
|
||||
func (a *OpenCodeACP) DisplayOrder() int { return 4 }
|
||||
|
||||
func (a *OpenCodeACP) Logo(v LogoVariant) []byte {
|
||||
if v == LogoDark {
|
||||
|
||||
@@ -328,17 +328,24 @@ func (sm *SessionManager) InitializeAndPrompt(
|
||||
execution.sessionInitialized = true
|
||||
|
||||
// Set the user's configured profile model if it differs from the agent's default.
|
||||
// ACP agents ignore --model CLI flags, so the model must be set via ACP protocol.
|
||||
// Resolve ACP-specific model ID (e.g., "claude-opus-4-6" → "default" for Claude ACP).
|
||||
if profileModel != "" && profileModel != agentConfig.DefaultModel() && execution.agentctl != nil {
|
||||
if err := execution.agentctl.SetModel(ctx, profileModel); err != nil {
|
||||
acpModel := profileModel
|
||||
if list, err := agentConfig.ListModels(ctx); err == nil && list != nil {
|
||||
acpModel = agents.ResolveACPModelID(list.Models, profileModel)
|
||||
}
|
||||
|
||||
if err := execution.agentctl.SetModel(ctx, acpModel); err != nil {
|
||||
sm.logger.Warn("failed to set profile model via ACP",
|
||||
zap.String("execution_id", execution.ID),
|
||||
zap.String("model", profileModel),
|
||||
zap.String("acp_model", acpModel),
|
||||
zap.Error(err))
|
||||
} else {
|
||||
sm.logger.Info("set profile model on ACP session",
|
||||
zap.String("execution_id", execution.ID),
|
||||
zap.String("model", profileModel))
|
||||
zap.String("model", profileModel),
|
||||
zap.String("acp_model", acpModel))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -100,6 +100,10 @@ type Adapter struct {
|
||||
// Attachment management
|
||||
attachMgr *shared.AttachmentManager
|
||||
|
||||
// Available models from the most recent session creation/load.
|
||||
// Used by SetModel to validate the requested model exists.
|
||||
availableModels []acp.ModelInfo
|
||||
|
||||
// Synchronization
|
||||
mu sync.RWMutex
|
||||
closed bool
|
||||
@@ -246,6 +250,9 @@ func (a *Adapter) NewSession(ctx context.Context, mcpServers []types.McpServer)
|
||||
a.mu.Lock()
|
||||
a.sessionID = string(resp.SessionId)
|
||||
sessionID := a.sessionID
|
||||
if resp.Models != nil {
|
||||
a.availableModels = resp.Models.AvailableModels
|
||||
}
|
||||
a.mu.Unlock()
|
||||
a.attachMgr.SetSessionID(sessionID)
|
||||
|
||||
@@ -371,6 +378,9 @@ func (a *Adapter) LoadSession(ctx context.Context, sessionID string) error {
|
||||
|
||||
a.mu.Lock()
|
||||
a.sessionID = sessionID
|
||||
if resp.Models != nil {
|
||||
a.availableModels = resp.Models.AvailableModels
|
||||
}
|
||||
a.mu.Unlock()
|
||||
a.attachMgr.SetSessionID(sessionID)
|
||||
|
||||
@@ -898,16 +908,35 @@ func (a *Adapter) SetMode(ctx context.Context, modeID string) error {
|
||||
}
|
||||
|
||||
// SetModel changes the agent's model via ACP session/set_model (unstable SDK method).
|
||||
// If the model ID doesn't exist in the agent's available models, the call is skipped to avoid 404.
|
||||
func (a *Adapter) SetModel(ctx context.Context, modelID string) error {
|
||||
a.mu.RLock()
|
||||
conn := a.acpConn
|
||||
sessionID := a.sessionID
|
||||
available := a.availableModels
|
||||
a.mu.RUnlock()
|
||||
|
||||
if conn == nil {
|
||||
return fmt.Errorf("adapter not initialized")
|
||||
}
|
||||
|
||||
// Validate model exists in the agent's available models (if known).
|
||||
if len(available) > 0 {
|
||||
found := false
|
||||
for _, m := range available {
|
||||
if string(m.ModelId) == modelID {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
a.logger.Warn("skipping SetModel: model not in agent's available models",
|
||||
zap.String("model_id", modelID),
|
||||
zap.Int("available_count", len(available)))
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
_, err := conn.SetSessionModel(ctx, acp.SetSessionModelRequest{
|
||||
SessionId: acp.SessionId(sessionID),
|
||||
ModelId: acp.ModelId(modelID),
|
||||
|
||||
Reference in New Issue
Block a user