diff --git a/docs/subsystems/agent-wiring.md b/docs/subsystems/agent-wiring.md index c9a1c2643..18959c7a1 100644 --- a/docs/subsystems/agent-wiring.md +++ b/docs/subsystems/agent-wiring.md @@ -88,6 +88,7 @@ something else shows up as drift. - 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`). 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. - Kimi Code's thinking field (`kimiThinkingField`) is the level its sessions start at, in `[thinking]` as Kimi Code's own `/model` saves it: `enabled = false` for off, else `enabled = true` and `effort`; Default takes both out, so each model starts at its `default_effort`, and off keeps `effort` for the next on, as Kimi Code does. Its levels are the current model table's `support_efforts` (an `[overrides]` table's first), with off unless the model is `always_thinking`, and the common levels for a model the config doesn't describe (`kimiThinkingOptions`). kimi-cli has only its top-level `default_thinking` (on, off). The `[thinking]` table keeps every other key (`keep`), and an empty one goes (`TestKimiThinkingField`). + - Kimi Code's subagents (`kimiSubagentFields` in [`kimi_secondary.go`](../../internal/agent/kimi_secondary.go); XiaoLing_Arisa on X) are its `[secondary_model]`: `default_model` (the model a subagent starts on; the legacy `model` stands for it), the pool `[secondary_model.models]` (`"alias" = "when to use it"`, the models its lead may start one on) and `default_effort`. Kimi Code 2.6.2 refuses a session, or a subagent's start, when a pool lacks its `default_model` or names a model with no `[models."…"]` table, and its validator also refuses an effort a pool model can't take, so every write is one it takes: picking a default adds it to the pool (as its own `/secondary-model` does), a pool without the default gets its first, an effort is offered only where each pool model takes it (`kimiPoolLevels`) and goes when the pool changes past it. A magpie model goes in only while `[providers.magpie]` is there. Keys are set in place; a hint, other keys and comments stay. Before a magpie model table goes (Sync dropping a model, Unwire), its name leaves the section (`kimiPruneSecondary`), the default going back to the user's own (stashed at `kimi::secondary`) or the pool's first, and a section left empty goes. The user's own pool of their own models is never touched (`TestKimiSubagentPool*`). The GUI shows the three as one Subagents line of the opened row, the pool a multi-pick menu, drawn by [`kimisub.js`](../../internal/gui/assets/kimisub.js), imported when the line first shows. A stopped WSL distro's Kimi Code shows none of the three, as each reads the config (#3896). kimi-cli has no such section. - 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.go b/internal/agent/kimi.go index 6c9dec2a6..90503d479 100644 --- a/internal/agent/kimi.go +++ b/internal/agent/kimi.go @@ -269,6 +269,19 @@ func kimiIn(at place) *Agent { return err } tables, wrote := kimiModelTables(path, legacy, kimiWrote(path)) + if !legacy { + // a model gone from the catalog out of the subagents' first: + // Kimi refuses a pool naming a model it doesn't have + names := map[string]bool{} + for _, t := range tables { + if k, err := strconv.Unquote(strings.TrimPrefix(t.Name, "models.")); err == nil { + names[k] = true + } + } + if err := kimiPruneSecondary(path, func(k string) bool { return names[k] }, kimiSecStashed(path)); err != nil { + return err + } + } if err := edit.SetTOMLTables(path, []string{kimiModelTable}, tables); err != nil { return err } @@ -277,6 +290,14 @@ func kimiIn(at place) *Agent { return nil } dropMagpie := func() error { + if !legacy { + // magpie's models out of the subagents' first, the model they + // had back + if err := kimiPruneSecondary(path, func(string) bool { return false }, kimiSecStashed(path)); err != nil { + return err + } + forget(kimiSecStashKey(path)) + } if err := edit.SetTOMLTables(path, []string{kimiModelTable}, nil); err != nil { return err } @@ -338,7 +359,7 @@ func kimiIn(at place) *Agent { return wiringOff("Kimi Code", path, func(k string) (string, bool) { v, ok := t[k]; return v, ok }, "base_url", at.v1(), "api_key", at.gwKey()) }, - Fields: []Field{{ + Fields: append([]Field{{ Key: "model", Label: "model", Get: get, Set: func(v string) error { @@ -366,7 +387,10 @@ func kimiIn(at place) *Agent { Options: func(cur map[string]string) []Option { return withVia(kimiOwnOptions(path, cur["model"]), "kimi", magpieID+"/") }, - }, kimiThinkingField(path, legacy, at.cold)}, + }, kimiThinkingField(path, legacy, at.cold)}, kimiSubagents(path, legacy, at.cold, func() bool { + t, err := edit.GetTOMLTable(path, providerTable) + return err == nil && t != nil + })...), }, path) } diff --git a/internal/agent/kimi_secondary.go b/internal/agent/kimi_secondary.go new file mode 100644 index 000000000..f5905a570 --- /dev/null +++ b/internal/agent/kimi_secondary.go @@ -0,0 +1,515 @@ +package agent + +// Kimi Code's subagents (XiaoLing_Arisa on X): the new Kimi Code (2.x) puts +// them on its [secondary_model] (docs: kimi-code-cli/configuration/ +// config-files#secondary-model; packages/agent-core-v2 session/subagent/ +// configSection.ts): +// +// [secondary_model] +// default_model = "alias" # what a subagent runs on unless the lead names one +// default_effort = "high" # their thinking level +// [secondary_model.models] # the pool the lead may pick from +// "alias" = "when to use it" +// +// Every name is a key of a [models.""] table. With no section a +// subagent runs on the lead's model and effort; default_model alone is a pool +// of one; the legacy model key stands for default_model. Kimi refuses to +// start, resume or fork a session when default_model is missing beside a +// pool or isn't in it, a pool entry names no model, or default_effort is one +// a pool model can't take (assertValidSubagentModelPool, +// assertValidSubagentDefaultEffort). So magpie's model tables going (a +// disconnect, a model leaving the catalog) take their names out of the +// section first. kimi-cli (Python) has no such section. + +import ( + "encoding/json" + "fmt" + "maps" + "slices" + "sort" + "strconv" + "strings" + + "github.com/pelletier/go-toml/v2" + + "github.com/yetone/magpie/internal/edit" +) + +const kimiSecondary = "secondary_model" + +// kimiSec is [secondary_model] as Kimi reads it. +type kimiSec struct { + Default string // default_model + Legacy string // model, read when default_model isn't there + Pool map[string]string // [secondary_model.models]; nil without one + Effort string // default_effort +} + +// def is the model a subagent starts on by Kimi's reading. +func (s kimiSec) def() string { + if s.Default != "" { + return s.Default + } + return s.Legacy +} + +// pool is the pool's names as Kimi resolves it (resolveSubagentModelPool): +// the table's, else default_model's (or model's) alone; nil for none. The +// default first, then the rest by name. +func (s kimiSec) pool() []string { + if s.Pool == nil { + if d := s.def(); d != "" { + return []string{d} + } + return nil + } + out := make([]string, 0, len(s.Pool)) + for k := range s.Pool { + if k != s.Default { + out = append(out, k) + } + } + sort.Strings(out) + if _, ok := s.Pool[s.Default]; ok { + out = append([]string{s.Default}, out...) + } + return out +} + +// kimiModelInfo is what a [models.""] table says of thinking, its +// [overrides] over it. +type kimiModelInfo struct { + Efforts []string + Default string + Caps []string +} + +func (m kimiModelInfo) thinks() bool { + return slices.Contains(m.Caps, "thinking") || slices.Contains(m.Caps, "always_thinking") || len(m.Efforts) > 0 +} + +func (m kimiModelInfo) always() bool { return slices.Contains(m.Caps, "always_thinking") } + +// kimiDoc is the config at path, read: [secondary_model] and the model +// tables' thinking. ok is false when it can't be read or parsed. +func kimiDoc(path string) (sec kimiSec, models map[string]kimiModelInfo, ok bool) { + type levels struct { + Capabilities []string `toml:"capabilities"` + SupportEfforts []string `toml:"support_efforts"` + DefaultEffort string `toml:"default_effort"` + } + var doc struct { + Secondary *struct { + DefaultModel string `toml:"default_model"` + Model string `toml:"model"` + Models map[string]string `toml:"models"` + DefaultEffort string `toml:"default_effort"` + } `toml:"secondary_model"` + Models map[string]struct { + levels + Overrides *levels `toml:"overrides"` + } `toml:"models"` + } + b, err := edit.Read(path) + if err != nil { + return kimiSec{}, nil, false + } + if err := toml.Unmarshal(edit.TrimBOM(b), &doc); err != nil { + return kimiSec{}, nil, false + } + if s := doc.Secondary; s != nil { + sec = kimiSec{Default: s.DefaultModel, Legacy: s.Model, Pool: s.Models, Effort: strings.ToLower(strings.TrimSpace(s.DefaultEffort))} + } + models = map[string]kimiModelInfo{} + for k, m := range doc.Models { + info := kimiModelInfo{Efforts: m.SupportEfforts, Default: m.DefaultEffort, Caps: m.Capabilities} + if o := m.Overrides; o != nil { + if o.SupportEfforts != nil { + info.Efforts = o.SupportEfforts + } + if o.DefaultEffort != "" { + info.Default = o.DefaultEffort + } + if o.Capabilities != nil { + info.Caps = o.Capabilities + } + } + models[k] = info + } + return sec, models, true +} + +// kimiPoolLevels are the subagent efforts every model of pool takes, as +// Kimi checks default_effort: off unless one always thinks, any other level +// only where each thinks and lists it (or lists none). A model the config +// doesn't describe (Kimi Code's own sign-in's, from its catalog) is taken +// at the common levels. Nil for no pool: Kimi ignores the effort then. +func kimiPoolLevels(pool []string, models map[string]kimiModelInfo) []string { + if len(pool) == 0 { + return nil + } + off := true + var levels []string // nil: any yet + any := true + for _, alias := range pool { + m, known := models[alias] + if !known { + m = kimiModelInfo{Efforts: kimiCommonLevels[1:], Caps: []string{"thinking"}} + } + if m.always() { + off = false + } + if !m.thinks() { + levels, any = []string{}, false + continue + } + if len(m.Efforts) == 0 { + continue + } + var own []string + for _, e := range m.Efforts { + if e = strings.ToLower(strings.TrimSpace(e)); e != "" && e != "off" && e != "none" { + own = append(own, e) + } + } + if any { + levels, any = own, false + continue + } + levels = slices.DeleteFunc(levels, func(e string) bool { return !slices.Contains(own, e) }) + } + if any { + levels = kimiCommonLevels[1:] + } + var out []string + if off { + out = append(out, "off") + } + return append(out, levels...) +} + +// kimiSecStashKey is where the stash keeps the subagent model the user had +// before magpie first put one of its own models in [secondary_model]. +func kimiSecStashKey(path string) string { return "kimi:" + path + ":secondary" } + +// kimiSecStash keeps the user's subagent model, once, as a magpie model +// first goes in. +func kimiSecStash(path string, s kimiSec) { + k := kimiSecStashKey(path) + if _, ok := stashShared()[k]; ok { + return + } + b, _ := json.Marshal(map[string]string{"default_model": s.def()}) + stash(map[string]string{k: string(b)}) +} + +func kimiSecStashed(path string) string { + var was map[string]string + json.Unmarshal([]byte(stashShared()[kimiSecStashKey(path)]), &was) + return was["default_model"] +} + +// kimiSecWrite writes [secondary_model] from was to now, each key in place, +// the user's other keys and comments kept. An effort the new pool can't +// take goes first and a new one last, so Kimi, which reads the file as it +// changes, never meets one its pool refuses. +func kimiSecWrite(path string, was, now kimiSec) error { + if was.Effort != "" && was.Effort != now.Effort { + if err := edit.DelTOMLKey(path, kimiSecondary, "default_effort"); err != nil { + return err + } + } + setDefault := func() error { + if now.Default == was.Default { + return nil + } + if now.Default == "" { + return edit.DelTOMLKey(path, kimiSecondary, "default_model") + } + return edit.SetTOMLKey(path, kimiSecondary, "default_model", now.Default) + } + // a section new: its default before its pool, a pool of one till then + fresh := was.Default == "" && was.Legacy == "" && was.Pool == nil && was.Effort == "" + if fresh { + if err := setDefault(); err != nil { + return err + } + } + if !sameTable(was.Pool, now.Pool) { + tables, _ := edit.TOMLTables(path) + own := slices.Contains(tables, kimiSecondary+".models") + if was.Pool != nil && !own { + // written inline (models = { … }) or dotted: out, for the table + if err := edit.DelTOMLKey(path, kimiSecondary, "models"); err != nil { + return err + } + } + if now.Pool == nil { + if err := edit.DelTOMLTable(path, kimiSecondary+".models"); err != nil { + return err + } + } else { + kvs := make([]edit.KV, 0, len(now.Pool)) + for _, k := range now.pool() { + kvs = append(kvs, edit.KV{Path: strconv.Quote(k), Value: now.Pool[k]}) + } + if err := edit.SetTOMLTable(path, kimiSecondary+".models", kvs...); err != nil { + return err + } + } + } + if !fresh { + if err := setDefault(); err != nil { + return err + } + } + if was.Legacy != "" && now.Legacy == "" { + if err := edit.DelTOMLKey(path, kimiSecondary, "model"); err != nil { + return err + } + } + if now.Effort != "" && now.Effort != was.Effort { + if err := edit.SetTOMLKey(path, kimiSecondary, "default_effort", now.Effort); err != nil { + return err + } + } + return nil +} + +// sameTable is maps.Equal with no table and an empty one apart. +func sameTable(a, b map[string]string) bool { + if (a == nil) != (b == nil) || len(a) != len(b) { + return false + } + for k, v := range a { + if w, ok := b[k]; !ok || w != v { + return false + } + } + return true +} + +// kimiSecFit is now with its effort dropped when its pool can't take it. +func kimiSecFit(now kimiSec, models map[string]kimiModelInfo) kimiSec { + if now.Effort != "" && !slices.Contains(kimiPoolLevels(now.pool(), models), now.Effort) && now.pool() != nil { + now.Effort = "" + } + return now +} + +// kimiPruneSecondary takes out of [secondary_model] each of magpie's +// models keep says is going: from the pool, and as the default, which goes +// back to the one the user had (restore, while Kimi still has it), else the +// pool's first, else none, so subagents follow the lead again. An effort +// the pool left can't take goes too. The user's own names stay. +func kimiPruneSecondary(path string, keep func(alias string) bool, restore string) error { + was, models, ok := kimiDoc(path) + if !ok { + return nil + } + gone := func(k string) bool { return strings.HasPrefix(k, magpieID+"/") && !keep(k) } + now := was + if was.Pool != nil { + now.Pool = map[string]string{} + for k, v := range was.Pool { + if !gone(k) { + now.Pool[k] = v + } + } + } + if gone(now.Legacy) { + now.Legacy = "" + } + if gone(now.Default) || now.Default == "" && was.Legacy != "" && now.Legacy == "" { + now.Default = "" + switch { + case restore != "" && !strings.HasPrefix(restore, magpieID+"/"): + // the user's, as they had it: into the pool left, as Kimi's + // own /secondary-model puts a default + now.Default = restore + if len(now.Pool) > 0 && !hasKey(now.Pool, restore) { + now.Pool[restore] = "" + } + case len(now.Pool) > 0: + now.Default = kimiSec{Pool: now.Pool}.pool()[0] + } + } + if now.Pool != nil && len(now.Pool) == 0 { + now.Pool = nil + } + if now.Pool == nil && now.def() == "" { + now.Effort = "" // nothing for it to apply to: the lead's own + } + now = kimiSecFit(now, models) + if sameTable(was.Pool, now.Pool) && was.Default == now.Default && was.Legacy == now.Legacy && was.Effort == now.Effort { + return nil + } + if err := kimiSecWrite(path, was, now); err != nil { + return err + } + return kimiSecDropEmpty(path) +} + +func hasKey(m map[string]string, k string) bool { _, ok := m[k]; return ok } + +// kimiSecDropEmpty takes out a [secondary_model] left with nothing in it. +func kimiSecDropEmpty(path string) error { + t, err := edit.GetTOMLTable(path, kimiSecondary) + if err != nil || t == nil || len(t) > 0 { + return err + } + tables, _ := edit.TOMLTables(path) + if slices.Contains(tables, kimiSecondary+".models") { + return nil + } + return edit.DelTOMLTable(path, kimiSecondary) +} + +// kimiSubagentFields are the subagents' model, pool and effort, for the new +// Kimi Code. wired reports whether magpie's provider is in the config: a +// magpie model can go in only then, its table there. +func kimiSubagentFields(path string, wired func() bool, own func(string) []Option) []Field { + read := func() (kimiSec, map[string]kimiModelInfo) { + s, m, _ := kimiDoc(path) + return s, m + } + // check refuses a name Kimi would not resolve: one of magpie's whose + // table isn't there (not connected, or gone from the catalog) + check := func(models map[string]kimiModelInfo, names ...string) error { + for _, k := range names { + if !strings.HasPrefix(k, magpieID+"/") { + continue + } + if _, ok := models[k]; !ok || !wired() { + return fmt.Errorf("pick a model through magpie for Kimi Code first; its subagents can then run on one of magpie's") + } + } + return nil + } + options := func() []Option { + if wired() { + return withVia(own(""), "kimi", magpieID+"/") + } + return own("") + } + return []Field{{ + // [secondary_model] default_model: unset, every subagent runs on + // the lead's model (no section at all, as Kimi has it) + Key: "subagent_model", Label: "subagent model", Quiet: true, + Get: func() string { s, _ := read(); return s.def() }, + Set: func(v string) error { + was, models := read() + now := was + if v == "" { + now = kimiSec{} + } else { + if err := check(models, v); err != nil { + return err + } + if strings.HasPrefix(v, magpieID+"/") { + kimiSecStash(path, was) + } + // as Kimi's own /secondary-model: the default, and into a + // pool there is, its description empty + now.Default, now.Legacy = v, "" + if was.Pool != nil { + now.Pool = maps.Clone(was.Pool) + if !hasKey(now.Pool, v) { + now.Pool[v] = "" + } + } + } + now = kimiSecFit(now, models) + if err := kimiSecWrite(path, was, now); err != nil { + return err + } + return kimiSecDropEmpty(path) + }, + Options: func(map[string]string) []Option { return options() }, + }, { + // [secondary_model.models]: the models the lead may put a subagent + // on, one a line; the default stays one of them + Key: "subagent_pool", Label: "subagent pool", Quiet: true, + Get: func() string { + s, _ := read() + if s.Pool == nil { + return "" + } + return strings.Join(s.pool(), "\n") + }, + Set: func(v string) error { + was, models := read() + var names []string + for _, k := range strings.Split(v, "\n") { + if k = strings.TrimSpace(k); k != "" && !slices.Contains(names, k) { + names = append(names, k) + } + } + if err := check(models, names...); err != nil { + return err + } + now := was + if len(names) == 0 { + now.Pool = nil + } else { + if slices.ContainsFunc(names, func(k string) bool { return strings.HasPrefix(k, magpieID+"/") }) { + kimiSecStash(path, was) + } + now.Pool = map[string]string{} + for _, k := range names { + now.Pool[k] = was.Pool[k] // a description written stays + } + if !hasKey(now.Pool, now.def()) { + now.Default, now.Legacy = names[0], "" + } + if now.Default == "" { + now.Default, now.Legacy = now.Legacy, "" + } + } + now = kimiSecFit(now, models) + if err := kimiSecWrite(path, was, now); err != nil { + return err + } + return kimiSecDropEmpty(path) + }, + Options: func(map[string]string) []Option { return options() }, + }, { + // [secondary_model] default_effort: unset, a subagent thinks as its + // model does by default + Key: "subagent_effort", Label: "subagent effort", Quiet: true, + Get: func() string { s, _ := read(); return s.Effort }, + Set: func(v string) error { + v = strings.ToLower(strings.TrimSpace(v)) + was, models := read() + if v != "" { + l := kimiPoolLevels(was.pool(), models) + if l == nil { + return fmt.Errorf("pick a subagent model for Kimi Code first; with none, its subagents think as the lead does") + } + if !slices.Contains(l, v) { + return fmt.Errorf("Kimi Code's subagent models take %s, not %q: it would refuse to start a session", strings.Join(l, ", "), v) + } + } + now := was + now.Effort = v + if err := kimiSecWrite(path, was, now); err != nil { + return err + } + return kimiSecDropEmpty(path) + }, + Options: func(map[string]string) []Option { + s, models := read() + return static(kimiPoolLevels(s.pool(), models)...) + }, + }} +} + +// kimiSubagents are kimiSubagentFields for the new Kimi Code; kimi-cli has +// no subagent pool, and a stopped WSL distro's (cold) has none until it runs +// again: each of the three reads the config, which would start it (#3896). +func kimiSubagents(path string, legacy, cold bool, wired func() bool) []Field { + if legacy || cold { + return nil + } + return kimiSubagentFields(path, wired, func(cur string) []Option { return kimiOwnOptions(path, cur) }) +} diff --git a/internal/agent/kimi_subagents_test.go b/internal/agent/kimi_subagents_test.go new file mode 100644 index 000000000..4fa69d61e --- /dev/null +++ b/internal/agent/kimi_subagents_test.go @@ -0,0 +1,294 @@ +package agent + +import ( + "os" + "path/filepath" + "slices" + "strings" + "testing" + + "github.com/pelletier/go-toml/v2" + + "github.com/yetone/magpie/internal/catalog" + "github.com/yetone/magpie/internal/provider" +) + +// kimiSubagentHome is a sandbox HOME with a Kimi Code config holding the +// user's own model, and magpie's provider "think" with three models: deep +// (high, max), wide (low, medium) and plain (no thinking). +func kimiSubagentHome(t *testing.T, config string) (home, path string) { + t.Helper() + home = t.TempDir() + t.Setenv("HOME", home) + t.Setenv("USERPROFILE", home) + t.Setenv("XDG_CONFIG_HOME", filepath.Join(home, ".config")) + t.Setenv("XDG_CACHE_HOME", filepath.Join(home, ".cache")) + t.Setenv("KIMI_SHARE_DIR", "") + t.Setenv("KIMI_CODE_HOME", "") + if err := provider.Save(provider.Provider{ + ID: "think", Name: "Think", Chat: "https://example.test/v1", Key: "key", + Models: []string{"deep", "wide", "plain"}, + }); err != nil { + t.Fatal(err) + } + if err := catalog.SaveLive("think", "https://example.test/v1", []catalog.Model{ + {ID: "deep", Efforts: []string{"high", "max"}}, + {ID: "wide", Efforts: []string{"low", "medium"}}, + {ID: "plain"}, + }); err != nil { + t.Fatal(err) + } + path = filepath.Join(home, ".kimi-code", "config.toml") + writeFile(t, path, config) + return home, path +} + +// kimiOwnConfig is Kimi Code after its own sign-in, with a model of the +// user's own that thinks at low to high. +const kimiOwnConfig = `default_model = "kimi-code/kimi-for-coding" + +[models."kimi-code/kimi-for-coding"] +provider = "managed:kimi-code" +model = "kimi-for-coding" +max_context_size = 262144 +capabilities = ["thinking", "tool_use"] +support_efforts = ["low", "medium", "high"] + +[providers."managed:kimi-code"] +type = "kimi" +base_url = "https://api.kimi.com/coding/v1" +api_key = "" +` + +// kimiSubagentsValid fails the test where Kimi Code 2.6.2 would refuse the +// config at a session's start (session/subagent/configSection.ts, +// assertValidSubagentModelPool and assertValidSubagentDefaultEffort), and +// returns its [secondary_model]. +func kimiSubagentsValid(t *testing.T, path string) map[string]any { + t.Helper() + b, err := os.ReadFile(path) + if err != nil { + t.Fatal(err) + } + var c struct { + Secondary map[string]any `toml:"secondary_model"` + Models map[string]struct { + Capabilities []string `toml:"capabilities"` + SupportEfforts []string `toml:"support_efforts"` + } `toml:"models"` + } + if err := toml.Unmarshal(b, &c); err != nil { + t.Fatalf("%v\n%s", err, b) + } + s := c.Secondary + if s == nil { + return nil + } + def, _ := s["default_model"].(string) + if def == "" { + def, _ = s["model"].(string) + } + var pool []string + if m, ok := s["models"].(map[string]any); ok { + if def == "" { + t.Fatalf("a pool with no default_model:\n%s", b) + } + if _, ok := m[def]; !ok { + t.Fatalf("default_model %q not in the pool:\n%s", def, b) + } + for k := range m { + pool = append(pool, k) + } + } else if def != "" { + pool = []string{def} + } + for _, k := range pool { + if _, ok := c.Models[k]; !ok { + t.Fatalf("pool entry %q names no model:\n%s", k, b) + } + } + eff, _ := s["default_effort"].(string) + if eff == "" || pool == nil { + return s + } + for _, k := range pool { + m := c.Models[k] + always := slices.Contains(m.Capabilities, "always_thinking") + thinks := always || slices.Contains(m.Capabilities, "thinking") + switch { + case eff == "off" && always: + t.Fatalf("off on %q, which always thinks:\n%s", k, b) + case eff == "off": + case !thinks: + t.Fatalf("effort %q on %q, which doesn't think:\n%s", eff, k, b) + case len(m.SupportEfforts) > 0 && eff != "on" && !slices.Contains(m.SupportEfforts, eff): + t.Fatalf("effort %q not among %q's %v:\n%s", eff, k, m.SupportEfforts, b) + } + } + return s +} + +func kimiOptionValues(f *Field, vals map[string]string) []string { + var out []string + for _, o := range f.Options(vals) { + out = append(out, o.Value) + } + return out +} + +// XiaoLing_Arisa on X: Kimi Code's subagent pool and its effort, picked +// from magpie's models, written as Kimi reads them; each write is one Kimi +// takes, and Disconnect puts back the subagent model the user had. +func TestKimiSubagentPool(t *testing.T) { + home, path := kimiSubagentHome(t, kimiOwnConfig+` +[secondary_model] +default_model = "kimi-code/kimi-for-coding" +`) + a := kimi(home) + sub, pool, eff := a.Field("subagent_model"), a.Field("subagent_pool"), a.Field("subagent_effort") + if sub == nil || pool == nil || eff == nil { + t.Fatal("no subagent fields") + } + if sub.Get() != "kimi-code/kimi-for-coding" || pool.Get() != "" { + t.Fatalf("read: %q %q", sub.Get(), pool.Get()) + } + // not connected: magpie's models have no tables Kimi could resolve + if err := sub.Set("magpie/think/deep"); err == nil { + t.Fatal("a magpie model went in with magpie not connected") + } + if slices.ContainsFunc(kimiOptionValues(sub, a.Values()), func(v string) bool { return strings.HasPrefix(v, "magpie/") }) { + t.Fatal("magpie's models offered before it is connected") + } + if err := a.Apply("model", "magpie/think/deep"); err != nil { + t.Fatal(err) + } + if !slices.Contains(kimiOptionValues(pool, a.Values()), "magpie/think/wide") { + t.Fatalf("pool options: %v", kimiOptionValues(pool, a.Values())) + } + + // a pool of magpie's: the user's default isn't in it, so the first is + if err := pool.Set("magpie/think/deep\nmagpie/think/wide"); err != nil { + t.Fatal(err) + } + s := kimiSubagentsValid(t, path) + if s["default_model"] != "magpie/think/deep" || pool.Get() != "magpie/think/deep\nmagpie/think/wide" { + t.Fatalf("pool: %v %q", s, pool.Get()) + } + // deep and wide share no level: off only + if got := kimiOptionValues(eff, a.Values()); !slices.Equal(got, []string{"off"}) { + t.Fatalf("effort options for deep+wide: %v", got) + } + if err := eff.Set("high"); err == nil { + t.Fatal("high taken for wide, which hasn't it") + } + + // the user's description of an entry stays through a change + b, _ := os.ReadFile(path) + os.WriteFile(path, []byte(strings.Replace(string(b), `"magpie/think/deep" = ""`, `"magpie/think/deep" = "hard problems"`, 1)), 0o644) + if err := pool.Set("magpie/think/deep"); err != nil { + t.Fatal(err) + } + s = kimiSubagentsValid(t, path) + if m, _ := s["models"].(map[string]any); m["magpie/think/deep"] != "hard problems" || len(m) != 1 { + t.Fatalf("description: %v", s) + } + if got := kimiOptionValues(eff, a.Values()); !slices.Equal(got, []string{"off", "high", "max"}) { + t.Fatalf("effort options for deep: %v", got) + } + if err := eff.Set("MAX"); err != nil { + t.Fatal(err) + } + if s = kimiSubagentsValid(t, path); s["default_effort"] != "max" { + t.Fatalf("effort: %v", s) + } + // wide joins: max is none of its, so the effort goes rather than + // leaving a config Kimi refuses + if err := pool.Set("magpie/think/deep\nmagpie/think/wide"); err != nil { + t.Fatal(err) + } + if s = kimiSubagentsValid(t, path); s["default_effort"] != nil { + t.Fatalf("max kept for wide: %v", s) + } + + // the default picked as Kimi's own /secondary-model does: into the pool + if err := sub.Set("magpie/think/plain"); err != nil { + t.Fatal(err) + } + s = kimiSubagentsValid(t, path) + if m, _ := s["models"].(map[string]any); s["default_model"] != "magpie/think/plain" || len(m) != 3 { + t.Fatalf("default: %v", s) + } + + // Disconnect: magpie's models out, the user's subagent model back + if err := a.Disconnect(); err != nil { + t.Fatal(err) + } + s = kimiSubagentsValid(t, path) + b, _ = os.ReadFile(path) + if s["default_model"] != "kimi-code/kimi-for-coding" || s["models"] != nil || strings.Contains(string(b), "magpie") { + t.Fatalf("disconnect:\n%s", b) + } +} + +// A model leaving magpie's catalog leaves the pool before its table goes, +// so Kimi never meets a pool naming a model it lacks. +func TestKimiSubagentPoolSync(t *testing.T) { + home, path := kimiSubagentHome(t, kimiOwnConfig) + a := kimi(home) + if err := a.Apply("model", "magpie/think/deep"); err != nil { + t.Fatal(err) + } + if err := a.Field("subagent_pool").Set("magpie/think/wide\nkimi-code/kimi-for-coding"); err != nil { + t.Fatal(err) + } + if s := kimiSubagentsValid(t, path); s["default_model"] != "magpie/think/wide" { + t.Fatalf("pool: %v", s) + } + if err := provider.Save(provider.Provider{ + ID: "think", Name: "Think", Chat: "https://example.test/v1", Key: "key", + Models: []string{"deep", "plain"}, + }); err != nil { + t.Fatal(err) + } + if err := a.Sync(); err != nil { + t.Fatal(err) + } + s := kimiSubagentsValid(t, path) + m, _ := s["models"].(map[string]any) + if s["default_model"] != "kimi-code/kimi-for-coding" || len(m) != 1 { + b, _ := os.ReadFile(path) + t.Fatalf("after sync:\n%s", b) + } + // Default: subagents on the lead's model, the section gone + if err := a.Field("subagent_model").Set(""); err != nil { + t.Fatal(err) + } + if b, _ := os.ReadFile(path); strings.Contains(string(b), "secondary_model") { + t.Fatalf("default:\n%s", b) + } +} + +// The user's own pool, of their own models, is theirs: connecting and +// disconnecting leave it as written, comments and all. +func TestKimiSubagentPoolKeepsTheUsers(t *testing.T) { + own := kimiOwnConfig + ` +[secondary_model] +# subagents on the plan's model +default_model = "kimi-code/kimi-for-coding" +default_effort = "medium" + +[secondary_model.models] +"kimi-code/kimi-for-coding" = "everything" +` + home, path := kimiSubagentHome(t, own) + a := kimi(home) + if err := a.Apply("model", "magpie/think/deep"); err != nil { + t.Fatal(err) + } + if err := a.Disconnect(); err != nil { + t.Fatal(err) + } + if b, _ := os.ReadFile(path); string(b) != own { + t.Fatalf("the user's pool changed:\n%s", b) + } +} diff --git a/internal/gui/assets/app.js b/internal/gui/assets/app.js index 25af17821..811328f49 100644 --- a/internal/gui/assets/app.js +++ b/internal/gui/assets/app.js @@ -516,7 +516,7 @@ function renderAgents() { const wide = (f) => f.label === "model" || f.label === "large" || f.label === "executor" || f.label === "planner"; // a field with nothing to pick and nothing set isn't drawn (#1499) const none = (f) => (f.key === "effort" || toggled(f) || f.label === "subagents" || f.label === "gateway" || f.label === SUB_EFFORT || f.label === SUB_MODEL || f.label === AUTO_MODE || f.label === ADVISOR || f.label === MEMORIES || f.label === COMPACT_MODEL || f.label === "sign-in" || f.key === "small" || asideAccount(a, f)) && !f.options.length && !f.value; - const shownFields = a.fields.filter((f) => !grouped(a, f) && !none(f) && !codexOwnSub(a, f) && !codexRowed(a, f) && !hermesBot(f) && !ompAdvisorKey(f) && !protocolField(f)); + const shownFields = a.fields.filter((f) => !(kimiSub(a) && f.key.startsWith("subagent_")) && !grouped(a, f) && !none(f) && !codexOwnSub(a, f) && !codexRowed(a, f) && !hermesBot(f) && !ompAdvisorKey(f) && !protocolField(f)); const tiers = tierMenu(a); if (tiers) shownFields.push(tiers); const sorted = shownFields.sort((x, y) => wide(y) - wide(x) || extra(x) - extra(y)); @@ -1493,12 +1493,14 @@ function expandLink(a) { const want = open ? null : a.id; const own = want && agentPrefsOf(a); const compact = own && own.includes("fullContextRow") && !window.agentCompactFill; + // and Kimi Code's Subagents line (kimisub.js) is there to measure + const kim = want && kimiSub(a) && !window.kimiSubLine; // sheet measures once: its settings are read first (#5360, chiperman) - if (own && (!prefs || compact)) { + if ((own && (!prefs || compact)) || kim) { const label = [...b.childNodes]; b.disabled = true; saving(b, t("Loading…")); - try { await Promise.all([!prefs && loadSettings(), compact && import("./agentcompact.js")]); } + try { await Promise.all([own && !prefs && loadSettings(), compact && import("./agentcompact.js"), kim && import("./kimisub.js")]); } catch (e) { if (request === agentExpandRequest && b.isConnected) statusErr(e); return; } finally { b.disabled = false; doneSaving(b); b.replaceChildren(...label); } if (request !== agentExpandRequest || !b.isConnected || view !== "agents") return; @@ -2251,6 +2253,10 @@ function connectPanel(a, { fields, fieldBtn }) { kv(t("Claude models"), line(t("claude-* models need a Claude subscription in magpie"), add)); } } + // Kimi Code's subagents ([secondary_model]; XiaoLing_Arisa on X): their + // line, drawn by kimisub.js, which Details imports before it first opens + // (a row drawn open from the start imports it here) + if (kimiSub(a)) { const v = kv(t("Subagents")), d = () => v.append(kimiSubLine(a, line, fieldBtn)); window.kimiSubLine ? d() : import("./kimisub.js").then(d, () => {}); } // which of magpie's models it lists, by whose they are if (a.models) { const chips = line(); @@ -3973,6 +3979,9 @@ const MEMORIES = "memories"; // the model magpie puts every Codex (or Claude Desktop) subagent on, // whatever its lead asked for (willz on Discord, #1633) const SUB_MODEL = "subagent model"; +// Kimi Code's subagents: their model, pool and effort are one line of the +// opened row (kimisub.js), never squares +const kimiSub = (a) => a.fields.some((f) => f.key == "subagent_pool"); // Claude Code's auto mode square: the model its client-side auto mode // classifier runs on (CLAUDE_CODE_AUTO_MODE_MODEL); unset, Claude Code's own // pick, not the model's @@ -4834,7 +4843,7 @@ function openPicker(agent, field, anchor, ev, only) { const note = agent.id === "reasonix" && ["model", "planner"].includes(field.key) ? "restore the previous {field} selection" : PICKS_ITSELF.includes(agent.id) && field.key === "model" ? "clears the default model; {agent} picks one on its own" : field.label === MEMORIES ? MEMORIES_DEFAULT - : field.label === SUB_MODEL ? "each subagent on the model {agent}'s lead asks for" + : field.label === SUB_MODEL ? (kimiSub(agent) ? "each subagent on the lead's model" : "each subagent on the model {agent}'s lead asks for") : field.label === AUTO_MODE ? "the model {agent} picks for its auto mode classifier" : field.label === ADVISOR ? "no advisor" : field.label === COMPACT_MODEL ? "each compaction on the session's model" diff --git a/internal/gui/assets/i18n.js b/internal/gui/assets/i18n.js index 832fb0eb8..247459d27 100644 --- a/internal/gui/assets/i18n.js +++ b/internal/gui/assets/i18n.js @@ -4486,6 +4486,11 @@ const I18N = { "{model} unless the lead or the subagent names another": "{model},主代理或子代理指定其他模型时除外", "the model the lead asks for": "主代理请求的模型", "each subagent on the model {agent}'s lead asks for": "每个子代理都用 {agent} 主代理请求的模型", + "each subagent on the lead's model": "每个子代理都用主代理的模型", + "More models": "更多模型", + "Models the lead may start a subagent on": "主代理可让子代理使用的模型", + "pick a model through magpie for Kimi Code first; its subagents can then run on one of magpie's": "请先为 Kimi Code 选一个经由 magpie 的模型,子代理才能用 magpie 的模型", + "pick a subagent model for Kimi Code first; with none, its subagents think as the lead does": "请先为 Kimi Code 选一个子代理模型;未选时,子代理的推理强度与主代理相同", "auto mode": "自动模式", "Auto mode": "自动模式", "Claude Code's own pick": "由 Claude Code 自己挑选", @@ -9823,6 +9828,11 @@ const I18N = { "{model} unless the lead or the subagent names another": "{model},主代理或子代理指定其他模型時除外", "the model the lead asks for": "主代理請求的模型", "each subagent on the model {agent}'s lead asks for": "每個子代理都用 {agent} 主代理請求的模型", + "each subagent on the lead's model": "每個子代理都用主代理的模型", + "More models": "更多模型", + "Models the lead may start a subagent on": "主代理可讓子代理使用的模型", + "pick a model through magpie for Kimi Code first; its subagents can then run on one of magpie's": "請先為 Kimi Code 選一個經由 magpie 的模型,子代理才能用 magpie 的模型", + "pick a subagent model for Kimi Code first; with none, its subagents think as the lead does": "請先為 Kimi Code 選一個子代理模型;未選時,子代理的推理強度與主代理相同", "auto mode": "自動模式", "Auto mode": "自動模式", "Claude Code's own pick": "由 Claude Code 自己挑選", @@ -15181,6 +15191,11 @@ const I18N = { "{model} unless the lead or the subagent names another": "{model}(リードかサブエージェントが別のモデルを指定した場合を除く)", "the model the lead asks for": "リードがリクエストしたモデル", "each subagent on the model {agent}'s lead asks for": "各サブエージェントは {agent} のリードがリクエストしたモデルを使います", + "each subagent on the lead's model": "各サブエージェントはリードのモデルを使います", + "More models": "ほかのモデル", + "Models the lead may start a subagent on": "リードがサブエージェントに使えるモデル", + "pick a model through magpie for Kimi Code first; its subagents can then run on one of magpie's": "先に Kimi Code で magpie 経由のモデルを選んでください。サブエージェントも magpie のモデルを使えるようになります", + "pick a subagent model for Kimi Code first; with none, its subagents think as the lead does": "先に Kimi Code のサブエージェントのモデルを選んでください。未設定ならリードと同じ推論レベルです", "auto mode": "自動モード", "Auto mode": "自動モード", "Claude Code's own pick": "Claude Code が自分で選ぶ", @@ -20546,6 +20561,11 @@ const I18N = { "{model} unless the lead or the subagent names another": "{model}, außer der Haupt-Agent oder der Subagent nennt ein anderes", "the model the lead asks for": "das Modell, das der Haupt-Agent anfordert", "each subagent on the model {agent}'s lead asks for": "jeder Subagent auf dem Modell, das der Haupt-Agent von {agent} anfordert", + "each subagent on the lead's model": "jeder Subagent auf dem Modell des Haupt-Agenten", + "More models": "Weitere Modelle", + "Models the lead may start a subagent on": "Modelle, auf denen der Haupt-Agent einen Subagenten starten darf", + "pick a model through magpie for Kimi Code first; its subagents can then run on one of magpie's": "Wähle zuerst ein Modell über magpie für Kimi Code; dann können seine Subagenten auf einem von magpies Modellen laufen", + "pick a subagent model for Kimi Code first; with none, its subagents think as the lead does": "Wähle zuerst ein Subagenten-Modell für Kimi Code; ohne eines denken seine Subagenten wie der Haupt-Agent", "auto mode": "Auto-Modus", "Auto mode": "Auto-Modus", "Claude Code's own pick": "wählt Claude Code selbst", diff --git a/internal/gui/assets/kimisub.js b/internal/gui/assets/kimisub.js new file mode 100644 index 000000000..86e83a01b --- /dev/null +++ b/internal/gui/assets/kimisub.js @@ -0,0 +1,63 @@ +// Kimi Code's subagents (XiaoLing_Arisa on X), one line of its opened row: +// the model each starts on, its effort, and the pool, the other models its +// lead may start one on, as Kimi Code's [secondary_model] has them +// (kimi_secondary.go). app.js imports this the first time the line shows +// (connectPanel), so it weighs nothing on the core. +const SUB_POOL = "subagent pool"; +window.kimiSubLine = function (a, line, fieldBtn) { + const sub = a.fields.find((f) => f.label === SUB_MODEL); + const eff = a.fields.find((f) => f.label === SUB_EFFORT); + const l = line(fieldBtn(sub, "ag-pick")); + if (eff && (eff.options.length || eff.value)) { + const b = fieldBtn(sub.value ? eff : { ...eff, value: "" }, "ag-eff"); + // Kimi Code takes an effort only beside a subagent model + b.disabled = !sub.value; + b.title = subEffortTitle(a, eff, optionFor(eff, eff.value)) + (sub.value ? "" : "\n" + t("Set a subagent model first")); + b.setAttribute("aria-label", b.title); + l.append(b); + } + l.append(kimiPoolButton(a)); + return l; +}; + +// kimiPoolButton: the other models Kimi Code's lead may start a subagent +// on, ticked in one menu; the subagent model stays among them +function kimiPoolButton(a) { + const f = a.fields.find((x) => x.label === SUB_POOL); + const sub = a.fields.find((x) => x.label === SUB_MODEL); + const names = (v) => String(v || "").split("\n").filter(Boolean); + const others = names(f.value).filter((v) => v !== sub?.value); + const b = el("button", "field ag-pick ag-pool"); + b.type = "button"; + b.dataset.key = f.key; + const label = (v) => optionFor(f, v)?.label || v; + b.append(svg("M8 3.25v9.5M3.25 8h9.5", 12, 1.6), el("span", "v" + (others.length ? "" : " empty"), others.length ? others.map(label).join(", ") : t("More models"))); + const c = el("span", "chev"); + c.append(svg(CHEV, 11, 1.7)); + b.append(c); + b.title = t("Models the lead may start a subagent on") + (others.length ? ":\n" + others.map(label).join("\n") : ""); + b.setAttribute("aria-label", b.title); + // the row is drawn again after each tick: read its fields as they are now + const live = (label) => state.agents.find((x) => x.id === a.id)?.fields.find((x) => x.label === label); + b.onclick = (ev) => { + openPicker({ id: "", name: "", fields: [] }, { key: f.key, label: "model", value: "", multi: true, + options: f.options.filter((o) => o.value), picked: (id) => names(live(SUB_POOL)?.value).includes(id), + onPick: async (id) => { + const p = live(SUB_POOL), s = live(SUB_MODEL)?.value; + if (!id || !p) return; + let have = names(p.value); + // the subagent model's own tick stays: Kimi wants it in the pool + if (id === s && have.includes(id)) return; + have = have.includes(id) ? have.filter((x) => x !== id) : [...have, id]; + if (s && have.length && !have.includes(s)) have.unshift(s); + try { + state = await api("set", { agent: a.id, field: p.key, value: have.join("\n") }); + renderAgents(); + // the menu stays on the row drawn again, for the next tick + const at = document.querySelector(`.agent[data-id="${CSS.escape(a.id)}"] .ag-pool`); + if (pick?.field.key === f.key && at) { pick.anchor = at; at.classList.add("open"); renderList(); } + } catch (err) { status(t(err.message), "err"); } + } }, b, ev); + }; + return b; +} diff --git a/internal/gui/core_budget_test.go b/internal/gui/core_budget_test.go index a24643e95..4d91ef2de 100644 --- a/internal/gui/core_budget_test.go +++ b/internal/gui/core_budget_test.go @@ -17,8 +17,8 @@ import ( // never what pays for a change (#5918); the history of each number is in // `git log -L` of this file. const ( - appScriptBudget = 1_088_312 // app.js: 1,080,614 at 8016205e3, with the 5,653 of room it had; +123 for a sidebar list folded from its page's row (hkwok06 on X), its chevron and fold in navicons.js, imported with the first list; +57 for each account of a provider's Usage card in a card of its own (normalcoder_ on X), past the 24 of room left; +17 for an allowance card's wallet line under its rings (apple_test_src on X), the one filter shared with its text line; +338 for the Daily update channel (fishmagic80 on X): its segment, its line under Update channel and the version row's two Up to date on Daily words, packed to the shortest form (one t() per choice); Settings › About and renderUpdate draw them on every window, so there is no page to move them to; +35 for Baidu Qianfan's Token Plan sign-in (yuushabu_buyinn on X, #5860): its field in qianfanplan.js, imported when such a provider's editor opens, drawn by renderStepPlan now told whose sign-in it brings, and what is left is the import and two quotaError lines, past the room there was; quotaError reads every card's error, so there is no page to move it to; +27 for Windows' title bar (258a14 on X): the caption buttons, their clicks, the bar's double click and what keeps them over a dialog in wincap.js, imported in Windows' window alone, the header's room for them in app.css, and what is left is the one line that imports it, past the 29 of room there was; that window's frame is drawn on every start, so there is no page to move it to; +107 for the pages in the reader's own order (chet030714 on X): the order, the sidebar and tab bar put in it, and the menu's drag and keys in navorder.js and navpages.js, imported once an order is kept or Settings draws, and what is left is the one line in navHides that imports it; navHides runs on every start, so there is no page to move it to; +275 for the grants Alibaba's Token Plan asks of a RAM user's AccessKey in the reader's language (MetalHqa on X): one string (ALI_RAM) shown under the editor's AccessKey ID and on the card that names them, less the 48 of the wrong "a RAM user that may use Model Studio is enough" it replaces; the editor and quotaError draw them on every window, so there is no page to move them to; +135 for a model test its vendor queued shown queued and not green (sufeng1894 on X): queuedSaid, one string shared by the chip's title, Test models' and Test this model's status, and the chip's amber dot; renderModels draws the provider editor's chips, so there is no page to move it to; +66 for AstrLink Guard's row saying an x64 magpie runs it under Windows on Arm's emulation until the next update installs the Arm build (EV_John_Liu on X), the Rosetta line's sibling, one line in pmSub; the Privacy rows draw it, so there is no page to move it to; +864 for Use on a Claude setup-token account, which switches Claude Code itself to it in its settings.json, and Use back on its signed-in account (liukaybee on X): one swUse helper shared by both buttons, packed to the shortest form; renderAccounts draws every account row, so there is no page to move it to; +1 for the classifier timeout's unset default, 15 and not 8 (ESern29751 on X): its second digit in the Settings row's fallback, which renderReplies draws, so there is no page to move it to - coreScriptBudget = 1_272_591 // every core script at 8016205e3, the old measure 682 over its cap there (#5918); +367 for the model test on a chosen account (tmr11235), no page left to move it to; +151 for the provider menu's "Only on this device" item and its four translations; +458 for Settings › About's Report a problem row and its translations; +113 for withScheme, the one rule every typed address goes through (eachg0 on X), cut to the shortest form that keeps it whole; +10 for the kept whole's tooltip (Musikrv77852 on X), the past-cycle line reused for it, no page left to move it to; +1,112 for Codex's Open button and its Open Codex with menu (Yink88564391 on X), packed to the shortest form, no page left to move them to; +168 for Discover's long lists drawn in part (the owner, 11-13), after the rest of its hook moved into plugingrid.js, imported when Plugins first draws; +296 for the cap toggle and Smart sentences that say what they do and the Sign in on another computer row (Wing8Aqua on X), packed to the shortest form, no page left to move them to; +333 for In turn's figure in a provider's editor and its words naming the message that goes round (Wing8Aqua on X), the figure itself in rotfig.js, imported when In turn is first shown, the hook packed to the shortest form; +236 for a lone capped Codex account's row saying its turns go to the fallbacks when Codex is connected (not_4O4 on X), the two helpers inlined, no page left to move it to; +717 for omp's advisor (Awad_Yoo on X, #6408): its three rows moved into ompadvisor.js, imported when an omp's settings show, and what is left is the import, the role's " · off" and the Settings line's name, packed to the shortest form; +468 for a plugin's own file import (auth.import) in the import sheet, in the plugin's words (marchen_cc on X), packed to one statement; importSay is read as the Providers rows draw, so it has no lazy page to go to, and nothing else was moved out; +180 for Claude Magpie's own Claude Code folder (xMopf7RF on X, #6459): its Advanced fold in claudemagpie.js, imported when it first shows, and what is left is the import and the fold's place in the Separate app line, 216 bytes packed to the shortest form, less the 36 of room there was; +81 for the Use Claude Magpie button on Claude Desktop's row (xMopf7RF on X), drawn by claudemagpie.js too, what is left the one line that places it (#2710); +225 for the Hermes row's Other profiles lines (Norethcy on X), which 1d60b165c took out while each profile had a row and c96f33d65 left with no place at all, packed to the shortest form; the dead hermes# Default note went with it, and the Agents rows draw it, so there is no page to move it to; +397 for a key's own price rate (tnt12231 on X): its lines, check and placeholder in keyrates.js, imported when a provider with two or more keys opens, and what is left is the import, the draft's copy, Advanced opening for it, the save's one line and proxyLines drawing another kind of line; +316 for an image or video model's chip saying what it makes from its right-click (iceloon on X): the chat chip's Makes… now shared with it, and the media chip's Copy model ID left out, packed to the shortest form; the provider's editor draws it, so there is no page to move it to; +67 for the Claude Code · Claude Magpie row saying it is on magpie through Claude Magpie (xMopf7RF on X), one line in connectLine with the shortest words that say it; the Agents rows draw it, so there is no page to move it to; +12 for AIGoCode's logo in pngIcons (MindfulReturn on X), the list every drawn icon is looked up in; +491 for each cost in the tray panel's and Requests' chart and ranking in its own provider's currency (onkashiko on X): ledProv and the provider passed through, packed to the shortest form; drawLedColumns and drawLedRank are shared by the panel, so there is no page to move it to; +326 for the Qwen AI platform's Token Plan sign-in (imthe99galaxy on X): its field, sign-in and wait in qianwenplan.js, imported when such a provider's editor opens, and what is left is the import and one quotaError line for its two refusals, packed to the shortest form; quotaError reads every card's error, so there is no page to move it to; +72 for Copy all keys (emilochen on X): its row in keyrates.js, imported when a provider with two or more keys opens through keyRateField, now told which of its parts to draw, and what is left is the one line that places it; +83 for the page saying it has gone from view, so what its Sessions and Usage pages keep goes in 30 s and not 7 minutes (P0 memory): folded into the visibilitychange listener every window has, packed to the shortest form, so there is no page to move it to; +270 for Providers' Select, to remove several at once (eiyuuzaki2333 on X): its rows, bar, removal and keys in pvpick.js, imported when Select is first clicked, and what is left is pvSel, the button's click and two lines in renderProviders, which draws the list, so there is no page to move it to; +81 for each account of a provider's Usage card in a card of its own (normalcoder_ on X): one line that makes the box, its brief look left to CSS, and renderQuotas, which draws every card, so there is no page to move it to; +17 for Kimi Code's booster balance under an allowance card's rings in the tray panel (apple_test_src on X): the card's text line and the wallet line share one filter, packed to the shortest form; panelQuotaCard draws every card, so there is no page to move it to; +51 for what a failed plugin install left in plugins/, listed under Installed with a Remove (CHENGJIAHEGOXIS on X): its section in plugininstalled.js as pmLeftovers, imported when Plugins first draws, and what is left is the one call after drawInstalled; draw is what draws the page, so there is no page to move it to; +123 for a sidebar list folded from its page's row (hkwok06 on X): the chevron, its click and the fold kept per page in navicons.js, imported with the first list, and what is left is the folded list read beside the hidden pages' (navList, which navMine now shares) and the two rows' clicks asking navFold first; navSubs draws every list, so there is no page to move it to; +338 for the Daily update channel (fishmagic80 on X): its segment, its line under Update channel and the version row's two Up to date on Daily words, packed to the shortest form (one t() per choice); Settings › About and renderUpdate draw them on every window, so there is no page to move them to; +35 for Baidu Qianfan's Token Plan sign-in (yuushabu_buyinn on X, #5860): its field in qianfanplan.js, imported when such a provider's editor opens, drawn by renderStepPlan now told whose sign-in it brings, and what is left is the import and two quotaError lines, past the room there was; quotaError reads every card's error, so there is no page to move it to; +27 for Windows' title bar (258a14 on X): the caption buttons, their clicks, the bar's double click and what keeps them over a dialog in wincap.js, imported in Windows' window alone, the header's room for them in app.css, and what is left is the one line that imports it, past the 29 of room there was; that window's frame is drawn on every start, so there is no page to move it to; +107 for the pages in the reader's own order (chet030714 on X): the order, the sidebar and tab bar put in it, and the menu's drag and keys in navorder.js and navpages.js, imported once an order is kept or Settings draws, and what is left is the one line in navHides that imports it; navHides runs on every start, so there is no page to move it to; +275 for the grants Alibaba's Token Plan asks of a RAM user's AccessKey in the reader's language (MetalHqa on X): one string (ALI_RAM) shown under the editor's AccessKey ID and on the card that names them, less the 48 of the wrong "a RAM user that may use Model Studio is enough" it replaces; the editor and quotaError draw them on every window, so there is no page to move them to; +135 for a model test its vendor queued shown queued and not green (sufeng1894 on X): queuedSaid, one string shared by the chip's title, Test models' and Test this model's status, and the chip's amber dot; renderModels draws the provider editor's chips, so there is no page to move it to; +66 for AstrLink Guard's row saying an x64 magpie runs it under Windows on Arm's emulation until the next update installs the Arm build (EV_John_Liu on X), the Rosetta line's sibling, one line in pmSub; the Privacy rows draw it, so there is no page to move it to; +189 for Let magpie set it on a Codex card locked by config.toml's own compact limit or background threshold (sufeng1894 on X), and Undo for a background share taken over: the shared send posts it, packed to the shortest form; adviceRow draws every card, so there is no page to move it to; +864 for Use on a Claude setup-token account, which switches Claude Code itself to it in its settings.json, and Use back on its signed-in account (liukaybee on X): one swUse helper shared by both buttons, packed to the shortest form; renderAccounts draws every account row, so there is no page to move it to; +1 for the classifier timeout's unset default, 15 and not 8 (ESern29751 on X): its second digit in the Settings row's fallback, which renderReplies draws, so there is no page to move it to + appScriptBudget = 1_088_769 // app.js: 1,080,614 at 8016205e3, with the 5,653 of room it had; +123 for a sidebar list folded from its page's row (hkwok06 on X), its chevron and fold in navicons.js, imported with the first list; +57 for each account of a provider's Usage card in a card of its own (normalcoder_ on X), past the 24 of room left; +17 for an allowance card's wallet line under its rings (apple_test_src on X), the one filter shared with its text line; +338 for the Daily update channel (fishmagic80 on X): its segment, its line under Update channel and the version row's two Up to date on Daily words, packed to the shortest form (one t() per choice); Settings › About and renderUpdate draw them on every window, so there is no page to move them to; +35 for Baidu Qianfan's Token Plan sign-in (yuushabu_buyinn on X, #5860): its field in qianfanplan.js, imported when such a provider's editor opens, drawn by renderStepPlan now told whose sign-in it brings, and what is left is the import and two quotaError lines, past the room there was; quotaError reads every card's error, so there is no page to move it to; +27 for Windows' title bar (258a14 on X): the caption buttons, their clicks, the bar's double click and what keeps them over a dialog in wincap.js, imported in Windows' window alone, the header's room for them in app.css, and what is left is the one line that imports it, past the 29 of room there was; that window's frame is drawn on every start, so there is no page to move it to; +107 for the pages in the reader's own order (chet030714 on X): the order, the sidebar and tab bar put in it, and the menu's drag and keys in navorder.js and navpages.js, imported once an order is kept or Settings draws, and what is left is the one line in navHides that imports it; navHides runs on every start, so there is no page to move it to; +275 for the grants Alibaba's Token Plan asks of a RAM user's AccessKey in the reader's language (MetalHqa on X): one string (ALI_RAM) shown under the editor's AccessKey ID and on the card that names them, less the 48 of the wrong "a RAM user that may use Model Studio is enough" it replaces; the editor and quotaError draw them on every window, so there is no page to move them to; +135 for a model test its vendor queued shown queued and not green (sufeng1894 on X): queuedSaid, one string shared by the chip's title, Test models' and Test this model's status, and the chip's amber dot; renderModels draws the provider editor's chips, so there is no page to move it to; +66 for AstrLink Guard's row saying an x64 magpie runs it under Windows on Arm's emulation until the next update installs the Arm build (EV_John_Liu on X), the Rosetta line's sibling, one line in pmSub; the Privacy rows draw it, so there is no page to move it to; +864 for Use on a Claude setup-token account, which switches Claude Code itself to it in its settings.json, and Use back on its signed-in account (liukaybee on X): one swUse helper shared by both buttons, packed to the shortest form; renderAccounts draws every account row, so there is no page to move it to; +1 for the classifier timeout's unset default, 15 and not 8 (ESern29751 on X): its second digit in the Settings row's fallback, which renderReplies draws, so there is no page to move it to; +457 for Kimi Code's subagent pool and its effort (XiaoLing_Arisa on X): the Subagents line and its pool menu in kimisub.js, imported before a Kimi Code row's Details first slides open so it measures the line, and what is left is that import, the line's place, the three fields kept out of the row's squares and the picker's note that Kimi's subagents run on the lead's model, packed to the shortest form; renderAgents draws every row, so there is no page to move it to + coreScriptBudget = 1_273_048 // every core script at 8016205e3, the old measure 682 over its cap there (#5918); +367 for the model test on a chosen account (tmr11235), no page left to move it to; +151 for the provider menu's "Only on this device" item and its four translations; +458 for Settings › About's Report a problem row and its translations; +113 for withScheme, the one rule every typed address goes through (eachg0 on X), cut to the shortest form that keeps it whole; +10 for the kept whole's tooltip (Musikrv77852 on X), the past-cycle line reused for it, no page left to move it to; +1,112 for Codex's Open button and its Open Codex with menu (Yink88564391 on X), packed to the shortest form, no page left to move them to; +168 for Discover's long lists drawn in part (the owner, 11-13), after the rest of its hook moved into plugingrid.js, imported when Plugins first draws; +296 for the cap toggle and Smart sentences that say what they do and the Sign in on another computer row (Wing8Aqua on X), packed to the shortest form, no page left to move them to; +333 for In turn's figure in a provider's editor and its words naming the message that goes round (Wing8Aqua on X), the figure itself in rotfig.js, imported when In turn is first shown, the hook packed to the shortest form; +236 for a lone capped Codex account's row saying its turns go to the fallbacks when Codex is connected (not_4O4 on X), the two helpers inlined, no page left to move it to; +717 for omp's advisor (Awad_Yoo on X, #6408): its three rows moved into ompadvisor.js, imported when an omp's settings show, and what is left is the import, the role's " · off" and the Settings line's name, packed to the shortest form; +468 for a plugin's own file import (auth.import) in the import sheet, in the plugin's words (marchen_cc on X), packed to one statement; importSay is read as the Providers rows draw, so it has no lazy page to go to, and nothing else was moved out; +180 for Claude Magpie's own Claude Code folder (xMopf7RF on X, #6459): its Advanced fold in claudemagpie.js, imported when it first shows, and what is left is the import and the fold's place in the Separate app line, 216 bytes packed to the shortest form, less the 36 of room there was; +81 for the Use Claude Magpie button on Claude Desktop's row (xMopf7RF on X), drawn by claudemagpie.js too, what is left the one line that places it (#2710); +225 for the Hermes row's Other profiles lines (Norethcy on X), which 1d60b165c took out while each profile had a row and c96f33d65 left with no place at all, packed to the shortest form; the dead hermes# Default note went with it, and the Agents rows draw it, so there is no page to move it to; +397 for a key's own price rate (tnt12231 on X): its lines, check and placeholder in keyrates.js, imported when a provider with two or more keys opens, and what is left is the import, the draft's copy, Advanced opening for it, the save's one line and proxyLines drawing another kind of line; +316 for an image or video model's chip saying what it makes from its right-click (iceloon on X): the chat chip's Makes… now shared with it, and the media chip's Copy model ID left out, packed to the shortest form; the provider's editor draws it, so there is no page to move it to; +67 for the Claude Code · Claude Magpie row saying it is on magpie through Claude Magpie (xMopf7RF on X), one line in connectLine with the shortest words that say it; the Agents rows draw it, so there is no page to move it to; +12 for AIGoCode's logo in pngIcons (MindfulReturn on X), the list every drawn icon is looked up in; +491 for each cost in the tray panel's and Requests' chart and ranking in its own provider's currency (onkashiko on X): ledProv and the provider passed through, packed to the shortest form; drawLedColumns and drawLedRank are shared by the panel, so there is no page to move it to; +326 for the Qwen AI platform's Token Plan sign-in (imthe99galaxy on X): its field, sign-in and wait in qianwenplan.js, imported when such a provider's editor opens, and what is left is the import and one quotaError line for its two refusals, packed to the shortest form; quotaError reads every card's error, so there is no page to move it to; +72 for Copy all keys (emilochen on X): its row in keyrates.js, imported when a provider with two or more keys opens through keyRateField, now told which of its parts to draw, and what is left is the one line that places it; +83 for the page saying it has gone from view, so what its Sessions and Usage pages keep goes in 30 s and not 7 minutes (P0 memory): folded into the visibilitychange listener every window has, packed to the shortest form, so there is no page to move it to; +270 for Providers' Select, to remove several at once (eiyuuzaki2333 on X): its rows, bar, removal and keys in pvpick.js, imported when Select is first clicked, and what is left is pvSel, the button's click and two lines in renderProviders, which draws the list, so there is no page to move it to; +81 for each account of a provider's Usage card in a card of its own (normalcoder_ on X): one line that makes the box, its brief look left to CSS, and renderQuotas, which draws every card, so there is no page to move it to; +17 for Kimi Code's booster balance under an allowance card's rings in the tray panel (apple_test_src on X): the card's text line and the wallet line share one filter, packed to the shortest form; panelQuotaCard draws every card, so there is no page to move it to; +51 for what a failed plugin install left in plugins/, listed under Installed with a Remove (CHENGJIAHEGOXIS on X): its section in plugininstalled.js as pmLeftovers, imported when Plugins first draws, and what is left is the one call after drawInstalled; draw is what draws the page, so there is no page to move it to; +123 for a sidebar list folded from its page's row (hkwok06 on X): the chevron, its click and the fold kept per page in navicons.js, imported with the first list, and what is left is the folded list read beside the hidden pages' (navList, which navMine now shares) and the two rows' clicks asking navFold first; navSubs draws every list, so there is no page to move it to; +338 for the Daily update channel (fishmagic80 on X): its segment, its line under Update channel and the version row's two Up to date on Daily words, packed to the shortest form (one t() per choice); Settings › About and renderUpdate draw them on every window, so there is no page to move them to; +35 for Baidu Qianfan's Token Plan sign-in (yuushabu_buyinn on X, #5860): its field in qianfanplan.js, imported when such a provider's editor opens, drawn by renderStepPlan now told whose sign-in it brings, and what is left is the import and two quotaError lines, past the room there was; quotaError reads every card's error, so there is no page to move it to; +27 for Windows' title bar (258a14 on X): the caption buttons, their clicks, the bar's double click and what keeps them over a dialog in wincap.js, imported in Windows' window alone, the header's room for them in app.css, and what is left is the one line that imports it, past the 29 of room there was; that window's frame is drawn on every start, so there is no page to move it to; +107 for the pages in the reader's own order (chet030714 on X): the order, the sidebar and tab bar put in it, and the menu's drag and keys in navorder.js and navpages.js, imported once an order is kept or Settings draws, and what is left is the one line in navHides that imports it; navHides runs on every start, so there is no page to move it to; +275 for the grants Alibaba's Token Plan asks of a RAM user's AccessKey in the reader's language (MetalHqa on X): one string (ALI_RAM) shown under the editor's AccessKey ID and on the card that names them, less the 48 of the wrong "a RAM user that may use Model Studio is enough" it replaces; the editor and quotaError draw them on every window, so there is no page to move them to; +135 for a model test its vendor queued shown queued and not green (sufeng1894 on X): queuedSaid, one string shared by the chip's title, Test models' and Test this model's status, and the chip's amber dot; renderModels draws the provider editor's chips, so there is no page to move it to; +66 for AstrLink Guard's row saying an x64 magpie runs it under Windows on Arm's emulation until the next update installs the Arm build (EV_John_Liu on X), the Rosetta line's sibling, one line in pmSub; the Privacy rows draw it, so there is no page to move it to; +189 for Let magpie set it on a Codex card locked by config.toml's own compact limit or background threshold (sufeng1894 on X), and Undo for a background share taken over: the shared send posts it, packed to the shortest form; adviceRow draws every card, so there is no page to move it to; +864 for Use on a Claude setup-token account, which switches Claude Code itself to it in its settings.json, and Use back on its signed-in account (liukaybee on X): one swUse helper shared by both buttons, packed to the shortest form; renderAccounts draws every account row, so there is no page to move it to; +1 for the classifier timeout's unset default, 15 and not 8 (ESern29751 on X): its second digit in the Settings row's fallback, which renderReplies draws, so there is no page to move it to; +457 for Kimi Code's subagent pool and its effort (XiaoLing_Arisa on X): the Subagents line and its pool menu in kimisub.js, imported before a Kimi Code row's Details first slides open so it measures the line, and what is left is that import, the line's place, the three fields kept out of the row's squares and the picker's note that Kimi's subagents run on the lead's model, packed to the shortest form; renderAgents draws every row, so there is no page to move it to ) // codeBytes is how many bytes of b are code: its blank lines, its lines diff --git a/internal/gui/tests/kimi-subagent-pool.test.cjs b/internal/gui/tests/kimi-subagent-pool.test.cjs new file mode 100644 index 000000000..e2e5531b3 --- /dev/null +++ b/internal/gui/tests/kimi-subagent-pool.test.cjs @@ -0,0 +1,142 @@ +// Run with Node's test runner and Playwright on the module path; see README.md. +// Kimi Code's subagent pool (XiaoLing_Arisa on X): Kimi Code's own +// [secondary_model] is the model a subagent starts on, the other models its +// lead may start one on, and their effort. In the window they are one +// Subagents line of the opened row, not squares of their own: the model, +// its effort (off until a model is set), and the pool, ticked in one menu +// that stays open. Every language, Chromium and WebKit, wide and narrow. +// No backend: the API is faked here. +const assert = require("node:assert/strict"); +const fs = require("node:fs/promises"); +const path = require("node:path"); +const { test } = require("node:test"); +const { chromium, webkit } = require("playwright"); + +const assets = path.resolve(__dirname, "../assets"); +const models = [ + { value: "magpie/think/deep", label: "Deep", ref: "think/deep" }, + { value: "magpie/think/wide", label: "Wide", ref: "think/wide" }, +]; +const kimi = () => ({ + id: "kimi", name: "Kimi Code", icon: "kimi", path: "/home/u/.kimi-code/config.toml", wired: true, + fields: [ + { key: "model", label: "model", value: "magpie/think/deep", options: models }, + { key: "effort", label: "thinking", value: "", options: [{ value: "" }, { value: "off" }, { value: "high" }] }, + { key: "subagent_model", label: "subagent model", value: "", options: [{ value: "" }, ...models] }, + { key: "subagent_pool", label: "subagent pool", value: "", options: models }, + { key: "subagent_effort", label: "subagent effort", value: "", options: [{ value: "" }, { value: "off" }, { value: "high" }] }, + ], +}); + +function server(lang, sets) { + let cur = { agents: [kimi()], profiles: [] }; + return async (route) => { + const req = route.request(), url = new URL(req.url()); + if (url.pathname === "/boot.js") return route.fulfill({ contentType: "text/javascript", body: `window.bootPrefs = {lang:"${lang}",theme:"light",web:true};` }); + if (url.pathname === "/wails/runtime.js") return route.fulfill({ contentType: "text/javascript", body: "export const Window = {};" }); + if (url.pathname === "/api/state") return route.fulfill({ json: { ...cur, settings: { lang, theme: "light", guideHidden: true } } }); + if (url.pathname === "/api/set") { + const body = req.postDataJSON(); + sets.push(body); + cur = JSON.parse(JSON.stringify(cur)); + const fields = cur.agents[0].fields, f = (k) => fields.find((x) => x.key === k); + f(body.field).value = body.value; + // as kimi_secondary.go: the subagent model joins the pool, and the + // pool's first is the subagent model when there was none + if (body.field === "subagent_model" && body.value && f("subagent_pool").value && !f("subagent_pool").value.split("\n").includes(body.value)) f("subagent_pool").value += "\n" + body.value; + if (body.field === "subagent_pool" && body.value && !f("subagent_model").value) f("subagent_model").value = body.value.split("\n")[0]; + return route.fulfill({ json: { ...cur, settings: { lang, theme: "light", guideHidden: true } } }); + } + if (url.pathname === "/api/usage/quotas") return route.fulfill({ json: [] }); + if (url.pathname === "/api/groups") return route.fulfill({ json: { groups: [] } }); + if (url.pathname === "/api/agents/cli") return route.fulfill({ json: { agents: {}, pending: false } }); + if (url.pathname === "/api/providers") return route.fulfill({ json: { providers: [], gateway: { running: true } } }); + if (url.pathname === "/api/plugins") return route.fulfill({ json: { plugins: [] } }); + if (url.pathname.startsWith("/api/")) return route.fulfill({ json: {} }); + const file = path.join(assets, url.pathname === "/" ? "index.html" : url.pathname); + const contentType = { ".html": "text/html", ".js": "text/javascript", ".css": "text/css", ".svg": "image/svg+xml", ".png": "image/png" }[path.extname(file)]; + await route.fulfill({ body: await fs.readFile(file), contentType }); + }; +} + +// the words as i18n.js has them +const W = { + en: { subagents: "Subagents", more: "More models" }, + zh: { subagents: "子代理", more: "更多模型" }, + "zh-TW": { subagents: "子代理", more: "更多模型" }, + ja: { subagents: "サブエージェント", more: "ほかのモデル" }, + de: { subagents: "Subagenten", more: "Weitere Modelle" }, +}; + +const row = '.row.agent[data-id="kimi"]'; +const panel = `${row} .ag-exp`; + +for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) { + for (const lang of Object.keys(W)) { + for (const width of [1100, 560]) { + test(`${engine} ${lang} ${width}px: Kimi Code's subagent pool`, async (t) => { + const w = W[lang]; + const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" })); + const page = await browser.newPage({ viewport: { width, height: 800 } }); + page.setDefaultTimeout(5000); + page.setDefaultNavigationTimeout(60000); + const errors = [], sets = []; + page.on("pageerror", (e) => errors.push(e.message)); + await page.route("**/*", server(lang, sets)); + t.after(() => browser.close()); + await page.goto("http://magpie.test/"); + await page.locator(row).waitFor(); + // closed, the row has no square for the pool + assert.equal(await page.locator(`${row} [data-key="subagent_pool"]`).count(), 0); + // the sheet is measured as it first appears: the line (kimisub.js) + // is in it then, not a task later + await page.evaluate((sel) => new MutationObserver((_, o) => { + const p = document.querySelector(sel); + if (p) { window.poolAtFirst = !!p.querySelector(".ag-pool"); o.disconnect(); } + }).observe(document.body, { childList: true, subtree: true }), panel); + await page.locator(`${row} .ag-link`).click(); + await page.locator(panel).waitFor(); + assert.equal(await page.evaluate(() => window.poolAtFirst), true, "the Subagents line is there when Details first draws"); + + // one Subagents line, in the panel only + const line = page.locator(`${panel} .ag-kv`, { has: page.locator(".ag-k", { hasText: w.subagents }) }); + assert.equal(await line.count(), 1); + for (const k of ["subagent_model", "subagent_effort", "subagent_pool"]) { + assert.equal(await page.locator(`${row} [data-key="${k}"]`).count(), 1, k); + assert.equal(await line.locator(`[data-key="${k}"]`).count(), 1, k); + } + const eff = line.locator('[data-key="subagent_effort"]'); + assert.ok(await eff.isDisabled(), "an effort without a subagent model"); + const pool = line.locator(".ag-pool"); + assert.equal(await pool.locator(".v").textContent(), w.more); + assert.ok(await page.evaluate(() => document.documentElement.scrollWidth <= innerWidth), "the Agents view overflows"); + + // the pool: two ticks in one menu, which stays open + const y = await page.evaluate(() => scrollY); + await pool.click(); + await page.locator("#pop:not([hidden]) #list li").first().waitFor(); + assert.equal(await page.evaluate(() => scrollY), y, "the click scrolled the page"); + await page.locator("#pop #list li", { hasText: "Wide" }).first().click(); + await page.waitForFunction(() => document.querySelector('.row.agent[data-id="kimi"] .ag-exp [data-key="subagent_model"] .v')?.textContent === "Wide"); + assert.ok(!(await page.locator("#pop").isHidden()), "the menu closed after one tick"); + await page.locator("#pop #list li", { hasText: "Deep" }).first().click(); + await page.waitForFunction(() => document.querySelector('.row.agent[data-id="kimi"] .ag-pool .v')?.textContent === "Deep"); + assert.deepEqual(sets, [ + { agent: "kimi", field: "subagent_pool", value: "magpie/think/wide" }, + { agent: "kimi", field: "subagent_pool", value: "magpie/think/wide\nmagpie/think/deep" }, + ]); + // the subagent model's own tick can't be taken out of the pool + await page.locator("#pop #list li", { hasText: "Wide" }).first().click(); + assert.equal(sets.length, 2); + assert.equal(await page.locator("#pop #list li.cur").count(), 2); + await page.keyboard.press("Escape"); + await page.locator("#pop").waitFor({ state: "hidden" }); + + // with a subagent model, its effort can be picked + assert.ok(!(await page.locator(`${panel} [data-key="subagent_effort"]`).isDisabled())); + assert.ok(await page.evaluate(() => document.documentElement.scrollWidth <= innerWidth), "the Agents view overflows"); + assert.deepEqual(errors, []); + }); + } + } +} diff --git a/internal/gui/tests/old-webkit.test.cjs b/internal/gui/tests/old-webkit.test.cjs index ab246d4ba..c1e3881db 100644 --- a/internal/gui/tests/old-webkit.test.cjs +++ b/internal/gui/tests/old-webkit.test.cjs @@ -180,13 +180,14 @@ test("compat.js is the first of the page's own scripts", async () => { // plugingrid.js and plugininstalled.js when Plugins first draws; // rotfig.js when a routing's In turn is first shown; // ompadvisor.js when an omp's settings first show; + // kimisub.js when a Kimi Code row's Subagents line first shows; // claudemagpie.js when Claude Desktop's twin button or Advanced fold first shows; // keyrates.js when a provider with two or more keys opens; // appearance.js when Settings draws General or the look changes; // navorder.js once a page order is kept, or Settings › Sidebar pages draws; // the checks above // still read them - for (const f of await scripts()) if (!["webfonts.js", "cfgblocked.js", "signsheets.js", "ruleedit.js", "ratewindows.js", "traywindows.js", "autoresetown.js", "registry.js", "navlamp.js", "whatsnew.js", "claudemode.js", "ctxtext.js", "resetask.js", "quotaall.js", "quotatable.js", "quitask.js", "checkinnow.js", "proxies.js", "autobackup.js", "scrollends.js", "profilerename.js", "settingshints.js", "keyspend.js", "syncfiles.js", "agentcompact.js", "agentwindow.js", "balfound.js", "passerrors.js", "tlscerts.js", "keybalance.js", "modellimits.js", "notices.js", "videogen.js", "provlinks.js", "setfeats.js", "pageshare.js", "panelfirst.js", "panelarrange.js", "modelfind.js", "agentsmanager.js", "agentsuffix.js", "phonetabs.js", "pluginmd.js", "bark.js", "acctexport.js", "plugincounts.js", "navicons.js", "autoswitchtip.js", "codexprojects.js", "pipecheck.js", "addfloat.js", "plugingrid.js", "plugininstalled.js", "rotfig.js", "ompadvisor.js", "claudemagpie.js", "keyrates.js", "qianwenplan.js", "qianfanplan.js", "agymove.js", "updatetrust.js", "currencyprefs.js", "appearance.js", "mirroredit.js", "navorder.js", "instancename.js"].includes(f)) assert(all.includes(f), f + " is not loaded by index.html"); + for (const f of await scripts()) if (!["webfonts.js", "cfgblocked.js", "signsheets.js", "ruleedit.js", "ratewindows.js", "traywindows.js", "autoresetown.js", "registry.js", "navlamp.js", "whatsnew.js", "claudemode.js", "ctxtext.js", "resetask.js", "quotaall.js", "quotatable.js", "quitask.js", "checkinnow.js", "proxies.js", "autobackup.js", "scrollends.js", "profilerename.js", "settingshints.js", "keyspend.js", "syncfiles.js", "agentcompact.js", "agentwindow.js", "balfound.js", "passerrors.js", "tlscerts.js", "keybalance.js", "modellimits.js", "notices.js", "videogen.js", "provlinks.js", "setfeats.js", "pageshare.js", "panelfirst.js", "panelarrange.js", "modelfind.js", "agentsmanager.js", "agentsuffix.js", "phonetabs.js", "pluginmd.js", "bark.js", "acctexport.js", "plugincounts.js", "navicons.js", "autoswitchtip.js", "codexprojects.js", "pipecheck.js", "addfloat.js", "plugingrid.js", "plugininstalled.js", "rotfig.js", "ompadvisor.js", "kimisub.js", "claudemagpie.js", "keyrates.js", "qianwenplan.js", "qianfanplan.js", "agymove.js", "updatetrust.js", "currencyprefs.js", "appearance.js", "mirroredit.js", "navorder.js", "instancename.js"].includes(f)) assert(all.includes(f), f + " is not loaded by index.html"); }); test("the styles hold up in Safari 15.0", async () => {