@threadbase-sh/scanner 0.17.6 → 0.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +34 -22
- package/dist/cache.d.ts +12 -0
- package/dist/cache.d.ts.map +1 -0
- package/dist/canonical-path.d.ts +2 -0
- package/dist/canonical-path.d.ts.map +1 -0
- package/dist/cli.js +598 -64
- package/dist/cli.js.map +1 -1
- package/dist/discovery.d.ts +9 -0
- package/dist/discovery.d.ts.map +1 -0
- package/dist/filters.d.ts +12 -0
- package/dist/filters.d.ts.map +1 -0
- package/dist/git.d.ts +2 -0
- package/dist/git.d.ts.map +1 -0
- package/dist/index.cjs +633 -89
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +27 -461
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +609 -75
- package/dist/index.js.map +1 -1
- package/dist/indexer.d.ts +21 -0
- package/dist/indexer.d.ts.map +1 -0
- package/dist/logger.d.ts +6 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/parser.d.ts +18 -0
- package/dist/parser.d.ts.map +1 -0
- package/dist/persistent/conversation-reducer.d.ts +15 -0
- package/dist/persistent/conversation-reducer.d.ts.map +1 -0
- package/dist/persistent/conversation-stream.d.ts +14 -0
- package/dist/persistent/conversation-stream.d.ts.map +1 -0
- package/dist/persistent/cursor.d.ts +12 -0
- package/dist/persistent/cursor.d.ts.map +1 -0
- package/dist/persistent/db.d.ts +4 -0
- package/dist/persistent/db.d.ts.map +1 -0
- package/dist/persistent/dir-watermark.d.ts +11 -0
- package/dist/persistent/dir-watermark.d.ts.map +1 -0
- package/dist/persistent/index-engine.d.ts +49 -0
- package/dist/persistent/index-engine.d.ts.map +1 -0
- package/dist/persistent/jsonl-tail-reader.d.ts +11 -0
- package/dist/persistent/jsonl-tail-reader.d.ts.map +1 -0
- package/dist/persistent/metadata-reducer.d.ts +32 -0
- package/dist/persistent/metadata-reducer.d.ts.map +1 -0
- package/dist/persistent/migrations.d.ts +3 -0
- package/dist/persistent/migrations.d.ts.map +1 -0
- package/dist/persistent/paged-reader.d.ts +14 -0
- package/dist/persistent/paged-reader.d.ts.map +1 -0
- package/dist/persistent/repositories/checkpoints.repo.d.ts +19 -0
- package/dist/persistent/repositories/checkpoints.repo.d.ts.map +1 -0
- package/dist/persistent/repositories/conversation-files.repo.d.ts +40 -0
- package/dist/persistent/repositories/conversation-files.repo.d.ts.map +1 -0
- package/dist/persistent/repositories/conversations.repo.d.ts +55 -0
- package/dist/persistent/repositories/conversations.repo.d.ts.map +1 -0
- package/dist/persistent/repositories/fts.repo.d.ts +28 -0
- package/dist/persistent/repositories/fts.repo.d.ts.map +1 -0
- package/dist/persistent/repositories/scanned-dirs.repo.d.ts +16 -0
- package/dist/persistent/repositories/scanned-dirs.repo.d.ts.map +1 -0
- package/dist/persistent/schema.d.ts +3 -0
- package/dist/persistent/schema.d.ts.map +1 -0
- package/dist/persistent/sidecar.d.ts +29 -0
- package/dist/persistent/sidecar.d.ts.map +1 -0
- package/dist/profiles.d.ts +7 -0
- package/dist/profiles.d.ts.map +1 -0
- package/dist/providers/codex-cli.d.ts +40 -0
- package/dist/providers/codex-cli.d.ts.map +1 -0
- package/dist/providers/cursor.d.ts +38 -0
- package/dist/providers/cursor.d.ts.map +1 -0
- package/dist/providers/parse.d.ts +4 -0
- package/dist/providers/parse.d.ts.map +1 -0
- package/dist/providers/provider.d.ts +23 -0
- package/dist/providers/provider.d.ts.map +1 -0
- package/dist/providers/threadbase.d.ts +12 -0
- package/dist/providers/threadbase.d.ts.map +1 -0
- package/dist/scanner.d.ts +77 -0
- package/dist/scanner.d.ts.map +1 -0
- package/dist/search-document.d.ts +20 -0
- package/dist/search-document.d.ts.map +1 -0
- package/dist/search-matches.d.ts +13 -0
- package/dist/search-matches.d.ts.map +1 -0
- package/dist/tags.d.ts +2 -0
- package/dist/tags.d.ts.map +1 -0
- package/dist/tiers.d.ts +4 -0
- package/dist/tiers.d.ts.map +1 -0
- package/dist/types.d.ts +212 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/watcher/file-watcher.d.ts +21 -0
- package/dist/watcher/file-watcher.d.ts.map +1 -0
- package/dist/watcher/index-queue.d.ts +18 -0
- package/dist/watcher/index-queue.d.ts.map +1 -0
- package/package.json +3 -3
- package/dist/index.d.cts +0 -461
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.
|
|
8
|
+
var version = "0.18.0";
|
|
9
9
|
|
|
10
10
|
// src/logger.ts
|
|
11
11
|
import pino from "pino";
|
|
@@ -60,9 +60,9 @@ async function saveProfiles(profiles, configPath) {
|
|
|
60
60
|
|
|
61
61
|
// src/scanner.ts
|
|
62
62
|
import { EventEmitter } from "events";
|
|
63
|
-
import { closeSync as closeSync2, openSync as openSync2, readSync as readSync2, statSync as
|
|
63
|
+
import { closeSync as closeSync2, openSync as openSync2, readSync as readSync2, statSync as statSync4 } from "fs";
|
|
64
64
|
import { homedir as homedir2 } from "os";
|
|
65
|
-
import { join as
|
|
65
|
+
import { join as join6 } from "path";
|
|
66
66
|
|
|
67
67
|
// src/cache.ts
|
|
68
68
|
var LRUCache = class {
|
|
@@ -614,6 +614,29 @@ import { basename, dirname as dirname2, join as join3 } from "path";
|
|
|
614
614
|
// src/providers/provider.ts
|
|
615
615
|
var CLAUDE_CODE_PROVIDER = "claude-code";
|
|
616
616
|
var CODEX_CLI_PROVIDER = "codex-cli";
|
|
617
|
+
var CURSOR_PROVIDER = "cursor";
|
|
618
|
+
var LEGACY_CURSOR_PROVIDER = "cursor-cli";
|
|
619
|
+
function canonicalizeProviderName(value) {
|
|
620
|
+
if (value === LEGACY_CURSOR_PROVIDER) return CURSOR_PROVIDER;
|
|
621
|
+
if (value === CLAUDE_CODE_PROVIDER || value === CODEX_CLI_PROVIDER || value === CURSOR_PROVIDER) {
|
|
622
|
+
return value;
|
|
623
|
+
}
|
|
624
|
+
return void 0;
|
|
625
|
+
}
|
|
626
|
+
function canonicalizeProviderList(providers) {
|
|
627
|
+
const src = providers ?? [CLAUDE_CODE_PROVIDER];
|
|
628
|
+
const out = [];
|
|
629
|
+
for (const p of src) {
|
|
630
|
+
const n = canonicalizeProviderName(p);
|
|
631
|
+
if (n && !out.includes(n)) out.push(n);
|
|
632
|
+
}
|
|
633
|
+
return out;
|
|
634
|
+
}
|
|
635
|
+
function providerMatches(stored, wanted) {
|
|
636
|
+
const a = canonicalizeProviderName(stored ?? CLAUDE_CODE_PROVIDER) ?? stored;
|
|
637
|
+
const b = canonicalizeProviderName(wanted) ?? wanted;
|
|
638
|
+
return a === b;
|
|
639
|
+
}
|
|
617
640
|
|
|
618
641
|
// src/persistent/metadata-reducer.ts
|
|
619
642
|
function initialReducerState() {
|
|
@@ -1199,37 +1222,37 @@ function fingerprint(filePath, size) {
|
|
|
1199
1222
|
return hash.digest("hex");
|
|
1200
1223
|
}
|
|
1201
1224
|
function classify(filePath, existing) {
|
|
1202
|
-
let
|
|
1225
|
+
let stat5;
|
|
1203
1226
|
try {
|
|
1204
1227
|
const s = statSync(filePath);
|
|
1205
|
-
|
|
1228
|
+
stat5 = { size: s.size, mtimeMs: s.mtimeMs };
|
|
1206
1229
|
} catch {
|
|
1207
1230
|
return { change: "vanished" };
|
|
1208
1231
|
}
|
|
1209
1232
|
if (!existing || existing.status !== "active" || existing.last_indexed_offset === 0) {
|
|
1210
|
-
return { change: "reindex", stat:
|
|
1233
|
+
return { change: "reindex", stat: stat5 };
|
|
1211
1234
|
}
|
|
1212
|
-
if (
|
|
1213
|
-
return { change: "reindex", stat:
|
|
1235
|
+
if (stat5.size < existing.last_indexed_offset) {
|
|
1236
|
+
return { change: "reindex", stat: stat5 };
|
|
1214
1237
|
}
|
|
1215
|
-
if (
|
|
1216
|
-
return { change: "unchanged", stat:
|
|
1238
|
+
if (stat5.size === existing.size_bytes && stat5.mtimeMs === existing.mtime_ms) {
|
|
1239
|
+
return { change: "unchanged", stat: stat5 };
|
|
1217
1240
|
}
|
|
1218
|
-
if (
|
|
1219
|
-
const fp = fingerprint(filePath,
|
|
1241
|
+
if (stat5.size === existing.last_indexed_offset) {
|
|
1242
|
+
const fp = fingerprint(filePath, stat5.size);
|
|
1220
1243
|
if (existing.content_fingerprint && fp !== existing.content_fingerprint) {
|
|
1221
|
-
return { change: "reindex", stat:
|
|
1244
|
+
return { change: "reindex", stat: stat5 };
|
|
1222
1245
|
}
|
|
1223
|
-
return { change: "unchanged", stat:
|
|
1246
|
+
return { change: "unchanged", stat: stat5 };
|
|
1224
1247
|
}
|
|
1225
1248
|
if (existing.content_fingerprint && existing.size_bytes === existing.last_indexed_offset && fingerprint(filePath, existing.last_indexed_offset) === existing.content_fingerprint) {
|
|
1226
|
-
return { change: "appended", stat:
|
|
1249
|
+
return { change: "appended", stat: stat5 };
|
|
1227
1250
|
}
|
|
1228
|
-
return { change: "reindex", stat:
|
|
1251
|
+
return { change: "reindex", stat: stat5 };
|
|
1229
1252
|
}
|
|
1230
1253
|
|
|
1231
1254
|
// src/persistent/index-engine.ts
|
|
1232
|
-
import { statSync as
|
|
1255
|
+
import { statSync as statSync3 } from "fs";
|
|
1233
1256
|
|
|
1234
1257
|
// src/providers/codex-cli.ts
|
|
1235
1258
|
import fg2 from "fast-glob";
|
|
@@ -1322,6 +1345,16 @@ function extractCodexText(content) {
|
|
|
1322
1345
|
return "";
|
|
1323
1346
|
}).filter(Boolean).map(cleanSystemTags).join(" ");
|
|
1324
1347
|
}
|
|
1348
|
+
function parseCodexJsonlLine(line) {
|
|
1349
|
+
if (!line.trim()) return null;
|
|
1350
|
+
let entry;
|
|
1351
|
+
try {
|
|
1352
|
+
entry = JSON.parse(line);
|
|
1353
|
+
} catch {
|
|
1354
|
+
return null;
|
|
1355
|
+
}
|
|
1356
|
+
return codexEntryToMessage(entry);
|
|
1357
|
+
}
|
|
1325
1358
|
function codexEntryToMessage(entry) {
|
|
1326
1359
|
const payload = entry.payload;
|
|
1327
1360
|
if (!payload || typeof payload !== "object") return null;
|
|
@@ -1494,14 +1527,410 @@ async function parseCodexConversation(filePath, account) {
|
|
|
1494
1527
|
};
|
|
1495
1528
|
}
|
|
1496
1529
|
|
|
1497
|
-
// src/providers/
|
|
1498
|
-
import
|
|
1530
|
+
// src/providers/cursor.ts
|
|
1531
|
+
import fg3 from "fast-glob";
|
|
1532
|
+
import { createReadStream as createReadStream5, existsSync, statSync as statSync2 } from "fs";
|
|
1533
|
+
import { stat as stat3 } from "fs/promises";
|
|
1534
|
+
import { basename as basename5, dirname as dirname3, join as join4, sep as sep2 } from "path";
|
|
1499
1535
|
import { createInterface as createInterface3 } from "readline";
|
|
1536
|
+
var TIMESTAMP_RE = /<timestamp>\s*([\s\S]*?)\s*<\/timestamp>/;
|
|
1537
|
+
var USER_QUERY_RE = /<user_query>\s*([\s\S]*?)\s*<\/user_query>/;
|
|
1538
|
+
var SUBAGENT_PATH_RE2 = /[\\/]subagents[\\/]/;
|
|
1539
|
+
var CursorProvider = class {
|
|
1540
|
+
name = CURSOR_PROVIDER;
|
|
1541
|
+
async discover(roots) {
|
|
1542
|
+
const log = getLogger();
|
|
1543
|
+
const results = [];
|
|
1544
|
+
for (const root of roots) {
|
|
1545
|
+
let paths;
|
|
1546
|
+
try {
|
|
1547
|
+
paths = await fg3(["**/agent-transcripts/**/*.jsonl"], {
|
|
1548
|
+
cwd: root,
|
|
1549
|
+
absolute: true,
|
|
1550
|
+
dot: false,
|
|
1551
|
+
unique: true
|
|
1552
|
+
});
|
|
1553
|
+
} catch (err) {
|
|
1554
|
+
log.warn({ root, err }, "cursor discovery: glob failed");
|
|
1555
|
+
continue;
|
|
1556
|
+
}
|
|
1557
|
+
for (const filePath of paths) {
|
|
1558
|
+
try {
|
|
1559
|
+
const s = await stat3(filePath);
|
|
1560
|
+
if (s.size > 0) results.push({ filePath: canonicalPath(filePath), account: "cursor" });
|
|
1561
|
+
} catch (err) {
|
|
1562
|
+
log.warn({ filePath, err }, "cursor discovery: stat failed");
|
|
1563
|
+
}
|
|
1564
|
+
}
|
|
1565
|
+
}
|
|
1566
|
+
return results;
|
|
1567
|
+
}
|
|
1568
|
+
canParse(filePath, sample) {
|
|
1569
|
+
const underTranscripts = /[\\/]agent-transcripts[\\/]/.test(filePath);
|
|
1570
|
+
for (const line of sample.split("\n")) {
|
|
1571
|
+
if (!line.trim()) continue;
|
|
1572
|
+
try {
|
|
1573
|
+
const e = JSON.parse(line);
|
|
1574
|
+
if (looksLikeImportedCodexEntry(e) || looksLikeImportedClaudeEntry(e)) {
|
|
1575
|
+
return underTranscripts;
|
|
1576
|
+
}
|
|
1577
|
+
if (looksLikeCursorChatEntry(e)) return true;
|
|
1578
|
+
} catch {
|
|
1579
|
+
}
|
|
1580
|
+
}
|
|
1581
|
+
return false;
|
|
1582
|
+
}
|
|
1583
|
+
createEmptyAccumulator() {
|
|
1584
|
+
return {
|
|
1585
|
+
sessionId: "",
|
|
1586
|
+
latestTimestamp: "",
|
|
1587
|
+
messageCount: 0,
|
|
1588
|
+
lastMessageSender: "user",
|
|
1589
|
+
isSubagent: false,
|
|
1590
|
+
parentSessionUuid: null,
|
|
1591
|
+
subagentId: null,
|
|
1592
|
+
firstUser: null,
|
|
1593
|
+
lastUser: null,
|
|
1594
|
+
lastAssistant: null,
|
|
1595
|
+
isImportedFromClaude: false,
|
|
1596
|
+
isImportedFromCodex: false,
|
|
1597
|
+
toolNames: [],
|
|
1598
|
+
previewParts: [],
|
|
1599
|
+
previewLength: 0,
|
|
1600
|
+
snippetParts: [],
|
|
1601
|
+
snippetLength: 0
|
|
1602
|
+
};
|
|
1603
|
+
}
|
|
1604
|
+
reduceEntry(acc, entry, tier) {
|
|
1605
|
+
reduceCursorEntry(acc, entry, tier);
|
|
1606
|
+
}
|
|
1607
|
+
finalize(acc, filePath, account, tier) {
|
|
1608
|
+
return finalizeCursorMeta(acc, filePath, account, tier);
|
|
1609
|
+
}
|
|
1610
|
+
};
|
|
1611
|
+
function looksLikeCursorChatEntry(entry) {
|
|
1612
|
+
const role = entry.role;
|
|
1613
|
+
if (role !== "user" && role !== "assistant") return false;
|
|
1614
|
+
if (entry.type === "user" || entry.type === "assistant") return false;
|
|
1615
|
+
return true;
|
|
1616
|
+
}
|
|
1617
|
+
function looksLikeImportedClaudeEntry(entry) {
|
|
1618
|
+
return entry.type === "user" || entry.type === "assistant";
|
|
1619
|
+
}
|
|
1620
|
+
function looksLikeImportedCodexEntry(entry) {
|
|
1621
|
+
return entry.type === "session_meta" || entry.type === "response_item" || entry.type === "event_msg";
|
|
1622
|
+
}
|
|
1623
|
+
function asString2(value) {
|
|
1624
|
+
return typeof value === "string" ? value : "";
|
|
1625
|
+
}
|
|
1626
|
+
function provenanceToken(value) {
|
|
1627
|
+
if (typeof value === "string") return value.trim().toLowerCase();
|
|
1628
|
+
if (value && typeof value === "object") {
|
|
1629
|
+
const rec = value;
|
|
1630
|
+
return provenanceToken(
|
|
1631
|
+
rec.importedFrom ?? rec.imported_from ?? rec.sourceProvider ?? rec.source
|
|
1632
|
+
);
|
|
1633
|
+
}
|
|
1634
|
+
return "";
|
|
1635
|
+
}
|
|
1636
|
+
function importedFromClaudeToken(token) {
|
|
1637
|
+
return token === "claude" || token === "claude-code" || token === "claude_code" || token === "anthropic";
|
|
1638
|
+
}
|
|
1639
|
+
function importedFromCodexToken(token) {
|
|
1640
|
+
return token === "codex" || token === "codex-cli" || token === "codex_cli" || token === "openai-codex";
|
|
1641
|
+
}
|
|
1642
|
+
function noteImportProvenance(acc, entry, text) {
|
|
1643
|
+
const token = provenanceToken(
|
|
1644
|
+
entry.importedFrom ?? entry.imported_from ?? entry.sourceProvider ?? entry.source ?? (entry.message && typeof entry.message === "object" ? entry.message.importedFrom ?? entry.message.imported_from ?? entry.message.sourceProvider : void 0)
|
|
1645
|
+
);
|
|
1646
|
+
if (importedFromClaudeToken(token) || looksLikeImportedClaudeEntry(entry)) {
|
|
1647
|
+
acc.isImportedFromClaude = true;
|
|
1648
|
+
}
|
|
1649
|
+
if (importedFromCodexToken(token) || looksLikeImportedCodexEntry(entry)) {
|
|
1650
|
+
acc.isImportedFromCodex = true;
|
|
1651
|
+
}
|
|
1652
|
+
if (/imported from claude/i.test(text) || /<imported_from_claude>/i.test(text)) {
|
|
1653
|
+
acc.isImportedFromClaude = true;
|
|
1654
|
+
}
|
|
1655
|
+
if (/imported from codex/i.test(text) || /<imported_from_codex>/i.test(text)) {
|
|
1656
|
+
acc.isImportedFromCodex = true;
|
|
1657
|
+
}
|
|
1658
|
+
}
|
|
1659
|
+
function unwrapCursorUserText(text) {
|
|
1660
|
+
const query = text.match(USER_QUERY_RE);
|
|
1661
|
+
const body = query ? query[1] : text.replace(TIMESTAMP_RE, "");
|
|
1662
|
+
return cleanSystemTags(body);
|
|
1663
|
+
}
|
|
1664
|
+
function timestampFromCursorUserText(text) {
|
|
1665
|
+
const match = text.match(TIMESTAMP_RE);
|
|
1666
|
+
if (!match) return "";
|
|
1667
|
+
const parsed = Date.parse(match[1].trim());
|
|
1668
|
+
return Number.isNaN(parsed) ? "" : new Date(parsed).toISOString();
|
|
1669
|
+
}
|
|
1670
|
+
function extractCursorText(content) {
|
|
1671
|
+
if (typeof content === "string") return unwrapCursorUserText(content);
|
|
1672
|
+
if (!Array.isArray(content)) return "";
|
|
1673
|
+
return content.map((item) => {
|
|
1674
|
+
if (typeof item === "string") return unwrapCursorUserText(item);
|
|
1675
|
+
const block = item;
|
|
1676
|
+
if ((block?.type === "text" || block?.type === void 0) && typeof block.text === "string") {
|
|
1677
|
+
return unwrapCursorUserText(block.text);
|
|
1678
|
+
}
|
|
1679
|
+
return "";
|
|
1680
|
+
}).filter(Boolean).join(" ");
|
|
1681
|
+
}
|
|
1682
|
+
function collectCursorToolNames(content, into) {
|
|
1683
|
+
if (!Array.isArray(content)) return;
|
|
1684
|
+
for (const item of content) {
|
|
1685
|
+
const block = item;
|
|
1686
|
+
if (block?.type === "tool_use" && typeof block.name === "string" && block.name) {
|
|
1687
|
+
if (!into.includes(block.name)) into.push(block.name);
|
|
1688
|
+
}
|
|
1689
|
+
}
|
|
1690
|
+
}
|
|
1691
|
+
function firstTimestampHint(content) {
|
|
1692
|
+
if (typeof content === "string") return timestampFromCursorUserText(content);
|
|
1693
|
+
if (!Array.isArray(content)) return "";
|
|
1694
|
+
for (const item of content) {
|
|
1695
|
+
if (typeof item === "string") {
|
|
1696
|
+
const ts = timestampFromCursorUserText(item);
|
|
1697
|
+
if (ts) return ts;
|
|
1698
|
+
} else if (typeof item?.text === "string") {
|
|
1699
|
+
const ts = timestampFromCursorUserText(item.text);
|
|
1700
|
+
if (ts) return ts;
|
|
1701
|
+
}
|
|
1702
|
+
}
|
|
1703
|
+
return "";
|
|
1704
|
+
}
|
|
1705
|
+
function parseCursorJsonlLine(line) {
|
|
1706
|
+
if (!line.trim()) return null;
|
|
1707
|
+
let entry;
|
|
1708
|
+
try {
|
|
1709
|
+
entry = JSON.parse(line);
|
|
1710
|
+
} catch {
|
|
1711
|
+
return null;
|
|
1712
|
+
}
|
|
1713
|
+
return cursorEntryToMessage(entry);
|
|
1714
|
+
}
|
|
1715
|
+
function cursorEntryToMessage(entry) {
|
|
1716
|
+
if (looksLikeCursorChatEntry(entry)) {
|
|
1717
|
+
const role = entry.role;
|
|
1718
|
+
const message = entry.message;
|
|
1719
|
+
const text = extractCursorText(message?.content ?? entry.content);
|
|
1720
|
+
if (!text) return null;
|
|
1721
|
+
const ts = firstTimestampHint(message?.content ?? entry.content);
|
|
1722
|
+
return { role, text, timestamp: ts };
|
|
1723
|
+
}
|
|
1724
|
+
if (looksLikeImportedClaudeEntry(entry)) {
|
|
1725
|
+
const message = entry.message;
|
|
1726
|
+
const role = message?.role === "assistant" || entry.type === "assistant" ? "assistant" : "user";
|
|
1727
|
+
const text = extractCursorText(message?.content ?? entry.content);
|
|
1728
|
+
if (!text) return null;
|
|
1729
|
+
const ts = asString2(entry.timestamp);
|
|
1730
|
+
return { role, text, timestamp: ts };
|
|
1731
|
+
}
|
|
1732
|
+
return parseCodexJsonlLine(JSON.stringify(entry));
|
|
1733
|
+
}
|
|
1734
|
+
function foldCursorMessage(acc, role, text, timestamp, tier) {
|
|
1735
|
+
if (timestamp && (!acc.latestTimestamp || timestamp > acc.latestTimestamp)) {
|
|
1736
|
+
acc.latestTimestamp = timestamp;
|
|
1737
|
+
}
|
|
1738
|
+
acc.messageCount++;
|
|
1739
|
+
acc.lastMessageSender = role;
|
|
1740
|
+
const snapshot = { text: text.slice(0, 200), timestamp };
|
|
1741
|
+
if (role === "user") {
|
|
1742
|
+
if (!acc.firstUser) acc.firstUser = snapshot;
|
|
1743
|
+
acc.lastUser = snapshot;
|
|
1744
|
+
} else {
|
|
1745
|
+
acc.lastAssistant = snapshot;
|
|
1746
|
+
}
|
|
1747
|
+
if (acc.previewLength < tier.previewMax) {
|
|
1748
|
+
acc.previewParts.push(text);
|
|
1749
|
+
acc.previewLength += text.length;
|
|
1750
|
+
}
|
|
1751
|
+
if (acc.snippetLength < tier.snippetMax) {
|
|
1752
|
+
const remaining = tier.snippetMax - acc.snippetLength;
|
|
1753
|
+
const chunk = text.length > remaining ? text.slice(0, remaining) : text;
|
|
1754
|
+
acc.snippetParts.push(chunk);
|
|
1755
|
+
acc.snippetLength += chunk.length;
|
|
1756
|
+
}
|
|
1757
|
+
}
|
|
1758
|
+
function reduceCursorEntry(acc, entry, tier) {
|
|
1759
|
+
const message = entry.message;
|
|
1760
|
+
const content = message?.content ?? entry.content;
|
|
1761
|
+
const textHint = extractCursorText(content);
|
|
1762
|
+
noteImportProvenance(acc, entry, textHint);
|
|
1763
|
+
if (looksLikeCursorChatEntry(entry)) {
|
|
1764
|
+
collectCursorToolNames(content, acc.toolNames);
|
|
1765
|
+
const text = textHint;
|
|
1766
|
+
if (!text) return;
|
|
1767
|
+
foldCursorMessage(acc, entry.role, text, firstTimestampHint(content), tier);
|
|
1768
|
+
return;
|
|
1769
|
+
}
|
|
1770
|
+
if (looksLikeImportedClaudeEntry(entry)) {
|
|
1771
|
+
collectCursorToolNames(content, acc.toolNames);
|
|
1772
|
+
const msg = cursorEntryToMessage(entry);
|
|
1773
|
+
if (!msg) return;
|
|
1774
|
+
foldCursorMessage(acc, msg.role, msg.text, msg.timestamp, tier);
|
|
1775
|
+
return;
|
|
1776
|
+
}
|
|
1777
|
+
if (looksLikeImportedCodexEntry(entry)) {
|
|
1778
|
+
const msg = parseCodexJsonlLine(JSON.stringify(entry));
|
|
1779
|
+
if (!msg) return;
|
|
1780
|
+
foldCursorMessage(acc, msg.role, msg.text, msg.timestamp, tier);
|
|
1781
|
+
}
|
|
1782
|
+
}
|
|
1783
|
+
function finalizeCursorMeta(acc, filePath, account, tier) {
|
|
1784
|
+
if (acc.messageCount === 0) return null;
|
|
1785
|
+
const sessionId = basename5(filePath, ".jsonl");
|
|
1786
|
+
const isSubagent = SUBAGENT_PATH_RE2.test(filePath);
|
|
1787
|
+
const parent = isSubagent ? parentFromSubagentPath(filePath) : null;
|
|
1788
|
+
const { projectPath, projectName } = projectFromCursorPath(filePath);
|
|
1789
|
+
const timestamp = acc.latestTimestamp || fileMtimeIso(filePath);
|
|
1790
|
+
const kind = acc.lastAssistant === null && acc.toolNames.length > 0 ? "task" : "conversation";
|
|
1791
|
+
return {
|
|
1792
|
+
id: filePath,
|
|
1793
|
+
filePath,
|
|
1794
|
+
provider: CURSOR_PROVIDER,
|
|
1795
|
+
kind,
|
|
1796
|
+
externalSessionId: sessionId,
|
|
1797
|
+
sessionId,
|
|
1798
|
+
sessionName: deriveSessionNameFromFirstMessage(acc.firstUser),
|
|
1799
|
+
projectPath,
|
|
1800
|
+
projectName,
|
|
1801
|
+
account,
|
|
1802
|
+
timestamp,
|
|
1803
|
+
messageCount: acc.messageCount,
|
|
1804
|
+
lastMessageSender: acc.lastMessageSender,
|
|
1805
|
+
preview: acc.previewParts.join(" ").slice(0, tier.previewMax),
|
|
1806
|
+
contentSnippet: acc.snippetParts.join(" "),
|
|
1807
|
+
gitBranch: null,
|
|
1808
|
+
model: null,
|
|
1809
|
+
isSubagent,
|
|
1810
|
+
parentSessionId: parent?.parentFilePath ?? null,
|
|
1811
|
+
subagentId: isSubagent ? sessionId : void 0,
|
|
1812
|
+
parentSessionUuid: parent?.parentSessionUuid ?? void 0,
|
|
1813
|
+
isTeammate: false,
|
|
1814
|
+
teamName: null,
|
|
1815
|
+
toolNames: acc.toolNames,
|
|
1816
|
+
firstMessage: acc.firstUser,
|
|
1817
|
+
lastMessage: acc.lastAssistant ?? acc.lastUser,
|
|
1818
|
+
lastPrompt: acc.lastUser?.text || void 0,
|
|
1819
|
+
...acc.isImportedFromClaude ? { isImportedFromClaude: true } : {},
|
|
1820
|
+
...acc.isImportedFromCodex ? { isImportedFromCodex: true } : {}
|
|
1821
|
+
};
|
|
1822
|
+
}
|
|
1823
|
+
function parentFromSubagentPath(filePath) {
|
|
1824
|
+
const subagentsDir = dirname3(filePath);
|
|
1825
|
+
const parentDir = dirname3(subagentsDir);
|
|
1826
|
+
const parentSessionUuid = basename5(parentDir);
|
|
1827
|
+
if (!parentSessionUuid) return null;
|
|
1828
|
+
return {
|
|
1829
|
+
parentSessionUuid,
|
|
1830
|
+
parentFilePath: canonicalPath(join4(parentDir, `${parentSessionUuid}.jsonl`))
|
|
1831
|
+
};
|
|
1832
|
+
}
|
|
1833
|
+
function projectFromCursorPath(filePath) {
|
|
1834
|
+
const parts = filePath.split(/[/\\]/);
|
|
1835
|
+
const idx = parts.lastIndexOf("agent-transcripts");
|
|
1836
|
+
const cursorProjectDir = idx > 0 ? parts.slice(0, idx).join(sep2) : dirname3(dirname3(filePath));
|
|
1837
|
+
const slug = basename5(cursorProjectDir);
|
|
1838
|
+
const decoded = decodeCursorProjectSlug(slug);
|
|
1839
|
+
const projectPath = decoded ?? cursorProjectDir;
|
|
1840
|
+
return { projectPath, projectName: getShortProjectName4(projectPath) || slug };
|
|
1841
|
+
}
|
|
1842
|
+
function decodeCursorProjectSlug(slug) {
|
|
1843
|
+
if (!slug) return null;
|
|
1844
|
+
const segments = slug.split("-");
|
|
1845
|
+
if (segments.length === 0) return null;
|
|
1846
|
+
const rooted = slug.startsWith("Users-") || slug.startsWith("home-") || /^[A-Za-z]-/.test(slug);
|
|
1847
|
+
let acc = rooted ? sep2 : "";
|
|
1848
|
+
let i = 0;
|
|
1849
|
+
if (rooted && segments[0] === "Users") {
|
|
1850
|
+
const users = `${sep2}Users`;
|
|
1851
|
+
if (!existsSync(users)) return null;
|
|
1852
|
+
acc = users;
|
|
1853
|
+
i = 1;
|
|
1854
|
+
}
|
|
1855
|
+
while (i < segments.length) {
|
|
1856
|
+
let found = null;
|
|
1857
|
+
let next = i + 1;
|
|
1858
|
+
for (let j = segments.length; j > i; j--) {
|
|
1859
|
+
const candidate = join4(acc, segments.slice(i, j).join("-"));
|
|
1860
|
+
try {
|
|
1861
|
+
if (existsSync(candidate) && statSync2(candidate).isDirectory()) {
|
|
1862
|
+
found = candidate;
|
|
1863
|
+
next = j;
|
|
1864
|
+
break;
|
|
1865
|
+
}
|
|
1866
|
+
} catch {
|
|
1867
|
+
}
|
|
1868
|
+
}
|
|
1869
|
+
if (!found) return null;
|
|
1870
|
+
acc = found;
|
|
1871
|
+
i = next;
|
|
1872
|
+
}
|
|
1873
|
+
return acc;
|
|
1874
|
+
}
|
|
1875
|
+
function getShortProjectName4(fullPath) {
|
|
1876
|
+
return fullPath.split(/[/\\]/).filter(Boolean).slice(-3).join("/");
|
|
1877
|
+
}
|
|
1878
|
+
function fileMtimeIso(filePath) {
|
|
1879
|
+
try {
|
|
1880
|
+
return new Date(statSync2(filePath).mtimeMs).toISOString();
|
|
1881
|
+
} catch {
|
|
1882
|
+
return (/* @__PURE__ */ new Date()).toISOString();
|
|
1883
|
+
}
|
|
1884
|
+
}
|
|
1885
|
+
async function parseCursorConversation(filePath, account) {
|
|
1886
|
+
const log = getLogger();
|
|
1887
|
+
const messages = [];
|
|
1888
|
+
const textParts = [];
|
|
1889
|
+
let latestTimestamp = "";
|
|
1890
|
+
let lastUserText = "";
|
|
1891
|
+
const rl = createInterface3({ input: createReadStream5(filePath), crlfDelay: Infinity });
|
|
1892
|
+
try {
|
|
1893
|
+
for await (const line of rl) {
|
|
1894
|
+
const message = parseCursorJsonlLine(line);
|
|
1895
|
+
if (!message) continue;
|
|
1896
|
+
if (message.timestamp && (!latestTimestamp || message.timestamp > latestTimestamp)) {
|
|
1897
|
+
latestTimestamp = message.timestamp;
|
|
1898
|
+
}
|
|
1899
|
+
messages.push(message);
|
|
1900
|
+
textParts.push(message.text);
|
|
1901
|
+
if (message.role === "user") lastUserText = message.text;
|
|
1902
|
+
}
|
|
1903
|
+
} catch (err) {
|
|
1904
|
+
log.warn({ filePath, err }, "parseCursorConversation: read failed");
|
|
1905
|
+
return null;
|
|
1906
|
+
}
|
|
1907
|
+
if (messages.length === 0) return null;
|
|
1908
|
+
const { projectPath, projectName } = projectFromCursorPath(filePath);
|
|
1909
|
+
const sessionId = basename5(filePath, ".jsonl");
|
|
1910
|
+
return {
|
|
1911
|
+
id: filePath,
|
|
1912
|
+
filePath,
|
|
1913
|
+
projectPath,
|
|
1914
|
+
projectName,
|
|
1915
|
+
sessionId,
|
|
1916
|
+
sessionName: "",
|
|
1917
|
+
messages,
|
|
1918
|
+
fullText: textParts.join(" "),
|
|
1919
|
+
timestamp: latestTimestamp || fileMtimeIso(filePath),
|
|
1920
|
+
messageCount: messages.length,
|
|
1921
|
+
account,
|
|
1922
|
+
lastPrompt: lastUserText || void 0
|
|
1923
|
+
};
|
|
1924
|
+
}
|
|
1925
|
+
|
|
1926
|
+
// src/providers/parse.ts
|
|
1927
|
+
import { createReadStream as createReadStream6 } from "fs";
|
|
1928
|
+
import { createInterface as createInterface4 } from "readline";
|
|
1500
1929
|
async function parseMetaWithProvider(provider, filePath, account, tier, onEntry) {
|
|
1501
1930
|
const log = getLogger();
|
|
1502
1931
|
const acc = provider.createEmptyAccumulator();
|
|
1503
|
-
const rl =
|
|
1504
|
-
input:
|
|
1932
|
+
const rl = createInterface4({
|
|
1933
|
+
input: createReadStream6(filePath),
|
|
1505
1934
|
crlfDelay: Infinity
|
|
1506
1935
|
});
|
|
1507
1936
|
try {
|
|
@@ -1571,8 +2000,35 @@ function extractSearchDelta(entry) {
|
|
|
1571
2000
|
if (entry.type === "response_item" || entry.type === "session_meta") {
|
|
1572
2001
|
return extractCodexDelta(entry);
|
|
1573
2002
|
}
|
|
2003
|
+
if (looksLikeCursorChatEntry(entry)) {
|
|
2004
|
+
return extractCursorDelta(entry);
|
|
2005
|
+
}
|
|
1574
2006
|
return extractClaudeDelta(entry);
|
|
1575
2007
|
}
|
|
2008
|
+
function extractCursorDelta(entry) {
|
|
2009
|
+
const msg = entry.message;
|
|
2010
|
+
const content = msg?.content ?? entry.content;
|
|
2011
|
+
return {
|
|
2012
|
+
text: extractCursorSearchText(content),
|
|
2013
|
+
thinking: "",
|
|
2014
|
+
tools: extractClaudeToolContent(content)
|
|
2015
|
+
};
|
|
2016
|
+
}
|
|
2017
|
+
function extractCursorSearchText(content) {
|
|
2018
|
+
if (typeof content === "string") return unwrapCursorUserText(content);
|
|
2019
|
+
if (!Array.isArray(content)) return "";
|
|
2020
|
+
const parts = [];
|
|
2021
|
+
for (const item of content) {
|
|
2022
|
+
if (typeof item === "string") {
|
|
2023
|
+
const cleaned = unwrapCursorUserText(item);
|
|
2024
|
+
if (cleaned) parts.push(cleaned);
|
|
2025
|
+
} else if ((item?.type === "text" || item?.type === void 0) && typeof item?.text === "string") {
|
|
2026
|
+
const cleaned = unwrapCursorUserText(item.text);
|
|
2027
|
+
if (cleaned) parts.push(cleaned);
|
|
2028
|
+
}
|
|
2029
|
+
}
|
|
2030
|
+
return parts.join(SEP);
|
|
2031
|
+
}
|
|
1576
2032
|
function extractClaudeDelta(entry) {
|
|
1577
2033
|
const type = entry.type;
|
|
1578
2034
|
if (type !== "user" && type !== "assistant") return emptySearchDocument();
|
|
@@ -1690,10 +2146,10 @@ function resolveTier(tierName, customTiers) {
|
|
|
1690
2146
|
// src/persistent/db.ts
|
|
1691
2147
|
import Database from "better-sqlite3";
|
|
1692
2148
|
import { mkdirSync } from "fs";
|
|
1693
|
-
import { dirname as
|
|
2149
|
+
import { dirname as dirname4 } from "path";
|
|
1694
2150
|
|
|
1695
2151
|
// src/persistent/schema.ts
|
|
1696
|
-
var SCHEMA_VERSION =
|
|
2152
|
+
var SCHEMA_VERSION = 9;
|
|
1697
2153
|
var SCHEMA_SQL = `
|
|
1698
2154
|
CREATE TABLE IF NOT EXISTS conversation_files (
|
|
1699
2155
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
@@ -1778,6 +2234,10 @@ CREATE TABLE IF NOT EXISTS conversations (
|
|
|
1778
2234
|
tool_names_json TEXT,
|
|
1779
2235
|
last_prompt TEXT,
|
|
1780
2236
|
|
|
2237
|
+
is_imported_from_claude INTEGER NOT NULL DEFAULT 0,
|
|
2238
|
+
is_imported_from_codex INTEGER NOT NULL DEFAULT 0,
|
|
2239
|
+
is_imported_from_cursor INTEGER NOT NULL DEFAULT 0,
|
|
2240
|
+
|
|
1781
2241
|
status TEXT NOT NULL DEFAULT 'active',
|
|
1782
2242
|
|
|
1783
2243
|
created_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
@@ -1943,6 +2403,45 @@ function runMigrations(db) {
|
|
|
1943
2403
|
db.exec(`UPDATE conversation_files SET ${assignments.join(", ")}`);
|
|
1944
2404
|
}
|
|
1945
2405
|
}
|
|
2406
|
+
if (current >= 1 && current < 8 && tableExists(db, "conversations")) {
|
|
2407
|
+
for (const [col, ddl] of [
|
|
2408
|
+
[
|
|
2409
|
+
"is_imported_from_claude",
|
|
2410
|
+
"ALTER TABLE conversations ADD COLUMN is_imported_from_claude INTEGER NOT NULL DEFAULT 0"
|
|
2411
|
+
],
|
|
2412
|
+
[
|
|
2413
|
+
"is_imported_from_codex",
|
|
2414
|
+
"ALTER TABLE conversations ADD COLUMN is_imported_from_codex INTEGER NOT NULL DEFAULT 0"
|
|
2415
|
+
],
|
|
2416
|
+
[
|
|
2417
|
+
"is_imported_from_cursor",
|
|
2418
|
+
"ALTER TABLE conversations ADD COLUMN is_imported_from_cursor INTEGER NOT NULL DEFAULT 0"
|
|
2419
|
+
]
|
|
2420
|
+
]) {
|
|
2421
|
+
if (!hasColumn(db, "conversations", col)) db.exec(ddl);
|
|
2422
|
+
}
|
|
2423
|
+
if (tableExists(db, "conversation_files")) {
|
|
2424
|
+
const assignments = [];
|
|
2425
|
+
if (hasColumn(db, "conversation_files", "last_indexed_offset")) {
|
|
2426
|
+
assignments.push("last_indexed_offset = 0");
|
|
2427
|
+
}
|
|
2428
|
+
if (hasColumn(db, "conversation_files", "last_indexed_line")) {
|
|
2429
|
+
assignments.push("last_indexed_line = 0");
|
|
2430
|
+
}
|
|
2431
|
+
if (hasColumn(db, "conversation_files", "reducer_state")) {
|
|
2432
|
+
assignments.push("reducer_state = NULL");
|
|
2433
|
+
}
|
|
2434
|
+
if (assignments.length > 0) {
|
|
2435
|
+
db.exec(
|
|
2436
|
+
`UPDATE conversation_files SET ${assignments.join(", ")}
|
|
2437
|
+
WHERE id IN (SELECT file_id FROM conversations WHERE provider IN ('cursor', 'cursor-cli'))`
|
|
2438
|
+
);
|
|
2439
|
+
}
|
|
2440
|
+
}
|
|
2441
|
+
}
|
|
2442
|
+
if (current >= 1 && current < 9 && tableExists(db, "conversations")) {
|
|
2443
|
+
db.exec(`UPDATE conversations SET provider = 'cursor' WHERE provider = 'cursor-cli'`);
|
|
2444
|
+
}
|
|
1946
2445
|
db.exec(SCHEMA_SQL);
|
|
1947
2446
|
db.pragma(`user_version = ${SCHEMA_VERSION}`);
|
|
1948
2447
|
}
|
|
@@ -1957,7 +2456,7 @@ function hasColumn(db, table, column) {
|
|
|
1957
2456
|
// src/persistent/db.ts
|
|
1958
2457
|
function openDatabase(dbPath) {
|
|
1959
2458
|
if (dbPath !== ":memory:") {
|
|
1960
|
-
mkdirSync(
|
|
2459
|
+
mkdirSync(dirname4(dbPath), { recursive: true });
|
|
1961
2460
|
}
|
|
1962
2461
|
let db;
|
|
1963
2462
|
try {
|
|
@@ -2001,8 +2500,8 @@ function nativeBindingError(err, dbPath) {
|
|
|
2001
2500
|
}
|
|
2002
2501
|
|
|
2003
2502
|
// src/persistent/dir-watermark.ts
|
|
2004
|
-
import { readdir, stat as
|
|
2005
|
-
import { dirname as
|
|
2503
|
+
import { readdir, stat as stat4 } from "fs/promises";
|
|
2504
|
+
import { dirname as dirname5, join as join5 } from "path";
|
|
2006
2505
|
var FULL_RECONCILE_EVERY_N_SCANS = 20;
|
|
2007
2506
|
async function discoverJsonlFilesGated(dirs, files, scannedDirs, options = {}) {
|
|
2008
2507
|
const log = getLogger();
|
|
@@ -2018,7 +2517,7 @@ async function discoverJsonlFilesGated(dirs, files, scannedDirs, options = {}) {
|
|
|
2018
2517
|
for (const projectDir of resolved.entries) {
|
|
2019
2518
|
let dirStat;
|
|
2020
2519
|
try {
|
|
2021
|
-
dirStat = await
|
|
2520
|
+
dirStat = await stat4(projectDir);
|
|
2022
2521
|
} catch {
|
|
2023
2522
|
scannedDirs.remove(projectDir);
|
|
2024
2523
|
continue;
|
|
@@ -2056,7 +2555,7 @@ async function discoverJsonlFilesGated(dirs, files, scannedDirs, options = {}) {
|
|
|
2056
2555
|
async function resolveProjectDirs(projectsDir, scannedDirs) {
|
|
2057
2556
|
let rootStat;
|
|
2058
2557
|
try {
|
|
2059
|
-
rootStat = await
|
|
2558
|
+
rootStat = await stat4(projectsDir);
|
|
2060
2559
|
} catch {
|
|
2061
2560
|
return null;
|
|
2062
2561
|
}
|
|
@@ -2073,10 +2572,10 @@ async function resolveProjectDirs(projectsDir, scannedDirs) {
|
|
|
2073
2572
|
return { entries, commitRoot: { mtimeMs: rootStat.mtimeMs } };
|
|
2074
2573
|
}
|
|
2075
2574
|
function dirnameOf(filePath) {
|
|
2076
|
-
return
|
|
2575
|
+
return dirname5(filePath);
|
|
2077
2576
|
}
|
|
2078
2577
|
function joinPath(dir, name) {
|
|
2079
|
-
return
|
|
2578
|
+
return join5(dir, name);
|
|
2080
2579
|
}
|
|
2081
2580
|
|
|
2082
2581
|
// src/persistent/repositories/checkpoints.repo.ts
|
|
@@ -2156,7 +2655,7 @@ function toCheckpoint(row) {
|
|
|
2156
2655
|
}
|
|
2157
2656
|
|
|
2158
2657
|
// src/persistent/repositories/conversation-files.repo.ts
|
|
2159
|
-
import { basename as
|
|
2658
|
+
import { basename as basename6, dirname as dirname6 } from "path";
|
|
2160
2659
|
var ConversationFilesRepo = class {
|
|
2161
2660
|
constructor(db) {
|
|
2162
2661
|
this.db = db;
|
|
@@ -2179,7 +2678,7 @@ var ConversationFilesRepo = class {
|
|
|
2179
2678
|
const info = this.db.prepare(
|
|
2180
2679
|
`INSERT INTO conversation_files (absolute_path, parent_dir, file_name, account)
|
|
2181
2680
|
VALUES (?, ?, ?, ?)`
|
|
2182
|
-
).run(canonical,
|
|
2681
|
+
).run(canonical, dirname6(canonical), basename6(canonical), account);
|
|
2183
2682
|
return Number(info.lastInsertRowid);
|
|
2184
2683
|
}
|
|
2185
2684
|
// Advance the cursor + persisted reducer state after a successful index pass.
|
|
@@ -2274,7 +2773,10 @@ function rowToMeta(row) {
|
|
|
2274
2773
|
toolNames: row.tool_names_json ? JSON.parse(row.tool_names_json) : [],
|
|
2275
2774
|
firstMessage: row.first_sent_text ? { text: row.first_sent_text, timestamp: row.first_sent_at ?? "" } : null,
|
|
2276
2775
|
lastMessage: row.last_sent_text ? { text: row.last_sent_text, timestamp: row.last_sent_at ?? "" } : null,
|
|
2277
|
-
lastPrompt: row.last_prompt ?? void 0
|
|
2776
|
+
lastPrompt: row.last_prompt ?? void 0,
|
|
2777
|
+
...row.is_imported_from_claude === 1 ? { isImportedFromClaude: true } : {},
|
|
2778
|
+
...row.is_imported_from_codex === 1 ? { isImportedFromCodex: true } : {},
|
|
2779
|
+
...row.is_imported_from_cursor === 1 ? { isImportedFromCursor: true } : {}
|
|
2278
2780
|
};
|
|
2279
2781
|
}
|
|
2280
2782
|
var ConversationsRepo = class {
|
|
@@ -2294,7 +2796,8 @@ var ConversationsRepo = class {
|
|
|
2294
2796
|
timestamp, index_seq, first_sent_at, first_sent_text, last_sent_at, last_sent_text,
|
|
2295
2797
|
model, is_subagent, parent_session_id, subagent_id, parent_session_uuid,
|
|
2296
2798
|
is_teammate, team_name, tool_names_json,
|
|
2297
|
-
last_prompt,
|
|
2799
|
+
last_prompt, is_imported_from_claude, is_imported_from_codex,
|
|
2800
|
+
is_imported_from_cursor, status, updated_at
|
|
2298
2801
|
) VALUES (
|
|
2299
2802
|
@file_id, @source_path, @provider, @kind, @external_session_id,
|
|
2300
2803
|
@session_id, @session_name, @project_path, @project_name,
|
|
@@ -2305,7 +2808,8 @@ var ConversationsRepo = class {
|
|
|
2305
2808
|
@first_sent_at, @first_sent_text, @last_sent_at, @last_sent_text,
|
|
2306
2809
|
@model, @is_subagent, @parent_session_id, @subagent_id, @parent_session_uuid,
|
|
2307
2810
|
@is_teammate, @team_name, @tool_names_json,
|
|
2308
|
-
@last_prompt,
|
|
2811
|
+
@last_prompt, @is_imported_from_claude, @is_imported_from_codex,
|
|
2812
|
+
@is_imported_from_cursor, 'active', CURRENT_TIMESTAMP
|
|
2309
2813
|
)
|
|
2310
2814
|
ON CONFLICT(file_id) DO UPDATE SET
|
|
2311
2815
|
source_path = excluded.source_path,
|
|
@@ -2337,6 +2841,9 @@ var ConversationsRepo = class {
|
|
|
2337
2841
|
team_name = excluded.team_name,
|
|
2338
2842
|
tool_names_json = excluded.tool_names_json,
|
|
2339
2843
|
last_prompt = excluded.last_prompt,
|
|
2844
|
+
is_imported_from_claude = excluded.is_imported_from_claude,
|
|
2845
|
+
is_imported_from_codex = excluded.is_imported_from_codex,
|
|
2846
|
+
is_imported_from_cursor = excluded.is_imported_from_cursor,
|
|
2340
2847
|
status = 'active',
|
|
2341
2848
|
index_seq = (SELECT COALESCE(MAX(index_seq), 0) + 1 FROM conversations),
|
|
2342
2849
|
updated_at = CURRENT_TIMESTAMP`
|
|
@@ -2373,7 +2880,10 @@ var ConversationsRepo = class {
|
|
|
2373
2880
|
is_teammate: meta.isTeammate ? 1 : 0,
|
|
2374
2881
|
team_name: meta.teamName,
|
|
2375
2882
|
tool_names_json: JSON.stringify(meta.toolNames),
|
|
2376
|
-
last_prompt: meta.lastPrompt ?? null
|
|
2883
|
+
last_prompt: meta.lastPrompt ?? null,
|
|
2884
|
+
is_imported_from_claude: meta.isImportedFromClaude ? 1 : 0,
|
|
2885
|
+
is_imported_from_codex: meta.isImportedFromCodex ? 1 : 0,
|
|
2886
|
+
is_imported_from_cursor: meta.isImportedFromCursor ? 1 : 0
|
|
2377
2887
|
});
|
|
2378
2888
|
}
|
|
2379
2889
|
getBySourcePath(sourcePath) {
|
|
@@ -2533,8 +3043,14 @@ var FtsRepo = class {
|
|
|
2533
3043
|
params.push(filters.account);
|
|
2534
3044
|
}
|
|
2535
3045
|
if (filters.provider) {
|
|
2536
|
-
|
|
2537
|
-
|
|
3046
|
+
const provider = canonicalizeProviderName(filters.provider) ?? filters.provider;
|
|
3047
|
+
if (provider === CURSOR_PROVIDER) {
|
|
3048
|
+
where.push("(c.provider = ? OR c.provider = ?)");
|
|
3049
|
+
params.push(CURSOR_PROVIDER, LEGACY_CURSOR_PROVIDER);
|
|
3050
|
+
} else {
|
|
3051
|
+
where.push("c.provider = ?");
|
|
3052
|
+
params.push(provider);
|
|
3053
|
+
}
|
|
2538
3054
|
}
|
|
2539
3055
|
if (filters.project) {
|
|
2540
3056
|
where.push("(lower(c.project_path) LIKE ? OR lower(c.project_name) LIKE ?)");
|
|
@@ -2686,7 +3202,7 @@ var PersistentEngine = class {
|
|
|
2686
3202
|
async indexAll(activeProfiles, options) {
|
|
2687
3203
|
const log = getLogger();
|
|
2688
3204
|
const tier = resolveTier(options.tier ?? "standard", options.tiers);
|
|
2689
|
-
const enabled = options.providers
|
|
3205
|
+
const enabled = canonicalizeProviderList(options.providers);
|
|
2690
3206
|
const discovered = [];
|
|
2691
3207
|
if (enabled.includes(CLAUDE_CODE_PROVIDER)) {
|
|
2692
3208
|
const configDirs = activeProfiles.map((p) => ({
|
|
@@ -2706,6 +3222,12 @@ var PersistentEngine = class {
|
|
|
2706
3222
|
discovered.push({ ...f, provider: codex });
|
|
2707
3223
|
}
|
|
2708
3224
|
}
|
|
3225
|
+
const cursor = new CursorProvider();
|
|
3226
|
+
if (enabled.includes(CURSOR_PROVIDER) && (options.cursorRoots?.length ?? 0) > 0) {
|
|
3227
|
+
for (const f of await cursor.discover(options.cursorRoots)) {
|
|
3228
|
+
discovered.push({ ...f, provider: cursor });
|
|
3229
|
+
}
|
|
3230
|
+
}
|
|
2709
3231
|
let scanned = 0;
|
|
2710
3232
|
const gitBranchMemo = /* @__PURE__ */ new Map();
|
|
2711
3233
|
const resolveGitBranch = (projectPath) => {
|
|
@@ -2744,6 +3266,9 @@ var PersistentEngine = class {
|
|
|
2744
3266
|
if (enabled.includes(CODEX_CLI_PROVIDER) && (options.codexRoots?.length ?? 0) > 0) {
|
|
2745
3267
|
coveredAccounts.add("codex");
|
|
2746
3268
|
}
|
|
3269
|
+
if (enabled.includes(CURSOR_PROVIDER) && (options.cursorRoots?.length ?? 0) > 0) {
|
|
3270
|
+
coveredAccounts.add("cursor");
|
|
3271
|
+
}
|
|
2747
3272
|
const seen = new Set(discovered.map((d) => canonicalPath(d.filePath)));
|
|
2748
3273
|
for (const path of this.files.activePathsByAccounts([...coveredAccounts])) {
|
|
2749
3274
|
if (!seen.has(path)) this.markDeleted(path);
|
|
@@ -2763,8 +3288,8 @@ var PersistentEngine = class {
|
|
|
2763
3288
|
const tier = resolveTier(tierName, customTiers);
|
|
2764
3289
|
const filePath = canonicalPath(rawFilePath);
|
|
2765
3290
|
const existing = this.files.getByPath(filePath);
|
|
2766
|
-
const { change, stat:
|
|
2767
|
-
if (change === "vanished" || !
|
|
3291
|
+
const { change, stat: stat5 } = classify(filePath, existing);
|
|
3292
|
+
if (change === "vanished" || !stat5) {
|
|
2768
3293
|
this.markDeleted(filePath);
|
|
2769
3294
|
return { meta: null, change: "vanished" };
|
|
2770
3295
|
}
|
|
@@ -2777,7 +3302,7 @@ var PersistentEngine = class {
|
|
|
2777
3302
|
filePath,
|
|
2778
3303
|
account,
|
|
2779
3304
|
tier,
|
|
2780
|
-
|
|
3305
|
+
stat5,
|
|
2781
3306
|
resolveGitBranch
|
|
2782
3307
|
);
|
|
2783
3308
|
return { meta: meta2, change };
|
|
@@ -2803,7 +3328,7 @@ var PersistentEngine = class {
|
|
|
2803
3328
|
return { meta: null, change };
|
|
2804
3329
|
}
|
|
2805
3330
|
meta.gitBranch = resolveGitBranch(meta.projectPath);
|
|
2806
|
-
const fp =
|
|
3331
|
+
const fp = stat5.size > 0 ? fingerprint(filePath, stat5.size) : null;
|
|
2807
3332
|
const fileId = this.files.ensure(filePath, account);
|
|
2808
3333
|
const base = resume ? this.fts.readDocument(fileId) ?? emptySearchDocument() : emptySearchDocument();
|
|
2809
3334
|
const searchDoc = appendSearchDelta(base, searchDelta);
|
|
@@ -2814,8 +3339,8 @@ var PersistentEngine = class {
|
|
|
2814
3339
|
}
|
|
2815
3340
|
if (!resume) this.checkpoints.remove(filePath);
|
|
2816
3341
|
this.files.updateCursor(fileId, {
|
|
2817
|
-
sizeBytes:
|
|
2818
|
-
mtimeMs:
|
|
3342
|
+
sizeBytes: stat5.size,
|
|
3343
|
+
mtimeMs: stat5.mtimeMs,
|
|
2819
3344
|
// Advance only to the last fully-parsed line; a trailing partial line
|
|
2820
3345
|
// is left for the next pass.
|
|
2821
3346
|
offset: result.newOffset,
|
|
@@ -2832,8 +3357,8 @@ var PersistentEngine = class {
|
|
|
2832
3357
|
buildSidecar(
|
|
2833
3358
|
meta,
|
|
2834
3359
|
{
|
|
2835
|
-
sizeBytes:
|
|
2836
|
-
mtimeMs:
|
|
3360
|
+
sizeBytes: stat5.size,
|
|
3361
|
+
mtimeMs: stat5.mtimeMs,
|
|
2837
3362
|
offset: result.newOffset,
|
|
2838
3363
|
line: result.newLine
|
|
2839
3364
|
},
|
|
@@ -2852,7 +3377,7 @@ var PersistentEngine = class {
|
|
|
2852
3377
|
// the Threadbase path uses. The cursor records size/mtime (and offset = size)
|
|
2853
3378
|
// so the next pass classifies an unchanged file as "unchanged" and skips it;
|
|
2854
3379
|
// any change reparses from 0 again. No reducer_state is persisted.
|
|
2855
|
-
async indexFileWithProvider(provider, filePath, account, tier,
|
|
3380
|
+
async indexFileWithProvider(provider, filePath, account, tier, stat5, resolveGitBranch) {
|
|
2856
3381
|
const log = getLogger();
|
|
2857
3382
|
let searchDoc = emptySearchDocument();
|
|
2858
3383
|
const meta = await parseMetaWithProvider(provider, filePath, account, tier, (entry) => {
|
|
@@ -2865,7 +3390,7 @@ var PersistentEngine = class {
|
|
|
2865
3390
|
if (meta.gitBranch === null && meta.projectPath) {
|
|
2866
3391
|
meta.gitBranch = resolveGitBranch(meta.projectPath);
|
|
2867
3392
|
}
|
|
2868
|
-
const fp =
|
|
3393
|
+
const fp = stat5.size > 0 ? fingerprint(filePath, stat5.size) : null;
|
|
2869
3394
|
const fileId = this.files.ensure(filePath, account);
|
|
2870
3395
|
const upsert = this.db.transaction(() => {
|
|
2871
3396
|
this.conversations.upsert(fileId, meta, meta.messageCount);
|
|
@@ -2874,11 +3399,11 @@ var PersistentEngine = class {
|
|
|
2874
3399
|
}
|
|
2875
3400
|
this.checkpoints.remove(filePath);
|
|
2876
3401
|
this.files.updateCursor(fileId, {
|
|
2877
|
-
sizeBytes:
|
|
2878
|
-
mtimeMs:
|
|
3402
|
+
sizeBytes: stat5.size,
|
|
3403
|
+
mtimeMs: stat5.mtimeMs,
|
|
2879
3404
|
// offset = size marks the file fully consumed (non-zero so the next pass
|
|
2880
3405
|
// can classify it "unchanged"); no resumable reducer state is kept.
|
|
2881
|
-
offset:
|
|
3406
|
+
offset: stat5.size,
|
|
2882
3407
|
line: 0,
|
|
2883
3408
|
reducerState: null,
|
|
2884
3409
|
fingerprint: fp,
|
|
@@ -2944,8 +3469,8 @@ var PersistentEngine = class {
|
|
|
2944
3469
|
const meta = this.conversations.getByIdOrSession(id);
|
|
2945
3470
|
if (!meta) return null;
|
|
2946
3471
|
const filePath = meta.filePath;
|
|
2947
|
-
if (meta.provider === CODEX_CLI_PROVIDER) {
|
|
2948
|
-
const conversation = await parseCodexConversation(filePath, meta.account);
|
|
3472
|
+
if (meta.provider === CODEX_CLI_PROVIDER || meta.provider === CURSOR_PROVIDER) {
|
|
3473
|
+
const conversation = meta.provider === CODEX_CLI_PROVIDER ? await parseCodexConversation(filePath, meta.account) : await parseCursorConversation(filePath, meta.account);
|
|
2949
3474
|
if (!conversation) return null;
|
|
2950
3475
|
const { messages } = conversation;
|
|
2951
3476
|
const total2 = messages.length;
|
|
@@ -2960,7 +3485,7 @@ var PersistentEngine = class {
|
|
|
2960
3485
|
let floor = this.checkpoints.floor(filePath, fromIndex);
|
|
2961
3486
|
if (floor) {
|
|
2962
3487
|
try {
|
|
2963
|
-
if (floor.byteOffset >
|
|
3488
|
+
if (floor.byteOffset > statSync3(filePath).size) floor = null;
|
|
2964
3489
|
} catch {
|
|
2965
3490
|
}
|
|
2966
3491
|
}
|
|
@@ -3135,7 +3660,7 @@ function defaultDbPath() {
|
|
|
3135
3660
|
"TB_SCANNER_DB must be set under a test runner. Refusing to open the default index at ~/.config/threadbase-scanner/index.db, because test fixtures written there are indistinguishable from real conversations and corrupt every measurement of the index. Point it at a temp directory in your test setup, or pass persistent.dbPath explicitly."
|
|
3136
3661
|
);
|
|
3137
3662
|
}
|
|
3138
|
-
return
|
|
3663
|
+
return join6(homedir2(), ".config", "threadbase-scanner", "index.db");
|
|
3139
3664
|
}
|
|
3140
3665
|
function capForMemory(doc, max) {
|
|
3141
3666
|
const combined = combineSearchContent(doc);
|
|
@@ -3314,7 +3839,7 @@ var ConversationScanner = class {
|
|
|
3314
3839
|
const cached = statCache.get(filePath);
|
|
3315
3840
|
if (cached) {
|
|
3316
3841
|
try {
|
|
3317
|
-
const s =
|
|
3842
|
+
const s = statSync4(filePath);
|
|
3318
3843
|
if (s.mtimeMs === cached.stat.mtimeMs && s.size === cached.stat.size) {
|
|
3319
3844
|
return {
|
|
3320
3845
|
meta: cached.meta,
|
|
@@ -3445,9 +3970,7 @@ var ConversationScanner = class {
|
|
|
3445
3970
|
results = results.filter((r) => r.meta.account === options.account);
|
|
3446
3971
|
}
|
|
3447
3972
|
if (options.provider) {
|
|
3448
|
-
results = results.filter(
|
|
3449
|
-
(r) => (r.meta.provider ?? CLAUDE_CODE_PROVIDER) === options.provider
|
|
3450
|
-
);
|
|
3973
|
+
results = results.filter((r) => providerMatches(r.meta.provider, options.provider));
|
|
3451
3974
|
}
|
|
3452
3975
|
if (options.since) {
|
|
3453
3976
|
const cutoff = parseSinceCutoff(options.since);
|
|
@@ -3474,12 +3997,12 @@ var ConversationScanner = class {
|
|
|
3474
3997
|
}
|
|
3475
3998
|
log.debug({ id, filePath: meta.filePath }, "getConversation: cache miss, parsing");
|
|
3476
3999
|
try {
|
|
3477
|
-
if (this.persistent && meta.provider !== CODEX_CLI_PROVIDER) {
|
|
4000
|
+
if (this.persistent && meta.provider !== CODEX_CLI_PROVIDER && meta.provider !== CURSOR_PROVIDER) {
|
|
3478
4001
|
const parsed = await parseConversationResumable(meta.filePath, meta.account);
|
|
3479
4002
|
if (parsed) this.conversationLRU.set(cid, parsed);
|
|
3480
4003
|
return parsed?.conversation ?? null;
|
|
3481
4004
|
}
|
|
3482
|
-
const conversation = meta.provider === CODEX_CLI_PROVIDER ? await parseCodexConversation(meta.filePath, meta.account) : await parseConversation(meta.filePath, meta.account);
|
|
4005
|
+
const conversation = meta.provider === CODEX_CLI_PROVIDER ? await parseCodexConversation(meta.filePath, meta.account) : meta.provider === CURSOR_PROVIDER ? await parseCursorConversation(meta.filePath, meta.account) : await parseConversation(meta.filePath, meta.account);
|
|
3483
4006
|
if (conversation) {
|
|
3484
4007
|
this.conversationLRU.set(cid, { conversation });
|
|
3485
4008
|
}
|
|
@@ -3533,7 +4056,7 @@ var ConversationScanner = class {
|
|
|
3533
4056
|
// fallback, matching refreshFile.
|
|
3534
4057
|
async parseSingleFilePage(filePath, account, options) {
|
|
3535
4058
|
const provider = await this.resolveProviderForFile(filePath, null);
|
|
3536
|
-
const conversation = provider?.name === CODEX_CLI_PROVIDER ? await parseCodexConversation(filePath, account ?? "default") : await parseConversation(filePath, account ?? "default");
|
|
4059
|
+
const conversation = provider?.name === CODEX_CLI_PROVIDER ? await parseCodexConversation(filePath, account ?? "default") : provider?.name === CURSOR_PROVIDER ? await parseCursorConversation(filePath, account ?? "default") : await parseConversation(filePath, account ?? "default");
|
|
3537
4060
|
if (!conversation) return null;
|
|
3538
4061
|
const { messages } = conversation;
|
|
3539
4062
|
const total = messages.length;
|
|
@@ -3822,7 +4345,7 @@ var ConversationScanner = class {
|
|
|
3822
4345
|
// discovers under the active profiles' project dirs; Codex discovers under
|
|
3823
4346
|
// the explicit codexRoots (opt-in — no default home scan).
|
|
3824
4347
|
async discoverWithProviders(activeProfiles, options) {
|
|
3825
|
-
const enabled = options.providers
|
|
4348
|
+
const enabled = canonicalizeProviderList(options.providers);
|
|
3826
4349
|
const work = [];
|
|
3827
4350
|
if (enabled.includes(CLAUDE_CODE_PROVIDER)) {
|
|
3828
4351
|
const provider = new ThreadbaseProvider();
|
|
@@ -3837,6 +4360,12 @@ var ConversationScanner = class {
|
|
|
3837
4360
|
work.push({ ...f, provider });
|
|
3838
4361
|
}
|
|
3839
4362
|
}
|
|
4363
|
+
if (enabled.includes(CURSOR_PROVIDER) && (options.cursorRoots?.length ?? 0) > 0) {
|
|
4364
|
+
const provider = new CursorProvider();
|
|
4365
|
+
for (const f of await provider.discover(options.cursorRoots)) {
|
|
4366
|
+
work.push({ ...f, provider });
|
|
4367
|
+
}
|
|
4368
|
+
}
|
|
3840
4369
|
return work;
|
|
3841
4370
|
}
|
|
3842
4371
|
// Resolve which provider should (re)parse a file. Stored metadata wins; for a
|
|
@@ -3845,6 +4374,9 @@ var ConversationScanner = class {
|
|
|
3845
4374
|
// tail-read path).
|
|
3846
4375
|
async resolveProviderForFile(filePath, previous) {
|
|
3847
4376
|
if (previous?.provider === CODEX_CLI_PROVIDER) return new CodexCliProvider();
|
|
4377
|
+
if (providerMatches(previous?.provider, CURSOR_PROVIDER)) {
|
|
4378
|
+
return new CursorProvider();
|
|
4379
|
+
}
|
|
3848
4380
|
if (previous?.provider) return void 0;
|
|
3849
4381
|
let sample = "";
|
|
3850
4382
|
try {
|
|
@@ -3859,6 +4391,8 @@ var ConversationScanner = class {
|
|
|
3859
4391
|
} catch {
|
|
3860
4392
|
return void 0;
|
|
3861
4393
|
}
|
|
4394
|
+
const cursor = new CursorProvider();
|
|
4395
|
+
if (cursor.canParse(filePath, sample)) return cursor;
|
|
3862
4396
|
const codex = new CodexCliProvider();
|
|
3863
4397
|
if (codex.canParse(filePath, sample)) return codex;
|
|
3864
4398
|
return void 0;
|