UNPKG

ctrlshiftleft

Version:

AI-powered toolkit for embedding QA and security testing into development workflows

63 lines 2.46 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.semanticSearchCommand = void 0; exports.semantic_search = semantic_search; const openaiAgent_1 = require("../core/openaiAgent"); const path_1 = __importDefault(require("path")); const fs_1 = __importDefault(require("fs")); const glob_1 = require("glob"); /** * Perform a semantic code search * @param query Search query * @param files Optional array of file paths to search within * @returns Search results with file paths and relevance scores */ async function semantic_search({ query, files = [] }) { const openaiAgent = new openaiAgent_1.OpenAIAgent(); // If no files specified, get all TypeScript/JavaScript files in src directory if (!files || files.length === 0) { const srcPath = path_1.default.resolve(process.cwd(), 'src'); if (fs_1.default.existsSync(srcPath)) { files = (0, glob_1.globSync)(path_1.default.join(srcPath, '**/*.{ts,tsx,js,jsx}'), { ignore: ['**/node_modules/**', '**/*.test.{ts,tsx,js,jsx}', '**/*.spec.{ts,tsx,js,jsx}'] }); } } // Read content of each file const filesContent = files.map(filePath => { try { const content = fs_1.default.readFileSync(filePath, 'utf8'); return { filePath, content }; } catch (error) { console.error(`Error reading file ${filePath}:`, error); return null; } }).filter((file) => file !== null); try { const results = await openaiAgent.performSemanticSearch(query, filesContent); return results; } catch (error) { console.error('Error performing semantic search:', error); return []; } } /** * Register the semantic-search command */ const semanticSearchCommand = (program) => { program .command('semantic-search <query>') .description('Perform a semantic code search') .option('-f, --files <files...>', 'Specific files to search within') .action(async (query, options) => { const results = await semantic_search({ query, files: options.files }); console.log(JSON.stringify(results, null, 2)); }); }; exports.semanticSearchCommand = semanticSearchCommand; //# sourceMappingURL=semanticSearch.js.map