@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/cli.js +118 -17
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +119 -18
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +119 -18
- package/dist/index.js.map +1 -1
- package/dist/providers/codex-cli.d.ts.map +1 -1
- package/dist/providers/cursor.d.ts.map +1 -1
- package/package.json +1 -1
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.
|
|
8
|
+
var version = "0.19.0";
|
|
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"
|
|
1362
|
-
const
|
|
1363
|
-
|
|
1364
|
-
const
|
|
1365
|
-
|
|
1366
|
-
|
|
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";
|
|
@@ -1716,21 +1794,43 @@ function cursorEntryToMessage(entry) {
|
|
|
1716
1794
|
if (looksLikeCursorChatEntry(entry)) {
|
|
1717
1795
|
const role = entry.role;
|
|
1718
1796
|
const message = entry.message;
|
|
1719
|
-
const
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1797
|
+
const content = message?.content ?? entry.content;
|
|
1798
|
+
return withToolUses(
|
|
1799
|
+
{ role, text: extractCursorText(content), timestamp: firstTimestampHint(content) },
|
|
1800
|
+
content
|
|
1801
|
+
);
|
|
1723
1802
|
}
|
|
1724
1803
|
if (looksLikeImportedClaudeEntry(entry)) {
|
|
1725
1804
|
const message = entry.message;
|
|
1726
1805
|
const role = message?.role === "assistant" || entry.type === "assistant" ? "assistant" : "user";
|
|
1727
|
-
const
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1806
|
+
const content = message?.content ?? entry.content;
|
|
1807
|
+
return withToolUses(
|
|
1808
|
+
{ role, text: extractCursorText(content), timestamp: asString2(entry.timestamp) },
|
|
1809
|
+
content
|
|
1810
|
+
);
|
|
1731
1811
|
}
|
|
1732
1812
|
return parseCodexJsonlLine(JSON.stringify(entry));
|
|
1733
1813
|
}
|
|
1814
|
+
function withToolUses(message, content) {
|
|
1815
|
+
const blocks = extractCursorToolUseBlocks(content);
|
|
1816
|
+
if (blocks.length === 0) return message.text ? message : null;
|
|
1817
|
+
return {
|
|
1818
|
+
...message,
|
|
1819
|
+
metadata: { toolUses: blocks.map((b) => b.name), toolUseBlocks: blocks }
|
|
1820
|
+
};
|
|
1821
|
+
}
|
|
1822
|
+
function extractCursorToolUseBlocks(content) {
|
|
1823
|
+
if (!Array.isArray(content)) return [];
|
|
1824
|
+
const blocks = [];
|
|
1825
|
+
for (const item of content) {
|
|
1826
|
+
const block = item;
|
|
1827
|
+
if (block?.type !== "tool_use" || typeof block.name !== "string" || !block.name) continue;
|
|
1828
|
+
const input = block.input && typeof block.input === "object" && !Array.isArray(block.input) ? block.input : {};
|
|
1829
|
+
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)}`;
|
|
1830
|
+
blocks.push({ id, name: block.name, input });
|
|
1831
|
+
}
|
|
1832
|
+
return blocks;
|
|
1833
|
+
}
|
|
1734
1834
|
function foldCursorMessage(acc, role, text, timestamp, tier) {
|
|
1735
1835
|
if (timestamp && (!acc.latestTimestamp || timestamp > acc.latestTimestamp)) {
|
|
1736
1836
|
acc.latestTimestamp = timestamp;
|
|
@@ -1770,13 +1870,13 @@ function reduceCursorEntry(acc, entry, tier) {
|
|
|
1770
1870
|
if (looksLikeImportedClaudeEntry(entry)) {
|
|
1771
1871
|
collectCursorToolNames(content, acc.toolNames);
|
|
1772
1872
|
const msg = cursorEntryToMessage(entry);
|
|
1773
|
-
if (!msg) return;
|
|
1873
|
+
if (!msg?.text) return;
|
|
1774
1874
|
foldCursorMessage(acc, msg.role, msg.text, msg.timestamp, tier);
|
|
1775
1875
|
return;
|
|
1776
1876
|
}
|
|
1777
1877
|
if (looksLikeImportedCodexEntry(entry)) {
|
|
1778
1878
|
const msg = parseCodexJsonlLine(JSON.stringify(entry));
|
|
1779
|
-
if (!msg) return;
|
|
1879
|
+
if (!msg?.text) return;
|
|
1780
1880
|
foldCursorMessage(acc, msg.role, msg.text, msg.timestamp, tier);
|
|
1781
1881
|
}
|
|
1782
1882
|
}
|
|
@@ -1897,6 +1997,7 @@ async function parseCursorConversation(filePath, account) {
|
|
|
1897
1997
|
latestTimestamp = message.timestamp;
|
|
1898
1998
|
}
|
|
1899
1999
|
messages.push(message);
|
|
2000
|
+
if (!message.text) continue;
|
|
1900
2001
|
textParts.push(message.text);
|
|
1901
2002
|
if (message.role === "user") lastUserText = message.text;
|
|
1902
2003
|
}
|