@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.
@@ -102,4 +102,5 @@ export declare function listSavedHistorySessions(agentType: string, options?: {
102
102
  sessions: SavedHistorySessionSummary[];
103
103
  hasMore: boolean;
104
104
  };
105
+ export declare function rebuildHermesSavedHistoryFromCanonicalSession(historySessionId: string): boolean;
105
106
  export {};
package/dist/index.js CHANGED
@@ -12123,6 +12123,30 @@ init_contracts();
12123
12123
  init_provider_cli_adapter();
12124
12124
  init_logger();
12125
12125
  init_chat_message_normalization();
12126
+ function normalizePersistableCliHistoryContent(content) {
12127
+ return flattenContent(content).replace(/\s+/g, " ").trim();
12128
+ }
12129
+ function buildPersistableCliHistorySignature(message) {
12130
+ return [
12131
+ String(message.role || ""),
12132
+ String(message.kind || ""),
12133
+ String(message.senderName || ""),
12134
+ normalizePersistableCliHistoryContent(message.content)
12135
+ ].join("|");
12136
+ }
12137
+ function buildIncrementalHistoryAppendMessages(previousMessages, currentMessages) {
12138
+ if (!Array.isArray(currentMessages) || currentMessages.length === 0) return [];
12139
+ if (!Array.isArray(previousMessages) || previousMessages.length === 0) return currentMessages;
12140
+ const previousSignatures = previousMessages.map(buildPersistableCliHistorySignature);
12141
+ const currentSignatures = currentMessages.map(buildPersistableCliHistorySignature);
12142
+ let sharedPrefixLength = 0;
12143
+ while (sharedPrefixLength < previousSignatures.length && sharedPrefixLength < currentSignatures.length && previousSignatures[sharedPrefixLength] === currentSignatures[sharedPrefixLength]) {
12144
+ sharedPrefixLength += 1;
12145
+ }
12146
+ if (sharedPrefixLength === currentSignatures.length) return [];
12147
+ if (sharedPrefixLength === previousSignatures.length) return currentMessages.slice(sharedPrefixLength);
12148
+ return currentMessages;
12149
+ }
12126
12150
  var CachedDatabaseSync = null;
12127
12151
  function getDatabaseSync() {
12128
12152
  if (CachedDatabaseSync) return CachedDatabaseSync;
@@ -12200,6 +12224,7 @@ var CliProviderInstance = class {
12200
12224
  appliedEffectKeys = /* @__PURE__ */ new Set();
12201
12225
  historyWriter;
12202
12226
  runtimeMessages = [];
12227
+ lastPersistedHistoryMessages = [];
12203
12228
  instanceId;
12204
12229
  suppressIdleHistoryReplay = false;
12205
12230
  errorMessage = void 0;
@@ -12240,6 +12265,13 @@ var CliProviderInstance = class {
12240
12265
  this.providerSessionId,
12241
12266
  this.instanceId
12242
12267
  );
12268
+ this.lastPersistedHistoryMessages = restoredHistory.messages.map((message) => ({
12269
+ role: message.role,
12270
+ content: message.content,
12271
+ kind: message.kind,
12272
+ senderName: message.senderName,
12273
+ receivedAt: message.receivedAt
12274
+ }));
12243
12275
  this.suppressIdleHistoryReplay = restoredHistory.messages.length > 0;
12244
12276
  if (restoredHistory.messages.length > 0) {
12245
12277
  this.adapter.seedCommittedMessages(
@@ -12371,15 +12403,24 @@ var CliProviderInstance = class {
12371
12403
  messagesToSave = messagesToSave.slice(0, lastIdx);
12372
12404
  }
12373
12405
  }
12374
- if (!shouldSkipReplayPersist && messagesToSave.length > 0) {
12406
+ const normalizedMessagesToSave = messagesToSave.map((message) => ({
12407
+ role: message.role,
12408
+ content: flattenContent(message.content),
12409
+ kind: typeof message.kind === "string" ? message.kind : void 0,
12410
+ senderName: typeof message.senderName === "string" ? message.senderName : void 0,
12411
+ receivedAt: typeof message.receivedAt === "number" ? message.receivedAt : message.timestamp
12412
+ }));
12413
+ if (!shouldSkipReplayPersist && normalizedMessagesToSave.length > 0) {
12414
+ const incrementalMessages = buildIncrementalHistoryAppendMessages(this.lastPersistedHistoryMessages, normalizedMessagesToSave);
12375
12415
  this.historyWriter.appendNewMessages(
12376
12416
  this.type,
12377
- messagesToSave,
12417
+ incrementalMessages,
12378
12418
  parsedStatus?.title || dirName,
12379
12419
  this.instanceId,
12380
12420
  this.providerSessionId
12381
12421
  );
12382
12422
  }
12423
+ this.lastPersistedHistoryMessages = normalizedMessagesToSave;
12383
12424
  }
12384
12425
  this.applyProviderResponse(parsedStatus, { phase: "immediate" });
12385
12426
  const surface = resolveProviderStateSurface({
@@ -12627,6 +12668,7 @@ var CliProviderInstance = class {
12627
12668
  }
12628
12669
  if (data.sessionEvent === "new_session") {
12629
12670
  this.runtimeMessages = [];
12671
+ this.lastPersistedHistoryMessages = [];
12630
12672
  this.suppressIdleHistoryReplay = false;
12631
12673
  this.adapter.clearHistory();
12632
12674
  }