Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ These instructions apply across the repository. Read the closest `AGENTS.md` for
| Local startup, package use, and database administration | [Launcher](crates/bin/tokencraft), [admin CLI](crates/bin/admin-cli), and [local setup](docs/setup.md) |
| PostgreSQL queries, migrations, and runtime grants | [Query crate](crates/db-queries/AGENTS.md), [migrations](crates/db/migrations), and [grants](deploy/postgres) |
| Provider integrations and tool runners | [Provider plugins](plugins/providers/README.md), [connector protocol](docs/provider-connectors.md#queued-media-protocol-version-1), and [media runner](plugins/tools/media/README.md) |
| Browser console and client libraries | [Frontend](frontend/README.md), [Rust SDK](sdk/rust/README.md), and [TypeScript SDK](sdk/typescript/README.md) |
| Browser console and client libraries | [Frontend](frontend/README.md), its [design system](frontend/design-system.md), [Rust SDK](sdk/rust/README.md), and [TypeScript SDK](sdk/typescript/README.md) |
| Deployment, packaging, and operator guidance | [Deployment guide](docs/deployment.md), [native packager](scripts/native_package.py), and [CI workflows](.github/workflows) |

## Preserve behavior across boundaries
Expand All @@ -28,6 +28,16 @@ These instructions apply across the repository. Read the closest `AGENTS.md` for
- Use a disposable local database, synthetic inputs, and fixture credentials for runtime checks. Keep real credentials, customer content, private traces, local state, and build output out of commits. Keep vendor keys in the provider service when the gateway only needs a connector credential.
- Keep fixture and prototype behavior clearly identified in the UI. Check loading, empty, error, and permission states for user-facing changes. Verify that assets referenced by a changed surface ship in the intended build.

## Build the UI from the design system

Follow the [design system](frontend/design-system.md) for any change under `frontend/`.

- Build interactive controls from the Base UI kit in `frontend/src/components/ui.tsx`: `Button`, `ToggleChips`, `Input`, `Textarea`, `Checkbox`, `Select`, `Slider`, `Menu`, `Popover`, and `Modal`. A link that looks like a button takes its classes from `buttonClass`. If the kit lacks a control, add it to the kit.
- Style with Tailwind classes that use the theme's tokens in `frontend/src/index.css`: colours (`bg-surface`, `text-muted`, `border-border`), the page rhythm (`pt-page`, `gap-list`, `p-card`), control sizes, `shadow-pop`, and `hud`. Combine classes with `cn()` from `frontend/src/lib/cn.ts`.
- Keep corners square and motion quiet: `transition-colors` for hover and press, and `motion-safe:` for anything that loops or enters.
- Give every control its hover, keyboard focus, pressed, disabled, and invalid states. Icon-only controls need an `aria-label`.
- Make every view work by keyboard and touch, in light and dark themes, from 320px wide. Shape a loading placeholder like the content that replaces it.

## Keep contracts and releases reproducible

- Preserve the bytes of existing SQL migrations, including comments. The migration ledger and cutover checks compare checksums. Add a migration for schema changes and check runtime grants, lock and backfill impact, and overlap with running API and worker builds. Use the [rollout procedure](docs/deployment.md#roll-out-compatible-database-changes) when a change affects deployment.
Expand Down
4 changes: 4 additions & 0 deletions frontend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ Open `http://localhost:3000`. The default gateway is `http://localhost:4000`. Se

Set `VITE_TOKENCRAFT_PACKAGED=true` for a native launcher build, `VITE_TOKENCRAFT_FIXTURES=true` to use fixture data, or `VITE_TOKENCRAFT_LEGAL_DRAFTS=true` to review the draft policies.

## Design system

Pages are built from the tokens and component kit described in the [design system](design-system.md).

## Shared example prompts

Use the exact prompt and settings from the [image suite](content/benchmark-suites/image-1.json) or the [video, mesh, and world suites](src/lib/model-examples.ts). Confirm the request, model, provider, and output before publishing approved media. Create a new suite revision when a prompt or comparison setting changes.
Expand Down
168 changes: 168 additions & 0 deletions frontend/design-system.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
# TokenCraft design system

These are the rules the public site and the console follow, so every page looks and behaves the same.

- **Styling:** [Tailwind CSS](https://tailwindcss.com) classes on the elements.
- **Theme:** the tokens in [`src/index.css`](src/index.css).
- **Interactive controls:** the component kit in [`src/components/ui.tsx`](src/components/ui.tsx), built on [Base UI](https://base-ui.com).

## How styling works

- **Classes in the markup.** An element's look is the Tailwind classes in its `className`.
- **Tokens first.** Use a token wherever one fits. Tailwind's own palette is still available, and is used only for status colours (see below). Never write a raw hex or HSL colour where a token exists.
- **Combining classes.** Use `cn()` from [`src/lib/cn.ts`](src/lib/cn.ts), never string concatenation. It drops empty values and resolves conflicts, so a later class overrides an earlier one of the same kind (`cn("p-3", "p-card")` gives `p-card`). Kit components merge their `className` the same way. When you add a spacing, shadow or easing token, also add its name to `cn.ts`, or the merge will not see it.
- **Surface stylesheets.** A surface may keep one stylesheet beside it for layout that utilities cannot express, such as the landing page's hero (`surfaces/marketing/landing.css`). Its colours and spacing still come from the tokens, written as `hsl(var(--brand))` or `var(--gutter)`.
- **Repetition.** When the same class list appears three or more times, give it one home: a component when it has structure, otherwise a `const`. Shared ones go in `ui.tsx`.
- **Arbitrary values.** Use them only where no token fits, such as a `clamp()` headline size or a one-off breakpoint.

## Tokens

### Colour

Light is the default; the `dark` class switches to dark. Each surface (public site, console, playground) wraps its tree in `ThemeProvider` from [`src/lib/theme.tsx`](src/lib/theme.tsx) and keeps its own choice. Both themes define the same names, so classes never change per theme.

| Class suffix | Use |
| --- | --- |
| `bg` | page background |
| `surface` | cards and panels |
| `surface2` | wells, tab strips, secondary buttons |
| `raised` | popups and menus |
| `sunken` | fields |
| `border`, `line-strong` | dividers; control borders |
| `fg`, `muted`, `faint` | text, from primary to least important |
| `hover`, `active` | row hover; pressed fills and skeletons |
| `brand`, `brand2` | teal text, lines, the logo and the focus ring |
| `brand-fill`, `brand-hover`, `brand-fg` | primary buttons and selected chips; text on them |
| `accent` | the amber highlight |
| `scrim` | behind dialogs |

Use them as `bg-*`, `text-*`, `border-*`, `outline-*`, and so on. A tint is an opacity step, such as `bg-brand/12`.

**Status** has no tokens. Use the pairs the `Badge` tones use: emerald for success, amber for warning, rose for danger, each with a `dark:` partner (`text-emerald-800 dark:text-emerald-300`).

Contrast:
- Text keeps 4.5:1 against its background and controls 3:1, in both themes.
- Colour is never the only signal: pair it with text or an icon.

### Type

- `font-sans` is Figtree, for text and headings. Body text is 450 weight, 15px, line height 1.5.
- `font-mono` is JetBrains Mono, for code, model ids, prices and the label voice.
- `hud` is the micro-label voice: mono, 11px, uppercase, letter-spaced. Use it for eyebrows, tabs and small labels. Buttons, chips and badges already carry their own version of it.
- Headings wrap balanced and `h1`/`h2` are tightly tracked (base rules).
- Sizes are Tailwind's (`text-xs` to `text-3xl`). Page and hero headlines use `clamp()` sizes as arbitrary values.
- Numbers that line up in columns use `tabular-nums`.

### Spacing

Spacing uses Tailwind's 4px scale: `p-3` is 12px, `gap-1.5` is 6px. The page rhythm has named steps, which grow with the viewport:

| Class suffix | Between |
| --- | --- |
| `gutter` | the page edge and content: 16px, 24px from 640px, 32px from 1024px |
| `page` | the header and a page's title (`pt-page`) |
| `title` | a page's title block and its content (`mb-title`) |
| `section` | sections (`gap-section`, `mt-section`) |
| `heading` | a section heading and its content (`mb-heading`) |
| `list` | cards, tiles and rows in a grid or list (`gap-list`) |
| `card` | a card's edge and its content (`p-card`) |
| `panel` | a hero panel's edge and its content (`p-panel`) |

Page wrappers use `Container` (the `container-page` utility): at most 1280px wide, inside the gutter.

### Shape and motion

**Shape**
- Corners are square. The theme has no radius scale except `rounded-full`, for avatars and dots.
- `shadow-pop` is for menus, popovers and dialogs. `shadow-glow` is a brand outline for a highlighted card. There are no other shadows.

**Motion** is quiet and consistent:

| Use | Class | Timing |
| --- | --- | --- |
| hover and press | `transition-colors` (or `transition-[…]` for other properties) | 120ms, standard ease (`ease-standard`), the default |
| small state changes | `duration-fast` | 100ms |
| popups opening and closing | `duration-base` | 150ms |
| dialogs | `duration-slow` | 180ms |

- Popups fade and scale from 98%; the kit does this.
- Looping or entrance animations (`animate-fade-up`, `animate-shimmer`) go behind `motion-safe:`.
- Under reduced motion every transition and animation collapses to nothing (base rules).

## Interaction states

Every interactive element has all of these:

| State | Treatment |
| --- | --- |
| Hover | Every control that isn't the primary action inverts (`hover:bg-fg hover:text-bg`) or moves to `hover`; links go to `fg` or underline. The primary button moves to `brand-hover`. |
| Focus | Keyboard focus shows a 2px brand outline, offset 2px (base rule). Fields show a brand border and a soft ring instead (`focus-visible:field-focus`, built into the kit). |
| Pressed or selected | brand fill or `active`, through `aria-pressed:`, `aria-[current=page]:`, `data-checked:`, `data-highlighted:`, `data-popup-open:` |
| Disabled | `disabled:opacity-50 disabled:cursor-not-allowed` (also `data-disabled:` for Base UI parts) |
| Invalid | `aria-invalid:border-rose-500`, with an error message tied to the field |

## Controls

### Sizes

- **Default:** controls are 32px tall (`min-h-control`). Small is 28px (`control-sm`), large is 44px (`control-lg`).
- **Touch screens:** `touch:` means `pointer: coarse`. Controls grow to 40px (`touch:min-h-control-touch`), and fields use 16px text so iOS doesn't zoom. The kit already does both.

### The component kit

Interactive controls come from `src/components/ui.tsx`, so focus, keyboard and ARIA behaviour are the same everywhere. Older screens still contain native `<button>`, `<input>` and `<details>` elements; use the kit for anything you add or rework.

| Need | Use |
| --- | --- |
| Button | `Button` with `variant` and optional `size` |
| Link that looks like a button | a router `Link` with `buttonClass({ variant, size })` |
| Icon button | `iconButton` classes, with an `aria-label`; `CloseButton` for a dialog's ✕ |
| One of several choices | `ToggleChips` with `look="chips"` or `"segmented"`; `chipClass` for a link in a row of chips |
| Text field, multi-line field | `Input`, `Textarea`, each under a `Label`; `inputClass` for a field the kit does not wrap |
| Checkbox | `Checkbox` |
| Dropdown choice | `Select` with `options`; `selectTrigger` for a trigger that opens a custom picker |
| Range | `Slider` |
| Action menu | `Menu`, `MenuItem`, `MenuSeparator`; `render={<Link to=… />}` makes an item a page link |
| Anchored panel | `Popover`; `popup` classes for a custom floating panel |
| Modal | `Modal`, `DialogTitle`, `DialogClose` |
| Card, status label | `Card`, `Badge` with a `tone` |
| Loading block | `skeleton` classes |
| Logo | `Logo`; `LogoMark` for the mark alone |
| Day and night switch | `ThemeToggle` |

Styling kit components:
- Pass utilities through `className`; `cn` merges them after the kit's own classes.
- Style state through Base UI's attributes: `data-checked:`, `data-popup-open:`, `data-highlighted:`, `data-disabled:`, `data-starting-style:`, `data-ending-style:`.

If the kit lacks a control, add it to `ui.tsx` rather than making a one-off copy in a surface.

### Buttons

Pick the variant by what the button does:

| Variant | Use |
| --- | --- |
| `primary` | the one main action in a view: Create, Save, Send |
| `secondary` | other actions: a filled neutral block that inverts under the pointer |
| `outline` | the same weight as secondary on a surface that is already filled |
| `ghost` | low-emphasis actions: Cancel, Close, Load more. Text only until the pointer is on it. |
| `danger` | destructive actions: Delete, Revoke, Remove. Rose text that fills under the pointer. |

- `size="sm"` is 28px, for dense rows and cards. `size="lg"` is 44px, for a hero's main action.
- `Button` submits a surrounding form unless you pass `type="button"`, like a native button.

## Layout

- **Public header:** one 48px row, sticky at the top. The page links sit in the bar from 768px (`md`); below that they move into the menu at its end. `--site-header` holds the bar's height for anything that sticks or scrolls to an anchor under it.
- **Sections:** separated by `section`; grids use `gap-list`.
- **Loading:** content that waits for data shows a `skeleton` block shaped like what replaces it, so nothing moves when the data arrives. Check the loading, empty, error and permission states of every view you change.
- **Breakpoints:** use Tailwind's: `sm` 640, `md` 768, `lg` 1024, `xl` 1280. Write mobile-first (`md:grid-cols-2`). Use an arbitrary breakpoint only when content needs it.
- **Landing hero:** the prism is a live 3D scene, loaded as its own chunk. It is still on phones and under reduced motion, and falls back to an image without WebGL 2.

## Accessibility

- Everything works by keyboard, and focus is always visible.
- Each control has a visible label or an `aria-label`. Icon-only controls always need an `aria-label`.
- Icons beside text are `aria-hidden`.
- Movement beyond a short fade goes behind `motion-safe:`.
- Everything works on touch screens, in light and dark themes, from 320px wide up.
Loading