diff --git a/docs/subsystems/agent-wiring.md b/docs/subsystems/agent-wiring.md index 12a3640e1..018cd7eb6 100644 --- a/docs/subsystems/agent-wiring.md +++ b/docs/subsystems/agent-wiring.md @@ -62,6 +62,7 @@ something else shows up as drift. - Codex's `spawn_agent` tool names only the first five models of its catalog to the lead (codex-rs `MAX_SPAWN_AGENT_MODEL_OVERRIDES` in `child_config.rs`, `spawn_agent_models_description`), Codex's own ahead of magpie's, though it takes any catalog model by name (`find_spawn_agent_model_name`). So a lead could put its subagents on none of magpie's models (Gearclickist on Discord). The gateway adds the rest of the catalog Codex was handed to that tool's description, after Codex's own list, at most 200 (`spawnAgentModels` in [`codex_spawn_models.go`](../../internal/gateway/codex_spawn_models.go)). A model that can search tools (`supports_search_tool`) isn't handed it in the request's tools: Codex defers its multi-agent V1 tools behind `tool_search` (codex-rs `core/src/tools/spec_plan.rs`), and the lead gets `spawn_agent` in the `tool_search_output` Codex puts in the conversation and sends again every turn, so that one is widened too. That text goes upstream with the prompt, to OpenAI too for a ChatGPT lead, so its header (`spawnMore`) stays neutral: it names neither magpie nor Codex's limit. At `CodexPath` that is Codex's own listed models less the hidden ones, then `CodexListed` unless Codex is held to its own. At `/v1` it is `CodexCatalog` under the key's allowance. A lead the ChatGPT backend answers in multi-agent V2 seals its subagents' tasks for a ChatGPT account (#619), so it gets Codex's own only. The model catalog Codex puts in context under `model_catalog_in_context` (under development, off by default) is capped at five too, and isn't widened. - Snow CLI runs on one profile at a time (`profiles/.json` in `~/.snow` or `$SNOW_CONFIG_DIR`, named in `active-profile.json`) and copies the active one over `config.json` at every start, `snow --ask` too ([`snow.go`](../../internal/agent/snow.go)). magpie writes a `magpie` profile, makes it the active one, and copies it to `config.json` itself, so a Snow already running and Snow App's "Sync Snow CLI API config" see the same. It is made from the profile the user was on, their settings kept and its OAuth sign-in left out. A vision model of that profile comes along only with an endpoint and key of its own (`snowOwnVision`), since one on the profile's would now go to the gateway. `maxContextTokens`, `maxTokens` and `supportsVision` follow the model from the catalog (`snowSynced`; `supportsVision` as every agent is told, true while magpie's Vision describes images); what magpie last wrote of them is stashed, and one the user changed since in Snow's own settings is kept through later picks and syncs. The small field is magpie's profile's `basicModel`, Snow's light model for summaries, compaction and file search: empty while it follows the main model, a model through magpie of its own kept through new main models and syncs; on a profile of the user's it offers nothing and is hidden. The thinking field is magpie's profile's `chatThinking` (`{enabled: true, reasoning_effort}`), the only thinking setting Snow reads on the chat protocol; empty deletes it, Snow's default, which sends thinking disabled. A chatThinking the user brought from their profile is shown, not written over. The profile they were on (or that there was no `active-profile.json`) and a `magpie.json` of their own are stashed and put back by Disconnect. A Snow from before profiles (`config.json` alone) gets the `default.json` Snow itself would have made of it, so its next start doesn't take magpie's for the user's. Picking a model of another of the user's profiles switches Snow to that profile. On magpie's profile, a value that is neither a model through magpie nor the model of one of the user's profiles is refused and changes nothing (#1457: `magpie snow --help` used to take magpie out and write `--help` as the model of the profile it went back to). Gemini CLI's auth field refuses an auth it doesn't know before it unroutes, for the same reason. On the CLI, `-h`/`--help` after any command or agent only prints its usage, before `run` reads or moves anything, and any other flag given to `magpie …` is refused (`help_cli.go`; `TestHelpOnEveryCommandDoesNothing` walks `run`'s switch and every agent). - omp's `enabledModels` in `config.yml` is the list it holds its default role to: a model left out of it isn't used, whatever `modelRoles.default` says (#1769). So a model picked for the default role is added to a list that is there and doesn't take it in already, by name or by one of omp's globs (`*` not crossing `/`, as `Bun.Glob`), and once nothing in `config.yml` is on magpie its plain `magpie/…` entries are taken out (a list left empty goes, never `[]`); a renamed provider's entries are renamed once, and folder-scoped entries are left alone (`ompScope*` in [`omp_scope.go`](../../internal/agent/omp_scope.go)). No list, no change: omp then takes every model. A list that leaves the default role's model out is drift, which Reapply mends. +- Pi's `enabledModels` in `settings.json` (and OmO's and Prime Agent's, `piLike`) is the Ctrl+P list a new session starts from. A picked model the list doesn't take in is added (`piScopeWith` in [`pi.go`](../../internal/agent/pi.go)), and a renamed provider's `magpie//` entries are renamed with it, a glob or a thinking level included, the copy the pick just added dropped (`renameRefList` in [`rename.go`](../../internal/agent/rename.go), #1919, `TestPiEnabledModelsFollowRename`). The user's other entries stay; a list naming none of the provider's models isn't rewritten. - A value an agent spells as its own provider's model is never taken for one of magpie's, even when magpie has a provider of the same name (`Spelled`, #835). - `Reapply` on `unwired` sets again every field on one of magpie's models and every field set to magpie itself (`magpieID`, as `Wired` takes it): Claude Desktop's drift shows on a tier, and its `provider` field is what writes the gateway back (dumplings on Discord). Claude Desktop's `Check` judges only the set of folders whose Claude-3p it ran in last (`desktopRead`, by `desktopdir.LastRun`), every set when it ran in none: magpie writes both of an MSIX install's sets, and 2.31226 reads the real `%LOCALAPPDATA%\Claude-3p`, so the package's copy being emptied is not Desktop off magpie. - `unreachable` never sets anything: the config is right, and the page's pill only says what has to listen. The exception is an address a WSL distro reached Windows at before (`distro.Was`, kept in `wsl.json`) while it reaches Windows at another now: the pill offers that one, and `Reapply` moves the config there (`Agent.move`, Codex's `codexMoveGateway`). An address no distro was seen at is the user's own and is never moved. An unknown answer (no probe yet) and a gateway down on loopback too are not drift. Tests stub `reachProbe` in `TestMain`. diff --git a/internal/agent/agents.go b/internal/agent/agents.go index 226e5f8c9..946a7b1e0 100644 --- a/internal/agent/agents.go +++ b/internal/agent/agents.go @@ -1002,6 +1002,16 @@ func piLikeKeyed(at place, id, name, dir string, key func() string) *Agent { Sync: func() error { return syncJSON(modelsPath, "providers."+magpieID, block) }, + // a provider renamed takes its magpie// entries in enabledModels + // with it: an entry left on the old id names nothing, and Pi would + // leave that model out of Ctrl+P (#1919, #1828) + RenameRefs: func(from, to string) (bool, error) { + next, ok := renameRefList(piScope(path), from, to) + if !ok { + return false, nil + } + return true, edit.SetJSON(path, edit.KV{Path: "enabledModels", Value: next}) + }, Fields: []Field{ { Key: "model", Label: "model", diff --git a/internal/agent/pi_scope_test.go b/internal/agent/pi_scope_test.go index cb469d315..91c8d600d 100644 --- a/internal/agent/pi_scope_test.go +++ b/internal/agent/pi_scope_test.go @@ -7,6 +7,7 @@ import ( "testing" "github.com/yetone/magpie/internal/edit" + "github.com/yetone/magpie/internal/provider" ) func TestPiTakes(t *testing.T) { @@ -139,3 +140,64 @@ func mustGet(t *testing.T, path, key string) string { } return v } + +// A provider renamed moves the magpie// entries in Pi's enabledModels +// onto the new id, in Pi and in its forks that keep the same settings.json +// (OmO, Prime Agent): the model it is on, kept at its place and not listed +// twice, another of that provider's with a thinking level, and a glob. The +// user's own entries stay, and so does a name that only shares a prefix +// (#1919, #1828). +func TestPiEnabledModelsFollowRename(t *testing.T) { + for _, c := range []struct { + id string + dir []string + a func(string) *Agent + }{ + {"pi", []string{".pi", "agent"}, pi}, + {"omo", []string{".omo", "agent"}, omo}, + {"prime-agent", []string{".prime", "agent"}, primeAgent}, + } { + t.Run(c.id, func(t *testing.T) { + home := syncHome(t) + if err := provider.Save(provider.Provider{ID: "deepseek", Name: "DeepSeek", Chat: "https://api.deepseek.com/v1", Key: "k", Models: []string{"pro", "flash"}}); err != nil { + t.Fatal(err) + } + settings := filepath.Join(append([]string{home}, append(c.dir, "settings.json")...)...) + os.MkdirAll(filepath.Dir(settings), 0o755) + os.WriteFile(settings, []byte(`{ + // the user's own + "enabledModels": ["xai/grok-4.6:high", "magpie/deepseek/flash:low", "magpie/deepseek/*", "magpie/deepseekx/flash", "magpie/deepseek/pro"], + "defaultProvider": "xai", + "defaultModel": "grok-4.6" +} +`), 0o644) + a := c.a(home) + if err := a.Apply("model", "magpie/deepseek/pro"); err != nil { + t.Fatal(err) + } + if _, err := RenameProvider("deepseek", "ds"); err != nil { + t.Fatal(err) + } + want := `["xai/grok-4.6:high","magpie/ds/flash:low","magpie/ds/*","magpie/deepseekx/flash","magpie/ds/pro"]` + if got := strings.Join(strings.Fields(mustGet(t, settings, "enabledModels")), ""); got != want { + t.Errorf("enabledModels = %s, want %s", got, want) + } + if !strings.Contains(readFile(settings), "// the user's own") { + t.Errorf("comment lost: %s", readFile(settings)) + } + if got := a.Field("model").Get(); got != "magpie/ds/pro" { + t.Errorf("model = %q", got) + } + + // a list naming none of the provider's models is left byte for byte + const mine = `{"enabledModels": ["xai/grok-4.6", "xai/grok-4.6"]}` + "\n" + os.WriteFile(settings, []byte(mine), 0o644) + if _, err := RenameProvider("ds", "deepseek"); err != nil { + t.Fatal(err) + } + if got := readFile(settings); got != mine { + t.Errorf("user list rewritten: %s", got) + } + }) + } +} diff --git a/internal/agent/rename.go b/internal/agent/rename.go index 226aabb9e..ce96f40c4 100644 --- a/internal/agent/rename.go +++ b/internal/agent/rename.go @@ -96,3 +96,44 @@ func MoveOffAccountIDs() { _, _ = RenameProvider(id, provider.FreeID(id)) } } + +// renameRef is one entry of an agent's enabledModels (StepCode's, Pi's +// and its forks') with magpie's provider from renamed to to. A glob or a thinking level after the model stays. An entry that +// does not name that provider is the user's and is left as it is. +func renameRef(s, from, to string) (string, bool) { + rest, ok := strings.CutPrefix(s, magpieID+"/"+from+"/") + if !ok { + return s, false + } + return magpieID + "/" + to + "/" + rest, true +} + +// renameRefList renames magpie// entries. The model just set is +// appended before the old entry is renamed onto the same text, so that +// second copy is dropped. A list that names nothing of that provider is +// returned unchanged, a repeated entry of the user's included. +func renameRefList(pats []string, from, to string) ([]string, bool) { + if len(pats) == 0 { + return pats, false + } + out := make([]string, 0, len(pats)) + seen := map[string]bool{} + fromRename := map[string]bool{} + renamed := false + for _, p := range pats { + n, hit := renameRef(p, from, to) + renamed = renamed || hit + if seen[n] && (hit || fromRename[n]) { + continue + } + if !seen[n] { + seen[n] = true + fromRename[n] = hit + } + out = append(out, n) + } + if !renamed { + return pats, false + } + return out, true +} diff --git a/internal/agent/stepcode.go b/internal/agent/stepcode.go index 981179873..e3e2bfaab 100644 --- a/internal/agent/stepcode.go +++ b/internal/agent/stepcode.go @@ -255,47 +255,6 @@ func stepcodeStartup(cfg stepcodeTOML) string { return first } -// stepcodeRenameRef is one enabledModels entry with provider from renamed -// to to. A glob or a thinking level after the model stays. An entry that -// does not name that provider is the user's and is left as it is. -func stepcodeRenameRef(s, from, to string) (string, bool) { - rest, ok := strings.CutPrefix(s, magpieID+"/"+from+"/") - if !ok { - return s, false - } - return magpieID + "/" + to + "/" + rest, true -} - -// stepcodeRenameList renames magpie// entries. The model just set is -// appended before the old entry is renamed onto the same text, so that -// second copy is dropped. A list that names nothing of that provider is -// returned unchanged, a repeated entry of the user's included. -func stepcodeRenameList(pats []string, from, to string) ([]string, bool) { - if len(pats) == 0 { - return pats, false - } - out := make([]string, 0, len(pats)) - seen := map[string]bool{} - fromRename := map[string]bool{} - renamed := false - for _, p := range pats { - n, hit := stepcodeRenameRef(p, from, to) - renamed = renamed || hit - if seen[n] && (hit || fromRename[n]) { - continue - } - if !seen[n] { - seen[n] = true - fromRename[n] = hit - } - out = append(out, n) - } - if !renamed { - return pats, false - } - return out, true -} - // stepcodeRenameRefs moves enabledModels off a renamed provider, in the // file and in the scope disconnect remembers, so a reset does not put the // old id back and still takes out only what magpie appended. @@ -306,7 +265,7 @@ func stepcodeRenameRefs(at place, path, from, to string) (bool, error) { } moved := false if cur.Scope != nil { - next, ok := stepcodeRenameList(*cur.Scope, from, to) + next, ok := renameRefList(*cur.Scope, from, to) if ok { raw, err := stepcodeScopeRaw(next) if err != nil { @@ -326,15 +285,15 @@ func stepcodeRenameRefs(at place, path, from, to string) (bool, error) { return moved, nil } changed := false - if next, ok := stepcodeRenameList(state.OrigScope, from, to); ok { + if next, ok := renameRefList(state.OrigScope, from, to); ok { state.OrigScope = next changed = true } - if next, ok := stepcodeRenameList(state.LastScope, from, to); ok { + if next, ok := renameRefList(state.LastScope, from, to); ok { state.LastScope = next changed = true } - if next, ok := stepcodeRenameList(state.AppendedScope, from, to); ok { + if next, ok := renameRefList(state.AppendedScope, from, to); ok { state.AppendedScope = next changed = true }