From ee530d36c0b123740469e907e056000c0e76050a Mon Sep 17 00:00:00 2001 From: Justin Parker Date: Sun, 29 Nov 2026 21:15:46 -0800 Subject: [PATCH] Quiet the Tidy up banner once a tidy-up finds nothing AI Assisted --- .readme/web-console-internals.md | 1 + AGENTS.md | 2 +- CHANGELOG.md | 5 +++ scripts/test-web-console-learning.mjs | 30 +++++++++++++ scripts/test-web-console-page-learning.mjs | 11 +++++ scripts/test-web-console-shape.mjs | 2 +- src/web-console/learning.mjs | 47 ++++++++++++++++++++- src/web-console/public/screens/dashboard.js | 24 +++++++++++ src/web-console/routes.mjs | 34 ++++++++++++--- 9 files changed, 148 insertions(+), 8 deletions(-) diff --git a/.readme/web-console-internals.md b/.readme/web-console-internals.md index f17310b..de9a0a9 100644 --- a/.readme/web-console-internals.md +++ b/.readme/web-console-internals.md @@ -169,6 +169,7 @@ origin. | `POST /open-prototype` | `{ spec, name }`: opens one `.html` from `/prototypes/` in the person's default browser. 404 for any other name, 500 when no browser could start. | | `GET /handoff?id=` | *Read it all*: the handoff's `.md` from `~/.plan2code/handoffs/`, as `text/markdown` with `cache-control: no-store`. A dashboard only, and only an id its own scan listed: a used, unknown or malformed id is 404. | | `POST /learning/pause` | Pause for me: `{ paused: boolean }` (origin-checked; anything else is 400 `bad-request`, and 409 `not-on` unless Learning is On or Paused for you). Writes the personal pause on this machine only (`pause.json` under `~/.plan2code/learning//`), the server's only write for Learning, and repaints the row with no agent. | +| `POST /learning/tidy-quiet` | Tidy-up quiet: an empty JSON object (origin-checked; 409 `not-on` unless Learning is On). Stores a fingerprint of the saved lessons in `tidy-quiet.json` beside `pause.json`, so `scan.learning.nearCap` stays false until a lesson file changes. Sent by the banner's Not now and by a Tidy up that proposed nothing; repaints with no agent. | | `GET /learning/state` | The Learning row's state worked out now, `{ state, pausedSince, waiting, oldestDays, nearCap }` (`{}` when the project's settings file is from a format it cannot read), with `cache-control: no-store`. | | `GET /learning/lessons` | Open the lessons, read only: `{ files: [{ name, title, text }], follows: { : { count, last } } }` (follows from this machine's `follows.ndjson`, for the reader's "Followed N times" line) from the project's lessons (`.plan2code/lessons/`, saved with the repository), `general.md` first, then the other `.md` files in name order (plain files only, at most 100 of 512 KB each), with `cache-control: no-store`. | | `GET /workspace` | The Workspace dialog's list: folders, `missing`, `remote` and the agent's folder `issues`. `?check=1` re-checks every folder on disk first. | diff --git a/AGENTS.md b/AGENTS.md index 8aef8c9..fe567e3 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -40,7 +40,7 @@ Optional local browser UI (`src/web-console/`, zero dependencies, detached `node One agent list and one lookup rule serve the launcher, the console and the app: `src/launcher/agents.json` (the built-ins and starter templates with per-OS install data) and `src/web-console/agent-lookup.mjs` (`loadAgentList()` and `findAgent()`, both copied by `install.js` into `~/.plan2code/bin/`); the app carries a Rust twin held to the same cases by `scripts/fixtures/agent-lookup-cases.json`. -**Learning** (lessons about a codebase, kept with it): the dashboard draws a Learning row (Not set up, Off, On or Paused for you, with a Pause for me switch and a More menu) and, while lessons are waiting, a banner with Review (plus a Tidy up nudge from the scan's `nearCap`; More, Tidy up lessons sends the `tidy` action, which writes `tidy` waiting items the same card applies), both from the scan's `learning` field (`public/screens/learning-row.js`, `public/styles/learning.css`); skills ask for approval through the `lessons` card kind. Before that card, every waiting lesson is graded by a separate check, a fresh read-only helper where the agent has one, else a labeled second pass by the same agent (`src/shared-references/lesson-check.md`; `lessons.mjs check-input` prepares, the checker judges, `check-record` stores), and the card shows each Doubt or Fail with its reason; follows ("Following a lesson") are counted on this machine only, in `follows.ndjson`, for the lessons reader. The server's only write for it is the personal pause, on this machine only (`POST /learning/pause`, under `~/.plan2code/learning/`); every change to the project's Learning files (`.plan2code/settings.json` and `.plan2code/lessons/`) goes through the `lessons.mjs` skill script, which shares one core with the scan, `src/web-console/learning.mjs`. +**Learning** (lessons about a codebase, kept with it): the dashboard draws a Learning row (Not set up, Off, On or Paused for you, with a Pause for me switch and a More menu) and, while lessons are waiting, a banner with Review (plus a Tidy up nudge from the scan's `nearCap`; More, Tidy up lessons sends the `tidy` action, which writes `tidy` waiting items the same card applies), both from the scan's `learning` field (`public/screens/learning-row.js`, `public/styles/learning.css`); skills ask for approval through the `lessons` card kind. Before that card, every waiting lesson is graded by a separate check, a fresh read-only helper where the agent has one, else a labeled second pass by the same agent (`src/shared-references/lesson-check.md`; `lessons.mjs check-input` prepares, the checker judges, `check-record` stores), and the card shows each Doubt or Fail with its reason; follows ("Following a lesson") are counted on this machine only, in `follows.ndjson`, for the lessons reader. The server's only writes for it are the personal pause (`POST /learning/pause`) and the tidy-up quiet (`POST /learning/tidy-quiet`: a Tidy up that proposed nothing, or the banner's Not now, hides the nudge until the saved lessons change), both on this machine only, under `~/.plan2code/learning/`; every change to the project's Learning files (`.plan2code/settings.json` and `.plan2code/lessons/`) goes through the `lessons.mjs` skill script, which shares one core with the scan, `src/web-console/learning.mjs`. Building or changing an Activities game: follow the game rules in [Activities](./.agents-docs/AGENTS-architecture-activities.md) ("Building an Activities game": lives in the solid lives pill, the endless-lives code (`cheat(on)`) in every game with lives, banners placed away from the player and see-through over what matters, pausing left to the window). Details: [Web console server and contract](./.agents-docs/AGENTS-architecture-console.md), [page](./.agents-docs/AGENTS-architecture-console-page.md), [design points](./.agents-docs/AGENTS-architecture-console-design.md), [Activities](./.agents-docs/AGENTS-architecture-activities.md) (and the Ghoul Rush and Bounce Road files it links) [.readme/web-console.md](./.readme/web-console.md) (the user guide), [.readme/activities.md](./.readme/activities.md) and [.readme/web-console-internals.md](./.readme/web-console-internals.md) (routes, security, driving it by hand, refreshing screenshots) Why the agent-facing console docs are shaped as they are (the card, pointers, refusals): [Web Console Contract](./.agents-docs/AGENTS-web-console-contract.md); it never ships. diff --git a/CHANGELOG.md b/CHANGELOG.md index 2892afd..d5226dc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,11 @@ All notable changes to Plan2Code will be documented in this file. ### ✨ Added - **Web console**: text size buttons in the top bar, between the megaphone and the die: [-], the current size and [+] scale all the console's text in seven steps from 80% to 150%, the size returns to 100% when you click it, your choice is kept with your other looks, and Back to default on the Appearance tab resets it. +- **Learning**: the Tidy up banner has a Not now button that hides it until your saved lessons change (remembered on this machine only). + +### 🐛 Fixed + +- **Learning**: the Tidy up banner stays hidden once a Tidy up finds nothing to do, until your saved lessons change; before, it came straight back and Tidy up only said there was nothing to tidy. ## v3.2.0 (2026-11-29) diff --git a/scripts/test-web-console-learning.mjs b/scripts/test-web-console-learning.mjs index 87338d7..74367be 100644 --- a/scripts/test-web-console-learning.mjs +++ b/scripts/test-web-console-learning.mjs @@ -119,6 +119,36 @@ test("scan.learning.nearCap: true at 22 general lessons or 30 in an area, false assert.deepEqual(listing(full), before, "the scan writes nothing"); }); +test("scan.learning.nearCap stays false once a tidy-up found nothing, until the saved lessons change", async (t) => { + const dir = project({ ...SETTINGS("on"), ".plan2code/lessons/general.md": lessonFile("General", 23) }); + assert.equal(learningScan(dir).nearCap, true); + const s = dashboard(t, dir); + const res = await s.post("/learning/tidy-quiet", {}); + assert.equal(res.status, 200); + const body = await res.json(); + assert.equal(body.ok, true); + assert.equal(body.learning.nearCap, false, "the answer carries the patched scan"); + assert.equal(readState(s.session).scan.learning.nearCap, false, "the page repaints from the patched scan"); + assert.equal(learningScan(dir).nearCap, false, "a later scan agrees"); + assert.ok(fs.existsSync(path.join(storeDir(dir), "tidy-quiet.json")), "it lives in the learning store on this machine"); + // The lessons change (a merge, a new lesson): the nudge may come back. + fs.writeFileSync(path.join(dir, ".plan2code", "lessons", "general.md"), lessonFile("General", 24)); + assert.equal(learningScan(dir).nearCap, true); +}); + +test("POST /learning/tidy-quiet is 409 when the project is not on and writes nothing into the project", async (t) => { + for (const files of [{}, SETTINGS("off")]) { + const s = dashboard(t, project(files)); + const res = await s.post("/learning/tidy-quiet", {}); + assert.equal(res.status, 409); + assert.deepEqual(await res.json(), { error: "not-on" }); + } + const dir = project({ ...SETTINGS("on"), ".plan2code/lessons/general.md": lessonFile("General", 23) }); + const before = listing(dir); + await dashboard(t, dir).post("/learning/tidy-quiet", {}); + assert.deepEqual(listing(dir), before); +}); + test("a failure in Learning's core never fails the scan", () => { const boom = () => { throw new Error("the core broke"); diff --git a/scripts/test-web-console-page-learning.mjs b/scripts/test-web-console-page-learning.mjs index f618f37..1ad7f0c 100644 --- a/scripts/test-web-console-page-learning.mjs +++ b/scripts/test-web-console-page-learning.mjs @@ -282,6 +282,17 @@ test("the banner nudges a tidy-up when lessons are near their limit, and only th assert.equal(await below.main.locator(".learn-banner").count(), 0, "no banner below the line"); }); +test("Not now hides the tidy-up nudge at once and it stays hidden for the same lessons", async (t) => { + const full = await dashboard(t, { ...PROJECT("on"), ".plan2code/lessons/general.md": lessonFile("General", 22) }); + const banner = full.main.locator(".learn-banner"); + await banner.waitFor(); + await banner.getByRole("button", { name: "Not now" }).click(); + await until(async () => (await full.main.locator(".learn-banner").count()) === 0, 5000); + const state = await full.s.page.evaluate(() => fetch("/learning/state").then((r) => r.json())); + assert.equal(state.nearCap, false, "the server remembers it"); + assert.equal(await full.main.locator(".learn-banner").count(), 0, "still hidden after the repaint"); +}); + test("a launch from a dashboard showing lessons waiting carries fromBanner", async (t) => { const { s, main } = await dashboard(t, PROJECT("on"), (p) => writeWaiting(p, { id: "20261113-120000-eeeeee", type: "lesson", text: "Waits.", noted: new Date().toISOString() }) diff --git a/scripts/test-web-console-shape.mjs b/scripts/test-web-console-shape.mjs index fb7d7cd..7c9a910 100644 --- a/scripts/test-web-console-shape.mjs +++ b/scripts/test-web-console-shape.mjs @@ -189,7 +189,7 @@ test("shape: no page module sets a style attribute from script", () => { // no routes of its own: its buttons are sends (`__git`), through /submit. const ROUTE_ORDER = [ "/health", "/s/", "/handover", "/", "SERVABLE", "/overview", "/agents-doc", "/prototypes", "/prototype", "/handoff", "/version", "/state", "/events", "/draft", - "/looks", "/looks", "/subagents", "/learning/pause", "/learning/state", "/learning/lessons", "/pr-host", "/models", "/models", "/agents", "/agents", "/agents/test", "/agents/use-path", "/cleanup", "/upload", + "/looks", "/looks", "/subagents", "/learning/pause", "/learning/tidy-quiet", "/learning/state", "/learning/lessons", "/pr-host", "/models", "/models", "/agents", "/agents", "/agents/test", "/agents/use-path", "/cleanup", "/upload", "/notepad", "/notepad/text", "/notepad/image", "/notepad/thumb", "/notepad/image/delete", "/notepad/tab", "/notepad/tab/rename", "/notepad/tab/delete", "/notepad/tab/order", "/notepad/tab/last", "/notepad/tab/sent", "/notepad/images/", "/attachments/", "/shots/", "/uploads/", "/submit", "/open-link", "/open-prototype", "/chat", "/chat/decision", "/workspace", diff --git a/src/web-console/learning.mjs b/src/web-console/learning.mjs index 33ebcba..e145c3d 100644 --- a/src/web-console/learning.mjs +++ b/src/web-console/learning.mjs @@ -126,6 +126,49 @@ export function writePause(cwd, paused, now) { return { paused: true, since }; } +/* ------------------------------------------------------- the tidy-up quiet */ + +/** + * A short fingerprint of the project's saved lessons (every `.md` file's name + * and text under `.plan2code/lessons/`, in name order). It changes when a + * lesson is added, merged, reworded or retired, and only then. Reads only; a + * missing folder or an unreadable file counts as empty. + */ +export function lessonsFingerprint(cwd = process.cwd()) { + const dir = path.join(worktreeOf(cwd), ".plan2code", "lessons"); + const hash = crypto.createHash("sha1"); + let names = []; + try { + names = fs.readdirSync(dir).filter((n) => n.endsWith(".md")).sort(); + } catch {} + for (const name of names) { + let text = ""; + try { + text = fs.readFileSync(path.join(dir, name), "utf8"); + } catch {} + hash.update(`${name}\0${text}\0`); + } + return hash.digest("hex"); +} + +/** The lessons a tidy-up already looked over (or the person waved off), or null. */ +export function readTidyQuiet(cwd) { + const data = readJson(path.join(storeDir(cwd), "tidy-quiet.json")); + if (!data || typeof data !== "object" || data.format !== FORMAT || typeof data.fingerprint !== "string") return null; + return data.fingerprint; +} + +/** + * Remember that the lessons as they are now need no tidy-up nudge: a tidy-up + * proposed nothing, or the person pressed Not now. `now` pins the clock. + */ +export function writeTidyQuiet(cwd, now) { + const fingerprint = lessonsFingerprint(cwd); + ensureDir(storeDir(cwd)); + writeJsonAtomic(path.join(storeDir(cwd), "tidy-quiet.json"), { format: FORMAT, fingerprint, at: toDate(now).toISOString() }); + return fingerprint; +} + /* ------------------------------------------------------------ follow counts */ /** One line per "Following a lesson" moment, on this machine only. */ @@ -330,6 +373,8 @@ export function learningScan(cwd = process.cwd(), { now, read = learningState } pausedSince: s.pausedSince || null, waiting: Number.isInteger(waiting.count) ? waiting.count : 0, oldestDays: Number.isInteger(waiting.oldestDays) ? waiting.oldestDays : 0, - nearCap: s.state === "on" && lessonsNearCap(cwd), + // Crowded, and not already looked over: a tidy-up that proposed nothing (or + // a Not now) quiets the nudge until the saved lessons change. + nearCap: s.state === "on" && lessonsNearCap(cwd) && readTidyQuiet(cwd) !== lessonsFingerprint(cwd), }; } diff --git a/src/web-console/public/screens/dashboard.js b/src/web-console/public/screens/dashboard.js index 358469c..dcb0c05 100644 --- a/src/web-console/public/screens/dashboard.js +++ b/src/web-console/public/screens/dashboard.js @@ -16,6 +16,7 @@ import { } from "../selectors.js"; import { whenTitle, whenWords } from "../labels.js"; import { hooks, page, redraw, saveNow } from "../state.js"; +import { postJson } from "../net.js"; import { el, approvalTip, mdInto, releasesLink, copyButton, lightDismiss, icon, SVG_NS } from "../render.js"; import { needsRoleNudge, ROLE_NOT_SET } from "../starters.js"; import { looks, saveLooks } from "../looks.js"; @@ -1483,6 +1484,15 @@ function learningBanner(sc) { if (why) b.title = why; b.addEventListener("click", () => sendLearning(what)); r.appendChild(b); + if (what === "tidy") { + // Not now needs no agent: the server remembers it, on this machine only, + // and the nudge stays hidden until the saved lessons change. + const later = el("button", "btn sm", "Not now"); + later.type = "button"; + later.title = "Hide this until your lessons change."; + later.addEventListener("click", () => quietTidyNudge()); + r.appendChild(later); + } banner.appendChild(r); }; if (text) row(text, "Review", "review", true); @@ -1490,6 +1500,17 @@ function learningBanner(sc) { return banner; } +// Hide the tidy-up nudge until the saved lessons change (POST /learning/tidy-quiet; +// the server pushes the patched scan, so the banner redraws without it). Used by +// Not now and by a Tidy up that came back with nothing to propose. A failure is +// quiet: the nudge simply stays, as it did before. +async function quietTidyNudge() { + try { + await postJson("/learning/tidy-quiet", {}); + } catch {} + redraw(); +} + // The agent finishing with nothing to show ends the wait early: a Review whose // card never came (the banner was stale) says so at once instead of spinning // to the limit, and a saved choice stops when the agent is back to waiting. @@ -1514,6 +1535,9 @@ function watchLearningBusy(busy) { clearInterval(timer); page.learningBusy = null; if (busy.what === "review" || busy.what === "tidy") { + // A tidy-up with nothing to propose is an answer: remember it, so the + // nudge does not come straight back for the same lessons. + if (busy.what === "tidy") quietTidyNudge(); const none = hooks.banner(busy.what === "tidy" ? "Nothing to tidy up right now." : "No lessons are waiting any more.", "info"); setTimeout(() => hooks.clearBanner(none), 4000); } diff --git a/src/web-console/routes.mjs b/src/web-console/routes.mjs index da70314..56677c6 100644 --- a/src/web-console/routes.mjs +++ b/src/web-console/routes.mjs @@ -53,7 +53,7 @@ import { cleanSetting, offered } from "./public/subagents.js"; import { DEFAULT_ACCENT, DEFAULT_CARD_WIDTH, DEFAULT_TEXT_SIZE, accentId, cardWidth, textSize } from "./public/palette.js"; import { SERVABLE, TYPES, asset } from "./static.mjs"; import { handoffsDir, isHandoffId } from "./handoffs.mjs"; -import { followCounts, learningScan, learningState, writePause } from "./learning.mjs"; +import { followCounts, learningScan, learningState, writePause, writeTidyQuiet } from "./learning.mjs"; import { linkToOpen, openFile, openLink } from "./open-link.mjs"; import { NotepadError, @@ -100,6 +100,7 @@ const ROUTES = [ { path: "/looks", method: "POST", origin: true, run: looksPost }, { path: "/subagents", method: "POST", origin: true, run: subagentsPost }, { path: "/learning/pause", method: "POST", origin: true, run: learningPause }, + { path: "/learning/tidy-quiet", method: "POST", origin: true, run: learningTidyQuiet }, { path: "/learning/state", method: "GET", run: learningStateGet }, { path: "/learning/lessons", method: "GET", run: learningLessons }, { path: "/pr-host", method: "POST", origin: true, run: prHost }, @@ -660,17 +661,40 @@ function subagentsPost(req, res, ctx) { // store), never inside the project. It needs no agent: the dashboard's // scan.learning is patched in place and pushed, so the row repaints at once. function learningPause(req, res, ctx) { + return learningWrite(req, res, ctx, { + valid: (body) => typeof body.paused === "boolean", + states: ["on", "paused"], + write: (worktree, body) => writePause(worktree, body.paused), + event: (body) => ({ type: "learning-pause", paused: body.paused }), + }); +} + +// Learning's tidy-up quiet (learning.mjs): a Tidy up that proposed nothing, or +// the banner's Not now, hides the tidy-up nudge until the saved lessons change. +// Machine-local like the pause, and only while Learning is on. +function learningTidyQuiet(req, res, ctx) { + return learningWrite(req, res, ctx, { + valid: () => true, + states: ["on"], + write: (worktree) => writeTidyQuiet(worktree), + event: () => ({ type: "learning-tidy-quiet" }), + }); +} + +// The shared body of the Learning routes that write on this machine: check the +// body and the state, write, patch the dashboard's scan in place and push it. +function learningWrite(req, res, ctx, { valid, states, write, event }) { return readBody(req, res, (err, body) => { if (err) return json(res, err.tooBig ? 413 : 400, { error: err.tooBig ? "too large" : "body must be JSON" }); - if (!body || typeof body !== "object" || typeof body.paused !== "boolean") return json(res, 400, { error: "bad-request" }); + if (!body || typeof body !== "object" || !valid(body)) return json(res, 400, { error: "bad-request" }); const worktree = ctx.worktree() || ctx.project; let learning; let written = null; let agentWrote = false; try { const current = learningState(worktree, undefined, { prune: false }); - if (current.state !== "on" && current.state !== "paused") return json(res, 409, { error: "not-on" }); - writePause(worktree, body.paused); + if (!states.includes(current.state)) return json(res, 409, { error: "not-on" }); + write(worktree, body); learning = learningScan(worktree); written = updateState(ctx.dir, (fresh) => { if (!fresh || !fresh.scan || typeof fresh.scan !== "object") return null; @@ -700,7 +724,7 @@ function learningPause(req, res, ctx) { } catch {} } } - noteEvent(ctx.dir, { type: "learning-pause", paused: body.paused }); + noteEvent(ctx.dir, event(body)); ctx.pushState(); return json(res, 200, { ok: true, learning }); });