@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.js CHANGED
@@ -12067,7 +12067,7 @@ function normalizeReadChatTailLimit(args) {
12067
12067
  }
12068
12068
  function normalizeReadChatMessages(payload) {
12069
12069
  const messages = Array.isArray(payload.messages) ? payload.messages : [];
12070
- return messages;
12070
+ return normalizeChatMessages(messages);
12071
12071
  }
12072
12072
  function deriveHistoryDedupKey(message) {
12073
12073
  const unitKey = typeof message._unitKey === "string" ? message._unitKey.trim() : "";
@@ -15799,16 +15799,46 @@ ${effect.notification.body || ""}`.trim();
15799
15799
  const runtimeEntries = this.runtimeMessages.map((entry, index) => ({
15800
15800
  message: entry.message,
15801
15801
  index: parsedMessages.length + index,
15802
- source: "runtime"
15802
+ source: "runtime",
15803
+ runtimeKey: entry.key
15803
15804
  }));
15804
15805
  const getTime = (message) => {
15805
15806
  const value = typeof message.receivedAt === "number" ? message.receivedAt : typeof message.timestamp === "number" ? message.timestamp : 0;
15806
15807
  return Number.isFinite(value) && value > 0 ? value : 0;
15807
15808
  };
15809
+ const getRole = (message) => typeof message.role === "string" ? message.role.trim().toLowerCase() : "";
15810
+ const isRuntimeOverlay = (entry) => {
15811
+ if (entry.source !== "runtime") return false;
15812
+ const key = typeof entry.runtimeKey === "string" ? entry.runtimeKey.trim().toLowerCase() : "";
15813
+ if (key.startsWith("auto_approval:")) return true;
15814
+ return !isUserFacingChatMessage(entry.message);
15815
+ };
15816
+ const shouldKeepParsedBeforeUntimedRuntime = (message) => {
15817
+ const role = getRole(message);
15818
+ return role === "user" || role === "human";
15819
+ };
15820
+ const shouldKeepParsedAfterUntimedRuntime = (message) => {
15821
+ const role = getRole(message);
15822
+ if (role !== "assistant") return false;
15823
+ const kind = resolveChatMessageKind(message);
15824
+ return kind === "standard" || kind === "terminal";
15825
+ };
15808
15826
  return normalizeChatMessages([...parsedEntries, ...runtimeEntries].sort((a, b) => {
15809
15827
  const aTime = getTime(a.message);
15810
15828
  const bTime = getTime(b.message);
15811
15829
  if (aTime && bTime && aTime !== bTime) return aTime - bTime;
15830
+ if (a.source !== b.source && aTime !== bTime) {
15831
+ const parsedEntry = a.source === "parsed" ? a : b.source === "parsed" ? b : null;
15832
+ const runtimeEntry = a.source === "runtime" ? a : b.source === "runtime" ? b : null;
15833
+ if (parsedEntry && runtimeEntry && isRuntimeOverlay(runtimeEntry) && getTime(parsedEntry.message) === 0 && getTime(runtimeEntry.message) > 0) {
15834
+ if (shouldKeepParsedBeforeUntimedRuntime(parsedEntry.message)) {
15835
+ return a.source === "parsed" ? -1 : 1;
15836
+ }
15837
+ if (shouldKeepParsedAfterUntimedRuntime(parsedEntry.message)) {
15838
+ return a.source === "parsed" ? 1 : -1;
15839
+ }
15840
+ }
15841
+ }
15812
15842
  return a.index - b.index;
15813
15843
  }).map((entry) => entry.message));
15814
15844
  }