Skip to content

Self-hosted workflows for coding-agent delivery. Orchestrate CodeBuddy, Codex and Claude Code with scripts and human approval gates. Includes Local workflows for coding assistants.

fix(cursor): fold effort variants into one model row (#491)

crispinhu278e7484614d4a
diff --git a/chatbot/src/effort.js b/chatbot/src/effort.js
index b24dd788..42fb577c 100644
--- a/chatbot/src/effort.js
+++ b/chatbot/src/effort.js
@@ -1,9 +1,12 @@
const levels = {
+ none: { label: "关闭", icon: "sparkles", detail: "不使用额外推理。" },
+ minimal: { label: "最低", icon: "effort-low", detail: "只做最少推理,优先尽快返回。" },
low: { label: "低", icon: "effort-low", detail: "优先响应速度,适合简单问题。" },
medium: { label: "中", icon: "effort-medium", detail: "兼顾响应速度与推理深度。" },
high: { label: "高", icon: "brain", detail: "更充分地推理,适合复杂问题。" },
xhigh: { label: "更高", icon: "search", detail: "投入更多推理时间,适合困难任务。" },
max: { label: "最高", icon: "effort-max", detail: "使用模型支持的最高思考强度,耗时可能更长。" },
+ ultra: { label: "极致", icon: "effort-max", detail: "使用极致推理强度,耗时可能更长。" },
};
export function modelEffort(model, value) {
diff --git a/chatbot/tests/effort.test.mjs b/chatbot/tests/effort.test.mjs
index e42af38a..1b9bca9a 100644
--- a/chatbot/tests/effort.test.mjs
+++ b/chatbot/tests/effort.test.mjs
@@ -9,3 +9,12 @@ test("effort choices follow the current model catalog and keep the native defaul
assert.equal(modelEffort({ efforts: ["high"] }, "max"), "");
assert.equal(modelEffort(undefined, "high"), "");
});
+
+test("cursor-only effort levels none, minimal and ultra are offered when the model lists them", () => {
+ const options = effortOptions({ efforts: ["none", "minimal", "low", "ultra", "bogus"] });
+ assert.deepEqual(options.map((v) => v.id), ["", "none", "minimal", "low", "ultra"]);
+ for (const option of options) {
+ assert.ok(option.label && option.icon && option.detail, `effort ${option.id} has display metadata`);
+ }
+ assert.equal(modelEffort({ efforts: ["none", "ultra"] }, "ultra"), "ultra");
+});
diff --git a/internal/domain/agent.go b/internal/domain/agent.go
index 5e98e7ea..bca6dcb5 100644
--- a/internal/domain/agent.go
+++ b/internal/domain/agent.go
@@ -14,7 +14,7 @@ var ExecutorEffortLevels = map[string][]string{
"codebuddy": {"low", "medium", "high", "xhigh", "max", "ultracode"},
"codex": {"low", "medium", "high", "xhigh", "max", "ultra"},
"opencode": {"low", "medium", "high"},
- "cursor": {"none", "minimal", "low", "medium", "high", "xhigh", "max"},
+ "cursor": {"none", "minimal", "low", "medium", "high", "xhigh", "max", "ultra"},
"agy": {"low", "medium", "high", "xhigh", "max"},
"pi": {"minimal", "low", "medium", "high", "xhigh", "max"},
}
diff --git a/internal/domain/runner.go b/internal/domain/runner.go
index 48bebf5b..be3d1f36 100644
--- a/internal/domain/runner.go
+++ b/internal/domain/runner.go
@@ -408,6 +408,7 @@ func PublicRunnerTask(task RunnerTask) RunnerTask {
copyInvocation.AgentCLIAPIKey = ""
copyInvocation.AgentCLIBaseURL = ""
copyInvocation.AgentCLIProtocol = ""
+ copyInvocation.AgentCLIModels = nil
copyInvocation.GitSSHUserID = 0
copyInvocation.GitSSHKeys = nil
if copyInvocation.Repository != nil {
@@ -475,6 +476,9 @@ type RunnerInvocation struct {
AgentCLIAPIKey string `json:"agentCliApiKey,omitempty"`
AgentCLIBaseURL string `json:"agentCliBaseUrl,omitempty"`
AgentCLIProtocol string `json:"agentCliProtocol,omitempty"`
+ // AgentCLIModels is the responsible user's saved catalog for the agent
+ // CLI; Cursor resolves the model's effort to an ID from it.
+ AgentCLIModels []CLIModel `json:"agentCliModels,omitempty"`
// MCPCallServers is the project/personal HTTP MCP set for `agentflow mcp call`
// in scripts, verification gates, and Agent hooks. It is unbound; personal
// credentials are applied in memory on the runner. Agent Assets stay
diff --git a/internal/domain/user.go b/internal/domain/user.go
index 55cec9f2..b2535895 100644
--- a/internal/domain/user.go
+++ b/internal/domain/user.go
@@ -101,9 +101,17 @@ func PublicUser(u User) User {
// CLIModel is one entry of a CLI model catalog. ID is passed to the CLI
// as-is; an empty Name shows the ID.
+//
+// Efforts is set on a Cursor model family folded out of the CLI's own model
+// list: it maps each reasoning effort onto the model ID cursor-agent printed
+// for it, and DefaultEffort is the effort an empty choice runs. They are
+// saved with the catalog so the family resolves for its owner on any
+// instance and after a restart.
type CLIModel struct {
- ID string `json:"id"`
- Name string `json:"name,omitempty"`
+ ID string `json:"id"`
+ Name string `json:"name,omitempty"`
+ Efforts map[string]string `json:"efforts,omitempty"`
+ DefaultEffort string `json:"defaultEffort,omitempty"`
}
// AgentCLICredential is the personal configuration of one agent CLI. An
diff --git a/internal/engine/runner_dispatch.go b/internal/engine/runner_dispatch.go
index a1e6b4f6..33218498 100644
--- a/internal/engine/runner_dispatch.go
+++ b/internal/engine/runner_dispatch.go
@@ -228,6 +228,7 @@ func (e *Engine) dispatchRunnerTask(ctx context.Context, runnerID string, run do
invocation.AgentCLIAPIKey = cred.APIKey
invocation.AgentCLIBaseURL = cred.BaseURL
invocation.AgentCLIProtocol = cred.Protocol
+ invocation.AgentCLIModels = cred.Models
}
}
}
diff --git a/internal/httpapi/assistant.go b/internal/httpapi/assistant.go
index e674c72a..841042a7 100644
--- a/internal/httpapi/assistant.go
+++ b/internal/httpapi/assistant.go
@@ -179,7 +179,7 @@ func (h *assistantHandlers) chat(c *gin.Context) {
req.Model = assistantAllowedUserModel(req.Model, catalog, user)
cliEngine, _ = assistantModelEngine(req.Model)
req.Executor = cliEngine
- if err := validateAssistantEffort(req.Model, req.Effort); err != nil {
+ if err := validateAssistantEffort(user, req.Model, req.Effort); err != nil {
c.JSON(400, gin.H{"error": err.Error()})
return
}
diff --git a/internal/httpapi/assistant_effort.go b/internal/httpapi/assistant_effort.go
index f7fbde99..c712878e 100644
--- a/internal/httpapi/assistant_effort.go
+++ b/internal/httpapi/assistant_effort.go
@@ -14,9 +14,18 @@ import (
// fallback: the CLI clamps xhigh/max to high when no capability is known.
// Keep this snapshot alongside the fixed chat model catalog when updating it.
// Empty effort always leaves the model's native default untouched.
-func assistantModelEfforts(model string) []string {
+//
+// user's saved Cursor catalog resolves the Cursor families folded out of
+// their CLI's own model list (runtime.FoldCursorCLIModels).
+func assistantModelEfforts(user domain.User, model string) []string {
+ return assistantModelEffortsIn(model, assistantCursorCatalog(user))
+}
+
+// assistantModelEffortsIn is assistantModelEfforts with the Cursor catalog
+// given directly.
+func assistantModelEffortsIn(model string, cursor []domain.CLIModel) []string {
if engine, id := assistantModelEngine(model); engine == runtime.AgentCLICursor {
- return runtime.CursorModelEfforts(id)
+ return runtime.CursorModelEfforts(id, cursor)
} else if engine == runtime.AgentCLIAntigravity {
return runtime.AgyModelEfforts(id)
} else if runtime.IsAgentCLI(engine) {
@@ -38,12 +47,18 @@ func assistantModelEfforts(model string) []string {
}
}
-func validateAssistantEffort(model, effort string) error {
+func validateAssistantEffort(user domain.User, model, effort string) error {
if effort == "" {
return nil
}
- if !slices.Contains(assistantModelEfforts(model), effort) {
- return fmt.Errorf("模型 %s 不支持思考强度 %q,可选:默认、%s", model, effort, strings.Join(assistantModelEfforts(model), "、"))
+ efforts := assistantModelEfforts(user, model)
+ if !slices.Contains(efforts, effort) {
+ return fmt.Errorf("模型 %s 不支持思考强度 %q,可选:默认、%s", model, effort, strings.Join(efforts, "、"))
}
return nil
}
+
+// assistantCursorCatalog is the user's saved Cursor model list.
+func assistantCursorCatalog(user domain.User) []domain.CLIModel {
+ return user.AgentCLICredentials[runtime.AgentCLICursor].Models
+}
diff --git a/internal/httpapi/assistant_engines.go b/internal/httpapi/assistant_engines.go
index 1201b04a..e06f76a1 100644
--- a/internal/httpapi/assistant_engines.go
+++ b/internal/httpapi/assistant_engines.go
@@ -8,15 +8,19 @@ import (
"errors"
"fmt"
"io"
+ "log"
+ "maps"
"net/http"
"net/url"
"os"
"path/filepath"
+ "slices"
"strings"
"sync"
"time"
"agentflow/internal/domain"
+ "agentflow/internal/repo"
"agentflow/internal/runtime"
)
@@ -313,18 +317,23 @@ func assistantEngineModels(ctx context.Context, user domain.User) []assistantMod
var listed []assistantDiscoveredModel
for _, model := range assistantEngineCustomModels(user, engine) {
if assistantValidEngineModel(model.ID) {
- listed = append(listed, assistantDiscoveredModel{ID: model.ID, Name: model.Name})
+ listed = append(listed, assistantDiscoveredModel{ID: model.ID, Name: model.Name, Efforts: model.Efforts, DefaultEffort: model.DefaultEffort})
}
}
if len(listed) == 0 && baseURL != "" {
listed = cachedAssistantEngineDiscovery(ctx, assistantEngineAnthropicModels(engine, protocol), key, baseURL)
}
+ // Cursor's list comes from the CLI; the saved one (the last list
+ // saveCursorCatalog kept) answers until a fresh one is cached.
if engine == runtime.AgentCLICursor {
- listed = cachedCursorModels(key)
+ if fresh := cachedCursorModels(key); len(fresh) > 0 {
+ listed = fresh
+ }
}
if len(listed) == 0 {
listed = assistantEngineBuiltinModels(engine)
}
+ catalog := cliModelsOf(listed)
for _, model := range listed {
name := strings.TrimSpace(model.Name)
if name == "" {
@@ -336,7 +345,7 @@ func assistantEngineModels(ctx context.Context, user domain.User) []assistantMod
Name: name,
Family: assistantModelFamily(model.ID),
Engine: engine,
- Efforts: assistantModelEfforts(id),
+ Efforts: assistantModelEffortsIn(id, catalog),
})
}
}
@@ -346,6 +355,10 @@ func assistantEngineModels(ctx context.Context, user domain.User) []assistantMod
type assistantDiscoveredModel struct {
ID string
Name string
+ // Efforts and DefaultEffort describe a Cursor family folded out of the
+ // CLI's list (domain.CLIModel).
+ Efforts map[string]string
+ DefaultEffort string
}
type assistantDiscoveryEntry struct {
@@ -416,7 +429,7 @@ func cachedCursorModels(apiKey string) []assistantDiscoveredModel {
var models []assistantDiscoveredModel
for _, model := range found {
if assistantValidEngineModel(model.ID) && len(models) < assistantDiscoveryMaxModels {
- models = append(models, assistantDiscoveredModel{ID: model.ID, Name: model.Name})
+ models = append(models, assistantDiscoveredModel{ID: model.ID, Name: model.Name, Efforts: model.Efforts, DefaultEffort: model.DefaultEffort})
}
}
ttl := assistantDiscoveryTTL
@@ -429,6 +442,41 @@ func cachedCursorModels(apiKey string) []assistantDiscoveredModel {
return stale
}
+// saveCursorCatalog keeps the user's freshly listed Cursor models, folded
+// families with their effort→ID mapping included, in their Cursor
+// credential. Effort checks and the --model of chat turns and SOP nodes
+// resolve from that saved list, so a family keeps working on every instance
+// and after a restart, and each user resolves against their own CLI's list.
+func (h *assistantHandlers) saveCursorCatalog(user domain.User) {
+ if h == nil || h.repo == nil || user.ID <= 0 {
+ return
+ }
+ key, _ := assistantEngineCredential(user, runtime.AgentCLICursor)
+ if key == "" {
+ return
+ }
+ fresh := cachedCursorModels(key)
+ if len(fresh) == 0 {
+ return
+ }
+ models := cliModelsOf(fresh)
+ if cursorCatalogEqual(models, assistantCursorCatalog(user)) {
+ return
+ }
+ if _, err := h.repo.UpdateUserCredentials(user.ID, repo.UserCredentialUpdate{
+ AgentCLICredentials: map[string]repo.AgentCLICredentialUpdate{runtime.AgentCLICursor: {Models: &models}},
+ }); err != nil {
+ log.Printf("cursor model catalog save skipped user=%d: %v", user.ID, err)
+ }
+}
+
+func cursorCatalogEqual(a, b []domain.CLIModel) bool {
+ return slices.EqualFunc(a, b, func(x, y domain.CLIModel) bool {
+ return x.ID == y.ID && (x.Name == y.Name || x.Name == x.ID && y.Name == "" || y.Name == y.ID && x.Name == "") &&
+ x.DefaultEffort == y.DefaultEffort && maps.Equal(x.Efforts, y.Efforts)
+ })
+}
+
// discoverAssistantEngineModels reads the OpenAI-style model list behind a
// Base URL: {base}/models for OpenAI-style Base URLs (which already end in
// /v1) and {base}/v1/models for Anthropic ones. Gateways answer both with
diff --git a/internal/httpapi/assistant_generation.go b/internal/httpapi/assistant_generation.go
index 19a9cefd..16468db2 100644
--- a/internal/httpapi/assistant_generation.go
+++ b/internal/httpapi/assistant_generation.go
@@ -101,7 +101,7 @@ func (h *assistantHandlers) startGeneration(c *gin.Context) {
req.Model = assistantAllowedUserModel(req.Model, catalog, user)
cliEngine, _ = assistantModelEngine(req.Model)
req.Executor = cliEngine
- if err := validateAssistantEffort(req.Model, req.Effort); err != nil {
+ if err := validateAssistantEffort(user, req.Model, req.Effort); err != nil {
c.JSON(400, gin.H{"error": err.Error()})
return
}
@@ -428,7 +428,7 @@ func (h *assistantHandlers) steerGeneration(c *gin.Context) {
model = forced
}
model = assistantAllowedModel(model, h.chatCatalog(c.Request.Context(), user))
- if err := validateAssistantEffort(model, body.Effort); err != nil {
+ if err := validateAssistantEffort(user, model, body.Effort); err != nil {
c.JSON(400, gin.H{"error": err.Error()})
return
}
diff --git a/internal/httpapi/assistant_models.go b/internal/httpapi/assistant_models.go
index 4e562bd1..4a4fd6e9 100644
--- a/internal/httpapi/assistant_models.go
+++ b/internal/httpapi/assistant_models.go
@@ -220,6 +220,7 @@ func (h *assistantHandlers) models(c *gin.Context) {
}
if signedIn {
catalog.Models = append(catalog.Models, assistantEngineModels(c.Request.Context(), user)...)
+ h.saveCursorCatalog(user)
catalog.Engines = assistantEngineOptions(user, shared && strings.TrimSpace(user.CodeBuddyAPIKey) == "")
}
c.JSON(200, catalog)
@@ -295,7 +296,7 @@ func assistantFixedCatalog() assistantModelCatalog {
}
func assistantListedModel(id, name, credits string) assistantModel {
- return assistantModel{ID: id, Name: name, Family: assistantModelFamily(id), Credits: credits, Efforts: assistantModelEfforts(id)}
+ return assistantModel{ID: id, Name: name, Family: assistantModelFamily(id), Credits: credits, Efforts: assistantModelEfforts(domain.User{}, id)}
}
func assistantModelFamily(id string) string {
diff --git a/internal/httpapi/assistant_session.go b/internal/httpapi/assistant_session.go
index 9d1d5f40..6911ffa8 100644
--- a/internal/httpapi/assistant_session.go
+++ b/internal/httpapi/assistant_session.go
@@ -370,7 +370,8 @@ func (h *assistantHandlers) session(c *gin.Context) {
if conv.Model == "" {
conv.Model = existing.Model
}
- if err := validateAssistantEffort(conv.Model, conv.Effort); err != nil {
+ editor, _ := h.repo.User(current.ID)
+ if err := validateAssistantEffort(editor, conv.Model, conv.Effort); err != nil {
c.JSON(400, gin.H{"error": err.Error()})
return
}
diff --git a/internal/httpapi/assistant_title.go b/internal/httpapi/assistant_title.go
index dab04043..be8c6c42 100644
--- a/internal/httpapi/assistant_title.go
+++ b/internal/httpapi/assistant_title.go
@@ -120,7 +120,7 @@ func (h *assistantHandlers) scheduleAssistantTitle(ctx context.Context, ownerID
// effort; the gateway behind a Base URL may serve nothing else.
func assistantTitleModel(ctx context.Context, user domain.User, model string, shared []string) (string, string) {
if engine, _ := assistantModelEngine(model); engine != assistantEngineCodeBuddy {
- if efforts := assistantModelEfforts(model); len(efforts) > 0 {
+ if efforts := assistantModelEfforts(user, model); len(efforts) > 0 {
return model, efforts[0]
}
return model, ""
diff --git a/internal/httpapi/cli_models_probe.go b/internal/httpapi/cli_models_probe.go
index e1621b34..a1a97c16 100644
--- a/internal/httpapi/cli_models_probe.go
+++ b/internal/httpapi/cli_models_probe.go
@@ -168,27 +168,11 @@ func cursorAgentModels(ctx context.Context, apiKey string) ([]domain.CLIModel, e
return cursorModelFamilies(parseCursorModels(string(out))), nil
}
-// cursorModelFamilies folds the effort variants cursor-agent lists into the
-// families of the built-in table, in table order; IDs outside it follow as
-// they are.
+// cursorModelFamilies folds the effort variants cursor-agent lists into one
+// row per family. The built-in table wins; other IDs ending in a recognized
+// effort suffix fold the same way.
func cursorModelFamilies(models []domain.CLIModel) []domain.CLIModel {
- present, seen := map[string]bool{}, map[string]bool{}
- var unknown []domain.CLIModel
- for _, model := range models {
- if family, ok := runtime.CursorModelFamily(model.ID); ok {
- present[family.ID] = true
- } else if !seen[model.ID] {
- seen[model.ID] = true
- unknown = append(unknown, model)
- }
- }
- out := []domain.CLIModel{}
- for _, family := range runtime.CursorModels() {
- if present[family.ID] {
- out = append(out, domain.CLIModel{ID: family.ID, Name: family.Name})
- }
- }
- return append(out, unknown...)
+ return runtime.FoldCursorCLIModels(models)
}
func parseCursorModels(output string) []domain.CLIModel {
@@ -205,7 +189,7 @@ func parseCursorModels(output string) []domain.CLIModel {
func cliModelsOf(models []assistantDiscoveredModel) []domain.CLIModel {
out := make([]domain.CLIModel, 0, len(models))
for _, model := range models {
- out = append(out, domain.CLIModel{ID: model.ID, Name: model.Name})
+ out = append(out, domain.CLIModel{ID: model.ID, Name: model.Name, Efforts: model.Efforts, DefaultEffort: model.DefaultEffort})
}
return out
}
diff --git a/internal/httpapi/cli_models_probe_test.go b/internal/httpapi/cli_models_probe_test.go
new file mode 100644
index 00000000..83103f31
--- /dev/null
+++ b/internal/httpapi/cli_models_probe_test.go
@@ -0,0 +1,32 @@
+package httpapi
+
+import (
+ "reflect"
+ "testing"
+
+ "agentflow/internal/domain"
+)
+
+func TestCursorModelFamiliesFoldGemini4(t *testing.T) {
+ output := `
+gemini-4-carbon-low - Gemini 4 Carbon Low
+gemini-4-carbon-medium - Gemini 4 Carbon Medium
+gemini-4-carbon-high - Gemini 4 Carbon High
+gemini-4-hydrogen-low - Gemini 4 Hydrogen Low
+gemini-4-hydrogen-medium - Gemini 4 Hydrogen Medium
+gemini-4-hydrogen-high - Gemini 4 Hydrogen High
+gemini-4-hydrogen-xhigh - Gemini 4 Hydrogen Extra High
+gemini-4-argon-low - Gemini 4 Argon Low
+gemini-4-argon-medium - Gemini 4 Argon Medium (default)
+gemini-4-argon-high - Gemini 4 Argon High
+`
+ got := cursorModelFamilies(parseCursorModels(output))
+ want := []domain.CLIModel{
+ {ID: "gemini-4-carbon", Name: "Gemini 4 Carbon"},
+ {ID: "gemini-4-hydrogen", Name: "Gemini 4 Hydrogen"},
+ {ID: "gemini-4-argon", Name: "Gemini 4 Argon"},
+ }
+ if !reflect.DeepEqual(got, want) {
+ t.Fatalf("families:\n got %v\nwant %v", got, want)
+ }
+}
diff --git a/internal/httpapi/cursor_catalog_test.go b/internal/httpapi/cursor_catalog_test.go
new file mode 100644
index 00000000..adb075eb
--- /dev/null
+++ b/internal/httpapi/cursor_catalog_test.go
@@ -0,0 +1,132 @@
+package httpapi
+
+import (
+ "context"
+ "slices"
+ "testing"
+ "time"
+
+ "agentflow/internal/domain"
+ "agentflow/internal/repo"
+ "agentflow/internal/runtime"
+)
+
+const cursorCatalogTestOutput = `Available models
+
+widget-low - Widget Low
+widget - Widget
+widget-extra-high - Widget Extra High
+nova-medium - Nova Medium (NO ZDR)
+nova-high - Nova High (NO ZDR)
+grok-5-code - Grok 5 Code
+`
+
+// TestCursorFamiliesSurviveRestart covers a family folded out of the CLI's
+// own list: it is saved with the user's Cursor credential, so effort checks
+// and the --model of a turn still resolve once the in-memory list is gone
+// (a restart, another instance), and only for the user whose CLI listed it.
+func TestCursorFamiliesSurviveRestart(t *testing.T) {
+ st, err := repo.OpenTest()
+ if err != nil {
+ t.Fatal(err)
+ }
+ t.Cleanup(st.Close)
+ for _, login := range []string{"cursor-a", "cursor-b"} {
+ if err := st.PutUser(domain.User{LoginName: login}); err != nil {
+ t.Fatal(err)
+ }
+ }
+ a, _ := st.UserByLoginName("cursor-a")
+ b, _ := st.UserByLoginName("cursor-b")
+ for _, u := range []domain.User{a, b} {
+ if _, err := st.UpdateUserCredentials(u.ID, repo.UserCredentialUpdate{AgentCLICredentials: map[string]repo.AgentCLICredentialUpdate{
+ runtime.AgentCLICursor: {APIKey: "crsr_" + u.LoginName},
+ }}); err != nil {
+ t.Fatal(err)
+ }
+ }
+ a, _ = st.User(a.ID)
+ b, _ = st.User(b.ID)
+
+ previous := assistantCursorModels
+ t.Cleanup(func() { assistantCursorModels = previous; clearCursorModelsCache() })
+ assistantCursorModels = func(_ context.Context, apiKey string) ([]domain.CLIModel, error) {
+ if apiKey != "crsr_cursor-a" {
+ return nil, nil
+ }
+ return cursorModelFamilies(parseCursorModels(cursorCatalogTestOutput)), nil
+ }
+ clearCursorModelsCache()
+ cachedCursorModels("crsr_cursor-a")
+ deadline := time.Now().Add(5 * time.Second)
+ for len(cachedCursorModels("crsr_cursor-a")) == 0 {
+ if time.Now().After(deadline) {
+ t.Fatal("cursor model list was never cached")
+ }
+ time.Sleep(10 * time.Millisecond)
+ }
+ h := &assistantHandlers{deps: &deps{repo: st}}
+ h.saveCursorCatalog(a)
+
+ // Restart: the process forgets every listed model.
+ clearCursorModelsCache()
+ assistantCursorModels = func(context.Context, string) ([]domain.CLIModel, error) { return nil, nil }
+ a, _ = st.User(a.ID)
+
+ if err := validateAssistantEffort(a, "cursor:widget", "xhigh"); err != nil {
+ t.Fatalf("saved family rejected its effort: %v", err)
+ }
+ if err := validateAssistantEffort(a, "cursor:nova", "max"); err == nil {
+ t.Fatal("effort the family lacks was accepted")
+ }
+ if err := validateAssistantEffort(b, "cursor:widget", "xhigh"); err == nil {
+ t.Fatal("another user's family resolved")
+ }
+ if err := validateAssistantEffort(a, "cursor:grok-5-code", "high"); err == nil {
+ t.Fatal("unknown model accepted an effort")
+ }
+ var listed []assistantModel
+ for _, model := range assistantEngineModels(context.Background(), a) {
+ if model.Engine == runtime.AgentCLICursor {
+ listed = append(listed, model)
+ }
+ }
+ names := map[string]assistantModel{}
+ for _, model := range listed {
+ names[model.ID] = model
+ }
+ if got := names["cursor:widget"]; !slices.Equal(got.Efforts, []string{"low", "medium", "xhigh"}) {
+ t.Fatalf("listed after restart: %+v", listed)
+ }
+ if got := names["cursor:nova"]; got.Name != "Nova (NO ZDR)" || !slices.Equal(got.Efforts, []string{"medium", "high"}) {
+ t.Fatalf("nova after restart: %+v", got)
+ }
+
+ for _, c := range []struct {
+ user domain.User
+ model, effort, want string
+ }{
+ {a, "widget", "xhigh", "widget-extra-high"},
+ {a, "widget", "", "widget"},
+ {a, "nova", "", "nova-medium"},
+ {a, "grok-5-code", "high", "grok-5-code"},
+ {b, "widget", "xhigh", "widget"},
+ } {
+ command := runtime.AgentCLICommand(runtime.AgentCLICursor, runtime.AgentCLICommandOptions{Model: c.model, Effort: c.effort, Prompt: "p", Chat: true})
+ home := runtime.AgentCLIHome{Base: t.TempDir(), Rel: "home"}
+ argv, _, err := runtime.ApplyAgentCLICredential(runtime.AgentCLICursor, runtime.AgentCLIUserCredentials(c.user)[runtime.AgentCLICursor], command.AgentCLI, home, home.Base, command.Argv)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if i := slices.Index(argv, "--model"); i < 0 || argv[i+1] != c.want {
+ t.Errorf("%s %s/%s: argv %q, want --model %s", c.user.LoginName, c.model, c.effort, argv, c.want)
+ }
+ }
+}
+
+func clearCursorModelsCache() {
+ assistantCursorModelsCache.Range(func(key, _ any) bool {
+ assistantCursorModelsCache.Delete(key)
+ return true
+ })
+}
diff --git a/internal/repo/provider_credentials_test.go b/internal/repo/provider_credentials_test.go
index 6f954e9f..03ba0698 100644
--- a/internal/repo/provider_credentials_test.go
+++ b/internal/repo/provider_credentials_test.go
@@ -148,3 +148,57 @@ func TestProviderUserCredentials(t *testing.T) {
})
}
}
+
+func TestCursorFamilyEffortsRoundTrip(t *testing.T) {
+ st, err := OpenTest()
+ if err != nil {
+ t.Fatal(err)
+ }
+ defer st.Close()
+ if err := st.PutUser(domain.User{LoginName: "cursor-owner"}); err != nil {
+ t.Fatal(err)
+ }
+ user, _ := st.UserByLoginName("cursor-owner")
+ models := []domain.CLIModel{
+ {ID: "widget", Name: "Widget", Efforts: map[string]string{"low": "widget-low", "medium": "widget", "xhigh": "widget-extra-high"}, DefaultEffort: "medium"},
+ {ID: "solo", Efforts: map[string]string{"ultra": "solo-ultra"}, DefaultEffort: "high"},
+ {ID: "plain-model"},
+ }
+ if _, err := st.UpdateUserCredentials(user.ID, UserCredentialUpdate{AgentCLICredentials: map[string]AgentCLICredentialUpdate{
+ "cursor": {APIKey: "crsr_secret", Models: &models},
+ }}); err != nil {
+ t.Fatal(err)
+ }
+ got, _ := st.User(user.ID)
+ saved := got.AgentCLICredentials["cursor"].Models
+ if len(saved) != 3 || saved[0].Efforts["xhigh"] != "widget-extra-high" || saved[0].DefaultEffort != "medium" || saved[1].DefaultEffort != "" || saved[2].Efforts != nil {
+ t.Fatalf("saved cursor catalog = %+v", saved)
+ }
+ // The catalog came from this key's plan; a new key drops it.
+ if _, err := st.UpdateUserCredentials(user.ID, UserCredentialUpdate{AgentCLICredentials: map[string]AgentCLICredentialUpdate{
+ "cursor": {APIKey: "crsr_secret"},
+ }}); err != nil {
+ t.Fatal(err)
+ }
+ if got, _ := st.User(user.ID); len(got.AgentCLICredentials["cursor"].Models) != 3 {
+ t.Fatal("saving the same key dropped the catalog")
+ }
+ if _, err := st.UpdateUserCredentials(user.ID, UserCredentialUpdate{AgentCLICredentials: map[string]AgentCLICredentialUpdate{
+ "cursor": {APIKey: "crsr_other"},
+ }}); err != nil {
+ t.Fatal(err)
+ }
+ if got, _ := st.User(user.ID); got.AgentCLICredentials["cursor"].Models != nil {
+ t.Fatalf("new key kept the old catalog: %+v", got.AgentCLICredentials["cursor"])
+ }
+ for name, bad := range map[string]domain.CLIModel{
+ "unknown effort": {ID: "widget", Efforts: map[string]string{"turbo": "widget-turbo"}},
+ "bad target": {ID: "widget", Efforts: map[string]string{"low": "widget low"}},
+ } {
+ if _, err := st.UpdateUserCredentials(user.ID, UserCredentialUpdate{AgentCLICredentials: map[string]AgentCLICredentialUpdate{
+ "cursor": {Models: &[]domain.CLIModel{bad}},
+ }}); err == nil {
+ t.Errorf("%s was accepted", name)
+ }
+ }
+}
diff --git a/internal/repo/users.go b/internal/repo/users.go
index e15ec2c6..6fb2a8f4 100644
--- a/internal/repo/users.go
+++ b/internal/repo/users.go
@@ -4,6 +4,7 @@ import (
"encoding/json"
"errors"
"fmt"
+ "slices"
"sort"
"strings"
"time"
@@ -380,11 +381,17 @@ func applyAgentCLICredentialUpdates(user *domain.User, updates map[string]AgentC
return fmt.Errorf("不支持的 CLI:%s", kind)
}
cred := merged[kind]
+ previousKey := cred.APIKey
if update.APIKeyClear {
cred.APIKey = ""
} else if value := strings.TrimSpace(update.APIKey); value != "" {
cred.APIKey = value
}
+ // Cursor's catalog is the list the key's plan offered (saved by the
+ // chat model list); another key starts from that key's own list.
+ if kind == "cursor" && cred.APIKey != previousKey && update.Models == nil {
+ cred.Models = nil
+ }
if update.BaseURL != nil {
cred.BaseURL = strings.TrimSpace(*update.BaseURL)
}
@@ -462,16 +469,8 @@ func normalizeCLIModels(models []domain.CLIModel) ([]domain.CLIModel, error) {
seen := map[string]bool{}
for _, model := range models {
id, name := strings.TrimSpace(model.ID), strings.TrimSpace(model.Name)
- if id == "" {
- return nil, errors.New("模型 ID 不能为空")
- }
- if len(id) > maxCLIModelIDLen {
- return nil, fmt.Errorf("模型 ID 长度不能超过 %d 个字符", maxCLIModelIDLen)
- }
- for _, r := range id {
- if r <= ' ' || r == 0x7f || r == '"' || r == '\'' || r == '`' || r == '\\' {
- return nil, fmt.Errorf("模型 ID %q 不能包含空格、引号、反斜杠或控制字符", id)
- }
+ if err := validCLIModelID(id); err != nil {
+ return nil, err
}
if seen[id] {
return nil, fmt.Errorf("模型 ID %s 重复", id)
@@ -488,7 +487,52 @@ func normalizeCLIModels(models []domain.CLIModel) ([]domain.CLIModel, error) {
if name == id {
name = ""
}
- out = append(out, domain.CLIModel{ID: id, Name: name})
+ efforts, defaultEffort, err := normalizeCLIModelEfforts(model.Efforts, model.DefaultEffort)
+ if err != nil {
+ return nil, fmt.Errorf("模型 %s:%w", id, err)
+ }
+ out = append(out, domain.CLIModel{ID: id, Name: name, Efforts: efforts, DefaultEffort: defaultEffort})
}
return out, nil
}
+
+func validCLIModelID(id string) error {
+ if id == "" {
+ return errors.New("模型 ID 不能为空")
+ }
+ if len(id) > maxCLIModelIDLen {
+ return fmt.Errorf("模型 ID 长度不能超过 %d 个字符", maxCLIModelIDLen)
+ }
+ for _, r := range id {
+ if r <= ' ' || r == 0x7f || r == '"' || r == '\'' || r == '`' || r == '\\' {
+ return fmt.Errorf("模型 ID %q 不能包含空格、引号、反斜杠或控制字符", id)
+ }
+ }
+ return nil
+}
+
+// normalizeCLIModelEfforts checks the effort→model ID mapping of a Cursor
+// model family: efforts are Cursor's levels and every target is a valid
+// model ID. A default outside the mapping is dropped.
+func normalizeCLIModelEfforts(efforts map[string]string, defaultEffort string) (map[string]string, string, error) {
+ if len(efforts) == 0 {
+ return nil, "", nil
+ }
+ levels := domain.ExecutorEffortLevels["cursor"]
+ out := make(map[string]string, len(efforts))
+ for effort, raw := range efforts {
+ effort, raw = strings.TrimSpace(effort), strings.TrimSpace(raw)
+ if !slices.Contains(levels, effort) {
+ return nil, "", fmt.Errorf("不支持思考强度 %q", effort)
+ }
+ if err := validCLIModelID(raw); err != nil {
+ return nil, "", err
+ }
+ out[effort] = raw
+ }
+ defaultEffort = strings.TrimSpace(defaultEffort)
+ if _, ok := out[defaultEffort]; !ok {
+ defaultEffort = ""
+ }
+ return out, defaultEffort, nil
+}
diff --git a/internal/runner/daemon.go b/internal/runner/daemon.go
index 9c6125df..7c0a4181 100644
--- a/internal/runner/daemon.go
+++ b/internal/runner/daemon.go
@@ -859,7 +859,7 @@ func (d *Daemon) executeInvocation(ctx context.Context, task domain.RunnerTask)
return execResult{status: domain.RunnerTaskFailed, errMsg: err.Error()}, nil
}
if runtime.IsAgentCLI(prepared.Command.Provider) {
- cred := runtime.ProviderCredential{APIKey: inv.AgentCLIAPIKey, BaseURL: inv.AgentCLIBaseURL, Protocol: inv.AgentCLIProtocol}
+ cred := runtime.ProviderCredential{APIKey: inv.AgentCLIAPIKey, BaseURL: inv.AgentCLIBaseURL, Protocol: inv.AgentCLIProtocol, Models: inv.AgentCLIModels}
var agentEnv map[string]string
argv, agentEnv, err = runtime.BindAgentCLICommand(sandbox, workspace, prepared.Command, cred, argv)
if err != nil {
diff --git a/internal/runtime/agent_cli.go b/internal/runtime/agent_cli.go
index 8dbfeed6..71adc55a 100644
--- a/internal/runtime/agent_cli.go
+++ b/internal/runtime/agent_cli.go
@@ -79,6 +79,9 @@ func agentCLIModelOptional(kind, baseURL string) bool {
// needs to render a CLI's model configuration.
type AgentCLIOptions struct {
Model string
+ // Effort is the reasoning effort chosen for Model; Cursor resolves the
+ // pair to one model ID with the owner's catalog.
+ Effort string
// SystemPromptFile is the system prompt path as the process sees it
// (relative paths resolve against the working directory).
SystemPromptFile string
@@ -402,6 +405,9 @@ func ApplyAgentCLICredential(kind string, cred ProviderCredential, options Agent
env["OPENCODE_DISABLE_AUTOUPDATE"] = "1"
case AgentCLICursor:
env["CURSOR_API_KEY"] = key
+ if model != "" {
+ argv = withCursorModelArg(argv, CursorModelID(model, options.Effort, cred.Models))
+ }
case AgentCLIAntigravity:
settings := map[string]any{}
if protocol == AgentCLIProtocolChat {
@@ -537,7 +543,7 @@ func AgentCLIUserCredentials(user domain.User) map[string]ProviderCredential {
}
out := make(map[string]ProviderCredential, len(user.AgentCLICredentials))
for kind, cred := range user.AgentCLICredentials {
- out[kind] = ProviderCredential{APIKey: cred.APIKey, BaseURL: cred.BaseURL, Protocol: cred.Protocol}
+ out[kind] = ProviderCredential{APIKey: cred.APIKey, BaseURL: cred.BaseURL, Protocol: cred.Protocol, Models: cred.Models}
}
return out
}
@@ -571,3 +577,18 @@ func AgentCLIBinary(kind string) string {
}
return kind
}
+
+// withCursorModelArg replaces the value of the first --model option.
+func withCursorModelArg(argv []string, id string) []string {
+ for i := 0; i+1 < len(argv); i++ {
+ if argv[i] == "--model" {
+ if argv[i+1] == id {
+ return argv
+ }
+ out := append([]string{}, argv...)
+ out[i+1] = id
+ return out
+ }
+ }
+ return argv
+}
diff --git a/internal/runtime/agent_cli_test.go b/internal/runtime/agent_cli_test.go
index 9cd69276..c0e8a374 100644
--- a/internal/runtime/agent_cli_test.go
+++ b/internal/runtime/agent_cli_test.go
@@ -4,6 +4,7 @@ import (
"encoding/json"
"os"
"path/filepath"
+ "reflect"
"slices"
"strconv"
"strings"
@@ -273,8 +274,9 @@ func TestAgentCLITranslatorDeepSeekReplacesTruncatedTextWithFinal(t *testing.T)
}
func TestAgentCLIUserCredentials(t *testing.T) {
- creds := AgentCLIUserCredentials(domain.User{AgentCLICredentials: map[string]domain.AgentCLICredential{"kimi": {APIKey: "k", BaseURL: "u", Protocol: "messages"}}})
- if creds["kimi"] != (ProviderCredential{APIKey: "k", BaseURL: "u", Protocol: "messages"}) {
+ models := []domain.CLIModel{{ID: "widget", Efforts: map[string]string{"low": "widget-low"}}}
+ creds := AgentCLIUserCredentials(domain.User{AgentCLICredentials: map[string]domain.AgentCLICredential{"kimi": {APIKey: "k", BaseURL: "u", Protocol: "messages", Models: models}}})
+ if !reflect.DeepEqual(creds["kimi"], ProviderCredential{APIKey: "k", BaseURL: "u", Protocol: "messages", Models: models}) {
t.Fatalf("credentials: %+v", creds)
}
if AgentCLIUserCredentials(domain.User{}) != nil {
diff --git a/internal/runtime/cursor_models.go b/internal/runtime/cursor_models.go
index c8804a2f..3e0af88d 100644
--- a/internal/runtime/cursor_models.go
+++ b/internal/runtime/cursor_models.go
@@ -2,6 +2,7 @@ package runtime
import (
"slices"
+ "strings"
"agentflow/internal/domain"
)
@@ -82,6 +83,8 @@ var cursorModels = []CursorModel{
{ID: "gpt-5.2-fast", Name: "GPT-5.2 Fast", Default: "medium", Variants: map[string]string{"low": "gpt-5.2-low-fast", "medium": "gpt-5.2-fast", "high": "gpt-5.2-high-fast", "xhigh": "gpt-5.2-xhigh-fast"}},
{ID: "gpt-5.1", Name: "GPT-5.1", Default: "medium", Variants: map[string]string{"low": "gpt-5.1-low", "medium": "gpt-5.1", "high": "gpt-5.1-high"}},
{ID: "gpt-5-mini", Name: "GPT-5 Mini", Default: "", Variants: map[string]string{"": "gpt-5-mini"}},
+ {ID: "gemini-4-carbon", Name: "Gemini 4 Carbon", Default: "medium", Variants: map[string]string{"low": "gemini-4-carbon-low", "medium": "gemini-4-carbon-medium", "high": "gemini-4-carbon-high"}},
+ {ID: "gemini-4-hydrogen", Name: "Gemini 4 Hydrogen", Default: "medium", Variants: map[string]string{"low": "gemini-4-hydrogen-low", "medium": "gemini-4-hydrogen-medium", "high": "gemini-4-hydrogen-high", "xhigh": "gemini-4-hydrogen-xhigh"}},
{ID: "gemini-4-argon", Name: "Gemini 4 Argon", Default: "medium", Variants: map[string]string{"low": "gemini-4-argon-low", "medium": "gemini-4-argon-medium", "high": "gemini-4-argon-high"}},
{ID: "gemini-3.8-flash", Name: "Gemini 3.8 Flash", Default: "medium", Variants: map[string]string{"low": "gemini-3.8-flash-low", "medium": "gemini-3.8-flash-medium", "high": "gemini-3.8-flash-high"}},
{ID: "gemini-3.7-flash", Name: "Gemini 3.7 Flash", Default: "high", Variants: map[string]string{"low": "gemini-3.7-flash-low", "medium": "gemini-3.7-flash-medium", "high": "gemini-3.7-flash-high"}},
@@ -118,26 +121,37 @@ func CursorModelFamily(id string) (CursorModel, bool) {
}
// CursorModelEfforts lists the efforts of a family, weakest first; nil for
-// a model ID outside the table or without effort variants.
-func CursorModelEfforts(id string) []string {
+// a model ID outside the known families or without effort variants. catalog
+// is the owner's saved Cursor model list: families folded out of their CLI's
+// own list (FoldCursorCLIModels) resolve from it.
+func CursorModelEfforts(id string, catalog []domain.CLIModel) []string {
+ model, ok := lookupCursorFamily(id, catalog)
+ if !ok {
+ return nil
+ }
var out []string
for _, effort := range domain.ExecutorEffortLevels[AgentCLICursor] {
- if _, ok := cursorModelByID[id].Variants[effort]; ok {
+ if _, ok := model.Variants[effort]; ok {
out = append(out, effort)
}
}
return out
}
-// CursorModelID resolves a family and effort to the cursor-agent model ID.
-// An empty effort takes the family default and an effort the family lacks
-// the closest one (the stronger on a tie); IDs outside the table, including
-// raw cursor-agent IDs, pass through.
-func CursorModelID(id, effort string) string {
- model, ok := cursorModelByID[id]
- if !ok {
- return id
+// CursorModelID resolves a family and effort to the cursor-agent model ID,
+// looking the family up in the built-in table, then in catalog (see
+// CursorModelEfforts). An empty effort takes the family default and an
+// effort the family lacks the closest one (the stronger on a tie). Any other
+// ID passes through unchanged: only a family known to have an effort may
+// gain its suffix, otherwise the CLI would get an ID it never listed.
+func CursorModelID(id, effort string, catalog []domain.CLIModel) string {
+ if model, ok := lookupCursorFamily(id, catalog); ok {
+ return cursorVariantID(model, effort)
}
+ return id
+}
+
+func cursorVariantID(model CursorModel, effort string) string {
if raw, ok := model.Variants[""]; ok {
return raw
}
@@ -164,3 +178,227 @@ func abs(n int) int {
}
return n
}
+
+// cursorEffortSuffixes are the trailing tokens cursor-agent appends to a
+// family ID. Longer tokens come first so xhigh is not read as high.
+// extra-high is the spelling some models use for xhigh.
+var cursorEffortSuffixes = []struct{ token, effort string }{
+ {"extra-high", "xhigh"},
+ {"minimal", "minimal"},
+ {"medium", "medium"},
+ {"xhigh", "xhigh"},
+ {"ultra", "ultra"},
+ {"high", "high"},
+ {"none", "none"},
+ {"max", "max"},
+ {"low", "low"},
+}
+
+var cursorEffortNameSuffixes = []string{"Extra High", "Minimal", "Medium", "Xhigh", "Ultra", "High", "None", "Max", "Low"}
+
+func lookupCursorFamily(id string, catalog []domain.CLIModel) (CursorModel, bool) {
+ if model, ok := cursorModelByID[id]; ok {
+ return model, true
+ }
+ for _, entry := range catalog {
+ if entry.ID != id || len(entry.Efforts) == 0 {
+ continue
+ }
+ variants := map[string]string{}
+ for effort, raw := range entry.Efforts {
+ if cursorEffortToken(effort) != "" && strings.TrimSpace(raw) != "" {
+ variants[effort] = strings.TrimSpace(raw)
+ }
+ }
+ if len(variants) == 0 {
+ return CursorModel{}, false
+ }
+ def := entry.DefaultEffort
+ if _, ok := variants[def]; !ok {
+ def = inferredCursorDefault(variants)
+ }
+ return CursorModel{ID: id, Name: entry.Name, Default: def, Variants: variants}, true
+ }
+ return CursorModel{}, false
+}
+
+func cursorEffortToken(effort string) string {
+ switch strings.TrimSpace(effort) {
+ case "none", "minimal", "low", "medium", "high", "xhigh", "max", "ultra":
+ return effort
+ default:
+ return ""
+ }
+}
+
+// splitCursorEffortID reports the family and effort of a cursor-agent model
+// ID. A trailing -fast stays on the family: speed is its own family.
+func splitCursorEffortID(id string) (family, effort string, ok bool) {
+ fast := false
+ if base, found := strings.CutSuffix(id, "-fast"); found && base != "" {
+ id, fast = base, true
+ }
+ for _, suffix := range cursorEffortSuffixes {
+ base, found := strings.CutSuffix(id, "-"+suffix.token)
+ if !found || base == "" {
+ continue
+ }
+ if fast {
+ base += "-fast"
+ }
+ return base, suffix.effort, true
+ }
+ return "", "", false
+}
+
+// stripCursorEffortName drops the effort word from a cursor-agent model
+// name, keeping a trailing Fast and any trailing notes in parentheses:
+// "Gemini 4 Carbon Medium (NO ZDR)" names the family "Gemini 4 Carbon (NO ZDR)".
+func stripCursorEffortName(name string) string {
+ name = strings.TrimSpace(name)
+ notes := ""
+ for strings.HasSuffix(name, ")") {
+ open := strings.LastIndex(name, " (")
+ if open <= 0 {
+ break
+ }
+ notes = name[open:] + notes
+ name = strings.TrimSpace(name[:open])
+ }
+ fast := false
+ if base, found := strings.CutSuffix(name, " Fast"); found && strings.TrimSpace(base) != "" {
+ name, fast = strings.TrimSpace(base), true
+ }
+ for _, suffix := range cursorEffortNameSuffixes {
+ if len(name) <= len(suffix)+1 || name[len(name)-len(suffix)-1] != ' ' {
+ continue
+ }
+ if strings.EqualFold(name[len(name)-len(suffix):], suffix) {
+ name = strings.TrimSpace(name[:len(name)-len(suffix)])
+ break
+ }
+ }
+ if fast {
+ name += " Fast"
+ }
+ return name + notes
+}
+
+func inferredCursorDefault(variants map[string]string) string {
+ if _, ok := variants["medium"]; ok {
+ return "medium"
+ }
+ levels := domain.ExecutorEffortLevels[AgentCLICursor]
+ want := slices.Index(levels, "medium")
+ best, distance, bestIndex := "", len(levels)+1, -1
+ for i, level := range levels {
+ if _, ok := variants[level]; !ok {
+ continue
+ }
+ gap := abs(i - want)
+ if best == "" || gap < distance || (gap == distance && i > bestIndex) {
+ best, distance, bestIndex = level, gap, i
+ }
+ }
+ return best
+}
+
+// FoldCursorCLIModels collapses cursor-agent's per-effort IDs into one row
+// per family. Families in the built-in table keep that table's name and
+// order. Other IDs ending in a recognized effort suffix fold the same way,
+// and the rest stay as the CLI listed them. Such a folded row carries its
+// effort→ID mapping (Efforts, DefaultEffort); it is saved with the owner's
+// Cursor catalog, which CursorModelID and CursorModelEfforts resolve from.
+func FoldCursorCLIModels(models []domain.CLIModel) []domain.CLIModel {
+ present := map[string]bool{}
+ type group struct {
+ name string
+ variants map[string]string
+ }
+ groups := map[string]*group{}
+ type slot struct {
+ family bool
+ id string
+ plain domain.CLIModel
+ }
+ var tail []slot
+ seen := map[string]bool{}
+ for _, model := range models {
+ id := strings.TrimSpace(model.ID)
+ if id == "" {
+ continue
+ }
+ if family, ok := CursorModelFamily(id); ok {
+ present[family.ID] = true
+ continue
+ }
+ if familyID, effort, ok := splitCursorEffortID(id); ok {
+ if _, known := cursorModelByID[familyID]; known {
+ present[familyID] = true
+ continue
+ }
+ g := groups[familyID]
+ if g == nil {
+ g = &group{variants: map[string]string{}}
+ groups[familyID] = g
+ if !seen["family:"+familyID] {
+ seen["family:"+familyID] = true
+ tail = append(tail, slot{family: true, id: familyID})
+ }
+ }
+ if _, exists := g.variants[effort]; !exists {
+ g.variants[effort] = id
+ }
+ if stripped := stripCursorEffortName(model.Name); stripped != "" && (g.name == "" || effort == "medium") {
+ g.name = stripped
+ }
+ continue
+ }
+ if seen["plain:"+id] {
+ continue
+ }
+ seen["plain:"+id] = true
+ tail = append(tail, slot{id: id, plain: domain.CLIModel{ID: id, Name: strings.TrimSpace(model.Name)}})
+ }
+ var dynamic []slot
+ for _, item := range tail {
+ if item.family {
+ dynamic = append(dynamic, item)
+ continue
+ }
+ g := groups[item.id]
+ if g == nil {
+ dynamic = append(dynamic, item)
+ continue
+ }
+ if _, ok := g.variants["medium"]; !ok {
+ g.variants["medium"] = item.id
+ if item.plain.Name != "" {
+ g.name = item.plain.Name
+ }
+ }
+ }
+ out := make([]domain.CLIModel, 0, len(present)+len(dynamic))
+ for _, family := range cursorModels {
+ if present[family.ID] {
+ out = append(out, domain.CLIModel{ID: family.ID, Name: family.Name})
+ }
+ }
+ for _, item := range dynamic {
+ if !item.family {
+ out = append(out, item.plain)
+ continue
+ }
+ g := groups[item.id]
+ name := g.name
+ if name == "" {
+ name = item.id
+ }
+ variants := make(map[string]string, len(g.variants))
+ for effort, raw := range g.variants {
+ variants[effort] = raw
+ }
+ out = append(out, domain.CLIModel{ID: item.id, Name: name, Efforts: variants, DefaultEffort: inferredCursorDefault(variants)})
+ }
+ return out
+}
diff --git a/internal/runtime/cursor_models_test.go b/internal/runtime/cursor_models_test.go
index 8bde0a2a..00c99721 100644
--- a/internal/runtime/cursor_models_test.go
+++ b/internal/runtime/cursor_models_test.go
@@ -1,6 +1,7 @@
package runtime
import (
+ "reflect"
"slices"
"testing"
@@ -42,21 +43,31 @@ func TestCursorModelID(t *testing.T) {
{"gemini-4-argon", "max", "gemini-4-argon-high"},
{"composer-2.5", "high", "composer-2.5"},
{"auto", "", "auto"},
- // Raw IDs and unknown models pass through.
+ {"gemini-4-carbon", "", "gemini-4-carbon-medium"},
+ {"gemini-4-carbon", "high", "gemini-4-carbon-high"},
+ {"gemini-4-hydrogen", "xhigh", "gemini-4-hydrogen-xhigh"},
+ {"gemini-4-hydrogen", "max", "gemini-4-hydrogen-xhigh"},
+ // A raw effort ID keeps that effort.
{"claude-opus-5-high", "low", "claude-opus-5-high"},
- {"some-new-model", "high", "some-new-model"},
+ // An ID outside the table and the catalog never gains a suffix: the
+ // CLI only accepts IDs it listed (grok-5-code-high does not exist).
+ {"grok-5-code", "high", "grok-5-code"},
+ {"some-new-model", "", "some-new-model"},
}
for _, c := range cases {
- if got := CursorModelID(c.id, c.effort); got != c.want {
+ if got := CursorModelID(c.id, c.effort, nil); got != c.want {
t.Errorf("CursorModelID(%q, %q) = %q, want %q", c.id, c.effort, got, c.want)
}
}
- if got := CursorModelEfforts("kimi-k3"); !slices.Equal(got, []string{"low", "high", "max"}) {
+ if got := CursorModelEfforts("kimi-k3", nil); !slices.Equal(got, []string{"low", "high", "max"}) {
t.Errorf("kimi-k3 efforts: %v", got)
}
- if got := CursorModelEfforts("composer-2.5"); got != nil {
+ if got := CursorModelEfforts("composer-2.5", nil); got != nil {
t.Errorf("composer efforts: %v", got)
}
+ if got := CursorModelEfforts("grok-5-code", nil); got != nil {
+ t.Errorf("unknown model efforts: %v", got)
+ }
if family, ok := CursorModelFamily("gpt-5.6-terra-xhigh-fast"); !ok || family.ID != "gpt-5.6-terra-fast" {
t.Errorf("family of a fast variant: %+v %v", family, ok)
}
@@ -64,4 +75,106 @@ func TestCursorModelID(t *testing.T) {
if i := slices.Index(argv, "--model"); i < 0 || argv[i+1] != "claude-opus-4-8-thinking-xhigh" {
t.Errorf("cursor argv: %q", argv)
}
+ // The SOP path: an unknown ID with an effort reaches the CLI unchanged.
+ argv = AgentCLICommand(AgentCLICursor, AgentCLICommandOptions{Model: "grok-5-code", Effort: "high", Prompt: "p"}).Argv
+ if i := slices.Index(argv, "--model"); i < 0 || argv[i+1] != "grok-5-code" {
+ t.Errorf("unknown model argv: %q", argv)
+ }
+}
+
+func TestFoldCursorCLIModels(t *testing.T) {
+ got := FoldCursorCLIModels([]domain.CLIModel{
+ {ID: "gemini-4-carbon-high", Name: "Gemini 4 Carbon High"},
+ {ID: "gemini-4-carbon-low", Name: "Gemini 4 Carbon Low"},
+ {ID: "gemini-4-carbon-medium", Name: "Gemini 4 Carbon Medium"},
+ {ID: "gemini-4-hydrogen-xhigh", Name: "Gemini 4 Hydrogen Extra High"},
+ {ID: "widget-extra-high", Name: "Widget Extra High"},
+ {ID: "widget-low", Name: "Widget Low"},
+ {ID: "widget", Name: "Widget"},
+ {ID: "widget-low-fast", Name: "Widget Low Fast"},
+ {ID: "widget-high-fast", Name: "Widget High Fast"},
+ {ID: "plain-model", Name: "Plain Model"},
+ {ID: "solo-ultra", Name: "Solo Ultra"},
+ {ID: "nova-medium", Name: "Nova Medium (NO ZDR)"},
+ {ID: "nova-high", Name: "Nova High (NO ZDR)"},
+ })
+ want := []domain.CLIModel{
+ {ID: "gemini-4-carbon", Name: "Gemini 4 Carbon"},
+ {ID: "gemini-4-hydrogen", Name: "Gemini 4 Hydrogen"},
+ {ID: "widget", Name: "Widget", DefaultEffort: "medium", Efforts: map[string]string{"low": "widget-low", "medium": "widget", "xhigh": "widget-extra-high"}},
+ {ID: "widget-fast", Name: "Widget Fast", DefaultEffort: "high", Efforts: map[string]string{"low": "widget-low-fast", "high": "widget-high-fast"}},
+ {ID: "plain-model", Name: "Plain Model"},
+ {ID: "solo", Name: "Solo", DefaultEffort: "ultra", Efforts: map[string]string{"ultra": "solo-ultra"}},
+ {ID: "nova", Name: "Nova (NO ZDR)", DefaultEffort: "medium", Efforts: map[string]string{"medium": "nova-medium", "high": "nova-high"}},
+ }
+ if !reflect.DeepEqual(got, want) {
+ t.Fatalf("folded models:\n got %+v\nwant %+v", got, want)
+ }
+ // The folded rows are what gets saved; they resolve without any state
+ // left behind by the fold, as after a restart or on another instance.
+ cases := []struct{ id, effort, want string }{
+ {"widget", "xhigh", "widget-extra-high"},
+ {"widget", "", "widget"},
+ {"widget-fast", "high", "widget-high-fast"},
+ {"solo", "", "solo-ultra"},
+ {"nova", "max", "nova-high"},
+ }
+ for _, c := range cases {
+ if got := CursorModelID(c.id, c.effort, want); got != c.want {
+ t.Errorf("CursorModelID(%q, %q) = %q, want %q", c.id, c.effort, got, c.want)
+ }
+ if got := CursorModelID(c.id, c.effort, nil); got != c.id {
+ t.Errorf("without the catalog %q/%q = %q, want it unchanged", c.id, c.effort, got)
+ }
+ }
+ if got := CursorModelEfforts("widget", want); !slices.Equal(got, []string{"low", "medium", "xhigh"}) {
+ t.Errorf("widget efforts: %v", got)
+ }
+ if got := CursorModelEfforts("solo", want); !slices.Equal(got, []string{"ultra"}) {
+ t.Errorf("solo efforts: %v", got)
+ }
+ // Each user resolves against their own list: another user's CLI may map
+ // the same family differently or not offer it at all.
+ other := []domain.CLIModel{{ID: "widget", Efforts: map[string]string{"high": "widget-high"}, DefaultEffort: "high"}}
+ if got := CursorModelID("widget", "xhigh", other); got != "widget-high" {
+ t.Errorf("other user's widget = %q", got)
+ }
+ if got := CursorModelEfforts("widget", nil); got != nil {
+ t.Errorf("widget efforts without a catalog: %v", got)
+ }
+}
+
+func TestStripCursorEffortName(t *testing.T) {
+ for name, want := range map[string]string{
+ "Gemini 4 Carbon Medium": "Gemini 4 Carbon",
+ "Medium Model Medium (NO ZDR)": "Medium Model (NO ZDR)",
+ "Widget Extra High Fast": "Widget Fast",
+ "Widget High Fast (NO ZDR)": "Widget Fast (NO ZDR)",
+ "Claude Fable 5.1 Max (NO ZDR)": "Claude Fable 5.1 (NO ZDR)",
+ "Nova Low (preview) (NO ZDR)": "Nova (preview) (NO ZDR)",
+ "Plain (NO ZDR)": "Plain (NO ZDR)",
+ } {
+ if got := stripCursorEffortName(name); got != want {
+ t.Errorf("stripCursorEffortName(%q) = %q, want %q", name, got, want)
+ }
+ }
+}
+
+func TestCursorCredentialResolvesSavedFamily(t *testing.T) {
+ catalog := []domain.CLIModel{{ID: "widget", Efforts: map[string]string{"low": "widget-low", "medium": "widget", "xhigh": "widget-extra-high"}, DefaultEffort: "medium"}}
+ command := AgentCLICommand(AgentCLICursor, AgentCLICommandOptions{Model: "widget", Effort: "xhigh", Prompt: "p"})
+ if i := slices.Index(command.Argv, "--model"); command.Argv[i+1] != "widget" {
+ t.Fatalf("argv before the credential: %q", command.Argv)
+ }
+ home := AgentCLIHome{Base: t.TempDir(), Rel: "home"}
+ argv, env, err := ApplyAgentCLICredential(AgentCLICursor, ProviderCredential{APIKey: "crsr_x", Models: catalog}, command.AgentCLI, home, home.Base, command.Argv)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if i := slices.Index(argv, "--model"); argv[i+1] != "widget-extra-high" || env["CURSOR_API_KEY"] != "crsr_x" {
+ t.Fatalf("bound argv %q env %v", argv, env)
+ }
+ if argv[len(argv)-1] != "p" {
+ t.Fatalf("prompt moved: %q", argv)
+ }
}
diff --git a/internal/runtime/provider_agentcli.go b/internal/runtime/provider_agentcli.go
index 80d0483f..2bb11df9 100644
--- a/internal/runtime/provider_agentcli.go
+++ b/internal/runtime/provider_agentcli.go
@@ -137,7 +137,10 @@ func AgentCLICommand(kind string, o AgentCLICommandOptions) CommandSpec {
// still approves the MCP tools.
argv = []string{binary, "-p", "--output-format", "stream-json", "--stream-partial-output", "--trust", "--force", "--approve-mcps"}
if model != "" {
- argv = append(argv, "--model", CursorModelID(model, effort))
+ // ApplyAgentCLICredential re-resolves this against the owner's
+ // saved catalog, which only the credential carries.
+ argv = append(argv, "--model", CursorModelID(model, effort, nil))
+ options.Effort = effort
}
if resume != "" {
argv = append(argv, "--resume", resume)
diff --git a/internal/runtime/runtime.go b/internal/runtime/runtime.go
index 4b3c7e9c..99f398b0 100644
--- a/internal/runtime/runtime.go
+++ b/internal/runtime/runtime.go
@@ -55,6 +55,9 @@ type ProviderCredential struct {
APIKey string
BaseURL string
Protocol string
+ // Models is the user's saved model catalog for an agent CLI; Cursor
+ // resolves folded families from it (CursorModelID).
+ Models []domain.CLIModel
}
type InvocationOptions struct {