Update the web console server, screens, help, prefs and loop setup, with matching page and logic suites

AI Assisted
This commit is contained in:
jparkerweb committed 2026-11-02 12:00:12 -08:00
1 parent 2468027a5a
commit 8e34bf1005
119 files changed
+9957 -3728

No files matched your search

+211 -20
View File
@@ -576,12 +576,13 @@ test("chat lines list documents after images, and chatView carries files on sent
const lines = chatReplyLines([
{
kind: "message",
seq: 7,
text: "Read these",
images: [{ path: "/u/a.jpg", name: "a.png" }],
files: [{ path: "/u/b.md", name: "b.md" }],
},
]);
assert.equal(lines, "Quick question: Read these\n Image: /u/a.jpg (a.png)\n File: /u/b.md (b.md)");
assert.equal(lines, "Quick question (7): Read these\n Image: /u/a.jpg (a.png)\n File: /u/b.md (b.md)");
const view = chatView(
{ conversation: 1, messages: [{ from: "person", kind: "message", seq: 1, text: "Read", files: [{ path: "/u/b.md", name: "b.md" }] }] },
{ pendingSends: [{ tempId: "t", text: "More", files: [{ path: "/u/c.pdf", name: "c.pdf" }] }] }
@@ -1498,22 +1499,22 @@ test("no starter steers the workflow: approve, skip, commit, run, execute, delet
test("validate: templates only as \"idea\", only on a text item", () => {
const item = (extra) => ({ items: [{ id: "idea", kind: "text", title: "What's the idea?", ...extra }] });
const message = 'item "idea" has "templates": only a text item can carry it, and its only value is "idea".';
const message = 'item "idea" templates: only a text item can carry it, and its only value is "idea".';
assert.deepEqual(validate(item({ templates: "idea" })), []);
assert.deepEqual(validate(item({})), []);
assert.ok(validate(item({ kind: "choice", options: [{ k: "A", text: "a" }], templates: "idea" })).includes(message));
assert.ok(validate(item({ templates: "yes" })).includes(message));
assert.ok(validate(item({ kind: "choice", options: [{ k: "A", text: "a" }], templates: "idea" })).some((p) => p.startsWith(message)));
assert.ok(validate(item({ templates: "yes" })).some((p) => p.startsWith(message)));
});
test("validate: fill only as \"note\", only on a text item", () => {
const item = (extra) => ({ items: [{ id: "idea", kind: "text", title: "What's the idea?", ...extra }] });
const message = 'item "idea" has "fill": only a text item can carry it, and its only value is "note".';
const message = 'item "idea" fill: only a text item can carry it, and its only value is "note".';
assert.deepEqual(validate(item({ fill: "note" })), []);
assert.deepEqual(validate(item({ fill: "note", templates: "idea" })), []);
assert.ok(validate(item({ kind: "choice", options: [{ k: "A", text: "a" }], fill: "note" })).includes(message));
assert.ok(validate(item({ kind: "confirm", fill: "note" })).includes(message));
assert.ok(validate(item({ fill: "idea" })).includes(message));
assert.ok(validate(item({ fill: true })).includes(message));
assert.ok(validate(item({ kind: "choice", options: [{ k: "A", text: "a" }], fill: "note" })).some((p) => p.startsWith(message)));
assert.ok(validate(item({ kind: "confirm", fill: "note" })).some((p) => p.startsWith(message)));
assert.ok(validate(item({ fill: "idea" })).some((p) => p.startsWith(message)));
assert.ok(validate(item({ fill: true })).some((p) => p.startsWith(message)));
});
test("attachmentName: slug of the original name, 8 characters of the upload id, the upload's own extension", () => {
@@ -1748,7 +1749,7 @@ test("meter: a build post's headline.cleared reaches the ledger as progress", ()
assert.equal(postPatch(s, { headline: { cleared: 7 }, run: { event: "implement-phase", id: "phase-1", tasks: 7 } }).status, 0);
assert.equal(points(), 3, "the phase's run took over: 7 tasks score 3, not 3 + 3");
} finally {
cli(["stop", "--session", s.sid]);
cli(["stop", "--session", s.sid, "--force"]);
}
});
@@ -2040,26 +2041,25 @@ test("subagents: blockFor walks every switch transition, and never says off to a
assert.equal(blockFor(setting(false, 1), none), null, "never on: nothing");
assert.equal(blockFor(null, none), null, "no setting: nothing");
const line = (word, max) => `Subagents: on, ${word} strength, at most ${max} helpers at once (a console setting, not typed by the person).`;
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.equal(on.lines[0], line("balanced", 3));
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);
for (const frame of FRAME_LINES) assert.ok(!on.lines.some((l) => l.includes(frame)), "the frame sentences live in console-subagents.md, not in the block");
const edit = blockFor(setting(true, 5, { instruction: "First line\n\nSecond line", max: 7 }), { revision: 4, state: "on" });
assert.equal(edit.lines[0], "Subagents: on (revision 5, replaces revision 4) — a console setting, not typed by the person.");
assert.equal(edit.lines[0], line("balanced", 7));
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");
assert.ok(!edit.lines.some((l) => !l.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(-4, -2), [" - a", " - b"], "the person's own indentation survives, CRLF and blank lines do not");
assert.deepEqual(nested.lines.slice(-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");
for (const l of edit.lines.slice(1)) assert.match(l, /^ {2}\S/, "only the first line starts at column 0");
const off = blockFor(setting(false, 6), { revision: 5, state: "on" });
assert.deepEqual(off.lines, [offLine(6)]);
assert.equal(off.lines[0], "Subagents: off (revision 6) — don't start new helpers for the rest of this session.");
assert.equal(off.lines[0], "Subagents: off. Start no new helpers for the rest of this session.");
assert.deepEqual(off.cursor, { revision: 6, state: "off" });
assert.equal(off.field.state, "off");
@@ -2067,7 +2067,7 @@ test("subagents: blockFor walks every switch transition, and never says off to a
assert.equal(blockFor(setting(true, 6), { revision: 6, state: "on" }), null, "same revision while on: nothing");
assert.equal(blockFor(setting(false, 3), { revision: 2, state: "off" }), null, "off after off: nothing");
assert.equal(blockFor(setting(true, 6), none).lines[0], "Subagents: on (revision 6) — a console setting, not typed by the person.", "a reset cursor re-states on");
assert.equal(blockFor(setting(true, 6), none).lines[0], line("balanced", 3), "a reset cursor re-states on");
assert.equal(blockFor(setting(false, 6), none), null, "a reset cursor with it off: nothing");
assert.equal(blockFor({ ...setting(true, 9), workflow: "document" }, none), null, "a workflow that does not offer it: nothing");
});
@@ -2378,3 +2378,194 @@ test("Notebook pick rules: an empty tab, the first five pictures ticked, and no
assert.deepEqual(toggleNoteTick(four, "f"), ["a", "b", "d", "e", "f"], "untick one to tick another");
assert.equal(NOTE_LONG_BYTES, 51200);
});
/* ------------------------------------- the wire: defaults, patch reading, errors */
import { applyPatch, blankState } from "../src/web-console/patches.mjs";
import { readPatch } from "../src/web-console/cmd-post-wait.mjs";
import { openSession } from "./web-console-test-helpers.mjs";
const wireState = () => blankState({ sid: "x", project: "p", workflow: "plan" });
const wireItem = (kind, options) => ({ id: "q1", kind, title: "Pick one", body: "Which?", ...(options ? { options } : {}) });
test("defaults: options with no k are lettered A, B, C on choice, multi and menu", () => {
for (const kind of ["choice", "multi", "menu"]) {
const next = applyPatch(wireState(), { items: [wireItem(kind, [{ text: "CSV" }, { text: "Excel" }, { text: "JSON" }])] });
assert.deepEqual(next.items[0].options.map((o) => o.k), ["A", "B", "C"], kind);
assert.deepEqual(validate(next), [], kind);
}
});
test("defaults: options that all carry a k keep it, and a mix is refused naming the item and options", () => {
const next = applyPatch(wireState(), { items: [wireItem("choice", [{ k: "1", text: "CSV" }, { k: "9", text: "Excel" }])] });
assert.deepEqual(next.items[0].options.map((o) => o.k), ["1", "9"]);
assert.throws(
() => applyPatch(wireState(), { items: [wireItem("choice", [{ k: "A", text: "CSV" }, { text: "Excel" }])] }),
(e) => /item "q1" options:/.test(e.message) && /Like this:/.test(e.message)
);
});
test("defaults: a new item gets status, required and allowOther filled, and a given value is kept", () => {
const next = applyPatch(wireState(), { items: [wireItem("choice", [{ text: "CSV" }]), { ...wireItem("text"), id: "q2", required: false, allowOther: false }] });
const [a, b] = next.items;
assert.equal(a.status, "open");
assert.equal(a.required, true);
assert.equal(a.allowOther, true);
assert.deepEqual(a.thread, []);
assert.equal(b.required, false);
assert.equal(b.allowOther, false);
});
test("readPatch: indented, minified, BOM and UTF-16 patches all read the same", () => {
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "p2c-readpatch-"));
try {
const patch = { title: "Café – résumé", items: [{ id: "q1", kind: "text", title: "Name" }] };
const json = JSON.stringify(patch);
const write = (name, buf) => {
const p = path.join(dir, name);
fs.writeFileSync(p, buf);
return p;
};
const le = Buffer.concat([Buffer.from([0xff, 0xfe]), Buffer.from(json, "utf16le")]);
const be = Buffer.concat([Buffer.from([0xfe, 0xff]), Buffer.from(json, "utf16le").swap16()]);
for (const [name, buf] of [
["minified.json", json],
["indented.json", JSON.stringify(patch, null, 4)],
["bom.json", "" + json],
["le.json", le],
["be.json", be],
]) {
assert.deepEqual(readPatch(write(name, buf)), { patch }, name);
}
} finally {
fs.rmSync(dir, { recursive: true, force: true });
}
});
test("readPatch: a cut-off, a trailing comma and a missing brace name the line and column, show the spot and a caret", () => {
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "p2c-readpatch-"));
try {
const read = (text) => {
const p = path.join(dir, "p.json");
fs.writeFileSync(p, text);
return readPatch(p);
};
const cases = {
"a cut-off write": '{"title":"Audit export","items":[{"id":"q1","kind":"te',
"a trailing comma": '{"title":"Audit",\n"items":[],\n}',
"a missing brace": '{"title":"Audit","agent":{"status":"waiting"}',
};
for (const [what, text] of Object.entries(cases)) {
const { error, patch } = read(text);
assert.equal(patch, undefined, what);
const lines = error.split("\n");
assert.match(lines[0], /^line \d+, column \d+: \S/, `${what}: ${error}`);
assert.equal(lines.length, 3, `${what}: the message, the excerpt, the caret`);
assert.match(lines[2], /^ *\^$/, `${what}: a caret under the spot`);
assert.ok(lines[1].length > 0 && lines[1].length <= 61, `${what}: an excerpt around the spot`);
}
const comma = read(cases["a trailing comma"]).error;
assert.match(comma, /^line 3, column 1:/, "the trailing comma is reported on the closing brace's line");
const cut = read(cases["a cut-off write"]).error;
assert.match(cut, /^line 1, column \d+:/);
assert.ok(cut.split("\n")[1].includes('"kind":"te'), "the excerpt shows where the write stopped");
} finally {
fs.rmSync(dir, { recursive: true, force: true });
}
});
test("readPatch: empty input and a JSON array each get their own message", () => {
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "p2c-readpatch-"));
try {
const read = (text) => {
const p = path.join(dir, "p.json");
fs.writeFileSync(p, text);
return readPatch(p).error;
};
const empty = read(" \n");
const array = read("[1,2]");
const nul = read("null");
assert.match(empty, /empty/);
assert.match(array, /one JSON object/);
assert.match(array, /an array/);
assert.match(nul, /null/);
assert.notEqual(empty, array);
assert.match(readPatch(path.join(dir, "missing.json")).error, /no such file/);
} finally {
fs.rmSync(dir, { recursive: true, force: true });
}
});
// Each rule break names the item id, the field and a "Like this:" fragment.
// The fragment is applied to the patch by `fix`, and the result must pass.
test("rule breaks name the item and field, and their Like this: passes validate() when applied", () => {
const withFragment = (problem) => {
const at = problem.indexOf("Like this: ");
assert.ok(at > 0, `a Like this: in ${problem}`);
return JSON.parse(problem.slice(at + "Like this: ".length));
};
const cases = [
{
what: "an unknown kind",
patch: { items: [{ id: "q1", kind: "nope", title: "Pick one", body: "Which?" }] },
start: /^item "q1" kind:/,
fix: (p, like) => Object.assign(p.items[0], like),
},
{
what: "an option with label",
patch: { items: [{ id: "q1", kind: "choice", title: "Pick one", body: "Which?", options: [{ label: "CSV" }, { text: "Excel" }] }] },
start: /^item "q1" options:/,
fix: (p, like) => (p.items[0].options[0] = like),
},
{
what: "two recommended options",
patch: { items: [{ id: "q1", kind: "choice", title: "Pick one", body: "Which?", options: [{ text: "CSV", recommended: true }, { text: "Excel", recommended: true }] }] },
start: /^item "q1" options:/,
fix: (p, like) => (p.items[0].options = like),
},
{
what: "a finish with a placeholder",
patch: { finish: { headline: "Done", command: "/plan2code-<x>" } },
start: /^finish\.command:/,
fix: (p, like) => Object.assign(p.finish, like.finish),
},
];
for (const { what, patch, start, fix } of cases) {
const problems = validate(applyPatch(wireState(), structuredClone(patch)));
assert.equal(problems.length, 1, `${what}: ${JSON.stringify(problems)}`);
assert.match(problems[0], start, what);
const fixed = structuredClone(patch);
fix(fixed, withFragment(problems[0]));
assert.deepEqual(validate(applyPatch(wireState(), fixed)), [], `${what}: the Like this: passes`);
}
// An unanswered note: the person wrote in a thread and the patch settles without replying.
const note = { ...wireItem("choice", [{ k: "A", text: "CSV" }]), thread: [{ who: "user", text: "Why?" }], submitted: { k: "A", at: "2026-01-01T00:00:00.000Z" } };
const base = { ...wireState(), items: [note] };
const stuck = validate(applyPatch(base, { settle: ["q1"] }));
assert.equal(stuck.length, 1);
assert.match(stuck[0], /^item "q1" thread:/);
const like = withFragment(stuck[0]);
assert.deepEqual(validate(applyPatch(base, { settle: ["q1"], items: [{ id: "q1", thread: like.thread.map((t) => ({ ...t, text: "Because." })) }] })), []);
});
test("a refused patch leaves state.json byte for byte as it was", () => {
const s = openSession();
try {
const file = path.join(s.session, "state.json");
const before = fs.readFileSync(file);
const refused = [
{ items: [{ id: "q9", kind: "nope", title: "Pick one", body: "Which?" }] },
{ items: [{ id: "q9", kind: "choice", title: "Pick one", body: "Which?", options: [{ k: "A", text: "x" }, { text: "y" }] }] },
{ finish: { headline: "Done", command: "/plan2code-<x>" } },
];
for (const patch of refused) {
const res = postPatch(s, patch, { expectFail: true });
assert.equal(res.status, 3, JSON.stringify(patch));
assert.match(res.stderr, /Like this:/);
assert.ok(fs.readFileSync(file).equals(before), "state.json is untouched");
}
} finally {
cli(["stop", "--session", s.sid, "--force"]);
}
});