figma-cli 0.3.0__tar.gz → 0.4.0__tar.gz

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.
@@ -30,14 +30,19 @@ jobs:
30
30
  run: pytest tests/
31
31
 
32
32
  live:
33
- # Runs against the real Figma API when the FIGMA_TOKEN secret is configured;
34
- # the tests skip cleanly when it is absent (forks, unconfigured repos).
33
+ # Runs against the real Figma API when the FIGMA_TOKEN (and, for OAuth, the
34
+ # FIGMA_OAUTH_REFRESH_TOKEN, FIGMA_CLIENT_ID and FIGMA_CLIENT_SECRET) secrets are
35
+ # configured; the tests skip cleanly when they are absent (forks, unconfigured).
35
36
  runs-on: ubuntu-latest
36
37
  needs: test
37
38
  env:
38
39
  FIGMA_TOKEN: ${{ secrets.FIGMA_TOKEN }}
39
40
  FIGMA_TEST_FILE_KEY: ${{ vars.FIGMA_TEST_FILE_KEY }}
40
41
  FIGMA_TEST_NODE_ID: ${{ vars.FIGMA_TEST_NODE_ID }}
42
+ # A dedicated test OAuth app: each refresh invalidates its last access token.
43
+ FIGMA_OAUTH_REFRESH_TOKEN: ${{ secrets.FIGMA_OAUTH_REFRESH_TOKEN }}
44
+ FIGMA_CLIENT_ID: ${{ secrets.FIGMA_CLIENT_ID }}
45
+ FIGMA_CLIENT_SECRET: ${{ secrets.FIGMA_CLIENT_SECRET }}
41
46
  steps:
42
47
  - uses: actions/checkout@v5
43
48
  with:
@@ -6,3 +6,4 @@ __pycache__/
6
6
  .pytest_cache/
7
7
  .ruff_cache/
8
8
  tmp/
9
+ .coverage
@@ -0,0 +1,246 @@
1
+ Metadata-Version: 2.5
2
+ Name: figma-cli
3
+ Version: 0.4.0
4
+ Summary: Headless Figma CLI for AI coding agents and automated design inspection.
5
+ Project-URL: Homepage, https://github.com/imperfect-co/figma-cli
6
+ Project-URL: Issues, https://github.com/imperfect-co/figma-cli/issues
7
+ Author: imperfect-co
8
+ License-Expression: MIT
9
+ License-File: LICENSE
10
+ Classifier: Environment :: Console
11
+ Classifier: Operating System :: OS Independent
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Programming Language :: Python :: 3 :: Only
14
+ Classifier: Programming Language :: Python :: 3.11
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Programming Language :: Python :: 3.13
17
+ Classifier: Programming Language :: Python :: 3.14
18
+ Requires-Python: >=3.11
19
+ Provides-Extra: dev
20
+ Requires-Dist: build; extra == 'dev'
21
+ Requires-Dist: pytest; extra == 'dev'
22
+ Requires-Dist: ruff; extra == 'dev'
23
+ Requires-Dist: twine>=6.1.0; extra == 'dev'
24
+ Description-Content-Type: text/markdown
25
+
26
+ # figma-cli
27
+
28
+ Headless Figma CLI for AI coding agents and automated design inspection.
29
+
30
+ Requires Python 3.11 or newer. Licensed under MIT.
31
+
32
+ ## Commands
33
+
34
+ The package installs two console scripts that run the same entrypoint:
35
+
36
+ - `figma-cli`
37
+ - `figma` (short alias)
38
+
39
+ Each reports its own name in `--help` and `--version`:
40
+
41
+ ```console
42
+ $ figma-cli --version
43
+ figma-cli 0.1.0
44
+ $ figma --version
45
+ figma 0.1.0
46
+ ```
47
+
48
+ The npm package `silships/figma-cli` also installs a `figma-cli` executable. If both are installed, whichever directory comes first on `PATH` wins. Run `command -v figma-cli` to check which one you get, or use the `figma` alias.
49
+
50
+ ## Usage
51
+
52
+ Every command talks to the Figma REST API with either a personal access token or an OAuth token from your own Figma OAuth app (see [OAuth login](#oauth-login)). Create a personal access token under Figma account settings (Security > Personal access tokens) with these scopes, the minimum the commands below need per [Figma's scope reference](https://developers.figma.com/docs/rest-api/scopes/):
53
+
54
+ | Scope | Used by |
55
+ | --- | --- |
56
+ | `current_user:read` | `auth check`, `auth login` (`GET /v1/me`) |
57
+ | `file_content:read` | `file get`, `node get`, `export` |
58
+ | `file_comments:read` | `comment list` |
59
+ | `file_comments:write` | `comment post`, `comment delete` |
60
+ | `file_variables:read` | `variable list` (Figma Enterprise only, see below) |
61
+
62
+ The Variables REST API is available only to full members of Figma Enterprise organizations, and the token needs `file_variables:read`. Anywhere else, `variable list` exits 3 with `{"error": "forbidden", "status": 403}`; the other commands do not need this scope.
63
+
64
+ Then store it once with `figma auth login`:
65
+
66
+ ```sh
67
+ figma auth login # interactive: browser OAuth if configured, else PAT steps and hidden prompt
68
+ echo "$TOKEN" | figma auth login # agents and CI: piped stdin
69
+ figma auth login --token - < token.txt # same, explicit
70
+ ```
71
+
72
+ `auth login` validates the token against `GET /v1/me` before writing anything. A rejected token exits 3 and leaves any existing token file untouched. A valid one is written to `~/.config/figma/token` with mode `0600` (its directory `0700`), through a temporary file renamed into place, so a failed write keeps the previous token, and the command reports the authenticated `id`, `handle` and `email` plus the file path. Prefer stdin over `--token <value>`, which exposes the token in process listings and shell history. Empty stdin exits 2. Without OAuth client credentials, the interactive prompt first explains how to enable 1-click browser login (export `FIGMA_CLIENT_ID` and `FIGMA_CLIENT_SECRET`, see [OAuth login](#oauth-login)), then lists the personal access token steps. Add `--no-browser` to skip opening the settings page.
73
+
74
+ `auth login` takes this personal access token path whenever `--token` is given, stdin is piped, or no OAuth client credentials are configured. Saving a personal access token also removes `~/.config/figma/token.json`, so stale OAuth tokens never shadow it.
75
+
76
+ Alternatively, export the token. `FIGMA_TOKEN` takes precedence over the stored files whenever it is set and non-empty. A value starting `figu_` (an OAuth access token) is sent as `Authorization: Bearer`, anything else as `X-Figma-Token`:
77
+
78
+ ```sh
79
+ export FIGMA_TOKEN=figd_...
80
+ export FIGMA_API_BASE=https://api.figma.com # optional, this is the default
81
+ ```
82
+
83
+ Credentials resolve in this order: `FIGMA_TOKEN`, then `~/.config/figma/token.json` (OAuth), then `~/.config/figma/token` (personal access token). With none of them, commands fail with `{"error": "missing_token"}` and exit code 3.
84
+
85
+ ### OAuth login
86
+
87
+ figma-cli ships no OAuth app of its own: Figma authenticates the client with its secret on every token call, and a secret embedded in an open-source package is not a secret. Bring your own:
88
+
89
+ 1. Create an OAuth app in the [Figma developer console](https://www.figma.com/developers/apps) and register the redirect URL `http://127.0.0.1:54321/callback`. Grant it the scopes above (`file_variables:read` only on Enterprise).
90
+ 2. Export its credentials and log in from an interactive terminal:
91
+
92
+ ```sh
93
+ export FIGMA_CLIENT_ID=...
94
+ export FIGMA_CLIENT_SECRET=...
95
+ figma auth login # opens the browser, waits on 127.0.0.1:54321
96
+ figma auth login --port 8765 # if you registered http://127.0.0.1:8765/callback instead
97
+ ```
98
+
99
+ `--client-id` and `--client-secret` override the variables, but a literal secret shows in process listings and shell history. The flow uses PKCE (S256) and a random `state`; a callback with the wrong `state` is answered with HTTP 400 and ignored. Because Figma matches redirect URLs exactly, a busy port is not swapped for another one: the command exits 2 with `{"error": "port_unavailable"}`. Add `--no-browser` to print the authorization URL without opening it.
100
+
101
+ Over SSH, in a container, or anywhere the browser runs on another machine, its redirect to `127.0.0.1` never reaches figma-cli. While it waits, the command reads the terminal: after authorizing, copy the full URL from the browser's address bar (the page itself fails to load) and paste it at the `Paste the callback URL here` prompt. A `code=...&state=...` query string works too. The paste is held to the same checks as the browser redirect: the path must be `/callback` on the configured port and `state` must match, so a bare code without `state` is refused. A rejected paste is explained and the prompt returns while the loopback server keeps listening.
102
+
103
+ The access token is checked against `GET /v1/me`, then the access token, refresh token, expiry, client id and client secret are written to `~/.config/figma/token.json` (mode `0600`, directory `0700`, atomic replace). Figma access tokens last 90 days. When the stored one has expired, the next command refreshes it through `POST /v1/oauth/refresh` before running. The refresh holds an advisory lock on `~/.config/figma/token.json.lock` and re-reads the file once it has the lock, so concurrent commands refresh once rather than invalidating each other's tokens (Windows has no `fcntl`, so there the refresh runs unlocked). A refresh Figma rejects exits 3 with `{"error": "refresh_failed"}` rather than falling back to an older personal access token; run `figma auth login` again.
104
+
105
+ Every subcommand prints human-readable text by default and a JSON document on stdout with `--json`.
106
+
107
+ | Command | Figma endpoint |
108
+ | --- | --- |
109
+ | `figma auth login [--token TOKEN\|-] [--no-browser]` | `GET /v1/me`, then writes `~/.config/figma/token` |
110
+ | `figma auth login [--client-id ID] [--client-secret SECRET] [--port PORT]` | OAuth: `POST /v1/oauth/token`, `GET /v1/me`, then writes `~/.config/figma/token.json` |
111
+ | `figma auth check` | `GET /v1/me` |
112
+ | `figma file get <file_key> [--depth N]` | `GET /v1/files/{file_key}?depth=N` |
113
+ | `figma node get <file_key> --nodes <ids> [--depth N] [--geometry paths]` | `GET /v1/files/{file_key}/nodes?ids=<ids>&depth=N&geometry=paths` |
114
+ | `figma variable list <file_key> [--published]` | `GET /v1/files/{file_key}/variables/local`, or `/variables/published` with `--published` |
115
+ | `figma export <file_key> --nodes <ids> [--format png\|svg] [--output DIR]` | `GET /v1/images/{file_key}`, then the asset URLs |
116
+ | `figma comment list <file_key>` | `GET /v1/files/{file_key}/comments` |
117
+ | `figma comment post <file_key> --message TEXT [--comment-id ID] [--node-id ID]` | `POST /v1/files/{file_key}/comments` |
118
+ | `figma comment delete <file_key> <comment_id>` | `DELETE /v1/files/{file_key}/comments/{comment_id}` |
119
+
120
+ The file key is the segment after `/design/` (or `/file/`) in a Figma URL. Node ids use the `1:2` form; a URL shows them as `node-id=1-2`.
121
+
122
+ ### Examples
123
+
124
+ Check the token:
125
+
126
+ ```console
127
+ $ figma auth check --json
128
+ {
129
+ "id": "123456789",
130
+ "handle": "Design Bot",
131
+ "email": "bot@example.com"
132
+ }
133
+ ```
134
+
135
+ Inspect only the pages of a file. `--depth` is passed to Figma, so the server trims the tree before it is sent:
136
+
137
+ ```sh
138
+ figma file get AbCdEf123 --depth 1
139
+ figma file get AbCdEf123 --depth 2 --json | jq '.document.children[].name'
140
+ ```
141
+
142
+ Fetch only the subtrees you need instead of the whole file. Ids Figma cannot find come back as `null` in the JSON and as a `not found` line in the text output; the command still exits 0:
143
+
144
+ ```console
145
+ $ figma node get AbCdEf123 --nodes 1:2,9:9 --depth 1
146
+ Spec (last modified 2026-01-01T00:00:00Z)
147
+ FRAME Card (1:2)
148
+ TEXT Title (1:3)
149
+ Node 9:9: not found
150
+ ```
151
+
152
+ `--geometry paths` adds vector path data to each node. With `--json`, the response is Figma's unchanged, keyed by node id under `nodes`.
153
+
154
+ List the design variables in a file, one collection per block with each variable's resolved type and its value in every mode (colors as hex, aliases as `-> <name>`, or `-> <id>` when the aliased variable is not in the response, such as one from a library). `--published` lists the variables this file publishes to its library instead; Figma returns no per-mode values for those:
155
+
156
+ ```console
157
+ $ figma variable list AbCdEf123
158
+ Colors (VariableCollectionId:1:1) [modes: Light, Dark]
159
+ brand/primary COLOR Light=#FF0000 Dark=#00000080
160
+ text/default COLOR Light=-> brand/primary Dark=-> VariableID:9:9
161
+ radius FLOAT Light=4 Dark=8
162
+ ```
163
+
164
+ Render two frames to PNG and print where they were written. Files are named `<file_key>_<node_id>.<format>` with `:` and other unsafe characters replaced by `-`; re-exporting the same node overwrites its file:
165
+
166
+ ```console
167
+ $ figma export AbCdEf123 --nodes 1:2,1:3 --output shots
168
+ shots/AbCdEf123_1-2.png
169
+ shots/AbCdEf123_1-3.png
170
+ ```
171
+
172
+ Post a comment pinned to a frame, reply to it, list the thread, then clean up:
173
+
174
+ ```sh
175
+ id=$(figma comment post AbCdEf123 --message "Spacing is off" --node-id 1:2 --json | jq -r .id)
176
+ figma comment post AbCdEf123 --message "Fixed in the next build" --comment-id "$id"
177
+ figma comment list AbCdEf123
178
+ figma comment delete AbCdEf123 "$id"
179
+ ```
180
+
181
+ ### Errors and exit codes
182
+
183
+ | Exit code | Meaning |
184
+ | --- | --- |
185
+ | 0 | Success |
186
+ | 2 | Usage error (bad or missing arguments) |
187
+ | 3 | Figma API, network, or local write failure |
188
+
189
+ With `--json`, a failure prints a JSON object on stdout; without it, a one-line message goes to stderr. HTTP 401, 403, 404 and 5xx become `unauthorized`, `forbidden`, `not_found` and `server_error`:
190
+
191
+ ```json
192
+ {"error": "forbidden", "status": 403, "message": "Invalid token"}
193
+ ```
194
+
195
+ HTTP 429 is reported at once, never retried, so the caller decides when to try again. `retry_after` comes from the `Retry-After` header and is `null` when Figma sends none:
196
+
197
+ ```json
198
+ {"error": "rate_limit_exceeded", "status": 429, "retry_after": 30}
199
+ ```
200
+
201
+ ### Token safety
202
+
203
+ A request carrying a credential (`X-Figma-Token`, `Authorization: Bearer`, or the `Authorization: Basic` client credentials on the OAuth token calls) follows no redirects. Any 3xx answer is refused with `{"error": "redirect_refused"}` and exit code 3 before a second request is made, so the credential never reaches another host. Exported images are downloaded from the pre-signed URLs Figma returns with a separate request that carries no token; only that request follows redirects.
204
+
205
+ ## Installation and quick run
206
+
207
+ Run on-demand without installing via [uv](https://docs.astral.sh/uv/):
208
+
209
+ ```sh
210
+ uvx figma-cli --help
211
+ uvx figma-cli auth check --json
212
+ ```
213
+
214
+ Or install from [PyPI](https://pypi.org/project/figma-cli/):
215
+
216
+ ```sh
217
+ pip install figma-cli
218
+ ```
219
+
220
+ From a local checkout:
221
+
222
+ ```sh
223
+ uvx --from . figma-cli --version
224
+ ```
225
+
226
+ ## Development
227
+
228
+ ```sh
229
+ python -m venv .venv && . .venv/bin/activate
230
+ pip install -e ".[dev]"
231
+ ruff check .
232
+ ruff format --check .
233
+ pytest tests/
234
+ ```
235
+
236
+ The tests are hermetic: no network access and no Figma token are needed, and `HOME` points at a temporary directory so a stored token never leaks in. The redirect tests use real sockets on `127.0.0.1`.
237
+
238
+ `tests/test_live.py` runs against the real API only when `FIGMA_TOKEN` is set. With the token alone it checks `auth check` and runs `auth login` from stdin into a temporary `HOME`; the file, comment, export, node and variable checks also need `FIGMA_TEST_FILE_KEY` (add `FIGMA_TEST_NODE_ID` to exercise export and `node get`). The `node get` check also asserts the call takes under 2 seconds and returns less than `file get` does on the same file. The variable check passes on either outcome the plan allows: collections on an Enterprise token, or exit 3 `forbidden` elsewhere. The comment check posts one comment and deletes it. CI runs it in the `live` job from the `FIGMA_TOKEN` secret and the `FIGMA_TEST_FILE_KEY` / `FIGMA_TEST_NODE_ID` repository variables, and skips it when they are absent.
239
+
240
+ ## Release
241
+
242
+ Bump `__version__` in `src/figma_cli/__init__.py`, merge, then push a matching tag (`v0.1.0` for `0.1.0`). The release workflow refuses a tag that does not match `__version__`, builds the sdist and wheel, runs `twine check`, and publishes to PyPI through trusted publishing (OIDC, the `pypi` environment).
243
+
244
+ ## License
245
+
246
+ MIT, see [LICENSE](LICENSE).
@@ -0,0 +1,221 @@
1
+ # figma-cli
2
+
3
+ Headless Figma CLI for AI coding agents and automated design inspection.
4
+
5
+ Requires Python 3.11 or newer. Licensed under MIT.
6
+
7
+ ## Commands
8
+
9
+ The package installs two console scripts that run the same entrypoint:
10
+
11
+ - `figma-cli`
12
+ - `figma` (short alias)
13
+
14
+ Each reports its own name in `--help` and `--version`:
15
+
16
+ ```console
17
+ $ figma-cli --version
18
+ figma-cli 0.1.0
19
+ $ figma --version
20
+ figma 0.1.0
21
+ ```
22
+
23
+ The npm package `silships/figma-cli` also installs a `figma-cli` executable. If both are installed, whichever directory comes first on `PATH` wins. Run `command -v figma-cli` to check which one you get, or use the `figma` alias.
24
+
25
+ ## Usage
26
+
27
+ Every command talks to the Figma REST API with either a personal access token or an OAuth token from your own Figma OAuth app (see [OAuth login](#oauth-login)). Create a personal access token under Figma account settings (Security > Personal access tokens) with these scopes, the minimum the commands below need per [Figma's scope reference](https://developers.figma.com/docs/rest-api/scopes/):
28
+
29
+ | Scope | Used by |
30
+ | --- | --- |
31
+ | `current_user:read` | `auth check`, `auth login` (`GET /v1/me`) |
32
+ | `file_content:read` | `file get`, `node get`, `export` |
33
+ | `file_comments:read` | `comment list` |
34
+ | `file_comments:write` | `comment post`, `comment delete` |
35
+ | `file_variables:read` | `variable list` (Figma Enterprise only, see below) |
36
+
37
+ The Variables REST API is available only to full members of Figma Enterprise organizations, and the token needs `file_variables:read`. Anywhere else, `variable list` exits 3 with `{"error": "forbidden", "status": 403}`; the other commands do not need this scope.
38
+
39
+ Then store it once with `figma auth login`:
40
+
41
+ ```sh
42
+ figma auth login # interactive: browser OAuth if configured, else PAT steps and hidden prompt
43
+ echo "$TOKEN" | figma auth login # agents and CI: piped stdin
44
+ figma auth login --token - < token.txt # same, explicit
45
+ ```
46
+
47
+ `auth login` validates the token against `GET /v1/me` before writing anything. A rejected token exits 3 and leaves any existing token file untouched. A valid one is written to `~/.config/figma/token` with mode `0600` (its directory `0700`), through a temporary file renamed into place, so a failed write keeps the previous token, and the command reports the authenticated `id`, `handle` and `email` plus the file path. Prefer stdin over `--token <value>`, which exposes the token in process listings and shell history. Empty stdin exits 2. Without OAuth client credentials, the interactive prompt first explains how to enable 1-click browser login (export `FIGMA_CLIENT_ID` and `FIGMA_CLIENT_SECRET`, see [OAuth login](#oauth-login)), then lists the personal access token steps. Add `--no-browser` to skip opening the settings page.
48
+
49
+ `auth login` takes this personal access token path whenever `--token` is given, stdin is piped, or no OAuth client credentials are configured. Saving a personal access token also removes `~/.config/figma/token.json`, so stale OAuth tokens never shadow it.
50
+
51
+ Alternatively, export the token. `FIGMA_TOKEN` takes precedence over the stored files whenever it is set and non-empty. A value starting `figu_` (an OAuth access token) is sent as `Authorization: Bearer`, anything else as `X-Figma-Token`:
52
+
53
+ ```sh
54
+ export FIGMA_TOKEN=figd_...
55
+ export FIGMA_API_BASE=https://api.figma.com # optional, this is the default
56
+ ```
57
+
58
+ Credentials resolve in this order: `FIGMA_TOKEN`, then `~/.config/figma/token.json` (OAuth), then `~/.config/figma/token` (personal access token). With none of them, commands fail with `{"error": "missing_token"}` and exit code 3.
59
+
60
+ ### OAuth login
61
+
62
+ figma-cli ships no OAuth app of its own: Figma authenticates the client with its secret on every token call, and a secret embedded in an open-source package is not a secret. Bring your own:
63
+
64
+ 1. Create an OAuth app in the [Figma developer console](https://www.figma.com/developers/apps) and register the redirect URL `http://127.0.0.1:54321/callback`. Grant it the scopes above (`file_variables:read` only on Enterprise).
65
+ 2. Export its credentials and log in from an interactive terminal:
66
+
67
+ ```sh
68
+ export FIGMA_CLIENT_ID=...
69
+ export FIGMA_CLIENT_SECRET=...
70
+ figma auth login # opens the browser, waits on 127.0.0.1:54321
71
+ figma auth login --port 8765 # if you registered http://127.0.0.1:8765/callback instead
72
+ ```
73
+
74
+ `--client-id` and `--client-secret` override the variables, but a literal secret shows in process listings and shell history. The flow uses PKCE (S256) and a random `state`; a callback with the wrong `state` is answered with HTTP 400 and ignored. Because Figma matches redirect URLs exactly, a busy port is not swapped for another one: the command exits 2 with `{"error": "port_unavailable"}`. Add `--no-browser` to print the authorization URL without opening it.
75
+
76
+ Over SSH, in a container, or anywhere the browser runs on another machine, its redirect to `127.0.0.1` never reaches figma-cli. While it waits, the command reads the terminal: after authorizing, copy the full URL from the browser's address bar (the page itself fails to load) and paste it at the `Paste the callback URL here` prompt. A `code=...&state=...` query string works too. The paste is held to the same checks as the browser redirect: the path must be `/callback` on the configured port and `state` must match, so a bare code without `state` is refused. A rejected paste is explained and the prompt returns while the loopback server keeps listening.
77
+
78
+ The access token is checked against `GET /v1/me`, then the access token, refresh token, expiry, client id and client secret are written to `~/.config/figma/token.json` (mode `0600`, directory `0700`, atomic replace). Figma access tokens last 90 days. When the stored one has expired, the next command refreshes it through `POST /v1/oauth/refresh` before running. The refresh holds an advisory lock on `~/.config/figma/token.json.lock` and re-reads the file once it has the lock, so concurrent commands refresh once rather than invalidating each other's tokens (Windows has no `fcntl`, so there the refresh runs unlocked). A refresh Figma rejects exits 3 with `{"error": "refresh_failed"}` rather than falling back to an older personal access token; run `figma auth login` again.
79
+
80
+ Every subcommand prints human-readable text by default and a JSON document on stdout with `--json`.
81
+
82
+ | Command | Figma endpoint |
83
+ | --- | --- |
84
+ | `figma auth login [--token TOKEN\|-] [--no-browser]` | `GET /v1/me`, then writes `~/.config/figma/token` |
85
+ | `figma auth login [--client-id ID] [--client-secret SECRET] [--port PORT]` | OAuth: `POST /v1/oauth/token`, `GET /v1/me`, then writes `~/.config/figma/token.json` |
86
+ | `figma auth check` | `GET /v1/me` |
87
+ | `figma file get <file_key> [--depth N]` | `GET /v1/files/{file_key}?depth=N` |
88
+ | `figma node get <file_key> --nodes <ids> [--depth N] [--geometry paths]` | `GET /v1/files/{file_key}/nodes?ids=<ids>&depth=N&geometry=paths` |
89
+ | `figma variable list <file_key> [--published]` | `GET /v1/files/{file_key}/variables/local`, or `/variables/published` with `--published` |
90
+ | `figma export <file_key> --nodes <ids> [--format png\|svg] [--output DIR]` | `GET /v1/images/{file_key}`, then the asset URLs |
91
+ | `figma comment list <file_key>` | `GET /v1/files/{file_key}/comments` |
92
+ | `figma comment post <file_key> --message TEXT [--comment-id ID] [--node-id ID]` | `POST /v1/files/{file_key}/comments` |
93
+ | `figma comment delete <file_key> <comment_id>` | `DELETE /v1/files/{file_key}/comments/{comment_id}` |
94
+
95
+ The file key is the segment after `/design/` (or `/file/`) in a Figma URL. Node ids use the `1:2` form; a URL shows them as `node-id=1-2`.
96
+
97
+ ### Examples
98
+
99
+ Check the token:
100
+
101
+ ```console
102
+ $ figma auth check --json
103
+ {
104
+ "id": "123456789",
105
+ "handle": "Design Bot",
106
+ "email": "bot@example.com"
107
+ }
108
+ ```
109
+
110
+ Inspect only the pages of a file. `--depth` is passed to Figma, so the server trims the tree before it is sent:
111
+
112
+ ```sh
113
+ figma file get AbCdEf123 --depth 1
114
+ figma file get AbCdEf123 --depth 2 --json | jq '.document.children[].name'
115
+ ```
116
+
117
+ Fetch only the subtrees you need instead of the whole file. Ids Figma cannot find come back as `null` in the JSON and as a `not found` line in the text output; the command still exits 0:
118
+
119
+ ```console
120
+ $ figma node get AbCdEf123 --nodes 1:2,9:9 --depth 1
121
+ Spec (last modified 2026-01-01T00:00:00Z)
122
+ FRAME Card (1:2)
123
+ TEXT Title (1:3)
124
+ Node 9:9: not found
125
+ ```
126
+
127
+ `--geometry paths` adds vector path data to each node. With `--json`, the response is Figma's unchanged, keyed by node id under `nodes`.
128
+
129
+ List the design variables in a file, one collection per block with each variable's resolved type and its value in every mode (colors as hex, aliases as `-> <name>`, or `-> <id>` when the aliased variable is not in the response, such as one from a library). `--published` lists the variables this file publishes to its library instead; Figma returns no per-mode values for those:
130
+
131
+ ```console
132
+ $ figma variable list AbCdEf123
133
+ Colors (VariableCollectionId:1:1) [modes: Light, Dark]
134
+ brand/primary COLOR Light=#FF0000 Dark=#00000080
135
+ text/default COLOR Light=-> brand/primary Dark=-> VariableID:9:9
136
+ radius FLOAT Light=4 Dark=8
137
+ ```
138
+
139
+ Render two frames to PNG and print where they were written. Files are named `<file_key>_<node_id>.<format>` with `:` and other unsafe characters replaced by `-`; re-exporting the same node overwrites its file:
140
+
141
+ ```console
142
+ $ figma export AbCdEf123 --nodes 1:2,1:3 --output shots
143
+ shots/AbCdEf123_1-2.png
144
+ shots/AbCdEf123_1-3.png
145
+ ```
146
+
147
+ Post a comment pinned to a frame, reply to it, list the thread, then clean up:
148
+
149
+ ```sh
150
+ id=$(figma comment post AbCdEf123 --message "Spacing is off" --node-id 1:2 --json | jq -r .id)
151
+ figma comment post AbCdEf123 --message "Fixed in the next build" --comment-id "$id"
152
+ figma comment list AbCdEf123
153
+ figma comment delete AbCdEf123 "$id"
154
+ ```
155
+
156
+ ### Errors and exit codes
157
+
158
+ | Exit code | Meaning |
159
+ | --- | --- |
160
+ | 0 | Success |
161
+ | 2 | Usage error (bad or missing arguments) |
162
+ | 3 | Figma API, network, or local write failure |
163
+
164
+ With `--json`, a failure prints a JSON object on stdout; without it, a one-line message goes to stderr. HTTP 401, 403, 404 and 5xx become `unauthorized`, `forbidden`, `not_found` and `server_error`:
165
+
166
+ ```json
167
+ {"error": "forbidden", "status": 403, "message": "Invalid token"}
168
+ ```
169
+
170
+ HTTP 429 is reported at once, never retried, so the caller decides when to try again. `retry_after` comes from the `Retry-After` header and is `null` when Figma sends none:
171
+
172
+ ```json
173
+ {"error": "rate_limit_exceeded", "status": 429, "retry_after": 30}
174
+ ```
175
+
176
+ ### Token safety
177
+
178
+ A request carrying a credential (`X-Figma-Token`, `Authorization: Bearer`, or the `Authorization: Basic` client credentials on the OAuth token calls) follows no redirects. Any 3xx answer is refused with `{"error": "redirect_refused"}` and exit code 3 before a second request is made, so the credential never reaches another host. Exported images are downloaded from the pre-signed URLs Figma returns with a separate request that carries no token; only that request follows redirects.
179
+
180
+ ## Installation and quick run
181
+
182
+ Run on-demand without installing via [uv](https://docs.astral.sh/uv/):
183
+
184
+ ```sh
185
+ uvx figma-cli --help
186
+ uvx figma-cli auth check --json
187
+ ```
188
+
189
+ Or install from [PyPI](https://pypi.org/project/figma-cli/):
190
+
191
+ ```sh
192
+ pip install figma-cli
193
+ ```
194
+
195
+ From a local checkout:
196
+
197
+ ```sh
198
+ uvx --from . figma-cli --version
199
+ ```
200
+
201
+ ## Development
202
+
203
+ ```sh
204
+ python -m venv .venv && . .venv/bin/activate
205
+ pip install -e ".[dev]"
206
+ ruff check .
207
+ ruff format --check .
208
+ pytest tests/
209
+ ```
210
+
211
+ The tests are hermetic: no network access and no Figma token are needed, and `HOME` points at a temporary directory so a stored token never leaks in. The redirect tests use real sockets on `127.0.0.1`.
212
+
213
+ `tests/test_live.py` runs against the real API only when `FIGMA_TOKEN` is set. With the token alone it checks `auth check` and runs `auth login` from stdin into a temporary `HOME`; the file, comment, export, node and variable checks also need `FIGMA_TEST_FILE_KEY` (add `FIGMA_TEST_NODE_ID` to exercise export and `node get`). The `node get` check also asserts the call takes under 2 seconds and returns less than `file get` does on the same file. The variable check passes on either outcome the plan allows: collections on an Enterprise token, or exit 3 `forbidden` elsewhere. The comment check posts one comment and deletes it. CI runs it in the `live` job from the `FIGMA_TOKEN` secret and the `FIGMA_TEST_FILE_KEY` / `FIGMA_TEST_NODE_ID` repository variables, and skips it when they are absent.
214
+
215
+ ## Release
216
+
217
+ Bump `__version__` in `src/figma_cli/__init__.py`, merge, then push a matching tag (`v0.1.0` for `0.1.0`). The release workflow refuses a tag that does not match `__version__`, builds the sdist and wheel, runs `twine check`, and publishes to PyPI through trusted publishing (OIDC, the `pypi` environment).
218
+
219
+ ## License
220
+
221
+ MIT, see [LICENSE](LICENSE).
@@ -1,3 +1,3 @@
1
1
  """Headless Figma CLI for AI coding agents and automated design inspection."""
2
2
 
3
- __version__ = "0.3.0"
3
+ __version__ = "0.4.0"