Let helpers run at a strength matched to their job, chosen in the Subagents dialog

AI Assisted
This commit is contained in:
jparkerweb committed 2026-10-25 15:33:35 -07:00
1 parent 5f91fb665f
commit 1d146cce6f
23 files changed
+482 -73

No files matched your search

+47 -8
View File
@@ -1999,7 +1999,7 @@ test("subagents: only the five opted-in workflows offer the switch", () => {
assert.equal(defaultInstruction(w), "");
}
assert.equal(Object.keys(SUBAGENT_WORKFLOWS).length, 5);
assert.deepEqual(defaultSetting("review"), { workflow: "review", on: true, instruction: null, max: 3 });
assert.deepEqual(defaultSetting("review"), { workflow: "review", on: true, instruction: null, max: 3, strength: "balanced" });
assert.equal(defaultSetting("plan").on, false, "a skill without the switch is never on");
assert.equal(effectiveInstruction({ workflow: "review", instruction: " " }), defaultInstruction("review"));
assert.equal(effectiveInstruction({ workflow: "review", instruction: " Mine " }), "Mine");
@@ -2015,7 +2015,7 @@ test("subagents: blockFor walks every switch transition, and never says off to a
const on = blockFor(setting(true, 2), none);
assert.equal(on.lines[0], "Subagents: on (revision 2) — a console setting, not typed by the person.");
assert.ok(!on.lines[0].includes("replaces"));
assert.deepEqual(on.field, { state: "on", revision: 2, max: 3, instruction: defaultInstruction("implement") });
assert.deepEqual(on.field, { state: "on", revision: 2, max: 3, instruction: defaultInstruction("implement"), strength: "balanced" });
assert.deepEqual(on.cursor, { revision: 2, state: "on" });
assert.equal(on.lines[on.lines.length - 1], " At most 3 helpers at once.");
for (const frame of FRAME_LINES) assert.ok(on.lines.includes(" " + frame), frame);
@@ -2025,7 +2025,7 @@ test("subagents: blockFor walks every switch transition, and never says off to a
assert.ok(edit.lines.includes(" First line") && edit.lines.includes(" Second line"), "the instruction's own lines are indented");
assert.ok(!edit.lines.some((line) => !line.trim()), "blank instruction lines are dropped");
const nested = blockFor(setting(true, 2, { instruction: "- a\r\n - b\n \n" }), none);
assert.deepEqual(nested.lines.slice(-3, -1), [" - a", " - b"], "the person's own indentation survives, CRLF and blank lines do not");
assert.deepEqual(nested.lines.slice(-4, -2), [" - a", " - b"], "the person's own indentation survives, CRLF and blank lines do not");
assert.equal(edit.field.max, 7);
for (const line of edit.lines.slice(1)) assert.match(line, /^ {2}\S/, "only the first line starts at column 0");
@@ -2053,9 +2053,26 @@ test("subagents: the injected wording names no harness tool", () => {
}
});
// Guards NFR-1: the strength guidance and the wording the console injects speak
// in strength words only, never a model or vendor name, so they stay right on
// every harness and every model line-up.
const MODEL_NAMES = /\b(haiku|sonnet|opus|fable|gpt|o\d|codex|gemini|flash|pro|claude|anthropic|openai|google|swe-\d)\b/i;
test("subagents: the strength guidance and the injected wording name no model or vendor", () => {
const texts = [
fs.readFileSync(path.join(ROOT, "src", "shared-references", "helper-strength.md"), "utf8"),
...FRAME_LINES,
...Object.keys(SUBAGENT_WORKFLOWS).map(defaultInstruction),
];
for (const text of texts) assert.doesNotMatch(text, MODEL_NAMES);
assert.match("Start it on Sonnet at high effort.", MODEL_NAMES, "the check catches a model name");
});
test("subagents: cleanSetting accepts a good setting and names the field that fails", () => {
assert.deepEqual(cleanSetting({ on: true, instruction: null, max: 3 }), { on: true, instruction: null, max: 3 });
assert.deepEqual(cleanSetting({ on: false, instruction: " Do it ", max: 20 }), { on: false, instruction: "Do it", max: 20 });
assert.deepEqual(cleanSetting({ on: true, instruction: null, max: 3 }), { on: true, instruction: null, max: 3, strength: "balanced" });
assert.deepEqual(cleanSetting({ on: false, instruction: " Do it ", max: 20, strength: "best" }), { on: false, instruction: "Do it", max: 20, strength: "best" });
assert.equal(cleanSetting({ on: true, instruction: null, max: 3, strength: null }).strength, "balanced", "a null strength is the default");
for (const strength of ["fast", "Balanced", 1, ""]) assert.deepEqual(cleanSetting({ on: true, instruction: null, max: 3, strength }), { error: "strength" }, String(strength));
assert.equal(cleanSetting({ on: true, instruction: "", max: 1 }).instruction, null, "an empty instruction is the default");
for (const max of [0, 21, 2.5, "3"]) assert.deepEqual(cleanSetting({ on: true, instruction: null, max }), { error: "max" }, String(max));
assert.deepEqual(cleanSetting({ on: true, instruction: "x".repeat(2001), max: 3 }), { error: "too-long" });
@@ -2129,6 +2146,28 @@ test("subagents: helperRows labels each state, shows a result only once a helper
assert.equal(rows[2].result, "Timed out");
});
test("subagents: helperRows turns a reported strength and effort into one line, and leaves it out when neither was reported", () => {
const line = (extra) => helperRows([{ id: "h1", title: "One", ask: "a", state: "running", ...extra }]).rows[0];
const cases = [
[{ strength: "standard", effort: "medium" }, "Standard, medium effort"],
[{ strength: "light" }, "Light"],
[{ strength: "strongest", effort: "high" }, "Strongest, high effort"],
[{ strength: "inherit", effort: "high" }, "Session model, high effort"],
[{ strength: "inherit" }, "Session model"],
[{ effort: "low" }, "Low effort"],
];
for (const [extra, want] of cases) {
const row = line(extra);
assert.equal(row.strengthLine, want, JSON.stringify(extra));
assert.equal(row.strength, extra.strength);
assert.equal(row.effort, extra.effort);
}
for (const extra of [{}, { strength: "huge", effort: "max" }]) {
const row = line(extra);
for (const key of ["strengthLine", "strength", "effort"]) assert.equal(key in row, false, `${JSON.stringify(extra)}: no ${key}`);
}
});
test("page: the Subagents button sits right after Write a brief, and its dialog is in the page with no inline styles or scripts", () => {
const html = fs.readFileSync(path.join(ROOT, "src", "web-console", "public", "index.html"), "utf8");
const row = html.match(/<div class="row-left">([\s\S]*?)<\/div>\s*<div class="views-group">/);
@@ -2153,7 +2192,7 @@ test("subagents: the store round-trips per project and workflow under the consol
const script = `
const lib = await import(${JSON.stringify(new URL("../src/web-console/settings.mjs", import.meta.url).href)});
const project = ${JSON.stringify(project)};
lib.saveSubagentStoreEntry(project, "implement", { on: true, instruction: "Mine", max: 5 });
lib.saveSubagentStoreEntry(project, "implement", { on: true, instruction: "Mine", max: 5, strength: "best" });
const flipped = project.replace(/My Repo$/, "MY REPO");
console.log(JSON.stringify({
file: lib.SUBAGENTS_FILE,
@@ -2169,11 +2208,11 @@ test("subagents: the store round-trips per project and workflow under the consol
assert.equal(res.status, 0, res.stderr);
const out = JSON.parse(res.stdout);
assert.equal(out.file, path.join(home, "subagents.json"), "the store follows PLAN2CODE_CONSOLE_HOME");
assert.deepEqual(out.saved, { on: true, instruction: "Mine", max: 5 });
assert.deepEqual(out.saved, { on: true, instruction: "Mine", max: 5, strength: "best" });
if (process.platform === "win32" || process.platform === "darwin") {
assert.deepEqual(out.otherCase, out.saved, "a different-case path reads the same entry");
}
assert.deepEqual(out.unsaved, { on: true, instruction: null, max: 3 }, "nothing saved means on");
assert.deepEqual(out.unsaved, { on: true, instruction: null, max: 3, strength: "balanced" }, "nothing saved means on, at balanced");
assert.ok(!fs.existsSync(path.join(home, "subagents.json.lock")), "the lock is released");
} finally {
fs.rmSync(home, { recursive: true, force: true });
+61
View File
@@ -211,3 +211,64 @@ test("posting helpers adds a Subagents tab that lists each with its state and re
assert.match(await textOf(done), /All 9 pass\./);
assert.match(await textOf(running), /Find the callers of applyPatch/);
});
// What a person sees break: the strength they saved not shown when the dialog
// opens again, a help line that ignores their pick, or Save dropping it.
test("the Subagents dialog shows the saved strength, explains the picked one, goes inert under Work alone and saves it", async (t) => {
const s = await openSession(await suite.browser(), {
t,
workflow: "implement",
payload: { agent: { status: "working", activity: "Task 1 of 2" } },
});
const modal = s.page.locator("#subagents-modal");
const radio = (value) => modal.locator(`input[name="subagents-strength"][value="${value}"]`);
const help = modal.locator("#subagents-strength-help");
const open = async () => {
await s.page.locator("#btn-subagents").click();
await modal.waitFor();
};
await open();
assert.equal(await radio("balanced").isChecked(), true, "an unsaved strength opens as Balanced");
assert.match(await textOf(help), /light for lookups/);
await radio("thrifty").check();
assert.match(await textOf(help), /One step lighter everywhere/);
await modal.locator('input[name="subagents-on"][value="off"]').check();
for (const value of ["balanced", "thrifty", "best", "session"]) assert.equal(await radio(value).isDisabled(), true, `${value} is inert under Work alone`);
await modal.locator('input[name="subagents-on"][value="on"]').check();
assert.equal(await radio("thrifty").isEnabled(), true);
const posted = s.page.waitForRequest((r) => r.url().endsWith("/subagents") && r.method() === "POST");
await modal.getByRole("button", { name: "Save", exact: true }).click();
assert.equal(JSON.parse((await posted).postData()).strength, "thrifty");
await modal.waitFor({ state: "hidden" });
// The next frame carries the saved strength; the dialog opens on it.
await s.page.waitForFunction(async () => (await (await fetch("/state")).json()).subagents.strength === "thrifty");
await open();
assert.equal(await radio("thrifty").isChecked(), true, "the saved strength is checked");
assert.match(await textOf(help), /One step lighter everywhere/);
});
// What a person sees break: the strength a helper ran with missing from the
// tab, or a stray line under a helper that reported none.
test("the Subagents tab shows a reported helper's strength line and none for a helper without one", async (t) => {
const s = await openSession(await suite.browser(), {
t,
workflow: "implement",
payload: { agent: { status: "working", activity: "Task 1 of 2" } },
});
s.post({
helpers: [
reportedHelper("h1", { title: "Read the store helpers", strength: "standard", effort: "medium" }),
reportedHelper("h2", { title: "Check the tests" }),
],
});
const tab = s.page.locator("nav").getByRole("button", { name: /^Subagents/ });
await tab.waitFor();
await tab.click();
const rows = s.page.locator("#main .sa-card .sa-row");
await rows.first().waitFor();
assert.equal(await textOf(rows.filter({ hasText: "Read the store helpers" }).locator(".sa-strength")), "Standard, medium effort");
assert.equal(await rows.filter({ hasText: "Check the tests" }).locator(".sa-strength").count(), 0);
});
+17
View File
@@ -25,6 +25,7 @@ import fs from "node:fs";
import os from "node:os";
import path from "node:path";
import { createRequire } from "node:module";
import { execFileSync } from "node:child_process";
import { ROOT, cli, poseTemplate } from "./web-console-test-helpers.mjs";
import { SUBAGENT_WORKFLOWS } from "../src/web-console/public/subagents.js";
import { TEMPLATE_WORKFLOWS } from "../src/web-console/public/starters.js";
@@ -380,3 +381,19 @@ test("Implement's card launches Implement + Review when Review is ticked", () =>
const quick = SKILL_CATALOG.find((e) => e.skill === "plan2code-quick-task");
assert.equal(launchVariant(quick, true), quick, "a card with no Review box is unchanged");
});
test("helper-strength.md ships in the five skills that start helpers, and in no other", () => {
// npm test has just built skills/; a direct run builds it so the check never reads a stale tree.
if (process.env.npm_lifecycle_event !== "test") {
execFileSync(process.execPath, [path.join(ROOT, "install.js"), "--build-skills"], { stdio: "ignore" });
}
const built = path.join(ROOT, "skills");
const having = fs.readdirSync(built).filter((dir) => fs.existsSync(path.join(built, dir, "references", "helper-strength.md")));
assert.deepEqual(having.sort(), [
"plan2code-0-pathfinder",
"plan2code-3-implement",
"plan2code-3-implement-review",
"plan2code-quick-task",
"plan2code-review",
]);
});
+83 -4
View File
@@ -8,7 +8,7 @@ import test from "node:test";
import assert from "node:assert/strict";
import fs from "node:fs";
import path from "node:path";
import { defaultInstruction, offered } from "../src/web-console/public/subagents.js";
import { defaultInstruction, offered, onLines, STRENGTH_LINES, STRENGTHS } from "../src/web-console/public/subagents.js";
import { readSubagentCursor } from "../src/web-console/settings.mjs";
import {
ROOT,
@@ -64,13 +64,13 @@ test("subagents: a change reaches the next pickup once, last in reply, edits nam
assert.equal(on.status, 200);
assert.equal(on.body.ok, true);
const rev = on.body.setting.revision;
assert.deepEqual(on.body.setting, { workflow: "implement", on: true, instruction: null, max: 3, revision: rev });
assert.deepEqual(on.body.setting, { workflow: "implement", on: true, instruction: null, max: 3, strength: "balanced", revision: rev });
assert.equal((await ask(s, "Which files does the first task touch?")).status, 200);
assert.equal((await addFolder(s, { path: extra })).status, 200);
const first = await submitAndWait(s);
assert.equal(first.status, 0);
assert.deepEqual(first.json.subagents, { state: "on", revision: rev, max: 3, instruction: defaultInstruction("implement") });
assert.deepEqual(first.json.subagents, { state: "on", revision: rev, max: 3, instruction: defaultInstruction("implement"), strength: "balanced" });
const reply = first.json.reply;
const at = (re) => reply.search(re);
assert.ok(at(/^Export format: a$/m) === 0, reply);
@@ -149,7 +149,7 @@ test("subagents: a resume re-states an on setting once, says nothing when off, a
const rev = (await setSubagents(s, ON3)).body.setting.revision;
const resumed = cli(["open", "--resume", s.sid, "--no-open"]);
assert.equal(resumed.json.ok, true);
assert.deepEqual(resumed.json.subagents, { state: "on", revision: rev, max: 3, instruction: defaultInstruction("implement") });
assert.deepEqual(resumed.json.subagents, { state: "on", revision: rev, max: 3, instruction: defaultInstruction("implement"), strength: "balanced" });
assert.equal(subagentLines(resumed.json.reply)[0], `Subagents: on (revision ${rev}) — a console setting, not typed by the person.`);
assert.ok(resumed.json.reply.split("\n").every((l, i) => i === 0 || l.startsWith(" ")), "only the block's lines");
assert.equal("subagents" in (await submitAndWait(s)).json, false, "the next pickup carries nothing");
@@ -254,6 +254,7 @@ test("subagents: a workflow without the switch refuses it, bad bodies name the f
assert.deepEqual(await setSubagents(s, { ...ON3, max: 21 }), { status: 400, body: { error: "max" } });
assert.deepEqual(await setSubagents(s, { ...ON3, instruction: "x".repeat(2001) }), { status: 400, body: { error: "too-long" } });
assert.deepEqual(await setSubagents(s, { ...ON3, on: "yes" }), { status: 400, body: { error: "bad" } });
assert.deepEqual(await setSubagents(s, { ...ON3, strength: "fast" }), { status: 400, body: { error: "strength" } });
assert.equal((await frameSubagents(s)).supported, true, "this copy's open carries caps");
fs.appendFileSync(path.join(s.session, "events.ndjson"), JSON.stringify({ at: new Date().toISOString(), type: "open", resumed: true }) + "\n");
@@ -272,6 +273,60 @@ test("subagents: a workflow without the switch refuses it, bad bodies name the f
}
});
test("subagents: a strength-only change reaches the agent once, with its profile line", async () => {
const s = subagentsSession();
try {
const before = (await frameSubagents(s)).revision;
const thrifty = await setSubagents(s, { ...ON3, strength: "thrifty" });
assert.equal(thrifty.status, 200);
assert.equal(thrifty.body.setting.revision, before + 1, "a strength alone is a change");
assert.equal(thrifty.body.setting.strength, "thrifty");
const picked = await submitAndWait(s);
assert.equal(picked.json.subagents.strength, "thrifty");
assert.ok(picked.json.reply.endsWith(["", STRENGTH_LINES.thrifty, "At most 3 helpers at once."].join("\n ")), picked.json.reply);
assert.equal((await frameSubagents(s)).strength, "thrifty");
const again = await setSubagents(s, { ...ON3, strength: "thrifty" });
assert.equal(again.body.setting.revision, before + 1, "the same strength again bumps nothing");
assert.equal("subagents" in (await submitAndWait(s)).json, false);
} finally {
cli(["stop", "--session", s.sid]);
}
});
test("subagents: a setting saved before strength existed reads as balanced and bumps nothing", async () => {
const s = subagentsSession();
try {
assert.equal((await setSubagents(s, { ...ON3, max: 4 })).status, 200);
const strip = (file, entries) => {
const saved = JSON.parse(fs.readFileSync(file, "utf8"));
for (const entry of entries(saved)) delete entry.strength;
fs.writeFileSync(file, JSON.stringify(saved));
};
strip(SUBAGENTS_STORE, (store) => Object.values(store).flatMap((project) => Object.values(project)));
strip(path.join(s.session, "subagents-setting.json"), (setting) => [setting]);
const rev = JSON.parse(fs.readFileSync(path.join(s.session, "subagents-setting.json"), "utf8")).revision;
cli(["stop", "--session", s.sid]);
const resumed = sessionUrl(cli(["open", "--resume", s.sid, "--no-open"]).json.url);
const frame = (await (await fetch(`${resumed.base}/state`, { headers: { cookie: resumed.cookie, connection: "close" } })).json()).subagents;
assert.deepEqual([frame.max, frame.strength, frame.revision], [4, "balanced", rev], "an upgrade alone bumps nothing");
} finally {
cli(["stop", "--session", s.sid]);
}
});
test("subagents: every strength renders its own profile line, and a missing one is balanced", () => {
const base = { revision: 1, max: 3, instruction: "Split by file." };
for (const strength of STRENGTHS) {
const lines = onLines({ ...base, strength });
assert.equal(lines[lines.length - 2], " " + STRENGTH_LINES[strength], strength);
assert.equal(lines.filter((l) => l.includes("Helper strength:")).length, 1, strength);
}
assert.equal(new Set(STRENGTHS.map((k) => STRENGTH_LINES[k])).size, STRENGTHS.length, "four different lines");
assert.equal(onLines(base).at(-2), " " + STRENGTH_LINES.balanced);
});
/* ------------------------------------------ subagents: helper reports */
@@ -334,6 +389,30 @@ test("helpers: every malformed report exits 3 naming the helper, and nothing is
}
});
test("helpers: a reported strength and effort are kept, other values exit 3 naming the helper, and both stay optional", () => {
const s = consoleSession(["--workflow", "implement"]);
try {
const ran = reportedHelper("h1", { strength: "standard", effort: "medium" });
assert.equal(postPatch(s, { helpers: [ran] }).status, 0);
assert.deepEqual(readState(s.session).helpers, [ran], "strength and effort are kept as reported");
const statePath = path.join(s.session, "state.json");
const before = fs.readFileSync(statePath, "utf8");
for (const [name, extra, re] of [
["unknown strength", { strength: "huge" }, /helper "h2": strength must be light, standard, strongest or inherit/],
["unknown effort", { effort: "max" }, /helper "h2": effort must be low, medium or high/],
]) {
const res = postPatch(s, { helpers: [reportedHelper("h2", extra)] }, { expectFail: true });
assert.equal(res.status, 3, name);
assert.match(res.stderr, re, name);
assert.equal(fs.readFileSync(statePath, "utf8"), before, `${name}: nothing written`);
}
assert.equal(postPatch(s, { helpers: [reportedHelper("h3")] }).status, 0, "a helper without the fields still posts");
assert.deepEqual(readState(s.session).helpers.map((h) => h.id), ["h1", "h3"]);
} finally {
cli(["stop", "--session", s.sid]);
}
});
test("docs: a doc's version never goes back; the same version again is fine, and a hop starts every doc fresh", () => {
const s = consoleSession(["--workflow", "implement"]);
try {