@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/README.md +14 -4
- package/dist/cli.js +401 -75
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +437 -105
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +415 -86
- package/dist/index.js.map +1 -1
- package/dist/persistent/conversation-reducer.d.ts +2 -1
- package/dist/persistent/conversation-reducer.d.ts.map +1 -1
- package/dist/persistent/index-engine.d.ts.map +1 -1
- package/dist/persistent/metadata-reducer.d.ts.map +1 -1
- package/dist/providers/copilot.d.ts +33 -0
- package/dist/providers/copilot.d.ts.map +1 -0
- package/dist/providers/provider.d.ts +2 -1
- package/dist/providers/provider.d.ts.map +1 -1
- package/dist/scanner.d.ts.map +1 -1
- package/dist/search-document.d.ts.map +1 -1
- package/dist/types.d.ts +9 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
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;
|
|
@@ -431,6 +432,10 @@ function reduceLine(state, entry, tier) {
|
|
|
431
432
|
if (type !== "user" && type !== "assistant") return;
|
|
432
433
|
if (entry.isMeta) return;
|
|
433
434
|
const msg = entry.message;
|
|
435
|
+
if (entry.isCompactSummary === true) {
|
|
436
|
+
if (extractTextContent(msg?.content)) state.pageMessageCount++;
|
|
437
|
+
return;
|
|
438
|
+
}
|
|
434
439
|
if (state.model === null && msg?.model) state.model = msg.model;
|
|
435
440
|
if (type === "user" && !state.firstUserSeen) {
|
|
436
441
|
state.firstUserSeen = true;
|
|
@@ -765,8 +770,20 @@ function reduceConvLine(state, entry) {
|
|
|
765
770
|
if (entry.lastPrompt && !state.lastPrompt) state.lastPrompt = entry.lastPrompt;
|
|
766
771
|
return null;
|
|
767
772
|
}
|
|
773
|
+
if (type === "system" && entry.subtype === "compact_boundary") {
|
|
774
|
+
const meta = entry.compactMetadata ?? {};
|
|
775
|
+
state.pendingCompaction = {
|
|
776
|
+
trigger: typeof meta.trigger === "string" ? meta.trigger : void 0,
|
|
777
|
+
preTokens: typeof meta.preTokens === "number" ? meta.preTokens : void 0,
|
|
778
|
+
postTokens: typeof meta.postTokens === "number" ? meta.postTokens : void 0
|
|
779
|
+
};
|
|
780
|
+
return null;
|
|
781
|
+
}
|
|
768
782
|
if (type !== "user" && type !== "assistant") return null;
|
|
769
783
|
if (entry.isMeta) return null;
|
|
784
|
+
const isCompactSummary = type === "user" && entry.isCompactSummary === true;
|
|
785
|
+
const compaction = isCompactSummary ? state.pendingCompaction : void 0;
|
|
786
|
+
if (isCompactSummary) delete state.pendingCompaction;
|
|
770
787
|
const msg = entry.message;
|
|
771
788
|
const toolUseBlocks = extractToolUseBlocks(msg?.content);
|
|
772
789
|
for (const block of toolUseBlocks) state.pendingToolUses[block.id] = block;
|
|
@@ -826,7 +843,9 @@ function reduceConvLine(state, entry) {
|
|
|
826
843
|
isSidechain: typeof entry.isSidechain === "boolean" ? entry.isSidechain : void 0,
|
|
827
844
|
permissionMode: type === "user" ? entry.permissionMode : void 0,
|
|
828
845
|
hasImages: hasImageBlocks(msg?.content) || void 0,
|
|
829
|
-
attachment: entry.attachment !== void 0 ? entry.attachment : void 0
|
|
846
|
+
attachment: entry.attachment !== void 0 ? entry.attachment : void 0,
|
|
847
|
+
isCompactSummary: isCompactSummary || void 0,
|
|
848
|
+
compaction
|
|
830
849
|
};
|
|
831
850
|
}
|
|
832
851
|
function parseJsonlLine(line, state = initialConvState()) {
|
|
@@ -1287,13 +1306,293 @@ async function parseCodexConversation(filePath, account) {
|
|
|
1287
1306
|
};
|
|
1288
1307
|
}
|
|
1289
1308
|
|
|
1290
|
-
// src/providers/
|
|
1291
|
-
import { createHash } from "crypto";
|
|
1309
|
+
// src/providers/copilot.ts
|
|
1292
1310
|
import fg2 from "fast-glob";
|
|
1293
|
-
import { createReadStream as createReadStream3,
|
|
1311
|
+
import { createReadStream as createReadStream3, statSync } from "fs";
|
|
1294
1312
|
import { stat as stat2 } from "fs/promises";
|
|
1295
|
-
import { basename as basename4, dirname as dirname3
|
|
1313
|
+
import { basename as basename4, dirname as dirname3 } from "path";
|
|
1296
1314
|
import { createInterface as createInterface3 } from "readline";
|
|
1315
|
+
var SESSION_START = "session.start";
|
|
1316
|
+
var USER_MESSAGE = "user.message";
|
|
1317
|
+
var ASSISTANT_MESSAGE = "assistant.message";
|
|
1318
|
+
var CopilotProvider = class {
|
|
1319
|
+
name = COPILOT_PROVIDER;
|
|
1320
|
+
async discover(roots) {
|
|
1321
|
+
const log = getLogger();
|
|
1322
|
+
const results = [];
|
|
1323
|
+
for (const root of roots) {
|
|
1324
|
+
let paths;
|
|
1325
|
+
try {
|
|
1326
|
+
paths = await fg2(["*/events.jsonl", "session-state/*/events.jsonl"], {
|
|
1327
|
+
cwd: root,
|
|
1328
|
+
absolute: true,
|
|
1329
|
+
dot: false,
|
|
1330
|
+
unique: true
|
|
1331
|
+
});
|
|
1332
|
+
} catch (err) {
|
|
1333
|
+
log.warn({ root, err }, "copilot discovery: glob failed");
|
|
1334
|
+
continue;
|
|
1335
|
+
}
|
|
1336
|
+
for (const filePath of paths) {
|
|
1337
|
+
try {
|
|
1338
|
+
const s = await stat2(filePath);
|
|
1339
|
+
if (s.size > 0) results.push({ filePath: canonicalPath(filePath), account: "copilot" });
|
|
1340
|
+
} catch (err) {
|
|
1341
|
+
log.warn({ filePath, err }, "copilot discovery: stat failed");
|
|
1342
|
+
}
|
|
1343
|
+
}
|
|
1344
|
+
}
|
|
1345
|
+
return results;
|
|
1346
|
+
}
|
|
1347
|
+
canParse(_filePath, sample) {
|
|
1348
|
+
for (const line of sample.split("\n")) {
|
|
1349
|
+
if (!line.trim()) continue;
|
|
1350
|
+
try {
|
|
1351
|
+
if (looksLikeCopilotEvent(JSON.parse(line))) return true;
|
|
1352
|
+
} catch {
|
|
1353
|
+
}
|
|
1354
|
+
}
|
|
1355
|
+
return false;
|
|
1356
|
+
}
|
|
1357
|
+
createEmptyAccumulator() {
|
|
1358
|
+
return {
|
|
1359
|
+
sessionId: "",
|
|
1360
|
+
cwd: "",
|
|
1361
|
+
gitBranch: null,
|
|
1362
|
+
model: null,
|
|
1363
|
+
latestTimestamp: "",
|
|
1364
|
+
messageCount: 0,
|
|
1365
|
+
lastMessageSender: "user",
|
|
1366
|
+
firstUser: null,
|
|
1367
|
+
lastUser: null,
|
|
1368
|
+
lastAssistant: null,
|
|
1369
|
+
toolNames: [],
|
|
1370
|
+
previewParts: [],
|
|
1371
|
+
previewLength: 0,
|
|
1372
|
+
snippetParts: [],
|
|
1373
|
+
snippetLength: 0
|
|
1374
|
+
};
|
|
1375
|
+
}
|
|
1376
|
+
reduceEntry(acc, entry, tier) {
|
|
1377
|
+
reduceCopilotEntry(acc, entry, tier);
|
|
1378
|
+
}
|
|
1379
|
+
finalize(acc, filePath, account, tier) {
|
|
1380
|
+
return finalizeCopilotMeta(acc, filePath, account, tier);
|
|
1381
|
+
}
|
|
1382
|
+
};
|
|
1383
|
+
function looksLikeCopilotEvent(entry) {
|
|
1384
|
+
return typeof entry.type === "string" && typeof entry.id === "string" && "parentId" in entry && asRecord(entry.data) !== null;
|
|
1385
|
+
}
|
|
1386
|
+
var asString2 = (v) => typeof v === "string" ? v : "";
|
|
1387
|
+
function asRecord(v) {
|
|
1388
|
+
return v && typeof v === "object" && !Array.isArray(v) ? v : null;
|
|
1389
|
+
}
|
|
1390
|
+
function copilotToolUseBlocks(data) {
|
|
1391
|
+
if (!Array.isArray(data.toolRequests)) return [];
|
|
1392
|
+
const blocks = [];
|
|
1393
|
+
for (const item of data.toolRequests) {
|
|
1394
|
+
const request = asRecord(item);
|
|
1395
|
+
const name = asString2(request?.name);
|
|
1396
|
+
if (!request || !name) continue;
|
|
1397
|
+
const input = asRecord(request.arguments) ?? { arguments: asString2(request.arguments) };
|
|
1398
|
+
blocks.push({ id: asString2(request.toolCallId), name, input });
|
|
1399
|
+
}
|
|
1400
|
+
return blocks;
|
|
1401
|
+
}
|
|
1402
|
+
function copilotEntryToMessage(entry) {
|
|
1403
|
+
if (!looksLikeCopilotEvent(entry)) return null;
|
|
1404
|
+
const data = entry.data;
|
|
1405
|
+
const timestamp = asString2(entry.timestamp);
|
|
1406
|
+
const uuid = asString2(data.messageId) || asString2(entry.id);
|
|
1407
|
+
if (entry.type === USER_MESSAGE) {
|
|
1408
|
+
const text = cleanSystemTags(asString2(data.content));
|
|
1409
|
+
return text ? { role: "user", text, timestamp, uuid } : null;
|
|
1410
|
+
}
|
|
1411
|
+
if (entry.type === ASSISTANT_MESSAGE) {
|
|
1412
|
+
const text = asString2(data.content).trim();
|
|
1413
|
+
const blocks = copilotToolUseBlocks(data);
|
|
1414
|
+
if (!text && blocks.length === 0) return null;
|
|
1415
|
+
const model = asString2(data.model);
|
|
1416
|
+
const metadata = {
|
|
1417
|
+
...model ? { model } : {},
|
|
1418
|
+
...blocks.length > 0 ? { toolUses: blocks.map((b) => b.name), toolUseBlocks: blocks } : {}
|
|
1419
|
+
};
|
|
1420
|
+
return {
|
|
1421
|
+
role: "assistant",
|
|
1422
|
+
text,
|
|
1423
|
+
timestamp,
|
|
1424
|
+
uuid,
|
|
1425
|
+
...Object.keys(metadata).length > 0 ? { metadata } : {}
|
|
1426
|
+
};
|
|
1427
|
+
}
|
|
1428
|
+
return null;
|
|
1429
|
+
}
|
|
1430
|
+
function parseCopilotJsonlLine(line) {
|
|
1431
|
+
const trimmed = line.trim();
|
|
1432
|
+
if (!trimmed) return null;
|
|
1433
|
+
try {
|
|
1434
|
+
return copilotEntryToMessage(JSON.parse(trimmed));
|
|
1435
|
+
} catch {
|
|
1436
|
+
return null;
|
|
1437
|
+
}
|
|
1438
|
+
}
|
|
1439
|
+
function readSessionStart(entry) {
|
|
1440
|
+
if (entry.type !== SESSION_START) return null;
|
|
1441
|
+
const data = asRecord(entry.data);
|
|
1442
|
+
if (!data) return null;
|
|
1443
|
+
const context = asRecord(data.context);
|
|
1444
|
+
return {
|
|
1445
|
+
sessionId: asString2(data.sessionId),
|
|
1446
|
+
cwd: asString2(context?.cwd),
|
|
1447
|
+
branch: asString2(context?.branch)
|
|
1448
|
+
};
|
|
1449
|
+
}
|
|
1450
|
+
function reduceCopilotEntry(acc, entry, tier) {
|
|
1451
|
+
const start = readSessionStart(entry);
|
|
1452
|
+
if (start) {
|
|
1453
|
+
if (!acc.sessionId) acc.sessionId = start.sessionId;
|
|
1454
|
+
if (!acc.cwd) acc.cwd = start.cwd;
|
|
1455
|
+
if (!acc.gitBranch && start.branch) acc.gitBranch = start.branch;
|
|
1456
|
+
return;
|
|
1457
|
+
}
|
|
1458
|
+
const message = copilotEntryToMessage(entry);
|
|
1459
|
+
if (!message) return;
|
|
1460
|
+
for (const name of message.metadata?.toolUses ?? []) {
|
|
1461
|
+
if (!acc.toolNames.includes(name)) acc.toolNames.push(name);
|
|
1462
|
+
}
|
|
1463
|
+
if (message.metadata?.model) acc.model = message.metadata.model;
|
|
1464
|
+
const { role, text, timestamp } = message;
|
|
1465
|
+
if (!text) return;
|
|
1466
|
+
if (timestamp && (!acc.latestTimestamp || timestamp > acc.latestTimestamp)) {
|
|
1467
|
+
acc.latestTimestamp = timestamp;
|
|
1468
|
+
}
|
|
1469
|
+
acc.messageCount++;
|
|
1470
|
+
acc.lastMessageSender = role;
|
|
1471
|
+
const snapshot = { text: text.slice(0, 200), timestamp };
|
|
1472
|
+
if (role === "user") {
|
|
1473
|
+
if (!acc.firstUser) acc.firstUser = snapshot;
|
|
1474
|
+
acc.lastUser = snapshot;
|
|
1475
|
+
} else {
|
|
1476
|
+
acc.lastAssistant = snapshot;
|
|
1477
|
+
}
|
|
1478
|
+
if (acc.previewLength < tier.previewMax) {
|
|
1479
|
+
acc.previewParts.push(text);
|
|
1480
|
+
acc.previewLength += text.length;
|
|
1481
|
+
}
|
|
1482
|
+
if (acc.snippetLength < tier.snippetMax) {
|
|
1483
|
+
const remaining = tier.snippetMax - acc.snippetLength;
|
|
1484
|
+
const chunk = text.length > remaining ? text.slice(0, remaining) : text;
|
|
1485
|
+
acc.snippetParts.push(chunk);
|
|
1486
|
+
acc.snippetLength += chunk.length;
|
|
1487
|
+
}
|
|
1488
|
+
}
|
|
1489
|
+
function finalizeCopilotMeta(acc, filePath, account, tier) {
|
|
1490
|
+
if (acc.messageCount === 0) return null;
|
|
1491
|
+
const sessionId = acc.sessionId || sessionIdFromPath(filePath);
|
|
1492
|
+
const kind = acc.lastAssistant === null && acc.toolNames.length > 0 ? "task" : "conversation";
|
|
1493
|
+
return {
|
|
1494
|
+
id: filePath,
|
|
1495
|
+
filePath,
|
|
1496
|
+
provider: COPILOT_PROVIDER,
|
|
1497
|
+
kind,
|
|
1498
|
+
externalSessionId: sessionId,
|
|
1499
|
+
sessionId,
|
|
1500
|
+
sessionName: deriveSessionNameFromFirstMessage(acc.firstUser),
|
|
1501
|
+
projectPath: acc.cwd,
|
|
1502
|
+
projectName: getShortProjectName4(acc.cwd),
|
|
1503
|
+
account,
|
|
1504
|
+
timestamp: acc.latestTimestamp || fileMtimeIso(filePath),
|
|
1505
|
+
messageCount: acc.messageCount,
|
|
1506
|
+
lastMessageSender: acc.lastMessageSender,
|
|
1507
|
+
preview: acc.previewParts.join(" ").slice(0, tier.previewMax),
|
|
1508
|
+
contentSnippet: acc.snippetParts.join(" "),
|
|
1509
|
+
gitBranch: acc.gitBranch,
|
|
1510
|
+
model: acc.model,
|
|
1511
|
+
isSubagent: false,
|
|
1512
|
+
parentSessionId: null,
|
|
1513
|
+
isTeammate: false,
|
|
1514
|
+
teamName: null,
|
|
1515
|
+
toolNames: acc.toolNames,
|
|
1516
|
+
firstMessage: acc.firstUser,
|
|
1517
|
+
lastMessage: acc.lastAssistant ?? acc.lastUser,
|
|
1518
|
+
lastPrompt: acc.lastUser?.text || void 0
|
|
1519
|
+
};
|
|
1520
|
+
}
|
|
1521
|
+
function sessionIdFromPath(filePath) {
|
|
1522
|
+
return basename4(dirname3(filePath));
|
|
1523
|
+
}
|
|
1524
|
+
function getShortProjectName4(fullPath) {
|
|
1525
|
+
return fullPath.split(/[/\\]/).filter(Boolean).slice(-3).join("/");
|
|
1526
|
+
}
|
|
1527
|
+
function fileMtimeIso(filePath) {
|
|
1528
|
+
try {
|
|
1529
|
+
return new Date(statSync(filePath).mtimeMs).toISOString();
|
|
1530
|
+
} catch {
|
|
1531
|
+
return (/* @__PURE__ */ new Date()).toISOString();
|
|
1532
|
+
}
|
|
1533
|
+
}
|
|
1534
|
+
async function parseCopilotConversation(filePath, account) {
|
|
1535
|
+
const log = getLogger();
|
|
1536
|
+
const messages = [];
|
|
1537
|
+
const textParts = [];
|
|
1538
|
+
let sessionId = "";
|
|
1539
|
+
let cwd = "";
|
|
1540
|
+
let latestTimestamp = "";
|
|
1541
|
+
let lastUserText = "";
|
|
1542
|
+
const rl = createInterface3({ input: createReadStream3(filePath), crlfDelay: Infinity });
|
|
1543
|
+
try {
|
|
1544
|
+
for await (const line of rl) {
|
|
1545
|
+
if (!line.trim()) continue;
|
|
1546
|
+
let entry;
|
|
1547
|
+
try {
|
|
1548
|
+
entry = JSON.parse(line);
|
|
1549
|
+
} catch {
|
|
1550
|
+
continue;
|
|
1551
|
+
}
|
|
1552
|
+
const start = readSessionStart(entry);
|
|
1553
|
+
if (start) {
|
|
1554
|
+
if (!sessionId) sessionId = start.sessionId;
|
|
1555
|
+
if (!cwd) cwd = start.cwd;
|
|
1556
|
+
continue;
|
|
1557
|
+
}
|
|
1558
|
+
const message = copilotEntryToMessage(entry);
|
|
1559
|
+
if (!message) continue;
|
|
1560
|
+
if (message.timestamp && (!latestTimestamp || message.timestamp > latestTimestamp)) {
|
|
1561
|
+
latestTimestamp = message.timestamp;
|
|
1562
|
+
}
|
|
1563
|
+
messages.push(message);
|
|
1564
|
+
if (!message.text) continue;
|
|
1565
|
+
textParts.push(message.text);
|
|
1566
|
+
if (message.role === "user") lastUserText = message.text;
|
|
1567
|
+
}
|
|
1568
|
+
} catch (err) {
|
|
1569
|
+
log.warn({ filePath, err }, "parseCopilotConversation: read failed");
|
|
1570
|
+
return null;
|
|
1571
|
+
}
|
|
1572
|
+
if (messages.length === 0) return null;
|
|
1573
|
+
return {
|
|
1574
|
+
id: filePath,
|
|
1575
|
+
filePath,
|
|
1576
|
+
projectPath: cwd,
|
|
1577
|
+
projectName: getShortProjectName4(cwd),
|
|
1578
|
+
sessionId: sessionId || sessionIdFromPath(filePath),
|
|
1579
|
+
sessionName: "",
|
|
1580
|
+
messages,
|
|
1581
|
+
fullText: textParts.join(" "),
|
|
1582
|
+
timestamp: latestTimestamp || fileMtimeIso(filePath),
|
|
1583
|
+
messageCount: messages.length,
|
|
1584
|
+
account,
|
|
1585
|
+
lastPrompt: lastUserText || void 0
|
|
1586
|
+
};
|
|
1587
|
+
}
|
|
1588
|
+
|
|
1589
|
+
// src/providers/cursor.ts
|
|
1590
|
+
import { createHash } from "crypto";
|
|
1591
|
+
import fg3 from "fast-glob";
|
|
1592
|
+
import { createReadStream as createReadStream4, existsSync, statSync as statSync2 } from "fs";
|
|
1593
|
+
import { stat as stat3 } from "fs/promises";
|
|
1594
|
+
import { basename as basename5, dirname as dirname4, join as join4, sep as sep2 } from "path";
|
|
1595
|
+
import { createInterface as createInterface4 } from "readline";
|
|
1297
1596
|
var TIMESTAMP_RE = /<timestamp>\s*([\s\S]*?)\s*<\/timestamp>/;
|
|
1298
1597
|
var USER_QUERY_RE = /<user_query>\s*([\s\S]*?)\s*<\/user_query>/;
|
|
1299
1598
|
var SUBAGENT_PATH_RE2 = /[\\/]subagents[\\/]/;
|
|
@@ -1305,7 +1604,7 @@ var CursorProvider = class {
|
|
|
1305
1604
|
for (const root of roots) {
|
|
1306
1605
|
let paths;
|
|
1307
1606
|
try {
|
|
1308
|
-
paths = await
|
|
1607
|
+
paths = await fg3(["**/agent-transcripts/**/*.jsonl"], {
|
|
1309
1608
|
cwd: root,
|
|
1310
1609
|
absolute: true,
|
|
1311
1610
|
dot: false,
|
|
@@ -1317,7 +1616,7 @@ var CursorProvider = class {
|
|
|
1317
1616
|
}
|
|
1318
1617
|
for (const filePath of paths) {
|
|
1319
1618
|
try {
|
|
1320
|
-
const s = await
|
|
1619
|
+
const s = await stat3(filePath);
|
|
1321
1620
|
if (s.size > 0) results.push({ filePath: canonicalPath(filePath), account: "cursor" });
|
|
1322
1621
|
} catch (err) {
|
|
1323
1622
|
log.warn({ filePath, err }, "cursor discovery: stat failed");
|
|
@@ -1381,7 +1680,7 @@ function looksLikeImportedClaudeEntry(entry) {
|
|
|
1381
1680
|
function looksLikeImportedCodexEntry(entry) {
|
|
1382
1681
|
return entry.type === "session_meta" || entry.type === "response_item" || entry.type === "event_msg";
|
|
1383
1682
|
}
|
|
1384
|
-
function
|
|
1683
|
+
function asString3(value) {
|
|
1385
1684
|
return typeof value === "string" ? value : "";
|
|
1386
1685
|
}
|
|
1387
1686
|
function provenanceToken(value) {
|
|
@@ -1495,7 +1794,7 @@ function cursorEntryToMessage(entry) {
|
|
|
1495
1794
|
const role = message?.role === "assistant" || entry.type === "assistant" ? "assistant" : "user";
|
|
1496
1795
|
const content = message?.content ?? entry.content;
|
|
1497
1796
|
return withToolUses(
|
|
1498
|
-
{ role, text: extractCursorText(content), timestamp:
|
|
1797
|
+
{ role, text: extractCursorText(content), timestamp: asString3(entry.timestamp) },
|
|
1499
1798
|
content
|
|
1500
1799
|
);
|
|
1501
1800
|
}
|
|
@@ -1572,11 +1871,11 @@ function reduceCursorEntry(acc, entry, tier) {
|
|
|
1572
1871
|
}
|
|
1573
1872
|
function finalizeCursorMeta(acc, filePath, account, tier) {
|
|
1574
1873
|
if (acc.messageCount === 0) return null;
|
|
1575
|
-
const sessionId =
|
|
1874
|
+
const sessionId = basename5(filePath, ".jsonl");
|
|
1576
1875
|
const isSubagent = SUBAGENT_PATH_RE2.test(filePath);
|
|
1577
1876
|
const parent = isSubagent ? parentFromSubagentPath(filePath) : null;
|
|
1578
1877
|
const { projectPath, projectName } = projectFromCursorPath(filePath);
|
|
1579
|
-
const timestamp = acc.latestTimestamp ||
|
|
1878
|
+
const timestamp = acc.latestTimestamp || fileMtimeIso2(filePath);
|
|
1580
1879
|
const kind = acc.lastAssistant === null && acc.toolNames.length > 0 ? "task" : "conversation";
|
|
1581
1880
|
return {
|
|
1582
1881
|
id: filePath,
|
|
@@ -1611,9 +1910,9 @@ function finalizeCursorMeta(acc, filePath, account, tier) {
|
|
|
1611
1910
|
};
|
|
1612
1911
|
}
|
|
1613
1912
|
function parentFromSubagentPath(filePath) {
|
|
1614
|
-
const subagentsDir =
|
|
1615
|
-
const parentDir =
|
|
1616
|
-
const parentSessionUuid =
|
|
1913
|
+
const subagentsDir = dirname4(filePath);
|
|
1914
|
+
const parentDir = dirname4(subagentsDir);
|
|
1915
|
+
const parentSessionUuid = basename5(parentDir);
|
|
1617
1916
|
if (!parentSessionUuid) return null;
|
|
1618
1917
|
return {
|
|
1619
1918
|
parentSessionUuid,
|
|
@@ -1623,11 +1922,11 @@ function parentFromSubagentPath(filePath) {
|
|
|
1623
1922
|
function projectFromCursorPath(filePath) {
|
|
1624
1923
|
const parts = filePath.split(/[/\\]/);
|
|
1625
1924
|
const idx = parts.lastIndexOf("agent-transcripts");
|
|
1626
|
-
const cursorProjectDir = idx > 0 ? parts.slice(0, idx).join(sep2) :
|
|
1627
|
-
const slug =
|
|
1925
|
+
const cursorProjectDir = idx > 0 ? parts.slice(0, idx).join(sep2) : dirname4(dirname4(filePath));
|
|
1926
|
+
const slug = basename5(cursorProjectDir);
|
|
1628
1927
|
const decoded = decodeCursorProjectSlug(slug);
|
|
1629
1928
|
const projectPath = decoded ?? cursorProjectDir;
|
|
1630
|
-
return { projectPath, projectName:
|
|
1929
|
+
return { projectPath, projectName: getShortProjectName5(projectPath) || slug };
|
|
1631
1930
|
}
|
|
1632
1931
|
function decodeCursorProjectSlug(slug) {
|
|
1633
1932
|
if (!slug) return null;
|
|
@@ -1648,7 +1947,7 @@ function decodeCursorProjectSlug(slug) {
|
|
|
1648
1947
|
for (let j = segments.length; j > i; j--) {
|
|
1649
1948
|
const candidate = join4(acc, segments.slice(i, j).join("-"));
|
|
1650
1949
|
try {
|
|
1651
|
-
if (existsSync(candidate) &&
|
|
1950
|
+
if (existsSync(candidate) && statSync2(candidate).isDirectory()) {
|
|
1652
1951
|
found = candidate;
|
|
1653
1952
|
next = j;
|
|
1654
1953
|
break;
|
|
@@ -1662,12 +1961,12 @@ function decodeCursorProjectSlug(slug) {
|
|
|
1662
1961
|
}
|
|
1663
1962
|
return acc;
|
|
1664
1963
|
}
|
|
1665
|
-
function
|
|
1964
|
+
function getShortProjectName5(fullPath) {
|
|
1666
1965
|
return fullPath.split(/[/\\]/).filter(Boolean).slice(-3).join("/");
|
|
1667
1966
|
}
|
|
1668
|
-
function
|
|
1967
|
+
function fileMtimeIso2(filePath) {
|
|
1669
1968
|
try {
|
|
1670
|
-
return new Date(
|
|
1969
|
+
return new Date(statSync2(filePath).mtimeMs).toISOString();
|
|
1671
1970
|
} catch {
|
|
1672
1971
|
return (/* @__PURE__ */ new Date()).toISOString();
|
|
1673
1972
|
}
|
|
@@ -1678,7 +1977,7 @@ async function parseCursorConversation(filePath, account) {
|
|
|
1678
1977
|
const textParts = [];
|
|
1679
1978
|
let latestTimestamp = "";
|
|
1680
1979
|
let lastUserText = "";
|
|
1681
|
-
const rl =
|
|
1980
|
+
const rl = createInterface4({ input: createReadStream4(filePath), crlfDelay: Infinity });
|
|
1682
1981
|
try {
|
|
1683
1982
|
for await (const line of rl) {
|
|
1684
1983
|
const message = parseCursorJsonlLine(line, messages.length);
|
|
@@ -1697,7 +1996,7 @@ async function parseCursorConversation(filePath, account) {
|
|
|
1697
1996
|
}
|
|
1698
1997
|
if (messages.length === 0) return null;
|
|
1699
1998
|
const { projectPath, projectName } = projectFromCursorPath(filePath);
|
|
1700
|
-
const sessionId =
|
|
1999
|
+
const sessionId = basename5(filePath, ".jsonl");
|
|
1701
2000
|
return {
|
|
1702
2001
|
id: filePath,
|
|
1703
2002
|
filePath,
|
|
@@ -1707,7 +2006,7 @@ async function parseCursorConversation(filePath, account) {
|
|
|
1707
2006
|
sessionName: "",
|
|
1708
2007
|
messages,
|
|
1709
2008
|
fullText: textParts.join(" "),
|
|
1710
|
-
timestamp: latestTimestamp ||
|
|
2009
|
+
timestamp: latestTimestamp || fileMtimeIso2(filePath),
|
|
1711
2010
|
messageCount: messages.length,
|
|
1712
2011
|
account,
|
|
1713
2012
|
lastPrompt: lastUserText || void 0
|
|
@@ -1715,8 +2014,8 @@ async function parseCursorConversation(filePath, account) {
|
|
|
1715
2014
|
}
|
|
1716
2015
|
|
|
1717
2016
|
// src/discovery.ts
|
|
1718
|
-
import
|
|
1719
|
-
import { stat as
|
|
2017
|
+
import fg4 from "fast-glob";
|
|
2018
|
+
import { stat as stat4 } from "fs/promises";
|
|
1720
2019
|
var EXCLUDED_SEGMENTS = ["/memory/", "/tool-results/"];
|
|
1721
2020
|
var STAT_CONCURRENCY = 32;
|
|
1722
2021
|
async function discoverJsonlFiles(dirs, onProgress) {
|
|
@@ -1725,7 +2024,7 @@ async function discoverJsonlFiles(dirs, onProgress) {
|
|
|
1725
2024
|
for (const { projectsDir, account } of dirs) {
|
|
1726
2025
|
let filePaths;
|
|
1727
2026
|
try {
|
|
1728
|
-
filePaths = await
|
|
2027
|
+
filePaths = await fg4("**/*.jsonl", {
|
|
1729
2028
|
cwd: projectsDir,
|
|
1730
2029
|
absolute: true,
|
|
1731
2030
|
dot: false
|
|
@@ -1743,7 +2042,7 @@ async function discoverJsonlFiles(dirs, onProgress) {
|
|
|
1743
2042
|
const statted = await Promise.all(
|
|
1744
2043
|
chunk.map(async (filePath) => {
|
|
1745
2044
|
try {
|
|
1746
|
-
const s = await
|
|
2045
|
+
const s = await stat4(filePath);
|
|
1747
2046
|
return { filePath, size: s.size };
|
|
1748
2047
|
} catch (err) {
|
|
1749
2048
|
log.warn({ filePath, err }, "discovery: stat failed");
|
|
@@ -1818,7 +2117,7 @@ var ThreadbaseProvider = class {
|
|
|
1818
2117
|
|
|
1819
2118
|
// src/scanner.ts
|
|
1820
2119
|
import { EventEmitter } from "events";
|
|
1821
|
-
import { closeSync as closeSync2, openSync as openSync2, readSync as readSync2, statSync as
|
|
2120
|
+
import { closeSync as closeSync2, openSync as openSync2, readSync as readSync2, statSync as statSync5 } from "fs";
|
|
1822
2121
|
import { homedir as homedir2 } from "os";
|
|
1823
2122
|
import { join as join6 } from "path";
|
|
1824
2123
|
|
|
@@ -1859,18 +2158,18 @@ var LRUCache = class {
|
|
|
1859
2158
|
};
|
|
1860
2159
|
|
|
1861
2160
|
// src/persistent/conversation-stream.ts
|
|
1862
|
-
import { basename as
|
|
2161
|
+
import { basename as basename6 } from "path";
|
|
1863
2162
|
|
|
1864
2163
|
// src/persistent/paged-reader.ts
|
|
1865
|
-
import { createReadStream as
|
|
2164
|
+
import { createReadStream as createReadStream6 } from "fs";
|
|
1866
2165
|
import { setImmediate as yieldToEventLoop2 } from "timers/promises";
|
|
1867
2166
|
|
|
1868
2167
|
// src/persistent/jsonl-tail-reader.ts
|
|
1869
|
-
import { createReadStream as
|
|
2168
|
+
import { createReadStream as createReadStream5 } from "fs";
|
|
1870
2169
|
import { setImmediate as yieldToEventLoop } from "timers/promises";
|
|
1871
2170
|
var YIELD_EVERY_LINES = 500;
|
|
1872
2171
|
async function tailReduce(filePath, startOffset, startLine, state, tier, onEntry) {
|
|
1873
|
-
const stream =
|
|
2172
|
+
const stream = createReadStream5(filePath, { start: startOffset, encoding: "utf8" });
|
|
1874
2173
|
let buffer = "";
|
|
1875
2174
|
let offset = startOffset;
|
|
1876
2175
|
let line = startLine;
|
|
@@ -1907,7 +2206,7 @@ async function tailReduce(filePath, startOffset, startLine, state, tier, onEntry
|
|
|
1907
2206
|
// src/persistent/paged-reader.ts
|
|
1908
2207
|
var CHECKPOINT_INTERVAL = 500;
|
|
1909
2208
|
async function streamMessages(filePath, startOffset, startLine, state, onMessage, onEntry) {
|
|
1910
|
-
const stream =
|
|
2209
|
+
const stream = createReadStream6(filePath, { start: startOffset, encoding: "utf8" });
|
|
1911
2210
|
let buffer = "";
|
|
1912
2211
|
let offset = startOffset;
|
|
1913
2212
|
let line = startLine;
|
|
@@ -2019,7 +2318,7 @@ function assemble(filePath, account, messages, fullText, turnDurations, state) {
|
|
|
2019
2318
|
filePath,
|
|
2020
2319
|
projectPath: state.cwd,
|
|
2021
2320
|
projectName: getShortProjectName2(state.cwd),
|
|
2022
|
-
sessionId: state.sessionId ||
|
|
2321
|
+
sessionId: state.sessionId || basename6(filePath, ".jsonl"),
|
|
2023
2322
|
sessionName: state.sessionName || deriveSessionNameFromFirstMessage(messages.find((m) => m.role === "user" && m.text) ?? null),
|
|
2024
2323
|
messages,
|
|
2025
2324
|
fullText,
|
|
@@ -2064,7 +2363,7 @@ async function extendConversation(previous, resume, filePath, account) {
|
|
|
2064
2363
|
|
|
2065
2364
|
// src/persistent/cursor.ts
|
|
2066
2365
|
import { createHash as createHash2 } from "crypto";
|
|
2067
|
-
import { closeSync, openSync, readSync, statSync as
|
|
2366
|
+
import { closeSync, openSync, readSync, statSync as statSync3 } from "fs";
|
|
2068
2367
|
var FP_BYTES = 4096;
|
|
2069
2368
|
function fingerprint(filePath, size) {
|
|
2070
2369
|
const hash = createHash2("sha1");
|
|
@@ -2088,46 +2387,46 @@ function fingerprint(filePath, size) {
|
|
|
2088
2387
|
return hash.digest("hex");
|
|
2089
2388
|
}
|
|
2090
2389
|
function classify(filePath, existing) {
|
|
2091
|
-
let
|
|
2390
|
+
let stat6;
|
|
2092
2391
|
try {
|
|
2093
|
-
const s =
|
|
2094
|
-
|
|
2392
|
+
const s = statSync3(filePath);
|
|
2393
|
+
stat6 = { size: s.size, mtimeMs: s.mtimeMs };
|
|
2095
2394
|
} catch {
|
|
2096
2395
|
return { change: "vanished" };
|
|
2097
2396
|
}
|
|
2098
2397
|
if (!existing || existing.status !== "active" || existing.last_indexed_offset === 0) {
|
|
2099
|
-
return { change: "reindex", stat:
|
|
2398
|
+
return { change: "reindex", stat: stat6 };
|
|
2100
2399
|
}
|
|
2101
|
-
if (
|
|
2102
|
-
return { change: "reindex", stat:
|
|
2400
|
+
if (stat6.size < existing.last_indexed_offset) {
|
|
2401
|
+
return { change: "reindex", stat: stat6 };
|
|
2103
2402
|
}
|
|
2104
|
-
if (
|
|
2105
|
-
return { change: "unchanged", stat:
|
|
2403
|
+
if (stat6.size === existing.size_bytes && stat6.mtimeMs === existing.mtime_ms) {
|
|
2404
|
+
return { change: "unchanged", stat: stat6 };
|
|
2106
2405
|
}
|
|
2107
|
-
if (
|
|
2108
|
-
const fp = fingerprint(filePath,
|
|
2406
|
+
if (stat6.size === existing.last_indexed_offset) {
|
|
2407
|
+
const fp = fingerprint(filePath, stat6.size);
|
|
2109
2408
|
if (existing.content_fingerprint && fp !== existing.content_fingerprint) {
|
|
2110
|
-
return { change: "reindex", stat:
|
|
2409
|
+
return { change: "reindex", stat: stat6 };
|
|
2111
2410
|
}
|
|
2112
|
-
return { change: "unchanged", stat:
|
|
2411
|
+
return { change: "unchanged", stat: stat6 };
|
|
2113
2412
|
}
|
|
2114
2413
|
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:
|
|
2414
|
+
return { change: "appended", stat: stat6 };
|
|
2116
2415
|
}
|
|
2117
|
-
return { change: "reindex", stat:
|
|
2416
|
+
return { change: "reindex", stat: stat6 };
|
|
2118
2417
|
}
|
|
2119
2418
|
|
|
2120
2419
|
// src/persistent/index-engine.ts
|
|
2121
|
-
import { statSync as
|
|
2420
|
+
import { statSync as statSync4 } from "fs";
|
|
2122
2421
|
|
|
2123
2422
|
// src/providers/parse.ts
|
|
2124
|
-
import { createReadStream as
|
|
2125
|
-
import { createInterface as
|
|
2423
|
+
import { createReadStream as createReadStream7 } from "fs";
|
|
2424
|
+
import { createInterface as createInterface5 } from "readline";
|
|
2126
2425
|
async function parseMetaWithProvider(provider, filePath, account, tier, onEntry) {
|
|
2127
2426
|
const log = getLogger();
|
|
2128
2427
|
const acc = provider.createEmptyAccumulator();
|
|
2129
|
-
const rl =
|
|
2130
|
-
input:
|
|
2428
|
+
const rl = createInterface5({
|
|
2429
|
+
input: createReadStream7(filePath),
|
|
2131
2430
|
crlfDelay: Infinity
|
|
2132
2431
|
});
|
|
2133
2432
|
try {
|
|
@@ -2200,8 +2499,17 @@ function extractSearchDelta(entry) {
|
|
|
2200
2499
|
if (looksLikeCursorChatEntry(entry)) {
|
|
2201
2500
|
return extractCursorDelta(entry);
|
|
2202
2501
|
}
|
|
2502
|
+
if (looksLikeCopilotEvent(entry)) {
|
|
2503
|
+
return extractCopilotDelta(entry);
|
|
2504
|
+
}
|
|
2203
2505
|
return extractClaudeDelta(entry);
|
|
2204
2506
|
}
|
|
2507
|
+
function extractCopilotDelta(entry) {
|
|
2508
|
+
const message = parseCopilotJsonlLine(JSON.stringify(entry));
|
|
2509
|
+
if (!message) return emptySearchDocument();
|
|
2510
|
+
const tools = (message.metadata?.toolUseBlocks ?? []).map((block) => capToolPayload(block.input)).filter(Boolean).join(SEP);
|
|
2511
|
+
return { text: message.text, thinking: "", tools };
|
|
2512
|
+
}
|
|
2205
2513
|
function extractCursorDelta(entry) {
|
|
2206
2514
|
const msg = entry.message;
|
|
2207
2515
|
const content = msg?.content ?? entry.content;
|
|
@@ -2229,7 +2537,7 @@ function extractCursorSearchText(content) {
|
|
|
2229
2537
|
function extractClaudeDelta(entry) {
|
|
2230
2538
|
const type = entry.type;
|
|
2231
2539
|
if (type !== "user" && type !== "assistant") return emptySearchDocument();
|
|
2232
|
-
if (entry.isMeta) return emptySearchDocument();
|
|
2540
|
+
if (entry.isMeta || entry.isCompactSummary === true) return emptySearchDocument();
|
|
2233
2541
|
const msg = entry.message;
|
|
2234
2542
|
const content = msg?.content;
|
|
2235
2543
|
const tools = [
|
|
@@ -2343,7 +2651,7 @@ function resolveTier(tierName, customTiers) {
|
|
|
2343
2651
|
// src/persistent/db.ts
|
|
2344
2652
|
import Database from "better-sqlite3";
|
|
2345
2653
|
import { mkdirSync } from "fs";
|
|
2346
|
-
import { dirname as
|
|
2654
|
+
import { dirname as dirname5 } from "path";
|
|
2347
2655
|
|
|
2348
2656
|
// src/persistent/schema.ts
|
|
2349
2657
|
var SCHEMA_VERSION = 10;
|
|
@@ -2668,7 +2976,7 @@ function hasColumn(db, table, column) {
|
|
|
2668
2976
|
// src/persistent/db.ts
|
|
2669
2977
|
function openDatabase(dbPath) {
|
|
2670
2978
|
if (dbPath !== ":memory:") {
|
|
2671
|
-
mkdirSync(
|
|
2979
|
+
mkdirSync(dirname5(dbPath), { recursive: true });
|
|
2672
2980
|
}
|
|
2673
2981
|
let db;
|
|
2674
2982
|
try {
|
|
@@ -2712,8 +3020,8 @@ function nativeBindingError(err, dbPath) {
|
|
|
2712
3020
|
}
|
|
2713
3021
|
|
|
2714
3022
|
// src/persistent/dir-watermark.ts
|
|
2715
|
-
import { readdir, stat as
|
|
2716
|
-
import { dirname as
|
|
3023
|
+
import { readdir, stat as stat5 } from "fs/promises";
|
|
3024
|
+
import { dirname as dirname6, join as join5 } from "path";
|
|
2717
3025
|
var FULL_RECONCILE_EVERY_N_SCANS = 20;
|
|
2718
3026
|
async function discoverJsonlFilesGated(dirs, files, scannedDirs, options = {}) {
|
|
2719
3027
|
const log = getLogger();
|
|
@@ -2729,7 +3037,7 @@ async function discoverJsonlFilesGated(dirs, files, scannedDirs, options = {}) {
|
|
|
2729
3037
|
for (const projectDir of resolved.entries) {
|
|
2730
3038
|
let dirStat;
|
|
2731
3039
|
try {
|
|
2732
|
-
dirStat = await
|
|
3040
|
+
dirStat = await stat5(projectDir);
|
|
2733
3041
|
} catch {
|
|
2734
3042
|
scannedDirs.remove(projectDir);
|
|
2735
3043
|
continue;
|
|
@@ -2767,7 +3075,7 @@ async function discoverJsonlFilesGated(dirs, files, scannedDirs, options = {}) {
|
|
|
2767
3075
|
async function resolveProjectDirs(projectsDir, scannedDirs) {
|
|
2768
3076
|
let rootStat;
|
|
2769
3077
|
try {
|
|
2770
|
-
rootStat = await
|
|
3078
|
+
rootStat = await stat5(projectsDir);
|
|
2771
3079
|
} catch {
|
|
2772
3080
|
return null;
|
|
2773
3081
|
}
|
|
@@ -2784,7 +3092,7 @@ async function resolveProjectDirs(projectsDir, scannedDirs) {
|
|
|
2784
3092
|
return { entries, commitRoot: { mtimeMs: rootStat.mtimeMs } };
|
|
2785
3093
|
}
|
|
2786
3094
|
function dirnameOf(filePath) {
|
|
2787
|
-
return
|
|
3095
|
+
return dirname6(filePath);
|
|
2788
3096
|
}
|
|
2789
3097
|
function joinPath(dir, name) {
|
|
2790
3098
|
return join5(dir, name);
|
|
@@ -2867,7 +3175,7 @@ function toCheckpoint(row) {
|
|
|
2867
3175
|
}
|
|
2868
3176
|
|
|
2869
3177
|
// src/persistent/repositories/conversation-files.repo.ts
|
|
2870
|
-
import { basename as
|
|
3178
|
+
import { basename as basename7, dirname as dirname7 } from "path";
|
|
2871
3179
|
var ConversationFilesRepo = class {
|
|
2872
3180
|
constructor(db) {
|
|
2873
3181
|
this.db = db;
|
|
@@ -2890,7 +3198,7 @@ var ConversationFilesRepo = class {
|
|
|
2890
3198
|
const info = this.db.prepare(
|
|
2891
3199
|
`INSERT INTO conversation_files (absolute_path, parent_dir, file_name, account)
|
|
2892
3200
|
VALUES (?, ?, ?, ?)`
|
|
2893
|
-
).run(canonical,
|
|
3201
|
+
).run(canonical, dirname7(canonical), basename7(canonical), account);
|
|
2894
3202
|
return Number(info.lastInsertRowid);
|
|
2895
3203
|
}
|
|
2896
3204
|
// Advance the cursor + persisted reducer state after a successful index pass.
|
|
@@ -3407,6 +3715,12 @@ var PersistentEngine = class {
|
|
|
3407
3715
|
discovered.push({ ...f, provider: cursor });
|
|
3408
3716
|
}
|
|
3409
3717
|
}
|
|
3718
|
+
const copilot = new CopilotProvider();
|
|
3719
|
+
if (enabled.includes(COPILOT_PROVIDER) && (options.copilotRoots?.length ?? 0) > 0) {
|
|
3720
|
+
for (const f of await copilot.discover(options.copilotRoots)) {
|
|
3721
|
+
discovered.push({ ...f, provider: copilot });
|
|
3722
|
+
}
|
|
3723
|
+
}
|
|
3410
3724
|
let scanned = 0;
|
|
3411
3725
|
const gitBranchMemo = /* @__PURE__ */ new Map();
|
|
3412
3726
|
const resolveGitBranch = (projectPath) => {
|
|
@@ -3448,6 +3762,9 @@ var PersistentEngine = class {
|
|
|
3448
3762
|
if (enabled.includes(CURSOR_PROVIDER) && (options.cursorRoots?.length ?? 0) > 0) {
|
|
3449
3763
|
coveredAccounts.add("cursor");
|
|
3450
3764
|
}
|
|
3765
|
+
if (enabled.includes(COPILOT_PROVIDER) && (options.copilotRoots?.length ?? 0) > 0) {
|
|
3766
|
+
coveredAccounts.add("copilot");
|
|
3767
|
+
}
|
|
3451
3768
|
const seen = new Set(discovered.map((d) => canonicalPath(d.filePath)));
|
|
3452
3769
|
for (const path of this.files.activePathsByAccounts([...coveredAccounts])) {
|
|
3453
3770
|
if (!seen.has(path)) this.markDeleted(path);
|
|
@@ -3467,8 +3784,8 @@ var PersistentEngine = class {
|
|
|
3467
3784
|
const tier = resolveTier(tierName, customTiers);
|
|
3468
3785
|
const filePath = canonicalPath(rawFilePath);
|
|
3469
3786
|
const existing = this.files.getByPath(filePath);
|
|
3470
|
-
const { change, stat:
|
|
3471
|
-
if (change === "vanished" || !
|
|
3787
|
+
const { change, stat: stat6 } = classify(filePath, existing);
|
|
3788
|
+
if (change === "vanished" || !stat6) {
|
|
3472
3789
|
this.markDeleted(filePath);
|
|
3473
3790
|
return { meta: null, change: "vanished" };
|
|
3474
3791
|
}
|
|
@@ -3481,7 +3798,7 @@ var PersistentEngine = class {
|
|
|
3481
3798
|
filePath,
|
|
3482
3799
|
account,
|
|
3483
3800
|
tier,
|
|
3484
|
-
|
|
3801
|
+
stat6,
|
|
3485
3802
|
resolveGitBranch
|
|
3486
3803
|
);
|
|
3487
3804
|
return { meta: meta2, change };
|
|
@@ -3507,7 +3824,7 @@ var PersistentEngine = class {
|
|
|
3507
3824
|
return { meta: null, change };
|
|
3508
3825
|
}
|
|
3509
3826
|
meta.gitBranch = resolveGitBranch(meta.projectPath);
|
|
3510
|
-
const fp =
|
|
3827
|
+
const fp = stat6.size > 0 ? fingerprint(filePath, stat6.size) : null;
|
|
3511
3828
|
const fileId = this.files.ensure(filePath, account);
|
|
3512
3829
|
const base = resume ? this.fts.readDocument(fileId) ?? emptySearchDocument() : emptySearchDocument();
|
|
3513
3830
|
const searchDoc = appendSearchDelta(base, searchDelta);
|
|
@@ -3518,8 +3835,8 @@ var PersistentEngine = class {
|
|
|
3518
3835
|
}
|
|
3519
3836
|
if (!resume) this.checkpoints.remove(filePath);
|
|
3520
3837
|
this.files.updateCursor(fileId, {
|
|
3521
|
-
sizeBytes:
|
|
3522
|
-
mtimeMs:
|
|
3838
|
+
sizeBytes: stat6.size,
|
|
3839
|
+
mtimeMs: stat6.mtimeMs,
|
|
3523
3840
|
// Advance only to the last fully-parsed line; a trailing partial line
|
|
3524
3841
|
// is left for the next pass.
|
|
3525
3842
|
offset: result.newOffset,
|
|
@@ -3536,8 +3853,8 @@ var PersistentEngine = class {
|
|
|
3536
3853
|
buildSidecar(
|
|
3537
3854
|
meta,
|
|
3538
3855
|
{
|
|
3539
|
-
sizeBytes:
|
|
3540
|
-
mtimeMs:
|
|
3856
|
+
sizeBytes: stat6.size,
|
|
3857
|
+
mtimeMs: stat6.mtimeMs,
|
|
3541
3858
|
offset: result.newOffset,
|
|
3542
3859
|
line: result.newLine
|
|
3543
3860
|
},
|
|
@@ -3556,7 +3873,7 @@ var PersistentEngine = class {
|
|
|
3556
3873
|
// the Threadbase path uses. The cursor records size/mtime (and offset = size)
|
|
3557
3874
|
// so the next pass classifies an unchanged file as "unchanged" and skips it;
|
|
3558
3875
|
// any change reparses from 0 again. No reducer_state is persisted.
|
|
3559
|
-
async indexFileWithProvider(provider, filePath, account, tier,
|
|
3876
|
+
async indexFileWithProvider(provider, filePath, account, tier, stat6, resolveGitBranch) {
|
|
3560
3877
|
const log = getLogger();
|
|
3561
3878
|
let searchDoc = emptySearchDocument();
|
|
3562
3879
|
const meta = await parseMetaWithProvider(provider, filePath, account, tier, (entry) => {
|
|
@@ -3569,7 +3886,7 @@ var PersistentEngine = class {
|
|
|
3569
3886
|
if (meta.gitBranch === null && meta.projectPath) {
|
|
3570
3887
|
meta.gitBranch = resolveGitBranch(meta.projectPath);
|
|
3571
3888
|
}
|
|
3572
|
-
const fp =
|
|
3889
|
+
const fp = stat6.size > 0 ? fingerprint(filePath, stat6.size) : null;
|
|
3573
3890
|
const fileId = this.files.ensure(filePath, account);
|
|
3574
3891
|
const upsert = this.db.transaction(() => {
|
|
3575
3892
|
this.conversations.upsert(fileId, meta, meta.messageCount);
|
|
@@ -3578,11 +3895,11 @@ var PersistentEngine = class {
|
|
|
3578
3895
|
}
|
|
3579
3896
|
this.checkpoints.remove(filePath);
|
|
3580
3897
|
this.files.updateCursor(fileId, {
|
|
3581
|
-
sizeBytes:
|
|
3582
|
-
mtimeMs:
|
|
3898
|
+
sizeBytes: stat6.size,
|
|
3899
|
+
mtimeMs: stat6.mtimeMs,
|
|
3583
3900
|
// offset = size marks the file fully consumed (non-zero so the next pass
|
|
3584
3901
|
// can classify it "unchanged"); no resumable reducer state is kept.
|
|
3585
|
-
offset:
|
|
3902
|
+
offset: stat6.size,
|
|
3586
3903
|
line: 0,
|
|
3587
3904
|
reducerState: null,
|
|
3588
3905
|
fingerprint: fp,
|
|
@@ -3648,8 +3965,8 @@ var PersistentEngine = class {
|
|
|
3648
3965
|
const meta = this.conversations.getByIdOrSession(id);
|
|
3649
3966
|
if (!meta) return null;
|
|
3650
3967
|
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);
|
|
3968
|
+
if (meta.provider === CODEX_CLI_PROVIDER || meta.provider === CURSOR_PROVIDER || meta.provider === COPILOT_PROVIDER) {
|
|
3969
|
+
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
3970
|
if (!conversation) return null;
|
|
3654
3971
|
const { messages } = conversation;
|
|
3655
3972
|
const total2 = messages.length;
|
|
@@ -3664,7 +3981,7 @@ var PersistentEngine = class {
|
|
|
3664
3981
|
let floor = this.checkpoints.floor(filePath, fromIndex);
|
|
3665
3982
|
if (floor) {
|
|
3666
3983
|
try {
|
|
3667
|
-
if (floor.byteOffset >
|
|
3984
|
+
if (floor.byteOffset > statSync4(filePath).size) floor = null;
|
|
3668
3985
|
} catch {
|
|
3669
3986
|
}
|
|
3670
3987
|
}
|
|
@@ -3982,7 +4299,7 @@ var ConversationScanner = class {
|
|
|
3982
4299
|
const cached = statCache.get(filePath);
|
|
3983
4300
|
if (cached) {
|
|
3984
4301
|
try {
|
|
3985
|
-
const s =
|
|
4302
|
+
const s = statSync5(filePath);
|
|
3986
4303
|
if (s.mtimeMs === cached.stat.mtimeMs && s.size === cached.stat.size) {
|
|
3987
4304
|
return {
|
|
3988
4305
|
meta: cached.meta,
|
|
@@ -4140,12 +4457,12 @@ var ConversationScanner = class {
|
|
|
4140
4457
|
}
|
|
4141
4458
|
log.debug({ id, filePath: meta.filePath }, "getConversation: cache miss, parsing");
|
|
4142
4459
|
try {
|
|
4143
|
-
if (this.persistent && meta.provider !== CODEX_CLI_PROVIDER && meta.provider !== CURSOR_PROVIDER) {
|
|
4460
|
+
if (this.persistent && meta.provider !== CODEX_CLI_PROVIDER && meta.provider !== CURSOR_PROVIDER && meta.provider !== COPILOT_PROVIDER) {
|
|
4144
4461
|
const parsed = await parseConversationResumable(meta.filePath, meta.account);
|
|
4145
4462
|
if (parsed) this.conversationLRU.set(cid, parsed);
|
|
4146
4463
|
return parsed?.conversation ?? null;
|
|
4147
4464
|
}
|
|
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);
|
|
4465
|
+
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
4466
|
if (conversation) {
|
|
4150
4467
|
this.conversationLRU.set(cid, { conversation });
|
|
4151
4468
|
}
|
|
@@ -4199,7 +4516,7 @@ var ConversationScanner = class {
|
|
|
4199
4516
|
// fallback, matching refreshFile.
|
|
4200
4517
|
async parseSingleFilePage(filePath, account, options) {
|
|
4201
4518
|
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");
|
|
4519
|
+
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
4520
|
if (!conversation) return null;
|
|
4204
4521
|
const { messages } = conversation;
|
|
4205
4522
|
const total = messages.length;
|
|
@@ -4509,6 +4826,12 @@ var ConversationScanner = class {
|
|
|
4509
4826
|
work.push({ ...f, provider });
|
|
4510
4827
|
}
|
|
4511
4828
|
}
|
|
4829
|
+
if (enabled.includes(COPILOT_PROVIDER) && (options.copilotRoots?.length ?? 0) > 0) {
|
|
4830
|
+
const provider = new CopilotProvider();
|
|
4831
|
+
for (const f of await provider.discover(options.copilotRoots)) {
|
|
4832
|
+
work.push({ ...f, provider });
|
|
4833
|
+
}
|
|
4834
|
+
}
|
|
4512
4835
|
return work;
|
|
4513
4836
|
}
|
|
4514
4837
|
// Resolve which provider should (re)parse a file. Stored metadata wins; for a
|
|
@@ -4520,6 +4843,7 @@ var ConversationScanner = class {
|
|
|
4520
4843
|
if (providerMatches(previous?.provider, CURSOR_PROVIDER)) {
|
|
4521
4844
|
return new CursorProvider();
|
|
4522
4845
|
}
|
|
4846
|
+
if (previous?.provider === COPILOT_PROVIDER) return new CopilotProvider();
|
|
4523
4847
|
if (previous?.provider) return void 0;
|
|
4524
4848
|
let sample = "";
|
|
4525
4849
|
try {
|
|
@@ -4538,6 +4862,8 @@ var ConversationScanner = class {
|
|
|
4538
4862
|
if (cursor.canParse(filePath, sample)) return cursor;
|
|
4539
4863
|
const codex = new CodexCliProvider();
|
|
4540
4864
|
if (codex.canParse(filePath, sample)) return codex;
|
|
4865
|
+
const copilot = new CopilotProvider();
|
|
4866
|
+
if (copilot.canParse(filePath, sample)) return copilot;
|
|
4541
4867
|
return void 0;
|
|
4542
4868
|
}
|
|
4543
4869
|
addToSessionIndex(meta) {
|
|
@@ -4646,9 +4972,11 @@ async function getConversation(id, options, scanner) {
|
|
|
4646
4972
|
export {
|
|
4647
4973
|
CLAUDE_CODE_PROVIDER,
|
|
4648
4974
|
CODEX_CLI_PROVIDER,
|
|
4975
|
+
COPILOT_PROVIDER,
|
|
4649
4976
|
CURSOR_PROVIDER,
|
|
4650
4977
|
CodexCliProvider,
|
|
4651
4978
|
ConversationScanner,
|
|
4979
|
+
CopilotProvider,
|
|
4652
4980
|
CursorProvider,
|
|
4653
4981
|
DEFAULT_TIERS,
|
|
4654
4982
|
LEGACY_CURSOR_PROVIDER,
|
|
@@ -4673,6 +5001,7 @@ export {
|
|
|
4673
5001
|
isCodexInjectedContext,
|
|
4674
5002
|
loadProfiles,
|
|
4675
5003
|
parseCodexJsonlLine,
|
|
5004
|
+
parseCopilotJsonlLine,
|
|
4676
5005
|
parseCursorJsonlLine,
|
|
4677
5006
|
parseJsonlLine,
|
|
4678
5007
|
providerMatches,
|