@threadbase-sh/scanner 0.18.0 → 0.19.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
@@ -1040,12 +1040,88 @@ function parseCodexJsonlLine(line) {
1040
1040
  function codexEntryToMessage(entry) {
1041
1041
  const payload = entry.payload;
1042
1042
  if (!payload || typeof payload !== "object") return null;
1043
- if (entry.type !== "response_item" || payload.type !== "message") return null;
1044
- const role = payload.role;
1045
- if (role !== "user" && role !== "assistant") return null;
1046
- const text = extractCodexText(payload.content);
1047
- if (!text) return null;
1048
- return { role, text, timestamp: asString(entry.timestamp) };
1043
+ if (entry.type !== "response_item") return null;
1044
+ const timestamp = asString(entry.timestamp);
1045
+ const uuid = asString(payload.id) || void 0;
1046
+ const base = { timestamp, ...uuid ? { uuid } : {} };
1047
+ switch (payload.type) {
1048
+ case "message": {
1049
+ const role = payload.role;
1050
+ if (role !== "user" && role !== "assistant") return null;
1051
+ const text = extractCodexText(payload.content);
1052
+ if (!text) return null;
1053
+ return { role, text, ...base };
1054
+ }
1055
+ case "function_call":
1056
+ case "custom_tool_call":
1057
+ case "web_search_call": {
1058
+ const block = codexToolUseBlock(payload);
1059
+ if (!block) return null;
1060
+ return {
1061
+ role: "assistant",
1062
+ text: "",
1063
+ ...base,
1064
+ metadata: { toolUses: [block.name], toolUseBlocks: [block] }
1065
+ };
1066
+ }
1067
+ case "function_call_output":
1068
+ case "custom_tool_call_output": {
1069
+ const toolUseId = asString(payload.call_id);
1070
+ if (!toolUseId) return null;
1071
+ return {
1072
+ role: "user",
1073
+ text: "",
1074
+ ...base,
1075
+ isToolResult: true,
1076
+ metadata: {
1077
+ toolResults: [
1078
+ {
1079
+ toolUseId,
1080
+ type: "generic",
1081
+ content: { output: codexToolOutputText(payload.output) }
1082
+ }
1083
+ ]
1084
+ }
1085
+ };
1086
+ }
1087
+ case "reasoning": {
1088
+ const summary = Array.isArray(payload.summary) ? payload.summary : [];
1089
+ const thinkingContent = summary.map((s) => asString(s?.text)).filter((t) => t.trim()).join("\n\n");
1090
+ if (!thinkingContent) return null;
1091
+ return { role: "assistant", text: "", ...base, isThinking: true, thinkingContent };
1092
+ }
1093
+ default:
1094
+ return null;
1095
+ }
1096
+ }
1097
+ function codexToolUseBlock(payload) {
1098
+ if (payload.type === "web_search_call") {
1099
+ const action = payload.action;
1100
+ return {
1101
+ id: asString(payload.id),
1102
+ name: "web_search",
1103
+ input: action && typeof action === "object" ? action : {}
1104
+ };
1105
+ }
1106
+ const name = asString(payload.name);
1107
+ if (!name) return null;
1108
+ const id = asString(payload.call_id);
1109
+ if (payload.type === "custom_tool_call") {
1110
+ return { id, name, input: { input: asString(payload.input) } };
1111
+ }
1112
+ const args = asString(payload.arguments);
1113
+ let input = { arguments: args };
1114
+ try {
1115
+ const parsed = JSON.parse(args);
1116
+ if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) input = parsed;
1117
+ } catch {
1118
+ }
1119
+ return { id, name, input };
1120
+ }
1121
+ function codexToolOutputText(output) {
1122
+ if (typeof output === "string") return output;
1123
+ if (!Array.isArray(output)) return "";
1124
+ return output.map((item) => typeof item === "string" ? item : asString(item?.text)).filter(Boolean).join("\n");
1049
1125
  }
1050
1126
  function reduceCodexEntry(acc, entry, tier) {
1051
1127
  const ts = asString(entry.timestamp);
@@ -1185,6 +1261,7 @@ async function parseCodexConversation(filePath, account) {
1185
1261
  const message = codexEntryToMessage(entry);
1186
1262
  if (!message) continue;
1187
1263
  messages.push(message);
1264
+ if (!message.text) continue;
1188
1265
  textParts.push(message.text);
1189
1266
  if (message.role === "user") lastUserText = message.text;
1190
1267
  }
@@ -1210,6 +1287,7 @@ async function parseCodexConversation(filePath, account) {
1210
1287
  }
1211
1288
 
1212
1289
  // src/providers/cursor.ts
1290
+ import { createHash } from "crypto";
1213
1291
  import fg2 from "fast-glob";
1214
1292
  import { createReadStream as createReadStream3, existsSync, statSync } from "fs";
1215
1293
  import { stat as stat2 } from "fs/promises";
@@ -1398,21 +1476,43 @@ function cursorEntryToMessage(entry) {
1398
1476
  if (looksLikeCursorChatEntry(entry)) {
1399
1477
  const role = entry.role;
1400
1478
  const message = entry.message;
1401
- const text = extractCursorText(message?.content ?? entry.content);
1402
- if (!text) return null;
1403
- const ts = firstTimestampHint(message?.content ?? entry.content);
1404
- return { role, text, timestamp: ts };
1479
+ const content = message?.content ?? entry.content;
1480
+ return withToolUses(
1481
+ { role, text: extractCursorText(content), timestamp: firstTimestampHint(content) },
1482
+ content
1483
+ );
1405
1484
  }
1406
1485
  if (looksLikeImportedClaudeEntry(entry)) {
1407
1486
  const message = entry.message;
1408
1487
  const role = message?.role === "assistant" || entry.type === "assistant" ? "assistant" : "user";
1409
- const text = extractCursorText(message?.content ?? entry.content);
1410
- if (!text) return null;
1411
- const ts = asString2(entry.timestamp);
1412
- return { role, text, timestamp: ts };
1488
+ const content = message?.content ?? entry.content;
1489
+ return withToolUses(
1490
+ { role, text: extractCursorText(content), timestamp: asString2(entry.timestamp) },
1491
+ content
1492
+ );
1413
1493
  }
1414
1494
  return parseCodexJsonlLine(JSON.stringify(entry));
1415
1495
  }
1496
+ function withToolUses(message, content) {
1497
+ const blocks = extractCursorToolUseBlocks(content);
1498
+ if (blocks.length === 0) return message.text ? message : null;
1499
+ return {
1500
+ ...message,
1501
+ metadata: { toolUses: blocks.map((b) => b.name), toolUseBlocks: blocks }
1502
+ };
1503
+ }
1504
+ function extractCursorToolUseBlocks(content) {
1505
+ if (!Array.isArray(content)) return [];
1506
+ const blocks = [];
1507
+ for (const item of content) {
1508
+ const block = item;
1509
+ if (block?.type !== "tool_use" || typeof block.name !== "string" || !block.name) continue;
1510
+ const input = block.input && typeof block.input === "object" && !Array.isArray(block.input) ? block.input : {};
1511
+ const id = typeof block.id === "string" && block.id ? block.id : `cursor-tool-${createHash("sha1").update(`${block.name}\0${JSON.stringify(input)}`).digest("hex").slice(0, 16)}`;
1512
+ blocks.push({ id, name: block.name, input });
1513
+ }
1514
+ return blocks;
1515
+ }
1416
1516
  function foldCursorMessage(acc, role, text, timestamp, tier) {
1417
1517
  if (timestamp && (!acc.latestTimestamp || timestamp > acc.latestTimestamp)) {
1418
1518
  acc.latestTimestamp = timestamp;
@@ -1452,13 +1552,13 @@ function reduceCursorEntry(acc, entry, tier) {
1452
1552
  if (looksLikeImportedClaudeEntry(entry)) {
1453
1553
  collectCursorToolNames(content, acc.toolNames);
1454
1554
  const msg = cursorEntryToMessage(entry);
1455
- if (!msg) return;
1555
+ if (!msg?.text) return;
1456
1556
  foldCursorMessage(acc, msg.role, msg.text, msg.timestamp, tier);
1457
1557
  return;
1458
1558
  }
1459
1559
  if (looksLikeImportedCodexEntry(entry)) {
1460
1560
  const msg = parseCodexJsonlLine(JSON.stringify(entry));
1461
- if (!msg) return;
1561
+ if (!msg?.text) return;
1462
1562
  foldCursorMessage(acc, msg.role, msg.text, msg.timestamp, tier);
1463
1563
  }
1464
1564
  }
@@ -1579,6 +1679,7 @@ async function parseCursorConversation(filePath, account) {
1579
1679
  latestTimestamp = message.timestamp;
1580
1680
  }
1581
1681
  messages.push(message);
1682
+ if (!message.text) continue;
1582
1683
  textParts.push(message.text);
1583
1684
  if (message.role === "user") lastUserText = message.text;
1584
1685
  }
@@ -1954,11 +2055,11 @@ async function extendConversation(previous, resume, filePath, account) {
1954
2055
  }
1955
2056
 
1956
2057
  // src/persistent/cursor.ts
1957
- import { createHash } from "crypto";
2058
+ import { createHash as createHash2 } from "crypto";
1958
2059
  import { closeSync, openSync, readSync, statSync as statSync2 } from "fs";
1959
2060
  var FP_BYTES = 4096;
1960
2061
  function fingerprint(filePath, size) {
1961
- const hash = createHash("sha1");
2062
+ const hash = createHash2("sha1");
1962
2063
  hash.update(String(size));
1963
2064
  const fd = openSync(filePath, "r");
1964
2065
  try {