agent: Show project name in the Agent notification (#29211)

Danilo Leal created

Release Notes:

- agent: Added the project name in the Agent Panel notification.

Change summary

crates/agent/src/active_thread.rs         | 14 +++++++++++
crates/agent/src/ui/agent_notification.rs | 28 ++++++++++++++++++++++++
2 files changed, 40 insertions(+), 2 deletions(-)

Detailed changes

crates/agent/src/active_thread.rs 🔗

@@ -1093,9 +1093,21 @@ impl ActiveThread {
     ) {
         let options = AgentNotification::window_options(screen, cx);
 
+        let project_name = self.workspace.upgrade().and_then(|workspace| {
+            workspace
+                .read(cx)
+                .project()
+                .read(cx)
+                .visible_worktrees(cx)
+                .next()
+                .map(|worktree| worktree.read(cx).root_name().to_string())
+        });
+
         if let Some(screen_window) = cx
             .open_window(options, |_, cx| {
-                cx.new(|_| AgentNotification::new(title.clone(), caption.clone(), icon))
+                cx.new(|_| {
+                    AgentNotification::new(title.clone(), caption.clone(), icon, project_name)
+                })
             })
             .log_err()
         {

crates/agent/src/ui/agent_notification.rs 🔗

@@ -12,6 +12,7 @@ pub struct AgentNotification {
     title: SharedString,
     caption: SharedString,
     icon: IconName,
+    project_name: Option<SharedString>,
 }
 
 impl AgentNotification {
@@ -19,11 +20,13 @@ impl AgentNotification {
         title: impl Into<SharedString>,
         caption: impl Into<SharedString>,
         icon: IconName,
+        project_name: Option<impl Into<SharedString>>,
     ) -> Self {
         Self {
             title: title.into(),
             caption: caption.into(),
             icon,
+            project_name: project_name.map(|name| name.into()),
         }
     }
 
@@ -130,11 +133,34 @@ impl Render for AgentNotification {
                                     .child(gradient_overflow()),
                             )
                             .child(
-                                div()
+                                h_flex()
                                     .relative()
+                                    .gap_1p5()
                                     .text_size(px(12.))
                                     .text_color(cx.theme().colors().text_muted)
                                     .truncate()
+                                    .when_some(
+                                        self.project_name.clone(),
+                                        |description, project_name| {
+                                            description.child(
+                                                h_flex()
+                                                    .gap_1p5()
+                                                    .child(
+                                                        div()
+                                                            .max_w_16()
+                                                            .truncate()
+                                                            .child(project_name),
+                                                    )
+                                                    .child(
+                                                        div().size(px(3.)).rounded_full().bg(cx
+                                                            .theme()
+                                                            .colors()
+                                                            .text
+                                                            .opacity(0.5)),
+                                                    ),
+                                            )
+                                        },
+                                    )
                                     .child(self.caption.clone())
                                     .child(gradient_overflow()),
                             ),