diff --git a/apps/desktop/src/shell/navigation/row.rs b/apps/desktop/src/shell/navigation/row.rs index 2d02076d2..433194e83 100644 --- a/apps/desktop/src/shell/navigation/row.rs +++ b/apps/desktop/src/shell/navigation/row.rs @@ -101,13 +101,14 @@ fn render_draft_row(p: &Pal, d: &DraftRow, pos: usize, size: usize) -> El { ) } +/// The sidebar's marks (`session_busy`, `status_dot`), so switching layouts keeps them. fn status_mark(p: &Pal, st: Status) -> Option { + use session_view::style::{DOT, Dot, session_busy, status_dot}; match st { - // `ActivityRing`'s 14 (`navigation/row.tsx`). - Status::Working => Some(session_view::style::activity_ring_sized(p, 14.0)), - Status::Approval | Status::Question => Some(el().size(7.0, 7.0).radius(3.5).fill(p.v1_icon_warning)), - Status::Failed => Some(el().size(7.0, 7.0).radius(3.5).fill(p.danger)), - Status::Unread => Some(el().size(7.0, 7.0).radius(3.5).fill(p.bg_accent)), + Status::Working => Some(session_busy(p)), + Status::Approval | Status::Question => Some(status_dot(p, Dot::Attention, DOT)), + Status::Failed => Some(status_dot(p, Dot::Failed, DOT)), + Status::Unread => Some(status_dot(p, Dot::Unread, DOT)), Status::Idle => None, } } diff --git a/apps/desktop/src/shell/tabs/pins.rs b/apps/desktop/src/shell/tabs/pins.rs index 59a33cb4b..d3d02b5f4 100644 --- a/apps/desktop/src/shell/tabs/pins.rs +++ b/apps/desktop/src/shell/tabs/pins.rs @@ -537,15 +537,18 @@ pub fn new_group(s: &mut App, r: PinRef) { #[derive(Clone, Copy, PartialEq, Eq)] pub enum HiddenMark { Attention, + Failed, Unread, } -/// What a collapsed pin group's hidden sessions need (`hiddenMark`, `pinned-area.tsx`). +/// What a collapsed pin group's hidden sessions need (`hiddenMark`, `pinned-area.tsx`): the most +/// urgent of them, Attention over Failed over Unread. The current session and muted ones' unread +/// or failed runs don't count. pub fn hidden_mark(s: &App, group: &PinGroup) -> Option { if !state(s).doc.collapsed.get(&group.id).copied().unwrap_or(false) { return None; } - let mut unread = false; + let (mut failed, mut unread) = (false, false); for r in &group.sessions { if is_current(s, r) { continue; @@ -554,11 +557,16 @@ pub fn hidden_mark(s: &App, group: &PinGroup) -> Option { let status = status_of(s, r); match status { Some(crate::TabStatus::Attention) => return Some(HiddenMark::Attention), - Some(crate::TabStatus::Unread | crate::TabStatus::Failed) if !muted => unread = true, + Some(crate::TabStatus::Failed) if !muted => failed = true, + Some(crate::TabStatus::Unread) if !muted => unread = true, _ => {} } } - unread.then_some(HiddenMark::Unread) + if failed { + Some(HiddenMark::Failed) + } else { + unread.then_some(HiddenMark::Unread) + } } pub fn status_of(s: &App, r: &PinRef) -> Option { diff --git a/apps/desktop/src/shell/view/inbox.rs b/apps/desktop/src/shell/view/inbox.rs index a60a9a6d5..2bca28578 100644 --- a/apps/desktop/src/shell/view/inbox.rs +++ b/apps/desktop/src/shell/view/inbox.rs @@ -490,14 +490,15 @@ fn card(s: &App, p: &Pal, e: &Entry<'_>, in_shelf: bool, group: Group, card_epoc let mut end = row().key("end").gap(6.0).center_y(); match e.status { InboxStatus::Ready => {} - InboxStatus::Working => end = end.child(activity_ring(p)), + InboxStatus::Working => end = end.child(session_view::style::session_busy(p)), status => { - let fill = match status { - InboxStatus::Approval | InboxStatus::Input => p.warning, - InboxStatus::Failed => p.danger, - _ => p.bg_accent, + use session_view::style::{DOT, Dot, status_dot}; + let dot = match status { + InboxStatus::Approval | InboxStatus::Input => Dot::Attention, + InboxStatus::Failed => Dot::Failed, + _ => Dot::Unread, }; - end = end.child(el().key("dot").size(7.0, 7.0).radius(3.5).fill(fill)); + end = end.child(el().key("dot").child(status_dot(p, dot, DOT))); } } let key = e.key(); diff --git a/apps/desktop/src/shell/view/sidebar/auto_sections.rs b/apps/desktop/src/shell/view/sidebar/auto_sections.rs index a96281d3a..87e41b87b 100644 --- a/apps/desktop/src/shell/view/sidebar/auto_sections.rs +++ b/apps/desktop/src/shell/view/sidebar/auto_sections.rs @@ -71,11 +71,12 @@ fn header(s: &App, p: &Pal, g: &Group, first: bool) -> El { None => icon(&ic::SERVER, 14.0).color(p.icon_muted), }; let tag = g.server.as_ref().filter(|_| g.spans_servers).and_then(crate::servers::runtime::tag); - let dot = |color: Color| el().key("mark").size(6.0, 6.0).radius(3.0).fill(color).a11y_hidden(); + use session_view::style::{DOT, Dot, session_busy, status_dot}; + let dot = |d: Dot| el().key("mark").child(status_dot(p, d, DOT)); let mark = auto_groups::mark(s, g).map(|m| match m { - Mark::Busy => activity_ring(p).key("ring"), - Mark::Attention => dot(p.warning), - Mark::Unread => dot(p.bg_accent), + Mark::Busy => session_busy(p), + Mark::Attention => dot(Dot::Attention), + Mark::Unread => dot(Dot::Unread), }); let key = g.key.clone(); row() diff --git a/apps/desktop/src/shell/view/sidebar/pinned_area.rs b/apps/desktop/src/shell/view/sidebar/pinned_area.rs index fb66484cb..a9b51a57f 100644 --- a/apps/desktop/src/shell/view/sidebar/pinned_area.rs +++ b/apps/desktop/src/shell/view/sidebar/pinned_area.rs @@ -9,6 +9,7 @@ use crate::popup::{self, Item, Menu, MenuButton as _}; use crate::session_menu::{Spot, Target, preferences}; use crate::tabs::pins::{self, HiddenMark, PinColor, PinGroup, PinItem, PinRef}; use opencode_i18n::t; +use session_view::style::{DOT, DOT_BADGE, Dot, dot_color, session_busy, status_dot}; /// `sessions-stack` (`packages/ui/src/icons/catalog.ts:393`): Home's glyph in every layout /// (`packages/app/src/shell/titlebar/titlebar.tsx:427,438`, `opencode#66594`). @@ -57,17 +58,13 @@ fn group_square(c: PinColor, dark: bool) -> El { } fn hidden_dot(p: &Pal, mark: HiddenMark, vertical: bool) -> El { - let color = match mark { - HiddenMark::Attention => p.warning, - HiddenMark::Unread => p.accent, + let dot = match mark { + HiddenMark::Attention => Dot::Attention, + HiddenMark::Failed => Dot::Failed, + HiddenMark::Unread => Dot::Unread, }; let end = if vertical { 0.0 } else { -3.0 }; - el().key("group-mark") - .pin(None, Some(-3.0), Some(end), None) - .size(6.0, 6.0) - .radius(3.0) - .fill(color) - .a11y_hidden() + el().key("group-mark").pin(None, Some(-3.0), Some(end), None).child(status_dot(p, dot, DOT_BADGE)) } /// Consolidated side tabs: pinned area above, divider, then unpinned open tabs, in their groups @@ -210,10 +207,11 @@ fn vertical_session(s: &App, p: &Pal, r: &PinRef, nav_order: &[String], show_hin let marked = s.kernel.slots.get(&crate::session_menu::MENUS).on.as_ref() == Some(&target); let avatar = crate::icons::tab_badge(s, p, d.project, &d.title, d.shortcut, show_hints); let mark = match d.status { - Some(TabItemStatus::Busy) => Some(session_view::style::tab_busy_glyph(crate::palette::kit(p), 14.0)), + Some(TabItemStatus::Busy) => Some(session_busy(p)), _ if d.muted => Some(super::pins::muted_mark(p)), - Some(TabItemStatus::Attention) => Some(el().key("attention").size(7.0, 7.0).radius(3.5).fill(p.warning).a11y_hidden()), - Some(TabItemStatus::Unread | TabItemStatus::Failed) if !d.active => Some(el().key("unread").size(7.0, 7.0).radius(3.5).fill(p.accent).a11y_hidden()), + Some(TabItemStatus::Attention) => Some(status_dot(p, Dot::Attention, DOT)), + Some(TabItemStatus::Unread) if !d.active => Some(status_dot(p, Dot::Unread, DOT)), + Some(TabItemStatus::Failed) if !d.active => Some(status_dot(p, Dot::Failed, DOT)), _ => None, }; let ink = if d.active || d.status.is_some() { p.text } else { p.muted }; @@ -261,18 +259,19 @@ fn horizontal_session(s: &App, p: &Pal, r: &PinRef, nav_order: &[String], show_h let target = Target::on(&r.server, &r.session_id, Spot::Row); let marked = s.kernel.slots.get(&crate::session_menu::MENUS).on.as_ref() == Some(&target); let avatar = if d.status == Some(TabItemStatus::Busy) && !show_hints { - session_view::style::tab_busy_glyph(crate::palette::kit(p), 14.0) + session_busy(p) } else { crate::icons::tab_badge(s, p, d.project, &d.title, d.shortcut, show_hints) }; let dot = match d.status { - Some(TabItemStatus::Attention) => Some(p.warning), - Some(TabItemStatus::Unread | TabItemStatus::Failed) if !d.active && !d.muted => Some(p.accent), + Some(TabItemStatus::Attention) => Some(Dot::Attention), + Some(TabItemStatus::Unread) if !d.active && !d.muted => Some(Dot::Unread), + Some(TabItemStatus::Failed) if !d.active && !d.muted => Some(Dot::Failed), _ => None, }; let mut lead = el().size(16.0, 16.0).center().child(avatar); - if let Some(color) = dot { - lead = lead.child(el().key("dot").pin(None, Some(-2.0), Some(-2.0), None).size(6.0, 6.0).radius(3.0).fill(color).a11y_hidden()); + if let Some(dot) = dot { + lead = lead.child(el().key("dot").pin(None, Some(-2.0), Some(-2.0), None).size(DOT_BADGE, DOT_BADGE).radius(DOT_BADGE / 2.0).fill(dot_color(p, dot)).a11y_hidden()); } let pin_click = r.clone(); let pin_ctx = r.clone(); @@ -305,24 +304,26 @@ fn horizontal_session(s: &App, p: &Pal, r: &PinRef, nav_order: &[String], show_h /// default ease). const CHEVRON: Curve = Curve::tween(0.15, Easing::cubic(0.4, 0.0, 0.2, 1.0)); -/// A header's chevron that shows with the pointer over the header's row or with the keyboard's -/// focus on its toggle (the ancestor keyed `toggle`), fading over 150 ms, and always where the -/// pointer cannot hover (`pinned-area.tsx:376`, `recent-sessions.tsx:1222-1225`: `opacity-0 -/// transition-[transform,opacity] group-hover/row:opacity-100 -/// group-focus-visible/toggle:opacity-100 [@media(hover:none)]:opacity-100`, opencode#66265). -/// It turns over the same 150 ms. +/// A header's chevron. Open, it shows with the pointer over the header's row or with the +/// keyboard's focus on its toggle (the ancestor keyed `toggle`), fading over 150 ms +/// (`pinned-area.tsx:376`, opencode#66265). Folded, it stays at rest, turned to point at the +/// hidden rows, so a folded group reads as one that opens (as a folded tab group's does, +/// `tab_groups.rs`). It always shows where the pointer cannot hover, and turns over 150 ms. pub(super) fn group_chevron(p: &Pal, open: bool, toggle: &str) -> El { let chevron = icon(&ic::FILL_TRIANGLE_DOWN, 14.0) .color(p.icon_muted) .rotate(if open { 0.0 } else { -std::f32::consts::FRAC_PI_2 }) .mirror_in_rtl() .rotate_motion(CHEVRON); - if session_view::style::hover_none() { + if session_view::style::hover_none() || !open { return chevron; } chevron.group_opacity(0.0, 1.0).group_focus_within(toggle.to_owned()).group_motion(CHEVRON, CHEVRON) } +/// A folded group's session count, faint after its name (as a folded tab group's, `tab_groups.rs`). +const COUNT: TextStyle = TextStyle::new(11.0, 440.0).lh(16.0).features("\"tnum\""); + fn vertical_group(s: &App, p: &Pal, g: &PinGroup, nav_order: &[String], show_hints: bool) -> El { let open = !pins::state(s).doc.collapsed.get(&g.id).copied().unwrap_or(false); let mark = pins::hidden_mark(s, g); @@ -335,6 +336,7 @@ fn vertical_group(s: &App, p: &Pal, g: &PinGroup, nav_order: &[String], show_hin .children(mark.map(|m| hidden_dot(p, m, true))); let label_el = text(g.name.clone()).font(UI_MED).color(p.text).shrink().min_w(0.0).truncate().dir(rune::Direction::Auto); + let count = (!open && !g.sessions.is_empty()).then(|| text(g.sessions.len().to_string()).key("count").font(COUNT).color(p.faint)); let toggle_id = g.id.clone(); let ctx_id = g.id.clone(); @@ -348,7 +350,7 @@ fn vertical_group(s: &App, p: &Pal, g: &PinGroup, nav_order: &[String], show_hin let trigger = row() .key(toggle_key.clone()) .role("button") - .label(g.name.clone()) + .label(if open || g.sessions.is_empty() { g.name.clone() } else { format!("{} ({})", g.name, g.sessions.len()) }) .expanded(open) .grow(1.0) .shrink() @@ -375,6 +377,7 @@ fn vertical_group(s: &App, p: &Pal, g: &PinGroup, nav_order: &[String], show_hin .child(el().key("hover").pin(Some(0.0), Some(0.0), Some(0.0), Some(0.0)).radius(6.0).fill(p.hover).group_opacity(0.0, 1.0).a11y_hidden()) .child(marker) .child(label_el) + .children(count) .child(group_chevron(p, open, &toggle_key)); // The menu button shows with the pointer over the row or with focus on itself diff --git a/apps/desktop/src/shell/view/sidebar/recent.rs b/apps/desktop/src/shell/view/sidebar/recent.rs index 44c8b63cc..e6f97b56a 100644 --- a/apps/desktop/src/shell/view/sidebar/recent.rs +++ b/apps/desktop/src/shell/view/sidebar/recent.rs @@ -401,8 +401,8 @@ fn group_header(s: &App, p: &Pal, group_key: &str, g: &GroupHeader) -> El { btn = btn.child(text(n.to_string()).font(UI_SMALL).color(p.faint)); } if let Some(m) = mark { - let dot_color = if m == RecentStatus::Attention { p.warning } else { p.accent }; - btn = btn.child(el().key("group-dot").size(6.0, 6.0).radius(3.0).fill(dot_color).a11y_hidden()); + let dot = if m == RecentStatus::Attention { session_view::style::Dot::Attention } else { session_view::style::Dot::Unread }; + btn = btn.child(el().key("group-dot").child(session_view::style::status_dot(p, dot, session_view::style::DOT))); } // Under Consolidated the chevron shows with the pointer over the header or the keyboard's // focus on the header's button, on a 150 ms fade (`recent-sessions.tsx:1222-1225`, diff --git a/apps/desktop/src/shell/view/sidebar/rows.rs b/apps/desktop/src/shell/view/sidebar/rows.rs index 6c146a8ca..8e0373dc8 100644 --- a/apps/desktop/src/shell/view/sidebar/rows.rs +++ b/apps/desktop/src/shell/view/sidebar/rows.rs @@ -5,6 +5,7 @@ use super::*; use crate::session_menu::{Spot, Target}; use opencode_i18n::t; +use session_view::style::{DOT, Dot, session_busy, status_dot}; /// A collapsible section's title (`text-[12px] font-medium`) and a group's (`text-[13px]`, 440). const SECTION: TextStyle = TextStyle::new(12.0, 530.0).lh(16.0); @@ -12,7 +13,7 @@ const GROUP: TextStyle = TextStyle::new(13.0, 440.0).lh(16.0).tracking(-0.04); /// The Sessions, Pinned and Recent headers (`text-[13px] leading-4 font-medium`). pub(super) const HEADER: TextStyle = TextStyle::new(13.0, 530.0).lh(16.0).tracking(-0.04); /// A row's faint trailing label and a collapsed group's count (`text-[11px]`). -const LABEL: TextStyle = TextStyle::new(11.0, 400.0).lh(16.0); +const LABEL: TextStyle = TextStyle::new(11.0, 440.0).lh(16.0); /// A ghost-muted Button's label. const BUTTON: TextStyle = TextStyle::new(13.0, 440.0).lh(20.0).tracking(-0.04); @@ -31,14 +32,15 @@ pub(super) struct SessionRow<'a> { } /// `ProjectSessionRow`: 28 tall, 32 in (14 more per step), its title in the text colour while -/// current and faint otherwise, a ring while it works or a dot while unread; its menu on a -/// right-click. A press opens it. +/// current and faint otherwise, the busy glyph while it works or a status dot while unread or +/// failed; its menu on a right-click. A press opens it. pub(super) fn session_row(s: &App, p: &Pal, key: String, r: SessionRow) -> El { let id = r.session.id.clone(); let mark = match s.tab_status(&id) { - Some(crate::TabStatus::Busy) => Some(activity_ring(p).key("ring")), + Some(crate::TabStatus::Busy) => Some(session_busy(p)), _ if crate::session_menu::preferences::muted(r.server, &id) => Some(super::pins::muted_mark(p)), - Some(crate::TabStatus::Unread | crate::TabStatus::Failed) if !r.active => Some(el().key("unread").size(6.0, 6.0).radius(3.0).fill(p.text)), + Some(crate::TabStatus::Unread) if !r.active => Some(status_dot(p, Dot::Unread, DOT)), + Some(crate::TabStatus::Failed) if !r.active => Some(status_dot(p, Dot::Failed, DOT)), _ => None, }; let start = 32.0 + 14.0 * r.depth as f32; @@ -304,12 +306,7 @@ pub(super) fn recent_tab_row( r = r.child(lead).child(title_el); } if !editing && let Some(st) = row_data.mark { - let glyph = match st { - TabItemStatus::Busy => session_view::style::tab_busy_glyph(crate::palette::kit(p), 14.0), - TabItemStatus::Attention => el().size(7.0, 7.0).radius(3.5).fill(p.warning), - TabItemStatus::Failed => el().size(7.0, 7.0).radius(3.5).fill(p.danger), - TabItemStatus::Unread => el().size(7.0, 7.0).radius(3.5).fill(p.bg_accent), - }; + let glyph = super::sections::status_mark(p, st); r = r.child(row().key("status").pin(None, Some((h - 20.0) * 0.5), Some(4.0), None).size(20.0, 20.0).center().a11y_hidden().child(glyph)); } if !editing { diff --git a/apps/desktop/src/shell/view/sidebar/sections/mod.rs b/apps/desktop/src/shell/view/sidebar/sections/mod.rs index 38f33dfbd..8171dcd3e 100644 --- a/apps/desktop/src/shell/view/sidebar/sections/mod.rs +++ b/apps/desktop/src/shell/view/sidebar/sections/mod.rs @@ -10,6 +10,9 @@ mod menu; mod row; mod story; +/// A status's mark in a side row's slot, shared by every sidebar row. +pub(super) use row::status_mark; + use super::*; use crate::tabs::sections::{self as sec, Entry, LIVE}; use opencode_i18n::t; diff --git a/apps/desktop/src/shell/view/sidebar/sections/row.rs b/apps/desktop/src/shell/view/sidebar/sections/row.rs index b97d67895..92184c353 100644 --- a/apps/desktop/src/shell/view/sidebar/sections/row.rs +++ b/apps/desktop/src/shell/view/sidebar/sections/row.rs @@ -24,14 +24,14 @@ pub(super) fn in_slot(what: El) -> El { row().key("mark").absolute(0.0, 0.0).size(SLOT, SLOT).center().a11y_hidden().child(what) } -/// What a status draws in the slot: the busy glyph, or a 7 pt dot. -pub(super) fn status_mark(p: &Pal, status: TabItemStatus) -> El { - let dot = |key: &'static str, c: Color| el().key(key).size(7.0, 7.0).radius(3.5).fill(c).a11y_hidden(); +/// What a status draws in a row's slot: the busy glyph, or a status dot. +pub(crate) fn status_mark(p: &Pal, status: TabItemStatus) -> El { + use session_view::style::{DOT, Dot, session_busy, status_dot}; match status { - TabItemStatus::Busy => session_view::style::tab_busy_glyph(crate::palette::kit(p), 14.0), - TabItemStatus::Attention => dot("attention", p.warning), - TabItemStatus::Unread => dot("unread", p.bg_accent), - TabItemStatus::Failed => dot("failed", p.danger), + TabItemStatus::Busy => session_busy(p), + TabItemStatus::Attention => status_dot(p, Dot::Attention, DOT), + TabItemStatus::Unread => status_dot(p, Dot::Unread, DOT), + TabItemStatus::Failed => status_dot(p, Dot::Failed, DOT), } } diff --git a/apps/desktop/src/shell/view/sidebar/tab_groups.rs b/apps/desktop/src/shell/view/sidebar/tab_groups.rs index 1b57f1e57..43a12cad3 100644 --- a/apps/desktop/src/shell/view/sidebar/tab_groups.rs +++ b/apps/desktop/src/shell/view/sidebar/tab_groups.rs @@ -375,10 +375,8 @@ fn tab_row(s: &App, p: &Pal, g: &Group, t: &crate::tabs::Tab, tab_index: usize, None => text(face.title.clone()).font(UI).color(if active || mark.is_some() { p.text } else { p.muted }).grow(1.0).shrink().min_w(0.0).truncate_fade().dir(rune::Direction::Auto), }; let status_el = match mark { - Some(TabItemStatus::Busy) => Some(session_view::style::tab_busy_glyph(crate::palette::kit(p), 14.0)), - Some(TabItemStatus::Attention) => Some(el().key("attention").size(7.0, 7.0).radius(3.5).fill(p.warning).a11y_hidden()), - Some(TabItemStatus::Unread) if !active => Some(el().key("unread").size(7.0, 7.0).radius(3.5).fill(p.accent).a11y_hidden()), - Some(TabItemStatus::Failed) if !active => Some(el().key("failed").size(7.0, 7.0).radius(3.5).fill(p.danger).a11y_hidden()), + Some(m @ (TabItemStatus::Busy | TabItemStatus::Attention)) => Some(super::sections::status_mark(p, m)), + Some(m @ (TabItemStatus::Unread | TabItemStatus::Failed)) if !active => Some(super::sections::status_mark(p, m)), _ => None, }; let close_uid = uid.clone(); diff --git a/crates/opencode-ui/src/style.rs b/crates/opencode-ui/src/style.rs index b53f63c74..e43caca28 100644 --- a/crates/opencode-ui/src/style.rs +++ b/crates/opencode-ui/src/style.rs @@ -539,6 +539,58 @@ pub fn busy_ink(k: &rune_kit::Kit) -> Color { k.c.icon_muted } +// Two busy marks, one role each: +// - a session's turn running, in any navigation row (pinned, sidebar, inbox, new navigation): +// [`session_busy`], the same 14 pt glyph the tab strip draws beside it; +// - a short system or IO action (stopping a shell, a check, an upload): [`io_loader`]. + +/// A running session's mark in a navigation row: [`tab_busy_glyph`] at 14 pt, as Rune's tab +/// strip draws it, so a pinned row and the unpinned row under it read alike. +pub fn session_busy(p: &Pal) -> El { + tab_busy_glyph(crate::palette::kit(p), 14.0) +} + +/// A short system or IO action in progress: rune-kit's `Loader` at `size` (14 inline, 16 in a +/// status row) in [`busy_ink`]. Not for a session's turn ([`session_busy`]). +pub fn io_loader(p: &Pal, size: f32) -> El { + let k = crate::palette::kit(p); + rune_kit::Loader::new().size(size).color(busy_ink(k)).build(k) +} + +/// A session state a navigation row marks with a dot. +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +pub enum Dot { + Unread, + /// A permission or question waits. + Attention, + Failed, +} + +/// A status dot in a row's 20 pt status slot, as Rune's tab strip draws it (`tab.rs` `DOT`). +pub const DOT: f32 = 7.0; +/// A status dot laid over an avatar's corner (`tab.rs` `BADGE`). +pub const DOT_BADGE: f32 = 6.0; + +/// A dot's ink, the tab strip's (`tab.rs` `dot_color`): accent for unread, warning for +/// attention, danger for a failed turn. +pub fn dot_color(p: &Pal, dot: Dot) -> Color { + match dot { + Dot::Unread => p.bg_accent, + Dot::Attention => p.warning, + Dot::Failed => p.danger, + } +} + +/// A `size` pt status dot ([`DOT`] in a slot, [`DOT_BADGE`] over an avatar), keyed by its state. +pub fn status_dot(p: &Pal, dot: Dot, size: f32) -> El { + let key = match dot { + Dot::Unread => "unread", + Dot::Attention => "attention", + Dot::Failed => "failed", + }; + el().key(key).size(size, size).radius(size / 2.0).fill(dot_color(p, dot)).a11y_hidden() +} + /// Desktop's eased fade into clear (`index.css:224-243`, `select-dialog.css:131-148`): `bg` at /// full strength through its sixteen stops, as CSS writes an eased curve as a stop list. pub fn eased_fade(bg: Color) -> [(f32, Color); 16] { diff --git a/crates/session-view/src/pickers/flyout.rs b/crates/session-view/src/pickers/flyout.rs index 3371a13bb..34c8ee3a6 100644 --- a/crates/session-view/src/pickers/flyout.rs +++ b/crates/session-view/src/pickers/flyout.rs @@ -4,15 +4,19 @@ //! the row opens it ([`super::hover`]); picking an effort picks the model with it. It appears at //! once, 160 pt wide, 6 pt past the row's end with its first option level with the row //! (`placeFlyout`, `select-dialog-machine.ts:348-359`). +//! +//! It wears the dialog's own look beside it, so the two read as one surface: [`LIST`]'s 12 pt +//! concentric corners, 6 pt inset and 32 pt rows 2 pt apart, the dialog's `bg_base` fill, its +//! lit row on `row_active`, and the dialog's 0.5 pt rule between sections. use opencode_kit::model::capitalize; -use rune::{Align, Color, El, Side, TextStyle, Transition, Tx, col, el, icon, row, text}; +use rune::{Align, El, Side, TextStyle, Transition, Tx, col, el, icon, row, text}; use rune_theme_opencode::icons as ic; use super::hover::ModelHover; use super::{Kind, PickerHost}; use crate::palette::Pal; -use crate::popover::{self as pop, MENU}; +use crate::popover::{self as pop, LIST, MENU}; use crate::style::UI; /// `FLYOUT_WIDTH_PX`. @@ -40,11 +44,11 @@ pub trait EffortFlyout: PickerHost + Sized + 'static { impl EffortFlyout for S {} /// What the flyout hangs from, inside the model row `key` while its flyout is open: a line -/// across the row 2 pt above it, so the flyout's first option, 2 pt into it, lands level with +/// across the row 6 pt above it, so the flyout's first option, 6 pt into it, lands level with /// the row. pub fn anchor(s: &S, key: &str) -> Option { (s.pickers().hover.flyout_model() == Some(key) && s.pickers().open() == Some(Kind::Model)).then_some(())?; - Some(el().key("effort-anchor").pin(Some(0.0), Some(-MENU.inset), Some(0.0), None).h(0.0).transition(Transition::none())) + Some(el().key("effort-anchor").pin(Some(0.0), Some(-LIST.inset), Some(0.0), None).h(0.0).transition(Transition::none())) } /// Element key of the keyboard-highlighted option inside `#effort-flyout` (`effort-default`, @@ -72,7 +76,7 @@ pub fn view(s: &S, p: &Pal) -> Option { let keyed = active_option_key(s); let lit = keyed.as_deref().or_else(|| pk.hover.lit()); let now = s.model_effort(flyout).unwrap_or_default(); - let mut list = col().key("effort-options").w_full().py(MENU.inset); + let mut list = col().key("effort-options").w_full().py(LIST.inset).gap(LIST.row_gap); if let Some((label, reached)) = s.model_budget(flyout) { list = list.child(text(label).font(UI).color(if reached { p.v2.danger.fg } else { p.muted }).padding(8.0)).child(separator(p, "budget-rule")); } @@ -98,7 +102,8 @@ pub fn view(s: &S, p: &Pal) -> Option { })); list = list.child(separator(p, "details-separator")); list = list.child(details(p, &model.group, pk.catalog.limits.get(&model.key).copied().unwrap_or(0), &model.inputs, model.tools)); - let menu = super::hover::flyout::(pop::surface::(p, MENU, "effort-flyout", opencode_i18n::t!("ui.promptInput.chooseVariant")).w(W).child(list)); + let surface = pop::surface::(p, LIST, "effort-flyout", opencode_i18n::t!("ui.promptInput.chooseVariant")).fill(p.bg_base); + let menu = super::hover::flyout::(surface.w(W).child(list)); let mut placed = menu.anchored("effort-anchor", Side::Right, Align::Start, GAP).anchored_round(); // Match Official `placeFlyout` (`select-dialog-machine.ts:554-572`): keep full 160 pt width // and slide inward over the dialog layer when neither side has room (instead of shrinking @@ -134,8 +139,8 @@ fn slide_inward_dx() -> Option { (dx.abs() >= 0.5).then_some(dx) } -/// A `menu-v2-item` (`menu.css:35-161`): 28 pt, 12 pt before its words and 6 after, 4 pt -/// corners, on the hover overlay while the pointer is on it, inside the flyout's 2 pt inset. +/// An option: the dialog's 32 pt row with its 6 pt corners, lit on `row_active` as the dialog's +/// rows are, 12 pt before its words and 6 after, inside the flyout's 6 pt inset. fn item( p: &Pal, lit: Option<&str>, @@ -148,8 +153,8 @@ fn item( ) -> El { let option = id.to_owned(); let lit = lit == Some(id); - let mut r = row().key(id.to_owned()).role(role).label(label.to_owned()).h(MENU.row_h).w_full().pl(MENU.pad_l).pr(MENU.pad_r).gap(8.0).center_y().radius(MENU.row_radius) - .fill(if lit { p.hover } else { Color::TRANSPARENT }) + let mut r = row().key(id.to_owned()).role(role).label(label.to_owned()).h(LIST.row_h).w_full().pl(MENU.pad_l).pr(MENU.pad_r).gap(8.0).center_y().radius(LIST.row_radius) + .fill(pop::lit(p, lit)) .transition(Transition::none()) .on_hover_change(move |s: &mut S, inside, tx: &mut Tx| { tx.instant(); @@ -161,12 +166,13 @@ fn item( if let Some(c) = checked { r = r.checked(c); } - row().key(format!("{id}-inset")).w_full().px(MENU.inset).child(r) + row().key(format!("{id}-inset")).w_full().px(LIST.inset).child(r) } -/// `menu-v2-separator`: 1 pt across the whole flyout, 2 pt above and below. +/// The dialog's rule under its search (`search_row`): a 0.5 pt hairline across the whole flyout, +/// 4 pt above and below. fn separator(p: &Pal, key: &str) -> El { - el().key(key.to_owned()).w_full().h(1.0).my(MENU.inset).fill(p.border_muted) + rune::hairline(p.border).key(key.to_owned()).w_full().my(4.0) } /// Favorite's shortcut as Compact Square keycap chips. @@ -187,7 +193,7 @@ fn details(p: &Pal, provider: &str, context: u64, inputs: &[String], tools: bool _ => opencode_i18n::t!("model.details.input.video"), }).chain(tools.then(|| opencode_i18n::t!("model.details.tools"))).collect(); // `select-dialog.css:229-231` (`padding: 2px` on `[data-scrollable]`) + `details.tsx:151` (`px-3 py-2`). - col().key("effort-details").w_full().px(12.0 + MENU.inset).py(8.0) + col().key("effort-details").w_full().px(MENU.pad_l + LIST.inset).py(8.0) .child(text(summary).key("summary").font(STATS).color(p.muted).wrap()) .children((!abilities.is_empty()).then(|| text(abilities.join(", ")).key("abilities").font(STATS).color(p.muted).wrap())) } diff --git a/crates/session-view/src/pickers/hover.rs b/crates/session-view/src/pickers/hover.rs index 68c292fe8..d8b1c3e85 100644 --- a/crates/session-view/src/pickers/hover.rs +++ b/crates/session-view/src/pickers/hover.rs @@ -6,8 +6,8 @@ //! - The first flyout waits 100 ms of the pointer on a row; while one is open, and for 300 ms //! after the pointer leaves it, the next opens at once. //! - A safe triangle, from the pointer's last point on the flyout's row to the flyout's near -//! corners, keeps the flyout while the pointer crosses other rows on its way in. Resting on a -//! row inside it for 300 ms hands over to that row, as on macOS. +//! corners, keeps the flyout while the pointer crosses other rows on its way in. Stopping on a +//! row inside it (no more progress toward the flyout) for 180 ms hands over to that row. //! - A wheel scroll lights the row it brings under the pointer and moves the flyout beside it. //! - The keys drive it too: the flyout opens beside the row the dialog opens on, and follows the //! highlight as the arrow keys and typing move it; rows they scroll under a still pointer leave @@ -311,12 +311,13 @@ pub fn row(e: El, key: &str) -> El { } /// The model list's scroll: where it draws, and a wheel scroll lighting the rows it brings under -/// the pointer. The list moving (Desktop's window `resize`) closes the flyout, which was placed -/// beside its row. +/// the pointer. The list moving or changing width (Desktop's window `resize`) closes the +/// flyout, which was placed beside its row; the list only growing or shrinking at its foot (results +/// landing, a sub-point settle) leaves it, since the flyout hangs from its row and follows it. pub fn scroll(e: El) -> El { e.on_drawn_layout_tx(|s: &mut S, r, tx: &mut Tx| { let was = s.pickers_mut().hover.list.replace(r); - if was.is_some_and(|w| w != r) { + if was.is_some_and(|w| moved(w, r)) { s.model_flyout_dismissed(tx); } }) @@ -326,6 +327,11 @@ pub fn scroll(e: El) -> El { }) } +/// Whether the list moved or changed width by a point or more (its height alone doesn't count). +fn moved(was: Rect, now: Rect) -> bool { + (was[0] - now[0]).abs() >= 1.0 || (was[1] - now[1]).abs() >= 1.0 || (was[2] - now[2]).abs() >= 1.0 +} + /// The flyout: where it draws, and the pointer reaching it. pub fn flyout(e: El) -> El { e.on_drawn_layout_tx(|s: &mut S, r, tx: &mut Tx| { diff --git a/crates/session-view/src/pickers/hover/machine.rs b/crates/session-view/src/pickers/hover/machine.rs index be85f5563..a1d494592 100644 --- a/crates/session-view/src/pickers/hover/machine.rs +++ b/crates/session-view/src/pickers/hover/machine.rs @@ -8,9 +8,13 @@ use rune::machine::{Attempt, Effects}; /// `FLYOUT_OPEN_DELAY_MS`: how long the pointer rests on a row before its flyout opens, unless /// a flyout was just open. pub const OPEN_DELAY: f64 = 0.1; -/// `FLYOUT_AIM_TIMEOUT_MS`: how long the pointer may rest on a row inside the safe triangle -/// before the flyout moves to that row. -pub const AIM_TIMEOUT: f64 = 0.3; +/// How long the pointer may rest on a row inside the safe triangle before the flyout moves to +/// that row. Desktop waits 300 ms (`FLYOUT_AIM_TIMEOUT_MS`) and restarts it on every move; here +/// only progress toward the flyout ([`AIM_PROGRESS`]) restarts it, so a pointer that stops or +/// jitters on a row hands over in at most this long. +pub const AIM_TIMEOUT: f64 = 0.18; +/// How far (pt) the pointer must move toward the flyout to count as still aiming at it. +pub const AIM_PROGRESS: f32 = 1.0; /// `FLYOUT_WARM_MS`: how long after a flyout closes that the next row's flyout still opens at once. pub const WARM: f64 = 0.3; @@ -36,8 +40,8 @@ pub enum State { Open { attempt: Attempt, id: String, apex: Point }, Keyed { attempt: Attempt, id: String, option: Option }, /// The pointer crossed onto row `target` on its way to the flyout; the flyout stays on `id` - /// while it keeps moving. - Aiming { attempt: Attempt, id: String, apex: Point, target: String }, + /// while it keeps moving toward it. `at`: where it last made progress. + Aiming { attempt: Attempt, id: String, apex: Point, target: String, at: Point }, } impl Default for State { @@ -207,15 +211,20 @@ fn moved(state: &mut State, id: &str, active: Option<&str>, point: Point, flyout let open = matches!(state, State::Open { .. } | State::Aiming { .. }); // On its way to the flyout, the pointer crosses other rows without taking the flyout with it. if open && flyout_id(state) != Some(id) && inside(point, apex(state), flyout) { - // Each move restarts the wait: the flyout moves only once the pointer rests on the row. - if let State::Aiming { attempt, target, .. } = state + // Only a move toward the flyout restarts the wait; a rest or a jitter lets it run out, so + // the flyout follows the pointer onto the row it stopped on without lag. + if let State::Aiming { attempt, target, at, .. } = state && target.as_str() == id { + if !toward(*at, point, flyout) { + return Effects::none(); + } + *at = point; return Effects::one(Effect::Schedule { kind: Timer::Aim, attempt: *attempt, delay: AIM_TIMEOUT }); } let attempt = following(attempt(state)); let (from, apex) = (flyout_id(state).unwrap_or_default().to_owned(), apex(state)); - *state = State::Aiming { attempt, id: from, apex, target: id.to_owned() }; + *state = State::Aiming { attempt, id: from, apex, target: id.to_owned(), at: point }; return Effects::one(Effect::Schedule { kind: Timer::Aim, attempt, delay: AIM_TIMEOUT }); } // Back on the flyout's own row: the pointer becomes the triangle's apex again. @@ -314,6 +323,15 @@ pub fn follows_pointer(state: &State) -> bool { !matches!(state, State::Closed { input: Input::Keyboard, .. } | State::Keyed { .. }) } +/// Whether the pointer moving from `from` to `to` closed at least [`AIM_PROGRESS`] on the flyout's +/// near edge. +fn toward(from: Point, to: Point, flyout: Option) -> bool { + let Some(f) = flyout else { return false }; + let dx = to[0] - from[0]; + let gain = if f[0] >= from[0] { dx } else { -dx }; + gain >= AIM_PROGRESS +} + /// `inside`: whether `p` is in the triangle from `apex` to the flyout's near corners, as on macOS. pub fn inside(p: Point, apex: Point, flyout: Option) -> bool { let Some(f) = flyout else { return false }; diff --git a/features/subagents/src/activity.rs b/features/subagents/src/activity.rs index 62dac10ab..b744f51d9 100644 --- a/features/subagents/src/activity.rs +++ b/features/subagents/src/activity.rs @@ -96,12 +96,14 @@ pub enum Panel { } /// The machine: the panel, the counter its attempts come from, and the Stops in flight by row -/// key (a shell's id, a subagent's session) with their attempts. +/// key (a shell's id, a subagent's session) with their attempts. `armed`: the row whose Stop +/// was pressed once and waits for a second press to confirm, with when (the panel's clock, ms). #[derive(Clone, Debug, Default, PartialEq)] pub struct Activity { pub panel: Panel, issued: u64, pub stopping: BTreeMap, + pub armed: Option<(String, i64)>, } /// What runs in the background now (`ShellPanelWork`): row keys. @@ -313,7 +315,7 @@ fn to_ending(state: Activity) -> (Activity, Vec) { /// the menu is shut. Stops in flight carry on. fn close(state: Activity) -> (Activity, Vec) { let effects = leave(&state); - (Activity { panel: Panel::Closed, issued: state.issued + 1, ..state }, effects) + (Activity { panel: Panel::Closed, issued: state.issued + 1, armed: None, ..state }, effects) } /// Leaving a view drops the shown shell's end lookup. diff --git a/features/subagents/src/lib.rs b/features/subagents/src/lib.rs index 73dbcecb8..a2b7bc49a 100644 --- a/features/subagents/src/lib.rs +++ b/features/subagents/src/lib.rs @@ -26,7 +26,7 @@ use session_view::inline::InlineSwap; use session_view::odometer::odometer; use session_view::palette::{Elevate as _, Pal}; use session_view::roll::SLIDE; -use session_view::style::{INSTANT, UI, UI_MED, activity_ring_sized}; +use session_view::style::{INSTANT, UI, activity_ring_sized}; pub use session_view::knobs::CAPSULE_RADIUS; pub use session_view::subagent_card::{elapsed, run_time}; @@ -438,13 +438,15 @@ pub fn chip_with_knobs(knobs: &Knobs, p: &Pal, key: &str, label: String, open: b } /// The capsule's list (`session-activity-panel`): a floating menu above the capsule, start -/// edges aligned, one 28pt row per running subagent with the spinner, the agent in medium, its -/// task in muted text and the run time in 11pt at the end, then one per background shell with -/// the console mark and its command across the agent and task columns. Agents and run times -/// line up in columns; the task takes the rest and fades out where it's cut once the menu -/// reaches 360pt. Hovering a row swaps its run time for a stop button. Past 270pt the rows -/// scroll inside the menu, fading only where rows hide under its edge, and nothing draws -/// outside it. A shell's row opens its own panel in place (`shells_view::panel`). +/// edges aligned, one 28pt row per running subagent with the spinner, a named agent's badge +/// (none for the default `general`), its task in muted text and its own run time in 11pt right +/// after it, then one per background shell with the console mark and its command. The task +/// fades out where it's cut once the menu reaches [`PANEL_W`], the width a shell's panel opens +/// at, so a list with shells in it opens at that width and drilling in doesn't jump. Hovering a +/// row swaps its run time for a Stop pill that asks once more before it stops anything +/// (`shells_view::end`). Past 270pt the rows scroll inside the menu, fading only where rows hide +/// under its edge, and nothing draws outside it. Its corners are concentric with the rows' +/// (`PANEL_PAD` + `ROW_RADIUS`), the lit row on `row_active` as every popover's is. pub fn panel(host: &H, p: &Pal, id: &str) -> Option { if !host.shells().activity.is_open() { return None; @@ -460,9 +462,9 @@ pub fn panel(host: &H, p: &Pal, id: &str) -> Option< let (visible, hover, stop_key) = (child.clone(), child.clone(), child.clone()); let name = subagent_name(it); let ms = (it.started > 0).then(|| clock - it.started); - let end_el = shells_view::end(host, p, &it.session, activity::Kind::Subagent, ms, layout.time_w); + let end_el = shells_view::end(host, p, &it.session, activity::Kind::Subagent, ms); list = list.child( - build_subagent_row_shell(p, it, name, layout.agent_w, end_el) + build_subagent_row_shell(p, it, name, end_el) .on_visible(move |s: &mut H, on, tx: &mut Tx| prefetch_on_visible(s, &visible, on, tx)) .on_hover_change(move |s: &mut H, inside, tx: &mut Tx| prefetch_on_hover(s, &hover, inside, tx)) .on_press_tx(move |s: &mut H, tx: &mut Tx| open_child_instant(s, &parent, &child, &title, &agent, tx)) @@ -470,27 +472,24 @@ pub fn panel(host: &H, p: &Pal, id: &str) -> Option< ); } for sc in &layout.scripts { - list = list.child(shells_view::script_row(host, p, sc, layout.span, layout.time_w)); + list = list.child(shells_view::script_row(host, p, sc)); } for sh in &layout.shell_items { - list = list.child(shells_view::row_of(host, p, sh, layout.span, layout.time_w)); + list = list.child(shells_view::row_of(host, p, sh)); } // `MenuScroll` (`activity-chips.tsx:214`). What it holds comes in with the list, not on fades // of its own. let rows = session_view::scroller::scroller("activity-scroll") .bar(session_view::scroller::Bar::MenuScroll) .build::(p, col().w_full().h(layout.h).scroll_edge_fade(12.0).scroll_margin(PANEL_PAD).instant_changes(), list); - Some(build_panel_frame(host.knobs(), p, layout.natural, layout.label, rows).on_press(|_: &mut H| {})) + Some(build_panel_frame(host.knobs(), p, layout.width, layout.label, rows).on_press(|_: &mut H| {})) } struct PanelLayout { items: Vec, scripts: Vec, shell_items: Vec, - agent_w: f32, - time_w: f32, - span: f32, - natural: f32, + width: f32, h: f32, label: String, } @@ -503,27 +502,30 @@ fn prepare_panel_layout(host: &dyn SubagentsHost, id: &str) -> Option 0 { elapsed(clock - started) } else { String::new() }; // Parley shapes an empty string as a synthetic space for caret metrics (`full_width()` > 0), - // so an unguarded `measure("")` leaves `agent_w` > 0 and mounts a ghost column plus extra gap. + // so an unguarded `measure("")` would count a ghost badge and gap. let width = |t: &str, style| if t.is_empty() { 0.0 } else { rune::text::measure(t, &[], style, None).0 }; - let agent_w = items.iter().map(|it| width(&subagent_name(it), UI_MED)).fold(0.0, f32::max); - let times = items.iter().map(|it| it.started).chain(scripts.iter().map(|sc| sc.started)).chain(shell_items.iter().map(|sh| sh.started)); - let time_w = time_column(times.map(time_at), &width); - let label_w = items.iter().map(|it| width(&it.label, UI)).fold(0.0, f32::max); - // A script's or shell's command spans the agent and task columns and the gap between them. + // A named agent's badge and its gap, then the task: each row's own, with no shared column. + let task_w = |it: &Running| { + let name = subagent_name(it); + let badge = if name.is_empty() { 0.0 } else { shells_view::badge_w(&name) + 6.0 }; + badge + width(&it.label, UI) + }; + let label_w = items.iter().map(task_w).fold(0.0, f32::max); let commands = scripts.iter().map(|sc| sc.label.as_str()).chain(shell_items.iter().map(|sh| sh.command.as_str())); let command_w = commands.map(|c| width(&shells_view::one_line(c), shells_view::COMMAND)).fold(0.0, f32::max); - // With no named agent the column and its gap go. - let agent_col = if agent_w > 0.0 { agent_w + 6.0 } else { 0.0 }; - let span = (agent_col + label_w).max(command_w); - // Panel inset 4 + hairline 0.5, row inset 4, then the mark, agent and task (or command) and - // time, 6 apart, with 8 more before the time (`activity-chips.css:9-64`). - let natural = 2.0 * (PANEL_PAD + 0.5 + 4.0) + 16.0 + 6.0 + span + 14.0 + time_w + if session_view::style::hover_none() { 46.0 } else { 0.0 }; + let span = label_w.max(command_w); + let starts = items.iter().map(|it| it.started).chain(scripts.iter().map(|sc| sc.started)).chain(shell_items.iter().map(|sh| sh.started)); + let end_w = starts.map(|started| shells_view::end_w((started > 0).then(|| clock - started))).fold(0.0, f32::max); + // Panel inset 4 + hairline 0.5, row inset 4, then the mark, the task (or command) and the + // row's end, 6 apart. + let natural = 2.0 * (PANEL_PAD + 0.5 + 4.0) + 16.0 + 6.0 + span + 6.0 + end_w + if session_view::style::hover_none() { 46.0 } else { 0.0 }; + // A list with shells opens as wide as a shell's panel, so drilling into one doesn't jump. + let width = if shell_items.is_empty() { natural.clamp(PANEL_MIN_W, PANEL_W).ceil() } else { PANEL_W }; let n = items.len() + scripts.len() + shell_items.len(); let h = (n as f32 * panel_row() + 2.0 * PANEL_PAD).min(PANEL_MAX_H); let label = activity::summary(items.len(), scripts.len(), shell_items.len()).label; - Some(PanelLayout { items, scripts, shell_items, agent_w, time_w, span, natural, h, label }) + Some(PanelLayout { items, scripts, shell_items, width, h, label }) } /// The agent's name in its column: none for the default `general` agent (`events::agent_name`). @@ -531,7 +533,7 @@ fn subagent_name(it: &Running) -> String { session_view::activity::events::agent_name(Some(&it.agent)).unwrap_or_default() } -fn build_subagent_row_shell(p: &Pal, it: &Running, name: String, agent_w: f32, end_el: El) -> El { +fn build_subagent_row_shell(p: &Pal, it: &Running, name: String, end_el: El) -> El { row() .key(format!("sub-{}", it.session)) .role("menuitem") @@ -541,27 +543,27 @@ fn build_subagent_row_shell(p: &Pal, it: &Running, name: String, agent_w: f32, e .px(4.0) .gap(6.0) .center_y() - .radius(4.0) + .radius(ROW_RADIUS) .focus_default(p) - .hover(p.hover) + .hover(p.row_active) .hover_motion(INSTANT, INSTANT) .hover_group_focus() .child(activity_ring_sized(p, 16.0)) - // A `general` row keeps the column empty so the tasks line up; with no named agent at all - // the column and its gap go. - .children((agent_w > 0.0).then(|| text(name).font(UI_MED).color(p.text).w(agent_w))) - .child(text(it.label.clone()).key("label").dir(rune::Direction::Auto).font(UI).color(p.muted).truncate_fade().grow(1.0).shrink().min_w(0.0)) + // A `general` row's task sits right after the spinner; a named agent's compact badge comes + // before its task. + .children((!name.is_empty()).then(|| session_view::popover::badge(p, &name).key("agent"))) + .child(text(it.label.clone()).key("label").dir(rune::Direction::Auto).font(UI).color(p.muted).truncate_fade().shrink().min_w(0.0)) .child(end_el) } -fn build_panel_frame(knobs: &Knobs, p: &Pal, natural: f32, label: String, rows: El) -> El { +fn build_panel_frame(knobs: &Knobs, p: &Pal, width: f32, label: String, rows: El) -> El { col() .key("activity-panel") .role("menu") .label(label) .above("activity-chip", 8.0) - .w(natural.clamp(240.0, 360.0).ceil()) - .radius(10.0) + .w(width) + .radius(PANEL_RADIUS) .fill(p.layer1) .elevate(p.floating) .clip_soft(0.0) @@ -590,15 +592,14 @@ fn open_child_instant(host: &mut dyn SubagentsHost, parent: &str, child: &str, t open_child(host, parent, child, title, agent, tx); } -/// The run-time column's width: the longest time shown, its figures tabular so ticking moves -/// nothing until a time gains a unit, as Desktop's grid column is as wide as its longest run -/// time (`activity-chips.css:77-91`); at least the stop button that swaps in for it. -fn time_column(times: impl Iterator, width: &impl Fn(&str, rune::TextStyle) -> f32) -> f32 { - let widest = |t: &str| width(&t.chars().map(|c| if c.is_ascii_digit() { '0' } else { c }).collect::(), ELAPSED); - times.map(|t| widest(&t)).fold(20.0, f32::max) -} - pub(crate) const PANEL_PAD: f32 = 4.0; +/// A row's corners inside the list's 4 pt inset. +pub(crate) const ROW_RADIUS: f32 = 4.0; +/// The list's corners: concentric with its rows' (`popover::Look::radius`). +pub(crate) const PANEL_RADIUS: f32 = PANEL_PAD + ROW_RADIUS; +/// The list's width bounds; a shell's panel opens at the widest, so drilling in never jumps. +const PANEL_MIN_W: f32 = 240.0; +pub(crate) const PANEL_W: f32 = 480.0; pub(crate) fn panel_row() -> f32 { if session_view::style::hover_none() { 44.0 } else { 28.0 } } diff --git a/features/subagents/src/reply.rs b/features/subagents/src/reply.rs index 7ac8e8677..e38fdaf05 100644 --- a/features/subagents/src/reply.rs +++ b/features/subagents/src/reply.rs @@ -47,6 +47,32 @@ const SUMMARY_FADE: f32 = 18.0; /// an orphaned variant label beside `·`. const MODEL_MIN_W: f32 = 40.0; +/// How long the latest run took, or has taken so far: from when it started (`time.busy`), not +/// from when the session was made, so a follow-up that wakes an old worker counts its own +/// seconds. A running session's `busy` counts only when it's this run's: after its last idle and +/// not ahead of the unrounded clock (in a run's first partial second it is ahead of the +/// whole-second `run_clock`, and is still valid). Without one, a running session counts from when +/// its last run ended (`run_started`) and a finished one from its creation. Never below zero. +fn run_ms(host: &dyn SubagentsHost, info: &SessionInfo, running: bool) -> i64 { + let (end, start) = if running { + let now = host.now_ms(); + let since_idle = info.idle.unwrap_or(info.created); + let start = match info.busy { + Some(busy) if busy >= info.created && busy >= since_idle && busy <= now => busy, + _ => host.run_started(&info.id, None), + }; + (run_clock(host), start) + } else { + let end = info.idle.unwrap_or(info.updated); + let start = match info.busy { + Some(busy) if busy >= info.created && busy <= end => busy, + _ => info.created, + }; + (end, start) + }; + (end - start).max(0) +} + fn bar_w(s: &str) -> f32 { if s.is_empty() { 0.0 } else { rune::text::measure(s, &[], BAR, None).0 } } @@ -111,15 +137,18 @@ fn model_view(p: &Pal, m: SubagentModel) -> (El, f32) { fn build_status_line(host: &dyn SubagentsHost, p: &Pal, id: &str, back: El) -> Option { let info = host.session_info(id).filter(|i| i.parent.is_some())?; let running = subtree_running(host, id); - let (glyph, status) = if running { - (None, Some(opencode_i18n::t!("session.child.status.running"))) + // A clean run stays as quiet as the rest of the bar; a failed one is red and an interrupted + // one amber, its mark and word both, as the timeline marks them. + let quiet = (p.faint, p.icon_faint); + let (glyph, status, (tone, icon_tone)) = if running { + (None, Some(opencode_i18n::t!("session.child.status.running")), quiet) } else { match info.outcome.as_deref() { - Some("succeeded") => (Some(&ic::CHECK), Some(opencode_i18n::t!("session.child.status.succeeded"))), + Some("succeeded") => (Some(&ic::CHECK), Some(opencode_i18n::t!("session.child.status.succeeded")), quiet), // Official `subagent-bar.tsx:53-55` uses `close` for both failed and interrupted runs. - Some("failed") => (Some(&ic::OUTLINE_XMARK), Some(opencode_i18n::t!("session.child.status.failed"))), - Some("interrupted") => (Some(&ic::OUTLINE_XMARK), Some(opencode_i18n::t!("session.child.status.interrupted"))), - _ => (None, None), + Some("failed") => (Some(&ic::OUTLINE_XMARK), Some(opencode_i18n::t!("session.child.status.failed")), (p.danger, p.danger)), + Some("interrupted") => (Some(&ic::OUTLINE_XMARK), Some(opencode_i18n::t!("session.child.status.interrupted")), (p.warning, p.warning)), + _ => (None, None, quiet), } }; let words = |t: String| text(t).font(BAR).color(p.faint).single_line(); @@ -138,9 +167,8 @@ fn build_status_line(host: &dyn SubagentsHost, p: &Pal, id: &str, back: El) -> O out }; if let Some(st) = status { - let end = if running { run_clock(host) } else { info.idle.unwrap_or(info.updated) }; - let ms = end - info.created.min(end); - summary = sep(summary, &mut count, &mut min_w).child(words(st.to_owned()).key("status")); + let ms = run_ms(host, info, running); + summary = sep(summary, &mut count, &mut min_w).child(text(st.to_owned()).font(BAR).color(tone).single_line().key("status")); min_w += bar_w(st); summary = sep(summary, &mut count, &mut min_w).child(run_time(format!("bar-time-{id}"), ms, BAR, p.faint)); min_w += bar_w(&crate::elapsed(ms)); @@ -180,7 +208,7 @@ fn build_status_line(host: &dyn SubagentsHost, p: &Pal, id: &str, back: El) -> O if status.is_some() { let mark = el().key("status-icon").size(16.0, 16.0).center(); line = line.child(match glyph { - Some(g) => mark.child(icon(g, 14.0).color(p.icon_faint)), + Some(g) => mark.child(icon(g, 14.0).color(icon_tone)), None => mark.child(activity_ring_sized(p, 16.0)), }); } diff --git a/features/subagents/src/shells/view.rs b/features/subagents/src/shells/view.rs index ad883444b..9558e64f4 100644 --- a/features/subagents/src/shells/view.rs +++ b/features/subagents/src/shells/view.rs @@ -5,65 +5,130 @@ use rune::{El, Key, KeyEvent, Tx, col, icon, row, text}; use rune_knobs::Knobs; use rune_theme_opencode::icons as ic; use session_view::focus::FocusExt; -use session_view::palette::{Elevate as _, Pal, kit}; -use session_view::style::{INSTANT, UI}; +use session_view::palette::{Elevate as _, Pal}; +use session_view::style::{INSTANT, UI, io_loader}; use super::tail; use super::{Shell, dispatch}; use crate::activity::{End, EndStatus, Event, Kind, Phase}; use crate::jobs::Script; -use crate::{ELAPSED, PANEL_PAD, SubagentsHost, elapsed, panel_clock, panel_row, run_time}; +use crate::{ELAPSED, PANEL_PAD, PANEL_RADIUS, PANEL_W, ROW_RADIUS, SubagentsHost, elapsed, panel_clock, panel_row, run_time}; /// The command in a row and the panel's header: the code face at 13/20 (`session-activity-shell-command`). pub const COMMAND: rune::TextStyle = session_view::style::TOOL_CODE.lh(20.0); -/// The shell panel's width (`min(560px, 100vw - 56px)`) and height cap (`min(320px, …)`). -const WIDE: f32 = 560.0; +/// The shell panel's width (the list's widest, so opening a shell from the list never jumps) +/// and height cap (`min(320px, …)`). +const WIDE: f32 = PANEL_W; const MAX_H: f32 = 320.0; +/// The Stop pill's word: 11 pt medium, on the run time's line. +const STOP: rune::TextStyle = rune::TextStyle::new(11.0, 530.0).lh(16.0); +/// A named agent's badge face (`popover::badge`): 11 pt medium, 4 pt in, a 0.5 pt ring. +const BADGE: rune::TextStyle = rune::TextStyle::new(11.0, 530.0).lh(11.0); +/// How long a first press on Stop waits for the second, on the panel's whole-second clock. +const ARM_MS: i64 = 3000; /// The tail shows its last 14 lines (`TAIL_LINES`). const TAIL_LINES: usize = 14; -/// A shell's row in the list: the console mark, its command across the agent and task columns, -/// and its run time, which hover swaps for a stop button. -pub fn row_of(host: &H, p: &Pal, sh: &Shell, span: f32, time_w: f32) -> El { +/// A shell's row in the list: the console mark, its command, and its run time, which hover swaps +/// for the Stop pill. +pub fn row_of(host: &H, p: &Pal, sh: &Shell) -> El { let open = sh.clone(); let stop_key = sh.id.clone(); - let end_el = end(host, p, &sh.id, Kind::Shell, (sh.started > 0).then(|| panel_clock(host) - sh.started), time_w); - build_row_shell(p, &format!("shell-{}", sh.id), &ic::CONSOLE, &sh.command, span, end_el) + let end_el = end(host, p, &sh.id, Kind::Shell, (sh.started > 0).then(|| panel_clock(host) - sh.started)); + build_row_shell(p, &format!("shell-{}", sh.id), &ic::CONSOLE, &sh.command, end_el) .on_press_tx(move |s: &mut H, tx: &mut Tx| select_shell(s, open.clone(), tx)) .on_key(move |s: &mut H, ev: &KeyEvent, tx: &mut Tx| stop_on_delete(s, &stop_key, Kind::Shell, ev, tx)) } -/// A background Code Mode script's row: the code mark, its first line across the agent and task -/// columns, and its run time, which hover swaps for a stop button. Selecting it does nothing -/// (a script has nowhere to open, `activity-chips.tsx`'s `row`). -pub fn script_row(host: &H, p: &Pal, sc: &Script, span: f32, time_w: f32) -> El { +/// A background Code Mode script's row: the code mark, its first line, and its run time, which +/// hover swaps for the Stop pill. Selecting it does nothing (a script has nowhere to open, +/// `activity-chips.tsx`'s `row`). +pub fn script_row(host: &H, p: &Pal, sc: &Script) -> El { let stop_key = sc.id.clone(); - let end_el = end(host, p, &sc.id, Kind::Script, (sc.started > 0).then(|| panel_clock(host) - sc.started), time_w); - build_row_shell(p, &format!("script-{}", sc.id), &ic::CODE, &sc.label, span, end_el) + let end_el = end(host, p, &sc.id, Kind::Script, (sc.started > 0).then(|| panel_clock(host) - sc.started)); + build_row_shell(p, &format!("script-{}", sc.id), &ic::CODE, &sc.label, end_el) .on_key(move |s: &mut H, ev: &KeyEvent, tx: &mut Tx| stop_on_delete(s, &stop_key, Kind::Script, ev, tx)) } -/// Pressing Delete or Backspace on a focused activity row stops it (`activity-chips.tsx:129-134`). +/// Delete or Backspace on a focused activity row presses its Stop (`activity-chips.tsx:129-134`): +/// the first press asks, the second stops. Escape takes the question back. pub(crate) fn stop_on_delete(host: &mut dyn SubagentsHost, key: &str, kind: Kind, ev: &KeyEvent, tx: &mut Tx) -> bool { - if !matches!(ev.key, Key::Delete | Key::Backspace) { - return false; + match ev.key { + Key::Delete | Key::Backspace => press_stop(host, key, kind, tx), + Key::Escape if is_armed(host, key) => disarm(host, key), + _ => return false, } - request_stop(host, key.to_owned(), kind, tx); true } -/// A row's end (`session-activity-end`): its run time, and the stop button over it, shown under -/// the pointer or while its Stop is out. -pub fn end(host: &H, p: &Pal, key: &str, kind: Kind, ms: Option, time_w: f32) -> El { +/// Whether row `key`'s Stop was pressed once in the last [`ARM_MS`] and asks to be pressed again. +fn is_armed(host: &dyn SubagentsHost, key: &str) -> bool { + host.shells().activity.armed.as_ref().is_some_and(|(k, at)| k == key && panel_clock(host) - at < ARM_MS) +} + +/// A press on row `key`'s Stop: the first turns it into a red "Stop?", the second stops it. +fn press_stop(host: &mut dyn SubagentsHost, key: &str, kind: Kind, tx: &mut Tx) { + if is_armed(host, key) { + host.shells_mut().activity.armed = None; + return request_stop(host, key.to_owned(), kind, tx); + } + tx.instant(); + let at = panel_clock(host); + host.shells_mut().activity.armed = Some((key.to_owned(), at)); +} + +fn disarm(host: &mut dyn SubagentsHost, key: &str) { + if host.shells().activity.armed.as_ref().is_some_and(|(k, _)| k == key) { + host.shells_mut().activity.armed = None; + } +} + +/// The Stop pill's width: its widest word, "Stop?", 6 in each side. +fn stop_w() -> f32 { + let words = format!("{}?", opencode_i18n::t!("session.activity.shell.stop")); + (rune::text::measure(&words, &[], STOP, None).0 + 12.0).ceil() +} + +/// A named agent's badge width ([`session_view::popover::badge`]). +pub(crate) fn badge_w(name: &str) -> f32 { + rune::text::measure(name, &[], BADGE, None).0 + 9.0 +} + +/// A row's end width: its run time, figures tabular so ticking moves nothing until a time gains +/// a unit, or the Stop pill that swaps in for it, whichever is wider. +pub(crate) fn end_w(ms: Option) -> f32 { + let time = ms.map_or(0.0, |ms| { + let t: String = elapsed(ms).chars().map(|c| if c.is_ascii_digit() { '0' } else { c }).collect(); + rune::text::measure(&t, &[], ELAPSED, None).0.ceil() + }); + time.max(stop_w()) +} + +/// A row's end (`session-activity-end`): its own run time right after its words, and the Stop +/// pill over it, shown under the pointer, while it asks, or while its Stop is out. +pub fn end(host: &H, p: &Pal, key: &str, kind: Kind, ms: Option) -> El { let stopping = host.shells().activity.stopping.contains_key(key); - let target = key.to_owned(); - let stop = build_stop_button_shell(p, kind, stopping); + let armed = !stopping && is_armed(host, key); + let stop = build_stop_button_shell(p, kind, stopping, armed); let stop = if stopping { stop } else { - stop.on_press_tx(move |s: &mut H, tx: &mut Tx| request_stop(s, target.clone(), kind, tx)) + let (target, left, esc) = (key.to_owned(), key.to_owned(), key.to_owned()); + stop.on_press_tx(move |s: &mut H, tx: &mut Tx| press_stop(s, &target, kind, tx)) + .on_hover_change(move |s: &mut H, inside, _: &mut Tx| { + if !inside { + disarm(s, &left); + } + }) + .on_key(move |s: &mut H, ev: &KeyEvent, _: &mut Tx| { + let hit = ev.key == Key::Escape && is_armed(s, &esc); + if hit { + disarm(s, &esc); + } + hit + }) }; - build_end_layout(p, key, ms, time_w, stopping, stop) + build_end_layout(p, key, ms, stopping || armed, stop) } /// The panel of the shell the list opened: back, its command, run time and Stop (or how it @@ -114,7 +179,7 @@ fn back_pressed(host: &mut dyn SubagentsHost, tx: &mut Tx) { dispatch(host, Event::Back); } -fn build_row_shell(p: &Pal, key: &str, mark: &'static rune::Icon, command: &str, span: f32, end_el: El) -> El { +fn build_row_shell(p: &Pal, key: &str, mark: &'static rune::Icon, command: &str, end_el: El) -> El { row() .key(key) .role("menuitem") @@ -124,13 +189,13 @@ fn build_row_shell(p: &Pal, key: &str, mark: &'static rune::Icon, command: &str, .px(4.0) .gap(6.0) .center_y() - .radius(4.0) + .radius(ROW_RADIUS) .focus_default(p) - .hover(p.hover) + .hover(p.row_active) .hover_motion(INSTANT, INSTANT) .hover_group_focus() .child(icon(mark, 16.0).key("mark").color(p.icon_muted)) - .child(text(one_line(command)).key("command").font(COMMAND).color(p.text).truncate_fade().w(span).grow(1.0).shrink().min_w(0.0)) + .child(text(one_line(command)).key("command").font(COMMAND).color(p.text).truncate_fade().shrink().min_w(0.0)) .child(end_el) } @@ -141,42 +206,49 @@ pub fn one_line(command: &str) -> String { command.split_whitespace().collect::>().join(" ") } -fn build_stop_button_shell(p: &Pal, kind: Kind, stopping: bool) -> El { +/// The Stop pill: "Stop", its tooltip saying what it stops; pressed once it turns into a red +/// "Stop?" that a second press confirms. While the stop is out, the IO loader. +fn build_stop_button_shell(p: &Pal, kind: Kind, stopping: bool, armed: bool) -> El { let label = match kind { Kind::Subagent => opencode_i18n::t!("session.running.stop.subagent"), Kind::Script => opencode_i18n::t!("session.running.stop.script"), Kind::Shell => opencode_i18n::t!("session.running.stop.shell"), }; - let mark = if stopping { rune_kit::Loader::new().size(14.0).build(kit(p)) } else { icon(&ic::OUTLINE_XMARK, 14.0).color(p.icon_muted) }; // Do not set `hover_alone()`: `build_end_layout` reveals this button via the row's // `group_opacity(0.0, 1.0)`, so shadowing the row's hover would hide the button as soon as // the pointer reaches it (`packages/app/src/session/composer/activity-chips.css:101-114`). - let b = row() - .key("stop") - .role("button") - .label(label) - .size(20.0, 20.0) - .center() - .radius(4.0) - .child(mark); + let b = row().key("stop").role("button").label(label).h(20.0).center().radius(4.0); if stopping { - b.disabled(true).busy(true) - } else { - b.focus_default(p).hover(p.hover).press(p.pressed).hover_motion(INSTANT, INSTANT) + return b.w(20.0).child(io_loader(p, 14.0)).disabled(true).busy(true); } + let word = opencode_i18n::t!("session.activity.shell.stop"); + let (words, ink, fill, hover) = if armed { + (format!("{word}?"), p.danger, p.danger.alpha(0.14), p.danger.alpha(0.2)) + } else { + (word.to_owned(), p.muted, p.hover, p.pressed) + }; + b.px(6.0) + .help(label) + .fill(fill) + .focus_default(p) + .hover(hover) + .press(p.pressed) + .hover_motion(INSTANT, INSTANT) + .instant_changes() + .child(text(words).key("stop-word").font(STOP).color(ink).single_line()) } -fn build_end_layout(p: &Pal, key: &str, ms: Option, time_w: f32, stopping: bool, stop: El) -> El { +fn build_end_layout(p: &Pal, key: &str, ms: Option, held: bool, stop: El) -> El { + let w = end_w(ms); let time = row().key("time").w_full().h_full().justify_end().center_y().children(ms.map(|ms| run_time(format!("time-{key}"), ms, ELAPSED, p.muted))); if session_view::style::hover_none() { - return row().key("end").h(44.0).gap(2.0).ml(8.0).center_y().child(time.w(time_w)).child(stop.size(44.0, 44.0)); + return row().key("end").h(44.0).gap(2.0).center_y().child(time.w(w)).child(stop.h(44.0)); } - let (time, stop) = if stopping { (time.opacity(0.0), stop) } else { (time.group_opacity(1.0, 0.0), stop.group_opacity(0.0, 1.0)) }; + let (time, stop) = if held { (time.opacity(0.0), stop) } else { (time.group_opacity(1.0, 0.0), stop.group_opacity(0.0, 1.0)) }; row() .key("end") - .w(time_w) + .w(w) .h(20.0) - .ml(8.0) .justify_end() .center_y() .child(time) @@ -190,7 +262,7 @@ fn build_back_button_shell(p: &Pal, back_lit: bool) -> El { .label_static(opencode_i18n::t!("session.activity.shell.back")) .size(28.0, 28.0) .center() - .radius(4.0) + .radius(ROW_RADIUS) .focus_default(p) .fill(if back_lit { p.hover } else { p.hover.alpha(0.0) }) .hover(p.hover) @@ -275,7 +347,7 @@ fn build_panel_frame(knobs: &Knobs, p: &Pal, header: El, output: El) -> El { .above("activity-chip", 8.0) .w(WIDE) .padding(PANEL_PAD) - .radius(10.0) + .radius(PANEL_RADIUS) .fill(p.layer1) .elevate(p.floating) .clip_soft(0.0)