# AGENTS.md — Linyi UI

This repository and documentation site (`https://linyiui.cn`) exposes a standard shadcn-compatible React 19 + Tailwind CSS v4 + Base UI + Motion component registry designed for autonomous coding agents, including **Claude Code**, **OpenAI Codex**, **Google Gemini CLI / Antigravity**, **Cursor**, and **VS Code** (via native MCP or static indexes).

## Quick Discovery

- Full component index (Markdown): `https://linyiui.cn/llms.txt`
- Full API contracts (exports, prop types, defaults, type-checked minimal examples): `https://linyiui.cn/llms-full.txt` and `https://linyiui.cn/r/registry-api.json`
- Native MCP server: `packages/mcp` in `https://github.com/HHuiLin/linyi-ui` (tools: `search_components`, `get_component`, `get_design_rules`, `list_presets`)
- Machine-readable Registry index: `https://linyiui.cn/r/registry.json`
- Component source JSON: `https://linyiui.cn/r/<slug>.json`
- Theme CSS variables & optical primitives: `https://linyiui.cn/r/linyi-theme.json`
- Motion physics presets: `https://linyiui.cn/r/motion.json`
- Zero-asset Web Audio sound engine: `https://linyiui.cn/r/sound.json`

## MCP Server (Recommended)

Clone the repository once (`git clone https://github.com/HHuiLin/linyi-ui.git && cd linyi-ui && npm install`), then register the stdio server. Replace `/path/to/linyi-ui` with the clone path. Inside the repository it reads `public/r/` offline; elsewhere it falls back to `https://linyiui.cn/r/`.

```bash
# Claude Code
claude mcp add linyi-ui -- node /path/to/linyi-ui/packages/mcp/src/index.mjs
```

```toml
# OpenAI Codex CLI (~/.codex/config.toml)
[mcp_servers.linyi-ui]
command = "node"
args = ["/path/to/linyi-ui/packages/mcp/src/index.mjs"]
```

```json
// Gemini CLI (~/.gemini/settings.json) / Cursor (.cursor/mcp.json)
{ "mcpServers": { "linyi-ui": { "command": "node", "args": ["/path/to/linyi-ui/packages/mcp/src/index.mjs"] } } }
```

Workflow: `search_components` → `get_component` (source + prop contract + verified example + install command) → `get_design_rules` before writing UI → `list_presets` when switching theme or density.

## Installing Components

Configure `@linyi-ui` in `components.json`:

```json
{
  "registries": {
    "@linyi-ui": "https://linyiui.cn/r/{name}.json"
  }
}
```

Then install any component directly into the user's source tree:

```bash
# Using configured registry namespace
bunx --bun shadcn@latest add @linyi-ui/download-button
npx shadcn@latest add @linyi-ui/bookshelf

# Or directly via URL (no components.json edits needed)
npx shadcn@latest add https://linyiui.cn/r/download-button.json
npx shadcn@latest add https://linyiui.cn/r/linyi-theme.json
```

## Agent-Specific Integration Notes

- **Claude Code (`CLAUDE.md`)**: Read `/llms.txt` first to pick the exact component slug, then install via `npx shadcn@latest add https://linyiui.cn/r/<slug>.json`.
- **OpenAI Codex (`AGENTS.md`)**: Follow the registry dependencies in `/r/<slug>.json` (`cn`, `motion`, `sound`). Never invent placeholder wrappers when an official registry item exists.
- **Google Gemini CLI / Antigravity (`GEMINI.md`)**: Use `https://linyiui.cn/r/registry.json` to inspect dependencies and target file paths before writing code.
- **xAI Grok**: Import installed components from `@/components/linyi/<slug>` and preserve the Linyi UI theme variables.

## Design & Engineering Baseline

- **Source of Truth (In-Repo Contributions)**: Read `DESIGN_PRINCIPLES.md` (copy & writing, visual, motion, performance, accessibility, component contracts, testing, backfill protocol, pitfalls) and `ROADMAP.md` (staged execution plan) before starting any repository iteration. A project-agnostic copy lives in `docs/通用规范.md`.
- **Copy Check**: All UI copy, docs and comments must pass `npm run writing:check` (word list in `scripts/writing-rules.mjs`, run automatically before `npm run build`).
- **Canvas & Presets**: Four semantic theme presets — Eastern Xuan Paper light (`#EFECE4` / `#F9F7F1`), Inkstone Lacquer dark (`#12110F` / `#1A1815`), and Neutral light/dark (`data-preset="xuan" | "neutral"`) — plus three information density modes (`data-density="compact" | "default" | "comfortable"`), 1px hairline borders, and 20px / 12px concentric radii.
- **Button Material & Tactility**: Default buttons (`Button` / `.ui-btn`) use flat 1px hairline styling with restrained press feedback (`scale(0.975)`). Thin optical Liquid Glass (`LiquidGlassButton` / `.lg-btn`) and 1px border beam (`.btn-beam`) are reserved strictly for 1–2 primary CTA buttons per page; curved refractive lenses use WebGL 1 Snell refraction shaders.
- **Single Accent**: Cinnabar Vermilion (`#C23B26`, dark `#DA523B`) with Pine-Jade (`#2C6B5E`) for positive status.
- **Interactive Primitives**: Built on headless `@base-ui/react` primitives (MIT) + `cva` + `cn()`, with zero global site coupling.
- **Motion**: Use low-mass calibrated springs (`mass: 0.3–0.6`) and exponential easing `[0.16, 1, 0.3, 1]` from `@/lib/motion`. Prefer `useMotionValue` + `useSpring` for continuous gestures to avoid React re-renders. Animate GPU properties (`transform`, `opacity`, `clipPath`) instead of `width`/`height` layout thrashing.
- **Performance Isolation**: Never use full-viewport `fixed` `mix-blend-mode` overlays. Always wrap dense live-preview grids with `useInView({ once: true, margin: "200px 0px" })` and `contain: paint`.
- **Restrained Chrome & Copy**: Keep component cards clean without redundant `ArrowUpRight` icons on cards or Pro buttons; reveal card title pills gently on hover/focus. Use natural, plain Chinese copy without promotional filler.
- **Sound**: Use `@/lib/sound` (`playSound`) for tactile Web Audio API feedback without external audio assets, respecting the global mute toggle and `prefers-reduced-motion: reduce`.
