@threadbase-sh/scanner 0.17.7 → 0.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.js CHANGED
@@ -5,7 +5,7 @@ import { Command } from "commander";
5
5
  import pino2 from "pino";
6
6
 
7
7
  // package.json
8
- var version = "0.17.7";
8
+ var version = "0.19.0";
9
9
 
10
10
  // src/logger.ts
11
11
  import pino from "pino";
@@ -60,9 +60,9 @@ async function saveProfiles(profiles, configPath) {
60
60
 
61
61
  // src/scanner.ts
62
62
  import { EventEmitter } from "events";
63
- import { closeSync as closeSync2, openSync as openSync2, readSync as readSync2, statSync as statSync3 } from "fs";
63
+ import { closeSync as closeSync2, openSync as openSync2, readSync as readSync2, statSync as statSync4 } from "fs";
64
64
  import { homedir as homedir2 } from "os";
65
- import { join as join5 } from "path";
65
+ import { join as join6 } from "path";
66
66
 
67
67
  // src/cache.ts
68
68
  var LRUCache = class {
@@ -614,6 +614,29 @@ import { basename, dirname as dirname2, join as join3 } from "path";
614
614
  // src/providers/provider.ts
615
615
  var CLAUDE_CODE_PROVIDER = "claude-code";
616
616
  var CODEX_CLI_PROVIDER = "codex-cli";
617
+ var CURSOR_PROVIDER = "cursor";
618
+ var LEGACY_CURSOR_PROVIDER = "cursor-cli";
619
+ function canonicalizeProviderName(value) {
620
+ if (value === LEGACY_CURSOR_PROVIDER) return CURSOR_PROVIDER;
621
+ if (value === CLAUDE_CODE_PROVIDER || value === CODEX_CLI_PROVIDER || value === CURSOR_PROVIDER) {
622
+ return value;
623
+ }
624
+ return void 0;
625
+ }
626
+ function canonicalizeProviderList(providers) {
627
+ const src = providers ?? [CLAUDE_CODE_PROVIDER];
628
+ const out = [];
629
+ for (const p of src) {
630
+ const n = canonicalizeProviderName(p);
631
+ if (n && !out.includes(n)) out.push(n);
632
+ }
633
+ return out;
634
+ }
635
+ function providerMatches(stored, wanted) {
636
+ const a = canonicalizeProviderName(stored ?? CLAUDE_CODE_PROVIDER) ?? stored;
637
+ const b = canonicalizeProviderName(wanted) ?? wanted;
638
+ return a === b;
639
+ }
617
640
 
618
641
  // src/persistent/metadata-reducer.ts
619
642
  function initialReducerState() {
@@ -1199,37 +1222,37 @@ function fingerprint(filePath, size) {
1199
1222
  return hash.digest("hex");
1200
1223
  }
1201
1224
  function classify(filePath, existing) {
1202
- let stat4;
1225
+ let stat5;
1203
1226
  try {
1204
1227
  const s = statSync(filePath);
1205
- stat4 = { size: s.size, mtimeMs: s.mtimeMs };
1228
+ stat5 = { size: s.size, mtimeMs: s.mtimeMs };
1206
1229
  } catch {
1207
1230
  return { change: "vanished" };
1208
1231
  }
1209
1232
  if (!existing || existing.status !== "active" || existing.last_indexed_offset === 0) {
1210
- return { change: "reindex", stat: stat4 };
1233
+ return { change: "reindex", stat: stat5 };
1211
1234
  }
1212
- if (stat4.size < existing.last_indexed_offset) {
1213
- return { change: "reindex", stat: stat4 };
1235
+ if (stat5.size < existing.last_indexed_offset) {
1236
+ return { change: "reindex", stat: stat5 };
1214
1237
  }
1215
- if (stat4.size === existing.size_bytes && stat4.mtimeMs === existing.mtime_ms) {
1216
- return { change: "unchanged", stat: stat4 };
1238
+ if (stat5.size === existing.size_bytes && stat5.mtimeMs === existing.mtime_ms) {
1239
+ return { change: "unchanged", stat: stat5 };
1217
1240
  }
1218
- if (stat4.size === existing.last_indexed_offset) {
1219
- const fp = fingerprint(filePath, stat4.size);
1241
+ if (stat5.size === existing.last_indexed_offset) {
1242
+ const fp = fingerprint(filePath, stat5.size);
1220
1243
  if (existing.content_fingerprint && fp !== existing.content_fingerprint) {
1221
- return { change: "reindex", stat: stat4 };
1244
+ return { change: "reindex", stat: stat5 };
1222
1245
  }
1223
- return { change: "unchanged", stat: stat4 };
1246
+ return { change: "unchanged", stat: stat5 };
1224
1247
  }
1225
1248
  if (existing.content_fingerprint && existing.size_bytes === existing.last_indexed_offset && fingerprint(filePath, existing.last_indexed_offset) === existing.content_fingerprint) {
1226
- return { change: "appended", stat: stat4 };
1249
+ return { change: "appended", stat: stat5 };
1227
1250
  }
1228
- return { change: "reindex", stat: stat4 };
1251
+ return { change: "reindex", stat: stat5 };
1229
1252
  }
1230
1253
 
1231
1254
  // src/persistent/index-engine.ts
1232
- import { statSync as statSync2 } from "fs";
1255
+ import { statSync as statSync3 } from "fs";
1233
1256
 
1234
1257
  // src/providers/codex-cli.ts
1235
1258
  import fg2 from "fast-glob";
@@ -1322,15 +1345,101 @@ function extractCodexText(content) {
1322
1345
  return "";
1323
1346
  }).filter(Boolean).map(cleanSystemTags).join(" ");
1324
1347
  }
1348
+ function parseCodexJsonlLine(line) {
1349
+ if (!line.trim()) return null;
1350
+ let entry;
1351
+ try {
1352
+ entry = JSON.parse(line);
1353
+ } catch {
1354
+ return null;
1355
+ }
1356
+ return codexEntryToMessage(entry);
1357
+ }
1325
1358
  function codexEntryToMessage(entry) {
1326
1359
  const payload = entry.payload;
1327
1360
  if (!payload || typeof payload !== "object") return null;
1328
- if (entry.type !== "response_item" || payload.type !== "message") return null;
1329
- const role = payload.role;
1330
- if (role !== "user" && role !== "assistant") return null;
1331
- const text = extractCodexText(payload.content);
1332
- if (!text) return null;
1333
- return { role, text, timestamp: asString(entry.timestamp) };
1361
+ if (entry.type !== "response_item") return null;
1362
+ const timestamp = asString(entry.timestamp);
1363
+ const uuid = asString(payload.id) || void 0;
1364
+ const base = { timestamp, ...uuid ? { uuid } : {} };
1365
+ switch (payload.type) {
1366
+ case "message": {
1367
+ const role = payload.role;
1368
+ if (role !== "user" && role !== "assistant") return null;
1369
+ const text = extractCodexText(payload.content);
1370
+ if (!text) return null;
1371
+ return { role, text, ...base };
1372
+ }
1373
+ case "function_call":
1374
+ case "custom_tool_call":
1375
+ case "web_search_call": {
1376
+ const block = codexToolUseBlock(payload);
1377
+ if (!block) return null;
1378
+ return {
1379
+ role: "assistant",
1380
+ text: "",
1381
+ ...base,
1382
+ metadata: { toolUses: [block.name], toolUseBlocks: [block] }
1383
+ };
1384
+ }
1385
+ case "function_call_output":
1386
+ case "custom_tool_call_output": {
1387
+ const toolUseId = asString(payload.call_id);
1388
+ if (!toolUseId) return null;
1389
+ return {
1390
+ role: "user",
1391
+ text: "",
1392
+ ...base,
1393
+ isToolResult: true,
1394
+ metadata: {
1395
+ toolResults: [
1396
+ {
1397
+ toolUseId,
1398
+ type: "generic",
1399
+ content: { output: codexToolOutputText(payload.output) }
1400
+ }
1401
+ ]
1402
+ }
1403
+ };
1404
+ }
1405
+ case "reasoning": {
1406
+ const summary = Array.isArray(payload.summary) ? payload.summary : [];
1407
+ const thinkingContent = summary.map((s) => asString(s?.text)).filter((t) => t.trim()).join("\n\n");
1408
+ if (!thinkingContent) return null;
1409
+ return { role: "assistant", text: "", ...base, isThinking: true, thinkingContent };
1410
+ }
1411
+ default:
1412
+ return null;
1413
+ }
1414
+ }
1415
+ function codexToolUseBlock(payload) {
1416
+ if (payload.type === "web_search_call") {
1417
+ const action = payload.action;
1418
+ return {
1419
+ id: asString(payload.id),
1420
+ name: "web_search",
1421
+ input: action && typeof action === "object" ? action : {}
1422
+ };
1423
+ }
1424
+ const name = asString(payload.name);
1425
+ if (!name) return null;
1426
+ const id = asString(payload.call_id);
1427
+ if (payload.type === "custom_tool_call") {
1428
+ return { id, name, input: { input: asString(payload.input) } };
1429
+ }
1430
+ const args = asString(payload.arguments);
1431
+ let input = { arguments: args };
1432
+ try {
1433
+ const parsed = JSON.parse(args);
1434
+ if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) input = parsed;
1435
+ } catch {
1436
+ }
1437
+ return { id, name, input };
1438
+ }
1439
+ function codexToolOutputText(output) {
1440
+ if (typeof output === "string") return output;
1441
+ if (!Array.isArray(output)) return "";
1442
+ return output.map((item) => typeof item === "string" ? item : asString(item?.text)).filter(Boolean).join("\n");
1334
1443
  }
1335
1444
  function reduceCodexEntry(acc, entry, tier) {
1336
1445
  const ts = asString(entry.timestamp);
@@ -1470,6 +1579,7 @@ async function parseCodexConversation(filePath, account) {
1470
1579
  const message = codexEntryToMessage(entry);
1471
1580
  if (!message) continue;
1472
1581
  messages.push(message);
1582
+ if (!message.text) continue;
1473
1583
  textParts.push(message.text);
1474
1584
  if (message.role === "user") lastUserText = message.text;
1475
1585
  }
@@ -1494,14 +1604,434 @@ async function parseCodexConversation(filePath, account) {
1494
1604
  };
1495
1605
  }
1496
1606
 
1497
- // src/providers/parse.ts
1498
- import { createReadStream as createReadStream5 } from "fs";
1607
+ // src/providers/cursor.ts
1608
+ import { createHash as createHash2 } from "crypto";
1609
+ import fg3 from "fast-glob";
1610
+ import { createReadStream as createReadStream5, existsSync, statSync as statSync2 } from "fs";
1611
+ import { stat as stat3 } from "fs/promises";
1612
+ import { basename as basename5, dirname as dirname3, join as join4, sep as sep2 } from "path";
1499
1613
  import { createInterface as createInterface3 } from "readline";
1614
+ var TIMESTAMP_RE = /<timestamp>\s*([\s\S]*?)\s*<\/timestamp>/;
1615
+ var USER_QUERY_RE = /<user_query>\s*([\s\S]*?)\s*<\/user_query>/;
1616
+ var SUBAGENT_PATH_RE2 = /[\\/]subagents[\\/]/;
1617
+ var CursorProvider = class {
1618
+ name = CURSOR_PROVIDER;
1619
+ async discover(roots) {
1620
+ const log = getLogger();
1621
+ const results = [];
1622
+ for (const root of roots) {
1623
+ let paths;
1624
+ try {
1625
+ paths = await fg3(["**/agent-transcripts/**/*.jsonl"], {
1626
+ cwd: root,
1627
+ absolute: true,
1628
+ dot: false,
1629
+ unique: true
1630
+ });
1631
+ } catch (err) {
1632
+ log.warn({ root, err }, "cursor discovery: glob failed");
1633
+ continue;
1634
+ }
1635
+ for (const filePath of paths) {
1636
+ try {
1637
+ const s = await stat3(filePath);
1638
+ if (s.size > 0) results.push({ filePath: canonicalPath(filePath), account: "cursor" });
1639
+ } catch (err) {
1640
+ log.warn({ filePath, err }, "cursor discovery: stat failed");
1641
+ }
1642
+ }
1643
+ }
1644
+ return results;
1645
+ }
1646
+ canParse(filePath, sample) {
1647
+ const underTranscripts = /[\\/]agent-transcripts[\\/]/.test(filePath);
1648
+ for (const line of sample.split("\n")) {
1649
+ if (!line.trim()) continue;
1650
+ try {
1651
+ const e = JSON.parse(line);
1652
+ if (looksLikeImportedCodexEntry(e) || looksLikeImportedClaudeEntry(e)) {
1653
+ return underTranscripts;
1654
+ }
1655
+ if (looksLikeCursorChatEntry(e)) return true;
1656
+ } catch {
1657
+ }
1658
+ }
1659
+ return false;
1660
+ }
1661
+ createEmptyAccumulator() {
1662
+ return {
1663
+ sessionId: "",
1664
+ latestTimestamp: "",
1665
+ messageCount: 0,
1666
+ lastMessageSender: "user",
1667
+ isSubagent: false,
1668
+ parentSessionUuid: null,
1669
+ subagentId: null,
1670
+ firstUser: null,
1671
+ lastUser: null,
1672
+ lastAssistant: null,
1673
+ isImportedFromClaude: false,
1674
+ isImportedFromCodex: false,
1675
+ toolNames: [],
1676
+ previewParts: [],
1677
+ previewLength: 0,
1678
+ snippetParts: [],
1679
+ snippetLength: 0
1680
+ };
1681
+ }
1682
+ reduceEntry(acc, entry, tier) {
1683
+ reduceCursorEntry(acc, entry, tier);
1684
+ }
1685
+ finalize(acc, filePath, account, tier) {
1686
+ return finalizeCursorMeta(acc, filePath, account, tier);
1687
+ }
1688
+ };
1689
+ function looksLikeCursorChatEntry(entry) {
1690
+ const role = entry.role;
1691
+ if (role !== "user" && role !== "assistant") return false;
1692
+ if (entry.type === "user" || entry.type === "assistant") return false;
1693
+ return true;
1694
+ }
1695
+ function looksLikeImportedClaudeEntry(entry) {
1696
+ return entry.type === "user" || entry.type === "assistant";
1697
+ }
1698
+ function looksLikeImportedCodexEntry(entry) {
1699
+ return entry.type === "session_meta" || entry.type === "response_item" || entry.type === "event_msg";
1700
+ }
1701
+ function asString2(value) {
1702
+ return typeof value === "string" ? value : "";
1703
+ }
1704
+ function provenanceToken(value) {
1705
+ if (typeof value === "string") return value.trim().toLowerCase();
1706
+ if (value && typeof value === "object") {
1707
+ const rec = value;
1708
+ return provenanceToken(
1709
+ rec.importedFrom ?? rec.imported_from ?? rec.sourceProvider ?? rec.source
1710
+ );
1711
+ }
1712
+ return "";
1713
+ }
1714
+ function importedFromClaudeToken(token) {
1715
+ return token === "claude" || token === "claude-code" || token === "claude_code" || token === "anthropic";
1716
+ }
1717
+ function importedFromCodexToken(token) {
1718
+ return token === "codex" || token === "codex-cli" || token === "codex_cli" || token === "openai-codex";
1719
+ }
1720
+ function noteImportProvenance(acc, entry, text) {
1721
+ const token = provenanceToken(
1722
+ 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)
1723
+ );
1724
+ if (importedFromClaudeToken(token) || looksLikeImportedClaudeEntry(entry)) {
1725
+ acc.isImportedFromClaude = true;
1726
+ }
1727
+ if (importedFromCodexToken(token) || looksLikeImportedCodexEntry(entry)) {
1728
+ acc.isImportedFromCodex = true;
1729
+ }
1730
+ if (/imported from claude/i.test(text) || /<imported_from_claude>/i.test(text)) {
1731
+ acc.isImportedFromClaude = true;
1732
+ }
1733
+ if (/imported from codex/i.test(text) || /<imported_from_codex>/i.test(text)) {
1734
+ acc.isImportedFromCodex = true;
1735
+ }
1736
+ }
1737
+ function unwrapCursorUserText(text) {
1738
+ const query = text.match(USER_QUERY_RE);
1739
+ const body = query ? query[1] : text.replace(TIMESTAMP_RE, "");
1740
+ return cleanSystemTags(body);
1741
+ }
1742
+ function timestampFromCursorUserText(text) {
1743
+ const match = text.match(TIMESTAMP_RE);
1744
+ if (!match) return "";
1745
+ const parsed = Date.parse(match[1].trim());
1746
+ return Number.isNaN(parsed) ? "" : new Date(parsed).toISOString();
1747
+ }
1748
+ function extractCursorText(content) {
1749
+ if (typeof content === "string") return unwrapCursorUserText(content);
1750
+ if (!Array.isArray(content)) return "";
1751
+ return content.map((item) => {
1752
+ if (typeof item === "string") return unwrapCursorUserText(item);
1753
+ const block = item;
1754
+ if ((block?.type === "text" || block?.type === void 0) && typeof block.text === "string") {
1755
+ return unwrapCursorUserText(block.text);
1756
+ }
1757
+ return "";
1758
+ }).filter(Boolean).join(" ");
1759
+ }
1760
+ function collectCursorToolNames(content, into) {
1761
+ if (!Array.isArray(content)) return;
1762
+ for (const item of content) {
1763
+ const block = item;
1764
+ if (block?.type === "tool_use" && typeof block.name === "string" && block.name) {
1765
+ if (!into.includes(block.name)) into.push(block.name);
1766
+ }
1767
+ }
1768
+ }
1769
+ function firstTimestampHint(content) {
1770
+ if (typeof content === "string") return timestampFromCursorUserText(content);
1771
+ if (!Array.isArray(content)) return "";
1772
+ for (const item of content) {
1773
+ if (typeof item === "string") {
1774
+ const ts = timestampFromCursorUserText(item);
1775
+ if (ts) return ts;
1776
+ } else if (typeof item?.text === "string") {
1777
+ const ts = timestampFromCursorUserText(item.text);
1778
+ if (ts) return ts;
1779
+ }
1780
+ }
1781
+ return "";
1782
+ }
1783
+ function parseCursorJsonlLine(line) {
1784
+ if (!line.trim()) return null;
1785
+ let entry;
1786
+ try {
1787
+ entry = JSON.parse(line);
1788
+ } catch {
1789
+ return null;
1790
+ }
1791
+ return cursorEntryToMessage(entry);
1792
+ }
1793
+ function cursorEntryToMessage(entry) {
1794
+ if (looksLikeCursorChatEntry(entry)) {
1795
+ const role = entry.role;
1796
+ const message = entry.message;
1797
+ const content = message?.content ?? entry.content;
1798
+ return withToolUses(
1799
+ { role, text: extractCursorText(content), timestamp: firstTimestampHint(content) },
1800
+ content
1801
+ );
1802
+ }
1803
+ if (looksLikeImportedClaudeEntry(entry)) {
1804
+ const message = entry.message;
1805
+ const role = message?.role === "assistant" || entry.type === "assistant" ? "assistant" : "user";
1806
+ const content = message?.content ?? entry.content;
1807
+ return withToolUses(
1808
+ { role, text: extractCursorText(content), timestamp: asString2(entry.timestamp) },
1809
+ content
1810
+ );
1811
+ }
1812
+ return parseCodexJsonlLine(JSON.stringify(entry));
1813
+ }
1814
+ function withToolUses(message, content) {
1815
+ const blocks = extractCursorToolUseBlocks(content);
1816
+ if (blocks.length === 0) return message.text ? message : null;
1817
+ return {
1818
+ ...message,
1819
+ metadata: { toolUses: blocks.map((b) => b.name), toolUseBlocks: blocks }
1820
+ };
1821
+ }
1822
+ function extractCursorToolUseBlocks(content) {
1823
+ if (!Array.isArray(content)) return [];
1824
+ const blocks = [];
1825
+ for (const item of content) {
1826
+ const block = item;
1827
+ if (block?.type !== "tool_use" || typeof block.name !== "string" || !block.name) continue;
1828
+ const input = block.input && typeof block.input === "object" && !Array.isArray(block.input) ? block.input : {};
1829
+ const id = typeof block.id === "string" && block.id ? block.id : `cursor-tool-${createHash2("sha1").update(`${block.name}\0${JSON.stringify(input)}`).digest("hex").slice(0, 16)}`;
1830
+ blocks.push({ id, name: block.name, input });
1831
+ }
1832
+ return blocks;
1833
+ }
1834
+ function foldCursorMessage(acc, role, text, timestamp, tier) {
1835
+ if (timestamp && (!acc.latestTimestamp || timestamp > acc.latestTimestamp)) {
1836
+ acc.latestTimestamp = timestamp;
1837
+ }
1838
+ acc.messageCount++;
1839
+ acc.lastMessageSender = role;
1840
+ const snapshot = { text: text.slice(0, 200), timestamp };
1841
+ if (role === "user") {
1842
+ if (!acc.firstUser) acc.firstUser = snapshot;
1843
+ acc.lastUser = snapshot;
1844
+ } else {
1845
+ acc.lastAssistant = snapshot;
1846
+ }
1847
+ if (acc.previewLength < tier.previewMax) {
1848
+ acc.previewParts.push(text);
1849
+ acc.previewLength += text.length;
1850
+ }
1851
+ if (acc.snippetLength < tier.snippetMax) {
1852
+ const remaining = tier.snippetMax - acc.snippetLength;
1853
+ const chunk = text.length > remaining ? text.slice(0, remaining) : text;
1854
+ acc.snippetParts.push(chunk);
1855
+ acc.snippetLength += chunk.length;
1856
+ }
1857
+ }
1858
+ function reduceCursorEntry(acc, entry, tier) {
1859
+ const message = entry.message;
1860
+ const content = message?.content ?? entry.content;
1861
+ const textHint = extractCursorText(content);
1862
+ noteImportProvenance(acc, entry, textHint);
1863
+ if (looksLikeCursorChatEntry(entry)) {
1864
+ collectCursorToolNames(content, acc.toolNames);
1865
+ const text = textHint;
1866
+ if (!text) return;
1867
+ foldCursorMessage(acc, entry.role, text, firstTimestampHint(content), tier);
1868
+ return;
1869
+ }
1870
+ if (looksLikeImportedClaudeEntry(entry)) {
1871
+ collectCursorToolNames(content, acc.toolNames);
1872
+ const msg = cursorEntryToMessage(entry);
1873
+ if (!msg?.text) return;
1874
+ foldCursorMessage(acc, msg.role, msg.text, msg.timestamp, tier);
1875
+ return;
1876
+ }
1877
+ if (looksLikeImportedCodexEntry(entry)) {
1878
+ const msg = parseCodexJsonlLine(JSON.stringify(entry));
1879
+ if (!msg?.text) return;
1880
+ foldCursorMessage(acc, msg.role, msg.text, msg.timestamp, tier);
1881
+ }
1882
+ }
1883
+ function finalizeCursorMeta(acc, filePath, account, tier) {
1884
+ if (acc.messageCount === 0) return null;
1885
+ const sessionId = basename5(filePath, ".jsonl");
1886
+ const isSubagent = SUBAGENT_PATH_RE2.test(filePath);
1887
+ const parent = isSubagent ? parentFromSubagentPath(filePath) : null;
1888
+ const { projectPath, projectName } = projectFromCursorPath(filePath);
1889
+ const timestamp = acc.latestTimestamp || fileMtimeIso(filePath);
1890
+ const kind = acc.lastAssistant === null && acc.toolNames.length > 0 ? "task" : "conversation";
1891
+ return {
1892
+ id: filePath,
1893
+ filePath,
1894
+ provider: CURSOR_PROVIDER,
1895
+ kind,
1896
+ externalSessionId: sessionId,
1897
+ sessionId,
1898
+ sessionName: deriveSessionNameFromFirstMessage(acc.firstUser),
1899
+ projectPath,
1900
+ projectName,
1901
+ account,
1902
+ timestamp,
1903
+ messageCount: acc.messageCount,
1904
+ lastMessageSender: acc.lastMessageSender,
1905
+ preview: acc.previewParts.join(" ").slice(0, tier.previewMax),
1906
+ contentSnippet: acc.snippetParts.join(" "),
1907
+ gitBranch: null,
1908
+ model: null,
1909
+ isSubagent,
1910
+ parentSessionId: parent?.parentFilePath ?? null,
1911
+ subagentId: isSubagent ? sessionId : void 0,
1912
+ parentSessionUuid: parent?.parentSessionUuid ?? void 0,
1913
+ isTeammate: false,
1914
+ teamName: null,
1915
+ toolNames: acc.toolNames,
1916
+ firstMessage: acc.firstUser,
1917
+ lastMessage: acc.lastAssistant ?? acc.lastUser,
1918
+ lastPrompt: acc.lastUser?.text || void 0,
1919
+ ...acc.isImportedFromClaude ? { isImportedFromClaude: true } : {},
1920
+ ...acc.isImportedFromCodex ? { isImportedFromCodex: true } : {}
1921
+ };
1922
+ }
1923
+ function parentFromSubagentPath(filePath) {
1924
+ const subagentsDir = dirname3(filePath);
1925
+ const parentDir = dirname3(subagentsDir);
1926
+ const parentSessionUuid = basename5(parentDir);
1927
+ if (!parentSessionUuid) return null;
1928
+ return {
1929
+ parentSessionUuid,
1930
+ parentFilePath: canonicalPath(join4(parentDir, `${parentSessionUuid}.jsonl`))
1931
+ };
1932
+ }
1933
+ function projectFromCursorPath(filePath) {
1934
+ const parts = filePath.split(/[/\\]/);
1935
+ const idx = parts.lastIndexOf("agent-transcripts");
1936
+ const cursorProjectDir = idx > 0 ? parts.slice(0, idx).join(sep2) : dirname3(dirname3(filePath));
1937
+ const slug = basename5(cursorProjectDir);
1938
+ const decoded = decodeCursorProjectSlug(slug);
1939
+ const projectPath = decoded ?? cursorProjectDir;
1940
+ return { projectPath, projectName: getShortProjectName4(projectPath) || slug };
1941
+ }
1942
+ function decodeCursorProjectSlug(slug) {
1943
+ if (!slug) return null;
1944
+ const segments = slug.split("-");
1945
+ if (segments.length === 0) return null;
1946
+ const rooted = slug.startsWith("Users-") || slug.startsWith("home-") || /^[A-Za-z]-/.test(slug);
1947
+ let acc = rooted ? sep2 : "";
1948
+ let i = 0;
1949
+ if (rooted && segments[0] === "Users") {
1950
+ const users = `${sep2}Users`;
1951
+ if (!existsSync(users)) return null;
1952
+ acc = users;
1953
+ i = 1;
1954
+ }
1955
+ while (i < segments.length) {
1956
+ let found = null;
1957
+ let next = i + 1;
1958
+ for (let j = segments.length; j > i; j--) {
1959
+ const candidate = join4(acc, segments.slice(i, j).join("-"));
1960
+ try {
1961
+ if (existsSync(candidate) && statSync2(candidate).isDirectory()) {
1962
+ found = candidate;
1963
+ next = j;
1964
+ break;
1965
+ }
1966
+ } catch {
1967
+ }
1968
+ }
1969
+ if (!found) return null;
1970
+ acc = found;
1971
+ i = next;
1972
+ }
1973
+ return acc;
1974
+ }
1975
+ function getShortProjectName4(fullPath) {
1976
+ return fullPath.split(/[/\\]/).filter(Boolean).slice(-3).join("/");
1977
+ }
1978
+ function fileMtimeIso(filePath) {
1979
+ try {
1980
+ return new Date(statSync2(filePath).mtimeMs).toISOString();
1981
+ } catch {
1982
+ return (/* @__PURE__ */ new Date()).toISOString();
1983
+ }
1984
+ }
1985
+ async function parseCursorConversation(filePath, account) {
1986
+ const log = getLogger();
1987
+ const messages = [];
1988
+ const textParts = [];
1989
+ let latestTimestamp = "";
1990
+ let lastUserText = "";
1991
+ const rl = createInterface3({ input: createReadStream5(filePath), crlfDelay: Infinity });
1992
+ try {
1993
+ for await (const line of rl) {
1994
+ const message = parseCursorJsonlLine(line);
1995
+ if (!message) continue;
1996
+ if (message.timestamp && (!latestTimestamp || message.timestamp > latestTimestamp)) {
1997
+ latestTimestamp = message.timestamp;
1998
+ }
1999
+ messages.push(message);
2000
+ if (!message.text) continue;
2001
+ textParts.push(message.text);
2002
+ if (message.role === "user") lastUserText = message.text;
2003
+ }
2004
+ } catch (err) {
2005
+ log.warn({ filePath, err }, "parseCursorConversation: read failed");
2006
+ return null;
2007
+ }
2008
+ if (messages.length === 0) return null;
2009
+ const { projectPath, projectName } = projectFromCursorPath(filePath);
2010
+ const sessionId = basename5(filePath, ".jsonl");
2011
+ return {
2012
+ id: filePath,
2013
+ filePath,
2014
+ projectPath,
2015
+ projectName,
2016
+ sessionId,
2017
+ sessionName: "",
2018
+ messages,
2019
+ fullText: textParts.join(" "),
2020
+ timestamp: latestTimestamp || fileMtimeIso(filePath),
2021
+ messageCount: messages.length,
2022
+ account,
2023
+ lastPrompt: lastUserText || void 0
2024
+ };
2025
+ }
2026
+
2027
+ // src/providers/parse.ts
2028
+ import { createReadStream as createReadStream6 } from "fs";
2029
+ import { createInterface as createInterface4 } from "readline";
1500
2030
  async function parseMetaWithProvider(provider, filePath, account, tier, onEntry) {
1501
2031
  const log = getLogger();
1502
2032
  const acc = provider.createEmptyAccumulator();
1503
- const rl = createInterface3({
1504
- input: createReadStream5(filePath),
2033
+ const rl = createInterface4({
2034
+ input: createReadStream6(filePath),
1505
2035
  crlfDelay: Infinity
1506
2036
  });
1507
2037
  try {
@@ -1571,8 +2101,35 @@ function extractSearchDelta(entry) {
1571
2101
  if (entry.type === "response_item" || entry.type === "session_meta") {
1572
2102
  return extractCodexDelta(entry);
1573
2103
  }
2104
+ if (looksLikeCursorChatEntry(entry)) {
2105
+ return extractCursorDelta(entry);
2106
+ }
1574
2107
  return extractClaudeDelta(entry);
1575
2108
  }
2109
+ function extractCursorDelta(entry) {
2110
+ const msg = entry.message;
2111
+ const content = msg?.content ?? entry.content;
2112
+ return {
2113
+ text: extractCursorSearchText(content),
2114
+ thinking: "",
2115
+ tools: extractClaudeToolContent(content)
2116
+ };
2117
+ }
2118
+ function extractCursorSearchText(content) {
2119
+ if (typeof content === "string") return unwrapCursorUserText(content);
2120
+ if (!Array.isArray(content)) return "";
2121
+ const parts = [];
2122
+ for (const item of content) {
2123
+ if (typeof item === "string") {
2124
+ const cleaned = unwrapCursorUserText(item);
2125
+ if (cleaned) parts.push(cleaned);
2126
+ } else if ((item?.type === "text" || item?.type === void 0) && typeof item?.text === "string") {
2127
+ const cleaned = unwrapCursorUserText(item.text);
2128
+ if (cleaned) parts.push(cleaned);
2129
+ }
2130
+ }
2131
+ return parts.join(SEP);
2132
+ }
1576
2133
  function extractClaudeDelta(entry) {
1577
2134
  const type = entry.type;
1578
2135
  if (type !== "user" && type !== "assistant") return emptySearchDocument();
@@ -1690,10 +2247,10 @@ function resolveTier(tierName, customTiers) {
1690
2247
  // src/persistent/db.ts
1691
2248
  import Database from "better-sqlite3";
1692
2249
  import { mkdirSync } from "fs";
1693
- import { dirname as dirname3 } from "path";
2250
+ import { dirname as dirname4 } from "path";
1694
2251
 
1695
2252
  // src/persistent/schema.ts
1696
- var SCHEMA_VERSION = 7;
2253
+ var SCHEMA_VERSION = 9;
1697
2254
  var SCHEMA_SQL = `
1698
2255
  CREATE TABLE IF NOT EXISTS conversation_files (
1699
2256
  id INTEGER PRIMARY KEY AUTOINCREMENT,
@@ -1778,6 +2335,10 @@ CREATE TABLE IF NOT EXISTS conversations (
1778
2335
  tool_names_json TEXT,
1779
2336
  last_prompt TEXT,
1780
2337
 
2338
+ is_imported_from_claude INTEGER NOT NULL DEFAULT 0,
2339
+ is_imported_from_codex INTEGER NOT NULL DEFAULT 0,
2340
+ is_imported_from_cursor INTEGER NOT NULL DEFAULT 0,
2341
+
1781
2342
  status TEXT NOT NULL DEFAULT 'active',
1782
2343
 
1783
2344
  created_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP,
@@ -1943,6 +2504,45 @@ function runMigrations(db) {
1943
2504
  db.exec(`UPDATE conversation_files SET ${assignments.join(", ")}`);
1944
2505
  }
1945
2506
  }
2507
+ if (current >= 1 && current < 8 && tableExists(db, "conversations")) {
2508
+ for (const [col, ddl] of [
2509
+ [
2510
+ "is_imported_from_claude",
2511
+ "ALTER TABLE conversations ADD COLUMN is_imported_from_claude INTEGER NOT NULL DEFAULT 0"
2512
+ ],
2513
+ [
2514
+ "is_imported_from_codex",
2515
+ "ALTER TABLE conversations ADD COLUMN is_imported_from_codex INTEGER NOT NULL DEFAULT 0"
2516
+ ],
2517
+ [
2518
+ "is_imported_from_cursor",
2519
+ "ALTER TABLE conversations ADD COLUMN is_imported_from_cursor INTEGER NOT NULL DEFAULT 0"
2520
+ ]
2521
+ ]) {
2522
+ if (!hasColumn(db, "conversations", col)) db.exec(ddl);
2523
+ }
2524
+ if (tableExists(db, "conversation_files")) {
2525
+ const assignments = [];
2526
+ if (hasColumn(db, "conversation_files", "last_indexed_offset")) {
2527
+ assignments.push("last_indexed_offset = 0");
2528
+ }
2529
+ if (hasColumn(db, "conversation_files", "last_indexed_line")) {
2530
+ assignments.push("last_indexed_line = 0");
2531
+ }
2532
+ if (hasColumn(db, "conversation_files", "reducer_state")) {
2533
+ assignments.push("reducer_state = NULL");
2534
+ }
2535
+ if (assignments.length > 0) {
2536
+ db.exec(
2537
+ `UPDATE conversation_files SET ${assignments.join(", ")}
2538
+ WHERE id IN (SELECT file_id FROM conversations WHERE provider IN ('cursor', 'cursor-cli'))`
2539
+ );
2540
+ }
2541
+ }
2542
+ }
2543
+ if (current >= 1 && current < 9 && tableExists(db, "conversations")) {
2544
+ db.exec(`UPDATE conversations SET provider = 'cursor' WHERE provider = 'cursor-cli'`);
2545
+ }
1946
2546
  db.exec(SCHEMA_SQL);
1947
2547
  db.pragma(`user_version = ${SCHEMA_VERSION}`);
1948
2548
  }
@@ -1957,7 +2557,7 @@ function hasColumn(db, table, column) {
1957
2557
  // src/persistent/db.ts
1958
2558
  function openDatabase(dbPath) {
1959
2559
  if (dbPath !== ":memory:") {
1960
- mkdirSync(dirname3(dbPath), { recursive: true });
2560
+ mkdirSync(dirname4(dbPath), { recursive: true });
1961
2561
  }
1962
2562
  let db;
1963
2563
  try {
@@ -2001,8 +2601,8 @@ function nativeBindingError(err, dbPath) {
2001
2601
  }
2002
2602
 
2003
2603
  // src/persistent/dir-watermark.ts
2004
- import { readdir, stat as stat3 } from "fs/promises";
2005
- import { dirname as dirname4, join as join4 } from "path";
2604
+ import { readdir, stat as stat4 } from "fs/promises";
2605
+ import { dirname as dirname5, join as join5 } from "path";
2006
2606
  var FULL_RECONCILE_EVERY_N_SCANS = 20;
2007
2607
  async function discoverJsonlFilesGated(dirs, files, scannedDirs, options = {}) {
2008
2608
  const log = getLogger();
@@ -2018,7 +2618,7 @@ async function discoverJsonlFilesGated(dirs, files, scannedDirs, options = {}) {
2018
2618
  for (const projectDir of resolved.entries) {
2019
2619
  let dirStat;
2020
2620
  try {
2021
- dirStat = await stat3(projectDir);
2621
+ dirStat = await stat4(projectDir);
2022
2622
  } catch {
2023
2623
  scannedDirs.remove(projectDir);
2024
2624
  continue;
@@ -2056,7 +2656,7 @@ async function discoverJsonlFilesGated(dirs, files, scannedDirs, options = {}) {
2056
2656
  async function resolveProjectDirs(projectsDir, scannedDirs) {
2057
2657
  let rootStat;
2058
2658
  try {
2059
- rootStat = await stat3(projectsDir);
2659
+ rootStat = await stat4(projectsDir);
2060
2660
  } catch {
2061
2661
  return null;
2062
2662
  }
@@ -2073,10 +2673,10 @@ async function resolveProjectDirs(projectsDir, scannedDirs) {
2073
2673
  return { entries, commitRoot: { mtimeMs: rootStat.mtimeMs } };
2074
2674
  }
2075
2675
  function dirnameOf(filePath) {
2076
- return dirname4(filePath);
2676
+ return dirname5(filePath);
2077
2677
  }
2078
2678
  function joinPath(dir, name) {
2079
- return join4(dir, name);
2679
+ return join5(dir, name);
2080
2680
  }
2081
2681
 
2082
2682
  // src/persistent/repositories/checkpoints.repo.ts
@@ -2156,7 +2756,7 @@ function toCheckpoint(row) {
2156
2756
  }
2157
2757
 
2158
2758
  // src/persistent/repositories/conversation-files.repo.ts
2159
- import { basename as basename5, dirname as dirname5 } from "path";
2759
+ import { basename as basename6, dirname as dirname6 } from "path";
2160
2760
  var ConversationFilesRepo = class {
2161
2761
  constructor(db) {
2162
2762
  this.db = db;
@@ -2179,7 +2779,7 @@ var ConversationFilesRepo = class {
2179
2779
  const info = this.db.prepare(
2180
2780
  `INSERT INTO conversation_files (absolute_path, parent_dir, file_name, account)
2181
2781
  VALUES (?, ?, ?, ?)`
2182
- ).run(canonical, dirname5(canonical), basename5(canonical), account);
2782
+ ).run(canonical, dirname6(canonical), basename6(canonical), account);
2183
2783
  return Number(info.lastInsertRowid);
2184
2784
  }
2185
2785
  // Advance the cursor + persisted reducer state after a successful index pass.
@@ -2274,7 +2874,10 @@ function rowToMeta(row) {
2274
2874
  toolNames: row.tool_names_json ? JSON.parse(row.tool_names_json) : [],
2275
2875
  firstMessage: row.first_sent_text ? { text: row.first_sent_text, timestamp: row.first_sent_at ?? "" } : null,
2276
2876
  lastMessage: row.last_sent_text ? { text: row.last_sent_text, timestamp: row.last_sent_at ?? "" } : null,
2277
- lastPrompt: row.last_prompt ?? void 0
2877
+ lastPrompt: row.last_prompt ?? void 0,
2878
+ ...row.is_imported_from_claude === 1 ? { isImportedFromClaude: true } : {},
2879
+ ...row.is_imported_from_codex === 1 ? { isImportedFromCodex: true } : {},
2880
+ ...row.is_imported_from_cursor === 1 ? { isImportedFromCursor: true } : {}
2278
2881
  };
2279
2882
  }
2280
2883
  var ConversationsRepo = class {
@@ -2294,7 +2897,8 @@ var ConversationsRepo = class {
2294
2897
  timestamp, index_seq, first_sent_at, first_sent_text, last_sent_at, last_sent_text,
2295
2898
  model, is_subagent, parent_session_id, subagent_id, parent_session_uuid,
2296
2899
  is_teammate, team_name, tool_names_json,
2297
- last_prompt, status, updated_at
2900
+ last_prompt, is_imported_from_claude, is_imported_from_codex,
2901
+ is_imported_from_cursor, status, updated_at
2298
2902
  ) VALUES (
2299
2903
  @file_id, @source_path, @provider, @kind, @external_session_id,
2300
2904
  @session_id, @session_name, @project_path, @project_name,
@@ -2305,7 +2909,8 @@ var ConversationsRepo = class {
2305
2909
  @first_sent_at, @first_sent_text, @last_sent_at, @last_sent_text,
2306
2910
  @model, @is_subagent, @parent_session_id, @subagent_id, @parent_session_uuid,
2307
2911
  @is_teammate, @team_name, @tool_names_json,
2308
- @last_prompt, 'active', CURRENT_TIMESTAMP
2912
+ @last_prompt, @is_imported_from_claude, @is_imported_from_codex,
2913
+ @is_imported_from_cursor, 'active', CURRENT_TIMESTAMP
2309
2914
  )
2310
2915
  ON CONFLICT(file_id) DO UPDATE SET
2311
2916
  source_path = excluded.source_path,
@@ -2337,6 +2942,9 @@ var ConversationsRepo = class {
2337
2942
  team_name = excluded.team_name,
2338
2943
  tool_names_json = excluded.tool_names_json,
2339
2944
  last_prompt = excluded.last_prompt,
2945
+ is_imported_from_claude = excluded.is_imported_from_claude,
2946
+ is_imported_from_codex = excluded.is_imported_from_codex,
2947
+ is_imported_from_cursor = excluded.is_imported_from_cursor,
2340
2948
  status = 'active',
2341
2949
  index_seq = (SELECT COALESCE(MAX(index_seq), 0) + 1 FROM conversations),
2342
2950
  updated_at = CURRENT_TIMESTAMP`
@@ -2373,7 +2981,10 @@ var ConversationsRepo = class {
2373
2981
  is_teammate: meta.isTeammate ? 1 : 0,
2374
2982
  team_name: meta.teamName,
2375
2983
  tool_names_json: JSON.stringify(meta.toolNames),
2376
- last_prompt: meta.lastPrompt ?? null
2984
+ last_prompt: meta.lastPrompt ?? null,
2985
+ is_imported_from_claude: meta.isImportedFromClaude ? 1 : 0,
2986
+ is_imported_from_codex: meta.isImportedFromCodex ? 1 : 0,
2987
+ is_imported_from_cursor: meta.isImportedFromCursor ? 1 : 0
2377
2988
  });
2378
2989
  }
2379
2990
  getBySourcePath(sourcePath) {
@@ -2533,8 +3144,14 @@ var FtsRepo = class {
2533
3144
  params.push(filters.account);
2534
3145
  }
2535
3146
  if (filters.provider) {
2536
- where.push("c.provider = ?");
2537
- params.push(filters.provider);
3147
+ const provider = canonicalizeProviderName(filters.provider) ?? filters.provider;
3148
+ if (provider === CURSOR_PROVIDER) {
3149
+ where.push("(c.provider = ? OR c.provider = ?)");
3150
+ params.push(CURSOR_PROVIDER, LEGACY_CURSOR_PROVIDER);
3151
+ } else {
3152
+ where.push("c.provider = ?");
3153
+ params.push(provider);
3154
+ }
2538
3155
  }
2539
3156
  if (filters.project) {
2540
3157
  where.push("(lower(c.project_path) LIKE ? OR lower(c.project_name) LIKE ?)");
@@ -2686,7 +3303,7 @@ var PersistentEngine = class {
2686
3303
  async indexAll(activeProfiles, options) {
2687
3304
  const log = getLogger();
2688
3305
  const tier = resolveTier(options.tier ?? "standard", options.tiers);
2689
- const enabled = options.providers ?? [CLAUDE_CODE_PROVIDER];
3306
+ const enabled = canonicalizeProviderList(options.providers);
2690
3307
  const discovered = [];
2691
3308
  if (enabled.includes(CLAUDE_CODE_PROVIDER)) {
2692
3309
  const configDirs = activeProfiles.map((p) => ({
@@ -2706,6 +3323,12 @@ var PersistentEngine = class {
2706
3323
  discovered.push({ ...f, provider: codex });
2707
3324
  }
2708
3325
  }
3326
+ const cursor = new CursorProvider();
3327
+ if (enabled.includes(CURSOR_PROVIDER) && (options.cursorRoots?.length ?? 0) > 0) {
3328
+ for (const f of await cursor.discover(options.cursorRoots)) {
3329
+ discovered.push({ ...f, provider: cursor });
3330
+ }
3331
+ }
2709
3332
  let scanned = 0;
2710
3333
  const gitBranchMemo = /* @__PURE__ */ new Map();
2711
3334
  const resolveGitBranch = (projectPath) => {
@@ -2744,6 +3367,9 @@ var PersistentEngine = class {
2744
3367
  if (enabled.includes(CODEX_CLI_PROVIDER) && (options.codexRoots?.length ?? 0) > 0) {
2745
3368
  coveredAccounts.add("codex");
2746
3369
  }
3370
+ if (enabled.includes(CURSOR_PROVIDER) && (options.cursorRoots?.length ?? 0) > 0) {
3371
+ coveredAccounts.add("cursor");
3372
+ }
2747
3373
  const seen = new Set(discovered.map((d) => canonicalPath(d.filePath)));
2748
3374
  for (const path of this.files.activePathsByAccounts([...coveredAccounts])) {
2749
3375
  if (!seen.has(path)) this.markDeleted(path);
@@ -2763,8 +3389,8 @@ var PersistentEngine = class {
2763
3389
  const tier = resolveTier(tierName, customTiers);
2764
3390
  const filePath = canonicalPath(rawFilePath);
2765
3391
  const existing = this.files.getByPath(filePath);
2766
- const { change, stat: stat4 } = classify(filePath, existing);
2767
- if (change === "vanished" || !stat4) {
3392
+ const { change, stat: stat5 } = classify(filePath, existing);
3393
+ if (change === "vanished" || !stat5) {
2768
3394
  this.markDeleted(filePath);
2769
3395
  return { meta: null, change: "vanished" };
2770
3396
  }
@@ -2777,7 +3403,7 @@ var PersistentEngine = class {
2777
3403
  filePath,
2778
3404
  account,
2779
3405
  tier,
2780
- stat4,
3406
+ stat5,
2781
3407
  resolveGitBranch
2782
3408
  );
2783
3409
  return { meta: meta2, change };
@@ -2803,7 +3429,7 @@ var PersistentEngine = class {
2803
3429
  return { meta: null, change };
2804
3430
  }
2805
3431
  meta.gitBranch = resolveGitBranch(meta.projectPath);
2806
- const fp = stat4.size > 0 ? fingerprint(filePath, stat4.size) : null;
3432
+ const fp = stat5.size > 0 ? fingerprint(filePath, stat5.size) : null;
2807
3433
  const fileId = this.files.ensure(filePath, account);
2808
3434
  const base = resume ? this.fts.readDocument(fileId) ?? emptySearchDocument() : emptySearchDocument();
2809
3435
  const searchDoc = appendSearchDelta(base, searchDelta);
@@ -2814,8 +3440,8 @@ var PersistentEngine = class {
2814
3440
  }
2815
3441
  if (!resume) this.checkpoints.remove(filePath);
2816
3442
  this.files.updateCursor(fileId, {
2817
- sizeBytes: stat4.size,
2818
- mtimeMs: stat4.mtimeMs,
3443
+ sizeBytes: stat5.size,
3444
+ mtimeMs: stat5.mtimeMs,
2819
3445
  // Advance only to the last fully-parsed line; a trailing partial line
2820
3446
  // is left for the next pass.
2821
3447
  offset: result.newOffset,
@@ -2832,8 +3458,8 @@ var PersistentEngine = class {
2832
3458
  buildSidecar(
2833
3459
  meta,
2834
3460
  {
2835
- sizeBytes: stat4.size,
2836
- mtimeMs: stat4.mtimeMs,
3461
+ sizeBytes: stat5.size,
3462
+ mtimeMs: stat5.mtimeMs,
2837
3463
  offset: result.newOffset,
2838
3464
  line: result.newLine
2839
3465
  },
@@ -2852,7 +3478,7 @@ var PersistentEngine = class {
2852
3478
  // the Threadbase path uses. The cursor records size/mtime (and offset = size)
2853
3479
  // so the next pass classifies an unchanged file as "unchanged" and skips it;
2854
3480
  // any change reparses from 0 again. No reducer_state is persisted.
2855
- async indexFileWithProvider(provider, filePath, account, tier, stat4, resolveGitBranch) {
3481
+ async indexFileWithProvider(provider, filePath, account, tier, stat5, resolveGitBranch) {
2856
3482
  const log = getLogger();
2857
3483
  let searchDoc = emptySearchDocument();
2858
3484
  const meta = await parseMetaWithProvider(provider, filePath, account, tier, (entry) => {
@@ -2865,7 +3491,7 @@ var PersistentEngine = class {
2865
3491
  if (meta.gitBranch === null && meta.projectPath) {
2866
3492
  meta.gitBranch = resolveGitBranch(meta.projectPath);
2867
3493
  }
2868
- const fp = stat4.size > 0 ? fingerprint(filePath, stat4.size) : null;
3494
+ const fp = stat5.size > 0 ? fingerprint(filePath, stat5.size) : null;
2869
3495
  const fileId = this.files.ensure(filePath, account);
2870
3496
  const upsert = this.db.transaction(() => {
2871
3497
  this.conversations.upsert(fileId, meta, meta.messageCount);
@@ -2874,11 +3500,11 @@ var PersistentEngine = class {
2874
3500
  }
2875
3501
  this.checkpoints.remove(filePath);
2876
3502
  this.files.updateCursor(fileId, {
2877
- sizeBytes: stat4.size,
2878
- mtimeMs: stat4.mtimeMs,
3503
+ sizeBytes: stat5.size,
3504
+ mtimeMs: stat5.mtimeMs,
2879
3505
  // offset = size marks the file fully consumed (non-zero so the next pass
2880
3506
  // can classify it "unchanged"); no resumable reducer state is kept.
2881
- offset: stat4.size,
3507
+ offset: stat5.size,
2882
3508
  line: 0,
2883
3509
  reducerState: null,
2884
3510
  fingerprint: fp,
@@ -2944,8 +3570,8 @@ var PersistentEngine = class {
2944
3570
  const meta = this.conversations.getByIdOrSession(id);
2945
3571
  if (!meta) return null;
2946
3572
  const filePath = meta.filePath;
2947
- if (meta.provider === CODEX_CLI_PROVIDER) {
2948
- const conversation = await parseCodexConversation(filePath, meta.account);
3573
+ if (meta.provider === CODEX_CLI_PROVIDER || meta.provider === CURSOR_PROVIDER) {
3574
+ const conversation = meta.provider === CODEX_CLI_PROVIDER ? await parseCodexConversation(filePath, meta.account) : await parseCursorConversation(filePath, meta.account);
2949
3575
  if (!conversation) return null;
2950
3576
  const { messages } = conversation;
2951
3577
  const total2 = messages.length;
@@ -2960,7 +3586,7 @@ var PersistentEngine = class {
2960
3586
  let floor = this.checkpoints.floor(filePath, fromIndex);
2961
3587
  if (floor) {
2962
3588
  try {
2963
- if (floor.byteOffset > statSync2(filePath).size) floor = null;
3589
+ if (floor.byteOffset > statSync3(filePath).size) floor = null;
2964
3590
  } catch {
2965
3591
  }
2966
3592
  }
@@ -3135,7 +3761,7 @@ function defaultDbPath() {
3135
3761
  "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."
3136
3762
  );
3137
3763
  }
3138
- return join5(homedir2(), ".config", "threadbase-scanner", "index.db");
3764
+ return join6(homedir2(), ".config", "threadbase-scanner", "index.db");
3139
3765
  }
3140
3766
  function capForMemory(doc, max) {
3141
3767
  const combined = combineSearchContent(doc);
@@ -3314,7 +3940,7 @@ var ConversationScanner = class {
3314
3940
  const cached = statCache.get(filePath);
3315
3941
  if (cached) {
3316
3942
  try {
3317
- const s = statSync3(filePath);
3943
+ const s = statSync4(filePath);
3318
3944
  if (s.mtimeMs === cached.stat.mtimeMs && s.size === cached.stat.size) {
3319
3945
  return {
3320
3946
  meta: cached.meta,
@@ -3445,9 +4071,7 @@ var ConversationScanner = class {
3445
4071
  results = results.filter((r) => r.meta.account === options.account);
3446
4072
  }
3447
4073
  if (options.provider) {
3448
- results = results.filter(
3449
- (r) => (r.meta.provider ?? CLAUDE_CODE_PROVIDER) === options.provider
3450
- );
4074
+ results = results.filter((r) => providerMatches(r.meta.provider, options.provider));
3451
4075
  }
3452
4076
  if (options.since) {
3453
4077
  const cutoff = parseSinceCutoff(options.since);
@@ -3474,12 +4098,12 @@ var ConversationScanner = class {
3474
4098
  }
3475
4099
  log.debug({ id, filePath: meta.filePath }, "getConversation: cache miss, parsing");
3476
4100
  try {
3477
- if (this.persistent && meta.provider !== CODEX_CLI_PROVIDER) {
4101
+ if (this.persistent && meta.provider !== CODEX_CLI_PROVIDER && meta.provider !== CURSOR_PROVIDER) {
3478
4102
  const parsed = await parseConversationResumable(meta.filePath, meta.account);
3479
4103
  if (parsed) this.conversationLRU.set(cid, parsed);
3480
4104
  return parsed?.conversation ?? null;
3481
4105
  }
3482
- const conversation = meta.provider === CODEX_CLI_PROVIDER ? await parseCodexConversation(meta.filePath, meta.account) : await parseConversation(meta.filePath, meta.account);
4106
+ 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);
3483
4107
  if (conversation) {
3484
4108
  this.conversationLRU.set(cid, { conversation });
3485
4109
  }
@@ -3533,7 +4157,7 @@ var ConversationScanner = class {
3533
4157
  // fallback, matching refreshFile.
3534
4158
  async parseSingleFilePage(filePath, account, options) {
3535
4159
  const provider = await this.resolveProviderForFile(filePath, null);
3536
- const conversation = provider?.name === CODEX_CLI_PROVIDER ? await parseCodexConversation(filePath, account ?? "default") : await parseConversation(filePath, account ?? "default");
4160
+ 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");
3537
4161
  if (!conversation) return null;
3538
4162
  const { messages } = conversation;
3539
4163
  const total = messages.length;
@@ -3822,7 +4446,7 @@ var ConversationScanner = class {
3822
4446
  // discovers under the active profiles' project dirs; Codex discovers under
3823
4447
  // the explicit codexRoots (opt-in — no default home scan).
3824
4448
  async discoverWithProviders(activeProfiles, options) {
3825
- const enabled = options.providers ?? [CLAUDE_CODE_PROVIDER];
4449
+ const enabled = canonicalizeProviderList(options.providers);
3826
4450
  const work = [];
3827
4451
  if (enabled.includes(CLAUDE_CODE_PROVIDER)) {
3828
4452
  const provider = new ThreadbaseProvider();
@@ -3837,6 +4461,12 @@ var ConversationScanner = class {
3837
4461
  work.push({ ...f, provider });
3838
4462
  }
3839
4463
  }
4464
+ if (enabled.includes(CURSOR_PROVIDER) && (options.cursorRoots?.length ?? 0) > 0) {
4465
+ const provider = new CursorProvider();
4466
+ for (const f of await provider.discover(options.cursorRoots)) {
4467
+ work.push({ ...f, provider });
4468
+ }
4469
+ }
3840
4470
  return work;
3841
4471
  }
3842
4472
  // Resolve which provider should (re)parse a file. Stored metadata wins; for a
@@ -3845,6 +4475,9 @@ var ConversationScanner = class {
3845
4475
  // tail-read path).
3846
4476
  async resolveProviderForFile(filePath, previous) {
3847
4477
  if (previous?.provider === CODEX_CLI_PROVIDER) return new CodexCliProvider();
4478
+ if (providerMatches(previous?.provider, CURSOR_PROVIDER)) {
4479
+ return new CursorProvider();
4480
+ }
3848
4481
  if (previous?.provider) return void 0;
3849
4482
  let sample = "";
3850
4483
  try {
@@ -3859,6 +4492,8 @@ var ConversationScanner = class {
3859
4492
  } catch {
3860
4493
  return void 0;
3861
4494
  }
4495
+ const cursor = new CursorProvider();
4496
+ if (cursor.canParse(filePath, sample)) return cursor;
3862
4497
  const codex = new CodexCliProvider();
3863
4498
  if (codex.canParse(filePath, sample)) return codex;
3864
4499
  return void 0;