@adhdev/daemon-core 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.mjs CHANGED
@@ -11984,6 +11984,30 @@ import { createRequire } from "module";
11984
11984
  init_provider_cli_adapter();
11985
11985
  init_logger();
11986
11986
  init_chat_message_normalization();
11987
+ function normalizePersistableCliHistoryContent(content) {
11988
+ return flattenContent(content).replace(/\s+/g, " ").trim();
11989
+ }
11990
+ function buildPersistableCliHistorySignature(message) {
11991
+ return [
11992
+ String(message.role || ""),
11993
+ String(message.kind || ""),
11994
+ String(message.senderName || ""),
11995
+ normalizePersistableCliHistoryContent(message.content)
11996
+ ].join("|");
11997
+ }
11998
+ function buildIncrementalHistoryAppendMessages(previousMessages, currentMessages) {
11999
+ if (!Array.isArray(currentMessages) || currentMessages.length === 0) return [];
12000
+ if (!Array.isArray(previousMessages) || previousMessages.length === 0) return currentMessages;
12001
+ const previousSignatures = previousMessages.map(buildPersistableCliHistorySignature);
12002
+ const currentSignatures = currentMessages.map(buildPersistableCliHistorySignature);
12003
+ let sharedPrefixLength = 0;
12004
+ while (sharedPrefixLength < previousSignatures.length && sharedPrefixLength < currentSignatures.length && previousSignatures[sharedPrefixLength] === currentSignatures[sharedPrefixLength]) {
12005
+ sharedPrefixLength += 1;
12006
+ }
12007
+ if (sharedPrefixLength === currentSignatures.length) return [];
12008
+ if (sharedPrefixLength === previousSignatures.length) return currentMessages.slice(sharedPrefixLength);
12009
+ return currentMessages;
12010
+ }
11987
12011
  var CachedDatabaseSync = null;
11988
12012
  function getDatabaseSync() {
11989
12013
  if (CachedDatabaseSync) return CachedDatabaseSync;
@@ -12061,6 +12085,7 @@ var CliProviderInstance = class {
12061
12085
  appliedEffectKeys = /* @__PURE__ */ new Set();
12062
12086
  historyWriter;
12063
12087
  runtimeMessages = [];
12088
+ lastPersistedHistoryMessages = [];
12064
12089
  instanceId;
12065
12090
  suppressIdleHistoryReplay = false;
12066
12091
  errorMessage = void 0;
@@ -12101,6 +12126,13 @@ var CliProviderInstance = class {
12101
12126
  this.providerSessionId,
12102
12127
  this.instanceId
12103
12128
  );
12129
+ this.lastPersistedHistoryMessages = restoredHistory.messages.map((message) => ({
12130
+ role: message.role,
12131
+ content: message.content,
12132
+ kind: message.kind,
12133
+ senderName: message.senderName,
12134
+ receivedAt: message.receivedAt
12135
+ }));
12104
12136
  this.suppressIdleHistoryReplay = restoredHistory.messages.length > 0;
12105
12137
  if (restoredHistory.messages.length > 0) {
12106
12138
  this.adapter.seedCommittedMessages(
@@ -12232,15 +12264,24 @@ var CliProviderInstance = class {
12232
12264
  messagesToSave = messagesToSave.slice(0, lastIdx);
12233
12265
  }
12234
12266
  }
12235
- if (!shouldSkipReplayPersist && messagesToSave.length > 0) {
12267
+ const normalizedMessagesToSave = messagesToSave.map((message) => ({
12268
+ role: message.role,
12269
+ content: flattenContent(message.content),
12270
+ kind: typeof message.kind === "string" ? message.kind : void 0,
12271
+ senderName: typeof message.senderName === "string" ? message.senderName : void 0,
12272
+ receivedAt: typeof message.receivedAt === "number" ? message.receivedAt : message.timestamp
12273
+ }));
12274
+ if (!shouldSkipReplayPersist && normalizedMessagesToSave.length > 0) {
12275
+ const incrementalMessages = buildIncrementalHistoryAppendMessages(this.lastPersistedHistoryMessages, normalizedMessagesToSave);
12236
12276
  this.historyWriter.appendNewMessages(
12237
12277
  this.type,
12238
- messagesToSave,
12278
+ incrementalMessages,
12239
12279
  parsedStatus?.title || dirName,
12240
12280
  this.instanceId,
12241
12281
  this.providerSessionId
12242
12282
  );
12243
12283
  }
12284
+ this.lastPersistedHistoryMessages = normalizedMessagesToSave;
12244
12285
  }
12245
12286
  this.applyProviderResponse(parsedStatus, { phase: "immediate" });
12246
12287
  const surface = resolveProviderStateSurface({
@@ -12488,6 +12529,7 @@ var CliProviderInstance = class {
12488
12529
  }
12489
12530
  if (data.sessionEvent === "new_session") {
12490
12531
  this.runtimeMessages = [];
12532
+ this.lastPersistedHistoryMessages = [];
12491
12533
  this.suppressIdleHistoryReplay = false;
12492
12534
  this.adapter.clearHistory();
12493
12535
  }