diff --git a/.claude/skills/openbot-screen-layout/SKILL.md b/.claude/skills/openbot-screen-layout/SKILL.md index 7e455c4f13..a5fcfcf2ab 100644 --- a/.claude/skills/openbot-screen-layout/SKILL.md +++ b/.claude/skills/openbot-screen-layout/SKILL.md @@ -168,6 +168,10 @@ itself when the screen behind it changes something. 1. `Item size="sm"` for rows inside a card. `default` only for a row standing on its own. 2. `Button size="sm"` for a control inside a row or a dialog footer; `lg` for a page's own actions; `icon-sm` for a control floating over artwork. + The page's main add action is one filled button, in the header or in the page's sticky toolbar + where one exists (Apps). In the header it is `PageAddButton` in `PageShell`'s `action`: a plus + and a short label ("New Bot", "Add fact"). The same add in an empty state is `outline`. Row + actions can still be filled. 3. `Item variant` — pick **one for the whole screen**. `muted` is a fill with no border; `outline` is a border with no fill; `default` is neither. Mixing two of them on one screen reads as two different kinds of list, and the reader looks for a distinction that is not there. @@ -178,7 +182,7 @@ itself when the screen behind it changes something. 1. Creating a thing that takes several fields — a credential, a key — is its own screen, not a dialog over the list. Put it at `_.new.tsx` (the `_` keeps it from nesting inside the list's route), - and make the list's `action` a `Button` rendering a `Link` to it. + and make the list's `action` a `PageAddButton` linking to it. 2. `PageShell` with `backButton` pointing at the list, a title that is the verb ("Add credential"), and a description saying what happens on save. 3. The fields go in one `PageCard` inside a `
`, stacked in a single column, each a `Field` diff --git a/app/src/components/layout/page-shell.tsx b/app/src/components/layout/page-shell.tsx index d6d1868dc2..ac9dae371d 100644 --- a/app/src/components/layout/page-shell.tsx +++ b/app/src/components/layout/page-shell.tsx @@ -1,4 +1,4 @@ -import { IconChevronLeft } from "@/components/icons"; +import { IconChevronLeft, IconPlus } from "@/components/icons"; import { Link, type LinkProps } from "@tanstack/react-router"; import type * as React from "react"; import { cn } from "@/lib/utils"; @@ -123,4 +123,35 @@ export function PageShell({ ); } +/** + * A list page's main add action, for `PageShell`'s `action`: one filled button with a plus and a + * short label ("New Bot", "Add fact"). Drawn here, once, so every list page draws it the same way: + * the default variant and the page-action size (the layout skill, Procedure 4). It is a link to the + * screen where the thing is made, or, given `onClick`, opens what the page opens itself. + * + * One per page. The same add in an empty state is an outlined `Button size="sm"`, so the page still + * has one filled button. It lives here, not in `page-parts.tsx`, because a link needs the router and + * that file imports none. + */ +export function PageAddButton({ + children, + link, + onClick, +}: { children: React.ReactNode } & ( + | { link: LinkProps; onClick?: never } + | { onClick: () => void; link?: never } +)) { + return link ? ( + + ) : ( + + ); +} + export { PageCard, PageEmpty, PageRows, PageSection } from "./page-parts"; diff --git a/app/src/components/manage/credentials-page.tsx b/app/src/components/manage/credentials-page.tsx index 3334bf6700..fd08e388f9 100644 --- a/app/src/components/manage/credentials-page.tsx +++ b/app/src/components/manage/credentials-page.tsx @@ -2,6 +2,7 @@ import { IconKey, IconPlus } from "@/components/icons"; import { useMutation, useQuery } from "@tanstack/react-query"; import { Link } from "@tanstack/react-router"; import { + PageAddButton, PageEmpty, PageRows, PageSection, @@ -36,14 +37,7 @@ export function CredentialsPage() { } - size="sm" - variant="ghost" - > - - Add {noun} - + Add {noun} } description="Manage this organization’s keys and tokens. Saved secrets cannot be viewed again." title={paths.credentialsLabel} diff --git a/app/src/components/manage/plugins-list-page.tsx b/app/src/components/manage/plugins-list-page.tsx index 5cb2b85cb4..bd14003338 100644 --- a/app/src/components/manage/plugins-list-page.tsx +++ b/app/src/components/manage/plugins-list-page.tsx @@ -5,12 +5,12 @@ import { IconChevronRight, IconCircleCheck, IconPlug, - IconPlus, } from "@/components/icons"; import { useQuery } from "@tanstack/react-query"; import { Link } from "@tanstack/react-router"; import * as React from "react"; import { + PageAddButton, PageEmpty, PageRows, PageSection, @@ -22,7 +22,6 @@ import { usePendingRequestCounts, } from "@/components/plugins/access-requests"; import { PluginLogo } from "@/components/plugins/plugin-logo"; -import { Button } from "@/components/ui/button"; import { Item, ItemActions, @@ -188,14 +187,9 @@ export function PluginsListPage({ */ action={ mayAddServer ? ( - + ) : undefined } description="Connect services for your company, then choose which Bots can use each service’s tools." diff --git a/app/src/components/manage/skills-page.tsx b/app/src/components/manage/skills-page.tsx index 1eac9c269e..d55562816f 100644 --- a/app/src/components/manage/skills-page.tsx +++ b/app/src/components/manage/skills-page.tsx @@ -3,6 +3,7 @@ import { useQuery } from "@tanstack/react-query"; import { Link } from "@tanstack/react-router"; import * as React from "react"; import { + PageAddButton, PageEmpty, PageRows, PageSection, @@ -47,11 +48,12 @@ export function SkillsPage() { const { data: hiddenAgents } = useQuery(agentListQueryOptions(true, scope)); const skills = skillList.data ?? []; - const newSkill = (size: "lg" | "sm") => ( + // The empty state's; the page's own is `PageAddButton`, so the page has one filled button. + const newSkill = () => ( + {variant === "page" ? ( + Add fact + ) : ( + + )} - Remember a fact + Add fact All your Bots will know it. @@ -147,11 +154,8 @@ export function MemoryList({ const botName = (id: string | null) => agents.data?.find((agent) => agent.id === id)?.name ?? "your Bot"; return ( - + // One section, so no title: the page title already names it. + {memories.isPending ? null : memories.error ? (

{failureSaid(memories.error)} @@ -175,9 +179,7 @@ export function MemoryList({ })} ) : ( - - Add one with Remember a fact. - + )} ); diff --git a/app/src/components/routines/new-routine-button.tsx b/app/src/components/routines/new-routine-button.tsx index 6adac61967..eecd4e2373 100644 --- a/app/src/components/routines/new-routine-button.tsx +++ b/app/src/components/routines/new-routine-button.tsx @@ -1,22 +1,32 @@ import { Link, useRouter } from "@tanstack/react-router"; import { IconPlus } from "@/components/icons"; +import { PageAddButton } from "@/components/layout/page-shell"; import { Button } from "@/components/ui/button"; /** * New routine, opening the create screen. `agentId` starts it out for one Bot. * - * `outline` where it stands alone in an empty state, `ghost` on a page's title row, as Add - * credential and New skill are drawn. + * The page's one add action on a page's title row (`PageAddButton`), `outline` where it stands + * alone in an empty state. */ export function NewRoutineButton({ agentId, - variant = "ghost", + variant = "page", }: { agentId?: string; - variant?: "ghost" | "outline"; + /** `page` for `PageShell`'s `action`, `outline` for an empty state. */ + variant?: "page" | "outline"; }) { // A list drawn with no router around it, as a skin's own tests draw it, has nowhere to link to. if (!useRouter({ warn: false })) return null; + if (variant === "page") + return ( + + New routine + + ); return ( ); return ( setCreating(true)}> + Create key + + ) : undefined + } description="Create a key so a script or another program can use OpenBot as you." title="API keys" > @@ -136,7 +144,7 @@ export function ApiKeysPage() { ) : list.data.apiKeys.length === 0 ? ( diff --git a/app/src/components/skills/skills-settings-page.tsx b/app/src/components/skills/skills-settings-page.tsx index bc054810ec..3079e0dd9d 100644 --- a/app/src/components/skills/skills-settings-page.tsx +++ b/app/src/components/skills/skills-settings-page.tsx @@ -3,7 +3,6 @@ import { IconChalkboardTeacher, IconChevronRight, IconDots, - IconPlus, } from "@/components/icons"; import { useMutation, useQuery } from "@tanstack/react-query"; import { Link, useNavigate } from "@tanstack/react-router"; @@ -11,6 +10,7 @@ import { useState } from "react"; import { TEACH_A_BOT } from "@/components/browser/browser-nav-item"; import { DetailPanel } from "@/components/layout/detail-panel"; import { + PageAddButton, PageRows, PageSection, PageShell, @@ -256,6 +256,19 @@ export function SkillsSettingsPage({ creating }: { creating: boolean }) { open={creating} > + New skill + + } className="@container" description="Skills are how your Bots do a task your way. Write one, teach a Bot by showing it, or review what OpenBot proposes." title="Skills" @@ -275,25 +288,6 @@ export function SkillsSettingsPage({ creating }: { creating: boolean }) { ) : null} - // The personal edition's skills each have a switch per Bot, so a new one is written - // on the page that leads to those switches. Elsewhere a person's own skill is - // written in the panel beside the list. - personal ? ( - - ) : ( - - ) - } - size="sm" - variant="ghost" - > - - New skill - - } afterSkills={workspace} heldAbove={heldAbove} written={written} diff --git a/app/src/components/teams/teams-page.tsx b/app/src/components/teams/teams-page.tsx index 805e32f52a..804d9e5511 100644 --- a/app/src/components/teams/teams-page.tsx +++ b/app/src/components/teams/teams-page.tsx @@ -9,7 +9,12 @@ import { useInfiniteQuery, useQuery } from "@tanstack/react-query"; import { Link } from "@tanstack/react-router"; import { useEffect, useState } from "react"; import { TeamPage } from "@/components/edition/for-a-team"; -import { PageEmpty, PageRows, PageShell } from "@/components/layout/page-shell"; +import { + PageAddButton, + PageEmpty, + PageRows, + PageShell, +} from "@/components/layout/page-shell"; import { StaggerItem } from "@/components/layout/stagger"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; @@ -49,11 +54,12 @@ function Teams({ paths }: { paths: TeamPaths }) { const teams = list.data?.pages.flatMap((page) => page.teams) ?? []; const canCreate = list.data?.pages[0]?.canCreate === true; - const newTeam = (variant: "ghost" | "outline") => ( + // The empty state's; the page's own is `PageAddButton`, so the page has one filled button. + const newTeam = () => ( - } description="API keys and tokens your apps and models use. A saved key can't be viewed again." title="Keys" > diff --git a/app/src/routes/_authed/_app/bots.index.tsx b/app/src/routes/_authed/_app/bots.index.tsx index ebf3f47dbb..48fece1ad7 100644 --- a/app/src/routes/_authed/_app/bots.index.tsx +++ b/app/src/routes/_authed/_app/bots.index.tsx @@ -1,20 +1,15 @@ -import { - IconBook, - IconBrain, - IconChevronRight, - IconPlus, -} from "@/components/icons"; +import { IconBook, IconBrain, IconChevronRight } from "@/components/icons"; import { useQuery } from "@tanstack/react-query"; import { createFileRoute, Link } from "@tanstack/react-router"; import { z } from "zod"; import { NewBotSheet } from "@/components/agents/new-bot-sheet"; import { BotRoster } from "@/components/bots/bot-roster"; import { + PageAddButton, PageRows, PageSection, PageShell, } from "@/components/layout/page-shell"; -import { Button } from "@/components/ui/button"; import { Item, ItemActions, @@ -78,16 +73,9 @@ function BotsPage() { return ( ( - - )} - size="sm" - variant="ghost" - > - + New Bot - + } description={ personal || alone diff --git a/app/src/routes/_authed/_app/memory.tsx b/app/src/routes/_authed/_app/memory.tsx index 554739ce22..d66a60e6ce 100644 --- a/app/src/routes/_authed/_app/memory.tsx +++ b/app/src/routes/_authed/_app/memory.tsx @@ -31,11 +31,12 @@ export const Route = createFileRoute("/_authed/_app/memory")({ function MemoryPage() { return ( } className="@container" description="Your Bots remember facts about you, like your role and how you like to work, and use them in every conversation. Facts you add, or ask a Bot to remember, reach all your Bots. A fact a Bot notices by itself stays with that Bot, and you can confirm or forget it here." title="Memory" > - } /> + ); } diff --git a/app/src/routes/_authed/admin/boundaries.tsx b/app/src/routes/_authed/admin/boundaries.tsx index 71baf60116..736c98fc66 100644 --- a/app/src/routes/_authed/admin/boundaries.tsx +++ b/app/src/routes/_authed/admin/boundaries.tsx @@ -7,6 +7,7 @@ import { import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query"; import { createFileRoute, Link } from "@tanstack/react-router"; import { + PageAddButton, PageEmpty, PageRows, PageSection, @@ -52,14 +53,9 @@ function BoundariesPage() { const policy = savePolicy.data ?? stored.data ?? null; const addRule = ( - + ); if (!policy) { diff --git a/app/src/routes/_authed/admin/identity-providers.tsx b/app/src/routes/_authed/admin/identity-providers.tsx index 4e3764b43e..d76d81bd9a 100644 --- a/app/src/routes/_authed/admin/identity-providers.tsx +++ b/app/src/routes/_authed/admin/identity-providers.tsx @@ -5,6 +5,7 @@ import { useId, useState } from "react"; import { SignInSection } from "@/components/admin/controls/sign-in-section"; import { TeamPage } from "@/components/edition/for-a-team"; import { + PageAddButton, PageEmpty, PageRows, PageSection, @@ -153,9 +154,9 @@ function IdentityProvidersPage() { action={ // Offered once the server has said the providers are this organization's to change. providers.data?.managedHere ? ( - + ) : undefined } description={words.description} diff --git a/app/src/skins/opendots/screens.tsx b/app/src/skins/opendots/screens.tsx index 1a07d79f40..36128fa623 100644 --- a/app/src/skins/opendots/screens.tsx +++ b/app/src/skins/opendots/screens.tsx @@ -71,7 +71,7 @@ export function MemoriesScreen() { if (!offersMemory(capabilities.data)) return ; return ( } + action={} description="What your Bots know about you." title="Memories" > diff --git a/app/tests/memory-settings.test.tsx b/app/tests/memory-settings.test.tsx index 9ccfe8c9b0..ca9d7ea670 100644 --- a/app/tests/memory-settings.test.tsx +++ b/app/tests/memory-settings.test.tsx @@ -106,7 +106,7 @@ test("remembering a fact saves it", async () => { const view = draw(); const user = userEvent.setup({ document }); // The form lives in a dialog behind the page's action, not on the page. - fireEvent.click(view.getByRole("button", { name: "Remember a fact" })); + fireEvent.click(view.getByRole("button", { name: "Add fact" })); await user.type( await view.findByRole("textbox", { name: "Something you want your Bots to know", @@ -148,12 +148,12 @@ test("Edit memory says what the dialog is for", async () => { expect(view.queryByText("You told a Bot", { exact: true })).toBeNull(); }); -test("reopening Remember a fact after a failure starts clean", async () => { +test("reopening Add fact after a failure starts clean", async () => { serving(); refuseWrite = "Memory is full."; const view = draw(); const user = userEvent.setup({ document }); - await user.click(view.getByRole("button", { name: "Remember a fact" })); + await user.click(view.getByRole("button", { name: "Add fact" })); await user.type( await view.findByRole("textbox", { name: "Something you want your Bots to know", @@ -164,7 +164,7 @@ test("reopening Remember a fact after a failure starts clean", async () => { expect((await view.findByRole("alert")).textContent).toBe("Memory is full."); await user.keyboard("{Escape}"); await waitFor(() => expect(view.queryByRole("dialog")).toBeNull()); - await user.click(view.getByRole("button", { name: "Remember a fact" })); + await user.click(view.getByRole("button", { name: "Add fact" })); const field = (await view.findByRole("textbox", { name: "Something you want your Bots to know", })) as HTMLTextAreaElement; diff --git a/app/tests/page-add-button.test.tsx b/app/tests/page-add-button.test.tsx new file mode 100644 index 0000000000..70bd879e0f --- /dev/null +++ b/app/tests/page-add-button.test.tsx @@ -0,0 +1,183 @@ +import { + afterAll, + afterEach, + beforeAll, + describe, + expect, + test, +} from "bun:test"; +import { readdirSync, readFileSync, statSync } from "node:fs"; +import { join, relative } from "node:path"; +import { GlobalRegistrator } from "@happy-dom/global-registrator"; +import { + createMemoryHistory, + createRootRoute, + createRouter, + RouterProvider, +} from "@tanstack/react-router"; +import { cleanup, render } from "@testing-library/react"; +import type { ReactNode } from "react"; +import { PageAddButton } from "@/components/layout/page-shell"; +import { settleReactWork } from "./settle-react-work"; + +/* + * ONE FILLED ADD BUTTON ON A LIST PAGE, DRAWN ONCE. A list page's main add action is + * `PageAddButton` in `PageShell`'s `action`: filled, the page-action size, a plus and a short label. + * Before it, Bots, Skills, Memory, Vault and the rest each drew that button by hand, as ghost, + * outline, large or down in a section, so no two pages matched. + * + * Two parts: what `PageAddButton` draws, and a read of every page's header action under app/src, + * so a page that draws its add button by hand again fails here. + */ + +beforeAll(() => GlobalRegistrator.register()); +afterEach(cleanup); +afterAll(async () => { + await settleReactWork(); + GlobalRegistrator.unregister(); +}); + +function draw(node: ReactNode) { + const router = createRouter({ + history: createMemoryHistory({ initialEntries: ["/"] }), + routeTree: createRootRoute({ component: () => node }), + }); + return render(); +} + +const classes = (element: HTMLElement) => element.className.split(" "); + +describe("PageAddButton", () => { + test("a link: filled, the page-action size, with a plus", async () => { + const view = draw( + New team, + ); + const link = await view.findByRole("button", { name: "New team" }); + expect(link.getAttribute("href")).toBe("/teams/new"); + expect(classes(link)).toContain("bg-primary"); + expect(classes(link)).toContain("h-10"); + expect(link.querySelector("svg")).not.toBeNull(); + }); + + test("a press, for a page that opens its own dialog", async () => { + let pressed = 0; + const view = draw( + pressed++}>Add fact, + ); + const button = await view.findByRole("button", { name: "Add fact" }); + expect(button.getAttribute("href")).toBeNull(); + expect(classes(button)).toContain("bg-primary"); + button.click(); + expect(pressed).toBe(1); + }); +}); + +const SRC = join(import.meta.dir, "../src"); + +function sources(dir: string): string[] { + return readdirSync(dir).flatMap((name) => { + const path = join(dir, name); + if (statSync(path).isDirectory()) + return name === "generated" ? [] : sources(path); + return /\.tsx$/.test(name) ? [path] : []; + }); +} + +/** The text from `start` to the bracket that closes the one at `start`. */ +function balanced(text: string, start: number): string { + const open = text[start] as string; + const close = ({ "{": "}", "(": ")" } as Record)[open]; + let depth = 0; + for (let i = start; i < text.length; i++) { + if (text[i] === open) depth++; + else if (text[i] === close && --depth === 0) + return text.slice(start, i + 1); + } + return text.slice(start); +} + +/** The opening tag that starts at `start`: up to the first `>` outside braces and quotes. */ +function openingTag(text: string, start: number): string { + let depth = 0; + let quote: string | null = null; + for (let i = start; i < text.length; i++) { + const c = text[i] as string; + if (quote) { + if (c === quote) quote = null; + } else if (c === '"' || c === "`") quote = c; + else if (c === "{") depth++; + else if (c === "}") depth--; + else if (c === ">" && depth === 0) return text.slice(start, i + 1); + } + return text.slice(start); +} + +/** + * Each header action in a file: the `action={…}` of every ` { + const pages = sources(SRC).map((path) => ({ + file: relative(SRC, path), + actions: headerActions(readFileSync(path, "utf8")), + })); + const handDrawn = pages + .filter(({ actions }) => actions.some((a) => a.includes(" file); + + test("draws its add button with PageAddButton, not by hand", () => { + // Apps keeps its add in the page's own toolbar, not in the header (#2646). + expect(handDrawn).toEqual([]); + }); + + test("the list pages each put PageAddButton, or a button made from it, in their header", () => { + const LIST_PAGES: Record = { + "routes/_authed/_app/bots.index.tsx": //, + "components/vault/vault-page.tsx": / { + const page = pages.find((one) => one.file === file); + return !page?.actions.some((action) => button.test(action)); + }) + .map(([file]) => file); + expect(missing).toEqual([]); + // And the two buttons made from it draw it on a title row. + for (const file of [ + "components/memory/memories.tsx", + "components/routines/new-routine-button.tsx", + ]) + expect(readFileSync(join(SRC, file), "utf8")).toContain(" { +test("Add fact refused 429 says the server's sentence, calmly, and isn't sent again by itself", async () => { serve(`GET ${MEMORY.memories}`, () => page(memoryContract.ListMemoriesResponse, "memories", []), ); serve(`POST ${MEMORY.memories}`, () => tooMany(3)); const view = draw(); const person = userEvent.setup({ document }); - await person.click(view.getByRole("button", { name: "Remember a fact" })); + await person.click(view.getByRole("button", { name: "Add fact" })); await person.type( await view.findByRole("textbox", { name: "Something you want your Bots to know",