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

+50 -58
View File
@@ -1,11 +1,12 @@
import { useEffect, useRef } from "react";
import { useEffect, useRef, useState } from "react";
import { useTranslation } from "react-i18next";
import { Icon, type IconName } from "@/components/icons";
import { LangMenu } from "@/components/shared/lang-menu";
import { Icon } from "@/components/icons";
import { CommandPalette } from "@/components/shared/command-palette";
import { NavList, pageName } from "@/components/shared/nav-list";
import { PagePill } from "@/components/shared/page-pill";
import { PrefsMenu } from "@/components/shared/prefs-menu";
import { ServerChip } from "@/components/shared/server-chip";
import { ThemeMenu } from "@/components/shared/theme-menu";
import { SidebarItem } from "@/components/ui/sidebar-item";
import { clearPairMeta } from "@/features/connect/pairing";
import { api, getDeviceToken, onUnauthorized } from "@/lib/api";
import { CONNECT_PATH, safeNext } from "@/lib/routing";
@@ -16,31 +17,6 @@ import { useWorkspacesStore } from "@/stores/workspaces";
import { Link, Outlet, useNavigate, useRouterState } from "@tanstack/react-router";
import { useQuery } from "@tanstack/react-query";
interface NavItem {
to: "/workspaces" | "/chat" | "/status";
labelKey: string;
icon: IconName;
match: (pathname: string) => boolean;
}
const NAV: NavItem[] = [
{
to: "/workspaces",
labelKey: "nav.workspaces",
icon: "folder",
match: (p) => p === "/workspaces" || p.startsWith("/workspace/"),
},
{ to: "/chat", labelKey: "nav.chat", icon: "chat", match: (p) => p.startsWith("/chat") },
{ to: "/status", labelKey: "nav.status", icon: "status", match: (p) => p.startsWith("/status") },
];
function pageName(pathname: string): string {
if (pathname.startsWith("/connect")) return "connect";
if (pathname.startsWith("/status")) return "status";
if (pathname.startsWith("/chat")) return "chat";
return "workspaces";
}
function RouteTitle({ pathname }: { pathname: string }) {
const { t } = useTranslation();
const server = useConnectionStore((state) => state.server);
@@ -91,19 +67,28 @@ function RouteTitle({ pathname }: { pathname: string }) {
);
}
function NavLinks({ pathname }: { pathname: string }) {
/** Topbar palette entry: icon + label (≤1099 label hidden) + platform kbd hint. */
function PaletteTrigger({ onOpen }: { onOpen: () => void }) {
const { t } = useTranslation();
const [kbd, setKbd] = useState("Ctrl K");
useEffect(() => {
const platform = typeof navigator === "undefined" ? "" : navigator.platform || "";
setKbd(/Mac|iPhone|iPad/.test(platform) ? "⌘K" : "Ctrl K");
}, []);
return (
<>
{NAV.map((item) => (
<SidebarItem key={item.to} active={item.match(pathname)} asChild>
<Link to={item.to}>
<Icon name={item.icon} />
<span>{t(item.labelKey)}</span>
</Link>
</SidebarItem>
))}
</>
<button
type="button"
className="btn btn--ghost btn--sm palette-trigger"
aria-label={t("shell.searchHint")}
title={t("shell.searchHint")}
onClick={onOpen}
>
<Icon name="search" />
<span className="palette-trigger__label">{t("shell.searchAction")}</span>
<span className="kbd palette-trigger__kbd">{kbd}</span>
</button>
);
}
@@ -122,6 +107,7 @@ export function AppShell() {
const ownsSocket = !pathname.startsWith("/chat");
const page = pageName(pathname);
const redirectingRef = useRef(false);
const [paletteOpen, setPaletteOpen] = useState(false);
const info = useQuery({
queryKey: ["info"],
@@ -191,28 +177,42 @@ export function AppShell() {
};
}, [disconnect, href, isConnect, navigate, ownsSocket, paired, setWsState]);
/** ⌘K / Ctrl-K opens the palette on every navigation page (never on /connect). */
useEffect(() => {
if (!paired || isConnect) return;
const onKeyDown = (event: KeyboardEvent) => {
if (!(event.metaKey || event.ctrlKey) || event.key.toLowerCase() !== "k") return;
if (event.defaultPrevented) return;
event.preventDefault();
setPaletteOpen(true);
};
document.addEventListener("keydown", onKeyDown);
return () => document.removeEventListener("keydown", onKeyDown);
}, [paired, isConnect]);
const connectionLost = paired && !isConnect && (wsState === "reconnecting" || wsState === "closed");
return (
<div className="shell bg-background text-foreground" data-ws-state={wsState} data-paired={paired ? "true" : "false"}>
<header className="topbar">
<Link to="/workspaces" className="brand">
<Link to="/workspaces" className="brand" aria-label="pi2.nvim">
<img
className="brand__logo"
src="/pi2-nvim.png"
alt=""
width={24}
height={24}
width={22}
height={22}
decoding="async"
/>
<span className="brand__text">pi2.nvim</span>
</Link>
{isConnect ? null : <PagePill page={page} onSearch={() => setPaletteOpen(true)} />}
<RouteTitle pathname={pathname} />
<div className="spacer" />
<div className="actions">
{isConnect ? null : <PaletteTrigger onOpen={() => setPaletteOpen(true)} />}
{isConnect ? null : <ServerChip />}
<LangMenu />
<ThemeMenu />
<PrefsMenu />
</div>
</header>
@@ -231,15 +231,11 @@ export function AppShell() {
) : null}
<div className="body">
{/* <600 has no persistent navigation strip: the page pill owns navigation. */}
{isConnect ? null : (
<>
<aside className="sidebar">
<div className="nav-label">{t("shell.navLabel")}</div>
<NavLinks pathname={pathname} />
</aside>
<aside className="rail">
<NavLinks pathname={pathname} />
</aside>
<NavList variant="sidebar" page={page} />
<NavList variant="rail" page={page} />
</>
)}
<main className="main">
@@ -247,11 +243,7 @@ export function AppShell() {
</main>
</div>
{isConnect ? null : (
<nav className="tabbar">
<NavLinks pathname={pathname} />
</nav>
)}
{isConnect ? null : <CommandPalette open={paletteOpen} onOpenChange={setPaletteOpen} />}
</div>
);
}