@bovinphang/frontend-craft 2.5.0

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 (180) hide show
  1. package/.claude-plugin/marketplace.json +61 -0
  2. package/.claude-plugin/plugin.json +32 -0
  3. package/.mcp.json +44 -0
  4. package/CHANGELOG.md +229 -0
  5. package/CHANGELOG.zh-CN.md +228 -0
  6. package/CODE_OF_CONDUCT.md +34 -0
  7. package/CODE_OF_CONDUCT.zh-CN.md +34 -0
  8. package/CONTRIBUTING.md +356 -0
  9. package/CONTRIBUTING.zh-CN.md +356 -0
  10. package/LICENSE +21 -0
  11. package/README.md +467 -0
  12. package/README.openclaw.md +262 -0
  13. package/README.openclaw.zh-CN.md +262 -0
  14. package/README.zh-CN.md +467 -0
  15. package/SECURITY.md +44 -0
  16. package/SECURITY.zh-CN.md +44 -0
  17. package/agents/fec-architect.md +125 -0
  18. package/agents/fec-code-reviewer.md +152 -0
  19. package/agents/fec-debugger.md +44 -0
  20. package/agents/fec-design-token-mapper.md +75 -0
  21. package/agents/fec-doc-updater.md +30 -0
  22. package/agents/fec-e2e-runner.md +107 -0
  23. package/agents/fec-figma-implementer.md +104 -0
  24. package/agents/fec-performance-optimizer.md +293 -0
  25. package/agents/fec-refactor-cleaner.md +32 -0
  26. package/agents/fec-security-reviewer.md +116 -0
  27. package/agents/fec-test-planner.md +50 -0
  28. package/agents/fec-typescript-reviewer.md +142 -0
  29. package/agents/fec-ui-checker.md +120 -0
  30. package/commands/fec-debug.md +30 -0
  31. package/commands/fec-doc-sync.md +18 -0
  32. package/commands/fec-init.md +70 -0
  33. package/commands/fec-plan.md +94 -0
  34. package/commands/fec-refactor-clean.md +19 -0
  35. package/commands/fec-review.md +66 -0
  36. package/commands/fec-scaffold.md +205 -0
  37. package/commands/fec-tdd.md +21 -0
  38. package/dist/bin/frontend-craft.js +82 -0
  39. package/dist/hooks/fec-cleanup-claude-cache.js +4 -0
  40. package/dist/hooks/fec-format-changed-file.js +1 -0
  41. package/dist/hooks/fec-notify.js +1 -0
  42. package/dist/hooks/fec-run-tests.js +1 -0
  43. package/dist/hooks/fec-security-check.js +2 -0
  44. package/dist/hooks/fec-session-start.js +1 -0
  45. package/docs/example-prompts.md +124 -0
  46. package/docs/ja-JP/README.md +467 -0
  47. package/docs/ko-KR/README.md +467 -0
  48. package/docs/project-structure.md +119 -0
  49. package/docs/runtimes/antigravity.md +10 -0
  50. package/docs/runtimes/augment.md +10 -0
  51. package/docs/runtimes/claude.md +171 -0
  52. package/docs/runtimes/claude.zh-CN.md +169 -0
  53. package/docs/runtimes/cline.md +10 -0
  54. package/docs/runtimes/codebuddy.md +10 -0
  55. package/docs/runtimes/codex.md +10 -0
  56. package/docs/runtimes/copilot.md +10 -0
  57. package/docs/runtimes/cursor.md +10 -0
  58. package/docs/runtimes/gemini.md +10 -0
  59. package/docs/runtimes/kilo.md +10 -0
  60. package/docs/runtimes/openclaw.md +10 -0
  61. package/docs/runtimes/opencode.md +10 -0
  62. package/docs/runtimes/qoder.md +19 -0
  63. package/docs/runtimes/trae.md +10 -0
  64. package/docs/runtimes/windsurf.md +10 -0
  65. package/docs/superpowers/plans/2026-05-29-fec-debug.md +491 -0
  66. package/docs/superpowers/specs/2026-05-29-fec-debug-design.md +340 -0
  67. package/docs/zh-CN/example-prompts.md +124 -0
  68. package/docs/zh-CN/project-structure.md +119 -0
  69. package/docs/zh-TW/README.md +467 -0
  70. package/hooks/hooks.json +71 -0
  71. package/openclaw.plugin.json +26 -0
  72. package/package.json +101 -0
  73. package/skills/TEMPLATE.md +155 -0
  74. package/skills/eval_queries.json +890 -0
  75. package/skills/fec-accessibility-check/SKILL.md +39 -0
  76. package/skills/fec-accessibility-check/references/report-template.md +23 -0
  77. package/skills/fec-accessibility-check/references/screen-reader-testing.md +33 -0
  78. package/skills/fec-api-integration/SKILL.md +78 -0
  79. package/skills/fec-api-integration/references/integration-patterns.md +80 -0
  80. package/skills/fec-browser-storage/SKILL.md +34 -0
  81. package/skills/fec-browser-storage/references/storage-patterns.md +65 -0
  82. package/skills/fec-canvas-threejs/SKILL.md +66 -0
  83. package/skills/fec-canvas-threejs/references/rendering-patterns.md +67 -0
  84. package/skills/fec-canvas-threejs/references/shader-webgl-patterns.md +67 -0
  85. package/skills/fec-code-review/SKILL.md +135 -0
  86. package/skills/fec-code-review/references/report-template.md +29 -0
  87. package/skills/fec-component-testing/SKILL.md +119 -0
  88. package/skills/fec-data-fetching/SKILL.md +62 -0
  89. package/skills/fec-data-fetching/references/query-patterns.md +77 -0
  90. package/skills/fec-debug-framework/SKILL.md +162 -0
  91. package/skills/fec-dependency-upgrade/SKILL.md +34 -0
  92. package/skills/fec-dependency-upgrade/references/dependency-upgrade-workflow.md +56 -0
  93. package/skills/fec-doc-sync/SKILL.md +37 -0
  94. package/skills/fec-e2e-testing/SKILL.md +40 -0
  95. package/skills/fec-e2e-testing/references/e2e-advanced.md +176 -0
  96. package/skills/fec-e2e-testing/references/playwright-patterns.md +95 -0
  97. package/skills/fec-form-handling/SKILL.md +76 -0
  98. package/skills/fec-form-handling/references/advanced-form-patterns.md +72 -0
  99. package/skills/fec-implement-from-design/SKILL.md +122 -0
  100. package/skills/fec-implement-from-design/references/design-plan-template.md +36 -0
  101. package/skills/fec-legacy-to-modern-migration/SKILL.md +180 -0
  102. package/skills/fec-legacy-to-modern-migration/references/migration-report-template.md +41 -0
  103. package/skills/fec-legacy-web-standard/SKILL.md +35 -0
  104. package/skills/fec-legacy-web-standard/references/legacy-patterns.md +85 -0
  105. package/skills/fec-list-virtualization/SKILL.md +34 -0
  106. package/skills/fec-list-virtualization/references/virtualization-patterns.md +52 -0
  107. package/skills/fec-monorepo-project-standard/SKILL.md +142 -0
  108. package/skills/fec-motion-interaction/SKILL.md +66 -0
  109. package/skills/fec-motion-interaction/references/motion-patterns.md +112 -0
  110. package/skills/fec-nextjs-project-standard/SKILL.md +117 -0
  111. package/skills/fec-nuxt-project-standard/SKILL.md +122 -0
  112. package/skills/fec-performance-optimization/SKILL.md +72 -0
  113. package/skills/fec-pwa-implementation/SKILL.md +36 -0
  114. package/skills/fec-pwa-implementation/references/manifest-and-icons.md +53 -0
  115. package/skills/fec-pwa-implementation/references/service-worker-workbox.md +68 -0
  116. package/skills/fec-react-project-standard/SKILL.md +83 -0
  117. package/skills/fec-react-project-standard/references/react-project-details.md +642 -0
  118. package/skills/fec-refactor-clean/SKILL.md +48 -0
  119. package/skills/fec-responsive-layout/SKILL.md +34 -0
  120. package/skills/fec-responsive-layout/references/responsive-layout-patterns.md +59 -0
  121. package/skills/fec-route-protection/SKILL.md +135 -0
  122. package/skills/fec-security-review/SKILL.md +38 -0
  123. package/skills/fec-security-review/references/report-template.md +27 -0
  124. package/skills/fec-security-review/references/security-checklist.md +64 -0
  125. package/skills/fec-source-driven-development/SKILL.md +61 -0
  126. package/skills/fec-state-management/SKILL.md +140 -0
  127. package/skills/fec-state-management/references/state-patterns.md +109 -0
  128. package/skills/fec-storybook-component-doc/SKILL.md +37 -0
  129. package/skills/fec-storybook-component-doc/references/story-patterns.md +118 -0
  130. package/skills/fec-svg-animation/SKILL.md +148 -0
  131. package/skills/fec-tailwind-design-system/SKILL.md +34 -0
  132. package/skills/fec-tailwind-design-system/references/tailwind-system-patterns.md +55 -0
  133. package/skills/fec-tdd-workflow/SKILL.md +52 -0
  134. package/skills/fec-testing-strategy/SKILL.md +45 -0
  135. package/skills/fec-typescript-type-safety/SKILL.md +157 -0
  136. package/skills/fec-typescript-type-safety/references/type-safety-patterns.md +102 -0
  137. package/skills/fec-ui-design/SKILL.md +90 -0
  138. package/skills/fec-ui-design/data/product-rules.json +110 -0
  139. package/skills/fec-ui-design/data/stack-ui-rules.json +14 -0
  140. package/skills/fec-ui-design/data/style-archetypes.json +74 -0
  141. package/skills/fec-ui-design/data/ux-quality-rules.json +56 -0
  142. package/skills/fec-ui-design/references/design-intelligence.md +37 -0
  143. package/skills/fec-ui-design/references/master-page-overrides.md +30 -0
  144. package/skills/fec-ui-design/references/pre-delivery-checklist.md +33 -0
  145. package/skills/fec-ui-design/scripts/design-system.mjs +530 -0
  146. package/skills/fec-validation-fix/SKILL.md +48 -0
  147. package/skills/fec-vite-project-standard/SKILL.md +83 -0
  148. package/skills/fec-vue3-project-standard/SKILL.md +49 -0
  149. package/skills/fec-vue3-project-standard/references/vue3-project-details.md +547 -0
  150. package/skills/fec-web-workers/SKILL.md +36 -0
  151. package/skills/fec-web-workers/references/advanced-workers.md +54 -0
  152. package/skills/fec-web-workers/references/basic-worker.md +67 -0
  153. package/skills/metadata.json +1422 -0
  154. package/skills/relations.json +644 -0
  155. package/templates/claude/CLAUDE.md +106 -0
  156. package/templates/claude/settings.json +62 -0
  157. package/templates/codex/AGENTS.md +105 -0
  158. package/templates/codex/config.toml +32 -0
  159. package/templates/openclaw/AGENTS.md +101 -0
  160. package/templates/openclaw/OPENCLAW-CONFIG.md +12 -0
  161. package/templates/shared/rules/fec-agent-workflow.md +54 -0
  162. package/templates/shared/rules/fec-api-layer.md +99 -0
  163. package/templates/shared/rules/fec-ci-cd.md +128 -0
  164. package/templates/shared/rules/fec-code-comments.md +33 -0
  165. package/templates/shared/rules/fec-design-system.md +248 -0
  166. package/templates/shared/rules/fec-error-handling.md +200 -0
  167. package/templates/shared/rules/fec-git-conventions.md +73 -0
  168. package/templates/shared/rules/fec-i18n.md +112 -0
  169. package/templates/shared/rules/fec-naming-conventions.md +120 -0
  170. package/templates/shared/rules/fec-performance.md +101 -0
  171. package/templates/shared/rules/fec-react.md +82 -0
  172. package/templates/shared/rules/fec-refactoring.md +43 -0
  173. package/templates/shared/rules/fec-rendering-patterns.md +183 -0
  174. package/templates/shared/rules/fec-responsive-design.md +227 -0
  175. package/templates/shared/rules/fec-source-driven-development.md +31 -0
  176. package/templates/shared/rules/fec-state-management.md +163 -0
  177. package/templates/shared/rules/fec-testing.md +98 -0
  178. package/templates/shared/rules/fec-typescript.md +355 -0
  179. package/templates/shared/rules/fec-vue.md +64 -0
  180. package/templates/shared/rules/fec-working-modes.md +50 -0
@@ -0,0 +1,227 @@
1
+ # 响应式设计规则
2
+
3
+ 凡是任务涉及移动端适配、响应式布局、多端兼容时,都应用本文件。
4
+
5
+ ## 核心原则
6
+
7
+ - **移动优先**: 从小屏幕开始设计,逐步增强到大屏幕
8
+ - **内容优先**: 移动端优先展示核心内容,次要内容折叠或延后
9
+ - **触摸友好**: 所有交互元素必须适配手指操作
10
+ - **性能优先**: 移动端网络和设备性能较弱,需优化加载
11
+ - **容器感知**: 可复用组件优先适配所在容器,而不是假设整页断点
12
+ - **稳定尺寸**: 工具栏、表格列、棋盘、卡片网格和计数器需要稳定约束,避免状态变化导致布局跳动
13
+
14
+ ## 断点策略
15
+
16
+ | 断点 | 宽度 | 设备 | Tailwind | 说明 |
17
+ | ----------- | ------ | --------------- | -------- | -------------------- |
18
+ | **Mobile** | 375px | 手机竖屏 | (默认) | 基础样式,无媒体查询 |
19
+ | **Tablet** | 768px | 平板 / 手机横屏 | `md:` | 两列布局起点 |
20
+ | **Desktop** | 1024px | 笔记本 | `lg:` | 完整布局 |
21
+ | **Large** | 1280px | 桌面显示器 | `xl:` | 宽屏优化 |
22
+ | **XLarge** | 1536px | 超宽屏 | `2xl:` | 最大内容宽度 |
23
+
24
+ ### 移动优先 CSS
25
+
26
+ ```css
27
+ /* 基础样式 — 移动端 */
28
+ .container {
29
+ padding: 16px;
30
+ display: flex;
31
+ flex-direction: column;
32
+ gap: 12px;
33
+ }
34
+
35
+ /* Tablet — 768px+ */
36
+ @media (min-width: 768px) {
37
+ .container {
38
+ padding: 24px;
39
+ flex-direction: row;
40
+ gap: 24px;
41
+ }
42
+ }
43
+
44
+ /* Desktop — 1024px+ */
45
+ @media (min-width: 1024px) {
46
+ .container {
47
+ max-width: 960px;
48
+ margin: 0 auto;
49
+ padding: 32px;
50
+ }
51
+ }
52
+ ```
53
+
54
+ ### Tailwind 移动优先
55
+
56
+ Tailwind 默认移动优先,无前缀类作用于所有屏幕,前缀仅覆盖更大断点:
57
+
58
+ ```html
59
+ <!-- 移动端: 单列, 小间距 | Tablet: 双列 | Desktop: 三列 -->
60
+ <div
61
+ class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4 md:gap-6 lg:gap-8"
62
+ >
63
+ <!-- 卡片: 移动端小字, Desktop 大字 -->
64
+ <div class="p-4 md:p-6 text-sm md:text-base">...</div>
65
+ </div>
66
+
67
+ <!-- 导航: 移动端隐藏, Desktop 显示 -->
68
+ <nav class="hidden md:flex">...</nav>
69
+
70
+ <!-- 移动端汉堡菜单, Desktop 隐藏 -->
71
+ <button class="md:hidden" aria-label="菜单">☰</button>
72
+ ```
73
+
74
+ **关键约定**:
75
+
76
+ - 始终使用 `min-width` 媒体查询(mobile-first),不用 `max-width`
77
+ - Tailwind 前缀从小到大:`sm:` → `md:` → `lg:` → `xl:`
78
+ - 不要在桌面端写默认样式然后用 `max-width` 覆盖移动端
79
+
80
+ ## 触摸目标
81
+
82
+ | 元素 | 最小尺寸 | 说明 |
83
+ | ----------- | --------- | --------------------------- |
84
+ | 按钮 | 44×44px | WCAG 2.2 触摸目标要求 |
85
+ | 链接 | 44×44px | 可通过 padding 扩大点击区域 |
86
+ | 表单输入 | 44px 高度 | 避免 iOS 自动缩放 |
87
+ | 复选框/单选 | 24×24px | 最小可见尺寸 |
88
+ | 关闭按钮 | 44×44px | 模态框、Toast 的关闭按钮 |
89
+
90
+ ```css
91
+ /* 扩大点击区域(视觉尺寸不变) */
92
+ .icon-button {
93
+ width: 24px;
94
+ height: 24px;
95
+ padding: 10px; /* 实际点击区域 44×44 */
96
+ }
97
+
98
+ /* 表单输入 — 避免 iOS 缩放 */
99
+ input,
100
+ select,
101
+ textarea {
102
+ font-size: 16px; /* < 16px 时 iOS Safari 会自动缩放页面 */
103
+ }
104
+ ```
105
+
106
+ ## 布局模式
107
+
108
+ ### Container Query
109
+
110
+ 当组件会出现在侧栏、弹窗、卡片和主内容区等不同容器时,优先使用容器查询:
111
+
112
+ ```css
113
+ .summary-panel {
114
+ container-type: inline-size;
115
+ }
116
+
117
+ @container (min-width: 42rem) {
118
+ .summary-panel__body {
119
+ display: grid;
120
+ grid-template-columns: 16rem minmax(0, 1fr);
121
+ }
122
+ }
123
+ ```
124
+
125
+ Flex/Grid 子项包含长文本、图表、代码或表格时,记得设置 `min-width: 0`。
126
+
127
+ ### Stack → Row
128
+
129
+ 移动端纵向堆叠,桌面端横向排列:
130
+
131
+ ```html
132
+ <div class="flex flex-col md:flex-row gap-4">
133
+ <div class="flex-1">主内容</div>
134
+ <div class="md:w-64 md:flex-shrink-0">侧边栏</div>
135
+ </div>
136
+ ```
137
+
138
+ ### 响应式表格
139
+
140
+ ```html
141
+ <!-- 小屏横向滚动 -->
142
+ <div class="overflow-x-auto">
143
+ <table class="min-w-full">
144
+ ...
145
+ </table>
146
+ </div>
147
+
148
+ <!-- 或:移动端卡片式布局 -->
149
+ <div class="hidden md:block">
150
+ <table>
151
+ ...
152
+ </table>
153
+ </div>
154
+ <div class="md:hidden">
155
+ <!-- 每行变为卡片 -->
156
+ </div>
157
+ ```
158
+
159
+ 移动端数据密集视图需先定义列优先级:主标识、状态和主操作优先保留;低优先级字段进入详情、展开行或抽屉。
160
+
161
+ ### 响应式图片
162
+
163
+ ```html
164
+ <!-- srcset 按设备像素比加载 -->
165
+ <img
166
+ src="/img/hero-800.jpg"
167
+ srcset="
168
+ /img/hero-400.jpg 400w,
169
+ /img/hero-800.jpg 800w,
170
+ /img/hero-1200.jpg 1200w
171
+ "
172
+ sizes="(max-width: 768px) 100vw, 800px"
173
+ alt="描述"
174
+ loading="lazy"
175
+ />
176
+
177
+ <!-- picture 元素按断点切换 -->
178
+ <picture>
179
+ <source
180
+ media="(min-width: 1024px)"
181
+ srcset="/img/hero-desktop.webp"
182
+ type="image/webp"
183
+ />
184
+ <source
185
+ media="(min-width: 768px)"
186
+ srcset="/img/hero-tablet.webp"
187
+ type="image/webp"
188
+ />
189
+ <img src="/img/hero-mobile.webp" alt="描述" loading="lazy" />
190
+ </picture>
191
+ ```
192
+
193
+ ## 移动端交互注意
194
+
195
+ - **悬停不可靠**: 移动端无 hover 状态,不要将关键功能隐藏在 hover 中(如 tooltip 改为点击触发)
196
+ - **键盘弹出**: 移动端虚拟键盘会缩小可视区域,固定定位元素需注意位置调整
197
+ - **滚动性能**: 使用 `-webkit-overflow-scrolling: touch`(iOS)或 `overscroll-behavior` 优化滚动体验
198
+ - **安全区域**: 适配 iPhone 刘海/底部横条,使用 `env(safe-area-inset-*)`:
199
+
200
+ ```css
201
+ .app-content {
202
+ padding-top: env(safe-area-inset-top);
203
+ padding-bottom: env(safe-area-inset-bottom);
204
+ padding-left: env(safe-area-inset-left);
205
+ padding-right: env(safe-area-inset-right);
206
+ }
207
+ ```
208
+
209
+ ## 测试策略
210
+
211
+ - 使用 Chrome DevTools Device Mode 测试主流设备
212
+ - 优先在真实设备上测试(iOS Safari / Android Chrome)
213
+ - 测试方向切换(横屏 / 竖屏)
214
+ - 测试不同网络条件(3G / 4G / 弱网)
215
+ - 不要假设桌面端是"默认",移动端优先验证
216
+
217
+ ## 检查清单
218
+
219
+ - [ ] 375px 宽度下布局正常,无水平溢出
220
+ - [ ] 所有交互元素 ≥ 44×44px(触摸目标)
221
+ - [ ] 输入框 font-size ≥ 16px(避免 iOS 缩放)
222
+ - [ ] 无 hover 依赖的关键功能
223
+ - [ ] 图片使用 srcset / picture 按设备加载
224
+ - [ ] iPhone 安全区域适配(safe-area-inset)
225
+ - [ ] 内容在断点间平滑过渡,无突变
226
+ - [ ] 断点中间值、横竖屏切换和虚拟键盘弹出不遮挡主操作
227
+ - [ ] 数据密集区域有列优先级或局部滚动策略
@@ -0,0 +1,31 @@
1
+ # 来源驱动开发规则
2
+
3
+ 当实现依赖框架、库、浏览器、运行时、构建工具或平台行为时,先确认事实来源,再写代码或评审结论。
4
+
5
+ ## 事实来源优先级
6
+
7
+ 1. 项目内 README、配置、测试、模板和已有实现。
8
+ 2. 官方文档、源码、类型定义、release notes、migration guide。
9
+ 3. Web 标准、浏览器兼容数据和平台文档。
10
+ 4. Issue、讨论、博客和第三方文章仅作为线索。
11
+
12
+ ## 使用场景
13
+
14
+ - 框架新版本、路由、渲染模式、缓存、构建配置、浏览器 API。
15
+ - 公共接口、组件 API、设计系统 token、CLI 命令和插件元数据。
16
+ - 依赖升级、迁移、废弃 API 替换、跨运行时兼容。
17
+ - 与安全、性能、可访问性相关的版本敏感判断。
18
+
19
+ ## 输出要求
20
+
21
+ - 写清来源、版本或项目事实、决策结论、影响范围和验证方式。
22
+ - 若项目现状与官方推荐冲突,说明冲突原因和渐进迁移策略。
23
+ - 不复制长篇外部文档;只保留必要结论、链接或项目内文件路径。
24
+ - 无法验证时标注不确定性和需要用户/团队确认的事项。
25
+
26
+ ## 反模式
27
+
28
+ - 凭记忆使用版本敏感 API。
29
+ - 用过时教程替代官方文档。
30
+ - 为追新推翻稳定项目约定。
31
+ - 在组件里散落外部库行为假设,而不是集中到适配层。
@@ -0,0 +1,163 @@
1
+ # 状态管理规范
2
+
3
+ ## 状态分类
4
+
5
+ | 类型 | 示例 | 存放位置 |
6
+ | ------------ | -------------------------------- | ------------------- |
7
+ | 组件 UI 状态 | modal 开关、tab 索引、hover 状态 | 组件内 state |
8
+ | 表单状态 | 输入值、校验错误 | 表单库或组件 state |
9
+ | 服务端数据 | 用户列表、订单详情 | 数据请求库缓存 |
10
+ | 全局业务状态 | 当前用户、权限、主题 | 全局 Store |
11
+ | URL 状态 | 当前页码、筛选条件、排序 | 路由参数 / 搜索参数 |
12
+
13
+ ## 核心原则
14
+
15
+ - **就近管理**: 状态放在需要它的最近公共祖先
16
+ - **单一数据源**: 同一份数据只在一个地方维护
17
+ - **派生优于同步**: 可计算的值用 computed / useMemo,而不是手动同步多个 state
18
+ - **最小状态**: 不存储可以从已有状态推导的值
19
+
20
+ ## React 状态管理
21
+
22
+ ### 本地状态
23
+
24
+ ```tsx
25
+ // 简单值 - useState
26
+ const [count, setCount] = useState(0);
27
+
28
+ // 复杂逻辑 - useReducer
29
+ const [state, dispatch] = useReducer(formReducer, initialState);
30
+ ```
31
+
32
+ ### 全局状态(Zustand 示例)
33
+
34
+ <!-- 请根据项目实际选型调整:Redux Toolkit / Zustand / Jotai -->
35
+
36
+ ```tsx
37
+ const useAuthStore = create<AuthState>((set) => ({
38
+ user: null,
39
+ login: async (credentials) => {
40
+ const user = await authApi.login(credentials);
41
+ set({ user });
42
+ },
43
+ logout: () => set({ user: null }),
44
+ }));
45
+ ```
46
+
47
+ ### 服务端状态
48
+
49
+ <!-- 请根据项目实际选型调整:React Query / SWR -->
50
+
51
+ ```tsx
52
+ const { data, isLoading, error } = useQuery({
53
+ queryKey: ["users", params],
54
+ queryFn: () => fetchUsers(params),
55
+ staleTime: 5 * 60 * 1000,
56
+ });
57
+ ```
58
+
59
+ ## Vue 状态管理
60
+
61
+ ### 本地状态
62
+
63
+ ```typescript
64
+ const count = ref(0);
65
+ const form = reactive({ name: "", email: "" });
66
+ ```
67
+
68
+ ### 全局状态(Pinia)
69
+
70
+ ```typescript
71
+ export const useAuthStore = defineStore("auth", () => {
72
+ const user = ref<User | null>(null);
73
+
74
+ async function login(credentials: LoginParams) {
75
+ user.value = await authApi.login(credentials);
76
+ }
77
+
78
+ function logout() {
79
+ user.value = null;
80
+ }
81
+
82
+ const isLoggedIn = computed(() => user.value !== null);
83
+
84
+ return { user: readonly(user), isLoggedIn, login, logout };
85
+ });
86
+ ```
87
+
88
+ ### 服务端状态
89
+
90
+ <!-- 请根据项目实际选型调整:VueQuery / 自定义 composable -->
91
+
92
+ ```typescript
93
+ const { data, isLoading, error } = useQuery({
94
+ queryKey: ["users", params],
95
+ queryFn: () => fetchUsers(toValue(params)),
96
+ });
97
+ ```
98
+
99
+ ## 选型决策矩阵
100
+
101
+ ### React 全局状态管理选型
102
+
103
+ | 维度 | Context API | Zustand | Redux Toolkit | Jotai |
104
+ | -------------- | -------------------------------------- | -------------------------------------- | ------------------------------- | ------------------- |
105
+ | **适用场景** | 全局常量(主题、语言、用户信息) | 复杂业务状态(购物车、Dashboard 筛选) | 大型应用,需要严格的状态流控制 | 细粒度原子状态 |
106
+ | **重渲染性能** | ❌ 任何 value 变化导致所有消费者重渲染 | ✅ 通过 selector 精确订阅 | ✅ connect/useSelector 精确订阅 | ✅ 原子级订阅 |
107
+ | **样板代码** | 少(Provider + createContext) | 极少(一个 create 调用) | 多(slice / action / selector) | 极少(atom) |
108
+ | **DevTools** | ❌ 无 | ✅ Redux DevTools(中间件) | ✅ Redux DevTools | ✅ 专用 DevTools |
109
+ | **TypeScript** | ⚠️ 需手动类型标注 | ✅ 自动推导 | ✅ 自动推导 | ✅ 自动推导 |
110
+ | **中间件** | ❌ | ✅(persist / devtools / immer) | ✅(thunk / listener) | ✅ |
111
+ | **Provider** | ✅ 必须包裹 | ❌ 不需要(外部 store) | ✅ Provider | ❌(可选 Provider) |
112
+
113
+ **推荐决策流程**:
114
+
115
+ ```
116
+ 状态是否跨组件共享?
117
+ ├── 否 → useState / useReducer(本地状态)
118
+ └── 是
119
+ ├── 值是否几乎不变?(主题、语言、配置)
120
+ │ └── 是 → Context API
121
+ │
122
+ ├── 是否需要严格状态流 + 时间旅行调试?
123
+ │ └── 是 → Redux Toolkit
124
+ │
125
+ ├── 状态是否高度关联、需要集中管理?
126
+ │ └── 是 → Zustand
127
+ │
128
+ └── 状态是否独立、需要细粒度订阅?
129
+ └── 是 → Jotai
130
+ ```
131
+
132
+ ### Vue 全局状态管理选型
133
+
134
+ | 维度 | provide/inject | Pinia |
135
+ | -------------- | ---------------------------------- | ---------------- |
136
+ | **适用场景** | 局部跨层级传递(主题、表单上下文) | 全局业务状态 |
137
+ | **响应式** | ✅(传入 reactive/ref) | ✅ |
138
+ | **DevTools** | ❌ | ✅ Vue DevTools |
139
+ | **TypeScript** | ⚠️ 需 InjectionKey | ✅ 自动推导 |
140
+ | **SSR 安全** | ⚠️ 需注意作用域 | ✅ 内置 SSR 支持 |
141
+
142
+ **Vue 选型结论**:Pinia 是 Vue 3 官方推荐,新项目直接使用。provide/inject 仅用于局部上下文传递。
143
+
144
+ ---
145
+
146
+ ## 反模式
147
+
148
+ - 将所有状态都放进全局 store(应优先本地状态)
149
+ - 在 store 中存放 UI 临时状态(modal 开关、表单输入等)
150
+ - 手动同步多份相同数据而不是用计算属性
151
+ - 在组件中直接修改 store 的内部数据(应通过 action / mutation)
152
+ - 将服务端响应原封不动存入全局 store 而不用请求缓存库
153
+ - 过度使用 Context / provide 替代 props 传递
154
+ - 用 Context 管理频繁更新的状态(导致全量消费者重渲染,应改用 Zustand/Pinia)
155
+
156
+ ## 检查清单
157
+
158
+ - [ ] 每个状态都有明确的归属(本地 / 全局 / URL / 服务端缓存)
159
+ - [ ] 可派生的值没有被存为独立 state
160
+ - [ ] 全局 store 仅包含真正需要跨组件共享的数据
161
+ - [ ] 服务端数据通过请求库管理,而非手动存入 store
162
+ - [ ] URL 状态(搜索、分页、筛选)与路由参数同步
163
+ - [ ] Context 仅用于低频变更的全局值(主题、语言、用户信息)
@@ -0,0 +1,98 @@
1
+ # 测试与校验规则
2
+
3
+ 凡是新增、修改、重构或评审代码时,都应用本文件。
4
+
5
+ ## 校验顺序
6
+
7
+ 优先按以下顺序执行:
8
+
9
+ 1. lint
10
+ 2. type check
11
+ 3. unit test
12
+ 4. build
13
+
14
+ 优先使用仓库已有脚本。
15
+ 如果命令不确定,先检查 `package.json`。
16
+
17
+ ## 改动校验原则
18
+
19
+ - 先修复范围最小且正确的问题
20
+ - 每次关键修复后重新执行受影响的命令
21
+ - 不要盲目压掉报错或关闭规则
22
+ - 不要为了通过检查而降低类型安全
23
+ - 不要因为一个局部测试失败就重写无关模块
24
+
25
+ ## 测试要求
26
+
27
+ 新增或修改行为时,考虑是否需要覆盖以下内容:
28
+
29
+ - 组件渲染
30
+ - 交互行为
31
+ - 状态切换
32
+ - 边界场景
33
+ - loading / empty / error 状态
34
+ - 与可访问性相关的关键交互
35
+
36
+ 如果没有补测试,需要说明原因。
37
+
38
+ ## Fixture 与 Mock
39
+
40
+ - Fixture 表达业务场景,不使用随机、无语义或只对测试作者有意义的数据
41
+ - 复杂对象使用 builder 填充默认值,每个测试只覆盖当前场景相关字段
42
+ - 测试间不共享可变全局状态、fake timer、store 或 mock server handler
43
+ - 网络 mock 应模拟公开契约和用户可见错误,不复制后端内部实现
44
+
45
+ ## TDD 与回归测试
46
+
47
+ 新增行为、修复 Bug 或重构关键逻辑时,优先采用 TDD:
48
+
49
+ 1. 先写能描述期望行为的失败测试。
50
+ 2. 运行测试并确认失败原因正确。
51
+ 3. 写最小实现让测试通过。
52
+ 4. 测试保持通过后再重构。
53
+
54
+ Bug 修复应优先保留能复现问题的回归测试。若现有项目缺少测试基础设施,不要盲目引入新框架;先给出最小测试落地建议并说明维护成本。
55
+
56
+ ## 代码评审输出风格
57
+
58
+ 评审代码时,返回:
59
+
60
+ - 总体评估
61
+ - 必修问题
62
+ - 建议优化
63
+ - 可选优化项
64
+ - 风险等级
65
+
66
+ 结论要具体且可执行。
67
+
68
+ ## E2E 测试规则
69
+
70
+ 使用 Playwright 或 Cypress 时:
71
+
72
+ - 遵循 **Page Object**,spec 内不写裸选择器;优先 **`data-testid`**,其次 **`role` / `label`**
73
+ - 用 **`test.describe` + `beforeEach`** 组织场景,单用例可独立运行、不依赖执行顺序
74
+ - 禁止用固定 **`sleep`** 当主要同步手段;用 **Locator 自动等待**、`expect`、`waitForResponse` 等
75
+ - Playwright:**`playwright.config.ts`** 中配置 `baseURL`、CI 下 `retries`/`workers`、`trace`/`screenshot`/`video`、**`webServer`** 与多 **`projects`(含移动端)**
76
+ - 关键流程至少覆盖桌面、平板、移动端视口(或等价 device 项目)
77
+ - **不稳定用例**:`test.fixme` / `test.skip` 需写原因与 issue;用 `--repeat-each` 辅助定位 flaky
78
+ - 失败时保留 **截图、Trace、视频**,CI 用 **artifact** 上传 HTML 报告与产物
79
+ - 高风险/资金类流程:**勿在生产跑真实 E2E**;staging 或 mock,必要时 `test.skip`
80
+ - 测试数据可重复:优先 seed、测试账号或 mock 服务;随机值必须带唯一前缀并在 teardown 清理
81
+
82
+ 详细模式与示例见插件 **`fec-e2e-testing`** skill。
83
+
84
+ ## 重构规则
85
+
86
+ 进行重构时:
87
+
88
+ - 除非任务明确要求改行为,否则保持行为一致
89
+ - 说明可能的迁移风险
90
+ - 优先做渐进式修改,而不是大范围重写
91
+ - 总结改动文件、执行过的命令和剩余风险
92
+
93
+ ## 验证失败处理
94
+
95
+ - 按文件和根因分组错误,一次修复一类问题。
96
+ - 每次修复后重新运行最近的失败命令。
97
+ - 不删除失败测试、不关闭规则、不降低类型安全来换取通过。
98
+ - 同一错误多次修复仍失败时,停止扩大改动并报告阻塞。