/** * figma_tokens — design tokens registered as styles in the file. * * v1 returns names + descriptions (cheap, works on any file). Value * resolution for FILL styles requires an additional per-style node fetch and * is deferred to v0.2 to keep this tool's cost predictable. */ import { Type } from "@sinclair/typebox"; import { defineTool } from "@mariozechner/pi-coding-agent"; import { getFile, parseFileKey } from "../client.js"; import { buildTokenBundle } from "../transforms.js"; export const tokensTool = defineTool({ name: "figma_tokens", label: "Figma Tokens", description: "List design tokens (color/text/effect/grid styles) registered in a Figma file. Useful for design-system audits and naming-convention checks.", promptSnippet: "figma_tokens(file) — registered styles (colors/text/effects/grids), names only.", promptGuidelines: [ "Color values are not resolved in v1 — if you need a specific hex, call figma_inspect on a consuming node and read its fill.", ], parameters: Type.Object({ file: Type.String({ description: "File key or URL." }), }), async execute(_id, params, signal) { const fileKey = parseFileKey(params.file); const file = await getFile(fileKey, 1, signal); // depth=1 is enough — styles live at top level const bundle = buildTokenBundle(file.styles, file.components); return { content: [ { type: "text" as const, text: JSON.stringify( { file: { name: file.name, key: fileKey, version: file.version }, counts: { colors: bundle.colors.length, text: bundle.text.length, effects: bundle.effects.length, grids: bundle.grids.length, }, tokens: bundle, }, null, 2, ), }, ], details: { fileKey, version: file.version }, }; }, });