diff --git a/apps/desktop/e2e/menu-hints.spec.ts b/apps/desktop/e2e/menu-hints.spec.ts new file mode 100644 index 00000000..c1794654 --- /dev/null +++ b/apps/desktop/e2e/menu-hints.spec.ts @@ -0,0 +1,94 @@ +import { test, expect, type ElectronApplication, type Page } from "@playwright/test"; +import fs from "node:fs"; +import { launch, seedHome, tid } from "./support"; + +/** + * The composer's menus keep each row to one line. The sentence that used to sit under a row's title is + * the row's accessible description, and shows once, at the foot of the menu, for the row under the + * pointer or the keyboard focus. A menu that passes no hints keeps its rows and has no foot. + */ +let app: ElectronApplication; +let page: Page; +let home: string; +let repo: string; + +const ATTACH = "Add files or images to your next message."; +const PLAN = "Investigate read-only and return a plan instead of editing."; +const AUTO = "A fast judge picks the model, effort and speed for each turn, within your limits."; + +test.beforeAll(async () => { + ({ home, repo } = seedHome()); + ({ app, page } = await launch(home)); + // A draft has a composer and no thread: the seeded mode is Chat and the backend is the mock. + await page.keyboard.press("Meta+n"); + await expect(tid(page, "draft-view")).toBeVisible(); +}); + +test.afterAll(async () => { + await app?.close(); + fs.rmSync(home, { recursive: true, force: true }); + fs.rmSync(repo, { recursive: true, force: true }); +}); + +test("the access menu keeps each choice to one line and describes the focused or hovered one at its foot", async () => { + await tid(page, "access-picker").click(); + const menu = tid(page, "access-menu"); + const option = (mode: string) => menu.locator(`[data-testid="access-option"][data-mode="${mode}"]`); + const foot = tid(menu, "menu-hint"); + // Opened without touching a row: the checked choice has focus, and the foot already describes it. + await expect(option("chat")).toBeFocused(); + await expect(foot).toHaveText("Read-only. Asks before any command or edit."); + // The foot is the visible copy; assistive technology reads the description from the row itself. + await expect(foot).toHaveAttribute("aria-hidden", "true"); + await expect(option("chat")).toHaveText("Read only"); + await expect(option("chat")).toHaveAttribute("aria-description", "Read-only. Asks before any command or edit."); + await expect(option("full-access")).toHaveText("Full access"); + await expect(option("full-access")).toHaveAttribute("aria-description", "No sandbox, no prompts. Only in a trusted environment."); + expect(Math.round((await option("agent").boundingBox())!.height)).toBe(32); + await page.keyboard.press("ArrowDown"); + await expect(option("agent")).toBeFocused(); + await expect(foot).toHaveText("Edits and runs commands inside the project; asks to go outside it."); + await option("full-access").hover(); + await expect(foot).toHaveText("No sandbox, no prompts. Only in a trusted environment."); + await page.keyboard.press("Escape"); + await expect(menu).toHaveCount(0); + await expect(tid(page, "access-picker")).toBeFocused(); + // Nothing was chosen. + await expect(tid(page, "access-picker")).toHaveAttribute("data-mode", "chat"); +}); + +test("the + menu shows Plan and Auto as switches and describes each row", async () => { + await tid(page, "composer-plus").click(); + const menu = tid(page, "composer-plus-menu"); + const foot = tid(menu, "menu-hint"); + await expect(page.getByRole("menuitem", { name: "Attach files", exact: true })).toBeFocused(); + await expect(foot).toHaveText(ATTACH); + await page.keyboard.press("ArrowDown"); + const plan = tid(menu, "plan-toggle"); + await expect(plan).toBeFocused(); + await expect(foot).toHaveText(PLAN); + await expect(plan).toHaveRole("menuitemcheckbox"); + await expect(plan).toHaveAttribute("aria-checked", "false"); + await expect(plan).toHaveAttribute("aria-description", PLAN); + // The row is its title and key hint; the sentence is no longer part of the row's text. + await expect(plan).not.toContainText("Investigate"); + expect(Math.round((await plan.boundingBox())!.height)).toBe(32); + await tid(menu, "auto-toggle").hover(); + await expect(foot).toHaveText(AUTO); + const backend = tid(menu, "backend-picker").getByRole("menuitemradio", { checked: true }); + await expect(backend).toHaveText("Mock"); + // A disabled row may not report the pointer; its description is still on the row. + await expect(backend).toHaveAttribute("aria-description", "Offline scripted engine (demo)"); + await page.keyboard.press("Escape"); + await expect(menu).toHaveCount(0); + await expect(tid(page, "plan-chip")).toHaveCount(0); +}); + +test("a menu without hints has no foot", async () => { + await tid(page, "model-picker").click(); + const menu = tid(page, "model-menu"); + await expect(menu).toBeVisible(); + await expect(tid(menu, "menu-hint")).toHaveCount(0); + await page.keyboard.press("Escape"); + await expect(menu).toHaveCount(0); +}); diff --git a/apps/desktop/src/renderer/components/Composer.tsx b/apps/desktop/src/renderer/components/Composer.tsx index b9116e76..40c31e11 100644 --- a/apps/desktop/src/renderer/components/Composer.tsx +++ b/apps/desktop/src/renderer/components/Composer.tsx @@ -261,33 +261,27 @@ function PlusMenu({ busy, pinned, backend, plan, auto, onBackend, onPlan, onAuto return ( setOpen((v) => !v)} /> - setOpen(false)} anchorRef={trigger} label="Composer options" placement="top-start" testId="composer-plus-menu" className="composer-options"> - Attach files + setOpen(false)} anchorRef={trigger} label="Composer options" placement="top-start" testId="composer-plus-menu" className="composer-options" hint={ATTACH_HINT}> + Attach files {pinned &&
This thread uses a local model, so Plan, Auto and the backend are fixed. Choose cloud models in the model menu to change them.
} - onPlan(!plan))}> - - Plan mode ⇧⌘P - {pinned ? "Plan mode is not qualified for local models." : "Investigate read-only and return a plan instead of editing."} - + onPlan(!plan))}> + Plan mode ⇧⌘P - onAuto(!auto))}> - - Auto routing - {pinned ? "Local threads keep the model you explicitly selected." : "A fast judge picks the model, effort and speed for each turn, within your limits."} - + onAuto(!auto))}> + Auto routing Backend
{BACKENDS.map((b) => ( - onBackend(b.id))}> - {b.label} + onBackend(b.id))}> + {b.label} ))} {backend === "mock" && ( - - Mock + + Mock )}
@@ -296,6 +290,7 @@ function PlusMenu({ busy, pinned, backend, plan, auto, onBackend, onPlan, onAuto ); } +const ATTACH_HINT = "Add files or images to your next message."; const ACCESS_LABEL: Record = { chat: "Read only", agent: "Agent", "full-access": "Full access" }; /** The access pill: how much the agent may do without asking (the thread's mode). Orange only for full access. */ @@ -316,27 +311,22 @@ function AccessMenu({ busy, mode, onMode, approvals, onApprovals }: { busy: bool {ACCESS_LABEL[mode]} - setOpen(false)} anchorRef={trigger} label="Access" placement="top-start" testId="access-menu" className="access-options"> + setOpen(false)} anchorRef={trigger} label="Access" placement="top-start" testId="access-menu" className="access-options" focusSelected hint={info?.hint ?? ""}> + Access {MODES.map((m) => ( - { onMode(m.id); setOpen(false); }}> - - {ACCESS_LABEL[m.id]} - {m.hint} - + { onMode(m.id); setOpen(false); }}> + {ACCESS_LABEL[m.id]} ))} {onApprovals && } {onApprovals && Approvals} {onApprovals && APPROVAL_POLICIES.map((p) => ( - { + { setOpen(false); if (p !== "yolo") onApprovals(p); else void confirmDialog(YOLO_CONFIRM).then((ok) => { if (ok) onApprovals(p); }); }}> - - {APPROVAL_LABEL[p]} - {APPROVAL_HINT[p]} - + {APPROVAL_LABEL[p]} ))} diff --git a/apps/desktop/src/renderer/components/ui/Menu.tsx b/apps/desktop/src/renderer/components/ui/Menu.tsx index d976d312..08c37269 100644 --- a/apps/desktop/src/renderer/components/ui/Menu.tsx +++ b/apps/desktop/src/renderer/components/ui/Menu.tsx @@ -1,4 +1,4 @@ -import { createContext, useContext, useEffect, useLayoutEffect, useRef, type ButtonHTMLAttributes, type ReactNode, type RefObject } from "react"; +import { createContext, useContext, useEffect, useLayoutEffect, useRef, useState, type ButtonHTMLAttributes, type ReactNode, type RefObject } from "react"; import { Icon } from "./Icon"; type MenuRole = "menu" | "listbox"; @@ -21,6 +21,11 @@ interface MenuProps { fitViewport?: boolean; className?: string; testId?: string; + /** + * Gives the menu a description area at its foot. It shows the `hint` of the row under the pointer + * or the keyboard focus, and this text until one is. Rows in such a menu stay on one line. + */ + hint?: string; children: ReactNode; } @@ -35,8 +40,15 @@ const MenuContext = createContext("menu"); * - a pointer press outside the menu and trigger closes it. * Position it by placing it inside a `position: relative` wrapper next to the trigger. */ -export function Menu({ open, onClose, anchorRef, label, role = "menu", focusSelected = role === "listbox", initialFocusRef, placement = "top-start", fitViewport = false, className, testId, children }: MenuProps) { +export function Menu({ open, onClose, anchorRef, label, role = "menu", focusSelected = role === "listbox", initialFocusRef, placement = "top-start", fitViewport = false, className, testId, hint, children }: MenuProps) { const ref = useRef(null); + // The description at the foot follows the pointer and the focus; each opening starts from `hint`. + const [described, setDescribed] = useState(hint); + useEffect(() => { if (open) setDescribed(hint); }, [open, hint]); + const describe = (target: EventTarget) => { + const text = target instanceof Element ? target.closest("[data-hint]")?.dataset.hint : undefined; + if (text !== undefined) setDescribed(text); + }; useLayoutEffect(() => { if (!open || !fitViewport) return; const fit = () => { @@ -114,8 +126,11 @@ export function Menu({ open, onClose, anchorRef, label, role = "menu", focusSele if (!open) return null; return ( -
+
describe(e.target) : undefined} onFocus={hint !== undefined ? (e) => describe(e.target) : undefined}> {children} + {/* Each row carries its own description for assistive technology; this is the visible copy. */} + {hint !== undefined && }
); @@ -128,20 +143,28 @@ interface MenuItemProps extends Omit, "r checkable?: boolean; /** An on/off setting (menuitemcheckbox); `selected` is its state. */ toggle?: boolean; + /** + * What choosing this row does, in a sentence. The row then stays on one line: the sentence is its + * accessible description and shows at the foot of a `Menu` that has a `hint`. + */ + hint?: string; children: ReactNode; } /** One row of a Menu. Its ARIA role follows the parent (option in a listbox, menuitem/menuitemradio in a menu). */ -export function MenuItem({ selected, checkable, toggle, className, children, type = "button", ...rest }: MenuItemProps) { +export function MenuItem({ selected, checkable, toggle, hint, className, children, type = "button", ...rest }: MenuItemProps) { const parent = useContext(MenuContext); const aria = parent === "listbox" ? { role: "option", "aria-selected": Boolean(selected) } : toggle ? { role: "menuitemcheckbox", "aria-checked": Boolean(selected) } : checkable ? { role: "menuitemradio", "aria-checked": Boolean(selected) } : { role: "menuitem" }; + const compact = hint !== undefined; + const described = compact ? { "data-hint": hint, "aria-description": hint } : {}; return ( - ); diff --git a/apps/desktop/src/renderer/styles.css b/apps/desktop/src/renderer/styles.css index 649f82e7..b0a94010 100644 --- a/apps/desktop/src/renderer/styles.css +++ b/apps/desktop/src/renderer/styles.css @@ -558,6 +558,32 @@ a.thread-pr:hover { text-decoration: underline; } .menu-separator { height: 1px; margin: 4px 6px; background: var(--border-pane); } .menu-item:disabled { opacity: .5; cursor: default; background: transparent; } .menu-title .kbd { margin-left: auto; } +/* Menus (components/ui/Menu.tsx). Every menu shares the shell. A menu with a `hint` keeps each row to + one line and describes the row under the pointer or focus once, at its foot. */ +.menu { border-color: var(--hairline); background: var(--bg-elevated); box-shadow: inset 0 1px 0 color-mix(in srgb, var(--text-1) 5%, transparent), 0 24px 60px -12px rgba(0, 0, 0, .6); animation: menu-in var(--duration-fast) var(--ease-out) both; } +@keyframes menu-in { from { opacity: 0; } } +/* On the elevated surface a hovered row takes the light tint and the selected row the stronger one. */ +.menu-item:hover:not(:disabled), .menu-item:focus-visible { background: var(--tint); } +.menu-item.selected, .menu-item.selected:hover:not(:disabled) { background: var(--tint-strong); } +.menu.has-hint { width: 264px; min-width: 0; max-width: calc(100vw - 24px); } +.menu.has-hint .menu-label { padding: 8px 10px 5px; color: var(--text-3); font: var(--weight-medium) 11px/14px var(--font-sans); letter-spacing: .09em; text-transform: uppercase; } +.menu.has-hint .menu-separator { margin: 6px 10px; background: var(--hairline); } +.menu-item.compact { align-items: center; height: 32px; padding: 0 10px; color: var(--text-2); font-size: var(--text-sm); } +.menu-item.compact.selected { background: transparent; color: var(--text-1); } +.menu-item.compact:hover:not(:disabled), .menu-item.compact:focus-visible { background: var(--tint-strong); color: var(--text-1); } +.menu-item.compact > .icon-svg { flex: none; color: var(--text-3); } +.menu-item.compact .menu-title { flex: 1; min-width: 0; overflow: hidden; font-weight: var(--weight-regular); white-space: nowrap; } +.menu-item.compact.selected .menu-title { font-weight: var(--weight-medium); } +/* The check and the switch sit at the row's right edge, after its title. */ +.menu-item.compact .menu-check { order: 9; height: 14px; color: var(--text-1); } +.menu-item.compact .kbd { margin: 0 0 0 auto; padding: 0; border: 0; background: none; color: var(--text-3); font: 11.5px/1 var(--font-sans); } +.menu-switch { order: 9; position: relative; width: 26px; height: 16px; flex: none; border-radius: var(--radius-xs); background: var(--tint-strong); box-shadow: inset 0 0 0 1px var(--hairline); transition: background var(--duration-fast) var(--ease-out); } +.menu-switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 10px; height: 10px; border-radius: 2px; background: var(--text-3); transition: transform var(--duration-fast) var(--ease-out), background var(--duration-fast) var(--ease-out); } +.menu-item[aria-checked="true"] .menu-switch { background: var(--text-1); box-shadow: none; } +.menu-item[aria-checked="true"] .menu-switch::after { transform: translateX(10px); background: var(--bg-elevated); } +.menu-hint { min-height: 58px; margin-top: 6px; padding: 10px 10px 4px; border-top: 1px solid var(--hairline); color: var(--text-info); font-size: var(--text-xs); line-height: 1.45; } +@media (prefers-reduced-motion: reduce) { .menu { animation: none; } } +@media (forced-colors: active) { .menu-switch { border: 1px solid ButtonText; } .menu-item[aria-checked="true"] .menu-switch { background: Highlight; } } .icon-btn.composer-plus-btn, .icon-btn.composer-attach-btn { color: var(--text-1); } .model-trigger:focus-visible, .access-pill:focus-visible, .composer-chip:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; } diff --git a/docs/status.md b/docs/status.md index ce8e8213..3c5744de 100644 --- a/docs/status.md +++ b/docs/status.md @@ -147,7 +147,9 @@ before relying on a tick. ## In flight -- **Chat and prompts refresh, PR 1 of 5** (branch `chat-refresh-foundation`). Val approved the design on 2026-11-15: [`superpowers/specs/2026-11-15-chat-prompts-refresh-design.md`](superpowers/specs/2026-11-15-chat-prompts-refresh-design.md). This first PR is the foundation, per [`superpowers/plans/2026-11-15-chat-refresh-foundation.md`](superpowers/plans/2026-11-15-chat-refresh-foundation.md): one radius scale for every renderer stylesheet (8 px surfaces, 6 px controls, 4 px parts; only dots and spinners stay round), the `--tint`, `--tint-strong` and `--hairline` tokens, and one in-app confirm dialog that replaces all ten `window.confirm` calls (YOLO, cloud model, delete thread, remove project, discard changes, reset learning, remove local connection, delete task). The source was written in a session that could not install dependencies: the radius guard (`scripts/test/radius-scale.test.mjs`) and the confirm store's logic were run there, and the build, unit suite and Electron specs were not, so CI is the first full run. Menus, transcript rows, the request panel and the composer follow in PRs 2 to 5. +- **Chat and prompts refresh, PR 1 of 5** (branch `chat-refresh-foundation`). Val approved the design on 2026-11-15: [`superpowers/specs/2026-11-15-chat-prompts-refresh-design.md`](superpowers/specs/2026-11-15-chat-prompts-refresh-design.md). This first PR is the foundation, per [`superpowers/plans/2026-11-15-chat-refresh-foundation.md`](superpowers/plans/2026-11-15-chat-refresh-foundation.md): one radius scale for every renderer stylesheet (8 px surfaces, 6 px controls, 4 px parts; only dots and spinners stay round), the `--tint`, `--tint-strong` and `--hairline` tokens, and one in-app confirm dialog that replaces all ten `window.confirm` calls (YOLO, cloud model, delete thread, remove project, discard changes, reset learning, remove local connection, delete task). The source was written in a session that could not install dependencies: the radius guard (`scripts/test/radius-scale.test.mjs`) and the confirm store's logic were run there, and the build, unit suite and Electron specs were not, so CI is the first full run. Menus, transcript rows, the request panel and the composer follow in PRs 2 to 5. CI on #527 then passed on its first full run (2,563 unit tests; 553 Electron cases with the 14 standing live and native skips). + +- **Chat and prompts refresh, PR 2 of 5: menus** (branch `chat-refresh-menus`, stacked on #527). Per [`superpowers/plans/2026-11-16-chat-refresh-menus.md`](superpowers/plans/2026-11-16-chat-refresh-menus.md): `Menu` and `MenuItem` take an optional `hint`. A row with a hint stays on one line and carries the sentence as its `aria-description`; a menu with a hint shows one description at its foot for the row under the pointer or focus. The composer's access and `+` menus use it, with Plan and Auto as switches; every sentence is today's copy, plus one new line for Attach files. All menus take the refreshed shell (hairline border, elevated surface, tinted hover and selection); menus that pass no hint, the model picker included, keep their rows. Written without a local build, like PR 1: CI is its first full run. - **Code Review person-run seed and header-panel focus.** The owned source candidate repairs the actual human-review seed: long description, 101 paged comments, checks/stack/deployment and coherent diffs for all listed synthetic PRs. A normal Electron regression reproduced header Review panel Close dropping focus; Review/Merge Close and scoped Escape now return to their own split-pane button, preserving instructions Escape. Build, workspace typechecks, 2,588 units with 36 skips, 531 desktop E2E cases with 17 opt-in skips, eight site cases and four web cases pass. The isolated seeded overview/activity/panel/diff journey passes; the final fixture-only D5 scroll-density correction passes actual wide/narrow PageDown checks with unchanged diff/inbox positions, its final full units also pass, and protected delivery is pending. Human Result cells stay blank. The checklist uses explicit private-home General opt-in, removes C07 and describes conditional tree folding. Initial signed source `1b2c58b` passed hosted units and iPhone suites but failed two desktop E2E cases. The immutable-comparison fixture race is reproduced and repaired with two deterministic request orderings; the unexplained Markdown ArrowRight failure has validated observation-only diagnostics, with all original assertions retained. The follow-up full build, workspace/E2E typechecks and 2,588 units with 36 skips pass. Full follow-up E2E passes 532 desktop cases with 17 opt-in skips, eight site cases and four web cases, zero failures/retries; exact-head hosted/protected qualification remains pending. The original human candidate is independently preserved and natively qualified in a portable runtime, with human rows still blank. State-change panel focus/Escape remains a named follow-up. [Repair and limits](reviews/2026-11-13-cr-human-seed-focus.md), [CI follow-up](reviews/2026-11-13-pr522-ci-followup.md). diff --git a/docs/superpowers/plans/2026-11-16-chat-refresh-menus.md b/docs/superpowers/plans/2026-11-16-chat-refresh-menus.md new file mode 100644 index 00000000..bdbf6121 --- /dev/null +++ b/docs/superpowers/plans/2026-11-16-chat-refresh-menus.md @@ -0,0 +1,125 @@ +# Chat Refresh Menus (PR 2 of 5) Implementation Plan + +> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking. + +**Goal:** Give every menu the refreshed shell, and make the composer's two menus one line per row with a single description at the foot. + +**Architecture:** `Menu` and `MenuItem` each gain an optional `hint`. A row with a hint renders on one line and carries the sentence as its accessible description; a menu with a hint renders one description area at its foot and fills it from the row under the pointer or focus, by event delegation on the menu element. Menus that pass no hint keep their markup and take only the shared shell styling, so the model picker and the eleven other menus are not restructured. + +**Tech Stack:** Existing TypeScript, React 19, Playwright; no new dependencies. + +**Spec:** `docs/superpowers/specs/2026-11-15-chat-prompts-refresh-design.md`, section "2. Menus". Stacked on PR 1 (`chat-refresh-foundation`), whose tokens it uses. The request panel's "more" menu arrives with PR 4 and uses the same props. + +## Global Constraints + +- A menu with a hint is `264px` wide; its rows are `32px` high; its section labels are `11px` uppercase with `.09em` letter spacing. +- The foot uses `--text-info`, because it carries information (`styles.css` reserves `--text-3` for labels). +- A row's description is never visual only: it is the row's `aria-description`. The foot is `aria-hidden`. +- The selected row of a one-line menu has a check at its right edge and medium weight, no fill. An on/off row shows a switch; its state stays the row's `aria-checked`. +- Radii come from the PR 1 scale: menu `--radius-md`, rows `--radius-sm`, switch `--radius-xs`. +- Existing `data-testid`s, roles and accessible names do not change (`access-menu`, `access-option`, `approvals-option`, `composer-plus-menu`, `plan-toggle`, `auto-toggle`, `backend-picker`; "Attach files" stays the first row's exact name). +- Menu copy is unchanged: every description sentence that exists today is the row's hint, word for word. One sentence is new: "Add files or images to your next message." for Attach files, which had none. +- No behavior change: the same handlers run, the same rows are disabled, the menus close as they do today. + +## Review Focus + +1. **A menu opened with the keyboard, never touched by the pointer.** Expected: the foot describes the focused row from the first frame and follows the arrow keys. Pinned in Task 2. +2. **A screen reader on a one-line row.** Expected: the description is announced from the row itself, and the foot is not read a second time. Pinned in Task 2 (`aria-description` on the row, `aria-hidden` on the foot). +3. **A menu that passes no hint** (model picker, sidebar, title bar, Changes, routines, Space, Code Review, plugins). Expected: same rows as before, no foot, selection still visible on the new surface. Pinned in Task 2 (model menu has no foot) and by the existing specs for those menus. +4. **A thread pinned to a local model.** Expected: Plan, Auto and Backend stay disabled, the pinned note still shows, and each disabled row's hint is today's pinned sentence. Covered by the existing local-model specs; the hints are the same strings. +5. **Forced colors.** Expected: the switch is visible as a bordered track and shows its on state. Pinned in the stylesheet's `forced-colors` rule; checked by review, not by a test. + +--- + +### Task 1: `hint` on `Menu` and `MenuItem`, and the shared shell + +**Files:** +- Modify: `apps/desktop/src/renderer/components/ui/Menu.tsx` +- Modify: `apps/desktop/src/renderer/styles.css` (after `.menu-title .kbd`) + +**Interfaces:** +- Consumes: `--tint`, `--tint-strong`, `--hairline`, `--radius-xs` from PR 1. +- Produces: + - `Menu` prop `hint?: string`. When defined, the menu element gains the class `has-hint` and a last child `