diff --git a/crates/agent/src/db.rs b/crates/agent/src/db.rs index 14ec9bb9af92c2f9720af5714c7344b986f5f7b5..fa4b37dba3e789b499bfe5db4f0b76ccf12e5a09 100644 --- a/crates/agent/src/db.rs +++ b/crates/agent/src/db.rs @@ -23,17 +23,6 @@ pub type DbMessage = crate::Message; pub type DbSummary = crate::legacy_thread::DetailedSummaryState; pub type DbLanguageModel = crate::legacy_thread::SerializedLanguageModel; -/// Metadata about the git worktree associated with an agent thread. -#[derive(Debug, Clone, Serialize, Deserialize)] -pub struct AgentGitWorktreeInfo { - /// The branch name in the git worktree. - pub branch: String, - /// Absolute path to the git worktree on disk. - pub worktree_path: std::path::PathBuf, - /// The base branch/commit the worktree was created from. - pub base_ref: String, -} - #[derive(Debug, Clone, Serialize, Deserialize)] pub struct DbThreadMetadata { pub id: acp::SessionId, @@ -41,10 +30,6 @@ pub struct DbThreadMetadata { #[serde(alias = "summary")] pub title: SharedString, pub updated_at: DateTime, - /// Denormalized from `DbThread::git_worktree_info.branch` for efficient - /// listing without decompressing thread data. The blob is the source of - /// truth; this column is populated on save for query convenience. - pub worktree_branch: Option, } #[derive(Debug, Serialize, Deserialize)] @@ -68,8 +53,6 @@ pub struct DbThread { pub imported: bool, #[serde(default)] pub subagent_context: Option, - #[serde(default)] - pub git_worktree_info: Option, } #[derive(Debug, Clone, Serialize, Deserialize)] @@ -108,7 +91,6 @@ impl SharedThread { profile: None, imported: true, subagent_context: None, - git_worktree_info: None, } } @@ -283,7 +265,6 @@ impl DbThread { profile: thread.profile, imported: false, subagent_context: None, - git_worktree_info: None, }) } } @@ -388,13 +369,6 @@ impl ThreadsDatabase { s().ok(); } - if let Ok(mut s) = connection.exec(indoc! {" - ALTER TABLE threads ADD COLUMN worktree_branch TEXT - "}) - { - s().ok(); - } - let db = Self { executor, connection: Arc::new(Mutex::new(connection)), @@ -423,10 +397,6 @@ impl ThreadsDatabase { .subagent_context .as_ref() .map(|ctx| ctx.parent_thread_id.0.clone()); - let worktree_branch = thread - .git_worktree_info - .as_ref() - .map(|info| info.branch.clone()); let json_data = serde_json::to_string(&SerializedThread { thread, version: DbThread::VERSION, @@ -438,19 +408,11 @@ impl ThreadsDatabase { let data_type = DataType::Zstd; let data = compressed; - let mut insert = connection.exec_bound::<(Arc, Option>, Option, String, String, DataType, Vec)>(indoc! {" - INSERT OR REPLACE INTO threads (id, parent_id, worktree_branch, summary, updated_at, data_type, data) VALUES (?, ?, ?, ?, ?, ?, ?) + let mut insert = connection.exec_bound::<(Arc, Option>, String, String, DataType, Vec)>(indoc! {" + INSERT OR REPLACE INTO threads (id, parent_id, summary, updated_at, data_type, data) VALUES (?, ?, ?, ?, ?, ?) "})?; - insert(( - id.0, - parent_id, - worktree_branch, - title, - updated_at, - data_type, - data, - ))?; + insert((id.0, parent_id, title, updated_at, data_type, data))?; Ok(()) } @@ -462,20 +424,19 @@ impl ThreadsDatabase { let connection = connection.lock(); let mut select = connection - .select_bound::<(), (Arc, Option>, Option, String, String)>(indoc! {" - SELECT id, parent_id, worktree_branch, summary, updated_at FROM threads ORDER BY updated_at DESC + .select_bound::<(), (Arc, Option>, String, String)>(indoc! {" + SELECT id, parent_id, summary, updated_at FROM threads ORDER BY updated_at DESC "})?; let rows = select(())?; let mut threads = Vec::new(); - for (id, parent_id, worktree_branch, summary, updated_at) in rows { + for (id, parent_id, summary, updated_at) in rows { threads.push(DbThreadMetadata { id: acp::SessionId::new(id), parent_session_id: parent_id.map(acp::SessionId::new), title: summary.into(), updated_at: DateTime::parse_from_rfc3339(&updated_at)?.with_timezone(&Utc), - worktree_branch, }); } @@ -609,7 +570,6 @@ mod tests { profile: None, imported: false, subagent_context: None, - git_worktree_info: None, } } @@ -753,94 +713,4 @@ mod tests { "Regular threads should have no subagent_context" ); } - - #[gpui::test] - async fn test_git_worktree_info_roundtrip(cx: &mut TestAppContext) { - let database = ThreadsDatabase::new(cx.executor()).unwrap(); - - let thread_id = session_id("worktree-thread"); - let mut thread = make_thread( - "Worktree Thread", - Utc.with_ymd_and_hms(2024, 6, 15, 12, 0, 0).unwrap(), - ); - thread.git_worktree_info = Some(AgentGitWorktreeInfo { - branch: "zed/agent/a4Xiu".to_string(), - worktree_path: std::path::PathBuf::from("/repo/worktrees/zed/agent/a4Xiu"), - base_ref: "main".to_string(), - }); - - database - .save_thread(thread_id.clone(), thread) - .await - .unwrap(); - - let loaded = database - .load_thread(thread_id) - .await - .unwrap() - .expect("thread should exist"); - - let info = loaded - .git_worktree_info - .expect("git_worktree_info should be restored"); - assert_eq!(info.branch, "zed/agent/a4Xiu"); - assert_eq!( - info.worktree_path, - std::path::PathBuf::from("/repo/worktrees/zed/agent/a4Xiu") - ); - assert_eq!(info.base_ref, "main"); - } - - #[gpui::test] - async fn test_session_list_includes_worktree_meta(cx: &mut TestAppContext) { - let database = ThreadsDatabase::new(cx.executor()).unwrap(); - - // Save a thread with worktree info - let worktree_id = session_id("wt-thread"); - let mut worktree_thread = make_thread( - "With Worktree", - Utc.with_ymd_and_hms(2024, 6, 15, 12, 0, 0).unwrap(), - ); - worktree_thread.git_worktree_info = Some(AgentGitWorktreeInfo { - branch: "zed/agent/bR9kz".to_string(), - worktree_path: std::path::PathBuf::from("/repo/worktrees/zed/agent/bR9kz"), - base_ref: "develop".to_string(), - }); - - database - .save_thread(worktree_id.clone(), worktree_thread) - .await - .unwrap(); - - // Save a thread without worktree info - let plain_id = session_id("plain-thread"); - let plain_thread = make_thread( - "Without Worktree", - Utc.with_ymd_and_hms(2024, 6, 15, 11, 0, 0).unwrap(), - ); - - database - .save_thread(plain_id.clone(), plain_thread) - .await - .unwrap(); - - // List threads and verify worktree_branch is populated correctly - let threads = database.list_threads().await.unwrap(); - assert_eq!(threads.len(), 2); - - let wt_entry = threads - .iter() - .find(|t| t.id == worktree_id) - .expect("should find worktree thread"); - assert_eq!(wt_entry.worktree_branch.as_deref(), Some("zed/agent/bR9kz")); - - let plain_entry = threads - .iter() - .find(|t| t.id == plain_id) - .expect("should find plain thread"); - assert!( - plain_entry.worktree_branch.is_none(), - "plain thread should have no worktree_branch" - ); - } } diff --git a/crates/agent/src/thread.rs b/crates/agent/src/thread.rs index f9be3bfbeacfd137b06da7dc99eef7ae34422325..39fef567916eb7d4a7bf04db3a0455bead6eee2f 100644 --- a/crates/agent/src/thread.rs +++ b/crates/agent/src/thread.rs @@ -1,8 +1,8 @@ use crate::{ - AgentGitWorktreeInfo, ContextServerRegistry, CopyPathTool, CreateDirectoryTool, - DbLanguageModel, DbThread, DeletePathTool, DiagnosticsTool, EditFileTool, FetchTool, - FindPathTool, GrepTool, ListDirectoryTool, MovePathTool, NowTool, OpenTool, ProjectSnapshot, - ReadFileTool, RestoreFileFromDiskTool, SaveFileTool, SpawnAgentTool, StreamingEditFileTool, + ContextServerRegistry, CopyPathTool, CreateDirectoryTool, DbLanguageModel, DbThread, + DeletePathTool, DiagnosticsTool, EditFileTool, FetchTool, FindPathTool, GrepTool, + ListDirectoryTool, MovePathTool, NowTool, OpenTool, ProjectSnapshot, ReadFileTool, + RestoreFileFromDiskTool, SaveFileTool, SpawnAgentTool, StreamingEditFileTool, SystemPromptTemplate, Template, Templates, TerminalTool, ToolPermissionDecision, WebSearchTool, decide_permission_from_settings, }; @@ -904,8 +904,6 @@ pub struct Thread { subagent_context: Option, /// Weak references to running subagent threads for cancellation propagation running_subagents: Vec>, - /// Git worktree info if this thread is running in an agent worktree. - git_worktree_info: Option, } impl Thread { @@ -996,7 +994,6 @@ impl Thread { imported: false, subagent_context: None, running_subagents: Vec::new(), - git_worktree_info: None, } } @@ -1221,7 +1218,6 @@ impl Thread { imported: db_thread.imported, subagent_context: db_thread.subagent_context, running_subagents: Vec::new(), - git_worktree_info: db_thread.git_worktree_info, } } @@ -1242,7 +1238,6 @@ impl Thread { profile: Some(self.profile_id.clone()), imported: self.imported, subagent_context: self.subagent_context.clone(), - git_worktree_info: self.git_worktree_info.clone(), }; cx.background_spawn(async move { diff --git a/crates/agent/src/thread_store.rs b/crates/agent/src/thread_store.rs index 8dd1ac36e8f6667ec5ecec2286d85ade2b12ee72..d5526b0953cb4342fcbf3b13a883385dfcf609ea 100644 --- a/crates/agent/src/thread_store.rs +++ b/crates/agent/src/thread_store.rs @@ -133,7 +133,6 @@ mod tests { profile: None, imported: false, subagent_context: None, - git_worktree_info: None, } }