UNPKG

codevault

Version:

AI-powered semantic code search via Model Context Protocol

139 lines • 5.27 kB
import cliProgress from 'cli-progress'; import ora from 'ora'; import chalk from 'chalk'; export class IndexerUI { progressBar = null; spinner = null; startTime = 0; totalFiles = 0; processedFiles = 0; stats = { chunks: 0, merged: 0, subdivided: 0, skipped: 0 }; showHeader() { console.log(chalk.cyan.bold('\nšŸ” CodeVault Indexer')); } showConfiguration(config) { console.log(chalk.white('\nšŸ“Š Configuration')); console.log(chalk.gray(` Provider: ${config.provider}${config.model ? ` (${config.model})` : ''}`)); console.log(chalk.gray(` Dimensions: ${config.dimensions}`)); console.log(chalk.gray(` Chunk size: ${Math.floor(config.chunkSize.min / 1000)}K-${Math.floor(config.chunkSize.max / 1000)}K tokens (optimal: ${Math.floor(config.chunkSize.optimal / 1000)}K)`)); if (config.rateLimit) { console.log(chalk.gray(` Rate limit: ${config.rateLimit.rpm.toLocaleString()} req/min`)); } } startScanning() { this.spinner = ora({ text: chalk.white('Scanning project...'), color: 'cyan' }).start(); } finishScanning(fileCount, languages) { if (this.spinner) { this.spinner.succeed(chalk.white(`Found ${chalk.cyan(fileCount)} files across ${chalk.cyan(languages)}+ languages`)); this.spinner = null; } this.totalFiles = fileCount; } startIndexing() { this.startTime = Date.now(); this.processedFiles = 0; console.log(chalk.white('\n⚔ Indexing files')); if (this.totalFiles > 0) { this.progressBar = new cliProgress.SingleBar({ format: chalk.cyan(' [{bar}]') + ' {percentage}% | {value}/{total} files | ETA {eta_formatted}', barCompleteChar: 'ā–ˆ', barIncompleteChar: 'ā–‘', hideCursor: true, clearOnComplete: false, stopOnComplete: true }); this.progressBar.start(this.totalFiles, 0); } } updateProgress(fileName) { this.processedFiles++; if (this.progressBar) { this.progressBar.update(this.processedFiles); } } updateStats(stats) { if (stats.chunks !== undefined) this.stats.chunks = stats.chunks; if (stats.merged !== undefined) this.stats.merged = stats.merged; if (stats.subdivided !== undefined) this.stats.subdivided = stats.subdivided; if (stats.skipped !== undefined) this.stats.skipped = stats.skipped; } showFinalizing() { if (this.progressBar) { this.progressBar.stop(); this.progressBar = null; } this.spinner = ora({ text: chalk.white('Finalizing embeddings and building indexes...'), color: 'cyan' }).start(); } finishIndexing() { if (this.spinner) { this.spinner.stop(); this.spinner = null; } if (this.progressBar) { this.progressBar.stop(); this.progressBar = null; } if (this.startTime > 0) { const duration = Date.now() - this.startTime; const minutes = Math.floor(duration / 60000); const seconds = Math.floor((duration % 60000) / 1000); const timeStr = minutes > 0 ? `${minutes}m ${seconds}s` : `${seconds}s`; console.log(chalk.green(`\nāœ… Indexing complete in ${timeStr}!`)); } else { console.log(chalk.green(`\nāœ… Indexing complete!`)); } } showSummary(summary) { console.log(chalk.white('\nšŸ“Š Summary')); console.log(chalk.gray(` Total chunks: ${chalk.white(summary.totalChunks)}`)); if (this.stats.merged > 0) { console.log(chalk.gray(` Merged small: ${chalk.white(this.stats.merged)}`)); } if (this.stats.subdivided > 0) { console.log(chalk.gray(` Subdivided large: ${chalk.white(this.stats.subdivided)}`)); } if (this.stats.skipped > 0) { console.log(chalk.gray(` Skipped (small): ${chalk.white(this.stats.skipped)}`)); } if (summary.dbSize) { console.log(chalk.gray(` Database: ${chalk.white(summary.dbSize)}`)); } if (summary.codemapSize) { console.log(chalk.gray(` Codemap: ${chalk.white(summary.codemapSize)}`)); } console.log(chalk.cyan('\nšŸš€ Ready to search!')); console.log(chalk.gray(` Quick search: ${chalk.white('codevault search "your query"')}`)); console.log(chalk.gray(` With code: ${chalk.white('codevault search-with-code "your query"')}\n`)); } showError(message) { console.error(chalk.red(`\nāŒ Error: ${message}\n`)); } cleanup() { if (this.spinner) { this.spinner.stop(); this.spinner = null; } if (this.progressBar) { this.progressBar.stop(); this.progressBar = null; } } } //# sourceMappingURL=cli-ui.js.map