@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.cjs CHANGED
@@ -513,6 +513,10 @@ function reduceLine(state, entry, tier) {
513
513
  if (type !== "user" && type !== "assistant") return;
514
514
  if (entry.isMeta) return;
515
515
  const msg = entry.message;
516
+ if (entry.isCompactSummary === true) {
517
+ if (extractTextContent(msg?.content)) state.pageMessageCount++;
518
+ return;
519
+ }
516
520
  if (state.model === null && msg?.model) state.model = msg.model;
517
521
  if (type === "user" && !state.firstUserSeen) {
518
522
  state.firstUserSeen = true;
@@ -695,7 +699,7 @@ async function parseConversation(filePath, account) {
695
699
  const message = reduceConvLine(state, entry);
696
700
  if (message) {
697
701
  messages.push(message);
698
- if (message.text) textParts.push(message.text);
702
+ if (message.text && !message.isCompactSummary) textParts.push(message.text);
699
703
  }
700
704
  }
701
705
  } catch (err) {
@@ -717,7 +721,9 @@ async function parseConversation(filePath, account) {
717
721
  projectPath: state.cwd,
718
722
  projectName: getShortProjectName2(state.cwd),
719
723
  sessionId: state.sessionId || (0, import_path3.basename)(filePath, ".jsonl"),
720
- sessionName: state.sessionName || deriveSessionNameFromFirstMessage(messages.find((m) => m.role === "user" && m.text) ?? null),
724
+ sessionName: state.sessionName || deriveSessionNameFromFirstMessage(
725
+ messages.find((m) => m.role === "user" && m.text && !m.isCompactSummary) ?? null
726
+ ),
721
727
  messages,
722
728
  fullText: textParts.join(" "),
723
729
  timestamp: state.latestTimestamp || (/* @__PURE__ */ new Date()).toISOString(),
@@ -847,8 +853,20 @@ function reduceConvLine(state, entry) {
847
853
  if (entry.lastPrompt && !state.lastPrompt) state.lastPrompt = entry.lastPrompt;
848
854
  return null;
849
855
  }
856
+ if (type === "system" && entry.subtype === "compact_boundary") {
857
+ const meta = entry.compactMetadata ?? {};
858
+ state.pendingCompaction = {
859
+ trigger: typeof meta.trigger === "string" ? meta.trigger : void 0,
860
+ preTokens: typeof meta.preTokens === "number" ? meta.preTokens : void 0,
861
+ postTokens: typeof meta.postTokens === "number" ? meta.postTokens : void 0
862
+ };
863
+ return null;
864
+ }
850
865
  if (type !== "user" && type !== "assistant") return null;
851
866
  if (entry.isMeta) return null;
867
+ const isCompactSummary = type === "user" && entry.isCompactSummary === true;
868
+ const compaction = isCompactSummary ? state.pendingCompaction : void 0;
869
+ if (isCompactSummary) delete state.pendingCompaction;
852
870
  const msg = entry.message;
853
871
  const toolUseBlocks = extractToolUseBlocks(msg?.content);
854
872
  for (const block of toolUseBlocks) state.pendingToolUses[block.id] = block;
@@ -908,7 +926,9 @@ function reduceConvLine(state, entry) {
908
926
  isSidechain: typeof entry.isSidechain === "boolean" ? entry.isSidechain : void 0,
909
927
  permissionMode: type === "user" ? entry.permissionMode : void 0,
910
928
  hasImages: hasImageBlocks(msg?.content) || void 0,
911
- attachment: entry.attachment !== void 0 ? entry.attachment : void 0
929
+ attachment: entry.attachment !== void 0 ? entry.attachment : void 0,
930
+ isCompactSummary: isCompactSummary || void 0,
931
+ compaction
912
932
  };
913
933
  }
914
934
  function parseJsonlLine(line, state = initialConvState()) {
@@ -2358,7 +2378,7 @@ async function foldTail(filePath, resume) {
2358
2378
  resume.state,
2359
2379
  (message) => {
2360
2380
  messages.push(message);
2361
- if (message.text) textParts.push(message.text);
2381
+ if (message.text && !message.isCompactSummary) textParts.push(message.text);
2362
2382
  return false;
2363
2383
  },
2364
2384
  (entry) => {
@@ -2382,7 +2402,9 @@ function assemble(filePath, account, messages, fullText, turnDurations, state) {
2382
2402
  projectPath: state.cwd,
2383
2403
  projectName: getShortProjectName2(state.cwd),
2384
2404
  sessionId: state.sessionId || (0, import_path9.basename)(filePath, ".jsonl"),
2385
- sessionName: state.sessionName || deriveSessionNameFromFirstMessage(messages.find((m) => m.role === "user" && m.text) ?? null),
2405
+ sessionName: state.sessionName || deriveSessionNameFromFirstMessage(
2406
+ messages.find((m) => m.role === "user" && m.text && !m.isCompactSummary) ?? null
2407
+ ),
2386
2408
  messages,
2387
2409
  fullText,
2388
2410
  timestamp: state.latestTimestamp || (/* @__PURE__ */ new Date()).toISOString(),
@@ -2600,7 +2622,7 @@ function extractCursorSearchText(content) {
2600
2622
  function extractClaudeDelta(entry) {
2601
2623
  const type = entry.type;
2602
2624
  if (type !== "user" && type !== "assistant") return emptySearchDocument();
2603
- if (entry.isMeta) return emptySearchDocument();
2625
+ if (entry.isMeta || entry.isCompactSummary === true) return emptySearchDocument();
2604
2626
  const msg = entry.message;
2605
2627
  const content = msg?.content;
2606
2628
  const tools = [