@threadbase-sh/scanner 0.20.0 → 0.21.1

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
@@ -432,6 +432,10 @@ function reduceLine(state, entry, tier) {
432
432
  if (type !== "user" && type !== "assistant") return;
433
433
  if (entry.isMeta) return;
434
434
  const msg = entry.message;
435
+ if (entry.isCompactSummary === true) {
436
+ if (extractTextContent(msg?.content)) state.pageMessageCount++;
437
+ return;
438
+ }
435
439
  if (state.model === null && msg?.model) state.model = msg.model;
436
440
  if (type === "user" && !state.firstUserSeen) {
437
441
  state.firstUserSeen = true;
@@ -614,7 +618,7 @@ async function parseConversation(filePath, account) {
614
618
  const message = reduceConvLine(state, entry);
615
619
  if (message) {
616
620
  messages.push(message);
617
- if (message.text) textParts.push(message.text);
621
+ if (message.text && !message.isCompactSummary) textParts.push(message.text);
618
622
  }
619
623
  }
620
624
  } catch (err) {
@@ -636,7 +640,9 @@ async function parseConversation(filePath, account) {
636
640
  projectPath: state.cwd,
637
641
  projectName: getShortProjectName2(state.cwd),
638
642
  sessionId: state.sessionId || basename2(filePath, ".jsonl"),
639
- sessionName: state.sessionName || deriveSessionNameFromFirstMessage(messages.find((m) => m.role === "user" && m.text) ?? null),
643
+ sessionName: state.sessionName || deriveSessionNameFromFirstMessage(
644
+ messages.find((m) => m.role === "user" && m.text && !m.isCompactSummary) ?? null
645
+ ),
640
646
  messages,
641
647
  fullText: textParts.join(" "),
642
648
  timestamp: state.latestTimestamp || (/* @__PURE__ */ new Date()).toISOString(),
@@ -766,8 +772,20 @@ function reduceConvLine(state, entry) {
766
772
  if (entry.lastPrompt && !state.lastPrompt) state.lastPrompt = entry.lastPrompt;
767
773
  return null;
768
774
  }
775
+ if (type === "system" && entry.subtype === "compact_boundary") {
776
+ const meta = entry.compactMetadata ?? {};
777
+ state.pendingCompaction = {
778
+ trigger: typeof meta.trigger === "string" ? meta.trigger : void 0,
779
+ preTokens: typeof meta.preTokens === "number" ? meta.preTokens : void 0,
780
+ postTokens: typeof meta.postTokens === "number" ? meta.postTokens : void 0
781
+ };
782
+ return null;
783
+ }
769
784
  if (type !== "user" && type !== "assistant") return null;
770
785
  if (entry.isMeta) return null;
786
+ const isCompactSummary = type === "user" && entry.isCompactSummary === true;
787
+ const compaction = isCompactSummary ? state.pendingCompaction : void 0;
788
+ if (isCompactSummary) delete state.pendingCompaction;
771
789
  const msg = entry.message;
772
790
  const toolUseBlocks = extractToolUseBlocks(msg?.content);
773
791
  for (const block of toolUseBlocks) state.pendingToolUses[block.id] = block;
@@ -827,7 +845,9 @@ function reduceConvLine(state, entry) {
827
845
  isSidechain: typeof entry.isSidechain === "boolean" ? entry.isSidechain : void 0,
828
846
  permissionMode: type === "user" ? entry.permissionMode : void 0,
829
847
  hasImages: hasImageBlocks(msg?.content) || void 0,
830
- attachment: entry.attachment !== void 0 ? entry.attachment : void 0
848
+ attachment: entry.attachment !== void 0 ? entry.attachment : void 0,
849
+ isCompactSummary: isCompactSummary || void 0,
850
+ compaction
831
851
  };
832
852
  }
833
853
  function parseJsonlLine(line, state = initialConvState()) {
@@ -2277,7 +2297,7 @@ async function foldTail(filePath, resume) {
2277
2297
  resume.state,
2278
2298
  (message) => {
2279
2299
  messages.push(message);
2280
- if (message.text) textParts.push(message.text);
2300
+ if (message.text && !message.isCompactSummary) textParts.push(message.text);
2281
2301
  return false;
2282
2302
  },
2283
2303
  (entry) => {
@@ -2301,7 +2321,9 @@ function assemble(filePath, account, messages, fullText, turnDurations, state) {
2301
2321
  projectPath: state.cwd,
2302
2322
  projectName: getShortProjectName2(state.cwd),
2303
2323
  sessionId: state.sessionId || basename6(filePath, ".jsonl"),
2304
- sessionName: state.sessionName || deriveSessionNameFromFirstMessage(messages.find((m) => m.role === "user" && m.text) ?? null),
2324
+ sessionName: state.sessionName || deriveSessionNameFromFirstMessage(
2325
+ messages.find((m) => m.role === "user" && m.text && !m.isCompactSummary) ?? null
2326
+ ),
2305
2327
  messages,
2306
2328
  fullText,
2307
2329
  timestamp: state.latestTimestamp || (/* @__PURE__ */ new Date()).toISOString(),
@@ -2519,7 +2541,7 @@ function extractCursorSearchText(content) {
2519
2541
  function extractClaudeDelta(entry) {
2520
2542
  const type = entry.type;
2521
2543
  if (type !== "user" && type !== "assistant") return emptySearchDocument();
2522
- if (entry.isMeta) return emptySearchDocument();
2544
+ if (entry.isMeta || entry.isCompactSummary === true) return emptySearchDocument();
2523
2545
  const msg = entry.message;
2524
2546
  const content = msg?.content;
2525
2547
  const tools = [