@pedroab0/skills 1.0.1 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +19 -3
- package/bin/cli.js +175 -35
- package/figma-extractor/README.md +14 -6
- package/figma-extractor/SKILL.md +18 -16
- package/figma-extractor/figma-plugin/README.md +10 -5
- package/figma-extractor/figma-plugin/code.js +461 -87
- package/figma-extractor/figma-plugin/ui.html +76 -23
- package/figma-extractor/scripts/fetch_figma.js +465 -61
- package/figma-node-builder/README.md +1 -1
- package/figma-node-builder/SKILL.md +7 -8
- package/figma-node-builder/scripts/inspect_spec.js +15 -2
- package/figma-to-code/README.md +10 -4
- package/figma-to-code/SKILL.md +18 -16
- package/figma-to-code/scripts/fetch_figma.js +448 -53
- package/package.json +12 -3
- package/figma-extractor/demo/desktop_home.json +0 -2434
- package/figma-extractor/demo/dt_money_desktop_home.png +0 -0
- package/figma-extractor/demo/dt_money_preview.png +0 -0
- package/figma-extractor/demo/dt_money_selection.json +0 -472
- package/figma-extractor/demo/index.html +0 -188
- package/figma-extractor/demo/style.css +0 -360
- package/figma-extractor/figma-plugin/assets/cover-1920.png +0 -0
- package/figma-extractor/figma-plugin/assets/cover.jpg +0 -0
- package/figma-extractor/figma-plugin/assets/cover.png +0 -0
- package/figma-extractor/figma-plugin/assets/icon-128.png +0 -0
- package/figma-extractor/figma-plugin/assets/icon.png +0 -0
- package/figma-extractor/scripts/test_fetch_figma.js +0 -601
- package/figma-node-builder/scripts/test_inspect_spec.js +0 -148
- package/figma-to-code/scripts/test_fetch_figma.js +0 -581
|
@@ -39,14 +39,13 @@ Before writing any code, inspect the host project to ground your implementation:
|
|
|
39
39
|
### Phase 2: Gap Analysis & Token Mapping
|
|
40
40
|
Analyze the input JSON spec (`.specs/<name>.json`).
|
|
41
41
|
|
|
42
|
-
> **Tip**: Instead of reading the entire raw JSON AST into your context window, run the companion **Spec Inspector CLI**
|
|
42
|
+
> **Tip**: Instead of reading the entire raw JSON AST into your context window, run the companion **Spec Inspector CLI** from this skill's directory (`<skill-dir>` is the folder containing this `SKILL.md` file; if loaded from `.cursor/rules/figma-node-builder.mdc`, use `.cursor/skills/figma-node-builder`):
|
|
43
43
|
> ```bash
|
|
44
|
-
> #
|
|
45
|
-
> node
|
|
46
|
-
>
|
|
47
|
-
> node figma-node-builder/scripts/inspect_spec.js .specs/<name>.json
|
|
44
|
+
> # Compact terminal summary (always quote the script path for Windows/macOS/Linux compatibility):
|
|
45
|
+
> node "<skill-dir>/scripts/inspect_spec.js" .specs/<name>.json
|
|
46
|
+
>
|
|
48
47
|
> # Output Markdown directly for your implementation plan:
|
|
49
|
-
> node <skill-dir>/scripts/inspect_spec.js .specs/<name>.json --markdown
|
|
48
|
+
> node "<skill-dir>/scripts/inspect_spec.js" .specs/<name>.json --markdown
|
|
50
49
|
> ```
|
|
51
50
|
|
|
52
51
|
* **Component Instances**: For each node with `type: "INSTANCE"`, match `component.name` against existing codebase components. Extract its `props` (e.g., `{ variant: "outline", size: "lg", hasIcon: true }`).
|
|
@@ -54,10 +53,10 @@ Analyze the input JSON spec (`.specs/<name>.json`).
|
|
|
54
53
|
* **Gaps**: Identify any sub-components that do not exist yet in the codebase and plan to scaffold them.
|
|
55
54
|
|
|
56
55
|
### Phase 3: Grounded Code Synthesis
|
|
57
|
-
Generate component code strictly adhering to the node specification:
|
|
56
|
+
Generate component code strictly adhering to the node specification and adapting syntax to the host project's detected stack (e.g., React, Vue, Svelte, Angular, or HTML/CSS):
|
|
58
57
|
|
|
59
58
|
1. **Reusing Existing Components (Anti-Div Soup Rule)**:
|
|
60
|
-
- When an `INSTANCE` node matches an existing component, **import and render it directly
|
|
59
|
+
- When an `INSTANCE` node matches an existing component, **import and render it directly** (example in JSX — adapt to your framework):
|
|
61
60
|
```tsx
|
|
62
61
|
// Correct:
|
|
63
62
|
<Button variant="primary" size="large" hasIcon>Confirm Order</Button>
|
|
@@ -28,9 +28,21 @@ const style = {
|
|
|
28
28
|
};
|
|
29
29
|
|
|
30
30
|
// -----------------------------------------------------------------------------
|
|
31
|
-
// Path Resolution
|
|
31
|
+
// Path & Encoding Resolution
|
|
32
32
|
// -----------------------------------------------------------------------------
|
|
33
33
|
|
|
34
|
+
function decodeTextBuffer(buf) {
|
|
35
|
+
if (!Buffer.isBuffer(buf)) {
|
|
36
|
+
const str = String(buf || '');
|
|
37
|
+
return str.charCodeAt(0) === 0xfeff ? str.slice(1) : str;
|
|
38
|
+
}
|
|
39
|
+
if (buf.length >= 2 && buf[0] === 0xff && buf[1] === 0xfe) {
|
|
40
|
+
return buf.toString('utf16le', 2);
|
|
41
|
+
}
|
|
42
|
+
const str = buf.toString('utf8');
|
|
43
|
+
return str.charCodeAt(0) === 0xfeff ? str.slice(1) : str;
|
|
44
|
+
}
|
|
45
|
+
|
|
34
46
|
function resolveSpecPath(inputPath) {
|
|
35
47
|
if (!inputPath || typeof inputPath !== 'string') {
|
|
36
48
|
throw new Error('Please specify a specification file (e.g. .specs/card.json or card)');
|
|
@@ -480,7 +492,7 @@ function main() {
|
|
|
480
492
|
|
|
481
493
|
try {
|
|
482
494
|
const resolvedPath = resolveSpecPath(positional[0]);
|
|
483
|
-
const rawContent = fs.readFileSync(resolvedPath
|
|
495
|
+
const rawContent = decodeTextBuffer(fs.readFileSync(resolvedPath));
|
|
484
496
|
const parsedData = JSON.parse(rawContent);
|
|
485
497
|
|
|
486
498
|
const inspection = inspectSpec(parsedData, resolvedPath);
|
|
@@ -507,6 +519,7 @@ if (require.main === module) {
|
|
|
507
519
|
}
|
|
508
520
|
|
|
509
521
|
module.exports = {
|
|
522
|
+
decodeTextBuffer,
|
|
510
523
|
resolveSpecPath,
|
|
511
524
|
inspectSpec,
|
|
512
525
|
formatTerminalReport,
|
package/figma-to-code/README.md
CHANGED
|
@@ -74,10 +74,16 @@ Choose one of the following terminal commands:
|
|
|
74
74
|
```bash
|
|
75
75
|
export FIGMA_ACCESS_TOKEN="figd_your_token_here"
|
|
76
76
|
```
|
|
77
|
-
- **Persist globally
|
|
77
|
+
- **Persist globally on macOS / Linux (`~/.zshrc`)**:
|
|
78
78
|
```bash
|
|
79
79
|
echo 'export FIGMA_ACCESS_TOKEN="figd_your_token_here"' >> ~/.zshrc && source ~/.zshrc
|
|
80
80
|
```
|
|
81
|
+
- **Persist globally on Windows (PowerShell)**:
|
|
82
|
+
```powershell
|
|
83
|
+
[Environment]::SetEnvironmentVariable("FIGMA_ACCESS_TOKEN", "figd_your_token_here", "User")
|
|
84
|
+
# Or inside your PowerShell profile ($PROFILE):
|
|
85
|
+
# $env:FIGMA_ACCESS_TOKEN="figd_your_token_here"
|
|
86
|
+
```
|
|
81
87
|
|
|
82
88
|
*(Optional: If behind a corporate proxy with self-signed SSL certificates, run `echo 'FIGMA_IGNORE_SSL=true' >> .env`).*
|
|
83
89
|
|
|
@@ -88,7 +94,7 @@ Flags are **completely optional** — you do not have to specify any flags:
|
|
|
88
94
|
- *"Inspect this frame and download a preview image"* (agent uses `--image` or `-i`).
|
|
89
95
|
- *"Only extract the design tokens from this file"* (agent uses `--tokens`).
|
|
90
96
|
- *"Collapse component sub-layers into props"* (agent uses `--shallow-instances`).
|
|
91
|
-
- **Tip (Guarantee Autonomous Invocation)**: To ensure the agent never skips the extractor and never estimates CSS without extracting, add this suggestion to your project's `
|
|
97
|
+
- **Tip (Guarantee Autonomous Invocation)**: To ensure the agent never skips the extractor and never estimates CSS without extracting, add this suggestion to your project's agent instructions file (e.g., `AGENTS.md`, `CLAUDE.md`, `GEMINI.md`, `.kiro/steering/`, or `.cursor/rules/`):
|
|
92
98
|
```markdown
|
|
93
99
|
## Figma UI Development
|
|
94
100
|
Whenever a Figma link is provided or you are asked to build UI from Figma:
|
|
@@ -142,9 +148,9 @@ node figma-to-code/scripts/fetch_figma.js "<FigmaURL>" -i --shallow-instances
|
|
|
142
148
|
|
|
143
149
|
The skill includes the following resources:
|
|
144
150
|
|
|
145
|
-
- **Agent Instruction Guide (`SKILL.md`)**: The core skill definition read by AI agents (
|
|
151
|
+
- **Agent Instruction Guide (`SKILL.md`)**: The core skill definition read by AI agents (Claude Code, Kiro, Cursor, OpenCode, Codex, Antigravity) containing workflow triggers and pair-programming guidelines.
|
|
146
152
|
- **Core Extraction Script (`scripts/fetch_figma.js`)**: The standalone, zero-dependency Node.js script that interfaces with the Figma REST API, resolves tokens, prunes the AST, and downloads preview images.
|
|
147
|
-
- **Unit Test Suite (`scripts/test_fetch_figma.js`)**:
|
|
153
|
+
- **Unit Test Suite (`scripts/test_fetch_figma.js`)**: Automated unit tests verifying environment/profile parsing, URL parsing, token formatting, component prop cleaning, rate-limit gates, and node pruning without requiring network access.
|
|
148
154
|
- **Specification Directory (`.specs/`)**: The local workspace directory where downloaded image previews are stored for multimodal visual inspection.
|
|
149
155
|
- **Reference Documentation (`README.md`)**: This guide explaining architecture, MCP comparison, and operational flags.
|
|
150
156
|
|
package/figma-to-code/SKILL.md
CHANGED
|
@@ -17,7 +17,7 @@ This skill connects to the Figma REST API, extracts a compact design-system-awar
|
|
|
17
17
|
> **NEVER use browser tools (Playwright, Puppeteer, Chrome DevTools, `browser_navigate`, `read_browser_page`) on Figma URLs.**
|
|
18
18
|
>
|
|
19
19
|
> 1. **Figma Canvas is WebGL/Wasm**: Figma renders design canvas elements inside an HTML5 `<canvas>` via WebAssembly. There are NO inspectable HTML DOM elements for frames, layers, texts, or styles. Browser automation cannot extract Figma nodes or properties.
|
|
20
|
-
> 2. **Never search
|
|
20
|
+
> 2. **Never search for local browser binaries**: Do not search OS application directories (e.g., `/Applications`, `Program Files`, `/usr/bin`) or run browser automation scripts.
|
|
21
21
|
> 3. **API Errors Are Final**: If `fetch_figma.js` returns an API error (e.g., 401 Unauthorized, 403 Forbidden, or 429 Rate Limited), **report the error directly to the user**. Guide them to check their `FIGMA_ACCESS_TOKEN`, permissions, or wait out rate limits. Do NOT attempt browser scraping fallbacks.
|
|
22
22
|
|
|
23
23
|
---
|
|
@@ -27,7 +27,7 @@ This skill connects to the Figma REST API, extracts a compact design-system-awar
|
|
|
27
27
|
To protect your Figma file quota and prevent lockout penalties, `fetch_figma.js` enforces an automatic safety gate:
|
|
28
28
|
* **Max 5 requests per minute** per file key (sliding window limit).
|
|
29
29
|
* **2.5s inter-request pacing** between consecutive requests.
|
|
30
|
-
* **Persistent Circuit Breaker**: If Figma returns HTTP 429, the script records the lockout time locally in
|
|
30
|
+
* **Persistent Circuit Breaker**: If Figma returns HTTP 429, the script records the lockout time locally in `.figma_ratelimit.json` inside the user's home directory. All future calls to that file key are **immediately blocked with zero network traffic**, preventing Figma from extending the lockout penalty.
|
|
31
31
|
|
|
32
32
|
### Agent Behavioral Rules (Zero-Hammer Protocol)
|
|
33
33
|
1. **Single-Shot Execution**: Run `fetch_figma.js` **once** per target frame or component.
|
|
@@ -41,7 +41,9 @@ To protect your Figma file quota and prevent lockout penalties, `fetch_figma.js`
|
|
|
41
41
|
A Figma Access Token (Personal Access Token or OAuth Token) is required.
|
|
42
42
|
|
|
43
43
|
Configure it using either:
|
|
44
|
-
1. **Environment Variable**:
|
|
44
|
+
1. **Environment Variable**:
|
|
45
|
+
- **macOS / Linux**: `export FIGMA_ACCESS_TOKEN="figd_your_token_here"` (or `FIGMA_TOKEN`)
|
|
46
|
+
- **Windows (PowerShell)**: `[Environment]::SetEnvironmentVariable("FIGMA_ACCESS_TOKEN", "figd_your_token_here", "User")` or `$env:FIGMA_ACCESS_TOKEN="figd_your_token_here"` in `$PROFILE`
|
|
45
47
|
2. **Workspace `.env` File**:
|
|
46
48
|
```env
|
|
47
49
|
FIGMA_ACCESS_TOKEN=figd_your_token_here
|
|
@@ -66,20 +68,20 @@ FIGMA_IGNORE_SSL=true
|
|
|
66
68
|
|
|
67
69
|
## Agent Execution Instructions
|
|
68
70
|
|
|
69
|
-
To extract and build UI from a Figma URL, run `fetch_figma.js` from
|
|
71
|
+
To extract and build UI from a Figma URL, run `fetch_figma.js` from this skill's `scripts/` directory:
|
|
70
72
|
|
|
71
73
|
```bash
|
|
72
74
|
# Recommended: Extract compact AST (1 Tier 1 call)
|
|
73
|
-
node <skill-dir>/scripts/fetch_figma.js "<FigmaURL>"
|
|
75
|
+
node "<skill-dir>/scripts/fetch_figma.js" "<FigmaURL>"
|
|
74
76
|
|
|
75
77
|
# Optional: With companion preview image (2 Tier 1 calls)
|
|
76
|
-
node <skill-dir>/scripts/fetch_figma.js "<FigmaURL>" -i
|
|
78
|
+
node "<skill-dir>/scripts/fetch_figma.js" "<FigmaURL>" -i
|
|
77
79
|
```
|
|
78
80
|
|
|
79
|
-
**
|
|
80
|
-
- **
|
|
81
|
-
- **
|
|
82
|
-
- **
|
|
81
|
+
**Resolving `<skill-dir>` (Agent-Agnostic)**:
|
|
82
|
+
Substitute `<skill-dir>` with the directory where this skill is installed — **never guess another agent's folder** (always keep double quotes around the script path for Windows/macOS/Linux compatibility):
|
|
83
|
+
- **Standard Skills (`SKILL.md`)**: `<skill-dir>` is the exact parent directory of this `SKILL.md` file.
|
|
84
|
+
- **Cursor Rule (`.cursor/rules/figma-to-code.mdc`)**: `<skill-dir>` is the sibling `.cursor/skills/figma-to-code` directory (replace `rules/figma-to-code.mdc` with `skills/figma-to-code`).
|
|
83
85
|
|
|
84
86
|
---
|
|
85
87
|
|
|
@@ -89,13 +91,13 @@ node <skill-dir>/scripts/fetch_figma.js "<FigmaURL>" -i
|
|
|
89
91
|
|
|
90
92
|
```bash
|
|
91
93
|
# Standard extraction (1 Tier 1 call - recommended)
|
|
92
|
-
node
|
|
94
|
+
node "<skill-dir>/scripts/fetch_figma.js" "https://www.figma.com/design/:fileKey/:name?node-id=4023-474"
|
|
93
95
|
|
|
94
96
|
# Optional: With preview image (2 Tier 1 calls)
|
|
95
|
-
node
|
|
97
|
+
node "<skill-dir>/scripts/fetch_figma.js" "https://www.figma.com/design/:fileKey/:name?node-id=4023-474" -i
|
|
96
98
|
|
|
97
99
|
# Collapse internal layers of component instances into props (guides agent to reuse existing components)
|
|
98
|
-
node
|
|
100
|
+
node "<skill-dir>/scripts/fetch_figma.js" "https://www.figma.com/design/:fileKey/:name?node-id=4023-474" --shallow-instances
|
|
99
101
|
```
|
|
100
102
|
|
|
101
103
|
### 2. CLI Flags Reference
|
|
@@ -169,7 +171,7 @@ When an `INSTANCE` node is present, internal property hashes are converted into
|
|
|
169
171
|
|
|
170
172
|
## How to Build Components from the Extracted Data
|
|
171
173
|
|
|
172
|
-
When synthesizing code from the output:
|
|
174
|
+
When synthesizing code from the output (always adapting syntax, attributes, and styling conventions to the project's detected stack — e.g., React, Vue, Svelte, Angular, or plain HTML/CSS):
|
|
173
175
|
|
|
174
176
|
1. **Using Existing UI Components**:
|
|
175
177
|
- For `INSTANCE` nodes with resolved `component.name` and `props`:
|
|
@@ -202,10 +204,10 @@ When synthesizing code from the output:
|
|
|
202
204
|
|
|
203
205
|
- **Token Expired / Missing (`FIGMA_TOKEN_EXPIRED_OR_INVALID` / `isTokenExpiredOrInvalid`)**:
|
|
204
206
|
- Alert the user that their Figma access token is missing, invalid, or expired.
|
|
205
|
-
- Instruct the user to create a token in **Figma Settings $\rightarrow$ Personal Access Tokens** and
|
|
207
|
+
- Instruct the user to create a token in **Figma Settings $\rightarrow$ Personal Access Tokens** and configure `FIGMA_ACCESS_TOKEN` in their environment or workspace `.env` file.
|
|
206
208
|
- **Node Not Found**:
|
|
207
209
|
- Alert the user that the node ID could not be found in the specified file.
|
|
208
210
|
- **Corporate Proxy / Self-Signed SSL (`FIGMA_SSL_CERTIFICATE_ERROR`)**:
|
|
209
|
-
- Instruct the user to add `FIGMA_IGNORE_SSL=true` to `.env` or
|
|
211
|
+
- Instruct the user to add `FIGMA_IGNORE_SSL=true` to `.env` or set it in their environment.
|
|
210
212
|
- **Rate Limited (`FIGMA_RATE_LIMIT_EXCEEDED` / `FIGMA_CIRCUIT_BREAKER_ACTIVE`)**:
|
|
211
213
|
- Figma REST API has strict per-minute and monthly rate limits. If rate limited or the circuit breaker trips, report the cooldown to the user and suggest duplicating the file in Figma Drafts to get a fresh URL.
|