understand-figma
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinese/understand-figma
/understand-figma
Analyzes a Figma file and produces an interactive design knowledge graph in the existing dashboard.
分析Figma文件并在现有仪表盘中生成交互式设计知识图谱。
Prerequisites
前置条件
- environment variable — a Figma personal access token (create one at https://www.figma.com/settings). If it is missing, STOP and tell the user:
FIGMA_TOKENSet a Figma token first: create one at figma.com/settings, then.export FIGMA_TOKEN=<token> - Node ≥ 22, pnpm ≥ 10.
Security: the token is read only from the environment and travels only in therequest header. Never write it to the graph,X-Figma-Token, logs, or intermediate files. This skill makes outbound calls tometa.json— unlikeapi.figma.com, it is not fully offline. Tell the user this once./understand
- 环境变量 —— Figma个人访问令牌(可在https://www.figma.com/settings创建)。如果缺失,请停止操作并告知用户:
FIGMA_TOKEN请先设置Figma令牌:在figma.com/settings创建令牌,然后执行。export FIGMA_TOKEN=<token> - Node ≥ 22,pnpm ≥ 10.
安全说明:令牌仅从环境变量读取,且仅通过请求头传输。切勿将其写入图谱、X-Figma-Token、日志或中间文件。该技能会向meta.json发起外部请求 —— 与api.figma.com不同,它并非完全离线。请告知用户这一点。/understand
Phase 0 — Pre-flight
阶段0 —— 预检
- Parse for a Figma URL or bare file key (the non-flag token) and an optional
$ARGUMENTS.--language <lang> - Resolve to the current working directory. Resolve the data directory
PROJECT_ROOTonce and reuse it for every read and write below:$UA_DIR— the legacyUA_DIR="$PROJECT_ROOT/$([ -d "$PROJECT_ROOT/.understand-anything" ] && echo .understand-anything || echo .ua)"when it already exists, otherwise the new.understand-anything/. Because each phase may run in a fresh shell, carry.ua/forward like$UA_DIR, re-resolving it with the same line if a later command block needs it.$PROJECT_ROOT - Resolve and ensure core is built (same logic as
PLUGIN_ROOTPhase 0.1.5). If/understandis missing, run:packages/core/dist/figma/index.jsbashcd "$PLUGIN_ROOT" && (pnpm install --frozen-lockfile 2>/dev/null || pnpm install) && pnpm --filter @understand-anything/core build - .
mkdir -p $UA_DIR/intermediate
- 解析以获取Figma URL或裸文件密钥(非标志令牌),以及可选的
$ARGUMENTS参数。--language <lang> - 将解析为当前工作目录。**解析数据目录
PROJECT_ROOT**一次,并在后续所有读写操作中复用:$UA_DIR—— 如果已存在旧版UA_DIR="$PROJECT_ROOT/$([ -d "$PROJECT_ROOT/.understand-anything" ] && echo .understand-anything || echo .ua)"目录则使用它,否则使用新的.understand-anything/目录。由于每个阶段可能在新的shell中运行,请像传递.ua/一样传递$PROJECT_ROOT,如果后续命令块需要,用相同的行重新解析它。$UA_DIR - 解析并确保核心已构建(与
PLUGIN_ROOT阶段0.1.5的逻辑相同)。如果/understand缺失,运行:packages/core/dist/figma/index.jsbashcd "$PLUGIN_ROOT" && (pnpm install --frozen-lockfile 2>/dev/null || pnpm install) && pnpm --filter @understand-anything/core build - .
mkdir -p $UA_DIR/intermediate
Phase 1 — FETCH & PARSE (deterministic)
阶段1 —— 抓取与解析(确定性)
Run the bundled scan script ( is this skill's directory):
<SKILL_DIR>bash
FIGMA_TOKEN="$FIGMA_TOKEN" node <SKILL_DIR>/figma-scan.mjs "$PROJECT_ROOT" "<url-or-key>"It writes and prints the node counts. Relay the counts to the user. If it exits non-zero, relay stderr and STOP.
$UA_DIR/intermediate/scan-manifest.jsonIf the scan prints, report "Design graph is already up to date for this Figma file version" and STOP. To force a full rebuild, re-run withUP_TO_DATEset in the environment.UNDERSTAND_FIGMA_FORCE=1
运行捆绑的扫描脚本(为该技能的目录):
<SKILL_DIR>bash
FIGMA_TOKEN="$FIGMA_TOKEN" node <SKILL_DIR>/figma-scan.mjs "$PROJECT_ROOT" "<url-or-key>"它会写入并打印节点数量。将数量告知用户。如果脚本非零退出,传递错误信息并停止操作。
$UA_DIR/intermediate/scan-manifest.json如果扫描输出,则报告“此Figma文件版本的设计图谱已为最新”并停止操作。如需强制完全重建,请在环境中设置UP_TO_DATE后重新运行。UNDERSTAND_FIGMA_FORCE=1
Phase 2 — ANALYZE (LLM enrichment)
阶段2 —— 分析(LLM增强)
- Read . Group nodes into batches of ~15, grouped by page when possible.
scan-manifest.json - For each batch, dispatch a subagent using the agent definition (
design-analyzer). Pass:agents/design-analyzer.md- the batch of nodes (,
id,type,name, child names, token usage),figmaMeta - the full list of existing node IDs,
- ,
$INTERMEDIATE_DIR = $UA_DIR/intermediate - the batch number for output naming.
The agent writes . Append
analysis-batch-<N>.jsonif$LANGUAGE_DIRECTIVEwas provided (reuse--language's directive text)./understand
- the batch of nodes (
- Run up to 5 batches concurrently. If a batch fails, log a warning and continue — the manifest is a solid base.
- 读取。将节点分组为约15个一批的批次,尽可能按页面分组。
scan-manifest.json - 对每个批次,使用代理定义(
design-analyzer)调度子代理。传递:agents/design-analyzer.md- 节点批次(包含、
id、type、name、子节点名称、令牌使用情况),figmaMeta - 现有节点ID的完整列表,
- ,
$INTERMEDIATE_DIR = $UA_DIR/intermediate - 批次编号用于输出命名。
代理会写入。 如果提供了
analysis-batch-<N>.json参数,追加--language(复用$LANGUAGE_DIRECTIVE的指令文本)。/understand
- 节点批次(包含
- 最多同时运行5个批次。如果某个批次失败,记录警告并继续操作 —— 扫描清单是可靠的基础。
Phase 3 — MERGE
阶段3 —— 合并
bash
node <SKILL_DIR>/figma-merge.mjs "$PROJECT_ROOT"It combines + , runs (validates, re-attaches ), and writes + . Relay the printed stats and any non- issues.
scan-manifest.jsonanalysis-batch-*.jsonmergeDesignGraphkind:"design"knowledge-graph.jsonmeta.jsonauto-correctedbash
node <SKILL_DIR>/figma-merge.mjs "$PROJECT_ROOT"它会合并 + ,运行(验证并重新附加),并写入 + 。传递打印的统计信息以及所有非的问题。
scan-manifest.jsonanalysis-batch-*.jsonmergeDesignGraphkind:"design"knowledge-graph.jsonmeta.jsonauto-correctedPhase 4 — SAVE & LAUNCH
阶段4 —— 保存与启动
- Clean up intermediate files except :
scan-manifest.jsonbashINTER="$UA_DIR/intermediate" find "$INTER" -mindepth 1 -maxdepth 1 -not -name 'scan-manifest.json' -exec rm -rf {} + - Report a summary: project name, counts by node type, edges by type, layers, tour steps, and the path .
$UA_DIR/knowledge-graph.json - Auto-launch the dashboard by invoking the skill.
/understand-dashboard
- 清理中间文件除了:
scan-manifest.jsonbashINTER="$UA_DIR/intermediate" find "$INTER" -mindepth 1 -maxdepth 1 -not -name 'scan-manifest.json' -exec rm -rf {} + - 报告摘要:项目名称、按节点类型统计的数量、按类型统计的边数、图层、引导步骤,以及路径。
$UA_DIR/knowledge-graph.json - 通过调用技能自动启动仪表盘。
/understand-dashboard