@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,355 @@
1
+ # TypeScript / JavaScript 规则
2
+
3
+ 编写、修改或评审 `.ts`、`.tsx`、`.js`、`.jsx` 时应用本文件。注释风格另见 `fec-code-comments.md`;E2E 与校验流程另见 `fec-testing.md`。
4
+
5
+ ## 类型与接口
6
+
7
+ 用类型让对外 API、共享模型与组件 props 显式、可读、可复用。
8
+
9
+ ### 对外导出的 API
10
+
11
+ - 对**导出**的函数、共享工具函数、公开类方法,写明参数与返回值类型。
12
+ - **局部**变量在类型显而易见时交给 TypeScript 推断。
13
+ - 重复出现的内联对象形状抽成具名 `interface` 或 `type`。
14
+
15
+ ```typescript
16
+ // 错误:导出函数缺少显式类型
17
+ export function formatUser(user) {
18
+ return `${user.firstName} ${user.lastName}`;
19
+ }
20
+
21
+ // 正确:对外 API 显式标注
22
+ interface User {
23
+ firstName: string;
24
+ lastName: string;
25
+ }
26
+
27
+ export function formatUser(user: User): string {
28
+ return `${user.firstName} ${user.lastName}`;
29
+ }
30
+ ```
31
+
32
+ ### `interface` 与 `type`
33
+
34
+ - 可能被扩展或 `implements` 的**对象形状**优先用 `interface`。
35
+ - **联合、交叉、元组、映射类型、工具类型组合**用 `type`。
36
+ - 优先**字符串字面量联合**;仅在互操作或团队统一要求时使用 `enum`。
37
+
38
+ ```typescript
39
+ interface User {
40
+ id: string;
41
+ email: string;
42
+ }
43
+
44
+ type UserRole = "admin" | "member";
45
+ type UserWithRole = User & { role: UserRole };
46
+ ```
47
+
48
+ ### 函数参数:复杂类型宜具名
49
+
50
+ - 参数上的**复杂联合**、**内联对象类型**、**较复杂的回调签名**等,应**优先**提取为具名 `type` / `interface`,再在函数签名中引用,便于阅读、复测与重构。
51
+ - **仅当**类型**简单**、**短小**、一眼可读,且**明显无复用**价值时,允许在参数位置内联(如单独的 `string`、`number`、`boolean` 等)。
52
+
53
+ ```typescript
54
+ // 不推荐:联合与可选散落在参数上,语义不突出
55
+ function getUserInfo(id: string | number | undefined) {}
56
+
57
+ // 推荐:具名类型表达「用户标识」语义,可选更自然
58
+ type UserId = string | number;
59
+ function getUserInfo(id?: UserId) {}
60
+ ```
61
+
62
+ ```typescript
63
+ // 不推荐:内联联合对象冗长,难复用、难单测描述
64
+ function send(data: string | { content: string; type: "text" | "html" }) {}
65
+
66
+ // 推荐:消息载荷单一真源
67
+ type MessagePayload =
68
+ | string
69
+ | {
70
+ content: string;
71
+ type: "text" | "html";
72
+ };
73
+
74
+ function send(data: MessagePayload) {}
75
+ ```
76
+
77
+ ### 避免 `any`
78
+
79
+ - 业务代码中避免 `any`。
80
+ - 外部或不可信数据用 `unknown`,再安全收窄。
81
+ - 类型随调用方变化时用泛型。
82
+
83
+ ```typescript
84
+ // 错误:any 取消类型检查
85
+ function getErrorMessage(error: any) {
86
+ return error.message;
87
+ }
88
+
89
+ // 正确:unknown 强制收窄
90
+ function getErrorMessage(error: unknown): string {
91
+ if (error instanceof Error) {
92
+ return error.message;
93
+ }
94
+ return "Unexpected error";
95
+ }
96
+ ```
97
+
98
+ ### React 组件 Props
99
+
100
+ - 用具名 `interface` 或 `type` 定义 props。
101
+ - 回调 props 写清参数与返回值。
102
+ - 无特殊理由不使用 `React.FC`(避免隐式 `children` 等差异)。
103
+
104
+ ```typescript
105
+ interface User {
106
+ id: string;
107
+ email: string;
108
+ }
109
+
110
+ interface UserCardProps {
111
+ user: User;
112
+ onSelect: (id: string) => void;
113
+ }
114
+
115
+ function UserCard({ user, onSelect }: UserCardProps) {
116
+ return <button onClick={() => onSelect(user.id)}>{user.email}</button>;
117
+ }
118
+ ```
119
+
120
+ ## 单文件规模与模块拆分
121
+
122
+ - `.ts` / `.tsx` / `.js` / `.jsx` 单文件建议控制在 **约 300 行以内**。该阈值是可维护性与评审效率的经验上限,不是机械的硬限制。
123
+ - 当文件明显超过该规模且承担多重职责时,应优先按职责拆分:如数据访问、业务规则、视图渲染、适配层、常量与映射。
124
+ - 超阈值优先提取:纯函数、子组件、自定义 Hook、`*.types.ts` 类型模块、常量表,不要仅为压行数做无意义切分。
125
+ - 可接受例外:生成代码、极薄的 re-export 聚合文件、经团队评审确认的高内聚模块;例外建议在文件头简短注明原因。
126
+
127
+ ### 仍为 JavaScript 的文件
128
+
129
+ - 在 `.js` / `.jsx` 中,若短期无法迁 TS,可用 **JSDoc** 补类型,并与运行时行为一致。
130
+
131
+ ```javascript
132
+ /**
133
+ * @param {{ firstName: string, lastName: string }} user
134
+ * @returns {string}
135
+ */
136
+ export function formatUser(user) {
137
+ return `${user.firstName} ${user.lastName}`;
138
+ }
139
+ ```
140
+
141
+ ## 禁止 Magic Number / Magic String
142
+
143
+ - **业务代码中禁止**使用**无语义**的硬编码数字或字符串(如 `1`、`2`、`3`、`"1"`、`"2"`、`"3"`)直接表示**状态、类型、标识或业务含义**(含 `if`/`switch`/赋值与 API 字段映射等)。
144
+ - **固定且有限的取值范围**须在单一真源处定义,并在全仓引用名称,避免裸值散落:
145
+ - **`enum`**(与后端或协议对齐、或团队明确约定时使用;注意字符串 enum、const enum 与打包/tree-shaking 策略);
146
+ - **`as const` 常量对象**(常与 `typeof` / `keyof` 推导联合类型,适合前端主路径);
147
+ - **字面量联合类型**(`type Status = "a" | "b"`)并与上面对象或 map 配套,保证调用处可收窄、可重构。
148
+ - **不属本条**的典型例外(仍应保持可读):纯算法下标、 obvious 的 `0`/`1` 长度判断、与业务无关的 UI 刻度若已有设计 Token 则改走 `fec-design-system.md`。
149
+
150
+ ```typescript
151
+ // 不佳:业务语义依赖裸数字 / 裸字符串
152
+ function label(status: number) {
153
+ if (status === 1) return "待支付";
154
+ if (status === 2) return "已支付";
155
+ return "未知";
156
+ }
157
+ if (user.role === "3") {
158
+ /* ... */
159
+ }
160
+
161
+ // 更佳:字面量联合 + as const 常量对象(或团队约定的 enum)
162
+ type OrderStatus = "pending" | "paid" | "cancelled";
163
+ const ORDER_STATUS = {
164
+ Pending: "pending",
165
+ Paid: "paid",
166
+ Cancelled: "cancelled",
167
+ } as const satisfies Record<string, OrderStatus>;
168
+
169
+ function label(status: OrderStatus) {
170
+ if (status === ORDER_STATUS.Pending) return "待支付";
171
+ if (status === ORDER_STATUS.Paid) return "已支付";
172
+ return "已取消";
173
+ }
174
+ ```
175
+
176
+ ## 不可变更新
177
+
178
+ 优先用展开运算符合并新对象,避免直接改写入参。
179
+
180
+ ```typescript
181
+ interface User {
182
+ id: string;
183
+ name: string;
184
+ }
185
+
186
+ // 错误:修改原对象
187
+ function updateUser(user: User, name: string): User {
188
+ user.name = name;
189
+ return user;
190
+ }
191
+
192
+ // 正确:返回新对象
193
+ function updateUser(user: Readonly<User>, name: string): User {
194
+ return { ...user, name };
195
+ }
196
+ ```
197
+
198
+ ## 异步与错误处理
199
+
200
+ 使用 `async/await` 与 `try/catch`,在 `catch` 中将错误视为 `unknown` 再收窄。
201
+
202
+ ```typescript
203
+ interface User {
204
+ id: string;
205
+ email: string;
206
+ }
207
+
208
+ declare function riskyOperation(userId: string): Promise<User>;
209
+
210
+ function getErrorMessage(error: unknown): string {
211
+ if (error instanceof Error) {
212
+ return error.message;
213
+ }
214
+ return "Unexpected error";
215
+ }
216
+
217
+ const logger = {
218
+ error: (message: string, error: unknown) => {
219
+ // 替换为项目内的日志实现(如 pino、winston 等)
220
+ },
221
+ };
222
+
223
+ async function loadUser(userId: string): Promise<User> {
224
+ try {
225
+ return await riskyOperation(userId);
226
+ } catch (error: unknown) {
227
+ logger.error("Operation failed", error);
228
+ throw new Error(getErrorMessage(error));
229
+ }
230
+ }
231
+ ```
232
+
233
+ ## 输入校验
234
+
235
+ 对外部输入(表单、API、URL 参数等)宜用 **Zod**(或项目选用的同类库)做模式校验,并用 `z.infer` 推导类型。
236
+
237
+ ```typescript
238
+ import { z } from "zod";
239
+
240
+ const userSchema = z.object({
241
+ email: z.string().email(),
242
+ age: z.number().int().min(0).max(150),
243
+ });
244
+
245
+ type UserInput = z.infer<typeof userSchema>;
246
+
247
+ const validated: UserInput = userSchema.parse(input);
248
+ ```
249
+
250
+ ## 类型资产分层与命名
251
+
252
+ - 模块或特性专属类型使用 `*.types.ts`,并与实现文件同目录或同 feature 目录放置,例如 `user.types.ts`、`billing.types.ts`。
253
+ - 全局与环境相关声明放在 `global.d.ts`、`env.d.ts` 或 `types/*.d.ts`,仅用于真全局或 ambient 声明,不将可模块化类型放入全局。
254
+ - 仅用于类型的导入导出优先使用 `import type` 与 `export type`,减少值空间歧义并提升编译语义清晰度。
255
+ - 与 API DTO 同源的类型,放在对应 feature 或 API 子目录的 `*.types.ts`,避免在页面或组件实现内散落大型匿名类型。
256
+
257
+ ```typescript
258
+ // user.types.ts
259
+ export interface UserProfile {
260
+ id: string;
261
+ email: string;
262
+ status: "active" | "disabled";
263
+ }
264
+
265
+ // user.service.ts
266
+ import type { UserProfile } from "./user.types";
267
+ export type { UserProfile };
268
+ ```
269
+
270
+ ## 工程化与惯用法补充
271
+
272
+ - 使用**判别式联合**配合 `never` 穷尽检查,确保分支新增成员时编译期可发现遗漏。
273
+ - 需要同时满足「字面量保留」与「结构校验」时优先使用 `satisfies`,再考虑类型断言。
274
+ - 优先使用类型收窄(`typeof` / `in` / 自定义 predicate)而非 `as` 强转;`as` 应用于边界互操作而非消错。
275
+ - 对不应被修改的数据优先建模为 `readonly` / `Readonly<T>`,与不可变更新规则协同。
276
+ - 新业务代码默认采用 ES Module;`namespace` 与三斜线指令仅用于声明合并或遗留互操作场景。
277
+ - `index.ts` 聚合导出应保持浅层且按 feature 边界组织,避免深层 barrel 引发循环依赖与不必要的耦合。
278
+ - 扩展第三方类型时使用独立声明文件(如 `types/vendor-foo.d.ts`)并通过 `declare module "pkg"` 局部扩展,避免污染全局实现文件。
279
+ - `tsconfig` 应保持 `strict` 族能力;若为兼容遗留场景需要放宽严格项,必须在评审中明确说明范围、风险与回收计划。
280
+ - 可在消费项目使用 lint(如 `max-lines`)辅助识别超长文件,但规则设计应服务可维护性,而非追求机械达标。
281
+
282
+ ## 日志与 `console.log`
283
+
284
+ - 生产路径避免遗留 `console.log`;使用项目统一的日志方案。
285
+ - 可在保存后格式化、`tsc` 检查或提交前脚本中对 `console.log` 做提示或拦截(按团队工具链配置)。
286
+
287
+ ## 常见模式
288
+
289
+ ### 统一 API 响应形状(示例)
290
+
291
+ ```typescript
292
+ interface ApiResponse<T> {
293
+ success: boolean;
294
+ data?: T;
295
+ error?: string;
296
+ meta?: {
297
+ total: number;
298
+ page: number;
299
+ limit: number;
300
+ };
301
+ }
302
+ ```
303
+
304
+ ### 自定义 Hook(示例)
305
+
306
+ ```typescript
307
+ export function useDebounce<T>(value: T, delay: number): T {
308
+ const [debouncedValue, setDebouncedValue] = useState<T>(value);
309
+
310
+ useEffect(() => {
311
+ const handler = setTimeout(() => setDebouncedValue(value), delay);
312
+ return () => clearTimeout(handler);
313
+ }, [value, delay]);
314
+
315
+ return debouncedValue;
316
+ }
317
+ ```
318
+
319
+ ### 仓储接口(示例)
320
+
321
+ ```typescript
322
+ interface Repository<T> {
323
+ findAll(filters?: Filters): Promise<T[]>;
324
+ findById(id: string): Promise<T | null>;
325
+ create(data: CreateDto): Promise<T>;
326
+ update(id: string, data: UpdateDto): Promise<T>;
327
+ delete(id: string): Promise<void>;
328
+ }
329
+ ```
330
+
331
+ ## 密钥与敏感配置
332
+
333
+ - **禁止**在源码中硬编码密钥、Token、私钥。
334
+ - **必须**通过环境变量或构建期注入(如 `process.env.*`、`import.meta.env.*`,以项目脚手架为准),并在缺失时显式失败或降级策略清晰。
335
+
336
+ ```typescript
337
+ // 错误:硬编码密钥
338
+ const apiKey = "sk-proj-xxxxx";
339
+
340
+ // 正确:环境变量(Node 示例;Vite 等请用 import.meta.env 及 VITE_ 前缀约定)
341
+ const apiKey = process.env.OPENAI_API_KEY;
342
+ if (!apiKey) {
343
+ throw new Error("OPENAI_API_KEY not configured");
344
+ }
345
+ ```
346
+
347
+ 涉及认证、支付、上传等场景时,结合项目安全规范做专项评审。
348
+
349
+ ## 与测试规则的关系
350
+
351
+ 关键用户路径的端到端覆盖方式(Playwright、Cypress、Page Object 等)以 `fec-testing.md` 为准;本文件不重复展开 E2E 细则。
352
+
353
+ ## 与 `typescript-reviewer` 子代理
354
+
355
+ 对 **`.ts` / `.tsx` / `.js` / `.jsx`** 进行专项评审(先跑 typecheck/eslint、PR 合并就绪检查、分级结论)时,可委托插件内置的 **`typescript-reviewer`** 子代理;其报告默认写入 `reports/typescript-review-YYYY-MM-DD-HHmmss.md`,规则底线仍以本文件与项目 `CLAUDE.md` 为准。
@@ -0,0 +1,64 @@
1
+ # Vue 规则
2
+
3
+ 当仓库或目标模块使用 Vue 时,应用本文件。
4
+
5
+ ## 技术栈
6
+
7
+ <!-- 请根据项目实际情况修改 -->
8
+
9
+ - 框架: Vue 3 + TypeScript
10
+ - 状态管理: Pinia
11
+ - UI 组件库: 按项目实际选择(如 Element Plus、Naive UI、Vant 或内部 Design System)
12
+ - 版本与依赖:新建模块、补充 `package.json` 或更新本节前,优先采用彼此兼容的主流稳定版本(对齐官方文档、脚手架默认值或包管理器推荐),避免混用已停止维护或与仓库主线 major 不匹配的依赖。
13
+
14
+ ## Vue 组件规范
15
+
16
+ - 使用 `<script setup lang="ts">`
17
+ - 明确使用 `defineProps` 和 `defineEmits`
18
+ - 保持模板逻辑简单、可读
19
+ - 将可复用逻辑提取到 composables
20
+ - 优先使用 computed,而不是大范围 watcher
21
+ - 保持组件职责聚焦,避免上帝组件
22
+ - props、emits、refs 和 expose 方法尽量使用强类型
23
+
24
+ ## Vue 实现指导
25
+
26
+ 创建新组件前:
27
+
28
+ 1. 先搜索项目中是否已有可复用组件
29
+ 2. 判断逻辑是否适合提取到 composable
30
+ 3. 检查样式是否应沿用周边现有模式
31
+
32
+ 编辑 Vue 组件时:
33
+
34
+ - 在可能的情况下,不要把 API 调用直接放进纯展示组件
35
+ - 不要在组件文件中内联大段业务逻辑
36
+ - 不要重复维护可从 props 或 store 推导出的状态
37
+ - 事件 payload 要明确且有类型约束
38
+
39
+ ## Vue 文件组织
40
+
41
+ 优先遵循项目已有约定。
42
+ 常见输出可能包括:
43
+
44
+ - `ComponentName.vue`
45
+ - `types.ts`
46
+ - `useXxx.ts`
47
+ - 只有在符合仓库模式时才新增本地样式文件
48
+
49
+ ## 组件文件规模
50
+
51
+ - 单个 `.vue` 文件或同一组件模块保持**职责单一**、语义清晰、易于维护。
52
+ - **行数参考**:优先控制在约 **300 行**以内;超过 **500 行**应视为**强烈拆分信号**。
53
+ - **未到 500 行也应拆分**的情形:同时存在**复杂响应式状态**、**过多副作用 / watch**、**模板嵌套过深**、**`<script setup>` 内逻辑过长**、密集条件分支等,应拆为**子组件**、**Composables**、**工具模块**、**常量**与**类型定义**等(与上文「Vue 组件规范」「Vue 文件组织」一致)。
54
+
55
+ ## Vue 反模式
56
+
57
+ 避免:
58
+
59
+ - 本该使用 computed 却使用大范围 watcher
60
+ - 对 props、emits 或 refs 无理由使用 `any`
61
+ - 模板分支层级过深却不提取
62
+ - 在一个组件中混入无关职责
63
+ - 单 `.vue` **逾 500 行或复杂度已高**仍拒不拆分(参见上文「组件文件规模」)
64
+ - 用大范围全局样式覆盖去解决局部 UI 问题
@@ -0,0 +1,50 @@
1
+ # 工作模式规则
2
+
3
+ 根据任务阶段选择合适的工作模式,避免一边探索一边大改代码。
4
+
5
+ ## 调研模式
6
+
7
+ 适用于需求不清、现状复杂、需要比较方案或定位风险时。
8
+
9
+ - 先阅读 README、项目规则、相关源码和最近变更。
10
+ - 用 `rg` 查找已有模式、组件、工具函数和测试。
11
+ - 先列发现,再给建议。
12
+ - 在证据不足时不要下确定结论。
13
+ - 涉及版本敏感框架、库或平台行为时,先查项目内事实和官方来源。
14
+
15
+ ## 计划模式
16
+
17
+ 适用于复杂功能、架构调整、跨文件重构和高风险修复。
18
+
19
+ - 重述目标、成功标准和不做什么。
20
+ - 标出影响范围、文件边界、依赖关系、风险和验证方式。
21
+ - 计划应能分批执行,每批都有可验证结果。
22
+ - 用户未确认前,不执行大范围实现。
23
+
24
+ ## 开发模式
25
+
26
+ 适用于目标明确且已有计划或范围很小的实现。
27
+
28
+ - 优先复用现有模式。
29
+ - 行为变更优先使用 TDD:先失败测试,再最小实现,再重构。
30
+ - 每次关键修改后运行最近的验证命令。
31
+ - 完成时总结改动、命令和剩余风险。
32
+ - 行为、接口或性能假设必须能被类型、测试、构建、浏览器观察或文档来源支撑。
33
+
34
+ ## 评审模式
35
+
36
+ 适用于 PR、最近变更、合并前检查和专项审查。
37
+
38
+ - 先通读上下文,再按严重程度列问题。
39
+ - 优先报告会导致 bug、安全风险、回归或维护成本明显上升的问题。
40
+ - 每个问题给出文件位置、影响、建议修复方式和置信度。
41
+ - 无问题时明确说明剩余测试缺口。
42
+
43
+ ## 收尾模式
44
+
45
+ 适用于提交前或交付前。
46
+
47
+ - 运行 lint、type-check、test、build 中与改动相关的命令。
48
+ - 检查是否有调试代码、临时文件、未同步文档或未说明的风险。
49
+ - 不在未经确认时提交或推送。
50
+ - 不用“应该可以”作为交付依据;交付前报告实际运行过的命令和结果。