coder-agent 2.3.3 → 2.3.4
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/memory.js +46 -4
- package/package.json +1 -1
package/dist/memory.js
CHANGED
|
@@ -12,6 +12,7 @@ PRINCIPLES & SYSTEM PROTOCOLS FOR ERROR-FREE EXECUTION:
|
|
|
12
12
|
4. Auto-Verification Loop: After any code or file edit, you MUST run the appropriate compiler, type-check, build script, or test tool (e.g. npm run build, npx tsc, pytest, cargo build, etc.) to verify your changes are syntactically and logically correct. If compilation fails, diagnose the error and patch it immediately.
|
|
13
13
|
5. Autonomous Troubleshooting: If a command fails or times out, inspect the codebase or script to see why it hangs or fails. Do not blindly edit package scripts or configs.
|
|
14
14
|
6. Automated Diagnostic Parsing: When the user pastes IDE problem diagnostics (e.g., JSON blocks containing "resource", "message", "startLineNumber"), stack traces, or compiler errors, parse the diagnostic payload autonomously. Extract the file path and line number, locate the file inside the workspace (resolving drive formats like '/c:/...' to standard local paths, or searching for the filename if needed), read the target lines, and formulate a fix. Do not ask the user for clarifying questions (such as "where is this error?") if the path and error message are already present in the diagnostic block.
|
|
15
|
+
7. Resilience on Tool Failures: If a tool execution returns an error (such as "Target code not found in file" during patch_file, or any other tool failure), do NOT stop or give up. Autonomously analyze the error, adjust your arguments/parameters, or read the file to verify its exact content, and try again with a corrected tool call (or fall back to a full write_file if patching repeatedly fails) to achieve the user's goal.
|
|
15
16
|
|
|
16
17
|
Guidelines:
|
|
17
18
|
- Be concise in your explanations; let code and command output speak for itself.
|
|
@@ -218,6 +219,50 @@ ${topLevelStructure || "(empty)"}
|
|
|
218
219
|
\`\`\`
|
|
219
220
|
`;
|
|
220
221
|
}
|
|
222
|
+
function pruneMessages(messages, maxMessages) {
|
|
223
|
+
if (messages.length <= maxMessages + 1) {
|
|
224
|
+
return messages;
|
|
225
|
+
}
|
|
226
|
+
const systemPrompt = messages[0];
|
|
227
|
+
const history = messages.slice(1);
|
|
228
|
+
// Group history into turns, where each turn starts with role === "user"
|
|
229
|
+
const turns = [];
|
|
230
|
+
let currentTurn = [];
|
|
231
|
+
for (const msg of history) {
|
|
232
|
+
if (msg.role === "user") {
|
|
233
|
+
if (currentTurn.length > 0) {
|
|
234
|
+
turns.push(currentTurn);
|
|
235
|
+
}
|
|
236
|
+
currentTurn = [msg];
|
|
237
|
+
}
|
|
238
|
+
else {
|
|
239
|
+
currentTurn.push(msg);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
if (currentTurn.length > 0) {
|
|
243
|
+
turns.push(currentTurn);
|
|
244
|
+
}
|
|
245
|
+
// Keep turns from the end (most recent) until we hit the maxMessages limit
|
|
246
|
+
const keptTurns = [];
|
|
247
|
+
let currentCount = 0;
|
|
248
|
+
for (let i = turns.length - 1; i >= 0; i--) {
|
|
249
|
+
const turn = turns[i];
|
|
250
|
+
if (currentCount + turn.length <= maxMessages) {
|
|
251
|
+
keptTurns.unshift(turn);
|
|
252
|
+
currentCount += turn.length;
|
|
253
|
+
}
|
|
254
|
+
else {
|
|
255
|
+
// If we can't fit this turn, but we have kept nothing so far (e.g. a single giant turn),
|
|
256
|
+
// we must keep at least this turn to avoid sending an empty history.
|
|
257
|
+
if (keptTurns.length === 0) {
|
|
258
|
+
keptTurns.push(turn);
|
|
259
|
+
}
|
|
260
|
+
break;
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
const prunedHistory = keptTurns.flat();
|
|
264
|
+
return [systemPrompt, ...prunedHistory];
|
|
265
|
+
}
|
|
221
266
|
export class Memory {
|
|
222
267
|
messages = [];
|
|
223
268
|
maxMessages;
|
|
@@ -240,10 +285,7 @@ export class Memory {
|
|
|
240
285
|
}
|
|
241
286
|
add(msg) {
|
|
242
287
|
this.messages.push(msg);
|
|
243
|
-
|
|
244
|
-
if (this.messages.length > this.maxMessages + 1) {
|
|
245
|
-
this.messages = [this.messages[0], ...this.messages.slice(-(this.maxMessages))];
|
|
246
|
-
}
|
|
288
|
+
this.messages = pruneMessages(this.messages, this.maxMessages);
|
|
247
289
|
}
|
|
248
290
|
getAll() {
|
|
249
291
|
return this.messages;
|