@@ -54,7 +54,7 @@ use crate::ai::blocklist::agent_view::{
5454 agent_view_bg_fill, get_agent_view_entry_block_position_id, AgentViewController,
5555 AgentViewControllerEvent, AgentViewDisplayMode, AgentViewEntryBlockParams,
5656 AgentViewEntryOrigin, AgentViewHeaderDisabledTheme, AgentViewHeaderTheme,
57- AgentViewZeroStateBlock, AgentViewZeroStateEvent, EphemeralMessageModel, ExitAgentViewError,
57+ AgentViewZeroStateBlock, AgentViewZeroStateEvent, EphemeralMessageModel,
5858 ExitConfirmationTrigger, InlineAgentViewHeader, OrchestrationPillBar,
5959 ENTER_OR_EXIT_CONFIRMATION_WINDOW,
6060};
@@ -4717,20 +4717,6 @@ impl TerminalView {
47174717 callback(self, ctx);
47184718 }
47194719
4720- fn can_exit_agent_view_for_terminal_view(
4721- &self,
4722- ctx: &AppContext,
4723- ) -> Result<(), ExitAgentViewError> {
4724- match self.agent_view_controller.as_ref(ctx).can_exit_agent_view() {
4725- Err(ExitAgentViewError::LongRunningCommand)
4726- if self.can_pop_nested_cloud_agent_view(ctx) =>
4727- {
4728- Ok(())
4729- }
4730- result => result,
4731- }
4732- }
4733-
47344720 /// If the active conversation is a child agent, navigate to the parent
47354721 /// and return `true`; otherwise return `false` so the caller can run
47364722 /// the normal exit-agent-view flow. Cross-tab and swap-target cases
@@ -4771,19 +4757,21 @@ impl TerminalView {
47714757 true
47724758 }
47734759
4774- fn can_pop_nested_cloud_agent_view(&self, ctx: &AppContext) -> bool {
4775- self.is_ambient_agent_session(ctx) && self.is_nested_cloud_mode(ctx)
4776- }
4777-
47784760 /// Exits the active agent, either:
47794761 /// * Exiting agent view for the selected conversation
4780- /// * Popping the current view off the navigation stack (for cloud mode agents)
4762+ /// * Popping the current view off the navigation stack (for nested cloud mode agents)
4763+ /// Root cloud-mode panes (stack depth ≤ 1) are a no-op — there is nowhere to return to.
47814764 fn exit_agent_view(&mut self, ctx: &mut ViewContext<Self>) {
4782- // For ambient agent sessions (cloud mode), always pop from pane stack.
4783- // These sessions are pushed onto a nav stack and have no underlying terminal
4784- // to return to via the normal agent view exit path .
4765+ // For nested ambient agent sessions (cloud mode), pop from pane stack.
4766+ // Root cloud-mode panes have no parent terminal to return to, so escape
4767+ // is a no-op to avoid leaving the app in a borked state .
47854768 if self.is_ambient_agent_session(ctx) {
4786- if let Some(pane_stack) = self.pane_stack.as_ref().and_then(|h| h.upgrade(ctx)) {
4769+ if let Some(pane_stack) = self
4770+ .pane_stack
4771+ .as_ref()
4772+ .and_then(|h| h.upgrade(ctx))
4773+ .filter(|stack| stack.as_ref(ctx).depth() > 1)
4774+ {
47874775 pane_stack.update(ctx, |stack, ctx| {
47884776 stack.pop(ctx);
47894777 });
@@ -10755,7 +10743,9 @@ impl TerminalView {
1075510743 let disabled_reason = if is_child_agent {
1075610744 None
1075710745 } else {
10758- self.can_exit_agent_view_for_terminal_view(ctx)
10746+ self.agent_view_controller
10747+ .as_ref(ctx)
10748+ .can_exit_agent_view()
1075910749 .err()
1076010750 .map(|e| e.to_string())
1076110751 };
@@ -20561,7 +20551,12 @@ impl TerminalView {
2056120551 }
2056220552
2056320553 // Disable escape completely for ambient agents without a parent terminal.
20564- if self.can_exit_agent_view_for_terminal_view(ctx).is_err() {
20554+ if self
20555+ .agent_view_controller
20556+ .as_ref(ctx)
20557+ .can_exit_agent_view()
20558+ .is_err()
20559+ {
2056520560 return;
2056620561 }
2056720562
@@ -20571,7 +20566,7 @@ impl TerminalView {
2057120566 .block_list()
2057220567 .active_block()
2057320568 .is_active_and_long_running();
20574- if is_long_running && self.can_pop_nested_cloud_agent_view (ctx) {
20569+ if is_long_running && self.is_ambient_agent_session (ctx) {
2057520570 self.exit_agent_view(ctx);
2057620571 } else if !is_long_running {
2057720572 // During first-time setup, always exit directly without confirmation
@@ -26171,7 +26166,12 @@ impl TypedActionView for TerminalView {
2617126166 // to the in-place exit flow.
2617226167 if self.try_navigate_to_parent_conversation(ctx) {
2617326168 ctx.notify();
26174- } else if self.can_exit_agent_view_for_terminal_view(ctx).is_ok() {
26169+ } else if self
26170+ .agent_view_controller
26171+ .as_ref(ctx)
26172+ .can_exit_agent_view()
26173+ .is_ok()
26174+ {
2617526175 self.exit_agent_view(ctx);
2617626176 ctx.notify();
2617726177 }
0 commit comments