From 1824d7427065da487a19bea0e64b5cbb079fa142 Mon Sep 17 00:00:00 2001 From: Gabriel Peal Date: Wed, 25 Jun 2025 08:15:14 -0400 Subject: [PATCH] Works --- codex-rs/core/src/codex.rs | 4 ++++ codex-rs/core/src/protocol.rs | 7 +++++++ codex-rs/exec/src/event_processor.rs | 5 ++++- codex-rs/mcp-server/src/codex_tool_runner.rs | 1 + codex-rs/tui/src/app.rs | 9 +++++++-- codex-rs/tui/src/chatwidget.rs | 12 +++++------- codex-rs/tui/src/conversation_history_widget.rs | 4 ++++ codex-rs/tui/src/history_cell.rs | 13 +++++++++++++ 8 files changed, 45 insertions(+), 10 deletions(-) diff --git a/codex-rs/core/src/codex.rs b/codex-rs/core/src/codex.rs index 2837dd032e..0afbc1e18e 100644 --- a/codex-rs/core/src/codex.rs +++ b/codex-rs/core/src/codex.rs @@ -989,6 +989,10 @@ async fn run_turn( sub_id: String, input: Vec, ) -> CodexResult> { + debug!("[GABE] codex#run_turn"); + info!("[GABE] codex#run_turn"); + error!("[GABE] codex#run_turn"); + // Decide whether to use server-side storage (previous_response_id) or disable it let (prev_id, store) = { let state = sess.state.lock().unwrap(); diff --git a/codex-rs/core/src/protocol.rs b/codex-rs/core/src/protocol.rs index 737acc7732..10157bc528 100644 --- a/codex-rs/core/src/protocol.rs +++ b/codex-rs/core/src/protocol.rs @@ -352,6 +352,8 @@ pub enum EventMsg { ApplyPatchApprovalRequest(ApplyPatchApprovalRequestEvent), BackgroundEvent(BackgroundEventEvent), + + Log(LogEvent), /// Notification that the agent is about to apply a code patch. Mirrors /// `ExecCommandBegin` so front‑ends can show progress indicators. @@ -464,6 +466,11 @@ pub struct BackgroundEventEvent { pub message: String, } +#[derive(Debug, Clone, Deserialize, Serialize)] +pub struct LogEvent { + pub line: String, +} + #[derive(Debug, Clone, Deserialize, Serialize)] pub struct PatchApplyBeginEvent { /// Identifier so this can be paired with the PatchApplyEnd event. diff --git a/codex-rs/exec/src/event_processor.rs b/codex-rs/exec/src/event_processor.rs index 4cbbd25f0b..dfb9d6bae5 100644 --- a/codex-rs/exec/src/event_processor.rs +++ b/codex-rs/exec/src/event_processor.rs @@ -2,7 +2,6 @@ use codex_common::elapsed::format_elapsed; use codex_core::WireApi; use codex_core::config::Config; use codex_core::model_supports_reasoning_summaries; -use codex_core::protocol::AgentMessageEvent; use codex_core::protocol::BackgroundEventEvent; use codex_core::protocol::ErrorEvent; use codex_core::protocol::Event; @@ -15,6 +14,7 @@ use codex_core::protocol::McpToolCallEndEvent; use codex_core::protocol::PatchApplyBeginEvent; use codex_core::protocol::PatchApplyEndEvent; use codex_core::protocol::SessionConfiguredEvent; +use codex_core::protocol::{AgentMessageEvent, LogEvent}; use owo_colors::OwoColorize; use owo_colors::Style; use shlex::try_join; @@ -176,6 +176,9 @@ impl EventProcessor { EventMsg::BackgroundEvent(BackgroundEventEvent { message }) => { ts_println!(self, "{}", message.style(self.dimmed)); } + EventMsg::Log(LogEvent { line }) => { + ts_println!(self, "{}", line.style(self.dimmed)); + } EventMsg::TaskStarted | EventMsg::TaskComplete(_) => { // Ignore. } diff --git a/codex-rs/mcp-server/src/codex_tool_runner.rs b/codex-rs/mcp-server/src/codex_tool_runner.rs index 67c990b00c..e72aba0071 100644 --- a/codex-rs/mcp-server/src/codex_tool_runner.rs +++ b/codex-rs/mcp-server/src/codex_tool_runner.rs @@ -168,6 +168,7 @@ pub async fn run_codex_tool_session( | EventMsg::ExecCommandBegin(_) | EventMsg::ExecCommandEnd(_) | EventMsg::BackgroundEvent(_) + | EventMsg::Log(_) | EventMsg::PatchApplyBegin(_) | EventMsg::PatchApplyEnd(_) | EventMsg::GetHistoryEntryResponse(_) => { diff --git a/codex-rs/tui/src/app.rs b/codex-rs/tui/src/app.rs index ff61b5c941..06201ce406 100644 --- a/codex-rs/tui/src/app.rs +++ b/codex-rs/tui/src/app.rs @@ -9,7 +9,7 @@ use crate::scroll_event_helper::ScrollEventHelper; use crate::slash_command::SlashCommand; use crate::tui; use codex_core::config::Config; -use codex_core::protocol::Event; +use codex_core::protocol::{Event, EventMsg, LogEvent}; use codex_core::protocol::Op; use color_eyre::eyre::Result; use crossterm::event::KeyCode; @@ -228,7 +228,12 @@ impl<'a> App<'a> { AppState::Login { .. } | AppState::GitWarning { .. } => {} }, AppEvent::LatestLog(line) => match &mut self.app_state { - AppState::Chat { widget } => widget.update_latest_log(line), + AppState::Chat { widget } => widget.handle_codex_event(Event { + id: "123".to_string(), + msg: EventMsg::Log(LogEvent { + line: line.clone(), + }) + }), AppState::Login { .. } | AppState::GitWarning { .. } => {} }, AppEvent::DispatchCommand(command) => match command { diff --git a/codex-rs/tui/src/chatwidget.rs b/codex-rs/tui/src/chatwidget.rs index bd5197c73b..79ac9fb68c 100644 --- a/codex-rs/tui/src/chatwidget.rs +++ b/codex-rs/tui/src/chatwidget.rs @@ -3,7 +3,7 @@ use std::sync::Arc; use codex_core::codex_wrapper::init_codex; use codex_core::config::Config; -use codex_core::protocol::AgentMessageEvent; +use codex_core::protocol::{AgentMessageEvent, LogEvent}; use codex_core::protocol::AgentReasoningEvent; use codex_core::protocol::ApplyPatchApprovalRequestEvent; use codex_core::protocol::ErrorEvent; @@ -358,6 +358,10 @@ impl ChatWidget<'_> { self.bottom_pane .on_history_entry_response(log_id, offset, entry.map(|e| e.text)); } + EventMsg::Log(LogEvent { line }) => { + self.conversation_history.add_log_line(line); + self.request_redraw(); + } event => { self.conversation_history .add_background_event(format!("{event:?}")); @@ -366,12 +370,6 @@ impl ChatWidget<'_> { } } - /// Update the live log preview while a task is running. - pub(crate) fn update_latest_log(&mut self, line: String) { - // Forward only if we are currently showing the status indicator. - self.bottom_pane.update_status_text(line); - } - fn request_redraw(&mut self) { self.app_event_tx.send(AppEvent::Redraw); } diff --git a/codex-rs/tui/src/conversation_history_widget.rs b/codex-rs/tui/src/conversation_history_widget.rs index 714ac074a7..299d747351 100644 --- a/codex-rs/tui/src/conversation_history_widget.rs +++ b/codex-rs/tui/src/conversation_history_widget.rs @@ -205,6 +205,10 @@ impl ConversationHistoryWidget { pub fn add_background_event(&mut self, message: String) { self.add_to_history(HistoryCell::new_background_event(message)); } + + pub fn add_log_line(&mut self, line: String) { + self.add_to_history(HistoryCell::new_log_line(line)) + } pub fn add_error(&mut self, message: String) { self.add_to_history(HistoryCell::new_error_event(message)); diff --git a/codex-rs/tui/src/history_cell.rs b/codex-rs/tui/src/history_cell.rs index 481576b5b3..59e5328446 100644 --- a/codex-rs/tui/src/history_cell.rs +++ b/codex-rs/tui/src/history_cell.rs @@ -113,6 +113,8 @@ pub(crate) enum HistoryCell { /// behaviour of `ActiveExecCommand` so the user sees *what* patch the /// model wants to apply before being prompted to approve or deny it. PendingPatch { view: TextBlock }, + + Log { view: TextBlock } } const TOOL_CALL_MAX_LINES: usize = 5; @@ -459,6 +461,15 @@ impl HistoryCell { } } + pub(crate) fn new_log_line(message: String) -> Self { + let mut lines: Vec> = Vec::new(); + lines.extend(message.lines().map(|l| Line::from(l.to_string()).dim())); + HistoryCell::Log { + view: TextBlock::new(lines), + } + + } + pub(crate) fn new_error_event(message: String) -> Self { let lines: Vec> = vec![ vec!["ERROR: ".red().bold(), message.into()].into(), @@ -554,6 +565,7 @@ impl CellWidget for HistoryCell { | HistoryCell::CompletedMcpToolCall { view } | HistoryCell::PendingPatch { view } | HistoryCell::ActiveExecCommand { view, .. } + | HistoryCell::Log { view } | HistoryCell::ActiveMcpToolCall { view, .. } => view.height(width), HistoryCell::CompletedMcpToolCallWithImageOutput { image, @@ -575,6 +587,7 @@ impl CellWidget for HistoryCell { | HistoryCell::CompletedMcpToolCall { view } | HistoryCell::PendingPatch { view } | HistoryCell::ActiveExecCommand { view, .. } + | HistoryCell::Log { view } | HistoryCell::ActiveMcpToolCall { view, .. } => { view.render_window(first_visible_line, area, buf) }