super-dev 2.0.0__py3-none-any.whl

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 (61) hide show
  1. super_dev/__init__.py +11 -0
  2. super_dev/analyzer/__init__.py +34 -0
  3. super_dev/analyzer/analyzer.py +440 -0
  4. super_dev/analyzer/detectors.py +511 -0
  5. super_dev/analyzer/models.py +285 -0
  6. super_dev/cli.py +3257 -0
  7. super_dev/config/__init__.py +11 -0
  8. super_dev/config/frontend.py +557 -0
  9. super_dev/config/manager.py +281 -0
  10. super_dev/creators/__init__.py +26 -0
  11. super_dev/creators/creator.py +134 -0
  12. super_dev/creators/document_generator.py +2473 -0
  13. super_dev/creators/frontend_builder.py +371 -0
  14. super_dev/creators/implementation_builder.py +789 -0
  15. super_dev/creators/prompt_generator.py +289 -0
  16. super_dev/creators/requirement_parser.py +354 -0
  17. super_dev/creators/spec_builder.py +195 -0
  18. super_dev/deployers/__init__.py +20 -0
  19. super_dev/deployers/cicd.py +1269 -0
  20. super_dev/deployers/delivery.py +229 -0
  21. super_dev/deployers/migration.py +1032 -0
  22. super_dev/design/__init__.py +74 -0
  23. super_dev/design/aesthetics.py +530 -0
  24. super_dev/design/charts.py +396 -0
  25. super_dev/design/codegen.py +379 -0
  26. super_dev/design/engine.py +528 -0
  27. super_dev/design/generator.py +395 -0
  28. super_dev/design/landing.py +422 -0
  29. super_dev/design/tech_stack.py +524 -0
  30. super_dev/design/tokens.py +269 -0
  31. super_dev/design/ux_guide.py +391 -0
  32. super_dev/exceptions.py +119 -0
  33. super_dev/experts/__init__.py +19 -0
  34. super_dev/experts/service.py +161 -0
  35. super_dev/integrations/__init__.py +7 -0
  36. super_dev/integrations/manager.py +264 -0
  37. super_dev/orchestrator/__init__.py +12 -0
  38. super_dev/orchestrator/engine.py +958 -0
  39. super_dev/orchestrator/experts.py +423 -0
  40. super_dev/orchestrator/knowledge.py +352 -0
  41. super_dev/orchestrator/quality.py +356 -0
  42. super_dev/reviewers/__init__.py +17 -0
  43. super_dev/reviewers/code_review.py +471 -0
  44. super_dev/reviewers/quality_gate.py +964 -0
  45. super_dev/reviewers/redteam.py +881 -0
  46. super_dev/skills/__init__.py +7 -0
  47. super_dev/skills/manager.py +307 -0
  48. super_dev/specs/__init__.py +44 -0
  49. super_dev/specs/generator.py +264 -0
  50. super_dev/specs/manager.py +428 -0
  51. super_dev/specs/models.py +348 -0
  52. super_dev/specs/validator.py +415 -0
  53. super_dev/utils/__init__.py +11 -0
  54. super_dev/utils/logger.py +133 -0
  55. super_dev/web/api.py +1402 -0
  56. super_dev-2.0.0.dist-info/METADATA +252 -0
  57. super_dev-2.0.0.dist-info/RECORD +61 -0
  58. super_dev-2.0.0.dist-info/WHEEL +5 -0
  59. super_dev-2.0.0.dist-info/entry_points.txt +2 -0
  60. super_dev-2.0.0.dist-info/licenses/LICENSE +21 -0
  61. super_dev-2.0.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,524 @@
1
+ """
2
+ 开发:Excellent(11964948@qq.com)
3
+ 功能:技术栈最佳实践引擎
4
+ 作用:提供各技术栈的最佳实践、性能优化和常见模式
5
+ 创建时间:2025-01-04
6
+ 最后修改:2025-01-04
7
+ """
8
+
9
+ import csv
10
+ from dataclasses import dataclass
11
+ from enum import Enum
12
+ from pathlib import Path
13
+
14
+
15
+ class TechStack(str, Enum):
16
+ """技术栈枚举"""
17
+ NEXTJS = "Next.js"
18
+ REMIX = "Remix"
19
+ REACT = "React"
20
+ VUE = "Vue"
21
+ SVELTEKIT = "SvelteKit"
22
+ ANGULAR = "Angular"
23
+ ASTRO = "Astro"
24
+ SOLIDJS = "SolidJS"
25
+ QWIK = "Qwik"
26
+ SWIFTUI = "SwiftUI"
27
+ REACT_NATIVE = "React Native"
28
+ FLUTTER = "Flutter"
29
+
30
+
31
+ class PracticeCategory(str, Enum):
32
+ """实践类别"""
33
+ ARCHITECTURE = "architecture"
34
+ PERFORMANCE = "performance"
35
+ STATE_MANAGEMENT = "state_management"
36
+ STYLING = "styling"
37
+ TESTING = "testing"
38
+ DEPLOYMENT = "deployment"
39
+ SECURITY = "security"
40
+ ACCESSIBILITY = "accessibility"
41
+
42
+
43
+ @dataclass
44
+ class TechBestPractice:
45
+ """技术栈最佳实践"""
46
+ stack: TechStack
47
+ category: PracticeCategory
48
+ topic: str
49
+ practice: str
50
+ anti_pattern: str
51
+ code_example: str
52
+ benefits: str
53
+ complexity: str # low, medium, high
54
+
55
+
56
+ @dataclass
57
+ class TechPattern:
58
+ """设计模式"""
59
+ stack: TechStack
60
+ name: str
61
+ description: str
62
+ use_case: str
63
+ implementation: str
64
+ pros: list[str]
65
+ cons: list[str]
66
+
67
+
68
+ @dataclass
69
+ class PerformanceTip:
70
+ """性能优化建议"""
71
+ stack: TechStack
72
+ topic: str
73
+ technique: str
74
+ impact: str # high, medium, low
75
+ effort: str # low, medium, high
76
+ description: str
77
+ code_snippet: str
78
+
79
+
80
+ @dataclass
81
+ class StackRecommendation:
82
+ """技术栈推荐"""
83
+ practice: TechBestPractice
84
+ priority: str # critical, high, medium, low
85
+ context: str
86
+ alternatives: list[str]
87
+ resources: list[str]
88
+
89
+
90
+ class TechStackEngine:
91
+ """技术栈引擎"""
92
+
93
+ def __init__(self, data_dir: Path | None = None):
94
+ """
95
+ 初始化引擎
96
+
97
+ Args:
98
+ data_dir: 数据目录路径
99
+ """
100
+ if data_dir is None:
101
+ data_dir = Path(__file__).parent.parent / "data" / "design"
102
+
103
+ self.data_dir = Path(data_dir)
104
+ self.practices: list[TechBestPractice] = []
105
+ self.patterns: list[TechPattern] = []
106
+ self.performance_tips: list[PerformanceTip] = []
107
+ self._load_data()
108
+
109
+ def _load_data(self):
110
+ """从 CSV 加载数据"""
111
+ # 加载最佳实践
112
+ practices_path = self.data_dir / "tech_practices.csv"
113
+ if practices_path.exists():
114
+ self._load_practices(practices_path)
115
+ else:
116
+ self.practices = self._get_default_practices()
117
+
118
+ # 加载设计模式
119
+ patterns_path = self.data_dir / "tech_patterns.csv"
120
+ if patterns_path.exists():
121
+ self._load_patterns(patterns_path)
122
+ else:
123
+ self.patterns = self._get_default_patterns()
124
+
125
+ # 加载性能建议
126
+ performance_path = self.data_dir / "tech_performance.csv"
127
+ if performance_path.exists():
128
+ self._load_performance(performance_path)
129
+ else:
130
+ self.performance_tips = self._get_default_performance()
131
+
132
+ def _load_practices(self, csv_path: Path):
133
+ """加载最佳实践数据"""
134
+ with open(csv_path, encoding='utf-8') as f:
135
+ reader = csv.DictReader(f)
136
+ for row in reader:
137
+ try:
138
+ practice = TechBestPractice(
139
+ stack=TechStack(row["stack"]),
140
+ category=PracticeCategory(row["category"]),
141
+ topic=row["topic"],
142
+ practice=row["practice"],
143
+ anti_pattern=row["anti_pattern"],
144
+ code_example=row["code_example"],
145
+ benefits=row["benefits"],
146
+ complexity=row["complexity"]
147
+ )
148
+ self.practices.append(practice)
149
+ except Exception as e:
150
+ print(f"Warning: Failed to parse practice: {e}")
151
+
152
+ def _load_patterns(self, csv_path: Path):
153
+ """加载设计模式数据"""
154
+ with open(csv_path, encoding='utf-8') as f:
155
+ reader = csv.DictReader(f)
156
+ for row in reader:
157
+ try:
158
+ pattern = TechPattern(
159
+ stack=TechStack(row["stack"]),
160
+ name=row["name"],
161
+ description=row["description"],
162
+ use_case=row["use_case"],
163
+ implementation=row["implementation"],
164
+ pros=row["pros"].split(";"),
165
+ cons=row["cons"].split(";")
166
+ )
167
+ self.patterns.append(pattern)
168
+ except Exception as e:
169
+ print(f"Warning: Failed to parse pattern: {e}")
170
+
171
+ def _load_performance(self, csv_path: Path):
172
+ """加载性能建议数据"""
173
+ with open(csv_path, encoding='utf-8') as f:
174
+ reader = csv.DictReader(f)
175
+ for row in reader:
176
+ try:
177
+ tip = PerformanceTip(
178
+ stack=TechStack(row["stack"]),
179
+ topic=row["topic"],
180
+ technique=row["technique"],
181
+ impact=row["impact"],
182
+ effort=row["effort"],
183
+ description=row["description"],
184
+ code_snippet=row["code_snippet"]
185
+ )
186
+ self.performance_tips.append(tip)
187
+ except Exception as e:
188
+ print(f"Warning: Failed to parse performance tip: {e}")
189
+
190
+ def _get_default_practices(self) -> list[TechBestPractice]:
191
+ """获取默认最佳实践"""
192
+ return [
193
+ TechBestPractice(
194
+ stack=TechStack.NEXTJS,
195
+ category=PracticeCategory.ARCHITECTURE,
196
+ topic="Server Components",
197
+ practice="Use Server Components by default, Client Components only when needed",
198
+ anti_pattern="Mark all components with 'use client'",
199
+ code_example="// Server Component (default)\nexport default function Profile() {\n return <div>{user.name}</div>\n}\n\n// Client Component\n'use client'\nexport function Button() { return <button>Click</button> }",
200
+ benefits="Reduced bundle size, improved performance, simpler data fetching",
201
+ complexity="low"
202
+ ),
203
+ TechBestPractice(
204
+ stack=TechStack.REACT,
205
+ category=PracticeCategory.PERFORMANCE,
206
+ topic="Code Splitting",
207
+ practice="Use React.lazy and Suspense for route-based code splitting",
208
+ anti_pattern="Load entire application bundle upfront",
209
+ code_example="const Dashboard = React.lazy(() => import('./Dashboard'));\n\n<Suspense fallback={<Loading />}>\n <Dashboard />\n</Suspense>",
210
+ benefits="Faster initial load, better user experience",
211
+ complexity="medium"
212
+ ),
213
+ TechBestPractice(
214
+ stack=TechStack.VUE,
215
+ category=PracticeCategory.STATE_MANAGEMENT,
216
+ topic="Composition API",
217
+ practice="Use Composition API with <script setup> syntax",
218
+ anti_pattern="Mix Options API and Composition API",
219
+ code_example="<script setup>\nimport { ref, computed } from 'vue'\nconst count = ref(0)\nconst doubled = computed(() => count.value * 2)\n</script>",
220
+ benefits="Better type inference, code organization, tree-shaking",
221
+ complexity="low"
222
+ )
223
+ ]
224
+
225
+ def _get_default_patterns(self) -> list[TechPattern]:
226
+ """获取默认设计模式"""
227
+ return [
228
+ TechPattern(
229
+ stack=TechStack.NEXTJS,
230
+ name="Parallel Routes",
231
+ description="Render multiple sections of a page in parallel",
232
+ use_case="Dashboard with independent sections",
233
+ implementation="// app/dashboard/layout.tsx\nexport default function Layout({\n children,\n analytics,\n users\n}: {\n children: React.ReactNode\n analytics: React.ReactNode\n users: React.ReactNode\n}) {\n return (\n <div>\n {children}\n {analytics}\n {users}\n </div>\n )\n}",
234
+ pros=["Independent loading states", "Parallel rendering", "Better UX"],
235
+ cons=["More complex routing", "Not suitable for all layouts"]
236
+ ),
237
+ TechPattern(
238
+ stack=TechStack.REACT,
239
+ name="Compound Components",
240
+ description="Build components that share state implicitly",
241
+ use_case="Modals, Dropdowns, Tabs",
242
+ implementation="const Tabs = ({ children }) => {\n const [active, setActive] = useState(0)\n return (\n <TabsContext value={{ active, setActive }}>\n {children}\n </TabsContext>\n )\n}",
243
+ pros=["Flexible API", "Less prop drilling", "Intuitive usage"],
244
+ cons=["Harder to understand", "Requires context"]
245
+ )
246
+ ]
247
+
248
+ def _get_default_performance(self) -> list[PerformanceTip]:
249
+ """获取默认性能建议"""
250
+ return [
251
+ PerformanceTip(
252
+ stack=TechStack.NEXTJS,
253
+ topic="Image Optimization",
254
+ technique="Use next/image for all images",
255
+ impact="high",
256
+ effort="low",
257
+ description="Automatic optimization, lazy loading, and responsive images",
258
+ code_snippet="import Image from 'next/image'\n\n<Image\n src='/hero.jpg'\n alt='Hero'\n width={1200}\n height={600}\n priority\n/>"
259
+ ),
260
+ PerformanceTip(
261
+ stack=TechStack.REACT,
262
+ topic="Memoization",
263
+ technique="Use useMemo and useCallback sparingly",
264
+ impact="medium",
265
+ effort="medium",
266
+ description="Memoize expensive computations and callbacks",
267
+ code_snippet="const memoizedValue = useMemo(() => {\n return computeExpensiveValue(a, b)\n}, [a, b])"
268
+ )
269
+ ]
270
+
271
+ def search_practices(
272
+ self,
273
+ stack: str,
274
+ query: str | None = None,
275
+ category: str | None = None,
276
+ max_results: int = 5
277
+ ) -> list[StackRecommendation]:
278
+ """
279
+ 搜索最佳实践
280
+
281
+ Args:
282
+ stack: 技术栈名称
283
+ query: 搜索查询
284
+ category: 类别过滤
285
+ max_results: 最大结果数
286
+
287
+ Returns:
288
+ 推荐建议列表
289
+ """
290
+ stack_lower = stack.lower()
291
+
292
+ # 筛选最佳实践
293
+ filtered_practices = []
294
+ for practice in self.practices:
295
+ # 技术栈过滤
296
+ if practice.stack.value.lower() != stack_lower:
297
+ continue
298
+
299
+ # 类别过滤
300
+ if category and practice.category.value.lower() != category.lower():
301
+ continue
302
+
303
+ # 查询评分
304
+ if query:
305
+ query_lower = query.lower()
306
+ score = 0
307
+
308
+ if query_lower in practice.topic.lower():
309
+ score += 10
310
+ if query_lower in practice.practice.lower():
311
+ score += 8
312
+ if query_lower in practice.benefits.lower():
313
+ score += 5
314
+
315
+ if score == 0:
316
+ continue
317
+
318
+ filtered_practices.append(practice)
319
+
320
+ # 构建推荐
321
+ recommendations = []
322
+ for practice in filtered_practices[:max_results]:
323
+ priority = self._determine_priority(practice)
324
+ context = self._get_context(practice)
325
+ alternatives = self._get_alternatives(practice)
326
+ resources = self._get_resources(practice)
327
+
328
+ recommendations.append(StackRecommendation(
329
+ practice=practice,
330
+ priority=priority,
331
+ context=context,
332
+ alternatives=alternatives,
333
+ resources=resources
334
+ ))
335
+
336
+ return recommendations
337
+
338
+ def get_patterns(self, stack: str) -> list[TechPattern]:
339
+ """
340
+ 获取设计模式
341
+
342
+ Args:
343
+ stack: 技术栈名称
344
+
345
+ Returns:
346
+ 设计模式列表
347
+ """
348
+ stack_lower = stack.lower()
349
+ return [
350
+ p for p in self.patterns
351
+ if p.stack.value.lower() == stack_lower
352
+ ]
353
+
354
+ def get_performance_tips(
355
+ self,
356
+ stack: str,
357
+ impact: str | None = None,
358
+ effort: str | None = None
359
+ ) -> list[PerformanceTip]:
360
+ """
361
+ 获取性能优化建议
362
+
363
+ Args:
364
+ stack: 技术栈名称
365
+ impact: 影响程度过滤
366
+ effort: 实施难度过滤
367
+
368
+ Returns:
369
+ 性能建议列表
370
+ """
371
+ stack_lower = stack.lower()
372
+ tips = []
373
+
374
+ for tip in self.performance_tips:
375
+ if tip.stack.value.lower() != stack_lower:
376
+ continue
377
+
378
+ if impact and tip.impact.lower() != impact.lower():
379
+ continue
380
+
381
+ if effort and tip.effort.lower() != effort.lower():
382
+ continue
383
+
384
+ tips.append(tip)
385
+
386
+ # 按影响程度排序
387
+ impact_order = {"high": 0, "medium": 1, "low": 2}
388
+ tips.sort(key=lambda t: impact_order.get(t.impact.lower(), 3))
389
+
390
+ return tips
391
+
392
+ def get_quick_wins(self, stack: str) -> list[PerformanceTip]:
393
+ """
394
+ 获取快速见效的性能优化
395
+
396
+ Args:
397
+ stack: 技术栈名称
398
+
399
+ Returns:
400
+ 高影响、低难度的优化建议
401
+ """
402
+ tips = self.get_performance_tips(stack)
403
+
404
+ return [
405
+ tip for tip in tips
406
+ if tip.impact.lower() == "high" and tip.effort.lower() == "low"
407
+ ]
408
+
409
+ def get_migration_guide(
410
+ self,
411
+ from_stack: str,
412
+ to_stack: str
413
+ ) -> dict[str, str]:
414
+ """
415
+ 获取技术栈迁移指南
416
+
417
+ Args:
418
+ from_stack: 源技术栈
419
+ to_stack: 目标技术栈
420
+
421
+ Returns:
422
+ 迁移指南
423
+ """
424
+ # 简化版迁移指南
425
+ # 实际应用中可以扩展为更详细的文档
426
+ guides = {
427
+ "react->nextjs": {
428
+ "routing": "Replace react-router with Next.js App Router file-based routing",
429
+ "data_fetching": "Move from useEffect to Server Components and async/await",
430
+ "styling": "Keep existing CSS solutions, they work with Next.js",
431
+ "deployment": "Deploy to Vercel for zero-config hosting"
432
+ },
433
+ "vue->nuxt": {
434
+ "routing": "Replace vue-router with file-based routing in pages/",
435
+ "data_fetching": "Use useAsyncData and useFetch composables",
436
+ "styling": "Vue SFC styles work the same way",
437
+ "deployment": "Deploy to Vercel, Netlify, or Node.js server"
438
+ }
439
+ }
440
+
441
+ key = f"{from_stack.lower()}->{to_stack.lower()}"
442
+ return guides.get(key, {})
443
+
444
+ def _determine_priority(self, practice: TechBestPractice) -> str:
445
+ """确定优先级"""
446
+ if practice.category == PracticeCategory.SECURITY:
447
+ return "critical"
448
+
449
+ if practice.category == PracticeCategory.PERFORMANCE:
450
+ return "high"
451
+
452
+ if practice.complexity == "low":
453
+ return "high"
454
+
455
+ return "medium"
456
+
457
+ def _get_context(self, practice: TechBestPractice) -> str:
458
+ """获取上下文说明"""
459
+ contexts = {
460
+ PracticeCategory.ARCHITECTURE: "架构层面的最佳实践,影响整体代码组织",
461
+ PracticeCategory.PERFORMANCE: "性能优化建议,提升用户体验",
462
+ PracticeCategory.STATE_MANAGEMENT: "状态管理模式,确保数据流清晰",
463
+ PracticeCategory.STYLING: "样式方案,保持视觉一致性",
464
+ PracticeCategory.TESTING: "测试策略,确保代码质量",
465
+ PracticeCategory.DEPLOYMENT: "部署方案,简化发布流程",
466
+ PracticeCategory.SECURITY: "安全实践,保护应用和用户",
467
+ PracticeCategory.ACCESSIBILITY: "无障碍性,确保所有用户可用"
468
+ }
469
+
470
+ return contexts.get(practice.category, "通用最佳实践")
471
+
472
+ def _get_alternatives(self, practice: TechBestPractice) -> list[str]:
473
+ """获取替代方案"""
474
+ # 简化版,可以扩展为更详细的映射
475
+ return ["See documentation for alternatives"]
476
+
477
+ def _get_resources(self, practice: TechBestPractice) -> list[str]:
478
+ """获取相关资源"""
479
+ resources = {
480
+ TechStack.NEXTJS: [
481
+ "Next.js Documentation: https://nextjs.org/docs",
482
+ "Next.js Learn: https://nextjs.org/learn"
483
+ ],
484
+ TechStack.REACT: [
485
+ "React Documentation: https://react.dev",
486
+ "React Patterns: https://reactpatterns.com"
487
+ ],
488
+ TechStack.VUE: [
489
+ "Vue Documentation: https://vuejs.org/guide/",
490
+ "Vue Style Guide: https://vuejs.org/style-guide/"
491
+ ],
492
+ TechStack.SVELTEKIT: [
493
+ "SvelteKit Docs: https://kit.svelte.dev/docs",
494
+ "Svelte Docs: https://svelte.dev/docs"
495
+ ]
496
+ }
497
+
498
+ return resources.get(practice.stack, [])
499
+
500
+ def list_stacks(self) -> list[str]:
501
+ """列出所有支持的技术栈"""
502
+ return list(set(p.stack.value for p in self.practices))
503
+
504
+ def list_categories(self, stack: str | None = None) -> list[str]:
505
+ """
506
+ 列出所有类别
507
+
508
+ Args:
509
+ stack: 可选的技术栈过滤
510
+
511
+ Returns:
512
+ 类别列表
513
+ """
514
+ if stack:
515
+ practices = [p for p in self.practices if p.stack.value.lower() == stack.lower()]
516
+ return list(set(p.category.value for p in practices))
517
+
518
+ return list(set(p.category.value for p in self.practices))
519
+
520
+
521
+ # 便捷函数
522
+ def get_tech_stack_engine(data_dir: Path | None = None) -> TechStackEngine:
523
+ """获取技术栈引擎实例"""
524
+ return TechStackEngine(data_dir)