fix: 用 Esc 關選單不會順便拒絕等你允許的卡片;被擋住時重新計時
- 第八輪審查(探測測試確認,main 就有):選單開著時按 Esc,egui 關掉選單但不把按鍵用掉、 選單又已經標成關了,聊天裡等你允許的卡片就把這個 Esc 當成「拒絕」,Bot 那一輪就停了。 現在記住上一幀有沒有選單開著(和游標在哪一起記),這一幀和上一幀都沒有選單才接按鍵。 - 只要有東西擋著(選單、對話框、游標在別的欄位、輸入法組字中),卡片的 0.6 秒就重新算: 擋在對話框後面才出現的卡片,或在搜尋框連按兩次 Enter,不會一露出來就被回答。 已驗證: cargo test 整套連跑 5 次全綠(621);新測試 esc_closing_a_menu_does_not_turn_down_the_waiting_step (拿掉「上一幀有選單」時會失敗);enter_in_an_empty_box_approves_the_waiting_step 照常允許。 未驗證: 實機按鍵手感。 動到審批路徑(approval_dock):依 CLAUDE.md 需要實機測試+人類簽名,不得自行發佈。 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Uirha3KhvSzysuKUobKUTR
This commit is contained in:
parent
e48e1eb214
commit
a30443f105
|
|
@ -4,7 +4,7 @@ Bot 要動到你的電腦、對外送出或做收不回來的事時,先問你
|
|||
|
||||
## 子功能
|
||||
|
||||
- 允許請求:黃色卡片停在輸入框上方,「允許 {Bot} {動作}嗎?」加細節框。按鈕:「允許」、「一律允許{類別}」(有能記住的類別才有)、「拒絕」。電腦工具沒開、或「在這台電腦上執行」沒開時,一律允許的按鈕就是「一律允許」,會打開什麼寫在滑過的說明裡。輸入框空著時 Enter 允許、Esc 拒絕——有任何對話框開著(設定、Bot 設定、記憶、檔案或頁面…)、或游標在別的輸入框時不算,那裡的 Enter/Esc 不會替你回答卡片(Esc 照樣關對話框)。
|
||||
- 允許請求:黃色卡片停在輸入框上方,「允許 {Bot} {動作}嗎?」加細節框。按鈕:「允許」、「一律允許{類別}」(有能記住的類別才有)、「拒絕」。電腦工具沒開、或「在這台電腦上執行」沒開時,一律允許的按鈕就是「一律允許」,會打開什麼寫在滑過的說明裡。輸入框空著時 Enter 允許、Esc 拒絕——有任何對話框或選單開著(設定、Bot 設定、記憶、檔案或頁面、右鍵選單…)、或游標在別的輸入框時不算,那裡的 Enter/Esc 不會替你回答卡片(Esc 照樣關對話框和選單);這些都沒了之後要再等一下(約 0.6 秒)卡片才接按鍵。
|
||||
- 允許卡片:一句「它想在你的電腦上執行:」+指令,三個按鈕「允許」「一律允許」(滑過說明它會打開什麼)「拒絕」;下面一行灰字「之後都直接操作,不再一個個問」:允許這一筆並打開直接操作(還沒開、管理員沒鎖時才有)。等你的卡片(允許、問題、交給你處理)都是同一種黃:淡黃底、細黃框。
|
||||
- 一律允許記在那個 Bot 身上(例如「修改檔案」、「npm install」、某個連接器),Bot 設定 ›「電腦操作」的「已設定「一律允許」」看得到,按 × 移除。
|
||||
- 拒絕後停下:同一輪裡 Bot 再提一模一樣的操作(同一個工具、同樣的參數),直接替你拒絕、不再問,直到你再傳一則訊息(工作中插話也算)。按停止、關視窗不算拒絕。
|
||||
|
|
|
|||
54
src/app.rs
54
src/app.rs
|
|
@ -3984,12 +3984,22 @@ impl App {
|
|||
// with the caret in another field (a connector's name, a search).
|
||||
// (Where the caret was as this frame began: a field that takes the Enter first lets go
|
||||
// of the caret before this card looks, so the last frame's is what counts.)
|
||||
// A menu too: one closed by this very Esc is already marked closed (egui doesn't use the key
|
||||
// up), so whether one was open as the frame began counts as well — that Esc closed a menu,
|
||||
// it didn't say no.
|
||||
let composer = egui::Id::unique(("composer", bot.id));
|
||||
let seen = egui::Id::unique("approval-dock-caret");
|
||||
let before: Option<egui::Id> = ctx.data(|d| d.get_temp(seen)).flatten();
|
||||
let elsewhere = before.or_else(|| ctx.memory(|m| m.focused())).is_some_and(|f| f != composer);
|
||||
let (caret_before, menu_before): (Option<egui::Id>, bool) = ctx.data(|d| d.get_temp(seen)).unwrap_or((None, false));
|
||||
let elsewhere = caret_before.or_else(|| ctx.memory(|m| m.focused())).is_some_and(|f| f != composer);
|
||||
let dialog_open = self.show_settings || ctx.memory(|m| m.top_modal_layer()).is_some();
|
||||
if answer.is_none() && draft_empty && !typing && !elsewhere && !dialog_open && shown > 0.6 && !egui::Popup::is_any_open(ctx) {
|
||||
let menu_now = egui::Popup::is_any_open(ctx);
|
||||
let blocked = typing || elsewhere || dialog_open || menu_now || menu_before;
|
||||
// While anything else has the keys, the wait starts over: a card that comes into view
|
||||
// (a dialog closed, a field let go) takes keys only after it has been there a moment.
|
||||
if blocked {
|
||||
self.ask_shown.insert(bot.id, Instant::now());
|
||||
}
|
||||
if answer.is_none() && draft_empty && !blocked && shown > 0.6 {
|
||||
let (pressed, _) = ui.input_mut(chat_ui::take_enter);
|
||||
if enter || pressed {
|
||||
answer = Some(ApprovalAnswer::Once);
|
||||
|
|
@ -3998,7 +4008,7 @@ impl App {
|
|||
}
|
||||
}
|
||||
// (Read, then kept: one lock at a time — a ctx call inside another freezes the window.)
|
||||
let now = ctx.memory(|m| m.focused());
|
||||
let now = (ctx.memory(|m| m.focused()), egui::Popup::is_any_open(ctx));
|
||||
ctx.data_mut(|d| d.insert_temp(seen, now));
|
||||
if let Some(ans) = answer {
|
||||
self.ask_shown.remove(&bot.id);
|
||||
|
|
@ -7933,6 +7943,42 @@ mod tests {
|
|||
assert!(got.try_recv().is_err(), "keys in another dialog don't answer the card");
|
||||
}
|
||||
|
||||
/// Esc that closes a menu closes the menu: it isn't a no to the step waiting in the chat.
|
||||
/// And a card that comes into view (a field let go) takes keys only after a moment.
|
||||
#[test]
|
||||
fn esc_closing_a_menu_does_not_turn_down_the_waiting_step() {
|
||||
let ctx = egui::Context::default();
|
||||
let mut app = super::App::new(&ctx, Some(std::env::temp_dir().join("anybot-esc-menu.png")));
|
||||
let id = app.state.bots[0].id;
|
||||
let (reply, got) = std::sync::mpsc::channel();
|
||||
app.approvals.insert(id, Approval { call_id: "c1".into(), tool: "shell".into(), reason: "執行:ls".into(), grant: String::new(), reply, kind: ApprovalKind::Action });
|
||||
app.ask_shown.insert(id, Instant::now() - std::time::Duration::from_secs(2));
|
||||
let bot = app.state.bot(id).unwrap().clone();
|
||||
let esc = egui::Event::Key { key: Key::Escape, physical_key: None, pressed: true, repeat: false, modifiers: egui::Modifiers::NONE };
|
||||
let menu = egui::Id::unique("a-menu");
|
||||
// A menu drawn before the chat's input, open; then Esc (which closes it first).
|
||||
let frame = |app: &mut super::App, events: Vec<egui::Event>, open: bool| {
|
||||
let mut out = ctx.run_ui(egui::RawInput { events, ..Default::default() }, |ui| {
|
||||
let r = ui.button("⋯");
|
||||
if open {
|
||||
egui::Popup::open_id(ui.ctx(), menu);
|
||||
}
|
||||
egui::Popup::menu(&r).id(menu).show(|ui| ui.label("釘選"));
|
||||
app.composer(ui, &ctx, &bot);
|
||||
});
|
||||
out.textures_delta.clear();
|
||||
};
|
||||
frame(&mut app, vec![], true);
|
||||
frame(&mut app, vec![], false);
|
||||
// (Even with the card up long enough by the clock: the menu's own Esc is the menu's.)
|
||||
app.ask_shown.insert(id, Instant::now() - std::time::Duration::from_secs(2));
|
||||
frame(&mut app, vec![esc.clone()], false);
|
||||
assert!(got.try_recv().is_err(), "the Esc closed the menu, it didn't say no");
|
||||
// Right after (the menu just gone): still a moment before the card takes keys.
|
||||
frame(&mut app, vec![esc], false);
|
||||
assert!(got.try_recv().is_err(), "not at once after the menu");
|
||||
}
|
||||
|
||||
/// Enter in an empty box with a step waiting for a yes is the yes. (The box took the Enter
|
||||
/// first, sent nothing — it was empty — and the waiting step never heard it.)
|
||||
#[test]
|
||||
|
|
|
|||
Loading…
Reference in New Issue