@threadbase-sh/scanner 0.17.7 → 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/README.md +34 -22
- package/dist/cli.js +705 -70
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +742 -97
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +718 -83
- package/dist/index.js.map +1 -1
- package/dist/persistent/index-engine.d.ts.map +1 -1
- package/dist/persistent/migrations.d.ts.map +1 -1
- package/dist/persistent/repositories/conversations.repo.d.ts +3 -0
- package/dist/persistent/repositories/conversations.repo.d.ts.map +1 -1
- package/dist/persistent/repositories/fts.repo.d.ts.map +1 -1
- package/dist/persistent/schema.d.ts +2 -2
- package/dist/persistent/schema.d.ts.map +1 -1
- package/dist/providers/codex-cli.d.ts.map +1 -1
- package/dist/providers/cursor.d.ts +38 -0
- package/dist/providers/cursor.d.ts.map +1 -0
- package/dist/providers/provider.d.ts +7 -1
- package/dist/providers/provider.d.ts.map +1 -1
- package/dist/scanner.d.ts.map +1 -1
- package/dist/search-document.d.ts.map +1 -1
- package/dist/types.d.ts +7 -3
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -361,6 +361,29 @@ import { basename, dirname as dirname2, join as join2 } from "path";
|
|
|
361
361
|
// src/providers/provider.ts
|
|
362
362
|
var CLAUDE_CODE_PROVIDER = "claude-code";
|
|
363
363
|
var CODEX_CLI_PROVIDER = "codex-cli";
|
|
364
|
+
var CURSOR_PROVIDER = "cursor";
|
|
365
|
+
var LEGACY_CURSOR_PROVIDER = "cursor-cli";
|
|
366
|
+
function canonicalizeProviderName(value) {
|
|
367
|
+
if (value === LEGACY_CURSOR_PROVIDER) return CURSOR_PROVIDER;
|
|
368
|
+
if (value === CLAUDE_CODE_PROVIDER || value === CODEX_CLI_PROVIDER || value === CURSOR_PROVIDER) {
|
|
369
|
+
return value;
|
|
370
|
+
}
|
|
371
|
+
return void 0;
|
|
372
|
+
}
|
|
373
|
+
function canonicalizeProviderList(providers) {
|
|
374
|
+
const src = providers ?? [CLAUDE_CODE_PROVIDER];
|
|
375
|
+
const out = [];
|
|
376
|
+
for (const p of src) {
|
|
377
|
+
const n = canonicalizeProviderName(p);
|
|
378
|
+
if (n && !out.includes(n)) out.push(n);
|
|
379
|
+
}
|
|
380
|
+
return out;
|
|
381
|
+
}
|
|
382
|
+
function providerMatches(stored, wanted) {
|
|
383
|
+
const a = canonicalizeProviderName(stored ?? CLAUDE_CODE_PROVIDER) ?? stored;
|
|
384
|
+
const b = canonicalizeProviderName(wanted) ?? wanted;
|
|
385
|
+
return a === b;
|
|
386
|
+
}
|
|
364
387
|
|
|
365
388
|
// src/persistent/metadata-reducer.ts
|
|
366
389
|
function initialReducerState() {
|
|
@@ -1017,12 +1040,88 @@ function parseCodexJsonlLine(line) {
|
|
|
1017
1040
|
function codexEntryToMessage(entry) {
|
|
1018
1041
|
const payload = entry.payload;
|
|
1019
1042
|
if (!payload || typeof payload !== "object") return null;
|
|
1020
|
-
if (entry.type !== "response_item"
|
|
1021
|
-
const
|
|
1022
|
-
|
|
1023
|
-
const
|
|
1024
|
-
|
|
1025
|
-
|
|
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");
|
|
1026
1125
|
}
|
|
1027
1126
|
function reduceCodexEntry(acc, entry, tier) {
|
|
1028
1127
|
const ts = asString(entry.timestamp);
|
|
@@ -1162,6 +1261,7 @@ async function parseCodexConversation(filePath, account) {
|
|
|
1162
1261
|
const message = codexEntryToMessage(entry);
|
|
1163
1262
|
if (!message) continue;
|
|
1164
1263
|
messages.push(message);
|
|
1264
|
+
if (!message.text) continue;
|
|
1165
1265
|
textParts.push(message.text);
|
|
1166
1266
|
if (message.role === "user") lastUserText = message.text;
|
|
1167
1267
|
}
|
|
@@ -1186,9 +1286,429 @@ async function parseCodexConversation(filePath, account) {
|
|
|
1186
1286
|
};
|
|
1187
1287
|
}
|
|
1188
1288
|
|
|
1189
|
-
// src/
|
|
1289
|
+
// src/providers/cursor.ts
|
|
1290
|
+
import { createHash } from "crypto";
|
|
1190
1291
|
import fg2 from "fast-glob";
|
|
1292
|
+
import { createReadStream as createReadStream3, existsSync, statSync } from "fs";
|
|
1191
1293
|
import { stat as stat2 } from "fs/promises";
|
|
1294
|
+
import { basename as basename4, dirname as dirname3, join as join4, sep as sep2 } from "path";
|
|
1295
|
+
import { createInterface as createInterface3 } from "readline";
|
|
1296
|
+
var TIMESTAMP_RE = /<timestamp>\s*([\s\S]*?)\s*<\/timestamp>/;
|
|
1297
|
+
var USER_QUERY_RE = /<user_query>\s*([\s\S]*?)\s*<\/user_query>/;
|
|
1298
|
+
var SUBAGENT_PATH_RE2 = /[\\/]subagents[\\/]/;
|
|
1299
|
+
var CursorProvider = class {
|
|
1300
|
+
name = CURSOR_PROVIDER;
|
|
1301
|
+
async discover(roots) {
|
|
1302
|
+
const log = getLogger();
|
|
1303
|
+
const results = [];
|
|
1304
|
+
for (const root of roots) {
|
|
1305
|
+
let paths;
|
|
1306
|
+
try {
|
|
1307
|
+
paths = await fg2(["**/agent-transcripts/**/*.jsonl"], {
|
|
1308
|
+
cwd: root,
|
|
1309
|
+
absolute: true,
|
|
1310
|
+
dot: false,
|
|
1311
|
+
unique: true
|
|
1312
|
+
});
|
|
1313
|
+
} catch (err) {
|
|
1314
|
+
log.warn({ root, err }, "cursor discovery: glob failed");
|
|
1315
|
+
continue;
|
|
1316
|
+
}
|
|
1317
|
+
for (const filePath of paths) {
|
|
1318
|
+
try {
|
|
1319
|
+
const s = await stat2(filePath);
|
|
1320
|
+
if (s.size > 0) results.push({ filePath: canonicalPath(filePath), account: "cursor" });
|
|
1321
|
+
} catch (err) {
|
|
1322
|
+
log.warn({ filePath, err }, "cursor discovery: stat failed");
|
|
1323
|
+
}
|
|
1324
|
+
}
|
|
1325
|
+
}
|
|
1326
|
+
return results;
|
|
1327
|
+
}
|
|
1328
|
+
canParse(filePath, sample) {
|
|
1329
|
+
const underTranscripts = /[\\/]agent-transcripts[\\/]/.test(filePath);
|
|
1330
|
+
for (const line of sample.split("\n")) {
|
|
1331
|
+
if (!line.trim()) continue;
|
|
1332
|
+
try {
|
|
1333
|
+
const e = JSON.parse(line);
|
|
1334
|
+
if (looksLikeImportedCodexEntry(e) || looksLikeImportedClaudeEntry(e)) {
|
|
1335
|
+
return underTranscripts;
|
|
1336
|
+
}
|
|
1337
|
+
if (looksLikeCursorChatEntry(e)) return true;
|
|
1338
|
+
} catch {
|
|
1339
|
+
}
|
|
1340
|
+
}
|
|
1341
|
+
return false;
|
|
1342
|
+
}
|
|
1343
|
+
createEmptyAccumulator() {
|
|
1344
|
+
return {
|
|
1345
|
+
sessionId: "",
|
|
1346
|
+
latestTimestamp: "",
|
|
1347
|
+
messageCount: 0,
|
|
1348
|
+
lastMessageSender: "user",
|
|
1349
|
+
isSubagent: false,
|
|
1350
|
+
parentSessionUuid: null,
|
|
1351
|
+
subagentId: null,
|
|
1352
|
+
firstUser: null,
|
|
1353
|
+
lastUser: null,
|
|
1354
|
+
lastAssistant: null,
|
|
1355
|
+
isImportedFromClaude: false,
|
|
1356
|
+
isImportedFromCodex: false,
|
|
1357
|
+
toolNames: [],
|
|
1358
|
+
previewParts: [],
|
|
1359
|
+
previewLength: 0,
|
|
1360
|
+
snippetParts: [],
|
|
1361
|
+
snippetLength: 0
|
|
1362
|
+
};
|
|
1363
|
+
}
|
|
1364
|
+
reduceEntry(acc, entry, tier) {
|
|
1365
|
+
reduceCursorEntry(acc, entry, tier);
|
|
1366
|
+
}
|
|
1367
|
+
finalize(acc, filePath, account, tier) {
|
|
1368
|
+
return finalizeCursorMeta(acc, filePath, account, tier);
|
|
1369
|
+
}
|
|
1370
|
+
};
|
|
1371
|
+
function looksLikeCursorChatEntry(entry) {
|
|
1372
|
+
const role = entry.role;
|
|
1373
|
+
if (role !== "user" && role !== "assistant") return false;
|
|
1374
|
+
if (entry.type === "user" || entry.type === "assistant") return false;
|
|
1375
|
+
return true;
|
|
1376
|
+
}
|
|
1377
|
+
function looksLikeImportedClaudeEntry(entry) {
|
|
1378
|
+
return entry.type === "user" || entry.type === "assistant";
|
|
1379
|
+
}
|
|
1380
|
+
function looksLikeImportedCodexEntry(entry) {
|
|
1381
|
+
return entry.type === "session_meta" || entry.type === "response_item" || entry.type === "event_msg";
|
|
1382
|
+
}
|
|
1383
|
+
function asString2(value) {
|
|
1384
|
+
return typeof value === "string" ? value : "";
|
|
1385
|
+
}
|
|
1386
|
+
function provenanceToken(value) {
|
|
1387
|
+
if (typeof value === "string") return value.trim().toLowerCase();
|
|
1388
|
+
if (value && typeof value === "object") {
|
|
1389
|
+
const rec = value;
|
|
1390
|
+
return provenanceToken(
|
|
1391
|
+
rec.importedFrom ?? rec.imported_from ?? rec.sourceProvider ?? rec.source
|
|
1392
|
+
);
|
|
1393
|
+
}
|
|
1394
|
+
return "";
|
|
1395
|
+
}
|
|
1396
|
+
function importedFromClaudeToken(token) {
|
|
1397
|
+
return token === "claude" || token === "claude-code" || token === "claude_code" || token === "anthropic";
|
|
1398
|
+
}
|
|
1399
|
+
function importedFromCodexToken(token) {
|
|
1400
|
+
return token === "codex" || token === "codex-cli" || token === "codex_cli" || token === "openai-codex";
|
|
1401
|
+
}
|
|
1402
|
+
function noteImportProvenance(acc, entry, text) {
|
|
1403
|
+
const token = provenanceToken(
|
|
1404
|
+
entry.importedFrom ?? entry.imported_from ?? entry.sourceProvider ?? entry.source ?? (entry.message && typeof entry.message === "object" ? entry.message.importedFrom ?? entry.message.imported_from ?? entry.message.sourceProvider : void 0)
|
|
1405
|
+
);
|
|
1406
|
+
if (importedFromClaudeToken(token) || looksLikeImportedClaudeEntry(entry)) {
|
|
1407
|
+
acc.isImportedFromClaude = true;
|
|
1408
|
+
}
|
|
1409
|
+
if (importedFromCodexToken(token) || looksLikeImportedCodexEntry(entry)) {
|
|
1410
|
+
acc.isImportedFromCodex = true;
|
|
1411
|
+
}
|
|
1412
|
+
if (/imported from claude/i.test(text) || /<imported_from_claude>/i.test(text)) {
|
|
1413
|
+
acc.isImportedFromClaude = true;
|
|
1414
|
+
}
|
|
1415
|
+
if (/imported from codex/i.test(text) || /<imported_from_codex>/i.test(text)) {
|
|
1416
|
+
acc.isImportedFromCodex = true;
|
|
1417
|
+
}
|
|
1418
|
+
}
|
|
1419
|
+
function unwrapCursorUserText(text) {
|
|
1420
|
+
const query = text.match(USER_QUERY_RE);
|
|
1421
|
+
const body = query ? query[1] : text.replace(TIMESTAMP_RE, "");
|
|
1422
|
+
return cleanSystemTags(body);
|
|
1423
|
+
}
|
|
1424
|
+
function timestampFromCursorUserText(text) {
|
|
1425
|
+
const match = text.match(TIMESTAMP_RE);
|
|
1426
|
+
if (!match) return "";
|
|
1427
|
+
const parsed = Date.parse(match[1].trim());
|
|
1428
|
+
return Number.isNaN(parsed) ? "" : new Date(parsed).toISOString();
|
|
1429
|
+
}
|
|
1430
|
+
function extractCursorText(content) {
|
|
1431
|
+
if (typeof content === "string") return unwrapCursorUserText(content);
|
|
1432
|
+
if (!Array.isArray(content)) return "";
|
|
1433
|
+
return content.map((item) => {
|
|
1434
|
+
if (typeof item === "string") return unwrapCursorUserText(item);
|
|
1435
|
+
const block = item;
|
|
1436
|
+
if ((block?.type === "text" || block?.type === void 0) && typeof block.text === "string") {
|
|
1437
|
+
return unwrapCursorUserText(block.text);
|
|
1438
|
+
}
|
|
1439
|
+
return "";
|
|
1440
|
+
}).filter(Boolean).join(" ");
|
|
1441
|
+
}
|
|
1442
|
+
function collectCursorToolNames(content, into) {
|
|
1443
|
+
if (!Array.isArray(content)) return;
|
|
1444
|
+
for (const item of content) {
|
|
1445
|
+
const block = item;
|
|
1446
|
+
if (block?.type === "tool_use" && typeof block.name === "string" && block.name) {
|
|
1447
|
+
if (!into.includes(block.name)) into.push(block.name);
|
|
1448
|
+
}
|
|
1449
|
+
}
|
|
1450
|
+
}
|
|
1451
|
+
function firstTimestampHint(content) {
|
|
1452
|
+
if (typeof content === "string") return timestampFromCursorUserText(content);
|
|
1453
|
+
if (!Array.isArray(content)) return "";
|
|
1454
|
+
for (const item of content) {
|
|
1455
|
+
if (typeof item === "string") {
|
|
1456
|
+
const ts = timestampFromCursorUserText(item);
|
|
1457
|
+
if (ts) return ts;
|
|
1458
|
+
} else if (typeof item?.text === "string") {
|
|
1459
|
+
const ts = timestampFromCursorUserText(item.text);
|
|
1460
|
+
if (ts) return ts;
|
|
1461
|
+
}
|
|
1462
|
+
}
|
|
1463
|
+
return "";
|
|
1464
|
+
}
|
|
1465
|
+
function parseCursorJsonlLine(line) {
|
|
1466
|
+
if (!line.trim()) return null;
|
|
1467
|
+
let entry;
|
|
1468
|
+
try {
|
|
1469
|
+
entry = JSON.parse(line);
|
|
1470
|
+
} catch {
|
|
1471
|
+
return null;
|
|
1472
|
+
}
|
|
1473
|
+
return cursorEntryToMessage(entry);
|
|
1474
|
+
}
|
|
1475
|
+
function cursorEntryToMessage(entry) {
|
|
1476
|
+
if (looksLikeCursorChatEntry(entry)) {
|
|
1477
|
+
const role = entry.role;
|
|
1478
|
+
const message = entry.message;
|
|
1479
|
+
const content = message?.content ?? entry.content;
|
|
1480
|
+
return withToolUses(
|
|
1481
|
+
{ role, text: extractCursorText(content), timestamp: firstTimestampHint(content) },
|
|
1482
|
+
content
|
|
1483
|
+
);
|
|
1484
|
+
}
|
|
1485
|
+
if (looksLikeImportedClaudeEntry(entry)) {
|
|
1486
|
+
const message = entry.message;
|
|
1487
|
+
const role = message?.role === "assistant" || entry.type === "assistant" ? "assistant" : "user";
|
|
1488
|
+
const content = message?.content ?? entry.content;
|
|
1489
|
+
return withToolUses(
|
|
1490
|
+
{ role, text: extractCursorText(content), timestamp: asString2(entry.timestamp) },
|
|
1491
|
+
content
|
|
1492
|
+
);
|
|
1493
|
+
}
|
|
1494
|
+
return parseCodexJsonlLine(JSON.stringify(entry));
|
|
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
|
+
}
|
|
1516
|
+
function foldCursorMessage(acc, role, text, timestamp, tier) {
|
|
1517
|
+
if (timestamp && (!acc.latestTimestamp || timestamp > acc.latestTimestamp)) {
|
|
1518
|
+
acc.latestTimestamp = timestamp;
|
|
1519
|
+
}
|
|
1520
|
+
acc.messageCount++;
|
|
1521
|
+
acc.lastMessageSender = role;
|
|
1522
|
+
const snapshot = { text: text.slice(0, 200), timestamp };
|
|
1523
|
+
if (role === "user") {
|
|
1524
|
+
if (!acc.firstUser) acc.firstUser = snapshot;
|
|
1525
|
+
acc.lastUser = snapshot;
|
|
1526
|
+
} else {
|
|
1527
|
+
acc.lastAssistant = snapshot;
|
|
1528
|
+
}
|
|
1529
|
+
if (acc.previewLength < tier.previewMax) {
|
|
1530
|
+
acc.previewParts.push(text);
|
|
1531
|
+
acc.previewLength += text.length;
|
|
1532
|
+
}
|
|
1533
|
+
if (acc.snippetLength < tier.snippetMax) {
|
|
1534
|
+
const remaining = tier.snippetMax - acc.snippetLength;
|
|
1535
|
+
const chunk = text.length > remaining ? text.slice(0, remaining) : text;
|
|
1536
|
+
acc.snippetParts.push(chunk);
|
|
1537
|
+
acc.snippetLength += chunk.length;
|
|
1538
|
+
}
|
|
1539
|
+
}
|
|
1540
|
+
function reduceCursorEntry(acc, entry, tier) {
|
|
1541
|
+
const message = entry.message;
|
|
1542
|
+
const content = message?.content ?? entry.content;
|
|
1543
|
+
const textHint = extractCursorText(content);
|
|
1544
|
+
noteImportProvenance(acc, entry, textHint);
|
|
1545
|
+
if (looksLikeCursorChatEntry(entry)) {
|
|
1546
|
+
collectCursorToolNames(content, acc.toolNames);
|
|
1547
|
+
const text = textHint;
|
|
1548
|
+
if (!text) return;
|
|
1549
|
+
foldCursorMessage(acc, entry.role, text, firstTimestampHint(content), tier);
|
|
1550
|
+
return;
|
|
1551
|
+
}
|
|
1552
|
+
if (looksLikeImportedClaudeEntry(entry)) {
|
|
1553
|
+
collectCursorToolNames(content, acc.toolNames);
|
|
1554
|
+
const msg = cursorEntryToMessage(entry);
|
|
1555
|
+
if (!msg?.text) return;
|
|
1556
|
+
foldCursorMessage(acc, msg.role, msg.text, msg.timestamp, tier);
|
|
1557
|
+
return;
|
|
1558
|
+
}
|
|
1559
|
+
if (looksLikeImportedCodexEntry(entry)) {
|
|
1560
|
+
const msg = parseCodexJsonlLine(JSON.stringify(entry));
|
|
1561
|
+
if (!msg?.text) return;
|
|
1562
|
+
foldCursorMessage(acc, msg.role, msg.text, msg.timestamp, tier);
|
|
1563
|
+
}
|
|
1564
|
+
}
|
|
1565
|
+
function finalizeCursorMeta(acc, filePath, account, tier) {
|
|
1566
|
+
if (acc.messageCount === 0) return null;
|
|
1567
|
+
const sessionId = basename4(filePath, ".jsonl");
|
|
1568
|
+
const isSubagent = SUBAGENT_PATH_RE2.test(filePath);
|
|
1569
|
+
const parent = isSubagent ? parentFromSubagentPath(filePath) : null;
|
|
1570
|
+
const { projectPath, projectName } = projectFromCursorPath(filePath);
|
|
1571
|
+
const timestamp = acc.latestTimestamp || fileMtimeIso(filePath);
|
|
1572
|
+
const kind = acc.lastAssistant === null && acc.toolNames.length > 0 ? "task" : "conversation";
|
|
1573
|
+
return {
|
|
1574
|
+
id: filePath,
|
|
1575
|
+
filePath,
|
|
1576
|
+
provider: CURSOR_PROVIDER,
|
|
1577
|
+
kind,
|
|
1578
|
+
externalSessionId: sessionId,
|
|
1579
|
+
sessionId,
|
|
1580
|
+
sessionName: deriveSessionNameFromFirstMessage(acc.firstUser),
|
|
1581
|
+
projectPath,
|
|
1582
|
+
projectName,
|
|
1583
|
+
account,
|
|
1584
|
+
timestamp,
|
|
1585
|
+
messageCount: acc.messageCount,
|
|
1586
|
+
lastMessageSender: acc.lastMessageSender,
|
|
1587
|
+
preview: acc.previewParts.join(" ").slice(0, tier.previewMax),
|
|
1588
|
+
contentSnippet: acc.snippetParts.join(" "),
|
|
1589
|
+
gitBranch: null,
|
|
1590
|
+
model: null,
|
|
1591
|
+
isSubagent,
|
|
1592
|
+
parentSessionId: parent?.parentFilePath ?? null,
|
|
1593
|
+
subagentId: isSubagent ? sessionId : void 0,
|
|
1594
|
+
parentSessionUuid: parent?.parentSessionUuid ?? void 0,
|
|
1595
|
+
isTeammate: false,
|
|
1596
|
+
teamName: null,
|
|
1597
|
+
toolNames: acc.toolNames,
|
|
1598
|
+
firstMessage: acc.firstUser,
|
|
1599
|
+
lastMessage: acc.lastAssistant ?? acc.lastUser,
|
|
1600
|
+
lastPrompt: acc.lastUser?.text || void 0,
|
|
1601
|
+
...acc.isImportedFromClaude ? { isImportedFromClaude: true } : {},
|
|
1602
|
+
...acc.isImportedFromCodex ? { isImportedFromCodex: true } : {}
|
|
1603
|
+
};
|
|
1604
|
+
}
|
|
1605
|
+
function parentFromSubagentPath(filePath) {
|
|
1606
|
+
const subagentsDir = dirname3(filePath);
|
|
1607
|
+
const parentDir = dirname3(subagentsDir);
|
|
1608
|
+
const parentSessionUuid = basename4(parentDir);
|
|
1609
|
+
if (!parentSessionUuid) return null;
|
|
1610
|
+
return {
|
|
1611
|
+
parentSessionUuid,
|
|
1612
|
+
parentFilePath: canonicalPath(join4(parentDir, `${parentSessionUuid}.jsonl`))
|
|
1613
|
+
};
|
|
1614
|
+
}
|
|
1615
|
+
function projectFromCursorPath(filePath) {
|
|
1616
|
+
const parts = filePath.split(/[/\\]/);
|
|
1617
|
+
const idx = parts.lastIndexOf("agent-transcripts");
|
|
1618
|
+
const cursorProjectDir = idx > 0 ? parts.slice(0, idx).join(sep2) : dirname3(dirname3(filePath));
|
|
1619
|
+
const slug = basename4(cursorProjectDir);
|
|
1620
|
+
const decoded = decodeCursorProjectSlug(slug);
|
|
1621
|
+
const projectPath = decoded ?? cursorProjectDir;
|
|
1622
|
+
return { projectPath, projectName: getShortProjectName4(projectPath) || slug };
|
|
1623
|
+
}
|
|
1624
|
+
function decodeCursorProjectSlug(slug) {
|
|
1625
|
+
if (!slug) return null;
|
|
1626
|
+
const segments = slug.split("-");
|
|
1627
|
+
if (segments.length === 0) return null;
|
|
1628
|
+
const rooted = slug.startsWith("Users-") || slug.startsWith("home-") || /^[A-Za-z]-/.test(slug);
|
|
1629
|
+
let acc = rooted ? sep2 : "";
|
|
1630
|
+
let i = 0;
|
|
1631
|
+
if (rooted && segments[0] === "Users") {
|
|
1632
|
+
const users = `${sep2}Users`;
|
|
1633
|
+
if (!existsSync(users)) return null;
|
|
1634
|
+
acc = users;
|
|
1635
|
+
i = 1;
|
|
1636
|
+
}
|
|
1637
|
+
while (i < segments.length) {
|
|
1638
|
+
let found = null;
|
|
1639
|
+
let next = i + 1;
|
|
1640
|
+
for (let j = segments.length; j > i; j--) {
|
|
1641
|
+
const candidate = join4(acc, segments.slice(i, j).join("-"));
|
|
1642
|
+
try {
|
|
1643
|
+
if (existsSync(candidate) && statSync(candidate).isDirectory()) {
|
|
1644
|
+
found = candidate;
|
|
1645
|
+
next = j;
|
|
1646
|
+
break;
|
|
1647
|
+
}
|
|
1648
|
+
} catch {
|
|
1649
|
+
}
|
|
1650
|
+
}
|
|
1651
|
+
if (!found) return null;
|
|
1652
|
+
acc = found;
|
|
1653
|
+
i = next;
|
|
1654
|
+
}
|
|
1655
|
+
return acc;
|
|
1656
|
+
}
|
|
1657
|
+
function getShortProjectName4(fullPath) {
|
|
1658
|
+
return fullPath.split(/[/\\]/).filter(Boolean).slice(-3).join("/");
|
|
1659
|
+
}
|
|
1660
|
+
function fileMtimeIso(filePath) {
|
|
1661
|
+
try {
|
|
1662
|
+
return new Date(statSync(filePath).mtimeMs).toISOString();
|
|
1663
|
+
} catch {
|
|
1664
|
+
return (/* @__PURE__ */ new Date()).toISOString();
|
|
1665
|
+
}
|
|
1666
|
+
}
|
|
1667
|
+
async function parseCursorConversation(filePath, account) {
|
|
1668
|
+
const log = getLogger();
|
|
1669
|
+
const messages = [];
|
|
1670
|
+
const textParts = [];
|
|
1671
|
+
let latestTimestamp = "";
|
|
1672
|
+
let lastUserText = "";
|
|
1673
|
+
const rl = createInterface3({ input: createReadStream3(filePath), crlfDelay: Infinity });
|
|
1674
|
+
try {
|
|
1675
|
+
for await (const line of rl) {
|
|
1676
|
+
const message = parseCursorJsonlLine(line);
|
|
1677
|
+
if (!message) continue;
|
|
1678
|
+
if (message.timestamp && (!latestTimestamp || message.timestamp > latestTimestamp)) {
|
|
1679
|
+
latestTimestamp = message.timestamp;
|
|
1680
|
+
}
|
|
1681
|
+
messages.push(message);
|
|
1682
|
+
if (!message.text) continue;
|
|
1683
|
+
textParts.push(message.text);
|
|
1684
|
+
if (message.role === "user") lastUserText = message.text;
|
|
1685
|
+
}
|
|
1686
|
+
} catch (err) {
|
|
1687
|
+
log.warn({ filePath, err }, "parseCursorConversation: read failed");
|
|
1688
|
+
return null;
|
|
1689
|
+
}
|
|
1690
|
+
if (messages.length === 0) return null;
|
|
1691
|
+
const { projectPath, projectName } = projectFromCursorPath(filePath);
|
|
1692
|
+
const sessionId = basename4(filePath, ".jsonl");
|
|
1693
|
+
return {
|
|
1694
|
+
id: filePath,
|
|
1695
|
+
filePath,
|
|
1696
|
+
projectPath,
|
|
1697
|
+
projectName,
|
|
1698
|
+
sessionId,
|
|
1699
|
+
sessionName: "",
|
|
1700
|
+
messages,
|
|
1701
|
+
fullText: textParts.join(" "),
|
|
1702
|
+
timestamp: latestTimestamp || fileMtimeIso(filePath),
|
|
1703
|
+
messageCount: messages.length,
|
|
1704
|
+
account,
|
|
1705
|
+
lastPrompt: lastUserText || void 0
|
|
1706
|
+
};
|
|
1707
|
+
}
|
|
1708
|
+
|
|
1709
|
+
// src/discovery.ts
|
|
1710
|
+
import fg3 from "fast-glob";
|
|
1711
|
+
import { stat as stat3 } from "fs/promises";
|
|
1192
1712
|
var EXCLUDED_SEGMENTS = ["/memory/", "/tool-results/"];
|
|
1193
1713
|
var STAT_CONCURRENCY = 32;
|
|
1194
1714
|
async function discoverJsonlFiles(dirs, onProgress) {
|
|
@@ -1197,7 +1717,7 @@ async function discoverJsonlFiles(dirs, onProgress) {
|
|
|
1197
1717
|
for (const { projectsDir, account } of dirs) {
|
|
1198
1718
|
let filePaths;
|
|
1199
1719
|
try {
|
|
1200
|
-
filePaths = await
|
|
1720
|
+
filePaths = await fg3("**/*.jsonl", {
|
|
1201
1721
|
cwd: projectsDir,
|
|
1202
1722
|
absolute: true,
|
|
1203
1723
|
dot: false
|
|
@@ -1215,7 +1735,7 @@ async function discoverJsonlFiles(dirs, onProgress) {
|
|
|
1215
1735
|
const statted = await Promise.all(
|
|
1216
1736
|
chunk.map(async (filePath) => {
|
|
1217
1737
|
try {
|
|
1218
|
-
const s = await
|
|
1738
|
+
const s = await stat3(filePath);
|
|
1219
1739
|
return { filePath, size: s.size };
|
|
1220
1740
|
} catch (err) {
|
|
1221
1741
|
log.warn({ filePath, err }, "discovery: stat failed");
|
|
@@ -1290,9 +1810,9 @@ var ThreadbaseProvider = class {
|
|
|
1290
1810
|
|
|
1291
1811
|
// src/scanner.ts
|
|
1292
1812
|
import { EventEmitter } from "events";
|
|
1293
|
-
import { closeSync as closeSync2, openSync as openSync2, readSync as readSync2, statSync as
|
|
1813
|
+
import { closeSync as closeSync2, openSync as openSync2, readSync as readSync2, statSync as statSync4 } from "fs";
|
|
1294
1814
|
import { homedir as homedir2 } from "os";
|
|
1295
|
-
import { join as
|
|
1815
|
+
import { join as join6 } from "path";
|
|
1296
1816
|
|
|
1297
1817
|
// src/cache.ts
|
|
1298
1818
|
var LRUCache = class {
|
|
@@ -1331,18 +1851,18 @@ var LRUCache = class {
|
|
|
1331
1851
|
};
|
|
1332
1852
|
|
|
1333
1853
|
// src/persistent/conversation-stream.ts
|
|
1334
|
-
import { basename as
|
|
1854
|
+
import { basename as basename5 } from "path";
|
|
1335
1855
|
|
|
1336
1856
|
// src/persistent/paged-reader.ts
|
|
1337
|
-
import { createReadStream as
|
|
1857
|
+
import { createReadStream as createReadStream5 } from "fs";
|
|
1338
1858
|
import { setImmediate as yieldToEventLoop2 } from "timers/promises";
|
|
1339
1859
|
|
|
1340
1860
|
// src/persistent/jsonl-tail-reader.ts
|
|
1341
|
-
import { createReadStream as
|
|
1861
|
+
import { createReadStream as createReadStream4 } from "fs";
|
|
1342
1862
|
import { setImmediate as yieldToEventLoop } from "timers/promises";
|
|
1343
1863
|
var YIELD_EVERY_LINES = 500;
|
|
1344
1864
|
async function tailReduce(filePath, startOffset, startLine, state, tier, onEntry) {
|
|
1345
|
-
const stream =
|
|
1865
|
+
const stream = createReadStream4(filePath, { start: startOffset, encoding: "utf8" });
|
|
1346
1866
|
let buffer = "";
|
|
1347
1867
|
let offset = startOffset;
|
|
1348
1868
|
let line = startLine;
|
|
@@ -1379,7 +1899,7 @@ async function tailReduce(filePath, startOffset, startLine, state, tier, onEntry
|
|
|
1379
1899
|
// src/persistent/paged-reader.ts
|
|
1380
1900
|
var CHECKPOINT_INTERVAL = 500;
|
|
1381
1901
|
async function streamMessages(filePath, startOffset, startLine, state, onMessage, onEntry) {
|
|
1382
|
-
const stream =
|
|
1902
|
+
const stream = createReadStream5(filePath, { start: startOffset, encoding: "utf8" });
|
|
1383
1903
|
let buffer = "";
|
|
1384
1904
|
let offset = startOffset;
|
|
1385
1905
|
let line = startLine;
|
|
@@ -1491,7 +2011,7 @@ function assemble(filePath, account, messages, fullText, turnDurations, state) {
|
|
|
1491
2011
|
filePath,
|
|
1492
2012
|
projectPath: state.cwd,
|
|
1493
2013
|
projectName: getShortProjectName2(state.cwd),
|
|
1494
|
-
sessionId: state.sessionId ||
|
|
2014
|
+
sessionId: state.sessionId || basename5(filePath, ".jsonl"),
|
|
1495
2015
|
sessionName: state.sessionName || deriveSessionNameFromFirstMessage(messages.find((m) => m.role === "user" && m.text) ?? null),
|
|
1496
2016
|
messages,
|
|
1497
2017
|
fullText,
|
|
@@ -1535,11 +2055,11 @@ async function extendConversation(previous, resume, filePath, account) {
|
|
|
1535
2055
|
}
|
|
1536
2056
|
|
|
1537
2057
|
// src/persistent/cursor.ts
|
|
1538
|
-
import { createHash } from "crypto";
|
|
1539
|
-
import { closeSync, openSync, readSync, statSync } from "fs";
|
|
2058
|
+
import { createHash as createHash2 } from "crypto";
|
|
2059
|
+
import { closeSync, openSync, readSync, statSync as statSync2 } from "fs";
|
|
1540
2060
|
var FP_BYTES = 4096;
|
|
1541
2061
|
function fingerprint(filePath, size) {
|
|
1542
|
-
const hash =
|
|
2062
|
+
const hash = createHash2("sha1");
|
|
1543
2063
|
hash.update(String(size));
|
|
1544
2064
|
const fd = openSync(filePath, "r");
|
|
1545
2065
|
try {
|
|
@@ -1560,46 +2080,46 @@ function fingerprint(filePath, size) {
|
|
|
1560
2080
|
return hash.digest("hex");
|
|
1561
2081
|
}
|
|
1562
2082
|
function classify(filePath, existing) {
|
|
1563
|
-
let
|
|
2083
|
+
let stat5;
|
|
1564
2084
|
try {
|
|
1565
|
-
const s =
|
|
1566
|
-
|
|
2085
|
+
const s = statSync2(filePath);
|
|
2086
|
+
stat5 = { size: s.size, mtimeMs: s.mtimeMs };
|
|
1567
2087
|
} catch {
|
|
1568
2088
|
return { change: "vanished" };
|
|
1569
2089
|
}
|
|
1570
2090
|
if (!existing || existing.status !== "active" || existing.last_indexed_offset === 0) {
|
|
1571
|
-
return { change: "reindex", stat:
|
|
2091
|
+
return { change: "reindex", stat: stat5 };
|
|
1572
2092
|
}
|
|
1573
|
-
if (
|
|
1574
|
-
return { change: "reindex", stat:
|
|
2093
|
+
if (stat5.size < existing.last_indexed_offset) {
|
|
2094
|
+
return { change: "reindex", stat: stat5 };
|
|
1575
2095
|
}
|
|
1576
|
-
if (
|
|
1577
|
-
return { change: "unchanged", stat:
|
|
2096
|
+
if (stat5.size === existing.size_bytes && stat5.mtimeMs === existing.mtime_ms) {
|
|
2097
|
+
return { change: "unchanged", stat: stat5 };
|
|
1578
2098
|
}
|
|
1579
|
-
if (
|
|
1580
|
-
const fp = fingerprint(filePath,
|
|
2099
|
+
if (stat5.size === existing.last_indexed_offset) {
|
|
2100
|
+
const fp = fingerprint(filePath, stat5.size);
|
|
1581
2101
|
if (existing.content_fingerprint && fp !== existing.content_fingerprint) {
|
|
1582
|
-
return { change: "reindex", stat:
|
|
2102
|
+
return { change: "reindex", stat: stat5 };
|
|
1583
2103
|
}
|
|
1584
|
-
return { change: "unchanged", stat:
|
|
2104
|
+
return { change: "unchanged", stat: stat5 };
|
|
1585
2105
|
}
|
|
1586
2106
|
if (existing.content_fingerprint && existing.size_bytes === existing.last_indexed_offset && fingerprint(filePath, existing.last_indexed_offset) === existing.content_fingerprint) {
|
|
1587
|
-
return { change: "appended", stat:
|
|
2107
|
+
return { change: "appended", stat: stat5 };
|
|
1588
2108
|
}
|
|
1589
|
-
return { change: "reindex", stat:
|
|
2109
|
+
return { change: "reindex", stat: stat5 };
|
|
1590
2110
|
}
|
|
1591
2111
|
|
|
1592
2112
|
// src/persistent/index-engine.ts
|
|
1593
|
-
import { statSync as
|
|
2113
|
+
import { statSync as statSync3 } from "fs";
|
|
1594
2114
|
|
|
1595
2115
|
// src/providers/parse.ts
|
|
1596
|
-
import { createReadStream as
|
|
1597
|
-
import { createInterface as
|
|
2116
|
+
import { createReadStream as createReadStream6 } from "fs";
|
|
2117
|
+
import { createInterface as createInterface4 } from "readline";
|
|
1598
2118
|
async function parseMetaWithProvider(provider, filePath, account, tier, onEntry) {
|
|
1599
2119
|
const log = getLogger();
|
|
1600
2120
|
const acc = provider.createEmptyAccumulator();
|
|
1601
|
-
const rl =
|
|
1602
|
-
input:
|
|
2121
|
+
const rl = createInterface4({
|
|
2122
|
+
input: createReadStream6(filePath),
|
|
1603
2123
|
crlfDelay: Infinity
|
|
1604
2124
|
});
|
|
1605
2125
|
try {
|
|
@@ -1669,8 +2189,35 @@ function extractSearchDelta(entry) {
|
|
|
1669
2189
|
if (entry.type === "response_item" || entry.type === "session_meta") {
|
|
1670
2190
|
return extractCodexDelta(entry);
|
|
1671
2191
|
}
|
|
2192
|
+
if (looksLikeCursorChatEntry(entry)) {
|
|
2193
|
+
return extractCursorDelta(entry);
|
|
2194
|
+
}
|
|
1672
2195
|
return extractClaudeDelta(entry);
|
|
1673
2196
|
}
|
|
2197
|
+
function extractCursorDelta(entry) {
|
|
2198
|
+
const msg = entry.message;
|
|
2199
|
+
const content = msg?.content ?? entry.content;
|
|
2200
|
+
return {
|
|
2201
|
+
text: extractCursorSearchText(content),
|
|
2202
|
+
thinking: "",
|
|
2203
|
+
tools: extractClaudeToolContent(content)
|
|
2204
|
+
};
|
|
2205
|
+
}
|
|
2206
|
+
function extractCursorSearchText(content) {
|
|
2207
|
+
if (typeof content === "string") return unwrapCursorUserText(content);
|
|
2208
|
+
if (!Array.isArray(content)) return "";
|
|
2209
|
+
const parts = [];
|
|
2210
|
+
for (const item of content) {
|
|
2211
|
+
if (typeof item === "string") {
|
|
2212
|
+
const cleaned = unwrapCursorUserText(item);
|
|
2213
|
+
if (cleaned) parts.push(cleaned);
|
|
2214
|
+
} else if ((item?.type === "text" || item?.type === void 0) && typeof item?.text === "string") {
|
|
2215
|
+
const cleaned = unwrapCursorUserText(item.text);
|
|
2216
|
+
if (cleaned) parts.push(cleaned);
|
|
2217
|
+
}
|
|
2218
|
+
}
|
|
2219
|
+
return parts.join(SEP);
|
|
2220
|
+
}
|
|
1674
2221
|
function extractClaudeDelta(entry) {
|
|
1675
2222
|
const type = entry.type;
|
|
1676
2223
|
if (type !== "user" && type !== "assistant") return emptySearchDocument();
|
|
@@ -1788,10 +2335,10 @@ function resolveTier(tierName, customTiers) {
|
|
|
1788
2335
|
// src/persistent/db.ts
|
|
1789
2336
|
import Database from "better-sqlite3";
|
|
1790
2337
|
import { mkdirSync } from "fs";
|
|
1791
|
-
import { dirname as
|
|
2338
|
+
import { dirname as dirname4 } from "path";
|
|
1792
2339
|
|
|
1793
2340
|
// src/persistent/schema.ts
|
|
1794
|
-
var SCHEMA_VERSION =
|
|
2341
|
+
var SCHEMA_VERSION = 9;
|
|
1795
2342
|
var SCHEMA_SQL = `
|
|
1796
2343
|
CREATE TABLE IF NOT EXISTS conversation_files (
|
|
1797
2344
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
@@ -1876,6 +2423,10 @@ CREATE TABLE IF NOT EXISTS conversations (
|
|
|
1876
2423
|
tool_names_json TEXT,
|
|
1877
2424
|
last_prompt TEXT,
|
|
1878
2425
|
|
|
2426
|
+
is_imported_from_claude INTEGER NOT NULL DEFAULT 0,
|
|
2427
|
+
is_imported_from_codex INTEGER NOT NULL DEFAULT 0,
|
|
2428
|
+
is_imported_from_cursor INTEGER NOT NULL DEFAULT 0,
|
|
2429
|
+
|
|
1879
2430
|
status TEXT NOT NULL DEFAULT 'active',
|
|
1880
2431
|
|
|
1881
2432
|
created_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
@@ -2041,6 +2592,45 @@ function runMigrations(db) {
|
|
|
2041
2592
|
db.exec(`UPDATE conversation_files SET ${assignments.join(", ")}`);
|
|
2042
2593
|
}
|
|
2043
2594
|
}
|
|
2595
|
+
if (current >= 1 && current < 8 && tableExists(db, "conversations")) {
|
|
2596
|
+
for (const [col, ddl] of [
|
|
2597
|
+
[
|
|
2598
|
+
"is_imported_from_claude",
|
|
2599
|
+
"ALTER TABLE conversations ADD COLUMN is_imported_from_claude INTEGER NOT NULL DEFAULT 0"
|
|
2600
|
+
],
|
|
2601
|
+
[
|
|
2602
|
+
"is_imported_from_codex",
|
|
2603
|
+
"ALTER TABLE conversations ADD COLUMN is_imported_from_codex INTEGER NOT NULL DEFAULT 0"
|
|
2604
|
+
],
|
|
2605
|
+
[
|
|
2606
|
+
"is_imported_from_cursor",
|
|
2607
|
+
"ALTER TABLE conversations ADD COLUMN is_imported_from_cursor INTEGER NOT NULL DEFAULT 0"
|
|
2608
|
+
]
|
|
2609
|
+
]) {
|
|
2610
|
+
if (!hasColumn(db, "conversations", col)) db.exec(ddl);
|
|
2611
|
+
}
|
|
2612
|
+
if (tableExists(db, "conversation_files")) {
|
|
2613
|
+
const assignments = [];
|
|
2614
|
+
if (hasColumn(db, "conversation_files", "last_indexed_offset")) {
|
|
2615
|
+
assignments.push("last_indexed_offset = 0");
|
|
2616
|
+
}
|
|
2617
|
+
if (hasColumn(db, "conversation_files", "last_indexed_line")) {
|
|
2618
|
+
assignments.push("last_indexed_line = 0");
|
|
2619
|
+
}
|
|
2620
|
+
if (hasColumn(db, "conversation_files", "reducer_state")) {
|
|
2621
|
+
assignments.push("reducer_state = NULL");
|
|
2622
|
+
}
|
|
2623
|
+
if (assignments.length > 0) {
|
|
2624
|
+
db.exec(
|
|
2625
|
+
`UPDATE conversation_files SET ${assignments.join(", ")}
|
|
2626
|
+
WHERE id IN (SELECT file_id FROM conversations WHERE provider IN ('cursor', 'cursor-cli'))`
|
|
2627
|
+
);
|
|
2628
|
+
}
|
|
2629
|
+
}
|
|
2630
|
+
}
|
|
2631
|
+
if (current >= 1 && current < 9 && tableExists(db, "conversations")) {
|
|
2632
|
+
db.exec(`UPDATE conversations SET provider = 'cursor' WHERE provider = 'cursor-cli'`);
|
|
2633
|
+
}
|
|
2044
2634
|
db.exec(SCHEMA_SQL);
|
|
2045
2635
|
db.pragma(`user_version = ${SCHEMA_VERSION}`);
|
|
2046
2636
|
}
|
|
@@ -2055,7 +2645,7 @@ function hasColumn(db, table, column) {
|
|
|
2055
2645
|
// src/persistent/db.ts
|
|
2056
2646
|
function openDatabase(dbPath) {
|
|
2057
2647
|
if (dbPath !== ":memory:") {
|
|
2058
|
-
mkdirSync(
|
|
2648
|
+
mkdirSync(dirname4(dbPath), { recursive: true });
|
|
2059
2649
|
}
|
|
2060
2650
|
let db;
|
|
2061
2651
|
try {
|
|
@@ -2099,8 +2689,8 @@ function nativeBindingError(err, dbPath) {
|
|
|
2099
2689
|
}
|
|
2100
2690
|
|
|
2101
2691
|
// src/persistent/dir-watermark.ts
|
|
2102
|
-
import { readdir, stat as
|
|
2103
|
-
import { dirname as
|
|
2692
|
+
import { readdir, stat as stat4 } from "fs/promises";
|
|
2693
|
+
import { dirname as dirname5, join as join5 } from "path";
|
|
2104
2694
|
var FULL_RECONCILE_EVERY_N_SCANS = 20;
|
|
2105
2695
|
async function discoverJsonlFilesGated(dirs, files, scannedDirs, options = {}) {
|
|
2106
2696
|
const log = getLogger();
|
|
@@ -2116,7 +2706,7 @@ async function discoverJsonlFilesGated(dirs, files, scannedDirs, options = {}) {
|
|
|
2116
2706
|
for (const projectDir of resolved.entries) {
|
|
2117
2707
|
let dirStat;
|
|
2118
2708
|
try {
|
|
2119
|
-
dirStat = await
|
|
2709
|
+
dirStat = await stat4(projectDir);
|
|
2120
2710
|
} catch {
|
|
2121
2711
|
scannedDirs.remove(projectDir);
|
|
2122
2712
|
continue;
|
|
@@ -2154,7 +2744,7 @@ async function discoverJsonlFilesGated(dirs, files, scannedDirs, options = {}) {
|
|
|
2154
2744
|
async function resolveProjectDirs(projectsDir, scannedDirs) {
|
|
2155
2745
|
let rootStat;
|
|
2156
2746
|
try {
|
|
2157
|
-
rootStat = await
|
|
2747
|
+
rootStat = await stat4(projectsDir);
|
|
2158
2748
|
} catch {
|
|
2159
2749
|
return null;
|
|
2160
2750
|
}
|
|
@@ -2171,10 +2761,10 @@ async function resolveProjectDirs(projectsDir, scannedDirs) {
|
|
|
2171
2761
|
return { entries, commitRoot: { mtimeMs: rootStat.mtimeMs } };
|
|
2172
2762
|
}
|
|
2173
2763
|
function dirnameOf(filePath) {
|
|
2174
|
-
return
|
|
2764
|
+
return dirname5(filePath);
|
|
2175
2765
|
}
|
|
2176
2766
|
function joinPath(dir, name) {
|
|
2177
|
-
return
|
|
2767
|
+
return join5(dir, name);
|
|
2178
2768
|
}
|
|
2179
2769
|
|
|
2180
2770
|
// src/persistent/repositories/checkpoints.repo.ts
|
|
@@ -2254,7 +2844,7 @@ function toCheckpoint(row) {
|
|
|
2254
2844
|
}
|
|
2255
2845
|
|
|
2256
2846
|
// src/persistent/repositories/conversation-files.repo.ts
|
|
2257
|
-
import { basename as
|
|
2847
|
+
import { basename as basename6, dirname as dirname6 } from "path";
|
|
2258
2848
|
var ConversationFilesRepo = class {
|
|
2259
2849
|
constructor(db) {
|
|
2260
2850
|
this.db = db;
|
|
@@ -2277,7 +2867,7 @@ var ConversationFilesRepo = class {
|
|
|
2277
2867
|
const info = this.db.prepare(
|
|
2278
2868
|
`INSERT INTO conversation_files (absolute_path, parent_dir, file_name, account)
|
|
2279
2869
|
VALUES (?, ?, ?, ?)`
|
|
2280
|
-
).run(canonical,
|
|
2870
|
+
).run(canonical, dirname6(canonical), basename6(canonical), account);
|
|
2281
2871
|
return Number(info.lastInsertRowid);
|
|
2282
2872
|
}
|
|
2283
2873
|
// Advance the cursor + persisted reducer state after a successful index pass.
|
|
@@ -2372,7 +2962,10 @@ function rowToMeta(row) {
|
|
|
2372
2962
|
toolNames: row.tool_names_json ? JSON.parse(row.tool_names_json) : [],
|
|
2373
2963
|
firstMessage: row.first_sent_text ? { text: row.first_sent_text, timestamp: row.first_sent_at ?? "" } : null,
|
|
2374
2964
|
lastMessage: row.last_sent_text ? { text: row.last_sent_text, timestamp: row.last_sent_at ?? "" } : null,
|
|
2375
|
-
lastPrompt: row.last_prompt ?? void 0
|
|
2965
|
+
lastPrompt: row.last_prompt ?? void 0,
|
|
2966
|
+
...row.is_imported_from_claude === 1 ? { isImportedFromClaude: true } : {},
|
|
2967
|
+
...row.is_imported_from_codex === 1 ? { isImportedFromCodex: true } : {},
|
|
2968
|
+
...row.is_imported_from_cursor === 1 ? { isImportedFromCursor: true } : {}
|
|
2376
2969
|
};
|
|
2377
2970
|
}
|
|
2378
2971
|
var ConversationsRepo = class {
|
|
@@ -2392,7 +2985,8 @@ var ConversationsRepo = class {
|
|
|
2392
2985
|
timestamp, index_seq, first_sent_at, first_sent_text, last_sent_at, last_sent_text,
|
|
2393
2986
|
model, is_subagent, parent_session_id, subagent_id, parent_session_uuid,
|
|
2394
2987
|
is_teammate, team_name, tool_names_json,
|
|
2395
|
-
last_prompt,
|
|
2988
|
+
last_prompt, is_imported_from_claude, is_imported_from_codex,
|
|
2989
|
+
is_imported_from_cursor, status, updated_at
|
|
2396
2990
|
) VALUES (
|
|
2397
2991
|
@file_id, @source_path, @provider, @kind, @external_session_id,
|
|
2398
2992
|
@session_id, @session_name, @project_path, @project_name,
|
|
@@ -2403,7 +2997,8 @@ var ConversationsRepo = class {
|
|
|
2403
2997
|
@first_sent_at, @first_sent_text, @last_sent_at, @last_sent_text,
|
|
2404
2998
|
@model, @is_subagent, @parent_session_id, @subagent_id, @parent_session_uuid,
|
|
2405
2999
|
@is_teammate, @team_name, @tool_names_json,
|
|
2406
|
-
@last_prompt,
|
|
3000
|
+
@last_prompt, @is_imported_from_claude, @is_imported_from_codex,
|
|
3001
|
+
@is_imported_from_cursor, 'active', CURRENT_TIMESTAMP
|
|
2407
3002
|
)
|
|
2408
3003
|
ON CONFLICT(file_id) DO UPDATE SET
|
|
2409
3004
|
source_path = excluded.source_path,
|
|
@@ -2435,6 +3030,9 @@ var ConversationsRepo = class {
|
|
|
2435
3030
|
team_name = excluded.team_name,
|
|
2436
3031
|
tool_names_json = excluded.tool_names_json,
|
|
2437
3032
|
last_prompt = excluded.last_prompt,
|
|
3033
|
+
is_imported_from_claude = excluded.is_imported_from_claude,
|
|
3034
|
+
is_imported_from_codex = excluded.is_imported_from_codex,
|
|
3035
|
+
is_imported_from_cursor = excluded.is_imported_from_cursor,
|
|
2438
3036
|
status = 'active',
|
|
2439
3037
|
index_seq = (SELECT COALESCE(MAX(index_seq), 0) + 1 FROM conversations),
|
|
2440
3038
|
updated_at = CURRENT_TIMESTAMP`
|
|
@@ -2471,7 +3069,10 @@ var ConversationsRepo = class {
|
|
|
2471
3069
|
is_teammate: meta.isTeammate ? 1 : 0,
|
|
2472
3070
|
team_name: meta.teamName,
|
|
2473
3071
|
tool_names_json: JSON.stringify(meta.toolNames),
|
|
2474
|
-
last_prompt: meta.lastPrompt ?? null
|
|
3072
|
+
last_prompt: meta.lastPrompt ?? null,
|
|
3073
|
+
is_imported_from_claude: meta.isImportedFromClaude ? 1 : 0,
|
|
3074
|
+
is_imported_from_codex: meta.isImportedFromCodex ? 1 : 0,
|
|
3075
|
+
is_imported_from_cursor: meta.isImportedFromCursor ? 1 : 0
|
|
2475
3076
|
});
|
|
2476
3077
|
}
|
|
2477
3078
|
getBySourcePath(sourcePath) {
|
|
@@ -2631,8 +3232,14 @@ var FtsRepo = class {
|
|
|
2631
3232
|
params.push(filters.account);
|
|
2632
3233
|
}
|
|
2633
3234
|
if (filters.provider) {
|
|
2634
|
-
|
|
2635
|
-
|
|
3235
|
+
const provider = canonicalizeProviderName(filters.provider) ?? filters.provider;
|
|
3236
|
+
if (provider === CURSOR_PROVIDER) {
|
|
3237
|
+
where.push("(c.provider = ? OR c.provider = ?)");
|
|
3238
|
+
params.push(CURSOR_PROVIDER, LEGACY_CURSOR_PROVIDER);
|
|
3239
|
+
} else {
|
|
3240
|
+
where.push("c.provider = ?");
|
|
3241
|
+
params.push(provider);
|
|
3242
|
+
}
|
|
2636
3243
|
}
|
|
2637
3244
|
if (filters.project) {
|
|
2638
3245
|
where.push("(lower(c.project_path) LIKE ? OR lower(c.project_name) LIKE ?)");
|
|
@@ -2751,7 +3358,7 @@ var PersistentEngine = class {
|
|
|
2751
3358
|
async indexAll(activeProfiles, options) {
|
|
2752
3359
|
const log = getLogger();
|
|
2753
3360
|
const tier = resolveTier(options.tier ?? "standard", options.tiers);
|
|
2754
|
-
const enabled = options.providers
|
|
3361
|
+
const enabled = canonicalizeProviderList(options.providers);
|
|
2755
3362
|
const discovered = [];
|
|
2756
3363
|
if (enabled.includes(CLAUDE_CODE_PROVIDER)) {
|
|
2757
3364
|
const configDirs = activeProfiles.map((p) => ({
|
|
@@ -2771,6 +3378,12 @@ var PersistentEngine = class {
|
|
|
2771
3378
|
discovered.push({ ...f, provider: codex });
|
|
2772
3379
|
}
|
|
2773
3380
|
}
|
|
3381
|
+
const cursor = new CursorProvider();
|
|
3382
|
+
if (enabled.includes(CURSOR_PROVIDER) && (options.cursorRoots?.length ?? 0) > 0) {
|
|
3383
|
+
for (const f of await cursor.discover(options.cursorRoots)) {
|
|
3384
|
+
discovered.push({ ...f, provider: cursor });
|
|
3385
|
+
}
|
|
3386
|
+
}
|
|
2774
3387
|
let scanned = 0;
|
|
2775
3388
|
const gitBranchMemo = /* @__PURE__ */ new Map();
|
|
2776
3389
|
const resolveGitBranch = (projectPath) => {
|
|
@@ -2809,6 +3422,9 @@ var PersistentEngine = class {
|
|
|
2809
3422
|
if (enabled.includes(CODEX_CLI_PROVIDER) && (options.codexRoots?.length ?? 0) > 0) {
|
|
2810
3423
|
coveredAccounts.add("codex");
|
|
2811
3424
|
}
|
|
3425
|
+
if (enabled.includes(CURSOR_PROVIDER) && (options.cursorRoots?.length ?? 0) > 0) {
|
|
3426
|
+
coveredAccounts.add("cursor");
|
|
3427
|
+
}
|
|
2812
3428
|
const seen = new Set(discovered.map((d) => canonicalPath(d.filePath)));
|
|
2813
3429
|
for (const path of this.files.activePathsByAccounts([...coveredAccounts])) {
|
|
2814
3430
|
if (!seen.has(path)) this.markDeleted(path);
|
|
@@ -2828,8 +3444,8 @@ var PersistentEngine = class {
|
|
|
2828
3444
|
const tier = resolveTier(tierName, customTiers);
|
|
2829
3445
|
const filePath = canonicalPath(rawFilePath);
|
|
2830
3446
|
const existing = this.files.getByPath(filePath);
|
|
2831
|
-
const { change, stat:
|
|
2832
|
-
if (change === "vanished" || !
|
|
3447
|
+
const { change, stat: stat5 } = classify(filePath, existing);
|
|
3448
|
+
if (change === "vanished" || !stat5) {
|
|
2833
3449
|
this.markDeleted(filePath);
|
|
2834
3450
|
return { meta: null, change: "vanished" };
|
|
2835
3451
|
}
|
|
@@ -2842,7 +3458,7 @@ var PersistentEngine = class {
|
|
|
2842
3458
|
filePath,
|
|
2843
3459
|
account,
|
|
2844
3460
|
tier,
|
|
2845
|
-
|
|
3461
|
+
stat5,
|
|
2846
3462
|
resolveGitBranch
|
|
2847
3463
|
);
|
|
2848
3464
|
return { meta: meta2, change };
|
|
@@ -2868,7 +3484,7 @@ var PersistentEngine = class {
|
|
|
2868
3484
|
return { meta: null, change };
|
|
2869
3485
|
}
|
|
2870
3486
|
meta.gitBranch = resolveGitBranch(meta.projectPath);
|
|
2871
|
-
const fp =
|
|
3487
|
+
const fp = stat5.size > 0 ? fingerprint(filePath, stat5.size) : null;
|
|
2872
3488
|
const fileId = this.files.ensure(filePath, account);
|
|
2873
3489
|
const base = resume ? this.fts.readDocument(fileId) ?? emptySearchDocument() : emptySearchDocument();
|
|
2874
3490
|
const searchDoc = appendSearchDelta(base, searchDelta);
|
|
@@ -2879,8 +3495,8 @@ var PersistentEngine = class {
|
|
|
2879
3495
|
}
|
|
2880
3496
|
if (!resume) this.checkpoints.remove(filePath);
|
|
2881
3497
|
this.files.updateCursor(fileId, {
|
|
2882
|
-
sizeBytes:
|
|
2883
|
-
mtimeMs:
|
|
3498
|
+
sizeBytes: stat5.size,
|
|
3499
|
+
mtimeMs: stat5.mtimeMs,
|
|
2884
3500
|
// Advance only to the last fully-parsed line; a trailing partial line
|
|
2885
3501
|
// is left for the next pass.
|
|
2886
3502
|
offset: result.newOffset,
|
|
@@ -2897,8 +3513,8 @@ var PersistentEngine = class {
|
|
|
2897
3513
|
buildSidecar(
|
|
2898
3514
|
meta,
|
|
2899
3515
|
{
|
|
2900
|
-
sizeBytes:
|
|
2901
|
-
mtimeMs:
|
|
3516
|
+
sizeBytes: stat5.size,
|
|
3517
|
+
mtimeMs: stat5.mtimeMs,
|
|
2902
3518
|
offset: result.newOffset,
|
|
2903
3519
|
line: result.newLine
|
|
2904
3520
|
},
|
|
@@ -2917,7 +3533,7 @@ var PersistentEngine = class {
|
|
|
2917
3533
|
// the Threadbase path uses. The cursor records size/mtime (and offset = size)
|
|
2918
3534
|
// so the next pass classifies an unchanged file as "unchanged" and skips it;
|
|
2919
3535
|
// any change reparses from 0 again. No reducer_state is persisted.
|
|
2920
|
-
async indexFileWithProvider(provider, filePath, account, tier,
|
|
3536
|
+
async indexFileWithProvider(provider, filePath, account, tier, stat5, resolveGitBranch) {
|
|
2921
3537
|
const log = getLogger();
|
|
2922
3538
|
let searchDoc = emptySearchDocument();
|
|
2923
3539
|
const meta = await parseMetaWithProvider(provider, filePath, account, tier, (entry) => {
|
|
@@ -2930,7 +3546,7 @@ var PersistentEngine = class {
|
|
|
2930
3546
|
if (meta.gitBranch === null && meta.projectPath) {
|
|
2931
3547
|
meta.gitBranch = resolveGitBranch(meta.projectPath);
|
|
2932
3548
|
}
|
|
2933
|
-
const fp =
|
|
3549
|
+
const fp = stat5.size > 0 ? fingerprint(filePath, stat5.size) : null;
|
|
2934
3550
|
const fileId = this.files.ensure(filePath, account);
|
|
2935
3551
|
const upsert = this.db.transaction(() => {
|
|
2936
3552
|
this.conversations.upsert(fileId, meta, meta.messageCount);
|
|
@@ -2939,11 +3555,11 @@ var PersistentEngine = class {
|
|
|
2939
3555
|
}
|
|
2940
3556
|
this.checkpoints.remove(filePath);
|
|
2941
3557
|
this.files.updateCursor(fileId, {
|
|
2942
|
-
sizeBytes:
|
|
2943
|
-
mtimeMs:
|
|
3558
|
+
sizeBytes: stat5.size,
|
|
3559
|
+
mtimeMs: stat5.mtimeMs,
|
|
2944
3560
|
// offset = size marks the file fully consumed (non-zero so the next pass
|
|
2945
3561
|
// can classify it "unchanged"); no resumable reducer state is kept.
|
|
2946
|
-
offset:
|
|
3562
|
+
offset: stat5.size,
|
|
2947
3563
|
line: 0,
|
|
2948
3564
|
reducerState: null,
|
|
2949
3565
|
fingerprint: fp,
|
|
@@ -3009,8 +3625,8 @@ var PersistentEngine = class {
|
|
|
3009
3625
|
const meta = this.conversations.getByIdOrSession(id);
|
|
3010
3626
|
if (!meta) return null;
|
|
3011
3627
|
const filePath = meta.filePath;
|
|
3012
|
-
if (meta.provider === CODEX_CLI_PROVIDER) {
|
|
3013
|
-
const conversation = await parseCodexConversation(filePath, meta.account);
|
|
3628
|
+
if (meta.provider === CODEX_CLI_PROVIDER || meta.provider === CURSOR_PROVIDER) {
|
|
3629
|
+
const conversation = meta.provider === CODEX_CLI_PROVIDER ? await parseCodexConversation(filePath, meta.account) : await parseCursorConversation(filePath, meta.account);
|
|
3014
3630
|
if (!conversation) return null;
|
|
3015
3631
|
const { messages } = conversation;
|
|
3016
3632
|
const total2 = messages.length;
|
|
@@ -3025,7 +3641,7 @@ var PersistentEngine = class {
|
|
|
3025
3641
|
let floor = this.checkpoints.floor(filePath, fromIndex);
|
|
3026
3642
|
if (floor) {
|
|
3027
3643
|
try {
|
|
3028
|
-
if (floor.byteOffset >
|
|
3644
|
+
if (floor.byteOffset > statSync3(filePath).size) floor = null;
|
|
3029
3645
|
} catch {
|
|
3030
3646
|
}
|
|
3031
3647
|
}
|
|
@@ -3164,7 +3780,7 @@ function defaultDbPath() {
|
|
|
3164
3780
|
"TB_SCANNER_DB must be set under a test runner. Refusing to open the default index at ~/.config/threadbase-scanner/index.db, because test fixtures written there are indistinguishable from real conversations and corrupt every measurement of the index. Point it at a temp directory in your test setup, or pass persistent.dbPath explicitly."
|
|
3165
3781
|
);
|
|
3166
3782
|
}
|
|
3167
|
-
return
|
|
3783
|
+
return join6(homedir2(), ".config", "threadbase-scanner", "index.db");
|
|
3168
3784
|
}
|
|
3169
3785
|
function capForMemory(doc, max) {
|
|
3170
3786
|
const combined = combineSearchContent(doc);
|
|
@@ -3343,7 +3959,7 @@ var ConversationScanner = class {
|
|
|
3343
3959
|
const cached = statCache.get(filePath);
|
|
3344
3960
|
if (cached) {
|
|
3345
3961
|
try {
|
|
3346
|
-
const s =
|
|
3962
|
+
const s = statSync4(filePath);
|
|
3347
3963
|
if (s.mtimeMs === cached.stat.mtimeMs && s.size === cached.stat.size) {
|
|
3348
3964
|
return {
|
|
3349
3965
|
meta: cached.meta,
|
|
@@ -3474,9 +4090,7 @@ var ConversationScanner = class {
|
|
|
3474
4090
|
results = results.filter((r) => r.meta.account === options.account);
|
|
3475
4091
|
}
|
|
3476
4092
|
if (options.provider) {
|
|
3477
|
-
results = results.filter(
|
|
3478
|
-
(r) => (r.meta.provider ?? CLAUDE_CODE_PROVIDER) === options.provider
|
|
3479
|
-
);
|
|
4093
|
+
results = results.filter((r) => providerMatches(r.meta.provider, options.provider));
|
|
3480
4094
|
}
|
|
3481
4095
|
if (options.since) {
|
|
3482
4096
|
const cutoff = parseSinceCutoff(options.since);
|
|
@@ -3503,12 +4117,12 @@ var ConversationScanner = class {
|
|
|
3503
4117
|
}
|
|
3504
4118
|
log.debug({ id, filePath: meta.filePath }, "getConversation: cache miss, parsing");
|
|
3505
4119
|
try {
|
|
3506
|
-
if (this.persistent && meta.provider !== CODEX_CLI_PROVIDER) {
|
|
4120
|
+
if (this.persistent && meta.provider !== CODEX_CLI_PROVIDER && meta.provider !== CURSOR_PROVIDER) {
|
|
3507
4121
|
const parsed = await parseConversationResumable(meta.filePath, meta.account);
|
|
3508
4122
|
if (parsed) this.conversationLRU.set(cid, parsed);
|
|
3509
4123
|
return parsed?.conversation ?? null;
|
|
3510
4124
|
}
|
|
3511
|
-
const conversation = meta.provider === CODEX_CLI_PROVIDER ? await parseCodexConversation(meta.filePath, meta.account) : await parseConversation(meta.filePath, meta.account);
|
|
4125
|
+
const conversation = meta.provider === CODEX_CLI_PROVIDER ? await parseCodexConversation(meta.filePath, meta.account) : meta.provider === CURSOR_PROVIDER ? await parseCursorConversation(meta.filePath, meta.account) : await parseConversation(meta.filePath, meta.account);
|
|
3512
4126
|
if (conversation) {
|
|
3513
4127
|
this.conversationLRU.set(cid, { conversation });
|
|
3514
4128
|
}
|
|
@@ -3562,7 +4176,7 @@ var ConversationScanner = class {
|
|
|
3562
4176
|
// fallback, matching refreshFile.
|
|
3563
4177
|
async parseSingleFilePage(filePath, account, options) {
|
|
3564
4178
|
const provider = await this.resolveProviderForFile(filePath, null);
|
|
3565
|
-
const conversation = provider?.name === CODEX_CLI_PROVIDER ? await parseCodexConversation(filePath, account ?? "default") : await parseConversation(filePath, account ?? "default");
|
|
4179
|
+
const conversation = provider?.name === CODEX_CLI_PROVIDER ? await parseCodexConversation(filePath, account ?? "default") : provider?.name === CURSOR_PROVIDER ? await parseCursorConversation(filePath, account ?? "default") : await parseConversation(filePath, account ?? "default");
|
|
3566
4180
|
if (!conversation) return null;
|
|
3567
4181
|
const { messages } = conversation;
|
|
3568
4182
|
const total = messages.length;
|
|
@@ -3851,7 +4465,7 @@ var ConversationScanner = class {
|
|
|
3851
4465
|
// discovers under the active profiles' project dirs; Codex discovers under
|
|
3852
4466
|
// the explicit codexRoots (opt-in — no default home scan).
|
|
3853
4467
|
async discoverWithProviders(activeProfiles, options) {
|
|
3854
|
-
const enabled = options.providers
|
|
4468
|
+
const enabled = canonicalizeProviderList(options.providers);
|
|
3855
4469
|
const work = [];
|
|
3856
4470
|
if (enabled.includes(CLAUDE_CODE_PROVIDER)) {
|
|
3857
4471
|
const provider = new ThreadbaseProvider();
|
|
@@ -3866,6 +4480,12 @@ var ConversationScanner = class {
|
|
|
3866
4480
|
work.push({ ...f, provider });
|
|
3867
4481
|
}
|
|
3868
4482
|
}
|
|
4483
|
+
if (enabled.includes(CURSOR_PROVIDER) && (options.cursorRoots?.length ?? 0) > 0) {
|
|
4484
|
+
const provider = new CursorProvider();
|
|
4485
|
+
for (const f of await provider.discover(options.cursorRoots)) {
|
|
4486
|
+
work.push({ ...f, provider });
|
|
4487
|
+
}
|
|
4488
|
+
}
|
|
3869
4489
|
return work;
|
|
3870
4490
|
}
|
|
3871
4491
|
// Resolve which provider should (re)parse a file. Stored metadata wins; for a
|
|
@@ -3874,6 +4494,9 @@ var ConversationScanner = class {
|
|
|
3874
4494
|
// tail-read path).
|
|
3875
4495
|
async resolveProviderForFile(filePath, previous) {
|
|
3876
4496
|
if (previous?.provider === CODEX_CLI_PROVIDER) return new CodexCliProvider();
|
|
4497
|
+
if (providerMatches(previous?.provider, CURSOR_PROVIDER)) {
|
|
4498
|
+
return new CursorProvider();
|
|
4499
|
+
}
|
|
3877
4500
|
if (previous?.provider) return void 0;
|
|
3878
4501
|
let sample = "";
|
|
3879
4502
|
try {
|
|
@@ -3888,6 +4511,8 @@ var ConversationScanner = class {
|
|
|
3888
4511
|
} catch {
|
|
3889
4512
|
return void 0;
|
|
3890
4513
|
}
|
|
4514
|
+
const cursor = new CursorProvider();
|
|
4515
|
+
if (cursor.canParse(filePath, sample)) return cursor;
|
|
3891
4516
|
const codex = new CodexCliProvider();
|
|
3892
4517
|
if (codex.canParse(filePath, sample)) return codex;
|
|
3893
4518
|
return void 0;
|
|
@@ -3996,9 +4621,14 @@ async function getConversation(id, options, scanner) {
|
|
|
3996
4621
|
return (scanner ?? getDefaultScanner()).getConversation(id, options);
|
|
3997
4622
|
}
|
|
3998
4623
|
export {
|
|
4624
|
+
CLAUDE_CODE_PROVIDER,
|
|
4625
|
+
CODEX_CLI_PROVIDER,
|
|
4626
|
+
CURSOR_PROVIDER,
|
|
3999
4627
|
CodexCliProvider,
|
|
4000
4628
|
ConversationScanner,
|
|
4629
|
+
CursorProvider,
|
|
4001
4630
|
DEFAULT_TIERS,
|
|
4631
|
+
LEGACY_CURSOR_PROVIDER,
|
|
4002
4632
|
SearchIndexer,
|
|
4003
4633
|
ThreadbaseProvider,
|
|
4004
4634
|
VALID_SORT_ORDERS,
|
|
@@ -4008,6 +4638,8 @@ export {
|
|
|
4008
4638
|
applyProjectFilter,
|
|
4009
4639
|
applySinceFilter,
|
|
4010
4640
|
applySort,
|
|
4641
|
+
canonicalizeProviderList,
|
|
4642
|
+
canonicalizeProviderName,
|
|
4011
4643
|
cleanSystemTags,
|
|
4012
4644
|
initialConvState as createJsonlParseState,
|
|
4013
4645
|
createLogger,
|
|
@@ -4018,7 +4650,9 @@ export {
|
|
|
4018
4650
|
isCodexInjectedContext,
|
|
4019
4651
|
loadProfiles,
|
|
4020
4652
|
parseCodexJsonlLine,
|
|
4653
|
+
parseCursorJsonlLine,
|
|
4021
4654
|
parseJsonlLine,
|
|
4655
|
+
providerMatches,
|
|
4022
4656
|
readGitBranch,
|
|
4023
4657
|
readSidecar,
|
|
4024
4658
|
resetDefaultScanner,
|
|
@@ -4028,6 +4662,7 @@ export {
|
|
|
4028
4662
|
scan,
|
|
4029
4663
|
search,
|
|
4030
4664
|
setLogger,
|
|
4031
|
-
sidecarPath
|
|
4665
|
+
sidecarPath,
|
|
4666
|
+
unwrapCursorUserText
|
|
4032
4667
|
};
|
|
4033
4668
|
//# sourceMappingURL=index.js.map
|