@oalacea/daemon 0.6.4 → 0.7.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.
- package/README.md +268 -58
- package/bin/Dockerfile +158 -16
- package/dist/cli/cli.d.ts.map +1 -1
- package/dist/cli/cli.js +22 -2
- package/dist/cli/cli.js.map +1 -1
- package/dist/cli/commands/command.types.d.ts +216 -0
- package/dist/cli/commands/command.types.d.ts.map +1 -0
- package/dist/cli/commands/command.types.js +64 -0
- package/dist/cli/commands/command.types.js.map +1 -0
- package/dist/cli/commands/history.command.d.ts +91 -0
- package/dist/cli/commands/history.command.d.ts.map +1 -0
- package/dist/cli/commands/history.command.js +336 -0
- package/dist/cli/commands/history.command.js.map +1 -0
- package/dist/cli/commands/index.d.ts +14 -3
- package/dist/cli/commands/index.d.ts.map +1 -1
- package/dist/cli/commands/index.js +7 -0
- package/dist/cli/commands/index.js.map +1 -1
- package/dist/cli/commands/optimize.command.d.ts +110 -0
- package/dist/cli/commands/optimize.command.d.ts.map +1 -0
- package/dist/cli/commands/optimize.command.js +497 -0
- package/dist/cli/commands/optimize.command.js.map +1 -0
- package/dist/cli/commands/report.command.d.ts +110 -0
- package/dist/cli/commands/report.command.d.ts.map +1 -0
- package/dist/cli/commands/report.command.js +532 -0
- package/dist/cli/commands/report.command.js.map +1 -0
- package/dist/cli/commands/review.command.d.ts +110 -0
- package/dist/cli/commands/review.command.d.ts.map +1 -0
- package/dist/cli/commands/review.command.js +520 -0
- package/dist/cli/commands/review.command.js.map +1 -0
- package/dist/cli/commands/score.command.d.ts +47 -0
- package/dist/cli/commands/score.command.d.ts.map +1 -0
- package/dist/cli/commands/score.command.js +261 -0
- package/dist/cli/commands/score.command.js.map +1 -0
- package/dist/cli/utils/index.d.ts +10 -0
- package/dist/cli/utils/index.d.ts.map +1 -0
- package/dist/cli/utils/index.js +10 -0
- package/dist/cli/utils/index.js.map +1 -0
- package/dist/cli/utils/output.d.ts +192 -0
- package/dist/cli/utils/output.d.ts.map +1 -0
- package/dist/cli/utils/output.js +411 -0
- package/dist/cli/utils/output.js.map +1 -0
- package/dist/cli/utils/progress.d.ts +204 -0
- package/dist/cli/utils/progress.d.ts.map +1 -0
- package/dist/cli/utils/progress.js +396 -0
- package/dist/cli/utils/progress.js.map +1 -0
- package/dist/core/types/index.d.ts +1 -0
- package/dist/core/types/index.d.ts.map +1 -1
- package/dist/core/types/project.types.d.ts +3 -3
- package/dist/core/types/project.types.d.ts.map +1 -1
- package/dist/core/types/scoring.types.d.ts +301 -0
- package/dist/core/types/scoring.types.d.ts.map +1 -0
- package/dist/core/types/scoring.types.js +8 -0
- package/dist/core/types/scoring.types.js.map +1 -0
- package/dist/services/detection/framework-detector.d.ts.map +1 -1
- package/dist/services/detection/framework-detector.js +74 -5
- package/dist/services/detection/framework-detector.js.map +1 -1
- package/dist/services/index.d.ts +12 -0
- package/dist/services/index.d.ts.map +1 -1
- package/dist/services/index.js +14 -0
- package/dist/services/index.js.map +1 -1
- package/dist/services/optimization/detectors/bug-detector.d.ts +82 -0
- package/dist/services/optimization/detectors/bug-detector.d.ts.map +1 -0
- package/dist/services/optimization/detectors/bug-detector.js +443 -0
- package/dist/services/optimization/detectors/bug-detector.js.map +1 -0
- package/dist/services/optimization/detectors/code-smell-detector.d.ts +108 -0
- package/dist/services/optimization/detectors/code-smell-detector.d.ts.map +1 -0
- package/dist/services/optimization/detectors/code-smell-detector.js +569 -0
- package/dist/services/optimization/detectors/code-smell-detector.js.map +1 -0
- package/dist/services/optimization/detectors/index.d.ts +7 -0
- package/dist/services/optimization/detectors/index.d.ts.map +1 -0
- package/dist/services/optimization/detectors/index.js +7 -0
- package/dist/services/optimization/detectors/index.js.map +1 -0
- package/dist/services/optimization/detectors/perf-detector.d.ts +80 -0
- package/dist/services/optimization/detectors/perf-detector.d.ts.map +1 -0
- package/dist/services/optimization/detectors/perf-detector.js +451 -0
- package/dist/services/optimization/detectors/perf-detector.js.map +1 -0
- package/dist/services/optimization/index.d.ts +61 -0
- package/dist/services/optimization/index.d.ts.map +1 -0
- package/dist/services/optimization/index.js +69 -0
- package/dist/services/optimization/index.js.map +1 -0
- package/dist/services/optimization/optimization.service.d.ts +65 -0
- package/dist/services/optimization/optimization.service.d.ts.map +1 -0
- package/dist/services/optimization/optimization.service.js +511 -0
- package/dist/services/optimization/optimization.service.js.map +1 -0
- package/dist/services/optimization/optimization.types.d.ts +343 -0
- package/dist/services/optimization/optimization.types.d.ts.map +1 -0
- package/dist/services/optimization/optimization.types.js +8 -0
- package/dist/services/optimization/optimization.types.js.map +1 -0
- package/dist/services/optimization/optimizers/code-optimizer.d.ts +87 -0
- package/dist/services/optimization/optimizers/code-optimizer.d.ts.map +1 -0
- package/dist/services/optimization/optimizers/code-optimizer.js +436 -0
- package/dist/services/optimization/optimizers/code-optimizer.js.map +1 -0
- package/dist/services/optimization/optimizers/index.d.ts +7 -0
- package/dist/services/optimization/optimizers/index.d.ts.map +1 -0
- package/dist/services/optimization/optimizers/index.js +7 -0
- package/dist/services/optimization/optimizers/index.js.map +1 -0
- package/dist/services/optimization/optimizers/perf-optimizer.d.ts +64 -0
- package/dist/services/optimization/optimizers/perf-optimizer.d.ts.map +1 -0
- package/dist/services/optimization/optimizers/perf-optimizer.js +330 -0
- package/dist/services/optimization/optimizers/perf-optimizer.js.map +1 -0
- package/dist/services/optimization/optimizers/refact-optimizer.d.ts +82 -0
- package/dist/services/optimization/optimizers/refact-optimizer.d.ts.map +1 -0
- package/dist/services/optimization/optimizers/refact-optimizer.js +354 -0
- package/dist/services/optimization/optimizers/refact-optimizer.js.map +1 -0
- package/dist/services/optimization/patterns/anti-patterns.d.ts +31 -0
- package/dist/services/optimization/patterns/anti-patterns.d.ts.map +1 -0
- package/dist/services/optimization/patterns/anti-patterns.js +501 -0
- package/dist/services/optimization/patterns/anti-patterns.js.map +1 -0
- package/dist/services/optimization/patterns/index.d.ts +5 -0
- package/dist/services/optimization/patterns/index.d.ts.map +1 -0
- package/dist/services/optimization/patterns/index.js +5 -0
- package/dist/services/optimization/patterns/index.js.map +1 -0
- package/dist/services/reporting/export/chart.exporter.d.ts +59 -0
- package/dist/services/reporting/export/chart.exporter.d.ts.map +1 -0
- package/dist/services/reporting/export/chart.exporter.js +350 -0
- package/dist/services/reporting/export/chart.exporter.js.map +1 -0
- package/dist/services/reporting/export/index.d.ts +9 -0
- package/dist/services/reporting/export/index.d.ts.map +1 -0
- package/dist/services/reporting/export/index.js +10 -0
- package/dist/services/reporting/export/index.js.map +1 -0
- package/dist/services/reporting/export/pdf.exporter.d.ts +133 -0
- package/dist/services/reporting/export/pdf.exporter.d.ts.map +1 -0
- package/dist/services/reporting/export/pdf.exporter.js +270 -0
- package/dist/services/reporting/export/pdf.exporter.js.map +1 -0
- package/dist/services/reporting/history.service.d.ts +93 -0
- package/dist/services/reporting/history.service.d.ts.map +1 -0
- package/dist/services/reporting/history.service.js +285 -0
- package/dist/services/reporting/history.service.js.map +1 -0
- package/dist/services/reporting/index.d.ts +15 -0
- package/dist/services/reporting/index.d.ts.map +1 -0
- package/dist/services/reporting/index.js +16 -0
- package/dist/services/reporting/index.js.map +1 -0
- package/dist/services/reporting/report.service.d.ts +102 -0
- package/dist/services/reporting/report.service.d.ts.map +1 -0
- package/dist/services/reporting/report.service.js +240 -0
- package/dist/services/reporting/report.service.js.map +1 -0
- package/dist/services/reporting/reporting.types.d.ts +329 -0
- package/dist/services/reporting/reporting.types.d.ts.map +1 -0
- package/dist/services/reporting/reporting.types.js +8 -0
- package/dist/services/reporting/reporting.types.js.map +1 -0
- package/dist/services/reporting/templates/html.template.d.ts +81 -0
- package/dist/services/reporting/templates/html.template.d.ts.map +1 -0
- package/dist/services/reporting/templates/html.template.js +741 -0
- package/dist/services/reporting/templates/html.template.js.map +1 -0
- package/dist/services/reporting/templates/json.template.d.ts +85 -0
- package/dist/services/reporting/templates/json.template.d.ts.map +1 -0
- package/dist/services/reporting/templates/json.template.js +308 -0
- package/dist/services/reporting/templates/json.template.js.map +1 -0
- package/dist/services/reporting/templates/markdown.template.d.ts +69 -0
- package/dist/services/reporting/templates/markdown.template.d.ts.map +1 -0
- package/dist/services/reporting/templates/markdown.template.js +311 -0
- package/dist/services/reporting/templates/markdown.template.js.map +1 -0
- package/dist/services/reporting/trend-analyzer.d.ts +73 -0
- package/dist/services/reporting/trend-analyzer.d.ts.map +1 -0
- package/dist/services/reporting/trend-analyzer.js +291 -0
- package/dist/services/reporting/trend-analyzer.js.map +1 -0
- package/dist/services/review/analyzers/dependency-analyzer.d.ts +87 -0
- package/dist/services/review/analyzers/dependency-analyzer.d.ts.map +1 -0
- package/dist/services/review/analyzers/dependency-analyzer.js +458 -0
- package/dist/services/review/analyzers/dependency-analyzer.js.map +1 -0
- package/dist/services/review/analyzers/index.d.ts +13 -0
- package/dist/services/review/analyzers/index.d.ts.map +1 -0
- package/dist/services/review/analyzers/index.js +13 -0
- package/dist/services/review/analyzers/index.js.map +1 -0
- package/dist/services/review/analyzers/nestjs-analyzer.d.ts +210 -0
- package/dist/services/review/analyzers/nestjs-analyzer.d.ts.map +1 -0
- package/dist/services/review/analyzers/nestjs-analyzer.js +571 -0
- package/dist/services/review/analyzers/nestjs-analyzer.js.map +1 -0
- package/dist/services/review/analyzers/performance-analyzer.d.ts +91 -0
- package/dist/services/review/analyzers/performance-analyzer.d.ts.map +1 -0
- package/dist/services/review/analyzers/performance-analyzer.js +589 -0
- package/dist/services/review/analyzers/performance-analyzer.js.map +1 -0
- package/dist/services/review/analyzers/security-analyzer.d.ts +96 -0
- package/dist/services/review/analyzers/security-analyzer.d.ts.map +1 -0
- package/dist/services/review/analyzers/security-analyzer.js +512 -0
- package/dist/services/review/analyzers/security-analyzer.js.map +1 -0
- package/dist/services/review/analyzers/static-analyzer.d.ts +90 -0
- package/dist/services/review/analyzers/static-analyzer.d.ts.map +1 -0
- package/dist/services/review/analyzers/static-analyzer.js +423 -0
- package/dist/services/review/analyzers/static-analyzer.js.map +1 -0
- package/dist/services/review/fixers/auto-fixer.d.ts +94 -0
- package/dist/services/review/fixers/auto-fixer.d.ts.map +1 -0
- package/dist/services/review/fixers/auto-fixer.js +404 -0
- package/dist/services/review/fixers/auto-fixer.js.map +1 -0
- package/dist/services/review/fixers/index.d.ts +11 -0
- package/dist/services/review/fixers/index.d.ts.map +1 -0
- package/dist/services/review/fixers/index.js +11 -0
- package/dist/services/review/fixers/index.js.map +1 -0
- package/dist/services/review/fixers/refactor-suggester.d.ts +100 -0
- package/dist/services/review/fixers/refactor-suggester.d.ts.map +1 -0
- package/dist/services/review/fixers/refactor-suggester.js +555 -0
- package/dist/services/review/fixers/refactor-suggester.js.map +1 -0
- package/dist/services/review/fixers/test-generator.d.ts +99 -0
- package/dist/services/review/fixers/test-generator.d.ts.map +1 -0
- package/dist/services/review/fixers/test-generator.js +458 -0
- package/dist/services/review/fixers/test-generator.js.map +1 -0
- package/dist/services/review/index.d.ts +14 -0
- package/dist/services/review/index.d.ts.map +1 -0
- package/dist/services/review/index.js +14 -0
- package/dist/services/review/index.js.map +1 -0
- package/dist/services/review/reporters/fix-reporter.d.ts +67 -0
- package/dist/services/review/reporters/fix-reporter.d.ts.map +1 -0
- package/dist/services/review/reporters/fix-reporter.js +437 -0
- package/dist/services/review/reporters/fix-reporter.js.map +1 -0
- package/dist/services/review/reporters/index.d.ts +10 -0
- package/dist/services/review/reporters/index.d.ts.map +1 -0
- package/dist/services/review/reporters/index.js +10 -0
- package/dist/services/review/reporters/index.js.map +1 -0
- package/dist/services/review/reporters/score-reporter.d.ts +84 -0
- package/dist/services/review/reporters/score-reporter.d.ts.map +1 -0
- package/dist/services/review/reporters/score-reporter.js +560 -0
- package/dist/services/review/reporters/score-reporter.js.map +1 -0
- package/dist/services/review/review.service.d.ts +129 -0
- package/dist/services/review/review.service.d.ts.map +1 -0
- package/dist/services/review/review.service.js +396 -0
- package/dist/services/review/review.service.js.map +1 -0
- package/dist/services/review/review.types.d.ts +443 -0
- package/dist/services/review/review.types.d.ts.map +1 -0
- package/dist/services/review/review.types.js +11 -0
- package/dist/services/review/review.types.js.map +1 -0
- package/dist/services/scoring/dimensions/accessibility.analyzer.d.ts +53 -0
- package/dist/services/scoring/dimensions/accessibility.analyzer.d.ts.map +1 -0
- package/dist/services/scoring/dimensions/accessibility.analyzer.js +260 -0
- package/dist/services/scoring/dimensions/accessibility.analyzer.js.map +1 -0
- package/dist/services/scoring/dimensions/backend-logic.analyzer.d.ts +138 -0
- package/dist/services/scoring/dimensions/backend-logic.analyzer.d.ts.map +1 -0
- package/dist/services/scoring/dimensions/backend-logic.analyzer.js +713 -0
- package/dist/services/scoring/dimensions/backend-logic.analyzer.js.map +1 -0
- package/dist/services/scoring/dimensions/business-logic.analyzer.d.ts +142 -0
- package/dist/services/scoring/dimensions/business-logic.analyzer.d.ts.map +1 -0
- package/dist/services/scoring/dimensions/business-logic.analyzer.js +747 -0
- package/dist/services/scoring/dimensions/business-logic.analyzer.js.map +1 -0
- package/dist/services/scoring/dimensions/code-quality.analyzer.d.ts +142 -0
- package/dist/services/scoring/dimensions/code-quality.analyzer.d.ts.map +1 -0
- package/dist/services/scoring/dimensions/code-quality.analyzer.js +685 -0
- package/dist/services/scoring/dimensions/code-quality.analyzer.js.map +1 -0
- package/dist/services/scoring/dimensions/index.d.ts +18 -0
- package/dist/services/scoring/dimensions/index.d.ts.map +1 -0
- package/dist/services/scoring/dimensions/index.js +27 -0
- package/dist/services/scoring/dimensions/index.js.map +1 -0
- package/dist/services/scoring/dimensions/performance.analyzer.d.ts +125 -0
- package/dist/services/scoring/dimensions/performance.analyzer.d.ts.map +1 -0
- package/dist/services/scoring/dimensions/performance.analyzer.js +615 -0
- package/dist/services/scoring/dimensions/performance.analyzer.js.map +1 -0
- package/dist/services/scoring/dimensions/security.analyzer.d.ts +53 -0
- package/dist/services/scoring/dimensions/security.analyzer.d.ts.map +1 -0
- package/dist/services/scoring/dimensions/security.analyzer.js +327 -0
- package/dist/services/scoring/dimensions/security.analyzer.js.map +1 -0
- package/dist/services/scoring/dimensions/seo.analyzer.d.ts +77 -0
- package/dist/services/scoring/dimensions/seo.analyzer.d.ts.map +1 -0
- package/dist/services/scoring/dimensions/seo.analyzer.js +502 -0
- package/dist/services/scoring/dimensions/seo.analyzer.js.map +1 -0
- package/dist/services/scoring/dimensions/test-coverage.analyzer.d.ts +106 -0
- package/dist/services/scoring/dimensions/test-coverage.analyzer.d.ts.map +1 -0
- package/dist/services/scoring/dimensions/test-coverage.analyzer.js +496 -0
- package/dist/services/scoring/dimensions/test-coverage.analyzer.js.map +1 -0
- package/dist/services/scoring/dimensions/ui-ux.analyzer.d.ts +126 -0
- package/dist/services/scoring/dimensions/ui-ux.analyzer.d.ts.map +1 -0
- package/dist/services/scoring/dimensions/ui-ux.analyzer.js +665 -0
- package/dist/services/scoring/dimensions/ui-ux.analyzer.js.map +1 -0
- package/dist/services/scoring/index.d.ts +10 -0
- package/dist/services/scoring/index.d.ts.map +1 -0
- package/dist/services/scoring/index.js +10 -0
- package/dist/services/scoring/index.js.map +1 -0
- package/dist/services/scoring/scoring-service.d.ts +222 -0
- package/dist/services/scoring/scoring-service.d.ts.map +1 -0
- package/dist/services/scoring/scoring-service.js +636 -0
- package/dist/services/scoring/scoring-service.js.map +1 -0
- package/package.json +11 -3
- package/templates/README.md +183 -0
- package/templates/nestjs/controller.spec.ts +203 -0
- package/templates/nestjs/e2e/api.e2e-spec.ts +451 -0
- package/templates/nestjs/e2e/auth.e2e-spec.ts +533 -0
- package/templates/nestjs/fixtures/test-module.ts +311 -0
- package/templates/nestjs/guard.spec.ts +314 -0
- package/templates/nestjs/interceptor.spec.ts +458 -0
- package/templates/nestjs/module.spec.ts +173 -0
- package/templates/nestjs/pipe.spec.ts +474 -0
- package/templates/nestjs/service.spec.ts +296 -0
- package/templates/rust/Cargo.toml +72 -0
- package/templates/rust/actix-controller.test.rs +114 -0
- package/templates/rust/axum-handler.test.rs +117 -0
- package/templates/rust/integration.test.rs +63 -0
- package/templates/rust/rocket-route.test.rs +106 -0
- package/templates/rust/unit.test.rs +38 -0
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Optimization Service Barrel Export
|
|
3
|
+
*
|
|
4
|
+
* Central export point for all optimization-related services and types.
|
|
5
|
+
*/
|
|
6
|
+
import { OptimizationService } from './optimization.service.js';
|
|
7
|
+
// Main service
|
|
8
|
+
export { OptimizationService } from './optimization.service.js';
|
|
9
|
+
// Detectors
|
|
10
|
+
export { BugDetector } from './detectors/bug-detector.js';
|
|
11
|
+
export { PerfDetector } from './detectors/perf-detector.js';
|
|
12
|
+
export { CodeSmellDetector } from './detectors/code-smell-detector.js';
|
|
13
|
+
// Optimizers
|
|
14
|
+
export { CodeOptimizer } from './optimizers/code-optimizer.js';
|
|
15
|
+
export { PerfOptimizer } from './optimizers/perf-optimizer.js';
|
|
16
|
+
export { RefactOptimizer } from './optimizers/refact-optimizer.js';
|
|
17
|
+
// Patterns
|
|
18
|
+
export { ANTI_PATTERNS, getAntiPatternsByCategory, getAntiPatternById, getAntiPatternsBySeverity, findMatchingAntiPatterns, } from './patterns/anti-patterns.js';
|
|
19
|
+
/**
|
|
20
|
+
* Default optimization service instance
|
|
21
|
+
*/
|
|
22
|
+
export const optimizationService = new OptimizationService();
|
|
23
|
+
/**
|
|
24
|
+
* Convenience function to detect issues in a project
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```ts
|
|
28
|
+
* import { detectOptimizations } from '@pamacea/daemon';
|
|
29
|
+
*
|
|
30
|
+
* const report = await detectOptimizations('/path/to/project');
|
|
31
|
+
* console.log(`Found ${report.bugs.length} bugs`);
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export async function detectOptimizations(projectPath, options) {
|
|
35
|
+
return optimizationService.detect(projectPath, options);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Convenience function to detect and optimize in one operation
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```ts
|
|
42
|
+
* import { detectAndOptimize } from '@pamacea/daemon';
|
|
43
|
+
*
|
|
44
|
+
* const result = await detectAndOptimize('/path/to/project', {
|
|
45
|
+
* autoFix: true,
|
|
46
|
+
* maxFixes: 10,
|
|
47
|
+
* });
|
|
48
|
+
* console.log(`Applied ${result.appliedOptimizations.length} optimizations`);
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
export async function detectAndOptimize(projectPath, options) {
|
|
52
|
+
return optimizationService.detectAndOptimize(projectPath, options);
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Convenience function to generate a summary report
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* ```ts
|
|
59
|
+
* import { generateReport } from '@pamacea/daemon';
|
|
60
|
+
*
|
|
61
|
+
* const report = await detectOptimizations('/path/to/project');
|
|
62
|
+
* const summary = generateReport(report);
|
|
63
|
+
* console.log(summary);
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
export function generateReport(report) {
|
|
67
|
+
return optimizationService.generateSummary(report);
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/services/optimization/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAOhE,eAAe;AACf,OAAO,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAEhE,YAAY;AACZ,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC1D,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAC5D,OAAO,EAAE,iBAAiB,EAAE,MAAM,oCAAoC,CAAC;AAEvE,aAAa;AACb,OAAO,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAC;AAC/D,OAAO,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAC;AAC/D,OAAO,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AAEnE,WAAW;AACX,OAAO,EACL,aAAa,EACb,yBAAyB,EACzB,kBAAkB,EAClB,yBAAyB,EACzB,wBAAwB,GACzB,MAAM,6BAA6B,CAAC;AA2CrC;;GAEG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,IAAI,mBAAmB,EAAE,CAAC;AAE7D;;;;;;;;;;GAUG;AACH,MAAM,CAAC,KAAK,UAAU,mBAAmB,CACvC,WAAmB,EACnB,OAA0B;IAE1B,OAAO,mBAAmB,CAAC,MAAM,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;AAC1D,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,WAAmB,EACnB,OAAkC;IAElC,OAAO,mBAAmB,CAAC,iBAAiB,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;AACrE,CAAC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,cAAc,CAAC,MAA0B;IACvD,OAAO,mBAAmB,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC;AACrD,CAAC"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Optimization Service
|
|
3
|
+
*
|
|
4
|
+
* Main orchestration service for bug detection, performance analysis,
|
|
5
|
+
* and code optimization. Coordinates all detectors and optimizers.
|
|
6
|
+
*/
|
|
7
|
+
import type { AppliedOptimization, DetectAndOptimizeOptions, DetectionOptions, OptimizationReport, OptimizationResult } from './optimization.types.js';
|
|
8
|
+
/**
|
|
9
|
+
* Optimization Service - Main orchestration
|
|
10
|
+
*/
|
|
11
|
+
export declare class OptimizationService {
|
|
12
|
+
private readonly logger;
|
|
13
|
+
private readonly bugDetector;
|
|
14
|
+
private readonly perfDetector;
|
|
15
|
+
private readonly codeSmellDetector;
|
|
16
|
+
private readonly codeOptimizer;
|
|
17
|
+
private readonly perfOptimizer;
|
|
18
|
+
private readonly refactOptimizer;
|
|
19
|
+
constructor();
|
|
20
|
+
/**
|
|
21
|
+
* Detect all issues in a project
|
|
22
|
+
*/
|
|
23
|
+
detect(projectPath: string, options?: DetectionOptions): Promise<OptimizationReport>;
|
|
24
|
+
/**
|
|
25
|
+
* Apply optimizations to a project
|
|
26
|
+
*/
|
|
27
|
+
optimize(projectPath: string, optimizations: AppliedOptimization[], options?: DetectAndOptimizeOptions): Promise<OptimizationResult>;
|
|
28
|
+
/**
|
|
29
|
+
* Detect and optimize in one operation
|
|
30
|
+
*/
|
|
31
|
+
detectAndOptimize(projectPath: string, options?: DetectAndOptimizeOptions): Promise<OptimizationResult>;
|
|
32
|
+
/**
|
|
33
|
+
* Generate a human-readable summary report
|
|
34
|
+
*/
|
|
35
|
+
generateSummary(report: OptimizationReport): string;
|
|
36
|
+
/**
|
|
37
|
+
* Calculate potential impact score (0-100)
|
|
38
|
+
*/
|
|
39
|
+
private calculatePotentialImpact;
|
|
40
|
+
/**
|
|
41
|
+
* Estimate time to fix all issues
|
|
42
|
+
*/
|
|
43
|
+
private estimateFixTime;
|
|
44
|
+
/**
|
|
45
|
+
* Calculate estimated improvement from applied optimizations
|
|
46
|
+
*/
|
|
47
|
+
private calculateEstimatedImprovement;
|
|
48
|
+
/**
|
|
49
|
+
* Detect project framework
|
|
50
|
+
*/
|
|
51
|
+
private detectFramework;
|
|
52
|
+
/**
|
|
53
|
+
* Collect file statistics
|
|
54
|
+
*/
|
|
55
|
+
private collectFileStats;
|
|
56
|
+
/**
|
|
57
|
+
* Check if working directory has uncommitted changes
|
|
58
|
+
*/
|
|
59
|
+
private hasUncommittedChanges;
|
|
60
|
+
/**
|
|
61
|
+
* Check if severity matches minimum requirement
|
|
62
|
+
*/
|
|
63
|
+
private isSeverityMatch;
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=optimization.service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"optimization.service.d.ts","sourceRoot":"","sources":["../../../src/services/optimization/optimization.service.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH,OAAO,KAAK,EACV,mBAAmB,EACnB,wBAAwB,EACxB,gBAAgB,EAChB,kBAAkB,EAClB,kBAAkB,EAEnB,MAAM,yBAAyB,CAAC;AASjC;;GAEG;AACH,qBAAa,mBAAmB;IAC9B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAc;IAC1C,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAe;IAC5C,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAoB;IACtD,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAgB;IAC9C,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAgB;IAC9C,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAkB;;IAYlD;;OAEG;IACG,MAAM,CACV,WAAW,EAAE,MAAM,EACnB,OAAO,GAAE,gBAAqB,GAC7B,OAAO,CAAC,kBAAkB,CAAC;IA2D9B;;OAEG;IACG,QAAQ,CACZ,WAAW,EAAE,MAAM,EACnB,aAAa,EAAE,mBAAmB,EAAE,EACpC,OAAO,GAAE,wBAA6B,GACrC,OAAO,CAAC,kBAAkB,CAAC;IAmF9B;;OAEG;IACG,iBAAiB,CACrB,WAAW,EAAE,MAAM,EACnB,OAAO,GAAE,wBAA6B,GACrC,OAAO,CAAC,kBAAkB,CAAC;IAoG9B;;OAEG;IACH,eAAe,CAAC,MAAM,EAAE,kBAAkB,GAAG,MAAM;IAuGnD;;OAEG;IACH,OAAO,CAAC,wBAAwB;IAsBhC;;OAEG;IACH,OAAO,CAAC,eAAe;IAsBvB;;OAEG;IACH,OAAO,CAAC,6BAA6B;IAwBrC;;OAEG;YACW,eAAe;IAgC7B;;OAEG;YACW,gBAAgB;IAiD9B;;OAEG;YACW,qBAAqB;IAiBnC;;OAEG;IACH,OAAO,CAAC,eAAe;CAOxB"}
|
|
@@ -0,0 +1,511 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Optimization Service
|
|
3
|
+
*
|
|
4
|
+
* Main orchestration service for bug detection, performance analysis,
|
|
5
|
+
* and code optimization. Coordinates all detectors and optimizers.
|
|
6
|
+
*/
|
|
7
|
+
import * as fs from 'node:fs/promises';
|
|
8
|
+
import * as path from 'node:path';
|
|
9
|
+
import { BugDetector } from './detectors/bug-detector.js';
|
|
10
|
+
import { CodeSmellDetector } from './detectors/code-smell-detector.js';
|
|
11
|
+
import { PerfDetector } from './detectors/perf-detector.js';
|
|
12
|
+
import { CodeOptimizer } from './optimizers/code-optimizer.js';
|
|
13
|
+
import { PerfOptimizer } from './optimizers/perf-optimizer.js';
|
|
14
|
+
import { RefactOptimizer } from './optimizers/refact-optimizer.js';
|
|
15
|
+
import { createLogger } from '../../shared/utils/logger.js';
|
|
16
|
+
/**
|
|
17
|
+
* Optimization Service - Main orchestration
|
|
18
|
+
*/
|
|
19
|
+
export class OptimizationService {
|
|
20
|
+
logger;
|
|
21
|
+
bugDetector;
|
|
22
|
+
perfDetector;
|
|
23
|
+
codeSmellDetector;
|
|
24
|
+
codeOptimizer;
|
|
25
|
+
perfOptimizer;
|
|
26
|
+
refactOptimizer;
|
|
27
|
+
constructor() {
|
|
28
|
+
this.logger = createLogger('OptimizationService');
|
|
29
|
+
this.bugDetector = new BugDetector();
|
|
30
|
+
this.perfDetector = new PerfDetector();
|
|
31
|
+
this.codeSmellDetector = new CodeSmellDetector();
|
|
32
|
+
this.codeOptimizer = new CodeOptimizer();
|
|
33
|
+
this.perfOptimizer = new PerfOptimizer();
|
|
34
|
+
this.refactOptimizer = new RefactOptimizer();
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Detect all issues in a project
|
|
38
|
+
*/
|
|
39
|
+
async detect(projectPath, options = {}) {
|
|
40
|
+
const startTime = performance.now();
|
|
41
|
+
this.logger.info(`Starting optimization detection for: ${projectPath}`);
|
|
42
|
+
// Verify project exists
|
|
43
|
+
try {
|
|
44
|
+
await fs.access(projectPath);
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
throw new Error(`Project path does not exist: ${projectPath}`);
|
|
48
|
+
}
|
|
49
|
+
// Run all detectors in parallel
|
|
50
|
+
const [bugs, performanceIssues, codeSmells] = await Promise.all([
|
|
51
|
+
this.bugDetector.detectInDirectory(projectPath, options).catch(err => {
|
|
52
|
+
this.logger.error('Bug detection failed:', err);
|
|
53
|
+
return [];
|
|
54
|
+
}),
|
|
55
|
+
this.perfDetector.detectInDirectory(projectPath, options).catch(err => {
|
|
56
|
+
this.logger.error('Performance detection failed:', err);
|
|
57
|
+
return [];
|
|
58
|
+
}),
|
|
59
|
+
this.codeSmellDetector.detectInDirectory(projectPath, options).catch(err => {
|
|
60
|
+
this.logger.error('Code smell detection failed:', err);
|
|
61
|
+
return [];
|
|
62
|
+
}),
|
|
63
|
+
]);
|
|
64
|
+
// Collect file statistics
|
|
65
|
+
const stats = await this.collectFileStats(projectPath);
|
|
66
|
+
const duration = Math.round(performance.now() - startTime);
|
|
67
|
+
this.logger.info(`Detection complete in ${duration}ms: ${bugs.length} bugs, ` +
|
|
68
|
+
`${performanceIssues.length} performance issues, ${codeSmells.length} code smells`);
|
|
69
|
+
// Calculate total potential impact
|
|
70
|
+
const totalPotentialImpact = this.calculatePotentialImpact(bugs, performanceIssues, codeSmells);
|
|
71
|
+
return {
|
|
72
|
+
projectPath,
|
|
73
|
+
timestamp: new Date(),
|
|
74
|
+
bugs: this.bugDetector.prioritizeBugs(bugs),
|
|
75
|
+
performanceIssues: this.perfDetector.prioritizeIssues(performanceIssues),
|
|
76
|
+
codeSmells: this.codeSmellDetector.prioritizeSmells(codeSmells),
|
|
77
|
+
totalPotentialImpact,
|
|
78
|
+
estimatedFixTime: this.estimateFixTime(bugs.length, performanceIssues.length, codeSmells.length),
|
|
79
|
+
framework: await this.detectFramework(projectPath),
|
|
80
|
+
filesAnalyzed: stats.fileCount,
|
|
81
|
+
linesOfCode: stats.linesOfCode,
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Apply optimizations to a project
|
|
86
|
+
*/
|
|
87
|
+
async optimize(projectPath, optimizations, options = {}) {
|
|
88
|
+
const startTime = performance.now();
|
|
89
|
+
this.logger.info(`Starting optimization for: ${projectPath}`);
|
|
90
|
+
// Check if dry run
|
|
91
|
+
if (options.dryRun) {
|
|
92
|
+
this.logger.info('Dry run mode - no files will be modified');
|
|
93
|
+
}
|
|
94
|
+
// Check git status if not skipping
|
|
95
|
+
if (!options.skipGitCheck && !options.dryRun) {
|
|
96
|
+
const hasUncommittedChanges = await this.hasUncommittedChanges(projectPath);
|
|
97
|
+
if (hasUncommittedChanges) {
|
|
98
|
+
throw new Error('Working directory has uncommitted changes. Please commit or stash changes before running optimizations, or use --skip-git-check');
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
const appliedOptimizations = [];
|
|
102
|
+
const errors = [];
|
|
103
|
+
// Group optimizations by file
|
|
104
|
+
const optimizationsByFile = new Map();
|
|
105
|
+
for (const opt of optimizations) {
|
|
106
|
+
for (const file of opt.modifiedFiles) {
|
|
107
|
+
const fullPath = path.resolve(projectPath, file);
|
|
108
|
+
if (!optimizationsByFile.has(fullPath)) {
|
|
109
|
+
optimizationsByFile.set(fullPath, []);
|
|
110
|
+
}
|
|
111
|
+
optimizationsByFile.get(fullPath).push(opt);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
// Apply optimizations per file
|
|
115
|
+
for (const [filePath, fileOpts] of optimizationsByFile.entries()) {
|
|
116
|
+
try {
|
|
117
|
+
if (options.dryRun) {
|
|
118
|
+
appliedOptimizations.push(...fileOpts);
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
// Read file content
|
|
122
|
+
const content = await fs.readFile(filePath, 'utf-8');
|
|
123
|
+
// Apply appropriate optimizer based on optimization type
|
|
124
|
+
for (const opt of fileOpts) {
|
|
125
|
+
switch (opt.type) {
|
|
126
|
+
case 'bug-fix':
|
|
127
|
+
case 'refactoring':
|
|
128
|
+
// Code optimizer handles basic refactoring
|
|
129
|
+
break;
|
|
130
|
+
case 'performance':
|
|
131
|
+
// Performance optimizer
|
|
132
|
+
break;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
appliedOptimizations.push(...fileOpts);
|
|
136
|
+
}
|
|
137
|
+
catch (error) {
|
|
138
|
+
errors.push({
|
|
139
|
+
target: filePath,
|
|
140
|
+
message: error instanceof Error ? error.message : String(error),
|
|
141
|
+
fatal: false,
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
const duration = Math.round(performance.now() - startTime);
|
|
146
|
+
// Generate updated report
|
|
147
|
+
const report = await this.detect(projectPath, options);
|
|
148
|
+
return {
|
|
149
|
+
report,
|
|
150
|
+
appliedOptimizations,
|
|
151
|
+
remainingSuggestions: [],
|
|
152
|
+
estimatedImprovement: this.calculateEstimatedImprovement(appliedOptimizations),
|
|
153
|
+
errors,
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Detect and optimize in one operation
|
|
158
|
+
*/
|
|
159
|
+
async detectAndOptimize(projectPath, options = {}) {
|
|
160
|
+
this.logger.info(`Starting detect-and-optimize for: ${projectPath}`);
|
|
161
|
+
// First, detect all issues
|
|
162
|
+
const report = await this.detect(projectPath, options);
|
|
163
|
+
if (options.reportOnly) {
|
|
164
|
+
return {
|
|
165
|
+
report,
|
|
166
|
+
appliedOptimizations: [],
|
|
167
|
+
remainingSuggestions: [],
|
|
168
|
+
estimatedImprovement: 'Report only - no optimizations applied',
|
|
169
|
+
errors: [],
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
if (options.detectOnly) {
|
|
173
|
+
return {
|
|
174
|
+
report,
|
|
175
|
+
appliedOptimizations: [],
|
|
176
|
+
remainingSuggestions: [],
|
|
177
|
+
estimatedImprovement: 'Detect only - no optimizations applied',
|
|
178
|
+
errors: [],
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
// Determine which optimizations to apply
|
|
182
|
+
const optimizationsToApply = [];
|
|
183
|
+
// Auto-fixable bugs
|
|
184
|
+
const fixableBugs = report.bugs.filter(b => b.fixable);
|
|
185
|
+
for (const bug of fixableBugs.slice(0, options.maxFixes || 10)) {
|
|
186
|
+
if (options.minSeverity && !this.isSeverityMatch(bug.severity, options.minSeverity)) {
|
|
187
|
+
continue;
|
|
188
|
+
}
|
|
189
|
+
optimizationsToApply.push({
|
|
190
|
+
id: bug.id,
|
|
191
|
+
type: 'bug-fix',
|
|
192
|
+
description: bug.description,
|
|
193
|
+
modifiedFiles: [bug.location.filePath],
|
|
194
|
+
originalCode: bug.codeSnippet || '',
|
|
195
|
+
fixedCode: bug.suggestedFix,
|
|
196
|
+
location: bug.location,
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
// Generate suggestions for non-auto-fixable issues
|
|
200
|
+
const remainingSuggestions = [];
|
|
201
|
+
for (const bug of report.bugs.filter(b => !b.fixable)) {
|
|
202
|
+
remainingSuggestions.push({
|
|
203
|
+
id: bug.id,
|
|
204
|
+
type: 'bug-fix',
|
|
205
|
+
description: bug.description,
|
|
206
|
+
reason: 'Requires manual review and intervention',
|
|
207
|
+
manualFix: bug.suggestedFix,
|
|
208
|
+
location: bug.location,
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
for (const perfIssue of report.performanceIssues) {
|
|
212
|
+
remainingSuggestions.push({
|
|
213
|
+
id: perfIssue.id,
|
|
214
|
+
type: 'performance',
|
|
215
|
+
description: perfIssue.description,
|
|
216
|
+
reason: 'Performance optimization requires manual implementation',
|
|
217
|
+
manualFix: perfIssue.expectedImprovement,
|
|
218
|
+
location: perfIssue.location,
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
for (const smell of report.codeSmells) {
|
|
222
|
+
remainingSuggestions.push({
|
|
223
|
+
id: smell.id,
|
|
224
|
+
type: 'refactoring',
|
|
225
|
+
description: smell.description,
|
|
226
|
+
reason: 'Refactoring requires manual implementation',
|
|
227
|
+
manualFix: smell.suggestion,
|
|
228
|
+
location: smell.location,
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
// Apply optimizations if autoFix is enabled
|
|
232
|
+
let appliedOptimizations = [];
|
|
233
|
+
if (options.autoFix && optimizationsToApply.length > 0) {
|
|
234
|
+
const result = await this.optimize(projectPath, optimizationsToApply, options);
|
|
235
|
+
appliedOptimizations = result.appliedOptimizations;
|
|
236
|
+
}
|
|
237
|
+
return {
|
|
238
|
+
report,
|
|
239
|
+
appliedOptimizations,
|
|
240
|
+
remainingSuggestions,
|
|
241
|
+
estimatedImprovement: this.calculateEstimatedImprovement(appliedOptimizations),
|
|
242
|
+
errors: [],
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* Generate a human-readable summary report
|
|
247
|
+
*/
|
|
248
|
+
generateSummary(report) {
|
|
249
|
+
const lines = [];
|
|
250
|
+
lines.push('');
|
|
251
|
+
lines.push('═══════════════════════════════════════════════════════════');
|
|
252
|
+
lines.push(' OPTIMIZATION REPORT');
|
|
253
|
+
lines.push('═══════════════════════════════════════════════════════════');
|
|
254
|
+
lines.push('');
|
|
255
|
+
lines.push(`Project: ${report.projectPath}`);
|
|
256
|
+
lines.push(`Analyzed: ${report.timestamp.toLocaleString()}`);
|
|
257
|
+
lines.push(`Files: ${report.filesAnalyzed} (${report.linesOfCode.toLocaleString()} LOC)`);
|
|
258
|
+
lines.push(`Framework: ${report.framework || 'Unknown'}`);
|
|
259
|
+
lines.push('');
|
|
260
|
+
// Summary
|
|
261
|
+
lines.push('───────────────────────────────────────────────────────────');
|
|
262
|
+
lines.push('SUMMARY');
|
|
263
|
+
lines.push('───────────────────────────────────────────────────────────');
|
|
264
|
+
lines.push(`Potential Impact Score: ${report.totalPotentialImpact}/100`);
|
|
265
|
+
lines.push(`Estimated Fix Time: ${report.estimatedFixTime || 'Unknown'}`);
|
|
266
|
+
lines.push('');
|
|
267
|
+
// Bugs
|
|
268
|
+
lines.push('───────────────────────────────────────────────────────────');
|
|
269
|
+
lines.push('BUGS');
|
|
270
|
+
lines.push('───────────────────────────────────────────────────────────');
|
|
271
|
+
const bugSummary = this.bugDetector.generateSummary(report.bugs);
|
|
272
|
+
lines.push(`Total: ${bugSummary.total}`);
|
|
273
|
+
lines.push(` Critical: ${bugSummary.bySeverity.critical}`);
|
|
274
|
+
lines.push(` High: ${bugSummary.bySeverity.high}`);
|
|
275
|
+
lines.push(` Medium: ${bugSummary.bySeverity.medium}`);
|
|
276
|
+
lines.push(` Low: ${bugSummary.bySeverity.low}`);
|
|
277
|
+
lines.push(`Fixable: ${bugSummary.fixable}`);
|
|
278
|
+
lines.push('');
|
|
279
|
+
// Top bugs
|
|
280
|
+
const topBugs = report.bugs.slice(0, 5);
|
|
281
|
+
if (topBugs.length > 0) {
|
|
282
|
+
lines.push('Top Priority Bugs:');
|
|
283
|
+
for (const bug of topBugs) {
|
|
284
|
+
lines.push(` [${bug.severity.toUpperCase()}] ${bug.description}`);
|
|
285
|
+
lines.push(` → ${bug.location.filePath}:${bug.location.line}`);
|
|
286
|
+
}
|
|
287
|
+
lines.push('');
|
|
288
|
+
}
|
|
289
|
+
// Performance Issues
|
|
290
|
+
lines.push('───────────────────────────────────────────────────────────');
|
|
291
|
+
lines.push('PERFORMANCE ISSUES');
|
|
292
|
+
lines.push('───────────────────────────────────────────────────────────');
|
|
293
|
+
const perfSummary = this.perfDetector.generateSummary(report.performanceIssues);
|
|
294
|
+
lines.push(`Total: ${perfSummary.total}`);
|
|
295
|
+
lines.push(` High Impact: ${perfSummary.byImpact.high}`);
|
|
296
|
+
lines.push(` Medium Impact: ${perfSummary.byImpact.medium}`);
|
|
297
|
+
lines.push(` Low Impact: ${perfSummary.byImpact.low}`);
|
|
298
|
+
lines.push(`Estimated Gain: ${perfSummary.totalEstimatedGain}%`);
|
|
299
|
+
lines.push('');
|
|
300
|
+
// Top performance issues
|
|
301
|
+
const topPerf = report.performanceIssues.slice(0, 5);
|
|
302
|
+
if (topPerf.length > 0) {
|
|
303
|
+
lines.push('Top Impact Issues:');
|
|
304
|
+
for (const issue of topPerf) {
|
|
305
|
+
lines.push(` [${issue.impact.toUpperCase()}] ${issue.description}`);
|
|
306
|
+
lines.push(` → ${issue.location.filePath}:${issue.location.line}`);
|
|
307
|
+
lines.push(` Expected: ${issue.expectedImprovement}`);
|
|
308
|
+
}
|
|
309
|
+
lines.push('');
|
|
310
|
+
}
|
|
311
|
+
// Code Smells
|
|
312
|
+
lines.push('───────────────────────────────────────────────────────────');
|
|
313
|
+
lines.push('CODE SMELLS');
|
|
314
|
+
lines.push('───────────────────────────────────────────────────────────');
|
|
315
|
+
const smellSummary = this.codeSmellDetector.generateSummary(report.codeSmells);
|
|
316
|
+
lines.push(`Total: ${smellSummary.total}`);
|
|
317
|
+
lines.push(` High: ${smellSummary.bySeverity.high}`);
|
|
318
|
+
lines.push(` Medium: ${smellSummary.bySeverity.medium}`);
|
|
319
|
+
lines.push(` Low: ${smellSummary.bySeverity.low}`);
|
|
320
|
+
lines.push(`Avg Complexity: ${smellSummary.avgComplexity}`);
|
|
321
|
+
lines.push('');
|
|
322
|
+
// Recommendations
|
|
323
|
+
lines.push('───────────────────────────────────────────────────────────');
|
|
324
|
+
lines.push('RECOMMENDATIONS');
|
|
325
|
+
lines.push('───────────────────────────────────────────────────────────');
|
|
326
|
+
if (bugSummary.fixable > 0) {
|
|
327
|
+
lines.push(`• Apply ${bugSummary.fixable} auto-fixable bugs immediately`);
|
|
328
|
+
}
|
|
329
|
+
if (perfSummary.totalEstimatedGain > 30) {
|
|
330
|
+
lines.push(`• Address performance issues for ${perfSummary.totalEstimatedGain}% potential improvement`);
|
|
331
|
+
}
|
|
332
|
+
if (bugSummary.bySeverity.critical > 0) {
|
|
333
|
+
lines.push(`• CRITICAL: Fix ${bugSummary.bySeverity.critical} critical bugs before deployment`);
|
|
334
|
+
}
|
|
335
|
+
lines.push('');
|
|
336
|
+
lines.push('═══════════════════════════════════════════════════════════');
|
|
337
|
+
lines.push('');
|
|
338
|
+
return lines.join('\n');
|
|
339
|
+
}
|
|
340
|
+
/**
|
|
341
|
+
* Calculate potential impact score (0-100)
|
|
342
|
+
*/
|
|
343
|
+
calculatePotentialImpact(bugs, perfIssues, codeSmells) {
|
|
344
|
+
const bugWeight = 2;
|
|
345
|
+
const perfWeight = 1;
|
|
346
|
+
const smellWeight = 0.5;
|
|
347
|
+
const bugScore = Math.min(bugs.length * bugWeight, 40);
|
|
348
|
+
const perfScore = Math.min(perfIssues.reduce((sum, p) => sum + (p.estimatedGain || 0), 0) / 10, 40);
|
|
349
|
+
const smellScore = Math.min(codeSmells.reduce((sum, s) => sum + (s.complexityScore || 0), 0) / 20, 20);
|
|
350
|
+
return Math.round(Math.min(bugScore + perfScore + smellScore, 100));
|
|
351
|
+
}
|
|
352
|
+
/**
|
|
353
|
+
* Estimate time to fix all issues
|
|
354
|
+
*/
|
|
355
|
+
estimateFixTime(bugCount, perfCount, smellCount) {
|
|
356
|
+
const bugTime = bugCount * 15; // 15 minutes per bug
|
|
357
|
+
const perfTime = perfCount * 30; // 30 minutes per perf issue
|
|
358
|
+
const smellTime = smellCount * 20; // 20 minutes per code smell
|
|
359
|
+
const totalMinutes = bugTime + perfTime + smellTime;
|
|
360
|
+
if (totalMinutes < 60) {
|
|
361
|
+
return `${totalMinutes} minutes`;
|
|
362
|
+
}
|
|
363
|
+
const hours = Math.floor(totalMinutes / 60);
|
|
364
|
+
const minutes = totalMinutes % 60;
|
|
365
|
+
if (hours < 8) {
|
|
366
|
+
return minutes > 0 ? `${hours}h ${minutes}m` : `${hours} hours`;
|
|
367
|
+
}
|
|
368
|
+
const days = Math.ceil(hours / 8);
|
|
369
|
+
return `${days} days`;
|
|
370
|
+
}
|
|
371
|
+
/**
|
|
372
|
+
* Calculate estimated improvement from applied optimizations
|
|
373
|
+
*/
|
|
374
|
+
calculateEstimatedImprovement(optimizations) {
|
|
375
|
+
if (optimizations.length === 0) {
|
|
376
|
+
return 'No optimizations applied';
|
|
377
|
+
}
|
|
378
|
+
const perfOpts = optimizations.filter(o => o.type === 'performance').length;
|
|
379
|
+
const bugOpts = optimizations.filter(o => o.type === 'bug-fix').length;
|
|
380
|
+
const refactorOpts = optimizations.filter(o => o.type === 'refactoring').length;
|
|
381
|
+
const improvements = [];
|
|
382
|
+
if (perfOpts > 0) {
|
|
383
|
+
improvements.push(`~${perfOpts * 5}% performance improvement`);
|
|
384
|
+
}
|
|
385
|
+
if (bugOpts > 0) {
|
|
386
|
+
improvements.push(`${bugOpts} bugs fixed`);
|
|
387
|
+
}
|
|
388
|
+
if (refactorOpts > 0) {
|
|
389
|
+
improvements.push(`${refactorOpts} refactorings applied`);
|
|
390
|
+
}
|
|
391
|
+
return improvements.join(', ') || 'Minor improvements';
|
|
392
|
+
}
|
|
393
|
+
/**
|
|
394
|
+
* Detect project framework
|
|
395
|
+
*/
|
|
396
|
+
async detectFramework(projectPath) {
|
|
397
|
+
try {
|
|
398
|
+
const pkgPath = path.join(projectPath, 'package.json');
|
|
399
|
+
const pkgContent = await fs.readFile(pkgPath, 'utf-8');
|
|
400
|
+
const pkg = JSON.parse(pkgContent);
|
|
401
|
+
const deps = { ...pkg.dependencies, ...pkg.devDependencies };
|
|
402
|
+
if (deps.next)
|
|
403
|
+
return 'Next.js';
|
|
404
|
+
if (deps.react && deps.vite)
|
|
405
|
+
return 'Vite + React';
|
|
406
|
+
if (deps.vue && deps.vite)
|
|
407
|
+
return 'Vite + Vue';
|
|
408
|
+
if (deps.svelte && deps.vite)
|
|
409
|
+
return 'Vite + Svelte';
|
|
410
|
+
if (deps.remix)
|
|
411
|
+
return 'Remix';
|
|
412
|
+
if (deps['@sveltejs/kit'])
|
|
413
|
+
return 'SvelteKit';
|
|
414
|
+
if (deps.nuxt)
|
|
415
|
+
return 'Nuxt';
|
|
416
|
+
if (deps.astro)
|
|
417
|
+
return 'Astro';
|
|
418
|
+
if (deps.gatsby)
|
|
419
|
+
return 'Gatsby';
|
|
420
|
+
if (deps.angular)
|
|
421
|
+
return 'Angular';
|
|
422
|
+
if (deps.react)
|
|
423
|
+
return 'React';
|
|
424
|
+
if (deps.vue)
|
|
425
|
+
return 'Vue';
|
|
426
|
+
if (deps.svelte)
|
|
427
|
+
return 'Svelte';
|
|
428
|
+
if (deps.express)
|
|
429
|
+
return 'Express';
|
|
430
|
+
if (deps.nest)
|
|
431
|
+
return 'NestJS';
|
|
432
|
+
if (deps.fastify)
|
|
433
|
+
return 'Fastify';
|
|
434
|
+
if (deps.hono)
|
|
435
|
+
return 'Hono';
|
|
436
|
+
return undefined;
|
|
437
|
+
}
|
|
438
|
+
catch {
|
|
439
|
+
return undefined;
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
/**
|
|
443
|
+
* Collect file statistics
|
|
444
|
+
*/
|
|
445
|
+
async collectFileStats(projectPath) {
|
|
446
|
+
let fileCount = 0;
|
|
447
|
+
let linesOfCode = 0;
|
|
448
|
+
const extensions = ['.ts', '.tsx', '.js', '.jsx', '.vue', '.svelte'];
|
|
449
|
+
async function walk(currentPath) {
|
|
450
|
+
try {
|
|
451
|
+
const entries = await fs.readdir(currentPath, { withFileTypes: true });
|
|
452
|
+
for (const entry of entries) {
|
|
453
|
+
if (entry.name === 'node_modules' ||
|
|
454
|
+
entry.name === '.git' ||
|
|
455
|
+
entry.name === 'dist' ||
|
|
456
|
+
entry.name === 'build') {
|
|
457
|
+
continue;
|
|
458
|
+
}
|
|
459
|
+
const fullPath = path.join(currentPath, entry.name);
|
|
460
|
+
if (entry.isDirectory()) {
|
|
461
|
+
await walk(fullPath);
|
|
462
|
+
}
|
|
463
|
+
else if (entry.isFile()) {
|
|
464
|
+
const ext = path.extname(entry.name);
|
|
465
|
+
if (extensions.includes(ext)) {
|
|
466
|
+
fileCount++;
|
|
467
|
+
try {
|
|
468
|
+
const content = await fs.readFile(fullPath, 'utf-8');
|
|
469
|
+
linesOfCode += content.split('\n').length;
|
|
470
|
+
}
|
|
471
|
+
catch {
|
|
472
|
+
// Skip files that can't be read
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
catch {
|
|
479
|
+
// Skip directories we can't read
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
await walk(projectPath);
|
|
483
|
+
return { fileCount, linesOfCode };
|
|
484
|
+
}
|
|
485
|
+
/**
|
|
486
|
+
* Check if working directory has uncommitted changes
|
|
487
|
+
*/
|
|
488
|
+
async hasUncommittedChanges(projectPath) {
|
|
489
|
+
try {
|
|
490
|
+
const { exec } = await import('node:child_process');
|
|
491
|
+
const util = require('node:util');
|
|
492
|
+
const execAsync = util.promisify(exec);
|
|
493
|
+
const { stdout } = await execAsync('git status --porcelain', {
|
|
494
|
+
cwd: projectPath,
|
|
495
|
+
});
|
|
496
|
+
return stdout.trim().length > 0;
|
|
497
|
+
}
|
|
498
|
+
catch {
|
|
499
|
+
// Not a git repo or git not available
|
|
500
|
+
return false;
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
/**
|
|
504
|
+
* Check if severity matches minimum requirement
|
|
505
|
+
*/
|
|
506
|
+
isSeverityMatch(severity, minSeverity) {
|
|
507
|
+
const order = ['critical', 'high', 'medium', 'low'];
|
|
508
|
+
return order.indexOf(severity) <= order.indexOf(minSeverity);
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
//# sourceMappingURL=optimization.service.js.map
|