figma-cache-toolchain 2.0.3 → 2.0.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.
Files changed (35) hide show
  1. package/README.md +197 -170
  2. package/cursor-bootstrap/AGENT-SETUP-PROMPT.md +75 -43
  3. package/cursor-bootstrap/examples/README.md +26 -15
  4. package/cursor-bootstrap/examples/ui-adapter.contract.template.json +90 -0
  5. package/cursor-bootstrap/examples/ui-execution-template.fast.md +11 -0
  6. package/cursor-bootstrap/examples/ui-execution-template.strict.md +13 -0
  7. package/cursor-bootstrap/examples/ui-override.template.json +26 -0
  8. package/cursor-bootstrap/figma-cache.config.example.js +51 -9
  9. package/cursor-bootstrap/managed-files.json +40 -40
  10. package/cursor-bootstrap/skills/figma-ui-dual-mode-execution/SKILL.md +55 -37
  11. package/figma-cache/adapters/recipes/button.recipe.json +24 -0
  12. package/figma-cache/adapters/recipes/card.recipe.json +24 -0
  13. package/figma-cache/adapters/recipes/checkbox.recipe.json +24 -0
  14. package/figma-cache/adapters/recipes/input.recipe.json +24 -0
  15. package/figma-cache/adapters/recipes/modal.recipe.json +25 -0
  16. package/figma-cache/adapters/recipes/radio.recipe.json +23 -0
  17. package/figma-cache/adapters/recipes/select.recipe.json +24 -0
  18. package/figma-cache/adapters/recipes/table.recipe.json +25 -0
  19. package/figma-cache/adapters/recipes/tabs.recipe.json +24 -0
  20. package/figma-cache/adapters/recipes/tooltip.recipe.json +24 -0
  21. package/figma-cache/docs/README.md +323 -237
  22. package/figma-cache/docs/p0-ui-preflight-handoff.md +207 -0
  23. package/figma-cache/docs/ui-1to1-optimization-roadmap.md +182 -0
  24. package/figma-cache/docs/ui-1to1-report.schema.json +104 -0
  25. package/figma-cache/figma-cache.js +639 -562
  26. package/figma-cache/js/contract-check-cli.js +466 -0
  27. package/figma-cache/js/cursor-bootstrap-cli.js +22 -0
  28. package/figma-cache/js/ui-facts-normalizer.js +233 -0
  29. package/package.json +93 -73
  30. package/scripts/cross-project-e2e.js +594 -0
  31. package/scripts/ui-1to1-audit.js +431 -0
  32. package/scripts/ui-auto-acceptance.js +248 -0
  33. package/scripts/ui-preflight.js +289 -0
  34. package/scripts/ui-profile.js +46 -0
  35. package/scripts/ui-report-aggregate.js +124 -0
@@ -0,0 +1,207 @@
1
+ # P0 执行交接文档:UI Preflight 门禁落地
2
+
3
+ > 目标:先落地 **P0**,让 UI 生成前有机器门禁,减少“生成后返工”。
4
+ >
5
+ > 本文档给下一个 Agent 直接执行,按顺序完成即可。
6
+
7
+ ---
8
+
9
+ ## 1. 背景与目标
10
+
11
+ 当前项目已有:
12
+
13
+ - `figma-cache validate`:索引/证据完整性门禁
14
+ - `figma:cache:contract:check`:token/state 映射门禁
15
+ - `figma:ui:gate`:聚合门禁(当前无 preflight)
16
+
17
+ 缺口:
18
+
19
+ - 缺少“面向 UI 任务”的结构化 preflight 产物与阻断策略。
20
+ - 当前 gate 偏通用校验,无法直观看到“为何当前 cacheKey 不适合开工写组件”。
21
+
22
+ P0 目标:
23
+
24
+ 1. 新增 `figma:ui:preflight` 命令(脚本 `scripts/ui-preflight.js`)。
25
+ 2. 生成结构化报告(默认输出到 `figma-cache/reports/ui-preflight-report.json`)。
26
+ 3. 存在阻断项时返回非零退出码(建议 `2`)。
27
+ 4. 将 preflight 接到 `figma:ui:gate` 前置步骤。
28
+ 5. 增加 smoke 覆盖与文档说明。
29
+
30
+ ---
31
+
32
+ ## 2. 设计约束(必须遵守)
33
+
34
+ - 不修改 Core 语义边界:`figma-cache/figma-cache.js` 继续保持“缓存/索引/校验入口”。
35
+ - P0 先做“门禁与可观测性”,不做 1:1 评分器(那是 P1)。
36
+ - 新脚本必须支持 PowerShell 与 CI(Linux)执行。
37
+ - 输出报告必须机器可读 JSON,便于后续接 CI 与二次分析。
38
+ - 默认尽量零配置可跑;参数可选。
39
+
40
+ ---
41
+
42
+ ## 3. 需要改动的文件(最小集)
43
+
44
+ ### 3.1 新增
45
+
46
+ - `scripts/ui-preflight.js`
47
+
48
+ ### 3.2 修改
49
+
50
+ - `package.json`
51
+ - 新增 script:`figma:ui:preflight`
52
+ - 调整 script:`figma:ui:gate` 前置执行 preflight
53
+ - `tests/smoke.js`
54
+ - 增加 preflight 正向/负向用例
55
+ - `README.md`
56
+ - 增加 preflight 与 gate 新流程
57
+ - `figma-cache/docs/README.md`
58
+ - 增加 preflight 命令、参数、报告字段
59
+
60
+ > 若有必要,可补一个文档:`figma-cache/docs/ui-preflight-spec.md`(可选)
61
+
62
+ ---
63
+
64
+ ## 4. `scripts/ui-preflight.js` 规格(执行标准)
65
+
66
+ ## 4.1 CLI 参数
67
+
68
+ 建议支持:
69
+
70
+ - `--cacheKey=<fileKey#nodeId>`(可选;不传则扫描全部 items)
71
+ - `--contract=<path>`(可选;默认 `figma-cache/adapters/ui-adapter.contract.json`)
72
+ - `--report=<path>`(可选;默认 `figma-cache/reports/ui-preflight-report.json`)
73
+ - `--allow-warn`(可选;仅对 warning 放行,blocking 仍失败)
74
+
75
+ ## 4.2 输入源
76
+
77
+ - 读取 `FIGMA_CACHE_DIR/index.json`
78
+ - 读取 contract JSON
79
+ - 对每个命中 item 读取:
80
+ - `paths.meta`
81
+ - `paths.spec`
82
+ - `paths.stateMap`
83
+ - `paths.raw`
84
+ - 若 source=figma-mcp,则读取 `mcp-raw/mcp-raw-manifest.json`
85
+
86
+ ## 4.3 报告结构(建议)
87
+
88
+ ```json
89
+ {
90
+ "ok": false,
91
+ "generatedAt": "ISO",
92
+ "summary": {
93
+ "checkedItems": 1,
94
+ "blockingCount": 2,
95
+ "warningCount": 1
96
+ },
97
+ "items": [
98
+ {
99
+ "cacheKey": "xxx#yyy",
100
+ "source": "manual|figma-mcp",
101
+ "blocking": ["..."],
102
+ "warnings": ["..."],
103
+ "checks": {
104
+ "cacheItemExists": true,
105
+ "entryFilesExist": true,
106
+ "coverageEvidenceReady": false,
107
+ "contractExists": true,
108
+ "tokenMappingReady": true,
109
+ "stateMappingReady": false,
110
+ "mcpRawReady": true
111
+ }
112
+ }
113
+ ]
114
+ }
115
+ ```
116
+
117
+ ## 4.4 阻断规则(P0)
118
+
119
+ 任一命中即 blocking:
120
+
121
+ - 指定 cacheKey 不存在
122
+ - item 缺失关键文件路径或文件不存在
123
+ - `raw.coverageSummary.evidence` 缺失/维度为空(按 item.completeness)
124
+ - contract 文件不存在或 JSON 非法
125
+ - `tokenMappings` 或 `stateMappings` 为空
126
+ - source=figma-mcp 时缺失 mcp-raw manifest(或 files 映射缺失)
127
+
128
+ warning(不阻断,可积累):
129
+
130
+ - spec/state-map 中仍存在 TODO 占位
131
+ - contract 存在但 mapping 命中率低(可输出统计)
132
+
133
+ ## 4.5 退出码
134
+
135
+ - `0`: 无 blocking
136
+ - `2`: 存在 blocking 或参数错误
137
+
138
+ ---
139
+
140
+ ## 5. gate 接入策略
141
+
142
+ 调整 `package.json`:
143
+
144
+ - 新增:
145
+ - `"figma:ui:preflight": "node scripts/ui-preflight.js"`
146
+ - 调整:
147
+ - `"figma:ui:gate": "npm run figma:ui:preflight && npm run figma:cache:validate && npm run cursor:shadow:check && npm test"`
148
+
149
+ > 说明:P0 不强制在 gate 中跑 `figma:cache:contract:check`,避免对旧项目立即破坏性升级。可在 P0.5 再接入。
150
+
151
+ ---
152
+
153
+ ## 6. 测试用例(必须)
154
+
155
+ 在 `tests/smoke.js` 至少补以下:
156
+
157
+ 1. **negative**:指定不存在 cacheKey,preflight 返回 `status=2`
158
+ 2. **negative**:构造 raw evidence 缺失,preflight 返回 `status=2`
159
+ 3. **positive**:构造最小完整 item + contract,preflight 返回 0,且报告 `ok=true`
160
+ 4. **assert 报告文件存在**:默认 report 路径成功写出
161
+
162
+ ---
163
+
164
+ ## 7. 验收命令(交付前必须全部通过)
165
+
166
+ 按顺序执行:
167
+
168
+ 1. `npm run cursor:shadow:sync`
169
+ 2. `npm run cursor:shadow:check`
170
+ 3. `npm test`
171
+ 4. `npm run figma:ui:preflight`(至少跑一次)
172
+ 5. `npm run figma:ui:gate`
173
+
174
+ ---
175
+
176
+ ## 8. 风险与注意事项
177
+
178
+ - `package.json` 当前格式被 PowerShell 写成“宽缩进 + 转义字符形式”,属于可接受状态;若后续要美化,单独做格式提交,不要混在 P0 逻辑提交里。
179
+ - `figma-cache/files/*` 可能有历史样例数据,不要把“样例缺陷”误当脚本 bug。
180
+ - 在 Windows PowerShell 5.1 中链式命令不要用 `&&`;优先 `;`。
181
+
182
+ ---
183
+
184
+ ## 9. 建议提交信息(给下一个 Agent)
185
+
186
+ ```text
187
+ feat(gate): 新增 figma ui preflight 结构化门禁并接入 figma:ui:gate
188
+
189
+ - 新增 scripts/ui-preflight.js,输出 ui-preflight-report.json 并对阻断项返回 exit code 2。
190
+ - 在 package.json 增加 figma:ui:preflight,且将 figma:ui:gate 前置 preflight 执行。
191
+ - 扩展 smoke 覆盖 preflight 的正负场景与报告落盘断言。
192
+ - 同步 README 与 figma-cache/docs/README.md,补充 preflight 使用说明与报告字段。
193
+ ```
194
+
195
+ ---
196
+
197
+ ## 11. 全量优化路线图(P1/P2/P3)
198
+
199
+ - 总体路线图文档:`figma-cache/docs/ui-1to1-optimization-roadmap.md`
200
+ - 建议:先完成本文件 P0,再按路线图推进 P1 -> P2 -> P3。
201
+
202
+ ---
203
+ ## 10. 当前上下文状态(切换 Agent 前说明)
204
+
205
+ - 最新提交:`8f27b82`
206
+ - 当前工作区:干净
207
+ - 本文档已落地,下一位 Agent 直接按本文执行 P0 即可
@@ -0,0 +1,182 @@
1
+ # UI 1:1 还原优化路线图(P0-P3)
2
+
3
+ > 目标:让 Agent 生成的组件/页面尽可能一次性 1:1 还原,显著降低返工轮次。
4
+
5
+ ---
6
+
7
+ ## 0. 北极星目标与衡量指标
8
+
9
+ ## 0.1 北极星目标
10
+
11
+ - **一次性交付可用率**:目标从当前基线提升到 `>=85%`(P2 结束)并冲刺 `>=95%`(P3)
12
+ - **平均返工轮次**:降到 `<=1.0`(P2)
13
+ - **关键页面首轮通过率**:`>=90%`(P3)
14
+
15
+ ## 0.2 指标定义(统一口径)
16
+
17
+ - `firstPassAccepted`: 首轮无需视觉/交互修改即可验收
18
+ - `reworkRounds`: 从首次生成到验收的修改轮次
19
+ - `score.layout/text/token/state/interaction`: 五维质量得分(0-100)
20
+ - `blockingRate`: preflight 阻断率(要区分“真实阻断”与“误报阻断”)
21
+
22
+ ---
23
+
24
+ ## 1. P0(当前):开工前门禁与可观测性
25
+
26
+ ## 1.1 目标
27
+
28
+ - 新增 `figma:ui:preflight`,先判断“是否具备开工条件”,减少无效生成。
29
+ - 在 `figma:ui:gate` 中前置 preflight。
30
+
31
+ ## 1.2 交付物
32
+
33
+ - `scripts/ui-preflight.js`
34
+ - `figma-cache/reports/ui-preflight-report.json`
35
+ - `package.json`:`figma:ui:preflight` + 更新 `figma:ui:gate`
36
+ - `tests/smoke.js`:preflight 正负样例
37
+
38
+ ## 1.3 完成判定
39
+
40
+ - preflight 对缺失证据/缺失 contract/覆盖证据空维度能稳定阻断(exit 2)
41
+ - gate 能在 preflight blocking 时提前失败
42
+
43
+ ---
44
+
45
+ ## 2. P1:结果可度量(从“过程正确”到“结果可验”)
46
+
47
+ ## 2.1 目标
48
+
49
+ - 建立统一评分与差异报告,明确“还差多少才 1:1”。
50
+
51
+ ## 2.2 交付物(建议)
52
+
53
+ 1. **质量审计脚本**
54
+ - 新增:`scripts/ui-1to1-audit.js`
55
+ - 输入:`cacheKey`、目标组件路径、可选 contract
56
+ - 输出:`figma-cache/reports/ui-1to1-report.json`
57
+
58
+ 2. **报告规范(schema)**
59
+ - 新增:`figma-cache/docs/ui-1to1-report.schema.json`
60
+ - 字段至少包含:
61
+ - `score.total`
62
+ - `score.layout/text/token/state/interaction`
63
+ - `diffs[]`(事实差异项)
64
+ - `blocking[]`、`warnings[]`
65
+
66
+ 3. **gate 接入阈值**
67
+ - 新增 script:`figma:ui:audit`
68
+ - 更新 gate:加入审计阈值(如 `score.total >= 85` 才放行)
69
+
70
+ ## 2.3 技术策略
71
+
72
+ - 先做“事实对事实”比对(cache 事实 vs 代码事实),避免一上来就纯像素比对。
73
+ - 文本、token、状态覆盖优先,布局分阶段细化(先主轴、后细节)。
74
+
75
+ ## 2.4 完成判定
76
+
77
+ - 每次生成后都可产出结构化评分报告
78
+ - 失败有明确差异清单,不再依赖人工口头描述
79
+
80
+ ---
81
+
82
+ ## 3. P2:生成准确性强化(减少二次修改)
83
+
84
+ ## 3.1 目标
85
+
86
+ - 将“映射与规则”从提示词级别,提升为可执行资产,降低 Agent 自由发挥空间。
87
+
88
+ ## 3.2 交付物(建议)
89
+
90
+ 1. **设计事实标准化层**
91
+ - 新增:`figma-cache/js/ui-facts-normalizer.js`
92
+ - 职责:把 `spec/raw/state-map/mcp-raw` 统一成稳定事实模型(dimensions/states/tokens/interactions)
93
+
94
+ 2. **组件生成配方(recipe)机制**
95
+ - 新增目录:`figma-cache/adapters/recipes/`
96
+ - 每类组件(select/input/modal/table)定义:
97
+ - 结构模板
98
+ - 状态机模板
99
+ - token 映射优先级
100
+ - 常见陷阱修正
101
+
102
+ 3. **contract 增强(从静态映射到约束映射)**
103
+ - 扩展 `ui-adapter.contract.json`:
104
+ - `layoutRules`
105
+ - `typographyRules`
106
+ - `interactionRules`
107
+ - 并增强 `contract-check`:新增规则级校验(非仅 token/state)
108
+
109
+ 4. **节点级 override 正规化**
110
+ - 规范 `ui-override.json` 字段与优先级
111
+ - 增加冲突检测(global contract vs node override)
112
+
113
+ ## 3.3 完成判定
114
+
115
+ - 常见组件类型(前 10 类)首轮通过率显著提升
116
+ - 同一组件跨页面表现一致(规则资产复用)
117
+
118
+ ---
119
+
120
+ ## 4. P3:体系化与规模化(团队长期稳定)
121
+
122
+ ## 4.1 目标
123
+
124
+ - 让流程可治理、可追踪、可持续优化。
125
+
126
+ ## 4.2 交付物(建议)
127
+
128
+ 1. **模式分层(降低认知负担)**
129
+ - 引入 `FIGMA_UI_PROFILE=fast|standard|strict`
130
+ - profile 映射到:preflight 严格度、审计阈值、是否强制预检文档
131
+
132
+ 2. **报告汇总与趋势分析**
133
+ - 新增:`scripts/ui-report-aggregate.js`
134
+ - 汇总 `ui-preflight-report.json` + `ui-1to1-report.json`,输出周报/趋势
135
+
136
+ 3. **CI 质量门禁矩阵**
137
+ - PR 最低门槛:preflight 必过
138
+ - 主干门槛:audit 分数阈值
139
+ - 关键路径页面:视觉基线对比(可选)
140
+
141
+ 4. **最佳实践模板化**
142
+ - 在 `cursor-bootstrap` 增加短版/严格版执行模板
143
+ - 把高频问题沉淀为“自动检查而非口头提醒”
144
+
145
+ ## 4.3 完成判定
146
+
147
+ - 指标长期稳定(首轮通过率、返工轮次)
148
+ - 新成员可按模板快速落地,不依赖专家经验
149
+
150
+ ---
151
+
152
+ ## 5. 建议实施顺序(现实可执行)
153
+
154
+ 1. **先做 P0(当前)**:先拦截无效开工
155
+ 2. **紧接 P1**:先拿到评分与差异报告
156
+ 3. **再做 P2**:把高频返工点产品化(recipe + contract 增强)
157
+ 4. **最后 P3**:标准化与团队化治理
158
+
159
+ ---
160
+
161
+ ## 6. 每阶段建议工期(参考)
162
+
163
+ - P0:1~2 天
164
+ - P1:3~5 天
165
+ - P2:1~2 周(按组件类型分批)
166
+ - P3:持续迭代(每周治理)
167
+
168
+ ---
169
+
170
+ ## 7. 与现有文档关系
171
+
172
+ - P0 详细执行:`figma-cache/docs/p0-ui-preflight-handoff.md`
173
+ - 本文档:总路线图(P0-P3)
174
+
175
+ ---
176
+
177
+ ## 8. 当前实现进度(2026-04)
178
+
179
+ - P0:已完成(preflight + gate 前置 + smoke + 文档)
180
+ - P1:已完成(audit + schema + gate 阈值)
181
+ - P2:已完成第一批(facts normalizer、recipes、contract 规则增强、override 冲突检测)
182
+ - P3:已完成第一批(profile 分层、报告聚合、PR/main 门禁矩阵、执行模板)
@@ -0,0 +1,104 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-07/schema#",
3
+ "title": "UI 1to1 Audit Report",
4
+ "type": "object",
5
+ "required": [
6
+ "ok",
7
+ "generatedAt",
8
+ "summary",
9
+ "blocking",
10
+ "warnings",
11
+ "diffs",
12
+ "items"
13
+ ],
14
+ "properties": {
15
+ "ok": {
16
+ "type": "boolean"
17
+ },
18
+ "generatedAt": {
19
+ "type": "string"
20
+ },
21
+ "summary": {
22
+ "type": "object",
23
+ "required": [
24
+ "checkedItems",
25
+ "score",
26
+ "blockingCount",
27
+ "warningCount",
28
+ "diffCount",
29
+ "minScore"
30
+ ],
31
+ "properties": {
32
+ "checkedItems": { "type": "integer" },
33
+ "blockingCount": { "type": "integer" },
34
+ "warningCount": { "type": "integer" },
35
+ "diffCount": { "type": "integer" },
36
+ "minScore": { "type": "number" },
37
+ "recipesTotal": { "type": "integer" },
38
+ "recipesMatchedItems": { "type": "integer" },
39
+ "score": {
40
+ "type": "object",
41
+ "required": ["total", "layout", "text", "token", "state", "interaction"],
42
+ "properties": {
43
+ "total": { "type": "number" },
44
+ "layout": { "type": "number" },
45
+ "text": { "type": "number" },
46
+ "token": { "type": "number" },
47
+ "state": { "type": "number" },
48
+ "interaction": { "type": "number" }
49
+ }
50
+ }
51
+ }
52
+ },
53
+ "blocking": {
54
+ "type": "array",
55
+ "items": { "type": "string" }
56
+ },
57
+ "warnings": {
58
+ "type": "array",
59
+ "items": { "type": "string" }
60
+ },
61
+ "diffs": {
62
+ "type": "array",
63
+ "items": { "type": "string" }
64
+ },
65
+ "items": {
66
+ "type": "array",
67
+ "items": {
68
+ "type": "object",
69
+ "required": ["cacheKey", "score", "blocking", "warnings", "diffs"],
70
+ "properties": {
71
+ "cacheKey": { "type": "string" },
72
+ "score": {
73
+ "type": "object",
74
+ "required": ["total", "layout", "text", "token", "state", "interaction"],
75
+ "properties": {
76
+ "total": { "type": "number" },
77
+ "layout": { "type": "number" },
78
+ "text": { "type": "number" },
79
+ "token": { "type": "number" },
80
+ "state": { "type": "number" },
81
+ "interaction": { "type": "number" }
82
+ }
83
+ },
84
+ "blocking": {
85
+ "type": "array",
86
+ "items": { "type": "string" }
87
+ },
88
+ "warnings": {
89
+ "type": "array",
90
+ "items": { "type": "string" }
91
+ },
92
+ "diffs": {
93
+ "type": "array",
94
+ "items": { "type": "string" }
95
+ },
96
+ "matchedRecipes": {
97
+ "type": "array",
98
+ "items": { "type": "string" }
99
+ }
100
+ }
101
+ }
102
+ }
103
+ }
104
+ }