pi-mono-figma 0.1.1

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/CHANGELOG.md ADDED
@@ -0,0 +1,34 @@
1
+ # pi-mono-figma
2
+
3
+ ## Unreleased
4
+
5
+ ### Minor Changes
6
+
7
+ ### Added: LLM-ready Figma workflow
8
+
9
+ - Added `figma_get_node_summary`, `figma_extract_text`, `figma_explain_node`, and `figma_get_implementation_context` processed tools.
10
+ - Added compact node summarization that ignores hidden nodes, vector internals, and component instance internals by default.
11
+ - Changed `figma_get_design_context` to return compact top-level file context or target-node summaries instead of full recursive file structure.
12
+ - Updated tool descriptions, README, and skill guidance to prefer processed tools and keep raw JSON tools as debugging escape hatches.
13
+ - Added response caps, truncation metadata, and next-step suggestions for summarized node output.
14
+
15
+ ## 0.1.1
16
+
17
+ ### Patch Changes
18
+
19
+ ### Enhanced: auth setup
20
+
21
+ - Added `/figma-auth` command and `figma_configure_auth` tool for masked local token capture.
22
+ - Figma tools now prompt for a fresh token and retry once when auth is missing, invalid, or expired.
23
+ - Token setup writes to `~/.pi/agent/auth.json` without returning the token to the model.
24
+
25
+ ## 0.1.0
26
+
27
+ ### Minor Changes
28
+
29
+ ### New Extension: figma
30
+
31
+ - Added native Figma REST API tools for file, node, styles, variables, components, component sets, component search, design-context, URL parsing, metadata, and node rendering workflows.
32
+ - Added bundled `figma` skill that explains when and how to use the native `figma_*` tools.
33
+ - Added authentication support via `FIGMA_TOKEN` and `~/.pi/agent/auth.json` at `.figma.token`.
34
+ - Added README documentation for token creation, required Figma file-content read scope, and setup/troubleshooting.
package/LICENCE.md ADDED
@@ -0,0 +1,7 @@
1
+ Copyright 2026 Emanuel Casco
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,171 @@
1
+ # pi-mono-figma
2
+
3
+ A pi extension and skill package that exposes native Figma tools for design exploration and design-to-code workflows. The default tools return compact, LLM-ready design context instead of raw Figma JSON.
4
+
5
+ ## Tools
6
+
7
+ ### Processed, LLM-ready tools (preferred)
8
+
9
+ - `figma_parse_url` — parse a Figma URL into `fileKey` and `nodeId`.
10
+ - `figma_render_nodes` — render node image URLs and optionally download assets locally. Downloads use an OS temp directory by default unless `outputDir` is provided.
11
+ - `figma_get_node_summary` — fetch a compact structured summary of a node: name, type, size, layout, spacing, visual style, visible text, component properties, and shallow child hierarchy.
12
+ - `figma_extract_text` — return visible text nodes only.
13
+ - `figma_explain_node` — explain a node in Markdown using summary, visible text, hierarchy, and optional rendered asset.
14
+ - `figma_get_implementation_context` — return coding-ready design context: purpose, sections, fields/buttons, measurements, typography, colors, spacing, assets, and component hierarchy.
15
+ - `figma_get_design_context` — fetch compact file context. With `nodeId`, returns target node summary plus location/sibling context; without `nodeId`, returns canvases and top-level frames only.
16
+ - `figma_get_node_metadata` — fetch compact spatial/layout metadata for one or more nodes.
17
+ - `figma_get_styles` — fetch named styles.
18
+ - `figma_get_variables` — fetch local variables/collections for design tokens.
19
+ - `figma_get_components` — fetch component metadata.
20
+ - `figma_get_component_sets` — fetch component set metadata.
21
+ - `figma_search_components` — search components by name or description.
22
+ - `figma_configure_auth` — securely prompt for and store a Figma token without exposing it to the model.
23
+
24
+ ### Raw escape hatches
25
+
26
+ - `figma_get_file` — fetch raw Figma file JSON. Use only when raw Figma JSON is explicitly needed or when debugging the extension.
27
+ - `figma_get_nodes` — fetch raw node JSON. Use only when raw Figma JSON is explicitly needed or when debugging the extension.
28
+
29
+ The package also bundles the `figma` skill under `skills/figma/SKILL.md`.
30
+
31
+ ## Recommended workflows
32
+
33
+ ### Explaining a component
34
+
35
+ ```text
36
+ figma_parse_url
37
+ figma_render_nodes
38
+ figma_explain_node
39
+ ```
40
+
41
+ ### Implementing a design
42
+
43
+ ```text
44
+ figma_parse_url
45
+ figma_render_nodes
46
+ figma_get_implementation_context
47
+ figma_get_node_summary for specific subnodes if needed
48
+ ```
49
+
50
+ ### Debugging raw Figma data
51
+
52
+ ```text
53
+ figma_get_nodes
54
+ ```
55
+
56
+ ## Processed node options
57
+
58
+ Processed tools fetch nodes with compact depth limits and summarize safely:
59
+
60
+ ```ts
61
+ {
62
+ depth?: number; // default 2, capped at 4
63
+ includeHidden?: boolean; // default false
64
+ includeVectors?: boolean; // default false
65
+ includeComponentInternals?: boolean; // default false
66
+ }
67
+ ```
68
+
69
+ Defaults intentionally avoid hidden layers, vector internals, and huge component instance trees. Increase depth or include internals only for a focused child node.
70
+
71
+ ## Output limits and truncation
72
+
73
+ Processed tools default to compact responses (~20k chars unless overridden by `maxResponseChars`) and cap common large arrays:
74
+
75
+ - visible text: 200 entries
76
+ - children: 100 entries
77
+ - depth: 4 max
78
+
79
+ When data is capped, responses include `metadata.truncated: true`, `truncatedReasons`, and `nextSteps` such as inspecting a child node or increasing depth.
80
+
81
+ ## Authentication
82
+
83
+ The extension looks for a Figma token in this order:
84
+
85
+ 1. in-memory token override created by `/figma-auth --force` or `figma_configure_auth`
86
+ 2. `FIGMA_TOKEN` environment variable
87
+ 3. `~/.pi/agent/auth.json` at `.figma.token`
88
+
89
+ If no token is found, or if Figma rejects the token as invalid/expired, the native tools can prompt you with a masked local dialog and store the replacement token without returning it to the model.
90
+
91
+ Do **not** paste tokens into an LLM chat.
92
+
93
+ ### Recommended: native auth command
94
+
95
+ Run this in pi:
96
+
97
+ ```text
98
+ /figma-auth --force
99
+ ```
100
+
101
+ The command shows the Figma token URL and required scopes, prompts for the token with masked input, and writes it to `~/.pi/agent/auth.json` at `.figma.token`.
102
+
103
+ The same flow is available to the agent through the `figma_configure_auth` tool. That tool returns only metadata such as `stored: true`; it never returns the token.
104
+
105
+ ### Option A: environment variable
106
+
107
+ For the current shell session:
108
+
109
+ ```bash
110
+ export FIGMA_TOKEN="figd_xxx"
111
+ ```
112
+
113
+ To persist it, add that export to your shell profile (`~/.zshrc`, `~/.bashrc`, etc.) or your preferred secrets manager.
114
+
115
+ ### Option B: pi auth file
116
+
117
+ Create or update `~/.pi/agent/auth.json`:
118
+
119
+ ```json
120
+ {
121
+ "figma": {
122
+ "token": "figd_xxx"
123
+ }
124
+ }
125
+ ```
126
+
127
+ Recommended file permissions:
128
+
129
+ ```bash
130
+ mkdir -p ~/.pi/agent
131
+ chmod 700 ~/.pi/agent
132
+ chmod 600 ~/.pi/agent/auth.json
133
+ ```
134
+
135
+ If the file already contains other credentials, merge the `figma.token` entry instead of overwriting the file.
136
+
137
+ ## Creating a Figma token
138
+
139
+ 1. Open Figma.
140
+ 2. Go to **Settings → Security → Personal access tokens**.
141
+ 3. Click **Generate new token**.
142
+ 4. Name it something recognizable, for example `pi-agent`.
143
+ 5. Enable the required scopes/permissions below.
144
+ 6. Copy the token once and store it via `FIGMA_TOKEN` or `~/.pi/agent/auth.json`.
145
+
146
+ ## Required scopes / permissions
147
+
148
+ This extension is read-only. It needs permission to read file content and render nodes.
149
+
150
+ Enable:
151
+
152
+ - **File content** / read access to files
153
+
154
+ Also make sure the token has access to the specific Figma file, project, or team you want to inspect. If your Figma organization supports resource scoping, grant access only to the minimum projects/files needed.
155
+
156
+ No write/admin scopes are required.
157
+
158
+ ## Troubleshooting
159
+
160
+ ### `Token expired`
161
+
162
+ Generate a new Figma personal access token and update `FIGMA_TOKEN` or `~/.pi/agent/auth.json`.
163
+
164
+ ### Missing or inaccessible file
165
+
166
+ Confirm that:
167
+
168
+ - the file key is correct,
169
+ - the token has file-content read permission,
170
+ - the token owner can access the file in Figma,
171
+ - the node ID uses either URL format (`27399-4245`) or API format (`27399:4245`).
package/index.ts ADDED
@@ -0,0 +1,6 @@
1
+ import type { ExtensionAPI } from "@mariozechner/pi-coding-agent";
2
+ import { registerFigmaTools } from "./src/figma-tools.js";
3
+
4
+ export default function figmaExtension(pi: ExtensionAPI): void {
5
+ registerFigmaTools(pi);
6
+ }
package/package.json ADDED
@@ -0,0 +1,27 @@
1
+ {
2
+ "name": "pi-mono-figma",
3
+ "version": "0.1.1",
4
+ "description": "Pi extension and skill for Figma design context tools",
5
+ "type": "module",
6
+ "keywords": [
7
+ "pi-package",
8
+ "pi-extension",
9
+ "pi-skill",
10
+ "figma"
11
+ ],
12
+ "dependencies": {
13
+ "pi-common": "0.1.1"
14
+ },
15
+ "peerDependencies": {
16
+ "@mariozechner/pi-coding-agent": "*",
17
+ "@sinclair/typebox": "*"
18
+ },
19
+ "pi": {
20
+ "extensions": [
21
+ "./index.ts"
22
+ ],
23
+ "skills": [
24
+ "./skills"
25
+ ]
26
+ }
27
+ }
@@ -0,0 +1,113 @@
1
+ ---
2
+ name: figma
3
+ description: Access Figma design files using native pi tools — read LLM-ready summaries, explanations, implementation context, screenshots, components, styles, variables, and design tokens. Requires a Figma personal access token.
4
+ ---
5
+
6
+ # Figma Design Integration
7
+
8
+ Use the native `figma_*` tools to read Figma files and translate designs into code. Prefer processed, LLM-ready tools over raw Figma JSON.
9
+
10
+ ## When to Use
11
+
12
+ - User provides a Figma file URL and asks you to explain or implement a design.
13
+ - User asks about Figma colors, typography, spacing, components, variables, or layout.
14
+ - You need screenshots/assets for visual validation.
15
+
16
+ ## Authentication
17
+
18
+ The tools read the token from an in-memory override, `FIGMA_TOKEN`, or `~/.pi/agent/auth.json` at `.figma.token`.
19
+
20
+ If auth is missing, invalid, or expired, do **not** ask the user to paste the token in chat. Use the native `figma_configure_auth` tool or ask the user to run `/figma-auth --force`. The prompt is masked and the token is stored by the extension without returning it to the model.
21
+
22
+ ## URL Parsing
23
+
24
+ Given:
25
+
26
+ ```text
27
+ https://www.figma.com/design/ABC123def456/Project-Name?node-id=123-456
28
+ ```
29
+
30
+ - File key: `ABC123def456`
31
+ - Node ID: `123-456` from the URL (`figma_*` tools also accept API format `123:456`)
32
+
33
+ Use `figma_parse_url` when you need to extract these values from a full URL.
34
+
35
+ ## Default Tool Workflow
36
+
37
+ 1. Use `figma_configure_auth` only when auth is missing, invalid, expired, or the user asks to update the token.
38
+ 2. Use `figma_parse_url` for full Figma URLs.
39
+ 3. Use `figma_render_nodes` for screenshots/assets when visual context helps.
40
+ 4. Use `figma_explain_node` or `figma_get_node_summary` for the target frame/component.
41
+ 5. Use `figma_get_implementation_context` when coding from a design.
42
+ 6. Use `figma_get_design_context` for compact file/page/top-level context.
43
+ 7. Use `figma_get_nodes` only for raw debugging.
44
+
45
+ **Do not call `figma_get_nodes` by default. Prefer processed tools.**
46
+
47
+ Prefer batch calls where supported: pass multiple node IDs to `figma_render_nodes`, `figma_get_node_metadata`, or raw `figma_get_nodes` instead of looping.
48
+
49
+ ## Recommended Workflows
50
+
51
+ ### Explaining a component
52
+
53
+ ```text
54
+ figma_parse_url
55
+ figma_render_nodes
56
+ figma_explain_node
57
+ ```
58
+
59
+ ### Implementing a design
60
+
61
+ ```text
62
+ figma_parse_url
63
+ figma_render_nodes
64
+ figma_get_implementation_context
65
+ figma_get_node_summary for specific subnodes if needed
66
+ ```
67
+
68
+ ### Debugging the extension or raw Figma data
69
+
70
+ ```text
71
+ figma_get_nodes
72
+ ```
73
+
74
+ ## Processed Tools
75
+
76
+ - `figma_get_node_summary` returns compact structured summaries: name, type, size, layout, spacing/padding, fills/strokes/effects, visible text, component properties, and immediate child hierarchy.
77
+ - `figma_extract_text` returns visible text nodes only.
78
+ - `figma_explain_node` returns human-readable Markdown for questions like “Explain this component.”
79
+ - `figma_get_implementation_context` returns coding-ready context: purpose, sections, fields/buttons, measurements, typography, colors, spacing, assets, and React-friendly hierarchy.
80
+
81
+ Processed tools default to shallow, safe fetches:
82
+
83
+ ```ts
84
+ {
85
+ depth: 2,
86
+ includeHidden: false,
87
+ includeVectors: false,
88
+ includeComponentInternals: false
89
+ }
90
+ ```
91
+
92
+ Only increase `depth` (max 4) or enable internals/vectors for a specific child node when needed.
93
+
94
+ ## Raw Escape Hatches
95
+
96
+ - `figma_get_file`
97
+ - `figma_get_nodes`
98
+
99
+ Use these only when raw Figma JSON is explicitly needed or when debugging the extension. They may return very large responses and reduce answer quality.
100
+
101
+ ## Output Limits
102
+
103
+ Processed tools enforce compact defaults and may include `metadata.truncated: true` plus `nextSteps`, for example:
104
+
105
+ - Call `figma_get_node_summary` with a deeper `depth`.
106
+ - Inspect a specific child node by ID.
107
+ - Enable `includeComponentInternals=true` for a focused component instance.
108
+
109
+ ## Notes
110
+
111
+ - Figma API is rate-limited; batch node IDs where supported.
112
+ - Large responses may be truncated; narrow to a specific child node when needed.
113
+ - This integration is read-only and cannot modify Figma files.
@@ -0,0 +1,6 @@
1
+ import { createTtlCache } from "pi-common/cache";
2
+
3
+ export const figmaCache = createTtlCache<unknown>({
4
+ defaultTtlMs: 5 * 60 * 1000,
5
+ maxEntries: 100,
6
+ });