@threadbase-sh/scanner 0.21.1 → 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 +494 -130
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +577 -154
- 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 +549 -135
- 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.js
CHANGED
|
@@ -350,13 +350,329 @@ function toIndexDoc(meta, searchContent) {
|
|
|
350
350
|
};
|
|
351
351
|
}
|
|
352
352
|
|
|
353
|
+
// src/name-stores.ts
|
|
354
|
+
import Database from "better-sqlite3";
|
|
355
|
+
import { closeSync, existsSync, openSync, readdirSync, readFileSync as readFileSync2, readSync, statSync } from "fs";
|
|
356
|
+
import { basename, dirname as dirname2, join as join2 } from "path";
|
|
357
|
+
|
|
358
|
+
// src/tags.ts
|
|
359
|
+
var SYSTEM_TAGS = [
|
|
360
|
+
"system-reminder",
|
|
361
|
+
"command-name",
|
|
362
|
+
"command-message",
|
|
363
|
+
"command-args",
|
|
364
|
+
"ide_selection",
|
|
365
|
+
"ide_opened_file",
|
|
366
|
+
"local-command-stdout",
|
|
367
|
+
"local-command-caveat",
|
|
368
|
+
"retrieval_status",
|
|
369
|
+
"task_id",
|
|
370
|
+
"task_type",
|
|
371
|
+
"task-id",
|
|
372
|
+
"task-notification",
|
|
373
|
+
"fast_mode_info",
|
|
374
|
+
"persisted-output",
|
|
375
|
+
"tool_use_error",
|
|
376
|
+
"user-prompt-submit-hook",
|
|
377
|
+
"thinking",
|
|
378
|
+
"ask_user",
|
|
379
|
+
"teammate-message"
|
|
380
|
+
];
|
|
381
|
+
var SYSTEM_TAG_RE = new RegExp(`<(${SYSTEM_TAGS.join("|")})[^>]*>[\\s\\S]*?<\\/\\1>`, "g");
|
|
382
|
+
var PASTED_CONTENT_RE = /<pasted_content id="[0-9a-f]{4}">([\s\S]*?)<\/pasted_content(?: id="[0-9a-f]{4}")?>/g;
|
|
383
|
+
function cleanSystemTags(text) {
|
|
384
|
+
return text.replace(SYSTEM_TAG_RE, "").replace(PASTED_CONTENT_RE, "$1").replace(/[^\S\n]+/g, " ").replace(/\n{3,}/g, "\n\n").trim();
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
// src/session-name.ts
|
|
388
|
+
var NAME_PRECEDENCE = [
|
|
389
|
+
"userTitle",
|
|
390
|
+
"toolTitle",
|
|
391
|
+
"lastPrompt",
|
|
392
|
+
"firstUserMessage",
|
|
393
|
+
"slug"
|
|
394
|
+
];
|
|
395
|
+
var CLAUDE_SYSTEM_PREFIXES = [
|
|
396
|
+
"<command-name>",
|
|
397
|
+
"<command-message>",
|
|
398
|
+
"<command-args>",
|
|
399
|
+
"<local-command-stdout>",
|
|
400
|
+
"<local-command-stderr>",
|
|
401
|
+
"<local-command-caveat>",
|
|
402
|
+
"<bash-input>",
|
|
403
|
+
"<bash-stdout>",
|
|
404
|
+
"<bash-stderr>",
|
|
405
|
+
"<system-reminder>",
|
|
406
|
+
"<task-notification>",
|
|
407
|
+
"<teammate-message",
|
|
408
|
+
"Another Claude session sent a message:",
|
|
409
|
+
"[Request interrupted by user"
|
|
410
|
+
];
|
|
411
|
+
var CODEX_SYSTEM_PREFIXES = [
|
|
412
|
+
"<environment_context>",
|
|
413
|
+
"# AGENTS.md instructions",
|
|
414
|
+
"<user_instructions>",
|
|
415
|
+
"<INSTRUCTIONS>",
|
|
416
|
+
"<external_codex_apps_open",
|
|
417
|
+
"<user_shell_command>",
|
|
418
|
+
"<turn_aborted>"
|
|
419
|
+
];
|
|
420
|
+
function isCodexInjectedContext(text) {
|
|
421
|
+
if (text.startsWith("# AGENTS.md") || text.includes("<INSTRUCTIONS>")) return true;
|
|
422
|
+
return text.startsWith("<permissions instructions>") || text.includes("Filesystem sandboxing defines");
|
|
423
|
+
}
|
|
424
|
+
var CODEX_IMAGE_TAG_RE = /<\/?image\b[^>]*>/g;
|
|
425
|
+
function normalizeCandidate(text, provider) {
|
|
426
|
+
let t = text.trim();
|
|
427
|
+
if (provider === "codex-cli") t = t.replace(CODEX_IMAGE_TAG_RE, "").trim();
|
|
428
|
+
const prefixes = provider === "claude-code" ? CLAUDE_SYSTEM_PREFIXES : provider === "codex-cli" ? CODEX_SYSTEM_PREFIXES : [];
|
|
429
|
+
if (prefixes.some((p) => t.startsWith(p))) return null;
|
|
430
|
+
if (provider === "codex-cli" && isCodexInjectedContext(t)) return null;
|
|
431
|
+
return cleanSystemTags(t) || null;
|
|
432
|
+
}
|
|
433
|
+
function isValidNameCandidate(text, provider) {
|
|
434
|
+
return normalizeCandidate(text, provider) !== null;
|
|
435
|
+
}
|
|
436
|
+
function resolveSessionName(slots) {
|
|
437
|
+
for (const slot of NAME_PRECEDENCE) {
|
|
438
|
+
const value = slots[slot];
|
|
439
|
+
if (value?.trim()) return { name: value, source: slot };
|
|
440
|
+
}
|
|
441
|
+
return { name: null, source: null };
|
|
442
|
+
}
|
|
443
|
+
function applyNameCandidate(slots, slot, raw, provider) {
|
|
444
|
+
if (typeof raw !== "string") return slots;
|
|
445
|
+
if (slot === "firstUserMessage" && slots.firstUserMessage !== void 0) return slots;
|
|
446
|
+
const text = normalizeCandidate(raw, provider);
|
|
447
|
+
return text === null ? slots : { ...slots, [slot]: text };
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
// src/name-stores.ts
|
|
451
|
+
function slotsFrom(provider, candidates) {
|
|
452
|
+
return candidates.reduce(
|
|
453
|
+
(slots, [slot, raw]) => applyNameCandidate(slots, slot, typeof raw === "string" ? raw : void 0, provider),
|
|
454
|
+
{}
|
|
455
|
+
);
|
|
456
|
+
}
|
|
457
|
+
function readJson(path) {
|
|
458
|
+
try {
|
|
459
|
+
return JSON.parse(readFileSync2(path, "utf8"));
|
|
460
|
+
} catch {
|
|
461
|
+
return void 0;
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
function queryOne(dbPath, sql, ...params) {
|
|
465
|
+
let db;
|
|
466
|
+
try {
|
|
467
|
+
db = new Database(dbPath, { readonly: true, fileMustExist: true, timeout: 250 });
|
|
468
|
+
return db.prepare(sql).get(...params);
|
|
469
|
+
} catch (err) {
|
|
470
|
+
getLogger().debug({ dbPath, err }, "name store: query failed");
|
|
471
|
+
return void 0;
|
|
472
|
+
} finally {
|
|
473
|
+
db?.close();
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
var lastByIdCache = /* @__PURE__ */ new Map();
|
|
477
|
+
function lastValueById(path, idField, valueField) {
|
|
478
|
+
let sig;
|
|
479
|
+
try {
|
|
480
|
+
const s = statSync(path);
|
|
481
|
+
sig = `${s.mtimeMs}:${s.size}`;
|
|
482
|
+
} catch {
|
|
483
|
+
return /* @__PURE__ */ new Map();
|
|
484
|
+
}
|
|
485
|
+
const key = `${path}\0${idField}\0${valueField}`;
|
|
486
|
+
const cached = lastByIdCache.get(key);
|
|
487
|
+
if (cached?.sig === sig) return cached.map;
|
|
488
|
+
const map = /* @__PURE__ */ new Map();
|
|
489
|
+
try {
|
|
490
|
+
for (const line of readFileSync2(path, "utf8").split("\n")) {
|
|
491
|
+
if (!line.trim()) continue;
|
|
492
|
+
try {
|
|
493
|
+
const row = JSON.parse(line);
|
|
494
|
+
const id = row[idField];
|
|
495
|
+
const value = row[valueField];
|
|
496
|
+
if (typeof id === "string" && typeof value === "string") map.set(id, value);
|
|
497
|
+
} catch {
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
} catch {
|
|
501
|
+
}
|
|
502
|
+
lastByIdCache.set(key, { sig, map });
|
|
503
|
+
return map;
|
|
504
|
+
}
|
|
505
|
+
function readCodexNameSlots(codexHome, id) {
|
|
506
|
+
const index = lastValueById(join2(codexHome, "session_index.jsonl"), "id", "thread_name");
|
|
507
|
+
const history = lastValueById(join2(codexHome, "history.jsonl"), "session_id", "text");
|
|
508
|
+
let title = index.get(id);
|
|
509
|
+
if (!index.has(id)) {
|
|
510
|
+
title = queryOne(
|
|
511
|
+
join2(codexHome, "state_5.sqlite"),
|
|
512
|
+
"SELECT name FROM threads WHERE id = ?",
|
|
513
|
+
id
|
|
514
|
+
)?.name;
|
|
515
|
+
}
|
|
516
|
+
return slotsFrom("codex-cli", [
|
|
517
|
+
["toolTitle", title],
|
|
518
|
+
["lastPrompt", history.get(id)]
|
|
519
|
+
]);
|
|
520
|
+
}
|
|
521
|
+
function readCursorCliNameSlots(chatsDir, id) {
|
|
522
|
+
let chat;
|
|
523
|
+
try {
|
|
524
|
+
chat = readdirSync(chatsDir).map((hash) => join2(chatsDir, hash, id)).find((p) => existsSync(p));
|
|
525
|
+
} catch {
|
|
526
|
+
}
|
|
527
|
+
if (!chat) return {};
|
|
528
|
+
const meta = readJson(join2(chat, "meta.json"));
|
|
529
|
+
const history = readJson(join2(chat, "prompt_history.json"));
|
|
530
|
+
let title = meta?.title;
|
|
531
|
+
if (typeof title !== "string" || !title.trim()) title = storeDbName(join2(chat, "store.db"));
|
|
532
|
+
return slotsFrom("cursor", [
|
|
533
|
+
["toolTitle", title],
|
|
534
|
+
["lastPrompt", Array.isArray(history) ? history[0] : void 0]
|
|
535
|
+
]);
|
|
536
|
+
}
|
|
537
|
+
function storeDbName(dbPath) {
|
|
538
|
+
const row = queryOne(
|
|
539
|
+
dbPath,
|
|
540
|
+
"SELECT value FROM meta WHERE key = '0'"
|
|
541
|
+
);
|
|
542
|
+
if (!row) return void 0;
|
|
543
|
+
try {
|
|
544
|
+
const text = row.value.toString();
|
|
545
|
+
const json = /^(?:[0-9a-f]{2})+$/i.test(text) ? Buffer.from(text, "hex").toString("utf8") : text;
|
|
546
|
+
const name = JSON.parse(json).name;
|
|
547
|
+
return typeof name === "string" ? name : void 0;
|
|
548
|
+
} catch {
|
|
549
|
+
return void 0;
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
function readCursorIdeNameSlots(stateDbPath, id) {
|
|
553
|
+
const row = queryOne(
|
|
554
|
+
stateDbPath,
|
|
555
|
+
"SELECT json_extract(CAST(value AS TEXT), '$.name') AS name FROM cursorDiskKV WHERE key = ?",
|
|
556
|
+
`composerData:${id}`
|
|
557
|
+
);
|
|
558
|
+
return slotsFrom("cursor", [["toolTitle", row?.name]]);
|
|
559
|
+
}
|
|
560
|
+
function yamlScalar(text, key) {
|
|
561
|
+
const m = text.match(new RegExp(`^${key}:[ \\t]*(.*)$`, "m"));
|
|
562
|
+
const v = m?.[1].trim().replace(/^(["'])(.*)\1$/, "$2");
|
|
563
|
+
return v || void 0;
|
|
564
|
+
}
|
|
565
|
+
function readCopilotTitleSlots(sessionDir) {
|
|
566
|
+
const id = basename(sessionDir);
|
|
567
|
+
let yaml = "";
|
|
568
|
+
try {
|
|
569
|
+
yaml = readFileSync2(join2(sessionDir, "workspace.yaml"), "utf8");
|
|
570
|
+
} catch {
|
|
571
|
+
}
|
|
572
|
+
const name = yamlScalar(yaml, "name");
|
|
573
|
+
if (name) {
|
|
574
|
+
return slotsFrom("copilot", [
|
|
575
|
+
[yamlScalar(yaml, "user_named") === "true" ? "userTitle" : "toolTitle", name]
|
|
576
|
+
]);
|
|
577
|
+
}
|
|
578
|
+
const row = queryOne(
|
|
579
|
+
join2(dirname2(dirname2(sessionDir)), "session-store.db"),
|
|
580
|
+
"SELECT summary FROM sessions WHERE id = ?",
|
|
581
|
+
id
|
|
582
|
+
);
|
|
583
|
+
return slotsFrom("copilot", [["toolTitle", row?.summary]]);
|
|
584
|
+
}
|
|
585
|
+
function readCopilotNameSlots(sessionDir) {
|
|
586
|
+
return {
|
|
587
|
+
...readCopilotTitleSlots(sessionDir),
|
|
588
|
+
...slotsFrom("copilot", [
|
|
589
|
+
["firstUserMessage", firstCopilotUserMessage(join2(sessionDir, "events.jsonl"))]
|
|
590
|
+
])
|
|
591
|
+
};
|
|
592
|
+
}
|
|
593
|
+
function firstCopilotUserMessage(path) {
|
|
594
|
+
let fd;
|
|
595
|
+
try {
|
|
596
|
+
fd = openSync(path, "r");
|
|
597
|
+
} catch {
|
|
598
|
+
return void 0;
|
|
599
|
+
}
|
|
600
|
+
try {
|
|
601
|
+
const buf = Buffer.alloc(64 * 1024);
|
|
602
|
+
let pending = "";
|
|
603
|
+
for (let n = readSync(fd, buf, 0, buf.length, null); n > 0; n = readSync(fd, buf, 0, buf.length, null)) {
|
|
604
|
+
pending += buf.toString("utf8", 0, n);
|
|
605
|
+
const lines = pending.split("\n");
|
|
606
|
+
pending = lines.pop() ?? "";
|
|
607
|
+
for (const line of lines) {
|
|
608
|
+
try {
|
|
609
|
+
const e = JSON.parse(line);
|
|
610
|
+
if (e.type === "user.message" && typeof e.data?.content === "string")
|
|
611
|
+
return e.data.content;
|
|
612
|
+
} catch {
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
return void 0;
|
|
617
|
+
} catch {
|
|
618
|
+
return void 0;
|
|
619
|
+
} finally {
|
|
620
|
+
closeSync(fd);
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
function findUp(start, hasStore, levels) {
|
|
624
|
+
let dir = start;
|
|
625
|
+
for (let i = 0; i < levels; i++) {
|
|
626
|
+
if (hasStore(dir)) return dir;
|
|
627
|
+
const parent = dirname2(dir);
|
|
628
|
+
if (parent === dir) break;
|
|
629
|
+
dir = parent;
|
|
630
|
+
}
|
|
631
|
+
return null;
|
|
632
|
+
}
|
|
633
|
+
function codexNameSlotsFor(rolloutPath, id) {
|
|
634
|
+
const home = findUp(
|
|
635
|
+
dirname2(rolloutPath),
|
|
636
|
+
(d) => ["session_index.jsonl", "history.jsonl", "state_5.sqlite"].some(
|
|
637
|
+
(f) => existsSync(join2(d, f))
|
|
638
|
+
),
|
|
639
|
+
6
|
|
640
|
+
);
|
|
641
|
+
return home ? readCodexNameSlots(home, id) : {};
|
|
642
|
+
}
|
|
643
|
+
var cursorStateDb;
|
|
644
|
+
function setCursorStateDb(path) {
|
|
645
|
+
cursorStateDb = path;
|
|
646
|
+
}
|
|
647
|
+
function cursorNameSlotsFor(transcriptPath, id) {
|
|
648
|
+
const home = findUp(dirname2(transcriptPath), (d) => existsSync(join2(d, "chats")), 6);
|
|
649
|
+
const cli = home ? readCursorCliNameSlots(join2(home, "chats"), id) : {};
|
|
650
|
+
if (cli.toolTitle || !cursorStateDb) return cli;
|
|
651
|
+
return { ...cli, ...readCursorIdeNameSlots(cursorStateDb, id) };
|
|
652
|
+
}
|
|
653
|
+
function copilotNameSlotsFor(eventsPath) {
|
|
654
|
+
return readCopilotTitleSlots(dirname2(eventsPath));
|
|
655
|
+
}
|
|
656
|
+
function nameStoreSlotsFor(provider, filePath, sessionId) {
|
|
657
|
+
switch (provider) {
|
|
658
|
+
case "codex-cli":
|
|
659
|
+
return codexNameSlotsFor(filePath, sessionId);
|
|
660
|
+
case "cursor":
|
|
661
|
+
return cursorNameSlotsFor(filePath, basename(filePath, ".jsonl"));
|
|
662
|
+
case "copilot":
|
|
663
|
+
return copilotNameSlotsFor(filePath);
|
|
664
|
+
default:
|
|
665
|
+
return {};
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
|
|
353
669
|
// src/parser.ts
|
|
354
670
|
import { createReadStream } from "fs";
|
|
355
|
-
import { basename as
|
|
671
|
+
import { basename as basename3 } from "path";
|
|
356
672
|
import { createInterface } from "readline";
|
|
357
673
|
|
|
358
674
|
// src/persistent/metadata-reducer.ts
|
|
359
|
-
import { basename, dirname as
|
|
675
|
+
import { basename as basename2, dirname as dirname3, join as join3 } from "path";
|
|
360
676
|
|
|
361
677
|
// src/providers/provider.ts
|
|
362
678
|
var CLAUDE_CODE_PROVIDER = "claude-code";
|
|
@@ -386,11 +702,36 @@ function providerMatches(stored, wanted) {
|
|
|
386
702
|
return a === b;
|
|
387
703
|
}
|
|
388
704
|
|
|
705
|
+
// src/persistent/claude-name-slots.ts
|
|
706
|
+
function userPromptText(entry) {
|
|
707
|
+
if (entry.isMeta || entry.isCompactSummary === true) return "";
|
|
708
|
+
const content = entry.message?.content;
|
|
709
|
+
if (typeof content === "string") return content;
|
|
710
|
+
if (!Array.isArray(content)) return "";
|
|
711
|
+
return content.map((b) => typeof b === "string" ? b : b?.type === "text" ? b.text : "").filter((t) => typeof t === "string" && t !== "").join(" ");
|
|
712
|
+
}
|
|
713
|
+
function applyClaudeNameEntry(slots, entry) {
|
|
714
|
+
const apply = (slot, raw) => applyNameCandidate(slots, slot, typeof raw === "string" ? raw : void 0, "claude-code");
|
|
715
|
+
if (entry.slug !== slots.slug) slots = apply("slug", entry.slug);
|
|
716
|
+
switch (entry.type) {
|
|
717
|
+
case "custom-title":
|
|
718
|
+
return apply("userTitle", entry.customTitle);
|
|
719
|
+
case "ai-title":
|
|
720
|
+
return apply("toolTitle", entry.aiTitle);
|
|
721
|
+
case "last-prompt":
|
|
722
|
+
return apply("lastPrompt", entry.lastPrompt);
|
|
723
|
+
case "user":
|
|
724
|
+
return slots.firstUserMessage === void 0 ? apply("firstUserMessage", userPromptText(entry)) : slots;
|
|
725
|
+
default:
|
|
726
|
+
return slots;
|
|
727
|
+
}
|
|
728
|
+
}
|
|
729
|
+
|
|
389
730
|
// src/persistent/metadata-reducer.ts
|
|
390
731
|
function initialReducerState() {
|
|
391
732
|
return {
|
|
392
733
|
sessionId: "",
|
|
393
|
-
|
|
734
|
+
nameSlots: {},
|
|
394
735
|
latestTimestamp: "",
|
|
395
736
|
cwd: "",
|
|
396
737
|
teamName: "",
|
|
@@ -416,7 +757,7 @@ function initialReducerState() {
|
|
|
416
757
|
function reduceLine(state, entry, tier) {
|
|
417
758
|
if (entry.cwd && !state.cwd) state.cwd = entry.cwd;
|
|
418
759
|
if (entry.sessionId && !state.sessionId) state.sessionId = entry.sessionId;
|
|
419
|
-
|
|
760
|
+
state.nameSlots = applyClaudeNameEntry(state.nameSlots, entry);
|
|
420
761
|
if (entry.teamName && !state.teamName) state.teamName = entry.teamName;
|
|
421
762
|
if (entry.agentId && !state.agentId) state.agentId = entry.agentId;
|
|
422
763
|
if (entry.isSidechain === true) state.isSidechain = true;
|
|
@@ -480,16 +821,16 @@ function finalizeMeta(state, filePath, account, tier) {
|
|
|
480
821
|
const isSubagent = isSidechain || isSubagentPath;
|
|
481
822
|
let parentSessionId = null;
|
|
482
823
|
if (isSubagentPath) {
|
|
483
|
-
const uuidDir =
|
|
484
|
-
parentSessionId =
|
|
824
|
+
const uuidDir = dirname3(dirname3(filePath));
|
|
825
|
+
parentSessionId = join3(dirname3(uuidDir), `${basename2(uuidDir)}.jsonl`);
|
|
485
826
|
}
|
|
486
827
|
const projectPath = state.cwd;
|
|
487
828
|
return {
|
|
488
829
|
id: filePath,
|
|
489
830
|
filePath,
|
|
490
831
|
provider: CLAUDE_CODE_PROVIDER,
|
|
491
|
-
sessionId: state.sessionId ||
|
|
492
|
-
sessionName: state.
|
|
832
|
+
sessionId: state.sessionId || basename2(filePath, ".jsonl"),
|
|
833
|
+
sessionName: resolveSessionName(state.nameSlots).name ?? "",
|
|
493
834
|
projectPath,
|
|
494
835
|
projectName: getShortProjectName(projectPath),
|
|
495
836
|
account,
|
|
@@ -515,44 +856,11 @@ function finalizeMeta(state, filePath, account, tier) {
|
|
|
515
856
|
};
|
|
516
857
|
}
|
|
517
858
|
var SUBAGENT_PATH_RE = /[\\/]subagents[\\/]/;
|
|
518
|
-
function deriveSessionNameFromFirstMessage(firstMessage) {
|
|
519
|
-
const firstLine = firstMessage?.text.split("\n", 1)[0]?.trim() ?? "";
|
|
520
|
-
return firstLine.slice(0, 80);
|
|
521
|
-
}
|
|
522
859
|
function getShortProjectName(fullPath) {
|
|
523
860
|
const parts = fullPath.split("/").filter(Boolean);
|
|
524
861
|
return parts.slice(-3).join("/");
|
|
525
862
|
}
|
|
526
863
|
|
|
527
|
-
// src/tags.ts
|
|
528
|
-
var SYSTEM_TAGS = [
|
|
529
|
-
"system-reminder",
|
|
530
|
-
"command-name",
|
|
531
|
-
"command-message",
|
|
532
|
-
"command-args",
|
|
533
|
-
"ide_selection",
|
|
534
|
-
"ide_opened_file",
|
|
535
|
-
"local-command-stdout",
|
|
536
|
-
"local-command-caveat",
|
|
537
|
-
"retrieval_status",
|
|
538
|
-
"task_id",
|
|
539
|
-
"task_type",
|
|
540
|
-
"task-id",
|
|
541
|
-
"task-notification",
|
|
542
|
-
"fast_mode_info",
|
|
543
|
-
"persisted-output",
|
|
544
|
-
"tool_use_error",
|
|
545
|
-
"user-prompt-submit-hook",
|
|
546
|
-
"thinking",
|
|
547
|
-
"ask_user",
|
|
548
|
-
"teammate-message"
|
|
549
|
-
];
|
|
550
|
-
var SYSTEM_TAG_RE = new RegExp(`<(${SYSTEM_TAGS.join("|")})[^>]*>[\\s\\S]*?<\\/\\1>`, "g");
|
|
551
|
-
var PASTED_CONTENT_RE = /<pasted_content id="[0-9a-f]{4}">([\s\S]*?)<\/pasted_content(?: id="[0-9a-f]{4}")?>/g;
|
|
552
|
-
function cleanSystemTags(text) {
|
|
553
|
-
return text.replace(SYSTEM_TAG_RE, "").replace(PASTED_CONTENT_RE, "$1").replace(/[^\S\n]+/g, " ").replace(/\n{3,}/g, "\n\n").trim();
|
|
554
|
-
}
|
|
555
|
-
|
|
556
864
|
// src/parser.ts
|
|
557
865
|
async function parseMeta(filePath, account, tier, onEntry) {
|
|
558
866
|
const log = getLogger();
|
|
@@ -639,10 +947,8 @@ async function parseConversation(filePath, account) {
|
|
|
639
947
|
filePath,
|
|
640
948
|
projectPath: state.cwd,
|
|
641
949
|
projectName: getShortProjectName2(state.cwd),
|
|
642
|
-
sessionId: state.sessionId ||
|
|
643
|
-
sessionName: state.
|
|
644
|
-
messages.find((m) => m.role === "user" && m.text && !m.isCompactSummary) ?? null
|
|
645
|
-
),
|
|
950
|
+
sessionId: state.sessionId || basename3(filePath, ".jsonl"),
|
|
951
|
+
sessionName: resolveSessionName(state.nameSlots).name ?? "",
|
|
646
952
|
messages,
|
|
647
953
|
fullText: textParts.join(" "),
|
|
648
954
|
timestamp: state.latestTimestamp || (/* @__PURE__ */ new Date()).toISOString(),
|
|
@@ -752,7 +1058,7 @@ function initialConvState() {
|
|
|
752
1058
|
return {
|
|
753
1059
|
cwd: "",
|
|
754
1060
|
sessionId: "",
|
|
755
|
-
|
|
1061
|
+
nameSlots: {},
|
|
756
1062
|
latestTimestamp: "",
|
|
757
1063
|
lastPrompt: "",
|
|
758
1064
|
pendingToolUses: {},
|
|
@@ -762,7 +1068,7 @@ function initialConvState() {
|
|
|
762
1068
|
function reduceConvLine(state, entry) {
|
|
763
1069
|
if (entry.cwd && !state.cwd) state.cwd = entry.cwd;
|
|
764
1070
|
if (entry.sessionId && !state.sessionId) state.sessionId = entry.sessionId;
|
|
765
|
-
|
|
1071
|
+
state.nameSlots = applyClaudeNameEntry(state.nameSlots, entry);
|
|
766
1072
|
if (entry.timestamp) {
|
|
767
1073
|
const ts = entry.timestamp;
|
|
768
1074
|
if (!state.latestTimestamp || ts > state.latestTimestamp) state.latestTimestamp = ts;
|
|
@@ -870,7 +1176,7 @@ function applyTeamInfo(messages, state) {
|
|
|
870
1176
|
}
|
|
871
1177
|
|
|
872
1178
|
// src/persistent/sidecar.ts
|
|
873
|
-
import { readFileSync as
|
|
1179
|
+
import { readFileSync as readFileSync3, writeFileSync } from "fs";
|
|
874
1180
|
var SIDECAR_VERSION = 1;
|
|
875
1181
|
function sidecarPath(jsonlPath) {
|
|
876
1182
|
return `${jsonlPath}.idx.json`;
|
|
@@ -903,7 +1209,7 @@ function writeSidecar(jsonlPath, sidecar) {
|
|
|
903
1209
|
}
|
|
904
1210
|
function readSidecar(jsonlPath) {
|
|
905
1211
|
try {
|
|
906
|
-
return JSON.parse(
|
|
1212
|
+
return JSON.parse(readFileSync3(sidecarPath(jsonlPath), "utf-8"));
|
|
907
1213
|
} catch {
|
|
908
1214
|
return null;
|
|
909
1215
|
}
|
|
@@ -912,19 +1218,19 @@ function readSidecar(jsonlPath) {
|
|
|
912
1218
|
// src/profiles.ts
|
|
913
1219
|
import { mkdir, readFile, writeFile } from "fs/promises";
|
|
914
1220
|
import { homedir } from "os";
|
|
915
|
-
import { join as
|
|
1221
|
+
import { join as join4 } from "path";
|
|
916
1222
|
var PROFILES_FILE = "profiles.json";
|
|
917
1223
|
function resolveConfigDir(configDir) {
|
|
918
1224
|
return configDir.replace(/^~/, homedir());
|
|
919
1225
|
}
|
|
920
1226
|
function getProjectsDir(profile) {
|
|
921
|
-
return
|
|
1227
|
+
return join4(resolveConfigDir(profile.configDir), "projects");
|
|
922
1228
|
}
|
|
923
1229
|
async function detectDefaultProfile() {
|
|
924
1230
|
return {
|
|
925
1231
|
id: "default",
|
|
926
1232
|
label: "Default",
|
|
927
|
-
configDir:
|
|
1233
|
+
configDir: join4(homedir(), ".claude"),
|
|
928
1234
|
enabled: true,
|
|
929
1235
|
emoji: "\u{1F916}"
|
|
930
1236
|
};
|
|
@@ -933,7 +1239,7 @@ async function loadProfiles(configPath) {
|
|
|
933
1239
|
const log = getLogger();
|
|
934
1240
|
try {
|
|
935
1241
|
const resolved = resolveConfigDir(configPath);
|
|
936
|
-
const data = await readFile(
|
|
1242
|
+
const data = await readFile(join4(resolved, PROFILES_FILE), "utf-8");
|
|
937
1243
|
const profiles = JSON.parse(data);
|
|
938
1244
|
log.debug({ configPath, count: profiles.length }, "profiles: loaded");
|
|
939
1245
|
return profiles;
|
|
@@ -946,7 +1252,7 @@ async function loadProfiles(configPath) {
|
|
|
946
1252
|
async function saveProfiles(profiles, configPath) {
|
|
947
1253
|
const resolved = resolveConfigDir(configPath);
|
|
948
1254
|
await mkdir(resolved, { recursive: true });
|
|
949
|
-
await writeFile(
|
|
1255
|
+
await writeFile(join4(resolved, PROFILES_FILE), JSON.stringify(profiles, null, 2));
|
|
950
1256
|
getLogger().debug({ configPath, count: profiles.length }, "profiles: saved");
|
|
951
1257
|
}
|
|
952
1258
|
|
|
@@ -954,7 +1260,7 @@ async function saveProfiles(profiles, configPath) {
|
|
|
954
1260
|
import fg from "fast-glob";
|
|
955
1261
|
import { createReadStream as createReadStream2 } from "fs";
|
|
956
1262
|
import { stat } from "fs/promises";
|
|
957
|
-
import { basename as
|
|
1263
|
+
import { basename as basename4 } from "path";
|
|
958
1264
|
import { createInterface as createInterface2 } from "readline";
|
|
959
1265
|
|
|
960
1266
|
// src/canonical-path.ts
|
|
@@ -1020,6 +1326,7 @@ var CodexCliProvider = class {
|
|
|
1020
1326
|
isSubagent: false,
|
|
1021
1327
|
parentSessionUuid: null,
|
|
1022
1328
|
firstUser: null,
|
|
1329
|
+
nameSlots: {},
|
|
1023
1330
|
lastUser: null,
|
|
1024
1331
|
lastAssistant: null,
|
|
1025
1332
|
toolNames: [],
|
|
@@ -1182,6 +1489,7 @@ function reduceCodexEntry(acc, entry, tier) {
|
|
|
1182
1489
|
const snapshot = { text: text.slice(0, 200), timestamp: ts };
|
|
1183
1490
|
if (sender === "user") {
|
|
1184
1491
|
if (!acc.firstUser) acc.firstUser = snapshot;
|
|
1492
|
+
acc.nameSlots = applyNameCandidate(acc.nameSlots, "firstUserMessage", text, CODEX_CLI_PROVIDER);
|
|
1185
1493
|
acc.lastUser = snapshot;
|
|
1186
1494
|
} else {
|
|
1187
1495
|
acc.lastAssistant = snapshot;
|
|
@@ -1199,7 +1507,7 @@ function reduceCodexEntry(acc, entry, tier) {
|
|
|
1199
1507
|
}
|
|
1200
1508
|
function finalizeCodexMeta(acc, filePath, account, tier) {
|
|
1201
1509
|
if (acc.messageCount === 0) return null;
|
|
1202
|
-
const sessionId = acc.sessionId ||
|
|
1510
|
+
const sessionId = acc.sessionId || basename4(filePath, ".jsonl");
|
|
1203
1511
|
const projectPath = acc.cwd;
|
|
1204
1512
|
const kind = acc.lastAssistant === null && acc.toolNames.length > 0 ? "task" : "conversation";
|
|
1205
1513
|
return {
|
|
@@ -1209,10 +1517,7 @@ function finalizeCodexMeta(acc, filePath, account, tier) {
|
|
|
1209
1517
|
kind,
|
|
1210
1518
|
externalSessionId: acc.sessionId || void 0,
|
|
1211
1519
|
sessionId,
|
|
1212
|
-
|
|
1213
|
-
// is the only human-readable name source. Only useful because the injected
|
|
1214
|
-
// AGENTS.md turn is skipped above — otherwise every title would be that blob.
|
|
1215
|
-
sessionName: deriveSessionNameFromFirstMessage(acc.firstUser),
|
|
1520
|
+
sessionName: resolveSessionName({ ...acc.nameSlots, ...codexNameSlotsFor(filePath, acc.sessionId) }).name ?? "",
|
|
1216
1521
|
projectPath,
|
|
1217
1522
|
projectName: getShortProjectName3(projectPath),
|
|
1218
1523
|
account,
|
|
@@ -1235,10 +1540,6 @@ function finalizeCodexMeta(acc, filePath, account, tier) {
|
|
|
1235
1540
|
lastPrompt: acc.lastUser?.text || void 0
|
|
1236
1541
|
};
|
|
1237
1542
|
}
|
|
1238
|
-
function isCodexInjectedContext(text) {
|
|
1239
|
-
if (text.startsWith("# AGENTS.md") || text.includes("<INSTRUCTIONS>")) return true;
|
|
1240
|
-
return text.startsWith("<permissions instructions>") || text.includes("Filesystem sandboxing defines");
|
|
1241
|
-
}
|
|
1242
1543
|
function getShortProjectName3(fullPath) {
|
|
1243
1544
|
return fullPath.split("/").filter(Boolean).slice(-3).join("/");
|
|
1244
1545
|
}
|
|
@@ -1261,6 +1562,7 @@ async function parseCodexConversation(filePath, account) {
|
|
|
1261
1562
|
let cwd = "";
|
|
1262
1563
|
let latestTimestamp = "";
|
|
1263
1564
|
let lastUserText = "";
|
|
1565
|
+
let nameSlots = {};
|
|
1264
1566
|
const rl = createInterface2({ input: createReadStream2(filePath), crlfDelay: Infinity });
|
|
1265
1567
|
try {
|
|
1266
1568
|
for await (const line of rl) {
|
|
@@ -1285,7 +1587,15 @@ async function parseCodexConversation(filePath, account) {
|
|
|
1285
1587
|
messages.push(message);
|
|
1286
1588
|
if (!message.text) continue;
|
|
1287
1589
|
textParts.push(message.text);
|
|
1288
|
-
if (message.role === "user")
|
|
1590
|
+
if (message.role === "user") {
|
|
1591
|
+
lastUserText = message.text;
|
|
1592
|
+
nameSlots = applyNameCandidate(
|
|
1593
|
+
nameSlots,
|
|
1594
|
+
"firstUserMessage",
|
|
1595
|
+
message.text,
|
|
1596
|
+
CODEX_CLI_PROVIDER
|
|
1597
|
+
);
|
|
1598
|
+
}
|
|
1289
1599
|
}
|
|
1290
1600
|
} catch (err) {
|
|
1291
1601
|
log.warn({ filePath, err }, "parseCodexConversation: read failed");
|
|
@@ -1297,8 +1607,8 @@ async function parseCodexConversation(filePath, account) {
|
|
|
1297
1607
|
filePath,
|
|
1298
1608
|
projectPath: cwd,
|
|
1299
1609
|
projectName: getShortProjectName3(cwd),
|
|
1300
|
-
sessionId: sessionId ||
|
|
1301
|
-
sessionName: "",
|
|
1610
|
+
sessionId: sessionId || basename4(filePath, ".jsonl"),
|
|
1611
|
+
sessionName: resolveSessionName({ ...nameSlots, ...codexNameSlotsFor(filePath, sessionId) }).name ?? "",
|
|
1302
1612
|
messages,
|
|
1303
1613
|
fullText: textParts.join(" "),
|
|
1304
1614
|
timestamp: latestTimestamp || (/* @__PURE__ */ new Date()).toISOString(),
|
|
@@ -1310,9 +1620,9 @@ async function parseCodexConversation(filePath, account) {
|
|
|
1310
1620
|
|
|
1311
1621
|
// src/providers/copilot.ts
|
|
1312
1622
|
import fg2 from "fast-glob";
|
|
1313
|
-
import { createReadStream as createReadStream3, statSync } from "fs";
|
|
1623
|
+
import { createReadStream as createReadStream3, statSync as statSync2 } from "fs";
|
|
1314
1624
|
import { stat as stat2 } from "fs/promises";
|
|
1315
|
-
import { basename as
|
|
1625
|
+
import { basename as basename5, dirname as dirname4 } from "path";
|
|
1316
1626
|
import { createInterface as createInterface3 } from "readline";
|
|
1317
1627
|
var SESSION_START = "session.start";
|
|
1318
1628
|
var USER_MESSAGE = "user.message";
|
|
@@ -1366,6 +1676,7 @@ var CopilotProvider = class {
|
|
|
1366
1676
|
messageCount: 0,
|
|
1367
1677
|
lastMessageSender: "user",
|
|
1368
1678
|
firstUser: null,
|
|
1679
|
+
nameSlots: {},
|
|
1369
1680
|
lastUser: null,
|
|
1370
1681
|
lastAssistant: null,
|
|
1371
1682
|
toolNames: [],
|
|
@@ -1473,6 +1784,7 @@ function reduceCopilotEntry(acc, entry, tier) {
|
|
|
1473
1784
|
const snapshot = { text: text.slice(0, 200), timestamp };
|
|
1474
1785
|
if (role === "user") {
|
|
1475
1786
|
if (!acc.firstUser) acc.firstUser = snapshot;
|
|
1787
|
+
acc.nameSlots = applyNameCandidate(acc.nameSlots, "firstUserMessage", text, COPILOT_PROVIDER);
|
|
1476
1788
|
acc.lastUser = snapshot;
|
|
1477
1789
|
} else {
|
|
1478
1790
|
acc.lastAssistant = snapshot;
|
|
@@ -1499,7 +1811,7 @@ function finalizeCopilotMeta(acc, filePath, account, tier) {
|
|
|
1499
1811
|
kind,
|
|
1500
1812
|
externalSessionId: sessionId,
|
|
1501
1813
|
sessionId,
|
|
1502
|
-
sessionName:
|
|
1814
|
+
sessionName: resolveSessionName({ ...acc.nameSlots, ...copilotNameSlotsFor(filePath) }).name ?? "",
|
|
1503
1815
|
projectPath: acc.cwd,
|
|
1504
1816
|
projectName: getShortProjectName4(acc.cwd),
|
|
1505
1817
|
account,
|
|
@@ -1521,14 +1833,14 @@ function finalizeCopilotMeta(acc, filePath, account, tier) {
|
|
|
1521
1833
|
};
|
|
1522
1834
|
}
|
|
1523
1835
|
function sessionIdFromPath(filePath) {
|
|
1524
|
-
return
|
|
1836
|
+
return basename5(dirname4(filePath));
|
|
1525
1837
|
}
|
|
1526
1838
|
function getShortProjectName4(fullPath) {
|
|
1527
1839
|
return fullPath.split(/[/\\]/).filter(Boolean).slice(-3).join("/");
|
|
1528
1840
|
}
|
|
1529
1841
|
function fileMtimeIso(filePath) {
|
|
1530
1842
|
try {
|
|
1531
|
-
return new Date(
|
|
1843
|
+
return new Date(statSync2(filePath).mtimeMs).toISOString();
|
|
1532
1844
|
} catch {
|
|
1533
1845
|
return (/* @__PURE__ */ new Date()).toISOString();
|
|
1534
1846
|
}
|
|
@@ -1541,6 +1853,7 @@ async function parseCopilotConversation(filePath, account) {
|
|
|
1541
1853
|
let cwd = "";
|
|
1542
1854
|
let latestTimestamp = "";
|
|
1543
1855
|
let lastUserText = "";
|
|
1856
|
+
let nameSlots = {};
|
|
1544
1857
|
const rl = createInterface3({ input: createReadStream3(filePath), crlfDelay: Infinity });
|
|
1545
1858
|
try {
|
|
1546
1859
|
for await (const line of rl) {
|
|
@@ -1565,7 +1878,15 @@ async function parseCopilotConversation(filePath, account) {
|
|
|
1565
1878
|
messages.push(message);
|
|
1566
1879
|
if (!message.text) continue;
|
|
1567
1880
|
textParts.push(message.text);
|
|
1568
|
-
if (message.role === "user")
|
|
1881
|
+
if (message.role === "user") {
|
|
1882
|
+
lastUserText = message.text;
|
|
1883
|
+
nameSlots = applyNameCandidate(
|
|
1884
|
+
nameSlots,
|
|
1885
|
+
"firstUserMessage",
|
|
1886
|
+
message.text,
|
|
1887
|
+
COPILOT_PROVIDER
|
|
1888
|
+
);
|
|
1889
|
+
}
|
|
1569
1890
|
}
|
|
1570
1891
|
} catch (err) {
|
|
1571
1892
|
log.warn({ filePath, err }, "parseCopilotConversation: read failed");
|
|
@@ -1578,7 +1899,7 @@ async function parseCopilotConversation(filePath, account) {
|
|
|
1578
1899
|
projectPath: cwd,
|
|
1579
1900
|
projectName: getShortProjectName4(cwd),
|
|
1580
1901
|
sessionId: sessionId || sessionIdFromPath(filePath),
|
|
1581
|
-
sessionName: "",
|
|
1902
|
+
sessionName: resolveSessionName({ ...nameSlots, ...copilotNameSlotsFor(filePath) }).name ?? "",
|
|
1582
1903
|
messages,
|
|
1583
1904
|
fullText: textParts.join(" "),
|
|
1584
1905
|
timestamp: latestTimestamp || fileMtimeIso(filePath),
|
|
@@ -1591,9 +1912,9 @@ async function parseCopilotConversation(filePath, account) {
|
|
|
1591
1912
|
// src/providers/cursor.ts
|
|
1592
1913
|
import { createHash } from "crypto";
|
|
1593
1914
|
import fg3 from "fast-glob";
|
|
1594
|
-
import { createReadStream as createReadStream4, existsSync, statSync as
|
|
1915
|
+
import { createReadStream as createReadStream4, existsSync as existsSync2, statSync as statSync3 } from "fs";
|
|
1595
1916
|
import { stat as stat3 } from "fs/promises";
|
|
1596
|
-
import { basename as
|
|
1917
|
+
import { basename as basename6, dirname as dirname5, join as join5, sep as sep2 } from "path";
|
|
1597
1918
|
import { createInterface as createInterface4 } from "readline";
|
|
1598
1919
|
var TIMESTAMP_RE = /<timestamp>\s*([\s\S]*?)\s*<\/timestamp>/;
|
|
1599
1920
|
var USER_QUERY_RE = /<user_query>\s*([\s\S]*?)\s*<\/user_query>/;
|
|
@@ -1652,6 +1973,7 @@ var CursorProvider = class {
|
|
|
1652
1973
|
parentSessionUuid: null,
|
|
1653
1974
|
subagentId: null,
|
|
1654
1975
|
firstUser: null,
|
|
1976
|
+
nameSlots: {},
|
|
1655
1977
|
lastUser: null,
|
|
1656
1978
|
lastAssistant: null,
|
|
1657
1979
|
isImportedFromClaude: false,
|
|
@@ -1718,6 +2040,15 @@ function noteImportProvenance(acc, entry, text) {
|
|
|
1718
2040
|
acc.isImportedFromCodex = true;
|
|
1719
2041
|
}
|
|
1720
2042
|
}
|
|
2043
|
+
function cursorUserQuery(content) {
|
|
2044
|
+
const texts = typeof content === "string" ? [content] : Array.isArray(content) ? content : [];
|
|
2045
|
+
for (const item of texts) {
|
|
2046
|
+
const text = typeof item === "string" ? item : item?.text;
|
|
2047
|
+
const query = typeof text === "string" ? text.match(USER_QUERY_RE) : null;
|
|
2048
|
+
if (query) return query[1];
|
|
2049
|
+
}
|
|
2050
|
+
return void 0;
|
|
2051
|
+
}
|
|
1721
2052
|
function unwrapCursorUserText(text) {
|
|
1722
2053
|
const query = text.match(USER_QUERY_RE);
|
|
1723
2054
|
const body = query ? query[1] : text.replace(TIMESTAMP_RE, "");
|
|
@@ -1855,6 +2186,14 @@ function reduceCursorEntry(acc, entry, tier) {
|
|
|
1855
2186
|
collectCursorToolNames(content, acc.toolNames);
|
|
1856
2187
|
const text = textHint;
|
|
1857
2188
|
if (!text) return;
|
|
2189
|
+
if (entry.role === "user") {
|
|
2190
|
+
acc.nameSlots = applyNameCandidate(
|
|
2191
|
+
acc.nameSlots,
|
|
2192
|
+
"firstUserMessage",
|
|
2193
|
+
cursorUserQuery(content),
|
|
2194
|
+
CURSOR_PROVIDER
|
|
2195
|
+
);
|
|
2196
|
+
}
|
|
1858
2197
|
foldCursorMessage(acc, entry.role, text, firstTimestampHint(content), tier);
|
|
1859
2198
|
return;
|
|
1860
2199
|
}
|
|
@@ -1873,7 +2212,7 @@ function reduceCursorEntry(acc, entry, tier) {
|
|
|
1873
2212
|
}
|
|
1874
2213
|
function finalizeCursorMeta(acc, filePath, account, tier) {
|
|
1875
2214
|
if (acc.messageCount === 0) return null;
|
|
1876
|
-
const sessionId =
|
|
2215
|
+
const sessionId = basename6(filePath, ".jsonl");
|
|
1877
2216
|
const isSubagent = SUBAGENT_PATH_RE2.test(filePath);
|
|
1878
2217
|
const parent = isSubagent ? parentFromSubagentPath(filePath) : null;
|
|
1879
2218
|
const { projectPath, projectName } = projectFromCursorPath(filePath);
|
|
@@ -1886,7 +2225,7 @@ function finalizeCursorMeta(acc, filePath, account, tier) {
|
|
|
1886
2225
|
kind,
|
|
1887
2226
|
externalSessionId: sessionId,
|
|
1888
2227
|
sessionId,
|
|
1889
|
-
sessionName:
|
|
2228
|
+
sessionName: resolveSessionName({ ...acc.nameSlots, ...cursorNameSlotsFor(filePath, sessionId) }).name ?? "",
|
|
1890
2229
|
projectPath,
|
|
1891
2230
|
projectName,
|
|
1892
2231
|
account,
|
|
@@ -1912,20 +2251,20 @@ function finalizeCursorMeta(acc, filePath, account, tier) {
|
|
|
1912
2251
|
};
|
|
1913
2252
|
}
|
|
1914
2253
|
function parentFromSubagentPath(filePath) {
|
|
1915
|
-
const subagentsDir =
|
|
1916
|
-
const parentDir =
|
|
1917
|
-
const parentSessionUuid =
|
|
2254
|
+
const subagentsDir = dirname5(filePath);
|
|
2255
|
+
const parentDir = dirname5(subagentsDir);
|
|
2256
|
+
const parentSessionUuid = basename6(parentDir);
|
|
1918
2257
|
if (!parentSessionUuid) return null;
|
|
1919
2258
|
return {
|
|
1920
2259
|
parentSessionUuid,
|
|
1921
|
-
parentFilePath: canonicalPath(
|
|
2260
|
+
parentFilePath: canonicalPath(join5(parentDir, `${parentSessionUuid}.jsonl`))
|
|
1922
2261
|
};
|
|
1923
2262
|
}
|
|
1924
2263
|
function projectFromCursorPath(filePath) {
|
|
1925
2264
|
const parts = filePath.split(/[/\\]/);
|
|
1926
2265
|
const idx = parts.lastIndexOf("agent-transcripts");
|
|
1927
|
-
const cursorProjectDir = idx > 0 ? parts.slice(0, idx).join(sep2) :
|
|
1928
|
-
const slug =
|
|
2266
|
+
const cursorProjectDir = idx > 0 ? parts.slice(0, idx).join(sep2) : dirname5(dirname5(filePath));
|
|
2267
|
+
const slug = basename6(cursorProjectDir);
|
|
1929
2268
|
const decoded = decodeCursorProjectSlug(slug);
|
|
1930
2269
|
const projectPath = decoded ?? cursorProjectDir;
|
|
1931
2270
|
return { projectPath, projectName: getShortProjectName5(projectPath) || slug };
|
|
@@ -1939,7 +2278,7 @@ function decodeCursorProjectSlug(slug) {
|
|
|
1939
2278
|
let i = 0;
|
|
1940
2279
|
if (rooted && segments[0] === "Users") {
|
|
1941
2280
|
const users = `${sep2}Users`;
|
|
1942
|
-
if (!
|
|
2281
|
+
if (!existsSync2(users)) return null;
|
|
1943
2282
|
acc = users;
|
|
1944
2283
|
i = 1;
|
|
1945
2284
|
}
|
|
@@ -1947,9 +2286,9 @@ function decodeCursorProjectSlug(slug) {
|
|
|
1947
2286
|
let found = null;
|
|
1948
2287
|
let next = i + 1;
|
|
1949
2288
|
for (let j = segments.length; j > i; j--) {
|
|
1950
|
-
const candidate =
|
|
2289
|
+
const candidate = join5(acc, segments.slice(i, j).join("-"));
|
|
1951
2290
|
try {
|
|
1952
|
-
if (
|
|
2291
|
+
if (existsSync2(candidate) && statSync3(candidate).isDirectory()) {
|
|
1953
2292
|
found = candidate;
|
|
1954
2293
|
next = j;
|
|
1955
2294
|
break;
|
|
@@ -1968,17 +2307,26 @@ function getShortProjectName5(fullPath) {
|
|
|
1968
2307
|
}
|
|
1969
2308
|
function fileMtimeIso2(filePath) {
|
|
1970
2309
|
try {
|
|
1971
|
-
return new Date(
|
|
2310
|
+
return new Date(statSync3(filePath).mtimeMs).toISOString();
|
|
1972
2311
|
} catch {
|
|
1973
2312
|
return (/* @__PURE__ */ new Date()).toISOString();
|
|
1974
2313
|
}
|
|
1975
2314
|
}
|
|
2315
|
+
function cursorLineContent(line) {
|
|
2316
|
+
try {
|
|
2317
|
+
const entry = JSON.parse(line);
|
|
2318
|
+
return entry.message?.content ?? entry.content;
|
|
2319
|
+
} catch {
|
|
2320
|
+
return void 0;
|
|
2321
|
+
}
|
|
2322
|
+
}
|
|
1976
2323
|
async function parseCursorConversation(filePath, account) {
|
|
1977
2324
|
const log = getLogger();
|
|
1978
2325
|
const messages = [];
|
|
1979
2326
|
const textParts = [];
|
|
1980
2327
|
let latestTimestamp = "";
|
|
1981
2328
|
let lastUserText = "";
|
|
2329
|
+
let nameSlots = {};
|
|
1982
2330
|
const rl = createInterface4({ input: createReadStream4(filePath), crlfDelay: Infinity });
|
|
1983
2331
|
try {
|
|
1984
2332
|
for await (const line of rl) {
|
|
@@ -1990,7 +2338,17 @@ async function parseCursorConversation(filePath, account) {
|
|
|
1990
2338
|
messages.push(message);
|
|
1991
2339
|
if (!message.text) continue;
|
|
1992
2340
|
textParts.push(message.text);
|
|
1993
|
-
if (message.role === "user")
|
|
2341
|
+
if (message.role === "user") {
|
|
2342
|
+
lastUserText = message.text;
|
|
2343
|
+
if (nameSlots.firstUserMessage === void 0) {
|
|
2344
|
+
nameSlots = applyNameCandidate(
|
|
2345
|
+
nameSlots,
|
|
2346
|
+
"firstUserMessage",
|
|
2347
|
+
cursorUserQuery(cursorLineContent(line)),
|
|
2348
|
+
CURSOR_PROVIDER
|
|
2349
|
+
);
|
|
2350
|
+
}
|
|
2351
|
+
}
|
|
1994
2352
|
}
|
|
1995
2353
|
} catch (err) {
|
|
1996
2354
|
log.warn({ filePath, err }, "parseCursorConversation: read failed");
|
|
@@ -1998,14 +2356,14 @@ async function parseCursorConversation(filePath, account) {
|
|
|
1998
2356
|
}
|
|
1999
2357
|
if (messages.length === 0) return null;
|
|
2000
2358
|
const { projectPath, projectName } = projectFromCursorPath(filePath);
|
|
2001
|
-
const sessionId =
|
|
2359
|
+
const sessionId = basename6(filePath, ".jsonl");
|
|
2002
2360
|
return {
|
|
2003
2361
|
id: filePath,
|
|
2004
2362
|
filePath,
|
|
2005
2363
|
projectPath,
|
|
2006
2364
|
projectName,
|
|
2007
2365
|
sessionId,
|
|
2008
|
-
sessionName: "",
|
|
2366
|
+
sessionName: resolveSessionName({ ...nameSlots, ...cursorNameSlotsFor(filePath, sessionId) }).name ?? "",
|
|
2009
2367
|
messages,
|
|
2010
2368
|
fullText: textParts.join(" "),
|
|
2011
2369
|
timestamp: latestTimestamp || fileMtimeIso2(filePath),
|
|
@@ -2119,9 +2477,9 @@ var ThreadbaseProvider = class {
|
|
|
2119
2477
|
|
|
2120
2478
|
// src/scanner.ts
|
|
2121
2479
|
import { EventEmitter } from "events";
|
|
2122
|
-
import { closeSync as
|
|
2480
|
+
import { closeSync as closeSync3, openSync as openSync3, readSync as readSync3, statSync as statSync6 } from "fs";
|
|
2123
2481
|
import { homedir as homedir2 } from "os";
|
|
2124
|
-
import { join as
|
|
2482
|
+
import { join as join7 } from "path";
|
|
2125
2483
|
|
|
2126
2484
|
// src/cache.ts
|
|
2127
2485
|
var LRUCache = class {
|
|
@@ -2160,7 +2518,7 @@ var LRUCache = class {
|
|
|
2160
2518
|
};
|
|
2161
2519
|
|
|
2162
2520
|
// src/persistent/conversation-stream.ts
|
|
2163
|
-
import { basename as
|
|
2521
|
+
import { basename as basename7 } from "path";
|
|
2164
2522
|
|
|
2165
2523
|
// src/persistent/paged-reader.ts
|
|
2166
2524
|
import { createReadStream as createReadStream6 } from "fs";
|
|
@@ -2320,10 +2678,8 @@ function assemble(filePath, account, messages, fullText, turnDurations, state) {
|
|
|
2320
2678
|
filePath,
|
|
2321
2679
|
projectPath: state.cwd,
|
|
2322
2680
|
projectName: getShortProjectName2(state.cwd),
|
|
2323
|
-
sessionId: state.sessionId ||
|
|
2324
|
-
sessionName: state.
|
|
2325
|
-
messages.find((m) => m.role === "user" && m.text && !m.isCompactSummary) ?? null
|
|
2326
|
-
),
|
|
2681
|
+
sessionId: state.sessionId || basename7(filePath, ".jsonl"),
|
|
2682
|
+
sessionName: resolveSessionName(state.nameSlots).name ?? "",
|
|
2327
2683
|
messages,
|
|
2328
2684
|
fullText,
|
|
2329
2685
|
timestamp: state.latestTimestamp || (/* @__PURE__ */ new Date()).toISOString(),
|
|
@@ -2367,33 +2723,33 @@ async function extendConversation(previous, resume, filePath, account) {
|
|
|
2367
2723
|
|
|
2368
2724
|
// src/persistent/cursor.ts
|
|
2369
2725
|
import { createHash as createHash2 } from "crypto";
|
|
2370
|
-
import { closeSync, openSync, readSync, statSync as
|
|
2726
|
+
import { closeSync as closeSync2, openSync as openSync2, readSync as readSync2, statSync as statSync4 } from "fs";
|
|
2371
2727
|
var FP_BYTES = 4096;
|
|
2372
2728
|
function fingerprint(filePath, size) {
|
|
2373
2729
|
const hash = createHash2("sha1");
|
|
2374
2730
|
hash.update(String(size));
|
|
2375
|
-
const fd =
|
|
2731
|
+
const fd = openSync2(filePath, "r");
|
|
2376
2732
|
try {
|
|
2377
2733
|
const head = Buffer.alloc(Math.min(FP_BYTES, size));
|
|
2378
2734
|
if (head.length > 0) {
|
|
2379
|
-
|
|
2735
|
+
readSync2(fd, head, 0, head.length, 0);
|
|
2380
2736
|
hash.update(head);
|
|
2381
2737
|
}
|
|
2382
2738
|
if (size > FP_BYTES) {
|
|
2383
2739
|
const tailLen = Math.min(FP_BYTES, size);
|
|
2384
2740
|
const tail = Buffer.alloc(tailLen);
|
|
2385
|
-
|
|
2741
|
+
readSync2(fd, tail, 0, tailLen, size - tailLen);
|
|
2386
2742
|
hash.update(tail);
|
|
2387
2743
|
}
|
|
2388
2744
|
} finally {
|
|
2389
|
-
|
|
2745
|
+
closeSync2(fd);
|
|
2390
2746
|
}
|
|
2391
2747
|
return hash.digest("hex");
|
|
2392
2748
|
}
|
|
2393
2749
|
function classify(filePath, existing) {
|
|
2394
2750
|
let stat6;
|
|
2395
2751
|
try {
|
|
2396
|
-
const s =
|
|
2752
|
+
const s = statSync4(filePath);
|
|
2397
2753
|
stat6 = { size: s.size, mtimeMs: s.mtimeMs };
|
|
2398
2754
|
} catch {
|
|
2399
2755
|
return { change: "vanished" };
|
|
@@ -2421,12 +2777,12 @@ function classify(filePath, existing) {
|
|
|
2421
2777
|
}
|
|
2422
2778
|
|
|
2423
2779
|
// src/persistent/index-engine.ts
|
|
2424
|
-
import { statSync as
|
|
2780
|
+
import { statSync as statSync5 } from "fs";
|
|
2425
2781
|
|
|
2426
2782
|
// src/providers/parse.ts
|
|
2427
2783
|
import { createReadStream as createReadStream7 } from "fs";
|
|
2428
2784
|
import { createInterface as createInterface5 } from "readline";
|
|
2429
|
-
async function parseMetaWithProvider(provider, filePath, account, tier, onEntry) {
|
|
2785
|
+
async function parseMetaWithProvider(provider, filePath, account, tier, onEntry, onAccumulator) {
|
|
2430
2786
|
const log = getLogger();
|
|
2431
2787
|
const acc = provider.createEmptyAccumulator();
|
|
2432
2788
|
const rl = createInterface5({
|
|
@@ -2453,6 +2809,7 @@ async function parseMetaWithProvider(provider, filePath, account, tier, onEntry)
|
|
|
2453
2809
|
log.warn({ filePath, provider: provider.name, err }, "provider parse: read failed");
|
|
2454
2810
|
return null;
|
|
2455
2811
|
}
|
|
2812
|
+
onAccumulator?.(acc);
|
|
2456
2813
|
return provider.finalize(acc, filePath, account, tier);
|
|
2457
2814
|
}
|
|
2458
2815
|
|
|
@@ -2653,12 +3010,12 @@ function resolveTier(tierName, customTiers) {
|
|
|
2653
3010
|
}
|
|
2654
3011
|
|
|
2655
3012
|
// src/persistent/db.ts
|
|
2656
|
-
import
|
|
3013
|
+
import Database2 from "better-sqlite3";
|
|
2657
3014
|
import { mkdirSync } from "fs";
|
|
2658
|
-
import { dirname as
|
|
3015
|
+
import { dirname as dirname6 } from "path";
|
|
2659
3016
|
|
|
2660
3017
|
// src/persistent/schema.ts
|
|
2661
|
-
var SCHEMA_VERSION =
|
|
3018
|
+
var SCHEMA_VERSION = 11;
|
|
2662
3019
|
var SCHEMA_SQL = `
|
|
2663
3020
|
CREATE TABLE IF NOT EXISTS conversation_files (
|
|
2664
3021
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
@@ -2704,6 +3061,9 @@ CREATE TABLE IF NOT EXISTS conversations (
|
|
|
2704
3061
|
external_session_id TEXT,
|
|
2705
3062
|
session_id TEXT NOT NULL,
|
|
2706
3063
|
session_name TEXT,
|
|
3064
|
+
-- JSON NameSlots the name was resolved from; lets a side-store change
|
|
3065
|
+
-- re-resolve the name without reparsing the transcript.
|
|
3066
|
+
name_slots TEXT,
|
|
2707
3067
|
|
|
2708
3068
|
project_path TEXT,
|
|
2709
3069
|
project_name TEXT,
|
|
@@ -2966,6 +3326,27 @@ function runMigrations(db) {
|
|
|
2966
3326
|
db.exec(`UPDATE conversation_files SET ${assignments.join(", ")}`);
|
|
2967
3327
|
}
|
|
2968
3328
|
}
|
|
3329
|
+
if (current >= 1 && current < 11 && tableExists(db, "conversations")) {
|
|
3330
|
+
if (tableExists(db, "message_checkpoints")) db.exec("DELETE FROM message_checkpoints");
|
|
3331
|
+
if (!hasColumn(db, "conversations", "name_slots")) {
|
|
3332
|
+
db.exec("ALTER TABLE conversations ADD COLUMN name_slots TEXT");
|
|
3333
|
+
}
|
|
3334
|
+
if (tableExists(db, "conversation_files")) {
|
|
3335
|
+
const assignments = [];
|
|
3336
|
+
if (hasColumn(db, "conversation_files", "last_indexed_offset")) {
|
|
3337
|
+
assignments.push("last_indexed_offset = 0");
|
|
3338
|
+
}
|
|
3339
|
+
if (hasColumn(db, "conversation_files", "last_indexed_line")) {
|
|
3340
|
+
assignments.push("last_indexed_line = 0");
|
|
3341
|
+
}
|
|
3342
|
+
if (hasColumn(db, "conversation_files", "reducer_state")) {
|
|
3343
|
+
assignments.push("reducer_state = NULL");
|
|
3344
|
+
}
|
|
3345
|
+
if (assignments.length > 0) {
|
|
3346
|
+
db.exec(`UPDATE conversation_files SET ${assignments.join(", ")}`);
|
|
3347
|
+
}
|
|
3348
|
+
}
|
|
3349
|
+
}
|
|
2969
3350
|
db.exec(SCHEMA_SQL);
|
|
2970
3351
|
db.pragma(`user_version = ${SCHEMA_VERSION}`);
|
|
2971
3352
|
}
|
|
@@ -2980,11 +3361,11 @@ function hasColumn(db, table, column) {
|
|
|
2980
3361
|
// src/persistent/db.ts
|
|
2981
3362
|
function openDatabase(dbPath) {
|
|
2982
3363
|
if (dbPath !== ":memory:") {
|
|
2983
|
-
mkdirSync(
|
|
3364
|
+
mkdirSync(dirname6(dbPath), { recursive: true });
|
|
2984
3365
|
}
|
|
2985
3366
|
let db;
|
|
2986
3367
|
try {
|
|
2987
|
-
db = new
|
|
3368
|
+
db = new Database2(dbPath);
|
|
2988
3369
|
} catch (err) {
|
|
2989
3370
|
if (isNativeBindingFailure(err)) throw nativeBindingError(err, dbPath);
|
|
2990
3371
|
throw err;
|
|
@@ -3025,7 +3406,7 @@ function nativeBindingError(err, dbPath) {
|
|
|
3025
3406
|
|
|
3026
3407
|
// src/persistent/dir-watermark.ts
|
|
3027
3408
|
import { readdir, stat as stat5 } from "fs/promises";
|
|
3028
|
-
import { dirname as
|
|
3409
|
+
import { dirname as dirname7, join as join6 } from "path";
|
|
3029
3410
|
var FULL_RECONCILE_EVERY_N_SCANS = 20;
|
|
3030
3411
|
async function discoverJsonlFilesGated(dirs, files, scannedDirs, options = {}) {
|
|
3031
3412
|
const log = getLogger();
|
|
@@ -3096,10 +3477,10 @@ async function resolveProjectDirs(projectsDir, scannedDirs) {
|
|
|
3096
3477
|
return { entries, commitRoot: { mtimeMs: rootStat.mtimeMs } };
|
|
3097
3478
|
}
|
|
3098
3479
|
function dirnameOf(filePath) {
|
|
3099
|
-
return
|
|
3480
|
+
return dirname7(filePath);
|
|
3100
3481
|
}
|
|
3101
3482
|
function joinPath(dir, name) {
|
|
3102
|
-
return
|
|
3483
|
+
return join6(dir, name);
|
|
3103
3484
|
}
|
|
3104
3485
|
|
|
3105
3486
|
// src/persistent/repositories/checkpoints.repo.ts
|
|
@@ -3179,7 +3560,7 @@ function toCheckpoint(row) {
|
|
|
3179
3560
|
}
|
|
3180
3561
|
|
|
3181
3562
|
// src/persistent/repositories/conversation-files.repo.ts
|
|
3182
|
-
import { basename as
|
|
3563
|
+
import { basename as basename8, dirname as dirname8 } from "path";
|
|
3183
3564
|
var ConversationFilesRepo = class {
|
|
3184
3565
|
constructor(db) {
|
|
3185
3566
|
this.db = db;
|
|
@@ -3202,7 +3583,7 @@ var ConversationFilesRepo = class {
|
|
|
3202
3583
|
const info = this.db.prepare(
|
|
3203
3584
|
`INSERT INTO conversation_files (absolute_path, parent_dir, file_name, account)
|
|
3204
3585
|
VALUES (?, ?, ?, ?)`
|
|
3205
|
-
).run(canonical,
|
|
3586
|
+
).run(canonical, dirname8(canonical), basename8(canonical), account);
|
|
3206
3587
|
return Number(info.lastInsertRowid);
|
|
3207
3588
|
}
|
|
3208
3589
|
// Advance the cursor + persisted reducer state after a successful index pass.
|
|
@@ -3310,7 +3691,7 @@ var ConversationsRepo = class {
|
|
|
3310
3691
|
db;
|
|
3311
3692
|
// Upsert by file_id (1 file = 1 conversation). Keyed on the unique file_id so
|
|
3312
3693
|
// a re-index overwrites the prior summary in place.
|
|
3313
|
-
upsert(fileId, meta, pageMessageCount = meta.messageCount) {
|
|
3694
|
+
upsert(fileId, meta, pageMessageCount = meta.messageCount, nameSlots) {
|
|
3314
3695
|
this.db.prepare(
|
|
3315
3696
|
`INSERT INTO conversations (
|
|
3316
3697
|
file_id, source_path, provider, kind, external_session_id,
|
|
@@ -3321,7 +3702,7 @@ var ConversationsRepo = class {
|
|
|
3321
3702
|
model, is_subagent, parent_session_id, subagent_id, parent_session_uuid,
|
|
3322
3703
|
is_teammate, team_name, tool_names_json,
|
|
3323
3704
|
last_prompt, is_imported_from_claude, is_imported_from_codex,
|
|
3324
|
-
is_imported_from_cursor, status, updated_at
|
|
3705
|
+
is_imported_from_cursor, name_slots, status, updated_at
|
|
3325
3706
|
) VALUES (
|
|
3326
3707
|
@file_id, @source_path, @provider, @kind, @external_session_id,
|
|
3327
3708
|
@session_id, @session_name, @project_path, @project_name,
|
|
@@ -3333,7 +3714,7 @@ var ConversationsRepo = class {
|
|
|
3333
3714
|
@model, @is_subagent, @parent_session_id, @subagent_id, @parent_session_uuid,
|
|
3334
3715
|
@is_teammate, @team_name, @tool_names_json,
|
|
3335
3716
|
@last_prompt, @is_imported_from_claude, @is_imported_from_codex,
|
|
3336
|
-
@is_imported_from_cursor, 'active', CURRENT_TIMESTAMP
|
|
3717
|
+
@is_imported_from_cursor, @name_slots, 'active', CURRENT_TIMESTAMP
|
|
3337
3718
|
)
|
|
3338
3719
|
ON CONFLICT(file_id) DO UPDATE SET
|
|
3339
3720
|
source_path = excluded.source_path,
|
|
@@ -3368,6 +3749,7 @@ var ConversationsRepo = class {
|
|
|
3368
3749
|
is_imported_from_claude = excluded.is_imported_from_claude,
|
|
3369
3750
|
is_imported_from_codex = excluded.is_imported_from_codex,
|
|
3370
3751
|
is_imported_from_cursor = excluded.is_imported_from_cursor,
|
|
3752
|
+
name_slots = excluded.name_slots,
|
|
3371
3753
|
status = 'active',
|
|
3372
3754
|
index_seq = (SELECT COALESCE(MAX(index_seq), 0) + 1 FROM conversations),
|
|
3373
3755
|
updated_at = CURRENT_TIMESTAMP`
|
|
@@ -3407,7 +3789,8 @@ var ConversationsRepo = class {
|
|
|
3407
3789
|
last_prompt: meta.lastPrompt ?? null,
|
|
3408
3790
|
is_imported_from_claude: meta.isImportedFromClaude ? 1 : 0,
|
|
3409
3791
|
is_imported_from_codex: meta.isImportedFromCodex ? 1 : 0,
|
|
3410
|
-
is_imported_from_cursor: meta.isImportedFromCursor ? 1 : 0
|
|
3792
|
+
is_imported_from_cursor: meta.isImportedFromCursor ? 1 : 0,
|
|
3793
|
+
name_slots: nameSlots ? JSON.stringify(nameSlots) : null
|
|
3411
3794
|
});
|
|
3412
3795
|
}
|
|
3413
3796
|
getBySourcePath(sourcePath) {
|
|
@@ -3788,13 +4171,18 @@ var PersistentEngine = class {
|
|
|
3788
4171
|
const tier = resolveTier(tierName, customTiers);
|
|
3789
4172
|
const filePath = canonicalPath(rawFilePath);
|
|
3790
4173
|
const existing = this.files.getByPath(filePath);
|
|
3791
|
-
const
|
|
4174
|
+
const classified = classify(filePath, existing);
|
|
4175
|
+
const stat6 = classified.stat;
|
|
4176
|
+
let change = classified.change;
|
|
3792
4177
|
if (change === "vanished" || !stat6) {
|
|
3793
4178
|
this.markDeleted(filePath);
|
|
3794
4179
|
return { meta: null, change: "vanished" };
|
|
3795
4180
|
}
|
|
3796
4181
|
if (change === "unchanged" && !force) {
|
|
3797
|
-
|
|
4182
|
+
const meta2 = this.conversations.getBySourcePath(filePath);
|
|
4183
|
+
const sideStoresMoved = provider && provider.name !== CLAUDE_CODE_PROVIDER && meta2 && JSON.stringify(nameStoreSlotsFor(provider.name, filePath, meta2.sessionId)) !== existing?.reducer_state;
|
|
4184
|
+
if (!sideStoresMoved) return { meta: meta2, change };
|
|
4185
|
+
change = "reindex";
|
|
3798
4186
|
}
|
|
3799
4187
|
if (provider && provider.name !== CLAUDE_CODE_PROVIDER) {
|
|
3800
4188
|
const meta2 = await this.indexFileWithProvider(
|
|
@@ -3833,7 +4221,7 @@ var PersistentEngine = class {
|
|
|
3833
4221
|
const base = resume ? this.fts.readDocument(fileId) ?? emptySearchDocument() : emptySearchDocument();
|
|
3834
4222
|
const searchDoc = appendSearchDelta(base, searchDelta);
|
|
3835
4223
|
const upsert = this.db.transaction(() => {
|
|
3836
|
-
this.conversations.upsert(fileId, meta, state.pageMessageCount);
|
|
4224
|
+
this.conversations.upsert(fileId, meta, state.pageMessageCount, state.nameSlots);
|
|
3837
4225
|
if (!this.fts.isCurrent(fileId, meta, searchDoc)) {
|
|
3838
4226
|
this.fts.upsert(fileId, meta, searchDoc);
|
|
3839
4227
|
}
|
|
@@ -3876,13 +4264,23 @@ var PersistentEngine = class {
|
|
|
3876
4264
|
// provider's reducer/finalize, then the same upsert + FTS write + cursor bump
|
|
3877
4265
|
// the Threadbase path uses. The cursor records size/mtime (and offset = size)
|
|
3878
4266
|
// so the next pass classifies an unchanged file as "unchanged" and skips it;
|
|
3879
|
-
// any change reparses from 0 again.
|
|
4267
|
+
// any change reparses from 0 again. reducer_state holds the side-store name slots, not a fold.
|
|
3880
4268
|
async indexFileWithProvider(provider, filePath, account, tier, stat6, resolveGitBranch) {
|
|
3881
4269
|
const log = getLogger();
|
|
3882
4270
|
let searchDoc = emptySearchDocument();
|
|
3883
|
-
|
|
3884
|
-
|
|
3885
|
-
|
|
4271
|
+
let transcriptSlots = {};
|
|
4272
|
+
const meta = await parseMetaWithProvider(
|
|
4273
|
+
provider,
|
|
4274
|
+
filePath,
|
|
4275
|
+
account,
|
|
4276
|
+
tier,
|
|
4277
|
+
(entry) => {
|
|
4278
|
+
searchDoc = appendSearchDelta(searchDoc, extractSearchDelta(entry));
|
|
4279
|
+
},
|
|
4280
|
+
(acc) => {
|
|
4281
|
+
transcriptSlots = acc.nameSlots ?? {};
|
|
4282
|
+
}
|
|
4283
|
+
);
|
|
3886
4284
|
if (!meta) {
|
|
3887
4285
|
this.markDeleted(filePath);
|
|
3888
4286
|
return null;
|
|
@@ -3890,10 +4288,14 @@ var PersistentEngine = class {
|
|
|
3890
4288
|
if (meta.gitBranch === null && meta.projectPath) {
|
|
3891
4289
|
meta.gitBranch = resolveGitBranch(meta.projectPath);
|
|
3892
4290
|
}
|
|
4291
|
+
const sideSlots = nameStoreSlotsFor(provider.name, filePath, meta.sessionId);
|
|
3893
4292
|
const fp = stat6.size > 0 ? fingerprint(filePath, stat6.size) : null;
|
|
3894
4293
|
const fileId = this.files.ensure(filePath, account);
|
|
3895
4294
|
const upsert = this.db.transaction(() => {
|
|
3896
|
-
this.conversations.upsert(fileId, meta, meta.messageCount
|
|
4295
|
+
this.conversations.upsert(fileId, meta, meta.messageCount, {
|
|
4296
|
+
...transcriptSlots,
|
|
4297
|
+
...sideSlots
|
|
4298
|
+
});
|
|
3897
4299
|
if (!this.fts.isCurrent(fileId, meta, searchDoc)) {
|
|
3898
4300
|
this.fts.upsert(fileId, meta, searchDoc);
|
|
3899
4301
|
}
|
|
@@ -3905,7 +4307,9 @@ var PersistentEngine = class {
|
|
|
3905
4307
|
// can classify it "unchanged"); no resumable reducer state is kept.
|
|
3906
4308
|
offset: stat6.size,
|
|
3907
4309
|
line: 0,
|
|
3908
|
-
|
|
4310
|
+
// Not resumable state: the side-store name slots this parse used, so the
|
|
4311
|
+
// next pass can tell when they moved (see indexFile).
|
|
4312
|
+
reducerState: JSON.stringify(sideSlots),
|
|
3909
4313
|
fingerprint: fp,
|
|
3910
4314
|
status: "active"
|
|
3911
4315
|
});
|
|
@@ -3985,7 +4389,7 @@ var PersistentEngine = class {
|
|
|
3985
4389
|
let floor = this.checkpoints.floor(filePath, fromIndex);
|
|
3986
4390
|
if (floor) {
|
|
3987
4391
|
try {
|
|
3988
|
-
if (floor.byteOffset >
|
|
4392
|
+
if (floor.byteOffset > statSync5(filePath).size) floor = null;
|
|
3989
4393
|
} catch {
|
|
3990
4394
|
}
|
|
3991
4395
|
}
|
|
@@ -4124,7 +4528,7 @@ function defaultDbPath() {
|
|
|
4124
4528
|
"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."
|
|
4125
4529
|
);
|
|
4126
4530
|
}
|
|
4127
|
-
return
|
|
4531
|
+
return join7(homedir2(), ".config", "threadbase-scanner", "index.db");
|
|
4128
4532
|
}
|
|
4129
4533
|
function capForMemory(doc, max) {
|
|
4130
4534
|
const combined = combineSearchContent(doc);
|
|
@@ -4217,6 +4621,7 @@ var ConversationScanner = class {
|
|
|
4217
4621
|
}
|
|
4218
4622
|
}
|
|
4219
4623
|
async runScan(options) {
|
|
4624
|
+
if (options.cursorStateDb !== void 0) setCursorStateDb(options.cursorStateDb);
|
|
4220
4625
|
const profiles = await this.resolveProfiles(options.profiles);
|
|
4221
4626
|
const activeProfiles = profiles.filter((p) => p.enabled && p.scanHistory !== false);
|
|
4222
4627
|
this.lastTier = resolveTier(options.tier ?? "standard", options.tiers);
|
|
@@ -4303,7 +4708,7 @@ var ConversationScanner = class {
|
|
|
4303
4708
|
const cached = statCache.get(filePath);
|
|
4304
4709
|
if (cached) {
|
|
4305
4710
|
try {
|
|
4306
|
-
const s =
|
|
4711
|
+
const s = statSync6(filePath);
|
|
4307
4712
|
if (s.mtimeMs === cached.stat.mtimeMs && s.size === cached.stat.size) {
|
|
4308
4713
|
return {
|
|
4309
4714
|
meta: cached.meta,
|
|
@@ -4851,13 +5256,13 @@ var ConversationScanner = class {
|
|
|
4851
5256
|
if (previous?.provider) return void 0;
|
|
4852
5257
|
let sample = "";
|
|
4853
5258
|
try {
|
|
4854
|
-
const fd =
|
|
5259
|
+
const fd = openSync3(filePath, "r");
|
|
4855
5260
|
try {
|
|
4856
5261
|
const buf = Buffer.alloc(8192);
|
|
4857
|
-
const n =
|
|
5262
|
+
const n = readSync3(fd, buf, 0, buf.length, 0);
|
|
4858
5263
|
sample = buf.subarray(0, n).toString("utf8");
|
|
4859
5264
|
} finally {
|
|
4860
|
-
|
|
5265
|
+
closeSync3(fd);
|
|
4861
5266
|
}
|
|
4862
5267
|
} catch {
|
|
4863
5268
|
return void 0;
|
|
@@ -4984,11 +5389,13 @@ export {
|
|
|
4984
5389
|
CursorProvider,
|
|
4985
5390
|
DEFAULT_TIERS,
|
|
4986
5391
|
LEGACY_CURSOR_PROVIDER,
|
|
5392
|
+
NAME_PRECEDENCE,
|
|
4987
5393
|
SearchIndexer,
|
|
4988
5394
|
ThreadbaseProvider,
|
|
4989
5395
|
VALID_SORT_ORDERS,
|
|
4990
5396
|
applyAccountFilter,
|
|
4991
5397
|
applyIncludeFilter,
|
|
5398
|
+
applyNameCandidate,
|
|
4992
5399
|
applyPagination,
|
|
4993
5400
|
applyProjectFilter,
|
|
4994
5401
|
applySinceFilter,
|
|
@@ -5003,20 +5410,27 @@ export {
|
|
|
5003
5410
|
getLogger,
|
|
5004
5411
|
getProjectsDir,
|
|
5005
5412
|
isCodexInjectedContext,
|
|
5413
|
+
isValidNameCandidate,
|
|
5006
5414
|
loadProfiles,
|
|
5007
5415
|
parseCodexJsonlLine,
|
|
5008
5416
|
parseCopilotJsonlLine,
|
|
5009
5417
|
parseCursorJsonlLine,
|
|
5010
5418
|
parseJsonlLine,
|
|
5011
5419
|
providerMatches,
|
|
5420
|
+
readCodexNameSlots,
|
|
5421
|
+
readCopilotNameSlots,
|
|
5422
|
+
readCursorCliNameSlots,
|
|
5423
|
+
readCursorIdeNameSlots,
|
|
5012
5424
|
readGitBranch,
|
|
5013
5425
|
readSidecar,
|
|
5014
5426
|
resetDefaultScanner,
|
|
5015
5427
|
resolveConfigDir,
|
|
5428
|
+
resolveSessionName,
|
|
5016
5429
|
resolveTier,
|
|
5017
5430
|
saveProfiles,
|
|
5018
5431
|
scan,
|
|
5019
5432
|
search,
|
|
5433
|
+
setCursorStateDb,
|
|
5020
5434
|
setLogger,
|
|
5021
5435
|
sidecarPath,
|
|
5022
5436
|
unwrapCursorUserText
|