adhdev 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/cli/index.js CHANGED
@@ -13879,6 +13879,30 @@ ${data.message || ""}`.trim();
13879
13879
  });
13880
13880
 
13881
13881
  // ../../oss/packages/daemon-core/src/providers/cli-provider-instance.ts
13882
+ function normalizePersistableCliHistoryContent(content) {
13883
+ return flattenContent(content).replace(/\s+/g, " ").trim();
13884
+ }
13885
+ function buildPersistableCliHistorySignature(message) {
13886
+ return [
13887
+ String(message.role || ""),
13888
+ String(message.kind || ""),
13889
+ String(message.senderName || ""),
13890
+ normalizePersistableCliHistoryContent(message.content)
13891
+ ].join("|");
13892
+ }
13893
+ function buildIncrementalHistoryAppendMessages(previousMessages, currentMessages) {
13894
+ if (!Array.isArray(currentMessages) || currentMessages.length === 0) return [];
13895
+ if (!Array.isArray(previousMessages) || previousMessages.length === 0) return currentMessages;
13896
+ const previousSignatures = previousMessages.map(buildPersistableCliHistorySignature);
13897
+ const currentSignatures = currentMessages.map(buildPersistableCliHistorySignature);
13898
+ let sharedPrefixLength = 0;
13899
+ while (sharedPrefixLength < previousSignatures.length && sharedPrefixLength < currentSignatures.length && previousSignatures[sharedPrefixLength] === currentSignatures[sharedPrefixLength]) {
13900
+ sharedPrefixLength += 1;
13901
+ }
13902
+ if (sharedPrefixLength === currentSignatures.length) return [];
13903
+ if (sharedPrefixLength === previousSignatures.length) return currentMessages.slice(sharedPrefixLength);
13904
+ return currentMessages;
13905
+ }
13882
13906
  function getDatabaseSync() {
13883
13907
  if (CachedDatabaseSync) return CachedDatabaseSync;
13884
13908
  const requireFn = typeof require === "function" ? require : (0, import_node_module.createRequire)(path12.join(process.cwd(), "__adhdev_sqlite_loader__.js"));
@@ -13977,6 +14001,7 @@ var init_cli_provider_instance = __esm({
13977
14001
  appliedEffectKeys = /* @__PURE__ */ new Set();
13978
14002
  historyWriter;
13979
14003
  runtimeMessages = [];
14004
+ lastPersistedHistoryMessages = [];
13980
14005
  instanceId;
13981
14006
  suppressIdleHistoryReplay = false;
13982
14007
  errorMessage = void 0;
@@ -14017,6 +14042,13 @@ var init_cli_provider_instance = __esm({
14017
14042
  this.providerSessionId,
14018
14043
  this.instanceId
14019
14044
  );
14045
+ this.lastPersistedHistoryMessages = restoredHistory.messages.map((message) => ({
14046
+ role: message.role,
14047
+ content: message.content,
14048
+ kind: message.kind,
14049
+ senderName: message.senderName,
14050
+ receivedAt: message.receivedAt
14051
+ }));
14020
14052
  this.suppressIdleHistoryReplay = restoredHistory.messages.length > 0;
14021
14053
  if (restoredHistory.messages.length > 0) {
14022
14054
  this.adapter.seedCommittedMessages(
@@ -14148,15 +14180,24 @@ var init_cli_provider_instance = __esm({
14148
14180
  messagesToSave = messagesToSave.slice(0, lastIdx);
14149
14181
  }
14150
14182
  }
14151
- if (!shouldSkipReplayPersist && messagesToSave.length > 0) {
14183
+ const normalizedMessagesToSave = messagesToSave.map((message) => ({
14184
+ role: message.role,
14185
+ content: flattenContent(message.content),
14186
+ kind: typeof message.kind === "string" ? message.kind : void 0,
14187
+ senderName: typeof message.senderName === "string" ? message.senderName : void 0,
14188
+ receivedAt: typeof message.receivedAt === "number" ? message.receivedAt : message.timestamp
14189
+ }));
14190
+ if (!shouldSkipReplayPersist && normalizedMessagesToSave.length > 0) {
14191
+ const incrementalMessages = buildIncrementalHistoryAppendMessages(this.lastPersistedHistoryMessages, normalizedMessagesToSave);
14152
14192
  this.historyWriter.appendNewMessages(
14153
14193
  this.type,
14154
- messagesToSave,
14194
+ incrementalMessages,
14155
14195
  parsedStatus?.title || dirName,
14156
14196
  this.instanceId,
14157
14197
  this.providerSessionId
14158
14198
  );
14159
14199
  }
14200
+ this.lastPersistedHistoryMessages = normalizedMessagesToSave;
14160
14201
  }
14161
14202
  this.applyProviderResponse(parsedStatus, { phase: "immediate" });
14162
14203
  const surface = resolveProviderStateSurface({
@@ -14404,6 +14445,7 @@ var init_cli_provider_instance = __esm({
14404
14445
  }
14405
14446
  if (data.sessionEvent === "new_session") {
14406
14447
  this.runtimeMessages = [];
14448
+ this.lastPersistedHistoryMessages = [];
14407
14449
  this.suppressIdleHistoryReplay = false;
14408
14450
  this.adapter.clearHistory();
14409
14451
  }
@@ -86108,7 +86150,7 @@ var init_adhdev_daemon = __esm({
86108
86150
  init_source();
86109
86151
  init_version();
86110
86152
  init_src();
86111
- pkgVersion = resolvePackageVersion({ injectedVersion: "0.8.83" });
86153
+ pkgVersion = resolvePackageVersion({ injectedVersion: "0.8.84" });
86112
86154
  AdhdevDaemon = class _AdhdevDaemon {
86113
86155
  localHttpServer = null;
86114
86156
  localWss = null;