@reverse-craft/smart-fs 1.0.6 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/README.md +160 -13
  2. package/dist/analyzer.d.ts +91 -0
  3. package/dist/analyzer.d.ts.map +1 -0
  4. package/dist/beautifier.d.ts +120 -0
  5. package/dist/beautifier.d.ts.map +1 -0
  6. package/dist/index.d.ts +102 -0
  7. package/dist/index.d.ts.map +1 -0
  8. package/dist/index.js +1267 -0
  9. package/dist/index.js.map +7 -0
  10. package/dist/languageDetector.d.ts +74 -0
  11. package/dist/languageDetector.d.ts.map +1 -0
  12. package/dist/llmConfig.d.ts +34 -0
  13. package/dist/llmConfig.d.ts.map +1 -0
  14. package/dist/searcher.d.ts +113 -0
  15. package/dist/searcher.d.ts.map +1 -0
  16. package/dist/server.d.ts +2 -0
  17. package/dist/server.d.ts.map +1 -0
  18. package/dist/server.js +571 -78
  19. package/dist/server.js.map +4 -4
  20. package/dist/tools/ToolDefinition.d.ts +24 -0
  21. package/dist/tools/ToolDefinition.d.ts.map +1 -0
  22. package/dist/tools/aiFindJsvmpDispatcher.d.ts +79 -0
  23. package/dist/tools/aiFindJsvmpDispatcher.d.ts.map +1 -0
  24. package/dist/tools/applyCustomTransform.d.ts +14 -0
  25. package/dist/tools/applyCustomTransform.d.ts.map +1 -0
  26. package/dist/tools/findUsageSmart.d.ts +16 -0
  27. package/dist/tools/findUsageSmart.d.ts.map +1 -0
  28. package/dist/tools/index.d.ts +43 -0
  29. package/dist/tools/index.d.ts.map +1 -0
  30. package/dist/tools/readCodeSmart.d.ts +13 -0
  31. package/dist/tools/readCodeSmart.d.ts.map +1 -0
  32. package/dist/tools/searchCodeSmart.d.ts +18 -0
  33. package/dist/tools/searchCodeSmart.d.ts.map +1 -0
  34. package/dist/transformer.d.ts +119 -0
  35. package/dist/transformer.d.ts.map +1 -0
  36. package/dist/truncator.d.ts +69 -0
  37. package/dist/truncator.d.ts.map +1 -0
  38. package/dist/types.d.ts +61 -0
  39. package/dist/types.d.ts.map +1 -0
  40. package/package.json +16 -16
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
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: '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('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 `${filePath} (${startLine}-${endLine}/${totalLines})`,\n `Src=original position for breakpoints`,\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 srcPos = sourcePos ? sourcePos.padEnd(10, ' ') : ' ';\n return `${lineNumStr} ${srcPos} ${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(`MAP: ${localMapPath}`);\n }\n }\n if (localSaveError) {\n outputParts.push(`ERROR: ${localSaveError}`);\n }\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(), 'smart-fs-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 // Reserved for future options\n}\n\nexport interface BeautifyResult {\n code: string;\n rawMap: SourceMap;\n /** \u672C\u5730\u4FDD\u5B58\u7684\u7F8E\u5316\u6587\u4EF6\u8DEF\u5F84 */\n localPath: string;\n /** \u672C\u5730\u4FDD\u5B58\u7684 source map \u8DEF\u5F84 */\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 \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 local save/read\n const localPaths = getLocalPaths(absolutePath);\n \n // Check local cache first\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 // 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 localPath: localPaths.beautifiedPath,\n localMapPath: localPaths.mapPath\n };\n \n // Also save to local directory\n await saveToLocal(result, localPaths, mapContent);\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 = {\n code,\n rawMap,\n localPath: localPaths.beautifiedPath,\n localMapPath: localPaths.mapPath\n };\n \n // Save to local directory\n await saveToLocal(result, localPaths, mapText);\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 { truncateLongLines } from '../truncator.js';\nimport { searchInCode, formatSearchResult, unescapeBackslashes } 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 is_regex: z.boolean().default(false).describe('Treat query as regex pattern (default: false for literal text search)'),\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 is_regex: z.boolean().default(false).describe('Treat query as regex pattern (default: false for literal text search)'),\n },\n handler: async (params) => {\n const { file_path, query, context_lines, case_sensitive, char_limit, max_line_chars, is_regex } = params;\n\n // Unescape double-escaped backslashes from MCP JSON transmission\n const unescapedQuery = unescapeBackslashes(query);\n\n // Beautify the file and get source map\n const beautifyResult = await ensureBeautified(file_path);\n const { code, rawMap } = beautifyResult;\n\n // Execute search on original beautified code (no truncation before search)\n const searchResult = searchInCode(code, rawMap, {\n query: unescapedQuery,\n contextLines: context_lines,\n caseSensitive: case_sensitive,\n maxMatches: 50,\n isRegex: is_regex,\n });\n\n // Format the result\n let output = formatSearchResult(file_path, unescapedQuery, case_sensitive, searchResult, 50, is_regex);\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 /** Treat query as regex pattern (default false for literal text search) */\n isRegex?: boolean;\n /** Timeout in milliseconds for search operation (default 500) */\n timeoutMs?: 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 * Convert double-escaped backslashes to single backslashes.\n * Fixes MCP JSON transmission double-escaping issue.\n * \n * @param str - String with potentially double-escaped backslashes\n * @returns String with `\\\\` converted to `\\`\n * \n * @example\n * unescapeBackslashes(\"for\\\\s*\\\\(\") // returns \"for\\s*\\(\"\n * unescapeBackslashes(\"\\\\\\\\n\") // returns \"\\\\n\" (literal backslash + n)\n * unescapeBackslashes(\"hello\") // returns \"hello\" (unchanged)\n */\nexport function unescapeBackslashes(str: string): string {\n return str.replace(/\\\\\\\\/g, '\\\\');\n}\n\n/**\n * Escape all regex special characters in a string for literal matching\n * @param str - String to escape\n * @returns Escaped string safe for use in RegExp\n */\nexport function escapeRegex(str: string): string {\n return str.replace(/[()[\\]{}.*+?^$|\\\\]/g, '\\\\$&');\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 * @param isRegex - Whether to treat query as regex (default false)\n * @returns Created RegExp\n * @throws Error if regex is invalid\n */\nexport function createRegex(query: string, caseSensitive: boolean = false, isRegex: boolean = false): RegExp {\n try {\n const flags = caseSensitive ? 'g' : 'gi';\n const pattern = isRegex ? query : escapeRegex(query);\n return new RegExp(pattern, 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 * Build line offset index using Int32Array for memory efficiency.\n * Returns the offset array and total line count.\n */\nfunction buildLineOffsets(code: string): { offsets: Int32Array; totalLines: number } {\n // Pre-allocate with estimated average line length of 40 chars\n let capacity = Math.max(16, Math.ceil(code.length / 40));\n let offsets = new Int32Array(capacity);\n let lineCount = 0;\n\n offsets[0] = 0; // First line starts at index 0\n\n for (let i = 0; i < code.length; i++) {\n if (code[i] === '\\n') {\n lineCount++;\n // Dynamic resize if needed\n if (lineCount >= capacity) {\n capacity *= 2;\n const newArr = new Int32Array(capacity);\n newArr.set(offsets);\n offsets = newArr;\n }\n offsets[lineCount] = i + 1; // Next line starts after \\n\n }\n }\n\n return {\n offsets: offsets.subarray(0, lineCount + 1),\n totalLines: lineCount + 1,\n };\n}\n\n/**\n * Binary search to find line number (1-based) from character index.\n */\nfunction getLineNumberFromIndex(offsets: Int32Array, totalLines: number, index: number): number {\n let low = 0;\n let high = totalLines - 1;\n\n while (low <= high) {\n const mid = (low + high) >>> 1;\n if (offsets[mid] <= index) {\n low = mid + 1;\n } else {\n high = mid - 1;\n }\n }\n return low; // 1-based line number\n}\n\n/**\n * Get line content by line number (1-based) without splitting entire string.\n */\nfunction getLineContent(\n code: string,\n offsets: Int32Array,\n totalLines: number,\n lineNo: number\n): string {\n if (lineNo < 1 || lineNo > totalLines) return '';\n\n const start = offsets[lineNo - 1];\n let end: number;\n\n if (lineNo < totalLines) {\n // End is one before the next line's start (exclude \\n)\n end = offsets[lineNo] - 1;\n } else {\n // Last line: go to end of string\n end = code.length;\n }\n\n // Handle \\r\\n line endings\n if (end > start && code[end - 1] === '\\r') {\n end--;\n }\n\n return code.slice(start, end);\n}\n\n/**\n * Search for pattern in code and return matches with context.\n * Optimized version: avoids split() for large files, uses index-based iteration.\n *\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 = 10,\n isRegex = false,\n timeoutMs = 500,\n } = options;\n\n // Build line offset index (memory efficient)\n const { offsets, totalLines } = buildLineOffsets(code);\n\n // Create regex with global + multiline flags\n const flags = (caseSensitive ? 'g' : 'gi') + 'm';\n const patternStr = isRegex ? unescapeBackslashes(query) : escapeRegex(query);\n\n let regex: RegExp;\n try {\n regex = new RegExp(patternStr, flags);\n } catch (err) {\n const message = err instanceof Error ? err.message : String(err);\n throw new Error(`Invalid regex: ${message}`);\n }\n\n // Create source map consumer\n const consumer = new SourceMapConsumer({\n ...rawMap,\n version: String(rawMap.version),\n });\n\n const matches: SearchMatch[] = [];\n let lastMatchedLine = -1;\n let totalMatchesFound = 0;\n let match: RegExpExecArray | null;\n\n // Performance protection\n const startTime = Date.now();\n\n // Iterate matches using exec() - no string splitting\n while ((match = regex.exec(code)) !== null) {\n // Prevent infinite loop on zero-width matches\n if (match.index === regex.lastIndex) {\n regex.lastIndex++;\n }\n\n const lineNumber = getLineNumberFromIndex(offsets, totalLines, match.index);\n\n // Dedupe: skip if same line already matched\n if (lineNumber === lastMatchedLine) {\n continue;\n }\n lastMatchedLine = lineNumber;\n totalMatchesFound++;\n\n // Only build match details if we haven't hit the limit yet\n if (matches.length < maxMatches) {\n // Build context (lazy: only fetch line content when needed)\n const contextBefore: ContextLine[] = [];\n for (let i = Math.max(1, lineNumber - contextLines); i < lineNumber; i++) {\n contextBefore.push({\n lineNumber: i,\n content: getLineContent(code, offsets, totalLines, i),\n originalPosition: getOriginalPosition(consumer, i),\n });\n }\n\n const contextAfter: ContextLine[] = [];\n for (let i = lineNumber + 1; i <= Math.min(totalLines, lineNumber + contextLines); i++) {\n contextAfter.push({\n lineNumber: i,\n content: getLineContent(code, offsets, totalLines, i),\n originalPosition: getOriginalPosition(consumer, i),\n });\n }\n\n matches.push({\n lineNumber,\n lineContent: getLineContent(code, offsets, totalLines, lineNumber),\n originalPosition: getOriginalPosition(consumer, lineNumber),\n contextBefore,\n contextAfter,\n });\n }\n\n // Timeout protection (still count but stop searching)\n if (Date.now() - startTime > timeoutMs) {\n break;\n }\n }\n\n return {\n matches,\n totalMatches: totalMatchesFound,\n truncated: totalMatchesFound > maxMatches,\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 * @param isRegex - Whether query was treated as regex pattern\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 isRegex: boolean = false\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 const modeInfo = isRegex ? 'regex' : 'literal';\n outputParts.push(`FILE: ${filePath}`);\n outputParts.push(`QUERY: \"${query}\" (${modeInfo}, ${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 = await 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\ntype TraverseFn = (\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\nlet traverse: TraverseFn | null = null;\n\nasync function getTraverse(): Promise<TraverseFn> {\n if (!traverse) {\n const mod = await import('@babel/traverse');\n // Handle both ESM default export and CJS module.exports\n traverse = (mod.default?.default ?? mod.default) as TraverseFn;\n }\n return traverse;\n}\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 async function analyzeBindings(\n code: string,\n rawMap: SourceMap,\n identifier: string,\n options?: AnalyzeOptions\n): Promise<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 // Get traverse function\n const traverse = await getTraverse();\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;AAC1B,SAAS,4BAA4B;AACrC,SAAS,KAAAA,UAAS;;;ACFlB,SAAS,SAAS;AAClB,SAAS,yBAAyB;;;ACuB3B,SAAS,WACd,YACyB;AACzB,SAAO;AACT;;;AC5BA,YAAY,aAAa;AACzB,YAAY,YAAY;AACxB,YAAY,QAAQ;AACpB,YAAY,UAAU;AACtB,YAAY,QAAQ;AAEpB,IAAM,WAAgB,UAAQ,UAAO,GAAG,oBAAoB;AA6B5D,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;AAyBO,SAAS,cAAc,cAAkC;AAC9D,QAAM,eAAoB,aAAQ,YAAY;AAC9C,QAAM,MAAW,aAAQ,YAAY;AACrC,QAAM,MAAW,aAAQ,YAAY;AACrC,QAAM,WAAgB,cAAS,cAAc,GAAG;AAEhD,QAAM,iBAAsB,UAAK,KAAK,GAAG,QAAQ,gBAAgB;AACjE,QAAM,UAAU,GAAG,cAAc;AAEjC,SAAO,EAAE,gBAAgB,QAAQ;AACnC;AAKA,eAAe,aAAa,gBAAwB,SAAmC;AACrF,MAAI;AAC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O,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,sCAAsC;AACtD;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", "SourceMapConsumer", "formatSourcePosition", "z", "z", "SourceMapConsumer", "parse", "getOriginalPosition", "getLineContent", "traverse", "path", "formatSourcePosition", "z", "applyCustomTransform", "z"]
3
+ "sources": ["../src/server.ts", "../src/tools/readCodeSmart.ts", "../src/tools/ToolDefinition.ts", "../src/beautifier.ts", "../src/languageDetector.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/aiFindJsvmpDispatcher.ts", "../src/llmConfig.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: '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('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 `${filePath} (${startLine}-${endLine}/${totalLines})`,\n `Src=original position for breakpoints`,\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 srcPos = sourcePos ? sourcePos.padEnd(10, ' ') : ' ';\n return `${lineNumStr} ${srcPos} ${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(`MAP: ${localMapPath}`);\n }\n }\n if (localSaveError) {\n outputParts.push(`ERROR: ${localSaveError}`);\n }\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';\nimport { detectLanguage, getLanguageInfo, type SupportedLanguage } from './languageDetector.js';\n\nconst TEMP_DIR = path.join(os.tmpdir(), 'smart-fs-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 /** Override auto-detected language */\n language?: SupportedLanguage;\n /** Save beautified file locally (default: true for JS/TS) */\n saveLocal?: boolean;\n}\n\nexport interface BeautifyResult {\n code: string;\n /** Source map (null for languages that don't support it) */\n rawMap: SourceMap | null;\n /** \u672C\u5730\u4FDD\u5B58\u7684\u7F8E\u5316\u6587\u4EF6\u8DEF\u5F84 */\n localPath: string;\n /** \u672C\u5730\u4FDD\u5B58\u7684 source map \u8DEF\u5F84 */\n localMapPath: string;\n /** \u672C\u5730\u4FDD\u5B58\u5931\u8D25\u65F6\u7684\u9519\u8BEF\u4FE1\u606F */\n localSaveError?: string;\n /** Whether fallback mode was used */\n usedFallback: boolean;\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 JSON content with proper indentation\n * @param content - JSON string to beautify\n * @returns Object with beautified JSON string and error flag\n */\nexport function beautifyJson(content: string): { code: string; parseFailed: boolean } {\n try {\n const parsed = JSON.parse(content);\n return { code: JSON.stringify(parsed, null, 2), parseFailed: false };\n } catch {\n // If parsing fails, return original content (Requirement 8.5)\n return { code: content, parseFailed: true };\n }\n}\n\n/**\n * Simple HTML/XML beautification with indentation\n * This is a basic formatter that handles common cases\n * @param content - HTML/XML string to beautify\n * @returns Beautified HTML/XML string, or original content if formatting fails\n */\nexport function beautifyHtml(content: string): string {\n try {\n // Simple regex-based formatting for HTML/XML\n // This handles basic indentation without a full parser\n \n let formatted = '';\n let indent = 0;\n const indentStr = ' '; // 2 spaces\n \n // Normalize line endings and split by tags\n const normalized = content.replace(/\\r\\n/g, '\\n').replace(/\\r/g, '\\n');\n \n // Split content into tokens (tags and text)\n const tokens = normalized.split(/(<[^>]+>)/g).filter(token => token.trim() !== '');\n \n for (const token of tokens) {\n const trimmedToken = token.trim();\n \n if (!trimmedToken) continue;\n \n // Check if it's a tag\n if (trimmedToken.startsWith('<')) {\n // Self-closing tag or declaration\n if (trimmedToken.startsWith('<!') || \n trimmedToken.startsWith('<?') || \n trimmedToken.endsWith('/>')) {\n formatted += indentStr.repeat(indent) + trimmedToken + '\\n';\n }\n // Closing tag\n else if (trimmedToken.startsWith('</')) {\n indent = Math.max(0, indent - 1);\n formatted += indentStr.repeat(indent) + trimmedToken + '\\n';\n }\n // Opening tag\n else {\n formatted += indentStr.repeat(indent) + trimmedToken + '\\n';\n indent++;\n }\n } else {\n // Text content - preserve it with current indentation\n const textLines = trimmedToken.split('\\n');\n for (const line of textLines) {\n const trimmedLine = line.trim();\n if (trimmedLine) {\n formatted += indentStr.repeat(indent) + trimmedLine + '\\n';\n }\n }\n }\n }\n \n return formatted.trimEnd();\n } catch {\n // If formatting fails, return original content (Requirement 8.5)\n return content;\n }\n}\n\n/**\n * Simple CSS beautification with indentation\n * @param content - CSS string to beautify\n * @returns Beautified CSS string, or original content if formatting fails\n */\nexport function beautifyCss(content: string): string {\n try {\n // Simple regex-based formatting for CSS\n let formatted = content;\n \n // Normalize line endings\n formatted = formatted.replace(/\\r\\n/g, '\\n').replace(/\\r/g, '\\n');\n \n // Add newline after { and before }\n formatted = formatted.replace(/\\{/g, ' {\\n');\n formatted = formatted.replace(/\\}/g, '\\n}\\n');\n \n // Add newline after ;\n formatted = formatted.replace(/;/g, ';\\n');\n \n // Clean up multiple newlines\n formatted = formatted.replace(/\\n\\s*\\n/g, '\\n');\n \n // Add indentation\n const lines = formatted.split('\\n');\n let indent = 0;\n const indentStr = ' ';\n const result: string[] = [];\n \n for (const line of lines) {\n const trimmed = line.trim();\n if (!trimmed) continue;\n \n // Decrease indent before closing brace\n if (trimmed.startsWith('}')) {\n indent = Math.max(0, indent - 1);\n }\n \n result.push(indentStr.repeat(indent) + trimmed);\n \n // Increase indent after opening brace\n if (trimmed.endsWith('{')) {\n indent++;\n }\n }\n \n return result.join('\\n');\n } catch {\n // If formatting fails, return original content (Requirement 8.5)\n return content;\n }\n}\n\n/**\n * Beautify code string directly based on language\n * @param code - Source code to beautify\n * @param language - Language type\n * @returns Beautified code (or original if fallback mode)\n */\nexport function beautifyCode(\n code: string,\n language: SupportedLanguage\n): { code: string; usedFallback: boolean } {\n const langInfo = getLanguageInfo(language);\n \n // If language doesn't support beautification, return original (fallback mode)\n if (!langInfo.supportsBeautify) {\n return { code, usedFallback: true };\n }\n \n switch (language) {\n case 'json': {\n const result = beautifyJson(code);\n // If JSON parsing failed, use fallback mode (Requirement 8.4)\n return { code: result.code, usedFallback: result.parseFailed };\n }\n case 'html':\n case 'xml':\n return { code: beautifyHtml(code), usedFallback: false };\n case 'css':\n return { code: beautifyCss(code), usedFallback: false };\n case 'javascript':\n case 'typescript':\n // JS/TS beautification requires async esbuild, handled separately\n // This function is for sync beautification of simple formats\n return { code, usedFallback: true };\n default:\n // Unknown language - fallback mode\n return { code, usedFallback: true };\n }\n}\n\n/**\n * Beautify file based on detected or specified language\n * - JS/TS: Use esbuild for formatting with source map\n * - JSON: Use JSON.stringify with indentation\n * - HTML/XML: Use simple indentation-based formatting\n * - CSS: Use simple formatting\n * - Unknown: Return original (fallback mode)\n * \n * @param originalPath - Original file path\n * @param options - Optional beautify options (language, saveLocal, etc.)\n * @returns Beautified code and Source Map (null for non-JS/TS)\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 \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 // Detect or use specified language\n const langInfo = options?.language \n ? getLanguageInfo(options.language)\n : detectLanguage(absolutePath);\n \n const language = langInfo.language;\n \n // Get local paths for local save/read\n const localPaths = getLocalPaths(absolutePath);\n \n // Handle non-JS/TS languages (no caching, no source map)\n if (language !== 'javascript' && language !== 'typescript') {\n const content = await fs.readFile(absolutePath, 'utf-8');\n const beautified = beautifyCode(content, language);\n \n return {\n code: beautified.code,\n rawMap: null, // No source map for non-JS/TS\n localPath: localPaths.beautifiedPath,\n localMapPath: localPaths.mapPath,\n usedFallback: beautified.usedFallback,\n };\n }\n \n // JS/TS processing with esbuild and caching\n // Check local cache first\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 usedFallback: false,\n };\n } catch {\n // If reading local cache fails, fall through to regenerate\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 localPath: localPaths.beautifiedPath,\n localMapPath: localPaths.mapPath,\n usedFallback: false,\n };\n \n // Also save to local directory\n await saveToLocal(result, localPaths, mapContent);\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 // If esbuild fails, fall back to returning original content\n const content = await fs.readFile(absolutePath, 'utf-8');\n return {\n code: content,\n rawMap: null,\n localPath: localPaths.beautifiedPath,\n localMapPath: localPaths.mapPath,\n usedFallback: true,\n };\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 // If output files are missing, fall back to original content\n const content = await fs.readFile(absolutePath, 'utf-8');\n return {\n code: content,\n rawMap: null,\n localPath: localPaths.beautifiedPath,\n localMapPath: localPaths.mapPath,\n usedFallback: true,\n };\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 = {\n code,\n rawMap,\n localPath: localPaths.beautifiedPath,\n localMapPath: localPaths.mapPath,\n usedFallback: false,\n };\n \n // Save to local directory\n await saveToLocal(result, localPaths, mapText);\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 * as path from 'path';\n\n/**\n * Supported language types for smart-fs processing\n */\nexport type SupportedLanguage =\n | 'javascript'\n | 'typescript'\n | 'json'\n | 'html'\n | 'xml'\n | 'css'\n | 'unknown';\n\n/**\n * Information about a language's processing capabilities\n */\nexport interface LanguageInfo {\n /** The language identifier */\n language: SupportedLanguage;\n /** Whether AST-based processing is supported */\n supportsAST: boolean;\n /** Whether beautification is supported */\n supportsBeautify: boolean;\n /** Whether source map generation is supported */\n supportsSourceMap: boolean;\n}\n\n/**\n * Language configuration mapping\n */\nconst LANGUAGE_CONFIG: Record<SupportedLanguage, LanguageInfo> = {\n javascript: {\n language: 'javascript',\n supportsAST: true,\n supportsBeautify: true,\n supportsSourceMap: true,\n },\n typescript: {\n language: 'typescript',\n supportsAST: true,\n supportsBeautify: true,\n supportsSourceMap: true,\n },\n json: {\n language: 'json',\n supportsAST: false,\n supportsBeautify: true,\n supportsSourceMap: false,\n },\n html: {\n language: 'html',\n supportsAST: false,\n supportsBeautify: true,\n supportsSourceMap: false,\n },\n xml: {\n language: 'xml',\n supportsAST: false,\n supportsBeautify: true,\n supportsSourceMap: false,\n },\n css: {\n language: 'css',\n supportsAST: false,\n supportsBeautify: true,\n supportsSourceMap: false,\n },\n unknown: {\n language: 'unknown',\n supportsAST: false,\n supportsBeautify: false,\n supportsSourceMap: false,\n },\n};\n\n/**\n * File extension to language mapping\n */\nconst EXTENSION_MAP: Record<string, SupportedLanguage> = {\n '.js': 'javascript',\n '.mjs': 'javascript',\n '.cjs': 'javascript',\n '.jsx': 'javascript',\n '.ts': 'typescript',\n '.tsx': 'typescript',\n '.mts': 'typescript',\n '.cts': 'typescript',\n '.json': 'json',\n '.html': 'html',\n '.htm': 'html',\n '.xml': 'xml',\n '.svg': 'xml',\n '.css': 'css',\n};\n\n/**\n * Detect language from file path based on extension\n * \n * @param filePath - Path to the file (can be relative or absolute)\n * @returns LanguageInfo object with detected language and capabilities\n * \n * @example\n * ```typescript\n * const info = detectLanguage('./src/app.ts');\n * // { language: 'typescript', supportsAST: true, supportsBeautify: true, supportsSourceMap: true }\n * \n * const unknown = detectLanguage('./readme.md');\n * // { language: 'unknown', supportsAST: false, supportsBeautify: false, supportsSourceMap: false }\n * ```\n */\nexport function detectLanguage(filePath: string): LanguageInfo {\n const ext = path.extname(filePath).toLowerCase();\n const language = EXTENSION_MAP[ext] ?? 'unknown';\n return LANGUAGE_CONFIG[language];\n}\n\n/**\n * Get language info by explicit language name\n * \n * @param language - The language identifier\n * @returns LanguageInfo object with language capabilities\n * \n * @example\n * ```typescript\n * const info = getLanguageInfo('typescript');\n * // { language: 'typescript', supportsAST: true, supportsBeautify: true, supportsSourceMap: true }\n * ```\n */\nexport function getLanguageInfo(language: SupportedLanguage): LanguageInfo {\n return LANGUAGE_CONFIG[language];\n}\n\n/**\n * Check if a language supports full processing (AST + beautify + source map)\n * \n * @param language - The language identifier\n * @returns true if the language supports all processing features\n * \n * @example\n * ```typescript\n * isFullySupportedLanguage('javascript'); // true\n * isFullySupportedLanguage('json'); // false (no AST or source map)\n * isFullySupportedLanguage('unknown'); // false\n * ```\n */\nexport function isFullySupportedLanguage(language: SupportedLanguage): boolean {\n const info = LANGUAGE_CONFIG[language];\n return info.supportsAST && info.supportsBeautify && info.supportsSourceMap;\n}\n\n/**\n * Get all supported file extensions\n * \n * @returns Array of supported file extensions (including the dot)\n */\nexport function getSupportedExtensions(): string[] {\n return Object.keys(EXTENSION_MAP);\n}\n\n/**\n * Check if a file extension is supported (not unknown)\n * \n * @param ext - File extension (with or without leading dot)\n * @returns true if the extension maps to a known language\n */\nexport function isExtensionSupported(ext: string): boolean {\n const normalizedExt = ext.startsWith('.') ? ext.toLowerCase() : `.${ext.toLowerCase()}`;\n return normalizedExt in EXTENSION_MAP;\n}\n", "import { parse } from 'meriyah';\nimport { walk } from 'estree-walker';\nimport MagicString from 'magic-string';\nimport type { Node } from 'estree';\nimport { detectLanguage, getLanguageInfo, type SupportedLanguage } from './languageDetector.js';\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 * Options for truncation operations\n */\nexport interface TruncateOptions {\n /** Override auto-detected language */\n language?: SupportedLanguage;\n /** Character limit for string truncation (default: 200) */\n charLimit?: number;\n /** Maximum characters per line (default: 500) */\n maxLineChars?: number;\n /** Preview length for truncated content (default: 50) */\n previewLength?: number;\n}\n\n/**\n * Result of truncation operation\n */\nexport interface TruncateResult {\n /** Truncated code */\n code: string;\n /** Whether fallback mode was used */\n usedFallback: boolean;\n}\n\n/**\n * Result of AST-based truncation\n */\ninterface ASTTruncateResult {\n /** Truncated code */\n code: string;\n /** Whether parsing failed and fallback was used */\n parseFailed: boolean;\n}\n\n/**\n * Truncate long strings in JavaScript/TypeScript code using AST-based processing\n * This function uses meriyah to parse the AST and truncate string literals\n * \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 ASTTruncateResult with truncated code and parse failure indicator\n */\nfunction truncateCodeAST(sourceCode: string, limit: number = 200, previewLength: number = 50): ASTTruncateResult {\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 8.4, 8.5)\n // Signal that fallback mode should be used\n return { code: sourceCode, parseFailed: true };\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 { code: magicString.toString(), parseFailed: false };\n}\n\n/**\n * Legacy function name for backward compatibility\n * @deprecated Use truncateCode instead\n */\nexport function truncateCodeHighPerf(sourceCode: string, limit: number = 200, previewLength: number = 50): string {\n return truncateCodeAST(sourceCode, limit, previewLength).code;\n}\n\n/**\n * Fallback truncation for unsupported languages\n * Only truncates lines exceeding the character limit, no AST parsing\n * Preserves the original line count (Requirement 3.3)\n * \n * @param code - Source code to process\n * @param maxLineChars - Maximum characters per line (default: 500)\n * @param previewLength - Length of start/end preview portions (default: 50)\n * @returns Truncated code with preserved line count\n */\nexport function truncateFallback(\n code: string,\n maxLineChars: number = 500,\n previewLength: number = 50\n): string {\n if (!code) {\n return code;\n }\n\n const lines = code.split('\\n');\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\n/**\n * Truncate code based on language type\n * - For JS/TS: Use AST-based truncation for string literals + line truncation\n * - For other languages: Use line-based truncation only (fallback mode)\n * \n * @param code - Source code to process\n * @param options - Truncation options including language, limits, etc.\n * @returns TruncateResult with truncated code and fallback indicator\n */\nexport function truncateCode(\n code: string,\n options?: TruncateOptions\n): TruncateResult {\n const {\n language,\n charLimit = 200,\n maxLineChars = 500,\n previewLength = 50,\n } = options ?? {};\n\n // Determine language info\n const langInfo = language ? getLanguageInfo(language) : null;\n \n // Check if AST-based truncation is supported\n const supportsAST = langInfo?.supportsAST ?? false;\n \n if (supportsAST && (language === 'javascript' || language === 'typescript')) {\n // Use AST-based truncation for JS/TS\n const astResult = truncateCodeAST(code, charLimit, previewLength);\n \n // If AST parsing failed, fall back to line-based truncation (Requirement 8.4)\n if (astResult.parseFailed) {\n const truncatedCode = truncateFallback(code, maxLineChars, previewLength);\n return {\n code: truncatedCode,\n usedFallback: true,\n };\n }\n \n // Also apply line truncation to AST-processed code\n const truncatedCode = truncateLongLines(astResult.code, maxLineChars, previewLength / maxLineChars);\n return {\n code: truncatedCode,\n usedFallback: false,\n };\n }\n \n // Fallback mode: only line-based truncation (Requirement 3.2)\n const truncatedCode = truncateFallback(code, maxLineChars, previewLength);\n return {\n code: truncatedCode,\n usedFallback: true,\n };\n}\n\n/**\n * Truncate code from a file path, auto-detecting language\n * \n * @param filePath - Path to the file (used for language detection)\n * @param code - Source code to process\n * @param options - Truncation options (language override, limits, etc.)\n * @returns TruncateResult with truncated code and fallback indicator\n */\nexport function truncateCodeFromFile(\n filePath: string,\n code: string,\n options?: Omit<TruncateOptions, 'language'> & { language?: SupportedLanguage }\n): TruncateResult {\n // Detect language from file path if not specified\n const language = options?.language ?? detectLanguage(filePath).language;\n \n return truncateCode(code, {\n ...options,\n language,\n });\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 { truncateLongLines } from '../truncator.js';\nimport { searchInCode, formatSearchResult, unescapeBackslashes } 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 is_regex: z.boolean().default(false).describe('Treat query as regex pattern (default: false for literal text search)'),\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 is_regex: z.boolean().default(false).describe('Treat query as regex pattern (default: false for literal text search)'),\n },\n handler: async (params) => {\n const { file_path, query, context_lines, case_sensitive, char_limit, max_line_chars, is_regex } = params;\n\n // Unescape double-escaped backslashes from MCP JSON transmission\n const unescapedQuery = unescapeBackslashes(query);\n\n // Beautify the file and get source map\n const beautifyResult = await ensureBeautified(file_path);\n const { code, rawMap } = beautifyResult;\n\n // Execute search on original beautified code (no truncation before search)\n const searchResult = searchInCode(code, rawMap, {\n query: unescapedQuery,\n contextLines: context_lines,\n caseSensitive: case_sensitive,\n maxMatches: 50,\n isRegex: is_regex,\n });\n\n // Format the result\n let output = formatSearchResult(file_path, unescapedQuery, case_sensitive, searchResult, 50, is_regex);\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 /** Treat query as regex pattern (default false for literal text search) */\n isRegex?: boolean;\n /** Timeout in milliseconds for search operation (default 500) */\n timeoutMs?: 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 * Convert double-escaped backslashes to single backslashes.\n * Fixes MCP JSON transmission double-escaping issue.\n * \n * @param str - String with potentially double-escaped backslashes\n * @returns String with `\\\\` converted to `\\`\n * \n * @example\n * unescapeBackslashes(\"for\\\\s*\\\\(\") // returns \"for\\s*\\(\"\n * unescapeBackslashes(\"\\\\\\\\n\") // returns \"\\\\n\" (literal backslash + n)\n * unescapeBackslashes(\"hello\") // returns \"hello\" (unchanged)\n */\nexport function unescapeBackslashes(str: string): string {\n return str.replace(/\\\\\\\\/g, '\\\\');\n}\n\n/**\n * Escape all regex special characters in a string for literal matching\n * @param str - String to escape\n * @returns Escaped string safe for use in RegExp\n */\nexport function escapeRegex(str: string): string {\n return str.replace(/[()[\\]{}.*+?^$|\\\\]/g, '\\\\$&');\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 * @param isRegex - Whether to treat query as regex (default false)\n * @returns Created RegExp\n * @throws Error if regex is invalid\n */\nexport function createRegex(query: string, caseSensitive: boolean = false, isRegex: boolean = false): RegExp {\n try {\n const flags = caseSensitive ? 'g' : 'gi';\n const pattern = isRegex ? query : escapeRegex(query);\n return new RegExp(pattern, 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 * Build line offset index using Int32Array for memory efficiency.\n * Returns the offset array and total line count.\n */\nfunction buildLineOffsets(code: string): { offsets: Int32Array; totalLines: number } {\n // Pre-allocate with estimated average line length of 40 chars\n let capacity = Math.max(16, Math.ceil(code.length / 40));\n let offsets = new Int32Array(capacity);\n let lineCount = 0;\n\n offsets[0] = 0; // First line starts at index 0\n\n for (let i = 0; i < code.length; i++) {\n if (code[i] === '\\n') {\n lineCount++;\n // Dynamic resize if needed\n if (lineCount >= capacity) {\n capacity *= 2;\n const newArr = new Int32Array(capacity);\n newArr.set(offsets);\n offsets = newArr;\n }\n offsets[lineCount] = i + 1; // Next line starts after \\n\n }\n }\n\n return {\n offsets: offsets.subarray(0, lineCount + 1),\n totalLines: lineCount + 1,\n };\n}\n\n/**\n * Binary search to find line number (1-based) from character index.\n */\nfunction getLineNumberFromIndex(offsets: Int32Array, totalLines: number, index: number): number {\n let low = 0;\n let high = totalLines - 1;\n\n while (low <= high) {\n const mid = (low + high) >>> 1;\n if (offsets[mid] <= index) {\n low = mid + 1;\n } else {\n high = mid - 1;\n }\n }\n return low; // 1-based line number\n}\n\n/**\n * Get line content by line number (1-based) without splitting entire string.\n */\nfunction getLineContent(\n code: string,\n offsets: Int32Array,\n totalLines: number,\n lineNo: number\n): string {\n if (lineNo < 1 || lineNo > totalLines) return '';\n\n const start = offsets[lineNo - 1];\n let end: number;\n\n if (lineNo < totalLines) {\n // End is one before the next line's start (exclude \\n)\n end = offsets[lineNo] - 1;\n } else {\n // Last line: go to end of string\n end = code.length;\n }\n\n // Handle \\r\\n line endings\n if (end > start && code[end - 1] === '\\r') {\n end--;\n }\n\n return code.slice(start, end);\n}\n\n/**\n * Search for pattern in code and return matches with context.\n * Optimized version: avoids split() for large files, uses index-based iteration.\n *\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 = 10,\n isRegex = false,\n timeoutMs = 500,\n } = options;\n\n // Build line offset index (memory efficient)\n const { offsets, totalLines } = buildLineOffsets(code);\n\n // Create regex with global + multiline flags\n const flags = (caseSensitive ? 'g' : 'gi') + 'm';\n const patternStr = isRegex ? unescapeBackslashes(query) : escapeRegex(query);\n\n let regex: RegExp;\n try {\n regex = new RegExp(patternStr, flags);\n } catch (err) {\n const message = err instanceof Error ? err.message : String(err);\n throw new Error(`Invalid regex: ${message}`);\n }\n\n // Create source map consumer\n const consumer = new SourceMapConsumer({\n ...rawMap,\n version: String(rawMap.version),\n });\n\n const matches: SearchMatch[] = [];\n let lastMatchedLine = -1;\n let totalMatchesFound = 0;\n let match: RegExpExecArray | null;\n\n // Performance protection\n const startTime = Date.now();\n\n // Iterate matches using exec() - no string splitting\n while ((match = regex.exec(code)) !== null) {\n // Prevent infinite loop on zero-width matches\n if (match.index === regex.lastIndex) {\n regex.lastIndex++;\n }\n\n const lineNumber = getLineNumberFromIndex(offsets, totalLines, match.index);\n\n // Dedupe: skip if same line already matched\n if (lineNumber === lastMatchedLine) {\n continue;\n }\n lastMatchedLine = lineNumber;\n totalMatchesFound++;\n\n // Only build match details if we haven't hit the limit yet\n if (matches.length < maxMatches) {\n // Build context (lazy: only fetch line content when needed)\n const contextBefore: ContextLine[] = [];\n for (let i = Math.max(1, lineNumber - contextLines); i < lineNumber; i++) {\n contextBefore.push({\n lineNumber: i,\n content: getLineContent(code, offsets, totalLines, i),\n originalPosition: getOriginalPosition(consumer, i),\n });\n }\n\n const contextAfter: ContextLine[] = [];\n for (let i = lineNumber + 1; i <= Math.min(totalLines, lineNumber + contextLines); i++) {\n contextAfter.push({\n lineNumber: i,\n content: getLineContent(code, offsets, totalLines, i),\n originalPosition: getOriginalPosition(consumer, i),\n });\n }\n\n matches.push({\n lineNumber,\n lineContent: getLineContent(code, offsets, totalLines, lineNumber),\n originalPosition: getOriginalPosition(consumer, lineNumber),\n contextBefore,\n contextAfter,\n });\n }\n\n // Timeout protection (still count but stop searching)\n if (Date.now() - startTime > timeoutMs) {\n break;\n }\n }\n\n return {\n matches,\n totalMatches: totalMatchesFound,\n truncated: totalMatchesFound > maxMatches,\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 a single code line with line number, source coordinates, and content\n * Matches the format used in read_code_smart\n */\nfunction formatCodeLine(lineNumber: number, sourcePos: string, code: string, maxLineNumWidth: number, prefix: string = ' '): string {\n const lineNumStr = String(lineNumber).padStart(maxLineNumWidth, ' ');\n const srcPosPadded = sourcePos ? sourcePos.padEnd(10, ' ') : ' ';\n return `${prefix}${lineNumStr} ${srcPosPadded} ${code}`;\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 * @param isRegex - Whether query was treated as regex pattern\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 isRegex: boolean = false\n): string {\n const { matches, totalMatches, truncated } = result;\n\n const outputParts: string[] = [];\n\n // Header - matches read_code_smart format\n const caseInfo = caseSensitive ? 'case-sensitive' : 'case-insensitive';\n const modeInfo = isRegex ? 'regex' : 'literal';\n outputParts.push(`${filePath}`);\n outputParts.push(`Query=\"${query}\" (${modeInfo}, ${caseInfo})`);\n outputParts.push(`Src=original position for breakpoints`);\n\n if (totalMatches === 0) {\n outputParts.push('Matches: None');\n return outputParts.join('\\n');\n }\n\n const matchInfo = truncated\n ? `Matches: ${totalMatches} (showing first ${maxMatches})`\n : `Matches: ${totalMatches}`;\n outputParts.push(matchInfo);\n\n // Format each match\n for (const match of matches) {\n outputParts.push(`--- 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 srcPos = formatSourcePosition(ctx.originalPosition.line, ctx.originalPosition.column);\n outputParts.push(formatCodeLine(ctx.lineNumber, srcPos, ctx.content, maxLineNumWidth, ' '));\n }\n\n // Format match line with >> prefix\n const matchSrcPos = formatSourcePosition(match.originalPosition.line, match.originalPosition.column);\n outputParts.push(formatCodeLine(match.lineNumber, matchSrcPos, match.lineContent, maxLineNumWidth, '>>'));\n\n // Format context after\n for (const ctx of match.contextAfter) {\n const srcPos = formatSourcePosition(ctx.originalPosition.line, ctx.originalPosition.column);\n outputParts.push(formatCodeLine(ctx.lineNumber, srcPos, ctx.content, maxLineNumWidth, ' '));\n }\n }\n\n // Add truncation message if needed\n if (truncated) {\n outputParts.push(`\\n... (${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 = await 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\ntype TraverseFn = (\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\nlet traverse: TraverseFn | null = null;\n\nasync function getTraverse(): Promise<TraverseFn> {\n if (!traverse) {\n const mod = await import('@babel/traverse');\n // Handle both ESM default export and CJS module.exports\n traverse = (mod.default?.default ?? mod.default) as TraverseFn;\n }\n return traverse;\n}\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 async function analyzeBindings(\n code: string,\n rawMap: SourceMap,\n identifier: string,\n options?: AnalyzeOptions\n): Promise<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 // Get traverse function\n const traverse = await getTraverse();\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 * Format a single code line with line number, source coordinates, and content\n * Matches the format used in read_code_smart\n */\nfunction formatCodeLine(lineNumber: number, sourcePos: string, code: string, prefix: string = ' '): string {\n const lineNumStr = String(lineNumber).padStart(5, ' ');\n const srcPosPadded = sourcePos ? sourcePos.padEnd(10, ' ') : ' ';\n return `${prefix}${lineNumStr} ${srcPosPadded} ${code}`;\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 - matches read_code_smart format\n outputParts.push(`${filePath}`);\n outputParts.push(`Identifier=\"${identifier}\"`);\n outputParts.push(`Src=original position for breakpoints`);\n \n // Handle no bindings found\n if (bindings.length === 0) {\n if (isTargeted && targetLine !== undefined) {\n outputParts.push(`Bindings: None 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: None');\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 (Targeted at line ${targetLine})`);\n } else {\n const scopeInfo = bindings.length > 1 ? ' (different scopes)' : '';\n outputParts.push(`Bindings: ${bindings.length}${scopeInfo}`);\n }\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 defMarker = defIsHit ? ' \u25C0\u2500\u2500 hit' : '';\n outputParts.push(formatCodeLine(binding.definition.line, defSrcPos, binding.definition.lineContent + defMarker, ' '));\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 refMarker = refIsHit ? ' \u25C0\u2500\u2500 hit' : '';\n outputParts.push(formatCodeLine(ref.line, refSrcPos, ref.lineContent + refMarker, ' '));\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 \n return outputParts.join('\\n');\n}\n", "import { SourceMapConsumer } from 'source-map-js';\nimport { ensureBeautified } from '../beautifier.js';\nimport { truncateCodeHighPerf } from '../truncator.js';\n\n/**\n * Formatted code result interface\n */\nexport interface FormattedCode {\n content: string; // \u683C\u5F0F\u5316\u540E\u7684\u4EE3\u7801\u5B57\u7B26\u4E32\n totalLines: number; // \u603B\u884C\u6570\n startLine: number; // \u5B9E\u9645\u8D77\u59CB\u884C\n endLine: number; // \u5B9E\u9645\u7ED3\u675F\u884C\n}\n\n/**\n * Detection type for JSVMP patterns\n */\nexport type DetectionType = \n | \"If-Else Dispatcher\" \n | \"Switch Dispatcher\" \n | \"Instruction Array\" \n | \"Stack Operation\";\n\n/**\n * Confidence level for detection results\n */\nexport type ConfidenceLevel = \"ultra_high\" | \"high\" | \"medium\" | \"low\";\n\n/**\n * A detected region in the code\n */\nexport interface DetectionRegion {\n start: number; // \u8D77\u59CB\u884C\u53F7\n end: number; // \u7ED3\u675F\u884C\u53F7\n type: DetectionType; // \u68C0\u6D4B\u7C7B\u578B\n confidence: ConfidenceLevel; // \u7F6E\u4FE1\u5EA6\n description: string; // \u63CF\u8FF0\uFF08\u4E2D\u6587\uFF09\n}\n\n/**\n * Complete detection result from LLM analysis\n */\nexport interface DetectionResult {\n summary: string; // \u5206\u6790\u6458\u8981\uFF08\u4E2D\u6587\uFF09\n regions: DetectionRegion[];\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 a single code line with line number, source coordinates, and content\n * Format: \"LineNo SourceLoc Code\"\n */\nfunction formatCodeLine(lineNumber: number, sourcePos: string, code: string): string {\n const lineNumStr = String(lineNumber).padStart(5, ' ');\n const srcPosPadded = sourcePos ? sourcePos.padEnd(10, ' ') : ' ';\n return `${lineNumStr} ${srcPosPadded} ${code}`;\n}\n\n/**\n * \u683C\u5F0F\u5316\u4EE3\u7801\u4E3A LLM \u5206\u6790\u683C\u5F0F\n * \u683C\u5F0F: \"LineNo SourceLoc Code\"\n * \n * \u5904\u7406\u6D41\u7A0B\uFF1A\n * 1. \u8C03\u7528 ensureBeautified \u7F8E\u5316\u4EE3\u7801\n * 2. \u8C03\u7528 truncateCodeHighPerf \u622A\u65AD\u957F\u5B57\u7B26\u4E32\n * 3. \u4F7F\u7528 SourceMapConsumer \u83B7\u53D6\u539F\u59CB\u5750\u6807\n * 4. \u683C\u5F0F\u5316\u4E3A \"LineNo SourceLoc Code\" \u683C\u5F0F\n * \n * @param filePath - Path to the JavaScript file\n * @param startLine - Start line number (1-based)\n * @param endLine - End line number (1-based)\n * @param charLimit - Character limit for string truncation (default 300)\n * @returns FormattedCode object with formatted content and metadata\n */\nexport async function formatCodeForAnalysis(\n filePath: string,\n startLine: number,\n endLine: number,\n charLimit: number = 300\n): Promise<FormattedCode> {\n // Step 1: Beautify the file and get source map\n const beautifyResult = await ensureBeautified(filePath);\n const { code, rawMap } = beautifyResult;\n\n // Step 2: Truncate long strings\n const truncatedCode = truncateCodeHighPerf(code, charLimit);\n\n // Split into lines\n const lines = truncatedCode.split('\\n');\n const totalLines = lines.length;\n\n // Step 3: Adjust line range boundaries (Requirements 2.3)\n const effectiveStartLine = Math.max(1, Math.min(totalLines, startLine));\n const effectiveEndLine = Math.max(effectiveStartLine, Math.min(totalLines, endLine));\n\n // Step 4: Create source map consumer\n const consumer = new SourceMapConsumer({\n ...rawMap,\n version: String(rawMap.version),\n });\n\n // Step 5: Format each line with \"LineNo SourceLoc Code\" format\n const formattedLines: string[] = [];\n\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 formattedLines.push(formatCodeLine(lineNum, sourcePos, lineContent));\n }\n\n return {\n content: formattedLines.join('\\n'),\n totalLines,\n startLine: effectiveStartLine,\n endLine: effectiveEndLine,\n };\n}\n\n/**\n * Valid detection types for validation\n */\nconst VALID_DETECTION_TYPES: DetectionType[] = [\n \"If-Else Dispatcher\",\n \"Switch Dispatcher\",\n \"Instruction Array\",\n \"Stack Operation\"\n];\n\n/**\n * Valid confidence levels for validation\n */\nconst VALID_CONFIDENCE_LEVELS: ConfidenceLevel[] = [\n \"ultra_high\",\n \"high\",\n \"medium\",\n \"low\"\n];\n\n/**\n * Check if a value is a valid DetectionType\n */\nfunction isValidDetectionType(value: any): value is DetectionType {\n return VALID_DETECTION_TYPES.includes(value);\n}\n\n/**\n * Check if a value is a valid ConfidenceLevel\n */\nfunction isValidConfidenceLevel(value: any): value is ConfidenceLevel {\n return VALID_CONFIDENCE_LEVELS.includes(value);\n}\n\n/**\n * Parse and validate LLM detection result from JSON string\n * \n * Validates:\n * - JSON is parseable\n * - Required fields exist: summary, regions\n * - Each region has required fields: start, end, type, confidence, description\n * - Enum values are valid\n * \n * @param jsonString - JSON string from LLM response\n * @returns Parsed and validated DetectionResult\n * @throws Error if JSON is invalid or structure doesn't match expected format\n */\nexport function parseDetectionResult(jsonString: string): DetectionResult {\n // Parse JSON (Requirements 3.5)\n let parsed: any;\n try {\n parsed = JSON.parse(jsonString);\n } catch (error) {\n throw new Error(`\u65E0\u6CD5\u89E3\u6790 LLM \u54CD\u5E94: ${error instanceof Error ? error.message : String(error)}`);\n }\n\n // Validate required top-level fields (Requirements 3.3, 4.1)\n if (typeof parsed !== 'object' || parsed === null) {\n throw new Error('LLM \u54CD\u5E94\u683C\u5F0F\u65E0\u6548\uFF0C\u671F\u671B\u5BF9\u8C61\u7C7B\u578B');\n }\n\n if (typeof parsed.summary !== 'string') {\n throw new Error('LLM \u54CD\u5E94\u683C\u5F0F\u65E0\u6548\uFF0C\u7F3A\u5C11\u5FC5\u9700\u5B57\u6BB5: summary');\n }\n\n if (!Array.isArray(parsed.regions)) {\n throw new Error('LLM \u54CD\u5E94\u683C\u5F0F\u65E0\u6548\uFF0C\u7F3A\u5C11\u5FC5\u9700\u5B57\u6BB5: regions');\n }\n\n // Validate each region (Requirements 4.2, 4.3, 4.4)\n const validatedRegions: DetectionRegion[] = [];\n\n for (let i = 0; i < parsed.regions.length; i++) {\n const region = parsed.regions[i];\n\n // Check region is an object\n if (typeof region !== 'object' || region === null) {\n throw new Error(`LLM \u54CD\u5E94\u683C\u5F0F\u65E0\u6548\uFF0Cregions[${i}] \u4E0D\u662F\u5BF9\u8C61`);\n }\n\n // Validate required fields exist and have correct types\n if (typeof region.start !== 'number') {\n throw new Error(`LLM \u54CD\u5E94\u683C\u5F0F\u65E0\u6548\uFF0Cregions[${i}] \u7F3A\u5C11\u5FC5\u9700\u5B57\u6BB5: start`);\n }\n\n if (typeof region.end !== 'number') {\n throw new Error(`LLM \u54CD\u5E94\u683C\u5F0F\u65E0\u6548\uFF0Cregions[${i}] \u7F3A\u5C11\u5FC5\u9700\u5B57\u6BB5: end`);\n }\n\n if (typeof region.type !== 'string') {\n throw new Error(`LLM \u54CD\u5E94\u683C\u5F0F\u65E0\u6548\uFF0Cregions[${i}] \u7F3A\u5C11\u5FC5\u9700\u5B57\u6BB5: type`);\n }\n\n if (typeof region.confidence !== 'string') {\n throw new Error(`LLM \u54CD\u5E94\u683C\u5F0F\u65E0\u6548\uFF0Cregions[${i}] \u7F3A\u5C11\u5FC5\u9700\u5B57\u6BB5: confidence`);\n }\n\n if (typeof region.description !== 'string') {\n throw new Error(`LLM \u54CD\u5E94\u683C\u5F0F\u65E0\u6548\uFF0Cregions[${i}] \u7F3A\u5C11\u5FC5\u9700\u5B57\u6BB5: description`);\n }\n\n // Validate enum values (Requirements 4.3, 4.4)\n if (!isValidDetectionType(region.type)) {\n throw new Error(\n `LLM \u54CD\u5E94\u683C\u5F0F\u65E0\u6548\uFF0Cregions[${i}].type \u503C\u65E0\u6548: \"${region.type}\". ` +\n `\u6709\u6548\u503C: ${VALID_DETECTION_TYPES.join(', ')}`\n );\n }\n\n if (!isValidConfidenceLevel(region.confidence)) {\n throw new Error(\n `LLM \u54CD\u5E94\u683C\u5F0F\u65E0\u6548\uFF0Cregions[${i}].confidence \u503C\u65E0\u6548: \"${region.confidence}\". ` +\n `\u6709\u6548\u503C: ${VALID_CONFIDENCE_LEVELS.join(', ')}`\n );\n }\n\n validatedRegions.push({\n start: region.start,\n end: region.end,\n type: region.type,\n confidence: region.confidence,\n description: region.description,\n });\n }\n\n return {\n summary: parsed.summary,\n regions: validatedRegions,\n };\n}\n\n/**\n * Format detection result for display\n */\nfunction formatDetectionResult(\n result: DetectionResult,\n filePath: string,\n startLine: number,\n endLine: number\n): string {\n const lines: string[] = [];\n \n lines.push('=== JSVMP Dispatcher Detection Result ===');\n lines.push(`File: ${filePath} (${startLine}-${endLine})`);\n lines.push('');\n lines.push(`Summary: ${result.summary}`);\n lines.push('');\n \n if (result.regions.length > 0) {\n lines.push('Detected Regions:');\n for (const region of result.regions) {\n lines.push(`[${region.confidence}] Lines ${region.start}-${region.end}: ${region.type}`);\n lines.push(` ${region.description}`);\n lines.push('');\n }\n } else {\n lines.push('No JSVMP dispatcher patterns detected.');\n }\n \n return lines.join('\\n');\n}\n\nimport { z } from 'zod';\nimport { defineTool } from './ToolDefinition.js';\nimport { getLLMConfig, createLLMClient } from '../llmConfig.js';\nimport { existsSync } from 'fs';\n\n/**\n * Input schema for ai_find_jsvmp_dispatcher tool\n */\nexport const AiFindJsvmpDispatcherInputSchema = z.object({\n file_path: z.string().describe('Path to the JavaScript file to analyze'),\n start_line: z.number().int().positive().describe('Start line number (1-based)'),\n end_line: z.number().int().positive().describe('End line number (1-based)'),\n char_limit: z.number().int().positive().optional().describe('Character limit for string truncation (default: 300)'),\n});\n\n/**\n * ai_find_jsvmp_dispatcher tool definition\n * \n * AI-powered tool that analyzes JavaScript code to find JSVMP (JavaScript Virtual Machine Protection) \n * dispatcher patterns using LLM-based analysis. Requires OPENAI_API_KEY environment variable.\n * \n * Requirements: 5.1, 5.2, 1.2, 5.3\n */\nexport const aiFindJsvmpDispatcher = defineTool({\n name: 'ai_find_jsvmp_dispatcher',\n description: 'AI-powered tool to find JSVMP (JavaScript Virtual Machine Protection) dispatcher patterns in code using LLM analysis. Identifies dispatchers (switch/if-else), virtual stacks, instruction arrays, and other obfuscation patterns. Requires OPENAI_API_KEY environment variable.',\n schema: AiFindJsvmpDispatcherInputSchema.shape,\n handler: async (params) => {\n const { file_path, start_line, end_line, char_limit } = params;\n \n // Check LLM configuration (Requirements 1.2, 5.3)\n const config = getLLMConfig();\n if (!config) {\n return '\u9519\u8BEF\uFF1A\u672A\u914D\u7F6E LLM\u3002\u8BF7\u8BBE\u7F6E\u73AF\u5883\u53D8\u91CF OPENAI_API_KEY \u4EE5\u542F\u7528 JSVMP dispatcher \u68C0\u6D4B\u529F\u80FD\u3002';\n }\n \n // Check file exists (Requirements 2.4)\n if (!existsSync(file_path)) {\n return `\u9519\u8BEF\uFF1A\u6587\u4EF6\u4E0D\u5B58\u5728: ${file_path}`;\n }\n \n try {\n // Format code for analysis (Requirements 2.1, 2.2, 2.3)\n const formattedCode = await formatCodeForAnalysis(\n file_path,\n start_line,\n end_line,\n char_limit\n );\n \n // Create LLM client and analyze (Requirements 3.1, 3.2)\n const client = createLLMClient(config);\n const llmResponse = await client.analyzeJSVMP(formattedCode.content);\n \n // Parse detection result (Requirements 3.3, 4.1, 4.2, 4.3, 4.4)\n const result = parseDetectionResult(llmResponse);\n \n // Format and return result (Requirements 4.1, 4.2)\n return formatDetectionResult(result, file_path, start_line, end_line);\n \n } catch (error) {\n // Error handling (Requirements 3.4, 3.5)\n if (error instanceof Error) {\n return `\u9519\u8BEF\uFF1A${error.message}`;\n }\n return `\u9519\u8BEF\uFF1A${String(error)}`;\n }\n },\n});\n", "/**\n * LLM Configuration Module\n * Handles reading and validating LLM configuration from environment variables\n */\n\nexport interface LLMConfig {\n apiKey: string;\n baseUrl: string;\n model: string;\n}\n\n/**\n * \u4ECE\u73AF\u5883\u53D8\u91CF\u8BFB\u53D6 LLM \u914D\u7F6E\n * @returns LLMConfig | null (null \u8868\u793A\u672A\u914D\u7F6E)\n */\nexport function getLLMConfig(): LLMConfig | null {\n const apiKey = process.env.OPENAI_API_KEY;\n \n // API Key is required\n if (!apiKey) {\n return null;\n }\n \n // Use defaults for optional configuration\n const baseUrl = process.env.OPENAI_BASE_URL || \"https://api.openai.com/v1\";\n const model = process.env.OPENAI_MODEL || \"gpt-4o-mini\";\n \n return {\n apiKey,\n baseUrl,\n model\n };\n}\n\n/**\n * \u68C0\u67E5 LLM \u662F\u5426\u5DF2\u914D\u7F6E\n */\nexport function isLLMConfigured(): boolean {\n return getLLMConfig() !== null;\n}\n\n/**\n * LLM Client Interface\n */\nexport interface LLMClient {\n /**\n * \u53D1\u9001 JSVMP \u68C0\u6D4B\u8BF7\u6C42\u5230 LLM\n * @param formattedCode \u683C\u5F0F\u5316\u540E\u7684\u4EE3\u7801\n * @returns LLM \u8FD4\u56DE\u7684\u539F\u59CB JSON \u5B57\u7B26\u4E32\n */\n analyzeJSVMP(formattedCode: string): Promise<string>;\n}\n\n/**\n * \u6784\u5EFA JSVMP \u68C0\u6D4B\u7CFB\u7EDF\u63D0\u793A\u8BCD\n */\nfunction buildJSVMPSystemPrompt(): string {\n return `\u4F60\u662F\u4E00\u4E2A\u4E13\u4E1A\u7684 JavaScript \u9006\u5411\u5DE5\u7A0B\u4E13\u5BB6\uFF0C\u4E13\u95E8\u8BC6\u522B JSVMP\uFF08JavaScript Virtual Machine Protection\uFF09\u4FDD\u62A4\u4EE3\u7801\u3002\n\nJSVMP \u662F\u4E00\u79CD\u4EE3\u7801\u4FDD\u62A4\u6280\u672F\uFF0C\u5C06 JavaScript \u4EE3\u7801\u8F6C\u6362\u4E3A\u5B57\u8282\u7801\uFF0C\u5E76\u901A\u8FC7\u865A\u62DF\u673A\u6267\u884C\u3002\u5178\u578B\u7279\u5F81\u5305\u62EC\uFF1A\n\n1. **\u865A\u62DF\u6808\uFF08Virtual Stack\uFF09**\uFF1A\u4E2D\u592E\u6570\u7EC4\u7528\u4E8E\u5B58\u50A8\u64CD\u4F5C\u6570\u548C\u7ED3\u679C\n2. **\u5206\u53D1\u5668\uFF08Dispatcher\uFF09**\uFF1A\u5927\u578B switch \u8BED\u53E5\u6216\u5D4C\u5957 if-else \u94FE\uFF0C\u6839\u636E\u6307\u4EE4\u7801\u6267\u884C\u4E0D\u540C\u64CD\u4F5C\n3. **\u6307\u4EE4\u6570\u7EC4\uFF08Instruction Array\uFF09**\uFF1A\u5B58\u50A8\u5B57\u8282\u7801\u6307\u4EE4\u7684\u6570\u7EC4\n4. **\u4E3B\u5FAA\u73AF\uFF08Main Loop\uFF09**\uFF1Awhile \u5FAA\u73AF\u6301\u7EED\u6267\u884C\u6307\u4EE4\n\n\u68C0\u6D4B\u89C4\u5219\uFF1A\n\n**Ultra High \u7F6E\u4FE1\u5EA6**\uFF1A\n- \u540C\u65F6\u51FA\u73B0\uFF1A\u4E3B\u5FAA\u73AF + \u5206\u53D1\u5668 + \u6808\u64CD\u4F5C\n- \u5206\u53D1\u5668\u6709 >20 \u4E2A case \u6216 >10 \u5C42\u5D4C\u5957\n- \u660E\u786E\u7684\u6808\u64CD\u4F5C\u6A21\u5F0F\uFF08push/pop/\u6570\u7EC4\u7D22\u5F15\uFF09\n\n**High \u7F6E\u4FE1\u5EA6**\uFF1A\n- \u72EC\u7ACB\u7684\u5927\u578B\u5206\u53D1\u5668\u7ED3\u6784\uFF08>20 case \u7684 switch \u6216 >10 \u5C42\u5D4C\u5957\u7684 if-else\uFF09\n- \u660E\u786E\u7684\u6307\u4EE4\u6570\u7EC4\u548C\u7A0B\u5E8F\u8BA1\u6570\u5668\u6A21\u5F0F\n\n**Medium \u7F6E\u4FE1\u5EA6**\uFF1A\n- \u5B64\u7ACB\u7684\u6808\u64CD\u4F5C\u6216\u53EF\u7591\u7684 while \u5FAA\u73AF\n- \u90E8\u5206 JSVMP \u7279\u5F81\u4F46\u4E0D\u5B8C\u6574\n\n**Low \u7F6E\u4FE1\u5EA6**\uFF1A\n- \u901A\u7528\u6DF7\u6DC6\u6A21\u5F0F\n- \u53EF\u80FD\u76F8\u5173\u4F46\u4E0D\u786E\u5B9A\u7684\u7ED3\u6784\n\n\u8BF7\u5206\u6790\u63D0\u4F9B\u7684\u4EE3\u7801\uFF0C\u8BC6\u522B JSVMP \u76F8\u5173\u533A\u57DF\u3002\u8FD4\u56DE JSON \u683C\u5F0F\uFF1A\n\n{\n \"summary\": \"\u5206\u6790\u6458\u8981\uFF08\u4E2D\u6587\uFF09\",\n \"regions\": [\n {\n \"start\": \u8D77\u59CB\u884C\u53F7,\n \"end\": \u7ED3\u675F\u884C\u53F7,\n \"type\": \"If-Else Dispatcher\" | \"Switch Dispatcher\" | \"Instruction Array\" | \"Stack Operation\",\n \"confidence\": \"ultra_high\" | \"high\" | \"medium\" | \"low\",\n \"description\": \"\u8BE6\u7EC6\u63CF\u8FF0\uFF08\u4E2D\u6587\uFF09\"\n }\n ]\n}\n\n\u5982\u679C\u6CA1\u6709\u68C0\u6D4B\u5230 JSVMP \u7279\u5F81\uFF0C\u8FD4\u56DE\u7A7A\u7684 regions \u6570\u7EC4\u3002`;\n}\n\n/**\n * \u521B\u5EFA LLM \u5BA2\u6237\u7AEF\u5B9E\u4F8B\n */\nexport function createLLMClient(config: LLMConfig): LLMClient {\n return {\n async analyzeJSVMP(formattedCode: string): Promise<string> {\n const systemPrompt = buildJSVMPSystemPrompt();\n \n const requestBody = {\n model: config.model,\n messages: [\n {\n role: \"system\",\n content: systemPrompt\n },\n {\n role: \"user\",\n content: `\u8BF7\u5206\u6790\u4EE5\u4E0B\u4EE3\u7801\uFF0C\u8BC6\u522B JSVMP \u4FDD\u62A4\u7ED3\u6784\uFF1A\\n\\n${formattedCode}`\n }\n ],\n temperature: 0.1,\n response_format: { type: \"json_object\" }\n };\n \n try {\n const response = await fetch(`${config.baseUrl}/chat/completions`, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n \"Authorization\": `Bearer ${config.apiKey}`\n },\n body: JSON.stringify(requestBody)\n });\n \n if (!response.ok) {\n const errorText = await response.text();\n throw new Error(`API \u8BF7\u6C42\u5931\u8D25 (${response.status}): ${errorText}`);\n }\n \n const data = await response.json();\n \n if (!data.choices || !data.choices[0] || !data.choices[0].message) {\n throw new Error(\"API \u54CD\u5E94\u683C\u5F0F\u65E0\u6548\uFF1A\u7F3A\u5C11 choices \u6216 message \u5B57\u6BB5\");\n }\n \n const content = data.choices[0].message.content;\n \n if (typeof content !== \"string\") {\n throw new Error(\"API \u54CD\u5E94\u683C\u5F0F\u65E0\u6548\uFF1Amessage.content \u4E0D\u662F\u5B57\u7B26\u4E32\");\n }\n \n return content;\n } catch (error) {\n if (error instanceof Error) {\n throw new Error(`LLM \u8BF7\u6C42\u5931\u8D25: ${error.message}`);\n }\n throw new Error(`LLM \u8BF7\u6C42\u5931\u8D25: ${String(error)}`);\n }\n }\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';\nimport { aiFindJsvmpDispatcher } from './aiFindJsvmpDispatcher.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 aiFindJsvmpDispatcher,\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;AAC1B,SAAS,4BAA4B;AACrC,SAAS,KAAAA,UAAS;;;ACFlB,SAAS,SAAS;AAClB,SAAS,yBAAyB;;;ACuB3B,SAAS,WACd,YACyB;AACzB,SAAO;AACT;;;AC5BA,YAAY,aAAa;AACzB,YAAY,YAAY;AACxB,YAAY,QAAQ;AACpB,YAAYC,WAAU;AACtB,YAAY,QAAQ;;;ACJpB,YAAY,UAAU;AA+BtB,IAAM,kBAA2D;AAAA,EAC/D,YAAY;AAAA,IACV,UAAU;AAAA,IACV,aAAa;AAAA,IACb,kBAAkB;AAAA,IAClB,mBAAmB;AAAA,EACrB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3C,QAAM,OAAO,QAAQ,SAAS;AAC9B,UAAQ,MAAM,sCAAsC;AACtD;AAEA,KAAK,EAAE,MAAM,CAAC,UAAU;AACtB,UAAQ,MAAM,gBAAgB,KAAK;AACnC,UAAQ,KAAK,CAAC;AAChB,CAAC;",
6
+ "names": ["z", "path", "code", "result", "z", "path", "fs", "basename", "z", "applyCustomTransform", "z", "SourceMapConsumer", "SourceMapConsumer", "formatSourcePosition", "formatCodeLine", "z", "z", "SourceMapConsumer", "parse", "getOriginalPosition", "getLineContent", "traverse", "path", "formatSourcePosition", "formatCodeLine", "z", "SourceMapConsumer", "z", "formatSourcePosition", "formatCodeLine", "SourceMapConsumer", "z", "applyCustomTransform", "z"]
7
7
  }