diff --git a/docs/subsystems/agent-wiring.md b/docs/subsystems/agent-wiring.md index 7fbbb1d99..a27c2c277 100644 --- a/docs/subsystems/agent-wiring.md +++ b/docs/subsystems/agent-wiring.md @@ -44,6 +44,7 @@ something else shows up as drift. - magpie only removes what it wrote. Anything else in an agent's config stays as it was. - agy's shell function (`update.ShellFunction`, [`shellfn.go`](../../internal/update/shellfn.go)) sits between `# >>> magpie agy >>>` and `# <<< magpie agy <<<`, the only lines magpie writes or takes out of a profile. The profiles are those `cliProfile` names (zsh's in `ZDOTDIR` when set, bash's, fish's `config.fish`), plus PowerShell 7's and Windows PowerShell's on Windows when their execution policy runs a profile. A missing profile is made only for the shell a terminal opens. Only a file inside the home is written, writes go through temp-and-rename, and a profile that can't be read is left alone. Picking one of magpie's models and every `Sync` on one put it there, which covers users wired before it existed. Stepping out and a `Sync` off magpie take it out. agy in a WSL distro gets the function in the distro's own profiles (`agyDistroProfiles` in [`agy.go`](../../internal/agent/agy.go), through `update.ShellFunctionAt`): `~/.bashrc`, `~/.zshrc` and `~/.config/fish/config.fish` where each is, and the profile of the login shell the distro's `/etc/passwd` names (bash when it names none) made where it isn't. The distro's `ZDOTDIR` and `XDG_CONFIG_HOME` aren't read. No magpie runs there, so the function (`agyDistroFunction`) reads `settings.json`'s model with `sed` and carries the gateway's address as the distro reaches it (`place.gw`, Windows' under NAT) and the key it takes from there (`agentKeyAt`, the WSL key under NAT). `Sync` writes it again, so an address WSL changed on a restart follows, and until then `Check` reports a function naming another address. A user's own `alias agy` still wins over it. A terminal opened before the change still needs the `Launch` command. - A sync brings magpie's models up to date, not where the agent reaches magpie. Every `Sync` that `SyncCatalog` runs (each start and update of magpie, a provider added, and a plugin signed in to, out of or renewed, or listing other models than the last time: `plugin.OnChange` and `plugin.OnListed` call `catalog.Touched`, #2373) goes through `synced`, which passes each file written through `kept.away` (`edit.Filtered`, [`keptaway.go`](../../internal/agent/keptaway.go)). The filter sees every file written through `edit` while it is on, from any goroutine and under whatever lock the writer holds, so it takes none a writer may hold: the gateway's address and the LAN key are read before it is on (`keeping`), and magpie's own files (`magpieFile`: its folder as named or where its links lead, such as a `~/.config` linked into a dotfiles repo) are left as they are (ylorn on Discord: `settings.Save` under the settings' lock reached a filter that read the settings, and the app hung ~10s after every start; `TestOwnWritesDuringASyncWithALinkedConfig`). In a file without the gateway's own address, whose magpie the user pointed at an address on another machine (a NAS's, or this machine's LAN address), and with no address a WSL distro was seen at, that address stays in place of `gateway.URL()`, with the path before magpie's every URL at it had (`awayPath`: a reverse proxy's `/magpie`; on loopback, a local proxy's route where magpie answered or hasn't been asked), and so does the key that went with it in place of magpie's own (coeo91 on Discord: the base URL went back to 127.0.0.1 after an update or restart). An address on this machine's loopback follows the gateway; with more than one address or key gone, the write is left as it is. Picking a model in magpie still points the agent at this magpie, but for Claude Code at a proxy to it (above). ZCode and WorkBuddy keep such an address in their own writers too (`zcodeAddress`, `buddyWriteAt`). +- An agent whose `Sync` does nothing but bring a block of magpie's name up to the catalog is `ListOnly` (OpenCode, MiMo Code and the other OpenCode forms, Pi and its forks, Goose, Crush, Air, AtomCode, Command Code, Droid, Fx, jcode, Kimi, MiniMax, Mothx, omp, OpenChamber, OpenClaw, OpenPencil, Penguin, Qwen Code, T3 Code). `SyncCatalog` runs it only while the agent is connected (`Wired`), as its switch on the Agents page says: a custom provider the user named magpie in the agent, with a few models picked by hand, was written over with the whole catalog at every start (yyddbds on Discord, Xiaomi MiMo; `TestCatalogSyncLeavesAHandWrittenMagpieBlock`). A list magpie wrote while connected waits, while the agent runs a model of its own, until a model of magpie's is picked again. Every `ListOnly` agent magpie connects reads as `Wired` (`TestListOnlyAgentsReadConnected`). Agents whose `Sync` also repairs while not connected (Codex, Claude, Grok, Hermes' bots) are not `ListOnly`. magpie keeps no copy of a list it wrote over before this, so such a list stays full until the user trims it. - `SyncCatalog` holds the catalog it builds (`provider.Hold`), the plugins' providers and sign-ins among it, for up to a second. Those `catalog.Touched` drops are told in the background, so a plugin change also drops what is held at once (`plugin.OnChangeNow`, [`hold.go`](../../internal/provider/hold.go)): the host's "auth" event is read before its reply to the sign-in that saved it, and a look at the accounts once the sign-in returns sees it (#2449: `magpie plugin login` found no account while a sync ran; `TestHeldGoesWithAPluginChange`). - JetBrains Air's `magpie-opencode.json` keeps user-added fields in `provider.magpie`, including nested options, on sync and model picks (`air` in [`air.go`](../../internal/agent/air.go), using `theirsKept` in [`sync.go`](../../internal/agent/sync.go)). The gateway fields and complete model list are still replaced, so removed models leave the list. - In every OpenCode-shaped config (OpenCode, DevEco, Air, OpenChamber; `openCodeKept` in [`agents.go`](../../internal/agent/agents.go)), a variant the user put on one of magpie's models stays through a sync, and so does one they wrote over under a name of magpie's. A variant exactly as magpie writes it under its name (`openCodeVariant`) is magpie's, so one the model no longer has goes (#2379, `TestOpenCodeCodexFastVariants`). diff --git a/internal/agent/agent.go b/internal/agent/agent.go index ebcede4ea..822188c2a 100644 --- a/internal/agent/agent.go +++ b/internal/agent/agent.go @@ -153,6 +153,16 @@ type Agent struct { // rather than asking the gateway, rewrites that list as the catalog is // now — where magpie wrote one; nothing else changes (see SyncCatalog). Sync func() error + // ListOnly: Sync does nothing but bring a block of magpie's name in the + // agent's files up to the catalog. A catalog sync runs it only while + // the agent is connected (Wired), as its switch on the Agents page + // says: switched off, nothing of magpie's writes its files. A custom + // provider the user named magpie in the agent, with a few models picked + // by hand (yyddbds on Discord, Xiaomi MiMo), was written over with the + // whole catalog at every start. A list magpie wrote while connected + // waits, while the agent runs a model of its own, until a model of + // magpie's is picked again. + ListOnly bool // Unwire, for an agent whose fields' default is the agent as installed // rather than what it had before magpie (Codex, Claude Code, Gemini // CLI), takes magpie out of its config and puts back what the stash diff --git a/internal/agent/agents.go b/internal/agent/agents.go index 04650be8f..c157c7906 100644 --- a/internal/agent/agents.go +++ b/internal/agent/agents.go @@ -943,6 +943,7 @@ func openCodeLike(at place, id, name, icon, bin, dir, auth string, ua []string, return wiringOff(name, path, func(k string) (string, bool) { return edit.GetJSON(path, "provider."+magpieID+".options."+k) }, "baseURL", at.v1(), "apiKey", openCodeKeyAt(id, at.gw())) }, + ListOnly: true, Sync: func() error { // a model of magpie's chosen, but its provider gone from the // file: put it back, or the agent has nothing to send it to @@ -1266,6 +1267,7 @@ func piLikeKeyed(at place, id, name, dir string, key func() string) *Agent { return wiringOff(name, modelsPath, func(k string) (string, bool) { return edit.GetJSON(modelsPath, "providers."+magpieID+"."+k) }, "baseUrl", at.v1(), "apiKey", key()) }, + ListOnly: true, Sync: func() error { if err := syncJSON(modelsPath, "providers."+magpieID, block); err != nil { return err @@ -1395,7 +1397,8 @@ func gooseIn(at place, cfg string) *Agent { return wiringOff("Goose", provider, func(k string) (string, bool) { return edit.GetJSON(provider, k) }, "base_url", at.v1(), "headers.Authorization", "Bearer "+gooseKey(at)) }, - Sync: func() error { return syncGooseProvider(provider, at) }, + ListOnly: true, + Sync: func() error { return syncGooseProvider(provider, at) }, // goose loads custom_providers when it starts Notice: func() string { if p, _ := gooseActive(path); p == gooseProviderID && Running(`Goose\.app/`, `(^|/)goose( |$)`) { @@ -1676,6 +1679,7 @@ func crushAt(at place, path, data string) *Agent { return wiringOff("Crush", path, func(k string) (string, bool) { return get("providers." + magpieID + "." + k) }, "base_url", at.v1(), "api_key", at.gwKey()) }, + ListOnly: true, Sync: func() error { return syncJSON(path, "providers."+magpieID, provider) }, diff --git a/internal/agent/air.go b/internal/agent/air.go index 4c4e4c594..ff3dd4f31 100644 --- a/internal/agent/air.go +++ b/internal/agent/air.go @@ -174,6 +174,7 @@ func air(home, cfg string) *Agent { return wiringOff("Air", ocPath, func(k string) (string, bool) { return edit.GetJSON(ocPath, "provider."+magpieID+".options."+k) }, "baseURL", gatewayV1(), "apiKey", hereKey()) }, + ListOnly: true, Sync: func() error { return syncJSONInOrder(ocPath, "provider."+magpieID, provider) }, diff --git a/internal/agent/atomcode.go b/internal/agent/atomcode.go index 477c0f4ca..beb5c7a78 100644 --- a/internal/agent/atomcode.go +++ b/internal/agent/atomcode.go @@ -115,6 +115,7 @@ func atomcodeIn(at place) *Agent { ID: "atomcode", Name: "AtomCode", Icon: "atomcode", Spelled: prefixed, NoNames: true, UA: []string{"atomcode"}, Bin: "atomcode", Dir: dir, Path: path, + ListOnly: true, Sync: func() error { ts, err := edit.TOMLTables(path) if err != nil { diff --git a/internal/agent/commandcode.go b/internal/agent/commandcode.go index e521ac8b5..ae9ebf215 100644 --- a/internal/agent/commandcode.go +++ b/internal/agent/commandcode.go @@ -42,6 +42,7 @@ func commandCodeIn(at place) *Agent { ID: "commandcode", Name: "Command Code", Icon: "commandcode", Aliases: []string{"command-code", "cmd"}, Spelled: prefixed, UA: []string{"command-code", "commandcode"}, Bin: "command-code", Dir: dir, Path: path, + ListOnly: true, Sync: func() error { return syncJSON(providers, "provider."+magpieID, theirsKept(providers, "provider."+magpieID, ccProviderJSON, "models")) }, diff --git a/internal/agent/droid.go b/internal/agent/droid.go index e8659cb9d..45ec83ef7 100644 --- a/internal/agent/droid.go +++ b/internal/agent/droid.go @@ -209,6 +209,7 @@ func droidIn(at place) *Agent { // droid's requests to a custom model carry factory-cli/ UA: []string{"factory-cli"}, Bin: "droid", Dir: dir, Path: path, + ListOnly: true, Sync: func() error { for _, c := range droidCustoms(path, droidModels) { if strings.HasPrefix(c.id, droidID) { diff --git a/internal/agent/fx.go b/internal/agent/fx.go index b789b6916..bc20398ad 100644 --- a/internal/agent/fx.go +++ b/internal/agent/fx.go @@ -62,7 +62,8 @@ func fxIn(at place) *Agent { Dir: dir, Path: path, // ~/.fx is where its settings are. No command: `fx` is a common name // (the JSON viewer has it too), as in WSL (wsl.go). - detect: func() bool { return agentDir(dir) }, + detect: func() bool { return agentDir(dir) }, + ListOnly: true, Sync: func() error { return syncJSON(path, "providers."+magpieID, func() any { return fxProvider(fxModels(path)[magpieID]) }) }, diff --git a/internal/agent/jcode.go b/internal/agent/jcode.go index 47d53c2d9..f94af66ea 100644 --- a/internal/agent/jcode.go +++ b/internal/agent/jcode.go @@ -293,6 +293,7 @@ func jcodeAt(at place) *Agent { } return "" }, + ListOnly: true, Sync: func() error { c, err := jcodeRead(path) if err != nil { diff --git a/internal/agent/kimi.go b/internal/agent/kimi.go index 9f9c3a7ce..822b7c472 100644 --- a/internal/agent/kimi.go +++ b/internal/agent/kimi.go @@ -261,6 +261,7 @@ func kimiIn(at place) *Agent { ID: "kimi", Name: "Kimi Code", Icon: "kimi", Aliases: []string{"kimi-code", "kimi-cli"}, Spelled: prefixed, UA: []string{"kimicli"}, Bin: "kimi", Dir: dir, Path: path, + ListOnly: true, Sync: func() error { t, err := edit.GetTOMLTable(path, providerTable) if err != nil || t == nil { diff --git a/internal/agent/listonly_test.go b/internal/agent/listonly_test.go new file mode 100644 index 000000000..ead07f9d8 --- /dev/null +++ b/internal/agent/listonly_test.go @@ -0,0 +1,117 @@ +package agent + +import ( + "path/filepath" + "strings" + "testing" + + "github.com/yetone/magpie/internal/provider" +) + +// yyddbds on Discord: in Xiaomi MiMo they added a custom provider pointing +// at magpie and picked a few of its models by hand. MiMo wasn't connected +// on magpie's Agents page, yet after an update the provider had every one +// of magpie's models: the start's catalog sync wrote magpie's whole list +// over any block named magpie. Magpie's default never goes over a list the +// user wrote; one magpie wrote still follows the catalog. +func TestCatalogSyncLeavesAHandWrittenMagpieBlock(t *testing.T) { + home := syncHome(t) + if err := provider.Save(provider.Provider{ID: "added", Name: "Added", Key: "k", Chat: "http://127.0.0.1:1/v1", Models: []string{"m2"}}); err != nil { + t.Fatal(err) + } + cfgDir := filepath.Join(home, ".config") + mimo := filepath.Join(cfgDir, "mimocode", "mimocode.json") + // as the app writes a custom provider: magpie's address, a key, the + // models the user picked; the model they run is MiMo's own + own := `{ + "model": "mimo/mimo-v2.5-pro", + "provider": { + "magpie": { + "npm": "@ai-sdk/openai-compatible", + "name": "magpie", + "options": {"baseURL": "http://127.0.0.1:3425/v1", "apiKey": "sk-mine"}, + "models": {"relay/glm-4.6": {"name": "GLM 4.6"}} + } + } +} +` + writeFile(t, mimo, own) + // a sibling on the same sync: Pi with a magpie provider written by + // hand in models.json, its default its own + piModels := filepath.Join(home, ".pi", "agent", "models.json") + piOwn := `{"providers":{"magpie":{"baseUrl":"http://127.0.0.1:3425/v1","api":"openai-completions","models":[{"id":"relay/glm-4.6"}]}}}` + writeFile(t, piModels, piOwn) + writeFile(t, filepath.Join(home, ".pi", "agent", "settings.json"), `{"defaultProvider":"anthropic","defaultModel":"claude-x"}`) + // and Crush + crushCfg := filepath.Join(cfgDir, "crush", "crush.json") + crushOwn := `{"providers":{"magpie":{"type":"openai-compat","base_url":"http://127.0.0.1:3425/v1","models":[{"id":"relay/glm-4.6"}]}}}` + writeFile(t, crushCfg, crushOwn) + + SyncCatalog() + if got := readFile(mimo); got != own { + t.Errorf("MiMo's own magpie provider written over:\n%s", got) + } + if got := readFile(piModels); got != piOwn { + t.Errorf("Pi's own magpie provider written over:\n%s", got) + } + if got := readFile(crushCfg); got != crushOwn { + t.Errorf("Crush's own magpie provider written over:\n%s", got) + } + + // connected through magpie, the list follows the catalog + a := mimocode(home, cfgDir) + if err := a.Connect(); err != nil { + t.Fatal(err) + } + if err := provider.Save(provider.Provider{ID: "later", Name: "Later", Key: "k", Chat: "http://127.0.0.1:1/v1", Models: []string{"m3"}}); err != nil { + t.Fatal(err) + } + SyncCatalog() + if got := readFile(mimo); !strings.Contains(got, `"later/m3"`) || !strings.Contains(got, `"added/m2"`) { + t.Errorf("a connected MiMo's list not kept current:\n%s", got) + } + + // switched off on the Agents page, then a provider of that name + // written by hand again: it is the user's + if err := a.Disconnect(); err != nil { + t.Fatal(err) + } + writeFile(t, mimo, own) + SyncCatalog() + if got := readFile(mimo); got != own { + t.Errorf("after Disconnect, MiMo's own magpie provider written over:\n%s", got) + } + + // a model of magpie's picked in MiMo connects it: the list is + // magpie's again + connected := strings.Replace(own, `"mimo/mimo-v2.5-pro"`, `"magpie/relay/glm-4.6"`, 1) + writeFile(t, mimo, connected) + SyncCatalog() + if got := readFile(mimo); !strings.Contains(got, `"later/m3"`) { + t.Errorf("a connected MiMo's list not kept current:\n%s", got) + } +} + +// A catalog sync runs a ListOnly agent's Sync only while it reads as +// connected: every one of them connected by magpie reads so, or its list +// would never follow the catalog again. +func TestListOnlyAgentsReadConnected(t *testing.T) { + codexHome(t, "", "") + n := 0 + for _, a := range All() { + if !a.ListOnly || a.WSL != "" { + continue + } + n++ + if err := a.Connect(); err != nil { + t.Errorf("%s: %v", a.ID, err) + continue + } + if !a.Wired() { + t.Errorf("%s connected but not Wired: a catalog sync would skip its list", a.ID) + } + } + if n < 15 { + t.Fatalf("only %d ListOnly agents", n) + } +} diff --git a/internal/agent/minimax.go b/internal/agent/minimax.go index 6ab740366..13e5055ec 100644 --- a/internal/agent/minimax.go +++ b/internal/agent/minimax.go @@ -114,6 +114,7 @@ func miniMaxAt(at place, dir string) *Agent { ID: "minimax-code", Name: "MiniMax Code", Icon: "minimax-color", Aliases: []string{"mcode"}, Spelled: prefixed, UA: []string{mcodeUA, "minimaxcode"}, Bin: "mcode", Dir: dir, Path: path, + ListOnly: true, Sync: func() error { if _, ok := edit.GetYAMLText(path, mcodeEntry); !ok { return nil diff --git a/internal/agent/modelprefs_test.go b/internal/agent/modelprefs_test.go index 1c580f12b..cfe0836b3 100644 --- a/internal/agent/modelprefs_test.go +++ b/internal/agent/modelprefs_test.go @@ -24,6 +24,8 @@ func TestModelNameAndLevelsReachAgentFiles(t *testing.T) { } piModels := filepath.Join(home, ".pi", "agent", "models.json") writeFile(t, piModels, `{"providers":{"magpie":{"name":"magpie","models":[]}}}`) + // Pi runs a model of magpie's: connected, so its list follows + writeFile(t, filepath.Join(home, ".pi", "agent", "settings.json"), `{"defaultProvider":"magpie","defaultModel":"relay/glm-4.6"}`) codexDir := filepath.Join(home, ".codex") codexCat := filepath.Join(codexDir, "magpie-models.json") writeFile(t, filepath.Join(codexDir, "config.toml"), "model = \"relay/glm-4.6\"\nmodel_provider = \"magpie\"\nmodel_catalog_json = '"+codexCat+"'\n") diff --git a/internal/agent/mothx.go b/internal/agent/mothx.go index aeda1f95a..66b6b33b2 100644 --- a/internal/agent/mothx.go +++ b/internal/agent/mothx.go @@ -77,7 +77,8 @@ func mothxIn(at place) *Agent { return wiringOff("MothX", path, func(k string) (string, bool) { return edit.GetJSON(path, "providers."+magpieID+"."+k) }, "baseUrl", at.v1(), "apiKey", key()) }, - Sync: func() error { return syncJSON(path, "providers."+magpieID, block) }, + ListOnly: true, + Sync: func() error { return syncJSON(path, "providers."+magpieID, block) }, Notice: func() string { if p, _ := get("defaultProvider"); p == magpieID && Running(`(^|/)mothx( |$)`, `(^|/)vibecoding( |$)`) { return noticeMothx.String() diff --git a/internal/agent/omp.go b/internal/agent/omp.go index 681a0447b..273af6371 100644 --- a/internal/agent/omp.go +++ b/internal/agent/omp.go @@ -455,6 +455,7 @@ func ompAt(at place, dir string, entry func() ompProviderEntry) *Agent { // a role's thinking level is omp's, after whichever model it is on; // a list of models is the user's own SplitSuffix: ompSplit, + ListOnly: true, Sync: func() error { models := pick("models") if err := syncYAML(models, "providers."+magpieID, func() any { return ompProvider(models) }); err != nil { diff --git a/internal/agent/openchamber.go b/internal/agent/openchamber.go index 6c9c0ba33..1bebdb39a 100644 --- a/internal/agent/openchamber.go +++ b/internal/agent/openchamber.go @@ -206,6 +206,7 @@ func openChamber(home, cfg string) *Agent { return wiringOff("OpenChamber", ocPath, func(k string) (string, bool) { return edit.GetJSON(ocPath, "provider."+magpieID+".options."+k) }, "baseURL", gatewayV1(), "apiKey", hereKey()) }, + ListOnly: true, Sync: func() error { if _, ok := edit.GetJSON(ocPath, "provider."+magpieID); !ok && usesMagpie(s.model(), s.small()) { return edit.SetJSON(ocPath, edit.KV{Path: "provider." + magpieID, Value: provider()}) diff --git a/internal/agent/openclaw.go b/internal/agent/openclaw.go index 8c58fdfd1..6338eef2f 100644 --- a/internal/agent/openclaw.go +++ b/internal/agent/openclaw.go @@ -416,7 +416,8 @@ func openClawAt(at place) *Agent { return atomic(&Agent{ ID: "openclaw", Name: "OpenClaw", Icon: "openclaw", Spelled: prefixed, NoNames: true, Bin: "openclaw", Dir: dir, Path: path, - Notice: func() string { return noticeOpenClaw.String() }, + Notice: func() string { return noticeOpenClaw.String() }, + ListOnly: true, Sync: func() error { s, err := openClawRead(path) if err != nil { diff --git a/internal/agent/pencil.go b/internal/agent/pencil.go index 149021140..229bad4f9 100644 --- a/internal/agent/pencil.go +++ b/internal/agent/pencil.go @@ -49,6 +49,7 @@ func pencil(home string) *Agent { } return "" }, + ListOnly: true, Sync: func() error { return syncJSON(path, key, theirsKept(path, key, func() any { return pencilProviderJSON(gateway.URL()) }, "models")) }, diff --git a/internal/agent/penguin.go b/internal/agent/penguin.go index 2c80d6787..18fc1bf2c 100644 --- a/internal/agent/penguin.go +++ b/internal/agent/penguin.go @@ -193,7 +193,8 @@ func penguinIn(at place) *Agent { Dir: filepath.Dir(root), Path: path, // the desktop app, on this machine (a distro has none): installed // and not opened yet, it has made no ~/.penguin - sign: func() bool { return at.spell == nil && (&Agent{ID: "penguin"}).HasApp() }, + sign: func() bool { return at.spell == nil && (&Agent{ID: "penguin"}).HasApp() }, + ListOnly: true, Sync: func() error { t, err := edit.GetTOMLTable(path, providerTable) if err != nil || t == nil { diff --git a/internal/agent/qwen.go b/internal/agent/qwen.go index f9d519d3d..264a66965 100644 --- a/internal/agent/qwen.go +++ b/internal/agent/qwen.go @@ -318,6 +318,7 @@ func qwenIn(at place) *Agent { // openaiContentGenerator/provider/default.ts buildHeaders) UA: []string{"qwencode"}, Bin: "qwen", Dir: dir, Path: path, + ListOnly: true, Sync: func() error { for _, c := range qwenCustoms(path) { if c.ours { diff --git a/internal/agent/suffix_mode_test.go b/internal/agent/suffix_mode_test.go index aba2e76e3..5856c94fb 100644 --- a/internal/agent/suffix_mode_test.go +++ b/internal/agent/suffix_mode_test.go @@ -32,6 +32,8 @@ func TestSuffixModesReachAgentFiles(t *testing.T) { } piModels := filepath.Join(home, ".pi", "agent", "models.json") writeFile(t, piModels, `{"providers":{"magpie":{"name":"magpie","models":[]}}}`) + // Pi runs a model of magpie's: connected, so its list follows + writeFile(t, filepath.Join(home, ".pi", "agent", "settings.json"), `{"defaultProvider":"magpie","defaultModel":"relay/glm-4.6"}`) codexDir := filepath.Join(home, ".codex") codexCat := filepath.Join(codexDir, "magpie-models.json") writeFile(t, filepath.Join(codexDir, "config.toml"), "model = \"relay/glm-4.6\"\nmodel_provider = \"magpie\"\nmodel_catalog_json = \""+tomlString(codexCat)+"\"\n") diff --git a/internal/agent/sync.go b/internal/agent/sync.go index 3853fca87..c22c2a3ea 100644 --- a/internal/agent/sync.go +++ b/internal/agent/sync.go @@ -52,7 +52,7 @@ func SyncCatalog() { unhold := filememo.Hold() renaming := setToFoundGroups() for _, a := range All() { - if a.Sync != nil { + if a.Sync != nil && (!a.ListOnly || a.Wired()) { _ = synced(a.Sync) } // a field magpie set to a found group's id before (autoref.go) diff --git a/internal/agent/sync_keep_test.go b/internal/agent/sync_keep_test.go index 1a76b2dd5..9d9494553 100644 --- a/internal/agent/sync_keep_test.go +++ b/internal/agent/sync_keep_test.go @@ -49,6 +49,8 @@ func TestPiKeepsTheirKeysInMagpiesProvider(t *testing.T) { } } `) + // Pi runs a model of magpie's: connected, so its list follows + writeFile(t, filepath.Join(home, ".pi", "agent", "settings.json"), `{"defaultProvider":"magpie","defaultModel":"relay/glm-4.6"}`) SyncCatalog() p := providerAt(t, piModels, "providers") compat, _ := p["compat"].(map[string]any) diff --git a/internal/agent/sync_test.go b/internal/agent/sync_test.go index 7b69f7057..287af70e0 100644 --- a/internal/agent/sync_test.go +++ b/internal/agent/sync_test.go @@ -229,6 +229,9 @@ func TestSyncCatalogRewritesAgentLists(t *testing.T) { home := syncHome(t) piModels := filepath.Join(home, ".pi", "agent", "models.json") writeFile(t, piModels, `{"providers":{"mine":{"baseUrl":"http://x"},"magpie":{"name":"magpie","models":[]}}}`) + // connected: a block of magpie's name in an agent not on magpie is the + // user's own (TestCatalogSyncLeavesAHandWrittenMagpieBlock) + writeFile(t, filepath.Join(home, ".pi", "agent", "settings.json"), `{"defaultProvider":"magpie","defaultModel":"relay/glm-4.6"}`) crushCfg := filepath.Join(home, ".config", "crush", "crush.json") crushBody := `{"providers":{"mine":{"base_url":"http://x"}}}` writeFile(t, crushCfg, crushBody) diff --git a/internal/agent/t3code.go b/internal/agent/t3code.go index 7d8eb7203..fca05884a 100644 --- a/internal/agent/t3code.go +++ b/internal/agent/t3code.go @@ -67,7 +67,8 @@ func t3code(home string) *Agent { Dir: base, Path: path, // ~/.t3 is made at its first start; a Mac app never opened yet is // found by its bundle. No command: `t3` is a common name. - detect: func() bool { return isDir(base) || t3App(home) }, + detect: func() bool { return isDir(base) || t3App(home) }, + ListOnly: true, Sync: func() error { return syncJSON(path, t3Instance, func() any { return t3Merged(path, gateway.URL()) }) }, diff --git a/internal/cli/save_sync_behind_test.go b/internal/cli/save_sync_behind_test.go index 0fc0179e1..5dce2b058 100644 --- a/internal/cli/save_sync_behind_test.go +++ b/internal/cli/save_sync_behind_test.go @@ -50,7 +50,8 @@ func TestSaveAnswersBeforeTheAgentsSync(t *testing.T) { if err := os.MkdirAll(dir, 0o755); err != nil { t.Fatal(err) } - if err := os.WriteFile(filepath.Join(dir, "settings.json"), []byte(`{}`), 0o600); err != nil { + // Pi runs a model of magpie's: connected, so a sync writes its list + if err := os.WriteFile(filepath.Join(dir, "settings.json"), []byte(`{"defaultProvider":"magpie","defaultModel":"a/m1"}`), 0o600); err != nil { t.Fatal(err) } fifo := filepath.Join(dir, "models.json")