Luxe 0.1.2: Windows fixes, working compaction, and compaction progress in the dock

This commit is contained in:
Evan Whittaker
2026-10-18 15:04:51 -05:00
parent 4ed87ee4e4
commit 33b87c78a8
69 changed files with 1470 additions and 424 deletions

View File

@@ -157,6 +157,7 @@ impl App {
self.refresh_configuration();
}
WizardOutcome::Finished(outcome) => self.finish_login(*outcome),
WizardOutcome::CopyCode(code) => self.record_copy(code),
}
}

View File

@@ -98,8 +98,7 @@ impl App {
mention_listings: Default::default(),
plan_written: None,
plan_handoff: None,
pending_build: None,
send_draft_on_load: false,
arrival: Default::default(),
permission_auto_approve: false,
file_provider,
file_listing: FileListing::default(),

View File

@@ -8,6 +8,7 @@ use super::{App, ConvoBlock};
use luxe_core::config::NotificationEvent;
use luxe_core::event::Event;
mod compaction;
mod github;
mod review;
mod transcript;
@@ -116,16 +117,11 @@ pub(super) fn reduce(app: &mut App, event: Event) {
Event::ContextComposition(report) => app.push_convo(ConvoBlock::Context(report)),
// Compaction rewrites what the model can see and spends a provider call doing it. Saying
// so is the difference between "the agent forgot" and "the conversation was summarized".
Event::CompactionStarted { .. } => compaction::started(app),
Event::CompactionDone { tokens_before, tokens_after } => {
use luxe_core::usage::format_tokens;
// The summary may not have kept a server's tool names, so the next reference sends them
app.mcp_listed.clear();
app.push_convo(ConvoBlock::System(format!(
"Compacted the conversation — {} → {} of context.",
format_tokens(tokens_before),
format_tokens(tokens_after)
)));
compaction::done(app, tokens_before, tokens_after);
}
Event::CompactionStopped => compaction::ended(app),
Event::WorkspaceUpdated(snapshot) => workspace_updated(app, *snapshot),
Event::ToolActivityUpdated(activity) => app.apply_tool_activity(*activity),
Event::PermissionRequested { id, tool, summary, always_patterns, .. } => {

View File

@@ -0,0 +1,40 @@
//! Compaction — the dock while a summary is written, and its reading once one stands.
//!
//! A summary is one provider call that can take a minute, on request or mid-turn. Without a state
//! of its own the dock showed nothing for `/compact` and the turn's label for an automatic one, and
//! the context reading kept the full figure until the next provider call reported a new one.
use super::super::{App, AppState, ConvoBlock};
/// The engine began writing a summary.
pub(super) fn started(app: &mut App) {
app.status.compacting_mid_turn = matches!(app.status.state, AppState::Streaming);
app.status.state = AppState::Compacting;
}
/// The summary stands: the dock reads what it left, and the transcript says what happened.
pub(super) fn done(app: &mut App, tokens_before: u64, tokens_after: u64) {
use luxe_core::usage::format_tokens;
ended(app);
if app.status.context_window > 0 {
let used = tokens_after as f32 / app.status.context_window as f32 * 100.0;
app.status.context_pct = used.min(100.0);
}
// The summary may not have kept a server's tool names, so the next reference sends them
app.mcp_listed.clear();
app.push_convo(ConvoBlock::System(format!(
"Compacted the conversation — {} → {} of context.",
format_tokens(tokens_before),
format_tokens(tokens_after)
)));
}
/// The compaction under way is over, with or without a summary; the turn it interrupted, if any,
/// carries on.
pub(super) fn ended(app: &mut App) {
if !matches!(app.status.state, AppState::Compacting) {
return;
}
app.status.state =
if app.status.compacting_mid_turn { AppState::Streaming } else { AppState::Idle };
}

View File

@@ -109,6 +109,8 @@ pub(super) fn failed(app: &mut App, msg: String) {
/// A prompt can't outlive its turn (the engine already resolved or dropped it), and a card still
/// spinning is settled as cancelled with `reason`.
fn end_turn(app: &mut App, reason: &str) {
// A load that failed sends no snapshot, and one that never comes must not mute the next real one
app.arrival.owes_snapshot = false;
app.interrupt_sent_at = None;
app.streaming = false;
app.streamed_thinking = false;
@@ -132,7 +134,12 @@ pub(super) fn tool_started(app: &mut App, name: String) {
}
pub(super) fn state_changed(app: &mut App, state: EngineState) {
app.status.state = if state.streaming { AppState::Streaming } else { AppState::Idle };
// The load's own snapshot was taken before the turn its `SessionLoaded` sent, so its idle is
// about a moment that has passed; believed, it hides the running turn until the first token
let stale = std::mem::take(&mut app.arrival.owes_snapshot) && app.turn_in_flight();
if !stale {
follow_reported_activity(app, state.streaming);
}
if !state.model.model.is_empty() {
app.status.model = state.model.display().to_string();
app.status.provider = state.model.provider.clone();
@@ -142,7 +149,16 @@ pub(super) fn state_changed(app: &mut App, state: EngineState) {
// Not marked in the transcript: the composer's title, the bar and the dock say which
// mode is on, and a line per switch would fill the scrollback with every toggle
app.status.mode = state.mode.clone();
if !state.streaming {
}
/// Takes the engine's word on whether a turn is running. A turn that is still running leaves a
/// compaction inside it on show: the summary is the turn's work until its own end event lands.
fn follow_reported_activity(app: &mut App, streaming: bool) {
if streaming && matches!(app.status.state, AppState::Compacting) {
return;
}
app.status.state = if streaming { AppState::Streaming } else { AppState::Idle };
if !streaming {
app.status.active_tool = None;
app.status.tool_started = None;
}

View File

@@ -99,7 +99,7 @@ fn ask_in_a_new_session(app: &mut App) {
return;
}
start_new_session(app);
app.send_draft_on_load = true;
app.arrival.send_draft = true;
}
/// Runs a command typed or found on the start screen.
@@ -167,10 +167,24 @@ impl App {
NextSession::Load(session_id) => (Action::LoadSession(session_id), "load a session"),
NextSession::ResumeLatest => (Action::ResumeLatest, "resume the latest session"),
};
self.send_action(action, doing)
let sent = self.send_action(action, doing);
self.arrival.owes_snapshot = sent;
sent
}
}
/// What waits on a session the TUI asked the engine for, settled as it arrives.
#[derive(Debug, Default)]
pub(crate) struct SessionArrival {
/// The plan's build prompt, built from scratch in the new session
pub(crate) build: Option<String>,
/// Whether the composer's draft goes out once it loads: a prompt typed on the start screen
pub(crate) send_draft: bool,
/// Whether its closing state snapshot is still to come. It trails `SessionLoaded`, which may
/// already have sent a turn, so its "idle" is stale
pub(crate) owes_snapshot: bool,
}
/// Where `/sessions` reads the project's sessions from, and how many reads it has asked for.
#[derive(Default)]
pub(crate) struct SessionCatalog {

View File

@@ -64,7 +64,8 @@ pub(super) fn answered(app: &mut App, answers: Option<Vec<String>>) {
// Sent once the new session has loaded, or it would land in the one being left; parked
// only once there is a new session coming to send it to
if app.send_action(Action::NewSession, "start a new session") {
app.pending_build = Some(build);
app.arrival.build = Some(build);
app.arrival.owes_snapshot = true;
}
}
RUN_AS_LOOP => {
@@ -87,11 +88,11 @@ pub(super) fn answered(app: &mut App, answers: Option<Vec<String>>) {
pub(super) fn session_loaded(app: &mut App) {
// a plan another session wrote is not this session's to offer
app.plan_written = None;
if let Some(build) = app.pending_build.take() {
if let Some(build) = app.arrival.build.take() {
submit(app, &build);
}
// A prompt typed on the start screen, which asked for this session to answer it
if std::mem::take(&mut app.send_draft_on_load) {
if std::mem::take(&mut app.arrival.send_draft) {
super::input::submit_prompt(app);
}
}
@@ -137,7 +138,7 @@ mod tests {
fn building_fresh_parks_nothing_when_no_session_is_coming() {
let mut app = seeded_app("nord", FixtureScenario::ChatIdle).unwrap();
answered(&mut app, Some(vec![BUILD_FRESH.to_string()]));
assert_eq!(app.pending_build, None);
assert_eq!(app.arrival.build, None);
}
/// Building fresh asks for a new session and sends the build prompt once that session loads.
@@ -147,11 +148,12 @@ mod tests {
answered(&mut app, Some(vec![BUILD_FRESH.to_string()]));
let asked: Vec<Action> = std::iter::from_fn(|| engine.try_recv().ok()).collect();
assert!(asked.iter().any(|action| matches!(action, Action::NewSession)), "{asked:?}");
assert!(app.pending_build.is_some());
assert!(app.arrival.build.is_some());
let loaded = Event::SessionLoaded { session_id: "fresh".into(), messages: Vec::new() };
app.update(crate::app::Msg::Engine(loaded));
assert!(app.pending_build.is_none(), "sent into the session that loaded");
assert!(app.arrival.build.is_none(), "sent into the session that loaded");
assert!(app.arrival.owes_snapshot, "and the load's closing snapshot is known to be stale");
let sent: Vec<Action> = std::iter::from_fn(|| engine.try_recv().ok()).collect();
let submitted = sent.iter().any(|action| {
matches!(action, Action::SubmitUserMessage { content, .. } if content.contains("Build the plan"))

View File

@@ -23,6 +23,9 @@ pub struct StatusModel {
pub active_tool: Option<String>,
/// Current state (streaming, idle, compacting).
pub state: AppState,
/// Whether the compaction under way started inside a turn, which carries on once it ends; one
/// asked for with `/compact` returns to idle
pub(crate) compacting_mid_turn: bool,
/// Animation frame counter, advanced on every tick while streaming/compacting.
///
/// Monotonic within a turn: every consumer takes it modulo its own frame count, and the
@@ -101,6 +104,7 @@ impl Default for StatusModel {
cwd: None,
active_tool: None,
state: AppState::Idle,
compacting_mid_turn: false,
spinner_frame: 0,
animating: false,
turn_started: None,

View File

@@ -262,6 +262,42 @@ fn a_prompt_typed_on_the_start_screen_is_sent_in_the_new_session() {
assert!(app.editor.current_input().is_empty(), "and it left the composer");
}
/// The turn a start-screen prompt starts shows as running from the moment it is sent.
///
/// The engine finishes a session load with an idle snapshot *after* `SessionLoaded`, which is what
/// sends the draft, so that snapshot lands on a turn it never saw. The break this catches: taking it
/// at its word hid the activity bar and the clock until the model's first token, a second or two
/// of a screen that looked like nothing had happened.
#[test]
fn the_snapshot_finishing_a_load_does_not_stop_the_turn_the_load_started() {
let (tx, _rx) = mpsc::channel(100);
let mut app = App::new(tx, KeyMap::defaults(), Default::default());
app.status.model = "qwen3.8-27b".into();
app.enter_dashboard(crate::dashboard::DashboardState::new(Vec::new()));
app.editor.insert_text("summarize the parser");
app.handle_dashboard_outcome(crate::dashboard::DashOutcome::Ask);
app.update(Msg::Engine(Event::SessionLoaded { session_id: "s1".into(), messages: vec![] }));
app.update(Msg::Engine(idle_snapshot("new session: s1")));
assert!(crate::statusline::activity_parts(&app).is_some(), "the activity bar stays up");
assert!(app.status.turn_started.is_some(), "and so does the clock");
// Only the one snapshot is stale: a later idle report is believed
app.update(Msg::Engine(idle_snapshot("cancelled")));
assert!(crate::statusline::activity_parts(&app).is_none(), "a later report still counts");
}
/// The engine's at-rest state report, as it closes a session load or a cancel.
fn idle_snapshot(status: &str) -> Event {
Event::StateChanged(luxe_core::event::EngineState {
model: luxe_core::event::ModelRef::new("lmstudio", "qwen3.8-27b"),
streaming: false,
status: status.into(),
mode: luxe_core::mode::BUILD.into(),
thinking: luxe_core::provider::ThinkingLevel::Off,
})
}
/// With no model chosen, asking opens the picker over the start screen and keeps the draft — the
/// same courtesy the composer extends in a session.
#[test]

View File

@@ -346,6 +346,56 @@ fn test_status_model_format_cost() {
assert_eq!(StatusModel::format_cost(Some(0.004)), "<$0.01");
}
fn idle_app() -> App {
let (tx, _rx) = mpsc::channel(8);
App::new(tx, luxe_core::keymap::KeyMap::defaults(), luxe_core::config::Config::default())
}
fn engine_reports_streaming(app: &mut App, streaming: bool) {
app.update(Msg::Engine(Event::StateChanged(luxe_core::event::EngineState {
streaming,
..Default::default()
})));
}
/// `/compact` shows as under way, and its end leaves the dock idle reading what the summary left.
///
/// The break this catches: nothing set the compacting state, so `/compact` showed no sign of life
/// for the minute a summary takes, and the context figure stayed full until the next turn.
#[tokio::test]
async fn compact_on_request_shows_while_it_runs_and_refreshes_the_context_reading() {
let mut app = idle_app();
app.update(Msg::Engine(Event::ContextUsage { used_tokens: 190_000, context_window: 200_000 }));
app.update(Msg::Engine(Event::CompactionStarted { tokens_before: 190_000 }));
assert!(matches!(app.status.state, AppState::Compacting), "{:?}", app.status.state);
app.update(Msg::Engine(Event::CompactionDone { tokens_before: 190_000, tokens_after: 20_000 }));
assert!(matches!(app.status.state, AppState::Idle), "{:?}", app.status.state);
assert!((app.status.context_pct - 10.0).abs() < 0.01, "got {}", app.status.context_pct);
}
/// A compaction inside a turn hands the dock back to the turn, whether or not it succeeded.
#[tokio::test]
async fn a_stopped_compaction_mid_turn_returns_to_the_turn() {
let mut app = idle_app();
engine_reports_streaming(&mut app, true);
app.update(Msg::Engine(Event::CompactionStarted { tokens_before: 190_000 }));
app.update(Msg::Engine(Event::CompactionStopped));
assert!(matches!(app.status.state, AppState::Streaming), "{:?}", app.status.state);
}
/// The engine's turn reports leave a compaction on show while the turn runs, and end it with the turn.
#[tokio::test]
async fn turn_reports_keep_a_compaction_on_show_until_the_turn_ends() {
let mut app = idle_app();
engine_reports_streaming(&mut app, true);
app.update(Msg::Engine(Event::CompactionStarted { tokens_before: 190_000 }));
engine_reports_streaming(&mut app, true);
assert!(matches!(app.status.state, AppState::Compacting), "{:?}", app.status.state);
engine_reports_streaming(&mut app, false);
assert!(matches!(app.status.state, AppState::Idle), "{:?}", app.status.state);
}
pub(super) fn type_into(app: &mut App, text: &str) {
for character in text.chars() {
app.update(Msg::Key(KeyEvent::new(KeyCode::Char(character), KeyModifiers::NONE)));