context: the card's head names the agent and the model's lab
The owner asked for the agent's name and the model's icon on the context window card, and picked design A from a mock-up: in the head, right of the title and before the state pill, [agent icon] Claude Code › [lab icon] anthropic/claude-sonnet-5-5 - context.js: the head's model is now a route (.ctx-route): the agent's icon and name (agentIcon, agentLabel, as the Usage page names it), a ›, then the model's lab icon before its id. labIcon picks the lab from the id after its provider prefix (Claude, OpenAI's gpt/o-series/codex, Gemma, Gemini, DeepSeek, Qwen, Kimi, GLM, Grok, MiniMax, Doubao, Mistral, Llama, MiMo, Step, Hunyuan); an id it doesn't know gets no icon, so a wrong logo never stands for a model. - context.css: the name in --fg-2 at 500, the › in --faint, the agent's icon 14px and the lab's 12px; the model id keeps its ellipsis. In a card 420px or narrower the agent's name and the › go and its icon stays; folded and that narrow, the model goes as it did before. - core_budget_test.go: lowered to 1,532,958, the core after this and the text viewer's move to ctxtext.js (the commit before), on origin/main0fe9f97c1. Tests: ctx-route.test.cjs, Chromium and WebKit, en/zh/zh-TW/ja/de: the agent's name and icon, the lab icon for Claude, an OpenRouter-prefixed GPT, DeepSeek and GLM, none for an unknown model, the route still on the folded head's one line, the name gone and the icon kept at 400px, nothing past the head, no page error. Run at this head: - the full GUI suite on mote (6 wide) before the last rebase: 16,938 tests, 283 red in 50 files. Those 50 files again at 2 wide: 292 red, and at origin/main2cca11176: the same files red (model chips, rule ⋯, Settings redraw, fetched editor; #4600), context-map's 420px "two tiles overlap" among them (#3488). - after the rebase on origin/main0fe9f97c1, on mote: go test ./internal/gui: only TestSettingsSaveKeepsWhatItDoesNotSend (#4514) and TestMainWindowCorners (#3949) red, as on main; Budget ok. The ctx*/context* GUI files, old-webkit and i18n-keys: 346 tests, 6 red: context-map 420px (#3488) and i18n-keys "Unmarked" (#4524). - rebased again on origin/main20482d71f(two commits, 21 lines of GUI assets): TestCoreScriptBudget ok there. Broken by hand, each red, then put back: - labIcon returning nothing: 42 of 52 red ("the model's lab icon"); - the narrow rule removed: 12 red ("a narrow card leaves the name out"); - the route hidden when folded: the folded case red in every language. routing-ctx-still.test.cjs is red on Windows 16 of 16 ("used held still", the big figure's width 60.97 to 61.5), the same frames at origin/maina4151142aalone (#4494). Not tried: the real app on Windows (WebView2) and Linux (WebKitGTK).
This commit is contained in:
@@ -25,6 +25,13 @@ i.dot.free { background: var(--k-free); box-shadow: inset 0 0 0 1px color-mix(in
|
||||
.ctx-head { display: flex; align-items: center; gap: 8px; min-width: 0; }
|
||||
.ctx-head .grow, .ctx-foot .grow, .ctx-contents-head .grow, .ctx-agent-head .grow, .ctx-agent-foot .grow, .ctx-sess-head .grow { flex: 1; }
|
||||
.ctx-title { font-size: 13px; font-weight: 600; color: var(--fg); white-space: nowrap; }
|
||||
.ctx-route, .ctx-who, .ctx-what { display: inline-flex; align-items: center; gap: 5px; min-width: 0; }
|
||||
.ctx-route { gap: 6px; font-size: 12px; }
|
||||
.ctx-who { flex: none; color: var(--fg-2); font-weight: 500; white-space: nowrap; }
|
||||
.ctx-who .ic { width: 14px; height: 14px; }
|
||||
.ctx-what .ic { flex: none; width: 12px; height: 12px; }
|
||||
.ctx-sep { flex: none; color: var(--faint); }
|
||||
:where(.ctx-card.max420) :is(.ctx-who-n, .ctx-sep) { display: none; }
|
||||
.ctx-model { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: var(--code-font, var(--code)); font-size: 11px; color: var(--muted); }
|
||||
.ctx-state { display: inline-flex; align-items: center; gap: 5px; flex: none; height: 20px; padding: 0 8px; border-radius: 10px; font-size: 11px; font-weight: 500; background: var(--pill); color: var(--fg-2); }
|
||||
.ctx-state i { width: 6px; height: 6px; border-radius: 50%; background: var(--faint); }
|
||||
@@ -145,7 +152,7 @@ i.dot.free { background: var(--k-free); box-shadow: inset 0 0 0 1px color-mix(in
|
||||
.ctx-card.shut > :not(.ctx-head) { display: none; }
|
||||
/* its head alone, the space under it is the space over it */
|
||||
.ctx-card.shut { padding-bottom: 14px; }
|
||||
:where(.ctx-card.shut.max420) .ctx-model { display: none; }
|
||||
:where(.ctx-card.shut.max420) .ctx-what { display: none; }
|
||||
/* folded, the head is one line of a fixed height whatever a live request
|
||||
puts in it, so nothing under it moves; a thin bar of what fills the
|
||||
window, a part each, takes the room between the figure and the model */
|
||||
|
||||
@@ -45,6 +45,18 @@
|
||||
// "scripts": requests naming only a library (context.go's scriptsAgent)
|
||||
const agentLabel = (id) => (id === "scripts" ? t("Scripts") : agentMeta(id)?.name || id || t("your agent"));
|
||||
const agentIcon = (id) => icon(agentMeta(id)?.icon || "generic");
|
||||
// the lab a model id is from, by its name after the provider's; none when
|
||||
// it isn't known, so a wrong logo never stands for it
|
||||
const LABS = [[/claude/, "claude-color"], [/gpt|^o\d|codex/, "openai"], [/gemma/, "gemma-color"], [/gemini/, "gemini-color"],
|
||||
[/deepseek/, "deepseek-color"], [/qwen|qwq/, "qwen-color"], [/kimi|moonshot/, "kimi"], [/glm/, "zhipu-color"], [/grok/, "grok"],
|
||||
[/minimax|abab/, "minimax-color"], [/doubao|seed/, "doubao-color"], [/stral/, "mistral-color"], [/llama/, "meta-color"],
|
||||
[/mimo/, "xiaomimimo"], [/^step/, "stepfun-color"], [/hunyuan/, "hunyuan-color"]];
|
||||
const labIcon = (model) => {
|
||||
const m = model.toLowerCase().split("/").pop();
|
||||
const hit = LABS.find(([re]) => re.test(m));
|
||||
return hit ? [icon(hit[1])] : [];
|
||||
};
|
||||
|
||||
// what an item of the prompt is called: a file's path or a tool's name
|
||||
// as it is; magpie's own names for the rest in the reader's language
|
||||
const ITEM_NAMES = {
|
||||
@@ -761,7 +773,21 @@
|
||||
head.append(bar);
|
||||
}
|
||||
head.append(el("span", "grow"));
|
||||
if (r.model) head.append(el("code", "ctx-model", r.model));
|
||||
// whose request it is and the model it went to; in a narrow card the
|
||||
// agent's name goes first, its icon stays
|
||||
const route = el("span", "ctx-route");
|
||||
if (r.agent) {
|
||||
const who = el("span", "ctx-who");
|
||||
who.append(agentIcon(r.agent), el("span", "ctx-who-n", agentLabel(r.agent)));
|
||||
route.append(who);
|
||||
}
|
||||
if (r.model) {
|
||||
const what = el("span", "ctx-what");
|
||||
what.append(...labIcon(r.model), el("code", "ctx-model", r.model));
|
||||
if (r.agent) route.append(el("span", "ctx-sep", "›"));
|
||||
route.append(what);
|
||||
}
|
||||
head.append(route);
|
||||
head.append(st);
|
||||
|
||||
// how full, and the cache
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,131 @@
|
||||
// Run with Node's test runner and Playwright on the module path; see README.md.
|
||||
// Routing: the context window card's head says whose request it is and the
|
||||
// model it went to (the owner): the agent's icon and name, then the model's
|
||||
// lab icon before its id. A model from a lab magpie doesn't know gets no
|
||||
// icon, so a wrong logo never stands for it. In a narrow card the agent's
|
||||
// name and the › go first and its icon stays; folded, the route is still in
|
||||
// the head. Nothing in the head runs past the card. Every GUI language,
|
||||
// Chromium and WebKit.
|
||||
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 iso = (ms) => new Date(ms).toISOString();
|
||||
const prompt = {
|
||||
window: 200000, tokens: 52000, counted: true, turns: 3,
|
||||
parts: [
|
||||
{ kind: "system", tokens: 12000, items: [{ name: "prompt", tokens: 12000 }] },
|
||||
{ kind: "tools", tokens: 15000, items: [{ name: "Bash", tokens: 15000 }] },
|
||||
{ kind: "chat", tokens: 25000, items: [{ name: "turn", tag: "turns", n: 3, tokens: 25000 }] },
|
||||
],
|
||||
};
|
||||
function req(agent, model) {
|
||||
const seat = { id: "acc@me", provider: "anthropic", name: "Acme", who: "me@example.com", kind: "account", model, known: true };
|
||||
return {
|
||||
id: 101, seq: 1010, time: iso(Date.now() - 5000), agent, session: "s-1", model, provider: "anthropic",
|
||||
order: [seat], tries: [{ id: seat.id, model, start: iso(Date.now() - 5000), done: true, status: 200, ms: 3000 }],
|
||||
done: true, status: 200, ms: 3000, tokens: 900, usage: [{ in: 52000, out: 900 }], prompt,
|
||||
};
|
||||
}
|
||||
|
||||
function serve(lang, r) {
|
||||
const state = { agents: [{ id: "claude", name: "Claude Code", icon: "claudecode-color", path: "/test/claude", fields: [] }], 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")) return; // no more requests come in
|
||||
return json({ mine: true, now: new Date().toISOString(), seq: r.seq, totals: { requests: 1, rerouted: 0, errors: 0 }, routes: [r] });
|
||||
}
|
||||
if (url.pathname === "/api/gateway/history") return json({ cut: false, days: [], routes: [] });
|
||||
if (url.pathname === "/api/groups") return json({ groups: [], models: [], pools: [] });
|
||||
if (url.pathname === "/api/providers") return json({ providers: [], presets: [], excluded: [], gateway: { running: true, window: true, url: "http://127.0.0.1:3999" } });
|
||||
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)];
|
||||
await route.fulfill({ body: await fs.readFile(file).catch(() => ""), contentType });
|
||||
};
|
||||
}
|
||||
|
||||
// what the head shows: each part's text, whether it is drawn, its icons
|
||||
const look = (page) => page.evaluate(() => {
|
||||
const q = (s) => document.querySelector(".rt-ctx .ctx-head " + s);
|
||||
const shown = (e) => !!e && e.getClientRects().length > 0 && e.getBoundingClientRect().width > 0;
|
||||
const head = q("") || document.querySelector(".rt-ctx .ctx-head"), card = document.querySelector(".rt-ctx .ctx-card");
|
||||
const hr = head.getBoundingClientRect(), cr = card.getBoundingClientRect();
|
||||
const past = [...head.querySelectorAll("*")].filter((e) => shown(e) && getComputedStyle(e).overflow !== "hidden" && e.getBoundingClientRect().right > hr.right + 0.5).map((e) => e.className);
|
||||
return {
|
||||
name: q(".ctx-who-n")?.textContent, nameShown: shown(q(".ctx-who-n")), sepShown: shown(q(".ctx-sep")),
|
||||
agentIcon: q(".ctx-who .ic")?.dataset.icon, agentIconShown: shown(q(".ctx-who .ic")),
|
||||
labIcons: [...head.querySelectorAll(".ctx-what .ic")].map((e) => e.dataset.icon), model: q(".ctx-model")?.textContent, modelShown: shown(q(".ctx-model")),
|
||||
routeShown: shown(q(".ctx-route")), stateShown: shown(q(".ctx-state")),
|
||||
inCard: hr.right <= cr.right + 0.5, past, headH: hr.height,
|
||||
};
|
||||
});
|
||||
|
||||
const cases = [
|
||||
["claude", "anthropic/claude-sonnet-5-5", "claude-color"],
|
||||
["claude", "openrouter/openai/gpt-6.1-sol", "openai"],
|
||||
["claude", "deepseek/deepseek-v4", "deepseek-color"],
|
||||
["claude", "zai/glm-5", "zhipu-color"],
|
||||
["claude", "acme/zz-model-1", null],
|
||||
];
|
||||
const langs = ["en", "zh", "zh-TW", "ja", "de"];
|
||||
|
||||
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
|
||||
test(`${engine}: the context window's head names the agent and the model's lab`, async (t) => {
|
||||
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
|
||||
t.after(() => browser.close());
|
||||
for (const lang of langs) {
|
||||
for (const [agent, model, lab] of cases) {
|
||||
await t.test(`${lang} ${model}`, async () => {
|
||||
const context = await browser.newContext({ viewport: { width: 1100, height: 900 } });
|
||||
t.after(() => context.close());
|
||||
const page = await context.newPage();
|
||||
await page.addInitScript(() => { try { localStorage.setItem("magpie.ctxShut", "0"); } catch {} });
|
||||
page.setDefaultTimeout(5000);
|
||||
page.setDefaultNavigationTimeout(60000);
|
||||
const errors = [];
|
||||
page.on("pageerror", (e) => errors.push(e.message));
|
||||
await page.route("**/*", serve(lang, req(agent, model)));
|
||||
await page.goto("http://magpie.test/?view=routing");
|
||||
await page.locator(".rt-ctx .ctx-head .ctx-route").waitFor();
|
||||
const lab$ = await look(page);
|
||||
assert.equal(lab$.name, "Claude Code");
|
||||
assert.ok(lab$.nameShown && lab$.sepShown, "a wide card names the agent before the ›");
|
||||
assert.equal(lab$.agentIcon, "claudecode-color");
|
||||
assert.deepEqual(lab$.labIcons, lab ? [lab] : [], "the model's lab icon, none when the lab isn't known");
|
||||
assert.equal(lab$.model, model);
|
||||
assert.ok(lab$.modelShown && lab$.stateShown && lab$.inCard, JSON.stringify(lab$));
|
||||
assert.deepEqual(lab$.past, [], "nothing runs past the head");
|
||||
if (model !== cases[0][1]) return;
|
||||
|
||||
// folded: the route is still in the head, on its one line
|
||||
await page.locator(".rt-ctx .ctx-fold").click();
|
||||
await page.locator(".rt-ctx .ctx-card.shut").waitFor();
|
||||
const shut = await look(page);
|
||||
assert.ok(shut.routeShown && shut.nameShown && shut.modelShown && shut.inCard, JSON.stringify(shut));
|
||||
assert.deepEqual(shut.labIcons, [lab]);
|
||||
assert.ok(shut.headH <= 20.5, `folded, the head is one line (${shut.headH})`);
|
||||
await page.locator(".rt-ctx .ctx-fold").click();
|
||||
await page.locator(".rt-ctx .ctx-card:not(.shut)").waitFor();
|
||||
|
||||
// narrow: the agent's name and the › go, its icon stays
|
||||
await page.setViewportSize({ width: 400, height: 900 });
|
||||
await page.locator(".rt-ctx .ctx-card.max420").waitFor();
|
||||
const narrow = await look(page);
|
||||
assert.ok(!narrow.nameShown && !narrow.sepShown, "a narrow card leaves the name out");
|
||||
assert.ok(narrow.agentIconShown && narrow.modelShown && narrow.stateShown && narrow.inCard, JSON.stringify(narrow));
|
||||
assert.deepEqual(narrow.past, [], "nothing runs past a narrow head");
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user