figma-cache-toolchain 1.4.3 → 1.4.5

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.
@@ -0,0 +1,199 @@
1
+ # figma-cache-toolchain:团队使用说明(可转发)
2
+
3
+ 本文面向业务仓库里需要使用 Figma 本地缓存的同事,目标是统一最新协作流程:
4
+ - 先读本地缓存,命中即复用;
5
+ - 仅在缺口或明确刷新时调用 Figma MCP;
6
+ - MCP 原始证据先落盘,再执行 `upsert/ensure`;
7
+ - 同轮完成 `validate`,未通过不算完成。
8
+
9
+ ---
10
+
11
+ ## 0. 三句话先记住
12
+
13
+ 1. **缓存优先**:同一节点已有可用缓存时,不重复拉 MCP。
14
+ 2. **证据优先**:当来源是 `figma-mcp`,节点目录必须有 `mcp-raw/` 证据文件,不能只写骨架假成功。
15
+ 3. **校验闭环**:执行 `upsert/ensure` 后必须通过 `figma:cache:validate`,否则不能宣称“缓存已就绪”。
16
+
17
+ ---
18
+
19
+ ## 1. 核心术语速查
20
+
21
+ | 名词 | 一句话解释 |
22
+ |------|------------|
23
+ | `index.json` | 缓存总索引,包含 `items`(节点)与 `flows`(流程关系)。 |
24
+ | `item` | 一个缓存节点记录,键是 `cacheKey`,值包含 `url`、`paths`、`completeness` 等。 |
25
+ | `cacheKey` | 标准唯一键,通常是 `fileKey#nodeId`(无 node 时 `fileKey#__FILE__`)。 |
26
+ | `ensure` | 负责索引与骨架文件,不是 MCP 拉取器。 |
27
+ | `upsert` | 更新或写入缓存记录,常与 MCP 拉取后的落盘联用。 |
28
+ | `validate` | 校验索引结构、证据完整性、流程引用关系。 |
29
+ | `completeness` | 这次希望覆盖的维度集合(如 `layout,text,tokens,...`)。 |
30
+ | `mcp-raw/` | MCP 原始回包目录,作为“来源为 figma-mcp”的审计证据。 |
31
+ | `tokenProxyBytes` | 基于 `mcp-raw-get-design-context.txt` 文件大小的 token 代理指标。 |
32
+ | `flow` | 业务流程关系(多屏顺序/分支),维护在 `index.json.flows`。 |
33
+
34
+ ---
35
+
36
+ ## 2. 一次性接入(仅首次)
37
+
38
+ 按固定顺序执行,避免混淆:
39
+
40
+ ### 步骤 1:安装
41
+
42
+ ```bash
43
+ npm i -D figma-cache-toolchain
44
+ ```
45
+
46
+ ### 步骤 2:初始化 Cursor 模板
47
+
48
+ ```bash
49
+ npx figma-cache cursor init
50
+ ```
51
+
52
+ 这一步会刷新:
53
+ - `.cursor/rules/` 与 `.cursor/skills/`(按安全策略写入/跳过)
54
+ - `figma-cache.config.js`
55
+ - 根目录 `AGENT-SETUP-PROMPT.md`
56
+ - `figma-cache/docs/colleague-guide-zh.md`
57
+
58
+ ### 步骤 3:在 Cursor 中执行任务书
59
+
60
+ 在对话中 `@AGENT-SETUP-PROMPT.md` 并要求 Agent 按文档执行。通常只需成功一次,用于补齐栈适配规则与 `figma:cache:*` scripts。
61
+
62
+ ### 步骤 4:初始化缓存索引
63
+
64
+ ```bash
65
+ npm run figma:cache:init
66
+ ```
67
+
68
+ 若尚未配置 scripts:
69
+
70
+ ```bash
71
+ npx figma-cache init
72
+ ```
73
+
74
+ > `cursor init` 负责模板与任务书;`figma-cache init` 负责本地数据骨架(`figma-cache/index.json`)。
75
+
76
+ ---
77
+
78
+ ## 3. 日常协作流程(最新口径)
79
+
80
+ ### 3.1 同事侧只需要做什么
81
+
82
+ - 把 Figma 链接 + 任务目标发给 Agent。
83
+ - 若有关系语义(前后页、分支、跳转),在同一条需求里说清楚。
84
+ - 需要最新稿时明确写“强制刷新”。
85
+
86
+ ### 3.2 Agent 侧标准执行链
87
+
88
+ 1. 标准化链接并查本地缓存。
89
+ 2. 命中且字段足够:直接复用,不调 MCP。
90
+ 3. 未命中/字段不足/用户要求刷新:按最小调用集调 MCP,原始回包写入 `mcp-raw/`。
91
+ 4. 执行 `upsert/ensure` 写索引与缓存文件。
92
+ 5. 同轮执行 `figma:cache:validate`,直到通过。
93
+
94
+ ### 3.3 本轮交付最小回报项(建议)
95
+
96
+ - 缓存状态:命中 / 缺失 / 更新
97
+ - 来源:Local / MCP
98
+ - 关键输出文件清单
99
+ - MCP 调用次数与是否触发 flow 自动追加(若触发,注明原因)
100
+
101
+ ---
102
+
103
+ ## 4. completeness、flow 与预算策略
104
+
105
+ ### 4.1 默认 completeness
106
+
107
+ 默认值:`layout,text,tokens,interactions,states,accessibility`。
108
+
109
+ ### 4.2 flow 自动追加(白名单)
110
+
111
+ 仅在以下场景自动追加 `flow`:
112
+ - 关系关键词命中:`关联`、`流程`、`跳转`、`前后页`、`上一步`、`下一步`、`分支`、`链路`、`路径`、`from/to`、`next`、`branch`
113
+ - 同轮或断续出现多条 Figma 链接,且明确有串联意图(如 A -> B)
114
+
115
+ 不会自动追加 `flow` 的场景:
116
+ - 单链接且无关系意图
117
+ - 仅视觉微调/文案修改
118
+ - 仅资产导出
119
+
120
+ ### 4.3 严格证据与骨架模式
121
+
122
+ - `source=figma-mcp` 时,`upsert/ensure` 默认需要通过 MCP 证据门禁。
123
+ - 仅当你明确知道在做“先落骨架”时,才临时使用 `--allow-skeleton-with-figma-mcp`。
124
+ - 即使允许骨架写入,后续 `validate` 仍必须通过,才能视为完成。
125
+
126
+ ### 4.4 预算字段
127
+
128
+ - 建议统一看 `tokenProxyBytes`。
129
+ - `tokenProxyChars` 为兼容字段,仅用于平滑迁移。
130
+
131
+ ---
132
+
133
+ ## 5. 团队主提示词(保留一个模板)
134
+
135
+ ### 5.1 默认主提示词
136
+
137
+ ```text
138
+ 请按项目 figma 缓存规则处理下面这条(或多条)Figma 链接,并遵循“缓存优先 + 按需 MCP + 最小调用集 + 校验闭环”:
139
+ 1) 先查本地 figma-cache,命中且字段足够则直接复用,不刷新;
140
+ 2) 仅在未命中、字段不足或我明确要求刷新时,调用 figma-mcp;
141
+ 3) MCP 原始数据写入节点目录 mcp-raw/ 后,再执行 upsert/ensure;
142
+ 4) completeness 默认 layout,text,tokens,interactions,states,accessibility;仅命中 flow 白名单时自动补 flow;
143
+ 5) 完成后执行 figma:cache:validate,并汇报缓存状态、来源、MCP 调用次数、输出文件清单;若自动补 flow,说明触发原因。
144
+
145
+ [Figma 链接]
146
+ ```
147
+
148
+ ### 5.2 可选附加句(按需加一句)
149
+
150
+ - 强制最新:`忽略本地缓存,强制刷新,以 Figma 最新为准。`
151
+ - 补流程关系:`请在 flow [flowId] 下补齐节点关系(link/chain),并输出 mermaid。`
152
+ - 资产留档:`本次需要 assets 维度,请补全资产相关证据。`
153
+
154
+ ---
155
+
156
+ ## 6. 常用命令(排障/复核用)
157
+
158
+ ```bash
159
+ npm run figma:cache:config
160
+ npm run figma:cache:get -- "<figma-url>"
161
+ npm run figma:cache:ensure -- "<figma-url>" --source=manual --completeness=layout,text,tokens,interactions,states,accessibility
162
+ npm run figma:cache:upsert -- "<figma-url>" --source=figma-mcp --completeness=layout,text,tokens,interactions,states,accessibility
163
+ npm run figma:cache:validate
164
+ npm run figma:cache:budget
165
+ npm run figma:cache:flow:show -- --flow=<flowId>
166
+ npm run figma:cache:flow:mermaid -- --flow=<flowId>
167
+ ```
168
+
169
+ ---
170
+
171
+ ## 7. 提交与协作建议
172
+
173
+ - 建议提交:`.cursor/`、`figma-cache.config.js`、`AGENT-SETUP-PROMPT.md`、`package.json`/lock。
174
+ - `figma-cache/index.json` 与 `figma-cache/files/` 是否入库,由团队统一约定。
175
+ - 若使用流程文档,建议同步维护 `docs/figma-flow-readme.md`(或 `FIGMA_CACHE_FLOW_README` 指定路径)。
176
+
177
+ ---
178
+
179
+ ## 8. 升级包后的动作
180
+
181
+ ```bash
182
+ npm i -D figma-cache-toolchain@latest
183
+ npx figma-cache cursor init
184
+ ```
185
+
186
+ 说明:
187
+ - `cursor init` 每次会刷新任务书与本同事指南。
188
+ - 仅升级包通常不需要重复完整接入流程。
189
+ - 已有 `figma-cache/index.json` 时,一般不需要重复 `figma:cache:init`。
190
+
191
+ ---
192
+
193
+ ## 9. 文档入口
194
+
195
+ - 业务仓库推荐入口:`figma-cache/docs/colleague-guide-zh.md`
196
+ - 包内完整文档:`node_modules/figma-cache-toolchain/figma-cache/docs/README.md`
197
+ - 规范文档:`link-normalization-spec.md`、`flow-edge-taxonomy.md`
198
+
199
+ 将本文件转发到团队 IM / Wiki 即可作为统一口径使用。
@@ -0,0 +1,14 @@
1
+ # Figma 缓存 → UI 实现(目录级提示)
2
+
3
+ 本文件由示例 `postEnsure` 生成,默认放在 **figma-cache 目录级**,用于避免“每个节点重复生成同一提示”。
4
+
5
+ - **默认来源优先级**:先用 `raw.json` / `spec.md` / `meta.json` / `state-map.md`,仅在缺口或冲突时再读 `mcp-raw/*`
6
+ - **证据约束**:同一设计事实只保留一个主证据来源,避免重复引用
7
+ - **命中检查**:先查本地缓存命中与字段覆盖,再决定是否需要 MCP 补齐
8
+
9
+ 可选模式(环境变量):
10
+ - `FIGMA_CACHE_ADAPTER_DOC_MODE=cache-root`(默认)
11
+ - `FIGMA_CACHE_ADAPTER_DOC_MODE=node`(按节点写入)
12
+ - `FIGMA_CACHE_ADAPTER_DOC_MODE=off`(关闭)
13
+
14
+ 最近触发:`abcABCd0123456789vWxyZ#1:2`(`2026-04-15T07:24:18.617Z`)
@@ -0,0 +1,42 @@
1
+ # Figma 缓存一页式速查(团队版)
2
+
3
+ ## 1) 日常只做这三步
4
+
5
+ 1. 把 Figma 链接和目标发给 Agent(是否强制刷新请写清楚)。
6
+ 2. 有流程关系时写明前后页/分支/跳转。
7
+ 3. 看回报是否包含:缓存状态、来源、MCP 调用次数、输出文件。
8
+
9
+ ## 2) 默认执行链(统一口径)
10
+
11
+ `先查本地缓存 -> 按需 MCP -> mcp-raw/ 落盘 -> upsert/ensure -> validate`
12
+
13
+ ## 3) 三条红线
14
+
15
+ - `ensure` 不是 MCP 拉取器。
16
+ - `source=figma-mcp` 但没有 `mcp-raw/` 证据,不算完成。
17
+ - `upsert/ensure` 后 `validate` 未通过,不算完成。
18
+
19
+ ## 4) completeness 记忆法
20
+
21
+ - 默认:`layout,text,tokens,interactions,states,accessibility`
22
+ - `flow` 仅在关系关键词或多链接串联意图时自动追加
23
+ - 仅视觉微调/单链接无关系/仅资产导出:通常不自动补 `flow`
24
+
25
+ ## 5) 主提示词(建议直接复制)
26
+
27
+ ```text
28
+ 请按项目 figma 缓存规则处理下面链接:先查本地缓存,未命中或字段不足再按需调用 figma-mcp;原始回包写入 mcp-raw/ 后执行 upsert/ensure;最后执行 figma:cache:validate。请回报缓存状态、来源、MCP 调用次数、输出文件清单;若自动补 flow,请说明触发原因。
29
+
30
+ [Figma 链接]
31
+ ```
32
+
33
+ ## 6) 排障常用命令
34
+
35
+ ```bash
36
+ npm run figma:cache:config
37
+ npm run figma:cache:get -- "<figma-url>"
38
+ npm run figma:cache:validate
39
+ npm run figma:cache:budget
40
+ ```
41
+
42
+ 更多细节:`figma-cache/docs/colleague-guide-zh.md`