@threadbase-sh/scanner 0.19.0 → 0.19.2

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/dist/index.cjs CHANGED
@@ -621,8 +621,9 @@ var SYSTEM_TAGS = [
621
621
  "teammate-message"
622
622
  ];
623
623
  var SYSTEM_TAG_RE = new RegExp(`<(${SYSTEM_TAGS.join("|")})[^>]*>[\\s\\S]*?<\\/\\1>`, "g");
624
+ var PASTED_CONTENT_RE = /<pasted_content id="[0-9a-f]{4}">([\s\S]*?)<\/pasted_content(?: id="[0-9a-f]{4}")?>/g;
624
625
  function cleanSystemTags(text) {
625
- return text.replace(SYSTEM_TAG_RE, "").replace(/[^\S\n]+/g, " ").replace(/\n{3,}/g, "\n\n").trim();
626
+ return text.replace(SYSTEM_TAG_RE, "").replace(PASTED_CONTENT_RE, "$1").replace(/[^\S\n]+/g, " ").replace(/\n{3,}/g, "\n\n").trim();
626
627
  }
627
628
 
628
629
  // src/parser.ts
@@ -1540,15 +1541,22 @@ function firstTimestampHint(content) {
1540
1541
  }
1541
1542
  return "";
1542
1543
  }
1543
- function parseCursorJsonlLine(line) {
1544
- if (!line.trim()) return null;
1544
+ function parseCursorJsonlLine(line, index) {
1545
+ const trimmed = line.trim();
1546
+ if (!trimmed) return null;
1545
1547
  let entry;
1546
1548
  try {
1547
- entry = JSON.parse(line);
1549
+ entry = JSON.parse(trimmed);
1548
1550
  } catch {
1549
1551
  return null;
1550
1552
  }
1551
- return cursorEntryToMessage(entry);
1553
+ const message = cursorEntryToMessage(entry);
1554
+ if (!message || message.uuid) return message;
1555
+ return { ...message, uuid: cursorMessageUuid(trimmed, message.role, index) };
1556
+ }
1557
+ function cursorMessageUuid(line, role, index) {
1558
+ const hash = (0, import_crypto.createHash)("sha1").update(line).digest("hex").slice(0, 16);
1559
+ return index === void 0 ? `cursor-${role}-${hash}` : `cursor-${role}-${index}-${hash}`;
1552
1560
  }
1553
1561
  function cursorEntryToMessage(entry) {
1554
1562
  if (looksLikeCursorChatEntry(entry)) {
@@ -1751,7 +1759,7 @@ async function parseCursorConversation(filePath, account) {
1751
1759
  const rl = (0, import_readline3.createInterface)({ input: (0, import_fs5.createReadStream)(filePath), crlfDelay: Infinity });
1752
1760
  try {
1753
1761
  for await (const line of rl) {
1754
- const message = parseCursorJsonlLine(line);
1762
+ const message = parseCursorJsonlLine(line, messages.length);
1755
1763
  if (!message) continue;
1756
1764
  if (message.timestamp && (!latestTimestamp || message.timestamp > latestTimestamp)) {
1757
1765
  latestTimestamp = message.timestamp;
@@ -2416,7 +2424,7 @@ var import_fs10 = require("fs");
2416
2424
  var import_path9 = require("path");
2417
2425
 
2418
2426
  // src/persistent/schema.ts
2419
- var SCHEMA_VERSION = 9;
2427
+ var SCHEMA_VERSION = 10;
2420
2428
  var SCHEMA_SQL = `
2421
2429
  CREATE TABLE IF NOT EXISTS conversation_files (
2422
2430
  id INTEGER PRIMARY KEY AUTOINCREMENT,
@@ -2709,6 +2717,21 @@ function runMigrations(db) {
2709
2717
  if (current >= 1 && current < 9 && tableExists(db, "conversations")) {
2710
2718
  db.exec(`UPDATE conversations SET provider = 'cursor' WHERE provider = 'cursor-cli'`);
2711
2719
  }
2720
+ if (current >= 1 && current < 10 && tableExists(db, "conversation_files")) {
2721
+ const assignments = [];
2722
+ if (hasColumn(db, "conversation_files", "last_indexed_offset")) {
2723
+ assignments.push("last_indexed_offset = 0");
2724
+ }
2725
+ if (hasColumn(db, "conversation_files", "last_indexed_line")) {
2726
+ assignments.push("last_indexed_line = 0");
2727
+ }
2728
+ if (hasColumn(db, "conversation_files", "reducer_state")) {
2729
+ assignments.push("reducer_state = NULL");
2730
+ }
2731
+ if (assignments.length > 0) {
2732
+ db.exec(`UPDATE conversation_files SET ${assignments.join(", ")}`);
2733
+ }
2734
+ }
2712
2735
  db.exec(SCHEMA_SQL);
2713
2736
  db.pragma(`user_version = ${SCHEMA_VERSION}`);
2714
2737
  }