diff --git a/docs/subsystems/agent-wiring.md b/docs/subsystems/agent-wiring.md index 13aa2d990..11ae96a31 100644 --- a/docs/subsystems/agent-wiring.md +++ b/docs/subsystems/agent-wiring.md @@ -62,7 +62,7 @@ something else shows up as drift. - Hermes's `api_key` may be a reference, `${VAR}` or `${env:VAR}`, which Hermes expands from the `.env` beside the config (its own or a profile's) and then the environment. `Check` and a sync read the key it names (`hermesKey`): one that holds (`keyHolds`) stays and isn't drift, and so does one naming a variable magpie can't see (only a shell profile sets it), which is unknown. One naming a key the gateway doesn't take is drift, and a sync keeps the reference and writes magpie's key into that `.env` under the variable, made `0600` when there is none (`hermesKeptKey`; PaulT on Discord, `TestHermesWithAKeyInItsEnvFile`). A value with more than the one reference in it is replaced by magpie's key, as before. - omp's `models.yml` keeps `modelOverrides`, `discovery`, `disableStrictTools`, headers and compat flags (`ompKept`). Its `auth` and `apiKey` are magpie's, or gone. - Kimi Code's `[providers.magpie]` has magpie's three keys set in place, so `custom_headers`, `env` and `default_model` stay (`kimiProvider`). - - A Kimi Code model table says what Kimi's own list (`/coding/v1/models`) says of the model, as Kimi Code's own provider does (`capabilitiesForModel` in its `managed-kimi-code.ts`): `always_thinking` for `supports_thinking_type` "only", `dynamically_loaded_tools` for `supports_dynamic_tools`, and `default_effort` at its `think_efforts.default_effort` (max on K2.8 Preview), else high (`kimiModelTables`, `kimiFacts`; `TestKimiCodePlanCapabilities`). kimi-cli gets neither word. `video_in` is never written: Kimi Code uploads a video to its provider's `/files`, which the gateway has no route for (#4485). A `default_effort` the user set stays while the model has it; one magpie wrote is recorded in the stash (`kimiWroteKey`), and an unrecorded high is read as the one magpie wrote before it kept a record. + - A Kimi Code model table says what Kimi's own list (`/coding/v1/models`) says of the model, as Kimi Code's own provider does (`capabilitiesForModel` in its `managed-kimi-code.ts`): `always_thinking` for `supports_thinking_type` "only", `dynamically_loaded_tools` for `supports_dynamic_tools`, and `default_effort` at its `think_efforts.default_effort` (max on K2.8 Preview), else high (`kimiModelTables`, `kimiFacts`; `TestKimiCodePlanCapabilities`). A routing group says each of the three when every member's entry says the same, and none of it when one member doesn't (`groupSharedKimi`; `TestGroupSharesKimiFacts`). kimi-cli gets neither word. `video_in` is never written: Kimi Code uploads a video to its provider's `/files`, which the gateway has no route for (#4485). A `default_effort` the user set stays while the model has it; one magpie wrote is recorded in the stash (`kimiWroteKey`), and an unrecorded high is read as the one magpie wrote before it kept a record. - Cline's `models.json` keeps the provider's other keys, and on each model magpie lists what magpie doesn't write, such as a VS Code override (`clineKept`). - VS Code's, Insiders' and VSCodium's group in `chatLanguageModels.json` (each profile's too) keeps every key magpie doesn't write, such as `settings[""].reasoningEffort`, which VS Code writes there when the user picks an effort in Copilot Chat's model picker (`setModelConfiguration`); a whole rewrite on each Sync and pick sent the model at its first level (chim3744 on Discord). A model's settings stay after it leaves the catalog; the model list is magpie's (`vscodeGroupKept`, `TestVSCodeKeepsThePickedEffort`). - Goose's custom provider file keeps a name, `timeout_seconds`, `toolshim`, headers and the like (`gooseProviderKept`). diff --git a/internal/agent/kimi_caps_test.go b/internal/agent/kimi_caps_test.go index 364cae93f..4f5ace7e5 100644 --- a/internal/agent/kimi_caps_test.go +++ b/internal/agent/kimi_caps_test.go @@ -67,6 +67,14 @@ func TestKimiCodePlanCapabilities(t *testing.T) { }); err != nil { t.Fatal(err) } + // jiabubu again: one Kimi model put in a group so it lists first keeps + // what its list says; a group with another vendor's model has none + if err := provider.SaveGroup(provider.Group{ID: "top", Name: "Top", Members: []string{"kimi-code-cn/kimi-for-coding"}}); err != nil { + t.Fatal(err) + } + if err := provider.SaveGroup(provider.Group{ID: "mix", Name: "Mix", Members: []string{"kimi-code-cn/kimi-for-coding", "relay/gemini-3-pro"}}); err != nil { + t.Fatal(err) + } type model struct { Capabilities []string `toml:"capabilities"` @@ -99,6 +107,9 @@ func TestKimiCodePlanCapabilities(t *testing.T) { []string{"low", "high", "max"}, "high"}, // another vendor's model, video and all, as it was "magpie/relay/gemini-3-pro": {[]string{"thinking", "image_in", "tool_use"}, []string{"low", "high"}, "high"}, + "magpie/group/top": {[]string{"thinking", "always_thinking", "image_in", "tool_use", "dynamically_loaded_tools"}, + []string{"low", "high", "max"}, "max"}, + "magpie/group/mix": {[]string{"thinking", "image_in", "tool_use"}, []string{"low", "high"}, "high"}, } got := read(path) for k, w := range want { diff --git a/internal/provider/group.go b/internal/provider/group.go index a51df6131..2866097c5 100644 --- a/internal/provider/group.go +++ b/internal/provider/group.go @@ -1073,6 +1073,33 @@ func entriesBy(entries []Entry) entryOf { } } +// groupSharedKimi gives a group what the providers' lists say of a model +// (AlwaysThinks, DynamicTools, DefaultEffort) when every member's entry +// says the same: a group of Kimi Code's models keeps always_thinking and +// dynamically_loaded_tools in Kimi Code (jiabubu on Discord: one Kimi +// model put in a group to list it first lost both). One member without it, +// or one magpie has no entry for, and the group has none: Kimi Code would +// send a member that can't the request shaped for one that can +func groupSharedKimi(e *Entry, ms []Member, entries []Entry, find entryOf) { + for i, m := range ms { + j := find(m.Provider.ID, m.Model) + if j < 0 { + e.AlwaysThinks, e.DynamicTools, e.DefaultEffort = false, false, "" + return + } + x := &entries[j] + if i == 0 { + e.AlwaysThinks, e.DynamicTools, e.DefaultEffort = x.AlwaysThinks, x.DynamicTools, x.DefaultEffort + continue + } + e.AlwaysThinks = e.AlwaysThinks && x.AlwaysThinks + e.DynamicTools = e.DynamicTools && x.DynamicTools + if e.DefaultEffort != x.DefaultEffort { + e.DefaultEffort = "" + } + } +} + func buildGroupEntries(entries []Entry) []Entry { var out []Entry all := groupsIn(entries) @@ -1220,6 +1247,7 @@ func buildGroupEntries(entries []Entry) []Entry { // V2 for Ultra only when no member is a ChatGPT account's: a lead // it answers seals its subagents' tasks (#141) e.AgentsV2 = !chatgpt && slices.Contains(e.Efforts, "ultra") + groupSharedKimi(&e, ms, entries, find) e.Reasoning = e.Reasoning || len(e.Efforts) > 0 if e.ImageInput != nil && !*e.ImageInput { e.Images = false diff --git a/internal/provider/group_test.go b/internal/provider/group_test.go index d02c747ee..e8947fef4 100644 --- a/internal/provider/group_test.go +++ b/internal/provider/group_test.go @@ -103,3 +103,38 @@ func TestCodexListedKeepsGroups(t *testing.T) { t.Errorf("fast: group %v, model %v", ms[0].Fast, ms[1].Fast) } } + +// A group keeps what Kimi Code's list says of its models (always thinks, +// loads tools mid-conversation, its default effort) when every member says +// it, and has none of it when one member doesn't (jiabubu on Discord: a Kimi +// model put in a group lost always_thinking and dynamically_loaded_tools in +// Kimi Code). +func TestGroupSharesKimiFacts(t *testing.T) { + t.Setenv("HOME", t.TempDir()) + t.Setenv("USERPROFILE", t.TempDir()) + t.Setenv("XDG_CONFIG_HOME", "") + e := func(p, m string, always, dynamic bool, def string) Entry { + return Entry{ID: p + "/" + m, Model: m, Name: m, Provider: Provider{ID: p}, Reasoning: true, + Efforts: []string{"low", "medium", "high"}, AlwaysThinks: always, DynamicTools: dynamic, DefaultEffort: def} + } + type facts struct { + always, dynamic bool + def string + } + got := map[string]facts{} + for _, g := range groupEntries([]Entry{ + e("kimi-code", "kimi-k3", true, true, "high"), e("kimi-code-cn", "kimi-k3", true, true, "high"), + e("kimi-code", "kimi-k2.7", true, true, "high"), e("or", "kimi-k2.7", false, false, ""), + e("kimi-code", "kimi-k2.8", true, false, "medium"), e("kimi-code-cn", "kimi-k2.8", true, true, "high"), + }) { + got[g.ID] = facts{g.AlwaysThinks, g.DynamicTools, g.DefaultEffort} + } + want := map[string]facts{ + AutoPrefix + "kimi-k3": {true, true, "high"}, + AutoPrefix + "kimi-k2.7": {}, + AutoPrefix + "kimi-k2.8": {always: true}, + } + if !maps.Equal(got, want) { + t.Errorf("got %+v, want %+v", got, want) + } +} diff --git a/internal/provider/models.go b/internal/provider/models.go index 5aa9d4e68..2721df30d 100644 --- a/internal/provider/models.go +++ b/internal/provider/models.go @@ -2648,8 +2648,8 @@ type Entry struct { // AlwaysThinks, DynamicTools and DefaultEffort are what the provider's // own list says of the model (catalog.Model's): it always thinks, it // loads tools mid-conversation, it thinks at this effort unasked. - // Kimi Code's list says them, and Kimi Code is told them (a group - // has none of them) + // Kimi Code's list says them, and Kimi Code is told them. A group + // has each one its members all share (groupSharedKimi) AlwaysThinks bool `json:"-"` DynamicTools bool `json:"-"` DefaultEffort string `json:"-"`