fix: 等你允許的卡片:計時跟著每一張卡,送出後的 Enter、按住的 Enter 都不算允許
- 第九輪審查(探測測試確認,main 就有):
- 送出訊息後馬上再按 Enter(或按住 Enter 的重複),會允許等你的步驟:輸入框有字時計時沒有
重來,按住的重複也被當成按了一下。現在輸入框有字、有檔案等著送、按住的重複,都算「擋住」,
計時重來;聊天框那條路也不收按住的重複。
- 0.6 秒跟著 Bot 不跟著卡片:舊卡在手機上回答、新卡馬上來,或切到別的聊天再切回來,
新卡的第一幀就能被 Enter 回答。現在記住的狀態要是「同一張卡(call_id)、緊接著的上一幀」,
不是就算擋住、計時重來。
已驗證: cargo test 整套連跑 5 次全綠(622);新測試 a_new_card_or_a_second_enter_is_not_a_yes
(拿掉修正時兩段都會失敗);既有的 enter_in_an_empty_box_approves_the_waiting_step 照常允許
(卡片先露出一下再按)。
未驗證: 實機按鍵手感(尤其 0.6 秒等待是否讓人覺得按了沒反應)。
動到審批路徑(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
a30443f105
commit
1b714f76fd
|
|
@ -4,7 +4,7 @@ Bot 要動到你的電腦、對外送出或做收不回來的事時,先問你
|
||||||
|
|
||||||
## 子功能
|
## 子功能
|
||||||
|
|
||||||
- 允許請求:黃色卡片停在輸入框上方,「允許 {Bot} {動作}嗎?」加細節框。按鈕:「允許」、「一律允許{類別}」(有能記住的類別才有)、「拒絕」。電腦工具沒開、或「在這台電腦上執行」沒開時,一律允許的按鈕就是「一律允許」,會打開什麼寫在滑過的說明裡。輸入框空著時 Enter 允許、Esc 拒絕——有任何對話框或選單開著(設定、Bot 設定、記憶、檔案或頁面、右鍵選單…)、或游標在別的輸入框時不算,那裡的 Enter/Esc 不會替你回答卡片(Esc 照樣關對話框和選單);這些都沒了之後要再等一下(約 0.6 秒)卡片才接按鍵。
|
- 允許請求:黃色卡片停在輸入框上方,「允許 {Bot} {動作}嗎?」加細節框。按鈕:「允許」、「一律允許{類別}」(有能記住的類別才有)、「拒絕」。電腦工具沒開、或「在這台電腦上執行」沒開時,一律允許的按鈕就是「一律允許」,會打開什麼寫在滑過的說明裡。輸入框空著時 Enter 允許、Esc 拒絕——有任何對話框或選單開著(設定、Bot 設定、記憶、檔案或頁面、右鍵選單…)、或游標在別的輸入框時不算,那裡的 Enter/Esc 不會替你回答卡片(Esc 照樣關對話框和選單);這些都沒了之後要再等一下(約 0.6 秒)卡片才接按鍵;換了一張新卡片、剛切回這個聊天、輸入框有字或有檔案等著送、按住不放的 Enter,也都要重新等。
|
||||||
- 允許卡片:一句「它想在你的電腦上執行:」+指令,三個按鈕「允許」「一律允許」(滑過說明它會打開什麼)「拒絕」;下面一行灰字「之後都直接操作,不再一個個問」:允許這一筆並打開直接操作(還沒開、管理員沒鎖時才有)。等你的卡片(允許、問題、交給你處理)都是同一種黃:淡黃底、細黃框。
|
- 允許卡片:一句「它想在你的電腦上執行:」+指令,三個按鈕「允許」「一律允許」(滑過說明它會打開什麼)「拒絕」;下面一行灰字「之後都直接操作,不再一個個問」:允許這一筆並打開直接操作(還沒開、管理員沒鎖時才有)。等你的卡片(允許、問題、交給你處理)都是同一種黃:淡黃底、細黃框。
|
||||||
- 一律允許記在那個 Bot 身上(例如「修改檔案」、「npm install」、某個連接器),Bot 設定 ›「電腦操作」的「已設定「一律允許」」看得到,按 × 移除。
|
- 一律允許記在那個 Bot 身上(例如「修改檔案」、「npm install」、某個連接器),Bot 設定 ›「電腦操作」的「已設定「一律允許」」看得到,按 × 移除。
|
||||||
- 拒絕後停下:同一輪裡 Bot 再提一模一樣的操作(同一個工具、同樣的參數),直接替你拒絕、不再問,直到你再傳一則訊息(工作中插話也算)。按停止、關視窗不算拒絕。
|
- 拒絕後停下:同一輪裡 Bot 再提一模一樣的操作(同一個工具、同樣的參數),直接替你拒絕、不再問,直到你再傳一則訊息(工作中插話也算)。按停止、關視窗不算拒絕。
|
||||||
|
|
|
||||||
84
src/app.rs
84
src/app.rs
|
|
@ -3987,13 +3987,22 @@ impl App {
|
||||||
// A menu too: one closed by this very Esc is already marked closed (egui doesn't use the key
|
// 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,
|
// up), so whether one was open as the frame began counts as well — that Esc closed a menu,
|
||||||
// it didn't say no.
|
// it didn't say no.
|
||||||
|
// What was kept is this card's, from the frame just before (not another bot's card, not
|
||||||
|
// from before the person came back to this chat): otherwise it counts as blocked.
|
||||||
let composer = egui::Id::unique(("composer", bot.id));
|
let composer = egui::Id::unique(("composer", bot.id));
|
||||||
let seen = egui::Id::unique("approval-dock-caret");
|
let seen = egui::Id::unique("approval-dock-caret");
|
||||||
let (caret_before, menu_before): (Option<egui::Id>, bool) = ctx.data(|d| d.get_temp(seen)).unwrap_or((None, false));
|
let card = self.approvals.get(&bot.id).map(|a| a.call_id.clone()).unwrap_or_default();
|
||||||
|
let pass = ctx.cumulative_pass_nr();
|
||||||
|
let kept: Option<(Option<egui::Id>, bool, u64, String)> = ctx.data(|d| d.get_temp(seen));
|
||||||
|
let fresh = kept.as_ref().is_some_and(|k| k.2 + 1 == pass && k.3 == card);
|
||||||
|
let (caret_before, menu_before) = kept.map(|k| (k.0, k.1)).unwrap_or((None, false));
|
||||||
let elsewhere = caret_before.or_else(|| ctx.memory(|m| m.focused())).is_some_and(|f| f != composer);
|
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();
|
let dialog_open = self.show_settings || ctx.memory(|m| m.top_modal_layer()).is_some();
|
||||||
let menu_now = 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;
|
// A key held down (its repeats), words in the box (Enter sends them; a second Enter right
|
||||||
|
// after was the yes), files waiting to go: none of them is a yes or a no either.
|
||||||
|
let repeated = ui.input(|i| i.events.iter().any(|e| matches!(e, egui::Event::Key { key: Key::Enter | Key::Escape, pressed: true, repeat: true, .. })));
|
||||||
|
let blocked = !fresh || typing || elsewhere || dialog_open || menu_now || menu_before || repeated || !draft_empty || self.has_pending_attachments(bot.id);
|
||||||
// While anything else has the keys, the wait starts over: a card that comes into view
|
// 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.
|
// (a dialog closed, a field let go) takes keys only after it has been there a moment.
|
||||||
if blocked {
|
if blocked {
|
||||||
|
|
@ -4008,7 +4017,7 @@ impl App {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// (Read, then kept: one lock at a time — a ctx call inside another freezes the window.)
|
// (Read, then kept: one lock at a time — a ctx call inside another freezes the window.)
|
||||||
let now = (ctx.memory(|m| m.focused()), egui::Popup::is_any_open(ctx));
|
let now = (ctx.memory(|m| m.focused()), egui::Popup::is_any_open(ctx), pass, card);
|
||||||
ctx.data_mut(|d| d.insert_temp(seen, now));
|
ctx.data_mut(|d| d.insert_temp(seen, now));
|
||||||
if let Some(ans) = answer {
|
if let Some(ans) = answer {
|
||||||
self.ask_shown.remove(&bot.id);
|
self.ask_shown.remove(&bot.id);
|
||||||
|
|
@ -4472,9 +4481,11 @@ impl App {
|
||||||
let approval_waits = self.approvals.get(&bot.id).is_some_and(|a| !matches!(a.kind, ApprovalKind::Question | ApprovalKind::Handoff)) && draft.trim().is_empty() && !self.has_pending_attachments(bot.id);
|
let approval_waits = self.approvals.get(&bot.id).is_some_and(|a| !matches!(a.kind, ApprovalKind::Question | ApprovalKind::Handoff)) && draft.trim().is_empty() && !self.has_pending_attachments(bot.id);
|
||||||
let mut enter_for_approval = false;
|
let mut enter_for_approval = false;
|
||||||
if had_focus && !composing {
|
if had_focus && !composing {
|
||||||
|
let held = ui.input(|i| i.events.iter().any(|e| matches!(e, egui::Event::Key { key: Key::Enter, pressed: true, repeat: true, .. })));
|
||||||
let (enter, shift_enter) = ui.input_mut(chat_ui::take_enter);
|
let (enter, shift_enter) = ui.input_mut(chat_ui::take_enter);
|
||||||
if approval_waits {
|
if approval_waits {
|
||||||
enter_for_approval = enter;
|
// (A held Enter's repeats are not a yes.)
|
||||||
|
enter_for_approval = enter && !held;
|
||||||
} else {
|
} else {
|
||||||
send_now |= enter;
|
send_now |= enter;
|
||||||
}
|
}
|
||||||
|
|
@ -7943,6 +7954,69 @@ mod tests {
|
||||||
assert!(got.try_recv().is_err(), "keys in another dialog don't answer the card");
|
assert!(got.try_recv().is_err(), "keys in another dialog don't answer the card");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The card's keys are the card's, once it has been seen: a second Enter right after sending
|
||||||
|
/// words isn't a yes, nor is an Enter on the first frame of a new card (the last one answered
|
||||||
|
/// on the phone, the next one already there).
|
||||||
|
#[test]
|
||||||
|
fn a_new_card_or_a_second_enter_is_not_a_yes() {
|
||||||
|
let enter = egui::Event::Key { key: Key::Enter, physical_key: None, pressed: true, repeat: false, modifiers: egui::Modifiers::NONE };
|
||||||
|
let setup = |name: &str| {
|
||||||
|
let ctx = egui::Context::default();
|
||||||
|
let app = super::App::new(&ctx, Some(std::env::temp_dir().join(name)));
|
||||||
|
(ctx, app)
|
||||||
|
};
|
||||||
|
let card = |app: &mut super::App, id: u64, call: &str| {
|
||||||
|
let (reply, got) = std::sync::mpsc::channel();
|
||||||
|
app.approvals.insert(id, Approval { call_id: call.into(), tool: "shell".into(), reason: "執行:rm -rf build".into(), grant: String::new(), reply, kind: ApprovalKind::Action });
|
||||||
|
got
|
||||||
|
};
|
||||||
|
// Words typed in the box with the card up a while: Enter sends them to the running turn;
|
||||||
|
// the next Enter isn't the yes.
|
||||||
|
let (ctx, mut app) = setup("anybot-second-enter.png");
|
||||||
|
let id = app.state.bots[0].id;
|
||||||
|
let bot = app.state.bot(id).unwrap().clone();
|
||||||
|
let composer = egui::Id::unique(("composer", id));
|
||||||
|
let frame = |app: &mut super::App, events: Vec<egui::Event>, focus: bool| {
|
||||||
|
let mut out = ctx.run_ui(egui::RawInput { events, ..Default::default() }, |ui| {
|
||||||
|
if focus {
|
||||||
|
ui.memory_mut(|m| m.request_focus(composer));
|
||||||
|
}
|
||||||
|
app.composer(ui, &ctx, &bot);
|
||||||
|
});
|
||||||
|
out.textures_delta.clear();
|
||||||
|
};
|
||||||
|
let got = card(&mut app, id, "c1");
|
||||||
|
let steer = Arc::new(Mutex::new(vec![]));
|
||||||
|
app.streams.insert(id, Live { cancel: Arc::new(AtomicBool::new(false)), started: Instant::now(), last: Instant::now(), produced: true, status: None, paused: false, paused_at: None, unattended: false, steer: steer.clone(), direct: Arc::new(AtomicBool::new(false)), turn_id: "t".into(), turn: 0 });
|
||||||
|
app.drafts.insert(id, "不要刪".into());
|
||||||
|
frame(&mut app, vec![], true);
|
||||||
|
frame(&mut app, vec![], false);
|
||||||
|
app.ask_shown.insert(id, Instant::now() - std::time::Duration::from_secs(2));
|
||||||
|
frame(&mut app, vec![enter.clone()], false);
|
||||||
|
assert_eq!(steer.lock().unwrap().len(), 1, "the words went");
|
||||||
|
// The same Enter held a moment (its repeat), and a quick second one: neither is the yes.
|
||||||
|
frame(&mut app, vec![egui::Event::Key { key: Key::Enter, physical_key: None, pressed: true, repeat: true, modifiers: egui::Modifiers::NONE }], false);
|
||||||
|
frame(&mut app, vec![enter.clone()], false);
|
||||||
|
let r = got.try_recv();
|
||||||
|
assert!(!matches!(r, Ok(ApprovalAnswer::Once)) && app.approvals.contains_key(&id), "the Enter right after sending isn't a yes");
|
||||||
|
// A new card in the old one's place (the old one answered on the phone): its first frame
|
||||||
|
// doesn't take an Enter, however long the bot has been asking.
|
||||||
|
let (ctx2, mut app2) = setup("anybot-new-card.png");
|
||||||
|
let id2 = app2.state.bots[0].id;
|
||||||
|
let bot2 = app2.state.bot(id2).unwrap().clone();
|
||||||
|
let frame2 = |app: &mut super::App, events: Vec<egui::Event>| {
|
||||||
|
let mut out = ctx2.run_ui(egui::RawInput { events, ..Default::default() }, |ui| app.composer(ui, &ctx2, &bot2));
|
||||||
|
out.textures_delta.clear();
|
||||||
|
};
|
||||||
|
let _old = card(&mut app2, id2, "c1");
|
||||||
|
frame2(&mut app2, vec![]);
|
||||||
|
frame2(&mut app2, vec![]);
|
||||||
|
app2.ask_shown.insert(id2, Instant::now() - std::time::Duration::from_secs(2));
|
||||||
|
let got2 = card(&mut app2, id2, "c2");
|
||||||
|
frame2(&mut app2, vec![enter]);
|
||||||
|
assert!(got2.try_recv().is_err(), "a card seen for no time isn't answered");
|
||||||
|
}
|
||||||
|
|
||||||
/// Esc that closes a menu closes the menu: it isn't a no to the step waiting in the chat.
|
/// 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.
|
/// And a card that comes into view (a field let go) takes keys only after a moment.
|
||||||
#[test]
|
#[test]
|
||||||
|
|
@ -8003,6 +8077,8 @@ mod tests {
|
||||||
out.textures_delta.clear();
|
out.textures_delta.clear();
|
||||||
};
|
};
|
||||||
frame(&mut app, vec![], true);
|
frame(&mut app, vec![], true);
|
||||||
|
frame(&mut app, vec![], false);
|
||||||
|
app.ask_shown.insert(id, Instant::now() - std::time::Duration::from_secs(2));
|
||||||
frame(&mut app, vec![enter.clone()], false);
|
frame(&mut app, vec![enter.clone()], false);
|
||||||
assert!(matches!(got.try_recv(), Ok(ApprovalAnswer::Once)), "Enter said yes");
|
assert!(matches!(got.try_recv(), Ok(ApprovalAnswer::Once)), "Enter said yes");
|
||||||
// With words in the box, Enter sends them (to the running turn) and the step keeps waiting.
|
// With words in the box, Enter sends them (to the running turn) and the step keeps waiting.
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue