luxe update and /update, editable question answers, and a version bump owed once per release

- luxe update and /update update Luxe with the command for however it was installed (cargo or
  Homebrew), run one program at a time with the terminal attached, then check that the luxe on
  PATH is the new version. Luxe never downloads or replaces its own binary. The start screen says
  "Update available · /update".
- A question's typed answer edits at its caret: arrows, word jumps, Home, End and Delete work,
  and up and down move through a wrapped answer before leaving it.
- The version check owes a bump once per release: the version on main is the next release, and
  only a released one (a v-tag) has to move.
- Dependency updates arrive through the sync, so Dependabot and the weekly jobs no longer run here.
This commit is contained in:
Evan Whittaker
2026-10-17 14:14:27 -05:00
parent 0e84deb59c
commit bf86df5098
41 changed files with 794 additions and 355 deletions

View File

@@ -21,6 +21,7 @@ pub(super) fn run_slash(app: &mut App, cmd: &crate::commands::Command) -> bool {
}
}
id::SESSIONS => app.open_sessions(),
id::UPDATE => app.outbox.update = true,
id::MODEL => {
// Opens the searchable model picker (also reachable from the palette). Selecting a
// model sends `Action::SetModel`, switching the active model in-session.

View File

@@ -122,6 +122,8 @@ fn run_command(app: &mut App, command: crate::commands::Command) {
// The mode outlives the session, so it is chosen here rather than in a session made for it
id::MODE => super::commands::dispatch(app, command),
id::SESSIONS => app.open_sessions(),
// Leaves Luxe, so a session started for it would only be left empty
id::UPDATE => app.outbox.update = true,
_ if command.slash_name() == Some("/quit") => {
app.should_quit = true;
}

View File

@@ -25,6 +25,8 @@ pub struct Outbox {
pub issue: Option<u64>,
/// A session of yours to leave this one for, and what the reader carries into it
pub resume: Option<crate::main_loop::ResumeLaunch>,
/// Whether to leave and update Luxe
pub update: bool,
/// Text to hand to the reader's editor and bring back
pub text_edit: Option<TextEdit>,
/// A file or folder to open in the reader's editor
@@ -45,7 +47,8 @@ pub struct Outbox {
impl Outbox {
/// The exit the parked asks end the TUI with, taking them all; when several are parked the
/// last of an editor file, a worktree removal, an issue, a resume and a pull request fix wins.
/// last of an editor file, a worktree removal, an issue, a resume, a pull request fix and an
/// update wins.
pub fn exit(&mut self) -> Option<TuiExit> {
[
self.editor_file.take().map(TuiExit::OpenInEditor),
@@ -53,6 +56,7 @@ impl Outbox {
self.issue.take().map(TuiExit::TakeUpIssue),
self.resume.take().map(TuiExit::ResumeSession),
self.pull_request_fix.take().map(TuiExit::FixPullRequest),
std::mem::take(&mut self.update).then_some(TuiExit::Update),
]
.into_iter()
.flatten()
@@ -93,6 +97,10 @@ mod tests {
..Outbox::default()
};
assert_eq!(everything.exit(), Some(TuiExit::FixPullRequest(fix)));
// An update asked for after a fix is the one taken, and taken once
let mut update = Outbox { issue: Some(7), update: true, ..Outbox::default() };
assert_eq!(update.exit(), Some(TuiExit::Update));
assert_eq!(update.exit(), None);
let mut removal_then_issue = Outbox {
worktree_removal: Some(PathBuf::from("/work/.luxe/worktrees/x")),
issue: Some(7),

View File

@@ -381,6 +381,34 @@ fn the_mode_command_on_the_start_screen_stays_on_it() {
assert!(matches!(actions.as_slice(), [Action::SetMode(mode)] if mode == "plan"), "{actions:?}");
}
/// `/update` on the start screen leaves Luxe for the CLI's update, which needs the terminal, and
/// starts no session on the way out.
#[test]
fn the_update_command_on_the_start_screen_leaves_to_update() {
let (tx, mut rx) = mpsc::channel(100);
let mut app = App::new(tx, KeyMap::defaults(), Default::default());
app.enter_dashboard(crate::dashboard::DashboardState::new(Vec::new()));
let update = crate::commands::CommandRegistry::all().parse_slash("/update").expect("it");
app.handle_dashboard_outcome(crate::dashboard::DashOutcome::RunCommand(update));
let mut exit = crate::main_loop::TuiExit::Quit;
crate::main_loop::collect_exit_for_tests(&mut app, &mut exit);
assert_eq!(exit, crate::main_loop::TuiExit::Update);
assert!(app.should_quit);
assert!(rx.try_recv().is_err(), "no session started for it");
}
/// From a session, `/update` typed in the composer leaves the same way.
#[test]
fn the_update_command_in_a_session_leaves_to_update() {
let (tx, _rx) = mpsc::channel(100);
let mut app = App::new(tx, KeyMap::defaults(), Default::default());
app.editor.insert_text("/update");
app.update(Msg::Key(KeyEvent::new(KeyCode::Enter, KeyModifiers::NONE)));
let mut exit = crate::main_loop::TuiExit::Quit;
crate::main_loop::collect_exit_for_tests(&mut app, &mut exit);
assert_eq!(exit, crate::main_loop::TuiExit::Update);
}
/// Setup's answers reach the reader's file one key at a time, and skipping writes a file that
/// chooses nothing, so the first run asks once.
#[tokio::test]

View File

@@ -19,6 +19,13 @@ pub(super) fn built_in() -> Vec<Command> {
.with_slash("/quit")
.summary("Leaves Luxe; the session is saved as it goes, so nothing is lost.")
.keywords(&["exit", "close"]),
Command::slash(id::UPDATE, "Update Luxe", "/update")
.summary("Quits Luxe and updates it with the command for however you installed it.")
.detail(
"The same as `luxe update`: each command is shown before it runs, in this \
terminal. A copy your system's package manager owns is left to it.",
)
.keywords(&["upgrade", "version", "release", "new"]),
Command::action(UiAction::Reload)
.with_slash("/reload")
.summary("Re-reads your config and keybindings without restarting.")

View File

@@ -34,4 +34,5 @@ pub(crate) const STATUSLINE: &str = "cmd.statusline";
pub(crate) const THEME: &str = "cmd.theme";
pub(crate) const THINKING: &str = "cmd.thinking";
pub(crate) const TOOLS: &str = "cmd.tools";
pub(crate) const UPDATE: &str = "cmd.update";
pub(crate) const WORKTREE: &str = "cmd.worktree";

View File

@@ -8,10 +8,8 @@ mod motion;
mod parts;
use crossterm::event::{KeyCode, KeyEvent, KeyModifiers};
pub(crate) use layout::TextLayout;
pub use layout::VisualCursor;
#[cfg(test)]
use layout::VisualSegment;
pub(crate) use layout::{TextLayout, VisualSegment};
use motion::text_command;
pub use parts::AttachedImage;
use parts::{shift_offset, PromptPart, PromptPartKind};

View File

@@ -67,6 +67,8 @@ pub enum TuiExit {
///
/// Args: `(launch)` — the session, and the draft and mode the reader carries into it.
ResumeSession(ResumeLaunch),
/// Leave Luxe and run `luxe update`, which needs the terminal for the package manager.
Update,
}
/// A pull request to fix in a new session, and the comments written reading it, which become the

View File

@@ -176,6 +176,7 @@ fn prompt_budget(available: u16, rows: &[LaidOutRow]) -> usize {
usize::from(available).saturating_sub(chrome_and_rows(rows)).clamp(1, MAX_PROMPT_ROWS)
}
mod answer;
mod rows;
mod state;

View File

@@ -0,0 +1,84 @@
//! Answer — the typed answer while it is being written: its rows, its selection, and the caret.
//!
//! The answer is the composer's [`crate::editor::Editor`], so it is drawn from the editor's own
//! wrap: the rows the reader sees are the rows up and down move through.
use super::QuestionPromptState;
use crate::editor::{Editor, TextLayout, VisualSegment};
use ratatui::style::Style;
use ratatui::text::Span;
/// The glyph drawn where typing lands.
const CARET: &str = "▏";
/// The rows of the answer being typed that fit in `max_rows`, the caret drawn where typing lands,
/// and whether rows above were scrolled off.
///
/// Each row keeps a cell for the caret, and a scrolled answer one more for the mark that says so.
/// The width it wrapped at is recorded on the state, so up and down move through these rows.
pub(super) fn editing_rows(
state: &QuestionPromptState,
room: usize,
max_rows: usize,
(text, selected): (Style, Style),
) -> (Vec<Vec<Span<'static>>>, bool) {
let editor = state.answer();
let max_rows = max_rows.max(1);
let (width, layout) = fit(editor, room, max_rows);
state.set_answer_width(width);
let caret = editor.cursor_in(&layout);
// The window follows the caret, so the row being typed in is always on screen
let first = caret.row.saturating_sub(max_rows - 1);
let rows = layout.rows()[first..]
.iter()
.take(max_rows)
.enumerate()
.map(|(offset, segments)| {
let at = (first + offset == caret.row).then_some(caret.column);
row_spans(segments, at, text, selected)
})
.collect();
(rows, first > 0)
}
/// The width the answer wraps at, and its wrap: a cell short of `room` for the caret, and one more
/// when it takes more than `max_rows` and needs the scrolled mark.
fn fit(editor: &Editor, room: usize, max_rows: usize) -> (u16, TextLayout) {
let cells = |width: usize| u16::try_from(width.max(1)).unwrap_or(u16::MAX);
let width = cells(room.saturating_sub(1));
let layout = editor.layout(width);
if layout.row_count() <= max_rows {
return (width, layout);
}
let width = cells(room.saturating_sub(2));
(width, editor.layout(width))
}
/// One row's spans, the selection lit and the caret set before the cell at column `caret`.
fn row_spans(
segments: &[VisualSegment],
caret: Option<usize>,
text: Style,
selected: Style,
) -> Vec<Span<'static>> {
let mut spans = Vec::new();
let mut column = 0usize;
for segment in segments {
let style = if segment.is_selected { text.patch(selected) } else { text };
let mut run = String::new();
for character in segment.text.chars() {
if caret == Some(column) {
spans.push(Span::styled(std::mem::take(&mut run), style));
spans.push(Span::styled(CARET, text));
}
run.push(character);
column += unicode_width::UnicodeWidthChar::width(character).unwrap_or(0);
}
spans.push(Span::styled(run, style));
}
if caret.is_some_and(|at| at >= column) {
spans.push(Span::styled(CARET, text));
}
spans.retain(|span| !span.content.is_empty());
spans
}

View File

@@ -68,22 +68,31 @@ fn row_content(
// truncating: an answer cut off at the right edge is one the reader cannot check
// before sending it.
None => {
let body = if state.editing() {
format!("{}▏", state.custom())
} else if state.custom().is_empty() {
CUSTOM_PLACEHOLDER.to_string()
} else {
state.custom().to_string()
};
let number = format!("{}. ", i + 1);
// The text column, wherever a longer number puts it
let text_at = indent + number.chars().count().saturating_sub(3);
let room = text_width.saturating_sub(text_at);
let (mut wrapped, scrolled) = custom_view(&body, room, custom_rows, state.editing());
let (mut wrapped, scrolled) = match state.editing() {
true => {
let styles = (label_style, theme.selected_bg);
super::answer::editing_rows(state, room, custom_rows, styles)
}
false => {
let body = match state.custom() {
"" => CUSTOM_PLACEHOLDER,
typed => typed,
};
let rows = wrapped_rows(body, room, custom_rows);
(
rows.into_iter().map(|row| vec![Span::styled(row, label_style)]).collect(),
false,
)
}
};
// An answer of nothing but spaces still owns a row: it is the one the cursor
// can land on, and the click regions are laid out over the rows there are.
if wrapped.is_empty() {
wrapped.push(String::new());
wrapped.push(Vec::new());
}
for (index, row) in wrapped.into_iter().enumerate() {
let mut line = if index == 0 {
@@ -99,7 +108,7 @@ fn row_content(
let lead = if index == 0 { "…" } else { " " };
line.push(Span::styled(lead, cursor_style));
}
line.push(Span::styled(row, label_style));
line.extend(row);
content.push(line);
}
}
@@ -176,24 +185,3 @@ pub(super) fn wrapped_rows(text: &str, width: usize, max_rows: usize) -> Vec<Str
}
rows
}
/// The rows of a typed answer that fit, and whether any were left above them.
///
/// While the row is being edited the caret is what has to stay on screen, so the window follows
/// the tail of the answer; at rest it reads from the top like any other text, with the usual
/// clipped-tail mark.
fn custom_view(text: &str, width: usize, max_rows: usize, editing: bool) -> (Vec<String>, bool) {
if !editing {
return (wrapped_rows(text, width, max_rows), false);
}
if max_rows == 0 {
return (Vec::new(), false);
}
let rows = wrap_rows(text, width);
if rows.len() <= max_rows {
return (rows, false);
}
// a cell short, for the mark that says there is more above
let mut rows = wrap_rows(text, width.saturating_sub(1));
(rows.split_off(rows.len() - max_rows), true)
}

View File

@@ -1,7 +1,9 @@
//! Question prompt state — which row the cursor is on, what is checked, and what a key does.
use crate::editor::Editor;
use crossterm::event::{KeyCode, KeyEvent, KeyModifiers};
use luxe_core::question::{default_selection, QuestionOption, QuestionRequestId};
use std::cell::Cell;
/// State for an in-flight question modal (one at a time — tools dispatch sequentially).
#[derive(Clone, Debug)]
@@ -18,9 +20,11 @@ pub struct QuestionPromptState {
selected: usize,
/// Per-option checkbox state (multi-select only).
checked: Vec<bool>,
/// The user's free-text answer.
custom: String,
/// Whether the free-text row is being edited (keystrokes append to `custom`).
/// The user's free-text answer: the composer's editor, so the caret moves and edits where it is.
custom: Editor,
/// Cells the answer last wrapped at on screen, so up and down move through the rows drawn.
answer_width: Cell<u16>,
/// Whether the free-text row is being edited (keystrokes go to `custom`).
editing: bool,
/// Whether the typed answer is checked (multi-select): typing checks it, Space toggles it.
custom_checked: bool,
@@ -53,7 +57,8 @@ impl QuestionPromptState {
multi,
selected,
checked,
custom: String::new(),
custom: Editor::new(),
answer_width: Cell::new(u16::MAX),
editing: false,
custom_checked: false,
}
@@ -77,16 +82,26 @@ impl QuestionPromptState {
/// Whether row `i` is checked (multi-select), the typed answer included.
pub fn is_checked(&self, i: usize) -> bool {
if i == self.custom_row() {
return self.custom_checked && !self.custom.trim().is_empty();
return self.custom_checked && !self.custom().trim().is_empty();
}
self.checked.get(i).copied().unwrap_or(false)
}
/// The current free-text entry.
pub fn custom(&self) -> &str {
self.custom.current_input()
}
/// The free-text entry's editor, for drawing it with its caret and selection.
pub(crate) fn answer(&self) -> &Editor {
&self.custom
}
/// Records the width the answer was just drawn at; up and down wrap it the same way.
pub(super) fn set_answer_width(&self, width: u16) {
self.answer_width.set(width);
}
/// Whether the free-text row is in edit mode.
pub fn editing(&self) -> bool {
self.editing
@@ -99,7 +114,7 @@ impl QuestionPromptState {
return;
}
self.start_typing();
self.custom.push_str(&text);
self.custom.insert_text(&text);
}
/// Move the cursor to `index` (a hover or a click), clamped to range.
@@ -136,7 +151,7 @@ impl QuestionPromptState {
/// A single answer is one answer. Text left in the typed row while picking another option used
/// to ride along with it, which made a choice and an abandoned draft one reply.
fn collect(&self, option: Option<usize>) -> Vec<String> {
let custom = self.custom.trim();
let custom = self.custom().trim();
if !self.multi {
return match option {
Some(i) => vec![self.options[i].label.clone()],
@@ -206,7 +221,7 @@ impl QuestionPromptState {
if self.multi {
QuestionPromptOutcome::Answer(self.collect(None))
} else if self.selected == self.custom_row() {
if self.custom.trim().is_empty() {
if self.custom().trim().is_empty() {
self.editing = true;
QuestionPromptOutcome::Consumed
} else {
@@ -217,9 +232,9 @@ impl QuestionPromptState {
}
}
// Start typing anywhere jumps into the free-text row.
KeyCode::Char(c) if !ctrl => {
KeyCode::Char(_) if !ctrl => {
self.start_typing();
self.custom.push(c);
self.custom.handle_key(*key);
QuestionPromptOutcome::Consumed
}
_ => QuestionPromptOutcome::Consumed,
@@ -234,31 +249,56 @@ impl QuestionPromptState {
QuestionPromptOutcome::Consumed
}
KeyCode::Char('c') if ctrl => {
self.custom.clear();
QuestionPromptOutcome::Consumed
}
KeyCode::Backspace => {
self.custom.pop();
self.custom.select_all();
self.custom.delete_selection();
QuestionPromptOutcome::Consumed
}
KeyCode::Up | KeyCode::Down => self.vertical_in_answer(key),
// The answer is one reply on one line, and Tab means nothing in it
KeyCode::Tab | KeyCode::BackTab => QuestionPromptOutcome::Consumed,
// Every Enter, Shift+Enter's newline included, is the question's to answer
KeyCode::Enter => {
if self.multi {
// Commit the text and submit everything checked plus the free text.
self.editing = false;
QuestionPromptOutcome::Answer(self.collect(None))
} else if self.custom.trim().is_empty() {
} else if self.custom().trim().is_empty() {
self.editing = false;
QuestionPromptOutcome::Consumed
} else {
QuestionPromptOutcome::Answer(self.collect(None))
}
}
KeyCode::Char(c) if !ctrl => {
self.custom.push(c);
self.custom_checked = true;
// Typing, deleting and every caret motion are the composer's own
_ => {
let before = self.custom().len();
self.custom.handle_key(*key);
if self.custom().len() > before {
self.custom_checked = true;
}
QuestionPromptOutcome::Consumed
}
_ => QuestionPromptOutcome::Consumed,
}
}
/// Up and down move through the rows the answer wraps to; from its first row up, or its last
/// row down, they leave it for the options, as the launcher hands its arrows to the list.
/// Shift always stays in the answer, where it is selecting.
fn vertical_in_answer(&mut self, key: &KeyEvent) -> QuestionPromptOutcome {
self.custom.set_viewport_width(self.answer_width.get());
let up = key.code == KeyCode::Up;
let edge =
if up { self.custom.cursor_on_first_row() } else { self.custom.cursor_on_last_row() };
if edge && !key.modifiers.contains(KeyModifiers::SHIFT) {
self.editing = false;
if up {
self.move_up();
} else {
self.move_down();
}
} else {
self.custom.handle_key(*key);
}
QuestionPromptOutcome::Consumed
}
}

View File

@@ -543,3 +543,84 @@ fn the_measured_height_is_the_height_it_draws() {
}
assert_eq!(height(&s, &theme, 0, 20), 0, "no width, no panel");
}
fn type_answer(state: &mut QuestionPromptState, text: &str) {
for c in text.chars() {
state.on_key(&key(KeyCode::Char(c)));
}
}
/// The typed answer edits where its caret is: the arrows move it, and typing, Backspace and Delete
/// act there rather than at the end of the text.
#[test]
fn the_typed_answer_edits_at_its_caret() {
let mut state = state(false);
type_answer(&mut state, "helo");
state.on_key(&key(KeyCode::Left));
state.on_key(&key(KeyCode::Left));
state.on_key(&key(KeyCode::Char('l')));
assert_eq!(state.custom(), "hello");
state.on_key(&key(KeyCode::Home));
state.on_key(&key(KeyCode::Delete));
assert_eq!(state.custom(), "ello", "delete takes the character after the caret");
state.on_key(&key(KeyCode::End));
state.on_key(&key(KeyCode::Backspace));
assert_eq!(state.custom(), "ell");
assert!(state.editing(), "none of that left the answer");
}
/// A word jump moves through the answer the way it does in the composer.
#[test]
fn a_word_jump_moves_through_the_typed_answer() {
let mut state = state(false);
type_answer(&mut state, "one two");
state.on_key(&KeyEvent::new(KeyCode::Left, KeyModifiers::ALT));
type_answer(&mut state, "big ");
assert_eq!(state.custom(), "one big two");
}
/// Up and down move through the rows a long answer wraps to, and up from its first row leaves the
/// answer for the option above, the way the launcher hands its arrows to the list.
#[test]
fn up_and_down_move_through_a_wrapped_answer_then_leave_it() {
let mut state = state(false);
type_answer(&mut state, "alpha beta gamma delta epsilon zeta eta theta iota kappa");
// Drawn once, so the answer has wrapped at the panel's width
render(&state, 30, 24);
let end = state.answer().cursor();
state.on_key(&key(KeyCode::Up));
assert!(state.editing() && state.answer().cursor() < end, "up reached the row above");
state.on_key(&key(KeyCode::Down));
assert_eq!(state.answer().cursor(), end, "and down came back");
// Bounded, so a regression that never leaves fails rather than hangs
for _ in 0..10 {
if state.editing() {
state.on_key(&key(KeyCode::Up));
}
}
assert!(!state.editing(), "up from the first row leaves the answer");
assert_eq!(state.selected(), 1, "for the option above it");
}
/// An answer short enough for one row has nowhere to go: down leaves it at once.
#[test]
fn down_from_a_one_row_answer_leaves_it() {
let mut state = state(false);
type_answer(&mut state, "short");
render(&state, 60, 24);
state.on_key(&key(KeyCode::Down));
assert!(!state.editing());
assert_eq!(state.selected(), 0, "down from the last row wraps to the first option");
}
/// The caret is drawn where typing lands, not after the last character.
#[test]
fn the_caret_is_drawn_where_typing_lands() {
let mut state = state(false);
type_answer(&mut state, "abc");
state.on_key(&key(KeyCode::Left));
let (text, _) = render(&state, 60, 12);
assert!(text.contains("ab▏c"), "the caret sits before the c: {text}");
}

View File

@@ -64,9 +64,9 @@ ChatTurn@64x20: frame=91595c7c8fb3a9de hits=bc965e96875bbfe6
ChatPermission@140x44: frame=54ddeb5522ffcb19 hits=063b591e442cd221
ChatPermission@100x30: frame=b2c0e21530b64523 hits=200049ec7749eeb8
ChatPermission@64x20: frame=9f98f5664f85406f hits=abbd7bfaa97a4ed0
ChatPalette@140x44: frame=2563eb3755b4caff hits=bf9355f178f8e332
ChatPalette@100x30: frame=ef4b4b78ce5ecf34 hits=eae72d9c1c194fee
ChatPalette@64x20: frame=77258679e0458932 hits=888344c2d380ae7f
ChatPalette@140x44: frame=3022f8834ce418f2 hits=bf9355f178f8e332
ChatPalette@100x30: frame=cacc9b3e033c0401 hits=eae72d9c1c194fee
ChatPalette@64x20: frame=085c324962ef0357 hits=888344c2d380ae7f
ChatScreenshot@140x44: frame=5aec1b106f841d81 hits=1489393a2950d711
ChatScreenshot@100x30: frame=709f9e4b32a7c8f6 hits=f8537762de7b55a2
ChatScreenshot@64x20: frame=0a22c420e0e4092e hits=1e33d25e6f2a5032
@@ -178,7 +178,7 @@ ChangesFailed@64x20: frame=69cdcefbe785c866 hits=27476cdcd9937bea
ChangesExternal@140x44: frame=fc75aaae10ddb262 hits=d5c3115642e748ad
ChangesExternal@100x30: frame=522c8250b0f50ac4 hits=3dd17e6200cfb4b5
ChangesExternal@64x20: frame=a6d2706231364207 hits=6f0e8da295aaa965
ChatTools+palette: frame=96a7e733812fba95 hits=ca2a2a735278a5bd
ChatTools+palette: frame=85cc5ae977de2fa6 hits=ca2a2a735278a5bd
ChatTools+slash: frame=a3ce4c3a7d03f8d0 hits=8adf06de80ecdcb2
ChatTools+mention: frame=33c4a73f189a3dcc hits=c1b8d78b51a767b7
ChatTools+model: frame=98b419f1ad7ab1ea hits=c1b8d78b51a767b7