Refuse a new question until a noted one is dealt with

AI Assisted
This commit is contained in:
jparkerweb committed 2026-11-09 10:08:45 -08:00
1 parent 92d4d880bf
commit 1a17578aa9
19 files changed
+475 -24

No files matched your search

+2 -2
View File
@@ -38,9 +38,9 @@ export const BUDGETS = {
"init.md": 300,
"loop.md": 11600,
"pathfinder.md": 2400,
"plan.md": 700,
"plan.md": 800,
"pr-prep.md": 4500,
"quick-task.md": 4000,
"quick-task.md": 4100,
"review.md": 1000,
"revise-plan.md": 1200,
"test.md": 5400,
+108
View File
@@ -827,3 +827,111 @@ test("a pathfinder session offers Write a brief, and the picked range reaches th
assert.deepEqual(got.actions.map(({ i, type, range }) => ({ i, type, range })), [{ i: "__brief", type: "brief", range: "this week" }]);
assert.equal(got.reply, "Write a brief for this week.");
});
// What a person sees break: the agent answers a note in the thread and the
// card says nothing, so the question looks as current as before the reply.
test("a noted card with a trailing agent reply shows the check tag, and an un-noted one does not", async (t) => {
const s = await openSession(await suite.browser(), {
t,
workflow: "plan",
payload: {
items: [
{ id: "q1", kind: "text", title: "What to call it", body: "A short name." },
{ id: "q2", kind: "text", title: "Who uses it", body: "Who, and for what?" },
],
},
});
const aside = s.page.locator("#aside");
const tag = aside.locator(".noted-tag");
await itemCard(s.page, "q1").waitFor();
assert.equal(await tag.count(), 0, "no tag before any note");
await fillBox(s.page.locator("#thread-q1"), "Maybe two names?");
await sendAndCollect(s);
s.post({ items: [{ id: "q1", thread: [{ who: "agent", text: "Two names fit, I will ask." }] }, { id: "q2", thread: [{ who: "agent", text: "A plain reply, no note from you." }] }] });
await aside.getByText("Two names fit, I will ask.").waitFor();
await tag.waitFor();
assert.equal((await tag.innerText()).trim(), "Plan2Code replied, check this still fits");
assert.equal(await tag.getAttribute("role"), "note", "the tag has an accessible role");
assert.notEqual(await styleOf(tag, "backgroundColor"), "rgba(0, 0, 0, 0)", "the tag is drawn, not bare text");
await s.page.locator("#sidebar .rail-item", { hasText: "Who uses it" }).click();
await aside.getByText("A plain reply, no note from you.").waitFor();
assert.equal(await aside.locator(".noted-tag").count(), 0, "a reply on a question nobody noted gets no tag");
});
// What a person sees break: a question arrives while they type, the notice
// vanishes after 8 seconds, and the question stays buried in the list.
test("a question arriving while a note is typed keeps its notice and a New mark until it is opened", async (t) => {
const s = await openSession(await suite.browser(), {
t,
workflow: "plan",
clock: true,
payload: { items: [{ id: "q1", kind: "text", title: "What to call it", body: "A short name." }] },
});
const note = s.page.locator("#thread-q1");
await itemCard(s.page, "q1").waitFor();
await fillBox(note, "my half-written thought");
await note.click();
await s.page.waitForFunction(() => Boolean(document.activeElement && document.activeElement.field));
s.post({ items: [{ id: "q2", kind: "text", title: "Who uses it", body: "Who, and for what?" }] });
const banner = s.page.locator("#banner");
await s.page.getByText("A new question from Plan2Code").waitFor();
const entry = s.page.locator("#sidebar .rail-item", { hasText: "Who uses it" });
await entry.locator(".rail-new").waitFor();
await s.page.clock.fastForward(20000);
assert.equal(await banner.isVisible(), true, "the notice is still up after 20 seconds");
assert.match(await banner.innerText(), /new question/);
assert.equal(await boxValue(note), "my half-written thought", "the draft is untouched");
assert.equal(await s.page.evaluate(() => Boolean(document.activeElement && document.activeElement.field)), true, "focus is still in the note box");
assert.equal(await itemCard(s.page, "q1").isVisible(), true, "the selection did not move");
// By keyboard, so no pointer press clears the notice first: only the prune can.
await entry.focus();
await s.page.keyboard.press("Enter");
await itemCard(s.page, "q2").waitFor();
assert.equal(await s.page.locator("#sidebar .rail-new").count(), 0, "the mark is gone once the question is opened");
assert.equal(await banner.isVisible(), false, "the notice goes with the last mark");
});
test("opening the marked question from the pager clears its New mark", async (t) => {
const s = await openSession(await suite.browser(), {
t,
workflow: "plan",
payload: { items: [{ id: "q1", kind: "text", title: "What to call it", body: "A short name." }] },
});
const note = s.page.locator("#thread-q1");
await itemCard(s.page, "q1").waitFor();
await fillBox(note, "half a thought");
await note.click();
await s.page.waitForFunction(() => Boolean(document.activeElement && document.activeElement.field));
s.post({ items: [{ id: "q2", kind: "text", title: "Who uses it", body: "Who, and for what?" }] });
const entry = s.page.locator("#sidebar .rail-item", { hasText: "Who uses it" });
await entry.locator(".rail-new").waitFor();
const pager = s.page.getByRole("navigation", { name: "Move between the questions waiting" });
await pager.getByRole("button", { name: /Next.*Who uses it/ }).click();
await itemCard(s.page, "q2").waitFor();
assert.equal(await s.page.locator("#sidebar .rail-new").count(), 0, "the mark is gone once the pager opens the question");
});
test("a staying arrival notice survives typing, goes on Escape, and the New mark outlasts it", async (t) => {
const s = await openSession(await suite.browser(), {
t,
workflow: "plan",
payload: { items: [{ id: "q1", kind: "text", title: "What to call it", body: "A short name." }] },
});
const note = s.page.locator("#thread-q1");
await itemCard(s.page, "q1").waitFor();
await note.click();
await s.page.waitForFunction(() => Boolean(document.activeElement && document.activeElement.field));
s.post({ items: [{ id: "q2", kind: "text", title: "Who uses it", body: "Who, and for what?" }] });
const banner = s.page.locator("#banner");
await s.page.getByText("A new question from Plan2Code").waitFor();
await s.page.keyboard.press("a");
assert.equal(await banner.isVisible(), true, "a letter typed in the note does not clear the notice");
await s.page.keyboard.press("Escape");
await banner.waitFor({ state: "hidden" });
assert.equal(await s.page.locator("#sidebar .rail-item", { hasText: "Who uses it" }).locator(".rail-new").count(), 1, "the New mark stays after the notice is dismissed");
});
+155
View File
@@ -156,6 +156,161 @@ test("a finish patch is exempt from the unanswered-note check", () => {
assert.deepEqual(validate(next), []);
});
/* ------------------------------------------------- a note on a question */
const guardNoted = () => ({
...choice("guard"),
thread: [{ who: "user", text: "Why this option?" }],
noted: true,
});
const plan = (items) => ({ ...blankState({ sid: "x", project: "p", workflow: "plan" }), items });
const notedAfter = (patch, item = guardNoted()) => applyPatch(plan([item]), patch).items.find((i) => i.id === "guard");
// The reported session: a note lands on an open question, the agent replies in
// its thread and asks the next question in the same patch, and the page buries
// the new one while the person is still typing. The console refuses the patch
// and names the fix.
const NOTED_REFUSAL =
'item "guard" noted: has a note from the person that you answered in the thread: reword it, delete it ("_delete": true) or send "stands": true, in the same patch that adds a new question. Like this: {"id":"guard","stands":true}';
const guardReply = { id: "guard", thread: [{ who: "agent", text: "Because it matches the brief." }] };
const refusedPast = (state, patch) => assert.throws(() => applyPatch(state, patch), (e) => e.message === NOTED_REFUSAL);
const passesPast = (state, patch) => {
const next = applyPatch(state, patch);
assert.deepEqual(validate(next), []);
return next;
};
test("a reply in the thread of a noted question, with a new question in the same patch, is refused", () => {
const state = plan([choice("guard")]);
state.items[0].noted = true; // the way the server sets it when the note lands
refusedPast(state, { items: [guardReply, choice("build")] });
});
test("the refusal names every noted question still standing, and only those", () => {
const state = plan([guardNoted(), { ...guardNoted(), id: "other" }]);
assert.throws(
() => applyPatch(state, { items: [guardReply, { id: "other", stands: true, thread: [{ who: "agent", text: "Still right." }] }, choice("build")] }),
(e) => e.message === NOTED_REFUSAL,
);
});
test("a reply alone on a noted question passes and keeps it noted: only a new question is refused", () => {
const next = passesPast(plan([guardNoted()]), { items: [guardReply] });
assert.equal(next.items[0].noted, true);
});
test("a later patch that adds a new question past a still-noted card is refused", () => {
const replied = applyPatch(plan([guardNoted()]), { items: [guardReply] });
refusedPast(replied, { items: [choice("build")] });
});
test('"stands": true on the noted question lets a new question through', () => {
const next = passesPast(plan([guardNoted()]), { items: [{ ...guardReply, stands: true }, choice("build")] });
assert.equal("noted" in next.items[0], false);
});
test("rewording the noted question lets a new question through", () => {
passesPast(plan([guardNoted()]), { items: [{ ...guardReply, body: "Which option fits the brief?" }, choice("build")] });
});
test("deleting the noted question in the same patch lets a new question through", () => {
const next = passesPast(plan([guardNoted()]), { items: [{ id: "guard", _delete: true }, choice("build")] });
assert.deepEqual(next.items.map((i) => i.id), ["build"]);
});
test("settling the noted question in the same patch lets a new question through", () => {
passesPast(plan([guardNoted()]), { items: [{ ...guardReply, status: "answered", answer: { k: "A" } }, choice("build")] });
});
test("an answered or skipped card that still carries noted holds nothing up", () => {
for (const status of ["answered", "skipped"]) {
passesPast(plan([{ ...guardNoted(), thread: [], status }]), { items: [choice("build")] });
}
});
test("an optional question or a notice may follow a noted card", () => {
passesPast(plan([guardNoted()]), { items: [guardReply, choice("maybe", { required: false })] });
passesPast(plan([guardNoted()]), { items: [guardReply, { id: "fyi", kind: "notice", title: "Heads up" }] });
});
test("a patch that posts a finish is not held to the noted rule", () => {
const finish = { headline: "Paused at the guard question", body: "Picked up later." };
assert.doesNotThrow(() => applyPatch(plan([guardNoted()]), { items: [guardReply, choice("build")], finish }));
});
test("the dashboard is not held to the noted rule (it draws no cards at all)", () => {
const state = { ...blankState({ sid: "x", project: "p", workflow: "dashboard" }), items: [guardNoted()] };
assert.doesNotThrow(() => applyPatch(state, { items: [guardReply, choice("build")] }));
});
test("a noted card whose note is not yet replied to is refused for both, in one message", () => {
assert.throws(
() => applyPatch(plan([guardNoted()]), { items: [choice("build")] }),
(e) =>
e.message ===
'item "guard" thread: has an unanswered note from the person; reply in its thread in this patch. Like this: {"id":"guard","thread":[{"who":"agent","text":"..."}]}\n' +
NOTED_REFUSAL,
);
});
test("a top-level settle clears noted, so reopening the card later holds nothing up", () => {
for (const settle of [true, ["guard"]]) {
const sent = { ...guardNoted(), thread: [...guardNoted().thread, guardReply.thread[0]], submitted: { at: "2026-11-09T08:00:00.000Z", k: "A" } };
const settled = applyPatch(plan([sent]), { settle });
assert.equal(settled.items[0].status, "answered");
assert.equal("noted" in settled.items[0], false);
passesPast(settled, { items: [{ id: "guard", status: "reopened" }, choice("build")] });
}
});
test("one patch may settle an answered noted card and ask the next question", () => {
const sent = { ...guardNoted(), thread: [...guardNoted().thread, guardReply.thread[0]], submitted: { at: "2026-11-09T08:00:00.000Z", k: "A" } };
passesPast(plan([sent]), { settle: true, items: [choice("build")] });
});
test("a reworded body clears noted", () => {
assert.equal("noted" in notedAfter({ items: [{ id: "guard", body: "A different question." }] }), false);
});
test("changed options clear noted", () => {
const options = [{ k: "A", text: "Only this" }];
assert.equal("noted" in notedAfter({ items: [{ id: "guard", options }] }), false);
});
test("a reply that leaves the question alone keeps noted", () => {
const item = notedAfter({ items: [{ id: "guard", thread: [{ who: "agent", text: "Seen." }] }] });
assert.equal(item.noted, true);
});
test("a patch that repeats the same body keeps noted", () => {
assert.equal(notedAfter({ items: [{ id: "guard", body: guardNoted().body }] }).noted, true);
});
test("deleting a noted question removes it with its flag", () => {
assert.deepEqual(applyPatch(plan([guardNoted()]), { items: [{ id: "guard", _delete: true }] }).items, []);
});
test("settling a noted question clears noted", () => {
assert.equal("noted" in notedAfter({ items: [{ id: "guard", status: "answered" }] }), false);
assert.equal("noted" in notedAfter({ items: [{ id: "guard", status: "skipped" }] }), false);
assert.equal("noted" in notedAfter({ items: [{ id: "guard", answer: { k: "A" } }] }), false);
});
test("stands: true clears noted and is never stored; a non-boolean stands is refused", () => {
const item = notedAfter({ items: [{ id: "guard", stands: true }] });
assert.equal("noted" in item, false);
assert.equal("stands" in item, false);
const kept = notedAfter({ items: [{ id: "guard", stands: false }] });
assert.equal(kept.noted, true, "stands: false clears nothing");
assert.equal("stands" in kept, false);
assert.throws(() => applyPatch(plan([guardNoted()]), { items: [{ id: "guard", stands: "yes" }] }), /stands/);
});
test("stands on a new question is dropped, not stored", () => {
const next = applyPatch(plan([]), { items: [{ ...choice("fresh"), stands: true }] });
assert.equal("stands" in next.items[0], false);
});
/* ------------------------------------------------------------- the CLI */
test("post --file reads a patch PowerShell wrote: a UTF-8 BOM, or UTF-16", () => {
+9
View File
@@ -1285,6 +1285,7 @@ test("a send records its note and attachments on the item, so the page can show
assert.equal(only.status, 200);
const after = readState().items.find((i) => i.id === "q1");
assert.equal(after.sentNote.text, "just a note");
assert.equal(after.noted, true, "a note on an open question marks it noted");
assert.deepEqual(after.sentNote.images ?? [], []);
assert.deepEqual(
after.thread.filter((m) => m.who === "user").map((m) => m.text).slice(-2),
@@ -1298,11 +1299,18 @@ test("a request for suggestions is recorded with its flag and threaded even with
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;
// Earlier notes on q1 left it noted: the agent says the question stands.
assert.equal(readState().items.find((i) => i.id === "q1").noted, true);
assert.equal(cli(["post", "--session", sid, "--file", payload("stands-q1.json", { items: [{ id: "q1", stands: true }] })]).status, 0);
assert.equal("noted" in readState().items.find((i) => i.id === "q1"), false, "stands: true clears noted");
assert.equal("stands" in readState().items.find((i) => i.id === "q1"), false, "stands is never stored");
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);
assert.equal("noted" in q1, false, "a request for suggestions is not a note on the question");
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");
@@ -1315,6 +1323,7 @@ test("a request for suggestions is recorded with its flag and threaded even with
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("noted" in q1, false, "an empty comment leaves nothing to deal with, so it does not mark the question noted");
assert.equal(cli(["wait", "--session", sid, "--seconds", "10"]).status, 0);
});
+1
View File
@@ -61,6 +61,7 @@ test("state: the rest of the shared state starts as app.js always started it", (
dashPick: null,
mentionPop: null,
heldPose: null,
newQuestions: new Set(),
scopeMine: null,
launchScoping: false,
});