Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions internal/components/sdd/profiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,10 +223,14 @@ func extractModelFromAgent(agentMap map[string]any) model.ModelAssignment {
return model.ModelAssignment{}
}

// Try colon separator first (standard: "anthropic:claude-sonnet-4"), then slash.
idx := strings.Index(modelStr, ":")
if idx <= 0 {
idx = strings.Index(modelStr, "/")
// Find the first separator (either "/" or ":") to split provider from model.
// This handles specs like "openrouter/qwen/qwen3.6-plus:free" correctly.
idx := -1
for i := 0; i < len(modelStr); i++ {
if modelStr[i] == '/' || modelStr[i] == ':' {
idx = i
break
}
}
if idx <= 0 {
return model.ModelAssignment{}
Expand Down
64 changes: 64 additions & 0 deletions internal/components/sdd/profiles_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -858,6 +858,70 @@ func TestExtractModelFromAgent_NoVariantDefaultsEmpty(t *testing.T) {
}
}

// TestExtractModelFromAgent_OpenRouterFreeModel verifies that extractModelFromAgent
// correctly parses OpenRouter free-model specs like "openrouter/qwen/qwen3.6-plus:free".
// The first separator is "/" (not ":"), so the provider should be "openrouter" and
// the model should be "qwen/qwen3.6-plus:free".
func TestExtractModelFromAgent_OpenRouterFreeModel(t *testing.T) {
agentMap := map[string]any{
"model": "openrouter/qwen/qwen3.6-plus:free",
}
got := extractModelFromAgent(agentMap)
if got.ProviderID != "openrouter" {
t.Errorf("extractModelFromAgent ProviderID = %q, want %q", got.ProviderID, "openrouter")
}
if got.ModelID != "qwen/qwen3.6-plus:free" {
t.Errorf("extractModelFromAgent ModelID = %q, want %q", got.ModelID, "qwen/qwen3.6-plus:free")
}
}

// TestDetectProfiles_OpenRouterFreeModel verifies that DetectProfiles
// correctly parses OpenRouter free-model specs when detecting profiles.
func TestDetectProfiles_OpenRouterFreeModel(t *testing.T) {
dir := t.TempDir()
settingsPath := filepath.Join(dir, "opencode.json")

content := `{
"agent": {
"sdd-orchestrator-openr": { "mode": "primary", "model": "openrouter/qwen/qwen3.6-plus:free" },
"sdd-apply-openr": { "mode": "subagent", "model": "openrouter/qwen/qwen3.6-plus:free" }
}
}`
if err := os.WriteFile(settingsPath, []byte(content), 0o644); err != nil {
t.Fatalf("write settings: %v", err)
}

profiles, err := DetectProfiles(settingsPath)
if err != nil {
t.Fatalf("DetectProfiles() error = %v", err)
}
if len(profiles) != 1 {
t.Fatalf("DetectProfiles() returned %d profiles, want 1", len(profiles))
}

p := profiles[0]
if p.Name != "openr" {
t.Errorf("Profile.Name = %q, want %q", p.Name, "openr")
}
if p.OrchestratorModel.ProviderID != "openrouter" {
t.Errorf("OrchestratorModel.ProviderID = %q, want %q", p.OrchestratorModel.ProviderID, "openrouter")
}
if p.OrchestratorModel.ModelID != "qwen/qwen3.6-plus:free" {
t.Errorf("OrchestratorModel.ModelID = %q, want %q", p.OrchestratorModel.ModelID, "qwen/qwen3.6-plus:free")
}

m, ok := p.PhaseAssignments["sdd-apply"]
if !ok {
t.Fatal("sdd-apply missing from PhaseAssignments")
}
if m.ProviderID != "openrouter" {
t.Errorf("PhaseAssignments[sdd-apply] ProviderID = %q, want %q", m.ProviderID, "openrouter")
}
if m.ModelID != "qwen/qwen3.6-plus:free" {
t.Errorf("PhaseAssignments[sdd-apply] ModelID = %q, want %q", m.ModelID, "qwen/qwen3.6-plus:free")
}
}

// TestGenerateProfileOverlay_VariantInjected verifies that a profile
// phase assignment with Effort="medium" results in "variant":"medium"
// in the generated overlay JSON.
Expand Down
22 changes: 13 additions & 9 deletions internal/components/sdd/read_assignments.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package sdd
import (
"encoding/json"
"os"
"strings"

"github.com/gentleman-programming/gentle-ai/internal/model"
"github.com/gentleman-programming/gentle-ai/internal/opencode"
Expand Down Expand Up @@ -79,18 +78,23 @@ func ReadCurrentModelAssignments(settingsPath string) (map[string]model.ModelAss
if !ok || modelStr == "" {
continue
}
// Try colon first (standard: "anthropic:claude-sonnet-4"), then slash
// ("zai-coding-plan/glm-5-turbo") for custom providers (issue #152).
idx := strings.Index(modelStr, ":")
if idx <= 0 {
idx = strings.Index(modelStr, "/")
// Find the first separator (either '/' or ':') to correctly parse
// model specs like "openrouter/qwen/qwen3.6-plus:free" where the
// provider is before the first slash, not before the colon.
// Issue #802: colon-first parsing broke OpenRouter free-model specs.
sep := -1
for i, c := range modelStr {
if c == '/' || c == ':' {
sep = i
break
}
}
if idx <= 0 {
if sep <= 0 {
// No separator or separator is the first character — skip malformed value.
continue
}
providerID := modelStr[:idx]
modelID := modelStr[idx+1:]
providerID := modelStr[:sep]
modelID := modelStr[sep+1:]
if modelID == "" {
continue
}
Expand Down
34 changes: 34 additions & 0 deletions internal/components/sdd/read_assignments_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,40 @@ func TestReadCurrentModelAssignmentsSlashSeparator(t *testing.T) {
}
}

// TestReadCurrentModelAssignmentsOpenRouterFreeModel verifies that model specs
// with multiple slashes and a colon (like "openrouter/qwen/qwen3.6-plus:free")
// are parsed correctly. The provider is everything before the FIRST separator
// (slash or colon), not before the colon. Issue #802.
func TestReadCurrentModelAssignmentsOpenRouterFreeModel(t *testing.T) {
dir := t.TempDir()
settingsPath := filepath.Join(dir, "opencode.json")

content := `{
"agent": {
"sdd-apply": { "model": "openrouter/qwen/qwen3.6-plus:free" }
}
}`
if err := os.WriteFile(settingsPath, []byte(content), 0o644); err != nil {
t.Fatalf("write settings: %v", err)
}

got, err := ReadCurrentModelAssignments(settingsPath)
if err != nil {
t.Fatalf("ReadCurrentModelAssignments() error = %v", err)
}

a, ok := got["sdd-apply"]
if !ok {
t.Fatal("sdd-apply missing from result — OpenRouter free-model format not parsed")
}
if a.ProviderID != "openrouter" {
t.Errorf("ProviderID = %q, want %q", a.ProviderID, "openrouter")
}
if a.ModelID != "qwen/qwen3.6-plus:free" {
t.Errorf("ModelID = %q, want %q", a.ModelID, "qwen/qwen3.6-plus:free")
}
}

// TestReadCurrentModelAssignmentsReadsVariant verifies that the
// variant field in an agent definition is populated on the returned
// ModelAssignment.Effort.
Expand Down
11 changes: 7 additions & 4 deletions internal/update/upgrade/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"testing"

"github.com/gentleman-programming/gentle-ai/internal/backup"
"github.com/gentleman-programming/gentle-ai/internal/components/gga"
"github.com/gentleman-programming/gentle-ai/internal/model"
"github.com/gentleman-programming/gentle-ai/internal/state"
"github.com/gentleman-programming/gentle-ai/internal/system"
Expand Down Expand Up @@ -856,17 +857,19 @@ func TestConfigPathsForBackup_CoversRegistryAgentsNotInOldList(t *testing.T) {
func TestConfigPathsForBackup_GGAExtrasAreIncluded(t *testing.T) {
homeDir := t.TempDir()

// Create GGA config file at ~/.config/gga/config
ggaConfigFile := filepath.Join(homeDir, ".config", "gga", "config")
// Use gga package functions to get platform-correct paths
// (Windows uses %APPDATA%\gga, Unix uses ~/.config/gga)
ggaConfigFile := gga.ConfigPath(homeDir)
if err := os.MkdirAll(filepath.Dir(ggaConfigFile), 0o755); err != nil {
t.Fatalf("MkdirAll gga config: %v", err)
}
if err := os.WriteFile(ggaConfigFile, []byte("gga-config"), 0o644); err != nil {
t.Fatalf("WriteFile gga config: %v", err)
}

// Create GGA runtime lib file at ~/.local/share/gga/lib/pr_mode.sh
ggaLibFile := filepath.Join(homeDir, ".local", "share", "gga", "lib", "pr_mode.sh")
// GGA runtime lib file at ~/.local/share/gga/lib/pr_mode.sh
// (same path on all platforms)
ggaLibFile := gga.RuntimePRModePath(homeDir)
if err := os.MkdirAll(filepath.Dir(ggaLibFile), 0o755); err != nil {
t.Fatalf("MkdirAll gga lib: %v", err)
}
Expand Down