Files
magpie/internal/gui/assets/agentwindow.js
T
yetone 046a131304 gui: an agent's Long conversations is one row, and its context window is picked
The owner (11-12): an agent's sheet showed Long conversations twice, every
agent's row above the agent's own, which read as the same setting twice.
Now the sheet shows one row, the agent's own (.own-compact hides
#fullContextRow there). It shows the agent's own value, else every agent's,
and a change posts settings/agent-compact {agent, own: true, full, at}, so
it is that agent's alone. Settings keeps every agent's row for when no agent
holds one. The Context card's note says "Long conversations in {agent}" when
the agent holds its own value (context.js), in en/zh/zh-TW/ja/de.

The agent's context window (agentwindow.js) is picked, never typed as a
syntax: one size for all its models from the app's menu (Each model's own,
128K to 1M, Other size… typed as 300k), and "Set a model apart" adds a
model from the agent's model picker with its own size, a line each, with a
remove button.

Tests rewritten to the one row, keeping what each guarded:
- compact-one-value: Tuned for you and Long conversations are one window,
  now through the agent's own value and its post.
- codex-compact-held: Codex's held values are under the agent's row.
- agent-prefs: what an agent's opened row and its panel sheet show
  (#fullContextRow hidden, .row.agent-compact visible).
- compact-at: a typed size posts settings/agent-compact for Claude Code,
  and never settings/full-context.
- codex-memories-settings "no Codex, no memories row": waits on the
  merged row, lists the visible rows in its message.
- agent-compact, agent-window: the new row and the picker.

Run on mote (macOS, Playwright 1.62.0, chromium + webkit, every language
each file covers, narrow and wide), at f9bc297a5 + this change; origin/main
then rebased (main has since changed app.css and app.js; see below):
- go test -run 'TestCoreScriptBudget|TestAssetBudget' ./internal/gui: ok
- agent-window 20/20, agent-compact 8/8, compact-one-value 12/12,
  codex-compact-held 20/20, agent-prefs 56/56, claude-cache 8/8,
  context-tune 284/284, compact-at 8/8, settings-general 20/20,
  i18n-keys 4/4, i18n-en-no-cjk 4/4
- codex-memories-settings 8 pass / 10 fail; after the no-Codex fix that
  subtest passes 2/2. The other 8 (chromium "picking a model scrolled the
  page 944 !== 1056") fail the same on origin/main dbaf9d68c: #6372.
- agent-details-ready 4 pass / 32 fail, the same on origin/main dbaf9d68c
  ("Details must end without a height jump: 772.98 -> 852.92"): #6373
  (#6369 is the late-settings subtest).

Again at this commit on be8e352a2: the budgets ok, agent-window 20/20,
agent-compact 8/8, compact-one-value 12/12, codex-compact-held 20/20,
agent-prefs 56/56, compact-at 8/8, i18n-keys 4/4.

Broken by hand, each red, then put back:
- .own-compact > #fullContextRow removed and the card note back to the
  shared words: compact-one-value 12/12 red, agent-prefs red (en/zh, 1100
  and 440, panel). codex-compact-held stayed green; it checks the held
  values sit in the agent's row, which still holds them.
- own: true dropped from the agent-compact post: compact-at 4/8 red,
  agent-compact red, compact-one-value red.
- "Set a model apart" not drawn: agent-window red.

Not tried: the real app, and a real Codex or Claude Code session reading
the agent's own compaction size.
2026-11-13 05:07:32 +08:00

140 lines
6.5 KiB
JavaScript

// An agent's own context windows (ul3140773077392 on X: dsh compacts
// earlier than Codex at the same window, so its window wants setting
// apart from every other agent's). Picked, never typed as a syntax (the
// owner, 11-12: "128k, gpt-6=1m" in a field was too much to ask): one size
// for all its models, from a menu, and a model of its own with its size on
// a line each, added from the agent's model picker. "*" is all of them,
// any other key the model as the catalog has it (settings.AgentContexts).
// Nothing set is each model's own window. app.js imports this when an
// agent's sheet opens, so it weighs nothing on the core.
const WINDOW_SIZES = [128e3, 200e3, 256e3, 400e3, 512e3, 1e6];
const windowWord = (n) => contextsText({ "*": n }).toUpperCase();
window.agentWindowFill = function (list, a) {
const kind = kindOf(a).split("#")[0];
const row = el("div", "row pref agent-window");
row.dataset.agent = kind;
const who = el("div", "who"), box = el("div", "window-own");
who.append(el("div", "name", t("Context window")));
row.append(who, box);
const own = () => ({ ...(((prefs || {}).agentContexts || {})[kind] || {}) });
const main = a.fields.find((f) => f.key === "model");
const models = (main?.options || []).filter((o) => o.value && !o.reset && !o.run && !o.custom);
const save = (map) => writingPrefs(api("settings/agent-contexts", { agent: kind, contexts: map }))
.then((ns) => { prefs = ns; renderSettings(); draw(true); status(t("Takes effect when {agent} next starts", { agent: a.name }), "ok"); }).catch(settingsErr);
// a size typed when none of the menu's is it: one length, 300k or 1.5m
const typeIn = (b, cur, done) => {
const num = input(cur ? contextsText({ "*": cur }) : "", "300k");
num.className = "words window-in";
num.spellcheck = false;
num.setAttribute("aria-label", t("Context window"));
let gone = false;
const end = (n) => { if (gone) return; gone = true; n === undefined ? draw(true) : done(n); };
num.onkeydown = (e) => {
e.stopPropagation();
if (e.key === "Escape") end();
else if (e.key === "Enter") num.blur();
};
num.onblur = () => {
const v = num.value.trim();
if (!v) return end();
const r = parseContexts(v);
if (r.error || Object.keys(r.map).some((k) => k !== "*") || !r.map["*"]) {
status(t("Context window: {v} is not a length like 128k or 1m", { v }), "err");
return end();
}
end(r.map["*"]);
};
b.replaceWith(num);
num.focus();
};
// the sizes, from the app's menu (never a native select); "" is each
// model's own, offered for all of them only
const pickSize = (b, cur, none, done) => {
const odd = cur && !WINDOW_SIZES.includes(cur);
const opts = [...(none ? [{ v: "", name: t("Each model's own"), note: "" }] : []),
...WINDOW_SIZES.map((n) => ({ v: String(n), name: windowWord(n), note: "" })),
{ v: "other", name: odd ? windowWord(cur) : t("Other size…"), note: "" }];
openProtoMenu(b, opts, !cur ? "" : odd ? "other" : String(cur), (v) => v === "other" ? typeIn(b, cur, done) : done(v ? +v : 0), "Context window", "sess-menu", "right");
};
const chip = (text, label, cls) => {
const b = el("button", "sess-pick " + cls);
b.type = "button";
b.setAttribute("aria-label", label);
b.setAttribute("aria-haspopup", "menu");
b.setAttribute("aria-expanded", "false");
b.append(el("span", "", text), svg(CHEV, 11, 1.6));
return b;
};
const modelName = (id) => optNamed(models.find((o) => o.value === id), id);
const pickModel = (anchor, ev, cur, done) => openPicker(a, { key: "windowModel", label: "model", value: cur || "", options: models, onPick: (v) => { if (v) done(v); } }, anchor, ev);
let drawn;
const draw = (again) => {
const cur = own();
const key = JSON.stringify(cur);
if (!again && key === drawn) return;
drawn = key;
const lines = [];
// all its models: the one most set
const all = chip(cur["*"] ? windowWord(cur["*"]) : t("Each model's own"), t("Context window"), "window-all");
all.onclick = (e) => {
e.stopPropagation();
if (all.classList.contains("open")) return closeProtoMenu();
pickSize(all, cur["*"] || 0, true, (n) => { const m = own(); if (n) m["*"] = n; else delete m["*"]; save(m); });
};
lines.push(all);
// a model of its own, a line each
for (const id of Object.keys(cur).filter((k) => k !== "*").sort()) {
const line = el("div", "window-model");
line.dataset.model = id;
const o = models.find((x) => x.value === id);
const m = el("button", "sess-pick set window-model-b");
m.type = "button";
m.setAttribute("aria-haspopup", "menu");
m.append(icon(o?.icon || "generic"), el("span", "", modelName(id)));
m.onclick = (ev) => pickModel(m, ev, id, (v) => {
if (v === id) return;
const map = own();
map[v] = map[id];
delete map[id];
save(map);
});
const s = chip(windowWord(cur[id]), `${modelName(id)}: ${t("Context window")}`, "window-size");
s.onclick = (e) => {
e.stopPropagation();
if (s.classList.contains("open")) return closeProtoMenu();
pickSize(s, cur[id], false, (n) => { const map = own(); map[id] = n; save(map); });
};
const rm = el("button", "window-rm");
rm.type = "button";
rm.title = t("Remove");
rm.setAttribute("aria-label", `${t("Remove")}: ${modelName(id)}`);
rm.append(svg(CROSS, 10, 1.8));
rm.onclick = () => { const map = own(); delete map[id]; save(map); };
line.append(m, s, rm);
lines.push(line);
}
// another model of its own: picked, then its size from the same menu
if (models.length) {
const add = el("button", "text window-add", t("Set a model apart"));
add.type = "button";
add.onclick = (ev) => pickModel(add, ev, "", (v) => {
if (own()[v]) return;
// the picker closes first; the size menu opens from the same button
requestAnimationFrame(() => add.isConnected && pickSize(add, 0, false, (n) => { const map = own(); map[v] = n; save(map); }));
});
lines.push(add);
}
box.replaceChildren(...lines);
};
draw();
// drawn again when the settings are read again
const seen = new MutationObserver(() => row.isConnected ? draw() : seen.disconnect());
const segsBox = list.querySelector("#fullContextSegs");
if (segsBox) seen.observe(segsBox, { childList: true });
list.querySelector(".agent-window")?.remove();
list.append(row);
};