@threadbase-sh/scanner 0.21.1 → 0.22.0

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.
Files changed (39) hide show
  1. package/README.md +3 -1
  2. package/dist/cli.js +494 -130
  3. package/dist/cli.js.map +1 -1
  4. package/dist/index.cjs +577 -154
  5. package/dist/index.cjs.map +1 -1
  6. package/dist/index.d.ts +3 -0
  7. package/dist/index.d.ts.map +1 -1
  8. package/dist/index.js +549 -135
  9. package/dist/index.js.map +1 -1
  10. package/dist/name-stores.d.ts +13 -0
  11. package/dist/name-stores.d.ts.map +1 -0
  12. package/dist/parser.d.ts.map +1 -1
  13. package/dist/persistent/claude-name-slots.d.ts +3 -0
  14. package/dist/persistent/claude-name-slots.d.ts.map +1 -0
  15. package/dist/persistent/conversation-reducer.d.ts +2 -1
  16. package/dist/persistent/conversation-reducer.d.ts.map +1 -1
  17. package/dist/persistent/conversation-stream.d.ts.map +1 -1
  18. package/dist/persistent/index-engine.d.ts.map +1 -1
  19. package/dist/persistent/metadata-reducer.d.ts +2 -4
  20. package/dist/persistent/metadata-reducer.d.ts.map +1 -1
  21. package/dist/persistent/migrations.d.ts.map +1 -1
  22. package/dist/persistent/repositories/conversations.repo.d.ts +2 -1
  23. package/dist/persistent/repositories/conversations.repo.d.ts.map +1 -1
  24. package/dist/persistent/schema.d.ts +2 -2
  25. package/dist/persistent/schema.d.ts.map +1 -1
  26. package/dist/providers/codex-cli.d.ts +3 -6
  27. package/dist/providers/codex-cli.d.ts.map +1 -1
  28. package/dist/providers/copilot.d.ts +2 -0
  29. package/dist/providers/copilot.d.ts.map +1 -1
  30. package/dist/providers/cursor.d.ts +2 -0
  31. package/dist/providers/cursor.d.ts.map +1 -1
  32. package/dist/providers/parse.d.ts +1 -1
  33. package/dist/providers/parse.d.ts.map +1 -1
  34. package/dist/scanner.d.ts.map +1 -1
  35. package/dist/session-name.d.ts +24 -0
  36. package/dist/session-name.d.ts.map +1 -0
  37. package/dist/types.d.ts +1 -0
  38. package/dist/types.d.ts.map +1 -1
  39. package/package.json +1 -1
package/dist/index.cjs CHANGED
@@ -40,11 +40,13 @@ __export(index_exports, {
40
40
  CursorProvider: () => CursorProvider,
41
41
  DEFAULT_TIERS: () => DEFAULT_TIERS,
42
42
  LEGACY_CURSOR_PROVIDER: () => LEGACY_CURSOR_PROVIDER,
43
+ NAME_PRECEDENCE: () => NAME_PRECEDENCE,
43
44
  SearchIndexer: () => SearchIndexer,
44
45
  ThreadbaseProvider: () => ThreadbaseProvider,
45
46
  VALID_SORT_ORDERS: () => VALID_SORT_ORDERS,
46
47
  applyAccountFilter: () => applyAccountFilter,
47
48
  applyIncludeFilter: () => applyIncludeFilter,
49
+ applyNameCandidate: () => applyNameCandidate,
48
50
  applyPagination: () => applyPagination,
49
51
  applyProjectFilter: () => applyProjectFilter,
50
52
  applySinceFilter: () => applySinceFilter,
@@ -59,20 +61,27 @@ __export(index_exports, {
59
61
  getLogger: () => getLogger,
60
62
  getProjectsDir: () => getProjectsDir,
61
63
  isCodexInjectedContext: () => isCodexInjectedContext,
64
+ isValidNameCandidate: () => isValidNameCandidate,
62
65
  loadProfiles: () => loadProfiles,
63
66
  parseCodexJsonlLine: () => parseCodexJsonlLine,
64
67
  parseCopilotJsonlLine: () => parseCopilotJsonlLine,
65
68
  parseCursorJsonlLine: () => parseCursorJsonlLine,
66
69
  parseJsonlLine: () => parseJsonlLine,
67
70
  providerMatches: () => providerMatches,
71
+ readCodexNameSlots: () => readCodexNameSlots,
72
+ readCopilotNameSlots: () => readCopilotNameSlots,
73
+ readCursorCliNameSlots: () => readCursorCliNameSlots,
74
+ readCursorIdeNameSlots: () => readCursorIdeNameSlots,
68
75
  readGitBranch: () => readGitBranch,
69
76
  readSidecar: () => readSidecar,
70
77
  resetDefaultScanner: () => resetDefaultScanner,
71
78
  resolveConfigDir: () => resolveConfigDir,
79
+ resolveSessionName: () => resolveSessionName,
72
80
  resolveTier: () => resolveTier,
73
81
  saveProfiles: () => saveProfiles,
74
82
  scan: () => scan,
75
83
  search: () => search,
84
+ setCursorStateDb: () => setCursorStateDb,
76
85
  setLogger: () => setLogger,
77
86
  sidecarPath: () => sidecarPath,
78
87
  unwrapCursorUserText: () => unwrapCursorUserText
@@ -431,13 +440,329 @@ function toIndexDoc(meta, searchContent) {
431
440
  };
432
441
  }
433
442
 
434
- // src/parser.ts
443
+ // src/name-stores.ts
444
+ var import_better_sqlite3 = __toESM(require("better-sqlite3"), 1);
435
445
  var import_fs2 = require("fs");
436
- var import_path3 = require("path");
446
+ var import_path2 = require("path");
447
+
448
+ // src/tags.ts
449
+ var SYSTEM_TAGS = [
450
+ "system-reminder",
451
+ "command-name",
452
+ "command-message",
453
+ "command-args",
454
+ "ide_selection",
455
+ "ide_opened_file",
456
+ "local-command-stdout",
457
+ "local-command-caveat",
458
+ "retrieval_status",
459
+ "task_id",
460
+ "task_type",
461
+ "task-id",
462
+ "task-notification",
463
+ "fast_mode_info",
464
+ "persisted-output",
465
+ "tool_use_error",
466
+ "user-prompt-submit-hook",
467
+ "thinking",
468
+ "ask_user",
469
+ "teammate-message"
470
+ ];
471
+ var SYSTEM_TAG_RE = new RegExp(`<(${SYSTEM_TAGS.join("|")})[^>]*>[\\s\\S]*?<\\/\\1>`, "g");
472
+ var PASTED_CONTENT_RE = /<pasted_content id="[0-9a-f]{4}">([\s\S]*?)<\/pasted_content(?: id="[0-9a-f]{4}")?>/g;
473
+ function cleanSystemTags(text) {
474
+ return text.replace(SYSTEM_TAG_RE, "").replace(PASTED_CONTENT_RE, "$1").replace(/[^\S\n]+/g, " ").replace(/\n{3,}/g, "\n\n").trim();
475
+ }
476
+
477
+ // src/session-name.ts
478
+ var NAME_PRECEDENCE = [
479
+ "userTitle",
480
+ "toolTitle",
481
+ "lastPrompt",
482
+ "firstUserMessage",
483
+ "slug"
484
+ ];
485
+ var CLAUDE_SYSTEM_PREFIXES = [
486
+ "<command-name>",
487
+ "<command-message>",
488
+ "<command-args>",
489
+ "<local-command-stdout>",
490
+ "<local-command-stderr>",
491
+ "<local-command-caveat>",
492
+ "<bash-input>",
493
+ "<bash-stdout>",
494
+ "<bash-stderr>",
495
+ "<system-reminder>",
496
+ "<task-notification>",
497
+ "<teammate-message",
498
+ "Another Claude session sent a message:",
499
+ "[Request interrupted by user"
500
+ ];
501
+ var CODEX_SYSTEM_PREFIXES = [
502
+ "<environment_context>",
503
+ "# AGENTS.md instructions",
504
+ "<user_instructions>",
505
+ "<INSTRUCTIONS>",
506
+ "<external_codex_apps_open",
507
+ "<user_shell_command>",
508
+ "<turn_aborted>"
509
+ ];
510
+ function isCodexInjectedContext(text) {
511
+ if (text.startsWith("# AGENTS.md") || text.includes("<INSTRUCTIONS>")) return true;
512
+ return text.startsWith("<permissions instructions>") || text.includes("Filesystem sandboxing defines");
513
+ }
514
+ var CODEX_IMAGE_TAG_RE = /<\/?image\b[^>]*>/g;
515
+ function normalizeCandidate(text, provider) {
516
+ let t = text.trim();
517
+ if (provider === "codex-cli") t = t.replace(CODEX_IMAGE_TAG_RE, "").trim();
518
+ const prefixes = provider === "claude-code" ? CLAUDE_SYSTEM_PREFIXES : provider === "codex-cli" ? CODEX_SYSTEM_PREFIXES : [];
519
+ if (prefixes.some((p) => t.startsWith(p))) return null;
520
+ if (provider === "codex-cli" && isCodexInjectedContext(t)) return null;
521
+ return cleanSystemTags(t) || null;
522
+ }
523
+ function isValidNameCandidate(text, provider) {
524
+ return normalizeCandidate(text, provider) !== null;
525
+ }
526
+ function resolveSessionName(slots) {
527
+ for (const slot of NAME_PRECEDENCE) {
528
+ const value = slots[slot];
529
+ if (value?.trim()) return { name: value, source: slot };
530
+ }
531
+ return { name: null, source: null };
532
+ }
533
+ function applyNameCandidate(slots, slot, raw, provider) {
534
+ if (typeof raw !== "string") return slots;
535
+ if (slot === "firstUserMessage" && slots.firstUserMessage !== void 0) return slots;
536
+ const text = normalizeCandidate(raw, provider);
537
+ return text === null ? slots : { ...slots, [slot]: text };
538
+ }
539
+
540
+ // src/name-stores.ts
541
+ function slotsFrom(provider, candidates) {
542
+ return candidates.reduce(
543
+ (slots, [slot, raw]) => applyNameCandidate(slots, slot, typeof raw === "string" ? raw : void 0, provider),
544
+ {}
545
+ );
546
+ }
547
+ function readJson(path) {
548
+ try {
549
+ return JSON.parse((0, import_fs2.readFileSync)(path, "utf8"));
550
+ } catch {
551
+ return void 0;
552
+ }
553
+ }
554
+ function queryOne(dbPath, sql, ...params) {
555
+ let db;
556
+ try {
557
+ db = new import_better_sqlite3.default(dbPath, { readonly: true, fileMustExist: true, timeout: 250 });
558
+ return db.prepare(sql).get(...params);
559
+ } catch (err) {
560
+ getLogger().debug({ dbPath, err }, "name store: query failed");
561
+ return void 0;
562
+ } finally {
563
+ db?.close();
564
+ }
565
+ }
566
+ var lastByIdCache = /* @__PURE__ */ new Map();
567
+ function lastValueById(path, idField, valueField) {
568
+ let sig;
569
+ try {
570
+ const s = (0, import_fs2.statSync)(path);
571
+ sig = `${s.mtimeMs}:${s.size}`;
572
+ } catch {
573
+ return /* @__PURE__ */ new Map();
574
+ }
575
+ const key = `${path}\0${idField}\0${valueField}`;
576
+ const cached = lastByIdCache.get(key);
577
+ if (cached?.sig === sig) return cached.map;
578
+ const map = /* @__PURE__ */ new Map();
579
+ try {
580
+ for (const line of (0, import_fs2.readFileSync)(path, "utf8").split("\n")) {
581
+ if (!line.trim()) continue;
582
+ try {
583
+ const row = JSON.parse(line);
584
+ const id = row[idField];
585
+ const value = row[valueField];
586
+ if (typeof id === "string" && typeof value === "string") map.set(id, value);
587
+ } catch {
588
+ }
589
+ }
590
+ } catch {
591
+ }
592
+ lastByIdCache.set(key, { sig, map });
593
+ return map;
594
+ }
595
+ function readCodexNameSlots(codexHome, id) {
596
+ const index = lastValueById((0, import_path2.join)(codexHome, "session_index.jsonl"), "id", "thread_name");
597
+ const history = lastValueById((0, import_path2.join)(codexHome, "history.jsonl"), "session_id", "text");
598
+ let title = index.get(id);
599
+ if (!index.has(id)) {
600
+ title = queryOne(
601
+ (0, import_path2.join)(codexHome, "state_5.sqlite"),
602
+ "SELECT name FROM threads WHERE id = ?",
603
+ id
604
+ )?.name;
605
+ }
606
+ return slotsFrom("codex-cli", [
607
+ ["toolTitle", title],
608
+ ["lastPrompt", history.get(id)]
609
+ ]);
610
+ }
611
+ function readCursorCliNameSlots(chatsDir, id) {
612
+ let chat;
613
+ try {
614
+ chat = (0, import_fs2.readdirSync)(chatsDir).map((hash) => (0, import_path2.join)(chatsDir, hash, id)).find((p) => (0, import_fs2.existsSync)(p));
615
+ } catch {
616
+ }
617
+ if (!chat) return {};
618
+ const meta = readJson((0, import_path2.join)(chat, "meta.json"));
619
+ const history = readJson((0, import_path2.join)(chat, "prompt_history.json"));
620
+ let title = meta?.title;
621
+ if (typeof title !== "string" || !title.trim()) title = storeDbName((0, import_path2.join)(chat, "store.db"));
622
+ return slotsFrom("cursor", [
623
+ ["toolTitle", title],
624
+ ["lastPrompt", Array.isArray(history) ? history[0] : void 0]
625
+ ]);
626
+ }
627
+ function storeDbName(dbPath) {
628
+ const row = queryOne(
629
+ dbPath,
630
+ "SELECT value FROM meta WHERE key = '0'"
631
+ );
632
+ if (!row) return void 0;
633
+ try {
634
+ const text = row.value.toString();
635
+ const json = /^(?:[0-9a-f]{2})+$/i.test(text) ? Buffer.from(text, "hex").toString("utf8") : text;
636
+ const name = JSON.parse(json).name;
637
+ return typeof name === "string" ? name : void 0;
638
+ } catch {
639
+ return void 0;
640
+ }
641
+ }
642
+ function readCursorIdeNameSlots(stateDbPath, id) {
643
+ const row = queryOne(
644
+ stateDbPath,
645
+ "SELECT json_extract(CAST(value AS TEXT), '$.name') AS name FROM cursorDiskKV WHERE key = ?",
646
+ `composerData:${id}`
647
+ );
648
+ return slotsFrom("cursor", [["toolTitle", row?.name]]);
649
+ }
650
+ function yamlScalar(text, key) {
651
+ const m = text.match(new RegExp(`^${key}:[ \\t]*(.*)$`, "m"));
652
+ const v = m?.[1].trim().replace(/^(["'])(.*)\1$/, "$2");
653
+ return v || void 0;
654
+ }
655
+ function readCopilotTitleSlots(sessionDir) {
656
+ const id = (0, import_path2.basename)(sessionDir);
657
+ let yaml = "";
658
+ try {
659
+ yaml = (0, import_fs2.readFileSync)((0, import_path2.join)(sessionDir, "workspace.yaml"), "utf8");
660
+ } catch {
661
+ }
662
+ const name = yamlScalar(yaml, "name");
663
+ if (name) {
664
+ return slotsFrom("copilot", [
665
+ [yamlScalar(yaml, "user_named") === "true" ? "userTitle" : "toolTitle", name]
666
+ ]);
667
+ }
668
+ const row = queryOne(
669
+ (0, import_path2.join)((0, import_path2.dirname)((0, import_path2.dirname)(sessionDir)), "session-store.db"),
670
+ "SELECT summary FROM sessions WHERE id = ?",
671
+ id
672
+ );
673
+ return slotsFrom("copilot", [["toolTitle", row?.summary]]);
674
+ }
675
+ function readCopilotNameSlots(sessionDir) {
676
+ return {
677
+ ...readCopilotTitleSlots(sessionDir),
678
+ ...slotsFrom("copilot", [
679
+ ["firstUserMessage", firstCopilotUserMessage((0, import_path2.join)(sessionDir, "events.jsonl"))]
680
+ ])
681
+ };
682
+ }
683
+ function firstCopilotUserMessage(path) {
684
+ let fd;
685
+ try {
686
+ fd = (0, import_fs2.openSync)(path, "r");
687
+ } catch {
688
+ return void 0;
689
+ }
690
+ try {
691
+ const buf = Buffer.alloc(64 * 1024);
692
+ let pending = "";
693
+ for (let n = (0, import_fs2.readSync)(fd, buf, 0, buf.length, null); n > 0; n = (0, import_fs2.readSync)(fd, buf, 0, buf.length, null)) {
694
+ pending += buf.toString("utf8", 0, n);
695
+ const lines = pending.split("\n");
696
+ pending = lines.pop() ?? "";
697
+ for (const line of lines) {
698
+ try {
699
+ const e = JSON.parse(line);
700
+ if (e.type === "user.message" && typeof e.data?.content === "string")
701
+ return e.data.content;
702
+ } catch {
703
+ }
704
+ }
705
+ }
706
+ return void 0;
707
+ } catch {
708
+ return void 0;
709
+ } finally {
710
+ (0, import_fs2.closeSync)(fd);
711
+ }
712
+ }
713
+ function findUp(start, hasStore, levels) {
714
+ let dir = start;
715
+ for (let i = 0; i < levels; i++) {
716
+ if (hasStore(dir)) return dir;
717
+ const parent = (0, import_path2.dirname)(dir);
718
+ if (parent === dir) break;
719
+ dir = parent;
720
+ }
721
+ return null;
722
+ }
723
+ function codexNameSlotsFor(rolloutPath, id) {
724
+ const home = findUp(
725
+ (0, import_path2.dirname)(rolloutPath),
726
+ (d) => ["session_index.jsonl", "history.jsonl", "state_5.sqlite"].some(
727
+ (f) => (0, import_fs2.existsSync)((0, import_path2.join)(d, f))
728
+ ),
729
+ 6
730
+ );
731
+ return home ? readCodexNameSlots(home, id) : {};
732
+ }
733
+ var cursorStateDb;
734
+ function setCursorStateDb(path) {
735
+ cursorStateDb = path;
736
+ }
737
+ function cursorNameSlotsFor(transcriptPath, id) {
738
+ const home = findUp((0, import_path2.dirname)(transcriptPath), (d) => (0, import_fs2.existsSync)((0, import_path2.join)(d, "chats")), 6);
739
+ const cli = home ? readCursorCliNameSlots((0, import_path2.join)(home, "chats"), id) : {};
740
+ if (cli.toolTitle || !cursorStateDb) return cli;
741
+ return { ...cli, ...readCursorIdeNameSlots(cursorStateDb, id) };
742
+ }
743
+ function copilotNameSlotsFor(eventsPath) {
744
+ return readCopilotTitleSlots((0, import_path2.dirname)(eventsPath));
745
+ }
746
+ function nameStoreSlotsFor(provider, filePath, sessionId) {
747
+ switch (provider) {
748
+ case "codex-cli":
749
+ return codexNameSlotsFor(filePath, sessionId);
750
+ case "cursor":
751
+ return cursorNameSlotsFor(filePath, (0, import_path2.basename)(filePath, ".jsonl"));
752
+ case "copilot":
753
+ return copilotNameSlotsFor(filePath);
754
+ default:
755
+ return {};
756
+ }
757
+ }
758
+
759
+ // src/parser.ts
760
+ var import_fs3 = require("fs");
761
+ var import_path4 = require("path");
437
762
  var import_readline = require("readline");
438
763
 
439
764
  // src/persistent/metadata-reducer.ts
440
- var import_path2 = require("path");
765
+ var import_path3 = require("path");
441
766
 
442
767
  // src/providers/provider.ts
443
768
  var CLAUDE_CODE_PROVIDER = "claude-code";
@@ -467,11 +792,36 @@ function providerMatches(stored, wanted) {
467
792
  return a === b;
468
793
  }
469
794
 
795
+ // src/persistent/claude-name-slots.ts
796
+ function userPromptText(entry) {
797
+ if (entry.isMeta || entry.isCompactSummary === true) return "";
798
+ const content = entry.message?.content;
799
+ if (typeof content === "string") return content;
800
+ if (!Array.isArray(content)) return "";
801
+ return content.map((b) => typeof b === "string" ? b : b?.type === "text" ? b.text : "").filter((t) => typeof t === "string" && t !== "").join(" ");
802
+ }
803
+ function applyClaudeNameEntry(slots, entry) {
804
+ const apply = (slot, raw) => applyNameCandidate(slots, slot, typeof raw === "string" ? raw : void 0, "claude-code");
805
+ if (entry.slug !== slots.slug) slots = apply("slug", entry.slug);
806
+ switch (entry.type) {
807
+ case "custom-title":
808
+ return apply("userTitle", entry.customTitle);
809
+ case "ai-title":
810
+ return apply("toolTitle", entry.aiTitle);
811
+ case "last-prompt":
812
+ return apply("lastPrompt", entry.lastPrompt);
813
+ case "user":
814
+ return slots.firstUserMessage === void 0 ? apply("firstUserMessage", userPromptText(entry)) : slots;
815
+ default:
816
+ return slots;
817
+ }
818
+ }
819
+
470
820
  // src/persistent/metadata-reducer.ts
471
821
  function initialReducerState() {
472
822
  return {
473
823
  sessionId: "",
474
- sessionName: "",
824
+ nameSlots: {},
475
825
  latestTimestamp: "",
476
826
  cwd: "",
477
827
  teamName: "",
@@ -497,7 +847,7 @@ function initialReducerState() {
497
847
  function reduceLine(state, entry, tier) {
498
848
  if (entry.cwd && !state.cwd) state.cwd = entry.cwd;
499
849
  if (entry.sessionId && !state.sessionId) state.sessionId = entry.sessionId;
500
- if (entry.slug && !state.sessionName) state.sessionName = entry.slug;
850
+ state.nameSlots = applyClaudeNameEntry(state.nameSlots, entry);
501
851
  if (entry.teamName && !state.teamName) state.teamName = entry.teamName;
502
852
  if (entry.agentId && !state.agentId) state.agentId = entry.agentId;
503
853
  if (entry.isSidechain === true) state.isSidechain = true;
@@ -561,16 +911,16 @@ function finalizeMeta(state, filePath, account, tier) {
561
911
  const isSubagent = isSidechain || isSubagentPath;
562
912
  let parentSessionId = null;
563
913
  if (isSubagentPath) {
564
- const uuidDir = (0, import_path2.dirname)((0, import_path2.dirname)(filePath));
565
- parentSessionId = (0, import_path2.join)((0, import_path2.dirname)(uuidDir), `${(0, import_path2.basename)(uuidDir)}.jsonl`);
914
+ const uuidDir = (0, import_path3.dirname)((0, import_path3.dirname)(filePath));
915
+ parentSessionId = (0, import_path3.join)((0, import_path3.dirname)(uuidDir), `${(0, import_path3.basename)(uuidDir)}.jsonl`);
566
916
  }
567
917
  const projectPath = state.cwd;
568
918
  return {
569
919
  id: filePath,
570
920
  filePath,
571
921
  provider: CLAUDE_CODE_PROVIDER,
572
- sessionId: state.sessionId || (0, import_path2.basename)(filePath, ".jsonl"),
573
- sessionName: state.sessionName || deriveSessionNameFromFirstMessage(state.firstMessage),
922
+ sessionId: state.sessionId || (0, import_path3.basename)(filePath, ".jsonl"),
923
+ sessionName: resolveSessionName(state.nameSlots).name ?? "",
574
924
  projectPath,
575
925
  projectName: getShortProjectName(projectPath),
576
926
  account,
@@ -596,50 +946,17 @@ function finalizeMeta(state, filePath, account, tier) {
596
946
  };
597
947
  }
598
948
  var SUBAGENT_PATH_RE = /[\\/]subagents[\\/]/;
599
- function deriveSessionNameFromFirstMessage(firstMessage) {
600
- const firstLine = firstMessage?.text.split("\n", 1)[0]?.trim() ?? "";
601
- return firstLine.slice(0, 80);
602
- }
603
949
  function getShortProjectName(fullPath) {
604
950
  const parts = fullPath.split("/").filter(Boolean);
605
951
  return parts.slice(-3).join("/");
606
952
  }
607
953
 
608
- // src/tags.ts
609
- var SYSTEM_TAGS = [
610
- "system-reminder",
611
- "command-name",
612
- "command-message",
613
- "command-args",
614
- "ide_selection",
615
- "ide_opened_file",
616
- "local-command-stdout",
617
- "local-command-caveat",
618
- "retrieval_status",
619
- "task_id",
620
- "task_type",
621
- "task-id",
622
- "task-notification",
623
- "fast_mode_info",
624
- "persisted-output",
625
- "tool_use_error",
626
- "user-prompt-submit-hook",
627
- "thinking",
628
- "ask_user",
629
- "teammate-message"
630
- ];
631
- var SYSTEM_TAG_RE = new RegExp(`<(${SYSTEM_TAGS.join("|")})[^>]*>[\\s\\S]*?<\\/\\1>`, "g");
632
- var PASTED_CONTENT_RE = /<pasted_content id="[0-9a-f]{4}">([\s\S]*?)<\/pasted_content(?: id="[0-9a-f]{4}")?>/g;
633
- function cleanSystemTags(text) {
634
- return text.replace(SYSTEM_TAG_RE, "").replace(PASTED_CONTENT_RE, "$1").replace(/[^\S\n]+/g, " ").replace(/\n{3,}/g, "\n\n").trim();
635
- }
636
-
637
954
  // src/parser.ts
638
955
  async function parseMeta(filePath, account, tier, onEntry) {
639
956
  const log = getLogger();
640
957
  log.trace({ filePath, account, tier: tier.name }, "parseMeta: start");
641
958
  const state = initialReducerState();
642
- const fileStream = (0, import_fs2.createReadStream)(filePath);
959
+ const fileStream = (0, import_fs3.createReadStream)(filePath);
643
960
  const rl = (0, import_readline.createInterface)({ input: fileStream, crlfDelay: Infinity });
644
961
  try {
645
962
  for await (const line of rl) {
@@ -676,7 +993,7 @@ async function parseConversation(filePath, account) {
676
993
  const textParts = [];
677
994
  const turnDurations = [];
678
995
  const state = initialConvState();
679
- const fileStream = (0, import_fs2.createReadStream)(filePath);
996
+ const fileStream = (0, import_fs3.createReadStream)(filePath);
680
997
  const rl = (0, import_readline.createInterface)({ input: fileStream, crlfDelay: Infinity });
681
998
  try {
682
999
  for await (const line of rl) {
@@ -720,10 +1037,8 @@ async function parseConversation(filePath, account) {
720
1037
  filePath,
721
1038
  projectPath: state.cwd,
722
1039
  projectName: getShortProjectName2(state.cwd),
723
- sessionId: state.sessionId || (0, import_path3.basename)(filePath, ".jsonl"),
724
- sessionName: state.sessionName || deriveSessionNameFromFirstMessage(
725
- messages.find((m) => m.role === "user" && m.text && !m.isCompactSummary) ?? null
726
- ),
1040
+ sessionId: state.sessionId || (0, import_path4.basename)(filePath, ".jsonl"),
1041
+ sessionName: resolveSessionName(state.nameSlots).name ?? "",
727
1042
  messages,
728
1043
  fullText: textParts.join(" "),
729
1044
  timestamp: state.latestTimestamp || (/* @__PURE__ */ new Date()).toISOString(),
@@ -833,7 +1148,7 @@ function initialConvState() {
833
1148
  return {
834
1149
  cwd: "",
835
1150
  sessionId: "",
836
- sessionName: "",
1151
+ nameSlots: {},
837
1152
  latestTimestamp: "",
838
1153
  lastPrompt: "",
839
1154
  pendingToolUses: {},
@@ -843,7 +1158,7 @@ function initialConvState() {
843
1158
  function reduceConvLine(state, entry) {
844
1159
  if (entry.cwd && !state.cwd) state.cwd = entry.cwd;
845
1160
  if (entry.sessionId && !state.sessionId) state.sessionId = entry.sessionId;
846
- if (entry.slug && !state.sessionName) state.sessionName = entry.slug;
1161
+ state.nameSlots = applyClaudeNameEntry(state.nameSlots, entry);
847
1162
  if (entry.timestamp) {
848
1163
  const ts = entry.timestamp;
849
1164
  if (!state.latestTimestamp || ts > state.latestTimestamp) state.latestTimestamp = ts;
@@ -951,7 +1266,7 @@ function applyTeamInfo(messages, state) {
951
1266
  }
952
1267
 
953
1268
  // src/persistent/sidecar.ts
954
- var import_fs3 = require("fs");
1269
+ var import_fs4 = require("fs");
955
1270
  var SIDECAR_VERSION = 1;
956
1271
  function sidecarPath(jsonlPath) {
957
1272
  return `${jsonlPath}.idx.json`;
@@ -977,14 +1292,14 @@ function buildSidecar(meta, cursor, updatedAt) {
977
1292
  }
978
1293
  function writeSidecar(jsonlPath, sidecar) {
979
1294
  try {
980
- (0, import_fs3.writeFileSync)(sidecarPath(jsonlPath), JSON.stringify(sidecar, null, 2));
1295
+ (0, import_fs4.writeFileSync)(sidecarPath(jsonlPath), JSON.stringify(sidecar, null, 2));
981
1296
  } catch (err) {
982
1297
  getLogger().warn({ jsonlPath, err }, "sidecar: write failed");
983
1298
  }
984
1299
  }
985
1300
  function readSidecar(jsonlPath) {
986
1301
  try {
987
- return JSON.parse((0, import_fs3.readFileSync)(sidecarPath(jsonlPath), "utf-8"));
1302
+ return JSON.parse((0, import_fs4.readFileSync)(sidecarPath(jsonlPath), "utf-8"));
988
1303
  } catch {
989
1304
  return null;
990
1305
  }
@@ -993,19 +1308,19 @@ function readSidecar(jsonlPath) {
993
1308
  // src/profiles.ts
994
1309
  var import_promises = require("fs/promises");
995
1310
  var import_os = require("os");
996
- var import_path4 = require("path");
1311
+ var import_path5 = require("path");
997
1312
  var PROFILES_FILE = "profiles.json";
998
1313
  function resolveConfigDir(configDir) {
999
1314
  return configDir.replace(/^~/, (0, import_os.homedir)());
1000
1315
  }
1001
1316
  function getProjectsDir(profile) {
1002
- return (0, import_path4.join)(resolveConfigDir(profile.configDir), "projects");
1317
+ return (0, import_path5.join)(resolveConfigDir(profile.configDir), "projects");
1003
1318
  }
1004
1319
  async function detectDefaultProfile() {
1005
1320
  return {
1006
1321
  id: "default",
1007
1322
  label: "Default",
1008
- configDir: (0, import_path4.join)((0, import_os.homedir)(), ".claude"),
1323
+ configDir: (0, import_path5.join)((0, import_os.homedir)(), ".claude"),
1009
1324
  enabled: true,
1010
1325
  emoji: "\u{1F916}"
1011
1326
  };
@@ -1014,7 +1329,7 @@ async function loadProfiles(configPath) {
1014
1329
  const log = getLogger();
1015
1330
  try {
1016
1331
  const resolved = resolveConfigDir(configPath);
1017
- const data = await (0, import_promises.readFile)((0, import_path4.join)(resolved, PROFILES_FILE), "utf-8");
1332
+ const data = await (0, import_promises.readFile)((0, import_path5.join)(resolved, PROFILES_FILE), "utf-8");
1018
1333
  const profiles = JSON.parse(data);
1019
1334
  log.debug({ configPath, count: profiles.length }, "profiles: loaded");
1020
1335
  return profiles;
@@ -1027,21 +1342,21 @@ async function loadProfiles(configPath) {
1027
1342
  async function saveProfiles(profiles, configPath) {
1028
1343
  const resolved = resolveConfigDir(configPath);
1029
1344
  await (0, import_promises.mkdir)(resolved, { recursive: true });
1030
- await (0, import_promises.writeFile)((0, import_path4.join)(resolved, PROFILES_FILE), JSON.stringify(profiles, null, 2));
1345
+ await (0, import_promises.writeFile)((0, import_path5.join)(resolved, PROFILES_FILE), JSON.stringify(profiles, null, 2));
1031
1346
  getLogger().debug({ configPath, count: profiles.length }, "profiles: saved");
1032
1347
  }
1033
1348
 
1034
1349
  // src/providers/codex-cli.ts
1035
1350
  var import_fast_glob = __toESM(require("fast-glob"), 1);
1036
- var import_fs4 = require("fs");
1351
+ var import_fs5 = require("fs");
1037
1352
  var import_promises2 = require("fs/promises");
1038
- var import_path6 = require("path");
1353
+ var import_path7 = require("path");
1039
1354
  var import_readline2 = require("readline");
1040
1355
 
1041
1356
  // src/canonical-path.ts
1042
- var import_path5 = require("path");
1357
+ var import_path6 = require("path");
1043
1358
  function canonicalPath(p) {
1044
- return import_path5.sep === "\\" ? p.replace(/\//g, "\\") : p;
1359
+ return import_path6.sep === "\\" ? p.replace(/\//g, "\\") : p;
1045
1360
  }
1046
1361
 
1047
1362
  // src/providers/codex-cli.ts
@@ -1101,6 +1416,7 @@ var CodexCliProvider = class {
1101
1416
  isSubagent: false,
1102
1417
  parentSessionUuid: null,
1103
1418
  firstUser: null,
1419
+ nameSlots: {},
1104
1420
  lastUser: null,
1105
1421
  lastAssistant: null,
1106
1422
  toolNames: [],
@@ -1263,6 +1579,7 @@ function reduceCodexEntry(acc, entry, tier) {
1263
1579
  const snapshot = { text: text.slice(0, 200), timestamp: ts };
1264
1580
  if (sender === "user") {
1265
1581
  if (!acc.firstUser) acc.firstUser = snapshot;
1582
+ acc.nameSlots = applyNameCandidate(acc.nameSlots, "firstUserMessage", text, CODEX_CLI_PROVIDER);
1266
1583
  acc.lastUser = snapshot;
1267
1584
  } else {
1268
1585
  acc.lastAssistant = snapshot;
@@ -1280,7 +1597,7 @@ function reduceCodexEntry(acc, entry, tier) {
1280
1597
  }
1281
1598
  function finalizeCodexMeta(acc, filePath, account, tier) {
1282
1599
  if (acc.messageCount === 0) return null;
1283
- const sessionId = acc.sessionId || (0, import_path6.basename)(filePath, ".jsonl");
1600
+ const sessionId = acc.sessionId || (0, import_path7.basename)(filePath, ".jsonl");
1284
1601
  const projectPath = acc.cwd;
1285
1602
  const kind = acc.lastAssistant === null && acc.toolNames.length > 0 ? "task" : "conversation";
1286
1603
  return {
@@ -1290,10 +1607,7 @@ function finalizeCodexMeta(acc, filePath, account, tier) {
1290
1607
  kind,
1291
1608
  externalSessionId: acc.sessionId || void 0,
1292
1609
  sessionId,
1293
- // Mirrors the Claude reducer: a rollout carries no slug, so the opening turn
1294
- // is the only human-readable name source. Only useful because the injected
1295
- // AGENTS.md turn is skipped above — otherwise every title would be that blob.
1296
- sessionName: deriveSessionNameFromFirstMessage(acc.firstUser),
1610
+ sessionName: resolveSessionName({ ...acc.nameSlots, ...codexNameSlotsFor(filePath, acc.sessionId) }).name ?? "",
1297
1611
  projectPath,
1298
1612
  projectName: getShortProjectName3(projectPath),
1299
1613
  account,
@@ -1316,10 +1630,6 @@ function finalizeCodexMeta(acc, filePath, account, tier) {
1316
1630
  lastPrompt: acc.lastUser?.text || void 0
1317
1631
  };
1318
1632
  }
1319
- function isCodexInjectedContext(text) {
1320
- if (text.startsWith("# AGENTS.md") || text.includes("<INSTRUCTIONS>")) return true;
1321
- return text.startsWith("<permissions instructions>") || text.includes("Filesystem sandboxing defines");
1322
- }
1323
1633
  function getShortProjectName3(fullPath) {
1324
1634
  return fullPath.split("/").filter(Boolean).slice(-3).join("/");
1325
1635
  }
@@ -1342,7 +1652,8 @@ async function parseCodexConversation(filePath, account) {
1342
1652
  let cwd = "";
1343
1653
  let latestTimestamp = "";
1344
1654
  let lastUserText = "";
1345
- const rl = (0, import_readline2.createInterface)({ input: (0, import_fs4.createReadStream)(filePath), crlfDelay: Infinity });
1655
+ let nameSlots = {};
1656
+ const rl = (0, import_readline2.createInterface)({ input: (0, import_fs5.createReadStream)(filePath), crlfDelay: Infinity });
1346
1657
  try {
1347
1658
  for await (const line of rl) {
1348
1659
  if (!line.trim()) continue;
@@ -1366,7 +1677,15 @@ async function parseCodexConversation(filePath, account) {
1366
1677
  messages.push(message);
1367
1678
  if (!message.text) continue;
1368
1679
  textParts.push(message.text);
1369
- if (message.role === "user") lastUserText = message.text;
1680
+ if (message.role === "user") {
1681
+ lastUserText = message.text;
1682
+ nameSlots = applyNameCandidate(
1683
+ nameSlots,
1684
+ "firstUserMessage",
1685
+ message.text,
1686
+ CODEX_CLI_PROVIDER
1687
+ );
1688
+ }
1370
1689
  }
1371
1690
  } catch (err) {
1372
1691
  log.warn({ filePath, err }, "parseCodexConversation: read failed");
@@ -1378,8 +1697,8 @@ async function parseCodexConversation(filePath, account) {
1378
1697
  filePath,
1379
1698
  projectPath: cwd,
1380
1699
  projectName: getShortProjectName3(cwd),
1381
- sessionId: sessionId || (0, import_path6.basename)(filePath, ".jsonl"),
1382
- sessionName: "",
1700
+ sessionId: sessionId || (0, import_path7.basename)(filePath, ".jsonl"),
1701
+ sessionName: resolveSessionName({ ...nameSlots, ...codexNameSlotsFor(filePath, sessionId) }).name ?? "",
1383
1702
  messages,
1384
1703
  fullText: textParts.join(" "),
1385
1704
  timestamp: latestTimestamp || (/* @__PURE__ */ new Date()).toISOString(),
@@ -1391,9 +1710,9 @@ async function parseCodexConversation(filePath, account) {
1391
1710
 
1392
1711
  // src/providers/copilot.ts
1393
1712
  var import_fast_glob2 = __toESM(require("fast-glob"), 1);
1394
- var import_fs5 = require("fs");
1713
+ var import_fs6 = require("fs");
1395
1714
  var import_promises3 = require("fs/promises");
1396
- var import_path7 = require("path");
1715
+ var import_path8 = require("path");
1397
1716
  var import_readline3 = require("readline");
1398
1717
  var SESSION_START = "session.start";
1399
1718
  var USER_MESSAGE = "user.message";
@@ -1447,6 +1766,7 @@ var CopilotProvider = class {
1447
1766
  messageCount: 0,
1448
1767
  lastMessageSender: "user",
1449
1768
  firstUser: null,
1769
+ nameSlots: {},
1450
1770
  lastUser: null,
1451
1771
  lastAssistant: null,
1452
1772
  toolNames: [],
@@ -1554,6 +1874,7 @@ function reduceCopilotEntry(acc, entry, tier) {
1554
1874
  const snapshot = { text: text.slice(0, 200), timestamp };
1555
1875
  if (role === "user") {
1556
1876
  if (!acc.firstUser) acc.firstUser = snapshot;
1877
+ acc.nameSlots = applyNameCandidate(acc.nameSlots, "firstUserMessage", text, COPILOT_PROVIDER);
1557
1878
  acc.lastUser = snapshot;
1558
1879
  } else {
1559
1880
  acc.lastAssistant = snapshot;
@@ -1580,7 +1901,7 @@ function finalizeCopilotMeta(acc, filePath, account, tier) {
1580
1901
  kind,
1581
1902
  externalSessionId: sessionId,
1582
1903
  sessionId,
1583
- sessionName: deriveSessionNameFromFirstMessage(acc.firstUser),
1904
+ sessionName: resolveSessionName({ ...acc.nameSlots, ...copilotNameSlotsFor(filePath) }).name ?? "",
1584
1905
  projectPath: acc.cwd,
1585
1906
  projectName: getShortProjectName4(acc.cwd),
1586
1907
  account,
@@ -1602,14 +1923,14 @@ function finalizeCopilotMeta(acc, filePath, account, tier) {
1602
1923
  };
1603
1924
  }
1604
1925
  function sessionIdFromPath(filePath) {
1605
- return (0, import_path7.basename)((0, import_path7.dirname)(filePath));
1926
+ return (0, import_path8.basename)((0, import_path8.dirname)(filePath));
1606
1927
  }
1607
1928
  function getShortProjectName4(fullPath) {
1608
1929
  return fullPath.split(/[/\\]/).filter(Boolean).slice(-3).join("/");
1609
1930
  }
1610
1931
  function fileMtimeIso(filePath) {
1611
1932
  try {
1612
- return new Date((0, import_fs5.statSync)(filePath).mtimeMs).toISOString();
1933
+ return new Date((0, import_fs6.statSync)(filePath).mtimeMs).toISOString();
1613
1934
  } catch {
1614
1935
  return (/* @__PURE__ */ new Date()).toISOString();
1615
1936
  }
@@ -1622,7 +1943,8 @@ async function parseCopilotConversation(filePath, account) {
1622
1943
  let cwd = "";
1623
1944
  let latestTimestamp = "";
1624
1945
  let lastUserText = "";
1625
- const rl = (0, import_readline3.createInterface)({ input: (0, import_fs5.createReadStream)(filePath), crlfDelay: Infinity });
1946
+ let nameSlots = {};
1947
+ const rl = (0, import_readline3.createInterface)({ input: (0, import_fs6.createReadStream)(filePath), crlfDelay: Infinity });
1626
1948
  try {
1627
1949
  for await (const line of rl) {
1628
1950
  if (!line.trim()) continue;
@@ -1646,7 +1968,15 @@ async function parseCopilotConversation(filePath, account) {
1646
1968
  messages.push(message);
1647
1969
  if (!message.text) continue;
1648
1970
  textParts.push(message.text);
1649
- if (message.role === "user") lastUserText = message.text;
1971
+ if (message.role === "user") {
1972
+ lastUserText = message.text;
1973
+ nameSlots = applyNameCandidate(
1974
+ nameSlots,
1975
+ "firstUserMessage",
1976
+ message.text,
1977
+ COPILOT_PROVIDER
1978
+ );
1979
+ }
1650
1980
  }
1651
1981
  } catch (err) {
1652
1982
  log.warn({ filePath, err }, "parseCopilotConversation: read failed");
@@ -1659,7 +1989,7 @@ async function parseCopilotConversation(filePath, account) {
1659
1989
  projectPath: cwd,
1660
1990
  projectName: getShortProjectName4(cwd),
1661
1991
  sessionId: sessionId || sessionIdFromPath(filePath),
1662
- sessionName: "",
1992
+ sessionName: resolveSessionName({ ...nameSlots, ...copilotNameSlotsFor(filePath) }).name ?? "",
1663
1993
  messages,
1664
1994
  fullText: textParts.join(" "),
1665
1995
  timestamp: latestTimestamp || fileMtimeIso(filePath),
@@ -1672,9 +2002,9 @@ async function parseCopilotConversation(filePath, account) {
1672
2002
  // src/providers/cursor.ts
1673
2003
  var import_crypto = require("crypto");
1674
2004
  var import_fast_glob3 = __toESM(require("fast-glob"), 1);
1675
- var import_fs6 = require("fs");
2005
+ var import_fs7 = require("fs");
1676
2006
  var import_promises4 = require("fs/promises");
1677
- var import_path8 = require("path");
2007
+ var import_path9 = require("path");
1678
2008
  var import_readline4 = require("readline");
1679
2009
  var TIMESTAMP_RE = /<timestamp>\s*([\s\S]*?)\s*<\/timestamp>/;
1680
2010
  var USER_QUERY_RE = /<user_query>\s*([\s\S]*?)\s*<\/user_query>/;
@@ -1733,6 +2063,7 @@ var CursorProvider = class {
1733
2063
  parentSessionUuid: null,
1734
2064
  subagentId: null,
1735
2065
  firstUser: null,
2066
+ nameSlots: {},
1736
2067
  lastUser: null,
1737
2068
  lastAssistant: null,
1738
2069
  isImportedFromClaude: false,
@@ -1799,6 +2130,15 @@ function noteImportProvenance(acc, entry, text) {
1799
2130
  acc.isImportedFromCodex = true;
1800
2131
  }
1801
2132
  }
2133
+ function cursorUserQuery(content) {
2134
+ const texts = typeof content === "string" ? [content] : Array.isArray(content) ? content : [];
2135
+ for (const item of texts) {
2136
+ const text = typeof item === "string" ? item : item?.text;
2137
+ const query = typeof text === "string" ? text.match(USER_QUERY_RE) : null;
2138
+ if (query) return query[1];
2139
+ }
2140
+ return void 0;
2141
+ }
1802
2142
  function unwrapCursorUserText(text) {
1803
2143
  const query = text.match(USER_QUERY_RE);
1804
2144
  const body = query ? query[1] : text.replace(TIMESTAMP_RE, "");
@@ -1936,6 +2276,14 @@ function reduceCursorEntry(acc, entry, tier) {
1936
2276
  collectCursorToolNames(content, acc.toolNames);
1937
2277
  const text = textHint;
1938
2278
  if (!text) return;
2279
+ if (entry.role === "user") {
2280
+ acc.nameSlots = applyNameCandidate(
2281
+ acc.nameSlots,
2282
+ "firstUserMessage",
2283
+ cursorUserQuery(content),
2284
+ CURSOR_PROVIDER
2285
+ );
2286
+ }
1939
2287
  foldCursorMessage(acc, entry.role, text, firstTimestampHint(content), tier);
1940
2288
  return;
1941
2289
  }
@@ -1954,7 +2302,7 @@ function reduceCursorEntry(acc, entry, tier) {
1954
2302
  }
1955
2303
  function finalizeCursorMeta(acc, filePath, account, tier) {
1956
2304
  if (acc.messageCount === 0) return null;
1957
- const sessionId = (0, import_path8.basename)(filePath, ".jsonl");
2305
+ const sessionId = (0, import_path9.basename)(filePath, ".jsonl");
1958
2306
  const isSubagent = SUBAGENT_PATH_RE2.test(filePath);
1959
2307
  const parent = isSubagent ? parentFromSubagentPath(filePath) : null;
1960
2308
  const { projectPath, projectName } = projectFromCursorPath(filePath);
@@ -1967,7 +2315,7 @@ function finalizeCursorMeta(acc, filePath, account, tier) {
1967
2315
  kind,
1968
2316
  externalSessionId: sessionId,
1969
2317
  sessionId,
1970
- sessionName: deriveSessionNameFromFirstMessage(acc.firstUser),
2318
+ sessionName: resolveSessionName({ ...acc.nameSlots, ...cursorNameSlotsFor(filePath, sessionId) }).name ?? "",
1971
2319
  projectPath,
1972
2320
  projectName,
1973
2321
  account,
@@ -1993,20 +2341,20 @@ function finalizeCursorMeta(acc, filePath, account, tier) {
1993
2341
  };
1994
2342
  }
1995
2343
  function parentFromSubagentPath(filePath) {
1996
- const subagentsDir = (0, import_path8.dirname)(filePath);
1997
- const parentDir = (0, import_path8.dirname)(subagentsDir);
1998
- const parentSessionUuid = (0, import_path8.basename)(parentDir);
2344
+ const subagentsDir = (0, import_path9.dirname)(filePath);
2345
+ const parentDir = (0, import_path9.dirname)(subagentsDir);
2346
+ const parentSessionUuid = (0, import_path9.basename)(parentDir);
1999
2347
  if (!parentSessionUuid) return null;
2000
2348
  return {
2001
2349
  parentSessionUuid,
2002
- parentFilePath: canonicalPath((0, import_path8.join)(parentDir, `${parentSessionUuid}.jsonl`))
2350
+ parentFilePath: canonicalPath((0, import_path9.join)(parentDir, `${parentSessionUuid}.jsonl`))
2003
2351
  };
2004
2352
  }
2005
2353
  function projectFromCursorPath(filePath) {
2006
2354
  const parts = filePath.split(/[/\\]/);
2007
2355
  const idx = parts.lastIndexOf("agent-transcripts");
2008
- const cursorProjectDir = idx > 0 ? parts.slice(0, idx).join(import_path8.sep) : (0, import_path8.dirname)((0, import_path8.dirname)(filePath));
2009
- const slug = (0, import_path8.basename)(cursorProjectDir);
2356
+ const cursorProjectDir = idx > 0 ? parts.slice(0, idx).join(import_path9.sep) : (0, import_path9.dirname)((0, import_path9.dirname)(filePath));
2357
+ const slug = (0, import_path9.basename)(cursorProjectDir);
2010
2358
  const decoded = decodeCursorProjectSlug(slug);
2011
2359
  const projectPath = decoded ?? cursorProjectDir;
2012
2360
  return { projectPath, projectName: getShortProjectName5(projectPath) || slug };
@@ -2016,11 +2364,11 @@ function decodeCursorProjectSlug(slug) {
2016
2364
  const segments = slug.split("-");
2017
2365
  if (segments.length === 0) return null;
2018
2366
  const rooted = slug.startsWith("Users-") || slug.startsWith("home-") || /^[A-Za-z]-/.test(slug);
2019
- let acc = rooted ? import_path8.sep : "";
2367
+ let acc = rooted ? import_path9.sep : "";
2020
2368
  let i = 0;
2021
2369
  if (rooted && segments[0] === "Users") {
2022
- const users = `${import_path8.sep}Users`;
2023
- if (!(0, import_fs6.existsSync)(users)) return null;
2370
+ const users = `${import_path9.sep}Users`;
2371
+ if (!(0, import_fs7.existsSync)(users)) return null;
2024
2372
  acc = users;
2025
2373
  i = 1;
2026
2374
  }
@@ -2028,9 +2376,9 @@ function decodeCursorProjectSlug(slug) {
2028
2376
  let found = null;
2029
2377
  let next = i + 1;
2030
2378
  for (let j = segments.length; j > i; j--) {
2031
- const candidate = (0, import_path8.join)(acc, segments.slice(i, j).join("-"));
2379
+ const candidate = (0, import_path9.join)(acc, segments.slice(i, j).join("-"));
2032
2380
  try {
2033
- if ((0, import_fs6.existsSync)(candidate) && (0, import_fs6.statSync)(candidate).isDirectory()) {
2381
+ if ((0, import_fs7.existsSync)(candidate) && (0, import_fs7.statSync)(candidate).isDirectory()) {
2034
2382
  found = candidate;
2035
2383
  next = j;
2036
2384
  break;
@@ -2049,18 +2397,27 @@ function getShortProjectName5(fullPath) {
2049
2397
  }
2050
2398
  function fileMtimeIso2(filePath) {
2051
2399
  try {
2052
- return new Date((0, import_fs6.statSync)(filePath).mtimeMs).toISOString();
2400
+ return new Date((0, import_fs7.statSync)(filePath).mtimeMs).toISOString();
2053
2401
  } catch {
2054
2402
  return (/* @__PURE__ */ new Date()).toISOString();
2055
2403
  }
2056
2404
  }
2405
+ function cursorLineContent(line) {
2406
+ try {
2407
+ const entry = JSON.parse(line);
2408
+ return entry.message?.content ?? entry.content;
2409
+ } catch {
2410
+ return void 0;
2411
+ }
2412
+ }
2057
2413
  async function parseCursorConversation(filePath, account) {
2058
2414
  const log = getLogger();
2059
2415
  const messages = [];
2060
2416
  const textParts = [];
2061
2417
  let latestTimestamp = "";
2062
2418
  let lastUserText = "";
2063
- const rl = (0, import_readline4.createInterface)({ input: (0, import_fs6.createReadStream)(filePath), crlfDelay: Infinity });
2419
+ let nameSlots = {};
2420
+ const rl = (0, import_readline4.createInterface)({ input: (0, import_fs7.createReadStream)(filePath), crlfDelay: Infinity });
2064
2421
  try {
2065
2422
  for await (const line of rl) {
2066
2423
  const message = parseCursorJsonlLine(line, messages.length);
@@ -2071,7 +2428,17 @@ async function parseCursorConversation(filePath, account) {
2071
2428
  messages.push(message);
2072
2429
  if (!message.text) continue;
2073
2430
  textParts.push(message.text);
2074
- if (message.role === "user") lastUserText = message.text;
2431
+ if (message.role === "user") {
2432
+ lastUserText = message.text;
2433
+ if (nameSlots.firstUserMessage === void 0) {
2434
+ nameSlots = applyNameCandidate(
2435
+ nameSlots,
2436
+ "firstUserMessage",
2437
+ cursorUserQuery(cursorLineContent(line)),
2438
+ CURSOR_PROVIDER
2439
+ );
2440
+ }
2441
+ }
2075
2442
  }
2076
2443
  } catch (err) {
2077
2444
  log.warn({ filePath, err }, "parseCursorConversation: read failed");
@@ -2079,14 +2446,14 @@ async function parseCursorConversation(filePath, account) {
2079
2446
  }
2080
2447
  if (messages.length === 0) return null;
2081
2448
  const { projectPath, projectName } = projectFromCursorPath(filePath);
2082
- const sessionId = (0, import_path8.basename)(filePath, ".jsonl");
2449
+ const sessionId = (0, import_path9.basename)(filePath, ".jsonl");
2083
2450
  return {
2084
2451
  id: filePath,
2085
2452
  filePath,
2086
2453
  projectPath,
2087
2454
  projectName,
2088
2455
  sessionId,
2089
- sessionName: "",
2456
+ sessionName: resolveSessionName({ ...nameSlots, ...cursorNameSlotsFor(filePath, sessionId) }).name ?? "",
2090
2457
  messages,
2091
2458
  fullText: textParts.join(" "),
2092
2459
  timestamp: latestTimestamp || fileMtimeIso2(filePath),
@@ -2200,9 +2567,9 @@ var ThreadbaseProvider = class {
2200
2567
 
2201
2568
  // src/scanner.ts
2202
2569
  var import_events = require("events");
2203
- var import_fs13 = require("fs");
2570
+ var import_fs14 = require("fs");
2204
2571
  var import_os2 = require("os");
2205
- var import_path13 = require("path");
2572
+ var import_path14 = require("path");
2206
2573
 
2207
2574
  // src/cache.ts
2208
2575
  var LRUCache = class {
@@ -2241,18 +2608,18 @@ var LRUCache = class {
2241
2608
  };
2242
2609
 
2243
2610
  // src/persistent/conversation-stream.ts
2244
- var import_path9 = require("path");
2611
+ var import_path10 = require("path");
2245
2612
 
2246
2613
  // src/persistent/paged-reader.ts
2247
- var import_fs8 = require("fs");
2614
+ var import_fs9 = require("fs");
2248
2615
  var import_promises7 = require("timers/promises");
2249
2616
 
2250
2617
  // src/persistent/jsonl-tail-reader.ts
2251
- var import_fs7 = require("fs");
2618
+ var import_fs8 = require("fs");
2252
2619
  var import_promises6 = require("timers/promises");
2253
2620
  var YIELD_EVERY_LINES = 500;
2254
2621
  async function tailReduce(filePath, startOffset, startLine, state, tier, onEntry) {
2255
- const stream = (0, import_fs7.createReadStream)(filePath, { start: startOffset, encoding: "utf8" });
2622
+ const stream = (0, import_fs8.createReadStream)(filePath, { start: startOffset, encoding: "utf8" });
2256
2623
  let buffer = "";
2257
2624
  let offset = startOffset;
2258
2625
  let line = startLine;
@@ -2289,7 +2656,7 @@ async function tailReduce(filePath, startOffset, startLine, state, tier, onEntry
2289
2656
  // src/persistent/paged-reader.ts
2290
2657
  var CHECKPOINT_INTERVAL = 500;
2291
2658
  async function streamMessages(filePath, startOffset, startLine, state, onMessage, onEntry) {
2292
- const stream = (0, import_fs8.createReadStream)(filePath, { start: startOffset, encoding: "utf8" });
2659
+ const stream = (0, import_fs9.createReadStream)(filePath, { start: startOffset, encoding: "utf8" });
2293
2660
  let buffer = "";
2294
2661
  let offset = startOffset;
2295
2662
  let line = startLine;
@@ -2401,10 +2768,8 @@ function assemble(filePath, account, messages, fullText, turnDurations, state) {
2401
2768
  filePath,
2402
2769
  projectPath: state.cwd,
2403
2770
  projectName: getShortProjectName2(state.cwd),
2404
- sessionId: state.sessionId || (0, import_path9.basename)(filePath, ".jsonl"),
2405
- sessionName: state.sessionName || deriveSessionNameFromFirstMessage(
2406
- messages.find((m) => m.role === "user" && m.text && !m.isCompactSummary) ?? null
2407
- ),
2771
+ sessionId: state.sessionId || (0, import_path10.basename)(filePath, ".jsonl"),
2772
+ sessionName: resolveSessionName(state.nameSlots).name ?? "",
2408
2773
  messages,
2409
2774
  fullText,
2410
2775
  timestamp: state.latestTimestamp || (/* @__PURE__ */ new Date()).toISOString(),
@@ -2448,33 +2813,33 @@ async function extendConversation(previous, resume, filePath, account) {
2448
2813
 
2449
2814
  // src/persistent/cursor.ts
2450
2815
  var import_crypto2 = require("crypto");
2451
- var import_fs9 = require("fs");
2816
+ var import_fs10 = require("fs");
2452
2817
  var FP_BYTES = 4096;
2453
2818
  function fingerprint(filePath, size) {
2454
2819
  const hash = (0, import_crypto2.createHash)("sha1");
2455
2820
  hash.update(String(size));
2456
- const fd = (0, import_fs9.openSync)(filePath, "r");
2821
+ const fd = (0, import_fs10.openSync)(filePath, "r");
2457
2822
  try {
2458
2823
  const head = Buffer.alloc(Math.min(FP_BYTES, size));
2459
2824
  if (head.length > 0) {
2460
- (0, import_fs9.readSync)(fd, head, 0, head.length, 0);
2825
+ (0, import_fs10.readSync)(fd, head, 0, head.length, 0);
2461
2826
  hash.update(head);
2462
2827
  }
2463
2828
  if (size > FP_BYTES) {
2464
2829
  const tailLen = Math.min(FP_BYTES, size);
2465
2830
  const tail = Buffer.alloc(tailLen);
2466
- (0, import_fs9.readSync)(fd, tail, 0, tailLen, size - tailLen);
2831
+ (0, import_fs10.readSync)(fd, tail, 0, tailLen, size - tailLen);
2467
2832
  hash.update(tail);
2468
2833
  }
2469
2834
  } finally {
2470
- (0, import_fs9.closeSync)(fd);
2835
+ (0, import_fs10.closeSync)(fd);
2471
2836
  }
2472
2837
  return hash.digest("hex");
2473
2838
  }
2474
2839
  function classify(filePath, existing) {
2475
2840
  let stat6;
2476
2841
  try {
2477
- const s = (0, import_fs9.statSync)(filePath);
2842
+ const s = (0, import_fs10.statSync)(filePath);
2478
2843
  stat6 = { size: s.size, mtimeMs: s.mtimeMs };
2479
2844
  } catch {
2480
2845
  return { change: "vanished" };
@@ -2502,16 +2867,16 @@ function classify(filePath, existing) {
2502
2867
  }
2503
2868
 
2504
2869
  // src/persistent/index-engine.ts
2505
- var import_fs12 = require("fs");
2870
+ var import_fs13 = require("fs");
2506
2871
 
2507
2872
  // src/providers/parse.ts
2508
- var import_fs10 = require("fs");
2873
+ var import_fs11 = require("fs");
2509
2874
  var import_readline5 = require("readline");
2510
- async function parseMetaWithProvider(provider, filePath, account, tier, onEntry) {
2875
+ async function parseMetaWithProvider(provider, filePath, account, tier, onEntry, onAccumulator) {
2511
2876
  const log = getLogger();
2512
2877
  const acc = provider.createEmptyAccumulator();
2513
2878
  const rl = (0, import_readline5.createInterface)({
2514
- input: (0, import_fs10.createReadStream)(filePath),
2879
+ input: (0, import_fs11.createReadStream)(filePath),
2515
2880
  crlfDelay: Infinity
2516
2881
  });
2517
2882
  try {
@@ -2534,6 +2899,7 @@ async function parseMetaWithProvider(provider, filePath, account, tier, onEntry)
2534
2899
  log.warn({ filePath, provider: provider.name, err }, "provider parse: read failed");
2535
2900
  return null;
2536
2901
  }
2902
+ onAccumulator?.(acc);
2537
2903
  return provider.finalize(acc, filePath, account, tier);
2538
2904
  }
2539
2905
 
@@ -2734,12 +3100,12 @@ function resolveTier(tierName, customTiers) {
2734
3100
  }
2735
3101
 
2736
3102
  // src/persistent/db.ts
2737
- var import_better_sqlite3 = __toESM(require("better-sqlite3"), 1);
2738
- var import_fs11 = require("fs");
2739
- var import_path10 = require("path");
3103
+ var import_better_sqlite32 = __toESM(require("better-sqlite3"), 1);
3104
+ var import_fs12 = require("fs");
3105
+ var import_path11 = require("path");
2740
3106
 
2741
3107
  // src/persistent/schema.ts
2742
- var SCHEMA_VERSION = 10;
3108
+ var SCHEMA_VERSION = 11;
2743
3109
  var SCHEMA_SQL = `
2744
3110
  CREATE TABLE IF NOT EXISTS conversation_files (
2745
3111
  id INTEGER PRIMARY KEY AUTOINCREMENT,
@@ -2785,6 +3151,9 @@ CREATE TABLE IF NOT EXISTS conversations (
2785
3151
  external_session_id TEXT,
2786
3152
  session_id TEXT NOT NULL,
2787
3153
  session_name TEXT,
3154
+ -- JSON NameSlots the name was resolved from; lets a side-store change
3155
+ -- re-resolve the name without reparsing the transcript.
3156
+ name_slots TEXT,
2788
3157
 
2789
3158
  project_path TEXT,
2790
3159
  project_name TEXT,
@@ -3047,6 +3416,27 @@ function runMigrations(db) {
3047
3416
  db.exec(`UPDATE conversation_files SET ${assignments.join(", ")}`);
3048
3417
  }
3049
3418
  }
3419
+ if (current >= 1 && current < 11 && tableExists(db, "conversations")) {
3420
+ if (tableExists(db, "message_checkpoints")) db.exec("DELETE FROM message_checkpoints");
3421
+ if (!hasColumn(db, "conversations", "name_slots")) {
3422
+ db.exec("ALTER TABLE conversations ADD COLUMN name_slots TEXT");
3423
+ }
3424
+ if (tableExists(db, "conversation_files")) {
3425
+ const assignments = [];
3426
+ if (hasColumn(db, "conversation_files", "last_indexed_offset")) {
3427
+ assignments.push("last_indexed_offset = 0");
3428
+ }
3429
+ if (hasColumn(db, "conversation_files", "last_indexed_line")) {
3430
+ assignments.push("last_indexed_line = 0");
3431
+ }
3432
+ if (hasColumn(db, "conversation_files", "reducer_state")) {
3433
+ assignments.push("reducer_state = NULL");
3434
+ }
3435
+ if (assignments.length > 0) {
3436
+ db.exec(`UPDATE conversation_files SET ${assignments.join(", ")}`);
3437
+ }
3438
+ }
3439
+ }
3050
3440
  db.exec(SCHEMA_SQL);
3051
3441
  db.pragma(`user_version = ${SCHEMA_VERSION}`);
3052
3442
  }
@@ -3061,11 +3451,11 @@ function hasColumn(db, table, column) {
3061
3451
  // src/persistent/db.ts
3062
3452
  function openDatabase(dbPath) {
3063
3453
  if (dbPath !== ":memory:") {
3064
- (0, import_fs11.mkdirSync)((0, import_path10.dirname)(dbPath), { recursive: true });
3454
+ (0, import_fs12.mkdirSync)((0, import_path11.dirname)(dbPath), { recursive: true });
3065
3455
  }
3066
3456
  let db;
3067
3457
  try {
3068
- db = new import_better_sqlite3.default(dbPath);
3458
+ db = new import_better_sqlite32.default(dbPath);
3069
3459
  } catch (err) {
3070
3460
  if (isNativeBindingFailure(err)) throw nativeBindingError(err, dbPath);
3071
3461
  throw err;
@@ -3106,7 +3496,7 @@ function nativeBindingError(err, dbPath) {
3106
3496
 
3107
3497
  // src/persistent/dir-watermark.ts
3108
3498
  var import_promises8 = require("fs/promises");
3109
- var import_path11 = require("path");
3499
+ var import_path12 = require("path");
3110
3500
  var FULL_RECONCILE_EVERY_N_SCANS = 20;
3111
3501
  async function discoverJsonlFilesGated(dirs, files, scannedDirs, options = {}) {
3112
3502
  const log = getLogger();
@@ -3177,10 +3567,10 @@ async function resolveProjectDirs(projectsDir, scannedDirs) {
3177
3567
  return { entries, commitRoot: { mtimeMs: rootStat.mtimeMs } };
3178
3568
  }
3179
3569
  function dirnameOf(filePath) {
3180
- return (0, import_path11.dirname)(filePath);
3570
+ return (0, import_path12.dirname)(filePath);
3181
3571
  }
3182
3572
  function joinPath(dir, name) {
3183
- return (0, import_path11.join)(dir, name);
3573
+ return (0, import_path12.join)(dir, name);
3184
3574
  }
3185
3575
 
3186
3576
  // src/persistent/repositories/checkpoints.repo.ts
@@ -3260,7 +3650,7 @@ function toCheckpoint(row) {
3260
3650
  }
3261
3651
 
3262
3652
  // src/persistent/repositories/conversation-files.repo.ts
3263
- var import_path12 = require("path");
3653
+ var import_path13 = require("path");
3264
3654
  var ConversationFilesRepo = class {
3265
3655
  constructor(db) {
3266
3656
  this.db = db;
@@ -3283,7 +3673,7 @@ var ConversationFilesRepo = class {
3283
3673
  const info = this.db.prepare(
3284
3674
  `INSERT INTO conversation_files (absolute_path, parent_dir, file_name, account)
3285
3675
  VALUES (?, ?, ?, ?)`
3286
- ).run(canonical, (0, import_path12.dirname)(canonical), (0, import_path12.basename)(canonical), account);
3676
+ ).run(canonical, (0, import_path13.dirname)(canonical), (0, import_path13.basename)(canonical), account);
3287
3677
  return Number(info.lastInsertRowid);
3288
3678
  }
3289
3679
  // Advance the cursor + persisted reducer state after a successful index pass.
@@ -3391,7 +3781,7 @@ var ConversationsRepo = class {
3391
3781
  db;
3392
3782
  // Upsert by file_id (1 file = 1 conversation). Keyed on the unique file_id so
3393
3783
  // a re-index overwrites the prior summary in place.
3394
- upsert(fileId, meta, pageMessageCount = meta.messageCount) {
3784
+ upsert(fileId, meta, pageMessageCount = meta.messageCount, nameSlots) {
3395
3785
  this.db.prepare(
3396
3786
  `INSERT INTO conversations (
3397
3787
  file_id, source_path, provider, kind, external_session_id,
@@ -3402,7 +3792,7 @@ var ConversationsRepo = class {
3402
3792
  model, is_subagent, parent_session_id, subagent_id, parent_session_uuid,
3403
3793
  is_teammate, team_name, tool_names_json,
3404
3794
  last_prompt, is_imported_from_claude, is_imported_from_codex,
3405
- is_imported_from_cursor, status, updated_at
3795
+ is_imported_from_cursor, name_slots, status, updated_at
3406
3796
  ) VALUES (
3407
3797
  @file_id, @source_path, @provider, @kind, @external_session_id,
3408
3798
  @session_id, @session_name, @project_path, @project_name,
@@ -3414,7 +3804,7 @@ var ConversationsRepo = class {
3414
3804
  @model, @is_subagent, @parent_session_id, @subagent_id, @parent_session_uuid,
3415
3805
  @is_teammate, @team_name, @tool_names_json,
3416
3806
  @last_prompt, @is_imported_from_claude, @is_imported_from_codex,
3417
- @is_imported_from_cursor, 'active', CURRENT_TIMESTAMP
3807
+ @is_imported_from_cursor, @name_slots, 'active', CURRENT_TIMESTAMP
3418
3808
  )
3419
3809
  ON CONFLICT(file_id) DO UPDATE SET
3420
3810
  source_path = excluded.source_path,
@@ -3449,6 +3839,7 @@ var ConversationsRepo = class {
3449
3839
  is_imported_from_claude = excluded.is_imported_from_claude,
3450
3840
  is_imported_from_codex = excluded.is_imported_from_codex,
3451
3841
  is_imported_from_cursor = excluded.is_imported_from_cursor,
3842
+ name_slots = excluded.name_slots,
3452
3843
  status = 'active',
3453
3844
  index_seq = (SELECT COALESCE(MAX(index_seq), 0) + 1 FROM conversations),
3454
3845
  updated_at = CURRENT_TIMESTAMP`
@@ -3488,7 +3879,8 @@ var ConversationsRepo = class {
3488
3879
  last_prompt: meta.lastPrompt ?? null,
3489
3880
  is_imported_from_claude: meta.isImportedFromClaude ? 1 : 0,
3490
3881
  is_imported_from_codex: meta.isImportedFromCodex ? 1 : 0,
3491
- is_imported_from_cursor: meta.isImportedFromCursor ? 1 : 0
3882
+ is_imported_from_cursor: meta.isImportedFromCursor ? 1 : 0,
3883
+ name_slots: nameSlots ? JSON.stringify(nameSlots) : null
3492
3884
  });
3493
3885
  }
3494
3886
  getBySourcePath(sourcePath) {
@@ -3869,13 +4261,18 @@ var PersistentEngine = class {
3869
4261
  const tier = resolveTier(tierName, customTiers);
3870
4262
  const filePath = canonicalPath(rawFilePath);
3871
4263
  const existing = this.files.getByPath(filePath);
3872
- const { change, stat: stat6 } = classify(filePath, existing);
4264
+ const classified = classify(filePath, existing);
4265
+ const stat6 = classified.stat;
4266
+ let change = classified.change;
3873
4267
  if (change === "vanished" || !stat6) {
3874
4268
  this.markDeleted(filePath);
3875
4269
  return { meta: null, change: "vanished" };
3876
4270
  }
3877
4271
  if (change === "unchanged" && !force) {
3878
- return { meta: this.conversations.getBySourcePath(filePath), change };
4272
+ const meta2 = this.conversations.getBySourcePath(filePath);
4273
+ const sideStoresMoved = provider && provider.name !== CLAUDE_CODE_PROVIDER && meta2 && JSON.stringify(nameStoreSlotsFor(provider.name, filePath, meta2.sessionId)) !== existing?.reducer_state;
4274
+ if (!sideStoresMoved) return { meta: meta2, change };
4275
+ change = "reindex";
3879
4276
  }
3880
4277
  if (provider && provider.name !== CLAUDE_CODE_PROVIDER) {
3881
4278
  const meta2 = await this.indexFileWithProvider(
@@ -3914,7 +4311,7 @@ var PersistentEngine = class {
3914
4311
  const base = resume ? this.fts.readDocument(fileId) ?? emptySearchDocument() : emptySearchDocument();
3915
4312
  const searchDoc = appendSearchDelta(base, searchDelta);
3916
4313
  const upsert = this.db.transaction(() => {
3917
- this.conversations.upsert(fileId, meta, state.pageMessageCount);
4314
+ this.conversations.upsert(fileId, meta, state.pageMessageCount, state.nameSlots);
3918
4315
  if (!this.fts.isCurrent(fileId, meta, searchDoc)) {
3919
4316
  this.fts.upsert(fileId, meta, searchDoc);
3920
4317
  }
@@ -3957,13 +4354,23 @@ var PersistentEngine = class {
3957
4354
  // provider's reducer/finalize, then the same upsert + FTS write + cursor bump
3958
4355
  // the Threadbase path uses. The cursor records size/mtime (and offset = size)
3959
4356
  // so the next pass classifies an unchanged file as "unchanged" and skips it;
3960
- // any change reparses from 0 again. No reducer_state is persisted.
4357
+ // any change reparses from 0 again. reducer_state holds the side-store name slots, not a fold.
3961
4358
  async indexFileWithProvider(provider, filePath, account, tier, stat6, resolveGitBranch) {
3962
4359
  const log = getLogger();
3963
4360
  let searchDoc = emptySearchDocument();
3964
- const meta = await parseMetaWithProvider(provider, filePath, account, tier, (entry) => {
3965
- searchDoc = appendSearchDelta(searchDoc, extractSearchDelta(entry));
3966
- });
4361
+ let transcriptSlots = {};
4362
+ const meta = await parseMetaWithProvider(
4363
+ provider,
4364
+ filePath,
4365
+ account,
4366
+ tier,
4367
+ (entry) => {
4368
+ searchDoc = appendSearchDelta(searchDoc, extractSearchDelta(entry));
4369
+ },
4370
+ (acc) => {
4371
+ transcriptSlots = acc.nameSlots ?? {};
4372
+ }
4373
+ );
3967
4374
  if (!meta) {
3968
4375
  this.markDeleted(filePath);
3969
4376
  return null;
@@ -3971,10 +4378,14 @@ var PersistentEngine = class {
3971
4378
  if (meta.gitBranch === null && meta.projectPath) {
3972
4379
  meta.gitBranch = resolveGitBranch(meta.projectPath);
3973
4380
  }
4381
+ const sideSlots = nameStoreSlotsFor(provider.name, filePath, meta.sessionId);
3974
4382
  const fp = stat6.size > 0 ? fingerprint(filePath, stat6.size) : null;
3975
4383
  const fileId = this.files.ensure(filePath, account);
3976
4384
  const upsert = this.db.transaction(() => {
3977
- this.conversations.upsert(fileId, meta, meta.messageCount);
4385
+ this.conversations.upsert(fileId, meta, meta.messageCount, {
4386
+ ...transcriptSlots,
4387
+ ...sideSlots
4388
+ });
3978
4389
  if (!this.fts.isCurrent(fileId, meta, searchDoc)) {
3979
4390
  this.fts.upsert(fileId, meta, searchDoc);
3980
4391
  }
@@ -3986,7 +4397,9 @@ var PersistentEngine = class {
3986
4397
  // can classify it "unchanged"); no resumable reducer state is kept.
3987
4398
  offset: stat6.size,
3988
4399
  line: 0,
3989
- reducerState: null,
4400
+ // Not resumable state: the side-store name slots this parse used, so the
4401
+ // next pass can tell when they moved (see indexFile).
4402
+ reducerState: JSON.stringify(sideSlots),
3990
4403
  fingerprint: fp,
3991
4404
  status: "active"
3992
4405
  });
@@ -4066,7 +4479,7 @@ var PersistentEngine = class {
4066
4479
  let floor = this.checkpoints.floor(filePath, fromIndex);
4067
4480
  if (floor) {
4068
4481
  try {
4069
- if (floor.byteOffset > (0, import_fs12.statSync)(filePath).size) floor = null;
4482
+ if (floor.byteOffset > (0, import_fs13.statSync)(filePath).size) floor = null;
4070
4483
  } catch {
4071
4484
  }
4072
4485
  }
@@ -4205,7 +4618,7 @@ function defaultDbPath() {
4205
4618
  "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."
4206
4619
  );
4207
4620
  }
4208
- return (0, import_path13.join)((0, import_os2.homedir)(), ".config", "threadbase-scanner", "index.db");
4621
+ return (0, import_path14.join)((0, import_os2.homedir)(), ".config", "threadbase-scanner", "index.db");
4209
4622
  }
4210
4623
  function capForMemory(doc, max) {
4211
4624
  const combined = combineSearchContent(doc);
@@ -4298,6 +4711,7 @@ var ConversationScanner = class {
4298
4711
  }
4299
4712
  }
4300
4713
  async runScan(options) {
4714
+ if (options.cursorStateDb !== void 0) setCursorStateDb(options.cursorStateDb);
4301
4715
  const profiles = await this.resolveProfiles(options.profiles);
4302
4716
  const activeProfiles = profiles.filter((p) => p.enabled && p.scanHistory !== false);
4303
4717
  this.lastTier = resolveTier(options.tier ?? "standard", options.tiers);
@@ -4384,7 +4798,7 @@ var ConversationScanner = class {
4384
4798
  const cached = statCache.get(filePath);
4385
4799
  if (cached) {
4386
4800
  try {
4387
- const s = (0, import_fs13.statSync)(filePath);
4801
+ const s = (0, import_fs14.statSync)(filePath);
4388
4802
  if (s.mtimeMs === cached.stat.mtimeMs && s.size === cached.stat.size) {
4389
4803
  return {
4390
4804
  meta: cached.meta,
@@ -4932,13 +5346,13 @@ var ConversationScanner = class {
4932
5346
  if (previous?.provider) return void 0;
4933
5347
  let sample = "";
4934
5348
  try {
4935
- const fd = (0, import_fs13.openSync)(filePath, "r");
5349
+ const fd = (0, import_fs14.openSync)(filePath, "r");
4936
5350
  try {
4937
5351
  const buf = Buffer.alloc(8192);
4938
- const n = (0, import_fs13.readSync)(fd, buf, 0, buf.length, 0);
5352
+ const n = (0, import_fs14.readSync)(fd, buf, 0, buf.length, 0);
4939
5353
  sample = buf.subarray(0, n).toString("utf8");
4940
5354
  } finally {
4941
- (0, import_fs13.closeSync)(fd);
5355
+ (0, import_fs14.closeSync)(fd);
4942
5356
  }
4943
5357
  } catch {
4944
5358
  return void 0;
@@ -5066,11 +5480,13 @@ async function getConversation(id, options, scanner) {
5066
5480
  CursorProvider,
5067
5481
  DEFAULT_TIERS,
5068
5482
  LEGACY_CURSOR_PROVIDER,
5483
+ NAME_PRECEDENCE,
5069
5484
  SearchIndexer,
5070
5485
  ThreadbaseProvider,
5071
5486
  VALID_SORT_ORDERS,
5072
5487
  applyAccountFilter,
5073
5488
  applyIncludeFilter,
5489
+ applyNameCandidate,
5074
5490
  applyPagination,
5075
5491
  applyProjectFilter,
5076
5492
  applySinceFilter,
@@ -5085,20 +5501,27 @@ async function getConversation(id, options, scanner) {
5085
5501
  getLogger,
5086
5502
  getProjectsDir,
5087
5503
  isCodexInjectedContext,
5504
+ isValidNameCandidate,
5088
5505
  loadProfiles,
5089
5506
  parseCodexJsonlLine,
5090
5507
  parseCopilotJsonlLine,
5091
5508
  parseCursorJsonlLine,
5092
5509
  parseJsonlLine,
5093
5510
  providerMatches,
5511
+ readCodexNameSlots,
5512
+ readCopilotNameSlots,
5513
+ readCursorCliNameSlots,
5514
+ readCursorIdeNameSlots,
5094
5515
  readGitBranch,
5095
5516
  readSidecar,
5096
5517
  resetDefaultScanner,
5097
5518
  resolveConfigDir,
5519
+ resolveSessionName,
5098
5520
  resolveTier,
5099
5521
  saveProfiles,
5100
5522
  scan,
5101
5523
  search,
5524
+ setCursorStateDb,
5102
5525
  setLogger,
5103
5526
  sidecarPath,
5104
5527
  unwrapCursorUserText