dsai-figma
Skill0 starsChanged 8 months agoMITView on GitHub
Reference for the @dsai-io/figma-tokens package and Figma integration workflow. Covers Figma Variables API sync, token pipeline, rate limiting, description parsing, Code Connect, and the complete Figma-to-production-CSS flow.
- Reads credentials
- Installs packages
In this repository30 other files it gives its agents.
- skills/react-best-practices/AGENTS.mdAGENTS.md
- accessibilitySkill
- adr-writerSkill
- automatic-code-reviewSkill
- component-visualizerSkill
- create-tasksSkill
- dsai-componentsSkill
- dsai-stylingSkill
- dsai-toolsSkill
- figma-code-connect-componentsSkill
- figma-create-design-system-rulesSkill
- figma-create-new-fileSkill
- figma-generate-designSkill
- figma-generate-librarySkill
- figma-implement-designSkill
- figma-useSkill
- miro-mcpSkill
- nodejsSkill
- playwright-skillSkill
- prismaSkill
- react-best-practicesSkill
- reactSkill
- route-testerSkill
- setupSkill
- skill-creatorSkill
- skill-developerSkill
- sync-schemasSkill
- task-checkSkill
- web-design-guidelinesSkill
- writing-testsSkill
The file
We split this skill into the rules it gives an agent
12 rules. About 0 are common, 6 are distinctive, and 6 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈6
Distinctive · estimate
This author's own choices. Worth a look.
6
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- could be automatic: a setting could enforce it
- Distinctive: line 17
Create a new token with File content: Read-only and Variables: Read scopes
- Very specific: line 22
Add to your project's .env file (never commit this):
- Distinctive: line 38
If successful, you'll see the list of variable collections found in the file.
- Distinctive: line 188
After publishing, Figma's Dev Mode shows the DSAI React code snippet for each mapped component.
- Very specific: line 226
Verify FIGMA_API_KEY is set in .env and the app has loaded it
- Distinctive: line 227
Check that the token has File content: Read-only and Variables: Read scopes
- Distinctive: line 235
Wait a few minutes and retry — Figma rate limits reset over time
- Very specific: line 236
Check the X-RateLimit-Remaining header in debug output
- Distinctive: line 240
Ensure the Figma file has Variables defined (not just Styles)
- Very specific: line 241
Verify FIGMA_FILE_ID matches the file containing the variables
- Very specific: line 242
Check src/figma-exports/ for raw output — if empty, the API returned no variables
- Very specific: line 246
Run dsai tokens validate to check for DTCG format errors
≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
@dsai-io/figma-tokens — Figma Integration
Package: @dsai-io/figma-tokens (v1.1.0)
Purpose: Pull design tokens from Figma Variables API into DTCG format for the DSAI token pipeline.
Getting Started
1. Create a Figma Personal Access Token
- Open Figma → Settings → Account → Personal access tokens
- Create a new token with File content: Read-only and Variables: Read scopes
- Copy the token
2. Set Environment Variables
Add to your project's .env file (never commit this):
FIGMA_API_KEY=figd_xxxxxxxxxxxxxxxxxxxx
FIGMA_FILE_ID=AbCdEfGhIjKlMnOpQrStUvFIGMA_FILE_ID is the string after /design/ in your Figma file URL:
figma.com/design/AbCdEfGhIjKlMnOpQrStUv/My-Design → AbCdEfGhIjKlMnOpQrStUv
3. Verify Connection
dsai figma sync --dry-runIf successful, you'll see the list of variable collections found in the file.
4. Run First Sync
dsai figma sync # Pull tokens from Figma
dsai tokens build # Build CSS/SCSS/JS/TS outputsArchitecture
Three components:
- FigmaClient — REST API wrapper for Figma Variables API
- RateLimiter — Automatic request throttling based on
X-RateLimit-*headers - DescriptionParser — Extracts structured metadata from Figma variable descriptions
The package re-exports all token operations from @dsai-io/tools, so consumers get both Figma sync AND token building from one import.
FigmaClient Configuration
const client = new FigmaClient({
accessToken: process.env.FIGMA_API_KEY, // Required
baseUrl: 'https://api.figma.com', // Default
timeout: 30000, // 30 seconds
retries: 3, // Auto-retry on failure
cache: true, // Cache responses
});Rate Limiting
Proactive throttling based on remaining API quota:
- At 20% remaining (
throttleThreshold: 0.2) → 2 second delay between requests - At 10% remaining (
criticalThreshold: 0.1) → 5 second delay - Parses
X-RateLimit-RemainingandX-RateLimit-Limitheaders automatically
Font Detection Patterns
Identifies font properties by Figma variable name:
| Property | Pattern |
| Weight | /weight/i |
| Family | /family/i |
| Size | /size|fontSize/i |
| LineHeight | /lineHeight|line-height/i |
| LetterSpacing | /letterSpacing|letter-spacing|tracking/i |
Description Parser
Extracts structured metadata from Figma variable descriptions:
Input: "Main description text. Docs.Reference: https://example.com • Platform.Variable: $color-primary"
Output: {
description: "Main description text",
metadata: {
docs: { reference: "https://example.com" },
platform: { variable: "$color-primary" }
}
}Complete Workflow: Figma → Production CSS
1. Design tokens defined in Figma Variables
↓
2. dsai figma sync (or pnpm figma:sync)
- Uses FIGMA_API_KEY and FIGMA_FILE_ID env vars
- Pulls variables via Figma REST API
- Rate-limited automatically
- Outputs to src/figma-exports/
↓
3. Token files land in src/figma-exports/ (raw Figma format)
↓
4. dsai tokens build
- Step 1: validate (DTCG schema check)
- Step 3: preprocess (extract light/dark modes)
- Step 4: transform (Figma → DTCG format in src/collections/)
- Steps 5-12: Build CSS/SCSS/JS/TS outputs
↓
5. Generated files in src/generated/
- tokens.css (:root { --dsai-*: value; })
- tokens-dark.css ([data-dsai-theme="dark"] { ... })
- dsai-theme-bs.css (Bootstrap compiled with token overrides)
↓
6. Imported in main.tsx, components use CSS custom propertiesFigma Code Connect
Separate from tokens — maps Figma component instances to code.
Setup
# Install Code Connect
npm install -D @figma/code-connect
# Initialize (creates figma.config.json)
pnpm figma:connectCreating a Code Connect Mapping
Code Connect files are colocated with their component. For example, Button.figma.tsx sits next to Button.tsx:
// src/client/components/ui/button/Button.figma.tsx
import figma from '@figma/code-connect';
import { Button } from './Button';
figma.connect(Button, 'https://figma.com/design/FILE_KEY/..?node-id=NODE_ID', {
props: {
label: figma.string('Label'),
variant: figma.enum('Variant', {
Primary: 'primary',
Secondary: 'secondary',
Danger: 'danger',
Ghost: 'ghost',
}),
size: figma.enum('Size', {
Small: 'sm',
Medium: 'md',
Large: 'lg',
}),
disabled: figma.boolean('Disabled'),
loading: figma.boolean('Loading'),
},
example: ({ label, variant, size, disabled, loading }) => (
<Button variant={variant} size={size} disabled={disabled} loading={loading}>
{label}
</Button>
),
});Publishing Mappings
pnpm figma:publish # Publish to Figma
pnpm figma:publish:dry # Preview without publishingAfter publishing, Figma's Dev Mode shows the DSAI React code snippet for each mapped component.
Environment Variables
FIGMA_API_KEY="" # Figma personal access token (required for sync)
FIGMA_FILE_ID="" # Figma file containing design tokens
FIGMA_PROJECT_ID="" # Optional: specific Figma projectToken Sync Scripts (in consumer project package.json)
{
"figma:sync": "dsai figma sync",
"tokens:build": "dsai tokens build",
"tokens:validate": "dsai tokens validate",
"tokens:watch": "dsai tokens watch"
}Critical Rules
- NEVER manually edit files in
src/generated/— they are auto-generated by the pipeline. - Edit tokens in
src/collections/*.json, then rundsai tokens build. - For Figma-sourced tokens, edit in Figma first, then
dsai figma sync+dsai tokens build. FIGMA_API_KEYshould be in.env(never committed to git).- Rate limiter is automatic — no manual throttling needed.
- Token edits in
collections/follow DTCG format ($value,$type,$description).
Troubleshooting
"Unauthorized" or "Invalid token" on dsai figma sync
- Verify
FIGMA_API_KEYis set in.envand the app has loaded it - Check that the token has File content: Read-only and Variables: Read scopes
- Regenerate the token if it was revoked or expired
Rate limit errors
The RateLimiter handles most cases automatically. If you still hit limits:
- Reduce the number of files being synced in parallel
- Wait a few minutes and retry — Figma rate limits reset over time
- Check the
X-RateLimit-Remainingheader in debug output
Sync runs but no tokens appear
- Ensure the Figma file has Variables defined (not just Styles)
- Verify
FIGMA_FILE_IDmatches the file containing the variables - Check
src/figma-exports/for raw output — if empty, the API returned no variables
dsai tokens build fails after sync
- Run
dsai tokens validateto check for DTCG format errors - Figma exports may need the
transformstep to convert to DTCG format — ensure the pipeline includes bothpreprocessandtransformsteps
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

