Collapse completed turn activity beneath transcript prompts (#60557)

## What changed

- Fold earlier commentary, reasoning, and tool activity beneath an expandable prompt control in the full-screen transcript, keeping partial and final answers visible.
- Label the control with completion timing when available, or a previous-message count otherwise. Keep tool groups independently expandable within the turn.
- Preserve assistant message phases during live completion and replay, and retain untimed completion markers to identify completed turns.

## Testing

Add transcript coverage for nested expansion, keyboard and mouse controls, narrow viewports, search anchor preservation, detailed mode, and legacy messages without phase or timing metadata.

GitOrigin-RevId: b17d9d7c870990178d76d12a13d463ff9c32b96c
This commit is contained in:
Eric Traut
2026-11-10 08:36:09 +00:00
committed by copyberry
parent bcbb7f5a9c
commit a7a9d82f15
20 changed files with 412 additions and 90 deletions
+28 -4
View File
@@ -166,6 +166,13 @@ impl TranscriptView {
.bold()
.remove_modifier(Modifier::DIM),
);
} else if layout.is_turn_disclosure() {
buf.set_style(
area,
Style::default()
.fg(crate::style::user_message_accent_color())
.bold(),
);
} else if row == usize::from(layout.separated) {
buf.set_style(area, Style::default().underlined());
}
@@ -334,11 +341,18 @@ impl TranscriptView {
let Some(layout) = self.layout(cells, index) else {
return false;
};
if !layout.disclosure {
let Some(control) = layout.disclosure_row() else {
return false;
}
};
let ids = self.activity_ids(cells, index);
let row = usize::from(layout.separated);
let row = if matches!(
self.turn_row(cells, index),
Some(turn_details::TurnRow::Prompt { .. })
) {
control
} else {
usize::from(layout.separated)
};
let visible = self.visible.iter().any(|visible| {
visible.row == row && visible.activity_ids.iter().any(|id| ids.contains(id))
});
@@ -381,6 +395,12 @@ impl TranscriptView {
if self.search.has_active_query() && !matched {
if let Some(snapshot) = &mut self.held_reading {
snapshot.pinned.remove(&key);
if let Some(details) = &self.turn_details {
for child in details.child_keys(index) {
snapshot.pinned.remove(&child);
snapshot.activities.remove(&child);
}
}
}
} else {
self.release_live_reading();
@@ -391,7 +411,11 @@ impl TranscriptView {
.and_then(|(key, top_ids, offset, row_bias)| {
let unchanged = cells.iter().position(|cell| EntryKey::cell(cell) == key);
let top = unchanged.or_else(|| self.canonical_activity_index(cells, &top_ids))?;
let preserve_offset = unchanged.is_some() && top != index;
let prompt = matches!(
self.turn_row(cells, top),
Some(turn_details::TurnRow::Prompt { .. })
);
let preserve_offset = unchanged.is_some() && (top != index || prompt);
Some(Anchor {
key: cells.get(top).map_or(EntryKey::Live, EntryKey::cell),
index: top,
+12 -6
View File
@@ -240,12 +240,17 @@ impl TranscriptView {
}
let mode = self.mode;
let mut presentation = self.content_presentation(cell.as_ref(), full_content, mode);
let mut turn_header = None;
if !full_content && let Some(row) = self.turn_row(cells, index) {
let ids = row.ids();
presentation.expanded = self.disclosure.is_expanded(ids);
presentation.summarized = true;
match &row {
turn_details::TurnRow::Prompt { label, .. } => {
let arrow = if presentation.expanded { "▾" } else { "▸" };
turn_header = Some(format!("{arrow} {label}"));
}
turn_details::TurnRow::Tools(_) => {
let ids = row.ids();
presentation.expanded = self.disclosure.is_expanded(ids);
presentation.summarized = true;
if presentation.expanded {
self.disclosure.expanded.extend(ids.iter().cloned());
}
@@ -253,9 +258,7 @@ impl TranscriptView {
row.layout(width, presentation.expanded, Vec::new())
}));
}
turn_details::TurnRow::Hidden => {
return Some(Arc::new(TextLayout::new(Vec::new(), width)));
}
_ => return Some(Arc::new(TextLayout::new(Vec::new(), width))),
}
}
let shortcut = self
@@ -302,6 +305,9 @@ impl TranscriptView {
if shares_prompt_background {
layout = layout.without_leading_blank_row();
}
if let Some(label) = turn_header {
layout = layout.with_turn_disclosure(label);
}
layout
}))
}
+73 -36
View File
@@ -53,9 +53,15 @@ pub(crate) struct TextLayout {
disclosure_control: Option<DisclosureControl>,
}
#[derive(Clone, Copy, PartialEq)]
enum DisclosureAnchor {
Activity(usize),
Turn,
}
struct DisclosureControl {
anchor: DisclosureAnchor,
label: String,
source_offset: usize,
row: usize,
}
@@ -160,8 +166,7 @@ impl TextLayout {
pub(super) fn rewrap(&self, width: u16) -> Self {
let mut layout = Self::from_logical(self.logical.clone(), width);
if let Some(control) = &self.disclosure_control {
layout =
layout.with_disclosure_control_at(control.label.clone(), control.source_offset);
layout = layout.with_control(control.label.clone(), control.anchor);
}
layout.image = self.image.clone();
if self.leading_blank_hidden {
@@ -181,46 +186,63 @@ impl TextLayout {
}
/// Place a control after an activity, before any following auxiliary source text.
pub(super) fn with_disclosure_control_at(
mut self,
label: String,
source_offset: usize,
) -> Self {
pub(super) fn with_disclosure_control_at(self, label: String, source_offset: usize) -> Self {
self.with_control(label, DisclosureAnchor::Activity(source_offset))
}
pub(super) fn with_turn_disclosure(self, label: String) -> Self {
self.with_control(label, DisclosureAnchor::Turn)
}
pub(super) fn is_turn_disclosure(&self) -> bool {
self.disclosure_control
.as_ref()
.is_some_and(|control| control.anchor == DisclosureAnchor::Turn)
}
fn with_control(mut self, label: String, anchor: DisclosureAnchor) -> Self {
if label.is_empty() {
return self;
}
if let Some(control) = self.disclosure_control.take() {
self.rows.remove(control.row);
if control.anchor == DisclosureAnchor::Turn {
self.rows.remove(control.row - 1);
}
}
let source_offset = self
.text
.floor_char_boundary(source_offset.min(self.text.len()));
let control_row = self
let source_offset = match anchor {
DisclosureAnchor::Activity(offset) => {
self.text.floor_char_boundary(offset.min(self.text.len()))
}
DisclosureAnchor::Turn => self.text.len(),
};
let mut control_row = self
.rows
.iter()
.rposition(|row| row.source.end <= source_offset)
.map_or(/*default*/ 0, |row| row + 1);
let indent = usize::from(self.width / 4).min(/*other*/ 4);
let indent = match anchor {
DisclosureAnchor::Activity(_) => usize::from(self.width / 4).min(/*other*/ 4),
DisclosureAnchor::Turn => {
self.insert_presentation_row(
control_row,
source_offset,
/*indent*/ 0,
Line::default(),
);
control_row += 1;
0
}
};
let line = truncate_line_to_width(
Line::from(format!("{}{label}", " ".repeat(indent))).dim(),
usize::from(self.width),
);
self.rows.insert(
control_row,
TextRow {
line: HyperlinkLine::from(line),
source: source_offset..source_offset,
line_end: None,
content_width: self.width,
first_column: indent,
prefix_columns: indent,
tabs: tabs::TabStops::default(),
},
);
self.insert_presentation_row(control_row, source_offset, indent, line);
self.disclosure = true;
self.disclosure_control = Some(DisclosureControl {
anchor,
label,
source_offset,
row: control_row,
});
self
@@ -254,17 +276,11 @@ impl TextLayout {
/// Reserve one presentation-only row before existing spacing and source text.
pub(super) fn with_leading_spacer(mut self) -> Self {
if !self.rows.is_empty() {
self.rows.insert(
self.insert_presentation_row(
/*index*/ 0,
TextRow {
line: HyperlinkLine::from(""),
source: 0..0,
line_end: None,
content_width: self.width,
first_column: 0,
prefix_columns: 0,
tabs: tabs::TabStops::default(),
},
/*offset*/ 0,
/*indent*/ 0,
Line::default(),
);
if let Some(control) = &mut self.disclosure_control {
control.row += 1;
@@ -273,6 +289,27 @@ impl TextLayout {
self
}
fn insert_presentation_row(
&mut self,
index: usize,
offset: usize,
indent: usize,
line: Line<'static>,
) {
self.rows.insert(
index,
TextRow {
line: HyperlinkLine::from(line),
source: offset..offset,
line_end: None,
content_width: self.width,
first_column: indent,
prefix_columns: indent,
tabs: tabs::TabStops::default(),
},
);
}
/// Source text between adjacent retained fragments; distinct logical lines have a hard break.
pub(super) fn separator_after(&self, next: &Self) -> &str {
if let Some(previous) = self.logical.last()
@@ -2,12 +2,18 @@
//! and scrollback retain their original cells, including command output.
use super::*;
use crate::history_cell::AgentMarkdownCell;
use crate::history_cell::AgentMessageCell;
use crate::history_cell::DynamicToolCallCell;
use crate::history_cell::FinalMessageSeparator;
use crate::history_cell::ReasoningSummaryCell;
use crate::history_cell::UserHistoryCell;
use crate::history_cell::WebSearchCell;
use codex_protocol::models::MessagePhase;
#[derive(Clone)]
pub(crate) enum TurnRow {
Prompt { id: String, label: String },
Tools(Arc<ToolGroup>),
Hidden,
}
@@ -15,6 +21,7 @@ pub(crate) enum TurnRow {
impl TurnRow {
pub(crate) fn ids(&self) -> &[String] {
match self {
Self::Prompt { id, .. } => std::slice::from_ref(id),
Self::Tools(group) => &group.ids,
Self::Hidden => &[],
}
@@ -70,6 +77,7 @@ pub(super) struct TurnDetails {
struct Entry {
key: EntryKey,
parent: Option<usize>,
row: Option<TurnRow>,
}
@@ -151,6 +159,13 @@ impl ToolGroup {
}
impl TurnDetails {
pub(super) fn child_keys(&self, parent: usize) -> impl Iterator<Item = EntryKey> + '_ {
self.rows
.iter()
.filter(move |entry| entry.parent == Some(parent))
.map(|entry| entry.key)
}
fn index_turn(
&mut self,
cells: &[Arc<dyn HistoryCell>],
@@ -159,16 +174,27 @@ impl TurnDetails {
) {
let rows = &mut self.rows;
let start = rows.len();
let has_prompt = cells
.first()
.is_some_and(|cell| cell.as_any().is::<UserHistoryCell>());
let keys = cells
.iter()
.map(EntryKey::cell)
.chain(latest.then_some(EntryKey::Live));
rows.extend(keys.map(|key| Entry { key, row: None }));
rows.extend(keys.map(|key| Entry {
key,
parent: None,
row: None,
}));
let rows = &mut rows[start..];
let mut group = ToolGroup::default();
if latest && !self.live.0.is_empty() {
group.push(rows, cells.len(), self.live.1.clone(), self.live.0.clone());
}
let mut completion = None;
let mut separator = None;
let mut fold = false;
let mut hidden_count = 0;
let mut searches = std::collections::HashSet::new();
for (index, cell) in cells.iter().enumerate().rev() {
// Keep older calls outside the group whose disclosure is pinned on screen.
@@ -187,7 +213,43 @@ impl TurnDetails {
rows[index].row = Some(TurnRow::Hidden);
continue;
}
let markdown = any.downcast_ref::<AgentMarkdownCell>();
let phase = markdown.and_then(|message| message.phase.as_ref());
let calls = cell.tool_call_labels();
if let Some(done) = any.downcast_ref::<FinalMessageSeparator>() {
// /review can complete another turn under the same prompt.
// A live timestamp can arrive immediately after an untimed replay marker.
if separator.is_none_or(|(next, _)| next != index + 1)
|| done.display_label().is_some()
{
separator = Some((index, done));
}
fold = false;
} else if phase == Some(&MessagePhase::FinalAnswer)
|| (!fold
&& separator.is_some()
&& ((markdown.is_some() && phase.is_none())
|| any.is::<crate::history_cell::ProposedPlanCell>()))
{
// An answer item can finish before its turn succeeds.
fold |= separator.is_some();
} else if fold
&& phase != Some(&MessagePhase::PartialAnswer)
&& has_prompt
&& (!calls.is_empty()
|| markdown.is_some()
|| any.is::<AgentMessageCell>()
|| any
.downcast_ref::<ReasoningSummaryCell>()
.is_some_and(|reasoning| !reasoning.is_transcript_only()))
{
rows[index].parent = Some(start);
hidden_count += calls.len().max(1);
if let Some((at, done)) = separator.take() {
rows[at].row = Some(TurnRow::Hidden);
completion.get_or_insert(done);
}
}
if let Some(tool) = any.downcast_ref::<DynamicToolCallCell>()
&& tool.is_active()
{
@@ -213,6 +275,18 @@ impl TurnDetails {
}
}
group.finish(rows, cells);
if hidden_count > 0 {
let label = completion
.and_then(FinalMessageSeparator::display_label)
.unwrap_or_else(|| match hidden_count {
1 => "1 previous message".into(),
count => format!("{count} previous messages"),
});
rows[0].row = Some(TurnRow::Prompt {
id: format!("turn:{:?}", rows[0].key),
label,
});
}
}
}
@@ -322,6 +396,12 @@ impl TranscriptView {
let details = self.turn_details.as_ref()?;
let key = cells.get(index).map_or(EntryKey::Live, EntryKey::cell);
let entry = details.rows.get(index).filter(|entry| entry.key == key)?;
if let Some(parent) = entry.parent
&& let Some(TurnRow::Prompt { id, .. }) = &details.rows[parent].row
&& !self.disclosure.expanded.contains(id)
{
return Some(TurnRow::Hidden);
}
entry.row.clone()
}
}
+4 -2
View File
@@ -17,8 +17,10 @@ impl TranscriptView {
cells
.last()
.filter(|cell| {
cell.as_any()
.is::<crate::history_cell::FinalMessageSeparator>()
self.turn_row(cells, cells.len() - 1).is_none()
&& cell
.as_any()
.is::<crate::history_cell::FinalMessageSeparator>()
&& !cell.display_lines(area.width).is_empty()
})
.map(EntryKey::cell)