From 4191aeaf50e8e255b07bdf2624d7fac17c12f695 Mon Sep 17 00:00:00 2001 From: Ted Robertson <10043369+tredondo@users.noreply.github.com> Date: Mon, 16 Nov 2026 19:20:21 +0000 Subject: [PATCH] agent_ui: Check only the clicked pattern in pipeline permission dropdown (#56492) Closes #55523 When the agent proposes a [chained command](https://github.com/zed-industries/zed/issues/55523) like `ls && git status && git log`, the permission dropdown lists an "Always for `X` commands" checkbox per sub-command. Clicking one checkbox activates pattern mode with *all* patterns pre-checked, so the user appeared to be approving every command in the pipeline even though they had only clicked one. Pressing Allow then allow-listed every sub-command. Fix: the first click activates pattern mode with only the clicked pattern checked. Additional patterns require explicit checks. **Note**: I've rebased onto `main` after #65039, which moved the dropdown's selection state into `Conversation`. The dropdown's click handler and the `ToggleCommandPattern` action handler now both call `Conversation::toggle_permission_pattern`, so the fix lives in one place. The duplicated fix and the one-click-behind workaround from the previous version of this PR are gone. **Self-Review Checklist** - [x] I've reviewed my own diff for quality, security, and reliability - [x] Unsafe blocks (if any) have justifying comments - [x] The content is consistent with the [UI/UX checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist) - [x] Tests cover the new/changed behavior - [x] Performance impact has been considered and is acceptable Release Notes: - Fixed the agent's permission dropdown for chained terminal commands checking every command when you clicked only one. --------- Co-authored-by: Smit Barmase --- crates/agent_ui/src/conversation_view.rs | 73 ++++++++++++++++--- .../src/conversation_view/thread_view.rs | 5 +- 2 files changed, 66 insertions(+), 12 deletions(-) diff --git a/crates/agent_ui/src/conversation_view.rs b/crates/agent_ui/src/conversation_view.rs index 8d5acd10a67..72529d5e159 100644 --- a/crates/agent_ui/src/conversation_view.rs +++ b/crates/agent_ui/src/conversation_view.rs @@ -400,26 +400,26 @@ impl Conversation { pattern_index: usize, cx: &mut Context, ) { - let Some(request) = self.permission_request(session_id, request_id, cx) else { + let Some(PermissionOptions::DropdownWithPatterns { patterns, .. }) = self + .permission_request(session_id, request_id, cx) + .and_then(PermissionRequest::legacy_options) + else { return; }; - let Some(options) = request.legacy_options() else { + if pattern_index >= patterns.len() { return; - }; - let pattern_count = match options { - PermissionOptions::DropdownWithPatterns { patterns, .. } => patterns.len(), - _ => 0, - }; + } match self.permission_selections.get_mut(&request_id) { Some(selection @ thread_view::PermissionSelection::SelectedPatterns(_)) => { selection.toggle_pattern(pattern_index); + if !selection.has_any_checked_patterns() { + self.permission_selections.remove(&request_id); + } } _ => { self.permission_selections.insert( request_id, - thread_view::PermissionSelection::SelectedPatterns( - (0..pattern_count).collect(), - ), + thread_view::PermissionSelection::SelectedPatterns(vec![pattern_index]), ); } } @@ -16959,6 +16959,53 @@ pub(crate) mod tests { }); } + #[gpui::test] + async fn test_toggle_command_pattern_toggles_only_clicked_pattern(cx: &mut TestAppContext) { + init_test(cx); + let (conversation_view, cx) = + setup_conversation_view(StubAgentServer::default_response(), cx).await; + let (thread, conversation) = active_thread(&conversation_view, cx) + .read_with(cx, |view, _| { + (view.thread.clone(), view.conversation.clone()) + }); + let session_id = thread.read_with(cx, |thread, _| thread.session_id().clone()); + // A chained command gets one pattern row per sub-command (`ls`, `git status`, `git log`). + let options = ToolPermissionContext::new( + TerminalTool::NAME, + vec!["ls && git status && git log".into()], + ) + .build_permission_options(); + let (request_id, _response) = + request_test_tool_authorization_with_options(&thread, "pipeline", options, cx); + + let toggle = |pattern_index, cx: &mut VisualTestContext| { + conversation.update(cx, |conversation, cx| { + conversation.toggle_permission_pattern(&session_id, request_id, pattern_index, cx); + match conversation.permission_selections.get(&request_id) { + Some(thread_view::PermissionSelection::SelectedPatterns(checked)) => { + let mut checked = checked.clone(); + checked.sort(); + Some(checked) + } + Some(thread_view::PermissionSelection::Choice(_)) => { + panic!("toggling a pattern must not select a dropdown choice") + } + None => None, + } + }) + }; + // An index with no matching row must not enter pattern mode. + assert_eq!(toggle(99, cx), None); + // The first click on a row other than the first checks only that row. + assert_eq!(toggle(1, cx), Some(vec![1])); + // Later clicks add only their own row... + assert_eq!(toggle(0, cx), Some(vec![0, 1])); + // ...and remove only their own row. + assert_eq!(toggle(1, cx), Some(vec![0])); + // Unchecking the last row goes back to the default selection. + assert_eq!(toggle(0, cx), None); + } + #[gpui::test] async fn test_allow_button_uses_selected_granularity(cx: &mut TestAppContext) { init_test(cx); @@ -17669,6 +17716,12 @@ pub(crate) mod tests { cx.run_until_parked(); if with_patterns { + let pattern = cx + .debug_bounds("MENU_ITEM-Always for `cargo test` commands") + .expect("the rendered persistent dropdown should offer the cargo pattern"); + cx.simulate_click(pattern.center(), gpui::Modifiers::default()); + cx.run_until_parked(); + // Toggling `sort` on and off must leave only `cargo test` checked. for _ in 0..2 { let pattern = cx .debug_bounds("MENU_ITEM-Always for `sort` commands") diff --git a/crates/agent_ui/src/conversation_view/thread_view.rs b/crates/agent_ui/src/conversation_view/thread_view.rs index 502cc6a1bdd..57bca0f2b51 100644 --- a/crates/agent_ui/src/conversation_view/thread_view.rs +++ b/crates/agent_ui/src/conversation_view/thread_view.rs @@ -691,7 +691,8 @@ pub(crate) enum PermissionSelection { Choice(usize), /// "Select options…" mode where individual command patterns can be toggled. /// Contains the indices of checked patterns in the `patterns` list. - /// All patterns start checked when this mode is first activated. + /// Only the pattern the user clicked is checked when this mode is first activated; + /// the user must explicitly check any additional patterns. SelectedPatterns(Vec), } @@ -712,7 +713,7 @@ impl PermissionSelection { } } - fn has_any_checked_patterns(&self) -> bool { + pub(super) fn has_any_checked_patterns(&self) -> bool { match self { Self::SelectedPatterns(checked) => !checked.is_empty(), _ => false,