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
113 changes: 107 additions & 6 deletions app/src/ai/blocklist/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ use crate::server::telemetry::{
use crate::settings::{
AISettings, AISettingsChangedEvent, AgentModeCodingPermissionsType, FontSettings,
InputModeSettings, InputModeSettingsChangedEvent, InputSettings,
OrchestrationMessageDisplayMode,
};
use crate::settings_view::SettingsSection;
use crate::terminal::find::TerminalFindModel;
Expand Down Expand Up @@ -783,7 +784,7 @@ impl CollapsibleElementState {
}

fn finish_reasoning(&mut self, app: &AppContext) {
let should_auto_collapse = self.should_auto_collapse_reasoning_on_finish();
let should_auto_collapse = self.should_auto_collapse_on_finish();
let thinking_mode = AISettings::as_ref(app).thinking_display_mode;

self.sync_finished_state(true);
Expand Down Expand Up @@ -815,6 +816,23 @@ impl CollapsibleElementState {
}
}

/// Applies orchestration message display behavior after streaming finishes.
fn finish_orchestration_message(&mut self, display_mode: OrchestrationMessageDisplayMode) {
let should_auto_collapse = self.should_auto_collapse_on_finish();

self.sync_finished_state(true);

if display_mode.should_collapse_agent_message_body_on_finish() && should_auto_collapse {
self.expansion_state = CollapsibleExpansionState::Collapsed;
} else if let CollapsibleExpansionState::Expanded {
scroll_pinned_to_bottom,
..
} = &mut self.expansion_state
{
*scroll_pinned_to_bottom = false;
}
}

fn toggle_expansion(&mut self) {
if !self.last_known_is_finished {
self.user_toggled_while_streaming = true;
Expand All @@ -830,7 +848,7 @@ impl CollapsibleElementState {
}
}

fn should_auto_collapse_reasoning_on_finish(&self) -> bool {
fn should_auto_collapse_on_finish(&self) -> bool {
!self.user_toggled_while_streaming
&& matches!(
self.expansion_state,
Expand All @@ -852,14 +870,33 @@ pub(crate) fn received_message_collapsible_id(message_id: &str) -> MessageId {

fn default_collapsible_state_for_orchestration_action(
action: &AIAgentActionType,
display_mode: OrchestrationMessageDisplayMode,
) -> Option<CollapsibleElementState> {
match action {
AIAgentActionType::StartAgent { .. } => Some(CollapsibleElementState::default()),
AIAgentActionType::SendMessageToAgent { .. } => Some(CollapsibleElementState::collapsed()),
AIAgentActionType::SendMessageToAgent { .. } => {
Some(default_orchestration_collapsible_state(
display_mode.should_expand_agent_message_body(),
))
}
_ => None,
}
}

fn default_collapsible_state_for_orchestration_message(
display_mode: OrchestrationMessageDisplayMode,
) -> CollapsibleElementState {
default_orchestration_collapsible_state(display_mode.should_expand_agent_message_body())
}

fn default_orchestration_collapsible_state(expanded: bool) -> CollapsibleElementState {
if expanded {
CollapsibleElementState::default()
} else {
CollapsibleElementState::collapsed()
}
}

pub struct AIBlock {
model: Rc<dyn AIBlockModel<View = AIBlock>>,
terminal_model: Arc<FairMutex<TerminalModel>>,
Expand Down Expand Up @@ -1133,6 +1170,10 @@ impl AIBlock {
}
ctx.notify();
}
AISettingsChangedEvent::ThinkingDisplayMode { .. }
| AISettingsChangedEvent::OrchestrationMessageDisplayMode { .. } => {
ctx.notify();
}
_ => {}
},
);
Expand Down Expand Up @@ -2148,10 +2189,14 @@ impl AIBlock {
}

// Register collapsible state for orchestration action messages.
let orchestration_message_display_mode =
AISettings::as_ref(ctx).orchestration_message_display_mode;
match &message.message {
AIAgentOutputMessageType::Action(AIAgentAction { action, .. }) => {
if let Some(state) = default_collapsible_state_for_orchestration_action(action)
{
if let Some(state) = default_collapsible_state_for_orchestration_action(
action,
orchestration_message_display_mode,
) {
self.collapsible_block_states
.entry(message.id.clone())
.or_insert(state);
Expand All @@ -2163,7 +2208,11 @@ impl AIBlock {
received_message_collapsible_id(&received_message.message_id);
self.collapsible_block_states
.entry(collapsible_id.clone())
.or_insert_with(CollapsibleElementState::collapsed);
.or_insert_with(|| {
default_collapsible_state_for_orchestration_message(
orchestration_message_display_mode,
)
});
self.state_handles
.transcript_avatar_handles
.entry(collapsible_id)
Expand Down Expand Up @@ -2340,7 +2389,59 @@ impl AIBlock {
self.keyboard_navigable_buttons = Some(menu);
}

/// Applies final display behavior to orchestration message bodies.
fn finish_orchestration_message_collapsible_states(
&mut self,
output: &AIAgentOutput,
ctx: &mut ViewContext<Self>,
) {
let display_mode = AISettings::as_ref(ctx).orchestration_message_display_mode;
for message in &output.messages {
match &message.message {
AIAgentOutputMessageType::Action(AIAgentAction {
action: AIAgentActionType::SendMessageToAgent { .. },
..
}) => {
self.collapsible_block_states
.entry(message.id.clone())
.or_insert_with(|| {
default_orchestration_collapsible_state(
display_mode.should_expand_agent_message_body(),
)
})
.finish_orchestration_message(display_mode);
}
AIAgentOutputMessageType::MessagesReceivedFromAgents { messages } => {
for received_message in messages {
let collapsible_id =
received_message_collapsible_id(&received_message.message_id);
self.collapsible_block_states
.entry(collapsible_id)
.or_insert_with(|| {
default_collapsible_state_for_orchestration_message(display_mode)
})
.finish_orchestration_message(display_mode);
}
}
AIAgentOutputMessageType::Text(_)
| AIAgentOutputMessageType::Reasoning { .. }
| AIAgentOutputMessageType::Summarization { .. }
| AIAgentOutputMessageType::Subagent(_)
| AIAgentOutputMessageType::Action(_)
| AIAgentOutputMessageType::TodoOperation(_)
| AIAgentOutputMessageType::WebSearch(_)
| AIAgentOutputMessageType::WebFetch(_)
| AIAgentOutputMessageType::CommentsAddressed { .. }
| AIAgentOutputMessageType::DebugOutput { .. }
| AIAgentOutputMessageType::ArtifactCreated(_)
| AIAgentOutputMessageType::SkillInvoked(_)
| AIAgentOutputMessageType::EventsFromAgents { .. } => {}
}
}
}

fn handle_complete_output(&mut self, output: &AIAgentOutput, ctx: &mut ViewContext<Self>) {
self.finish_orchestration_message_collapsible_states(output, ctx);
let mut suggestions = BlocklistAIHistoryModel::as_ref(ctx)
.existing_suggestions_for_conversation(self.client_ids.conversation_id)
.cloned()
Expand Down
146 changes: 131 additions & 15 deletions app/src/ai/blocklist/block_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ use warp_util::local_or_remote_path::LocalOrRemotePath;
use warpui::{App, SingletonEntity};

use super::{
default_collapsible_state_for_orchestration_action, received_message_collapsible_id,
default_collapsible_state_for_orchestration_action,
default_collapsible_state_for_orchestration_message, received_message_collapsible_id,
user_avatar_info_for_conversation_creator, CollapsibleElementState, CollapsibleExpansionState,
UserAvatarInfo,
};
Expand All @@ -17,7 +18,7 @@ use crate::ai::blocklist::action_model::{
compose_run_agents_child_prompt, run_agents_to_start_agent_mode,
};
use crate::auth::UserUid;
use crate::settings::AISettings;
use crate::settings::{AISettings, OrchestrationMessageDisplayMode};
use crate::test_util::settings::initialize_settings_for_tests;
use crate::workspaces::user_profiles::{UserProfileWithUID, UserProfiles};

Expand Down Expand Up @@ -47,6 +48,37 @@ fn collapsed_initializer_starts_collapsed() {
));
}

#[test]
fn orchestration_show_and_collapse_collapses_after_finish() {
let mut state = default_collapsible_state_for_orchestration_message(
OrchestrationMessageDisplayMode::ShowAndCollapse,
);

state.finish_orchestration_message(OrchestrationMessageDisplayMode::ShowAndCollapse);

assert!(matches!(
state.expansion_state,
CollapsibleExpansionState::Collapsed
));
}

#[test]
fn orchestration_always_show_stays_expanded_after_finish() {
let mut state = default_collapsible_state_for_orchestration_message(
OrchestrationMessageDisplayMode::AlwaysShow,
);

state.finish_orchestration_message(OrchestrationMessageDisplayMode::AlwaysShow);

assert!(matches!(
state.expansion_state,
CollapsibleExpansionState::Expanded {
is_finished: true,
scroll_pinned_to_bottom: false
}
));
}

#[test]
fn orchestration_send_message_starts_collapsed() {
let state = default_collapsible_state_for_orchestration_action(
Expand All @@ -55,6 +87,7 @@ fn orchestration_send_message_starts_collapsed() {
subject: "Status".to_string(),
message: "Body".to_string(),
},
OrchestrationMessageDisplayMode::AlwaysCollapse,
)
.expect("send-message actions should get a collapsible state");

Expand All @@ -65,17 +98,55 @@ fn orchestration_send_message_starts_collapsed() {
}

#[test]
fn orchestration_start_agent_keeps_expanded_default() {
let state =
default_collapsible_state_for_orchestration_action(&AIAgentActionType::StartAgent {
version: StartAgentVersion::V1,
name: "child-agent".to_string(),
prompt: "Investigate".to_string(),
execution_mode: StartAgentExecutionMode::local_harness("claude-code".to_string()),
lifecycle_subscription: None,
})
fn orchestration_start_agent_prompt_stays_expanded_for_all_message_modes() {
for display_mode in [
OrchestrationMessageDisplayMode::ShowAndCollapse,
OrchestrationMessageDisplayMode::AlwaysCollapse,
OrchestrationMessageDisplayMode::AlwaysShow,
] {
let state = default_collapsible_state_for_orchestration_action(
&AIAgentActionType::StartAgent {
version: StartAgentVersion::V1,
name: "child-agent".to_string(),
prompt: "Investigate".to_string(),
execution_mode: StartAgentExecutionMode::local_harness("claude-code".to_string()),
lifecycle_subscription: None,
},
display_mode,
)
.expect("start-agent actions should get a collapsible state");

assert!(matches!(
state.expansion_state,
CollapsibleExpansionState::Expanded {
is_finished: false,
scroll_pinned_to_bottom: true
}
));
}
}

#[test]
fn non_orchestration_actions_do_not_get_collapsible_state_defaults() {
assert!(default_collapsible_state_for_orchestration_action(
&AIAgentActionType::OpenCodeReview,
OrchestrationMessageDisplayMode::AlwaysCollapse,
)
.is_none());
}

#[test]
fn orchestration_show_and_collapse_starts_sent_messages_expanded() {
let state = default_collapsible_state_for_orchestration_action(
&AIAgentActionType::SendMessageToAgent {
addresses: vec!["child-agent".to_string()],
subject: "Status".to_string(),
message: "Body".to_string(),
},
OrchestrationMessageDisplayMode::ShowAndCollapse,
)
.expect("send-message actions should get a collapsible state");

assert!(matches!(
state.expansion_state,
CollapsibleExpansionState::Expanded {
Expand All @@ -86,11 +157,56 @@ fn orchestration_start_agent_keeps_expanded_default() {
}

#[test]
fn non_orchestration_actions_do_not_get_collapsible_state_defaults() {
assert!(
default_collapsible_state_for_orchestration_action(&AIAgentActionType::OpenCodeReview)
.is_none()
fn orchestration_always_show_starts_sent_messages_expanded() {
let state = default_collapsible_state_for_orchestration_action(
&AIAgentActionType::SendMessageToAgent {
addresses: vec!["child-agent".to_string()],
subject: "Status".to_string(),
message: "Body".to_string(),
},
OrchestrationMessageDisplayMode::AlwaysShow,
)
.expect("send-message actions should get a collapsible state");

assert!(matches!(
state.expansion_state,
CollapsibleExpansionState::Expanded {
is_finished: false,
scroll_pinned_to_bottom: true
}
));
}

#[test]
fn orchestration_received_messages_follow_initial_message_display_mode() {
let show_and_collapse = default_collapsible_state_for_orchestration_message(
OrchestrationMessageDisplayMode::ShowAndCollapse,
);
assert!(matches!(
show_and_collapse.expansion_state,
CollapsibleExpansionState::Expanded {
is_finished: false,
scroll_pinned_to_bottom: true
}
));
let collapsed = default_collapsible_state_for_orchestration_message(
OrchestrationMessageDisplayMode::AlwaysCollapse,
);
assert!(matches!(
collapsed.expansion_state,
CollapsibleExpansionState::Collapsed
));
let expanded = default_collapsible_state_for_orchestration_message(
OrchestrationMessageDisplayMode::AlwaysShow,
);

assert!(matches!(
expanded.expansion_state,
CollapsibleExpansionState::Expanded {
is_finished: false,
scroll_pinned_to_bottom: true
}
));
}

#[test]
Expand Down
Loading
Loading