blun-king-cli 9.1.204 → 9.1.205
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.
|
@@ -8,6 +8,7 @@ const REPEATED_RESPONSE_PLACEHOLDER = '[Historical repeated assistant response o
|
|
|
8
8
|
const INTRA_MESSAGE_MIN_REPEATS = 3;
|
|
9
9
|
const INTRA_MESSAGE_MIN_BLOCK_CHARS = 40;
|
|
10
10
|
const INTRA_MESSAGE_MIN_SAVED_CHARS = 1_000;
|
|
11
|
+
const INTRA_MESSAGE_SIMILARITY_THRESHOLD = 0.88;
|
|
11
12
|
const INTRA_MESSAGE_REPEAT_PLACEHOLDER = '[Exact repeated assistant paragraphs omitted from model projection; raw history preserved.]';
|
|
12
13
|
|
|
13
14
|
function isUserPrompt(message) {
|
|
@@ -60,6 +61,17 @@ function responseSimilarity(left, right) {
|
|
|
60
61
|
return (2 * intersection) / (leftBigrams.size + rightBigrams.size);
|
|
61
62
|
}
|
|
62
63
|
|
|
64
|
+
function fencedBlockIndexes(blocks) {
|
|
65
|
+
const protectedIndexes = new Set();
|
|
66
|
+
let insideFence = false;
|
|
67
|
+
for (let index = 0; index < blocks.length; index += 1) {
|
|
68
|
+
const fenceCount = blocks[index].match(/(?:^|\n)\s*(?:```|~~~)/gu)?.length ?? 0;
|
|
69
|
+
if (insideFence || fenceCount > 0) protectedIndexes.add(index);
|
|
70
|
+
if (fenceCount % 2 === 1) insideFence = !insideFence;
|
|
71
|
+
}
|
|
72
|
+
return protectedIndexes;
|
|
73
|
+
}
|
|
74
|
+
|
|
63
75
|
function hasUserPromptBetween(history, leftIndex, rightIndex) {
|
|
64
76
|
for (let index = leftIndex + 1; index < rightIndex; index += 1) {
|
|
65
77
|
if (isUserPrompt(history[index])) return true;
|
|
@@ -120,27 +132,31 @@ function compactRepeatedAssistantParagraphs(message) {
|
|
|
120
132
|
)) return null;
|
|
121
133
|
|
|
122
134
|
const text = textParts[0].text;
|
|
123
|
-
if (/```|~~~/u.test(text)) return null;
|
|
124
135
|
const blocks = text.split(/\n\s*\n/u).map((block) => block.trim()).filter(Boolean);
|
|
125
136
|
if (blocks.length < INTRA_MESSAGE_MIN_REPEATS + 1) return null;
|
|
137
|
+
const protectedIndexes = fencedBlockIndexes(blocks);
|
|
138
|
+
|
|
139
|
+
const clusters = [];
|
|
140
|
+
for (let index = 0; index < blocks.length; index += 1) {
|
|
141
|
+
const block = blocks[index];
|
|
142
|
+
if (protectedIndexes.has(index) || block.length < INTRA_MESSAGE_MIN_BLOCK_CHARS) continue;
|
|
143
|
+
const cluster = clusters.find((candidate) => (
|
|
144
|
+
candidate.representative === block
|
|
145
|
+
|| responseSimilarity(candidate.representative, block) >= INTRA_MESSAGE_SIMILARITY_THRESHOLD
|
|
146
|
+
));
|
|
147
|
+
if (cluster) cluster.indexes.push(index);
|
|
148
|
+
else clusters.push({ indexes: [index], representative: block });
|
|
149
|
+
}
|
|
150
|
+
const repeatedIndexes = new Set(clusters
|
|
151
|
+
.filter((cluster) => cluster.indexes.length >= INTRA_MESSAGE_MIN_REPEATS)
|
|
152
|
+
.flatMap((cluster) => cluster.indexes.slice(1)));
|
|
153
|
+
if (repeatedIndexes.size === 0) return null;
|
|
126
154
|
|
|
127
|
-
const counts = new Map();
|
|
128
|
-
for (const block of blocks) counts.set(block, (counts.get(block) ?? 0) + 1);
|
|
129
|
-
const repeated = new Set([...counts]
|
|
130
|
-
.filter(([block, count]) => (
|
|
131
|
-
block.length >= INTRA_MESSAGE_MIN_BLOCK_CHARS
|
|
132
|
-
&& count >= INTRA_MESSAGE_MIN_REPEATS
|
|
133
|
-
))
|
|
134
|
-
.map(([block]) => block));
|
|
135
|
-
if (repeated.size === 0) return null;
|
|
136
|
-
|
|
137
|
-
const seen = new Set();
|
|
138
155
|
const projectedBlocks = [];
|
|
139
156
|
let markerAdded = false;
|
|
140
|
-
for (
|
|
141
|
-
if (!
|
|
142
|
-
projectedBlocks.push(
|
|
143
|
-
if (repeated.has(block)) seen.add(block);
|
|
157
|
+
for (let index = 0; index < blocks.length; index += 1) {
|
|
158
|
+
if (!repeatedIndexes.has(index)) {
|
|
159
|
+
projectedBlocks.push(blocks[index]);
|
|
144
160
|
continue;
|
|
145
161
|
}
|
|
146
162
|
if (!markerAdded) {
|
|
@@ -184,6 +200,7 @@ module.exports = {
|
|
|
184
200
|
INTRA_MESSAGE_MIN_BLOCK_CHARS,
|
|
185
201
|
INTRA_MESSAGE_MIN_REPEATS,
|
|
186
202
|
INTRA_MESSAGE_MIN_SAVED_CHARS,
|
|
203
|
+
INTRA_MESSAGE_SIMILARITY_THRESHOLD,
|
|
187
204
|
INTRA_MESSAGE_REPEAT_PLACEHOLDER,
|
|
188
205
|
MAX_RECENT_ASSISTANT_RESPONSES,
|
|
189
206
|
MIN_RESPONSE_CHARS,
|