adhdev 0.9.63 → 0.9.64

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
@@ -8889,9 +8889,34 @@ function findLastMessageIndexBySignature(messages, signature) {
8889
8889
  }
8890
8890
  return -1;
8891
8891
  }
8892
+ function isReadChatConversationAnchorMessage(message) {
8893
+ if (!message) return false;
8894
+ const role = String(message.role || "").trim().toLowerCase();
8895
+ if (role !== "user" && role !== "assistant") return false;
8896
+ const kind = String(message.kind || "standard").trim().toLowerCase();
8897
+ return !kind || kind === "standard";
8898
+ }
8899
+ function buildVisibleReadChatTailMessages(messages, tailLimit) {
8900
+ const totalMessages = messages.length;
8901
+ if (tailLimit <= 0 || totalMessages <= tailLimit) return messages;
8902
+ const tailMessages = messages.slice(-tailLimit);
8903
+ if (tailMessages.some(isReadChatConversationAnchorMessage)) return tailMessages;
8904
+ const hiddenMessages = messages.slice(0, totalMessages - tailLimit);
8905
+ const anchors = [];
8906
+ const seenRoles = /* @__PURE__ */ new Set();
8907
+ for (let index = hiddenMessages.length - 1; index >= 0 && anchors.length < 2; index -= 1) {
8908
+ const message = hiddenMessages[index];
8909
+ if (!isReadChatConversationAnchorMessage(message)) continue;
8910
+ const role = String(message.role || "").trim().toLowerCase();
8911
+ if (seenRoles.has(role)) continue;
8912
+ seenRoles.add(role);
8913
+ anchors.unshift(message);
8914
+ }
8915
+ return anchors.length > 0 ? [...anchors, ...tailMessages] : tailMessages;
8916
+ }
8892
8917
  function buildBoundedTailSync(messages, cursor) {
8893
8918
  const totalMessages = messages.length;
8894
- const tailMessages = cursor.tailLimit > 0 && totalMessages > cursor.tailLimit ? messages.slice(-cursor.tailLimit) : messages;
8919
+ const tailMessages = buildVisibleReadChatTailMessages(messages, cursor.tailLimit);
8895
8920
  return {
8896
8921
  syncMode: "full",
8897
8922
  replaceFrom: 0,
@@ -9013,8 +9038,8 @@ function buildReadChatCommandResult(payload, args) {
9013
9038
  const messages = collapseReplayDuplicatesFromReadChat(normalizeReadChatMessages(validatedPayload));
9014
9039
  const cursor = normalizeReadChatCursor(args);
9015
9040
  if (!cursor.knownMessageCount && !cursor.lastMessageSignature && cursor.tailLimit > 0 && messages.length > cursor.tailLimit) {
9016
- const tailMessages = messages.slice(-cursor.tailLimit);
9017
- const lastMessageSignature = getChatMessageSignature(tailMessages[tailMessages.length - 1]);
9041
+ const tailMessages = buildVisibleReadChatTailMessages(messages, cursor.tailLimit);
9042
+ const lastMessageSignature = getChatMessageSignature(messages[messages.length - 1]);
9018
9043
  return {
9019
9044
  success: true,
9020
9045
  ...validatedPayload,
@@ -59246,7 +59271,7 @@ var init_adhdev_daemon = __esm({
59246
59271
  init_version();
59247
59272
  init_src();
59248
59273
  init_runtime_defaults();
59249
- pkgVersion = resolvePackageVersion({ injectedVersion: "0.9.63" });
59274
+ pkgVersion = resolvePackageVersion({ injectedVersion: "0.9.64" });
59250
59275
  AdhdevDaemon = class _AdhdevDaemon {
59251
59276
  localHttpServer = null;
59252
59277
  localWss = null;