From 5578d9a1a66594c6a3d2726911eeee68ff1ccc70 Mon Sep 17 00:00:00 2001 From: Szymon Chmal Date: Wed, 21 Oct 2026 14:15:55 +0200 Subject: [PATCH 01/32] =?UTF-8?q?test:=20=E2=8C=98K=20and=20Ctrl+K=20open?= =?UTF-8?q?=20the=20dialog=20and=20focus=20the=20box;=20the=20sidebar=20bu?= =?UTF-8?q?tton=20opens=20it=20too;=20Escape=20closes=20it=20and=20focus?= =?UTF-8?q?=20returns=20(#770)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- e2e/console/search.spec.ts | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 e2e/console/search.spec.ts diff --git a/e2e/console/search.spec.ts b/e2e/console/search.spec.ts new file mode 100644 index 000000000..4b568ccf5 --- /dev/null +++ b/e2e/console/search.spec.ts @@ -0,0 +1,36 @@ +import type { Page } from "@playwright/test"; + +import { expect, signIn, test } from "./fixtures.js"; + +async function openConsole(page: Page, token: string, path = "/"): Promise { + await page.goto(path); + await signIn(page, token); + await expect(page.getByRole("button", { name: "Search or jump to…" })).toBeVisible(); +} + +test.describe("the search box", () => { + test("⌘K and Ctrl+K open the dialog and focus the box, the sidebar button opens it too, and Escape closes it and returns focus", async ({ + daemon, + page, + }) => { + await openConsole(page, daemon.tokens.operator); + const dialog = page.getByRole("dialog", { name: "Search" }); + const box = dialog.getByRole("combobox", { name: "Search pages, items and actions" }); + + for (const shortcut of ["Meta+k", "Control+k"]) { + await page.keyboard.press(shortcut); + await expect(dialog).toBeVisible(); + await expect(box).toBeFocused(); + await page.keyboard.press("Escape"); + await expect(dialog).toBeHidden(); + } + + const button = page.getByRole("button", { name: "Search or jump to…" }); + await button.click(); + await expect(dialog).toBeVisible(); + await expect(box).toBeFocused(); + await page.keyboard.press("Escape"); + await expect(dialog).toBeHidden(); + await expect(button).toBeFocused(); + }); +}); From d3483e5856d5ca5bb34dabc0894a06b4f3b12d0a Mon Sep 17 00:00:00 2001 From: Szymon Chmal Date: Wed, 21 Oct 2026 14:17:39 +0200 Subject: [PATCH 02/32] =?UTF-8?q?feat(console):=20the=20search=20dialog=20?= =?UTF-8?q?opens=20from=20=E2=8C=98K,=20Ctrl+K=20and=20the=20sidebar=20but?= =?UTF-8?q?ton=20(#770)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ui/src/app/shell.tsx | 19 +++++++++++++++++- ui/src/ds/command-palette.css | 36 ++++++++++++++++++++++++++++++++++ ui/src/ds/command-palette.tsx | 31 +++++++++++++++++++++++++++++ ui/src/ds/icon.tsx | 1 + ui/src/ds/index.ts | 1 + ui/src/ds/sidebar.css | 37 +++++++++++++++++++++++++++++++++++ ui/src/ds/sidebar.tsx | 15 +++++++++++++- ui/src/state/search.ts | 14 +++++++++++++ 8 files changed, 152 insertions(+), 2 deletions(-) create mode 100644 ui/src/ds/command-palette.css create mode 100644 ui/src/ds/command-palette.tsx create mode 100644 ui/src/state/search.ts diff --git a/ui/src/app/shell.tsx b/ui/src/app/shell.tsx index f1f5e8b93..310bb3be3 100644 --- a/ui/src/app/shell.tsx +++ b/ui/src/app/shell.tsx @@ -1,8 +1,9 @@ import { useEffect } from "react"; -import { AppFrame, Button, Icon, Sidebar, Status, StatusDot } from "../ds"; +import { AppFrame, Button, CommandPalette, Icon, Sidebar, Status, StatusDot } from "../ds"; import { NotFoundScreen } from "../screens/not-found"; import { usePath } from "../state/router"; +import { useSearchPalette } from "../state/search"; import { useInboxCount, useConnectionStatus, @@ -18,8 +19,22 @@ export function Shell() { const route = routeFor(path); const inbox = useInboxCount(); const sidebar = useSidebar(); + const palette = useSearchPalette(); useTokenCheck(); + // why: ⌘K on a Mac and Ctrl+K elsewhere both open the search; the browser's own use of the + // chord is stopped while the console has focus. + useEffect(() => { + const onKey = (event: KeyboardEvent) => { + if ((event.metaKey || event.ctrlKey) && event.key.toLowerCase() === "k") { + event.preventDefault(); + palette.show(); + } + }; + window.addEventListener("keydown", onKey); + return () => window.removeEventListener("keydown", onKey); + }, [palette.show]); + useEffect(() => { document.title = route === undefined ? "Simlock" : `${route.label} · Simlock`; }, [route]); @@ -40,11 +55,13 @@ export function Shell() { entries={entries} collapsed={sidebar.collapsed} onToggle={sidebar.toggle} + onSearch={palette.show} footer={(collapsed) => } /> } > {route === undefined ? : } + {palette.open ? : null} ); } diff --git a/ui/src/ds/command-palette.css b/ui/src/ds/command-palette.css new file mode 100644 index 000000000..8b60505c9 --- /dev/null +++ b/ui/src/ds/command-palette.css @@ -0,0 +1,36 @@ +/* The search dialog: a panel near the top of the page over a dim layer, a box and its results. */ + +.palette-dim { + position: fixed; + inset: 0; + z-index: 60; + background: color-mix(in srgb, var(--bg) 70%, transparent); +} + +.palette { + position: fixed; + top: 12vh; + left: 50%; + z-index: 61; + display: flex; + flex-direction: column; + width: min(36rem, calc(100% - var(--space-8))); + max-height: 70vh; + border: 1px solid var(--border-strong); + background: var(--bg); + transform: translateX(-50%); +} + +.palette-input { + min-height: 48px; + padding: 0 var(--space-4); + border: 0; + border-bottom: 1px solid var(--border); + background: var(--field); + color: var(--text); + font-size: var(--text-md); +} + +.palette-list { + overflow-y: auto; +} diff --git a/ui/src/ds/command-palette.tsx b/ui/src/ds/command-palette.tsx new file mode 100644 index 000000000..6316ca7e5 --- /dev/null +++ b/ui/src/ds/command-palette.tsx @@ -0,0 +1,31 @@ +import "./command-palette.css"; + +import { Autocomplete } from "@base-ui/react/autocomplete"; +import { Dialog } from "@base-ui/react/dialog"; + +// why: the dialog is mounted only while open, so each opening starts from an empty box. +export function CommandPalette(props: { readonly onClose: () => void }) { + return ( + { + if (!open) props.onClose(); + }} + > + + + + Search + + + + + + + + ); +} diff --git a/ui/src/ds/icon.tsx b/ui/src/ds/icon.tsx index 2a8ddec18..b7c38f8ad 100644 --- a/ui/src/ds/icon.tsx +++ b/ui/src/ds/icon.tsx @@ -13,6 +13,7 @@ const PATHS = { signOut: "M6 2.5H2.5v11H6M10 5l3 3-3 3M13 8H6", more: "M3 8h.01M8 8h.01M13 8h.01", device: "M5 1.5h6v13H5zM7.5 12.5h1", + search: "M7 12.5a5.5 5.5 0 1 0 0-11 5.5 5.5 0 0 0 0 11zM11 11l3.5 3.5", } as const; export type IconName = keyof typeof PATHS; diff --git a/ui/src/ds/index.ts b/ui/src/ds/index.ts index b32d6e3a1..dc43c48ac 100644 --- a/ui/src/ds/index.ts +++ b/ui/src/ds/index.ts @@ -1,6 +1,7 @@ import "./foundation.css"; export { Button, ButtonLink } from "./button"; +export { CommandPalette } from "./command-palette"; export { ConfirmHost, createConfirmer, type ConfirmSpec } from "./confirm-dialog"; export { Drawer, DrawerTabs } from "./drawer"; export { ChartPanel, MinuteChart, MinuteTable } from "./chart"; diff --git a/ui/src/ds/sidebar.css b/ui/src/ds/sidebar.css index afbe523c1..8bb1f0835 100644 --- a/ui/src/ds/sidebar.css +++ b/ui/src/ds/sidebar.css @@ -382,3 +382,40 @@ text-overflow: ellipsis; white-space: nowrap; } + +.sidebar-search { + display: flex; + align-items: center; + gap: var(--space-3); + height: 40px; + padding: 0 var(--space-3); + border: 1px solid var(--border); + background: transparent; + color: var(--text-muted); + font-size: var(--text-sm); + white-space: nowrap; + cursor: pointer; +} + +.sidebar-search:hover { + border-color: var(--border-strong); + color: var(--text); +} + +.sidebar-search .icon { + flex: none; +} + +.sidebar-collapsed .sidebar-search { + justify-content: center; + gap: 0; + padding: 0; +} + +@media (max-width: 767.98px) { + .sidebar-collapsed .sidebar-search { + justify-content: flex-start; + gap: var(--space-3); + padding: 0 var(--space-3); + } +} diff --git a/ui/src/ds/sidebar.tsx b/ui/src/ds/sidebar.tsx index db51af718..252e6ca4a 100644 --- a/ui/src/ds/sidebar.tsx +++ b/ui/src/ds/sidebar.tsx @@ -50,9 +50,10 @@ export function Sidebar(props: { readonly entries: readonly NavEntry[]; readonly collapsed: boolean; readonly onToggle: () => void; + readonly onSearch: () => void; readonly footer: (collapsed: boolean) => ReactNode; }) { - const { collapsed, entries, footer, onToggle } = props; + const { collapsed, entries, footer, onSearch, onToggle } = props; const [menuOpen, setMenuOpen] = useState(false); const groups = [...new Set(entries.flatMap((entry) => (entry.group ? [entry.group] : [])))]; const nav = { collapsed, onNavigate: () => setMenuOpen(false) }; @@ -79,6 +80,18 @@ export function Sidebar(props: {
+ entry.group === undefined)} {...nav} /> {groups.map((group) => ( void; + readonly hide: () => void; +} + +export function useSearchPalette(): SearchPalette { + const [open, setOpen] = useState(false); + const show = useCallback(() => setOpen(true), []); + const hide = useCallback(() => setOpen(false), []); + return { hide, open, show }; +} From 2de87d7eee80fd512443227a97e9a04ca431251c Mon Sep 17 00:00:00 2001 From: Szymon Chmal Date: Wed, 21 Oct 2026 14:19:01 +0200 Subject: [PATCH 03/32] test: typing `fleet` and Enter goes to /fleet; a worker result goes to /fleet/; a device result opens /fleet//; a lease result opens /leases/; a request result opens /queue/ (#770) --- e2e/console/search.spec.ts | 64 +++++++++++++++++++++++++++++++++++++- 1 file changed, 63 insertions(+), 1 deletion(-) diff --git a/e2e/console/search.spec.ts b/e2e/console/search.spec.ts index 4b568ccf5..d61d94423 100644 --- a/e2e/console/search.spec.ts +++ b/e2e/console/search.spec.ts @@ -1,6 +1,32 @@ import type { Page } from "@playwright/test"; -import { expect, signIn, test } from "./fixtures.js"; +import { waitFor } from "../helpers/wait.js"; +import { expect, type RunningDaemon, signIn, startDaemon, test } from "./fixtures.js"; + +const ONE_DEVICE = { limits: { ios: { maxDevices: 1, maxRunning: 1 }, maxRunning: 1 } }; +const IOS = { availableOsVersions: ["18.4"], knownModels: ["iPhone 16"] }; + +async function readJson(daemon: RunningDaemon, path: string): Promise { + const response = await fetch(new URL(path, daemon.url), { + headers: { Authorization: `Bearer ${daemon.tokens.operator}` }, + }); + return (await response.json()) as T; +} + +// why: a host with one device held by `nav-holder` and one request, `nav-waiter`, waiting behind it. +async function startHostWithQueue(): Promise { + const host = await startDaemon("worker", { config: ONE_DEVICE, driverScript: { ios: IOS } }); + const args = ["lease", "--platform", "ios", "--device", "iPhone 16", "--os", "18.4"]; + const granted = await host.cli([...args, "--detach", "--agent-id", "nav-holder"]); + expect(granted.code, granted.stderr).toBe(0); + host.cliBackground([...args, "--agent-id", "nav-waiter"]); + await waitFor( + async () => + (await readJson<{ requests: unknown[] }>(host, "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/v1/lease-requests")).requests.length === 1, + { label: "the daemon lists the waiting request" }, + ); + return host; +} async function openConsole(page: Page, token: string, path = "/"): Promise { await page.goto(path); @@ -34,3 +60,39 @@ test.describe("the search box", () => { await expect(button).toBeFocused(); }); }); + +test.describe("the search results", () => { + test("a typed name and Enter go to its page, worker, device, lease or request", async ({ + page, + }) => { + const host = await startHostWithQueue(); + try { + const [worker] = ( + await readJson<{ workers: { id: string; label?: string }[] }>(host, "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/v1/workers") + ).workers as [{ id: string; label?: string }]; + const [lease] = ( + await readJson<{ leases: { id: string; deviceId: string }[] }>(host, "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/v1/leases") + ).leases as [{ id: string; deviceId: string }]; + const [request] = (await readJson<{ requests: { id: string }[] }>(host, "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/v1/lease-requests")) + .requests as [{ id: string }]; + await openConsole(page, host.tokens.operator, new URL("/", host.url).toString()); + const box = page.getByRole("combobox", { name: "Search pages, items and actions" }); + const goTo = async (typed: string, path: RegExp) => { + await page.keyboard.press("Control+k"); + await box.fill(typed); + await page.keyboard.press("Enter"); + await expect(page.getByRole("dialog", { name: "Search" })).toBeHidden(); + await expect(page).toHaveURL(path); + }; + const encoded = (id: string) => encodeURIComponent(id).replaceAll(".", "\\."); + + await goTo("fleet", /\/fleet$/); + await goTo(worker.label ?? worker.id, new RegExp(`/fleet/${encoded(worker.id)}$`)); + await goTo("iphone", new RegExp(`/fleet/${encoded(worker.id)}/${encoded(lease.deviceId)}$`)); + await goTo("nav-holder", new RegExp(`/leases/${encoded(lease.id)}/?$`)); + await goTo("nav-waiter", new RegExp(`/queue/${encoded(request.id)}$`)); + } finally { + await host.dispose(); + } + }); +}); From 1a827c633092d5903b39ad61be442a5e52bf4a4b Mon Sep 17 00:00:00 2001 From: Szymon Chmal Date: Wed, 21 Oct 2026 14:20:36 +0200 Subject: [PATCH 04/32] feat(console): Enter on a page, worker, device, lease or request result goes there (#770) --- ui/src/app/shell.tsx | 20 ++++++- ui/src/ds/command-palette.css | 28 +++++++++ ui/src/ds/command-palette.tsx | 58 +++++++++++++++++-- ui/src/ds/index.ts | 2 +- ui/src/model/search.ts | 105 ++++++++++++++++++++++++++++++++++ ui/src/state/search.ts | 49 ++++++++++++++++ 6 files changed, 254 insertions(+), 8 deletions(-) create mode 100644 ui/src/model/search.ts diff --git a/ui/src/app/shell.tsx b/ui/src/app/shell.tsx index 310bb3be3..3f41591ea 100644 --- a/ui/src/app/shell.tsx +++ b/ui/src/app/shell.tsx @@ -3,7 +3,7 @@ import { useEffect } from "react"; import { AppFrame, Button, CommandPalette, Icon, Sidebar, Status, StatusDot } from "../ds"; import { NotFoundScreen } from "../screens/not-found"; import { usePath } from "../state/router"; -import { useSearchPalette } from "../state/search"; +import { useSearchPalette, useSearchSession } from "../state/search"; import { useInboxCount, useConnectionStatus, @@ -61,7 +61,7 @@ export function Shell() { } > {route === undefined ? : } - {palette.open ? : null} + {palette.open ? : null} ); } @@ -124,3 +124,19 @@ function SignOutButton(props: { ); } + +function SearchDialog({ hide }: { readonly hide: () => void }) { + const session = useSearchSession( + ROUTES.map((route) => ({ label: route.label, path: route.path })), + hide, + ); + return ( + + ); +} diff --git a/ui/src/ds/command-palette.css b/ui/src/ds/command-palette.css index 8b60505c9..560be6e61 100644 --- a/ui/src/ds/command-palette.css +++ b/ui/src/ds/command-palette.css @@ -34,3 +34,31 @@ .palette-list { overflow-y: auto; } + +.palette-group { + display: block; + padding-bottom: var(--space-2); +} + +.palette-group-label { + padding: var(--space-2) var(--space-4); + color: var(--text-muted); + font-size: var(--text-xs); + letter-spacing: 0.08em; + text-transform: uppercase; +} + +.palette-item { + display: flex; + align-items: center; + min-height: 36px; + padding: 0 var(--space-4); + color: var(--text); + font-size: var(--text-sm); + cursor: pointer; +} + +.palette-item[data-highlighted] { + background: var(--field); + box-shadow: inset 2px 0 0 var(--accent); +} diff --git a/ui/src/ds/command-palette.tsx b/ui/src/ds/command-palette.tsx index 6316ca7e5..669a66cd8 100644 --- a/ui/src/ds/command-palette.tsx +++ b/ui/src/ds/command-palette.tsx @@ -3,26 +3,74 @@ import "./command-palette.css"; import { Autocomplete } from "@base-ui/react/autocomplete"; import { Dialog } from "@base-ui/react/dialog"; -// why: the dialog is mounted only while open, so each opening starts from an empty box. -export function CommandPalette(props: { readonly onClose: () => void }) { +export interface PaletteItem { + readonly id: string; + readonly label: string; +} + +export interface PaletteGroup { + readonly name: string; + readonly items: readonly PaletteItem[]; +} + +// why: the dialog is mounted only while open, so each opening starts from an empty box. The caller +// filters and orders the groups; the box only reports what was typed. +export function CommandPalette(props: { + readonly groups: readonly PaletteGroup[]; + readonly typed: string; + readonly onType: (typed: string) => void; + readonly onChoose: (id: string) => void; + readonly onClose: () => void; +}) { + const { groups, onChoose, onClose, onType, typed } = props; + const items = groups.map((group) => ({ items: group.items, value: group.name })); return ( { - if (!open) props.onClose(); + if (!open) onClose(); }} > Search - + item.label} + autoHighlight="always" + inline + open + > - + + {(group: { value: string; items: readonly PaletteItem[] }) => ( + + + {group.value} + + + {(item: PaletteItem) => ( + onChoose(item.id)} + > + {item.label} + + )} + + + )} + diff --git a/ui/src/ds/index.ts b/ui/src/ds/index.ts index dc43c48ac..568d8a53f 100644 --- a/ui/src/ds/index.ts +++ b/ui/src/ds/index.ts @@ -1,7 +1,7 @@ import "./foundation.css"; export { Button, ButtonLink } from "./button"; -export { CommandPalette } from "./command-palette"; +export { CommandPalette, type PaletteGroup, type PaletteItem } from "./command-palette"; export { ConfirmHost, createConfirmer, type ConfirmSpec } from "./confirm-dialog"; export { Drawer, DrawerTabs } from "./drawer"; export { ChartPanel, MinuteChart, MinuteTable } from "./chart"; diff --git a/ui/src/model/search.ts b/ui/src/model/search.ts new file mode 100644 index 000000000..0625de201 --- /dev/null +++ b/ui/src/model/search.ts @@ -0,0 +1,105 @@ +import type { LeaseRowView } from "./leases"; +import { devicePath } from "./paths"; +import type { WaitingRow } from "./waiting"; +import { type WorkerView, workerName, workerPath } from "./workers"; + +export const SEARCH_GROUPS = [ + "Pages", + "Workers", + "Devices", + "Leases", + "Requests", + "Actions", +] as const; +export type SearchGroupName = (typeof SEARCH_GROUPS)[number]; + +export interface SearchResult { + readonly id: string; + readonly group: SearchGroupName; + readonly label: string; + readonly to: `/${string}`; +} + +export interface SearchGroup { + readonly name: SearchGroupName; + readonly results: readonly SearchResult[]; +} + +export interface SearchInput { + readonly pages: readonly { readonly label: string; readonly path: `/${string}` }[]; + readonly workers: readonly WorkerView[]; + readonly leases: readonly LeaseRowView[]; + readonly requests: readonly WaitingRow[]; +} + +export function buildResults(input: SearchInput): readonly SearchResult[] { + return [ + ...input.pages.map( + (page): SearchResult => ({ + group: "Pages", + id: `page:${page.path}`, + label: page.label, + to: page.path, + }), + ), + ...input.workers.map( + (worker): SearchResult => ({ + group: "Workers", + id: `worker:${worker.id}`, + label: workerName(worker), + to: workerPath(worker.id), + }), + ), + ...input.workers.flatMap((worker) => + (worker.devices ?? []).map( + (device): SearchResult => ({ + group: "Devices", + id: `device:${worker.id}/${device.id}`, + label: `${device.spec.model} · ${workerName(worker)}`, + to: devicePath(worker.id, device.id), + }), + ), + ), + ...input.leases.map( + (lease): SearchResult => ({ + group: "Leases", + id: `lease:${lease.key}`, + label: `${lease.holder} · ${lease.model}`, + to: lease.to as `/${string}`, + }), + ), + ...input.requests.map( + (request): SearchResult => ({ + group: "Requests", + id: `request:${request.key}`, + label: `${request.requester} · ${request.device}`, + to: request.to as `/${string}`, + }), + ), + ]; +} + +// why: a label and what is typed are both cut into words at spaces, `·` and `—`, so a pasted +// label still matches and `mac-studio-2` stays one word. +function wordsOf(text: string): readonly string[] { + return text + .toLowerCase() + .split(/[\s·—]+/) + .filter((word) => word !== ""); +} + +function matches(label: string, typed: readonly string[]): boolean { + const words = wordsOf(label); + return typed.every((word) => words.some((candidate) => candidate.startsWith(word))); +} + +export function searchGroups( + results: readonly SearchResult[], + typed: string, +): readonly SearchGroup[] { + const words = wordsOf(typed); + return SEARCH_GROUPS.map((name) => ({ + name, + results: results.filter((result) => result.group === name && matches(result.label, words)), + })).filter((group) => group.results.length > 0); +} diff --git a/ui/src/state/search.ts b/ui/src/state/search.ts index 23997d846..28769b994 100644 --- a/ui/src/state/search.ts +++ b/ui/src/state/search.ts @@ -1,5 +1,13 @@ import { useCallback, useState } from "react"; +import type { PaletteGroup } from "../ds"; +import { leaseRows, type LeaseList, type TokenList } from "../model/leases"; +import { buildResults, searchGroups } from "../model/search"; +import { type WaitingList, waitingTable } from "../model/waiting"; +import type { WorkerList } from "../model/workers"; +import { useLiveResource, useNow } from "./live"; +import { navigate } from "./router"; + export interface SearchPalette { readonly open: boolean; readonly show: () => void; @@ -12,3 +20,44 @@ export function useSearchPalette(): SearchPalette { const hide = useCallback(() => setOpen(false), []); return { hide, open, show }; } + +export interface SearchSession { + readonly typed: string; + readonly type: (typed: string) => void; + readonly groups: readonly PaletteGroup[]; + readonly choose: (id: string) => void; +} + +// why: the list is built once, when the dialog opens, from what the pages already read. +export function useSearchSession( + pages: readonly { readonly label: string; readonly path: `/${string}` }[], + hide: () => void, +): SearchSession { + const workers = useLiveResource("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/v1/workers").data?.workers ?? []; + const leases = useLiveResource("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/v1/leases").data?.leases ?? []; + const tokens = useLiveResource("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/v1/tokens").data?.tokens ?? []; + const requests = useLiveResource("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/v1/lease-requests").data?.requests ?? []; + const now = useNow(); + const [results] = useState(() => + buildResults({ + leases: leaseRows({ leases, now: now.server, tokens, workers }), + pages, + requests: waitingTable(requests, workers, now.server).rows, + workers, + }), + ); + const [typed, type] = useState(""); + return { + choose: (id) => { + const chosen = results.find((result) => result.id === id); + hide(); + if (chosen !== undefined) navigate(chosen.to); + }, + groups: searchGroups(results, typed).map((group) => ({ + items: group.results, + name: group.name, + })), + type, + typed, + }; +} From 0b00329080699f47515d3a96a155c7120dede56e Mon Sep 17 00:00:00 2001 From: Szymon Chmal Date: Wed, 21 Oct 2026 14:21:30 +0200 Subject: [PATCH 05/32] test: every row of the In short table gives the results it lists (#770) --- ui/src/model/search.test.ts | 108 ++++++++++++++++++++++++++++++++++++ ui/src/model/search.ts | 2 + ui/src/state/search.ts | 4 +- 3 files changed, 113 insertions(+), 1 deletion(-) create mode 100644 ui/src/model/search.test.ts diff --git a/ui/src/model/search.test.ts b/ui/src/model/search.test.ts new file mode 100644 index 000000000..70d4fbc6d --- /dev/null +++ b/ui/src/model/search.test.ts @@ -0,0 +1,108 @@ +import { describe, expect, it } from "vitest"; + +import { leaseRows, type LeaseRecord } from "./leases"; +import { buildResults, searchGroups } from "./search"; +import { type WaitingRequest, waitingTable } from "./waiting"; +import type { WorkerView } from "./workers"; + +const NOW = Date.parse("2026-10-02T12:00:00Z"); + +const PAGES = [ + { label: "Overview", path: "/" }, + { label: "Inbox", path: "/inbox" }, + { label: "Fleet", path: "/fleet" }, + { label: "Leases", path: "/leases" }, + { label: "Queue", path: "/queue" }, + { label: "Activity", path: "/activity" }, + { label: "Usage", path: "/usage" }, +] as const; + +function worker(id: string, label: string, overrides: Partial = {}): WorkerView { + return { + catalog: [], + connection: "connected", + devices: [], + drained: false, + id, + label, + lastSeenAt: NOW, + leases: [], + ...overrides, + }; +} + +const PHONE = { + id: "dev_1", + mode: "full", + physical: false, + servesDefaultMode: true, + spec: { model: "iPhone 17 Pro", osVersion: "26.0", physical: false, platform: "ios" }, + state: "leased", +} as const; + +const LEASE = { + deviceId: "dev_1", + grantedAt: NOW - 600_000, + id: "lse_1", + requesterId: "agent-1", + ttlDeadline: NOW + 600_000, + ttlMs: 900_000, + workerId: "wrk_2", +} as unknown as LeaseRecord; + +const REQUEST = { + createdAt: NOW - 60_000, + id: "req_1", + requesterId: "waiter", + spec: { model: "iPhone 17 Pro", platform: "ios" }, + stage: "queued", +} as unknown as WaitingRequest; + +function search( + typed: string, + options: { + readonly workers?: readonly WorkerView[]; + readonly mode?: "gateway" | "worker"; + } = {}, +): string[] { + const workers = options.workers ?? [ + worker("wrk_2", "mac-studio-2", { devices: [PHONE] }), + worker("wrk_3", "mac-mini-3", { drained: true }), + ]; + const results = buildResults({ + leases: leaseRows({ leases: [LEASE], now: NOW, tokens: [], workers }), + mode: options.mode ?? "gateway", + pages: PAGES, + requests: waitingTable([REQUEST], workers, NOW).rows, + workers, + }); + return searchGroups(results, typed).flatMap((group) => + group.results.map((result) => `${group.name}: ${result.label}`), + ); +} + +// why: the filter and its order are pure logic with many cases. +describe("the search results", () => { + it("gives, for every row of the table in the spec, the results it lists", () => { + expect(search("")).toEqual(PAGES.map((page) => `Pages: ${page.label}`)); + expect(search("fleet")).toEqual(["Pages: Fleet"]); + expect(search("mac-studio-2")).toEqual([ + "Workers: mac-studio-2", + "Devices: iPhone 17 Pro · mac-studio-2", + "Actions: Drain — mac-studio-2", + ]); + expect(search("agent-1")).toEqual([ + "Leases: agent-1 · iPhone 17 Pro", + "Actions: Release lease — agent-1 · iPhone 17 Pro", + ]); + expect(search("DRAIN")).toEqual(["Actions: Drain — mac-studio-2"]); + expect(search("zzz")).toEqual([]); + expect(search("drain", { mode: "worker" })).toEqual([]); + + const both = [worker("wrk_20", "mac-studio-20"), worker("wrk_2", "mac-studio-2")]; + expect(search("drain mac-studio-2", { workers: both })).toEqual([ + "Actions: Drain — mac-studio-2", + "Actions: Drain — mac-studio-20", + ]); + }); +}); diff --git a/ui/src/model/search.ts b/ui/src/model/search.ts index 0625de201..498d13ef9 100644 --- a/ui/src/model/search.ts +++ b/ui/src/model/search.ts @@ -1,3 +1,4 @@ +import type { DaemonModeName } from "./actions"; import type { LeaseRowView } from "./leases"; import { devicePath } from "./paths"; import type { WaitingRow } from "./waiting"; @@ -30,6 +31,7 @@ export interface SearchInput { readonly workers: readonly WorkerView[]; readonly leases: readonly LeaseRowView[]; readonly requests: readonly WaitingRow[]; + readonly mode: DaemonModeName | undefined; } export function buildResults(input: SearchInput): readonly SearchResult[] { diff --git a/ui/src/state/search.ts b/ui/src/state/search.ts index 28769b994..4e1837c3f 100644 --- a/ui/src/state/search.ts +++ b/ui/src/state/search.ts @@ -5,7 +5,7 @@ import { leaseRows, type LeaseList, type TokenList } from "../model/leases"; import { buildResults, searchGroups } from "../model/search"; import { type WaitingList, waitingTable } from "../model/waiting"; import type { WorkerList } from "../model/workers"; -import { useLiveResource, useNow } from "./live"; +import { useDaemonMode, useLiveResource, useNow } from "./live"; import { navigate } from "./router"; export interface SearchPalette { @@ -38,9 +38,11 @@ export function useSearchSession( const tokens = useLiveResource("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/v1/tokens").data?.tokens ?? []; const requests = useLiveResource("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/v1/lease-requests").data?.requests ?? []; const now = useNow(); + const mode = useDaemonMode(); const [results] = useState(() => buildResults({ leases: leaseRows({ leases, now: now.server, tokens, workers }), + mode, pages, requests: waitingTable(requests, workers, now.server).rows, workers, From 79f924a5c9a926ef7d1405f2e41ef3ab391e7809 Mon Sep 17 00:00:00 2001 From: Szymon Chmal Date: Wed, 21 Oct 2026 14:22:10 +0200 Subject: [PATCH 06/32] feat(console): the search filters by word, ranks whole words first and lists the actions the menus offer (#770) --- ui/src/model/search.ts | 78 +++++++++++++++++++++++++++++++++++++----- ui/src/state/search.ts | 2 +- 2 files changed, 71 insertions(+), 9 deletions(-) diff --git a/ui/src/model/search.ts b/ui/src/model/search.ts index 498d13ef9..03b4d125b 100644 --- a/ui/src/model/search.ts +++ b/ui/src/model/search.ts @@ -1,4 +1,10 @@ -import type { DaemonModeName } from "./actions"; +import { + type DaemonModeName, + type ItemAction, + leaseActions, + requestActions, + workerActions, +} from "./actions"; import type { LeaseRowView } from "./leases"; import { devicePath } from "./paths"; import type { WaitingRow } from "./waiting"; @@ -18,9 +24,13 @@ export interface SearchResult { readonly id: string; readonly group: SearchGroupName; readonly label: string; - readonly to: `/${string}`; + readonly target: SearchTarget; } +export type SearchTarget = + | { readonly kind: "go"; readonly to: `/${string}` } + | { readonly kind: "run"; readonly action: ItemAction }; + export interface SearchGroup { readonly name: SearchGroupName; readonly results: readonly SearchResult[]; @@ -41,7 +51,7 @@ export function buildResults(input: SearchInput): readonly SearchResult[] { group: "Pages", id: `page:${page.path}`, label: page.label, - to: page.path, + target: { kind: "go", to: page.path }, }), ), ...input.workers.map( @@ -49,7 +59,7 @@ export function buildResults(input: SearchInput): readonly SearchResult[] { group: "Workers", id: `worker:${worker.id}`, label: workerName(worker), - to: workerPath(worker.id), + target: { kind: "go", to: workerPath(worker.id) }, }), ), ...input.workers.flatMap((worker) => @@ -58,7 +68,7 @@ export function buildResults(input: SearchInput): readonly SearchResult[] { group: "Devices", id: `device:${worker.id}/${device.id}`, label: `${device.spec.model} · ${workerName(worker)}`, - to: devicePath(worker.id, device.id), + target: { kind: "go", to: devicePath(worker.id, device.id) }, }), ), ), @@ -67,7 +77,7 @@ export function buildResults(input: SearchInput): readonly SearchResult[] { group: "Leases", id: `lease:${lease.key}`, label: `${lease.holder} · ${lease.model}`, - to: lease.to as `/${string}`, + target: { kind: "go", to: lease.to as `/${string}` }, }), ), ...input.requests.map( @@ -75,9 +85,45 @@ export function buildResults(input: SearchInput): readonly SearchResult[] { group: "Requests", id: `request:${request.key}`, label: `${request.requester} · ${request.device}`, - to: request.to as `/${string}`, + target: { kind: "go", to: request.to as `/${string}` }, }), ), + ...actionResults(input), + ]; +} + +function actionResult(action: ItemAction, item: string): SearchResult { + return { + group: "Actions", + id: `action:${action.itemKey}:${action.id}`, + label: `${action.label} — ${item}`, + target: { action, kind: "run" }, + }; +} + +// why: the actions are the ones the ⋯ menus offer, read from the same list (ADR 0037 §3); an Inbox +// item adds none, since its actions are the same actions on the same worker, lease or request. +function actionResults(input: SearchInput): readonly SearchResult[] { + return [ + ...input.workers.flatMap((worker) => + workerActions( + { + connection: worker.connection, + drained: worker.drained, + id: worker.id, + name: workerName(worker), + }, + input.mode, + ).map((action) => actionResult(action, workerName(worker))), + ), + ...input.leases.flatMap((lease) => + leaseActions(lease).map((action) => actionResult(action, `${lease.holder} · ${lease.model}`)), + ), + ...input.requests.flatMap((request) => + requestActions(request).map((action) => + actionResult(action, `${request.requester} · ${request.device}`), + ), + ), ]; } @@ -95,13 +141,29 @@ function matches(label: string, typed: readonly string[]): boolean { return typed.every((word) => words.some((candidate) => candidate.startsWith(word))); } +// why: a result whose every typed word is a whole word of its label ranks before one that only +// starts with them, so `drain mac-studio-2` finds mac-studio-2 before mac-studio-20. +function isExact(label: string, typed: readonly string[]): boolean { + const words = wordsOf(label); + return typed.every((word) => words.includes(word)); +} + export function searchGroups( results: readonly SearchResult[], typed: string, ): readonly SearchGroup[] { const words = wordsOf(typed); + if (words.length === 0) { + return [{ name: "Pages", results: results.filter((result) => result.group === "Pages") }]; + } return SEARCH_GROUPS.map((name) => ({ name, - results: results.filter((result) => result.group === name && matches(result.label, words)), + results: results + .filter((result) => result.group === name && matches(result.label, words)) + .sort( + (a, b) => + Number(isExact(b.label, words)) - Number(isExact(a.label, words)) || + a.label.localeCompare(b.label, "en"), + ), })).filter((group) => group.results.length > 0); } diff --git a/ui/src/state/search.ts b/ui/src/state/search.ts index 4e1837c3f..5942d616e 100644 --- a/ui/src/state/search.ts +++ b/ui/src/state/search.ts @@ -53,7 +53,7 @@ export function useSearchSession( choose: (id) => { const chosen = results.find((result) => result.id === id); hide(); - if (chosen !== undefined) navigate(chosen.to); + if (chosen?.target.kind === "go") navigate(chosen.target.to); }, groups: searchGroups(results, typed).map((group) => ({ items: group.results, From 800039b311a4b95c9a4bfad2f20b6bb1613b39ac Mon Sep 17 00:00:00 2001 From: Szymon Chmal Date: Wed, 21 Oct 2026 14:23:00 +0200 Subject: [PATCH 07/32] test: drain and Enter drains it with the menu's toast and Undo; release, cancel and remove ask the menu's confirms (#770) --- e2e/console/search.spec.ts | 71 +++++++++++++++++++++++++++++++++++++- 1 file changed, 70 insertions(+), 1 deletion(-) diff --git a/e2e/console/search.spec.ts b/e2e/console/search.spec.ts index d61d94423..df674db21 100644 --- a/e2e/console/search.spec.ts +++ b/e2e/console/search.spec.ts @@ -1,7 +1,15 @@ import type { Page } from "@playwright/test"; import { waitFor } from "../helpers/wait.js"; -import { expect, type RunningDaemon, signIn, startDaemon, test } from "./fixtures.js"; +import { + disposeFleet, + expect, + type RunningDaemon, + signIn, + startDaemon, + startFleet, + test, +} from "./fixtures.js"; const ONE_DEVICE = { limits: { ios: { maxDevices: 1, maxRunning: 1 }, maxRunning: 1 } }; const IOS = { availableOsVersions: ["18.4"], knownModels: ["iPhone 16"] }; @@ -96,3 +104,64 @@ test.describe("the search results", () => { } }); }); + +test.describe("the search actions", () => { + test("an action runs as from its menu: drain with its toast and Undo, release and cancel after their confirms, remove after the name is typed", async ({ + page, + }) => { + const fleet = await startFleet([ + { driverScript: { ios: IOS }, label: "gone-a" }, + { driverScript: { ios: IOS }, label: "live-b" }, + ]); + const host = await startHostWithQueue(); + try { + const [stopped] = fleet.workers as [RunningDaemon]; + await stopped.stop(); + await waitFor( + async () => + ( + await readJson<{ workers: { connection: string }[] }>(fleet.gateway, "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/v1/workers") + ).workers.some((view) => view.connection === "disconnected"), + { label: "the gateway sees the stopped worker disconnected" }, + ); + const run = async (typed: string) => { + await page.keyboard.press("Control+k"); + await page.getByRole("combobox", { name: "Search pages, items and actions" }).fill(typed); + await page.keyboard.press("Enter"); + await expect(page.getByRole("dialog", { name: "Search" })).toBeHidden(); + }; + + await openConsole(page, fleet.gateway.tokens.operator, fleet.gateway.url); + await run("drain live-b"); + await expect(page.getByText("live-b drained", { exact: true })).toBeVisible(); + await page.getByRole("button", { name: "Undo" }).click(); + await expect(page.getByText("live-b takes leases again")).toBeVisible(); + + await run("remove gone-a"); + const removal = page.getByRole("alertdialog", { name: "Remove gone-a?" }); + const remove = removal.getByRole("button", { name: "Remove worker" }); + await expect(remove).toBeDisabled(); + await removal.getByRole("textbox").fill("gone-"); + await expect(remove).toBeDisabled(); + await removal.getByRole("textbox").fill("gone-a"); + await expect(remove).toBeEnabled(); + await removal.getByRole("button", { name: "Keep" }).click(); + + await page.goto(host.url); + await signIn(page, host.tokens.operator); + await expect(page.getByRole("button", { name: "Search or jump to…" })).toBeVisible(); + await run("release nav-holder"); + await expect( + page.getByRole("alertdialog", { name: "Release nav-holder's lease?" }), + ).toBeVisible(); + await page.getByRole("button", { name: "Keep" }).click(); + await run("cancel nav-waiter"); + await expect( + page.getByRole("alertdialog", { name: "Cancel nav-waiter's request?" }), + ).toBeVisible(); + } finally { + await host.dispose(); + await disposeFleet(fleet); + } + }); +}); From 18e45e56c3cb953cb392008001526e8ad256163e Mon Sep 17 00:00:00 2001 From: Szymon Chmal Date: Wed, 21 Oct 2026 14:24:06 +0200 Subject: [PATCH 08/32] feat(console): Enter on an action runs it through the menus' runner (#770) --- ui/src/state/search.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ui/src/state/search.ts b/ui/src/state/search.ts index 5942d616e..8b9689205 100644 --- a/ui/src/state/search.ts +++ b/ui/src/state/search.ts @@ -5,6 +5,7 @@ import { leaseRows, type LeaseList, type TokenList } from "../model/leases"; import { buildResults, searchGroups } from "../model/search"; import { type WaitingList, waitingTable } from "../model/waiting"; import type { WorkerList } from "../model/workers"; +import { useActions } from "./actions"; import { useDaemonMode, useLiveResource, useNow } from "./live"; import { navigate } from "./router"; @@ -39,6 +40,7 @@ export function useSearchSession( const requests = useLiveResource("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/v1/lease-requests").data?.requests ?? []; const now = useNow(); const mode = useDaemonMode(); + const { run } = useActions(); const [results] = useState(() => buildResults({ leases: leaseRows({ leases, now: now.server, tokens, workers }), @@ -54,6 +56,8 @@ export function useSearchSession( const chosen = results.find((result) => result.id === id); hide(); if (chosen?.target.kind === "go") navigate(chosen.target.to); + // why: the same runner as the ⋯ menus, so the confirm, the in-flight flag and the toast are theirs. + else if (chosen !== undefined) void run(chosen.target.action); }, groups: searchGroups(results, typed).map((group) => ({ items: group.results, From f15c52552b14359798d9ea13e23abbd86d175209 Mon Sep 17 00:00:00 2001 From: Szymon Chmal Date: Wed, 21 Oct 2026 14:24:45 +0200 Subject: [PATCH 09/32] =?UTF-8?q?test:=20=E2=86=91=20and=20=E2=86=93=20mov?= =?UTF-8?q?e=20the=20highlight,=20and=20Enter=20runs=20the=20highlighted?= =?UTF-8?q?=20result=20(#770)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- e2e/console/search.spec.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/e2e/console/search.spec.ts b/e2e/console/search.spec.ts index df674db21..90e07ba33 100644 --- a/e2e/console/search.spec.ts +++ b/e2e/console/search.spec.ts @@ -69,6 +69,25 @@ test.describe("the search box", () => { }); }); +test.describe("the search list", () => { + test("the first result is highlighted, ↑ and ↓ move the highlight, and Enter runs the highlighted result", async ({ + daemon, + page, + }) => { + await openConsole(page, daemon.tokens.operator); + await page.keyboard.press("Control+k"); + const highlighted = page.getByRole("dialog", { name: "Search" }).locator("[data-highlighted]"); + await expect(highlighted).toHaveText("Overview"); + await page.keyboard.press("ArrowDown"); + await page.keyboard.press("ArrowDown"); + await expect(highlighted).toHaveText("Fleet"); + await page.keyboard.press("ArrowUp"); + await expect(highlighted).toHaveText("Inbox"); + await page.keyboard.press("Enter"); + await expect(page).toHaveURL(/\/inbox$/); + }); +}); + test.describe("the search results", () => { test("a typed name and Enter go to its page, worker, device, lease or request", async ({ page, From 1cec2695395f065f44f881c345f144ba5ffa20aa Mon Sep 17 00:00:00 2001 From: Szymon Chmal Date: Wed, 21 Oct 2026 14:24:49 +0200 Subject: [PATCH 10/32] test: no results shows "No results for " (#770) --- e2e/console/search.spec.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/e2e/console/search.spec.ts b/e2e/console/search.spec.ts index 90e07ba33..b8edb0d21 100644 --- a/e2e/console/search.spec.ts +++ b/e2e/console/search.spec.ts @@ -88,6 +88,18 @@ test.describe("the search list", () => { }); }); +test.describe("the search list when nothing matches", () => { + test('no results shows "No results for "', async ({ daemon, page }) => { + await openConsole(page, daemon.tokens.operator); + await page.keyboard.press("Control+k"); + const dialog = page.getByRole("dialog", { name: "Search" }); + await expect(dialog.getByText("No results for")).toBeHidden(); + await dialog.getByRole("combobox").fill("zzz"); + await expect(dialog.getByText("No results for zzz", { exact: true })).toBeVisible(); + await expect(dialog.getByRole("option")).toHaveCount(0); + }); +}); + test.describe("the search results", () => { test("a typed name and Enter go to its page, worker, device, lease or request", async ({ page, From e459fb50d9b3baf28b74c29dd64858775a2a50f5 Mon Sep 17 00:00:00 2001 From: Szymon Chmal Date: Wed, 21 Oct 2026 14:25:53 +0200 Subject: [PATCH 11/32] feat(console): the search says when nothing matches (#770) --- ui/src/app/shell.tsx | 1 + ui/src/ds/command-palette.css | 10 ++++++++++ ui/src/ds/command-palette.tsx | 4 +++- ui/src/state/search.ts | 2 ++ 4 files changed, 16 insertions(+), 1 deletion(-) diff --git a/ui/src/app/shell.tsx b/ui/src/app/shell.tsx index 3f41591ea..7b2c816eb 100644 --- a/ui/src/app/shell.tsx +++ b/ui/src/app/shell.tsx @@ -134,6 +134,7 @@ function SearchDialog({ hide }: { readonly hide: () => void }) { void; readonly onChoose: (id: string) => void; readonly onClose: () => void; }) { - const { groups, onChoose, onClose, onType, typed } = props; + const { empty, groups, onChoose, onClose, onType, typed } = props; const items = groups.map((group) => ({ items: group.items, value: group.name })); return ( + {empty} {(group: { value: string; items: readonly PaletteItem[] }) => ( diff --git a/ui/src/state/search.ts b/ui/src/state/search.ts index 8b9689205..90c3f514a 100644 --- a/ui/src/state/search.ts +++ b/ui/src/state/search.ts @@ -26,6 +26,7 @@ export interface SearchSession { readonly typed: string; readonly type: (typed: string) => void; readonly groups: readonly PaletteGroup[]; + readonly empty: string; readonly choose: (id: string) => void; } @@ -59,6 +60,7 @@ export function useSearchSession( // why: the same runner as the ⋯ menus, so the confirm, the in-flight flag and the toast are theirs. else if (chosen !== undefined) void run(chosen.target.action); }, + empty: `No results for ${typed}`, groups: searchGroups(results, typed).map((group) => ({ items: group.results, name: group.name, From 6a9c62063c7f8932b9e594fbf8e769a88dc00f55 Mon Sep 17 00:00:00 2001 From: Szymon Chmal Date: Wed, 21 Oct 2026 14:26:05 +0200 Subject: [PATCH 12/32] =?UTF-8?q?test:=20=E2=8C=98K=20does=20nothing=20whi?= =?UTF-8?q?le=20a=20drawer=20is=20open=20(#770)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- e2e/console/search.spec.ts | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/e2e/console/search.spec.ts b/e2e/console/search.spec.ts index b8edb0d21..d358a07fe 100644 --- a/e2e/console/search.spec.ts +++ b/e2e/console/search.spec.ts @@ -88,6 +88,28 @@ test.describe("the search list", () => { }); }); +test.describe("the search shortcut", () => { + test("⌘K does nothing while a drawer is open", async ({ page }) => { + const host = await startHostWithQueue(); + try { + const [request] = (await readJson<{ requests: { id: string }[] }>(host, "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/v1/lease-requests")) + .requests as [{ id: string }]; + await page.goto(new URL(`/queue/${request.id}`, host.url).toString()); + await signIn(page, host.tokens.operator); + const drawer = page.getByRole("dialog"); + await expect(drawer).toHaveCount(1); + await expect(drawer).toContainText("nav-waiter"); + await page.keyboard.press("Control+k"); + await page.keyboard.press("Meta+k"); + await expect(page.getByRole("dialog", { name: "Search" })).toHaveCount(0); + await expect(drawer).toHaveCount(1); + await expect(drawer).toContainText("nav-waiter"); + } finally { + await host.dispose(); + } + }); +}); + test.describe("the search list when nothing matches", () => { test('no results shows "No results for "', async ({ daemon, page }) => { await openConsole(page, daemon.tokens.operator); From 4bc27ce9de9e940fb961a20be6f9632a7ae59162 Mon Sep 17 00:00:00 2001 From: Szymon Chmal Date: Wed, 21 Oct 2026 14:34:49 +0200 Subject: [PATCH 13/32] =?UTF-8?q?feat(console):=20=E2=8C=98K=20does=20noth?= =?UTF-8?q?ing=20while=20a=20drawer=20or=20dialog=20is=20open=20(#770)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- e2e/console/search.spec.ts | 4 ++++ ui/src/app/shell.tsx | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/e2e/console/search.spec.ts b/e2e/console/search.spec.ts index d358a07fe..4685e3ea6 100644 --- a/e2e/console/search.spec.ts +++ b/e2e/console/search.spec.ts @@ -139,6 +139,9 @@ test.describe("the search results", () => { await openConsole(page, host.tokens.operator, new URL("/", host.url).toString()); const box = page.getByRole("combobox", { name: "Search pages, items and actions" }); const goTo = async (typed: string, path: RegExp) => { + // why: ⌘K does nothing while a drawer is open, so the one the last step opened is closed first. + if ((await page.getByRole("dialog").count()) > 0) await page.keyboard.press("Escape"); + await expect(page.getByRole("dialog")).toHaveCount(0); await page.keyboard.press("Control+k"); await box.fill(typed); await page.keyboard.press("Enter"); @@ -178,6 +181,7 @@ test.describe("the search actions", () => { { label: "the gateway sees the stopped worker disconnected" }, ); const run = async (typed: string) => { + await expect(page.getByRole("alertdialog")).toHaveCount(0); await page.keyboard.press("Control+k"); await page.getByRole("combobox", { name: "Search pages, items and actions" }).fill(typed); await page.keyboard.press("Enter"); diff --git a/ui/src/app/shell.tsx b/ui/src/app/shell.tsx index 7b2c816eb..092038464 100644 --- a/ui/src/app/shell.tsx +++ b/ui/src/app/shell.tsx @@ -14,6 +14,9 @@ import { import { useSidebar } from "../state/sidebar"; import { ROUTES, routeFor } from "./routes"; +const MODAL_DIALOG = + '[role="dialog"]:not([aria-modal="false"]), [role="alertdialog"]:not([aria-modal="false"])'; + export function Shell() { const path = usePath(); const route = routeFor(path); @@ -27,6 +30,9 @@ export function Shell() { useEffect(() => { const onKey = (event: KeyboardEvent) => { if ((event.metaKey || event.ctrlKey) && event.key.toLowerCase() === "k") { + // why: a drawer or a dialog is already open over the console, and the search opens over + // none; a toast is a non-modal dialog and does not count. + if (document.querySelector(MODAL_DIALOG) !== null) return; event.preventDefault(); palette.show(); } From 00a98e2b34ec5697b21e322a6a6c243b062f6a9a Mon Sep 17 00:00:00 2001 From: Szymon Chmal Date: Wed, 21 Oct 2026 14:35:45 +0200 Subject: [PATCH 14/32] =?UTF-8?q?test:=20opened=20before=20the=20data=20lo?= =?UTF-8?q?ads,=20the=20groups=20show=20Loading=E2=80=A6=20and=20fill=20in?= =?UTF-8?q?=20while=20the=20highlight=20stays;=20a=20failing=20/v1/workers?= =?UTF-8?q?=20says=20Could=20not=20load=20workers.=20(#770)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- e2e/console/search.spec.ts | 47 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/e2e/console/search.spec.ts b/e2e/console/search.spec.ts index 4685e3ea6..d258f524b 100644 --- a/e2e/console/search.spec.ts +++ b/e2e/console/search.spec.ts @@ -88,6 +88,53 @@ test.describe("the search list", () => { }); }); +test.describe("the search while data loads", () => { + test("opened before the data loads, each group says Loading… and fills in while the highlight stays, and a failed read says it could not load", async ({ + page, + }) => { + const host = await startHostWithQueue(); + try { + let release: () => void = () => undefined; + const gate = new Promise((resolve) => { + release = resolve; + }); + await page.route(/\/v1\/leases$/, async (route) => { + await gate; + await route.continue(); + }); + await openConsole(page, host.tokens.operator, new URL("/", host.url).toString()); + await page.keyboard.press("Control+k"); + const dialog = page.getByRole("dialog", { name: "Search" }); + await dialog.getByRole("combobox").fill("nav"); + const highlighted = dialog.locator("[data-highlighted]"); + await expect(highlighted).toContainText("nav-waiter"); + await expect(dialog.getByText("Loading…")).toHaveCount(2); + await expect(dialog.getByRole("option", { name: /nav-holder/ })).toHaveCount(0); + + release(); + await expect(dialog.getByRole("option", { name: /nav-holder/ })).toHaveCount(2); + await expect(dialog.getByText("Loading…")).toHaveCount(0); + await expect(highlighted).toContainText("nav-waiter"); + await expect(highlighted).toHaveCount(1); + + await page.keyboard.press("Escape"); + await page.unroute(/\/v1\/leases$/); + await page.route(/\/v1\/workers$/, (route) => + route.fulfill({ body: "{}", contentType: "application/json", status: 500 }), + ); + await page.reload(); + await expect(page.getByRole("button", { name: "Search or jump to…" })).toBeVisible(); + await page.keyboard.press("Control+k"); + await dialog.getByRole("combobox").fill("nav"); + await expect(dialog.getByText("Could not load workers.")).toBeVisible(); + await expect(dialog.getByText("Could not load devices.")).toBeVisible(); + await expect(dialog.getByRole("option", { name: /nav-holder/ })).toHaveCount(2); + } finally { + await host.dispose(); + } + }); +}); + test.describe("the search shortcut", () => { test("⌘K does nothing while a drawer is open", async ({ page }) => { const host = await startHostWithQueue(); From 97292bf9029301fe9f17082da11b4314c70ccdde Mon Sep 17 00:00:00 2001 From: Szymon Chmal Date: Wed, 21 Oct 2026 14:38:52 +0200 Subject: [PATCH 15/32] feat(console): groups still loading say so and fill in while the highlight stays on its result (#770) --- ui/src/app/shell.tsx | 7 +- ui/src/ds/command-palette.css | 8 ++ ui/src/ds/command-palette.tsx | 143 ++++++++++++++++++++++++---------- ui/src/model/search.ts | 19 +++-- ui/src/state/search.ts | 87 +++++++++++++++++---- 5 files changed, 200 insertions(+), 64 deletions(-) diff --git a/ui/src/app/shell.tsx b/ui/src/app/shell.tsx index 092038464..9697b2991 100644 --- a/ui/src/app/shell.tsx +++ b/ui/src/app/shell.tsx @@ -14,6 +14,8 @@ import { import { useSidebar } from "../state/sidebar"; import { ROUTES, routeFor } from "./routes"; +const PAGES = ROUTES.map((route) => ({ label: route.label, path: route.path })); + const MODAL_DIALOG = '[role="dialog"]:not([aria-modal="false"]), [role="alertdialog"]:not([aria-modal="false"])'; @@ -132,10 +134,7 @@ function SignOutButton(props: { } function SearchDialog({ hide }: { readonly hide: () => void }) { - const session = useSearchSession( - ROUTES.map((route) => ({ label: route.label, path: route.path })), - hide, - ); + const session = useSearchSession(PAGES, hide); return ( (undefined); + const current = items.some((item) => item.id === pinned) ? pinned : items[0]?.id; + if (current !== pinned) setPinned(current); + return { current, move: setPinned }; +} + // why: the dialog is mounted only while open, so each opening starts from an empty box. The caller // filters and orders the groups; the box only reports what was typed. export function CommandPalette(props: { @@ -24,7 +37,19 @@ export function CommandPalette(props: { readonly onClose: () => void; }) { const { empty, groups, onChoose, onClose, onType, typed } = props; - const items = groups.map((group) => ({ items: group.items, value: group.name })); + const listId = useId(); + const items = groups.flatMap((group) => group.items); + const { current, move } = useHighlight(items); + const optionId = (id: string) => `${listId}-${id}`; + useEffect(() => { + if (current !== undefined) { + document.getElementById(optionId(current))?.scrollIntoView({ block: "nearest" }); + } + }); + const step = (by: number) => { + const at = items.findIndex((item) => item.id === current); + move(items[Math.min(items.length - 1, Math.max(0, at + by))]?.id); + }; return ( Search - item.label} - autoHighlight="always" - inline - open - > - - {empty} - - {(group: { value: string; items: readonly PaletteItem[] }) => ( - - - {group.value} - - - {(item: PaletteItem) => ( - onChoose(item.id)} - > - {item.label} - - )} - - - )} - - + onChange={(event) => { + move(undefined); + onType(event.currentTarget.value); + }} + onKeyDown={(event) => { + if (event.key === "ArrowDown" || event.key === "ArrowUp") { + event.preventDefault(); + step(event.key === "ArrowDown" ? 1 : -1); + } else if (event.key === "Enter" && current !== undefined) { + event.preventDefault(); + onChoose(current); + } + }} + /> + {empty === "" ? null : ( +

+ {empty} +

+ )} +
+ {groups.map((group) => ( + + ))} +
); } + +function PaletteSection(props: { + readonly group: PaletteGroup; + readonly current: string | undefined; + readonly optionId: (id: string) => string; + readonly onMove: (id: string) => void; + readonly onChoose: (id: string) => void; +}) { + const { current, group, onChoose, onMove, optionId } = props; + const labelId = useId(); + return ( +
+

+ {group.name} +

+ {group.note === undefined ? null :

{group.note}

} + {group.items.map((item) => ( +
event.preventDefault()} + onMouseMove={() => onMove(item.id)} + onClick={() => onChoose(item.id)} + > + {item.label} +
+ ))} +
+ ); +} diff --git a/ui/src/model/search.ts b/ui/src/model/search.ts index 03b4d125b..7d81274a5 100644 --- a/ui/src/model/search.ts +++ b/ui/src/model/search.ts @@ -31,9 +31,12 @@ export type SearchTarget = | { readonly kind: "go"; readonly to: `/${string}` } | { readonly kind: "run"; readonly action: ItemAction }; +export type GroupStatus = "loading" | "failed"; + export interface SearchGroup { readonly name: SearchGroupName; readonly results: readonly SearchResult[]; + readonly note?: string; } export interface SearchInput { @@ -151,19 +154,25 @@ function isExact(label: string, typed: readonly string[]): boolean { export function searchGroups( results: readonly SearchResult[], typed: string, + statuses: Partial> = {}, ): readonly SearchGroup[] { const words = wordsOf(typed); if (words.length === 0) { return [{ name: "Pages", results: results.filter((result) => result.group === "Pages") }]; } - return SEARCH_GROUPS.map((name) => ({ - name, - results: results + return SEARCH_GROUPS.flatMap((name): SearchGroup[] => { + const found = results .filter((result) => result.group === name && matches(result.label, words)) .sort( (a, b) => Number(isExact(b.label, words)) - Number(isExact(a.label, words)) || a.label.localeCompare(b.label, "en"), - ), - })).filter((group) => group.results.length > 0); + ); + const status = statuses[name]; + if (status !== undefined) { + const note = status === "loading" ? "Loading…" : `Could not load ${name.toLowerCase()}.`; + return [{ name, note, results: found }]; + } + return found.length === 0 ? [] : [{ name, results: found }]; + }); } diff --git a/ui/src/state/search.ts b/ui/src/state/search.ts index 90c3f514a..34754ba27 100644 --- a/ui/src/state/search.ts +++ b/ui/src/state/search.ts @@ -1,12 +1,20 @@ -import { useCallback, useState } from "react"; +import { useCallback, useMemo, useState } from "react"; +import type { ApiPath } from "../data/api"; +import type { ResourceState } from "../data/live/connection"; import type { PaletteGroup } from "../ds"; import { leaseRows, type LeaseList, type TokenList } from "../model/leases"; -import { buildResults, searchGroups } from "../model/search"; +import { + buildResults, + type GroupStatus, + searchGroups, + type SearchGroupName, +} from "../model/search"; import { type WaitingList, waitingTable } from "../model/waiting"; import type { WorkerList } from "../model/workers"; import { useActions } from "./actions"; import { useDaemonMode, useLiveResource, useNow } from "./live"; +import { loadView } from "./resource"; import { navigate } from "./router"; export interface SearchPalette { @@ -30,28 +38,74 @@ export interface SearchSession { readonly choose: (id: string) => void; } -// why: the list is built once, when the dialog opens, from what the pages already read. +type Source = + | { readonly kind: "loading" } + | { readonly kind: "failed" } + | { readonly kind: "ready"; readonly data: T | undefined }; + +// why: a route a single host does not answer is not a failure to load; it lists nothing. +function sourceOf(state: ResourceState): Source { + const view = loadView(state); + if (view.kind === "loading") return { kind: "loading" }; + if (view.kind === "refused") return { kind: "failed" }; + return { data: view.kind === "ready" ? view.data : undefined, kind: "ready" }; +} + +// why: a group already shown never changes while the dialog is open, so each read is kept as it +// stood the first time it settled, answered or failed; a live update after that changes nothing. +function useSettledOnce(path: ApiPath): Source { + const live = sourceOf(useLiveResource(path)); + const [kept, keep] = useState(live); + if (kept.kind === "loading" && live.kind !== "loading") keep(live); + return kept.kind === "loading" ? live : kept; +} + +// why: the list is built when the dialog opens; a group that was loading fills in once its data +// arrives (the Actions only once every read they come from has settled), and then never changes. export function useSearchSession( pages: readonly { readonly label: string; readonly path: `/${string}` }[], hide: () => void, ): SearchSession { - const workers = useLiveResource("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/v1/workers").data?.workers ?? []; - const leases = useLiveResource("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/v1/leases").data?.leases ?? []; - const tokens = useLiveResource("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/v1/tokens").data?.tokens ?? []; - const requests = useLiveResource("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/v1/lease-requests").data?.requests ?? []; + const workers = useSettledOnce("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/v1/workers"); + const leases = useSettledOnce("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/v1/leases"); + const tokens = useSettledOnce("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/v1/tokens"); + const requests = useSettledOnce("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/v1/lease-requests"); const now = useNow(); + const [at] = useState(now.server); const mode = useDaemonMode(); const { run } = useActions(); - const [results] = useState(() => - buildResults({ - leases: leaseRows({ leases, now: now.server, tokens, workers }), + const results = useMemo(() => { + const workerList = workers.kind === "ready" ? (workers.data?.workers ?? []) : []; + return buildResults({ + leases: leaseRows({ + leases: leases.kind === "ready" ? (leases.data?.leases ?? []) : [], + now: at, + tokens: tokens.kind === "ready" ? (tokens.data?.tokens ?? []) : [], + workers: workerList, + }), mode, pages, - requests: waitingTable(requests, workers, now.server).rows, - workers, - }), - ); + requests: waitingTable( + requests.kind === "ready" ? (requests.data?.requests ?? []) : [], + workerList, + at, + ).rows, + workers: workerList, + }); + }, [at, leases, mode, pages, requests, tokens, workers]); + const statuses: Partial> = { + ...(workers.kind === "ready" ? {} : { Devices: workers.kind, Workers: workers.kind }), + ...(leases.kind === "failed" ? { Leases: "failed" as const } : {}), + ...(leases.kind === "loading" || tokens.kind === "loading" || workers.kind === "loading" + ? { Leases: "loading" as const } + : {}), + ...(requests.kind === "ready" ? {} : { Requests: requests.kind }), + ...([workers, leases, tokens, requests].some((source) => source.kind === "loading") + ? { Actions: "loading" as const } + : {}), + }; const [typed, type] = useState(""); + const groups = searchGroups(results, typed, statuses); return { choose: (id) => { const chosen = results.find((result) => result.id === id); @@ -60,10 +114,11 @@ export function useSearchSession( // why: the same runner as the ⋯ menus, so the confirm, the in-flight flag and the toast are theirs. else if (chosen !== undefined) void run(chosen.target.action); }, - empty: `No results for ${typed}`, - groups: searchGroups(results, typed).map((group) => ({ + empty: groups.length === 0 ? `No results for ${typed}` : "", + groups: groups.map((group) => ({ items: group.results, name: group.name, + ...(group.note === undefined ? {} : { note: group.note }), })), type, typed, From f946110e93654a9f31c6f4c6de38a96e8561f4ba Mon Sep 17 00:00:00 2001 From: Szymon Chmal Date: Wed, 21 Oct 2026 14:39:58 +0200 Subject: [PATCH 16/32] test: a live update while the dialog is open does not change the list or the highlight (#770) --- e2e/console/search.spec.ts | 51 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/e2e/console/search.spec.ts b/e2e/console/search.spec.ts index d258f524b..a271f20e5 100644 --- a/e2e/console/search.spec.ts +++ b/e2e/console/search.spec.ts @@ -135,6 +135,57 @@ test.describe("the search while data loads", () => { }); }); +test.describe("the search during live updates", () => { + test("a live update while the dialog is open changes neither the list nor the highlight, and reopening builds the list again", async ({ + page, + }) => { + const host = await startHostWithQueue(); + try { + await openConsole(page, host.tokens.operator, new URL("/", host.url).toString()); + await page.keyboard.press("Control+k"); + const dialog = page.getByRole("dialog", { name: "Search" }); + const box = dialog.getByRole("combobox"); + await box.fill("nav"); + const options = dialog.getByRole("option"); + const before = await options.allInnerTexts(); + expect(before).toHaveLength(4); + await page.keyboard.press("ArrowDown"); + const highlighted = dialog.locator("[data-highlighted]"); + await expect(highlighted).toHaveText(before[1] ?? ""); + + const refetched = page.waitForResponse( + async (response) => + response.url().endsWith("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/v1/lease-requests") && + (await response.text()).includes("nav-late"), + ); + host.cliBackground([ + "lease", + "--platform", + "ios", + "--device", + "iPhone 16", + "--os", + "18.4", + "--agent-id", + "nav-late", + ]); + await refetched; + await page.evaluate( + () => new Promise((resolve) => requestAnimationFrame(() => requestAnimationFrame(resolve))), + ); + expect(await options.allInnerTexts()).toEqual(before); + await expect(highlighted).toHaveText(before[1] ?? ""); + + await page.keyboard.press("Escape"); + await page.keyboard.press("Control+k"); + await box.fill("nav-late"); + await expect(options.first()).toContainText("nav-late"); + } finally { + await host.dispose(); + } + }); +}); + test.describe("the search shortcut", () => { test("⌘K does nothing while a drawer is open", async ({ page }) => { const host = await startHostWithQueue(); From cf833e30f287383efd13879dcf2154f9de4c179c Mon Sep 17 00:00:00 2001 From: Szymon Chmal Date: Wed, 21 Oct 2026 14:40:19 +0200 Subject: [PATCH 17/32] test: axe passes with the search open, in light and dark; it adds no