@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/package.json
CHANGED
|
@@ -48,6 +48,13 @@ function buildPersistableCliHistorySignature(message: PersistableCliHistoryMessa
|
|
|
48
48
|
].join('|');
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
+
function hasSamePersistableCliHistoryIdentity(a: PersistableCliHistoryMessage, b: PersistableCliHistoryMessage): boolean {
|
|
52
|
+
return String(a?.role || '') === String(b?.role || '')
|
|
53
|
+
&& String(a?.kind || '') === String(b?.kind || '')
|
|
54
|
+
&& String(a?.senderName || '') === String(b?.senderName || '')
|
|
55
|
+
&& String(a?.content || '') === String(b?.content || '');
|
|
56
|
+
}
|
|
57
|
+
|
|
51
58
|
export function buildIncrementalHistoryAppendMessages(
|
|
52
59
|
previousMessages: PersistableCliHistoryMessage[],
|
|
53
60
|
currentMessages: PersistableCliHistoryMessage[],
|
|
@@ -55,20 +62,32 @@ export function buildIncrementalHistoryAppendMessages(
|
|
|
55
62
|
if (!Array.isArray(currentMessages) || currentMessages.length === 0) return [];
|
|
56
63
|
if (!Array.isArray(previousMessages) || previousMessages.length === 0) return currentMessages;
|
|
57
64
|
|
|
58
|
-
const
|
|
59
|
-
const currentSignatures = currentMessages.map(buildPersistableCliHistorySignature);
|
|
60
|
-
|
|
65
|
+
const comparableLength = Math.min(previousMessages.length, currentMessages.length);
|
|
61
66
|
let sharedPrefixLength = 0;
|
|
62
67
|
while (
|
|
63
|
-
sharedPrefixLength <
|
|
64
|
-
&& sharedPrefixLength
|
|
65
|
-
&& previousSignatures[sharedPrefixLength] === currentSignatures[sharedPrefixLength]
|
|
68
|
+
sharedPrefixLength < comparableLength
|
|
69
|
+
&& hasSamePersistableCliHistoryIdentity(previousMessages[sharedPrefixLength], currentMessages[sharedPrefixLength])
|
|
66
70
|
) {
|
|
67
71
|
sharedPrefixLength += 1;
|
|
68
72
|
}
|
|
69
73
|
|
|
70
|
-
if (sharedPrefixLength ===
|
|
71
|
-
if (sharedPrefixLength ===
|
|
74
|
+
if (sharedPrefixLength === currentMessages.length) return [];
|
|
75
|
+
if (sharedPrefixLength === previousMessages.length) return currentMessages.slice(sharedPrefixLength);
|
|
76
|
+
|
|
77
|
+
// Rare fallback: preserve the older whitespace-normalized behavior only when
|
|
78
|
+
// the cheap identity check detects a changed prefix. Recomputing normalized
|
|
79
|
+
// signatures for the full transcript on every idle status poll was a CPU
|
|
80
|
+
// hot path for long CLI sessions.
|
|
81
|
+
while (
|
|
82
|
+
sharedPrefixLength < comparableLength
|
|
83
|
+
&& buildPersistableCliHistorySignature(previousMessages[sharedPrefixLength])
|
|
84
|
+
=== buildPersistableCliHistorySignature(currentMessages[sharedPrefixLength])
|
|
85
|
+
) {
|
|
86
|
+
sharedPrefixLength += 1;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (sharedPrefixLength === currentMessages.length) return [];
|
|
90
|
+
if (sharedPrefixLength === previousMessages.length) return currentMessages.slice(sharedPrefixLength);
|
|
72
91
|
return currentMessages;
|
|
73
92
|
}
|
|
74
93
|
|
|
@@ -418,13 +437,15 @@ export class CliProviderInstance implements ProviderInstance {
|
|
|
418
437
|
}));
|
|
419
438
|
if (!canonicalBackedHistory && !shouldSkipReplayPersist && normalizedMessagesToSave.length > 0) {
|
|
420
439
|
const incrementalMessages = buildIncrementalHistoryAppendMessages(this.lastPersistedHistoryMessages, normalizedMessagesToSave);
|
|
421
|
-
|
|
422
|
-
this.
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
440
|
+
if (incrementalMessages.length > 0) {
|
|
441
|
+
this.historyWriter.appendNewMessages(
|
|
442
|
+
this.type,
|
|
443
|
+
incrementalMessages,
|
|
444
|
+
parsedStatus?.title || dirName,
|
|
445
|
+
this.instanceId,
|
|
446
|
+
this.providerSessionId,
|
|
447
|
+
);
|
|
448
|
+
}
|
|
428
449
|
}
|
|
429
450
|
if (!canonicalBackedHistory) {
|
|
430
451
|
this.lastPersistedHistoryMessages = normalizedMessagesToSave;
|