naive-ui Agent Skills & AI Rules

GitHub

A Vue 3 Component Library. Fairly Complete. Theme Customizable. Uses TypeScript. Fast.

18,484 stars TypeScript TypeScript 1 file ยท ~3,274 tokens #component-library#ui-components#vue#vue-typescript#vue3-components
RAW Rules
1 Discovered Rules โ€ข ~1,232 Estimated Tokens
Quick:
Loading skill content...

AI Agent Protocol & Instructions

AGENTS.md root-instruction ~1,232 tokens
Raw
# Agent Guide for Naive UI

This file provides guidance to AI coding agents when working on the [Naive UI](https://github.com/tusen-ai/naive-ui) repository.

## Important Notes

- Vue 3 + TypeScript component library. Source is in `src/`.
- Package manager: pnpm (`11.10.0`). Node: `>=20`.
- Use English in code and comments. Keep comments meaningful and concise.
- Do not change public APIs or user-facing behavior unless requested.

## Build and Development Commands

```bash
# Start documentation site dev server
pnpm run dev

# Run all unit tests
pnpm run test

# Run tests for a specific component
pnpm run test src/button

# Update snapshots
pnpm run test:update

# Lint code and types
pnpm run lint

# Auto-fix lint issues
pnpm run lint:fix

# Format code
pnpm run format

# Full library build
pnpm run build:package

# Production docs site build
pnpm run build:site
```

## Architecture Overview

```
naive-ui/
โ”œโ”€โ”€ src/                  # Component library source
โ”‚   โ”œโ”€โ”€ _internal/        # Internal helper components
โ”‚   โ”œโ”€โ”€ _mixins/          # Shared composables: useTheme, useConfig, useFormItem, etc.
โ”‚   โ”œโ”€โ”€ _styles/          # Global theme tokens
โ”‚   โ”œโ”€โ”€ _utils/           # Utility modules
โ”‚   โ”œโ”€โ”€ <component>/      # One directory per public component
โ”‚   โ”‚   โ”œโ”€โ”€ index.ts      # Public exports
โ”‚   โ”‚   โ”œโ”€โ”€ src/          # Component implementation (.tsx)
โ”‚   โ”‚   โ”œโ”€โ”€ styles/       # Theme vars (light.ts / dark.ts / _common.ts / rtl.ts)
โ”‚   โ”‚   โ”œโ”€โ”€ demos/        # Documentation demos
โ”‚   โ”‚   โ””โ”€โ”€ tests/        # Vitest specs
โ”‚   โ”œโ”€โ”€ composables/      # Public composables
โ”‚   โ”œโ”€โ”€ locales/          # i18n locale objects
โ”‚   โ”œโ”€โ”€ themes/           # Theme definitions
โ”‚   โ”œโ”€โ”€ components.ts     # Aggregated component exports
โ”‚   โ”œโ”€โ”€ preset.ts         # Default plugin
โ”‚   โ”œโ”€โ”€ create.ts         # Plugin factory
โ”‚   โ””โ”€โ”€ vitest-setup.ts   # Test environment polyfills
โ”œโ”€โ”€ demo/                 # Documentation site source
โ”œโ”€โ”€ build/                # Custom Vite plugins and build helpers
โ”œโ”€โ”€ scripts/              # Build/release scripts
โ”œโ”€โ”€ themes/tusimple/      # Tusimple-branded theme overrides
โ”œโ”€โ”€ generic/              # Generic Vue component wrappers
โ”œโ”€โ”€ esm-test/             # Smoke test for ES build
โ”œโ”€โ”€ umd-test/             # Smoke test for UMD build
โ””โ”€โ”€ coverage/             # Vitest coverage output
```

## Component Conventions

- Props are declared as `componentProps` and exported from `index.ts`.
- Component implementation lives in `src/Component.tsx` using `defineComponent` + JSX.
- Styles live in `src/styles/index.cssr.ts` as CSS-render strings.
- Theme variables live in `styles/light.ts`, `styles/dark.ts`, and `styles/_common.ts`.
- Tests live in `tests/Component.spec.tsx`.

## Key Development Patterns

- Use shared mixins from `src/_mixins/`: `useConfig`, `useTheme`, `useThemeClass`, `useFormItem`, `useLocale`, `useRtl`.
- CSS class naming follows BEM: `.n-button`, `.n-button--primary`, `.n-button__icon`.
- Theme variable naming follows `<component><State><Variant>` order, e.g. `buttonColorErrorHover`.
- Use named imports and `h` from `vue` for JSX.

## Code Style

- Do not fix formatting manually. Use `pnpm run lint:fix` and `pnpm run format` to let the tools handle it.
- Prettier: `semi: false`, `singleQuote: true`, `printWidth: 80`, `trailingComma: none`.
- ESLint: `@antfu/eslint-config` with a few project-specific overrides.
- File naming: kebab-case directories, PascalCase component files.
- TypeScript strict mode enabled.

## Testing Approach

- Vitest with `jsdom` and `@vue/test-utils`.
- `src/vitest-setup.ts` polyfills browser APIs.
- When a change only affects a single component, run only that component's tests first: `pnpm run test src/<component>`.
- Add tests for new props or behaviors. Keep tests focused.

## Commit Message Format

Use Angular style:

```
feat(button): add ghost prop
fix(input): handle empty value correctly
docs: update contributing guide
```

## Pull Requests

- Prefer the `gh` CLI when interacting with GitHub (listing PRs, checking CI status, creating PRs, etc.).
- Always follow `.github/pull_request_template.md` when creating a PR.
- Keep PR titles and descriptions factual and concise.
- Do not add AI-tool branding or co-author trailers.
- If public APIs or user-facing behavior change, update docs and call out the impact in the PR template.

## Debugging

- Use `chrome-devtools-mcp` (Chrome DevTools Protocol) for browser debugging: inspecting elements, capturing screenshots, monitoring network requests, running performance traces, and executing scripts in the page context.

## Useful References

- `package.json` โ€” scripts, dependencies
- `vite.config.mts` โ€” dev server, aliases, test config
- `tsconfig.json` โ€” TypeScript config
- `eslint.config.mjs` โ€” lint rules
- `CONTRIBUTING.md` โ€” contribution workflow
- `design-notes/maintaining.md` โ€” release process
- `design-notes/how-to-name-a-style-var.md` โ€” theme variable naming guide