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

+135 -9
View File
@@ -38,6 +38,11 @@ function routes() {
];
}
/** Card names are also repeated in the activity column, so wait on the cards. */
async function waitForCards(count: number) {
await waitFor(() => expect(screen.getAllByTestId("workspace-row")).toHaveLength(count));
}
beforeEach(async () => {
await setLanguage("en");
});
@@ -59,32 +64,146 @@ describe("WorkspacesPage", () => {
]);
const { container } = await renderPage(routes(), "/workspaces", { paired: true });
await screen.findByText("Bravo");
await waitForCards(3);
const names = [...container.querySelectorAll(".list-row__name")].map((node) => node.textContent);
const names = [...container.querySelectorAll(".ws-grid .ws-card__name")].map((node) => node.textContent);
expect(names).toEqual(["Alpha", "Bravo", "Charlie"]);
// Stable hooks for the e2e/Playwright suite (row + enter link).
// Stable hooks for the e2e/Playwright suite (whole-card link per row).
const rows = screen.getAllByTestId("workspace-row");
expect(rows.map((row) => row.getAttribute("data-workspace-id"))).toEqual(["ws-a", "ws-b", "ws-c"]);
const enters = screen.getAllByTestId("workspace-enter");
expect(enters.map((link) => link.getAttribute("href"))).toEqual([
expect(rows.map((row) => row.getAttribute("href"))).toEqual([
"/chat?workspace=ws-a",
"/chat?workspace=ws-b",
"/chat?workspace=ws-c",
]);
});
it("makes the whole card the link and drops the in-row primary button", async () => {
mockApi([
{ path: "/api/v1/info", handler: () => ({ body: infoBody }) },
{
path: "/api/v1/workspaces",
handler: () => ({
body: [
workspace({
workspaceId: "ws-a",
cwd: "/work/alpha",
name: "Alpha",
sessionCount: 3,
liveCount: 2,
lastActiveAt: 4_000,
instance: {
workspaceId: "ws-a",
instanceId: "inst-a",
status: "ready",
nvimPid: 42,
pluginVersion: "0.1.1",
hasUI: true,
attachedClients: 1,
listenAddr: "127.0.0.1:7777",
startedAt: 1_000,
},
}),
],
}),
},
]);
const { container } = await renderPage(routes(), "/workspaces", { paired: true });
await waitForCards(1);
const [card] = screen.getAllByTestId("workspace-row");
expect(card?.tagName).toBe("A");
expect(card).toHaveClass("ws-card");
// Accessible name carries name + cwd + count (v0.1.1 §1.3).
expect(card?.getAttribute("aria-label")).toContain("Alpha — /work/alpha — 3 sessions");
// Aggregate state is a dot *plus* text, never colour alone.
expect(card?.querySelector(".ws-card__state .dot")).toHaveClass("dot--ok");
expect(card?.querySelector(".ws-card__state")).toHaveTextContent("Instance ready");
// Foot: count + the (non-interactive) "open" affordance.
expect(card?.querySelector(".ws-card__count")).toHaveTextContent("3 sessions");
expect(card?.querySelector(".ws-card__open")).toBeInTheDocument();
// No row-level primary "enter" button left anywhere on the page.
expect(screen.queryByTestId("workspace-enter")).toBeNull();
const primaries = [...container.querySelectorAll(".btn--primary")];
expect(primaries).toHaveLength(1);
expect(primaries[0]).toHaveTextContent("Open new workspace");
});
it("renders the server summary as one single-line status strip", async () => {
mockApi([
{ path: "/api/v1/info", handler: () => ({ body: infoBody }) },
{
path: "/api/v1/workspaces",
handler: () => ({
body: [
workspace({ workspaceId: "ws-a", cwd: "/work/a", name: "Alpha", lastActiveAt: 1_000 }),
workspace({ workspaceId: "ws-b", cwd: "/work/b", name: "Bravo", liveCount: 1, lastActiveAt: 2_000 }),
],
}),
},
]);
const { container } = await renderPage(routes(), "/workspaces", { paired: true });
await waitForCards(2);
const strip = screen.getByTestId("workspaces-status-line");
expect(strip.tagName).toBe("SECTION");
expect(strip).toHaveClass("status-line");
expect(strip).toHaveAttribute("role", "group");
expect(strip).toHaveAttribute("aria-label", "Current server");
expect(strip).toHaveTextContent("127.0.0.1:4321");
expect(strip).toHaveTextContent("2 workspaces");
expect(strip.querySelector(".dot")).toHaveClass("dot--lg");
expect(within(strip).getByRole("link")).toHaveAttribute("href", "/status");
// The v0.1.0 card-shaped context bar is gone.
expect(container.querySelector(".ws-context")).toBeNull();
});
it("lists the newest workspaces in a recent-activity column", async () => {
const items = [1, 2, 3, 4, 5, 6].map((n) =>
workspace({ workspaceId: `ws-${n}`, cwd: `/work/${n}`, name: `Project ${n}`, lastActiveAt: n * 1_000 }),
);
mockApi([
{ path: "/api/v1/info", handler: () => ({ body: infoBody }) },
{ path: "/api/v1/workspaces", handler: () => ({ body: items }) },
]);
await renderPage(routes(), "/workspaces", { paired: true });
await waitForCards(6);
const activity = screen.getByTestId("workspaces-activity");
expect(activity.tagName).toBe("ASIDE");
const rows = within(activity).getAllByTestId("workspace-activity-row");
// Newest first, capped at 5 (v0.1.1 §5.1).
expect(rows.map((row) => row.getAttribute("data-workspace-id"))).toEqual(["ws-6", "ws-5", "ws-4", "ws-3", "ws-2"]);
expect(rows[0]).toHaveAttribute("href", "/chat?workspace=ws-6");
// Head carries the section label + the entry count (a11y name is the i18n label).
expect(activity).toHaveAttribute("aria-label");
expect(activity.querySelector(".ws-activity__count")).toHaveTextContent("5");
});
it("opens the new-workspace dialog from the empty state", async () => {
const fetchMock = mockApi([
{ path: "/api/v1/info", handler: () => ({ body: infoBody }) },
{ path: "/api/v1/workspaces", handler: () => ({ body: [] }) },
]);
await renderPage(routes(), "/workspaces", { paired: true });
const { container } = await renderPage(routes(), "/workspaces", { paired: true });
await screen.findByText("No workspaces yet");
fireEvent.click(screen.getAllByRole("button", { name: "Open new workspace" })[0]!);
// The empty state owns the only primary; the page-head action stays off.
const newButtons = screen.getAllByRole("button", { name: "Open new workspace" });
expect(newButtons).toHaveLength(1);
expect(newButtons[0]).toHaveClass("btn--primary");
expect(container.querySelector(".page-head__actions")).toBeNull();
fireEvent.click(newButtons[0]!);
const dialog = await screen.findByRole("dialog");
expect(within(dialog).getByLabelText("Path")).toBeInTheDocument();
@@ -104,6 +223,8 @@ describe("WorkspacesPage", () => {
expect(await screen.findByText("No workspaces yet")).toBeInTheDocument();
expect(screen.getAllByRole("button", { name: "Open new workspace" }).length).toBeGreaterThan(0);
expect(screen.queryByRole("combobox")).not.toBeInTheDocument();
// The activity column keeps its own empty state.
expect(screen.getByTestId("workspaces-activity")).toBeInTheDocument();
});
it("shows an error state with retry when the list request fails", async () => {
@@ -123,7 +244,12 @@ describe("WorkspacesPage", () => {
expect(await screen.findByText("Could not load workspaces")).toBeInTheDocument();
expect(attempts).toBe(1);
fireEvent.click(screen.getByRole("button", { name: "Retry" }));
// Retry is not a second primary (the header primary stays off in error states).
const retry = screen.getByRole("button", { name: "Retry" });
expect(retry).not.toHaveClass("btn--primary");
expect(screen.queryByRole("button", { name: "Open new workspace" })).toBeNull();
fireEvent.click(retry);
await waitFor(() => expect(attempts).toBe(2));
});
@@ -148,7 +274,7 @@ describe("WorkspacesPage", () => {
]);
const { router } = await renderPage(routes(), "/workspaces", { paired: true });
await screen.findByText("Old project");
await waitForCards(1);
fireEvent.click(screen.getByRole("button", { name: "Open new workspace" }));
const dialog = await screen.findByRole("dialog");