@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.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() {
@@ -1254,9 +1287,405 @@ async function parseCodexConversation(filePath, account) {
1254
1287
  };
1255
1288
  }
1256
1289
 
1257
- // src/discovery.ts
1290
+ // src/providers/cursor.ts
1258
1291
  var import_fast_glob2 = __toESM(require("fast-glob"), 1);
1292
+ var import_fs5 = require("fs");
1259
1293
  var import_promises3 = require("fs/promises");
1294
+ var import_path7 = require("path");
1295
+ var import_readline3 = require("readline");
1296
+ var TIMESTAMP_RE = /<timestamp>\s*([\s\S]*?)\s*<\/timestamp>/;
1297
+ var USER_QUERY_RE = /<user_query>\s*([\s\S]*?)\s*<\/user_query>/;
1298
+ var SUBAGENT_PATH_RE2 = /[\\/]subagents[\\/]/;
1299
+ var CursorProvider = class {
1300
+ name = CURSOR_PROVIDER;
1301
+ async discover(roots) {
1302
+ const log = getLogger();
1303
+ const results = [];
1304
+ for (const root of roots) {
1305
+ let paths;
1306
+ try {
1307
+ paths = await (0, import_fast_glob2.default)(["**/agent-transcripts/**/*.jsonl"], {
1308
+ cwd: root,
1309
+ absolute: true,
1310
+ dot: false,
1311
+ unique: true
1312
+ });
1313
+ } catch (err) {
1314
+ log.warn({ root, err }, "cursor discovery: glob failed");
1315
+ continue;
1316
+ }
1317
+ for (const filePath of paths) {
1318
+ try {
1319
+ const s = await (0, import_promises3.stat)(filePath);
1320
+ if (s.size > 0) results.push({ filePath: canonicalPath(filePath), account: "cursor" });
1321
+ } catch (err) {
1322
+ log.warn({ filePath, err }, "cursor discovery: stat failed");
1323
+ }
1324
+ }
1325
+ }
1326
+ return results;
1327
+ }
1328
+ canParse(filePath, sample) {
1329
+ const underTranscripts = /[\\/]agent-transcripts[\\/]/.test(filePath);
1330
+ for (const line of sample.split("\n")) {
1331
+ if (!line.trim()) continue;
1332
+ try {
1333
+ const e = JSON.parse(line);
1334
+ if (looksLikeImportedCodexEntry(e) || looksLikeImportedClaudeEntry(e)) {
1335
+ return underTranscripts;
1336
+ }
1337
+ if (looksLikeCursorChatEntry(e)) return true;
1338
+ } catch {
1339
+ }
1340
+ }
1341
+ return false;
1342
+ }
1343
+ createEmptyAccumulator() {
1344
+ return {
1345
+ sessionId: "",
1346
+ latestTimestamp: "",
1347
+ messageCount: 0,
1348
+ lastMessageSender: "user",
1349
+ isSubagent: false,
1350
+ parentSessionUuid: null,
1351
+ subagentId: null,
1352
+ firstUser: null,
1353
+ lastUser: null,
1354
+ lastAssistant: null,
1355
+ isImportedFromClaude: false,
1356
+ isImportedFromCodex: false,
1357
+ toolNames: [],
1358
+ previewParts: [],
1359
+ previewLength: 0,
1360
+ snippetParts: [],
1361
+ snippetLength: 0
1362
+ };
1363
+ }
1364
+ reduceEntry(acc, entry, tier) {
1365
+ reduceCursorEntry(acc, entry, tier);
1366
+ }
1367
+ finalize(acc, filePath, account, tier) {
1368
+ return finalizeCursorMeta(acc, filePath, account, tier);
1369
+ }
1370
+ };
1371
+ function looksLikeCursorChatEntry(entry) {
1372
+ const role = entry.role;
1373
+ if (role !== "user" && role !== "assistant") return false;
1374
+ if (entry.type === "user" || entry.type === "assistant") return false;
1375
+ return true;
1376
+ }
1377
+ function looksLikeImportedClaudeEntry(entry) {
1378
+ return entry.type === "user" || entry.type === "assistant";
1379
+ }
1380
+ function looksLikeImportedCodexEntry(entry) {
1381
+ return entry.type === "session_meta" || entry.type === "response_item" || entry.type === "event_msg";
1382
+ }
1383
+ function asString2(value) {
1384
+ return typeof value === "string" ? value : "";
1385
+ }
1386
+ function provenanceToken(value) {
1387
+ if (typeof value === "string") return value.trim().toLowerCase();
1388
+ if (value && typeof value === "object") {
1389
+ const rec = value;
1390
+ return provenanceToken(
1391
+ rec.importedFrom ?? rec.imported_from ?? rec.sourceProvider ?? rec.source
1392
+ );
1393
+ }
1394
+ return "";
1395
+ }
1396
+ function importedFromClaudeToken(token) {
1397
+ return token === "claude" || token === "claude-code" || token === "claude_code" || token === "anthropic";
1398
+ }
1399
+ function importedFromCodexToken(token) {
1400
+ return token === "codex" || token === "codex-cli" || token === "codex_cli" || token === "openai-codex";
1401
+ }
1402
+ function noteImportProvenance(acc, entry, text) {
1403
+ const token = provenanceToken(
1404
+ entry.importedFrom ?? entry.imported_from ?? entry.sourceProvider ?? entry.source ?? (entry.message && typeof entry.message === "object" ? entry.message.importedFrom ?? entry.message.imported_from ?? entry.message.sourceProvider : void 0)
1405
+ );
1406
+ if (importedFromClaudeToken(token) || looksLikeImportedClaudeEntry(entry)) {
1407
+ acc.isImportedFromClaude = true;
1408
+ }
1409
+ if (importedFromCodexToken(token) || looksLikeImportedCodexEntry(entry)) {
1410
+ acc.isImportedFromCodex = true;
1411
+ }
1412
+ if (/imported from claude/i.test(text) || /<imported_from_claude>/i.test(text)) {
1413
+ acc.isImportedFromClaude = true;
1414
+ }
1415
+ if (/imported from codex/i.test(text) || /<imported_from_codex>/i.test(text)) {
1416
+ acc.isImportedFromCodex = true;
1417
+ }
1418
+ }
1419
+ function unwrapCursorUserText(text) {
1420
+ const query = text.match(USER_QUERY_RE);
1421
+ const body = query ? query[1] : text.replace(TIMESTAMP_RE, "");
1422
+ return cleanSystemTags(body);
1423
+ }
1424
+ function timestampFromCursorUserText(text) {
1425
+ const match = text.match(TIMESTAMP_RE);
1426
+ if (!match) return "";
1427
+ const parsed = Date.parse(match[1].trim());
1428
+ return Number.isNaN(parsed) ? "" : new Date(parsed).toISOString();
1429
+ }
1430
+ function extractCursorText(content) {
1431
+ if (typeof content === "string") return unwrapCursorUserText(content);
1432
+ if (!Array.isArray(content)) return "";
1433
+ return content.map((item) => {
1434
+ if (typeof item === "string") return unwrapCursorUserText(item);
1435
+ const block = item;
1436
+ if ((block?.type === "text" || block?.type === void 0) && typeof block.text === "string") {
1437
+ return unwrapCursorUserText(block.text);
1438
+ }
1439
+ return "";
1440
+ }).filter(Boolean).join(" ");
1441
+ }
1442
+ function collectCursorToolNames(content, into) {
1443
+ if (!Array.isArray(content)) return;
1444
+ for (const item of content) {
1445
+ const block = item;
1446
+ if (block?.type === "tool_use" && typeof block.name === "string" && block.name) {
1447
+ if (!into.includes(block.name)) into.push(block.name);
1448
+ }
1449
+ }
1450
+ }
1451
+ function firstTimestampHint(content) {
1452
+ if (typeof content === "string") return timestampFromCursorUserText(content);
1453
+ if (!Array.isArray(content)) return "";
1454
+ for (const item of content) {
1455
+ if (typeof item === "string") {
1456
+ const ts = timestampFromCursorUserText(item);
1457
+ if (ts) return ts;
1458
+ } else if (typeof item?.text === "string") {
1459
+ const ts = timestampFromCursorUserText(item.text);
1460
+ if (ts) return ts;
1461
+ }
1462
+ }
1463
+ return "";
1464
+ }
1465
+ function parseCursorJsonlLine(line) {
1466
+ if (!line.trim()) return null;
1467
+ let entry;
1468
+ try {
1469
+ entry = JSON.parse(line);
1470
+ } catch {
1471
+ return null;
1472
+ }
1473
+ return cursorEntryToMessage(entry);
1474
+ }
1475
+ function cursorEntryToMessage(entry) {
1476
+ if (looksLikeCursorChatEntry(entry)) {
1477
+ const role = entry.role;
1478
+ const message = entry.message;
1479
+ const text = extractCursorText(message?.content ?? entry.content);
1480
+ if (!text) return null;
1481
+ const ts = firstTimestampHint(message?.content ?? entry.content);
1482
+ return { role, text, timestamp: ts };
1483
+ }
1484
+ if (looksLikeImportedClaudeEntry(entry)) {
1485
+ const message = entry.message;
1486
+ const role = message?.role === "assistant" || entry.type === "assistant" ? "assistant" : "user";
1487
+ const text = extractCursorText(message?.content ?? entry.content);
1488
+ if (!text) return null;
1489
+ const ts = asString2(entry.timestamp);
1490
+ return { role, text, timestamp: ts };
1491
+ }
1492
+ return parseCodexJsonlLine(JSON.stringify(entry));
1493
+ }
1494
+ function foldCursorMessage(acc, role, text, timestamp, tier) {
1495
+ if (timestamp && (!acc.latestTimestamp || timestamp > acc.latestTimestamp)) {
1496
+ acc.latestTimestamp = timestamp;
1497
+ }
1498
+ acc.messageCount++;
1499
+ acc.lastMessageSender = role;
1500
+ const snapshot = { text: text.slice(0, 200), timestamp };
1501
+ if (role === "user") {
1502
+ if (!acc.firstUser) acc.firstUser = snapshot;
1503
+ acc.lastUser = snapshot;
1504
+ } else {
1505
+ acc.lastAssistant = snapshot;
1506
+ }
1507
+ if (acc.previewLength < tier.previewMax) {
1508
+ acc.previewParts.push(text);
1509
+ acc.previewLength += text.length;
1510
+ }
1511
+ if (acc.snippetLength < tier.snippetMax) {
1512
+ const remaining = tier.snippetMax - acc.snippetLength;
1513
+ const chunk = text.length > remaining ? text.slice(0, remaining) : text;
1514
+ acc.snippetParts.push(chunk);
1515
+ acc.snippetLength += chunk.length;
1516
+ }
1517
+ }
1518
+ function reduceCursorEntry(acc, entry, tier) {
1519
+ const message = entry.message;
1520
+ const content = message?.content ?? entry.content;
1521
+ const textHint = extractCursorText(content);
1522
+ noteImportProvenance(acc, entry, textHint);
1523
+ if (looksLikeCursorChatEntry(entry)) {
1524
+ collectCursorToolNames(content, acc.toolNames);
1525
+ const text = textHint;
1526
+ if (!text) return;
1527
+ foldCursorMessage(acc, entry.role, text, firstTimestampHint(content), tier);
1528
+ return;
1529
+ }
1530
+ if (looksLikeImportedClaudeEntry(entry)) {
1531
+ collectCursorToolNames(content, acc.toolNames);
1532
+ const msg = cursorEntryToMessage(entry);
1533
+ if (!msg) return;
1534
+ foldCursorMessage(acc, msg.role, msg.text, msg.timestamp, tier);
1535
+ return;
1536
+ }
1537
+ if (looksLikeImportedCodexEntry(entry)) {
1538
+ const msg = parseCodexJsonlLine(JSON.stringify(entry));
1539
+ if (!msg) return;
1540
+ foldCursorMessage(acc, msg.role, msg.text, msg.timestamp, tier);
1541
+ }
1542
+ }
1543
+ function finalizeCursorMeta(acc, filePath, account, tier) {
1544
+ if (acc.messageCount === 0) return null;
1545
+ const sessionId = (0, import_path7.basename)(filePath, ".jsonl");
1546
+ const isSubagent = SUBAGENT_PATH_RE2.test(filePath);
1547
+ const parent = isSubagent ? parentFromSubagentPath(filePath) : null;
1548
+ const { projectPath, projectName } = projectFromCursorPath(filePath);
1549
+ const timestamp = acc.latestTimestamp || fileMtimeIso(filePath);
1550
+ const kind = acc.lastAssistant === null && acc.toolNames.length > 0 ? "task" : "conversation";
1551
+ return {
1552
+ id: filePath,
1553
+ filePath,
1554
+ provider: CURSOR_PROVIDER,
1555
+ kind,
1556
+ externalSessionId: sessionId,
1557
+ sessionId,
1558
+ sessionName: deriveSessionNameFromFirstMessage(acc.firstUser),
1559
+ projectPath,
1560
+ projectName,
1561
+ account,
1562
+ timestamp,
1563
+ messageCount: acc.messageCount,
1564
+ lastMessageSender: acc.lastMessageSender,
1565
+ preview: acc.previewParts.join(" ").slice(0, tier.previewMax),
1566
+ contentSnippet: acc.snippetParts.join(" "),
1567
+ gitBranch: null,
1568
+ model: null,
1569
+ isSubagent,
1570
+ parentSessionId: parent?.parentFilePath ?? null,
1571
+ subagentId: isSubagent ? sessionId : void 0,
1572
+ parentSessionUuid: parent?.parentSessionUuid ?? void 0,
1573
+ isTeammate: false,
1574
+ teamName: null,
1575
+ toolNames: acc.toolNames,
1576
+ firstMessage: acc.firstUser,
1577
+ lastMessage: acc.lastAssistant ?? acc.lastUser,
1578
+ lastPrompt: acc.lastUser?.text || void 0,
1579
+ ...acc.isImportedFromClaude ? { isImportedFromClaude: true } : {},
1580
+ ...acc.isImportedFromCodex ? { isImportedFromCodex: true } : {}
1581
+ };
1582
+ }
1583
+ function parentFromSubagentPath(filePath) {
1584
+ const subagentsDir = (0, import_path7.dirname)(filePath);
1585
+ const parentDir = (0, import_path7.dirname)(subagentsDir);
1586
+ const parentSessionUuid = (0, import_path7.basename)(parentDir);
1587
+ if (!parentSessionUuid) return null;
1588
+ return {
1589
+ parentSessionUuid,
1590
+ parentFilePath: canonicalPath((0, import_path7.join)(parentDir, `${parentSessionUuid}.jsonl`))
1591
+ };
1592
+ }
1593
+ function projectFromCursorPath(filePath) {
1594
+ const parts = filePath.split(/[/\\]/);
1595
+ const idx = parts.lastIndexOf("agent-transcripts");
1596
+ const cursorProjectDir = idx > 0 ? parts.slice(0, idx).join(import_path7.sep) : (0, import_path7.dirname)((0, import_path7.dirname)(filePath));
1597
+ const slug = (0, import_path7.basename)(cursorProjectDir);
1598
+ const decoded = decodeCursorProjectSlug(slug);
1599
+ const projectPath = decoded ?? cursorProjectDir;
1600
+ return { projectPath, projectName: getShortProjectName4(projectPath) || slug };
1601
+ }
1602
+ function decodeCursorProjectSlug(slug) {
1603
+ if (!slug) return null;
1604
+ const segments = slug.split("-");
1605
+ if (segments.length === 0) return null;
1606
+ const rooted = slug.startsWith("Users-") || slug.startsWith("home-") || /^[A-Za-z]-/.test(slug);
1607
+ let acc = rooted ? import_path7.sep : "";
1608
+ let i = 0;
1609
+ if (rooted && segments[0] === "Users") {
1610
+ const users = `${import_path7.sep}Users`;
1611
+ if (!(0, import_fs5.existsSync)(users)) return null;
1612
+ acc = users;
1613
+ i = 1;
1614
+ }
1615
+ while (i < segments.length) {
1616
+ let found = null;
1617
+ let next = i + 1;
1618
+ for (let j = segments.length; j > i; j--) {
1619
+ const candidate = (0, import_path7.join)(acc, segments.slice(i, j).join("-"));
1620
+ try {
1621
+ if ((0, import_fs5.existsSync)(candidate) && (0, import_fs5.statSync)(candidate).isDirectory()) {
1622
+ found = candidate;
1623
+ next = j;
1624
+ break;
1625
+ }
1626
+ } catch {
1627
+ }
1628
+ }
1629
+ if (!found) return null;
1630
+ acc = found;
1631
+ i = next;
1632
+ }
1633
+ return acc;
1634
+ }
1635
+ function getShortProjectName4(fullPath) {
1636
+ return fullPath.split(/[/\\]/).filter(Boolean).slice(-3).join("/");
1637
+ }
1638
+ function fileMtimeIso(filePath) {
1639
+ try {
1640
+ return new Date((0, import_fs5.statSync)(filePath).mtimeMs).toISOString();
1641
+ } catch {
1642
+ return (/* @__PURE__ */ new Date()).toISOString();
1643
+ }
1644
+ }
1645
+ async function parseCursorConversation(filePath, account) {
1646
+ const log = getLogger();
1647
+ const messages = [];
1648
+ const textParts = [];
1649
+ let latestTimestamp = "";
1650
+ let lastUserText = "";
1651
+ const rl = (0, import_readline3.createInterface)({ input: (0, import_fs5.createReadStream)(filePath), crlfDelay: Infinity });
1652
+ try {
1653
+ for await (const line of rl) {
1654
+ const message = parseCursorJsonlLine(line);
1655
+ if (!message) continue;
1656
+ if (message.timestamp && (!latestTimestamp || message.timestamp > latestTimestamp)) {
1657
+ latestTimestamp = message.timestamp;
1658
+ }
1659
+ messages.push(message);
1660
+ textParts.push(message.text);
1661
+ if (message.role === "user") lastUserText = message.text;
1662
+ }
1663
+ } catch (err) {
1664
+ log.warn({ filePath, err }, "parseCursorConversation: read failed");
1665
+ return null;
1666
+ }
1667
+ if (messages.length === 0) return null;
1668
+ const { projectPath, projectName } = projectFromCursorPath(filePath);
1669
+ const sessionId = (0, import_path7.basename)(filePath, ".jsonl");
1670
+ return {
1671
+ id: filePath,
1672
+ filePath,
1673
+ projectPath,
1674
+ projectName,
1675
+ sessionId,
1676
+ sessionName: "",
1677
+ messages,
1678
+ fullText: textParts.join(" "),
1679
+ timestamp: latestTimestamp || fileMtimeIso(filePath),
1680
+ messageCount: messages.length,
1681
+ account,
1682
+ lastPrompt: lastUserText || void 0
1683
+ };
1684
+ }
1685
+
1686
+ // src/discovery.ts
1687
+ var import_fast_glob3 = __toESM(require("fast-glob"), 1);
1688
+ var import_promises4 = require("fs/promises");
1260
1689
  var EXCLUDED_SEGMENTS = ["/memory/", "/tool-results/"];
1261
1690
  var STAT_CONCURRENCY = 32;
1262
1691
  async function discoverJsonlFiles(dirs, onProgress) {
@@ -1265,7 +1694,7 @@ async function discoverJsonlFiles(dirs, onProgress) {
1265
1694
  for (const { projectsDir, account } of dirs) {
1266
1695
  let filePaths;
1267
1696
  try {
1268
- filePaths = await (0, import_fast_glob2.default)("**/*.jsonl", {
1697
+ filePaths = await (0, import_fast_glob3.default)("**/*.jsonl", {
1269
1698
  cwd: projectsDir,
1270
1699
  absolute: true,
1271
1700
  dot: false
@@ -1283,7 +1712,7 @@ async function discoverJsonlFiles(dirs, onProgress) {
1283
1712
  const statted = await Promise.all(
1284
1713
  chunk.map(async (filePath) => {
1285
1714
  try {
1286
- const s = await (0, import_promises3.stat)(filePath);
1715
+ const s = await (0, import_promises4.stat)(filePath);
1287
1716
  return { filePath, size: s.size };
1288
1717
  } catch (err) {
1289
1718
  log.warn({ filePath, err }, "discovery: stat failed");
@@ -1358,9 +1787,9 @@ var ThreadbaseProvider = class {
1358
1787
 
1359
1788
  // src/scanner.ts
1360
1789
  var import_events = require("events");
1361
- var import_fs11 = require("fs");
1790
+ var import_fs12 = require("fs");
1362
1791
  var import_os2 = require("os");
1363
- var import_path11 = require("path");
1792
+ var import_path12 = require("path");
1364
1793
 
1365
1794
  // src/cache.ts
1366
1795
  var LRUCache = class {
@@ -1399,18 +1828,18 @@ var LRUCache = class {
1399
1828
  };
1400
1829
 
1401
1830
  // src/persistent/conversation-stream.ts
1402
- var import_path7 = require("path");
1831
+ var import_path8 = require("path");
1403
1832
 
1404
1833
  // src/persistent/paged-reader.ts
1405
- var import_fs6 = require("fs");
1406
- var import_promises5 = require("timers/promises");
1834
+ var import_fs7 = require("fs");
1835
+ var import_promises6 = require("timers/promises");
1407
1836
 
1408
1837
  // src/persistent/jsonl-tail-reader.ts
1409
- var import_fs5 = require("fs");
1410
- var import_promises4 = require("timers/promises");
1838
+ var import_fs6 = require("fs");
1839
+ var import_promises5 = require("timers/promises");
1411
1840
  var YIELD_EVERY_LINES = 500;
1412
1841
  async function tailReduce(filePath, startOffset, startLine, state, tier, onEntry) {
1413
- const stream = (0, import_fs5.createReadStream)(filePath, { start: startOffset, encoding: "utf8" });
1842
+ const stream = (0, import_fs6.createReadStream)(filePath, { start: startOffset, encoding: "utf8" });
1414
1843
  let buffer = "";
1415
1844
  let offset = startOffset;
1416
1845
  let line = startLine;
@@ -1437,7 +1866,7 @@ async function tailReduce(filePath, startOffset, startLine, state, tier, onEntry
1437
1866
  line++;
1438
1867
  if (++sinceYield >= YIELD_EVERY_LINES) {
1439
1868
  sinceYield = 0;
1440
- await (0, import_promises4.setImmediate)();
1869
+ await (0, import_promises5.setImmediate)();
1441
1870
  }
1442
1871
  }
1443
1872
  }
@@ -1447,7 +1876,7 @@ async function tailReduce(filePath, startOffset, startLine, state, tier, onEntry
1447
1876
  // src/persistent/paged-reader.ts
1448
1877
  var CHECKPOINT_INTERVAL = 500;
1449
1878
  async function streamMessages(filePath, startOffset, startLine, state, onMessage, onEntry) {
1450
- const stream = (0, import_fs6.createReadStream)(filePath, { start: startOffset, encoding: "utf8" });
1879
+ const stream = (0, import_fs7.createReadStream)(filePath, { start: startOffset, encoding: "utf8" });
1451
1880
  let buffer = "";
1452
1881
  let offset = startOffset;
1453
1882
  let line = startLine;
@@ -1463,7 +1892,7 @@ async function streamMessages(filePath, startOffset, startLine, state, onMessage
1463
1892
  line += 1;
1464
1893
  if (++sinceYield >= YIELD_EVERY_LINES) {
1465
1894
  sinceYield = 0;
1466
- await (0, import_promises5.setImmediate)();
1895
+ await (0, import_promises6.setImmediate)();
1467
1896
  }
1468
1897
  if (text.length === 0) continue;
1469
1898
  let entry;
@@ -1559,7 +1988,7 @@ function assemble(filePath, account, messages, fullText, turnDurations, state) {
1559
1988
  filePath,
1560
1989
  projectPath: state.cwd,
1561
1990
  projectName: getShortProjectName2(state.cwd),
1562
- sessionId: state.sessionId || (0, import_path7.basename)(filePath, ".jsonl"),
1991
+ sessionId: state.sessionId || (0, import_path8.basename)(filePath, ".jsonl"),
1563
1992
  sessionName: state.sessionName || deriveSessionNameFromFirstMessage(messages.find((m) => m.role === "user" && m.text) ?? null),
1564
1993
  messages,
1565
1994
  fullText,
@@ -1604,70 +2033,70 @@ async function extendConversation(previous, resume, filePath, account) {
1604
2033
 
1605
2034
  // src/persistent/cursor.ts
1606
2035
  var import_crypto = require("crypto");
1607
- var import_fs7 = require("fs");
2036
+ var import_fs8 = require("fs");
1608
2037
  var FP_BYTES = 4096;
1609
2038
  function fingerprint(filePath, size) {
1610
2039
  const hash = (0, import_crypto.createHash)("sha1");
1611
2040
  hash.update(String(size));
1612
- const fd = (0, import_fs7.openSync)(filePath, "r");
2041
+ const fd = (0, import_fs8.openSync)(filePath, "r");
1613
2042
  try {
1614
2043
  const head = Buffer.alloc(Math.min(FP_BYTES, size));
1615
2044
  if (head.length > 0) {
1616
- (0, import_fs7.readSync)(fd, head, 0, head.length, 0);
2045
+ (0, import_fs8.readSync)(fd, head, 0, head.length, 0);
1617
2046
  hash.update(head);
1618
2047
  }
1619
2048
  if (size > FP_BYTES) {
1620
2049
  const tailLen = Math.min(FP_BYTES, size);
1621
2050
  const tail = Buffer.alloc(tailLen);
1622
- (0, import_fs7.readSync)(fd, tail, 0, tailLen, size - tailLen);
2051
+ (0, import_fs8.readSync)(fd, tail, 0, tailLen, size - tailLen);
1623
2052
  hash.update(tail);
1624
2053
  }
1625
2054
  } finally {
1626
- (0, import_fs7.closeSync)(fd);
2055
+ (0, import_fs8.closeSync)(fd);
1627
2056
  }
1628
2057
  return hash.digest("hex");
1629
2058
  }
1630
2059
  function classify(filePath, existing) {
1631
- let stat4;
2060
+ let stat5;
1632
2061
  try {
1633
- const s = (0, import_fs7.statSync)(filePath);
1634
- stat4 = { size: s.size, mtimeMs: s.mtimeMs };
2062
+ const s = (0, import_fs8.statSync)(filePath);
2063
+ stat5 = { size: s.size, mtimeMs: s.mtimeMs };
1635
2064
  } catch {
1636
2065
  return { change: "vanished" };
1637
2066
  }
1638
2067
  if (!existing || existing.status !== "active" || existing.last_indexed_offset === 0) {
1639
- return { change: "reindex", stat: stat4 };
2068
+ return { change: "reindex", stat: stat5 };
1640
2069
  }
1641
- if (stat4.size < existing.last_indexed_offset) {
1642
- return { change: "reindex", stat: stat4 };
2070
+ if (stat5.size < existing.last_indexed_offset) {
2071
+ return { change: "reindex", stat: stat5 };
1643
2072
  }
1644
- if (stat4.size === existing.size_bytes && stat4.mtimeMs === existing.mtime_ms) {
1645
- return { change: "unchanged", stat: stat4 };
2073
+ if (stat5.size === existing.size_bytes && stat5.mtimeMs === existing.mtime_ms) {
2074
+ return { change: "unchanged", stat: stat5 };
1646
2075
  }
1647
- if (stat4.size === existing.last_indexed_offset) {
1648
- const fp = fingerprint(filePath, stat4.size);
2076
+ if (stat5.size === existing.last_indexed_offset) {
2077
+ const fp = fingerprint(filePath, stat5.size);
1649
2078
  if (existing.content_fingerprint && fp !== existing.content_fingerprint) {
1650
- return { change: "reindex", stat: stat4 };
2079
+ return { change: "reindex", stat: stat5 };
1651
2080
  }
1652
- return { change: "unchanged", stat: stat4 };
2081
+ return { change: "unchanged", stat: stat5 };
1653
2082
  }
1654
2083
  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: stat4 };
2084
+ return { change: "appended", stat: stat5 };
1656
2085
  }
1657
- return { change: "reindex", stat: stat4 };
2086
+ return { change: "reindex", stat: stat5 };
1658
2087
  }
1659
2088
 
1660
2089
  // src/persistent/index-engine.ts
1661
- var import_fs10 = require("fs");
2090
+ var import_fs11 = require("fs");
1662
2091
 
1663
2092
  // src/providers/parse.ts
1664
- var import_fs8 = require("fs");
1665
- var import_readline3 = require("readline");
2093
+ var import_fs9 = require("fs");
2094
+ var import_readline4 = require("readline");
1666
2095
  async function parseMetaWithProvider(provider, filePath, account, tier, onEntry) {
1667
2096
  const log = getLogger();
1668
2097
  const acc = provider.createEmptyAccumulator();
1669
- const rl = (0, import_readline3.createInterface)({
1670
- input: (0, import_fs8.createReadStream)(filePath),
2098
+ const rl = (0, import_readline4.createInterface)({
2099
+ input: (0, import_fs9.createReadStream)(filePath),
1671
2100
  crlfDelay: Infinity
1672
2101
  });
1673
2102
  try {
@@ -1737,8 +2166,35 @@ function extractSearchDelta(entry) {
1737
2166
  if (entry.type === "response_item" || entry.type === "session_meta") {
1738
2167
  return extractCodexDelta(entry);
1739
2168
  }
2169
+ if (looksLikeCursorChatEntry(entry)) {
2170
+ return extractCursorDelta(entry);
2171
+ }
1740
2172
  return extractClaudeDelta(entry);
1741
2173
  }
2174
+ function extractCursorDelta(entry) {
2175
+ const msg = entry.message;
2176
+ const content = msg?.content ?? entry.content;
2177
+ return {
2178
+ text: extractCursorSearchText(content),
2179
+ thinking: "",
2180
+ tools: extractClaudeToolContent(content)
2181
+ };
2182
+ }
2183
+ function extractCursorSearchText(content) {
2184
+ if (typeof content === "string") return unwrapCursorUserText(content);
2185
+ if (!Array.isArray(content)) return "";
2186
+ const parts = [];
2187
+ for (const item of content) {
2188
+ if (typeof item === "string") {
2189
+ const cleaned = unwrapCursorUserText(item);
2190
+ if (cleaned) parts.push(cleaned);
2191
+ } else if ((item?.type === "text" || item?.type === void 0) && typeof item?.text === "string") {
2192
+ const cleaned = unwrapCursorUserText(item.text);
2193
+ if (cleaned) parts.push(cleaned);
2194
+ }
2195
+ }
2196
+ return parts.join(SEP);
2197
+ }
1742
2198
  function extractClaudeDelta(entry) {
1743
2199
  const type = entry.type;
1744
2200
  if (type !== "user" && type !== "assistant") return emptySearchDocument();
@@ -1855,11 +2311,11 @@ function resolveTier(tierName, customTiers) {
1855
2311
 
1856
2312
  // src/persistent/db.ts
1857
2313
  var import_better_sqlite3 = __toESM(require("better-sqlite3"), 1);
1858
- var import_fs9 = require("fs");
1859
- var import_path8 = require("path");
2314
+ var import_fs10 = require("fs");
2315
+ var import_path9 = require("path");
1860
2316
 
1861
2317
  // src/persistent/schema.ts
1862
- var SCHEMA_VERSION = 7;
2318
+ var SCHEMA_VERSION = 9;
1863
2319
  var SCHEMA_SQL = `
1864
2320
  CREATE TABLE IF NOT EXISTS conversation_files (
1865
2321
  id INTEGER PRIMARY KEY AUTOINCREMENT,
@@ -1944,6 +2400,10 @@ CREATE TABLE IF NOT EXISTS conversations (
1944
2400
  tool_names_json TEXT,
1945
2401
  last_prompt TEXT,
1946
2402
 
2403
+ is_imported_from_claude INTEGER NOT NULL DEFAULT 0,
2404
+ is_imported_from_codex INTEGER NOT NULL DEFAULT 0,
2405
+ is_imported_from_cursor INTEGER NOT NULL DEFAULT 0,
2406
+
1947
2407
  status TEXT NOT NULL DEFAULT 'active',
1948
2408
 
1949
2409
  created_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP,
@@ -2109,6 +2569,45 @@ function runMigrations(db) {
2109
2569
  db.exec(`UPDATE conversation_files SET ${assignments.join(", ")}`);
2110
2570
  }
2111
2571
  }
2572
+ if (current >= 1 && current < 8 && tableExists(db, "conversations")) {
2573
+ for (const [col, ddl] of [
2574
+ [
2575
+ "is_imported_from_claude",
2576
+ "ALTER TABLE conversations ADD COLUMN is_imported_from_claude INTEGER NOT NULL DEFAULT 0"
2577
+ ],
2578
+ [
2579
+ "is_imported_from_codex",
2580
+ "ALTER TABLE conversations ADD COLUMN is_imported_from_codex INTEGER NOT NULL DEFAULT 0"
2581
+ ],
2582
+ [
2583
+ "is_imported_from_cursor",
2584
+ "ALTER TABLE conversations ADD COLUMN is_imported_from_cursor INTEGER NOT NULL DEFAULT 0"
2585
+ ]
2586
+ ]) {
2587
+ if (!hasColumn(db, "conversations", col)) db.exec(ddl);
2588
+ }
2589
+ if (tableExists(db, "conversation_files")) {
2590
+ const assignments = [];
2591
+ if (hasColumn(db, "conversation_files", "last_indexed_offset")) {
2592
+ assignments.push("last_indexed_offset = 0");
2593
+ }
2594
+ if (hasColumn(db, "conversation_files", "last_indexed_line")) {
2595
+ assignments.push("last_indexed_line = 0");
2596
+ }
2597
+ if (hasColumn(db, "conversation_files", "reducer_state")) {
2598
+ assignments.push("reducer_state = NULL");
2599
+ }
2600
+ if (assignments.length > 0) {
2601
+ db.exec(
2602
+ `UPDATE conversation_files SET ${assignments.join(", ")}
2603
+ WHERE id IN (SELECT file_id FROM conversations WHERE provider IN ('cursor', 'cursor-cli'))`
2604
+ );
2605
+ }
2606
+ }
2607
+ }
2608
+ if (current >= 1 && current < 9 && tableExists(db, "conversations")) {
2609
+ db.exec(`UPDATE conversations SET provider = 'cursor' WHERE provider = 'cursor-cli'`);
2610
+ }
2112
2611
  db.exec(SCHEMA_SQL);
2113
2612
  db.pragma(`user_version = ${SCHEMA_VERSION}`);
2114
2613
  }
@@ -2123,7 +2622,7 @@ function hasColumn(db, table, column) {
2123
2622
  // src/persistent/db.ts
2124
2623
  function openDatabase(dbPath) {
2125
2624
  if (dbPath !== ":memory:") {
2126
- (0, import_fs9.mkdirSync)((0, import_path8.dirname)(dbPath), { recursive: true });
2625
+ (0, import_fs10.mkdirSync)((0, import_path9.dirname)(dbPath), { recursive: true });
2127
2626
  }
2128
2627
  let db;
2129
2628
  try {
@@ -2167,8 +2666,8 @@ function nativeBindingError(err, dbPath) {
2167
2666
  }
2168
2667
 
2169
2668
  // src/persistent/dir-watermark.ts
2170
- var import_promises6 = require("fs/promises");
2171
- var import_path9 = require("path");
2669
+ var import_promises7 = require("fs/promises");
2670
+ var import_path10 = require("path");
2172
2671
  var FULL_RECONCILE_EVERY_N_SCANS = 20;
2173
2672
  async function discoverJsonlFilesGated(dirs, files, scannedDirs, options = {}) {
2174
2673
  const log = getLogger();
@@ -2184,7 +2683,7 @@ async function discoverJsonlFilesGated(dirs, files, scannedDirs, options = {}) {
2184
2683
  for (const projectDir of resolved.entries) {
2185
2684
  let dirStat;
2186
2685
  try {
2187
- dirStat = await (0, import_promises6.stat)(projectDir);
2686
+ dirStat = await (0, import_promises7.stat)(projectDir);
2188
2687
  } catch {
2189
2688
  scannedDirs.remove(projectDir);
2190
2689
  continue;
@@ -2222,7 +2721,7 @@ async function discoverJsonlFilesGated(dirs, files, scannedDirs, options = {}) {
2222
2721
  async function resolveProjectDirs(projectsDir, scannedDirs) {
2223
2722
  let rootStat;
2224
2723
  try {
2225
- rootStat = await (0, import_promises6.stat)(projectsDir);
2724
+ rootStat = await (0, import_promises7.stat)(projectsDir);
2226
2725
  } catch {
2227
2726
  return null;
2228
2727
  }
@@ -2232,17 +2731,17 @@ async function resolveProjectDirs(projectsDir, scannedDirs) {
2232
2731
  }
2233
2732
  let entries;
2234
2733
  try {
2235
- entries = (await (0, import_promises6.readdir)(projectsDir, { withFileTypes: true })).filter((e) => e.isDirectory()).map((e) => joinPath(projectsDir, e.name));
2734
+ entries = (await (0, import_promises7.readdir)(projectsDir, { withFileTypes: true })).filter((e) => e.isDirectory()).map((e) => joinPath(projectsDir, e.name));
2236
2735
  } catch {
2237
2736
  return null;
2238
2737
  }
2239
2738
  return { entries, commitRoot: { mtimeMs: rootStat.mtimeMs } };
2240
2739
  }
2241
2740
  function dirnameOf(filePath) {
2242
- return (0, import_path9.dirname)(filePath);
2741
+ return (0, import_path10.dirname)(filePath);
2243
2742
  }
2244
2743
  function joinPath(dir, name) {
2245
- return (0, import_path9.join)(dir, name);
2744
+ return (0, import_path10.join)(dir, name);
2246
2745
  }
2247
2746
 
2248
2747
  // src/persistent/repositories/checkpoints.repo.ts
@@ -2322,7 +2821,7 @@ function toCheckpoint(row) {
2322
2821
  }
2323
2822
 
2324
2823
  // src/persistent/repositories/conversation-files.repo.ts
2325
- var import_path10 = require("path");
2824
+ var import_path11 = require("path");
2326
2825
  var ConversationFilesRepo = class {
2327
2826
  constructor(db) {
2328
2827
  this.db = db;
@@ -2345,7 +2844,7 @@ var ConversationFilesRepo = class {
2345
2844
  const info = this.db.prepare(
2346
2845
  `INSERT INTO conversation_files (absolute_path, parent_dir, file_name, account)
2347
2846
  VALUES (?, ?, ?, ?)`
2348
- ).run(canonical, (0, import_path10.dirname)(canonical), (0, import_path10.basename)(canonical), account);
2847
+ ).run(canonical, (0, import_path11.dirname)(canonical), (0, import_path11.basename)(canonical), account);
2349
2848
  return Number(info.lastInsertRowid);
2350
2849
  }
2351
2850
  // Advance the cursor + persisted reducer state after a successful index pass.
@@ -2440,7 +2939,10 @@ function rowToMeta(row) {
2440
2939
  toolNames: row.tool_names_json ? JSON.parse(row.tool_names_json) : [],
2441
2940
  firstMessage: row.first_sent_text ? { text: row.first_sent_text, timestamp: row.first_sent_at ?? "" } : null,
2442
2941
  lastMessage: row.last_sent_text ? { text: row.last_sent_text, timestamp: row.last_sent_at ?? "" } : null,
2443
- lastPrompt: row.last_prompt ?? void 0
2942
+ lastPrompt: row.last_prompt ?? void 0,
2943
+ ...row.is_imported_from_claude === 1 ? { isImportedFromClaude: true } : {},
2944
+ ...row.is_imported_from_codex === 1 ? { isImportedFromCodex: true } : {},
2945
+ ...row.is_imported_from_cursor === 1 ? { isImportedFromCursor: true } : {}
2444
2946
  };
2445
2947
  }
2446
2948
  var ConversationsRepo = class {
@@ -2460,7 +2962,8 @@ var ConversationsRepo = class {
2460
2962
  timestamp, index_seq, first_sent_at, first_sent_text, last_sent_at, last_sent_text,
2461
2963
  model, is_subagent, parent_session_id, subagent_id, parent_session_uuid,
2462
2964
  is_teammate, team_name, tool_names_json,
2463
- last_prompt, status, updated_at
2965
+ last_prompt, is_imported_from_claude, is_imported_from_codex,
2966
+ is_imported_from_cursor, status, updated_at
2464
2967
  ) VALUES (
2465
2968
  @file_id, @source_path, @provider, @kind, @external_session_id,
2466
2969
  @session_id, @session_name, @project_path, @project_name,
@@ -2471,7 +2974,8 @@ var ConversationsRepo = class {
2471
2974
  @first_sent_at, @first_sent_text, @last_sent_at, @last_sent_text,
2472
2975
  @model, @is_subagent, @parent_session_id, @subagent_id, @parent_session_uuid,
2473
2976
  @is_teammate, @team_name, @tool_names_json,
2474
- @last_prompt, 'active', CURRENT_TIMESTAMP
2977
+ @last_prompt, @is_imported_from_claude, @is_imported_from_codex,
2978
+ @is_imported_from_cursor, 'active', CURRENT_TIMESTAMP
2475
2979
  )
2476
2980
  ON CONFLICT(file_id) DO UPDATE SET
2477
2981
  source_path = excluded.source_path,
@@ -2503,6 +3007,9 @@ var ConversationsRepo = class {
2503
3007
  team_name = excluded.team_name,
2504
3008
  tool_names_json = excluded.tool_names_json,
2505
3009
  last_prompt = excluded.last_prompt,
3010
+ is_imported_from_claude = excluded.is_imported_from_claude,
3011
+ is_imported_from_codex = excluded.is_imported_from_codex,
3012
+ is_imported_from_cursor = excluded.is_imported_from_cursor,
2506
3013
  status = 'active',
2507
3014
  index_seq = (SELECT COALESCE(MAX(index_seq), 0) + 1 FROM conversations),
2508
3015
  updated_at = CURRENT_TIMESTAMP`
@@ -2539,7 +3046,10 @@ var ConversationsRepo = class {
2539
3046
  is_teammate: meta.isTeammate ? 1 : 0,
2540
3047
  team_name: meta.teamName,
2541
3048
  tool_names_json: JSON.stringify(meta.toolNames),
2542
- last_prompt: meta.lastPrompt ?? null
3049
+ last_prompt: meta.lastPrompt ?? null,
3050
+ is_imported_from_claude: meta.isImportedFromClaude ? 1 : 0,
3051
+ is_imported_from_codex: meta.isImportedFromCodex ? 1 : 0,
3052
+ is_imported_from_cursor: meta.isImportedFromCursor ? 1 : 0
2543
3053
  });
2544
3054
  }
2545
3055
  getBySourcePath(sourcePath) {
@@ -2699,8 +3209,14 @@ var FtsRepo = class {
2699
3209
  params.push(filters.account);
2700
3210
  }
2701
3211
  if (filters.provider) {
2702
- where.push("c.provider = ?");
2703
- params.push(filters.provider);
3212
+ const provider = canonicalizeProviderName(filters.provider) ?? filters.provider;
3213
+ if (provider === CURSOR_PROVIDER) {
3214
+ where.push("(c.provider = ? OR c.provider = ?)");
3215
+ params.push(CURSOR_PROVIDER, LEGACY_CURSOR_PROVIDER);
3216
+ } else {
3217
+ where.push("c.provider = ?");
3218
+ params.push(provider);
3219
+ }
2704
3220
  }
2705
3221
  if (filters.project) {
2706
3222
  where.push("(lower(c.project_path) LIKE ? OR lower(c.project_name) LIKE ?)");
@@ -2819,7 +3335,7 @@ var PersistentEngine = class {
2819
3335
  async indexAll(activeProfiles, options) {
2820
3336
  const log = getLogger();
2821
3337
  const tier = resolveTier(options.tier ?? "standard", options.tiers);
2822
- const enabled = options.providers ?? [CLAUDE_CODE_PROVIDER];
3338
+ const enabled = canonicalizeProviderList(options.providers);
2823
3339
  const discovered = [];
2824
3340
  if (enabled.includes(CLAUDE_CODE_PROVIDER)) {
2825
3341
  const configDirs = activeProfiles.map((p) => ({
@@ -2839,6 +3355,12 @@ var PersistentEngine = class {
2839
3355
  discovered.push({ ...f, provider: codex });
2840
3356
  }
2841
3357
  }
3358
+ const cursor = new CursorProvider();
3359
+ if (enabled.includes(CURSOR_PROVIDER) && (options.cursorRoots?.length ?? 0) > 0) {
3360
+ for (const f of await cursor.discover(options.cursorRoots)) {
3361
+ discovered.push({ ...f, provider: cursor });
3362
+ }
3363
+ }
2842
3364
  let scanned = 0;
2843
3365
  const gitBranchMemo = /* @__PURE__ */ new Map();
2844
3366
  const resolveGitBranch = (projectPath) => {
@@ -2877,6 +3399,9 @@ var PersistentEngine = class {
2877
3399
  if (enabled.includes(CODEX_CLI_PROVIDER) && (options.codexRoots?.length ?? 0) > 0) {
2878
3400
  coveredAccounts.add("codex");
2879
3401
  }
3402
+ if (enabled.includes(CURSOR_PROVIDER) && (options.cursorRoots?.length ?? 0) > 0) {
3403
+ coveredAccounts.add("cursor");
3404
+ }
2880
3405
  const seen = new Set(discovered.map((d) => canonicalPath(d.filePath)));
2881
3406
  for (const path of this.files.activePathsByAccounts([...coveredAccounts])) {
2882
3407
  if (!seen.has(path)) this.markDeleted(path);
@@ -2896,8 +3421,8 @@ var PersistentEngine = class {
2896
3421
  const tier = resolveTier(tierName, customTiers);
2897
3422
  const filePath = canonicalPath(rawFilePath);
2898
3423
  const existing = this.files.getByPath(filePath);
2899
- const { change, stat: stat4 } = classify(filePath, existing);
2900
- if (change === "vanished" || !stat4) {
3424
+ const { change, stat: stat5 } = classify(filePath, existing);
3425
+ if (change === "vanished" || !stat5) {
2901
3426
  this.markDeleted(filePath);
2902
3427
  return { meta: null, change: "vanished" };
2903
3428
  }
@@ -2910,7 +3435,7 @@ var PersistentEngine = class {
2910
3435
  filePath,
2911
3436
  account,
2912
3437
  tier,
2913
- stat4,
3438
+ stat5,
2914
3439
  resolveGitBranch
2915
3440
  );
2916
3441
  return { meta: meta2, change };
@@ -2936,7 +3461,7 @@ var PersistentEngine = class {
2936
3461
  return { meta: null, change };
2937
3462
  }
2938
3463
  meta.gitBranch = resolveGitBranch(meta.projectPath);
2939
- const fp = stat4.size > 0 ? fingerprint(filePath, stat4.size) : null;
3464
+ const fp = stat5.size > 0 ? fingerprint(filePath, stat5.size) : null;
2940
3465
  const fileId = this.files.ensure(filePath, account);
2941
3466
  const base = resume ? this.fts.readDocument(fileId) ?? emptySearchDocument() : emptySearchDocument();
2942
3467
  const searchDoc = appendSearchDelta(base, searchDelta);
@@ -2947,8 +3472,8 @@ var PersistentEngine = class {
2947
3472
  }
2948
3473
  if (!resume) this.checkpoints.remove(filePath);
2949
3474
  this.files.updateCursor(fileId, {
2950
- sizeBytes: stat4.size,
2951
- mtimeMs: stat4.mtimeMs,
3475
+ sizeBytes: stat5.size,
3476
+ mtimeMs: stat5.mtimeMs,
2952
3477
  // Advance only to the last fully-parsed line; a trailing partial line
2953
3478
  // is left for the next pass.
2954
3479
  offset: result.newOffset,
@@ -2965,8 +3490,8 @@ var PersistentEngine = class {
2965
3490
  buildSidecar(
2966
3491
  meta,
2967
3492
  {
2968
- sizeBytes: stat4.size,
2969
- mtimeMs: stat4.mtimeMs,
3493
+ sizeBytes: stat5.size,
3494
+ mtimeMs: stat5.mtimeMs,
2970
3495
  offset: result.newOffset,
2971
3496
  line: result.newLine
2972
3497
  },
@@ -2985,7 +3510,7 @@ var PersistentEngine = class {
2985
3510
  // the Threadbase path uses. The cursor records size/mtime (and offset = size)
2986
3511
  // so the next pass classifies an unchanged file as "unchanged" and skips it;
2987
3512
  // any change reparses from 0 again. No reducer_state is persisted.
2988
- async indexFileWithProvider(provider, filePath, account, tier, stat4, resolveGitBranch) {
3513
+ async indexFileWithProvider(provider, filePath, account, tier, stat5, resolveGitBranch) {
2989
3514
  const log = getLogger();
2990
3515
  let searchDoc = emptySearchDocument();
2991
3516
  const meta = await parseMetaWithProvider(provider, filePath, account, tier, (entry) => {
@@ -2998,7 +3523,7 @@ var PersistentEngine = class {
2998
3523
  if (meta.gitBranch === null && meta.projectPath) {
2999
3524
  meta.gitBranch = resolveGitBranch(meta.projectPath);
3000
3525
  }
3001
- const fp = stat4.size > 0 ? fingerprint(filePath, stat4.size) : null;
3526
+ const fp = stat5.size > 0 ? fingerprint(filePath, stat5.size) : null;
3002
3527
  const fileId = this.files.ensure(filePath, account);
3003
3528
  const upsert = this.db.transaction(() => {
3004
3529
  this.conversations.upsert(fileId, meta, meta.messageCount);
@@ -3007,11 +3532,11 @@ var PersistentEngine = class {
3007
3532
  }
3008
3533
  this.checkpoints.remove(filePath);
3009
3534
  this.files.updateCursor(fileId, {
3010
- sizeBytes: stat4.size,
3011
- mtimeMs: stat4.mtimeMs,
3535
+ sizeBytes: stat5.size,
3536
+ mtimeMs: stat5.mtimeMs,
3012
3537
  // offset = size marks the file fully consumed (non-zero so the next pass
3013
3538
  // can classify it "unchanged"); no resumable reducer state is kept.
3014
- offset: stat4.size,
3539
+ offset: stat5.size,
3015
3540
  line: 0,
3016
3541
  reducerState: null,
3017
3542
  fingerprint: fp,
@@ -3077,8 +3602,8 @@ var PersistentEngine = class {
3077
3602
  const meta = this.conversations.getByIdOrSession(id);
3078
3603
  if (!meta) return null;
3079
3604
  const filePath = meta.filePath;
3080
- if (meta.provider === CODEX_CLI_PROVIDER) {
3081
- const conversation = await parseCodexConversation(filePath, meta.account);
3605
+ if (meta.provider === CODEX_CLI_PROVIDER || meta.provider === CURSOR_PROVIDER) {
3606
+ const conversation = meta.provider === CODEX_CLI_PROVIDER ? await parseCodexConversation(filePath, meta.account) : await parseCursorConversation(filePath, meta.account);
3082
3607
  if (!conversation) return null;
3083
3608
  const { messages } = conversation;
3084
3609
  const total2 = messages.length;
@@ -3093,7 +3618,7 @@ var PersistentEngine = class {
3093
3618
  let floor = this.checkpoints.floor(filePath, fromIndex);
3094
3619
  if (floor) {
3095
3620
  try {
3096
- if (floor.byteOffset > (0, import_fs10.statSync)(filePath).size) floor = null;
3621
+ if (floor.byteOffset > (0, import_fs11.statSync)(filePath).size) floor = null;
3097
3622
  } catch {
3098
3623
  }
3099
3624
  }
@@ -3232,7 +3757,7 @@ function defaultDbPath() {
3232
3757
  "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
3758
  );
3234
3759
  }
3235
- return (0, import_path11.join)((0, import_os2.homedir)(), ".config", "threadbase-scanner", "index.db");
3760
+ return (0, import_path12.join)((0, import_os2.homedir)(), ".config", "threadbase-scanner", "index.db");
3236
3761
  }
3237
3762
  function capForMemory(doc, max) {
3238
3763
  const combined = combineSearchContent(doc);
@@ -3411,7 +3936,7 @@ var ConversationScanner = class {
3411
3936
  const cached = statCache.get(filePath);
3412
3937
  if (cached) {
3413
3938
  try {
3414
- const s = (0, import_fs11.statSync)(filePath);
3939
+ const s = (0, import_fs12.statSync)(filePath);
3415
3940
  if (s.mtimeMs === cached.stat.mtimeMs && s.size === cached.stat.size) {
3416
3941
  return {
3417
3942
  meta: cached.meta,
@@ -3542,9 +4067,7 @@ var ConversationScanner = class {
3542
4067
  results = results.filter((r) => r.meta.account === options.account);
3543
4068
  }
3544
4069
  if (options.provider) {
3545
- results = results.filter(
3546
- (r) => (r.meta.provider ?? CLAUDE_CODE_PROVIDER) === options.provider
3547
- );
4070
+ results = results.filter((r) => providerMatches(r.meta.provider, options.provider));
3548
4071
  }
3549
4072
  if (options.since) {
3550
4073
  const cutoff = parseSinceCutoff(options.since);
@@ -3571,12 +4094,12 @@ var ConversationScanner = class {
3571
4094
  }
3572
4095
  log.debug({ id, filePath: meta.filePath }, "getConversation: cache miss, parsing");
3573
4096
  try {
3574
- if (this.persistent && meta.provider !== CODEX_CLI_PROVIDER) {
4097
+ if (this.persistent && meta.provider !== CODEX_CLI_PROVIDER && meta.provider !== CURSOR_PROVIDER) {
3575
4098
  const parsed = await parseConversationResumable(meta.filePath, meta.account);
3576
4099
  if (parsed) this.conversationLRU.set(cid, parsed);
3577
4100
  return parsed?.conversation ?? null;
3578
4101
  }
3579
- const conversation = meta.provider === CODEX_CLI_PROVIDER ? await parseCodexConversation(meta.filePath, meta.account) : await parseConversation(meta.filePath, meta.account);
4102
+ 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
4103
  if (conversation) {
3581
4104
  this.conversationLRU.set(cid, { conversation });
3582
4105
  }
@@ -3630,7 +4153,7 @@ var ConversationScanner = class {
3630
4153
  // fallback, matching refreshFile.
3631
4154
  async parseSingleFilePage(filePath, account, options) {
3632
4155
  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");
4156
+ 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
4157
  if (!conversation) return null;
3635
4158
  const { messages } = conversation;
3636
4159
  const total = messages.length;
@@ -3919,7 +4442,7 @@ var ConversationScanner = class {
3919
4442
  // discovers under the active profiles' project dirs; Codex discovers under
3920
4443
  // the explicit codexRoots (opt-in — no default home scan).
3921
4444
  async discoverWithProviders(activeProfiles, options) {
3922
- const enabled = options.providers ?? [CLAUDE_CODE_PROVIDER];
4445
+ const enabled = canonicalizeProviderList(options.providers);
3923
4446
  const work = [];
3924
4447
  if (enabled.includes(CLAUDE_CODE_PROVIDER)) {
3925
4448
  const provider = new ThreadbaseProvider();
@@ -3934,6 +4457,12 @@ var ConversationScanner = class {
3934
4457
  work.push({ ...f, provider });
3935
4458
  }
3936
4459
  }
4460
+ if (enabled.includes(CURSOR_PROVIDER) && (options.cursorRoots?.length ?? 0) > 0) {
4461
+ const provider = new CursorProvider();
4462
+ for (const f of await provider.discover(options.cursorRoots)) {
4463
+ work.push({ ...f, provider });
4464
+ }
4465
+ }
3937
4466
  return work;
3938
4467
  }
3939
4468
  // Resolve which provider should (re)parse a file. Stored metadata wins; for a
@@ -3942,20 +4471,25 @@ var ConversationScanner = class {
3942
4471
  // tail-read path).
3943
4472
  async resolveProviderForFile(filePath, previous) {
3944
4473
  if (previous?.provider === CODEX_CLI_PROVIDER) return new CodexCliProvider();
4474
+ if (providerMatches(previous?.provider, CURSOR_PROVIDER)) {
4475
+ return new CursorProvider();
4476
+ }
3945
4477
  if (previous?.provider) return void 0;
3946
4478
  let sample = "";
3947
4479
  try {
3948
- const fd = (0, import_fs11.openSync)(filePath, "r");
4480
+ const fd = (0, import_fs12.openSync)(filePath, "r");
3949
4481
  try {
3950
4482
  const buf = Buffer.alloc(8192);
3951
- const n = (0, import_fs11.readSync)(fd, buf, 0, buf.length, 0);
4483
+ const n = (0, import_fs12.readSync)(fd, buf, 0, buf.length, 0);
3952
4484
  sample = buf.subarray(0, n).toString("utf8");
3953
4485
  } finally {
3954
- (0, import_fs11.closeSync)(fd);
4486
+ (0, import_fs12.closeSync)(fd);
3955
4487
  }
3956
4488
  } catch {
3957
4489
  return void 0;
3958
4490
  }
4491
+ const cursor = new CursorProvider();
4492
+ if (cursor.canParse(filePath, sample)) return cursor;
3959
4493
  const codex = new CodexCliProvider();
3960
4494
  if (codex.canParse(filePath, sample)) return codex;
3961
4495
  return void 0;
@@ -4065,9 +4599,14 @@ async function getConversation(id, options, scanner) {
4065
4599
  }
4066
4600
  // Annotate the CommonJS export names for ESM import in node:
4067
4601
  0 && (module.exports = {
4602
+ CLAUDE_CODE_PROVIDER,
4603
+ CODEX_CLI_PROVIDER,
4604
+ CURSOR_PROVIDER,
4068
4605
  CodexCliProvider,
4069
4606
  ConversationScanner,
4607
+ CursorProvider,
4070
4608
  DEFAULT_TIERS,
4609
+ LEGACY_CURSOR_PROVIDER,
4071
4610
  SearchIndexer,
4072
4611
  ThreadbaseProvider,
4073
4612
  VALID_SORT_ORDERS,
@@ -4077,6 +4616,8 @@ async function getConversation(id, options, scanner) {
4077
4616
  applyProjectFilter,
4078
4617
  applySinceFilter,
4079
4618
  applySort,
4619
+ canonicalizeProviderList,
4620
+ canonicalizeProviderName,
4080
4621
  cleanSystemTags,
4081
4622
  createJsonlParseState,
4082
4623
  createLogger,
@@ -4087,7 +4628,9 @@ async function getConversation(id, options, scanner) {
4087
4628
  isCodexInjectedContext,
4088
4629
  loadProfiles,
4089
4630
  parseCodexJsonlLine,
4631
+ parseCursorJsonlLine,
4090
4632
  parseJsonlLine,
4633
+ providerMatches,
4091
4634
  readGitBranch,
4092
4635
  readSidecar,
4093
4636
  resetDefaultScanner,
@@ -4097,6 +4640,7 @@ async function getConversation(id, options, scanner) {
4097
4640
  scan,
4098
4641
  search,
4099
4642
  setLogger,
4100
- sidecarPath
4643
+ sidecarPath,
4644
+ unwrapCursorUserText
4101
4645
  });
4102
4646
  //# sourceMappingURL=index.cjs.map