mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:31:09 +00:00
Group adjacent computer actions in the TUI (#43576)
## What changed Render adjacent `cua_repl` calls as a compact “Using computer” or “Used computer” group with action and failure counts. Show the current action while running, and prioritize failures and screenshots in completed previews while preserving their chronological order. Keep full call arguments and output in the expanded transcript, with a `ctrl+t` hint for hidden actions. End groups at other history items and turn boundaries, preserve completed results when pending actions are interrupted, and use the same grouping for live events and history replay. ## Testing Add unit and snapshot coverage for live/replay parity, grouping boundaries, out-of-order completion, interruption, failure and screenshot previews, full transcript details, and narrow-terminal and Unicode rendering. GitOrigin-RevId: 8e61ccf4c9f6d1a4d56d674a6d41ca5160d42c82
This commit is contained in:
1 parent
a51608398d
commit
4110342321
21 files changed
+656
-18
No files matched your search
@@ -376,7 +376,12 @@ impl ChatWidget {
|
||||
Some(exec_cell) if exec_cell.is_active() => {
|
||||
ExecEndTarget::OrphanHistoryWhileActiveExec
|
||||
}
|
||||
None if cell.as_any().is::<McpToolCallCell>() => {
|
||||
None if cell.as_any().is::<McpToolCallCell>()
|
||||
|| cell
|
||||
.as_any()
|
||||
.downcast_ref::<history_cell::ComputerActivityCell>()
|
||||
.is_some_and(history_cell::ComputerActivityCell::is_active) =>
|
||||
{
|
||||
ExecEndTarget::OrphanHistoryWhileActiveExec
|
||||
}
|
||||
Some(_) | None => ExecEndTarget::NewCell,
|
||||
|
||||
@@ -79,7 +79,7 @@ impl ChatWidget {
|
||||
if active_cell_is_empty {
|
||||
self.active_hook_cell = None;
|
||||
}
|
||||
self.flush_completed_command_activity();
|
||||
self.flush_completed_tool_activity();
|
||||
self.bump_active_cell_revision();
|
||||
self.app_event_tx
|
||||
.send(AppEvent::InsertHistoryCell(Box::new(completed_cell)));
|
||||
|
||||
@@ -243,6 +243,8 @@ mod compaction_tests;
|
||||
#[path = "tests/completion_styling_tests.rs"]
|
||||
mod completion_styling;
|
||||
mod composer_submission;
|
||||
#[path = "tests/computer_activity_tests.rs"]
|
||||
mod computer_activity_tests;
|
||||
#[path = "tests/config_errors_tests.rs"]
|
||||
mod config_errors;
|
||||
mod exec_flow;
|
||||
|
||||
@@ -0,0 +1,99 @@
|
||||
use super::*;
|
||||
|
||||
fn computer_item(
|
||||
id: &str,
|
||||
status: codex_app_server_protocol::McpToolCallStatus,
|
||||
) -> AppServerThreadItem {
|
||||
AppServerThreadItem::McpToolCall {
|
||||
id: id.to_string(),
|
||||
server: "cua_repl".to_string(),
|
||||
tool: "js".to_string(),
|
||||
status,
|
||||
arguments: json!({"title": format!("Inspect page {id}"), "code": "await cua.getState()"}),
|
||||
app_context: None,
|
||||
mcp_app_resource_uri: None,
|
||||
plugin_id: None,
|
||||
read_only_hint: None,
|
||||
result: Some(Box::new(codex_app_server_protocol::McpToolCallResult {
|
||||
content: vec![json!({"type": "text", "text": format!("Full output for {id}")})],
|
||||
structured_content: None,
|
||||
meta: None,
|
||||
})),
|
||||
error: None,
|
||||
duration_ms: Some(5),
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn computer_activity_live_and_replay_group_identically() {
|
||||
use codex_app_server_protocol::McpToolCallStatus;
|
||||
let mut outputs = Vec::new();
|
||||
for replay in [false, true] {
|
||||
let (mut chat, mut rx, _op_rx) = make_chatwidget_manual(/*model_override*/ None).await;
|
||||
for id in ["1", "2", "3", "4"] {
|
||||
let item = computer_item(id, McpToolCallStatus::Completed);
|
||||
if replay {
|
||||
chat.replay_thread_item(item, "turn-1".to_string(), ReplayKind::ThreadSnapshot);
|
||||
} else {
|
||||
chat.on_mcp_tool_call_started(computer_item(id, McpToolCallStatus::InProgress));
|
||||
chat.on_mcp_tool_call_completed(item);
|
||||
}
|
||||
}
|
||||
assert!(drain_insert_history(&mut rx).is_empty());
|
||||
let cell = chat.transcript.active_cell.as_ref().expect("group");
|
||||
outputs.push((
|
||||
cell.display_lines(/*width*/ 80),
|
||||
cell.transcript_lines(/*width*/ 100),
|
||||
));
|
||||
chat.finalize_turn();
|
||||
let cells = drain_insert_history(&mut rx);
|
||||
assert_eq!(cells.len(), 1);
|
||||
assert_eq!(cells[0], outputs.last().unwrap().0);
|
||||
}
|
||||
assert_eq!(outputs[0], outputs[1]);
|
||||
insta::assert_snapshot!(
|
||||
"computer_activity_replayed",
|
||||
lines_to_single_string(&outputs[0].0)
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn computer_activity_preserves_boundaries_and_expanded_output() {
|
||||
use codex_app_server_protocol::McpToolCallStatus;
|
||||
let (mut chat, mut rx, _op_rx) = make_chatwidget_manual(/*model_override*/ None).await;
|
||||
chat.on_mcp_tool_call_completed(computer_item("1", McpToolCallStatus::Completed));
|
||||
chat.prepare_assistant_message();
|
||||
let cells = drain_insert_history(&mut rx);
|
||||
assert!(lines_to_single_string(&cells[0]).contains("Used computer · 1 action"));
|
||||
chat.on_mcp_tool_call_completed(computer_item("2", McpToolCallStatus::Completed));
|
||||
let mut other = computer_item("other", McpToolCallStatus::Completed);
|
||||
if let AppServerThreadItem::McpToolCall { server, .. } = &mut other {
|
||||
*server = "another_server".to_string();
|
||||
}
|
||||
chat.on_mcp_tool_call_completed(other);
|
||||
let cells = drain_insert_history(&mut rx);
|
||||
assert_eq!(cells.len(), 2);
|
||||
assert!(lines_to_single_string(&cells[0]).contains("Used computer · 1 action"));
|
||||
assert!(lines_to_single_string(&cells[1]).contains("another_server"));
|
||||
chat.on_mcp_tool_call_completed(computer_item("3", McpToolCallStatus::Completed));
|
||||
let transcript = chat.active_cell_transcript_lines(/*width*/ 100).unwrap();
|
||||
assert!(lines_to_single_string(&transcript).contains("Full output for 3"));
|
||||
assert!(lines_to_single_string(&transcript).contains("await cua.getState()"));
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn computer_activity_out_of_order_completion_and_interruption() {
|
||||
use codex_app_server_protocol::McpToolCallStatus;
|
||||
let (mut chat, mut rx, _op_rx) = make_chatwidget_manual(/*model_override*/ None).await;
|
||||
chat.on_mcp_tool_call_started(computer_item("1", McpToolCallStatus::InProgress));
|
||||
chat.on_mcp_tool_call_started(computer_item("2", McpToolCallStatus::InProgress));
|
||||
chat.on_mcp_tool_call_completed(computer_item("2", McpToolCallStatus::Completed));
|
||||
assert!(active_blob(&chat).contains("Using computer"));
|
||||
chat.finalize_turn();
|
||||
let cells = drain_insert_history(&mut rx);
|
||||
assert_eq!(cells.len(), 1);
|
||||
insta::assert_snapshot!(
|
||||
"computer_activity_partial_interruption",
|
||||
lines_to_single_string(&cells[0])
|
||||
);
|
||||
}
|
||||
@@ -1271,10 +1271,15 @@ async fn failed_repl_mcp_tool_call_preserves_status_and_result() {
|
||||
/*replay_kind*/ None,
|
||||
);
|
||||
|
||||
chat.flush_active_cell();
|
||||
let cells = drain_insert_history(&mut rx);
|
||||
let [lines] = cells.as_slice() else {
|
||||
panic!("expected one completed MCP tool call for {server}");
|
||||
};
|
||||
if server == "cua_repl" {
|
||||
insta::assert_snapshot!("failed_computer_activity", lines_to_single_string(lines));
|
||||
continue;
|
||||
}
|
||||
insta::allow_duplicates! {
|
||||
insta::assert_snapshot!(lines_to_single_string(lines), @r#"
|
||||
• Called Inspect workspace
|
||||
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
---
|
||||
source: tui/src/chatwidget/tests/computer_activity_tests.rs
|
||||
expression: "lines_to_single_string(&cells[0])"
|
||||
---
|
||||
• Used computer · 2 actions · 1 failed
|
||||
├ Failed: Inspect page 1 — interrupted
|
||||
└ Inspect page 2
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
---
|
||||
source: tui/src/chatwidget/tests/computer_activity_tests.rs
|
||||
expression: "lines_to_single_string(&outputs[0].0)"
|
||||
---
|
||||
• Used computer · 4 actions
|
||||
├ Inspect page 3
|
||||
├ Inspect page 4
|
||||
└ 2 more · ctrl+t
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
---
|
||||
source: tui/src/chatwidget/tests/history_replay.rs
|
||||
expression: lines_to_single_string(lines)
|
||||
---
|
||||
• Used computer · 1 action · 1 failed
|
||||
└ Failed: Inspect workspace — permission denied
|
||||
@@ -173,14 +173,26 @@ impl ChatWidget {
|
||||
return;
|
||||
};
|
||||
self.flush_answer_stream_with_separator();
|
||||
let invocation = McpInvocation {
|
||||
server,
|
||||
tool,
|
||||
arguments: Some(arguments),
|
||||
};
|
||||
if invocation.is_computer_activity() {
|
||||
let call = history_cell::new_active_mcp_tool_call(
|
||||
id,
|
||||
invocation,
|
||||
self.local_settings.tui.animations,
|
||||
);
|
||||
self.update_computer_activity(|cell| cell.start(call));
|
||||
self.bump_active_cell_revision();
|
||||
self.request_redraw();
|
||||
return;
|
||||
}
|
||||
self.flush_active_cell();
|
||||
self.transcript.active_cell = Some(Box::new(history_cell::new_active_mcp_tool_call(
|
||||
id,
|
||||
McpInvocation {
|
||||
server,
|
||||
tool,
|
||||
arguments: Some(arguments),
|
||||
},
|
||||
invocation,
|
||||
self.local_settings.tui.animations,
|
||||
)));
|
||||
self.bump_active_cell_revision();
|
||||
@@ -224,6 +236,19 @@ impl ChatWidget {
|
||||
(None, None) => Err("MCP tool call completed without a result".to_string()),
|
||||
};
|
||||
|
||||
if invocation.is_computer_activity() {
|
||||
let call = history_cell::new_active_mcp_tool_call(
|
||||
id,
|
||||
invocation,
|
||||
self.local_settings.tui.animations,
|
||||
);
|
||||
self.update_computer_activity(|cell| cell.complete(call, duration, result));
|
||||
self.bump_active_cell_revision();
|
||||
self.transcript.had_work_activity = true;
|
||||
self.request_redraw();
|
||||
return;
|
||||
}
|
||||
|
||||
let extra_cell = match self
|
||||
.transcript
|
||||
.active_cell
|
||||
@@ -250,6 +275,24 @@ impl ChatWidget {
|
||||
}
|
||||
}
|
||||
|
||||
/// Reuse only adjacent computer calls; all other active cells form a transcript boundary.
|
||||
fn update_computer_activity(
|
||||
&mut self,
|
||||
update: impl FnOnce(&mut history_cell::ComputerActivityCell),
|
||||
) {
|
||||
if let Some(cell) = self.transcript.active_cell.as_mut().and_then(|cell| {
|
||||
cell.as_any_mut()
|
||||
.downcast_mut::<history_cell::ComputerActivityCell>()
|
||||
}) {
|
||||
update(cell);
|
||||
} else {
|
||||
self.flush_active_cell();
|
||||
let mut cell = history_cell::ComputerActivityCell::default();
|
||||
update(&mut cell);
|
||||
self.transcript.active_cell = Some(Box::new(cell));
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn handle_queued_item_started_now(&mut self, item: ThreadItem) {
|
||||
match item {
|
||||
item @ ThreadItem::CommandExecution { .. } => {
|
||||
|
||||
Reference in new issue
Block a user