Initial public release

Luxe 0.1.0: a coding agent harness for the terminal. See README.md to get started and CHANGELOG.md for releases.
This commit is contained in:
Evan Whittaker
2026-10-17 12:08:30 -05:00
commit 09a7de2520
1730 changed files with 412952 additions and 0 deletions

View File

@@ -0,0 +1,402 @@
//! Cards — notices, references and the tool card in each state.
use super::*;
/// A command a notice names is drawn as inline code, backticks dropped; the rest stays muted.
#[test]
fn a_notice_draws_its_commands_as_code() {
let styles = &theme();
let lines = system_lines("", "Use `luxe --no-tool <name>` for one", styles.muted, styles);
let spans = &lines[0].spans;
let code: Vec<&str> = spans
.iter()
.filter(|span| span.style == styles.md_code)
.map(|span| span.content.as_ref())
.collect();
assert_eq!(code, ["luxe --no-tool <name>"]);
assert!(spans.iter().all(|span| !span.content.contains('`')), "{spans:?}");
assert_eq!(spans[0].style, styles.muted);
}
/// A reference in a sent message stands apart from the accent prose around it: body ink, bold,
/// and no tint, which on the card's own band was too faint to read.
#[test]
fn a_reference_in_a_message_stands_apart() {
let styles = &theme();
let text = "fix acme/todo#12 with test-first";
let lines = chipped_lines(text, &[4..16, 22..32], styles.accent, styles);
assert_eq!(lines.len(), 1);
let spans = &lines[0].spans;
let texts: Vec<&str> = spans.iter().map(|span| span.content.as_ref()).collect();
assert_eq!(texts, ["fix ", "acme/todo#12", " with ", "test-first"]);
assert_eq!(spans[1].style.fg, styles.text.fg, "the body ink");
assert_ne!(spans[1].style.fg, spans[0].style.fg, "not the sentence's accent");
assert!(spans[1].style.add_modifier.contains(Modifier::BOLD), "in bold");
assert_eq!(spans[1].style.bg, styles.accent.bg, "on the card, not a tint");
assert!(!spans[0].style.add_modifier.contains(Modifier::BOLD), "the prose is not a chip");
// A range off this text's character boundaries is not trusted
let inside_the_e = std::ops::Range { start: 1, end: 2 };
let odd = chipped_lines("é", std::slice::from_ref(&inside_the_e), styles.accent, styles);
assert_eq!(odd[0].spans.len(), 1);
}
/// A transcript with no images in it, which is every block these tests build.
pub(super) static NO_IMAGES: OnceLock<crate::graphics::ImageStore> = OnceLock::new();
pub(super) static NO_TOOL_IMAGES: OnceLock<
std::collections::HashMap<(String, String), Vec<ImageKey>>,
> = OnceLock::new();
pub(super) fn theme() -> ThemeStyles {
let registry = luxe_core::theme::ThemeRegistry::new();
let resolved = registry.resolve("nord").expect("a bundled theme");
ThemeStyles::from_resolved(&resolved, "nord")
}
pub(super) fn tool_item(name: &str, state: luxe_core::ToolActivityState) -> ConvoBlock {
let mut activity =
luxe_core::ToolActivity::running("session-a", "call-a", name, "cargo test", 1);
activity.state = state;
activity.elapsed_ms = Some(842);
ConvoBlock::Tool(Box::new(crate::app::ToolItem {
activity,
expanded: false,
details_toggled: false,
waited_on_user_ms: 0,
}))
}
pub(super) fn context(styles: &ThemeStyles, spinner_frame: usize) -> BlockContext<'_> {
BlockContext {
styles,
spinner_frame,
waiting_on_user: false,
never_sent: false,
expanded: false,
images: NO_IMAGES.get_or_init(crate::graphics::ImageStore::default),
tool_images: NO_TOOL_IMAGES.get_or_init(std::collections::HashMap::new),
image_bounds: (80, 24),
card_width: 80,
prose_width: 80,
diff_layout: luxe_core::config::DiffLayout::Auto,
tool_output_expanded: false,
expand_chord: Some("ctrl+o".into()),
running_ms: None,
}
}
pub(super) fn header(block: &ConvoBlock, styles: &ThemeStyles) -> Line<'static> {
lines(block, &context(styles, 0)).remove(0).line
}
/// The card's three voices: the tool in bold state color, the subject in body text, the clock
/// muted. A reader's eye has to land on the command, not on `842ms`.
#[test]
fn a_tool_card_reads_in_three_voices() {
let styles = theme();
let line = header(&tool_item("bash", luxe_core::ToolActivityState::Succeeded), &styles);
let name = &line.spans[0];
assert_eq!(name.content.as_ref(), format!("{} bash", tool_glyph("bash")));
assert!(name.style.add_modifier.contains(Modifier::BOLD), "the tool name is bold");
assert_eq!(name.style.fg, styles.success.fg, "a landed call takes its outcome color");
let subject = &line.spans[1];
assert_eq!(subject.content.as_ref(), " cargo test");
assert_eq!(subject.style.fg, styles.text.fg, "the subject is plain body text");
assert!(!subject.style.add_modifier.contains(Modifier::BOLD));
let duration = &line.spans[2];
assert_eq!(duration.content.as_ref(), " 842ms", "held off by two spaces, not one");
assert_eq!(duration.style.fg, styles.muted.fg, "the clock is de-emphasized");
}
/// A running call keeps the spinner *and* its name in the warning color, so the eye still finds
/// the in-flight card while the subject and clock read as they do everywhere else.
#[test]
fn a_running_card_spins_in_the_warning_color() {
let styles = theme();
let block = tool_item("bash", luxe_core::ToolActivityState::Running);
let first = header(&block, &styles);
assert_eq!(first.spans[0].style.fg, styles.warning.fg);
assert!(first.spans[0].style.add_modifier.contains(Modifier::BOLD));
assert_eq!(first.spans[1].style.fg, styles.text.fg);
assert_ne!(
first.spans[0].content,
lines(&block, &context(&styles, 3)).remove(0).line.spans[0].content,
"the leading glyph animates while the call is in flight"
);
}
/// A call the model is still writing has a card but nothing yet to say about it. The header is
/// its mark and the tool, and no more — a subject slot filled with the tool's own name would
/// read `write write`.
#[test]
fn a_card_for_an_unnamed_call_is_its_mark_and_the_tool() {
let styles = theme();
let card = |label: &str| {
ConvoBlock::Tool(Box::new(crate::app::ToolItem {
activity: luxe_core::ToolActivity::composing("session-a", "call-a", "write", label, 1),
expanded: false,
details_toggled: false,
waited_on_user_ms: 0,
}))
};
let line = header(&card(""), &styles);
assert_eq!(line.spans.len(), 1, "{line}");
assert_eq!(line.spans[0].content.as_ref(), format!("{} write", crate::statusline::spinner(0)));
// Then the path arrives and takes the subject slot, on the same row.
assert_eq!(header(&card("notes.rs"), &styles).spans[1].content.as_ref(), " notes.rs");
}
/// Exactly one card looks busy, and it is whichever one is actually moving.
///
/// The model writing a call and the tool running it are both work, and the card says so the
/// same way for each. Only a call written in full and waiting its turn is idle. Both halves of
/// this were reported wrong: every un-started call drawn as running put two spinning `bash`
/// cards side by side, and every un-started call drawn as waiting put a paused mark on a card
/// that was visibly filling in.
#[test]
fn a_card_looks_busy_exactly_when_it_is() {
let styles = theme();
let card = |state| {
ConvoBlock::Tool(Box::new(crate::app::ToolItem {
activity: luxe_core::ToolActivity {
state,
..luxe_core::ToolActivity::running("s", "c", "bash", "vainfo", 1)
},
expanded: false,
details_toggled: false,
waited_on_user_ms: 0,
}))
};
let spinner = format!("{} bash", crate::statusline::spinner(0));
for busy in [luxe_core::ToolActivityState::Running, luxe_core::ToolActivityState::Composing] {
let line = header(&card(busy), &styles);
assert_eq!(line.spans[0].content.as_ref(), spinner, "{busy:?} is work in progress");
assert_eq!(line.spans[0].style.fg, styles.warning.fg, "{busy:?}");
// And it animates, or the spinner is a picture of a stalled thing.
let later = lines(&card(busy), &context(&styles, 3)).remove(0).line;
assert_ne!(line.spans[0].content, later.spans[0].content, "{busy:?}");
}
let queued = card(luxe_core::ToolActivityState::Queued);
let line = header(&queued, &styles);
assert_eq!(
line.spans[0].content.as_ref(),
format!("{} bash", Icon::Queued.glyph()),
"a call waiting its turn wears the mark a queued submission does",
);
assert_eq!(line.spans[0].style.fg, styles.muted.fg, "and it recedes");
let later = lines(&queued, &context(&styles, 3)).remove(0).line;
assert_eq!(line.spans[0].content, later.spans[0].content, "nothing is happening to it");
}
/// A header subject is a preview for a card that shows nothing else. Where the body *is* the
/// thing the subject was cut out of, the preview is the same string rendered worse, directly
/// above the real one.
#[test]
fn a_header_does_not_restate_the_body_under_it() {
let styles = theme();
let card = |tool: &str, arguments: serde_json::Value| {
let mut activity = luxe_core::ToolActivity::running(
"s",
"c",
tool,
luxe_core::describe_call(tool, &arguments, "/project"),
1,
);
activity.state = luxe_core::ToolActivityState::Succeeded;
activity.elapsed_ms = Some(5);
activity.card_body = luxe_core::tool_card_body(tool, &arguments, "/project");
ConvoBlock::Tool(Box::new(crate::app::ToolItem {
activity,
expanded: false,
details_toggled: false,
waited_on_user_ms: 0,
}))
};
// A multi-line command is drawn in full, highlighted, right below the header.
let script = card("bash", serde_json::json!({"command": "make build\nmake test"}));
let row = header(&script, &styles);
assert_eq!(row.spans.len(), 2, "the tool and the clock, and nothing else: {row}");
assert_eq!(row.spans[1].content.as_ref(), " 5ms");
let rendered = lines(&script, &context(&styles, 0));
assert!(rendered[1].line.to_string().contains("make build"), "the body has the command");
// Same for the queries a search ran: the header named the first and the body lists them.
let searched = card("web_search", serde_json::json!({"queries": ["one", "two"]}));
assert_eq!(header(&searched, &styles).spans.len(), 2);
// A one-line command has no body, so the header is the only place it can be.
let one = card("bash", serde_json::json!({"command": "make build"}));
assert_eq!(header(&one, &styles).spans[1].content.as_ref(), " make build");
// And a `write`'s subject is the path while its body is the file: different things.
let written = card("write", serde_json::json!({"path": "a.rs", "content": "fn main() {}"}));
assert_eq!(header(&written, &styles).spans[1].content.as_ref(), " a.rs");
// So is a described command: the header says what it is for, the body what ran, folded
let described = card(
"bash",
serde_json::json!({"description": "Build it", "command": "make build\nmake test"}),
);
assert_eq!(header(&described, &styles).spans[1].content.as_ref(), " Build it");
let rendered = lines(&described, &context(&styles, 0));
assert!(rendered[1].line.to_string().contains("make build"), "the command's first line");
assert!(
!rendered.iter().any(|row| row.line.to_string().contains("make test")),
"the rest is folded"
);
}
/// A call in flight reports how long it has been going, which is when that answers something.
///
/// The projector only times a call once it has *finished*, so a card used to show no figure at
/// all for the whole time "is this taking long?" was the live question — and then show one the
/// moment nobody was asking.
/// A call waiting on the reader stands still: its own glyph, in the running color, rather than a
/// spinner hurrying someone who is reading a question. Busy again, it spins again.
#[test]
fn a_call_waiting_on_you_does_not_spin() {
let styles = theme();
let question = ConvoBlock::Tool(Box::new(crate::app::ToolItem {
activity: luxe_core::ToolActivity::running("s", "c", "question", "Which runtime?", 1),
expanded: false,
details_toggled: false,
waited_on_user_ms: 0,
}));
let icon = |waiting: bool, frame: usize| {
let ctx = BlockContext { waiting_on_user: waiting, ..context(&styles, frame) };
let header = lines(&question, &ctx).remove(0).line;
(header.spans[0].content.to_string(), header.spans[0].style)
};
let (still, style) = icon(true, 0);
assert!(still.contains(tool_glyph("question")), "{still:?}");
assert_eq!(icon(true, 7), (still.clone(), style), "the same on every frame");
let (spinning, spinning_style) = icon(false, 0);
assert_ne!(spinning, still, "a call nobody waits on spins");
assert_ne!(icon(false, 7).0, spinning, "and moves");
assert_eq!(style, spinning_style, "in the running color either way");
}
#[test]
fn a_call_in_flight_reports_how_long_it_has_been_going() {
let styles = theme();
let card = |state| {
let mut activity = luxe_core::ToolActivity::running("s", "c", "bash", "make test", 1);
activity.state = state;
activity.elapsed_ms =
matches!(state, luxe_core::ToolActivityState::Succeeded).then_some(2_500);
ConvoBlock::Tool(Box::new(crate::app::ToolItem {
activity,
expanded: false,
details_toggled: false,
waited_on_user_ms: 0,
}))
};
let with_running = |block: &ConvoBlock, running_ms| {
let ctx = BlockContext { running_ms, ..context(&styles, 0) };
lines(block, &ctx).remove(0).line
};
let running = card(luxe_core::ToolActivityState::Running);
let live = with_running(&running, Some(12_000));
assert_eq!(live.spans[2].content.as_ref(), " 12s", "{live}");
assert!(!live.to_string().contains('.'), "a live figure with a tenths digit: {live}");
// Before the front-end has a start to measure from, it says nothing rather than `0ms`.
let cold = with_running(&running, None);
assert_eq!(cold.spans.len(), 2, "no clock yet: {cold}");
// And for its first second it says nothing either: the only reading available down there
// is milliseconds, which on a card redrawn every frame is three digits of noise beside a
// spinner that is already reporting the same fact.
let just_started = with_running(&running, Some(740));
assert_eq!(just_started.spans.len(), 2, "under a second, no figure: {just_started}");
assert_eq!(
with_running(&running, Some(1_000)).spans[2].content.as_ref(),
" 1s",
"and then it starts counting"
);
// Once it lands, the figure is the one the projector measured — not whatever the last
// frame happened to compute.
let done = card(luxe_core::ToolActivityState::Succeeded);
assert_eq!(with_running(&done, Some(99_000)).spans[2].content.as_ref(), " 2s");
}
/// A card reports the time the *tool* spent, not the time the reader spent deciding.
#[test]
fn a_card_does_not_report_the_readers_own_deliberation() {
let styles = theme();
let card = |tool: &str, waited_on_user_ms| {
let mut activity = luxe_core::ToolActivity::running("s", "c", tool, "subject", 1);
activity.state = luxe_core::ToolActivityState::Succeeded;
activity.elapsed_ms = Some(31_000);
ConvoBlock::Tool(Box::new(crate::app::ToolItem {
activity,
expanded: false,
details_toggled: false,
waited_on_user_ms,
}))
};
// Thirty of those thirty-one seconds were a permission prompt on screen.
let gated = header(&card("bash", 30_000), &styles);
assert_eq!(gated.spans[2].content.as_ref(), " 1s");
// Nothing waited on, nothing to subtract.
let plain = header(&card("bash", 0), &styles);
assert_eq!(plain.spans[2].content.as_ref(), " 31s");
// A `question` is that case taken to its limit: the whole call is a person thinking, so
// there is no tool time to report at all.
let asked = header(&card("question", 0), &styles);
assert_eq!(asked.spans.len(), 2, "the tool and the prompt, no clock: {asked}");
assert_eq!(asked.spans[1].content.as_ref(), " subject");
}
/// A long subject, a question or a command, wraps under itself rather than back under the
/// tool's name, so the card's header still reads as one block.
#[test]
fn a_card_header_wraps_under_its_subject() {
let styles = theme();
for tool in ["question", "bash"] {
let mut activity = luxe_core::ToolActivity::running("s", "c", tool, "a long subject", 1);
activity.state = luxe_core::ToolActivityState::Succeeded;
let block = ConvoBlock::Tool(Box::new(crate::app::ToolItem {
activity,
expanded: false,
details_toggled: false,
waited_on_user_ms: 0,
}));
let rendered = lines(&block, &context(&styles, 0));
assert_eq!(rendered[0].hang, Some(header_subject_column(tool)), "{tool}");
assert!(rendered[1..].iter().all(|line| line.hang.is_none()), "only the header hangs");
}
}
/// The band's wash says how it went, so the glyph is free to say *what ran* — except for the
/// two states that get no wash at all.
#[test]
fn a_landed_card_shows_its_tool_not_a_tick() {
let styles = theme();
for state in [luxe_core::ToolActivityState::Succeeded, luxe_core::ToolActivityState::Failed] {
for tool in ["read", "bash", "grep"] {
let line = header(&tool_item(tool, state), &styles);
assert_eq!(
line.spans[0].content.as_ref(),
format!("{} {tool}", tool_glyph(tool)),
"{tool} in {state:?} should wear its own icon"
);
}
}
// Cancelled and interrupted calls keep a state glyph: nothing else on the card says they
// never finished.
let cancelled = header(&tool_item("read", luxe_core::ToolActivityState::Cancelled), &styles);
assert!(cancelled.spans[0].content.starts_with('⊘'));
}

View File

@@ -0,0 +1,237 @@
//! Folds — a run of calls as one line, and what it counts and meters.
use super::*;
pub(super) fn group_header_text(items: &[ConversationItem], arriving: bool) -> String {
tool_group_lines(items, arriving, 0, 120, &theme())[0].line.to_string()
}
pub(super) fn group_text(items: &[ConversationItem], width: u16) -> Vec<String> {
tool_group_lines(items, false, 0, width, &theme())
.into_iter()
.map(|row| row.line.to_string())
.collect()
}
/// A settled call of `tool`, labeled `label`, as a transcript item.
pub(super) fn labeled_call(tool: &str, label: &str, call_id: &str) -> ConversationItem {
let mut activity = luxe_core::ToolActivity::running("session-a", call_id, tool, label, 1);
activity.state = luxe_core::ToolActivityState::Succeeded;
activity.summary = Some("Completed".into());
ConversationItem::new(
crate::app::ConversationItemId::Tool {
session_id: "session-a".into(),
call_id: call_id.into(),
},
ConvoBlock::Tool(Box::new(crate::app::ToolItem {
activity,
expanded: false,
details_toggled: false,
waited_on_user_ms: 0,
})),
)
}
/// A folded run says what it stands for, not only how much: the calls by name under the count,
/// all of them when there are five or fewer.
#[test]
fn a_folded_run_lists_what_it_folded() {
let run = [
labeled_call("read", "note.md", "a"),
labeled_call("read", "scripts/demo.py:12-40", "b"),
labeled_call("read", "tests/example.py", "c"),
];
let rows = group_text(&run, 120);
assert_eq!(
rows[1..],
[
format!("{BODY_INDENT}note.md"),
format!("{BODY_INDENT}scripts/demo.py:12-40"),
format!("{BODY_INDENT}tests/example.py"),
],
"{rows:#?}"
);
let rows = tool_group_lines(&run, false, 0, 120, &theme());
assert!(rows[0].handle, "the header opens the run");
assert!(rows[1..].iter().all(|row| !row.handle), "the list is text to select");
}
/// Past five, four by name and a count of the rest, which says how to see them.
#[test]
fn a_long_folded_run_counts_the_calls_it_does_not_list() {
let run: Vec<ConversationItem> = (0..9)
.map(|index| labeled_call("grep", &format!("\"pattern{index}\""), &index.to_string()))
.collect();
let rows = group_text(&run, 120);
assert_eq!(rows.len(), 1 + 4 + 1, "{rows:#?}");
assert!(rows[4].ends_with("\"pattern3\""));
assert_eq!(rows[5], format!("{BODY_INDENT}⋯ 5 more · 9 total · click to expand"));
let last = tool_group_lines(&run, false, 0, 120, &theme()).pop().expect("a footer");
assert!(last.handle, "the footer offers the expand, so a click on it has to open it");
let five = &run[..5];
assert_eq!(group_text(five, 120).len(), 6, "five fit whole: no '1 more'");
}
/// A mixed run names each call's tool, and a row too long for the card is cut, not wrapped.
#[test]
fn a_mixed_run_names_each_tool_and_cuts_long_rows() {
let run = [
labeled_call("read", "src/a/very/long/path/to/some/file/that/goes/on.rs", "a"),
labeled_call("grep", "\"needle\" in src", "b"),
labeled_call("glob", "**/*.rs", "c"),
];
let rows = group_text(&run, 30);
assert_eq!(rows[2], format!("{BODY_INDENT}grep \"needle\" in src"));
assert!(rows[1].ends_with('…'), "{rows:#?}");
assert!(rows.iter().all(|row| row.chars().count() <= 30), "{rows:#?}");
}
/// An MCP run names its server once, on the header, and each call by its tool.
#[test]
fn an_mcp_run_names_its_server_once() {
let run = [
labeled_call("mcp", "search tasks", "a"),
labeled_call("mcp", "asana/get_tasks", "b"),
labeled_call("mcp", "asana/update_task", "c"),
];
let rows = group_text(&run, 120);
assert_eq!(rows[0], format!("▸ {} 3 mcp calls · asana", tool_glyph("mcp")));
assert_eq!(
rows[1..],
[
format!("{BODY_INDENT}search tasks"),
format!("{BODY_INDENT}get_tasks"),
format!("{BODY_INDENT}update_task"),
]
);
}
/// A collapsed run of calls says which tool it collapsed; the wash already says they all
/// succeeded.
#[test]
fn a_collapsed_group_leads_with_its_tool_icon() {
let item = |name: &str| {
ConversationItem::new(
crate::app::ConversationItemId::Tool {
session_id: "session-a".into(),
call_id: name.into(),
},
tool_item(name, luxe_core::ToolActivityState::Succeeded),
)
};
// The run's time is its calls' time added up: what folding them cost, in one number.
let same = [item("read"), item("read"), item("read")];
let line = group_header_text(&same, false);
assert_eq!(line, format!("▸ {} 3 read calls 2s", tool_glyph("read")));
// A mixed run has no one tool to name, so it takes the generic icon — and a word for what
// the run actually was, since only lookups ever fold.
let mixed = [item("read"), item("grep"), item("read")];
let line = group_header_text(&mixed, false);
assert_eq!(line, format!("▸ {} 3 lookups 2s", GENERIC_TOOL.glyph()));
}
/// A run that is still moving is a progress line, and one that has stopped is not.
///
/// The meter is a claim that something is happening. Left on a settled run it would be a
/// picture of work that already finished, which is the one thing a progress bar must never be.
#[test]
fn a_folded_run_meters_itself_only_while_it_is_moving() {
let item = |call_id: &str, state: luxe_core::ToolActivityState, batch| {
let mut activity =
luxe_core::ToolActivity::running("session-a", call_id, "read", call_id, 1);
activity.state = state;
activity.batch = batch;
if state == luxe_core::ToolActivityState::Succeeded {
activity.elapsed_ms = Some(4);
activity.summary = Some("Completed".into());
}
ConversationItem::new(
crate::app::ConversationItemId::Tool {
session_id: "session-a".into(),
call_id: call_id.into(),
},
ConvoBlock::Tool(Box::new(crate::app::ToolItem {
activity,
expanded: false,
details_toggled: false,
waited_on_user_ms: 0,
})),
)
};
let batch = |index| Some(luxe_core::ToolBatch { index, total: 7 });
let live = [
item("a.rs", luxe_core::ToolActivityState::Succeeded, batch(1)),
item("b.rs", luxe_core::ToolActivityState::Succeeded, batch(2)),
item("c.rs", luxe_core::ToolActivityState::Running, batch(3)),
];
let line = group_header_text(&live, true);
assert!(line.contains("3/7"), "the run says how much of it is left: {line}");
assert!(line.contains("read"), "named for the call in flight: {line}");
assert!(line.contains("c.rs"), "and what it is doing right now: {line}");
assert!(line.contains('█') || line.contains('▁'), "with a meter: {line}");
let settled = [
item("a.rs", luxe_core::ToolActivityState::Succeeded, batch(1)),
item("b.rs", luxe_core::ToolActivityState::Succeeded, batch(2)),
item("c.rs", luxe_core::ToolActivityState::Succeeded, batch(3)),
];
let line = group_header_text(&settled, false);
assert_eq!(line, format!("▸ {} 3 read calls 12ms", tool_glyph("read")));
assert!(!line.contains('█') && !line.contains('▁'), "no meter once it stopped: {line}");
// Between two of its calls the run has nothing in flight and is nowhere near done. Reading
// that as settled summarized the run as "3 read calls" for a frame and washed the band
// green — once per call, all the way down a run of seven.
let between = &settled[..2];
let line = group_header_text(between, true);
assert!(line.contains("2/7"), "still a progress line: {line}");
assert!(run_is_working(between, true), "and still wearing the working band");
assert!(!run_is_working(&settled, false), "which it gives up when the run is done");
}
/// Both ends of the scale have to read as time, not as a raw counter.
#[test]
fn tool_durations_are_formatted_at_a_readable_scale() {
// Sub-millisecond calls really do happen (a small read, a rejected edit); `0ms` reads as
// "never ran", which is exactly the wrong conclusion.
assert_eq!(format_tool_duration(0), "<1ms");
assert_eq!(format_tool_duration(1), "1ms");
assert_eq!(format_tool_duration(842), "842ms");
assert_eq!(format_tool_duration(1_500), "1s", "a tenths digit moves ten times a second");
assert_eq!(format_tool_duration(47_608), "47s");
assert_eq!(format_tool_duration(134_000), "2m 14s");
assert_eq!(format_tool_duration(3_780_000), "1h 03m");
}
/// A card body sits inset under its header, and a `write` says what it did to the file.
#[test]
fn a_write_card_carries_its_content_under_its_header() {
let styles = theme();
let mut activity =
luxe_core::ToolActivity::running("session-a", "call-a", "write", "notes.rs", 1);
activity.state = luxe_core::ToolActivityState::Succeeded;
activity.summary = Some("Completed".into());
activity.output_preview = Some("Created 'notes.rs' (13 bytes)".into());
let arguments = serde_json::json!({"path": "notes.rs", "content": "fn main() {}"});
activity.card_body = luxe_core::tool_card_body("write", &arguments, "/project");
let block = ConvoBlock::Tool(Box::new(crate::app::ToolItem {
activity,
expanded: false,
details_toggled: false,
waited_on_user_ms: 0,
}));
let rendered = lines(&block, &context(&styles, 0));
let header = rendered[0].line.to_string();
assert!(header.contains("write notes.rs"), "{header}");
assert!(header.ends_with("· Created · 13 B"), "the header says what it did: {header}");
let body = rendered[1].line.to_string();
// Two cells of gutter whatever the file's depth, so a body filling in sits still.
assert_eq!(body, format!("{BODY_INDENT} 1 fn main() {{}}"));
assert_eq!(rendered.len(), 2, "no `arguments:`/`output:` rows once a body is shown");
}

View File

@@ -0,0 +1,191 @@
//! Reasoning — folded and expanded reasoning blocks and their peeks.
use super::*;
pub(super) fn reasoning(text: &str, expanded: bool) -> ConvoBlock {
ConvoBlock::Thinking { text: text.into(), expanded }
}
/// Reasoning is markdown, and the whole point of rendering it is that its syntax stops showing:
/// a `**title**` becomes a bold title, a backticked symbol becomes a code-colored one, and the
/// muted italic voice survives both.
#[test]
fn expanded_reasoning_renders_its_markdown_in_the_reasoning_voice() {
let styles = theme();
let block = reasoning("**Verifying configuration**\n\nStart with `lms ls`.", true);
let rendered = lines(&block, &context(&styles, 0));
let text = rendered.iter().map(|line| line.line.to_string()).collect::<Vec<_>>();
assert!(
text.iter().all(|line| !line.contains('*') && !line.contains('`')),
"markdown syntax must not survive rendering: {text:?}"
);
let title = rendered[0]
.line
.spans
.iter()
.find(|span| span.content.contains("Verifying configuration"))
.expect("the title renders");
assert!(title.style.add_modifier.contains(Modifier::BOLD), "a title is bold");
assert!(title.style.add_modifier.contains(Modifier::ITALIC), "and still italic");
assert_eq!(
title.style.fg, styles.thinking_text.fg,
"a title spends weight, not a color: the block stays reasoning"
);
let body = rendered.last().expect("a body line");
let prose = body
.line
.spans
.iter()
.find(|span| span.content.contains("Start with"))
.expect("the prose renders");
assert_eq!(prose.style.fg, styles.thinking_text.fg);
assert!(prose.style.add_modifier.contains(Modifier::ITALIC));
assert!(!prose.style.add_modifier.contains(Modifier::BOLD));
let code = body
.line
.spans
.iter()
.find(|span| span.content.contains("lms ls"))
.expect("the code span renders");
assert_eq!(code.style.fg, styles.md_code.fg, "a backticked symbol keeps the code hue");
assert!(code.style.add_modifier.contains(Modifier::ITALIC));
}
/// A model's own line breaks are structure, not accident: joining them into one paragraph the
/// way authored markdown would turns a list of separate thoughts into a wall of text.
#[test]
fn reasoning_keeps_the_line_breaks_the_model_wrote() {
let styles = theme();
let block = reasoning("first thought\nsecond thought", true);
// `Line`'s Display drops newlines, so the break has to be read off the spans themselves.
let text = lines(&block, &context(&styles, 0))
.iter()
.flat_map(|layout| layout.line.spans.iter())
.map(|span| span.content.to_string())
.collect::<String>();
assert_eq!(text, "first thought\nsecond thought");
// An answer, by contrast, reflows: a soft break there is authored prose, not structure.
let answer = ConvoBlock::Assistant("first thought\nsecond thought".into());
let reflowed = lines(&answer, &context(&styles, 0))
.iter()
.flat_map(|layout| layout.line.spans.iter())
.map(|span| span.content.to_string())
.collect::<String>();
assert_eq!(reflowed, "first thought second thought");
}
/// The remediation report is for the review: the transcript shows the prose around it, and a
/// message that was nothing but the report shows nothing.
#[test]
fn the_remediation_report_stays_out_of_the_transcript() {
let styles = theme();
let report = "```luxe-remediation\n{\"findings\":[]}\n```";
let text = |block: &ConvoBlock| {
lines(block, &context(&styles, 0))
.iter()
.map(|layout| layout.line.to_string())
.collect::<Vec<_>>()
.join("\n")
};
let answer = ConvoBlock::Assistant(format!("Fixed both.\n{report}"));
assert_eq!(text(&answer), "Fixed both.");
assert!(lines(&ConvoBlock::Assistant(report.into()), &context(&styles, 0)).is_empty());
}
/// The collapsed peek is built from the *rendered* line, so it shows the section title rather
/// than the asterisks that made it — and counts what it is standing in for.
#[test]
fn a_collapsed_reasoning_block_peeks_at_its_rendered_title() {
let styles = theme();
let block = reasoning("**Verifying configuration**\n\nStart with `lms ls`.", false);
let rendered = lines(&block, &context(&styles, 0));
assert_eq!(rendered.len(), 1, "a collapsed block is one line");
assert_eq!(rendered[0].line.to_string(), "Verifying configuration · +1 more line");
// A single short thought hides nothing, so it says nothing; empty reasoning still speaks.
let short = lines(&reasoning("just this", false), &context(&styles, 0));
assert_eq!(short[0].line.to_string(), "just this");
let empty = lines(&reasoning(" ", false), &context(&styles, 0));
assert_eq!(empty[0].line.to_string(), "(no content)");
// A hard break hides a line as surely as a paragraph does, and is counted the same way.
let broken = lines(&reasoning("one\ntwo\nthree", false), &context(&styles, 0));
assert_eq!(broken[0].line.to_string(), "one · +2 more lines");
// An over-long first line is cut to the prose measure, ellipsis included.
let long = "w".repeat(200);
let capped = lines(&reasoning(&long, false), &context(&styles, 0));
assert_eq!(capped[0].line.to_string(), format!("{}…", "w".repeat(79)));
// A line that fills the measure exactly is not cut: an ellipsis there would be spending a
// character to report an elision that never happened.
let exact = lines(&reasoning(&"w".repeat(80), false), &context(&styles, 0));
assert_eq!(exact[0].line.to_string(), "w".repeat(80));
let over = lines(&reasoning(&"w".repeat(81), false), &context(&styles, 0));
assert_eq!(over[0].line.to_string(), format!("{}…", "w".repeat(79)));
}
/// The peek's whole job is to be one line. A count that pushed it past the measure would wrap
/// into a second row, which is the fold failing at the only thing it promised.
#[test]
fn a_peek_and_its_count_fit_the_prose_measure() {
let styles = theme();
let sentence = "a thought long enough to run past any measure worth wrapping at, twice \
over, with no break in it anywhere";
for width in [16u16, 24, 30, 40, 72, 80, 120] {
let mut ctx = context(&styles, 0);
ctx.prose_width = width;
let peek = lines(&reasoning(&format!("{sentence}\nand another"), false), &ctx);
assert_eq!(peek.len(), 1, "a peek is one line at {width}");
let text = line_text(&peek[0].line);
assert!(
crate::selection::cell_width(&text) <= usize::from(width),
"{width}: peek is {} cells: {text:?}",
crate::selection::cell_width(&text)
);
// Wide enough to seat both, the count is there; too narrow, and the thought keeps the
// cells rather than sharing them with a number.
assert_eq!(
text.ends_with("· +1 more line"),
width >= 40,
"{width}: the wrong half won the canvas: {text:?}"
);
}
}
/// Reasoning shown in full is prose. A click on it must not fold it away, so no row of it is a
/// handle — the collapsed peek is the only thing here a click acts on.
#[test]
fn only_a_folded_reasoning_block_is_a_click_handle() {
let styles = theme();
let text = "**Tracing it**\n\nThe buffering happens in `feed`.\n\nSo I will read it.";
let shown = lines(&reasoning(text, true), &context(&styles, 0));
assert!(shown.len() > 1, "the fixture has rows to click");
assert!(
shown.iter().all(|line| !line.expands),
"nothing in fully shown reasoning opens or closes on a click"
);
let folded = lines(&reasoning(text, false), &context(&styles, 0));
assert!(folded[0].expands, "a peek is clickable, or there is no way back in with a mouse");
}
/// A fence inside reasoning stays in the reasoning voice: a syntect palette in a muted italic
/// block reads as an answer, which is exactly what it is not.
#[test]
fn a_reasoning_fence_is_not_syntax_highlighted() {
let styles = theme();
let block = reasoning("try:\n\n```rust\nlet total = 1 + 2;\n```", true);
let rendered = lines(&block, &context(&styles, 0));
let code = rendered
.iter()
.find(|line| line.line.to_string().contains("let total"))
.expect("the fence renders");
assert_eq!(code.line.spans.len(), 1, "one span, so nothing was tokenized");
assert_eq!(code.line.spans[0].style.fg, styles.md_code.fg);
assert!(code.line.spans[0].style.add_modifier.contains(Modifier::ITALIC));
}