diff --git a/apps/desktop/src/kernel.rs b/apps/desktop/src/kernel.rs index 0c5b058e0..63eec4f72 100644 --- a/apps/desktop/src/kernel.rs +++ b/apps/desktop/src/kernel.rs @@ -157,7 +157,8 @@ pub fn build() -> Kernel { crate::diagram::view(s, p, cx) }) .above("overlay.attachments.viewer") - .with_key(crate::diagram::key), + .with_key(crate::diagram::key) + .after_key("overlay.tool_details"), ); b.register_overlay( OverlayRegistration::::new("overlay.tool_details") @@ -165,7 +166,8 @@ pub fn build() -> Kernel { let p = crate::palette::pal(s.dark(cx)); session_view::tools::details_overlay(s, p, cx) }) - .above("overlay.diagram"), + .above("overlay.diagram") + .with_key(session_view::tools::details_key), ); b.register_overlay( OverlayRegistration::::new("overlay.tab_preview") diff --git a/apps/desktop/src/session/composer/add_selection.rs b/apps/desktop/src/session/composer/add_selection.rs index 18cac6ca4..b3c302f94 100644 --- a/apps/desktop/src/session/composer/add_selection.rs +++ b/apps/desktop/src/session/composer/add_selection.rs @@ -35,6 +35,7 @@ impl App { let file = ContextFile { path, start, end }; // One card per file and range (`contextItemKey`). if !self.composer_ext.attach.context.contains(&file) { + tx.follow_edge(); self.composer_ext.attach.context.push(file); } } diff --git a/apps/desktop/src/session/composer/win_clipboard.rs b/apps/desktop/src/session/composer/win_clipboard.rs index 80753a8f7..254326ee7 100644 --- a/apps/desktop/src/session/composer/win_clipboard.rs +++ b/apps/desktop/src/session/composer/win_clipboard.rs @@ -122,6 +122,7 @@ pub(crate) fn poll(s: &mut App, tx: &mut Tx) -> bool { if let Some(png) = png { if attachments::attach_pasted_image(s, "image/png", "png", png) { tx.instant(); + tx.follow_edge(); changed = true; } } else if let Some(fb) = fallback { diff --git a/apps/desktop/src/session/inbox/send.rs b/apps/desktop/src/session/inbox/send.rs index 78eaf194d..f5f3c281b 100644 --- a/apps/desktop/src/session/inbox/send.rs +++ b/apps/desktop/src/session/inbox/send.rs @@ -196,8 +196,11 @@ impl App { self.admit_with(&id, prompt, if queue { Delivery::Queue } else { Delivery::Steer }, queue_first); if queue { // Sent in place, the reader stays where they are. - if session_view::TimelineHost::smooth_timeline(self) && !stay_in_place { - tx.follow_edge(); + if session_view::TimelineHost::smooth_timeline(self) { + tx.animated(); + if !stay_in_place { + tx.follow_edge(); + } } tx.motion(opencode_ui::roll::SLIDE); tx.launch(from.as_str(), format!("queued-{local}")); diff --git a/apps/desktop/src/session/inbox/send_failed/mod.rs b/apps/desktop/src/session/inbox/send_failed/mod.rs index 1b8086c7f..0c3f3213a 100644 --- a/apps/desktop/src/session/inbox/send_failed/mod.rs +++ b/apps/desktop/src/session/inbox/send_failed/mod.rs @@ -171,6 +171,10 @@ impl SendFailedHost for App { crate::quote::send_result(self, id, result); } + fn is_session_busy(&self, session: &str) -> bool { + self.busy(session) + } + fn is_queue_busy(&self, session: &str) -> bool { self.kernel.slots.get(&crate::queue::QUEUE_OPS).get(session).is_some_and(crate::queue::machine::Queue::busy) } diff --git a/apps/desktop/src/shell/commands/type_to_compose.rs b/apps/desktop/src/shell/commands/type_to_compose.rs index a75f32d37..d3aa7ec23 100644 --- a/apps/desktop/src/shell/commands/type_to_compose.rs +++ b/apps/desktop/src/shell/commands/type_to_compose.rs @@ -129,6 +129,7 @@ fn paste(s: &mut App, content: &ClipboardContent, draft: Option, require } if attachments::paste_immediate(s, content) { tx.instant(); + tx.follow_edge(); return; } let fallback = FallbackText::from_content(content); @@ -187,6 +188,7 @@ fn read_named_image( if let Some(bytes) = data.filter(|b| attachments::valid_image_bytes(mime, b)) { if attachments::attach_pasted_image(s, mime, ext, bytes) { tx.instant(); + tx.follow_edge(); } return; } diff --git a/apps/desktop/src/shell/view/composer.rs b/apps/desktop/src/shell/view/composer.rs index ea64fa6c2..c49444e0f 100644 --- a/apps/desktop/src/shell/view/composer.rs +++ b/apps/desktop/src/shell/view/composer.rs @@ -396,6 +396,7 @@ impl ComposerHost for App { self.kernel.slots.get(&crate::suggestions::SUGGEST).state.held_height() } fn composer_on_change(&mut self, tx: &mut Tx) { + tx.follow_edge(); crate::dictation::dismiss_error(self); crate::plugin_host::services::composer_state::on_composer_edit(self); crate::tab_hints::cancel(self, tx); diff --git a/crates/opencode-ui/src/scroller.rs b/crates/opencode-ui/src/scroller.rs index 2e1d247db..fcc6ea837 100644 --- a/crates/opencode-ui/src/scroller.rs +++ b/crates/opencode-ui/src/scroller.rs @@ -133,12 +133,13 @@ pub struct Scroller { stable: bool, always: bool, both_axes: bool, + h_track_offset: (f32, f32), } /// A vertical scroll container keyed `key`, with `scrollbar.css`'s bar unless [`Scroller::bar`] /// says otherwise. pub fn scroller(key: impl Into) -> Scroller { - Scroller { key: Rc::from(key.into()), spec: ScrollSpec { stick_bottom: false }, bar: Bar::Native, stable: false, always: false, both_axes: false } + Scroller { key: Rc::from(key.into()), spec: ScrollSpec { stick_bottom: false }, bar: Bar::Native, stable: false, always: false, both_axes: false, h_track_offset: (0.0, 0.0) } } impl Scroller { @@ -169,6 +170,13 @@ impl Scroller { self } + /// Offsets the horizontal scroll bar's track inward from `(start, end)` (for example past a + /// sticky left line-number gutter so the thumb stays inside the scrolling code column). + pub fn horizontal_track_offset(mut self, start: f32, end: f32) -> Self { + self.h_track_offset = (start, end); + self + } + /// Desktop's counterpart has `bar`, not `scrollbar.css`'s. pub fn bar(mut self, bar: Bar) -> Self { self.bar = bar; @@ -188,10 +196,16 @@ impl Scroller { pub fn build(self, p: &Pal, viewport: El, content: El) -> El { let viewport = viewport.key(self.key.to_string()).scroll(self.spec); let viewport = if self.both_axes { viewport.scroll_xy() } else { viewport }; + let (h_start, h_end) = self.h_track_offset; let attach = |el: El, style: ScrollBarStyle| { let style = if self.always { style.always_visible() } else { style }; if self.both_axes { - el.scroll_bars_xy_styled(style, style.horizontal()) + let h_style = if h_start != 0.0 || h_end != 0.0 { + style.horizontal().track_offset(h_start, h_end) + } else { + style.horizontal() + }; + el.scroll_bars_xy_styled(style, h_style) } else { el.scroll_bar_styled(style) } @@ -199,7 +213,7 @@ impl Scroller { match self.bar { Bar::Native => { let bar = if self.always { native_bar(p).always_visible() } else { native_bar(p) }; - native::(bar, self.key, self.stable, self.both_axes, viewport, content) + native::(bar, self.h_track_offset, self.key, self.stable, self.both_axes, viewport, content) } Bar::ScrollView => attach(viewport.child(content), ScrollBarStyle::scroll_view(kit(p))), Bar::MenuScroll => attach(viewport.child(content), ScrollBarStyle::menu_scroll(p.border_muted, p.q.border_strong)), @@ -218,10 +232,15 @@ fn tree_bar(fg: Color, bg: Color) -> ScrollBarStyle { /// `scrollbar.css`'s bar: the content's 8 point gutter while it overflows, measured from both /// heights, and the bar in it. Only a change in whether it overflows runs the view again. -fn native(bar: ScrollBarStyle, key: Rc, stable: bool, both_axes: bool, viewport: El, content: El) -> El { +fn native(bar: ScrollBarStyle, (h_start, h_end): (f32, f32), key: Rc, stable: bool, both_axes: bool, viewport: El, content: El) -> El { let attach = |el: El| { if both_axes { - el.scroll_bars_xy_styled(bar, bar.horizontal()) + let h_bar = if h_start != 0.0 || h_end != 0.0 { + bar.horizontal().track_offset(h_start, h_end) + } else { + bar.horizontal() + }; + el.scroll_bars_xy_styled(bar, h_bar) } else { el.scroll_bar_styled(bar) } diff --git a/crates/session-view/src/composer/attachments.rs b/crates/session-view/src/composer/attachments.rs index f07bf1dff..e764993e1 100644 --- a/crates/session-view/src/composer/attachments.rs +++ b/crates/session-view/src/composer/attachments.rs @@ -196,6 +196,7 @@ pub fn paste(s: &mut S, content: &ClipboardContent, tx: &mut Tx return false; } if paste_immediate(s, content) { + tx.follow_edge(); return true; } #[cfg(not(target_arch = "wasm32"))] @@ -205,6 +206,7 @@ pub fn paste(s: &mut S, content: &ClipboardContent, tx: &mut Tx if let Some(bytes) = data.filter(|b| valid_image_bytes(mime, b)) { if attach_pasted_image(s, mime, ext, bytes) { tx.instant(); + tx.follow_edge(); } } else if let Some(fb) = fallback { fb.apply(s, tx); @@ -422,6 +424,7 @@ pub fn remove_button( .group_opacity(if crate::style::hover_none() { 1.0 } else { 0.0 }, 1.0) .on_press_tx(move |s: &mut S, tx: &mut Tx| { tx.instant(); + tx.follow_edge(); on(s); }) .child(icon(&ic::XMARK_SMALL, 12.0).color(p.icon_contrast)) diff --git a/crates/session-view/src/composer/mod.rs b/crates/session-view/src/composer/mod.rs index e9ee61ec3..5b7a3058f 100644 --- a/crates/session-view/src/composer/mod.rs +++ b/crates/session-view/src/composer/mod.rs @@ -34,11 +34,14 @@ pub const SHELL_PROMPT: TextStyle = TextStyle::new(13.0, 440.0).mono().lh(20.0). /// the timeline cuts to its end, where the message already stands. pub fn land(s: &mut S, session: &str, local: &str, from: &str, tx: &mut Tx) { if s.ends().at_end(session) { - tx.motion(opencode_ui::roll::SLIDE); - tx.follow_edge(); - if s.smooth_timeline() { + if s.smooth_timeline() && !s.reduced_motion() { + // Clear any earlier `tx.instant()` (e.g. closing an open suggestion/history popover) + // and opt poll-driven sends (dictation, held-submit) into `SLIDE` motion. + tx.animated(); tx.unclipped_flights(); } + tx.motion(opencode_ui::roll::SLIDE); + tx.follow_edge(); let gate = s.working_state().fades.launch(local); tx.launch_gated(from, format!("u-{local}/bubble"), gate); } else { @@ -54,11 +57,12 @@ pub fn land(s: &mut S, session: &str, local: &str, from: &str, /// Like [`land`], but keeps a scrolled-up timeline where it is instead of jumping to the end. pub fn land_in_place(s: &mut S, session: &str, local: &str, from: &str, tx: &mut Tx) { if s.ends().at_end(session) { - tx.motion(opencode_ui::roll::SLIDE); - tx.follow_edge(); - if s.smooth_timeline() { + if s.smooth_timeline() && !s.reduced_motion() { + tx.animated(); tx.unclipped_flights(); } + tx.motion(opencode_ui::roll::SLIDE); + tx.follow_edge(); let gate = s.working_state().fades.launch(local); tx.launch_gated(from, format!("u-{local}/bubble"), gate); } @@ -357,7 +361,9 @@ pub trait ComposerHost: TimelineHost { fn composer_held_height(&self) -> Option { None } - fn composer_on_change(&mut self, _tx: &mut Tx) {} + fn composer_on_change(&mut self, tx: &mut Tx) { + tx.follow_edge(); + } fn composer_set_hovered(&mut self, _hovered: bool) {} fn composer_on_key(&mut self, _ev: &KeyEvent, _tx: &mut Tx) -> bool { false @@ -586,9 +592,11 @@ pub fn composer_in(s: &S, p: &Pal, scope: &str) -> El { .min_h(if docked && s.composer_shell_mode() { 44.0 } else { 88.0 }) // `rounded-xl` (`editor.tsx:254`): the app's `--radius-xl` is 0.625rem (`theme.css:50`). .corners([RADIUS; 4]) - .on_hover_change(|s: &mut S, inside, tx: &mut Tx| { + // Never call window-wide `tx.instant()` here: when a multi-line composer shrinks on + // submit out from under a still pointer, `on_hover_change(false)` would wipe scroll + // `Slack` and snap the in-flight `SLIDE` launch; `effort-slot` already sets `INSTANT`. + .on_hover_change(|s: &mut S, inside, _: &mut Tx| { s.composer_set_hovered(inside); - tx.instant(); }); // A face with surfaces of its own keeps its shadows: no card under it and no clip over it. // Otherwise `--v2-elevation-raised` (`editor.tsx:248-251`): two drops, a 0.5 pt ring and diff --git a/crates/session-view/src/disclosure.rs b/crates/session-view/src/disclosure.rs index 35ecfa16c..0b921d968 100644 --- a/crates/session-view/src/disclosure.rs +++ b/crates/session-view/src/disclosure.rs @@ -420,15 +420,15 @@ pub fn anchor(s: &mut S, tx: &mut Tx, opening: bool, row: &str, /// as it always does. pub fn anchor_grow(s: &mut S, tx: &mut Tx, opening: bool, row: &str, header: &str) { let id = s.active_session_id().map(str::to_owned); - let at_end = id.as_deref().is_some_and(|id| s.ends().at_end(id)); - if at_end && !opening { + if id.as_deref().is_some_and(|id| s.ends().at_end(id)) { + if opening { + // Hold `row`'s top across the fold; if growing pushes the transcript's end below the + // viewport, Rune's `keep_on_screen` detaches `stick_bottom` and emits `AtBottom(false)`. + // If it still fits at the end, `Ends` stays `Following` in sync with `at_bottom`. + tx.keep_on_screen(row.to_owned()); + } return; } - if at_end { - // Leave the end before the fold grows: Rune rides a fold pinned to its end from its - // bottom, which is what scrolls the prompt's start away. - let _ = s.ends_mut().step(id.as_deref(), crate::follow::Event::AtEnd(false)); - } if let Some(crate::follow::Effect::Keep(key)) = s.ends_mut().step(id.as_deref(), crate::follow::Event::Disclosure { opening, row, header }) { tx.keep_on_screen(key); } diff --git a/crates/session-view/src/genui/inline.rs b/crates/session-view/src/genui/inline.rs index 9f9775863..b6b383379 100644 --- a/crates/session-view/src/genui/inline.rs +++ b/crates/session-view/src/genui/inline.rs @@ -106,7 +106,8 @@ impl PartsResolver for Resolver<'_, S> { return col().w_full().child(markdown_styled::(p, src, self.fade, false, markdown_style(p, color, self.width).body_font(font), marks, Vec::new(), None, &[], None, None)); } let hl = marks.into_iter().filter_map(|(i, m, on)| Some(text_mark(p, m.first()?.clone(), i, on))); - readable(p, text(src.to_owned()).font(font).color(color).wrap().reveal(self.fade).text_highlights(hl)) + let t = text(src.to_owned()).font(font).color(color).wrap().text_highlights(hl); + readable(p, if self.fade > 0.0 { t.reveal(self.fade) } else { t }) } } diff --git a/crates/session-view/src/genui/mod.rs b/crates/session-view/src/genui/mod.rs index 7ee0762ae..3977fdc3b 100644 --- a/crates/session-view/src/genui/mod.rs +++ b/crates/session-view/src/genui/mod.rs @@ -173,7 +173,9 @@ pub fn reply(s: &S, p: &Pal, row_key: &str, src: &str, fade: f3 Seg::Md(r) => { let marks = hits_in(hits, &r).into_iter().map(|(i, m, on)| (m, markdown_mark(p, i, on))).collect(); let seg_scope = format!("{row_key}-md-{}", r.start); - let el = crate::style::markdown_styled_wrap::(p, &src[r.clone()], fade, streaming && i + 1 == count, markdown_style(p, p.text, width), marks, crate::copied::current(s), Some(crate::images::md_media(s)), chips, None, links.clone(), crate::style::CodeWrap::of(s, &seg_scope)); + let seg_live = streaming && i + 1 == count; + let seg_fade = if !streaming || seg_live { fade } else { 0.0 }; + let el = crate::style::markdown_styled_wrap::(p, &src[r.clone()], seg_fade, seg_live, markdown_style(p, p.text, width), marks, crate::copied::current(s), Some(crate::images::md_media(s)), chips, None, links.clone(), crate::style::CodeWrap::of(s, &seg_scope)); // The first run is the root and keeps its blocks' keys from before any fence. let el = if i == 0 { el } else { el.key(format!("md-{}", r.start)) }; (el, md_edges(&src[r])) @@ -181,16 +183,17 @@ pub fn reply(s: &S, p: &Pal, row_key: &str, src: &str, fade: f3 Seg::Ui { at, src_at, line, nodes, code, open } => { let marks: Vec = hits_in(hits, &at).into_iter().map(|(i, m, on)| (i, shift(m, at.start), on)).collect(); let lines: Vec<(usize, u64)> = nodes_lines(&nodes); - let ver = (lines, src_at, width.to_bits(), fade.to_bits(), p.dark, (p.theme, p.generation), &marks); + let ui_fade = if !streaming || (open && i + 1 == count) { fade } else { 0.0 }; + let ver = (lines, src_at, width.to_bits(), ui_fade.to_bits(), p.dark, (p.theme, p.generation), &marks); let version = { use std::hash::{Hash, Hasher}; let mut h = std::hash::DefaultHasher::new(); ver.hash(&mut h); h.finish() }; - let outline = rune::memo(format!("outline-{line}"), ver, || inline::outline::(p, src, src_at, &nodes, width, fade, marks.clone())); + let outline = rune::memo(format!("outline-{line}"), ver, || inline::outline::(p, src, src_at, &nodes, width, ui_fade, marks.clone())); // The plugin that renders `ui` blocks places the outline (`ui.genUi`), or keeps the code. - let outline = s.code_block(p, "ui", &format!("outline-{line}"), &src[code], streaming && open, version, outline).unwrap_or_else(|| markdown_styled::(p, &src[at.clone()], fade, false, markdown_style(p, p.text, width), Vec::<(Vec>, rune_kit::Highlight)>::new(), crate::copied::current(s), None, chips, None, links.clone())); + let outline = s.code_block(p, "ui", &format!("outline-{line}"), &src[code], streaming && open, version, outline).unwrap_or_else(|| markdown_styled::(p, &src[at.clone()], ui_fade, false, markdown_style(p, p.text, width), Vec::<(Vec>, rune_kit::Highlight)>::new(), crate::copied::current(s), None, chips, None, links.clone())); // A pane that gains a sibling while it streams springs to its new width. (col().key(format!("ui-{line}")).w_full().animate_layout().child(outline), UI_EDGES) } diff --git a/crates/session-view/src/line_reveal.rs b/crates/session-view/src/line_reveal.rs index d72dea6dd..49e759018 100644 --- a/crates/session-view/src/line_reveal.rs +++ b/crates/session-view/src/line_reveal.rs @@ -4,7 +4,7 @@ //! (`cursor <= arrived`), Markdown-safe (never flashes unclosed `*`, `` ` ``, `[label](url`, or //! dangling block markers), strictly monotonic, and draining over 80 ms when a turn ends. -use std::{cell::Cell, collections::{HashMap, HashSet}}; +use std::{cell::Cell, collections::{HashMap, HashSet, VecDeque}}; use rune::Tx; @@ -28,9 +28,10 @@ pub struct Hold { last_poll: Cell, /// Last armed `tx.wake_after` deadline on the app clock (deduplicates sub-frame polls). wake_due: Cell>, - /// Keys that already completed a drip so switching tabs back to a live session never replays - /// an already-settled short preamble from 0. + /// Keys that already completed or displayed so switching tabs or starting a follow-up turn + /// never replays an already-settled reply from 0. seen: HashSet, + seen_order: VecDeque, } /// A caught-up turn has no timer work. Revisit it only when its inputs change; keep the @@ -39,7 +40,7 @@ pub struct Hold { enum Poll { #[default] Unversioned, - Current { session: String, version: u64, live: bool, instant: bool, len: usize }, + Current { session: String, version: Option, live: bool, instant: bool, len: usize }, } /// Explicit lifecycle phase for one dripping text part. @@ -166,7 +167,20 @@ impl Drip { } } +const SEEN_CAP: usize = 1024; + impl Hold { + fn mark_seen(&mut self, key: PartKey) { + if self.seen.insert(key.clone()) { + if self.seen_order.len() >= SEEN_CAP + && let Some(oldest) = self.seen_order.pop_front() + { + self.seen.remove(&oldest); + } + self.seen_order.push_back(key); + } + } + /// Bytes of part `part` of `message` in `session` revealed so far while Adaptive Drip runs. pub fn paced(&self, session: &str, message: &str, part: usize) -> Option { if self.drip.is_empty() { @@ -210,16 +224,20 @@ pub fn poll(s: &mut S, now: f64, tx: &mut Tx) -> bool { return false; }; let live = s.is_session_live(sid); - if !live && s.line_hold().drip.is_empty() { - s.line_hold().wake_due.set(None); - return false; - } let reduced = s.reduced_motion(); let stopped = s.is_session_stopped(sid); let instant = reduced || (!live && stopped); let version = s.transcript_version(sid); + let prior_len = match &s.line_hold().poll { + Poll::Current { session, len, .. } if session == sid => Some(*len), + _ => None, + }; let prior = match &s.line_hold().poll { - Poll::Current { session, version, live: l, instant: i, len } if session == sid && *l == live && *i == instant => Some((*version, *len)), + Poll::Current { session, version: Some(v), live: l, instant: i, len } + if session == sid && *l == live && *i == instant => + { + Some((*v, *len)) + } _ => None, }; if prior.is_some_and(|(v, _)| Some(v) == version) && s.line_hold().pending.is_empty() { @@ -227,6 +245,42 @@ pub fn poll(s: &mut S, now: f64, tx: &mut Tx) -> bool { s.line_hold().wake_due.set(None); return false; } + let turn_boundary = |m: &opencode_kit::model::Message| { + matches!(m, opencode_kit::model::Message::User { .. }) + || matches!(m, opencode_kit::model::Message::Notice(n) if n.kind == opencode_kit::model::NoticeKind::Idle) + }; + if !live && s.line_hold().drip.is_empty() { + s.line_hold().wake_due.set(None); + let same_poll = |len: usize, p: &Poll| { + matches!(p, Poll::Current { session, version: v, live: l, instant: i, len: n } + if session == sid && *v == version && *l == live && *i == instant && *n == len) + }; + if let Some(len) = s.with_transcript(sid, |t| t.messages.len()) { + if !same_poll(len, &s.line_hold().poll) || !s.line_hold().pending.is_empty() { + let sid = sid.to_owned(); + let mut hold = std::mem::take(s.line_hold_mut()); + s.with_transcript(&sid, |t| { + for m in t.messages.iter().rev().take_while(|m| !turn_boundary(m)) { + let opencode_kit::model::Message::Assistant(a) = m else { continue }; + for (pi, p) in a.parts.iter().enumerate() { + if let opencode_kit::model::Part::Text { text } = p + && !text.trim().is_empty() + { + hold.mark_seen(PartKey { session: sid.clone(), message: a.id.clone(), part: pi }); + } + } + } + }); + hold.poll = Poll::Current { session: sid, version, live, instant, len }; + hold.pending.clear(); + hold.last_poll.set(now); + *s.line_hold_mut() = hold; + } else { + s.line_hold().last_poll.set(now); + } + } + return false; + } let from = prior.map_or(0, |(v, _)| { if Some(v) == version { usize::MAX } else { s.transcript_changed_from(sid, v).unwrap_or(0) } }); @@ -243,11 +297,28 @@ pub fn poll(s: &mut S, now: f64, tx: &mut Tx) -> bool { { 0 } else { from }; let mut targets = std::mem::take(&mut hold.pending); if from == 0 { targets.clear(); } - // Only edited/new messages need discovery. A caught-up old part is revisited if its - // message changes; a part still dripping stays in `pending` until it catches up. - for (mi, m) in t.messages.iter().enumerate().skip(from).rev() - .take_while(|(_, m)| !matches!(**m, opencode_kit::model::Message::User { .. })) - { + // Keep already-active drips in the current turn alive across an appended `Idle` notice or + // `live` flip so buffered text drains smoothly over 80 ms instead of snapping at turn end. + let mut last_idle = None; + for (mi, m) in t.messages.iter().enumerate().rev() { + match m { + opencode_kit::model::Message::User { .. } => break, + opencode_kit::model::Message::Notice(n) if n.kind == opencode_kit::model::NoticeKind::Idle => { + if last_idle.is_none() { + last_idle = Some(mi); + } + } + opencode_kit::model::Message::Assistant(a) => { + if let Some(parts) = hold.drip.get(&sid).and_then(|s| s.get(&a.id)) { + targets.extend(parts.keys().copied().map(|pi| (mi, pi))); + } + } + _ => {} + } + } + // Only edited/new messages need discovery. Stop at any user prompt or `Idle` notice so a + // previous run's reply is never re-dripped while a follow-up prompt sits in `inboxes`. + for (mi, m) in t.messages.iter().enumerate().skip(from).rev().take_while(|(_, m)| !turn_boundary(m)) { let opencode_kit::model::Message::Assistant(a) = m else { continue }; targets.extend(a.parts.iter().enumerate().filter_map(|(pi, p)| matches!(p, opencode_kit::model::Part::Text { .. }).then_some((mi, pi)))); } @@ -259,22 +330,31 @@ pub fn poll(s: &mut S, now: f64, tx: &mut Tx) -> bool { if text.trim().is_empty() { continue; } let key = PartKey { session: sid.clone(), message: a.id.clone(), part: i }; let existing = hold.drip.get(&sid).and_then(|s| s.get(&a.id)).is_some_and(|p| p.contains_key(&i)); - if !live && !existing { continue; } - let already_seen = hold.seen.contains(&key); + let part_live = live && a.completed.is_none() && last_idle.is_none_or(|idle_mi| mi > idle_mi); + if !part_live && !existing { + hold.mark_seen(key); + continue; + } + // Entering a session (`prior_len.is_none()`), completed assistant steps, and + // non-trailing parts start at `text.len()` so only bytes arriving while viewing + // this session animate. + let already_seen = hold.seen.contains(&key) + || prior_len.is_none() + || a.completed.is_some() + || i + 1 < a.parts.len(); let d = hold.drip.entry(sid.clone()).or_default().entry(a.id.clone()).or_default().entry(i) - .or_insert_with(|| Drip::new(text.len(), live, already_seen, instant, now)); + .or_insert_with(|| Drip::new(text.len(), part_live, already_seen, instant, now)); // Skipped settled parts still experience the same per-frame dt on their next delta. if existing { d.last_tick = hold.last_poll.get(); } d.message = mi; - let (c, wake) = d.step(text, live, instant, now, step_dt); + let (c, wake) = d.step(text, part_live, instant, now, step_dt); changed |= c; if let Some(w) = wake { next = next.min(w); hold.pending.push((mi, i)); } if d.shown >= d.last_len && d.last_len > 0 { - if hold.seen.len() > 256 { hold.seen.clear(); } - hold.seen.insert(key.clone()); + hold.mark_seen(key); } live_keys.insert((mi, i)); } @@ -285,16 +365,18 @@ pub fn poll(s: &mut S, now: f64, tx: &mut Tx) -> bool { session == &sid && (d.message < from || live_keys.contains(&(d.message, part))) && !matches!(d.phase, DripPhase::Done) }); - changed |= parts.len() != before; + if session == &sid && prior_len.is_some() { + changed |= parts.len() != before; + } !parts.is_empty() }); !messages.is_empty() }); checked = Some(t.messages.len()); }); - hold.poll = match (version, checked) { - (Some(version), Some(len)) => Poll::Current { session: sid, version, live, instant, len }, - _ => Poll::Unversioned, + hold.poll = match checked { + Some(len) => Poll::Current { session: sid, version, live, instant, len }, + None => Poll::Unversioned, }; hold.last_poll.set(now); if next.is_finite() { diff --git a/crates/session-view/src/pickers/view.rs b/crates/session-view/src/pickers/view.rs index 18f776e76..e0b619158 100644 --- a/crates/session-view/src/pickers/view.rs +++ b/crates/session-view/src/pickers/view.rs @@ -243,6 +243,7 @@ pub fn effort_trigger(s: &S, p: &Pal, variant: &str, chevron: boo let label = if default { opencode_i18n::t!("common.default").to_owned() } else { capitalize(variant) }; let button = trigger(s, p, Kind::Effort, &label, p.muted, chevron); let shown = crate::style::hover_none() || !default || s.pickers().open() == Some(Kind::Effort) || s.pickers().composer_hovered; + let button = button.opacity_motion(rune::Anim::INSTANT); let button = if shown { button } else { button.group_opacity(0.0, 1.0) }; el().key("effort-slot").hover_group_focus().hover_motion(rune::Anim::INSTANT, rune::Anim::INSTANT).child(button) } diff --git a/crates/session-view/src/style.rs b/crates/session-view/src/style.rs index 0a040c00a..5d926f9f0 100644 --- a/crates/session-view/src/style.rs +++ b/crates/session-view/src/style.rs @@ -312,7 +312,6 @@ pub fn markdown_styled_wrap tips.iter().find(|(l, _)| l == url).map(|(_, t)| t.clone()).or_else(|| S::reply_link_help(url)), } }); + // Leave `Markdown::new`'s `-1.0` sentinel untouched when `fade <= 0.0` so settled + // replies never register word-reveal state (`rune-kit/src/markdown/render/inline.rs:247`). + if fade > 0.0 { + md = md.reveal(fade); + } if let Some(overrides) = code_wrap.overrides { let scope = code_wrap.scope; let mut scoped: Vec<(&str, bool)> = overrides diff --git a/crates/session-view/src/timeline/row_build.rs b/crates/session-view/src/timeline/row_build.rs index 3c1492cd5..fbf01f1dc 100644 --- a/crates/session-view/src/timeline/row_build.rs +++ b/crates/session-view/src/timeline/row_build.rs @@ -72,9 +72,11 @@ impl RowSpec { fn text_row(&self, s: &S, p: &Pal, t: &Transcript, mi: usize, part: usize, body: &str, fade: f32, live: bool, pt: f32, footer: bool) -> El { let message = t.messages[mi].id(); let prompt = prompt_dir(t, mi); - let body = s.line_hold().paced(&t.session, message, part).filter(|&n| body.is_char_boundary(n)).map_or(body, |n| &body[..n]); + let paced = s.line_hold().paced(&t.session, message, part); + let body = paced.filter(|&n| body.is_char_boundary(n)).map_or(body, |n| &body[..n]); + let reveal = if live || paced.is_some() { fade } else { 0.0 }; let trim_bottom = rhythm::prose_bottom_trim(body); - let md_el = super::markdown_view_find(s, p, &self.key, body, fade, live, Some(message), prompt); + let md_el = super::markdown_view_find(s, p, &self.key, body, reveal, live, Some(message), prompt); let md_el = if trim_bottom > 0.0 { md_el.mb(-trim_bottom) } else { md_el }; let row = self.wrap(s, col().w_full().pt(pt).child(md_el)); match reply_hover(t, mi, part, live, footer) { @@ -156,11 +158,12 @@ impl RowSpec { s.active_session_id().and_then(|id| s.session_directory(id)), ) }); + let reveal = if *live || line.1.is_some() { fade } else { 0.0 }; let ver = ( cx.base, (scan.hash, body.len()), [*live, ui_on], - [pt.to_bits(), fade.to_bits()], + [pt.to_bits(), reveal.to_bits()], dw, s.diagrams().hidden_in(body), line, @@ -168,9 +171,9 @@ impl RowSpec { ); return self.memo_row(p, shell, ver, || { if has_math { - rune_kit::math::collect(&self.key, || self.text_row(s, p, t, *message, *part, body, fade, *live, *pt, footer)) + rune_kit::math::collect(&self.key, || self.text_row(s, p, t, *message, *part, body, reveal, *live, *pt, footer)) } else { - self.text_row(s, p, t, *message, *part, body, fade, *live, *pt, footer) + self.text_row(s, p, t, *message, *part, body, reveal, *live, *pt, footer) } }); } diff --git a/crates/session-view/src/timeline/span.rs b/crates/session-view/src/timeline/span.rs index 7ce39245a..d9af1dd1b 100644 --- a/crates/session-view/src/timeline/span.rs +++ b/crates/session-view/src/timeline/span.rs @@ -197,6 +197,24 @@ impl<'a> TurnBuild<'a> { } } + fn has_step_since_idle(&self, messages: &[Message]) -> bool { + for e in self.steps().iter().rev() { + match e { + Entry::Step(_) => return true, + Entry::Idle => return false, + Entry::Notice(_) | Entry::Skip => {} + } + } + for m in messages[self.prefix_range()].iter().rev() { + match m { + Message::Assistant(_) | Message::Note { .. } => return true, + Message::Notice(n) if n.kind == model::NoticeKind::Idle => return false, + _ => {} + } + } + false + } + fn push(&mut self, start_if_idle: usize, entry: Entry<'a>) { match self { Self::Idle => { @@ -526,7 +544,8 @@ pub(super) fn project(s: &S, t: &Transcript, inp: &Inputs, rang return out.finish(t); } let had_open_turn = turn_build.is_open(); - turn_build.flush(s, t, &mut out, shown, inp.busy && inp.revert.is_none(), detail, script_diffs, flatten_cm, turn_diffs); + let trailing_live = inp.busy && inp.revert.is_none() && turn_build.has_step_since_idle(messages); + turn_build.flush(s, t, &mut out, shown, trailing_live, detail, script_diffs, flatten_cm, turn_diffs); // Background shells and subagents that came back wait, each a notice of its own, in the // order the server admitted them (`visibleTimelineMessages`): above the run's tail, where // each lands as it is delivered, under the same key. diff --git a/crates/session-view/src/tools/codemode.rs b/crates/session-view/src/tools/codemode.rs index 8350f09e9..caebe524a 100644 --- a/crates/session-view/src/tools/codemode.rs +++ b/crates/session-view/src/tools/codemode.rs @@ -343,7 +343,7 @@ pub fn mcp_tool(s: &S, p: &Pal, cx: Ctx, c: &Call) -> El { let line = if actions.is_empty() { row().key("line").w_full().h(28.0).gap(2.0).center_y().animate_layout().child(button.grow(1.0)) } else { - row().key("line").w_full().h(28.0).gap(2.0).center_y().animate_layout().child(button).child(row().key("actions").gap(2.0).center_y().children(actions)) + row().key("line").w_full().h(28.0).gap(2.0).center_y().justify_between().animate_layout().child(button).child(row().key("actions").gap(2.0).center_y().children(actions)) }; if !expandable { return still(line); @@ -467,19 +467,15 @@ pub fn codemode_search_tool(s: &S, p: &Pal, cx: Ctx, c: &Call) let template = opencode_i18n::t!("ui.timeline.codemode.loadedTools", name = marker); let (before, after) = template.split_once(marker).unwrap_or(("Loaded", "tools")); let item = loaded_item(s, p, before.trim(), &[(ns.to_owned(), d.busy())], Some(after.trim()).filter(|a| !a.is_empty())); - let row_el = if repeat.is_some() || code_act.is_some() { - let mut r = row().key(format!("tool-{}", c.id)).w_full().min_h(28.0).gap(6.0).center_y().child(item.shrink().min_w(0.0)); - if let Some(b) = repeat { - r = r.child(b); - } - if let Some(act) = code_act { - r = r.child(row().key("actions").gap(2.0).center_y().child(act)); - } - r - } else { - item.key(format!("tool-{}", c.id)) - }; - return still(row_el); + let mut left = row().key("words").gap(6.0).center_y().shrink().min_w(0.0).child(item); + if let Some(b) = repeat { + left = left.child(b); + } + let mut r = row().key(format!("tool-{}", c.id)).w_full().min_h(28.0).gap(6.0).center_y().child(left); + if let Some(act) = code_act { + r = r.justify_between().child(row().key("actions").gap(2.0).center_y().child(act)); + } + return still(r); } let query = field(c.input, "query").map(str::trim).filter(|s| !s.is_empty()).map(str::to_owned); let label = opencode_i18n::t!("ui.timeline.codemode.searchedTools"); @@ -488,15 +484,16 @@ pub fn codemode_search_tool(s: &S, p: &Pal, cx: Ctx, c: &Call) } else { text(label).key("title").font(UI).color(p.muted) }; - let mut r = row().key(format!("tool-{}", c.id)).w_full().min_h(28.0).gap(6.0).center_y().child(title); + let mut left = row().key("words").gap(6.0).center_y().shrink().min_w(0.0).child(title); if let Some(q) = query { - r = r.child(readable(p, text(q).key("value").font(UI).color(p.text).truncate_fade()).shrink().min_w(0.0)); + left = left.child(readable(p, text(q).key("value").font(UI).color(p.text).truncate_fade()).shrink().min_w(0.0)); } if let Some(b) = repeat { - r = r.child(b); + left = left.child(b); } + let mut r = row().key(format!("tool-{}", c.id)).w_full().min_h(28.0).gap(6.0).center_y().child(left); if let Some(act) = code_act { - r = r.child(row().key("actions").gap(2.0).center_y().child(act)); + r = r.justify_between().child(row().key("actions").gap(2.0).center_y().child(act)); } still(r) } diff --git a/crates/session-view/src/tools/console.rs b/crates/session-view/src/tools/console.rs index b53eff020..ab1ec5329 100644 --- a/crates/session-view/src/tools/console.rs +++ b/crates/session-view/src/tools/console.rs @@ -49,7 +49,7 @@ pub fn shell(s: &S, p: &Pal, cx: Ctx, c: &Call) -> El { // the slot so a zero-height closing wrapper leaves no flex gap behind. card=card.child(crate::disclosure::body_slot(crate::disclosure::reveal(s.knobs(),excerpt), d.shutting)); } - return col().w_full().child(trigger(s,p,cx,c,d,t,Press::Toggle(super::key(c.id)),None)).child(card); + return col().w_full().hover_group_focus().child(trigger(s,p,cx,c,d,t,Press::Toggle(super::key(c.id)),None)).child(card); } // Open, the console starts the small gap under the trigger's line, which ends 6 above the // trigger's foot (`timeline-next.css:395-402`, `:486-494`). diff --git a/crates/session-view/src/tools/details.rs b/crates/session-view/src/tools/details.rs index bf65c2945..318092833 100644 --- a/crates/session-view/src/tools/details.rs +++ b/crates/session-view/src/tools/details.rs @@ -9,8 +9,8 @@ use std::rc::Rc; use opencode_kit::model::{Message, Part, ToolStatus}; use rune::{ - Color, Cx, Direction, El, GrowthSpec, Shadow, Span, TextStyle, Transition, Tx, col, el, icon, - row, text, + Color, Cx, Direction, El, GrowthSpec, Key, KeyEvent, Shadow, Span, Spring, SpringPair, + TextStyle, Transition, Tx, col, el, icon, row, text, }; use super::Call; @@ -49,6 +49,18 @@ pub fn key(session: &str, id: &str) -> String { format!("execute-details:{session}:{id}") } +/// Closes the open Execute sheet on unmodified Escape before session-level Escape handlers run. +pub fn on_key(s: &mut S, ev: &KeyEvent, _tx: &mut Tx) -> bool { + if ev.key != Key::Escape || ev.mods.shift || ev.mods.ctrl || ev.mods.alt || ev.mods.cmd { + return false; + } + if !s.expanded().iter().any(|k| k.starts_with("execute-details:")) { + return false; + } + s.expanded_mut().retain(|k| !k.starts_with("execute-details:")); + true +} + /// What the dialog shows, read from the call. struct Details { id: String, @@ -213,7 +225,7 @@ pub fn overlay(s: &S, p: &Pal, cx: &Cx) -> Vec { let Some(open) = s.expanded().iter().find(|k| k.starts_with("execute-details:")).cloned() else { return Vec::new() }; let Some((session, id)) = open.trim_start_matches("execute-details:").split_once(':') else { return Vec::new() }; let Some(d) = s.with_transcript(session, |t| find(t, id)).flatten() else { return Vec::new() }; - let [win_w, win_h] = cx.layout_size("window").unwrap_or([1280.0, 820.0]); + let [win_w, win_h] = cx.layout_size("zoomed").or_else(|| cx.layout_size("window")).unwrap_or([1280.0, 820.0]); let size = crate::dialog::DialogSize::Large; let (w, max_dialog_h) = (size.width(win_w), size.height(win_h)); let (sp, hairline) = (SheetPal::new(p), border_width(0.5)); @@ -316,22 +328,32 @@ pub fn overlay(s: &S, p: &Pal, cx: &Cx) -> Vec { )); } + let fade = SpringPair::new(Spring::new(0.15, 0.0), Spring::new(0.12, 0.0)); + let scrim_t = Transition::opacity().springs(fade); + let sheet_t = if s.reduced_motion() { + Transition::opacity().springs(fade) + } else { + Transition::scale(0.96).springs(fade) + }; + let sheet = col() .key("execute-dialog") .role("dialog") .label_static(opencode_i18n::t!("ui.tool.execute")) + .absolute(((win_w - w) * 0.5).max(0.0), size.top(win_h)) .w(w) .max_h(max_dialog_h) .radius(RADIUS) .fill(sp.bg) .elevate(sp.elevation) - .transition(Transition::none()) + .motion(Spring::NONE) + .transition(sheet_t) .modal(true, close) + .raise() .child(body); - let scrim = el().key("execute-scrim").absolute(0.0, 0.0).w_full().h_full().fill(sp.scrim).transition(Transition::none()); - let modal = col().key("execute-modal").absolute(0.0, 0.0).w_full().h_full().items_center().pt(size.top(win_h)).transition(Transition::none()).child(sheet).raise(); - vec![scrim, modal] + let scrim = el().key("execute-scrim").absolute(0.0, 0.0).w_full().h_full().fill(sp.scrim).transition(scrim_t); + vec![scrim, sheet] } fn build_header(p: &Pal, sp: &SheetPal, d: &Details, close: impl Fn(&mut S) + 'static) -> El { @@ -361,8 +383,7 @@ fn build_header(p: &Pal, sp: &SheetPal, d: &Details, close: imp .key("close").role("button").label_static(opencode_i18n::t!("ui.common.close")) .help(opencode_i18n::t!("ui.common.close")).size(20.0, 20.0).center().radius(4.0) .focus_default(p).hover_group_focus().hover(p.hover).press(p.pressed).hover_motion(INSTANT, INSTANT) - .on_press_tx(move |s: &mut S, tx: &mut Tx| { - tx.instant(); + .on_press_tx(move |s: &mut S, _: &mut Tx| { close(s); }) .child(icon(&rune_theme_opencode::icons::CLOSE, 16.0).color(p.icon_muted).group_color(p.icon)), @@ -434,7 +455,7 @@ fn zone(s: &S, p: &Pal, sp: &SheetPal, spec: ZoneSpec<'_>, cont let inside = (0.0..=pe.w).contains(&pe.x) && (0.0..=pe.h).contains(&pe.y); let on_copy_btn = pe.x >= pe.w - (copy_right + 26.0) && pe.y <= 32.0; let on_v_bar = overflows_y && pe.x >= pe.w - BAR_GUTTER; - let on_h_bar = overflows_x && pe.y >= pe.h - BAR_GUTTER; + let on_h_bar = overflows_x && pe.x >= spec.gutter_w && pe.y >= pe.h - BAR_GUTTER; if !inside || on_copy_btn || on_v_bar || on_h_bar { tx.live_only(); return; @@ -444,7 +465,11 @@ fn zone(s: &S, p: &Pal, sp: &SheetPal, spec: ZoneSpec<'_>, cont } let scroll_key = format!("execute-scroll-{}-{}", spec.id, spec.part); - let scrolled = scroller(scroll_key).scroll_xy().bar(Bar::Styled(native_bar(p))).build::(p, viewport, scroll_body); + let scrolled = scroller(scroll_key) + .scroll_xy() + .horizontal_track_offset(spec.gutter_w, 0.0) + .bar(Bar::Styled(native_bar(p))) + .build::(p, viewport, scroll_body); let copied = spec.copy_text.to_owned(); let button = row() @@ -566,7 +591,7 @@ fn shape_visual_row( let (shown, spans) = expand_tabs(slice, spans); let base_ink = ink.unwrap_or(p.syntax.parameter); row() - .key(format!("l-{idx}")).h(LINE_H).items_start() + .key(format!("l-{idx}")).w_full().h(LINE_H).items_start() .child(gutter_cell(layout, vrow.mark)) .child(row().key("c").h(LINE_H).pl(CODE_PL).pr(CODE_PR).center_y().child(readable(p, text(shown).font(CODE_FONT).color(base_ink).spans(spans).nowrap()))) } @@ -587,7 +612,7 @@ fn build_lines( let (vrows, max_cols) = expand_visual_rows(raw, layout.lead_glyph); let code_ch = rune::text::measure("0", &[], CODE_FONT, None).0; let min_w = layout.dialog_w.max(layout.gutter_w + CODE_PL + code_ch * max_cols as f32 + CODE_PR); - let list = col().key("rows").dir(Direction::Ltr).min_w(min_w).py(PAD_Y).selection_group(true); + let list = col().key("rows").dir(Direction::Ltr).w_full().min_w(min_w).py(PAD_Y).selection_group(true); if vrows.len() <= VIRTUAL_LINES { let mut list = list; @@ -635,7 +660,7 @@ fn build_oversized_preview(p: &Pal, first: &str, last: &str, layout: LineLayout) } let code_ch = rune::text::measure("0", &[], CODE_FONT, None).0; let min_w = layout.dialog_w.max(layout.gutter_w + CODE_PL + code_ch * c1.max(c2).max(1) as f32 + CODE_PR); - let mut rows = col().key("rows").dir(Direction::Ltr).min_w(min_w).py(PAD_Y).selection_group(true); + let mut rows = col().key("rows").dir(Direction::Ltr).w_full().min_w(min_w).py(PAD_Y).selection_group(true); let mut idx = 0usize; for r in first_rows { rows = rows.child(shape_visual_row(p, first, r, None, None, layout, idx)); diff --git a/crates/session-view/src/tools/error.rs b/crates/session-view/src/tools/error.rs index c81d02737..35532fad2 100644 --- a/crates/session-view/src/tools/error.rs +++ b/crates/session-view/src/tools/error.rs @@ -54,7 +54,6 @@ pub fn card_with(s: &S, p: &Pal, session: &str, c: &Call, defau .key(id.clone()) .h(24.0) .center_y() - .grow(1.0) .shrink() .min_w(0.0) .role("button") @@ -66,14 +65,15 @@ pub fn card_with(s: &S, p: &Pal, session: &str, c: &Call, defau .on_press_tx(crate::disclosure::set::(k.clone(), default_open, id.clone())) .child(words) .child(el().key("arrow").size(14.0, 14.0).ml(6.0).center().child(arrow(p, open).color(p.faint))); - let mut line = row().key("line").w_full().min_h(line_h).gap(2.0).center_y().child(button); let actions: Vec = super::source_execute_code_action(s, p, session, c) .into_iter() .chain(s.tool_row_action(p, session, c)) .collect(); - if !actions.is_empty() { - line = line.child(row().key("actions").gap(2.0).center_y().children(actions)); - } + let line = if actions.is_empty() { + row().key("line").w_full().min_h(line_h).gap(2.0).center_y().child(button.grow(1.0)) + } else { + row().key("line").w_full().min_h(line_h).gap(2.0).center_y().justify_between().child(button).child(row().key("actions").gap(2.0).center_y().children(actions)) + }; // Its Copy fades in and out over 0.15 s ease (`tool-error-card.css:132-140`). let card = col().key("error-card").w_full().hover_group_focus().hover_motion(crate::style::HOVER_FADE, crate::style::HOVER_FADE).child(line); // A fold springing shut still builds its body: it stays painted under the row's clip until diff --git a/crates/session-view/src/tools/execute.rs b/crates/session-view/src/tools/execute.rs index ad51a35d6..978515165 100644 --- a/crates/session-view/src/tools/execute.rs +++ b/crates/session-view/src/tools/execute.rs @@ -293,8 +293,7 @@ pub(super) fn view_code_button(p: &Pal, session: &str, id: &str .hover(p.hover) .press(p.pressed) .hover_motion(INSTANT, INSTANT) - .on_press_tx(move |s: &mut S, tx: &mut Tx| { - tx.instant(); + .on_press_tx(move |s: &mut S, _: &mut Tx| { s.expanded_mut().insert(open.clone()); }) .child(icon(&rune_theme_opencode::icons::CODE_SLASH, 14.0).color(p.text)), diff --git a/crates/session-view/src/tools/lists.rs b/crates/session-view/src/tools/lists.rs index 7b4b10d57..c4c2e3419 100644 --- a/crates/session-view/src/tools/lists.rs +++ b/crates/session-view/src/tools/lists.rs @@ -28,7 +28,7 @@ pub fn read(s: &S, p: &Pal, cx: Ctx, c: &Call) -> El { if *c.status == opencode_kit::model::ToolStatus::Completed { let loaded: Vec<&str> = c.metadata["loaded"].as_array().into_iter().flatten().filter_map(Value::as_str).map(|x| super::session_relative(s, cx.session, x)).collect(); if !loaded.is_empty() { - out = out.child(loaded_item(s, p, opencode_i18n::t!("ui.tool.loaded"), &[(loaded.join(", "), false)], None)); + out = out.child(loaded_item(s, p, opencode_i18n::t!("ui.tool.loaded"), &[(loaded.join(", "), false)], None).w_full()); } } out @@ -57,10 +57,12 @@ pub fn read_group(s: &S, p: &Pal, cx: Ctx, calls: &[Call]) -> E list.push(','); } } + let code_act = shared_execute_code_action(s, p, cx.session, calls); + let action_w = if code_act.is_some() { 26.0 } else { 0.0 }; let pending = calls.iter().any(|c| busy(c.status, cx.live)); let title_w = rune::text::measure(opencode_i18n::t!("ui.tool.read"), &[], UI, None).0; // Wider than the row shows it in one line: Desktop measures the clip, this measures the words. - let long = rune::text::measure(&list, &[], UI, None).0 > column(cx.session) - 24.0 - 24.0 - title_w - 8.0; + let long = rune::text::measure(&list, &[], UI, None).0 > column(cx.session) - 24.0 - 24.0 - title_w - 8.0 - action_w; let k = super::key(first.id); let open = long && s.expanded().contains(&k); let title = if pending { crate::working::shimmer(s, p, opencode_i18n::t!("ui.tool.read"), UI).key("title") } else { text(opencode_i18n::t!("ui.tool.read")).key("title").font(UI).color(p.muted) }; @@ -68,7 +70,6 @@ pub fn read_group(s: &S, p: &Pal, cx: Ctx, calls: &[Call]) -> E let words = if open { words.wrap() } else { words.truncate_fade() }; let mut r = row() .key(format!("tool-{}", first.id)) - .w_full() .min_h(28.0) .gap(8.0) .hover_group_focus() @@ -89,7 +90,20 @@ pub fn read_group(s: &S, p: &Pal, cx: Ctx, calls: &[Call]) -> E .focus_default(p) .on_press_tx(crate::disclosure::toggle::(k, format!("tool-{}", first.id))); } - r + match code_act { + Some(act) => { + let line = row() + .key("line") + .w_full() + .min_h(28.0) + .gap(2.0) + .justify_between() + .child(r.shrink().min_w(0.0)) + .child(row().key("actions").h(28.0).gap(2.0).center_y().child(act)); + still(if open { line.items_start() } else { line.center_y() }) + } + None => r.w_full(), + } } pub(super) fn read_args(input: &Value) -> Vec { @@ -230,13 +244,29 @@ pub fn websearch(s: &S, p: &Pal, cx: Ctx, c: &Call) -> El { /// Skills in a row of the group: "Loaded release-notes skill", or "Loaded a, b skills" for named /// skills one after another, each name shimmering while it loads; "Skill" until its name is known. +fn shared_execute_code_action(s: &S, p: &Pal, session: &str, calls: &[Call]) -> Option { + let first = calls.first()?; + let id = first.metadata["sourceCallID"].as_str().filter(|s| !s.is_empty())?; + calls + .iter() + .all(|c| c.metadata["fromExecute"].as_bool() == Some(true) && c.metadata["sourceCallID"].as_str() == Some(id)) + .then(|| super::source_execute_code_action(s, p, session, first)) + .flatten() +} + pub fn skill_group(s: &S, p: &Pal, cx: Ctx, calls: &[Call]) -> El { let Some(first) = calls.first() else { return col() }; + let code_act = shared_execute_code_action(s, p, cx.session, calls); let names: Vec<(String, bool)> = calls.iter().filter_map(|c| skill_name(c).map(|n| (n.to_owned(), busy(c.status, cx.live)))).collect(); if names.is_empty() { let d = Display::of(s, cx, first, false); let title = if d.busy() { crate::working::shimmer(s, p, opencode_i18n::t!("ui.tool.skill"), UI) } else { text(opencode_i18n::t!("ui.tool.skill")).font(UI).color(p.muted) }; - return row().key(format!("tool-{}", first.id)).w_full().h(28.0).center_y().child(title.key("title")); + let mut r = row().key(format!("tool-{}", first.id)).w_full().h(28.0).center_y().child(title.key("title")); + if let Some(act) = code_act { + r = r.justify_between().child(row().key("actions").gap(2.0).center_y().child(act)); + return still(r); + } + return r; } // `ui.tool.loadedSkills` around its name: "Loaded" before it and "skill" or "skills" after. let template = opencode_i18n::plural_text(opencode_i18n::plural_key!("ui.tool.loadedSkills"), names.len() as u64); @@ -244,10 +274,20 @@ pub fn skill_group(s: &S, p: &Pal, cx: Ctx, calls: &[Call]) -> let after = after.replace("{{count}}", &names.len().to_string()); let item = loaded_item(s, p, before.trim(), &names, Some(after.trim()).filter(|a| !a.is_empty())); let repeat = (calls.len() == 1).then(|| crate::turns::codemode::repeat_count_of(first.metadata)).flatten(); - match super::codemode::repeat_badge(p, repeat) { - Some(badge) => row().key(format!("tool-{}", first.id)).w_full().min_h(28.0).gap(6.0).center_y().child(item.shrink().min_w(0.0)).child(badge), - None => item.key(format!("tool-{}", first.id)), + let badge = super::codemode::repeat_badge(p, repeat); + if badge.is_none() && code_act.is_none() { + return item.w_full().key(format!("tool-{}", first.id)); } + let mut left = row().key("words").gap(6.0).center_y().shrink().min_w(0.0).child(item); + if let Some(b) = badge { + left = left.child(b); + } + let mut r = row().key(format!("tool-{}", first.id)).w_full().min_h(28.0).gap(6.0).center_y().child(left); + if let Some(act) = code_act { + r = r.justify_between().child(row().key("actions").gap(2.0).center_y().child(act)); + return still(r); + } + r } /// A skill call's name: its metadata's, else what the model asked for. @@ -273,7 +313,8 @@ pub(super) fn loaded_item(s: &S, p: &Pal, label: &str, values: }; row() .key("loaded") - .w_full() + .shrink() + .min_w(0.0) .min_h(28.0) .gap(6.0) .center_y() diff --git a/crates/session-view/src/tools/mod.rs b/crates/session-view/src/tools/mod.rs index 66db6ccd6..d0d271da5 100644 --- a/crates/session-view/src/tools/mod.rs +++ b/crates/session-view/src/tools/mod.rs @@ -39,7 +39,7 @@ use crate::palette::Pal; use crate::style::{HOVER_FADE, TOOL_CODE, UI, arrow, readable}; pub use console::{console_open, follow as shell_follow}; -pub use details::overlay as details_overlay; +pub use details::{on_key as details_key, overlay as details_overlay}; pub use files::{draws_card as file_draws_card, group as file_group, is_file_tool, shut_group}; pub use execute::script_output_text; pub use lists::{read_group, skill_group, skill_name}; @@ -319,6 +319,9 @@ fn cached_with(s: &S, p: &Pal, cx: Ctx, calls: &[Call], after_c fingerprint_execute_metadata(c, shown, flat, &mut h); } else { fingerprint(c.metadata, &mut h); + if flatten && let Some(sid) = c.metadata["sourceCallID"].as_str() { + s.with_transcript(cx.session, |t| details::can_view_code(t, sid)).hash(&mut h); + } } // The output the host read from the call's shell (`console::follow`). console::follow(c, |_| false).and_then(|(id, _)| s.shell_output(id)).map(str::len).hash(&mut h); @@ -509,8 +512,8 @@ pub fn trigger(s: &S, p: &Pal, cx: Ctx, c: &Call, d: Display, t return line.child(button.grow(1.0)); } // The buttons' glyphs rest hidden (`group_opacity`), the buttons themselves still pressable, - // as Desktop's `basic-tool-action` is. - line.child(button).child(row().key("actions").gap(2.0).center_y().children(actions)) + // as Desktop's `basic-tool-action` is, pinned to the trailing edge (`timeline-next.css`). + line.justify_between().child(button).child(row().key("actions").gap(2.0).center_y().children(actions)) } fn title(s: &S, p: &Pal, t: &str, font: rune::TextStyle, d: Display) -> El { diff --git a/crates/session-view/src/turns/mod.rs b/crates/session-view/src/turns/mod.rs index 30b3d8eaa..8a195c76e 100644 --- a/crates/session-view/src/turns/mod.rs +++ b/crates/session-view/src/turns/mod.rs @@ -341,7 +341,7 @@ pub fn fold_with_flags<'a>( Entry::Skip | Entry::Idle => continue, Entry::Step(a) => *a, }; - let live_msg = live && Some(mi) == last; + let live_msg = live && Some(mi) == last && a.completed.is_none(); // Keys count each kind apart, as the server's ordinals do: a thought arriving or // showing up in a refetched copy doesn't re-key the answer beside it. let (mut texts, mut thoughts) = (0, 0); @@ -557,7 +557,7 @@ fn place_tool<'a>( Calls::One }; match out.last_mut() { - Some(Block::Calls { kind: k, steps, at: locs, .. }) if *k == kind && kind != Calls::One => { steps.push(step); locs.push(loc); } + Some(Block::Calls { kind: k, steps, at: locs, .. }) if *k == kind && (kind == Calls::Files || (kind == Calls::Reads && steps.first().map(source_call_id) == Some(source_call_id(&step)))) => { steps.push(step); locs.push(loc); } _ => out.push(Block::Calls { key: format!("p-{id}"), kind, steps: vec![step], at: vec![loc] }), } } @@ -785,4 +785,10 @@ fn named_skill(st: &Step) -> bool { && call(st).is_some_and(|c| crate::tools::skill_name(&c).is_some()) } +fn source_call_id<'a>(st: &'a Step<'a>) -> Option<&'a str> { + st.tool_ref() + .filter(|t| t.metadata["fromExecute"].as_bool() == Some(true)) + .and_then(|t| t.metadata["sourceCallID"].as_str().filter(|s| !s.is_empty())) +} + diff --git a/crates/session-view/src/turns/view.rs b/crates/session-view/src/turns/view.rs index adbe80203..63387664e 100644 --- a/crates/session-view/src/turns/view.rs +++ b/crates/session-view/src/turns/view.rs @@ -5,7 +5,7 @@ use rune::{El, col, el, row}; use super::labels::{activity_words, used_words}; -use super::{Calls, Loc, Step, call, file_like, file_tool, grouped_read, label, named_skill, script_change}; +use super::{Calls, Loc, Step, call, file_like, file_tool, grouped_read, label, named_skill, script_change, source_call_id}; use crate::TimelineHost; use crate::activity::{event_row, events, label as activity}; use crate::detail::Category; @@ -201,7 +201,18 @@ pub fn group( let messages = t.messages.get(span.clone())?; let steps: Vec = at.get(i..i + n)?.iter().map(|l| l.step(messages, flat)).collect::>()?; let cx = crate::tools::Ctx { session: &session, live, sticky: top + 28.0 + HEADER_PAD }; - Some((step_item(s, &p, cx, &group_key, &steps, live, fade, &after_ids, &output_after), closing_step(s, &group_key, &steps, &output_after))) + let step_fade = if matches!(steps.first(), Some(Step::Text { .. })) { + let text_live = live + && j + 1 == count + && at.get(i).and_then(|l| match messages.get(l.entry as usize) { + Some(opencode_kit::model::Message::Assistant(a)) => Some((l.part as usize, a)), + _ => None, + }).is_some_and(|(pi, a)| a.completed.is_none() && pi + 1 == a.parts.len()); + if text_live { fade } else { 0.0 } + } else { + fade + }; + Some((step_item(s, &p, cx, &group_key, &steps, live, step_fade, &after_ids, &output_after), closing_step(s, &group_key, &steps, &output_after))) }).flatten().unwrap_or_else(|| (col(), false)); // The gap is the row's own, so the list holds rows alone. Each step is the // innermost owner of the row it opens, so it feathers its own moving edge, and @@ -259,12 +270,16 @@ fn plan(steps: &[Step]) -> Vec<(usize, usize)> { let mut i = 0; while i < steps.len() { let run = |f: fn(&Step) -> bool| steps[i..].iter().take_while(|st| f(st)).count(); + let src = source_call_id(&steps[i]); + let same_src_run = |f: fn(&Step) -> bool| { + steps[i..].iter().take_while(|st| f(st) && source_call_id(st) == src).count() + }; let n = match &steps[i] { st if is_work(st) => run(is_work), Step::Thought { .. } => run(|st| matches!(st, Step::Thought { .. })), - st if grouped_read(st) => run(grouped_read), + st if grouped_read(st) => same_src_run(grouped_read), st if file_like(st) => run(file_like), - st if named_skill(st) => run(named_skill), + st if named_skill(st) => same_src_run(named_skill), _ => 1, }; out.push((i, n)); @@ -493,7 +508,7 @@ fn step_item( // No vertical padding on grouped notices (`timeline-next/row.tsx:1066`, `opencode#67760`). Step::Notice(n) => col().key(format!("notice-{}", n.id)).w_full().child(crate::turn_errors::notice(s, p, n, crate::compaction::Run::default())), // Commentary is keyed by its place among the group's steps, as it has no id. - Step::Text { body } => col().w_full().child(crate::timeline::markdown_view::(p, body, fade, false)), + Step::Text { body } => col().w_full().child(crate::timeline::markdown_view::(p, body, if live { fade } else { 0.0 }, false)), st if grouped_read(st) => { let calls: Vec = steps.iter().filter_map(call).collect(); crate::tools::cached(s, p, cx, &calls, || crate::tools::read_group(s, p, cx, &calls)).key(format!("reads-{}", calls[0].id)) diff --git a/features/annotations/src/line_comments/mod.rs b/features/annotations/src/line_comments/mod.rs index 47c9fa758..993d4d18b 100644 --- a/features/annotations/src/line_comments/mod.rs +++ b/features/annotations/src/line_comments/mod.rs @@ -339,6 +339,7 @@ pub fn line_comment(host: &mut dyn LineCommentsHost, spot: &Spot, event: machine } if host.line_comments().version(&spot.session) != before { host.line_comments_mut().plus_quiet = true; + tx.follow_edge(); } } diff --git a/features/annotations/src/quote/mod.rs b/features/annotations/src/quote/mod.rs index cf563d238..602bd791f 100644 --- a/features/annotations/src/quote/mod.rs +++ b/features/annotations/src/quote/mod.rs @@ -457,6 +457,7 @@ fn add_text(host: &mut dyn QuoteHost, text: String, from: Option bool { changed |= !effects.is_empty(); upload_effects(host, effects, None, tx); } + if changed { + tx.follow_edge(); + } changed } @@ -516,6 +519,7 @@ pub fn handle_picked_attachment(host: &mut dyn AttachmentsHost, result: Result { tx.instant(); + tx.follow_edge(); attach_path(host, &path); if host.auto_focus_composer(tx) { host.focus_composer(); diff --git a/features/composer-input/src/dropzone.rs b/features/composer-input/src/dropzone.rs index 6229e28f0..f3b49ed17 100644 --- a/features/composer-input/src/dropzone.rs +++ b/features/composer-input/src/dropzone.rs @@ -134,6 +134,9 @@ pub fn hover(host: &mut dyn DropzoneHost, over: bool, tx: &mut Tx) { /// showing through it and fades from [`poll`]. pub fn drop(host: &mut dyn DropzoneHost, paths: &[PathBuf], tx: &mut Tx) { apply(step(host.dropzone_mut(), Event::Dropped), tx); + if !paths.is_empty() { + tx.follow_edge(); + } for p in paths { host.attach_path(p); } diff --git a/features/composer-input/src/suggestions/mod.rs b/features/composer-input/src/suggestions/mod.rs index 42d34eba1..7e0e084b1 100644 --- a/features/composer-input/src/suggestions/mod.rs +++ b/features/composer-input/src/suggestions/mod.rs @@ -183,6 +183,7 @@ fn apply_suggestion(host: &mut dyn SuggestionsHost, effect: Effect, tx: &mut Tx) if let Some(entry) = host.prompts().entries(shell).get(index).cloned() { let caret = caret.unwrap_or(entry.text.len()); entry.put(host.composer_mut(), caret); + tx.follow_edge(); host.suggest_mut().search.focused = false; if host.auto_focus_composer(tx) { host.composer_mut().focused = true; @@ -191,6 +192,7 @@ fn apply_suggestion(host: &mut dyn SuggestionsHost, effect: Effect, tx: &mut Tx) } Effect::Restore { saved, focus } => { saved.entry.put(host.composer_mut(), saved.caret); + tx.follow_edge(); if focus { host.suggest_mut().search.focused = false; if host.auto_focus_composer(tx) { @@ -329,7 +331,11 @@ pub fn history_key(host: &mut dyn SuggestionsHost, ev: &KeyEvent, tx: &mut Tx) - let composer = host.composer(); (composer.text.len(), composer.focus, Saved { entry: Entry::of(composer), caret: composer.focus }) }; - suggest(host, Event::HistoryStep { up, len, caret, entries, draft }, tx) + let stepped = suggest(host, Event::HistoryStep { up, len, caret, entries, draft }, tx); + if stepped { + tx.follow_edge(); + } + stepped } /// Shift+↑: the history list over an empty draft, its newest entry previewed. diff --git a/features/dictation/src/lib.rs b/features/dictation/src/lib.rs index 77e81835a..cb8d5d97e 100644 --- a/features/dictation/src/lib.rs +++ b/features/dictation/src/lib.rs @@ -243,6 +243,7 @@ pub fn cancel(host: &mut dyn DictationHost) { /// Toggles dictation from a toolbar press (non-generic handler for the mic/stop button). pub fn toggle(host: &mut dyn DictationHost, tx: &mut Tx) { tx.instant(); + tx.follow_edge(); let now = tx.clock(); run(host, Event::Toggle { now, held: false }, Some(tx)); } @@ -309,8 +310,12 @@ fn run(host: &mut dyn DictationHost, event: Event, tx: Option<&mut Tx>) -> bool } Some(Effect::Words { words, send }) => { insert(host, &words); - if let (Some(kind), Some(tx)) = (send, tx) { - host.submit_prompt(kind, tx); + if let Some(tx) = tx { + if let Some(kind) = send { + host.submit_prompt(kind, tx); + } else { + tx.follow_edge(); + } } } Some(Effect::TimedOut { words, cancel }) => { @@ -340,6 +345,7 @@ pub fn key(host: &mut dyn DictationHost, ev: &KeyEvent, tx: &mut Tx) -> bool { if host.is_dictate_bind(ev, tx) { if !tx.key_repeat() { tx.instant(); + tx.follow_edge(); let now = tx.clock(); run(host, Event::Toggle { now, held: true }, Some(tx)); } @@ -347,6 +353,7 @@ pub fn key(host: &mut dyn DictationHost, ev: &KeyEvent, tx: &mut Tx) -> bool { } if ev.key == Key::Escape && host.dictation().active() { tx.instant(); + tx.follow_edge(); cancel(host); return true; } @@ -370,6 +377,7 @@ pub fn key_up(host: &mut dyn DictationHost, ev: &KeyEvent, tx: &mut Tx) -> bool } let now = tx.clock(); let was = host.dictation().recording(); + tx.follow_edge(); run(host, Event::Release { now }, Some(tx)); if was && !host.dictation().recording() { tx.instant(); @@ -395,6 +403,9 @@ pub fn poll(host: &mut dyn DictationHost, now: f64, tx: &mut Tx) -> bool { } else { tx.wake_at(t.max(now + 0.001)); } + if changed { + tx.follow_edge(); + } return changed; } if host.dictation().rec().is_none() { @@ -462,6 +473,9 @@ pub fn poll(host: &mut dyn DictationHost, now: f64, tx: &mut Tx) -> bool { if let Phase::Failed { until: Some(t), .. } = host.dictation().phase { tx.wake_at(t.max(now + 0.001)); } + if changed { + tx.follow_edge(); + } changed } diff --git a/features/dictation/src/view.rs b/features/dictation/src/view.rs index 219d9441b..3e5580bfc 100644 --- a/features/dictation/src/view.rs +++ b/features/dictation/src/view.rs @@ -129,6 +129,7 @@ pub fn status(host: &H, p: &Pal) -> Option { .child(dismiss.on_press_tx(|s: &mut H, tx: &mut Tx| { if dismiss_error(s) { tx.instant(); + tx.follow_edge(); } })); } diff --git a/features/inbox/src/send_failed/mod.rs b/features/inbox/src/send_failed/mod.rs index e54e0e66c..7df1f9a58 100644 --- a/features/inbox/src/send_failed/mod.rs +++ b/features/inbox/src/send_failed/mod.rs @@ -165,6 +165,12 @@ pub trait SendFailedHost: opencode_kernel::AppEnv + opencode_kernel::AppFeedback let _ = (id, result); } + /// Whether `session` currently has a live run under way (`App::busy`). + fn is_session_busy(&self, session: &str) -> bool { + let _ = session; + false + } + /// Whether `session`'s queue state machine currently has a rewrite/mutation in flight. /// While true, [`pump_outbox`] waits before sending another prompt for `session` so new /// admissions cannot race with an active `rewrite_queue`. diff --git a/features/inbox/src/send_failed/outbox.rs b/features/inbox/src/send_failed/outbox.rs index 28b64e72b..cf36e56c3 100644 --- a/features/inbox/src/send_failed/outbox.rs +++ b/features/inbox/src/send_failed/outbox.rs @@ -125,9 +125,9 @@ pub fn show_outbox(host: &mut dyn SendFailedHost) { if already_in_inbox { continue; } + let delivery = s.prompt.as_ref().and_then(|p| p.delivery).unwrap_or(Delivery::Steer); let has_steering = host.inboxes().get(&s.session).is_some_and(|i| i.steering().next().is_some()); - if s.inbox && has_steering { - let delivery = s.prompt.as_ref().and_then(|p| p.delivery).unwrap_or(Delivery::Steer); + if s.inbox && (delivery == Delivery::Queue || has_steering || host.is_session_busy(&s.session)) { let item = InboxItem { id: s.id.clone(), text: s.draft.text.clone(), files: s.files.clone(), delivery }; let later_pos = (delivery == Delivery::Queue) .then(|| {