Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Improve Zed agent thread history to update across all open windows (#47803)
Joseph T. Lyons081bb237f432
diff --git a/crates/agent/src/thread_store.rs b/crates/agent/src/thread_store.rsindex 3a8dd6690f9..cd7c03de546 100644--- a/crates/agent/src/thread_store.rs+++ b/crates/agent/src/thread_store.rs@@ -1,10 +1,14 @@use crate::{DbThread, DbThreadMetadata, ThreadsDatabase};use agent_client_protocol as acp;use anyhow::{Result, anyhow};-use gpui::{App, Context, Entity, Task, prelude::*};+use gpui::{App, Context, Entity, Global, Task, prelude::*};use project::Project;use std::rc::Rc;+struct GlobalThreadStore(Entity<ThreadStore>);++impl Global for GlobalThreadStore {}+// TODO: Remove once ACP thread loading is fully handled elsewhere.pub fn load_agent_thread(session_id: acp::SessionId,@@ -37,6 +41,15 @@ pub struct ThreadStore {}impl ThreadStore {+ pub fn init_global(cx: &mut App) {+ let thread_store = cx.new(|cx| Self::new(cx));+ cx.set_global(GlobalThreadStore(thread_store));+ }++ pub fn global(cx: &App) -> Entity<Self> {+ cx.global::<GlobalThreadStore>().0.clone()+ }+pub fn new(cx: &mut Context<Self>) -> Self {let this = Self {threads: Vec::new(),diff --git a/crates/agent_ui/src/agent_panel.rs b/crates/agent_ui/src/agent_panel.rsindex 766744907b6..aca4386a147 100644--- a/crates/agent_ui/src/agent_panel.rs+++ b/crates/agent_ui/src/agent_panel.rs@@ -507,7 +507,7 @@ impl AgentPanel {let context_server_registry =cx.new(|cx| ContextServerRegistry::new(project.read(cx).context_server_store(), cx));- let thread_store = cx.new(|cx| ThreadStore::new(cx));+ let thread_store = ThreadStore::global(cx);let acp_history = cx.new(|cx| AcpThreadHistory::new(None, window, cx));let text_thread_history =cx.new(|cx| TextThreadHistory::new(text_thread_store.clone(), window, cx));diff --git a/crates/agent_ui/src/agent_ui.rs b/crates/agent_ui/src/agent_ui.rsindex bb39ce96c34..62d22c9a22f 100644--- a/crates/agent_ui/src/agent_ui.rs+++ b/crates/agent_ui/src/agent_ui.rs@@ -256,6 +256,7 @@ pub fn init(is_eval: bool,cx: &mut App,) {+ agent::ThreadStore::init_global(cx);assistant_text_thread::init(client, cx);rules_library::init(cx);if !is_eval {diff --git a/crates/agent_ui_v2/src/agents_panel.rs b/crates/agent_ui_v2/src/agents_panel.rsindex f8e223ffbf8..3f56704850b 100644--- a/crates/agent_ui_v2/src/agents_panel.rs+++ b/crates/agent_ui_v2/src/agents_panel.rs@@ -124,7 +124,7 @@ impl AgentsPanel {) -> Self {let focus_handle = cx.focus_handle();- let thread_store = cx.new(|cx| ThreadStore::new(cx));+ let thread_store = ThreadStore::global(cx);let history = cx.new(|cx| AcpThreadHistory::new(None, window, cx));let history_handle = history.clone();