Add the headless Ask for suggestions send and its server flag

AI Assisted
This commit is contained in:
jparkerweb committed 2026-11-04 12:09:43 -08:00
1 parent eb235dd91e
commit f8a0a6bfc7
8 files changed
+264 -16

No files matched your search

+66
View File
@@ -62,6 +62,9 @@ import {
MAX_NOTE_IMAGES,
noteAction,
noteReplyLines,
pruneStaged,
suggestAction,
suggestReplyLines,
progressTotal,
quietLimitMs,
resumeCommand,
@@ -515,6 +518,69 @@ test("a note with documents splits them into files, keeps attach order in its li
]);
});
test("a request for suggestions reads apart from a note, with its note and attachments", () => {
assert.deepEqual(suggestReplyLines("Export format", "Which suits Excel?", []), ["Suggestions wanted on Export format: Which suits Excel?"]);
assert.deepEqual(suggestReplyLines("Export format", "", []), ["Suggestions wanted on Export format: (no note)"]);
assert.deepEqual(suggestReplyLines("Export format", "", undefined), ["Suggestions wanted on Export format: (no note)"]);
assert.deepEqual(suggestReplyLines("Export format", "Line one\nLine two", []), [
"Suggestions wanted on Export format: Line one\n Line two",
]);
const atts = [
{ key: "k1", path: "C:\\x\\a.jpg", name: "shot.png", status: "ready" },
{ key: "k2", kind: "file", path: "C:\\x\\b.pdf", name: "spec.pdf", status: "ready" },
];
assert.deepEqual(suggestReplyLines("Export format", "See these", atts), [
"Suggestions wanted on Export format: See these",
" Image: C:\\x\\a.jpg (shot.png)",
" File: C:\\x\\b.pdf (spec.pdf)",
]);
assert.deepEqual(suggestAction("q1", "See these", atts), {
i: "q1",
type: "comment",
text: "See these",
images: [{ path: "C:\\x\\a.jpg", name: "shot.png" }],
files: [{ path: "C:\\x\\b.pdf", name: "spec.pdf" }],
suggest: true,
});
assert.deepEqual(suggestAction("q1", "", []), { i: "q1", type: "comment", text: "", suggest: true });
});
test("pruneStaged drops only the picks a re-posted card no longer offers, without touching its inputs", () => {
const opts = (...ks) => ks.map((k) => ({ k, text: k }));
const items = [
{ id: "c1", kind: "choice", options: opts("A", "B") },
{ id: "c2", kind: "choice", options: opts("A") },
{ id: "m1", kind: "multi", options: opts("1", "3") },
{ id: "m2", kind: "multi", options: opts("1") },
{ id: "f1", kind: "confirm" },
{ id: "u1", kind: "choice", options: opts("A", "B") },
];
const staged = {
c1: { type: "answer", kind: "choice", k: "C" },
c2: { type: "answer", kind: "choice", k: "B", text: "or something else" },
m1: { type: "answer", kind: "multi", ks: ["1", "2", "3"] },
m2: { type: "answer", kind: "multi", ks: ["2"] },
f1: { type: "answer", kind: "confirm", yes: true },
u1: { type: "answer", kind: "choice", k: "B" },
gone: { type: "answer", kind: "choice", k: "Z" },
};
const before = structuredClone(staged);
const itemsBefore = structuredClone(items);
const out = pruneStaged(items, staged);
assert.deepEqual(out.dropped.sort(), ["c1", "c2", "m1", "m2"]);
assert.equal("c1" in out.staged, false, "a choice left with nothing goes");
assert.deepEqual(out.staged.c2, { type: "answer", kind: "choice", text: "or something else" }, "typed text keeps the entry");
assert.deepEqual(out.staged.m1.ks, ["1", "3"], "a multi keeps the keys still offered");
assert.equal("m2" in out.staged, false, "a multi left empty goes");
assert.equal(out.staged.f1, staged.f1, "a confirm is left alone");
assert.equal(out.staged.u1, staged.u1, "an unchanged card is left alone");
assert.equal(out.staged.gone, staged.gone, "an id not among the items is left alone");
assert.notEqual(out.staged, staged, "a new object comes back");
assert.deepEqual(staged, before, "staged is not changed");
assert.deepEqual(items, itemsBefore, "items are not changed");
assert.deepEqual(pruneStaged(items, { u1: staged.u1 }), { staged: { u1: staged.u1 }, dropped: [] });
});
test("document helpers: the extension allow-list, the picker's accept, sizes, and the kind of an old entry", () => {
assert.equal(MAX_ATTACHMENTS, 5);
assert.equal(MAX_DOC_BYTES, 10 * 1024 * 1024);
+34 -1
View File
@@ -8,7 +8,7 @@ import test from "node:test";
import assert from "node:assert/strict";
import { page, fresh } from "../src/web-console/public/state.js";
import { WORKING_GRACE_MS } from "../src/web-console/public/selectors.js";
import { sendState } from "../src/web-console/public/send-state.js";
import { sendState, suggestState } from "../src/web-console/public/send-state.js";
const MIN = 60 * 1000;
const ago = (ms) => new Date(Date.now() - ms).toISOString();
@@ -151,3 +151,36 @@ test("send state: a note waits while its picture uploads, and goes once it is re
page.local.images.q1 = [{ key: "a", status: "ready", url: "/uploads/a.jpg" }];
assert.deepEqual(sendState(), { disabled: false, why: "" });
});
test("send state: told there is something to send, an idle page enables it with nothing staged", () => {
setup();
assert.deepEqual(sendState(), { disabled: true, why: "" }, "left out, it reads what is staged");
assert.deepEqual(sendState(true), { disabled: false, why: "" });
assert.deepEqual(sendState(false), { disabled: true, why: "" });
});
test("suggest state: the chip follows Send, and waits while its own request does", () => {
const ready = { disabled: false, why: "Ask Plan2Code what it would pick here, and why." };
setup();
assert.deepEqual(suggestState(question()), ready, "nothing staged is needed: the request is the payload");
setup({ finish: { headline: "Phase 3 is done" } });
assert.deepEqual(suggestState(question()), { disabled: true, why: "This session is finished." });
setup();
page.pendingResult = true;
assert.deepEqual(suggestState(question()), { disabled: true, why: "Your last answers are on their way. One moment." });
const at = ago(MIN);
const asked = question("q1", { sentNote: { at, text: "", suggest: true }, thread: [{ who: "user", at, text: "", suggest: true }] });
setup({ items: [asked] });
assert.deepEqual(suggestState(asked), { disabled: true, why: "Plan2Code has your request for suggestions on this one." });
const plain = question("q1", { sentNote: { at, text: "Hm" }, thread: [{ who: "user", at, text: "Hm" }] });
setup({ items: [plain] });
assert.deepEqual(suggestState(plain), ready, "a plain note waiting does not hold the chip");
const replied = { ...asked, thread: [...asked.thread, { who: "agent", at: ago(0), text: "I would pick CSV." }] };
setup({ items: [replied] });
assert.deepEqual(suggestState(replied), ready, "the agent's reply frees it");
});
+24
View File
@@ -1281,6 +1281,30 @@ test("a send records its note and attachments on the item, so the page can show
assert.equal(cli(["wait", "--session", sid, "--seconds", "10"]).status, 0);
});
test("a request for suggestions is recorded with its flag and threaded even with no note; a non-boolean flag is dropped", async () => {
const readState = () => JSON.parse(fs.readFileSync(path.join(HOME, "sessions", sid, "state.json"), "utf8"));
const userCount = () => readState().items.find((i) => i.id === "q1").thread.filter((m) => m.who === "user").length;
let before = userCount();
const ok = await post("/submit", { actions: [{ i: "q1", type: "comment", text: "", suggest: true }], reply: "Suggestions wanted on q1: (no note)" });
assert.equal(ok.status, 200);
let q1 = readState().items.find((i) => i.id === "q1");
assert.equal(q1.sentNote.suggest, true);
const mine = q1.thread.filter((m) => m.who === "user").at(-1);
assert.equal(userCount(), before + 1, "an empty request still goes into the thread");
assert.equal(mine.who, "user");
assert.equal(mine.suggest, true);
assert.equal(mine.at, q1.sentNote.at);
assert.equal(cli(["wait", "--session", sid, "--seconds", "10"]).status, 0);
before = userCount();
assert.equal((await post("/submit", { actions: [{ i: "q1", type: "comment", text: "", suggest: "yes" }], reply: "z" })).status, 200);
q1 = readState().items.find((i) => i.id === "q1");
assert.equal("suggest" in q1.sentNote, false, "only true is kept");
assert.equal(userCount(), before, "a plain empty comment still adds no thread entry");
assert.equal(cli(["wait", "--session", sid, "--seconds", "10"]).status, 0);
});
test("what the person attached is not scanned for markers either", () => {
const statePath = path.join(HOME, "sessions", sid, "state.json");
const state = JSON.parse(fs.readFileSync(statePath, "utf8"));