agent_ui: Fix new thread in location setting renderer and flag (#51527)

Danilo Leal created

Follow up to https://github.com/zed-industries/zed/pull/51384

This PR fixes the settings UI rendering of this setting by adding a
default value and also wraps it in the feature flag (only the settings
UI rendering), given it's not widely available just yet.

Release Notes:

- N/A

Change summary

Cargo.lock                            |  1 +
assets/settings/default.json          |  4 ++++
crates/settings_content/src/agent.rs  | 13 ++++++++++++-
crates/settings_ui/Cargo.toml         |  1 +
crates/settings_ui/src/page_data.rs   | 27 ++++++++++++++++++---------
crates/settings_ui/src/settings_ui.rs |  2 +-
6 files changed, 37 insertions(+), 11 deletions(-)

Detailed changes

Cargo.lock 🔗

@@ -15711,6 +15711,7 @@ dependencies = [
  "edit_prediction",
  "edit_prediction_ui",
  "editor",
+ "feature_flags",
  "fs",
  "futures 0.3.31",
  "fuzzy",

assets/settings/default.json 🔗

@@ -1083,6 +1083,10 @@
         "tools": {},
       },
     },
+    // Whether to start a new thread in the current local project or in a new Git worktree.
+    //
+    // Default: local_project
+    "new_thread_location": "local_project",
     // Where to show notifications when the agent has either completed
     // its response, or else needs confirmation before it can run a
     // tool action.

crates/settings_content/src/agent.rs 🔗

@@ -11,7 +11,18 @@ use crate::DockPosition;
 
 /// Where new threads should start by default.
 #[derive(
-    Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema, MergeFrom,
+    Clone,
+    Copy,
+    Debug,
+    Default,
+    PartialEq,
+    Eq,
+    Serialize,
+    Deserialize,
+    JsonSchema,
+    MergeFrom,
+    strum::VariantArray,
+    strum::VariantNames,
 )]
 #[serde(rename_all = "snake_case")]
 pub enum NewThreadLocation {

crates/settings_ui/Cargo.toml 🔗

@@ -28,6 +28,7 @@ cpal.workspace = true
 edit_prediction.workspace = true
 edit_prediction_ui.workspace = true
 editor.workspace = true
+feature_flags.workspace = true
 fs.workspace = true
 futures.workspace = true
 fuzzy.workspace = true

crates/settings_ui/src/page_data.rs 🔗

@@ -1,3 +1,4 @@
+use feature_flags::{AgentV2FeatureFlag, FeatureFlagAppExt as _};
 use gpui::{Action as _, App};
 use itertools::Itertools as _;
 use settings::{
@@ -74,7 +75,7 @@ pub(crate) fn settings_data(cx: &App) -> Vec<SettingsPage> {
         terminal_page(),
         version_control_page(),
         collaboration_page(),
-        ai_page(),
+        ai_page(cx),
         network_page(),
     ]
 }
@@ -6978,7 +6979,7 @@ fn collaboration_page() -> SettingsPage {
     }
 }
 
-fn ai_page() -> SettingsPage {
+fn ai_page(cx: &App) -> SettingsPage {
     fn general_section() -> [SettingsPageItem; 2] {
         [
             SettingsPageItem::SectionHeader("General"),
@@ -6998,8 +6999,8 @@ fn ai_page() -> SettingsPage {
         ]
     }
 
-    fn agent_configuration_section() -> [SettingsPageItem; 13] {
-        [
+    fn agent_configuration_section(cx: &App) -> Box<[SettingsPageItem]> {
+        let mut items = vec![
             SettingsPageItem::SectionHeader("Agent Configuration"),
             SettingsPageItem::SubPageLink(SubPageLink {
                 title: "Tool Permissions".into(),
@@ -7010,11 +7011,14 @@ fn ai_page() -> SettingsPage {
                 files: USER,
                 render: render_tool_permissions_setup_page,
             }),
-            SettingsPageItem::SettingItem(SettingItem {
+        ];
+
+        if cx.has_flag::<AgentV2FeatureFlag>() {
+            items.push(SettingsPageItem::SettingItem(SettingItem {
                 title: "New Thread Location",
                 description: "Whether to start a new thread in the current local project or in a new Git worktree.",
                 field: Box::new(SettingField {
-                    json_path: Some("agent.default_start_thread_in"),
+                    json_path: Some("agent.new_thread_location"),
                     pick: |settings_content| {
                         settings_content
                             .agent
@@ -7031,7 +7035,10 @@ fn ai_page() -> SettingsPage {
                 }),
                 metadata: None,
                 files: USER,
-            }),
+            }));
+        }
+
+        items.extend([
             SettingsPageItem::SettingItem(SettingItem {
                 title: "Single File Review",
                 description: "When enabled, agent edits will also be displayed in single-file buffers for review.",
@@ -7236,7 +7243,9 @@ fn ai_page() -> SettingsPage {
                 metadata: None,
                 files: USER,
             }),
-        ]
+        ]);
+
+        items.into_boxed_slice()
     }
 
     fn context_servers_section() -> [SettingsPageItem; 2] {
@@ -7321,7 +7330,7 @@ fn ai_page() -> SettingsPage {
         title: "AI",
         items: concat_sections![
             general_section(),
-            agent_configuration_section(),
+            agent_configuration_section(cx),
             context_servers_section(),
             edit_prediction_language_settings_section(),
             edit_prediction_display_sub_section()

crates/settings_ui/src/settings_ui.rs 🔗

@@ -530,7 +530,7 @@ fn init_renderers(cx: &mut App) {
         .add_basic_renderer::<settings::VimInsertModeCursorShape>(render_dropdown)
         .add_basic_renderer::<settings::SteppingGranularity>(render_dropdown)
         .add_basic_renderer::<settings::NotifyWhenAgentWaiting>(render_dropdown)
-        .add_basic_renderer::<settings::NotifyWhenAgentWaiting>(render_dropdown)
+        .add_basic_renderer::<settings::NewThreadLocation>(render_dropdown)
         .add_basic_renderer::<settings::ImageFileSizeUnit>(render_dropdown)
         .add_basic_renderer::<settings::StatusStyle>(render_dropdown)
         .add_basic_renderer::<settings::EncodingDisplayOptions>(render_dropdown)