@threadbase-sh/scanner 0.24.7 → 0.25.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.
package/dist/index.js CHANGED
@@ -666,203 +666,7 @@ function nameStoreSlotsFor(provider, filePath, sessionId) {
666
666
  }
667
667
  }
668
668
 
669
- // src/parser.ts
670
- import { createReadStream } from "fs";
671
- import { basename as basename3 } from "path";
672
- import { createInterface } from "readline";
673
-
674
- // src/persistent/metadata-reducer.ts
675
- import { basename as basename2, dirname as dirname3, join as join3 } from "path";
676
-
677
- // src/providers/provider.ts
678
- var CLAUDE_CODE_PROVIDER = "claude-code";
679
- var CODEX_CLI_PROVIDER = "codex-cli";
680
- var CURSOR_PROVIDER = "cursor";
681
- var COPILOT_PROVIDER = "copilot";
682
- var LEGACY_CURSOR_PROVIDER = "cursor-cli";
683
- function canonicalizeProviderName(value) {
684
- if (value === LEGACY_CURSOR_PROVIDER) return CURSOR_PROVIDER;
685
- if (value === CLAUDE_CODE_PROVIDER || value === CODEX_CLI_PROVIDER || value === CURSOR_PROVIDER || value === COPILOT_PROVIDER) {
686
- return value;
687
- }
688
- return void 0;
689
- }
690
- function canonicalizeProviderList(providers) {
691
- const src = providers ?? [CLAUDE_CODE_PROVIDER];
692
- const out = [];
693
- for (const p of src) {
694
- const n = canonicalizeProviderName(p);
695
- if (n && !out.includes(n)) out.push(n);
696
- }
697
- return out;
698
- }
699
- function providerMatches(stored, wanted) {
700
- const a = canonicalizeProviderName(stored ?? CLAUDE_CODE_PROVIDER) ?? stored;
701
- const b = canonicalizeProviderName(wanted) ?? wanted;
702
- return a === b;
703
- }
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
-
730
- // src/persistent/metadata-reducer.ts
731
- function initialReducerState() {
732
- return {
733
- sessionId: "",
734
- nameSlots: {},
735
- latestTimestamp: "",
736
- cwd: "",
737
- teamName: "",
738
- model: null,
739
- messageCount: 0,
740
- lastMessageSender: "user",
741
- agentId: "",
742
- isSidechain: false,
743
- firstMessage: null,
744
- lastMessage: null,
745
- lastPrompt: "",
746
- pageMessageCount: 0,
747
- toolNames: [],
748
- previewParts: [],
749
- snippetParts: [],
750
- previewLength: 0,
751
- snippetLength: 0,
752
- badJsonLines: 0,
753
- turnDurations: []
754
- };
755
- }
756
- function reduceLine(state, rawEntry, tier) {
757
- const entry = asQueuedPromptUserEntry(rawEntry);
758
- if (entry.cwd && !state.cwd) state.cwd = entry.cwd;
759
- if (entry.sessionId && !state.sessionId) state.sessionId = entry.sessionId;
760
- state.nameSlots = applyClaudeNameEntry(state.nameSlots, entry);
761
- if (entry.teamName && !state.teamName) state.teamName = entry.teamName;
762
- if (entry.agentId && !state.agentId) state.agentId = entry.agentId;
763
- if (entry.isSidechain === true) state.isSidechain = true;
764
- if (entry.timestamp) {
765
- const ts = entry.timestamp;
766
- if (!state.latestTimestamp || ts > state.latestTimestamp) state.latestTimestamp = ts;
767
- }
768
- const turnDuration = turnDurationOf(entry);
769
- if (turnDuration) state.turnDurations?.push(turnDuration);
770
- const type = entry.type;
771
- if (type === "last-prompt") {
772
- if (entry.lastPrompt && !state.lastPrompt) state.lastPrompt = entry.lastPrompt;
773
- return;
774
- }
775
- if (type !== "user" && type !== "assistant") return;
776
- if (entry.isMeta) return;
777
- const msg = entry.message;
778
- if (entry.isCompactSummary === true) {
779
- if (extractTextContent(msg?.content)) state.pageMessageCount++;
780
- return;
781
- }
782
- if (state.model === null && msg?.model) state.model = msg.model;
783
- const content = extractTextContent(msg?.content);
784
- const hasToolUseResult = type === "user" && entry.toolUseResult != null;
785
- const isOnlyToolResult = hasToolUseResult && isOnlyToolResultContent(msg?.content);
786
- const toolSet = new Set(state.toolNames);
787
- collectToolNames(msg?.content, toolSet);
788
- state.toolNames = Array.from(toolSet);
789
- const toolUseBlocks = extractToolUseBlocks(msg?.content);
790
- const thinking = type === "assistant" ? extractThinking(msg?.content) : null;
791
- const hasThinking = !!(thinking?.content || thinking?.signature);
792
- if (content || isOnlyToolResult || toolUseBlocks.length > 0 || hasThinking) {
793
- state.pageMessageCount++;
794
- }
795
- if (content || isOnlyToolResult) {
796
- state.messageCount++;
797
- state.lastMessageSender = type;
798
- if (content) {
799
- const ts = entry.timestamp || "";
800
- if (!state.firstMessage) state.firstMessage = { text: content.slice(0, 200), timestamp: ts };
801
- state.lastMessage = { text: content.slice(0, 200), timestamp: ts };
802
- if (state.previewLength < tier.previewMax) {
803
- state.previewParts.push(content);
804
- state.previewLength += content.length;
805
- }
806
- if (state.snippetLength < tier.snippetMax) {
807
- const remaining = tier.snippetMax - state.snippetLength;
808
- const chunk = content.length > remaining ? content.slice(0, remaining) : content;
809
- state.snippetParts.push(chunk);
810
- state.snippetLength += chunk.length;
811
- }
812
- }
813
- }
814
- }
815
- function finalizeMeta(state, filePath, account, tier) {
816
- if (state.messageCount === 0) return null;
817
- const isSidechain = state.isSidechain && !!state.agentId;
818
- const isSubagentPath = SUBAGENT_PATH_RE.test(filePath);
819
- const isSubagent = isSidechain || isSubagentPath;
820
- let parentSessionId = null;
821
- if (isSubagentPath) {
822
- const uuidDir = dirname3(dirname3(filePath));
823
- parentSessionId = join3(dirname3(uuidDir), `${basename2(uuidDir)}.jsonl`);
824
- }
825
- const projectPath = state.cwd;
826
- return {
827
- id: filePath,
828
- filePath,
829
- provider: CLAUDE_CODE_PROVIDER,
830
- sessionId: state.sessionId || basename2(filePath, ".jsonl"),
831
- sessionName: resolveSessionName(state.nameSlots).name ?? "",
832
- nameSlots: state.nameSlots,
833
- projectPath,
834
- projectName: getShortProjectName(projectPath),
835
- account,
836
- timestamp: state.latestTimestamp || (/* @__PURE__ */ new Date()).toISOString(),
837
- messageCount: state.messageCount,
838
- lastMessageSender: state.lastMessageSender,
839
- preview: state.previewParts.join(" ").slice(0, tier.previewMax),
840
- contentSnippet: state.snippetParts.join(" "),
841
- gitBranch: null,
842
- model: state.model,
843
- isSubagent,
844
- parentSessionId,
845
- subagentId: isSidechain ? state.agentId : void 0,
846
- // A sidechain line's `sessionId` IS the parent's id — that is exactly the
847
- // conflation `subagentId` exists to undo, so it is the parent UUID here.
848
- parentSessionUuid: isSidechain && state.sessionId ? state.sessionId : void 0,
849
- // A teammate's records carry teamName; the lead's never do, yet the lead
850
- // receives <teammate-message> tags too, so the tag is not the discriminator.
851
- isTeammate: Boolean(state.teamName),
852
- teamName: state.teamName || null,
853
- toolNames: state.toolNames,
854
- firstMessage: state.firstMessage,
855
- lastMessage: state.lastMessage,
856
- lastPrompt: state.lastPrompt || void 0
857
- };
858
- }
859
- var SUBAGENT_PATH_RE = /[\\/]subagents[\\/]/;
860
- function getShortProjectName(fullPath) {
861
- const parts = fullPath.split("/").filter(Boolean);
862
- return parts.slice(-3).join("/");
863
- }
864
-
865
- // src/parser.ts
669
+ // src/parse-helpers.ts
866
670
  function asQueuedPromptUserEntry(entry) {
867
671
  if (entry.type !== "attachment") return entry;
868
672
  const att = entry.attachment;
@@ -875,109 +679,6 @@ function asQueuedPromptUserEntry(entry) {
875
679
  message: { role: "user", content: att.prompt }
876
680
  };
877
681
  }
878
- function turnDurationOf(entry) {
879
- if (entry.type !== "system" || entry.subtype !== "turn_duration" || typeof entry.durationMs !== "number") {
880
- return null;
881
- }
882
- return {
883
- durationMs: entry.durationMs,
884
- messageCount: entry.messageCount || 0,
885
- uuid: entry.uuid
886
- };
887
- }
888
- async function parseMeta(filePath, account, tier, onEntry) {
889
- const log = getLogger();
890
- log.trace({ filePath, account, tier: tier.name }, "parseMeta: start");
891
- const state = initialReducerState();
892
- const fileStream = createReadStream(filePath);
893
- const rl = createInterface({ input: fileStream, crlfDelay: Infinity });
894
- try {
895
- for await (const line of rl) {
896
- if (!line.trim()) continue;
897
- let entry;
898
- try {
899
- entry = JSON.parse(line);
900
- } catch {
901
- state.badJsonLines++;
902
- continue;
903
- }
904
- reduceLine(state, entry, tier);
905
- onEntry?.(entry);
906
- }
907
- } catch (err) {
908
- log.warn({ filePath, err }, "parseMeta: read failed");
909
- return null;
910
- }
911
- if (state.badJsonLines > 0) {
912
- log.warn(
913
- { filePath, badJsonLines: state.badJsonLines },
914
- "parseMeta: skipped malformed JSON lines"
915
- );
916
- }
917
- const meta = finalizeMeta(state, filePath, account, tier);
918
- if (!meta) log.trace({ filePath }, "parseMeta: no messages");
919
- return meta;
920
- }
921
- async function parseConversation(filePath, account) {
922
- const log = getLogger();
923
- log.trace({ filePath, account }, "parseConversation: start");
924
- const messages = [];
925
- let badJsonLines = 0;
926
- const textParts = [];
927
- const turnDurations = [];
928
- const state = initialConvState();
929
- const fileStream = createReadStream(filePath);
930
- const rl = createInterface({ input: fileStream, crlfDelay: Infinity });
931
- try {
932
- for await (const line of rl) {
933
- if (!line.trim()) continue;
934
- let entry;
935
- try {
936
- entry = JSON.parse(line);
937
- } catch {
938
- badJsonLines++;
939
- continue;
940
- }
941
- const turnDuration = turnDurationOf(entry);
942
- if (turnDuration) {
943
- turnDurations.push(turnDuration);
944
- continue;
945
- }
946
- const message = reduceConvLine(state, entry);
947
- if (message) {
948
- messages.push(message);
949
- if (message.text && !message.isCompactSummary) textParts.push(message.text);
950
- }
951
- }
952
- } catch (err) {
953
- log.warn({ filePath, err }, "parseConversation: read failed");
954
- return null;
955
- }
956
- if (badJsonLines > 0) {
957
- log.warn({ filePath, badJsonLines }, "parseConversation: skipped malformed JSON lines");
958
- }
959
- if (messages.length === 0) {
960
- log.trace({ filePath }, "parseConversation: no messages");
961
- return null;
962
- }
963
- log.debug({ filePath, messageCount: messages.length }, "parseConversation: complete");
964
- applyTeamInfo(messages, state);
965
- return {
966
- id: filePath,
967
- filePath,
968
- projectPath: state.cwd,
969
- projectName: getShortProjectName2(state.cwd),
970
- sessionId: state.sessionId || basename3(filePath, ".jsonl"),
971
- sessionName: resolveSessionName(state.nameSlots).name ?? "",
972
- messages,
973
- fullText: textParts.join(" "),
974
- timestamp: state.latestTimestamp || (/* @__PURE__ */ new Date()).toISOString(),
975
- messageCount: messages.length,
976
- account,
977
- turnDurations: turnDurations.length > 0 ? turnDurations : void 0,
978
- lastPrompt: state.lastPrompt || void 0
979
- };
980
- }
981
682
  function extractTextContent(content) {
982
683
  if (!content) return "";
983
684
  if (typeof content === "string") return cleanSystemTags(content);
@@ -1026,14 +727,6 @@ function extractToolResultBlocks(content, pendingToolUses) {
1026
727
  };
1027
728
  });
1028
729
  }
1029
- function collectToolNames(content, toolSet) {
1030
- if (!Array.isArray(content)) return;
1031
- for (const item of content) {
1032
- if (item?.type === "tool_use" && item?.name) {
1033
- toolSet.add(item.name);
1034
- }
1035
- }
1036
- }
1037
730
  function isOnlyToolResultContent(content) {
1038
731
  if (!Array.isArray(content)) return false;
1039
732
  return content.length > 0 && content.every((item) => item?.type === "tool_result");
@@ -1062,9 +755,30 @@ function parseTeammateMessageTag(content) {
1062
755
  const color = attrs.match(/color="([^"]*)"/)?.[1];
1063
756
  return { teammateId: id, summary, color };
1064
757
  }
1065
- function getShortProjectName2(fullPath) {
1066
- const parts = fullPath.split("/").filter(Boolean);
1067
- return parts.slice(-3).join("/");
758
+
759
+ // src/persistent/claude-name-slots.ts
760
+ function userPromptText(entry) {
761
+ if (entry.isMeta || entry.isCompactSummary === true) return "";
762
+ const content = entry.message?.content;
763
+ if (typeof content === "string") return content;
764
+ if (!Array.isArray(content)) return "";
765
+ return content.map((b) => typeof b === "string" ? b : b?.type === "text" ? b.text : "").filter((t) => typeof t === "string" && t !== "").join(" ");
766
+ }
767
+ function applyClaudeNameEntry(slots, entry) {
768
+ const apply = (slot, raw) => applyNameCandidate(slots, slot, typeof raw === "string" ? raw : void 0, "claude-code");
769
+ if (entry.slug !== slots.slug) slots = apply("slug", entry.slug);
770
+ switch (entry.type) {
771
+ case "custom-title":
772
+ return apply("userTitle", entry.customTitle);
773
+ case "ai-title":
774
+ return apply("toolTitle", entry.aiTitle);
775
+ case "last-prompt":
776
+ return apply("lastPrompt", entry.lastPrompt);
777
+ case "user":
778
+ return slots.firstUserMessage === void 0 ? apply("firstUserMessage", userPromptText(entry)) : slots;
779
+ default:
780
+ return slots;
781
+ }
1068
782
  }
1069
783
 
1070
784
  // src/persistent/conversation-reducer.ts
@@ -1233,19 +947,19 @@ function readSidecar(jsonlPath) {
1233
947
  // src/profiles.ts
1234
948
  import { mkdir, readFile, writeFile } from "fs/promises";
1235
949
  import { homedir } from "os";
1236
- import { join as join4 } from "path";
950
+ import { join as join3 } from "path";
1237
951
  var PROFILES_FILE = "profiles.json";
1238
952
  function resolveConfigDir(configDir) {
1239
953
  return configDir.replace(/^~/, homedir());
1240
954
  }
1241
955
  function getProjectsDir(profile) {
1242
- return join4(resolveConfigDir(profile.configDir), "projects");
956
+ return join3(resolveConfigDir(profile.configDir), "projects");
1243
957
  }
1244
958
  async function detectDefaultProfile() {
1245
959
  return {
1246
960
  id: "default",
1247
961
  label: "Default",
1248
- configDir: join4(homedir(), ".claude"),
962
+ configDir: join3(homedir(), ".claude"),
1249
963
  enabled: true,
1250
964
  emoji: "\u{1F916}"
1251
965
  };
@@ -1254,7 +968,7 @@ async function loadProfiles(configPath) {
1254
968
  const log = getLogger();
1255
969
  try {
1256
970
  const resolved = resolveConfigDir(configPath);
1257
- const data = await readFile(join4(resolved, PROFILES_FILE), "utf-8");
971
+ const data = await readFile(join3(resolved, PROFILES_FILE), "utf-8");
1258
972
  const profiles = JSON.parse(data);
1259
973
  log.debug({ configPath, count: profiles.length }, "profiles: loaded");
1260
974
  return profiles;
@@ -1267,16 +981,16 @@ async function loadProfiles(configPath) {
1267
981
  async function saveProfiles(profiles, configPath) {
1268
982
  const resolved = resolveConfigDir(configPath);
1269
983
  await mkdir(resolved, { recursive: true });
1270
- await writeFile(join4(resolved, PROFILES_FILE), JSON.stringify(profiles, null, 2));
984
+ await writeFile(join3(resolved, PROFILES_FILE), JSON.stringify(profiles, null, 2));
1271
985
  getLogger().debug({ configPath, count: profiles.length }, "profiles: saved");
1272
986
  }
1273
987
 
1274
988
  // src/providers/codex-cli.ts
1275
989
  import fg from "fast-glob";
1276
- import { createReadStream as createReadStream2 } from "fs";
990
+ import { createReadStream } from "fs";
1277
991
  import { stat } from "fs/promises";
1278
- import { basename as basename4 } from "path";
1279
- import { createInterface as createInterface2 } from "readline";
992
+ import { basename as basename2 } from "path";
993
+ import { createInterface } from "readline";
1280
994
 
1281
995
  // src/canonical-path.ts
1282
996
  import { sep } from "path";
@@ -1284,6 +998,34 @@ function canonicalPath(p) {
1284
998
  return sep === "\\" ? p.replace(/\//g, "\\") : p;
1285
999
  }
1286
1000
 
1001
+ // src/providers/provider.ts
1002
+ var CLAUDE_CODE_PROVIDER = "claude-code";
1003
+ var CODEX_CLI_PROVIDER = "codex-cli";
1004
+ var CURSOR_PROVIDER = "cursor";
1005
+ var COPILOT_PROVIDER = "copilot";
1006
+ var LEGACY_CURSOR_PROVIDER = "cursor-cli";
1007
+ function canonicalizeProviderName(value) {
1008
+ if (value === LEGACY_CURSOR_PROVIDER) return CURSOR_PROVIDER;
1009
+ if (value === CLAUDE_CODE_PROVIDER || value === CODEX_CLI_PROVIDER || value === CURSOR_PROVIDER || value === COPILOT_PROVIDER) {
1010
+ return value;
1011
+ }
1012
+ return void 0;
1013
+ }
1014
+ function canonicalizeProviderList(providers) {
1015
+ const src = providers ?? [CLAUDE_CODE_PROVIDER];
1016
+ const out = [];
1017
+ for (const p of src) {
1018
+ const n = canonicalizeProviderName(p);
1019
+ if (n && !out.includes(n)) out.push(n);
1020
+ }
1021
+ return out;
1022
+ }
1023
+ function providerMatches(stored, wanted) {
1024
+ const a = canonicalizeProviderName(stored ?? CLAUDE_CODE_PROVIDER) ?? stored;
1025
+ const b = canonicalizeProviderName(wanted) ?? wanted;
1026
+ return a === b;
1027
+ }
1028
+
1287
1029
  // src/providers/codex-cli.ts
1288
1030
  var CodexCliProvider = class {
1289
1031
  name = CODEX_CLI_PROVIDER;
@@ -1522,7 +1264,7 @@ function reduceCodexEntry(acc, entry, tier) {
1522
1264
  }
1523
1265
  function finalizeCodexMeta(acc, filePath, account, tier) {
1524
1266
  if (acc.messageCount === 0) return null;
1525
- const sessionId = acc.sessionId || basename4(filePath, ".jsonl");
1267
+ const sessionId = acc.sessionId || basename2(filePath, ".jsonl");
1526
1268
  const nameSlots = { ...acc.nameSlots, ...codexNameSlotsFor(filePath, acc.sessionId) };
1527
1269
  const projectPath = acc.cwd;
1528
1270
  const kind = acc.lastAssistant === null && acc.toolNames.length > 0 ? "task" : "conversation";
@@ -1536,7 +1278,7 @@ function finalizeCodexMeta(acc, filePath, account, tier) {
1536
1278
  sessionName: resolveSessionName(nameSlots).name ?? "",
1537
1279
  nameSlots,
1538
1280
  projectPath,
1539
- projectName: getShortProjectName3(projectPath),
1281
+ projectName: getShortProjectName(projectPath),
1540
1282
  account,
1541
1283
  timestamp: acc.latestTimestamp || (/* @__PURE__ */ new Date()).toISOString(),
1542
1284
  messageCount: acc.messageCount,
@@ -1557,7 +1299,7 @@ function finalizeCodexMeta(acc, filePath, account, tier) {
1557
1299
  lastPrompt: acc.lastUser?.text || void 0
1558
1300
  };
1559
1301
  }
1560
- function getShortProjectName3(fullPath) {
1302
+ function getShortProjectName(fullPath) {
1561
1303
  return fullPath.split("/").filter(Boolean).slice(-3).join("/");
1562
1304
  }
1563
1305
  function isSubagentSource(source) {
@@ -1580,7 +1322,7 @@ async function parseCodexConversation(filePath, account) {
1580
1322
  let latestTimestamp = "";
1581
1323
  let lastUserText = "";
1582
1324
  let nameSlots = {};
1583
- const rl = createInterface2({ input: createReadStream2(filePath), crlfDelay: Infinity });
1325
+ const rl = createInterface({ input: createReadStream(filePath), crlfDelay: Infinity });
1584
1326
  try {
1585
1327
  for await (const line of rl) {
1586
1328
  if (!line.trim()) continue;
@@ -1623,8 +1365,8 @@ async function parseCodexConversation(filePath, account) {
1623
1365
  id: filePath,
1624
1366
  filePath,
1625
1367
  projectPath: cwd,
1626
- projectName: getShortProjectName3(cwd),
1627
- sessionId: sessionId || basename4(filePath, ".jsonl"),
1368
+ projectName: getShortProjectName(cwd),
1369
+ sessionId: sessionId || basename2(filePath, ".jsonl"),
1628
1370
  sessionName: resolveSessionName({ ...nameSlots, ...codexNameSlotsFor(filePath, sessionId) }).name ?? "",
1629
1371
  messages,
1630
1372
  fullText: textParts.join(" "),
@@ -1637,10 +1379,10 @@ async function parseCodexConversation(filePath, account) {
1637
1379
 
1638
1380
  // src/providers/copilot.ts
1639
1381
  import fg2 from "fast-glob";
1640
- import { createReadStream as createReadStream3, statSync as statSync2 } from "fs";
1382
+ import { createReadStream as createReadStream2, statSync as statSync2 } from "fs";
1641
1383
  import { stat as stat2 } from "fs/promises";
1642
- import { basename as basename5, dirname as dirname4 } from "path";
1643
- import { createInterface as createInterface3 } from "readline";
1384
+ import { basename as basename3, dirname as dirname3 } from "path";
1385
+ import { createInterface as createInterface2 } from "readline";
1644
1386
  var SESSION_START = "session.start";
1645
1387
  var USER_MESSAGE = "user.message";
1646
1388
  var ASSISTANT_MESSAGE = "assistant.message";
@@ -1869,7 +1611,7 @@ function finalizeCopilotMeta(acc, filePath, account, tier) {
1869
1611
  sessionName: resolveSessionName(nameSlots).name ?? "",
1870
1612
  nameSlots,
1871
1613
  projectPath: acc.cwd,
1872
- projectName: getShortProjectName4(acc.cwd),
1614
+ projectName: getShortProjectName2(acc.cwd),
1873
1615
  account,
1874
1616
  timestamp: acc.latestTimestamp || fileMtimeIso(filePath),
1875
1617
  messageCount: acc.messageCount,
@@ -1889,9 +1631,9 @@ function finalizeCopilotMeta(acc, filePath, account, tier) {
1889
1631
  };
1890
1632
  }
1891
1633
  function sessionIdFromPath(filePath) {
1892
- return basename5(dirname4(filePath));
1634
+ return basename3(dirname3(filePath));
1893
1635
  }
1894
- function getShortProjectName4(fullPath) {
1636
+ function getShortProjectName2(fullPath) {
1895
1637
  return fullPath.split(/[/\\]/).filter(Boolean).slice(-3).join("/");
1896
1638
  }
1897
1639
  function fileMtimeIso(filePath) {
@@ -1910,7 +1652,7 @@ async function parseCopilotConversation(filePath, account) {
1910
1652
  let latestTimestamp = "";
1911
1653
  let lastUserText = "";
1912
1654
  let nameSlots = {};
1913
- const rl = createInterface3({ input: createReadStream3(filePath), crlfDelay: Infinity });
1655
+ const rl = createInterface2({ input: createReadStream2(filePath), crlfDelay: Infinity });
1914
1656
  try {
1915
1657
  for await (const line of rl) {
1916
1658
  if (!line.trim()) continue;
@@ -1953,7 +1695,7 @@ async function parseCopilotConversation(filePath, account) {
1953
1695
  id: filePath,
1954
1696
  filePath,
1955
1697
  projectPath: cwd,
1956
- projectName: getShortProjectName4(cwd),
1698
+ projectName: getShortProjectName2(cwd),
1957
1699
  sessionId: sessionId || sessionIdFromPath(filePath),
1958
1700
  sessionName: resolveSessionName({ ...nameSlots, ...copilotNameSlotsFor(filePath) }).name ?? "",
1959
1701
  messages,
@@ -1968,13 +1710,13 @@ async function parseCopilotConversation(filePath, account) {
1968
1710
  // src/providers/cursor.ts
1969
1711
  import { createHash } from "crypto";
1970
1712
  import fg3 from "fast-glob";
1971
- import { createReadStream as createReadStream4, existsSync as existsSync2, statSync as statSync3 } from "fs";
1713
+ import { createReadStream as createReadStream3, existsSync as existsSync2, statSync as statSync3 } from "fs";
1972
1714
  import { stat as stat3 } from "fs/promises";
1973
- import { basename as basename6, dirname as dirname5, join as join5, sep as sep2 } from "path";
1974
- import { createInterface as createInterface4 } from "readline";
1715
+ import { basename as basename4, dirname as dirname4, join as join4, sep as sep2 } from "path";
1716
+ import { createInterface as createInterface3 } from "readline";
1975
1717
  var TIMESTAMP_RE = /<timestamp>\s*([\s\S]*?)\s*<\/timestamp>/;
1976
1718
  var USER_QUERY_RE = /<user_query>\s*([\s\S]*?)\s*<\/user_query>/;
1977
- var SUBAGENT_PATH_RE2 = /[\\/]subagents[\\/]/;
1719
+ var SUBAGENT_PATH_RE = /[\\/]subagents[\\/]/;
1978
1720
  var CursorProvider = class {
1979
1721
  name = CURSOR_PROVIDER;
1980
1722
  async discover(roots) {
@@ -2268,9 +2010,9 @@ function reduceCursorEntry(acc, entry, tier) {
2268
2010
  }
2269
2011
  function finalizeCursorMeta(acc, filePath, account, tier) {
2270
2012
  if (acc.messageCount === 0) return null;
2271
- const sessionId = basename6(filePath, ".jsonl");
2013
+ const sessionId = basename4(filePath, ".jsonl");
2272
2014
  const nameSlots = { ...acc.nameSlots, ...cursorNameSlotsFor(filePath, sessionId) };
2273
- const isSubagent = SUBAGENT_PATH_RE2.test(filePath);
2015
+ const isSubagent = SUBAGENT_PATH_RE.test(filePath);
2274
2016
  const parent = isSubagent ? parentFromSubagentPath(filePath) : null;
2275
2017
  const { projectPath, projectName } = projectFromCursorPath(filePath);
2276
2018
  const timestamp = acc.latestTimestamp || fileMtimeIso2(filePath);
@@ -2309,23 +2051,23 @@ function finalizeCursorMeta(acc, filePath, account, tier) {
2309
2051
  };
2310
2052
  }
2311
2053
  function parentFromSubagentPath(filePath) {
2312
- const subagentsDir = dirname5(filePath);
2313
- const parentDir = dirname5(subagentsDir);
2314
- const parentSessionUuid = basename6(parentDir);
2054
+ const subagentsDir = dirname4(filePath);
2055
+ const parentDir = dirname4(subagentsDir);
2056
+ const parentSessionUuid = basename4(parentDir);
2315
2057
  if (!parentSessionUuid) return null;
2316
2058
  return {
2317
2059
  parentSessionUuid,
2318
- parentFilePath: canonicalPath(join5(parentDir, `${parentSessionUuid}.jsonl`))
2060
+ parentFilePath: canonicalPath(join4(parentDir, `${parentSessionUuid}.jsonl`))
2319
2061
  };
2320
2062
  }
2321
2063
  function projectFromCursorPath(filePath) {
2322
2064
  const parts = filePath.split(/[/\\]/);
2323
2065
  const idx = parts.lastIndexOf("agent-transcripts");
2324
- const cursorProjectDir = idx > 0 ? parts.slice(0, idx).join(sep2) : dirname5(dirname5(filePath));
2325
- const slug = basename6(cursorProjectDir);
2066
+ const cursorProjectDir = idx > 0 ? parts.slice(0, idx).join(sep2) : dirname4(dirname4(filePath));
2067
+ const slug = basename4(cursorProjectDir);
2326
2068
  const decoded = decodeCursorProjectSlug(slug);
2327
2069
  const projectPath = decoded ?? cursorProjectDir;
2328
- return { projectPath, projectName: getShortProjectName5(projectPath) || slug };
2070
+ return { projectPath, projectName: getShortProjectName3(projectPath) || slug };
2329
2071
  }
2330
2072
  function decodeCursorProjectSlug(slug) {
2331
2073
  if (!slug) return null;
@@ -2344,7 +2086,7 @@ function decodeCursorProjectSlug(slug) {
2344
2086
  let found = null;
2345
2087
  let next = i + 1;
2346
2088
  for (let j = segments.length; j > i; j--) {
2347
- const candidate = join5(acc, segments.slice(i, j).join("-"));
2089
+ const candidate = join4(acc, segments.slice(i, j).join("-"));
2348
2090
  try {
2349
2091
  if (existsSync2(candidate) && statSync3(candidate).isDirectory()) {
2350
2092
  found = candidate;
@@ -2360,7 +2102,7 @@ function decodeCursorProjectSlug(slug) {
2360
2102
  }
2361
2103
  return acc;
2362
2104
  }
2363
- function getShortProjectName5(fullPath) {
2105
+ function getShortProjectName3(fullPath) {
2364
2106
  return fullPath.split(/[/\\]/).filter(Boolean).slice(-3).join("/");
2365
2107
  }
2366
2108
  function fileMtimeIso2(filePath) {
@@ -2385,7 +2127,7 @@ async function parseCursorConversation(filePath, account) {
2385
2127
  let latestTimestamp = "";
2386
2128
  let lastUserText = "";
2387
2129
  let nameSlots = {};
2388
- const rl = createInterface4({ input: createReadStream4(filePath), crlfDelay: Infinity });
2130
+ const rl = createInterface3({ input: createReadStream3(filePath), crlfDelay: Infinity });
2389
2131
  try {
2390
2132
  for await (const line of rl) {
2391
2133
  const message = parseCursorJsonlLine(line, messages.length);
@@ -2414,7 +2156,7 @@ async function parseCursorConversation(filePath, account) {
2414
2156
  }
2415
2157
  if (messages.length === 0) return null;
2416
2158
  const { projectPath, projectName } = projectFromCursorPath(filePath);
2417
- const sessionId = basename6(filePath, ".jsonl");
2159
+ const sessionId = basename4(filePath, ".jsonl");
2418
2160
  return {
2419
2161
  id: filePath,
2420
2162
  filePath,
@@ -2497,6 +2239,264 @@ async function discoverJsonlFiles(dirs, onProgress) {
2497
2239
  return results;
2498
2240
  }
2499
2241
 
2242
+ // src/persistent/metadata-reducer.ts
2243
+ import { basename as basename6, dirname as dirname5, join as join5 } from "path";
2244
+
2245
+ // src/parser.ts
2246
+ import { createReadStream as createReadStream4 } from "fs";
2247
+ import { basename as basename5 } from "path";
2248
+ import { createInterface as createInterface4 } from "readline";
2249
+ function turnDurationOf(entry) {
2250
+ if (entry.type !== "system" || entry.subtype !== "turn_duration" || typeof entry.durationMs !== "number") {
2251
+ return null;
2252
+ }
2253
+ return {
2254
+ durationMs: entry.durationMs,
2255
+ messageCount: entry.messageCount || 0,
2256
+ uuid: entry.uuid
2257
+ };
2258
+ }
2259
+ async function parseMeta(filePath, account, tier, onEntry) {
2260
+ const log = getLogger();
2261
+ log.trace({ filePath, account, tier: tier.name }, "parseMeta: start");
2262
+ const state = initialReducerState();
2263
+ const fileStream = createReadStream4(filePath);
2264
+ const rl = createInterface4({ input: fileStream, crlfDelay: Infinity });
2265
+ try {
2266
+ for await (const line of rl) {
2267
+ if (!line.trim()) continue;
2268
+ let entry;
2269
+ try {
2270
+ entry = JSON.parse(line);
2271
+ } catch {
2272
+ state.badJsonLines++;
2273
+ continue;
2274
+ }
2275
+ reduceLine(state, entry, tier);
2276
+ onEntry?.(entry);
2277
+ }
2278
+ } catch (err) {
2279
+ log.warn({ filePath, err }, "parseMeta: read failed");
2280
+ return null;
2281
+ }
2282
+ if (state.badJsonLines > 0) {
2283
+ log.warn(
2284
+ { filePath, badJsonLines: state.badJsonLines },
2285
+ "parseMeta: skipped malformed JSON lines"
2286
+ );
2287
+ }
2288
+ const meta = finalizeMeta(state, filePath, account, tier);
2289
+ if (!meta) log.trace({ filePath }, "parseMeta: no messages");
2290
+ return meta;
2291
+ }
2292
+ async function parseConversation(filePath, account) {
2293
+ const log = getLogger();
2294
+ log.trace({ filePath, account }, "parseConversation: start");
2295
+ const messages = [];
2296
+ let badJsonLines = 0;
2297
+ const textParts = [];
2298
+ const turnDurations = [];
2299
+ const state = initialConvState();
2300
+ const fileStream = createReadStream4(filePath);
2301
+ const rl = createInterface4({ input: fileStream, crlfDelay: Infinity });
2302
+ try {
2303
+ for await (const line of rl) {
2304
+ if (!line.trim()) continue;
2305
+ let entry;
2306
+ try {
2307
+ entry = JSON.parse(line);
2308
+ } catch {
2309
+ badJsonLines++;
2310
+ continue;
2311
+ }
2312
+ const turnDuration = turnDurationOf(entry);
2313
+ if (turnDuration) {
2314
+ turnDurations.push(turnDuration);
2315
+ continue;
2316
+ }
2317
+ const message = reduceConvLine(state, entry);
2318
+ if (message) {
2319
+ messages.push(message);
2320
+ if (message.text && !message.isCompactSummary) textParts.push(message.text);
2321
+ }
2322
+ }
2323
+ } catch (err) {
2324
+ log.warn({ filePath, err }, "parseConversation: read failed");
2325
+ return null;
2326
+ }
2327
+ if (badJsonLines > 0) {
2328
+ log.warn({ filePath, badJsonLines }, "parseConversation: skipped malformed JSON lines");
2329
+ }
2330
+ if (messages.length === 0) {
2331
+ log.trace({ filePath }, "parseConversation: no messages");
2332
+ return null;
2333
+ }
2334
+ log.debug({ filePath, messageCount: messages.length }, "parseConversation: complete");
2335
+ applyTeamInfo(messages, state);
2336
+ return {
2337
+ id: filePath,
2338
+ filePath,
2339
+ projectPath: state.cwd,
2340
+ projectName: getShortProjectName4(state.cwd),
2341
+ sessionId: state.sessionId || basename5(filePath, ".jsonl"),
2342
+ sessionName: resolveSessionName(state.nameSlots).name ?? "",
2343
+ messages,
2344
+ fullText: textParts.join(" "),
2345
+ timestamp: state.latestTimestamp || (/* @__PURE__ */ new Date()).toISOString(),
2346
+ messageCount: messages.length,
2347
+ account,
2348
+ turnDurations: turnDurations.length > 0 ? turnDurations : void 0,
2349
+ lastPrompt: state.lastPrompt || void 0
2350
+ };
2351
+ }
2352
+ function collectToolNames(content, toolSet) {
2353
+ if (!Array.isArray(content)) return;
2354
+ for (const item of content) {
2355
+ if (item?.type === "tool_use" && item?.name) {
2356
+ toolSet.add(item.name);
2357
+ }
2358
+ }
2359
+ }
2360
+ function getShortProjectName4(fullPath) {
2361
+ const parts = fullPath.split("/").filter(Boolean);
2362
+ return parts.slice(-3).join("/");
2363
+ }
2364
+
2365
+ // src/persistent/metadata-reducer.ts
2366
+ function initialReducerState() {
2367
+ return {
2368
+ sessionId: "",
2369
+ nameSlots: {},
2370
+ latestTimestamp: "",
2371
+ cwd: "",
2372
+ teamName: "",
2373
+ model: null,
2374
+ messageCount: 0,
2375
+ lastMessageSender: "user",
2376
+ agentId: "",
2377
+ isSidechain: false,
2378
+ firstMessage: null,
2379
+ lastMessage: null,
2380
+ lastPrompt: "",
2381
+ pageMessageCount: 0,
2382
+ toolNames: [],
2383
+ previewParts: [],
2384
+ snippetParts: [],
2385
+ previewLength: 0,
2386
+ snippetLength: 0,
2387
+ badJsonLines: 0,
2388
+ turnDurations: []
2389
+ };
2390
+ }
2391
+ function reduceLine(state, rawEntry, tier) {
2392
+ const entry = asQueuedPromptUserEntry(rawEntry);
2393
+ if (entry.cwd && !state.cwd) state.cwd = entry.cwd;
2394
+ if (entry.sessionId && !state.sessionId) state.sessionId = entry.sessionId;
2395
+ state.nameSlots = applyClaudeNameEntry(state.nameSlots, entry);
2396
+ if (entry.teamName && !state.teamName) state.teamName = entry.teamName;
2397
+ if (entry.agentId && !state.agentId) state.agentId = entry.agentId;
2398
+ if (entry.isSidechain === true) state.isSidechain = true;
2399
+ if (entry.timestamp) {
2400
+ const ts = entry.timestamp;
2401
+ if (!state.latestTimestamp || ts > state.latestTimestamp) state.latestTimestamp = ts;
2402
+ }
2403
+ const turnDuration = turnDurationOf(entry);
2404
+ if (turnDuration) state.turnDurations?.push(turnDuration);
2405
+ const type = entry.type;
2406
+ if (type === "last-prompt") {
2407
+ if (entry.lastPrompt && !state.lastPrompt) state.lastPrompt = entry.lastPrompt;
2408
+ return;
2409
+ }
2410
+ if (type !== "user" && type !== "assistant") return;
2411
+ if (entry.isMeta) return;
2412
+ const msg = entry.message;
2413
+ if (entry.isCompactSummary === true) {
2414
+ if (extractTextContent(msg?.content)) state.pageMessageCount++;
2415
+ return;
2416
+ }
2417
+ if (state.model === null && msg?.model) state.model = msg.model;
2418
+ const content = extractTextContent(msg?.content);
2419
+ const hasToolUseResult = type === "user" && entry.toolUseResult != null;
2420
+ const isOnlyToolResult = hasToolUseResult && isOnlyToolResultContent(msg?.content);
2421
+ const toolSet = new Set(state.toolNames);
2422
+ collectToolNames(msg?.content, toolSet);
2423
+ state.toolNames = Array.from(toolSet);
2424
+ const toolUseBlocks = extractToolUseBlocks(msg?.content);
2425
+ const thinking = type === "assistant" ? extractThinking(msg?.content) : null;
2426
+ const hasThinking = !!(thinking?.content || thinking?.signature);
2427
+ if (content || isOnlyToolResult || toolUseBlocks.length > 0 || hasThinking) {
2428
+ state.pageMessageCount++;
2429
+ }
2430
+ if (content || isOnlyToolResult) {
2431
+ state.messageCount++;
2432
+ state.lastMessageSender = type;
2433
+ if (content) {
2434
+ const ts = entry.timestamp || "";
2435
+ if (!state.firstMessage) state.firstMessage = { text: content.slice(0, 200), timestamp: ts };
2436
+ state.lastMessage = { text: content.slice(0, 200), timestamp: ts };
2437
+ if (state.previewLength < tier.previewMax) {
2438
+ state.previewParts.push(content);
2439
+ state.previewLength += content.length;
2440
+ }
2441
+ if (state.snippetLength < tier.snippetMax) {
2442
+ const remaining = tier.snippetMax - state.snippetLength;
2443
+ const chunk = content.length > remaining ? content.slice(0, remaining) : content;
2444
+ state.snippetParts.push(chunk);
2445
+ state.snippetLength += chunk.length;
2446
+ }
2447
+ }
2448
+ }
2449
+ }
2450
+ function finalizeMeta(state, filePath, account, tier) {
2451
+ if (state.messageCount === 0) return null;
2452
+ const isSidechain = state.isSidechain && !!state.agentId;
2453
+ const isSubagentPath = SUBAGENT_PATH_RE2.test(filePath);
2454
+ const isSubagent = isSidechain || isSubagentPath;
2455
+ let parentSessionId = null;
2456
+ if (isSubagentPath) {
2457
+ const uuidDir = dirname5(dirname5(filePath));
2458
+ parentSessionId = join5(dirname5(uuidDir), `${basename6(uuidDir)}.jsonl`);
2459
+ }
2460
+ const projectPath = state.cwd;
2461
+ return {
2462
+ id: filePath,
2463
+ filePath,
2464
+ provider: CLAUDE_CODE_PROVIDER,
2465
+ sessionId: state.sessionId || basename6(filePath, ".jsonl"),
2466
+ sessionName: resolveSessionName(state.nameSlots).name ?? "",
2467
+ nameSlots: state.nameSlots,
2468
+ projectPath,
2469
+ projectName: getShortProjectName5(projectPath),
2470
+ account,
2471
+ timestamp: state.latestTimestamp || (/* @__PURE__ */ new Date()).toISOString(),
2472
+ messageCount: state.messageCount,
2473
+ lastMessageSender: state.lastMessageSender,
2474
+ preview: state.previewParts.join(" ").slice(0, tier.previewMax),
2475
+ contentSnippet: state.snippetParts.join(" "),
2476
+ gitBranch: null,
2477
+ model: state.model,
2478
+ isSubagent,
2479
+ parentSessionId,
2480
+ subagentId: isSidechain ? state.agentId : void 0,
2481
+ // A sidechain line's `sessionId` IS the parent's id — that is exactly the
2482
+ // conflation `subagentId` exists to undo, so it is the parent UUID here.
2483
+ parentSessionUuid: isSidechain && state.sessionId ? state.sessionId : void 0,
2484
+ // A teammate's records carry teamName; the lead's never do, yet the lead
2485
+ // receives <teammate-message> tags too, so the tag is not the discriminator.
2486
+ isTeammate: Boolean(state.teamName),
2487
+ teamName: state.teamName || null,
2488
+ toolNames: state.toolNames,
2489
+ firstMessage: state.firstMessage,
2490
+ lastMessage: state.lastMessage,
2491
+ lastPrompt: state.lastPrompt || void 0
2492
+ };
2493
+ }
2494
+ var SUBAGENT_PATH_RE2 = /[\\/]subagents[\\/]/;
2495
+ function getShortProjectName5(fullPath) {
2496
+ const parts = fullPath.split("/").filter(Boolean);
2497
+ return parts.slice(-3).join("/");
2498
+ }
2499
+
2500
2500
  // src/providers/threadbase.ts
2501
2501
  var ThreadbaseProvider = class {
2502
2502
  name = CLAUDE_CODE_PROVIDER;
@@ -2771,7 +2771,7 @@ function assemble(filePath, account, messages, fullText, turnDurations, state) {
2771
2771
  id: filePath,
2772
2772
  filePath,
2773
2773
  projectPath: state.cwd,
2774
- projectName: getShortProjectName2(state.cwd),
2774
+ projectName: getShortProjectName4(state.cwd),
2775
2775
  sessionId: state.sessionId || basename7(filePath, ".jsonl"),
2776
2776
  sessionName: resolveSessionName(state.nameSlots).name ?? "",
2777
2777
  messages,