From d68ea1ace6480879aa31f8786d2796e4714e5b85 Mon Sep 17 00:00:00 2001 From: aiofc-nx <0774543002@163.com> Date: Tue, 26 May 2026 21:42:19 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20auto-approve=20=E5=89=AF=E4=BD=9C?= =?UTF-8?q?=E7=94=A8=E4=BB=8E=20render()=20=E7=A7=BB=E5=88=B0=E7=A9=BA?= =?UTF-8?q?=E9=97=B2=20tick=20(refs=20#575)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - render() 保持纯函数,移除权限自动确认逻辑 - 新增 check_auto_approve() 方法,在 200ms 空闲 tick 调用 --- crates/uncode-tui/src/lib.rs | 39 +++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/crates/uncode-tui/src/lib.rs b/crates/uncode-tui/src/lib.rs index 082f2a0..6b83fa5 100644 --- a/crates/uncode-tui/src/lib.rs +++ b/crates/uncode-tui/src/lib.rs @@ -601,6 +601,25 @@ impl TuiEngine { } } + /// Auto-approve pending permission after 20s timeout (called from idle tick). + fn check_auto_approve(&mut self) { + if let Some(started) = self.permission_started_at { + if started.elapsed().as_secs() >= 20 { + if let Some(p) = self + .permission + .confirm(crate::permission::ConfirmOption::Allow) + { + self.resolve_permission(&p.tool_id, Approval::Allow); + } else { + self.permission_started_at = None; + } + } + if !self.permission.has_pending() { + self.permission_started_at = None; + } + } + } + /// End of a full agent `run` (not a single inner Turn). fn finish_agent_run(&mut self) { self.agent_busy = false; @@ -654,23 +673,6 @@ impl TuiEngine { if f.area().width == 0 || f.area().height == 0 { return; } - // Auto-approve pending permission after 20s timeout - if let Some(started) = self.permission_started_at { - if started.elapsed().as_secs() >= 20 { - if let Some(p) = self - .permission - .confirm(crate::permission::ConfirmOption::Allow) - { - self.resolve_permission(&p.tool_id, Approval::Allow); - } else { - self.permission_started_at = None; - } - } - // Defensive: clear timer if permission was externally resolved - if !self.permission.has_pending() { - self.permission_started_at = None; - } - } self.tick = self.tick.wrapping_add(1); use uncode_core::ui_action::WidgetPlacement; let above_lines = self.widget_manager.lines_for(WidgetPlacement::AboveEditor); @@ -1910,7 +1912,8 @@ impl TuiEngine { let _ = pending.response_tx.send(result); } _ = tokio::time::sleep(std::time::Duration::from_millis(200)) => { - // Idle tick: re-render for status animation + // Idle tick: check auto-approve + re-render for status animation + self.check_auto_approve(); } } if self.quit_requested {