From 1a17578aa941be3ebe476116eed5ddb2fd4ec8be Mon Sep 17 00:00:00 2001 From: Justin Parker Date: Mon, 9 Nov 2026 10:08:45 -0800 Subject: [PATCH] Refuse a new question until a noted one is dealt with AI Assisted --- .agents-docs/AGENTS-web-console-contract.md | 4 + CHANGELOG.md | 11 ++ scripts/test-console-wire-budgets.mjs | 4 +- scripts/test-web-console-page-cards.mjs | 108 ++++++++++++++ scripts/test-web-console-qa.mjs | 155 ++++++++++++++++++++ scripts/test-web-console-session.mjs | 9 ++ scripts/test-web-console-state.mjs | 1 + src/web-console/cmd-help.mjs | 14 +- src/web-console/console.md | 2 + src/web-console/notes/pathfinder.md | 1 + src/web-console/notes/plan.md | 1 + src/web-console/notes/quick-task.md | 1 + src/web-console/patches.mjs | 97 ++++++++++-- src/web-console/public/screens/ask.js | 9 ++ src/web-console/public/screens/core.js | 39 ++++- src/web-console/public/state.js | 3 + src/web-console/public/styles/pieces.css | 15 ++ src/web-console/public/styles/shell.css | 15 ++ src/web-console/routes.mjs | 10 +- 19 files changed, 475 insertions(+), 24 deletions(-) diff --git a/.agents-docs/AGENTS-web-console-contract.md b/.agents-docs/AGENTS-web-console-contract.md index 271844d..ca79cd4 100644 --- a/.agents-docs/AGENTS-web-console-contract.md +++ b/.agents-docs/AGENTS-web-console-contract.md @@ -30,6 +30,10 @@ A rule stated in six files is read six times and still skipped. The console sees Documents are read from `file` blocks rather than pasted so the page and the disk cannot disagree, and a progress post only has to ask for `refresh`. `assumed` and `draft` exist so a half-finished doc is not read as decisions. A doc `version` never goes back because the page keys its "new version" marker on it. +## Noted questions + +A person's note on an open question may change what it asks, and the agent's reply in the thread does not say what happens to the question. The server therefore records the fact (`noted`) when the note lands, and `validate()` refuses a new open required question until each noted one is reworded, deleted or confirmed with `stands: true`. A thread cannot answer this: it stays true forever after one reply. The page shows the same flag as a tag, and keeps the arrival notice and a New mark until the new question is opened, since eight seconds is easy to miss mid-sentence. + ## console-finish.md and console-stop.md - **Finish before stop.** The page tells the person to leave the tab open until the next question appears. Stopping first leaves them looking at a promise about a session that is over, and the one thing they need, a command to run in a terminal they are not looking at, never reaches them. The console refuses a `stop` with no `finish` (`--force` for a dead page). diff --git a/CHANGELOG.md b/CHANGELOG.md index a085b7b..7fcbe60 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,17 @@ All notable changes to Plan2Code will be documented in this file. - **web console**: the Implementation Loop's **Strength per phase** setting is now a grid instead of a dropdown per phase: one row per phase, a column each for Match my session, Thrifty, Balanced and Best, and a thick stepped line through each row's pick so the choices read at a glance. The saved picks and the loop's behavior are unchanged. +### ✨ Added + +- **web console**: Diagnose can now start from a Notebook tab. + +### 🐛 Fixed + +- **web console**: a question you put a note on is now flagged as noted, and the console refuses a new question from the agent until it rewords, deletes or confirms the noted one, so a question a reply made moot no longer sits open while the next one is buried; the page tags the card, keeps the new-question notice up until dismissed, and marks the new question "New" in the list. +- **web console**: a finish screen that was left stranded now has a way out, and a pressed Review clears when a different finish replaces it. +- **web console**: Quick Task asks for sign-off after its See it running demo. +- **web console**: a loop phase whose page does not show now offers a reconnect button. + ## v3.0.4 ### ✨ Added diff --git a/scripts/test-console-wire-budgets.mjs b/scripts/test-console-wire-budgets.mjs index c79ed5a..5afd67c 100644 --- a/scripts/test-console-wire-budgets.mjs +++ b/scripts/test-console-wire-budgets.mjs @@ -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, diff --git a/scripts/test-web-console-page-cards.mjs b/scripts/test-web-console-page-cards.mjs index c9629d0..9b710d1 100644 --- a/scripts/test-web-console-page-cards.mjs +++ b/scripts/test-web-console-page-cards.mjs @@ -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"); +}); diff --git a/scripts/test-web-console-qa.mjs b/scripts/test-web-console-qa.mjs index e8e96a0..b103413 100644 --- a/scripts/test-web-console-qa.mjs +++ b/scripts/test-web-console-qa.mjs @@ -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", () => { diff --git a/scripts/test-web-console-session.mjs b/scripts/test-web-console-session.mjs index 00d4ef9..754db53 100644 --- a/scripts/test-web-console-session.mjs +++ b/scripts/test-web-console-session.mjs @@ -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); }); diff --git a/scripts/test-web-console-state.mjs b/scripts/test-web-console-state.mjs index 97bb280..b379f22 100644 --- a/scripts/test-web-console-state.mjs +++ b/scripts/test-web-console-state.mjs @@ -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, }); diff --git a/src/web-console/cmd-help.mjs b/src/web-console/cmd-help.mjs index d8601d1..c556216 100644 --- a/src/web-console/cmd-help.mjs +++ b/src/web-console/cmd-help.mjs @@ -68,10 +68,16 @@ port, and the filesystem as transport; this CLI is the whole agent surface. then waits up to N seconds in the same command (two JSON lines; the exit code is the wait's). The patch may carry settle: true (or a list of item ids) to mark the latest send's cards answered - with what was sent; doc blocks may carry file: "" (and - select: "tasks"), read from the project, and a doc refresh: true - re-reads them. A doc's version moves up by itself. A patch may - carry run: { event, id, tasks? } (session meter points) and folderIssue: + with what was sent. An item may carry stands: true, saying it + still applies after its note's thread reply: it clears the + item's noted flag (set when the person's note lands on an open + question) and is never stored. While any open item is noted, a + patch adding a new open required question is refused unless it + also rewords, deletes ("_delete": true) or stands each one. Doc + blocks may carry file: "" (and select: "tasks"), read from + the project, and a doc refresh: true re-reads them. A doc's + version moves up by itself. A patch may carry run: { event, id, + tasks? } (session meter points) and folderIssue: { name, reason, hint? } (a workspace folder you could not read); both go to the ledger, never into the state. A patch may also carry helpers: [{ id, title, ask, state, result?, strength?, diff --git a/src/web-console/console.md b/src/web-console/console.md index 500e3a6..ea29379 100644 --- a/src/web-console/console.md +++ b/src/web-console/console.md @@ -77,6 +77,8 @@ Items show in the order sent: send them in the order you want them answered. Every note in an item's `thread` gets a reply: `{"id":"p4","thread":[{"who":"agent","text":"..."}]}`. Send only new entries. +After the person's note on an open question, reword it (same `id`), retire it with `"_delete":true`, or send `"stands":true` if it still applies, in the patch with your reply or your next question. Until you do, a new open required question is refused. Do the same when an Ask reply or your own finding changes what a question assumed. + ## What the console refuses (exit 3) - more than three open required questions at once (optional cards and notices do not count) diff --git a/src/web-console/notes/pathfinder.md b/src/web-console/notes/pathfinder.md index 3eca751..cc0e1ef 100644 --- a/src/web-console/notes/pathfinder.md +++ b/src/web-console/notes/pathfinder.md @@ -3,6 +3,7 @@ - Post `"stopWarning"` while no map exists (Steps 0 to 4), `""` once it does, and `"specDir":"specs/"` when the folder is created. - The menu after a decision is a `menu` card: `options` are `trail --form C`'s, the `Start fresh` one keeps `"fresh":true`. Set the card's `command` to the resume command printed under `OR START FRESH`. A declined confirm leaves you the pick: carry on as for `Start fresh`. - The fresh-idea card carries `"templates":"idea"`, `"fill":"note"`. +- A note on an open question: reword it (same `id`), `"_delete":true` it or send `"stands":true` on it if it still fits, in the patch with your reply. - A doc that is a file as written (the map, a brief) is a `file` block (`{"id":"body","file":"specs//pathfinder/map.md"}`). Keep `md` where `assumed` / `draft` state matters. - Step 8 research subagents all report before the finish; the finish `body` names what each found. Report every one as a helper, whatever the Subagents switch says. - Every session end `finish`es with Form A's command as `command`. diff --git a/src/web-console/notes/plan.md b/src/web-console/notes/plan.md index 91ae9c8..c6f2926 100644 --- a/src/web-console/notes/plan.md +++ b/src/web-console/notes/plan.md @@ -1,6 +1,7 @@ # Planning - Phase breakdowns are an editable `list`. The fresh-idea card carries `"templates":"idea"`, `"fill":"note"`. +- A note on an open question: reword it, `"_delete":true` it or send `"stands":true` (still fits), with your reply. - Nothing is saved before the Large checkpoint or Phase 7: a stop before then has `finish.body` say nothing was kept, `"command":"/plan2code-1-plan"`. After the checkpoint post `"stopWarning":""`. - Completion finish `command`: `/plan2code-2-document`. The Large checkpoint finish is a pause: headline starts "Paused", `command` `/plan2code-1-plan`, no `dashboard`. - Helpers are reported as `helpers`, each `done` or `failed` before the sign-off it feeds. Questions, sign-offs and the PLAN-DRAFT stay with you. diff --git a/src/web-console/notes/quick-task.md b/src/web-console/notes/quick-task.md index fdf20ab..fac0bab 100644 --- a/src/web-console/notes/quick-task.md +++ b/src/web-console/notes/quick-task.md @@ -3,6 +3,7 @@ Read `building.md` first. - Clarifying questions are `text` or `choice`. The first (what to build) carries `"templates":"idea"`, `"fill":"note"`. +- A note on an open question: reword it, `"_delete":true` it or send `"stands":true` (still fits), with your reply. - Post `"stopWarning":"A quick task saves nothing until it is built, so stopping now loses what we have worked out."` at the start and `""` once the build is under way. - **Scope check:** `choice` "Too big for a quick task?": `1` Continue (lightweight format), `2` Escalate to a full plan; measured counts against thresholds in `body`. - **Feature name** (escalating): `text`, `"pattern":"^[a-z0-9]+(-[a-z0-9]+)*$"`, kebab-case placeholder. diff --git a/src/web-console/patches.mjs b/src/web-console/patches.mjs index a104133..a6037f9 100644 --- a/src/web-console/patches.mjs +++ b/src/web-console/patches.mjs @@ -123,10 +123,21 @@ const QUESTION_FIELDS = ["kind", "title", "body", "options", "steps", "rows", "s * settle it, that record (and any stale `answer`) is dropped, so the page shows * the new question as open instead of "Sent, waiting for Plan2Code" forever. */ -function dropStaleSubmissions(currentItems, before, patchList) { +function dropStaleSubmissions(currentItems, before, patchList, stands = new Set()) { const merged = mergeKeyed(currentItems, patchList, "id", ITEM_DEFAULTS, "items"); for (const entry of patchList) { const prev = (before || []).find((x) => x.id === entry.id); + // The person's note landed on this question (`noted`, set by the server). + // It stays until the agent deals with the question: rewords it, settles it, + // or says in the patch that the question stands as it is. + if (prev && prev.noted) { + const reworded = ["title", "body", "options"].some( + (f) => f in entry && JSON.stringify(entry[f]) !== JSON.stringify(prev[f]), + ); + const settled = entry.status === "answered" || entry.status === "skipped" || "answer" in entry; + const item = merged.find((x) => x.id === entry.id); + if (item && (reworded || settled || stands.has(entry.id))) delete item.noted; + } // A whole new question under an answered card's id is not a typo fix: the // card would stay answered and nothing would be left for the person, who // sees a dead page. Refuse it so the agent picks a new id on the spot. @@ -296,8 +307,11 @@ function settleItems(items, settle, patchItems, collected) { // report) means it is not settled: no answer is recorded over the reopen. if (entry.status === "open" || entry.status === "reopened") return item; const { at, kind, ...answer } = item.submitted; + // A settled card has been dealt with, so a note on it no longer holds + // anything up, even when it is reopened later. + const { noted: _noted, ...settled } = item; return { - ...item, + ...settled, // A "Skip this one" send settles as skipped, not as an answer. status: "status" in entry ? item.status : answer.skipped === true ? "skipped" : "answered", ...("answer" in entry ? {} : { answer }), @@ -531,8 +545,22 @@ export function applyPatch(state, patch) { break; case "items": if (!Array.isArray(v)) throw new Error(rule("", "items", "must be an array", { items: [{ id: "q7", kind: "text", title: "Name" }] })); - next.items = dropStaleSubmissions(next.items, state.items, normalizeThreads(letterOptions(v), state.items)); - break; + { + // `stands: true` says "the question is still right after the note". It + // only clears `noted`, so it is never stored. + const stands = new Set(); + const list = v.map((entry) => { + if (!isPlainObject(entry) || !("stands" in entry)) return entry; + if (typeof entry.stands !== "boolean") { + throw new Error(rule(`item "${entry.id}"`, "stands", "must be true or false", { stands: true })); + } + if (entry.stands) stands.add(entry.id); + const { stands: _stands, ...rest } = entry; + return rest; + }); + next.items = dropStaleSubmissions(next.items, state.items, normalizeThreads(letterOptions(list), state.items), stands); + break; + } case "topics": if (!Array.isArray(v)) throw new Error(rule("", "topics", "must be an array", { topics: [{ id: "t2", title: "How it behaves", status: "current" }] })); next.topics = mergeKeyed(next.topics, v, "id", {}, "topics"); @@ -610,9 +638,59 @@ export function applyPatch(state, patch) { if (next.finish && !Object.hasOwn(patch, "finish") && asksSomething(patch.items, state.items)) { delete next.finish; } + refuseQuestionPastNote(state, next); return stampTimes(state, settleAgent(next, patch, state)); } +/** + * A question the person put a note on (`noted`, set by the server) stays in + * front of them until the agent deals with it. A new question asked past it + * would be buried behind a card the reply may have made moot, so the patch + * that adds one must also reword, delete or confirm (`stands`) every noted + * card. Only a new open required question counts: a reply alone, an optional + * card or a notice asks nothing new. A finish ends the session, and the + * dashboard draws no cards, so neither is held to it. + */ +function refuseQuestionPastNote(before, next) { + if (next.finish != null || next.workflow === "dashboard" || !Array.isArray(next.items)) return; + const noted = next.items.filter((i) => isPlainObject(i) && i.noted === true && isOpen(i)); + if (!noted.length) return; + const had = new Set((Array.isArray(before.items) ? before.items : []).map((i) => i && i.id)); + const asksNew = next.items.some( + (i) => isPlainObject(i) && !had.has(i.id) && i.required !== false && i.kind !== "notice" && i.noted !== true && isOpen(i), + ); + if (!asksNew) return; + // A note not yet replied to is named too: validate() never runs after this + // throw, and the agent would otherwise fix one and be refused for the other. + throw new Error( + noted + .flatMap((i) => [ + ...(lastWordIsTheirs(i) ? [unansweredNote(i)] : []), + rule( + `item "${i.id}"`, + "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', + { id: i.id, stands: true }, + ), + ]) + .join("\n"), + ); +} + +// The person had the last word in a card's thread: their note waits for a reply. +function lastWordIsTheirs(item) { + const thread = Array.isArray(item.thread) ? item.thread : []; + const last = thread[thread.length - 1]; + return isPlainObject(last) && last.who === "user"; +} + +function unansweredNote(item) { + return rule(`item "${item.id}"`, "thread", "has an unanswered note from the person; reply in its thread in this patch", { + id: item.id, + thread: [{ who: "agent", text: "..." }], + }); +} + // `activity` belongs under `agent`, which is the only place the page reads it. // Sent at the top level it would be stored where nothing looks, and the page // would sit on its starting screen while the skill works. @@ -862,16 +940,7 @@ export function validate(state) { // nothing further is coming to answer into. if (state.finish == null) { for (const item of state.items) { - const thread = Array.isArray(item.thread) ? item.thread : []; - const last = thread[thread.length - 1]; - if (isPlainObject(last) && last.who === "user") { - problems.push( - rule(`item "${item.id}"`, "thread", "has an unanswered note from the person; reply in its thread in this patch", { - id: item.id, - thread: [{ who: "agent", text: "..." }], - }), - ); - } + if (lastWordIsTheirs(item)) problems.push(unansweredNote(item)); } } diff --git a/src/web-console/public/screens/ask.js b/src/web-console/public/screens/ask.js index 8e2f8b1..9c7f5b0 100644 --- a/src/web-console/public/screens/ask.js +++ b/src/web-console/public/screens/ask.js @@ -760,6 +760,15 @@ export function renderAside() { aside.appendChild(box); } + // The agent answered a note and has not yet dealt with the question itself: + // say so, because the reply may have changed what the question asks. + const last = thread[thread.length - 1]; + if (item.noted === true && isOpen(item) && !finish() && last && threadWho(last) === "agent") { + const tag = el("p", "pill noted-tag", "Plan2Code replied, check this still fits"); + tag.setAttribute("role", "note"); + aside.appendChild(tag); + } + if (waiting && !waitingShown) { const box = el("div", "msg you pending"); const who = el("div", "msg-who"); diff --git a/src/web-console/public/screens/core.js b/src/web-console/public/screens/core.js index 8af1cbc..0f02de1 100644 --- a/src/web-console/public/screens/core.js +++ b/src/web-console/public/screens/core.js @@ -523,9 +523,13 @@ export function adopt(body) { arrived.length === 1 ? "A new question from Plan2Code. It is in the list on the left." : `${arrived.length} new questions from Plan2Code. They are in the list on the left.`; - banner(staleLine ? `${staleLine} ${arrivedLine}` : arrivedLine, "info"); + // The notice stays until a click, Escape or opening the question: a + // question that arrives mid-sentence is easy to miss in eight seconds. + // The question already on screen needs no mark: it is where they are looking. + for (const q of arrived) if (!(page.view === "questions" && page.selected === q.id)) page.newQuestions.add(q.id); + arrivalNotice = staleLine ? `${staleLine} ${arrivedLine}` : arrivedLine; + banner(arrivalNotice, "info"); clearTimeout(arrivalBannerTimer); - arrivalBannerTimer = setTimeout(() => !page.gone && banner(null), 8000); } else { page.selected = arrived[0].id; page.view = "questions"; @@ -534,6 +538,7 @@ export function adopt(body) { } if (!page.selected || !byId(page.selected)) page.selected = pickDefault(); + pruneNewQuestions(); // A reply that lands while another tab is open: a dot on Ask, and one chime. // Not on the first load, which has nothing new to announce. const dot = unreadDot({ lastSeenReplyId: page.local.chat.lastSeenReplyId, frameChat: page.chatFrame, viewIsAsk: page.view === "ask" }); @@ -600,6 +605,24 @@ function scrollRail(where) { } let arrivalBannerTimer = null; +// The text of a notice that stays up (see adopt), so only that banner is cleared. +let arrivalNotice = ""; + +function dropArrivalNotice() { + if (arrivalNotice && $("banner").textContent === arrivalNotice) banner(null); + arrivalNotice = ""; +} + +// Marks that no longer apply: a question that is answered or gone, or the one +// now on screen. The notice goes with the last mark. +function pruneNewQuestions() { + const had = page.newQuestions.size; + for (const id of [...page.newQuestions]) { + const item = byId(id); + if (!item || !isOpen(item) || (page.view === "questions" && page.selected === id)) page.newQuestions.delete(id); + } + if (had && !page.newQuestions.size) dropArrivalNotice(); +} // Typing in any text field, the question's own or the notes beside it. A // focused Markdown field surfaces as its .md-host (the editor inside its @@ -819,6 +842,8 @@ export function render() { if (rendering) return; rendering = true; try { + // A question opened by any route (the pager, a tab switch) loses its New mark. + pruneNewQuestions(); trackAbout(); const enteringAsk = page.view === "ask" && drawnView !== "ask"; const switchingTab = drawnView !== null && page.view !== drawnView; @@ -1606,9 +1631,15 @@ export function renderSidebar() { mark.title = m.label; b.appendChild(mark); b.appendChild(el("span", null, item.title)); + if (page.newQuestions.has(item.id)) { + const fresh = el("span", "rail-new", "New"); + fresh.title = "arrived while you were typing"; + b.appendChild(fresh); + } b.addEventListener("click", () => { page.selected = item.id; page.view = "questions"; + pruneNewQuestions(); render(); $("main").focus(); }); @@ -2313,6 +2344,10 @@ export function wireChrome() { true ); + // A click or Escape puts a staying arrival notice away; the list keeps the "New" mark. + document.addEventListener("pointerdown", () => arrivalNotice && dropArrivalNotice(), true); + document.addEventListener("keydown", (e) => e.key === "Escape" && arrivalNotice && dropArrivalNotice(), true); + $("meter-pill").addEventListener("click", () => toggleMeterPop()); $("meter-help").addEventListener("click", () => { toggleMeterPop(false); diff --git a/src/web-console/public/state.js b/src/web-console/public/state.js index 164baa6..5435ec1 100644 --- a/src/web-console/public/state.js +++ b/src/web-console/public/state.js @@ -155,6 +155,9 @@ export const page = { // The pose pane on screen when a render began, held back from the clear so // posePane() can take it up again. See posePane. heldPose: null, + // Questions that arrived while the person was typing and are not opened yet + // (a "New" mark in the list). Page-local, never saved. + newQuestions: new Set(), // The workspace scope (a spec dir, "" for the project) this tab last asked // for: its own pick, not whatever the frame says. And true from a launch's // scope sync until its send has gone (or failed). diff --git a/src/web-console/public/styles/pieces.css b/src/web-console/public/styles/pieces.css index 0c72fbe..3e50343 100644 --- a/src/web-console/public/styles/pieces.css +++ b/src/web-console/public/styles/pieces.css @@ -280,10 +280,14 @@ .card.is-inflight { border-color: var(--stage); } .card.is-inflight .option.is-locked.is-recorded { border-color: var(--stage); + text-transform: none; + letter-spacing: 0; background: var(--stage-soft); } .card.is-inflight .option.is-locked.is-recorded:hover { border-color: var(--stage); + text-transform: none; + letter-spacing: 0; background: var(--stage-soft); } .card.is-inflight .option-mark.on { color: var(--stage); } @@ -961,3 +965,14 @@ h4.md-h, h5.md-h, h6.md-h { font-size: 15px; } .modal-actions:has(#stop-cancel) .btn { width: 100%; } } + +/* A noted card whose last word in the thread is the agent's reply. */ +.noted-tag { + display: block; + margin: 2px 0 10px; + background: var(--stage-soft); + color: var(--stage); + border-color: var(--stage); + text-transform: none; + letter-spacing: 0; +} diff --git a/src/web-console/public/styles/shell.css b/src/web-console/public/styles/shell.css index 4bb90e9..4cec026 100644 --- a/src/web-console/public/styles/shell.css +++ b/src/web-console/public/styles/shell.css @@ -777,3 +777,18 @@ button.waiting-jump:hover { text-decoration-color: var(--accent); } } @keyframes arrival-draw { from { transform: scaleX(0); } to { transform: scaleX(1); } } + +/* A question that arrived while the person was typing, until it is opened. */ +.rail-new { + flex: none; + align-self: flex-start; + margin-top: 2px; + padding: 0 6px; + border-radius: 999px; + font-size: 10.5px; + font-weight: 700; + letter-spacing: .04em; + text-transform: uppercase; + background: var(--accent-soft); + color: var(--accent); +} diff --git a/src/web-console/routes.mjs b/src/web-console/routes.mjs index 2f17775..8b2c12e 100644 --- a/src/web-console/routes.mjs +++ b/src/web-console/routes.mjs @@ -31,7 +31,7 @@ import { import { AGENTS_SCHEMA, makeId, normalizeAgents, resolveCommand, validateForSave } from "./agents.mjs"; import { findAgent, loadAgentList } from "./agent-lookup.mjs"; import { checkDocument, cleanupFindings, readAgentsDoc, readSpecFile, removeCleanup } from "./sessions.mjs"; -import { SHOTS_DIR_NAME, SHOT_NAME, shotType } from "./patches.mjs"; +import { SHOTS_DIR_NAME, SHOT_NAME, shotType, isOpen } from "./patches.mjs"; import { appendChat, currentConversation, pendingChatCount, typedCount } from "./inbox.mjs"; import { specKey } from "./workspace.mjs"; import { readLoopSetup, saveLoopSetup } from "./loop-setup.mjs"; @@ -1395,9 +1395,15 @@ function recordSubmitted(state, actions) { // written, so a question asked in a note vanished once it was picked up // and the reply under it answered nothing on the page. A request for // suggestions is always written, note or not. - if (item.sentNote.text.trim() || item.sentNote.images.length || item.sentNote.files.length || item.sentNote.suggest) { + const hasNote = Boolean(item.sentNote.text.trim() || item.sentNote.images.length || item.sentNote.files.length); + if (hasNote || item.sentNote.suggest) { item.thread = [...(Array.isArray(item.thread) ? item.thread : []), { who: "user", ...item.sentNote }]; } + // A note on a question still open marks it `noted`: the agent has to deal + // with the question before it can ask another. A request for suggestions + // is not a note on the question, and an empty comment leaves nothing in + // the thread to deal with. + if (isOpen(item) && hasNote && action.suggest !== true) item.noted = true; continue; } const { i, type, ...rest } = action;