@threadbase-sh/scanner 0.18.0 → 0.19.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/cli.js CHANGED
@@ -5,7 +5,7 @@ import { Command } from "commander";
5
5
  import pino2 from "pino";
6
6
 
7
7
  // package.json
8
- var version = "0.18.0";
8
+ var version = "0.19.1";
9
9
 
10
10
  // src/logger.ts
11
11
  import pino from "pino";
@@ -1358,12 +1358,88 @@ function parseCodexJsonlLine(line) {
1358
1358
  function codexEntryToMessage(entry) {
1359
1359
  const payload = entry.payload;
1360
1360
  if (!payload || typeof payload !== "object") return null;
1361
- if (entry.type !== "response_item" || payload.type !== "message") return null;
1362
- const role = payload.role;
1363
- if (role !== "user" && role !== "assistant") return null;
1364
- const text = extractCodexText(payload.content);
1365
- if (!text) return null;
1366
- return { role, text, timestamp: asString(entry.timestamp) };
1361
+ if (entry.type !== "response_item") return null;
1362
+ const timestamp = asString(entry.timestamp);
1363
+ const uuid = asString(payload.id) || void 0;
1364
+ const base = { timestamp, ...uuid ? { uuid } : {} };
1365
+ switch (payload.type) {
1366
+ case "message": {
1367
+ const role = payload.role;
1368
+ if (role !== "user" && role !== "assistant") return null;
1369
+ const text = extractCodexText(payload.content);
1370
+ if (!text) return null;
1371
+ return { role, text, ...base };
1372
+ }
1373
+ case "function_call":
1374
+ case "custom_tool_call":
1375
+ case "web_search_call": {
1376
+ const block = codexToolUseBlock(payload);
1377
+ if (!block) return null;
1378
+ return {
1379
+ role: "assistant",
1380
+ text: "",
1381
+ ...base,
1382
+ metadata: { toolUses: [block.name], toolUseBlocks: [block] }
1383
+ };
1384
+ }
1385
+ case "function_call_output":
1386
+ case "custom_tool_call_output": {
1387
+ const toolUseId = asString(payload.call_id);
1388
+ if (!toolUseId) return null;
1389
+ return {
1390
+ role: "user",
1391
+ text: "",
1392
+ ...base,
1393
+ isToolResult: true,
1394
+ metadata: {
1395
+ toolResults: [
1396
+ {
1397
+ toolUseId,
1398
+ type: "generic",
1399
+ content: { output: codexToolOutputText(payload.output) }
1400
+ }
1401
+ ]
1402
+ }
1403
+ };
1404
+ }
1405
+ case "reasoning": {
1406
+ const summary = Array.isArray(payload.summary) ? payload.summary : [];
1407
+ const thinkingContent = summary.map((s) => asString(s?.text)).filter((t) => t.trim()).join("\n\n");
1408
+ if (!thinkingContent) return null;
1409
+ return { role: "assistant", text: "", ...base, isThinking: true, thinkingContent };
1410
+ }
1411
+ default:
1412
+ return null;
1413
+ }
1414
+ }
1415
+ function codexToolUseBlock(payload) {
1416
+ if (payload.type === "web_search_call") {
1417
+ const action = payload.action;
1418
+ return {
1419
+ id: asString(payload.id),
1420
+ name: "web_search",
1421
+ input: action && typeof action === "object" ? action : {}
1422
+ };
1423
+ }
1424
+ const name = asString(payload.name);
1425
+ if (!name) return null;
1426
+ const id = asString(payload.call_id);
1427
+ if (payload.type === "custom_tool_call") {
1428
+ return { id, name, input: { input: asString(payload.input) } };
1429
+ }
1430
+ const args = asString(payload.arguments);
1431
+ let input = { arguments: args };
1432
+ try {
1433
+ const parsed = JSON.parse(args);
1434
+ if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) input = parsed;
1435
+ } catch {
1436
+ }
1437
+ return { id, name, input };
1438
+ }
1439
+ function codexToolOutputText(output) {
1440
+ if (typeof output === "string") return output;
1441
+ if (!Array.isArray(output)) return "";
1442
+ return output.map((item) => typeof item === "string" ? item : asString(item?.text)).filter(Boolean).join("\n");
1367
1443
  }
1368
1444
  function reduceCodexEntry(acc, entry, tier) {
1369
1445
  const ts = asString(entry.timestamp);
@@ -1503,6 +1579,7 @@ async function parseCodexConversation(filePath, account) {
1503
1579
  const message = codexEntryToMessage(entry);
1504
1580
  if (!message) continue;
1505
1581
  messages.push(message);
1582
+ if (!message.text) continue;
1506
1583
  textParts.push(message.text);
1507
1584
  if (message.role === "user") lastUserText = message.text;
1508
1585
  }
@@ -1528,6 +1605,7 @@ async function parseCodexConversation(filePath, account) {
1528
1605
  }
1529
1606
 
1530
1607
  // src/providers/cursor.ts
1608
+ import { createHash as createHash2 } from "crypto";
1531
1609
  import fg3 from "fast-glob";
1532
1610
  import { createReadStream as createReadStream5, existsSync, statSync as statSync2 } from "fs";
1533
1611
  import { stat as stat3 } from "fs/promises";
@@ -1702,35 +1780,64 @@ function firstTimestampHint(content) {
1702
1780
  }
1703
1781
  return "";
1704
1782
  }
1705
- function parseCursorJsonlLine(line) {
1706
- if (!line.trim()) return null;
1783
+ function parseCursorJsonlLine(line, index) {
1784
+ const trimmed = line.trim();
1785
+ if (!trimmed) return null;
1707
1786
  let entry;
1708
1787
  try {
1709
- entry = JSON.parse(line);
1788
+ entry = JSON.parse(trimmed);
1710
1789
  } catch {
1711
1790
  return null;
1712
1791
  }
1713
- return cursorEntryToMessage(entry);
1792
+ const message = cursorEntryToMessage(entry);
1793
+ if (!message || message.uuid) return message;
1794
+ return { ...message, uuid: cursorMessageUuid(trimmed, message.role, index) };
1795
+ }
1796
+ function cursorMessageUuid(line, role, index) {
1797
+ const hash = createHash2("sha1").update(line).digest("hex").slice(0, 16);
1798
+ return index === void 0 ? `cursor-${role}-${hash}` : `cursor-${role}-${index}-${hash}`;
1714
1799
  }
1715
1800
  function cursorEntryToMessage(entry) {
1716
1801
  if (looksLikeCursorChatEntry(entry)) {
1717
1802
  const role = entry.role;
1718
1803
  const message = entry.message;
1719
- const text = extractCursorText(message?.content ?? entry.content);
1720
- if (!text) return null;
1721
- const ts = firstTimestampHint(message?.content ?? entry.content);
1722
- return { role, text, timestamp: ts };
1804
+ const content = message?.content ?? entry.content;
1805
+ return withToolUses(
1806
+ { role, text: extractCursorText(content), timestamp: firstTimestampHint(content) },
1807
+ content
1808
+ );
1723
1809
  }
1724
1810
  if (looksLikeImportedClaudeEntry(entry)) {
1725
1811
  const message = entry.message;
1726
1812
  const role = message?.role === "assistant" || entry.type === "assistant" ? "assistant" : "user";
1727
- const text = extractCursorText(message?.content ?? entry.content);
1728
- if (!text) return null;
1729
- const ts = asString2(entry.timestamp);
1730
- return { role, text, timestamp: ts };
1813
+ const content = message?.content ?? entry.content;
1814
+ return withToolUses(
1815
+ { role, text: extractCursorText(content), timestamp: asString2(entry.timestamp) },
1816
+ content
1817
+ );
1731
1818
  }
1732
1819
  return parseCodexJsonlLine(JSON.stringify(entry));
1733
1820
  }
1821
+ function withToolUses(message, content) {
1822
+ const blocks = extractCursorToolUseBlocks(content);
1823
+ if (blocks.length === 0) return message.text ? message : null;
1824
+ return {
1825
+ ...message,
1826
+ metadata: { toolUses: blocks.map((b) => b.name), toolUseBlocks: blocks }
1827
+ };
1828
+ }
1829
+ function extractCursorToolUseBlocks(content) {
1830
+ if (!Array.isArray(content)) return [];
1831
+ const blocks = [];
1832
+ for (const item of content) {
1833
+ const block = item;
1834
+ if (block?.type !== "tool_use" || typeof block.name !== "string" || !block.name) continue;
1835
+ const input = block.input && typeof block.input === "object" && !Array.isArray(block.input) ? block.input : {};
1836
+ const id = typeof block.id === "string" && block.id ? block.id : `cursor-tool-${createHash2("sha1").update(`${block.name}\0${JSON.stringify(input)}`).digest("hex").slice(0, 16)}`;
1837
+ blocks.push({ id, name: block.name, input });
1838
+ }
1839
+ return blocks;
1840
+ }
1734
1841
  function foldCursorMessage(acc, role, text, timestamp, tier) {
1735
1842
  if (timestamp && (!acc.latestTimestamp || timestamp > acc.latestTimestamp)) {
1736
1843
  acc.latestTimestamp = timestamp;
@@ -1770,13 +1877,13 @@ function reduceCursorEntry(acc, entry, tier) {
1770
1877
  if (looksLikeImportedClaudeEntry(entry)) {
1771
1878
  collectCursorToolNames(content, acc.toolNames);
1772
1879
  const msg = cursorEntryToMessage(entry);
1773
- if (!msg) return;
1880
+ if (!msg?.text) return;
1774
1881
  foldCursorMessage(acc, msg.role, msg.text, msg.timestamp, tier);
1775
1882
  return;
1776
1883
  }
1777
1884
  if (looksLikeImportedCodexEntry(entry)) {
1778
1885
  const msg = parseCodexJsonlLine(JSON.stringify(entry));
1779
- if (!msg) return;
1886
+ if (!msg?.text) return;
1780
1887
  foldCursorMessage(acc, msg.role, msg.text, msg.timestamp, tier);
1781
1888
  }
1782
1889
  }
@@ -1891,12 +1998,13 @@ async function parseCursorConversation(filePath, account) {
1891
1998
  const rl = createInterface3({ input: createReadStream5(filePath), crlfDelay: Infinity });
1892
1999
  try {
1893
2000
  for await (const line of rl) {
1894
- const message = parseCursorJsonlLine(line);
2001
+ const message = parseCursorJsonlLine(line, messages.length);
1895
2002
  if (!message) continue;
1896
2003
  if (message.timestamp && (!latestTimestamp || message.timestamp > latestTimestamp)) {
1897
2004
  latestTimestamp = message.timestamp;
1898
2005
  }
1899
2006
  messages.push(message);
2007
+ if (!message.text) continue;
1900
2008
  textParts.push(message.text);
1901
2009
  if (message.role === "user") lastUserText = message.text;
1902
2010
  }