@threadbase-sh/scanner 0.21.0 → 0.22.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 +3 -1
- package/dist/cli.js +496 -128
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +579 -152
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +551 -133
- package/dist/index.js.map +1 -1
- package/dist/name-stores.d.ts +13 -0
- package/dist/name-stores.d.ts.map +1 -0
- package/dist/parser.d.ts.map +1 -1
- package/dist/persistent/claude-name-slots.d.ts +3 -0
- package/dist/persistent/claude-name-slots.d.ts.map +1 -0
- package/dist/persistent/conversation-reducer.d.ts +2 -1
- package/dist/persistent/conversation-reducer.d.ts.map +1 -1
- package/dist/persistent/conversation-stream.d.ts.map +1 -1
- package/dist/persistent/index-engine.d.ts.map +1 -1
- package/dist/persistent/metadata-reducer.d.ts +2 -4
- package/dist/persistent/metadata-reducer.d.ts.map +1 -1
- package/dist/persistent/migrations.d.ts.map +1 -1
- package/dist/persistent/repositories/conversations.repo.d.ts +2 -1
- package/dist/persistent/repositories/conversations.repo.d.ts.map +1 -1
- package/dist/persistent/schema.d.ts +2 -2
- package/dist/persistent/schema.d.ts.map +1 -1
- package/dist/providers/codex-cli.d.ts +3 -6
- package/dist/providers/codex-cli.d.ts.map +1 -1
- package/dist/providers/copilot.d.ts +2 -0
- package/dist/providers/copilot.d.ts.map +1 -1
- package/dist/providers/cursor.d.ts +2 -0
- package/dist/providers/cursor.d.ts.map +1 -1
- package/dist/providers/parse.d.ts +1 -1
- package/dist/providers/parse.d.ts.map +1 -1
- package/dist/scanner.d.ts.map +1 -1
- package/dist/session-name.d.ts +24 -0
- package/dist/session-name.d.ts.map +1 -0
- package/dist/types.d.ts +1 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -40,11 +40,13 @@ __export(index_exports, {
|
|
|
40
40
|
CursorProvider: () => CursorProvider,
|
|
41
41
|
DEFAULT_TIERS: () => DEFAULT_TIERS,
|
|
42
42
|
LEGACY_CURSOR_PROVIDER: () => LEGACY_CURSOR_PROVIDER,
|
|
43
|
+
NAME_PRECEDENCE: () => NAME_PRECEDENCE,
|
|
43
44
|
SearchIndexer: () => SearchIndexer,
|
|
44
45
|
ThreadbaseProvider: () => ThreadbaseProvider,
|
|
45
46
|
VALID_SORT_ORDERS: () => VALID_SORT_ORDERS,
|
|
46
47
|
applyAccountFilter: () => applyAccountFilter,
|
|
47
48
|
applyIncludeFilter: () => applyIncludeFilter,
|
|
49
|
+
applyNameCandidate: () => applyNameCandidate,
|
|
48
50
|
applyPagination: () => applyPagination,
|
|
49
51
|
applyProjectFilter: () => applyProjectFilter,
|
|
50
52
|
applySinceFilter: () => applySinceFilter,
|
|
@@ -59,20 +61,27 @@ __export(index_exports, {
|
|
|
59
61
|
getLogger: () => getLogger,
|
|
60
62
|
getProjectsDir: () => getProjectsDir,
|
|
61
63
|
isCodexInjectedContext: () => isCodexInjectedContext,
|
|
64
|
+
isValidNameCandidate: () => isValidNameCandidate,
|
|
62
65
|
loadProfiles: () => loadProfiles,
|
|
63
66
|
parseCodexJsonlLine: () => parseCodexJsonlLine,
|
|
64
67
|
parseCopilotJsonlLine: () => parseCopilotJsonlLine,
|
|
65
68
|
parseCursorJsonlLine: () => parseCursorJsonlLine,
|
|
66
69
|
parseJsonlLine: () => parseJsonlLine,
|
|
67
70
|
providerMatches: () => providerMatches,
|
|
71
|
+
readCodexNameSlots: () => readCodexNameSlots,
|
|
72
|
+
readCopilotNameSlots: () => readCopilotNameSlots,
|
|
73
|
+
readCursorCliNameSlots: () => readCursorCliNameSlots,
|
|
74
|
+
readCursorIdeNameSlots: () => readCursorIdeNameSlots,
|
|
68
75
|
readGitBranch: () => readGitBranch,
|
|
69
76
|
readSidecar: () => readSidecar,
|
|
70
77
|
resetDefaultScanner: () => resetDefaultScanner,
|
|
71
78
|
resolveConfigDir: () => resolveConfigDir,
|
|
79
|
+
resolveSessionName: () => resolveSessionName,
|
|
72
80
|
resolveTier: () => resolveTier,
|
|
73
81
|
saveProfiles: () => saveProfiles,
|
|
74
82
|
scan: () => scan,
|
|
75
83
|
search: () => search,
|
|
84
|
+
setCursorStateDb: () => setCursorStateDb,
|
|
76
85
|
setLogger: () => setLogger,
|
|
77
86
|
sidecarPath: () => sidecarPath,
|
|
78
87
|
unwrapCursorUserText: () => unwrapCursorUserText
|
|
@@ -431,13 +440,329 @@ function toIndexDoc(meta, searchContent) {
|
|
|
431
440
|
};
|
|
432
441
|
}
|
|
433
442
|
|
|
434
|
-
// src/
|
|
443
|
+
// src/name-stores.ts
|
|
444
|
+
var import_better_sqlite3 = __toESM(require("better-sqlite3"), 1);
|
|
435
445
|
var import_fs2 = require("fs");
|
|
436
|
-
var
|
|
446
|
+
var import_path2 = require("path");
|
|
447
|
+
|
|
448
|
+
// src/tags.ts
|
|
449
|
+
var SYSTEM_TAGS = [
|
|
450
|
+
"system-reminder",
|
|
451
|
+
"command-name",
|
|
452
|
+
"command-message",
|
|
453
|
+
"command-args",
|
|
454
|
+
"ide_selection",
|
|
455
|
+
"ide_opened_file",
|
|
456
|
+
"local-command-stdout",
|
|
457
|
+
"local-command-caveat",
|
|
458
|
+
"retrieval_status",
|
|
459
|
+
"task_id",
|
|
460
|
+
"task_type",
|
|
461
|
+
"task-id",
|
|
462
|
+
"task-notification",
|
|
463
|
+
"fast_mode_info",
|
|
464
|
+
"persisted-output",
|
|
465
|
+
"tool_use_error",
|
|
466
|
+
"user-prompt-submit-hook",
|
|
467
|
+
"thinking",
|
|
468
|
+
"ask_user",
|
|
469
|
+
"teammate-message"
|
|
470
|
+
];
|
|
471
|
+
var SYSTEM_TAG_RE = new RegExp(`<(${SYSTEM_TAGS.join("|")})[^>]*>[\\s\\S]*?<\\/\\1>`, "g");
|
|
472
|
+
var PASTED_CONTENT_RE = /<pasted_content id="[0-9a-f]{4}">([\s\S]*?)<\/pasted_content(?: id="[0-9a-f]{4}")?>/g;
|
|
473
|
+
function cleanSystemTags(text) {
|
|
474
|
+
return text.replace(SYSTEM_TAG_RE, "").replace(PASTED_CONTENT_RE, "$1").replace(/[^\S\n]+/g, " ").replace(/\n{3,}/g, "\n\n").trim();
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
// src/session-name.ts
|
|
478
|
+
var NAME_PRECEDENCE = [
|
|
479
|
+
"userTitle",
|
|
480
|
+
"toolTitle",
|
|
481
|
+
"lastPrompt",
|
|
482
|
+
"firstUserMessage",
|
|
483
|
+
"slug"
|
|
484
|
+
];
|
|
485
|
+
var CLAUDE_SYSTEM_PREFIXES = [
|
|
486
|
+
"<command-name>",
|
|
487
|
+
"<command-message>",
|
|
488
|
+
"<command-args>",
|
|
489
|
+
"<local-command-stdout>",
|
|
490
|
+
"<local-command-stderr>",
|
|
491
|
+
"<local-command-caveat>",
|
|
492
|
+
"<bash-input>",
|
|
493
|
+
"<bash-stdout>",
|
|
494
|
+
"<bash-stderr>",
|
|
495
|
+
"<system-reminder>",
|
|
496
|
+
"<task-notification>",
|
|
497
|
+
"<teammate-message",
|
|
498
|
+
"Another Claude session sent a message:",
|
|
499
|
+
"[Request interrupted by user"
|
|
500
|
+
];
|
|
501
|
+
var CODEX_SYSTEM_PREFIXES = [
|
|
502
|
+
"<environment_context>",
|
|
503
|
+
"# AGENTS.md instructions",
|
|
504
|
+
"<user_instructions>",
|
|
505
|
+
"<INSTRUCTIONS>",
|
|
506
|
+
"<external_codex_apps_open",
|
|
507
|
+
"<user_shell_command>",
|
|
508
|
+
"<turn_aborted>"
|
|
509
|
+
];
|
|
510
|
+
function isCodexInjectedContext(text) {
|
|
511
|
+
if (text.startsWith("# AGENTS.md") || text.includes("<INSTRUCTIONS>")) return true;
|
|
512
|
+
return text.startsWith("<permissions instructions>") || text.includes("Filesystem sandboxing defines");
|
|
513
|
+
}
|
|
514
|
+
var CODEX_IMAGE_TAG_RE = /<\/?image\b[^>]*>/g;
|
|
515
|
+
function normalizeCandidate(text, provider) {
|
|
516
|
+
let t = text.trim();
|
|
517
|
+
if (provider === "codex-cli") t = t.replace(CODEX_IMAGE_TAG_RE, "").trim();
|
|
518
|
+
const prefixes = provider === "claude-code" ? CLAUDE_SYSTEM_PREFIXES : provider === "codex-cli" ? CODEX_SYSTEM_PREFIXES : [];
|
|
519
|
+
if (prefixes.some((p) => t.startsWith(p))) return null;
|
|
520
|
+
if (provider === "codex-cli" && isCodexInjectedContext(t)) return null;
|
|
521
|
+
return cleanSystemTags(t) || null;
|
|
522
|
+
}
|
|
523
|
+
function isValidNameCandidate(text, provider) {
|
|
524
|
+
return normalizeCandidate(text, provider) !== null;
|
|
525
|
+
}
|
|
526
|
+
function resolveSessionName(slots) {
|
|
527
|
+
for (const slot of NAME_PRECEDENCE) {
|
|
528
|
+
const value = slots[slot];
|
|
529
|
+
if (value?.trim()) return { name: value, source: slot };
|
|
530
|
+
}
|
|
531
|
+
return { name: null, source: null };
|
|
532
|
+
}
|
|
533
|
+
function applyNameCandidate(slots, slot, raw, provider) {
|
|
534
|
+
if (typeof raw !== "string") return slots;
|
|
535
|
+
if (slot === "firstUserMessage" && slots.firstUserMessage !== void 0) return slots;
|
|
536
|
+
const text = normalizeCandidate(raw, provider);
|
|
537
|
+
return text === null ? slots : { ...slots, [slot]: text };
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
// src/name-stores.ts
|
|
541
|
+
function slotsFrom(provider, candidates) {
|
|
542
|
+
return candidates.reduce(
|
|
543
|
+
(slots, [slot, raw]) => applyNameCandidate(slots, slot, typeof raw === "string" ? raw : void 0, provider),
|
|
544
|
+
{}
|
|
545
|
+
);
|
|
546
|
+
}
|
|
547
|
+
function readJson(path) {
|
|
548
|
+
try {
|
|
549
|
+
return JSON.parse((0, import_fs2.readFileSync)(path, "utf8"));
|
|
550
|
+
} catch {
|
|
551
|
+
return void 0;
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
function queryOne(dbPath, sql, ...params) {
|
|
555
|
+
let db;
|
|
556
|
+
try {
|
|
557
|
+
db = new import_better_sqlite3.default(dbPath, { readonly: true, fileMustExist: true, timeout: 250 });
|
|
558
|
+
return db.prepare(sql).get(...params);
|
|
559
|
+
} catch (err) {
|
|
560
|
+
getLogger().debug({ dbPath, err }, "name store: query failed");
|
|
561
|
+
return void 0;
|
|
562
|
+
} finally {
|
|
563
|
+
db?.close();
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
var lastByIdCache = /* @__PURE__ */ new Map();
|
|
567
|
+
function lastValueById(path, idField, valueField) {
|
|
568
|
+
let sig;
|
|
569
|
+
try {
|
|
570
|
+
const s = (0, import_fs2.statSync)(path);
|
|
571
|
+
sig = `${s.mtimeMs}:${s.size}`;
|
|
572
|
+
} catch {
|
|
573
|
+
return /* @__PURE__ */ new Map();
|
|
574
|
+
}
|
|
575
|
+
const key = `${path}\0${idField}\0${valueField}`;
|
|
576
|
+
const cached = lastByIdCache.get(key);
|
|
577
|
+
if (cached?.sig === sig) return cached.map;
|
|
578
|
+
const map = /* @__PURE__ */ new Map();
|
|
579
|
+
try {
|
|
580
|
+
for (const line of (0, import_fs2.readFileSync)(path, "utf8").split("\n")) {
|
|
581
|
+
if (!line.trim()) continue;
|
|
582
|
+
try {
|
|
583
|
+
const row = JSON.parse(line);
|
|
584
|
+
const id = row[idField];
|
|
585
|
+
const value = row[valueField];
|
|
586
|
+
if (typeof id === "string" && typeof value === "string") map.set(id, value);
|
|
587
|
+
} catch {
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
} catch {
|
|
591
|
+
}
|
|
592
|
+
lastByIdCache.set(key, { sig, map });
|
|
593
|
+
return map;
|
|
594
|
+
}
|
|
595
|
+
function readCodexNameSlots(codexHome, id) {
|
|
596
|
+
const index = lastValueById((0, import_path2.join)(codexHome, "session_index.jsonl"), "id", "thread_name");
|
|
597
|
+
const history = lastValueById((0, import_path2.join)(codexHome, "history.jsonl"), "session_id", "text");
|
|
598
|
+
let title = index.get(id);
|
|
599
|
+
if (!index.has(id)) {
|
|
600
|
+
title = queryOne(
|
|
601
|
+
(0, import_path2.join)(codexHome, "state_5.sqlite"),
|
|
602
|
+
"SELECT name FROM threads WHERE id = ?",
|
|
603
|
+
id
|
|
604
|
+
)?.name;
|
|
605
|
+
}
|
|
606
|
+
return slotsFrom("codex-cli", [
|
|
607
|
+
["toolTitle", title],
|
|
608
|
+
["lastPrompt", history.get(id)]
|
|
609
|
+
]);
|
|
610
|
+
}
|
|
611
|
+
function readCursorCliNameSlots(chatsDir, id) {
|
|
612
|
+
let chat;
|
|
613
|
+
try {
|
|
614
|
+
chat = (0, import_fs2.readdirSync)(chatsDir).map((hash) => (0, import_path2.join)(chatsDir, hash, id)).find((p) => (0, import_fs2.existsSync)(p));
|
|
615
|
+
} catch {
|
|
616
|
+
}
|
|
617
|
+
if (!chat) return {};
|
|
618
|
+
const meta = readJson((0, import_path2.join)(chat, "meta.json"));
|
|
619
|
+
const history = readJson((0, import_path2.join)(chat, "prompt_history.json"));
|
|
620
|
+
let title = meta?.title;
|
|
621
|
+
if (typeof title !== "string" || !title.trim()) title = storeDbName((0, import_path2.join)(chat, "store.db"));
|
|
622
|
+
return slotsFrom("cursor", [
|
|
623
|
+
["toolTitle", title],
|
|
624
|
+
["lastPrompt", Array.isArray(history) ? history[0] : void 0]
|
|
625
|
+
]);
|
|
626
|
+
}
|
|
627
|
+
function storeDbName(dbPath) {
|
|
628
|
+
const row = queryOne(
|
|
629
|
+
dbPath,
|
|
630
|
+
"SELECT value FROM meta WHERE key = '0'"
|
|
631
|
+
);
|
|
632
|
+
if (!row) return void 0;
|
|
633
|
+
try {
|
|
634
|
+
const text = row.value.toString();
|
|
635
|
+
const json = /^(?:[0-9a-f]{2})+$/i.test(text) ? Buffer.from(text, "hex").toString("utf8") : text;
|
|
636
|
+
const name = JSON.parse(json).name;
|
|
637
|
+
return typeof name === "string" ? name : void 0;
|
|
638
|
+
} catch {
|
|
639
|
+
return void 0;
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
function readCursorIdeNameSlots(stateDbPath, id) {
|
|
643
|
+
const row = queryOne(
|
|
644
|
+
stateDbPath,
|
|
645
|
+
"SELECT json_extract(CAST(value AS TEXT), '$.name') AS name FROM cursorDiskKV WHERE key = ?",
|
|
646
|
+
`composerData:${id}`
|
|
647
|
+
);
|
|
648
|
+
return slotsFrom("cursor", [["toolTitle", row?.name]]);
|
|
649
|
+
}
|
|
650
|
+
function yamlScalar(text, key) {
|
|
651
|
+
const m = text.match(new RegExp(`^${key}:[ \\t]*(.*)$`, "m"));
|
|
652
|
+
const v = m?.[1].trim().replace(/^(["'])(.*)\1$/, "$2");
|
|
653
|
+
return v || void 0;
|
|
654
|
+
}
|
|
655
|
+
function readCopilotTitleSlots(sessionDir) {
|
|
656
|
+
const id = (0, import_path2.basename)(sessionDir);
|
|
657
|
+
let yaml = "";
|
|
658
|
+
try {
|
|
659
|
+
yaml = (0, import_fs2.readFileSync)((0, import_path2.join)(sessionDir, "workspace.yaml"), "utf8");
|
|
660
|
+
} catch {
|
|
661
|
+
}
|
|
662
|
+
const name = yamlScalar(yaml, "name");
|
|
663
|
+
if (name) {
|
|
664
|
+
return slotsFrom("copilot", [
|
|
665
|
+
[yamlScalar(yaml, "user_named") === "true" ? "userTitle" : "toolTitle", name]
|
|
666
|
+
]);
|
|
667
|
+
}
|
|
668
|
+
const row = queryOne(
|
|
669
|
+
(0, import_path2.join)((0, import_path2.dirname)((0, import_path2.dirname)(sessionDir)), "session-store.db"),
|
|
670
|
+
"SELECT summary FROM sessions WHERE id = ?",
|
|
671
|
+
id
|
|
672
|
+
);
|
|
673
|
+
return slotsFrom("copilot", [["toolTitle", row?.summary]]);
|
|
674
|
+
}
|
|
675
|
+
function readCopilotNameSlots(sessionDir) {
|
|
676
|
+
return {
|
|
677
|
+
...readCopilotTitleSlots(sessionDir),
|
|
678
|
+
...slotsFrom("copilot", [
|
|
679
|
+
["firstUserMessage", firstCopilotUserMessage((0, import_path2.join)(sessionDir, "events.jsonl"))]
|
|
680
|
+
])
|
|
681
|
+
};
|
|
682
|
+
}
|
|
683
|
+
function firstCopilotUserMessage(path) {
|
|
684
|
+
let fd;
|
|
685
|
+
try {
|
|
686
|
+
fd = (0, import_fs2.openSync)(path, "r");
|
|
687
|
+
} catch {
|
|
688
|
+
return void 0;
|
|
689
|
+
}
|
|
690
|
+
try {
|
|
691
|
+
const buf = Buffer.alloc(64 * 1024);
|
|
692
|
+
let pending = "";
|
|
693
|
+
for (let n = (0, import_fs2.readSync)(fd, buf, 0, buf.length, null); n > 0; n = (0, import_fs2.readSync)(fd, buf, 0, buf.length, null)) {
|
|
694
|
+
pending += buf.toString("utf8", 0, n);
|
|
695
|
+
const lines = pending.split("\n");
|
|
696
|
+
pending = lines.pop() ?? "";
|
|
697
|
+
for (const line of lines) {
|
|
698
|
+
try {
|
|
699
|
+
const e = JSON.parse(line);
|
|
700
|
+
if (e.type === "user.message" && typeof e.data?.content === "string")
|
|
701
|
+
return e.data.content;
|
|
702
|
+
} catch {
|
|
703
|
+
}
|
|
704
|
+
}
|
|
705
|
+
}
|
|
706
|
+
return void 0;
|
|
707
|
+
} catch {
|
|
708
|
+
return void 0;
|
|
709
|
+
} finally {
|
|
710
|
+
(0, import_fs2.closeSync)(fd);
|
|
711
|
+
}
|
|
712
|
+
}
|
|
713
|
+
function findUp(start, hasStore, levels) {
|
|
714
|
+
let dir = start;
|
|
715
|
+
for (let i = 0; i < levels; i++) {
|
|
716
|
+
if (hasStore(dir)) return dir;
|
|
717
|
+
const parent = (0, import_path2.dirname)(dir);
|
|
718
|
+
if (parent === dir) break;
|
|
719
|
+
dir = parent;
|
|
720
|
+
}
|
|
721
|
+
return null;
|
|
722
|
+
}
|
|
723
|
+
function codexNameSlotsFor(rolloutPath, id) {
|
|
724
|
+
const home = findUp(
|
|
725
|
+
(0, import_path2.dirname)(rolloutPath),
|
|
726
|
+
(d) => ["session_index.jsonl", "history.jsonl", "state_5.sqlite"].some(
|
|
727
|
+
(f) => (0, import_fs2.existsSync)((0, import_path2.join)(d, f))
|
|
728
|
+
),
|
|
729
|
+
6
|
|
730
|
+
);
|
|
731
|
+
return home ? readCodexNameSlots(home, id) : {};
|
|
732
|
+
}
|
|
733
|
+
var cursorStateDb;
|
|
734
|
+
function setCursorStateDb(path) {
|
|
735
|
+
cursorStateDb = path;
|
|
736
|
+
}
|
|
737
|
+
function cursorNameSlotsFor(transcriptPath, id) {
|
|
738
|
+
const home = findUp((0, import_path2.dirname)(transcriptPath), (d) => (0, import_fs2.existsSync)((0, import_path2.join)(d, "chats")), 6);
|
|
739
|
+
const cli = home ? readCursorCliNameSlots((0, import_path2.join)(home, "chats"), id) : {};
|
|
740
|
+
if (cli.toolTitle || !cursorStateDb) return cli;
|
|
741
|
+
return { ...cli, ...readCursorIdeNameSlots(cursorStateDb, id) };
|
|
742
|
+
}
|
|
743
|
+
function copilotNameSlotsFor(eventsPath) {
|
|
744
|
+
return readCopilotTitleSlots((0, import_path2.dirname)(eventsPath));
|
|
745
|
+
}
|
|
746
|
+
function nameStoreSlotsFor(provider, filePath, sessionId) {
|
|
747
|
+
switch (provider) {
|
|
748
|
+
case "codex-cli":
|
|
749
|
+
return codexNameSlotsFor(filePath, sessionId);
|
|
750
|
+
case "cursor":
|
|
751
|
+
return cursorNameSlotsFor(filePath, (0, import_path2.basename)(filePath, ".jsonl"));
|
|
752
|
+
case "copilot":
|
|
753
|
+
return copilotNameSlotsFor(filePath);
|
|
754
|
+
default:
|
|
755
|
+
return {};
|
|
756
|
+
}
|
|
757
|
+
}
|
|
758
|
+
|
|
759
|
+
// src/parser.ts
|
|
760
|
+
var import_fs3 = require("fs");
|
|
761
|
+
var import_path4 = require("path");
|
|
437
762
|
var import_readline = require("readline");
|
|
438
763
|
|
|
439
764
|
// src/persistent/metadata-reducer.ts
|
|
440
|
-
var
|
|
765
|
+
var import_path3 = require("path");
|
|
441
766
|
|
|
442
767
|
// src/providers/provider.ts
|
|
443
768
|
var CLAUDE_CODE_PROVIDER = "claude-code";
|
|
@@ -467,11 +792,36 @@ function providerMatches(stored, wanted) {
|
|
|
467
792
|
return a === b;
|
|
468
793
|
}
|
|
469
794
|
|
|
795
|
+
// src/persistent/claude-name-slots.ts
|
|
796
|
+
function userPromptText(entry) {
|
|
797
|
+
if (entry.isMeta || entry.isCompactSummary === true) return "";
|
|
798
|
+
const content = entry.message?.content;
|
|
799
|
+
if (typeof content === "string") return content;
|
|
800
|
+
if (!Array.isArray(content)) return "";
|
|
801
|
+
return content.map((b) => typeof b === "string" ? b : b?.type === "text" ? b.text : "").filter((t) => typeof t === "string" && t !== "").join(" ");
|
|
802
|
+
}
|
|
803
|
+
function applyClaudeNameEntry(slots, entry) {
|
|
804
|
+
const apply = (slot, raw) => applyNameCandidate(slots, slot, typeof raw === "string" ? raw : void 0, "claude-code");
|
|
805
|
+
if (entry.slug !== slots.slug) slots = apply("slug", entry.slug);
|
|
806
|
+
switch (entry.type) {
|
|
807
|
+
case "custom-title":
|
|
808
|
+
return apply("userTitle", entry.customTitle);
|
|
809
|
+
case "ai-title":
|
|
810
|
+
return apply("toolTitle", entry.aiTitle);
|
|
811
|
+
case "last-prompt":
|
|
812
|
+
return apply("lastPrompt", entry.lastPrompt);
|
|
813
|
+
case "user":
|
|
814
|
+
return slots.firstUserMessage === void 0 ? apply("firstUserMessage", userPromptText(entry)) : slots;
|
|
815
|
+
default:
|
|
816
|
+
return slots;
|
|
817
|
+
}
|
|
818
|
+
}
|
|
819
|
+
|
|
470
820
|
// src/persistent/metadata-reducer.ts
|
|
471
821
|
function initialReducerState() {
|
|
472
822
|
return {
|
|
473
823
|
sessionId: "",
|
|
474
|
-
|
|
824
|
+
nameSlots: {},
|
|
475
825
|
latestTimestamp: "",
|
|
476
826
|
cwd: "",
|
|
477
827
|
teamName: "",
|
|
@@ -497,7 +847,7 @@ function initialReducerState() {
|
|
|
497
847
|
function reduceLine(state, entry, tier) {
|
|
498
848
|
if (entry.cwd && !state.cwd) state.cwd = entry.cwd;
|
|
499
849
|
if (entry.sessionId && !state.sessionId) state.sessionId = entry.sessionId;
|
|
500
|
-
|
|
850
|
+
state.nameSlots = applyClaudeNameEntry(state.nameSlots, entry);
|
|
501
851
|
if (entry.teamName && !state.teamName) state.teamName = entry.teamName;
|
|
502
852
|
if (entry.agentId && !state.agentId) state.agentId = entry.agentId;
|
|
503
853
|
if (entry.isSidechain === true) state.isSidechain = true;
|
|
@@ -561,16 +911,16 @@ function finalizeMeta(state, filePath, account, tier) {
|
|
|
561
911
|
const isSubagent = isSidechain || isSubagentPath;
|
|
562
912
|
let parentSessionId = null;
|
|
563
913
|
if (isSubagentPath) {
|
|
564
|
-
const uuidDir = (0,
|
|
565
|
-
parentSessionId = (0,
|
|
914
|
+
const uuidDir = (0, import_path3.dirname)((0, import_path3.dirname)(filePath));
|
|
915
|
+
parentSessionId = (0, import_path3.join)((0, import_path3.dirname)(uuidDir), `${(0, import_path3.basename)(uuidDir)}.jsonl`);
|
|
566
916
|
}
|
|
567
917
|
const projectPath = state.cwd;
|
|
568
918
|
return {
|
|
569
919
|
id: filePath,
|
|
570
920
|
filePath,
|
|
571
921
|
provider: CLAUDE_CODE_PROVIDER,
|
|
572
|
-
sessionId: state.sessionId || (0,
|
|
573
|
-
sessionName: state.
|
|
922
|
+
sessionId: state.sessionId || (0, import_path3.basename)(filePath, ".jsonl"),
|
|
923
|
+
sessionName: resolveSessionName(state.nameSlots).name ?? "",
|
|
574
924
|
projectPath,
|
|
575
925
|
projectName: getShortProjectName(projectPath),
|
|
576
926
|
account,
|
|
@@ -596,50 +946,17 @@ function finalizeMeta(state, filePath, account, tier) {
|
|
|
596
946
|
};
|
|
597
947
|
}
|
|
598
948
|
var SUBAGENT_PATH_RE = /[\\/]subagents[\\/]/;
|
|
599
|
-
function deriveSessionNameFromFirstMessage(firstMessage) {
|
|
600
|
-
const firstLine = firstMessage?.text.split("\n", 1)[0]?.trim() ?? "";
|
|
601
|
-
return firstLine.slice(0, 80);
|
|
602
|
-
}
|
|
603
949
|
function getShortProjectName(fullPath) {
|
|
604
950
|
const parts = fullPath.split("/").filter(Boolean);
|
|
605
951
|
return parts.slice(-3).join("/");
|
|
606
952
|
}
|
|
607
953
|
|
|
608
|
-
// src/tags.ts
|
|
609
|
-
var SYSTEM_TAGS = [
|
|
610
|
-
"system-reminder",
|
|
611
|
-
"command-name",
|
|
612
|
-
"command-message",
|
|
613
|
-
"command-args",
|
|
614
|
-
"ide_selection",
|
|
615
|
-
"ide_opened_file",
|
|
616
|
-
"local-command-stdout",
|
|
617
|
-
"local-command-caveat",
|
|
618
|
-
"retrieval_status",
|
|
619
|
-
"task_id",
|
|
620
|
-
"task_type",
|
|
621
|
-
"task-id",
|
|
622
|
-
"task-notification",
|
|
623
|
-
"fast_mode_info",
|
|
624
|
-
"persisted-output",
|
|
625
|
-
"tool_use_error",
|
|
626
|
-
"user-prompt-submit-hook",
|
|
627
|
-
"thinking",
|
|
628
|
-
"ask_user",
|
|
629
|
-
"teammate-message"
|
|
630
|
-
];
|
|
631
|
-
var SYSTEM_TAG_RE = new RegExp(`<(${SYSTEM_TAGS.join("|")})[^>]*>[\\s\\S]*?<\\/\\1>`, "g");
|
|
632
|
-
var PASTED_CONTENT_RE = /<pasted_content id="[0-9a-f]{4}">([\s\S]*?)<\/pasted_content(?: id="[0-9a-f]{4}")?>/g;
|
|
633
|
-
function cleanSystemTags(text) {
|
|
634
|
-
return text.replace(SYSTEM_TAG_RE, "").replace(PASTED_CONTENT_RE, "$1").replace(/[^\S\n]+/g, " ").replace(/\n{3,}/g, "\n\n").trim();
|
|
635
|
-
}
|
|
636
|
-
|
|
637
954
|
// src/parser.ts
|
|
638
955
|
async function parseMeta(filePath, account, tier, onEntry) {
|
|
639
956
|
const log = getLogger();
|
|
640
957
|
log.trace({ filePath, account, tier: tier.name }, "parseMeta: start");
|
|
641
958
|
const state = initialReducerState();
|
|
642
|
-
const fileStream = (0,
|
|
959
|
+
const fileStream = (0, import_fs3.createReadStream)(filePath);
|
|
643
960
|
const rl = (0, import_readline.createInterface)({ input: fileStream, crlfDelay: Infinity });
|
|
644
961
|
try {
|
|
645
962
|
for await (const line of rl) {
|
|
@@ -676,7 +993,7 @@ async function parseConversation(filePath, account) {
|
|
|
676
993
|
const textParts = [];
|
|
677
994
|
const turnDurations = [];
|
|
678
995
|
const state = initialConvState();
|
|
679
|
-
const fileStream = (0,
|
|
996
|
+
const fileStream = (0, import_fs3.createReadStream)(filePath);
|
|
680
997
|
const rl = (0, import_readline.createInterface)({ input: fileStream, crlfDelay: Infinity });
|
|
681
998
|
try {
|
|
682
999
|
for await (const line of rl) {
|
|
@@ -699,7 +1016,7 @@ async function parseConversation(filePath, account) {
|
|
|
699
1016
|
const message = reduceConvLine(state, entry);
|
|
700
1017
|
if (message) {
|
|
701
1018
|
messages.push(message);
|
|
702
|
-
if (message.text) textParts.push(message.text);
|
|
1019
|
+
if (message.text && !message.isCompactSummary) textParts.push(message.text);
|
|
703
1020
|
}
|
|
704
1021
|
}
|
|
705
1022
|
} catch (err) {
|
|
@@ -720,8 +1037,8 @@ async function parseConversation(filePath, account) {
|
|
|
720
1037
|
filePath,
|
|
721
1038
|
projectPath: state.cwd,
|
|
722
1039
|
projectName: getShortProjectName2(state.cwd),
|
|
723
|
-
sessionId: state.sessionId || (0,
|
|
724
|
-
sessionName: state.
|
|
1040
|
+
sessionId: state.sessionId || (0, import_path4.basename)(filePath, ".jsonl"),
|
|
1041
|
+
sessionName: resolveSessionName(state.nameSlots).name ?? "",
|
|
725
1042
|
messages,
|
|
726
1043
|
fullText: textParts.join(" "),
|
|
727
1044
|
timestamp: state.latestTimestamp || (/* @__PURE__ */ new Date()).toISOString(),
|
|
@@ -831,7 +1148,7 @@ function initialConvState() {
|
|
|
831
1148
|
return {
|
|
832
1149
|
cwd: "",
|
|
833
1150
|
sessionId: "",
|
|
834
|
-
|
|
1151
|
+
nameSlots: {},
|
|
835
1152
|
latestTimestamp: "",
|
|
836
1153
|
lastPrompt: "",
|
|
837
1154
|
pendingToolUses: {},
|
|
@@ -841,7 +1158,7 @@ function initialConvState() {
|
|
|
841
1158
|
function reduceConvLine(state, entry) {
|
|
842
1159
|
if (entry.cwd && !state.cwd) state.cwd = entry.cwd;
|
|
843
1160
|
if (entry.sessionId && !state.sessionId) state.sessionId = entry.sessionId;
|
|
844
|
-
|
|
1161
|
+
state.nameSlots = applyClaudeNameEntry(state.nameSlots, entry);
|
|
845
1162
|
if (entry.timestamp) {
|
|
846
1163
|
const ts = entry.timestamp;
|
|
847
1164
|
if (!state.latestTimestamp || ts > state.latestTimestamp) state.latestTimestamp = ts;
|
|
@@ -949,7 +1266,7 @@ function applyTeamInfo(messages, state) {
|
|
|
949
1266
|
}
|
|
950
1267
|
|
|
951
1268
|
// src/persistent/sidecar.ts
|
|
952
|
-
var
|
|
1269
|
+
var import_fs4 = require("fs");
|
|
953
1270
|
var SIDECAR_VERSION = 1;
|
|
954
1271
|
function sidecarPath(jsonlPath) {
|
|
955
1272
|
return `${jsonlPath}.idx.json`;
|
|
@@ -975,14 +1292,14 @@ function buildSidecar(meta, cursor, updatedAt) {
|
|
|
975
1292
|
}
|
|
976
1293
|
function writeSidecar(jsonlPath, sidecar) {
|
|
977
1294
|
try {
|
|
978
|
-
(0,
|
|
1295
|
+
(0, import_fs4.writeFileSync)(sidecarPath(jsonlPath), JSON.stringify(sidecar, null, 2));
|
|
979
1296
|
} catch (err) {
|
|
980
1297
|
getLogger().warn({ jsonlPath, err }, "sidecar: write failed");
|
|
981
1298
|
}
|
|
982
1299
|
}
|
|
983
1300
|
function readSidecar(jsonlPath) {
|
|
984
1301
|
try {
|
|
985
|
-
return JSON.parse((0,
|
|
1302
|
+
return JSON.parse((0, import_fs4.readFileSync)(sidecarPath(jsonlPath), "utf-8"));
|
|
986
1303
|
} catch {
|
|
987
1304
|
return null;
|
|
988
1305
|
}
|
|
@@ -991,19 +1308,19 @@ function readSidecar(jsonlPath) {
|
|
|
991
1308
|
// src/profiles.ts
|
|
992
1309
|
var import_promises = require("fs/promises");
|
|
993
1310
|
var import_os = require("os");
|
|
994
|
-
var
|
|
1311
|
+
var import_path5 = require("path");
|
|
995
1312
|
var PROFILES_FILE = "profiles.json";
|
|
996
1313
|
function resolveConfigDir(configDir) {
|
|
997
1314
|
return configDir.replace(/^~/, (0, import_os.homedir)());
|
|
998
1315
|
}
|
|
999
1316
|
function getProjectsDir(profile) {
|
|
1000
|
-
return (0,
|
|
1317
|
+
return (0, import_path5.join)(resolveConfigDir(profile.configDir), "projects");
|
|
1001
1318
|
}
|
|
1002
1319
|
async function detectDefaultProfile() {
|
|
1003
1320
|
return {
|
|
1004
1321
|
id: "default",
|
|
1005
1322
|
label: "Default",
|
|
1006
|
-
configDir: (0,
|
|
1323
|
+
configDir: (0, import_path5.join)((0, import_os.homedir)(), ".claude"),
|
|
1007
1324
|
enabled: true,
|
|
1008
1325
|
emoji: "\u{1F916}"
|
|
1009
1326
|
};
|
|
@@ -1012,7 +1329,7 @@ async function loadProfiles(configPath) {
|
|
|
1012
1329
|
const log = getLogger();
|
|
1013
1330
|
try {
|
|
1014
1331
|
const resolved = resolveConfigDir(configPath);
|
|
1015
|
-
const data = await (0, import_promises.readFile)((0,
|
|
1332
|
+
const data = await (0, import_promises.readFile)((0, import_path5.join)(resolved, PROFILES_FILE), "utf-8");
|
|
1016
1333
|
const profiles = JSON.parse(data);
|
|
1017
1334
|
log.debug({ configPath, count: profiles.length }, "profiles: loaded");
|
|
1018
1335
|
return profiles;
|
|
@@ -1025,21 +1342,21 @@ async function loadProfiles(configPath) {
|
|
|
1025
1342
|
async function saveProfiles(profiles, configPath) {
|
|
1026
1343
|
const resolved = resolveConfigDir(configPath);
|
|
1027
1344
|
await (0, import_promises.mkdir)(resolved, { recursive: true });
|
|
1028
|
-
await (0, import_promises.writeFile)((0,
|
|
1345
|
+
await (0, import_promises.writeFile)((0, import_path5.join)(resolved, PROFILES_FILE), JSON.stringify(profiles, null, 2));
|
|
1029
1346
|
getLogger().debug({ configPath, count: profiles.length }, "profiles: saved");
|
|
1030
1347
|
}
|
|
1031
1348
|
|
|
1032
1349
|
// src/providers/codex-cli.ts
|
|
1033
1350
|
var import_fast_glob = __toESM(require("fast-glob"), 1);
|
|
1034
|
-
var
|
|
1351
|
+
var import_fs5 = require("fs");
|
|
1035
1352
|
var import_promises2 = require("fs/promises");
|
|
1036
|
-
var
|
|
1353
|
+
var import_path7 = require("path");
|
|
1037
1354
|
var import_readline2 = require("readline");
|
|
1038
1355
|
|
|
1039
1356
|
// src/canonical-path.ts
|
|
1040
|
-
var
|
|
1357
|
+
var import_path6 = require("path");
|
|
1041
1358
|
function canonicalPath(p) {
|
|
1042
|
-
return
|
|
1359
|
+
return import_path6.sep === "\\" ? p.replace(/\//g, "\\") : p;
|
|
1043
1360
|
}
|
|
1044
1361
|
|
|
1045
1362
|
// src/providers/codex-cli.ts
|
|
@@ -1099,6 +1416,7 @@ var CodexCliProvider = class {
|
|
|
1099
1416
|
isSubagent: false,
|
|
1100
1417
|
parentSessionUuid: null,
|
|
1101
1418
|
firstUser: null,
|
|
1419
|
+
nameSlots: {},
|
|
1102
1420
|
lastUser: null,
|
|
1103
1421
|
lastAssistant: null,
|
|
1104
1422
|
toolNames: [],
|
|
@@ -1261,6 +1579,7 @@ function reduceCodexEntry(acc, entry, tier) {
|
|
|
1261
1579
|
const snapshot = { text: text.slice(0, 200), timestamp: ts };
|
|
1262
1580
|
if (sender === "user") {
|
|
1263
1581
|
if (!acc.firstUser) acc.firstUser = snapshot;
|
|
1582
|
+
acc.nameSlots = applyNameCandidate(acc.nameSlots, "firstUserMessage", text, CODEX_CLI_PROVIDER);
|
|
1264
1583
|
acc.lastUser = snapshot;
|
|
1265
1584
|
} else {
|
|
1266
1585
|
acc.lastAssistant = snapshot;
|
|
@@ -1278,7 +1597,7 @@ function reduceCodexEntry(acc, entry, tier) {
|
|
|
1278
1597
|
}
|
|
1279
1598
|
function finalizeCodexMeta(acc, filePath, account, tier) {
|
|
1280
1599
|
if (acc.messageCount === 0) return null;
|
|
1281
|
-
const sessionId = acc.sessionId || (0,
|
|
1600
|
+
const sessionId = acc.sessionId || (0, import_path7.basename)(filePath, ".jsonl");
|
|
1282
1601
|
const projectPath = acc.cwd;
|
|
1283
1602
|
const kind = acc.lastAssistant === null && acc.toolNames.length > 0 ? "task" : "conversation";
|
|
1284
1603
|
return {
|
|
@@ -1288,10 +1607,7 @@ function finalizeCodexMeta(acc, filePath, account, tier) {
|
|
|
1288
1607
|
kind,
|
|
1289
1608
|
externalSessionId: acc.sessionId || void 0,
|
|
1290
1609
|
sessionId,
|
|
1291
|
-
|
|
1292
|
-
// is the only human-readable name source. Only useful because the injected
|
|
1293
|
-
// AGENTS.md turn is skipped above — otherwise every title would be that blob.
|
|
1294
|
-
sessionName: deriveSessionNameFromFirstMessage(acc.firstUser),
|
|
1610
|
+
sessionName: resolveSessionName({ ...acc.nameSlots, ...codexNameSlotsFor(filePath, acc.sessionId) }).name ?? "",
|
|
1295
1611
|
projectPath,
|
|
1296
1612
|
projectName: getShortProjectName3(projectPath),
|
|
1297
1613
|
account,
|
|
@@ -1314,10 +1630,6 @@ function finalizeCodexMeta(acc, filePath, account, tier) {
|
|
|
1314
1630
|
lastPrompt: acc.lastUser?.text || void 0
|
|
1315
1631
|
};
|
|
1316
1632
|
}
|
|
1317
|
-
function isCodexInjectedContext(text) {
|
|
1318
|
-
if (text.startsWith("# AGENTS.md") || text.includes("<INSTRUCTIONS>")) return true;
|
|
1319
|
-
return text.startsWith("<permissions instructions>") || text.includes("Filesystem sandboxing defines");
|
|
1320
|
-
}
|
|
1321
1633
|
function getShortProjectName3(fullPath) {
|
|
1322
1634
|
return fullPath.split("/").filter(Boolean).slice(-3).join("/");
|
|
1323
1635
|
}
|
|
@@ -1340,7 +1652,8 @@ async function parseCodexConversation(filePath, account) {
|
|
|
1340
1652
|
let cwd = "";
|
|
1341
1653
|
let latestTimestamp = "";
|
|
1342
1654
|
let lastUserText = "";
|
|
1343
|
-
|
|
1655
|
+
let nameSlots = {};
|
|
1656
|
+
const rl = (0, import_readline2.createInterface)({ input: (0, import_fs5.createReadStream)(filePath), crlfDelay: Infinity });
|
|
1344
1657
|
try {
|
|
1345
1658
|
for await (const line of rl) {
|
|
1346
1659
|
if (!line.trim()) continue;
|
|
@@ -1364,7 +1677,15 @@ async function parseCodexConversation(filePath, account) {
|
|
|
1364
1677
|
messages.push(message);
|
|
1365
1678
|
if (!message.text) continue;
|
|
1366
1679
|
textParts.push(message.text);
|
|
1367
|
-
if (message.role === "user")
|
|
1680
|
+
if (message.role === "user") {
|
|
1681
|
+
lastUserText = message.text;
|
|
1682
|
+
nameSlots = applyNameCandidate(
|
|
1683
|
+
nameSlots,
|
|
1684
|
+
"firstUserMessage",
|
|
1685
|
+
message.text,
|
|
1686
|
+
CODEX_CLI_PROVIDER
|
|
1687
|
+
);
|
|
1688
|
+
}
|
|
1368
1689
|
}
|
|
1369
1690
|
} catch (err) {
|
|
1370
1691
|
log.warn({ filePath, err }, "parseCodexConversation: read failed");
|
|
@@ -1376,8 +1697,8 @@ async function parseCodexConversation(filePath, account) {
|
|
|
1376
1697
|
filePath,
|
|
1377
1698
|
projectPath: cwd,
|
|
1378
1699
|
projectName: getShortProjectName3(cwd),
|
|
1379
|
-
sessionId: sessionId || (0,
|
|
1380
|
-
sessionName: "",
|
|
1700
|
+
sessionId: sessionId || (0, import_path7.basename)(filePath, ".jsonl"),
|
|
1701
|
+
sessionName: resolveSessionName({ ...nameSlots, ...codexNameSlotsFor(filePath, sessionId) }).name ?? "",
|
|
1381
1702
|
messages,
|
|
1382
1703
|
fullText: textParts.join(" "),
|
|
1383
1704
|
timestamp: latestTimestamp || (/* @__PURE__ */ new Date()).toISOString(),
|
|
@@ -1389,9 +1710,9 @@ async function parseCodexConversation(filePath, account) {
|
|
|
1389
1710
|
|
|
1390
1711
|
// src/providers/copilot.ts
|
|
1391
1712
|
var import_fast_glob2 = __toESM(require("fast-glob"), 1);
|
|
1392
|
-
var
|
|
1713
|
+
var import_fs6 = require("fs");
|
|
1393
1714
|
var import_promises3 = require("fs/promises");
|
|
1394
|
-
var
|
|
1715
|
+
var import_path8 = require("path");
|
|
1395
1716
|
var import_readline3 = require("readline");
|
|
1396
1717
|
var SESSION_START = "session.start";
|
|
1397
1718
|
var USER_MESSAGE = "user.message";
|
|
@@ -1445,6 +1766,7 @@ var CopilotProvider = class {
|
|
|
1445
1766
|
messageCount: 0,
|
|
1446
1767
|
lastMessageSender: "user",
|
|
1447
1768
|
firstUser: null,
|
|
1769
|
+
nameSlots: {},
|
|
1448
1770
|
lastUser: null,
|
|
1449
1771
|
lastAssistant: null,
|
|
1450
1772
|
toolNames: [],
|
|
@@ -1552,6 +1874,7 @@ function reduceCopilotEntry(acc, entry, tier) {
|
|
|
1552
1874
|
const snapshot = { text: text.slice(0, 200), timestamp };
|
|
1553
1875
|
if (role === "user") {
|
|
1554
1876
|
if (!acc.firstUser) acc.firstUser = snapshot;
|
|
1877
|
+
acc.nameSlots = applyNameCandidate(acc.nameSlots, "firstUserMessage", text, COPILOT_PROVIDER);
|
|
1555
1878
|
acc.lastUser = snapshot;
|
|
1556
1879
|
} else {
|
|
1557
1880
|
acc.lastAssistant = snapshot;
|
|
@@ -1578,7 +1901,7 @@ function finalizeCopilotMeta(acc, filePath, account, tier) {
|
|
|
1578
1901
|
kind,
|
|
1579
1902
|
externalSessionId: sessionId,
|
|
1580
1903
|
sessionId,
|
|
1581
|
-
sessionName:
|
|
1904
|
+
sessionName: resolveSessionName({ ...acc.nameSlots, ...copilotNameSlotsFor(filePath) }).name ?? "",
|
|
1582
1905
|
projectPath: acc.cwd,
|
|
1583
1906
|
projectName: getShortProjectName4(acc.cwd),
|
|
1584
1907
|
account,
|
|
@@ -1600,14 +1923,14 @@ function finalizeCopilotMeta(acc, filePath, account, tier) {
|
|
|
1600
1923
|
};
|
|
1601
1924
|
}
|
|
1602
1925
|
function sessionIdFromPath(filePath) {
|
|
1603
|
-
return (0,
|
|
1926
|
+
return (0, import_path8.basename)((0, import_path8.dirname)(filePath));
|
|
1604
1927
|
}
|
|
1605
1928
|
function getShortProjectName4(fullPath) {
|
|
1606
1929
|
return fullPath.split(/[/\\]/).filter(Boolean).slice(-3).join("/");
|
|
1607
1930
|
}
|
|
1608
1931
|
function fileMtimeIso(filePath) {
|
|
1609
1932
|
try {
|
|
1610
|
-
return new Date((0,
|
|
1933
|
+
return new Date((0, import_fs6.statSync)(filePath).mtimeMs).toISOString();
|
|
1611
1934
|
} catch {
|
|
1612
1935
|
return (/* @__PURE__ */ new Date()).toISOString();
|
|
1613
1936
|
}
|
|
@@ -1620,7 +1943,8 @@ async function parseCopilotConversation(filePath, account) {
|
|
|
1620
1943
|
let cwd = "";
|
|
1621
1944
|
let latestTimestamp = "";
|
|
1622
1945
|
let lastUserText = "";
|
|
1623
|
-
|
|
1946
|
+
let nameSlots = {};
|
|
1947
|
+
const rl = (0, import_readline3.createInterface)({ input: (0, import_fs6.createReadStream)(filePath), crlfDelay: Infinity });
|
|
1624
1948
|
try {
|
|
1625
1949
|
for await (const line of rl) {
|
|
1626
1950
|
if (!line.trim()) continue;
|
|
@@ -1644,7 +1968,15 @@ async function parseCopilotConversation(filePath, account) {
|
|
|
1644
1968
|
messages.push(message);
|
|
1645
1969
|
if (!message.text) continue;
|
|
1646
1970
|
textParts.push(message.text);
|
|
1647
|
-
if (message.role === "user")
|
|
1971
|
+
if (message.role === "user") {
|
|
1972
|
+
lastUserText = message.text;
|
|
1973
|
+
nameSlots = applyNameCandidate(
|
|
1974
|
+
nameSlots,
|
|
1975
|
+
"firstUserMessage",
|
|
1976
|
+
message.text,
|
|
1977
|
+
COPILOT_PROVIDER
|
|
1978
|
+
);
|
|
1979
|
+
}
|
|
1648
1980
|
}
|
|
1649
1981
|
} catch (err) {
|
|
1650
1982
|
log.warn({ filePath, err }, "parseCopilotConversation: read failed");
|
|
@@ -1657,7 +1989,7 @@ async function parseCopilotConversation(filePath, account) {
|
|
|
1657
1989
|
projectPath: cwd,
|
|
1658
1990
|
projectName: getShortProjectName4(cwd),
|
|
1659
1991
|
sessionId: sessionId || sessionIdFromPath(filePath),
|
|
1660
|
-
sessionName: "",
|
|
1992
|
+
sessionName: resolveSessionName({ ...nameSlots, ...copilotNameSlotsFor(filePath) }).name ?? "",
|
|
1661
1993
|
messages,
|
|
1662
1994
|
fullText: textParts.join(" "),
|
|
1663
1995
|
timestamp: latestTimestamp || fileMtimeIso(filePath),
|
|
@@ -1670,9 +2002,9 @@ async function parseCopilotConversation(filePath, account) {
|
|
|
1670
2002
|
// src/providers/cursor.ts
|
|
1671
2003
|
var import_crypto = require("crypto");
|
|
1672
2004
|
var import_fast_glob3 = __toESM(require("fast-glob"), 1);
|
|
1673
|
-
var
|
|
2005
|
+
var import_fs7 = require("fs");
|
|
1674
2006
|
var import_promises4 = require("fs/promises");
|
|
1675
|
-
var
|
|
2007
|
+
var import_path9 = require("path");
|
|
1676
2008
|
var import_readline4 = require("readline");
|
|
1677
2009
|
var TIMESTAMP_RE = /<timestamp>\s*([\s\S]*?)\s*<\/timestamp>/;
|
|
1678
2010
|
var USER_QUERY_RE = /<user_query>\s*([\s\S]*?)\s*<\/user_query>/;
|
|
@@ -1731,6 +2063,7 @@ var CursorProvider = class {
|
|
|
1731
2063
|
parentSessionUuid: null,
|
|
1732
2064
|
subagentId: null,
|
|
1733
2065
|
firstUser: null,
|
|
2066
|
+
nameSlots: {},
|
|
1734
2067
|
lastUser: null,
|
|
1735
2068
|
lastAssistant: null,
|
|
1736
2069
|
isImportedFromClaude: false,
|
|
@@ -1797,6 +2130,15 @@ function noteImportProvenance(acc, entry, text) {
|
|
|
1797
2130
|
acc.isImportedFromCodex = true;
|
|
1798
2131
|
}
|
|
1799
2132
|
}
|
|
2133
|
+
function cursorUserQuery(content) {
|
|
2134
|
+
const texts = typeof content === "string" ? [content] : Array.isArray(content) ? content : [];
|
|
2135
|
+
for (const item of texts) {
|
|
2136
|
+
const text = typeof item === "string" ? item : item?.text;
|
|
2137
|
+
const query = typeof text === "string" ? text.match(USER_QUERY_RE) : null;
|
|
2138
|
+
if (query) return query[1];
|
|
2139
|
+
}
|
|
2140
|
+
return void 0;
|
|
2141
|
+
}
|
|
1800
2142
|
function unwrapCursorUserText(text) {
|
|
1801
2143
|
const query = text.match(USER_QUERY_RE);
|
|
1802
2144
|
const body = query ? query[1] : text.replace(TIMESTAMP_RE, "");
|
|
@@ -1934,6 +2276,14 @@ function reduceCursorEntry(acc, entry, tier) {
|
|
|
1934
2276
|
collectCursorToolNames(content, acc.toolNames);
|
|
1935
2277
|
const text = textHint;
|
|
1936
2278
|
if (!text) return;
|
|
2279
|
+
if (entry.role === "user") {
|
|
2280
|
+
acc.nameSlots = applyNameCandidate(
|
|
2281
|
+
acc.nameSlots,
|
|
2282
|
+
"firstUserMessage",
|
|
2283
|
+
cursorUserQuery(content),
|
|
2284
|
+
CURSOR_PROVIDER
|
|
2285
|
+
);
|
|
2286
|
+
}
|
|
1937
2287
|
foldCursorMessage(acc, entry.role, text, firstTimestampHint(content), tier);
|
|
1938
2288
|
return;
|
|
1939
2289
|
}
|
|
@@ -1952,7 +2302,7 @@ function reduceCursorEntry(acc, entry, tier) {
|
|
|
1952
2302
|
}
|
|
1953
2303
|
function finalizeCursorMeta(acc, filePath, account, tier) {
|
|
1954
2304
|
if (acc.messageCount === 0) return null;
|
|
1955
|
-
const sessionId = (0,
|
|
2305
|
+
const sessionId = (0, import_path9.basename)(filePath, ".jsonl");
|
|
1956
2306
|
const isSubagent = SUBAGENT_PATH_RE2.test(filePath);
|
|
1957
2307
|
const parent = isSubagent ? parentFromSubagentPath(filePath) : null;
|
|
1958
2308
|
const { projectPath, projectName } = projectFromCursorPath(filePath);
|
|
@@ -1965,7 +2315,7 @@ function finalizeCursorMeta(acc, filePath, account, tier) {
|
|
|
1965
2315
|
kind,
|
|
1966
2316
|
externalSessionId: sessionId,
|
|
1967
2317
|
sessionId,
|
|
1968
|
-
sessionName:
|
|
2318
|
+
sessionName: resolveSessionName({ ...acc.nameSlots, ...cursorNameSlotsFor(filePath, sessionId) }).name ?? "",
|
|
1969
2319
|
projectPath,
|
|
1970
2320
|
projectName,
|
|
1971
2321
|
account,
|
|
@@ -1991,20 +2341,20 @@ function finalizeCursorMeta(acc, filePath, account, tier) {
|
|
|
1991
2341
|
};
|
|
1992
2342
|
}
|
|
1993
2343
|
function parentFromSubagentPath(filePath) {
|
|
1994
|
-
const subagentsDir = (0,
|
|
1995
|
-
const parentDir = (0,
|
|
1996
|
-
const parentSessionUuid = (0,
|
|
2344
|
+
const subagentsDir = (0, import_path9.dirname)(filePath);
|
|
2345
|
+
const parentDir = (0, import_path9.dirname)(subagentsDir);
|
|
2346
|
+
const parentSessionUuid = (0, import_path9.basename)(parentDir);
|
|
1997
2347
|
if (!parentSessionUuid) return null;
|
|
1998
2348
|
return {
|
|
1999
2349
|
parentSessionUuid,
|
|
2000
|
-
parentFilePath: canonicalPath((0,
|
|
2350
|
+
parentFilePath: canonicalPath((0, import_path9.join)(parentDir, `${parentSessionUuid}.jsonl`))
|
|
2001
2351
|
};
|
|
2002
2352
|
}
|
|
2003
2353
|
function projectFromCursorPath(filePath) {
|
|
2004
2354
|
const parts = filePath.split(/[/\\]/);
|
|
2005
2355
|
const idx = parts.lastIndexOf("agent-transcripts");
|
|
2006
|
-
const cursorProjectDir = idx > 0 ? parts.slice(0, idx).join(
|
|
2007
|
-
const slug = (0,
|
|
2356
|
+
const cursorProjectDir = idx > 0 ? parts.slice(0, idx).join(import_path9.sep) : (0, import_path9.dirname)((0, import_path9.dirname)(filePath));
|
|
2357
|
+
const slug = (0, import_path9.basename)(cursorProjectDir);
|
|
2008
2358
|
const decoded = decodeCursorProjectSlug(slug);
|
|
2009
2359
|
const projectPath = decoded ?? cursorProjectDir;
|
|
2010
2360
|
return { projectPath, projectName: getShortProjectName5(projectPath) || slug };
|
|
@@ -2014,11 +2364,11 @@ function decodeCursorProjectSlug(slug) {
|
|
|
2014
2364
|
const segments = slug.split("-");
|
|
2015
2365
|
if (segments.length === 0) return null;
|
|
2016
2366
|
const rooted = slug.startsWith("Users-") || slug.startsWith("home-") || /^[A-Za-z]-/.test(slug);
|
|
2017
|
-
let acc = rooted ?
|
|
2367
|
+
let acc = rooted ? import_path9.sep : "";
|
|
2018
2368
|
let i = 0;
|
|
2019
2369
|
if (rooted && segments[0] === "Users") {
|
|
2020
|
-
const users = `${
|
|
2021
|
-
if (!(0,
|
|
2370
|
+
const users = `${import_path9.sep}Users`;
|
|
2371
|
+
if (!(0, import_fs7.existsSync)(users)) return null;
|
|
2022
2372
|
acc = users;
|
|
2023
2373
|
i = 1;
|
|
2024
2374
|
}
|
|
@@ -2026,9 +2376,9 @@ function decodeCursorProjectSlug(slug) {
|
|
|
2026
2376
|
let found = null;
|
|
2027
2377
|
let next = i + 1;
|
|
2028
2378
|
for (let j = segments.length; j > i; j--) {
|
|
2029
|
-
const candidate = (0,
|
|
2379
|
+
const candidate = (0, import_path9.join)(acc, segments.slice(i, j).join("-"));
|
|
2030
2380
|
try {
|
|
2031
|
-
if ((0,
|
|
2381
|
+
if ((0, import_fs7.existsSync)(candidate) && (0, import_fs7.statSync)(candidate).isDirectory()) {
|
|
2032
2382
|
found = candidate;
|
|
2033
2383
|
next = j;
|
|
2034
2384
|
break;
|
|
@@ -2047,18 +2397,27 @@ function getShortProjectName5(fullPath) {
|
|
|
2047
2397
|
}
|
|
2048
2398
|
function fileMtimeIso2(filePath) {
|
|
2049
2399
|
try {
|
|
2050
|
-
return new Date((0,
|
|
2400
|
+
return new Date((0, import_fs7.statSync)(filePath).mtimeMs).toISOString();
|
|
2051
2401
|
} catch {
|
|
2052
2402
|
return (/* @__PURE__ */ new Date()).toISOString();
|
|
2053
2403
|
}
|
|
2054
2404
|
}
|
|
2405
|
+
function cursorLineContent(line) {
|
|
2406
|
+
try {
|
|
2407
|
+
const entry = JSON.parse(line);
|
|
2408
|
+
return entry.message?.content ?? entry.content;
|
|
2409
|
+
} catch {
|
|
2410
|
+
return void 0;
|
|
2411
|
+
}
|
|
2412
|
+
}
|
|
2055
2413
|
async function parseCursorConversation(filePath, account) {
|
|
2056
2414
|
const log = getLogger();
|
|
2057
2415
|
const messages = [];
|
|
2058
2416
|
const textParts = [];
|
|
2059
2417
|
let latestTimestamp = "";
|
|
2060
2418
|
let lastUserText = "";
|
|
2061
|
-
|
|
2419
|
+
let nameSlots = {};
|
|
2420
|
+
const rl = (0, import_readline4.createInterface)({ input: (0, import_fs7.createReadStream)(filePath), crlfDelay: Infinity });
|
|
2062
2421
|
try {
|
|
2063
2422
|
for await (const line of rl) {
|
|
2064
2423
|
const message = parseCursorJsonlLine(line, messages.length);
|
|
@@ -2069,7 +2428,17 @@ async function parseCursorConversation(filePath, account) {
|
|
|
2069
2428
|
messages.push(message);
|
|
2070
2429
|
if (!message.text) continue;
|
|
2071
2430
|
textParts.push(message.text);
|
|
2072
|
-
if (message.role === "user")
|
|
2431
|
+
if (message.role === "user") {
|
|
2432
|
+
lastUserText = message.text;
|
|
2433
|
+
if (nameSlots.firstUserMessage === void 0) {
|
|
2434
|
+
nameSlots = applyNameCandidate(
|
|
2435
|
+
nameSlots,
|
|
2436
|
+
"firstUserMessage",
|
|
2437
|
+
cursorUserQuery(cursorLineContent(line)),
|
|
2438
|
+
CURSOR_PROVIDER
|
|
2439
|
+
);
|
|
2440
|
+
}
|
|
2441
|
+
}
|
|
2073
2442
|
}
|
|
2074
2443
|
} catch (err) {
|
|
2075
2444
|
log.warn({ filePath, err }, "parseCursorConversation: read failed");
|
|
@@ -2077,14 +2446,14 @@ async function parseCursorConversation(filePath, account) {
|
|
|
2077
2446
|
}
|
|
2078
2447
|
if (messages.length === 0) return null;
|
|
2079
2448
|
const { projectPath, projectName } = projectFromCursorPath(filePath);
|
|
2080
|
-
const sessionId = (0,
|
|
2449
|
+
const sessionId = (0, import_path9.basename)(filePath, ".jsonl");
|
|
2081
2450
|
return {
|
|
2082
2451
|
id: filePath,
|
|
2083
2452
|
filePath,
|
|
2084
2453
|
projectPath,
|
|
2085
2454
|
projectName,
|
|
2086
2455
|
sessionId,
|
|
2087
|
-
sessionName: "",
|
|
2456
|
+
sessionName: resolveSessionName({ ...nameSlots, ...cursorNameSlotsFor(filePath, sessionId) }).name ?? "",
|
|
2088
2457
|
messages,
|
|
2089
2458
|
fullText: textParts.join(" "),
|
|
2090
2459
|
timestamp: latestTimestamp || fileMtimeIso2(filePath),
|
|
@@ -2198,9 +2567,9 @@ var ThreadbaseProvider = class {
|
|
|
2198
2567
|
|
|
2199
2568
|
// src/scanner.ts
|
|
2200
2569
|
var import_events = require("events");
|
|
2201
|
-
var
|
|
2570
|
+
var import_fs14 = require("fs");
|
|
2202
2571
|
var import_os2 = require("os");
|
|
2203
|
-
var
|
|
2572
|
+
var import_path14 = require("path");
|
|
2204
2573
|
|
|
2205
2574
|
// src/cache.ts
|
|
2206
2575
|
var LRUCache = class {
|
|
@@ -2239,18 +2608,18 @@ var LRUCache = class {
|
|
|
2239
2608
|
};
|
|
2240
2609
|
|
|
2241
2610
|
// src/persistent/conversation-stream.ts
|
|
2242
|
-
var
|
|
2611
|
+
var import_path10 = require("path");
|
|
2243
2612
|
|
|
2244
2613
|
// src/persistent/paged-reader.ts
|
|
2245
|
-
var
|
|
2614
|
+
var import_fs9 = require("fs");
|
|
2246
2615
|
var import_promises7 = require("timers/promises");
|
|
2247
2616
|
|
|
2248
2617
|
// src/persistent/jsonl-tail-reader.ts
|
|
2249
|
-
var
|
|
2618
|
+
var import_fs8 = require("fs");
|
|
2250
2619
|
var import_promises6 = require("timers/promises");
|
|
2251
2620
|
var YIELD_EVERY_LINES = 500;
|
|
2252
2621
|
async function tailReduce(filePath, startOffset, startLine, state, tier, onEntry) {
|
|
2253
|
-
const stream = (0,
|
|
2622
|
+
const stream = (0, import_fs8.createReadStream)(filePath, { start: startOffset, encoding: "utf8" });
|
|
2254
2623
|
let buffer = "";
|
|
2255
2624
|
let offset = startOffset;
|
|
2256
2625
|
let line = startLine;
|
|
@@ -2287,7 +2656,7 @@ async function tailReduce(filePath, startOffset, startLine, state, tier, onEntry
|
|
|
2287
2656
|
// src/persistent/paged-reader.ts
|
|
2288
2657
|
var CHECKPOINT_INTERVAL = 500;
|
|
2289
2658
|
async function streamMessages(filePath, startOffset, startLine, state, onMessage, onEntry) {
|
|
2290
|
-
const stream = (0,
|
|
2659
|
+
const stream = (0, import_fs9.createReadStream)(filePath, { start: startOffset, encoding: "utf8" });
|
|
2291
2660
|
let buffer = "";
|
|
2292
2661
|
let offset = startOffset;
|
|
2293
2662
|
let line = startLine;
|
|
@@ -2376,7 +2745,7 @@ async function foldTail(filePath, resume) {
|
|
|
2376
2745
|
resume.state,
|
|
2377
2746
|
(message) => {
|
|
2378
2747
|
messages.push(message);
|
|
2379
|
-
if (message.text) textParts.push(message.text);
|
|
2748
|
+
if (message.text && !message.isCompactSummary) textParts.push(message.text);
|
|
2380
2749
|
return false;
|
|
2381
2750
|
},
|
|
2382
2751
|
(entry) => {
|
|
@@ -2399,8 +2768,8 @@ function assemble(filePath, account, messages, fullText, turnDurations, state) {
|
|
|
2399
2768
|
filePath,
|
|
2400
2769
|
projectPath: state.cwd,
|
|
2401
2770
|
projectName: getShortProjectName2(state.cwd),
|
|
2402
|
-
sessionId: state.sessionId || (0,
|
|
2403
|
-
sessionName: state.
|
|
2771
|
+
sessionId: state.sessionId || (0, import_path10.basename)(filePath, ".jsonl"),
|
|
2772
|
+
sessionName: resolveSessionName(state.nameSlots).name ?? "",
|
|
2404
2773
|
messages,
|
|
2405
2774
|
fullText,
|
|
2406
2775
|
timestamp: state.latestTimestamp || (/* @__PURE__ */ new Date()).toISOString(),
|
|
@@ -2444,33 +2813,33 @@ async function extendConversation(previous, resume, filePath, account) {
|
|
|
2444
2813
|
|
|
2445
2814
|
// src/persistent/cursor.ts
|
|
2446
2815
|
var import_crypto2 = require("crypto");
|
|
2447
|
-
var
|
|
2816
|
+
var import_fs10 = require("fs");
|
|
2448
2817
|
var FP_BYTES = 4096;
|
|
2449
2818
|
function fingerprint(filePath, size) {
|
|
2450
2819
|
const hash = (0, import_crypto2.createHash)("sha1");
|
|
2451
2820
|
hash.update(String(size));
|
|
2452
|
-
const fd = (0,
|
|
2821
|
+
const fd = (0, import_fs10.openSync)(filePath, "r");
|
|
2453
2822
|
try {
|
|
2454
2823
|
const head = Buffer.alloc(Math.min(FP_BYTES, size));
|
|
2455
2824
|
if (head.length > 0) {
|
|
2456
|
-
(0,
|
|
2825
|
+
(0, import_fs10.readSync)(fd, head, 0, head.length, 0);
|
|
2457
2826
|
hash.update(head);
|
|
2458
2827
|
}
|
|
2459
2828
|
if (size > FP_BYTES) {
|
|
2460
2829
|
const tailLen = Math.min(FP_BYTES, size);
|
|
2461
2830
|
const tail = Buffer.alloc(tailLen);
|
|
2462
|
-
(0,
|
|
2831
|
+
(0, import_fs10.readSync)(fd, tail, 0, tailLen, size - tailLen);
|
|
2463
2832
|
hash.update(tail);
|
|
2464
2833
|
}
|
|
2465
2834
|
} finally {
|
|
2466
|
-
(0,
|
|
2835
|
+
(0, import_fs10.closeSync)(fd);
|
|
2467
2836
|
}
|
|
2468
2837
|
return hash.digest("hex");
|
|
2469
2838
|
}
|
|
2470
2839
|
function classify(filePath, existing) {
|
|
2471
2840
|
let stat6;
|
|
2472
2841
|
try {
|
|
2473
|
-
const s = (0,
|
|
2842
|
+
const s = (0, import_fs10.statSync)(filePath);
|
|
2474
2843
|
stat6 = { size: s.size, mtimeMs: s.mtimeMs };
|
|
2475
2844
|
} catch {
|
|
2476
2845
|
return { change: "vanished" };
|
|
@@ -2498,16 +2867,16 @@ function classify(filePath, existing) {
|
|
|
2498
2867
|
}
|
|
2499
2868
|
|
|
2500
2869
|
// src/persistent/index-engine.ts
|
|
2501
|
-
var
|
|
2870
|
+
var import_fs13 = require("fs");
|
|
2502
2871
|
|
|
2503
2872
|
// src/providers/parse.ts
|
|
2504
|
-
var
|
|
2873
|
+
var import_fs11 = require("fs");
|
|
2505
2874
|
var import_readline5 = require("readline");
|
|
2506
|
-
async function parseMetaWithProvider(provider, filePath, account, tier, onEntry) {
|
|
2875
|
+
async function parseMetaWithProvider(provider, filePath, account, tier, onEntry, onAccumulator) {
|
|
2507
2876
|
const log = getLogger();
|
|
2508
2877
|
const acc = provider.createEmptyAccumulator();
|
|
2509
2878
|
const rl = (0, import_readline5.createInterface)({
|
|
2510
|
-
input: (0,
|
|
2879
|
+
input: (0, import_fs11.createReadStream)(filePath),
|
|
2511
2880
|
crlfDelay: Infinity
|
|
2512
2881
|
});
|
|
2513
2882
|
try {
|
|
@@ -2530,6 +2899,7 @@ async function parseMetaWithProvider(provider, filePath, account, tier, onEntry)
|
|
|
2530
2899
|
log.warn({ filePath, provider: provider.name, err }, "provider parse: read failed");
|
|
2531
2900
|
return null;
|
|
2532
2901
|
}
|
|
2902
|
+
onAccumulator?.(acc);
|
|
2533
2903
|
return provider.finalize(acc, filePath, account, tier);
|
|
2534
2904
|
}
|
|
2535
2905
|
|
|
@@ -2730,12 +3100,12 @@ function resolveTier(tierName, customTiers) {
|
|
|
2730
3100
|
}
|
|
2731
3101
|
|
|
2732
3102
|
// src/persistent/db.ts
|
|
2733
|
-
var
|
|
2734
|
-
var
|
|
2735
|
-
var
|
|
3103
|
+
var import_better_sqlite32 = __toESM(require("better-sqlite3"), 1);
|
|
3104
|
+
var import_fs12 = require("fs");
|
|
3105
|
+
var import_path11 = require("path");
|
|
2736
3106
|
|
|
2737
3107
|
// src/persistent/schema.ts
|
|
2738
|
-
var SCHEMA_VERSION =
|
|
3108
|
+
var SCHEMA_VERSION = 11;
|
|
2739
3109
|
var SCHEMA_SQL = `
|
|
2740
3110
|
CREATE TABLE IF NOT EXISTS conversation_files (
|
|
2741
3111
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
@@ -2781,6 +3151,9 @@ CREATE TABLE IF NOT EXISTS conversations (
|
|
|
2781
3151
|
external_session_id TEXT,
|
|
2782
3152
|
session_id TEXT NOT NULL,
|
|
2783
3153
|
session_name TEXT,
|
|
3154
|
+
-- JSON NameSlots the name was resolved from; lets a side-store change
|
|
3155
|
+
-- re-resolve the name without reparsing the transcript.
|
|
3156
|
+
name_slots TEXT,
|
|
2784
3157
|
|
|
2785
3158
|
project_path TEXT,
|
|
2786
3159
|
project_name TEXT,
|
|
@@ -3043,6 +3416,27 @@ function runMigrations(db) {
|
|
|
3043
3416
|
db.exec(`UPDATE conversation_files SET ${assignments.join(", ")}`);
|
|
3044
3417
|
}
|
|
3045
3418
|
}
|
|
3419
|
+
if (current >= 1 && current < 11 && tableExists(db, "conversations")) {
|
|
3420
|
+
if (tableExists(db, "message_checkpoints")) db.exec("DELETE FROM message_checkpoints");
|
|
3421
|
+
if (!hasColumn(db, "conversations", "name_slots")) {
|
|
3422
|
+
db.exec("ALTER TABLE conversations ADD COLUMN name_slots TEXT");
|
|
3423
|
+
}
|
|
3424
|
+
if (tableExists(db, "conversation_files")) {
|
|
3425
|
+
const assignments = [];
|
|
3426
|
+
if (hasColumn(db, "conversation_files", "last_indexed_offset")) {
|
|
3427
|
+
assignments.push("last_indexed_offset = 0");
|
|
3428
|
+
}
|
|
3429
|
+
if (hasColumn(db, "conversation_files", "last_indexed_line")) {
|
|
3430
|
+
assignments.push("last_indexed_line = 0");
|
|
3431
|
+
}
|
|
3432
|
+
if (hasColumn(db, "conversation_files", "reducer_state")) {
|
|
3433
|
+
assignments.push("reducer_state = NULL");
|
|
3434
|
+
}
|
|
3435
|
+
if (assignments.length > 0) {
|
|
3436
|
+
db.exec(`UPDATE conversation_files SET ${assignments.join(", ")}`);
|
|
3437
|
+
}
|
|
3438
|
+
}
|
|
3439
|
+
}
|
|
3046
3440
|
db.exec(SCHEMA_SQL);
|
|
3047
3441
|
db.pragma(`user_version = ${SCHEMA_VERSION}`);
|
|
3048
3442
|
}
|
|
@@ -3057,11 +3451,11 @@ function hasColumn(db, table, column) {
|
|
|
3057
3451
|
// src/persistent/db.ts
|
|
3058
3452
|
function openDatabase(dbPath) {
|
|
3059
3453
|
if (dbPath !== ":memory:") {
|
|
3060
|
-
(0,
|
|
3454
|
+
(0, import_fs12.mkdirSync)((0, import_path11.dirname)(dbPath), { recursive: true });
|
|
3061
3455
|
}
|
|
3062
3456
|
let db;
|
|
3063
3457
|
try {
|
|
3064
|
-
db = new
|
|
3458
|
+
db = new import_better_sqlite32.default(dbPath);
|
|
3065
3459
|
} catch (err) {
|
|
3066
3460
|
if (isNativeBindingFailure(err)) throw nativeBindingError(err, dbPath);
|
|
3067
3461
|
throw err;
|
|
@@ -3102,7 +3496,7 @@ function nativeBindingError(err, dbPath) {
|
|
|
3102
3496
|
|
|
3103
3497
|
// src/persistent/dir-watermark.ts
|
|
3104
3498
|
var import_promises8 = require("fs/promises");
|
|
3105
|
-
var
|
|
3499
|
+
var import_path12 = require("path");
|
|
3106
3500
|
var FULL_RECONCILE_EVERY_N_SCANS = 20;
|
|
3107
3501
|
async function discoverJsonlFilesGated(dirs, files, scannedDirs, options = {}) {
|
|
3108
3502
|
const log = getLogger();
|
|
@@ -3173,10 +3567,10 @@ async function resolveProjectDirs(projectsDir, scannedDirs) {
|
|
|
3173
3567
|
return { entries, commitRoot: { mtimeMs: rootStat.mtimeMs } };
|
|
3174
3568
|
}
|
|
3175
3569
|
function dirnameOf(filePath) {
|
|
3176
|
-
return (0,
|
|
3570
|
+
return (0, import_path12.dirname)(filePath);
|
|
3177
3571
|
}
|
|
3178
3572
|
function joinPath(dir, name) {
|
|
3179
|
-
return (0,
|
|
3573
|
+
return (0, import_path12.join)(dir, name);
|
|
3180
3574
|
}
|
|
3181
3575
|
|
|
3182
3576
|
// src/persistent/repositories/checkpoints.repo.ts
|
|
@@ -3256,7 +3650,7 @@ function toCheckpoint(row) {
|
|
|
3256
3650
|
}
|
|
3257
3651
|
|
|
3258
3652
|
// src/persistent/repositories/conversation-files.repo.ts
|
|
3259
|
-
var
|
|
3653
|
+
var import_path13 = require("path");
|
|
3260
3654
|
var ConversationFilesRepo = class {
|
|
3261
3655
|
constructor(db) {
|
|
3262
3656
|
this.db = db;
|
|
@@ -3279,7 +3673,7 @@ var ConversationFilesRepo = class {
|
|
|
3279
3673
|
const info = this.db.prepare(
|
|
3280
3674
|
`INSERT INTO conversation_files (absolute_path, parent_dir, file_name, account)
|
|
3281
3675
|
VALUES (?, ?, ?, ?)`
|
|
3282
|
-
).run(canonical, (0,
|
|
3676
|
+
).run(canonical, (0, import_path13.dirname)(canonical), (0, import_path13.basename)(canonical), account);
|
|
3283
3677
|
return Number(info.lastInsertRowid);
|
|
3284
3678
|
}
|
|
3285
3679
|
// Advance the cursor + persisted reducer state after a successful index pass.
|
|
@@ -3387,7 +3781,7 @@ var ConversationsRepo = class {
|
|
|
3387
3781
|
db;
|
|
3388
3782
|
// Upsert by file_id (1 file = 1 conversation). Keyed on the unique file_id so
|
|
3389
3783
|
// a re-index overwrites the prior summary in place.
|
|
3390
|
-
upsert(fileId, meta, pageMessageCount = meta.messageCount) {
|
|
3784
|
+
upsert(fileId, meta, pageMessageCount = meta.messageCount, nameSlots) {
|
|
3391
3785
|
this.db.prepare(
|
|
3392
3786
|
`INSERT INTO conversations (
|
|
3393
3787
|
file_id, source_path, provider, kind, external_session_id,
|
|
@@ -3398,7 +3792,7 @@ var ConversationsRepo = class {
|
|
|
3398
3792
|
model, is_subagent, parent_session_id, subagent_id, parent_session_uuid,
|
|
3399
3793
|
is_teammate, team_name, tool_names_json,
|
|
3400
3794
|
last_prompt, is_imported_from_claude, is_imported_from_codex,
|
|
3401
|
-
is_imported_from_cursor, status, updated_at
|
|
3795
|
+
is_imported_from_cursor, name_slots, status, updated_at
|
|
3402
3796
|
) VALUES (
|
|
3403
3797
|
@file_id, @source_path, @provider, @kind, @external_session_id,
|
|
3404
3798
|
@session_id, @session_name, @project_path, @project_name,
|
|
@@ -3410,7 +3804,7 @@ var ConversationsRepo = class {
|
|
|
3410
3804
|
@model, @is_subagent, @parent_session_id, @subagent_id, @parent_session_uuid,
|
|
3411
3805
|
@is_teammate, @team_name, @tool_names_json,
|
|
3412
3806
|
@last_prompt, @is_imported_from_claude, @is_imported_from_codex,
|
|
3413
|
-
@is_imported_from_cursor, 'active', CURRENT_TIMESTAMP
|
|
3807
|
+
@is_imported_from_cursor, @name_slots, 'active', CURRENT_TIMESTAMP
|
|
3414
3808
|
)
|
|
3415
3809
|
ON CONFLICT(file_id) DO UPDATE SET
|
|
3416
3810
|
source_path = excluded.source_path,
|
|
@@ -3445,6 +3839,7 @@ var ConversationsRepo = class {
|
|
|
3445
3839
|
is_imported_from_claude = excluded.is_imported_from_claude,
|
|
3446
3840
|
is_imported_from_codex = excluded.is_imported_from_codex,
|
|
3447
3841
|
is_imported_from_cursor = excluded.is_imported_from_cursor,
|
|
3842
|
+
name_slots = excluded.name_slots,
|
|
3448
3843
|
status = 'active',
|
|
3449
3844
|
index_seq = (SELECT COALESCE(MAX(index_seq), 0) + 1 FROM conversations),
|
|
3450
3845
|
updated_at = CURRENT_TIMESTAMP`
|
|
@@ -3484,7 +3879,8 @@ var ConversationsRepo = class {
|
|
|
3484
3879
|
last_prompt: meta.lastPrompt ?? null,
|
|
3485
3880
|
is_imported_from_claude: meta.isImportedFromClaude ? 1 : 0,
|
|
3486
3881
|
is_imported_from_codex: meta.isImportedFromCodex ? 1 : 0,
|
|
3487
|
-
is_imported_from_cursor: meta.isImportedFromCursor ? 1 : 0
|
|
3882
|
+
is_imported_from_cursor: meta.isImportedFromCursor ? 1 : 0,
|
|
3883
|
+
name_slots: nameSlots ? JSON.stringify(nameSlots) : null
|
|
3488
3884
|
});
|
|
3489
3885
|
}
|
|
3490
3886
|
getBySourcePath(sourcePath) {
|
|
@@ -3865,13 +4261,18 @@ var PersistentEngine = class {
|
|
|
3865
4261
|
const tier = resolveTier(tierName, customTiers);
|
|
3866
4262
|
const filePath = canonicalPath(rawFilePath);
|
|
3867
4263
|
const existing = this.files.getByPath(filePath);
|
|
3868
|
-
const
|
|
4264
|
+
const classified = classify(filePath, existing);
|
|
4265
|
+
const stat6 = classified.stat;
|
|
4266
|
+
let change = classified.change;
|
|
3869
4267
|
if (change === "vanished" || !stat6) {
|
|
3870
4268
|
this.markDeleted(filePath);
|
|
3871
4269
|
return { meta: null, change: "vanished" };
|
|
3872
4270
|
}
|
|
3873
4271
|
if (change === "unchanged" && !force) {
|
|
3874
|
-
|
|
4272
|
+
const meta2 = this.conversations.getBySourcePath(filePath);
|
|
4273
|
+
const sideStoresMoved = provider && provider.name !== CLAUDE_CODE_PROVIDER && meta2 && JSON.stringify(nameStoreSlotsFor(provider.name, filePath, meta2.sessionId)) !== existing?.reducer_state;
|
|
4274
|
+
if (!sideStoresMoved) return { meta: meta2, change };
|
|
4275
|
+
change = "reindex";
|
|
3875
4276
|
}
|
|
3876
4277
|
if (provider && provider.name !== CLAUDE_CODE_PROVIDER) {
|
|
3877
4278
|
const meta2 = await this.indexFileWithProvider(
|
|
@@ -3910,7 +4311,7 @@ var PersistentEngine = class {
|
|
|
3910
4311
|
const base = resume ? this.fts.readDocument(fileId) ?? emptySearchDocument() : emptySearchDocument();
|
|
3911
4312
|
const searchDoc = appendSearchDelta(base, searchDelta);
|
|
3912
4313
|
const upsert = this.db.transaction(() => {
|
|
3913
|
-
this.conversations.upsert(fileId, meta, state.pageMessageCount);
|
|
4314
|
+
this.conversations.upsert(fileId, meta, state.pageMessageCount, state.nameSlots);
|
|
3914
4315
|
if (!this.fts.isCurrent(fileId, meta, searchDoc)) {
|
|
3915
4316
|
this.fts.upsert(fileId, meta, searchDoc);
|
|
3916
4317
|
}
|
|
@@ -3953,13 +4354,23 @@ var PersistentEngine = class {
|
|
|
3953
4354
|
// provider's reducer/finalize, then the same upsert + FTS write + cursor bump
|
|
3954
4355
|
// the Threadbase path uses. The cursor records size/mtime (and offset = size)
|
|
3955
4356
|
// so the next pass classifies an unchanged file as "unchanged" and skips it;
|
|
3956
|
-
// any change reparses from 0 again.
|
|
4357
|
+
// any change reparses from 0 again. reducer_state holds the side-store name slots, not a fold.
|
|
3957
4358
|
async indexFileWithProvider(provider, filePath, account, tier, stat6, resolveGitBranch) {
|
|
3958
4359
|
const log = getLogger();
|
|
3959
4360
|
let searchDoc = emptySearchDocument();
|
|
3960
|
-
|
|
3961
|
-
|
|
3962
|
-
|
|
4361
|
+
let transcriptSlots = {};
|
|
4362
|
+
const meta = await parseMetaWithProvider(
|
|
4363
|
+
provider,
|
|
4364
|
+
filePath,
|
|
4365
|
+
account,
|
|
4366
|
+
tier,
|
|
4367
|
+
(entry) => {
|
|
4368
|
+
searchDoc = appendSearchDelta(searchDoc, extractSearchDelta(entry));
|
|
4369
|
+
},
|
|
4370
|
+
(acc) => {
|
|
4371
|
+
transcriptSlots = acc.nameSlots ?? {};
|
|
4372
|
+
}
|
|
4373
|
+
);
|
|
3963
4374
|
if (!meta) {
|
|
3964
4375
|
this.markDeleted(filePath);
|
|
3965
4376
|
return null;
|
|
@@ -3967,10 +4378,14 @@ var PersistentEngine = class {
|
|
|
3967
4378
|
if (meta.gitBranch === null && meta.projectPath) {
|
|
3968
4379
|
meta.gitBranch = resolveGitBranch(meta.projectPath);
|
|
3969
4380
|
}
|
|
4381
|
+
const sideSlots = nameStoreSlotsFor(provider.name, filePath, meta.sessionId);
|
|
3970
4382
|
const fp = stat6.size > 0 ? fingerprint(filePath, stat6.size) : null;
|
|
3971
4383
|
const fileId = this.files.ensure(filePath, account);
|
|
3972
4384
|
const upsert = this.db.transaction(() => {
|
|
3973
|
-
this.conversations.upsert(fileId, meta, meta.messageCount
|
|
4385
|
+
this.conversations.upsert(fileId, meta, meta.messageCount, {
|
|
4386
|
+
...transcriptSlots,
|
|
4387
|
+
...sideSlots
|
|
4388
|
+
});
|
|
3974
4389
|
if (!this.fts.isCurrent(fileId, meta, searchDoc)) {
|
|
3975
4390
|
this.fts.upsert(fileId, meta, searchDoc);
|
|
3976
4391
|
}
|
|
@@ -3982,7 +4397,9 @@ var PersistentEngine = class {
|
|
|
3982
4397
|
// can classify it "unchanged"); no resumable reducer state is kept.
|
|
3983
4398
|
offset: stat6.size,
|
|
3984
4399
|
line: 0,
|
|
3985
|
-
|
|
4400
|
+
// Not resumable state: the side-store name slots this parse used, so the
|
|
4401
|
+
// next pass can tell when they moved (see indexFile).
|
|
4402
|
+
reducerState: JSON.stringify(sideSlots),
|
|
3986
4403
|
fingerprint: fp,
|
|
3987
4404
|
status: "active"
|
|
3988
4405
|
});
|
|
@@ -4062,7 +4479,7 @@ var PersistentEngine = class {
|
|
|
4062
4479
|
let floor = this.checkpoints.floor(filePath, fromIndex);
|
|
4063
4480
|
if (floor) {
|
|
4064
4481
|
try {
|
|
4065
|
-
if (floor.byteOffset > (0,
|
|
4482
|
+
if (floor.byteOffset > (0, import_fs13.statSync)(filePath).size) floor = null;
|
|
4066
4483
|
} catch {
|
|
4067
4484
|
}
|
|
4068
4485
|
}
|
|
@@ -4201,7 +4618,7 @@ function defaultDbPath() {
|
|
|
4201
4618
|
"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."
|
|
4202
4619
|
);
|
|
4203
4620
|
}
|
|
4204
|
-
return (0,
|
|
4621
|
+
return (0, import_path14.join)((0, import_os2.homedir)(), ".config", "threadbase-scanner", "index.db");
|
|
4205
4622
|
}
|
|
4206
4623
|
function capForMemory(doc, max) {
|
|
4207
4624
|
const combined = combineSearchContent(doc);
|
|
@@ -4294,6 +4711,7 @@ var ConversationScanner = class {
|
|
|
4294
4711
|
}
|
|
4295
4712
|
}
|
|
4296
4713
|
async runScan(options) {
|
|
4714
|
+
if (options.cursorStateDb !== void 0) setCursorStateDb(options.cursorStateDb);
|
|
4297
4715
|
const profiles = await this.resolveProfiles(options.profiles);
|
|
4298
4716
|
const activeProfiles = profiles.filter((p) => p.enabled && p.scanHistory !== false);
|
|
4299
4717
|
this.lastTier = resolveTier(options.tier ?? "standard", options.tiers);
|
|
@@ -4380,7 +4798,7 @@ var ConversationScanner = class {
|
|
|
4380
4798
|
const cached = statCache.get(filePath);
|
|
4381
4799
|
if (cached) {
|
|
4382
4800
|
try {
|
|
4383
|
-
const s = (0,
|
|
4801
|
+
const s = (0, import_fs14.statSync)(filePath);
|
|
4384
4802
|
if (s.mtimeMs === cached.stat.mtimeMs && s.size === cached.stat.size) {
|
|
4385
4803
|
return {
|
|
4386
4804
|
meta: cached.meta,
|
|
@@ -4928,13 +5346,13 @@ var ConversationScanner = class {
|
|
|
4928
5346
|
if (previous?.provider) return void 0;
|
|
4929
5347
|
let sample = "";
|
|
4930
5348
|
try {
|
|
4931
|
-
const fd = (0,
|
|
5349
|
+
const fd = (0, import_fs14.openSync)(filePath, "r");
|
|
4932
5350
|
try {
|
|
4933
5351
|
const buf = Buffer.alloc(8192);
|
|
4934
|
-
const n = (0,
|
|
5352
|
+
const n = (0, import_fs14.readSync)(fd, buf, 0, buf.length, 0);
|
|
4935
5353
|
sample = buf.subarray(0, n).toString("utf8");
|
|
4936
5354
|
} finally {
|
|
4937
|
-
(0,
|
|
5355
|
+
(0, import_fs14.closeSync)(fd);
|
|
4938
5356
|
}
|
|
4939
5357
|
} catch {
|
|
4940
5358
|
return void 0;
|
|
@@ -5062,11 +5480,13 @@ async function getConversation(id, options, scanner) {
|
|
|
5062
5480
|
CursorProvider,
|
|
5063
5481
|
DEFAULT_TIERS,
|
|
5064
5482
|
LEGACY_CURSOR_PROVIDER,
|
|
5483
|
+
NAME_PRECEDENCE,
|
|
5065
5484
|
SearchIndexer,
|
|
5066
5485
|
ThreadbaseProvider,
|
|
5067
5486
|
VALID_SORT_ORDERS,
|
|
5068
5487
|
applyAccountFilter,
|
|
5069
5488
|
applyIncludeFilter,
|
|
5489
|
+
applyNameCandidate,
|
|
5070
5490
|
applyPagination,
|
|
5071
5491
|
applyProjectFilter,
|
|
5072
5492
|
applySinceFilter,
|
|
@@ -5081,20 +5501,27 @@ async function getConversation(id, options, scanner) {
|
|
|
5081
5501
|
getLogger,
|
|
5082
5502
|
getProjectsDir,
|
|
5083
5503
|
isCodexInjectedContext,
|
|
5504
|
+
isValidNameCandidate,
|
|
5084
5505
|
loadProfiles,
|
|
5085
5506
|
parseCodexJsonlLine,
|
|
5086
5507
|
parseCopilotJsonlLine,
|
|
5087
5508
|
parseCursorJsonlLine,
|
|
5088
5509
|
parseJsonlLine,
|
|
5089
5510
|
providerMatches,
|
|
5511
|
+
readCodexNameSlots,
|
|
5512
|
+
readCopilotNameSlots,
|
|
5513
|
+
readCursorCliNameSlots,
|
|
5514
|
+
readCursorIdeNameSlots,
|
|
5090
5515
|
readGitBranch,
|
|
5091
5516
|
readSidecar,
|
|
5092
5517
|
resetDefaultScanner,
|
|
5093
5518
|
resolveConfigDir,
|
|
5519
|
+
resolveSessionName,
|
|
5094
5520
|
resolveTier,
|
|
5095
5521
|
saveProfiles,
|
|
5096
5522
|
scan,
|
|
5097
5523
|
search,
|
|
5524
|
+
setCursorStateDb,
|
|
5098
5525
|
setLogger,
|
|
5099
5526
|
sidecarPath,
|
|
5100
5527
|
unwrapCursorUserText
|