UNPKG

@claude-vector/cli

Version:

CLI for Claude-integrated vector search

63 lines (49 loc) 1.99 kB
/** * Index command - Build or rebuild search index using AdvancedVectorEngine */ import chalk from 'chalk'; import { SmartClaude } from './smart-search.js'; export async function indexCommand(options) { console.log(chalk.bold('\n📚 Building Search Index\n')); const smartSearch = new SmartClaude(); try { // Load environment variables (same as smart-search) smartSearch.loadEnvironmentVariables(); // Use SmartClaudeSearch's createIndex method with AdvancedVectorEngine await smartSearch.createIndex(options.force || false, options.resume || false); console.log(chalk.bold('\nNext steps:')); console.log(chalk.gray('1.'), 'Search your code:', chalk.cyan('claude-search search "your query"')); console.log(chalk.gray('2.'), 'Start a task:', chalk.cyan('claude-search start "implement feature"')); // 正常終了 process.exit(0); } catch (error) { console.error(chalk.red(`\n❌ Indexing failed: ${error.message}`)); if (error.stack && process.env.DEBUG) { console.error(chalk.gray(error.stack)); } process.exit(1); } } /** * Show index statistics (for --stats option) */ export async function showIndexStats(files) { console.log(chalk.bold('\n📊 Index Statistics Preview\n')); const extensions = {}; let totalSize = 0; for (const file of files) { const ext = file.path.split('.').pop() || 'no-ext'; extensions[ext] = (extensions[ext] || 0) + 1; totalSize += file.size || 0; } console.log(chalk.gray('Total files:'), files.length); console.log(chalk.gray('Total size:'), `${(totalSize / 1024 / 1024).toFixed(2)} MB`); console.log(chalk.gray('\nFile types:')); const sorted = Object.entries(extensions).sort((a, b) => b[1] - a[1]); for (const [ext, count] of sorted.slice(0, 10)) { console.log(chalk.gray(` .${ext}:`), count); } if (sorted.length > 10) { console.log(chalk.gray(` ... and ${sorted.length - 10} more types`)); } }