Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
agent_ui: Replace thread controls with slash commands (#59974)
Danilo Leal550ddc940594
diff --git a/assets/icons/folder_share.svg b/assets/icons/folder_share.svgindex 36db1414b8c..898af2397c7 100644--- a/assets/icons/folder_share.svg+++ b/assets/icons/folder_share.svg@@ -1,5 +1,5 @@<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M6 13H4C2.89543 13 2 12.1046 2 11V5C2 3.89543 2.89543 3 4 3H6.17157C6.70201 3 7.21071 3.21071 7.58579 3.58579L8.41421 4.41421C8.78929 4.78929 9.29799 5 9.82843 5H12C13.1046 5 14 5.89543 14 7V7.5" stroke="#DCE0E5" stroke-width="1.2" stroke-linecap="round"/>-<path d="M11.2045 14.4761V9.7034" stroke="#DCE0E5" stroke-width="1.65153" stroke-linecap="round" stroke-linejoin="round"/>-<path d="M13.5926 11.5119L11.2046 9.12396L8.81659 11.5119" stroke="#DCE0E5" stroke-width="1.65153" stroke-linecap="round" stroke-linejoin="round"/>+<path d="M11.2045 14.4761V9.7034" stroke="#DCE0E5" stroke-width="1.2" stroke-linecap="round" stroke-linejoin="round"/>+<path d="M13.5926 11.5119L11.2046 9.12396L8.81659 11.5119" stroke="#DCE0E5" stroke-width="1.2" stroke-linecap="round" stroke-linejoin="round"/></svg>diff --git a/assets/icons/folder_shared.svg b/assets/icons/folder_shared.svgindex 785b3aa56d7..897bef603a1 100644--- a/assets/icons/folder_shared.svg+++ b/assets/icons/folder_shared.svg@@ -1,6 +1,6 @@<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M6 13H4C2.89543 13 2 12.1046 2 11V5C2 3.89543 2.89543 3 4 3H6.17157C6.70201 3 7.21071 3.21071 7.58579 3.58579L8.41421 4.41421C8.78929 4.78929 9.29799 5 9.82843 5H12C13.1046 5 14 5.89543 14 7V7.5" stroke="#DCE0E5" stroke-width="1.2" stroke-linecap="round"/><path opacity="0.2" d="M4 13H6H12C13.1046 13 14 12.1046 14 11V7.5V7C14 5.89543 13.1046 5 12 5H9.82843C9.29799 5 8.78929 4.78929 8.41421 4.41421L7.58579 3.58579C7.21071 3.21071 6.70201 3 6.17157 3H4C2.89543 3 2 3.89543 2 5V11C2 12.1046 2.89543 13 4 13Z" fill="#DCE0E5" stroke="#DCE0E5" stroke-width="1.2"/>-<path d="M11.2045 14.4761V9.7034" stroke="#DCE0E5" stroke-width="1.65153" stroke-linecap="round" stroke-linejoin="round"/>-<path d="M13.5926 11.5119L11.2046 9.12396L8.81659 11.5119" stroke="#DCE0E5" stroke-width="1.65153" stroke-linecap="round" stroke-linejoin="round"/>+<path d="M11.2045 14.4761V9.7034" stroke="#DCE0E5" stroke-width="1.2" stroke-linecap="round" stroke-linejoin="round"/>+<path d="M13.5926 11.5119L11.2046 9.12396L8.81659 11.5119" stroke="#DCE0E5" stroke-width="1.2" stroke-linecap="round" stroke-linejoin="round"/></svg>diff --git a/assets/icons/user_arrow_up.svg b/assets/icons/user_arrow_up.svgnew file mode 100644index 00000000000..8320108fa79--- /dev/null+++ b/assets/icons/user_arrow_up.svg@@ -0,0 +1,6 @@+<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">+<path d="M12.0295 14.8008V10.0281" stroke="#DCE0E5" stroke-width="1.2" stroke-linecap="round" stroke-linejoin="round"/>+<path d="M14.4177 11.8366L12.0297 9.44867L9.64166 11.8366" stroke="#DCE0E5" stroke-width="1.2" stroke-linecap="round" stroke-linejoin="round"/>+<path d="M1.66669 12.3688C1.66667 11.445 1.93321 10.5408 2.43433 9.76481C2.93545 8.98877 3.64985 8.37383 4.49181 7.99376C5.33376 7.61369 6.26751 7.48465 7.18099 7.62211C8.09447 7.75958 8.94888 8.15772 9.64169 8.76875" stroke="#DCE0E5" stroke-width="1.2" stroke-linecap="round" stroke-linejoin="round"/>+<path d="M7.61473 7.34036C7.25075 7.49113 6.86064 7.56873 6.46668 7.56873C5.67103 7.56873 4.90796 7.25266 4.34535 6.69005C3.78275 6.12744 3.46667 5.36438 3.46667 4.56873C3.46667 3.77308 3.78275 3.01001 4.34535 2.44741C4.90796 1.8848 5.67103 1.56873 6.46668 1.56873C6.86064 1.56873 7.25075 1.64632 7.61473 1.79709C7.9787 1.94785 8.30942 2.16883 8.58799 2.44741C8.86657 2.72598 9.08755 3.0567 9.23831 3.42068C9.38908 3.78465 9.46667 4.17476 9.46667 4.56873C9.46667 4.96269 9.38908 5.3528 9.23831 5.71678C9.08755 6.08075 8.86657 6.41147 8.58799 6.69005C8.30942 6.96862 7.9787 7.1896 7.61473 7.34036Z" stroke="#DCE0E5" stroke-width="1.2" stroke-linecap="round" stroke-linejoin="round"/>+</svg>diff --git a/crates/agent_ui/src/agent_panel.rs b/crates/agent_ui/src/agent_panel.rsindex 88d8a5fd86d..f22037c239a 100644--- a/crates/agent_ui/src/agent_panel.rs+++ b/crates/agent_ui/src/agent_panel.rs@@ -5499,6 +5499,10 @@ impl AgentPanel {.is_some_and(|thread| !thread.read(cx).is_generating_title())});+ let has_thread_messages = conversation_view.as_ref().is_some_and(|conversation_view| {+ conversation_view.read(cx).has_user_submitted_prompt(cx)+ });+let has_auth_methods = match &self.base_view {BaseView::AgentThread { conversation_view } => {conversation_view.read(cx).has_auth_methods()@@ -5534,15 +5538,15 @@ impl AgentPanel {.with_handle(self.agent_panel_menu_handle.clone()).menu({move |window, cx| {- Some(ContextMenu::build(window, cx, |mut menu, _window, _| {+ Some(ContextMenu::build(window, cx, |mut menu, _window, cx| {menu = menu.context(menu_action_context.clone());- if can_regenerate_thread_title {+ if has_thread_messages {menu = menu.header("Current Thread");if let Some(conversation_view) = conversation_view.as_ref() {- menu = menu- .entry("Regenerate Thread Title", None, {+ if can_regenerate_thread_title {+ menu = menu.entry("Regenerate Thread Title", None, {let conversation_view = conversation_view.clone();let workspace = workspace.clone();move |_, cx| {@@ -5552,8 +5556,29 @@ impl AgentPanel {cx,);}- })- .separator();+ });+ }++ let root_thread_view =+ conversation_view.read(cx).root_thread_view();+ if let Some(thread_view) = root_thread_view {+ let workspace = workspace.clone();+ menu = menu.entry("Open Thread as Markdown", None, {+ move |window, cx| {+ if let Some(workspace) = workspace.upgrade() {+ thread_view.update(cx, |thread_view, cx| {+ thread_view+ .open_thread_as_markdown(+ workspace, window, cx,+ )+ .detach_and_log_err(cx);+ });+ }+ }+ });+ }++ menu = menu.separator();}}@@ -5631,11 +5656,29 @@ impl AgentPanel {},);}-- menu = menu.separator();}- menu = menu.action("Profiles", Box::new(ManageProfiles::default()));+ menu = menu+ .separator()+ .header("MCP Servers")+ .action(+ "Add Server…",+ Box::new(zed_actions::OpenSettingsAt {+ path: "context_servers".to_string(),+ target: None,+ }),+ )+ .action(+ "Install New Servers…",+ Box::new(zed_actions::Extensions {+ category_filter: Some(+ zed_actions::ExtensionCategoryFilter::ContextServers,+ ),+ id: None,+ }),+ )+ .separator()+ .action("Profiles", Box::new(ManageProfiles::default()));}menu = menudiff --git a/crates/agent_ui/src/completion_provider.rs b/crates/agent_ui/src/completion_provider.rsindex d25eae39064..ccc95c2fc4e 100644--- a/crates/agent_ui/src/completion_provider.rs+++ b/crates/agent_ui/src/completion_provider.rs@@ -190,6 +190,51 @@ impl PromptContextAction {}}+/// A slash command that runs a local UI action against the conversation+/// (sending feedback) instead of being sent to the agent as part of a prompt.+/// Each variant maps to a method on `ThreadView`; the completion provider only+/// surfaces them and emits an event, while `ThreadView` performs the actual+/// work (see `handle_message_editor_event`).+#[derive(Debug, Clone, Copy, PartialEq, Eq)]+pub enum PromptLocalCommand {+ ThumbsUp,+ ThumbsDown,+}++impl PromptLocalCommand {+ pub fn keyword(&self) -> &'static str {+ match self {+ Self::ThumbsUp => "helpful",+ Self::ThumbsDown => "not-helpful",+ }+ }++ pub fn label(&self) -> &'static str {+ match self {+ Self::ThumbsUp => "Positive Feedback",+ Self::ThumbsDown => "Negative Feedback",+ }+ }++ pub fn description(&self) -> &'static str {+ match self {+ Self::ThumbsUp => {+ "Rate this response as helpful. Sends the current conversation to the Zed team."+ }+ Self::ThumbsDown => {+ "Rate this response as not helpful. Sends the current conversation to the Zed team."+ }+ }+ }++ pub fn icon(&self) -> IconName {+ match self {+ Self::ThumbsUp => IconName::ThumbsUp,+ Self::ThumbsDown => IconName::ThumbsDown,+ }+ }+}+impl TryFrom<&str> for PromptContextType {type Error = String;@@ -366,13 +411,15 @@ impl AvailableCommand {enum SlashCompletionCandidate {Skill(AvailableSkill),Command(AvailableCommand),+ LocalCommand(PromptLocalCommand),}impl SlashCompletionCandidate {- fn name(&self) -> &Arc<str> {+ fn name(&self) -> &str {match self {Self::Skill(skill) => &skill.name,Self::Command(command) => &command.name,+ Self::LocalCommand(command) => command.keyword(),}}}@@ -385,6 +432,7 @@ fn slash_completion_group_key(candidate: &SlashCompletionCandidate) -> u32 {match candidate {SlashCompletionCandidate::Skill(_) => 0,SlashCompletionCandidate::Command(command) => 1 + command.category_order() as u32,+ SlashCompletionCandidate::LocalCommand(_) => 4,}}@@ -411,6 +459,13 @@ pub trait PromptCompletionProviderDelegate: Send + Sync + 'static {fn available_skills(&self, _cx: &App) -> Vec<AvailableSkill> {Vec::new()}++ fn available_local_commands(&self, _cx: &App) -> Vec<PromptLocalCommand> {+ Vec::new()+ }++ fn run_local_command(&self, _command: PromptLocalCommand, _cx: &mut App) {}+fn confirm_command(&self, cx: &mut App);/// Called once each time the user opens slash-command autocomplete@@ -959,15 +1014,21 @@ impl<T: PromptCompletionProviderDelegate> PromptCompletionProvider<T> {let mut candidates = self.source- .available_skills(cx)+ .available_commands(cx).into_iter()- .map(SlashCompletionCandidate::Skill)+ .map(SlashCompletionCandidate::Command).collect::<Vec<_>>();candidates.extend(self.source- .available_commands(cx)+ .available_skills(cx).into_iter()- .map(SlashCompletionCandidate::Command),+ .map(SlashCompletionCandidate::Skill),+ );+ candidates.extend(+ self.source+ .available_local_commands(cx)+ .into_iter()+ .map(SlashCompletionCandidate::LocalCommand),);if candidates.is_empty() {return Task::ready(Vec::new());@@ -1429,7 +1490,10 @@ impl<T: PromptCompletionProviderDelegate> CompletionProvider for PromptCompletioSome((new_text, icon_path, icon_color, confirm)),)}- SlashCompletionCandidate::Command(_) => (candidate, None),+ SlashCompletionCandidate::Command(_)+ | SlashCompletionCandidate::LocalCommand(_) => {+ (candidate, None)+ }}).collect::<Vec<(SlashCompletionCandidate, Option<SkillInfo>)>>()})@@ -1542,6 +1606,50 @@ impl<T: PromptCompletionProviderDelegate> CompletionProvider for PromptCompletiogroup,}}+ SlashCompletionCandidate::LocalCommand(command) => {+ let group = show_section_headers.then(|| CompletionGroup {+ key: "local-commands".into(),+ label: Some("Actions".into()),+ });++ Completion {+ replace_range: source_range.clone(),+ // Local commands aren't part of the prompt;+ // confirming one clears the typed text+ // rather than leaving `/keyword` behind.+ new_text: String::new(),+ label: CodeLabel::plain(command.label().to_string(), None),+ documentation: Some(+ CompletionDocumentation::MultiLinePlainText(+ command.description().into(),+ ),+ ),+ source: project::CompletionSource::Custom,+ icon_path: Some(command.icon().path().into()),+ icon_color: None,+ match_start: None,+ snippet_deduplication_key: None,+ insert_text_mode: None,+ confirm: Some(Arc::new({+ let source = source.clone();+ move |intent, _window, cx| {+ cx.defer({+ let source = source.clone();+ move |cx| match intent {+ CompletionIntent::Complete+ | CompletionIntent::CompleteWithInsert+ | CompletionIntent::CompleteWithReplace => {+ source.run_local_command(command, cx);+ }+ CompletionIntent::Compose => {}+ }+ });+ false+ }+ })),+ group,+ }+ }}).collect();diff --git a/crates/agent_ui/src/conversation_view/thread_view.rs b/crates/agent_ui/src/conversation_view/thread_view.rsindex fc0f5b96a58..858fc5e840e 100644--- a/crates/agent_ui/src/conversation_view/thread_view.rs+++ b/crates/agent_ui/src/conversation_view/thread_view.rs@@ -23,7 +23,7 @@ use editor::actions::OpenExcerpts;use feature_flags::{AcpBetaFeatureFlag, FeatureFlagAppExt as _};use sandbox::{SandboxFsPolicy, SandboxNetPolicy, SandboxPolicy};-use crate::completion_provider::AvailableSkill;+use crate::completion_provider::{AvailableSkill, PromptLocalCommand};use crate::message_editor::SharedSessionCapabilities;use crate::ui::{SandboxGroup, SandboxRow, SandboxSection, SandboxStatusTooltip};@@ -36,6 +36,7 @@ use language_model::{FastModeConfirmation, LanguageModel, LanguageModelEffortLevel, LanguageModelId,LanguageModelProvider, LanguageModelProviderId, LanguageModelRegistry, Speed,};+use notifications::status_toast::StatusToast;use settings::{update_settings_file, update_settings_file_with_completion};use ui::{ButtonLike, CalloutBorderPosition, SpinnerLabel, SpinnerVariant, SplitButton, SplitButtonStyle,@@ -1109,11 +1110,48 @@ impl ThreadView {}MessageEditorEvent::LostFocus => {}MessageEditorEvent::SlashAutocompleteOpened => {}+ MessageEditorEvent::LocalCommandInvoked(command) => {+ self.run_local_command(*command, window, cx);+ }MessageEditorEvent::InputAttempted { .. } => {}MessageEditorEvent::Edited => {}}}+ fn run_local_command(+ &mut self,+ command: PromptLocalCommand,+ window: &mut Window,+ cx: &mut Context<Self>,+ ) {+ match command {+ PromptLocalCommand::ThumbsUp => {+ self.handle_feedback_click(ThreadFeedback::Positive, window, cx);+ self.show_local_command_toast("Thanks for your feedback!", cx);+ }+ PromptLocalCommand::ThumbsDown => {+ self.handle_feedback_click(ThreadFeedback::Negative, window, cx);+ }+ }+ }++ fn show_local_command_toast(&self, message: impl Into<SharedString>, cx: &mut Context<Self>) {+ // Shown after positive feedback, replacing the inline button state.+ let Some(workspace) = self.workspace.upgrade() else {+ return;+ };+ workspace.update(cx, |workspace, cx| {+ let toast = StatusToast::new(message, cx, |this, _cx| {+ this.icon(+ Icon::new(IconName::Check)+ .size(IconSize::Small)+ .color(Color::Success),+ )+ });+ workspace.toggle_status_toast(toast, cx);+ });+ }+pub(crate) fn as_native_connection(&self,cx: &App,@@ -1250,6 +1288,7 @@ impl ThreadView {}ViewEvent::MessageEditorEvent(_editor, MessageEditorEvent::SlashAutocompleteOpened) => {}+ ViewEvent::MessageEditorEvent(_editor, MessageEditorEvent::LocalCommandInvoked(_)) => {}ViewEvent::MessageEditorEvent(_editor, MessageEditorEvent::Edited) => {}ViewEvent::MessageEditorEvent(_editor, MessageEditorEvent::InputAttempted { .. }) => {}ViewEvent::OpenDiffLocation {@@ -6580,42 +6619,50 @@ impl ThreadView {cx: &Context<Self>,) -> impl IntoElement {let is_generating = matches!(thread.read(cx).status(), ThreadStatus::Generating);+if is_generating {return Empty.into_any_element();}- let open_as_markdown = IconButton::new("open-as-markdown", IconName::FileMarkdown)- .shape(ui::IconButtonShape::Square)- .icon_size(IconSize::Small)- .icon_color(Color::Ignored)- .tooltip(Tooltip::text("Open Thread as Markdown"))- .on_click(cx.listener(move |this, _, window, cx| {- if let Some(workspace) = this.workspace.upgrade() {- this.open_thread_as_markdown(workspace, window, cx)- .detach_and_log_err(cx);- }- }));+ let last_response_index = thread+ .read(cx)+ .entries()+ .iter()+ .rposition(|entry| matches!(entry, AgentThreadEntry::AssistantMessage(_)));++ let copy_response_button = last_response_index.map(|response_index| {+ IconButton::new("copy_agent_response", IconName::Copy)+ .icon_size(IconSize::Small)+ .icon_color(Color::Muted)+ .tooltip(Tooltip::text("Copy This Agent Response"))+ .on_click(cx.listener(move |this, _, _, cx| {+ let entries = this.thread.read(cx).entries();+ if let Some(text) = Self::get_agent_message_content(entries, response_index, cx)+ {+ cx.write_to_clipboard(ClipboardItem::new_string(text));+ }+ }))+ });let scroll_to_recent_user_prompt =- IconButton::new("scroll_to_recent_user_prompt", IconName::ForwardArrow)- .shape(ui::IconButtonShape::Square)+ IconButton::new("scroll_to_recent_user_prompt", IconName::UserArrowUp).icon_size(IconSize::Small)- .icon_color(Color::Ignored)- .tooltip(Tooltip::text("Scroll To Most Recent User Prompt"))+ .icon_color(Color::Muted)+ .tooltip(Tooltip::text("Scroll to Most Recent User Message")).on_click(cx.listener(move |this, _, _, cx| {this.scroll_to_most_recent_user_prompt(cx);}));let scroll_to_top = IconButton::new("scroll_to_top", IconName::ArrowUp)- .shape(ui::IconButtonShape::Square).icon_size(IconSize::Small)- .icon_color(Color::Ignored)- .tooltip(Tooltip::text("Scroll To Top"))+ .icon_color(Color::Muted)+ .tooltip(Tooltip::text("Scroll to Top")).on_click(cx.listener(move |this, _, _, cx| {this.scroll_to_top(cx);}));let show_stats = AgentSettings::get_global(cx).show_turn_stats;+let last_turn_clock = show_stats.then(|| {self.turn_fields@@ -6643,65 +6690,30 @@ impl ThreadView {}).flatten();- let mut container = h_flex()- .w_full()- .py_2()- .px_5()- .gap_px()- .opacity(0.6)- .hover(|s| s.opacity(1.))- .justify_end()- .when(- last_turn_tokens_label.is_some() || last_turn_clock.is_some(),- |this| {- this.child(- h_flex()- .gap_1()- .px_1()- .when_some(last_turn_tokens_label, |this, label| this.child(label))- .when_some(last_turn_clock, |this, label| this.child(label)),- )- },- );-- let enable_thread_feedback = util::maybe!({- let project = thread.read(cx).project().read(cx);- let user_store = project.user_store();- if let Some(configuration) = user_store.read(cx).current_organization_configuration() {- if !configuration.is_agent_thread_feedback_enabled {- return false;- }- }-- AgentSettings::get_global(cx).enable_feedback- && self.thread.read(cx).connection().telemetry().is_some()- });-- if enable_thread_feedback {- let feedback = self.thread_feedback.feedback;-- let tooltip_meta = || {- SharedString::new(- "Rating the thread sends all of your current conversation to the Zed team.",- )- };+ let feedback_buttons = (self.is_subagent() && self.is_thread_feedback_enabled(cx)).then(+ || {+ let feedback = self.thread_feedback.feedback;+ let tooltip_meta =+ "Rating the thread sends all of your current conversation to the Zed team.";- container = container+ h_flex().child(IconButton::new("feedback-thumbs-up", IconName::ThumbsUp)- .shape(ui::IconButtonShape::Square).icon_size(IconSize::Small).icon_color(match feedback {Some(ThreadFeedback::Positive) => Color::Accent,- _ => Color::Ignored,+ _ => Color::Muted,}).tooltip(move |window, cx| match feedback {Some(ThreadFeedback::Positive) => {Tooltip::text("Thanks for your feedback!")(window, cx)}- _ => {- Tooltip::with_meta("Helpful Response", None, tooltip_meta(), cx)- }+ _ => Tooltip::with_meta(+ "Helpful Response",+ None,+ tooltip_meta,+ cx,+ ),}).on_click(cx.listener(move |this, _, window, cx| {this.handle_feedback_click(ThreadFeedback::Positive, window, cx);@@ -6709,40 +6721,100 @@ impl ThreadView {).child(IconButton::new("feedback-thumbs-down", IconName::ThumbsDown)- .shape(ui::IconButtonShape::Square).icon_size(IconSize::Small).icon_color(match feedback {Some(ThreadFeedback::Negative) => Color::Accent,- _ => Color::Ignored,+ _ => Color::Muted,}).tooltip(move |window, cx| match feedback {- Some(ThreadFeedback::Negative) => {- Tooltip::text(+ Some(ThreadFeedback::Negative) => Tooltip::text("We appreciate your feedback and will use it to improve in the future.",- )(window, cx)- }- _ => {- Tooltip::with_meta(- "Not Helpful Response",- None,- tooltip_meta(),- cx,- )- }+ )(+ window, cx+ ),+ _ => Tooltip::with_meta(+ "Not Helpful Response",+ None,+ tooltip_meta,+ cx,+ ),}).on_click(cx.listener(move |this, _, window, cx| {this.handle_feedback_click(ThreadFeedback::Negative, window, cx);})),- );- }+ )+ },+ );- container- .child(open_as_markdown)+ h_flex()+ .w_full()+ .py_1p5()+ .px_4()+ .justify_end()+ .opacity(0.4)+ .hover(|s| s.opacity(1.))+ .when(+ last_turn_tokens_label.is_some() || last_turn_clock.is_some(),+ |this| {+ this.child(+ h_flex()+ .px_1()+ .gap_1()+ .when_some(last_turn_tokens_label, |this, label| {+ this.child(label).child(+ Label::new("•")+ .size(LabelSize::Small)+ .color(Color::Muted)+ .alpha(0.5),+ )+ })+ .when_some(last_turn_clock, |this, label| this.child(label)),+ )+ },+ )+ .when_some(feedback_buttons, |this, buttons| this.child(buttons))+ .when_some(copy_response_button, |this, button| this.child(button)).child(scroll_to_recent_user_prompt).child(scroll_to_top).into_any_element()}+ fn is_thread_feedback_enabled(&self, cx: &App) -> bool {+ util::maybe!({+ let project = self.thread.read(cx).project().read(cx);+ let user_store = project.user_store();+ if let Some(configuration) = user_store.read(cx).current_organization_configuration() {+ if !configuration.is_agent_thread_feedback_enabled {+ return false;+ }+ }++ AgentSettings::get_global(cx).enable_feedback+ && self.thread.read(cx).connection().telemetry().is_some()+ })+ }++ // The local slash commands the message editor should currently expose.+ // Kept in sync with the availability of the corresponding actions via+ // `sync_local_commands`.+ fn available_local_commands(&self, cx: &App) -> Vec<PromptLocalCommand> {+ let mut commands = Vec::new();++ if self.is_thread_feedback_enabled(cx) {+ commands.push(PromptLocalCommand::ThumbsUp);+ commands.push(PromptLocalCommand::ThumbsDown);+ }++ commands+ }++ // Pushes the current set of available local commands to the message+ // editor so they appear in its slash-command popup.+ pub(crate) fn sync_local_commands(&self, cx: &App) {+ let commands = self.available_local_commands(cx);+ self.message_editor.read(cx).set_local_commands(commands);+ }+fn render_request_elicitations(&self, cx: &Context<Self>) -> Vec<AnyElement> {let server_view = self.server_view.clone();let handlers_view = server_view.clone();@@ -11523,6 +11595,11 @@ impl ThreadView {impl Render for ThreadView {fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {+ // Keep the message editor's local slash commands in sync with the+ // current availability of feedback/sharing, which can change between+ // renders (settings, connection state, feature flags).+ self.sync_local_commands(cx);+let has_messages = self.list_state.item_count() > 0;let list_state = self.list_state.clone();diff --git a/crates/agent_ui/src/message_editor.rs b/crates/agent_ui/src/message_editor.rsindex f262e44f506..f9878d6c5ad 100644--- a/crates/agent_ui/src/message_editor.rs+++ b/crates/agent_ui/src/message_editor.rs@@ -5,7 +5,7 @@ use crate::{completion_provider::{AgentContextSelection, AvailableCommand, AvailableSkill, PromptCompletionProvider,PromptCompletionProviderDelegate, PromptContextAction, PromptContextType,- SlashCommandCompletion,+ PromptLocalCommand, SlashCommandCompletion,},mention_set::{Mention, MentionImage, MentionSet, insert_crease_for_mention},};@@ -140,10 +140,13 @@ impl SessionCapabilities {pub type SharedSessionCapabilities = Arc<RwLock<SessionCapabilities>>;+pub type SharedLocalCommands = Arc<RwLock<Vec<PromptLocalCommand>>>;+struct MessageEditorCompletionDelegate {session_capabilities: SharedSessionCapabilities,has_thread_store: bool,message_editor: WeakEntity<MessageEditor>,+ local_commands: SharedLocalCommands,}impl PromptCompletionProviderDelegate for MessageEditorCompletionDelegate {@@ -165,6 +168,18 @@ impl PromptCompletionProviderDelegate for MessageEditorCompletionDelegate {self.session_capabilities.read().completion_skills()}+ fn available_local_commands(&self, _cx: &App) -> Vec<PromptLocalCommand> {+ self.local_commands.read().clone()+ }++ fn run_local_command(&self, command: PromptLocalCommand, cx: &mut App) {+ self.message_editor+ .update(cx, |_this, cx| {+ cx.emit(MessageEditorEvent::LocalCommandInvoked(command));+ })+ .ok();+ }+fn slash_autocomplete_invoked(&self, cx: &mut App) {// This may be called synchronously from inside a `MessageEditor`// update (e.g. when pasting a slash command triggers completions),@@ -189,6 +204,7 @@ pub struct MessageEditor {editor: Entity<Editor>,workspace: WeakEntity<Workspace>,session_capabilities: SharedSessionCapabilities,+ local_commands: SharedLocalCommands,agent_id: AgentId,thread_store: Option<Entity<ThreadStore>>,_subscriptions: Vec<Subscription>,@@ -213,6 +229,11 @@ pub enum MessageEditorEvent {/// editor. Used by `ThreadView` to fire the global-skills scan/// trigger; see `NativeAgent::ensure_skills_scan_started`.SlashAutocompleteOpened,+ /// Emitted when the user confirms a local slash command (scrolling,+ /// exporting, feedback) in this editor's completion popup. `ThreadView`+ /// handles it by running the corresponding action; see+ /// `handle_message_editor_event`.+ LocalCommandInvoked(PromptLocalCommand),InputAttempted {attempt: InputAttempt,cursor_offset: usize,@@ -484,11 +505,13 @@ impl MessageEditor {editor});let mention_set = cx.new(|_cx| MentionSet::new(project, thread_store.clone()));+ let local_commands: SharedLocalCommands = Arc::new(RwLock::new(Vec::new()));let completion_provider = Rc::new(PromptCompletionProvider::new(MessageEditorCompletionDelegate {session_capabilities: session_capabilities.clone(),has_thread_store: thread_store.is_some(),message_editor: cx.weak_entity(),+ local_commands: local_commands.clone(),},editor.downgrade(),mention_set.clone(),@@ -583,6 +606,7 @@ impl MessageEditor {mention_set,workspace,session_capabilities,+ local_commands,agent_id,thread_store,_subscriptions: subscriptions,@@ -590,6 +614,10 @@ impl MessageEditor {}}+ pub fn set_local_commands(&self, commands: Vec<PromptLocalCommand>) {+ *self.local_commands.write() = commands;+ }+pub fn set_session_capabilities(&mut self,session_capabilities: SharedSessionCapabilities,@@ -2211,8 +2239,9 @@ fn find_matching_bracket(text: &str, open: char, close: char) -> Option<usize> {#[cfg(test)]mod tests {- use std::{ops::Range, path::Path, path::PathBuf, sync::Arc};+ use std::{ops::Range, path::Path, path::PathBuf, rc::Rc, sync::Arc};+ use super::PromptLocalCommand;use acp_thread::MentionUri;use agent::{ThreadStore, outline};use agent_client_protocol::schema::v1 as acp;@@ -2909,6 +2938,118 @@ mod tests {});}+ /// Local commands set via `set_local_commands` must surface in the+ /// slash-command popup, and confirming one must emit+ /// `MessageEditorEvent::LocalCommandInvoked` (so `ThreadView` can run the+ /// corresponding action) without leaving the `/keyword` in the editor.+ #[gpui::test]+ async fn test_local_commands_complete_and_emit_event(cx: &mut TestAppContext) {+ init_test(cx);++ let app_state = cx.update(AppState::test);++ cx.update(|cx| {+ editor::init(cx);+ workspace::init(app_state.clone(), cx);+ });++ let project = Project::test(app_state.fs.clone(), [path!("/dir").as_ref()], cx).await;+ let window =+ cx.add_window(|window, cx| MultiWorkspace::test_new(project.clone(), window, cx));+ let workspace = window+ .read_with(cx, |mw, _| mw.workspace().clone())+ .unwrap();++ let mut cx = VisualTestContext::from_window(window.into(), cx);++ let session_capabilities = Arc::new(RwLock::new(SessionCapabilities::from_acp_commands(+ acp::PromptCapabilities::default(),+ Vec::new(),+ )));++ let (message_editor, editor) = workspace.update_in(&mut cx, |workspace, window, cx| {+ let workspace_handle = cx.weak_entity();+ let message_editor = cx.new(|cx| {+ MessageEditor::new(+ workspace_handle,+ project.downgrade(),+ None,+ session_capabilities.clone(),+ "Test Agent".into(),+ "Test",+ EditorMode::AutoHeight {+ max_lines: None,+ min_lines: 1,+ },+ window,+ cx,+ )+ });+ workspace.active_pane().update(cx, |pane, cx| {+ pane.add_item(+ Box::new(cx.new(|_| MessageEditorItem(message_editor.clone()))),+ true,+ true,+ None,+ window,+ cx,+ );+ });+ message_editor.read(cx).focus_handle(cx).focus(window, cx);+ let editor = message_editor.read(cx).editor().clone();+ (message_editor, editor)+ });++ message_editor.read_with(&cx, |message_editor, _| {+ message_editor.set_local_commands(vec![+ PromptLocalCommand::ThumbsUp,+ PromptLocalCommand::ThumbsDown,+ ]);+ });++ let invoked = Rc::new(std::cell::RefCell::new(Vec::new()));+ let _subscription = cx.update(|_, cx| {+ cx.subscribe(&message_editor, {+ let invoked = invoked.clone();+ move |_editor, event, _cx| {+ if let MessageEditorEvent::LocalCommandInvoked(command) = event {+ invoked.borrow_mut().push(*command);+ }+ }+ })+ });++ // `/helpful` would fuzzy-match both commands ("helpful" is a+ // subsequence of "not-helpful"), so drive the unambiguous keyword.+ cx.simulate_input("/not-helpful");+ cx.run_until_parked();++ editor.read_with(&cx, |editor, _| {+ assert!(editor.has_visible_completions_menu());+ assert_eq!(+ current_completion_labels(editor),+ &[PromptLocalCommand::ThumbsDown.label().to_string()],+ );+ });++ editor.update_in(&mut cx, |editor, window, cx| {+ editor.confirm_completion(&editor::actions::ConfirmCompletion::default(), window, cx);+ });++ cx.run_until_parked();++ editor.read_with(&cx, |editor, cx| {+ // The `/keyword` text is removed when a local command is confirmed.+ assert_eq!(editor.text(cx), "");+ assert!(!editor.has_visible_completions_menu());+ });++ assert_eq!(+ invoked.borrow().as_slice(),+ &[PromptLocalCommand::ThumbsDown],+ );+ }+/// Opening slash-command autocomplete must emit/// [`MessageEditorEvent::SlashAutocompleteOpened`]. `ThreadView`/// subscribes to that event to fire the global-skills scan triggerdiff --git a/crates/icons/src/icons.rs b/crates/icons/src/icons.rsindex 56182da2133..3e22896e325 100644--- a/crates/icons/src/icons.rs+++ b/crates/icons/src/icons.rs@@ -281,6 +281,7 @@ pub enum IconName {TriangleRight,Undo,Unpin,+ UserArrowUp,UserCheck,UserGroup,UserRoundPen,