@threadbase-sh/scanner 0.14.5 → 0.14.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -3114,8 +3114,18 @@ var IndexQueue = class {
3114
3114
  // src/scanner.ts
3115
3115
  var BATCH_SIZE2 = 12;
3116
3116
  var DEFAULT_CONFIG_PATH = "~/.config/threadbase-scanner";
3117
+ function isTestProcess() {
3118
+ return Boolean(process.env.VITEST) || Boolean(process.env.JEST_WORKER_ID) || process.env.NODE_ENV === "test";
3119
+ }
3117
3120
  function defaultDbPath() {
3118
- return process.env.TB_SCANNER_DB ?? (0, import_path11.join)((0, import_os2.homedir)(), ".config", "threadbase-scanner", "index.db");
3121
+ const override = process.env.TB_SCANNER_DB;
3122
+ if (override) return override;
3123
+ if (isTestProcess()) {
3124
+ throw new Error(
3125
+ "TB_SCANNER_DB must be set under a test runner. Refusing to open the default index at ~/.config/threadbase-scanner/index.db, because test fixtures written there are indistinguishable from real conversations and corrupt every measurement of the index. Point it at a temp directory in your test setup, or pass persistent.dbPath explicitly."
3126
+ );
3127
+ }
3128
+ return (0, import_path11.join)((0, import_os2.homedir)(), ".config", "threadbase-scanner", "index.db");
3119
3129
  }
3120
3130
  function capForMemory(doc, max) {
3121
3131
  const combined = combineSearchContent(doc);
@@ -3512,7 +3522,8 @@ var ConversationScanner = class {
3512
3522
  // feeds the conversation's account field; "default" is the single-profile
3513
3523
  // fallback, matching refreshFile.
3514
3524
  async parseSingleFilePage(filePath, account, options) {
3515
- const conversation = await parseConversation(filePath, account ?? "default");
3525
+ const provider = await this.resolveProviderForFile(filePath, null);
3526
+ const conversation = provider?.name === CODEX_CLI_PROVIDER ? await parseCodexConversation(filePath, account ?? "default") : await parseConversation(filePath, account ?? "default");
3516
3527
  if (!conversation) return null;
3517
3528
  const { messages } = conversation;
3518
3529
  const total = messages.length;
@@ -3556,7 +3567,7 @@ var ConversationScanner = class {
3556
3567
  const engine = this.engine();
3557
3568
  const previous2 = engine.getByIdOrSession(filePath);
3558
3569
  const resolvedAccount2 = account ?? previous2?.account ?? "default";
3559
- const provider = await this.resolveProviderForFile(filePath, previous2);
3570
+ const provider2 = await this.resolveProviderForFile(filePath, previous2);
3560
3571
  const { meta: meta2, change } = await engine.indexFile(
3561
3572
  filePath,
3562
3573
  resolvedAccount2,
@@ -3564,7 +3575,7 @@ var ConversationScanner = class {
3564
3575
  void 0,
3565
3576
  readGitBranch,
3566
3577
  false,
3567
- provider
3578
+ provider2
3568
3579
  );
3569
3580
  const cacheKeys = /* @__PURE__ */ new Set();
3570
3581
  for (const m of [previous2, meta2]) {
@@ -3585,10 +3596,12 @@ var ConversationScanner = class {
3585
3596
  const resolvedAccount = account ?? previous?.account ?? "default";
3586
3597
  let meta = null;
3587
3598
  let searchDoc = emptySearchDocument();
3599
+ const onEntry = (entry) => {
3600
+ searchDoc = appendSearchDelta(searchDoc, extractSearchDelta(entry));
3601
+ };
3602
+ const provider = await this.resolveProviderForFile(filePath, previous ?? null);
3588
3603
  try {
3589
- meta = await parseMeta(filePath, resolvedAccount, this.lastTier, (entry) => {
3590
- searchDoc = appendSearchDelta(searchDoc, extractSearchDelta(entry));
3591
- });
3604
+ meta = provider ? await parseMetaWithProvider(provider, filePath, resolvedAccount, this.lastTier, onEntry) : await parseMeta(filePath, resolvedAccount, this.lastTier, onEntry);
3592
3605
  } catch (err) {
3593
3606
  log.warn({ filePath, err }, "refreshFile: parseMeta threw");
3594
3607
  meta = null;