@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 +130 -22
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +131 -23
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +131 -23
- package/dist/index.js.map +1 -1
- package/dist/providers/codex-cli.d.ts.map +1 -1
- package/dist/providers/cursor.d.ts +1 -1
- package/dist/providers/cursor.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1118,12 +1118,88 @@ function parseCodexJsonlLine(line) {
|
|
|
1118
1118
|
function codexEntryToMessage(entry) {
|
|
1119
1119
|
const payload = entry.payload;
|
|
1120
1120
|
if (!payload || typeof payload !== "object") return null;
|
|
1121
|
-
if (entry.type !== "response_item"
|
|
1122
|
-
const
|
|
1123
|
-
|
|
1124
|
-
const
|
|
1125
|
-
|
|
1126
|
-
|
|
1121
|
+
if (entry.type !== "response_item") return null;
|
|
1122
|
+
const timestamp = asString(entry.timestamp);
|
|
1123
|
+
const uuid = asString(payload.id) || void 0;
|
|
1124
|
+
const base = { timestamp, ...uuid ? { uuid } : {} };
|
|
1125
|
+
switch (payload.type) {
|
|
1126
|
+
case "message": {
|
|
1127
|
+
const role = payload.role;
|
|
1128
|
+
if (role !== "user" && role !== "assistant") return null;
|
|
1129
|
+
const text = extractCodexText(payload.content);
|
|
1130
|
+
if (!text) return null;
|
|
1131
|
+
return { role, text, ...base };
|
|
1132
|
+
}
|
|
1133
|
+
case "function_call":
|
|
1134
|
+
case "custom_tool_call":
|
|
1135
|
+
case "web_search_call": {
|
|
1136
|
+
const block = codexToolUseBlock(payload);
|
|
1137
|
+
if (!block) return null;
|
|
1138
|
+
return {
|
|
1139
|
+
role: "assistant",
|
|
1140
|
+
text: "",
|
|
1141
|
+
...base,
|
|
1142
|
+
metadata: { toolUses: [block.name], toolUseBlocks: [block] }
|
|
1143
|
+
};
|
|
1144
|
+
}
|
|
1145
|
+
case "function_call_output":
|
|
1146
|
+
case "custom_tool_call_output": {
|
|
1147
|
+
const toolUseId = asString(payload.call_id);
|
|
1148
|
+
if (!toolUseId) return null;
|
|
1149
|
+
return {
|
|
1150
|
+
role: "user",
|
|
1151
|
+
text: "",
|
|
1152
|
+
...base,
|
|
1153
|
+
isToolResult: true,
|
|
1154
|
+
metadata: {
|
|
1155
|
+
toolResults: [
|
|
1156
|
+
{
|
|
1157
|
+
toolUseId,
|
|
1158
|
+
type: "generic",
|
|
1159
|
+
content: { output: codexToolOutputText(payload.output) }
|
|
1160
|
+
}
|
|
1161
|
+
]
|
|
1162
|
+
}
|
|
1163
|
+
};
|
|
1164
|
+
}
|
|
1165
|
+
case "reasoning": {
|
|
1166
|
+
const summary = Array.isArray(payload.summary) ? payload.summary : [];
|
|
1167
|
+
const thinkingContent = summary.map((s) => asString(s?.text)).filter((t) => t.trim()).join("\n\n");
|
|
1168
|
+
if (!thinkingContent) return null;
|
|
1169
|
+
return { role: "assistant", text: "", ...base, isThinking: true, thinkingContent };
|
|
1170
|
+
}
|
|
1171
|
+
default:
|
|
1172
|
+
return null;
|
|
1173
|
+
}
|
|
1174
|
+
}
|
|
1175
|
+
function codexToolUseBlock(payload) {
|
|
1176
|
+
if (payload.type === "web_search_call") {
|
|
1177
|
+
const action = payload.action;
|
|
1178
|
+
return {
|
|
1179
|
+
id: asString(payload.id),
|
|
1180
|
+
name: "web_search",
|
|
1181
|
+
input: action && typeof action === "object" ? action : {}
|
|
1182
|
+
};
|
|
1183
|
+
}
|
|
1184
|
+
const name = asString(payload.name);
|
|
1185
|
+
if (!name) return null;
|
|
1186
|
+
const id = asString(payload.call_id);
|
|
1187
|
+
if (payload.type === "custom_tool_call") {
|
|
1188
|
+
return { id, name, input: { input: asString(payload.input) } };
|
|
1189
|
+
}
|
|
1190
|
+
const args = asString(payload.arguments);
|
|
1191
|
+
let input = { arguments: args };
|
|
1192
|
+
try {
|
|
1193
|
+
const parsed = JSON.parse(args);
|
|
1194
|
+
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) input = parsed;
|
|
1195
|
+
} catch {
|
|
1196
|
+
}
|
|
1197
|
+
return { id, name, input };
|
|
1198
|
+
}
|
|
1199
|
+
function codexToolOutputText(output) {
|
|
1200
|
+
if (typeof output === "string") return output;
|
|
1201
|
+
if (!Array.isArray(output)) return "";
|
|
1202
|
+
return output.map((item) => typeof item === "string" ? item : asString(item?.text)).filter(Boolean).join("\n");
|
|
1127
1203
|
}
|
|
1128
1204
|
function reduceCodexEntry(acc, entry, tier) {
|
|
1129
1205
|
const ts = asString(entry.timestamp);
|
|
@@ -1263,6 +1339,7 @@ async function parseCodexConversation(filePath, account) {
|
|
|
1263
1339
|
const message = codexEntryToMessage(entry);
|
|
1264
1340
|
if (!message) continue;
|
|
1265
1341
|
messages.push(message);
|
|
1342
|
+
if (!message.text) continue;
|
|
1266
1343
|
textParts.push(message.text);
|
|
1267
1344
|
if (message.role === "user") lastUserText = message.text;
|
|
1268
1345
|
}
|
|
@@ -1288,6 +1365,7 @@ async function parseCodexConversation(filePath, account) {
|
|
|
1288
1365
|
}
|
|
1289
1366
|
|
|
1290
1367
|
// src/providers/cursor.ts
|
|
1368
|
+
var import_crypto = require("crypto");
|
|
1291
1369
|
var import_fast_glob2 = __toESM(require("fast-glob"), 1);
|
|
1292
1370
|
var import_fs5 = require("fs");
|
|
1293
1371
|
var import_promises3 = require("fs/promises");
|
|
@@ -1462,35 +1540,64 @@ function firstTimestampHint(content) {
|
|
|
1462
1540
|
}
|
|
1463
1541
|
return "";
|
|
1464
1542
|
}
|
|
1465
|
-
function parseCursorJsonlLine(line) {
|
|
1466
|
-
|
|
1543
|
+
function parseCursorJsonlLine(line, index) {
|
|
1544
|
+
const trimmed = line.trim();
|
|
1545
|
+
if (!trimmed) return null;
|
|
1467
1546
|
let entry;
|
|
1468
1547
|
try {
|
|
1469
|
-
entry = JSON.parse(
|
|
1548
|
+
entry = JSON.parse(trimmed);
|
|
1470
1549
|
} catch {
|
|
1471
1550
|
return null;
|
|
1472
1551
|
}
|
|
1473
|
-
|
|
1552
|
+
const message = cursorEntryToMessage(entry);
|
|
1553
|
+
if (!message || message.uuid) return message;
|
|
1554
|
+
return { ...message, uuid: cursorMessageUuid(trimmed, message.role, index) };
|
|
1555
|
+
}
|
|
1556
|
+
function cursorMessageUuid(line, role, index) {
|
|
1557
|
+
const hash = (0, import_crypto.createHash)("sha1").update(line).digest("hex").slice(0, 16);
|
|
1558
|
+
return index === void 0 ? `cursor-${role}-${hash}` : `cursor-${role}-${index}-${hash}`;
|
|
1474
1559
|
}
|
|
1475
1560
|
function cursorEntryToMessage(entry) {
|
|
1476
1561
|
if (looksLikeCursorChatEntry(entry)) {
|
|
1477
1562
|
const role = entry.role;
|
|
1478
1563
|
const message = entry.message;
|
|
1479
|
-
const
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1564
|
+
const content = message?.content ?? entry.content;
|
|
1565
|
+
return withToolUses(
|
|
1566
|
+
{ role, text: extractCursorText(content), timestamp: firstTimestampHint(content) },
|
|
1567
|
+
content
|
|
1568
|
+
);
|
|
1483
1569
|
}
|
|
1484
1570
|
if (looksLikeImportedClaudeEntry(entry)) {
|
|
1485
1571
|
const message = entry.message;
|
|
1486
1572
|
const role = message?.role === "assistant" || entry.type === "assistant" ? "assistant" : "user";
|
|
1487
|
-
const
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1573
|
+
const content = message?.content ?? entry.content;
|
|
1574
|
+
return withToolUses(
|
|
1575
|
+
{ role, text: extractCursorText(content), timestamp: asString2(entry.timestamp) },
|
|
1576
|
+
content
|
|
1577
|
+
);
|
|
1491
1578
|
}
|
|
1492
1579
|
return parseCodexJsonlLine(JSON.stringify(entry));
|
|
1493
1580
|
}
|
|
1581
|
+
function withToolUses(message, content) {
|
|
1582
|
+
const blocks = extractCursorToolUseBlocks(content);
|
|
1583
|
+
if (blocks.length === 0) return message.text ? message : null;
|
|
1584
|
+
return {
|
|
1585
|
+
...message,
|
|
1586
|
+
metadata: { toolUses: blocks.map((b) => b.name), toolUseBlocks: blocks }
|
|
1587
|
+
};
|
|
1588
|
+
}
|
|
1589
|
+
function extractCursorToolUseBlocks(content) {
|
|
1590
|
+
if (!Array.isArray(content)) return [];
|
|
1591
|
+
const blocks = [];
|
|
1592
|
+
for (const item of content) {
|
|
1593
|
+
const block = item;
|
|
1594
|
+
if (block?.type !== "tool_use" || typeof block.name !== "string" || !block.name) continue;
|
|
1595
|
+
const input = block.input && typeof block.input === "object" && !Array.isArray(block.input) ? block.input : {};
|
|
1596
|
+
const id = typeof block.id === "string" && block.id ? block.id : `cursor-tool-${(0, import_crypto.createHash)("sha1").update(`${block.name}\0${JSON.stringify(input)}`).digest("hex").slice(0, 16)}`;
|
|
1597
|
+
blocks.push({ id, name: block.name, input });
|
|
1598
|
+
}
|
|
1599
|
+
return blocks;
|
|
1600
|
+
}
|
|
1494
1601
|
function foldCursorMessage(acc, role, text, timestamp, tier) {
|
|
1495
1602
|
if (timestamp && (!acc.latestTimestamp || timestamp > acc.latestTimestamp)) {
|
|
1496
1603
|
acc.latestTimestamp = timestamp;
|
|
@@ -1530,13 +1637,13 @@ function reduceCursorEntry(acc, entry, tier) {
|
|
|
1530
1637
|
if (looksLikeImportedClaudeEntry(entry)) {
|
|
1531
1638
|
collectCursorToolNames(content, acc.toolNames);
|
|
1532
1639
|
const msg = cursorEntryToMessage(entry);
|
|
1533
|
-
if (!msg) return;
|
|
1640
|
+
if (!msg?.text) return;
|
|
1534
1641
|
foldCursorMessage(acc, msg.role, msg.text, msg.timestamp, tier);
|
|
1535
1642
|
return;
|
|
1536
1643
|
}
|
|
1537
1644
|
if (looksLikeImportedCodexEntry(entry)) {
|
|
1538
1645
|
const msg = parseCodexJsonlLine(JSON.stringify(entry));
|
|
1539
|
-
if (!msg) return;
|
|
1646
|
+
if (!msg?.text) return;
|
|
1540
1647
|
foldCursorMessage(acc, msg.role, msg.text, msg.timestamp, tier);
|
|
1541
1648
|
}
|
|
1542
1649
|
}
|
|
@@ -1651,12 +1758,13 @@ async function parseCursorConversation(filePath, account) {
|
|
|
1651
1758
|
const rl = (0, import_readline3.createInterface)({ input: (0, import_fs5.createReadStream)(filePath), crlfDelay: Infinity });
|
|
1652
1759
|
try {
|
|
1653
1760
|
for await (const line of rl) {
|
|
1654
|
-
const message = parseCursorJsonlLine(line);
|
|
1761
|
+
const message = parseCursorJsonlLine(line, messages.length);
|
|
1655
1762
|
if (!message) continue;
|
|
1656
1763
|
if (message.timestamp && (!latestTimestamp || message.timestamp > latestTimestamp)) {
|
|
1657
1764
|
latestTimestamp = message.timestamp;
|
|
1658
1765
|
}
|
|
1659
1766
|
messages.push(message);
|
|
1767
|
+
if (!message.text) continue;
|
|
1660
1768
|
textParts.push(message.text);
|
|
1661
1769
|
if (message.role === "user") lastUserText = message.text;
|
|
1662
1770
|
}
|
|
@@ -2032,11 +2140,11 @@ async function extendConversation(previous, resume, filePath, account) {
|
|
|
2032
2140
|
}
|
|
2033
2141
|
|
|
2034
2142
|
// src/persistent/cursor.ts
|
|
2035
|
-
var
|
|
2143
|
+
var import_crypto2 = require("crypto");
|
|
2036
2144
|
var import_fs8 = require("fs");
|
|
2037
2145
|
var FP_BYTES = 4096;
|
|
2038
2146
|
function fingerprint(filePath, size) {
|
|
2039
|
-
const hash = (0,
|
|
2147
|
+
const hash = (0, import_crypto2.createHash)("sha1");
|
|
2040
2148
|
hash.update(String(size));
|
|
2041
2149
|
const fd = (0, import_fs8.openSync)(filePath, "r");
|
|
2042
2150
|
try {
|