@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.cjs
CHANGED
|
@@ -30,9 +30,14 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
30
30
|
// src/index.ts
|
|
31
31
|
var index_exports = {};
|
|
32
32
|
__export(index_exports, {
|
|
33
|
+
CLAUDE_CODE_PROVIDER: () => CLAUDE_CODE_PROVIDER,
|
|
34
|
+
CODEX_CLI_PROVIDER: () => CODEX_CLI_PROVIDER,
|
|
35
|
+
CURSOR_PROVIDER: () => CURSOR_PROVIDER,
|
|
33
36
|
CodexCliProvider: () => CodexCliProvider,
|
|
34
37
|
ConversationScanner: () => ConversationScanner,
|
|
38
|
+
CursorProvider: () => CursorProvider,
|
|
35
39
|
DEFAULT_TIERS: () => DEFAULT_TIERS,
|
|
40
|
+
LEGACY_CURSOR_PROVIDER: () => LEGACY_CURSOR_PROVIDER,
|
|
36
41
|
SearchIndexer: () => SearchIndexer,
|
|
37
42
|
ThreadbaseProvider: () => ThreadbaseProvider,
|
|
38
43
|
VALID_SORT_ORDERS: () => VALID_SORT_ORDERS,
|
|
@@ -42,6 +47,8 @@ __export(index_exports, {
|
|
|
42
47
|
applyProjectFilter: () => applyProjectFilter,
|
|
43
48
|
applySinceFilter: () => applySinceFilter,
|
|
44
49
|
applySort: () => applySort,
|
|
50
|
+
canonicalizeProviderList: () => canonicalizeProviderList,
|
|
51
|
+
canonicalizeProviderName: () => canonicalizeProviderName,
|
|
45
52
|
cleanSystemTags: () => cleanSystemTags,
|
|
46
53
|
createJsonlParseState: () => initialConvState,
|
|
47
54
|
createLogger: () => createLogger,
|
|
@@ -52,7 +59,9 @@ __export(index_exports, {
|
|
|
52
59
|
isCodexInjectedContext: () => isCodexInjectedContext,
|
|
53
60
|
loadProfiles: () => loadProfiles,
|
|
54
61
|
parseCodexJsonlLine: () => parseCodexJsonlLine,
|
|
62
|
+
parseCursorJsonlLine: () => parseCursorJsonlLine,
|
|
55
63
|
parseJsonlLine: () => parseJsonlLine,
|
|
64
|
+
providerMatches: () => providerMatches,
|
|
56
65
|
readGitBranch: () => readGitBranch,
|
|
57
66
|
readSidecar: () => readSidecar,
|
|
58
67
|
resetDefaultScanner: () => resetDefaultScanner,
|
|
@@ -62,7 +71,8 @@ __export(index_exports, {
|
|
|
62
71
|
scan: () => scan,
|
|
63
72
|
search: () => search,
|
|
64
73
|
setLogger: () => setLogger,
|
|
65
|
-
sidecarPath: () => sidecarPath
|
|
74
|
+
sidecarPath: () => sidecarPath,
|
|
75
|
+
unwrapCursorUserText: () => unwrapCursorUserText
|
|
66
76
|
});
|
|
67
77
|
module.exports = __toCommonJS(index_exports);
|
|
68
78
|
|
|
@@ -429,6 +439,29 @@ var import_path2 = require("path");
|
|
|
429
439
|
// src/providers/provider.ts
|
|
430
440
|
var CLAUDE_CODE_PROVIDER = "claude-code";
|
|
431
441
|
var CODEX_CLI_PROVIDER = "codex-cli";
|
|
442
|
+
var CURSOR_PROVIDER = "cursor";
|
|
443
|
+
var LEGACY_CURSOR_PROVIDER = "cursor-cli";
|
|
444
|
+
function canonicalizeProviderName(value) {
|
|
445
|
+
if (value === LEGACY_CURSOR_PROVIDER) return CURSOR_PROVIDER;
|
|
446
|
+
if (value === CLAUDE_CODE_PROVIDER || value === CODEX_CLI_PROVIDER || value === CURSOR_PROVIDER) {
|
|
447
|
+
return value;
|
|
448
|
+
}
|
|
449
|
+
return void 0;
|
|
450
|
+
}
|
|
451
|
+
function canonicalizeProviderList(providers) {
|
|
452
|
+
const src = providers ?? [CLAUDE_CODE_PROVIDER];
|
|
453
|
+
const out = [];
|
|
454
|
+
for (const p of src) {
|
|
455
|
+
const n = canonicalizeProviderName(p);
|
|
456
|
+
if (n && !out.includes(n)) out.push(n);
|
|
457
|
+
}
|
|
458
|
+
return out;
|
|
459
|
+
}
|
|
460
|
+
function providerMatches(stored, wanted) {
|
|
461
|
+
const a = canonicalizeProviderName(stored ?? CLAUDE_CODE_PROVIDER) ?? stored;
|
|
462
|
+
const b = canonicalizeProviderName(wanted) ?? wanted;
|
|
463
|
+
return a === b;
|
|
464
|
+
}
|
|
432
465
|
|
|
433
466
|
// src/persistent/metadata-reducer.ts
|
|
434
467
|
function initialReducerState() {
|
|
@@ -1085,12 +1118,88 @@ function parseCodexJsonlLine(line) {
|
|
|
1085
1118
|
function codexEntryToMessage(entry) {
|
|
1086
1119
|
const payload = entry.payload;
|
|
1087
1120
|
if (!payload || typeof payload !== "object") return null;
|
|
1088
|
-
if (entry.type !== "response_item"
|
|
1089
|
-
const
|
|
1090
|
-
|
|
1091
|
-
const
|
|
1092
|
-
|
|
1093
|
-
|
|
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");
|
|
1094
1203
|
}
|
|
1095
1204
|
function reduceCodexEntry(acc, entry, tier) {
|
|
1096
1205
|
const ts = asString(entry.timestamp);
|
|
@@ -1230,6 +1339,7 @@ async function parseCodexConversation(filePath, account) {
|
|
|
1230
1339
|
const message = codexEntryToMessage(entry);
|
|
1231
1340
|
if (!message) continue;
|
|
1232
1341
|
messages.push(message);
|
|
1342
|
+
if (!message.text) continue;
|
|
1233
1343
|
textParts.push(message.text);
|
|
1234
1344
|
if (message.role === "user") lastUserText = message.text;
|
|
1235
1345
|
}
|
|
@@ -1254,9 +1364,429 @@ async function parseCodexConversation(filePath, account) {
|
|
|
1254
1364
|
};
|
|
1255
1365
|
}
|
|
1256
1366
|
|
|
1257
|
-
// src/
|
|
1367
|
+
// src/providers/cursor.ts
|
|
1368
|
+
var import_crypto = require("crypto");
|
|
1258
1369
|
var import_fast_glob2 = __toESM(require("fast-glob"), 1);
|
|
1370
|
+
var import_fs5 = require("fs");
|
|
1259
1371
|
var import_promises3 = require("fs/promises");
|
|
1372
|
+
var import_path7 = require("path");
|
|
1373
|
+
var import_readline3 = require("readline");
|
|
1374
|
+
var TIMESTAMP_RE = /<timestamp>\s*([\s\S]*?)\s*<\/timestamp>/;
|
|
1375
|
+
var USER_QUERY_RE = /<user_query>\s*([\s\S]*?)\s*<\/user_query>/;
|
|
1376
|
+
var SUBAGENT_PATH_RE2 = /[\\/]subagents[\\/]/;
|
|
1377
|
+
var CursorProvider = class {
|
|
1378
|
+
name = CURSOR_PROVIDER;
|
|
1379
|
+
async discover(roots) {
|
|
1380
|
+
const log = getLogger();
|
|
1381
|
+
const results = [];
|
|
1382
|
+
for (const root of roots) {
|
|
1383
|
+
let paths;
|
|
1384
|
+
try {
|
|
1385
|
+
paths = await (0, import_fast_glob2.default)(["**/agent-transcripts/**/*.jsonl"], {
|
|
1386
|
+
cwd: root,
|
|
1387
|
+
absolute: true,
|
|
1388
|
+
dot: false,
|
|
1389
|
+
unique: true
|
|
1390
|
+
});
|
|
1391
|
+
} catch (err) {
|
|
1392
|
+
log.warn({ root, err }, "cursor discovery: glob failed");
|
|
1393
|
+
continue;
|
|
1394
|
+
}
|
|
1395
|
+
for (const filePath of paths) {
|
|
1396
|
+
try {
|
|
1397
|
+
const s = await (0, import_promises3.stat)(filePath);
|
|
1398
|
+
if (s.size > 0) results.push({ filePath: canonicalPath(filePath), account: "cursor" });
|
|
1399
|
+
} catch (err) {
|
|
1400
|
+
log.warn({ filePath, err }, "cursor discovery: stat failed");
|
|
1401
|
+
}
|
|
1402
|
+
}
|
|
1403
|
+
}
|
|
1404
|
+
return results;
|
|
1405
|
+
}
|
|
1406
|
+
canParse(filePath, sample) {
|
|
1407
|
+
const underTranscripts = /[\\/]agent-transcripts[\\/]/.test(filePath);
|
|
1408
|
+
for (const line of sample.split("\n")) {
|
|
1409
|
+
if (!line.trim()) continue;
|
|
1410
|
+
try {
|
|
1411
|
+
const e = JSON.parse(line);
|
|
1412
|
+
if (looksLikeImportedCodexEntry(e) || looksLikeImportedClaudeEntry(e)) {
|
|
1413
|
+
return underTranscripts;
|
|
1414
|
+
}
|
|
1415
|
+
if (looksLikeCursorChatEntry(e)) return true;
|
|
1416
|
+
} catch {
|
|
1417
|
+
}
|
|
1418
|
+
}
|
|
1419
|
+
return false;
|
|
1420
|
+
}
|
|
1421
|
+
createEmptyAccumulator() {
|
|
1422
|
+
return {
|
|
1423
|
+
sessionId: "",
|
|
1424
|
+
latestTimestamp: "",
|
|
1425
|
+
messageCount: 0,
|
|
1426
|
+
lastMessageSender: "user",
|
|
1427
|
+
isSubagent: false,
|
|
1428
|
+
parentSessionUuid: null,
|
|
1429
|
+
subagentId: null,
|
|
1430
|
+
firstUser: null,
|
|
1431
|
+
lastUser: null,
|
|
1432
|
+
lastAssistant: null,
|
|
1433
|
+
isImportedFromClaude: false,
|
|
1434
|
+
isImportedFromCodex: false,
|
|
1435
|
+
toolNames: [],
|
|
1436
|
+
previewParts: [],
|
|
1437
|
+
previewLength: 0,
|
|
1438
|
+
snippetParts: [],
|
|
1439
|
+
snippetLength: 0
|
|
1440
|
+
};
|
|
1441
|
+
}
|
|
1442
|
+
reduceEntry(acc, entry, tier) {
|
|
1443
|
+
reduceCursorEntry(acc, entry, tier);
|
|
1444
|
+
}
|
|
1445
|
+
finalize(acc, filePath, account, tier) {
|
|
1446
|
+
return finalizeCursorMeta(acc, filePath, account, tier);
|
|
1447
|
+
}
|
|
1448
|
+
};
|
|
1449
|
+
function looksLikeCursorChatEntry(entry) {
|
|
1450
|
+
const role = entry.role;
|
|
1451
|
+
if (role !== "user" && role !== "assistant") return false;
|
|
1452
|
+
if (entry.type === "user" || entry.type === "assistant") return false;
|
|
1453
|
+
return true;
|
|
1454
|
+
}
|
|
1455
|
+
function looksLikeImportedClaudeEntry(entry) {
|
|
1456
|
+
return entry.type === "user" || entry.type === "assistant";
|
|
1457
|
+
}
|
|
1458
|
+
function looksLikeImportedCodexEntry(entry) {
|
|
1459
|
+
return entry.type === "session_meta" || entry.type === "response_item" || entry.type === "event_msg";
|
|
1460
|
+
}
|
|
1461
|
+
function asString2(value) {
|
|
1462
|
+
return typeof value === "string" ? value : "";
|
|
1463
|
+
}
|
|
1464
|
+
function provenanceToken(value) {
|
|
1465
|
+
if (typeof value === "string") return value.trim().toLowerCase();
|
|
1466
|
+
if (value && typeof value === "object") {
|
|
1467
|
+
const rec = value;
|
|
1468
|
+
return provenanceToken(
|
|
1469
|
+
rec.importedFrom ?? rec.imported_from ?? rec.sourceProvider ?? rec.source
|
|
1470
|
+
);
|
|
1471
|
+
}
|
|
1472
|
+
return "";
|
|
1473
|
+
}
|
|
1474
|
+
function importedFromClaudeToken(token) {
|
|
1475
|
+
return token === "claude" || token === "claude-code" || token === "claude_code" || token === "anthropic";
|
|
1476
|
+
}
|
|
1477
|
+
function importedFromCodexToken(token) {
|
|
1478
|
+
return token === "codex" || token === "codex-cli" || token === "codex_cli" || token === "openai-codex";
|
|
1479
|
+
}
|
|
1480
|
+
function noteImportProvenance(acc, entry, text) {
|
|
1481
|
+
const token = provenanceToken(
|
|
1482
|
+
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)
|
|
1483
|
+
);
|
|
1484
|
+
if (importedFromClaudeToken(token) || looksLikeImportedClaudeEntry(entry)) {
|
|
1485
|
+
acc.isImportedFromClaude = true;
|
|
1486
|
+
}
|
|
1487
|
+
if (importedFromCodexToken(token) || looksLikeImportedCodexEntry(entry)) {
|
|
1488
|
+
acc.isImportedFromCodex = true;
|
|
1489
|
+
}
|
|
1490
|
+
if (/imported from claude/i.test(text) || /<imported_from_claude>/i.test(text)) {
|
|
1491
|
+
acc.isImportedFromClaude = true;
|
|
1492
|
+
}
|
|
1493
|
+
if (/imported from codex/i.test(text) || /<imported_from_codex>/i.test(text)) {
|
|
1494
|
+
acc.isImportedFromCodex = true;
|
|
1495
|
+
}
|
|
1496
|
+
}
|
|
1497
|
+
function unwrapCursorUserText(text) {
|
|
1498
|
+
const query = text.match(USER_QUERY_RE);
|
|
1499
|
+
const body = query ? query[1] : text.replace(TIMESTAMP_RE, "");
|
|
1500
|
+
return cleanSystemTags(body);
|
|
1501
|
+
}
|
|
1502
|
+
function timestampFromCursorUserText(text) {
|
|
1503
|
+
const match = text.match(TIMESTAMP_RE);
|
|
1504
|
+
if (!match) return "";
|
|
1505
|
+
const parsed = Date.parse(match[1].trim());
|
|
1506
|
+
return Number.isNaN(parsed) ? "" : new Date(parsed).toISOString();
|
|
1507
|
+
}
|
|
1508
|
+
function extractCursorText(content) {
|
|
1509
|
+
if (typeof content === "string") return unwrapCursorUserText(content);
|
|
1510
|
+
if (!Array.isArray(content)) return "";
|
|
1511
|
+
return content.map((item) => {
|
|
1512
|
+
if (typeof item === "string") return unwrapCursorUserText(item);
|
|
1513
|
+
const block = item;
|
|
1514
|
+
if ((block?.type === "text" || block?.type === void 0) && typeof block.text === "string") {
|
|
1515
|
+
return unwrapCursorUserText(block.text);
|
|
1516
|
+
}
|
|
1517
|
+
return "";
|
|
1518
|
+
}).filter(Boolean).join(" ");
|
|
1519
|
+
}
|
|
1520
|
+
function collectCursorToolNames(content, into) {
|
|
1521
|
+
if (!Array.isArray(content)) return;
|
|
1522
|
+
for (const item of content) {
|
|
1523
|
+
const block = item;
|
|
1524
|
+
if (block?.type === "tool_use" && typeof block.name === "string" && block.name) {
|
|
1525
|
+
if (!into.includes(block.name)) into.push(block.name);
|
|
1526
|
+
}
|
|
1527
|
+
}
|
|
1528
|
+
}
|
|
1529
|
+
function firstTimestampHint(content) {
|
|
1530
|
+
if (typeof content === "string") return timestampFromCursorUserText(content);
|
|
1531
|
+
if (!Array.isArray(content)) return "";
|
|
1532
|
+
for (const item of content) {
|
|
1533
|
+
if (typeof item === "string") {
|
|
1534
|
+
const ts = timestampFromCursorUserText(item);
|
|
1535
|
+
if (ts) return ts;
|
|
1536
|
+
} else if (typeof item?.text === "string") {
|
|
1537
|
+
const ts = timestampFromCursorUserText(item.text);
|
|
1538
|
+
if (ts) return ts;
|
|
1539
|
+
}
|
|
1540
|
+
}
|
|
1541
|
+
return "";
|
|
1542
|
+
}
|
|
1543
|
+
function parseCursorJsonlLine(line) {
|
|
1544
|
+
if (!line.trim()) return null;
|
|
1545
|
+
let entry;
|
|
1546
|
+
try {
|
|
1547
|
+
entry = JSON.parse(line);
|
|
1548
|
+
} catch {
|
|
1549
|
+
return null;
|
|
1550
|
+
}
|
|
1551
|
+
return cursorEntryToMessage(entry);
|
|
1552
|
+
}
|
|
1553
|
+
function cursorEntryToMessage(entry) {
|
|
1554
|
+
if (looksLikeCursorChatEntry(entry)) {
|
|
1555
|
+
const role = entry.role;
|
|
1556
|
+
const message = entry.message;
|
|
1557
|
+
const content = message?.content ?? entry.content;
|
|
1558
|
+
return withToolUses(
|
|
1559
|
+
{ role, text: extractCursorText(content), timestamp: firstTimestampHint(content) },
|
|
1560
|
+
content
|
|
1561
|
+
);
|
|
1562
|
+
}
|
|
1563
|
+
if (looksLikeImportedClaudeEntry(entry)) {
|
|
1564
|
+
const message = entry.message;
|
|
1565
|
+
const role = message?.role === "assistant" || entry.type === "assistant" ? "assistant" : "user";
|
|
1566
|
+
const content = message?.content ?? entry.content;
|
|
1567
|
+
return withToolUses(
|
|
1568
|
+
{ role, text: extractCursorText(content), timestamp: asString2(entry.timestamp) },
|
|
1569
|
+
content
|
|
1570
|
+
);
|
|
1571
|
+
}
|
|
1572
|
+
return parseCodexJsonlLine(JSON.stringify(entry));
|
|
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
|
+
}
|
|
1594
|
+
function foldCursorMessage(acc, role, text, timestamp, tier) {
|
|
1595
|
+
if (timestamp && (!acc.latestTimestamp || timestamp > acc.latestTimestamp)) {
|
|
1596
|
+
acc.latestTimestamp = timestamp;
|
|
1597
|
+
}
|
|
1598
|
+
acc.messageCount++;
|
|
1599
|
+
acc.lastMessageSender = role;
|
|
1600
|
+
const snapshot = { text: text.slice(0, 200), timestamp };
|
|
1601
|
+
if (role === "user") {
|
|
1602
|
+
if (!acc.firstUser) acc.firstUser = snapshot;
|
|
1603
|
+
acc.lastUser = snapshot;
|
|
1604
|
+
} else {
|
|
1605
|
+
acc.lastAssistant = snapshot;
|
|
1606
|
+
}
|
|
1607
|
+
if (acc.previewLength < tier.previewMax) {
|
|
1608
|
+
acc.previewParts.push(text);
|
|
1609
|
+
acc.previewLength += text.length;
|
|
1610
|
+
}
|
|
1611
|
+
if (acc.snippetLength < tier.snippetMax) {
|
|
1612
|
+
const remaining = tier.snippetMax - acc.snippetLength;
|
|
1613
|
+
const chunk = text.length > remaining ? text.slice(0, remaining) : text;
|
|
1614
|
+
acc.snippetParts.push(chunk);
|
|
1615
|
+
acc.snippetLength += chunk.length;
|
|
1616
|
+
}
|
|
1617
|
+
}
|
|
1618
|
+
function reduceCursorEntry(acc, entry, tier) {
|
|
1619
|
+
const message = entry.message;
|
|
1620
|
+
const content = message?.content ?? entry.content;
|
|
1621
|
+
const textHint = extractCursorText(content);
|
|
1622
|
+
noteImportProvenance(acc, entry, textHint);
|
|
1623
|
+
if (looksLikeCursorChatEntry(entry)) {
|
|
1624
|
+
collectCursorToolNames(content, acc.toolNames);
|
|
1625
|
+
const text = textHint;
|
|
1626
|
+
if (!text) return;
|
|
1627
|
+
foldCursorMessage(acc, entry.role, text, firstTimestampHint(content), tier);
|
|
1628
|
+
return;
|
|
1629
|
+
}
|
|
1630
|
+
if (looksLikeImportedClaudeEntry(entry)) {
|
|
1631
|
+
collectCursorToolNames(content, acc.toolNames);
|
|
1632
|
+
const msg = cursorEntryToMessage(entry);
|
|
1633
|
+
if (!msg?.text) return;
|
|
1634
|
+
foldCursorMessage(acc, msg.role, msg.text, msg.timestamp, tier);
|
|
1635
|
+
return;
|
|
1636
|
+
}
|
|
1637
|
+
if (looksLikeImportedCodexEntry(entry)) {
|
|
1638
|
+
const msg = parseCodexJsonlLine(JSON.stringify(entry));
|
|
1639
|
+
if (!msg?.text) return;
|
|
1640
|
+
foldCursorMessage(acc, msg.role, msg.text, msg.timestamp, tier);
|
|
1641
|
+
}
|
|
1642
|
+
}
|
|
1643
|
+
function finalizeCursorMeta(acc, filePath, account, tier) {
|
|
1644
|
+
if (acc.messageCount === 0) return null;
|
|
1645
|
+
const sessionId = (0, import_path7.basename)(filePath, ".jsonl");
|
|
1646
|
+
const isSubagent = SUBAGENT_PATH_RE2.test(filePath);
|
|
1647
|
+
const parent = isSubagent ? parentFromSubagentPath(filePath) : null;
|
|
1648
|
+
const { projectPath, projectName } = projectFromCursorPath(filePath);
|
|
1649
|
+
const timestamp = acc.latestTimestamp || fileMtimeIso(filePath);
|
|
1650
|
+
const kind = acc.lastAssistant === null && acc.toolNames.length > 0 ? "task" : "conversation";
|
|
1651
|
+
return {
|
|
1652
|
+
id: filePath,
|
|
1653
|
+
filePath,
|
|
1654
|
+
provider: CURSOR_PROVIDER,
|
|
1655
|
+
kind,
|
|
1656
|
+
externalSessionId: sessionId,
|
|
1657
|
+
sessionId,
|
|
1658
|
+
sessionName: deriveSessionNameFromFirstMessage(acc.firstUser),
|
|
1659
|
+
projectPath,
|
|
1660
|
+
projectName,
|
|
1661
|
+
account,
|
|
1662
|
+
timestamp,
|
|
1663
|
+
messageCount: acc.messageCount,
|
|
1664
|
+
lastMessageSender: acc.lastMessageSender,
|
|
1665
|
+
preview: acc.previewParts.join(" ").slice(0, tier.previewMax),
|
|
1666
|
+
contentSnippet: acc.snippetParts.join(" "),
|
|
1667
|
+
gitBranch: null,
|
|
1668
|
+
model: null,
|
|
1669
|
+
isSubagent,
|
|
1670
|
+
parentSessionId: parent?.parentFilePath ?? null,
|
|
1671
|
+
subagentId: isSubagent ? sessionId : void 0,
|
|
1672
|
+
parentSessionUuid: parent?.parentSessionUuid ?? void 0,
|
|
1673
|
+
isTeammate: false,
|
|
1674
|
+
teamName: null,
|
|
1675
|
+
toolNames: acc.toolNames,
|
|
1676
|
+
firstMessage: acc.firstUser,
|
|
1677
|
+
lastMessage: acc.lastAssistant ?? acc.lastUser,
|
|
1678
|
+
lastPrompt: acc.lastUser?.text || void 0,
|
|
1679
|
+
...acc.isImportedFromClaude ? { isImportedFromClaude: true } : {},
|
|
1680
|
+
...acc.isImportedFromCodex ? { isImportedFromCodex: true } : {}
|
|
1681
|
+
};
|
|
1682
|
+
}
|
|
1683
|
+
function parentFromSubagentPath(filePath) {
|
|
1684
|
+
const subagentsDir = (0, import_path7.dirname)(filePath);
|
|
1685
|
+
const parentDir = (0, import_path7.dirname)(subagentsDir);
|
|
1686
|
+
const parentSessionUuid = (0, import_path7.basename)(parentDir);
|
|
1687
|
+
if (!parentSessionUuid) return null;
|
|
1688
|
+
return {
|
|
1689
|
+
parentSessionUuid,
|
|
1690
|
+
parentFilePath: canonicalPath((0, import_path7.join)(parentDir, `${parentSessionUuid}.jsonl`))
|
|
1691
|
+
};
|
|
1692
|
+
}
|
|
1693
|
+
function projectFromCursorPath(filePath) {
|
|
1694
|
+
const parts = filePath.split(/[/\\]/);
|
|
1695
|
+
const idx = parts.lastIndexOf("agent-transcripts");
|
|
1696
|
+
const cursorProjectDir = idx > 0 ? parts.slice(0, idx).join(import_path7.sep) : (0, import_path7.dirname)((0, import_path7.dirname)(filePath));
|
|
1697
|
+
const slug = (0, import_path7.basename)(cursorProjectDir);
|
|
1698
|
+
const decoded = decodeCursorProjectSlug(slug);
|
|
1699
|
+
const projectPath = decoded ?? cursorProjectDir;
|
|
1700
|
+
return { projectPath, projectName: getShortProjectName4(projectPath) || slug };
|
|
1701
|
+
}
|
|
1702
|
+
function decodeCursorProjectSlug(slug) {
|
|
1703
|
+
if (!slug) return null;
|
|
1704
|
+
const segments = slug.split("-");
|
|
1705
|
+
if (segments.length === 0) return null;
|
|
1706
|
+
const rooted = slug.startsWith("Users-") || slug.startsWith("home-") || /^[A-Za-z]-/.test(slug);
|
|
1707
|
+
let acc = rooted ? import_path7.sep : "";
|
|
1708
|
+
let i = 0;
|
|
1709
|
+
if (rooted && segments[0] === "Users") {
|
|
1710
|
+
const users = `${import_path7.sep}Users`;
|
|
1711
|
+
if (!(0, import_fs5.existsSync)(users)) return null;
|
|
1712
|
+
acc = users;
|
|
1713
|
+
i = 1;
|
|
1714
|
+
}
|
|
1715
|
+
while (i < segments.length) {
|
|
1716
|
+
let found = null;
|
|
1717
|
+
let next = i + 1;
|
|
1718
|
+
for (let j = segments.length; j > i; j--) {
|
|
1719
|
+
const candidate = (0, import_path7.join)(acc, segments.slice(i, j).join("-"));
|
|
1720
|
+
try {
|
|
1721
|
+
if ((0, import_fs5.existsSync)(candidate) && (0, import_fs5.statSync)(candidate).isDirectory()) {
|
|
1722
|
+
found = candidate;
|
|
1723
|
+
next = j;
|
|
1724
|
+
break;
|
|
1725
|
+
}
|
|
1726
|
+
} catch {
|
|
1727
|
+
}
|
|
1728
|
+
}
|
|
1729
|
+
if (!found) return null;
|
|
1730
|
+
acc = found;
|
|
1731
|
+
i = next;
|
|
1732
|
+
}
|
|
1733
|
+
return acc;
|
|
1734
|
+
}
|
|
1735
|
+
function getShortProjectName4(fullPath) {
|
|
1736
|
+
return fullPath.split(/[/\\]/).filter(Boolean).slice(-3).join("/");
|
|
1737
|
+
}
|
|
1738
|
+
function fileMtimeIso(filePath) {
|
|
1739
|
+
try {
|
|
1740
|
+
return new Date((0, import_fs5.statSync)(filePath).mtimeMs).toISOString();
|
|
1741
|
+
} catch {
|
|
1742
|
+
return (/* @__PURE__ */ new Date()).toISOString();
|
|
1743
|
+
}
|
|
1744
|
+
}
|
|
1745
|
+
async function parseCursorConversation(filePath, account) {
|
|
1746
|
+
const log = getLogger();
|
|
1747
|
+
const messages = [];
|
|
1748
|
+
const textParts = [];
|
|
1749
|
+
let latestTimestamp = "";
|
|
1750
|
+
let lastUserText = "";
|
|
1751
|
+
const rl = (0, import_readline3.createInterface)({ input: (0, import_fs5.createReadStream)(filePath), crlfDelay: Infinity });
|
|
1752
|
+
try {
|
|
1753
|
+
for await (const line of rl) {
|
|
1754
|
+
const message = parseCursorJsonlLine(line);
|
|
1755
|
+
if (!message) continue;
|
|
1756
|
+
if (message.timestamp && (!latestTimestamp || message.timestamp > latestTimestamp)) {
|
|
1757
|
+
latestTimestamp = message.timestamp;
|
|
1758
|
+
}
|
|
1759
|
+
messages.push(message);
|
|
1760
|
+
if (!message.text) continue;
|
|
1761
|
+
textParts.push(message.text);
|
|
1762
|
+
if (message.role === "user") lastUserText = message.text;
|
|
1763
|
+
}
|
|
1764
|
+
} catch (err) {
|
|
1765
|
+
log.warn({ filePath, err }, "parseCursorConversation: read failed");
|
|
1766
|
+
return null;
|
|
1767
|
+
}
|
|
1768
|
+
if (messages.length === 0) return null;
|
|
1769
|
+
const { projectPath, projectName } = projectFromCursorPath(filePath);
|
|
1770
|
+
const sessionId = (0, import_path7.basename)(filePath, ".jsonl");
|
|
1771
|
+
return {
|
|
1772
|
+
id: filePath,
|
|
1773
|
+
filePath,
|
|
1774
|
+
projectPath,
|
|
1775
|
+
projectName,
|
|
1776
|
+
sessionId,
|
|
1777
|
+
sessionName: "",
|
|
1778
|
+
messages,
|
|
1779
|
+
fullText: textParts.join(" "),
|
|
1780
|
+
timestamp: latestTimestamp || fileMtimeIso(filePath),
|
|
1781
|
+
messageCount: messages.length,
|
|
1782
|
+
account,
|
|
1783
|
+
lastPrompt: lastUserText || void 0
|
|
1784
|
+
};
|
|
1785
|
+
}
|
|
1786
|
+
|
|
1787
|
+
// src/discovery.ts
|
|
1788
|
+
var import_fast_glob3 = __toESM(require("fast-glob"), 1);
|
|
1789
|
+
var import_promises4 = require("fs/promises");
|
|
1260
1790
|
var EXCLUDED_SEGMENTS = ["/memory/", "/tool-results/"];
|
|
1261
1791
|
var STAT_CONCURRENCY = 32;
|
|
1262
1792
|
async function discoverJsonlFiles(dirs, onProgress) {
|
|
@@ -1265,7 +1795,7 @@ async function discoverJsonlFiles(dirs, onProgress) {
|
|
|
1265
1795
|
for (const { projectsDir, account } of dirs) {
|
|
1266
1796
|
let filePaths;
|
|
1267
1797
|
try {
|
|
1268
|
-
filePaths = await (0,
|
|
1798
|
+
filePaths = await (0, import_fast_glob3.default)("**/*.jsonl", {
|
|
1269
1799
|
cwd: projectsDir,
|
|
1270
1800
|
absolute: true,
|
|
1271
1801
|
dot: false
|
|
@@ -1283,7 +1813,7 @@ async function discoverJsonlFiles(dirs, onProgress) {
|
|
|
1283
1813
|
const statted = await Promise.all(
|
|
1284
1814
|
chunk.map(async (filePath) => {
|
|
1285
1815
|
try {
|
|
1286
|
-
const s = await (0,
|
|
1816
|
+
const s = await (0, import_promises4.stat)(filePath);
|
|
1287
1817
|
return { filePath, size: s.size };
|
|
1288
1818
|
} catch (err) {
|
|
1289
1819
|
log.warn({ filePath, err }, "discovery: stat failed");
|
|
@@ -1358,9 +1888,9 @@ var ThreadbaseProvider = class {
|
|
|
1358
1888
|
|
|
1359
1889
|
// src/scanner.ts
|
|
1360
1890
|
var import_events = require("events");
|
|
1361
|
-
var
|
|
1891
|
+
var import_fs12 = require("fs");
|
|
1362
1892
|
var import_os2 = require("os");
|
|
1363
|
-
var
|
|
1893
|
+
var import_path12 = require("path");
|
|
1364
1894
|
|
|
1365
1895
|
// src/cache.ts
|
|
1366
1896
|
var LRUCache = class {
|
|
@@ -1399,18 +1929,18 @@ var LRUCache = class {
|
|
|
1399
1929
|
};
|
|
1400
1930
|
|
|
1401
1931
|
// src/persistent/conversation-stream.ts
|
|
1402
|
-
var
|
|
1932
|
+
var import_path8 = require("path");
|
|
1403
1933
|
|
|
1404
1934
|
// src/persistent/paged-reader.ts
|
|
1405
|
-
var
|
|
1406
|
-
var
|
|
1935
|
+
var import_fs7 = require("fs");
|
|
1936
|
+
var import_promises6 = require("timers/promises");
|
|
1407
1937
|
|
|
1408
1938
|
// src/persistent/jsonl-tail-reader.ts
|
|
1409
|
-
var
|
|
1410
|
-
var
|
|
1939
|
+
var import_fs6 = require("fs");
|
|
1940
|
+
var import_promises5 = require("timers/promises");
|
|
1411
1941
|
var YIELD_EVERY_LINES = 500;
|
|
1412
1942
|
async function tailReduce(filePath, startOffset, startLine, state, tier, onEntry) {
|
|
1413
|
-
const stream = (0,
|
|
1943
|
+
const stream = (0, import_fs6.createReadStream)(filePath, { start: startOffset, encoding: "utf8" });
|
|
1414
1944
|
let buffer = "";
|
|
1415
1945
|
let offset = startOffset;
|
|
1416
1946
|
let line = startLine;
|
|
@@ -1437,7 +1967,7 @@ async function tailReduce(filePath, startOffset, startLine, state, tier, onEntry
|
|
|
1437
1967
|
line++;
|
|
1438
1968
|
if (++sinceYield >= YIELD_EVERY_LINES) {
|
|
1439
1969
|
sinceYield = 0;
|
|
1440
|
-
await (0,
|
|
1970
|
+
await (0, import_promises5.setImmediate)();
|
|
1441
1971
|
}
|
|
1442
1972
|
}
|
|
1443
1973
|
}
|
|
@@ -1447,7 +1977,7 @@ async function tailReduce(filePath, startOffset, startLine, state, tier, onEntry
|
|
|
1447
1977
|
// src/persistent/paged-reader.ts
|
|
1448
1978
|
var CHECKPOINT_INTERVAL = 500;
|
|
1449
1979
|
async function streamMessages(filePath, startOffset, startLine, state, onMessage, onEntry) {
|
|
1450
|
-
const stream = (0,
|
|
1980
|
+
const stream = (0, import_fs7.createReadStream)(filePath, { start: startOffset, encoding: "utf8" });
|
|
1451
1981
|
let buffer = "";
|
|
1452
1982
|
let offset = startOffset;
|
|
1453
1983
|
let line = startLine;
|
|
@@ -1463,7 +1993,7 @@ async function streamMessages(filePath, startOffset, startLine, state, onMessage
|
|
|
1463
1993
|
line += 1;
|
|
1464
1994
|
if (++sinceYield >= YIELD_EVERY_LINES) {
|
|
1465
1995
|
sinceYield = 0;
|
|
1466
|
-
await (0,
|
|
1996
|
+
await (0, import_promises6.setImmediate)();
|
|
1467
1997
|
}
|
|
1468
1998
|
if (text.length === 0) continue;
|
|
1469
1999
|
let entry;
|
|
@@ -1559,7 +2089,7 @@ function assemble(filePath, account, messages, fullText, turnDurations, state) {
|
|
|
1559
2089
|
filePath,
|
|
1560
2090
|
projectPath: state.cwd,
|
|
1561
2091
|
projectName: getShortProjectName2(state.cwd),
|
|
1562
|
-
sessionId: state.sessionId || (0,
|
|
2092
|
+
sessionId: state.sessionId || (0, import_path8.basename)(filePath, ".jsonl"),
|
|
1563
2093
|
sessionName: state.sessionName || deriveSessionNameFromFirstMessage(messages.find((m) => m.role === "user" && m.text) ?? null),
|
|
1564
2094
|
messages,
|
|
1565
2095
|
fullText,
|
|
@@ -1603,71 +2133,71 @@ async function extendConversation(previous, resume, filePath, account) {
|
|
|
1603
2133
|
}
|
|
1604
2134
|
|
|
1605
2135
|
// src/persistent/cursor.ts
|
|
1606
|
-
var
|
|
1607
|
-
var
|
|
2136
|
+
var import_crypto2 = require("crypto");
|
|
2137
|
+
var import_fs8 = require("fs");
|
|
1608
2138
|
var FP_BYTES = 4096;
|
|
1609
2139
|
function fingerprint(filePath, size) {
|
|
1610
|
-
const hash = (0,
|
|
2140
|
+
const hash = (0, import_crypto2.createHash)("sha1");
|
|
1611
2141
|
hash.update(String(size));
|
|
1612
|
-
const fd = (0,
|
|
2142
|
+
const fd = (0, import_fs8.openSync)(filePath, "r");
|
|
1613
2143
|
try {
|
|
1614
2144
|
const head = Buffer.alloc(Math.min(FP_BYTES, size));
|
|
1615
2145
|
if (head.length > 0) {
|
|
1616
|
-
(0,
|
|
2146
|
+
(0, import_fs8.readSync)(fd, head, 0, head.length, 0);
|
|
1617
2147
|
hash.update(head);
|
|
1618
2148
|
}
|
|
1619
2149
|
if (size > FP_BYTES) {
|
|
1620
2150
|
const tailLen = Math.min(FP_BYTES, size);
|
|
1621
2151
|
const tail = Buffer.alloc(tailLen);
|
|
1622
|
-
(0,
|
|
2152
|
+
(0, import_fs8.readSync)(fd, tail, 0, tailLen, size - tailLen);
|
|
1623
2153
|
hash.update(tail);
|
|
1624
2154
|
}
|
|
1625
2155
|
} finally {
|
|
1626
|
-
(0,
|
|
2156
|
+
(0, import_fs8.closeSync)(fd);
|
|
1627
2157
|
}
|
|
1628
2158
|
return hash.digest("hex");
|
|
1629
2159
|
}
|
|
1630
2160
|
function classify(filePath, existing) {
|
|
1631
|
-
let
|
|
2161
|
+
let stat5;
|
|
1632
2162
|
try {
|
|
1633
|
-
const s = (0,
|
|
1634
|
-
|
|
2163
|
+
const s = (0, import_fs8.statSync)(filePath);
|
|
2164
|
+
stat5 = { size: s.size, mtimeMs: s.mtimeMs };
|
|
1635
2165
|
} catch {
|
|
1636
2166
|
return { change: "vanished" };
|
|
1637
2167
|
}
|
|
1638
2168
|
if (!existing || existing.status !== "active" || existing.last_indexed_offset === 0) {
|
|
1639
|
-
return { change: "reindex", stat:
|
|
2169
|
+
return { change: "reindex", stat: stat5 };
|
|
1640
2170
|
}
|
|
1641
|
-
if (
|
|
1642
|
-
return { change: "reindex", stat:
|
|
2171
|
+
if (stat5.size < existing.last_indexed_offset) {
|
|
2172
|
+
return { change: "reindex", stat: stat5 };
|
|
1643
2173
|
}
|
|
1644
|
-
if (
|
|
1645
|
-
return { change: "unchanged", stat:
|
|
2174
|
+
if (stat5.size === existing.size_bytes && stat5.mtimeMs === existing.mtime_ms) {
|
|
2175
|
+
return { change: "unchanged", stat: stat5 };
|
|
1646
2176
|
}
|
|
1647
|
-
if (
|
|
1648
|
-
const fp = fingerprint(filePath,
|
|
2177
|
+
if (stat5.size === existing.last_indexed_offset) {
|
|
2178
|
+
const fp = fingerprint(filePath, stat5.size);
|
|
1649
2179
|
if (existing.content_fingerprint && fp !== existing.content_fingerprint) {
|
|
1650
|
-
return { change: "reindex", stat:
|
|
2180
|
+
return { change: "reindex", stat: stat5 };
|
|
1651
2181
|
}
|
|
1652
|
-
return { change: "unchanged", stat:
|
|
2182
|
+
return { change: "unchanged", stat: stat5 };
|
|
1653
2183
|
}
|
|
1654
2184
|
if (existing.content_fingerprint && existing.size_bytes === existing.last_indexed_offset && fingerprint(filePath, existing.last_indexed_offset) === existing.content_fingerprint) {
|
|
1655
|
-
return { change: "appended", stat:
|
|
2185
|
+
return { change: "appended", stat: stat5 };
|
|
1656
2186
|
}
|
|
1657
|
-
return { change: "reindex", stat:
|
|
2187
|
+
return { change: "reindex", stat: stat5 };
|
|
1658
2188
|
}
|
|
1659
2189
|
|
|
1660
2190
|
// src/persistent/index-engine.ts
|
|
1661
|
-
var
|
|
2191
|
+
var import_fs11 = require("fs");
|
|
1662
2192
|
|
|
1663
2193
|
// src/providers/parse.ts
|
|
1664
|
-
var
|
|
1665
|
-
var
|
|
2194
|
+
var import_fs9 = require("fs");
|
|
2195
|
+
var import_readline4 = require("readline");
|
|
1666
2196
|
async function parseMetaWithProvider(provider, filePath, account, tier, onEntry) {
|
|
1667
2197
|
const log = getLogger();
|
|
1668
2198
|
const acc = provider.createEmptyAccumulator();
|
|
1669
|
-
const rl = (0,
|
|
1670
|
-
input: (0,
|
|
2199
|
+
const rl = (0, import_readline4.createInterface)({
|
|
2200
|
+
input: (0, import_fs9.createReadStream)(filePath),
|
|
1671
2201
|
crlfDelay: Infinity
|
|
1672
2202
|
});
|
|
1673
2203
|
try {
|
|
@@ -1737,8 +2267,35 @@ function extractSearchDelta(entry) {
|
|
|
1737
2267
|
if (entry.type === "response_item" || entry.type === "session_meta") {
|
|
1738
2268
|
return extractCodexDelta(entry);
|
|
1739
2269
|
}
|
|
2270
|
+
if (looksLikeCursorChatEntry(entry)) {
|
|
2271
|
+
return extractCursorDelta(entry);
|
|
2272
|
+
}
|
|
1740
2273
|
return extractClaudeDelta(entry);
|
|
1741
2274
|
}
|
|
2275
|
+
function extractCursorDelta(entry) {
|
|
2276
|
+
const msg = entry.message;
|
|
2277
|
+
const content = msg?.content ?? entry.content;
|
|
2278
|
+
return {
|
|
2279
|
+
text: extractCursorSearchText(content),
|
|
2280
|
+
thinking: "",
|
|
2281
|
+
tools: extractClaudeToolContent(content)
|
|
2282
|
+
};
|
|
2283
|
+
}
|
|
2284
|
+
function extractCursorSearchText(content) {
|
|
2285
|
+
if (typeof content === "string") return unwrapCursorUserText(content);
|
|
2286
|
+
if (!Array.isArray(content)) return "";
|
|
2287
|
+
const parts = [];
|
|
2288
|
+
for (const item of content) {
|
|
2289
|
+
if (typeof item === "string") {
|
|
2290
|
+
const cleaned = unwrapCursorUserText(item);
|
|
2291
|
+
if (cleaned) parts.push(cleaned);
|
|
2292
|
+
} else if ((item?.type === "text" || item?.type === void 0) && typeof item?.text === "string") {
|
|
2293
|
+
const cleaned = unwrapCursorUserText(item.text);
|
|
2294
|
+
if (cleaned) parts.push(cleaned);
|
|
2295
|
+
}
|
|
2296
|
+
}
|
|
2297
|
+
return parts.join(SEP);
|
|
2298
|
+
}
|
|
1742
2299
|
function extractClaudeDelta(entry) {
|
|
1743
2300
|
const type = entry.type;
|
|
1744
2301
|
if (type !== "user" && type !== "assistant") return emptySearchDocument();
|
|
@@ -1855,11 +2412,11 @@ function resolveTier(tierName, customTiers) {
|
|
|
1855
2412
|
|
|
1856
2413
|
// src/persistent/db.ts
|
|
1857
2414
|
var import_better_sqlite3 = __toESM(require("better-sqlite3"), 1);
|
|
1858
|
-
var
|
|
1859
|
-
var
|
|
2415
|
+
var import_fs10 = require("fs");
|
|
2416
|
+
var import_path9 = require("path");
|
|
1860
2417
|
|
|
1861
2418
|
// src/persistent/schema.ts
|
|
1862
|
-
var SCHEMA_VERSION =
|
|
2419
|
+
var SCHEMA_VERSION = 9;
|
|
1863
2420
|
var SCHEMA_SQL = `
|
|
1864
2421
|
CREATE TABLE IF NOT EXISTS conversation_files (
|
|
1865
2422
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
@@ -1944,6 +2501,10 @@ CREATE TABLE IF NOT EXISTS conversations (
|
|
|
1944
2501
|
tool_names_json TEXT,
|
|
1945
2502
|
last_prompt TEXT,
|
|
1946
2503
|
|
|
2504
|
+
is_imported_from_claude INTEGER NOT NULL DEFAULT 0,
|
|
2505
|
+
is_imported_from_codex INTEGER NOT NULL DEFAULT 0,
|
|
2506
|
+
is_imported_from_cursor INTEGER NOT NULL DEFAULT 0,
|
|
2507
|
+
|
|
1947
2508
|
status TEXT NOT NULL DEFAULT 'active',
|
|
1948
2509
|
|
|
1949
2510
|
created_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
@@ -2109,6 +2670,45 @@ function runMigrations(db) {
|
|
|
2109
2670
|
db.exec(`UPDATE conversation_files SET ${assignments.join(", ")}`);
|
|
2110
2671
|
}
|
|
2111
2672
|
}
|
|
2673
|
+
if (current >= 1 && current < 8 && tableExists(db, "conversations")) {
|
|
2674
|
+
for (const [col, ddl] of [
|
|
2675
|
+
[
|
|
2676
|
+
"is_imported_from_claude",
|
|
2677
|
+
"ALTER TABLE conversations ADD COLUMN is_imported_from_claude INTEGER NOT NULL DEFAULT 0"
|
|
2678
|
+
],
|
|
2679
|
+
[
|
|
2680
|
+
"is_imported_from_codex",
|
|
2681
|
+
"ALTER TABLE conversations ADD COLUMN is_imported_from_codex INTEGER NOT NULL DEFAULT 0"
|
|
2682
|
+
],
|
|
2683
|
+
[
|
|
2684
|
+
"is_imported_from_cursor",
|
|
2685
|
+
"ALTER TABLE conversations ADD COLUMN is_imported_from_cursor INTEGER NOT NULL DEFAULT 0"
|
|
2686
|
+
]
|
|
2687
|
+
]) {
|
|
2688
|
+
if (!hasColumn(db, "conversations", col)) db.exec(ddl);
|
|
2689
|
+
}
|
|
2690
|
+
if (tableExists(db, "conversation_files")) {
|
|
2691
|
+
const assignments = [];
|
|
2692
|
+
if (hasColumn(db, "conversation_files", "last_indexed_offset")) {
|
|
2693
|
+
assignments.push("last_indexed_offset = 0");
|
|
2694
|
+
}
|
|
2695
|
+
if (hasColumn(db, "conversation_files", "last_indexed_line")) {
|
|
2696
|
+
assignments.push("last_indexed_line = 0");
|
|
2697
|
+
}
|
|
2698
|
+
if (hasColumn(db, "conversation_files", "reducer_state")) {
|
|
2699
|
+
assignments.push("reducer_state = NULL");
|
|
2700
|
+
}
|
|
2701
|
+
if (assignments.length > 0) {
|
|
2702
|
+
db.exec(
|
|
2703
|
+
`UPDATE conversation_files SET ${assignments.join(", ")}
|
|
2704
|
+
WHERE id IN (SELECT file_id FROM conversations WHERE provider IN ('cursor', 'cursor-cli'))`
|
|
2705
|
+
);
|
|
2706
|
+
}
|
|
2707
|
+
}
|
|
2708
|
+
}
|
|
2709
|
+
if (current >= 1 && current < 9 && tableExists(db, "conversations")) {
|
|
2710
|
+
db.exec(`UPDATE conversations SET provider = 'cursor' WHERE provider = 'cursor-cli'`);
|
|
2711
|
+
}
|
|
2112
2712
|
db.exec(SCHEMA_SQL);
|
|
2113
2713
|
db.pragma(`user_version = ${SCHEMA_VERSION}`);
|
|
2114
2714
|
}
|
|
@@ -2123,7 +2723,7 @@ function hasColumn(db, table, column) {
|
|
|
2123
2723
|
// src/persistent/db.ts
|
|
2124
2724
|
function openDatabase(dbPath) {
|
|
2125
2725
|
if (dbPath !== ":memory:") {
|
|
2126
|
-
(0,
|
|
2726
|
+
(0, import_fs10.mkdirSync)((0, import_path9.dirname)(dbPath), { recursive: true });
|
|
2127
2727
|
}
|
|
2128
2728
|
let db;
|
|
2129
2729
|
try {
|
|
@@ -2167,8 +2767,8 @@ function nativeBindingError(err, dbPath) {
|
|
|
2167
2767
|
}
|
|
2168
2768
|
|
|
2169
2769
|
// src/persistent/dir-watermark.ts
|
|
2170
|
-
var
|
|
2171
|
-
var
|
|
2770
|
+
var import_promises7 = require("fs/promises");
|
|
2771
|
+
var import_path10 = require("path");
|
|
2172
2772
|
var FULL_RECONCILE_EVERY_N_SCANS = 20;
|
|
2173
2773
|
async function discoverJsonlFilesGated(dirs, files, scannedDirs, options = {}) {
|
|
2174
2774
|
const log = getLogger();
|
|
@@ -2184,7 +2784,7 @@ async function discoverJsonlFilesGated(dirs, files, scannedDirs, options = {}) {
|
|
|
2184
2784
|
for (const projectDir of resolved.entries) {
|
|
2185
2785
|
let dirStat;
|
|
2186
2786
|
try {
|
|
2187
|
-
dirStat = await (0,
|
|
2787
|
+
dirStat = await (0, import_promises7.stat)(projectDir);
|
|
2188
2788
|
} catch {
|
|
2189
2789
|
scannedDirs.remove(projectDir);
|
|
2190
2790
|
continue;
|
|
@@ -2222,7 +2822,7 @@ async function discoverJsonlFilesGated(dirs, files, scannedDirs, options = {}) {
|
|
|
2222
2822
|
async function resolveProjectDirs(projectsDir, scannedDirs) {
|
|
2223
2823
|
let rootStat;
|
|
2224
2824
|
try {
|
|
2225
|
-
rootStat = await (0,
|
|
2825
|
+
rootStat = await (0, import_promises7.stat)(projectsDir);
|
|
2226
2826
|
} catch {
|
|
2227
2827
|
return null;
|
|
2228
2828
|
}
|
|
@@ -2232,17 +2832,17 @@ async function resolveProjectDirs(projectsDir, scannedDirs) {
|
|
|
2232
2832
|
}
|
|
2233
2833
|
let entries;
|
|
2234
2834
|
try {
|
|
2235
|
-
entries = (await (0,
|
|
2835
|
+
entries = (await (0, import_promises7.readdir)(projectsDir, { withFileTypes: true })).filter((e) => e.isDirectory()).map((e) => joinPath(projectsDir, e.name));
|
|
2236
2836
|
} catch {
|
|
2237
2837
|
return null;
|
|
2238
2838
|
}
|
|
2239
2839
|
return { entries, commitRoot: { mtimeMs: rootStat.mtimeMs } };
|
|
2240
2840
|
}
|
|
2241
2841
|
function dirnameOf(filePath) {
|
|
2242
|
-
return (0,
|
|
2842
|
+
return (0, import_path10.dirname)(filePath);
|
|
2243
2843
|
}
|
|
2244
2844
|
function joinPath(dir, name) {
|
|
2245
|
-
return (0,
|
|
2845
|
+
return (0, import_path10.join)(dir, name);
|
|
2246
2846
|
}
|
|
2247
2847
|
|
|
2248
2848
|
// src/persistent/repositories/checkpoints.repo.ts
|
|
@@ -2322,7 +2922,7 @@ function toCheckpoint(row) {
|
|
|
2322
2922
|
}
|
|
2323
2923
|
|
|
2324
2924
|
// src/persistent/repositories/conversation-files.repo.ts
|
|
2325
|
-
var
|
|
2925
|
+
var import_path11 = require("path");
|
|
2326
2926
|
var ConversationFilesRepo = class {
|
|
2327
2927
|
constructor(db) {
|
|
2328
2928
|
this.db = db;
|
|
@@ -2345,7 +2945,7 @@ var ConversationFilesRepo = class {
|
|
|
2345
2945
|
const info = this.db.prepare(
|
|
2346
2946
|
`INSERT INTO conversation_files (absolute_path, parent_dir, file_name, account)
|
|
2347
2947
|
VALUES (?, ?, ?, ?)`
|
|
2348
|
-
).run(canonical, (0,
|
|
2948
|
+
).run(canonical, (0, import_path11.dirname)(canonical), (0, import_path11.basename)(canonical), account);
|
|
2349
2949
|
return Number(info.lastInsertRowid);
|
|
2350
2950
|
}
|
|
2351
2951
|
// Advance the cursor + persisted reducer state after a successful index pass.
|
|
@@ -2440,7 +3040,10 @@ function rowToMeta(row) {
|
|
|
2440
3040
|
toolNames: row.tool_names_json ? JSON.parse(row.tool_names_json) : [],
|
|
2441
3041
|
firstMessage: row.first_sent_text ? { text: row.first_sent_text, timestamp: row.first_sent_at ?? "" } : null,
|
|
2442
3042
|
lastMessage: row.last_sent_text ? { text: row.last_sent_text, timestamp: row.last_sent_at ?? "" } : null,
|
|
2443
|
-
lastPrompt: row.last_prompt ?? void 0
|
|
3043
|
+
lastPrompt: row.last_prompt ?? void 0,
|
|
3044
|
+
...row.is_imported_from_claude === 1 ? { isImportedFromClaude: true } : {},
|
|
3045
|
+
...row.is_imported_from_codex === 1 ? { isImportedFromCodex: true } : {},
|
|
3046
|
+
...row.is_imported_from_cursor === 1 ? { isImportedFromCursor: true } : {}
|
|
2444
3047
|
};
|
|
2445
3048
|
}
|
|
2446
3049
|
var ConversationsRepo = class {
|
|
@@ -2460,7 +3063,8 @@ var ConversationsRepo = class {
|
|
|
2460
3063
|
timestamp, index_seq, first_sent_at, first_sent_text, last_sent_at, last_sent_text,
|
|
2461
3064
|
model, is_subagent, parent_session_id, subagent_id, parent_session_uuid,
|
|
2462
3065
|
is_teammate, team_name, tool_names_json,
|
|
2463
|
-
last_prompt,
|
|
3066
|
+
last_prompt, is_imported_from_claude, is_imported_from_codex,
|
|
3067
|
+
is_imported_from_cursor, status, updated_at
|
|
2464
3068
|
) VALUES (
|
|
2465
3069
|
@file_id, @source_path, @provider, @kind, @external_session_id,
|
|
2466
3070
|
@session_id, @session_name, @project_path, @project_name,
|
|
@@ -2471,7 +3075,8 @@ var ConversationsRepo = class {
|
|
|
2471
3075
|
@first_sent_at, @first_sent_text, @last_sent_at, @last_sent_text,
|
|
2472
3076
|
@model, @is_subagent, @parent_session_id, @subagent_id, @parent_session_uuid,
|
|
2473
3077
|
@is_teammate, @team_name, @tool_names_json,
|
|
2474
|
-
@last_prompt,
|
|
3078
|
+
@last_prompt, @is_imported_from_claude, @is_imported_from_codex,
|
|
3079
|
+
@is_imported_from_cursor, 'active', CURRENT_TIMESTAMP
|
|
2475
3080
|
)
|
|
2476
3081
|
ON CONFLICT(file_id) DO UPDATE SET
|
|
2477
3082
|
source_path = excluded.source_path,
|
|
@@ -2503,6 +3108,9 @@ var ConversationsRepo = class {
|
|
|
2503
3108
|
team_name = excluded.team_name,
|
|
2504
3109
|
tool_names_json = excluded.tool_names_json,
|
|
2505
3110
|
last_prompt = excluded.last_prompt,
|
|
3111
|
+
is_imported_from_claude = excluded.is_imported_from_claude,
|
|
3112
|
+
is_imported_from_codex = excluded.is_imported_from_codex,
|
|
3113
|
+
is_imported_from_cursor = excluded.is_imported_from_cursor,
|
|
2506
3114
|
status = 'active',
|
|
2507
3115
|
index_seq = (SELECT COALESCE(MAX(index_seq), 0) + 1 FROM conversations),
|
|
2508
3116
|
updated_at = CURRENT_TIMESTAMP`
|
|
@@ -2539,7 +3147,10 @@ var ConversationsRepo = class {
|
|
|
2539
3147
|
is_teammate: meta.isTeammate ? 1 : 0,
|
|
2540
3148
|
team_name: meta.teamName,
|
|
2541
3149
|
tool_names_json: JSON.stringify(meta.toolNames),
|
|
2542
|
-
last_prompt: meta.lastPrompt ?? null
|
|
3150
|
+
last_prompt: meta.lastPrompt ?? null,
|
|
3151
|
+
is_imported_from_claude: meta.isImportedFromClaude ? 1 : 0,
|
|
3152
|
+
is_imported_from_codex: meta.isImportedFromCodex ? 1 : 0,
|
|
3153
|
+
is_imported_from_cursor: meta.isImportedFromCursor ? 1 : 0
|
|
2543
3154
|
});
|
|
2544
3155
|
}
|
|
2545
3156
|
getBySourcePath(sourcePath) {
|
|
@@ -2699,8 +3310,14 @@ var FtsRepo = class {
|
|
|
2699
3310
|
params.push(filters.account);
|
|
2700
3311
|
}
|
|
2701
3312
|
if (filters.provider) {
|
|
2702
|
-
|
|
2703
|
-
|
|
3313
|
+
const provider = canonicalizeProviderName(filters.provider) ?? filters.provider;
|
|
3314
|
+
if (provider === CURSOR_PROVIDER) {
|
|
3315
|
+
where.push("(c.provider = ? OR c.provider = ?)");
|
|
3316
|
+
params.push(CURSOR_PROVIDER, LEGACY_CURSOR_PROVIDER);
|
|
3317
|
+
} else {
|
|
3318
|
+
where.push("c.provider = ?");
|
|
3319
|
+
params.push(provider);
|
|
3320
|
+
}
|
|
2704
3321
|
}
|
|
2705
3322
|
if (filters.project) {
|
|
2706
3323
|
where.push("(lower(c.project_path) LIKE ? OR lower(c.project_name) LIKE ?)");
|
|
@@ -2819,7 +3436,7 @@ var PersistentEngine = class {
|
|
|
2819
3436
|
async indexAll(activeProfiles, options) {
|
|
2820
3437
|
const log = getLogger();
|
|
2821
3438
|
const tier = resolveTier(options.tier ?? "standard", options.tiers);
|
|
2822
|
-
const enabled = options.providers
|
|
3439
|
+
const enabled = canonicalizeProviderList(options.providers);
|
|
2823
3440
|
const discovered = [];
|
|
2824
3441
|
if (enabled.includes(CLAUDE_CODE_PROVIDER)) {
|
|
2825
3442
|
const configDirs = activeProfiles.map((p) => ({
|
|
@@ -2839,6 +3456,12 @@ var PersistentEngine = class {
|
|
|
2839
3456
|
discovered.push({ ...f, provider: codex });
|
|
2840
3457
|
}
|
|
2841
3458
|
}
|
|
3459
|
+
const cursor = new CursorProvider();
|
|
3460
|
+
if (enabled.includes(CURSOR_PROVIDER) && (options.cursorRoots?.length ?? 0) > 0) {
|
|
3461
|
+
for (const f of await cursor.discover(options.cursorRoots)) {
|
|
3462
|
+
discovered.push({ ...f, provider: cursor });
|
|
3463
|
+
}
|
|
3464
|
+
}
|
|
2842
3465
|
let scanned = 0;
|
|
2843
3466
|
const gitBranchMemo = /* @__PURE__ */ new Map();
|
|
2844
3467
|
const resolveGitBranch = (projectPath) => {
|
|
@@ -2877,6 +3500,9 @@ var PersistentEngine = class {
|
|
|
2877
3500
|
if (enabled.includes(CODEX_CLI_PROVIDER) && (options.codexRoots?.length ?? 0) > 0) {
|
|
2878
3501
|
coveredAccounts.add("codex");
|
|
2879
3502
|
}
|
|
3503
|
+
if (enabled.includes(CURSOR_PROVIDER) && (options.cursorRoots?.length ?? 0) > 0) {
|
|
3504
|
+
coveredAccounts.add("cursor");
|
|
3505
|
+
}
|
|
2880
3506
|
const seen = new Set(discovered.map((d) => canonicalPath(d.filePath)));
|
|
2881
3507
|
for (const path of this.files.activePathsByAccounts([...coveredAccounts])) {
|
|
2882
3508
|
if (!seen.has(path)) this.markDeleted(path);
|
|
@@ -2896,8 +3522,8 @@ var PersistentEngine = class {
|
|
|
2896
3522
|
const tier = resolveTier(tierName, customTiers);
|
|
2897
3523
|
const filePath = canonicalPath(rawFilePath);
|
|
2898
3524
|
const existing = this.files.getByPath(filePath);
|
|
2899
|
-
const { change, stat:
|
|
2900
|
-
if (change === "vanished" || !
|
|
3525
|
+
const { change, stat: stat5 } = classify(filePath, existing);
|
|
3526
|
+
if (change === "vanished" || !stat5) {
|
|
2901
3527
|
this.markDeleted(filePath);
|
|
2902
3528
|
return { meta: null, change: "vanished" };
|
|
2903
3529
|
}
|
|
@@ -2910,7 +3536,7 @@ var PersistentEngine = class {
|
|
|
2910
3536
|
filePath,
|
|
2911
3537
|
account,
|
|
2912
3538
|
tier,
|
|
2913
|
-
|
|
3539
|
+
stat5,
|
|
2914
3540
|
resolveGitBranch
|
|
2915
3541
|
);
|
|
2916
3542
|
return { meta: meta2, change };
|
|
@@ -2936,7 +3562,7 @@ var PersistentEngine = class {
|
|
|
2936
3562
|
return { meta: null, change };
|
|
2937
3563
|
}
|
|
2938
3564
|
meta.gitBranch = resolveGitBranch(meta.projectPath);
|
|
2939
|
-
const fp =
|
|
3565
|
+
const fp = stat5.size > 0 ? fingerprint(filePath, stat5.size) : null;
|
|
2940
3566
|
const fileId = this.files.ensure(filePath, account);
|
|
2941
3567
|
const base = resume ? this.fts.readDocument(fileId) ?? emptySearchDocument() : emptySearchDocument();
|
|
2942
3568
|
const searchDoc = appendSearchDelta(base, searchDelta);
|
|
@@ -2947,8 +3573,8 @@ var PersistentEngine = class {
|
|
|
2947
3573
|
}
|
|
2948
3574
|
if (!resume) this.checkpoints.remove(filePath);
|
|
2949
3575
|
this.files.updateCursor(fileId, {
|
|
2950
|
-
sizeBytes:
|
|
2951
|
-
mtimeMs:
|
|
3576
|
+
sizeBytes: stat5.size,
|
|
3577
|
+
mtimeMs: stat5.mtimeMs,
|
|
2952
3578
|
// Advance only to the last fully-parsed line; a trailing partial line
|
|
2953
3579
|
// is left for the next pass.
|
|
2954
3580
|
offset: result.newOffset,
|
|
@@ -2965,8 +3591,8 @@ var PersistentEngine = class {
|
|
|
2965
3591
|
buildSidecar(
|
|
2966
3592
|
meta,
|
|
2967
3593
|
{
|
|
2968
|
-
sizeBytes:
|
|
2969
|
-
mtimeMs:
|
|
3594
|
+
sizeBytes: stat5.size,
|
|
3595
|
+
mtimeMs: stat5.mtimeMs,
|
|
2970
3596
|
offset: result.newOffset,
|
|
2971
3597
|
line: result.newLine
|
|
2972
3598
|
},
|
|
@@ -2985,7 +3611,7 @@ var PersistentEngine = class {
|
|
|
2985
3611
|
// the Threadbase path uses. The cursor records size/mtime (and offset = size)
|
|
2986
3612
|
// so the next pass classifies an unchanged file as "unchanged" and skips it;
|
|
2987
3613
|
// any change reparses from 0 again. No reducer_state is persisted.
|
|
2988
|
-
async indexFileWithProvider(provider, filePath, account, tier,
|
|
3614
|
+
async indexFileWithProvider(provider, filePath, account, tier, stat5, resolveGitBranch) {
|
|
2989
3615
|
const log = getLogger();
|
|
2990
3616
|
let searchDoc = emptySearchDocument();
|
|
2991
3617
|
const meta = await parseMetaWithProvider(provider, filePath, account, tier, (entry) => {
|
|
@@ -2998,7 +3624,7 @@ var PersistentEngine = class {
|
|
|
2998
3624
|
if (meta.gitBranch === null && meta.projectPath) {
|
|
2999
3625
|
meta.gitBranch = resolveGitBranch(meta.projectPath);
|
|
3000
3626
|
}
|
|
3001
|
-
const fp =
|
|
3627
|
+
const fp = stat5.size > 0 ? fingerprint(filePath, stat5.size) : null;
|
|
3002
3628
|
const fileId = this.files.ensure(filePath, account);
|
|
3003
3629
|
const upsert = this.db.transaction(() => {
|
|
3004
3630
|
this.conversations.upsert(fileId, meta, meta.messageCount);
|
|
@@ -3007,11 +3633,11 @@ var PersistentEngine = class {
|
|
|
3007
3633
|
}
|
|
3008
3634
|
this.checkpoints.remove(filePath);
|
|
3009
3635
|
this.files.updateCursor(fileId, {
|
|
3010
|
-
sizeBytes:
|
|
3011
|
-
mtimeMs:
|
|
3636
|
+
sizeBytes: stat5.size,
|
|
3637
|
+
mtimeMs: stat5.mtimeMs,
|
|
3012
3638
|
// offset = size marks the file fully consumed (non-zero so the next pass
|
|
3013
3639
|
// can classify it "unchanged"); no resumable reducer state is kept.
|
|
3014
|
-
offset:
|
|
3640
|
+
offset: stat5.size,
|
|
3015
3641
|
line: 0,
|
|
3016
3642
|
reducerState: null,
|
|
3017
3643
|
fingerprint: fp,
|
|
@@ -3077,8 +3703,8 @@ var PersistentEngine = class {
|
|
|
3077
3703
|
const meta = this.conversations.getByIdOrSession(id);
|
|
3078
3704
|
if (!meta) return null;
|
|
3079
3705
|
const filePath = meta.filePath;
|
|
3080
|
-
if (meta.provider === CODEX_CLI_PROVIDER) {
|
|
3081
|
-
const conversation = await parseCodexConversation(filePath, meta.account);
|
|
3706
|
+
if (meta.provider === CODEX_CLI_PROVIDER || meta.provider === CURSOR_PROVIDER) {
|
|
3707
|
+
const conversation = meta.provider === CODEX_CLI_PROVIDER ? await parseCodexConversation(filePath, meta.account) : await parseCursorConversation(filePath, meta.account);
|
|
3082
3708
|
if (!conversation) return null;
|
|
3083
3709
|
const { messages } = conversation;
|
|
3084
3710
|
const total2 = messages.length;
|
|
@@ -3093,7 +3719,7 @@ var PersistentEngine = class {
|
|
|
3093
3719
|
let floor = this.checkpoints.floor(filePath, fromIndex);
|
|
3094
3720
|
if (floor) {
|
|
3095
3721
|
try {
|
|
3096
|
-
if (floor.byteOffset > (0,
|
|
3722
|
+
if (floor.byteOffset > (0, import_fs11.statSync)(filePath).size) floor = null;
|
|
3097
3723
|
} catch {
|
|
3098
3724
|
}
|
|
3099
3725
|
}
|
|
@@ -3232,7 +3858,7 @@ function defaultDbPath() {
|
|
|
3232
3858
|
"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."
|
|
3233
3859
|
);
|
|
3234
3860
|
}
|
|
3235
|
-
return (0,
|
|
3861
|
+
return (0, import_path12.join)((0, import_os2.homedir)(), ".config", "threadbase-scanner", "index.db");
|
|
3236
3862
|
}
|
|
3237
3863
|
function capForMemory(doc, max) {
|
|
3238
3864
|
const combined = combineSearchContent(doc);
|
|
@@ -3411,7 +4037,7 @@ var ConversationScanner = class {
|
|
|
3411
4037
|
const cached = statCache.get(filePath);
|
|
3412
4038
|
if (cached) {
|
|
3413
4039
|
try {
|
|
3414
|
-
const s = (0,
|
|
4040
|
+
const s = (0, import_fs12.statSync)(filePath);
|
|
3415
4041
|
if (s.mtimeMs === cached.stat.mtimeMs && s.size === cached.stat.size) {
|
|
3416
4042
|
return {
|
|
3417
4043
|
meta: cached.meta,
|
|
@@ -3542,9 +4168,7 @@ var ConversationScanner = class {
|
|
|
3542
4168
|
results = results.filter((r) => r.meta.account === options.account);
|
|
3543
4169
|
}
|
|
3544
4170
|
if (options.provider) {
|
|
3545
|
-
results = results.filter(
|
|
3546
|
-
(r) => (r.meta.provider ?? CLAUDE_CODE_PROVIDER) === options.provider
|
|
3547
|
-
);
|
|
4171
|
+
results = results.filter((r) => providerMatches(r.meta.provider, options.provider));
|
|
3548
4172
|
}
|
|
3549
4173
|
if (options.since) {
|
|
3550
4174
|
const cutoff = parseSinceCutoff(options.since);
|
|
@@ -3571,12 +4195,12 @@ var ConversationScanner = class {
|
|
|
3571
4195
|
}
|
|
3572
4196
|
log.debug({ id, filePath: meta.filePath }, "getConversation: cache miss, parsing");
|
|
3573
4197
|
try {
|
|
3574
|
-
if (this.persistent && meta.provider !== CODEX_CLI_PROVIDER) {
|
|
4198
|
+
if (this.persistent && meta.provider !== CODEX_CLI_PROVIDER && meta.provider !== CURSOR_PROVIDER) {
|
|
3575
4199
|
const parsed = await parseConversationResumable(meta.filePath, meta.account);
|
|
3576
4200
|
if (parsed) this.conversationLRU.set(cid, parsed);
|
|
3577
4201
|
return parsed?.conversation ?? null;
|
|
3578
4202
|
}
|
|
3579
|
-
const conversation = meta.provider === CODEX_CLI_PROVIDER ? await parseCodexConversation(meta.filePath, meta.account) : await parseConversation(meta.filePath, meta.account);
|
|
4203
|
+
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);
|
|
3580
4204
|
if (conversation) {
|
|
3581
4205
|
this.conversationLRU.set(cid, { conversation });
|
|
3582
4206
|
}
|
|
@@ -3630,7 +4254,7 @@ var ConversationScanner = class {
|
|
|
3630
4254
|
// fallback, matching refreshFile.
|
|
3631
4255
|
async parseSingleFilePage(filePath, account, options) {
|
|
3632
4256
|
const provider = await this.resolveProviderForFile(filePath, null);
|
|
3633
|
-
const conversation = provider?.name === CODEX_CLI_PROVIDER ? await parseCodexConversation(filePath, account ?? "default") : await parseConversation(filePath, account ?? "default");
|
|
4257
|
+
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");
|
|
3634
4258
|
if (!conversation) return null;
|
|
3635
4259
|
const { messages } = conversation;
|
|
3636
4260
|
const total = messages.length;
|
|
@@ -3919,7 +4543,7 @@ var ConversationScanner = class {
|
|
|
3919
4543
|
// discovers under the active profiles' project dirs; Codex discovers under
|
|
3920
4544
|
// the explicit codexRoots (opt-in — no default home scan).
|
|
3921
4545
|
async discoverWithProviders(activeProfiles, options) {
|
|
3922
|
-
const enabled = options.providers
|
|
4546
|
+
const enabled = canonicalizeProviderList(options.providers);
|
|
3923
4547
|
const work = [];
|
|
3924
4548
|
if (enabled.includes(CLAUDE_CODE_PROVIDER)) {
|
|
3925
4549
|
const provider = new ThreadbaseProvider();
|
|
@@ -3934,6 +4558,12 @@ var ConversationScanner = class {
|
|
|
3934
4558
|
work.push({ ...f, provider });
|
|
3935
4559
|
}
|
|
3936
4560
|
}
|
|
4561
|
+
if (enabled.includes(CURSOR_PROVIDER) && (options.cursorRoots?.length ?? 0) > 0) {
|
|
4562
|
+
const provider = new CursorProvider();
|
|
4563
|
+
for (const f of await provider.discover(options.cursorRoots)) {
|
|
4564
|
+
work.push({ ...f, provider });
|
|
4565
|
+
}
|
|
4566
|
+
}
|
|
3937
4567
|
return work;
|
|
3938
4568
|
}
|
|
3939
4569
|
// Resolve which provider should (re)parse a file. Stored metadata wins; for a
|
|
@@ -3942,20 +4572,25 @@ var ConversationScanner = class {
|
|
|
3942
4572
|
// tail-read path).
|
|
3943
4573
|
async resolveProviderForFile(filePath, previous) {
|
|
3944
4574
|
if (previous?.provider === CODEX_CLI_PROVIDER) return new CodexCliProvider();
|
|
4575
|
+
if (providerMatches(previous?.provider, CURSOR_PROVIDER)) {
|
|
4576
|
+
return new CursorProvider();
|
|
4577
|
+
}
|
|
3945
4578
|
if (previous?.provider) return void 0;
|
|
3946
4579
|
let sample = "";
|
|
3947
4580
|
try {
|
|
3948
|
-
const fd = (0,
|
|
4581
|
+
const fd = (0, import_fs12.openSync)(filePath, "r");
|
|
3949
4582
|
try {
|
|
3950
4583
|
const buf = Buffer.alloc(8192);
|
|
3951
|
-
const n = (0,
|
|
4584
|
+
const n = (0, import_fs12.readSync)(fd, buf, 0, buf.length, 0);
|
|
3952
4585
|
sample = buf.subarray(0, n).toString("utf8");
|
|
3953
4586
|
} finally {
|
|
3954
|
-
(0,
|
|
4587
|
+
(0, import_fs12.closeSync)(fd);
|
|
3955
4588
|
}
|
|
3956
4589
|
} catch {
|
|
3957
4590
|
return void 0;
|
|
3958
4591
|
}
|
|
4592
|
+
const cursor = new CursorProvider();
|
|
4593
|
+
if (cursor.canParse(filePath, sample)) return cursor;
|
|
3959
4594
|
const codex = new CodexCliProvider();
|
|
3960
4595
|
if (codex.canParse(filePath, sample)) return codex;
|
|
3961
4596
|
return void 0;
|
|
@@ -4065,9 +4700,14 @@ async function getConversation(id, options, scanner) {
|
|
|
4065
4700
|
}
|
|
4066
4701
|
// Annotate the CommonJS export names for ESM import in node:
|
|
4067
4702
|
0 && (module.exports = {
|
|
4703
|
+
CLAUDE_CODE_PROVIDER,
|
|
4704
|
+
CODEX_CLI_PROVIDER,
|
|
4705
|
+
CURSOR_PROVIDER,
|
|
4068
4706
|
CodexCliProvider,
|
|
4069
4707
|
ConversationScanner,
|
|
4708
|
+
CursorProvider,
|
|
4070
4709
|
DEFAULT_TIERS,
|
|
4710
|
+
LEGACY_CURSOR_PROVIDER,
|
|
4071
4711
|
SearchIndexer,
|
|
4072
4712
|
ThreadbaseProvider,
|
|
4073
4713
|
VALID_SORT_ORDERS,
|
|
@@ -4077,6 +4717,8 @@ async function getConversation(id, options, scanner) {
|
|
|
4077
4717
|
applyProjectFilter,
|
|
4078
4718
|
applySinceFilter,
|
|
4079
4719
|
applySort,
|
|
4720
|
+
canonicalizeProviderList,
|
|
4721
|
+
canonicalizeProviderName,
|
|
4080
4722
|
cleanSystemTags,
|
|
4081
4723
|
createJsonlParseState,
|
|
4082
4724
|
createLogger,
|
|
@@ -4087,7 +4729,9 @@ async function getConversation(id, options, scanner) {
|
|
|
4087
4729
|
isCodexInjectedContext,
|
|
4088
4730
|
loadProfiles,
|
|
4089
4731
|
parseCodexJsonlLine,
|
|
4732
|
+
parseCursorJsonlLine,
|
|
4090
4733
|
parseJsonlLine,
|
|
4734
|
+
providerMatches,
|
|
4091
4735
|
readGitBranch,
|
|
4092
4736
|
readSidecar,
|
|
4093
4737
|
resetDefaultScanner,
|
|
@@ -4097,6 +4741,7 @@ async function getConversation(id, options, scanner) {
|
|
|
4097
4741
|
scan,
|
|
4098
4742
|
search,
|
|
4099
4743
|
setLogger,
|
|
4100
|
-
sidecarPath
|
|
4744
|
+
sidecarPath,
|
|
4745
|
+
unwrapCursorUserText
|
|
4101
4746
|
});
|
|
4102
4747
|
//# sourceMappingURL=index.cjs.map
|