[2/3] Retain the TUI last exec history cell so that it can be updated by the next tool call (#2097)
Right now, every time an exec ends, we emit it to history which makes it immutable. In order to be able to update or merge successive tool calls (which will be useful after https://github.com/openai/codex/pull/2095), we need to retain it as the active cell. This also changes the cell to contain the metadata necessary to render it so it can be updated rather than baking in the final text lines when the cell is created. Part 1: https://github.com/openai/codex/pull/2095 Part 3: https://github.com/openai/codex/pull/2110
This commit is contained in:
@@ -81,12 +81,11 @@ pub(crate) enum HistoryCell {
|
||||
/// Message from the user.
|
||||
UserPrompt { view: TextBlock },
|
||||
|
||||
// AgentMessage and AgentReasoning variants were unused and have been removed.
|
||||
/// An exec tool call that has not finished yet.
|
||||
ActiveExecCommand { view: TextBlock },
|
||||
|
||||
/// Completed exec tool call.
|
||||
CompletedExecCommand { view: TextBlock },
|
||||
Exec {
|
||||
command: Vec<String>,
|
||||
parsed: Vec<ParsedCommand>,
|
||||
output: Option<CommandOutput>,
|
||||
},
|
||||
|
||||
/// An MCP tool call that has not finished yet.
|
||||
ActiveMcpToolCall { view: TextBlock },
|
||||
@@ -123,7 +122,7 @@ pub(crate) enum HistoryCell {
|
||||
SessionInfo { view: TextBlock },
|
||||
|
||||
/// A pending code patch that is awaiting user approval. Mirrors the
|
||||
/// behaviour of `ActiveExecCommand` so the user sees *what* patch the
|
||||
/// behaviour of `ExecCell` so the user sees *what* patch the
|
||||
/// model wants to apply before being prompted to approve or deny it.
|
||||
PendingPatch { view: TextBlock },
|
||||
|
||||
@@ -173,15 +172,18 @@ impl HistoryCell {
|
||||
| HistoryCell::PromptsOutput { view }
|
||||
| HistoryCell::ErrorEvent { view }
|
||||
| HistoryCell::SessionInfo { view }
|
||||
| HistoryCell::CompletedExecCommand { view }
|
||||
| HistoryCell::CompletedMcpToolCall { view }
|
||||
| HistoryCell::PendingPatch { view }
|
||||
| HistoryCell::PlanUpdate { view }
|
||||
| HistoryCell::PatchApplyResult { view }
|
||||
| HistoryCell::ActiveExecCommand { view, .. }
|
||||
| HistoryCell::ActiveMcpToolCall { view, .. } => {
|
||||
view.lines.iter().map(line_to_static).collect()
|
||||
}
|
||||
HistoryCell::Exec {
|
||||
command,
|
||||
parsed,
|
||||
output,
|
||||
} => HistoryCell::exec_command_lines(command, parsed, output.as_ref()),
|
||||
HistoryCell::CompletedMcpToolCallWithImageOutput { .. } => vec![
|
||||
Line::from("tool result (image output omitted)"),
|
||||
Line::from(""),
|
||||
@@ -268,10 +270,7 @@ impl HistoryCell {
|
||||
command: Vec<String>,
|
||||
parsed: Vec<ParsedCommand>,
|
||||
) -> Self {
|
||||
let lines = HistoryCell::exec_command_lines(&command, &parsed, None);
|
||||
HistoryCell::ActiveExecCommand {
|
||||
view: TextBlock::new(lines),
|
||||
}
|
||||
HistoryCell::new_exec_cell(command, parsed, None)
|
||||
}
|
||||
|
||||
pub(crate) fn new_completed_exec_command(
|
||||
@@ -279,9 +278,18 @@ impl HistoryCell {
|
||||
parsed: Vec<ParsedCommand>,
|
||||
output: CommandOutput,
|
||||
) -> Self {
|
||||
let lines = HistoryCell::exec_command_lines(&command, &parsed, Some(&output));
|
||||
HistoryCell::CompletedExecCommand {
|
||||
view: TextBlock::new(lines),
|
||||
HistoryCell::new_exec_cell(command, parsed, Some(output))
|
||||
}
|
||||
|
||||
fn new_exec_cell(
|
||||
command: Vec<String>,
|
||||
parsed: Vec<ParsedCommand>,
|
||||
output: Option<CommandOutput>,
|
||||
) -> Self {
|
||||
HistoryCell::Exec {
|
||||
command,
|
||||
parsed,
|
||||
output,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -290,10 +298,9 @@ impl HistoryCell {
|
||||
parsed: &[ParsedCommand],
|
||||
output: Option<&CommandOutput>,
|
||||
) -> Vec<Line<'static>> {
|
||||
if parsed.is_empty() {
|
||||
HistoryCell::new_exec_command_generic(command, output)
|
||||
} else {
|
||||
HistoryCell::new_parsed_command(parsed, output)
|
||||
match parsed.is_empty() {
|
||||
true => HistoryCell::new_exec_command_generic(command, output),
|
||||
false => HistoryCell::new_parsed_command(parsed, output),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user