@reverse-craft/smart-fs 1.0.2 → 1.0.3
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/dist/server.js +816 -100
- package/dist/server.js.map +4 -4
- package/package.json +9 -1
package/dist/server.js
CHANGED
|
@@ -1,15 +1,25 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
3
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
4
|
+
}) : x)(function(x) {
|
|
5
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
6
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
7
|
+
});
|
|
2
8
|
|
|
3
9
|
// src/server.ts
|
|
4
|
-
import {
|
|
10
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
5
11
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
} from "@modelcontextprotocol/sdk/types.js";
|
|
12
|
+
import { z as z5 } from "zod";
|
|
13
|
+
|
|
14
|
+
// src/tools/readCodeSmart.ts
|
|
10
15
|
import { z } from "zod";
|
|
11
16
|
import { SourceMapConsumer } from "source-map-js";
|
|
12
17
|
|
|
18
|
+
// src/tools/ToolDefinition.ts
|
|
19
|
+
function defineTool(definition) {
|
|
20
|
+
return definition;
|
|
21
|
+
}
|
|
22
|
+
|
|
13
23
|
// src/beautifier.ts
|
|
14
24
|
import * as esbuild from "esbuild";
|
|
15
25
|
import * as crypto from "crypto";
|
|
@@ -30,6 +40,15 @@ function getCachePaths(originalPath, hash) {
|
|
|
30
40
|
const mapPath = `${beautifiedPath}.map`;
|
|
31
41
|
return { beautifiedPath, mapPath };
|
|
32
42
|
}
|
|
43
|
+
function getLocalPaths(originalPath) {
|
|
44
|
+
const absolutePath = path.resolve(originalPath);
|
|
45
|
+
const dir = path.dirname(absolutePath);
|
|
46
|
+
const ext = path.extname(absolutePath);
|
|
47
|
+
const baseName = path.basename(absolutePath, ext);
|
|
48
|
+
const beautifiedPath = path.join(dir, `${baseName}.beautified.js`);
|
|
49
|
+
const mapPath = `${beautifiedPath}.map`;
|
|
50
|
+
return { beautifiedPath, mapPath };
|
|
51
|
+
}
|
|
33
52
|
async function isCacheValid(beautifiedPath, mapPath) {
|
|
34
53
|
try {
|
|
35
54
|
await Promise.all([
|
|
@@ -41,14 +60,69 @@ async function isCacheValid(beautifiedPath, mapPath) {
|
|
|
41
60
|
return false;
|
|
42
61
|
}
|
|
43
62
|
}
|
|
44
|
-
async function
|
|
63
|
+
async function isLocalCacheValid(originalPath) {
|
|
45
64
|
const absolutePath = path.resolve(originalPath);
|
|
65
|
+
const { beautifiedPath } = getLocalPaths(absolutePath);
|
|
66
|
+
let originalStats;
|
|
67
|
+
try {
|
|
68
|
+
originalStats = await fs.stat(absolutePath);
|
|
69
|
+
} catch {
|
|
70
|
+
return {
|
|
71
|
+
originalMtime: 0,
|
|
72
|
+
beautifiedExists: false,
|
|
73
|
+
beautifiedMtime: 0,
|
|
74
|
+
isValid: false
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
const originalMtime = originalStats.mtimeMs;
|
|
78
|
+
let beautifiedStats;
|
|
79
|
+
try {
|
|
80
|
+
beautifiedStats = await fs.stat(beautifiedPath);
|
|
81
|
+
} catch {
|
|
82
|
+
return {
|
|
83
|
+
originalMtime,
|
|
84
|
+
beautifiedExists: false,
|
|
85
|
+
beautifiedMtime: 0,
|
|
86
|
+
isValid: false
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
const beautifiedMtime = beautifiedStats.mtimeMs;
|
|
90
|
+
const isValid = beautifiedMtime >= originalMtime;
|
|
91
|
+
return {
|
|
92
|
+
originalMtime,
|
|
93
|
+
beautifiedExists: true,
|
|
94
|
+
beautifiedMtime,
|
|
95
|
+
isValid
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
async function ensureBeautified(originalPath, options) {
|
|
99
|
+
const absolutePath = path.resolve(originalPath);
|
|
100
|
+
const saveLocal = options?.saveLocal ?? false;
|
|
46
101
|
let stats;
|
|
47
102
|
try {
|
|
48
103
|
stats = await fs.stat(absolutePath);
|
|
49
104
|
} catch {
|
|
50
105
|
throw new Error(`File not found: ${originalPath}`);
|
|
51
106
|
}
|
|
107
|
+
const localPaths = getLocalPaths(absolutePath);
|
|
108
|
+
if (saveLocal) {
|
|
109
|
+
const localCacheCheck = await isLocalCacheValid(absolutePath);
|
|
110
|
+
if (localCacheCheck.isValid) {
|
|
111
|
+
try {
|
|
112
|
+
const [code2, mapContent] = await Promise.all([
|
|
113
|
+
fs.readFile(localPaths.beautifiedPath, "utf-8"),
|
|
114
|
+
fs.readFile(localPaths.mapPath, "utf-8")
|
|
115
|
+
]);
|
|
116
|
+
return {
|
|
117
|
+
code: code2,
|
|
118
|
+
rawMap: JSON.parse(mapContent),
|
|
119
|
+
localPath: localPaths.beautifiedPath,
|
|
120
|
+
localMapPath: localPaths.mapPath
|
|
121
|
+
};
|
|
122
|
+
} catch {
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
52
126
|
await ensureCacheDir();
|
|
53
127
|
const hash = calculateCacheKey(absolutePath, stats.mtimeMs);
|
|
54
128
|
const { beautifiedPath, mapPath } = getCachePaths(absolutePath, hash);
|
|
@@ -57,14 +131,18 @@ async function ensureBeautified(originalPath) {
|
|
|
57
131
|
fs.readFile(beautifiedPath, "utf-8"),
|
|
58
132
|
fs.readFile(mapPath, "utf-8")
|
|
59
133
|
]);
|
|
60
|
-
|
|
134
|
+
const result2 = {
|
|
61
135
|
code: code2,
|
|
62
136
|
rawMap: JSON.parse(mapContent)
|
|
63
137
|
};
|
|
138
|
+
if (saveLocal) {
|
|
139
|
+
await saveToLocal(result2, localPaths, mapContent);
|
|
140
|
+
}
|
|
141
|
+
return result2;
|
|
64
142
|
}
|
|
65
|
-
let
|
|
143
|
+
let esbuildResult;
|
|
66
144
|
try {
|
|
67
|
-
|
|
145
|
+
esbuildResult = await esbuild.build({
|
|
68
146
|
entryPoints: [absolutePath],
|
|
69
147
|
bundle: false,
|
|
70
148
|
write: false,
|
|
@@ -81,18 +159,42 @@ async function ensureBeautified(originalPath) {
|
|
|
81
159
|
const message = err instanceof Error ? err.message : String(err);
|
|
82
160
|
throw new Error(`Esbuild processing failed: ${message}`);
|
|
83
161
|
}
|
|
84
|
-
const codeFile =
|
|
85
|
-
const mapFile =
|
|
162
|
+
const codeFile = esbuildResult.outputFiles?.find((f) => f.path.endsWith(".js"));
|
|
163
|
+
const mapFile = esbuildResult.outputFiles?.find((f) => f.path.endsWith(".map"));
|
|
86
164
|
if (!codeFile || !mapFile) {
|
|
87
165
|
throw new Error("Esbuild processing failed: Missing output files");
|
|
88
166
|
}
|
|
89
167
|
const code = codeFile.text;
|
|
90
168
|
const rawMap = JSON.parse(mapFile.text);
|
|
169
|
+
const mapText = mapFile.text;
|
|
91
170
|
await Promise.all([
|
|
92
171
|
fs.writeFile(beautifiedPath, code, "utf-8"),
|
|
93
|
-
fs.writeFile(mapPath,
|
|
172
|
+
fs.writeFile(mapPath, mapText, "utf-8")
|
|
94
173
|
]);
|
|
95
|
-
|
|
174
|
+
const result = { code, rawMap };
|
|
175
|
+
if (saveLocal) {
|
|
176
|
+
await saveToLocal(result, localPaths, mapText);
|
|
177
|
+
}
|
|
178
|
+
return result;
|
|
179
|
+
}
|
|
180
|
+
async function saveToLocal(result, localPaths, mapText) {
|
|
181
|
+
try {
|
|
182
|
+
await Promise.all([
|
|
183
|
+
fs.writeFile(localPaths.beautifiedPath, result.code, "utf-8"),
|
|
184
|
+
fs.writeFile(localPaths.mapPath, mapText, "utf-8")
|
|
185
|
+
]);
|
|
186
|
+
result.localPath = localPaths.beautifiedPath;
|
|
187
|
+
result.localMapPath = localPaths.mapPath;
|
|
188
|
+
} catch (err) {
|
|
189
|
+
const error = err;
|
|
190
|
+
if (error.code === "EACCES" || error.code === "EPERM") {
|
|
191
|
+
result.localSaveError = `Permission denied: Cannot write to ${path.dirname(localPaths.beautifiedPath)}`;
|
|
192
|
+
} else if (error.code === "ENOSPC") {
|
|
193
|
+
result.localSaveError = `Insufficient disk space: Cannot write to ${path.dirname(localPaths.beautifiedPath)}`;
|
|
194
|
+
} else {
|
|
195
|
+
result.localSaveError = `Failed to save locally: ${error.message || String(err)}`;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
96
198
|
}
|
|
97
199
|
|
|
98
200
|
// src/truncator.ts
|
|
@@ -157,25 +259,26 @@ function truncateCodeHighPerf(sourceCode, limit = 200, previewLength = 50) {
|
|
|
157
259
|
});
|
|
158
260
|
return magicString.toString();
|
|
159
261
|
}
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
file_path: z.string().describe("Path to the JavaScript file"),
|
|
164
|
-
start_line: z.number().int().min(1).describe("Start line number (1-based)"),
|
|
165
|
-
end_line: z.number().int().min(1).describe("End line number (1-based)"),
|
|
166
|
-
char_limit: z.number().int().min(50).default(300).describe("Character limit for string truncation")
|
|
167
|
-
});
|
|
168
|
-
var server = new Server(
|
|
169
|
-
{
|
|
170
|
-
name: "jsvmp-smart-fs",
|
|
171
|
-
version: "1.0.0"
|
|
172
|
-
},
|
|
173
|
-
{
|
|
174
|
-
capabilities: {
|
|
175
|
-
tools: {}
|
|
176
|
-
}
|
|
262
|
+
function truncateLongLines(code, maxLineChars = 500, previewRatio = 0.2) {
|
|
263
|
+
if (!code) {
|
|
264
|
+
return code;
|
|
177
265
|
}
|
|
178
|
-
);
|
|
266
|
+
const lines = code.split("\n");
|
|
267
|
+
const previewLength = Math.floor(maxLineChars * previewRatio);
|
|
268
|
+
const processedLines = lines.map((line) => {
|
|
269
|
+
if (line.length <= maxLineChars) {
|
|
270
|
+
return line;
|
|
271
|
+
}
|
|
272
|
+
const start = line.slice(0, previewLength);
|
|
273
|
+
const end = line.slice(-previewLength);
|
|
274
|
+
const truncatedChars = line.length - previewLength * 2;
|
|
275
|
+
const marker = `...[LINE TRUNCATED ${truncatedChars} CHARS]...`;
|
|
276
|
+
return `${start}${marker}${end}`;
|
|
277
|
+
});
|
|
278
|
+
return processedLines.join("\n");
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
// src/tools/readCodeSmart.ts
|
|
179
282
|
function formatSourcePosition(line, column) {
|
|
180
283
|
if (line !== null && column !== null) {
|
|
181
284
|
return `L${line}:${column}`;
|
|
@@ -200,91 +303,704 @@ function formatPaginationHint(nextStartLine) {
|
|
|
200
303
|
return `
|
|
201
304
|
... (Use next start_line=${nextStartLine} to read more)`;
|
|
202
305
|
}
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
306
|
+
var readCodeSmart = defineTool({
|
|
307
|
+
name: "read_code_smart",
|
|
308
|
+
description: "Read and beautify minified/obfuscated JavaScript code with source map coordinates. Returns formatted code with original file positions for setting breakpoints. Optionally saves the beautified file locally alongside the original file.",
|
|
309
|
+
schema: {
|
|
310
|
+
file_path: z.string().describe("Path to the JavaScript file"),
|
|
311
|
+
start_line: z.number().int().min(1).describe("Start line number (1-based)"),
|
|
312
|
+
end_line: z.number().int().min(1).describe("End line number (1-based)"),
|
|
313
|
+
char_limit: z.number().int().min(50).default(300).describe("Character limit for string truncation"),
|
|
314
|
+
max_line_chars: z.number().int().min(80).default(500).describe("Maximum characters per line"),
|
|
315
|
+
save_local: z.boolean().optional().default(false).describe("Save beautified file to the same directory as the original file")
|
|
316
|
+
},
|
|
317
|
+
handler: async (params) => {
|
|
318
|
+
const { file_path, start_line, end_line, char_limit, max_line_chars, save_local } = params;
|
|
319
|
+
const beautifyResult = await ensureBeautified(file_path, { saveLocal: save_local });
|
|
320
|
+
const { code, rawMap, localPath, localMapPath, localSaveError } = beautifyResult;
|
|
321
|
+
const truncatedCode = truncateCodeHighPerf(code, char_limit);
|
|
322
|
+
const lineTruncatedCode = truncateLongLines(truncatedCode, max_line_chars);
|
|
323
|
+
const lines = lineTruncatedCode.split("\n");
|
|
324
|
+
const totalLines = lines.length;
|
|
325
|
+
const effectiveStartLine = Math.max(1, start_line);
|
|
326
|
+
const effectiveEndLine = Math.min(totalLines, end_line);
|
|
327
|
+
if (effectiveStartLine > totalLines) {
|
|
328
|
+
throw new Error(`Start line ${start_line} exceeds total lines ${totalLines}`);
|
|
329
|
+
}
|
|
330
|
+
const consumer = new SourceMapConsumer({
|
|
331
|
+
...rawMap,
|
|
332
|
+
version: String(rawMap.version)
|
|
333
|
+
});
|
|
334
|
+
const outputParts = [];
|
|
335
|
+
outputParts.push(formatHeader(file_path, effectiveStartLine, effectiveEndLine, totalLines));
|
|
336
|
+
if (save_local) {
|
|
337
|
+
if (localPath) {
|
|
338
|
+
outputParts.push(`LOCAL: ${localPath}`);
|
|
339
|
+
if (localMapPath) {
|
|
340
|
+
outputParts.push(`LOCAL_MAP: ${localMapPath}`);
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
if (localSaveError) {
|
|
344
|
+
outputParts.push(`LOCAL_SAVE_ERROR: ${localSaveError}`);
|
|
345
|
+
}
|
|
346
|
+
outputParts.push("-".repeat(85));
|
|
347
|
+
}
|
|
348
|
+
const maxLineNumWidth = String(effectiveEndLine).length;
|
|
349
|
+
for (let lineNum = effectiveStartLine; lineNum <= effectiveEndLine; lineNum++) {
|
|
350
|
+
const lineIndex = lineNum - 1;
|
|
351
|
+
const lineContent = lines[lineIndex] ?? "";
|
|
352
|
+
const originalPos = consumer.originalPositionFor({
|
|
353
|
+
line: lineNum,
|
|
354
|
+
column: 0
|
|
355
|
+
});
|
|
356
|
+
const sourcePos = formatSourcePosition(originalPos.line, originalPos.column);
|
|
357
|
+
outputParts.push(formatCodeLine(lineNum, sourcePos, lineContent, maxLineNumWidth));
|
|
358
|
+
}
|
|
359
|
+
if (effectiveEndLine < totalLines) {
|
|
360
|
+
outputParts.push(formatPaginationHint(effectiveEndLine + 1));
|
|
361
|
+
}
|
|
362
|
+
return outputParts.join("\n");
|
|
363
|
+
}
|
|
364
|
+
});
|
|
365
|
+
|
|
366
|
+
// src/tools/applyCustomTransform.ts
|
|
367
|
+
import { z as z2 } from "zod";
|
|
368
|
+
|
|
369
|
+
// src/transformer.ts
|
|
370
|
+
import * as path2 from "path";
|
|
371
|
+
import * as fs2 from "fs/promises";
|
|
372
|
+
import { transformSync } from "@babel/core";
|
|
373
|
+
function cleanBasename(filename) {
|
|
374
|
+
const base = path2.basename(filename);
|
|
375
|
+
let name = base.endsWith(".js") ? base.slice(0, -3) : base;
|
|
376
|
+
name = name.replace(/_deob[^/]*$/, "");
|
|
377
|
+
if (name.endsWith(".beautified")) {
|
|
378
|
+
name = name.slice(0, -".beautified".length);
|
|
379
|
+
}
|
|
380
|
+
return name;
|
|
381
|
+
}
|
|
382
|
+
function getOutputPaths(targetFile, outputSuffix = "_deob") {
|
|
383
|
+
const absolutePath = path2.resolve(targetFile);
|
|
384
|
+
const dir = path2.dirname(absolutePath);
|
|
385
|
+
const basename3 = cleanBasename(absolutePath);
|
|
386
|
+
const outputPath = path2.join(dir, `${basename3}${outputSuffix}.js`);
|
|
387
|
+
const mapPath = `${outputPath}.map`;
|
|
388
|
+
return { outputPath, mapPath };
|
|
389
|
+
}
|
|
390
|
+
async function loadBabelPlugin(scriptPath) {
|
|
391
|
+
const absolutePath = path2.resolve(scriptPath);
|
|
392
|
+
try {
|
|
393
|
+
await fs2.access(absolutePath);
|
|
394
|
+
} catch {
|
|
395
|
+
throw new Error(`Script not found: ${absolutePath}`);
|
|
396
|
+
}
|
|
397
|
+
const fileUrl = `file://${absolutePath}?t=${Date.now()}`;
|
|
398
|
+
let module;
|
|
399
|
+
try {
|
|
400
|
+
module = await import(fileUrl);
|
|
401
|
+
} catch (err) {
|
|
402
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
403
|
+
throw new Error(`Failed to load script: ${message}`);
|
|
404
|
+
}
|
|
405
|
+
const plugin = module.default ?? module;
|
|
406
|
+
if (typeof plugin !== "function") {
|
|
407
|
+
throw new Error(
|
|
408
|
+
`Invalid Babel plugin: Script must export a function that returns a visitor object. Got ${typeof plugin} instead.`
|
|
409
|
+
);
|
|
410
|
+
}
|
|
411
|
+
return plugin;
|
|
412
|
+
}
|
|
413
|
+
function runBabelTransform(code, inputSourceMap, plugin, filename) {
|
|
414
|
+
let result;
|
|
415
|
+
try {
|
|
416
|
+
result = transformSync(code, {
|
|
417
|
+
filename,
|
|
418
|
+
plugins: [plugin],
|
|
419
|
+
// Source map configuration for cascade
|
|
420
|
+
// @ts-expect-error - SourceMap is compatible with InputSourceMap at runtime
|
|
421
|
+
inputSourceMap,
|
|
422
|
+
sourceMaps: true,
|
|
423
|
+
// Readability settings
|
|
424
|
+
retainLines: false,
|
|
425
|
+
compact: false,
|
|
426
|
+
minified: false,
|
|
427
|
+
// Preserve code structure
|
|
428
|
+
parserOpts: {
|
|
429
|
+
sourceType: "unambiguous"
|
|
430
|
+
}
|
|
431
|
+
});
|
|
432
|
+
} catch (err) {
|
|
433
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
434
|
+
throw new Error(`Babel Error: ${message}`);
|
|
435
|
+
}
|
|
436
|
+
if (!result || !result.code) {
|
|
437
|
+
throw new Error("Babel Error: Transform produced no output");
|
|
438
|
+
}
|
|
439
|
+
if (!result.map) {
|
|
440
|
+
throw new Error("Babel Error: Transform produced no source map");
|
|
441
|
+
}
|
|
442
|
+
return {
|
|
443
|
+
code: result.code,
|
|
444
|
+
map: result.map
|
|
445
|
+
};
|
|
446
|
+
}
|
|
447
|
+
async function applyCustomTransform(targetFile, options) {
|
|
448
|
+
const { scriptPath, outputSuffix = "_deob" } = options;
|
|
449
|
+
const absoluteTargetPath = path2.resolve(targetFile);
|
|
450
|
+
try {
|
|
451
|
+
await fs2.access(absoluteTargetPath);
|
|
452
|
+
} catch {
|
|
453
|
+
throw new Error(`File not found: ${targetFile}`);
|
|
454
|
+
}
|
|
455
|
+
const plugin = await loadBabelPlugin(scriptPath);
|
|
456
|
+
const beautifyResult = await ensureBeautified(absoluteTargetPath);
|
|
457
|
+
const { code: beautifiedCode, rawMap: inputSourceMap } = beautifyResult;
|
|
458
|
+
const transformResult = runBabelTransform(
|
|
459
|
+
beautifiedCode,
|
|
460
|
+
inputSourceMap,
|
|
461
|
+
plugin,
|
|
462
|
+
absoluteTargetPath
|
|
463
|
+
);
|
|
464
|
+
const { outputPath, mapPath } = getOutputPaths(absoluteTargetPath, outputSuffix);
|
|
465
|
+
const mapFileName = path2.basename(mapPath);
|
|
466
|
+
const outputCode = `${transformResult.code}
|
|
467
|
+
//# sourceMappingURL=${mapFileName}`;
|
|
468
|
+
const outputMap = {
|
|
469
|
+
...transformResult.map,
|
|
470
|
+
file: path2.basename(outputPath)
|
|
471
|
+
};
|
|
472
|
+
try {
|
|
473
|
+
await Promise.all([
|
|
474
|
+
fs2.writeFile(outputPath, outputCode, "utf-8"),
|
|
475
|
+
fs2.writeFile(mapPath, JSON.stringify(outputMap, null, 2), "utf-8")
|
|
476
|
+
]);
|
|
477
|
+
} catch (err) {
|
|
478
|
+
const error = err;
|
|
479
|
+
if (error.code === "EACCES" || error.code === "EPERM") {
|
|
480
|
+
throw new Error(`Permission denied: Cannot write to ${path2.dirname(outputPath)}`);
|
|
481
|
+
}
|
|
482
|
+
throw new Error(`Failed to write output files: ${error.message || String(err)}`);
|
|
483
|
+
}
|
|
484
|
+
return {
|
|
485
|
+
code: outputCode,
|
|
486
|
+
map: outputMap,
|
|
487
|
+
outputPath,
|
|
488
|
+
mapPath
|
|
489
|
+
};
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
// src/tools/applyCustomTransform.ts
|
|
493
|
+
var ApplyCustomTransformInputSchema = z2.object({
|
|
494
|
+
target_file: z2.string().describe("Path to the JavaScript file to transform"),
|
|
495
|
+
script_path: z2.string().describe("Path to a JS file exporting a Babel Plugin function"),
|
|
496
|
+
output_suffix: z2.string().default("_deob").describe("Suffix for output file name")
|
|
497
|
+
});
|
|
498
|
+
var applyCustomTransform2 = defineTool({
|
|
499
|
+
name: "apply_custom_transform",
|
|
500
|
+
description: "Apply a custom Babel transformation to deobfuscate JavaScript code. Takes a target JS file and a Babel plugin script, runs the transformation, and outputs the deobfuscated code with a cascaded source map that traces back to the original minified file. The plugin script should export a function that returns a Babel visitor object.",
|
|
501
|
+
schema: {
|
|
502
|
+
target_file: z2.string().describe("Path to the JavaScript file to transform"),
|
|
503
|
+
script_path: z2.string().describe("Path to a JS file exporting a Babel Plugin function"),
|
|
504
|
+
output_suffix: z2.string().default("_deob").describe("Suffix for output file name")
|
|
505
|
+
},
|
|
506
|
+
handler: async (params) => {
|
|
507
|
+
const { target_file, script_path, output_suffix } = params;
|
|
508
|
+
const result = await applyCustomTransform(target_file, {
|
|
509
|
+
scriptPath: script_path,
|
|
510
|
+
outputSuffix: output_suffix
|
|
511
|
+
});
|
|
512
|
+
const successMessage = [
|
|
513
|
+
"Transform completed successfully!",
|
|
514
|
+
"",
|
|
515
|
+
`Output file: ${result.outputPath}`,
|
|
516
|
+
`Source map: ${result.mapPath}`
|
|
517
|
+
].join("\n");
|
|
518
|
+
return successMessage;
|
|
519
|
+
}
|
|
520
|
+
});
|
|
521
|
+
|
|
522
|
+
// src/tools/searchCodeSmart.ts
|
|
523
|
+
import { z as z3 } from "zod";
|
|
524
|
+
|
|
525
|
+
// src/searcher.ts
|
|
526
|
+
import { SourceMapConsumer as SourceMapConsumer2 } from "source-map-js";
|
|
527
|
+
function createRegex(query, caseSensitive = false) {
|
|
528
|
+
try {
|
|
529
|
+
const flags = caseSensitive ? "g" : "gi";
|
|
530
|
+
return new RegExp(query, flags);
|
|
531
|
+
} catch (err) {
|
|
532
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
533
|
+
throw new Error(`Invalid regex: ${message}`);
|
|
213
534
|
}
|
|
214
|
-
|
|
535
|
+
}
|
|
536
|
+
function getOriginalPosition(consumer, lineNumber) {
|
|
537
|
+
const pos = consumer.originalPositionFor({
|
|
538
|
+
line: lineNumber,
|
|
539
|
+
column: 0
|
|
540
|
+
});
|
|
541
|
+
return {
|
|
542
|
+
line: pos.line,
|
|
543
|
+
column: pos.column
|
|
544
|
+
};
|
|
545
|
+
}
|
|
546
|
+
function createContextLine(lineNumber, content, consumer) {
|
|
547
|
+
return {
|
|
548
|
+
lineNumber,
|
|
549
|
+
content,
|
|
550
|
+
originalPosition: getOriginalPosition(consumer, lineNumber)
|
|
551
|
+
};
|
|
552
|
+
}
|
|
553
|
+
function searchInCode(code, rawMap, options) {
|
|
554
|
+
const {
|
|
555
|
+
query,
|
|
556
|
+
contextLines = 2,
|
|
557
|
+
caseSensitive = false,
|
|
558
|
+
maxMatches = 50
|
|
559
|
+
} = options;
|
|
560
|
+
const regex = createRegex(query, caseSensitive);
|
|
561
|
+
const lines = code.split("\n");
|
|
562
|
+
const totalLines = lines.length;
|
|
563
|
+
const consumer = new SourceMapConsumer2({
|
|
215
564
|
...rawMap,
|
|
216
565
|
version: String(rawMap.version)
|
|
217
566
|
});
|
|
567
|
+
const matchingLineNumbers = [];
|
|
568
|
+
for (let i = 0; i < totalLines; i++) {
|
|
569
|
+
const line = lines[i];
|
|
570
|
+
regex.lastIndex = 0;
|
|
571
|
+
if (regex.test(line)) {
|
|
572
|
+
matchingLineNumbers.push(i + 1);
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
const totalMatches = matchingLineNumbers.length;
|
|
576
|
+
const truncated = totalMatches > maxMatches;
|
|
577
|
+
const limitedLineNumbers = matchingLineNumbers.slice(0, maxMatches);
|
|
578
|
+
const matches = limitedLineNumbers.map((lineNumber) => {
|
|
579
|
+
const lineIndex = lineNumber - 1;
|
|
580
|
+
const lineContent = lines[lineIndex];
|
|
581
|
+
const contextBefore = [];
|
|
582
|
+
for (let i = Math.max(0, lineIndex - contextLines); i < lineIndex; i++) {
|
|
583
|
+
contextBefore.push(createContextLine(i + 1, lines[i], consumer));
|
|
584
|
+
}
|
|
585
|
+
const contextAfter = [];
|
|
586
|
+
for (let i = lineIndex + 1; i <= Math.min(totalLines - 1, lineIndex + contextLines); i++) {
|
|
587
|
+
contextAfter.push(createContextLine(i + 1, lines[i], consumer));
|
|
588
|
+
}
|
|
589
|
+
return {
|
|
590
|
+
lineNumber,
|
|
591
|
+
lineContent,
|
|
592
|
+
originalPosition: getOriginalPosition(consumer, lineNumber),
|
|
593
|
+
contextBefore,
|
|
594
|
+
contextAfter
|
|
595
|
+
};
|
|
596
|
+
});
|
|
597
|
+
return {
|
|
598
|
+
matches,
|
|
599
|
+
totalMatches,
|
|
600
|
+
truncated
|
|
601
|
+
};
|
|
602
|
+
}
|
|
603
|
+
function formatSourcePosition2(line, column) {
|
|
604
|
+
if (line !== null && column !== null) {
|
|
605
|
+
return `L${line}:${column}`;
|
|
606
|
+
}
|
|
607
|
+
return "";
|
|
608
|
+
}
|
|
609
|
+
function formatSearchResult(filePath, query, caseSensitive, result, maxMatches = 50) {
|
|
610
|
+
const { matches, totalMatches, truncated } = result;
|
|
218
611
|
const outputParts = [];
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
line: lineNum,
|
|
226
|
-
column: 0
|
|
227
|
-
});
|
|
228
|
-
const sourcePos = formatSourcePosition(originalPos.line, originalPos.column);
|
|
229
|
-
outputParts.push(formatCodeLine(lineNum, sourcePos, lineContent, maxLineNumWidth));
|
|
612
|
+
const caseInfo = caseSensitive ? "case-sensitive" : "case-insensitive";
|
|
613
|
+
outputParts.push(`FILE: ${filePath}`);
|
|
614
|
+
outputParts.push(`QUERY: "${query}" (${caseInfo})`);
|
|
615
|
+
if (totalMatches === 0) {
|
|
616
|
+
outputParts.push("MATCHES: No matches found");
|
|
617
|
+
return outputParts.join("\n");
|
|
230
618
|
}
|
|
231
|
-
|
|
232
|
-
|
|
619
|
+
const matchInfo = truncated ? `MATCHES: ${totalMatches} found (showing first ${maxMatches})` : `MATCHES: ${totalMatches} found`;
|
|
620
|
+
outputParts.push(matchInfo);
|
|
621
|
+
outputParts.push("-".repeat(85));
|
|
622
|
+
for (const match of matches) {
|
|
623
|
+
outputParts.push(`--- Match at Line ${match.lineNumber} ---`);
|
|
624
|
+
const allLineNumbers = [
|
|
625
|
+
...match.contextBefore.map((c) => c.lineNumber),
|
|
626
|
+
match.lineNumber,
|
|
627
|
+
...match.contextAfter.map((c) => c.lineNumber)
|
|
628
|
+
];
|
|
629
|
+
const maxLineNumWidth = Math.max(...allLineNumbers.map((n) => String(n).length));
|
|
630
|
+
for (const ctx of match.contextBefore) {
|
|
631
|
+
const lineNumStr = String(ctx.lineNumber).padStart(maxLineNumWidth, " ");
|
|
632
|
+
const srcPos = formatSourcePosition2(ctx.originalPosition.line, ctx.originalPosition.column);
|
|
633
|
+
const srcPosPadded = srcPos ? `Src ${srcPos}` : "";
|
|
634
|
+
outputParts.push(` ${lineNumStr} | [${srcPosPadded.padEnd(14, " ")}] | ${ctx.content}`);
|
|
635
|
+
}
|
|
636
|
+
const matchLineNumStr = String(match.lineNumber).padStart(maxLineNumWidth, " ");
|
|
637
|
+
const matchSrcPos = formatSourcePosition2(match.originalPosition.line, match.originalPosition.column);
|
|
638
|
+
const matchSrcPosPadded = matchSrcPos ? `Src ${matchSrcPos}` : "";
|
|
639
|
+
outputParts.push(`>> ${matchLineNumStr} | [${matchSrcPosPadded.padEnd(14, " ")}] | ${match.lineContent}`);
|
|
640
|
+
for (const ctx of match.contextAfter) {
|
|
641
|
+
const lineNumStr = String(ctx.lineNumber).padStart(maxLineNumWidth, " ");
|
|
642
|
+
const srcPos = formatSourcePosition2(ctx.originalPosition.line, ctx.originalPosition.column);
|
|
643
|
+
const srcPosPadded = srcPos ? `Src ${srcPos}` : "";
|
|
644
|
+
outputParts.push(` ${lineNumStr} | [${srcPosPadded.padEnd(14, " ")}] | ${ctx.content}`);
|
|
645
|
+
}
|
|
646
|
+
outputParts.push("");
|
|
647
|
+
}
|
|
648
|
+
if (truncated) {
|
|
649
|
+
outputParts.push(`... (${totalMatches - maxMatches} more matches not shown)`);
|
|
233
650
|
}
|
|
234
651
|
return outputParts.join("\n");
|
|
235
652
|
}
|
|
236
|
-
|
|
653
|
+
|
|
654
|
+
// src/tools/searchCodeSmart.ts
|
|
655
|
+
var SearchCodeSmartInputSchema = z3.object({
|
|
656
|
+
file_path: z3.string().describe("Path to the JavaScript file"),
|
|
657
|
+
query: z3.string().describe("Regex pattern or text to search"),
|
|
658
|
+
context_lines: z3.number().int().min(0).default(2).describe("Number of context lines"),
|
|
659
|
+
case_sensitive: z3.boolean().default(false).describe("Case sensitive search"),
|
|
660
|
+
char_limit: z3.number().int().min(50).default(300).describe("Character limit for string truncation"),
|
|
661
|
+
max_line_chars: z3.number().int().min(80).default(500).describe("Maximum characters per line")
|
|
662
|
+
});
|
|
663
|
+
var searchCodeSmart = defineTool({
|
|
664
|
+
name: "search_code_smart",
|
|
665
|
+
description: "Search for text or regex patterns in beautified JavaScript code. Returns matching lines with context and original source coordinates for setting breakpoints. Useful for finding code patterns in minified/obfuscated files.",
|
|
666
|
+
schema: {
|
|
667
|
+
file_path: z3.string().describe("Path to the JavaScript file"),
|
|
668
|
+
query: z3.string().describe("Regex pattern or text to search"),
|
|
669
|
+
context_lines: z3.number().int().min(0).default(2).describe("Number of context lines"),
|
|
670
|
+
case_sensitive: z3.boolean().default(false).describe("Case sensitive search"),
|
|
671
|
+
char_limit: z3.number().int().min(50).default(300).describe("Character limit for string truncation"),
|
|
672
|
+
max_line_chars: z3.number().int().min(80).default(500).describe("Maximum characters per line")
|
|
673
|
+
},
|
|
674
|
+
handler: async (params) => {
|
|
675
|
+
const { file_path, query, context_lines, case_sensitive, char_limit, max_line_chars } = params;
|
|
676
|
+
const beautifyResult = await ensureBeautified(file_path);
|
|
677
|
+
const { code, rawMap } = beautifyResult;
|
|
678
|
+
const truncatedCode = truncateCodeHighPerf(code, char_limit);
|
|
679
|
+
const searchResult = searchInCode(truncatedCode, rawMap, {
|
|
680
|
+
query,
|
|
681
|
+
contextLines: context_lines,
|
|
682
|
+
caseSensitive: case_sensitive,
|
|
683
|
+
maxMatches: 50
|
|
684
|
+
});
|
|
685
|
+
let output = formatSearchResult(file_path, query, case_sensitive, searchResult, 50);
|
|
686
|
+
output = truncateLongLines(output, max_line_chars);
|
|
687
|
+
return output;
|
|
688
|
+
}
|
|
689
|
+
});
|
|
690
|
+
|
|
691
|
+
// src/tools/findUsageSmart.ts
|
|
692
|
+
import { z as z4 } from "zod";
|
|
693
|
+
|
|
694
|
+
// src/analyzer.ts
|
|
695
|
+
import { SourceMapConsumer as SourceMapConsumer3 } from "source-map-js";
|
|
696
|
+
import { parse as parse2 } from "@babel/parser";
|
|
697
|
+
var traverse = __require("@babel/traverse").default;
|
|
698
|
+
var DEFAULT_PARSER_OPTIONS = {
|
|
699
|
+
sourceType: "unambiguous",
|
|
700
|
+
plugins: [
|
|
701
|
+
"jsx",
|
|
702
|
+
"typescript",
|
|
703
|
+
"classProperties",
|
|
704
|
+
"classPrivateProperties",
|
|
705
|
+
"classPrivateMethods",
|
|
706
|
+
"dynamicImport",
|
|
707
|
+
"optionalChaining",
|
|
708
|
+
"nullishCoalescingOperator",
|
|
709
|
+
"objectRestSpread"
|
|
710
|
+
],
|
|
711
|
+
errorRecovery: true
|
|
712
|
+
};
|
|
713
|
+
function parseCode(code) {
|
|
714
|
+
try {
|
|
715
|
+
return parse2(code, DEFAULT_PARSER_OPTIONS);
|
|
716
|
+
} catch (err) {
|
|
717
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
718
|
+
throw new Error(`Parse error: ${message}`);
|
|
719
|
+
}
|
|
720
|
+
}
|
|
721
|
+
function getOriginalPosition2(consumer, line, column) {
|
|
722
|
+
const pos = consumer.originalPositionFor({ line, column });
|
|
723
|
+
return {
|
|
724
|
+
line: pos.line,
|
|
725
|
+
column: pos.column
|
|
726
|
+
};
|
|
727
|
+
}
|
|
728
|
+
function getLineContent(lines, lineNumber) {
|
|
729
|
+
if (lineNumber < 1 || lineNumber > lines.length) {
|
|
730
|
+
return "";
|
|
731
|
+
}
|
|
732
|
+
return lines[lineNumber - 1];
|
|
733
|
+
}
|
|
734
|
+
function createLocationInfo(line, column, lines, consumer) {
|
|
237
735
|
return {
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
736
|
+
line,
|
|
737
|
+
column,
|
|
738
|
+
originalPosition: getOriginalPosition2(consumer, line, column),
|
|
739
|
+
lineContent: getLineContent(lines, line)
|
|
740
|
+
};
|
|
741
|
+
}
|
|
742
|
+
function analyzeBindings(code, rawMap, identifier, options) {
|
|
743
|
+
const targetLine = options?.targetLine;
|
|
744
|
+
const isTargeted = targetLine !== void 0;
|
|
745
|
+
const maxReferences = options?.maxReferences ?? (isTargeted ? 15 : 10);
|
|
746
|
+
const ast = parseCode(code);
|
|
747
|
+
const lines = code.split("\n");
|
|
748
|
+
const consumer = new SourceMapConsumer3({
|
|
749
|
+
...rawMap,
|
|
750
|
+
version: String(rawMap.version)
|
|
751
|
+
});
|
|
752
|
+
const bindings = [];
|
|
753
|
+
const processedScopes = /* @__PURE__ */ new Set();
|
|
754
|
+
try {
|
|
755
|
+
traverse(ast, {
|
|
756
|
+
Identifier(path3) {
|
|
757
|
+
if (path3.node.name !== identifier) {
|
|
758
|
+
return;
|
|
759
|
+
}
|
|
760
|
+
if (isTargeted) {
|
|
761
|
+
const nodeLoc = path3.node.loc;
|
|
762
|
+
if (!nodeLoc || nodeLoc.start.line !== targetLine) {
|
|
763
|
+
return;
|
|
764
|
+
}
|
|
765
|
+
}
|
|
766
|
+
const binding = path3.scope.getBinding(identifier);
|
|
767
|
+
if (!binding) {
|
|
768
|
+
return;
|
|
769
|
+
}
|
|
770
|
+
const scopeUid = binding.scope.uid;
|
|
771
|
+
if (processedScopes.has(scopeUid)) {
|
|
772
|
+
return;
|
|
773
|
+
}
|
|
774
|
+
processedScopes.add(scopeUid);
|
|
775
|
+
const defNode = binding.identifier;
|
|
776
|
+
const defLoc = defNode.loc;
|
|
777
|
+
if (!defLoc) {
|
|
778
|
+
return;
|
|
779
|
+
}
|
|
780
|
+
const definition = createLocationInfo(
|
|
781
|
+
defLoc.start.line,
|
|
782
|
+
defLoc.start.column,
|
|
783
|
+
lines,
|
|
784
|
+
consumer
|
|
785
|
+
);
|
|
786
|
+
const allReferences = [];
|
|
787
|
+
for (const refPath of binding.referencePaths) {
|
|
788
|
+
const refLoc = refPath.node.loc;
|
|
789
|
+
if (!refLoc) {
|
|
790
|
+
continue;
|
|
791
|
+
}
|
|
792
|
+
allReferences.push(
|
|
793
|
+
createLocationInfo(
|
|
794
|
+
refLoc.start.line,
|
|
795
|
+
refLoc.start.column,
|
|
796
|
+
lines,
|
|
797
|
+
consumer
|
|
798
|
+
)
|
|
799
|
+
);
|
|
800
|
+
}
|
|
801
|
+
const totalReferences = allReferences.length;
|
|
802
|
+
const limitedReferences = allReferences.slice(0, maxReferences);
|
|
803
|
+
let hitLocation;
|
|
804
|
+
if (isTargeted) {
|
|
805
|
+
const nodeLoc = path3.node.loc;
|
|
806
|
+
hitLocation = createLocationInfo(
|
|
807
|
+
nodeLoc.start.line,
|
|
808
|
+
nodeLoc.start.column,
|
|
809
|
+
lines,
|
|
810
|
+
consumer
|
|
811
|
+
);
|
|
812
|
+
}
|
|
813
|
+
bindings.push({
|
|
814
|
+
scopeUid,
|
|
815
|
+
kind: binding.kind,
|
|
816
|
+
definition,
|
|
817
|
+
references: limitedReferences,
|
|
818
|
+
totalReferences,
|
|
819
|
+
hitLocation
|
|
820
|
+
});
|
|
821
|
+
if (isTargeted) {
|
|
822
|
+
path3.stop();
|
|
264
823
|
}
|
|
265
824
|
}
|
|
266
|
-
|
|
825
|
+
});
|
|
826
|
+
} catch (err) {
|
|
827
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
828
|
+
throw new Error(`Analysis error: ${message}`);
|
|
829
|
+
}
|
|
830
|
+
return {
|
|
831
|
+
bindings,
|
|
832
|
+
identifier,
|
|
833
|
+
isTargeted,
|
|
834
|
+
targetLine
|
|
267
835
|
};
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
throw new Error(`Tool not found: ${name}`);
|
|
836
|
+
}
|
|
837
|
+
function formatSourcePosition3(line, column) {
|
|
838
|
+
if (line !== null && column !== null) {
|
|
839
|
+
return `L${line}:${column}`;
|
|
273
840
|
}
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
841
|
+
return "";
|
|
842
|
+
}
|
|
843
|
+
function locationsMatch(loc1, loc2) {
|
|
844
|
+
return loc1.line === loc2.line && loc1.column === loc2.column;
|
|
845
|
+
}
|
|
846
|
+
function formatAnalysisResult(filePath, result, maxReferences = 10) {
|
|
847
|
+
const { bindings, identifier, isTargeted, targetLine } = result;
|
|
848
|
+
const outputParts = [];
|
|
849
|
+
outputParts.push(`FILE: ${filePath}`);
|
|
850
|
+
outputParts.push(`IDENTIFIER: "${identifier}"`);
|
|
851
|
+
if (bindings.length === 0) {
|
|
852
|
+
if (isTargeted && targetLine !== void 0) {
|
|
853
|
+
outputParts.push(`BINDINGS: No binding found for "${identifier}" at line ${targetLine}`);
|
|
854
|
+
outputParts.push(`The variable may be global, externally defined, or not present at this line.`);
|
|
855
|
+
} else {
|
|
856
|
+
outputParts.push("BINDINGS: No definitions or references found");
|
|
857
|
+
}
|
|
858
|
+
return outputParts.join("\n");
|
|
859
|
+
}
|
|
860
|
+
if (isTargeted) {
|
|
861
|
+
outputParts.push(`BINDINGS: 1 found (Targeted Scope at line ${targetLine})`);
|
|
862
|
+
} else {
|
|
863
|
+
const scopeInfo = bindings.length > 1 ? " (in different scopes)" : "";
|
|
864
|
+
outputParts.push(`BINDINGS: ${bindings.length} found${scopeInfo}`);
|
|
865
|
+
}
|
|
866
|
+
outputParts.push("-".repeat(85));
|
|
867
|
+
for (let i = 0; i < bindings.length; i++) {
|
|
868
|
+
const binding = bindings[i];
|
|
869
|
+
if (isTargeted) {
|
|
870
|
+
outputParts.push(`=== Targeted Scope (${binding.kind}) ===`);
|
|
871
|
+
} else {
|
|
872
|
+
outputParts.push(`=== Scope #${i + 1} (${binding.kind}) ===`);
|
|
873
|
+
}
|
|
874
|
+
const defIsHit = isTargeted && binding.hitLocation && locationsMatch(binding.definition, binding.hitLocation);
|
|
875
|
+
const defPrefix = defIsHit ? "\u{1F4CD} Definition (hit):" : "\u{1F4CD} Definition:";
|
|
876
|
+
outputParts.push(defPrefix);
|
|
877
|
+
const defSrcPos = formatSourcePosition3(
|
|
878
|
+
binding.definition.originalPosition.line,
|
|
879
|
+
binding.definition.originalPosition.column
|
|
880
|
+
);
|
|
881
|
+
const defSrcPosPadded = defSrcPos ? `Src ${defSrcPos}` : "";
|
|
882
|
+
const defMarker = defIsHit ? " \u25C0\u2500\u2500 hit" : "";
|
|
883
|
+
outputParts.push(
|
|
884
|
+
` ${binding.definition.line} | [${defSrcPosPadded.padEnd(14, " ")}] | ${binding.definition.lineContent}${defMarker}`
|
|
885
|
+
);
|
|
886
|
+
const totalRefs = binding.totalReferences;
|
|
887
|
+
if (totalRefs === 0) {
|
|
888
|
+
outputParts.push("\u{1F50E} References: None");
|
|
889
|
+
} else {
|
|
890
|
+
outputParts.push(`\u{1F50E} References (${totalRefs}):`);
|
|
891
|
+
for (const ref of binding.references) {
|
|
892
|
+
const refIsHit = isTargeted && binding.hitLocation && locationsMatch(ref, binding.hitLocation);
|
|
893
|
+
const refSrcPos = formatSourcePosition3(
|
|
894
|
+
ref.originalPosition.line,
|
|
895
|
+
ref.originalPosition.column
|
|
896
|
+
);
|
|
897
|
+
const refSrcPosPadded = refSrcPos ? `Src ${refSrcPos}` : "";
|
|
898
|
+
const refMarker = refIsHit ? " \u25C0\u2500\u2500 hit" : "";
|
|
899
|
+
outputParts.push(
|
|
900
|
+
` ${ref.line} | [${refSrcPosPadded.padEnd(14, " ")}] | ${ref.lineContent}${refMarker}`
|
|
901
|
+
);
|
|
902
|
+
}
|
|
903
|
+
if (totalRefs > maxReferences) {
|
|
904
|
+
const remaining = totalRefs - maxReferences;
|
|
905
|
+
outputParts.push(` ... (${remaining} more references not shown)`);
|
|
906
|
+
}
|
|
907
|
+
}
|
|
908
|
+
outputParts.push("");
|
|
909
|
+
}
|
|
910
|
+
return outputParts.join("\n");
|
|
911
|
+
}
|
|
912
|
+
|
|
913
|
+
// src/tools/findUsageSmart.ts
|
|
914
|
+
var FindUsageSmartInputSchema = z4.object({
|
|
915
|
+
file_path: z4.string().describe("Path to the JavaScript file"),
|
|
916
|
+
identifier: z4.string().describe("Variable or function name to find"),
|
|
917
|
+
line: z4.number().int().positive().optional().describe(
|
|
918
|
+
"The line number where you see this variable. HIGHLY RECOMMENDED for precision in obfuscated code."
|
|
919
|
+
),
|
|
920
|
+
char_limit: z4.number().int().min(50).default(300).describe("Character limit for string truncation"),
|
|
921
|
+
max_line_chars: z4.number().int().min(80).default(500).describe("Maximum characters per line")
|
|
922
|
+
});
|
|
923
|
+
var findUsageSmart = defineTool({
|
|
924
|
+
name: "find_usage_smart",
|
|
925
|
+
description: "Find all definitions and references of a variable/function using AST scope analysis. Returns binding information grouped by scope with original source coordinates for setting breakpoints. Useful for tracing variable usage in minified/obfuscated code with variable name reuse.",
|
|
926
|
+
schema: {
|
|
927
|
+
file_path: z4.string().describe("Path to the JavaScript file"),
|
|
928
|
+
identifier: z4.string().describe("Variable or function name to find"),
|
|
929
|
+
line: z4.number().int().positive().optional().describe(
|
|
930
|
+
"The line number where you see this variable. HIGHLY RECOMMENDED for precision in obfuscated code."
|
|
931
|
+
),
|
|
932
|
+
char_limit: z4.number().int().min(50).default(300).describe("Character limit for string truncation"),
|
|
933
|
+
max_line_chars: z4.number().int().min(80).default(500).describe("Maximum characters per line")
|
|
934
|
+
},
|
|
935
|
+
handler: async (params) => {
|
|
936
|
+
const { file_path, identifier, line, char_limit, max_line_chars } = params;
|
|
937
|
+
const beautifyResult = await ensureBeautified(file_path);
|
|
938
|
+
const { code, rawMap } = beautifyResult;
|
|
939
|
+
const analysisResult = analyzeBindings(code, rawMap, identifier, {
|
|
940
|
+
maxReferences: line ? 15 : 10,
|
|
941
|
+
targetLine: line
|
|
942
|
+
});
|
|
943
|
+
const truncatedCode = truncateCodeHighPerf(code, char_limit);
|
|
944
|
+
const truncatedLines = truncatedCode.split("\n");
|
|
945
|
+
for (const binding of analysisResult.bindings) {
|
|
946
|
+
const defLineIdx = binding.definition.line - 1;
|
|
947
|
+
if (defLineIdx >= 0 && defLineIdx < truncatedLines.length) {
|
|
948
|
+
binding.definition.lineContent = truncatedLines[defLineIdx];
|
|
949
|
+
}
|
|
950
|
+
for (const ref of binding.references) {
|
|
951
|
+
const refLineIdx = ref.line - 1;
|
|
952
|
+
if (refLineIdx >= 0 && refLineIdx < truncatedLines.length) {
|
|
953
|
+
ref.lineContent = truncatedLines[refLineIdx];
|
|
954
|
+
}
|
|
955
|
+
}
|
|
956
|
+
}
|
|
957
|
+
let output = formatAnalysisResult(file_path, analysisResult, line ? 15 : 10);
|
|
958
|
+
output = truncateLongLines(output, max_line_chars);
|
|
959
|
+
return output;
|
|
286
960
|
}
|
|
287
961
|
});
|
|
962
|
+
|
|
963
|
+
// src/tools/index.ts
|
|
964
|
+
var tools = [
|
|
965
|
+
readCodeSmart,
|
|
966
|
+
applyCustomTransform2,
|
|
967
|
+
searchCodeSmart,
|
|
968
|
+
findUsageSmart
|
|
969
|
+
];
|
|
970
|
+
|
|
971
|
+
// src/server.ts
|
|
972
|
+
var server = new McpServer({
|
|
973
|
+
name: "jsvmp-smart-fs",
|
|
974
|
+
version: "1.0.0"
|
|
975
|
+
});
|
|
976
|
+
function registerTool(tool) {
|
|
977
|
+
const zodSchema = z5.object(tool.schema);
|
|
978
|
+
server.registerTool(
|
|
979
|
+
tool.name,
|
|
980
|
+
{
|
|
981
|
+
description: tool.description,
|
|
982
|
+
inputSchema: tool.schema
|
|
983
|
+
},
|
|
984
|
+
async (params, _extra) => {
|
|
985
|
+
try {
|
|
986
|
+
const validatedParams = zodSchema.parse(params);
|
|
987
|
+
const result = await tool.handler(validatedParams);
|
|
988
|
+
return {
|
|
989
|
+
content: [{ type: "text", text: result }]
|
|
990
|
+
};
|
|
991
|
+
} catch (error) {
|
|
992
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
993
|
+
return {
|
|
994
|
+
content: [{ type: "text", text: `Error: ${message}` }],
|
|
995
|
+
isError: true
|
|
996
|
+
};
|
|
997
|
+
}
|
|
998
|
+
}
|
|
999
|
+
);
|
|
1000
|
+
}
|
|
1001
|
+
for (const tool of tools) {
|
|
1002
|
+
registerTool(tool);
|
|
1003
|
+
}
|
|
288
1004
|
async function main() {
|
|
289
1005
|
const transport = new StdioServerTransport();
|
|
290
1006
|
await server.connect(transport);
|
package/dist/server.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../src/server.ts", "../src/beautifier.ts", "../src/truncator.ts"],
|
|
4
|
-
"sourcesContent": ["import { Server } from '@modelcontextprotocol/sdk/server/index.js';\nimport { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';\nimport {\n CallToolRequestSchema,\n ListToolsRequestSchema,\n} from '@modelcontextprotocol/sdk/types.js';\nimport { z } from 'zod';\nimport { SourceMapConsumer } from 'source-map-js';\nimport { ensureBeautified } from './beautifier.js';\nimport { truncateCodeHighPerf } from './truncator.js';\n\n// Tool input schema using Zod\nconst ReadCodeSmartInputSchema = z.object({\n file_path: z.string().describe('Path to the JavaScript file'),\n start_line: z.number().int().min(1).describe('Start line number (1-based)'),\n end_line: z.number().int().min(1).describe('End line number (1-based)'),\n char_limit: z.number().int().min(50).default(300).describe('Character limit for string truncation'),\n});\n\ntype ReadCodeSmartInput = z.infer<typeof ReadCodeSmartInputSchema>;\n\n// Create MCP Server instance\nconst server = new Server(\n {\n name: 'jsvmp-smart-fs',\n version: '1.0.0',\n },\n {\n capabilities: {\n tools: {},\n },\n }\n);\n\n\n/**\n * Format source position as \"L{line}:{column}\" or empty placeholder\n */\nfunction formatSourcePosition(line: number | null, column: number | null): string {\n if (line !== null && column !== null) {\n return `L${line}:${column}`;\n }\n return '';\n}\n\n/**\n * Format output header with file info\n */\nfunction formatHeader(filePath: string, startLine: number, endLine: number, totalLines: number): string {\n return [\n `FILE: ${filePath}`,\n `VIEW: Auto-beautified (Lines ${startLine}-${endLine} of ${totalLines})`,\n `INFO: [Src L:C] = Location in original minified file (for Chrome Breakpoints)`,\n '-'.repeat(85),\n ].join('\\n');\n}\n\n/**\n * Format a single code line with line number, source coordinates, and content\n */\nfunction formatCodeLine(lineNumber: number, sourcePos: string, code: string, maxLineNumWidth: number): string {\n const lineNumStr = String(lineNumber).padStart(maxLineNumWidth, ' ');\n const srcPosStr = sourcePos ? `Src ${sourcePos}` : '';\n const srcPosPadded = srcPosStr.padEnd(14, ' ');\n return `${lineNumStr} | [${srcPosPadded}] | ${code}`;\n}\n\n/**\n * Format pagination hint\n */\nfunction formatPaginationHint(nextStartLine: number): string {\n return `\\n... (Use next start_line=${nextStartLine} to read more)`;\n}\n\n\n/**\n * Process read_code_smart request\n */\nasync function handleReadCodeSmart(input: ReadCodeSmartInput): Promise<string> {\n const { file_path, start_line, end_line, char_limit } = input;\n\n // Beautify the file and get source map\n const { code, rawMap } = await ensureBeautified(file_path);\n\n // Truncate long strings\n const truncatedCode = truncateCodeHighPerf(code, char_limit);\n\n // Split into lines\n const lines = truncatedCode.split('\\n');\n const totalLines = lines.length;\n\n // Validate line range\n const effectiveStartLine = Math.max(1, start_line);\n const effectiveEndLine = Math.min(totalLines, end_line);\n\n if (effectiveStartLine > totalLines) {\n throw new Error(`Start line ${start_line} exceeds total lines ${totalLines}`);\n }\n\n // Create source map consumer (cast version to string as required by source-map-js)\n const consumer = new SourceMapConsumer({\n ...rawMap,\n version: String(rawMap.version),\n });\n\n // Build output\n const outputParts: string[] = [];\n\n // Add header\n outputParts.push(formatHeader(file_path, effectiveStartLine, effectiveEndLine, totalLines));\n\n // Calculate max line number width for alignment\n const maxLineNumWidth = String(effectiveEndLine).length;\n\n // Format each line\n for (let lineNum = effectiveStartLine; lineNum <= effectiveEndLine; lineNum++) {\n const lineIndex = lineNum - 1;\n const lineContent = lines[lineIndex] ?? '';\n\n // Get original position from source map\n const originalPos = consumer.originalPositionFor({\n line: lineNum,\n column: 0,\n });\n\n const sourcePos = formatSourcePosition(originalPos.line, originalPos.column);\n outputParts.push(formatCodeLine(lineNum, sourcePos, lineContent, maxLineNumWidth));\n }\n\n // Add pagination hint if there are more lines\n if (effectiveEndLine < totalLines) {\n outputParts.push(formatPaginationHint(effectiveEndLine + 1));\n }\n\n return outputParts.join('\\n');\n}\n\n\n// Register ListTools handler\nserver.setRequestHandler(ListToolsRequestSchema, async () => {\n return {\n tools: [\n {\n name: 'read_code_smart',\n description:\n 'Read and beautify minified/obfuscated JavaScript code with source map coordinates. ' +\n 'Returns formatted code with original file positions for setting breakpoints.',\n inputSchema: {\n type: 'object',\n properties: {\n file_path: {\n type: 'string',\n description: 'Path to the JavaScript file',\n },\n start_line: {\n type: 'number',\n description: 'Start line number (1-based)',\n },\n end_line: {\n type: 'number',\n description: 'End line number (1-based)',\n },\n char_limit: {\n type: 'number',\n description: 'Character limit for string truncation (default: 300)',\n default: 300,\n },\n },\n required: ['file_path', 'start_line', 'end_line'],\n },\n },\n ],\n };\n});\n\n// Register CallTool handler\nserver.setRequestHandler(CallToolRequestSchema, async (request) => {\n const { name, arguments: args } = request.params;\n\n if (name !== 'read_code_smart') {\n throw new Error(`Tool not found: ${name}`);\n }\n\n try {\n // Validate and parse input\n const input = ReadCodeSmartInputSchema.parse(args);\n const result = await handleReadCodeSmart(input);\n\n return {\n content: [{ type: 'text', text: result }],\n };\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n return {\n content: [{ type: 'text', text: `Error: ${message}` }],\n isError: true,\n };\n }\n});\n\n// Main entry point\nasync function main() {\n const transport = new StdioServerTransport();\n await server.connect(transport);\n console.error('JSVMP Smart FS MCP Server running on stdio');\n}\n\nmain().catch((error) => {\n console.error('Fatal error:', error);\n process.exit(1);\n});\n", "import * as esbuild from 'esbuild';\nimport * as crypto from 'crypto';\nimport * as fs from 'fs/promises';\nimport * as path from 'path';\nimport * as os from 'os';\n\nconst TEMP_DIR = path.join(os.tmpdir(), 'jsvmp-mcp-cache');\n\nexport interface SourceMap {\n version: number;\n sources: string[];\n names: string[];\n mappings: string;\n file?: string;\n sourceRoot?: string;\n}\n\nexport interface BeautifyResult {\n code: string;\n rawMap: SourceMap;\n}\n\n/**\n * Ensure the cache directory exists\n */\nasync function ensureCacheDir(): Promise<void> {\n await fs.mkdir(TEMP_DIR, { recursive: true });\n}\n\n/**\n * Calculate cache key based on file path and modification time\n */\nfunction calculateCacheKey(originalPath: string, mtimeMs: number): string {\n const fileKey = `${originalPath}-${mtimeMs}`;\n return crypto.createHash('md5').update(fileKey).digest('hex');\n}\n\n/**\n * Get cache file paths for a given original file\n */\nfunction getCachePaths(originalPath: string, hash: string): { beautifiedPath: string; mapPath: string } {\n const fileName = path.basename(originalPath, '.js');\n const beautifiedPath = path.join(TEMP_DIR, `${fileName}.${hash}.beautified.js`);\n const mapPath = `${beautifiedPath}.map`;\n return { beautifiedPath, mapPath };\n}\n\n\n/**\n * Check if cache exists and is valid\n */\nasync function isCacheValid(beautifiedPath: string, mapPath: string): Promise<boolean> {\n try {\n await Promise.all([\n fs.access(beautifiedPath),\n fs.access(mapPath)\n ]);\n return true;\n } catch {\n return false;\n }\n}\n\n/**\n * Beautify JavaScript file and generate Source Map\n * @param originalPath - Original file path\n * @returns Beautified code and Source Map\n */\nexport async function ensureBeautified(originalPath: string): Promise<BeautifyResult> {\n // Resolve to absolute path\n const absolutePath = path.resolve(originalPath);\n \n // Check if file exists\n let stats: Awaited<ReturnType<typeof fs.stat>>;\n try {\n stats = await fs.stat(absolutePath);\n } catch {\n throw new Error(`File not found: ${originalPath}`);\n }\n \n // Ensure cache directory exists\n await ensureCacheDir();\n \n // Calculate cache key\n const hash = calculateCacheKey(absolutePath, stats.mtimeMs);\n const { beautifiedPath, mapPath } = getCachePaths(absolutePath, hash);\n \n // Check cache\n if (await isCacheValid(beautifiedPath, mapPath)) {\n // Cache hit - read from cache\n const [code, mapContent] = await Promise.all([\n fs.readFile(beautifiedPath, 'utf-8'),\n fs.readFile(mapPath, 'utf-8')\n ]);\n return {\n code,\n rawMap: JSON.parse(mapContent) as SourceMap\n };\n }\n \n // Cache miss - beautify with Esbuild\n let result: esbuild.BuildResult;\n try {\n result = await esbuild.build({\n entryPoints: [absolutePath],\n bundle: false,\n write: false,\n format: 'esm',\n sourcemap: 'external',\n sourcesContent: false,\n outfile: 'out.js',\n // Beautify settings\n minify: false,\n keepNames: true,\n treeShaking: false,\n });\n } catch (err) {\n const message = err instanceof Error ? err.message : String(err);\n throw new Error(`Esbuild processing failed: ${message}`);\n }\n \n // Extract code and source map from result\n const codeFile = result.outputFiles?.find(f => f.path.endsWith('.js'));\n const mapFile = result.outputFiles?.find(f => f.path.endsWith('.map'));\n \n if (!codeFile || !mapFile) {\n throw new Error('Esbuild processing failed: Missing output files');\n }\n \n const code = codeFile.text;\n const rawMap = JSON.parse(mapFile.text) as SourceMap;\n \n // Write to cache\n await Promise.all([\n fs.writeFile(beautifiedPath, code, 'utf-8'),\n fs.writeFile(mapPath, mapFile.text, 'utf-8')\n ]);\n \n return { code, rawMap };\n}\n", "import { parse } from 'meriyah';\nimport { walk } from 'estree-walker';\nimport MagicString from 'magic-string';\nimport type { Node } from 'estree';\n\n/**\n * Count newlines in a string\n */\nfunction countNewlines(str: string): number {\n let count = 0;\n for (const char of str) {\n if (char === '\\n') count++;\n }\n return count;\n}\n\n/**\n * Create truncated string with preserved newlines\n * Format: \"start ...[TRUNCATED {length} CHARS]... \\n\\n\\nend\"\n */\nfunction createTruncatedString(original: string, previewLength: number): string {\n const newlineCount = countNewlines(original);\n const start = original.slice(0, previewLength);\n const end = original.slice(-previewLength);\n \n // Build the truncation marker with preserved newlines\n const marker = `...[TRUNCATED ${original.length} CHARS]...`;\n \n // Create newlines to preserve line count\n // We need to account for newlines already in start and end portions\n const startNewlines = countNewlines(start);\n const endNewlines = countNewlines(end);\n const preservedNewlines = Math.max(0, newlineCount - startNewlines - endNewlines);\n const newlineStr = '\\n'.repeat(preservedNewlines);\n \n return `${start}${marker}${newlineStr}${end}`;\n}\n\n/**\n * Truncate long strings in JavaScript code while preserving line numbers\n * @param sourceCode - Source code to process\n * @param limit - Character limit for strings (default 200)\n * @param previewLength - Length of start/end preview portions (default 50)\n * @returns Truncated code with preserved line count\n */\nexport function truncateCodeHighPerf(sourceCode: string, limit: number = 200, previewLength: number = 50): string {\n // Try to parse the AST\n let ast: ReturnType<typeof parse>;\n try {\n ast = parse(sourceCode, {\n module: true,\n next: true,\n ranges: true,\n loc: true,\n raw: true,\n });\n } catch {\n // AST parsing failed - return original code unchanged (Requirement 2.4)\n return sourceCode;\n }\n\n const magicString = new MagicString(sourceCode);\n \n // Walk the AST and find string literals to truncate\n walk(ast as unknown as Node, {\n enter(node: Node) {\n // Handle regular string literals\n if (node.type === 'Literal' && typeof (node as any).value === 'string') {\n const literal = node as any;\n const value = literal.value as string;\n \n if (value.length > limit && literal.start !== undefined && literal.end !== undefined) {\n const truncated = createTruncatedString(value, previewLength);\n // Wrap in quotes matching the original\n const originalText = sourceCode.slice(literal.start, literal.end);\n const quote = originalText[0]; // Get the quote character used\n magicString.overwrite(literal.start, literal.end, `${quote}${truncated}${quote}`);\n }\n }\n \n // Handle template literals\n if (node.type === 'TemplateLiteral') {\n const template = node as any;\n \n // Process each quasi (template element)\n for (const quasi of template.quasis) {\n const value = quasi.value.raw as string;\n \n if (value.length > limit && quasi.start !== undefined && quasi.end !== undefined) {\n const truncated = createTruncatedString(value, previewLength);\n // Template literal quasis don't have surrounding quotes\n magicString.overwrite(quasi.start, quasi.end, truncated);\n }\n }\n }\n }\n });\n\n return magicString.toString();\n}\n"],
|
|
5
|
-
"mappings": ";;;AAAA,SAAS,cAAc;AACvB,SAAS,4BAA4B;AACrC;AAAA,EACE;AAAA,EACA;AAAA,OACK;AACP,SAAS,SAAS;AAClB,SAAS,yBAAyB;;;ACPlC,YAAY,aAAa;AACzB,YAAY,YAAY;AACxB,YAAY,QAAQ;AACpB,YAAY,UAAU;AACtB,YAAY,QAAQ;AAEpB,IAAM,WAAgB,UAAQ,UAAO,GAAG,iBAAiB;AAmBzD,eAAe,iBAAgC;AAC7C,QAAS,SAAM,UAAU,EAAE,WAAW,KAAK,CAAC;AAC9C;AAKA,SAAS,kBAAkB,cAAsB,SAAyB;AACxE,QAAM,UAAU,GAAG,YAAY,IAAI,OAAO;AAC1C,SAAc,kBAAW,KAAK,EAAE,OAAO,OAAO,EAAE,OAAO,KAAK;AAC9D;AAKA,SAAS,cAAc,cAAsB,MAA2D;AACtG,QAAM,WAAgB,cAAS,cAAc,KAAK;AAClD,QAAM,iBAAsB,UAAK,UAAU,GAAG,QAAQ,IAAI,IAAI,gBAAgB;AAC9E,QAAM,UAAU,GAAG,cAAc;AACjC,SAAO,EAAE,gBAAgB,QAAQ;AACnC;AAMA,eAAe,aAAa,gBAAwB,SAAmC;AACrF,MAAI;AACF,UAAM,Q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MAAM,WAAW,KAAK,IAAI,QAAQ;AAE1C,MAAI,SAAS,mBAAmB;AAC9B,UAAM,IAAI,MAAM,mBAAmB,IAAI,EAAE;AAAA,EAC3C;AAEA,MAAI;AAEF,UAAM,QAAQ,yBAAyB,MAAM,IAAI;AACjD,UAAM,SAAS,MAAM,oBAAoB,KAAK;AAE9C,WAAO;AAAA,MACL,SAAS,CAAC,EAAE,MAAM,QAAQ,MAAM,OAAO,CAAC;AAAA,IAC1C;AAAA,EACF,SAAS,OAAO;AACd,UAAM,UAAU,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;AACrE,WAAO;AAAA,MACL,SAAS,CAAC,EAAE,MAAM,QAAQ,MAAM,UAAU,OAAO,GAAG,CAAC;AAAA,MACrD,SAAS;AAAA,IACX;AAAA,EACF;AACF,CAAC;AAGD,eAAe,OAAO;AACpB,QAAM,YAAY,IAAI,qBAAqB;AAC3C,QAAM,OAAO,QAAQ,SAAS;AAC9B,UAAQ,MAAM,4CAA4C;AAC5D;AAEA,KAAK,EAAE,MAAM,CAAC,UAAU;AACtB,UAAQ,MAAM,gBAAgB,KAAK;AACnC,UAAQ,KAAK,CAAC;AAChB,CAAC;",
|
|
6
|
-
"names": ["code"]
|
|
3
|
+
"sources": ["../src/server.ts", "../src/tools/readCodeSmart.ts", "../src/tools/ToolDefinition.ts", "../src/beautifier.ts", "../src/truncator.ts", "../src/tools/applyCustomTransform.ts", "../src/transformer.ts", "../src/tools/searchCodeSmart.ts", "../src/searcher.ts", "../src/tools/findUsageSmart.ts", "../src/analyzer.ts", "../src/tools/index.ts"],
|
|
4
|
+
"sourcesContent": ["import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';\nimport { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';\nimport { z } from 'zod';\nimport { tools } from './tools/index.js';\n\n// Create MCP Server instance\nconst server = new McpServer({\n name: 'jsvmp-smart-fs',\n version: '1.0.0',\n});\n\n/**\n * Register a tool with the MCP server.\n * Converts ToolDefinition to MCP tool registration format.\n * \n * @param tool - The tool definition to register\n */\nfunction registerTool(tool: {\n name: string;\n description: string;\n schema: z.ZodRawShape;\n handler: (params: Record<string, unknown>) => Promise<string>;\n}): void {\n // Create Zod object schema from raw shape for validation\n const zodSchema = z.object(tool.schema);\n\n // Register the tool with MCP server using registerTool API\n server.registerTool(\n tool.name,\n {\n description: tool.description,\n inputSchema: tool.schema,\n },\n async (params, _extra) => {\n try {\n // Validate and parse input using the Zod schema\n const validatedParams = zodSchema.parse(params);\n const result = await tool.handler(validatedParams as Record<string, unknown>);\n\n return {\n content: [{ type: 'text' as const, text: result }],\n };\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n return {\n content: [{ type: 'text' as const, text: `Error: ${message}` }],\n isError: true,\n };\n }\n }\n );\n}\n\n// Register all tools from the tools array\nfor (const tool of tools) {\n registerTool(tool as unknown as {\n name: string;\n description: string;\n schema: z.ZodRawShape;\n handler: (params: Record<string, unknown>) => Promise<string>;\n });\n}\n\n// Main entry point\nasync function main() {\n const transport = new StdioServerTransport();\n await server.connect(transport);\n console.error('JSVMP Smart FS MCP Server running on stdio');\n}\n\nmain().catch((error) => {\n console.error('Fatal error:', error);\n process.exit(1);\n});\n", "import { z } from 'zod';\nimport { SourceMapConsumer } from 'source-map-js';\nimport { defineTool } from './ToolDefinition.js';\nimport { ensureBeautified } from '../beautifier.js';\nimport { truncateCodeHighPerf, truncateLongLines } from '../truncator.js';\n\n/**\n * Format source position as \"L{line}:{column}\" or empty placeholder\n */\nfunction formatSourcePosition(line: number | null, column: number | null): string {\n if (line !== null && column !== null) {\n return `L${line}:${column}`;\n }\n return '';\n}\n\n/**\n * Format output header with file info\n */\nfunction formatHeader(filePath: string, startLine: number, endLine: number, totalLines: number): string {\n return [\n `FILE: ${filePath}`,\n `VIEW: Auto-beautified (Lines ${startLine}-${endLine} of ${totalLines})`,\n `INFO: [Src L:C] = Location in original minified file (for Chrome Breakpoints)`,\n '-'.repeat(85),\n ].join('\\n');\n}\n\n/**\n * Format a single code line with line number, source coordinates, and content\n */\nfunction formatCodeLine(lineNumber: number, sourcePos: string, code: string, maxLineNumWidth: number): string {\n const lineNumStr = String(lineNumber).padStart(maxLineNumWidth, ' ');\n const srcPosStr = sourcePos ? `Src ${sourcePos}` : '';\n const srcPosPadded = srcPosStr.padEnd(14, ' ');\n return `${lineNumStr} | [${srcPosPadded}] | ${code}`;\n}\n\n/**\n * Format pagination hint\n */\nfunction formatPaginationHint(nextStartLine: number): string {\n return `\\n... (Use next start_line=${nextStartLine} to read more)`;\n}\n\n/**\n * read_code_smart tool definition\n * Read and beautify minified/obfuscated JavaScript code with source map coordinates.\n */\nexport const readCodeSmart = defineTool({\n name: 'read_code_smart',\n description:\n 'Read and beautify minified/obfuscated JavaScript code with source map coordinates. ' +\n 'Returns formatted code with original file positions for setting breakpoints. ' +\n 'Optionally saves the beautified file locally alongside the original file.',\n schema: {\n file_path: z.string().describe('Path to the JavaScript file'),\n start_line: z.number().int().min(1).describe('Start line number (1-based)'),\n end_line: z.number().int().min(1).describe('End line number (1-based)'),\n char_limit: z.number().int().min(50).default(300).describe('Character limit for string truncation'),\n max_line_chars: z.number().int().min(80).default(500).describe('Maximum characters per line'),\n save_local: z.boolean().optional().default(false).describe('Save beautified file to the same directory as the original file'),\n },\n handler: async (params) => {\n const { file_path, start_line, end_line, char_limit, max_line_chars, save_local } = params;\n\n // Beautify the file and get source map\n const beautifyResult = await ensureBeautified(file_path, { saveLocal: save_local });\n const { code, rawMap, localPath, localMapPath, localSaveError } = beautifyResult;\n\n // Truncate long strings\n const truncatedCode = truncateCodeHighPerf(code, char_limit);\n\n // Truncate long lines\n const lineTruncatedCode = truncateLongLines(truncatedCode, max_line_chars);\n\n // Split into lines\n const lines = lineTruncatedCode.split('\\n');\n const totalLines = lines.length;\n\n // Validate line range\n const effectiveStartLine = Math.max(1, start_line);\n const effectiveEndLine = Math.min(totalLines, end_line);\n\n if (effectiveStartLine > totalLines) {\n throw new Error(`Start line ${start_line} exceeds total lines ${totalLines}`);\n }\n\n // Create source map consumer (cast version to string as required by source-map-js)\n const consumer = new SourceMapConsumer({\n ...rawMap,\n version: String(rawMap.version),\n });\n\n // Build output\n const outputParts: string[] = [];\n\n // Add header\n outputParts.push(formatHeader(file_path, effectiveStartLine, effectiveEndLine, totalLines));\n\n // Add local save info if applicable\n if (save_local) {\n if (localPath) {\n outputParts.push(`LOCAL: ${localPath}`);\n if (localMapPath) {\n outputParts.push(`LOCAL_MAP: ${localMapPath}`);\n }\n }\n if (localSaveError) {\n outputParts.push(`LOCAL_SAVE_ERROR: ${localSaveError}`);\n }\n outputParts.push('-'.repeat(85));\n }\n\n // Calculate max line number width for alignment\n const maxLineNumWidth = String(effectiveEndLine).length;\n\n // Format each line\n for (let lineNum = effectiveStartLine; lineNum <= effectiveEndLine; lineNum++) {\n const lineIndex = lineNum - 1;\n const lineContent = lines[lineIndex] ?? '';\n\n // Get original position from source map\n const originalPos = consumer.originalPositionFor({\n line: lineNum,\n column: 0,\n });\n\n const sourcePos = formatSourcePosition(originalPos.line, originalPos.column);\n outputParts.push(formatCodeLine(lineNum, sourcePos, lineContent, maxLineNumWidth));\n }\n\n // Add pagination hint if there are more lines\n if (effectiveEndLine < totalLines) {\n outputParts.push(formatPaginationHint(effectiveEndLine + 1));\n }\n\n return outputParts.join('\\n');\n },\n});\n", "import { z } from 'zod';\n\n/**\n * Tool definition interface for MCP tools.\n * Each tool has a name, description, schema (Zod raw shape), and async handler.\n */\nexport interface ToolDefinition<TSchema extends z.ZodRawShape = z.ZodRawShape> {\n /** Unique tool name (e.g., 'read_code_smart') */\n name: string;\n /** Human-readable description of what the tool does */\n description: string;\n /** Zod schema object defining input parameters */\n schema: TSchema;\n /** Async handler function that processes the tool request */\n handler: (params: z.infer<z.ZodObject<TSchema>>) => Promise<string>;\n}\n\n/**\n * Helper function to create a type-safe tool definition.\n * Validates the tool definition structure at compile time.\n * \n * @param definition - The tool definition object\n * @returns The same definition with proper typing\n */\nexport function defineTool<TSchema extends z.ZodRawShape>(\n definition: ToolDefinition<TSchema>\n): ToolDefinition<TSchema> {\n return definition;\n}\n", "import * as esbuild from 'esbuild';\nimport * as crypto from 'crypto';\nimport * as fs from 'fs/promises';\nimport * as path from 'path';\nimport * as os from 'os';\n\nconst TEMP_DIR = path.join(os.tmpdir(), 'jsvmp-mcp-cache');\n\nexport interface SourceMap {\n version: number;\n sources: string[];\n names: string[];\n mappings: string;\n file?: string;\n sourceRoot?: string;\n}\n\nexport interface BeautifyOptions {\n /** \u662F\u5426\u4FDD\u5B58\u5230\u539F\u59CB\u6587\u4EF6\u540C\u7EA7\u76EE\u5F55 */\n saveLocal?: boolean;\n}\n\nexport interface BeautifyResult {\n code: string;\n rawMap: SourceMap;\n /** \u672C\u5730\u4FDD\u5B58\u7684\u7F8E\u5316\u6587\u4EF6\u8DEF\u5F84 (\u4EC5\u5F53 saveLocal=true \u65F6\u5B58\u5728) */\n localPath?: string;\n /** \u672C\u5730\u4FDD\u5B58\u7684 source map \u8DEF\u5F84 (\u4EC5\u5F53 saveLocal=true \u65F6\u5B58\u5728) */\n localMapPath?: string;\n /** \u672C\u5730\u4FDD\u5B58\u5931\u8D25\u65F6\u7684\u9519\u8BEF\u4FE1\u606F */\n localSaveError?: string;\n}\n\n/**\n * Ensure the cache directory exists\n */\nasync function ensureCacheDir(): Promise<void> {\n await fs.mkdir(TEMP_DIR, { recursive: true });\n}\n\n/**\n * Calculate cache key based on file path and modification time\n */\nfunction calculateCacheKey(originalPath: string, mtimeMs: number): string {\n const fileKey = `${originalPath}-${mtimeMs}`;\n return crypto.createHash('md5').update(fileKey).digest('hex');\n}\n\n/**\n * Get cache file paths for a given original file\n */\nfunction getCachePaths(originalPath: string, hash: string): { beautifiedPath: string; mapPath: string } {\n const fileName = path.basename(originalPath, '.js');\n const beautifiedPath = path.join(TEMP_DIR, `${fileName}.${hash}.beautified.js`);\n const mapPath = `${beautifiedPath}.map`;\n return { beautifiedPath, mapPath };\n}\n\n\n/**\n * Local paths result interface\n */\nexport interface LocalPaths {\n /** Path to the beautified file in the same directory as the original */\n beautifiedPath: string;\n /** Path to the source map file in the same directory as the original */\n mapPath: string;\n}\n\n/**\n * Get local file paths for beautified output\n * Given an original file path, returns the paths where the beautified file\n * and source map should be saved in the same directory.\n * \n * Naming convention:\n * - Original: {filename}.js -> Beautified: {filename}.beautified.js\n * - Source map: {filename}.beautified.js.map\n * \n * @param originalPath - Path to the original JavaScript file\n * @returns Object containing beautifiedPath and mapPath\n */\nexport function getLocalPaths(originalPath: string): LocalPaths {\n const absolutePath = path.resolve(originalPath);\n const dir = path.dirname(absolutePath);\n const ext = path.extname(absolutePath);\n const baseName = path.basename(absolutePath, ext);\n \n const beautifiedPath = path.join(dir, `${baseName}.beautified.js`);\n const mapPath = `${beautifiedPath}.map`;\n \n return { beautifiedPath, mapPath };\n}\n\n/**\n * Check if cache exists and is valid (for temp directory cache)\n */\nasync function isCacheValid(beautifiedPath: string, mapPath: string): Promise<boolean> {\n try {\n await Promise.all([\n fs.access(beautifiedPath),\n fs.access(mapPath)\n ]);\n return true;\n } catch {\n return false;\n }\n}\n\n/**\n * Local cache validation result interface\n */\nexport interface LocalCacheCheck {\n /** Original file modification time in milliseconds */\n originalMtime: number;\n /** Whether the beautified file exists */\n beautifiedExists: boolean;\n /** Beautified file modification time in milliseconds (0 if not exists) */\n beautifiedMtime: number;\n /** Whether the cache is valid (beautifiedMtime >= originalMtime) */\n isValid: boolean;\n}\n\n/**\n * Check if local beautified cache is valid\n * \n * A local cache is considered valid when:\n * 1. The beautified file exists\n * 2. The beautified file's modification time is >= the original file's modification time\n * \n * @param originalPath - Path to the original JavaScript file\n * @returns LocalCacheCheck object with validation details\n */\nexport async function isLocalCacheValid(originalPath: string): Promise<LocalCacheCheck> {\n const absolutePath = path.resolve(originalPath);\n const { beautifiedPath } = getLocalPaths(absolutePath);\n \n // Get original file stats\n let originalStats: Awaited<ReturnType<typeof fs.stat>>;\n try {\n originalStats = await fs.stat(absolutePath);\n } catch {\n // Original file doesn't exist - cache cannot be valid\n return {\n originalMtime: 0,\n beautifiedExists: false,\n beautifiedMtime: 0,\n isValid: false\n };\n }\n \n const originalMtime = originalStats.mtimeMs;\n \n // Check if beautified file exists and get its stats\n let beautifiedStats: Awaited<ReturnType<typeof fs.stat>>;\n try {\n beautifiedStats = await fs.stat(beautifiedPath);\n } catch {\n // Beautified file doesn't exist\n return {\n originalMtime,\n beautifiedExists: false,\n beautifiedMtime: 0,\n isValid: false\n };\n }\n \n const beautifiedMtime = beautifiedStats.mtimeMs;\n const isValid = beautifiedMtime >= originalMtime;\n \n return {\n originalMtime,\n beautifiedExists: true,\n beautifiedMtime,\n isValid\n };\n}\n\n/**\n * Beautify JavaScript file and generate Source Map\n * @param originalPath - Original file path\n * @param options - Optional beautify options (saveLocal, etc.)\n * @returns Beautified code and Source Map\n */\nexport async function ensureBeautified(\n originalPath: string,\n options?: BeautifyOptions\n): Promise<BeautifyResult> {\n // Resolve to absolute path\n const absolutePath = path.resolve(originalPath);\n const saveLocal = options?.saveLocal ?? false;\n \n // Check if file exists\n let stats: Awaited<ReturnType<typeof fs.stat>>;\n try {\n stats = await fs.stat(absolutePath);\n } catch {\n throw new Error(`File not found: ${originalPath}`);\n }\n \n // Get local paths for potential local save/read\n const localPaths = getLocalPaths(absolutePath);\n \n // If saveLocal is true, check local cache first\n if (saveLocal) {\n const localCacheCheck = await isLocalCacheValid(absolutePath);\n if (localCacheCheck.isValid) {\n // Local cache hit - read from local files\n try {\n const [code, mapContent] = await Promise.all([\n fs.readFile(localPaths.beautifiedPath, 'utf-8'),\n fs.readFile(localPaths.mapPath, 'utf-8')\n ]);\n return {\n code,\n rawMap: JSON.parse(mapContent) as SourceMap,\n localPath: localPaths.beautifiedPath,\n localMapPath: localPaths.mapPath\n };\n } catch {\n // If reading local cache fails, fall through to regenerate\n }\n }\n }\n \n // Ensure temp cache directory exists\n await ensureCacheDir();\n \n // Calculate cache key for temp directory\n const hash = calculateCacheKey(absolutePath, stats.mtimeMs);\n const { beautifiedPath, mapPath } = getCachePaths(absolutePath, hash);\n \n // Check temp cache\n if (await isCacheValid(beautifiedPath, mapPath)) {\n // Temp cache hit - read from cache\n const [code, mapContent] = await Promise.all([\n fs.readFile(beautifiedPath, 'utf-8'),\n fs.readFile(mapPath, 'utf-8')\n ]);\n \n const result: BeautifyResult = {\n code,\n rawMap: JSON.parse(mapContent) as SourceMap\n };\n \n // If saveLocal is true, also save to local directory\n if (saveLocal) {\n await saveToLocal(result, localPaths, mapContent);\n }\n \n return result;\n }\n \n // Cache miss - beautify with Esbuild\n let esbuildResult: esbuild.BuildResult;\n try {\n esbuildResult = await esbuild.build({\n entryPoints: [absolutePath],\n bundle: false,\n write: false,\n format: 'esm',\n sourcemap: 'external',\n sourcesContent: false,\n outfile: 'out.js',\n // Beautify settings\n minify: false,\n keepNames: true,\n treeShaking: false,\n });\n } catch (err) {\n const message = err instanceof Error ? err.message : String(err);\n throw new Error(`Esbuild processing failed: ${message}`);\n }\n \n // Extract code and source map from result\n const codeFile = esbuildResult.outputFiles?.find(f => f.path.endsWith('.js'));\n const mapFile = esbuildResult.outputFiles?.find(f => f.path.endsWith('.map'));\n \n if (!codeFile || !mapFile) {\n throw new Error('Esbuild processing failed: Missing output files');\n }\n \n const code = codeFile.text;\n const rawMap = JSON.parse(mapFile.text) as SourceMap;\n const mapText = mapFile.text;\n \n // Write to temp cache\n await Promise.all([\n fs.writeFile(beautifiedPath, code, 'utf-8'),\n fs.writeFile(mapPath, mapText, 'utf-8')\n ]);\n \n const result: BeautifyResult = { code, rawMap };\n \n // If saveLocal is true, also save to local directory\n if (saveLocal) {\n await saveToLocal(result, localPaths, mapText);\n }\n \n return result;\n}\n\n/**\n * Save beautified code and source map to local directory\n * Handles errors gracefully by setting localSaveError instead of throwing\n */\nasync function saveToLocal(\n result: BeautifyResult,\n localPaths: LocalPaths,\n mapText: string\n): Promise<void> {\n try {\n await Promise.all([\n fs.writeFile(localPaths.beautifiedPath, result.code, 'utf-8'),\n fs.writeFile(localPaths.mapPath, mapText, 'utf-8')\n ]);\n result.localPath = localPaths.beautifiedPath;\n result.localMapPath = localPaths.mapPath;\n } catch (err) {\n // Handle specific error types\n const error = err as NodeJS.ErrnoException;\n if (error.code === 'EACCES' || error.code === 'EPERM') {\n result.localSaveError = `Permission denied: Cannot write to ${path.dirname(localPaths.beautifiedPath)}`;\n } else if (error.code === 'ENOSPC') {\n result.localSaveError = `Insufficient disk space: Cannot write to ${path.dirname(localPaths.beautifiedPath)}`;\n } else {\n result.localSaveError = `Failed to save locally: ${error.message || String(err)}`;\n }\n // Don't throw - the temp cache result is still valid\n }\n}\n", "import { parse } from 'meriyah';\nimport { walk } from 'estree-walker';\nimport MagicString from 'magic-string';\nimport type { Node } from 'estree';\n\n/**\n * Count newlines in a string\n */\nfunction countNewlines(str: string): number {\n let count = 0;\n for (const char of str) {\n if (char === '\\n') count++;\n }\n return count;\n}\n\n/**\n * Create truncated string with preserved newlines\n * Format: \"start ...[TRUNCATED {length} CHARS]... \\n\\n\\nend\"\n */\nfunction createTruncatedString(original: string, previewLength: number): string {\n const newlineCount = countNewlines(original);\n const start = original.slice(0, previewLength);\n const end = original.slice(-previewLength);\n \n // Build the truncation marker with preserved newlines\n const marker = `...[TRUNCATED ${original.length} CHARS]...`;\n \n // Create newlines to preserve line count\n // We need to account for newlines already in start and end portions\n const startNewlines = countNewlines(start);\n const endNewlines = countNewlines(end);\n const preservedNewlines = Math.max(0, newlineCount - startNewlines - endNewlines);\n const newlineStr = '\\n'.repeat(preservedNewlines);\n \n return `${start}${marker}${newlineStr}${end}`;\n}\n\n/**\n * Truncate long strings in JavaScript code while preserving line numbers\n * @param sourceCode - Source code to process\n * @param limit - Character limit for strings (default 200)\n * @param previewLength - Length of start/end preview portions (default 50)\n * @returns Truncated code with preserved line count\n */\nexport function truncateCodeHighPerf(sourceCode: string, limit: number = 200, previewLength: number = 50): string {\n // Try to parse the AST\n let ast: ReturnType<typeof parse>;\n try {\n ast = parse(sourceCode, {\n module: true,\n next: true,\n ranges: true,\n loc: true,\n raw: true,\n });\n } catch {\n // AST parsing failed - return original code unchanged (Requirement 2.4)\n return sourceCode;\n }\n\n const magicString = new MagicString(sourceCode);\n \n // Walk the AST and find string literals to truncate\n walk(ast as unknown as Node, {\n enter(node: Node) {\n // Handle regular string literals\n if (node.type === 'Literal' && typeof (node as any).value === 'string') {\n const literal = node as any;\n const value = literal.value as string;\n \n if (value.length > limit && literal.start !== undefined && literal.end !== undefined) {\n const truncated = createTruncatedString(value, previewLength);\n // Wrap in quotes matching the original\n const originalText = sourceCode.slice(literal.start, literal.end);\n const quote = originalText[0]; // Get the quote character used\n magicString.overwrite(literal.start, literal.end, `${quote}${truncated}${quote}`);\n }\n }\n \n // Handle template literals\n if (node.type === 'TemplateLiteral') {\n const template = node as any;\n \n // Process each quasi (template element)\n for (const quasi of template.quasis) {\n const value = quasi.value.raw as string;\n \n if (value.length > limit && quasi.start !== undefined && quasi.end !== undefined) {\n const truncated = createTruncatedString(value, previewLength);\n // Template literal quasis don't have surrounding quotes\n magicString.overwrite(quasi.start, quasi.end, truncated);\n }\n }\n }\n }\n });\n\n return magicString.toString();\n}\n\n/**\n * Truncate lines that exceed the maximum character limit\n * @param code - Source code to process\n * @param maxLineChars - Maximum characters per line (default 500)\n * @param previewRatio - Ratio of line to show at start/end (default 0.2)\n * @returns Code with truncated long lines\n */\nexport function truncateLongLines(\n code: string,\n maxLineChars: number = 500,\n previewRatio: number = 0.2\n): string {\n if (!code) {\n return code;\n }\n\n const lines = code.split('\\n');\n const previewLength = Math.floor(maxLineChars * previewRatio);\n\n const processedLines = lines.map((line) => {\n if (line.length <= maxLineChars) {\n return line;\n }\n\n const start = line.slice(0, previewLength);\n const end = line.slice(-previewLength);\n const truncatedChars = line.length - previewLength * 2;\n const marker = `...[LINE TRUNCATED ${truncatedChars} CHARS]...`;\n\n return `${start}${marker}${end}`;\n });\n\n return processedLines.join('\\n');\n}\n", "import { z } from 'zod';\nimport { defineTool } from './ToolDefinition.js';\nimport { applyCustomTransform as runTransform } from '../transformer.js';\n\n/**\n * Schema for apply_custom_transform tool input validation\n */\nexport const ApplyCustomTransformInputSchema = z.object({\n target_file: z.string().describe('Path to the JavaScript file to transform'),\n script_path: z.string().describe('Path to a JS file exporting a Babel Plugin function'),\n output_suffix: z.string().default('_deob').describe('Suffix for output file name'),\n});\n\n/**\n * apply_custom_transform tool definition\n * Apply a custom Babel transformation to deobfuscate JavaScript code.\n */\nexport const applyCustomTransform = defineTool({\n name: 'apply_custom_transform',\n description:\n 'Apply a custom Babel transformation to deobfuscate JavaScript code. ' +\n 'Takes a target JS file and a Babel plugin script, runs the transformation, ' +\n 'and outputs the deobfuscated code with a cascaded source map that traces back to the original minified file. ' +\n 'The plugin script should export a function that returns a Babel visitor object.',\n schema: {\n target_file: z.string().describe('Path to the JavaScript file to transform'),\n script_path: z.string().describe('Path to a JS file exporting a Babel Plugin function'),\n output_suffix: z.string().default('_deob').describe('Suffix for output file name'),\n },\n handler: async (params) => {\n const { target_file, script_path, output_suffix } = params;\n\n // Call the transform function\n const result = await runTransform(target_file, {\n scriptPath: script_path,\n outputSuffix: output_suffix,\n });\n\n // Return success message with created file paths\n const successMessage = [\n 'Transform completed successfully!',\n '',\n `Output file: ${result.outputPath}`,\n `Source map: ${result.mapPath}`,\n ].join('\\n');\n\n return successMessage;\n },\n});\n", "import * as path from 'path';\nimport * as fs from 'fs/promises';\nimport { transformSync, type BabelFileResult, type PluginItem } from '@babel/core';\nimport { ensureBeautified, type SourceMap } from './beautifier.js';\n\n/**\n * Transform options interface\n */\nexport interface TransformOptions {\n /** Path to the user's Babel plugin script */\n scriptPath: string;\n /** Output file suffix (default \"_deob\") */\n outputSuffix?: string;\n}\n\n/**\n * Transform result interface\n */\nexport interface TransformResult {\n /** Transformed code */\n code: string;\n /** Cascaded Source Map */\n map: SourceMap;\n /** Output file path */\n outputPath: string;\n /** Source Map file path */\n mapPath: string;\n}\n\n/**\n * Output paths interface\n */\nexport interface OutputPaths {\n /** Output JS file path */\n outputPath: string;\n /** Source Map file path */\n mapPath: string;\n}\n\n/**\n * Clean basename by removing .beautified and _deob* suffixes\n * \n * Examples:\n * - main.js -> main\n * - main.beautified.js -> main\n * - main_deob.js -> main\n * - main.beautified_deob.js -> main\n * - main_deob_v2.js -> main\n * \n * @param filename - Original filename (with or without path)\n * @returns Cleaned basename without extension\n */\nexport function cleanBasename(filename: string): string {\n // Get just the filename without directory\n const base = path.basename(filename);\n \n // Remove .js extension\n let name = base.endsWith('.js') ? base.slice(0, -3) : base;\n \n // Remove _deob* suffix first (e.g., _deob, _deob_v2, _deob123)\n // This handles cases like main.beautified_deob.js\n name = name.replace(/_deob[^/]*$/, '');\n \n // Remove .beautified suffix if present\n if (name.endsWith('.beautified')) {\n name = name.slice(0, -'.beautified'.length);\n }\n \n return name;\n}\n\n/**\n * Calculate output paths for transformed file\n * \n * @param targetFile - Path to the target file\n * @param outputSuffix - Suffix for output file (default \"_deob\")\n * @returns Output paths for JS and map files\n */\nexport function getOutputPaths(targetFile: string, outputSuffix: string = '_deob'): OutputPaths {\n const absolutePath = path.resolve(targetFile);\n const dir = path.dirname(absolutePath);\n const basename = cleanBasename(absolutePath);\n \n const outputPath = path.join(dir, `${basename}${outputSuffix}.js`);\n const mapPath = `${outputPath}.map`;\n \n return { outputPath, mapPath };\n}\n\n/**\n * Babel plugin function type\n * A Babel plugin is a function that receives babel API and returns a visitor object\n */\nexport type BabelPluginFunction = (babel: { types: typeof import('@babel/types') }) => {\n visitor: Record<string, unknown>;\n};\n\n/**\n * Load a Babel plugin script from the given path\n * \n * Features:\n * - Resolves to absolute path\n * - Clears require cache for hot-reloading\n * - Validates plugin format\n * \n * @param scriptPath - Path to the Babel plugin script\n * @returns The loaded Babel plugin function\n * @throws Error if script not found or invalid format\n */\nexport async function loadBabelPlugin(scriptPath: string): Promise<BabelPluginFunction> {\n // Resolve to absolute path\n const absolutePath = path.resolve(scriptPath);\n \n // Check if file exists\n try {\n await fs.access(absolutePath);\n } catch {\n throw new Error(`Script not found: ${absolutePath}`);\n }\n \n // Convert to file URL for ESM import\n const fileUrl = `file://${absolutePath}?t=${Date.now()}`;\n \n // Dynamic import with cache busting for hot-reload\n let module: unknown;\n try {\n module = await import(fileUrl);\n } catch (err) {\n const message = err instanceof Error ? err.message : String(err);\n throw new Error(`Failed to load script: ${message}`);\n }\n \n // Extract the plugin function\n const plugin = (module as { default?: unknown }).default ?? module;\n \n // Validate plugin format - must be a function\n if (typeof plugin !== 'function') {\n throw new Error(\n `Invalid Babel plugin: Script must export a function that returns a visitor object. ` +\n `Got ${typeof plugin} instead.`\n );\n }\n \n return plugin as BabelPluginFunction;\n}\n\n\n/**\n * Babel transform result interface\n */\ninterface BabelTransformResult {\n /** Transformed code */\n code: string;\n /** Generated source map (cascaded) */\n map: SourceMap;\n}\n\n/**\n * Run Babel transform with source map cascade\n * \n * Configuration:\n * - inputSourceMap: Enables cascade from beautified -> original\n * - sourceMaps: true to generate output source map\n * - retainLines: false for best readability\n * - compact: false for readable output\n * - minified: false for readable output\n * \n * @param code - Input code (beautified)\n * @param inputSourceMap - Source map from beautifier (beautified -> original)\n * @param plugin - Babel plugin function\n * @param filename - Original filename for source map\n * @returns Transformed code and cascaded source map\n */\nexport function runBabelTransform(\n code: string,\n inputSourceMap: SourceMap,\n plugin: BabelPluginFunction,\n filename: string\n): BabelTransformResult {\n let result: BabelFileResult | null;\n \n try {\n result = transformSync(code, {\n filename,\n plugins: [plugin as PluginItem],\n // Source map configuration for cascade\n // @ts-expect-error - SourceMap is compatible with InputSourceMap at runtime\n inputSourceMap: inputSourceMap,\n sourceMaps: true,\n // Readability settings\n retainLines: false,\n compact: false,\n minified: false,\n // Preserve code structure\n parserOpts: {\n sourceType: 'unambiguous',\n },\n });\n } catch (err) {\n const message = err instanceof Error ? err.message : String(err);\n throw new Error(`Babel Error: ${message}`);\n }\n \n if (!result || !result.code) {\n throw new Error('Babel Error: Transform produced no output');\n }\n \n if (!result.map) {\n throw new Error('Babel Error: Transform produced no source map');\n }\n \n return {\n code: result.code,\n map: result.map as unknown as SourceMap,\n };\n}\n\n\n/**\n * Apply custom Babel transform to a JavaScript file\n * \n * Process:\n * 1. Load and validate the Babel plugin script\n * 2. Get beautified code and source map from target file\n * 3. Run Babel transform with source map cascade\n * 4. Write output file and source map\n * 5. Append sourceMappingURL comment\n * \n * @param targetFile - Path to the JavaScript file to transform\n * @param options - Transform options (scriptPath, outputSuffix)\n * @returns Transform result with output paths\n */\nexport async function applyCustomTransform(\n targetFile: string,\n options: TransformOptions\n): Promise<TransformResult> {\n const { scriptPath, outputSuffix = '_deob' } = options;\n \n // Resolve target file path\n const absoluteTargetPath = path.resolve(targetFile);\n \n // Check if target file exists\n try {\n await fs.access(absoluteTargetPath);\n } catch {\n throw new Error(`File not found: ${targetFile}`);\n }\n \n // Load the Babel plugin script\n const plugin = await loadBabelPlugin(scriptPath);\n \n // Get beautified code and source map\n const beautifyResult = await ensureBeautified(absoluteTargetPath);\n const { code: beautifiedCode, rawMap: inputSourceMap } = beautifyResult;\n \n // Run Babel transform with source map cascade\n const transformResult = runBabelTransform(\n beautifiedCode,\n inputSourceMap,\n plugin,\n absoluteTargetPath\n );\n \n // Calculate output paths\n const { outputPath, mapPath } = getOutputPaths(absoluteTargetPath, outputSuffix);\n \n // Prepare output code with sourceMappingURL comment\n const mapFileName = path.basename(mapPath);\n const outputCode = `${transformResult.code}\\n//# sourceMappingURL=${mapFileName}`;\n \n // Prepare source map with correct file reference\n const outputMap: SourceMap = {\n ...transformResult.map,\n file: path.basename(outputPath),\n };\n \n // Write output files\n try {\n await Promise.all([\n fs.writeFile(outputPath, outputCode, 'utf-8'),\n fs.writeFile(mapPath, JSON.stringify(outputMap, null, 2), 'utf-8'),\n ]);\n } catch (err) {\n const error = err as NodeJS.ErrnoException;\n if (error.code === 'EACCES' || error.code === 'EPERM') {\n throw new Error(`Permission denied: Cannot write to ${path.dirname(outputPath)}`);\n }\n throw new Error(`Failed to write output files: ${error.message || String(err)}`);\n }\n \n return {\n code: outputCode,\n map: outputMap,\n outputPath,\n mapPath,\n };\n}\n", "import { z } from 'zod';\nimport { defineTool } from './ToolDefinition.js';\nimport { ensureBeautified } from '../beautifier.js';\nimport { truncateCodeHighPerf, truncateLongLines } from '../truncator.js';\nimport { searchInCode, formatSearchResult } from '../searcher.js';\n\n/**\n * Schema for search_code_smart tool input validation\n */\nexport const SearchCodeSmartInputSchema = z.object({\n file_path: z.string().describe('Path to the JavaScript file'),\n query: z.string().describe('Regex pattern or text to search'),\n context_lines: z.number().int().min(0).default(2).describe('Number of context lines'),\n case_sensitive: z.boolean().default(false).describe('Case sensitive search'),\n char_limit: z.number().int().min(50).default(300).describe('Character limit for string truncation'),\n max_line_chars: z.number().int().min(80).default(500).describe('Maximum characters per line'),\n});\n\n/**\n * search_code_smart tool definition\n * Search for text or regex patterns in beautified JavaScript code.\n */\nexport const searchCodeSmart = defineTool({\n name: 'search_code_smart',\n description:\n 'Search for text or regex patterns in beautified JavaScript code. ' +\n 'Returns matching lines with context and original source coordinates for setting breakpoints. ' +\n 'Useful for finding code patterns in minified/obfuscated files.',\n schema: {\n file_path: z.string().describe('Path to the JavaScript file'),\n query: z.string().describe('Regex pattern or text to search'),\n context_lines: z.number().int().min(0).default(2).describe('Number of context lines'),\n case_sensitive: z.boolean().default(false).describe('Case sensitive search'),\n char_limit: z.number().int().min(50).default(300).describe('Character limit for string truncation'),\n max_line_chars: z.number().int().min(80).default(500).describe('Maximum characters per line'),\n },\n handler: async (params) => {\n const { file_path, query, context_lines, case_sensitive, char_limit, max_line_chars } = params;\n\n // Beautify the file and get source map\n const beautifyResult = await ensureBeautified(file_path);\n const { code, rawMap } = beautifyResult;\n\n // Truncate long strings before searching\n const truncatedCode = truncateCodeHighPerf(code, char_limit);\n\n // Execute search\n const searchResult = searchInCode(truncatedCode, rawMap, {\n query,\n contextLines: context_lines,\n caseSensitive: case_sensitive,\n maxMatches: 50,\n });\n\n // Format the result\n let output = formatSearchResult(file_path, query, case_sensitive, searchResult, 50);\n\n // Truncate long lines in output\n output = truncateLongLines(output, max_line_chars);\n\n return output;\n },\n});\n", "import { SourceMapConsumer } from 'source-map-js';\nimport type { SourceMap } from './beautifier.js';\n\n/**\n * Original position from source map\n */\nexport interface OriginalPosition {\n line: number | null;\n column: number | null;\n}\n\n/**\n * Context line with position info\n */\nexport interface ContextLine {\n lineNumber: number;\n content: string;\n originalPosition: OriginalPosition;\n}\n\n/**\n * Search match result\n */\nexport interface SearchMatch {\n /** Match line number (1-based, in beautified code) */\n lineNumber: number;\n /** Match line content */\n lineContent: string;\n /** Original file coordinates */\n originalPosition: OriginalPosition;\n /** Context lines before match */\n contextBefore: ContextLine[];\n /** Context lines after match */\n contextAfter: ContextLine[];\n}\n\n/**\n * Search options\n */\nexport interface SearchOptions {\n /** Regex pattern or text to search */\n query: string;\n /** Number of context lines (default 2) */\n contextLines?: number;\n /** Case sensitive search (default false) */\n caseSensitive?: boolean;\n /** Maximum matches to return (default 50) */\n maxMatches?: number;\n}\n\n/**\n * Search result\n */\nexport interface SearchResult {\n /** Matched results */\n matches: SearchMatch[];\n /** Total matches found (before truncation) */\n totalMatches: number;\n /** Whether results were truncated */\n truncated: boolean;\n}\n\n\n/**\n * Create regex from query string with error handling\n * @param query - Regex pattern or text\n * @param caseSensitive - Whether to be case sensitive\n * @returns Created RegExp\n * @throws Error if regex is invalid\n */\nexport function createRegex(query: string, caseSensitive: boolean = false): RegExp {\n try {\n const flags = caseSensitive ? 'g' : 'gi';\n return new RegExp(query, flags);\n } catch (err) {\n const message = err instanceof Error ? err.message : String(err);\n throw new Error(`Invalid regex: ${message}`);\n }\n}\n\n/**\n * Get original position for a line using source map consumer\n */\nfunction getOriginalPosition(\n consumer: SourceMapConsumer,\n lineNumber: number\n): OriginalPosition {\n const pos = consumer.originalPositionFor({\n line: lineNumber,\n column: 0,\n });\n return {\n line: pos.line,\n column: pos.column,\n };\n}\n\n/**\n * Create a context line object\n */\nfunction createContextLine(\n lineNumber: number,\n content: string,\n consumer: SourceMapConsumer\n): ContextLine {\n return {\n lineNumber,\n content,\n originalPosition: getOriginalPosition(consumer, lineNumber),\n };\n}\n\n/**\n * Search for pattern in code and return matches with context\n * @param code - Beautified code to search in\n * @param rawMap - Source map for coordinate mapping\n * @param options - Search options\n * @returns Search result with matches\n */\nexport function searchInCode(\n code: string,\n rawMap: SourceMap,\n options: SearchOptions\n): SearchResult {\n const {\n query,\n contextLines = 2,\n caseSensitive = false,\n maxMatches = 50,\n } = options;\n\n // Create regex from query\n const regex = createRegex(query, caseSensitive);\n\n // Split code into lines\n const lines = code.split('\\n');\n const totalLines = lines.length;\n\n // Create source map consumer\n const consumer = new SourceMapConsumer({\n ...rawMap,\n version: String(rawMap.version),\n });\n\n // Find all matching line numbers\n const matchingLineNumbers: number[] = [];\n for (let i = 0; i < totalLines; i++) {\n const line = lines[i];\n // Reset regex lastIndex for each line\n regex.lastIndex = 0;\n if (regex.test(line)) {\n matchingLineNumbers.push(i + 1); // 1-based line number\n }\n }\n\n const totalMatches = matchingLineNumbers.length;\n const truncated = totalMatches > maxMatches;\n\n // Limit matches\n const limitedLineNumbers = matchingLineNumbers.slice(0, maxMatches);\n\n // Build match results\n const matches: SearchMatch[] = limitedLineNumbers.map((lineNumber) => {\n const lineIndex = lineNumber - 1;\n const lineContent = lines[lineIndex];\n\n // Collect context before\n const contextBefore: ContextLine[] = [];\n for (let i = Math.max(0, lineIndex - contextLines); i < lineIndex; i++) {\n contextBefore.push(createContextLine(i + 1, lines[i], consumer));\n }\n\n // Collect context after\n const contextAfter: ContextLine[] = [];\n for (let i = lineIndex + 1; i <= Math.min(totalLines - 1, lineIndex + contextLines); i++) {\n contextAfter.push(createContextLine(i + 1, lines[i], consumer));\n }\n\n return {\n lineNumber,\n lineContent,\n originalPosition: getOriginalPosition(consumer, lineNumber),\n contextBefore,\n contextAfter,\n };\n });\n\n return {\n matches,\n totalMatches,\n truncated,\n };\n}\n\n/**\n * Format source position as \"L{line}:{column}\" or placeholder\n */\nexport function formatSourcePosition(line: number | null, column: number | null): string {\n if (line !== null && column !== null) {\n return `L${line}:${column}`;\n }\n return '';\n}\n\n/**\n * Format search result for output\n * @param filePath - Path to the file\n * @param query - Search query\n * @param caseSensitive - Whether search was case sensitive\n * @param result - Search result\n * @param maxMatches - Maximum matches limit\n * @returns Formatted output string\n */\nexport function formatSearchResult(\n filePath: string,\n query: string,\n caseSensitive: boolean,\n result: SearchResult,\n maxMatches: number = 50\n): string {\n const { matches, totalMatches, truncated } = result;\n\n const outputParts: string[] = [];\n\n // Header\n const caseInfo = caseSensitive ? 'case-sensitive' : 'case-insensitive';\n outputParts.push(`FILE: ${filePath}`);\n outputParts.push(`QUERY: \"${query}\" (${caseInfo})`);\n\n if (totalMatches === 0) {\n outputParts.push('MATCHES: No matches found');\n return outputParts.join('\\n');\n }\n\n const matchInfo = truncated\n ? `MATCHES: ${totalMatches} found (showing first ${maxMatches})`\n : `MATCHES: ${totalMatches} found`;\n outputParts.push(matchInfo);\n outputParts.push('-'.repeat(85));\n\n // Format each match\n for (const match of matches) {\n outputParts.push(`--- Match at Line ${match.lineNumber} ---`);\n\n // Calculate max line number width for alignment\n const allLineNumbers = [\n ...match.contextBefore.map((c) => c.lineNumber),\n match.lineNumber,\n ...match.contextAfter.map((c) => c.lineNumber),\n ];\n const maxLineNumWidth = Math.max(...allLineNumbers.map((n) => String(n).length));\n\n // Format context before\n for (const ctx of match.contextBefore) {\n const lineNumStr = String(ctx.lineNumber).padStart(maxLineNumWidth, ' ');\n const srcPos = formatSourcePosition(ctx.originalPosition.line, ctx.originalPosition.column);\n const srcPosPadded = srcPos ? `Src ${srcPos}` : '';\n outputParts.push(` ${lineNumStr} | [${srcPosPadded.padEnd(14, ' ')}] | ${ctx.content}`);\n }\n\n // Format match line with >> prefix\n const matchLineNumStr = String(match.lineNumber).padStart(maxLineNumWidth, ' ');\n const matchSrcPos = formatSourcePosition(match.originalPosition.line, match.originalPosition.column);\n const matchSrcPosPadded = matchSrcPos ? `Src ${matchSrcPos}` : '';\n outputParts.push(`>> ${matchLineNumStr} | [${matchSrcPosPadded.padEnd(14, ' ')}] | ${match.lineContent}`);\n\n // Format context after\n for (const ctx of match.contextAfter) {\n const lineNumStr = String(ctx.lineNumber).padStart(maxLineNumWidth, ' ');\n const srcPos = formatSourcePosition(ctx.originalPosition.line, ctx.originalPosition.column);\n const srcPosPadded = srcPos ? `Src ${srcPos}` : '';\n outputParts.push(` ${lineNumStr} | [${srcPosPadded.padEnd(14, ' ')}] | ${ctx.content}`);\n }\n\n outputParts.push(''); // Empty line between matches\n }\n\n // Add truncation message if needed\n if (truncated) {\n outputParts.push(`... (${totalMatches - maxMatches} more matches not shown)`);\n }\n\n return outputParts.join('\\n');\n}\n", "import { z } from 'zod';\nimport { defineTool } from './ToolDefinition.js';\nimport { ensureBeautified } from '../beautifier.js';\nimport { truncateCodeHighPerf, truncateLongLines } from '../truncator.js';\nimport { analyzeBindings, formatAnalysisResult } from '../analyzer.js';\n\n/**\n * Schema for find_usage_smart tool input validation\n */\nexport const FindUsageSmartInputSchema = z.object({\n file_path: z.string().describe('Path to the JavaScript file'),\n identifier: z.string().describe('Variable or function name to find'),\n line: z.number().int().positive().optional().describe(\n 'The line number where you see this variable. HIGHLY RECOMMENDED for precision in obfuscated code.'\n ),\n char_limit: z.number().int().min(50).default(300).describe('Character limit for string truncation'),\n max_line_chars: z.number().int().min(80).default(500).describe('Maximum characters per line'),\n});\n\n/**\n * find_usage_smart tool definition\n * Find all definitions and references of a variable/function using AST scope analysis.\n */\nexport const findUsageSmart = defineTool({\n name: 'find_usage_smart',\n description:\n 'Find all definitions and references of a variable/function using AST scope analysis. ' +\n 'Returns binding information grouped by scope with original source coordinates for setting breakpoints. ' +\n 'Useful for tracing variable usage in minified/obfuscated code with variable name reuse.',\n schema: {\n file_path: z.string().describe('Path to the JavaScript file'),\n identifier: z.string().describe('Variable or function name to find'),\n line: z.number().int().positive().optional().describe(\n 'The line number where you see this variable. HIGHLY RECOMMENDED for precision in obfuscated code.'\n ),\n char_limit: z.number().int().min(50).default(300).describe('Character limit for string truncation'),\n max_line_chars: z.number().int().min(80).default(500).describe('Maximum characters per line'),\n },\n handler: async (params) => {\n const { file_path, identifier, line, char_limit, max_line_chars } = params;\n\n // Beautify the file and get source map\n const beautifyResult = await ensureBeautified(file_path);\n const { code, rawMap } = beautifyResult;\n\n // Analyze bindings using full code (not truncated) for accurate AST analysis\n // When line is specified, increase maxReferences to 15 for targeted searches\n const analysisResult = analyzeBindings(code, rawMap, identifier, {\n maxReferences: line ? 15 : 10,\n targetLine: line,\n });\n\n // Truncate the code for display purposes\n const truncatedCode = truncateCodeHighPerf(code, char_limit);\n const truncatedLines = truncatedCode.split('\\n');\n\n // Update line content in analysis result with truncated versions\n for (const binding of analysisResult.bindings) {\n // Update definition line content\n const defLineIdx = binding.definition.line - 1;\n if (defLineIdx >= 0 && defLineIdx < truncatedLines.length) {\n binding.definition.lineContent = truncatedLines[defLineIdx];\n }\n\n // Update reference line contents\n for (const ref of binding.references) {\n const refLineIdx = ref.line - 1;\n if (refLineIdx >= 0 && refLineIdx < truncatedLines.length) {\n ref.lineContent = truncatedLines[refLineIdx];\n }\n }\n }\n\n // Format the result\n let output = formatAnalysisResult(file_path, analysisResult, line ? 15 : 10);\n\n // Truncate long lines in output\n output = truncateLongLines(output, max_line_chars);\n\n return output;\n },\n});\n", "import { SourceMapConsumer } from 'source-map-js';\nimport { parse, ParserOptions } from '@babel/parser';\nimport type { NodePath } from '@babel/traverse';\nimport type { Identifier } from '@babel/types';\nimport type { SourceMap } from './beautifier.js';\n\n// Dynamic import for babel traverse to handle ESM/CJS interop\n// eslint-disable-next-line @typescript-eslint/no-require-imports\nconst traverse = require('@babel/traverse').default as (\n parent: Parameters<typeof import('@babel/traverse').default>[0],\n opts?: Parameters<typeof import('@babel/traverse').default>[1],\n scope?: Parameters<typeof import('@babel/traverse').default>[2],\n state?: Parameters<typeof import('@babel/traverse').default>[3],\n parentPath?: Parameters<typeof import('@babel/traverse').default>[4]\n) => void;\n\n/**\n * Original position from source map\n */\nexport interface OriginalPosition {\n line: number | null;\n column: number | null;\n}\n\n/**\n * Location information for a definition or reference\n */\nexport interface LocationInfo {\n /** Line number in beautified code (1-based) */\n line: number;\n /** Column number in beautified code (0-based) */\n column: number;\n /** Original file coordinates from source map */\n originalPosition: OriginalPosition;\n /** Content of the line containing this location */\n lineContent: string;\n}\n\n/**\n * Binding information for a variable/function\n */\nexport interface BindingInfo {\n /** Unique scope identifier */\n scopeUid: number;\n /** Binding kind (var, let, const, param, etc.) */\n kind: string;\n /** Definition location */\n definition: LocationInfo;\n /** All reference locations */\n references: LocationInfo[];\n /** Total reference count (before limiting) */\n totalReferences: number;\n /** The location that matched the target line (if targeted search) */\n hitLocation?: LocationInfo;\n}\n\n/**\n * Analysis result containing all bindings for an identifier\n */\nexport interface AnalysisResult {\n /** All bindings found for the identifier */\n bindings: BindingInfo[];\n /** The identifier that was searched */\n identifier: string;\n /** Whether this was a targeted (line-specific) search */\n isTargeted: boolean;\n /** The target line if specified */\n targetLine?: number;\n}\n\n\n/**\n * Default parser options for Babel\n */\nconst DEFAULT_PARSER_OPTIONS: ParserOptions = {\n sourceType: 'unambiguous',\n plugins: [\n 'jsx',\n 'typescript',\n 'classProperties',\n 'classPrivateProperties',\n 'classPrivateMethods',\n 'dynamicImport',\n 'optionalChaining',\n 'nullishCoalescingOperator',\n 'objectRestSpread',\n ],\n errorRecovery: true,\n};\n\n/**\n * Parse JavaScript/TypeScript code into an AST\n * @param code - Source code to parse\n * @returns Parsed AST\n * @throws Error if parsing fails\n */\nexport function parseCode(code: string) {\n try {\n return parse(code, DEFAULT_PARSER_OPTIONS);\n } catch (err) {\n const message = err instanceof Error ? err.message : String(err);\n throw new Error(`Parse error: ${message}`);\n }\n}\n\n\n/**\n * Get original position for a location using source map consumer\n */\nfunction getOriginalPosition(\n consumer: SourceMapConsumer,\n line: number,\n column: number\n): OriginalPosition {\n const pos = consumer.originalPositionFor({ line, column });\n return {\n line: pos.line,\n column: pos.column,\n };\n}\n\n/**\n * Get line content from code by line number (1-based)\n */\nfunction getLineContent(lines: string[], lineNumber: number): string {\n if (lineNumber < 1 || lineNumber > lines.length) {\n return '';\n }\n return lines[lineNumber - 1];\n}\n\n/**\n * Create a LocationInfo object\n */\nfunction createLocationInfo(\n line: number,\n column: number,\n lines: string[],\n consumer: SourceMapConsumer\n): LocationInfo {\n return {\n line,\n column,\n originalPosition: getOriginalPosition(consumer, line, column),\n lineContent: getLineContent(lines, line),\n };\n}\n\n/**\n * Options for binding analysis\n */\nexport interface AnalyzeOptions {\n /** Maximum references to return per binding (default 10) */\n maxReferences?: number;\n /** Target line number for precise binding identification (1-based) */\n targetLine?: number;\n}\n\n/**\n * Analyze bindings for a specific identifier in the code\n * Uses Babel traverse to find all bindings and their references\n * \n * @param code - Beautified code to analyze\n * @param rawMap - Source map for coordinate mapping\n * @param identifier - Variable/function name to find\n * @param options - Analysis options\n * @returns Analysis result with all bindings\n */\nexport function analyzeBindings(\n code: string,\n rawMap: SourceMap,\n identifier: string,\n options?: AnalyzeOptions\n): AnalysisResult {\n const targetLine = options?.targetLine;\n const isTargeted = targetLine !== undefined;\n // Use 15 max references for targeted searches, 10 for regular searches\n const maxReferences = options?.maxReferences ?? (isTargeted ? 15 : 10);\n \n // Parse the code\n const ast = parseCode(code);\n \n // Split code into lines for content extraction\n const lines = code.split('\\n');\n \n // Create source map consumer\n const consumer = new SourceMapConsumer({\n ...rawMap,\n version: String(rawMap.version),\n });\n \n // Collect all bindings for the identifier\n const bindings: BindingInfo[] = [];\n const processedScopes = new Set<number>();\n \n try {\n traverse(ast, {\n Identifier(path: NodePath<Identifier>) {\n // Only process if this is the identifier we're looking for\n if (path.node.name !== identifier) {\n return;\n }\n \n // For targeted search, check if this identifier is at the target line\n if (isTargeted) {\n const nodeLoc = path.node.loc;\n if (!nodeLoc || nodeLoc.start.line !== targetLine) {\n return;\n }\n }\n \n // Get the binding for this identifier\n const binding = path.scope.getBinding(identifier);\n if (!binding) {\n return;\n }\n \n // Get scope UID to avoid processing same binding multiple times\n const scopeUid = binding.scope.uid;\n if (processedScopes.has(scopeUid)) {\n return;\n }\n processedScopes.add(scopeUid);\n \n // Get definition location\n const defNode = binding.identifier;\n const defLoc = defNode.loc;\n if (!defLoc) {\n return;\n }\n \n const definition = createLocationInfo(\n defLoc.start.line,\n defLoc.start.column,\n lines,\n consumer\n );\n \n // Get all reference locations\n const allReferences: LocationInfo[] = [];\n for (const refPath of binding.referencePaths) {\n const refLoc = refPath.node.loc;\n if (!refLoc) {\n continue;\n }\n \n allReferences.push(\n createLocationInfo(\n refLoc.start.line,\n refLoc.start.column,\n lines,\n consumer\n )\n );\n }\n \n // Store total count before limiting\n const totalReferences = allReferences.length;\n \n // Limit references\n const limitedReferences = allReferences.slice(0, maxReferences);\n \n // Create hit location for targeted search\n let hitLocation: LocationInfo | undefined;\n if (isTargeted) {\n const nodeLoc = path.node.loc!;\n hitLocation = createLocationInfo(\n nodeLoc.start.line,\n nodeLoc.start.column,\n lines,\n consumer\n );\n }\n \n bindings.push({\n scopeUid,\n kind: binding.kind,\n definition,\n references: limitedReferences,\n totalReferences,\n hitLocation,\n });\n \n // For targeted search, stop after finding the first matching binding\n if (isTargeted) {\n path.stop();\n }\n },\n });\n } catch (err) {\n const message = err instanceof Error ? err.message : String(err);\n throw new Error(`Analysis error: ${message}`);\n }\n \n return {\n bindings,\n identifier,\n isTargeted,\n targetLine,\n };\n}\n\n\n/**\n * Format source position as \"L{line}:{column}\" or placeholder\n */\nexport function formatSourcePosition(line: number | null, column: number | null): string {\n if (line !== null && column !== null) {\n return `L${line}:${column}`;\n }\n return '';\n}\n\n/**\n * Check if two locations match (same line and column)\n */\nfunction locationsMatch(loc1: LocationInfo, loc2: LocationInfo): boolean {\n return loc1.line === loc2.line && loc1.column === loc2.column;\n}\n\n/**\n * Format analysis result for output\n * @param filePath - Path to the file\n * @param result - Analysis result\n * @param maxReferences - Maximum references shown per binding\n * @returns Formatted output string\n */\nexport function formatAnalysisResult(\n filePath: string,\n result: AnalysisResult,\n maxReferences: number = 10\n): string {\n const { bindings, identifier, isTargeted, targetLine } = result;\n \n const outputParts: string[] = [];\n \n // Header\n outputParts.push(`FILE: ${filePath}`);\n outputParts.push(`IDENTIFIER: \"${identifier}\"`);\n \n // Handle no bindings found\n if (bindings.length === 0) {\n if (isTargeted && targetLine !== undefined) {\n // Descriptive message for targeted search with no results\n outputParts.push(`BINDINGS: No binding found for \"${identifier}\" at line ${targetLine}`);\n outputParts.push(`The variable may be global, externally defined, or not present at this line.`);\n } else {\n outputParts.push('BINDINGS: No definitions or references found');\n }\n return outputParts.join('\\n');\n }\n \n // Display \"Targeted Scope\" header when isTargeted is true\n if (isTargeted) {\n outputParts.push(`BINDINGS: 1 found (Targeted Scope at line ${targetLine})`);\n } else {\n const scopeInfo = bindings.length > 1 ? ' (in different scopes)' : '';\n outputParts.push(`BINDINGS: ${bindings.length} found${scopeInfo}`);\n }\n outputParts.push('-'.repeat(85));\n \n // Format each binding\n for (let i = 0; i < bindings.length; i++) {\n const binding = bindings[i];\n \n // Use \"Targeted Scope\" label for targeted searches\n if (isTargeted) {\n outputParts.push(`=== Targeted Scope (${binding.kind}) ===`);\n } else {\n outputParts.push(`=== Scope #${i + 1} (${binding.kind}) ===`);\n }\n \n // Format definition - check if definition is the hit location\n const defIsHit = isTargeted && binding.hitLocation && \n locationsMatch(binding.definition, binding.hitLocation);\n const defPrefix = defIsHit ? '\uD83D\uDCCD Definition (hit):' : '\uD83D\uDCCD Definition:';\n outputParts.push(defPrefix);\n \n const defSrcPos = formatSourcePosition(\n binding.definition.originalPosition.line,\n binding.definition.originalPosition.column\n );\n const defSrcPosPadded = defSrcPos ? `Src ${defSrcPos}` : '';\n const defMarker = defIsHit ? ' \u25C0\u2500\u2500 hit' : '';\n outputParts.push(\n ` ${binding.definition.line} | [${defSrcPosPadded.padEnd(14, ' ')}] | ${binding.definition.lineContent}${defMarker}`\n );\n \n // Format references\n const totalRefs = binding.totalReferences;\n \n if (totalRefs === 0) {\n outputParts.push('\uD83D\uDD0E References: None');\n } else {\n outputParts.push(`\uD83D\uDD0E References (${totalRefs}):`);\n \n for (const ref of binding.references) {\n // Check if this reference is the hit location\n const refIsHit = isTargeted && binding.hitLocation && \n locationsMatch(ref, binding.hitLocation);\n \n const refSrcPos = formatSourcePosition(\n ref.originalPosition.line,\n ref.originalPosition.column\n );\n const refSrcPosPadded = refSrcPos ? `Src ${refSrcPos}` : '';\n const refMarker = refIsHit ? ' \u25C0\u2500\u2500 hit' : '';\n outputParts.push(\n ` ${ref.line} | [${refSrcPosPadded.padEnd(14, ' ')}] | ${ref.lineContent}${refMarker}`\n );\n }\n \n // Add truncation message if references were limited\n if (totalRefs > maxReferences) {\n const remaining = totalRefs - maxReferences;\n outputParts.push(` ... (${remaining} more references not shown)`);\n }\n }\n \n outputParts.push(''); // Empty line between bindings\n }\n \n return outputParts.join('\\n');\n}\n", "/**\n * Tool aggregation module\n * Collects all tool definitions and exports them as a unified array.\n */\n\nimport { readCodeSmart } from './readCodeSmart.js';\nimport { applyCustomTransform, ApplyCustomTransformInputSchema } from './applyCustomTransform.js';\nimport { searchCodeSmart, SearchCodeSmartInputSchema } from './searchCodeSmart.js';\nimport { findUsageSmart, FindUsageSmartInputSchema } from './findUsageSmart.js';\n\n/**\n * Array of all available MCP tool definitions.\n * To add a new tool:\n * 1. Create a new tool module in src/tools/\n * 2. Import it here\n * 3. Add it to this array\n */\nexport const tools = [\n readCodeSmart,\n applyCustomTransform,\n searchCodeSmart,\n findUsageSmart,\n] as const;\n\n// Re-export ToolDefinition interface and defineTool helper\nexport { ToolDefinition, defineTool } from './ToolDefinition.js';\n\n// Re-export input schemas for testing\nexport { ApplyCustomTransformInputSchema, SearchCodeSmartInputSchema, FindUsageSmartInputSchema };\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;AAAA,SAAS,iBAAiB;AA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WAAO;AAAA,EACT;AACF,CAAC;;;AEhEM,IAAM,QAAQ;AAAA,EACnB;AAAA,EACAC;AAAA,EACA;AAAA,EACA;AACF;;;AXhBA,IAAM,SAAS,IAAI,UAAU;AAAA,EAC3B,MAAM;AAAA,EACN,SAAS;AACX,CAAC;AAQD,SAAS,aAAa,MAKb;AAEP,QAAM,YAAYC,GAAE,OAAO,KAAK,MAAM;AAGtC,SAAO;AAAA,IACL,KAAK;AAAA,IACL;AAAA,MACE,aAAa,KAAK;AAAA,MAClB,aAAa,KAAK;AAAA,IACpB;AAAA,IACA,OAAO,QAAQ,WAAW;AACxB,UAAI;AAEF,cAAM,kBAAkB,UAAU,MAAM,MAAM;AAC9C,cAAM,SAAS,MAAM,KAAK,QAAQ,eAA0C;AAE5E,eAAO;AAAA,UACL,SAAS,CAAC,EAAE,MAAM,QAAiB,MAAM,OAAO,CAAC;AAAA,QACnD;AAAA,MACF,SAAS,OAAO;AACd,cAAM,UAAU,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;AACrE,eAAO;AAAA,UACL,SAAS,CAAC,EAAE,MAAM,QAAiB,MAAM,UAAU,OAAO,GAAG,CAAC;AAAA,UAC9D,SAAS;AAAA,QACX;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;AAGA,WAAW,QAAQ,OAAO;AACxB,eAAa,IAKZ;AACH;AAGA,eAAe,OAAO;AACpB,QAAM,YAAY,IAAI,qBAAqB;AAC3C,QAAM,OAAO,QAAQ,SAAS;AAC9B,UAAQ,MAAM,4CAA4C;AAC5D;AAEA,KAAK,EAAE,MAAM,CAAC,UAAU;AACtB,UAAQ,MAAM,gBAAgB,KAAK;AACnC,UAAQ,KAAK,CAAC;AAChB,CAAC;",
|
|
6
|
+
"names": ["z", "code", "result", "z", "path", "fs", "basename", "z", "applyCustomTransform", "z", "SourceMapConsumer", "formatSourcePosition", "z", "z", "SourceMapConsumer", "parse", "getOriginalPosition", "path", "formatSourcePosition", "z", "applyCustomTransform", "z"]
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reverse-craft/smart-fs",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "MCP server for AI-assisted JavaScript reverse engineering - beautifies minified code and truncates long strings to prevent context overflow",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/server.js",
|
|
@@ -44,6 +44,11 @@
|
|
|
44
44
|
"node": ">=18"
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
|
+
"@babel/core": "^7.28.5",
|
|
48
|
+
"@babel/generator": "^7.28.5",
|
|
49
|
+
"@babel/parser": "^7.28.5",
|
|
50
|
+
"@babel/traverse": "^7.28.5",
|
|
51
|
+
"@babel/types": "^7.28.5",
|
|
47
52
|
"@modelcontextprotocol/sdk": "^1.25.1",
|
|
48
53
|
"esbuild": "^0.27.2",
|
|
49
54
|
"estree-walker": "^3.0.3",
|
|
@@ -54,6 +59,9 @@
|
|
|
54
59
|
"zod": "^4.2.1"
|
|
55
60
|
},
|
|
56
61
|
"devDependencies": {
|
|
62
|
+
"@types/babel__core": "^7.20.5",
|
|
63
|
+
"@types/babel__generator": "^7.27.0",
|
|
64
|
+
"@types/babel__traverse": "^7.28.0",
|
|
57
65
|
"@types/fs-extra": "^11.0.4",
|
|
58
66
|
"@types/node": "^22.15.29",
|
|
59
67
|
"fast-check": "^4.5.2",
|