Files
magpie/internal/gui/assets/agentwindow.js
T
yetone e18aca1038 agents: an agent's own context window, and a routing group's own Compact at (ul3140773077392, NovaStudiosss on X)
ul3140773077392 on X: dsh compacts earlier than other harnesses at the same
window, so one global size per model fits none. An agent's sheet (Agents,
the agent's Settings line) now holds "Context window": a size for every
model, or model=size pairs (provider/model, group/<id>, provider/*, a bare
model id, *). Empty follows each model's own window. It is applied in
provider.CatalogFor, the choke point every agent's model list goes through,
so dsh's contextWindow, Codex's catalog and Claude Code's window all read
it, and a window set this way makes Codex/Claude compact at that window
(Entry.WindowSet). Stored in settings.AgentContexts, kept by a general
save (settingsapi); POST /api/settings/agent-contexts and
`magpie model window <agent> [model=size...|off]`.

NovaStudiosss on X: Routing, a group's Edit, Advanced already had "Context"
(the window agents are told). It now has "Compact at" beside it
(Group.Compact; compactSet reads it before the members' smallest), also
`magpie group ... compact=`.

GUI: agentwindow.js, loaded on demand through agentcompact.js so app.js
stays inside its budget (TestCoreScriptBudget passes; the "Context window
in {agent}" label reuses the existing "Context window" key). Every agent
with fields now has a sheet; agent-prefs' Pi expectation says so.

Run at the pushed head, on mote: go vet (darwin; linux -tags nogui;
windows) on provider, agent, cli, gui, settings, settingsapi; gofmt clean;
go test provider, cli, settings, settingsapi, gui (TestCoreScriptBudget
and cli's route table fixed here), agent -run Dsh; node --test agent-window
and group-compact (chromium and webkit, en zh zh-TW ja de, 900 and 420px),
agent-compact, agent-prefs, compact-at. Reds seen identically on a
detached origin/main 4e0026661: agent-prefs webkit "in the panel a
Settings line..." (#6139) and old-webkit "compat.js is the first" / "styles
hold up in Safari 15.0" (#5919, #3403).

Broken by hand, each red then restored: withAgentWindows out of CatalogFor
(TestAgentOwnContextWindow, TestDshOwnContextWindow); the group branch in
compactSet (TestGroupOwnCompactAt); the settingsapi keep line
(TestSettingsSaveKeepsWhatItDoesNotSend); the window row in the sheet
(agent-window tests); compact dropped from the group save
(group-compact tests).

Not tried: a real dsh with a real account (its compaction is dsh's own;
the test reads the window magpie hands it), the full GUI suite (queued
behind another run on mote), Windows and Linux runs of the new tests.
2026-11-12 23:01:29 +08:00

32 lines
1.7 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). One line in the agent's sheet, model=size
// pairs or one size for all: the model as the catalog has it
// (provider/model, group/<id>), provider/*, a bare model id or *. Empty is
// each model's own window (settings.AgentContexts). app.js imports this when
// an agent's sheet opens, so it weighs nothing on the core.
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");
who.append(el("div", "name", t("Context window")));
const own = () => ((prefs || {}).agentContexts || {})[kind] || {};
const num = input(contextsText(own()), t("e.g. 128k · or gpt-6=1m, comma separated"));
num.className = "words window-in";
num.spellcheck = false;
num.setAttribute("aria-label", t("Context window"));
const shown = () => { if (document.activeElement !== num) num.value = contextsText(own()); };
num.onchange = () => {
const r = parseContexts(num.value);
if (r.error) return status(t("Context window: {v} is not a length like 128k or 1m", { v: r.error }), "err");
writingPrefs(api("settings/agent-contexts", { agent: kind, contexts: r.map }))
.then((ns) => { prefs = ns; renderSettings(); shown(); status(t("Takes effect when {agent} next starts", { agent: a.name }), "ok"); }).catch(settingsErr);
};
num.onkeydown = (e) => { e.stopPropagation(); if (e.key === "Enter") num.blur(); };
box.append(num);
row.append(who, box);
list.querySelector(".agent-window")?.remove();
list.append(row);
};