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.

Add ACP session notice support (#64606)

Ben Brandta3ccafef66af
diff --git a/crates/acp_thread/src/acp_thread.rs b/crates/acp_thread/src/acp_thread.rs
index b170b623516..9dbfe169296 100644
--- a/crates/acp_thread/src/acp_thread.rs
+++ b/crates/acp_thread/src/acp_thread.rs
@@ -2265,6 +2265,9 @@ pub struct AcpThread {
title: Option<SharedString>,
provisional_title: Option<SharedString>,
entries: Vec<AgentThreadEntry>,
+ // Notices stay with the live session, but never enter conversation history or exports.
+ notices: Vec<(usize, acp::Notice)>,
+ next_notice_id: usize,
elicitations: ElicitationStore,
plan: Plan,
project: Entity<Project>,
@@ -2338,6 +2341,7 @@ pub enum AcpThreadEvent {
PromptUpdated,
NewEntry,
TitleUpdated,
+ NoticesUpdated,
TokenUsageUpdated,
EntryUpdated(usize),
EntriesRemoved(Range<usize>),
@@ -2478,6 +2482,7 @@ impl AcpThread {
AcpThreadEvent::PromptUpdated
| AcpThreadEvent::NewEntry
| AcpThreadEvent::TitleUpdated
+ | AcpThreadEvent::NoticesUpdated
| AcpThreadEvent::TokenUsageUpdated
| AcpThreadEvent::EntryUpdated(_)
| AcpThreadEvent::Retry(_)
@@ -2516,6 +2521,8 @@ impl AcpThread {
update_last_checkpoint_if_changed_task: None,
shared_buffers: Default::default(),
entries: Default::default(),
+ notices: Vec::new(),
+ next_notice_id: 0,
elicitations: ElicitationStore::default(),
plan: Default::default(),
title,
@@ -2608,6 +2615,19 @@ impl AcpThread {
&self.entries
}
+ pub fn notices(&self) -> &[(usize, acp::Notice)] {
+ &self.notices
+ }
+
+ pub fn dismiss_notice(&mut self, notice_id: usize, cx: &mut Context<Self>) {
+ let previous_count = self.notices.len();
+ self.notices.retain(|(id, _)| *id != notice_id);
+ if self.notices.len() != previous_count {
+ cx.emit(AcpThreadEvent::NoticesUpdated);
+ cx.notify();
+ }
+ }
+
pub fn is_compacting(&self) -> bool {
self.entries.iter().rev().any(|entry| {
matches!(
@@ -2830,6 +2850,13 @@ impl AcpThread {
acp::SessionUpdate::Plan(plan) => {
self.update_plan(plan, cx);
}
+ acp::SessionUpdate::Notice(notice) => {
+ let notice_id = self.next_notice_id;
+ self.next_notice_id += 1;
+ self.notices.push((notice_id, notice));
+ cx.emit(AcpThreadEvent::NoticesUpdated);
+ cx.notify();
+ }
acp::SessionUpdate::SessionInfoUpdate(info_update) => {
if let MaybeUndefined::Value(title) = info_update.title {
let had_provisional = self.provisional_title.take().is_some();
@@ -11502,6 +11529,167 @@ mod tests {
);
}
+ #[gpui::test]
+ async fn test_session_notices_are_live_and_independently_dismissible(cx: &mut TestAppContext) {
+ init_test(cx);
+
+ let fs = FakeFs::new(cx.executor());
+ let project = Project::test(fs, [], cx).await;
+ let connection = Rc::new(FakeAgentConnection::new());
+ let thread = cx
+ .update(|cx| {
+ connection.new_session(project, PathList::new(&[Path::new(path!("/test"))]), cx)
+ })
+ .await
+ .expect("session should be created");
+
+ let notice_events = Rc::new(RefCell::new(0));
+ let _subscription = thread.update(cx, |_, cx| {
+ cx.subscribe_self({
+ let notice_events = notice_events.clone();
+ move |_, event, _| {
+ assert!(matches!(event, AcpThreadEvent::NoticesUpdated));
+ *notice_events.borrow_mut() += 1;
+ }
+ })
+ });
+
+ let warning = acp::Notice::new(acp::NoticeSeverity::Warning, "MCP server unavailable")
+ .description("Continuing without it.");
+ let notices = vec![
+ acp::Notice::new(acp::NoticeSeverity::Info, "Using default configuration"),
+ warning.clone(),
+ warning.clone(),
+ acp::Notice::new(acp::NoticeSeverity::Error, "Optional integration failed"),
+ acp::Notice::new(
+ acp::NoticeSeverity::Other("critical".into()),
+ "Future severity",
+ ),
+ acp::Notice::new(
+ acp::NoticeSeverity::Other("_custom".into()),
+ "**Plain text**, not Markdown",
+ )
+ .meta(acp::Meta::from_iter([("source".into(), "test".into())])),
+ ];
+
+ thread.update(cx, |thread, cx| {
+ for notice in &notices {
+ thread
+ .handle_session_update(acp::SessionUpdate::Notice(notice.clone()), cx)
+ .expect("notice should be accepted");
+ }
+ assert_eq!(
+ thread.notices(),
+ notices.iter().cloned().enumerate().collect::<Vec<_>>()
+ );
+ assert!(thread.entries().is_empty());
+ assert!(thread.to_markdown(cx).is_empty());
+ assert!(thread.is_draft_thread());
+ assert_eq!(thread.status(), ThreadStatus::Idle);
+ assert!(!thread.had_error());
+ assert!(!thread.is_waiting_for_confirmation());
+ assert!(thread.title().is_none());
+ });
+ assert_eq!(*notice_events.borrow(), notices.len());
+
+ thread.update(cx, |thread, cx| thread.dismiss_notice(1, cx));
+ assert_eq!(*notice_events.borrow(), notices.len() + 1);
+ thread.read_with(cx, |thread, _| {
+ assert_eq!(
+ thread.notices(),
+ notices
+ .iter()
+ .cloned()
+ .enumerate()
+ .filter(|(id, _)| *id != 1)
+ .collect::<Vec<_>>()
+ );
+ });
+
+ thread.update(cx, |thread, cx| thread.dismiss_notice(1, cx));
+ assert_eq!(*notice_events.borrow(), notices.len() + 1);
+
+ thread.update(cx, |thread, cx| {
+ for notice_id in 0..notices.len() {
+ thread.dismiss_notice(notice_id, cx);
+ }
+ assert!(thread.notices().is_empty());
+ thread
+ .handle_session_update(acp::SessionUpdate::Notice(warning.clone()), cx)
+ .expect("a repeated notice is a new live event");
+ thread.dismiss_notice(1, cx);
+ assert_eq!(thread.notices(), &[(notices.len(), warning)]);
+ assert!(thread.entries().is_empty());
+ assert!(thread.to_markdown(cx).is_empty());
+ });
+ assert_eq!(*notice_events.borrow(), notices.len() * 2 + 1);
+ }
+
+ #[gpui::test]
+ async fn test_session_notice_error_does_not_interrupt_prompt(cx: &mut TestAppContext) {
+ init_test(cx);
+
+ let fs = FakeFs::new(cx.executor());
+ let project = Project::test(fs, [], cx).await;
+ let connection = Rc::new(FakeAgentConnection::new().on_user_message(
+ |_, thread, mut cx| {
+ async move {
+ thread.update(&mut cx, |thread, cx| {
+ assert_eq!(thread.status(), ThreadStatus::Generating);
+ let history_before_notice = thread.to_markdown(cx);
+ let entry_count = thread.entries().len();
+ thread.handle_session_update(
+ acp::SessionUpdate::Notice(
+ acp::Notice::new(
+ acp::NoticeSeverity::Error,
+ "Optional integration failed",
+ )
+ .description("Work will continue without the integration."),
+ ),
+ cx,
+ )?;
+ assert_eq!(thread.status(), ThreadStatus::Generating);
+ assert!(!thread.had_error());
+ assert_eq!(thread.entries().len(), entry_count);
+ assert_eq!(thread.to_markdown(cx), history_before_notice);
+ thread.handle_session_update(
+ acp::SessionUpdate::AgentMessageChunk(acp::ContentChunk::new(
+ "The response continues.".into(),
+ )),
+ cx,
+ )
+ })??;
+ Ok(acp::PromptResponse::new(acp::StopReason::EndTurn))
+ }
+ .boxed_local()
+ },
+ ));
+ let thread = cx
+ .update(|cx| {
+ connection.new_session(project, PathList::new(&[Path::new(path!("/test"))]), cx)
+ })
+ .await
+ .expect("session should be created");
+
+ thread
+ .update(cx, |thread, cx| thread.send_raw("hello", cx))
+ .await
+ .expect("advisory errors must not fail prompts");
+
+ thread.read_with(cx, |thread, cx| {
+ assert_eq!(thread.status(), ThreadStatus::Idle);
+ assert!(!thread.had_error());
+ assert_eq!(thread.notices().len(), 1);
+ assert_eq!(thread.entries().len(), 2);
+ assert!(thread.to_markdown(cx).contains("The response continues."));
+ assert!(
+ !thread
+ .to_markdown(cx)
+ .contains("Optional integration failed")
+ );
+ });
+ }
+
#[gpui::test]
async fn test_usage_update_populates_token_usage_and_cost(cx: &mut TestAppContext) {
init_test(cx);
diff --git a/crates/agent_servers/src/acp.rs b/crates/agent_servers/src/acp.rs
index 854b406274a..b0165c90199 100644
--- a/crates/agent_servers/src/acp.rs
+++ b/crates/agent_servers/src/acp.rs
@@ -616,7 +616,9 @@ fn client_capabilities_for_agent(
.boolean(acp::BooleanConfigOptionCapabilities::new()),
);
if beta_features_enabled {
- session_capabilities = session_capabilities.compaction(acp::CompactionCapabilities::new());
+ session_capabilities = session_capabilities
+ .compaction(acp::CompactionCapabilities::new())
+ .notices(acp::NoticeCapabilities::new());
}
acp::ClientCapabilities::new()
@@ -2791,8 +2793,8 @@ mod tests {
}
#[test]
- fn client_capabilities_only_include_compaction_with_acp_beta() {
- for (beta_enabled, expected_compaction) in
+ fn client_capabilities_gate_compaction_and_notices_with_acp_beta() {
+ for (beta_enabled, expected_capability) in
[(false, None), (true, Some(serde_json::json!({})))]
{
let capabilities =
@@ -2802,7 +2804,13 @@ mod tests {
let session = capabilities
.get("session")
.expect("session capabilities should be advertised");
- assert_eq!(session.get("compaction"), expected_compaction.as_ref());
+ for capability in ["compaction", "notices"] {
+ assert_eq!(
+ session.get(capability),
+ expected_capability.as_ref(),
+ "{capability} with ACP beta enabled: {beta_enabled}"
+ );
+ }
}
}
@@ -3884,7 +3892,11 @@ exit 7
.expect("failed to receive ACP connection handle");
let response = client_conn
- .send_request(acp::InitializeRequest::new(ProtocolVersion::V1))
+ .send_request(
+ acp::InitializeRequest::new(ProtocolVersion::V1).client_capabilities(
+ client_capabilities_for_agent(&AgentId::new("fake-agent"), true),
+ ),
+ )
.block_task()
.await
.expect("failed to initialize ACP connection");
@@ -4023,6 +4035,94 @@ exit 7
);
}
+ #[gpui::test]
+ async fn test_session_notices_are_scoped_and_not_restored_on_reload(
+ cx: &mut gpui::TestAppContext,
+ ) {
+ let (
+ connection,
+ project,
+ _load_count,
+ _close_count,
+ load_session_updates,
+ _load_session_gate,
+ _keep_agent_alive,
+ ) = connect_fake_agent(cx).await;
+
+ let notice_update: acp::SessionUpdate = serde_json::from_value(serde_json::json!({
+ "sessionUpdate": "notice",
+ "severity": "_custom",
+ "title": "A current advisory",
+ "description": null,
+ "_meta": null,
+ }))
+ .expect("unknown notice severity should deserialize");
+ // An agent may emit a fresh notice about a current condition while reconnecting.
+ *load_session_updates
+ .lock()
+ .expect("load_session_updates mutex poisoned") = vec![notice_update];
+
+ let session_id = acp::SessionId::new("session-with-notice");
+ let work_dirs = util::path_list::PathList::new(&[std::path::Path::new("/a")]);
+ let thread = cx
+ .update(|cx| {
+ connection.clone().load_session(
+ session_id.clone(),
+ project.clone(),
+ work_dirs.clone(),
+ None,
+ cx,
+ )
+ })
+ .await
+ .expect("session should load");
+ cx.run_until_parked();
+
+ thread.read_with(cx, |thread, cx| {
+ let [(notice_id, notice)] = thread.notices() else {
+ panic!("the live notice should be received before a view is created");
+ };
+ assert_eq!(*notice_id, 0);
+ assert_eq!(notice.title, "A current advisory");
+ assert_eq!(
+ notice.severity,
+ acp::NoticeSeverity::Other("_custom".into())
+ );
+ assert_eq!(notice.description, None);
+ assert_eq!(notice.meta, None);
+ assert!(thread.entries().is_empty());
+ assert!(thread.to_markdown(cx).is_empty());
+ assert!(!thread.had_error());
+ });
+
+ let other_thread = cx
+ .update(|cx| {
+ connection.clone().load_session(
+ acp::SessionId::new("other-session"),
+ project.clone(),
+ work_dirs.clone(),
+ None,
+ cx,
+ )
+ })
+ .await
+ .expect("other session should load");
+ other_thread.read_with(cx, |thread, _| assert!(thread.notices().is_empty()));
+
+ drop(thread);
+ release_dropped_entities(cx);
+ let reloaded_thread = cx
+ .update(|cx| {
+ connection
+ .clone()
+ .load_session(session_id, project, work_dirs, None, cx)
+ })
+ .await
+ .expect("session should reload");
+ cx.run_until_parked();
+ reloaded_thread.read_with(cx, |thread, _| assert!(thread.notices().is_empty()));
+ }
+
// Regression test: per the ACP spec, an agent replays the entire conversation
// history as `session/update` notifications *before* responding to the
// `session/load` request. These notifications must be applied to the
diff --git a/crates/agent_ui/src/agent_diff.rs b/crates/agent_ui/src/agent_diff.rs
index d6ec9ce81e1..b81549dc6fd 100644
--- a/crates/agent_ui/src/agent_diff.rs
+++ b/crates/agent_ui/src/agent_diff.rs
@@ -1470,6 +1470,7 @@ impl AgentDiff {
AcpThreadEvent::TitleUpdated
| AcpThreadEvent::StatusChanged
| AcpThreadEvent::TokenUsageUpdated
+ | AcpThreadEvent::NoticesUpdated
| AcpThreadEvent::SubagentSpawned(_)
| AcpThreadEvent::EntriesRemoved(_)
| AcpThreadEvent::ToolAuthorizationRequested(_)
diff --git a/crates/agent_ui/src/conversation_view.rs b/crates/agent_ui/src/conversation_view.rs
index 37dc733e847..4811335886b 100644
--- a/crates/agent_ui/src/conversation_view.rs
+++ b/crates/agent_ui/src/conversation_view.rs
@@ -309,8 +309,8 @@ impl Conversation {
let subscription = cx.subscribe(&thread, {
let session_id = session_id.clone();
move |this, _thread, event, _cx| {
- this.updated_at = Some(Instant::now());
match event {
+ AcpThreadEvent::NoticesUpdated => return,
AcpThreadEvent::ToolAuthorizationRequested(id) => {
this.add_permission_request(&session_id, id);
}
@@ -355,6 +355,7 @@ impl Conversation {
| AcpThreadEvent::WorkingDirectoriesUpdated
| AcpThreadEvent::PromptUpdated => {}
}
+ this.updated_at = Some(Instant::now());
}
});
self.subscriptions.push(subscription);
@@ -621,6 +622,7 @@ fn affects_thread_metadata(event: &AcpThreadEvent) -> bool {
| AcpThreadEvent::ModeUpdated(_)
| AcpThreadEvent::ConfigOptionsUpdated(_)
| AcpThreadEvent::SubagentSpawned(_)
+ | AcpThreadEvent::NoticesUpdated
| AcpThreadEvent::PromptUpdated => false,
}
}
@@ -1906,6 +1908,11 @@ impl ConversationView {
AcpThreadEvent::WorkingDirectoriesUpdated => {
cx.notify();
}
+ AcpThreadEvent::NoticesUpdated => {
+ if let Some(thread_view) = self.thread_view(&session_id) {
+ thread_view.update(cx, |_, cx| cx.notify());
+ }
+ }
AcpThreadEvent::PromptUpdated => {
if !is_subagent && thread.read(cx).is_draft_thread() {
self.schedule_draft_prompt_persist(cx);
@@ -4382,6 +4389,248 @@ pub(crate) mod tests {
);
}
+ #[gpui::test]
+ async fn test_session_notices_render_and_dismiss_outside_transcript(cx: &mut TestAppContext) {
+ init_test(cx);
+
+ let (conversation_view, cx) =
+ setup_conversation_view(StubAgentServer::new(StubAgentConnection::new()), cx).await;
+ add_to_workspace_with_size(conversation_view.clone(), true, cx);
+ let thread_view = active_thread(&conversation_view, cx);
+ let thread = thread_view.read_with(cx, |view, _| view.thread.clone());
+ let notice = acp::Notice::new(acp::NoticeSeverity::Error, "Optional integration failed")
+ .description("**Plain text**, not Markdown. Work continues.");
+ thread.update(cx, |thread, cx| {
+ for _ in 0..2 {
+ thread
+ .handle_session_update(acp::SessionUpdate::Notice(notice.clone()), cx)
+ .expect("notice should be accepted");
+ }
+ });
+ cx.run_until_parked();
+
+ thread_view.read_with(cx, |view, cx| {
+ assert_eq!(view.list_state.item_count(), 0);
+ assert!(view.thread.read(cx).entries().is_empty());
+ assert!(!view.thread.read(cx).had_error());
+ });
+ let dismiss = cx
+ .debug_bounds("dismiss-session-notice-0")
+ .expect("the first notice should render a dismiss button");
+ assert!(cx.debug_bounds("dismiss-session-notice-1").is_some());
+ cx.simulate_click(dismiss.center(), gpui::Modifiers::default());
+ cx.run_until_parked();
+ thread.read_with(cx, |thread, _| {
+ assert_eq!(thread.notices(), &[(1, notice)]);
+ });
+ assert!(cx.debug_bounds("dismiss-session-notice-0").is_none());
+
+ assert!(cx.debug_bounds("dismiss-session-notice-1").is_some());
+ thread_view.update_in(cx, |view, window, cx| {
+ view.focus_handle(cx).focus(window, cx);
+ window.focus_next(cx);
+ });
+ cx.simulate_keystrokes("enter");
+ cx.simulate_event(gpui::KeyUpEvent {
+ keystroke: gpui::Keystroke::parse("enter").expect("valid keystroke"),
+ });
+ cx.run_until_parked();
+ assert!(cx.debug_bounds("session-notices").is_none());
+ thread_view.update_in(cx, |view, window, cx| {
+ assert!(view.activation_focus_handle(cx).is_focused(window));
+ assert_eq!(view.list_state.item_count(), 0);
+ assert!(view.thread.read(cx).notices().is_empty());
+ });
+ }
+
+ #[gpui::test]
+ async fn test_session_notices_stay_with_background_session_without_metadata_updates(
+ cx: &mut TestAppContext,
+ ) {
+ init_test(cx);
+
+ let connection = StubAgentConnection::new().with_supports_load_session(true);
+ let (conversation_view, cx) =
+ setup_conversation_view(StubAgentServer::new(connection.clone()), cx).await;
+ add_to_workspace_with_size(conversation_view.clone(), true, cx);
+ let root_thread =
+ active_thread(&conversation_view, cx).read_with(cx, |view, _| view.thread.clone());
+ let root_session_id = root_thread.read_with(cx, |thread, _| thread.session_id().clone());
+ let other_session_id = acp::SessionId::new("other-session");
+ conversation_view.update_in(cx, |view, window, cx| {
+ view.load_subagent_session(
+ other_session_id.clone(),
+ root_session_id.clone(),
+ window,
+ cx,
+ );
+ });
+ cx.run_until_parked();
+
+ let baseline_updated_at = Instant::now();
+ conversation_view.update_in(cx, |view, window, cx| {
+ view.set_updated_at(baseline_updated_at, cx);
+ view.navigate_to_thread(other_session_id.clone(), window, cx);
+ });
+ cx.run_until_parked();
+ let metadata_updates = Rc::new(std::cell::Cell::new(0));
+ let _subscription = cx.update(|_, cx| {
+ cx.subscribe(&conversation_view, {
+ let metadata_updates = metadata_updates.clone();
+ move |_, _: &RootThreadUpdated, _| {
+ metadata_updates.set(metadata_updates.get() + 1);
+ }
+ })
+ });
+
+ cx.deactivate_window();
+ cx.update(|_, cx| {
+ connection.send_update(
+ root_session_id.clone(),
+ acp::SessionUpdate::Notice(acp::Notice::new(
+ acp::NoticeSeverity::Error,
+ "Optional integration failed",
+ )),
+ cx,
+ );
+ });
+ cx.run_until_parked();
+ assert!(cx.debug_bounds("session-notices").is_none());
+ assert!(
+ !cx.windows()
+ .iter()
+ .any(|window| window.downcast::<AgentNotification>().is_some())
+ );
+ active_thread(&conversation_view, cx).read_with(cx, |view, cx| {
+ assert_eq!(view.thread.read(cx).session_id(), &other_session_id);
+ assert!(view.thread.read(cx).notices().is_empty());
+ });
+
+ conversation_view.update_in(cx, |view, window, cx| {
+ window.activate_window();
+ view.navigate_to_thread(root_session_id.clone(), window, cx);
+ });
+ cx.run_until_parked();
+ let dismiss = cx
+ .debug_bounds("dismiss-session-notice-0")
+ .expect("the background notice should render when its session becomes active");
+ cx.simulate_click(dismiss.center(), gpui::Modifiers::default());
+ cx.run_until_parked();
+
+ for session_id in [other_session_id, root_session_id] {
+ conversation_view.update_in(cx, |view, window, cx| {
+ view.navigate_to_thread(session_id, window, cx);
+ });
+ cx.run_until_parked();
+ assert!(cx.debug_bounds("session-notices").is_none());
+ }
+ root_thread.read_with(cx, |thread, cx| {
+ assert!(thread.notices().is_empty());
+ assert!(thread.entries().is_empty());
+ assert!(thread.to_markdown(cx).is_empty());
+ assert!(!thread.had_error());
+ });
+ assert_eq!(metadata_updates.get(), 0);
+ assert_eq!(
+ conversation_view.read_with(cx, |view, cx| view.updated_at(cx)),
+ Some(baseline_updated_at)
+ );
+ }
+
+ #[gpui::test]
+ async fn test_session_notices_scroll_without_hiding_composer(cx: &mut TestAppContext) {
+ init_test(cx);
+
+ let (conversation_view, cx) =
+ setup_conversation_view(StubAgentServer::new(StubAgentConnection::new()), cx).await;
+ cx.simulate_resize(size(px(480.), px(480.)));
+ let thread =
+ active_thread(&conversation_view, cx).read_with(cx, |view, _| view.thread.clone());
+ thread.update(cx, |thread, cx| {
+ for index in 0..8 {
+ thread
+ .handle_session_update(
+ acp::SessionUpdate::Notice(
+ acp::Notice::new(
+ acp::NoticeSeverity::Other("_advisory".into()),
+ "The optional documentation integration is unavailable",
+ )
+ .description(if index == 0 {
+ "Work continues using local files instead.\n".repeat(30)
+ } else {
+ "Work continues.\nUsing local files instead.".to_string()
+ }),
+ ),
+ cx,
+ )
+ .expect("notice should be accepted");
+ }
+ });
+ add_to_workspace_with_size(conversation_view.clone(), true, cx);
+ cx.run_until_parked();
+
+ let notices = cx
+ .debug_bounds("session-notices")
+ .expect("notices received before mounting the view should render");
+ let max_height = cx.update(|window, _| rems_from_px(192_f32).to_pixels(window.rem_size()));
+ assert!(notices.size.height <= max_height);
+ cx.simulate_event(gpui::ScrollWheelEvent {
+ position: notices.center(),
+ delta: gpui::ScrollDelta::Pixels(gpui::point(px(0.), px(-10_000.))),
+ modifiers: gpui::Modifiers::default(),
+ touch_phase: gpui::TouchPhase::Moved,
+ });
+ cx.run_until_parked();
+
+ let dismiss = cx
+ .debug_bounds("dismiss-session-notice-7")
+ .expect("the final notice should be reachable by scrolling");
+ assert!(dismiss.center().y >= notices.top());
+ assert!(dismiss.center().y < notices.bottom());
+ cx.simulate_click(dismiss.center(), gpui::Modifiers::default());
+ cx.run_until_parked();
+ thread.read_with(cx, |thread, _| {
+ assert_eq!(thread.notices().len(), 7);
+ assert!(thread.notices().iter().all(|(id, _)| *id != 7));
+ });
+
+ let editor = message_editor(&conversation_view, cx);
+ for expanded in [false, true] {
+ if expanded {
+ thread.update(cx, |thread, cx| {
+ thread
+ .handle_session_update(
+ acp::SessionUpdate::AgentMessageChunk(acp::ContentChunk::new(
+ "Work is continuing.".into(),
+ )),
+ cx,
+ )
+ .expect("message should be accepted");
+ });
+ active_thread(&conversation_view, cx)
+ .update(cx, |view, cx| view.set_editor_is_expanded(true, cx));
+ }
+ editor.update_in(cx, |editor, window, cx| editor.set_text("", window, cx));
+ cx.run_until_parked();
+ let editor_bounds = editor.read_with(cx, |editor, cx| {
+ *editor
+ .editor()
+ .read(cx)
+ .last_bounds()
+ .expect("the composer should be laid out")
+ });
+ let viewport_size = cx.update(|window, _| window.viewport_size());
+ assert!(editor_bounds.size.height > px(20.));
+ assert!(editor_bounds.top() >= px(0.));
+ assert!(editor_bounds.bottom() <= viewport_size.height);
+ assert!(editor_bounds.left() >= px(0.));
+ assert!(editor_bounds.right() <= viewport_size.width);
+ cx.simulate_click(editor_bounds.center(), gpui::Modifiers::default());
+ cx.simulate_keystrokes("c o n t i n u e");
+ assert_eq!(editor.update(cx, |editor, cx| editor.text(cx)), "continue");
+ }
+ }
+
#[gpui::test]
async fn test_acp_server_exit_transitions_conversation_to_load_error_without_panic(
cx: &mut TestAppContext,
diff --git a/crates/agent_ui/src/conversation_view/thread_view.rs b/crates/agent_ui/src/conversation_view/thread_view.rs
index 38dda4b233d..bfefb986bd0 100644
--- a/crates/agent_ui/src/conversation_view/thread_view.rs
+++ b/crates/agent_ui/src/conversation_view/thread_view.rs
@@ -11648,6 +11648,36 @@ impl ThreadView {
)
}
+ fn render_session_notices(&self, cx: &mut Context<Self>) -> Option<AnyElement> {
+ let notices = self.thread.read(cx).notices();
+ if notices.is_empty() {
+ return None;
+ }
+
+ Some(
+ crate::ui::session_notice_list("session-notices")
+ .debug_selector(|| "session-notices".into())
+ .children(notices.iter().map(|(notice_id, notice)| {
+ let notice_id = *notice_id;
+ let thread = self.thread.clone();
+ let focus_handle = self.activation_focus_handle(cx);
+ crate::ui::SessionNotice::new(
+ ("session-notice", notice_id),
+ notice,
+ move |event, window, cx| {
+ thread.update(cx, |thread, cx| {
+ thread.dismiss_notice(notice_id, cx);
+ });
+ if event.is_keyboard() {
+ focus_handle.focus(window, cx);
+ }
+ },
+ )
+ }))
+ .into_any_element(),
+ )
+ }
+
fn render_skill_loading_issues(&self, cx: &mut Context<Self>) -> Vec<Callout> {
let border_position = self.callout_border_position();
@@ -12580,6 +12610,9 @@ impl Render for ThreadView {
.child(conversation)
.children(self.render_multi_root_callout(cx))
.children(self.render_activity_bar(window, cx))
+ .when_some(self.render_session_notices(cx), |this, notices| {
+ this.child(notices)
+ })
.when(self.show_external_source_prompt_warning, |this| {
this.child(self.render_external_source_prompt_warning(cx))
})
diff --git a/crates/agent_ui/src/ui.rs b/crates/agent_ui/src/ui.rs
index d2fbdf7d4c1..2b6e97350d6 100644
--- a/crates/agent_ui/src/ui.rs
+++ b/crates/agent_ui/src/ui.rs
@@ -3,6 +3,7 @@ mod end_trial_upsell;
mod mention_crease;
mod model_selector_components;
mod sandbox_status_tooltip;
+mod session_notice;
mod terminal_tool_header;
mod undo_reject_toast;
@@ -11,6 +12,7 @@ pub use end_trial_upsell::*;
pub use mention_crease::*;
pub use model_selector_components::*;
pub use sandbox_status_tooltip::*;
+pub use session_notice::*;
pub use terminal_tool_header::*;
pub use undo_reject_toast::*;
diff --git a/crates/agent_ui/src/ui/session_notice.rs b/crates/agent_ui/src/ui/session_notice.rs
new file mode 100644
index 00000000000..c20e181c675
--- /dev/null
+++ b/crates/agent_ui/src/ui/session_notice.rs
@@ -0,0 +1,207 @@
+use agent_client_protocol::schema::v1 as acp;
+use component::{Component, ComponentScope, example_group_with_title, single_example};
+use gpui::{AnyElement, App, ClickEvent, ElementId, Stateful, Window, px};
+use ui::{Callout, Color, IconButton, IconName, IconSize, Severity, Tooltip, prelude::*};
+
+#[derive(IntoElement)]
+pub struct SessionNotice {
+ id: ElementId,
+ callout: Callout,
+}
+
+impl SessionNotice {
+ pub fn new(
+ id: impl Into<ElementId>,
+ notice: &acp::Notice,
+ on_dismiss: impl Fn(&ClickEvent, &mut Window, &mut App) + 'static,
+ ) -> Self {
+ let id = id.into();
+ let dismiss_id = id.clone();
+ let (severity, icon) = match &notice.severity {
+ acp::NoticeSeverity::Info => (Severity::Info, Some(IconName::Info)),
+ acp::NoticeSeverity::Warning => (Severity::Warning, Some(IconName::Warning)),
+ acp::NoticeSeverity::Error => (Severity::Error, Some(IconName::XCircle)),
+ _ => (Severity::Info, None),
+ };
+
+ Self {
+ id,
+ callout: Callout::new()
+ .severity(severity)
+ .title(notice.title.clone())
+ .when_some(icon, Callout::icon)
+ .when_some(notice.description.clone(), Callout::description)
+ .scrollable_description(false)
+ .dismiss_action(
+ div()
+ .debug_selector(move || format!("dismiss-{dismiss_id}"))
+ .child(
+ IconButton::new("dismiss", IconName::Close)
+ .icon_size(IconSize::Small)
+ .icon_color(Color::Muted)
+ .aria_label(format!("Dismiss notice: {}", notice.title))
+ .tab_index(0_isize)
+ .tooltip(Tooltip::text("Dismiss Notice"))
+ .on_click(on_dismiss),
+ ),
+ ),
+ }
+ }
+}
+
+impl RenderOnce for SessionNotice {
+ fn render(self, _window: &mut Window, _cx: &mut App) -> impl IntoElement {
+ div().id(self.id).w_full().flex_none().child(self.callout)
+ }
+}
+
+pub fn session_notice_list(id: impl Into<ElementId>) -> Stateful<Div> {
+ v_flex()
+ .id(id)
+ .w_full()
+ .flex_shrink_0()
+ .max_h(rems_from_px(192_f32))
+ .overflow_y_scroll()
+}
+
+fn preview_notice(id: impl Into<ElementId>, notice: acp::Notice) -> AnyElement {
+ SessionNotice::new(id, &notice, |_, _, _| {}).into_any_element()
+}
+
+#[derive(RegisterComponent)]
+pub struct SessionNoticePreview;
+
+impl Component for SessionNoticePreview {
+ fn scope() -> ComponentScope {
+ ComponentScope::Agent
+ }
+
+ fn name() -> &'static str {
+ "Session Notice"
+ }
+
+ fn description() -> &'static str {
+ "Live ACP session notices as rendered above the agent composer. Dismiss buttons are illustrative in these previews."
+ }
+
+ fn preview(_window: &mut Window, _cx: &mut App) -> AnyElement {
+ let detailed = acp::Notice::new(acp::NoticeSeverity::Warning, "MCP server unavailable")
+ .description("Continuing without it. Other integrations are still available.");
+ let long = acp::Notice::new(
+ acp::NoticeSeverity::Warning,
+ "The optional documentation integration is unavailable in this remote environment",
+ )
+ .description(
+ "Work continues using the files in your project.\nThe agent could not connect to the documentation service after several attempts.\n**This is plain text**, not Markdown.",
+ );
+
+ v_flex()
+ .gap_6()
+ .children([
+ example_group_with_title(
+ "Severities",
+ vec![
+ single_example(
+ "Info",
+ preview_notice(
+ "preview-info-notice",
+ acp::Notice::new(acp::NoticeSeverity::Info, "Indexing resumed"),
+ ),
+ )
+ .width(px(640.)),
+ single_example(
+ "Warning with detail",
+ preview_notice("preview-warning-notice", detailed),
+ )
+ .width(px(640.)),
+ single_example(
+ "Error",
+ preview_notice(
+ "preview-error-notice",
+ acp::Notice::new(
+ acp::NoticeSeverity::Error,
+ "Optional integration failed",
+ )
+ .description("Work will continue without this integration."),
+ ),
+ )
+ .width(px(640.)),
+ single_example(
+ "Future severity",
+ preview_notice(
+ "preview-custom-notice",
+ acp::Notice::new(
+ acp::NoticeSeverity::Other("maintenance".into()),
+ "Scheduled maintenance",
+ ),
+ ),
+ )
+ .width(px(640.)),
+ single_example(
+ "Custom severity",
+ preview_notice(
+ "preview-extension-notice",
+ acp::Notice::new(
+ acp::NoticeSeverity::Other("_agent_advisory".into()),
+ "Using the workspace configuration",
+ )
+ .description("Agent-specific and future severities use the same generic presentation."),
+ ),
+ )
+ .width(px(640.)),
+ ],
+ )
+ .vertical()
+ .into_any_element(),
+ example_group_with_title(
+ "Layout",
+ vec![
+ single_example("Narrow", preview_notice("preview-narrow-notice", long))
+ .width(px(320.)),
+ single_example(
+ "Notice stack",
+ session_notice_list("preview-notice-stack")
+ .children([
+ preview_notice(
+ "preview-stack-info",
+ acp::Notice::new(
+ acp::NoticeSeverity::Info,
+ "Connected to the remote environment",
+ ),
+ ),
+ preview_notice(
+ "preview-stack-warning",
+ acp::Notice::new(
+ acp::NoticeSeverity::Warning,
+ "Network performance is degraded",
+ )
+ .description("Responses may take longer than usual."),
+ ),
+ ])
+ .into_any_element(),
+ )
+ .width(px(640.)),
+ single_example(
+ "Overflowing notice stack",
+ session_notice_list("preview-overflow-notice-stack")
+ .children((0..6_usize).map(|index| {
+ preview_notice(
+ ("preview-repeated-notice", index),
+ acp::Notice::new(
+ acp::NoticeSeverity::Warning,
+ "MCP server unavailable",
+ )
+ .description("Continuing without it. Repeated notices are shown as separate events."),
+ )
+ }))
+ .into_any_element(),
+ )
+ .width(px(320.)),
+ ],
+ )
+ .vertical()
+ .into_any_element(),
+ ])
+ .into_any_element()
+ }
+}
diff --git a/crates/ui/src/components/callout.rs b/crates/ui/src/components/callout.rs
index d270aa19f81..46bbb58a1d1 100644
--- a/crates/ui/src/components/callout.rs
+++ b/crates/ui/src/components/callout.rs
@@ -35,6 +35,7 @@ pub struct Callout {
dismiss_action: Option<AnyElement>,
line_height: Option<Pixels>,
border_position: CalloutBorderPosition,
+ scrollable_description: bool,
}
impl Callout {
@@ -50,6 +51,7 @@ impl Callout {
dismiss_action: None,
line_height: None,
border_position: CalloutBorderPosition::Top,
+ scrollable_description: true,
}
}
@@ -78,6 +80,12 @@ impl Callout {
self
}
+ /// Disable internal scrolling when a surrounding container scrolls the entire callout.
+ pub fn scrollable_description(mut self, scrollable: bool) -> Self {
+ self.scrollable_description = scrollable;
+ self
+ }
+
/// Allows for any element—like markdown elements—to fill the description slot of the callout.
/// This method wins over `description` if both happen to be set.
pub fn description_slot(mut self, description: impl IntoElement) -> Self {
@@ -198,9 +206,9 @@ impl RenderOnce for Callout {
let base_desc_container = div()
.id("callout-description-slot")
.w_full()
- .max_h_32()
- .flex_1()
- .overflow_y_scroll()
+ .when(self.scrollable_description, |this| {
+ this.max_h_32().flex_1().overflow_y_scroll()
+ })
.text_ui_sm(cx);
if let Some(description_slot) = self.description_slot {