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/cli/index.js CHANGED
@@ -9409,9 +9409,34 @@ function findLastMessageIndexBySignature(messages, signature) {
9409
9409
  }
9410
9410
  return -1;
9411
9411
  }
9412
+ function isReadChatConversationAnchorMessage(message) {
9413
+ if (!message) return false;
9414
+ const role = String(message.role || "").trim().toLowerCase();
9415
+ if (role !== "user" && role !== "assistant") return false;
9416
+ const kind = String(message.kind || "standard").trim().toLowerCase();
9417
+ return !kind || kind === "standard";
9418
+ }
9419
+ function buildVisibleReadChatTailMessages(messages, tailLimit) {
9420
+ const totalMessages = messages.length;
9421
+ if (tailLimit <= 0 || totalMessages <= tailLimit) return messages;
9422
+ const tailMessages = messages.slice(-tailLimit);
9423
+ if (tailMessages.some(isReadChatConversationAnchorMessage)) return tailMessages;
9424
+ const hiddenMessages = messages.slice(0, totalMessages - tailLimit);
9425
+ const anchors = [];
9426
+ const seenRoles = /* @__PURE__ */ new Set();
9427
+ for (let index = hiddenMessages.length - 1; index >= 0 && anchors.length < 2; index -= 1) {
9428
+ const message = hiddenMessages[index];
9429
+ if (!isReadChatConversationAnchorMessage(message)) continue;
9430
+ const role = String(message.role || "").trim().toLowerCase();
9431
+ if (seenRoles.has(role)) continue;
9432
+ seenRoles.add(role);
9433
+ anchors.unshift(message);
9434
+ }
9435
+ return anchors.length > 0 ? [...anchors, ...tailMessages] : tailMessages;
9436
+ }
9412
9437
  function buildBoundedTailSync(messages, cursor) {
9413
9438
  const totalMessages = messages.length;
9414
- const tailMessages = cursor.tailLimit > 0 && totalMessages > cursor.tailLimit ? messages.slice(-cursor.tailLimit) : messages;
9439
+ const tailMessages = buildVisibleReadChatTailMessages(messages, cursor.tailLimit);
9415
9440
  return {
9416
9441
  syncMode: "full",
9417
9442
  replaceFrom: 0,
@@ -9533,8 +9558,8 @@ function buildReadChatCommandResult(payload, args) {
9533
9558
  const messages = collapseReplayDuplicatesFromReadChat(normalizeReadChatMessages(validatedPayload));
9534
9559
  const cursor = normalizeReadChatCursor(args);
9535
9560
  if (!cursor.knownMessageCount && !cursor.lastMessageSignature && cursor.tailLimit > 0 && messages.length > cursor.tailLimit) {
9536
- const tailMessages = messages.slice(-cursor.tailLimit);
9537
- const lastMessageSignature = getChatMessageSignature(tailMessages[tailMessages.length - 1]);
9561
+ const tailMessages = buildVisibleReadChatTailMessages(messages, cursor.tailLimit);
9562
+ const lastMessageSignature = getChatMessageSignature(messages[messages.length - 1]);
9538
9563
  return {
9539
9564
  success: true,
9540
9565
  ...validatedPayload,
@@ -90388,7 +90413,7 @@ var init_adhdev_daemon = __esm({
90388
90413
  init_version();
90389
90414
  init_src();
90390
90415
  init_runtime_defaults();
90391
- pkgVersion = resolvePackageVersion({ injectedVersion: "0.9.63" });
90416
+ pkgVersion = resolvePackageVersion({ injectedVersion: "0.9.64" });
90392
90417
  AdhdevDaemon = class _AdhdevDaemon {
90393
90418
  localHttpServer = null;
90394
90419
  localWss = null;