@adhdev/daemon-standalone 0.8.83 → 0.8.84

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
@@ -39867,6 +39867,30 @@ ${effect.notification.body || ""}`.trim();
39867
39867
  init_provider_cli_adapter();
39868
39868
  init_logger();
39869
39869
  init_chat_message_normalization();
39870
+ function normalizePersistableCliHistoryContent(content) {
39871
+ return flattenContent(content).replace(/\s+/g, " ").trim();
39872
+ }
39873
+ function buildPersistableCliHistorySignature(message) {
39874
+ return [
39875
+ String(message.role || ""),
39876
+ String(message.kind || ""),
39877
+ String(message.senderName || ""),
39878
+ normalizePersistableCliHistoryContent(message.content)
39879
+ ].join("|");
39880
+ }
39881
+ function buildIncrementalHistoryAppendMessages(previousMessages, currentMessages) {
39882
+ if (!Array.isArray(currentMessages) || currentMessages.length === 0) return [];
39883
+ if (!Array.isArray(previousMessages) || previousMessages.length === 0) return currentMessages;
39884
+ const previousSignatures = previousMessages.map(buildPersistableCliHistorySignature);
39885
+ const currentSignatures = currentMessages.map(buildPersistableCliHistorySignature);
39886
+ let sharedPrefixLength = 0;
39887
+ while (sharedPrefixLength < previousSignatures.length && sharedPrefixLength < currentSignatures.length && previousSignatures[sharedPrefixLength] === currentSignatures[sharedPrefixLength]) {
39888
+ sharedPrefixLength += 1;
39889
+ }
39890
+ if (sharedPrefixLength === currentSignatures.length) return [];
39891
+ if (sharedPrefixLength === previousSignatures.length) return currentMessages.slice(sharedPrefixLength);
39892
+ return currentMessages;
39893
+ }
39870
39894
  var CachedDatabaseSync = null;
39871
39895
  function getDatabaseSync() {
39872
39896
  if (CachedDatabaseSync) return CachedDatabaseSync;
@@ -39944,6 +39968,7 @@ ${effect.notification.body || ""}`.trim();
39944
39968
  appliedEffectKeys = /* @__PURE__ */ new Set();
39945
39969
  historyWriter;
39946
39970
  runtimeMessages = [];
39971
+ lastPersistedHistoryMessages = [];
39947
39972
  instanceId;
39948
39973
  suppressIdleHistoryReplay = false;
39949
39974
  errorMessage = void 0;
@@ -39984,6 +40009,13 @@ ${effect.notification.body || ""}`.trim();
39984
40009
  this.providerSessionId,
39985
40010
  this.instanceId
39986
40011
  );
40012
+ this.lastPersistedHistoryMessages = restoredHistory.messages.map((message) => ({
40013
+ role: message.role,
40014
+ content: message.content,
40015
+ kind: message.kind,
40016
+ senderName: message.senderName,
40017
+ receivedAt: message.receivedAt
40018
+ }));
39987
40019
  this.suppressIdleHistoryReplay = restoredHistory.messages.length > 0;
39988
40020
  if (restoredHistory.messages.length > 0) {
39989
40021
  this.adapter.seedCommittedMessages(
@@ -40115,15 +40147,24 @@ ${effect.notification.body || ""}`.trim();
40115
40147
  messagesToSave = messagesToSave.slice(0, lastIdx);
40116
40148
  }
40117
40149
  }
40118
- if (!shouldSkipReplayPersist && messagesToSave.length > 0) {
40150
+ const normalizedMessagesToSave = messagesToSave.map((message) => ({
40151
+ role: message.role,
40152
+ content: flattenContent(message.content),
40153
+ kind: typeof message.kind === "string" ? message.kind : void 0,
40154
+ senderName: typeof message.senderName === "string" ? message.senderName : void 0,
40155
+ receivedAt: typeof message.receivedAt === "number" ? message.receivedAt : message.timestamp
40156
+ }));
40157
+ if (!shouldSkipReplayPersist && normalizedMessagesToSave.length > 0) {
40158
+ const incrementalMessages = buildIncrementalHistoryAppendMessages(this.lastPersistedHistoryMessages, normalizedMessagesToSave);
40119
40159
  this.historyWriter.appendNewMessages(
40120
40160
  this.type,
40121
- messagesToSave,
40161
+ incrementalMessages,
40122
40162
  parsedStatus?.title || dirName,
40123
40163
  this.instanceId,
40124
40164
  this.providerSessionId
40125
40165
  );
40126
40166
  }
40167
+ this.lastPersistedHistoryMessages = normalizedMessagesToSave;
40127
40168
  }
40128
40169
  this.applyProviderResponse(parsedStatus, { phase: "immediate" });
40129
40170
  const surface = resolveProviderStateSurface({
@@ -40371,6 +40412,7 @@ ${effect.notification.body || ""}`.trim();
40371
40412
  }
40372
40413
  if (data.sessionEvent === "new_session") {
40373
40414
  this.runtimeMessages = [];
40415
+ this.lastPersistedHistoryMessages = [];
40374
40416
  this.suppressIdleHistoryReplay = false;
40375
40417
  this.adapter.clearHistory();
40376
40418
  }