feat(observabilidade): indexer full scan + CLI + stub watcher
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
#!/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') {
|
||||
startWatcher()
|
||||
return
|
||||
}
|
||||
|
||||
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}`)
|
||||
}
|
||||
|
||||
main().catch((err) => {
|
||||
console.error('[indexer] falha fatal:', err)
|
||||
process.exit(2)
|
||||
})
|
||||
Reference in New Issue
Block a user