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
17 changes: 13 additions & 4 deletions crates/tui/src/chatwidget/text_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,11 @@ impl ChatWidget {
self.flush_active_cell();
let item_id = self.legacy_text_item_id(kind);
if !self.transcript_projector.has_live_text(item_id) {
self.apply_item_lifecycle(ItemLifecycleEvent::TextStarted { item_id, kind });
self.apply_item_lifecycle(ItemLifecycleEvent::TextStarted {
item_id,
kind,
item_seq: None,
});
}
self.apply_item_lifecycle(ItemLifecycleEvent::TextDelta {
item_id,
Expand Down Expand Up @@ -128,7 +132,12 @@ impl ChatWidget {
self.frame_requester.schedule_frame();
}

pub(super) fn start_text_item(&mut self, item_id: ActiveTextItemId, kind: TextItemKind) {
pub(super) fn start_text_item(
&mut self,
item_id: ActiveTextItemId,
kind: TextItemKind,
seq: u64,
) {
if self
.active_text_items
.iter()
Expand All @@ -141,7 +150,6 @@ impl ChatWidget {
self.commit_completed_assistant_before_next_reasoning();
}

let seq = self.reserve_seq();
let insert_index = self.active_text_item_insert_index(kind);
tracing::debug!(
item_id = %item_id.log_label(),
Expand Down Expand Up @@ -232,7 +240,8 @@ impl ChatWidget {
return index;
}

self.start_text_item(item_id, kind);
let seq = self.reserve_seq();
self.start_text_item(item_id, kind, seq);
self.active_text_items
.iter()
.position(|item| item.item_id == item_id)
Expand Down
8 changes: 6 additions & 2 deletions crates/tui/src/chatwidget/transcript_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,17 +142,21 @@ impl ChatWidget {
.iter()
.any(|item| item.item_id == item_id)
{
// A completed exploration group is already in its compact
// display form and can safely remain alongside live text.
// Only detach an unfinished group so later tools do not get
// merged across the text boundary.
if let Some(cell) = self
.active_cell
.as_ref()
.and_then(|cell| cell.as_any().downcast_ref::<crate::exec_cell::ExecCell>())
.filter(|cell| cell.is_exploring_cell())
.filter(|cell| cell.is_exploring_cell() && cell.is_active())
{
self.detached_exec_tool_ids
.extend(cell.iter_calls().map(|call| call.call_id.clone()));
self.active_cell = None;
}
self.start_text_item(item_id, live.kind);
self.start_text_item(item_id, live.kind, live.seq);
}

self.sync_live_text_item(item_id);
Expand Down
65 changes: 65 additions & 0 deletions crates/tui/src/chatwidget_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11040,6 +11040,71 @@ fn merged_explored_group_becomes_explored_after_all_results_arrive() {
);
}

#[test]
fn live_tool_order_stays_before_reasoning_after_reasoning_completes() {
let model = Model {
slug: "test-model".to_string(),
display_name: "Test Model".to_string(),
..Model::default()
};
let (mut widget, _app_event_rx) = widget_with_model(model, PathBuf::from("."));
let _ = widget.drain_scrollback_lines(100);

widget.handle_worker_event(crate::worker_event_test_helpers::tool_call(
"tool-1".to_string(),
"Web Search(\"query\")".to_string(),
false,
None,
));
widget.handle_worker_event(crate::worker_event_test_helpers::tool_result(
"tool-1".to_string(),
"Web Search(\"query\")".to_string(),
"status: completed".to_string(),
false,
false,
));
let reasoning_id = devo_core::ItemId::new();
widget.handle_worker_event(crate::worker_event_test_helpers::text_item_started(
reasoning_id,
TextItemKind::Reasoning,
));
widget.handle_worker_event(crate::worker_event_test_helpers::text_item_delta(
reasoning_id,
TextItemKind::Reasoning,
"thinking body",
));

let live = line_texts(widget.active_viewport_lines_for_test(100)).join("\n");
let tool_position = live
.find("Web Search(\"query\")")
.expect("live tool row should render");
let thinking_position = live
.find("Thinking: thinking body")
.expect("live reasoning row should render");
assert!(
tool_position < thinking_position,
"tool should stay above live reasoning:\n{live}"
);

widget.handle_worker_event(crate::worker_event_test_helpers::text_item_completed(
reasoning_id,
TextItemKind::Reasoning,
"thinking body",
));

let transcript = line_texts(widget.transcript_overlay_lines(100)).join("\n");
let tool_position = transcript
.find("Web Search(\"query\")")
.expect("tool row should remain in transcript");
let thought_position = transcript
.find("Thought: thinking body")
.expect("completed reasoning row should render");
assert!(
tool_position < thought_position,
"tool should stay above completed reasoning:\n{transcript}"
);
}

#[test]
fn live_viewport_shows_explored_group_while_active() {
let model = Model {
Expand Down
80 changes: 80 additions & 0 deletions crates/tui/src/tool_rendering_e2e_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,15 @@ fn active_display(widget: &ChatWidget) -> String {
.join("\n")
}

fn viewport_display(widget: &ChatWidget) -> String {
widget
.active_viewport_lines_for_test(100)
.into_iter()
.map(|line| line.to_string())
.collect::<Vec<_>>()
.join("\n")
}

#[test]
fn streaming_read_and_glob_updates_render_in_one_explored_cell() {
let model = Model {
Expand Down Expand Up @@ -148,3 +157,74 @@ fn streaming_read_and_glob_updates_render_in_one_explored_cell() {
"glob placeholder must be replaced in place:\n{display}"
);
}

#[test]
fn explored_group_stays_collapsed_when_live_reasoning_starts() {
let model = Model {
slug: "test-model".to_string(),
display_name: "Test Model".to_string(),
..Model::default()
};
let (mut widget, _app_event_rx) = widget_with_model(model, PathBuf::from("."));

widget.handle_worker_event(crate::worker_event_test_helpers::tool_call(
"grep-1".to_string(),
"grep 'plan' in crates".to_string(),
false,
Some(vec![devo_protocol::parse_command::ParsedCommand::Search {
cmd: "grep 'plan' in crates".to_string(),
query: Some("plan".to_string()),
path: Some("crates".to_string()),
}]),
));
widget.handle_worker_event(crate::worker_event_test_helpers::tool_result(
"grep-1".to_string(),
"grep 'plan' in crates".to_string(),
"match".to_string(),
false,
false,
));
widget.handle_worker_event(crate::worker_event_test_helpers::tool_call(
"read-1".to_string(),
"read crates/tui/src/worker.rs".to_string(),
false,
Some(vec![devo_protocol::parse_command::ParsedCommand::Read {
cmd: "read crates/tui/src/worker.rs".to_string(),
name: "worker.rs".to_string(),
path: PathBuf::from("crates/tui/src/worker.rs"),
}]),
));
widget.handle_worker_event(crate::worker_event_test_helpers::tool_result(
"read-1".to_string(),
"read crates/tui/src/worker.rs".to_string(),
"source".to_string(),
false,
false,
));

let reasoning_id = devo_core::ItemId::new();
widget.handle_worker_event(crate::worker_event_test_helpers::text_item_started(
reasoning_id,
crate::events::TextItemKind::Reasoning,
));
widget.handle_worker_event(crate::worker_event_test_helpers::text_item_delta(
reasoning_id,
crate::events::TextItemKind::Reasoning,
"thinking while the explored group remains collapsed",
));

let display = viewport_display(&widget);
assert!(
display.contains("▌ Explored"),
"starting live reasoning must not expand the explored group into separate tool cells:\n{display}"
);
assert!(
display.contains("Grepped plan in crates")
&& display.contains("Read crates/tui/src/worker.rs"),
"the grouped explored summary must remain visible:\n{display}"
);
assert!(
display.contains("Thinking: thinking while the explored group remains collapsed"),
"live reasoning must still render after the explored group:\n{display}"
);
}
2 changes: 2 additions & 0 deletions crates/tui/src/transcript/lifecycle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ pub(crate) enum ItemLifecycleEvent {
TextStarted {
item_id: ItemId,
kind: TextItemKind,
item_seq: Option<u64>,
},
TextDelta {
item_id: ItemId,
Expand Down Expand Up @@ -54,6 +55,7 @@ pub(crate) enum ItemLifecycleEvent {
tool_use_id: String,
tool_name: String,
input: serde_json::Value,
item_seq: Option<u64>,
command: Option<String>,
command_source: Option<ExecCommandSource>,
parsed_commands: Vec<devo_protocol::parse_command::ParsedCommand>,
Expand Down
Loading
Loading