After #2081 gave Desktop a subagent model, its effort still came from the request. Add subagent_effort beside that model, using the existing effort slider. The live setting DesktopSubagentEffort belongs to magpie; no Claude client file or binary is changed. Empty preserves the request's effort, including disabled thinking. A pick applies only to Desktop requests with an agent id and tools, independently of model replacement: unset, equal and unavailable model picks all work. Reuse the attempt-level fitting; fixed group-member efforts and reasonless models keep their existing precedence. count_tokens applies the pick after unmasked-body restoration. A Codex SubagentPick is not evidence of a Desktop tool turn. Route.Effort keeps the incoming level, SubagentEffort records the configured pick, and tries/usage keep the actual level. Routing explains the pick even without a model replacement. Options follow the target model; a saved level survives a model change. POST /api/settings preserves it. Disconnected preferences, Disconnect/reconnect and restored settings work; a Live pick gives restart advice only when it actually connects the agent. Codex's own settings and default-effort explanation are unchanged. Verification onb9c589ebplus this change, with temp HOME and pinned Go caches: - go test -tags nogui ./...: 53 packages pass. - Gateway effort tests under -race -count=20: pass. - gofmt -l: empty; darwin, linux nogui and windows vet/build: exit 0. - 23 intentional Go behavior breaks produce real FAILs, then pass restored: application, scope, model independence, Default/none, disabled thinking, fitting/member priority, counts, next request, trace, saving/validation, Live notices and model-dependent options. - Three UI breaks fail in both engines at 1100/420: default explanation, missing effort story and missing translation. Restored: Desktop's new controls/story matrix passes 20/20 across five languages. Desktop, Codex, tier/effort and translation regressions pass 97/97. - Desktop-bundled Claude Code 2.1.295 runs real Agent calls through the built gateway, temporary HOME and loopback-only sandbox, all replies local fixtures. Low/high/Default sends its child low/high/xhigh on m2; its lead remains xhigh on m1. All three runs exit 0. The expanded Routing run is not green: Chromium 510/525, WebKit 485/525. These failures reproduce on untouchedb9c589eb, including targeted reruns. The day/row anchor assertions conflict with #2134's at-top rule: undoing that one guard makes all 12 tests pass. A narrow request lies below the viewport; user wheel input makes the failed click pass. WorkBuddy's wheel pointer/hidden-button failures overlap #2115; moving the wheel to the view gutter fixes 3/4 selected cases, one WebKit 420 case remains. The held-member clipping assertion also reproduces on base; its timing cause is not established. This baseline evidence is reported separately in the follow-up feature issue, not counted as passed or fixed here. Not run: the complete GUI suite, the Electron window/Cowork, native Linux/Windows or WebKitGTK. Cross-builds are not runtime checks. Reported-by: Koohoko
100 lines
3.7 KiB
Go
100 lines
3.7 KiB
Go
package provider
|
|
|
|
import (
|
|
"fmt"
|
|
"slices"
|
|
"strings"
|
|
|
|
"github.com/yetone/magpie/internal/settings"
|
|
)
|
|
|
|
// Claude Desktop runs the Claude Code of its Code tab with
|
|
// CLAUDE_CODE_PROVIDER_MANAGED_BY_HOST=1, and Claude Code then drops
|
|
// CLAUDE_CODE_SUBAGENT_MODEL, CLAUDE_CODE_SUBAGENT_MODEL_FORCE and the
|
|
// tiers' variables from the env of its settings files ("Ignoring … this
|
|
// session's provider routing is managed by the host", Claude Code
|
|
// 2.1.295). Desktop's own config has no key for it either (the env it
|
|
// builds for the Code tab, Desktop 2.31226). So the subagent model magpie
|
|
// writes into ~/.claude doesn't reach Desktop: its subagents run on the
|
|
// lead's model or on a tier's, and only the tiers could be picked.
|
|
// settings.DesktopSubagentModel is the model magpie puts every subagent
|
|
// turn of Desktop's on, whatever its lead or tier asked for: the gateway
|
|
// rewrites a subagent's request (x-claude-code-agent-id, with tools) to
|
|
// it, read on each request, so Desktop needn't restart. Its lead's turns
|
|
// and the tool-less helper calls Claude Code makes inside a subagent stay
|
|
// on the model they asked for. "" leaves every subagent as it was.
|
|
|
|
// DesktopSubagentModel is the model Desktop's subagents are put on, ""
|
|
// for the one the lead asks for. A provider renamed since it was set is
|
|
// named by its new id (RenamedRef), as a profile's model is.
|
|
func DesktopSubagentModel() string {
|
|
id := strings.TrimSpace(heldSettings().DesktopSubagentModel)
|
|
if id == "" {
|
|
return ""
|
|
}
|
|
return RenamedRef(id)
|
|
}
|
|
|
|
// SetDesktopSubagentModel puts Desktop's subagent turns on id, a model or
|
|
// routing group of magpie's (provider/model, group/<id>); "" leaves them
|
|
// on the model their lead asks for. One magpie doesn't serve now is kept
|
|
// all the same, as Codex's subagent model is, so a backup or profile put
|
|
// back on a computer whose providers differ still applies; the gateway
|
|
// leaves subagents on the model asked for until it is served. A bare name
|
|
// is refused: it names no model of magpie's.
|
|
func SetDesktopSubagentModel(id string) error {
|
|
id = strings.TrimSpace(id)
|
|
if pid, model, ok := strings.Cut(id, "/"); id != "" && (!ok || pid == "" || model == "") {
|
|
return fmt.Errorf("Claude Desktop's subagents can't be put on %q: pick one of magpie's models (provider/model)", id)
|
|
}
|
|
s := settings.Load()
|
|
if s.DesktopSubagentModel == id {
|
|
return nil
|
|
}
|
|
s.DesktopSubagentModel = id
|
|
if err := settings.Save(s); err != nil {
|
|
return err
|
|
}
|
|
Changed()
|
|
return nil
|
|
}
|
|
|
|
// DesktopSubagentUnserved says why Desktop's subagents can't be put on
|
|
// id now, "" when magpie serves that exact model or routing group.
|
|
// Resolve isn't enough: it takes any model name under a provider that is
|
|
// on, and the subagent would go to the vendor for a model it lacks.
|
|
func DesktopSubagentUnserved(id string) string {
|
|
id = RenamedRef(id)
|
|
for _, e := range Served() {
|
|
if e.ID == id {
|
|
return ""
|
|
}
|
|
}
|
|
return "magpie doesn't serve it now"
|
|
}
|
|
|
|
// DesktopSubagentEffort is the effort set for Desktop's subagent turns,
|
|
// independent of their model. Empty leaves each request's effort alone.
|
|
func DesktopSubagentEffort() string {
|
|
return heldSettings().DesktopSubagentEffort
|
|
}
|
|
|
|
// SetDesktopSubagentEffort sets a level the gateway fits to the model
|
|
// each subagent reaches. It survives model changes; "" clears the pick.
|
|
func SetDesktopSubagentEffort(level string) error {
|
|
level = strings.ToLower(strings.TrimSpace(level))
|
|
if level != "" && !slices.Contains(MemberEfforts, level) {
|
|
return fmt.Errorf("%q is not a reasoning effort: one of %s", level, strings.Join(MemberEfforts, ", "))
|
|
}
|
|
s := settings.Load()
|
|
if s.DesktopSubagentEffort == level {
|
|
return nil
|
|
}
|
|
s.DesktopSubagentEffort = level
|
|
if err := settings.Save(s); err != nil {
|
|
return err
|
|
}
|
|
Changed()
|
|
return nil
|
|
}
|