@blockrun/runcode 2.3.1 → 2.3.2

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.
@@ -31,6 +31,10 @@ export declare function normalizeWhitespace(history: Dialogue[]): Dialogue[];
31
31
  * Recent messages: keep full. Old long messages: keep first 1000 chars.
32
32
  */
33
33
  export declare function trimOldAssistantMessages(history: Dialogue[]): Dialogue[];
34
+ /**
35
+ * Remove consecutive duplicate messages (same role + same content).
36
+ */
37
+ export declare function deduplicateMessages(history: Dialogue[]): Dialogue[];
34
38
  /**
35
39
  * Run all token reduction passes on conversation history.
36
40
  * Returns same reference if nothing changed (cheap identity check).
@@ -168,7 +168,27 @@ export function trimOldAssistantMessages(history) {
168
168
  });
169
169
  return modified ? result : history;
170
170
  }
171
- // ─── Pipeline ─────────────────────────────────────────────────────────────
171
+ // ─── 4. Deduplication ────────────���────────────────────────────────────────
172
+ /**
173
+ * Remove consecutive duplicate messages (same role + same content).
174
+ */
175
+ export function deduplicateMessages(history) {
176
+ if (history.length < 3)
177
+ return history;
178
+ const result = [history[0]];
179
+ let modified = false;
180
+ for (let i = 1; i < history.length; i++) {
181
+ const prev = history[i - 1];
182
+ const curr = history[i];
183
+ if (curr.role === prev.role && typeof curr.content === 'string' && curr.content === prev.content) {
184
+ modified = true;
185
+ continue;
186
+ }
187
+ result.push(curr);
188
+ }
189
+ return modified ? result : history;
190
+ }
191
+ // ─── Pipeline ───────���───────────────────���─────────────────────────────────
172
192
  /**
173
193
  * Run all token reduction passes on conversation history.
174
194
  * Returns same reference if nothing changed (cheap identity check).
@@ -200,6 +220,13 @@ export function reduceTokens(history, debug) {
200
220
  current = trimmed;
201
221
  totalSaved += before - estimateChars(current);
202
222
  }
223
+ // Pass 4: Remove consecutive duplicate messages
224
+ const deduped = deduplicateMessages(current);
225
+ if (deduped !== current) {
226
+ const before = estimateChars(current);
227
+ current = deduped;
228
+ totalSaved += before - estimateChars(current);
229
+ }
203
230
  if (debug && totalSaved > 500) {
204
231
  const tokensSaved = Math.round(totalSaved / 4);
205
232
  console.error(`[runcode] Token reduction: ~${tokensSaved} tokens saved`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blockrun/runcode",
3
- "version": "2.3.1",
3
+ "version": "2.3.2",
4
4
  "description": "RunCode — AI coding agent powered by 41+ models. Pay per use with USDC.",
5
5
  "type": "module",
6
6
  "bin": {