@pmate/cli 0.21.14 → 0.21.15

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.
Files changed (2) hide show
  1. package/dist/index.js +42 -29
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -15664,7 +15664,6 @@ var QuizCommandHandler = class {
15664
15664
 
15665
15665
  // src/commands/CollectCommandHandler.ts
15666
15666
  var import_playwright = require("playwright");
15667
- var import_node_crypto4 = require("crypto");
15668
15667
 
15669
15668
  // src/collectStore.ts
15670
15669
  var import_node_crypto3 = require("crypto");
@@ -15715,27 +15714,36 @@ async function writeStoredIndex(rootDir, index) {
15715
15714
  await import_node_fs11.promises.writeFile(filePath, JSON.stringify(index, null, 2) + "\n", "utf8");
15716
15715
  }
15717
15716
  function mergeMessages(existing, incoming) {
15718
- const seen = new Set(existing.map((message) => message.hash));
15717
+ const seenMessageIds = new Set(
15718
+ existing.map((message) => normalizeMessageId(message.messageId)).filter((value) => !!value)
15719
+ );
15719
15720
  const merged = [...existing];
15720
15721
  let added = 0;
15721
15722
  for (const message of incoming) {
15722
- if (seen.has(message.hash)) {
15723
+ const incomingMessageId = normalizeMessageId(message.messageId);
15724
+ if (incomingMessageId && seenMessageIds.has(incomingMessageId)) {
15723
15725
  continue;
15724
15726
  }
15725
15727
  const upgradeIndex = merged.findIndex((current) => shouldUpgradeMessage(current, message));
15726
15728
  if (upgradeIndex >= 0) {
15727
15729
  merged[upgradeIndex] = message;
15728
- seen.add(message.hash);
15730
+ if (incomingMessageId) {
15731
+ seenMessageIds.add(incomingMessageId);
15732
+ }
15729
15733
  continue;
15730
15734
  }
15731
- seen.add(message.hash);
15735
+ if (incomingMessageId) {
15736
+ seenMessageIds.add(incomingMessageId);
15737
+ }
15732
15738
  merged.push(message);
15733
15739
  added += 1;
15734
15740
  }
15735
15741
  return { messages: merged, added };
15736
15742
  }
15737
15743
  function shouldUpgradeMessage(existing, incoming) {
15738
- if (existing.hash === incoming.hash) {
15744
+ const existingMessageId = normalizeMessageId(existing.messageId);
15745
+ const incomingMessageId = normalizeMessageId(incoming.messageId);
15746
+ if (existingMessageId && incomingMessageId && existingMessageId === incomingMessageId) {
15739
15747
  return false;
15740
15748
  }
15741
15749
  if (existing.time && incoming.time && existing.time !== incoming.time) {
@@ -15746,6 +15754,10 @@ function shouldUpgradeMessage(existing, incoming) {
15746
15754
  function normalizeMessageField(value) {
15747
15755
  return (value ?? "").trim();
15748
15756
  }
15757
+ function normalizeMessageId(value) {
15758
+ const normalized = (value ?? "").trim();
15759
+ return normalized || null;
15760
+ }
15749
15761
  function joinNormalized(values) {
15750
15762
  return values.map((value) => value.trim()).join("|");
15751
15763
  }
@@ -15753,7 +15765,7 @@ async function readStoredMessages(rootDir, threadKey) {
15753
15765
  const filePath = getThreadMessagesFilePath(rootDir, threadKey);
15754
15766
  try {
15755
15767
  const raw = await import_node_fs11.promises.readFile(filePath, "utf8");
15756
- return raw.split("\n").map((line) => line.trim()).filter(Boolean).map((line) => JSON.parse(line));
15768
+ return raw.split("\n").map((line) => line.trim()).filter(Boolean).map((line) => normalizeStoredMessage(JSON.parse(line)));
15757
15769
  } catch {
15758
15770
  return [];
15759
15771
  }
@@ -15776,6 +15788,17 @@ function getThreadMessagesFilePath(rootDir, threadKey) {
15776
15788
  function getLegacyThreadFilePath(rootDir, threadKey) {
15777
15789
  return import_node_path16.default.join(rootDir, "threads", `${threadKey}.json`);
15778
15790
  }
15791
+ function normalizeStoredMessage(message) {
15792
+ return {
15793
+ messageId: normalizeMessageId(message.messageId),
15794
+ time: message.time ?? null,
15795
+ sender: message.sender ?? null,
15796
+ content: message.content ?? "",
15797
+ links: Array.isArray(message.links) ? message.links : [],
15798
+ images: Array.isArray(message.images) ? message.images : [],
15799
+ collectedAt: message.collectedAt
15800
+ };
15801
+ }
15779
15802
 
15780
15803
  // src/commands/CollectCommandHandler.ts
15781
15804
  var CollectCommandHandler = class {
@@ -15833,7 +15856,7 @@ var CollectCommandHandler = class {
15833
15856
  async persistThread(rootDir, target, thread, messages2, syncedAt, existing) {
15834
15857
  const threadKey = toThreadKey(thread.name);
15835
15858
  const incoming = messages2.map((message) => ({
15836
- hash: message.hash,
15859
+ messageId: message.messageId,
15837
15860
  time: message.time,
15838
15861
  sender: message.sender,
15839
15862
  content: message.content,
@@ -15949,7 +15972,9 @@ var CollectCommandHandler = class {
15949
15972
  error: result && "reason" in result && typeof result.reason === "string" ? result.reason : "unknown error"
15950
15973
  };
15951
15974
  }
15952
- const seenHashes = new Set(existingMessages.map((message) => message.hash));
15975
+ const seenMessageIds = new Set(
15976
+ existingMessages.map((message) => (message.messageId ?? "").trim()).filter((value) => !!value)
15977
+ );
15953
15978
  const collected = [];
15954
15979
  for (let i = result.messages.length - 1; i >= 0; i -= 1) {
15955
15980
  const raw = result.messages[i];
@@ -15960,18 +15985,17 @@ var CollectCommandHandler = class {
15960
15985
  const attachmentPaths = Array.isArray(raw.attachments) ? raw.attachments.map((attachment) => attachment.path ?? null).filter((value) => !!value) : [];
15961
15986
  const message = {
15962
15987
  index: raw.index,
15963
- hash: "",
15988
+ messageId: normalizeText(raw.id ?? "") || null,
15964
15989
  time: formatSentAt(raw.sentAt),
15965
15990
  sender: normalizeText(raw.senderName ?? raw.source ?? "") || null,
15966
15991
  content: contentParts.filter(Boolean).join("\n") || (attachmentPaths.length > 0 ? "[Image]" : ""),
15967
15992
  links: [],
15968
15993
  images: attachmentPaths
15969
15994
  };
15970
- message.hash = computeMessageHash(thread.name, message);
15971
15995
  if (!message.content && message.images.length === 0) {
15972
15996
  continue;
15973
15997
  }
15974
- if (seenHashes.has(message.hash)) {
15998
+ if (message.messageId && seenMessageIds.has(message.messageId)) {
15975
15999
  break;
15976
16000
  }
15977
16001
  collected.push(message);
@@ -16002,17 +16026,6 @@ function normalizeUnreadCount(value) {
16002
16026
  const parsed = typeof value === "number" ? value : typeof value === "string" && value.trim() ? Number.parseInt(value, 10) : 0;
16003
16027
  return Number.isFinite(parsed) && parsed > 0 ? parsed : 0;
16004
16028
  }
16005
- function computeMessageHash(threadName, message) {
16006
- const base = [
16007
- normalizeText(threadName),
16008
- normalizeText(message.sender ?? ""),
16009
- normalizeText(message.time ?? ""),
16010
- normalizeText(message.content),
16011
- message.links.map(normalizeText).join("|"),
16012
- message.images.map(normalizeText).join("|")
16013
- ].join("||");
16014
- return (0, import_node_crypto4.createHash)("sha1").update(base).digest("hex").slice(0, 16);
16015
- }
16016
16029
  function buildListThreadsExpr() {
16017
16030
  return `(function() {
16018
16031
  try {
@@ -16225,7 +16238,7 @@ init_sessionStore();
16225
16238
  var STORE_LOG_VERSION = 1;
16226
16239
  var LOG_KIND_TABLE = 1e4;
16227
16240
  var LOG_KIND_MAPPING = 6003;
16228
- function createHash4() {
16241
+ function createHash3() {
16229
16242
  return `${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 10)}`;
16230
16243
  }
16231
16244
  function createDescriptor(input) {
@@ -16364,7 +16377,7 @@ var Namespace = class {
16364
16377
  },
16365
16378
  appendRow: async (data) => {
16366
16379
  const log = {
16367
- hash: createHash4(),
16380
+ hash: createHash3(),
16368
16381
  t: Date.now(),
16369
16382
  kind: LOG_KIND_TABLE,
16370
16383
  topic: descriptorToTopic(descriptor),
@@ -16376,7 +16389,7 @@ var Namespace = class {
16376
16389
  updateRow: async (data) => {
16377
16390
  const { id, ...value } = data;
16378
16391
  const log = {
16379
- hash: createHash4(),
16392
+ hash: createHash3(),
16380
16393
  t: Date.now(),
16381
16394
  kind: LOG_KIND_TABLE,
16382
16395
  topic: descriptorToTopic(descriptor),
@@ -16387,7 +16400,7 @@ var Namespace = class {
16387
16400
  },
16388
16401
  deleteRow: async (id) => {
16389
16402
  const log = {
16390
- hash: createHash4(),
16403
+ hash: createHash3(),
16391
16404
  t: Date.now(),
16392
16405
  kind: LOG_KIND_TABLE,
16393
16406
  topic: descriptorToTopic(descriptor),
@@ -16430,7 +16443,7 @@ var Namespace = class {
16430
16443
  },
16431
16444
  set: async (key, value) => {
16432
16445
  const log = {
16433
- hash: createHash4(),
16446
+ hash: createHash3(),
16434
16447
  t: Date.now(),
16435
16448
  kind: LOG_KIND_MAPPING,
16436
16449
  topic: descriptorToTopic(descriptor),
@@ -16441,7 +16454,7 @@ var Namespace = class {
16441
16454
  },
16442
16455
  delete: async (key) => {
16443
16456
  const log = {
16444
- hash: createHash4(),
16457
+ hash: createHash3(),
16445
16458
  t: Date.now(),
16446
16459
  kind: LOG_KIND_MAPPING,
16447
16460
  topic: descriptorToTopic(descriptor),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pmate/cli",
3
- "version": "0.21.14",
3
+ "version": "0.21.15",
4
4
  "description": "CLI utilities for the pMate project",
5
5
  "license": "MIT",
6
6
  "bin": {