Skip to content

feat: extract and surface Dev Mode annotations - #425

Open
qqqq5953 wants to merge 1 commit into
GLips:mainfrom
qqqq5953:feat/dev-mode-annotations
Open

qqqq5953 wants to merge 1 commit into
GLips:mainfrom
qqqq5953:feat/dev-mode-annotations

Conversation

@qqqq5953

@qqqq5953 qqqq5953 commented Sep 7, 2026

Copy link
Copy Markdown

Motivation

ROADMAP.md already listed this as an open item: "Investigate feasibility of pulling in annotations via the Figma API." This PR implements it.

Background

@figma/rest-api-spec (v0.37.0) publishes AnnotationsTrait as an empty object — the annotations field on nodes isn't typed at all in the generated spec. However, the live Figma REST API does return it on nodes that carry a Dev Mode annotation. I verified this against a real Figma file with an existing annotation — the raw GET /v1/files/:key/nodes response actually contains "annotations": [{ "label": "..." }] on the relevant node — so this isn't based on documentation alone, it's confirmed against live API responses.

What changed

  • src/transformers/annotation.ts (new): models the real wire shape (label, labelMarkdown, properties[].type, categoryId) since the spec package doesn't, and simplifies it to { label?, properties?: string[], categoryId? } — preferring labelMarkdown over label when both are present, and dropping the property wrapper objects for token efficiency.
  • src/extractors/built-in.ts: new annotationExtractor, added to allExtractors so it's included by default in get_figma_data output.
  • src/extractors/types.ts: added annotations?: SimplifiedAnnotation[] to SimplifiedNode.
  • src/utils/serialize-tree.ts: added annotations= rendering to the default tree output format.
  • Wired through the src/extractors/index.ts / src/index.ts export barrels, updated src/extractors/README.md, and checked off the corresponding ROADMAP.md item.

Testing

  • Added unit tests for annotationExtractor (label/labelMarkdown precedence, pinned properties, omission when absent) in src/tests/tree-walker.test.ts.
  • Added a regression test in src/tests/serialization.test.ts for the tree-format serializer — the field is easy to add to the extractor/type and forget to wire into the tree renderer's field whitelist, which is exactly what happened during my own testing before I caught it.
  • Manually validated end-to-end against a live Figma file with an existing Dev Mode annotation: raw REST API response → simplifyRawFigmaObjectserializeResult(..., "tree"), confirming the annotation text survives all the way to the actual string the get_figma_data tool returns.
  • pnpm test, pnpm type-check, pnpm lint, pnpm prettier --check, and node scripts/scan-hidden-chars.mjs all pass.

Scope note

This only covers reading annotations (surfacing them in get_figma_data output), matching this project's read-only REST API architecture. There's no REST endpoint to write annotations back — only the Figma plugin API supports that — so this PR doesn't attempt it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants