@threadbase-sh/scanner 0.21.1 → 0.23.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 +481 -123
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +564 -147
- 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 +536 -128
- 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 +1 -0
- 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/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 +3 -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,17 @@ 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 ?? "",
|
|
924
|
+
nameSlots: state.nameSlots,
|
|
574
925
|
projectPath,
|
|
575
926
|
projectName: getShortProjectName(projectPath),
|
|
576
927
|
account,
|
|
@@ -596,50 +947,17 @@ function finalizeMeta(state, filePath, account, tier) {
|
|
|
596
947
|
};
|
|
597
948
|
}
|
|
598
949
|
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
950
|
function getShortProjectName(fullPath) {
|
|
604
951
|
const parts = fullPath.split("/").filter(Boolean);
|
|
605
952
|
return parts.slice(-3).join("/");
|
|
606
953
|
}
|
|
607
954
|
|
|
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
955
|
// src/parser.ts
|
|
638
956
|
async function parseMeta(filePath, account, tier, onEntry) {
|
|
639
957
|
const log = getLogger();
|
|
640
958
|
log.trace({ filePath, account, tier: tier.name }, "parseMeta: start");
|
|
641
959
|
const state = initialReducerState();
|
|
642
|
-
const fileStream = (0,
|
|
960
|
+
const fileStream = (0, import_fs3.createReadStream)(filePath);
|
|
643
961
|
const rl = (0, import_readline.createInterface)({ input: fileStream, crlfDelay: Infinity });
|
|
644
962
|
try {
|
|
645
963
|
for await (const line of rl) {
|
|
@@ -676,7 +994,7 @@ async function parseConversation(filePath, account) {
|
|
|
676
994
|
const textParts = [];
|
|
677
995
|
const turnDurations = [];
|
|
678
996
|
const state = initialConvState();
|
|
679
|
-
const fileStream = (0,
|
|
997
|
+
const fileStream = (0, import_fs3.createReadStream)(filePath);
|
|
680
998
|
const rl = (0, import_readline.createInterface)({ input: fileStream, crlfDelay: Infinity });
|
|
681
999
|
try {
|
|
682
1000
|
for await (const line of rl) {
|
|
@@ -720,10 +1038,8 @@ async function parseConversation(filePath, account) {
|
|
|
720
1038
|
filePath,
|
|
721
1039
|
projectPath: state.cwd,
|
|
722
1040
|
projectName: getShortProjectName2(state.cwd),
|
|
723
|
-
sessionId: state.sessionId || (0,
|
|
724
|
-
sessionName: state.
|
|
725
|
-
messages.find((m) => m.role === "user" && m.text && !m.isCompactSummary) ?? null
|
|
726
|
-
),
|
|
1041
|
+
sessionId: state.sessionId || (0, import_path4.basename)(filePath, ".jsonl"),
|
|
1042
|
+
sessionName: resolveSessionName(state.nameSlots).name ?? "",
|
|
727
1043
|
messages,
|
|
728
1044
|
fullText: textParts.join(" "),
|
|
729
1045
|
timestamp: state.latestTimestamp || (/* @__PURE__ */ new Date()).toISOString(),
|
|
@@ -833,7 +1149,7 @@ function initialConvState() {
|
|
|
833
1149
|
return {
|
|
834
1150
|
cwd: "",
|
|
835
1151
|
sessionId: "",
|
|
836
|
-
|
|
1152
|
+
nameSlots: {},
|
|
837
1153
|
latestTimestamp: "",
|
|
838
1154
|
lastPrompt: "",
|
|
839
1155
|
pendingToolUses: {},
|
|
@@ -843,7 +1159,7 @@ function initialConvState() {
|
|
|
843
1159
|
function reduceConvLine(state, entry) {
|
|
844
1160
|
if (entry.cwd && !state.cwd) state.cwd = entry.cwd;
|
|
845
1161
|
if (entry.sessionId && !state.sessionId) state.sessionId = entry.sessionId;
|
|
846
|
-
|
|
1162
|
+
state.nameSlots = applyClaudeNameEntry(state.nameSlots, entry);
|
|
847
1163
|
if (entry.timestamp) {
|
|
848
1164
|
const ts = entry.timestamp;
|
|
849
1165
|
if (!state.latestTimestamp || ts > state.latestTimestamp) state.latestTimestamp = ts;
|
|
@@ -951,7 +1267,7 @@ function applyTeamInfo(messages, state) {
|
|
|
951
1267
|
}
|
|
952
1268
|
|
|
953
1269
|
// src/persistent/sidecar.ts
|
|
954
|
-
var
|
|
1270
|
+
var import_fs4 = require("fs");
|
|
955
1271
|
var SIDECAR_VERSION = 1;
|
|
956
1272
|
function sidecarPath(jsonlPath) {
|
|
957
1273
|
return `${jsonlPath}.idx.json`;
|
|
@@ -977,14 +1293,14 @@ function buildSidecar(meta, cursor, updatedAt) {
|
|
|
977
1293
|
}
|
|
978
1294
|
function writeSidecar(jsonlPath, sidecar) {
|
|
979
1295
|
try {
|
|
980
|
-
(0,
|
|
1296
|
+
(0, import_fs4.writeFileSync)(sidecarPath(jsonlPath), JSON.stringify(sidecar, null, 2));
|
|
981
1297
|
} catch (err) {
|
|
982
1298
|
getLogger().warn({ jsonlPath, err }, "sidecar: write failed");
|
|
983
1299
|
}
|
|
984
1300
|
}
|
|
985
1301
|
function readSidecar(jsonlPath) {
|
|
986
1302
|
try {
|
|
987
|
-
return JSON.parse((0,
|
|
1303
|
+
return JSON.parse((0, import_fs4.readFileSync)(sidecarPath(jsonlPath), "utf-8"));
|
|
988
1304
|
} catch {
|
|
989
1305
|
return null;
|
|
990
1306
|
}
|
|
@@ -993,19 +1309,19 @@ function readSidecar(jsonlPath) {
|
|
|
993
1309
|
// src/profiles.ts
|
|
994
1310
|
var import_promises = require("fs/promises");
|
|
995
1311
|
var import_os = require("os");
|
|
996
|
-
var
|
|
1312
|
+
var import_path5 = require("path");
|
|
997
1313
|
var PROFILES_FILE = "profiles.json";
|
|
998
1314
|
function resolveConfigDir(configDir) {
|
|
999
1315
|
return configDir.replace(/^~/, (0, import_os.homedir)());
|
|
1000
1316
|
}
|
|
1001
1317
|
function getProjectsDir(profile) {
|
|
1002
|
-
return (0,
|
|
1318
|
+
return (0, import_path5.join)(resolveConfigDir(profile.configDir), "projects");
|
|
1003
1319
|
}
|
|
1004
1320
|
async function detectDefaultProfile() {
|
|
1005
1321
|
return {
|
|
1006
1322
|
id: "default",
|
|
1007
1323
|
label: "Default",
|
|
1008
|
-
configDir: (0,
|
|
1324
|
+
configDir: (0, import_path5.join)((0, import_os.homedir)(), ".claude"),
|
|
1009
1325
|
enabled: true,
|
|
1010
1326
|
emoji: "\u{1F916}"
|
|
1011
1327
|
};
|
|
@@ -1014,7 +1330,7 @@ async function loadProfiles(configPath) {
|
|
|
1014
1330
|
const log = getLogger();
|
|
1015
1331
|
try {
|
|
1016
1332
|
const resolved = resolveConfigDir(configPath);
|
|
1017
|
-
const data = await (0, import_promises.readFile)((0,
|
|
1333
|
+
const data = await (0, import_promises.readFile)((0, import_path5.join)(resolved, PROFILES_FILE), "utf-8");
|
|
1018
1334
|
const profiles = JSON.parse(data);
|
|
1019
1335
|
log.debug({ configPath, count: profiles.length }, "profiles: loaded");
|
|
1020
1336
|
return profiles;
|
|
@@ -1027,21 +1343,21 @@ async function loadProfiles(configPath) {
|
|
|
1027
1343
|
async function saveProfiles(profiles, configPath) {
|
|
1028
1344
|
const resolved = resolveConfigDir(configPath);
|
|
1029
1345
|
await (0, import_promises.mkdir)(resolved, { recursive: true });
|
|
1030
|
-
await (0, import_promises.writeFile)((0,
|
|
1346
|
+
await (0, import_promises.writeFile)((0, import_path5.join)(resolved, PROFILES_FILE), JSON.stringify(profiles, null, 2));
|
|
1031
1347
|
getLogger().debug({ configPath, count: profiles.length }, "profiles: saved");
|
|
1032
1348
|
}
|
|
1033
1349
|
|
|
1034
1350
|
// src/providers/codex-cli.ts
|
|
1035
1351
|
var import_fast_glob = __toESM(require("fast-glob"), 1);
|
|
1036
|
-
var
|
|
1352
|
+
var import_fs5 = require("fs");
|
|
1037
1353
|
var import_promises2 = require("fs/promises");
|
|
1038
|
-
var
|
|
1354
|
+
var import_path7 = require("path");
|
|
1039
1355
|
var import_readline2 = require("readline");
|
|
1040
1356
|
|
|
1041
1357
|
// src/canonical-path.ts
|
|
1042
|
-
var
|
|
1358
|
+
var import_path6 = require("path");
|
|
1043
1359
|
function canonicalPath(p) {
|
|
1044
|
-
return
|
|
1360
|
+
return import_path6.sep === "\\" ? p.replace(/\//g, "\\") : p;
|
|
1045
1361
|
}
|
|
1046
1362
|
|
|
1047
1363
|
// src/providers/codex-cli.ts
|
|
@@ -1101,6 +1417,7 @@ var CodexCliProvider = class {
|
|
|
1101
1417
|
isSubagent: false,
|
|
1102
1418
|
parentSessionUuid: null,
|
|
1103
1419
|
firstUser: null,
|
|
1420
|
+
nameSlots: {},
|
|
1104
1421
|
lastUser: null,
|
|
1105
1422
|
lastAssistant: null,
|
|
1106
1423
|
toolNames: [],
|
|
@@ -1263,6 +1580,7 @@ function reduceCodexEntry(acc, entry, tier) {
|
|
|
1263
1580
|
const snapshot = { text: text.slice(0, 200), timestamp: ts };
|
|
1264
1581
|
if (sender === "user") {
|
|
1265
1582
|
if (!acc.firstUser) acc.firstUser = snapshot;
|
|
1583
|
+
acc.nameSlots = applyNameCandidate(acc.nameSlots, "firstUserMessage", text, CODEX_CLI_PROVIDER);
|
|
1266
1584
|
acc.lastUser = snapshot;
|
|
1267
1585
|
} else {
|
|
1268
1586
|
acc.lastAssistant = snapshot;
|
|
@@ -1280,7 +1598,8 @@ function reduceCodexEntry(acc, entry, tier) {
|
|
|
1280
1598
|
}
|
|
1281
1599
|
function finalizeCodexMeta(acc, filePath, account, tier) {
|
|
1282
1600
|
if (acc.messageCount === 0) return null;
|
|
1283
|
-
const sessionId = acc.sessionId || (0,
|
|
1601
|
+
const sessionId = acc.sessionId || (0, import_path7.basename)(filePath, ".jsonl");
|
|
1602
|
+
const nameSlots = { ...acc.nameSlots, ...codexNameSlotsFor(filePath, acc.sessionId) };
|
|
1284
1603
|
const projectPath = acc.cwd;
|
|
1285
1604
|
const kind = acc.lastAssistant === null && acc.toolNames.length > 0 ? "task" : "conversation";
|
|
1286
1605
|
return {
|
|
@@ -1290,10 +1609,8 @@ function finalizeCodexMeta(acc, filePath, account, tier) {
|
|
|
1290
1609
|
kind,
|
|
1291
1610
|
externalSessionId: acc.sessionId || void 0,
|
|
1292
1611
|
sessionId,
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
// AGENTS.md turn is skipped above — otherwise every title would be that blob.
|
|
1296
|
-
sessionName: deriveSessionNameFromFirstMessage(acc.firstUser),
|
|
1612
|
+
sessionName: resolveSessionName(nameSlots).name ?? "",
|
|
1613
|
+
nameSlots,
|
|
1297
1614
|
projectPath,
|
|
1298
1615
|
projectName: getShortProjectName3(projectPath),
|
|
1299
1616
|
account,
|
|
@@ -1316,10 +1633,6 @@ function finalizeCodexMeta(acc, filePath, account, tier) {
|
|
|
1316
1633
|
lastPrompt: acc.lastUser?.text || void 0
|
|
1317
1634
|
};
|
|
1318
1635
|
}
|
|
1319
|
-
function isCodexInjectedContext(text) {
|
|
1320
|
-
if (text.startsWith("# AGENTS.md") || text.includes("<INSTRUCTIONS>")) return true;
|
|
1321
|
-
return text.startsWith("<permissions instructions>") || text.includes("Filesystem sandboxing defines");
|
|
1322
|
-
}
|
|
1323
1636
|
function getShortProjectName3(fullPath) {
|
|
1324
1637
|
return fullPath.split("/").filter(Boolean).slice(-3).join("/");
|
|
1325
1638
|
}
|
|
@@ -1342,7 +1655,8 @@ async function parseCodexConversation(filePath, account) {
|
|
|
1342
1655
|
let cwd = "";
|
|
1343
1656
|
let latestTimestamp = "";
|
|
1344
1657
|
let lastUserText = "";
|
|
1345
|
-
|
|
1658
|
+
let nameSlots = {};
|
|
1659
|
+
const rl = (0, import_readline2.createInterface)({ input: (0, import_fs5.createReadStream)(filePath), crlfDelay: Infinity });
|
|
1346
1660
|
try {
|
|
1347
1661
|
for await (const line of rl) {
|
|
1348
1662
|
if (!line.trim()) continue;
|
|
@@ -1366,7 +1680,15 @@ async function parseCodexConversation(filePath, account) {
|
|
|
1366
1680
|
messages.push(message);
|
|
1367
1681
|
if (!message.text) continue;
|
|
1368
1682
|
textParts.push(message.text);
|
|
1369
|
-
if (message.role === "user")
|
|
1683
|
+
if (message.role === "user") {
|
|
1684
|
+
lastUserText = message.text;
|
|
1685
|
+
nameSlots = applyNameCandidate(
|
|
1686
|
+
nameSlots,
|
|
1687
|
+
"firstUserMessage",
|
|
1688
|
+
message.text,
|
|
1689
|
+
CODEX_CLI_PROVIDER
|
|
1690
|
+
);
|
|
1691
|
+
}
|
|
1370
1692
|
}
|
|
1371
1693
|
} catch (err) {
|
|
1372
1694
|
log.warn({ filePath, err }, "parseCodexConversation: read failed");
|
|
@@ -1378,8 +1700,8 @@ async function parseCodexConversation(filePath, account) {
|
|
|
1378
1700
|
filePath,
|
|
1379
1701
|
projectPath: cwd,
|
|
1380
1702
|
projectName: getShortProjectName3(cwd),
|
|
1381
|
-
sessionId: sessionId || (0,
|
|
1382
|
-
sessionName: "",
|
|
1703
|
+
sessionId: sessionId || (0, import_path7.basename)(filePath, ".jsonl"),
|
|
1704
|
+
sessionName: resolveSessionName({ ...nameSlots, ...codexNameSlotsFor(filePath, sessionId) }).name ?? "",
|
|
1383
1705
|
messages,
|
|
1384
1706
|
fullText: textParts.join(" "),
|
|
1385
1707
|
timestamp: latestTimestamp || (/* @__PURE__ */ new Date()).toISOString(),
|
|
@@ -1391,9 +1713,9 @@ async function parseCodexConversation(filePath, account) {
|
|
|
1391
1713
|
|
|
1392
1714
|
// src/providers/copilot.ts
|
|
1393
1715
|
var import_fast_glob2 = __toESM(require("fast-glob"), 1);
|
|
1394
|
-
var
|
|
1716
|
+
var import_fs6 = require("fs");
|
|
1395
1717
|
var import_promises3 = require("fs/promises");
|
|
1396
|
-
var
|
|
1718
|
+
var import_path8 = require("path");
|
|
1397
1719
|
var import_readline3 = require("readline");
|
|
1398
1720
|
var SESSION_START = "session.start";
|
|
1399
1721
|
var USER_MESSAGE = "user.message";
|
|
@@ -1447,6 +1769,7 @@ var CopilotProvider = class {
|
|
|
1447
1769
|
messageCount: 0,
|
|
1448
1770
|
lastMessageSender: "user",
|
|
1449
1771
|
firstUser: null,
|
|
1772
|
+
nameSlots: {},
|
|
1450
1773
|
lastUser: null,
|
|
1451
1774
|
lastAssistant: null,
|
|
1452
1775
|
toolNames: [],
|
|
@@ -1554,6 +1877,7 @@ function reduceCopilotEntry(acc, entry, tier) {
|
|
|
1554
1877
|
const snapshot = { text: text.slice(0, 200), timestamp };
|
|
1555
1878
|
if (role === "user") {
|
|
1556
1879
|
if (!acc.firstUser) acc.firstUser = snapshot;
|
|
1880
|
+
acc.nameSlots = applyNameCandidate(acc.nameSlots, "firstUserMessage", text, COPILOT_PROVIDER);
|
|
1557
1881
|
acc.lastUser = snapshot;
|
|
1558
1882
|
} else {
|
|
1559
1883
|
acc.lastAssistant = snapshot;
|
|
@@ -1572,6 +1896,7 @@ function reduceCopilotEntry(acc, entry, tier) {
|
|
|
1572
1896
|
function finalizeCopilotMeta(acc, filePath, account, tier) {
|
|
1573
1897
|
if (acc.messageCount === 0) return null;
|
|
1574
1898
|
const sessionId = acc.sessionId || sessionIdFromPath(filePath);
|
|
1899
|
+
const nameSlots = { ...acc.nameSlots, ...copilotNameSlotsFor(filePath) };
|
|
1575
1900
|
const kind = acc.lastAssistant === null && acc.toolNames.length > 0 ? "task" : "conversation";
|
|
1576
1901
|
return {
|
|
1577
1902
|
id: filePath,
|
|
@@ -1580,7 +1905,8 @@ function finalizeCopilotMeta(acc, filePath, account, tier) {
|
|
|
1580
1905
|
kind,
|
|
1581
1906
|
externalSessionId: sessionId,
|
|
1582
1907
|
sessionId,
|
|
1583
|
-
sessionName:
|
|
1908
|
+
sessionName: resolveSessionName(nameSlots).name ?? "",
|
|
1909
|
+
nameSlots,
|
|
1584
1910
|
projectPath: acc.cwd,
|
|
1585
1911
|
projectName: getShortProjectName4(acc.cwd),
|
|
1586
1912
|
account,
|
|
@@ -1602,14 +1928,14 @@ function finalizeCopilotMeta(acc, filePath, account, tier) {
|
|
|
1602
1928
|
};
|
|
1603
1929
|
}
|
|
1604
1930
|
function sessionIdFromPath(filePath) {
|
|
1605
|
-
return (0,
|
|
1931
|
+
return (0, import_path8.basename)((0, import_path8.dirname)(filePath));
|
|
1606
1932
|
}
|
|
1607
1933
|
function getShortProjectName4(fullPath) {
|
|
1608
1934
|
return fullPath.split(/[/\\]/).filter(Boolean).slice(-3).join("/");
|
|
1609
1935
|
}
|
|
1610
1936
|
function fileMtimeIso(filePath) {
|
|
1611
1937
|
try {
|
|
1612
|
-
return new Date((0,
|
|
1938
|
+
return new Date((0, import_fs6.statSync)(filePath).mtimeMs).toISOString();
|
|
1613
1939
|
} catch {
|
|
1614
1940
|
return (/* @__PURE__ */ new Date()).toISOString();
|
|
1615
1941
|
}
|
|
@@ -1622,7 +1948,8 @@ async function parseCopilotConversation(filePath, account) {
|
|
|
1622
1948
|
let cwd = "";
|
|
1623
1949
|
let latestTimestamp = "";
|
|
1624
1950
|
let lastUserText = "";
|
|
1625
|
-
|
|
1951
|
+
let nameSlots = {};
|
|
1952
|
+
const rl = (0, import_readline3.createInterface)({ input: (0, import_fs6.createReadStream)(filePath), crlfDelay: Infinity });
|
|
1626
1953
|
try {
|
|
1627
1954
|
for await (const line of rl) {
|
|
1628
1955
|
if (!line.trim()) continue;
|
|
@@ -1646,7 +1973,15 @@ async function parseCopilotConversation(filePath, account) {
|
|
|
1646
1973
|
messages.push(message);
|
|
1647
1974
|
if (!message.text) continue;
|
|
1648
1975
|
textParts.push(message.text);
|
|
1649
|
-
if (message.role === "user")
|
|
1976
|
+
if (message.role === "user") {
|
|
1977
|
+
lastUserText = message.text;
|
|
1978
|
+
nameSlots = applyNameCandidate(
|
|
1979
|
+
nameSlots,
|
|
1980
|
+
"firstUserMessage",
|
|
1981
|
+
message.text,
|
|
1982
|
+
COPILOT_PROVIDER
|
|
1983
|
+
);
|
|
1984
|
+
}
|
|
1650
1985
|
}
|
|
1651
1986
|
} catch (err) {
|
|
1652
1987
|
log.warn({ filePath, err }, "parseCopilotConversation: read failed");
|
|
@@ -1659,7 +1994,7 @@ async function parseCopilotConversation(filePath, account) {
|
|
|
1659
1994
|
projectPath: cwd,
|
|
1660
1995
|
projectName: getShortProjectName4(cwd),
|
|
1661
1996
|
sessionId: sessionId || sessionIdFromPath(filePath),
|
|
1662
|
-
sessionName: "",
|
|
1997
|
+
sessionName: resolveSessionName({ ...nameSlots, ...copilotNameSlotsFor(filePath) }).name ?? "",
|
|
1663
1998
|
messages,
|
|
1664
1999
|
fullText: textParts.join(" "),
|
|
1665
2000
|
timestamp: latestTimestamp || fileMtimeIso(filePath),
|
|
@@ -1672,9 +2007,9 @@ async function parseCopilotConversation(filePath, account) {
|
|
|
1672
2007
|
// src/providers/cursor.ts
|
|
1673
2008
|
var import_crypto = require("crypto");
|
|
1674
2009
|
var import_fast_glob3 = __toESM(require("fast-glob"), 1);
|
|
1675
|
-
var
|
|
2010
|
+
var import_fs7 = require("fs");
|
|
1676
2011
|
var import_promises4 = require("fs/promises");
|
|
1677
|
-
var
|
|
2012
|
+
var import_path9 = require("path");
|
|
1678
2013
|
var import_readline4 = require("readline");
|
|
1679
2014
|
var TIMESTAMP_RE = /<timestamp>\s*([\s\S]*?)\s*<\/timestamp>/;
|
|
1680
2015
|
var USER_QUERY_RE = /<user_query>\s*([\s\S]*?)\s*<\/user_query>/;
|
|
@@ -1733,6 +2068,7 @@ var CursorProvider = class {
|
|
|
1733
2068
|
parentSessionUuid: null,
|
|
1734
2069
|
subagentId: null,
|
|
1735
2070
|
firstUser: null,
|
|
2071
|
+
nameSlots: {},
|
|
1736
2072
|
lastUser: null,
|
|
1737
2073
|
lastAssistant: null,
|
|
1738
2074
|
isImportedFromClaude: false,
|
|
@@ -1799,6 +2135,15 @@ function noteImportProvenance(acc, entry, text) {
|
|
|
1799
2135
|
acc.isImportedFromCodex = true;
|
|
1800
2136
|
}
|
|
1801
2137
|
}
|
|
2138
|
+
function cursorUserQuery(content) {
|
|
2139
|
+
const texts = typeof content === "string" ? [content] : Array.isArray(content) ? content : [];
|
|
2140
|
+
for (const item of texts) {
|
|
2141
|
+
const text = typeof item === "string" ? item : item?.text;
|
|
2142
|
+
const query = typeof text === "string" ? text.match(USER_QUERY_RE) : null;
|
|
2143
|
+
if (query) return query[1];
|
|
2144
|
+
}
|
|
2145
|
+
return void 0;
|
|
2146
|
+
}
|
|
1802
2147
|
function unwrapCursorUserText(text) {
|
|
1803
2148
|
const query = text.match(USER_QUERY_RE);
|
|
1804
2149
|
const body = query ? query[1] : text.replace(TIMESTAMP_RE, "");
|
|
@@ -1936,6 +2281,14 @@ function reduceCursorEntry(acc, entry, tier) {
|
|
|
1936
2281
|
collectCursorToolNames(content, acc.toolNames);
|
|
1937
2282
|
const text = textHint;
|
|
1938
2283
|
if (!text) return;
|
|
2284
|
+
if (entry.role === "user") {
|
|
2285
|
+
acc.nameSlots = applyNameCandidate(
|
|
2286
|
+
acc.nameSlots,
|
|
2287
|
+
"firstUserMessage",
|
|
2288
|
+
cursorUserQuery(content),
|
|
2289
|
+
CURSOR_PROVIDER
|
|
2290
|
+
);
|
|
2291
|
+
}
|
|
1939
2292
|
foldCursorMessage(acc, entry.role, text, firstTimestampHint(content), tier);
|
|
1940
2293
|
return;
|
|
1941
2294
|
}
|
|
@@ -1954,7 +2307,8 @@ function reduceCursorEntry(acc, entry, tier) {
|
|
|
1954
2307
|
}
|
|
1955
2308
|
function finalizeCursorMeta(acc, filePath, account, tier) {
|
|
1956
2309
|
if (acc.messageCount === 0) return null;
|
|
1957
|
-
const sessionId = (0,
|
|
2310
|
+
const sessionId = (0, import_path9.basename)(filePath, ".jsonl");
|
|
2311
|
+
const nameSlots = { ...acc.nameSlots, ...cursorNameSlotsFor(filePath, sessionId) };
|
|
1958
2312
|
const isSubagent = SUBAGENT_PATH_RE2.test(filePath);
|
|
1959
2313
|
const parent = isSubagent ? parentFromSubagentPath(filePath) : null;
|
|
1960
2314
|
const { projectPath, projectName } = projectFromCursorPath(filePath);
|
|
@@ -1967,7 +2321,8 @@ function finalizeCursorMeta(acc, filePath, account, tier) {
|
|
|
1967
2321
|
kind,
|
|
1968
2322
|
externalSessionId: sessionId,
|
|
1969
2323
|
sessionId,
|
|
1970
|
-
sessionName:
|
|
2324
|
+
sessionName: resolveSessionName(nameSlots).name ?? "",
|
|
2325
|
+
nameSlots,
|
|
1971
2326
|
projectPath,
|
|
1972
2327
|
projectName,
|
|
1973
2328
|
account,
|
|
@@ -1993,20 +2348,20 @@ function finalizeCursorMeta(acc, filePath, account, tier) {
|
|
|
1993
2348
|
};
|
|
1994
2349
|
}
|
|
1995
2350
|
function parentFromSubagentPath(filePath) {
|
|
1996
|
-
const subagentsDir = (0,
|
|
1997
|
-
const parentDir = (0,
|
|
1998
|
-
const parentSessionUuid = (0,
|
|
2351
|
+
const subagentsDir = (0, import_path9.dirname)(filePath);
|
|
2352
|
+
const parentDir = (0, import_path9.dirname)(subagentsDir);
|
|
2353
|
+
const parentSessionUuid = (0, import_path9.basename)(parentDir);
|
|
1999
2354
|
if (!parentSessionUuid) return null;
|
|
2000
2355
|
return {
|
|
2001
2356
|
parentSessionUuid,
|
|
2002
|
-
parentFilePath: canonicalPath((0,
|
|
2357
|
+
parentFilePath: canonicalPath((0, import_path9.join)(parentDir, `${parentSessionUuid}.jsonl`))
|
|
2003
2358
|
};
|
|
2004
2359
|
}
|
|
2005
2360
|
function projectFromCursorPath(filePath) {
|
|
2006
2361
|
const parts = filePath.split(/[/\\]/);
|
|
2007
2362
|
const idx = parts.lastIndexOf("agent-transcripts");
|
|
2008
|
-
const cursorProjectDir = idx > 0 ? parts.slice(0, idx).join(
|
|
2009
|
-
const slug = (0,
|
|
2363
|
+
const cursorProjectDir = idx > 0 ? parts.slice(0, idx).join(import_path9.sep) : (0, import_path9.dirname)((0, import_path9.dirname)(filePath));
|
|
2364
|
+
const slug = (0, import_path9.basename)(cursorProjectDir);
|
|
2010
2365
|
const decoded = decodeCursorProjectSlug(slug);
|
|
2011
2366
|
const projectPath = decoded ?? cursorProjectDir;
|
|
2012
2367
|
return { projectPath, projectName: getShortProjectName5(projectPath) || slug };
|
|
@@ -2016,11 +2371,11 @@ function decodeCursorProjectSlug(slug) {
|
|
|
2016
2371
|
const segments = slug.split("-");
|
|
2017
2372
|
if (segments.length === 0) return null;
|
|
2018
2373
|
const rooted = slug.startsWith("Users-") || slug.startsWith("home-") || /^[A-Za-z]-/.test(slug);
|
|
2019
|
-
let acc = rooted ?
|
|
2374
|
+
let acc = rooted ? import_path9.sep : "";
|
|
2020
2375
|
let i = 0;
|
|
2021
2376
|
if (rooted && segments[0] === "Users") {
|
|
2022
|
-
const users = `${
|
|
2023
|
-
if (!(0,
|
|
2377
|
+
const users = `${import_path9.sep}Users`;
|
|
2378
|
+
if (!(0, import_fs7.existsSync)(users)) return null;
|
|
2024
2379
|
acc = users;
|
|
2025
2380
|
i = 1;
|
|
2026
2381
|
}
|
|
@@ -2028,9 +2383,9 @@ function decodeCursorProjectSlug(slug) {
|
|
|
2028
2383
|
let found = null;
|
|
2029
2384
|
let next = i + 1;
|
|
2030
2385
|
for (let j = segments.length; j > i; j--) {
|
|
2031
|
-
const candidate = (0,
|
|
2386
|
+
const candidate = (0, import_path9.join)(acc, segments.slice(i, j).join("-"));
|
|
2032
2387
|
try {
|
|
2033
|
-
if ((0,
|
|
2388
|
+
if ((0, import_fs7.existsSync)(candidate) && (0, import_fs7.statSync)(candidate).isDirectory()) {
|
|
2034
2389
|
found = candidate;
|
|
2035
2390
|
next = j;
|
|
2036
2391
|
break;
|
|
@@ -2049,18 +2404,27 @@ function getShortProjectName5(fullPath) {
|
|
|
2049
2404
|
}
|
|
2050
2405
|
function fileMtimeIso2(filePath) {
|
|
2051
2406
|
try {
|
|
2052
|
-
return new Date((0,
|
|
2407
|
+
return new Date((0, import_fs7.statSync)(filePath).mtimeMs).toISOString();
|
|
2053
2408
|
} catch {
|
|
2054
2409
|
return (/* @__PURE__ */ new Date()).toISOString();
|
|
2055
2410
|
}
|
|
2056
2411
|
}
|
|
2412
|
+
function cursorLineContent(line) {
|
|
2413
|
+
try {
|
|
2414
|
+
const entry = JSON.parse(line);
|
|
2415
|
+
return entry.message?.content ?? entry.content;
|
|
2416
|
+
} catch {
|
|
2417
|
+
return void 0;
|
|
2418
|
+
}
|
|
2419
|
+
}
|
|
2057
2420
|
async function parseCursorConversation(filePath, account) {
|
|
2058
2421
|
const log = getLogger();
|
|
2059
2422
|
const messages = [];
|
|
2060
2423
|
const textParts = [];
|
|
2061
2424
|
let latestTimestamp = "";
|
|
2062
2425
|
let lastUserText = "";
|
|
2063
|
-
|
|
2426
|
+
let nameSlots = {};
|
|
2427
|
+
const rl = (0, import_readline4.createInterface)({ input: (0, import_fs7.createReadStream)(filePath), crlfDelay: Infinity });
|
|
2064
2428
|
try {
|
|
2065
2429
|
for await (const line of rl) {
|
|
2066
2430
|
const message = parseCursorJsonlLine(line, messages.length);
|
|
@@ -2071,7 +2435,17 @@ async function parseCursorConversation(filePath, account) {
|
|
|
2071
2435
|
messages.push(message);
|
|
2072
2436
|
if (!message.text) continue;
|
|
2073
2437
|
textParts.push(message.text);
|
|
2074
|
-
if (message.role === "user")
|
|
2438
|
+
if (message.role === "user") {
|
|
2439
|
+
lastUserText = message.text;
|
|
2440
|
+
if (nameSlots.firstUserMessage === void 0) {
|
|
2441
|
+
nameSlots = applyNameCandidate(
|
|
2442
|
+
nameSlots,
|
|
2443
|
+
"firstUserMessage",
|
|
2444
|
+
cursorUserQuery(cursorLineContent(line)),
|
|
2445
|
+
CURSOR_PROVIDER
|
|
2446
|
+
);
|
|
2447
|
+
}
|
|
2448
|
+
}
|
|
2075
2449
|
}
|
|
2076
2450
|
} catch (err) {
|
|
2077
2451
|
log.warn({ filePath, err }, "parseCursorConversation: read failed");
|
|
@@ -2079,14 +2453,14 @@ async function parseCursorConversation(filePath, account) {
|
|
|
2079
2453
|
}
|
|
2080
2454
|
if (messages.length === 0) return null;
|
|
2081
2455
|
const { projectPath, projectName } = projectFromCursorPath(filePath);
|
|
2082
|
-
const sessionId = (0,
|
|
2456
|
+
const sessionId = (0, import_path9.basename)(filePath, ".jsonl");
|
|
2083
2457
|
return {
|
|
2084
2458
|
id: filePath,
|
|
2085
2459
|
filePath,
|
|
2086
2460
|
projectPath,
|
|
2087
2461
|
projectName,
|
|
2088
2462
|
sessionId,
|
|
2089
|
-
sessionName: "",
|
|
2463
|
+
sessionName: resolveSessionName({ ...nameSlots, ...cursorNameSlotsFor(filePath, sessionId) }).name ?? "",
|
|
2090
2464
|
messages,
|
|
2091
2465
|
fullText: textParts.join(" "),
|
|
2092
2466
|
timestamp: latestTimestamp || fileMtimeIso2(filePath),
|
|
@@ -2200,9 +2574,9 @@ var ThreadbaseProvider = class {
|
|
|
2200
2574
|
|
|
2201
2575
|
// src/scanner.ts
|
|
2202
2576
|
var import_events = require("events");
|
|
2203
|
-
var
|
|
2577
|
+
var import_fs14 = require("fs");
|
|
2204
2578
|
var import_os2 = require("os");
|
|
2205
|
-
var
|
|
2579
|
+
var import_path14 = require("path");
|
|
2206
2580
|
|
|
2207
2581
|
// src/cache.ts
|
|
2208
2582
|
var LRUCache = class {
|
|
@@ -2241,18 +2615,18 @@ var LRUCache = class {
|
|
|
2241
2615
|
};
|
|
2242
2616
|
|
|
2243
2617
|
// src/persistent/conversation-stream.ts
|
|
2244
|
-
var
|
|
2618
|
+
var import_path10 = require("path");
|
|
2245
2619
|
|
|
2246
2620
|
// src/persistent/paged-reader.ts
|
|
2247
|
-
var
|
|
2621
|
+
var import_fs9 = require("fs");
|
|
2248
2622
|
var import_promises7 = require("timers/promises");
|
|
2249
2623
|
|
|
2250
2624
|
// src/persistent/jsonl-tail-reader.ts
|
|
2251
|
-
var
|
|
2625
|
+
var import_fs8 = require("fs");
|
|
2252
2626
|
var import_promises6 = require("timers/promises");
|
|
2253
2627
|
var YIELD_EVERY_LINES = 500;
|
|
2254
2628
|
async function tailReduce(filePath, startOffset, startLine, state, tier, onEntry) {
|
|
2255
|
-
const stream = (0,
|
|
2629
|
+
const stream = (0, import_fs8.createReadStream)(filePath, { start: startOffset, encoding: "utf8" });
|
|
2256
2630
|
let buffer = "";
|
|
2257
2631
|
let offset = startOffset;
|
|
2258
2632
|
let line = startLine;
|
|
@@ -2289,7 +2663,7 @@ async function tailReduce(filePath, startOffset, startLine, state, tier, onEntry
|
|
|
2289
2663
|
// src/persistent/paged-reader.ts
|
|
2290
2664
|
var CHECKPOINT_INTERVAL = 500;
|
|
2291
2665
|
async function streamMessages(filePath, startOffset, startLine, state, onMessage, onEntry) {
|
|
2292
|
-
const stream = (0,
|
|
2666
|
+
const stream = (0, import_fs9.createReadStream)(filePath, { start: startOffset, encoding: "utf8" });
|
|
2293
2667
|
let buffer = "";
|
|
2294
2668
|
let offset = startOffset;
|
|
2295
2669
|
let line = startLine;
|
|
@@ -2401,10 +2775,8 @@ function assemble(filePath, account, messages, fullText, turnDurations, state) {
|
|
|
2401
2775
|
filePath,
|
|
2402
2776
|
projectPath: state.cwd,
|
|
2403
2777
|
projectName: getShortProjectName2(state.cwd),
|
|
2404
|
-
sessionId: state.sessionId || (0,
|
|
2405
|
-
sessionName: state.
|
|
2406
|
-
messages.find((m) => m.role === "user" && m.text && !m.isCompactSummary) ?? null
|
|
2407
|
-
),
|
|
2778
|
+
sessionId: state.sessionId || (0, import_path10.basename)(filePath, ".jsonl"),
|
|
2779
|
+
sessionName: resolveSessionName(state.nameSlots).name ?? "",
|
|
2408
2780
|
messages,
|
|
2409
2781
|
fullText,
|
|
2410
2782
|
timestamp: state.latestTimestamp || (/* @__PURE__ */ new Date()).toISOString(),
|
|
@@ -2448,33 +2820,33 @@ async function extendConversation(previous, resume, filePath, account) {
|
|
|
2448
2820
|
|
|
2449
2821
|
// src/persistent/cursor.ts
|
|
2450
2822
|
var import_crypto2 = require("crypto");
|
|
2451
|
-
var
|
|
2823
|
+
var import_fs10 = require("fs");
|
|
2452
2824
|
var FP_BYTES = 4096;
|
|
2453
2825
|
function fingerprint(filePath, size) {
|
|
2454
2826
|
const hash = (0, import_crypto2.createHash)("sha1");
|
|
2455
2827
|
hash.update(String(size));
|
|
2456
|
-
const fd = (0,
|
|
2828
|
+
const fd = (0, import_fs10.openSync)(filePath, "r");
|
|
2457
2829
|
try {
|
|
2458
2830
|
const head = Buffer.alloc(Math.min(FP_BYTES, size));
|
|
2459
2831
|
if (head.length > 0) {
|
|
2460
|
-
(0,
|
|
2832
|
+
(0, import_fs10.readSync)(fd, head, 0, head.length, 0);
|
|
2461
2833
|
hash.update(head);
|
|
2462
2834
|
}
|
|
2463
2835
|
if (size > FP_BYTES) {
|
|
2464
2836
|
const tailLen = Math.min(FP_BYTES, size);
|
|
2465
2837
|
const tail = Buffer.alloc(tailLen);
|
|
2466
|
-
(0,
|
|
2838
|
+
(0, import_fs10.readSync)(fd, tail, 0, tailLen, size - tailLen);
|
|
2467
2839
|
hash.update(tail);
|
|
2468
2840
|
}
|
|
2469
2841
|
} finally {
|
|
2470
|
-
(0,
|
|
2842
|
+
(0, import_fs10.closeSync)(fd);
|
|
2471
2843
|
}
|
|
2472
2844
|
return hash.digest("hex");
|
|
2473
2845
|
}
|
|
2474
2846
|
function classify(filePath, existing) {
|
|
2475
2847
|
let stat6;
|
|
2476
2848
|
try {
|
|
2477
|
-
const s = (0,
|
|
2849
|
+
const s = (0, import_fs10.statSync)(filePath);
|
|
2478
2850
|
stat6 = { size: s.size, mtimeMs: s.mtimeMs };
|
|
2479
2851
|
} catch {
|
|
2480
2852
|
return { change: "vanished" };
|
|
@@ -2502,16 +2874,16 @@ function classify(filePath, existing) {
|
|
|
2502
2874
|
}
|
|
2503
2875
|
|
|
2504
2876
|
// src/persistent/index-engine.ts
|
|
2505
|
-
var
|
|
2877
|
+
var import_fs13 = require("fs");
|
|
2506
2878
|
|
|
2507
2879
|
// src/providers/parse.ts
|
|
2508
|
-
var
|
|
2880
|
+
var import_fs11 = require("fs");
|
|
2509
2881
|
var import_readline5 = require("readline");
|
|
2510
2882
|
async function parseMetaWithProvider(provider, filePath, account, tier, onEntry) {
|
|
2511
2883
|
const log = getLogger();
|
|
2512
2884
|
const acc = provider.createEmptyAccumulator();
|
|
2513
2885
|
const rl = (0, import_readline5.createInterface)({
|
|
2514
|
-
input: (0,
|
|
2886
|
+
input: (0, import_fs11.createReadStream)(filePath),
|
|
2515
2887
|
crlfDelay: Infinity
|
|
2516
2888
|
});
|
|
2517
2889
|
try {
|
|
@@ -2734,12 +3106,12 @@ function resolveTier(tierName, customTiers) {
|
|
|
2734
3106
|
}
|
|
2735
3107
|
|
|
2736
3108
|
// src/persistent/db.ts
|
|
2737
|
-
var
|
|
2738
|
-
var
|
|
2739
|
-
var
|
|
3109
|
+
var import_better_sqlite32 = __toESM(require("better-sqlite3"), 1);
|
|
3110
|
+
var import_fs12 = require("fs");
|
|
3111
|
+
var import_path11 = require("path");
|
|
2740
3112
|
|
|
2741
3113
|
// src/persistent/schema.ts
|
|
2742
|
-
var SCHEMA_VERSION =
|
|
3114
|
+
var SCHEMA_VERSION = 11;
|
|
2743
3115
|
var SCHEMA_SQL = `
|
|
2744
3116
|
CREATE TABLE IF NOT EXISTS conversation_files (
|
|
2745
3117
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
@@ -2785,6 +3157,9 @@ CREATE TABLE IF NOT EXISTS conversations (
|
|
|
2785
3157
|
external_session_id TEXT,
|
|
2786
3158
|
session_id TEXT NOT NULL,
|
|
2787
3159
|
session_name TEXT,
|
|
3160
|
+
-- JSON NameSlots the name was resolved from; lets a side-store change
|
|
3161
|
+
-- re-resolve the name without reparsing the transcript.
|
|
3162
|
+
name_slots TEXT,
|
|
2788
3163
|
|
|
2789
3164
|
project_path TEXT,
|
|
2790
3165
|
project_name TEXT,
|
|
@@ -3047,6 +3422,27 @@ function runMigrations(db) {
|
|
|
3047
3422
|
db.exec(`UPDATE conversation_files SET ${assignments.join(", ")}`);
|
|
3048
3423
|
}
|
|
3049
3424
|
}
|
|
3425
|
+
if (current >= 1 && current < 11 && tableExists(db, "conversations")) {
|
|
3426
|
+
if (tableExists(db, "message_checkpoints")) db.exec("DELETE FROM message_checkpoints");
|
|
3427
|
+
if (!hasColumn(db, "conversations", "name_slots")) {
|
|
3428
|
+
db.exec("ALTER TABLE conversations ADD COLUMN name_slots TEXT");
|
|
3429
|
+
}
|
|
3430
|
+
if (tableExists(db, "conversation_files")) {
|
|
3431
|
+
const assignments = [];
|
|
3432
|
+
if (hasColumn(db, "conversation_files", "last_indexed_offset")) {
|
|
3433
|
+
assignments.push("last_indexed_offset = 0");
|
|
3434
|
+
}
|
|
3435
|
+
if (hasColumn(db, "conversation_files", "last_indexed_line")) {
|
|
3436
|
+
assignments.push("last_indexed_line = 0");
|
|
3437
|
+
}
|
|
3438
|
+
if (hasColumn(db, "conversation_files", "reducer_state")) {
|
|
3439
|
+
assignments.push("reducer_state = NULL");
|
|
3440
|
+
}
|
|
3441
|
+
if (assignments.length > 0) {
|
|
3442
|
+
db.exec(`UPDATE conversation_files SET ${assignments.join(", ")}`);
|
|
3443
|
+
}
|
|
3444
|
+
}
|
|
3445
|
+
}
|
|
3050
3446
|
db.exec(SCHEMA_SQL);
|
|
3051
3447
|
db.pragma(`user_version = ${SCHEMA_VERSION}`);
|
|
3052
3448
|
}
|
|
@@ -3061,11 +3457,11 @@ function hasColumn(db, table, column) {
|
|
|
3061
3457
|
// src/persistent/db.ts
|
|
3062
3458
|
function openDatabase(dbPath) {
|
|
3063
3459
|
if (dbPath !== ":memory:") {
|
|
3064
|
-
(0,
|
|
3460
|
+
(0, import_fs12.mkdirSync)((0, import_path11.dirname)(dbPath), { recursive: true });
|
|
3065
3461
|
}
|
|
3066
3462
|
let db;
|
|
3067
3463
|
try {
|
|
3068
|
-
db = new
|
|
3464
|
+
db = new import_better_sqlite32.default(dbPath);
|
|
3069
3465
|
} catch (err) {
|
|
3070
3466
|
if (isNativeBindingFailure(err)) throw nativeBindingError(err, dbPath);
|
|
3071
3467
|
throw err;
|
|
@@ -3106,7 +3502,7 @@ function nativeBindingError(err, dbPath) {
|
|
|
3106
3502
|
|
|
3107
3503
|
// src/persistent/dir-watermark.ts
|
|
3108
3504
|
var import_promises8 = require("fs/promises");
|
|
3109
|
-
var
|
|
3505
|
+
var import_path12 = require("path");
|
|
3110
3506
|
var FULL_RECONCILE_EVERY_N_SCANS = 20;
|
|
3111
3507
|
async function discoverJsonlFilesGated(dirs, files, scannedDirs, options = {}) {
|
|
3112
3508
|
const log = getLogger();
|
|
@@ -3177,10 +3573,10 @@ async function resolveProjectDirs(projectsDir, scannedDirs) {
|
|
|
3177
3573
|
return { entries, commitRoot: { mtimeMs: rootStat.mtimeMs } };
|
|
3178
3574
|
}
|
|
3179
3575
|
function dirnameOf(filePath) {
|
|
3180
|
-
return (0,
|
|
3576
|
+
return (0, import_path12.dirname)(filePath);
|
|
3181
3577
|
}
|
|
3182
3578
|
function joinPath(dir, name) {
|
|
3183
|
-
return (0,
|
|
3579
|
+
return (0, import_path12.join)(dir, name);
|
|
3184
3580
|
}
|
|
3185
3581
|
|
|
3186
3582
|
// src/persistent/repositories/checkpoints.repo.ts
|
|
@@ -3260,7 +3656,7 @@ function toCheckpoint(row) {
|
|
|
3260
3656
|
}
|
|
3261
3657
|
|
|
3262
3658
|
// src/persistent/repositories/conversation-files.repo.ts
|
|
3263
|
-
var
|
|
3659
|
+
var import_path13 = require("path");
|
|
3264
3660
|
var ConversationFilesRepo = class {
|
|
3265
3661
|
constructor(db) {
|
|
3266
3662
|
this.db = db;
|
|
@@ -3283,7 +3679,7 @@ var ConversationFilesRepo = class {
|
|
|
3283
3679
|
const info = this.db.prepare(
|
|
3284
3680
|
`INSERT INTO conversation_files (absolute_path, parent_dir, file_name, account)
|
|
3285
3681
|
VALUES (?, ?, ?, ?)`
|
|
3286
|
-
).run(canonical, (0,
|
|
3682
|
+
).run(canonical, (0, import_path13.dirname)(canonical), (0, import_path13.basename)(canonical), account);
|
|
3287
3683
|
return Number(info.lastInsertRowid);
|
|
3288
3684
|
}
|
|
3289
3685
|
// Advance the cursor + persisted reducer state after a successful index pass.
|
|
@@ -3359,6 +3755,7 @@ function rowToMeta(row) {
|
|
|
3359
3755
|
externalSessionId: row.external_session_id ?? void 0,
|
|
3360
3756
|
sessionId: row.session_id,
|
|
3361
3757
|
sessionName: row.session_name ?? "",
|
|
3758
|
+
nameSlots: row.name_slots ? JSON.parse(row.name_slots) : void 0,
|
|
3362
3759
|
projectPath: row.project_path ?? "",
|
|
3363
3760
|
projectName: row.project_name ?? "",
|
|
3364
3761
|
account: row.account,
|
|
@@ -3402,7 +3799,7 @@ var ConversationsRepo = class {
|
|
|
3402
3799
|
model, is_subagent, parent_session_id, subagent_id, parent_session_uuid,
|
|
3403
3800
|
is_teammate, team_name, tool_names_json,
|
|
3404
3801
|
last_prompt, is_imported_from_claude, is_imported_from_codex,
|
|
3405
|
-
is_imported_from_cursor, status, updated_at
|
|
3802
|
+
is_imported_from_cursor, name_slots, status, updated_at
|
|
3406
3803
|
) VALUES (
|
|
3407
3804
|
@file_id, @source_path, @provider, @kind, @external_session_id,
|
|
3408
3805
|
@session_id, @session_name, @project_path, @project_name,
|
|
@@ -3414,7 +3811,7 @@ var ConversationsRepo = class {
|
|
|
3414
3811
|
@model, @is_subagent, @parent_session_id, @subagent_id, @parent_session_uuid,
|
|
3415
3812
|
@is_teammate, @team_name, @tool_names_json,
|
|
3416
3813
|
@last_prompt, @is_imported_from_claude, @is_imported_from_codex,
|
|
3417
|
-
@is_imported_from_cursor, 'active', CURRENT_TIMESTAMP
|
|
3814
|
+
@is_imported_from_cursor, @name_slots, 'active', CURRENT_TIMESTAMP
|
|
3418
3815
|
)
|
|
3419
3816
|
ON CONFLICT(file_id) DO UPDATE SET
|
|
3420
3817
|
source_path = excluded.source_path,
|
|
@@ -3449,6 +3846,7 @@ var ConversationsRepo = class {
|
|
|
3449
3846
|
is_imported_from_claude = excluded.is_imported_from_claude,
|
|
3450
3847
|
is_imported_from_codex = excluded.is_imported_from_codex,
|
|
3451
3848
|
is_imported_from_cursor = excluded.is_imported_from_cursor,
|
|
3849
|
+
name_slots = excluded.name_slots,
|
|
3452
3850
|
status = 'active',
|
|
3453
3851
|
index_seq = (SELECT COALESCE(MAX(index_seq), 0) + 1 FROM conversations),
|
|
3454
3852
|
updated_at = CURRENT_TIMESTAMP`
|
|
@@ -3488,7 +3886,8 @@ var ConversationsRepo = class {
|
|
|
3488
3886
|
last_prompt: meta.lastPrompt ?? null,
|
|
3489
3887
|
is_imported_from_claude: meta.isImportedFromClaude ? 1 : 0,
|
|
3490
3888
|
is_imported_from_codex: meta.isImportedFromCodex ? 1 : 0,
|
|
3491
|
-
is_imported_from_cursor: meta.isImportedFromCursor ? 1 : 0
|
|
3889
|
+
is_imported_from_cursor: meta.isImportedFromCursor ? 1 : 0,
|
|
3890
|
+
name_slots: meta.nameSlots ? JSON.stringify(meta.nameSlots) : null
|
|
3492
3891
|
});
|
|
3493
3892
|
}
|
|
3494
3893
|
getBySourcePath(sourcePath) {
|
|
@@ -3869,13 +4268,18 @@ var PersistentEngine = class {
|
|
|
3869
4268
|
const tier = resolveTier(tierName, customTiers);
|
|
3870
4269
|
const filePath = canonicalPath(rawFilePath);
|
|
3871
4270
|
const existing = this.files.getByPath(filePath);
|
|
3872
|
-
const
|
|
4271
|
+
const classified = classify(filePath, existing);
|
|
4272
|
+
const stat6 = classified.stat;
|
|
4273
|
+
let change = classified.change;
|
|
3873
4274
|
if (change === "vanished" || !stat6) {
|
|
3874
4275
|
this.markDeleted(filePath);
|
|
3875
4276
|
return { meta: null, change: "vanished" };
|
|
3876
4277
|
}
|
|
3877
4278
|
if (change === "unchanged" && !force) {
|
|
3878
|
-
|
|
4279
|
+
const meta2 = this.conversations.getBySourcePath(filePath);
|
|
4280
|
+
const sideStoresMoved = provider && provider.name !== CLAUDE_CODE_PROVIDER && meta2 && JSON.stringify(nameStoreSlotsFor(provider.name, filePath, meta2.sessionId)) !== existing?.reducer_state;
|
|
4281
|
+
if (!sideStoresMoved) return { meta: meta2, change };
|
|
4282
|
+
change = "reindex";
|
|
3879
4283
|
}
|
|
3880
4284
|
if (provider && provider.name !== CLAUDE_CODE_PROVIDER) {
|
|
3881
4285
|
const meta2 = await this.indexFileWithProvider(
|
|
@@ -3957,7 +4361,7 @@ var PersistentEngine = class {
|
|
|
3957
4361
|
// provider's reducer/finalize, then the same upsert + FTS write + cursor bump
|
|
3958
4362
|
// the Threadbase path uses. The cursor records size/mtime (and offset = size)
|
|
3959
4363
|
// so the next pass classifies an unchanged file as "unchanged" and skips it;
|
|
3960
|
-
// any change reparses from 0 again.
|
|
4364
|
+
// any change reparses from 0 again. reducer_state holds the side-store name slots, not a fold.
|
|
3961
4365
|
async indexFileWithProvider(provider, filePath, account, tier, stat6, resolveGitBranch) {
|
|
3962
4366
|
const log = getLogger();
|
|
3963
4367
|
let searchDoc = emptySearchDocument();
|
|
@@ -3971,6 +4375,7 @@ var PersistentEngine = class {
|
|
|
3971
4375
|
if (meta.gitBranch === null && meta.projectPath) {
|
|
3972
4376
|
meta.gitBranch = resolveGitBranch(meta.projectPath);
|
|
3973
4377
|
}
|
|
4378
|
+
const sideSlots = nameStoreSlotsFor(provider.name, filePath, meta.sessionId);
|
|
3974
4379
|
const fp = stat6.size > 0 ? fingerprint(filePath, stat6.size) : null;
|
|
3975
4380
|
const fileId = this.files.ensure(filePath, account);
|
|
3976
4381
|
const upsert = this.db.transaction(() => {
|
|
@@ -3986,7 +4391,9 @@ var PersistentEngine = class {
|
|
|
3986
4391
|
// can classify it "unchanged"); no resumable reducer state is kept.
|
|
3987
4392
|
offset: stat6.size,
|
|
3988
4393
|
line: 0,
|
|
3989
|
-
|
|
4394
|
+
// Not resumable state: the side-store name slots this parse used, so the
|
|
4395
|
+
// next pass can tell when they moved (see indexFile).
|
|
4396
|
+
reducerState: JSON.stringify(sideSlots),
|
|
3990
4397
|
fingerprint: fp,
|
|
3991
4398
|
status: "active"
|
|
3992
4399
|
});
|
|
@@ -4066,7 +4473,7 @@ var PersistentEngine = class {
|
|
|
4066
4473
|
let floor = this.checkpoints.floor(filePath, fromIndex);
|
|
4067
4474
|
if (floor) {
|
|
4068
4475
|
try {
|
|
4069
|
-
if (floor.byteOffset > (0,
|
|
4476
|
+
if (floor.byteOffset > (0, import_fs13.statSync)(filePath).size) floor = null;
|
|
4070
4477
|
} catch {
|
|
4071
4478
|
}
|
|
4072
4479
|
}
|
|
@@ -4205,7 +4612,7 @@ function defaultDbPath() {
|
|
|
4205
4612
|
"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."
|
|
4206
4613
|
);
|
|
4207
4614
|
}
|
|
4208
|
-
return (0,
|
|
4615
|
+
return (0, import_path14.join)((0, import_os2.homedir)(), ".config", "threadbase-scanner", "index.db");
|
|
4209
4616
|
}
|
|
4210
4617
|
function capForMemory(doc, max) {
|
|
4211
4618
|
const combined = combineSearchContent(doc);
|
|
@@ -4298,6 +4705,7 @@ var ConversationScanner = class {
|
|
|
4298
4705
|
}
|
|
4299
4706
|
}
|
|
4300
4707
|
async runScan(options) {
|
|
4708
|
+
if (options.cursorStateDb !== void 0) setCursorStateDb(options.cursorStateDb);
|
|
4301
4709
|
const profiles = await this.resolveProfiles(options.profiles);
|
|
4302
4710
|
const activeProfiles = profiles.filter((p) => p.enabled && p.scanHistory !== false);
|
|
4303
4711
|
this.lastTier = resolveTier(options.tier ?? "standard", options.tiers);
|
|
@@ -4384,7 +4792,7 @@ var ConversationScanner = class {
|
|
|
4384
4792
|
const cached = statCache.get(filePath);
|
|
4385
4793
|
if (cached) {
|
|
4386
4794
|
try {
|
|
4387
|
-
const s = (0,
|
|
4795
|
+
const s = (0, import_fs14.statSync)(filePath);
|
|
4388
4796
|
if (s.mtimeMs === cached.stat.mtimeMs && s.size === cached.stat.size) {
|
|
4389
4797
|
return {
|
|
4390
4798
|
meta: cached.meta,
|
|
@@ -4932,13 +5340,13 @@ var ConversationScanner = class {
|
|
|
4932
5340
|
if (previous?.provider) return void 0;
|
|
4933
5341
|
let sample = "";
|
|
4934
5342
|
try {
|
|
4935
|
-
const fd = (0,
|
|
5343
|
+
const fd = (0, import_fs14.openSync)(filePath, "r");
|
|
4936
5344
|
try {
|
|
4937
5345
|
const buf = Buffer.alloc(8192);
|
|
4938
|
-
const n = (0,
|
|
5346
|
+
const n = (0, import_fs14.readSync)(fd, buf, 0, buf.length, 0);
|
|
4939
5347
|
sample = buf.subarray(0, n).toString("utf8");
|
|
4940
5348
|
} finally {
|
|
4941
|
-
(0,
|
|
5349
|
+
(0, import_fs14.closeSync)(fd);
|
|
4942
5350
|
}
|
|
4943
5351
|
} catch {
|
|
4944
5352
|
return void 0;
|
|
@@ -5066,11 +5474,13 @@ async function getConversation(id, options, scanner) {
|
|
|
5066
5474
|
CursorProvider,
|
|
5067
5475
|
DEFAULT_TIERS,
|
|
5068
5476
|
LEGACY_CURSOR_PROVIDER,
|
|
5477
|
+
NAME_PRECEDENCE,
|
|
5069
5478
|
SearchIndexer,
|
|
5070
5479
|
ThreadbaseProvider,
|
|
5071
5480
|
VALID_SORT_ORDERS,
|
|
5072
5481
|
applyAccountFilter,
|
|
5073
5482
|
applyIncludeFilter,
|
|
5483
|
+
applyNameCandidate,
|
|
5074
5484
|
applyPagination,
|
|
5075
5485
|
applyProjectFilter,
|
|
5076
5486
|
applySinceFilter,
|
|
@@ -5085,20 +5495,27 @@ async function getConversation(id, options, scanner) {
|
|
|
5085
5495
|
getLogger,
|
|
5086
5496
|
getProjectsDir,
|
|
5087
5497
|
isCodexInjectedContext,
|
|
5498
|
+
isValidNameCandidate,
|
|
5088
5499
|
loadProfiles,
|
|
5089
5500
|
parseCodexJsonlLine,
|
|
5090
5501
|
parseCopilotJsonlLine,
|
|
5091
5502
|
parseCursorJsonlLine,
|
|
5092
5503
|
parseJsonlLine,
|
|
5093
5504
|
providerMatches,
|
|
5505
|
+
readCodexNameSlots,
|
|
5506
|
+
readCopilotNameSlots,
|
|
5507
|
+
readCursorCliNameSlots,
|
|
5508
|
+
readCursorIdeNameSlots,
|
|
5094
5509
|
readGitBranch,
|
|
5095
5510
|
readSidecar,
|
|
5096
5511
|
resetDefaultScanner,
|
|
5097
5512
|
resolveConfigDir,
|
|
5513
|
+
resolveSessionName,
|
|
5098
5514
|
resolveTier,
|
|
5099
5515
|
saveProfiles,
|
|
5100
5516
|
scan,
|
|
5101
5517
|
search,
|
|
5518
|
+
setCursorStateDb,
|
|
5102
5519
|
setLogger,
|
|
5103
5520
|
sidecarPath,
|
|
5104
5521
|
unwrapCursorUserText
|