Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
acp_thread: Remove completed plan cards from conversation history (#64719)
Ben Brandt99f947e5f620
diff --git a/crates/acp_thread/src/acp_thread.rs b/crates/acp_thread/src/acp_thread.rsindex 993a30f3f90..16335b870ca 100644--- a/crates/acp_thread/src/acp_thread.rs+++ b/crates/acp_thread/src/acp_thread.rs@@ -396,7 +396,6 @@ pub enum AgentThreadEntry {AssistantMessage(AssistantMessage),ToolCall(ToolCall),Elicitation(ElicitationEntryId),- CompletedPlan(Vec<PlanEntry>),ContextCompaction(ContextCompaction),}@@ -849,7 +848,6 @@ impl AgentThreadEntry {Self::AssistantMessage(message) => message.indented,Self::ToolCall(_) => false,Self::Elicitation(_) => false,- Self::CompletedPlan(_) => false,Self::ContextCompaction(_) => false,}}@@ -860,14 +858,6 @@ impl AgentThreadEntry {Self::AssistantMessage(message) => message.to_markdown(cx),Self::ToolCall(tool_call) => tool_call.to_markdown(cx),Self::Elicitation(_) => "## Input Requested\n\n".to_string(),- Self::CompletedPlan(entries) => {- let mut md = String::from("## Plan\n\n");- for entry in entries {- let source = entry.content.read(cx).source().to_string();- md.push_str(&format!("- [x] {}\n", source));- }- md- }Self::ContextCompaction(compaction) => {let status = match &compaction.status {ContextCompactionStatus::InProgress => "In Progress",@@ -2933,7 +2923,6 @@ impl AcpThread {AgentThreadEntry::ToolCall(_)| AgentThreadEntry::Elicitation(_)| AgentThreadEntry::AssistantMessage(_)- | AgentThreadEntry::CompletedPlan(_)| AgentThreadEntry::ContextCompaction(_) => {}}}@@ -2963,7 +2952,6 @@ impl AcpThread {AgentThreadEntry::ToolCall(_)| AgentThreadEntry::Elicitation(_)| AgentThreadEntry::AssistantMessage(_)- | AgentThreadEntry::CompletedPlan(_)| AgentThreadEntry::ContextCompaction(_) => {}}}@@ -2984,7 +2972,6 @@ impl AcpThread {AgentThreadEntry::ToolCall(_)| AgentThreadEntry::Elicitation(_)| AgentThreadEntry::AssistantMessage(_)- | AgentThreadEntry::CompletedPlan(_)| AgentThreadEntry::ContextCompaction(_) => {}}}@@ -2997,7 +2984,6 @@ impl AcpThread {match entry {AgentThreadEntry::UserMessage(..) => return false,AgentThreadEntry::AssistantMessage(..)- | AgentThreadEntry::CompletedPlan(..)| AgentThreadEntry::ContextCompaction(_)| AgentThreadEntry::Elicitation(_) => continue,AgentThreadEntry::ToolCall(..) => return true,@@ -4139,13 +4125,6 @@ impl AcpThread {cx.notify();}- pub fn snapshot_completed_plan(&mut self, cx: &mut Context<Self>) {- if !self.plan.is_empty() && self.plan.stats().pending == 0 {- let completed_entries = std::mem::take(&mut self.plan.entries);- self.push_entry(AgentThreadEntry::CompletedPlan(completed_entries), cx);- }- }-fn clear_completed_plan_entries(&mut self, cx: &mut Context<Self>) {self.plan.entries@@ -4381,10 +4360,6 @@ impl AcpThread {this.cancel_pending_turn_entries(cx);}- if !canceled {- this.snapshot_completed_plan(cx);- }-// Handle refusal - distinguish between user prompt and tool call refusalsif let acp::StopReason::Refusal = r.stop_reason {this.had_error = true;diff --git a/crates/agent/src/agent.rs b/crates/agent/src/agent.rsindex d64f350a7ba..89dc13d6bea 100644--- a/crates/agent/src/agent.rs+++ b/crates/agent/src/agent.rs@@ -1729,9 +1729,6 @@ impl NativeAgent {}).await.map_err(Arc::new)?;- acp_thread.update(cx, |thread, cx| {- thread.snapshot_completed_plan(cx);- });Ok(acp_thread)}})diff --git a/crates/agent_servers/src/acp.rs b/crates/agent_servers/src/acp.rsindex f5ebfd73328..859cf7bbd32 100644--- a/crates/agent_servers/src/acp.rs+++ b/crates/agent_servers/src/acp.rs@@ -4326,7 +4326,6 @@ exit 7acp_thread::AgentThreadEntry::AssistantMessage(_) => "assistant",acp_thread::AgentThreadEntry::ToolCall(_) => "tool_call",acp_thread::AgentThreadEntry::Elicitation(_) => "elicitation",- acp_thread::AgentThreadEntry::CompletedPlan(_) => "plan",acp_thread::AgentThreadEntry::ContextCompaction(_) => "compaction",}).collect::<Vec<_>>()diff --git a/crates/agent_ui/src/conversation_view.rs b/crates/agent_ui/src/conversation_view.rsindex 4811335886b..cb11c7d8895 100644--- a/crates/agent_ui/src/conversation_view.rs+++ b/crates/agent_ui/src/conversation_view.rs@@ -5978,7 +5978,7 @@ pub(crate) mod tests {}#[gpui::test]- async fn test_completed_plan_snapshot_keeps_list_state_in_sync(cx: &mut TestAppContext) {+ async fn test_plan_completion_does_not_add_transcript_entries(cx: &mut TestAppContext) {init_test(cx);let connection = StubAgentConnection::new();@@ -5993,9 +5993,34 @@ pub(crate) mod tests {});cx.run_until_parked();- let session_id = active_thread(&conversation_view, cx).read_with(cx, |view, cx| {- assert_thread_list_item_count_matches_entries(view, cx);- view.thread.read(cx).session_id().clone()+ let (session_id, entry_count) =+ active_thread(&conversation_view, cx).read_with(cx, |view, cx| {+ assert_thread_list_item_count_matches_entries(view, cx);+ let thread = view.thread.read(cx);+ (thread.session_id().clone(), thread.entries().len())+ });++ cx.update(|_, cx| {+ connection.send_update(+ session_id.clone(),+ acp::SessionUpdate::Plan(acp::Plan::new(vec![acp::PlanEntry::new(+ "Do the thing",+ acp::PlanEntryPriority::Medium,+ acp::PlanEntryStatus::InProgress,+ )])),+ cx,+ );+ });+ cx.run_until_parked();+ let plan_content = active_thread(&conversation_view, cx).read_with(cx, |view, cx| {+ view.thread+ .read(cx)+ .plan()+ .entries+ .first()+ .expect("active plan entry")+ .content+ .clone()});cx.update(|_, cx| {@@ -6004,6 +6029,42 @@ pub(crate) mod tests {acp::SessionUpdate::Plan(acp::Plan::new(vec![acp::PlanEntry::new("Do the thing",acp::PlanEntryPriority::Medium,+ acp::PlanEntryStatus::Completed,+ )])),+ cx,+ );+ });+ cx.run_until_parked();+ active_thread(&conversation_view, cx).read_with(cx, |view, cx| {+ assert_thread_list_item_count_matches_entries(view, cx);+ });++ connection.end_turn(session_id.clone(), acp::StopReason::EndTurn);+ cx.run_until_parked();+ active_thread(&conversation_view, cx).read_with(cx, |view, cx| {+ assert_thread_list_item_count_matches_entries(view, cx);+ let thread = view.thread.read(cx);+ assert_eq!(thread.status(), ThreadStatus::Idle);+ assert_eq!(thread.entries().len(), entry_count);+ assert_eq!(thread.plan().stats().completed, 1);+ assert_eq!(thread.plan().stats().pending, 0);+ assert_eq!(+ thread+ .plan()+ .entries+ .first()+ .expect("completed plan entry")+ .content,+ plan_content+ );+ });++ cx.update(|_, cx| {+ connection.send_update(+ session_id.clone(),+ acp::SessionUpdate::Plan(acp::Plan::new(vec![acp::PlanEntry::new(+ "Revise the thing",+ acp::PlanEntryPriority::High,acp::PlanEntryStatus::InProgress,)])),cx,@@ -6012,13 +6073,26 @@ pub(crate) mod tests {cx.run_until_parked();active_thread(&conversation_view, cx).read_with(cx, |view, cx| {assert_thread_list_item_count_matches_entries(view, cx);+ let thread = view.thread.read(cx);+ let entry = thread.plan().entries.first().expect("reopened plan entry");+ assert_eq!(entry.content, plan_content);+ assert_eq!(entry.content.read(cx).source(), "Revise the thing");+ assert_eq!(thread.plan().stats().pending, 1);+ assert_eq!(thread.entries().len(), entry_count);});+ active_thread(&conversation_view, cx).update(cx, |view, cx| {+ view.thread.update(cx, |thread, cx| {+ thread.clear_plan(cx);+ assert!(thread.plan().is_empty());+ assert_eq!(thread.entries().len(), entry_count);+ });+ });cx.update(|_, cx| {connection.send_update(session_id.clone(),acp::SessionUpdate::Plan(acp::Plan::new(vec![acp::PlanEntry::new(- "Do the thing",+ "Another task",acp::PlanEntryPriority::Medium,acp::PlanEntryStatus::Completed,)])),@@ -6027,14 +6101,22 @@ pub(crate) mod tests {});cx.run_until_parked();active_thread(&conversation_view, cx).read_with(cx, |view, cx| {- assert_thread_list_item_count_matches_entries(view, cx);+ assert_eq!(view.thread.read(cx).plan().stats().completed, 1);});- connection.end_turn(session_id, acp::StopReason::EndTurn);+ message_editor(&conversation_view, cx).update_in(cx, |editor, window, cx| {+ editor.set_text("Continue", window, cx);+ });+ active_thread(&conversation_view, cx).update_in(cx, |view, window, cx| {+ view.send(window, cx);+ });cx.run_until_parked();active_thread(&conversation_view, cx).read_with(cx, |view, cx| {assert_thread_list_item_count_matches_entries(view, cx);+ assert!(view.thread.read(cx).plan().is_empty());});+ connection.end_turn(session_id, acp::StopReason::EndTurn);+ cx.run_until_parked();}async fn setup_conversation_view_with_initial_content(diff --git a/crates/agent_ui/src/conversation_view/thread_search_bar.rs b/crates/agent_ui/src/conversation_view/thread_search_bar.rsindex b89a0f3f629..9fad3704f55 100644--- a/crates/agent_ui/src/conversation_view/thread_search_bar.rs+++ b/crates/agent_ui/src/conversation_view/thread_search_bar.rs@@ -918,9 +918,6 @@ fn collect_markdowns();}}- AgentThreadEntry::CompletedPlan(entries) => {- out.extend(entries.iter().map(|e| e.content.clone()))- }AgentThreadEntry::ContextCompaction(compaction) => out.extend(compaction_markdowns(compaction,entry_view_state.is_compaction_expanded(entry_ix),diff --git a/crates/agent_ui/src/conversation_view/thread_view.rs b/crates/agent_ui/src/conversation_view/thread_view.rsindex f936430759a..b384c158c3d 100644--- a/crates/agent_ui/src/conversation_view/thread_view.rs+++ b/crates/agent_ui/src/conversation_view/thread_view.rs@@ -1,6 +1,5 @@use crate::{DEFAULT_THREAD_TITLE, SelectPermissionGranularity,- agent_configuration::configure_context_server_modal::default_markdown_style,conversation_view::thread_search_bar::{ThreadSearchBar, ThreadSearchBarEvent},open_abs_path_at_point,thread_metadata_store::{ThreadId, ThreadMetadataStore},@@ -9,7 +8,7 @@ use agent_client_protocol::schema::v1 as acp;use std::cell::RefCell;use acp_thread::{- Elicitation, ElicitationEntryId, ElicitationStatus, PlanEntry, SandboxAuthorizationDetails,+ Elicitation, ElicitationEntryId, ElicitationStatus, SandboxAuthorizationDetails,SandboxFallbackAuthorizationDetails, SandboxNotAppliedReason, decode_path_escapes,};use agent::{@@ -3867,76 +3866,6 @@ impl ThreadView {.into_any_element()}- fn render_completed_plan(- &self,- entries: &[PlanEntry],- window: &Window,- cx: &Context<Self>,- ) -> AnyElement {- v_flex()- .px_5()- .py_1p5()- .w_full()- .child(- v_flex()- .w_full()- .rounded_md()- .border_1()- .border_color(self.tool_card_border_color(cx))- .child(- h_flex()- .px_2()- .py_1()- .gap_1()- .bg(self.tool_card_header_bg(cx))- .border_b_1()- .border_color(self.tool_card_border_color(cx))- .child(- Label::new("Completed Plan")- .size(LabelSize::Small)- .color(Color::Muted),- )- .child(- Label::new(format!(- "— {} {}",- entries.len(),- if entries.len() == 1 { "step" } else { "steps" }- ))- .size(LabelSize::Small)- .color(Color::Muted),- ),- )- .child(- v_flex().children(entries.iter().enumerate().map(|(index, entry)| {- h_flex()- .py_1()- .px_2()- .gap_1p5()- .when(index < entries.len() - 1, |this| {- this.border_b_1().border_color(cx.theme().colors().border)- })- .child(- Icon::new(IconName::TodoComplete)- .size(IconSize::Small)- .color(Color::Success),- )- .child(- div()- .max_w_full()- .overflow_x_hidden()- .text_xs()- .text_color(cx.theme().colors().text_muted)- .child(MarkdownElement::new(- entry.content.clone(),- default_markdown_style(window, cx),- )),- )- })),- ),- )- .into_any()- }-fn render_context_compaction(&self,entry_ix: usize,@@ -6468,9 +6397,6 @@ impl ThreadView {Empty.into_any()}}- AgentThreadEntry::CompletedPlan(entries) => {- self.render_completed_plan(entries, window, cx)- }AgentThreadEntry::ContextCompaction(compaction) => {self.render_context_compaction(entry_ix, compaction, window, cx)}@@ -7788,7 +7714,6 @@ impl ThreadView {AgentThreadEntry::ToolCall(_)| AgentThreadEntry::Elicitation(_)| AgentThreadEntry::AssistantMessage(_)- | AgentThreadEntry::CompletedPlan(_)| AgentThreadEntry::ContextCompaction(_) => {}}}diff --git a/crates/agent_ui/src/entry_view_state.rs b/crates/agent_ui/src/entry_view_state.rsindex 9a22ead900d..4532d4ec18e 100644--- a/crates/agent_ui/src/entry_view_state.rs+++ b/crates/agent_ui/src/entry_view_state.rs@@ -414,11 +414,6 @@ impl EntryViewState {};entry.sync(message);}- AgentThreadEntry::CompletedPlan(_) => {- if !matches!(self.entries.get(index), Some(Entry::CompletedPlan)) {- self.set_entry(index, Entry::CompletedPlan);- }- }AgentThreadEntry::ContextCompaction(_) => {if !matches!(self.entries.get(index), Some(Entry::ContextCompaction)) {self.set_entry(index, Entry::ContextCompaction);@@ -470,7 +465,6 @@ impl EntryViewState {Entry::UserMessage { .. }| Entry::AssistantMessage { .. }| Entry::Elicitation { .. }- | Entry::CompletedPlan| Entry::ContextCompaction => {}Entry::ToolCall(ToolCallEntry { content, .. }) => {for view in content.values() {@@ -540,7 +534,6 @@ pub enum Entry {AssistantMessage(AssistantMessageEntry),ToolCall(ToolCallEntry),Elicitation { focus_handle: FocusHandle },- CompletedPlan,ContextCompaction,}@@ -551,7 +544,7 @@ impl Entry {Self::AssistantMessage(message) => Some(message.focus_handle.clone()),Self::ToolCall(tool_call) => Some(tool_call.focus_handle.clone()),Self::Elicitation { focus_handle } => Some(focus_handle.clone()),- Self::CompletedPlan | Self::ContextCompaction => None,+ Self::ContextCompaction => None,}}@@ -561,7 +554,6 @@ impl Entry {Self::AssistantMessage(_)| Self::ToolCall(_)| Self::Elicitation { .. }- | Self::CompletedPlan| Self::ContextCompaction => None,}}@@ -592,7 +584,6 @@ impl Entry {Self::UserMessage(_)| Self::ToolCall(_)| Self::Elicitation { .. }- | Self::CompletedPlan| Self::ContextCompaction => None,}}@@ -611,7 +602,6 @@ impl Entry {Self::UserMessage(_)| Self::AssistantMessage(_)| Self::Elicitation { .. }- | Self::CompletedPlan| Self::ContextCompaction => false,}}@@ -630,7 +620,7 @@ impl Focusable for Entry {Self::AssistantMessage(message) => message.focus_handle.clone(),Self::ToolCall(tool_call) => tool_call.focus_handle.clone(),Self::Elicitation { focus_handle } => focus_handle.clone(),- Self::CompletedPlan | Self::ContextCompaction => cx.focus_handle(),+ Self::ContextCompaction => cx.focus_handle(),}}}