refactor(indexer): route claude indexing through adapter + persist (Phase 5b-2b)
buildIndex's claude branch now parses via providers/claude.ts and writes via persist.ts instead of the inlined indexJsonl. Behavior is equivalent — the full buildIndex integration suite (runtime.test.mjs) stays green, 116/116 — and a force rebuild of the real ~/.obelisk index (327 sessions, 119k messages) reproduced identical session counts with project_path fully populated. codex, indexSubagentMeta, workflows, history and the project_path pass are untouched. indexJsonl is now unused by buildIndex (kept for its drift test; removed once codex is migrated). Adds tests/incremental-index.test.mjs: verifies resume/accumulate through the full buildIndex path (append new lines to an indexed session → incremental build resumes from the cursor, message_count accumulates, no duplicates). The 30s shouldSkipBuild debounce is cleared in-test so the incremental run fires.
This commit is contained in:
+10
-1
@@ -1,4 +1,6 @@
|
||||
import { CLAUDE_DIR, CODEX_DIR, openDb, rebuildMemoryFts, trunc, truncJson, extractText, extractContentType, extractMessageIsMeta, filePath, isDir, readLines, fs, path } from './db.mjs';
|
||||
import { persist } from './persist.ts';
|
||||
import { parse as claudeParse } from './providers/claude.ts';
|
||||
|
||||
const PROJECTS_DIR = path.join(CLAUDE_DIR, 'projects');
|
||||
const HISTORY_PATH = path.join(CLAUDE_DIR, 'history.jsonl');
|
||||
@@ -782,7 +784,14 @@ function buildIndex({ force = false } = {}) {
|
||||
if (f.source === 'codex') {
|
||||
indexCodexJsonl(db, f);
|
||||
} else {
|
||||
indexJsonl(db, f);
|
||||
// Claude transcripts now go through the pure adapter + shared persist
|
||||
// (docs/adr/0001). needsReindex keeps the "skip unchanged file" fast path;
|
||||
// the cursor's line count drives incremental resume inside parse().
|
||||
const { needed, skip } = needsReindex(db, f.path);
|
||||
if (needed) {
|
||||
const unit = { key: f.path, sessionId: f.sessionId, project: f.project, isSubagent: f.isSubagent, agentId: f.agentId };
|
||||
persist(db, unit, claudeParse(unit, skip > 0 ? `0:${skip}` : null));
|
||||
}
|
||||
indexSubagentMeta(db, f);
|
||||
}
|
||||
db.exec('COMMIT');
|
||||
|
||||
Reference in New Issue
Block a user