diff --git a/.agents-docs/AGENTS-architecture-console-page.md b/.agents-docs/AGENTS-architecture-console-page.md index 03dac2f..be2bae5 100644 --- a/.agents-docs/AGENTS-architecture-console-page.md +++ b/.agents-docs/AGENTS-architecture-console-page.md @@ -27,7 +27,7 @@ One row per file under `src/web-console/public/` (the games and their sound are | `public/state.js` | the page's shared state (`page.S` the server's truth, `page.local` what is staged) and the `redraw()` / save hooks every screen calls; defines only | | `public/uploads.js` | pictures and documents attached to a note: chips, trays, re-encoding, upload, retry, and the page's shared full-screen picture preview (`openPicview`, the `#picview` dialog every thumbnail opens) | | `public/screens/ask.js` | the Ask chat, the Subagents tab, and attaching files to notes | -| `public/screens/cards.js` | question cards: every kind (one builder per kind in `BUILDERS`), the pager, settled and in-flight records. The `lessons` kind's builder is `buildLessons()`: the approval card for noted lessons, one row per waiting item (`lessonRow()`) decided on its own with the words its type takes, the choices kept as a draft (`lessons-`) until Send, or the first ask's three answers when the card carries `firstAsk`; on the dashboard it is drawn in the Lessons to review dialog (`renderLessonsDialog()` in `screens/learning-row.js`). A `multi` option may carry `ticked: true` (the row starts ticked the first time the card shows, never on a `locked` row) and `tag` (1 to 16 characters, drawn as a neutral `.pill.tag` beside the label and read in the checkbox's accessible name after the `k: text`); on a card with a ticked row, unticking the last box (or pressing a lit preset off) stages `ks: []`, an answer that reads `none`, where other cards stage nothing. | +| `public/screens/cards.js` | question cards: every kind (one builder per kind in `BUILDERS`), the pager, settled and in-flight records. The `lessons` kind's builder is `buildLessons()`: the approval card for noted lessons, one row per waiting item (`lessonRow()`) decided on its own with the words its type takes, the choices kept as a draft (`lessons-`) until Send, or the first ask's three answers when the card carries `firstAsk`; a `suggested` map (row id to one of that row's choices, checked in `lessonsProblems()` in `patches.mjs`) draws a dashed `is-suggested` ring on those buttons without picking them; on the dashboard it is drawn in the Lessons to review dialog (`renderLessonsDialog()` in `screens/learning-row.js`). A `multi` option may carry `ticked: true` (the row starts ticked the first time the card shows, never on a `locked` row) and `tag` (1 to 16 characters, drawn as a neutral `.pill.tag` beside the label and read in the checkbox's accessible name after the `k: text`); on a card with a ticked row, unticking the last box (or pressing a lit preset off) stages `ks: []`, an answer that reads `none`, where other cards stage nothing. | | `public/screens/cleanup.js` | User Preferences' Cleanup section, on the System tab | | `public/screens/core.js` | the core every screen sits inside: connection, the render loop, the page chrome and Send; the only file that imports the screens, and only `app.js` imports it | | `public/screens/dashboard.js` | the dashboard: cards, the spec picker, handoff chips, delete, the first-open wake-up, and Learning's waiting banner (`learningBanner()`: the line from `learningBannerText()` and a **Review** button sending `__learning` `review`, last of the banners), which places Learning's row through `hooks.renderLearningRow` | diff --git a/.readme/web-console.md b/.readme/web-console.md index cc9a527..5bb33bf 100644 --- a/.readme/web-console.md +++ b/.readme/web-console.md @@ -73,7 +73,7 @@ Scroll down for the utilities. Outside a git repository the **Git** card says so ## What you get - **Every question laid out**, with the trade-offs next to each option, a progress bar ("4 of 9 settled") and Previous and Next under each card. -- **Help with the answer.** An *Autofill suggestion* button puts an example in the box for you to edit, and *Ask for suggestions* in the notes panel asks Plan2Code what it would pick and why. Some pick lists open with the suggestion already ticked; an empty pick is an answer too. +- **Help with the answer.** An *Autofill suggestion* button puts an example in the box for you to edit, and *Ask for suggestions* in the notes panel asks Plan2Code what it would pick and why (on the lessons card, its pick for each lesson is outlined with a dashed ring, never chosen for you). Some pick lists open with the suggestion already ticked; an empty pick is an answer too. - **Settled answers read as answers**: what you chose, in words, with the rest locked. A question you have sent is held until Plan2Code answers it, and the page carries on working meanwhile. - **Nothing is sent until you press Send**, and nothing gets lost: close the tab, reload, restart the machine, and your half-typed answers are still there. diff --git a/CHANGELOG.md b/CHANGELOG.md index cb88772..9cd4dda 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ All notable changes to Plan2Code will be documented in this file. - **desktop app**: Update and restart in the top bar installs the newest release with live progress and reopens on the same project, asking first when an agent or a loop is running. - **desktop app**: the window remembers its size and place, and the terminal gets a right-click menu, copy on select, font size keys and clickable links; new keyboard shortcuts work from both panes. - **docs**: a SECURITY.md for private vulnerability reports, and the issue form links to the docs, the desktop app guide and security. +- **Learning**: Ask for suggestions on the lessons review now outlines the suggested choice on each lesson (Keep, Drop and the rest) with a dashed ring, without choosing it for you. ### šŸ”§ Changed @@ -22,6 +23,7 @@ All notable changes to Plan2Code will be documented in this file. - **installer**: plainer output, with no colors or boxes when piped (`NO_COLOR` is honored), a spinner while the skills install, the exact PATH line for your shell when the command is not found, and a clear stop on Node.js older than 18. - **web console**: a broad visual refresh (spacing, type, shadow and motion tokens, shared top-bar icons); "Helpers" is now "Subagents" everywhere, and the meter says "Conversation". - **web console**: Clear acts at once with a 10-second Undo, the finish screen shows one main button, Help groups its topics with a filter and opens with `?`, and Cleanup shows what it will delete and its size. +- **Learning**: the lessons review keeps Ask for suggestions, Not now and Save lessons pinned to the bottom of the dialog, shows a spinner while suggestions are on the way, and lets the answer use the dialog's full width. - **desktop app**: its own confirm dialogs (Cancel first and focused), plain-language errors with the details underneath, the console's theme from the first paint, and a top bar that folds extra buttons into a "+N more" menu. - **UI Prototype**: the carry-over card opens ticked as suggested, each item tagged Keep or Free up with its reason. - **docs**: the README is rewritten and shorter, the long guides moved into `.readme/`, the site hosts its own fonts and has a social card, and the screenshots are refreshed (Notepad is now Notebook). diff --git a/scripts/test-web-console-logic.mjs b/scripts/test-web-console-logic.mjs index 7585715..e63cb9e 100644 --- a/scripts/test-web-console-logic.mjs +++ b/scripts/test-web-console-logic.mjs @@ -1692,6 +1692,13 @@ test("validate: a lessons item takes rows each with a type and its own choices, refused({ rows: [row({ selected: true })] }, 'row "w1" selected: is not allowed'); refused({ firstAsk: { ...firstAsk, sentences: ["a", "b"] } }, "firstAsk"); + // Suggestions: one of each row's own words, for rows the card has; never a choice. + assert.deepEqual(one({ rows: [row(), row({ id: "w2" })], suggested: { w1: "Keep", w2: "Drop" } }), [], "a suggestion per row"); + assert.deepEqual(one({ rows: [row()], suggested: null }), [], "cleared"); + refused({ rows: [row()], suggested: ["Keep"] }, "suggested: must be"); + refused({ rows: [row()], suggested: { w9: "Keep" } }, 'suggested "w9"'); + refused({ rows: [row()], suggested: { w1: "Apply" } }, 'suggested "w1"'); + const two = validate({ items: [item({ rows: [row()] }), item({ id: "lessons-2", rows: [row()] })] }); assert.ok(two.some((p) => p.includes("2 lessons cards are open at once")), two.join(" | ")); const answered = validate({ items: [item({ rows: [row()], status: "answered" }), item({ id: "lessons-2", rows: [row()] })] }); diff --git a/scripts/test-web-console-page-learning.mjs b/scripts/test-web-console-page-learning.mjs index df5b014..18c55ba 100644 --- a/scripts/test-web-console-page-learning.mjs +++ b/scripts/test-web-console-page-learning.mjs @@ -11,7 +11,7 @@ import test from "node:test"; import assert from "node:assert/strict"; -import { pageSuite, openSession, tempProject, textOf, styleOf, stylesOf, itemCard, sendAndCollect, settled } from "./page-test-helpers.mjs"; +import { pageSuite, openSession, tempProject, textOf, styleOf, stylesOf, itemCard, sendAndCollect, settled, scrollCard } from "./page-test-helpers.mjs"; import { cli, until } from "./web-console-test-helpers.mjs"; import { writePause, writeWaiting } from "../src/web-console/learning.mjs"; @@ -540,12 +540,90 @@ test("lessons card: the dialog has Ask for suggestions, which sends one request 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: "Asking…" }).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: Ask for suggestions spins until the reply lands, and the reply is as wide as its box", async (t) => { + const { s, dlg } = await reviewOpen(t); + s.wait(10); + postCard(s); + await dlg.locator(".lessons-row").waitFor(); + await dlg.getByRole("button", { name: "Ask for suggestions" }).click(); + s.wait(10); + await dlg.locator("#lessons-suggest .spinner").waitFor(); + await dlg.locator(".lessons-suggestions .spinner").waitFor(); + const long = "My suggestion is Keep. " + "It is a real trap that a full run hides, and the docs never say so. ".repeat(6); + s.post({ items: [{ id: "lessons", thread: [{ who: "agent", text: long }] }], agent: { status: "waiting" } }); + const reply = dlg.locator(".lessons-suggestions .md"); + await reply.waitFor(); + assert.equal(await dlg.locator(".spinner").count(), 0, "no spinner once the reply is in"); + const box = await dlg.locator(".lessons-suggestions").boundingBox(); + const text = await reply.boundingBox(); + assert.ok(text.width > box.width * 0.85, `the reply fills its box: ${text.width} of ${box.width}`); +}); + +test("lessons card: the dialog's buttons stay in view while the lessons scroll", async (t) => { + const { s, dlg } = await reviewOpen(t); + s.wait(10); + const rows = Array.from({ length: 10 }, (_, i) => ({ ...ROWS[0], id: `${LESSON_ID}-${i}`, text: `Lesson number ${i + 1}, long enough to take a line.` })); + s.post({ items: [CARD(rows)], agent: { status: "waiting" } }); + await dlg.locator(".lessons-row").first().waitFor(); + const overflows = await dlg.evaluate((d) => d.scrollHeight > d.clientHeight + 40); + assert.ok(overflows, "the dialog scrolls with ten lessons"); + for (const top of [0, 300]) { + await scrollCard(dlg, top); + const frame = await dlg.boundingBox(); + const ask = await dlg.getByRole("button", { name: "Ask for suggestions" }).boundingBox(); + assert.ok(ask.y >= frame.y && ask.y + ask.height <= frame.y + frame.height + 1, `scrolled to ${top}: Ask for suggestions is in view`); + const bar = await dlg.locator(":scope > .modal-actions").boundingBox(); + assert.ok(bar.y + bar.height >= frame.y + frame.height - 2, `scrolled to ${top}: the bar reaches the dialog's bottom edge, with nothing showing under it`); + } + // A reply is scrolled into view once; a later state push leaves the scroll where the person put it. + await dlg.getByRole("button", { name: "Ask for suggestions" }).click(); + s.wait(10); + s.post({ items: [{ id: "lessons", thread: [{ who: "agent", text: "Keep them all." }] }], agent: { status: "waiting" } }); + await dlg.locator(".lessons-suggestions", { hasText: "Keep them all." }).waitFor(); + await until(async () => (await dlg.evaluate((d) => d.scrollTop)) > 0, 3000); + await scrollCard(dlg, 0); + s.post({ agent: { status: "waiting", activity: "Still here" } }); + s.post({ headline: { stage: "Reviewing lessons" }, agent: { status: "waiting" } }); + await settled(s.page, "#lessons-modal"); + assert.equal(await dlg.evaluate((d) => d.scrollTop), 0, "no pull back down to the reply"); +}); + +test("lessons card: a suggestion outlines its button on each lesson without choosing it", async (t) => { + const { s, dlg } = await reviewOpen(t); + s.wait(10); + const second = `${LESSON_ID}-b`; + s.post({ items: [CARD([{ ...ROWS[0], id: LESSON_ID }, { ...ROWS[0], id: second, text: "Another lesson." }])], agent: { status: "waiting" } }); + await dlg.locator(".lessons-row").first().waitFor(); + await dlg.getByRole("button", { name: "Ask for suggestions" }).click(); + s.wait(10); + s.post({ items: [{ id: "lessons", suggested: { [LESSON_ID]: "Keep", [second]: "Drop" }, thread: [{ who: "agent", text: "Keep the first, drop the second." }] }], agent: { status: "waiting" } }); + await dlg.locator(".lessons-suggestions", { hasText: "Keep the first" }).waitFor(); + const keep = dlg.locator(`.lessons-row[data-row="${LESSON_ID}"] .lessons-choices button`, { hasText: "Keep" }); + const drop = dlg.locator(`.lessons-row[data-row="${second}"] .lessons-choices button`, { hasText: "Drop" }); + for (const b of [keep, drop]) { + await b.and(s.page.locator(".is-suggested")).waitFor(); + assert.equal(await b.getAttribute("aria-pressed"), "false", "a suggestion is not a choice"); + assert.notEqual(await styleOf(b, "outlineStyle"), "none", "outlined"); + assert.match(await b.getAttribute("title"), /Suggested/); + } + assert.equal(await dlg.locator(".lessons-choices .is-suggested").count(), 2, "only the suggested buttons"); + assert.equal(await dlg.getByRole("button", { name: "Save lessons" }).isDisabled(), true, "nothing chosen for the person"); + // Keyboard focus on a suggested button shows the solid focus ring, not the dashed hint. + await dlg.locator(`.lessons-row[data-row="${second}"] .lessons-choices button`, { hasText: "Reword" }).focus(); + await s.page.keyboard.press("Tab"); + await drop.and(s.page.locator(":focus")).waitFor(); + assert.equal(await styleOf(drop, "outlineStyle"), "solid", "focused: the focus ring"); + // Choosing the suggestion keeps the mark. + await keep.click(); + await dlg.locator(`.lessons-row[data-row="${LESSON_ID}"] button.is-suggested[aria-pressed="true"]`).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/shared-references/lessons.md b/src/shared-references/lessons.md index dd1b07c..2b5a505 100644 --- a/src/shared-references/lessons.md +++ b/src/shared-references/lessons.md @@ -59,7 +59,7 @@ The seven noting skills only (and any skill sent here by Start's Review now), be 2. `items` empty and no `firstAsk`: say nothing and skip this step. 3. `firstAsk` present: see The first ask below, instead of 4 to 7. 4. Show `opening` first when present. -5. **On the web console:** post the returned `card` as one `lessons` item with `--wait` (a new `id` when an earlier lessons card is in the session). Its reply has one line per decision ("Keep: ...", "Reword: ...") and a `Decisions:` line holding them as JSON: that JSON is step 6's file, plus what a choice still needs. **In a terminal:** ask each group in `rounds` with your question tool, one question per item with exactly its `choices` and nothing pre-selected (`heading`, `text`, `why`, `origin` and `note` are what the person reads; an area shows its `name` and `paths`); with no question tool, a numbered list. A choice that needs more (step 6) asks the person for it. +5. **On the web console:** post the returned `card` as one `lessons` item with `--wait` (a new `id` when an earlier lessons card is in the session). Its reply has one line per decision ("Keep: ...", "Reword: ...") and a `Decisions:` line holding them as JSON: that JSON is step 6's file, plus what a choice still needs. A `Suggestions wanted on` line for it: reply in its `thread` and, in the same patch, send `suggested` (row id to one of that row's `choices`, such as `{"w1":"Keep"}`), which outlines those buttons without choosing them. **In a terminal:** ask each group in `rounds` with your question tool, one question per item with exactly its `choices` and nothing pre-selected (`heading`, `text`, `why`, `origin` and `note` are what the person reads; an area shows its `name` and `paths`); with no question tool, a numbered list. A choice that needs more (step 6) asks the person for it. 6. Write the decisions, one `{ "id", "choice" }` per answered item plus what its choice needs, to a JSON file in the console session folder, or the OS temp folder in a terminal, never in the project. Run `decide --file ` and print its `closing` line, such as "Kept 2 (1 reworded), retired 1. 1 still waiting." What a choice needs: - Reword of a lesson, a doubt or a lesson whose files are gone: the new `text`, plus `why`, `kind`, `about` or `area` when they change. - Rename of an area: the new `name`, plus `paths` when they change. diff --git a/src/web-console/console.md b/src/web-console/console.md index 4ee0017..ac12365 100644 --- a/src/web-console/console.md +++ b/src/web-console/console.md @@ -65,7 +65,7 @@ Every item: `id` (new for each question, whole session), `kind`, `title` (2 to 4 | `review` | read, then approve | `doc` (required), `summary`, `verdicts:[{id,label,danger?}]`, `nothingYet` (false once the change is on disk) | `{verdict,text?}` | | `checklist` | steps only they can do | `steps`, `valuesLabel` | `{done?,state?,text?}` | | `list` | reorder or edit a breakdown | `rows:[{id,title,body}]` | `{rows}` or `{text}` | -| `lessons` | approve noted lessons | `rows`, `opening`, `firstAsk` (from `lessons.mjs list`) | `{decisions}` or `{firstAsk}` | +| `lessons` | approve noted lessons | `rows`, `opening`, `firstAsk` (from `lessons.mjs list`), `suggested` (row id to a choice: outlined, not picked) | `{decisions}` or `{firstAsk}` | | `notice` | read, no answer | none | none | Items show in the order sent, so send them in answering order. diff --git a/src/web-console/patches.mjs b/src/web-console/patches.mjs index fb60fd3..54df212 100644 --- a/src/web-console/patches.mjs +++ b/src/web-console/patches.mjs @@ -924,6 +924,22 @@ function lessonsProblems(item, at) { problems.push(rule(at, `${name} refused`, "must be the { pattern, part } lessons.mjs gave, or null", { refused: { pattern: "aws-access-key", part: "AKIA" } })); } }); + // The agent's answer to Ask for suggestions, readable by the page: row id to + // one of that row's own choice words. It outlines a button; it never picks. + const sug = item.suggested; + const SUGGESTED_RIGHT = { suggested: { w1: "Keep", w2: "Drop" } }; + if (sug != null && !isPlainObject(sug)) { + problems.push(rule(at, "suggested", "must be an object of row id to one of that row's choice words, or null", SUGGESTED_RIGHT)); + } else if (sug != null) { + const byId = new Map((hasRows ? item.rows : []).filter(isPlainObject).map((r) => [r.id, r])); + for (const [id, word] of Object.entries(sug)) { + const row = byId.get(id); + if (!row) problems.push(rule(at, `suggested "${id}"`, "names no row on this card. Use the row ids the card was posted with", SUGGESTED_RIGHT)); + else if (typeof word !== "string" || !(row.choices || []).includes(word)) { + problems.push(rule(at, `suggested "${id}"`, `must be one of that row's choices (${(row.choices || []).join(", ")})`, SUGGESTED_RIGHT)); + } + } + } return problems; } diff --git a/src/web-console/public/screens/cards.js b/src/web-console/public/screens/cards.js index f1e1bd8..af51a7d 100644 --- a/src/web-console/public/screens/cards.js +++ b/src/web-console/public/screens/cards.js @@ -1905,12 +1905,20 @@ function lessonRow(item, row, draft, commit) { const group = el("div", "lessons-choices"); group.setAttribute("role", "group"); group.setAttribute("aria-label", "Choices for: " + (row.text || row.id)); + // The agent's suggestion (Ask for suggestions) outlines its word; it is + // never a pick, so nothing is chosen for the person. + const suggested = item.suggested && typeof item.suggested === "object" ? item.suggested[row.id] : null; choices.forEach((word, i) => { const on = pick === word; - const b = el("button", "btn sm" + (on ? " primary" : ""), word); + const hint = suggested === word; + const b = el("button", "btn sm" + (on ? " primary" : "") + (hint ? " is-suggested" : ""), word); b.type = "button"; b.id = `lesson-${item.id}-${row.id}-${i}`; b.setAttribute("aria-pressed", String(on)); + if (hint) { + b.title = "Suggested by Plan2Code"; + b.setAttribute("aria-description", "Suggested"); + } if (row.refused && word === keepWord && !reworded) { b.disabled = true; b.title = "Reword it first: part of it was refused."; diff --git a/src/web-console/public/screens/learning-row.js b/src/web-console/public/screens/learning-row.js index 0bc6d56..dfcf98c 100644 --- a/src/web-console/public/screens/learning-row.js +++ b/src/web-console/public/screens/learning-row.js @@ -201,6 +201,12 @@ function wireOutside() { // was asked for while something is chosen. let saving = false; let askingClose = false; +// Ask for suggestions pressed and its send still in flight: the button spins +// from the press, before the card's thread shows the request. +let asking = false; +// The key of the agent reply last shown in the Suggestions box, so a new one is scrolled +// into view once and not again on every redraw. +let shownReply = null; // The card the dialog shows now, for the handlers made once with the dialog. let shownItem = null; @@ -348,17 +354,29 @@ 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"); + const ask = el("button", "btn ghost"); ask.type = "button"; ask.id = "lessons-suggest"; - ask.disabled = saving || st.disabled; + if (asking || suggestWaiting(item)) { + ask.classList.add("is-asking"); + ask.appendChild(spinnerLabel("Asking…")); + } else ask.textContent = "Ask for suggestions"; + ask.disabled = saving || asking || st.disabled; ask.title = st.why || ""; - ask.addEventListener("click", () => hooks.askSuggestions(item.id)); + ask.addEventListener("click", async () => { + if (asking) return; + asking = true; + redraw(); + try { + await hooks.askSuggestions(item.id); + } finally { + asking = false; + redraw(); + } + }); const later = el("button", "btn ghost", "Not now"); later.type = "button"; later.id = "lessons-later"; @@ -373,32 +391,66 @@ export function renderLessonsDialog(on) { 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); + // The Suggestions box sits in the scrolling body, after the card, so the + // button bar below it can stay pinned to the dialog's bottom edge. + const suggest = askingClose && !saving ? null : suggestionsBox(item); + dlg.replaceChildren(...[card, suggest, actions, x].filter(Boolean)); refreshLessonsSend(); if (!dlg.open) dlg.showModal(); dlg.scrollTop = scroll; + // A new answer lands below the lessons: bring it into view once. + const reply = suggest && !suggestWaiting(item) ? suggestReply(item) : null; + // Keyed on what the reply says: every state push parses fresh objects, so + // the same reply is a new object each time. + const replyKey = reply ? `${item.id}|${reply.at || ""}|${threadText(reply)}` : null; + if (replyKey && replyKey !== shownReply) { + shownReply = replyKey; + suggest.scrollIntoView({ block: "nearest" }); + } } -/** - * 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) { +/** Where the last request for suggestions sits in the card's thread, and the thread. */ +function lastAsk(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; + return { thread, asked }; +} + +/** A request for suggestions sent and not answered yet. */ +function suggestWaiting(item) { + const { thread, asked } = lastAsk(item); + return Boolean(item.sentNote && item.sentNote.suggest === true && !thread.slice(asked + 1).some((m) => threadWho(m) === "agent")); +} + +/** The agent's latest reply after the last request, or null. */ +function suggestReply(item) { + const { thread, asked } = lastAsk(item); + return asked >= 0 ? thread.slice(asked + 1).filter((m) => threadWho(m) === "agent").pop() || null : null; +} + +/** + * The Suggestions box above the dialog's buttons: a spinner and "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 waiting = suggestWaiting(item); + const reply = suggestReply(item); if (!waiting && !reply) return null; const box = el("div", "callout is-info lessons-suggestions"); box.id = "lessons-suggestions"; box.setAttribute("role", "status"); + box.setAttribute("aria-busy", waiting ? "true" : "false"); 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.")); + else { + const p = el("p", "help lessons-asking"); + p.appendChild(spinnerLabel("Asking Plan2Code. Its answer shows here.")); + box.appendChild(p); + } return box; } diff --git a/src/web-console/public/styles/learning.css b/src/web-console/public/styles/learning.css index ba48a77..123dedb 100644 --- a/src/web-console/public/styles/learning.css +++ b/src/web-console/public/styles/learning.css @@ -149,6 +149,11 @@ .lessons-flag, .lessons-refused { padding: 5px 9px; font-size: var(--fs-sm); } .lessons-choices { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; } +/* The agent's suggestion: a dashed accent ring, apart from focus's solid one; + it stays once the person picks that word. */ +.lessons-choices .btn.is-suggested { outline: 2px dashed var(--accent); outline-offset: 2px; } +/* Keyboard focus still shows as the page's solid focus ring. */ +.lessons-choices .btn.is-suggested:focus-visible { outline: 2px solid var(--focus); outline-offset: var(--focus-offset); } .lessons-edit { margin-top: 10px; display: grid; gap: 8px; } .lessons-field { margin: 0; } .lessons-input, @@ -173,13 +178,33 @@ .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; } -/* Closable (corner x, Not now, Escape), locked while saving. */ +/* Closable (corner x, Not now, Escape), locked while saving. The button bar + is pinned to the dialog's bottom edge while the lessons scroll under it: + the negative margins run it to the dialog's edges over its padding. */ .lessons-dialog .modal-actions { align-items: center; justify-content: flex-end; } -.lessons-suggestions { flex: 1 1 100%; } +.lessons-dialog > .modal-actions { + position: sticky; + /* Chrome sticks inside the dialog's 24px bottom padding; this reaches its edge. */ + bottom: -24px; + z-index: 1; + margin: 20px -26px -24px; + padding: 14px 26px 20px; + background: var(--panel); + border-top: 1px solid var(--rule); +} +/* After the card, in the scrolling body; the margin keeps a reply scrolled + into view clear of the pinned buttons. The page-wide .md 68ch cap is lifted + so the reply fills the box. */ +.lessons-suggestions { margin: 16px 0 0; scroll-margin-bottom: 96px; } .lessons-suggestions h3 { margin: 0 0 6px; font-size: var(--fs-md); } -.lessons-suggestions .md { max-height: 40vh; overflow: auto; font-size: var(--fs-md); } +.lessons-suggestions .md { max-width: none; max-height: 40vh; overflow: auto; font-size: var(--fs-md); } +.lessons-asking { display: inline-flex; align-items: center; gap: 8px; margin: 0; } +.lessons-asking .spinner { margin: 0; } .lessons-dialog .modal-actions { flex-wrap: wrap; } -.lessons-dialog .modal-actions .btn .spinner { margin-right: 8px; } +/* A span is inline, so the ring needs a box to show at its size in a button. */ +.lessons-dialog .modal-actions .btn .spinner { display: inline-block; vertical-align: -2px; margin-right: 8px; } +/* Asking: held, but at full strength so the spinning ring reads as working. */ +.lessons-dialog #lessons-suggest.is-asking:disabled { opacity: 1; cursor: progress; } .modal-x { position: absolute; top: 10px;