@threadbase-sh/scanner 0.21.0 → 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 +496 -128
  3. package/dist/cli.js.map +1 -1
  4. package/dist/index.cjs +579 -152
  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 +551 -133
  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.js CHANGED
@@ -350,13 +350,329 @@ function toIndexDoc(meta, searchContent) {
350
350
  };
351
351
  }
352
352
 
353
+ // src/name-stores.ts
354
+ import Database from "better-sqlite3";
355
+ import { closeSync, existsSync, openSync, readdirSync, readFileSync as readFileSync2, readSync, statSync } from "fs";
356
+ import { basename, dirname as dirname2, join as join2 } from "path";
357
+
358
+ // src/tags.ts
359
+ var SYSTEM_TAGS = [
360
+ "system-reminder",
361
+ "command-name",
362
+ "command-message",
363
+ "command-args",
364
+ "ide_selection",
365
+ "ide_opened_file",
366
+ "local-command-stdout",
367
+ "local-command-caveat",
368
+ "retrieval_status",
369
+ "task_id",
370
+ "task_type",
371
+ "task-id",
372
+ "task-notification",
373
+ "fast_mode_info",
374
+ "persisted-output",
375
+ "tool_use_error",
376
+ "user-prompt-submit-hook",
377
+ "thinking",
378
+ "ask_user",
379
+ "teammate-message"
380
+ ];
381
+ var SYSTEM_TAG_RE = new RegExp(`<(${SYSTEM_TAGS.join("|")})[^>]*>[\\s\\S]*?<\\/\\1>`, "g");
382
+ var PASTED_CONTENT_RE = /<pasted_content id="[0-9a-f]{4}">([\s\S]*?)<\/pasted_content(?: id="[0-9a-f]{4}")?>/g;
383
+ function cleanSystemTags(text) {
384
+ return text.replace(SYSTEM_TAG_RE, "").replace(PASTED_CONTENT_RE, "$1").replace(/[^\S\n]+/g, " ").replace(/\n{3,}/g, "\n\n").trim();
385
+ }
386
+
387
+ // src/session-name.ts
388
+ var NAME_PRECEDENCE = [
389
+ "userTitle",
390
+ "toolTitle",
391
+ "lastPrompt",
392
+ "firstUserMessage",
393
+ "slug"
394
+ ];
395
+ var CLAUDE_SYSTEM_PREFIXES = [
396
+ "<command-name>",
397
+ "<command-message>",
398
+ "<command-args>",
399
+ "<local-command-stdout>",
400
+ "<local-command-stderr>",
401
+ "<local-command-caveat>",
402
+ "<bash-input>",
403
+ "<bash-stdout>",
404
+ "<bash-stderr>",
405
+ "<system-reminder>",
406
+ "<task-notification>",
407
+ "<teammate-message",
408
+ "Another Claude session sent a message:",
409
+ "[Request interrupted by user"
410
+ ];
411
+ var CODEX_SYSTEM_PREFIXES = [
412
+ "<environment_context>",
413
+ "# AGENTS.md instructions",
414
+ "<user_instructions>",
415
+ "<INSTRUCTIONS>",
416
+ "<external_codex_apps_open",
417
+ "<user_shell_command>",
418
+ "<turn_aborted>"
419
+ ];
420
+ function isCodexInjectedContext(text) {
421
+ if (text.startsWith("# AGENTS.md") || text.includes("<INSTRUCTIONS>")) return true;
422
+ return text.startsWith("<permissions instructions>") || text.includes("Filesystem sandboxing defines");
423
+ }
424
+ var CODEX_IMAGE_TAG_RE = /<\/?image\b[^>]*>/g;
425
+ function normalizeCandidate(text, provider) {
426
+ let t = text.trim();
427
+ if (provider === "codex-cli") t = t.replace(CODEX_IMAGE_TAG_RE, "").trim();
428
+ const prefixes = provider === "claude-code" ? CLAUDE_SYSTEM_PREFIXES : provider === "codex-cli" ? CODEX_SYSTEM_PREFIXES : [];
429
+ if (prefixes.some((p) => t.startsWith(p))) return null;
430
+ if (provider === "codex-cli" && isCodexInjectedContext(t)) return null;
431
+ return cleanSystemTags(t) || null;
432
+ }
433
+ function isValidNameCandidate(text, provider) {
434
+ return normalizeCandidate(text, provider) !== null;
435
+ }
436
+ function resolveSessionName(slots) {
437
+ for (const slot of NAME_PRECEDENCE) {
438
+ const value = slots[slot];
439
+ if (value?.trim()) return { name: value, source: slot };
440
+ }
441
+ return { name: null, source: null };
442
+ }
443
+ function applyNameCandidate(slots, slot, raw, provider) {
444
+ if (typeof raw !== "string") return slots;
445
+ if (slot === "firstUserMessage" && slots.firstUserMessage !== void 0) return slots;
446
+ const text = normalizeCandidate(raw, provider);
447
+ return text === null ? slots : { ...slots, [slot]: text };
448
+ }
449
+
450
+ // src/name-stores.ts
451
+ function slotsFrom(provider, candidates) {
452
+ return candidates.reduce(
453
+ (slots, [slot, raw]) => applyNameCandidate(slots, slot, typeof raw === "string" ? raw : void 0, provider),
454
+ {}
455
+ );
456
+ }
457
+ function readJson(path) {
458
+ try {
459
+ return JSON.parse(readFileSync2(path, "utf8"));
460
+ } catch {
461
+ return void 0;
462
+ }
463
+ }
464
+ function queryOne(dbPath, sql, ...params) {
465
+ let db;
466
+ try {
467
+ db = new Database(dbPath, { readonly: true, fileMustExist: true, timeout: 250 });
468
+ return db.prepare(sql).get(...params);
469
+ } catch (err) {
470
+ getLogger().debug({ dbPath, err }, "name store: query failed");
471
+ return void 0;
472
+ } finally {
473
+ db?.close();
474
+ }
475
+ }
476
+ var lastByIdCache = /* @__PURE__ */ new Map();
477
+ function lastValueById(path, idField, valueField) {
478
+ let sig;
479
+ try {
480
+ const s = statSync(path);
481
+ sig = `${s.mtimeMs}:${s.size}`;
482
+ } catch {
483
+ return /* @__PURE__ */ new Map();
484
+ }
485
+ const key = `${path}\0${idField}\0${valueField}`;
486
+ const cached = lastByIdCache.get(key);
487
+ if (cached?.sig === sig) return cached.map;
488
+ const map = /* @__PURE__ */ new Map();
489
+ try {
490
+ for (const line of readFileSync2(path, "utf8").split("\n")) {
491
+ if (!line.trim()) continue;
492
+ try {
493
+ const row = JSON.parse(line);
494
+ const id = row[idField];
495
+ const value = row[valueField];
496
+ if (typeof id === "string" && typeof value === "string") map.set(id, value);
497
+ } catch {
498
+ }
499
+ }
500
+ } catch {
501
+ }
502
+ lastByIdCache.set(key, { sig, map });
503
+ return map;
504
+ }
505
+ function readCodexNameSlots(codexHome, id) {
506
+ const index = lastValueById(join2(codexHome, "session_index.jsonl"), "id", "thread_name");
507
+ const history = lastValueById(join2(codexHome, "history.jsonl"), "session_id", "text");
508
+ let title = index.get(id);
509
+ if (!index.has(id)) {
510
+ title = queryOne(
511
+ join2(codexHome, "state_5.sqlite"),
512
+ "SELECT name FROM threads WHERE id = ?",
513
+ id
514
+ )?.name;
515
+ }
516
+ return slotsFrom("codex-cli", [
517
+ ["toolTitle", title],
518
+ ["lastPrompt", history.get(id)]
519
+ ]);
520
+ }
521
+ function readCursorCliNameSlots(chatsDir, id) {
522
+ let chat;
523
+ try {
524
+ chat = readdirSync(chatsDir).map((hash) => join2(chatsDir, hash, id)).find((p) => existsSync(p));
525
+ } catch {
526
+ }
527
+ if (!chat) return {};
528
+ const meta = readJson(join2(chat, "meta.json"));
529
+ const history = readJson(join2(chat, "prompt_history.json"));
530
+ let title = meta?.title;
531
+ if (typeof title !== "string" || !title.trim()) title = storeDbName(join2(chat, "store.db"));
532
+ return slotsFrom("cursor", [
533
+ ["toolTitle", title],
534
+ ["lastPrompt", Array.isArray(history) ? history[0] : void 0]
535
+ ]);
536
+ }
537
+ function storeDbName(dbPath) {
538
+ const row = queryOne(
539
+ dbPath,
540
+ "SELECT value FROM meta WHERE key = '0'"
541
+ );
542
+ if (!row) return void 0;
543
+ try {
544
+ const text = row.value.toString();
545
+ const json = /^(?:[0-9a-f]{2})+$/i.test(text) ? Buffer.from(text, "hex").toString("utf8") : text;
546
+ const name = JSON.parse(json).name;
547
+ return typeof name === "string" ? name : void 0;
548
+ } catch {
549
+ return void 0;
550
+ }
551
+ }
552
+ function readCursorIdeNameSlots(stateDbPath, id) {
553
+ const row = queryOne(
554
+ stateDbPath,
555
+ "SELECT json_extract(CAST(value AS TEXT), '$.name') AS name FROM cursorDiskKV WHERE key = ?",
556
+ `composerData:${id}`
557
+ );
558
+ return slotsFrom("cursor", [["toolTitle", row?.name]]);
559
+ }
560
+ function yamlScalar(text, key) {
561
+ const m = text.match(new RegExp(`^${key}:[ \\t]*(.*)$`, "m"));
562
+ const v = m?.[1].trim().replace(/^(["'])(.*)\1$/, "$2");
563
+ return v || void 0;
564
+ }
565
+ function readCopilotTitleSlots(sessionDir) {
566
+ const id = basename(sessionDir);
567
+ let yaml = "";
568
+ try {
569
+ yaml = readFileSync2(join2(sessionDir, "workspace.yaml"), "utf8");
570
+ } catch {
571
+ }
572
+ const name = yamlScalar(yaml, "name");
573
+ if (name) {
574
+ return slotsFrom("copilot", [
575
+ [yamlScalar(yaml, "user_named") === "true" ? "userTitle" : "toolTitle", name]
576
+ ]);
577
+ }
578
+ const row = queryOne(
579
+ join2(dirname2(dirname2(sessionDir)), "session-store.db"),
580
+ "SELECT summary FROM sessions WHERE id = ?",
581
+ id
582
+ );
583
+ return slotsFrom("copilot", [["toolTitle", row?.summary]]);
584
+ }
585
+ function readCopilotNameSlots(sessionDir) {
586
+ return {
587
+ ...readCopilotTitleSlots(sessionDir),
588
+ ...slotsFrom("copilot", [
589
+ ["firstUserMessage", firstCopilotUserMessage(join2(sessionDir, "events.jsonl"))]
590
+ ])
591
+ };
592
+ }
593
+ function firstCopilotUserMessage(path) {
594
+ let fd;
595
+ try {
596
+ fd = openSync(path, "r");
597
+ } catch {
598
+ return void 0;
599
+ }
600
+ try {
601
+ const buf = Buffer.alloc(64 * 1024);
602
+ let pending = "";
603
+ for (let n = readSync(fd, buf, 0, buf.length, null); n > 0; n = readSync(fd, buf, 0, buf.length, null)) {
604
+ pending += buf.toString("utf8", 0, n);
605
+ const lines = pending.split("\n");
606
+ pending = lines.pop() ?? "";
607
+ for (const line of lines) {
608
+ try {
609
+ const e = JSON.parse(line);
610
+ if (e.type === "user.message" && typeof e.data?.content === "string")
611
+ return e.data.content;
612
+ } catch {
613
+ }
614
+ }
615
+ }
616
+ return void 0;
617
+ } catch {
618
+ return void 0;
619
+ } finally {
620
+ closeSync(fd);
621
+ }
622
+ }
623
+ function findUp(start, hasStore, levels) {
624
+ let dir = start;
625
+ for (let i = 0; i < levels; i++) {
626
+ if (hasStore(dir)) return dir;
627
+ const parent = dirname2(dir);
628
+ if (parent === dir) break;
629
+ dir = parent;
630
+ }
631
+ return null;
632
+ }
633
+ function codexNameSlotsFor(rolloutPath, id) {
634
+ const home = findUp(
635
+ dirname2(rolloutPath),
636
+ (d) => ["session_index.jsonl", "history.jsonl", "state_5.sqlite"].some(
637
+ (f) => existsSync(join2(d, f))
638
+ ),
639
+ 6
640
+ );
641
+ return home ? readCodexNameSlots(home, id) : {};
642
+ }
643
+ var cursorStateDb;
644
+ function setCursorStateDb(path) {
645
+ cursorStateDb = path;
646
+ }
647
+ function cursorNameSlotsFor(transcriptPath, id) {
648
+ const home = findUp(dirname2(transcriptPath), (d) => existsSync(join2(d, "chats")), 6);
649
+ const cli = home ? readCursorCliNameSlots(join2(home, "chats"), id) : {};
650
+ if (cli.toolTitle || !cursorStateDb) return cli;
651
+ return { ...cli, ...readCursorIdeNameSlots(cursorStateDb, id) };
652
+ }
653
+ function copilotNameSlotsFor(eventsPath) {
654
+ return readCopilotTitleSlots(dirname2(eventsPath));
655
+ }
656
+ function nameStoreSlotsFor(provider, filePath, sessionId) {
657
+ switch (provider) {
658
+ case "codex-cli":
659
+ return codexNameSlotsFor(filePath, sessionId);
660
+ case "cursor":
661
+ return cursorNameSlotsFor(filePath, basename(filePath, ".jsonl"));
662
+ case "copilot":
663
+ return copilotNameSlotsFor(filePath);
664
+ default:
665
+ return {};
666
+ }
667
+ }
668
+
353
669
  // src/parser.ts
354
670
  import { createReadStream } from "fs";
355
- import { basename as basename2 } from "path";
671
+ import { basename as basename3 } from "path";
356
672
  import { createInterface } from "readline";
357
673
 
358
674
  // src/persistent/metadata-reducer.ts
359
- import { basename, dirname as dirname2, join as join2 } from "path";
675
+ import { basename as basename2, dirname as dirname3, join as join3 } from "path";
360
676
 
361
677
  // src/providers/provider.ts
362
678
  var CLAUDE_CODE_PROVIDER = "claude-code";
@@ -386,11 +702,36 @@ function providerMatches(stored, wanted) {
386
702
  return a === b;
387
703
  }
388
704
 
705
+ // src/persistent/claude-name-slots.ts
706
+ function userPromptText(entry) {
707
+ if (entry.isMeta || entry.isCompactSummary === true) return "";
708
+ const content = entry.message?.content;
709
+ if (typeof content === "string") return content;
710
+ if (!Array.isArray(content)) return "";
711
+ return content.map((b) => typeof b === "string" ? b : b?.type === "text" ? b.text : "").filter((t) => typeof t === "string" && t !== "").join(" ");
712
+ }
713
+ function applyClaudeNameEntry(slots, entry) {
714
+ const apply = (slot, raw) => applyNameCandidate(slots, slot, typeof raw === "string" ? raw : void 0, "claude-code");
715
+ if (entry.slug !== slots.slug) slots = apply("slug", entry.slug);
716
+ switch (entry.type) {
717
+ case "custom-title":
718
+ return apply("userTitle", entry.customTitle);
719
+ case "ai-title":
720
+ return apply("toolTitle", entry.aiTitle);
721
+ case "last-prompt":
722
+ return apply("lastPrompt", entry.lastPrompt);
723
+ case "user":
724
+ return slots.firstUserMessage === void 0 ? apply("firstUserMessage", userPromptText(entry)) : slots;
725
+ default:
726
+ return slots;
727
+ }
728
+ }
729
+
389
730
  // src/persistent/metadata-reducer.ts
390
731
  function initialReducerState() {
391
732
  return {
392
733
  sessionId: "",
393
- sessionName: "",
734
+ nameSlots: {},
394
735
  latestTimestamp: "",
395
736
  cwd: "",
396
737
  teamName: "",
@@ -416,7 +757,7 @@ function initialReducerState() {
416
757
  function reduceLine(state, entry, tier) {
417
758
  if (entry.cwd && !state.cwd) state.cwd = entry.cwd;
418
759
  if (entry.sessionId && !state.sessionId) state.sessionId = entry.sessionId;
419
- if (entry.slug && !state.sessionName) state.sessionName = entry.slug;
760
+ state.nameSlots = applyClaudeNameEntry(state.nameSlots, entry);
420
761
  if (entry.teamName && !state.teamName) state.teamName = entry.teamName;
421
762
  if (entry.agentId && !state.agentId) state.agentId = entry.agentId;
422
763
  if (entry.isSidechain === true) state.isSidechain = true;
@@ -480,16 +821,16 @@ function finalizeMeta(state, filePath, account, tier) {
480
821
  const isSubagent = isSidechain || isSubagentPath;
481
822
  let parentSessionId = null;
482
823
  if (isSubagentPath) {
483
- const uuidDir = dirname2(dirname2(filePath));
484
- parentSessionId = join2(dirname2(uuidDir), `${basename(uuidDir)}.jsonl`);
824
+ const uuidDir = dirname3(dirname3(filePath));
825
+ parentSessionId = join3(dirname3(uuidDir), `${basename2(uuidDir)}.jsonl`);
485
826
  }
486
827
  const projectPath = state.cwd;
487
828
  return {
488
829
  id: filePath,
489
830
  filePath,
490
831
  provider: CLAUDE_CODE_PROVIDER,
491
- sessionId: state.sessionId || basename(filePath, ".jsonl"),
492
- sessionName: state.sessionName || deriveSessionNameFromFirstMessage(state.firstMessage),
832
+ sessionId: state.sessionId || basename2(filePath, ".jsonl"),
833
+ sessionName: resolveSessionName(state.nameSlots).name ?? "",
493
834
  projectPath,
494
835
  projectName: getShortProjectName(projectPath),
495
836
  account,
@@ -515,44 +856,11 @@ function finalizeMeta(state, filePath, account, tier) {
515
856
  };
516
857
  }
517
858
  var SUBAGENT_PATH_RE = /[\\/]subagents[\\/]/;
518
- function deriveSessionNameFromFirstMessage(firstMessage) {
519
- const firstLine = firstMessage?.text.split("\n", 1)[0]?.trim() ?? "";
520
- return firstLine.slice(0, 80);
521
- }
522
859
  function getShortProjectName(fullPath) {
523
860
  const parts = fullPath.split("/").filter(Boolean);
524
861
  return parts.slice(-3).join("/");
525
862
  }
526
863
 
527
- // src/tags.ts
528
- var SYSTEM_TAGS = [
529
- "system-reminder",
530
- "command-name",
531
- "command-message",
532
- "command-args",
533
- "ide_selection",
534
- "ide_opened_file",
535
- "local-command-stdout",
536
- "local-command-caveat",
537
- "retrieval_status",
538
- "task_id",
539
- "task_type",
540
- "task-id",
541
- "task-notification",
542
- "fast_mode_info",
543
- "persisted-output",
544
- "tool_use_error",
545
- "user-prompt-submit-hook",
546
- "thinking",
547
- "ask_user",
548
- "teammate-message"
549
- ];
550
- var SYSTEM_TAG_RE = new RegExp(`<(${SYSTEM_TAGS.join("|")})[^>]*>[\\s\\S]*?<\\/\\1>`, "g");
551
- var PASTED_CONTENT_RE = /<pasted_content id="[0-9a-f]{4}">([\s\S]*?)<\/pasted_content(?: id="[0-9a-f]{4}")?>/g;
552
- function cleanSystemTags(text) {
553
- return text.replace(SYSTEM_TAG_RE, "").replace(PASTED_CONTENT_RE, "$1").replace(/[^\S\n]+/g, " ").replace(/\n{3,}/g, "\n\n").trim();
554
- }
555
-
556
864
  // src/parser.ts
557
865
  async function parseMeta(filePath, account, tier, onEntry) {
558
866
  const log = getLogger();
@@ -618,7 +926,7 @@ async function parseConversation(filePath, account) {
618
926
  const message = reduceConvLine(state, entry);
619
927
  if (message) {
620
928
  messages.push(message);
621
- if (message.text) textParts.push(message.text);
929
+ if (message.text && !message.isCompactSummary) textParts.push(message.text);
622
930
  }
623
931
  }
624
932
  } catch (err) {
@@ -639,8 +947,8 @@ async function parseConversation(filePath, account) {
639
947
  filePath,
640
948
  projectPath: state.cwd,
641
949
  projectName: getShortProjectName2(state.cwd),
642
- sessionId: state.sessionId || basename2(filePath, ".jsonl"),
643
- sessionName: state.sessionName || deriveSessionNameFromFirstMessage(messages.find((m) => m.role === "user" && m.text) ?? null),
950
+ sessionId: state.sessionId || basename3(filePath, ".jsonl"),
951
+ sessionName: resolveSessionName(state.nameSlots).name ?? "",
644
952
  messages,
645
953
  fullText: textParts.join(" "),
646
954
  timestamp: state.latestTimestamp || (/* @__PURE__ */ new Date()).toISOString(),
@@ -750,7 +1058,7 @@ function initialConvState() {
750
1058
  return {
751
1059
  cwd: "",
752
1060
  sessionId: "",
753
- sessionName: "",
1061
+ nameSlots: {},
754
1062
  latestTimestamp: "",
755
1063
  lastPrompt: "",
756
1064
  pendingToolUses: {},
@@ -760,7 +1068,7 @@ function initialConvState() {
760
1068
  function reduceConvLine(state, entry) {
761
1069
  if (entry.cwd && !state.cwd) state.cwd = entry.cwd;
762
1070
  if (entry.sessionId && !state.sessionId) state.sessionId = entry.sessionId;
763
- if (entry.slug && !state.sessionName) state.sessionName = entry.slug;
1071
+ state.nameSlots = applyClaudeNameEntry(state.nameSlots, entry);
764
1072
  if (entry.timestamp) {
765
1073
  const ts = entry.timestamp;
766
1074
  if (!state.latestTimestamp || ts > state.latestTimestamp) state.latestTimestamp = ts;
@@ -868,7 +1176,7 @@ function applyTeamInfo(messages, state) {
868
1176
  }
869
1177
 
870
1178
  // src/persistent/sidecar.ts
871
- import { readFileSync as readFileSync2, writeFileSync } from "fs";
1179
+ import { readFileSync as readFileSync3, writeFileSync } from "fs";
872
1180
  var SIDECAR_VERSION = 1;
873
1181
  function sidecarPath(jsonlPath) {
874
1182
  return `${jsonlPath}.idx.json`;
@@ -901,7 +1209,7 @@ function writeSidecar(jsonlPath, sidecar) {
901
1209
  }
902
1210
  function readSidecar(jsonlPath) {
903
1211
  try {
904
- return JSON.parse(readFileSync2(sidecarPath(jsonlPath), "utf-8"));
1212
+ return JSON.parse(readFileSync3(sidecarPath(jsonlPath), "utf-8"));
905
1213
  } catch {
906
1214
  return null;
907
1215
  }
@@ -910,19 +1218,19 @@ function readSidecar(jsonlPath) {
910
1218
  // src/profiles.ts
911
1219
  import { mkdir, readFile, writeFile } from "fs/promises";
912
1220
  import { homedir } from "os";
913
- import { join as join3 } from "path";
1221
+ import { join as join4 } from "path";
914
1222
  var PROFILES_FILE = "profiles.json";
915
1223
  function resolveConfigDir(configDir) {
916
1224
  return configDir.replace(/^~/, homedir());
917
1225
  }
918
1226
  function getProjectsDir(profile) {
919
- return join3(resolveConfigDir(profile.configDir), "projects");
1227
+ return join4(resolveConfigDir(profile.configDir), "projects");
920
1228
  }
921
1229
  async function detectDefaultProfile() {
922
1230
  return {
923
1231
  id: "default",
924
1232
  label: "Default",
925
- configDir: join3(homedir(), ".claude"),
1233
+ configDir: join4(homedir(), ".claude"),
926
1234
  enabled: true,
927
1235
  emoji: "\u{1F916}"
928
1236
  };
@@ -931,7 +1239,7 @@ async function loadProfiles(configPath) {
931
1239
  const log = getLogger();
932
1240
  try {
933
1241
  const resolved = resolveConfigDir(configPath);
934
- const data = await readFile(join3(resolved, PROFILES_FILE), "utf-8");
1242
+ const data = await readFile(join4(resolved, PROFILES_FILE), "utf-8");
935
1243
  const profiles = JSON.parse(data);
936
1244
  log.debug({ configPath, count: profiles.length }, "profiles: loaded");
937
1245
  return profiles;
@@ -944,7 +1252,7 @@ async function loadProfiles(configPath) {
944
1252
  async function saveProfiles(profiles, configPath) {
945
1253
  const resolved = resolveConfigDir(configPath);
946
1254
  await mkdir(resolved, { recursive: true });
947
- await writeFile(join3(resolved, PROFILES_FILE), JSON.stringify(profiles, null, 2));
1255
+ await writeFile(join4(resolved, PROFILES_FILE), JSON.stringify(profiles, null, 2));
948
1256
  getLogger().debug({ configPath, count: profiles.length }, "profiles: saved");
949
1257
  }
950
1258
 
@@ -952,7 +1260,7 @@ async function saveProfiles(profiles, configPath) {
952
1260
  import fg from "fast-glob";
953
1261
  import { createReadStream as createReadStream2 } from "fs";
954
1262
  import { stat } from "fs/promises";
955
- import { basename as basename3 } from "path";
1263
+ import { basename as basename4 } from "path";
956
1264
  import { createInterface as createInterface2 } from "readline";
957
1265
 
958
1266
  // src/canonical-path.ts
@@ -1018,6 +1326,7 @@ var CodexCliProvider = class {
1018
1326
  isSubagent: false,
1019
1327
  parentSessionUuid: null,
1020
1328
  firstUser: null,
1329
+ nameSlots: {},
1021
1330
  lastUser: null,
1022
1331
  lastAssistant: null,
1023
1332
  toolNames: [],
@@ -1180,6 +1489,7 @@ function reduceCodexEntry(acc, entry, tier) {
1180
1489
  const snapshot = { text: text.slice(0, 200), timestamp: ts };
1181
1490
  if (sender === "user") {
1182
1491
  if (!acc.firstUser) acc.firstUser = snapshot;
1492
+ acc.nameSlots = applyNameCandidate(acc.nameSlots, "firstUserMessage", text, CODEX_CLI_PROVIDER);
1183
1493
  acc.lastUser = snapshot;
1184
1494
  } else {
1185
1495
  acc.lastAssistant = snapshot;
@@ -1197,7 +1507,7 @@ function reduceCodexEntry(acc, entry, tier) {
1197
1507
  }
1198
1508
  function finalizeCodexMeta(acc, filePath, account, tier) {
1199
1509
  if (acc.messageCount === 0) return null;
1200
- const sessionId = acc.sessionId || basename3(filePath, ".jsonl");
1510
+ const sessionId = acc.sessionId || basename4(filePath, ".jsonl");
1201
1511
  const projectPath = acc.cwd;
1202
1512
  const kind = acc.lastAssistant === null && acc.toolNames.length > 0 ? "task" : "conversation";
1203
1513
  return {
@@ -1207,10 +1517,7 @@ function finalizeCodexMeta(acc, filePath, account, tier) {
1207
1517
  kind,
1208
1518
  externalSessionId: acc.sessionId || void 0,
1209
1519
  sessionId,
1210
- // Mirrors the Claude reducer: a rollout carries no slug, so the opening turn
1211
- // is the only human-readable name source. Only useful because the injected
1212
- // AGENTS.md turn is skipped above — otherwise every title would be that blob.
1213
- sessionName: deriveSessionNameFromFirstMessage(acc.firstUser),
1520
+ sessionName: resolveSessionName({ ...acc.nameSlots, ...codexNameSlotsFor(filePath, acc.sessionId) }).name ?? "",
1214
1521
  projectPath,
1215
1522
  projectName: getShortProjectName3(projectPath),
1216
1523
  account,
@@ -1233,10 +1540,6 @@ function finalizeCodexMeta(acc, filePath, account, tier) {
1233
1540
  lastPrompt: acc.lastUser?.text || void 0
1234
1541
  };
1235
1542
  }
1236
- function isCodexInjectedContext(text) {
1237
- if (text.startsWith("# AGENTS.md") || text.includes("<INSTRUCTIONS>")) return true;
1238
- return text.startsWith("<permissions instructions>") || text.includes("Filesystem sandboxing defines");
1239
- }
1240
1543
  function getShortProjectName3(fullPath) {
1241
1544
  return fullPath.split("/").filter(Boolean).slice(-3).join("/");
1242
1545
  }
@@ -1259,6 +1562,7 @@ async function parseCodexConversation(filePath, account) {
1259
1562
  let cwd = "";
1260
1563
  let latestTimestamp = "";
1261
1564
  let lastUserText = "";
1565
+ let nameSlots = {};
1262
1566
  const rl = createInterface2({ input: createReadStream2(filePath), crlfDelay: Infinity });
1263
1567
  try {
1264
1568
  for await (const line of rl) {
@@ -1283,7 +1587,15 @@ async function parseCodexConversation(filePath, account) {
1283
1587
  messages.push(message);
1284
1588
  if (!message.text) continue;
1285
1589
  textParts.push(message.text);
1286
- if (message.role === "user") lastUserText = message.text;
1590
+ if (message.role === "user") {
1591
+ lastUserText = message.text;
1592
+ nameSlots = applyNameCandidate(
1593
+ nameSlots,
1594
+ "firstUserMessage",
1595
+ message.text,
1596
+ CODEX_CLI_PROVIDER
1597
+ );
1598
+ }
1287
1599
  }
1288
1600
  } catch (err) {
1289
1601
  log.warn({ filePath, err }, "parseCodexConversation: read failed");
@@ -1295,8 +1607,8 @@ async function parseCodexConversation(filePath, account) {
1295
1607
  filePath,
1296
1608
  projectPath: cwd,
1297
1609
  projectName: getShortProjectName3(cwd),
1298
- sessionId: sessionId || basename3(filePath, ".jsonl"),
1299
- sessionName: "",
1610
+ sessionId: sessionId || basename4(filePath, ".jsonl"),
1611
+ sessionName: resolveSessionName({ ...nameSlots, ...codexNameSlotsFor(filePath, sessionId) }).name ?? "",
1300
1612
  messages,
1301
1613
  fullText: textParts.join(" "),
1302
1614
  timestamp: latestTimestamp || (/* @__PURE__ */ new Date()).toISOString(),
@@ -1308,9 +1620,9 @@ async function parseCodexConversation(filePath, account) {
1308
1620
 
1309
1621
  // src/providers/copilot.ts
1310
1622
  import fg2 from "fast-glob";
1311
- import { createReadStream as createReadStream3, statSync } from "fs";
1623
+ import { createReadStream as createReadStream3, statSync as statSync2 } from "fs";
1312
1624
  import { stat as stat2 } from "fs/promises";
1313
- import { basename as basename4, dirname as dirname3 } from "path";
1625
+ import { basename as basename5, dirname as dirname4 } from "path";
1314
1626
  import { createInterface as createInterface3 } from "readline";
1315
1627
  var SESSION_START = "session.start";
1316
1628
  var USER_MESSAGE = "user.message";
@@ -1364,6 +1676,7 @@ var CopilotProvider = class {
1364
1676
  messageCount: 0,
1365
1677
  lastMessageSender: "user",
1366
1678
  firstUser: null,
1679
+ nameSlots: {},
1367
1680
  lastUser: null,
1368
1681
  lastAssistant: null,
1369
1682
  toolNames: [],
@@ -1471,6 +1784,7 @@ function reduceCopilotEntry(acc, entry, tier) {
1471
1784
  const snapshot = { text: text.slice(0, 200), timestamp };
1472
1785
  if (role === "user") {
1473
1786
  if (!acc.firstUser) acc.firstUser = snapshot;
1787
+ acc.nameSlots = applyNameCandidate(acc.nameSlots, "firstUserMessage", text, COPILOT_PROVIDER);
1474
1788
  acc.lastUser = snapshot;
1475
1789
  } else {
1476
1790
  acc.lastAssistant = snapshot;
@@ -1497,7 +1811,7 @@ function finalizeCopilotMeta(acc, filePath, account, tier) {
1497
1811
  kind,
1498
1812
  externalSessionId: sessionId,
1499
1813
  sessionId,
1500
- sessionName: deriveSessionNameFromFirstMessage(acc.firstUser),
1814
+ sessionName: resolveSessionName({ ...acc.nameSlots, ...copilotNameSlotsFor(filePath) }).name ?? "",
1501
1815
  projectPath: acc.cwd,
1502
1816
  projectName: getShortProjectName4(acc.cwd),
1503
1817
  account,
@@ -1519,14 +1833,14 @@ function finalizeCopilotMeta(acc, filePath, account, tier) {
1519
1833
  };
1520
1834
  }
1521
1835
  function sessionIdFromPath(filePath) {
1522
- return basename4(dirname3(filePath));
1836
+ return basename5(dirname4(filePath));
1523
1837
  }
1524
1838
  function getShortProjectName4(fullPath) {
1525
1839
  return fullPath.split(/[/\\]/).filter(Boolean).slice(-3).join("/");
1526
1840
  }
1527
1841
  function fileMtimeIso(filePath) {
1528
1842
  try {
1529
- return new Date(statSync(filePath).mtimeMs).toISOString();
1843
+ return new Date(statSync2(filePath).mtimeMs).toISOString();
1530
1844
  } catch {
1531
1845
  return (/* @__PURE__ */ new Date()).toISOString();
1532
1846
  }
@@ -1539,6 +1853,7 @@ async function parseCopilotConversation(filePath, account) {
1539
1853
  let cwd = "";
1540
1854
  let latestTimestamp = "";
1541
1855
  let lastUserText = "";
1856
+ let nameSlots = {};
1542
1857
  const rl = createInterface3({ input: createReadStream3(filePath), crlfDelay: Infinity });
1543
1858
  try {
1544
1859
  for await (const line of rl) {
@@ -1563,7 +1878,15 @@ async function parseCopilotConversation(filePath, account) {
1563
1878
  messages.push(message);
1564
1879
  if (!message.text) continue;
1565
1880
  textParts.push(message.text);
1566
- if (message.role === "user") lastUserText = message.text;
1881
+ if (message.role === "user") {
1882
+ lastUserText = message.text;
1883
+ nameSlots = applyNameCandidate(
1884
+ nameSlots,
1885
+ "firstUserMessage",
1886
+ message.text,
1887
+ COPILOT_PROVIDER
1888
+ );
1889
+ }
1567
1890
  }
1568
1891
  } catch (err) {
1569
1892
  log.warn({ filePath, err }, "parseCopilotConversation: read failed");
@@ -1576,7 +1899,7 @@ async function parseCopilotConversation(filePath, account) {
1576
1899
  projectPath: cwd,
1577
1900
  projectName: getShortProjectName4(cwd),
1578
1901
  sessionId: sessionId || sessionIdFromPath(filePath),
1579
- sessionName: "",
1902
+ sessionName: resolveSessionName({ ...nameSlots, ...copilotNameSlotsFor(filePath) }).name ?? "",
1580
1903
  messages,
1581
1904
  fullText: textParts.join(" "),
1582
1905
  timestamp: latestTimestamp || fileMtimeIso(filePath),
@@ -1589,9 +1912,9 @@ async function parseCopilotConversation(filePath, account) {
1589
1912
  // src/providers/cursor.ts
1590
1913
  import { createHash } from "crypto";
1591
1914
  import fg3 from "fast-glob";
1592
- import { createReadStream as createReadStream4, existsSync, statSync as statSync2 } from "fs";
1915
+ import { createReadStream as createReadStream4, existsSync as existsSync2, statSync as statSync3 } from "fs";
1593
1916
  import { stat as stat3 } from "fs/promises";
1594
- import { basename as basename5, dirname as dirname4, join as join4, sep as sep2 } from "path";
1917
+ import { basename as basename6, dirname as dirname5, join as join5, sep as sep2 } from "path";
1595
1918
  import { createInterface as createInterface4 } from "readline";
1596
1919
  var TIMESTAMP_RE = /<timestamp>\s*([\s\S]*?)\s*<\/timestamp>/;
1597
1920
  var USER_QUERY_RE = /<user_query>\s*([\s\S]*?)\s*<\/user_query>/;
@@ -1650,6 +1973,7 @@ var CursorProvider = class {
1650
1973
  parentSessionUuid: null,
1651
1974
  subagentId: null,
1652
1975
  firstUser: null,
1976
+ nameSlots: {},
1653
1977
  lastUser: null,
1654
1978
  lastAssistant: null,
1655
1979
  isImportedFromClaude: false,
@@ -1716,6 +2040,15 @@ function noteImportProvenance(acc, entry, text) {
1716
2040
  acc.isImportedFromCodex = true;
1717
2041
  }
1718
2042
  }
2043
+ function cursorUserQuery(content) {
2044
+ const texts = typeof content === "string" ? [content] : Array.isArray(content) ? content : [];
2045
+ for (const item of texts) {
2046
+ const text = typeof item === "string" ? item : item?.text;
2047
+ const query = typeof text === "string" ? text.match(USER_QUERY_RE) : null;
2048
+ if (query) return query[1];
2049
+ }
2050
+ return void 0;
2051
+ }
1719
2052
  function unwrapCursorUserText(text) {
1720
2053
  const query = text.match(USER_QUERY_RE);
1721
2054
  const body = query ? query[1] : text.replace(TIMESTAMP_RE, "");
@@ -1853,6 +2186,14 @@ function reduceCursorEntry(acc, entry, tier) {
1853
2186
  collectCursorToolNames(content, acc.toolNames);
1854
2187
  const text = textHint;
1855
2188
  if (!text) return;
2189
+ if (entry.role === "user") {
2190
+ acc.nameSlots = applyNameCandidate(
2191
+ acc.nameSlots,
2192
+ "firstUserMessage",
2193
+ cursorUserQuery(content),
2194
+ CURSOR_PROVIDER
2195
+ );
2196
+ }
1856
2197
  foldCursorMessage(acc, entry.role, text, firstTimestampHint(content), tier);
1857
2198
  return;
1858
2199
  }
@@ -1871,7 +2212,7 @@ function reduceCursorEntry(acc, entry, tier) {
1871
2212
  }
1872
2213
  function finalizeCursorMeta(acc, filePath, account, tier) {
1873
2214
  if (acc.messageCount === 0) return null;
1874
- const sessionId = basename5(filePath, ".jsonl");
2215
+ const sessionId = basename6(filePath, ".jsonl");
1875
2216
  const isSubagent = SUBAGENT_PATH_RE2.test(filePath);
1876
2217
  const parent = isSubagent ? parentFromSubagentPath(filePath) : null;
1877
2218
  const { projectPath, projectName } = projectFromCursorPath(filePath);
@@ -1884,7 +2225,7 @@ function finalizeCursorMeta(acc, filePath, account, tier) {
1884
2225
  kind,
1885
2226
  externalSessionId: sessionId,
1886
2227
  sessionId,
1887
- sessionName: deriveSessionNameFromFirstMessage(acc.firstUser),
2228
+ sessionName: resolveSessionName({ ...acc.nameSlots, ...cursorNameSlotsFor(filePath, sessionId) }).name ?? "",
1888
2229
  projectPath,
1889
2230
  projectName,
1890
2231
  account,
@@ -1910,20 +2251,20 @@ function finalizeCursorMeta(acc, filePath, account, tier) {
1910
2251
  };
1911
2252
  }
1912
2253
  function parentFromSubagentPath(filePath) {
1913
- const subagentsDir = dirname4(filePath);
1914
- const parentDir = dirname4(subagentsDir);
1915
- const parentSessionUuid = basename5(parentDir);
2254
+ const subagentsDir = dirname5(filePath);
2255
+ const parentDir = dirname5(subagentsDir);
2256
+ const parentSessionUuid = basename6(parentDir);
1916
2257
  if (!parentSessionUuid) return null;
1917
2258
  return {
1918
2259
  parentSessionUuid,
1919
- parentFilePath: canonicalPath(join4(parentDir, `${parentSessionUuid}.jsonl`))
2260
+ parentFilePath: canonicalPath(join5(parentDir, `${parentSessionUuid}.jsonl`))
1920
2261
  };
1921
2262
  }
1922
2263
  function projectFromCursorPath(filePath) {
1923
2264
  const parts = filePath.split(/[/\\]/);
1924
2265
  const idx = parts.lastIndexOf("agent-transcripts");
1925
- const cursorProjectDir = idx > 0 ? parts.slice(0, idx).join(sep2) : dirname4(dirname4(filePath));
1926
- const slug = basename5(cursorProjectDir);
2266
+ const cursorProjectDir = idx > 0 ? parts.slice(0, idx).join(sep2) : dirname5(dirname5(filePath));
2267
+ const slug = basename6(cursorProjectDir);
1927
2268
  const decoded = decodeCursorProjectSlug(slug);
1928
2269
  const projectPath = decoded ?? cursorProjectDir;
1929
2270
  return { projectPath, projectName: getShortProjectName5(projectPath) || slug };
@@ -1937,7 +2278,7 @@ function decodeCursorProjectSlug(slug) {
1937
2278
  let i = 0;
1938
2279
  if (rooted && segments[0] === "Users") {
1939
2280
  const users = `${sep2}Users`;
1940
- if (!existsSync(users)) return null;
2281
+ if (!existsSync2(users)) return null;
1941
2282
  acc = users;
1942
2283
  i = 1;
1943
2284
  }
@@ -1945,9 +2286,9 @@ function decodeCursorProjectSlug(slug) {
1945
2286
  let found = null;
1946
2287
  let next = i + 1;
1947
2288
  for (let j = segments.length; j > i; j--) {
1948
- const candidate = join4(acc, segments.slice(i, j).join("-"));
2289
+ const candidate = join5(acc, segments.slice(i, j).join("-"));
1949
2290
  try {
1950
- if (existsSync(candidate) && statSync2(candidate).isDirectory()) {
2291
+ if (existsSync2(candidate) && statSync3(candidate).isDirectory()) {
1951
2292
  found = candidate;
1952
2293
  next = j;
1953
2294
  break;
@@ -1966,17 +2307,26 @@ function getShortProjectName5(fullPath) {
1966
2307
  }
1967
2308
  function fileMtimeIso2(filePath) {
1968
2309
  try {
1969
- return new Date(statSync2(filePath).mtimeMs).toISOString();
2310
+ return new Date(statSync3(filePath).mtimeMs).toISOString();
1970
2311
  } catch {
1971
2312
  return (/* @__PURE__ */ new Date()).toISOString();
1972
2313
  }
1973
2314
  }
2315
+ function cursorLineContent(line) {
2316
+ try {
2317
+ const entry = JSON.parse(line);
2318
+ return entry.message?.content ?? entry.content;
2319
+ } catch {
2320
+ return void 0;
2321
+ }
2322
+ }
1974
2323
  async function parseCursorConversation(filePath, account) {
1975
2324
  const log = getLogger();
1976
2325
  const messages = [];
1977
2326
  const textParts = [];
1978
2327
  let latestTimestamp = "";
1979
2328
  let lastUserText = "";
2329
+ let nameSlots = {};
1980
2330
  const rl = createInterface4({ input: createReadStream4(filePath), crlfDelay: Infinity });
1981
2331
  try {
1982
2332
  for await (const line of rl) {
@@ -1988,7 +2338,17 @@ async function parseCursorConversation(filePath, account) {
1988
2338
  messages.push(message);
1989
2339
  if (!message.text) continue;
1990
2340
  textParts.push(message.text);
1991
- if (message.role === "user") lastUserText = message.text;
2341
+ if (message.role === "user") {
2342
+ lastUserText = message.text;
2343
+ if (nameSlots.firstUserMessage === void 0) {
2344
+ nameSlots = applyNameCandidate(
2345
+ nameSlots,
2346
+ "firstUserMessage",
2347
+ cursorUserQuery(cursorLineContent(line)),
2348
+ CURSOR_PROVIDER
2349
+ );
2350
+ }
2351
+ }
1992
2352
  }
1993
2353
  } catch (err) {
1994
2354
  log.warn({ filePath, err }, "parseCursorConversation: read failed");
@@ -1996,14 +2356,14 @@ async function parseCursorConversation(filePath, account) {
1996
2356
  }
1997
2357
  if (messages.length === 0) return null;
1998
2358
  const { projectPath, projectName } = projectFromCursorPath(filePath);
1999
- const sessionId = basename5(filePath, ".jsonl");
2359
+ const sessionId = basename6(filePath, ".jsonl");
2000
2360
  return {
2001
2361
  id: filePath,
2002
2362
  filePath,
2003
2363
  projectPath,
2004
2364
  projectName,
2005
2365
  sessionId,
2006
- sessionName: "",
2366
+ sessionName: resolveSessionName({ ...nameSlots, ...cursorNameSlotsFor(filePath, sessionId) }).name ?? "",
2007
2367
  messages,
2008
2368
  fullText: textParts.join(" "),
2009
2369
  timestamp: latestTimestamp || fileMtimeIso2(filePath),
@@ -2117,9 +2477,9 @@ var ThreadbaseProvider = class {
2117
2477
 
2118
2478
  // src/scanner.ts
2119
2479
  import { EventEmitter } from "events";
2120
- import { closeSync as closeSync2, openSync as openSync2, readSync as readSync2, statSync as statSync5 } from "fs";
2480
+ import { closeSync as closeSync3, openSync as openSync3, readSync as readSync3, statSync as statSync6 } from "fs";
2121
2481
  import { homedir as homedir2 } from "os";
2122
- import { join as join6 } from "path";
2482
+ import { join as join7 } from "path";
2123
2483
 
2124
2484
  // src/cache.ts
2125
2485
  var LRUCache = class {
@@ -2158,7 +2518,7 @@ var LRUCache = class {
2158
2518
  };
2159
2519
 
2160
2520
  // src/persistent/conversation-stream.ts
2161
- import { basename as basename6 } from "path";
2521
+ import { basename as basename7 } from "path";
2162
2522
 
2163
2523
  // src/persistent/paged-reader.ts
2164
2524
  import { createReadStream as createReadStream6 } from "fs";
@@ -2295,7 +2655,7 @@ async function foldTail(filePath, resume) {
2295
2655
  resume.state,
2296
2656
  (message) => {
2297
2657
  messages.push(message);
2298
- if (message.text) textParts.push(message.text);
2658
+ if (message.text && !message.isCompactSummary) textParts.push(message.text);
2299
2659
  return false;
2300
2660
  },
2301
2661
  (entry) => {
@@ -2318,8 +2678,8 @@ function assemble(filePath, account, messages, fullText, turnDurations, state) {
2318
2678
  filePath,
2319
2679
  projectPath: state.cwd,
2320
2680
  projectName: getShortProjectName2(state.cwd),
2321
- sessionId: state.sessionId || basename6(filePath, ".jsonl"),
2322
- sessionName: state.sessionName || deriveSessionNameFromFirstMessage(messages.find((m) => m.role === "user" && m.text) ?? null),
2681
+ sessionId: state.sessionId || basename7(filePath, ".jsonl"),
2682
+ sessionName: resolveSessionName(state.nameSlots).name ?? "",
2323
2683
  messages,
2324
2684
  fullText,
2325
2685
  timestamp: state.latestTimestamp || (/* @__PURE__ */ new Date()).toISOString(),
@@ -2363,33 +2723,33 @@ async function extendConversation(previous, resume, filePath, account) {
2363
2723
 
2364
2724
  // src/persistent/cursor.ts
2365
2725
  import { createHash as createHash2 } from "crypto";
2366
- import { closeSync, openSync, readSync, statSync as statSync3 } from "fs";
2726
+ import { closeSync as closeSync2, openSync as openSync2, readSync as readSync2, statSync as statSync4 } from "fs";
2367
2727
  var FP_BYTES = 4096;
2368
2728
  function fingerprint(filePath, size) {
2369
2729
  const hash = createHash2("sha1");
2370
2730
  hash.update(String(size));
2371
- const fd = openSync(filePath, "r");
2731
+ const fd = openSync2(filePath, "r");
2372
2732
  try {
2373
2733
  const head = Buffer.alloc(Math.min(FP_BYTES, size));
2374
2734
  if (head.length > 0) {
2375
- readSync(fd, head, 0, head.length, 0);
2735
+ readSync2(fd, head, 0, head.length, 0);
2376
2736
  hash.update(head);
2377
2737
  }
2378
2738
  if (size > FP_BYTES) {
2379
2739
  const tailLen = Math.min(FP_BYTES, size);
2380
2740
  const tail = Buffer.alloc(tailLen);
2381
- readSync(fd, tail, 0, tailLen, size - tailLen);
2741
+ readSync2(fd, tail, 0, tailLen, size - tailLen);
2382
2742
  hash.update(tail);
2383
2743
  }
2384
2744
  } finally {
2385
- closeSync(fd);
2745
+ closeSync2(fd);
2386
2746
  }
2387
2747
  return hash.digest("hex");
2388
2748
  }
2389
2749
  function classify(filePath, existing) {
2390
2750
  let stat6;
2391
2751
  try {
2392
- const s = statSync3(filePath);
2752
+ const s = statSync4(filePath);
2393
2753
  stat6 = { size: s.size, mtimeMs: s.mtimeMs };
2394
2754
  } catch {
2395
2755
  return { change: "vanished" };
@@ -2417,12 +2777,12 @@ function classify(filePath, existing) {
2417
2777
  }
2418
2778
 
2419
2779
  // src/persistent/index-engine.ts
2420
- import { statSync as statSync4 } from "fs";
2780
+ import { statSync as statSync5 } from "fs";
2421
2781
 
2422
2782
  // src/providers/parse.ts
2423
2783
  import { createReadStream as createReadStream7 } from "fs";
2424
2784
  import { createInterface as createInterface5 } from "readline";
2425
- async function parseMetaWithProvider(provider, filePath, account, tier, onEntry) {
2785
+ async function parseMetaWithProvider(provider, filePath, account, tier, onEntry, onAccumulator) {
2426
2786
  const log = getLogger();
2427
2787
  const acc = provider.createEmptyAccumulator();
2428
2788
  const rl = createInterface5({
@@ -2449,6 +2809,7 @@ async function parseMetaWithProvider(provider, filePath, account, tier, onEntry)
2449
2809
  log.warn({ filePath, provider: provider.name, err }, "provider parse: read failed");
2450
2810
  return null;
2451
2811
  }
2812
+ onAccumulator?.(acc);
2452
2813
  return provider.finalize(acc, filePath, account, tier);
2453
2814
  }
2454
2815
 
@@ -2649,12 +3010,12 @@ function resolveTier(tierName, customTiers) {
2649
3010
  }
2650
3011
 
2651
3012
  // src/persistent/db.ts
2652
- import Database from "better-sqlite3";
3013
+ import Database2 from "better-sqlite3";
2653
3014
  import { mkdirSync } from "fs";
2654
- import { dirname as dirname5 } from "path";
3015
+ import { dirname as dirname6 } from "path";
2655
3016
 
2656
3017
  // src/persistent/schema.ts
2657
- var SCHEMA_VERSION = 10;
3018
+ var SCHEMA_VERSION = 11;
2658
3019
  var SCHEMA_SQL = `
2659
3020
  CREATE TABLE IF NOT EXISTS conversation_files (
2660
3021
  id INTEGER PRIMARY KEY AUTOINCREMENT,
@@ -2700,6 +3061,9 @@ CREATE TABLE IF NOT EXISTS conversations (
2700
3061
  external_session_id TEXT,
2701
3062
  session_id TEXT NOT NULL,
2702
3063
  session_name TEXT,
3064
+ -- JSON NameSlots the name was resolved from; lets a side-store change
3065
+ -- re-resolve the name without reparsing the transcript.
3066
+ name_slots TEXT,
2703
3067
 
2704
3068
  project_path TEXT,
2705
3069
  project_name TEXT,
@@ -2962,6 +3326,27 @@ function runMigrations(db) {
2962
3326
  db.exec(`UPDATE conversation_files SET ${assignments.join(", ")}`);
2963
3327
  }
2964
3328
  }
3329
+ if (current >= 1 && current < 11 && tableExists(db, "conversations")) {
3330
+ if (tableExists(db, "message_checkpoints")) db.exec("DELETE FROM message_checkpoints");
3331
+ if (!hasColumn(db, "conversations", "name_slots")) {
3332
+ db.exec("ALTER TABLE conversations ADD COLUMN name_slots TEXT");
3333
+ }
3334
+ if (tableExists(db, "conversation_files")) {
3335
+ const assignments = [];
3336
+ if (hasColumn(db, "conversation_files", "last_indexed_offset")) {
3337
+ assignments.push("last_indexed_offset = 0");
3338
+ }
3339
+ if (hasColumn(db, "conversation_files", "last_indexed_line")) {
3340
+ assignments.push("last_indexed_line = 0");
3341
+ }
3342
+ if (hasColumn(db, "conversation_files", "reducer_state")) {
3343
+ assignments.push("reducer_state = NULL");
3344
+ }
3345
+ if (assignments.length > 0) {
3346
+ db.exec(`UPDATE conversation_files SET ${assignments.join(", ")}`);
3347
+ }
3348
+ }
3349
+ }
2965
3350
  db.exec(SCHEMA_SQL);
2966
3351
  db.pragma(`user_version = ${SCHEMA_VERSION}`);
2967
3352
  }
@@ -2976,11 +3361,11 @@ function hasColumn(db, table, column) {
2976
3361
  // src/persistent/db.ts
2977
3362
  function openDatabase(dbPath) {
2978
3363
  if (dbPath !== ":memory:") {
2979
- mkdirSync(dirname5(dbPath), { recursive: true });
3364
+ mkdirSync(dirname6(dbPath), { recursive: true });
2980
3365
  }
2981
3366
  let db;
2982
3367
  try {
2983
- db = new Database(dbPath);
3368
+ db = new Database2(dbPath);
2984
3369
  } catch (err) {
2985
3370
  if (isNativeBindingFailure(err)) throw nativeBindingError(err, dbPath);
2986
3371
  throw err;
@@ -3021,7 +3406,7 @@ function nativeBindingError(err, dbPath) {
3021
3406
 
3022
3407
  // src/persistent/dir-watermark.ts
3023
3408
  import { readdir, stat as stat5 } from "fs/promises";
3024
- import { dirname as dirname6, join as join5 } from "path";
3409
+ import { dirname as dirname7, join as join6 } from "path";
3025
3410
  var FULL_RECONCILE_EVERY_N_SCANS = 20;
3026
3411
  async function discoverJsonlFilesGated(dirs, files, scannedDirs, options = {}) {
3027
3412
  const log = getLogger();
@@ -3092,10 +3477,10 @@ async function resolveProjectDirs(projectsDir, scannedDirs) {
3092
3477
  return { entries, commitRoot: { mtimeMs: rootStat.mtimeMs } };
3093
3478
  }
3094
3479
  function dirnameOf(filePath) {
3095
- return dirname6(filePath);
3480
+ return dirname7(filePath);
3096
3481
  }
3097
3482
  function joinPath(dir, name) {
3098
- return join5(dir, name);
3483
+ return join6(dir, name);
3099
3484
  }
3100
3485
 
3101
3486
  // src/persistent/repositories/checkpoints.repo.ts
@@ -3175,7 +3560,7 @@ function toCheckpoint(row) {
3175
3560
  }
3176
3561
 
3177
3562
  // src/persistent/repositories/conversation-files.repo.ts
3178
- import { basename as basename7, dirname as dirname7 } from "path";
3563
+ import { basename as basename8, dirname as dirname8 } from "path";
3179
3564
  var ConversationFilesRepo = class {
3180
3565
  constructor(db) {
3181
3566
  this.db = db;
@@ -3198,7 +3583,7 @@ var ConversationFilesRepo = class {
3198
3583
  const info = this.db.prepare(
3199
3584
  `INSERT INTO conversation_files (absolute_path, parent_dir, file_name, account)
3200
3585
  VALUES (?, ?, ?, ?)`
3201
- ).run(canonical, dirname7(canonical), basename7(canonical), account);
3586
+ ).run(canonical, dirname8(canonical), basename8(canonical), account);
3202
3587
  return Number(info.lastInsertRowid);
3203
3588
  }
3204
3589
  // Advance the cursor + persisted reducer state after a successful index pass.
@@ -3306,7 +3691,7 @@ var ConversationsRepo = class {
3306
3691
  db;
3307
3692
  // Upsert by file_id (1 file = 1 conversation). Keyed on the unique file_id so
3308
3693
  // a re-index overwrites the prior summary in place.
3309
- upsert(fileId, meta, pageMessageCount = meta.messageCount) {
3694
+ upsert(fileId, meta, pageMessageCount = meta.messageCount, nameSlots) {
3310
3695
  this.db.prepare(
3311
3696
  `INSERT INTO conversations (
3312
3697
  file_id, source_path, provider, kind, external_session_id,
@@ -3317,7 +3702,7 @@ var ConversationsRepo = class {
3317
3702
  model, is_subagent, parent_session_id, subagent_id, parent_session_uuid,
3318
3703
  is_teammate, team_name, tool_names_json,
3319
3704
  last_prompt, is_imported_from_claude, is_imported_from_codex,
3320
- is_imported_from_cursor, status, updated_at
3705
+ is_imported_from_cursor, name_slots, status, updated_at
3321
3706
  ) VALUES (
3322
3707
  @file_id, @source_path, @provider, @kind, @external_session_id,
3323
3708
  @session_id, @session_name, @project_path, @project_name,
@@ -3329,7 +3714,7 @@ var ConversationsRepo = class {
3329
3714
  @model, @is_subagent, @parent_session_id, @subagent_id, @parent_session_uuid,
3330
3715
  @is_teammate, @team_name, @tool_names_json,
3331
3716
  @last_prompt, @is_imported_from_claude, @is_imported_from_codex,
3332
- @is_imported_from_cursor, 'active', CURRENT_TIMESTAMP
3717
+ @is_imported_from_cursor, @name_slots, 'active', CURRENT_TIMESTAMP
3333
3718
  )
3334
3719
  ON CONFLICT(file_id) DO UPDATE SET
3335
3720
  source_path = excluded.source_path,
@@ -3364,6 +3749,7 @@ var ConversationsRepo = class {
3364
3749
  is_imported_from_claude = excluded.is_imported_from_claude,
3365
3750
  is_imported_from_codex = excluded.is_imported_from_codex,
3366
3751
  is_imported_from_cursor = excluded.is_imported_from_cursor,
3752
+ name_slots = excluded.name_slots,
3367
3753
  status = 'active',
3368
3754
  index_seq = (SELECT COALESCE(MAX(index_seq), 0) + 1 FROM conversations),
3369
3755
  updated_at = CURRENT_TIMESTAMP`
@@ -3403,7 +3789,8 @@ var ConversationsRepo = class {
3403
3789
  last_prompt: meta.lastPrompt ?? null,
3404
3790
  is_imported_from_claude: meta.isImportedFromClaude ? 1 : 0,
3405
3791
  is_imported_from_codex: meta.isImportedFromCodex ? 1 : 0,
3406
- is_imported_from_cursor: meta.isImportedFromCursor ? 1 : 0
3792
+ is_imported_from_cursor: meta.isImportedFromCursor ? 1 : 0,
3793
+ name_slots: nameSlots ? JSON.stringify(nameSlots) : null
3407
3794
  });
3408
3795
  }
3409
3796
  getBySourcePath(sourcePath) {
@@ -3784,13 +4171,18 @@ var PersistentEngine = class {
3784
4171
  const tier = resolveTier(tierName, customTiers);
3785
4172
  const filePath = canonicalPath(rawFilePath);
3786
4173
  const existing = this.files.getByPath(filePath);
3787
- const { change, stat: stat6 } = classify(filePath, existing);
4174
+ const classified = classify(filePath, existing);
4175
+ const stat6 = classified.stat;
4176
+ let change = classified.change;
3788
4177
  if (change === "vanished" || !stat6) {
3789
4178
  this.markDeleted(filePath);
3790
4179
  return { meta: null, change: "vanished" };
3791
4180
  }
3792
4181
  if (change === "unchanged" && !force) {
3793
- return { meta: this.conversations.getBySourcePath(filePath), change };
4182
+ const meta2 = this.conversations.getBySourcePath(filePath);
4183
+ const sideStoresMoved = provider && provider.name !== CLAUDE_CODE_PROVIDER && meta2 && JSON.stringify(nameStoreSlotsFor(provider.name, filePath, meta2.sessionId)) !== existing?.reducer_state;
4184
+ if (!sideStoresMoved) return { meta: meta2, change };
4185
+ change = "reindex";
3794
4186
  }
3795
4187
  if (provider && provider.name !== CLAUDE_CODE_PROVIDER) {
3796
4188
  const meta2 = await this.indexFileWithProvider(
@@ -3829,7 +4221,7 @@ var PersistentEngine = class {
3829
4221
  const base = resume ? this.fts.readDocument(fileId) ?? emptySearchDocument() : emptySearchDocument();
3830
4222
  const searchDoc = appendSearchDelta(base, searchDelta);
3831
4223
  const upsert = this.db.transaction(() => {
3832
- this.conversations.upsert(fileId, meta, state.pageMessageCount);
4224
+ this.conversations.upsert(fileId, meta, state.pageMessageCount, state.nameSlots);
3833
4225
  if (!this.fts.isCurrent(fileId, meta, searchDoc)) {
3834
4226
  this.fts.upsert(fileId, meta, searchDoc);
3835
4227
  }
@@ -3872,13 +4264,23 @@ var PersistentEngine = class {
3872
4264
  // provider's reducer/finalize, then the same upsert + FTS write + cursor bump
3873
4265
  // the Threadbase path uses. The cursor records size/mtime (and offset = size)
3874
4266
  // so the next pass classifies an unchanged file as "unchanged" and skips it;
3875
- // any change reparses from 0 again. No reducer_state is persisted.
4267
+ // any change reparses from 0 again. reducer_state holds the side-store name slots, not a fold.
3876
4268
  async indexFileWithProvider(provider, filePath, account, tier, stat6, resolveGitBranch) {
3877
4269
  const log = getLogger();
3878
4270
  let searchDoc = emptySearchDocument();
3879
- const meta = await parseMetaWithProvider(provider, filePath, account, tier, (entry) => {
3880
- searchDoc = appendSearchDelta(searchDoc, extractSearchDelta(entry));
3881
- });
4271
+ let transcriptSlots = {};
4272
+ const meta = await parseMetaWithProvider(
4273
+ provider,
4274
+ filePath,
4275
+ account,
4276
+ tier,
4277
+ (entry) => {
4278
+ searchDoc = appendSearchDelta(searchDoc, extractSearchDelta(entry));
4279
+ },
4280
+ (acc) => {
4281
+ transcriptSlots = acc.nameSlots ?? {};
4282
+ }
4283
+ );
3882
4284
  if (!meta) {
3883
4285
  this.markDeleted(filePath);
3884
4286
  return null;
@@ -3886,10 +4288,14 @@ var PersistentEngine = class {
3886
4288
  if (meta.gitBranch === null && meta.projectPath) {
3887
4289
  meta.gitBranch = resolveGitBranch(meta.projectPath);
3888
4290
  }
4291
+ const sideSlots = nameStoreSlotsFor(provider.name, filePath, meta.sessionId);
3889
4292
  const fp = stat6.size > 0 ? fingerprint(filePath, stat6.size) : null;
3890
4293
  const fileId = this.files.ensure(filePath, account);
3891
4294
  const upsert = this.db.transaction(() => {
3892
- this.conversations.upsert(fileId, meta, meta.messageCount);
4295
+ this.conversations.upsert(fileId, meta, meta.messageCount, {
4296
+ ...transcriptSlots,
4297
+ ...sideSlots
4298
+ });
3893
4299
  if (!this.fts.isCurrent(fileId, meta, searchDoc)) {
3894
4300
  this.fts.upsert(fileId, meta, searchDoc);
3895
4301
  }
@@ -3901,7 +4307,9 @@ var PersistentEngine = class {
3901
4307
  // can classify it "unchanged"); no resumable reducer state is kept.
3902
4308
  offset: stat6.size,
3903
4309
  line: 0,
3904
- reducerState: null,
4310
+ // Not resumable state: the side-store name slots this parse used, so the
4311
+ // next pass can tell when they moved (see indexFile).
4312
+ reducerState: JSON.stringify(sideSlots),
3905
4313
  fingerprint: fp,
3906
4314
  status: "active"
3907
4315
  });
@@ -3981,7 +4389,7 @@ var PersistentEngine = class {
3981
4389
  let floor = this.checkpoints.floor(filePath, fromIndex);
3982
4390
  if (floor) {
3983
4391
  try {
3984
- if (floor.byteOffset > statSync4(filePath).size) floor = null;
4392
+ if (floor.byteOffset > statSync5(filePath).size) floor = null;
3985
4393
  } catch {
3986
4394
  }
3987
4395
  }
@@ -4120,7 +4528,7 @@ function defaultDbPath() {
4120
4528
  "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."
4121
4529
  );
4122
4530
  }
4123
- return join6(homedir2(), ".config", "threadbase-scanner", "index.db");
4531
+ return join7(homedir2(), ".config", "threadbase-scanner", "index.db");
4124
4532
  }
4125
4533
  function capForMemory(doc, max) {
4126
4534
  const combined = combineSearchContent(doc);
@@ -4213,6 +4621,7 @@ var ConversationScanner = class {
4213
4621
  }
4214
4622
  }
4215
4623
  async runScan(options) {
4624
+ if (options.cursorStateDb !== void 0) setCursorStateDb(options.cursorStateDb);
4216
4625
  const profiles = await this.resolveProfiles(options.profiles);
4217
4626
  const activeProfiles = profiles.filter((p) => p.enabled && p.scanHistory !== false);
4218
4627
  this.lastTier = resolveTier(options.tier ?? "standard", options.tiers);
@@ -4299,7 +4708,7 @@ var ConversationScanner = class {
4299
4708
  const cached = statCache.get(filePath);
4300
4709
  if (cached) {
4301
4710
  try {
4302
- const s = statSync5(filePath);
4711
+ const s = statSync6(filePath);
4303
4712
  if (s.mtimeMs === cached.stat.mtimeMs && s.size === cached.stat.size) {
4304
4713
  return {
4305
4714
  meta: cached.meta,
@@ -4847,13 +5256,13 @@ var ConversationScanner = class {
4847
5256
  if (previous?.provider) return void 0;
4848
5257
  let sample = "";
4849
5258
  try {
4850
- const fd = openSync2(filePath, "r");
5259
+ const fd = openSync3(filePath, "r");
4851
5260
  try {
4852
5261
  const buf = Buffer.alloc(8192);
4853
- const n = readSync2(fd, buf, 0, buf.length, 0);
5262
+ const n = readSync3(fd, buf, 0, buf.length, 0);
4854
5263
  sample = buf.subarray(0, n).toString("utf8");
4855
5264
  } finally {
4856
- closeSync2(fd);
5265
+ closeSync3(fd);
4857
5266
  }
4858
5267
  } catch {
4859
5268
  return void 0;
@@ -4980,11 +5389,13 @@ export {
4980
5389
  CursorProvider,
4981
5390
  DEFAULT_TIERS,
4982
5391
  LEGACY_CURSOR_PROVIDER,
5392
+ NAME_PRECEDENCE,
4983
5393
  SearchIndexer,
4984
5394
  ThreadbaseProvider,
4985
5395
  VALID_SORT_ORDERS,
4986
5396
  applyAccountFilter,
4987
5397
  applyIncludeFilter,
5398
+ applyNameCandidate,
4988
5399
  applyPagination,
4989
5400
  applyProjectFilter,
4990
5401
  applySinceFilter,
@@ -4999,20 +5410,27 @@ export {
4999
5410
  getLogger,
5000
5411
  getProjectsDir,
5001
5412
  isCodexInjectedContext,
5413
+ isValidNameCandidate,
5002
5414
  loadProfiles,
5003
5415
  parseCodexJsonlLine,
5004
5416
  parseCopilotJsonlLine,
5005
5417
  parseCursorJsonlLine,
5006
5418
  parseJsonlLine,
5007
5419
  providerMatches,
5420
+ readCodexNameSlots,
5421
+ readCopilotNameSlots,
5422
+ readCursorCliNameSlots,
5423
+ readCursorIdeNameSlots,
5008
5424
  readGitBranch,
5009
5425
  readSidecar,
5010
5426
  resetDefaultScanner,
5011
5427
  resolveConfigDir,
5428
+ resolveSessionName,
5012
5429
  resolveTier,
5013
5430
  saveProfiles,
5014
5431
  scan,
5015
5432
  search,
5433
+ setCursorStateDb,
5016
5434
  setLogger,
5017
5435
  sidecarPath,
5018
5436
  unwrapCursorUserText