diff --git a/codex-rs/tui/src/chatwidget.rs b/codex-rs/tui/src/chatwidget.rs index cb037e0aeb..94ac8d7961 100644 --- a/codex-rs/tui/src/chatwidget.rs +++ b/codex-rs/tui/src/chatwidget.rs @@ -240,8 +240,7 @@ impl ChatWidget<'_> { self.request_redraw()?; } EventMsg::Error { message } => { - self.conversation_history - .add_background_event(format!("Error: {message}")); + self.conversation_history.add_error(message); self.bottom_pane.set_task_running(false)?; } EventMsg::ExecApprovalRequest { diff --git a/codex-rs/tui/src/conversation_history_widget.rs b/codex-rs/tui/src/conversation_history_widget.rs index f8fc53f920..fde5ea34b9 100644 --- a/codex-rs/tui/src/conversation_history_widget.rs +++ b/codex-rs/tui/src/conversation_history_widget.rs @@ -174,6 +174,10 @@ impl ConversationHistoryWidget { self.add_to_history(HistoryCell::new_background_event(message)); } + pub fn add_error(&mut self, message: String) { + self.add_to_history(HistoryCell::new_error_event(message)); + } + /// Add a pending patch entry (before user approval). pub fn add_patch_event( &mut self, diff --git a/codex-rs/tui/src/history_cell.rs b/codex-rs/tui/src/history_cell.rs index d8e2b2e289..2590a01168 100644 --- a/codex-rs/tui/src/history_cell.rs +++ b/codex-rs/tui/src/history_cell.rs @@ -69,6 +69,9 @@ pub(crate) enum HistoryCell { /// Background event BackgroundEvent { lines: Vec> }, + /// Error event from the backend. + ErrorEvent { lines: Vec> }, + /// Info describing the newly‑initialized session. SessionInfo { lines: Vec> }, @@ -245,6 +248,12 @@ impl HistoryCell { HistoryCell::BackgroundEvent { lines } } + pub(crate) fn new_error_event(message: String) -> Self { + let lines: Vec> = + vec![vec!["ERROR".red().bold(), message.into()].into(), "".into()]; + HistoryCell::ErrorEvent { lines } + } + pub(crate) fn new_session_info(config: &Config, model: String) -> Self { let mut lines: Vec> = Vec::new(); @@ -332,6 +341,7 @@ impl HistoryCell { HistoryCell::UserPrompt { lines, .. } | HistoryCell::AgentMessage { lines, .. } | HistoryCell::BackgroundEvent { lines, .. } + | HistoryCell::ErrorEvent { lines, .. } | HistoryCell::SessionInfo { lines, .. } | HistoryCell::ActiveExecCommand { lines, .. } | HistoryCell::CompletedExecCommand { lines, .. }