@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.js CHANGED
@@ -543,8 +543,9 @@ var SYSTEM_TAGS = [
543
543
  "teammate-message"
544
544
  ];
545
545
  var SYSTEM_TAG_RE = new RegExp(`<(${SYSTEM_TAGS.join("|")})[^>]*>[\\s\\S]*?<\\/\\1>`, "g");
546
+ var PASTED_CONTENT_RE = /<pasted_content id="[0-9a-f]{4}">([\s\S]*?)<\/pasted_content(?: id="[0-9a-f]{4}")?>/g;
546
547
  function cleanSystemTags(text) {
547
- return text.replace(SYSTEM_TAG_RE, "").replace(/[^\S\n]+/g, " ").replace(/\n{3,}/g, "\n\n").trim();
548
+ return text.replace(SYSTEM_TAG_RE, "").replace(PASTED_CONTENT_RE, "$1").replace(/[^\S\n]+/g, " ").replace(/\n{3,}/g, "\n\n").trim();
548
549
  }
549
550
 
550
551
  // src/parser.ts
@@ -1462,15 +1463,22 @@ function firstTimestampHint(content) {
1462
1463
  }
1463
1464
  return "";
1464
1465
  }
1465
- function parseCursorJsonlLine(line) {
1466
- if (!line.trim()) return null;
1466
+ function parseCursorJsonlLine(line, index) {
1467
+ const trimmed = line.trim();
1468
+ if (!trimmed) return null;
1467
1469
  let entry;
1468
1470
  try {
1469
- entry = JSON.parse(line);
1471
+ entry = JSON.parse(trimmed);
1470
1472
  } catch {
1471
1473
  return null;
1472
1474
  }
1473
- return cursorEntryToMessage(entry);
1475
+ const message = cursorEntryToMessage(entry);
1476
+ if (!message || message.uuid) return message;
1477
+ return { ...message, uuid: cursorMessageUuid(trimmed, message.role, index) };
1478
+ }
1479
+ function cursorMessageUuid(line, role, index) {
1480
+ const hash = createHash("sha1").update(line).digest("hex").slice(0, 16);
1481
+ return index === void 0 ? `cursor-${role}-${hash}` : `cursor-${role}-${index}-${hash}`;
1474
1482
  }
1475
1483
  function cursorEntryToMessage(entry) {
1476
1484
  if (looksLikeCursorChatEntry(entry)) {
@@ -1673,7 +1681,7 @@ async function parseCursorConversation(filePath, account) {
1673
1681
  const rl = createInterface3({ input: createReadStream3(filePath), crlfDelay: Infinity });
1674
1682
  try {
1675
1683
  for await (const line of rl) {
1676
- const message = parseCursorJsonlLine(line);
1684
+ const message = parseCursorJsonlLine(line, messages.length);
1677
1685
  if (!message) continue;
1678
1686
  if (message.timestamp && (!latestTimestamp || message.timestamp > latestTimestamp)) {
1679
1687
  latestTimestamp = message.timestamp;
@@ -2338,7 +2346,7 @@ import { mkdirSync } from "fs";
2338
2346
  import { dirname as dirname4 } from "path";
2339
2347
 
2340
2348
  // src/persistent/schema.ts
2341
- var SCHEMA_VERSION = 9;
2349
+ var SCHEMA_VERSION = 10;
2342
2350
  var SCHEMA_SQL = `
2343
2351
  CREATE TABLE IF NOT EXISTS conversation_files (
2344
2352
  id INTEGER PRIMARY KEY AUTOINCREMENT,
@@ -2631,6 +2639,21 @@ function runMigrations(db) {
2631
2639
  if (current >= 1 && current < 9 && tableExists(db, "conversations")) {
2632
2640
  db.exec(`UPDATE conversations SET provider = 'cursor' WHERE provider = 'cursor-cli'`);
2633
2641
  }
2642
+ if (current >= 1 && current < 10 && tableExists(db, "conversation_files")) {
2643
+ const assignments = [];
2644
+ if (hasColumn(db, "conversation_files", "last_indexed_offset")) {
2645
+ assignments.push("last_indexed_offset = 0");
2646
+ }
2647
+ if (hasColumn(db, "conversation_files", "last_indexed_line")) {
2648
+ assignments.push("last_indexed_line = 0");
2649
+ }
2650
+ if (hasColumn(db, "conversation_files", "reducer_state")) {
2651
+ assignments.push("reducer_state = NULL");
2652
+ }
2653
+ if (assignments.length > 0) {
2654
+ db.exec(`UPDATE conversation_files SET ${assignments.join(", ")}`);
2655
+ }
2656
+ }
2634
2657
  db.exec(SCHEMA_SQL);
2635
2658
  db.pragma(`user_version = ${SCHEMA_VERSION}`);
2636
2659
  }