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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions apps/desktop/src/shell/view/composer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -595,28 +595,34 @@ fn folds(
let need = |k: usize| {
let t = narrow::Toolbar::after(k);
// The add button and its 2 pt margin, the room, and Send.
let mut items = vec![30.0, 0.0, 28.0];
let (mut sum, mut count) = (30.0 + 0.0 + 28.0_f32, 3usize);
let mut push = |w: f32| {
sum += w;
count += 1;
};
if s.kernel.slots.get(&crate::add_menu::ADD_MENU).shell() {
// Exit and its keys (from 640 wide), 6 in and 6 apart, and 10 before Send.
let keys = if s.layout.narrow.sm() { 6.0 + narrow::text_w(t!("common.key.esc"), UI_SMALL) + 8.0 } else { 0.0 };
items.push(narrow::text_w(t!("ui.promptInput.exitShell"), UI_MED) + keys + 12.0 + 10.0);
push(narrow::text_w(t!("ui.promptInput.exitShell"), UI_MED) + keys + 12.0 + 10.0);
}
if mic && (t.mic || dictating) {
items.push(28.0);
push(28.0);
}
match (agent, t.agent) {
(Some(name), Agent::Name) => items.push(label(name, t.chevrons)),
(Some(_), Agent::Icon) => items.push(28.0),
(Some(name), Agent::Name) => push(label(name, t.chevrons)),
(Some(_), Agent::Icon) => push(28.0),
_ => {}
}
// The slash takes its 6 pt either side, a little more than the spaces measured.
let badge_w = badge.map_or(0.0, |b| 4.0 + 8.0 + narrow::text_w(b, session_view::pickers::view::TRIGGER_BADGE));
let whole = label(model.0, t.chevrons) + if model.1 { 4.0 } else { 0.0 } + badge_w;
items.push(if t.model_whole { whole } else { whole.min(narrow::MODEL_FLOOR) });
push(if t.model_whole { whole } else { whole.min(narrow::MODEL_FLOOR) });
if t.effort {
items.extend(after.iter().flatten().map(|name| label(name, t.chevrons)));
for name in after.iter().flatten() {
push(label(name, t.chevrons));
}
}
items.iter().sum::<f32>() + 2.0 * (items.len() - 1) as f32
sum + 2.0 * (count - 1) as f32
};
narrow::Toolbar::after(narrow::steps(room, narrow::Toolbar::FOLDS, need))
}
Expand Down
29 changes: 21 additions & 8 deletions apps/desktop/src/shell/view/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ pub(super) fn session_body(s: &App, p: &Pal, id: &str, page: El, with_header: bo
s.kernel.slots.untracked(&crate::subagents::SHELLS).follow.version(),
has_pills,
session_view::TimelineHost::more_above(s, shown),
s.opening.as_ref().filter(|o| o.id == shown).and_then(|o| o.error()).map(str::to_owned),
crate::plugin_host::services::timeline::highlighted_row(s, shown).map(str::to_owned),
s.opening.as_ref().filter(|o| o.id == shown).and_then(|o| o.error()),
crate::plugin_host::services::timeline::highlighted_row(s, shown),
),
);
let lane = session_view::jump::lane(has_pills);
Expand Down Expand Up @@ -143,16 +143,29 @@ fn pills(s: &App, p: &Pal, id: &str) -> Vec<El> {
// The timeline's edge rises over their row first, so a pill fades in only once nothing is
// under it, and goes at once so the edge can come back down (t1129).
let enter = |pill: El| pill.transition(rune::Transition::asymmetric(rune::Transition::opacity(), rune::Transition::none())).enter_delay(PILL_WAIT);
let own: Vec<El> = capsule.into_iter().chain(crate::todos::pill(s, p, id).map(|t| t.ml(gap))).collect();
let todo = crate::todos::pill(s, p, id).map(|t| t.ml(gap));
let plugin_pills = crate::plugin_host::pill_views(s, p, id);
let own_count = usize::from(capsule.is_some()) + usize::from(todo.is_some());
let total = own_count + plugin_pills.len();
if total == 0 {
return Vec::new();
}
let mut out = Vec::with_capacity(total);
if let Some(c) = capsule {
out.push(enter(c));
}
if let Some(t) = todo {
out.push(enter(t));
}
// Plugins' pills follow the app's (`SessionPluginPills`), 8 apart.
let gap = if own.is_empty() { 0.0 } else { 8.0 };
let gap = if own_count == 0 { 0.0 } else { 8.0 };
// Keep each plugin pill's `region_with` placeholder unmodified for Rune's `same_root_el`
// flattened-node reuse by applying margin and enter transition to a thin keyed wrapper.
let plugins = crate::plugin_host::pill_views(s, p, id).into_iter().enumerate().map(|(k, pill)| {
for (k, pill) in plugin_pills.into_iter().enumerate() {
let wrap_key = pill.key_ref().map_or_else(|| format!("plugin-pill-wrap-{k}"), |name| format!("{name}-wrap"));
el().key(wrap_key).shrink().min_w(0.0).ml(if k == 0 { gap } else { 8.0 }).child(pill)
});
own.into_iter().chain(plugins).map(enter).collect()
out.push(enter(el().key(wrap_key).shrink().min_w(0.0).ml(if k == 0 { gap } else { 8.0 }).child(pill)));
}
out
}

/// How long the timeline's edge takes to clear the pills' row (the page's spring).
Expand Down
67 changes: 59 additions & 8 deletions crates/session-view/src/compaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use crate::style::{BUBBLE, UI, markdown_tinted, readable};
const CYCLE: f32 = 3.2;

/// One row of a compaction in the timeline.
#[derive(Clone, Copy, Debug, PartialEq)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum Piece {
Quiet,
Start,
Expand Down Expand Up @@ -82,6 +82,57 @@ pub fn view<S: TimelineHost>(s: &S, p: &Pal, c: &Compaction, piece: Piece, run:
}
}

/// Allocation-free memo stamp for a settled (`status != Running`) compaction row.
/// Returns `None` when an expanded/shutting summary contains async Markdown (math or Mermaid)
/// so pending rasterization and lightbox transitions rebuild cleanly, matching `Group`/`Thought`.
pub(crate) fn memo_stamp<S: TimelineHost>(s: &S, c: &Compaction, piece: Piece, run: Run) -> Option<u64> {
use std::hash::{DefaultHasher, Hash, Hasher};
let k = s.knobs();
let state = (piece == Piece::Quiet)
.then(|| s.expanded().get_parts("cmp-", &c.id, "-quiet"))
.flatten();
let open = state == Some(crate::disclosure::Disclosure::Open);
let shutting = matches!(state, Some(crate::disclosure::Disclosure::Shutting { .. }));
let hidden_diagrams = if open || shutting {
let body = summary(c);
if rune_kit::math::may_have_math(body)
&& let Some(m) = s.math_client()
{
m.hold();
}
if crate::timeline::group_hash::has_async_markdown(body) {
return None;
}
Some(s.diagrams().hidden_in(body))
} else {
None
};
let tokens = c.tokens.as_ref().map(|t| (t.input, t.output, t.reasoning, t.cache_read, t.cache_write));
let mut h = DefaultHasher::new();
(
&c.id,
std::mem::discriminant(&c.status),
c.manual,
&c.summary,
c.native,
&c.error,
c.created,
tokens,
piece,
run,
([open, shutting, s.reduced_motion()], hidden_diagrams),
[
crate::style::sticky_top().to_bits(),
crate::disclosure::fold(k).duration.to_bits(),
k.get(&crate::disclosure::FOLD_FEATHER).to_bits(),
k.get(&DIVIDER_GAP).to_bits(),
if open || shutting { crate::genui::width(s).to_bits() } else { 0 },
],
)
.hash(&mut h);
Some(h.finish())
}

/// A compaction the server admitted but hasn't started.
pub fn queued<S: TimelineHost>(s: &S, p: &Pal, run: Run) -> El {
divider(s, p, opencode_i18n::t!("ui.messagePart.compaction.queued"), run)
Expand All @@ -96,7 +147,7 @@ pub const GROUP: Group = Group::new("Dividers", "dividers", &[DIVIDER_GAP]).unde
pub const WORDS: f32 = 16.0;

/// What sits beside a divider, on one side.
#[derive(Clone, Copy, Debug, Default, PartialEq)]
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub enum Beside {
/// Rows with no room of their own toward it, as a reply's text: the turn's usual 16.
#[default]
Expand All @@ -108,7 +159,7 @@ pub enum Beside {
}

/// What sits above and below a divider, and who holds the room over its words.
#[derive(Clone, Copy, Debug, Default, PartialEq)]
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub struct Run {
pub above: Beside,
pub below: Beside,
Expand All @@ -119,7 +170,7 @@ pub struct Run {
/// never the lower row (official `timeline-next/spacing.ts` `timelineGaps`, where a divider is a
/// row like any other; `packages/app/AGENTS.md` "Rows that load above the reader"): a divider
/// that took it on top would change when the row before it loads, and move what is on screen.
#[derive(Clone, Copy, Debug, Default, PartialEq)]
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub enum Over {
/// The divider: it starts the session, and nothing loads above it.
#[default]
Expand Down Expand Up @@ -233,9 +284,9 @@ fn error_card(p: &Pal, message: &str) -> El {

fn quiet_view<S: TimelineHost>(s: &S, p: &Pal, c: &Compaction, run: Run) -> El {
let running = c.status == CompactionStatus::Running;
// Only the active divider needs a phase. Map the work's start to the animation clock;
// no per-poll history of which dividers have mounted is needed.
let start = if running { s.clock() - s.now_ms().saturating_sub(c.created).max(0) as f64 / 1000.0 } else { 0.0 };
// Only the active divider needs a phase. Read the untracked poll clock and wall clock so
// an active compaction divider never subscribes `timeline-fade` to the 165 Hz frame clock.
let start = if running { s.working_state().poll_clock() - s.now_ms_untracked().saturating_sub(c.created).max(0) as f64 / 1000.0 } else { 0.0 };
let body = summary(c);
let expandable = !running && !body.is_empty();
let key = Piece::Quiet.key(&c.id);
Expand Down Expand Up @@ -332,7 +383,7 @@ fn light<S: TimelineHost>(s: &S, p: &Pal, start: f64, end: bool) -> El {
let peak = Color { a: p.muted.a * 0.55, ..p.muted };
let clear = Color { a: 0.0, ..p.muted };
let (from, to) = if end { (-SLIDE.0, -SLIDE.1) } else { SLIDE };
let slide = LoopSpec { delay: loop_delay(s.clock(), start), ..LoopSpec::slide(f64::from(CYCLE), [from, 0.0], [to, 0.0]).easing(travel()) };
let slide = LoopSpec { delay: loop_delay(s.working_state().poll_clock(), start), ..LoopSpec::slide(f64::from(CYCLE), [from, 0.0], [to, 0.0]).easing(travel()) };
let beam = el()
.key("beam")
.pin((!end).then_some(0.0), Some(0.0), end.then_some(0.0), None)
Expand Down
38 changes: 38 additions & 0 deletions crates/session-view/src/copied.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,44 @@ pub fn is_copied<S: TimelineHost>(s: &S, key: &str) -> bool {
s.copied_state().ticks.contains_key(key)
}

/// Allocation-free check for a copy key composed of `prefix` + `suffix`.
pub fn is_copied_prefixed<S: TimelineHost>(s: &S, prefix: &str, suffix: &str) -> bool {
let ticks = &s.copied_state().ticks;
if ticks.is_empty() {
return false;
}
let len = prefix.len() + suffix.len();
ticks.keys().any(|k| k.len() == len && k.starts_with(prefix) && k.ends_with(suffix))
}

/// Order-independent hash stamp of all active copy ticks without allocating or sorting a `Vec`.
pub fn stamp<S: TimelineHost>(s: &S) -> u64 {
let ticks = &s.copied_state().ticks;
if ticks.is_empty() {
return 0;
}
use std::hash::{DefaultHasher, Hash, Hasher};
ticks.keys().fold(0u64, |sum, key| {
let mut h = DefaultHasher::new();
key.hash(&mut h);
sum.wrapping_add(h.finish())
})
}

/// Order-independent hash stamp of active copy ticks whose key contains `needle`.
pub fn stamp_containing<S: TimelineHost>(s: &S, needle: &str) -> u64 {
let ticks = &s.copied_state().ticks;
if ticks.is_empty() {
return 0;
}
use std::hash::{DefaultHasher, Hash, Hasher};
ticks.keys().filter(|k| k.contains(needle)).fold(0u64, |sum, key| {
let mut h = DefaultHasher::new();
key.hash(&mut h);
sum.wrapping_add(h.finish())
})
}

/// The copy buttons showing their ticks now, in order (`poll` evicts expired entries before view).
pub fn current<S: TimelineHost>(s: &S) -> Vec<String> {
if s.copied_state().ticks.is_empty() {
Expand Down
72 changes: 67 additions & 5 deletions crates/session-view/src/disclosure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,22 +127,84 @@ impl Disclosures {
self.0.get(key).copied()
}

/// Allocation-free lookup for a key formed by concatenating `prefix` and `suffix`.
pub fn get_prefixed(&self, prefix: &str, suffix: &str) -> Option<Disclosure> {
self.get_parts(prefix, suffix, "")
}

/// Allocation-free lookup for a key formed by concatenating `a`, `b`, and `c`.
pub fn get_parts(&self, a: &str, b: &str, c: &str) -> Option<Disclosure> {
if self.0.is_empty() {
return None;
}
let total = a.len() + b.len() + c.len();
let mut buf = [0u8; 128];
if total <= buf.len() {
let ab = a.len() + b.len();
buf[..a.len()].copy_from_slice(a.as_bytes());
buf[a.len()..ab].copy_from_slice(b.as_bytes());
buf[ab..total].copy_from_slice(c.as_bytes());
if let Ok(key) = std::str::from_utf8(&buf[..total]) {
return self.0.get(key).copied();
}
}
let mut owned = String::with_capacity(total);
owned.push_str(a);
owned.push_str(b);
owned.push_str(c);
self.0.get(&owned).copied()
}

/// Whether the reader opened `key`.
pub fn contains(&self, key: &str) -> bool {
self.get(key) == Some(Disclosure::Open)
}

/// True when no disclosures have been toggled in any state.
#[inline]
pub fn none_touched(&self) -> bool {
self.0.is_empty()
}

/// What the reader toggled among the keys that start with `prefix`, as a number that moves
/// when one of them opens, shuts or follows its default again: for a memo whose row draws
/// such a disclosure (`rune::memo` builds again only when its version moves).
pub fn stamp(&self, prefix: &str) -> u64 {
self.stamp_parts(prefix, "", "")
}

/// Like [`Self::stamp`] for a prefix formed by concatenating `a`, `b`, and `c` without
/// allocating a temporary `String`.
pub fn stamp_parts(&self, a: &str, b: &str, c: &str) -> u64 {
if self.0.is_empty() {
return 0;
}
use std::hash::{DefaultHasher, Hash, Hasher};
// The map has no order, so the sum of each one's hash.
self.0.iter().filter(|(key, _)| key.starts_with(prefix)).fold(0, |sum, (key, state)| {
let mut h = DefaultHasher::new();
(key, std::mem::discriminant(state)).hash(&mut h);
sum.wrapping_add(h.finish())
})
self.0
.iter()
.filter(|(key, _)| {
key.strip_prefix(a)
.and_then(|r| r.strip_prefix(b))
.is_some_and(|r| r.starts_with(c))
})
.fold(0, |sum, (key, state)| {
let mut h = DefaultHasher::new();
(key, std::mem::discriminant(state)).hash(&mut h);
sum.wrapping_add(h.finish())
})
}

/// True when any key starting with `a + b + c` is currently springing shut.
pub fn any_shutting_parts(&self, a: &str, b: &str, c: &str) -> bool {
!self.0.is_empty()
&& self.0.iter().any(|(key, state)| {
matches!(state, Disclosure::Shutting { .. })
&& key
.strip_prefix(a)
.and_then(|r| r.strip_prefix(b))
.is_some_and(|r| r.starts_with(c))
})
}

/// Opens `key`; true when it wasn't open.
Expand Down
5 changes: 4 additions & 1 deletion crates/session-view/src/fold.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,12 @@ pub fn place<'a, S: TimelineHost>(s: &'a S, session: &'a str) -> impl Fn(&str) -
}
}

/// Prefix of [`key`], for allocation-free disclosure lookups.
pub const KEY_PREFIX: &str = "user-expanded:";

/// The `expanded` key of an opened prompt, Desktop's disclosure key.
pub fn key(id: &str) -> String {
format!("user-expanded:{id}")
format!("{KEY_PREFIX}{id}")
}

/// The width a prompt's words wrap at in a timeline viewport `viewport` points wide: the row is
Expand Down
Loading
Loading