Compact successful command activity in the TUI (#38921)

## What changed

- Group consecutive successful agent and unified-exec startup commands into a compact `Ran N commands` entry while preserving their full transcript.
- Flush command groups at interaction boundaries, after failures, and after 32 completed commands. Keep manual shell commands and failed or declined commands visible.
- Apply the same grouping rules when replaying thread history without duplicating command starts or disturbing unrelated active commands.

## Testing

- Add TUI coverage for live and replayed grouping, transcript preservation, failures, overlapping commands, group limits, and interaction boundaries.

GitOrigin-RevId: d6602a20201644012fcff3d6cecf4690024383a9
This commit is contained in:
Eric Traut
2026-08-17 00:32:09 +00:00
committed by copyberry
parent 935b1c4e3d
commit 1f41cc5d92
18 changed files with 696 additions and 76 deletions
+66 -1
View File
@@ -14,6 +14,8 @@ use codex_app_server_protocol::CommandExecutionSource as ExecCommandSource;
use codex_protocol::parse_command::ParsedCommand;
use itertools::Either;
const MAX_GROUPED_COMMANDS: usize = 32;
#[derive(Debug, Default)]
pub(crate) struct CommandOutput {
pub(crate) exit_code: i32,
@@ -104,7 +106,38 @@ impl ExecCell {
duration: None,
interaction_input,
};
if self.is_exploring_cell() && Self::is_exploring_call(&call) {
let has_failed_call = self.calls.iter().any(|existing| {
existing
.output
.as_ref()
.is_some_and(|output| output.exit_code != 0)
});
if (self.calls.len() >= MAX_GROUPED_COMMANDS && !self.is_active())
|| (!Self::is_groupable_source(call.source) && !self.is_active())
|| (has_failed_call && !self.is_active())
{
return false;
}
let continues_exploration = Self::is_exploring_call(&call)
&& (self.is_exploring_cell()
|| self.calls.last().is_some_and(|existing| {
existing.duration.is_none() && Self::is_exploring_call(existing)
}))
&& (self.is_active()
|| self
.calls
.iter()
.all(|existing| Self::is_groupable_source(existing.source)));
let continues_compact_group = self.calls.iter().all(|existing| {
Self::is_groupable_source(existing.source)
&& existing.duration.is_some()
&& existing
.output
.as_ref()
.is_some_and(|output| output.exit_code == 0)
});
if continues_exploration || continues_compact_group {
self.calls.push(call);
true
} else {
@@ -133,6 +166,31 @@ impl ExecCell {
}
pub(crate) fn should_flush(&self) -> bool {
if self.calls.iter().any(|call| {
!Self::is_groupable_source(call.source)
|| call
.output
.as_ref()
.is_some_and(|output| output.exit_code != 0)
}) {
return !self.is_active();
}
if self.calls.len() >= MAX_GROUPED_COMMANDS {
return !self.is_active();
}
if self.calls.iter().all(|call| {
Self::is_groupable_source(call.source)
&& call.duration.is_some()
&& call
.output
.as_ref()
.is_some_and(|output| output.exit_code == 0)
}) {
return false;
}
!self.is_exploring_cell() && self.calls.iter().all(|c| c.duration.is_some())
}
@@ -202,6 +260,13 @@ impl ExecCell {
)
})
}
fn is_groupable_source(source: ExecCommandSource) -> bool {
matches!(
source,
ExecCommandSource::Agent | ExecCommandSource::UnifiedExecStartup
)
}
}
impl ExecCall {
+44 -2
View File
@@ -185,7 +185,9 @@ fn activity_marker(start_time: Option<Instant>, animations_enabled: bool) -> Spa
impl HistoryCell for ExecCell {
fn display_lines(&self, width: u16) -> Vec<Line<'static>> {
if self.is_exploring_cell() {
if self.calls.len() > 1 && (!self.is_exploring_cell() || !self.is_active()) {
self.compact_group_display_lines(width)
} else if self.is_exploring_cell() {
self.exploring_display_lines(width)
} else {
self.command_display_lines(width)
@@ -244,6 +246,42 @@ impl HistoryCell for ExecCell {
}
impl ExecCell {
fn compact_group_display_lines(&self, width: u16) -> Vec<Line<'static>> {
let completed_commands = self
.calls
.iter()
.take_while(|call| {
matches!(
call.source,
ExecCommandSource::Agent | ExecCommandSource::UnifiedExecStartup
) && call.duration.is_some()
&& call
.output
.as_ref()
.is_some_and(|output| output.exit_code == 0)
})
.count();
let mut lines = Vec::new();
if completed_commands > 0 {
let noun = if completed_commands == 1 {
"command"
} else {
"commands"
};
lines.push(Line::from(vec![
"•".green().bold(),
" ".into(),
format!("Ran {completed_commands} {noun}").bold(),
" · ".dim(),
TRANSCRIPT_HINT.dim(),
]));
}
for call in &self.calls[completed_commands..] {
lines.extend(self.command_call_display_lines(width, call));
}
lines
}
fn output_ellipsis_text(omitted: usize) -> String {
format!("… +{omitted} lines ({TRANSCRIPT_HINT})")
}
@@ -353,6 +391,10 @@ impl ExecCell {
let [call] = &self.calls.as_slice() else {
panic!("Expected exactly one call in a command display cell");
};
self.command_call_display_lines(width, call)
}
fn command_call_display_lines(&self, width: u16, call: &ExecCall) -> Vec<Line<'static>> {
let layout = EXEC_DISPLAY_LAYOUT;
let success = call
.duration
@@ -365,7 +407,7 @@ impl ExecCell {
let is_interaction = call.is_unified_exec_interaction();
let title = if is_interaction {
""
} else if self.is_active() {
} else if call.duration.is_none() {
"Running"
} else if call.is_user_shell_command() {
"You ran"