@threadbase-sh/scanner 0.17.7 → 0.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/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() {
@@ -1186,9 +1209,405 @@ async function parseCodexConversation(filePath, account) {
1186
1209
  };
1187
1210
  }
1188
1211
 
1189
- // src/discovery.ts
1212
+ // src/providers/cursor.ts
1190
1213
  import fg2 from "fast-glob";
1214
+ import { createReadStream as createReadStream3, existsSync, statSync } from "fs";
1191
1215
  import { stat as stat2 } from "fs/promises";
1216
+ import { basename as basename4, dirname as dirname3, join as join4, sep as sep2 } from "path";
1217
+ import { createInterface as createInterface3 } from "readline";
1218
+ var TIMESTAMP_RE = /<timestamp>\s*([\s\S]*?)\s*<\/timestamp>/;
1219
+ var USER_QUERY_RE = /<user_query>\s*([\s\S]*?)\s*<\/user_query>/;
1220
+ var SUBAGENT_PATH_RE2 = /[\\/]subagents[\\/]/;
1221
+ var CursorProvider = class {
1222
+ name = CURSOR_PROVIDER;
1223
+ async discover(roots) {
1224
+ const log = getLogger();
1225
+ const results = [];
1226
+ for (const root of roots) {
1227
+ let paths;
1228
+ try {
1229
+ paths = await fg2(["**/agent-transcripts/**/*.jsonl"], {
1230
+ cwd: root,
1231
+ absolute: true,
1232
+ dot: false,
1233
+ unique: true
1234
+ });
1235
+ } catch (err) {
1236
+ log.warn({ root, err }, "cursor discovery: glob failed");
1237
+ continue;
1238
+ }
1239
+ for (const filePath of paths) {
1240
+ try {
1241
+ const s = await stat2(filePath);
1242
+ if (s.size > 0) results.push({ filePath: canonicalPath(filePath), account: "cursor" });
1243
+ } catch (err) {
1244
+ log.warn({ filePath, err }, "cursor discovery: stat failed");
1245
+ }
1246
+ }
1247
+ }
1248
+ return results;
1249
+ }
1250
+ canParse(filePath, sample) {
1251
+ const underTranscripts = /[\\/]agent-transcripts[\\/]/.test(filePath);
1252
+ for (const line of sample.split("\n")) {
1253
+ if (!line.trim()) continue;
1254
+ try {
1255
+ const e = JSON.parse(line);
1256
+ if (looksLikeImportedCodexEntry(e) || looksLikeImportedClaudeEntry(e)) {
1257
+ return underTranscripts;
1258
+ }
1259
+ if (looksLikeCursorChatEntry(e)) return true;
1260
+ } catch {
1261
+ }
1262
+ }
1263
+ return false;
1264
+ }
1265
+ createEmptyAccumulator() {
1266
+ return {
1267
+ sessionId: "",
1268
+ latestTimestamp: "",
1269
+ messageCount: 0,
1270
+ lastMessageSender: "user",
1271
+ isSubagent: false,
1272
+ parentSessionUuid: null,
1273
+ subagentId: null,
1274
+ firstUser: null,
1275
+ lastUser: null,
1276
+ lastAssistant: null,
1277
+ isImportedFromClaude: false,
1278
+ isImportedFromCodex: false,
1279
+ toolNames: [],
1280
+ previewParts: [],
1281
+ previewLength: 0,
1282
+ snippetParts: [],
1283
+ snippetLength: 0
1284
+ };
1285
+ }
1286
+ reduceEntry(acc, entry, tier) {
1287
+ reduceCursorEntry(acc, entry, tier);
1288
+ }
1289
+ finalize(acc, filePath, account, tier) {
1290
+ return finalizeCursorMeta(acc, filePath, account, tier);
1291
+ }
1292
+ };
1293
+ function looksLikeCursorChatEntry(entry) {
1294
+ const role = entry.role;
1295
+ if (role !== "user" && role !== "assistant") return false;
1296
+ if (entry.type === "user" || entry.type === "assistant") return false;
1297
+ return true;
1298
+ }
1299
+ function looksLikeImportedClaudeEntry(entry) {
1300
+ return entry.type === "user" || entry.type === "assistant";
1301
+ }
1302
+ function looksLikeImportedCodexEntry(entry) {
1303
+ return entry.type === "session_meta" || entry.type === "response_item" || entry.type === "event_msg";
1304
+ }
1305
+ function asString2(value) {
1306
+ return typeof value === "string" ? value : "";
1307
+ }
1308
+ function provenanceToken(value) {
1309
+ if (typeof value === "string") return value.trim().toLowerCase();
1310
+ if (value && typeof value === "object") {
1311
+ const rec = value;
1312
+ return provenanceToken(
1313
+ rec.importedFrom ?? rec.imported_from ?? rec.sourceProvider ?? rec.source
1314
+ );
1315
+ }
1316
+ return "";
1317
+ }
1318
+ function importedFromClaudeToken(token) {
1319
+ return token === "claude" || token === "claude-code" || token === "claude_code" || token === "anthropic";
1320
+ }
1321
+ function importedFromCodexToken(token) {
1322
+ return token === "codex" || token === "codex-cli" || token === "codex_cli" || token === "openai-codex";
1323
+ }
1324
+ function noteImportProvenance(acc, entry, text) {
1325
+ const token = provenanceToken(
1326
+ 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)
1327
+ );
1328
+ if (importedFromClaudeToken(token) || looksLikeImportedClaudeEntry(entry)) {
1329
+ acc.isImportedFromClaude = true;
1330
+ }
1331
+ if (importedFromCodexToken(token) || looksLikeImportedCodexEntry(entry)) {
1332
+ acc.isImportedFromCodex = true;
1333
+ }
1334
+ if (/imported from claude/i.test(text) || /<imported_from_claude>/i.test(text)) {
1335
+ acc.isImportedFromClaude = true;
1336
+ }
1337
+ if (/imported from codex/i.test(text) || /<imported_from_codex>/i.test(text)) {
1338
+ acc.isImportedFromCodex = true;
1339
+ }
1340
+ }
1341
+ function unwrapCursorUserText(text) {
1342
+ const query = text.match(USER_QUERY_RE);
1343
+ const body = query ? query[1] : text.replace(TIMESTAMP_RE, "");
1344
+ return cleanSystemTags(body);
1345
+ }
1346
+ function timestampFromCursorUserText(text) {
1347
+ const match = text.match(TIMESTAMP_RE);
1348
+ if (!match) return "";
1349
+ const parsed = Date.parse(match[1].trim());
1350
+ return Number.isNaN(parsed) ? "" : new Date(parsed).toISOString();
1351
+ }
1352
+ function extractCursorText(content) {
1353
+ if (typeof content === "string") return unwrapCursorUserText(content);
1354
+ if (!Array.isArray(content)) return "";
1355
+ return content.map((item) => {
1356
+ if (typeof item === "string") return unwrapCursorUserText(item);
1357
+ const block = item;
1358
+ if ((block?.type === "text" || block?.type === void 0) && typeof block.text === "string") {
1359
+ return unwrapCursorUserText(block.text);
1360
+ }
1361
+ return "";
1362
+ }).filter(Boolean).join(" ");
1363
+ }
1364
+ function collectCursorToolNames(content, into) {
1365
+ if (!Array.isArray(content)) return;
1366
+ for (const item of content) {
1367
+ const block = item;
1368
+ if (block?.type === "tool_use" && typeof block.name === "string" && block.name) {
1369
+ if (!into.includes(block.name)) into.push(block.name);
1370
+ }
1371
+ }
1372
+ }
1373
+ function firstTimestampHint(content) {
1374
+ if (typeof content === "string") return timestampFromCursorUserText(content);
1375
+ if (!Array.isArray(content)) return "";
1376
+ for (const item of content) {
1377
+ if (typeof item === "string") {
1378
+ const ts = timestampFromCursorUserText(item);
1379
+ if (ts) return ts;
1380
+ } else if (typeof item?.text === "string") {
1381
+ const ts = timestampFromCursorUserText(item.text);
1382
+ if (ts) return ts;
1383
+ }
1384
+ }
1385
+ return "";
1386
+ }
1387
+ function parseCursorJsonlLine(line) {
1388
+ if (!line.trim()) return null;
1389
+ let entry;
1390
+ try {
1391
+ entry = JSON.parse(line);
1392
+ } catch {
1393
+ return null;
1394
+ }
1395
+ return cursorEntryToMessage(entry);
1396
+ }
1397
+ function cursorEntryToMessage(entry) {
1398
+ if (looksLikeCursorChatEntry(entry)) {
1399
+ const role = entry.role;
1400
+ const message = entry.message;
1401
+ const text = extractCursorText(message?.content ?? entry.content);
1402
+ if (!text) return null;
1403
+ const ts = firstTimestampHint(message?.content ?? entry.content);
1404
+ return { role, text, timestamp: ts };
1405
+ }
1406
+ if (looksLikeImportedClaudeEntry(entry)) {
1407
+ const message = entry.message;
1408
+ const role = message?.role === "assistant" || entry.type === "assistant" ? "assistant" : "user";
1409
+ const text = extractCursorText(message?.content ?? entry.content);
1410
+ if (!text) return null;
1411
+ const ts = asString2(entry.timestamp);
1412
+ return { role, text, timestamp: ts };
1413
+ }
1414
+ return parseCodexJsonlLine(JSON.stringify(entry));
1415
+ }
1416
+ function foldCursorMessage(acc, role, text, timestamp, tier) {
1417
+ if (timestamp && (!acc.latestTimestamp || timestamp > acc.latestTimestamp)) {
1418
+ acc.latestTimestamp = timestamp;
1419
+ }
1420
+ acc.messageCount++;
1421
+ acc.lastMessageSender = role;
1422
+ const snapshot = { text: text.slice(0, 200), timestamp };
1423
+ if (role === "user") {
1424
+ if (!acc.firstUser) acc.firstUser = snapshot;
1425
+ acc.lastUser = snapshot;
1426
+ } else {
1427
+ acc.lastAssistant = snapshot;
1428
+ }
1429
+ if (acc.previewLength < tier.previewMax) {
1430
+ acc.previewParts.push(text);
1431
+ acc.previewLength += text.length;
1432
+ }
1433
+ if (acc.snippetLength < tier.snippetMax) {
1434
+ const remaining = tier.snippetMax - acc.snippetLength;
1435
+ const chunk = text.length > remaining ? text.slice(0, remaining) : text;
1436
+ acc.snippetParts.push(chunk);
1437
+ acc.snippetLength += chunk.length;
1438
+ }
1439
+ }
1440
+ function reduceCursorEntry(acc, entry, tier) {
1441
+ const message = entry.message;
1442
+ const content = message?.content ?? entry.content;
1443
+ const textHint = extractCursorText(content);
1444
+ noteImportProvenance(acc, entry, textHint);
1445
+ if (looksLikeCursorChatEntry(entry)) {
1446
+ collectCursorToolNames(content, acc.toolNames);
1447
+ const text = textHint;
1448
+ if (!text) return;
1449
+ foldCursorMessage(acc, entry.role, text, firstTimestampHint(content), tier);
1450
+ return;
1451
+ }
1452
+ if (looksLikeImportedClaudeEntry(entry)) {
1453
+ collectCursorToolNames(content, acc.toolNames);
1454
+ const msg = cursorEntryToMessage(entry);
1455
+ if (!msg) return;
1456
+ foldCursorMessage(acc, msg.role, msg.text, msg.timestamp, tier);
1457
+ return;
1458
+ }
1459
+ if (looksLikeImportedCodexEntry(entry)) {
1460
+ const msg = parseCodexJsonlLine(JSON.stringify(entry));
1461
+ if (!msg) return;
1462
+ foldCursorMessage(acc, msg.role, msg.text, msg.timestamp, tier);
1463
+ }
1464
+ }
1465
+ function finalizeCursorMeta(acc, filePath, account, tier) {
1466
+ if (acc.messageCount === 0) return null;
1467
+ const sessionId = basename4(filePath, ".jsonl");
1468
+ const isSubagent = SUBAGENT_PATH_RE2.test(filePath);
1469
+ const parent = isSubagent ? parentFromSubagentPath(filePath) : null;
1470
+ const { projectPath, projectName } = projectFromCursorPath(filePath);
1471
+ const timestamp = acc.latestTimestamp || fileMtimeIso(filePath);
1472
+ const kind = acc.lastAssistant === null && acc.toolNames.length > 0 ? "task" : "conversation";
1473
+ return {
1474
+ id: filePath,
1475
+ filePath,
1476
+ provider: CURSOR_PROVIDER,
1477
+ kind,
1478
+ externalSessionId: sessionId,
1479
+ sessionId,
1480
+ sessionName: deriveSessionNameFromFirstMessage(acc.firstUser),
1481
+ projectPath,
1482
+ projectName,
1483
+ account,
1484
+ timestamp,
1485
+ messageCount: acc.messageCount,
1486
+ lastMessageSender: acc.lastMessageSender,
1487
+ preview: acc.previewParts.join(" ").slice(0, tier.previewMax),
1488
+ contentSnippet: acc.snippetParts.join(" "),
1489
+ gitBranch: null,
1490
+ model: null,
1491
+ isSubagent,
1492
+ parentSessionId: parent?.parentFilePath ?? null,
1493
+ subagentId: isSubagent ? sessionId : void 0,
1494
+ parentSessionUuid: parent?.parentSessionUuid ?? void 0,
1495
+ isTeammate: false,
1496
+ teamName: null,
1497
+ toolNames: acc.toolNames,
1498
+ firstMessage: acc.firstUser,
1499
+ lastMessage: acc.lastAssistant ?? acc.lastUser,
1500
+ lastPrompt: acc.lastUser?.text || void 0,
1501
+ ...acc.isImportedFromClaude ? { isImportedFromClaude: true } : {},
1502
+ ...acc.isImportedFromCodex ? { isImportedFromCodex: true } : {}
1503
+ };
1504
+ }
1505
+ function parentFromSubagentPath(filePath) {
1506
+ const subagentsDir = dirname3(filePath);
1507
+ const parentDir = dirname3(subagentsDir);
1508
+ const parentSessionUuid = basename4(parentDir);
1509
+ if (!parentSessionUuid) return null;
1510
+ return {
1511
+ parentSessionUuid,
1512
+ parentFilePath: canonicalPath(join4(parentDir, `${parentSessionUuid}.jsonl`))
1513
+ };
1514
+ }
1515
+ function projectFromCursorPath(filePath) {
1516
+ const parts = filePath.split(/[/\\]/);
1517
+ const idx = parts.lastIndexOf("agent-transcripts");
1518
+ const cursorProjectDir = idx > 0 ? parts.slice(0, idx).join(sep2) : dirname3(dirname3(filePath));
1519
+ const slug = basename4(cursorProjectDir);
1520
+ const decoded = decodeCursorProjectSlug(slug);
1521
+ const projectPath = decoded ?? cursorProjectDir;
1522
+ return { projectPath, projectName: getShortProjectName4(projectPath) || slug };
1523
+ }
1524
+ function decodeCursorProjectSlug(slug) {
1525
+ if (!slug) return null;
1526
+ const segments = slug.split("-");
1527
+ if (segments.length === 0) return null;
1528
+ const rooted = slug.startsWith("Users-") || slug.startsWith("home-") || /^[A-Za-z]-/.test(slug);
1529
+ let acc = rooted ? sep2 : "";
1530
+ let i = 0;
1531
+ if (rooted && segments[0] === "Users") {
1532
+ const users = `${sep2}Users`;
1533
+ if (!existsSync(users)) return null;
1534
+ acc = users;
1535
+ i = 1;
1536
+ }
1537
+ while (i < segments.length) {
1538
+ let found = null;
1539
+ let next = i + 1;
1540
+ for (let j = segments.length; j > i; j--) {
1541
+ const candidate = join4(acc, segments.slice(i, j).join("-"));
1542
+ try {
1543
+ if (existsSync(candidate) && statSync(candidate).isDirectory()) {
1544
+ found = candidate;
1545
+ next = j;
1546
+ break;
1547
+ }
1548
+ } catch {
1549
+ }
1550
+ }
1551
+ if (!found) return null;
1552
+ acc = found;
1553
+ i = next;
1554
+ }
1555
+ return acc;
1556
+ }
1557
+ function getShortProjectName4(fullPath) {
1558
+ return fullPath.split(/[/\\]/).filter(Boolean).slice(-3).join("/");
1559
+ }
1560
+ function fileMtimeIso(filePath) {
1561
+ try {
1562
+ return new Date(statSync(filePath).mtimeMs).toISOString();
1563
+ } catch {
1564
+ return (/* @__PURE__ */ new Date()).toISOString();
1565
+ }
1566
+ }
1567
+ async function parseCursorConversation(filePath, account) {
1568
+ const log = getLogger();
1569
+ const messages = [];
1570
+ const textParts = [];
1571
+ let latestTimestamp = "";
1572
+ let lastUserText = "";
1573
+ const rl = createInterface3({ input: createReadStream3(filePath), crlfDelay: Infinity });
1574
+ try {
1575
+ for await (const line of rl) {
1576
+ const message = parseCursorJsonlLine(line);
1577
+ if (!message) continue;
1578
+ if (message.timestamp && (!latestTimestamp || message.timestamp > latestTimestamp)) {
1579
+ latestTimestamp = message.timestamp;
1580
+ }
1581
+ messages.push(message);
1582
+ textParts.push(message.text);
1583
+ if (message.role === "user") lastUserText = message.text;
1584
+ }
1585
+ } catch (err) {
1586
+ log.warn({ filePath, err }, "parseCursorConversation: read failed");
1587
+ return null;
1588
+ }
1589
+ if (messages.length === 0) return null;
1590
+ const { projectPath, projectName } = projectFromCursorPath(filePath);
1591
+ const sessionId = basename4(filePath, ".jsonl");
1592
+ return {
1593
+ id: filePath,
1594
+ filePath,
1595
+ projectPath,
1596
+ projectName,
1597
+ sessionId,
1598
+ sessionName: "",
1599
+ messages,
1600
+ fullText: textParts.join(" "),
1601
+ timestamp: latestTimestamp || fileMtimeIso(filePath),
1602
+ messageCount: messages.length,
1603
+ account,
1604
+ lastPrompt: lastUserText || void 0
1605
+ };
1606
+ }
1607
+
1608
+ // src/discovery.ts
1609
+ import fg3 from "fast-glob";
1610
+ import { stat as stat3 } from "fs/promises";
1192
1611
  var EXCLUDED_SEGMENTS = ["/memory/", "/tool-results/"];
1193
1612
  var STAT_CONCURRENCY = 32;
1194
1613
  async function discoverJsonlFiles(dirs, onProgress) {
@@ -1197,7 +1616,7 @@ async function discoverJsonlFiles(dirs, onProgress) {
1197
1616
  for (const { projectsDir, account } of dirs) {
1198
1617
  let filePaths;
1199
1618
  try {
1200
- filePaths = await fg2("**/*.jsonl", {
1619
+ filePaths = await fg3("**/*.jsonl", {
1201
1620
  cwd: projectsDir,
1202
1621
  absolute: true,
1203
1622
  dot: false
@@ -1215,7 +1634,7 @@ async function discoverJsonlFiles(dirs, onProgress) {
1215
1634
  const statted = await Promise.all(
1216
1635
  chunk.map(async (filePath) => {
1217
1636
  try {
1218
- const s = await stat2(filePath);
1637
+ const s = await stat3(filePath);
1219
1638
  return { filePath, size: s.size };
1220
1639
  } catch (err) {
1221
1640
  log.warn({ filePath, err }, "discovery: stat failed");
@@ -1290,9 +1709,9 @@ var ThreadbaseProvider = class {
1290
1709
 
1291
1710
  // src/scanner.ts
1292
1711
  import { EventEmitter } from "events";
1293
- import { closeSync as closeSync2, openSync as openSync2, readSync as readSync2, statSync as statSync3 } from "fs";
1712
+ import { closeSync as closeSync2, openSync as openSync2, readSync as readSync2, statSync as statSync4 } from "fs";
1294
1713
  import { homedir as homedir2 } from "os";
1295
- import { join as join5 } from "path";
1714
+ import { join as join6 } from "path";
1296
1715
 
1297
1716
  // src/cache.ts
1298
1717
  var LRUCache = class {
@@ -1331,18 +1750,18 @@ var LRUCache = class {
1331
1750
  };
1332
1751
 
1333
1752
  // src/persistent/conversation-stream.ts
1334
- import { basename as basename4 } from "path";
1753
+ import { basename as basename5 } from "path";
1335
1754
 
1336
1755
  // src/persistent/paged-reader.ts
1337
- import { createReadStream as createReadStream4 } from "fs";
1756
+ import { createReadStream as createReadStream5 } from "fs";
1338
1757
  import { setImmediate as yieldToEventLoop2 } from "timers/promises";
1339
1758
 
1340
1759
  // src/persistent/jsonl-tail-reader.ts
1341
- import { createReadStream as createReadStream3 } from "fs";
1760
+ import { createReadStream as createReadStream4 } from "fs";
1342
1761
  import { setImmediate as yieldToEventLoop } from "timers/promises";
1343
1762
  var YIELD_EVERY_LINES = 500;
1344
1763
  async function tailReduce(filePath, startOffset, startLine, state, tier, onEntry) {
1345
- const stream = createReadStream3(filePath, { start: startOffset, encoding: "utf8" });
1764
+ const stream = createReadStream4(filePath, { start: startOffset, encoding: "utf8" });
1346
1765
  let buffer = "";
1347
1766
  let offset = startOffset;
1348
1767
  let line = startLine;
@@ -1379,7 +1798,7 @@ async function tailReduce(filePath, startOffset, startLine, state, tier, onEntry
1379
1798
  // src/persistent/paged-reader.ts
1380
1799
  var CHECKPOINT_INTERVAL = 500;
1381
1800
  async function streamMessages(filePath, startOffset, startLine, state, onMessage, onEntry) {
1382
- const stream = createReadStream4(filePath, { start: startOffset, encoding: "utf8" });
1801
+ const stream = createReadStream5(filePath, { start: startOffset, encoding: "utf8" });
1383
1802
  let buffer = "";
1384
1803
  let offset = startOffset;
1385
1804
  let line = startLine;
@@ -1491,7 +1910,7 @@ function assemble(filePath, account, messages, fullText, turnDurations, state) {
1491
1910
  filePath,
1492
1911
  projectPath: state.cwd,
1493
1912
  projectName: getShortProjectName2(state.cwd),
1494
- sessionId: state.sessionId || basename4(filePath, ".jsonl"),
1913
+ sessionId: state.sessionId || basename5(filePath, ".jsonl"),
1495
1914
  sessionName: state.sessionName || deriveSessionNameFromFirstMessage(messages.find((m) => m.role === "user" && m.text) ?? null),
1496
1915
  messages,
1497
1916
  fullText,
@@ -1536,7 +1955,7 @@ async function extendConversation(previous, resume, filePath, account) {
1536
1955
 
1537
1956
  // src/persistent/cursor.ts
1538
1957
  import { createHash } from "crypto";
1539
- import { closeSync, openSync, readSync, statSync } from "fs";
1958
+ import { closeSync, openSync, readSync, statSync as statSync2 } from "fs";
1540
1959
  var FP_BYTES = 4096;
1541
1960
  function fingerprint(filePath, size) {
1542
1961
  const hash = createHash("sha1");
@@ -1560,46 +1979,46 @@ function fingerprint(filePath, size) {
1560
1979
  return hash.digest("hex");
1561
1980
  }
1562
1981
  function classify(filePath, existing) {
1563
- let stat4;
1982
+ let stat5;
1564
1983
  try {
1565
- const s = statSync(filePath);
1566
- stat4 = { size: s.size, mtimeMs: s.mtimeMs };
1984
+ const s = statSync2(filePath);
1985
+ stat5 = { size: s.size, mtimeMs: s.mtimeMs };
1567
1986
  } catch {
1568
1987
  return { change: "vanished" };
1569
1988
  }
1570
1989
  if (!existing || existing.status !== "active" || existing.last_indexed_offset === 0) {
1571
- return { change: "reindex", stat: stat4 };
1990
+ return { change: "reindex", stat: stat5 };
1572
1991
  }
1573
- if (stat4.size < existing.last_indexed_offset) {
1574
- return { change: "reindex", stat: stat4 };
1992
+ if (stat5.size < existing.last_indexed_offset) {
1993
+ return { change: "reindex", stat: stat5 };
1575
1994
  }
1576
- if (stat4.size === existing.size_bytes && stat4.mtimeMs === existing.mtime_ms) {
1577
- return { change: "unchanged", stat: stat4 };
1995
+ if (stat5.size === existing.size_bytes && stat5.mtimeMs === existing.mtime_ms) {
1996
+ return { change: "unchanged", stat: stat5 };
1578
1997
  }
1579
- if (stat4.size === existing.last_indexed_offset) {
1580
- const fp = fingerprint(filePath, stat4.size);
1998
+ if (stat5.size === existing.last_indexed_offset) {
1999
+ const fp = fingerprint(filePath, stat5.size);
1581
2000
  if (existing.content_fingerprint && fp !== existing.content_fingerprint) {
1582
- return { change: "reindex", stat: stat4 };
2001
+ return { change: "reindex", stat: stat5 };
1583
2002
  }
1584
- return { change: "unchanged", stat: stat4 };
2003
+ return { change: "unchanged", stat: stat5 };
1585
2004
  }
1586
2005
  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: stat4 };
2006
+ return { change: "appended", stat: stat5 };
1588
2007
  }
1589
- return { change: "reindex", stat: stat4 };
2008
+ return { change: "reindex", stat: stat5 };
1590
2009
  }
1591
2010
 
1592
2011
  // src/persistent/index-engine.ts
1593
- import { statSync as statSync2 } from "fs";
2012
+ import { statSync as statSync3 } from "fs";
1594
2013
 
1595
2014
  // src/providers/parse.ts
1596
- import { createReadStream as createReadStream5 } from "fs";
1597
- import { createInterface as createInterface3 } from "readline";
2015
+ import { createReadStream as createReadStream6 } from "fs";
2016
+ import { createInterface as createInterface4 } from "readline";
1598
2017
  async function parseMetaWithProvider(provider, filePath, account, tier, onEntry) {
1599
2018
  const log = getLogger();
1600
2019
  const acc = provider.createEmptyAccumulator();
1601
- const rl = createInterface3({
1602
- input: createReadStream5(filePath),
2020
+ const rl = createInterface4({
2021
+ input: createReadStream6(filePath),
1603
2022
  crlfDelay: Infinity
1604
2023
  });
1605
2024
  try {
@@ -1669,8 +2088,35 @@ function extractSearchDelta(entry) {
1669
2088
  if (entry.type === "response_item" || entry.type === "session_meta") {
1670
2089
  return extractCodexDelta(entry);
1671
2090
  }
2091
+ if (looksLikeCursorChatEntry(entry)) {
2092
+ return extractCursorDelta(entry);
2093
+ }
1672
2094
  return extractClaudeDelta(entry);
1673
2095
  }
2096
+ function extractCursorDelta(entry) {
2097
+ const msg = entry.message;
2098
+ const content = msg?.content ?? entry.content;
2099
+ return {
2100
+ text: extractCursorSearchText(content),
2101
+ thinking: "",
2102
+ tools: extractClaudeToolContent(content)
2103
+ };
2104
+ }
2105
+ function extractCursorSearchText(content) {
2106
+ if (typeof content === "string") return unwrapCursorUserText(content);
2107
+ if (!Array.isArray(content)) return "";
2108
+ const parts = [];
2109
+ for (const item of content) {
2110
+ if (typeof item === "string") {
2111
+ const cleaned = unwrapCursorUserText(item);
2112
+ if (cleaned) parts.push(cleaned);
2113
+ } else if ((item?.type === "text" || item?.type === void 0) && typeof item?.text === "string") {
2114
+ const cleaned = unwrapCursorUserText(item.text);
2115
+ if (cleaned) parts.push(cleaned);
2116
+ }
2117
+ }
2118
+ return parts.join(SEP);
2119
+ }
1674
2120
  function extractClaudeDelta(entry) {
1675
2121
  const type = entry.type;
1676
2122
  if (type !== "user" && type !== "assistant") return emptySearchDocument();
@@ -1788,10 +2234,10 @@ function resolveTier(tierName, customTiers) {
1788
2234
  // src/persistent/db.ts
1789
2235
  import Database from "better-sqlite3";
1790
2236
  import { mkdirSync } from "fs";
1791
- import { dirname as dirname3 } from "path";
2237
+ import { dirname as dirname4 } from "path";
1792
2238
 
1793
2239
  // src/persistent/schema.ts
1794
- var SCHEMA_VERSION = 7;
2240
+ var SCHEMA_VERSION = 9;
1795
2241
  var SCHEMA_SQL = `
1796
2242
  CREATE TABLE IF NOT EXISTS conversation_files (
1797
2243
  id INTEGER PRIMARY KEY AUTOINCREMENT,
@@ -1876,6 +2322,10 @@ CREATE TABLE IF NOT EXISTS conversations (
1876
2322
  tool_names_json TEXT,
1877
2323
  last_prompt TEXT,
1878
2324
 
2325
+ is_imported_from_claude INTEGER NOT NULL DEFAULT 0,
2326
+ is_imported_from_codex INTEGER NOT NULL DEFAULT 0,
2327
+ is_imported_from_cursor INTEGER NOT NULL DEFAULT 0,
2328
+
1879
2329
  status TEXT NOT NULL DEFAULT 'active',
1880
2330
 
1881
2331
  created_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP,
@@ -2041,6 +2491,45 @@ function runMigrations(db) {
2041
2491
  db.exec(`UPDATE conversation_files SET ${assignments.join(", ")}`);
2042
2492
  }
2043
2493
  }
2494
+ if (current >= 1 && current < 8 && tableExists(db, "conversations")) {
2495
+ for (const [col, ddl] of [
2496
+ [
2497
+ "is_imported_from_claude",
2498
+ "ALTER TABLE conversations ADD COLUMN is_imported_from_claude INTEGER NOT NULL DEFAULT 0"
2499
+ ],
2500
+ [
2501
+ "is_imported_from_codex",
2502
+ "ALTER TABLE conversations ADD COLUMN is_imported_from_codex INTEGER NOT NULL DEFAULT 0"
2503
+ ],
2504
+ [
2505
+ "is_imported_from_cursor",
2506
+ "ALTER TABLE conversations ADD COLUMN is_imported_from_cursor INTEGER NOT NULL DEFAULT 0"
2507
+ ]
2508
+ ]) {
2509
+ if (!hasColumn(db, "conversations", col)) db.exec(ddl);
2510
+ }
2511
+ if (tableExists(db, "conversation_files")) {
2512
+ const assignments = [];
2513
+ if (hasColumn(db, "conversation_files", "last_indexed_offset")) {
2514
+ assignments.push("last_indexed_offset = 0");
2515
+ }
2516
+ if (hasColumn(db, "conversation_files", "last_indexed_line")) {
2517
+ assignments.push("last_indexed_line = 0");
2518
+ }
2519
+ if (hasColumn(db, "conversation_files", "reducer_state")) {
2520
+ assignments.push("reducer_state = NULL");
2521
+ }
2522
+ if (assignments.length > 0) {
2523
+ db.exec(
2524
+ `UPDATE conversation_files SET ${assignments.join(", ")}
2525
+ WHERE id IN (SELECT file_id FROM conversations WHERE provider IN ('cursor', 'cursor-cli'))`
2526
+ );
2527
+ }
2528
+ }
2529
+ }
2530
+ if (current >= 1 && current < 9 && tableExists(db, "conversations")) {
2531
+ db.exec(`UPDATE conversations SET provider = 'cursor' WHERE provider = 'cursor-cli'`);
2532
+ }
2044
2533
  db.exec(SCHEMA_SQL);
2045
2534
  db.pragma(`user_version = ${SCHEMA_VERSION}`);
2046
2535
  }
@@ -2055,7 +2544,7 @@ function hasColumn(db, table, column) {
2055
2544
  // src/persistent/db.ts
2056
2545
  function openDatabase(dbPath) {
2057
2546
  if (dbPath !== ":memory:") {
2058
- mkdirSync(dirname3(dbPath), { recursive: true });
2547
+ mkdirSync(dirname4(dbPath), { recursive: true });
2059
2548
  }
2060
2549
  let db;
2061
2550
  try {
@@ -2099,8 +2588,8 @@ function nativeBindingError(err, dbPath) {
2099
2588
  }
2100
2589
 
2101
2590
  // src/persistent/dir-watermark.ts
2102
- import { readdir, stat as stat3 } from "fs/promises";
2103
- import { dirname as dirname4, join as join4 } from "path";
2591
+ import { readdir, stat as stat4 } from "fs/promises";
2592
+ import { dirname as dirname5, join as join5 } from "path";
2104
2593
  var FULL_RECONCILE_EVERY_N_SCANS = 20;
2105
2594
  async function discoverJsonlFilesGated(dirs, files, scannedDirs, options = {}) {
2106
2595
  const log = getLogger();
@@ -2116,7 +2605,7 @@ async function discoverJsonlFilesGated(dirs, files, scannedDirs, options = {}) {
2116
2605
  for (const projectDir of resolved.entries) {
2117
2606
  let dirStat;
2118
2607
  try {
2119
- dirStat = await stat3(projectDir);
2608
+ dirStat = await stat4(projectDir);
2120
2609
  } catch {
2121
2610
  scannedDirs.remove(projectDir);
2122
2611
  continue;
@@ -2154,7 +2643,7 @@ async function discoverJsonlFilesGated(dirs, files, scannedDirs, options = {}) {
2154
2643
  async function resolveProjectDirs(projectsDir, scannedDirs) {
2155
2644
  let rootStat;
2156
2645
  try {
2157
- rootStat = await stat3(projectsDir);
2646
+ rootStat = await stat4(projectsDir);
2158
2647
  } catch {
2159
2648
  return null;
2160
2649
  }
@@ -2171,10 +2660,10 @@ async function resolveProjectDirs(projectsDir, scannedDirs) {
2171
2660
  return { entries, commitRoot: { mtimeMs: rootStat.mtimeMs } };
2172
2661
  }
2173
2662
  function dirnameOf(filePath) {
2174
- return dirname4(filePath);
2663
+ return dirname5(filePath);
2175
2664
  }
2176
2665
  function joinPath(dir, name) {
2177
- return join4(dir, name);
2666
+ return join5(dir, name);
2178
2667
  }
2179
2668
 
2180
2669
  // src/persistent/repositories/checkpoints.repo.ts
@@ -2254,7 +2743,7 @@ function toCheckpoint(row) {
2254
2743
  }
2255
2744
 
2256
2745
  // src/persistent/repositories/conversation-files.repo.ts
2257
- import { basename as basename5, dirname as dirname5 } from "path";
2746
+ import { basename as basename6, dirname as dirname6 } from "path";
2258
2747
  var ConversationFilesRepo = class {
2259
2748
  constructor(db) {
2260
2749
  this.db = db;
@@ -2277,7 +2766,7 @@ var ConversationFilesRepo = class {
2277
2766
  const info = this.db.prepare(
2278
2767
  `INSERT INTO conversation_files (absolute_path, parent_dir, file_name, account)
2279
2768
  VALUES (?, ?, ?, ?)`
2280
- ).run(canonical, dirname5(canonical), basename5(canonical), account);
2769
+ ).run(canonical, dirname6(canonical), basename6(canonical), account);
2281
2770
  return Number(info.lastInsertRowid);
2282
2771
  }
2283
2772
  // Advance the cursor + persisted reducer state after a successful index pass.
@@ -2372,7 +2861,10 @@ function rowToMeta(row) {
2372
2861
  toolNames: row.tool_names_json ? JSON.parse(row.tool_names_json) : [],
2373
2862
  firstMessage: row.first_sent_text ? { text: row.first_sent_text, timestamp: row.first_sent_at ?? "" } : null,
2374
2863
  lastMessage: row.last_sent_text ? { text: row.last_sent_text, timestamp: row.last_sent_at ?? "" } : null,
2375
- lastPrompt: row.last_prompt ?? void 0
2864
+ lastPrompt: row.last_prompt ?? void 0,
2865
+ ...row.is_imported_from_claude === 1 ? { isImportedFromClaude: true } : {},
2866
+ ...row.is_imported_from_codex === 1 ? { isImportedFromCodex: true } : {},
2867
+ ...row.is_imported_from_cursor === 1 ? { isImportedFromCursor: true } : {}
2376
2868
  };
2377
2869
  }
2378
2870
  var ConversationsRepo = class {
@@ -2392,7 +2884,8 @@ var ConversationsRepo = class {
2392
2884
  timestamp, index_seq, first_sent_at, first_sent_text, last_sent_at, last_sent_text,
2393
2885
  model, is_subagent, parent_session_id, subagent_id, parent_session_uuid,
2394
2886
  is_teammate, team_name, tool_names_json,
2395
- last_prompt, status, updated_at
2887
+ last_prompt, is_imported_from_claude, is_imported_from_codex,
2888
+ is_imported_from_cursor, status, updated_at
2396
2889
  ) VALUES (
2397
2890
  @file_id, @source_path, @provider, @kind, @external_session_id,
2398
2891
  @session_id, @session_name, @project_path, @project_name,
@@ -2403,7 +2896,8 @@ var ConversationsRepo = class {
2403
2896
  @first_sent_at, @first_sent_text, @last_sent_at, @last_sent_text,
2404
2897
  @model, @is_subagent, @parent_session_id, @subagent_id, @parent_session_uuid,
2405
2898
  @is_teammate, @team_name, @tool_names_json,
2406
- @last_prompt, 'active', CURRENT_TIMESTAMP
2899
+ @last_prompt, @is_imported_from_claude, @is_imported_from_codex,
2900
+ @is_imported_from_cursor, 'active', CURRENT_TIMESTAMP
2407
2901
  )
2408
2902
  ON CONFLICT(file_id) DO UPDATE SET
2409
2903
  source_path = excluded.source_path,
@@ -2435,6 +2929,9 @@ var ConversationsRepo = class {
2435
2929
  team_name = excluded.team_name,
2436
2930
  tool_names_json = excluded.tool_names_json,
2437
2931
  last_prompt = excluded.last_prompt,
2932
+ is_imported_from_claude = excluded.is_imported_from_claude,
2933
+ is_imported_from_codex = excluded.is_imported_from_codex,
2934
+ is_imported_from_cursor = excluded.is_imported_from_cursor,
2438
2935
  status = 'active',
2439
2936
  index_seq = (SELECT COALESCE(MAX(index_seq), 0) + 1 FROM conversations),
2440
2937
  updated_at = CURRENT_TIMESTAMP`
@@ -2471,7 +2968,10 @@ var ConversationsRepo = class {
2471
2968
  is_teammate: meta.isTeammate ? 1 : 0,
2472
2969
  team_name: meta.teamName,
2473
2970
  tool_names_json: JSON.stringify(meta.toolNames),
2474
- last_prompt: meta.lastPrompt ?? null
2971
+ last_prompt: meta.lastPrompt ?? null,
2972
+ is_imported_from_claude: meta.isImportedFromClaude ? 1 : 0,
2973
+ is_imported_from_codex: meta.isImportedFromCodex ? 1 : 0,
2974
+ is_imported_from_cursor: meta.isImportedFromCursor ? 1 : 0
2475
2975
  });
2476
2976
  }
2477
2977
  getBySourcePath(sourcePath) {
@@ -2631,8 +3131,14 @@ var FtsRepo = class {
2631
3131
  params.push(filters.account);
2632
3132
  }
2633
3133
  if (filters.provider) {
2634
- where.push("c.provider = ?");
2635
- params.push(filters.provider);
3134
+ const provider = canonicalizeProviderName(filters.provider) ?? filters.provider;
3135
+ if (provider === CURSOR_PROVIDER) {
3136
+ where.push("(c.provider = ? OR c.provider = ?)");
3137
+ params.push(CURSOR_PROVIDER, LEGACY_CURSOR_PROVIDER);
3138
+ } else {
3139
+ where.push("c.provider = ?");
3140
+ params.push(provider);
3141
+ }
2636
3142
  }
2637
3143
  if (filters.project) {
2638
3144
  where.push("(lower(c.project_path) LIKE ? OR lower(c.project_name) LIKE ?)");
@@ -2751,7 +3257,7 @@ var PersistentEngine = class {
2751
3257
  async indexAll(activeProfiles, options) {
2752
3258
  const log = getLogger();
2753
3259
  const tier = resolveTier(options.tier ?? "standard", options.tiers);
2754
- const enabled = options.providers ?? [CLAUDE_CODE_PROVIDER];
3260
+ const enabled = canonicalizeProviderList(options.providers);
2755
3261
  const discovered = [];
2756
3262
  if (enabled.includes(CLAUDE_CODE_PROVIDER)) {
2757
3263
  const configDirs = activeProfiles.map((p) => ({
@@ -2771,6 +3277,12 @@ var PersistentEngine = class {
2771
3277
  discovered.push({ ...f, provider: codex });
2772
3278
  }
2773
3279
  }
3280
+ const cursor = new CursorProvider();
3281
+ if (enabled.includes(CURSOR_PROVIDER) && (options.cursorRoots?.length ?? 0) > 0) {
3282
+ for (const f of await cursor.discover(options.cursorRoots)) {
3283
+ discovered.push({ ...f, provider: cursor });
3284
+ }
3285
+ }
2774
3286
  let scanned = 0;
2775
3287
  const gitBranchMemo = /* @__PURE__ */ new Map();
2776
3288
  const resolveGitBranch = (projectPath) => {
@@ -2809,6 +3321,9 @@ var PersistentEngine = class {
2809
3321
  if (enabled.includes(CODEX_CLI_PROVIDER) && (options.codexRoots?.length ?? 0) > 0) {
2810
3322
  coveredAccounts.add("codex");
2811
3323
  }
3324
+ if (enabled.includes(CURSOR_PROVIDER) && (options.cursorRoots?.length ?? 0) > 0) {
3325
+ coveredAccounts.add("cursor");
3326
+ }
2812
3327
  const seen = new Set(discovered.map((d) => canonicalPath(d.filePath)));
2813
3328
  for (const path of this.files.activePathsByAccounts([...coveredAccounts])) {
2814
3329
  if (!seen.has(path)) this.markDeleted(path);
@@ -2828,8 +3343,8 @@ var PersistentEngine = class {
2828
3343
  const tier = resolveTier(tierName, customTiers);
2829
3344
  const filePath = canonicalPath(rawFilePath);
2830
3345
  const existing = this.files.getByPath(filePath);
2831
- const { change, stat: stat4 } = classify(filePath, existing);
2832
- if (change === "vanished" || !stat4) {
3346
+ const { change, stat: stat5 } = classify(filePath, existing);
3347
+ if (change === "vanished" || !stat5) {
2833
3348
  this.markDeleted(filePath);
2834
3349
  return { meta: null, change: "vanished" };
2835
3350
  }
@@ -2842,7 +3357,7 @@ var PersistentEngine = class {
2842
3357
  filePath,
2843
3358
  account,
2844
3359
  tier,
2845
- stat4,
3360
+ stat5,
2846
3361
  resolveGitBranch
2847
3362
  );
2848
3363
  return { meta: meta2, change };
@@ -2868,7 +3383,7 @@ var PersistentEngine = class {
2868
3383
  return { meta: null, change };
2869
3384
  }
2870
3385
  meta.gitBranch = resolveGitBranch(meta.projectPath);
2871
- const fp = stat4.size > 0 ? fingerprint(filePath, stat4.size) : null;
3386
+ const fp = stat5.size > 0 ? fingerprint(filePath, stat5.size) : null;
2872
3387
  const fileId = this.files.ensure(filePath, account);
2873
3388
  const base = resume ? this.fts.readDocument(fileId) ?? emptySearchDocument() : emptySearchDocument();
2874
3389
  const searchDoc = appendSearchDelta(base, searchDelta);
@@ -2879,8 +3394,8 @@ var PersistentEngine = class {
2879
3394
  }
2880
3395
  if (!resume) this.checkpoints.remove(filePath);
2881
3396
  this.files.updateCursor(fileId, {
2882
- sizeBytes: stat4.size,
2883
- mtimeMs: stat4.mtimeMs,
3397
+ sizeBytes: stat5.size,
3398
+ mtimeMs: stat5.mtimeMs,
2884
3399
  // Advance only to the last fully-parsed line; a trailing partial line
2885
3400
  // is left for the next pass.
2886
3401
  offset: result.newOffset,
@@ -2897,8 +3412,8 @@ var PersistentEngine = class {
2897
3412
  buildSidecar(
2898
3413
  meta,
2899
3414
  {
2900
- sizeBytes: stat4.size,
2901
- mtimeMs: stat4.mtimeMs,
3415
+ sizeBytes: stat5.size,
3416
+ mtimeMs: stat5.mtimeMs,
2902
3417
  offset: result.newOffset,
2903
3418
  line: result.newLine
2904
3419
  },
@@ -2917,7 +3432,7 @@ var PersistentEngine = class {
2917
3432
  // the Threadbase path uses. The cursor records size/mtime (and offset = size)
2918
3433
  // so the next pass classifies an unchanged file as "unchanged" and skips it;
2919
3434
  // any change reparses from 0 again. No reducer_state is persisted.
2920
- async indexFileWithProvider(provider, filePath, account, tier, stat4, resolveGitBranch) {
3435
+ async indexFileWithProvider(provider, filePath, account, tier, stat5, resolveGitBranch) {
2921
3436
  const log = getLogger();
2922
3437
  let searchDoc = emptySearchDocument();
2923
3438
  const meta = await parseMetaWithProvider(provider, filePath, account, tier, (entry) => {
@@ -2930,7 +3445,7 @@ var PersistentEngine = class {
2930
3445
  if (meta.gitBranch === null && meta.projectPath) {
2931
3446
  meta.gitBranch = resolveGitBranch(meta.projectPath);
2932
3447
  }
2933
- const fp = stat4.size > 0 ? fingerprint(filePath, stat4.size) : null;
3448
+ const fp = stat5.size > 0 ? fingerprint(filePath, stat5.size) : null;
2934
3449
  const fileId = this.files.ensure(filePath, account);
2935
3450
  const upsert = this.db.transaction(() => {
2936
3451
  this.conversations.upsert(fileId, meta, meta.messageCount);
@@ -2939,11 +3454,11 @@ var PersistentEngine = class {
2939
3454
  }
2940
3455
  this.checkpoints.remove(filePath);
2941
3456
  this.files.updateCursor(fileId, {
2942
- sizeBytes: stat4.size,
2943
- mtimeMs: stat4.mtimeMs,
3457
+ sizeBytes: stat5.size,
3458
+ mtimeMs: stat5.mtimeMs,
2944
3459
  // offset = size marks the file fully consumed (non-zero so the next pass
2945
3460
  // can classify it "unchanged"); no resumable reducer state is kept.
2946
- offset: stat4.size,
3461
+ offset: stat5.size,
2947
3462
  line: 0,
2948
3463
  reducerState: null,
2949
3464
  fingerprint: fp,
@@ -3009,8 +3524,8 @@ var PersistentEngine = class {
3009
3524
  const meta = this.conversations.getByIdOrSession(id);
3010
3525
  if (!meta) return null;
3011
3526
  const filePath = meta.filePath;
3012
- if (meta.provider === CODEX_CLI_PROVIDER) {
3013
- const conversation = await parseCodexConversation(filePath, meta.account);
3527
+ if (meta.provider === CODEX_CLI_PROVIDER || meta.provider === CURSOR_PROVIDER) {
3528
+ const conversation = meta.provider === CODEX_CLI_PROVIDER ? await parseCodexConversation(filePath, meta.account) : await parseCursorConversation(filePath, meta.account);
3014
3529
  if (!conversation) return null;
3015
3530
  const { messages } = conversation;
3016
3531
  const total2 = messages.length;
@@ -3025,7 +3540,7 @@ var PersistentEngine = class {
3025
3540
  let floor = this.checkpoints.floor(filePath, fromIndex);
3026
3541
  if (floor) {
3027
3542
  try {
3028
- if (floor.byteOffset > statSync2(filePath).size) floor = null;
3543
+ if (floor.byteOffset > statSync3(filePath).size) floor = null;
3029
3544
  } catch {
3030
3545
  }
3031
3546
  }
@@ -3164,7 +3679,7 @@ function defaultDbPath() {
3164
3679
  "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
3680
  );
3166
3681
  }
3167
- return join5(homedir2(), ".config", "threadbase-scanner", "index.db");
3682
+ return join6(homedir2(), ".config", "threadbase-scanner", "index.db");
3168
3683
  }
3169
3684
  function capForMemory(doc, max) {
3170
3685
  const combined = combineSearchContent(doc);
@@ -3343,7 +3858,7 @@ var ConversationScanner = class {
3343
3858
  const cached = statCache.get(filePath);
3344
3859
  if (cached) {
3345
3860
  try {
3346
- const s = statSync3(filePath);
3861
+ const s = statSync4(filePath);
3347
3862
  if (s.mtimeMs === cached.stat.mtimeMs && s.size === cached.stat.size) {
3348
3863
  return {
3349
3864
  meta: cached.meta,
@@ -3474,9 +3989,7 @@ var ConversationScanner = class {
3474
3989
  results = results.filter((r) => r.meta.account === options.account);
3475
3990
  }
3476
3991
  if (options.provider) {
3477
- results = results.filter(
3478
- (r) => (r.meta.provider ?? CLAUDE_CODE_PROVIDER) === options.provider
3479
- );
3992
+ results = results.filter((r) => providerMatches(r.meta.provider, options.provider));
3480
3993
  }
3481
3994
  if (options.since) {
3482
3995
  const cutoff = parseSinceCutoff(options.since);
@@ -3503,12 +4016,12 @@ var ConversationScanner = class {
3503
4016
  }
3504
4017
  log.debug({ id, filePath: meta.filePath }, "getConversation: cache miss, parsing");
3505
4018
  try {
3506
- if (this.persistent && meta.provider !== CODEX_CLI_PROVIDER) {
4019
+ if (this.persistent && meta.provider !== CODEX_CLI_PROVIDER && meta.provider !== CURSOR_PROVIDER) {
3507
4020
  const parsed = await parseConversationResumable(meta.filePath, meta.account);
3508
4021
  if (parsed) this.conversationLRU.set(cid, parsed);
3509
4022
  return parsed?.conversation ?? null;
3510
4023
  }
3511
- const conversation = meta.provider === CODEX_CLI_PROVIDER ? await parseCodexConversation(meta.filePath, meta.account) : await parseConversation(meta.filePath, meta.account);
4024
+ 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
4025
  if (conversation) {
3513
4026
  this.conversationLRU.set(cid, { conversation });
3514
4027
  }
@@ -3562,7 +4075,7 @@ var ConversationScanner = class {
3562
4075
  // fallback, matching refreshFile.
3563
4076
  async parseSingleFilePage(filePath, account, options) {
3564
4077
  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");
4078
+ 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
4079
  if (!conversation) return null;
3567
4080
  const { messages } = conversation;
3568
4081
  const total = messages.length;
@@ -3851,7 +4364,7 @@ var ConversationScanner = class {
3851
4364
  // discovers under the active profiles' project dirs; Codex discovers under
3852
4365
  // the explicit codexRoots (opt-in — no default home scan).
3853
4366
  async discoverWithProviders(activeProfiles, options) {
3854
- const enabled = options.providers ?? [CLAUDE_CODE_PROVIDER];
4367
+ const enabled = canonicalizeProviderList(options.providers);
3855
4368
  const work = [];
3856
4369
  if (enabled.includes(CLAUDE_CODE_PROVIDER)) {
3857
4370
  const provider = new ThreadbaseProvider();
@@ -3866,6 +4379,12 @@ var ConversationScanner = class {
3866
4379
  work.push({ ...f, provider });
3867
4380
  }
3868
4381
  }
4382
+ if (enabled.includes(CURSOR_PROVIDER) && (options.cursorRoots?.length ?? 0) > 0) {
4383
+ const provider = new CursorProvider();
4384
+ for (const f of await provider.discover(options.cursorRoots)) {
4385
+ work.push({ ...f, provider });
4386
+ }
4387
+ }
3869
4388
  return work;
3870
4389
  }
3871
4390
  // Resolve which provider should (re)parse a file. Stored metadata wins; for a
@@ -3874,6 +4393,9 @@ var ConversationScanner = class {
3874
4393
  // tail-read path).
3875
4394
  async resolveProviderForFile(filePath, previous) {
3876
4395
  if (previous?.provider === CODEX_CLI_PROVIDER) return new CodexCliProvider();
4396
+ if (providerMatches(previous?.provider, CURSOR_PROVIDER)) {
4397
+ return new CursorProvider();
4398
+ }
3877
4399
  if (previous?.provider) return void 0;
3878
4400
  let sample = "";
3879
4401
  try {
@@ -3888,6 +4410,8 @@ var ConversationScanner = class {
3888
4410
  } catch {
3889
4411
  return void 0;
3890
4412
  }
4413
+ const cursor = new CursorProvider();
4414
+ if (cursor.canParse(filePath, sample)) return cursor;
3891
4415
  const codex = new CodexCliProvider();
3892
4416
  if (codex.canParse(filePath, sample)) return codex;
3893
4417
  return void 0;
@@ -3996,9 +4520,14 @@ async function getConversation(id, options, scanner) {
3996
4520
  return (scanner ?? getDefaultScanner()).getConversation(id, options);
3997
4521
  }
3998
4522
  export {
4523
+ CLAUDE_CODE_PROVIDER,
4524
+ CODEX_CLI_PROVIDER,
4525
+ CURSOR_PROVIDER,
3999
4526
  CodexCliProvider,
4000
4527
  ConversationScanner,
4528
+ CursorProvider,
4001
4529
  DEFAULT_TIERS,
4530
+ LEGACY_CURSOR_PROVIDER,
4002
4531
  SearchIndexer,
4003
4532
  ThreadbaseProvider,
4004
4533
  VALID_SORT_ORDERS,
@@ -4008,6 +4537,8 @@ export {
4008
4537
  applyProjectFilter,
4009
4538
  applySinceFilter,
4010
4539
  applySort,
4540
+ canonicalizeProviderList,
4541
+ canonicalizeProviderName,
4011
4542
  cleanSystemTags,
4012
4543
  initialConvState as createJsonlParseState,
4013
4544
  createLogger,
@@ -4018,7 +4549,9 @@ export {
4018
4549
  isCodexInjectedContext,
4019
4550
  loadProfiles,
4020
4551
  parseCodexJsonlLine,
4552
+ parseCursorJsonlLine,
4021
4553
  parseJsonlLine,
4554
+ providerMatches,
4022
4555
  readGitBranch,
4023
4556
  readSidecar,
4024
4557
  resetDefaultScanner,
@@ -4028,6 +4561,7 @@ export {
4028
4561
  scan,
4029
4562
  search,
4030
4563
  setLogger,
4031
- sidecarPath
4564
+ sidecarPath,
4565
+ unwrapCursorUserText
4032
4566
  };
4033
4567
  //# sourceMappingURL=index.js.map