@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/cli.js CHANGED
@@ -5,7 +5,7 @@ import { Command } from "commander";
5
5
  import pino2 from "pino";
6
6
 
7
7
  // package.json
8
- var version = "0.21.1";
8
+ var version = "0.22.0";
9
9
 
10
10
  // src/logger.ts
11
11
  import pino from "pino";
@@ -60,9 +60,9 @@ async function saveProfiles(profiles, configPath) {
60
60
 
61
61
  // src/scanner.ts
62
62
  import { EventEmitter } from "events";
63
- import { closeSync as closeSync2, openSync as openSync2, readSync as readSync2, statSync as statSync5 } from "fs";
63
+ import { closeSync as closeSync3, openSync as openSync3, readSync as readSync3, statSync as statSync6 } from "fs";
64
64
  import { homedir as homedir2 } from "os";
65
- import { join as join6 } from "path";
65
+ import { join as join7 } from "path";
66
66
 
67
67
  // src/cache.ts
68
68
  var LRUCache = class {
@@ -506,17 +506,317 @@ function toIndexDoc(meta, searchContent) {
506
506
  };
507
507
  }
508
508
 
509
+ // src/name-stores.ts
510
+ import Database from "better-sqlite3";
511
+ import { closeSync, existsSync, openSync, readdirSync, readFileSync as readFileSync2, readSync, statSync } from "fs";
512
+ import { basename, dirname as dirname2, join as join3 } from "path";
513
+
514
+ // src/tags.ts
515
+ var SYSTEM_TAGS = [
516
+ "system-reminder",
517
+ "command-name",
518
+ "command-message",
519
+ "command-args",
520
+ "ide_selection",
521
+ "ide_opened_file",
522
+ "local-command-stdout",
523
+ "local-command-caveat",
524
+ "retrieval_status",
525
+ "task_id",
526
+ "task_type",
527
+ "task-id",
528
+ "task-notification",
529
+ "fast_mode_info",
530
+ "persisted-output",
531
+ "tool_use_error",
532
+ "user-prompt-submit-hook",
533
+ "thinking",
534
+ "ask_user",
535
+ "teammate-message"
536
+ ];
537
+ var SYSTEM_TAG_RE = new RegExp(`<(${SYSTEM_TAGS.join("|")})[^>]*>[\\s\\S]*?<\\/\\1>`, "g");
538
+ var PASTED_CONTENT_RE = /<pasted_content id="[0-9a-f]{4}">([\s\S]*?)<\/pasted_content(?: id="[0-9a-f]{4}")?>/g;
539
+ function cleanSystemTags(text) {
540
+ return text.replace(SYSTEM_TAG_RE, "").replace(PASTED_CONTENT_RE, "$1").replace(/[^\S\n]+/g, " ").replace(/\n{3,}/g, "\n\n").trim();
541
+ }
542
+
543
+ // src/session-name.ts
544
+ var NAME_PRECEDENCE = [
545
+ "userTitle",
546
+ "toolTitle",
547
+ "lastPrompt",
548
+ "firstUserMessage",
549
+ "slug"
550
+ ];
551
+ var CLAUDE_SYSTEM_PREFIXES = [
552
+ "<command-name>",
553
+ "<command-message>",
554
+ "<command-args>",
555
+ "<local-command-stdout>",
556
+ "<local-command-stderr>",
557
+ "<local-command-caveat>",
558
+ "<bash-input>",
559
+ "<bash-stdout>",
560
+ "<bash-stderr>",
561
+ "<system-reminder>",
562
+ "<task-notification>",
563
+ "<teammate-message",
564
+ "Another Claude session sent a message:",
565
+ "[Request interrupted by user"
566
+ ];
567
+ var CODEX_SYSTEM_PREFIXES = [
568
+ "<environment_context>",
569
+ "# AGENTS.md instructions",
570
+ "<user_instructions>",
571
+ "<INSTRUCTIONS>",
572
+ "<external_codex_apps_open",
573
+ "<user_shell_command>",
574
+ "<turn_aborted>"
575
+ ];
576
+ function isCodexInjectedContext(text) {
577
+ if (text.startsWith("# AGENTS.md") || text.includes("<INSTRUCTIONS>")) return true;
578
+ return text.startsWith("<permissions instructions>") || text.includes("Filesystem sandboxing defines");
579
+ }
580
+ var CODEX_IMAGE_TAG_RE = /<\/?image\b[^>]*>/g;
581
+ function normalizeCandidate(text, provider) {
582
+ let t = text.trim();
583
+ if (provider === "codex-cli") t = t.replace(CODEX_IMAGE_TAG_RE, "").trim();
584
+ const prefixes = provider === "claude-code" ? CLAUDE_SYSTEM_PREFIXES : provider === "codex-cli" ? CODEX_SYSTEM_PREFIXES : [];
585
+ if (prefixes.some((p) => t.startsWith(p))) return null;
586
+ if (provider === "codex-cli" && isCodexInjectedContext(t)) return null;
587
+ return cleanSystemTags(t) || null;
588
+ }
589
+ function resolveSessionName(slots) {
590
+ for (const slot of NAME_PRECEDENCE) {
591
+ const value = slots[slot];
592
+ if (value?.trim()) return { name: value, source: slot };
593
+ }
594
+ return { name: null, source: null };
595
+ }
596
+ function applyNameCandidate(slots, slot, raw, provider) {
597
+ if (typeof raw !== "string") return slots;
598
+ if (slot === "firstUserMessage" && slots.firstUserMessage !== void 0) return slots;
599
+ const text = normalizeCandidate(raw, provider);
600
+ return text === null ? slots : { ...slots, [slot]: text };
601
+ }
602
+
603
+ // src/name-stores.ts
604
+ function slotsFrom(provider, candidates) {
605
+ return candidates.reduce(
606
+ (slots, [slot, raw]) => applyNameCandidate(slots, slot, typeof raw === "string" ? raw : void 0, provider),
607
+ {}
608
+ );
609
+ }
610
+ function readJson(path) {
611
+ try {
612
+ return JSON.parse(readFileSync2(path, "utf8"));
613
+ } catch {
614
+ return void 0;
615
+ }
616
+ }
617
+ function queryOne(dbPath, sql, ...params) {
618
+ let db;
619
+ try {
620
+ db = new Database(dbPath, { readonly: true, fileMustExist: true, timeout: 250 });
621
+ return db.prepare(sql).get(...params);
622
+ } catch (err) {
623
+ getLogger().debug({ dbPath, err }, "name store: query failed");
624
+ return void 0;
625
+ } finally {
626
+ db?.close();
627
+ }
628
+ }
629
+ var lastByIdCache = /* @__PURE__ */ new Map();
630
+ function lastValueById(path, idField, valueField) {
631
+ let sig;
632
+ try {
633
+ const s = statSync(path);
634
+ sig = `${s.mtimeMs}:${s.size}`;
635
+ } catch {
636
+ return /* @__PURE__ */ new Map();
637
+ }
638
+ const key = `${path}\0${idField}\0${valueField}`;
639
+ const cached = lastByIdCache.get(key);
640
+ if (cached?.sig === sig) return cached.map;
641
+ const map = /* @__PURE__ */ new Map();
642
+ try {
643
+ for (const line of readFileSync2(path, "utf8").split("\n")) {
644
+ if (!line.trim()) continue;
645
+ try {
646
+ const row = JSON.parse(line);
647
+ const id = row[idField];
648
+ const value = row[valueField];
649
+ if (typeof id === "string" && typeof value === "string") map.set(id, value);
650
+ } catch {
651
+ }
652
+ }
653
+ } catch {
654
+ }
655
+ lastByIdCache.set(key, { sig, map });
656
+ return map;
657
+ }
658
+ function readCodexNameSlots(codexHome, id) {
659
+ const index = lastValueById(join3(codexHome, "session_index.jsonl"), "id", "thread_name");
660
+ const history = lastValueById(join3(codexHome, "history.jsonl"), "session_id", "text");
661
+ let title = index.get(id);
662
+ if (!index.has(id)) {
663
+ title = queryOne(
664
+ join3(codexHome, "state_5.sqlite"),
665
+ "SELECT name FROM threads WHERE id = ?",
666
+ id
667
+ )?.name;
668
+ }
669
+ return slotsFrom("codex-cli", [
670
+ ["toolTitle", title],
671
+ ["lastPrompt", history.get(id)]
672
+ ]);
673
+ }
674
+ function readCursorCliNameSlots(chatsDir, id) {
675
+ let chat;
676
+ try {
677
+ chat = readdirSync(chatsDir).map((hash) => join3(chatsDir, hash, id)).find((p) => existsSync(p));
678
+ } catch {
679
+ }
680
+ if (!chat) return {};
681
+ const meta = readJson(join3(chat, "meta.json"));
682
+ const history = readJson(join3(chat, "prompt_history.json"));
683
+ let title = meta?.title;
684
+ if (typeof title !== "string" || !title.trim()) title = storeDbName(join3(chat, "store.db"));
685
+ return slotsFrom("cursor", [
686
+ ["toolTitle", title],
687
+ ["lastPrompt", Array.isArray(history) ? history[0] : void 0]
688
+ ]);
689
+ }
690
+ function storeDbName(dbPath) {
691
+ const row = queryOne(
692
+ dbPath,
693
+ "SELECT value FROM meta WHERE key = '0'"
694
+ );
695
+ if (!row) return void 0;
696
+ try {
697
+ const text = row.value.toString();
698
+ const json = /^(?:[0-9a-f]{2})+$/i.test(text) ? Buffer.from(text, "hex").toString("utf8") : text;
699
+ const name = JSON.parse(json).name;
700
+ return typeof name === "string" ? name : void 0;
701
+ } catch {
702
+ return void 0;
703
+ }
704
+ }
705
+ function readCursorIdeNameSlots(stateDbPath, id) {
706
+ const row = queryOne(
707
+ stateDbPath,
708
+ "SELECT json_extract(CAST(value AS TEXT), '$.name') AS name FROM cursorDiskKV WHERE key = ?",
709
+ `composerData:${id}`
710
+ );
711
+ return slotsFrom("cursor", [["toolTitle", row?.name]]);
712
+ }
713
+ function yamlScalar(text, key) {
714
+ const m = text.match(new RegExp(`^${key}:[ \\t]*(.*)$`, "m"));
715
+ const v = m?.[1].trim().replace(/^(["'])(.*)\1$/, "$2");
716
+ return v || void 0;
717
+ }
718
+ function readCopilotTitleSlots(sessionDir) {
719
+ const id = basename(sessionDir);
720
+ let yaml = "";
721
+ try {
722
+ yaml = readFileSync2(join3(sessionDir, "workspace.yaml"), "utf8");
723
+ } catch {
724
+ }
725
+ const name = yamlScalar(yaml, "name");
726
+ if (name) {
727
+ return slotsFrom("copilot", [
728
+ [yamlScalar(yaml, "user_named") === "true" ? "userTitle" : "toolTitle", name]
729
+ ]);
730
+ }
731
+ const row = queryOne(
732
+ join3(dirname2(dirname2(sessionDir)), "session-store.db"),
733
+ "SELECT summary FROM sessions WHERE id = ?",
734
+ id
735
+ );
736
+ return slotsFrom("copilot", [["toolTitle", row?.summary]]);
737
+ }
738
+ function findUp(start, hasStore, levels) {
739
+ let dir = start;
740
+ for (let i = 0; i < levels; i++) {
741
+ if (hasStore(dir)) return dir;
742
+ const parent = dirname2(dir);
743
+ if (parent === dir) break;
744
+ dir = parent;
745
+ }
746
+ return null;
747
+ }
748
+ function codexNameSlotsFor(rolloutPath, id) {
749
+ const home = findUp(
750
+ dirname2(rolloutPath),
751
+ (d) => ["session_index.jsonl", "history.jsonl", "state_5.sqlite"].some(
752
+ (f) => existsSync(join3(d, f))
753
+ ),
754
+ 6
755
+ );
756
+ return home ? readCodexNameSlots(home, id) : {};
757
+ }
758
+ var cursorStateDb;
759
+ function setCursorStateDb(path) {
760
+ cursorStateDb = path;
761
+ }
762
+ function cursorNameSlotsFor(transcriptPath, id) {
763
+ const home = findUp(dirname2(transcriptPath), (d) => existsSync(join3(d, "chats")), 6);
764
+ const cli = home ? readCursorCliNameSlots(join3(home, "chats"), id) : {};
765
+ if (cli.toolTitle || !cursorStateDb) return cli;
766
+ return { ...cli, ...readCursorIdeNameSlots(cursorStateDb, id) };
767
+ }
768
+ function copilotNameSlotsFor(eventsPath) {
769
+ return readCopilotTitleSlots(dirname2(eventsPath));
770
+ }
771
+ function nameStoreSlotsFor(provider, filePath, sessionId) {
772
+ switch (provider) {
773
+ case "codex-cli":
774
+ return codexNameSlotsFor(filePath, sessionId);
775
+ case "cursor":
776
+ return cursorNameSlotsFor(filePath, basename(filePath, ".jsonl"));
777
+ case "copilot":
778
+ return copilotNameSlotsFor(filePath);
779
+ default:
780
+ return {};
781
+ }
782
+ }
783
+
509
784
  // src/parser.ts
510
785
  import { createReadStream } from "fs";
511
- import { basename as basename2 } from "path";
786
+ import { basename as basename3 } from "path";
512
787
  import { createInterface } from "readline";
513
788
 
789
+ // src/persistent/claude-name-slots.ts
790
+ function userPromptText(entry) {
791
+ if (entry.isMeta || entry.isCompactSummary === true) return "";
792
+ const content = entry.message?.content;
793
+ if (typeof content === "string") return content;
794
+ if (!Array.isArray(content)) return "";
795
+ return content.map((b) => typeof b === "string" ? b : b?.type === "text" ? b.text : "").filter((t) => typeof t === "string" && t !== "").join(" ");
796
+ }
797
+ function applyClaudeNameEntry(slots, entry) {
798
+ const apply = (slot, raw) => applyNameCandidate(slots, slot, typeof raw === "string" ? raw : void 0, "claude-code");
799
+ if (entry.slug !== slots.slug) slots = apply("slug", entry.slug);
800
+ switch (entry.type) {
801
+ case "custom-title":
802
+ return apply("userTitle", entry.customTitle);
803
+ case "ai-title":
804
+ return apply("toolTitle", entry.aiTitle);
805
+ case "last-prompt":
806
+ return apply("lastPrompt", entry.lastPrompt);
807
+ case "user":
808
+ return slots.firstUserMessage === void 0 ? apply("firstUserMessage", userPromptText(entry)) : slots;
809
+ default:
810
+ return slots;
811
+ }
812
+ }
813
+
514
814
  // src/persistent/conversation-reducer.ts
515
815
  function initialConvState() {
516
816
  return {
517
817
  cwd: "",
518
818
  sessionId: "",
519
- sessionName: "",
819
+ nameSlots: {},
520
820
  latestTimestamp: "",
521
821
  lastPrompt: "",
522
822
  pendingToolUses: {},
@@ -526,7 +826,7 @@ function initialConvState() {
526
826
  function reduceConvLine(state, entry) {
527
827
  if (entry.cwd && !state.cwd) state.cwd = entry.cwd;
528
828
  if (entry.sessionId && !state.sessionId) state.sessionId = entry.sessionId;
529
- if (entry.slug && !state.sessionName) state.sessionName = entry.slug;
829
+ state.nameSlots = applyClaudeNameEntry(state.nameSlots, entry);
530
830
  if (entry.timestamp) {
531
831
  const ts = entry.timestamp;
532
832
  if (!state.latestTimestamp || ts > state.latestTimestamp) state.latestTimestamp = ts;
@@ -623,7 +923,7 @@ function applyTeamInfo(messages, state) {
623
923
  }
624
924
 
625
925
  // src/persistent/metadata-reducer.ts
626
- import { basename, dirname as dirname2, join as join3 } from "path";
926
+ import { basename as basename2, dirname as dirname3, join as join4 } from "path";
627
927
 
628
928
  // src/providers/provider.ts
629
929
  var CLAUDE_CODE_PROVIDER = "claude-code";
@@ -657,7 +957,7 @@ function providerMatches(stored, wanted) {
657
957
  function initialReducerState() {
658
958
  return {
659
959
  sessionId: "",
660
- sessionName: "",
960
+ nameSlots: {},
661
961
  latestTimestamp: "",
662
962
  cwd: "",
663
963
  teamName: "",
@@ -683,7 +983,7 @@ function initialReducerState() {
683
983
  function reduceLine(state, entry, tier) {
684
984
  if (entry.cwd && !state.cwd) state.cwd = entry.cwd;
685
985
  if (entry.sessionId && !state.sessionId) state.sessionId = entry.sessionId;
686
- if (entry.slug && !state.sessionName) state.sessionName = entry.slug;
986
+ state.nameSlots = applyClaudeNameEntry(state.nameSlots, entry);
687
987
  if (entry.teamName && !state.teamName) state.teamName = entry.teamName;
688
988
  if (entry.agentId && !state.agentId) state.agentId = entry.agentId;
689
989
  if (entry.isSidechain === true) state.isSidechain = true;
@@ -747,16 +1047,16 @@ function finalizeMeta(state, filePath, account, tier) {
747
1047
  const isSubagent = isSidechain || isSubagentPath;
748
1048
  let parentSessionId = null;
749
1049
  if (isSubagentPath) {
750
- const uuidDir = dirname2(dirname2(filePath));
751
- parentSessionId = join3(dirname2(uuidDir), `${basename(uuidDir)}.jsonl`);
1050
+ const uuidDir = dirname3(dirname3(filePath));
1051
+ parentSessionId = join4(dirname3(uuidDir), `${basename2(uuidDir)}.jsonl`);
752
1052
  }
753
1053
  const projectPath = state.cwd;
754
1054
  return {
755
1055
  id: filePath,
756
1056
  filePath,
757
1057
  provider: CLAUDE_CODE_PROVIDER,
758
- sessionId: state.sessionId || basename(filePath, ".jsonl"),
759
- sessionName: state.sessionName || deriveSessionNameFromFirstMessage(state.firstMessage),
1058
+ sessionId: state.sessionId || basename2(filePath, ".jsonl"),
1059
+ sessionName: resolveSessionName(state.nameSlots).name ?? "",
760
1060
  projectPath,
761
1061
  projectName: getShortProjectName(projectPath),
762
1062
  account,
@@ -782,44 +1082,11 @@ function finalizeMeta(state, filePath, account, tier) {
782
1082
  };
783
1083
  }
784
1084
  var SUBAGENT_PATH_RE = /[\\/]subagents[\\/]/;
785
- function deriveSessionNameFromFirstMessage(firstMessage) {
786
- const firstLine = firstMessage?.text.split("\n", 1)[0]?.trim() ?? "";
787
- return firstLine.slice(0, 80);
788
- }
789
1085
  function getShortProjectName(fullPath) {
790
1086
  const parts = fullPath.split("/").filter(Boolean);
791
1087
  return parts.slice(-3).join("/");
792
1088
  }
793
1089
 
794
- // src/tags.ts
795
- var SYSTEM_TAGS = [
796
- "system-reminder",
797
- "command-name",
798
- "command-message",
799
- "command-args",
800
- "ide_selection",
801
- "ide_opened_file",
802
- "local-command-stdout",
803
- "local-command-caveat",
804
- "retrieval_status",
805
- "task_id",
806
- "task_type",
807
- "task-id",
808
- "task-notification",
809
- "fast_mode_info",
810
- "persisted-output",
811
- "tool_use_error",
812
- "user-prompt-submit-hook",
813
- "thinking",
814
- "ask_user",
815
- "teammate-message"
816
- ];
817
- var SYSTEM_TAG_RE = new RegExp(`<(${SYSTEM_TAGS.join("|")})[^>]*>[\\s\\S]*?<\\/\\1>`, "g");
818
- var PASTED_CONTENT_RE = /<pasted_content id="[0-9a-f]{4}">([\s\S]*?)<\/pasted_content(?: id="[0-9a-f]{4}")?>/g;
819
- function cleanSystemTags(text) {
820
- return text.replace(SYSTEM_TAG_RE, "").replace(PASTED_CONTENT_RE, "$1").replace(/[^\S\n]+/g, " ").replace(/\n{3,}/g, "\n\n").trim();
821
- }
822
-
823
1090
  // src/parser.ts
824
1091
  async function parseMeta(filePath, account, tier, onEntry) {
825
1092
  const log = getLogger();
@@ -906,10 +1173,8 @@ async function parseConversation(filePath, account) {
906
1173
  filePath,
907
1174
  projectPath: state.cwd,
908
1175
  projectName: getShortProjectName2(state.cwd),
909
- sessionId: state.sessionId || basename2(filePath, ".jsonl"),
910
- sessionName: state.sessionName || deriveSessionNameFromFirstMessage(
911
- messages.find((m) => m.role === "user" && m.text && !m.isCompactSummary) ?? null
912
- ),
1176
+ sessionId: state.sessionId || basename3(filePath, ".jsonl"),
1177
+ sessionName: resolveSessionName(state.nameSlots).name ?? "",
913
1178
  messages,
914
1179
  fullText: textParts.join(" "),
915
1180
  timestamp: state.latestTimestamp || (/* @__PURE__ */ new Date()).toISOString(),
@@ -1015,7 +1280,7 @@ function getShortProjectName2(fullPath) {
1015
1280
  }
1016
1281
 
1017
1282
  // src/persistent/conversation-stream.ts
1018
- import { basename as basename3 } from "path";
1283
+ import { basename as basename4 } from "path";
1019
1284
 
1020
1285
  // src/persistent/paged-reader.ts
1021
1286
  import { createReadStream as createReadStream3 } from "fs";
@@ -1175,10 +1440,8 @@ function assemble(filePath, account, messages, fullText, turnDurations, state) {
1175
1440
  filePath,
1176
1441
  projectPath: state.cwd,
1177
1442
  projectName: getShortProjectName2(state.cwd),
1178
- sessionId: state.sessionId || basename3(filePath, ".jsonl"),
1179
- sessionName: state.sessionName || deriveSessionNameFromFirstMessage(
1180
- messages.find((m) => m.role === "user" && m.text && !m.isCompactSummary) ?? null
1181
- ),
1443
+ sessionId: state.sessionId || basename4(filePath, ".jsonl"),
1444
+ sessionName: resolveSessionName(state.nameSlots).name ?? "",
1182
1445
  messages,
1183
1446
  fullText,
1184
1447
  timestamp: state.latestTimestamp || (/* @__PURE__ */ new Date()).toISOString(),
@@ -1222,33 +1485,33 @@ async function extendConversation(previous, resume, filePath, account) {
1222
1485
 
1223
1486
  // src/persistent/cursor.ts
1224
1487
  import { createHash } from "crypto";
1225
- import { closeSync, openSync, readSync, statSync } from "fs";
1488
+ import { closeSync as closeSync2, openSync as openSync2, readSync as readSync2, statSync as statSync2 } from "fs";
1226
1489
  var FP_BYTES = 4096;
1227
1490
  function fingerprint(filePath, size) {
1228
1491
  const hash = createHash("sha1");
1229
1492
  hash.update(String(size));
1230
- const fd = openSync(filePath, "r");
1493
+ const fd = openSync2(filePath, "r");
1231
1494
  try {
1232
1495
  const head = Buffer.alloc(Math.min(FP_BYTES, size));
1233
1496
  if (head.length > 0) {
1234
- readSync(fd, head, 0, head.length, 0);
1497
+ readSync2(fd, head, 0, head.length, 0);
1235
1498
  hash.update(head);
1236
1499
  }
1237
1500
  if (size > FP_BYTES) {
1238
1501
  const tailLen = Math.min(FP_BYTES, size);
1239
1502
  const tail = Buffer.alloc(tailLen);
1240
- readSync(fd, tail, 0, tailLen, size - tailLen);
1503
+ readSync2(fd, tail, 0, tailLen, size - tailLen);
1241
1504
  hash.update(tail);
1242
1505
  }
1243
1506
  } finally {
1244
- closeSync(fd);
1507
+ closeSync2(fd);
1245
1508
  }
1246
1509
  return hash.digest("hex");
1247
1510
  }
1248
1511
  function classify(filePath, existing) {
1249
1512
  let stat6;
1250
1513
  try {
1251
- const s = statSync(filePath);
1514
+ const s = statSync2(filePath);
1252
1515
  stat6 = { size: s.size, mtimeMs: s.mtimeMs };
1253
1516
  } catch {
1254
1517
  return { change: "vanished" };
@@ -1276,13 +1539,13 @@ function classify(filePath, existing) {
1276
1539
  }
1277
1540
 
1278
1541
  // src/persistent/index-engine.ts
1279
- import { statSync as statSync4 } from "fs";
1542
+ import { statSync as statSync5 } from "fs";
1280
1543
 
1281
1544
  // src/providers/codex-cli.ts
1282
1545
  import fg2 from "fast-glob";
1283
1546
  import { createReadStream as createReadStream4 } from "fs";
1284
1547
  import { stat as stat2 } from "fs/promises";
1285
- import { basename as basename4 } from "path";
1548
+ import { basename as basename5 } from "path";
1286
1549
  import { createInterface as createInterface2 } from "readline";
1287
1550
  var CodexCliProvider = class {
1288
1551
  name = CODEX_CLI_PROVIDER;
@@ -1340,6 +1603,7 @@ var CodexCliProvider = class {
1340
1603
  isSubagent: false,
1341
1604
  parentSessionUuid: null,
1342
1605
  firstUser: null,
1606
+ nameSlots: {},
1343
1607
  lastUser: null,
1344
1608
  lastAssistant: null,
1345
1609
  toolNames: [],
@@ -1502,6 +1766,7 @@ function reduceCodexEntry(acc, entry, tier) {
1502
1766
  const snapshot = { text: text.slice(0, 200), timestamp: ts };
1503
1767
  if (sender === "user") {
1504
1768
  if (!acc.firstUser) acc.firstUser = snapshot;
1769
+ acc.nameSlots = applyNameCandidate(acc.nameSlots, "firstUserMessage", text, CODEX_CLI_PROVIDER);
1505
1770
  acc.lastUser = snapshot;
1506
1771
  } else {
1507
1772
  acc.lastAssistant = snapshot;
@@ -1519,7 +1784,7 @@ function reduceCodexEntry(acc, entry, tier) {
1519
1784
  }
1520
1785
  function finalizeCodexMeta(acc, filePath, account, tier) {
1521
1786
  if (acc.messageCount === 0) return null;
1522
- const sessionId = acc.sessionId || basename4(filePath, ".jsonl");
1787
+ const sessionId = acc.sessionId || basename5(filePath, ".jsonl");
1523
1788
  const projectPath = acc.cwd;
1524
1789
  const kind = acc.lastAssistant === null && acc.toolNames.length > 0 ? "task" : "conversation";
1525
1790
  return {
@@ -1529,10 +1794,7 @@ function finalizeCodexMeta(acc, filePath, account, tier) {
1529
1794
  kind,
1530
1795
  externalSessionId: acc.sessionId || void 0,
1531
1796
  sessionId,
1532
- // Mirrors the Claude reducer: a rollout carries no slug, so the opening turn
1533
- // is the only human-readable name source. Only useful because the injected
1534
- // AGENTS.md turn is skipped above — otherwise every title would be that blob.
1535
- sessionName: deriveSessionNameFromFirstMessage(acc.firstUser),
1797
+ sessionName: resolveSessionName({ ...acc.nameSlots, ...codexNameSlotsFor(filePath, acc.sessionId) }).name ?? "",
1536
1798
  projectPath,
1537
1799
  projectName: getShortProjectName3(projectPath),
1538
1800
  account,
@@ -1555,10 +1817,6 @@ function finalizeCodexMeta(acc, filePath, account, tier) {
1555
1817
  lastPrompt: acc.lastUser?.text || void 0
1556
1818
  };
1557
1819
  }
1558
- function isCodexInjectedContext(text) {
1559
- if (text.startsWith("# AGENTS.md") || text.includes("<INSTRUCTIONS>")) return true;
1560
- return text.startsWith("<permissions instructions>") || text.includes("Filesystem sandboxing defines");
1561
- }
1562
1820
  function getShortProjectName3(fullPath) {
1563
1821
  return fullPath.split("/").filter(Boolean).slice(-3).join("/");
1564
1822
  }
@@ -1581,6 +1839,7 @@ async function parseCodexConversation(filePath, account) {
1581
1839
  let cwd = "";
1582
1840
  let latestTimestamp = "";
1583
1841
  let lastUserText = "";
1842
+ let nameSlots = {};
1584
1843
  const rl = createInterface2({ input: createReadStream4(filePath), crlfDelay: Infinity });
1585
1844
  try {
1586
1845
  for await (const line of rl) {
@@ -1605,7 +1864,15 @@ async function parseCodexConversation(filePath, account) {
1605
1864
  messages.push(message);
1606
1865
  if (!message.text) continue;
1607
1866
  textParts.push(message.text);
1608
- if (message.role === "user") lastUserText = message.text;
1867
+ if (message.role === "user") {
1868
+ lastUserText = message.text;
1869
+ nameSlots = applyNameCandidate(
1870
+ nameSlots,
1871
+ "firstUserMessage",
1872
+ message.text,
1873
+ CODEX_CLI_PROVIDER
1874
+ );
1875
+ }
1609
1876
  }
1610
1877
  } catch (err) {
1611
1878
  log.warn({ filePath, err }, "parseCodexConversation: read failed");
@@ -1617,8 +1884,8 @@ async function parseCodexConversation(filePath, account) {
1617
1884
  filePath,
1618
1885
  projectPath: cwd,
1619
1886
  projectName: getShortProjectName3(cwd),
1620
- sessionId: sessionId || basename4(filePath, ".jsonl"),
1621
- sessionName: "",
1887
+ sessionId: sessionId || basename5(filePath, ".jsonl"),
1888
+ sessionName: resolveSessionName({ ...nameSlots, ...codexNameSlotsFor(filePath, sessionId) }).name ?? "",
1622
1889
  messages,
1623
1890
  fullText: textParts.join(" "),
1624
1891
  timestamp: latestTimestamp || (/* @__PURE__ */ new Date()).toISOString(),
@@ -1630,9 +1897,9 @@ async function parseCodexConversation(filePath, account) {
1630
1897
 
1631
1898
  // src/providers/copilot.ts
1632
1899
  import fg3 from "fast-glob";
1633
- import { createReadStream as createReadStream5, statSync as statSync2 } from "fs";
1900
+ import { createReadStream as createReadStream5, statSync as statSync3 } from "fs";
1634
1901
  import { stat as stat3 } from "fs/promises";
1635
- import { basename as basename5, dirname as dirname3 } from "path";
1902
+ import { basename as basename6, dirname as dirname4 } from "path";
1636
1903
  import { createInterface as createInterface3 } from "readline";
1637
1904
  var SESSION_START = "session.start";
1638
1905
  var USER_MESSAGE = "user.message";
@@ -1686,6 +1953,7 @@ var CopilotProvider = class {
1686
1953
  messageCount: 0,
1687
1954
  lastMessageSender: "user",
1688
1955
  firstUser: null,
1956
+ nameSlots: {},
1689
1957
  lastUser: null,
1690
1958
  lastAssistant: null,
1691
1959
  toolNames: [],
@@ -1793,6 +2061,7 @@ function reduceCopilotEntry(acc, entry, tier) {
1793
2061
  const snapshot = { text: text.slice(0, 200), timestamp };
1794
2062
  if (role === "user") {
1795
2063
  if (!acc.firstUser) acc.firstUser = snapshot;
2064
+ acc.nameSlots = applyNameCandidate(acc.nameSlots, "firstUserMessage", text, COPILOT_PROVIDER);
1796
2065
  acc.lastUser = snapshot;
1797
2066
  } else {
1798
2067
  acc.lastAssistant = snapshot;
@@ -1819,7 +2088,7 @@ function finalizeCopilotMeta(acc, filePath, account, tier) {
1819
2088
  kind,
1820
2089
  externalSessionId: sessionId,
1821
2090
  sessionId,
1822
- sessionName: deriveSessionNameFromFirstMessage(acc.firstUser),
2091
+ sessionName: resolveSessionName({ ...acc.nameSlots, ...copilotNameSlotsFor(filePath) }).name ?? "",
1823
2092
  projectPath: acc.cwd,
1824
2093
  projectName: getShortProjectName4(acc.cwd),
1825
2094
  account,
@@ -1841,14 +2110,14 @@ function finalizeCopilotMeta(acc, filePath, account, tier) {
1841
2110
  };
1842
2111
  }
1843
2112
  function sessionIdFromPath(filePath) {
1844
- return basename5(dirname3(filePath));
2113
+ return basename6(dirname4(filePath));
1845
2114
  }
1846
2115
  function getShortProjectName4(fullPath) {
1847
2116
  return fullPath.split(/[/\\]/).filter(Boolean).slice(-3).join("/");
1848
2117
  }
1849
2118
  function fileMtimeIso(filePath) {
1850
2119
  try {
1851
- return new Date(statSync2(filePath).mtimeMs).toISOString();
2120
+ return new Date(statSync3(filePath).mtimeMs).toISOString();
1852
2121
  } catch {
1853
2122
  return (/* @__PURE__ */ new Date()).toISOString();
1854
2123
  }
@@ -1861,6 +2130,7 @@ async function parseCopilotConversation(filePath, account) {
1861
2130
  let cwd = "";
1862
2131
  let latestTimestamp = "";
1863
2132
  let lastUserText = "";
2133
+ let nameSlots = {};
1864
2134
  const rl = createInterface3({ input: createReadStream5(filePath), crlfDelay: Infinity });
1865
2135
  try {
1866
2136
  for await (const line of rl) {
@@ -1885,7 +2155,15 @@ async function parseCopilotConversation(filePath, account) {
1885
2155
  messages.push(message);
1886
2156
  if (!message.text) continue;
1887
2157
  textParts.push(message.text);
1888
- if (message.role === "user") lastUserText = message.text;
2158
+ if (message.role === "user") {
2159
+ lastUserText = message.text;
2160
+ nameSlots = applyNameCandidate(
2161
+ nameSlots,
2162
+ "firstUserMessage",
2163
+ message.text,
2164
+ COPILOT_PROVIDER
2165
+ );
2166
+ }
1889
2167
  }
1890
2168
  } catch (err) {
1891
2169
  log.warn({ filePath, err }, "parseCopilotConversation: read failed");
@@ -1898,7 +2176,7 @@ async function parseCopilotConversation(filePath, account) {
1898
2176
  projectPath: cwd,
1899
2177
  projectName: getShortProjectName4(cwd),
1900
2178
  sessionId: sessionId || sessionIdFromPath(filePath),
1901
- sessionName: "",
2179
+ sessionName: resolveSessionName({ ...nameSlots, ...copilotNameSlotsFor(filePath) }).name ?? "",
1902
2180
  messages,
1903
2181
  fullText: textParts.join(" "),
1904
2182
  timestamp: latestTimestamp || fileMtimeIso(filePath),
@@ -1911,9 +2189,9 @@ async function parseCopilotConversation(filePath, account) {
1911
2189
  // src/providers/cursor.ts
1912
2190
  import { createHash as createHash2 } from "crypto";
1913
2191
  import fg4 from "fast-glob";
1914
- import { createReadStream as createReadStream6, existsSync, statSync as statSync3 } from "fs";
2192
+ import { createReadStream as createReadStream6, existsSync as existsSync2, statSync as statSync4 } from "fs";
1915
2193
  import { stat as stat4 } from "fs/promises";
1916
- import { basename as basename6, dirname as dirname4, join as join4, sep as sep2 } from "path";
2194
+ import { basename as basename7, dirname as dirname5, join as join5, sep as sep2 } from "path";
1917
2195
  import { createInterface as createInterface4 } from "readline";
1918
2196
  var TIMESTAMP_RE = /<timestamp>\s*([\s\S]*?)\s*<\/timestamp>/;
1919
2197
  var USER_QUERY_RE = /<user_query>\s*([\s\S]*?)\s*<\/user_query>/;
@@ -1972,6 +2250,7 @@ var CursorProvider = class {
1972
2250
  parentSessionUuid: null,
1973
2251
  subagentId: null,
1974
2252
  firstUser: null,
2253
+ nameSlots: {},
1975
2254
  lastUser: null,
1976
2255
  lastAssistant: null,
1977
2256
  isImportedFromClaude: false,
@@ -2038,6 +2317,15 @@ function noteImportProvenance(acc, entry, text) {
2038
2317
  acc.isImportedFromCodex = true;
2039
2318
  }
2040
2319
  }
2320
+ function cursorUserQuery(content) {
2321
+ const texts = typeof content === "string" ? [content] : Array.isArray(content) ? content : [];
2322
+ for (const item of texts) {
2323
+ const text = typeof item === "string" ? item : item?.text;
2324
+ const query = typeof text === "string" ? text.match(USER_QUERY_RE) : null;
2325
+ if (query) return query[1];
2326
+ }
2327
+ return void 0;
2328
+ }
2041
2329
  function unwrapCursorUserText(text) {
2042
2330
  const query = text.match(USER_QUERY_RE);
2043
2331
  const body = query ? query[1] : text.replace(TIMESTAMP_RE, "");
@@ -2175,6 +2463,14 @@ function reduceCursorEntry(acc, entry, tier) {
2175
2463
  collectCursorToolNames(content, acc.toolNames);
2176
2464
  const text = textHint;
2177
2465
  if (!text) return;
2466
+ if (entry.role === "user") {
2467
+ acc.nameSlots = applyNameCandidate(
2468
+ acc.nameSlots,
2469
+ "firstUserMessage",
2470
+ cursorUserQuery(content),
2471
+ CURSOR_PROVIDER
2472
+ );
2473
+ }
2178
2474
  foldCursorMessage(acc, entry.role, text, firstTimestampHint(content), tier);
2179
2475
  return;
2180
2476
  }
@@ -2193,7 +2489,7 @@ function reduceCursorEntry(acc, entry, tier) {
2193
2489
  }
2194
2490
  function finalizeCursorMeta(acc, filePath, account, tier) {
2195
2491
  if (acc.messageCount === 0) return null;
2196
- const sessionId = basename6(filePath, ".jsonl");
2492
+ const sessionId = basename7(filePath, ".jsonl");
2197
2493
  const isSubagent = SUBAGENT_PATH_RE2.test(filePath);
2198
2494
  const parent = isSubagent ? parentFromSubagentPath(filePath) : null;
2199
2495
  const { projectPath, projectName } = projectFromCursorPath(filePath);
@@ -2206,7 +2502,7 @@ function finalizeCursorMeta(acc, filePath, account, tier) {
2206
2502
  kind,
2207
2503
  externalSessionId: sessionId,
2208
2504
  sessionId,
2209
- sessionName: deriveSessionNameFromFirstMessage(acc.firstUser),
2505
+ sessionName: resolveSessionName({ ...acc.nameSlots, ...cursorNameSlotsFor(filePath, sessionId) }).name ?? "",
2210
2506
  projectPath,
2211
2507
  projectName,
2212
2508
  account,
@@ -2232,20 +2528,20 @@ function finalizeCursorMeta(acc, filePath, account, tier) {
2232
2528
  };
2233
2529
  }
2234
2530
  function parentFromSubagentPath(filePath) {
2235
- const subagentsDir = dirname4(filePath);
2236
- const parentDir = dirname4(subagentsDir);
2237
- const parentSessionUuid = basename6(parentDir);
2531
+ const subagentsDir = dirname5(filePath);
2532
+ const parentDir = dirname5(subagentsDir);
2533
+ const parentSessionUuid = basename7(parentDir);
2238
2534
  if (!parentSessionUuid) return null;
2239
2535
  return {
2240
2536
  parentSessionUuid,
2241
- parentFilePath: canonicalPath(join4(parentDir, `${parentSessionUuid}.jsonl`))
2537
+ parentFilePath: canonicalPath(join5(parentDir, `${parentSessionUuid}.jsonl`))
2242
2538
  };
2243
2539
  }
2244
2540
  function projectFromCursorPath(filePath) {
2245
2541
  const parts = filePath.split(/[/\\]/);
2246
2542
  const idx = parts.lastIndexOf("agent-transcripts");
2247
- const cursorProjectDir = idx > 0 ? parts.slice(0, idx).join(sep2) : dirname4(dirname4(filePath));
2248
- const slug = basename6(cursorProjectDir);
2543
+ const cursorProjectDir = idx > 0 ? parts.slice(0, idx).join(sep2) : dirname5(dirname5(filePath));
2544
+ const slug = basename7(cursorProjectDir);
2249
2545
  const decoded = decodeCursorProjectSlug(slug);
2250
2546
  const projectPath = decoded ?? cursorProjectDir;
2251
2547
  return { projectPath, projectName: getShortProjectName5(projectPath) || slug };
@@ -2259,7 +2555,7 @@ function decodeCursorProjectSlug(slug) {
2259
2555
  let i = 0;
2260
2556
  if (rooted && segments[0] === "Users") {
2261
2557
  const users = `${sep2}Users`;
2262
- if (!existsSync(users)) return null;
2558
+ if (!existsSync2(users)) return null;
2263
2559
  acc = users;
2264
2560
  i = 1;
2265
2561
  }
@@ -2267,9 +2563,9 @@ function decodeCursorProjectSlug(slug) {
2267
2563
  let found = null;
2268
2564
  let next = i + 1;
2269
2565
  for (let j = segments.length; j > i; j--) {
2270
- const candidate = join4(acc, segments.slice(i, j).join("-"));
2566
+ const candidate = join5(acc, segments.slice(i, j).join("-"));
2271
2567
  try {
2272
- if (existsSync(candidate) && statSync3(candidate).isDirectory()) {
2568
+ if (existsSync2(candidate) && statSync4(candidate).isDirectory()) {
2273
2569
  found = candidate;
2274
2570
  next = j;
2275
2571
  break;
@@ -2288,17 +2584,26 @@ function getShortProjectName5(fullPath) {
2288
2584
  }
2289
2585
  function fileMtimeIso2(filePath) {
2290
2586
  try {
2291
- return new Date(statSync3(filePath).mtimeMs).toISOString();
2587
+ return new Date(statSync4(filePath).mtimeMs).toISOString();
2292
2588
  } catch {
2293
2589
  return (/* @__PURE__ */ new Date()).toISOString();
2294
2590
  }
2295
2591
  }
2592
+ function cursorLineContent(line) {
2593
+ try {
2594
+ const entry = JSON.parse(line);
2595
+ return entry.message?.content ?? entry.content;
2596
+ } catch {
2597
+ return void 0;
2598
+ }
2599
+ }
2296
2600
  async function parseCursorConversation(filePath, account) {
2297
2601
  const log = getLogger();
2298
2602
  const messages = [];
2299
2603
  const textParts = [];
2300
2604
  let latestTimestamp = "";
2301
2605
  let lastUserText = "";
2606
+ let nameSlots = {};
2302
2607
  const rl = createInterface4({ input: createReadStream6(filePath), crlfDelay: Infinity });
2303
2608
  try {
2304
2609
  for await (const line of rl) {
@@ -2310,7 +2615,17 @@ async function parseCursorConversation(filePath, account) {
2310
2615
  messages.push(message);
2311
2616
  if (!message.text) continue;
2312
2617
  textParts.push(message.text);
2313
- if (message.role === "user") lastUserText = message.text;
2618
+ if (message.role === "user") {
2619
+ lastUserText = message.text;
2620
+ if (nameSlots.firstUserMessage === void 0) {
2621
+ nameSlots = applyNameCandidate(
2622
+ nameSlots,
2623
+ "firstUserMessage",
2624
+ cursorUserQuery(cursorLineContent(line)),
2625
+ CURSOR_PROVIDER
2626
+ );
2627
+ }
2628
+ }
2314
2629
  }
2315
2630
  } catch (err) {
2316
2631
  log.warn({ filePath, err }, "parseCursorConversation: read failed");
@@ -2318,14 +2633,14 @@ async function parseCursorConversation(filePath, account) {
2318
2633
  }
2319
2634
  if (messages.length === 0) return null;
2320
2635
  const { projectPath, projectName } = projectFromCursorPath(filePath);
2321
- const sessionId = basename6(filePath, ".jsonl");
2636
+ const sessionId = basename7(filePath, ".jsonl");
2322
2637
  return {
2323
2638
  id: filePath,
2324
2639
  filePath,
2325
2640
  projectPath,
2326
2641
  projectName,
2327
2642
  sessionId,
2328
- sessionName: "",
2643
+ sessionName: resolveSessionName({ ...nameSlots, ...cursorNameSlotsFor(filePath, sessionId) }).name ?? "",
2329
2644
  messages,
2330
2645
  fullText: textParts.join(" "),
2331
2646
  timestamp: latestTimestamp || fileMtimeIso2(filePath),
@@ -2338,7 +2653,7 @@ async function parseCursorConversation(filePath, account) {
2338
2653
  // src/providers/parse.ts
2339
2654
  import { createReadStream as createReadStream7 } from "fs";
2340
2655
  import { createInterface as createInterface5 } from "readline";
2341
- async function parseMetaWithProvider(provider, filePath, account, tier, onEntry) {
2656
+ async function parseMetaWithProvider(provider, filePath, account, tier, onEntry, onAccumulator) {
2342
2657
  const log = getLogger();
2343
2658
  const acc = provider.createEmptyAccumulator();
2344
2659
  const rl = createInterface5({
@@ -2365,6 +2680,7 @@ async function parseMetaWithProvider(provider, filePath, account, tier, onEntry)
2365
2680
  log.warn({ filePath, provider: provider.name, err }, "provider parse: read failed");
2366
2681
  return null;
2367
2682
  }
2683
+ onAccumulator?.(acc);
2368
2684
  return provider.finalize(acc, filePath, account, tier);
2369
2685
  }
2370
2686
 
@@ -2565,12 +2881,12 @@ function resolveTier(tierName, customTiers) {
2565
2881
  }
2566
2882
 
2567
2883
  // src/persistent/db.ts
2568
- import Database from "better-sqlite3";
2884
+ import Database2 from "better-sqlite3";
2569
2885
  import { mkdirSync } from "fs";
2570
- import { dirname as dirname5 } from "path";
2886
+ import { dirname as dirname6 } from "path";
2571
2887
 
2572
2888
  // src/persistent/schema.ts
2573
- var SCHEMA_VERSION = 10;
2889
+ var SCHEMA_VERSION = 11;
2574
2890
  var SCHEMA_SQL = `
2575
2891
  CREATE TABLE IF NOT EXISTS conversation_files (
2576
2892
  id INTEGER PRIMARY KEY AUTOINCREMENT,
@@ -2616,6 +2932,9 @@ CREATE TABLE IF NOT EXISTS conversations (
2616
2932
  external_session_id TEXT,
2617
2933
  session_id TEXT NOT NULL,
2618
2934
  session_name TEXT,
2935
+ -- JSON NameSlots the name was resolved from; lets a side-store change
2936
+ -- re-resolve the name without reparsing the transcript.
2937
+ name_slots TEXT,
2619
2938
 
2620
2939
  project_path TEXT,
2621
2940
  project_name TEXT,
@@ -2878,6 +3197,27 @@ function runMigrations(db) {
2878
3197
  db.exec(`UPDATE conversation_files SET ${assignments.join(", ")}`);
2879
3198
  }
2880
3199
  }
3200
+ if (current >= 1 && current < 11 && tableExists(db, "conversations")) {
3201
+ if (tableExists(db, "message_checkpoints")) db.exec("DELETE FROM message_checkpoints");
3202
+ if (!hasColumn(db, "conversations", "name_slots")) {
3203
+ db.exec("ALTER TABLE conversations ADD COLUMN name_slots TEXT");
3204
+ }
3205
+ if (tableExists(db, "conversation_files")) {
3206
+ const assignments = [];
3207
+ if (hasColumn(db, "conversation_files", "last_indexed_offset")) {
3208
+ assignments.push("last_indexed_offset = 0");
3209
+ }
3210
+ if (hasColumn(db, "conversation_files", "last_indexed_line")) {
3211
+ assignments.push("last_indexed_line = 0");
3212
+ }
3213
+ if (hasColumn(db, "conversation_files", "reducer_state")) {
3214
+ assignments.push("reducer_state = NULL");
3215
+ }
3216
+ if (assignments.length > 0) {
3217
+ db.exec(`UPDATE conversation_files SET ${assignments.join(", ")}`);
3218
+ }
3219
+ }
3220
+ }
2881
3221
  db.exec(SCHEMA_SQL);
2882
3222
  db.pragma(`user_version = ${SCHEMA_VERSION}`);
2883
3223
  }
@@ -2892,11 +3232,11 @@ function hasColumn(db, table, column) {
2892
3232
  // src/persistent/db.ts
2893
3233
  function openDatabase(dbPath) {
2894
3234
  if (dbPath !== ":memory:") {
2895
- mkdirSync(dirname5(dbPath), { recursive: true });
3235
+ mkdirSync(dirname6(dbPath), { recursive: true });
2896
3236
  }
2897
3237
  let db;
2898
3238
  try {
2899
- db = new Database(dbPath);
3239
+ db = new Database2(dbPath);
2900
3240
  } catch (err) {
2901
3241
  if (isNativeBindingFailure(err)) throw nativeBindingError(err, dbPath);
2902
3242
  throw err;
@@ -2937,7 +3277,7 @@ function nativeBindingError(err, dbPath) {
2937
3277
 
2938
3278
  // src/persistent/dir-watermark.ts
2939
3279
  import { readdir, stat as stat5 } from "fs/promises";
2940
- import { dirname as dirname6, join as join5 } from "path";
3280
+ import { dirname as dirname7, join as join6 } from "path";
2941
3281
  var FULL_RECONCILE_EVERY_N_SCANS = 20;
2942
3282
  async function discoverJsonlFilesGated(dirs, files, scannedDirs, options = {}) {
2943
3283
  const log = getLogger();
@@ -3008,10 +3348,10 @@ async function resolveProjectDirs(projectsDir, scannedDirs) {
3008
3348
  return { entries, commitRoot: { mtimeMs: rootStat.mtimeMs } };
3009
3349
  }
3010
3350
  function dirnameOf(filePath) {
3011
- return dirname6(filePath);
3351
+ return dirname7(filePath);
3012
3352
  }
3013
3353
  function joinPath(dir, name) {
3014
- return join5(dir, name);
3354
+ return join6(dir, name);
3015
3355
  }
3016
3356
 
3017
3357
  // src/persistent/repositories/checkpoints.repo.ts
@@ -3091,7 +3431,7 @@ function toCheckpoint(row) {
3091
3431
  }
3092
3432
 
3093
3433
  // src/persistent/repositories/conversation-files.repo.ts
3094
- import { basename as basename7, dirname as dirname7 } from "path";
3434
+ import { basename as basename8, dirname as dirname8 } from "path";
3095
3435
  var ConversationFilesRepo = class {
3096
3436
  constructor(db) {
3097
3437
  this.db = db;
@@ -3114,7 +3454,7 @@ var ConversationFilesRepo = class {
3114
3454
  const info = this.db.prepare(
3115
3455
  `INSERT INTO conversation_files (absolute_path, parent_dir, file_name, account)
3116
3456
  VALUES (?, ?, ?, ?)`
3117
- ).run(canonical, dirname7(canonical), basename7(canonical), account);
3457
+ ).run(canonical, dirname8(canonical), basename8(canonical), account);
3118
3458
  return Number(info.lastInsertRowid);
3119
3459
  }
3120
3460
  // Advance the cursor + persisted reducer state after a successful index pass.
@@ -3222,7 +3562,7 @@ var ConversationsRepo = class {
3222
3562
  db;
3223
3563
  // Upsert by file_id (1 file = 1 conversation). Keyed on the unique file_id so
3224
3564
  // a re-index overwrites the prior summary in place.
3225
- upsert(fileId, meta, pageMessageCount = meta.messageCount) {
3565
+ upsert(fileId, meta, pageMessageCount = meta.messageCount, nameSlots) {
3226
3566
  this.db.prepare(
3227
3567
  `INSERT INTO conversations (
3228
3568
  file_id, source_path, provider, kind, external_session_id,
@@ -3233,7 +3573,7 @@ var ConversationsRepo = class {
3233
3573
  model, is_subagent, parent_session_id, subagent_id, parent_session_uuid,
3234
3574
  is_teammate, team_name, tool_names_json,
3235
3575
  last_prompt, is_imported_from_claude, is_imported_from_codex,
3236
- is_imported_from_cursor, status, updated_at
3576
+ is_imported_from_cursor, name_slots, status, updated_at
3237
3577
  ) VALUES (
3238
3578
  @file_id, @source_path, @provider, @kind, @external_session_id,
3239
3579
  @session_id, @session_name, @project_path, @project_name,
@@ -3245,7 +3585,7 @@ var ConversationsRepo = class {
3245
3585
  @model, @is_subagent, @parent_session_id, @subagent_id, @parent_session_uuid,
3246
3586
  @is_teammate, @team_name, @tool_names_json,
3247
3587
  @last_prompt, @is_imported_from_claude, @is_imported_from_codex,
3248
- @is_imported_from_cursor, 'active', CURRENT_TIMESTAMP
3588
+ @is_imported_from_cursor, @name_slots, 'active', CURRENT_TIMESTAMP
3249
3589
  )
3250
3590
  ON CONFLICT(file_id) DO UPDATE SET
3251
3591
  source_path = excluded.source_path,
@@ -3280,6 +3620,7 @@ var ConversationsRepo = class {
3280
3620
  is_imported_from_claude = excluded.is_imported_from_claude,
3281
3621
  is_imported_from_codex = excluded.is_imported_from_codex,
3282
3622
  is_imported_from_cursor = excluded.is_imported_from_cursor,
3623
+ name_slots = excluded.name_slots,
3283
3624
  status = 'active',
3284
3625
  index_seq = (SELECT COALESCE(MAX(index_seq), 0) + 1 FROM conversations),
3285
3626
  updated_at = CURRENT_TIMESTAMP`
@@ -3319,7 +3660,8 @@ var ConversationsRepo = class {
3319
3660
  last_prompt: meta.lastPrompt ?? null,
3320
3661
  is_imported_from_claude: meta.isImportedFromClaude ? 1 : 0,
3321
3662
  is_imported_from_codex: meta.isImportedFromCodex ? 1 : 0,
3322
- is_imported_from_cursor: meta.isImportedFromCursor ? 1 : 0
3663
+ is_imported_from_cursor: meta.isImportedFromCursor ? 1 : 0,
3664
+ name_slots: nameSlots ? JSON.stringify(nameSlots) : null
3323
3665
  });
3324
3666
  }
3325
3667
  getBySourcePath(sourcePath) {
@@ -3568,7 +3910,7 @@ var ScannedDirsRepo = class {
3568
3910
  };
3569
3911
 
3570
3912
  // src/persistent/sidecar.ts
3571
- import { readFileSync as readFileSync2, writeFileSync } from "fs";
3913
+ import { readFileSync as readFileSync3, writeFileSync } from "fs";
3572
3914
  var SIDECAR_VERSION = 1;
3573
3915
  function sidecarPath(jsonlPath) {
3574
3916
  return `${jsonlPath}.idx.json`;
@@ -3733,13 +4075,18 @@ var PersistentEngine = class {
3733
4075
  const tier = resolveTier(tierName, customTiers);
3734
4076
  const filePath = canonicalPath(rawFilePath);
3735
4077
  const existing = this.files.getByPath(filePath);
3736
- const { change, stat: stat6 } = classify(filePath, existing);
4078
+ const classified = classify(filePath, existing);
4079
+ const stat6 = classified.stat;
4080
+ let change = classified.change;
3737
4081
  if (change === "vanished" || !stat6) {
3738
4082
  this.markDeleted(filePath);
3739
4083
  return { meta: null, change: "vanished" };
3740
4084
  }
3741
4085
  if (change === "unchanged" && !force) {
3742
- return { meta: this.conversations.getBySourcePath(filePath), change };
4086
+ const meta2 = this.conversations.getBySourcePath(filePath);
4087
+ const sideStoresMoved = provider && provider.name !== CLAUDE_CODE_PROVIDER && meta2 && JSON.stringify(nameStoreSlotsFor(provider.name, filePath, meta2.sessionId)) !== existing?.reducer_state;
4088
+ if (!sideStoresMoved) return { meta: meta2, change };
4089
+ change = "reindex";
3743
4090
  }
3744
4091
  if (provider && provider.name !== CLAUDE_CODE_PROVIDER) {
3745
4092
  const meta2 = await this.indexFileWithProvider(
@@ -3778,7 +4125,7 @@ var PersistentEngine = class {
3778
4125
  const base = resume ? this.fts.readDocument(fileId) ?? emptySearchDocument() : emptySearchDocument();
3779
4126
  const searchDoc = appendSearchDelta(base, searchDelta);
3780
4127
  const upsert = this.db.transaction(() => {
3781
- this.conversations.upsert(fileId, meta, state.pageMessageCount);
4128
+ this.conversations.upsert(fileId, meta, state.pageMessageCount, state.nameSlots);
3782
4129
  if (!this.fts.isCurrent(fileId, meta, searchDoc)) {
3783
4130
  this.fts.upsert(fileId, meta, searchDoc);
3784
4131
  }
@@ -3821,13 +4168,23 @@ var PersistentEngine = class {
3821
4168
  // provider's reducer/finalize, then the same upsert + FTS write + cursor bump
3822
4169
  // the Threadbase path uses. The cursor records size/mtime (and offset = size)
3823
4170
  // so the next pass classifies an unchanged file as "unchanged" and skips it;
3824
- // any change reparses from 0 again. No reducer_state is persisted.
4171
+ // any change reparses from 0 again. reducer_state holds the side-store name slots, not a fold.
3825
4172
  async indexFileWithProvider(provider, filePath, account, tier, stat6, resolveGitBranch) {
3826
4173
  const log = getLogger();
3827
4174
  let searchDoc = emptySearchDocument();
3828
- const meta = await parseMetaWithProvider(provider, filePath, account, tier, (entry) => {
3829
- searchDoc = appendSearchDelta(searchDoc, extractSearchDelta(entry));
3830
- });
4175
+ let transcriptSlots = {};
4176
+ const meta = await parseMetaWithProvider(
4177
+ provider,
4178
+ filePath,
4179
+ account,
4180
+ tier,
4181
+ (entry) => {
4182
+ searchDoc = appendSearchDelta(searchDoc, extractSearchDelta(entry));
4183
+ },
4184
+ (acc) => {
4185
+ transcriptSlots = acc.nameSlots ?? {};
4186
+ }
4187
+ );
3831
4188
  if (!meta) {
3832
4189
  this.markDeleted(filePath);
3833
4190
  return null;
@@ -3835,10 +4192,14 @@ var PersistentEngine = class {
3835
4192
  if (meta.gitBranch === null && meta.projectPath) {
3836
4193
  meta.gitBranch = resolveGitBranch(meta.projectPath);
3837
4194
  }
4195
+ const sideSlots = nameStoreSlotsFor(provider.name, filePath, meta.sessionId);
3838
4196
  const fp = stat6.size > 0 ? fingerprint(filePath, stat6.size) : null;
3839
4197
  const fileId = this.files.ensure(filePath, account);
3840
4198
  const upsert = this.db.transaction(() => {
3841
- this.conversations.upsert(fileId, meta, meta.messageCount);
4199
+ this.conversations.upsert(fileId, meta, meta.messageCount, {
4200
+ ...transcriptSlots,
4201
+ ...sideSlots
4202
+ });
3842
4203
  if (!this.fts.isCurrent(fileId, meta, searchDoc)) {
3843
4204
  this.fts.upsert(fileId, meta, searchDoc);
3844
4205
  }
@@ -3850,7 +4211,9 @@ var PersistentEngine = class {
3850
4211
  // can classify it "unchanged"); no resumable reducer state is kept.
3851
4212
  offset: stat6.size,
3852
4213
  line: 0,
3853
- reducerState: null,
4214
+ // Not resumable state: the side-store name slots this parse used, so the
4215
+ // next pass can tell when they moved (see indexFile).
4216
+ reducerState: JSON.stringify(sideSlots),
3854
4217
  fingerprint: fp,
3855
4218
  status: "active"
3856
4219
  });
@@ -3930,7 +4293,7 @@ var PersistentEngine = class {
3930
4293
  let floor = this.checkpoints.floor(filePath, fromIndex);
3931
4294
  if (floor) {
3932
4295
  try {
3933
- if (floor.byteOffset > statSync4(filePath).size) floor = null;
4296
+ if (floor.byteOffset > statSync5(filePath).size) floor = null;
3934
4297
  } catch {
3935
4298
  }
3936
4299
  }
@@ -4105,7 +4468,7 @@ function defaultDbPath() {
4105
4468
  "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."
4106
4469
  );
4107
4470
  }
4108
- return join6(homedir2(), ".config", "threadbase-scanner", "index.db");
4471
+ return join7(homedir2(), ".config", "threadbase-scanner", "index.db");
4109
4472
  }
4110
4473
  function capForMemory(doc, max) {
4111
4474
  const combined = combineSearchContent(doc);
@@ -4198,6 +4561,7 @@ var ConversationScanner = class {
4198
4561
  }
4199
4562
  }
4200
4563
  async runScan(options) {
4564
+ if (options.cursorStateDb !== void 0) setCursorStateDb(options.cursorStateDb);
4201
4565
  const profiles = await this.resolveProfiles(options.profiles);
4202
4566
  const activeProfiles = profiles.filter((p) => p.enabled && p.scanHistory !== false);
4203
4567
  this.lastTier = resolveTier(options.tier ?? "standard", options.tiers);
@@ -4284,7 +4648,7 @@ var ConversationScanner = class {
4284
4648
  const cached = statCache.get(filePath);
4285
4649
  if (cached) {
4286
4650
  try {
4287
- const s = statSync5(filePath);
4651
+ const s = statSync6(filePath);
4288
4652
  if (s.mtimeMs === cached.stat.mtimeMs && s.size === cached.stat.size) {
4289
4653
  return {
4290
4654
  meta: cached.meta,
@@ -4832,13 +5196,13 @@ var ConversationScanner = class {
4832
5196
  if (previous?.provider) return void 0;
4833
5197
  let sample = "";
4834
5198
  try {
4835
- const fd = openSync2(filePath, "r");
5199
+ const fd = openSync3(filePath, "r");
4836
5200
  try {
4837
5201
  const buf = Buffer.alloc(8192);
4838
- const n = readSync2(fd, buf, 0, buf.length, 0);
5202
+ const n = readSync3(fd, buf, 0, buf.length, 0);
4839
5203
  sample = buf.subarray(0, n).toString("utf8");
4840
5204
  } finally {
4841
- closeSync2(fd);
5205
+ closeSync3(fd);
4842
5206
  }
4843
5207
  } catch {
4844
5208
  return void 0;