Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions THIRD_PARTY_NOTICES.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 11 additions & 1 deletion crates/agent/src/panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ impl AgentPanel {
let composer = composer_view::ComposerView::new(window, cx);
let menus = menu_view::MenuView::new(composer.focus(cx), window, cx);
let history = history_column::HistoryColumn::new(window, cx);
let layout = layout::PanelLayout::new(layout, cx);
let layout = layout::PanelLayout::new(layout, window, cx);
let messages = message_list::MessageList::new(images, cx);
let subscriptions = Self::bind_panel(&host, &settings, window, cx);
// Whatever the panel redraws for, its cached regions redraw too; thread changes
Expand Down Expand Up @@ -455,6 +455,14 @@ impl AgentPanel {
) -> AnyElement {
match kind {
parts::PartKind::Transcript => self.render_transcript_part(cx),
parts::PartKind::Approvals => self
.current()
.and_then(|thread| self.render_approvals(&thread, window, cx))
.unwrap_or_else(|| div().into_any_element()),
parts::PartKind::Status => self
.current()
.and_then(|thread| self.chat_status(&thread, cx))
.unwrap_or_else(|| div().into_any_element()),
parts::PartKind::Footer => self.render_footer(window, cx),
parts::PartKind::Queue => self.render_queue_part(cx),
}
Expand Down Expand Up @@ -629,6 +637,8 @@ impl Render for AgentPanel {
.min_w_0()
.min_h_0()
.child(self.layout.parts().transcript())
.child(self.layout.parts().approvals())
.child(self.layout.parts().status())
.child(self.layout.parts().footer(self.menus.current().is_some()))
.into_any_element();
if self.layout.history() {
Expand Down
6 changes: 1 addition & 5 deletions crates/agent/src/panel/chat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use nocterm_ai::usage::{Breakdown, RateLimit};
use std::time::Duration;

impl AgentPanel {
/// The open chat's footer: approvals, status, queue, commands and the composer.
/// The open chat's footer: queue, commands and the composer.
pub(super) fn render_footer(
&mut self,
window: &mut Window,
Expand All @@ -20,8 +20,6 @@ impl AgentPanel {
return div().into_any_element();
};
let frame = super::composer_frame::ComposerFrame::read(&thread, cx);
let approvals = self.render_approvals(&thread, window, cx);
let status = self.chat_status(&thread, cx);
let labels = attachments::AttachmentLabels::new(thread.read(cx).workspace_seat(), cx);
let queue =
(!thread.read(cx).composer().queue().is_empty()).then(|| self.layout.parts().queue());
Expand All @@ -30,8 +28,6 @@ impl AgentPanel {
v_flex()
.w_full()
.min_w_0()
.children(approvals)
.children(status)
.children(queue)
.children(commands)
.child(composer)
Expand Down
6 changes: 4 additions & 2 deletions crates/agent/src/panel/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ pub(super) struct PanelLayout {
parts: super::parts::PanelParts,
}
impl PanelLayout {
pub(super) fn new(layout: LayoutHandle, cx: &mut Context<AgentPanel>) -> Self {
pub(super) fn new(layout: LayoutHandle, window: &Window, cx: &mut Context<AgentPanel>) -> Self {
let mut bindings = Vec::new();
let splits = [1, 0].map(|index| {
let split = cx.new(|_| ResizableState::default());
Expand All @@ -112,6 +112,8 @@ impl PanelLayout {
panel.on_shared_history_width_changed(value, cx)
});
}));
let parts = super::parts::PanelParts::new(cx);
bindings.push(parts.observe_status_visibility(window));
Self {
history: true,
widened: None,
Expand All @@ -121,7 +123,7 @@ impl PanelLayout {
layout,
_bindings: bindings,
refresh: std::array::from_fn(|_| SplitRefresh::Idle),
parts: super::parts::PanelParts::new(cx),
parts,
}
}
pub(super) fn history(&self) -> bool {
Expand Down
2 changes: 1 addition & 1 deletion crates/agent/src/panel/lifecycle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ impl AgentPanel {
let stamp = super::parts::transcript_stamp(loaded.read(cx));
let parts = self.layout.parts();
parts.transcript_changed(rows, stamp, cx);
parts.notify(super::parts::PartKind::Footer, cx);
parts.notify_chat_footer(cx);
}
self.schedule_history_redraw(cx);
}
Expand Down
44 changes: 41 additions & 3 deletions crates/agent/src/panel/parts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,22 @@
//! Cached regions are reused unless they are notified. Any notify of the panel
//! invalidates all of them, so state the panel changes stays correct by default;
//! thread changes, typing and queue disclosure can target a single region.
//! The footer (approvals, status, queue, commands and composer) is cached to its
//! Approvals and animated status are independent siblings of the footer.
//! The footer (queue, commands and composer) is cached to its
//! content while its pickers are closed. Open pickers keep their interaction state
//! live instead of reusing a content-sized cache's deferred popup.
use super::{AgentPanel, history::HistoryViewport};
use gpui_kit::{
App, AppContext as _, Context, Entity, IntoElement, Render, StyleRefinement, Styled,
WeakEntity, Window, div,
Subscription, WeakEntity, Window, div,
};
use std::hash::{Hash, Hasher};

#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub(super) enum PartKind {
Transcript,
Approvals,
Status,
Footer,
Queue,
}
Expand Down Expand Up @@ -48,6 +51,8 @@ impl Render for HistoryPart {
pub(super) struct PanelParts {
transcript: Entity<PanelPart>,
history: Entity<HistoryPart>,
approvals: Entity<PanelPart>,
status: Entity<PanelPart>,
footer: Entity<PanelPart>,
queue: Entity<PanelPart>,
transcript_seen: Option<u64>,
Expand All @@ -61,6 +66,8 @@ impl PanelParts {
cx.new(|_| PanelPart { panel, kind })
};
let transcript = part(PartKind::Transcript);
let approvals = part(PartKind::Approvals);
let status = part(PartKind::Status);
let footer = part(PartKind::Footer);
let queue = part(PartKind::Queue);
let history = cx.new(|_| HistoryPart {
Expand All @@ -70,6 +77,8 @@ impl PanelParts {
Self {
transcript,
history,
approvals,
status,
footer,
queue,
transcript_seen: None,
Expand All @@ -96,6 +105,27 @@ impl PanelParts {
.min_w_0(),
)
}
/// Approvals stay above the status and composer without being rebuilt by animation.
pub(super) fn approvals(&self) -> impl IntoElement + use<> {
self.approvals
.clone()
.cached_to_content(StyleRefinement::default().w_full())
}
/// The animation owns layout-time element state (including its paced wake).
/// Do not use a content-sized replay cache here: its replay only preserves
/// prepaint/paint state, not an animation's layout-time state. The surrounding
/// panel remains cached and the expensive sibling regions are independent.
pub(super) fn status(&self) -> impl IntoElement + use<> {
self.status.clone()
}
/// Visibility is not focus. Repaint the status when a hidden window is
/// presented again, even if its cached last draw had no animation wake.
pub(super) fn observe_status_visibility(&self, window: &Window) -> Subscription {
let status = self.status.downgrade();
window.observe_window_visibility(move |_, _, cx| {
let _ = status.update(cx, |_, cx| cx.notify());
})
}
/// Open pickers must retain their keyed popup, hover and scroll state across frames.
pub(super) fn footer(&self, picker_open: bool) -> impl IntoElement + use<> {
if picker_open {
Expand All @@ -107,7 +137,7 @@ impl PanelParts {
.into_any_element()
}
}
/// Keep a static queue available to the status animation's footer redraws.
/// Keep a static queue available to composer redraws.
pub(super) fn queue(&self) -> impl IntoElement + use<> {
self.queue
.clone()
Expand All @@ -117,11 +147,19 @@ impl PanelParts {
pub(super) fn invalidate(&self, cx: &mut App) {
self.transcript.update(cx, |_, cx| cx.notify());
self.invalidate_history(cx);
self.notify_chat_footer(cx);
}
/// A chat semantic update may change all of its lower regions.
pub(super) fn notify_chat_footer(&self, cx: &mut App) {
self.notify(PartKind::Approvals, cx);
self.notify(PartKind::Status, cx);
self.notify(PartKind::Footer, cx);
}
pub(super) fn notify(&self, kind: PartKind, cx: &mut App) {
let part = match kind {
PartKind::Transcript => &self.transcript,
PartKind::Approvals => &self.approvals,
PartKind::Status => &self.status,
PartKind::Footer => {
self.queue.update(cx, |_, cx| cx.notify());
&self.footer
Expand Down
2 changes: 1 addition & 1 deletion crates/agent/src/panel/tests/approvals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ fn live_group_membership_and_revoked_registration_reject_stale_terminal_ids(
icon: None,
flag: None,
};
let directory = Rc::new(Directory(std::cell::RefCell::new(vec![summary])));
let directory = Rc::new(Directory::new(std::cell::RefCell::new(vec![summary])));
cx.update(|cx| {
f.workspace.update(cx, |workspace, _| {
workspace.set_connection_directory(directory.clone())
Expand Down
2 changes: 1 addition & 1 deletion crates/agent/src/panel/tests/composer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ fn attach_menu_lists_servers_under_their_folders(cx: &mut TestAppContext) {
icon: None,
flag: None,
};
let directory = Rc::new(Directory(std::cell::RefCell::new(vec![
let directory = Rc::new(Directory::new(std::cell::RefCell::new(vec![
server("proxmox", Some("homelab")),
server("backup", None),
server("ai-server", Some("homelab")),
Expand Down
2 changes: 1 addition & 1 deletion crates/agent/src/panel/tests/composer/menu_stability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ impl gpui_kit::Render for PanelHost {
}

fn many_servers(f: &Fixture, cx: &mut TestAppContext) -> Rc<Directory> {
let directory = Rc::new(Directory(std::cell::RefCell::new(
let directory = Rc::new(Directory::new(std::cell::RefCell::new(
(0..35)
.map(|index| super::super::servers::summary(&format!("server-{index:02}"), None))
.collect(),
Expand Down
100 changes: 100 additions & 0 deletions crates/agent/src/panel/tests/invalidation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -563,3 +563,103 @@ fn a_growing_draft_grows_the_cached_composer_below_the_transcript(cx: &mut TestA
"the transcript gives way: {transcript:?} above {after:?}"
);
}

fn painted_thinking_tiles(f: &Fixture, cx: &mut TestAppContext) -> Vec<gpui_kit::Quad> {
cx.update_window(f.handle, |_, window, _| {
let scale = window.scale_factor();
let indicator = window.find("agent-thinking").bounds();
window
.painted_quads()
.into_iter()
.filter(|quad| {
let x = gpui_kit::px(quad.bounds.origin.x.0 / scale);
let y = gpui_kit::px(quad.bounds.origin.y.0 / scale);
indicator.contains(&gpui_kit::point(x, y))
&& (quad.bounds.size.width.0 / scale - 6.).abs() < 0.1
&& (quad.bounds.size.height.0 / scale - 6.).abs() < 0.1
})
.collect::<Vec<_>>()
})
.unwrap()
}

fn advance_thinking_frame(f: &Fixture, cx: &mut TestAppContext, millis: u64) {
cx.executor()
.advance_clock(std::time::Duration::from_millis(millis));
cx.run_until_parked();
cx.update_window(f.handle, |_, window, cx| window.draw(cx).clear(cx))
.unwrap();
}

#[gpui_kit::test]
fn thinking_animation_does_not_rebuild_attachment_labels(cx: &mut TestAppContext) {
let f = fixture(cx);
let directory = Rc::new(Directory::new(Default::default()));
cx.update(|cx| {
f.workspace.update(cx, |workspace, _| {
workspace.set_connection_directory(directory.clone());
});
});
new_chat(&f, cx);
let thread = cx.update(|cx| f.panel.read(cx).current().unwrap());
thread.update(cx, |thread, cx| thread.send("Think".into(), cx));
cx.run_until_parked();
cx.update_window(f.handle, |_, window, cx| {
window.activate_window();
// Exclude the composer's independent 500ms cursor blink from the
// measurement; the visible thinking indicator does not require focus.
window.blur(cx);
window.render_frame(cx);
assert!(window.try_find("agent-thinking").is_some());
})
.unwrap();
cx.run_until_parked();
// Let the initial chat notifications and coalesced history update settle
// before counting steady-state animation work.
for _ in 0..4 {
advance_thinking_frame(&f, cx, 25);
}
let start = painted_thinking_tiles(&f, cx);
let before = directory.reads();
for _ in 0..20 {
advance_thinking_frame(&f, cx, 25);
}
let reads = directory.reads() - before;
assert_eq!(
reads, 0,
"thinking animation must not rebuild attachment labels"
);
let end = painted_thinking_tiles(&f, cx);
assert_eq!(start.len(), 3);
assert_eq!(end.len(), 3);
assert_ne!(start, end, "timed redraws must actually move the indicator");

cx.simulate_window_visibility_change(f.handle, gpui_kit::WindowVisibility::Hidden);
cx.run_until_parked();
cx.update_window(f.handle, |_, window, cx| window.draw(cx).clear(cx))
.unwrap();
let hidden = painted_thinking_tiles(&f, cx);
advance_thinking_frame(&f, cx, 200);
assert_eq!(
hidden,
painted_thinking_tiles(&f, cx),
"hidden animation rests"
);
cx.simulate_window_visibility_change(f.handle, gpui_kit::WindowVisibility::Visible);
cx.run_until_parked();
cx.update_window(f.handle, |_, window, cx| window.draw(cx).clear(cx))
.unwrap();
let restored = painted_thinking_tiles(&f, cx);
advance_thinking_frame(&f, cx, 200);
assert_ne!(
restored,
painted_thinking_tiles(&f, cx),
"visible window must resume the loop"
);
complete_active(&f, cx);
cx.update_window(f.handle, |_, window, cx| {
window.draw(cx).clear(cx);
assert!(window.try_find("agent-thinking").is_none());
})
.unwrap();
}
14 changes: 13 additions & 1 deletion crates/agent/src/panel/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -465,9 +465,21 @@ fn exchange(f: &Fixture, text: &str, answer: &str, cx: &mut TestAppContext) -> S
session
}

struct Directory(std::cell::RefCell<Vec<nocterm_workspace::ConnectionSummary>>);
struct Directory(
std::cell::RefCell<Vec<nocterm_workspace::ConnectionSummary>>,
std::cell::Cell<usize>,
);
impl Directory {
fn new(entries: std::cell::RefCell<Vec<nocterm_workspace::ConnectionSummary>>) -> Self {
Self(entries, std::cell::Cell::new(0))
}
fn reads(&self) -> usize {
self.1.get()
}
}
impl nocterm_workspace::ConnectionDirectory for Directory {
fn connections(&self, _: &App) -> Vec<nocterm_workspace::ConnectionSummary> {
self.1.set(self.1.get() + 1);
self.0.borrow().clone()
}
fn open(
Expand Down
2 changes: 1 addition & 1 deletion crates/agent/src/panel/tests/servers/menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ fn servers_with_the_same_display_name_keep_independent_attachment_choices(cx: &m
db.name = "Same name".into();
cx.update(|cx| {
f.workspace.update(cx, |workspace, _| {
workspace.set_connection_directory(Rc::new(Directory(RefCell::new(vec![web, db]))))
workspace.set_connection_directory(Rc::new(Directory::new(RefCell::new(vec![web, db]))))
})
});
new_chat(&f, cx);
Expand Down
2 changes: 1 addition & 1 deletion crates/agent/src/panel/tests/tool_input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ fn verified_destination_uses_the_connected_host_and_survives_rename_detach_and_r
icon: None,
flag: None,
};
let directory = Rc::new(Directory(std::cell::RefCell::new(vec![summary])));
let directory = Rc::new(Directory::new(std::cell::RefCell::new(vec![summary])));
cx.update(|cx| {
f.workspace.update(cx, |workspace, _| {
workspace.set_connection_directory(directory.clone())
Expand Down
Loading
Loading