@performance-agent/mcp-server 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +503 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +300 -0
- package/dist/index.js.map +1 -0
- package/dist/tools/code-analyzer/analyzers/javascript-analyzer.d.ts +36 -0
- package/dist/tools/code-analyzer/analyzers/javascript-analyzer.d.ts.map +1 -0
- package/dist/tools/code-analyzer/analyzers/javascript-analyzer.js +241 -0
- package/dist/tools/code-analyzer/analyzers/javascript-analyzer.js.map +1 -0
- package/dist/tools/code-analyzer/analyzers/python-analyzer.d.ts +30 -0
- package/dist/tools/code-analyzer/analyzers/python-analyzer.d.ts.map +1 -0
- package/dist/tools/code-analyzer/analyzers/python-analyzer.js +142 -0
- package/dist/tools/code-analyzer/analyzers/python-analyzer.js.map +1 -0
- package/dist/tools/code-analyzer/git-helper.d.ts +52 -0
- package/dist/tools/code-analyzer/git-helper.d.ts.map +1 -0
- package/dist/tools/code-analyzer/git-helper.js +124 -0
- package/dist/tools/code-analyzer/git-helper.js.map +1 -0
- package/dist/tools/code-analyzer/index.d.ts +45 -0
- package/dist/tools/code-analyzer/index.d.ts.map +1 -0
- package/dist/tools/code-analyzer/index.js +213 -0
- package/dist/tools/code-analyzer/index.js.map +1 -0
- package/dist/tools/code-analyzer/types.d.ts +54 -0
- package/dist/tools/code-analyzer/types.d.ts.map +1 -0
- package/dist/tools/code-analyzer/types.js +5 -0
- package/dist/tools/code-analyzer/types.js.map +1 -0
- package/dist/tools/function-profiler/index.d.ts +11 -0
- package/dist/tools/function-profiler/index.d.ts.map +1 -0
- package/dist/tools/function-profiler/index.js +192 -0
- package/dist/tools/function-profiler/index.js.map +1 -0
- package/dist/tools/function-profiler/javascript-profiler.d.ts +27 -0
- package/dist/tools/function-profiler/javascript-profiler.d.ts.map +1 -0
- package/dist/tools/function-profiler/javascript-profiler.js +141 -0
- package/dist/tools/function-profiler/javascript-profiler.js.map +1 -0
- package/dist/tools/function-profiler/python-profiler.d.ts +31 -0
- package/dist/tools/function-profiler/python-profiler.d.ts.map +1 -0
- package/dist/tools/function-profiler/python-profiler.js +212 -0
- package/dist/tools/function-profiler/python-profiler.js.map +1 -0
- package/dist/tools/function-profiler/types.d.ts +41 -0
- package/dist/tools/function-profiler/types.d.ts.map +1 -0
- package/dist/tools/function-profiler/types.js +5 -0
- package/dist/tools/function-profiler/types.js.map +1 -0
- package/package.json +51 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Performance Agent MCP Server
|
|
4
|
+
*
|
|
5
|
+
* This MCP server provides 3 core tools:
|
|
6
|
+
* 1. Generate JMX scripts from Swagger/OpenAPI specifications
|
|
7
|
+
* 2. Analyze code complexity in local git repositories
|
|
8
|
+
* 3. Profile function execution time and identify slow functions
|
|
9
|
+
*
|
|
10
|
+
* Focused on local development and code quality.
|
|
11
|
+
*/
|
|
12
|
+
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
13
|
+
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
14
|
+
import { CallToolRequestSchema, ListToolsRequestSchema, } from '@modelcontextprotocol/sdk/types.js';
|
|
15
|
+
import axios from 'axios';
|
|
16
|
+
import * as dotenv from 'dotenv';
|
|
17
|
+
import { analyzeCodeComplexity } from './tools/code-analyzer/index.js';
|
|
18
|
+
import { profileFunctionPerformance } from './tools/function-profiler/index.js';
|
|
19
|
+
// Load environment variables
|
|
20
|
+
dotenv.config();
|
|
21
|
+
// Configuration
|
|
22
|
+
const API_BASE_URL = process.env.PERFORMANCE_AGENT_API_URL || 'http://localhost:8000';
|
|
23
|
+
const API_KEY = process.env.PERFORMANCE_AGENT_API_KEY || '';
|
|
24
|
+
/**
|
|
25
|
+
* Performance Agent API Client - Minimal client for JMX generation
|
|
26
|
+
*/
|
|
27
|
+
class PerformanceAgentClient {
|
|
28
|
+
client;
|
|
29
|
+
constructor(baseURL, apiKey) {
|
|
30
|
+
this.client = axios.create({
|
|
31
|
+
baseURL,
|
|
32
|
+
headers: {
|
|
33
|
+
'Content-Type': 'application/json',
|
|
34
|
+
...(apiKey && { 'Authorization': `Bearer ${apiKey}` }),
|
|
35
|
+
},
|
|
36
|
+
timeout: 300000, // 5 minutes
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Generate JMX script from Swagger content
|
|
41
|
+
*/
|
|
42
|
+
async generateFromSwagger(repoName, swaggerContent) {
|
|
43
|
+
const response = await this.client.post('/api/orchestrator/execute', {
|
|
44
|
+
action: 'generate_from_swagger',
|
|
45
|
+
payload: {
|
|
46
|
+
repo_name: repoName,
|
|
47
|
+
swagger_content: swaggerContent,
|
|
48
|
+
},
|
|
49
|
+
});
|
|
50
|
+
return response.data;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Define MCP Tools - Simplified to 2 core features
|
|
55
|
+
*/
|
|
56
|
+
const TOOLS = [
|
|
57
|
+
{
|
|
58
|
+
name: 'generateJMXFromSwagger',
|
|
59
|
+
description: 'Generate JMeter (JMX) performance test script from Swagger/OpenAPI specification. Analyzes API endpoints and creates comprehensive load test scenarios.',
|
|
60
|
+
inputSchema: {
|
|
61
|
+
type: 'object',
|
|
62
|
+
properties: {
|
|
63
|
+
repo_name: {
|
|
64
|
+
type: 'string',
|
|
65
|
+
description: 'Repository name for the generated script',
|
|
66
|
+
},
|
|
67
|
+
swagger_content: {
|
|
68
|
+
type: 'object',
|
|
69
|
+
description: 'Swagger/OpenAPI JSON specification object',
|
|
70
|
+
additionalProperties: true,
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
required: ['swagger_content'],
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
name: 'analyzeCodeComplexity',
|
|
78
|
+
description: 'Analyze cyclomatic complexity of code changes in local git repository. Helps identify overly complex functions that may have performance or maintainability issues. Supports Python, JavaScript, and TypeScript.',
|
|
79
|
+
inputSchema: {
|
|
80
|
+
type: 'object',
|
|
81
|
+
properties: {
|
|
82
|
+
repo_path: {
|
|
83
|
+
type: 'string',
|
|
84
|
+
description: 'Absolute path to git repository (defaults to workspace root)',
|
|
85
|
+
},
|
|
86
|
+
mode: {
|
|
87
|
+
type: 'string',
|
|
88
|
+
enum: ['staged', 'last_commit', 'uncommitted', 'commit_sha'],
|
|
89
|
+
description: 'What to analyze: staged changes, last commit, uncommitted changes, or specific commit',
|
|
90
|
+
default: 'last_commit',
|
|
91
|
+
},
|
|
92
|
+
commit_sha: {
|
|
93
|
+
type: 'string',
|
|
94
|
+
description: 'Specific commit SHA to analyze (required if mode=commit_sha)',
|
|
95
|
+
},
|
|
96
|
+
threshold: {
|
|
97
|
+
type: 'number',
|
|
98
|
+
description: 'Complexity threshold to flag as high-risk (default: 10)',
|
|
99
|
+
default: 10,
|
|
100
|
+
},
|
|
101
|
+
language: {
|
|
102
|
+
type: 'string',
|
|
103
|
+
enum: ['python', 'javascript', 'typescript', 'all'],
|
|
104
|
+
description: 'Programming language to analyze (default: all)',
|
|
105
|
+
default: 'all',
|
|
106
|
+
},
|
|
107
|
+
},
|
|
108
|
+
required: ['repo_path'],
|
|
109
|
+
},
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
name: 'profileFunctionPerformance',
|
|
113
|
+
description: 'Profile function execution time by running functions multiple times. Identifies slow functions that may need optimization. Supports Python and JavaScript/TypeScript.',
|
|
114
|
+
inputSchema: {
|
|
115
|
+
type: 'object',
|
|
116
|
+
properties: {
|
|
117
|
+
repo_path: {
|
|
118
|
+
type: 'string',
|
|
119
|
+
description: 'Absolute path to the repository or file to profile',
|
|
120
|
+
},
|
|
121
|
+
file_path: {
|
|
122
|
+
type: 'string',
|
|
123
|
+
description: 'Specific file to profile (optional, if not provided will profile changed files)',
|
|
124
|
+
},
|
|
125
|
+
function_name: {
|
|
126
|
+
type: 'string',
|
|
127
|
+
description: 'Specific function to profile (optional, if not provided will profile all functions)',
|
|
128
|
+
},
|
|
129
|
+
iterations: {
|
|
130
|
+
type: 'number',
|
|
131
|
+
description: 'Number of times to run each function (default: 10)',
|
|
132
|
+
default: 10,
|
|
133
|
+
},
|
|
134
|
+
threshold_ms: {
|
|
135
|
+
type: 'number',
|
|
136
|
+
description: 'Threshold in milliseconds - functions slower than this are flagged (default: 100)',
|
|
137
|
+
default: 100,
|
|
138
|
+
},
|
|
139
|
+
mode: {
|
|
140
|
+
type: 'string',
|
|
141
|
+
enum: ['staged', 'last_commit', 'uncommitted', 'file'],
|
|
142
|
+
description: 'What to profile: git changes or specific file',
|
|
143
|
+
default: 'uncommitted',
|
|
144
|
+
},
|
|
145
|
+
},
|
|
146
|
+
required: ['repo_path'],
|
|
147
|
+
},
|
|
148
|
+
},
|
|
149
|
+
];
|
|
150
|
+
/**
|
|
151
|
+
* Create and configure MCP Server
|
|
152
|
+
*/
|
|
153
|
+
const server = new Server({
|
|
154
|
+
name: 'performance-agent-mcp',
|
|
155
|
+
version: '1.0.0',
|
|
156
|
+
}, {
|
|
157
|
+
capabilities: {
|
|
158
|
+
tools: {},
|
|
159
|
+
},
|
|
160
|
+
});
|
|
161
|
+
// Initialize API client
|
|
162
|
+
const apiClient = new PerformanceAgentClient(API_BASE_URL, API_KEY);
|
|
163
|
+
/**
|
|
164
|
+
* List available tools
|
|
165
|
+
*/
|
|
166
|
+
server.setRequestHandler(ListToolsRequestSchema, async () => {
|
|
167
|
+
return {
|
|
168
|
+
tools: TOOLS,
|
|
169
|
+
};
|
|
170
|
+
});
|
|
171
|
+
/**
|
|
172
|
+
* Handle tool execution
|
|
173
|
+
*/
|
|
174
|
+
server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
175
|
+
const { name, arguments: args } = request.params;
|
|
176
|
+
if (!args || typeof args !== 'object') {
|
|
177
|
+
throw new Error('Invalid arguments');
|
|
178
|
+
}
|
|
179
|
+
try {
|
|
180
|
+
let result;
|
|
181
|
+
// Route to appropriate tool handler
|
|
182
|
+
switch (name) {
|
|
183
|
+
case 'generateJMXFromSwagger':
|
|
184
|
+
result = await handleGenerateJMX(args);
|
|
185
|
+
break;
|
|
186
|
+
case 'analyzeCodeComplexity':
|
|
187
|
+
result = await handleCodeComplexity(args);
|
|
188
|
+
break;
|
|
189
|
+
case 'profileFunctionPerformance':
|
|
190
|
+
result = await handleFunctionProfiling(args);
|
|
191
|
+
break;
|
|
192
|
+
default:
|
|
193
|
+
throw new Error(`Unknown tool: ${name}`);
|
|
194
|
+
}
|
|
195
|
+
return {
|
|
196
|
+
content: [
|
|
197
|
+
{
|
|
198
|
+
type: 'text',
|
|
199
|
+
text: JSON.stringify(result, null, 2),
|
|
200
|
+
},
|
|
201
|
+
],
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
catch (error) {
|
|
205
|
+
const errorMessage = error.message || 'Unknown error';
|
|
206
|
+
return {
|
|
207
|
+
content: [
|
|
208
|
+
{
|
|
209
|
+
type: 'text',
|
|
210
|
+
text: JSON.stringify({
|
|
211
|
+
error: true,
|
|
212
|
+
message: errorMessage,
|
|
213
|
+
tool: name,
|
|
214
|
+
}, null, 2),
|
|
215
|
+
},
|
|
216
|
+
],
|
|
217
|
+
isError: true,
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
});
|
|
221
|
+
/**
|
|
222
|
+
* Handler for generateJMXFromSwagger tool
|
|
223
|
+
*/
|
|
224
|
+
async function handleGenerateJMX(args) {
|
|
225
|
+
const { repo_name = 'api-test', swagger_content } = args;
|
|
226
|
+
if (!swagger_content) {
|
|
227
|
+
throw new Error('Missing required field: swagger_content');
|
|
228
|
+
}
|
|
229
|
+
const result = await apiClient.generateFromSwagger(repo_name, swagger_content);
|
|
230
|
+
return {
|
|
231
|
+
success: true,
|
|
232
|
+
tool: 'generateJMXFromSwagger',
|
|
233
|
+
repo_name,
|
|
234
|
+
jmx_script: result.jmx_script,
|
|
235
|
+
local_file: result.local_file,
|
|
236
|
+
message: result.message || 'JMX script generated successfully',
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Handler for analyzeCodeComplexity tool
|
|
241
|
+
*/
|
|
242
|
+
async function handleCodeComplexity(args) {
|
|
243
|
+
const { repo_path, mode = 'last_commit', commit_sha, threshold = 10, language = 'all', } = args;
|
|
244
|
+
if (!repo_path) {
|
|
245
|
+
throw new Error('Missing required field: repo_path');
|
|
246
|
+
}
|
|
247
|
+
const report = await analyzeCodeComplexity({
|
|
248
|
+
repo_path,
|
|
249
|
+
mode,
|
|
250
|
+
commit_sha,
|
|
251
|
+
threshold,
|
|
252
|
+
language,
|
|
253
|
+
});
|
|
254
|
+
return {
|
|
255
|
+
success: true,
|
|
256
|
+
tool: 'analyzeCodeComplexity',
|
|
257
|
+
...report,
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* Handler for profileFunctionPerformance tool
|
|
262
|
+
*/
|
|
263
|
+
async function handleFunctionProfiling(args) {
|
|
264
|
+
const { repo_path, file_path, function_name, iterations = 10, threshold_ms = 100, mode = 'uncommitted', } = args;
|
|
265
|
+
if (!repo_path) {
|
|
266
|
+
throw new Error('Missing required field: repo_path');
|
|
267
|
+
}
|
|
268
|
+
const report = await profileFunctionPerformance({
|
|
269
|
+
repo_path,
|
|
270
|
+
file_path,
|
|
271
|
+
function_name,
|
|
272
|
+
iterations,
|
|
273
|
+
threshold_ms,
|
|
274
|
+
mode,
|
|
275
|
+
});
|
|
276
|
+
return {
|
|
277
|
+
success: true,
|
|
278
|
+
tool: 'profileFunctionPerformance',
|
|
279
|
+
...report,
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
/**
|
|
283
|
+
* Start the MCP server
|
|
284
|
+
*/
|
|
285
|
+
async function main() {
|
|
286
|
+
console.error('Starting Performance Agent MCP Server...');
|
|
287
|
+
console.error('Available tools:');
|
|
288
|
+
console.error(' 1. generateJMXFromSwagger - Generate JMeter scripts from Swagger');
|
|
289
|
+
console.error(' 2. analyzeCodeComplexity - Analyze code complexity in local repos');
|
|
290
|
+
console.error(' 3. profileFunctionPerformance - Profile function execution time');
|
|
291
|
+
console.error(`API Base URL: ${API_BASE_URL}`);
|
|
292
|
+
const transport = new StdioServerTransport();
|
|
293
|
+
await server.connect(transport);
|
|
294
|
+
console.error('Performance Agent MCP Server running on stdio');
|
|
295
|
+
}
|
|
296
|
+
main().catch((error) => {
|
|
297
|
+
console.error('Fatal error starting MCP server:', error);
|
|
298
|
+
process.exit(1);
|
|
299
|
+
});
|
|
300
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAEA;;;;;;;;;GASG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AACnE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EACL,qBAAqB,EACrB,sBAAsB,GAEvB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,KAAwB,MAAM,OAAO,CAAC;AAC7C,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAC;AACjC,OAAO,EAAE,qBAAqB,EAAE,MAAM,gCAAgC,CAAC;AACvE,OAAO,EAAE,0BAA0B,EAAE,MAAM,oCAAoC,CAAC;AAEhF,6BAA6B;AAC7B,MAAM,CAAC,MAAM,EAAE,CAAC;AAEhB,gBAAgB;AAChB,MAAM,YAAY,GAAG,OAAO,CAAC,GAAG,CAAC,yBAAyB,IAAI,uBAAuB,CAAC;AACtF,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,yBAAyB,IAAI,EAAE,CAAC;AAE5D;;GAEG;AACH,MAAM,sBAAsB;IAClB,MAAM,CAAgB;IAE9B,YAAY,OAAe,EAAE,MAAe;QAC1C,I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C,MAAM,SAAS,GAAG,IAAI,oBAAoB,EAAE,CAAC;IAC7C,MAAM,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IAEhC,OAAO,CAAC,KAAK,CAAC,+CAA+C,CAAC,CAAC;AACjE,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;IACrB,OAAO,CAAC,KAAK,CAAC,kCAAkC,EAAE,KAAK,CAAC,CAAC;IACzD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JavaScript/TypeScript complexity analyzer
|
|
3
|
+
* Uses TypeScript compiler to transpile TS to JS, then escomplex for analysis
|
|
4
|
+
* Falls back to regex-based analysis if escomplex fails
|
|
5
|
+
* No Python dependencies required!
|
|
6
|
+
*/
|
|
7
|
+
import { ComplexityResult } from '../types.js';
|
|
8
|
+
export declare class JavaScriptAnalyzer {
|
|
9
|
+
private threshold;
|
|
10
|
+
private escomplexLoaded;
|
|
11
|
+
constructor(threshold?: number);
|
|
12
|
+
/**
|
|
13
|
+
* Lazy load escomplex module
|
|
14
|
+
*/
|
|
15
|
+
private loadEscomplex;
|
|
16
|
+
/**
|
|
17
|
+
* Analyze JavaScript/TypeScript file complexity using escomplex
|
|
18
|
+
*/
|
|
19
|
+
analyzeFile(filePath: string): Promise<ComplexityResult[]>;
|
|
20
|
+
/**
|
|
21
|
+
* Transpile TypeScript to JavaScript using TypeScript compiler
|
|
22
|
+
* This properly removes all type annotations, interfaces, and type-only imports
|
|
23
|
+
* Output is ES5 CommonJS format for escomplex compatibility
|
|
24
|
+
*/
|
|
25
|
+
private transpileTypeScript;
|
|
26
|
+
/**
|
|
27
|
+
* Fallback analyzer using simple pattern matching
|
|
28
|
+
* Used when escomplex is not available or fails
|
|
29
|
+
*/
|
|
30
|
+
private analyzeFallback;
|
|
31
|
+
/**
|
|
32
|
+
* Determine risk level based on complexity score
|
|
33
|
+
*/
|
|
34
|
+
private getRiskLevel;
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=javascript-analyzer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"javascript-analyzer.d.ts","sourceRoot":"","sources":["../../../../src/tools/code-analyzer/analyzers/javascript-analyzer.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAK/C,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,eAAe,CAAkB;gBAE7B,SAAS,GAAE,MAAW;IAIlC;;OAEG;YACW,aAAa;IAgB3B;;OAEG;IACG,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,EAAE,CAAC;IAuEhE;;;;OAIG;IACH,OAAO,CAAC,mBAAmB;IAmB3B;;;OAGG;YACW,eAAe;IA8G7B;;OAEG;IACH,OAAO,CAAC,YAAY;CAMrB"}
|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JavaScript/TypeScript complexity analyzer
|
|
3
|
+
* Uses TypeScript compiler to transpile TS to JS, then escomplex for analysis
|
|
4
|
+
* Falls back to regex-based analysis if escomplex fails
|
|
5
|
+
* No Python dependencies required!
|
|
6
|
+
*/
|
|
7
|
+
import * as path from 'path';
|
|
8
|
+
import * as fs from 'fs-extra';
|
|
9
|
+
import * as ts from 'typescript';
|
|
10
|
+
// Dynamic import for escomplex (CommonJS module)
|
|
11
|
+
let escomplex = null;
|
|
12
|
+
export class JavaScriptAnalyzer {
|
|
13
|
+
threshold;
|
|
14
|
+
escomplexLoaded = false;
|
|
15
|
+
constructor(threshold = 10) {
|
|
16
|
+
this.threshold = threshold;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Lazy load escomplex module
|
|
20
|
+
*/
|
|
21
|
+
async loadEscomplex() {
|
|
22
|
+
if (this.escomplexLoaded)
|
|
23
|
+
return escomplex !== null;
|
|
24
|
+
try {
|
|
25
|
+
// Dynamic import for CommonJS module
|
|
26
|
+
const module = await import('escomplex');
|
|
27
|
+
escomplex = module.default || module;
|
|
28
|
+
this.escomplexLoaded = true;
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
console.warn('⚠️ escomplex not available, using fallback analyzer');
|
|
33
|
+
this.escomplexLoaded = true;
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Analyze JavaScript/TypeScript file complexity using escomplex
|
|
39
|
+
*/
|
|
40
|
+
async analyzeFile(filePath) {
|
|
41
|
+
const hasEscomplex = await this.loadEscomplex();
|
|
42
|
+
if (!hasEscomplex) {
|
|
43
|
+
return this.analyzeFallback(filePath);
|
|
44
|
+
}
|
|
45
|
+
try {
|
|
46
|
+
const content = await fs.readFile(filePath, 'utf-8');
|
|
47
|
+
const ext = path.extname(filePath).toLowerCase();
|
|
48
|
+
// For TypeScript, use TypeScript compiler to transpile to JavaScript
|
|
49
|
+
let codeToAnalyze = content;
|
|
50
|
+
if (ext === '.ts' || ext === '.tsx') {
|
|
51
|
+
codeToAnalyze = this.transpileTypeScript(content, ext === '.tsx');
|
|
52
|
+
}
|
|
53
|
+
// Analyze with escomplex
|
|
54
|
+
const report = escomplex.analyse(codeToAnalyze, {
|
|
55
|
+
loc: true,
|
|
56
|
+
newmi: true,
|
|
57
|
+
});
|
|
58
|
+
const results = [];
|
|
59
|
+
// TypeScript helper function names to filter out (generated by transpilation)
|
|
60
|
+
const tsHelpers = new Set([
|
|
61
|
+
'__extends', '__assign', '__rest', '__decorate', '__param', '__metadata',
|
|
62
|
+
'__awaiter', '__generator', '__createBinding', '__exportStar', '__values',
|
|
63
|
+
'__read', '__spread', '__spreadArrays', '__spreadArray', '__await',
|
|
64
|
+
'__asyncGenerator', '__asyncDelegator', '__asyncValues', '__makeTemplateObject',
|
|
65
|
+
'__importStar', '__importDefault', '__classPrivateFieldGet', '__classPrivateFieldSet',
|
|
66
|
+
'__classPrivateFieldIn', 'anonymous', '<anonymous>'
|
|
67
|
+
]);
|
|
68
|
+
// Extract function-level metrics, filtering out TS helpers
|
|
69
|
+
for (const func of report.functions || []) {
|
|
70
|
+
const funcName = func.name || 'anonymous';
|
|
71
|
+
// Skip TypeScript helper functions
|
|
72
|
+
if (tsHelpers.has(funcName))
|
|
73
|
+
continue;
|
|
74
|
+
results.push({
|
|
75
|
+
file: filePath,
|
|
76
|
+
function: funcName,
|
|
77
|
+
line: func.line || 1,
|
|
78
|
+
complexity: func.cyclomatic || 1,
|
|
79
|
+
risk_level: this.getRiskLevel(func.cyclomatic || 1),
|
|
80
|
+
loc: func.sloc?.logical || 0,
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
// If no functions found but module has complexity, add module-level entry
|
|
84
|
+
if (results.length === 0 && report.aggregate) {
|
|
85
|
+
results.push({
|
|
86
|
+
file: filePath,
|
|
87
|
+
function: '<module>',
|
|
88
|
+
line: 1,
|
|
89
|
+
complexity: report.aggregate.cyclomatic || 1,
|
|
90
|
+
risk_level: this.getRiskLevel(report.aggregate.cyclomatic || 1),
|
|
91
|
+
loc: report.aggregate.sloc?.logical || 0,
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
return results;
|
|
95
|
+
}
|
|
96
|
+
catch (error) {
|
|
97
|
+
console.error(`escomplex analysis failed for ${filePath}:`, error.message);
|
|
98
|
+
return this.analyzeFallback(filePath);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Transpile TypeScript to JavaScript using TypeScript compiler
|
|
103
|
+
* This properly removes all type annotations, interfaces, and type-only imports
|
|
104
|
+
* Output is ES5 CommonJS format for escomplex compatibility
|
|
105
|
+
*/
|
|
106
|
+
transpileTypeScript(code, isJsx = false) {
|
|
107
|
+
try {
|
|
108
|
+
const result = ts.transpileModule(code, {
|
|
109
|
+
compilerOptions: {
|
|
110
|
+
module: ts.ModuleKind.CommonJS,
|
|
111
|
+
target: ts.ScriptTarget.ES5, // ES5 for escomplex compatibility
|
|
112
|
+
jsx: isJsx ? ts.JsxEmit.React : undefined,
|
|
113
|
+
removeComments: false, // Keep comments for line number accuracy
|
|
114
|
+
esModuleInterop: true,
|
|
115
|
+
downlevelIteration: true,
|
|
116
|
+
},
|
|
117
|
+
});
|
|
118
|
+
return result.outputText;
|
|
119
|
+
}
|
|
120
|
+
catch (error) {
|
|
121
|
+
console.warn('TypeScript transpilation failed, using original code');
|
|
122
|
+
return code;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Fallback analyzer using simple pattern matching
|
|
127
|
+
* Used when escomplex is not available or fails
|
|
128
|
+
*/
|
|
129
|
+
async analyzeFallback(filePath) {
|
|
130
|
+
try {
|
|
131
|
+
const content = await fs.readFile(filePath, 'utf-8');
|
|
132
|
+
const lines = content.split('\n');
|
|
133
|
+
const results = [];
|
|
134
|
+
let currentFunction = '';
|
|
135
|
+
let functionLine = 0;
|
|
136
|
+
let complexity = 1;
|
|
137
|
+
let braceDepth = 0;
|
|
138
|
+
let inFunction = false;
|
|
139
|
+
for (let i = 0; i < lines.length; i++) {
|
|
140
|
+
const line = lines[i].trim();
|
|
141
|
+
// Skip comments
|
|
142
|
+
if (line.startsWith('//') || line.startsWith('*') || line.startsWith('/*')) {
|
|
143
|
+
continue;
|
|
144
|
+
}
|
|
145
|
+
// Detect function definition
|
|
146
|
+
const funcMatch = line.match(/(?:async\s+)?(?:function\s+(\w+)|(?:const|let|var)\s+(\w+)\s*=\s*(?:async\s+)?(?:function|\([^)]*\)\s*=>)|(\w+)\s*\([^)]*\)\s*(?::\s*\w+)?\s*{)/);
|
|
147
|
+
if (funcMatch && !line.includes('//')) {
|
|
148
|
+
// Save previous function if exists
|
|
149
|
+
if (currentFunction && inFunction) {
|
|
150
|
+
results.push({
|
|
151
|
+
file: filePath,
|
|
152
|
+
function: currentFunction,
|
|
153
|
+
line: functionLine,
|
|
154
|
+
complexity: complexity,
|
|
155
|
+
risk_level: this.getRiskLevel(complexity),
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
// Start new function
|
|
159
|
+
currentFunction = funcMatch[1] || funcMatch[2] || funcMatch[3] || 'anonymous';
|
|
160
|
+
functionLine = i + 1;
|
|
161
|
+
complexity = 1;
|
|
162
|
+
braceDepth = 0;
|
|
163
|
+
inFunction = true;
|
|
164
|
+
}
|
|
165
|
+
if (inFunction) {
|
|
166
|
+
// Track braces
|
|
167
|
+
const openBraces = (line.match(/{/g) || []).length;
|
|
168
|
+
const closeBraces = (line.match(/}/g) || []).length;
|
|
169
|
+
braceDepth += openBraces - closeBraces;
|
|
170
|
+
// Count complexity indicators
|
|
171
|
+
if (!line.startsWith('//')) {
|
|
172
|
+
// Conditionals
|
|
173
|
+
if (/\bif\s*\(/.test(line))
|
|
174
|
+
complexity++;
|
|
175
|
+
if (/\belse\s+if\s*\(/.test(line))
|
|
176
|
+
complexity++;
|
|
177
|
+
// Loops
|
|
178
|
+
if (/\bfor\s*\(/.test(line))
|
|
179
|
+
complexity++;
|
|
180
|
+
if (/\bwhile\s*\(/.test(line))
|
|
181
|
+
complexity++;
|
|
182
|
+
if (/\bdo\s*{/.test(line))
|
|
183
|
+
complexity++;
|
|
184
|
+
// Logical operators (each adds a path)
|
|
185
|
+
complexity += (line.match(/&&/g) || []).length;
|
|
186
|
+
complexity += (line.match(/\|\|/g) || []).length;
|
|
187
|
+
complexity += (line.match(/\?\?/g) || []).length;
|
|
188
|
+
// Switch cases
|
|
189
|
+
if (/\bcase\s+/.test(line))
|
|
190
|
+
complexity++;
|
|
191
|
+
// Exception handling
|
|
192
|
+
if (/\bcatch\s*\(/.test(line))
|
|
193
|
+
complexity++;
|
|
194
|
+
// Ternary operators
|
|
195
|
+
complexity += (line.match(/\?[^?:]*:/g) || []).length;
|
|
196
|
+
}
|
|
197
|
+
// End of function
|
|
198
|
+
if (braceDepth <= 0 && currentFunction && closeBraces > 0) {
|
|
199
|
+
results.push({
|
|
200
|
+
file: filePath,
|
|
201
|
+
function: currentFunction,
|
|
202
|
+
line: functionLine,
|
|
203
|
+
complexity: complexity,
|
|
204
|
+
risk_level: this.getRiskLevel(complexity),
|
|
205
|
+
});
|
|
206
|
+
currentFunction = '';
|
|
207
|
+
inFunction = false;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
// Save last function if still open
|
|
212
|
+
if (currentFunction && inFunction) {
|
|
213
|
+
results.push({
|
|
214
|
+
file: filePath,
|
|
215
|
+
function: currentFunction,
|
|
216
|
+
line: functionLine,
|
|
217
|
+
complexity: complexity,
|
|
218
|
+
risk_level: this.getRiskLevel(complexity),
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
return results;
|
|
222
|
+
}
|
|
223
|
+
catch (error) {
|
|
224
|
+
console.error(`Fallback analysis failed for ${filePath}:`, error);
|
|
225
|
+
return [];
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Determine risk level based on complexity score
|
|
230
|
+
*/
|
|
231
|
+
getRiskLevel(complexity) {
|
|
232
|
+
if (complexity < 5)
|
|
233
|
+
return 'low';
|
|
234
|
+
if (complexity < this.threshold)
|
|
235
|
+
return 'medium';
|
|
236
|
+
if (complexity < this.threshold * 2)
|
|
237
|
+
return 'high';
|
|
238
|
+
return 'very_high';
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
//# sourceMappingURL=javascript-analyzer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"javascript-analyzer.js","sourceRoot":"","sources":["../../../../src/tools/code-analyzer/analyzers/javascript-analyzer.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,KAAK,EAAE,M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AAQ,EAAE,eAAe;oBACzB,IAAI,EAAE,YAAY;oBAClB,UAAU,EAAE,UAAU;oBACtB,UAAU,EAAE,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC;iBAC1C,CAAC,CAAC;YACL,CAAC;YAED,OAAO,OAAO,CAAC;QACjB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,KAAK,CAAC,gCAAgC,QAAQ,GAAG,EAAE,KAAK,CAAC,CAAC;YAClE,OAAO,EAAE,CAAC;QACZ,CAAC;IACH,CAAC;IAED;;OAEG;IACK,YAAY,CAAC,UAAkB;QACrC,IAAI,UAAU,GAAG,CAAC;YAAE,OAAO,KAAK,CAAC;QACjC,IAAI,UAAU,GAAG,IAAI,CAAC,SAAS;YAAE,OAAO,QAAQ,CAAC;QACjD,IAAI,UAAU,GAAG,IAAI,CAAC,SAAS,GAAG,CAAC;YAAE,OAAO,MAAM,CAAC;QACnD,OAAO,WAAW,CAAC;IACrB,CAAC;CACF"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Python code complexity analyzer using radon
|
|
3
|
+
*/
|
|
4
|
+
import { ComplexityResult } from '../types.js';
|
|
5
|
+
export declare class PythonAnalyzer {
|
|
6
|
+
private threshold;
|
|
7
|
+
constructor(threshold?: number);
|
|
8
|
+
/**
|
|
9
|
+
* Check if radon is installed
|
|
10
|
+
*/
|
|
11
|
+
isRadonInstalled(): Promise<boolean>;
|
|
12
|
+
/**
|
|
13
|
+
* Analyze Python file complexity
|
|
14
|
+
*/
|
|
15
|
+
analyzeFile(filePath: string): Promise<ComplexityResult[]>;
|
|
16
|
+
/**
|
|
17
|
+
* Fallback analyzer using simple regex patterns
|
|
18
|
+
* Not as accurate but doesn't require external tools
|
|
19
|
+
*/
|
|
20
|
+
private analyzeFallback;
|
|
21
|
+
/**
|
|
22
|
+
* Determine risk level based on complexity score
|
|
23
|
+
*/
|
|
24
|
+
private getRiskLevel;
|
|
25
|
+
/**
|
|
26
|
+
* Get installation instructions for radon
|
|
27
|
+
*/
|
|
28
|
+
getInstallInstructions(): string;
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=python-analyzer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"python-analyzer.d.ts","sourceRoot":"","sources":["../../../../src/tools/code-analyzer/analyzers/python-analyzer.ts"],"names":[],"mappings":"AAAA;;GAEG;AAKH,OAAO,EAAE,gBAAgB,EAAuB,MAAM,aAAa,CAAC;AAIpE,qBAAa,cAAc;IACzB,OAAO,CAAC,SAAS,CAAS;gBAEd,SAAS,GAAE,MAAW;IAIlC;;OAEG;IACG,gBAAgB,IAAI,OAAO,CAAC,OAAO,CAAC;IAS1C;;OAEG;IACG,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,EAAE,CAAC;IAqChE;;;OAGG;YACW,eAAe;IA6D7B;;OAEG;IACH,OAAO,CAAC,YAAY;IAOpB;;OAEG;IACH,sBAAsB,IAAI,MAAM;CAMjC"}
|