@threadbase-sh/scanner 0.19.5 → 0.21.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.19.5";
8
+ var version = "0.21.0";
9
9
 
10
10
  // src/logger.ts
11
11
  import pino from "pino";
@@ -60,7 +60,7 @@ 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 statSync4 } from "fs";
63
+ import { closeSync as closeSync2, openSync as openSync2, readSync as readSync2, statSync as statSync5 } from "fs";
64
64
  import { homedir as homedir2 } from "os";
65
65
  import { join as join6 } from "path";
66
66
 
@@ -536,8 +536,20 @@ function reduceConvLine(state, entry) {
536
536
  if (entry.lastPrompt && !state.lastPrompt) state.lastPrompt = entry.lastPrompt;
537
537
  return null;
538
538
  }
539
+ if (type === "system" && entry.subtype === "compact_boundary") {
540
+ const meta = entry.compactMetadata ?? {};
541
+ state.pendingCompaction = {
542
+ trigger: typeof meta.trigger === "string" ? meta.trigger : void 0,
543
+ preTokens: typeof meta.preTokens === "number" ? meta.preTokens : void 0,
544
+ postTokens: typeof meta.postTokens === "number" ? meta.postTokens : void 0
545
+ };
546
+ return null;
547
+ }
539
548
  if (type !== "user" && type !== "assistant") return null;
540
549
  if (entry.isMeta) return null;
550
+ const isCompactSummary = type === "user" && entry.isCompactSummary === true;
551
+ const compaction = isCompactSummary ? state.pendingCompaction : void 0;
552
+ if (isCompactSummary) delete state.pendingCompaction;
541
553
  const msg = entry.message;
542
554
  const toolUseBlocks = extractToolUseBlocks(msg?.content);
543
555
  for (const block of toolUseBlocks) state.pendingToolUses[block.id] = block;
@@ -597,7 +609,9 @@ function reduceConvLine(state, entry) {
597
609
  isSidechain: typeof entry.isSidechain === "boolean" ? entry.isSidechain : void 0,
598
610
  permissionMode: type === "user" ? entry.permissionMode : void 0,
599
611
  hasImages: hasImageBlocks(msg?.content) || void 0,
600
- attachment: entry.attachment !== void 0 ? entry.attachment : void 0
612
+ attachment: entry.attachment !== void 0 ? entry.attachment : void 0,
613
+ isCompactSummary: isCompactSummary || void 0,
614
+ compaction
601
615
  };
602
616
  }
603
617
  function applyTeamInfo(messages, state) {
@@ -615,10 +629,11 @@ import { basename, dirname as dirname2, join as join3 } from "path";
615
629
  var CLAUDE_CODE_PROVIDER = "claude-code";
616
630
  var CODEX_CLI_PROVIDER = "codex-cli";
617
631
  var CURSOR_PROVIDER = "cursor";
632
+ var COPILOT_PROVIDER = "copilot";
618
633
  var LEGACY_CURSOR_PROVIDER = "cursor-cli";
619
634
  function canonicalizeProviderName(value) {
620
635
  if (value === LEGACY_CURSOR_PROVIDER) return CURSOR_PROVIDER;
621
- if (value === CLAUDE_CODE_PROVIDER || value === CODEX_CLI_PROVIDER || value === CURSOR_PROVIDER) {
636
+ if (value === CLAUDE_CODE_PROVIDER || value === CODEX_CLI_PROVIDER || value === CURSOR_PROVIDER || value === COPILOT_PROVIDER) {
622
637
  return value;
623
638
  }
624
639
  return void 0;
@@ -684,6 +699,10 @@ function reduceLine(state, entry, tier) {
684
699
  if (type !== "user" && type !== "assistant") return;
685
700
  if (entry.isMeta) return;
686
701
  const msg = entry.message;
702
+ if (entry.isCompactSummary === true) {
703
+ if (extractTextContent(msg?.content)) state.pageMessageCount++;
704
+ return;
705
+ }
687
706
  if (state.model === null && msg?.model) state.model = msg.model;
688
707
  if (type === "user" && !state.firstUserSeen) {
689
708
  state.firstUserSeen = true;
@@ -1223,37 +1242,37 @@ function fingerprint(filePath, size) {
1223
1242
  return hash.digest("hex");
1224
1243
  }
1225
1244
  function classify(filePath, existing) {
1226
- let stat5;
1245
+ let stat6;
1227
1246
  try {
1228
1247
  const s = statSync(filePath);
1229
- stat5 = { size: s.size, mtimeMs: s.mtimeMs };
1248
+ stat6 = { size: s.size, mtimeMs: s.mtimeMs };
1230
1249
  } catch {
1231
1250
  return { change: "vanished" };
1232
1251
  }
1233
1252
  if (!existing || existing.status !== "active" || existing.last_indexed_offset === 0) {
1234
- return { change: "reindex", stat: stat5 };
1253
+ return { change: "reindex", stat: stat6 };
1235
1254
  }
1236
- if (stat5.size < existing.last_indexed_offset) {
1237
- return { change: "reindex", stat: stat5 };
1255
+ if (stat6.size < existing.last_indexed_offset) {
1256
+ return { change: "reindex", stat: stat6 };
1238
1257
  }
1239
- if (stat5.size === existing.size_bytes && stat5.mtimeMs === existing.mtime_ms) {
1240
- return { change: "unchanged", stat: stat5 };
1258
+ if (stat6.size === existing.size_bytes && stat6.mtimeMs === existing.mtime_ms) {
1259
+ return { change: "unchanged", stat: stat6 };
1241
1260
  }
1242
- if (stat5.size === existing.last_indexed_offset) {
1243
- const fp = fingerprint(filePath, stat5.size);
1261
+ if (stat6.size === existing.last_indexed_offset) {
1262
+ const fp = fingerprint(filePath, stat6.size);
1244
1263
  if (existing.content_fingerprint && fp !== existing.content_fingerprint) {
1245
- return { change: "reindex", stat: stat5 };
1264
+ return { change: "reindex", stat: stat6 };
1246
1265
  }
1247
- return { change: "unchanged", stat: stat5 };
1266
+ return { change: "unchanged", stat: stat6 };
1248
1267
  }
1249
1268
  if (existing.content_fingerprint && existing.size_bytes === existing.last_indexed_offset && fingerprint(filePath, existing.last_indexed_offset) === existing.content_fingerprint) {
1250
- return { change: "appended", stat: stat5 };
1269
+ return { change: "appended", stat: stat6 };
1251
1270
  }
1252
- return { change: "reindex", stat: stat5 };
1271
+ return { change: "reindex", stat: stat6 };
1253
1272
  }
1254
1273
 
1255
1274
  // src/persistent/index-engine.ts
1256
- import { statSync as statSync3 } from "fs";
1275
+ import { statSync as statSync4 } from "fs";
1257
1276
 
1258
1277
  // src/providers/codex-cli.ts
1259
1278
  import fg2 from "fast-glob";
@@ -1605,13 +1624,293 @@ async function parseCodexConversation(filePath, account) {
1605
1624
  };
1606
1625
  }
1607
1626
 
1608
- // src/providers/cursor.ts
1609
- import { createHash as createHash2 } from "crypto";
1627
+ // src/providers/copilot.ts
1610
1628
  import fg3 from "fast-glob";
1611
- import { createReadStream as createReadStream5, existsSync, statSync as statSync2 } from "fs";
1629
+ import { createReadStream as createReadStream5, statSync as statSync2 } from "fs";
1612
1630
  import { stat as stat3 } from "fs/promises";
1613
- import { basename as basename5, dirname as dirname3, join as join4, sep as sep2 } from "path";
1631
+ import { basename as basename5, dirname as dirname3 } from "path";
1614
1632
  import { createInterface as createInterface3 } from "readline";
1633
+ var SESSION_START = "session.start";
1634
+ var USER_MESSAGE = "user.message";
1635
+ var ASSISTANT_MESSAGE = "assistant.message";
1636
+ var CopilotProvider = class {
1637
+ name = COPILOT_PROVIDER;
1638
+ async discover(roots) {
1639
+ const log = getLogger();
1640
+ const results = [];
1641
+ for (const root of roots) {
1642
+ let paths;
1643
+ try {
1644
+ paths = await fg3(["*/events.jsonl", "session-state/*/events.jsonl"], {
1645
+ cwd: root,
1646
+ absolute: true,
1647
+ dot: false,
1648
+ unique: true
1649
+ });
1650
+ } catch (err) {
1651
+ log.warn({ root, err }, "copilot discovery: glob failed");
1652
+ continue;
1653
+ }
1654
+ for (const filePath of paths) {
1655
+ try {
1656
+ const s = await stat3(filePath);
1657
+ if (s.size > 0) results.push({ filePath: canonicalPath(filePath), account: "copilot" });
1658
+ } catch (err) {
1659
+ log.warn({ filePath, err }, "copilot discovery: stat failed");
1660
+ }
1661
+ }
1662
+ }
1663
+ return results;
1664
+ }
1665
+ canParse(_filePath, sample) {
1666
+ for (const line of sample.split("\n")) {
1667
+ if (!line.trim()) continue;
1668
+ try {
1669
+ if (looksLikeCopilotEvent(JSON.parse(line))) return true;
1670
+ } catch {
1671
+ }
1672
+ }
1673
+ return false;
1674
+ }
1675
+ createEmptyAccumulator() {
1676
+ return {
1677
+ sessionId: "",
1678
+ cwd: "",
1679
+ gitBranch: null,
1680
+ model: null,
1681
+ latestTimestamp: "",
1682
+ messageCount: 0,
1683
+ lastMessageSender: "user",
1684
+ firstUser: null,
1685
+ lastUser: null,
1686
+ lastAssistant: null,
1687
+ toolNames: [],
1688
+ previewParts: [],
1689
+ previewLength: 0,
1690
+ snippetParts: [],
1691
+ snippetLength: 0
1692
+ };
1693
+ }
1694
+ reduceEntry(acc, entry, tier) {
1695
+ reduceCopilotEntry(acc, entry, tier);
1696
+ }
1697
+ finalize(acc, filePath, account, tier) {
1698
+ return finalizeCopilotMeta(acc, filePath, account, tier);
1699
+ }
1700
+ };
1701
+ function looksLikeCopilotEvent(entry) {
1702
+ return typeof entry.type === "string" && typeof entry.id === "string" && "parentId" in entry && asRecord(entry.data) !== null;
1703
+ }
1704
+ var asString2 = (v) => typeof v === "string" ? v : "";
1705
+ function asRecord(v) {
1706
+ return v && typeof v === "object" && !Array.isArray(v) ? v : null;
1707
+ }
1708
+ function copilotToolUseBlocks(data) {
1709
+ if (!Array.isArray(data.toolRequests)) return [];
1710
+ const blocks = [];
1711
+ for (const item of data.toolRequests) {
1712
+ const request = asRecord(item);
1713
+ const name = asString2(request?.name);
1714
+ if (!request || !name) continue;
1715
+ const input = asRecord(request.arguments) ?? { arguments: asString2(request.arguments) };
1716
+ blocks.push({ id: asString2(request.toolCallId), name, input });
1717
+ }
1718
+ return blocks;
1719
+ }
1720
+ function copilotEntryToMessage(entry) {
1721
+ if (!looksLikeCopilotEvent(entry)) return null;
1722
+ const data = entry.data;
1723
+ const timestamp = asString2(entry.timestamp);
1724
+ const uuid = asString2(data.messageId) || asString2(entry.id);
1725
+ if (entry.type === USER_MESSAGE) {
1726
+ const text = cleanSystemTags(asString2(data.content));
1727
+ return text ? { role: "user", text, timestamp, uuid } : null;
1728
+ }
1729
+ if (entry.type === ASSISTANT_MESSAGE) {
1730
+ const text = asString2(data.content).trim();
1731
+ const blocks = copilotToolUseBlocks(data);
1732
+ if (!text && blocks.length === 0) return null;
1733
+ const model = asString2(data.model);
1734
+ const metadata = {
1735
+ ...model ? { model } : {},
1736
+ ...blocks.length > 0 ? { toolUses: blocks.map((b) => b.name), toolUseBlocks: blocks } : {}
1737
+ };
1738
+ return {
1739
+ role: "assistant",
1740
+ text,
1741
+ timestamp,
1742
+ uuid,
1743
+ ...Object.keys(metadata).length > 0 ? { metadata } : {}
1744
+ };
1745
+ }
1746
+ return null;
1747
+ }
1748
+ function parseCopilotJsonlLine(line) {
1749
+ const trimmed = line.trim();
1750
+ if (!trimmed) return null;
1751
+ try {
1752
+ return copilotEntryToMessage(JSON.parse(trimmed));
1753
+ } catch {
1754
+ return null;
1755
+ }
1756
+ }
1757
+ function readSessionStart(entry) {
1758
+ if (entry.type !== SESSION_START) return null;
1759
+ const data = asRecord(entry.data);
1760
+ if (!data) return null;
1761
+ const context = asRecord(data.context);
1762
+ return {
1763
+ sessionId: asString2(data.sessionId),
1764
+ cwd: asString2(context?.cwd),
1765
+ branch: asString2(context?.branch)
1766
+ };
1767
+ }
1768
+ function reduceCopilotEntry(acc, entry, tier) {
1769
+ const start = readSessionStart(entry);
1770
+ if (start) {
1771
+ if (!acc.sessionId) acc.sessionId = start.sessionId;
1772
+ if (!acc.cwd) acc.cwd = start.cwd;
1773
+ if (!acc.gitBranch && start.branch) acc.gitBranch = start.branch;
1774
+ return;
1775
+ }
1776
+ const message = copilotEntryToMessage(entry);
1777
+ if (!message) return;
1778
+ for (const name of message.metadata?.toolUses ?? []) {
1779
+ if (!acc.toolNames.includes(name)) acc.toolNames.push(name);
1780
+ }
1781
+ if (message.metadata?.model) acc.model = message.metadata.model;
1782
+ const { role, text, timestamp } = message;
1783
+ if (!text) return;
1784
+ if (timestamp && (!acc.latestTimestamp || timestamp > acc.latestTimestamp)) {
1785
+ acc.latestTimestamp = timestamp;
1786
+ }
1787
+ acc.messageCount++;
1788
+ acc.lastMessageSender = role;
1789
+ const snapshot = { text: text.slice(0, 200), timestamp };
1790
+ if (role === "user") {
1791
+ if (!acc.firstUser) acc.firstUser = snapshot;
1792
+ acc.lastUser = snapshot;
1793
+ } else {
1794
+ acc.lastAssistant = snapshot;
1795
+ }
1796
+ if (acc.previewLength < tier.previewMax) {
1797
+ acc.previewParts.push(text);
1798
+ acc.previewLength += text.length;
1799
+ }
1800
+ if (acc.snippetLength < tier.snippetMax) {
1801
+ const remaining = tier.snippetMax - acc.snippetLength;
1802
+ const chunk = text.length > remaining ? text.slice(0, remaining) : text;
1803
+ acc.snippetParts.push(chunk);
1804
+ acc.snippetLength += chunk.length;
1805
+ }
1806
+ }
1807
+ function finalizeCopilotMeta(acc, filePath, account, tier) {
1808
+ if (acc.messageCount === 0) return null;
1809
+ const sessionId = acc.sessionId || sessionIdFromPath(filePath);
1810
+ const kind = acc.lastAssistant === null && acc.toolNames.length > 0 ? "task" : "conversation";
1811
+ return {
1812
+ id: filePath,
1813
+ filePath,
1814
+ provider: COPILOT_PROVIDER,
1815
+ kind,
1816
+ externalSessionId: sessionId,
1817
+ sessionId,
1818
+ sessionName: deriveSessionNameFromFirstMessage(acc.firstUser),
1819
+ projectPath: acc.cwd,
1820
+ projectName: getShortProjectName4(acc.cwd),
1821
+ account,
1822
+ timestamp: acc.latestTimestamp || fileMtimeIso(filePath),
1823
+ messageCount: acc.messageCount,
1824
+ lastMessageSender: acc.lastMessageSender,
1825
+ preview: acc.previewParts.join(" ").slice(0, tier.previewMax),
1826
+ contentSnippet: acc.snippetParts.join(" "),
1827
+ gitBranch: acc.gitBranch,
1828
+ model: acc.model,
1829
+ isSubagent: false,
1830
+ parentSessionId: null,
1831
+ isTeammate: false,
1832
+ teamName: null,
1833
+ toolNames: acc.toolNames,
1834
+ firstMessage: acc.firstUser,
1835
+ lastMessage: acc.lastAssistant ?? acc.lastUser,
1836
+ lastPrompt: acc.lastUser?.text || void 0
1837
+ };
1838
+ }
1839
+ function sessionIdFromPath(filePath) {
1840
+ return basename5(dirname3(filePath));
1841
+ }
1842
+ function getShortProjectName4(fullPath) {
1843
+ return fullPath.split(/[/\\]/).filter(Boolean).slice(-3).join("/");
1844
+ }
1845
+ function fileMtimeIso(filePath) {
1846
+ try {
1847
+ return new Date(statSync2(filePath).mtimeMs).toISOString();
1848
+ } catch {
1849
+ return (/* @__PURE__ */ new Date()).toISOString();
1850
+ }
1851
+ }
1852
+ async function parseCopilotConversation(filePath, account) {
1853
+ const log = getLogger();
1854
+ const messages = [];
1855
+ const textParts = [];
1856
+ let sessionId = "";
1857
+ let cwd = "";
1858
+ let latestTimestamp = "";
1859
+ let lastUserText = "";
1860
+ const rl = createInterface3({ input: createReadStream5(filePath), crlfDelay: Infinity });
1861
+ try {
1862
+ for await (const line of rl) {
1863
+ if (!line.trim()) continue;
1864
+ let entry;
1865
+ try {
1866
+ entry = JSON.parse(line);
1867
+ } catch {
1868
+ continue;
1869
+ }
1870
+ const start = readSessionStart(entry);
1871
+ if (start) {
1872
+ if (!sessionId) sessionId = start.sessionId;
1873
+ if (!cwd) cwd = start.cwd;
1874
+ continue;
1875
+ }
1876
+ const message = copilotEntryToMessage(entry);
1877
+ if (!message) continue;
1878
+ if (message.timestamp && (!latestTimestamp || message.timestamp > latestTimestamp)) {
1879
+ latestTimestamp = message.timestamp;
1880
+ }
1881
+ messages.push(message);
1882
+ if (!message.text) continue;
1883
+ textParts.push(message.text);
1884
+ if (message.role === "user") lastUserText = message.text;
1885
+ }
1886
+ } catch (err) {
1887
+ log.warn({ filePath, err }, "parseCopilotConversation: read failed");
1888
+ return null;
1889
+ }
1890
+ if (messages.length === 0) return null;
1891
+ return {
1892
+ id: filePath,
1893
+ filePath,
1894
+ projectPath: cwd,
1895
+ projectName: getShortProjectName4(cwd),
1896
+ sessionId: sessionId || sessionIdFromPath(filePath),
1897
+ sessionName: "",
1898
+ messages,
1899
+ fullText: textParts.join(" "),
1900
+ timestamp: latestTimestamp || fileMtimeIso(filePath),
1901
+ messageCount: messages.length,
1902
+ account,
1903
+ lastPrompt: lastUserText || void 0
1904
+ };
1905
+ }
1906
+
1907
+ // src/providers/cursor.ts
1908
+ import { createHash as createHash2 } from "crypto";
1909
+ import fg4 from "fast-glob";
1910
+ import { createReadStream as createReadStream6, existsSync, statSync as statSync3 } from "fs";
1911
+ import { stat as stat4 } from "fs/promises";
1912
+ import { basename as basename6, dirname as dirname4, join as join4, sep as sep2 } from "path";
1913
+ import { createInterface as createInterface4 } from "readline";
1615
1914
  var TIMESTAMP_RE = /<timestamp>\s*([\s\S]*?)\s*<\/timestamp>/;
1616
1915
  var USER_QUERY_RE = /<user_query>\s*([\s\S]*?)\s*<\/user_query>/;
1617
1916
  var SUBAGENT_PATH_RE2 = /[\\/]subagents[\\/]/;
@@ -1623,7 +1922,7 @@ var CursorProvider = class {
1623
1922
  for (const root of roots) {
1624
1923
  let paths;
1625
1924
  try {
1626
- paths = await fg3(["**/agent-transcripts/**/*.jsonl"], {
1925
+ paths = await fg4(["**/agent-transcripts/**/*.jsonl"], {
1627
1926
  cwd: root,
1628
1927
  absolute: true,
1629
1928
  dot: false,
@@ -1635,7 +1934,7 @@ var CursorProvider = class {
1635
1934
  }
1636
1935
  for (const filePath of paths) {
1637
1936
  try {
1638
- const s = await stat3(filePath);
1937
+ const s = await stat4(filePath);
1639
1938
  if (s.size > 0) results.push({ filePath: canonicalPath(filePath), account: "cursor" });
1640
1939
  } catch (err) {
1641
1940
  log.warn({ filePath, err }, "cursor discovery: stat failed");
@@ -1699,7 +1998,7 @@ function looksLikeImportedClaudeEntry(entry) {
1699
1998
  function looksLikeImportedCodexEntry(entry) {
1700
1999
  return entry.type === "session_meta" || entry.type === "response_item" || entry.type === "event_msg";
1701
2000
  }
1702
- function asString2(value) {
2001
+ function asString3(value) {
1703
2002
  return typeof value === "string" ? value : "";
1704
2003
  }
1705
2004
  function provenanceToken(value) {
@@ -1813,7 +2112,7 @@ function cursorEntryToMessage(entry) {
1813
2112
  const role = message?.role === "assistant" || entry.type === "assistant" ? "assistant" : "user";
1814
2113
  const content = message?.content ?? entry.content;
1815
2114
  return withToolUses(
1816
- { role, text: extractCursorText(content), timestamp: asString2(entry.timestamp) },
2115
+ { role, text: extractCursorText(content), timestamp: asString3(entry.timestamp) },
1817
2116
  content
1818
2117
  );
1819
2118
  }
@@ -1890,11 +2189,11 @@ function reduceCursorEntry(acc, entry, tier) {
1890
2189
  }
1891
2190
  function finalizeCursorMeta(acc, filePath, account, tier) {
1892
2191
  if (acc.messageCount === 0) return null;
1893
- const sessionId = basename5(filePath, ".jsonl");
2192
+ const sessionId = basename6(filePath, ".jsonl");
1894
2193
  const isSubagent = SUBAGENT_PATH_RE2.test(filePath);
1895
2194
  const parent = isSubagent ? parentFromSubagentPath(filePath) : null;
1896
2195
  const { projectPath, projectName } = projectFromCursorPath(filePath);
1897
- const timestamp = acc.latestTimestamp || fileMtimeIso(filePath);
2196
+ const timestamp = acc.latestTimestamp || fileMtimeIso2(filePath);
1898
2197
  const kind = acc.lastAssistant === null && acc.toolNames.length > 0 ? "task" : "conversation";
1899
2198
  return {
1900
2199
  id: filePath,
@@ -1929,9 +2228,9 @@ function finalizeCursorMeta(acc, filePath, account, tier) {
1929
2228
  };
1930
2229
  }
1931
2230
  function parentFromSubagentPath(filePath) {
1932
- const subagentsDir = dirname3(filePath);
1933
- const parentDir = dirname3(subagentsDir);
1934
- const parentSessionUuid = basename5(parentDir);
2231
+ const subagentsDir = dirname4(filePath);
2232
+ const parentDir = dirname4(subagentsDir);
2233
+ const parentSessionUuid = basename6(parentDir);
1935
2234
  if (!parentSessionUuid) return null;
1936
2235
  return {
1937
2236
  parentSessionUuid,
@@ -1941,11 +2240,11 @@ function parentFromSubagentPath(filePath) {
1941
2240
  function projectFromCursorPath(filePath) {
1942
2241
  const parts = filePath.split(/[/\\]/);
1943
2242
  const idx = parts.lastIndexOf("agent-transcripts");
1944
- const cursorProjectDir = idx > 0 ? parts.slice(0, idx).join(sep2) : dirname3(dirname3(filePath));
1945
- const slug = basename5(cursorProjectDir);
2243
+ const cursorProjectDir = idx > 0 ? parts.slice(0, idx).join(sep2) : dirname4(dirname4(filePath));
2244
+ const slug = basename6(cursorProjectDir);
1946
2245
  const decoded = decodeCursorProjectSlug(slug);
1947
2246
  const projectPath = decoded ?? cursorProjectDir;
1948
- return { projectPath, projectName: getShortProjectName4(projectPath) || slug };
2247
+ return { projectPath, projectName: getShortProjectName5(projectPath) || slug };
1949
2248
  }
1950
2249
  function decodeCursorProjectSlug(slug) {
1951
2250
  if (!slug) return null;
@@ -1966,7 +2265,7 @@ function decodeCursorProjectSlug(slug) {
1966
2265
  for (let j = segments.length; j > i; j--) {
1967
2266
  const candidate = join4(acc, segments.slice(i, j).join("-"));
1968
2267
  try {
1969
- if (existsSync(candidate) && statSync2(candidate).isDirectory()) {
2268
+ if (existsSync(candidate) && statSync3(candidate).isDirectory()) {
1970
2269
  found = candidate;
1971
2270
  next = j;
1972
2271
  break;
@@ -1980,12 +2279,12 @@ function decodeCursorProjectSlug(slug) {
1980
2279
  }
1981
2280
  return acc;
1982
2281
  }
1983
- function getShortProjectName4(fullPath) {
2282
+ function getShortProjectName5(fullPath) {
1984
2283
  return fullPath.split(/[/\\]/).filter(Boolean).slice(-3).join("/");
1985
2284
  }
1986
- function fileMtimeIso(filePath) {
2285
+ function fileMtimeIso2(filePath) {
1987
2286
  try {
1988
- return new Date(statSync2(filePath).mtimeMs).toISOString();
2287
+ return new Date(statSync3(filePath).mtimeMs).toISOString();
1989
2288
  } catch {
1990
2289
  return (/* @__PURE__ */ new Date()).toISOString();
1991
2290
  }
@@ -1996,7 +2295,7 @@ async function parseCursorConversation(filePath, account) {
1996
2295
  const textParts = [];
1997
2296
  let latestTimestamp = "";
1998
2297
  let lastUserText = "";
1999
- const rl = createInterface3({ input: createReadStream5(filePath), crlfDelay: Infinity });
2298
+ const rl = createInterface4({ input: createReadStream6(filePath), crlfDelay: Infinity });
2000
2299
  try {
2001
2300
  for await (const line of rl) {
2002
2301
  const message = parseCursorJsonlLine(line, messages.length);
@@ -2015,7 +2314,7 @@ async function parseCursorConversation(filePath, account) {
2015
2314
  }
2016
2315
  if (messages.length === 0) return null;
2017
2316
  const { projectPath, projectName } = projectFromCursorPath(filePath);
2018
- const sessionId = basename5(filePath, ".jsonl");
2317
+ const sessionId = basename6(filePath, ".jsonl");
2019
2318
  return {
2020
2319
  id: filePath,
2021
2320
  filePath,
@@ -2025,7 +2324,7 @@ async function parseCursorConversation(filePath, account) {
2025
2324
  sessionName: "",
2026
2325
  messages,
2027
2326
  fullText: textParts.join(" "),
2028
- timestamp: latestTimestamp || fileMtimeIso(filePath),
2327
+ timestamp: latestTimestamp || fileMtimeIso2(filePath),
2029
2328
  messageCount: messages.length,
2030
2329
  account,
2031
2330
  lastPrompt: lastUserText || void 0
@@ -2033,13 +2332,13 @@ async function parseCursorConversation(filePath, account) {
2033
2332
  }
2034
2333
 
2035
2334
  // src/providers/parse.ts
2036
- import { createReadStream as createReadStream6 } from "fs";
2037
- import { createInterface as createInterface4 } from "readline";
2335
+ import { createReadStream as createReadStream7 } from "fs";
2336
+ import { createInterface as createInterface5 } from "readline";
2038
2337
  async function parseMetaWithProvider(provider, filePath, account, tier, onEntry) {
2039
2338
  const log = getLogger();
2040
2339
  const acc = provider.createEmptyAccumulator();
2041
- const rl = createInterface4({
2042
- input: createReadStream6(filePath),
2340
+ const rl = createInterface5({
2341
+ input: createReadStream7(filePath),
2043
2342
  crlfDelay: Infinity
2044
2343
  });
2045
2344
  try {
@@ -2112,8 +2411,17 @@ function extractSearchDelta(entry) {
2112
2411
  if (looksLikeCursorChatEntry(entry)) {
2113
2412
  return extractCursorDelta(entry);
2114
2413
  }
2414
+ if (looksLikeCopilotEvent(entry)) {
2415
+ return extractCopilotDelta(entry);
2416
+ }
2115
2417
  return extractClaudeDelta(entry);
2116
2418
  }
2419
+ function extractCopilotDelta(entry) {
2420
+ const message = parseCopilotJsonlLine(JSON.stringify(entry));
2421
+ if (!message) return emptySearchDocument();
2422
+ const tools = (message.metadata?.toolUseBlocks ?? []).map((block) => capToolPayload(block.input)).filter(Boolean).join(SEP);
2423
+ return { text: message.text, thinking: "", tools };
2424
+ }
2117
2425
  function extractCursorDelta(entry) {
2118
2426
  const msg = entry.message;
2119
2427
  const content = msg?.content ?? entry.content;
@@ -2141,7 +2449,7 @@ function extractCursorSearchText(content) {
2141
2449
  function extractClaudeDelta(entry) {
2142
2450
  const type = entry.type;
2143
2451
  if (type !== "user" && type !== "assistant") return emptySearchDocument();
2144
- if (entry.isMeta) return emptySearchDocument();
2452
+ if (entry.isMeta || entry.isCompactSummary === true) return emptySearchDocument();
2145
2453
  const msg = entry.message;
2146
2454
  const content = msg?.content;
2147
2455
  const tools = [
@@ -2255,7 +2563,7 @@ function resolveTier(tierName, customTiers) {
2255
2563
  // src/persistent/db.ts
2256
2564
  import Database from "better-sqlite3";
2257
2565
  import { mkdirSync } from "fs";
2258
- import { dirname as dirname4 } from "path";
2566
+ import { dirname as dirname5 } from "path";
2259
2567
 
2260
2568
  // src/persistent/schema.ts
2261
2569
  var SCHEMA_VERSION = 10;
@@ -2580,7 +2888,7 @@ function hasColumn(db, table, column) {
2580
2888
  // src/persistent/db.ts
2581
2889
  function openDatabase(dbPath) {
2582
2890
  if (dbPath !== ":memory:") {
2583
- mkdirSync(dirname4(dbPath), { recursive: true });
2891
+ mkdirSync(dirname5(dbPath), { recursive: true });
2584
2892
  }
2585
2893
  let db;
2586
2894
  try {
@@ -2624,8 +2932,8 @@ function nativeBindingError(err, dbPath) {
2624
2932
  }
2625
2933
 
2626
2934
  // src/persistent/dir-watermark.ts
2627
- import { readdir, stat as stat4 } from "fs/promises";
2628
- import { dirname as dirname5, join as join5 } from "path";
2935
+ import { readdir, stat as stat5 } from "fs/promises";
2936
+ import { dirname as dirname6, join as join5 } from "path";
2629
2937
  var FULL_RECONCILE_EVERY_N_SCANS = 20;
2630
2938
  async function discoverJsonlFilesGated(dirs, files, scannedDirs, options = {}) {
2631
2939
  const log = getLogger();
@@ -2641,7 +2949,7 @@ async function discoverJsonlFilesGated(dirs, files, scannedDirs, options = {}) {
2641
2949
  for (const projectDir of resolved.entries) {
2642
2950
  let dirStat;
2643
2951
  try {
2644
- dirStat = await stat4(projectDir);
2952
+ dirStat = await stat5(projectDir);
2645
2953
  } catch {
2646
2954
  scannedDirs.remove(projectDir);
2647
2955
  continue;
@@ -2679,7 +2987,7 @@ async function discoverJsonlFilesGated(dirs, files, scannedDirs, options = {}) {
2679
2987
  async function resolveProjectDirs(projectsDir, scannedDirs) {
2680
2988
  let rootStat;
2681
2989
  try {
2682
- rootStat = await stat4(projectsDir);
2990
+ rootStat = await stat5(projectsDir);
2683
2991
  } catch {
2684
2992
  return null;
2685
2993
  }
@@ -2696,7 +3004,7 @@ async function resolveProjectDirs(projectsDir, scannedDirs) {
2696
3004
  return { entries, commitRoot: { mtimeMs: rootStat.mtimeMs } };
2697
3005
  }
2698
3006
  function dirnameOf(filePath) {
2699
- return dirname5(filePath);
3007
+ return dirname6(filePath);
2700
3008
  }
2701
3009
  function joinPath(dir, name) {
2702
3010
  return join5(dir, name);
@@ -2779,7 +3087,7 @@ function toCheckpoint(row) {
2779
3087
  }
2780
3088
 
2781
3089
  // src/persistent/repositories/conversation-files.repo.ts
2782
- import { basename as basename6, dirname as dirname6 } from "path";
3090
+ import { basename as basename7, dirname as dirname7 } from "path";
2783
3091
  var ConversationFilesRepo = class {
2784
3092
  constructor(db) {
2785
3093
  this.db = db;
@@ -2802,7 +3110,7 @@ var ConversationFilesRepo = class {
2802
3110
  const info = this.db.prepare(
2803
3111
  `INSERT INTO conversation_files (absolute_path, parent_dir, file_name, account)
2804
3112
  VALUES (?, ?, ?, ?)`
2805
- ).run(canonical, dirname6(canonical), basename6(canonical), account);
3113
+ ).run(canonical, dirname7(canonical), basename7(canonical), account);
2806
3114
  return Number(info.lastInsertRowid);
2807
3115
  }
2808
3116
  // Advance the cursor + persisted reducer state after a successful index pass.
@@ -3352,6 +3660,12 @@ var PersistentEngine = class {
3352
3660
  discovered.push({ ...f, provider: cursor });
3353
3661
  }
3354
3662
  }
3663
+ const copilot = new CopilotProvider();
3664
+ if (enabled.includes(COPILOT_PROVIDER) && (options.copilotRoots?.length ?? 0) > 0) {
3665
+ for (const f of await copilot.discover(options.copilotRoots)) {
3666
+ discovered.push({ ...f, provider: copilot });
3667
+ }
3668
+ }
3355
3669
  let scanned = 0;
3356
3670
  const gitBranchMemo = /* @__PURE__ */ new Map();
3357
3671
  const resolveGitBranch = (projectPath) => {
@@ -3393,6 +3707,9 @@ var PersistentEngine = class {
3393
3707
  if (enabled.includes(CURSOR_PROVIDER) && (options.cursorRoots?.length ?? 0) > 0) {
3394
3708
  coveredAccounts.add("cursor");
3395
3709
  }
3710
+ if (enabled.includes(COPILOT_PROVIDER) && (options.copilotRoots?.length ?? 0) > 0) {
3711
+ coveredAccounts.add("copilot");
3712
+ }
3396
3713
  const seen = new Set(discovered.map((d) => canonicalPath(d.filePath)));
3397
3714
  for (const path of this.files.activePathsByAccounts([...coveredAccounts])) {
3398
3715
  if (!seen.has(path)) this.markDeleted(path);
@@ -3412,8 +3729,8 @@ var PersistentEngine = class {
3412
3729
  const tier = resolveTier(tierName, customTiers);
3413
3730
  const filePath = canonicalPath(rawFilePath);
3414
3731
  const existing = this.files.getByPath(filePath);
3415
- const { change, stat: stat5 } = classify(filePath, existing);
3416
- if (change === "vanished" || !stat5) {
3732
+ const { change, stat: stat6 } = classify(filePath, existing);
3733
+ if (change === "vanished" || !stat6) {
3417
3734
  this.markDeleted(filePath);
3418
3735
  return { meta: null, change: "vanished" };
3419
3736
  }
@@ -3426,7 +3743,7 @@ var PersistentEngine = class {
3426
3743
  filePath,
3427
3744
  account,
3428
3745
  tier,
3429
- stat5,
3746
+ stat6,
3430
3747
  resolveGitBranch
3431
3748
  );
3432
3749
  return { meta: meta2, change };
@@ -3452,7 +3769,7 @@ var PersistentEngine = class {
3452
3769
  return { meta: null, change };
3453
3770
  }
3454
3771
  meta.gitBranch = resolveGitBranch(meta.projectPath);
3455
- const fp = stat5.size > 0 ? fingerprint(filePath, stat5.size) : null;
3772
+ const fp = stat6.size > 0 ? fingerprint(filePath, stat6.size) : null;
3456
3773
  const fileId = this.files.ensure(filePath, account);
3457
3774
  const base = resume ? this.fts.readDocument(fileId) ?? emptySearchDocument() : emptySearchDocument();
3458
3775
  const searchDoc = appendSearchDelta(base, searchDelta);
@@ -3463,8 +3780,8 @@ var PersistentEngine = class {
3463
3780
  }
3464
3781
  if (!resume) this.checkpoints.remove(filePath);
3465
3782
  this.files.updateCursor(fileId, {
3466
- sizeBytes: stat5.size,
3467
- mtimeMs: stat5.mtimeMs,
3783
+ sizeBytes: stat6.size,
3784
+ mtimeMs: stat6.mtimeMs,
3468
3785
  // Advance only to the last fully-parsed line; a trailing partial line
3469
3786
  // is left for the next pass.
3470
3787
  offset: result.newOffset,
@@ -3481,8 +3798,8 @@ var PersistentEngine = class {
3481
3798
  buildSidecar(
3482
3799
  meta,
3483
3800
  {
3484
- sizeBytes: stat5.size,
3485
- mtimeMs: stat5.mtimeMs,
3801
+ sizeBytes: stat6.size,
3802
+ mtimeMs: stat6.mtimeMs,
3486
3803
  offset: result.newOffset,
3487
3804
  line: result.newLine
3488
3805
  },
@@ -3501,7 +3818,7 @@ var PersistentEngine = class {
3501
3818
  // the Threadbase path uses. The cursor records size/mtime (and offset = size)
3502
3819
  // so the next pass classifies an unchanged file as "unchanged" and skips it;
3503
3820
  // any change reparses from 0 again. No reducer_state is persisted.
3504
- async indexFileWithProvider(provider, filePath, account, tier, stat5, resolveGitBranch) {
3821
+ async indexFileWithProvider(provider, filePath, account, tier, stat6, resolveGitBranch) {
3505
3822
  const log = getLogger();
3506
3823
  let searchDoc = emptySearchDocument();
3507
3824
  const meta = await parseMetaWithProvider(provider, filePath, account, tier, (entry) => {
@@ -3514,7 +3831,7 @@ var PersistentEngine = class {
3514
3831
  if (meta.gitBranch === null && meta.projectPath) {
3515
3832
  meta.gitBranch = resolveGitBranch(meta.projectPath);
3516
3833
  }
3517
- const fp = stat5.size > 0 ? fingerprint(filePath, stat5.size) : null;
3834
+ const fp = stat6.size > 0 ? fingerprint(filePath, stat6.size) : null;
3518
3835
  const fileId = this.files.ensure(filePath, account);
3519
3836
  const upsert = this.db.transaction(() => {
3520
3837
  this.conversations.upsert(fileId, meta, meta.messageCount);
@@ -3523,11 +3840,11 @@ var PersistentEngine = class {
3523
3840
  }
3524
3841
  this.checkpoints.remove(filePath);
3525
3842
  this.files.updateCursor(fileId, {
3526
- sizeBytes: stat5.size,
3527
- mtimeMs: stat5.mtimeMs,
3843
+ sizeBytes: stat6.size,
3844
+ mtimeMs: stat6.mtimeMs,
3528
3845
  // offset = size marks the file fully consumed (non-zero so the next pass
3529
3846
  // can classify it "unchanged"); no resumable reducer state is kept.
3530
- offset: stat5.size,
3847
+ offset: stat6.size,
3531
3848
  line: 0,
3532
3849
  reducerState: null,
3533
3850
  fingerprint: fp,
@@ -3593,8 +3910,8 @@ var PersistentEngine = class {
3593
3910
  const meta = this.conversations.getByIdOrSession(id);
3594
3911
  if (!meta) return null;
3595
3912
  const filePath = meta.filePath;
3596
- if (meta.provider === CODEX_CLI_PROVIDER || meta.provider === CURSOR_PROVIDER) {
3597
- const conversation = meta.provider === CODEX_CLI_PROVIDER ? await parseCodexConversation(filePath, meta.account) : await parseCursorConversation(filePath, meta.account);
3913
+ if (meta.provider === CODEX_CLI_PROVIDER || meta.provider === CURSOR_PROVIDER || meta.provider === COPILOT_PROVIDER) {
3914
+ 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);
3598
3915
  if (!conversation) return null;
3599
3916
  const { messages } = conversation;
3600
3917
  const total2 = messages.length;
@@ -3609,7 +3926,7 @@ var PersistentEngine = class {
3609
3926
  let floor = this.checkpoints.floor(filePath, fromIndex);
3610
3927
  if (floor) {
3611
3928
  try {
3612
- if (floor.byteOffset > statSync3(filePath).size) floor = null;
3929
+ if (floor.byteOffset > statSync4(filePath).size) floor = null;
3613
3930
  } catch {
3614
3931
  }
3615
3932
  }
@@ -3963,7 +4280,7 @@ var ConversationScanner = class {
3963
4280
  const cached = statCache.get(filePath);
3964
4281
  if (cached) {
3965
4282
  try {
3966
- const s = statSync4(filePath);
4283
+ const s = statSync5(filePath);
3967
4284
  if (s.mtimeMs === cached.stat.mtimeMs && s.size === cached.stat.size) {
3968
4285
  return {
3969
4286
  meta: cached.meta,
@@ -4121,12 +4438,12 @@ var ConversationScanner = class {
4121
4438
  }
4122
4439
  log.debug({ id, filePath: meta.filePath }, "getConversation: cache miss, parsing");
4123
4440
  try {
4124
- if (this.persistent && meta.provider !== CODEX_CLI_PROVIDER && meta.provider !== CURSOR_PROVIDER) {
4441
+ if (this.persistent && meta.provider !== CODEX_CLI_PROVIDER && meta.provider !== CURSOR_PROVIDER && meta.provider !== COPILOT_PROVIDER) {
4125
4442
  const parsed = await parseConversationResumable(meta.filePath, meta.account);
4126
4443
  if (parsed) this.conversationLRU.set(cid, parsed);
4127
4444
  return parsed?.conversation ?? null;
4128
4445
  }
4129
- 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);
4446
+ 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);
4130
4447
  if (conversation) {
4131
4448
  this.conversationLRU.set(cid, { conversation });
4132
4449
  }
@@ -4180,7 +4497,7 @@ var ConversationScanner = class {
4180
4497
  // fallback, matching refreshFile.
4181
4498
  async parseSingleFilePage(filePath, account, options) {
4182
4499
  const provider = await this.resolveProviderForFile(filePath, null);
4183
- 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");
4500
+ 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");
4184
4501
  if (!conversation) return null;
4185
4502
  const { messages } = conversation;
4186
4503
  const total = messages.length;
@@ -4490,6 +4807,12 @@ var ConversationScanner = class {
4490
4807
  work.push({ ...f, provider });
4491
4808
  }
4492
4809
  }
4810
+ if (enabled.includes(COPILOT_PROVIDER) && (options.copilotRoots?.length ?? 0) > 0) {
4811
+ const provider = new CopilotProvider();
4812
+ for (const f of await provider.discover(options.copilotRoots)) {
4813
+ work.push({ ...f, provider });
4814
+ }
4815
+ }
4493
4816
  return work;
4494
4817
  }
4495
4818
  // Resolve which provider should (re)parse a file. Stored metadata wins; for a
@@ -4501,6 +4824,7 @@ var ConversationScanner = class {
4501
4824
  if (providerMatches(previous?.provider, CURSOR_PROVIDER)) {
4502
4825
  return new CursorProvider();
4503
4826
  }
4827
+ if (previous?.provider === COPILOT_PROVIDER) return new CopilotProvider();
4504
4828
  if (previous?.provider) return void 0;
4505
4829
  let sample = "";
4506
4830
  try {
@@ -4519,6 +4843,8 @@ var ConversationScanner = class {
4519
4843
  if (cursor.canParse(filePath, sample)) return cursor;
4520
4844
  const codex = new CodexCliProvider();
4521
4845
  if (codex.canParse(filePath, sample)) return codex;
4846
+ const copilot = new CopilotProvider();
4847
+ if (copilot.canParse(filePath, sample)) return copilot;
4522
4848
  return void 0;
4523
4849
  }
4524
4850
  addToSessionIndex(meta) {