/** * brainbank reindex [path] — Nuke data and re-index from scratch. * * Deletes the .brainbank/data/ directory (SQLite DB + HNSW index) * then runs a headless `index --yes` to rebuild everything. */ import * as fs from 'node:fs'; import * as path from 'node:path'; import { c, args, stripFlags } from '@/cli/utils.ts'; import { cmdIndex } from './index.ts'; export async function cmdReindex(): Promise { const positional = stripFlags(args); const repoPath = path.resolve(positional[1] || '.'); const dataDir = path.join(repoPath, '.brainbank', 'data'); if (fs.existsSync(dataDir)) { const entries = fs.readdirSync(dataDir); console.log(c.bold('\n━━━ Reindex ━━━\n')); console.log(` ${c.yellow('✗')} Deleting ${path.relative(process.cwd(), dataDir)}/ (${entries.length} files)`); fs.rmSync(dataDir, { recursive: true, force: true }); console.log(` ${c.green('✓')} Data cleared\n`); } else { console.log(c.bold('\n━━━ Reindex ━━━\n')); console.log(c.dim(' No existing data — fresh index\n')); } // Inject --yes into args so index runs headless (no TUI) if (!args.includes('--yes') && !args.includes('-y')) { args.push('--yes'); } // Force re-index all files if (!args.includes('--force')) { args.push('--force'); } return cmdIndex(); }