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
19 changes: 19 additions & 0 deletions crates/agent/src/panel/composer_renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ use super::{
};
use crate::thread::{AgentThread, config_label};

fn codex_goal_mode_notice(thread: &AgentThread) -> bool {
thread.document().agent_id() == "codex"
&& thread.draft_text().is_some_and(|draft| {
nocterm_ai::commands::invocation(draft, thread.configuration().commands())
.is_some_and(|command| command.name == "goal")
})
}

fn remove_image(origin: gpui_kit::EntityId, index: usize, cx: &mut Context<AgentPanel>) -> Button {
Button::new(("remove-image", index))
.ghost()
Expand Down Expand Up @@ -389,6 +397,17 @@ impl ComposerRenderer {
.into_any_element(),
);
}
if codex_goal_mode_notice(thread.read(cx)) {
notices.push(
div()
.id("codex-goal-mode-notice")
.test_support()
.text_xs()
.text_color(cx.theme().muted_foreground)
.child("Codex goal commands may retain the last applied permission mode. After changing mode, send a regular message before starting or resuming a goal.")
.into_any_element(),
);
}
if thread.read(cx).ended() && !thread.read(cx).session_generating() {
notices.push(
Button::new("agent-restart")
Expand Down
15 changes: 14 additions & 1 deletion crates/agent/src/panel/entries/tool_output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use gpui_kit::{
px,
};
use nocterm_ai::model::content::Content;
use nocterm_ai::model::tools::{ToolContent, ToolRecord};
use nocterm_ai::model::tools::{ToolContent, ToolRecord, ToolStatus};
use nocterm_ai::tool_display::{self, ToolDisplay, ToolOutcome};
use serde_json::Value;

Expand Down Expand Up @@ -91,6 +91,19 @@ pub(in crate::panel) fn source(call: &ToolRecord, redact: bool) -> Option<Output
.map(|display| display.tool.as_ref())
.or_else(|| tool_display::fallback_tool(call));
let mut output = provider_output(call, tool);
if tool.is_some()
&& call.status == ToolStatus::Failed
&& call
.raw_output
.as_ref()
.and_then(|raw| raw["error"]["message"].as_str())
== Some("MCP tool call requires approval, but approval policy is never")
{
output.append(Output::plain(
"Codex approval mode",
"Codex refused this request before it reached Nocterm because its effective approval policy is never. The displayed mode can differ from the effective mode, especially with /goal. Stop the goal, select Workspace access and send a regular message before resuming. Nocterm terminal permissions still apply.".into(),
));
}
if output.sections.is_empty() {
return None;
}
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
52 changes: 52 additions & 0 deletions crates/agent/src/panel/tests/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,58 @@ fn commands(f: &Fixture, values: Vec<AvailableCommand>, text: &str, cx: &mut Tes
}
}

#[gpui_kit::test]
fn codex_goal_warns_about_the_effective_mode_instead_of_assuming_full_access(
cx: &mut TestAppContext,
) {
let f = fixture(cx);
f.commands.config.set_options(vec![
ConfigOption::select(
"mode",
"Mode",
"agent-full-access",
vec![
ConfigChoice::new("agent-full-access", "Full access"),
ConfigChoice::new("workspace-write", "Workspace access"),
],
)
.category(ConfigCategory::Mode),
]);
new_chat(&f, cx);
let goals = || vec![AvailableCommand::new("goal", "Work towards an objective")];
commands(&f, goals(), "Ordinary message", cx);
cx.update_window(f.handle, |_, window, _cx| {
assert!(window.try_find("codex-goal-mode-notice").is_none());
})
.unwrap();

commands(&f, goals(), "/goal resume", cx);
cx.update_window(f.handle, |_, window, cx| {
assert!(window.try_find("codex-goal-mode-notice").is_some());
window.click("config-picker-mode", cx);
window.render_frame(cx);
window.click("config-mode-workspace-write", cx);
})
.unwrap();
cx.run_until_parked();
cx.update_window(f.handle, |_, window, cx| {
window.render_frame(cx);
assert!(window.try_find("codex-goal-mode-notice").is_some());
})
.unwrap();
assert_eq!(f.commands.config.requests().len(), 1);
assert!(
f.commands.prompts.lock().unwrap().is_empty(),
"the notice must not send an implicit prompt"
);

commands(&f, goals(), "/goals", cx);
cx.update_window(f.handle, |_, window, _cx| {
assert!(window.try_find("codex-goal-mode-notice").is_none());
})
.unwrap();
}

#[gpui_kit::test]
fn clicked_unicode_command_keeps_focus_and_appends_at_end(cx: &mut TestAppContext) {
let f = fixture(cx);
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
Loading
Loading