Files
DashDescomplicar/api/scripts/sessions-indexer.ts
T

55 lines
1.7 KiB
TypeScript

#!/usr/bin/env tsx
/**
* CLI do indexer de sessões Claude Code (Observabilidade/Espelho).
*
* Modos:
* --full Full scan de ~/.claude/projects -> SQLite em ~/.claude-work/sessions.db
* --watch Modo incremental (stub; implementação Task 8)
*
* Env:
* OBSERVABILIDADE_DB Override ao caminho da BD SQLite
*/
import { indexAll, DEFAULT_DB_PATH } from '../services/sessions/indexer.js'
import { startWatcher } from '../services/sessions/watcher.js'
async function main(): Promise<void> {
const args = process.argv.slice(2)
const mode = args.find((a) => a === '--full' || a === '--watch')
if (!mode) {
console.error('Uso: sessions-indexer.ts [--full|--watch]')
process.exit(1)
}
const dbPath = process.env.OBSERVABILIDADE_DB ?? DEFAULT_DB_PATH
console.log(`[indexer] modo=${mode} db=${dbPath}`)
if (mode === '--watch') {
console.log(`[indexer] watch mode em ${dbPath}`)
await indexAll({ dbPath })
await startWatcher(dbPath)
console.log('[indexer] watcher ainda não implementado (ver Task 8) — saída limpa')
process.exit(0)
}
const start = Date.now()
let lastLogged = 0
const { indexed, failed } = await indexAll({
dbPath,
onProgress: (done, total) => {
if (done - lastLogged >= 50 || done === total) {
console.log(`[indexer] ${done}/${total}`)
lastLogged = done
}
},
})
const durationMs = Date.now() - start
const durationSec = (durationMs / 1000).toFixed(1)
console.log(`[indexer] concluído em ${durationSec}s · indexed=${indexed} failed=${failed}`)
process.exit(failed > 0 ? 1 : 0)
}
main().catch((err) => {
console.error('[indexer] falha fatal:', err)
process.exit(2)
})