@adhdev/daemon-core 0.9.37 → 0.9.38

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
@@ -13137,17 +13137,24 @@ function buildPersistableCliHistorySignature(message) {
13137
13137
  normalizePersistableCliHistoryContent(message.content)
13138
13138
  ].join("|");
13139
13139
  }
13140
+ function hasSamePersistableCliHistoryIdentity(a, b) {
13141
+ return String(a?.role || "") === String(b?.role || "") && String(a?.kind || "") === String(b?.kind || "") && String(a?.senderName || "") === String(b?.senderName || "") && String(a?.content || "") === String(b?.content || "");
13142
+ }
13140
13143
  function buildIncrementalHistoryAppendMessages(previousMessages, currentMessages) {
13141
13144
  if (!Array.isArray(currentMessages) || currentMessages.length === 0) return [];
13142
13145
  if (!Array.isArray(previousMessages) || previousMessages.length === 0) return currentMessages;
13143
- const previousSignatures = previousMessages.map(buildPersistableCliHistorySignature);
13144
- const currentSignatures = currentMessages.map(buildPersistableCliHistorySignature);
13146
+ const comparableLength = Math.min(previousMessages.length, currentMessages.length);
13145
13147
  let sharedPrefixLength = 0;
13146
- while (sharedPrefixLength < previousSignatures.length && sharedPrefixLength < currentSignatures.length && previousSignatures[sharedPrefixLength] === currentSignatures[sharedPrefixLength]) {
13148
+ while (sharedPrefixLength < comparableLength && hasSamePersistableCliHistoryIdentity(previousMessages[sharedPrefixLength], currentMessages[sharedPrefixLength])) {
13149
+ sharedPrefixLength += 1;
13150
+ }
13151
+ if (sharedPrefixLength === currentMessages.length) return [];
13152
+ if (sharedPrefixLength === previousMessages.length) return currentMessages.slice(sharedPrefixLength);
13153
+ while (sharedPrefixLength < comparableLength && buildPersistableCliHistorySignature(previousMessages[sharedPrefixLength]) === buildPersistableCliHistorySignature(currentMessages[sharedPrefixLength])) {
13147
13154
  sharedPrefixLength += 1;
13148
13155
  }
13149
- if (sharedPrefixLength === currentSignatures.length) return [];
13150
- if (sharedPrefixLength === previousSignatures.length) return currentMessages.slice(sharedPrefixLength);
13156
+ if (sharedPrefixLength === currentMessages.length) return [];
13157
+ if (sharedPrefixLength === previousMessages.length) return currentMessages.slice(sharedPrefixLength);
13151
13158
  return currentMessages;
13152
13159
  }
13153
13160
  var CachedDatabaseSync = null;
@@ -13393,13 +13400,15 @@ var CliProviderInstance = class {
13393
13400
  }));
13394
13401
  if (!canonicalBackedHistory && !shouldSkipReplayPersist && normalizedMessagesToSave.length > 0) {
13395
13402
  const incrementalMessages = buildIncrementalHistoryAppendMessages(this.lastPersistedHistoryMessages, normalizedMessagesToSave);
13396
- this.historyWriter.appendNewMessages(
13397
- this.type,
13398
- incrementalMessages,
13399
- parsedStatus?.title || dirName,
13400
- this.instanceId,
13401
- this.providerSessionId
13402
- );
13403
+ if (incrementalMessages.length > 0) {
13404
+ this.historyWriter.appendNewMessages(
13405
+ this.type,
13406
+ incrementalMessages,
13407
+ parsedStatus?.title || dirName,
13408
+ this.instanceId,
13409
+ this.providerSessionId
13410
+ );
13411
+ }
13403
13412
  }
13404
13413
  if (!canonicalBackedHistory) {
13405
13414
  this.lastPersistedHistoryMessages = normalizedMessagesToSave;