diff --git a/.plan2code/lessons/general.md b/.plan2code/lessons/general.md index 1e8f4f8..94fa921 100644 --- a/.plan2code/lessons/general.md +++ b/.plan2code/lessons/general.md @@ -27,6 +27,12 @@ - Why: A piped --update test run repointed the real plan2code shims at a temp folder until they were fixed by hand. - Noted: 2026-11-17, implement-review +### Before adding a class to the git board, grep styles/git.css for it: short names like git-tools and git-path are already taken (the Branches search row, the file path cell). +- Kind: correction +- About: src/web-console/public/styles/git.css +- Why: The new tools fold-out reused git-tools and the Branches row's flex rule laid it out side by side. +- Noted: 2026-11-17, quick-task + ### Each recordInstalled() in install.js stamps the version being installed into install.json, so a failed update must restore the old one with setRecordVersion(), or a retry says Already on. - Kind: how-it-works - About: install.js diff --git a/AGENTS.md b/AGENTS.md index 3ace86f..b8b7618 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -36,7 +36,7 @@ Details: [Status line](./.agents-docs/AGENTS-architecture-statusline.md) ## Web Console -Optional local browser UI (`src/web-console/`, zero dependencies, detached `node` server on `127.0.0.1`) installed once under `~/.plan2code/console//` (`installSharedConsole` in `install.js`) and reached from every skill through a forwarding stub, `src/web-console-stub/console.mjs`. The bare `plan2code` skill opens its dashboard, a card menu that launches any skill in the same session. Pages cover questions, sign-off gates (with an in-page code review, and in Implement, Implement + Review and Quick task a **Changes** tab: a `diff` doc block fed by the `changes.mjs` skill script, parsed by `public/diff-parse.js` and drawn by `public/diff-view.js`), build progress, the living document, a spec's saved prototypes (a **Prototypes** tab: an `.md` read in place, an `.html` opened in the default browser), an **Ask** chat, a read-only **Workspace** of extra folders (remembered per folder and spec in `~/.plan2code/console/workspaces.json`), a session meter, a **git board** for the `git` workflow (three tabs, Changes, Branches and Sync, opening on the likely next step; branches, pull, push, commits and pull-request links, drawn from `state.git`; contract in `notes/git.md`), **Stop with a handoff** (handoffs live in `~/.plan2code/handoffs/`, owned by `handoffs.mjs`, swept after 30 days, and offered as dashboard chips to pick up in the same session), a private **Notebook** in the top bar (named tabs of Markdown and pictures, a live-preview CodeMirror editor, one notepad per folder in `~/.plan2code/notepads/`, owned by `notepads.mjs`, private: the agent reads a tab only when you start Pathfinder, Plan, Quick task, Diagnose, UI Prototype or Revise plan from the dashboard with it and send the box it fills (an idea box marked `fill: "note"`, up to five ticked pictures attached), which then marks the tab sent via `POST /notepad/tab/sent`; the agent CLI never imports the store; removed only through Cleanup once a month untouched), **Activities** behind the top bar's die (thirteen small games, Snake, Mini golf, Light Trails, Bug Hunt, Sunset Drive, Stack Deploy, Bumper Ring, Rapids Run, Hot Potato, Crossing Rush, Bounce Road, Ghoul Rush and Flock Dash, listed in `public/activities.js` with one module per game under `public/activities/` (Ghoul Rush is its own folder of modules, `public/activities/ghoul-rush/`) and a card line (`blurb`) each, a picker of game rows in two columns, ordered Recently played or A to Z (saved in `activityOrder`), with never-picked games under Not played yet, once two are listed, that plays one game at a time (another pick drops the last game's round), driven by `screens/activities.js` (keys, key releases for a game with `release()`, canvas pointer events for a game with `pointer()`, one frame timer), paused whenever the person's turn comes and resumed only by the person (while that pause's banner is up, only by its **Unpause game** button), best scores in flat `activityBest` keys in `looks.json` (and the time each game was last picked in `activityPlayed`) (lowest wins for a game that sets `lowerIsBetter`; Mini golf opens on a dashboard of its six 18-hole courses, one file each under `public/activities/golf-course-.js`, and keeps a best per course, `activityBestGolf`), and one number a game may keep between sessions in `activityMemo` (Snake's tally of surprises found, Light Trails' furthest arena, Bug Hunt's tally of finds, Sunset Drive's roads found, Stack Deploy's highest floor, Bumper Ring's furthest arena, Rapids Run's furthest dam, Hot Potato's furthest venue, Crossing Rush's furthest zone, Bounce Road's furthest stage, Ghoul Rush's most stages cleared in a run, Flock Dash's furthest stage), never shown to the agent), a built-in 23-topic Help, the app-only **Implementation Loop** (a dashboard card and a setup screen drawn by the page, `public/screens/loop-setup.js`; the last setup remembered per project in `~/.plan2code/console/loop-setup.json`, owned by `loop-setup.mjs`; a page that locks while `state.loop.driving` is set, until the app posts `loopEnd`; a skill run with `--loop` reports a `loopOutcome` instead of asking for sign-off, per `notes/loop.md`), a first-run Welcome, User Preferences (gear: four tabs, Appearance, Agents & models, System and Sounds & activities, on the `public/tabs.js` helper Help also uses, with `public/prefs.js`, `screens/prefs-dialog.js` and `screens/agents-view.js`), an agent-less **setup** page (the `setup` workflow `plan2code` or the desktop app opens when no agent can run: each built-in's found / outside-PATH / missing state from `agent-lookup.mjs`, install lines, Check again, Use it from here, starter templates and Start, which hands the tab to the new agent through a token-guarded `POST /handover` and a `move` event; the app shows it in its window from a Set up an agent button instead) and a bug/idea link to GitHub issues. On opted-in skills (every workflow but the dashboard, setup, Changelog, Git, Handoff and UI Prototype) a **Subagents** button in the top bar turns helpers on or off per project and skill (on by default for those skills until switched off, saved in `~/.plan2code/console/subagents.json`), and a Helper strength choice (Balanced, Thrifty, Best, Match my session; rules in `src/shared-references/helper-strength.md`, shipped in the seventeen helper skills); the agent hears of it as a standing instruction only when it changes, and reports its helpers in a **Subagents** tab beside Ask (contract in `console-subagents.md`). Per-skill facts live in one list, `public/skills.js`, from which the meter, the resume command, Help's card list and the CLI's workflow list are derived; task files are read through `spec-files.mjs` (shared with the `specs.mjs` skill script), and the rule for which hops start the page clean is `startsClean()` in `public/hops.js`. The agent contract is a card plus pointers: `console.md` (the card) once per conversation, then a topic file (`console-*.md` such as `console-docs.md`, `notes/.md`, `building*.md`) only when the console names it in its own `read` output, once per session per topic (remembered in `pointers.json` in the session folder, owned by `pointers.mjs`); the console refuses the slips it can see (a `stop` with no `finish`, a `finish` while `stopWarning` is set, with `stop --force` for a dead page) instead of the docs repeating each rule. Byte budgets for the card, every notes file and a sample session's outputs run in `npm test` (`scripts/test-console-wire-budgets.mjs`). The server never writes into a project; the one thing it deletes there is an old `specs--completed/` the person picks in Cleanup, and only when git tracks it (an untracked one is refused, with the reason on the page). +Optional local browser UI (`src/web-console/`, zero dependencies, detached `node` server on `127.0.0.1`) installed once under `~/.plan2code/console//` (`installSharedConsole` in `install.js`) and reached from every skill through a forwarding stub, `src/web-console-stub/console.mjs`. The bare `plan2code` skill opens its dashboard, a card menu that launches any skill in the same session. Pages cover questions, sign-off gates (with an in-page code review, and in Implement, Implement + Review and Quick task a **Changes** tab: a `diff` doc block fed by the `changes.mjs` skill script, parsed by `public/diff-parse.js` and drawn by `public/diff-view.js`), build progress, the living document, a spec's saved prototypes (a **Prototypes** tab: an `.md` read in place, an `.html` opened in the default browser), an **Ask** chat, a read-only **Workspace** of extra folders (remembered per folder and spec in `~/.plan2code/console/workspaces.json`), a session meter, a **git board** for the `git` workflow (a Save, Share, Review, Tidy path, one task card for the step you are on, and the Changes, Branches and Sync tabs folded into **All branches and tools**; branches, pull, push, commits and pull-request links, drawn from `state.git`; contract in `notes/git.md`), **Stop with a handoff** (handoffs live in `~/.plan2code/handoffs/`, owned by `handoffs.mjs`, swept after 30 days, and offered as dashboard chips to pick up in the same session), a private **Notebook** in the top bar (named tabs of Markdown and pictures, a live-preview CodeMirror editor, one notepad per folder in `~/.plan2code/notepads/`, owned by `notepads.mjs`, private: the agent reads a tab only when you start Pathfinder, Plan, Quick task, Diagnose, UI Prototype or Revise plan from the dashboard with it and send the box it fills (an idea box marked `fill: "note"`, up to five ticked pictures attached), which then marks the tab sent via `POST /notepad/tab/sent`; the agent CLI never imports the store; removed only through Cleanup once a month untouched), **Activities** behind the top bar's die (thirteen small games, Snake, Mini golf, Light Trails, Bug Hunt, Sunset Drive, Stack Deploy, Bumper Ring, Rapids Run, Hot Potato, Crossing Rush, Bounce Road, Ghoul Rush and Flock Dash, listed in `public/activities.js` with one module per game under `public/activities/` (Ghoul Rush is its own folder of modules, `public/activities/ghoul-rush/`) and a card line (`blurb`) each, a picker of game rows in two columns, ordered Recently played or A to Z (saved in `activityOrder`), with never-picked games under Not played yet, once two are listed, that plays one game at a time (another pick drops the last game's round), driven by `screens/activities.js` (keys, key releases for a game with `release()`, canvas pointer events for a game with `pointer()`, one frame timer), paused whenever the person's turn comes and resumed only by the person (while that pause's banner is up, only by its **Unpause game** button), best scores in flat `activityBest` keys in `looks.json` (and the time each game was last picked in `activityPlayed`) (lowest wins for a game that sets `lowerIsBetter`; Mini golf opens on a dashboard of its six 18-hole courses, one file each under `public/activities/golf-course-.js`, and keeps a best per course, `activityBestGolf`), and one number a game may keep between sessions in `activityMemo` (Snake's tally of surprises found, Light Trails' furthest arena, Bug Hunt's tally of finds, Sunset Drive's roads found, Stack Deploy's highest floor, Bumper Ring's furthest arena, Rapids Run's furthest dam, Hot Potato's furthest venue, Crossing Rush's furthest zone, Bounce Road's furthest stage, Ghoul Rush's most stages cleared in a run, Flock Dash's furthest stage), never shown to the agent), a built-in 23-topic Help, the app-only **Implementation Loop** (a dashboard card and a setup screen drawn by the page, `public/screens/loop-setup.js`; the last setup remembered per project in `~/.plan2code/console/loop-setup.json`, owned by `loop-setup.mjs`; a page that locks while `state.loop.driving` is set, until the app posts `loopEnd`; a skill run with `--loop` reports a `loopOutcome` instead of asking for sign-off, per `notes/loop.md`), a first-run Welcome, User Preferences (gear: four tabs, Appearance, Agents & models, System and Sounds & activities, on the `public/tabs.js` helper Help also uses, with `public/prefs.js`, `screens/prefs-dialog.js` and `screens/agents-view.js`), an agent-less **setup** page (the `setup` workflow `plan2code` or the desktop app opens when no agent can run: each built-in's found / outside-PATH / missing state from `agent-lookup.mjs`, install lines, Check again, Use it from here, starter templates and Start, which hands the tab to the new agent through a token-guarded `POST /handover` and a `move` event; the app shows it in its window from a Set up an agent button instead) and a bug/idea link to GitHub issues. On opted-in skills (every workflow but the dashboard, setup, Changelog, Git, Handoff and UI Prototype) a **Subagents** button in the top bar turns helpers on or off per project and skill (on by default for those skills until switched off, saved in `~/.plan2code/console/subagents.json`), and a Helper strength choice (Balanced, Thrifty, Best, Match my session; rules in `src/shared-references/helper-strength.md`, shipped in the seventeen helper skills); the agent hears of it as a standing instruction only when it changes, and reports its helpers in a **Subagents** tab beside Ask (contract in `console-subagents.md`). Per-skill facts live in one list, `public/skills.js`, from which the meter, the resume command, Help's card list and the CLI's workflow list are derived; task files are read through `spec-files.mjs` (shared with the `specs.mjs` skill script), and the rule for which hops start the page clean is `startsClean()` in `public/hops.js`. The agent contract is a card plus pointers: `console.md` (the card) once per conversation, then a topic file (`console-*.md` such as `console-docs.md`, `notes/.md`, `building*.md`) only when the console names it in its own `read` output, once per session per topic (remembered in `pointers.json` in the session folder, owned by `pointers.mjs`); the console refuses the slips it can see (a `stop` with no `finish`, a `finish` while `stopWarning` is set, with `stop --force` for a dead page) instead of the docs repeating each rule. Byte budgets for the card, every notes file and a sample session's outputs run in `npm test` (`scripts/test-console-wire-budgets.mjs`). The server never writes into a project; the one thing it deletes there is an old `specs--completed/` the person picks in Cleanup, and only when git tracks it (an untracked one is refused, with the reason on the page). 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`. diff --git a/scripts/test-web-console-git-board.mjs b/scripts/test-web-console-git-board.mjs index fbc3071..bbb57c9 100644 --- a/scripts/test-web-console-git-board.mjs +++ b/scripts/test-web-console-git-board.mjs @@ -12,7 +12,10 @@ import { JOURNEYS, NOW, STATES } from "./fixtures/git-board-states.mjs"; import { BRANCH_TYPES, GIT_TABS, + PATH_STOPS, + boardPath, busyMode, + cardShowsFiles, commitTicks, controlAllowed, createSources, @@ -30,10 +33,7 @@ const ROLES = ["nav", "action", "done"]; const TAB_IDS = GIT_TABS.map((t) => t.id); const step = (id) => nextStep(STATES[id].git, { now: NOW }); -const badges = (id) => { - const s = step(id); - return tabBadges(STATES[id].git, { now: NOW, stepTab: s.tab }); -}; +const badges = (id) => tabBadges(STATES[id].git, { now: NOW }); test("git board rules: every sample state gives its expected primary, secondary and tab", () => { for (const [id, s] of Object.entries(STATES)) { @@ -88,14 +88,14 @@ test("git board rules: no default branch means no clean-up step or badge, as boa const noDefault = { ...git, defaultBranch: null, branches: git.branches.map((b) => ({ ...b, default: false, merged: false, gone: b.current ? b.gone : b.name === "chore/bump-deps" })) }; const n = nextStep(noDefault, { now: NOW }); assert.ok(![n.primary, ...n.secondary].some((s) => s && s.op === "cleanup")); - assert.equal(tabBadges(noDefault, { now: NOW, stepTab: n.tab }).branches, null); + assert.equal(tabBadges(noDefault, { now: NOW }).branches, null); }); test("git board badges: no 'not published' badge before the first commit, even with a remote", () => { const git = { ...STATES["e-first-commit"].git, remotes: STATES["cp-dirty"].git.remotes, lastFetch: STATES["cp-dirty"].git.lastFetch }; const n = nextStep(git, { now: NOW }); assert.equal(n.primary.op, "commit"); - assert.equal(tabBadges(git, { now: NOW, stepTab: n.tab }).sync, null); + assert.equal(tabBadges(git, { now: NOW }).sync, null); }); test("git board rules: the stale line never changes the step, and needs a remote", () => { @@ -142,20 +142,20 @@ test("git board rules: on the default branch, a branch is suggested and committi assert.equal(n.secondary[0].tab, "changes"); }); -test("git board badges: each tab badges what it has waiting, and the next step's tab is filled", () => { +test("git board badges: each tab badges what it has waiting", () => { const dirty = badges("cp-dirty"); - assert.deepEqual([dirty.changes.text, dirty.changes.kind, dirty.changes.next], ["3", "count", true]); - assert.equal(dirty.changes.label, "3 waiting, next step"); + assert.deepEqual([dirty.changes.text, dirty.changes.kind, dirty.changes.next], ["3", "count", false]); + assert.equal(dirty.changes.label, "3 waiting"); assert.equal(dirty.branches.text, "2"); assert.equal(dirty.branches.next, false); assert.equal(dirty.sync, null); const held = badges("e-held-only"); - assert.deepEqual([held.changes.kind, held.changes.text, held.changes.next], ["dot", "·", false], "no primary, so no filled badge"); + assert.deepEqual([held.changes.kind, held.changes.text, held.changes.next], ["dot", "·", false]); assert.equal(badges("e-many-branches").branches.text, "40"); assert.equal(badges("pc-diverged").sync.text, "↑1 ↓3"); - assert.equal(badges("pc-diverged").sync.label, "1 to push, 3 to pull, next step"); + assert.equal(badges("pc-diverged").sync.label, "1 to push, 3 to pull"); assert.equal(badges("nb-unpublished").sync.text, "↑"); assert.equal(badges("e-gone").sync.text, "↑"); assert.equal(badges("e-stale").sync.text, "?"); @@ -168,12 +168,6 @@ test("git board badges: each tab badges what it has waiting, and the next step's assert.equal(conflict.branches, null); }); -test("git board badges: a tab owning the step with nothing of its own gets a filled dot", () => { - const b = badges("cp-pushed"); - assert.deepEqual([b.sync.kind, b.sync.text, b.sync.next], ["dot", "·", true]); - assert.equal(b.sync.label, "next step"); -}); - test("git board busy: offline beats running beats a waiting card", () => { for (let bits = 0; bits < 16; bits++) { const f = { running: Boolean(bits & 1), cardWaiting: Boolean(bits & 2), gone: Boolean(bits & 4), pending: Boolean(bits & 8) }; @@ -299,7 +293,7 @@ function fakeOn() { const rec = (name) => (...args) => calls.push([name, ...args]); return { calls, - send: rec("send"), redraw: rec("redraw"), pickTab: rec("pickTab"), openPanel: rec("openPanel"), + send: rec("send"), redraw: rec("redraw"), pickTab: rec("pickTab"), openPanel: rec("openPanel"), toggleTools: rec("toggleTools"), closePanel: rec("closePanel"), pickPrHost: rec("pickPrHost"), persist: rec("persist"), }; } @@ -318,13 +312,14 @@ const seedCreate = (git, commit = false) => ({ // The panels each tab can draw; "create-commit" is the create panel in commit mode, on Changes. const PANELS = { changes: [null, "commit", "create-commit"], branches: [null, "create", "cleanup"], sync: [null] }; -function draw(id, { mode = "idle", tab = null, panel = null, create = null } = {}) { +function draw(id, { mode = "idle", tab = null, panel = null, create = null, tools = false } = {}) { const s = STATES[id]; const git = s.git; const step = nextStep(git, { now: NOW }); - const badges = tabBadges(git, { now: NOW, stepTab: step.tab }); + const badges = tabBadges(git, { now: NOW }); const board = { tab, + tools, panel: panel === "create-commit" ? "create" : panel, create: create || (panel === "create" ? seedCreate(git) : panel === "create-commit" ? seedCreate(git, true) : null), ticks: null, ignore: new Set(), sweep: null, query: "", showAll: false, remoteOpen: null, base: null, @@ -353,7 +348,7 @@ const words = (n) => n.textContent.trim() || (n.parent && n.parent.tag === "labe function* everyRender(modes = ["idle", "running", "card", "offline"]) { for (const id of Object.keys(STATES)) { for (const mode of modes) { - for (const tab of TAB_IDS) for (const panel of PANELS[tab]) yield { id, mode, tab, panel, r: draw(id, { mode, tab, panel }) }; + for (const tab of TAB_IDS) for (const panel of PANELS[tab]) yield { id, mode, tab, panel, r: draw(id, { mode, tab, panel, tools: true }) }; } } } @@ -378,7 +373,7 @@ test("git board view: no control leaks the busy lock, in any state, mode, tab or assert.ok(checked > 1000, "the guard looked at the board's controls"); }); -test("git board view: every function of today's board is reachable on some tab", () => { +test("git board view: every function of today's board is reachable in the card or the tools", () => { const texts = new Set(); const ids = { select: new Set(), input: new Set() }; const take = (r) => { @@ -389,7 +384,7 @@ test("git board view: every function of today's board is reachable on some tab", }; for (const { r } of everyRender(["idle"])) take(r); // A name that is taken offers Switch to it. - take(draw("cp-dirty", { tab: "branches", panel: "create", create: { ...seedCreate(STATES["cp-dirty"].git), name: "main" } })); + take(draw("cp-dirty", { tools: true, tab: "branches", panel: "create", create: { ...seedCreate(STATES["cp-dirty"].git), name: "main" } })); // Exact, except the labels that carry a count ("Commit 3 files", "Show all 179"). const has = (want, prefix = false) => [...texts].some((t) => t === want || (prefix && t.startsWith(`${want} `))); @@ -433,17 +428,11 @@ test("git board view: pins on its source and on a few states", () => { const conflict = controls(draw("pc-conflict").node).filter((c) => c.textContent.startsWith("Abort")); assert.equal(conflict.length, 1, "mid-rebase, Abort is offered once"); - const held = draw("e-held-only", { tab: "changes" }); + const held = draw("e-held-only"); const strip = walk(held.node).find((n) => n.classes.has("git-step")); - assert.ok(strip, "the step strip is on Changes"); + assert.ok(strip, "the task card is drawn"); assert.ok(walk(strip).find((n) => n.classes.has("git-held")).textContent.includes("`.env.local` held back")); assert.ok(controls(strip).some((c) => c.textContent === "Add `.env.local` to .gitignore"), "the ignore offer is the secondary"); - - const away = draw("cp-dirty", { tab: "sync" }); - const hint = walk(away.node).find((n) => n.classes.has("git-hint")); - assert.ok(hint, "a tab that does not own the step points at it"); - assert.ok(hint.textContent.includes("Commit 3 files")); - assert.ok(hint.textContent.startsWith("Next step is on Changes:")); }); test("git board view: a working line carries the spinner, and only while running", () => { @@ -451,14 +440,14 @@ test("git board view: a working line carries the spinner, and only while running const spun = (n) => n.children.some((c) => c.classes.has("spinner") && c.classes.has("tiny")); const busy = lines(draw("cp-committing", { mode: "running", tab: "changes" })); - assert.equal(busy.length, 2, "the header and the step strip both say what is under way"); + assert.equal(busy.length, 2, "the header and the task card both say what is under way"); for (const n of busy) { assert.ok(spun(n), `"${n.textContent}" has a spinner`); assert.equal(n.textContent, "Committing 3 files on feature/ABC-12001-export-csv"); } const quiet = lines(draw("cp-dirty", { mode: "running", tab: "changes" })); - assert.equal(quiet.length, 1, "with no activity, only the step strip speaks"); + assert.equal(quiet.length, 1, "with no activity, only the task card speaks"); assert.ok(spun(quiet[0])); assert.equal(quiet[0].textContent, "Plan2Code is working on it."); @@ -466,7 +455,8 @@ test("git board view: a working line carries the spinner, and only while running }); const click = (n) => n.listeners.click.forEach((fn) => fn()); -const stepButtons = (r) => controls(walk(r.node).find((n) => n.classes.has("git-step"))); +// The card's buttons (and links), not the file table's ticks inside it. +const stepButtons = (r) => controls(walk(r.node).find((n) => n.classes.has("git-step"))).filter((c) => c.tag !== "input"); test("git board view: each step's click goes out as the board offers it", () => { const held = draw("e-held-only"); @@ -482,10 +472,10 @@ test("git board view: each step's click goes out as the board offers it", () => click(branch); click(onMain); const mainFiles = [...commitTicks(STATES["nb-main-dirty"].git.changes)]; - assert.deepEqual(main.on.calls, [["openPanel", "create", { commit: true }], ["send", "commit", { files: mainFiles, ignore: [] }]]); + assert.deepEqual(main.on.calls, [["openPanel", "create", { commit: true, files: mainFiles, ignore: [] }], ["send", "commit", { files: mainFiles, ignore: [] }]]); - // The commit table is always on show below the step, so the step's Commit - // sends what the table has ticked rather than "opening" a panel already open. + // The commit table is in the card, so the card's Commit sends what it has + // ticked rather than "opening" a panel already open. const dirty = draw("cp-dirty", { tab: "changes" }); const ticked = [...commitTicks(STATES["cp-dirty"].git.changes)]; const top = stepButtons(dirty).find((c) => c.textContent.startsWith("Commit ")); @@ -497,7 +487,7 @@ test("git board view: each step's click goes out as the board offers it", () => unticked.board.ticks.clear(); const redrawn = drawGitBoard({ git: STATES["cp-dirty"].git, board: unticked.board, now: NOW, mode: "idle", step: unticked.step, - badges: tabBadges(STATES["cp-dirty"].git, { now: NOW, stepTab: unticked.step.tab }), notice: null, activity: null, hasCard: false, h: fakeH(), on: fakeOn(), + badges: tabBadges(STATES["cp-dirty"].git, { now: NOW }), notice: null, activity: null, hasCard: false, h: fakeH(), on: fakeOn(), }); const none = controls(walk(redrawn.node).find((n) => n.classes.has("git-step"))).find((c) => c.textContent.startsWith("Commit ")); assert.ok(none.disabled, "nothing ticked: the step's Commit is grayed, like the table's"); @@ -506,14 +496,13 @@ test("git board view: each step's click goes out as the board offers it", () => one.board.ticks = new Set([ticked[0]]); const again = drawGitBoard({ git: STATES["cp-dirty"].git, board: one.board, now: NOW, mode: "idle", step: one.step, - badges: tabBadges(STATES["cp-dirty"].git, { now: NOW, stepTab: one.step.tab }), notice: null, activity: null, hasCard: false, h: fakeH(), on: fakeOn(), + badges: tabBadges(STATES["cp-dirty"].git, { now: NOW }), notice: null, activity: null, hasCard: false, h: fakeH(), on: fakeOn(), }); const card = walk(again.node).find((n) => n.classes.has("git-step")); assert.equal(walk(card).find((n) => n.classes.has("git-step-title")).textContent, "Commit 1 file", "the card's title follows the ticks too"); - const away = draw("pc-conflict", { tab: "changes" }); - click(walk(away.node).find((n) => n.classes.has("git-hint"))); - assert.deepEqual(away.on.calls, [["pickTab", "sync"]]); + const fix = draw("pc-conflict"); + assert.ok(!walk(fix.node).some((n) => n.classes.has("git-hint")), "no hint pointing at another tab"); const op = draw("pc-conflict"); const opButtons = controls(walk(op.node).find((n) => n.classes.has("git-op"))); @@ -525,10 +514,10 @@ test("git board view: a .gitignore-only pick commits just .gitignore, and never const ignoreHeld = (git) => ({ ...git, changes: STATES["e-held-only"].git.changes }); const opened = (git) => { const step = nextStep(git, { now: NOW }); - const board = { tab: "changes", panel: "commit", create: null, ticks: new Set(), ignore: new Set([".env.local"]), sweep: null, query: "", showAll: false, remoteOpen: null, base: null }; + const board = { tab: "changes", tools: true, panel: "commit", create: null, ticks: new Set(), ignore: new Set([".env.local"]), sweep: null, query: "", showAll: false, remoteOpen: null, base: null }; const h = fakeH(); const on = fakeOn(); - const { node } = drawGitBoard({ git, board, now: NOW, mode: "idle", step, badges: tabBadges(git, { now: NOW, stepTab: step.tab }), notice: null, activity: null, h, on }); + const { node } = drawGitBoard({ git, board, now: NOW, mode: "idle", step, badges: tabBadges(git, { now: NOW }), notice: null, activity: null, h, on }); return { node, on }; }; @@ -589,12 +578,12 @@ test("git board docs: the agent prose, Help topic and readme describe the tabbed assert.ok(!read("../.readme/web-console.md").includes("commits on one page"), "the readme no longer says commits on one page"); }); -test("git board view: a landed result splits the step strip into Just landed and Still on the tree", () => { +test("git board view: a landed result splits the task card into Just landed and Still on the tree", () => { const landed = (id, notice) => { const s = STATES[id]; const git = s.git; const step = nextStep(git, { now: NOW }); - const badges = tabBadges(git, { now: NOW, stepTab: step.tab }); + const badges = tabBadges(git, { now: NOW }); const board = { tab: null, panel: null, create: null, ticks: null, ignore: new Set(), sweep: null, query: "", showAll: false, remoteOpen: null, base: null }; const h = fakeH(); const on = fakeOn(); @@ -625,3 +614,141 @@ test("git board view: a landed result splits the step strip into Just landed and const duoClean = walk(clean.node).find((n) => n.classes.has("git-duo")); assert.ok(duoClean, "zones still draw when nothing is left to commit"); }); + +/* ------------------------------------------------- the guided path */ + +// Where each sample state sits on the path: the current stop, or null when +// nothing is left (every stop done) or an operation has paused the path. +const PATH_AT = { + "cp-dirty": "save", "cp-committing": "save", "cp-ahead": "share", "cp-pushing": "share", "cp-pushed": "review", + "nb-main-dirty": "save", "nb-creating": "save", "nb-unpublished": "share", "nb-publishing": "share", "nb-published": "review", + "pc-diverged": "share", "pc-pulling": "share", "pc-conflict": null, "pc-resolved": null, "pc-continuing": null, + "pc-rebased": "share", "pc-pushing": "share", "pc-pushed": "review", + "e-caught-up": null, "e-stale": null, "e-held-only": null, "e-gone": "share", "e-no-remote": null, + "e-first-commit": "save", "e-detached": "save", "e-many-branches": "tidy", +}; + +test("git board path: four stops, Save, Share, Review and Tidy, in that order", () => { + assert.deepEqual(PATH_STOPS.map((s) => [s.id, s.label]), [["save", "Save"], ["share", "Share"], ["review", "Review"], ["tidy", "Tidy"]]); + for (const s of PATH_STOPS) assert.ok(typeof s.hint === "string" && s.hint.length > 0, `${s.id} has a hint`); +}); + +test("git board path: every sample state lands on its stop; stops before it are done, after it still to do", () => { + assert.deepEqual(Object.keys(PATH_AT).sort(), Object.keys(STATES).sort(), "every sample state has an expected stop"); + const ids = PATH_STOPS.map((s) => s.id); + for (const [id, s] of Object.entries(STATES)) { + const p = boardPath(s.git, nextStep(s.git, { now: NOW })); + assert.equal(p.current, PATH_AT[id], `${id}: current stop`); + assert.equal(p.paused, Boolean(s.git.inProgress), `${id}: paused only mid-operation`); + assert.deepEqual(p.stops.map((x) => x.id), ids, `${id}: stops in order`); + const at = ids.indexOf(p.current); + p.stops.forEach((x, i) => { + const want = p.paused ? "todo" : p.current === null ? "done" : i < at ? "done" : i === at ? "now" : "todo"; + assert.equal(x.state, want, `${id}: ${x.id} is ${want}`); + }); + } +}); + +test("git board path: the card shows the file table only on a Save stop that commits", () => { + const shows = (id) => cardShowsFiles(STATES[id].git, nextStep(STATES[id].git, { now: NOW })); + for (const id of ["cp-dirty", "nb-main-dirty", "e-first-commit"]) assert.equal(shows(id), true, id); + for (const id of ["e-detached", "e-held-only", "pc-conflict", "cp-ahead", "e-caught-up"]) assert.equal(shows(id), false, id); +}); + +test("git board path: the branch-and-commit step's button says what it does", () => { + const s = step("nb-main-dirty"); + assert.equal(s.primary.label, "Start a branch for 2 files"); + assert.equal(s.primary.action, "Start a branch and commit"); +}); + +test("git board badges: no tab is marked as the next step any more", () => { + for (const id of Object.keys(STATES)) { + const b = tabBadges(STATES[id].git, { now: NOW }); + for (const t of TAB_IDS) assert.ok(!b[t] || b[t].next === false, `${id}: ${t} is not marked next`); + } + assert.equal(tabBadges(STATES["cp-pushed"].git, { now: NOW }).sync, null, "a tab with nothing of its own has no badge"); +}); + +test("git board view: the path, one task card and a closed tools fold-out lead the board", () => { + for (const id of Object.keys(STATES)) { + const r = draw(id); + const nodes = walk(r.node); + const path = nodes.find((n) => n.classes.has("git-route")); + assert.ok(path, `${id}: the path is drawn`); + assert.equal(path.children.length, 4, `${id}: four stops`); + const now = path.children.filter((c) => c.classes.has("is-now")); + assert.equal(now.length, PATH_AT[id] ? 1 : 0, `${id}: one current stop at most`); + if (PATH_AT[id]) assert.ok(now[0].textContent.includes(PATH_STOPS.find((s) => s.id === PATH_AT[id]).label), `${id}: the right stop is current`); + assert.equal(nodes.filter((n) => n.classes.has("git-step")).length, 1, `${id}: exactly one task card`); + assert.ok(!nodes.some((n) => n.classes.has("git-hint")), `${id}: no "Next step is on" hint`); + const tools = nodes.find((n) => n.classes.has("git-toolbox")); + assert.ok(tools, `${id}: the tools fold-out is there`); + const toggle = controls(tools).find((c) => c.classes.has("git-toolbox-toggle")); + assert.equal(toggle.attrs["aria-expanded"], "false", `${id}: closed by default`); + assert.equal(toggle.attrs["data-gate"], "nav", `${id}: opening it is never locked`); + assert.ok(!nodes.some((n) => n.classes.has("git-tabs")), `${id}: no tab strip while closed`); + const head = r.node.children.find((c) => c.tag === "header"); + assert.ok(controls(head).some((c) => c.textContent === "Done with git"), `${id}: Done with git sits in the header`); + } + const paused = walk(draw("pc-conflict").node).find((n) => n.classes.has("git-route")); + assert.ok(paused.classes.has("is-paused"), "mid-rebase the path is paused"); +}); + +test("git board view: opening the fold-out shows the tabs and the active tab's panel", () => { + const r = draw("cp-ahead", { tools: true, tab: "branches" }); + const nodes = walk(r.node); + const toggle = nodes.find((n) => n.classes.has("git-toolbox-toggle")); + assert.equal(toggle.attrs["aria-expanded"], "true"); + assert.ok(nodes.some((n) => n.classes.has("git-tabs")), "the tab strip is inside"); + assert.ok(nodes.some((n) => n.id === "git-panel-branches"), "the Branches panel is drawn"); + click(toggle); + assert.deepEqual(r.on.calls, [["toggleTools"]], "the toggle asks the host to flip it"); +}); + +test("git board view: on a Save stop the file table sits in the task card, with one set of commit buttons", () => { + const main = draw("nb-main-dirty", { tools: true, tab: "changes" }); + const card = walk(main.node).find((n) => n.classes.has("git-step")); + assert.ok(walk(card).some((n) => n.classes.has("git-files")), "the file table is in the card"); + const labels = controls(main.node).map((c) => words(c)); + assert.equal(labels.filter((t) => t === "Start a branch and commit").length, 1, "one branch-and-commit button"); + assert.equal(labels.filter((t) => t === "Commit on main").length, 1, "one commit-on-main button"); + assert.ok(!labels.includes("Create branch"), "the table's old You're on main buttons are gone"); + const changes = walk(main.node).find((n) => n.id === "git-panel-changes"); + assert.ok(!walk(changes).some((n) => n.classes.has("git-files")), "the Changes tab does not draw the table twice"); + assert.ok(changes.textContent.includes("in the Save step above"), "the Changes tab points at the card"); + + const dirty = draw("cp-dirty", { tools: true, tab: "changes" }); + assert.equal(controls(dirty.node).filter((c) => /^Commit \d+ files?$/.test(c.textContent)).length, 1, "one Commit N files button"); + + const detached = draw("e-detached", { tools: true, tab: "changes" }); + const dCard = walk(detached.node).find((n) => n.classes.has("git-step")); + assert.ok(!walk(dCard).some((n) => n.classes.has("git-files")), "no table in a card that is not committing"); +}); + +test("git board view: mid-operation the card is the operation, and Sync does not repeat it", () => { + const r = draw("pc-conflict", { tools: true, tab: "sync" }); + const card = walk(r.node).find((n) => n.classes.has("git-step")); + assert.ok(card.classes.has("git-op"), "the card lists the files and the two buttons"); + assert.equal(controls(r.node).filter((c) => c.textContent.startsWith("Abort")).length, 1, "Abort once, tools open or not"); + assert.equal(controls(r.node).filter((c) => c.textContent === "Continue").length, 1, "Continue once"); +}); + +test("git board view: with only .gitignore picks, the card commits just .gitignore", () => { + const r = draw("cp-dirty"); + r.board.ticks = new Set(); + r.board.ignore = new Set([".env.local"]); + const git = STATES["cp-dirty"].git; + const on = fakeOn(); + const { node } = drawGitBoard({ git, board: r.board, now: NOW, mode: "idle", step: r.step, badges: tabBadges(git, { now: NOW }), notice: null, activity: null, hasCard: false, h: fakeH(), on }); + const card = walk(node).find((n) => n.classes.has("git-step")); + assert.equal(walk(card).find((n) => n.classes.has("git-step-title")).textContent, "Add 1 to .gitignore", "the title says what the click does"); + const add = controls(card).filter((c) => c.tag !== "input").find((c) => c.textContent === "Add 1 to .gitignore"); + assert.ok(add && !add.disabled, "the card's button is live with only a .gitignore pick"); + click(add); + assert.deepEqual(on.calls, [["send", "commit", { files: [], ignore: [".env.local"] }]]); + + r.board.ignore = new Set(); + const empty = drawGitBoard({ git, board: r.board, now: NOW, mode: "idle", step: r.step, badges: tabBadges(git, { now: NOW }), notice: null, activity: null, hasCard: false, h: fakeH(), on: fakeOn() }); + const none = controls(walk(empty.node).find((n) => n.classes.has("git-step"))).find((c) => c.textContent === "Commit 0 files"); + assert.ok(none && none.disabled, "nothing ticked and nothing to ignore: grayed"); +}); diff --git a/scripts/test-web-console-page-git.mjs b/scripts/test-web-console-page-git.mjs index 2c6a745..a8fbb39 100644 --- a/scripts/test-web-console-page-git.mjs +++ b/scripts/test-web-console-page-git.mjs @@ -1,6 +1,6 @@ -// Page tests for the git board: the Changes, Branches and Sync tabs drawn -// from a real repository, each tab's content on show when it is picked. Run -// with: +// Page tests for the git board: the path, the task card and the Changes, +// Branches and Sync tabs inside the "All branches and tools" fold-out, drawn +// from a real repository. Run with: // node --test scripts/test-web-console-page-git.mjs // // Each test drives the real console in a real Chrome or Edge through @@ -35,13 +35,29 @@ function gitProject() { // so the console snapshots the repo, and the description of what changed. const BOARD = { reread: true, board: { describe: "export-more" } }; -test("the git board shows Changes, Branches and Sync, and each tab shows its own content", async (t) => { +// Opens the "All branches and tools" fold-out (closed on arrival) and waits for its tabs. +async function openTools(page) { + const toggle = page.locator(".git-toolbox-toggle"); + await toggle.waitFor(); + if ((await toggle.getAttribute("aria-expanded")) !== "true") await toggle.click(); + await page.getByRole("tablist").waitFor(); +} + +test("the git board leads with the path and one task card, and the tools hold Changes, Branches and Sync", async (t) => { const s = await openSession(await suite.browser(), { t, workflow: "git", project: gitProject(), payload: BOARD }); const { page } = s; const tab = (label) => page.getByRole("tab", { name: new RegExp(`^${label}\\b`) }); const panel = page.getByRole("tabpanel"); - await page.getByRole("tablist").waitFor(); + // On main with a changed file: the path is on Save, and the card carries the file. + const path = page.getByRole("list", { name: "Where you are" }); + await path.waitFor(); + assert.deepEqual((await path.locator(".git-stop-label").allInnerTexts()).map((x) => x.trim()), ["Save", "Share", "Review", "Tidy"]); + assert.match(await textOf(path.locator('[aria-current="step"]')), /Save/); + await page.locator(".git-step").getByText("src/app.js", { exact: true }).waitFor(); + assert.equal(await page.getByRole("tablist").count(), 0, "the tabs stay folded away on arrival"); + + await openTools(page); assert.deepEqual( (await page.getByRole("tab").allInnerTexts()).map((x) => x.trim().split(/\s/)[0]), ["Changes", "Branches", "Sync"] @@ -49,14 +65,14 @@ test("the git board shows Changes, Branches and Sync, and each tab shows its own await tab("Changes").click(); await page.waitForFunction(() => document.querySelector('[role="tab"][aria-selected="true"]')?.textContent.startsWith("Changes")); - await panel.getByText("src/app.js", { exact: true }).waitFor(); - assert.match(await textOf(panel), /src\/app\.js/); + await panel.getByText(/in the Save step above/).waitFor(); + assert.doesNotMatch(await textOf(panel), /src\/app\.js/, "the Changes tab does not list the files a second time"); await tab("Branches").click(); await panel.getByText("feature/export-csv").first().waitFor(); const branches = await textOf(panel); assert.match(branches, /feature\/export-csv/); - assert.doesNotMatch(branches, /src\/app\.js/, "the Branches tab still shows the changed files"); + assert.doesNotMatch(await textOf(panel), /in the Save step above/, "the Branches tab still shows the Changes tab"); await tab("Sync").click(); await panel.getByText(/nothing to sync/).waitFor(); @@ -68,12 +84,12 @@ test("the git board shows Changes, Branches and Sync, and each tab shows its own test("each git tab keeps its own scroll place, across a tab switch and an agent post", async (t) => { const s = await openSession(await suite.browser(), { t, workflow: "git", project: gitProject(), payload: BOARD }); const { page } = s; - await page.getByRole("tablist").waitFor(); + await openTools(page); await page.setViewportSize({ width: 1280, height: 260 }); const tab = (label) => page.getByRole("tab", { name: new RegExp(`^${label}\\b`) }); const column = () => page.locator("#main").evaluate((el) => el.scrollTop); await tab("Changes").click(); - await page.getByRole("tabpanel").getByText("src/app.js", { exact: true }).waitFor(); + await page.getByRole("tabpanel").getByText(/in the Save step above/).waitFor(); await scrollCard(page.locator("#main"), 120); const changesAt = await column(); assert.ok(changesAt > 0, "the board's column scrolls"); @@ -82,7 +98,7 @@ test("each git tab keeps its own scroll place, across a tab switch and an agent await page.getByRole("tabpanel").getByText("feature/export-csv").first().waitFor(); assert.equal(await column(), 0, "Branches opened at the place Changes was left"); await tab("Changes").click(); - await page.getByRole("tabpanel").getByText("src/app.js", { exact: true }).waitFor(); + await page.getByRole("tabpanel").getByText(/in the Save step above/).waitFor(); assert.equal(await column(), changesAt, "Changes lost its place across the switch"); // An agent post redraws the board: still the same place. s.post({ title: "Git, take two" }); @@ -121,15 +137,16 @@ const tabButton = (page, label) => page.getByRole("tab", { name: new RegExp(`^${ const tickBox = (page, file) => page.getByLabel(`Commit ${file}`); // The Branches tab's Switch button, for the one other branch. const switchButton = (page) => page.getByRole("tabpanel").getByRole("button", { name: "Switch" }); -// The board's step button, in the strip above the tab's content. +// The task card's button, under the path. const stepButton = (page, name) => page.locator(".git-step-actions").getByRole("button", { name }); -// Whether the board's own controls (not its tabs or the pointer to another -// tab) are all off, or at least one is on. Whatever tab the board has moved to, -// a locked board has every one of them disabled. -const boardControls = (page) => page.locator(".git-panel-tab").locator("button, input[type=checkbox], select"); +// Whether the board's own controls (not its tabs, the tools toggle or Done +// with git, nor the agent's own cards in the card slot) are all off, or at least one is on. A locked board has every one +// of them disabled, in the card and in the tools alike. +const boardControls = (page) => + page.locator(".git-board > :not(.git-cards)").locator("button:not(.git-tab):not(.git-toolbox-toggle):not(.git-done), input[type=checkbox], select"); const usable = async (page) => { - const off = await boardControls(page).evaluateAll((all) => all.filter((x) => !x.classList.contains("git-hint")).map((x) => x.disabled)); + const off = await boardControls(page).evaluateAll((all) => all.map((x) => x.disabled)); return off.some((x) => !x); }; // The board redraws a moment after its cause, so each check gets time to settle. @@ -140,10 +157,9 @@ const titled = (page, text) => page.waitForFunction((x) => document.getElementBy test("the next step's Commit sends the files ticked in the table as one __git action, with its reply sentence", async (t) => { const s = await openSession(await suite.browser(), { t, workflow: "git", project: changesProject({ branch: "feature/x" }), payload: READY }); const { page } = s; - await page.getByRole("tablist").waitFor(); await stepButton(page, "Commit 2 files").waitFor(); await tickBox(page, "notes.md").uncheck(); - // The table is already on show below, so the step's button commits rather than opening it. + // The table is in the card, so the card's button commits rather than opening it. await stepButton(page, "Commit 1 file").click(); const got = s.wait(10); assert.equal(got.code, 0, "the agent collected the click"); @@ -154,6 +170,7 @@ test("the next step's Commit sends the files ticked in the table as one __git ac test("a board click is exactly one __git action", async (t) => { const s = await openSession(await suite.browser(), { t, workflow: "git", project: gitProject(), payload: READY }); const { page } = s; + await openTools(page); await tabButton(page, "Branches").click(); await switchButton(page).click(); const got = s.wait(10); @@ -168,6 +185,7 @@ test("a board click is exactly one __git action", async (t) => { test("the board stays locked from a click until the agent's next post, not just until it is collected", async (t) => { const s = await openSession(await suite.browser(), { t, workflow: "git", project: gitProject(), payload: READY }); const { page } = s; + await openTools(page); await tabButton(page, "Branches").click(); assert.ok(await settlesUsable(page, true), "the board is the person's before any click"); await switchButton(page).click(); @@ -212,7 +230,6 @@ test("the commit table keeps the person's ticks across an agent post, and a clic const dir = changesProject({ branch: "feature/x" }); const s = await openSession(await suite.browser(), { t, workflow: "git", project: dir, payload: READY }); const { page } = s; - await tabButton(page, "Changes").click(); await tickBox(page, "notes.md").uncheck(); // An agent post redraws the board: the person's tick stays off. s.post({ title: "Still looking", agent: { status: "waiting" } }); @@ -228,7 +245,6 @@ test("the commit table keeps the person's ticks across an agent post, and a clic fs.writeFileSync(path.join(dir, "later.md"), "Later.\n"); s.post({ reread: true, title: "Committed", agent: { status: "waiting" } }); await titled(page, "Committed"); - await tabButton(page, "Changes").click(); await tickBox(page, "later.md").waitFor(); assert.equal(await tickBox(page, "notes.md").isChecked(), true, "the click dropped the old picks, so the table was seeded afresh"); }); @@ -236,10 +252,10 @@ test("the commit table keeps the person's ticks across an agent post, and a clic test("starting a branch for the changes carries the files ticked in the commit table", async (t) => { const s = await openSession(await suite.browser(), { t, workflow: "git", project: changesProject(), payload: READY }); const { page } = s; - await tabButton(page, "Changes").click(); await tickBox(page, "notes.md").uncheck(); - await stepButton(page, /^Start a branch for/).click(); - const panel = page.locator(".git-panel"); + await stepButton(page, "Start a branch and commit").click(); + // The new-branch prompt opens in the card, where the files were ticked. + const panel = page.locator(".git-step .git-panel"); await panel.getByRole("heading", { name: "New branch for this commit" }).waitFor(); const create = panel.getByRole("button", { name: "Create", exact: true }); assert.ok(await settles(create, true), "a free name is composed from the description"); @@ -256,10 +272,11 @@ test("starting a branch for the changes carries the files ticked in the commit t test("a commit with no branch to land on carries the ticked files into the new branch", async (t) => { const s = await openSession(await suite.browser(), { t, workflow: "git", project: changesProject({ branch: "detached" }), payload: READY }); const { page } = s; + // Not a Save step that commits (it makes a branch first), so the table stays on the Changes tab. + await openTools(page); await tabButton(page, "Changes").click(); await tickBox(page, "notes.md").uncheck(); - // The step is on the Branches tab, and its Commit button finds no branch to commit on. - await tabButton(page, "Branches").click(); + // The card's quieter Commit finds no branch to commit on. await stepButton(page, "Commit 1 file").click(); const panel = page.locator(".git-panel"); await panel.getByRole("heading", { name: "New branch for this commit" }).waitFor(); @@ -277,6 +294,7 @@ test("Publish names a remote only when there is exactly one", async (t) => { const browser = await suite.browser(); const published = async (remotes) => { const s = await openSession(browser, { t, workflow: "git", project: changesProject({ branch: "feature/x", remotes }), payload: READY }); + await openTools(s.page); await tabButton(s.page, "Sync").click(); await s.page.locator(".git-sync-actions").getByRole("button", { name: "Publish" }).click(); const got = s.wait(10); @@ -313,13 +331,13 @@ test("over the git board a note box grows with its text, and the no-repo note on }); // The three W25 leftovers, checked against the current build. -test("the Changes tab offers one Commit N files, Send is gone with nothing to send, and Done with git sits outside the tablist", async (t) => { +test("the board offers one Commit N files, Send is gone with nothing to send, and Done with git sits in the header", async (t) => { const s = await openSession(await suite.browser(), { t, workflow: "git", project: changesProject({ branch: "feature/x" }), payload: READY }); const { page } = s; - await page.getByRole("tablist").waitFor(); await stepButton(page, "Commit 2 files").waitFor(); - // One Commit N files across the whole board, not one in the step and one in the table. - assert.equal(await page.getByRole("button", { name: /^Commit \d+ files?$/ }).count(), 1, "one commit button on the Changes tab"); + await openTools(page); + // One Commit N files across the whole board, tools open, not one in the card and one in the table. + assert.equal(await page.getByRole("button", { name: /^Commit \d+ files?$/ }).count(), 1, "one commit button on the board"); assert.equal(await page.locator(".git-panel-actions").getByRole("button", { name: /^Commit \d+ files?$/ }).count(), 0, "the table carries no second one"); // Unticking a file moves the one button's count. await tickBox(page, "notes.md").uncheck(); @@ -329,11 +347,12 @@ test("the Changes tab offers one Commit N files, Send is gone with nothing to se assert.equal(await page.locator("#btn-send").isHidden(), true, "no Send button on a board with nothing to send"); assert.match((await page.locator("#footer-summary").innerText()).trim(), /Nothing to send yet/, "the status words stay"); - // Done with git is beside the tablist, not one of its tabs, and at the right end of the row. + // Done with git is in the header, at the right end of the branch row, never inside the tools. const done = page.getByRole("button", { name: "Done with git" }); - assert.equal(await page.getByRole("tablist").getByRole("button", { name: "Done with git" }).count(), 0, "not inside the tablist"); - const [tabs, btn] = await Promise.all([page.getByRole("tablist").boundingBox(), done.boundingBox()]); - assert.ok(btn.x >= tabs.x + tabs.width - 1, "to the right of the tabs"); + assert.equal(await page.locator(".git-head").getByRole("button", { name: "Done with git" }).count(), 1, "in the header"); + assert.equal(await page.locator(".git-toolbox").getByRole("button", { name: "Done with git" }).count(), 0, "not inside the tools"); + const [row, btn] = await Promise.all([page.locator(".git-head-row").boundingBox(), done.boundingBox()]); + assert.ok(btn.x + btn.width >= row.x + row.width - 2, "at the right end of the row"); }); test("a card open on the board brings the Send button back", async (t) => { diff --git a/src/plan2code-git.md b/src/plan2code-git.md index 7d4ed1a..f48b1b4 100644 --- a/src/plan2code-git.md +++ b/src/plan2code-git.md @@ -94,7 +94,7 @@ In the terminal the same stops are asked in prose, with the diff printed. 1. **State.** Run `state`. Exit 3 → 1b. `inProgress` or `conflicted` → say what is in progress and go to Conflict help. 1b. **Not a repository.** Run `init-check`. `safe: false` → explain (inside another repository, the home folder or a drive root) and stop. `safe` → ask before `git init`, naming the folder and its first branch (`branch`, `main` unless `init.defaultBranch` says otherwise). On yes run `commands` in order (never a bare `git init`, which may start on `master`). If `hasGitignore` is false and `suggestedIgnore` is not empty, propose that `.gitignore` for approval, write it, then continue at 4 (the first commit; no push offer later because there is no remote; say it can be added with `git remote add origin `). 2. **Nothing to commit.** If `push` is not null, go to 7. Otherwise say the tree is clean and everything is pushed (or that there is no remote), and stop. -3. **Branch.** On the board, skip this: the page's **You're on main** line already offered it, and its answer arrives as `create` with `then: "commit"`. In the terminal, when `onDefault` (or `detached`) and `hasCommits`, offer one drafted branch name `/` (types: feature, fix, chore, docs, refactor, test; `feature/export-csv`). Run any name the person types through `branch-check`, then `plan create`. Skipping is always fine (on a detached HEAD, warn that commits there are easy to lose). When `defaultBranch` is null say why there is no offer. +3. **Branch.** On the board, skip this: the Save step's **Start a branch and commit** already offered it, and its answer arrives as `create` with `then: "commit"`. In the terminal, when `onDefault` (or `detached`) and `hasCommits`, offer one drafted branch name `/` (types: feature, fix, chore, docs, refactor, test; `feature/export-csv`). Run any name the person types through `branch-check`, then `plan create`. Skipping is always fine (on a detached HEAD, warn that commits there are easy to lose). When `defaultBranch` is null say why there is no offer. 4. **Read the changes.** `git diff`, `git diff --cached` and the untracked files (an `untracked` path ending in `/` is a folder: list its files with `git ls-files -o --exclude-standard -- ` and stage them by name). If the person staged some files, work from that staged set and leave the rest alone (say what was left). On the board, only the paths the action named, or every changed file on a hand-off. Decide whether the work is one concern or several. 5. **Message.** One concern: draft a subject, or use the argument and skip approval; ask **Yes** / **Edit** / **No**. Several: always suggest whole-file groups, each with a subject, naming any file that mixes concerns and which group took it; ask **Approve** / **Change it** / **One commit instead** (asked even when the subject came as the argument). Name the `sensitive` and `large` files you are leaving out. 6. **Commit.** For each group in order: with more than one group, run `git reset -q` first so only that group is staged; then run `commit-msg.mjs --subject "" --files --files ` (`--files` once per path) and its `command` (or `add`, then `commit`). Finish with `git log --oneline -`. On the console post `run: { "event": "git-commits", "id": "", "commits": }` with the `reread` and a `git-result` line naming the hashes with `op: "commit"`, so the board lights Push. diff --git a/src/web-console/notes/git.md b/src/web-console/notes/git.md index d18d951..52ace5c 100644 --- a/src/web-console/notes/git.md +++ b/src/web-console/notes/git.md @@ -49,7 +49,7 @@ An `auth` failure: a `notice` saying the tool never handles logins, with `next`. | `git init` | `confirm` naming folder and first branch (`init-check`'s `branch`, `danger:false`), `consequences` its `commands`. Run those, not a bare `git init`. | | `.gitignore` | The proposed file, or a `commit`'s `ignore[]` lines, as a doc plus `review`. | -Risky files (`sensitive`, `large`) go in the card's `body`. There is no branch-offer card: the commit panel's **You're on main** asks, answered as `create` with `then:"commit"`. +Risky files (`sensitive`, `large`) go in the card's `body`. There is no branch-offer card: on the default branch the board's Save step offers **Start a branch and commit**, answered as `create` with `then:"commit"`. **Conflict help.** A pull, rebase or merge stopped on conflicts: `choice` "Resolve them for me?": **Yes**, **I'll fix it**, **Abort pull**. On yes, each stop is doc `conflict` (replaced per stop: step N of M, the commit replayed, each file with a one-line reason, per-file diff) plus a `review` with a fresh id per stop, `"nothingYet":false`, verdicts `continue`, `change`, `abort` ("Abort pull", `danger`). Only **Continue** runs `plan continue`'s commands; **Abort pull** runs `plan abort`. A file you cannot resolve confidently keeps its markers, as does **I'll fix it**. A `continue` click from the board's banner means the files are fixed: run `plan continue`; on exit 5 (markers left) post a `reread` with its `message` as the `git-result`. End with a `notice` summary (commits replayed, each resolved file with its reason, "N commits ready to push"). diff --git a/src/web-console/public/git-board-view.js b/src/web-console/public/git-board-view.js index 677ddc8..b539f69 100644 --- a/src/web-console/public/git-board-view.js +++ b/src/web-console/public/git-board-view.js @@ -1,8 +1,10 @@ // Plan2Code Web Console - the tabbed git board's drawing. // -// drawGitBoard(ctx) builds the whole board -- header, tab strip, card slot, -// step strip and the Changes, Branches and Sync bodies -- from what -// git-board.js decides and what the host hands it. It decides nothing new: +// drawGitBoard(ctx) builds the whole board -- header (with Done with git), the +// path (Save, Share, Review, Tidy), the card slot, one task card for where the +// person is on it, and the "All branches and tools" fold-out holding the +// Changes, Branches and Sync tabs -- from what git-board.js decides and what +// the host hands it. It decides nothing new: // a rule belongs in git-board.js, a click goes out through ctx.on. // // No DOM access: every node comes from `ctx.h` (el, md, copyButton); the page @@ -24,8 +26,10 @@ import { NOT_CONNECTED, PR_HOST_LABELS, boardActions, + boardPath, boardBranchLink, boardPrLink, + cardShowsFiles, cleanupGroups, commitTicks, composeBranchName, @@ -101,8 +105,8 @@ export function activeTab(ctx) { /** * The whole board: `{ node, cardSlot }`. `node` is div.git-board holding the - * header, the result line, the tab strip, `cardSlot` (empty, for the host's - * cards) and the active tab's panel. + * header, the result line, the path, `cardSlot` (empty, for the host's + * cards), the task card and the tools fold-out (the tabs, while open). */ export function drawGitBoard(ctx) { const { git, h } = ctx; @@ -132,11 +136,12 @@ export function drawGitBoard(ctx) { } const tab = activeTab(ctx); node.appendChild(header(ctx)); - // A landed result (`op` set) lives in the step strip's two zones instead. + // A landed result (`op` set) lives in the task card's two zones instead. if (ctx.notice && !ctx.notice.op) node.appendChild(resultLine(ctx, ctx.notice)); - node.appendChild(tabStrip(ctx, tab)); + node.appendChild(pathStrip(ctx)); node.appendChild(cardSlot); - node.appendChild(tabPanel(ctx, tab)); + node.appendChild(taskCard(ctx)); + node.appendChild(toolsBox(ctx, tab)); return { node, cardSlot }; } @@ -170,6 +175,9 @@ function header(ctx) { ); if (remotes.length > 1 && cur && cur.upstreamRemote) row.appendChild(h.el("span", "pill is-accent is-caps badge", cur.upstreamRemote)); } + const done = control(ctx, "button", "btn sm git-done", "Done with git", { role: "done", onClick: () => ctx.on.send("done") }); + if (ctx.mode === "offline") done.title = ctx.offlineReason === "pending" ? "Your last click is still being picked up." : NOT_CONNECTED; + row.appendChild(done); box.appendChild(row); const meta = h.el("div", "git-head-meta"); @@ -221,18 +229,65 @@ function tabStrip(ctx, active) { b.appendChild(h.el("span", "git-tab-label", t.label)); const badge = ctx.badges && ctx.badges[t.id]; if (badge) { - b.appendChild(h.el("span", `git-tab-badge is-${badge.kind}${badge.next ? " is-next" : ""}`, badge.text)); + b.appendChild(h.el("span", `git-tab-badge is-${badge.kind}`, badge.text)); if (badge.label) b.setAttribute("aria-label", `${t.label}, ${badge.label}`); } strip.appendChild(b); } bar.appendChild(strip); - const done = control(ctx, "button", "btn sm git-done", "Done with git", { role: "done", onClick: () => ctx.on.send("done") }); - if (ctx.mode === "offline") done.title = ctx.offlineReason === "pending" ? "Your last click is still being picked up." : NOT_CONNECTED; - bar.appendChild(done); return bar; } +/* ---------------------------------------------------------------- path */ + +// The four stops, the current one lit. Plain marks, no controls: the task +// card under it is where the click is. +function pathStrip(ctx) { + const { h } = ctx; + const p = boardPath(ctx.git, ctx.step); + const ol = h.el("ol", "git-route" + (p.paused ? " is-paused" : "")); + ol.setAttribute("aria-label", p.paused ? "Where you are: paused until this is sorted" : "Where you are"); + p.stops.forEach((s, i) => { + const li = h.el("li", `git-stop is-${s.state}`); + if (s.state === "now") li.setAttribute("aria-current", "step"); + const mark = h.el("span", "git-stop-mark", s.state === "done" ? "✓" : String(i + 1)); + mark.setAttribute("aria-hidden", "true"); + li.appendChild(mark); + const words = h.el("span", "git-stop-words"); + words.appendChild(h.el("strong", "git-stop-label", s.label)); + words.appendChild(h.el("span", "git-stop-hint", s.hint)); + li.appendChild(words); + ol.appendChild(li); + }); + return ol; +} + +/* --------------------------------------------------------------- tools */ + +// Every action the path does not put front and center, folded away until +// the person opens it. Opening it is navigation, so it is never locked. +function toolsBox(ctx, tab) { + const { h } = ctx; + const open = Boolean(ctx.board && ctx.board.tools); + const box = h.el("section", "git-toolbox" + (open ? " is-open" : "")); + const toggle = control(ctx, "button", "git-toolbox-toggle", null, { role: "nav", onClick: () => ctx.on.toggleTools() }); + toggle.setAttribute("aria-expanded", open ? "true" : "false"); + toggle.setAttribute("aria-controls", "git-toolbox-body"); + const chev = h.el("span", "git-toolbox-chev", "›"); + chev.setAttribute("aria-hidden", "true"); + toggle.appendChild(chev); + toggle.appendChild(h.el("span", "git-toolbox-label", "All branches and tools")); + toggle.appendChild(h.el("span", "git-toolbox-sub", "Changes, Branches, Sync")); + box.appendChild(toggle); + if (!open) return box; + const body = h.el("div", "git-toolbox-body"); + body.id = "git-toolbox-body"; + body.appendChild(tabStrip(ctx, tab)); + body.appendChild(tabPanel(ctx, tab)); + box.appendChild(body); + return box; +} + /* ---------------------------------------------------------- tab panels */ function tabPanel(ctx, id) { @@ -240,13 +295,11 @@ function tabPanel(ctx, id) { panel.setAttribute("role", "tabpanel"); panel.id = `git-panel-${id}`; panel.setAttribute("aria-labelledby", `git-tab-${id}`); - const strip = stepStrip(ctx, id); - if (strip) panel.appendChild(strip); panel.appendChild(id === "changes" ? changesBody(ctx) : id === "branches" ? branchesBody(ctx) : syncBody(ctx)); return panel; } -/* ---------------------------------------------------------- step strip */ +/* ----------------------------------------------------------- task card */ // One step's click, as the board offers it. function runStep(ctx, s) { @@ -260,7 +313,7 @@ function runStep(ctx, s) { return on.send("commit", picks); } case "create-commit": - return on.openPanel("create", { commit: true }); + return on.openPanel("create", { commit: true, ...tablePicks(ctx) }); case "create": return on.openPanel("create"); case "cleanup": @@ -282,24 +335,24 @@ function runStep(ctx, s) { } } +// A commit step works on ticked files or .gitignore picks alone (the held-back +// offer leaves only those), so it grays only when both are empty. function stepButton(ctx, s, cls) { if (s.op === "pr") return prLink(ctx, s.url, cls); - const disabled = s.op === "commit" && !tablePicks(ctx).files.length; - return control(ctx, "button", cls, stepLabel(ctx, s), { disabled, onClick: () => runStep(ctx, s) }); + const ticking = s.op === "commit" || (s.op === "create-commit" && cardShowsFiles(ctx.git, ctx.step)); + const picks = tablePicks(ctx); + const disabled = ticking && !picks.files.length && !picks.ignore.length; + return control(ctx, "button", cls, s.action || stepLabel(ctx, s), { disabled, onClick: () => runStep(ctx, s) }); } // A step's name. A "Commit N files" count follows the table's ticks, so the -// card and its button say what the click will send. +// card and its button say what the click will send; with only .gitignore +// picks, the commit takes .gitignore alone and says so. function stepLabel(ctx, s) { if (!s || s.op !== "commit" || !/^Commit \d+ files?$/.test(s.label)) return s ? s.label : ""; - return `Commit ${plural(tablePicks(ctx).files.length, "file", "files")}`; -} - -// Whether the step strip over the Changes tab already carries a plain commit -// button (the same one the commit table would draw). -function stripCommits(ctx) { - const p = ctx.step && ctx.step.primary; - return Boolean(p && p.op === "commit" && ctx.step.tab === "changes"); + const { files, ignore } = tablePicks(ctx); + if (!files.length && ignore.length) return `Add ${ignore.length} to .gitignore`; + return `Commit ${plural(files.length, "file", "files")}`; } // The commit table's ticked files and .gitignore picks, checked against the snapshot. @@ -312,19 +365,16 @@ function tablePicks(ctx) { return { files: [...ticks].filter((path) => known.has(path)), ignore: [...ignored].filter((path) => known.has(path)) }; } -function stepStrip(ctx, id) { +// The one thing to do now, under the path. On a Save stop that commits it +// carries the file table (and, once asked, the new-branch prompt), so the +// person ticks and commits in one place. +function taskCard(ctx) { const { git, h, step } = ctx; const p = step.primary; - if (id !== step.tab) { - if (!p) return null; - const where = GIT_TABS.find((t) => t.id === step.tab); - return control(ctx, "button", "btn sm standby git-hint", `Next step is on ${where ? where.label : step.tab}: ${stepLabel(ctx, p)} →`, { - role: "nav", - onClick: () => ctx.on.pickTab(step.tab), - }); - } - // Mid-operation, Sync's own block is the step (syncBody). - if (id === "sync" && git.inProgress) return null; + // Mid-operation the card is the operation: its files and its two buttons. + if (git.inProgress) return opBlock(ctx); + const files = cardShowsFiles(git, step); + const creating = Boolean(files && ctx.board.panel === "create" && ctx.board.create && ctx.board.create.commit); // A landed result: the notice (it carries `op`) becomes the left zone and // the leftover step the right, muted, so the board reads "done, and this // much is not yours" rather than one loud suggestion to commit it all. @@ -357,6 +407,12 @@ function stepStrip(ctx, id) { held.appendChild(h.md(step.held, "md git-held-body")); left.appendChild(held); } + if (creating) { + left.appendChild(createPanel(ctx, false)); + duo.appendChild(left); + return duo; + } + if (files) left.appendChild(fileTable(ctx, false)); const acts = h.el("div", "git-step-actions"); if (theirs) { acts.appendChild(stepButton(ctx, { ...theirs, label: "Commit other changes" }, "btn primary")); @@ -369,7 +425,7 @@ function stepStrip(ctx, id) { duo.appendChild(left); return duo; } - const box = h.el("div", "git-step" + (git.inProgress ? " is-warn" : "") + (p ? "" : " is-calm")); + const box = h.el("div", "git-step" + (p ? "" : " is-calm")); box.appendChild(h.el("div", "git-step-kicker", p ? "Next step" : "Nothing to do")); box.appendChild(h.el("h3", "git-step-title", p ? stepLabel(ctx, p) : step.line)); if (p && p.why) box.appendChild(h.el("p", "git-step-why", p.why)); @@ -379,6 +435,11 @@ function stepStrip(ctx, id) { held.appendChild(h.md(step.held, "md git-held-body")); box.appendChild(held); } + if (creating) { + box.appendChild(createPanel(ctx, false)); + return box; + } + if (files) box.appendChild(fileTable(ctx, false)); if (ctx.mode === "running") { box.appendChild(activityLine(ctx, "p", ctx.activity || "Plan2Code is working on it.")); return box; @@ -425,6 +486,13 @@ function changesBody(ctx) { const body = h.el("div", "git-changes"); const frozen = Boolean(git.inProgress); if (frozen) body.appendChild(waitLine(ctx)); + // The task card already carries the table: say so rather than draw it twice. + if (cardShowsFiles(git, ctx.step)) { + const ch0 = git.changes || {}; + const n = list(ch0.files).length + list(ch0.untrackedDirs).length; + body.appendChild(h.el("p", "git-note", `Your ${plural(n, "changed file is", "changed files are")} in the Save step above.`)); + return body; + } if (board.panel === "create" && board.create && board.create.commit) { body.appendChild(createPanel(ctx, frozen)); return body; @@ -439,12 +507,12 @@ function changesBody(ctx) { return body; } -function commitPanel(ctx, frozen) { +// The commit table: one row per changed file or untracked folder, each with +// its tick and, for held-back files and folders, an Add to .gitignore toggle. +// Shared by the task card (on a Save stop) and the Changes tab. +function fileTable(ctx, frozen) { const { git, board, h, on } = ctx; const ch = git.changes || {}; - const first = git.hasCommits === false; - const opened = board.panel === "commit"; - const p = panelFrame(ctx, first ? "Make the first commit" : "Commit", { closable: opened, disabled: frozen }); const ticks = board.ticks || (board.ticks = commitTicks(ch)); const ignored = board.ignore || (board.ignore = new Set()); @@ -518,7 +586,15 @@ function commitPanel(ctx, frozen) { tbody.appendChild(tr); }); table.appendChild(tbody); - p.appendChild(table); + return table; +} + +function commitPanel(ctx, frozen) { + const { git, board, h, on } = ctx; + const first = git.hasCommits === false; + const opened = board.panel === "commit"; + const p = panelFrame(ctx, first ? "Make the first commit" : "Commit", { closable: opened, disabled: frozen }); + p.appendChild(fileTable(ctx, frozen)); const { files, ignore } = tablePicks(ctx); const send = () => on.send("commit", { files, ignore }); @@ -545,10 +621,7 @@ function commitPanel(ctx, frozen) { }) ); actions.appendChild(control(ctx, "button", "btn sm", `Commit on ${head.branch}`, { disabled: frozen || !files.length, onClick: send })); - } else if (!stripCommits(ctx)) { - // The step above this table already offers this same "Commit N files" (its - // count follows the ticks), so a second one here would be a duplicate; the - // table keeps its own only when the step is somewhere else. + } else { actions.appendChild( control(ctx, "button", "btn sm primary", `Commit ${plural(files.length, "file", "files")}`, { disabled: frozen || !files.length, onClick: send }) ); @@ -882,7 +955,7 @@ function syncBody(ctx) { const { git, h } = ctx; const body = h.el("div", "git-sync"); if (git.inProgress) { - body.appendChild(opBlock(ctx)); + body.appendChild(h.el("p", "git-wait", `The ${opName(git.inProgress)} is in the step above; everything here waits until it is finished or aborted.`)); return body; } const pr = prBlock(ctx); @@ -890,12 +963,11 @@ function syncBody(ctx) { const acts = boardActions(git, { busy: ctx.mode !== "idle" }); const row = h.el("div", "git-sync-actions"); - const primaryOp = ctx.step.primary && ctx.step.primary.op; for (const key of ["refresh", "pull", "push", "publish"]) { const a = acts[key]; if (!a.shown) continue; row.appendChild( - control(ctx, "button", "btn sm" + (key === primaryOp ? " primary" : ""), a.label, { + control(ctx, "button", "btn sm", a.label, { disabled: ctx.mode === "idle" && !a.enabled, title: a.title, onClick: () => runStep(ctx, { op: key }), diff --git a/src/web-console/public/git-board.js b/src/web-console/public/git-board.js index e5efed8..f1e07dc 100644 --- a/src/web-console/public/git-board.js +++ b/src/web-console/public/git-board.js @@ -507,7 +507,12 @@ function matches(git) { // 4. Uncommitted changes, held-back files left out. if (count > 0) { if (onDefault) { - out.push({ op: "create-commit", label: `Start a branch for ${files(count)}`, why: `You're on ${head.branch}. Work usually goes on its own branch.` }); + out.push({ + op: "create-commit", + label: `Start a branch for ${files(count)}`, + action: "Start a branch and commit", + why: `You're on ${head.branch}. Work usually goes on its own branch, so ${head.branch} stays clean; your changes come along.`, + }); out.push({ op: "commit", label: `Commit on ${head.branch}`, why: "Commit straight to the default branch.", forced: true }); } else { out.push({ op: "commit", label: `Commit ${files(count)}`, why: `${files(count)} changed on ${head.branch || "this commit"}.` }); @@ -589,11 +594,11 @@ export function nextStep(git, { now = Date.now() } = {}) { /** * What each tab has waiting: `{ changes, branches, sync }`, each null or * `{ kind, text, label, next }` (kind "count", "dot" or "warn"; `label` is - * for the tab's accessible name). `next` marks the tab owning the next step - * when there is a primary; that tab always carries a badge. Mid-operation - * only Sync is badged, with a warning. + * for the tab's accessible name). `next` is always false: the task card above + * the tools carries the next step, so no tab points at it. Mid-operation only + * Sync is badged, with a warning. */ -export function tabBadges(git, { now = Date.now(), stepTab = null } = {}) { +export function tabBadges(git, { now = Date.now() } = {}) { const g = git || {}; const head = g.head || {}; const out = { changes: null, branches: null, sync: null }; @@ -621,15 +626,69 @@ export function tabBadges(git, { now = Date.now(), stepTab = null } = {}) { out.sync = { kind: "count", text: "?", label: "not checked lately", next: false }; } } - const step = nextStep(g, { now }); - const owner = TAB_IDS.has(stepTab) ? stepTab : step.tab; - if (step.primary && TAB_IDS.has(owner)) { - const b = out[owner] || { kind: "dot", text: "·", label: "" }; - out[owner] = { ...b, next: true, label: b.label ? `${b.label}, next step` : "next step" }; - } return out; } +/* ---------------------------------------------------------------- path */ + +/** + * The usual trip through git, as the board walks it: save the work (a branch + * first when on the default one), share it, get it reviewed, tidy up after + * the merge. A pull belongs to Share; only an operation stopped part-way + * (conflicts) pauses the path. + */ +export const PATH_STOPS = Object.freeze([ + Object.freeze({ id: "save", label: "Save", hint: "Commit your changes" }), + Object.freeze({ id: "share", label: "Share", hint: "Publish or push" }), + Object.freeze({ id: "review", label: "Review", hint: "Open a pull request" }), + Object.freeze({ id: "tidy", label: "Tidy", hint: "Clean up merged branches" }), +]); + +// The stop each suggested step belongs to. Pull sits on Share: it is what +// stands between the work and pushing it. +const STOP_OF = Object.freeze({ + commit: "save", + "create-commit": "save", + create: "save", + ignore: "save", + pull: "share", + push: "share", + publish: "share", + pr: "review", + cleanup: "tidy", +}); + +/** + * Where the board stands on the path: `{ current, paused, stops }`, each stop + * a PATH_STOPS entry plus `state` ("done", "now" or "todo"). `current` is the + * stop of the step's primary; with no primary every stop is done. An + * operation stopped part-way pauses the path: no current stop, all to do. + */ +export function boardPath(git, step) { + const paused = Boolean(git && git.inProgress); + const primary = step && step.primary; + const current = paused || !primary ? null : STOP_OF[primary.op] || null; + const at = PATH_STOPS.findIndex((s) => s.id === current); + const stops = PATH_STOPS.map((s, i) => ({ + ...s, + state: paused ? "todo" : current === null ? "done" : i < at ? "done" : i === at ? "now" : "todo", + })); + return { current, paused, stops }; +} + +/** + * Whether the task card carries the commit table: its step commits (on this + * branch, or on a new one) and there is something on the tree to tick. + * Otherwise the table stays on the Changes tab inside the tools. + */ +export function cardShowsFiles(git, step) { + const g = git || {}; + const p = step && step.primary; + if (g.inProgress || !p || (p.op !== "commit" && p.op !== "create-commit")) return false; + const ch = g.changes || {}; + return list(ch.files).length + list(ch.untrackedDirs).length > 0; +} + /* ---------------------------------------------------------------- busy */ /** diff --git a/src/web-console/public/index.html b/src/web-console/public/index.html index 79c274c..3cc72c3 100644 --- a/src/web-console/public/index.html +++ b/src/web-console/public/index.html @@ -2607,9 +2607,12 @@

The git board

- The Git card opens a board for your repository: three tabs — Changes, - Branches and Sync — and the next step on top. Every button is a request - to Plan2Code, which runs the git commands and says what each one did. + The Git card opens a board that walks you through the usual trip: + save your work, share it, get it reviewed, tidy up. A path shows where + you are, one card holds the thing to do now, and every other action + waits in All branches and tools. Every button is a + request to Plan2Code, which runs the git commands and says what each + one did.

The header

    @@ -2626,8 +2629,25 @@ Last refreshed says when the remotes were last fetched. If a refresh fails, the line says so. +
  • Done with git sits at the right end of the branch line.
-

The tabs

+

The path

+
    +
  • + Four stops: Save (commit your changes, on a branch of + their own when you are on the default one), Share + (publish or push), Review (open a pull request) and + Tidy (clean up merged branches). +
  • +
  • The stop you are on is lit; the ones behind you are checked.
  • +
  • A stopped rebase or merge pauses the path (it dims) until it is sorted; a pull is part of Share.
  • +
+

All branches and tools

+

+ Closed until you open it. Inside are three tabs, Changes, Branches and + Sync, with everything the board can do. A step that needs one of them, + such as clean-up or a new branch, opens it for you. +

  • Changes lists your uncommitted files, ready to @@ -2652,18 +2672,18 @@ branch or the one you pick beside it; the first time a host is unknown, it asks which kind it is and remembers the answer.
  • -
  • A filled badge marks the tab where the next step is.
-

The next step

+

The task card

  • - The tab that holds it opens with one main button and, at most, one - quieter one beside it: Commit, Push, Publish, Open pull request, and - so on. + Under the path: one main button and, at most, one quieter one beside + it: Commit, Push, Publish, Open pull request, and so on.
  • - On the other tabs, a line reads Next step is on - ‹tab›; click it to go there. + On the Save stop it lists your changed files with their ticks, so you + pick and commit in one place. On the default branch its button is + Start a branch and commit, with + Commit on ‹branch› as the quieter choice.
  • Held-back files never count toward the next step. The board offers @@ -2687,10 +2707,10 @@

    Moving between tabs

    • - Once a click of yours has landed, the board moves to the tab of the + Once a click of yours has landed, the tools move to the tab of the next step. Anything else that changes leaves you where you are.
    • -
    • Reloading the page keeps the tab you were on.
    • +
    • Reloading the page keeps the tools open or closed, and the tab you were on.
    • The arrow keys move between tabs, and Home and End jump to the first and last.

    While something is running

    @@ -2699,8 +2719,8 @@ Everything grays out except switching tabs, searching and opening folds, so nothing queues up behind the running command.
  • -
  • What is running shows where the next step usually sits.
  • -
  • Plan2Code's questions appear under the tab strip.
  • +
  • What is running shows in the task card.
  • +
  • Plan2Code's questions appear under the path.
  • When it is done, a result line says what happened, with the commit hashes, and the board redraws from the repository as it now stands. @@ -2708,11 +2728,11 @@

Mid-rebase or merge

- A rebase or merge that stopped on conflicts shows one block on Sync, - with the files still to fix. Continue becomes the main + A rebase or merge that stopped on conflicts turns the task card into + one block, with the files still to fix. Continue becomes the main button once no conflict markers are left; a single Abort - puts everything back as it was. The other tabs wait until it is - finished or aborted. + puts everything back as it was. The tools wait until it is finished + or aborted.

Done with git

diff --git a/src/web-console/public/screens/git-host.js b/src/web-console/public/screens/git-host.js index 04659c0..b028c3e 100644 --- a/src/web-console/public/screens/git-host.js +++ b/src/web-console/public/screens/git-host.js @@ -1,7 +1,7 @@ // Plan2Code Web Console - hosts the git board: tabs, panels and what each click sends. import { hooks, page, saveNow, redraw } from "../state.js"; -import { GIT_TABS, busyMode, gitReply, pickTab, nextStep, tabBadges, createSources, BRANCH_TYPES, commitTicks, cleanupGroups } from "../git-board.js"; +import { GIT_TABS, busyMode, cardShowsFiles, gitReply, pickTab, nextStep, tabBadges, createSources, BRANCH_TYPES, commitTicks, cleanupGroups } from "../git-board.js"; import { finish, agentWorking, agentAdrift, gitAwaiting, myTurn, byId, activity } from "../selectors.js"; import { drawGitBoard, activeTab } from "../git-board-view.js"; import { el, md, copyButton } from "../render.js"; @@ -25,11 +25,13 @@ const $ = (id) => document.getElementById(id); // sweep the cleanup list's ticked branches // base the pull-request base the picker chose // settled cards the agent settled since the last click on the board -// tab the tab on show: "changes", "branches" or "sync", or null before the first draw +// tools whether the "All branches and tools" fold-out is open (closed by default) +// tab the tab on show inside it: "changes", "branches" or "sync", or null before the first draw // scroll how far the column was scrolled on each tab, put back after each redraw // repickAt when their last board click went out (ms): the first agent post // after it moves the board to the new next step's tab export const board = { + tools: false, tab: null, scroll: { changes: 0, branches: 0, sync: 0 }, repickAt: null, @@ -50,6 +52,7 @@ export const board = { // are harmless: the next send re-checks every path against the snapshot. The // restore waits for the first draw: load() has not run when this module does. const boardBlank = { + tools: false, tab: null, scroll: { changes: 0, branches: 0, sync: 0 }, repickAt: null, @@ -80,6 +83,7 @@ const hydrateBoard = () => { if (!g) return; boardReloaded = true; Object.assign(board, boardBlank, { + tools: g.tools === true, tab: GIT_TABS.some((t) => t.id === g.tab) ? g.tab : null, scroll: { changes: 0, branches: 0, sync: 0, ...(g.scroll || {}) }, repickAt: typeof g.repickAt === "number" ? g.repickAt : null, @@ -97,6 +101,7 @@ const hydrateBoard = () => { const persistBoard = () => { page.local.gitBoard = { + tools: board.tools, tab: board.tab, scroll: { ...board.scroll }, repickAt: board.repickAt, @@ -180,6 +185,12 @@ const gitOn = { redraw: () => redraw(), pickTab: (id) => { board.tab = id; + board.tools = true; + persistBoard(); + redraw(); + }, + toggleTools: () => { + board.tools = !board.tools; persistBoard(); redraw(); }, @@ -222,7 +233,7 @@ export function renderGitBoard(main, card = null, pager = null) { mode: gitMode(), offlineReason: page.gone ? "gone" : page.pendingResult ? "pending" : null, step, - badges: tabBadges(git, { stepTab: step.tab }), + badges: tabBadges(git), notice: result && result.kind === "notice" ? result : null, activity: activity(), hasCard: Boolean(card), @@ -280,14 +291,19 @@ async function pickPrHost(host, kind) { sendGit("pr-host", { host, kind }); } -// Opening a panel moves to the tab that draws it, so a panel is never open -// on a hidden tab. `opts.ticks` / `opts.ignore` set the commit panel's picks -// (the held-back .gitignore offer opens it with nothing ticked). +// Opening a panel moves to the tab that draws it, and opens the tools when +// that tab lives there, so a panel is never open out of sight. The commit +// table and its new-branch prompt sit in the task card on a Save stop, so +// those leave the tools as they are. `opts.ticks` / `opts.ignore` set the +// commit panel's picks (the held-back .gitignore offer opens it with nothing +// ticked). function openPanel(name, opts = {}) { if (gitLocked()) return; const git = page.S.git; + const inCard = cardShowsFiles(git, nextStep(git)); if (name === "commit") { board.tab = "changes"; + if (!inCard) board.tools = true; if (opts.ticks) board.ticks = new Set(opts.ticks); if (opts.ignore) board.ignore = new Set(opts.ignore); if (board.panel !== "commit") return openCommit(git); @@ -296,12 +312,14 @@ function openPanel(name, opts = {}) { } if (name === "create") { board.tab = opts.commit ? "changes" : "branches"; + if (!(opts.commit && inCard)) board.tools = true; // A branch for the commit takes what the commit table has ticked, not a fresh default. if (opts.commit && !opts.files) return openCreate(git, { ...opts, ...tablePicks(git) }); return openCreate(git, opts); } if (name === "cleanup") { board.tab = "branches"; + board.tools = true; return openCleanup(git); } } diff --git a/src/web-console/public/styles/git.css b/src/web-console/public/styles/git.css index a0631ed..206a98b 100644 --- a/src/web-console/public/styles/git.css +++ b/src/web-console/public/styles/git.css @@ -38,11 +38,11 @@ } /* Narrow layout keys off the board's width, not the window's. */ .git-board { container-type: inline-size; container-name: git-board; } -/* Plan2Code's card, between the tab strip and the tab's content. */ +/* Plan2Code's card, between the path and the task card. */ .git-cards { display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; } .git-cards:empty { display: none; } -/* The tab strip: three tabs, Done with git on the right. */ +/* The tab strip inside the tools fold-out: three tabs. */ .git-tab-bar { display: flex; align-items: flex-end; @@ -80,11 +80,78 @@ } .git-tab-badge.is-dot { min-width: 0; font-weight: 700; } .git-tab-badge.is-warn { color: var(--warn); background: var(--warn-soft); border-color: var(--warn); } -.git-tab-badge.is-next { color: var(--accent-ink); background: var(--accent); border-color: var(--accent); } -.git-tab-badge.is-warn.is-next { color: var(--accent-ink); background: var(--warn); border-color: var(--warn); } -.git-done { margin: 0 0 6px auto; } +/* Done with git sits at the right end of the header's branch row. */ +.git-done { margin-left: auto; align-self: center; } .git-done:not(:disabled) { border-color: var(--accent); } +/* The path: Save, Share, Review, Tidy. Marks, not buttons; the current stop + is lit, finished ones get a check. */ +.git-route { + list-style: none; + margin: 0; + padding: 0; + display: grid; + grid-template-columns: repeat(4, minmax(0, 1fr)); + gap: var(--sp-2); +} +.git-stop { + display: flex; + align-items: center; + gap: var(--sp-2); + min-width: 0; + padding: var(--sp-2) var(--sp-3); + border: 1px solid transparent; + border-radius: var(--radius-md); + color: var(--ink-3); +} +.git-stop-mark { + flex: none; + display: grid; + place-items: center; + width: 24px; + height: 24px; + border: 1.5px solid var(--rule-2); + border-radius: 50%; + background: var(--panel); + font-size: var(--fs-xs); + font-weight: 700; +} +.git-stop-words { display: grid; min-width: 0; } +.git-stop-label { font-size: var(--fs-md); font-weight: 600; } +.git-stop-hint { font-size: var(--fs-xs); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } +.git-stop.is-done { color: var(--ink-2); } +.git-stop.is-done .git-stop-mark { color: var(--ok); border-color: var(--ok); background: var(--ok-soft); } +.git-stop.is-now { color: var(--ink); background: var(--panel); border-color: var(--accent); box-shadow: var(--shadow-1); } +.git-stop.is-now .git-stop-mark { color: var(--accent-ink); border-color: var(--accent); background: var(--accent); } +.git-route.is-paused { opacity: 0.55; } + +/* Every other action, folded away until asked for. */ +.git-toolbox { display: grid; grid-template-columns: minmax(0, 1fr); border: 1px dashed var(--rule-2); border-radius: var(--radius); } +.git-toolbox.is-open { border-style: solid; background: var(--panel-2); } +.git-toolbox-toggle { + display: flex; + align-items: baseline; + gap: var(--sp-2); + width: 100%; + padding: var(--sp-3) var(--sp-4); + border: 0; + border-radius: var(--radius); + background: transparent; + color: var(--ink-2); + font: inherit; + font-size: var(--fs-md); + text-align: left; + cursor: pointer; +} +.git-toolbox-toggle:hover { color: var(--ink); } +.git-toolbox-toggle:focus-visible { outline: 2px solid var(--focus); outline-offset: var(--focus-offset); } +.git-toolbox-chev { display: inline-block; transition: rotate 0.15s; } +.git-toolbox.is-open .git-toolbox-chev { rotate: 90deg; } +.git-toolbox-label { font-weight: 600; } +.git-toolbox-sub { font-size: var(--fs-sm); color: var(--ink-3); } +.git-toolbox-body { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--sp-3); padding: 0 var(--sp-4) var(--sp-4); } +@media (prefers-reduced-motion: reduce) { .git-toolbox-chev { transition: none; } } + /* The next step: one primary button, at most one quieter one. */ .git-step { display: grid; gap: 6px; padding: 14px 18px; } .git-step:not(.callout) { @@ -101,7 +168,8 @@ .git-step-why, .git-step-label { margin: 0; font-size: var(--fs-md); color: var(--ink-2); } .git-step-label { font-weight: 600; color: var(--ink); } .git-step-actions, .git-sync-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; } -.git-hint { justify-self: start; border-style: dashed; font-weight: 400; } +/* The file table inside the task card, on a Save stop. */ +.git-step .git-files, .git-left .git-files { margin: var(--sp-1) 0; } .git-stale { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: 0; font-size: var(--fs-md); color: var(--stage); } .git-held { font-size: var(--fs-md); color: var(--ink-2); } .git-held .md-p { margin: 0; } @@ -218,7 +286,7 @@ .git-duo { grid-template-columns: 1fr; } .git-tab-bar { flex-wrap: wrap; } .git-tabs { flex-wrap: wrap; } - .git-done { margin: 0 0 6px; } + .git-route { grid-template-columns: repeat(2, minmax(0, 1fr)); } .git-head-meta { flex-direction: column; align-items: flex-start; } .git-step-actions, .git-sync-actions, .git-op-actions, .git-panel-actions { flex-wrap: wrap; } .git-step-actions .btn, .git-op-actions .btn { flex: 1 1 auto; }