# @agimon-ai/style-system

MCP server and CLI for exploring themes, Tailwind CSS classes, and UI components from Storybook, with
standalone component rendering.

## Install

```bash
pnpm add -D @agimon-ai/style-system
```

## CLI

```bash
style-system --help
```

| Command                  | Purpose                                                                 |
| ------------------------ | ----------------------------------------------------------------------- |
| `get-css-classes`        | Extract the valid CSS classes from a theme CSS file                     |
| `get-ui-component`       | Render a component to a screenshot using the app's design-system config |
| `list-app-components`    | List app-specific components and package components                     |
| `polish-component`       | Design-system-aware component polish                                    |
| `generate-oxlint-config` | Generate an oxlint `no-restricted-classes` config from theme tokens     |
| `mcp-serve`              | Run as an MCP server over stdio                                         |

## MCP server

```json
{
  "mcpServers": {
    "style-system": {
      "command": "npx",
      "args": ["-y", "@agimon-ai/style-system", "mcp-serve"]
    }
  }
}
```

## Configuration

Configuration lives in files named `style-system.config.yaml`, at two levels:

```
<workspace-root>/style-system.config.yaml   # defines defaults and presets
<project>/style-system.config.yaml          # selects a preset, applies overrides
```

The workspace root is found by walking up from the current working directory until a `.git`
directory is found, falling back to the working directory itself. It is your repository root, not
the installed package location.

### Resolution order

```
built-in defaults  ->  root `defaults`  ->  preset chain (parents before child)  ->  project config
```

Last wins, and **fields replace wholesale**. Lists and objects are never merged element-wise, so a
project that sets `cssFiles` replaces the inherited list entirely. Use `cssFiles: []` to clear one.

Every field is optional in any individual file. Required-ness is enforced against the merged result,
so a project config can be valid while inheriting nearly everything.

Both schemas are strict: an unknown or misspelled key is a hard error rather than a silent no-op. The
project schema additionally rejects `root`, `defaults` and `presets`, so the two file types can never
be confused for one another.

### Workspace root file

```yaml
# <workspace-root>/style-system.config.yaml
root: true # required literal; marks this as the workspace file

# Story tags that mark a component as shared/design-system.
sharedComponentTags:
  - style-system

# Optional service overrides. Paths are workspace-root relative.
# getCssClasses:
#   customService: packages/.../CustomCSSClassesService.ts
# bundler:
#   customService: packages/.../CustomBundlerService.ts

# Applied to every project, beneath its preset chain.
defaults:
  type: tailwind
  colorScheme: automatic

presets:
  web-app:
    viewport: { width: 1280, height: 800 }
    cssFiles: ['src/assets/main.css']
    componentLibrary: '@acme/web-ui'
  mcp-app:
    extends: web-app # presets may extend other presets
    rootComponent: 'src/components/Root/index.tsx'
  native-app:
    bundler: vite-react-native
    unistylesConfig: unistyles.ts
    viewport: { width: 393, height: 852 }
```

### Project file

```yaml
# <project>/style-system.config.yaml
extends: web-app # a preset name, or a list: [base, overrides]
viewport: { width: 1440, height: 900 }
```

### Fields

| Field                 | Type                             | Purpose                                            |
| --------------------- | -------------------------------- | -------------------------------------------------- |
| `type`                | `tailwind` \| `shadcn`           | Design system flavour                              |
| `bundler`             | string                           | Bundler strategy, e.g. `vite-react-native`         |
| `brand`               | string                           | Brand identifier                                   |
| `unistylesConfig`     | string                           | Path to the Unistyles config, for native rendering |
| `colorScheme`         | `automatic` \| `light` \| `dark` | Rendering colour scheme                            |
| `viewport`            | `{ width, height }`              | Screenshot viewport, positive integers             |
| `tailwindConfig`      | string                           | Path to a Tailwind config                          |
| `themeProvider`       | string                           | Module providing the theme provider component      |
| `rootComponent`       | string                           | Root component wrapped around rendered stories     |
| `cssFiles`            | string[]                         | Stylesheets loaded before rendering                |
| `componentLibrary`    | string                           | Package holding shared components                  |
| `themePath`           | string                           | Path to the theme CSS                              |
| `sharedComponentTags` | string[]                         | Story tags marking a component as shared           |

`bundler` is shape-dependent on level: in `defaults`, a preset, or a project file it is a **string**
naming the strategy; at the workspace root, alongside `getCssClasses`, it is a **service override
object** taking `customService`.

## Native rendering

Rendering React Native stories additionally requires the application being rendered to provide
`react-native`, `react-native-unistyles`, `react-native-reanimated`, `@babel/core`,
`expo-modules-core` and `@expo/vector-icons`. These are resolved from the target application's
directory, not from this package, so a React Native app already satisfies them.

## Agent skill

The published package ships a `skills/style-system` skill describing when and how an agent should use
these commands.

## License

MIT
