History

agent: Extract unrelated cleanups from worktree-directory branch

- Remove subagent filter from set_title (lazy session lookup) The old code eagerly filtered out subagent threads in set_title. Now it always returns a NativeAgentSessionSetTitle that lazily looks up the session in run(), returning an error if not found. - Remove snake_case conversion for MCP tool name disambiguation Server IDs are now used as-is (to_string) instead of being converted to snake_case via heck. - Remove dead heck dependency from agent crate

Richard Feldman committed 8 months ago

Commit 4ff0d641 parent d60b2915 files · +20 −24Browse files

Unified · Split

5 files
  1. Cargo.lock +0 −1
  2. crates/agent/Cargo.toml +1 −1
  3. crates/agent/src/agent.rs +12 −15
  4. crates/agent/src/tests/mod.rs +3 −3
  5. crates/agent/src/thread.rs +4 −4
Cargo.lock+0−1
@@ -180,7 +180,6 @@ dependencies = [ · 179 unmodified lines
180180 "gpui",
181181 "gpui_tokio",
182182 "handlebars 4.5.0",
183− "heck 0.5.0",
184183 "html_to_markdown",
185184 "http_client",
186185 "indoc",
crates/agent/Cargo.toml+1−1
@@ -38,7 +38,7 @@ futures.workspace = true · 37 unmodified lines
3838 git.workspace = true
3939 gpui.workspace = true
4040 handlebars = { workspace = true, features = ["rust-embed"] }
41−heck.workspace = true
41+
4242 html_to_markdown.workspace = true
4343 http_client.workspace = true
4444 indoc.workspace = true
crates/agent/src/agent.rs+12−15
@@ -1396,19 +1396,12 @@ impl acp_thread::AgentConnection for NativeAgentConnection { · 1395 unmodified lines
13961396 fn set_title(
13971397 &self,
13981398 session_id: &acp::SessionId,
1399− cx: &App,
1399+ _cx: &App,
14001400 ) -> Option<Rc<dyn acp_thread::AgentSessionSetTitle>> {
1401− self.0.read_with(cx, |agent, _cx| {
1402− agent
1403− .sessions
1404− .get(session_id)
1405− .filter(|s| !s.thread.read(cx).is_subagent())
1406− .map(|session| {
1407− Rc::new(NativeAgentSessionSetTitle {
1408− thread: session.thread.clone(),
1409− }) as _
1410− })
1411− })
1401+ Some(Rc::new(NativeAgentSessionSetTitle {
1402+ connection: self.clone(),
1403+ session_id: session_id.clone(),
1404+ }) as _)
14121405 }
14131406
14141407 fn session_list(&self, cx: &mut App) -> Option<Rc<dyn AgentSessionList>> {
@@ -1567,13 +1560,17 @@ impl acp_thread::AgentSessionRetry for NativeAgentSessionRetry { · 152 unmodified lines
15671560 }
15681561
15691562 struct NativeAgentSessionSetTitle {
1570− thread: Entity<Thread>,
1563+ connection: NativeAgentConnection,
1564+ session_id: acp::SessionId,
15711565 }
15721566
15731567 impl acp_thread::AgentSessionSetTitle for NativeAgentSessionSetTitle {
15741568 fn run(&self, title: SharedString, cx: &mut App) -> Task<Result<()>> {
1575− self.thread
1576− .update(cx, |thread, cx| thread.set_title(title, cx));
1569+ let Some(session) = self.connection.0.read(cx).sessions.get(&self.session_id) else {
1570+ return Task::ready(Err(anyhow!("session not found")));
1571+ };
1572+ let thread = session.thread.clone();
1573+ thread.update(cx, |thread, cx| thread.set_title(title, cx));
15771574 Task::ready(Ok(()))
15781575 }
15791576 }
crates/agent/src/tests/mod.rs+3−3
@@ -1828,11 +1828,11 @@ async fn test_mcp_tool_truncation(cx: &mut TestAppContext) { · 1827 unmodified lines
18281828 cx,
18291829 );
18301830
1831− // Server with spaces in name - tests snake_case conversion for API compatibility
1831+ // Server with spaces in name - tests disambiguation with server ID prefix
18321832 let _server4_calls = setup_context_server(
18331833 "Azure DevOps",
18341834 vec![context_server::types::Tool {
1835− name: "echo".into(), // Also conflicts - will be disambiguated as azure_dev_ops_echo
1835+ name: "echo".into(), // Also conflicts - will be disambiguated as Azure DevOps_echo
18361836 description: None,
18371837 input_schema: serde_json::to_value(EchoTool::input_schema(
18381838 LanguageModelToolSchemaFormat::JsonSchema,
@@ -1855,7 +1855,7 @@ async fn test_mcp_tool_truncation(cx: &mut TestAppContext) { · 16 unmodified lines
18551855 assert_eq!(
18561856 tool_names_for_completion(&completion),
18571857 vec![
1858− "azure_dev_ops_echo",
1858+ "Azure DevOps_echo",
18591859 "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
18601860 "cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc",
18611861 "delay",
crates/agent/src/thread.rs+4−4
@@ -32,7 +32,7 @@ use futures::{ · 31 unmodified lines
3232 use gpui::{
3333 App, AppContext, AsyncApp, Context, Entity, EventEmitter, SharedString, Task, WeakEntity,
3434 };
35−use heck::ToSnakeCase as _;
35+
3636 use language_model::{
3737 LanguageModel, LanguageModelCompletionError, LanguageModelCompletionEvent, LanguageModelId,
3838 LanguageModelImage, LanguageModelProviderId, LanguageModelRegistry, LanguageModelRequest,
@@ -2525,14 +2525,14 @@ impl Thread { · 2486 unmodified lines
25252525 }
25262526
25272527 // When there are duplicate tool names, disambiguate by prefixing them
2528− // with the server ID (converted to snake_case for API compatibility).
2529− // In the rare case there isn't enough space for the disambiguated tool
2528+ // with the server ID. In the rare case there isn't enough space for the
2529+ // disambiguated tool
25302530 // name, keep only the last tool with this name.
25312531 for (server_id, tool_name, tool) in context_server_tools {
25322532 if duplicate_tool_names.contains(&tool_name) {
25332533 let available = MAX_TOOL_NAME_LENGTH.saturating_sub(tool_name.len());
25342534 if available >= 2 {
2535− let mut disambiguated = server_id.0.to_snake_case();
2535+ let mut disambiguated = server_id.0.to_string();
25362536 disambiguated.truncate(available - 1);
25372537 disambiguated.push('_');
25382538 disambiguated.push_str(&tool_name);