From 97f65edd84f5de9a49ce1b4c7eea0242561bfec0 Mon Sep 17 00:00:00 2001 From: Justin Parker Date: Sun, 29 Nov 2026 10:49:44 -0800 Subject: [PATCH] Let the app bar's update line use the room the bar has AI Assisted --- .plan2code/lessons/general.md | 6 ++ plan2code-app/ui/app.js | 5 +- plan2code-app/ui/index.html | 11 +++- scripts/test-app-meter.mjs | 114 +++++++++++++++++++++++++++++++++- 4 files changed, 132 insertions(+), 4 deletions(-) diff --git a/.plan2code/lessons/general.md b/.plan2code/lessons/general.md index 5471912..2272b36 100644 --- a/.plan2code/lessons/general.md +++ b/.plan2code/lessons/general.md @@ -115,6 +115,12 @@ - Why: Each launcher prompt opens a new readline, so piping all answers at once loses every answer after the first. - Noted: 2026-11-17, implement-review, checked 2026-11-28 +### To run plan2code-app/ui/app.js in a page test, serve the ui folder over HTTP and stub window.__TAURI__, with platform_info answering { os }; from file:// the module never loads. +- Kind: how-it-works +- About: scripts/test-app-meter.mjs, plan2code-app/ui/app.js +- Why: A test that loaded index.html from file:// never ran fitBar(), and a catch-all stub made mountTerminal's top-level await throw. +- Noted: 2026-11-29, quick-task + ### 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/plan2code-app/ui/app.js b/plan2code-app/ui/app.js index bcb3dcd..b7f8fe6 100644 --- a/plan2code-app/ui/app.js +++ b/plan2code-app/ui/app.js @@ -427,8 +427,11 @@ function fitBar() { barRowEl.classList.remove('no-model', 'no-status'); const model = agentModelEl.hidden ? 0 : agentModelEl.offsetWidth; const status = agentStatusEl.textContent ? agentStatusEl.offsetWidth : 0; + // The step text shrinks rather than overflowing the row, so what it hides + // counts as needed room: the model and status drop before it is cut. + const stepCut = nextStepEl.hidden ? 0 : Math.max(0, nextStepTextEl.scrollWidth - nextStepTextEl.clientWidth); // Only an agent's menu can hold them, so with none the row keeps everything. - const fit = agentMenuBtn.hidden ? { model: true, status: true } : barFit({ available: barRowEl.clientWidth, needed: barRowEl.scrollWidth, model, status }); + const fit = agentMenuBtn.hidden ? { model: true, status: true } : barFit({ available: barRowEl.clientWidth, needed: barRowEl.scrollWidth + stepCut, model, status }); const dropModel = !fit.model && model > 0; const dropStatus = !fit.status && status > 0; barRowEl.classList.toggle('no-model', dropModel); diff --git a/plan2code-app/ui/index.html b/plan2code-app/ui/index.html index 92fbb70..795eb5c 100644 --- a/plan2code-app/ui/index.html +++ b/plan2code-app/ui/index.html @@ -105,8 +105,15 @@ @media (prefers-reduced-motion: reduce) { #loop-dot, .loop-pip.current { animation: none; } } #bar-grow { flex: 1; min-width: 0; } /* The one next step for the console or the skills, at the right end. */ - #next-step { display: flex; align-items: center; gap: 8px; flex: none; } - #next-step-text { overflow: hidden; text-overflow: ellipsis; max-width: 320px; } + /* It takes the room the row has left and is cut, with an ellipsis, only + once fitBar() has already dropped the model and status text. The text's + column may shrink to nothing, so the box's own floor is its buttons: + it never squeezes them, or runs them under the menu button. */ + #bar-row > #next-step { + display: grid; grid-auto-flow: column; grid-template-columns: minmax(0, max-content); grid-auto-columns: max-content; + align-items: center; gap: 8px; flex: 0 1 auto; + } + #next-step > #next-step-text { min-width: 0; overflow: hidden; text-overflow: ellipsis; } #next-step-text.is-ok { color: var(--ok); } #next-step-text.is-warn { color: var(--stage); } #next-step-text.is-err { color: var(--warn); } diff --git a/scripts/test-app-meter.mjs b/scripts/test-app-meter.mjs index a13c7f6..3dee18a 100644 --- a/scripts/test-app-meter.mjs +++ b/scripts/test-app-meter.mjs @@ -9,6 +9,7 @@ import test from "node:test"; import assert from "node:assert/strict"; import fs from "node:fs"; +import http from "node:http"; import path from "node:path"; import { fileURLToPath, pathToFileURL } from "node:url"; import { looksFromMessage, terminalFontStep, TERMINAL_FONT_DEFAULT, TERMINAL_FONT_MIN, TERMINAL_FONT_MAX, splitterFraction, splitterAria, terminalTitle, barFit, terminalAnsi, TERMINAL_ANSI, hexToRgba, helloRetryAction, retryLabel, RETRY_AFTER_SECONDS, attentionSignal, commandSegments, plainCommandText, menuStep, pageNotShownView, pageDetailsLine, redactSessionUrl, barNextSteps, continueKeys, defaultRightFraction, folderName, folderPickerRows, pickDefaultAgent, taskbarSwitch, windowTitleFor, deadConsoleAction, loopBanner, loopRunText, loopLocks, loopStopLabels, loopWindowTitle, CONSOLE_ASIDE_BREAKPOINT_PX, NEXT_STEP_LABELS, NEW_RELEASE_COMMAND, STILL_WAITING_MS, STILL_WAITING_TEXT, waitingView, friendlyError, endedView, confirmButtons, trapTab, SHORTCUTS, shortcutAction, shortcutLabel, tipWithShortcut, shortcutFromMessage, clipboardAction, releaseAfterCheck, releaseNotesUrl, reasonSentence, UPDATE_RECHECK_MS } from "../plan2code-app/ui/meter.js"; @@ -1135,11 +1136,122 @@ test("barFit drops the model text first, then the status line, and only when the assert.deepEqual(barFit({ available: 500, needed: 800 }), { model: false, status: false }, "no parts measured, none claimed"); }); +// The app's ui/ folder over HTTP on a free local port, for a test that needs app.js to run. +function serveFolder(dir) { + const TYPES = { ".html": "text/html", ".js": "text/javascript", ".css": "text/css", ".svg": "image/svg+xml", ".woff2": "font/woff2" }; + const server = http.createServer((req, res) => { + const file = path.join(dir, decodeURIComponent(new URL(req.url, "http://x").pathname)); + if (!file.startsWith(dir) || !fs.existsSync(file) || !fs.statSync(file).isFile()) { + res.writeHead(404).end(); + return; + } + res.writeHead(200, { "content-type": TYPES[path.extname(file)] || "application/octet-stream" }); + fs.createReadStream(file).pipe(res); + }); + return new Promise((resolve) => server.listen(0, "127.0.0.1", () => resolve(server))); +} + +test("the bar's step text uses the room the row has; model and status drop before it is cut, and its buttons never shrink", async (t) => { + if (!findBrowser()) return t.skip("no Chrome or Edge installed"); + const browser = await launchBrowser(); + try { + const page = await browser.newPage({ viewport: { width: 1800, height: 600 } }); + // Later start-up steps trip over the stub's nulls; the bar is wired before them, + // and "the model alone drops" below shows fitBar() ran. + page.on("pageerror", () => {}); + // Enough of __TAURI__ for app.js to run, so its real fitBar() lays out the row: + // every command answers null (platform_info a platform), every window call resolves. + await page.addInitScript(() => { + const resolved = () => Promise.resolve(); + const win = new Proxy({}, { get: () => resolved }); + const known = { + core: { invoke: (cmd) => Promise.resolve(cmd === "platform_info" ? { os: "linux" } : null), Channel: class {} }, + window: { getCurrentWindow: () => win }, + event: { listen: () => Promise.resolve(() => {}) }, + }; + window.__TAURI__ = new Proxy(known, { get: (all, key) => all[key] || new Proxy({}, { get: () => resolved }) }); + }); + // app.js is a module, which Chrome will not load from file://: serve the folder. + const server = await serveFolder(path.dirname(INDEX_HTML_PATH)); + t.after(() => server.close()); + await page.goto(`http://127.0.0.1:${server.address().port}/index.html`, { waitUntil: "networkidle" }); + await page.evaluate(() => { + const show = (id, text) => { + const el = document.getElementById(id); + el.hidden = false; + if (text !== undefined) el.textContent = text; + }; + document.getElementById("agent-none").hidden = true; + show("project-menu-button"); + document.getElementById("project-name").textContent = "plan2code"; + show("agent-restart"); + show("agent-menu-button"); + document.getElementById("agent-name").textContent = "Claude Code"; + show("agent-model", "opus 5.5 xhigh"); + document.getElementById("agent-status").textContent = "Working: reading the plan and every phase file"; + show("next-step"); + const text = document.getElementById("next-step-text"); + text.textContent = "npx fetches it quietly first, which can take a minute or two."; + text.className = "is-warn is-busy"; + show("next-step-button", "Update and restart"); + show("next-step-more", "+1 more"); + show("next-step-notes"); + }); + const settle = () => page.evaluate(() => new Promise((r) => requestAnimationFrame(() => requestAnimationFrame(r)))); + const measure = () => + page.evaluate(() => { + const row = document.getElementById("bar-row"); + const text = document.getElementById("next-step-text"); + const box = (id) => document.getElementById(id).getBoundingClientRect(); + const menu = box("app-menu-button"); + const buttons = ["next-step-button", "next-step-more", "next-step-notes"].map(box); + return { + noModel: row.classList.contains("no-model"), + noStatus: row.classList.contains("no-status"), + cut: text.scrollWidth > text.clientWidth, + textWidth: text.clientWidth, + buttonWidths: buttons.map((b) => Math.round(b.width)), + overlap: buttons.some((b) => b.right > menu.left + 0.5), + menuInside: menu.width > 0 && menu.right <= row.getBoundingClientRect().right + 0.5, + }; + }); + await settle(); + const wide = await measure(); + assert.deepEqual([wide.noModel, wide.noStatus, wide.cut], [false, false, false], "a wide window shows everything, the whole line included"); + assert.ok(wide.textWidth > 320, `wider than the old 320px cap (${wide.textWidth}px)`); + const seen = new Set(); + // Down to the app's minimum width (tauri.conf.json minWidth 960). + for (let width = 1800; width >= 960; width -= 20) { + await page.setViewportSize({ width, height: 600 }); + await settle(); + const at = await measure(); + if (at.cut) assert.ok(at.noModel && at.noStatus, `${width}px: the line is cut only after the model and status dropped`); + if (at.noStatus) assert.ok(at.noModel, `${width}px: the model drops before the status`); + assert.deepEqual(at.buttonWidths, wide.buttonWidths, `${width}px: the step buttons keep their width`); + assert.equal(at.overlap, false, `${width}px: no step button runs under the menu button`); + assert.equal(at.menuInside, true, `${width}px: the menu button stays inside the row`); + seen.add(`${at.noModel}/${at.noStatus}/${at.cut}`); + } + assert.ok(seen.has("true/false/false"), `the model alone drops at some width (${[...seen]})`); + assert.ok(seen.has("true/true/true"), `the line is cut at the narrowest widths (${[...seen]})`); + assert.equal(await page.evaluate(() => getComputedStyle(document.getElementById("next-step-text")).textOverflow), "ellipsis"); + // Below the minimum, the row runs out at its end as it always did: the text + // has shrunk to nothing, but its buttons are never squeezed under the menu. + await page.setViewportSize({ width: 400, height: 600 }); + await settle(); + const tight = await measure(); + assert.deepEqual(tight.buttonWidths, wide.buttonWidths, "400px: the step buttons keep their width"); + assert.equal(tight.overlap, false, "400px: no step button runs under the menu button"); + } finally { + await browser.close(); + } +}); + test("the top bar collapses instead of scrolling, and +N more is a button that lists the other steps", () => { assert.doesNotMatch(INDEX_HTML, /#bar-row \{[^}]*overflow-x: auto/, "no sideways scrolling row"); assert.match(INDEX_HTML, /#bar-row\.no-model #agent-model, #bar-row\.no-status #agent-status \{ display: none; \}/); assert.match(APP_JS, /new ResizeObserver\(scheduleFitBar\)\.observe\(barRowEl\);/); - assert.match(APP_JS, /barFit\(\{ available: barRowEl\.clientWidth, needed: barRowEl\.scrollWidth, model, status \}\)/); + assert.match(APP_JS, /barFit\(\{ available: barRowEl\.clientWidth, needed: barRowEl\.scrollWidth \+ stepCut, model, status \}\)/); assert.doesNotMatch(APP_JS, /barRowEl\.addEventListener\('scroll'/); assert.match(INDEX_HTML, /