---
name: aisquare-ui
description: Use for ANY user-interface work in an AISquare repo — building or changing a screen, page, form, modal, card, button, table, chart, chat surface, empty/loading/error state, navigation, or theming; picking a color, radius, spacing value, or animation; and reviewing UI code. @aisquare/ui is the single source of truth for UI: this skill covers finding what the library already has, adding to the library what it lacks, the token and Onyx material rules, accessibility and motion requirements, and consumer setup. Triggers on "component", "UI", "design system", "styling", "Tailwind class", "token", "theme", "unstyled", "shadcn", "@aisquare/ui".
---

# @aisquare/ui — the single source of truth for UI

Every visual element comes from `@aisquare/ui`. Not a hand-rolled component, not a second
library, not a local copy. If the library lacks something, **it gets added to the library
first**, then imported.

This is not a style preference. A parallel implementation is a fork that drifts: it misses
the next token change, a11y fix, and motion update. Two buttons means two bugs.

## The loop

**1. Find it before you build it.**

```
search_components  { query: "what the UI needs to DO" }
check_exists       { needs: ["…", "…"] }        # planning a whole screen
```

Search by **intent**, not by the widget word you had in mind. The library names things for the
pattern: `ArtifactTile` is a card, `SourceIngestion` is an uploader, `StatusExpression` is a
badge family. A search for "card" misses all three.

Without the MCP server: `rg -i "<concept>" node_modules/@aisquare/ui/dist/index.d.ts`, or read
`src/{primitives,components,ui}/` in the library repo, or browse
[ui.aisquare.studio](https://ui.aisquare.studio).

**2. Read it before you use it.**

```
get_component { name: "ArtifactTile" }
```

Gives the import line, props, cva variants, and the JSDoc that says when to reach for it over
its neighbours. A search result is a candidate, not a confirmation — the ranker is a keyword
matcher and cannot tell "covers this" from "looks similar".

**3. If it almost fits, extend it upstream.**

Add a prop or a cva variant to the library component. Never fork it, never `patch-package` it,
never override it with app CSS or `!important`. One PR fixes it for every consumer.

**4. If it genuinely does not exist, add it to the library.**

```
plan_new_component  { name, description }   # checks overlap first
scaffold_component  { name, description, layer, dryRun: true }
```

The scaffold writes the component, its story, the barrel export, the barrel-integrity test
entry, and the playground demo — already conforming to the house rules. Then fill in the JSDoc
and the real class strings. Full procedure: **[ADDING.md](ADDING.md)**.

Building it in the app "for now" is the one thing not on the table. There is no "for now" — a
local component is permanent, and it is invisible to every future library fix.

**5. Never guess a value.**

```
get_tokens { group: "semantic" | "spacing" | "radius" | "motion" | "material" | ... }
```

No hex, no `rgb()`, no `bg-blue-500`, no `rounded-[12px]`. Every value is a token utility.

**6. Review before you call it done.**

```
review_code { code, context: "app" | "library" }
```

Fix every `must`. If UI renders unstyled or colorless, run `doctor` — that symptom is nearly
always the Tailwind preset, the content glob, or missing `--success`/`--warning`.

## Import rules

```tsx
import { Button, Dialog, cn, nx, elev } from "@aisquare/ui";        // always this
import { Button as StockButton } from "@aisquare/ui/stock";          // only for upstream parity
```

Never deep-import (`@aisquare/ui/dist/...`), and never import Radix, `clsx`, `cva`, or
`tailwind-merge` directly in app code — the library already wraps them, and `cn` is what makes a
caller's `className` actually win.

## The rules that bite most often

- **Token utilities only.** No hex, no palette class (`bg-blue-500`), no arbitrary bracket value
  (`rounded-[12px]`). A bracket class written in the library renders **unstyled** in any consumer
  whose Tailwind content glob misses the file.
- **`cn` for every conditional className**, merged **last** so the caller wins.
- **The Onyx notch is for clickable rectangles only** — buttons and interactive cards. Inputs,
  badges, chips, tabs, and floating surfaces stay round. On a notched (`nx-*`) surface, elevation
  is `elev-*` (a drop-shadow filter) and the outline is `nx-rim` — `clip-path` slices an outer
  `box-shadow` away entirely and cuts a real `border` open at the chamfer.
- **Clickable means a `<button>` or `<a>`**: focusable, keyboard-operable, with an accessible
  name. Never `onClick` on a `div`. Icon-only controls always carry `aria-label`.
- **All motion is gated by `useReducedMotion()`** and uses the shared presets
  (`springs`/`easings`/`durations`/`transitions`), not an ad-hoc cubic-bezier.
- **`src/ui/` is byte-for-byte shadcn.** Never hand-edit it — the next `pnpm import:shadcn`
  reverts you. Brand styling belongs in a `src/primitives/` wrapper.
- **No browser globals at module scope.** They throw on import under SSR and in the node test
  project, taking the whole barrel down.

Full text, with the rationale and source for each: **[RULES.md](RULES.md)** — or
`get_rules { topic, verbose: true }`.

## Consuming the library in an app

Four things, and three of the four failure modes look identical (everything renders unstyled):
the Tailwind preset, the content glob covering `node_modules/@aisquare/ui`, the token CSS import,
and `--success`/`--warning`. See **[CONSUMING.md](CONSUMING.md)**, or run `doctor`.

## Shipping a library change

```bash
pnpm typecheck && pnpm lint && pnpm test:ci && pnpm build
pnpm test:storybook   # CI does NOT gate this — run it locally
```

A new component is a **minor** bump. Open the PR as a draft.
