@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/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");
|
|
@@ -1476,21 +1554,43 @@ function cursorEntryToMessage(entry) {
|
|
|
1476
1554
|
if (looksLikeCursorChatEntry(entry)) {
|
|
1477
1555
|
const role = entry.role;
|
|
1478
1556
|
const message = entry.message;
|
|
1479
|
-
const
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1557
|
+
const content = message?.content ?? entry.content;
|
|
1558
|
+
return withToolUses(
|
|
1559
|
+
{ role, text: extractCursorText(content), timestamp: firstTimestampHint(content) },
|
|
1560
|
+
content
|
|
1561
|
+
);
|
|
1483
1562
|
}
|
|
1484
1563
|
if (looksLikeImportedClaudeEntry(entry)) {
|
|
1485
1564
|
const message = entry.message;
|
|
1486
1565
|
const role = message?.role === "assistant" || entry.type === "assistant" ? "assistant" : "user";
|
|
1487
|
-
const
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1566
|
+
const content = message?.content ?? entry.content;
|
|
1567
|
+
return withToolUses(
|
|
1568
|
+
{ role, text: extractCursorText(content), timestamp: asString2(entry.timestamp) },
|
|
1569
|
+
content
|
|
1570
|
+
);
|
|
1491
1571
|
}
|
|
1492
1572
|
return parseCodexJsonlLine(JSON.stringify(entry));
|
|
1493
1573
|
}
|
|
1574
|
+
function withToolUses(message, content) {
|
|
1575
|
+
const blocks = extractCursorToolUseBlocks(content);
|
|
1576
|
+
if (blocks.length === 0) return message.text ? message : null;
|
|
1577
|
+
return {
|
|
1578
|
+
...message,
|
|
1579
|
+
metadata: { toolUses: blocks.map((b) => b.name), toolUseBlocks: blocks }
|
|
1580
|
+
};
|
|
1581
|
+
}
|
|
1582
|
+
function extractCursorToolUseBlocks(content) {
|
|
1583
|
+
if (!Array.isArray(content)) return [];
|
|
1584
|
+
const blocks = [];
|
|
1585
|
+
for (const item of content) {
|
|
1586
|
+
const block = item;
|
|
1587
|
+
if (block?.type !== "tool_use" || typeof block.name !== "string" || !block.name) continue;
|
|
1588
|
+
const input = block.input && typeof block.input === "object" && !Array.isArray(block.input) ? block.input : {};
|
|
1589
|
+
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)}`;
|
|
1590
|
+
blocks.push({ id, name: block.name, input });
|
|
1591
|
+
}
|
|
1592
|
+
return blocks;
|
|
1593
|
+
}
|
|
1494
1594
|
function foldCursorMessage(acc, role, text, timestamp, tier) {
|
|
1495
1595
|
if (timestamp && (!acc.latestTimestamp || timestamp > acc.latestTimestamp)) {
|
|
1496
1596
|
acc.latestTimestamp = timestamp;
|
|
@@ -1530,13 +1630,13 @@ function reduceCursorEntry(acc, entry, tier) {
|
|
|
1530
1630
|
if (looksLikeImportedClaudeEntry(entry)) {
|
|
1531
1631
|
collectCursorToolNames(content, acc.toolNames);
|
|
1532
1632
|
const msg = cursorEntryToMessage(entry);
|
|
1533
|
-
if (!msg) return;
|
|
1633
|
+
if (!msg?.text) return;
|
|
1534
1634
|
foldCursorMessage(acc, msg.role, msg.text, msg.timestamp, tier);
|
|
1535
1635
|
return;
|
|
1536
1636
|
}
|
|
1537
1637
|
if (looksLikeImportedCodexEntry(entry)) {
|
|
1538
1638
|
const msg = parseCodexJsonlLine(JSON.stringify(entry));
|
|
1539
|
-
if (!msg) return;
|
|
1639
|
+
if (!msg?.text) return;
|
|
1540
1640
|
foldCursorMessage(acc, msg.role, msg.text, msg.timestamp, tier);
|
|
1541
1641
|
}
|
|
1542
1642
|
}
|
|
@@ -1657,6 +1757,7 @@ async function parseCursorConversation(filePath, account) {
|
|
|
1657
1757
|
latestTimestamp = message.timestamp;
|
|
1658
1758
|
}
|
|
1659
1759
|
messages.push(message);
|
|
1760
|
+
if (!message.text) continue;
|
|
1660
1761
|
textParts.push(message.text);
|
|
1661
1762
|
if (message.role === "user") lastUserText = message.text;
|
|
1662
1763
|
}
|
|
@@ -2032,11 +2133,11 @@ async function extendConversation(previous, resume, filePath, account) {
|
|
|
2032
2133
|
}
|
|
2033
2134
|
|
|
2034
2135
|
// src/persistent/cursor.ts
|
|
2035
|
-
var
|
|
2136
|
+
var import_crypto2 = require("crypto");
|
|
2036
2137
|
var import_fs8 = require("fs");
|
|
2037
2138
|
var FP_BYTES = 4096;
|
|
2038
2139
|
function fingerprint(filePath, size) {
|
|
2039
|
-
const hash = (0,
|
|
2140
|
+
const hash = (0, import_crypto2.createHash)("sha1");
|
|
2040
2141
|
hash.update(String(size));
|
|
2041
2142
|
const fd = (0, import_fs8.openSync)(filePath, "r");
|
|
2042
2143
|
try {
|