# AGENTS.md — building an app with `@aisquare/ui`

Instructions for AI coding agents (Claude Code, Codex, Cursor, …) tasked with building or
modifying an app that depends on `@aisquare/ui`. Ships inside the published npm package
(`node_modules/@aisquare/ui/AGENTS.md`) — point your agent here directly, or copy this file into
your own project's `AGENTS.md` / `CLAUDE.md`.

This is a **consumption** guide. For contributing to the library itself (adding a primitive,
changing a token), read [DESIGN.md](DESIGN.md) instead.

- **Repository (source of truth):** https://github.com/AISquare-Studio/aisquare-ui
- **Component registry:** [`registry/components.json`](registry/components.json) — every
  component, its layer, files, and description in one machine-readable index.
- **Live component catalog:** run `pnpm storybook` in this repo (Foundations, Stock,
  Primitives, Components sections); `@storybook/addon-mcp` exposes it over MCP while the dev
  server is running, so an MCP-capable agent can query it directly instead of guessing an API.

## What this is

One package, three layers, all themed off one token contract: stock shadcn/ui v4 primitives,
brand-flavored primitives, and composed AISquare patterns. Every visual value — color, spacing,
radius, shadow, motion — comes from a CSS variable, never a hardcoded literal.

## Before writing any UI code — confirm setup

1. `@aisquare/ui/tailwind.preset` is in the app's `tailwind.config.ts` `presets`, and
   `node_modules/@aisquare/ui/dist/**/*.{js,mjs}` is in `content`.
2. `@aisquare/ui/tokens/tokens.template.css` and `@aisquare/ui/tokens/fonts.css` are imported at
   the app root.
3. If using `Sidebar` / `Chart`, `@aisquare/ui/tokens/shadcn-extras.css` is imported too, and
   `--success` / `--warning` are defined in `:root`.

No React/Tailwind app at all? Use
[`docs/aisquare-foundations.css`](docs/aisquare-foundations.css) — a standalone, dependency-free
stylesheet with the same tokens.

## Hard rules

1. **Check the registry before building anything custom.** Read
   [`registry/components.json`](registry/components.json) — 239 components across three layers.
   A large fraction of "I need a UI for X" is already solved in the composed layer (chat UI,
   status chips, artifact tiles, empty/error states, the `Aiko*` surface system). Only hand-roll
   a one-off when nothing close exists, and then compose it from existing primitives + tokens.
2. **Pick the right layer, don't default to the fanciest one.**

   | Layer | Import from | Use when |
   |---|---|---|
   | Stock shadcn | `@aisquare/ui/stock` | Unstyled-by-brand primitive, or bundle weight matters. |
   | Brand primitives | `@aisquare/ui` | Default choice — buttons, inputs, cards, badges. |
   | Composed components | `@aisquare/ui` | A higher-level AISquare pattern already exists. |

   ```tsx
   import { Button } from "@aisquare/ui";              // brand-flavored (default)
   import { Button as StockButton } from "@aisquare/ui/stock"; // plain shadcn
   ```
3. **Tokens only — never hardcode.** No `#hex`, no `bg-[#1f84ff]`, no `bg-blue-500`, no
   `rounded-[12px]`. Every value has a token; use its utility class. Two tiers: **semantic**
   (`--background`, `--primary`, `--border`, mode-aware, flip under `.dark` — reach for these
   first) and **foundation primitives** (`navy-*`, `accent-*`, `--space-*`, `--radius-*`,
   absolute, don't flip — drop to these only when no semantic role fits). Look up what exists in
   Storybook's **Foundations** section or [`docs/FOUNDATIONS.md`](docs/FOUNDATIONS.md).
4. **A component's `.meta.json` is the fast reference.** Next to a component's source
   (`<name>.meta.json`, camelCase) when it exists — props, the tokens it reads, accessibility
   contract, dependencies. Not every component has one yet (`registry/components.json`'s
   `hasMeta` flag says which do); where it's missing, read the component's own JSDoc header and
   its `.stories.tsx`.
5. **Match the house style while composing:** `cn(...)` for className composition (never inline
   `clsx`); `cva` for variants; keep every `data-slot`/`aria-*`/`role`/`focus-visible:` class
   shadcn ships; motion gated by `useReducedMotion()`; no em-dashes in default rendered strings;
   SSR-safe (no `window`/`document` at module top).
6. **If something genuinely doesn't exist,** build it with the same tokens and conventions and
   say so in your summary — don't reach for another UI library, and don't invent a one-off color
   or shadow to make a screen look right locally (that's exactly the drift the token contract
   exists to prevent).

## Example

```tsx
import { Button, Card, CardBody, CardTitle } from "@aisquare/ui";

export function Example() {
  return (
    <Card interactive onClick={() => {}}>
      <CardBody>
        <CardTitle>Launch retro notes</CardTitle>
      </CardBody>
      <Button variant="default">Open</Button>
    </Card>
  );
}
```

## Staying current

`CHANGELOG.md` logs what shipped each version — check it before assuming a component does or
doesn't exist, or that a prop still means what an older memory of this library suggests.

## Deeper reference

- [DESIGN.md](DESIGN.md) — full design rules, the three-layer contract, how to add a new
  primitive.
- [docs/FOUNDATIONS.md](docs/FOUNDATIONS.md) — the primitive token tier in depth.
- [docs/ADOPTION.md](docs/ADOPTION.md) — component-by-component adoption guide.
- [README.md](README.md) — install and wire-up steps.
