Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
ROADMAP.mdalready 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) publishesAnnotationsTraitas an emptyobject— theannotationsfield 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 rawGET /v1/files/:key/nodesresponse 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? }— preferringlabelMarkdownoverlabelwhen both are present, and dropping the property wrapper objects for token efficiency.src/extractors/built-in.ts: newannotationExtractor, added toallExtractorsso it's included by default inget_figma_dataoutput.src/extractors/types.ts: addedannotations?: SimplifiedAnnotation[]toSimplifiedNode.src/utils/serialize-tree.ts: addedannotations=rendering to the default tree output format.src/extractors/index.ts/src/index.tsexport barrels, updatedsrc/extractors/README.md, and checked off the correspondingROADMAP.mditem.Testing
annotationExtractor(label/labelMarkdown precedence, pinned properties, omission when absent) insrc/tests/tree-walker.test.ts.src/tests/serialization.test.tsfor 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.simplifyRawFigmaObject→serializeResult(..., "tree"), confirming the annotation text survives all the way to the actual string theget_figma_datatool returns.pnpm test,pnpm type-check,pnpm lint,pnpm prettier --check, andnode scripts/scan-hidden-chars.mjsall pass.Scope note
This only covers reading annotations (surfacing them in
get_figma_dataoutput), 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.