From a90fb8647c1c5838727bc406190b0a806157473f Mon Sep 17 00:00:00 2001 From: Justin Parker Date: Sun, 15 Nov 2026 14:58:02 -0800 Subject: [PATCH] Size the Lessons modal like the Notebook and offer suggestions on the Lessons card AI Assisted --- .plan2code/lessons/general.md | 17 ++++++++ CHANGELOG.md | 2 + scripts/test-web-console-page-ask.mjs | 5 ++- scripts/test-web-console-page-learning.mjs | 22 ++++++++++ src/web-console/public/screens/ask.js | 2 +- .../public/screens/learning-row.js | 41 +++++++++++++++++-- src/web-console/public/styles/learning.css | 11 +++-- 7 files changed, 91 insertions(+), 9 deletions(-) diff --git a/.plan2code/lessons/general.md b/.plan2code/lessons/general.md index f489f3d..d21d7a4 100644 --- a/.plan2code/lessons/general.md +++ b/.plan2code/lessons/general.md @@ -1,10 +1,27 @@ # General +### A new dialog wider than 440px needs max-width: none next to its width, sized like the Notebook dialog (min(1200px, 90vw)); the base .modal caps every dialog at 440px, so a width alone has no effect. +- Kind: correction +- About: src/web-console/public/styles/learning.css, src/web-console/public/styles/pieces.css +- Why: The Lessons dialog declared width: min(720px, ...) without max-width: none and rendered about 440px wide. +- Noted: 2026-11-15, quick-task + ### A new file under src/web-console/ needs a row in the AGENTS-architecture console files tables; run scripts/test-web-console-shape.mjs after adding one, since it fails until the row exists. - Kind: convention - About: scripts/test-web-console-shape.mjs, .agents-docs/AGENTS-architecture-console-page.md - Noted: 2026-11-14, implement-review +### In a node:test file, start fixtures such as a test server in a root before hook, never with a top-level await after the first test(), which lets the runner run after hooks early +- Kind: correction +- About: scripts/test-script-deps.mjs +- Why: test-script-deps.mjs awaited its server mid-file and 7 tests failed on Ubuntu and macOS CI only. +- Noted: 2026-11-15, Failure log + +### The launcher's prompts each open a new readline on stdin, so a test piping several answers at once loses all but the first; drive a multi-prompt flow by writing each answer after a short delay. +- Kind: how-it-works +- About: src/launcher/plan2code.js +- Noted: 2026-11-15, implement-review + ### When a card in src/plan2code-deps.md changes (what it lists or asks), change the same card in src/web-console/notes/deps.md in the same edit: the console builds the card from the notes. - Kind: correction - About: src/plan2code-deps.md, src/web-console/notes/deps.md diff --git a/CHANGELOG.md b/CHANGELOG.md index 0211c96..9138889 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ All notable changes to Plan2Code will be documented in this file. - **web console**: a swaying question mark beside Ask for suggestions, and a chevron before Send. - **Snake**: lives, bonus lives at score marks, and three bosses (Grumpy Golem, Comet Queen, Thunder Toad). - **Bounce Road**: four new music tracks and extras. +- **web console**: Ask for suggestions is on the Lessons to keep card, in the Notes panel and in the Lessons modal, where the reply shows in a Suggestions box. ### 🔧 Changed @@ -28,6 +29,7 @@ All notable changes to Plan2Code will be documented in this file. ### 🐛 Fixed - **Quick Task**: a finish that offers the review again after a review already ran in that launch is refused. +- **web console**: the Lessons modal is as wide as the Notebook (it was stuck at the 440px default). ## v3.0.6 diff --git a/scripts/test-web-console-page-ask.mjs b/scripts/test-web-console-page-ask.mjs index 2b95c97..cc8a93d 100644 --- a/scripts/test-web-console-page-ask.mjs +++ b/scripts/test-web-console-page-ask.mjs @@ -392,7 +392,7 @@ const chipOf = (s) => s.page.locator("#aside").getByRole("button", { name: "Ask // What a person sees break: the chip on a card where there is nothing to pick, // on a settled record, or missing where they are unsure what to pick. -test("the Ask for suggestions chip shows on open choice, multi and confirm cards only", async (t) => { +test("the Ask for suggestions chip shows on open choice, multi, confirm and lessons cards only", async (t) => { const s = await openSession(await suite.browser(), { t, workflow: "plan", @@ -401,13 +401,14 @@ test("the Ask for suggestions chip shows on open choice, multi and confirm cards { id: "c1", kind: "choice", title: "Export format", body: "Which format?", options: [opt("A", "CSV"), opt("B", "JSON")] }, { id: "m1", kind: "multi", title: "Columns", body: "Which?", options: [opt("1", "Date"), opt("2", "User")] }, { id: "y1", kind: "confirm", title: "Keep going", body: "Carry on?" }, + { id: "l1", kind: "lessons", title: "Lessons to keep", body: "Choose for each one.", required: false, rows: [{ id: "r1", type: "lesson", text: "A lesson.", why: "", origin: "You said this.", note: "", flags: [], refused: null, area: "General", kind: "convention", about: ["a.js"], areas: ["General"], choices: ["Keep", "Reword", "Drop"] }] }, { id: "t1", kind: "text", title: "What to call it", body: "A name.", required: false }, { id: "d1", kind: "choice", title: "Old pick", body: "Which?", options: [opt("A", "CSV"), opt("B", "JSON")], status: "answered", answer: { k: "B" } }, ], agent: { status: "waiting" }, }, }); - for (const [id, title, shown] of [["c1", "Export format", 1], ["m1", "Columns", 1], ["y1", "Keep going", 1], ["t1", "What to call it", 0], ["d1", "Old pick", 0]]) { + for (const [id, title, shown] of [["c1", "Export format", 1], ["m1", "Columns", 1], ["y1", "Keep going", 1], ["l1", "Lessons to keep", 1], ["t1", "What to call it", 0], ["d1", "Old pick", 0]]) { await goTo(s, id, title); assert.equal(await chipOf(s).count(), shown, `chip on ${id}`); if (shown) assert.equal(await textOf(chipOf(s)), "Ask for suggestions"); diff --git a/scripts/test-web-console-page-learning.mjs b/scripts/test-web-console-page-learning.mjs index 093407e..d3f4fa3 100644 --- a/scripts/test-web-console-page-learning.mjs +++ b/scripts/test-web-console-page-learning.mjs @@ -517,6 +517,28 @@ test("lessons card: Not now and the corner close leave every lesson waiting and } }); +test("lessons card: the dialog has Ask for suggestions, which sends one request and shows the reply in a Suggestions box", async (t) => { + const { s, dlg } = await reviewOpen(t); + s.wait(10); + postCard(s); + await dlg.locator(".lessons-row").waitFor(); + const ask = dlg.getByRole("button", { name: "Ask for suggestions" }); + assert.equal(await ask.isDisabled(), false); + assert.equal(await dlg.locator(".lessons-suggestions").count(), 0, "nothing asked yet"); + await ask.click(); + const got = s.wait(10); + assert.equal(got.code, 0); + const sentAction = got.actions.find((a) => a.suggest === true); + assert.ok(sentAction, JSON.stringify(got.actions)); + assert.equal(sentAction.i, "lessons"); + assert.match(got.reply, /^Suggestions wanted on Lessons to keep:/m); + await dlg.locator(".lessons-suggestions", { hasText: "Asking Plan2Code" }).waitFor(); + assert.equal(await dlg.getByRole("button", { name: "Ask for suggestions" }).isDisabled(), true, "one request waits at a time"); + assert.equal(await dlg.getByRole("button", { name: "Keep" }).count(), 1, "the lessons stay open to choose"); + s.post({ items: [{ id: "lessons", thread: [{ who: "agent", text: "1. Keep it: a real trap." }] }], agent: { status: "waiting" } }); + await dlg.locator(".lessons-suggestions", { hasText: "Keep it: a real trap." }).waitFor(); +}); + test("lessons card: closing with choices made asks first, and Keep editing goes back", async (t) => { const { s, dlg } = await reviewOpen(t); s.wait(10); diff --git a/src/web-console/public/screens/ask.js b/src/web-console/public/screens/ask.js index 5896375..ad89516 100644 --- a/src/web-console/public/screens/ask.js +++ b/src/web-console/public/screens/ask.js @@ -834,7 +834,7 @@ export function renderAside() { // The cards with options to pick from, where asking what Plan2Code would pick // makes sense. -const SUGGEST_KINDS = ["choice", "multi", "confirm"]; +const SUGGEST_KINDS = ["choice", "multi", "confirm", "lessons"]; // Ask for suggestions: its own send, beside the main one (core.js). Focus // stays in the panel: on the chip when it is live again, else the note box. diff --git a/src/web-console/public/screens/learning-row.js b/src/web-console/public/screens/learning-row.js index ad17238..319a08a 100644 --- a/src/web-console/public/screens/learning-row.js +++ b/src/web-console/public/screens/learning-row.js @@ -10,9 +10,10 @@ // and is disabled whenever a card would be. import { page, redraw, hooks, stage } from "../state.js"; -import { el, mdInto, lightDismiss } from "../render.js"; +import { el, md, mdInto, lightDismiss } from "../render.js"; import { postJson } from "../net.js"; -import { sendState } from "../send-state.js"; +import { sendState, suggestState } from "../send-state.js"; +import { threadWho, threadText } from "../answers.js"; import { loopDriving, isOpen, stagedCount, learningBusyNow } from "../selectors.js"; const TOP_STATES = new Set(["not-set-up", "off", "paused"]); @@ -345,6 +346,17 @@ export function renderLessonsDialog(on) { ask.appendChild(row); actions.appendChild(ask); } else { + const suggest = suggestionsBox(item); + if (suggest) actions.appendChild(suggest); + // The Notes panel is not on this dialog, so its Ask for suggestions chip + // is here: the same request, answered in the Suggestions box above. + const st = suggestState(item); + const ask = el("button", "btn ghost", "Ask for suggestions"); + ask.type = "button"; + ask.id = "lessons-suggest"; + ask.disabled = saving || st.disabled; + ask.title = st.why || ""; + ask.addEventListener("click", () => hooks.askSuggestions(item.id)); const later = el("button", "btn ghost", "Not now"); later.type = "button"; later.id = "lessons-later"; @@ -356,7 +368,7 @@ export function renderLessonsDialog(on) { if (saving) go.appendChild(spinnerLabel("Saving…")); else go.textContent = "Save lessons"; go.addEventListener("click", () => saveLessons(item)); - actions.append(later, go); + actions.append(ask, later, go); if (stagedCount() > 1) actions.appendChild(el("p", "help", "Anything else ready to send goes with it.")); } dlg.replaceChildren(card, actions, x); @@ -365,6 +377,29 @@ export function renderLessonsDialog(on) { dlg.scrollTop = scroll; } +/** + * The Suggestions box above the dialog's buttons: "Asking Plan2Code…" while a + * request waits, then the agent's latest reply in the card's thread after the + * last request. Null when nothing was asked. + */ +function suggestionsBox(item) { + const thread = Array.isArray(item.thread) ? item.thread : []; + let asked = -1; + thread.forEach((m, i) => { + if (m && m.suggest === true && threadWho(m) === "user") asked = i; + }); + const waiting = item.sentNote && item.sentNote.suggest === true && !thread.slice(asked + 1).some((m) => threadWho(m) === "agent"); + const reply = asked >= 0 ? thread.slice(asked + 1).filter((m) => threadWho(m) === "agent").pop() : null; + if (!waiting && !reply) return null; + const box = el("div", "lessons-suggestions"); + box.id = "lessons-suggestions"; + box.setAttribute("role", "status"); + box.appendChild(el("h3", null, "Suggestions")); + if (reply && !waiting) box.appendChild(md(threadText(reply), "md")); + else box.appendChild(el("p", "help", "Asking Plan2Code. Its answer shows here.")); + return box; +} + /** * The dialog's Save lessons, set again whenever what is staged changes, * including the quiet staging of typing (a Reword field emptied, a note): on diff --git a/src/web-console/public/styles/learning.css b/src/web-console/public/styles/learning.css index 6c95714..ce72234 100644 --- a/src/web-console/public/styles/learning.css +++ b/src/web-console/public/styles/learning.css @@ -193,14 +193,19 @@ .lessons-first-about { margin: 12px 0 0; } .lessons-later { margin-top: 8px; } -/* Review from the dashboard: the same card in a dialog over the menu. */ -.modal.lessons-dialog { width: min(720px, calc(100vw - 32px)); } -.lessons-dialog .card { margin: 0; box-shadow: none; border: 0; padding: 0; } +/* Review from the dashboard: the same card in a dialog over the menu. Sized + like the Notebook dialog; max-width: none lifts the base .modal 440px cap. */ +.modal.lessons-dialog { width: min(1200px, 90vw); max-width: none; } +.lessons-dialog .card { margin: 0; box-shadow: none; border: 0; padding: 0; max-width: none; } /* The lessons dialog: closable (the corner ×, Not now, Escape), and locked while Save lessons goes. */ .lessons-dialog .modal-actions { align-items: center; justify-content: flex-end; } .lessons-dialog .modal-actions .btn { margin: 0; } +.lessons-suggestions { flex: 1 1 100%; padding: 10px 14px; border-left: 4px solid var(--accent); background: var(--accent-soft); border-radius: calc(var(--radius) * 0.5); } +.lessons-suggestions h3 { margin: 0 0 6px; font-size: 13.5px; } +.lessons-suggestions .md { max-height: 40vh; overflow: auto; font-size: 13.5px; } +.lessons-dialog .modal-actions { flex-wrap: wrap; } .lessons-dialog .modal-actions .btn .spinner { margin-right: 8px; } .modal-x { position: absolute;