coder-agent 2.5.0 → 2.5.1
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/agent.js +7 -1
- package/dist/memory.js +12 -3
- package/package.json +1 -1
package/dist/agent.js
CHANGED
|
@@ -531,9 +531,15 @@ export class Agent {
|
|
|
531
531
|
else {
|
|
532
532
|
statusLines.push(`${chalk.hex('#30d158')('✓')} ${chalk.gray(getToolSuccessSummary(name, args, result))}`);
|
|
533
533
|
}
|
|
534
|
+
// Truncate result if it is extremely large to prevent context/token overflow
|
|
535
|
+
const MAX_TOOL_OUTPUT = 60000;
|
|
536
|
+
let toolResult = result;
|
|
537
|
+
if (toolResult.length > MAX_TOOL_OUTPUT) {
|
|
538
|
+
toolResult = toolResult.slice(0, MAX_TOOL_OUTPUT) + `\n\n... [Tool output truncated: total length was ${toolResult.length} characters] ...`;
|
|
539
|
+
}
|
|
534
540
|
this.memory.add({
|
|
535
541
|
role: "tool",
|
|
536
|
-
content:
|
|
542
|
+
content: toolResult,
|
|
537
543
|
tool_call_id: toolCall.id,
|
|
538
544
|
name,
|
|
539
545
|
});
|
package/dist/memory.js
CHANGED
|
@@ -220,10 +220,11 @@ ${topLevelStructure || "(empty)"}
|
|
|
220
220
|
`;
|
|
221
221
|
}
|
|
222
222
|
function pruneMessages(messages, maxMessages) {
|
|
223
|
-
if (messages.length <=
|
|
223
|
+
if (messages.length <= 1) {
|
|
224
224
|
return messages;
|
|
225
225
|
}
|
|
226
226
|
const systemPrompt = messages[0];
|
|
227
|
+
const systemPromptLen = systemPrompt.content?.length || 0;
|
|
227
228
|
const history = messages.slice(1);
|
|
228
229
|
// Group history into turns, where each turn starts with role === "user"
|
|
229
230
|
const turns = [];
|
|
@@ -242,14 +243,22 @@ function pruneMessages(messages, maxMessages) {
|
|
|
242
243
|
if (currentTurn.length > 0) {
|
|
243
244
|
turns.push(currentTurn);
|
|
244
245
|
}
|
|
245
|
-
// Keep turns from the end (most recent) until we hit the maxMessages limit
|
|
246
|
+
// Keep turns from the end (most recent) until we hit the maxMessages limit or character limit
|
|
246
247
|
const keptTurns = [];
|
|
247
248
|
let currentCount = 0;
|
|
249
|
+
let currentChars = systemPromptLen;
|
|
250
|
+
const MAX_CHARS = 500000; // ~125k tokens (very safe limit for 256k context models)
|
|
248
251
|
for (let i = turns.length - 1; i >= 0; i--) {
|
|
249
252
|
const turn = turns[i];
|
|
250
|
-
|
|
253
|
+
const turnChars = turn.reduce((sum, msg) => {
|
|
254
|
+
const contentLen = msg.content?.length || 0;
|
|
255
|
+
const toolCallsLen = msg.tool_calls ? JSON.stringify(msg.tool_calls).length : 0;
|
|
256
|
+
return sum + contentLen + toolCallsLen;
|
|
257
|
+
}, 0);
|
|
258
|
+
if ((currentCount + turn.length <= maxMessages) && (currentChars + turnChars <= MAX_CHARS)) {
|
|
251
259
|
keptTurns.unshift(turn);
|
|
252
260
|
currentCount += turn.length;
|
|
261
|
+
currentChars += turnChars;
|
|
253
262
|
}
|
|
254
263
|
else {
|
|
255
264
|
// If we can't fit this turn, but we have kept nothing so far (e.g. a single giant turn),
|