From fa5e86cf2b144fb870c69805050e5b2cebe81789 Mon Sep 17 00:00:00 2001 From: yetone Date: Sat, 31 Oct 2026 03:45:07 +0800 Subject: [PATCH] agents: Kimi Code and Kimi Code Desktop requests show their own name and icon, not the raw id and the cube (jiabubu) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit jiabubu on Discord (magpie 0.1.2245, Windows, Kimi Code 2.4.1, Kimi Code Desktop 1.2.1.0): the Routing page's request list drew Kimi Code's requests as the grey cube and "kimi-code-cli", and Kimi Code Desktop's as the cube and "kimi-code-desktop". The request list, Usage and Sessions already take a client's name and icon from one table, /api/state's clients (agent.Clients). The drift was in usage.AgentOf: Kimi Code 2.x sends "kimi-code-cli/…", which matched neither the kimi agent's "kimicli" prefix nor its "kimi-code" alias, and Kimi Code Desktop ("kimi-code-desktop/…", its bundle's clientName) had no entry at all, so both kept their raw product names. - kimi's UA list takes kimi-code-cli. - Kimi Code Desktop is a client of its own (agents.go's others). It runs Kimi Code's engine on ~/.kimi-code, so it is set up through Kimi Code's row. Its icon is the app's own: the 128px entry of build/icon.ico in KimiCode-1.2.1-win-x64.exe, the installer winget's MoonshotAI.KimiCodeDesktop 1.2.1 points to on code.kimi.com (sha256 75111cb6…c312, as the manifest says). Nothing was drawn by hand. - app.js's pngIcons names it (comment shortened, app.js 5 bytes smaller, budget untouched); app.css's tile rule names it, as icon-tile measures it solid to its edges. - Old records re-resolve through AgentOf, so earlier kimi-code-cli requests read as Kimi Code too. Guard: TestEveryClientHasNameAndIcon checks that every client has a name and an icon file app.js's icon() really loads (a PNG only if pngIcons names it), and that the ids the gateway records by more than a User-Agent (claude-desktop, claude-science, cursor-local, codex, magpie) and kimi / kimi-code-desktop are all clients. The cube is allowed only for the six clients with no logo yet (ante, pencil, openpencil, newmax, kirocrew, raft), filed as #4487. routing-client-icons.test.cjs draws the request list from a history fixture and checks names, data-icon, and that the desktop PNG loads. Run (mote unless said): - Red on the old code: TestAgentOf (got "kimi-code-cli" want "kimi"), TestEveryClientHasNameAndIcon (kimi-code-desktop not among the clients); routing-client-icons in Chromium on the old app.js (0/2, the desktop row is the cube). - Broken by hand: pngIcons without the entry makes the guard fail ("a PNG app.js's pngIcons doesn't name, so it is drawn as the cube"). - go test ./internal/agent ./internal/usage ./internal/usageapi: ok. ./internal/gui: ok except the ten real-window AppKit tests killed at their deadline on mote (#4125, #2645). ok with those skipped, after the rebase. - go vet (darwin), GOOS=linux -tags nogui and GOOS=windows vet of internal/agent and internal/gui: ok. gofmt -l: nothing. - routing-client-icons: Chromium 2/2 on mote, WebKit 2/2 on Linux (wsl-run; WebKit launch hangs on mote, #4125). - routing-*, i18n-keys, icon-tile, mono-icon-redraw and models-add-and-icons in Chromium on mote and WebKit on Linux: i18n-keys green. icon-tile caught the missing tile entry (fixed here). The other Routing reds are still being compared against a fresh origin/main copy in both engines (running at push time). Any that turns out to be ours gets a follow-up commit. Not tried: a real Kimi Code 2.4.1 or Kimi Code Desktop 1.2.1 against magpie (the UA strings come from their bundles: appName kimi-code-cli, clientName kimi-code-desktop). Only the Windows installer's icon was read; the macOS app's wasn't compared. Full Go suite to follow the tag. --- internal/agent/agents.go | 5 + internal/agent/kimi.go | 4 +- internal/agent/useragent_test.go | 5 + internal/gui/assets/app.css | 2 +- internal/gui/assets/app.js | 5 +- .../gui/assets/icons/kimi-code-desktop.png | Bin 0 -> 8357 bytes internal/gui/client_icons_test.go | 77 +++++++++++++ .../gui/tests/routing-client-icons.test.cjs | 102 ++++++++++++++++++ 8 files changed, 195 insertions(+), 5 deletions(-) create mode 100644 internal/gui/assets/icons/kimi-code-desktop.png create mode 100644 internal/gui/client_icons_test.go create mode 100644 internal/gui/tests/routing-client-icons.test.cjs diff --git a/internal/agent/agents.go b/internal/agent/agents.go index 93413d4c9..9aa79e64d 100644 --- a/internal/agent/agents.go +++ b/internal/agent/agents.go @@ -150,6 +150,11 @@ var others = []*Agent{ // ("pi-desktop/0.1.0"), it is told apart from Pi by that name, which // Pi's "pi-" would take otherwise (#1966, dgmico) {ID: "pi-desktop", Name: "PI-Desktop", Icon: "pi", UA: []string{"pi-desktop"}}, + // Kimi Code Desktop runs Kimi Code's engine on ~/.kimi-code, so it + // reaches magpie through Kimi Code's config, under a client name of + // its own ("kimi-code-desktop/…", jiabubu on Discord). Its icon is the + // app's own, from KimiCode-1.2.1-win-x64.exe's build/icon.ico. + {ID: "kimi-code-desktop", Name: "Kimi Code Desktop", Icon: "kimi-code-desktop", UA: []string{"kimi-code-desktop"}}, // Raft (slock's raft-computer) runs Pi in each of its agents' folders; // Sessions lists those as Raft's (internal/sessions/raft.go), while // their requests say "pi (…)" and are Pi's diff --git a/internal/agent/kimi.go b/internal/agent/kimi.go index 3a0028888..43db92b40 100644 --- a/internal/agent/kimi.go +++ b/internal/agent/kimi.go @@ -295,7 +295,9 @@ func kimiIn(at place) *Agent { } return atomic(&Agent{ ID: "kimi", Name: "Kimi Code", Icon: "kimi", Aliases: []string{"kimi-code", "kimi-cli"}, Spelled: prefixed, - UA: []string{"kimicli"}, + // kimi-cli (Python) says KimiCLI/…; Kimi Code 2.x, kimi-code-cli/… + // (jiabubu on Discord: its requests showed the raw name) + UA: []string{"kimicli", "kimi-code-cli"}, Bin: "kimi", Dir: dir, Path: path, ListOnly: true, Sync: func() error { diff --git a/internal/agent/useragent_test.go b/internal/agent/useragent_test.go index ae8e1e4a0..dd85ae17a 100644 --- a/internal/agent/useragent_test.go +++ b/internal/agent/useragent_test.go @@ -33,6 +33,11 @@ func TestAgentOf(t *testing.T) { "minimax-code": "minimax-code", // what magpie's entry sends "MiniMaxCode": "minimax-code", // 0.6.8's own (#1605) "": "other", + // Kimi Code 2.x and its desktop app, as jiabubu's requests named + // them; the old Python kimi-cli's KimiCLI/ + "kimi-code-cli/2.4.1": "kimi", + "kimi-code-desktop/1.2.1": "kimi-code-desktop", + "KimiCLI/1.4.0": "kimi", } for ua, want := range cases { if got := usage.AgentOf(ua); got != want { diff --git a/internal/gui/assets/app.css b/internal/gui/assets/app.css index 40eb7948a..4cedc5a2b 100644 --- a/internal/gui/assets/app.css +++ b/internal/gui/assets/app.css @@ -174,7 +174,7 @@ code { font: var(--code-style, normal) var(--code-weight, 400) 11.5px var(--code they read a size bigger than a line logo beside them, so they are drawn at the size Alma's and Cindy's tiles have of their own. icon-tile.test.cjs measures every file in icons/ and keeps this list whole. */ -.ic:is([data-icon="aihubmix-color"], [data-icon="atomcode"], [data-icon="cherryin-color"], [data-icon="codebuddy-color"], [data-icon="codex-color"], [data-icon="crush"], [data-icon="geminicli-color"], [data-icon="hanako"], [data-icon="hunyuan-color"], [data-icon="kilo"], [data-icon="kiro-color"], [data-icon="lody"], [data-icon="mistermorph-color"], [data-icon="mlx-serve"], [data-icon="monica-color"], [data-icon="penguin-color"], [data-icon="phala-color"], [data-icon="pipellm-color"], [data-icon="qoder"], [data-icon="snow"], [data-icon="targon-color"], [data-icon="typesafe"], [data-icon="workbuddy-color"], [data-icon="yuanbao-color"], [data-icon="zcode"], [data-icon="zoo-code"]) > * { width: 82%; height: 82%; } +.ic:is([data-icon="aihubmix-color"], [data-icon="atomcode"], [data-icon="cherryin-color"], [data-icon="codebuddy-color"], [data-icon="codex-color"], [data-icon="crush"], [data-icon="geminicli-color"], [data-icon="hanako"], [data-icon="hunyuan-color"], [data-icon="kilo"], [data-icon="kimi-code-desktop"], [data-icon="kiro-color"], [data-icon="lody"], [data-icon="mistermorph-color"], [data-icon="mlx-serve"], [data-icon="monica-color"], [data-icon="penguin-color"], [data-icon="phala-color"], [data-icon="pipellm-color"], [data-icon="qoder"], [data-icon="snow"], [data-icon="targon-color"], [data-icon="typesafe"], [data-icon="workbuddy-color"], [data-icon="yuanbao-color"], [data-icon="zcode"], [data-icon="zoo-code"]) > * { width: 82%; height: 82%; } .ic.generic { color: var(--muted); } /* maskSpan's shelf: a hidden user of every mask picture loaded, so a logo drawn again paints at once (#1847) */ .mask-shelf { position: fixed; top: 0; left: 0; width: 0; height: 0; overflow: hidden; visibility: hidden; pointer-events: none; } diff --git a/internal/gui/assets/app.js b/internal/gui/assets/app.js index 8916e6b02..e929f1d8d 100644 --- a/internal/gui/assets/app.js +++ b/internal/gui/assets/app.js @@ -327,11 +327,10 @@ function maskSpan(src, failed) { if (failed) load.then((ok) => ok || failed()); return m; } -const pngIcons = new Set(["crush", "zcode", "alma", "hanako", "cindy", "lody", "typesafe", "atomcode", "snow", "mlx-serve", "mothx", "zoo-code"]); +const pngIcons = new Set(["crush", "zcode", "alma", "hanako", "cindy", "lody", "typesafe", "atomcode", "snow", "mlx-serve", "mothx", "zoo-code", "kimi-code-desktop"]); // lazy: a picture in a long list (Plugins' rows) is asked for near the -// screen. Each SVG an draws is a webview document, ~0.6 MB, kept -// while the page is open (#909) +// screen: each SVG an draws is a ~0.6 MB webview document, kept (#909) function icon(name, lazy) { const kept = keptIcons?.get(name || "")?.shift(); if (kept) { kept.removeAttribute("title"); return kept; } diff --git a/internal/gui/assets/icons/kimi-code-desktop.png b/internal/gui/assets/icons/kimi-code-desktop.png new file mode 100644 index 0000000000000000000000000000000000000000..2adae5e018260d13c920eb5fd4ec6258a0c1fc13 GIT binary patch literal 8357 zcmV;WAX?vvP)_R|R&LBsmU2q9`B=A{mAO^SVYv zFaQ!H2s0$f86@YZAkUn6tE(uA3$20*rj<1(P^P=;yzkV#fA{U`>WMw^>-&8_)pS?7 z_nbf8TQ!!Izy_cUfN~U{-%bT^A%GSD`UAKRz*GP$0qg|uGJv-MeBe0FQ2@sr$N3(> z&yM4q0Ps72AOIVH|mzZ4-@C8hnU$7&OR;d%_u&T6cSta)z+ zz?lGg0odR;&SzP4QZyx#TgP!i6#ad1((rI ze?DKc^&_L>vJLu}?qu_CQLaRj#2ibu!+NaGH*hFdn83Tt)1UtU;2r>97&mEW$LM6s zbu-7*C4%EPUji6H3^W!6Zw)-)w{sll9esn2VZxKGV4Lk3>vxHT*D4nT_+swM14!45 zWJ_v$(Go#0ASUHCMu~L^hSoDhc}^~B+(5DwQ8NNcXlyP@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rY-G(*(1piDj0i zKMPk-$#`%iNrIBo1S?`!DMzM13lh}lQ>2~~CtLB4__-XrexAVhi3ghK6S5^qP<)$< zjm9d)#4yjzAVEF;ZAjxn$?Tx`G{;cPL&Pc};QNq(>j$56ujn|TWU;8|n+Jzy-F1G6 z1m7nnV0MsUT$Id97K{qN*@np{78ypgpEsYM0}_-mh|tb)9R0U0Rk0yy5elW*dYskY zXi*rn6Rj^W@I53DmvB0O!A6$g7|i5087Jhw#T!$O`4E=w4e)c8=O>5=Wesa^9)RHh zJ~D1vwwa!rPm&^jb3A~X!M1Ea(qny|fkR^beQvFRQ9V2ZKrb#i0`PgdmrrG~B-)hNMo9Z{427N3)%_3p?uD00000NkvXXu0mjfy@;i% literal 0 HcmV?d00001 diff --git a/internal/gui/client_icons_test.go b/internal/gui/client_icons_test.go new file mode 100644 index 000000000..e88dce829 --- /dev/null +++ b/internal/gui/client_icons_test.go @@ -0,0 +1,77 @@ +package gui + +import ( + "os" + "regexp" + "strings" + "testing" + + "github.com/yetone/magpie/internal/agent" + "github.com/yetone/magpie/internal/gateway" +) + +// genericIcon are the clients magpie has no logo for yet, drawn with the +// generic cube on purpose (#4487). Each leaves this list when its real +// logo, from the app or its vendor, is added. +var genericIcon = map[string]bool{"ante": true, "pencil": true, "openpencil": true, "newmax": true, "kirocrew": true, "raft": true} + +// Every client a request can be recorded as is drawn by its own name and +// icon in the Routing page's request list, Usage and Sessions, which all +// look the request's client up in /api/state's clients (agent.Clients): +// one not there shows its raw id and the cube (jiabubu on Discord: +// kimi-code-cli and kimi-code-desktop). This holds the table to the ids +// the gateway records, and each entry's icon to a file app.js's icon() +// loads: a PNG only when pngIcons names it, else an SVG. +func TestEveryClientHasNameAndIcon(t *testing.T) { + js, err := os.ReadFile("assets/app.js") + if err != nil { + t.Fatal(err) + } + m := regexp.MustCompile(`const pngIcons = new Set\(\[([^\]]*)\]\)`).FindSubmatch(js) + if m == nil { + t.Fatal("app.js's pngIcons isn't found") + } + png := map[string]bool{} + for _, q := range regexp.MustCompile(`"([^"]+)"`).FindAllSubmatch(m[1], -1) { + png[string(q[1])] = true + } + exists := func(f string) bool { _, err := os.Stat("assets/icons/" + f); return err == nil } + + clients := map[string]bool{} + for _, a := range agent.Clients() { + clients[a.ID] = true + if strings.TrimSpace(a.Name) == "" { + t.Errorf("%s has no name", a.ID) + } + switch { + case a.Icon == "generic": + if !genericIcon[a.ID] { + t.Errorf("%s is drawn with the generic cube: give it its real logo", a.ID) + } + case a.Icon == "" || strings.HasPrefix(a.Icon, "file:") || strings.ContainsAny(a.Icon, ":/"): + t.Errorf("%s's icon %q isn't one of magpie's", a.ID, a.Icon) + case png[a.Icon]: + if !exists(a.Icon + ".png") { + t.Errorf("%s's icon: pngIcons names %s, with no icons/%[2]s.png", a.ID, a.Icon) + } + case !exists(a.Icon + ".svg"): + if exists(a.Icon + ".png") { + t.Errorf("%s's icon %s is a PNG app.js's pngIcons doesn't name, so it is drawn as the cube", a.ID, a.Icon) + } else { + t.Errorf("%s's icon %s has no file in icons/", a.ID, a.Icon) + } + } + } + for id := range genericIcon { + if !clients[id] { + t.Errorf("genericIcon names %s, which is no client", id) + } + } + // the ids the gateway gives a request by more than its User-Agent + // (gateway.agentOf), and those it names by one: each is a client + for _, id := range []string{"claude-desktop", gateway.ScienceID, "cursor-local", "codex", "magpie", "kimi", "kimi-code-desktop"} { + if !clients[id] { + t.Errorf("the gateway records requests as %s, which isn't among the clients", id) + } + } +} diff --git a/internal/gui/tests/routing-client-icons.test.cjs b/internal/gui/tests/routing-client-icons.test.cjs new file mode 100644 index 000000000..6d2860a37 --- /dev/null +++ b/internal/gui/tests/routing-client-icons.test.cjs @@ -0,0 +1,102 @@ +// Run with Node's test runner and Playwright on the module path; see README.md. +// The Routing page's request list draws each request's client by its own +// icon and name, from /api/state's clients (agent.Clients): Kimi Code and +// Kimi Code Desktop showed the cube and their raw ids, kimi-code-cli and +// kimi-code-desktop (jiabubu on Discord). Kimi Code Desktop's logo is a +// PNG, which icon() draws only when app.js's pngIcons names it; one it +// doesn't is asked for as an SVG mask and falls back to the cube. +// TestEveryClientHasNameAndIcon holds the Go table to the files. +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 now = new Date(); +const day = [now.getFullYear(), now.getMonth() + 1, now.getDate()].map((n) => String(n).padStart(2, "0")).join("-"); +const at = (i) => new Date(now.getTime() - (i + 1) * 60e3).toISOString(); +// as agent.Clients() gives them +const clients = [ + { id: "kimi", name: "Kimi Code", icon: "kimi" }, + { id: "kimi-code-desktop", name: "Kimi Code Desktop", icon: "kimi-code-desktop" }, + { id: "workbuddy", name: "WorkBuddy", icon: "workbuddy-color" }, +]; +const routes = clients.map((c, i) => ({ + id: 100 + i, seq: 100 + i, time: at(i), agent: c.id, model: "kimi-k3", provider: "kimi-code", + order: [], tries: [], done: true, status: 200, ms: 900, tokens: 100, +})); + +function serve(lang) { + const state = { agents: [{ id: "kimi", name: "Kimi Code", icon: "kimi", path: "/test/config.toml", fields: [] }], clients, profiles: [], settings: { lang, theme: "light" } }; + return async (route) => { + const url = new URL(route.request().url()); + const json = (data) => route.fulfill({ json: data }); + 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 json(state); + if (url.pathname === "/api/gateway/trace") { + if (url.searchParams.get("wait")) await new Promise((r) => setTimeout(r, 20e3)); + return json({ mine: true, now: now.toISOString(), seq: 1, totals: { requests: 0, rerouted: 0, errors: 0 }, routes: [] }); + } + if (url.pathname === "/api/gateway/history") { + const d = url.searchParams.get("day"); + return json({ cut: false, days: [{ day, requests: routes.length }], routes: d ? routes : [] }); + } + if (url.pathname === "/api/groups") return json({ groups: [] }); + if (url.pathname === "/api/providers") return json({ providers: [], gateway: { running: true, window: true } }); + if (url.pathname.startsWith("/api/")) return 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)]; + try { + await route.fulfill({ body: await fs.readFile(file), contentType }); + } catch { + await route.fulfill({ status: 404, body: "" }); + } + }; +} + +for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) { + for (const lang of ["en", "zh"]) { + test(`${engine} ${lang}: a request's client is drawn by its own icon and name`, async (t) => { + const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" })); + const context = await browser.newContext({ viewport: { width: 1100, height: 760 }, reducedMotion: "reduce" }); + const page = await context.newPage(); + page.setDefaultTimeout(5000); + page.setDefaultNavigationTimeout(60000); + const errors = []; + page.on("pageerror", (e) => errors.push(e.message)); + await page.route("**/*", serve(lang)); + t.after(async () => { + if (process.env.ARTIFACT_DIR) { + await fs.mkdir(process.env.ARTIFACT_DIR, { recursive: true }); + await page.screenshot({ path: path.join(process.env.ARTIFACT_DIR, `${engine}-${lang}-client-icons.png`) }); + } + await browser.close(); + }); + await page.goto("http://magpie.test/?view=routing"); + await page.locator(".rt-days .rt-day").nth(1).click(); + await page.locator(".rt-req").nth(clients.length - 1).waitFor(); + // every picture asked for has come, or failed + await page.waitForFunction(() => [...document.querySelectorAll(".rt-req .asked .ic img")].every((i) => i.complete)); + + const rows = await page.locator(".rt-req").evaluateAll((bs) => bs.map((b) => { + const ic = b.querySelector(".asked .ic"), img = ic?.querySelector("img"); + return { title: b.title, icon: ic?.dataset.icon, generic: !!ic?.classList.contains("generic") || ic?.dataset.icon === "generic", src: img?.getAttribute("src") || "", loaded: !!img && img.naturalWidth > 0 }; + })); + for (const c of clients) { + const r = rows.find((x) => x.title.startsWith(c.name + " · ")); + assert(r, `${c.name}: ${JSON.stringify(rows)}`); + assert.equal(r.icon, c.icon, JSON.stringify(r)); + assert(!r.generic, JSON.stringify(r)); + } + // its own logo, the PNG, drawn + const desk = rows.find((x) => x.title.startsWith("Kimi Code Desktop · ")); + assert.equal(desk.src, "icons/kimi-code-desktop.png", JSON.stringify(desk)); + assert(desk.loaded, JSON.stringify(desk)); + // no raw client id stands for a name + assert(!rows.some((x) => /^kimi-code-(cli|desktop) · /.test(x.title)), JSON.stringify(rows)); + assert.deepEqual(errors, []); + }); + } +}