@mison/ag-kit-cn 2.0.1

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 (237) hide show
  1. package/.agent/.shared/ui-ux-pro-max/data/charts.csv +26 -0
  2. package/.agent/.shared/ui-ux-pro-max/data/colors.csv +97 -0
  3. package/.agent/.shared/ui-ux-pro-max/data/icons.csv +101 -0
  4. package/.agent/.shared/ui-ux-pro-max/data/landing.csv +31 -0
  5. package/.agent/.shared/ui-ux-pro-max/data/products.csv +97 -0
  6. package/.agent/.shared/ui-ux-pro-max/data/prompts.csv +24 -0
  7. package/.agent/.shared/ui-ux-pro-max/data/react-performance.csv +45 -0
  8. package/.agent/.shared/ui-ux-pro-max/data/stacks/flutter.csv +53 -0
  9. package/.agent/.shared/ui-ux-pro-max/data/stacks/html-tailwind.csv +56 -0
  10. package/.agent/.shared/ui-ux-pro-max/data/stacks/jetpack-compose.csv +53 -0
  11. package/.agent/.shared/ui-ux-pro-max/data/stacks/nextjs.csv +53 -0
  12. package/.agent/.shared/ui-ux-pro-max/data/stacks/nuxt-ui.csv +51 -0
  13. package/.agent/.shared/ui-ux-pro-max/data/stacks/nuxtjs.csv +59 -0
  14. package/.agent/.shared/ui-ux-pro-max/data/stacks/react-native.csv +52 -0
  15. package/.agent/.shared/ui-ux-pro-max/data/stacks/react.csv +54 -0
  16. package/.agent/.shared/ui-ux-pro-max/data/stacks/shadcn.csv +61 -0
  17. package/.agent/.shared/ui-ux-pro-max/data/stacks/svelte.csv +54 -0
  18. package/.agent/.shared/ui-ux-pro-max/data/stacks/swiftui.csv +51 -0
  19. package/.agent/.shared/ui-ux-pro-max/data/stacks/vue.csv +50 -0
  20. package/.agent/.shared/ui-ux-pro-max/data/styles.csv +59 -0
  21. package/.agent/.shared/ui-ux-pro-max/data/typography.csv +58 -0
  22. package/.agent/.shared/ui-ux-pro-max/data/ui-reasoning.csv +101 -0
  23. package/.agent/.shared/ui-ux-pro-max/data/ux-guidelines.csv +100 -0
  24. package/.agent/.shared/ui-ux-pro-max/data/web-interface.csv +31 -0
  25. package/.agent/.shared/ui-ux-pro-max/scripts/core.py +258 -0
  26. package/.agent/.shared/ui-ux-pro-max/scripts/design_system.py +1067 -0
  27. package/.agent/.shared/ui-ux-pro-max/scripts/search.py +106 -0
  28. package/.agent/ARCHITECTURE.md +285 -0
  29. package/.agent/agents/backend-specialist.md +268 -0
  30. package/.agent/agents/code-archaeologist.md +106 -0
  31. package/.agent/agents/database-architect.md +225 -0
  32. package/.agent/agents/debugger.md +225 -0
  33. package/.agent/agents/devops-engineer.md +242 -0
  34. package/.agent/agents/documentation-writer.md +104 -0
  35. package/.agent/agents/explorer-agent.md +73 -0
  36. package/.agent/agents/frontend-specialist.md +618 -0
  37. package/.agent/agents/game-developer.md +162 -0
  38. package/.agent/agents/mobile-developer.md +382 -0
  39. package/.agent/agents/orchestrator.md +438 -0
  40. package/.agent/agents/penetration-tester.md +188 -0
  41. package/.agent/agents/performance-optimizer.md +187 -0
  42. package/.agent/agents/product-manager.md +112 -0
  43. package/.agent/agents/product-owner.md +95 -0
  44. package/.agent/agents/project-planner.md +405 -0
  45. package/.agent/agents/qa-automation-engineer.md +103 -0
  46. package/.agent/agents/security-auditor.md +170 -0
  47. package/.agent/agents/seo-specialist.md +111 -0
  48. package/.agent/agents/test-engineer.md +158 -0
  49. package/.agent/mcp_config.json +12 -0
  50. package/.agent/rules/GEMINI.md +273 -0
  51. package/.agent/scripts/auto_preview.py +148 -0
  52. package/.agent/scripts/checklist.py +217 -0
  53. package/.agent/scripts/session_manager.py +120 -0
  54. package/.agent/scripts/verify_all.py +327 -0
  55. package/.agent/skills/api-patterns/SKILL.md +84 -0
  56. package/.agent/skills/api-patterns/api-style.md +42 -0
  57. package/.agent/skills/api-patterns/auth.md +24 -0
  58. package/.agent/skills/api-patterns/documentation.md +26 -0
  59. package/.agent/skills/api-patterns/graphql.md +41 -0
  60. package/.agent/skills/api-patterns/rate-limiting.md +31 -0
  61. package/.agent/skills/api-patterns/response.md +37 -0
  62. package/.agent/skills/api-patterns/rest.md +40 -0
  63. package/.agent/skills/api-patterns/scripts/api_validator.py +211 -0
  64. package/.agent/skills/api-patterns/security-testing.md +122 -0
  65. package/.agent/skills/api-patterns/trpc.md +41 -0
  66. package/.agent/skills/api-patterns/versioning.md +22 -0
  67. package/.agent/skills/app-builder/SKILL.md +75 -0
  68. package/.agent/skills/app-builder/agent-coordination.md +74 -0
  69. package/.agent/skills/app-builder/feature-building.md +53 -0
  70. package/.agent/skills/app-builder/project-detection.md +34 -0
  71. package/.agent/skills/app-builder/scaffolding.md +118 -0
  72. package/.agent/skills/app-builder/tech-stack.md +40 -0
  73. package/.agent/skills/app-builder/templates/SKILL.md +39 -0
  74. package/.agent/skills/app-builder/templates/astro-static/TEMPLATE.md +76 -0
  75. package/.agent/skills/app-builder/templates/chrome-extension/TEMPLATE.md +92 -0
  76. package/.agent/skills/app-builder/templates/cli-tool/TEMPLATE.md +88 -0
  77. package/.agent/skills/app-builder/templates/electron-desktop/TEMPLATE.md +88 -0
  78. package/.agent/skills/app-builder/templates/express-api/TEMPLATE.md +83 -0
  79. package/.agent/skills/app-builder/templates/flutter-app/TEMPLATE.md +90 -0
  80. package/.agent/skills/app-builder/templates/monorepo-turborepo/TEMPLATE.md +90 -0
  81. package/.agent/skills/app-builder/templates/nextjs-fullstack/TEMPLATE.md +122 -0
  82. package/.agent/skills/app-builder/templates/nextjs-saas/TEMPLATE.md +122 -0
  83. package/.agent/skills/app-builder/templates/nextjs-static/TEMPLATE.md +169 -0
  84. package/.agent/skills/app-builder/templates/nuxt-app/TEMPLATE.md +134 -0
  85. package/.agent/skills/app-builder/templates/python-fastapi/TEMPLATE.md +83 -0
  86. package/.agent/skills/app-builder/templates/react-native-app/TEMPLATE.md +119 -0
  87. package/.agent/skills/architecture/SKILL.md +57 -0
  88. package/.agent/skills/architecture/context-discovery.md +43 -0
  89. package/.agent/skills/architecture/examples.md +94 -0
  90. package/.agent/skills/architecture/pattern-selection.md +68 -0
  91. package/.agent/skills/architecture/patterns-reference.md +50 -0
  92. package/.agent/skills/architecture/trade-off-analysis.md +77 -0
  93. package/.agent/skills/bash-linux/SKILL.md +201 -0
  94. package/.agent/skills/behavioral-modes/SKILL.md +264 -0
  95. package/.agent/skills/brainstorming/SKILL.md +164 -0
  96. package/.agent/skills/brainstorming/dynamic-questioning.md +359 -0
  97. package/.agent/skills/clean-code/SKILL.md +200 -0
  98. package/.agent/skills/code-review-checklist/SKILL.md +125 -0
  99. package/.agent/skills/database-design/SKILL.md +54 -0
  100. package/.agent/skills/database-design/database-selection.md +43 -0
  101. package/.agent/skills/database-design/indexing.md +39 -0
  102. package/.agent/skills/database-design/migrations.md +50 -0
  103. package/.agent/skills/database-design/optimization.md +36 -0
  104. package/.agent/skills/database-design/orm-selection.md +30 -0
  105. package/.agent/skills/database-design/schema-design.md +56 -0
  106. package/.agent/skills/database-design/scripts/schema_validator.py +172 -0
  107. package/.agent/skills/deployment-procedures/SKILL.md +241 -0
  108. package/.agent/skills/doc.md +177 -0
  109. package/.agent/skills/documentation-templates/SKILL.md +194 -0
  110. package/.agent/skills/frontend-design/SKILL.md +418 -0
  111. package/.agent/skills/frontend-design/animation-guide.md +331 -0
  112. package/.agent/skills/frontend-design/color-system.md +307 -0
  113. package/.agent/skills/frontend-design/decision-trees.md +418 -0
  114. package/.agent/skills/frontend-design/motion-graphics.md +306 -0
  115. package/.agent/skills/frontend-design/scripts/accessibility_checker.py +183 -0
  116. package/.agent/skills/frontend-design/scripts/ux_audit.py +727 -0
  117. package/.agent/skills/frontend-design/typography-system.md +345 -0
  118. package/.agent/skills/frontend-design/ux-psychology.md +1118 -0
  119. package/.agent/skills/frontend-design/visual-effects.md +383 -0
  120. package/.agent/skills/game-development/2d-games/SKILL.md +119 -0
  121. package/.agent/skills/game-development/3d-games/SKILL.md +135 -0
  122. package/.agent/skills/game-development/SKILL.md +167 -0
  123. package/.agent/skills/game-development/game-art/SKILL.md +185 -0
  124. package/.agent/skills/game-development/game-audio/SKILL.md +190 -0
  125. package/.agent/skills/game-development/game-design/SKILL.md +129 -0
  126. package/.agent/skills/game-development/mobile-games/SKILL.md +108 -0
  127. package/.agent/skills/game-development/multiplayer/SKILL.md +132 -0
  128. package/.agent/skills/game-development/pc-games/SKILL.md +144 -0
  129. package/.agent/skills/game-development/vr-ar/SKILL.md +123 -0
  130. package/.agent/skills/game-development/web-games/SKILL.md +150 -0
  131. package/.agent/skills/geo-fundamentals/SKILL.md +155 -0
  132. package/.agent/skills/geo-fundamentals/scripts/geo_checker.py +289 -0
  133. package/.agent/skills/i18n-localization/SKILL.md +154 -0
  134. package/.agent/skills/i18n-localization/scripts/i18n_checker.py +241 -0
  135. package/.agent/skills/intelligent-routing/SKILL.md +335 -0
  136. package/.agent/skills/lint-and-validate/SKILL.md +44 -0
  137. package/.agent/skills/lint-and-validate/scripts/lint_runner.py +184 -0
  138. package/.agent/skills/lint-and-validate/scripts/type_coverage.py +173 -0
  139. package/.agent/skills/mcp-builder/SKILL.md +176 -0
  140. package/.agent/skills/mobile-design/SKILL.md +394 -0
  141. package/.agent/skills/mobile-design/decision-trees.md +516 -0
  142. package/.agent/skills/mobile-design/mobile-backend.md +491 -0
  143. package/.agent/skills/mobile-design/mobile-color-system.md +420 -0
  144. package/.agent/skills/mobile-design/mobile-debugging.md +122 -0
  145. package/.agent/skills/mobile-design/mobile-design-thinking.md +355 -0
  146. package/.agent/skills/mobile-design/mobile-navigation.md +458 -0
  147. package/.agent/skills/mobile-design/mobile-performance.md +767 -0
  148. package/.agent/skills/mobile-design/mobile-testing.md +356 -0
  149. package/.agent/skills/mobile-design/mobile-typography.md +432 -0
  150. package/.agent/skills/mobile-design/platform-android.md +666 -0
  151. package/.agent/skills/mobile-design/platform-ios.md +561 -0
  152. package/.agent/skills/mobile-design/scripts/mobile_audit.py +670 -0
  153. package/.agent/skills/mobile-design/touch-psychology.md +537 -0
  154. package/.agent/skills/nextjs-react-expert/1-async-eliminating-waterfalls.md +311 -0
  155. package/.agent/skills/nextjs-react-expert/2-bundle-bundle-size-optimization.md +241 -0
  156. package/.agent/skills/nextjs-react-expert/3-server-server-side-performance.md +489 -0
  157. package/.agent/skills/nextjs-react-expert/4-client-client-side-data-fetching.md +263 -0
  158. package/.agent/skills/nextjs-react-expert/5-rerender-re-render-optimization.md +581 -0
  159. package/.agent/skills/nextjs-react-expert/6-rendering-rendering-performance.md +431 -0
  160. package/.agent/skills/nextjs-react-expert/7-js-javascript-performance.md +683 -0
  161. package/.agent/skills/nextjs-react-expert/8-advanced-advanced-patterns.md +149 -0
  162. package/.agent/skills/nextjs-react-expert/SKILL.md +286 -0
  163. package/.agent/skills/nextjs-react-expert/scripts/convert_rules.py +222 -0
  164. package/.agent/skills/nextjs-react-expert/scripts/react_performance_checker.py +252 -0
  165. package/.agent/skills/nodejs-best-practices/SKILL.md +333 -0
  166. package/.agent/skills/parallel-agents/SKILL.md +194 -0
  167. package/.agent/skills/performance-profiling/SKILL.md +149 -0
  168. package/.agent/skills/performance-profiling/scripts/lighthouse_audit.py +76 -0
  169. package/.agent/skills/plan-writing/SKILL.md +152 -0
  170. package/.agent/skills/powershell-windows/SKILL.md +166 -0
  171. package/.agent/skills/python-patterns/SKILL.md +441 -0
  172. package/.agent/skills/red-team-tactics/SKILL.md +203 -0
  173. package/.agent/skills/rust-pro/SKILL.md +190 -0
  174. package/.agent/skills/seo-fundamentals/SKILL.md +135 -0
  175. package/.agent/skills/seo-fundamentals/scripts/seo_checker.py +215 -0
  176. package/.agent/skills/server-management/SKILL.md +161 -0
  177. package/.agent/skills/systematic-debugging/SKILL.md +114 -0
  178. package/.agent/skills/tailwind-patterns/SKILL.md +269 -0
  179. package/.agent/skills/tdd-workflow/SKILL.md +149 -0
  180. package/.agent/skills/testing-patterns/SKILL.md +178 -0
  181. package/.agent/skills/testing-patterns/scripts/test_runner.py +219 -0
  182. package/.agent/skills/vulnerability-scanner/SKILL.md +276 -0
  183. package/.agent/skills/vulnerability-scanner/checklists.md +131 -0
  184. package/.agent/skills/vulnerability-scanner/scripts/security_scan.py +459 -0
  185. package/.agent/skills/web-design-guidelines/SKILL.md +57 -0
  186. package/.agent/skills/webapp-testing/SKILL.md +187 -0
  187. package/.agent/skills/webapp-testing/scripts/playwright_runner.py +173 -0
  188. package/.agent/workflows/brainstorm.md +113 -0
  189. package/.agent/workflows/create.md +59 -0
  190. package/.agent/workflows/debug.md +103 -0
  191. package/.agent/workflows/deploy.md +176 -0
  192. package/.agent/workflows/enhance.md +63 -0
  193. package/.agent/workflows/orchestrate.md +242 -0
  194. package/.agent/workflows/plan.md +89 -0
  195. package/.agent/workflows/preview.md +80 -0
  196. package/.agent/workflows/restore-localize-compat.md +525 -0
  197. package/.agent/workflows/status.md +86 -0
  198. package/.agent/workflows/test.md +144 -0
  199. package/.agent/workflows/ui-ux-pro-max.md +295 -0
  200. package/AGENT_FLOW.md +609 -0
  201. package/CHANGELOG.md +68 -0
  202. package/LICENSE +21 -0
  203. package/README.md +260 -0
  204. package/bin/adapters/base.js +63 -0
  205. package/bin/adapters/codex.js +391 -0
  206. package/bin/adapters/gemini.js +137 -0
  207. package/bin/ag-kit.js +1336 -0
  208. package/bin/core/builder.js +80 -0
  209. package/bin/core/generator.js +59 -0
  210. package/bin/core/resource-loader.js +64 -0
  211. package/bin/core/transformer.js +208 -0
  212. package/bin/interactive.js +65 -0
  213. package/bin/utils/atomic-writer.js +97 -0
  214. package/bin/utils/git-helper.js +68 -0
  215. package/bin/utils/managed-block.js +65 -0
  216. package/bin/utils/manifest.js +241 -0
  217. package/bin/utils.js +82 -0
  218. package/docs/codex-rules-template.md +36 -0
  219. package/docs/mapping-spec.md +68 -0
  220. package/docs/multi-target-adapter.md +80 -0
  221. package/docs/official/README.md +53 -0
  222. package/docs/official/antigravity/agent-modes-settings.md +64 -0
  223. package/docs/official/antigravity/rules-workflows.md +96 -0
  224. package/docs/official/antigravity/skills.md +147 -0
  225. package/docs/official/codex/agents-md.md +119 -0
  226. package/docs/official/codex/config-advanced.md +358 -0
  227. package/docs/official/codex/config-basic.md +141 -0
  228. package/docs/official/codex/config-reference.md +223 -0
  229. package/docs/official/codex/config-sample.md +216 -0
  230. package/docs/official/codex/mcp.md +107 -0
  231. package/docs/official/codex/rules.md +79 -0
  232. package/docs/official/codex/skills.md +114 -0
  233. package/docs/official/sources-index.md +32 -0
  234. package/docs/operations.md +145 -0
  235. package/docs/terminology-style-guide.md +69 -0
  236. package/package.json +51 -0
  237. package/scripts/postinstall-check.js +112 -0
@@ -0,0 +1,252 @@
1
+ #!/usr/bin/env python3
2
+ """
3
+ React Performance Checker
4
+ Automated performance audit for React/Next.js projects
5
+ Based on Vercel Engineering best practices
6
+ """
7
+
8
+ import os
9
+ import re
10
+ import json
11
+ from pathlib import Path
12
+ from typing import List, Dict, Tuple
13
+
14
+ class PerformanceChecker:
15
+ def __init__(self, project_path: str):
16
+ self.project_path = Path(project_path)
17
+ self.issues = []
18
+ self.warnings = []
19
+ self.passed = []
20
+
21
+ def check_waterfalls(self):
22
+ """Check for sequential await patterns (Section 1)"""
23
+ print("\n[*] Checking for waterfalls (sequential awaits)...")
24
+
25
+ for filepath in self.project_path.rglob('*.{ts,tsx,js,jsx}'):
26
+ if 'node_modules' in str(filepath):
27
+ continue
28
+
29
+ try:
30
+ content = filepath.read_text(encoding='utf-8')
31
+
32
+ # Pattern: multiple awaits in sequence without Promise.all
33
+ sequential_awaits = re.findall(r'await\s+\w+.*?\n\s*await\s+\w+', content)
34
+
35
+ if sequential_awaits:
36
+ self.issues.append({
37
+ 'file': str(filepath.relative_to(self.project_path)),
38
+ 'type': 'CRITICAL',
39
+ 'issue': 'Sequential awaits detected (waterfall)',
40
+ 'fix': 'Use Promise.all() for parallel fetching',
41
+ 'section': '1-async-eliminating-waterfalls.md'
42
+ })
43
+ except Exception as e:
44
+ continue
45
+
46
+ def check_barrel_imports(self):
47
+ """Check for barrel imports (Section 2)"""
48
+ print("[*] Checking for barrel imports...")
49
+
50
+ for filepath in self.project_path.rglob('*.{ts,tsx,js,jsx}'):
51
+ if 'node_modules' in str(filepath):
52
+ continue
53
+
54
+ try:
55
+ content = filepath.read_text(encoding='utf-8')
56
+
57
+ # Pattern: import from index files or barrel exports
58
+ barrel_imports = re.findall(r"import.*from\s+['\"](@/.*?)/index['\"]", content)
59
+ barrel_imports += re.findall(r"import.*from\s+['\"]\.\.?/.*?['\"](?!.*?\.tsx?)", content)
60
+
61
+ if barrel_imports:
62
+ self.warnings.append({
63
+ 'file': str(filepath.relative_to(self.project_path)),
64
+ 'type': 'CRITICAL',
65
+ 'issue': 'Potential barrel imports detected',
66
+ 'fix': 'Import directly from specific files',
67
+ 'section': '2-bundle-bundle-size-optimization.md'
68
+ })
69
+ except Exception as e:
70
+ continue
71
+
72
+ def check_dynamic_imports(self):
73
+ """Check if large components use dynamic imports (Section 2)"""
74
+ print("[*] Checking for missing dynamic imports...")
75
+
76
+ for filepath in self.project_path.rglob('*.{ts,tsx}'):
77
+ if 'node_modules' in str(filepath):
78
+ continue
79
+
80
+ try:
81
+ content = filepath.read_text(encoding='utf-8')
82
+
83
+ # Check file size - if > 10KB, should probably use dynamic import
84
+ if len(content) > 10000:
85
+ # Check if it's imported statically somewhere
86
+ filename = filepath.stem
87
+
88
+ # Search for static imports of this component
89
+ for check_file in self.project_path.rglob('*.{ts,tsx}'):
90
+ if check_file == filepath or 'node_modules' in str(check_file):
91
+ continue
92
+
93
+ check_content = check_file.read_text(encoding='utf-8')
94
+ if f"import {filename}" in check_content or f"import {{ {filename}" in check_content:
95
+ if 'dynamic(' not in check_content:
96
+ self.warnings.append({
97
+ 'file': str(check_file.relative_to(self.project_path)),
98
+ 'type': 'CRITICAL',
99
+ 'issue': f'Large component {filename} imported statically',
100
+ 'fix': 'Use dynamic() for code splitting',
101
+ 'section': '2-bundle-bundle-size-optimization.md'
102
+ })
103
+ break
104
+ except Exception as e:
105
+ continue
106
+
107
+ def check_useEffect_fetching(self):
108
+ """Check for data fetching in useEffect (Section 4)"""
109
+ print("[*] Checking for useEffect data fetching...")
110
+
111
+ for filepath in self.project_path.rglob('*.{ts,tsx}'):
112
+ if 'node_modules' in str(filepath):
113
+ continue
114
+
115
+ try:
116
+ content = filepath.read_text(encoding='utf-8')
117
+
118
+ # Pattern: fetch or axios in useEffect
119
+ if 'useEffect' in content:
120
+ if re.search(r'useEffect.*?fetch\(', content, re.DOTALL):
121
+ self.warnings.append({
122
+ 'file': str(filepath.relative_to(self.project_path)),
123
+ 'type': 'MEDIUM-HIGH',
124
+ 'issue': 'Data fetching in useEffect',
125
+ 'fix': 'Consider using SWR or React Query for deduplication',
126
+ 'section': '4-client-client-side-data-fetching.md'
127
+ })
128
+ except Exception as e:
129
+ continue
130
+
131
+ def check_missing_memoization(self):
132
+ """Check for missing React.memo, useMemo, useCallback (Section 5)"""
133
+ print("[*] Checking for missing memoization...")
134
+
135
+ for filepath in self.project_path.rglob('*.{tsx}'):
136
+ if 'node_modules' in str(filepath):
137
+ continue
138
+
139
+ try:
140
+ content = filepath.read_text(encoding='utf-8')
141
+
142
+ # Check for component definitions without memo
143
+ components = re.findall(r'(?:export\s+)?(?:const|function)\s+([A-Z]\w+)', content)
144
+
145
+ if components and 'React.memo' not in content and 'memo(' not in content:
146
+ # Check if component receives props
147
+ if 'props:' in content or 'Props>' in content:
148
+ self.warnings.append({
149
+ 'file': str(filepath.relative_to(self.project_path)),
150
+ 'type': 'MEDIUM',
151
+ 'issue': 'Component with props not memoized',
152
+ 'fix': 'Consider using React.memo if props are stable',
153
+ 'section': '5-rerender-re-render-optimization.md'
154
+ })
155
+ except Exception as e:
156
+ continue
157
+
158
+ def check_image_optimization(self):
159
+ """Check for unoptimized images (Section 6)"""
160
+ print("[*] Checking for image optimization...")
161
+
162
+ for filepath in self.project_path.rglob('*.{ts,tsx,js,jsx}'):
163
+ if 'node_modules' in str(filepath):
164
+ continue
165
+
166
+ try:
167
+ content = filepath.read_text(encoding='utf-8')
168
+
169
+ # Check for <img> tags instead of next/image
170
+ if '<img' in content and 'next/image' not in content:
171
+ self.warnings.append({
172
+ 'file': str(filepath.relative_to(self.project_path)),
173
+ 'type': 'MEDIUM',
174
+ 'issue': 'Using <img> instead of next/image',
175
+ 'fix': 'Use next/image for automatic optimization',
176
+ 'section': '6-rendering-rendering-performance.md'
177
+ })
178
+ except Exception as e:
179
+ continue
180
+
181
+ def generate_report(self):
182
+ """Generate final report"""
183
+ print("\n" + "="*60)
184
+ print("REACT PERFORMANCE AUDIT REPORT")
185
+ print("="*60)
186
+
187
+ print(f"\n[CRITICAL ISSUES] ({len([i for i in self.issues if i['type'] == 'CRITICAL'])})")
188
+ for issue in self.issues:
189
+ if issue['type'] == 'CRITICAL':
190
+ print(f" - {issue['file']}")
191
+ print(f" Issue: {issue['issue']}")
192
+ print(f" Fix: {issue['fix']}")
193
+ print(f" Reference: {issue['section']}\n")
194
+
195
+ print(f"\n[WARNINGS] ({len(self.warnings)})")
196
+ for warning in self.warnings[:10]: # Show first 10
197
+ print(f" - {warning['file']}")
198
+ print(f" Issue: {warning['issue']}")
199
+ print(f" Fix: {warning['fix']}")
200
+ print(f" Reference: {warning['section']}\n")
201
+
202
+ if len(self.warnings) > 10:
203
+ print(f" ... and {len(self.warnings) - 10} more warnings")
204
+
205
+ print("\n" + "="*60)
206
+ print(f"SUMMARY:")
207
+ print(f" Critical Issues: {len([i for i in self.issues if i['type'] == 'CRITICAL'])}")
208
+ print(f" Warnings: {len(self.warnings)}")
209
+ print("="*60)
210
+
211
+ if len(self.issues) == 0 and len(self.warnings) == 0:
212
+ print("\n[SUCCESS] No major performance issues detected!")
213
+ else:
214
+ print("\n[ACTION REQUIRED] Review and fix issues above")
215
+ print("Priority: CRITICAL > HIGH > MEDIUM > LOW")
216
+
217
+ def run(self):
218
+ """Run all checks"""
219
+ print("="*60)
220
+ print("React Performance Checker (Vercel Engineering)")
221
+ print("="*60)
222
+ print(f"Scanning: {self.project_path}")
223
+
224
+ self.check_waterfalls()
225
+ self.check_barrel_imports()
226
+ self.check_dynamic_imports()
227
+ self.check_useEffect_fetching()
228
+ self.check_missing_memoization()
229
+ self.check_image_optimization()
230
+
231
+ self.generate_report()
232
+
233
+
234
+ def main():
235
+ import sys
236
+
237
+ if len(sys.argv) < 2:
238
+ print("Usage: python react_performance_checker.py <project_path>")
239
+ sys.exit(1)
240
+
241
+ project_path = sys.argv[1]
242
+
243
+ if not os.path.exists(project_path):
244
+ print(f"[ERROR] Path not found: {project_path}")
245
+ sys.exit(1)
246
+
247
+ checker = PerformanceChecker(project_path)
248
+ checker.run()
249
+
250
+
251
+ if __name__ == '__main__':
252
+ main()
@@ -0,0 +1,333 @@
1
+ ---
2
+ name: nodejs-best-practices
3
+ description: Node.js 开发原则与决策方法。覆盖框架选型、异步模式、安全与架构设计。强调思考,而非照抄。
4
+ allowed-tools: Read, Write, Edit, Glob, Grep
5
+ ---
6
+
7
+ # Node.js 最佳实践
8
+
9
+ > 面向 2025 的 Node.js 开发原则与决策方法。
10
+ > **学习如何思考,不要只记代码套路。**
11
+
12
+ ---
13
+
14
+ ## ⚠️ 本技能使用方式
15
+
16
+ 本技能教授的是**决策原则**,不是固定代码模板。
17
+
18
+ - 需求不明确时,先向用户确认偏好
19
+ - 根据上下文(Context)选择框架与模式
20
+ - 不要每次都默认同一套方案
21
+
22
+ ---
23
+
24
+ ## 1. 框架选型(2025)
25
+
26
+ ### 决策树
27
+
28
+ ```
29
+ 你要构建什么?
30
+
31
+ ├── Edge/Serverless(边缘/无服务器,Cloudflare、Vercel)
32
+ │ └── Hono(零依赖、冷启动极快)
33
+
34
+ ├── 高性能 API
35
+ │ └── Fastify(通常比 Express 快 2-3 倍)
36
+
37
+ ├── 企业协作/团队熟悉度优先
38
+ │ └── NestJS(结构化、DI、装饰器)
39
+
40
+ ├── 传统/稳定/生态最大化
41
+ │ └── Express(成熟、middleware 最多)
42
+
43
+ └── 前后端一体
44
+ └── Next.js API Routes 或 tRPC
45
+ ```
46
+
47
+ ### 对比原则
48
+
49
+ | 维度 | Hono | Fastify | Express |
50
+ |------|------|---------|---------|
51
+ | **适用场景** | Edge、serverless | 性能优先 | 传统、学习 |
52
+ | **冷启动** | 最快 | 快 | 中等 |
53
+ | **生态** | 成长中 | 较好 | 最大 |
54
+ | **TypeScript** | 原生支持 | 优秀 | 良好 |
55
+ | **学习曲线** | 低 | 中 | 低 |
56
+
57
+ ### 选型前必须询问:
58
+ 1. 部署目标是什么?
59
+ 2. 冷启动时间是否关键?
60
+ 3. 团队是否有既有经验?
61
+ 4. 是否存在需要维护的遗留代码?
62
+
63
+ ---
64
+
65
+ ## 2. 运行时考量(2025)
66
+
67
+ ### 原生 TypeScript
68
+
69
+ ```
70
+ Node.js 22+: --experimental-strip-types
71
+ ├── 可直接运行 .ts 文件
72
+ ├── 简单项目可免构建步骤
73
+ └── 适用:脚本、简单 API
74
+ ```
75
+
76
+ ### 模块系统决策
77
+
78
+ ```
79
+ ESM(import/export)
80
+ ├── 现代标准
81
+ ├── 更好的 tree-shaking
82
+ ├── 异步模块加载
83
+ └── 适用:新项目
84
+
85
+ CommonJS(require)
86
+ ├── 遗留兼容性更好
87
+ ├── 对部分 npm 包支持更成熟
88
+ └── 适用:既有代码库、特定边界场景
89
+ ```
90
+
91
+ ### Runtime 选择
92
+
93
+ | Runtime | 适用场景 |
94
+ |---------|----------|
95
+ | **Node.js** | 通用场景、生态最大 |
96
+ | **Bun** | 性能优先、内置 bundler |
97
+ | **Deno** | 安全优先、内置 TypeScript |
98
+
99
+ ---
100
+
101
+ ## 3. 架构原则
102
+
103
+ ### 分层结构概念
104
+
105
+ ```
106
+ 请求流(Request Flow):
107
+
108
+ ├── Controller/Route 层
109
+ │ ├── 处理 HTTP 细节
110
+ │ ├── 在边界做输入校验
111
+ │ └── 调用 service 层
112
+
113
+ ├── Service 层
114
+ │ ├── 承载业务逻辑
115
+ │ ├── 与框架解耦
116
+ │ └── 调用 repository 层
117
+
118
+ └── Repository 层
119
+ ├── 仅处理数据访问
120
+ ├── 数据库查询
121
+ └── ORM 交互
122
+ ```
123
+
124
+ ### 为什么重要
125
+ - **可测性(Testability):** 可独立 mock 每一层
126
+ - **灵活性(Flexibility):** 更换数据库不影响业务层
127
+ - **清晰性(Clarity):** 每层职责单一
128
+
129
+ ### 何时简化
130
+ - 小型脚本 → 单文件可接受
131
+ - 原型验证 → 可降低结构复杂度
132
+ - 始终追问:“这个项目会继续增长吗?”
133
+
134
+ ---
135
+
136
+ ## 4. 错误处理原则
137
+
138
+ ### 集中式错误处理
139
+
140
+ ```
141
+ Pattern:
142
+ ├── 定义自定义错误类
143
+ ├── 各层都可 throw
144
+ ├── 在顶层统一 catch(middleware)
145
+ └── 输出一致的响应格式
146
+ ```
147
+
148
+ ### 错误响应哲学
149
+
150
+ ```
151
+ Client gets:
152
+ ├── 合理的 HTTP 状态码
153
+ ├── 可程序化处理的错误码
154
+ ├── 对用户友好的提示
155
+ └── 不暴露内部细节(安全要求)
156
+
157
+ Logs get:
158
+ ├── 完整堆栈信息
159
+ ├── 请求上下文
160
+ ├── 用户 ID(如适用)
161
+ └── 时间戳
162
+ ```
163
+
164
+ ### 状态码选择
165
+
166
+ | 场景 | 状态码 | 说明 |
167
+ |------|--------|------|
168
+ | Bad input | 400 | 客户端输入无效 |
169
+ | No auth | 401 | 缺少或无效凭据 |
170
+ | No permission | 403 | 已认证但无权限 |
171
+ | Not found | 404 | 资源不存在 |
172
+ | Conflict | 409 | 重复或状态冲突 |
173
+ | Validation | 422 | schema 合法但业务规则失败 |
174
+ | Server error | 500 | 服务端责任,完整记录日志 |
175
+
176
+ ---
177
+
178
+ ## 5. 异步模式原则
179
+
180
+ ### 各模式使用时机
181
+
182
+ | 模式 | 适用场景 |
183
+ |------|----------|
184
+ | `async/await` | 串行异步操作 |
185
+ | `Promise.all` | 可并行且互不依赖 |
186
+ | `Promise.allSettled` | 并行且允许部分失败 |
187
+ | `Promise.race` | 超时控制或“先返回者胜出” |
188
+
189
+ ### Event Loop 认知
190
+
191
+ ```
192
+ I/O-bound(异步有帮助):
193
+ ├── 数据库查询
194
+ ├── HTTP 请求
195
+ ├── 文件系统
196
+ └── 网络操作
197
+
198
+ CPU-bound(异步无帮助):
199
+ ├── 加密计算
200
+ ├── 图像处理
201
+ ├── 复杂计算
202
+ └── → 使用 worker threads 或外部任务卸载
203
+ ```
204
+
205
+ ### 避免阻塞 Event Loop
206
+
207
+ - 生产环境避免使用同步方法(如 `fs.readFileSync`)
208
+ - CPU 密集任务必须卸载
209
+ - 大数据处理优先使用 streaming
210
+
211
+ ---
212
+
213
+ ## 6. 校验原则
214
+
215
+ ### 在边界做校验
216
+
217
+ ```
218
+ 校验位置:
219
+ ├── API 入口(request body/params)
220
+ ├── 数据库操作之前
221
+ ├── 外部数据(API 响应、文件上传)
222
+ └── 环境变量(启动时)
223
+ ```
224
+
225
+ ### 校验库选型
226
+
227
+ | 库 | 适用场景 |
228
+ |----|----------|
229
+ | **Zod** | TypeScript 优先、类型推断友好 |
230
+ | **Valibot** | 包体积更小(tree-shakeable) |
231
+ | **ArkType** | 性能敏感场景 |
232
+ | **Yup** | 既有 React Form 生态 |
233
+
234
+ ### 校验哲学
235
+
236
+ - Fail fast:尽早校验、尽早失败
237
+ - Be specific:错误信息必须明确
238
+ - Don't trust:即使“内部数据”也不能默认可信
239
+
240
+ ---
241
+
242
+ ## 7. 安全原则
243
+
244
+ ### 安全检查清单(不是代码模板)
245
+
246
+ - [ ] **Input validation(输入校验)**:所有输入已校验
247
+ - [ ] **Parameterized queries(参数化查询)**:SQL 禁止字符串拼接
248
+ - [ ] **Password hashing(密码哈希)**:使用 bcrypt 或 argon2
249
+ - [ ] **JWT verification(JWT 校验)**:必须校验签名与过期时间
250
+ - [ ] **Rate limiting(限流)**:具备防滥用机制
251
+ - [ ] **Security headers(安全响应头)**:使用 Helmet.js 或同等方案
252
+ - [ ] **HTTPS**:生产环境全链路启用
253
+ - [ ] **CORS**:配置正确
254
+ - [ ] **Secrets(密钥)**:仅使用环境变量管理
255
+ - [ ] **Dependencies(依赖)**:定期审计
256
+
257
+ ### 安全思维
258
+
259
+ ```
260
+ Trust nothing(默认不信任):
261
+ ├── Query params(查询参数)→ 校验
262
+ ├── Request body(请求体)→ 校验
263
+ ├── Headers(请求头)→ 校验
264
+ ├── Cookies → 校验
265
+ ├── File uploads(文件上传)→ 扫描
266
+ └── External APIs(外部 API)→ 校验响应
267
+ ```
268
+
269
+ ---
270
+
271
+ ## 8. 测试原则
272
+
273
+ ### 测试策略选择
274
+
275
+ | 类型 | 目的 | 工具 |
276
+ |------|------|------|
277
+ | **Unit(单元测试)** | 业务逻辑 | node:test, Vitest |
278
+ | **Integration(集成测试)** | API 端点 | Supertest |
279
+ | **E2E(端到端)** | 完整流程 | Playwright |
280
+
281
+ ### 测试优先级
282
+
283
+ 1. **关键路径**:鉴权、支付、核心业务
284
+ 2. **边界场景**:空输入、边界值
285
+ 3. **错误处理**:失败时系统如何表现
286
+ 4. **不值得测**:框架内部代码、过于简单的 getter
287
+
288
+ ### 内置测试运行器(Node.js 22+)
289
+
290
+ ```
291
+ node --test src/**/*.test.ts
292
+ ├── 无需额外依赖
293
+ ├── 覆盖率报告可用
294
+ └── 支持 watch mode(监听模式)
295
+ ```
296
+
297
+ ---
298
+
299
+ ## 10. 需要避免的反模式
300
+
301
+ ### ❌ 不要这样做:
302
+ - 新 Edge 项目默认用 Express(优先考虑 Hono)
303
+ - 在生产代码中使用同步方法
304
+ - 在 controller 中堆业务逻辑
305
+ - 跳过输入校验
306
+ - 硬编码 secrets
307
+ - 不校验就信任外部数据
308
+ - 用 CPU 重任务阻塞 event loop(事件循环)
309
+
310
+ ### ✅ 推荐做法:
311
+ - 基于上下文选择框架
312
+ - 需求不清晰先询问用户偏好
313
+ - 可增长项目采用分层架构
314
+ - 对所有输入做校验
315
+ - secrets 使用环境变量管理
316
+ - 优化前先做 profile(性能分析)
317
+
318
+ ---
319
+
320
+ ## 11. 决策检查清单
321
+
322
+ 开始实现前:
323
+
324
+ - [ ] **是否询问了用户的技术栈偏好?**
325
+ - [ ] **是否为当前上下文选了合适框架?**(而非默认)
326
+ - [ ] **是否考虑了部署目标?**
327
+ - [ ] **是否规划了错误处理策略?**
328
+ - [ ] **是否识别了校验边界点?**
329
+ - [ ] **是否评估了安全要求?**
330
+
331
+ ---
332
+
333
+ > **牢记:** Node.js 最佳实践的核心是“决策能力”,不是“背模板”。每个项目都应基于其真实需求重新判断。