coder-agent 2.9.9 → 2.9.10

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 CHANGED
@@ -277,7 +277,7 @@ function hasRepeatingCycle(history) {
277
277
  const n = history.length;
278
278
  for (let len = 1; len <= 4; len++) {
279
279
  if (n >= len * 2) {
280
- const minRepeats = len === 1 ? 3 : 2;
280
+ const minRepeats = 2;
281
281
  if (n >= len * minRepeats) {
282
282
  let isLoop = true;
283
283
  const lastBlock = history.slice(n - len);
@@ -927,12 +927,15 @@ export class Agent {
927
927
  console.log(chalk.hex('#ff453a')('\n✕ Loop intervention failed: Coder is stuck in an execution loop. Exiting to prompt.'));
928
928
  break;
929
929
  }
930
- const warningMessage = `⚠️ [LOOP DETECTED] You are repeating the exact same thoughts or tool calls. Please break out of this loop. Do not repeat the same actions. Re-evaluate your strategy, look at a different file, run a different command, or ask the user for clarification if you cannot proceed.`;
931
- console.log(chalk.hex('#ff9f0a')('\n⚠ Loop detected! Intervening to break the loop...'));
932
- this.memory.add({
933
- role: "user",
934
- content: warningMessage,
935
- });
930
+ const originalGoal = this.memory.getAll().find(m => m.role === "user")?.content || userMessage;
931
+ const warningMessage = `⚠️ [LOOP DETECTED & CONTEXT RESET] You got stuck in a repeating thinking/execution loop. To break the loop, all intermediate repetitive chat context has been discarded.
932
+
933
+ Here is your original goal:
934
+ "${originalGoal}"
935
+
936
+ Please start fresh. Re-evaluate your strategy, check other files, run different commands, or ask the user for clarification directly. Do NOT repeat the same failed tool calls.`;
937
+ console.log(chalk.hex('#ff9f0a')('\n⚠ Loop detected! Compressing memory and resetting context window...'));
938
+ this.memory.resetToInitialPrompt(warningMessage);
936
939
  stateHistory.length = 0; // Reset history to allow a fresh start
937
940
  }
938
941
  else {
package/dist/memory.js CHANGED
@@ -524,6 +524,25 @@ export class Memory {
524
524
  this.messages = [this.messages[0]]; // keep system prompt
525
525
  console.log(" Memory cleared.");
526
526
  }
527
+ resetToInitialPrompt(warningMessage) {
528
+ if (this.messages.length <= 1)
529
+ return;
530
+ const systemMsg = this.messages[0];
531
+ const firstUserMsg = this.messages.find(m => m.role === "user");
532
+ if (firstUserMsg) {
533
+ this.messages = [
534
+ systemMsg,
535
+ firstUserMsg,
536
+ { role: "user", content: warningMessage }
537
+ ];
538
+ }
539
+ else {
540
+ this.messages = [
541
+ systemMsg,
542
+ { role: "user", content: warningMessage }
543
+ ];
544
+ }
545
+ }
527
546
  summary() {
528
547
  const turns = this.messages.filter(m => m.role === "user").length;
529
548
  return `${turns} turn(s) in memory (${getMemoryScopeDisplay(this.scope)} scope)`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "coder-agent",
3
- "version": "2.9.9",
3
+ "version": "2.9.10",
4
4
  "description": "CLI coding agent powered by Google Gemini",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",