@tng-sh/mcp-server 1.0.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 +461 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +189 -0
- package/dist/index.js.map +1 -0
- package/dist/init.d.ts +2 -0
- package/dist/init.d.ts.map +1 -0
- package/dist/init.js +113 -0
- package/dist/init.js.map +1 -0
- package/dist/tools/audit.d.ts +21 -0
- package/dist/tools/audit.d.ts.map +1 -0
- package/dist/tools/audit.js +204 -0
- package/dist/tools/audit.js.map +1 -0
- package/dist/tools/clones.d.ts +20 -0
- package/dist/tools/clones.d.ts.map +1 -0
- package/dist/tools/clones.js +202 -0
- package/dist/tools/clones.js.map +1 -0
- package/dist/tools/config.d.ts +30 -0
- package/dist/tools/config.d.ts.map +1 -0
- package/dist/tools/config.js +51 -0
- package/dist/tools/config.js.map +1 -0
- package/dist/tools/deadcode.d.ts +19 -0
- package/dist/tools/deadcode.d.ts.map +1 -0
- package/dist/tools/deadcode.js +223 -0
- package/dist/tools/deadcode.js.map +1 -0
- package/dist/tools/generate.d.ts +21 -0
- package/dist/tools/generate.d.ts.map +1 -0
- package/dist/tools/generate.js +186 -0
- package/dist/tools/generate.js.map +1 -0
- package/dist/tools/list.d.ts +18 -0
- package/dist/tools/list.d.ts.map +1 -0
- package/dist/tools/list.js +147 -0
- package/dist/tools/list.js.map +1 -0
- package/dist/tools/trace.d.ts +20 -0
- package/dist/tools/trace.d.ts.map +1 -0
- package/dist/tools/trace.js +194 -0
- package/dist/tools/trace.js.map +1 -0
- package/dist/tools/utils.d.ts +19 -0
- package/dist/tools/utils.d.ts.map +1 -0
- package/dist/tools/utils.js +143 -0
- package/dist/tools/utils.js.map +1 -0
- package/dist/tools/xray.d.ts +20 -0
- package/dist/tools/xray.d.ts.map +1 -0
- package/dist/tools/xray.js +187 -0
- package/dist/tools/xray.js.map +1 -0
- package/package.json +44 -0
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from 'fs';
|
|
2
|
+
import { join } from 'path';
|
|
3
|
+
import { homedir } from 'os';
|
|
4
|
+
let configCache = null;
|
|
5
|
+
/**
|
|
6
|
+
* Load TNG configuration from the user's config file.
|
|
7
|
+
* Looks for config in:
|
|
8
|
+
* 1. ~/.config/tng-mcp/config.json
|
|
9
|
+
* 2. ~/.tng-mcp.json
|
|
10
|
+
*/
|
|
11
|
+
export function loadConfig() {
|
|
12
|
+
if (configCache)
|
|
13
|
+
return configCache;
|
|
14
|
+
const configPaths = [
|
|
15
|
+
join(homedir(), '.config', 'tng-mcp', 'config.json'),
|
|
16
|
+
join(homedir(), '.tng-mcp.json'),
|
|
17
|
+
];
|
|
18
|
+
for (const configPath of configPaths) {
|
|
19
|
+
if (existsSync(configPath)) {
|
|
20
|
+
try {
|
|
21
|
+
const content = readFileSync(configPath, 'utf-8');
|
|
22
|
+
configCache = JSON.parse(content);
|
|
23
|
+
console.error(`[TNG MCP] Loaded config from ${configPath}`);
|
|
24
|
+
return configCache;
|
|
25
|
+
}
|
|
26
|
+
catch (e) {
|
|
27
|
+
console.error(`[TNG MCP] Failed to parse config at ${configPath}:`, e);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
// No config file found, return empty config
|
|
32
|
+
configCache = {};
|
|
33
|
+
return configCache;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Get the configured command for a specific language.
|
|
37
|
+
* Returns undefined if not configured.
|
|
38
|
+
*/
|
|
39
|
+
export function getConfiguredCommand(language) {
|
|
40
|
+
const config = loadConfig();
|
|
41
|
+
return config[language]?.command;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Get custom environment variables from config.
|
|
45
|
+
* These will be merged with process.env when running commands.
|
|
46
|
+
*/
|
|
47
|
+
export function getConfiguredEnv() {
|
|
48
|
+
const config = loadConfig();
|
|
49
|
+
return config.env || {};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EAAE,CAAC;IAC5B,OAAO,MAAM,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC;AACrC,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,gBAAgB;IAC5B,MAAM,MAAM,GAAG,UAAU,EAAE,CAAC;IAC5B,OAAO,MAAM,CAAC,GAAG,IAAI,EAAE,CAAC;AAC5B,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
interface DeadCodeArgs {
|
|
2
|
+
file_path: string;
|
|
3
|
+
project_root?: string;
|
|
4
|
+
}
|
|
5
|
+
export declare function detectDeadCode(args: DeadCodeArgs): Promise<{
|
|
6
|
+
content: {
|
|
7
|
+
type: "text";
|
|
8
|
+
text: string;
|
|
9
|
+
}[];
|
|
10
|
+
isError: boolean;
|
|
11
|
+
} | {
|
|
12
|
+
content: {
|
|
13
|
+
type: "text";
|
|
14
|
+
text: string;
|
|
15
|
+
}[];
|
|
16
|
+
isError?: undefined;
|
|
17
|
+
}>;
|
|
18
|
+
export {};
|
|
19
|
+
//# sourceMappingURL=deadcode.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deadcode.d.ts","sourceRoot":"","sources":["../../src/tools/deadcode.ts"],"names":[],"mappings":"AAQA,UAAU,YAAY;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,wBAAsB,cAAc,CAAC,IAAI,EAAE,YAAY;;;;;;;;;;;;GA0ItD"}
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
import { exec, execFile } from 'child_process';
|
|
2
|
+
import { promisify } from 'util';
|
|
3
|
+
import { resolve } from 'path';
|
|
4
|
+
import { findProjectRoot, getTngCommandConfig, getShellEnv, shellEscape } from './utils.js';
|
|
5
|
+
const execAsync = promisify(exec);
|
|
6
|
+
const execFileAsync = promisify(execFile);
|
|
7
|
+
export async function detectDeadCode(args) {
|
|
8
|
+
const { file_path, project_root } = args;
|
|
9
|
+
try {
|
|
10
|
+
const absoluteFilePath = resolve(file_path);
|
|
11
|
+
const cwd = project_root || findProjectRoot(absoluteFilePath) || process.cwd();
|
|
12
|
+
const tngCommand = getTngCommandConfig(cwd, file_path);
|
|
13
|
+
// Build dead code command with JSON output
|
|
14
|
+
const baseArgs = ['--deadcode', '--json', '-f', file_path];
|
|
15
|
+
const command = tngCommand.shell
|
|
16
|
+
? `${tngCommand.cmd} ${baseArgs.map(shellEscape).join(' ')}`
|
|
17
|
+
: `${tngCommand.cmd} ${[...tngCommand.args, ...baseArgs].map(shellEscape).join(' ')}`;
|
|
18
|
+
console.error(`[TNG MCP] Running: ${command}`);
|
|
19
|
+
console.error(`[TNG MCP] CWD: ${cwd}`);
|
|
20
|
+
const { stdout, stderr } = tngCommand.shell
|
|
21
|
+
? await execAsync(command, {
|
|
22
|
+
cwd,
|
|
23
|
+
env: getShellEnv(),
|
|
24
|
+
timeout: 600000,
|
|
25
|
+
maxBuffer: 10 * 1024 * 1024,
|
|
26
|
+
})
|
|
27
|
+
: await execFileAsync(tngCommand.cmd, [...tngCommand.args, ...baseArgs], {
|
|
28
|
+
cwd,
|
|
29
|
+
env: getShellEnv(),
|
|
30
|
+
timeout: 600000,
|
|
31
|
+
maxBuffer: 10 * 1024 * 1024,
|
|
32
|
+
});
|
|
33
|
+
if (stderr && !stderr.includes('TNG')) {
|
|
34
|
+
console.error('[TNG MCP] stderr:', stderr);
|
|
35
|
+
}
|
|
36
|
+
// Parse JSON output
|
|
37
|
+
const lines = stdout.trim().split('\n');
|
|
38
|
+
let result = null;
|
|
39
|
+
for (const line of lines) {
|
|
40
|
+
if (!line.trim())
|
|
41
|
+
continue;
|
|
42
|
+
try {
|
|
43
|
+
const event = JSON.parse(line);
|
|
44
|
+
if (event.type === 'result' || event.type === 'dead_code' || event.dead_code || event.unused || event.issues || Array.isArray(event)) {
|
|
45
|
+
result = event;
|
|
46
|
+
break;
|
|
47
|
+
}
|
|
48
|
+
if (event.type === 'error' || event.type === 'auth_error') {
|
|
49
|
+
throw new Error(event.message || 'Dead code detection failed');
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
catch (e) {
|
|
53
|
+
// Try parsing as single JSON
|
|
54
|
+
if (line.includes('{') && (line.includes('"dead_code"') ||
|
|
55
|
+
line.includes('"unused"') ||
|
|
56
|
+
line.includes('"issue_type"') ||
|
|
57
|
+
line.includes('"issues"') ||
|
|
58
|
+
(line.startsWith('[') && line.includes('"type"')))) {
|
|
59
|
+
result = JSON.parse(line);
|
|
60
|
+
break;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
if (!result) {
|
|
65
|
+
return {
|
|
66
|
+
content: [
|
|
67
|
+
{
|
|
68
|
+
type: 'text',
|
|
69
|
+
text: `No dead code detection results returned. Raw output:\n${stdout.substring(0, 500)}`,
|
|
70
|
+
},
|
|
71
|
+
],
|
|
72
|
+
isError: true,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
const formattedOutput = formatDeadCodeResult(result, file_path);
|
|
76
|
+
return {
|
|
77
|
+
content: [
|
|
78
|
+
{
|
|
79
|
+
type: 'text',
|
|
80
|
+
text: formattedOutput,
|
|
81
|
+
},
|
|
82
|
+
],
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
catch (error) {
|
|
86
|
+
if (error.code === 'ENOENT') {
|
|
87
|
+
return {
|
|
88
|
+
content: [
|
|
89
|
+
{
|
|
90
|
+
type: 'text',
|
|
91
|
+
text: `Error: TNG CLI not found in project. Please install TNG first.`,
|
|
92
|
+
},
|
|
93
|
+
],
|
|
94
|
+
isError: true,
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
if (error.killed) {
|
|
98
|
+
return {
|
|
99
|
+
content: [
|
|
100
|
+
{
|
|
101
|
+
type: 'text',
|
|
102
|
+
text: `Error: Dead code detection timed out after 3 minutes.`,
|
|
103
|
+
},
|
|
104
|
+
],
|
|
105
|
+
isError: true,
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
let errorMessage = error.message;
|
|
109
|
+
try {
|
|
110
|
+
const errorOutput = error.stdout || error.stderr || '';
|
|
111
|
+
const lines = errorOutput.split('\n');
|
|
112
|
+
for (const line of lines) {
|
|
113
|
+
if (!line.trim())
|
|
114
|
+
continue;
|
|
115
|
+
try {
|
|
116
|
+
const event = JSON.parse(line);
|
|
117
|
+
if (event.type === 'error' || event.type === 'auth_error') {
|
|
118
|
+
errorMessage = event.message || errorMessage;
|
|
119
|
+
break;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
catch { }
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
catch { }
|
|
126
|
+
return {
|
|
127
|
+
content: [
|
|
128
|
+
{
|
|
129
|
+
type: 'text',
|
|
130
|
+
text: `Error detecting dead code in ${file_path}: ${errorMessage}`,
|
|
131
|
+
},
|
|
132
|
+
],
|
|
133
|
+
isError: true,
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
function formatDeadCodeResult(result, filePath) {
|
|
138
|
+
let findings = [];
|
|
139
|
+
// Extract findings from various possible formats
|
|
140
|
+
if (Array.isArray(result.dead_code)) {
|
|
141
|
+
findings = result.dead_code;
|
|
142
|
+
}
|
|
143
|
+
else if (Array.isArray(result.unused)) {
|
|
144
|
+
findings = result.unused;
|
|
145
|
+
}
|
|
146
|
+
else if (Array.isArray(result.findings)) {
|
|
147
|
+
findings = result.findings;
|
|
148
|
+
}
|
|
149
|
+
else if (Array.isArray(result.issues)) {
|
|
150
|
+
findings = result.issues;
|
|
151
|
+
}
|
|
152
|
+
else if (Array.isArray(result)) {
|
|
153
|
+
findings = result;
|
|
154
|
+
}
|
|
155
|
+
else if (Array.isArray(result.dead_code)) {
|
|
156
|
+
findings = result.dead_code;
|
|
157
|
+
}
|
|
158
|
+
else if (result.type === 'dead_code') {
|
|
159
|
+
// Handle JS format: {"0": {...}, "1": {...}, "type": "dead_code"}
|
|
160
|
+
findings = Object.entries(result)
|
|
161
|
+
.filter(([key]) => !isNaN(Number(key)))
|
|
162
|
+
.map(([_, value]) => value);
|
|
163
|
+
}
|
|
164
|
+
const summary = result.summary || {};
|
|
165
|
+
let output = `# Dead Code Analysis for ${filePath}\n\n`;
|
|
166
|
+
// Show summary if available
|
|
167
|
+
if (summary.total_issues !== undefined) {
|
|
168
|
+
output += `## Summary\n\n`;
|
|
169
|
+
output += `- **Total Issues:** ${summary.total_issues || 0}\n`;
|
|
170
|
+
if (summary.unused_imports !== undefined)
|
|
171
|
+
output += `- **Unused Imports:** ${summary.unused_imports}\n`;
|
|
172
|
+
if (summary.unused_variables !== undefined)
|
|
173
|
+
output += `- **Unused Variables:** ${summary.unused_variables}\n`;
|
|
174
|
+
if (summary.unused_functions !== undefined)
|
|
175
|
+
output += `- **Unused Functions:** ${summary.unused_functions}\n`;
|
|
176
|
+
if (summary.unreachable_code !== undefined)
|
|
177
|
+
output += `- **Unreachable Code:** ${summary.unreachable_code}\n`;
|
|
178
|
+
output += '\n';
|
|
179
|
+
}
|
|
180
|
+
if (findings.length === 0) {
|
|
181
|
+
output += `## ✅ No Dead Code Found\n\n`;
|
|
182
|
+
output += `Great! This file has no detected unused imports, variables, functions, or unreachable code.\n`;
|
|
183
|
+
return output;
|
|
184
|
+
}
|
|
185
|
+
// Group by category
|
|
186
|
+
const byCategory = {};
|
|
187
|
+
findings.forEach((issue) => {
|
|
188
|
+
const category = issue.category || issue.issue_type || issue.type || 'Other';
|
|
189
|
+
// Normalize category name (e.g. "unused_variable" -> "Unused Variables")
|
|
190
|
+
const normalizedCategory = category
|
|
191
|
+
.split('_')
|
|
192
|
+
.map((word) => word.charAt(0).toUpperCase() + word.slice(1))
|
|
193
|
+
.join(' ') + (category.includes('unused') ? 's' : '');
|
|
194
|
+
if (!byCategory[normalizedCategory]) {
|
|
195
|
+
byCategory[normalizedCategory] = [];
|
|
196
|
+
}
|
|
197
|
+
byCategory[normalizedCategory].push(issue);
|
|
198
|
+
});
|
|
199
|
+
output += `## Issues Found (${findings.length})\n\n`;
|
|
200
|
+
// Display each category
|
|
201
|
+
Object.keys(byCategory).sort().forEach((category) => {
|
|
202
|
+
const issues = byCategory[category];
|
|
203
|
+
output += `### ${category} (${issues.length})\n\n`;
|
|
204
|
+
issues.forEach((issue, index) => {
|
|
205
|
+
const name = issue.name || issue.identifier || issue.code_snippet || issue.code || 'Unknown';
|
|
206
|
+
const location = issue.location || issue.line || issue.line_number || '';
|
|
207
|
+
const description = issue.description || issue.message || '';
|
|
208
|
+
const suggestion = issue.suggestion || issue.fix || '';
|
|
209
|
+
output += `${index + 1}. **${name}**\n`;
|
|
210
|
+
if (location)
|
|
211
|
+
output += ` - **Location:** Line ${location}\n`;
|
|
212
|
+
if (description)
|
|
213
|
+
output += ` - **Issue:** ${description}\n`;
|
|
214
|
+
if (suggestion)
|
|
215
|
+
output += ` - **Suggestion:** ${suggestion}\n`;
|
|
216
|
+
output += '\n';
|
|
217
|
+
});
|
|
218
|
+
});
|
|
219
|
+
output += `---\n\n`;
|
|
220
|
+
output += `> **Recommendation:** Remove unused code to improve maintainability and reduce bundle size.\n`;
|
|
221
|
+
return output;
|
|
222
|
+
}
|
|
223
|
+
//# sourceMappingURL=deadcode.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deadcode.js","sourceRoot":"","sources":["../../src/tools/deadcode.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EAAE,SAAS,EAAE,MAAM,MAAM,CAAC;AACjC,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAC/B,OAAO,EAAE,eAAe,EAAE,mBAAmB,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE5F,MAAM,SAAS,GAAG,SAAS,CAAC,IAAI,CAAC,CAAC;AAClC,MAAM,aAAa,GAAG,SAAS,CAAC,QAAQ,CAAC,CAAC;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IAAI,+FAA+F,CAAC;IAE1G,OAAO,MAAM,CAAC;AAClB,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
interface GenerateTestArgs {
|
|
2
|
+
file_path: string;
|
|
3
|
+
method_name: string;
|
|
4
|
+
test_type?: string;
|
|
5
|
+
project_root?: string;
|
|
6
|
+
}
|
|
7
|
+
export declare function generateTest(args: GenerateTestArgs): Promise<{
|
|
8
|
+
content: {
|
|
9
|
+
type: "text";
|
|
10
|
+
text: string;
|
|
11
|
+
}[];
|
|
12
|
+
isError: boolean;
|
|
13
|
+
} | {
|
|
14
|
+
content: {
|
|
15
|
+
type: "text";
|
|
16
|
+
text: string;
|
|
17
|
+
}[];
|
|
18
|
+
isError?: undefined;
|
|
19
|
+
}>;
|
|
20
|
+
export {};
|
|
21
|
+
//# sourceMappingURL=generate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate.d.ts","sourceRoot":"","sources":["../../src/tools/generate.ts"],"names":[],"mappings":"AAQA,UAAU,gBAAgB;IACtB,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,YAAY,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,wBAAsB,YAAY,CAAC,IAAI,EAAE,gBAAgB;;;;;;;;;;;;GAwJxD"}
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import { exec, execFile } from 'child_process';
|
|
2
|
+
import { promisify } from 'util';
|
|
3
|
+
import { resolve } from 'path';
|
|
4
|
+
import { findProjectRoot, getTngCommandConfig, detectLanguage, getShellEnv, shellEscape } from './utils.js';
|
|
5
|
+
const execAsync = promisify(exec);
|
|
6
|
+
const execFileAsync = promisify(execFile);
|
|
7
|
+
export async function generateTest(args) {
|
|
8
|
+
const { file_path, method_name, test_type, project_root } = args;
|
|
9
|
+
try {
|
|
10
|
+
// Resolve to absolute path if relative
|
|
11
|
+
const absoluteFilePath = resolve(file_path);
|
|
12
|
+
const cwd = project_root || findProjectRoot(absoluteFilePath) || process.cwd();
|
|
13
|
+
const tngCommand = getTngCommandConfig(cwd, file_path);
|
|
14
|
+
const baseArgs = ['--json', '-f', file_path, '-m', method_name];
|
|
15
|
+
if (test_type) {
|
|
16
|
+
baseArgs.push('--type', test_type);
|
|
17
|
+
}
|
|
18
|
+
const command = tngCommand.shell
|
|
19
|
+
? `${tngCommand.cmd} ${baseArgs.map(shellEscape).join(' ')}`
|
|
20
|
+
: `${tngCommand.cmd} ${[...tngCommand.args, ...baseArgs].map(shellEscape).join(' ')}`;
|
|
21
|
+
console.error(`[TNG MCP] Running: ${command}`);
|
|
22
|
+
console.error(`[TNG MCP] CWD: ${cwd}`);
|
|
23
|
+
const { stdout, stderr } = tngCommand.shell
|
|
24
|
+
? await execAsync(command, {
|
|
25
|
+
cwd,
|
|
26
|
+
env: getShellEnv(),
|
|
27
|
+
timeout: 600000,
|
|
28
|
+
maxBuffer: 10 * 1024 * 1024,
|
|
29
|
+
})
|
|
30
|
+
: await execFileAsync(tngCommand.cmd, [...tngCommand.args, ...baseArgs], {
|
|
31
|
+
cwd,
|
|
32
|
+
env: getShellEnv(),
|
|
33
|
+
timeout: 600000,
|
|
34
|
+
maxBuffer: 10 * 1024 * 1024,
|
|
35
|
+
});
|
|
36
|
+
if (stderr && !stderr.includes('TNG')) {
|
|
37
|
+
console.error('[TNG MCP] stderr:', stderr);
|
|
38
|
+
}
|
|
39
|
+
const lines = stdout.trim().split('\n');
|
|
40
|
+
let result = null;
|
|
41
|
+
for (const line of lines) {
|
|
42
|
+
if (!line.trim())
|
|
43
|
+
continue;
|
|
44
|
+
try {
|
|
45
|
+
const event = JSON.parse(line);
|
|
46
|
+
if (event.type === 'result') {
|
|
47
|
+
result = event;
|
|
48
|
+
break;
|
|
49
|
+
}
|
|
50
|
+
if (event.type === 'error' || event.type === 'auth_error') {
|
|
51
|
+
throw new Error(event.message || 'Test generation failed');
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
catch (e) {
|
|
55
|
+
// Try parsing the whole output as single JSON (fallback)
|
|
56
|
+
if (line.includes('{') && (line.includes('file_path') || line.includes('test_code'))) {
|
|
57
|
+
result = JSON.parse(line);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
if (!result) {
|
|
62
|
+
return {
|
|
63
|
+
content: [
|
|
64
|
+
{
|
|
65
|
+
type: 'text',
|
|
66
|
+
text: `No test generation results returned. Raw output:\n${stdout.substring(0, 500)}`,
|
|
67
|
+
},
|
|
68
|
+
],
|
|
69
|
+
isError: true,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
// Format the response
|
|
73
|
+
const formattedOutput = formatGenerateTestResult(result);
|
|
74
|
+
return {
|
|
75
|
+
content: [
|
|
76
|
+
{
|
|
77
|
+
type: 'text',
|
|
78
|
+
text: formattedOutput,
|
|
79
|
+
},
|
|
80
|
+
],
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
catch (error) {
|
|
84
|
+
// Handle specific error cases
|
|
85
|
+
if (error.code === 'ENOENT') {
|
|
86
|
+
return {
|
|
87
|
+
content: [
|
|
88
|
+
{
|
|
89
|
+
type: 'text',
|
|
90
|
+
text: `Error: TNG CLI not found in project. Please install TNG first:
|
|
91
|
+
|
|
92
|
+
**For Ruby projects:**
|
|
93
|
+
\`gem install tng\` or add to Gemfile: \`gem 'tng'\`
|
|
94
|
+
|
|
95
|
+
**For Python projects:**
|
|
96
|
+
\`pip install tng-python\` or \`uv add tng-python\`
|
|
97
|
+
|
|
98
|
+
**For Node.js projects:**
|
|
99
|
+
\`npm install tng-js\`
|
|
100
|
+
|
|
101
|
+
Then configure your API key.`,
|
|
102
|
+
},
|
|
103
|
+
],
|
|
104
|
+
isError: true,
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
if (error.killed) {
|
|
108
|
+
return {
|
|
109
|
+
content: [
|
|
110
|
+
{
|
|
111
|
+
type: 'text',
|
|
112
|
+
text: `Error: Test generation timed out after 10 minutes.`,
|
|
113
|
+
},
|
|
114
|
+
],
|
|
115
|
+
isError: true,
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
// Extract error message
|
|
119
|
+
let errorMessage = error.message;
|
|
120
|
+
try {
|
|
121
|
+
const errorOutput = error.stdout || error.stderr || '';
|
|
122
|
+
const lines = errorOutput.split('\n');
|
|
123
|
+
for (const line of lines) {
|
|
124
|
+
if (!line.trim())
|
|
125
|
+
continue;
|
|
126
|
+
try {
|
|
127
|
+
const event = JSON.parse(line);
|
|
128
|
+
if (event.type === 'error' || event.type === 'auth_error') {
|
|
129
|
+
errorMessage = event.message || errorMessage;
|
|
130
|
+
break;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
catch { }
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
catch { }
|
|
137
|
+
return {
|
|
138
|
+
content: [
|
|
139
|
+
{
|
|
140
|
+
type: 'text',
|
|
141
|
+
text: `Error generating tests for ${file_path}#${method_name}: ${errorMessage}
|
|
142
|
+
|
|
143
|
+
Make sure TNG is properly installed and configured in your project.`,
|
|
144
|
+
},
|
|
145
|
+
],
|
|
146
|
+
isError: true,
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
function formatGenerateTestResult(result) {
|
|
151
|
+
if (!result) {
|
|
152
|
+
return 'No test generation results returned from TNG.';
|
|
153
|
+
}
|
|
154
|
+
let output = '';
|
|
155
|
+
// Show success message
|
|
156
|
+
if (result.file_path || result.absolute_path) {
|
|
157
|
+
output += `# ✅ Test Generated Successfully\n\n`;
|
|
158
|
+
output += `**Test File:** ${result.file_path || result.absolute_path}\n`;
|
|
159
|
+
if (result.run_command) {
|
|
160
|
+
output += `**Command to Run:** ${result.run_command}\n`;
|
|
161
|
+
}
|
|
162
|
+
if (result.test_count) {
|
|
163
|
+
output += `**Test Count:** ${result.test_count}\n`;
|
|
164
|
+
}
|
|
165
|
+
output += '\n';
|
|
166
|
+
}
|
|
167
|
+
// Include generated test code if available
|
|
168
|
+
if (result.test_code) {
|
|
169
|
+
output += `## Generated Test Code\n\n`;
|
|
170
|
+
output += `\`\`\`${detectLanguage(result.file_path || result.absolute_path || '')}\n`;
|
|
171
|
+
output += result.test_code;
|
|
172
|
+
output += `\n\`\`\`\n\n`;
|
|
173
|
+
}
|
|
174
|
+
// Show metadata if available
|
|
175
|
+
if (result.metadata) {
|
|
176
|
+
output += `## Test Metadata\n\n`;
|
|
177
|
+
if (result.metadata.test_type || result.metadata.framework) {
|
|
178
|
+
output += `- **Test Framework:** ${result.metadata.test_type || result.metadata.framework}\n`;
|
|
179
|
+
}
|
|
180
|
+
if (result.metadata.coverage) {
|
|
181
|
+
output += `- **Coverage Areas:** ${Array.isArray(result.metadata.coverage) ? result.metadata.coverage.join(', ') : result.metadata.coverage}\n`;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
return output || JSON.stringify(result, null, 2);
|
|
185
|
+
}
|
|
186
|
+
//# sourceMappingURL=generate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate.js","sourceRoot":"","sources":["../../src/tools/generate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EAAE,SAAS,EAAE,MAAM,MAAM,CAAC;AACjC,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAC/B,OAAO,EAAE,eAAe,EAAE,mBAAmB,EAAE,cAAc,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE5G,MAAM,SAAS,GAAG,SAAS,CAAC,IAAI,CAAC,CAAC;AAClC,MAAM,aAAa,GAAG,SAAS,CAAC,QAAQ,CAAC,CAAC;AAS1C,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,IAAsB;IACrD,MAAM,EAAE,SAAS,EAAE,WAAW,EAAE,SA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,IAAI,MAAM,CAAC,SAAS,EAAE,CAAC;QACnB,MAAM,IAAI,4BAA4B,CAAC;QACvC,MAAM,IAAI,SAAS,cAAc,CAAC,MAAM,CAAC,SAAS,IAAI,MAAM,CAAC,aAAa,IAAI,EAAE,CAAC,IAAI,CAAC;QACtF,MAAM,IAAI,MAAM,CAAC,SAAS,CAAC;QAC3B,MAAM,IAAI,cAAc,CAAC;IAC7B,CAAC;IAED,6BAA6B;IAC7B,IAAI,MAAM,CAAC,QAAQ,EAAE,CAAC;QAClB,MAAM,IAAI,sBAAsB,CAAC;QACjC,IAAI,MAAM,CAAC,QAAQ,CAAC,SAAS,IAAI,MAAM,CAAC,QAAQ,CAAC,SAAS,EAAE,CAAC;YACzD,MAAM,IAAI,yBAAyB,MAAM,CAAC,QAAQ,CAAC,SAAS,IAAI,MAAM,CAAC,QAAQ,CAAC,SAAS,IAAI,CAAC;QAClG,CAAC;QACD,IAAI,MAAM,CAAC,QAAQ,CAAC,QAAQ,EAAE,CAAC;YAC3B,MAAM,IAAI,yBAAyB,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,QAAQ,IAAI,CAAC;QACpJ,CAAC;IACL,CAAC;IAED,OAAO,MAAM,IAAI,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;AACrD,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
interface ListMethodsArgs {
|
|
2
|
+
file_path: string;
|
|
3
|
+
}
|
|
4
|
+
export declare function listMethods(args: ListMethodsArgs): Promise<{
|
|
5
|
+
content: {
|
|
6
|
+
type: string;
|
|
7
|
+
text: string;
|
|
8
|
+
}[];
|
|
9
|
+
isError?: undefined;
|
|
10
|
+
} | {
|
|
11
|
+
content: {
|
|
12
|
+
type: string;
|
|
13
|
+
text: string;
|
|
14
|
+
}[];
|
|
15
|
+
isError: boolean;
|
|
16
|
+
}>;
|
|
17
|
+
export {};
|
|
18
|
+
//# sourceMappingURL=list.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"list.d.ts","sourceRoot":"","sources":["../../src/tools/list.ts"],"names":[],"mappings":"AAMA,UAAU,eAAe;IACrB,SAAS,EAAE,MAAM,CAAC;CACrB;AAED,wBAAsB,WAAW,CAAC,IAAI,EAAE,eAAe;;;;;;;;;;;;GAsCtD"}
|