From 2dc8e249cb9d2e7eb8268d7dd0e012877fb51eb4 Mon Sep 17 00:00:00 2001 From: yetone Date: Sun, 4 Oct 2026 22:03:41 +0800 Subject: [PATCH] =?UTF-8?q?agent:=20dsh=20on=20a=20DeepSeek=20model=20pick?= =?UTF-8?q?ed=20in=20its=20own=20/model=20stays=20connected=20while=20magp?= =?UTF-8?q?ie's=20route=20is=20in=20its=20list=20(Fate=20on=20Discord:=20D?= =?UTF-8?q?SH=20went=20back=20to=20Not=20connected)=20=E2=80=94=20magpie?= =?UTF-8?q?=20connects=20dsh=20by=20putting=20its=20route=20among=20dsh's?= =?UTF-8?q?=20custom=20providers=20and=20starting=20it=20on=20one=20of=20m?= =?UTF-8?q?agpie's=20models;=20a=20model=20of=20DeepSeek's=20own=20picked?= =?UTF-8?q?=20in=20dsh=20is=20saved=20in=20its=20settings.yaml=20over=20th?= =?UTF-8?q?e=20patch=20list,=20and=20the=20Agents=20page,=20which=20called?= =?UTF-8?q?=20an=20agent=20connected=20only=20when=20its=20model=20field?= =?UTF-8?q?=20was=20magpie's,=20showed=20it=20Not=20connected,=20though=20?= =?UTF-8?q?the=20route,=20its=20key=20and=20magpie's=20models=20in=20dsh's?= =?UTF-8?q?=20/model=20were=20all=20still=20there.=20dsh=20now=20has=20Joi?= =?UTF-8?q?ned=20(the=20first=20profile's=20patch=20list=20has=20magpie's?= =?UTF-8?q?=20route),=20as=20Codex=20signed=20in=20with=20ChatGPT=20does,?= =?UTF-8?q?=20so=20it=20reads=20Connected=20=C2=B7=20pick=20magpie's=20mod?= =?UTF-8?q?els=20with=20/model,=20and=20a=20pick=20off=20magpie=20while=20?= =?UTF-8?q?joined=20isn't=20drift=20("changed=20outside=20magpie").=20Disc?= =?UTF-8?q?onnect=20in=20that=20state=20has=20an=20Unwire=20that=20takes?= =?UTF-8?q?=20the=20route,=20the=20start=20magpie=20wrote=20and=20the=20ke?= =?UTF-8?q?y=20out=20of=20every=20profile=20and=20.env=20and=20leaves=20th?= =?UTF-8?q?e=20model=20picked=20in=20dsh;=20on=20one=20of=20magpie's=20mod?= =?UTF-8?q?els=20it=20does=20nothing=20and=20the=20model=20set=20back=20do?= =?UTF-8?q?es=20it=20all,=20as=20before.=20TestDshOwnPickStaysConnected=20?= =?UTF-8?q?(connect,=20a=20DeepSeek=20pick=20in=20settings.yaml:=20wired,?= =?UTF-8?q?=20no=20drift;=20Disconnect:=20the=20template=20as=20it=20was,?= =?UTF-8?q?=20no=20key,=20the=20pick=20kept)=20fails=20on=20the=20old=20co?= =?UTF-8?q?de.=20go=20vet,=20builds=20(darwin,=20GOOS=3Dlinux=20nogui,=20G?= =?UTF-8?q?OOS=3Dwindows)=20and=20go=20test=20-tags=20nogui=20-count=3D1?= =?UTF-8?q?=20./...=20under=20a=20temp=20HOME=20pass.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/agent/applied.go | 5 +- internal/agent/dsh.go | 27 +++++++++++ internal/agent/dsh_joined_test.go | 76 +++++++++++++++++++++++++++++++ 3 files changed, 107 insertions(+), 1 deletion(-) create mode 100644 internal/agent/dsh_joined_test.go diff --git a/internal/agent/applied.go b/internal/agent/applied.go index 626f5c96b..f27ec04c4 100644 --- a/internal/agent/applied.go +++ b/internal/agent/applied.go @@ -135,9 +135,12 @@ func (a *Agent) Drift() *Drift { } } rec := appliedOf(a.ID) + // still joined, a model off magpie is one picked in the agent, beside + // magpie's in its list (dsh's /model), not a change from outside + joined := a.Joined != nil && a.Joined() for _, f := range a.Fields { want, ok := rec.Fields[f.Key] - if !ok || vals[f.Key] == want || !magpieValue(a, f, want, vals) || magpieValue(a, f, vals[f.Key], vals) || sameGroup(want, vals[f.Key]) { + if !ok || joined || vals[f.Key] == want || !magpieValue(a, f, want, vals) || magpieValue(a, f, vals[f.Key], vals) || sameGroup(want, vals[f.Key]) { continue } return &Drift{Kind: "replaced", Field: f.Key, Now: vals[f.Key], Want: want, diff --git a/internal/agent/dsh.go b/internal/agent/dsh.go index 82419d34b..2b8ae3b8f 100644 --- a/internal/agent/dsh.go +++ b/internal/agent/dsh.go @@ -112,6 +112,33 @@ func dshAt(at place) *Agent { return strings.Join(notes, " ") }, Check: func() string { return dshCheck(dir, gw()) }, + // a model of DeepSeek's own picked in dsh (saved in its settings) + // leaves magpie's route in its list: dsh is still connected, its + // /model has magpie's models beside DeepSeek's (Fate on Discord: + // DSH went back to Not connected) + Joined: func() bool { + files := dshProfiles(dir) + if len(files) == 0 { + return false + } + _, items, err := dshRead(files[0]) + return err == nil && dshWired(items) + }, + // connected so, Disconnect takes the route out, the start magpie + // wrote and its key; the model picked in dsh stays its own + Unwire: func() error { + if usesMagpie(dshGet(dir)) { + return nil // the model set back does it all + } + dshWrites.Lock() + defer dshWrites.Unlock() + for _, f := range dshProfiles(dir) { + if err := dshSetFile(f, "", true, nil, gw()); err != nil { + return err + } + } + return dshEnv(dir, false) + }, Fields: []Field{{ Key: "model", Label: "model", Get: func() string { return dshGet(dir) }, diff --git a/internal/agent/dsh_joined_test.go b/internal/agent/dsh_joined_test.go new file mode 100644 index 000000000..47792899a --- /dev/null +++ b/internal/agent/dsh_joined_test.go @@ -0,0 +1,76 @@ +package agent + +import ( + "os" + "path/filepath" + "strings" + "testing" + + "github.com/yetone/magpie/internal/provider" +) + +// A model of DeepSeek's own picked in dsh's /model, which dsh saves in its +// settings over the patch list, leaves dsh connected: magpie's route is +// still in its list, beside DeepSeek's (Fate on Discord: DSH went back to +// Not connected). Disconnect then takes the route, magpie's start and its +// key out, and the model picked in dsh stays. +func TestDshOwnPickStaysConnected(t *testing.T) { + home := t.TempDir() + t.Setenv("HOME", home) + t.Setenv("USERPROFILE", home) + t.Setenv("DSH_HOME", "") + t.Setenv("XDG_CONFIG_HOME", filepath.Join(home, ".config")) + t.Setenv("XDG_CACHE_HOME", filepath.Join(home, ".cache")) + if err := provider.Save(provider.Provider{ID: "glm", Name: "GLM", Chat: "https://glm.test/v1", Key: "k", Models: []string{"glm-5.3"}}); err != nil { + t.Fatal(err) + } + dir := filepath.Join(home, ".dsh") + template := "# Your patch layer for this dsh profile.\n[]\n" + web := filepath.Join(dir, "profiles", "web", "cordis.patch.yml") + os.MkdirAll(filepath.Dir(web), 0o755) + os.WriteFile(web, []byte(template), 0o644) + settings := filepath.Join(dir, "settings.yaml") + read := func(p string) string { b, _ := os.ReadFile(p); return string(b) } + + a := dsh(home) + if a.Wired() { + t.Fatal("wired before anything") + } + if err := a.Pick("model", "magpie/glm/glm-5.3"); err != nil { + t.Fatal(err) + } + if !a.Wired() { + t.Fatal("not wired on magpie's model") + } + + // picked in dsh: DeepSeek's own + os.WriteFile(settings, []byte("ui:\n theme: dark\nagent-default-model:\n provider: deepseek-official\n model: deepseek-v4-flash\n"), 0o644) + if got := a.Field("model").Get(); got != "deepseek-v4-flash" { + t.Fatalf("model: %q", got) + } + if !a.Wired() { + t.Fatal("dsh went back to Not connected with magpie's route still in its list") + } + if d := a.Drift(); d != nil { + t.Fatalf("drift: %+v", d) + } + + if err := a.Disconnect(); err != nil { + t.Fatal(err) + } + if a.Wired() { + t.Fatal("still wired after Disconnect") + } + if got := read(web); got != template { + t.Fatalf("the patch list after Disconnect:\n%q", got) + } + if strings.Contains(read(filepath.Join(dir, ".env")), dshKeyRef) { + t.Fatal("the key outlived the route") + } + if s := read(settings); !strings.Contains(s, "model: deepseek-v4-flash") || !strings.Contains(s, "theme: dark") { + t.Fatalf("the pick made in dsh was lost:\n%s", s) + } + if got := a.Field("model").Get(); got != "deepseek-v4-flash" { + t.Fatalf("model after Disconnect: %q", got) + } +}