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: Keep inline review on the root thread when subagents appear (#66093)

Ben Brandt78f5a535a3b4
diff --git a/crates/agent_ui/src/agent_diff.rs b/crates/agent_ui/src/agent_diff.rs
index 31d22a5b78b..b79651c4a12 100644
--- a/crates/agent_ui/src/agent_diff.rs
+++ b/crates/agent_ui/src/agent_diff.rs
@@ -1309,6 +1309,19 @@ impl AgentDiff {
});
}
+ #[cfg(test)]
+ pub(crate) fn reviewed_thread(
+ workspace: &WeakEntity<Workspace>,
+ cx: &mut App,
+ ) -> Option<Entity<AcpThread>> {
+ Self::global(cx)
+ .read(cx)
+ .workspace_threads
+ .get(workspace)?
+ .thread
+ .upgrade()
+ }
+
fn register_active_thread_impl(
&mut self,
workspace: &WeakEntity<Workspace>,
diff --git a/crates/agent_ui/src/conversation_view.rs b/crates/agent_ui/src/conversation_view.rs
index 6096e43ba1c..31955752cd3 100644
--- a/crates/agent_ui/src/conversation_view.rs
+++ b/crates/agent_ui/src/conversation_view.rs
@@ -1624,7 +1624,11 @@ impl ConversationView {
list_state.scroll_to_end();
}
- AgentDiff::set_active_thread(&self.workspace, thread.clone(), window, cx);
+ // A subagent's edits are also recorded in its parent's action log, so reviewing the
+ // root thread covers the whole conversation.
+ if thread.read(cx).parent_session_id().is_none() {
+ AgentDiff::set_active_thread(&self.workspace, thread.clone(), window, cx);
+ }
let connection = thread.read(cx).connection().clone();
let session_id = thread.read(cx).session_id().clone();
@@ -6796,6 +6800,51 @@ pub(crate) mod tests {
});
}
+ #[gpui::test]
+ async fn test_subagent_views_keep_the_root_thread_under_review(cx: &mut TestAppContext) {
+ init_test(cx);
+ let connection = StubAgentConnection::new();
+ let (conversation_view, cx) =
+ setup_conversation_view(StubAgentServer::new(connection.clone()), cx).await;
+ let root =
+ active_thread(&conversation_view, cx).read_with(cx, |view, _| view.thread.clone());
+ let root_session_id = root.read_with(cx, |thread, _| thread.session_id().clone());
+ let workspace = conversation_view.read_with(cx, |view, _| view.workspace.clone());
+ let reviewed_thread = |cx: &mut VisualTestContext| {
+ cx.update(|_, cx| AgentDiff::reviewed_thread(&workspace, cx))
+ };
+ assert_eq!(reviewed_thread(cx).as_ref(), Some(&root));
+
+ let child = conversation_view.update(cx, |view, cx| {
+ create_test_acp_thread(
+ Some(root_session_id),
+ "child",
+ Rc::new(connection.clone()),
+ view.project.clone(),
+ cx,
+ )
+ });
+ root.update(cx, |root, cx| root.register_subagent(child.clone(), cx));
+ cx.run_until_parked();
+ assert!(
+ conversation_view.read_with(cx, |view, _| view
+ .thread_view(&acp_v2::SessionId::new("child"))
+ .is_some()),
+ "the subagent got its view"
+ );
+ assert_eq!(reviewed_thread(cx).as_ref(), Some(&root));
+
+ conversation_view.update_in(cx, |view, window, cx| {
+ view.navigate_to_thread(acp_v2::SessionId::new("child"), window, cx)
+ });
+ cx.run_until_parked();
+ assert_eq!(
+ reviewed_thread(cx).as_ref(),
+ Some(&root),
+ "opening a subagent keeps the conversation's edits under review"
+ );
+ }
+
#[gpui::test]
async fn test_subagent_card_state_follows_the_spawn_tool_call(cx: &mut TestAppContext) {
use super::subagent_card::{SubagentCardState, SubagentEntries, SubagentStatus};