agents: Kimi Code and Kimi Code Desktop requests show their own name and icon, not the raw id and the cube (jiabubu)
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.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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; }
|
||||
|
||||
@@ -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 <img> draws is a webview document, ~0.6 MB, kept
|
||||
// while the page is open (#909)
|
||||
// screen: each SVG an <img> 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; }
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 8.2 KiB |
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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, []);
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user