Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions codex-rs/tui/src/app/agent_message_consolidation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use super::resize_reflow::trailing_run_start;
use crate::app_event::ConsolidationScrollbackReflow;
use crate::history_cell;
use crate::history_cell::HistoryCell;
use crate::inline_visualization::InlineVisualizationContext;
use crate::pager_overlay::Overlay;
use crate::tui;

Expand All @@ -26,6 +27,7 @@ impl App {
tui: &mut tui::Tui,
source: String,
cwd: PathBuf,
inline_visualization_context: Option<InlineVisualizationContext>,
scrollback_reflow: ConsolidationScrollbackReflow,
deferred_history_cell: Option<Box<dyn HistoryCell>>,
) -> Result<()> {
Expand All @@ -52,8 +54,13 @@ impl App {
tracing::debug!(
"ConsolidateAgentMessage: replacing cells [{start}..{end}] with AgentMarkdownCell"
);
let consolidated: Arc<dyn HistoryCell> =
Arc::new(history_cell::AgentMarkdownCell::new(source, &cwd));
let consolidated: Arc<dyn HistoryCell> = Arc::new(
history_cell::AgentMarkdownCell::new_with_inline_visualizations(
source,
&cwd,
inline_visualization_context,
),
);
self.transcript_cells
.splice(start..end, std::iter::once(consolidated.clone()));

Expand Down
2 changes: 2 additions & 0 deletions codex-rs/tui/src/app/event_dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,13 +317,15 @@ impl App {
AppEvent::ConsolidateAgentMessage {
source,
cwd,
inline_visualization_context,
scrollback_reflow,
deferred_history_cell,
} => {
self.handle_consolidate_agent_message(
tui,
source,
cwd,
inline_visualization_context,
scrollback_reflow,
deferred_history_cell,
)?;
Expand Down
1 change: 1 addition & 0 deletions codex-rs/tui/src/app/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5036,6 +5036,7 @@ async fn required_stream_reflow_during_capped_initial_replay_survives_transcript
"Final answer:\n\n| Pattern | Outcome |\n| --- | --- |\n| Table tail | Preserved |"
.to_string(),
PathBuf::from("/tmp"),
/*inline_visualization_context*/ None,
ConsolidationScrollbackReflow::Required,
/*deferred_history_cell*/ None,
)?;
Expand Down
2 changes: 2 additions & 0 deletions codex-rs/tui/src/app_event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use std::path::PathBuf;
use std::sync::Arc;
use std::sync::atomic::AtomicBool;

use crate::inline_visualization::InlineVisualizationContext;
use codex_app_server_protocol::AddCreditsNudgeCreditType;
use codex_app_server_protocol::AddCreditsNudgeEmailStatus;
use codex_app_server_protocol::ConsumeAccountRateLimitResetCreditResponse;
Expand Down Expand Up @@ -734,6 +735,7 @@ pub(crate) enum AppEvent {
ConsolidateAgentMessage {
source: String,
cwd: PathBuf,
inline_visualization_context: Option<InlineVisualizationContext>,
scrollback_reflow: ConsolidationScrollbackReflow,
deferred_history_cell: Option<Box<dyn HistoryCell>>,
},
Expand Down
16 changes: 15 additions & 1 deletion codex-rs/tui/src/chatwidget/streaming.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,17 @@ impl ChatWidget {
if let Some(source) = source {
let source =
parse_assistant_markdown(&source, self.config.cwd.as_path()).visible_markdown;
let inline_visualization_context = self.thread_id.and_then(|thread_id| {
crate::inline_visualization::InlineVisualizationContext::from_config(
&self.config,
thread_id,
)
});
self.note_stream_consolidation_queued();
self.app_event_tx.send(AppEvent::ConsolidateAgentMessage {
source,
cwd: self.config.cwd.to_path_buf(),
inline_visualization_context,
scrollback_reflow,
deferred_history_cell,
});
Expand Down Expand Up @@ -408,10 +415,17 @@ impl ChatWidget {
// Reset the flag even if we don't show separator (no work was done)
self.transcript.needs_final_message_separator = false;
}
self.stream_controller = Some(StreamController::new(
let inline_visualization_context = self.thread_id.and_then(|thread_id| {
crate::inline_visualization::InlineVisualizationContext::from_config(
&self.config,
thread_id,
)
});
self.stream_controller = Some(StreamController::new_with_inline_visualizations(
self.current_stream_width(/*reserved_cols*/ 2),
&self.config.cwd,
self.history_render_mode(),
inline_visualization_context,
));
}
if let Some(controller) = self.stream_controller.as_mut()
Expand Down
20 changes: 19 additions & 1 deletion codex-rs/tui/src/history_cell/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,7 @@ impl HistoryCell for AgentMessageCell {
pub(crate) struct AgentMarkdownCell {
markdown_source: String,
cwd: PathBuf,
inline_visualization_context: Option<crate::inline_visualization::InlineVisualizationContext>,
}

impl AgentMarkdownCell {
Expand All @@ -373,10 +374,26 @@ impl AgentMarkdownCell {
/// `markdown_source` must be the raw source accumulated by the stream controller, not already
/// wrapped terminal lines. Passing rendered lines here would make future resize reflow preserve
/// stale wrapping instead of repairing it.
#[cfg(test)]
pub(crate) fn new(markdown_source: String, cwd: &Path) -> Self {
Self::new_with_inline_visualizations(
markdown_source,
cwd,
/*inline_visualization_context*/ None,
)
}

pub(crate) fn new_with_inline_visualizations(
markdown_source: String,
cwd: &Path,
inline_visualization_context: Option<
crate::inline_visualization::InlineVisualizationContext,
>,
) -> Self {
Self {
markdown_source,
cwd: cwd.to_path_buf(),
inline_visualization_context,
}
}
}
Expand All @@ -399,10 +416,11 @@ impl HistoryCell for AgentMarkdownCell {

// Re-render markdown from source at the current width. Reserve 2 columns for the "• " /
// " " prefix prepended below.
let lines = crate::markdown::render_markdown_agent_with_links_and_cwd(
let lines = crate::markdown::render_markdown_agent_with_links_cwd_and_visualizations(
&self.markdown_source,
Some(wrap_width),
Some(self.cwd.as_path()),
self.inline_visualization_context.as_ref(),
);
prefix_hyperlink_lines(lines, "• ".dim(), " ".into())
}
Expand Down
8 changes: 4 additions & 4 deletions codex-rs/tui/src/history_cell/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -349,10 +349,10 @@ fn composite_cell_preserves_child_web_links() {

assert_eq!(
lines[2].hyperlinks,
vec![crate::terminal_hyperlinks::TerminalHyperlink {
columns: 0..destination.len(),
destination: destination.to_string(),
}]
vec![crate::terminal_hyperlinks::TerminalHyperlink::web(
/*columns*/ 0..destination.len(),
destination.to_string(),
)]
);
}

Expand Down
Loading
Loading