diff --git a/docs/subsystems/agent-wiring.md b/docs/subsystems/agent-wiring.md index 5b74ce706..97002b029 100644 --- a/docs/subsystems/agent-wiring.md +++ b/docs/subsystems/agent-wiring.md @@ -35,6 +35,7 @@ something else shows up as drift. | Codex instructions | Each magpie model's entry in Codex's catalog carries the instructions official Codex sends that model, Codex's own text word for word; magpie writes none of its own and never changes the identity line (`codexcat.officialFor`). The model's slug (the id's last path segment, lowercased) is matched as Codex matches one, by the longest prefix of an official slug (`longestPrefix`; `auto/gpt-6.1-sol` takes gpt-6.1-sol's, `s2a/openai/gpt-6-luna-2026-09-14` gpt-6-luna's): first against the entries the user's ChatGPT account handed this Codex (`CacheEntries`, models_cache.json), whose `base_instructions` (else `model_messages.instructions_template`) and `model_messages` go over as sent; then against Codex's bundled catalog (`codex_instructions.json`, each model's `instructions_template` from openai/codex rust-v0.166.0's models-manager/models.json), the text only, as an older Codex may not read that release's `model_messages`. Any other model, and a routing group (`group/`), which may hand a turn to any model, takes Codex's prompt for a model it doesn't know (`Prompt`, models-manager/prompt.md), which is what official Codex sends it (`model_info_from_slug`). An entry Codex was handed with no `base_instructions` (`ownEntry`) takes its `model_messages.instructions_template`, else `Official`, and magpie's own ChatGPT-backend requests fall back to `Official` too (`codexInstructions` in internal/provider). Until 11-01 every third-party model was handed gpt-5.2-codex_prompt.md ("You are Codex, based on GPT-5"), so a magpie GPT-6 model ran on a GPT-5.2-era prompt (#3759, #4008, #4783). The Codex files are in testdata (`testdata/codex-rust-v0.166.0`), and `TestBundledIsCodexOwn` fails when the embedded copies differ from them; on a new Codex release copy its two files there and rebuild `codex_instructions.json`. Real Codex 0.166 against a capturing gateway sends the official text as its first developer message for a GPT-6 model and prompt.md for DeepSeek. `TestThirdPartyModelsTakeCodexOwnInstructions`, `TestThirdPartyModelsTakeCachedEntry`, `TestOwnEntryInstructions`. Not read: the bundled catalog inside the user's installed Codex binary. | [`codexcat.go`](../../internal/codexcat/codexcat.go) | | Codex: DeepSeek models | A DeepSeek model's entry (`codexcat.deepSeek`: deepseek-v4*, -flash, -pro, -chat, -reasoner after any provider or relay prefix; not a routing group, not a distill) takes what DeepSeek's own Codex setup (cdn.deepseek.com/api-docs/codex-deepseek-setup-en.sh, its models.json) says of its models: `shell_type` `shell_command` (Codex 0.165 reads it as `unified_exec`, its only shell; older Codex had a one-shot `shell_command` tool), `support_verbosity` with `default_verbosity` low, `default_reasoning_summary` none (no `reasoning.summary` sent), `multi_agent_version` v2, and `supports_image_detail_original` on a model whose entry takes images. Not taken: its `base_instructions`/`model_messages` (magpie never rewrites a Codex prompt), its `auto_compact_token_limit` null (magpie's 272K default stays, from e950eb080's DeepSeek latency report; Full window or the model's Compact at gives the whole window), `supports_search_tool` false on v4-pro (#258), its reasoning levels (the provider's). `default_reasoning_summary` is tagged `keep:"unset"`, so a value the user put in another model's entry stays (`Keep`). Other vendors' entries are unchanged. `TestCodexCatalogDeepSeekAsDeepSeekSays`, `TestCodexCatalogKeepsUsersSummary`. | [`codexcat.go`](../../internal/codexcat/codexcat.go) | | Codex: Ultra on other vendors' models | An entry of a model that lists reasoning levels, from a vendor other than OpenAI, ends its levels with `ultra` and says `multi_agent_version` v2 (`codexcat.ultraHere`; pingqipai3 on X: Codex offers Ultra only where a model's entry lists it). Codex never sends Ultra itself: `ModelInfo::resolve_reasoning_effort` sends the entry's `multi_agent_reasoning_effort`, else `max`, else its highest other level, so the model is asked its own top level; and under V2 Ultra is what turns subagents to proactive (`effective_multi_agent_mode`). Not given it: GPT, o-series and Codex models (their own Ultra is `provider.OffersUltra`'s), a model with no levels, a Fast or Seals entry (V1 stays theirs), a vendor's own Codex entry (`listedEntry`). The default level is never Ultra. `catalogFormat` v3 makes Codex fetch the list again. `TestUltraOnOtherVendorsModels`. | [`codexcat.go`](../../internal/codexcat/codexcat.go) | +| Codex: Ultra on GPT models | A GPT model served by anything other than a ChatGPT account (a relay, an OpenAI key, Copilot) whose levels reach `max` ends them with `ultra` and says `multi_agent_version` v2 (`provider.withUltra` in `entryFor`; a group whose members offer it, `group.go`). Which models is a family rule, not a list: `provider.OffersUltra` is true where `catalog.FamilyOf` names `gpt-sol`, `gpt-astra` or `gpt-terra` with a version, the way openai/codex's models-manager/models.json lists Ultra on every Sol, Astra and Terra (GPT-5.6 to GPT-6.2) and on no Luna, GPT-5.5 or older. The rule is asked of every spelling the catalog matches (`catalog.IsOneLike`: a provider or relay prefix, `:official`, `[A]`, a dated suffix, `gpt-6-1-sol`), so a Fast, Pro or other variant stays out. Until 11-19 it was a hand list (`ultraModels`), and each new model lacked Ultra until it was added (#4909 for GPT-6.1 Terra; forkhouhou on X for GPT-6.2 Sol and Astra). Ultra goes upstream as the entry's `multi_agent_reasoning_effort` or `max` (the gateway's `fitEffort`); it changes no sandbox or approval. `TestUltraOnModelsThatOfferIt`, `TestCopilotSolOffersUltra`. | [`ultra.go`](../../internal/provider/ultra.go), [`catalog.go`](../../internal/catalog/catalog.go) | | Named omp profiles | omp keeps a profile's settings under `~/.omp/profiles/` (or under `PI_CONFIG_DIR`), each with its own `config.yml` and `models.yml`. Every such profile is an agent of its own — `omp#` on Windows, `omp#@wsl:` in a distro — so each can be connected, drifted and disconnected on its own. They share omp's model lists (`ListsFor`), and the default `omp` row is the folder `ompDir`/`ompIn` already pick, so an `OMP_PROFILE` that row is already pointed at is not listed twice. A name omp refuses is not a row: `default`, a trailing dot, or a Windows reserved device name (`aux`, `nul`, `com1`, `lpt9.x`, `con.work`), on every platform (`ompProfileOK`). A distro's profile names come from its probe and are kept in `wsl.json`; a stopped distro is never started to list them, its profile rows showing what was last seen (`asleep`). | [`omp.go`](../../internal/agent/omp.go), [`wsl.go`](../../internal/agent/wsl.go) | | omp's advisor | omp's advisor (`src/advisor`) is a second model, on the `advisor` role, that reviews the main agent's work and sends it notes; it runs only while `advisor.enabled` is true, which omp leaves off (#6408, Awad_Yoo on X). A model picked for the advisor role turns it on when the user hasn't set it, and the role's reset takes back only what that pick wrote (`ompAdvisorTurnedOn`, a stash mark). Three Quiet fields write the rest of `config.yml`'s `advisor` block as omp reads it (`ompAdvisorFields` in [`omp_advisor.go`](../../internal/agent/omp_advisor.go)): `advisor_review` (off, `turn`, `agent-end`: `enabled` with `reviewMode`; off keeps the mode), `advisor_wait` (`syncBacklog`: `off`, `"1"`, `"3"`, `"5"`, `strict`, written as strings since omp's enum settings take strings only) and `advisor_wake` (`continueSeverity`: `nit`, `concern`, `blocker`, omp 18.12.1 or later). They show in omp's opened row and sheet as three rows (`ompAdvisorIn`, drawn by `ompadvisor.js`, imported the first time), the last two only while it reviews; the roles square's advisor line says " · off" when it is off. A `WATCHDOG.yml` roster sets each advisor's own review and wait over these, and is not shown. Taking over from the main model after repeated failures is not omp's advisor's: omp has no such setting, and an omp extension (`pi.on("tool_result")`, `pi.setModel`) is where it goes. `TestOmpAdvisorPickTurnsItOn`, `TestOmpAdvisorSettings`, `omp-advisor.test.cjs`. | | Claude Code in more than one folder | A Claude Code kept elsewhere with `CLAUDE_CONFIG_DIR` (an alias per account or workspace) has its own settings.json. The claude row is the folder the variable names, else `~/.claude`; every other folder under the home folder named `.claude…` that holds Claude Code's own files (`settings.json`, `.credentials.json` or `projects/`) is a row of its own, `claude#` (`.claude-work` → `Claude Code · work`; the default `~/.claude` is `claude#default` while the variable points elsewhere), made by `claudeIn` at that folder (`place.dir`, as the `claude#launch` file is) and connected, set and checked there alone. The file `~/.claude.json`, another tool's `.claude-…` folder with none of those files and the launch file's folder are not listed. A folder outside the home folder is not found (BieJian21872 on X; `TestClaudeCodeInMoreThanOneFolder`). | [`claude_dirs.go`](../../internal/agent/claude_dirs.go) | diff --git a/internal/catalog/catalog.go b/internal/catalog/catalog.go index 556806563..ca377a6fb 100644 --- a/internal/catalog/catalog.go +++ b/internal/catalog/catalog.go @@ -1583,6 +1583,18 @@ func IsOneOf(id string, ids map[string]bool) bool { return ok } +// IsOneLike is IsOneOf for models a rule names by their id rather than a +// list: whether like takes the model of this id, by the id or any spelling +// IsOneOf hears (a relay's rename, a tag in brackets, ":official", the +// model the user said it is). like gets bare ids, lowercase. A rule kept +// so reaches a model newer than any list: provider.OffersUltra's every GPT +// Sol, Astra and Terra. +func IsOneLike(id string, like func(bare string) bool) bool { + load() + _, ok := lookupBy(bareID(id), func(b string) (bool, bool) { return true, like(b) }, true, true) + return ok +} + // KnowsAsWritten is Knows without another spelling (normalFor): the // usage report sends a model's id only when models.dev knows it as // written, so an id a user typed that only folds into a known one @@ -1813,24 +1825,38 @@ func lookupAs[T any](id string, table map[string]T, spellings bool) (T, bool) { // lookupIn is lookupAs for a bare id, the user's word heard only with // user, as contextIn. func lookupIn[T any](b string, table map[string]T, spellings, user bool) (T, bool) { - if v, ok := found(b, table); ok { + return lookupBy(b, inMap(table), spellings, user) +} + +// inMap is a table's lookup of a bare id as it is written, for foundBy. +func inMap[T any](table map[string]T) func(string) (T, bool) { + return func(b string) (T, bool) { + v, ok := table[b] + return v, ok + } +} + +// lookupBy is lookupIn for a table read through get, which may be a rule +// rather than a map (IsOneLike). +func lookupBy[T any](b string, get func(string) (T, bool), spellings, user bool) (T, bool) { + if v, ok := foundBy(b, get); ok { return v, true } if s, ok := userSame(b, user); ok { - if v, ok := lookupIn(s, table, true, false); ok { + if v, ok := lookupBy(s, get, true, false); ok { return v, true } } if r, _, ok := renamed(b); ok { - if v, ok := found(r, table); ok { + if v, ok := foundBy(r, get); ok { return v, true } } if n, ok := normalFor(b); spellings && ok { - return found(n, table) + return foundBy(n, get) } if t, ok := untagged(b); spellings && ok { - return lookupIn(t, table, true, user) + return lookupBy(t, get, true, user) } var zero T return zero, false @@ -1916,21 +1942,25 @@ func normalFor(b string) (string, bool) { // profile's without its geography, "gpt-5.4(high)" (CLIProxyAPI's level in // the id) as gpt-5.4, or "glm-5:free" (":batch", ":thinking") as glm-5. func found[T any](b string, table map[string]T) (T, bool) { - if v, ok := table[b]; ok { + return foundBy(b, inMap(table)) +} + +// foundBy is found for a table read through get. +func foundBy[T any](b string, get func(string) (T, bool)) (T, bool) { + if v, ok := get(b); ok { return v, true } if r, ok := unprofiled(b); ok { - return found(r, table) + return foundBy(r, get) } if i := strings.IndexByte(b, '('); i > 0 && strings.HasSuffix(b, ")") { - if v, ok := table[b[:i]]; ok { + if v, ok := get(b[:i]); ok { return v, true } b = b[:i] } if i := strings.IndexByte(b, ':'); i > 0 { - v, ok := table[b[:i]] - return v, ok + return get(b[:i]) } var zero T return zero, false diff --git a/internal/provider/ultra.go b/internal/provider/ultra.go index 6c737d178..89f458a22 100644 --- a/internal/provider/ultra.go +++ b/internal/provider/ultra.go @@ -12,21 +12,22 @@ import ( // (or the entry's multi_agent_reasoning_effort) and, on a thread at // multi-agent V2, hands parts of the task to agents of its own unasked // (codex-rs core/src/session/multi_agents.rs). Codex offers it on a model -// whose entry lists "ultra"; its own catalog (models-manager/models.json) -// lists it for these alone — GPT-6 Luna and GPT-5.6 Luna stop at max — so -// magpie offers it on them wherever they are served (Copilot's, a key's, a -// relay's: #656), never on every model that reaches max. GPT-6.1 Terra -// carries it since #4909. -var ultraModels = []string{"gpt-6.1-sol", "gpt-6-sol", "gpt-6-astra", "gpt-5.6-sol", "gpt-5.6-terra", "gpt-6.1-terra"} +// whose entry lists "ultra", and its own catalog (models-manager/ +// models.json) lists it on every GPT Sol, Astra and Terra, from GPT-5.6 Sol +// to GPT-6.2 Sol and Astra, and on no Luna. So magpie offers it on a model +// of those families wherever it is served (Copilot's, a key's, a relay's: +// #656), never on every model that reaches max. It was a list of ids, and +// each new model went without until it was added by hand: GPT-6.1 Terra +// (#4909), then GPT-6.2 Sol and Astra (forkhouhou on X). +var ultraFamilies = map[string]bool{"gpt-sol": true, "gpt-astra": true, "gpt-terra": true} -// ultraSet is ultraModels as catalog.IsOneOf takes them. -var ultraSet = func() map[string]bool { - m := map[string]bool{} - for _, id := range ultraModels { - m[id] = true - } - return m -}() +// ultraFamily reports whether a bare id (lowercase, no vendor's prefix) +// names a version of a family Codex offers Ultra on: gpt-6.2-sol and its +// dated snapshots, not gpt-6.1-sol-mini, gpt-6-sol-fast or gpt-6-luna. +func ultraFamily(bare string) bool { + f := catalog.FamilyOf(bare) + return len(f.Version) > 0 && ultraFamilies[f.Name] +} // datedSuffix is a snapshot's date after a model's id (-2026-09-14, -20260914). var datedSuffix = lazyre.New(`-(\d{4}-\d{2}-\d{2}|\d{8})$`) @@ -37,12 +38,14 @@ var datedSuffix = lazyre.New(`-(\d{4}-\d{2}-\d{2}|\d{8})$`) // "[A]gpt-6.1-sol", one the user said is gpt-6.1-sol), whose levels are // that model's already (provider.borrowedEfforts) and stopped at max. func OffersUltra(model string) bool { - id := strings.ToLower(model) + id := strings.ToLower(strings.TrimSpace(model)) if i := strings.LastIndex(id, "/"); i >= 0 { id = id[i+1:] } - id = datedSuffix.ReplaceAllString(id, "") - return ultraSet[id] || id != "" && catalog.IsOneOf(id, ultraSet) + if id == "" { + return false + } + return catalog.IsOneLike(id, ultraFamily) } // withUltra adds Codex's ultra to the levels of a model that offers it and diff --git a/internal/provider/ultra_test.go b/internal/provider/ultra_test.go index 29a76bba8..b69fb8c25 100644 --- a/internal/provider/ultra_test.go +++ b/internal/provider/ultra_test.go @@ -27,7 +27,13 @@ func TestUltraOnModelsThatOfferIt(t *testing.T) { "gpt-6.1-sol": true, "openai/gpt-6.1-sol": true, "GPT-6.1-Sol": true, "gpt-6.1-sol-2026-09-14": true, "gpt-6-astra": true, "gpt-6-sol": true, "gpt-5.6-sol": true, "gpt-5.6-terra": true, "gpt-6.1-terra": true, "relay/gpt-6.1-terra": true, - "gpt-6-luna": false, "gpt-5.6-luna": false, "gpt-6.1-sol-mini": false, "claude-opus-5-5": false, "": false, + // by the rule, not a list: Codex's catalog gives GPT-6.2 Sol and + // Astra Ultra (forkhouhou on X), and the next of these families + // has it the day it is served + "gpt-6.2-sol": true, "gpt-6.2-astra": true, "relay/gpt-6.2-astra": true, "gpt-6.2-sol-2026-11-17": true, + "gpt-6.3-terra": true, "gpt-6.1-sol:official": true, "[A]gpt-6.2-sol": true, "gpt-6-1-sol": true, + "gpt-6-luna": false, "gpt-5.6-luna": false, "gpt-6.2-luna": false, "gpt-6.1-sol-mini": false, + "gpt-6-sol-fast": false, "gpt-6.2-sol-pro": false, "gpt-5.5": false, "claude-opus-5-5": false, "": false, } { if OffersUltra(id) != want { t.Errorf("OffersUltra(%q) = %v", id, !want) @@ -47,6 +53,16 @@ func TestUltraOnModelsThatOfferIt(t *testing.T) { if !slices.Equal(terra.Efforts, append(slices.Clone(upToMax), "ultra")) || !terra.AgentsV2 { t.Fatalf("copilot/gpt-6.1-terra: %v v2=%v", terra.Efforts, terra.AgentsV2) } + // GPT-6.2 Astra and Sol, which the catalog knows no levels of yet, up + // to max on a relay or a key: Ultra after max, as on their siblings + for _, p := range []Provider{copilot, {ID: "relay"}} { + for _, id := range []string{"gpt-6.2-astra", "gpt-6.2-sol"} { + e := entryFor(p, catalog.Model{ID: id, Efforts: upToMax}, s) + if !slices.Equal(e.Efforts, append(slices.Clone(upToMax), "ultra")) || !e.AgentsV2 { + t.Fatalf("%s/%s: %v v2=%v", p.ID, id, e.Efforts, e.AgentsV2) + } + } + } luna := entryFor(copilot, catalog.Model{ID: "gpt-6-luna", Efforts: upToMax}, s) if !slices.Equal(luna.Efforts, upToMax) || luna.AgentsV2 { t.Fatalf("copilot/gpt-6-luna: %v v2=%v", luna.Efforts, luna.AgentsV2)