{
+ let (label, color) = match state {
+ StepState::Failed => (tr("chat-status-failed"), theme::status_error()),
+ StepState::Stopped => (tr("chat-status-stopped"), theme::text_muted()),
+ StepState::Running | StepState::Done => return None,
+ };
+ Some(
+ div()
+ .flex_none()
+ .font_weight(gpui::FontWeight::NORMAL)
+ .text_xs()
+ .text_color(gpui::rgb(color))
+ .child(label),
)
}
@@ -1573,8 +1548,8 @@ pub(super) fn plan_finished(plan: &[PlanEntry]) -> bool {
.all(|entry| entry.status == PlanStatus::Completed)
}
-/// The transcript row of a finished todo list: a foldable card like a tool
-/// call's, or `None` while the list is unfinished and the pinned card
+/// The transcript row of a finished todo list: a step that opens like a
+/// tool call's, or `None` while the list is unfinished and the pinned card
/// shows it.
fn render_finished_plan(
item: &AgentTimelineItem,
@@ -1587,8 +1562,7 @@ fn render_finished_plan(
let count = format!("{}/{}", plan.len(), plan.len());
let item_id = item.id.clone();
let chat = transcript.chat.clone();
- let mut card = div()
- .id(SharedString::from(format!("plan-toggle-{item_id}")))
+ let header = step::step_header(SharedString::from(format!("plan-toggle-{item_id}")))
.debug_selector(|| "plan-row".to_string())
.role(gpui::Role::DisclosureTriangle)
.aria_label(
@@ -1597,61 +1571,46 @@ fn render_finished_plan(
.get("chat-plan-done", [("count", count.clone().into())]),
)
.aria_expanded(details)
- .flex()
- .flex_col()
- .gap_1()
- .px_3()
- .py_2()
- .rounded(theme::RADIUS_SM)
- .bg(gpui::rgb(theme::bg_tool_card()))
- .border_1()
- .border_color(gpui::rgb(theme::border_subtle()))
- .hover(|style| {
- style
- .border_color(gpui::rgb(theme::border()))
- .cursor_pointer()
- })
+ .cursor_pointer()
+ .font_weight(gpui::FontWeight::MEDIUM)
+ .text_color(gpui::rgb(StepState::Done.ink()))
+ .child(tr("chat-plan"))
+ .child(
+ div()
+ .font_weight(gpui::FontWeight::NORMAL)
+ .text_xs()
+ .text_color(gpui::rgb(theme::text_muted()))
+ .child(count),
+ )
+ .child(motion::chevron(
+ SharedString::from(format!("plan-chevron-{}", item.id)),
+ details,
+ px(14.),
+ theme::text_muted(),
+ ))
+ .hover_bg(theme::overlay_hover())
.on_click(move |_event, _window, cx: &mut gpui::App| {
chat.update(cx, |chat, cx| chat.toggle_tool(&item_id, cx))
.ok();
- })
- .child(
- div()
- .flex()
- .gap_2()
- .items_center()
- .child(
- div()
- .flex_1()
- .text_sm()
- .font_weight(gpui::FontWeight::SEMIBOLD)
- .text_color(gpui::rgb(theme::text_primary()))
- .child(tr("chat-plan")),
- )
- .child(
- div()
- .text_xs()
- .text_color(gpui::rgb(theme::text_muted()))
- .child(count),
- )
- .child(motion::chevron(
- SharedString::from(format!("plan-chevron-{}", item.id)),
- details,
- px(14.),
- theme::text_muted(),
- )),
- );
- if details {
- card = card.child(revealed(
+ });
+ let rows = details.then(|| {
+ revealed(
div()
.flex()
.flex_col()
.gap_1()
.children(plan.iter().map(render_plan_row)),
transcript.reveal,
- ));
- }
- Some(div().child(card))
+ )
+ .into_any_element()
+ });
+ Some(step::step(
+ "check",
+ StepState::Done,
+ transcript.rail,
+ header,
+ rows,
+ ))
}
/// One row of the subagent card: what the subagent was asked to do, the
@@ -1830,21 +1789,30 @@ pub(super) fn diff_lines_for(item: &AgentTimelineItem) -> Vec<(char, SharedStrin
lines
}
-/// Tool card whose payload renders as a colored diff when it carries
-/// edit/write replacements.
-fn render_tool_with_diff(
- item: &AgentTimelineItem,
- revision: u64,
- details: bool,
- transcript: &TranscriptCtx,
-) -> Div {
- let card = render_tool(item, revision, details, transcript);
- if !details {
- return card;
+/// How many lines an edit or write adds and removes, counted from the
+/// whole input. `diff_lines_for` stops at the display cap; this does not.
+pub(super) fn diff_counts(item: &AgentTimelineItem) -> (usize, usize) {
+ let Some(serde_json::Value::Object(map)) = item.input.as_ref() else {
+ return (0, 0);
+ };
+ let lines = |text: Option<&serde_json::Value>| {
+ text.and_then(|text| text.as_str())
+ .map_or(0, |text| text.lines().count())
+ };
+ let (mut added, mut removed) = (lines(map.get("content")), 0);
+ if let Some(serde_json::Value::Array(edits)) = map.get("edits") {
+ for edit in edits {
+ removed += lines(edit.get("oldText"));
+ added += lines(edit.get("newText"));
+ }
}
- let diff_lines = Arc::clone(&transcript.derived.get(item, revision).diff_lines);
- if diff_lines.is_empty() {
- return card;
+ (added, removed)
+}
+
+/// The +/- lines of an edit or write, coloured.
+fn render_diff(lines: &[(char, SharedString)]) -> Option
{
+ if lines.is_empty() {
+ return None;
}
let mut diff = div()
.flex()
@@ -1855,7 +1823,7 @@ fn render_tool_with_diff(
.border_1()
.border_color(gpui::rgb(theme::border_subtle()))
.overflow_x_hidden();
- for (sign, line) in diff_lines.iter() {
+ for (sign, line) in lines {
let color = match sign {
'+' => theme::status_success(),
'-' => theme::status_error(),
@@ -1885,18 +1853,7 @@ fn render_tool_with_diff(
),
);
}
- // The diff is content: swallow clicks so selecting it does not toggle.
- card.child(revealed(
- div()
- .id(gpui::SharedString::from(format!("tool-diff-{}", item.id)))
- .on_click(
- |_event: &gpui::ClickEvent, _window: &mut Window, cx: &mut gpui::App| {
- cx.stop_propagation();
- },
- )
- .child(diff),
- transcript.reveal,
- ))
+ Some(diff)
}
/// Title shown before the model summary arrives: just the tool label from
@@ -1922,138 +1879,126 @@ pub(super) fn tool_label_title(title: &str) -> &str {
}
}
+/// A tool call as a step. `diff`: an edit or write, whose details also
+/// show its replacements as a coloured diff.
fn render_tool(
item: &AgentTimelineItem,
revision: u64,
details: bool,
+ diff: bool,
transcript: &TranscriptCtx,
) -> Div {
- let (label, status_color) = tool_status_style(item.status.as_deref());
- let running = !matches!(
- item.status.as_deref(),
- Some("completed" | "failed" | "error" | "cancelled")
- );
+ let state = StepState::of(item.status.as_deref());
let item_id = item.id.clone();
- let chat_header = transcript.chat.clone();
+ let chat = transcript.chat.clone();
+ let derived = transcript.derived.get(item, revision);
// An external agent's row draws its own activity; a summary asked
// when its call started would hide what it did.
let summary = (!has_external_agent_activity(item))
.then(|| transcript.tool_summaries.get(&item.id).cloned())
.flatten();
- // The model summary stands in for the title; until it lands, show just
- // the tool label ("Terminal"), not the raw `tool: args` title.
- let title = summary.clone().unwrap_or_else(|| {
- if let Some(label) = crate::ui::timeline_labels::tool_label(item, transcript.messages)
- .or_else(|| crate::ui::timeline_labels::title(item, transcript.messages))
- {
- return label;
+ // The model summary stands in for the title; until it lands, the
+ // tool's name does ("Terminal"). Either leaves what the call acts on
+ // to the chip beside it.
+ let named =
+ summary.or_else(|| crate::ui::timeline_labels::tool_name(item, transcript.messages));
+ let acted_on = named.as_ref().and(derived.acted_on.clone());
+ let title = named.unwrap_or_else(|| {
+ if let Some(title) = crate::ui::timeline_labels::title(item, transcript.messages) {
+ return title;
}
let raw = item.title.as_deref().unwrap_or(&item.item_type);
SharedString::from(tool_label_title(raw).to_string())
});
- let card = div()
- .id(gpui::SharedString::from(format!("tool-toggle-{item_id}")))
- .debug_selector(|| "tool-card".to_string())
+ // Only the header toggles, so the details under it can be read and
+ // selected without folding them.
+ let header = step::step_header(SharedString::from(format!("tool-toggle-{item_id}")))
.role(gpui::Role::DisclosureTriangle)
.aria_label(title.clone())
.aria_expanded(details)
- .flex()
- .flex_col()
- .gap_1()
- .px_3()
- .py_2()
- .rounded(theme::RADIUS_SM)
- .bg(gpui::rgb(theme::bg_tool_card()))
- .border_1()
- .border_color(gpui::rgb(theme::border_subtle()))
- .hover(|style| {
- style
- .border_color(gpui::rgb(theme::border()))
- .cursor_pointer()
- })
- .on_click(move |_event, _window, cx: &mut gpui::App| {
- chat_header
- .update(cx, |chat, cx| {
- chat.toggle_tool(&item_id, cx);
- })
- .ok();
- })
+ .cursor_pointer()
+ .font_weight(gpui::FontWeight::MEDIUM)
+ .text_color(gpui::rgb(state.ink()))
.child(
div()
- .flex()
- .gap_2()
- .items_center()
- .child(
- div()
- // The summary is prose: it grows to fill the row
- // and ellipsizes at the row's end. Without min_w_0
- // the flex item collapses to its longest word and
- // the old middle-ellipsis cut mid-sentence inside
- // a sliver while the row sat empty.
- .min_w_0()
- .flex_1()
- .text_sm()
- .font_weight(gpui::FontWeight::SEMIBOLD)
- .text_color(gpui::rgb(theme::text_primary()))
- .truncate()
- .debug_selector(|| "tool-title".to_string())
- .child(title),
- )
- .child(tool_status(&item.id, running, label, status_color))
- .child(motion::chevron(
- SharedString::from(format!("tool-chevron-{}", item.id)),
- details,
- px(14.),
- theme::text_muted(),
- )),
- );
- // Collapsed: the header alone; the summary takes over the title when it lands.
- // Expanded cards also show the cached arguments and output.
- if !details {
- return div().child(card);
- }
- let derived = transcript.derived.get(item, revision);
- if let Some(activity) = &derived.external_agent {
- return div().child(card.child(revealed(
- render_external_agent_activity(item, revision, activity, transcript),
- transcript.reveal,
- )));
- }
- // A click anywhere on the card, payload included, toggles it.
- let mut payload = div().flex().flex_col().gap_1();
- // Expanded: the call arguments and the raw output. The summary is
- // made from the input alone, so it never stands in for the output.
- if let Some(input) = &derived.input_line {
- payload = payload.child(
- div()
- .text_xs()
- .text_color(gpui::rgb(theme::text_muted()))
- .font_family(crate::assets::FONT_MONO)
- .overflow_x_hidden()
- .child(gpui::text!(
- id = SharedString::from(format!("tool-input-{}", item.id)),
- input.clone()
- )),
- );
- }
- if let Some(output) = &derived.output_text {
- payload = payload.child(
- typography::chat_reading(div())
- .mt_1()
- .w_full()
- .text_color(gpui::rgb(theme::text_secondary()))
- .child(markdown::render_with(
- &transcript.markdown_cache.get(
- &item.id,
- MarkdownKind::ToolOutput,
- revision,
- output,
- ),
- &readable_ctx(transcript.render),
- )),
- );
- }
- div().child(card.child(revealed(payload, transcript.reveal)))
+ // The summary is prose: it takes the row's width before
+ // it ellipsizes at the row's end. Without min_w_0 the
+ // flex item would not shrink and would push the rest out.
+ .min_w_0()
+ .truncate()
+ .debug_selector(|| "tool-title".to_string())
+ .child(title),
+ )
+ .children(acted_on.map(step::chip))
+ // Counted from the call's input: true only once the edit landed.
+ .children(
+ derived
+ .changed
+ .as_ref()
+ .filter(|_| state == StepState::Done)
+ .map(step::changed),
+ )
+ .children(step_outcome(state))
+ .child(motion::chevron(
+ SharedString::from(format!("tool-chevron-{}", item.id)),
+ details,
+ px(14.),
+ theme::text_muted(),
+ ))
+ .hover_bg(theme::overlay_hover())
+ .on_click(move |_event, _window, cx: &mut gpui::App| {
+ chat.update(cx, |chat, cx| {
+ chat.toggle_tool(&item_id, cx);
+ })
+ .ok();
+ });
+ // Open: the call's arguments and its raw output. The summary is made
+ // from the input alone, so it never stands in for the output.
+ let body = details.then(|| {
+ if let Some(activity) = &derived.external_agent {
+ return render_external_agent_activity(item, revision, activity, transcript);
+ }
+ let mut payload = div().flex().flex_col().gap_1();
+ if let Some(input) = &derived.input_line {
+ payload = payload.child(
+ div()
+ .text_xs()
+ .text_color(gpui::rgb(theme::text_muted()))
+ .font_family(crate::assets::FONT_MONO)
+ .overflow_x_hidden()
+ .child(gpui::text!(
+ id = SharedString::from(format!("tool-input-{}", item.id)),
+ input.clone()
+ )),
+ );
+ }
+ if let Some(output) = &derived.output_text {
+ payload = payload.child(
+ typography::chat_reading(div())
+ .mt_1()
+ .w_full()
+ .text_color(gpui::rgb(theme::text_secondary()))
+ .child(markdown::render_with(
+ &transcript.markdown_cache.get(
+ &item.id,
+ MarkdownKind::ToolOutput,
+ revision,
+ output,
+ ),
+ &readable_ctx(transcript.render),
+ )),
+ );
+ }
+ payload.children(diff.then(|| render_diff(&derived.diff_lines)).flatten())
+ });
+ step::step(
+ step::tool_icon(item),
+ state,
+ transcript.rail,
+ header,
+ body.map(|body| revealed(body, transcript.reveal).into_any_element()),
+ )
+ .debug_selector(|| "tool-card".to_string())
}
/// Keep a card's output out of the shared selection, which would treat its
@@ -3593,7 +3538,7 @@ mod motion_tests {
}
#[gpui::test]
- fn a_turns_steps_stay_folded_until_its_line_is_clicked(cx: &mut TestAppContext) {
+ fn a_chunks_steps_stay_folded_until_its_header_is_clicked(cx: &mut TestAppContext) {
let _clock = Clock::start();
let (chat, cx) = pane(cx, 30);
// A finished turn after the history: two steps, then the reply.
@@ -3617,6 +3562,13 @@ mod motion_tests {
cx.simulate_click(line.center(), gpui::Modifiers::default());
redraw(&chat, cx);
+ assert!(
+ cx.debug_bounds("tool-card").is_none(),
+ "the turn line is informational"
+ );
+ let header = bounds(cx, "activity-chunk-call");
+ cx.simulate_click(header.center(), gpui::Modifiers::default());
+ redraw(&chat, cx);
let call = bounds(cx, "tool-card");
let thought = bounds(cx, "thinking-title");
assert_eq!(
@@ -3629,7 +3581,8 @@ mod motion_tests {
"the steps open under the line, in order: {line:?}, {call:?}, {thought:?}"
);
- cx.simulate_click(line.center(), gpui::Modifiers::default());
+ let header = bounds(cx, "activity-chunk-call");
+ cx.simulate_click(header.center(), gpui::Modifiers::default());
redraw(&chat, cx);
assert!(
cx.debug_bounds("tool-card").is_none(),
@@ -3658,7 +3611,7 @@ mod motion_tests {
}
#[gpui::test]
- fn the_line_keeps_its_place_when_the_turns_first_step_arrives(cx: &mut TestAppContext) {
+ fn the_line_hands_off_without_a_jump_as_the_first_chunk_enters(cx: &mut TestAppContext) {
let clock = Clock::start();
let (chat, cx) = pane(cx, 30);
// A run is going and nothing has come back yet: the line waits
@@ -3683,17 +3636,23 @@ mod motion_tests {
});
let tops =
tops_through_entrance(&chat, &clock, start, &["turn-line", "timeline-row-h29"], cx);
- assert!(
- tops[0].iter().all(|top| *top == waiting.origin.y),
- "the line stays where it waited ({:?}) once a row carries it: {:?}",
- waiting.origin.y,
- tops[0]
+ assert_eq!(tops[0][0], waiting.origin.y, "the line hands off in place");
+ assert_eq!(
+ tops[1][0], older.origin.y,
+ "older rows do not jump on handoff"
);
+ assert_glides(&tops[0], "the line above the arriving chunk header");
+ assert_glides(&tops[1], "the history above the arriving chunk header");
+ for (line, history) in tops[0].iter().zip(&tops[1]) {
+ assert_eq!(
+ *line - *history,
+ waiting.origin.y - older.origin.y,
+ "the header's entrance moves the line and history together"
+ );
+ }
assert!(
- tops[1].iter().all(|top| *top == older.origin.y),
- "older rows hold still: {:?} then {:?}",
- older.origin.y,
- tops[1]
+ bounds(cx, "activity-chunk-call").top() >= bounds(cx, "turn-line").bottom(),
+ "the inline disclosure settles below the informational line"
);
}
diff --git a/apps/maple-agent/app/src/ui/chat/turn.rs b/apps/maple-agent/app/src/ui/chat/turn.rs
index f21f072d0..945c3b940 100644
--- a/apps/maple-agent/app/src/ui/chat/turn.rs
+++ b/apps/maple-agent/app/src/ui/chat/turn.rs
@@ -1,24 +1,25 @@
-//! The line a turn's steps fold under.
+//! A turn's status line and independently disclosed activity chunks.
//!
-//! A turn is what Maple does between two messages from the user. Its
-//! thinking rows and tool calls are its steps. The first step carries the
-//! turn's line: the Maple mark, what Maple is doing, and for how long. The
-//! steps stay folded under the line until it is clicked. Before a turn has
-//! a step, the same line waits in the slot under the transcript.
+//! A turn runs between user messages. Visible messages and notices split
+//! its steps into chunks, without splitting its clock or animated status.
+use std::collections::HashMap;
use std::time::{Duration, Instant};
use gpui::{Context, Div, SharedString, div, prelude::*, px};
use maple_agent::agent::AgentTimelineItem;
use super::ChatScreen;
+use super::step;
use super::transcript::{
WAITING_ROW_HEIGHT, format_subagent_elapsed, has_tool_input, plan_entries, plan_finished,
};
use crate::ui::i18n::{MessageCache, tr};
use crate::ui::morph_text::morph_text;
use crate::ui::motion;
+use crate::ui::motion::HoverBg as _;
use crate::ui::theme;
+use crate::ui::{icons::icon, widgets};
/// Gap between two repaints of a running turn's time where loops hold
/// still. The time counts whole seconds, so one repaint a second is enough.
@@ -30,25 +31,87 @@ const RUN_TICK: Duration = Duration::from_secs(1);
const MARK_CYCLE: Duration = Duration::from_millis(2400);
const SHINE_CYCLE: Duration = Duration::from_millis(1900);
-/// What a transcript row is to its turn's line.
+/// A transcript row's place in its turn and activity chunk.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub(super) enum TurnRow {
- /// A message, a notice, an error: always shown.
Plain,
- /// The turn's first step. The line is drawn above it.
+ /// The first chunk also carries the turn's status line.
Lead,
- /// A later step, folded under the lead at this index.
+ Chunk,
Step(usize),
}
-/// Each loaded row's place in its turn, kept beside the timeline so no
-/// frame regroups it.
+impl TurnRow {
+ pub(super) fn lead(self, index: usize) -> Option {
+ match self {
+ Self::Plain => None,
+ Self::Lead | Self::Chunk => Some(index),
+ Self::Step(lead) => Some(lead),
+ }
+ }
+}
+
+/// Header data maintained on row changes, never derived during rendering.
+#[derive(Default)]
+pub(super) struct Chunk {
+ end: usize,
+ icons: Vec<(&'static str, usize)>,
+ states: [usize; 4],
+}
+
+impl Chunk {
+ fn add_icon(&mut self, icon: &'static str) {
+ if let Some((_, count)) = self.icons.iter_mut().find(|(name, _)| *name == icon) {
+ *count += 1;
+ } else {
+ self.icons.push((icon, 1));
+ }
+ }
+
+ fn add(&mut self, (icon, state): (&'static str, step::StepState)) {
+ self.add_icon(icon);
+ self.states[state as usize] += 1;
+ }
+
+ fn replace(
+ &mut self,
+ before: (&'static str, step::StepState),
+ after: (&'static str, step::StepState),
+ ) {
+ self.states[before.1 as usize] -= 1;
+ self.states[after.1 as usize] += 1;
+ if before.0 != after.0 {
+ for (name, count) in &mut self.icons {
+ if *name == before.0 {
+ *count -= 1;
+ }
+ }
+ self.icons.retain(|(_, count)| *count > 0);
+ self.add_icon(after.0);
+ }
+ }
+
+ pub(super) fn count(&self) -> usize {
+ self.states.iter().sum()
+ }
+
+ pub(super) fn state(&self, live: bool) -> Option {
+ use step::StepState;
+ [StepState::Failed, StepState::Running, StepState::Stopped]
+ .into_iter()
+ .find(|state| {
+ self.states[*state as usize] > 0 && (*state != StepState::Running || live)
+ })
+ }
+}
+
#[derive(Default)]
pub(super) struct Turns {
rows: Vec,
- /// The lead of the turn at the end of the loaded rows, once that turn
- /// has a step.
+ chunks: HashMap,
+ /// First step of the latest user turn, kept stable for its clock.
tail: Option,
+ chunk: Option,
}
fn starts_turn(item: &AgentTimelineItem) -> bool {
@@ -69,16 +132,44 @@ fn is_step(item: &AgentTimelineItem) -> bool {
matches!(item.item_type.as_str(), "thinking" | "reasoning")
}
-/// What decides a row's place in its turn: whether it starts one, and
-/// whether it is a step.
-pub(super) fn part(item: &AgentTimelineItem) -> (bool, bool) {
- (starts_turn(item), is_step(item))
+/// Classification changes can move both turn and chunk boundaries.
+pub(super) fn part(item: &AgentTimelineItem) -> (bool, bool, bool) {
+ let step = is_step(item);
+ (
+ starts_turn(item),
+ step,
+ !step && !is_tool(item) && super::navigation::timeline_item_is_navigable(item),
+ )
+}
+
+pub(super) fn step_info(item: &AgentTimelineItem) -> (&'static str, step::StepState) {
+ if is_tool(item) {
+ if has_tool_input(item, "todos") {
+ return ("check", step::StepState::Done);
+ }
+ return (
+ step::tool_icon(item),
+ step::StepState::of(item.status.as_deref()),
+ );
+ }
+ let state = if item
+ .text
+ .as_deref()
+ .is_none_or(|text| text.trim().is_empty())
+ {
+ step::StepState::Running
+ } else {
+ step::StepState::Done
+ };
+ ("brain", state)
}
impl Turns {
/// Group a whole timeline: a snapshot, a history page, a trimmed window.
pub(super) fn rebuild(&mut self, timeline: &[AgentTimelineItem]) {
self.rows.clear();
+ self.chunks.clear();
+ self.chunk = None;
self.tail = None;
for item in timeline {
self.push(item);
@@ -87,17 +178,35 @@ impl Turns {
/// One row arrived at the end.
pub(super) fn push(&mut self, item: &AgentTimelineItem) {
- let row = if starts_turn(item) {
+ let index = self.rows.len();
+ let (starts_turn, is_step, breaks_chunk) = part(item);
+ let row = if starts_turn {
self.tail = None;
+ self.chunk = None;
TurnRow::Plain
- } else if !is_step(item) {
+ } else if !is_step {
+ // Hidden plans and empty streamed messages do not separate
+ // the activities around them.
+ if breaks_chunk {
+ self.chunk = None;
+ }
TurnRow::Plain
- } else if let Some(lead) = self.tail {
+ } else if let Some(lead) = self.chunk {
TurnRow::Step(lead)
} else {
- self.tail = Some(self.rows.len());
- TurnRow::Lead
+ self.chunk = Some(index);
+ if self.tail.is_none() {
+ self.tail = Some(index);
+ TurnRow::Lead
+ } else {
+ TurnRow::Chunk
+ }
};
+ if let Some(lead) = row.lead(index) {
+ let chunk = self.chunks.entry(lead).or_default();
+ chunk.end = index + 1;
+ chunk.add(step_info(item));
+ }
self.rows.push(row);
}
@@ -109,17 +218,26 @@ impl Turns {
self.tail
}
- /// One past the last step of the turn led by the row at `lead`.
+ pub(super) fn chunk(&self, lead: usize) -> Option<&Chunk> {
+ self.chunks.get(&lead)
+ }
+
pub(super) fn end(&self, lead: usize) -> usize {
- let mut end = lead + 1;
- for (index, row) in self.rows.iter().enumerate().skip(end) {
- match row {
- TurnRow::Step(of) if *of == lead => end = index + 1,
- TurnRow::Lead => break,
- _ => {}
- }
+ self.chunk(lead).map_or(lead + 1, |chunk| chunk.end)
+ }
+
+ pub(super) fn update_step(
+ &mut self,
+ index: usize,
+ before: (&'static str, step::StepState),
+ after: (&'static str, step::StepState),
+ ) -> Option {
+ if before == after {
+ return None;
}
- end
+ let lead = self.row(index).lead(index)?;
+ self.chunks.get_mut(&lead)?.replace(before, after);
+ Some(lead)
}
}
@@ -350,17 +468,9 @@ fn maple_mark(mark: Mark, phase: f32) -> Div {
grid
}
-/// The line, as tall as the slot under the transcript it first shows in,
-/// so taking its place in the list moves nothing. `fold` names the turn's
-/// lead and says whether its steps show; the slot's line has no steps to
-/// open and passes `None`.
-pub(super) fn render_line(
- line: Line,
- fold: Option<(&str, bool)>,
- chat: &gpui::WeakEntity,
- messages: &MessageCache,
-) -> Div {
- let key = fold.map_or("slot", |(lead, _)| lead);
+/// The summary keeps the same height and identity when it takes over the
+/// waiting slot. Chunk disclosures do not replace or restart its motion.
+pub(super) fn render_line(line: Line, key: &str, messages: &MessageCache) -> Div {
let id = |part: &str| SharedString::from(format!("turn-{part}-{key}"));
let (label, mark, time) = match line {
Line::Live {
@@ -399,14 +509,24 @@ pub(super) fn render_line(
} else {
theme::text_secondary()
}))
- .child(if running {
- motion::ticker(id("mark"), MARK_CYCLE, |phase| {
- maple_mark(Mark::Working, phase).into_any_element()
- })
- .into_any_element()
- } else {
- maple_mark(mark, 0.).into_any_element()
- })
+ // The mark sits in the column of the steps' nodes, and the words
+ // start where the steps' titles do.
+ .child(
+ div()
+ .flex_none()
+ .w(step::NODE)
+ .mr(px(2.))
+ .flex()
+ .justify_center()
+ .child(if running {
+ motion::ticker(id("mark"), MARK_CYCLE, |phase| {
+ maple_mark(Mark::Working, phase).into_any_element()
+ })
+ .into_any_element()
+ } else {
+ maple_mark(mark, 0.).into_any_element()
+ }),
+ )
.child(if running {
words.shine(SHINE_CYCLE, gpui::rgb(theme::text_heading()))
} else {
@@ -421,31 +541,100 @@ pub(super) fn render_line(
.text_color(gpui::rgb(theme::text_muted()))
.child(gpui::text!(time))
}));
- let row = div().h(WAITING_ROW_HEIGHT).flex().items_center();
- let Some((lead, open)) = fold else {
- return row.child(button.role(gpui::Role::Status));
- };
- let lead = lead.to_owned();
- let chat = chat.clone();
- row.child(
- button
- .role(gpui::Role::DisclosureTriangle)
- .aria_expanded(open)
- .hover(|style| {
- style
- .cursor_pointer()
- .text_color(gpui::rgb(theme::text_primary()))
- })
- .child(motion::chevron(
- id("chevron"),
- open,
- px(14.),
- theme::text_muted(),
- ))
- .on_click(move |_event, _window, cx: &mut gpui::App| {
- chat.update(cx, |chat, cx| chat.toggle_turn(&lead, cx)).ok();
- }),
- )
+ div()
+ .h(WAITING_ROW_HEIGHT)
+ .flex()
+ .items_center()
+ .child(button.role(gpui::Role::Status))
+}
+
+pub(super) fn render_chunk(
+ lead: &str,
+ chunk: &Chunk,
+ open: bool,
+ live: bool,
+ chat: &gpui::WeakEntity,
+ messages: &MessageCache,
+) -> Div {
+ let label = messages.get("chat-activity-steps", [("count", chunk.count().into())]);
+ let status = chunk.state(live).map(|state| {
+ let (key, ink) = match state {
+ step::StepState::Failed => ("chat-status-failed", theme::status_error()),
+ step::StepState::Stopped => ("chat-status-stopped", theme::text_muted()),
+ _ => ("chat-status-running", theme::text_muted()),
+ };
+ let id = SharedString::from(format!("activity-status-{lead}"));
+ div()
+ .id(id.clone())
+ .debug_selector(move || id.to_string())
+ .role(gpui::Role::Status)
+ .aria_label(tr(key))
+ .text_xs()
+ .text_color(gpui::rgb(ink))
+ .child(gpui::text!(tr(key)))
+ });
+ let debug = format!("activity-chunk-{lead}");
+ let target = chat.clone();
+ let key = lead.to_owned();
+ div()
+ .flex()
+ .when(!open, |row| row.pb_2())
+ .items_start()
+ .child(
+ div()
+ .id(SharedString::from(format!("activity-toggle-{lead}")))
+ .debug_selector(move || debug.clone())
+ .role(gpui::Role::DisclosureTriangle)
+ .aria_label(label.clone())
+ .aria_expanded(open)
+ .tab_index(0)
+ .on_key_down(ChatScreen::sidebar_button_key_down)
+ .focus_visible(widgets::focus_ring)
+ .min_h(px(32.))
+ .max_w_full()
+ .px_2()
+ .ml(px(-8.))
+ .rounded(theme::RADIUS_SM)
+ .flex()
+ .flex_wrap()
+ .items_center()
+ .gap_2p5()
+ .text_sm()
+ .text_color(gpui::rgb(theme::text_secondary()))
+ .hover_bg(theme::overlay_hover())
+ .hover(|style| {
+ style
+ .cursor_pointer()
+ .text_color(gpui::rgb(theme::text_primary()))
+ })
+ .child(
+ div()
+ .w(step::NODE)
+ .flex()
+ .justify_center()
+ .child(motion::chevron(
+ SharedString::from(format!("activity-chevron-{lead}")),
+ open,
+ px(14.),
+ theme::text_muted(),
+ )),
+ )
+ .child(gpui::text!(label))
+ .child(
+ div().flex().gap_1p5().children(
+ chunk
+ .icons
+ .iter()
+ .map(|(name, _)| icon(name, px(12.), theme::text_muted())),
+ ),
+ )
+ .children(status)
+ .on_click(move |_, _, cx| {
+ target
+ .update(cx, |chat, cx| chat.toggle_chunk(&key, cx))
+ .ok();
+ }),
+ )
}
impl ChatScreen {
@@ -460,8 +649,8 @@ impl ChatScreen {
/// earlier one, and the line waits in the slot instead. A window that
/// is paged back in history, or still lacks the run's newest rows,
/// does not hold the turn the run works on at all.
- fn turn_runs(&self, lead: usize) -> bool {
- self.turns.tail() == Some(lead)
+ pub(super) fn turn_runs(&self, lead: usize) -> bool {
+ self.turns.tail().is_some_and(|turn| lead >= turn)
&& self.is_run_active()
&& !self.awaiting_first_token
&& !self.pages.after
@@ -506,25 +695,24 @@ impl ChatScreen {
}
}
- /// Whether the steps of the turn led by the row at `lead` show. "Show
- /// tool call details" opens every turn; a click on the line inverts
- /// that for its turn.
- pub(super) fn turn_open(&self, lead: usize) -> bool {
+ /// The existing details preference is the default; a click changes
+ /// only this chunk, including while more steps arrive in it.
+ pub(super) fn chunk_open(&self, lead: usize) -> bool {
self.timeline
.get(lead)
- .is_some_and(|item| self.tool_details != self.toggled_turns.contains(&item.id))
+ .is_some_and(|item| self.tool_details != self.toggled_chunks.contains(&item.id))
}
- /// Show or fold a turn's steps and re-measure their rows.
- pub(super) fn toggle_turn(&mut self, lead_id: &str, cx: &mut Context) {
+ /// Show or fold one chunk and re-measure only its rows.
+ pub(super) fn toggle_chunk(&mut self, lead_id: &str, cx: &mut Context) {
let Some(&(lead, _)) = self.timeline_index.get(lead_id) else {
return;
};
- if !self.toggled_turns.remove(lead_id) {
- self.toggled_turns.insert(lead_id.to_owned());
+ if !self.toggled_chunks.remove(lead_id) {
+ self.toggled_chunks.insert(lead_id.to_owned());
}
- let open = self.turn_open(lead);
- self.row_motion.disclose_turn(lead_id, open, motion::now());
+ let open = self.chunk_open(lead);
+ self.row_motion.disclose_chunk(lead_id, open, motion::now());
if !open {
self.keep_application_selection_shown(lead);
} else if self.list_state.is_following_tail()
@@ -637,8 +825,8 @@ impl ChatScreen {
/// A live row took its persisted id; what was kept under the old one
/// follows it.
pub(super) fn rekey_turn(&mut self, old: &str, new: &str) {
- if self.toggled_turns.remove(old) {
- self.toggled_turns.insert(new.to_owned());
+ if self.toggled_chunks.remove(old) {
+ self.toggled_chunks.insert(new.to_owned());
}
if let Some(worked) = self.turn_worked.remove(old) {
self.turn_worked.insert(new.to_owned(), worked);
@@ -701,11 +889,14 @@ mod tests {
}
#[test]
- fn a_turn_folds_its_later_steps_under_its_first() {
+ fn messages_split_chunks_without_splitting_the_turn() {
let timeline = [
item("message", Some("user")),
item("thinking", None),
- item("message", Some("assistant")),
+ AgentTimelineItem {
+ text: Some("Checking the remaining files.".into()),
+ ..item("message", Some("assistant"))
+ },
item("tool", None),
item("error", None),
item("message", Some("user")),
@@ -721,15 +912,15 @@ mod tests {
TurnRow::Plain,
TurnRow::Lead,
TurnRow::Plain,
- TurnRow::Step(1),
+ TurnRow::Chunk,
TurnRow::Plain,
TurnRow::Plain,
TurnRow::Plain,
TurnRow::Lead,
]
);
- // The first turn ends at its last step, not at the error after it.
- assert_eq!(turns.end(1), 4);
+ assert_eq!(turns.end(1), 2);
+ assert_eq!(turns.end(3), 4);
assert_eq!(turns.end(7), 8);
assert_eq!(turns.tail(), Some(7));
}
@@ -758,6 +949,103 @@ mod tests {
assert_eq!(live.tail(), None);
}
+ #[test]
+ fn hidden_plans_do_not_split_activity_and_status_updates_stay_in_their_chunk() {
+ let done = AgentTimelineItem {
+ status: Some("completed".into()),
+ ..item("tool", None)
+ };
+ let plan = AgentTimelineItem {
+ input: Some(serde_json::json!({"todos": [{"text": "Read", "status": "pending"}]})),
+ ..item("tool", None)
+ };
+ let mut turns = Turns::default();
+ turns.rebuild(&[done.clone(), plan, done.clone()]);
+ assert_eq!(turns.row(2), TurnRow::Step(0));
+ let chunk = turns.chunk(0).unwrap();
+ assert_eq!(chunk.count(), 2);
+ assert_eq!(chunk.state(true), None);
+ let failed = AgentTimelineItem {
+ status: Some("failed".into()),
+ ..done.clone()
+ };
+ assert_eq!(
+ turns.update_step(2, step_info(&done), step_info(&failed)),
+ Some(0)
+ );
+ assert_eq!(
+ turns.chunk(0).unwrap().state(false),
+ Some(step::StepState::Failed)
+ );
+ turns.update_step(2, step_info(&failed), step_info(&done));
+ assert_eq!(turns.chunk(0).unwrap().state(false), None);
+ assert_eq!(turns.chunk(0).unwrap().count(), 2);
+ turns.push(&AgentTimelineItem {
+ input: Some(serde_json::json!({"todos": [{"text": "Read", "status": "completed"}]})),
+ ..item("tool", None)
+ });
+ assert_eq!(turns.chunk(0).unwrap().count(), 3);
+ assert!(
+ turns
+ .chunk(0)
+ .unwrap()
+ .icons
+ .iter()
+ .any(|(icon, _)| *icon == "check")
+ );
+ }
+
+ #[test]
+ fn empty_messages_and_internal_rows_do_not_split_activity_chunks() {
+ let mut timeline = [
+ item("tool", None),
+ AgentTimelineItem {
+ text: Some("\n\n".into()),
+ ..item("message", Some("assistant"))
+ },
+ item("internal", None),
+ item("tool", None),
+ ];
+ let mut turns = Turns::default();
+ turns.rebuild(&timeline);
+ assert_eq!(turns.row(3), TurnRow::Step(0));
+ assert_eq!(turns.chunk(0).unwrap().count(), 2);
+ let before = part(&timeline[1]);
+ timeline[1].text = Some("Now checking the result.".into());
+ assert_ne!(before, part(&timeline[1]));
+ turns.rebuild(&timeline);
+ assert_eq!(turns.row(3), TurnRow::Chunk);
+ assert_eq!(turns.chunk(0).unwrap().count(), 1);
+ assert_eq!(turns.tail(), Some(0));
+ }
+
+ #[test]
+ fn finished_thinking_clears_its_chunk_status_during_a_live_turn() {
+ let thinking = item("thinking", None);
+ let mut turns = Turns::default();
+ turns.push(&thinking);
+ assert_eq!(
+ turns.chunk(0).unwrap().state(true),
+ Some(step::StepState::Running)
+ );
+ let done = AgentTimelineItem {
+ text: Some("The next action is clear.".into()),
+ ..thinking.clone()
+ };
+ turns.update_step(0, step_info(&thinking), step_info(&done));
+ assert_eq!(turns.chunk(0).unwrap().state(true), None);
+ turns.push(&AgentTimelineItem {
+ text: Some("Applying the change.".into()),
+ ..item("message", Some("assistant"))
+ });
+ turns.push(&item("tool", None));
+ assert_eq!(turns.chunk(0).unwrap().state(true), None);
+ assert_eq!(
+ turns.chunk(2).unwrap().state(true),
+ Some(step::StepState::Running)
+ );
+ }
+
#[test]
fn the_clock_stops_while_a_question_waits() {
let began = Instant::now();
diff --git a/apps/maple-agent/app/src/ui/timeline_labels.rs b/apps/maple-agent/app/src/ui/timeline_labels.rs
index dc5f45079..993378bc6 100644
--- a/apps/maple-agent/app/src/ui/timeline_labels.rs
+++ b/apps/maple-agent/app/src/ui/timeline_labels.rs
@@ -27,19 +27,7 @@ pub(crate) fn title(item: &AgentTimelineItem, cache: &MessageCache) -> Option tr("runtime-timeline-builtin-read"),
- "edit" => tr("runtime-timeline-builtin-edit"),
- "write" => tr("runtime-timeline-builtin-write"),
- "agent_start" => tr("runtime-timeline-agent-start"),
- "agent_send" => tr("runtime-timeline-agent-send"),
- "agent_status" => tr("runtime-timeline-agent-status"),
- "agent_cancel" => tr("runtime-timeline-agent-cancel"),
- "list_agent_providers" => tr("runtime-timeline-agent-providers"),
- _ => return None,
- })
- })?;
+ let name = tool_name(item, cache)?;
match &label.detail {
Some(detail) => cache.get(
"runtime-timeline-tool-detail",
@@ -111,6 +99,24 @@ pub(crate) fn body(item: &AgentTimelineItem, cache: &MessageCache) -> Option Option {
+ tool_label(item, cache).or_else(|| {
+ let label = item.label.as_ref().filter(|label| label.kind == "tool")?;
+ Some(match label.name.as_deref()? {
+ "read" => tr("runtime-timeline-builtin-read"),
+ "edit" => tr("runtime-timeline-builtin-edit"),
+ "write" => tr("runtime-timeline-builtin-write"),
+ "agent_start" => tr("runtime-timeline-agent-start"),
+ "agent_send" => tr("runtime-timeline-agent-send"),
+ "agent_status" => tr("runtime-timeline-agent-status"),
+ "agent_cancel" => tr("runtime-timeline-agent-cancel"),
+ "list_agent_providers" => tr("runtime-timeline-agent-providers"),
+ _ => return None,
+ })
+ })
+}
+
pub(crate) fn tool_label(item: &AgentTimelineItem, _cache: &MessageCache) -> Option {
let label = item.label.as_ref()?;
if label.kind != "tool" {
diff --git a/apps/maple-agent/app/translation-revisions/de.txt b/apps/maple-agent/app/translation-revisions/de.txt
index f2fd49ea9..6793328af 100644
--- a/apps/maple-agent/app/translation-revisions/de.txt
+++ b/apps/maple-agent/app/translation-revisions/de.txt
@@ -2,6 +2,7 @@
chat-absolute-path a2ba378ac24704c4
chat-active 196d1c9462f99ad3
chat-activity-outside dc914a2d8037659c
+chat-activity-steps a12bb21490dd0f51
chat-agent-task-cancelled e26bb0917a4c240b
chat-agents-running 15f7861d7b1f2dc3
chat-all-settings f521b783e34e05d0
@@ -354,7 +355,6 @@ chat-staging-unsafe-directory 13ed7aa88e08c0a8
chat-starting f00ec83fc396c4b0
chat-starting-agent 0e61b8da983ef787
chat-status-allowed 11310a7438dc9e0c
-chat-status-completed f7f8f9dd4adb3a0c
chat-status-denied deee947bb13482c4
chat-status-done 54904e435ce0c52e
chat-status-failed 3aa7979f86ebefa0
diff --git a/apps/maple-agent/app/translation-revisions/es.txt b/apps/maple-agent/app/translation-revisions/es.txt
index f2fd49ea9..6793328af 100644
--- a/apps/maple-agent/app/translation-revisions/es.txt
+++ b/apps/maple-agent/app/translation-revisions/es.txt
@@ -2,6 +2,7 @@
chat-absolute-path a2ba378ac24704c4
chat-active 196d1c9462f99ad3
chat-activity-outside dc914a2d8037659c
+chat-activity-steps a12bb21490dd0f51
chat-agent-task-cancelled e26bb0917a4c240b
chat-agents-running 15f7861d7b1f2dc3
chat-all-settings f521b783e34e05d0
@@ -354,7 +355,6 @@ chat-staging-unsafe-directory 13ed7aa88e08c0a8
chat-starting f00ec83fc396c4b0
chat-starting-agent 0e61b8da983ef787
chat-status-allowed 11310a7438dc9e0c
-chat-status-completed f7f8f9dd4adb3a0c
chat-status-denied deee947bb13482c4
chat-status-done 54904e435ce0c52e
chat-status-failed 3aa7979f86ebefa0
diff --git a/apps/maple-agent/app/translation-revisions/ko.txt b/apps/maple-agent/app/translation-revisions/ko.txt
index f2fd49ea9..6793328af 100644
--- a/apps/maple-agent/app/translation-revisions/ko.txt
+++ b/apps/maple-agent/app/translation-revisions/ko.txt
@@ -2,6 +2,7 @@
chat-absolute-path a2ba378ac24704c4
chat-active 196d1c9462f99ad3
chat-activity-outside dc914a2d8037659c
+chat-activity-steps a12bb21490dd0f51
chat-agent-task-cancelled e26bb0917a4c240b
chat-agents-running 15f7861d7b1f2dc3
chat-all-settings f521b783e34e05d0
@@ -354,7 +355,6 @@ chat-staging-unsafe-directory 13ed7aa88e08c0a8
chat-starting f00ec83fc396c4b0
chat-starting-agent 0e61b8da983ef787
chat-status-allowed 11310a7438dc9e0c
-chat-status-completed f7f8f9dd4adb3a0c
chat-status-denied deee947bb13482c4
chat-status-done 54904e435ce0c52e
chat-status-failed 3aa7979f86ebefa0
diff --git a/apps/maple-agent/docs/motion.md b/apps/maple-agent/docs/motion.md
index 0ae290a0e..9a3f93ecc 100644
--- a/apps/maple-agent/docs/motion.md
+++ b/apps/maple-agent/docs/motion.md
@@ -85,13 +85,13 @@ the shared 15 fps `ticker` clock and pause in background windows.
| Screen change (Chat ↔ Settings) and Settings sections | new content fades in, `REVEAL` | immediate |
| Empty state ↔ conversation (first message, opening a task, New Task) | the composer changes place at once | at once |
| Switching tasks | transcript fades in when its snapshot lands, `REVEAL` | immediate |
-| Live transcript rows at the end of the thread (sent message, reply, thinking, tool card, error, stop notice) | height grows from 0 and the row fades in, `ENTER`, so older rows glide up; scrolled up, a fade and 6 px rise | — |
+| Live transcript rows at the end of the thread (sent message, reply, thinking, tool call, error, stop notice) | height grows from 0 and the row fades in, `ENTER`, so older rows glide up; scrolled up, a fade and 6 px rise | — |
| Sent message | the composer empties at once and the bubble's slot opens from the height it gave up, so the thread does not drop; the bubble rises in, the real row takes its exact place, and "Sending…" and the turn's line share one slot under it | — |
-| Tool status | spinner leaves at once, the outcome fades in, `TOGGLE` | — |
+| A step's state | a running step is dim and inks at once when it finishes; nothing on it loops, the turn's line carries the motion | — |
| Disclosed details (tool output, thinking) | fade in, `REVEAL` | immediate |
| Streaming text | grows in place, no animation | — |
| A turn's line ("Maple is thinking", "Worked for 11s") | fades in under the transcript, `REVEAL`, and keeps its place when the turn's first step takes it into the list; while Maple works a shine crosses the words and the mark's blocks shrink and grow one at a time all the way around the M's outline, never both shining; the words morph when they change and the time counts whole seconds | immediate |
-| A turn's steps, shown from its line | fade in, `REVEAL`; the chevron turns, `TOGGLE` | immediate |
+| Activity chunks between visible messages, shown from their inline headers | fade in independently, `REVEAL`; each chevron turns, `TOGGLE` | immediate |
| Notices, queued messages, cards above the composer | fade and rise, `ENTER` | immediate |
| Files attached to the draft | fade and 6 px rise, `ENTER` | immediate |
| Composer and multi-line fields | height eases to the new line count, `resize(distance)` | same |
@@ -103,6 +103,12 @@ the shared 15 fps `ticker` clock and pause in background windows.
| Sidebar collapse | width eases, `PANEL` | same, reversed |
| Task status in the sidebar, project folders | indicators and folder icons cross-fade, `TOGGLE` | same |
+The turn's line stays informational and keeps one clock for the whole turn.
+Each activity chunk has its own disclosure; folding one leaves the other
+chunks and the assistant's explanations alone. Tool details keep their own
+disclosure state. Chunk headers use the same hover and chevron motion as
+other controls; they do not add another looping indicator.
+
Loading spinners for work that usually finishes quickly (opening a task)
appear only after 300 ms, so fast loads never flash a spinner.