feat(web): port the pi2-web-ui-design v0.1.1 UI

Sync the React console with the v0.1.1 prototype (20 CHGs): Quiet Workbench
shell, Chat IA v3, tool-family rendering, and the mobile page pill.

Shell / tokens (CHG-01/04/15/20):
- tokens.css rewritten from the prototype (three-layer light/dark/system),
  `--tabbar-h` removed, new faint/border-subtle/surface-1-2/fs-*/dur-*/reading-max
- 56px icon-only nav rail/sidebar (44x44 hit targets, CSS tooltips, active is a
  solid primary fill, no left bar), 52px topbar, merged preferences menu,
  ⌘K/Cmd-K palette
- `<600` gets a topbar page pill + page sheet; the bottom tabbar is gone

Pages (CHG-01): workspaces becomes a card grid with whole-card links and a
320px recent-activity column; status gets four metric tiles + a zero-primary
layout; connect gets a two-column hero, one primary per state and a collapsed
manual form.

Chat IA v3 (CHG-02/10-14/16-19): two columns, single-workspace tree with a
workspace switch, single-line rows with attention, body-level row popover,
session tray (todo/tasks) replacing the right panel, context ring moved into a
composer telemetry line, right-aligned user messages, queued messages as one
stream entity plus a composer status bar, and an in-place subagent child view.

Tool rendering (CHG-05/06/09): new `features/chat/tools` module — one row per
call, DTO adapter for the daemon's block shape, 11 kind families, state
semantics ("one state, one meaning"), 44px touch targets and the diff row
contrast fix.

i18n: 729 keys per language (zh/en parity checked), 0 unresolved keys.

Verification: web typecheck + 297 vitest + vite build green, root typecheck
green, `scripts/smoke.sh` green, and a new visual harness
(`scripts/ui-mock-server.mjs` + `scripts/ui-shots.mjs`, docs/ui-parity.md)
shoots 4 pages x 3 viewports x 2 themes = 24 screenshots clean with
overflow/console/primary/tabbar assertions. `scripts/e2e/ui-e2e.mjs` selectors
are updated to the new DOM; that suite still needs a real pi + nvim to run.
This commit is contained in:
yuez committed 2026-10-26 20:28:47 +08:00
1 parent a8425a51b6
commit 88e73c7737
98 files changed
+17676 -2871

No files matched your search

+32 -10
View File
@@ -1,4 +1,4 @@
import { fireEvent, screen, waitFor } from "@testing-library/react";
import { fireEvent, screen, waitFor, within } from "@testing-library/react";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { mockApi } from "./helpers/api-mock";
@@ -71,6 +71,17 @@ function serve(items: WorkspaceInfo[]) {
]);
}
/** Names are also repeated in the activity column; assert on the grid only. */
async function waitForCards(count: number) {
await waitFor(() => expect(screen.getAllByTestId("workspace-row")).toHaveLength(count));
}
function grid(): HTMLElement {
const node = document.querySelector<HTMLElement>(".ws-grid");
if (!node) throw new Error("no workspace grid rendered");
return node;
}
beforeEach(async () => {
await setLanguage("en");
});
@@ -128,33 +139,42 @@ describe("WorkspacesPage secondary rows", () => {
serve([primary, ghost, hidden]);
const { container } = await renderPage(routes(), "/workspaces");
await screen.findByText("Alpha");
await waitForCards(1);
expect(within(grid()).getByText("Alpha")).toBeInTheDocument();
expect(screen.queryByText("Ghost")).not.toBeInTheDocument();
expect(screen.queryByText("Hidden")).not.toBeInTheDocument();
const toggle = await screen.findByTestId("workspaces-show-all");
expect(toggle).toHaveTextContent("Show 2 hidden");
expect(toggle).toHaveAttribute("aria-pressed", "false");
// The toggle lives in the collapsed strip under the grid, outside the head,
// and is never a second primary (H1).
expect(toggle.closest(".ws-hidden-bar")).not.toBeNull();
expect(toggle).not.toHaveClass("btn--primary");
expect(container.querySelectorAll('[data-testid="workspace-row"]')).toHaveLength(1);
expect(container.querySelectorAll(".btn--primary")).toHaveLength(1);
expect(readShowAll()).toBe(false);
});
it("reveals dimmed secondary rows with a reason badge on toggle", async () => {
serve([primary, ghost, hidden]);
await renderPage(routes(), "/workspaces");
await screen.findByText("Alpha");
await waitForCards(1);
fireEvent.click(screen.getByTestId("workspaces-show-all"));
expect(await screen.findByText("Ghost")).toBeInTheDocument();
expect(screen.getByText("Hidden")).toBeInTheDocument();
expect(await within(grid()).findByText("Ghost")).toBeInTheDocument();
expect(within(grid()).getByText("Hidden")).toBeInTheDocument();
const rows = screen.getAllByTestId("workspace-row");
expect(rows.map((row) => row.getAttribute("data-visibility"))).toEqual(["default", "secondary", "secondary"]);
const ghostRow = rows.find((row) => row.getAttribute("data-workspace-id") === "ws-g");
expect(ghostRow).toHaveAttribute("data-visibility-reason", "ghost");
expect(ghostRow).toHaveStyle({ opacity: "0.55" });
// Dimming is a class (no inline styles on the page).
expect(ghostRow).toHaveClass("ws-card--secondary");
expect(ghostRow?.querySelector('[data-testid="workspace-reason"]')).toHaveTextContent("missing");
// The card stays a link to the chat UI even when it is secondary.
expect(ghostRow?.getAttribute("href")).toBe("/chat?workspace=ws-g");
const toggle = screen.getByTestId("workspaces-show-all");
expect(toggle).toHaveTextContent("Hide 2 hidden");
@@ -170,9 +190,10 @@ describe("WorkspacesPage secondary rows", () => {
serve([primary, ghost, hidden]);
await renderPage(routes(), "/workspaces", { storage: { [SHOW_ALL_STORAGE_KEY]: "1" } });
expect(await screen.findByText("Alpha")).toBeInTheDocument();
expect(await screen.findByText("Ghost")).toBeInTheDocument();
expect(screen.getByText("Hidden")).toBeInTheDocument();
await waitForCards(3);
expect(within(grid()).getByText("Alpha")).toBeInTheDocument();
expect(within(grid()).getByText("Ghost")).toBeInTheDocument();
expect(within(grid()).getByText("Hidden")).toBeInTheDocument();
});
it("offers the toggle from the empty state when every row is secondary", async () => {
@@ -181,6 +202,7 @@ describe("WorkspacesPage secondary rows", () => {
expect(await screen.findByText("All workspaces are hidden")).toBeInTheDocument();
fireEvent.click(screen.getByTestId("workspaces-show-all"));
expect(await screen.findByText("Ghost")).toBeInTheDocument();
await waitForCards(2);
expect(within(grid()).getByText("Ghost")).toBeInTheDocument();
});
});