sinapse-ai 1.12.2 → 1.14.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 (244) hide show
  1. package/.claude/CLAUDE.md +2 -2
  2. package/.claude/rules/agent-memory-imports.md +4 -0
  3. package/.sinapse-ai/cli/commands/pro/index.js +8 -48
  4. package/.sinapse-ai/constitution.md +6 -2
  5. package/.sinapse-ai/data/entity-registry.yaml +63 -429
  6. package/.sinapse-ai/development/agents/analyst/MEMORY.md +19 -0
  7. package/.sinapse-ai/development/agents/architect/MEMORY.md +52 -0
  8. package/.sinapse-ai/development/agents/data-engineer/MEMORY.md +55 -0
  9. package/.sinapse-ai/development/agents/developer/MEMORY.md +53 -0
  10. package/.sinapse-ai/development/agents/devops/MEMORY.md +56 -0
  11. package/.sinapse-ai/development/agents/product-lead/MEMORY.md +53 -0
  12. package/.sinapse-ai/development/agents/project-lead/MEMORY.md +53 -0
  13. package/.sinapse-ai/development/agents/quality-gate/MEMORY.md +52 -0
  14. package/.sinapse-ai/development/agents/snps-orqx.md +15 -0
  15. package/.sinapse-ai/development/agents/sprint-lead/MEMORY.md +53 -0
  16. package/.sinapse-ai/development/agents/squad-creator.md +15 -0
  17. package/.sinapse-ai/development/agents/ux/MEMORY.md +21 -0
  18. package/.sinapse-ai/development/templates/chrome-brain/knowledge-base/chrome-brain.md +2 -2
  19. package/.sinapse-ai/infrastructure/scripts/ide-sync/index.js +15 -0
  20. package/.sinapse-ai/infrastructure/scripts/validate-agents.js +159 -8
  21. package/.sinapse-ai/install-manifest.yaml +16 -152
  22. package/AGENTS.md +13 -2
  23. package/CHANGELOG.md +135 -3
  24. package/README.en.md +1 -1
  25. package/README.md +6 -26
  26. package/bin/cli.js +2 -7
  27. package/bin/commands/install.js +19 -257
  28. package/bin/commands/update.js +18 -78
  29. package/bin/lib/command-generator.js +261 -0
  30. package/bin/lib/prompts.js +2 -65
  31. package/bin/modules/chrome-brain-installer.js +2 -1
  32. package/bin/postinstall.js +6 -6
  33. package/docs/getting-started.md +0 -1
  34. package/docs/pt/getting-started.md +1 -1
  35. package/docs/security/dependabot-triage.md +17 -17
  36. package/package.json +6 -3
  37. package/packages/installer/src/wizard/i18n.js +3 -204
  38. package/packages/installer/src/wizard/index.js +1 -1
  39. package/packages/installer/src/wizard/questions.js +5 -368
  40. package/packages/installer/src/wizard/wizard.js +0 -9
  41. package/scripts/generate-install-manifest.js +6 -0
  42. package/scripts/validate-changelog-tags.js +97 -0
  43. package/scripts/validate-no-personal-leaks.js +184 -28
  44. package/scripts/validate-schemas.js +55 -10
  45. package/scripts/validate-story-meta.js +25 -12
  46. package/squads/claude-code-mastery/agents/claude-mastery-chief.md +15 -1
  47. package/squads/claude-code-mastery/agents/config-engineer.md +15 -0
  48. package/squads/claude-code-mastery/agents/hooks-architect.md +27 -20
  49. package/squads/claude-code-mastery/agents/mcp-integrator.md +15 -0
  50. package/squads/claude-code-mastery/agents/project-integrator.md +15 -0
  51. package/squads/claude-code-mastery/agents/roadmap-sentinel.md +15 -0
  52. package/squads/claude-code-mastery/agents/skill-craftsman.md +15 -0
  53. package/squads/claude-code-mastery/agents/swarm-orqx.md +15 -0
  54. package/squads/claude-code-mastery/tasks/audit-setup.md +1 -1
  55. package/squads/squad-animations/agents/animation-interpreter.md +15 -0
  56. package/squads/squad-animations/agents/animation-performance-engineer.md +15 -0
  57. package/squads/squad-animations/agents/animations-orqx.md +13 -0
  58. package/squads/squad-animations/agents/css-motion-artist.md +15 -0
  59. package/squads/squad-animations/agents/generative-particle-engineer.md +15 -0
  60. package/squads/squad-animations/agents/motion-choreographer.md +15 -0
  61. package/squads/squad-animations/agents/scroll-narrative-engineer.md +15 -0
  62. package/squads/squad-animations/agents/shader-artist.md +15 -0
  63. package/squads/squad-animations/agents/threejs-architect.md +15 -0
  64. package/squads/squad-brand/agents/brand-archetype-strategist.md +13 -0
  65. package/squads/squad-brand/agents/brand-auditor.md +15 -0
  66. package/squads/squad-brand/agents/brand-collateral-designer.md +15 -0
  67. package/squads/squad-brand/agents/brand-compiler.md +13 -0
  68. package/squads/squad-brand/agents/brand-creative-engineer.md +15 -0
  69. package/squads/squad-brand/agents/brand-culture-architect.md +15 -0
  70. package/squads/squad-brand/agents/brand-growth-strategist.md +15 -0
  71. package/squads/squad-brand/agents/brand-identity-designer.md +15 -0
  72. package/squads/squad-brand/agents/brand-motion-vfx.md +15 -0
  73. package/squads/squad-brand/agents/brand-naming-specialist.md +15 -0
  74. package/squads/squad-brand/agents/brand-orqx.md +13 -0
  75. package/squads/squad-brand/agents/brand-positioning-strategist.md +15 -0
  76. package/squads/squad-brand/agents/brand-sonic-designer.md +15 -0
  77. package/squads/squad-brand/agents/brand-strategist.md +15 -0
  78. package/squads/squad-brand/agents/brand-system-architect.md +15 -0
  79. package/squads/squad-cloning/agents/agent-forger.md +15 -0
  80. package/squads/squad-cloning/agents/cloning-orqx.md +15 -0
  81. package/squads/squad-cloning/agents/cognitive-extractor.md +15 -0
  82. package/squads/squad-cloning/agents/content-capturer.md +15 -0
  83. package/squads/squad-cloning/agents/kb-architect.md +15 -0
  84. package/squads/squad-cloning/agents/mind-synthesizer.md +15 -0
  85. package/squads/squad-cloning/agents/sop-extractor.md +15 -0
  86. package/squads/squad-cloning/agents/source-hunter.md +13 -0
  87. package/squads/squad-cloning/agents/squad-assembler.md +15 -0
  88. package/squads/squad-commercial/agents/commercial-orqx.md +13 -0
  89. package/squads/squad-commercial/agents/cs-business-auditor.md +15 -0
  90. package/squads/squad-commercial/agents/cs-client-success.md +15 -0
  91. package/squads/squad-commercial/agents/cs-crm-specialist.md +15 -0
  92. package/squads/squad-commercial/agents/cs-funnel-architect.md +15 -0
  93. package/squads/squad-commercial/agents/cs-lead-generation-strategist.md +15 -0
  94. package/squads/squad-commercial/agents/cs-offer-designer.md +15 -0
  95. package/squads/squad-commercial/agents/cs-revops-analyst.md +15 -0
  96. package/squads/squad-commercial/agents/cs-sales-closer.md +13 -0
  97. package/squads/squad-commercial/agents/cs-sales-enablement.md +15 -0
  98. package/squads/squad-content/agents/content-analyst.md +13 -0
  99. package/squads/squad-content/agents/content-engineer.md +15 -0
  100. package/squads/squad-content/agents/content-governor.md +13 -0
  101. package/squads/squad-content/agents/content-orqx.md +13 -0
  102. package/squads/squad-content/agents/editorial-strategist.md +15 -0
  103. package/squads/squad-content/agents/platform-specialist.md +15 -0
  104. package/squads/squad-content/agents/signal-intelligence.md +13 -0
  105. package/squads/squad-copy/agents/ad-copywriter.md +13 -0
  106. package/squads/squad-copy/agents/brand-voice-writer.md +15 -0
  107. package/squads/squad-copy/agents/conversion-writer.md +13 -0
  108. package/squads/squad-copy/agents/copy-editor.md +15 -0
  109. package/squads/squad-copy/agents/copy-orqx.md +13 -0
  110. package/squads/squad-copy/agents/copy-strategist.md +15 -0
  111. package/squads/squad-copy/agents/direct-response-writer.md +15 -0
  112. package/squads/squad-copy/agents/email-sequence-strategist.md +15 -0
  113. package/squads/squad-copy/agents/funnel-copywriter.md +15 -0
  114. package/squads/squad-copy/agents/headline-specialist.md +13 -0
  115. package/squads/squad-copy/agents/long-form-writer.md +15 -0
  116. package/squads/squad-copy/agents/persuasion-psychologist.md +15 -0
  117. package/squads/squad-copy/agents/proof-architect.md +15 -0
  118. package/squads/squad-council/agents/brene-brown.md +13 -0
  119. package/squads/squad-council/agents/charlie-munger.md +13 -0
  120. package/squads/squad-council/agents/council-orqx.md +13 -0
  121. package/squads/squad-council/agents/derek-sivers.md +13 -0
  122. package/squads/squad-council/agents/naval-ravikant.md +13 -0
  123. package/squads/squad-council/agents/patrick-lencioni.md +15 -0
  124. package/squads/squad-council/agents/peter-thiel.md +13 -0
  125. package/squads/squad-council/agents/ray-dalio.md +13 -0
  126. package/squads/squad-council/agents/reid-hoffman.md +13 -0
  127. package/squads/squad-council/agents/simon-sinek.md +15 -0
  128. package/squads/squad-council/agents/yvon-chouinard.md +13 -0
  129. package/squads/squad-courses/agents/assessment-creator.md +15 -0
  130. package/squads/squad-courses/agents/content-writer.md +15 -0
  131. package/squads/squad-courses/agents/courses-orqx.md +15 -0
  132. package/squads/squad-courses/agents/curriculum-designer.md +15 -0
  133. package/squads/squad-courses/agents/launch-strategist.md +15 -0
  134. package/squads/squad-courses/agents/lesson-architect.md +15 -0
  135. package/squads/squad-courses/agents/production-director.md +13 -0
  136. package/squads/squad-courses/agents/slide-designer.md +15 -0
  137. package/squads/squad-cybersecurity/agents/cloud-security-engineer.md +15 -0
  138. package/squads/squad-cybersecurity/agents/compliance-officer.md +15 -0
  139. package/squads/squad-cybersecurity/agents/cyber-orqx.md +15 -0
  140. package/squads/squad-cybersecurity/agents/incident-responder.md +15 -0
  141. package/squads/squad-cybersecurity/agents/network-security-engineer.md +15 -0
  142. package/squads/squad-cybersecurity/agents/penetration-tester.md +15 -0
  143. package/squads/squad-cybersecurity/agents/soc-analyst.md +15 -0
  144. package/squads/squad-cybersecurity/agents/threat-analyst.md +15 -0
  145. package/squads/squad-design/agents/cro-persuasion.md +15 -0
  146. package/squads/squad-design/agents/design-orqx.md +13 -0
  147. package/squads/squad-design/agents/design-system.md +15 -0
  148. package/squads/squad-design/agents/dx-accessibility-specialist.md +15 -0
  149. package/squads/squad-design/agents/dx-design-system-architect.md +15 -0
  150. package/squads/squad-design/agents/dx-frontend-engineer.md +15 -0
  151. package/squads/squad-design/agents/dx-interaction-designer.md +15 -0
  152. package/squads/squad-design/agents/dx-performance-engineer.md +15 -0
  153. package/squads/squad-design/agents/dx-ui-designer.md +15 -0
  154. package/squads/squad-design/agents/dx-ux-strategist.md +15 -0
  155. package/squads/squad-design/agents/platform-aesthetic-director.md +15 -0
  156. package/squads/squad-design/agents/premium-packaging-strategist.md +15 -0
  157. package/squads/squad-design/agents/product-surface-director.md +15 -0
  158. package/squads/squad-design/agents/ux-designer.md +15 -0
  159. package/squads/squad-finance/agents/budget-controller.md +15 -0
  160. package/squads/squad-finance/agents/cost-optimizer.md +15 -0
  161. package/squads/squad-finance/agents/finance-orqx.md +15 -0
  162. package/squads/squad-finance/agents/fiscal-compliance-br.md +15 -0
  163. package/squads/squad-finance/agents/forecast-strategist.md +15 -0
  164. package/squads/squad-finance/agents/pricing-strategist.md +15 -0
  165. package/squads/squad-finance/agents/profitability-analyst.md +15 -0
  166. package/squads/squad-finance/agents/revenue-analyst.md +15 -0
  167. package/squads/squad-growth/agents/ga-analytics-engineer.md +15 -0
  168. package/squads/squad-growth/agents/ga-campaign-analyst.md +15 -0
  169. package/squads/squad-growth/agents/ga-cro-specialist.md +15 -0
  170. package/squads/squad-growth/agents/ga-data-analyst.md +13 -0
  171. package/squads/squad-growth/agents/ga-growth-hacker.md +15 -0
  172. package/squads/squad-growth/agents/ga-seo-strategist.md +15 -0
  173. package/squads/squad-growth/agents/growth-orqx.md +15 -0
  174. package/squads/squad-paidmedia/agents/campaign-analyst.md +15 -0
  175. package/squads/squad-paidmedia/agents/creative-strategist.md +15 -0
  176. package/squads/squad-paidmedia/agents/cro-specialist.md +15 -0
  177. package/squads/squad-paidmedia/agents/google-ads-specialist.md +15 -0
  178. package/squads/squad-paidmedia/agents/meta-ads-specialist.md +15 -0
  179. package/squads/squad-paidmedia/agents/paidmedia-orqx.md +15 -0
  180. package/squads/squad-paidmedia/agents/performance-engineer.md +15 -0
  181. package/squads/squad-paidmedia/agents/pm-creative-performance-analyst.md +15 -0
  182. package/squads/squad-paidmedia/agents/pm-youtube-ads-specialist.md +15 -0
  183. package/squads/squad-product/agents/product-orqx.md +13 -1
  184. package/squads/squad-product/agents/ps-client-product-manager.md +13 -1
  185. package/squads/squad-product/agents/ps-delivery-manager.md +13 -1
  186. package/squads/squad-product/agents/ps-discovery-lead.md +15 -1
  187. package/squads/squad-product/agents/ps-product-analyst.md +15 -1
  188. package/squads/squad-product/agents/ps-product-ops-specialist.md +15 -1
  189. package/squads/squad-product/agents/ps-product-strategist.md +15 -1
  190. package/squads/squad-research/agents/audience-intelligence.md +15 -0
  191. package/squads/squad-research/agents/competitive-intelligence.md +15 -0
  192. package/squads/squad-research/agents/data-synthesizer.md +15 -0
  193. package/squads/squad-research/agents/deep-researcher.md +15 -0
  194. package/squads/squad-research/agents/market-analyst.md +15 -0
  195. package/squads/squad-research/agents/research-orqx.md +15 -0
  196. package/squads/squad-research/agents/trend-forecaster.md +15 -0
  197. package/squads/squad-storytelling/agents/blake-snyder.md +13 -0
  198. package/squads/squad-storytelling/agents/dan-harmon.md +13 -0
  199. package/squads/squad-storytelling/agents/joseph-campbell.md +13 -0
  200. package/squads/squad-storytelling/agents/keith-johnstone.md +13 -0
  201. package/squads/squad-storytelling/agents/kindra-hall.md +15 -0
  202. package/squads/squad-storytelling/agents/marshall-ganz.md +15 -0
  203. package/squads/squad-storytelling/agents/nancy-duarte.md +15 -0
  204. package/squads/squad-storytelling/agents/oren-klaff.md +15 -0
  205. package/squads/squad-storytelling/agents/park-howell.md +13 -0
  206. package/squads/squad-storytelling/agents/storytelling-orqx.md +13 -0
  207. package/.sinapse-ai/core/grounding/README.md +0 -83
  208. package/.sinapse-ai/core/grounding/brand.cjs +0 -29
  209. package/.sinapse-ai/core/grounding/config-loader.cjs +0 -52
  210. package/.sinapse-ai/core/grounding/design-system.cjs +0 -29
  211. package/.sinapse-ai/core/grounding/vault.cjs +0 -36
  212. package/.sinapse-ai/development/scripts/approval-workflow.js +0 -643
  213. package/.sinapse-ai/development/scripts/backup-manager.js +0 -607
  214. package/.sinapse-ai/development/scripts/branch-manager.js +0 -390
  215. package/.sinapse-ai/development/scripts/code-quality-improver.js +0 -1329
  216. package/.sinapse-ai/development/scripts/commit-message-generator.js +0 -850
  217. package/.sinapse-ai/development/scripts/conflict-resolver.js +0 -675
  218. package/.sinapse-ai/development/scripts/dependency-analyzer.js +0 -638
  219. package/.sinapse-ai/development/scripts/diff-generator.js +0 -352
  220. package/.sinapse-ai/development/scripts/git-wrapper.js +0 -462
  221. package/.sinapse-ai/development/scripts/modification-validator.js +0 -555
  222. package/.sinapse-ai/development/scripts/performance-analyzer.js +0 -758
  223. package/.sinapse-ai/development/scripts/refactoring-suggester.js +0 -1148
  224. package/.sinapse-ai/development/scripts/rollback-handler.js +0 -531
  225. package/.sinapse-ai/development/scripts/security-checker.js +0 -359
  226. package/.sinapse-ai/development/scripts/template-engine.js +0 -240
  227. package/.sinapse-ai/development/scripts/template-validator.js +0 -279
  228. package/.sinapse-ai/development/scripts/test-generator.js +0 -844
  229. package/.sinapse-ai/development/scripts/transaction-manager.js +0 -590
  230. package/.sinapse-ai/development/scripts/yaml-validator.js +0 -397
  231. package/.sinapse-ai/hooks/sinapse-brand-grounding.cjs +0 -162
  232. package/.sinapse-ai/hooks/sinapse-ds-grounding.cjs +0 -211
  233. package/.sinapse-ai/hooks/sinapse-vault-grounding.cjs +0 -194
  234. package/bin/lib/register-grounding-hooks.js +0 -145
  235. package/docs/guides/agents/traces/execution-traces.zip +0 -0
  236. package/docs/guides/grounding-setup.md +0 -154
  237. package/docs/guides/workflows/SINAPSE-WORKFLOWS.zip +0 -0
  238. package/packages/installer/src/pro/pro-scaffolder.js +0 -449
  239. package/packages/installer/src/wizard/grounding-config.js +0 -131
  240. package/packages/installer/src/wizard/pro-setup.js +0 -1439
  241. package/packages/installer/templates/README.md +0 -16
  242. package/packages/installer/templates/brand-routing.example.json +0 -12
  243. package/packages/installer/templates/ds-routing.example.json +0 -12
  244. package/packages/installer/templates/vault-routing.example.json +0 -12
@@ -1,758 +0,0 @@
1
- const fs = require('fs').promises;
2
- const path = require('path');
3
- const chalk = require('chalk');
4
-
5
- /**
6
- * Performance bottleneck analyzer for SINAPSE-FULLSTACK framework
7
- * Identifies performance issues and optimization opportunities
8
- */
9
- class PerformanceAnalyzer {
10
- constructor(options = {}) {
11
- this.rootPath = options.rootPath || process.cwd();
12
- this.thresholds = {
13
- fileSize: 50 * 1024, // 50KB
14
- functionLength: 50, // lines
15
- cyclomaticComplexity: 10,
16
- nestingDepth: 5,
17
- importCount: 20,
18
- unusedCode: 0.1 // 10% unused code ratio
19
- };
20
- this.performancePatterns = {
21
- // Sync operations that should be async
22
- syncOperations: [
23
- /fs\.readFileSync/g,
24
- /fs\.writeFileSync/g,
25
- /fs\.existsSync/g,
26
- /JSON\.parse\(\s*fs\.readFileSync/g
27
- ],
28
- // Memory-intensive patterns
29
- memoryIssues: [
30
- /\.map\(\s*.*\.map\(/g, // Nested maps
31
- /new Array\(\d{4,}\)/g, // Large arrays
32
- /JSON\.stringify.*JSON\.parse/g, // Unnecessary serialization
33
- /require\(\s*['"`][^'"`]+\.json['"`]\s*\)/g // Large JSON imports
34
- ],
35
- // Performance anti-patterns
36
- antiPatterns: [
37
- /console\.log/g, // Console logs in production
38
- /debugger/g, // Debugger statements
39
- /setTimeout\(\s*.*,\s*0\s*\)/g, // Unnecessary setTimeout
40
- /setInterval\(\s*.*,\s*[0-9]{1,2}\s*\)/g // High-frequency intervals
41
- ],
42
- // Inefficient loops
43
- inefficientLoops: [
44
- /for\s*\(\s*.*\.length\s*;/g, // Length calculated in loop condition
45
- /while\s*\(\s*true\s*\)/g, // Infinite loops
46
- /forEach.*forEach/g // Nested forEach
47
- ]
48
- };
49
- }
50
-
51
- /**
52
- * Analyze performance across all components
53
- */
54
- async analyzePerformance(components) {
55
- const analysis = {
56
- timestamp: new Date().toISOString(),
57
- overall_score: 0,
58
- bottlenecks: [],
59
- optimization_opportunities: [],
60
- memory_issues: [],
61
- async_opportunities: [],
62
- code_quality_issues: [],
63
- file_size_issues: [],
64
- complexity_issues: [],
65
- recommendations: [],
66
- metrics: {
67
- total_files_analyzed: 0,
68
- total_issues_found: 0,
69
- critical_issues: 0,
70
- high_priority_issues: 0,
71
- medium_priority_issues: 0,
72
- low_priority_issues: 0
73
- }
74
- };
75
-
76
- try {
77
- console.log(chalk.blue('🔍 Analyzing performance bottlenecks...'));
78
-
79
- // Analyze each component
80
- for (const component of components) {
81
- const componentAnalysis = await this.analyzeComponentPerformance(component);
82
-
83
- // Aggregate results
84
- analysis.bottlenecks.push(...componentAnalysis.bottlenecks);
85
- analysis.optimization_opportunities.push(...componentAnalysis.optimizations);
86
- analysis.memory_issues.push(...componentAnalysis.memory_issues);
87
- analysis.async_opportunities.push(...componentAnalysis.async_opportunities);
88
- analysis.code_quality_issues.push(...componentAnalysis.quality_issues);
89
- analysis.file_size_issues.push(...componentAnalysis.file_size_issues);
90
- analysis.complexity_issues.push(...componentAnalysis.complexity_issues);
91
-
92
- analysis.metrics.total_files_analyzed++;
93
- }
94
-
95
- // Calculate overall metrics
96
- analysis.overall_score = this.calculateOverallScore(analysis);
97
- analysis.metrics.total_issues_found = this.countTotalIssues(analysis);
98
- analysis.metrics = this.calculateIssuePriorities(analysis);
99
- analysis.recommendations = this.generatePerformanceRecommendations(analysis);
100
-
101
- console.log(chalk.green(`✅ Performance analysis completed`));
102
- console.log(chalk.gray(` Files analyzed: ${analysis.metrics.total_files_analyzed}`));
103
- console.log(chalk.gray(` Issues found: ${analysis.metrics.total_issues_found}`));
104
- console.log(chalk.gray(` Overall score: ${analysis.overall_score}/10`));
105
-
106
- return analysis;
107
-
108
- } catch (error) {
109
- console.error(chalk.red(`Performance analysis failed: ${error.message}`));
110
- throw error;
111
- }
112
- }
113
-
114
- /**
115
- * Analyze performance for a single component
116
- */
117
- async analyzeComponentPerformance(component) {
118
- const analysis = {
119
- component_id: component.id,
120
- component_type: component.type,
121
- bottlenecks: [],
122
- optimizations: [],
123
- memory_issues: [],
124
- async_opportunities: [],
125
- quality_issues: [],
126
- file_size_issues: [],
127
- complexity_issues: []
128
- };
129
-
130
- try {
131
- // Only analyze JavaScript files and executable components
132
- if (!this.shouldAnalyzeComponent(component)) {
133
- return analysis;
134
- }
135
-
136
- const filePath = path.join(this.rootPath, component.file_path);
137
- const content = await fs.readFile(filePath, 'utf-8');
138
- const stats = await fs.stat(filePath);
139
-
140
- // File size analysis
141
- if (stats.size > this.thresholds.fileSize) {
142
- analysis.file_size_issues.push({
143
- component: component.id,
144
- issue: `Large file size: ${this.formatBytes(stats.size)}`,
145
- severity: stats.size > this.thresholds.fileSize * 2 ? 'high' : 'medium',
146
- recommendation: 'Consider breaking down into smaller modules',
147
- impact: 'high',
148
- effort: 'medium'
149
- });
150
- }
151
-
152
- // Synchronous operations analysis
153
- const syncIssues = this.findSyncOperations(content, component);
154
- analysis.async_opportunities.push(...syncIssues);
155
-
156
- // Memory usage analysis
157
- const memoryIssues = this.findMemoryIssues(content, component);
158
- analysis.memory_issues.push(...memoryIssues);
159
-
160
- // Performance anti-patterns
161
- const antiPatterns = this.findAntiPatterns(content, component);
162
- analysis.quality_issues.push(...antiPatterns);
163
-
164
- // Loop efficiency analysis
165
- const loopIssues = this.findLoopIssues(content, component);
166
- analysis.bottlenecks.push(...loopIssues);
167
-
168
- // Function complexity analysis
169
- const complexityIssues = this.analyzeComplexity(content, component);
170
- analysis.complexity_issues.push(...complexityIssues);
171
-
172
- // Import/require analysis
173
- const importIssues = this.analyzeImports(content, component);
174
- analysis.optimizations.push(...importIssues);
175
-
176
- // Dead code analysis
177
- const deadCodeIssues = await this.findDeadCode(content, component);
178
- analysis.optimizations.push(...deadCodeIssues);
179
-
180
- } catch (error) {
181
- console.warn(chalk.yellow(`Failed to analyze performance for ${component.id}: ${error.message}`));
182
- }
183
-
184
- return analysis;
185
- }
186
-
187
- /**
188
- * Find synchronous operations that should be async
189
- */
190
- findSyncOperations(content, component) {
191
- const issues = [];
192
- const lines = content.split('\n');
193
-
194
- this.performancePatterns.syncOperations.forEach(pattern => {
195
- lines.forEach((line, index) => {
196
- const matches = line.match(pattern);
197
- if (matches) {
198
- matches.forEach(match => {
199
- issues.push({
200
- component: component.id,
201
- issue: `Synchronous operation: ${match}`,
202
- line: index + 1,
203
- context: line.trim(),
204
- severity: 'high',
205
- recommendation: 'Convert to async equivalent',
206
- impact: 'high',
207
- effort: 'low'
208
- });
209
- });
210
- }
211
- });
212
- });
213
-
214
- return issues;
215
- }
216
-
217
- /**
218
- * Find memory-intensive patterns
219
- */
220
- findMemoryIssues(content, component) {
221
- const issues = [];
222
- const lines = content.split('\n');
223
-
224
- this.performancePatterns.memoryIssues.forEach(pattern => {
225
- lines.forEach((line, index) => {
226
- const matches = line.match(pattern);
227
- if (matches) {
228
- matches.forEach(match => {
229
- let severity = 'medium';
230
- let recommendation = 'Optimize memory usage';
231
-
232
- if (match.includes('new Array')) {
233
- severity = 'high';
234
- recommendation = 'Use array literals or streaming for large datasets';
235
- } else if (match.includes('JSON.stringify.*JSON.parse')) {
236
- recommendation = 'Use direct object assignment or deep clone utilities';
237
- } else if (match.includes('.map(.*map(')) {
238
- recommendation = 'Combine operations or use more efficient iteration';
239
- }
240
-
241
- issues.push({
242
- component: component.id,
243
- issue: `Memory-intensive pattern: ${match}`,
244
- line: index + 1,
245
- context: line.trim(),
246
- severity,
247
- recommendation,
248
- impact: 'medium',
249
- effort: 'medium'
250
- });
251
- });
252
- }
253
- });
254
- });
255
-
256
- return issues;
257
- }
258
-
259
- /**
260
- * Find performance anti-patterns
261
- */
262
- findAntiPatterns(content, component) {
263
- const issues = [];
264
- const lines = content.split('\n');
265
-
266
- this.performancePatterns.antiPatterns.forEach(pattern => {
267
- lines.forEach((line, index) => {
268
- const matches = line.match(pattern);
269
- if (matches) {
270
- matches.forEach(match => {
271
- let severity = 'low';
272
- let recommendation = 'Remove or optimize';
273
-
274
- if (match.includes('console.log')) {
275
- recommendation = 'Remove console.log statements from production code';
276
- } else if (match.includes('debugger')) {
277
- severity = 'medium';
278
- recommendation = 'Remove debugger statements';
279
- } else if (match.includes('setTimeout')) {
280
- recommendation = 'Use proper async/await or promises instead';
281
- }
282
-
283
- issues.push({
284
- component: component.id,
285
- issue: `Performance anti-pattern: ${match}`,
286
- line: index + 1,
287
- context: line.trim(),
288
- severity,
289
- recommendation,
290
- impact: 'low',
291
- effort: 'low'
292
- });
293
- });
294
- }
295
- });
296
- });
297
-
298
- return issues;
299
- }
300
-
301
- /**
302
- * Find inefficient loop patterns
303
- */
304
- findLoopIssues(content, component) {
305
- const issues = [];
306
- const lines = content.split('\n');
307
-
308
- this.performancePatterns.inefficientLoops.forEach(pattern => {
309
- lines.forEach((line, index) => {
310
- const matches = line.match(pattern);
311
- if (matches) {
312
- matches.forEach(match => {
313
- let severity = 'medium';
314
- let recommendation = 'Optimize loop structure';
315
-
316
- if (match.includes('.length')) {
317
- recommendation = 'Cache array length in variable before loop';
318
- } else if (match.includes('while(true)')) {
319
- severity = 'high';
320
- recommendation = 'Add proper exit condition to prevent infinite loops';
321
- } else if (match.includes('forEach.*forEach')) {
322
- recommendation = 'Consider using nested for loops or array methods like flatMap';
323
- }
324
-
325
- issues.push({
326
- component: component.id,
327
- issue: `Inefficient loop: ${match}`,
328
- line: index + 1,
329
- context: line.trim(),
330
- severity,
331
- recommendation,
332
- impact: 'medium',
333
- effort: 'low'
334
- });
335
- });
336
- }
337
- });
338
- });
339
-
340
- return issues;
341
- }
342
-
343
- /**
344
- * Analyze function complexity
345
- */
346
- analyzeComplexity(content, component) {
347
- const issues = [];
348
- const functions = this.extractFunctions(content);
349
-
350
- functions.forEach(func => {
351
- // Check function length
352
- if (func.lines > this.thresholds.functionLength) {
353
- issues.push({
354
- component: component.id,
355
- issue: `Long function: ${func.name} (${func.lines} lines)`,
356
- line: func.startLine,
357
- severity: func.lines > this.thresholds.functionLength * 2 ? 'high' : 'medium',
358
- recommendation: 'Break down into smaller functions',
359
- impact: 'medium',
360
- effort: 'medium'
361
- });
362
- }
363
-
364
- // Check cyclomatic complexity
365
- if (func.complexity > this.thresholds.cyclomaticComplexity) {
366
- issues.push({
367
- component: component.id,
368
- issue: `High complexity: ${func.name} (complexity: ${func.complexity})`,
369
- line: func.startLine,
370
- severity: func.complexity > this.thresholds.cyclomaticComplexity * 1.5 ? 'high' : 'medium',
371
- recommendation: 'Reduce conditional complexity',
372
- impact: 'high',
373
- effort: 'high'
374
- });
375
- }
376
-
377
- // Check nesting depth
378
- if (func.nestingDepth > this.thresholds.nestingDepth) {
379
- issues.push({
380
- component: component.id,
381
- issue: `Deep nesting: ${func.name} (depth: ${func.nestingDepth})`,
382
- line: func.startLine,
383
- severity: 'medium',
384
- recommendation: 'Reduce nesting depth using early returns or guard clauses',
385
- impact: 'medium',
386
- effort: 'medium'
387
- });
388
- }
389
- });
390
-
391
- return issues;
392
- }
393
-
394
- /**
395
- * Analyze imports and requires
396
- */
397
- analyzeImports(content, component) {
398
- const issues = [];
399
- const imports = this.extractImports(content);
400
-
401
- if (imports.length > this.thresholds.importCount) {
402
- issues.push({
403
- component: component.id,
404
- issue: `Too many imports: ${imports.length}`,
405
- severity: 'medium',
406
- recommendation: 'Consider breaking down module or using dynamic imports',
407
- impact: 'low',
408
- effort: 'medium'
409
- });
410
- }
411
-
412
- // Find unused imports (basic heuristic)
413
- const unusedImports = imports.filter(imp => {
414
- const usage = content.split(imp.name).length - 1;
415
- return usage <= 1; // Only appears in import statement
416
- });
417
-
418
- if (unusedImports.length > 0) {
419
- issues.push({
420
- component: component.id,
421
- issue: `Unused imports: ${unusedImports.map(i => i.name).join(', ')}`,
422
- severity: 'low',
423
- recommendation: 'Remove unused imports',
424
- impact: 'low',
425
- effort: 'low'
426
- });
427
- }
428
-
429
- return issues;
430
- }
431
-
432
- /**
433
- * Find dead code (unused functions, variables)
434
- */
435
- async findDeadCode(content, component) {
436
- const issues = [];
437
-
438
- // This is a simplified implementation
439
- // A full implementation would analyze the entire codebase for usage
440
- const functions = this.extractFunctions(content);
441
- const exports = this.extractExports(content);
442
-
443
- // Check for functions that are defined but never called within the file
444
- functions.forEach(func => {
445
- if (!func.name.startsWith('_') && !exports.includes(func.name)) {
446
- const usage = content.split(func.name).length - 1;
447
- if (usage <= 1) { // Only appears in definition
448
- issues.push({
449
- component: component.id,
450
- issue: `Potentially unused function: ${func.name}`,
451
- line: func.startLine,
452
- severity: 'low',
453
- recommendation: 'Remove if truly unused or export if needed elsewhere',
454
- impact: 'low',
455
- effort: 'low'
456
- });
457
- }
458
- }
459
- });
460
-
461
- return issues;
462
- }
463
-
464
- /**
465
- * Extract function information from code
466
- */
467
- extractFunctions(content) {
468
- const functions = [];
469
- const lines = content.split('\n');
470
- const functionRegex = /(?:function\s+(\w+)|(\w+)\s*[:=]\s*(?:async\s+)?function|(?:async\s+)?(\w+)\s*\([^)]*\)\s*(?:=>|{))/g;
471
-
472
- lines.forEach((line, index) => {
473
- const matches = [...line.matchAll(functionRegex)];
474
- matches.forEach(match => {
475
- const name = match[1] || match[2] || match[3] || 'anonymous';
476
-
477
- // Calculate function metrics (simplified)
478
- const funcInfo = {
479
- name,
480
- startLine: index + 1,
481
- lines: this.estimateFunctionLength(lines, index),
482
- complexity: this.estimateComplexity(lines, index),
483
- nestingDepth: this.estimateNestingDepth(lines, index)
484
- };
485
-
486
- functions.push(funcInfo);
487
- });
488
- });
489
-
490
- return functions;
491
- }
492
-
493
- /**
494
- * Extract import information
495
- */
496
- extractImports(content) {
497
- const imports = [];
498
- const importRegex = /(?:import\s+(?:(\w+)|\{([^}]+)\}|.*)\s+from\s+['"`]([^'"`]+)['"`]|const\s+(?:(\w+)|\{([^}]+)\})\s*=\s*require\(['"`]([^'"`]+)['"`]\))/g;
499
-
500
- const matches = [...content.matchAll(importRegex)];
501
- matches.forEach(match => {
502
- const defaultImport = match[1] || match[4];
503
- const namedImports = match[2] || match[5];
504
- const source = match[3] || match[6];
505
-
506
- if (defaultImport) {
507
- imports.push({ name: defaultImport, source, type: 'default' });
508
- }
509
-
510
- if (namedImports) {
511
- namedImports.split(',').forEach(name => {
512
- imports.push({ name: name.trim(), source, type: 'named' });
513
- });
514
- }
515
- });
516
-
517
- return imports;
518
- }
519
-
520
- /**
521
- * Extract export information
522
- */
523
- extractExports(content) {
524
- const exports = [];
525
- const exportRegex = /(?:export\s+(?:default\s+)?(?:function\s+(\w+)|class\s+(\w+)|(?:const|let|var)\s+(\w+))|module\.exports\s*=\s*(\w+))/g;
526
-
527
- const matches = [...content.matchAll(exportRegex)];
528
- matches.forEach(match => {
529
- const name = match[1] || match[2] || match[3] || match[4];
530
- if (name) exports.push(name);
531
- });
532
-
533
- return exports;
534
- }
535
-
536
- /**
537
- * Estimate function length (simplified)
538
- */
539
- estimateFunctionLength(lines, startIndex) {
540
- let braceCount = 0;
541
- let lineCount = 0;
542
- let inFunction = false;
543
-
544
- for (let i = startIndex; i < lines.length; i++) {
545
- const line = lines[i];
546
- lineCount++;
547
-
548
- // Count braces to find function end
549
- for (const char of line) {
550
- if (char === '{') {
551
- braceCount++;
552
- inFunction = true;
553
- } else if (char === '}') {
554
- braceCount--;
555
- if (inFunction && braceCount === 0) {
556
- return lineCount;
557
- }
558
- }
559
- }
560
-
561
- // Safety limit
562
- if (lineCount > 200) break;
563
- }
564
-
565
- return lineCount;
566
- }
567
-
568
- /**
569
- * Estimate cyclomatic complexity (simplified)
570
- */
571
- estimateComplexity(lines, startIndex) {
572
- let complexity = 1; // Base complexity
573
- const complexityKeywords = ['if', 'else', 'while', 'for', 'switch', 'case', 'catch', '&&', '||', '?'];
574
-
575
- const functionLines = lines.slice(startIndex, startIndex + this.estimateFunctionLength(lines, startIndex));
576
-
577
- functionLines.forEach(line => {
578
- complexityKeywords.forEach(keyword => {
579
- const matches = line.match(new RegExp(`\\b${keyword}\\b`, 'g'));
580
- if (matches) {
581
- complexity += matches.length;
582
- }
583
- });
584
- });
585
-
586
- return complexity;
587
- }
588
-
589
- /**
590
- * Estimate nesting depth (simplified)
591
- */
592
- estimateNestingDepth(lines, startIndex) {
593
- let maxDepth = 0;
594
- let currentDepth = 0;
595
-
596
- const functionLines = lines.slice(startIndex, startIndex + this.estimateFunctionLength(lines, startIndex));
597
-
598
- functionLines.forEach(line => {
599
- for (const char of line) {
600
- if (char === '{') {
601
- currentDepth++;
602
- maxDepth = Math.max(maxDepth, currentDepth);
603
- } else if (char === '}') {
604
- currentDepth--;
605
- }
606
- }
607
- });
608
-
609
- return maxDepth;
610
- }
611
-
612
- /**
613
- * Calculate overall performance score
614
- */
615
- calculateOverallScore(analysis) {
616
- let score = 10;
617
- const penalties = {
618
- critical: 2,
619
- high: 1,
620
- medium: 0.5,
621
- low: 0.1
622
- };
623
-
624
- // Apply penalties based on issue severity
625
- [...analysis.bottlenecks, ...analysis.memory_issues, ...analysis.async_opportunities,
626
- ...analysis.code_quality_issues, ...analysis.file_size_issues, ...analysis.complexity_issues]
627
- .forEach(issue => {
628
- score -= penalties[issue.severity] || 0.1;
629
- });
630
-
631
- return Math.max(0, Math.round(score * 10) / 10);
632
- }
633
-
634
- /**
635
- * Count total issues
636
- */
637
- countTotalIssues(analysis) {
638
- return analysis.bottlenecks.length +
639
- analysis.memory_issues.length +
640
- analysis.async_opportunities.length +
641
- analysis.code_quality_issues.length +
642
- analysis.file_size_issues.length +
643
- analysis.complexity_issues.length;
644
- }
645
-
646
- /**
647
- * Calculate issue priorities
648
- */
649
- calculateIssuePriorities(analysis) {
650
- const metrics = analysis.metrics;
651
- const allIssues = [
652
- ...analysis.bottlenecks,
653
- ...analysis.memory_issues,
654
- ...analysis.async_opportunities,
655
- ...analysis.code_quality_issues,
656
- ...analysis.file_size_issues,
657
- ...analysis.complexity_issues
658
- ];
659
-
660
- metrics.critical_issues = allIssues.filter(i => i.severity === 'critical').length;
661
- metrics.high_priority_issues = allIssues.filter(i => i.severity === 'high').length;
662
- metrics.medium_priority_issues = allIssues.filter(i => i.severity === 'medium').length;
663
- metrics.low_priority_issues = allIssues.filter(i => i.severity === 'low').length;
664
-
665
- return metrics;
666
- }
667
-
668
- /**
669
- * Generate performance recommendations
670
- */
671
- generatePerformanceRecommendations(analysis) {
672
- const recommendations = [];
673
-
674
- // Critical issues
675
- if (analysis.metrics.critical_issues > 0) {
676
- recommendations.push({
677
- priority: 'critical',
678
- category: 'immediate_action',
679
- message: `${analysis.metrics.critical_issues} critical performance issues require immediate attention`,
680
- action: 'Fix critical bottlenecks before deployment'
681
- });
682
- }
683
-
684
- // High severity issues
685
- if (analysis.metrics.high_priority_issues > 5) {
686
- recommendations.push({
687
- priority: 'high',
688
- category: 'performance',
689
- message: `${analysis.metrics.high_priority_issues} high-priority performance issues detected`,
690
- action: 'Address synchronous operations and complexity issues'
691
- });
692
- }
693
-
694
- // Memory issues
695
- if (analysis.memory_issues.length > 0) {
696
- recommendations.push({
697
- priority: 'medium',
698
- category: 'memory',
699
- message: `${analysis.memory_issues.length} memory optimization opportunities found`,
700
- action: 'Implement memory-efficient patterns and data structures'
701
- });
702
- }
703
-
704
- // File size issues
705
- if (analysis.file_size_issues.length > 0) {
706
- recommendations.push({
707
- priority: 'medium',
708
- category: 'modularity',
709
- message: `${analysis.file_size_issues.length} files are too large`,
710
- action: 'Break down large files into smaller, focused modules'
711
- });
712
- }
713
-
714
- // Overall score
715
- if (analysis.overall_score < 7) {
716
- recommendations.push({
717
- priority: 'high',
718
- category: 'general',
719
- message: `Overall performance score is ${analysis.overall_score}/10`,
720
- action: 'Comprehensive performance review and optimization needed'
721
- });
722
- }
723
-
724
- return recommendations;
725
- }
726
-
727
- /**
728
- * Check if component should be analyzed
729
- */
730
- shouldAnalyzeComponent(component) {
731
- const analyzableTypes = ['utility', 'task'];
732
- const analyzableExtensions = ['.js', '.mjs', '.ts'];
733
-
734
- if (!analyzableTypes.includes(component.type)) {
735
- return false;
736
- }
737
-
738
- if (component.file_path) {
739
- const ext = path.extname(component.file_path).toLowerCase();
740
- return analyzableExtensions.includes(ext);
741
- }
742
-
743
- return false;
744
- }
745
-
746
- /**
747
- * Format bytes for display
748
- */
749
- formatBytes(bytes) {
750
- if (bytes === 0) return '0 B';
751
- const k = 1024;
752
- const sizes = ['B', 'KB', 'MB', 'GB'];
753
- const i = Math.floor(Math.log(bytes) / Math.log(k));
754
- return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i];
755
- }
756
- }
757
-
758
- module.exports = PerformanceAnalyzer;