@adhdev/daemon-core 0.9.76-rc.54 → 0.9.76-rc.56

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.mjs CHANGED
@@ -11869,7 +11869,7 @@ function normalizeReadChatTailLimit(args) {
11869
11869
  }
11870
11870
  function normalizeReadChatMessages(payload) {
11871
11871
  const messages = Array.isArray(payload.messages) ? payload.messages : [];
11872
- return messages;
11872
+ return normalizeChatMessages(messages);
11873
11873
  }
11874
11874
  function deriveHistoryDedupKey(message) {
11875
11875
  const unitKey = typeof message._unitKey === "string" ? message._unitKey.trim() : "";
@@ -15601,16 +15601,46 @@ ${effect.notification.body || ""}`.trim();
15601
15601
  const runtimeEntries = this.runtimeMessages.map((entry, index) => ({
15602
15602
  message: entry.message,
15603
15603
  index: parsedMessages.length + index,
15604
- source: "runtime"
15604
+ source: "runtime",
15605
+ runtimeKey: entry.key
15605
15606
  }));
15606
15607
  const getTime = (message) => {
15607
15608
  const value = typeof message.receivedAt === "number" ? message.receivedAt : typeof message.timestamp === "number" ? message.timestamp : 0;
15608
15609
  return Number.isFinite(value) && value > 0 ? value : 0;
15609
15610
  };
15611
+ const getRole = (message) => typeof message.role === "string" ? message.role.trim().toLowerCase() : "";
15612
+ const isRuntimeOverlay = (entry) => {
15613
+ if (entry.source !== "runtime") return false;
15614
+ const key = typeof entry.runtimeKey === "string" ? entry.runtimeKey.trim().toLowerCase() : "";
15615
+ if (key.startsWith("auto_approval:")) return true;
15616
+ return !isUserFacingChatMessage(entry.message);
15617
+ };
15618
+ const shouldKeepParsedBeforeUntimedRuntime = (message) => {
15619
+ const role = getRole(message);
15620
+ return role === "user" || role === "human";
15621
+ };
15622
+ const shouldKeepParsedAfterUntimedRuntime = (message) => {
15623
+ const role = getRole(message);
15624
+ if (role !== "assistant") return false;
15625
+ const kind = resolveChatMessageKind(message);
15626
+ return kind === "standard" || kind === "terminal";
15627
+ };
15610
15628
  return normalizeChatMessages([...parsedEntries, ...runtimeEntries].sort((a, b) => {
15611
15629
  const aTime = getTime(a.message);
15612
15630
  const bTime = getTime(b.message);
15613
15631
  if (aTime && bTime && aTime !== bTime) return aTime - bTime;
15632
+ if (a.source !== b.source && aTime !== bTime) {
15633
+ const parsedEntry = a.source === "parsed" ? a : b.source === "parsed" ? b : null;
15634
+ const runtimeEntry = a.source === "runtime" ? a : b.source === "runtime" ? b : null;
15635
+ if (parsedEntry && runtimeEntry && isRuntimeOverlay(runtimeEntry) && getTime(parsedEntry.message) === 0 && getTime(runtimeEntry.message) > 0) {
15636
+ if (shouldKeepParsedBeforeUntimedRuntime(parsedEntry.message)) {
15637
+ return a.source === "parsed" ? -1 : 1;
15638
+ }
15639
+ if (shouldKeepParsedAfterUntimedRuntime(parsedEntry.message)) {
15640
+ return a.source === "parsed" ? 1 : -1;
15641
+ }
15642
+ }
15643
+ }
15614
15644
  return a.index - b.index;
15615
15645
  }).map((entry) => entry.message));
15616
15646
  }