Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

docs: add Working with AI guide (#2056)

Cindy Zhang2fe4f5256a6b
diff --git a/packages/cli/docs/getting-started.doc.mjs b/packages/cli/docs/getting-started.doc.mjs
index 313e21102a..02564e55c4 100644
--- a/packages/cli/docs/getting-started.doc.mjs
+++ b/packages/cli/docs/getting-started.doc.mjs
@@ -5,49 +5,72 @@ export const docs = {
title: 'Getting Started',
category: 'guide',
description:
- 'Go from zero to a working XDS app in five steps.',
+ 'Add XDS to your project and start building.',
sections: [
{
- title: 'Install the CLI',
- category: 'guide',
+ title: 'Quick Start with AI',
+ content: [
+ {
+ type: 'prose',
+ text: 'Paste this into your AI coding tool and let it handle the setup:',
+ },
+ {
+ type: 'code',
+ lang: 'text',
+ label: 'Paste this into your AI',
+ code: 'Install @xds/core, @xds/theme-default, and @xds/cli in this project. Run `npx xds init` to set up agent docs. Read the generated files to learn the conventions.',
+ },
+ ],
+ },
+ {
+ title: 'Install',
content: [
{
type: 'prose',
- text: 'Use the XDS CLI to scaffold a new app. It wires up Next.js, the design system, and a working theme out of the box.',
+ text: 'Add the core package, a theme, and the CLI to your existing project.',
},
{
type: 'code',
lang: 'bash',
label: 'Terminal',
- code: `npx @xds/cli init my-app
-cd my-app`,
+ code: `npm install @xds/core @xds/theme-default @xds/cli`,
+ },
+ {
+ type: 'prose',
+ text: 'Then run the init wizard to set up AI agent docs, pick a starter template, and learn about theming.',
+ },
+ {
+ type: 'code',
+ lang: 'bash',
+ label: 'Terminal',
+ code: `npx xds init`,
},
],
},
{
- title: 'Pick a theme',
- category: 'guide',
+ title: 'Add the theme CSS',
content: [
{
type: 'prose',
- text: 'Choose between the default theme and the neutral theme. Themes live as separate packages so you can swap them without touching component code.',
+ text: 'Import the reset stylesheet and a theme in your global CSS file. Themes provide all design tokens (colors, spacing, radius, typography) as CSS custom properties.',
},
{
type: 'code',
- lang: 'tsx',
- label: 'app/layout.tsx',
- code: `import '@xds/theme-default/styles.css';
-
-export default function RootLayout({children}) {
- return <html><body>{children}</body></html>;
-}`,
+ lang: 'css',
+ label: 'globals.css',
+ code: `@import '@xds/core/reset.css';
+@import '@xds/core/xds.css';
+@import '@xds/theme-default/theme.css';`,
+ },
+ {
+ type: 'prose',
+ text: 'Available themes: @xds/theme-default (blue accent), @xds/theme-neutral (grayscale), @xds/theme-brutalist (zero radius, monospace). See `npx xds docs theme` for the full theming guide.',
},
],
},
{
title: 'Add your first component',
- category: 'guide',
content: [
{
type: 'prose',
@@ -58,13 +81,13 @@ export default function RootLayout({children}) {
lang: 'tsx',
label: 'app/page.tsx',
code: `import {XDSButton} from '@xds/core/Button';
-import {XDSStack} from '@xds/core/Layout';
+import {XDSVStack} from '@xds/core/Layout';
export default function Page() {
return (
- <XDSStack direction="vertical" gap={2}>
- <XDSButton label="Hello XDS" onPress={() => alert('Hi!')} />
- </XDSStack>
+ <XDSVStack gap={2}>
+ <XDSButton label="Hello XDS" onClick={() => alert('Hi!')} />
+ </XDSVStack>
);
}`,
},
@@ -72,7 +95,6 @@ export default function Page() {
},
{
title: 'Customize with xstyle',
- category: 'guide',
content: [
{
type: 'prose',
@@ -93,18 +115,50 @@ const overrides = stylex.create({
],
},
{
- title: 'Run the dev server',
- category: 'guide',
+ title: 'Example Apps',
+ content: [
+ {
+ type: 'prose',
+ text: 'For a full working project, clone one of the example apps from the XDS repo. These are complete setups with routing, theming, and components wired together.',
+ },
+ {
+ type: 'table',
+ headers: ['Example', 'Stack', 'Path'],
+ rows: [
+ ['Next.js', 'Next.js + XDS theme CSS', 'apps/example-nextjs'],
+ ['Next.js + StyleX', 'Next.js + StyleX for custom styles', 'apps/example-nextjs-stylex'],
+ ['Next.js + Tailwind', 'Next.js + Tailwind bridge', 'apps/example-nextjs-tailwind'],
+ ['Next.js Source', 'Next.js importing XDS from source', 'apps/example-nextjs-source'],
+ ['Vite', 'Vite + XDS', 'apps/example-vite'],
+ ],
+ },
+ {
+ type: 'code',
+ lang: 'bash',
+ label: 'Clone and run an example',
+ code: `git clone https://github.com/facebookexperimental/xds.git
+cd xds/apps/example-nextjs
+yarn install
+yarn dev`,
+ },
+ ],
+ },
+ {
+ title: 'Explore the CLI',
content: [
{
type: 'prose',
- text: 'Start the dev server and open the preview URL. Changes to components hot-reload automatically.',
+ text: 'The CLI is your reference for components, tokens, templates, and docs. Use it to discover what\u2019s available.',
},
{
type: 'code',
lang: 'bash',
label: 'Terminal',
- code: `yarn dev`,
+ code: `npx xds component # list all components
+npx xds component Button # props, usage, theming for Button
+npx xds docs # list all doc topics
+npx xds template --list # available page templates
+npx xds docs tokens # spacing, color, radius reference`,
},
],
},
diff --git a/packages/cli/docs/working-with-ai.doc.mjs b/packages/cli/docs/working-with-ai.doc.mjs
new file mode 100644
index 0000000000..d739d9aaa7
--- /dev/null
+++ b/packages/cli/docs/working-with-ai.doc.mjs
@@ -0,0 +1,132 @@
+/** @type {import('../../core/src/docs-types').ReferenceDoc} */
+
+export const docs = {
+ name: 'working-with-ai',
+ title: 'Working with AI',
+ category: 'guide',
+ description:
+ 'How to set up AI coding tools to generate correct XDS component code.',
+
+ sections: [
+ {
+ title: 'Overview',
+ content: [
+ {
+ type: 'prose',
+ text: 'XDS is designed to be AI-friendly \u2014 consistent naming, predictable prop patterns, and a CLI that feeds structured documentation directly into AI context windows. But models still need the right context to avoid falling back to generic React patterns or inventing props.',
+ },
+ {
+ type: 'prose',
+ text: 'The XDS CLI includes a built-in agent docs system that generates context files for your AI tool of choice. One command sets up everything your AI needs to write correct XDS code.',
+ },
+ ],
+ },
+ {
+ title: 'Quick Start',
+ content: [
+ {
+ type: 'prose',
+ text: 'Tell your AI to install the CLI and set itself up:',
+ },
+ {
+ type: 'code',
+ lang: 'text',
+ label: 'Paste this into your AI',
+ code: 'Install @xds/cli and run `npx xds agent-docs` to set up your XDS context. Read the generated file.',
+ },
+ {
+ type: 'prose',
+ text: 'That\'s it. The agent-docs command generates everything your AI needs \u2014 component index, behavioral rules, CLI reference \u2014 pulled from your installed version. After a version bump, run it again to update in place.',
+ },
+ {
+ type: 'prose',
+ text: 'If you prefer to target a specific file format:',
+ },
+ {
+ type: 'code',
+ lang: 'bash',
+ label: 'Manual options',
+ code: `npx xds agent-docs --agent claude # CLAUDE.md
+npx xds agent-docs --agent cursor # .cursorrules
+npx xds agent-docs --agent codex # AGENTS.md (Copilot, Codex, etc.)`,
+ },
+ ],
+ },
+ {
+ title: 'What Gets Generated',
+ content: [
+ {
+ type: 'prose',
+ text: 'The generated context teaches your AI a 3-step workflow before writing any UI code:',
+ },
+ {
+ type: 'list',
+ style: 'ordered',
+ items: [
+ '`npx xds template --list` \u2014 find a related page pattern to use as reference',
+ '`npx xds template <name> --skeleton` \u2014 study the layout structure',
+ '`npx xds component <Name>` \u2014 read props and examples for every component used',
+ ],
+ },
+ {
+ type: 'prose',
+ text: 'It also includes rules that prevent common mistakes (no raw divs, no style={{}}, use tokens not magic values) and a CLI quick reference. After setup, you shouldn\'t need to manually correct your AI on XDS conventions \u2014 the agent docs handle it at the system level.',
+ },
+ ],
+ },
+ {
+ title: 'Cursor Setup',
+ content: [
+ {
+ type: 'prose',
+ text: 'Cursor project rules aren\'t always picked up \u2014 it selects which rules to apply based on relevance. For reliable inclusion, install XDS context as a User Rule instead. User Rules live at ~/.cursor/rules/ and apply across all projects.',
+ },
+ {
+ type: 'code',
+ lang: 'bash',
+ label: 'Install as a Cursor user rule',
+ code: `mkdir -p ~/.cursor/rules
+npx xds agent-docs --agent-docs-path ~/.cursor/rules/xds.mdc`,
+ },
+ ],
+ },
+ {
+ title: 'Checking Your Setup',
+ content: [
+ {
+ type: 'prose',
+ text: 'Paste this into your AI before writing any XDS code. These three questions have a 0% pass rate without docs \u2014 models confidently guess wrong on all of them. If your AI can\'t answer them, it\'ll know to install the agent docs first.',
+ },
+ {
+ type: 'code',
+ lang: 'text',
+ label: 'Paste this into your AI',
+ code: `Before writing any XDS code, check your knowledge:
+
+1. What is the correct import path for XDSButton?
+2. How do you make an XDSDialog non-dismissible?
+3. What prop does XDSSelector use for its items?
+
+If you don't know all three, run \`npx xds init --features agents\` to generate agent docs, then read the generated file.`,
+ },
+ ],
+ },
+ {
+ title: 'The --dense Flag',
+ content: [
+ {
+ type: 'prose',
+ text: 'Every CLI command supports --dense, which outputs a token-efficient format designed for AI context windows. Use it when pasting CLI output into a web-based AI tool like ChatGPT or Claude.',
+ },
+ {
+ type: 'code',
+ lang: 'bash',
+ label: 'Dense output for pasting into AI conversations',
+ code: `npx xds component Dialog --dense
+npx xds docs styling --dense
+npx xds docs tokens --dense`,
+ },
+ ],
+ },
+ ],
+};