1mod agent_configuration;
2mod agent_diff;
3mod agent_model_selector;
4mod agent_panel;
5mod agent_registry_ui;
6mod buffer_codegen;
7mod completion_provider;
8mod config_options;
9pub(crate) mod connection_view;
10mod context;
11mod context_server_configuration;
12mod entry_view_state;
13mod favorite_models;
14mod inline_assistant;
15mod inline_prompt_editor;
16mod language_model_selector;
17mod mention_set;
18mod message_editor;
19mod mode_selector;
20mod model_selector;
21mod model_selector_popover;
22mod profile_selector;
23mod slash_command;
24mod slash_command_picker;
25mod terminal_codegen;
26mod terminal_inline_assistant;
27mod text_thread_editor;
28mod text_thread_history;
29mod thread_history;
30mod ui;
31
32use std::rc::Rc;
33use std::sync::Arc;
34
35use agent_settings::{AgentProfileId, AgentSettings};
36use assistant_slash_command::SlashCommandRegistry;
37use client::Client;
38use command_palette_hooks::CommandPaletteFilter;
39use feature_flags::{AgentV2FeatureFlag, FeatureFlagAppExt as _};
40use fs::Fs;
41use gpui::{Action, App, Context, Entity, SharedString, Window, actions};
42use language::{
43 LanguageRegistry,
44 language_settings::{AllLanguageSettings, EditPredictionProvider},
45};
46use language_model::{
47 ConfiguredModel, LanguageModelId, LanguageModelProviderId, LanguageModelRegistry,
48};
49use project::DisableAiSettings;
50use prompt_store::PromptBuilder;
51use schemars::JsonSchema;
52use serde::{Deserialize, Serialize};
53use settings::{LanguageModelSelection, Settings as _, SettingsStore};
54use std::any::TypeId;
55use workspace::Workspace;
56
57use crate::agent_configuration::{ConfigureContextServerModal, ManageProfilesModal};
58pub use crate::agent_panel::{
59 AgentPanel, AgentPanelEvent, ConcreteAssistantPanelDelegate, WorktreeCreationStatus,
60};
61use crate::agent_registry_ui::AgentRegistryPage;
62pub use crate::inline_assistant::InlineAssistant;
63pub use agent_diff::{AgentDiffPane, AgentDiffToolbar};
64pub(crate) use connection_view::ConnectionView;
65pub(crate) use mode_selector::ModeSelector;
66pub(crate) use model_selector::ModelSelector;
67pub(crate) use model_selector_popover::ModelSelectorPopover;
68pub use text_thread_editor::{AgentPanelDelegate, TextThreadEditor};
69pub(crate) use thread_history::*;
70use zed_actions;
71
72actions!(
73 agent,
74 [
75 /// Creates a new text-based conversation thread.
76 NewTextThread,
77 /// Toggles the menu to create new agent threads.
78 ToggleNewThreadMenu,
79 /// Toggles the navigation menu for switching between threads and views.
80 ToggleNavigationMenu,
81 /// Toggles the options menu for agent settings and preferences.
82 ToggleOptionsMenu,
83 /// Toggles the profile or mode selector for switching between agent profiles.
84 ToggleProfileSelector,
85 /// Cycles through available session modes.
86 CycleModeSelector,
87 /// Cycles through favorited models in the ACP model selector.
88 CycleFavoriteModels,
89 /// Expands the message editor to full size.
90 ExpandMessageEditor,
91 /// Removes all thread history.
92 RemoveHistory,
93 /// Opens the conversation history view.
94 OpenHistory,
95 /// Adds a context server to the configuration.
96 AddContextServer,
97 /// Removes the currently selected thread.
98 RemoveSelectedThread,
99 /// Starts a chat conversation with follow-up enabled.
100 ChatWithFollow,
101 /// Cycles to the next inline assist suggestion.
102 CycleNextInlineAssist,
103 /// Cycles to the previous inline assist suggestion.
104 CyclePreviousInlineAssist,
105 /// Moves focus up in the interface.
106 FocusUp,
107 /// Moves focus down in the interface.
108 FocusDown,
109 /// Moves focus left in the interface.
110 FocusLeft,
111 /// Moves focus right in the interface.
112 FocusRight,
113 /// Opens the active thread as a markdown file.
114 OpenActiveThreadAsMarkdown,
115 /// Opens the agent diff view to review changes.
116 OpenAgentDiff,
117 /// Copies the current thread to the clipboard as JSON for debugging.
118 CopyThreadToClipboard,
119 /// Loads a thread from the clipboard JSON for debugging.
120 LoadThreadFromClipboard,
121 /// Keeps the current suggestion or change.
122 Keep,
123 /// Rejects the current suggestion or change.
124 Reject,
125 /// Rejects all suggestions or changes.
126 RejectAll,
127 /// Undoes the most recent reject operation, restoring the rejected changes.
128 UndoLastReject,
129 /// Keeps all suggestions or changes.
130 KeepAll,
131 /// Allow this operation only this time.
132 AllowOnce,
133 /// Allow this operation and remember the choice.
134 AllowAlways,
135 /// Reject this operation only this time.
136 RejectOnce,
137 /// Follows the agent's suggestions.
138 Follow,
139 /// Resets the trial upsell notification.
140 ResetTrialUpsell,
141 /// Resets the trial end upsell notification.
142 ResetTrialEndUpsell,
143 /// Opens the "Add Context" menu in the message editor.
144 OpenAddContextMenu,
145 /// Continues the current thread.
146 ContinueThread,
147 /// Interrupts the current generation and sends the message immediately.
148 SendImmediately,
149 /// Sends the next queued message immediately.
150 SendNextQueuedMessage,
151 /// Removes the first message from the queue (the next one to be sent).
152 RemoveFirstQueuedMessage,
153 /// Edits the first message in the queue (the next one to be sent).
154 EditFirstQueuedMessage,
155 /// Clears all messages from the queue.
156 ClearMessageQueue,
157 /// Opens the permission granularity dropdown for the current tool call.
158 OpenPermissionDropdown,
159 /// Toggles thinking mode for models that support extended thinking.
160 ToggleThinkingMode,
161 /// Cycles through available thinking effort levels for the current model.
162 CycleThinkingEffort,
163 /// Toggles the thinking effort selector menu open or closed.
164 ToggleThinkingEffortMenu,
165 /// Toggles fast mode for models that support it.
166 ToggleFastMode,
167 ]
168);
169
170/// Action to authorize a tool call with a specific permission option.
171/// This is used by the permission granularity dropdown to authorize tool calls.
172#[derive(Clone, PartialEq, Deserialize, JsonSchema, Action)]
173#[action(namespace = agent)]
174#[serde(deny_unknown_fields)]
175pub struct AuthorizeToolCall {
176 /// The tool call ID to authorize.
177 pub tool_call_id: String,
178 /// The permission option ID to use.
179 pub option_id: String,
180 /// The kind of permission option (serialized as string).
181 pub option_kind: String,
182}
183
184/// Creates a new conversation thread, optionally based on an existing thread.
185#[derive(Default, Clone, PartialEq, Deserialize, JsonSchema, Action)]
186#[action(namespace = agent)]
187#[serde(deny_unknown_fields)]
188pub struct NewThread;
189
190/// Creates a new external agent conversation thread.
191#[derive(Default, Clone, PartialEq, Deserialize, JsonSchema, Action)]
192#[action(namespace = agent)]
193#[serde(deny_unknown_fields)]
194pub struct NewExternalAgentThread {
195 /// Which agent to use for the conversation.
196 agent: Option<ExternalAgent>,
197}
198
199#[derive(Clone, PartialEq, Deserialize, JsonSchema, Action)]
200#[action(namespace = agent)]
201#[serde(deny_unknown_fields)]
202pub struct NewNativeAgentThreadFromSummary {
203 from_session_id: agent_client_protocol::SessionId,
204}
205
206// TODO unify this with AgentType
207#[derive(Debug, Clone, PartialEq, Serialize, JsonSchema)]
208#[serde(rename_all = "snake_case")]
209pub enum ExternalAgent {
210 NativeAgent,
211 Custom { name: SharedString },
212}
213
214// Custom impl handles legacy variant names from before the built-in agents were moved to
215// the registry: "claude_code" -> Custom { name: "claude-acp" }, "codex" -> Custom { name:
216// "codex-acp" }, "gemini" -> Custom { name: "gemini" }.
217// Can be removed at some point in the future and go back to #[derive(Deserialize)].
218impl<'de> serde::Deserialize<'de> for ExternalAgent {
219 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
220 where
221 D: serde::Deserializer<'de>,
222 {
223 use project::agent_server_store::{CLAUDE_AGENT_NAME, CODEX_NAME, GEMINI_NAME};
224
225 let value = serde_json::Value::deserialize(deserializer)?;
226
227 if let Some(s) = value.as_str() {
228 return match s {
229 "native_agent" => Ok(Self::NativeAgent),
230 "claude_code" | "claude_agent" => Ok(Self::Custom {
231 name: CLAUDE_AGENT_NAME.into(),
232 }),
233 "codex" => Ok(Self::Custom {
234 name: CODEX_NAME.into(),
235 }),
236 "gemini" => Ok(Self::Custom {
237 name: GEMINI_NAME.into(),
238 }),
239 other => Err(serde::de::Error::unknown_variant(
240 other,
241 &[
242 "native_agent",
243 "custom",
244 "claude_agent",
245 "claude_code",
246 "codex",
247 "gemini",
248 ],
249 )),
250 };
251 }
252
253 if let Some(obj) = value.as_object() {
254 if let Some(inner) = obj.get("custom") {
255 #[derive(serde::Deserialize)]
256 struct CustomFields {
257 name: SharedString,
258 }
259 let fields: CustomFields =
260 serde_json::from_value(inner.clone()).map_err(serde::de::Error::custom)?;
261 return Ok(Self::Custom { name: fields.name });
262 }
263 }
264
265 Err(serde::de::Error::custom(
266 "expected a string variant or {\"custom\": {\"name\": ...}}",
267 ))
268 }
269}
270
271impl ExternalAgent {
272 pub fn server(
273 &self,
274 fs: Arc<dyn fs::Fs>,
275 thread_store: Entity<agent::ThreadStore>,
276 ) -> Rc<dyn agent_servers::AgentServer> {
277 match self {
278 Self::NativeAgent => Rc::new(agent::NativeAgentServer::new(fs, thread_store)),
279 Self::Custom { name } => Rc::new(agent_servers::CustomAgentServer::new(name.clone())),
280 }
281 }
282}
283
284/// Sets where new threads will run.
285#[derive(
286 Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema, Action,
287)]
288#[action(namespace = agent)]
289#[serde(rename_all = "snake_case", tag = "kind")]
290pub enum StartThreadIn {
291 #[default]
292 LocalProject,
293 NewWorktree,
294}
295
296/// Content to initialize new external agent with.
297pub enum AgentInitialContent {
298 ThreadSummary(acp_thread::AgentSessionInfo),
299 ContentBlock {
300 blocks: Vec<agent_client_protocol::ContentBlock>,
301 auto_submit: bool,
302 },
303}
304
305/// Opens the profile management interface for configuring agent tools and settings.
306#[derive(PartialEq, Clone, Default, Debug, Deserialize, JsonSchema, Action)]
307#[action(namespace = agent)]
308#[serde(deny_unknown_fields)]
309pub struct ManageProfiles {
310 #[serde(default)]
311 pub customize_tools: Option<AgentProfileId>,
312}
313
314impl ManageProfiles {
315 pub fn customize_tools(profile_id: AgentProfileId) -> Self {
316 Self {
317 customize_tools: Some(profile_id),
318 }
319 }
320}
321
322#[derive(Clone)]
323pub(crate) enum ModelUsageContext {
324 InlineAssistant,
325}
326
327impl ModelUsageContext {
328 pub fn configured_model(&self, cx: &App) -> Option<ConfiguredModel> {
329 match self {
330 Self::InlineAssistant => {
331 LanguageModelRegistry::read_global(cx).inline_assistant_model()
332 }
333 }
334 }
335}
336
337/// Initializes the `agent` crate.
338pub fn init(
339 fs: Arc<dyn Fs>,
340 client: Arc<Client>,
341 prompt_builder: Arc<PromptBuilder>,
342 language_registry: Arc<LanguageRegistry>,
343 is_eval: bool,
344 cx: &mut App,
345) {
346 agent::ThreadStore::init_global(cx);
347 assistant_text_thread::init(client, cx);
348 rules_library::init(cx);
349 if !is_eval {
350 // Initializing the language model from the user settings messes with the eval, so we only initialize them when
351 // we're not running inside of the eval.
352 init_language_model_settings(cx);
353 }
354 assistant_slash_command::init(cx);
355 agent_panel::init(cx);
356 context_server_configuration::init(language_registry.clone(), fs.clone(), cx);
357 TextThreadEditor::init(cx);
358
359 register_slash_commands(cx);
360 inline_assistant::init(fs.clone(), prompt_builder.clone(), cx);
361 terminal_inline_assistant::init(fs.clone(), prompt_builder, cx);
362 cx.observe_new(move |workspace, window, cx| {
363 ConfigureContextServerModal::register(workspace, language_registry.clone(), window, cx)
364 })
365 .detach();
366 cx.observe_new(|workspace: &mut Workspace, _window, _cx| {
367 workspace.register_action(
368 move |workspace: &mut Workspace,
369 _: &zed_actions::AcpRegistry,
370 window: &mut Window,
371 cx: &mut Context<Workspace>| {
372 let existing = workspace
373 .active_pane()
374 .read(cx)
375 .items()
376 .find_map(|item| item.downcast::<AgentRegistryPage>());
377
378 if let Some(existing) = existing {
379 existing.update(cx, |_, cx| {
380 project::AgentRegistryStore::global(cx)
381 .update(cx, |store, cx| store.refresh(cx));
382 });
383 workspace.activate_item(&existing, true, true, window, cx);
384 } else {
385 let registry_page = AgentRegistryPage::new(workspace, window, cx);
386 workspace.add_item_to_active_pane(
387 Box::new(registry_page),
388 None,
389 true,
390 window,
391 cx,
392 );
393 }
394 },
395 );
396 })
397 .detach();
398 cx.observe_new(ManageProfilesModal::register).detach();
399
400 // Update command palette filter based on AI settings
401 update_command_palette_filter(cx);
402
403 // Watch for settings changes
404 cx.observe_global::<SettingsStore>(|app_cx| {
405 // When settings change, update the command palette filter
406 update_command_palette_filter(app_cx);
407 })
408 .detach();
409
410 cx.on_flags_ready(|_, cx| {
411 update_command_palette_filter(cx);
412 })
413 .detach();
414}
415
416fn update_command_palette_filter(cx: &mut App) {
417 let disable_ai = DisableAiSettings::get_global(cx).disable_ai;
418 let agent_enabled = AgentSettings::get_global(cx).enabled;
419 let agent_v2_enabled = cx.has_flag::<AgentV2FeatureFlag>();
420 let edit_prediction_provider = AllLanguageSettings::get_global(cx)
421 .edit_predictions
422 .provider;
423
424 CommandPaletteFilter::update_global(cx, |filter, _| {
425 use editor::actions::{
426 AcceptEditPrediction, AcceptNextLineEditPrediction, AcceptNextWordEditPrediction,
427 NextEditPrediction, PreviousEditPrediction, ShowEditPrediction, ToggleEditPrediction,
428 };
429 let edit_prediction_actions = [
430 TypeId::of::<AcceptEditPrediction>(),
431 TypeId::of::<AcceptNextWordEditPrediction>(),
432 TypeId::of::<AcceptNextLineEditPrediction>(),
433 TypeId::of::<AcceptEditPrediction>(),
434 TypeId::of::<ShowEditPrediction>(),
435 TypeId::of::<NextEditPrediction>(),
436 TypeId::of::<PreviousEditPrediction>(),
437 TypeId::of::<ToggleEditPrediction>(),
438 ];
439
440 if disable_ai {
441 filter.hide_namespace("agent");
442 filter.hide_namespace("agents");
443 filter.hide_namespace("assistant");
444 filter.hide_namespace("copilot");
445 filter.hide_namespace("zed_predict_onboarding");
446 filter.hide_namespace("edit_prediction");
447
448 filter.hide_action_types(&edit_prediction_actions);
449 filter.hide_action_types(&[TypeId::of::<zed_actions::OpenZedPredictOnboarding>()]);
450 } else {
451 if agent_enabled {
452 filter.show_namespace("agent");
453 filter.show_namespace("agents");
454 filter.show_namespace("assistant");
455 } else {
456 filter.hide_namespace("agent");
457 filter.hide_namespace("agents");
458 filter.hide_namespace("assistant");
459 }
460
461 match edit_prediction_provider {
462 EditPredictionProvider::None => {
463 filter.hide_namespace("edit_prediction");
464 filter.hide_namespace("copilot");
465 filter.hide_action_types(&edit_prediction_actions);
466 }
467 EditPredictionProvider::Copilot => {
468 filter.show_namespace("edit_prediction");
469 filter.show_namespace("copilot");
470 filter.show_action_types(edit_prediction_actions.iter());
471 }
472 EditPredictionProvider::Zed
473 | EditPredictionProvider::Codestral
474 | EditPredictionProvider::Ollama
475 | EditPredictionProvider::OpenAiCompatibleApi
476 | EditPredictionProvider::Sweep
477 | EditPredictionProvider::Mercury
478 | EditPredictionProvider::Experimental(_) => {
479 filter.show_namespace("edit_prediction");
480 filter.hide_namespace("copilot");
481 filter.show_action_types(edit_prediction_actions.iter());
482 }
483 }
484
485 filter.show_namespace("zed_predict_onboarding");
486 filter.show_action_types(&[TypeId::of::<zed_actions::OpenZedPredictOnboarding>()]);
487 }
488
489 if agent_v2_enabled {
490 filter.show_namespace("multi_workspace");
491 } else {
492 filter.hide_namespace("multi_workspace");
493 }
494 });
495}
496
497fn init_language_model_settings(cx: &mut App) {
498 update_active_language_model_from_settings(cx);
499
500 cx.observe_global::<SettingsStore>(update_active_language_model_from_settings)
501 .detach();
502 cx.subscribe(
503 &LanguageModelRegistry::global(cx),
504 |_, event: &language_model::Event, cx| match event {
505 language_model::Event::ProviderStateChanged(_)
506 | language_model::Event::AddedProvider(_)
507 | language_model::Event::RemovedProvider(_)
508 | language_model::Event::ProvidersChanged => {
509 update_active_language_model_from_settings(cx);
510 }
511 _ => {}
512 },
513 )
514 .detach();
515}
516
517fn update_active_language_model_from_settings(cx: &mut App) {
518 let settings = AgentSettings::get_global(cx);
519
520 fn to_selected_model(selection: &LanguageModelSelection) -> language_model::SelectedModel {
521 language_model::SelectedModel {
522 provider: LanguageModelProviderId::from(selection.provider.0.clone()),
523 model: LanguageModelId::from(selection.model.clone()),
524 }
525 }
526
527 let default = settings.default_model.as_ref().map(to_selected_model);
528 let inline_assistant = settings
529 .inline_assistant_model
530 .as_ref()
531 .map(to_selected_model);
532 let commit_message = settings
533 .commit_message_model
534 .as_ref()
535 .map(to_selected_model);
536 let thread_summary = settings
537 .thread_summary_model
538 .as_ref()
539 .map(to_selected_model);
540 let inline_alternatives = settings
541 .inline_alternatives
542 .iter()
543 .map(to_selected_model)
544 .collect::<Vec<_>>();
545
546 LanguageModelRegistry::global(cx).update(cx, |registry, cx| {
547 registry.select_default_model(default.as_ref(), cx);
548 registry.select_inline_assistant_model(inline_assistant.as_ref(), cx);
549 registry.select_commit_message_model(commit_message.as_ref(), cx);
550 registry.select_thread_summary_model(thread_summary.as_ref(), cx);
551 registry.select_inline_alternative_models(inline_alternatives, cx);
552 });
553}
554
555fn register_slash_commands(cx: &mut App) {
556 let slash_command_registry = SlashCommandRegistry::global(cx);
557
558 slash_command_registry.register_command(assistant_slash_commands::FileSlashCommand, true);
559 slash_command_registry.register_command(assistant_slash_commands::DeltaSlashCommand, true);
560 slash_command_registry.register_command(assistant_slash_commands::OutlineSlashCommand, true);
561 slash_command_registry.register_command(assistant_slash_commands::TabSlashCommand, true);
562 slash_command_registry.register_command(assistant_slash_commands::PromptSlashCommand, true);
563 slash_command_registry.register_command(assistant_slash_commands::SelectionCommand, true);
564 slash_command_registry.register_command(assistant_slash_commands::DefaultSlashCommand, false);
565 slash_command_registry.register_command(assistant_slash_commands::NowSlashCommand, false);
566 slash_command_registry
567 .register_command(assistant_slash_commands::DiagnosticsSlashCommand, true);
568 slash_command_registry.register_command(assistant_slash_commands::FetchSlashCommand, true);
569
570 cx.observe_flag::<assistant_slash_commands::StreamingExampleSlashCommandFeatureFlag, _>({
571 move |is_enabled, _cx| {
572 if is_enabled {
573 slash_command_registry.register_command(
574 assistant_slash_commands::StreamingExampleSlashCommand,
575 false,
576 );
577 }
578 }
579 })
580 .detach();
581}
582
583#[cfg(test)]
584mod tests {
585 use super::*;
586 use agent_settings::{AgentProfileId, AgentSettings};
587 use command_palette_hooks::CommandPaletteFilter;
588 use editor::actions::AcceptEditPrediction;
589 use gpui::{BorrowAppContext, TestAppContext, px};
590 use project::DisableAiSettings;
591 use settings::{
592 DefaultAgentView, DockPosition, NotifyWhenAgentWaiting, Settings, SettingsStore,
593 };
594
595 #[gpui::test]
596 fn test_agent_command_palette_visibility(cx: &mut TestAppContext) {
597 // Init settings
598 cx.update(|cx| {
599 let store = SettingsStore::test(cx);
600 cx.set_global(store);
601 command_palette_hooks::init(cx);
602 AgentSettings::register(cx);
603 DisableAiSettings::register(cx);
604 AllLanguageSettings::register(cx);
605 });
606
607 let agent_settings = AgentSettings {
608 enabled: true,
609 button: true,
610 dock: DockPosition::Right,
611 default_width: px(300.),
612 default_height: px(600.),
613 default_model: None,
614 inline_assistant_model: None,
615 inline_assistant_use_streaming_tools: false,
616 commit_message_model: None,
617 thread_summary_model: None,
618 inline_alternatives: vec![],
619 favorite_models: vec![],
620 default_profile: AgentProfileId::default(),
621 default_view: DefaultAgentView::Thread,
622 profiles: Default::default(),
623
624 notify_when_agent_waiting: NotifyWhenAgentWaiting::default(),
625 play_sound_when_agent_done: false,
626 single_file_review: false,
627 model_parameters: vec![],
628 enable_feedback: false,
629 expand_edit_card: true,
630 expand_terminal_card: true,
631 cancel_generation_on_terminal_stop: true,
632 use_modifier_to_send: true,
633 message_editor_min_lines: 1,
634 tool_permissions: Default::default(),
635 show_turn_stats: false,
636 };
637
638 cx.update(|cx| {
639 AgentSettings::override_global(agent_settings.clone(), cx);
640 DisableAiSettings::override_global(DisableAiSettings { disable_ai: false }, cx);
641
642 // Initial update
643 update_command_palette_filter(cx);
644 });
645
646 // Assert visible
647 cx.update(|cx| {
648 let filter = CommandPaletteFilter::try_global(cx).unwrap();
649 assert!(
650 !filter.is_hidden(&NewThread),
651 "NewThread should be visible by default"
652 );
653 assert!(
654 !filter.is_hidden(&text_thread_editor::CopyCode),
655 "CopyCode should be visible when agent is enabled"
656 );
657 });
658
659 // Disable agent
660 cx.update(|cx| {
661 let mut new_settings = agent_settings.clone();
662 new_settings.enabled = false;
663 AgentSettings::override_global(new_settings, cx);
664
665 // Trigger update
666 update_command_palette_filter(cx);
667 });
668
669 // Assert hidden
670 cx.update(|cx| {
671 let filter = CommandPaletteFilter::try_global(cx).unwrap();
672 assert!(
673 filter.is_hidden(&NewThread),
674 "NewThread should be hidden when agent is disabled"
675 );
676 assert!(
677 filter.is_hidden(&text_thread_editor::CopyCode),
678 "CopyCode should be hidden when agent is disabled"
679 );
680 });
681
682 // Test EditPredictionProvider
683 // Enable EditPredictionProvider::Copilot
684 cx.update(|cx| {
685 cx.update_global::<SettingsStore, _>(|store, cx| {
686 store.update_user_settings(cx, |s| {
687 s.project
688 .all_languages
689 .edit_predictions
690 .get_or_insert(Default::default())
691 .provider = Some(EditPredictionProvider::Copilot);
692 });
693 });
694 update_command_palette_filter(cx);
695 });
696
697 cx.update(|cx| {
698 let filter = CommandPaletteFilter::try_global(cx).unwrap();
699 assert!(
700 !filter.is_hidden(&AcceptEditPrediction),
701 "EditPrediction should be visible when provider is Copilot"
702 );
703 });
704
705 // Disable EditPredictionProvider (None)
706 cx.update(|cx| {
707 cx.update_global::<SettingsStore, _>(|store, cx| {
708 store.update_user_settings(cx, |s| {
709 s.project
710 .all_languages
711 .edit_predictions
712 .get_or_insert(Default::default())
713 .provider = Some(EditPredictionProvider::None);
714 });
715 });
716 update_command_palette_filter(cx);
717 });
718
719 cx.update(|cx| {
720 let filter = CommandPaletteFilter::try_global(cx).unwrap();
721 assert!(
722 filter.is_hidden(&AcceptEditPrediction),
723 "EditPrediction should be hidden when provider is None"
724 );
725 });
726 }
727
728 #[test]
729 fn test_deserialize_legacy_external_agent_variants() {
730 use project::agent_server_store::{CLAUDE_AGENT_NAME, CODEX_NAME, GEMINI_NAME};
731
732 assert_eq!(
733 serde_json::from_str::<ExternalAgent>(r#""claude_code""#).unwrap(),
734 ExternalAgent::Custom {
735 name: CLAUDE_AGENT_NAME.into(),
736 },
737 );
738 assert_eq!(
739 serde_json::from_str::<ExternalAgent>(r#""codex""#).unwrap(),
740 ExternalAgent::Custom {
741 name: CODEX_NAME.into(),
742 },
743 );
744 assert_eq!(
745 serde_json::from_str::<ExternalAgent>(r#""gemini""#).unwrap(),
746 ExternalAgent::Custom {
747 name: GEMINI_NAME.into(),
748 },
749 );
750 }
751
752 #[test]
753 fn test_deserialize_current_external_agent_variants() {
754 assert_eq!(
755 serde_json::from_str::<ExternalAgent>(r#""native_agent""#).unwrap(),
756 ExternalAgent::NativeAgent,
757 );
758 assert_eq!(
759 serde_json::from_str::<ExternalAgent>(r#"{"custom":{"name":"my-agent"}}"#).unwrap(),
760 ExternalAgent::Custom {
761 name: "my-agent".into(),
762 },
763 );
764 }
765}