@threadbase-sh/scanner 0.19.4 → 0.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -362,10 +362,11 @@ import { basename, dirname as dirname2, join as join2 } from "path";
362
362
  var CLAUDE_CODE_PROVIDER = "claude-code";
363
363
  var CODEX_CLI_PROVIDER = "codex-cli";
364
364
  var CURSOR_PROVIDER = "cursor";
365
+ var COPILOT_PROVIDER = "copilot";
365
366
  var LEGACY_CURSOR_PROVIDER = "cursor-cli";
366
367
  function canonicalizeProviderName(value) {
367
368
  if (value === LEGACY_CURSOR_PROVIDER) return CURSOR_PROVIDER;
368
- if (value === CLAUDE_CODE_PROVIDER || value === CODEX_CLI_PROVIDER || value === CURSOR_PROVIDER) {
369
+ if (value === CLAUDE_CODE_PROVIDER || value === CODEX_CLI_PROVIDER || value === CURSOR_PROVIDER || value === COPILOT_PROVIDER) {
369
370
  return value;
370
371
  }
371
372
  return void 0;
@@ -1287,13 +1288,293 @@ async function parseCodexConversation(filePath, account) {
1287
1288
  };
1288
1289
  }
1289
1290
 
1290
- // src/providers/cursor.ts
1291
- import { createHash } from "crypto";
1291
+ // src/providers/copilot.ts
1292
1292
  import fg2 from "fast-glob";
1293
- import { createReadStream as createReadStream3, existsSync, statSync } from "fs";
1293
+ import { createReadStream as createReadStream3, statSync } from "fs";
1294
1294
  import { stat as stat2 } from "fs/promises";
1295
- import { basename as basename4, dirname as dirname3, join as join4, sep as sep2 } from "path";
1295
+ import { basename as basename4, dirname as dirname3 } from "path";
1296
1296
  import { createInterface as createInterface3 } from "readline";
1297
+ var SESSION_START = "session.start";
1298
+ var USER_MESSAGE = "user.message";
1299
+ var ASSISTANT_MESSAGE = "assistant.message";
1300
+ var CopilotProvider = class {
1301
+ name = COPILOT_PROVIDER;
1302
+ async discover(roots) {
1303
+ const log = getLogger();
1304
+ const results = [];
1305
+ for (const root of roots) {
1306
+ let paths;
1307
+ try {
1308
+ paths = await fg2(["*/events.jsonl", "session-state/*/events.jsonl"], {
1309
+ cwd: root,
1310
+ absolute: true,
1311
+ dot: false,
1312
+ unique: true
1313
+ });
1314
+ } catch (err) {
1315
+ log.warn({ root, err }, "copilot discovery: glob failed");
1316
+ continue;
1317
+ }
1318
+ for (const filePath of paths) {
1319
+ try {
1320
+ const s = await stat2(filePath);
1321
+ if (s.size > 0) results.push({ filePath: canonicalPath(filePath), account: "copilot" });
1322
+ } catch (err) {
1323
+ log.warn({ filePath, err }, "copilot discovery: stat failed");
1324
+ }
1325
+ }
1326
+ }
1327
+ return results;
1328
+ }
1329
+ canParse(_filePath, sample) {
1330
+ for (const line of sample.split("\n")) {
1331
+ if (!line.trim()) continue;
1332
+ try {
1333
+ if (looksLikeCopilotEvent(JSON.parse(line))) return true;
1334
+ } catch {
1335
+ }
1336
+ }
1337
+ return false;
1338
+ }
1339
+ createEmptyAccumulator() {
1340
+ return {
1341
+ sessionId: "",
1342
+ cwd: "",
1343
+ gitBranch: null,
1344
+ model: null,
1345
+ latestTimestamp: "",
1346
+ messageCount: 0,
1347
+ lastMessageSender: "user",
1348
+ firstUser: null,
1349
+ lastUser: null,
1350
+ lastAssistant: null,
1351
+ toolNames: [],
1352
+ previewParts: [],
1353
+ previewLength: 0,
1354
+ snippetParts: [],
1355
+ snippetLength: 0
1356
+ };
1357
+ }
1358
+ reduceEntry(acc, entry, tier) {
1359
+ reduceCopilotEntry(acc, entry, tier);
1360
+ }
1361
+ finalize(acc, filePath, account, tier) {
1362
+ return finalizeCopilotMeta(acc, filePath, account, tier);
1363
+ }
1364
+ };
1365
+ function looksLikeCopilotEvent(entry) {
1366
+ return typeof entry.type === "string" && typeof entry.id === "string" && "parentId" in entry && asRecord(entry.data) !== null;
1367
+ }
1368
+ var asString2 = (v) => typeof v === "string" ? v : "";
1369
+ function asRecord(v) {
1370
+ return v && typeof v === "object" && !Array.isArray(v) ? v : null;
1371
+ }
1372
+ function copilotToolUseBlocks(data) {
1373
+ if (!Array.isArray(data.toolRequests)) return [];
1374
+ const blocks = [];
1375
+ for (const item of data.toolRequests) {
1376
+ const request = asRecord(item);
1377
+ const name = asString2(request?.name);
1378
+ if (!request || !name) continue;
1379
+ const input = asRecord(request.arguments) ?? { arguments: asString2(request.arguments) };
1380
+ blocks.push({ id: asString2(request.toolCallId), name, input });
1381
+ }
1382
+ return blocks;
1383
+ }
1384
+ function copilotEntryToMessage(entry) {
1385
+ if (!looksLikeCopilotEvent(entry)) return null;
1386
+ const data = entry.data;
1387
+ const timestamp = asString2(entry.timestamp);
1388
+ const uuid = asString2(data.messageId) || asString2(entry.id);
1389
+ if (entry.type === USER_MESSAGE) {
1390
+ const text = cleanSystemTags(asString2(data.content));
1391
+ return text ? { role: "user", text, timestamp, uuid } : null;
1392
+ }
1393
+ if (entry.type === ASSISTANT_MESSAGE) {
1394
+ const text = asString2(data.content).trim();
1395
+ const blocks = copilotToolUseBlocks(data);
1396
+ if (!text && blocks.length === 0) return null;
1397
+ const model = asString2(data.model);
1398
+ const metadata = {
1399
+ ...model ? { model } : {},
1400
+ ...blocks.length > 0 ? { toolUses: blocks.map((b) => b.name), toolUseBlocks: blocks } : {}
1401
+ };
1402
+ return {
1403
+ role: "assistant",
1404
+ text,
1405
+ timestamp,
1406
+ uuid,
1407
+ ...Object.keys(metadata).length > 0 ? { metadata } : {}
1408
+ };
1409
+ }
1410
+ return null;
1411
+ }
1412
+ function parseCopilotJsonlLine(line) {
1413
+ const trimmed = line.trim();
1414
+ if (!trimmed) return null;
1415
+ try {
1416
+ return copilotEntryToMessage(JSON.parse(trimmed));
1417
+ } catch {
1418
+ return null;
1419
+ }
1420
+ }
1421
+ function readSessionStart(entry) {
1422
+ if (entry.type !== SESSION_START) return null;
1423
+ const data = asRecord(entry.data);
1424
+ if (!data) return null;
1425
+ const context = asRecord(data.context);
1426
+ return {
1427
+ sessionId: asString2(data.sessionId),
1428
+ cwd: asString2(context?.cwd),
1429
+ branch: asString2(context?.branch)
1430
+ };
1431
+ }
1432
+ function reduceCopilotEntry(acc, entry, tier) {
1433
+ const start = readSessionStart(entry);
1434
+ if (start) {
1435
+ if (!acc.sessionId) acc.sessionId = start.sessionId;
1436
+ if (!acc.cwd) acc.cwd = start.cwd;
1437
+ if (!acc.gitBranch && start.branch) acc.gitBranch = start.branch;
1438
+ return;
1439
+ }
1440
+ const message = copilotEntryToMessage(entry);
1441
+ if (!message) return;
1442
+ for (const name of message.metadata?.toolUses ?? []) {
1443
+ if (!acc.toolNames.includes(name)) acc.toolNames.push(name);
1444
+ }
1445
+ if (message.metadata?.model) acc.model = message.metadata.model;
1446
+ const { role, text, timestamp } = message;
1447
+ if (!text) return;
1448
+ if (timestamp && (!acc.latestTimestamp || timestamp > acc.latestTimestamp)) {
1449
+ acc.latestTimestamp = timestamp;
1450
+ }
1451
+ acc.messageCount++;
1452
+ acc.lastMessageSender = role;
1453
+ const snapshot = { text: text.slice(0, 200), timestamp };
1454
+ if (role === "user") {
1455
+ if (!acc.firstUser) acc.firstUser = snapshot;
1456
+ acc.lastUser = snapshot;
1457
+ } else {
1458
+ acc.lastAssistant = snapshot;
1459
+ }
1460
+ if (acc.previewLength < tier.previewMax) {
1461
+ acc.previewParts.push(text);
1462
+ acc.previewLength += text.length;
1463
+ }
1464
+ if (acc.snippetLength < tier.snippetMax) {
1465
+ const remaining = tier.snippetMax - acc.snippetLength;
1466
+ const chunk = text.length > remaining ? text.slice(0, remaining) : text;
1467
+ acc.snippetParts.push(chunk);
1468
+ acc.snippetLength += chunk.length;
1469
+ }
1470
+ }
1471
+ function finalizeCopilotMeta(acc, filePath, account, tier) {
1472
+ if (acc.messageCount === 0) return null;
1473
+ const sessionId = acc.sessionId || sessionIdFromPath(filePath);
1474
+ const kind = acc.lastAssistant === null && acc.toolNames.length > 0 ? "task" : "conversation";
1475
+ return {
1476
+ id: filePath,
1477
+ filePath,
1478
+ provider: COPILOT_PROVIDER,
1479
+ kind,
1480
+ externalSessionId: sessionId,
1481
+ sessionId,
1482
+ sessionName: deriveSessionNameFromFirstMessage(acc.firstUser),
1483
+ projectPath: acc.cwd,
1484
+ projectName: getShortProjectName4(acc.cwd),
1485
+ account,
1486
+ timestamp: acc.latestTimestamp || fileMtimeIso(filePath),
1487
+ messageCount: acc.messageCount,
1488
+ lastMessageSender: acc.lastMessageSender,
1489
+ preview: acc.previewParts.join(" ").slice(0, tier.previewMax),
1490
+ contentSnippet: acc.snippetParts.join(" "),
1491
+ gitBranch: acc.gitBranch,
1492
+ model: acc.model,
1493
+ isSubagent: false,
1494
+ parentSessionId: null,
1495
+ isTeammate: false,
1496
+ teamName: null,
1497
+ toolNames: acc.toolNames,
1498
+ firstMessage: acc.firstUser,
1499
+ lastMessage: acc.lastAssistant ?? acc.lastUser,
1500
+ lastPrompt: acc.lastUser?.text || void 0
1501
+ };
1502
+ }
1503
+ function sessionIdFromPath(filePath) {
1504
+ return basename4(dirname3(filePath));
1505
+ }
1506
+ function getShortProjectName4(fullPath) {
1507
+ return fullPath.split(/[/\\]/).filter(Boolean).slice(-3).join("/");
1508
+ }
1509
+ function fileMtimeIso(filePath) {
1510
+ try {
1511
+ return new Date(statSync(filePath).mtimeMs).toISOString();
1512
+ } catch {
1513
+ return (/* @__PURE__ */ new Date()).toISOString();
1514
+ }
1515
+ }
1516
+ async function parseCopilotConversation(filePath, account) {
1517
+ const log = getLogger();
1518
+ const messages = [];
1519
+ const textParts = [];
1520
+ let sessionId = "";
1521
+ let cwd = "";
1522
+ let latestTimestamp = "";
1523
+ let lastUserText = "";
1524
+ const rl = createInterface3({ input: createReadStream3(filePath), crlfDelay: Infinity });
1525
+ try {
1526
+ for await (const line of rl) {
1527
+ if (!line.trim()) continue;
1528
+ let entry;
1529
+ try {
1530
+ entry = JSON.parse(line);
1531
+ } catch {
1532
+ continue;
1533
+ }
1534
+ const start = readSessionStart(entry);
1535
+ if (start) {
1536
+ if (!sessionId) sessionId = start.sessionId;
1537
+ if (!cwd) cwd = start.cwd;
1538
+ continue;
1539
+ }
1540
+ const message = copilotEntryToMessage(entry);
1541
+ if (!message) continue;
1542
+ if (message.timestamp && (!latestTimestamp || message.timestamp > latestTimestamp)) {
1543
+ latestTimestamp = message.timestamp;
1544
+ }
1545
+ messages.push(message);
1546
+ if (!message.text) continue;
1547
+ textParts.push(message.text);
1548
+ if (message.role === "user") lastUserText = message.text;
1549
+ }
1550
+ } catch (err) {
1551
+ log.warn({ filePath, err }, "parseCopilotConversation: read failed");
1552
+ return null;
1553
+ }
1554
+ if (messages.length === 0) return null;
1555
+ return {
1556
+ id: filePath,
1557
+ filePath,
1558
+ projectPath: cwd,
1559
+ projectName: getShortProjectName4(cwd),
1560
+ sessionId: sessionId || sessionIdFromPath(filePath),
1561
+ sessionName: "",
1562
+ messages,
1563
+ fullText: textParts.join(" "),
1564
+ timestamp: latestTimestamp || fileMtimeIso(filePath),
1565
+ messageCount: messages.length,
1566
+ account,
1567
+ lastPrompt: lastUserText || void 0
1568
+ };
1569
+ }
1570
+
1571
+ // src/providers/cursor.ts
1572
+ import { createHash } from "crypto";
1573
+ import fg3 from "fast-glob";
1574
+ import { createReadStream as createReadStream4, existsSync, statSync as statSync2 } from "fs";
1575
+ import { stat as stat3 } from "fs/promises";
1576
+ import { basename as basename5, dirname as dirname4, join as join4, sep as sep2 } from "path";
1577
+ import { createInterface as createInterface4 } from "readline";
1297
1578
  var TIMESTAMP_RE = /<timestamp>\s*([\s\S]*?)\s*<\/timestamp>/;
1298
1579
  var USER_QUERY_RE = /<user_query>\s*([\s\S]*?)\s*<\/user_query>/;
1299
1580
  var SUBAGENT_PATH_RE2 = /[\\/]subagents[\\/]/;
@@ -1305,7 +1586,7 @@ var CursorProvider = class {
1305
1586
  for (const root of roots) {
1306
1587
  let paths;
1307
1588
  try {
1308
- paths = await fg2(["**/agent-transcripts/**/*.jsonl"], {
1589
+ paths = await fg3(["**/agent-transcripts/**/*.jsonl"], {
1309
1590
  cwd: root,
1310
1591
  absolute: true,
1311
1592
  dot: false,
@@ -1317,7 +1598,7 @@ var CursorProvider = class {
1317
1598
  }
1318
1599
  for (const filePath of paths) {
1319
1600
  try {
1320
- const s = await stat2(filePath);
1601
+ const s = await stat3(filePath);
1321
1602
  if (s.size > 0) results.push({ filePath: canonicalPath(filePath), account: "cursor" });
1322
1603
  } catch (err) {
1323
1604
  log.warn({ filePath, err }, "cursor discovery: stat failed");
@@ -1381,7 +1662,7 @@ function looksLikeImportedClaudeEntry(entry) {
1381
1662
  function looksLikeImportedCodexEntry(entry) {
1382
1663
  return entry.type === "session_meta" || entry.type === "response_item" || entry.type === "event_msg";
1383
1664
  }
1384
- function asString2(value) {
1665
+ function asString3(value) {
1385
1666
  return typeof value === "string" ? value : "";
1386
1667
  }
1387
1668
  function provenanceToken(value) {
@@ -1495,7 +1776,7 @@ function cursorEntryToMessage(entry) {
1495
1776
  const role = message?.role === "assistant" || entry.type === "assistant" ? "assistant" : "user";
1496
1777
  const content = message?.content ?? entry.content;
1497
1778
  return withToolUses(
1498
- { role, text: extractCursorText(content), timestamp: asString2(entry.timestamp) },
1779
+ { role, text: extractCursorText(content), timestamp: asString3(entry.timestamp) },
1499
1780
  content
1500
1781
  );
1501
1782
  }
@@ -1572,11 +1853,11 @@ function reduceCursorEntry(acc, entry, tier) {
1572
1853
  }
1573
1854
  function finalizeCursorMeta(acc, filePath, account, tier) {
1574
1855
  if (acc.messageCount === 0) return null;
1575
- const sessionId = basename4(filePath, ".jsonl");
1856
+ const sessionId = basename5(filePath, ".jsonl");
1576
1857
  const isSubagent = SUBAGENT_PATH_RE2.test(filePath);
1577
1858
  const parent = isSubagent ? parentFromSubagentPath(filePath) : null;
1578
1859
  const { projectPath, projectName } = projectFromCursorPath(filePath);
1579
- const timestamp = acc.latestTimestamp || fileMtimeIso(filePath);
1860
+ const timestamp = acc.latestTimestamp || fileMtimeIso2(filePath);
1580
1861
  const kind = acc.lastAssistant === null && acc.toolNames.length > 0 ? "task" : "conversation";
1581
1862
  return {
1582
1863
  id: filePath,
@@ -1611,9 +1892,9 @@ function finalizeCursorMeta(acc, filePath, account, tier) {
1611
1892
  };
1612
1893
  }
1613
1894
  function parentFromSubagentPath(filePath) {
1614
- const subagentsDir = dirname3(filePath);
1615
- const parentDir = dirname3(subagentsDir);
1616
- const parentSessionUuid = basename4(parentDir);
1895
+ const subagentsDir = dirname4(filePath);
1896
+ const parentDir = dirname4(subagentsDir);
1897
+ const parentSessionUuid = basename5(parentDir);
1617
1898
  if (!parentSessionUuid) return null;
1618
1899
  return {
1619
1900
  parentSessionUuid,
@@ -1623,11 +1904,11 @@ function parentFromSubagentPath(filePath) {
1623
1904
  function projectFromCursorPath(filePath) {
1624
1905
  const parts = filePath.split(/[/\\]/);
1625
1906
  const idx = parts.lastIndexOf("agent-transcripts");
1626
- const cursorProjectDir = idx > 0 ? parts.slice(0, idx).join(sep2) : dirname3(dirname3(filePath));
1627
- const slug = basename4(cursorProjectDir);
1907
+ const cursorProjectDir = idx > 0 ? parts.slice(0, idx).join(sep2) : dirname4(dirname4(filePath));
1908
+ const slug = basename5(cursorProjectDir);
1628
1909
  const decoded = decodeCursorProjectSlug(slug);
1629
1910
  const projectPath = decoded ?? cursorProjectDir;
1630
- return { projectPath, projectName: getShortProjectName4(projectPath) || slug };
1911
+ return { projectPath, projectName: getShortProjectName5(projectPath) || slug };
1631
1912
  }
1632
1913
  function decodeCursorProjectSlug(slug) {
1633
1914
  if (!slug) return null;
@@ -1648,7 +1929,7 @@ function decodeCursorProjectSlug(slug) {
1648
1929
  for (let j = segments.length; j > i; j--) {
1649
1930
  const candidate = join4(acc, segments.slice(i, j).join("-"));
1650
1931
  try {
1651
- if (existsSync(candidate) && statSync(candidate).isDirectory()) {
1932
+ if (existsSync(candidate) && statSync2(candidate).isDirectory()) {
1652
1933
  found = candidate;
1653
1934
  next = j;
1654
1935
  break;
@@ -1662,12 +1943,12 @@ function decodeCursorProjectSlug(slug) {
1662
1943
  }
1663
1944
  return acc;
1664
1945
  }
1665
- function getShortProjectName4(fullPath) {
1946
+ function getShortProjectName5(fullPath) {
1666
1947
  return fullPath.split(/[/\\]/).filter(Boolean).slice(-3).join("/");
1667
1948
  }
1668
- function fileMtimeIso(filePath) {
1949
+ function fileMtimeIso2(filePath) {
1669
1950
  try {
1670
- return new Date(statSync(filePath).mtimeMs).toISOString();
1951
+ return new Date(statSync2(filePath).mtimeMs).toISOString();
1671
1952
  } catch {
1672
1953
  return (/* @__PURE__ */ new Date()).toISOString();
1673
1954
  }
@@ -1678,7 +1959,7 @@ async function parseCursorConversation(filePath, account) {
1678
1959
  const textParts = [];
1679
1960
  let latestTimestamp = "";
1680
1961
  let lastUserText = "";
1681
- const rl = createInterface3({ input: createReadStream3(filePath), crlfDelay: Infinity });
1962
+ const rl = createInterface4({ input: createReadStream4(filePath), crlfDelay: Infinity });
1682
1963
  try {
1683
1964
  for await (const line of rl) {
1684
1965
  const message = parseCursorJsonlLine(line, messages.length);
@@ -1697,7 +1978,7 @@ async function parseCursorConversation(filePath, account) {
1697
1978
  }
1698
1979
  if (messages.length === 0) return null;
1699
1980
  const { projectPath, projectName } = projectFromCursorPath(filePath);
1700
- const sessionId = basename4(filePath, ".jsonl");
1981
+ const sessionId = basename5(filePath, ".jsonl");
1701
1982
  return {
1702
1983
  id: filePath,
1703
1984
  filePath,
@@ -1707,7 +1988,7 @@ async function parseCursorConversation(filePath, account) {
1707
1988
  sessionName: "",
1708
1989
  messages,
1709
1990
  fullText: textParts.join(" "),
1710
- timestamp: latestTimestamp || fileMtimeIso(filePath),
1991
+ timestamp: latestTimestamp || fileMtimeIso2(filePath),
1711
1992
  messageCount: messages.length,
1712
1993
  account,
1713
1994
  lastPrompt: lastUserText || void 0
@@ -1715,8 +1996,8 @@ async function parseCursorConversation(filePath, account) {
1715
1996
  }
1716
1997
 
1717
1998
  // src/discovery.ts
1718
- import fg3 from "fast-glob";
1719
- import { stat as stat3 } from "fs/promises";
1999
+ import fg4 from "fast-glob";
2000
+ import { stat as stat4 } from "fs/promises";
1720
2001
  var EXCLUDED_SEGMENTS = ["/memory/", "/tool-results/"];
1721
2002
  var STAT_CONCURRENCY = 32;
1722
2003
  async function discoverJsonlFiles(dirs, onProgress) {
@@ -1725,7 +2006,7 @@ async function discoverJsonlFiles(dirs, onProgress) {
1725
2006
  for (const { projectsDir, account } of dirs) {
1726
2007
  let filePaths;
1727
2008
  try {
1728
- filePaths = await fg3("**/*.jsonl", {
2009
+ filePaths = await fg4("**/*.jsonl", {
1729
2010
  cwd: projectsDir,
1730
2011
  absolute: true,
1731
2012
  dot: false
@@ -1743,7 +2024,7 @@ async function discoverJsonlFiles(dirs, onProgress) {
1743
2024
  const statted = await Promise.all(
1744
2025
  chunk.map(async (filePath) => {
1745
2026
  try {
1746
- const s = await stat3(filePath);
2027
+ const s = await stat4(filePath);
1747
2028
  return { filePath, size: s.size };
1748
2029
  } catch (err) {
1749
2030
  log.warn({ filePath, err }, "discovery: stat failed");
@@ -1818,7 +2099,7 @@ var ThreadbaseProvider = class {
1818
2099
 
1819
2100
  // src/scanner.ts
1820
2101
  import { EventEmitter } from "events";
1821
- import { closeSync as closeSync2, openSync as openSync2, readSync as readSync2, statSync as statSync4 } from "fs";
2102
+ import { closeSync as closeSync2, openSync as openSync2, readSync as readSync2, statSync as statSync5 } from "fs";
1822
2103
  import { homedir as homedir2 } from "os";
1823
2104
  import { join as join6 } from "path";
1824
2105
 
@@ -1859,18 +2140,18 @@ var LRUCache = class {
1859
2140
  };
1860
2141
 
1861
2142
  // src/persistent/conversation-stream.ts
1862
- import { basename as basename5 } from "path";
2143
+ import { basename as basename6 } from "path";
1863
2144
 
1864
2145
  // src/persistent/paged-reader.ts
1865
- import { createReadStream as createReadStream5 } from "fs";
2146
+ import { createReadStream as createReadStream6 } from "fs";
1866
2147
  import { setImmediate as yieldToEventLoop2 } from "timers/promises";
1867
2148
 
1868
2149
  // src/persistent/jsonl-tail-reader.ts
1869
- import { createReadStream as createReadStream4 } from "fs";
2150
+ import { createReadStream as createReadStream5 } from "fs";
1870
2151
  import { setImmediate as yieldToEventLoop } from "timers/promises";
1871
2152
  var YIELD_EVERY_LINES = 500;
1872
2153
  async function tailReduce(filePath, startOffset, startLine, state, tier, onEntry) {
1873
- const stream = createReadStream4(filePath, { start: startOffset, encoding: "utf8" });
2154
+ const stream = createReadStream5(filePath, { start: startOffset, encoding: "utf8" });
1874
2155
  let buffer = "";
1875
2156
  let offset = startOffset;
1876
2157
  let line = startLine;
@@ -1907,7 +2188,7 @@ async function tailReduce(filePath, startOffset, startLine, state, tier, onEntry
1907
2188
  // src/persistent/paged-reader.ts
1908
2189
  var CHECKPOINT_INTERVAL = 500;
1909
2190
  async function streamMessages(filePath, startOffset, startLine, state, onMessage, onEntry) {
1910
- const stream = createReadStream5(filePath, { start: startOffset, encoding: "utf8" });
2191
+ const stream = createReadStream6(filePath, { start: startOffset, encoding: "utf8" });
1911
2192
  let buffer = "";
1912
2193
  let offset = startOffset;
1913
2194
  let line = startLine;
@@ -2019,7 +2300,7 @@ function assemble(filePath, account, messages, fullText, turnDurations, state) {
2019
2300
  filePath,
2020
2301
  projectPath: state.cwd,
2021
2302
  projectName: getShortProjectName2(state.cwd),
2022
- sessionId: state.sessionId || basename5(filePath, ".jsonl"),
2303
+ sessionId: state.sessionId || basename6(filePath, ".jsonl"),
2023
2304
  sessionName: state.sessionName || deriveSessionNameFromFirstMessage(messages.find((m) => m.role === "user" && m.text) ?? null),
2024
2305
  messages,
2025
2306
  fullText,
@@ -2064,7 +2345,7 @@ async function extendConversation(previous, resume, filePath, account) {
2064
2345
 
2065
2346
  // src/persistent/cursor.ts
2066
2347
  import { createHash as createHash2 } from "crypto";
2067
- import { closeSync, openSync, readSync, statSync as statSync2 } from "fs";
2348
+ import { closeSync, openSync, readSync, statSync as statSync3 } from "fs";
2068
2349
  var FP_BYTES = 4096;
2069
2350
  function fingerprint(filePath, size) {
2070
2351
  const hash = createHash2("sha1");
@@ -2088,46 +2369,46 @@ function fingerprint(filePath, size) {
2088
2369
  return hash.digest("hex");
2089
2370
  }
2090
2371
  function classify(filePath, existing) {
2091
- let stat5;
2372
+ let stat6;
2092
2373
  try {
2093
- const s = statSync2(filePath);
2094
- stat5 = { size: s.size, mtimeMs: s.mtimeMs };
2374
+ const s = statSync3(filePath);
2375
+ stat6 = { size: s.size, mtimeMs: s.mtimeMs };
2095
2376
  } catch {
2096
2377
  return { change: "vanished" };
2097
2378
  }
2098
2379
  if (!existing || existing.status !== "active" || existing.last_indexed_offset === 0) {
2099
- return { change: "reindex", stat: stat5 };
2380
+ return { change: "reindex", stat: stat6 };
2100
2381
  }
2101
- if (stat5.size < existing.last_indexed_offset) {
2102
- return { change: "reindex", stat: stat5 };
2382
+ if (stat6.size < existing.last_indexed_offset) {
2383
+ return { change: "reindex", stat: stat6 };
2103
2384
  }
2104
- if (stat5.size === existing.size_bytes && stat5.mtimeMs === existing.mtime_ms) {
2105
- return { change: "unchanged", stat: stat5 };
2385
+ if (stat6.size === existing.size_bytes && stat6.mtimeMs === existing.mtime_ms) {
2386
+ return { change: "unchanged", stat: stat6 };
2106
2387
  }
2107
- if (stat5.size === existing.last_indexed_offset) {
2108
- const fp = fingerprint(filePath, stat5.size);
2388
+ if (stat6.size === existing.last_indexed_offset) {
2389
+ const fp = fingerprint(filePath, stat6.size);
2109
2390
  if (existing.content_fingerprint && fp !== existing.content_fingerprint) {
2110
- return { change: "reindex", stat: stat5 };
2391
+ return { change: "reindex", stat: stat6 };
2111
2392
  }
2112
- return { change: "unchanged", stat: stat5 };
2393
+ return { change: "unchanged", stat: stat6 };
2113
2394
  }
2114
2395
  if (existing.content_fingerprint && existing.size_bytes === existing.last_indexed_offset && fingerprint(filePath, existing.last_indexed_offset) === existing.content_fingerprint) {
2115
- return { change: "appended", stat: stat5 };
2396
+ return { change: "appended", stat: stat6 };
2116
2397
  }
2117
- return { change: "reindex", stat: stat5 };
2398
+ return { change: "reindex", stat: stat6 };
2118
2399
  }
2119
2400
 
2120
2401
  // src/persistent/index-engine.ts
2121
- import { statSync as statSync3 } from "fs";
2402
+ import { statSync as statSync4 } from "fs";
2122
2403
 
2123
2404
  // src/providers/parse.ts
2124
- import { createReadStream as createReadStream6 } from "fs";
2125
- import { createInterface as createInterface4 } from "readline";
2405
+ import { createReadStream as createReadStream7 } from "fs";
2406
+ import { createInterface as createInterface5 } from "readline";
2126
2407
  async function parseMetaWithProvider(provider, filePath, account, tier, onEntry) {
2127
2408
  const log = getLogger();
2128
2409
  const acc = provider.createEmptyAccumulator();
2129
- const rl = createInterface4({
2130
- input: createReadStream6(filePath),
2410
+ const rl = createInterface5({
2411
+ input: createReadStream7(filePath),
2131
2412
  crlfDelay: Infinity
2132
2413
  });
2133
2414
  try {
@@ -2200,8 +2481,17 @@ function extractSearchDelta(entry) {
2200
2481
  if (looksLikeCursorChatEntry(entry)) {
2201
2482
  return extractCursorDelta(entry);
2202
2483
  }
2484
+ if (looksLikeCopilotEvent(entry)) {
2485
+ return extractCopilotDelta(entry);
2486
+ }
2203
2487
  return extractClaudeDelta(entry);
2204
2488
  }
2489
+ function extractCopilotDelta(entry) {
2490
+ const message = parseCopilotJsonlLine(JSON.stringify(entry));
2491
+ if (!message) return emptySearchDocument();
2492
+ const tools = (message.metadata?.toolUseBlocks ?? []).map((block) => capToolPayload(block.input)).filter(Boolean).join(SEP);
2493
+ return { text: message.text, thinking: "", tools };
2494
+ }
2205
2495
  function extractCursorDelta(entry) {
2206
2496
  const msg = entry.message;
2207
2497
  const content = msg?.content ?? entry.content;
@@ -2343,7 +2633,7 @@ function resolveTier(tierName, customTiers) {
2343
2633
  // src/persistent/db.ts
2344
2634
  import Database from "better-sqlite3";
2345
2635
  import { mkdirSync } from "fs";
2346
- import { dirname as dirname4 } from "path";
2636
+ import { dirname as dirname5 } from "path";
2347
2637
 
2348
2638
  // src/persistent/schema.ts
2349
2639
  var SCHEMA_VERSION = 10;
@@ -2668,7 +2958,7 @@ function hasColumn(db, table, column) {
2668
2958
  // src/persistent/db.ts
2669
2959
  function openDatabase(dbPath) {
2670
2960
  if (dbPath !== ":memory:") {
2671
- mkdirSync(dirname4(dbPath), { recursive: true });
2961
+ mkdirSync(dirname5(dbPath), { recursive: true });
2672
2962
  }
2673
2963
  let db;
2674
2964
  try {
@@ -2712,8 +3002,8 @@ function nativeBindingError(err, dbPath) {
2712
3002
  }
2713
3003
 
2714
3004
  // src/persistent/dir-watermark.ts
2715
- import { readdir, stat as stat4 } from "fs/promises";
2716
- import { dirname as dirname5, join as join5 } from "path";
3005
+ import { readdir, stat as stat5 } from "fs/promises";
3006
+ import { dirname as dirname6, join as join5 } from "path";
2717
3007
  var FULL_RECONCILE_EVERY_N_SCANS = 20;
2718
3008
  async function discoverJsonlFilesGated(dirs, files, scannedDirs, options = {}) {
2719
3009
  const log = getLogger();
@@ -2729,7 +3019,7 @@ async function discoverJsonlFilesGated(dirs, files, scannedDirs, options = {}) {
2729
3019
  for (const projectDir of resolved.entries) {
2730
3020
  let dirStat;
2731
3021
  try {
2732
- dirStat = await stat4(projectDir);
3022
+ dirStat = await stat5(projectDir);
2733
3023
  } catch {
2734
3024
  scannedDirs.remove(projectDir);
2735
3025
  continue;
@@ -2767,7 +3057,7 @@ async function discoverJsonlFilesGated(dirs, files, scannedDirs, options = {}) {
2767
3057
  async function resolveProjectDirs(projectsDir, scannedDirs) {
2768
3058
  let rootStat;
2769
3059
  try {
2770
- rootStat = await stat4(projectsDir);
3060
+ rootStat = await stat5(projectsDir);
2771
3061
  } catch {
2772
3062
  return null;
2773
3063
  }
@@ -2784,7 +3074,7 @@ async function resolveProjectDirs(projectsDir, scannedDirs) {
2784
3074
  return { entries, commitRoot: { mtimeMs: rootStat.mtimeMs } };
2785
3075
  }
2786
3076
  function dirnameOf(filePath) {
2787
- return dirname5(filePath);
3077
+ return dirname6(filePath);
2788
3078
  }
2789
3079
  function joinPath(dir, name) {
2790
3080
  return join5(dir, name);
@@ -2867,7 +3157,7 @@ function toCheckpoint(row) {
2867
3157
  }
2868
3158
 
2869
3159
  // src/persistent/repositories/conversation-files.repo.ts
2870
- import { basename as basename6, dirname as dirname6 } from "path";
3160
+ import { basename as basename7, dirname as dirname7 } from "path";
2871
3161
  var ConversationFilesRepo = class {
2872
3162
  constructor(db) {
2873
3163
  this.db = db;
@@ -2890,7 +3180,7 @@ var ConversationFilesRepo = class {
2890
3180
  const info = this.db.prepare(
2891
3181
  `INSERT INTO conversation_files (absolute_path, parent_dir, file_name, account)
2892
3182
  VALUES (?, ?, ?, ?)`
2893
- ).run(canonical, dirname6(canonical), basename6(canonical), account);
3183
+ ).run(canonical, dirname7(canonical), basename7(canonical), account);
2894
3184
  return Number(info.lastInsertRowid);
2895
3185
  }
2896
3186
  // Advance the cursor + persisted reducer state after a successful index pass.
@@ -3407,6 +3697,12 @@ var PersistentEngine = class {
3407
3697
  discovered.push({ ...f, provider: cursor });
3408
3698
  }
3409
3699
  }
3700
+ const copilot = new CopilotProvider();
3701
+ if (enabled.includes(COPILOT_PROVIDER) && (options.copilotRoots?.length ?? 0) > 0) {
3702
+ for (const f of await copilot.discover(options.copilotRoots)) {
3703
+ discovered.push({ ...f, provider: copilot });
3704
+ }
3705
+ }
3410
3706
  let scanned = 0;
3411
3707
  const gitBranchMemo = /* @__PURE__ */ new Map();
3412
3708
  const resolveGitBranch = (projectPath) => {
@@ -3448,6 +3744,9 @@ var PersistentEngine = class {
3448
3744
  if (enabled.includes(CURSOR_PROVIDER) && (options.cursorRoots?.length ?? 0) > 0) {
3449
3745
  coveredAccounts.add("cursor");
3450
3746
  }
3747
+ if (enabled.includes(COPILOT_PROVIDER) && (options.copilotRoots?.length ?? 0) > 0) {
3748
+ coveredAccounts.add("copilot");
3749
+ }
3451
3750
  const seen = new Set(discovered.map((d) => canonicalPath(d.filePath)));
3452
3751
  for (const path of this.files.activePathsByAccounts([...coveredAccounts])) {
3453
3752
  if (!seen.has(path)) this.markDeleted(path);
@@ -3467,8 +3766,8 @@ var PersistentEngine = class {
3467
3766
  const tier = resolveTier(tierName, customTiers);
3468
3767
  const filePath = canonicalPath(rawFilePath);
3469
3768
  const existing = this.files.getByPath(filePath);
3470
- const { change, stat: stat5 } = classify(filePath, existing);
3471
- if (change === "vanished" || !stat5) {
3769
+ const { change, stat: stat6 } = classify(filePath, existing);
3770
+ if (change === "vanished" || !stat6) {
3472
3771
  this.markDeleted(filePath);
3473
3772
  return { meta: null, change: "vanished" };
3474
3773
  }
@@ -3481,7 +3780,7 @@ var PersistentEngine = class {
3481
3780
  filePath,
3482
3781
  account,
3483
3782
  tier,
3484
- stat5,
3783
+ stat6,
3485
3784
  resolveGitBranch
3486
3785
  );
3487
3786
  return { meta: meta2, change };
@@ -3507,7 +3806,7 @@ var PersistentEngine = class {
3507
3806
  return { meta: null, change };
3508
3807
  }
3509
3808
  meta.gitBranch = resolveGitBranch(meta.projectPath);
3510
- const fp = stat5.size > 0 ? fingerprint(filePath, stat5.size) : null;
3809
+ const fp = stat6.size > 0 ? fingerprint(filePath, stat6.size) : null;
3511
3810
  const fileId = this.files.ensure(filePath, account);
3512
3811
  const base = resume ? this.fts.readDocument(fileId) ?? emptySearchDocument() : emptySearchDocument();
3513
3812
  const searchDoc = appendSearchDelta(base, searchDelta);
@@ -3518,8 +3817,8 @@ var PersistentEngine = class {
3518
3817
  }
3519
3818
  if (!resume) this.checkpoints.remove(filePath);
3520
3819
  this.files.updateCursor(fileId, {
3521
- sizeBytes: stat5.size,
3522
- mtimeMs: stat5.mtimeMs,
3820
+ sizeBytes: stat6.size,
3821
+ mtimeMs: stat6.mtimeMs,
3523
3822
  // Advance only to the last fully-parsed line; a trailing partial line
3524
3823
  // is left for the next pass.
3525
3824
  offset: result.newOffset,
@@ -3536,8 +3835,8 @@ var PersistentEngine = class {
3536
3835
  buildSidecar(
3537
3836
  meta,
3538
3837
  {
3539
- sizeBytes: stat5.size,
3540
- mtimeMs: stat5.mtimeMs,
3838
+ sizeBytes: stat6.size,
3839
+ mtimeMs: stat6.mtimeMs,
3541
3840
  offset: result.newOffset,
3542
3841
  line: result.newLine
3543
3842
  },
@@ -3556,7 +3855,7 @@ var PersistentEngine = class {
3556
3855
  // the Threadbase path uses. The cursor records size/mtime (and offset = size)
3557
3856
  // so the next pass classifies an unchanged file as "unchanged" and skips it;
3558
3857
  // any change reparses from 0 again. No reducer_state is persisted.
3559
- async indexFileWithProvider(provider, filePath, account, tier, stat5, resolveGitBranch) {
3858
+ async indexFileWithProvider(provider, filePath, account, tier, stat6, resolveGitBranch) {
3560
3859
  const log = getLogger();
3561
3860
  let searchDoc = emptySearchDocument();
3562
3861
  const meta = await parseMetaWithProvider(provider, filePath, account, tier, (entry) => {
@@ -3569,7 +3868,7 @@ var PersistentEngine = class {
3569
3868
  if (meta.gitBranch === null && meta.projectPath) {
3570
3869
  meta.gitBranch = resolveGitBranch(meta.projectPath);
3571
3870
  }
3572
- const fp = stat5.size > 0 ? fingerprint(filePath, stat5.size) : null;
3871
+ const fp = stat6.size > 0 ? fingerprint(filePath, stat6.size) : null;
3573
3872
  const fileId = this.files.ensure(filePath, account);
3574
3873
  const upsert = this.db.transaction(() => {
3575
3874
  this.conversations.upsert(fileId, meta, meta.messageCount);
@@ -3578,11 +3877,11 @@ var PersistentEngine = class {
3578
3877
  }
3579
3878
  this.checkpoints.remove(filePath);
3580
3879
  this.files.updateCursor(fileId, {
3581
- sizeBytes: stat5.size,
3582
- mtimeMs: stat5.mtimeMs,
3880
+ sizeBytes: stat6.size,
3881
+ mtimeMs: stat6.mtimeMs,
3583
3882
  // offset = size marks the file fully consumed (non-zero so the next pass
3584
3883
  // can classify it "unchanged"); no resumable reducer state is kept.
3585
- offset: stat5.size,
3884
+ offset: stat6.size,
3586
3885
  line: 0,
3587
3886
  reducerState: null,
3588
3887
  fingerprint: fp,
@@ -3648,8 +3947,8 @@ var PersistentEngine = class {
3648
3947
  const meta = this.conversations.getByIdOrSession(id);
3649
3948
  if (!meta) return null;
3650
3949
  const filePath = meta.filePath;
3651
- if (meta.provider === CODEX_CLI_PROVIDER || meta.provider === CURSOR_PROVIDER) {
3652
- const conversation = meta.provider === CODEX_CLI_PROVIDER ? await parseCodexConversation(filePath, meta.account) : await parseCursorConversation(filePath, meta.account);
3950
+ if (meta.provider === CODEX_CLI_PROVIDER || meta.provider === CURSOR_PROVIDER || meta.provider === COPILOT_PROVIDER) {
3951
+ const conversation = meta.provider === CODEX_CLI_PROVIDER ? await parseCodexConversation(filePath, meta.account) : meta.provider === CURSOR_PROVIDER ? await parseCursorConversation(filePath, meta.account) : await parseCopilotConversation(filePath, meta.account);
3653
3952
  if (!conversation) return null;
3654
3953
  const { messages } = conversation;
3655
3954
  const total2 = messages.length;
@@ -3664,7 +3963,7 @@ var PersistentEngine = class {
3664
3963
  let floor = this.checkpoints.floor(filePath, fromIndex);
3665
3964
  if (floor) {
3666
3965
  try {
3667
- if (floor.byteOffset > statSync3(filePath).size) floor = null;
3966
+ if (floor.byteOffset > statSync4(filePath).size) floor = null;
3668
3967
  } catch {
3669
3968
  }
3670
3969
  }
@@ -3982,7 +4281,7 @@ var ConversationScanner = class {
3982
4281
  const cached = statCache.get(filePath);
3983
4282
  if (cached) {
3984
4283
  try {
3985
- const s = statSync4(filePath);
4284
+ const s = statSync5(filePath);
3986
4285
  if (s.mtimeMs === cached.stat.mtimeMs && s.size === cached.stat.size) {
3987
4286
  return {
3988
4287
  meta: cached.meta,
@@ -4140,12 +4439,12 @@ var ConversationScanner = class {
4140
4439
  }
4141
4440
  log.debug({ id, filePath: meta.filePath }, "getConversation: cache miss, parsing");
4142
4441
  try {
4143
- if (this.persistent && meta.provider !== CODEX_CLI_PROVIDER && meta.provider !== CURSOR_PROVIDER) {
4442
+ if (this.persistent && meta.provider !== CODEX_CLI_PROVIDER && meta.provider !== CURSOR_PROVIDER && meta.provider !== COPILOT_PROVIDER) {
4144
4443
  const parsed = await parseConversationResumable(meta.filePath, meta.account);
4145
4444
  if (parsed) this.conversationLRU.set(cid, parsed);
4146
4445
  return parsed?.conversation ?? null;
4147
4446
  }
4148
- 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);
4447
+ const conversation = meta.provider === CODEX_CLI_PROVIDER ? await parseCodexConversation(meta.filePath, meta.account) : meta.provider === CURSOR_PROVIDER ? await parseCursorConversation(meta.filePath, meta.account) : meta.provider === COPILOT_PROVIDER ? await parseCopilotConversation(meta.filePath, meta.account) : await parseConversation(meta.filePath, meta.account);
4149
4448
  if (conversation) {
4150
4449
  this.conversationLRU.set(cid, { conversation });
4151
4450
  }
@@ -4199,7 +4498,7 @@ var ConversationScanner = class {
4199
4498
  // fallback, matching refreshFile.
4200
4499
  async parseSingleFilePage(filePath, account, options) {
4201
4500
  const provider = await this.resolveProviderForFile(filePath, null);
4202
- 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");
4501
+ const conversation = provider?.name === CODEX_CLI_PROVIDER ? await parseCodexConversation(filePath, account ?? "default") : provider?.name === CURSOR_PROVIDER ? await parseCursorConversation(filePath, account ?? "default") : provider?.name === COPILOT_PROVIDER ? await parseCopilotConversation(filePath, account ?? "default") : await parseConversation(filePath, account ?? "default");
4203
4502
  if (!conversation) return null;
4204
4503
  const { messages } = conversation;
4205
4504
  const total = messages.length;
@@ -4509,6 +4808,12 @@ var ConversationScanner = class {
4509
4808
  work.push({ ...f, provider });
4510
4809
  }
4511
4810
  }
4811
+ if (enabled.includes(COPILOT_PROVIDER) && (options.copilotRoots?.length ?? 0) > 0) {
4812
+ const provider = new CopilotProvider();
4813
+ for (const f of await provider.discover(options.copilotRoots)) {
4814
+ work.push({ ...f, provider });
4815
+ }
4816
+ }
4512
4817
  return work;
4513
4818
  }
4514
4819
  // Resolve which provider should (re)parse a file. Stored metadata wins; for a
@@ -4520,6 +4825,7 @@ var ConversationScanner = class {
4520
4825
  if (providerMatches(previous?.provider, CURSOR_PROVIDER)) {
4521
4826
  return new CursorProvider();
4522
4827
  }
4828
+ if (previous?.provider === COPILOT_PROVIDER) return new CopilotProvider();
4523
4829
  if (previous?.provider) return void 0;
4524
4830
  let sample = "";
4525
4831
  try {
@@ -4538,6 +4844,8 @@ var ConversationScanner = class {
4538
4844
  if (cursor.canParse(filePath, sample)) return cursor;
4539
4845
  const codex = new CodexCliProvider();
4540
4846
  if (codex.canParse(filePath, sample)) return codex;
4847
+ const copilot = new CopilotProvider();
4848
+ if (copilot.canParse(filePath, sample)) return copilot;
4541
4849
  return void 0;
4542
4850
  }
4543
4851
  addToSessionIndex(meta) {
@@ -4646,9 +4954,11 @@ async function getConversation(id, options, scanner) {
4646
4954
  export {
4647
4955
  CLAUDE_CODE_PROVIDER,
4648
4956
  CODEX_CLI_PROVIDER,
4957
+ COPILOT_PROVIDER,
4649
4958
  CURSOR_PROVIDER,
4650
4959
  CodexCliProvider,
4651
4960
  ConversationScanner,
4961
+ CopilotProvider,
4652
4962
  CursorProvider,
4653
4963
  DEFAULT_TIERS,
4654
4964
  LEGACY_CURSOR_PROVIDER,
@@ -4673,6 +4983,7 @@ export {
4673
4983
  isCodexInjectedContext,
4674
4984
  loadProfiles,
4675
4985
  parseCodexJsonlLine,
4986
+ parseCopilotJsonlLine,
4676
4987
  parseCursorJsonlLine,
4677
4988
  parseJsonlLine,
4678
4989
  providerMatches,