Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

agent_ui: Show read-only ACP subagent configuration (#66058)

Ben Brandta8acb01f21c9
diff --git a/crates/acp_thread/src/connection.rs b/crates/acp_thread/src/connection.rs
index 2ac49e3bbe6..9ad1519c28f 100644
--- a/crates/acp_thread/src/connection.rs
+++ b/crates/acp_thread/src/connection.rs
@@ -386,6 +386,11 @@ pub trait AgentSessionConfigOptions {
/// Get all current config options with their state
fn config_options(&self) -> Vec<acp_v2::SessionConfigOption>;
+ /// Agent-owned sessions may report configuration without allowing the client to change it.
+ fn is_read_only(&self) -> bool {
+ false
+ }
+
/// Set a config option value
/// Returns the full updated list of config options
fn set_config_option(
diff --git a/crates/agent_servers/src/acp.rs b/crates/agent_servers/src/acp.rs
index 9267be38baa..5f1ebbb77ed 100644
--- a/crates/agent_servers/src/acp.rs
+++ b/crates/agent_servers/src/acp.rs
@@ -458,6 +458,31 @@ impl ConfigOptions {
}
}
+struct ReadOnlyConfigOptions(ConfigOptions);
+
+impl acp_thread::AgentSessionConfigOptions for ReadOnlyConfigOptions {
+ fn config_options(&self) -> Vec<acp_v2::SessionConfigOption> {
+ self.0.config_options.borrow().clone()
+ }
+
+ fn is_read_only(&self) -> bool {
+ true
+ }
+
+ fn set_config_option(
+ &self,
+ _config_id: acp_v2::SessionConfigId,
+ _value: acp_v2::SessionConfigOptionValue,
+ _cx: &mut App,
+ ) -> Task<Result<Vec<acp_v2::SessionConfigOption>>> {
+ Task::ready(Err(anyhow!("Subagent configuration is read-only")))
+ }
+
+ fn watch(&self, _cx: &mut App) -> Option<watch::Receiver<()>> {
+ Some(self.0.rx.clone())
+ }
+}
+
pub struct AcpSession {
thread: WeakEntity<AcpThread>,
/// Whether a parent announced this session as its ACP subagent. This mirrors the
@@ -841,7 +866,7 @@ fn apply_subagent_update(
is_subagent: true,
suppress_abort_err: false,
session_modes: None,
- config_options: None,
+ config_options: Some(ConfigOptions::new(Rc::new(RefCell::new(Vec::new())))),
default_config_task: None,
_release_subscription: release_subscription,
},
diff --git a/crates/agent_servers/src/acp/v1.rs b/crates/agent_servers/src/acp/v1.rs
index 8028ead19f5..364b9082abe 100644
--- a/crates/agent_servers/src/acp/v1.rs
+++ b/crates/agent_servers/src/acp/v1.rs
@@ -1,7 +1,7 @@
use super::{
AcpDebugLog, AcpDebugMessage, AcpSession, ClientContext, ConfigOptions, FlattenAcpResult as _,
- ForegroundWork, UnsupportedVersion, apply_subagent_update, drain_foreground_queue,
- enqueue_notification, enqueue_request, first_class_terminal_auth_task,
+ ForegroundWork, ReadOnlyConfigOptions, UnsupportedVersion, apply_subagent_update,
+ drain_foreground_queue, enqueue_notification, enqueue_request, first_class_terminal_auth_task,
handle_v2_complete_elicitation, handle_v2_create_elicitation, map_acp_error,
mcp_configurations_for_project, respond_err, respond_result, runtime, session_thread,
terminal_auth_task_id, transport, with_v2_client_ingress, work_dirs_from_session_info,
@@ -1727,12 +1727,21 @@ impl AgentConnection for AcpConnection {
fn session_config_options(
&self,
session_id: &acp_v2::SessionId,
- _cx: &App,
+ cx: &App,
) -> Option<Rc<dyn acp_thread::AgentSessionConfigOptions>> {
let sessions = self.sessions.borrow();
let session = sessions.get(session_id)?;
let config_opts = session.config_options.as_ref()?;
+ if session
+ .thread
+ .upgrade()?
+ .read(cx)
+ .parent_session_id()
+ .is_some()
+ {
+ return Some(Rc::new(ReadOnlyConfigOptions(config_opts.clone())));
+ }
Some(Rc::new(AcpSessionConfigOptions {
session_id: session_id.clone(),
@@ -8186,6 +8195,49 @@ exit 7
let child = parent
.read_with(cx, |parent, _| parent.subagent(&"child".into()).cloned())
.expect("the parent owns the announced subagent");
+ let options = ReadOnlyConfigOptions(
+ sessions
+ .borrow()
+ .get(&acp_v2::SessionId::new("child"))
+ .and_then(|session| session.config_options.clone())
+ .expect("child config exists at announcement"),
+ );
+ use acp_thread::AgentSessionConfigOptions as _;
+ assert!(options.is_read_only());
+ assert!(options.config_options().is_empty());
+ let mut config_updates = cx.update(|cx| options.watch(cx)).expect("config watcher");
+ for model in ["child-model", "fallback-model"] {
+ notify(
+ "child",
+ acp::SessionUpdate::ConfigOptionUpdate(acp::ConfigOptionUpdate::new(vec![
+ acp::SessionConfigOption::select(
+ "model",
+ "Model",
+ model,
+ vec![acp::SessionConfigSelectOption::new(model, model)],
+ ),
+ ])),
+ cx,
+ );
+ config_updates.recv().await.expect("config notification");
+ let reported = options.config_options();
+ assert_eq!(reported.len(), 1);
+ assert!(matches!(
+ &reported.first().expect("child model").kind,
+ acp_v2::SessionConfigKind::Select(select) if select.current_value.0.as_ref() == model
+ ));
+ }
+ let error = cx
+ .update(|cx| {
+ options.set_config_option(
+ "model".into(),
+ acp_v2::SessionConfigOptionValue::id("fallback-model"),
+ cx,
+ )
+ })
+ .await
+ .expect_err("child config is read-only");
+ assert!(error.to_string().contains("read-only"));
child.read_with(cx, |child, _| {
assert_eq!(child.parent_session_id(), Some(&parent_session_id));
assert_eq!(
diff --git a/crates/agent_servers/src/acp/v2.rs b/crates/agent_servers/src/acp/v2.rs
index 9947a609a86..e21c5abab56 100644
--- a/crates/agent_servers/src/acp/v2.rs
+++ b/crates/agent_servers/src/acp/v2.rs
@@ -1,10 +1,10 @@
use super::{
AcpDebugLog, AcpDebugMessage, AcpSession, ClientContext, ConfigOptions,
- ContextServerConfiguration, ForegroundWork, PendingSessionUpdates, UnsupportedVersion,
- apply_v2_session_notification, close_undelivered_session, drain_foreground_queue,
- enqueue_notification, first_class_terminal_auth_task, is_disconnect_error, map_acp_error,
- mcp_configurations_for_project, runtime, transport, with_v2_client_ingress,
- work_dirs_from_session_info,
+ ContextServerConfiguration, ForegroundWork, PendingSessionUpdates, ReadOnlyConfigOptions,
+ UnsupportedVersion, apply_v2_session_notification, close_undelivered_session,
+ drain_foreground_queue, enqueue_notification, first_class_terminal_auth_task,
+ is_disconnect_error, map_acp_error, mcp_configurations_for_project, runtime, transport,
+ with_v2_client_ingress, work_dirs_from_session_info,
};
use acp_thread::{
AcpThread, AgentConnection, AgentSessionConfigOptions, AgentSessionInfo, AgentSessionList,
@@ -1646,13 +1646,24 @@ impl AgentConnection for AcpV2Connection {
fn session_config_options(
&self,
session_id: &acp::SessionId,
- _cx: &App,
+ cx: &App,
) -> Option<Rc<dyn AgentSessionConfigOptions>> {
if self.is_subagent_session(session_id) {
return None;
}
let sessions = self.sessions.borrow();
let session = sessions.get(session_id)?;
+ if session
+ .thread
+ .upgrade()?
+ .read(cx)
+ .parent_session_id()
+ .is_some()
+ {
+ return Some(Rc::new(ReadOnlyConfigOptions(
+ session.config_options.clone()?,
+ )));
+ }
Some(Rc::new(V2SessionConfigOptions {
session_id: session_id.clone(),
thread: session.thread.clone(),
@@ -2441,6 +2452,73 @@ mod tests {
}
}
+ #[gpui::test]
+ async fn v2_subagent_config_options_are_read_only(cx: &mut TestAppContext) {
+ let harness = SessionHarness::new(session_capabilities(), vec![], vec![], cx).await;
+ let parent = harness.thread(cx).await;
+ harness.send_update(
+ "session",
+ acp::SessionUpdate::SubagentUpdate(acp::SubagentUpdate::new("child")),
+ );
+ harness.drain_updates(cx).await;
+
+ let options = cx
+ .read(|cx| harness.client.session_config_options(&"child".into(), cx))
+ .expect("the provider exists before the first config update");
+ assert!(options.is_read_only());
+ assert!(options.config_options().is_empty(), "no inherited values");
+ let mut updates = cx
+ .update(|cx| options.watch(cx))
+ .expect("child config watcher");
+ let model = |value: &str| {
+ acp::SessionConfigOption::select(
+ "model",
+ "Model",
+ value.to_owned(),
+ vec![acp::SessionConfigSelectOption::new(value, value)],
+ )
+ };
+ for snapshot in [
+ vec![
+ model("child-model"),
+ acp::SessionConfigOption::boolean("fast", "Fast", true),
+ ],
+ vec![model("fallback-model")],
+ vec![],
+ ] {
+ harness.send_update(
+ "child",
+ acp::SessionUpdate::ConfigOptionUpdate(acp::ConfigOptionUpdate::new(
+ snapshot.clone(),
+ )),
+ );
+ harness.drain_updates(cx).await;
+ bounded(updates.recv(), cx).await.expect("config update");
+ assert_eq!(options.config_options(), snapshot);
+ }
+ for (config_id, value) in [
+ ("model", acp::SessionConfigOptionValue::id("fallback-model")),
+ ("fast", acp::SessionConfigOptionValue::boolean(false)),
+ ] {
+ let error = cx
+ .update(|cx| options.set_config_option(config_id.into(), value, cx))
+ .await
+ .expect_err("child options cannot be set");
+ assert!(error.to_string().contains("read-only"));
+ }
+ assert!(
+ harness.config_requests.try_recv().is_err(),
+ "no wire mutation"
+ );
+ parent.read_with(cx, |parent, cx| {
+ let options = harness
+ .client
+ .session_config_options(parent.session_id(), cx)
+ .expect("parent config");
+ assert!(!options.is_read_only());
+ });
+ }
+
#[gpui::test]
async fn v2_resume_replay_delivers_subagent_history(cx: &mut TestAppContext) {
let harness = SessionHarness::new(session_capabilities(), vec![], vec![], cx).await;
diff --git a/crates/agent_ui/src/config_options.rs b/crates/agent_ui/src/config_options.rs
index 15a9c43539c..a3f8cbd99ce 100644
--- a/crates/agent_ui/src/config_options.rs
+++ b/crates/agent_ui/src/config_options.rs
@@ -73,6 +73,10 @@ impl ConfigOptionsView {
}
}
+ pub fn is_read_only(&self) -> bool {
+ self.config_options.is_read_only()
+ }
+
pub fn toggle_category_picker(
&mut self,
category: acp::SessionConfigOptionCategory,
@@ -98,6 +102,9 @@ impl ConfigOptionsView {
favorites_only: bool,
cx: &mut Context<Self>,
) -> bool {
+ if self.config_options.is_read_only() {
+ return false;
+ }
let Some(config_id) = self.first_config_option_id_matching(category, |option| {
Self::can_cycle_config_option(option, favorites_only)
}) else {
@@ -367,9 +374,10 @@ impl ConfigOptionSelector {
}
fn toggle_picker(&self, window: &mut Window, cx: &mut Context<Self>) -> bool {
- if !self
- .current_option()
- .is_some_and(|option| matches!(option.kind, acp::SessionConfigKind::Select(_)))
+ if self.config_options.is_read_only()
+ || !self
+ .current_option()
+ .is_some_and(|option| matches!(option.kind, acp::SessionConfigKind::Select(_)))
{
return false;
}
@@ -451,6 +459,28 @@ impl Render for ConfigOptionSelector {
return div().into_any_element();
};
+ if self.config_options.is_read_only() {
+ let value = match &option.kind {
+ acp::SessionConfigKind::Select(_) => self.current_value_name(),
+ acp::SessionConfigKind::Boolean(boolean) => {
+ format!(
+ "{}: {}",
+ option.name,
+ if boolean.current_value { "On" } else { "Off" }
+ )
+ }
+ _ => return div().into_any_element(),
+ };
+ return div()
+ .id(ElementId::Name(
+ format!("config-option-{}", option.config_id.0).into(),
+ ))
+ .px_1()
+ .child(Label::new(value).size(LabelSize::Small).color(Color::Muted))
+ .tooltip(Tooltip::text(option.description.unwrap_or(option.name)))
+ .into_any_element();
+ }
+
match &option.kind {
acp::SessionConfigKind::Select(_) => {
let (Some(picker), Some(picker_handle)) =
@@ -989,6 +1019,9 @@ fn set_config_option_and_default(
fs: Arc<dyn Fs>,
cx: &mut App,
) -> Task<anyhow::Result<()>> {
+ if config_options.is_read_only() {
+ return Task::ready(Err(anyhow::anyhow!("Session configuration is read-only")));
+ }
let response = config_options.set_config_option(config_id.clone(), value, cx);
cx.spawn(async move |cx| {
let options = response.await?;
@@ -1617,6 +1650,83 @@ mod tests {
);
}
+ #[gpui::test]
+ async fn read_only_config_options_do_not_set_values_or_defaults(cx: &mut TestAppContext) {
+ let agent_server = Rc::new(TestAgentServer::default());
+ let config_options = Rc::new(TestSessionConfigOptions {
+ read_only: true,
+ ..TestSessionConfigOptions::new(vec![
+ acp::SessionConfigOption::select(
+ "model",
+ "Model",
+ "child",
+ vec![acp::SessionConfigSelectOption::new("child", "Child model")],
+ )
+ .category(acp::SessionConfigOptionCategory::Model),
+ acp::SessionConfigOption::boolean("fast", "Fast", true)
+ .category(acp::SessionConfigOptionCategory::ModelConfig),
+ ])
+ });
+ let fs: Arc<dyn Fs> = FakeFs::new(cx.executor());
+ let cx = cx.add_empty_window();
+ let view = cx.update(|window, cx| {
+ cx.new(|cx| {
+ ConfigOptionsView::new(
+ config_options.clone(),
+ agent_server.clone(),
+ fs.clone(),
+ window,
+ cx,
+ )
+ })
+ });
+ cx.update(|window, cx| {
+ view.update(cx, |view, cx| {
+ assert_eq!(view.selectors.len(), 2);
+ assert!(!view.toggle_category_picker(
+ acp::SessionConfigOptionCategory::Model,
+ window,
+ cx,
+ ));
+ for category in [
+ acp::SessionConfigOptionCategory::Model,
+ acp::SessionConfigOptionCategory::ModelConfig,
+ ] {
+ assert!(!view.cycle_category_option(category, false, cx));
+ }
+ });
+ });
+ let error = cx
+ .update(|_, cx| {
+ set_config_option_and_default(
+ config_options.clone(),
+ agent_server.clone(),
+ "fast".into(),
+ acp::SessionConfigOptionValue::boolean(false),
+ fs,
+ cx,
+ )
+ })
+ .await
+ .expect_err("even a stale picker cannot set a read-only value");
+ assert!(error.to_string().contains("read-only"));
+ assert!(config_options.set_values.borrow().is_empty());
+ assert!(agent_server.saved_defaults.lock().is_empty());
+
+ config_options.replace_options(vec![acp::SessionConfigOption::boolean(
+ "fast", "Fast", false,
+ )]);
+ cx.run_until_parked();
+ view.read_with(cx, |view, cx| {
+ assert_eq!(view.selectors.len(), 1);
+ assert!(matches!(
+ view.selectors.first().expect("updated selector").read(cx).current_option()
+ .expect("updated option").kind,
+ acp::SessionConfigKind::Boolean(boolean) if !boolean.current_value
+ ));
+ });
+ }
+
#[derive(Default)]
struct TestAgentServer {
saved_defaults: Arc<Mutex<Vec<(String, Option<AgentConfigOptionValue>)>>>,
@@ -1658,6 +1768,7 @@ mod tests {
}
struct TestSessionConfigOptions {
+ read_only: bool,
options: RefCell<Vec<acp::SessionConfigOption>>,
set_values: RefCell<Vec<(String, acp::SessionConfigOptionValue)>>,
updates: RefCell<watch::Sender<()>>,
@@ -1671,6 +1782,7 @@ mod tests {
impl TestSessionConfigOptions {
fn new(options: Vec<acp::SessionConfigOption>) -> Self {
Self {
+ read_only: false,
options: RefCell::new(options),
set_values: RefCell::new(Vec::new()),
updates: RefCell::new(watch::channel(()).0),
@@ -1698,6 +1810,10 @@ mod tests {
self.options.borrow().clone()
}
+ fn is_read_only(&self) -> bool {
+ self.read_only
+ }
+
fn set_config_option(
&self,
config_id: acp::SessionConfigId,
diff --git a/crates/agent_ui/src/conversation_view/thread_view.rs b/crates/agent_ui/src/conversation_view/thread_view.rs
index af8d9075ccd..32ef9a5dba9 100644
--- a/crates/agent_ui/src/conversation_view/thread_view.rs
+++ b/crates/agent_ui/src/conversation_view/thread_view.rs
@@ -5354,7 +5354,15 @@ impl ThreadView {
cx: &mut Context<Self>,
) -> AnyElement {
if self.is_subagent() {
- return div().into_any_element();
+ return h_flex()
+ .px_2()
+ .py_1()
+ .children(
+ self.config_options_view
+ .clone()
+ .filter(|view| view.read(cx).is_read_only()),
+ )
+ .into_any_element();
}
let focus_handle = self.message_editor.focus_handle(cx);