@noobdemon/noob-cli 1.10.3 → 1.10.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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/agent.js +17 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@noobdemon/noob-cli",
3
- "version": "1.10.3",
3
+ "version": "1.10.4",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
package/src/agent.js CHANGED
@@ -496,6 +496,7 @@ export async function runAgent({ history, model, signal, onTool, onStatus, onDel
496
496
  // chạy không giới hạn token. Dừng theo: GOAL đạt, <<LOOP_DONE>>, <<ULTRA_DONE>>,
497
497
  // model tự kết thúc reply không có tool block, hoặc user Ctrl+C.
498
498
  const recentCalls = []; // {name, inputStr} — theo dõi vòng lặp
499
+ let idleRecoveries = 0; // đếm số lần idle recovery —max 5 để tránh infinite loop
499
500
  // Effort classifier: phân loại task từ user message gốc → set effort level.
500
501
  // Chỉ classify 1 lần ở bước đầu, giữ nguyên suốt task (thay đổi giữa chừng gây bất ổn).
501
502
  const effort = classifyEffort(history.find((m) => m.role === "user")?.content || "");
@@ -555,6 +556,22 @@ export async function runAgent({ history, model, signal, onTool, onStatus, onDel
555
556
  });
556
557
  continue;
557
558
  }
559
+ // ── Idle recovery: model dừng nhưng còn task chưa xong ────────────
560
+ // Nếu pendingTasks còn items → KHÔNG return, inject nudge rồi continue loop.
561
+ // Giới hạn 5 lần recovery để tránh infinite loop.
562
+ {
563
+ const tasks = pendingTasks || [];
564
+ const remaining = tasks.length;
565
+ if (remaining > 0 && idleRecoveries < 5) {
566
+ idleRecoveries++;
567
+ const next = tasks[0];
568
+ history.push({
569
+ role: "user",
570
+ content: `[SYSTEM] Bạn vừa dừng giữa chừng. Còn ${remaining} việc chưa hoàn thành: ${tasks.map((t) => `"${t}"`).join(", ")}. Việc tiếp theo BẮT BUỘC phải làm ngay: "${next}". Gọi tool (write_file/edit_file/run_command) để làm việc này. KHÔNG dừng, KHÔNG tóm tắt, KHÔNG đợi user.`,
571
+ });
572
+ continue;
573
+ }
574
+ }
558
575
  return text; // final answer
559
576
  }
560
577