mcp-react-toolkit 1.0.1 → 1.2.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 +146 -42
- package/package.json +12 -4
- package/tools/accessibility-checker/build/index.js +9 -5
- package/tools/accessibility-checker/build/index.js.map +1 -1
- package/tools/accessibility-checker/build/rules.d.ts.map +1 -1
- package/tools/accessibility-checker/build/rules.js +325 -94
- package/tools/accessibility-checker/build/rules.js.map +1 -1
- package/tools/code-modernizer/build/tools/01-convert-to-typescript.d.ts.map +1 -1
- package/tools/code-modernizer/build/tools/01-convert-to-typescript.js +65 -50
- package/tools/code-modernizer/build/tools/01-convert-to-typescript.js.map +1 -1
- package/tools/code-modernizer/build/types.d.ts +1 -0
- package/tools/code-modernizer/build/types.d.ts.map +1 -1
- package/tools/code-modernizer/build/utils/ast-parser.d.ts.map +1 -1
- package/tools/code-modernizer/build/utils/ast-parser.js +30 -14
- package/tools/code-modernizer/build/utils/ast-parser.js.map +1 -1
- package/tools/code-modernizer/build/utils/type-generator.d.ts +1 -1
- package/tools/code-modernizer/build/utils/type-generator.d.ts.map +1 -1
- package/tools/code-modernizer/build/utils/type-generator.js +72 -23
- package/tools/code-modernizer/build/utils/type-generator.js.map +1 -1
- package/tools/component-factory/build/index.js +59 -7
- package/tools/component-factory/build/index.js.map +1 -1
- package/tools/component-fixer/README.md +44 -0
- package/tools/component-fixer/build/index.d.ts +3 -0
- package/tools/component-fixer/build/index.d.ts.map +1 -0
- package/tools/component-fixer/build/index.js +647 -0
- package/tools/component-fixer/build/index.js.map +1 -0
- package/tools/component-fixer/build/index.test.d.ts +2 -0
- package/tools/component-fixer/build/index.test.d.ts.map +1 -0
- package/tools/component-fixer/build/index.test.js.map +1 -0
- package/tools/component-fixer/package.json +20 -0
- package/tools/component-reviewer/README.md +54 -0
- package/tools/component-reviewer/build/index.d.ts +39 -0
- package/tools/component-reviewer/build/index.d.ts.map +1 -0
- package/tools/component-reviewer/build/index.js +946 -0
- package/tools/component-reviewer/build/index.js.map +1 -0
- package/tools/component-reviewer/build/index.test.d.ts +2 -0
- package/tools/component-reviewer/build/index.test.d.ts.map +1 -0
- package/tools/component-reviewer/build/index.test.js.map +1 -0
- package/tools/component-reviewer/package.json +20 -0
- package/tools/dep-auditor/build/index.d.ts +1 -0
- package/tools/dep-auditor/build/index.d.ts.map +1 -1
- package/tools/dep-auditor/build/index.js +71 -16
- package/tools/dep-auditor/build/index.js.map +1 -1
- package/tools/generate-tests/build/analyzer.d.ts +14 -0
- package/tools/generate-tests/build/analyzer.d.ts.map +1 -1
- package/tools/generate-tests/build/analyzer.js +96 -42
- package/tools/generate-tests/build/analyzer.js.map +1 -1
- package/tools/generate-tests/build/generators.d.ts.map +1 -1
- package/tools/generate-tests/build/generators.js +304 -79
- package/tools/generate-tests/build/generators.js.map +1 -1
- package/tools/generate-tests/build/index.js +29 -10
- package/tools/generate-tests/build/index.js.map +1 -1
- package/tools/json-viewer/build/index.js +29 -6
- package/tools/json-viewer/build/index.js.map +1 -1
- package/tools/legacy-analyzer/README.md +66 -0
- package/tools/legacy-analyzer/build/index.d.ts +3 -0
- package/tools/legacy-analyzer/build/index.d.ts.map +1 -0
- package/tools/legacy-analyzer/build/index.js +209 -0
- package/tools/legacy-analyzer/build/index.js.map +1 -0
- package/tools/legacy-analyzer/build/index.test.d.ts +2 -0
- package/tools/legacy-analyzer/build/index.test.d.ts.map +1 -0
- package/tools/legacy-analyzer/build/index.test.js.map +1 -0
- package/tools/legacy-analyzer/build/tools/01-detect-project-tech.d.ts +3 -0
- package/tools/legacy-analyzer/build/tools/01-detect-project-tech.d.ts.map +1 -0
- package/tools/legacy-analyzer/build/tools/01-detect-project-tech.js +115 -0
- package/tools/legacy-analyzer/build/tools/01-detect-project-tech.js.map +1 -0
- package/tools/legacy-analyzer/build/tools/02-analyze-folder-structure.d.ts +3 -0
- package/tools/legacy-analyzer/build/tools/02-analyze-folder-structure.d.ts.map +1 -0
- package/tools/legacy-analyzer/build/tools/02-analyze-folder-structure.js +85 -0
- package/tools/legacy-analyzer/build/tools/02-analyze-folder-structure.js.map +1 -0
- package/tools/legacy-analyzer/build/tools/03-analyze-components.d.ts +3 -0
- package/tools/legacy-analyzer/build/tools/03-analyze-components.d.ts.map +1 -0
- package/tools/legacy-analyzer/build/tools/03-analyze-components.js +87 -0
- package/tools/legacy-analyzer/build/tools/03-analyze-components.js.map +1 -0
- package/tools/legacy-analyzer/build/tools/04-analyze-state-management.d.ts +3 -0
- package/tools/legacy-analyzer/build/tools/04-analyze-state-management.d.ts.map +1 -0
- package/tools/legacy-analyzer/build/tools/04-analyze-state-management.js +133 -0
- package/tools/legacy-analyzer/build/tools/04-analyze-state-management.js.map +1 -0
- package/tools/legacy-analyzer/build/tools/05-analyze-api-layer.d.ts +3 -0
- package/tools/legacy-analyzer/build/tools/05-analyze-api-layer.d.ts.map +1 -0
- package/tools/legacy-analyzer/build/tools/05-analyze-api-layer.js +160 -0
- package/tools/legacy-analyzer/build/tools/05-analyze-api-layer.js.map +1 -0
- package/tools/legacy-analyzer/build/tools/06-analyze-routing.d.ts +3 -0
- package/tools/legacy-analyzer/build/tools/06-analyze-routing.d.ts.map +1 -0
- package/tools/legacy-analyzer/build/tools/06-analyze-routing.js +150 -0
- package/tools/legacy-analyzer/build/tools/06-analyze-routing.js.map +1 -0
- package/tools/legacy-analyzer/build/tools/07-analyze-styling.d.ts +3 -0
- package/tools/legacy-analyzer/build/tools/07-analyze-styling.d.ts.map +1 -0
- package/tools/legacy-analyzer/build/tools/07-analyze-styling.js +131 -0
- package/tools/legacy-analyzer/build/tools/07-analyze-styling.js.map +1 -0
- package/tools/legacy-analyzer/build/tools/08-analyze-assets.d.ts +3 -0
- package/tools/legacy-analyzer/build/tools/08-analyze-assets.d.ts.map +1 -0
- package/tools/legacy-analyzer/build/tools/08-analyze-assets.js +85 -0
- package/tools/legacy-analyzer/build/tools/08-analyze-assets.js.map +1 -0
- package/tools/legacy-analyzer/build/tools/09-detect-anti-patterns.d.ts +3 -0
- package/tools/legacy-analyzer/build/tools/09-detect-anti-patterns.d.ts.map +1 -0
- package/tools/legacy-analyzer/build/tools/09-detect-anti-patterns.js +329 -0
- package/tools/legacy-analyzer/build/tools/09-detect-anti-patterns.js.map +1 -0
- package/tools/legacy-analyzer/build/tools/10-detect-duplication.d.ts +3 -0
- package/tools/legacy-analyzer/build/tools/10-detect-duplication.d.ts.map +1 -0
- package/tools/legacy-analyzer/build/tools/10-detect-duplication.js +192 -0
- package/tools/legacy-analyzer/build/tools/10-detect-duplication.js.map +1 -0
- package/tools/legacy-analyzer/build/tools/11-analyze-dependencies-usage.d.ts +3 -0
- package/tools/legacy-analyzer/build/tools/11-analyze-dependencies-usage.d.ts.map +1 -0
- package/tools/legacy-analyzer/build/tools/11-analyze-dependencies-usage.js +232 -0
- package/tools/legacy-analyzer/build/tools/11-analyze-dependencies-usage.js.map +1 -0
- package/tools/legacy-analyzer/build/tools/12-analyze-legacy-app.d.ts +3 -0
- package/tools/legacy-analyzer/build/tools/12-analyze-legacy-app.d.ts.map +1 -0
- package/tools/legacy-analyzer/build/tools/12-analyze-legacy-app.js +247 -0
- package/tools/legacy-analyzer/build/tools/12-analyze-legacy-app.js.map +1 -0
- package/tools/legacy-analyzer/build/tools/13-detect-features.d.ts +3 -0
- package/tools/legacy-analyzer/build/tools/13-detect-features.d.ts.map +1 -0
- package/tools/legacy-analyzer/build/tools/13-detect-features.js +141 -0
- package/tools/legacy-analyzer/build/tools/13-detect-features.js.map +1 -0
- package/tools/legacy-analyzer/build/tools/14-classify-files.d.ts +3 -0
- package/tools/legacy-analyzer/build/tools/14-classify-files.d.ts.map +1 -0
- package/tools/legacy-analyzer/build/tools/14-classify-files.js +76 -0
- package/tools/legacy-analyzer/build/tools/14-classify-files.js.map +1 -0
- package/tools/legacy-analyzer/build/tools/15-detect-shared-modules.d.ts +3 -0
- package/tools/legacy-analyzer/build/tools/15-detect-shared-modules.d.ts.map +1 -0
- package/tools/legacy-analyzer/build/tools/15-detect-shared-modules.js +70 -0
- package/tools/legacy-analyzer/build/tools/15-detect-shared-modules.js.map +1 -0
- package/tools/legacy-analyzer/build/tools/16-design-target-structure.d.ts +3 -0
- package/tools/legacy-analyzer/build/tools/16-design-target-structure.d.ts.map +1 -0
- package/tools/legacy-analyzer/build/tools/16-design-target-structure.js +26 -0
- package/tools/legacy-analyzer/build/tools/16-design-target-structure.js.map +1 -0
- package/tools/legacy-analyzer/build/tools/17-map-files-to-target.d.ts +3 -0
- package/tools/legacy-analyzer/build/tools/17-map-files-to-target.d.ts.map +1 -0
- package/tools/legacy-analyzer/build/tools/17-map-files-to-target.js +108 -0
- package/tools/legacy-analyzer/build/tools/17-map-files-to-target.js.map +1 -0
- package/tools/legacy-analyzer/build/tools/18-detect-boundary-violations.d.ts +3 -0
- package/tools/legacy-analyzer/build/tools/18-detect-boundary-violations.d.ts.map +1 -0
- package/tools/legacy-analyzer/build/tools/18-detect-boundary-violations.js +137 -0
- package/tools/legacy-analyzer/build/tools/18-detect-boundary-violations.js.map +1 -0
- package/tools/legacy-analyzer/build/tools/19-suggest-module-splitting.d.ts +3 -0
- package/tools/legacy-analyzer/build/tools/19-suggest-module-splitting.d.ts.map +1 -0
- package/tools/legacy-analyzer/build/tools/19-suggest-module-splitting.js +160 -0
- package/tools/legacy-analyzer/build/tools/19-suggest-module-splitting.js.map +1 -0
- package/tools/legacy-analyzer/build/tools/20-naming-standardizer.d.ts +3 -0
- package/tools/legacy-analyzer/build/tools/20-naming-standardizer.d.ts.map +1 -0
- package/tools/legacy-analyzer/build/tools/20-naming-standardizer.js +162 -0
- package/tools/legacy-analyzer/build/tools/20-naming-standardizer.js.map +1 -0
- package/tools/legacy-analyzer/build/tools/21-generate-refactor-plan.d.ts +3 -0
- package/tools/legacy-analyzer/build/tools/21-generate-refactor-plan.d.ts.map +1 -0
- package/tools/legacy-analyzer/build/tools/21-generate-refactor-plan.js +108 -0
- package/tools/legacy-analyzer/build/tools/21-generate-refactor-plan.js.map +1 -0
- package/tools/legacy-analyzer/build/tools/22-refactor-folder-structure.d.ts +3 -0
- package/tools/legacy-analyzer/build/tools/22-refactor-folder-structure.d.ts.map +1 -0
- package/tools/legacy-analyzer/build/tools/22-refactor-folder-structure.js +98 -0
- package/tools/legacy-analyzer/build/tools/22-refactor-folder-structure.js.map +1 -0
- package/tools/legacy-analyzer/build/types.d.ts +413 -0
- package/tools/legacy-analyzer/build/types.d.ts.map +1 -0
- package/tools/legacy-analyzer/build/types.js +12 -0
- package/tools/legacy-analyzer/build/types.js.map +1 -0
- package/tools/legacy-analyzer/build/utils/ast-parser.d.ts +34 -0
- package/tools/legacy-analyzer/build/utils/ast-parser.d.ts.map +1 -0
- package/tools/legacy-analyzer/build/utils/ast-parser.js +394 -0
- package/tools/legacy-analyzer/build/utils/ast-parser.js.map +1 -0
- package/tools/legacy-analyzer/build/utils/file-scanner.d.ts +51 -0
- package/tools/legacy-analyzer/build/utils/file-scanner.d.ts.map +1 -0
- package/tools/legacy-analyzer/build/utils/file-scanner.js +174 -0
- package/tools/legacy-analyzer/build/utils/file-scanner.js.map +1 -0
- package/tools/legacy-analyzer/build/utils/import-tracker.d.ts +38 -0
- package/tools/legacy-analyzer/build/utils/import-tracker.d.ts.map +1 -0
- package/tools/legacy-analyzer/build/utils/import-tracker.js +194 -0
- package/tools/legacy-analyzer/build/utils/import-tracker.js.map +1 -0
- package/tools/legacy-analyzer/build/utils/refactor-helpers.d.ts +88 -0
- package/tools/legacy-analyzer/build/utils/refactor-helpers.d.ts.map +1 -0
- package/tools/legacy-analyzer/build/utils/refactor-helpers.js +538 -0
- package/tools/legacy-analyzer/build/utils/refactor-helpers.js.map +1 -0
- package/tools/legacy-analyzer/package.json +20 -0
- package/tools/lighthouse-runner/README.md +45 -0
- package/tools/lighthouse-runner/build/index.d.ts +6 -0
- package/tools/lighthouse-runner/build/index.d.ts.map +1 -0
- package/tools/lighthouse-runner/build/index.js +295 -0
- package/tools/lighthouse-runner/build/index.js.map +1 -0
- package/tools/lighthouse-runner/build/index.test.d.ts +2 -0
- package/tools/lighthouse-runner/build/index.test.d.ts.map +1 -0
- package/tools/lighthouse-runner/build/index.test.js.map +1 -0
- package/tools/lighthouse-runner/package.json +20 -0
- package/tools/monorepo-manager/build/utils.d.ts.map +1 -1
- package/tools/monorepo-manager/build/utils.js +12 -9
- package/tools/monorepo-manager/build/utils.js.map +1 -1
- package/tools/performance-audit/README.md +37 -0
- package/tools/performance-audit/build/index.d.ts +13 -0
- package/tools/performance-audit/build/index.d.ts.map +1 -0
- package/tools/performance-audit/build/index.js +311 -0
- package/tools/performance-audit/build/index.js.map +1 -0
- package/tools/performance-audit/build/index.test.d.ts +2 -0
- package/tools/performance-audit/build/index.test.d.ts.map +1 -0
- package/tools/performance-audit/build/index.test.js.map +1 -0
- package/tools/performance-audit/package.json +20 -0
- package/tools/quality-pipeline/build/index.js +55 -15
- package/tools/quality-pipeline/build/index.js.map +1 -1
- package/tools/render-analyzer/README.md +43 -0
- package/tools/render-analyzer/build/index.d.ts +25 -0
- package/tools/render-analyzer/build/index.d.ts.map +1 -0
- package/tools/render-analyzer/build/index.js +342 -0
- package/tools/render-analyzer/build/index.js.map +1 -0
- package/tools/render-analyzer/build/index.test.d.ts +2 -0
- package/tools/render-analyzer/build/index.test.d.ts.map +1 -0
- package/tools/render-analyzer/build/index.test.js.map +1 -0
- package/tools/render-analyzer/package.json +20 -0
- package/tools/shared/build/fs.d.ts +8 -0
- package/tools/shared/build/fs.d.ts.map +1 -0
- package/tools/shared/build/fs.js +45 -0
- package/tools/shared/build/fs.js.map +1 -0
- package/tools/shared/build/index.d.ts +1 -0
- package/tools/shared/build/index.d.ts.map +1 -1
- package/tools/shared/build/index.js +1 -0
- package/tools/shared/build/index.js.map +1 -1
- package/tools/storybook-generator/README.md +39 -0
- package/tools/storybook-generator/build/index.d.ts +13 -0
- package/tools/storybook-generator/build/index.d.ts.map +1 -0
- package/tools/storybook-generator/build/index.js +478 -0
- package/tools/storybook-generator/build/index.js.map +1 -0
- package/tools/storybook-generator/build/index.test.d.ts +2 -0
- package/tools/storybook-generator/build/index.test.d.ts.map +1 -0
- package/tools/storybook-generator/build/index.test.js.map +1 -0
- package/tools/storybook-generator/package.json +20 -0
- package/tools/test-gap-analyzer/README.md +41 -0
- package/tools/test-gap-analyzer/build/index.d.ts +20 -0
- package/tools/test-gap-analyzer/build/index.d.ts.map +1 -0
- package/tools/test-gap-analyzer/build/index.js +371 -0
- package/tools/test-gap-analyzer/build/index.js.map +1 -0
- package/tools/test-gap-analyzer/build/index.test.d.ts +2 -0
- package/tools/test-gap-analyzer/build/index.test.d.ts.map +1 -0
- package/tools/test-gap-analyzer/build/index.test.js.map +1 -0
- package/tools/test-gap-analyzer/package.json +20 -0
- package/tools/typescript-enforcer/build/scanner.d.ts.map +1 -1
- package/tools/typescript-enforcer/build/scanner.js +13 -1
- package/tools/typescript-enforcer/build/scanner.js.map +1 -1
- package/tools/typescript-enforcer/build/types.d.ts +1 -0
- package/tools/typescript-enforcer/build/types.d.ts.map +1 -1
- package/mcp-publisher +0 -0
|
@@ -0,0 +1,647 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { McpServerBase } from '@mcp-showcase/shared';
|
|
3
|
+
import * as fs from 'fs';
|
|
4
|
+
import * as path from 'path';
|
|
5
|
+
import { execSync } from 'child_process';
|
|
6
|
+
import { fileURLToPath } from 'url';
|
|
7
|
+
import { dirname } from 'path';
|
|
8
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
9
|
+
const __dirname = dirname(__filename);
|
|
10
|
+
// ============================================================================
|
|
11
|
+
// UTILITY FUNCTIONS
|
|
12
|
+
// ============================================================================
|
|
13
|
+
function readFileContent(filePath) {
|
|
14
|
+
try {
|
|
15
|
+
return fs.readFileSync(filePath, 'utf-8');
|
|
16
|
+
}
|
|
17
|
+
catch {
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
function writeFileContent(filePath, content) {
|
|
22
|
+
fs.writeFileSync(filePath, content, 'utf-8');
|
|
23
|
+
}
|
|
24
|
+
function findComponentFile(componentDir, componentName) {
|
|
25
|
+
const extensions = ['.tsx', '.ts', '.jsx', '.js'];
|
|
26
|
+
for (const ext of extensions) {
|
|
27
|
+
const filePath = path.join(componentDir, `${componentName}${ext}`);
|
|
28
|
+
if (fs.existsSync(filePath))
|
|
29
|
+
return filePath;
|
|
30
|
+
}
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
function findTsconfig(dir) {
|
|
34
|
+
let current = dir;
|
|
35
|
+
while (current !== '/' && current !== '.') {
|
|
36
|
+
const tsconfig = path.join(current, 'tsconfig.json');
|
|
37
|
+
if (fs.existsSync(tsconfig))
|
|
38
|
+
return tsconfig;
|
|
39
|
+
current = path.dirname(current);
|
|
40
|
+
}
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
function runTypeScriptCheck(componentDir) {
|
|
44
|
+
try {
|
|
45
|
+
const tsconfigPath = findTsconfig(componentDir);
|
|
46
|
+
if (!tsconfigPath) {
|
|
47
|
+
return { errors: ['No tsconfig.json found'], passed: false };
|
|
48
|
+
}
|
|
49
|
+
execSync(`npx tsc --noEmit --project ${tsconfigPath}`, {
|
|
50
|
+
cwd: componentDir,
|
|
51
|
+
stdio: 'pipe',
|
|
52
|
+
timeout: 30000,
|
|
53
|
+
});
|
|
54
|
+
return { errors: [], passed: true };
|
|
55
|
+
}
|
|
56
|
+
catch (error) {
|
|
57
|
+
const err = error;
|
|
58
|
+
const output = err.stdout?.toString() || err.stderr?.toString() || err.message;
|
|
59
|
+
const errors = output.split('\n').filter((line) => line.trim().length > 0);
|
|
60
|
+
return { errors: errors.slice(0, 20), passed: false };
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
// ============================================================================
|
|
64
|
+
// FIX ENGINE - Line-based transformations
|
|
65
|
+
// ============================================================================
|
|
66
|
+
class FixEngine {
|
|
67
|
+
content;
|
|
68
|
+
filePath;
|
|
69
|
+
lines;
|
|
70
|
+
modified = false;
|
|
71
|
+
fixes = [];
|
|
72
|
+
constructor(content, filePath) {
|
|
73
|
+
this.content = content;
|
|
74
|
+
this.filePath = filePath;
|
|
75
|
+
this.lines = content.split('\n');
|
|
76
|
+
}
|
|
77
|
+
hasModifications() {
|
|
78
|
+
return this.modified;
|
|
79
|
+
}
|
|
80
|
+
getFixes() {
|
|
81
|
+
return this.fixes;
|
|
82
|
+
}
|
|
83
|
+
getResult() {
|
|
84
|
+
return this.lines.join('\n');
|
|
85
|
+
}
|
|
86
|
+
applyFix(issue) {
|
|
87
|
+
if (!issue.fixable || !issue.fixType) {
|
|
88
|
+
this.fixes.push({
|
|
89
|
+
issueId: issue.id,
|
|
90
|
+
category: issue.category,
|
|
91
|
+
line: issue.line,
|
|
92
|
+
message: issue.message,
|
|
93
|
+
applied: false,
|
|
94
|
+
detail: 'Issue is not fixable or missing fixType',
|
|
95
|
+
});
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
try {
|
|
99
|
+
switch (issue.fixType) {
|
|
100
|
+
case 'remove':
|
|
101
|
+
this.applyRemove(issue);
|
|
102
|
+
break;
|
|
103
|
+
case 'replace':
|
|
104
|
+
this.applyReplace(issue);
|
|
105
|
+
break;
|
|
106
|
+
case 'add':
|
|
107
|
+
this.applyAdd(issue);
|
|
108
|
+
break;
|
|
109
|
+
case 'refactor':
|
|
110
|
+
this.applyRefactor(issue);
|
|
111
|
+
break;
|
|
112
|
+
default:
|
|
113
|
+
this.fixes.push({
|
|
114
|
+
issueId: issue.id,
|
|
115
|
+
category: issue.category,
|
|
116
|
+
line: issue.line,
|
|
117
|
+
message: issue.message,
|
|
118
|
+
applied: false,
|
|
119
|
+
detail: `Unknown fixType: ${issue.fixType}`,
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
catch (error) {
|
|
124
|
+
this.fixes.push({
|
|
125
|
+
issueId: issue.id,
|
|
126
|
+
category: issue.category,
|
|
127
|
+
line: issue.line,
|
|
128
|
+
message: issue.message,
|
|
129
|
+
applied: false,
|
|
130
|
+
detail: `Error: ${error instanceof Error ? error.message : String(error)}`,
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
applyRemove(issue) {
|
|
135
|
+
if (issue.category === 'code-quality' && issue.message.includes('Console statement')) {
|
|
136
|
+
if (issue.line && issue.line > 0) {
|
|
137
|
+
const lineIdx = issue.line - 1;
|
|
138
|
+
const line = this.lines[lineIdx];
|
|
139
|
+
if (line.match(/console\.(log|debug|info)\(/)) {
|
|
140
|
+
this.lines.splice(lineIdx, 1);
|
|
141
|
+
this.modified = true;
|
|
142
|
+
this.fixes.push({
|
|
143
|
+
issueId: issue.id,
|
|
144
|
+
category: issue.category,
|
|
145
|
+
line: issue.line,
|
|
146
|
+
message: issue.message,
|
|
147
|
+
applied: true,
|
|
148
|
+
detail: `Removed console statement at line ${issue.line}`,
|
|
149
|
+
});
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
this.fixes.push({
|
|
155
|
+
issueId: issue.id,
|
|
156
|
+
category: issue.category,
|
|
157
|
+
line: issue.line,
|
|
158
|
+
message: issue.message,
|
|
159
|
+
applied: false,
|
|
160
|
+
detail: 'Remove fix not implemented for this issue type',
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
applyReplace(issue) {
|
|
164
|
+
const lineIdx = issue.line ? issue.line - 1 : -1;
|
|
165
|
+
if (issue.category === 'type-safety' && issue.message.includes("'any' type")) {
|
|
166
|
+
if (lineIdx >= 0 && lineIdx < this.lines.length) {
|
|
167
|
+
let line = this.lines[lineIdx];
|
|
168
|
+
line = line.replace(/:\s*any\b/g, ': unknown');
|
|
169
|
+
line = line.replace(/<any>/g, '<unknown>');
|
|
170
|
+
line = line.replace(/\bas\s+any\b/g, 'as unknown');
|
|
171
|
+
this.lines[lineIdx] = line;
|
|
172
|
+
this.modified = true;
|
|
173
|
+
this.fixes.push({
|
|
174
|
+
issueId: issue.id,
|
|
175
|
+
category: issue.category,
|
|
176
|
+
line: issue.line,
|
|
177
|
+
message: issue.message,
|
|
178
|
+
applied: true,
|
|
179
|
+
detail: `Replaced 'any' with 'unknown' at line ${issue.line}`,
|
|
180
|
+
});
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
if (issue.category === 'type-safety' && issue.message.includes('Non-null assertion')) {
|
|
185
|
+
if (lineIdx >= 0 && lineIdx < this.lines.length) {
|
|
186
|
+
let line = this.lines[lineIdx];
|
|
187
|
+
line = line.replace(/(\w+)!\./g, '$1?.');
|
|
188
|
+
this.lines[lineIdx] = line;
|
|
189
|
+
this.modified = true;
|
|
190
|
+
this.fixes.push({
|
|
191
|
+
issueId: issue.id,
|
|
192
|
+
category: issue.category,
|
|
193
|
+
line: issue.line,
|
|
194
|
+
message: issue.message,
|
|
195
|
+
applied: true,
|
|
196
|
+
detail: `Replaced non-null assertion with optional chaining at line ${issue.line}`,
|
|
197
|
+
});
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
if (issue.category === 'accessibility' && issue.message.includes('positive tabIndex')) {
|
|
202
|
+
if (lineIdx >= 0 && lineIdx < this.lines.length) {
|
|
203
|
+
let line = this.lines[lineIdx];
|
|
204
|
+
line = line.replace(/tabIndex=["'][1-9]\d*["']/g, 'tabIndex={0}');
|
|
205
|
+
this.lines[lineIdx] = line;
|
|
206
|
+
this.modified = true;
|
|
207
|
+
this.fixes.push({
|
|
208
|
+
issueId: issue.id,
|
|
209
|
+
category: issue.category,
|
|
210
|
+
line: issue.line,
|
|
211
|
+
message: issue.message,
|
|
212
|
+
applied: true,
|
|
213
|
+
detail: `Replaced positive tabIndex with 0 at line ${issue.line}`,
|
|
214
|
+
});
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
if (issue.category === 'accessibility' && issue.message.includes('Autoplay media')) {
|
|
219
|
+
if (lineIdx >= 0 && lineIdx < this.lines.length) {
|
|
220
|
+
let line = this.lines[lineIdx];
|
|
221
|
+
line = line.replace(/\s*autoPlay/, ' controls muted');
|
|
222
|
+
this.lines[lineIdx] = line;
|
|
223
|
+
this.modified = true;
|
|
224
|
+
this.fixes.push({
|
|
225
|
+
issueId: issue.id,
|
|
226
|
+
category: issue.category,
|
|
227
|
+
line: issue.line,
|
|
228
|
+
message: issue.message,
|
|
229
|
+
applied: true,
|
|
230
|
+
detail: `Replaced autoplay with controls muted at line ${issue.line}`,
|
|
231
|
+
});
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
this.fixes.push({
|
|
236
|
+
issueId: issue.id,
|
|
237
|
+
category: issue.category,
|
|
238
|
+
line: issue.line,
|
|
239
|
+
message: issue.message,
|
|
240
|
+
applied: false,
|
|
241
|
+
detail: 'Replace fix not implemented for this issue type',
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
applyAdd(issue) {
|
|
245
|
+
if (issue.category === 'react-patterns' && issue.message.includes('displayName')) {
|
|
246
|
+
const componentNameMatch = issue.suggestion.match(/(\w+)\.displayName/);
|
|
247
|
+
const componentName = componentNameMatch ? componentNameMatch[1] : null;
|
|
248
|
+
if (componentName) {
|
|
249
|
+
let insertIdx = this.lines.length;
|
|
250
|
+
for (let i = this.lines.length - 1; i >= 0; i--) {
|
|
251
|
+
if (this.lines[i].match(/export\s*\{/) || this.lines[i].match(/export\s+default/)) {
|
|
252
|
+
insertIdx = i;
|
|
253
|
+
break;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
this.lines.splice(insertIdx, 0, '', `${componentName}.displayName = '${componentName}';`);
|
|
257
|
+
this.modified = true;
|
|
258
|
+
this.fixes.push({
|
|
259
|
+
issueId: issue.id,
|
|
260
|
+
category: issue.category,
|
|
261
|
+
line: issue.line,
|
|
262
|
+
message: issue.message,
|
|
263
|
+
applied: true,
|
|
264
|
+
detail: `Added displayName = '${componentName}'`,
|
|
265
|
+
});
|
|
266
|
+
return;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
const lineIdx = issue.line ? issue.line - 1 : -1;
|
|
270
|
+
if (issue.category === 'accessibility' && issue.message.includes('Image missing alt')) {
|
|
271
|
+
if (lineIdx >= 0 && lineIdx < this.lines.length) {
|
|
272
|
+
let line = this.lines[lineIdx];
|
|
273
|
+
if (line.match(/<img\s[^/]*\/?\s*>/)) {
|
|
274
|
+
line = line.replace(/<img\s/, '<img alt="" ');
|
|
275
|
+
this.lines[lineIdx] = line;
|
|
276
|
+
this.modified = true;
|
|
277
|
+
this.fixes.push({
|
|
278
|
+
issueId: issue.id,
|
|
279
|
+
category: issue.category,
|
|
280
|
+
line: issue.line,
|
|
281
|
+
message: issue.message,
|
|
282
|
+
applied: true,
|
|
283
|
+
detail: `Added alt="" to image at line ${issue.line}`,
|
|
284
|
+
});
|
|
285
|
+
return;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
if (issue.category === 'accessibility' && issue.message.includes('Form input missing')) {
|
|
290
|
+
if (lineIdx >= 0 && lineIdx < this.lines.length) {
|
|
291
|
+
let line = this.lines[lineIdx];
|
|
292
|
+
if (!line.includes('aria-label') && !line.includes('aria-labelledby')) {
|
|
293
|
+
const inputTypeMatch = line.match(/type=["'](\w+)["']/);
|
|
294
|
+
const placeholder = inputTypeMatch ? inputTypeMatch[1] : 'input';
|
|
295
|
+
line = line.replace(/<input\s/, `<input aria-label="${placeholder}" `);
|
|
296
|
+
this.lines[lineIdx] = line;
|
|
297
|
+
this.modified = true;
|
|
298
|
+
this.fixes.push({
|
|
299
|
+
issueId: issue.id,
|
|
300
|
+
category: issue.category,
|
|
301
|
+
line: issue.line,
|
|
302
|
+
message: issue.message,
|
|
303
|
+
applied: true,
|
|
304
|
+
detail: `Added aria-label to input at line ${issue.line}`,
|
|
305
|
+
});
|
|
306
|
+
return;
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
if (issue.category === 'accessibility' && issue.message.includes('Clickable div missing')) {
|
|
311
|
+
if (lineIdx >= 0 && lineIdx < this.lines.length) {
|
|
312
|
+
let line = this.lines[lineIdx];
|
|
313
|
+
if (line.includes('onClick') && !line.includes('role=')) {
|
|
314
|
+
line = line.replace(/<div/, '<div role="button" tabIndex={0}');
|
|
315
|
+
this.lines[lineIdx] = line;
|
|
316
|
+
this.modified = true;
|
|
317
|
+
this.fixes.push({
|
|
318
|
+
issueId: issue.id,
|
|
319
|
+
category: issue.category,
|
|
320
|
+
line: issue.line,
|
|
321
|
+
message: issue.message,
|
|
322
|
+
applied: true,
|
|
323
|
+
detail: `Added role="button" and tabIndex={0} to clickable div at line ${issue.line}`,
|
|
324
|
+
});
|
|
325
|
+
return;
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
if (issue.category === 'accessibility' && issue.message.includes('Icon button missing')) {
|
|
330
|
+
if (lineIdx >= 0 && lineIdx < this.lines.length) {
|
|
331
|
+
let line = this.lines[lineIdx];
|
|
332
|
+
if ((line.includes('<button') || line.includes('<a')) && !line.includes('aria-label')) {
|
|
333
|
+
line = line.replace(/<(button|a)/, '<$1 aria-label="Button action"');
|
|
334
|
+
this.lines[lineIdx] = line;
|
|
335
|
+
this.modified = true;
|
|
336
|
+
this.fixes.push({
|
|
337
|
+
issueId: issue.id,
|
|
338
|
+
category: issue.category,
|
|
339
|
+
line: issue.line,
|
|
340
|
+
message: issue.message,
|
|
341
|
+
applied: true,
|
|
342
|
+
detail: `Added aria-label to icon button at line ${issue.line}`,
|
|
343
|
+
});
|
|
344
|
+
return;
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
if (issue.category === 'accessibility' && issue.message.includes('Link element missing href')) {
|
|
349
|
+
if (lineIdx >= 0 && lineIdx < this.lines.length) {
|
|
350
|
+
let line = this.lines[lineIdx];
|
|
351
|
+
if (line.match(/<a\s[^>]*>/) && !line.includes('href=')) {
|
|
352
|
+
line = line.replace(/<a\s/, '<a href="#" ');
|
|
353
|
+
this.lines[lineIdx] = line;
|
|
354
|
+
this.modified = true;
|
|
355
|
+
this.fixes.push({
|
|
356
|
+
issueId: issue.id,
|
|
357
|
+
category: issue.category,
|
|
358
|
+
line: issue.line,
|
|
359
|
+
message: issue.message,
|
|
360
|
+
applied: true,
|
|
361
|
+
detail: `Added href="#" to link at line ${issue.line} (update with actual URL)`,
|
|
362
|
+
});
|
|
363
|
+
return;
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
this.fixes.push({
|
|
368
|
+
issueId: issue.id,
|
|
369
|
+
category: issue.category,
|
|
370
|
+
line: issue.line,
|
|
371
|
+
message: issue.message,
|
|
372
|
+
applied: false,
|
|
373
|
+
detail: 'Add fix not implemented for this issue type',
|
|
374
|
+
});
|
|
375
|
+
}
|
|
376
|
+
applyRefactor(issue) {
|
|
377
|
+
const lineIdx = issue.line ? issue.line - 1 : -1;
|
|
378
|
+
if (issue.category === 'performance' && issue.message.includes('Inline arrow function')) {
|
|
379
|
+
if (lineIdx >= 0 && lineIdx < this.lines.length) {
|
|
380
|
+
const line = this.lines[lineIdx];
|
|
381
|
+
const handlerMatch = line.match(/(onClick|onChange|onSubmit|onFocus|onBlur)=\{([^}]+=>[^}]+)\}/);
|
|
382
|
+
if (handlerMatch) {
|
|
383
|
+
const eventName = handlerMatch[1];
|
|
384
|
+
const handlerBody = handlerMatch[2];
|
|
385
|
+
const handlerName = `handle${eventName.charAt(2).toUpperCase() + eventName.slice(3)}`;
|
|
386
|
+
this.lines[lineIdx] = line.replace(new RegExp(`${eventName}=\\{[^}]+=>[^}]+\\}`), `${eventName}={${handlerName}}`);
|
|
387
|
+
this.lines.splice(lineIdx, 0, `// TODO: Extract ${handlerName} = ${handlerBody} as a named function or useCallback`);
|
|
388
|
+
this.modified = true;
|
|
389
|
+
this.fixes.push({
|
|
390
|
+
issueId: issue.id,
|
|
391
|
+
category: issue.category,
|
|
392
|
+
line: issue.line,
|
|
393
|
+
message: issue.message,
|
|
394
|
+
applied: true,
|
|
395
|
+
detail: `Replaced inline ${eventName} handler with reference at line ${issue.line}`,
|
|
396
|
+
});
|
|
397
|
+
return;
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
if (issue.category === 'performance' && issue.message.includes('Inline object literal')) {
|
|
402
|
+
if (lineIdx >= 0 && lineIdx < this.lines.length) {
|
|
403
|
+
const line = this.lines[lineIdx];
|
|
404
|
+
const styleMatch = line.match(/style=\{\{([^}]+)\}\}/);
|
|
405
|
+
if (styleMatch) {
|
|
406
|
+
this.lines[lineIdx] = line.replace(/style=\{\{[^}]+\}\}/, 'style={styles} // TODO: Extract to constant or useMemo');
|
|
407
|
+
this.modified = true;
|
|
408
|
+
this.fixes.push({
|
|
409
|
+
issueId: issue.id,
|
|
410
|
+
category: issue.category,
|
|
411
|
+
line: issue.line,
|
|
412
|
+
message: issue.message,
|
|
413
|
+
applied: true,
|
|
414
|
+
detail: `Replaced inline style object with reference at line ${issue.line}`,
|
|
415
|
+
});
|
|
416
|
+
return;
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
if (issue.category === 'security' && issue.message.includes('innerHTML')) {
|
|
421
|
+
if (lineIdx >= 0 && lineIdx < this.lines.length) {
|
|
422
|
+
this.lines[lineIdx] = this.lines[lineIdx] + ' // TODO: Replace innerHTML with React declarative rendering';
|
|
423
|
+
this.modified = true;
|
|
424
|
+
this.fixes.push({
|
|
425
|
+
issueId: issue.id,
|
|
426
|
+
category: issue.category,
|
|
427
|
+
line: issue.line,
|
|
428
|
+
message: issue.message,
|
|
429
|
+
applied: true,
|
|
430
|
+
detail: `Added TODO comment for innerHTML usage at line ${issue.line}`,
|
|
431
|
+
});
|
|
432
|
+
return;
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
this.fixes.push({
|
|
436
|
+
issueId: issue.id,
|
|
437
|
+
category: issue.category,
|
|
438
|
+
line: issue.line,
|
|
439
|
+
message: issue.message,
|
|
440
|
+
applied: false,
|
|
441
|
+
detail: 'Refactor fix not implemented for this issue type',
|
|
442
|
+
});
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
// ============================================================================
|
|
446
|
+
// MAIN FIX HANDLER
|
|
447
|
+
// ============================================================================
|
|
448
|
+
function fixFromReview(componentDir, componentName, reviewResult) {
|
|
449
|
+
const componentFile = findComponentFile(componentDir, componentName);
|
|
450
|
+
if (!componentFile) {
|
|
451
|
+
return {
|
|
452
|
+
success: false,
|
|
453
|
+
component: componentName,
|
|
454
|
+
file: '',
|
|
455
|
+
summary: { totalFixable: 0, applied: 0, skipped: 0, failed: 0 },
|
|
456
|
+
fixes: [],
|
|
457
|
+
remainingIssues: [],
|
|
458
|
+
typescriptCheck: { passed: false, errors: ['Component file not found'] },
|
|
459
|
+
};
|
|
460
|
+
}
|
|
461
|
+
const content = readFileContent(componentFile);
|
|
462
|
+
if (!content) {
|
|
463
|
+
return {
|
|
464
|
+
success: false,
|
|
465
|
+
component: componentName,
|
|
466
|
+
file: componentFile,
|
|
467
|
+
summary: { totalFixable: 0, applied: 0, skipped: 0, failed: 0 },
|
|
468
|
+
fixes: [],
|
|
469
|
+
remainingIssues: [],
|
|
470
|
+
typescriptCheck: { passed: false, errors: ['Could not read component file'] },
|
|
471
|
+
};
|
|
472
|
+
}
|
|
473
|
+
const fixableIssues = reviewResult.issues.filter(i => i.fixable);
|
|
474
|
+
const scoreBefore = reviewResult.summary.overallScore;
|
|
475
|
+
const gradeBefore = reviewResult.summary.grade;
|
|
476
|
+
const engine = new FixEngine(content, componentFile);
|
|
477
|
+
for (const issue of fixableIssues) {
|
|
478
|
+
engine.applyFix(issue);
|
|
479
|
+
}
|
|
480
|
+
if (engine.hasModifications()) {
|
|
481
|
+
writeFileContent(componentFile, engine.getResult());
|
|
482
|
+
}
|
|
483
|
+
const tsResult = runTypeScriptCheck(componentDir);
|
|
484
|
+
const fixes = engine.getFixes();
|
|
485
|
+
const applied = fixes.filter(f => f.applied).length;
|
|
486
|
+
const skipped = fixes.filter(f => !f.applied && !f.detail.includes('Error')).length;
|
|
487
|
+
const failed = fixes.filter(f => !f.applied && f.detail.includes('Error')).length;
|
|
488
|
+
const remainingIssues = reviewResult.issues.filter(i => !i.fixable);
|
|
489
|
+
return {
|
|
490
|
+
success: true,
|
|
491
|
+
component: componentName,
|
|
492
|
+
file: path.relative(process.cwd(), componentFile),
|
|
493
|
+
summary: {
|
|
494
|
+
totalFixable: fixableIssues.length,
|
|
495
|
+
applied,
|
|
496
|
+
skipped,
|
|
497
|
+
failed,
|
|
498
|
+
scoreBefore,
|
|
499
|
+
gradeBefore,
|
|
500
|
+
},
|
|
501
|
+
fixes,
|
|
502
|
+
remainingIssues,
|
|
503
|
+
typescriptCheck: tsResult,
|
|
504
|
+
};
|
|
505
|
+
}
|
|
506
|
+
// ============================================================================
|
|
507
|
+
// MCP SERVER
|
|
508
|
+
// ============================================================================
|
|
509
|
+
class ComponentFixerServer extends McpServerBase {
|
|
510
|
+
constructor() {
|
|
511
|
+
super({ name: 'component-fixer', version: '3.0.0' });
|
|
512
|
+
}
|
|
513
|
+
registerTools() {
|
|
514
|
+
this.addTool('fix', 'Comprehensive React component fixer - applies fixes from review JSON output for type-safety, accessibility, performance, security, code quality, and more', {
|
|
515
|
+
type: 'object',
|
|
516
|
+
properties: {
|
|
517
|
+
path: {
|
|
518
|
+
type: 'string',
|
|
519
|
+
description: 'Path to the component directory',
|
|
520
|
+
},
|
|
521
|
+
reviewResult: {
|
|
522
|
+
type: 'object',
|
|
523
|
+
description: 'Review result JSON from component-reviewer (optional - if not provided, will run reviewer internally)',
|
|
524
|
+
},
|
|
525
|
+
},
|
|
526
|
+
required: ['path'],
|
|
527
|
+
}, this.handleFix.bind(this));
|
|
528
|
+
this.addTool('fix_from_review', 'Fix component issues from a pre-computed review JSON. Pass the exact output from component-reviewer.', {
|
|
529
|
+
type: 'object',
|
|
530
|
+
properties: {
|
|
531
|
+
path: {
|
|
532
|
+
type: 'string',
|
|
533
|
+
description: 'Path to the component directory',
|
|
534
|
+
},
|
|
535
|
+
reviewJson: {
|
|
536
|
+
type: 'string',
|
|
537
|
+
description: 'JSON string from component-reviewer output',
|
|
538
|
+
},
|
|
539
|
+
},
|
|
540
|
+
required: ['path', 'reviewJson'],
|
|
541
|
+
}, this.handleFixFromReview.bind(this));
|
|
542
|
+
}
|
|
543
|
+
async handleFix(args) {
|
|
544
|
+
const { path: componentPath, reviewResult } = args;
|
|
545
|
+
try {
|
|
546
|
+
const resolvedPath = path.resolve(componentPath);
|
|
547
|
+
if (!fs.existsSync(resolvedPath)) {
|
|
548
|
+
throw new Error(`Component path does not exist: ${componentPath}`);
|
|
549
|
+
}
|
|
550
|
+
let componentDir;
|
|
551
|
+
let componentName;
|
|
552
|
+
const stat = fs.statSync(resolvedPath);
|
|
553
|
+
if (stat.isFile()) {
|
|
554
|
+
componentDir = path.dirname(resolvedPath);
|
|
555
|
+
componentName = path.basename(resolvedPath, path.extname(resolvedPath));
|
|
556
|
+
}
|
|
557
|
+
else {
|
|
558
|
+
componentDir = resolvedPath;
|
|
559
|
+
componentName = path.basename(resolvedPath);
|
|
560
|
+
}
|
|
561
|
+
if (!reviewResult) {
|
|
562
|
+
return {
|
|
563
|
+
content: [{
|
|
564
|
+
type: 'text',
|
|
565
|
+
text: JSON.stringify({
|
|
566
|
+
success: false,
|
|
567
|
+
error: {
|
|
568
|
+
code: 'MISSING_REVIEW',
|
|
569
|
+
message: 'No reviewResult provided. Use fix_from_review with reviewJson.',
|
|
570
|
+
suggestion: 'Run component-reviewer first, then pass the result to fix_from_review.',
|
|
571
|
+
},
|
|
572
|
+
}, null, 2),
|
|
573
|
+
}],
|
|
574
|
+
isError: true,
|
|
575
|
+
};
|
|
576
|
+
}
|
|
577
|
+
const result = fixFromReview(componentDir, componentName, reviewResult);
|
|
578
|
+
return {
|
|
579
|
+
content: [{
|
|
580
|
+
type: 'text',
|
|
581
|
+
text: JSON.stringify(result, null, 2),
|
|
582
|
+
}],
|
|
583
|
+
};
|
|
584
|
+
}
|
|
585
|
+
catch (error) {
|
|
586
|
+
return {
|
|
587
|
+
content: [{
|
|
588
|
+
type: 'text',
|
|
589
|
+
text: JSON.stringify({
|
|
590
|
+
success: false,
|
|
591
|
+
error: {
|
|
592
|
+
code: error instanceof Error ? error.constructor.name : 'UNKNOWN_ERROR',
|
|
593
|
+
message: error instanceof Error ? error.message : String(error),
|
|
594
|
+
suggestion: 'Check input parameters and ensure the component path is valid.',
|
|
595
|
+
timestamp: new Date().toISOString(),
|
|
596
|
+
},
|
|
597
|
+
}, null, 2),
|
|
598
|
+
}],
|
|
599
|
+
isError: true,
|
|
600
|
+
};
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
async handleFixFromReview(args) {
|
|
604
|
+
const { path: componentPath, reviewJson } = args;
|
|
605
|
+
try {
|
|
606
|
+
const reviewResult = JSON.parse(reviewJson);
|
|
607
|
+
const resolvedPath = path.resolve(componentPath);
|
|
608
|
+
let componentDir;
|
|
609
|
+
let componentName;
|
|
610
|
+
const stat = fs.statSync(resolvedPath);
|
|
611
|
+
if (stat.isFile()) {
|
|
612
|
+
componentDir = path.dirname(resolvedPath);
|
|
613
|
+
componentName = path.basename(resolvedPath, path.extname(resolvedPath));
|
|
614
|
+
}
|
|
615
|
+
else {
|
|
616
|
+
componentDir = resolvedPath;
|
|
617
|
+
componentName = path.basename(resolvedPath);
|
|
618
|
+
}
|
|
619
|
+
const result = fixFromReview(componentDir, componentName, reviewResult);
|
|
620
|
+
return {
|
|
621
|
+
content: [{
|
|
622
|
+
type: 'text',
|
|
623
|
+
text: JSON.stringify(result, null, 2),
|
|
624
|
+
}],
|
|
625
|
+
};
|
|
626
|
+
}
|
|
627
|
+
catch (error) {
|
|
628
|
+
return {
|
|
629
|
+
content: [{
|
|
630
|
+
type: 'text',
|
|
631
|
+
text: JSON.stringify({
|
|
632
|
+
success: false,
|
|
633
|
+
error: {
|
|
634
|
+
code: error instanceof Error ? error.constructor.name : 'UNKNOWN_ERROR',
|
|
635
|
+
message: error instanceof Error ? error.message : String(error),
|
|
636
|
+
suggestion: 'Ensure reviewJson is valid JSON from component-reviewer.',
|
|
637
|
+
timestamp: new Date().toISOString(),
|
|
638
|
+
},
|
|
639
|
+
}, null, 2),
|
|
640
|
+
}],
|
|
641
|
+
isError: true,
|
|
642
|
+
};
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
new ComponentFixerServer().run().catch(console.error);
|
|
647
|
+
//# sourceMappingURL=index.js.map
|