routing: a group with no rule says what a rule is for, with an example rule (mr_coffee0083)

mr_coffee0083 on Discord asked how to set up a group where one model
thinks and several others write code: the group editor's rules part
had no word on it and no example to start from.

- plugins/routing/client.js: a group of two models or more, not routed
  by hand, with no rule yet, says under Rules that every turn goes by
  the routing, and how one model thinks while others write code: the
  coding models in a group of their own added first, the thinking model
  after it, routed In order, and a rule sending planning and hard
  problems to the thinking model. "Add an example rule" beside "Add a
  rule" adds that rule, its intent filled in ("planning, design, or a
  hard problem to think through"), for the editor to finish. Neither
  shows once the group has a rule, or for one model, or routed by hand.
- i18n.js: the three strings in zh, zh-TW, ja and de, with each
  language's own word for In order.
- routing.css: the button wraps and reads in the accent colour, as the
  text buttons beside it.

Run (wsl-run, magpie-desktop, Node 22, Playwright 1.62.0):
- routing-rule-example.test.cjs (new): 20 of 20, chromium and webkit,
  en zh zh-TW ja de, at 1100 and 390 wide. The hint and button show,
  nothing is past the editor's side, pressing adds one rule to opus
  with the translated intent, Save posts it with the classifier Jev;
  after a reload a group of one model, or routed by hand, shows
  neither.
- the 16 i18n-*, routing-rule*, routing-rules-*, group-editor-* and
  routing-classifier* files: 190 of 221. The 31 reds are in
  i18n-keys (#5327, #5332), routing-rule-drag, routing-rule-models,
  routing-rule-remove and routing-rules-line (#4585, #5088, #3789,
  #4112, #4560). Those five files run alone, one at a time, at clean
  origin/main 9d143eaca: 24 reds there, 27 here, the same tests with
  different subtests each run.
- at the pushed head, rebased on 5db1b07ed (which changed
  routing/client.js): routing-rule-example 20 of 20; i18n-keys red
  only by #5327, the same as main.

Broken by hand: rTry never shown (hidden = true): the new test 0 of
20, "the example's button shows". Restored after.

Not tried: the real app window; mr_coffee0083's own groups.
This commit is contained in:
yetone
2026-11-05 15:16:13 +08:00
parent 5db1b07ed9
commit 01a260af46
4 changed files with 192 additions and 4 deletions
+19 -4
View File
@@ -7190,8 +7190,12 @@ function routingPage(part) {
rAdd.append(svg(PLUS, 11, 1.8), el("span", "", t("Add a rule")));
const RULES_TIP = "Checked top first when you send a message: the first that matches sends that turn to its model first; the rest stay behind it if it fails. A turn under way is never moved.";
const rTip = infoTip(t(RULES_TIP));
// with no rule yet, an example of the split asked for most (mr_coffee0083:
// one model to think, others to write code), added as a rule to edit
const rTry = el("button", "text rt-try", t("Add an example rule"));
rTry.type = "button";
const rAdds = el("div", "rt-gadds");
rAdds.append(rAdd, rTip);
rAdds.append(rAdd, rTip, rTry);
const rHint2 = el("div", "hint");
// the conditions opened on each rule while the editor is open: one just
// added, or emptied while typing, stays in its place until it is taken
@@ -7307,10 +7311,13 @@ function routingPage(part) {
condsSeen.disconnect();
condsSeen.observe(rlist);
rAdd.hidden = rTip.hidden = d.members.length < 2;
// only what holds the rules back is said in a line: how they work is
// under the ⓘ beside Add a rule
const none = d.members.length > 1 && d.routing !== "manual" && !d.rules.length;
rTry.hidden = !none;
// only what holds the rules back is said in a line, and with no rule
// yet what one is for: how they work is under the ⓘ beside Add a rule
rHint2.textContent = d.members.length < 2 ? t("With two models or more, a rule can send some turns to one of them first.")
: d.routing === "manual" ? t("The rules wait while you pick the model by hand.") : "";
: d.routing === "manual" ? t("The rules wait while you pick the model by hand.")
: none ? t("No rule yet: every turn goes by the routing. For one model to think and others to write code, put the coding models in a group of their own, add it here first and the thinking model after it, route In order, and add a rule sending planning and hard problems to the thinking model.") : "";
rHint2.hidden = !rHint2.textContent;
let focus = null;
d.rules.forEach((r, i) => {
@@ -7679,6 +7686,14 @@ function routingPage(part) {
addCond(r, "intent");
};
rAdd.onclick = addIntentRule;
// the example: turns asking for planning or hard thinking to the last
// member, its words in the box to change
rTry.onclick = () => {
const r = newRule();
r.intent = t("planning, design, or a hard problem to think through");
d.rules.push(r);
addCond(r, "intent");
};
// the classifier, once a rule has an intent or the effort is picked
// per turn: the model asked which intent a turn's message is and how
// hard it is. Jev (a decision provider's model) answers both in one
@@ -339,6 +339,9 @@ magpie.strings({
"Pick a level to offer, or leave them to its models": "请至少选一个档位,或改回成员共有",
"As a turn begins, Jev is asked once which of the intents the message is, and how hard the turn is when it picks the effort. An intent it isn't sure of matches no rule. Its calls show in the usage as magpie’s own.": "每轮开始时问 Jev 一次消息意图;若由它选推理强度,同时问本轮难度。没把握的意图不命中任何规则。其调用在用量中记为 magpie 自身的。",
"It was told turn {prev} reasoned at {level}, which a message that only carries on from it needs too.": "并告知它第 {prev} 轮按 {level} 推理,仅承接上一轮的消息也需同等强度。",
"Add an example rule": "添加示例规则",
"planning, design, or a hard problem to think through": "规划、设计,或需要深入思考的难题",
"No rule yet: every turn goes by the routing. For one model to think and others to write code, put the coding models in a group of their own, add it here first and the thinking model after it, route In order, and add a rule sending planning and hard problems to the thinking model.": "还没有规则:每轮都按路由方式发送。想让一个模型专门思考、几个模型专门写代码:把写代码的模型放进一个单独的路由组,把它作为第一个成员加到这里,思考模型放在它后面,路由选「按顺序」,再添加一条规则,把规划和难题发给思考模型。",
"With two models or more, a rule can send some turns to one of them first.": "组内有两个及以上模型时,可用规则将某些轮次先发给其中一个。",
"Checked top first when you send a message: the first that matches sends that turn to its model first; the rest stay behind it if it fails. A turn under way is never moved.": "发送消息时从上往下检查:第一条命中的规则将本轮先发给其指定的模型,其余成员作为故障转移。进行中的一轮不会换模型。",
"Rule {n} ({when}) sent turn {turn} to {use} as it began; the turn stays with whoever took it then.": "第 {turn} 轮开始时命中规则 {n}({when}),先发给 {use};本轮留在当时接手的模型上。",
@@ -1003,6 +1006,9 @@ magpie.strings({
"Pick a level to offer, or leave them to its models": "請至少選一個檔位,或改回成員共有",
"As a turn begins, Jev is asked once which of the intents the message is, and how hard the turn is when it picks the effort. An intent it isn't sure of matches no rule. Its calls show in the usage as magpie’s own.": "每輪開始時問 Jev 一次訊息意圖;若由它選推理強度,同時問本輪難度。沒把握的意圖不命中任何規則。其呼叫在用量中記為 magpie 自身的。",
"It was told turn {prev} reasoned at {level}, which a message that only carries on from it needs too.": "並告知它第 {prev} 輪按 {level} 推理,僅承接上一輪的訊息也需同等強度。",
"Add an example rule": "新增範例規則",
"planning, design, or a hard problem to think through": "規劃、設計,或需要深入思考的難題",
"No rule yet: every turn goes by the routing. For one model to think and others to write code, put the coding models in a group of their own, add it here first and the thinking model after it, route In order, and add a rule sending planning and hard problems to the thinking model.": "還沒有規則:每輪都依路由方式傳送。想讓一個模型專門思考、幾個模型專門寫程式:把寫程式的模型放進一個單獨的路由群組,把它作為第一個成員加到這裡,思考模型放在它後面,路由選「按順序」,再新增一條規則,把規劃和難題傳給思考模型。",
"With two models or more, a rule can send some turns to one of them first.": "組內有兩個及以上模型時,可用規則將某些輪次先發給其中一個。",
"Checked top first when you send a message: the first that matches sends that turn to its model first; the rest stay behind it if it fails. A turn under way is never moved.": "傳送訊息時從上往下檢查:第一條命中的規則將本輪先發給其指定的模型,其餘成員作為故障轉移。進行中的一輪不會換模型。",
"Rule {n} ({when}) sent turn {turn} to {use} as it began; the turn stays with whoever took it then.": "第 {turn} 輪開始時命中規則 {n}({when}),先發給 {use};本輪留在當時接手的模型上。",
@@ -1665,6 +1671,9 @@ magpie.strings({
"Pick a level to offer, or leave them to its models": "提示するレベルを選ぶか、モデルに任せてください",
"As a turn begins, Jev is asked once which of the intents the message is, and how hard the turn is when it picks the effort. An intent it isn't sure of matches no rule. Its calls show in the usage as magpie’s own.": "ターンの開始時に、メッセージがどのインテントに当たるかと、推論レベルを選ぶ場合はターンの難しさを、Jev に 1 回尋ねます。確信のないインテントはどのルールにも一致しません。その呼び出しは使用量に magpie 自身のものとして表示されます。",
"It was told turn {prev} reasoned at {level}, which a message that only carries on from it needs too.": "ターン {prev} が {level} で推論したことも伝えています。それを続けるだけのメッセージも同じだけ必要です。",
"Add an example rule": "例のルールを追加",
"planning, design, or a hard problem to think through": "計画、設計、またはじっくり考える必要がある難問",
"No rule yet: every turn goes by the routing. For one model to think and others to write code, put the coding models in a group of their own, add it here first and the thinking model after it, route In order, and add a rule sending planning and hard problems to the thinking model.": "まだルールがありません。各ターンはルーティングどおりに送られます。1 つのモデルに考えさせ、ほかのモデルにコードを書かせるには、コーディング用のモデルを別のグループにまとめて最初のメンバーとしてここに追加し、考えるモデルをその後ろに置いて、ルーティングを「順番」にし、計画や難問を考えるモデルへ送るルールを追加します。",
"With two models or more, a rule can send some turns to one of them first.": "2 つ以上のモデルがあれば、ルールで一部のターンをそのうちの 1 つへ優先して送れます。",
"Checked top first when you send a message: the first that matches sends that turn to its model first; the rest stay behind it if it fails. A turn under way is never moved.": "メッセージを送るたびに上から確認します。最初に一致したルールがそのターンを指定モデルへ優先して送り、失敗した場合は残りが後に控えます。進行中のターンが移されることはありません。",
"Rule {n} ({when}) sent turn {turn} to {use} as it began; the turn stays with whoever took it then.": "ルール {n}({when})がターン {turn} の開始時にそれを {use} へ送りました。このターンはそのとき引き受けたモデルのままです。",
@@ -2329,6 +2338,9 @@ magpie.strings({
"Pick a level to offer, or leave them to its models": "Wählen Sie eine anzubietende Stufe oder überlassen Sie sie den Modellen",
"As a turn begins, Jev is asked once which of the intents the message is, and how hard the turn is when it picks the effort. An intent it isn't sure of matches no rule. Its calls show in the usage as magpie’s own.": "Zu Beginn einer Runde wird Jev einmal gefragt, welcher Absicht die Nachricht entspricht und, wenn es den Effort wählt, wie schwer die Runde ist. Eine Absicht, bei der es unsicher ist, trifft auf keine Regel zu. Seine Aufrufe erscheinen in der Nutzung als eigene von magpie.",
"It was told turn {prev} reasoned at {level}, which a message that only carries on from it needs too.": "Ihm wurde mitgeteilt, dass Runde {prev} {level} Reasoning nutzte; eine Nachricht, die nur daran anknüpft, braucht das ebenso.",
"Add an example rule": "Beispielregel hinzufügen",
"planning, design, or a hard problem to think through": "Planung, Entwurf oder ein schwieriges Problem zum Durchdenken",
"No rule yet: every turn goes by the routing. For one model to think and others to write code, put the coding models in a group of their own, add it here first and the thinking model after it, route In order, and add a rule sending planning and hard problems to the thinking model.": "Noch keine Regel: Jede Runde geht nach dem Routing. Für ein Modell zum Denken und andere zum Programmieren: die Programmiermodelle in eine eigene Gruppe legen, diese hier zuerst hinzufügen und das Denkmodell dahinter, „Der Reihe nach“ routen und eine Regel hinzufügen, die Planung und schwierige Probleme an das Denkmodell sendet.",
"With two models or more, a rule can send some turns to one of them first.": "Ab zwei Modellen kann eine Regel bestimmte Runden zuerst an eines davon senden.",
"Checked top first when you send a message: the first that matches sends that turn to its model first; the rest stay behind it if it fails. A turn under way is never moved.": "Beim Senden einer Nachricht von oben geprüft: Die erste zutreffende Regel sendet diese Runde zuerst an ihr Modell; die übrigen folgen dahinter, falls es fehlschlägt. Eine laufende Runde wird nie verschoben.",
"Rule {n} ({when}) sent turn {turn} to {use} as it began; the turn stays with whoever took it then.": "Regel {n} ({when}) sendete Runde {turn} zu Beginn an {use}; die Runde bleibt bei dem, der sie damals übernommen hat.",
@@ -907,6 +907,7 @@ body.window .rt-gedit > .bar { --vfoot: 8px; }
.rt-classifier .hint { flex-basis: 100%; }
/* the effort's classifier offering to pick the model too: a line of its
own, wrapping rather than running past a narrow window */
.rt-gadds .rt-try { white-space: normal; text-align: left; color: var(--accent); }
.rt-classifier .rt-cls-more { margin-left: -7px; white-space: normal; text-align: left; color: var(--accent); }
/* the levels a group names for agents (#295): one toggle each */
.rt-levels { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 6px; margin-top: 6px; }
@@ -0,0 +1,160 @@
// Run with Node's test runner and Playwright on the module path; see README.md.
// A routing group with two models and no rule says what a rule is for,
// with the split asked for (mr_coffee0083 on Discord: "一个专门思考的模型
// 几个专门写代码的模型", and nothing in the editor to go by): a line under
// Rules and an Add an example rule that adds a rule sending planning and
// hard problems to the last model, its words in the reader's language in
// its box, Jev picked to tell them. Once a rule is there, neither shows; a
// group of one model, or one routed by hand, never shows them. In every
// language, Chromium and WebKit, at a wide and a phone's width, nothing
// past the editor's side. Run with ASSETS set to the assets before this
// change to see it fail.
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(process.env.ASSETS || path.join(__dirname, "../assets"));
const models = [
{ id: "a/opus", name: "opus", providerName: "A", icon: "generic", context: 1000000, ready: true },
{ id: "b/flash", name: "flash", providerName: "B", icon: "generic", context: 1000000, ready: true },
];
const member = (id) => ({ id, ready: true, context: 1000000, images: true });
const rule = (use, more) => ({ use, pause: false, tokens: 0, images: false, effort: "", agents: [], intent: "", compact: false, folders: [], exceptFolders: [], time: null, ...more });
let shape = {};
const groups = () => ({
models,
deciders: [{ id: "typesafe/jev-latest", name: "Jev", providerName: "TypeSafe", icon: "generic" }],
groups: [{ id: "main", name: "Main", members: ["b/flash", "a/opus"], routing: "", ready: true, classifier: "",
rules: [], memberInfo: [member("b/flash"), member("a/opus")], ...shape }],
pools: [],
});
const words = {
en: { edit: "Edit", save: "Save", hint: "No rule yet", intent: "planning, design, or a hard problem to think through" },
zh: { edit: "编辑", save: "保存", hint: "还没有规则", intent: "规划、设计,或需要深入思考的难题" },
"zh-TW": { edit: "編輯", save: "儲存", hint: "還沒有規則", intent: "規劃、設計,或需要深入思考的難題" },
ja: { edit: "編集", save: "保存", hint: "まだルールがありません", intent: "計画、設計、またはじっくり考える必要がある難問" },
de: { edit: "Bearbeiten", save: "Speichern", hint: "Noch keine Regel", intent: "Planung, Entwurf oder ein schwieriges Problem zum Durchdenken" },
};
function serve(lang, posts) {
const state = { agents: [{ id: "claude", name: "Claude Code", path: "/test/claude", fields: [] }], profiles: [], settings: { lang, theme: "light" } };
return async (r) => {
const url = new URL(r.request().url());
const json = (data) => r.fulfill({ json: data });
if (url.pathname === "/boot.js") return r.fulfill({ contentType: "text/javascript", body: `window.bootPrefs = {lang:"${lang}",theme:"light",web:true};` });
if (url.pathname === "/wails/runtime.js") return r.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 new Promise(() => {}); // nothing more comes
return json({ mine: true, now: new Date().toISOString(), seq: 1, totals: { requests: 0, rerouted: 0, errors: 0 }, routes: [] });
}
if (url.pathname === "/api/gateway/history") return json({ cut: false, days: [], routes: [] });
if (url.pathname === "/api/groups") return json(groups());
if (url.pathname.startsWith("/api/groups/")) {
posts.push({ path: url.pathname, body: JSON.parse(r.request().postData() || "{}") });
return json(groups());
}
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)];
try { await r.fulfill({ body: await fs.readFile(file), contentType }); } catch { await r.fulfill({ status: 404 }); }
};
}
// wheel to a control, as the reader would (the page keeps still for any
// other scroll), and return where it is
async function reach(page, loc) {
const height = page.viewportSize().height;
await page.mouse.move(Math.min(550, (page.viewportSize().width / 2) | 0), 300);
for (let i = 0; i < 30; i++) {
const y = (await loc.boundingBox()).y;
if (y > 80 && y < height - 160) break;
await page.mouse.wheel(0, y < 80 ? -300 : 300);
await page.waitForTimeout(150);
}
return loc.boundingBox();
}
// reached, then clicked with the mouse
async function press(page, loc) {
const b = await reach(page, loc);
await page.mouse.click(b.x + b.width / 2, b.y + b.height / 2);
}
async function openEditor(page, w) {
const group = page.locator(".rt-group").first();
await group.waitFor();
await press(page, group.locator("button", { hasText: w.edit }));
const ed = page.locator(".rt-gedit");
await ed.waitFor();
return ed;
}
async function saved(page, ed, w, posts) {
const n = posts.length;
await press(page, ed.locator("button.primary", { hasText: w.save }));
await page.waitForFunction(() => !document.querySelector(".rt-gedit"));
const save = posts.slice(n).find((p) => p.path === "/api/groups/save");
assert(save, `saved: ${JSON.stringify(posts)}`);
return save.body;
}
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
for (const lang of Object.keys(words)) {
const w = words[lang];
for (const width of [1100, 390]) {
test(`${engine} ${lang} ${width}: a group with no rule offers an example rule`, async (t) => {
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
t.after(() => browser.close());
const page = await (await browser.newContext({ viewport: { width, height: 1400 } })).newPage();
page.setDefaultTimeout(5000);
page.setDefaultNavigationTimeout(60000);
const errors = [], posts = [];
page.on("pageerror", (e) => errors.push(e.message));
await page.route("**/*", serve(lang, posts));
shape = {};
await page.goto("http://magpie.test/?view=routing");
let ed = await openEditor(page, w);
const hint = ed.locator(".hint", { hasText: w.hint });
const tryIt = ed.locator("button.rt-try");
await hint.waitFor();
assert(await tryIt.isVisible(), "the example's button shows");
assert.match(await hint.textContent(), lang === "en" ? /In order/ : /./);
// nothing past the editor's side, nor a sideways scroll
const past = await page.evaluate(() => {
const e = document.querySelector(".rt-gedit").getBoundingClientRect();
return [...document.querySelectorAll(".rt-rules, .rt-rules *, .rt-gedit .hint")].filter((x) => x.offsetParent && x.getBoundingClientRect().right > e.right + 1).map((x) => x.className || x.tagName);
});
assert.deepEqual(past, []);
assert(await page.evaluate(() => document.documentElement.scrollWidth <= document.documentElement.clientWidth), "no sideways scroll");
await press(page, tryIt);
const rows = ed.locator(".rt-rule");
await rows.first().waitFor();
assert.equal(await rows.count(), 1);
assert.equal(await rows.first().locator(".rt-cond.in textarea").inputValue(), w.intent);
assert.match(await rows.first().locator(".rt-model").textContent(), /opus/, "to the last member");
assert(!(await tryIt.isVisible()) && !(await hint.isVisible()), "gone once a rule is there");
const body = await saved(page, ed, w, posts);
assert.deepEqual(body.rules, [rule("a/opus", { useEffort: "", intent: w.intent })]);
assert.equal(body.classifier, "typesafe/jev-latest");
assert.deepEqual(errors, []);
// one model, or routed by hand: no example
for (const s of [{ members: ["a/opus"], memberInfo: [member("a/opus")] }, { routing: "manual" }]) {
shape = s;
await page.reload();
ed = await openEditor(page, w);
await ed.locator(".rt-rules").waitFor({ state: "attached" });
assert(!(await tryIt.isVisible()), `no example: ${JSON.stringify(s)}`);
assert.equal(await hint.count(), 0);
}
});
}
}
}