diff --git a/.agents-docs/AGENTS-architecture-console-page.md b/.agents-docs/AGENTS-architecture-console-page.md index 75d0d0e..496ac9c 100644 --- a/.agents-docs/AGENTS-architecture-console-page.md +++ b/.agents-docs/AGENTS-architecture-console-page.md @@ -28,7 +28,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`; 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/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, or `{ choice, text?, why? }` where the words go only with Reword, Reword and move or Rename; checked in `lessonsProblems()` in `patches.mjs`, read by `lessonSuggestion()` in `answers.js`) draws a dashed `is-suggested` ring on those buttons without picking them, and its words fill that row's edit boxes once the suggested edit is open (`lessonsFillSuggested()`, once per suggestion, remembered in the draft's `applied`, so later typing stays); 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/scripts/test-web-console-logic.mjs b/scripts/test-web-console-logic.mjs index 6f4e65d..7f4f949 100644 --- a/scripts/test-web-console-logic.mjs +++ b/scripts/test-web-console-logic.mjs @@ -1700,6 +1700,14 @@ test("validate: a lessons item takes rows each with a type and its own choices, refused({ rows: [row()], suggested: ["Keep"] }, "suggested: must be"); refused({ rows: [row()], suggested: { w9: "Keep" } }, 'suggested "w9"'); refused({ rows: [row()], suggested: { w1: "Apply" } }, 'suggested "w1"'); + // A Reword suggestion may carry the words its boxes start on. + assert.deepEqual(one({ rows: [row()], suggested: { w1: { choice: "Reword", text: "New words.", why: "A reason." } } }), [], "words with a Reword"); + assert.deepEqual(one({ rows: [row()], suggested: { w1: { choice: "Keep" } } }), [], "the object form without words"); + refused({ rows: [row()], suggested: { w1: { choice: "Keep", why: "A reason." } } }, 'suggested "w1" why'); + refused({ rows: [row()], suggested: { w1: { choice: "Reword", why: "" } } }, 'suggested "w1" why'); + refused({ rows: [row()], suggested: { w1: { choice: "Reword", text: 3 } } }, 'suggested "w1" text'); + refused({ rows: [row()], suggested: { w1: { choice: "Reword", note: "x" } } }, 'suggested "w1" note'); + refused({ rows: [row()], suggested: { w1: { text: "New words." } } }, '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(" | ")); diff --git a/scripts/test-web-console-page-learning.mjs b/scripts/test-web-console-page-learning.mjs index 6f3fa71..f618f37 100644 --- a/scripts/test-web-console-page-learning.mjs +++ b/scripts/test-web-console-page-learning.mjs @@ -568,6 +568,74 @@ test("lessons card: Use this wording opens Reword filled with the suggestion, an ]); }); +test("lessons card: a Reword suggestion with words fills the lesson and Why boxes, open already or opened after", async (t) => { + const second = { ...ROWS[0], id: "w-later", text: "Another lesson.", why: "An old reason." }; + const { s, card } = await lessonsCard(t, CARD([ROWS[0], second])); + const open = rowOf(card, "w-lesson"); + // Reword picked before the suggestion lands. + await open.getByRole("button", { name: "Reword" }).click(); + await open.locator(".lessons-edit").waitFor(); + s.post({ + items: [ + { + id: "lessons", + suggested: { + "w-lesson": { choice: "Reword", text: "Run one page test file alone first.", why: "A full run hides a race between page tests." }, + "w-later": { choice: "Reword", why: "The newer reason." }, + }, + }, + ], + agent: { status: "waiting" }, + }); + await open.locator(".lessons-choices button.is-suggested", { hasText: "Reword" }).waitFor(); + await until(async () => (await open.getByLabel("Why").inputValue()) === "A full run hides a race between page tests.", 3000); + assert.equal(await open.getByLabel("The lesson").inputValue(), "Run one page test file alone first.", "the lesson box takes the suggested words"); + // Reword opened after the suggestion: a suggestion without text keeps the row's own words. + const later = rowOf(card, "w-later"); + await later.getByRole("button", { name: "Reword" }).click(); + await later.locator(".lessons-edit").waitFor(); + assert.equal(await later.getByLabel("Why").inputValue(), "The newer reason."); + assert.equal(await later.getByLabel("The lesson").inputValue(), "Another lesson."); + // What the person types afterwards stays through a later push. + await open.getByLabel("Why").fill("My own reason."); + s.post({ agent: { status: "waiting", activity: "Still here" } }); + await settled(s.page, "#main"); + assert.equal(await open.getByLabel("Why").inputValue(), "My own reason.", "the suggestion is applied once, never over typing"); + const got = await sendAndCollect(s); + assert.deepEqual(got.actions.find((a) => a.i === "lessons").decisions, [ + { id: "w-lesson", choice: "Reword", text: "Run one page test file alone first.", why: "My own reason." }, + { id: "w-later", choice: "Reword", text: "Another lesson.", why: "The newer reason." }, + ]); +}); + +test("lessons card: suggested words fill an area's name without a Why, and leave a log line's several lessons whole", async (t) => { + const area = ROWS[4]; + const log = { ...ROWS[3], id: "log:two", lessons: ["Run npm run fix:eol for line endings.", "Check .gitattributes first."] }; + const { s, card } = await lessonsCard(t, CARD([area, log])); + s.post({ + items: [ + { + id: "lessons", + suggested: { + "w-area": { choice: "Rename", text: "Games", why: "Ignored: an area has no Why." }, + "log:two": { choice: "Reword and move", text: "One sentence.", why: "Line endings break the diff." }, + }, + }, + ], + agent: { status: "waiting" }, + }); + const areaRow = rowOf(card, "w-area"); + await areaRow.locator(".lessons-choices button.is-suggested", { hasText: "Rename" }).waitFor(); + await areaRow.getByRole("button", { name: "Rename" }).click(); + await until(async () => (await areaRow.getByLabel("The area's name").inputValue()) === "Games", 3000); + assert.equal(await areaRow.getByLabel("Why").count(), 0, "an area has no Why box"); + const logRow = rowOf(card, "log:two"); + await logRow.getByRole("button", { name: "Reword and move" }).click(); + await until(async () => (await logRow.getByLabel("Why").inputValue()) === "Line endings break the diff.", 3000); + assert.equal(await logRow.getByLabel("Lesson 1").inputValue(), "Run npm run fix:eol for line endings.", "the several lessons stay"); + assert.equal(await logRow.getByLabel("Lesson 2").inputValue(), "Check .gitattributes first."); +}); + test("lessons card: a flagged row says what was flagged", async (t) => { const flagged = { ...ROWS[0], id: "w-flag", flags: [{ pattern: "email", part: "a@b.c" }] }; const { card } = await lessonsCard(t, CARD([flagged])); diff --git a/src/shared-references/lessons.md b/src/shared-references/lessons.md index b88e987..dade612 100644 --- a/src/shared-references/lessons.md +++ b/src/shared-references/lessons.md @@ -69,7 +69,7 @@ The seven noting skills (and any skill sent here by Start's Review now) run it b 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. 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. Show the card's `checked` line first ("Checked 6 lessons in 40 seconds by a fresh helper that could only read", "... by the same agent that noted them", or "The check could not run: "). Read each item's `check` and `tag` into its text in this order: every Fail, then every Doubt (each as "Fail : "), then the pass line ("Passed the other N", "Passed the check" with none, and no pass line when all four found something), then its `tag` when present. A `suggestion` is offered as a Reword carrying exactly those words, which the person may adjust. 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. A Reword you suggest goes with the words you would use, `{"w2":{"choice":"Reword","text":"","why":""}}` (either may be left out): the page puts them in that row's boxes when its Reword is open, so give the same words in the thread. **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. Show the card's `checked` line first ("Checked 6 lessons in 40 seconds by a fresh helper that could only read", "... by the same agent that noted them", or "The check could not run: "). Read each item's `check` and `tag` into its text in this order: every Fail, then every Doubt (each as "Fail : "), then the pass line ("Passed the other N", "Passed the check" with none, and no pass line when all four found something), then its `tag` when present. A `suggestion` is offered as a Reword carrying exactly those words, which the person may adjust. 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/patches.mjs b/src/web-console/patches.mjs index 4308c50..339519b 100644 --- a/src/web-console/patches.mjs +++ b/src/web-console/patches.mjs @@ -872,6 +872,8 @@ export const ITEM_KINDS = new Set([ export const LESSON_ROW_TYPES = ["lesson", "doubt", "gone", "agents-fix", "tidy", "log-line", "area"]; const LESSON_ROW_TEXT = ["why", "kind", "area", "origin", "note", "before", "after", "found", "heading", "file", "name", "change", "wording", "wordingWhy"]; const LESSON_ROW_LISTS = ["about", "areas", "flags", "lessons", "paths", "targets"]; +// The choices that open a row for editing: only these take suggested words. +const SUGGESTED_EDIT_WORDS = new Set(["Reword", "Reword and move", "Rename"]); const LESSONS_RIGHT = { kind: "lessons", rows: [{ id: "w1", type: "lesson", text: "Run a page test with node scripts/node-test.mjs .", choices: ["Keep", "Reword", "Drop"] }], @@ -986,18 +988,30 @@ function lessonsProblems(item, at) { }); if (item.checked != null) problems.push(...lessonsCheckedProblems(item.checked, at)); // 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. + // one of that row's own choice words, or { choice, text?, why? } where the + // choice opens an edit and the words are what its boxes start on. It + // outlines a button; it never picks. const sug = item.suggested; - const SUGGESTED_RIGHT = { suggested: { w1: "Keep", w2: "Drop" } }; + const SUGGESTED_RIGHT = { suggested: { w1: "Keep", w2: { choice: "Reword", text: "The new words.", why: "Why it matters." } } }; 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)) { + for (const [id, given] of Object.entries(sug)) { const row = byId.get(id); + const word = isPlainObject(given) ? given.choice : given; 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)); + } else if (isPlainObject(given)) { + for (const key of Object.keys(given)) { + if (!["choice", "text", "why"].includes(key)) problems.push(rule(at, `suggested "${id}" ${key}`, "is not allowed: a suggestion takes choice, text and why only", SUGGESTED_RIGHT)); + } + for (const key of ["text", "why"]) { + if (given[key] == null) continue; + if (!SUGGESTED_EDIT_WORDS.has(word)) problems.push(rule(at, `suggested "${id}" ${key}`, `goes only with a choice that opens an edit (${[...SUGGESTED_EDIT_WORDS].join(", ")}). Leave it out`, SUGGESTED_RIGHT)); + else if (typeof given[key] !== "string" || !given[key].trim()) problems.push(rule(at, `suggested "${id}" ${key}`, "must be a non-empty string, or left out", SUGGESTED_RIGHT)); + } } } } diff --git a/src/web-console/public/answers.js b/src/web-console/public/answers.js index b254154..df417dc 100644 --- a/src/web-console/public/answers.js +++ b/src/web-console/public/answers.js @@ -237,6 +237,21 @@ export function lessonOriginal(row) { return row.text || ""; } +/** + * The agent's suggestion for a row (Ask for suggestions): `{ choice, text, why }` + * from either form `suggested` takes, a bare choice word or an object. The + * words are kept only for a choice that opens an edit; null without one. + */ +export function lessonSuggestion(item, row) { + const all = item && item.suggested && typeof item.suggested === "object" ? item.suggested : null; + const given = all && row ? all[row.id] : null; + if (typeof given === "string") return { choice: given, text: "", why: "" }; + if (!given || typeof given !== "object" || typeof given.choice !== "string") return null; + const edit = LESSON_EDIT_WORDS.has(given.choice); + const words = (v) => (edit && typeof v === "string" && v.trim() ? v.trim() : ""); + return { choice: given.choice, text: words(given.text), why: words(given.why) }; +} + /** The edit's words in the same form as lessonOriginal, or the original when untouched. */ function lessonTyped(row, edit) { const field = lessonEditField(row).key; diff --git a/src/web-console/public/screens/cards.js b/src/web-console/public/screens/cards.js index ae6416f..039c5f3 100644 --- a/src/web-console/public/screens/cards.js +++ b/src/web-console/public/screens/cards.js @@ -43,6 +43,7 @@ import { lessonEditStart, lessonEditField, lessonReworded, + lessonSuggestion, startsTicked, } from "../answers.js"; import { el, hiddenText, icon, md, stateMark } from "../render.js"; @@ -1758,7 +1759,9 @@ function lessonsDraft(item) { } const picks = d && d.picks && typeof d.picks === "object" ? d.picks : {}; const edits = d && d.edits && typeof d.edits === "object" ? d.edits : {}; - return { picks, edits, leaveAll: Boolean(d && d.leaveAll) }; + // Which suggested words were already put in a row's boxes, so they go in once. + const applied = d && d.applied && typeof d.applied === "object" ? d.applied : {}; + return { picks, edits, applied, leaveAll: Boolean(d && d.leaveAll) }; } // The answer the draft stands for, or null with the field still missing. @@ -1829,8 +1832,10 @@ function buildLessons(card, item, staged) { const how = lessonsCheckedLine(item.checked); if (how) card.appendChild(el("p", "lessons-checked", how)); const list = el("ul", "lessons-rows"); + const filled = lessonsFillSuggested(item, draft); for (const row of item.rows || []) list.appendChild(lessonRow(item, row, draft, commit)); card.appendChild(list); + if (filled) commit(false); const { missing } = lessonsAnswer(item, draft); error.hidden = !missing; @@ -1908,6 +1913,32 @@ function lessonCheckLines(li, item, row, draft, commit) { li.appendChild(box); } +// A suggestion with words (Ask for suggestions) fills the boxes of a row whose +// edit is open on the suggested choice: once per suggestion, whether the edit +// was open when it landed or opened after, so typing afterwards stays. +function lessonsFillSuggested(item, draft) { + let filled = false; + for (const row of item.rows || []) { + const sug = lessonSuggestion(item, row); + if (!sug || (!sug.text && !sug.why) || draft.picks[row.id] !== sug.choice) continue; + const stamp = JSON.stringify([sug.text, sug.why]); + if (draft.applied[row.id] === stamp) continue; + const edit = draft.edits[row.id] || lessonEditStart(row); + if (sug.text) { + const key = lessonEditField(row).key; + // A log line that would become several lessons keeps them: one + // suggested sentence never stands in for the whole list. + if (key !== "lessons") edit[key] = sug.text; + else if (!Array.isArray(edit.lessons) || edit.lessons.length <= 1) edit.lessons = [sug.text]; + } + if (sug.why && "why" in edit) edit.why = sug.why; + draft.edits[row.id] = edit; + draft.applied[row.id] = stamp; + filled = true; + } + return filled; +} + // One waiting item: what it is, why, where it came from, and its own choices. function lessonRow(item, row, draft, commit) { const pick = draft.picks[row.id] || ""; @@ -1977,7 +2008,7 @@ function lessonRow(item, row, draft, commit) { 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; + const suggested = lessonSuggestion(item, row)?.choice ?? null; choices.forEach((word, i) => { const on = pick === word; const hint = suggested === word;