UNPKG

@mmlotfy/intellicodemcp

Version:

IntelliCodeMCP - Advanced AI Model Context Protocol System for intelligent code management and orchestration

162 lines 6.1 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.executeCodeTrace = executeCodeTrace; const fs_1 = require("fs"); const path_1 = __importDefault(require("path")); const child_process_1 = require("child_process"); const util_1 = __importDefault(require("util")); const memory_bank_1 = require("./memory-bank"); const fuse_js_1 = __importDefault(require("fuse.js")); async function executeCodeTrace(args) { const { project_path, check_type, fix } = args; const errors = []; const timestamp = new Date().toISOString(); try { // Run TypeScript check if (check_type === 'typescript' || check_type === 'all') { const tsErrors = await runTypeScriptCheck(project_path); errors.push(...tsErrors); } // Run ESLint check if (check_type === 'eslint' || check_type === 'all') { const eslintErrors = await runESLintCheck(project_path, fix); errors.push(...eslintErrors); } // Save error report if (errors.length > 0) { const reportFile = `error_report_${timestamp.replace(/[-:.]/g, '')}.json`; await (0, memory_bank_1.executeMemoryFile)({ action: 'write', category: 'technical', file_name: reportFile, content: JSON.stringify({ errors, timestamp }, null, 2), }); } // Update VS Code Problems tab (simulated for CLI) console.log('Updating VS Code Problems tab:', errors); return { status: 'success', errors, timestamp }; } catch (err) { const errorReport = { errors: [], timestamp, error: err.message, }; await (0, memory_bank_1.executeMemoryFile)({ action: 'write', category: 'technical', file_name: `error_report_${timestamp.replace(/[-:.]/g, '')}.json`, content: JSON.stringify(errorReport, null, 2), }); return { status: 'error', message: err.message }; } } async function runTypeScriptCheck(projectPath) { const execPromise = util_1.default.promisify(child_process_1.exec); const errors = []; try { await execPromise('tsc --noEmit', { cwd: projectPath }); } catch (err) { const lines = err.stdout.split('\n'); for (const line of lines) { const match = line.match(/(.+?)\((\d+),(\d+)\): error TS(\d+): (.+)/); if (match) { errors.push({ file: match[1], line: parseInt(match[2]), column: parseInt(match[3]), code: `TS${match[4]}`, message: match[5], timestamp: new Date().toISOString(), }); } } } return errors; } async function runESLintCheck(projectPath, fix) { const execPromise = util_1.default.promisify(child_process_1.exec); const errors = []; try { const command = fix ? 'eslint --fix . --ext .js,.ts,.jsx,.tsx' : 'eslint . --ext .js,.ts,.jsx,.tsx'; const { stdout } = await execPromise(command, { cwd: projectPath }); const lines = stdout.split('\n'); for (const line of lines) { const match = line.match(/(.+?):(\d+):(\d+): (.+) \[(.+)\]/); if (match) { errors.push({ file: match[1], line: parseInt(match[2]), column: parseInt(match[3]), message: match[4], code: match[5], timestamp: new Date().toISOString(), }); } } } catch (err) { // ESLint errors are in stderr const lines = err.stderr.split('\n'); for (const line of lines) { const match = line.match(/(.+?):(\d+):(\d+): (.+) \[(.+)\]/); if (match) { errors.push({ file: match[1], line: parseInt(match[2]), column: parseInt(match[3]), message: match[4], code: match[5], timestamp: new Date().toISOString(), }); } } } return errors; } async function searchErrors(query) { const basePath = path_1.default.resolve(process.cwd(), 'intelliMemoryHub'); const files = await getFiles(basePath); const documents = await Promise.all(files.map(async (file) => ({ file: path_1.default.relative(process.cwd(), file), content: await fs_1.promises.readFile(file, 'utf8'), }))); const fuse = new fuse_js_1.default(documents, { keys: ['content'], includeScore: true, threshold: 0.3, }); const results = fuse.search(query); const searchResults = results.map((result) => ({ file: result.item.file, content: result.item.content.slice(0, 200) + '...', score: result.score || 0, })); const timestamp = new Date().toISOString().replace(/[-:.]/g, ''); await (0, memory_bank_1.executeMemoryFile)({ action: 'write', category: 'search', file_name: `search_result_${timestamp}.json`, content: JSON.stringify({ query, results: searchResults, timestamp: new Date().toISOString() }, null, 2), }); return searchResults; } async function getFiles(dir) { const entries = await fs_1.promises.readdir(dir, { withFileTypes: true }); const files = []; for (const entry of entries) { const fullPath = path_1.default.join(dir, entry.name); if (entry.isDirectory()) { files.push(...await getFiles(fullPath)); } else if (fullPath.match(/\.(ts|tsx|js|jsx|txt|md|json|yaml)$/)) { files.push(fullPath); } } return files; } //# sourceMappingURL=code-trace.js.map