Files
magpie/internal/provider/desktop_subagent.go
T
yetone 60f0433d1b dsh: a model of its own for DeepSeek Harness's compaction (Musikrv77852 on X, #5395)
DSH compacts on the session's latest model (compaction-basic with no
summarizationModel). A session on magpie/workbuddy/deepseek-v4.1-flash
switched to another model compacted on WorkBuddy first, got 429, and the
switch failed.

DeepSeek Harness's opened row on the Agents page now has a "compaction
model" square (compact_model), offered once dsh is on magpie's route. It
is magpie's own Live setting (settings.DshCompactModel), so nothing is
written into dsh's profiles and no restart is needed. The gateway moves a
dsh compaction to it (dshCompactTo, Route.Moved why "dsh-compact") when
the model is enabled, served by its exact id and allowed to the key; else
the compaction stays as asked with a log line. The Routing page says why.

On magpie's llm-pi-ai routes DSH sends no x-deepseek-harness-compact mark,
so its compaction is now known by compaction-basic's own ask
(@deepseek-ai/dsh-compaction-basic 0.0.1-rc.3, the latest) in
compactAsks. As a result DSH compactions show as Compaction in Usage and
Routing, and a group's Compact rule reaches them too.

The options are spelt magpie/<id> like the model field's, so
`magpie dsh deepseek/flash` still sets the model (fieldForValue gives a
bare value to the first field offering it). CLI: `magpie dsh
compact_model magpie/deepseek/flash`; API: /api/set. zh, zh-TW, ja and
de strings added.

Run (mote): go test -count=1 -timeout 45m on internal/gateway,
provider: ok at the base before the rebase on 0842bc517; agent, gui,
settings, settingsapi, and the gateway's TestDsh/TestCompacting/
TestRuleCompact: ok at this head. The first agent run caught the square
reading dsh's profiles at a stopped WSL distro (TestWSLColdPlaceOpensNothing,
#3896); its options now look at nothing at a cold place. go vet on darwin,
GOOS=linux -tags nogui and GOOS=windows: clean. gofmt clean. GUI in
chromium and webkit: dsh-compact-model (new, 5 languages x 2 widths),
desktop-subagent-model, codex-subagent-model, routing-moved-why,
i18n-keys, i18n-en-no-cjk, claude-subagent-effort-row,
codex-start-model-field, model-test-why and agent-connect-no-models: 140
of 140 pass; after the rebase (i18n.js changed upstream) i18n-keys,
i18n-en-no-cjk, dsh-compact-model and routing-moved-why 48 of 48.

Broken by hand, each red: dropping the compactAsks line (TestCompacting,
TestDshCompactMoved on all three protocols), skipping the move in serve
(TestDshCompactMoved), dropping the agent check (TestDshCompactLeft's
other agent), taking the square out of extra() and dropping the routing
story's case (dsh-compact-model.test.cjs).

Not tried: a real DeepSeek Harness desktop app (none on this Mac or on
mote); the compaction text was checked against the npm package's source.
DS Bot's requests can't be told from dsh's, so its compactions follow
the same setting, though it has no square of its own.
2026-11-10 11:05:59 +08:00

104 lines
3.9 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 { return Unserved(id) }
// Unserved says why a request can't be put on id, a model or routing
// group a setting of magpie's names, "" when magpie serves that exact one.
func Unserved(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
}