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,100 @@
//! Review scrolling — the diff's rows and columns, and the hunk the cursor lands in.
use super::*;
impl GuidedReviewWorkspace {
/// Returns horizontally clipped diff source lines to their first terminal cell.
pub(crate) fn reset_column_offset(&mut self) {
self.diff_column_offset = 0;
}
/// Moves the selected file's source right by one bounded terminal-cell step, in whichever
/// layout it is drawn.
pub(crate) fn next_column(&mut self, files: &[ReviewFile]) {
let maximum = self.selected_file(files).map_or(0, |file| self.column_maximum(file));
self.diff_column_offset =
self.diff_column_offset.saturating_add(COLUMN_SCROLL_STEP).min(maximum);
}
/// Clamps horizontal position after a resize or presentation change.
pub(crate) fn clamp_column_offset(&mut self, files: &[ReviewFile]) {
let maximum = self.selected_file(files).map_or(0, |file| self.column_maximum(file));
self.diff_column_offset = self.diff_column_offset.min(maximum);
}
/// Moves the selected diff source left by one terminal-cell step without underflow.
pub(crate) fn previous_column(&mut self) {
self.diff_column_offset = self.diff_column_offset.saturating_sub(COLUMN_SCROLL_STEP);
}
/// Puts the cursor on the row `pick` chooses out of the furthest it can go, the way a drag on
/// the diff's scrollbar does.
pub(crate) fn scroll_to_row(
&mut self,
review: &GuidedReview,
pick: impl FnOnce(usize) -> usize,
) {
let files = &review.files;
let max_offset =
selected_file_row_count(&self.position, files, &self.fold).saturating_sub(1);
self.position.line_offset = pick(max_offset).min(max_offset);
self.sync_hunk_to_offset(files);
}
/// Scrolls the diff within the selected file, stopping at either end.
///
/// Never rolls into the neighboring file: the pane draws one file at a time, so one row too
/// many would silently move you to a diff you did not mean to be in. Moving between files is
/// what the explicit keys are for (`Space`/`n`, `[`/`]`, `Ctrl+↑/↓`), which keep the narration
/// and the reviewed marks in step; scrolling is only ever a look around.
pub(in crate::guided_review) fn scroll_lines(
&mut self,
review: &GuidedReview,
amount: usize,
forward: bool,
) {
let files = &review.files;
let max_offset =
selected_file_row_count(&self.position, files, &self.fold).saturating_sub(1);
self.position.line_offset = if forward {
self.position.line_offset.saturating_add(amount).min(max_offset)
} else {
self.position.line_offset.saturating_sub(amount)
};
self.sync_hunk_to_offset(files);
}
/// Re-points the selection at whatever the cursor row now sits inside, after the row space
/// changed underneath it (a fold opening or closing).
pub(crate) fn sync_hunk_to_cursor(&mut self, files: &[ReviewFile]) {
let rows = selected_file_row_count(&self.position, files, &self.fold);
self.position.line_offset = self.position.line_offset.min(rows.saturating_sub(1));
self.sync_hunk_to_offset(files);
}
/// Keeps the selected hunk pointing at whatever the cursor row now sits inside, so the
/// breadcrumb and reviewed marker follow a continuous scroll.
pub(super) fn sync_hunk_to_offset(&mut self, files: &[ReviewFile]) {
let Some(file) =
self.position.file_id.as_ref().and_then(|id| files.iter().find(|file| &file.id == id))
else {
return;
};
let mut row = 0usize;
for group in visible_groups(file, &self.fold) {
let span = group.rows();
if self.position.line_offset < row + span {
// A collapsed run belongs to no hunk, so the breadcrumb drops to the file.
let landed = match group {
VisibleGroup::Hunk(hunk) => Some(hunk.id.clone()),
VisibleGroup::Folded(_) => None,
};
if self.position.hunk_id != landed {
self.position.hunk_id = landed;
}
return;
}
row += span;
}
}
}

View File

@@ -0,0 +1,126 @@
//! Review search — the query, the rows it matches, and jumping between them.
use super::*;
impl GuidedReviewWorkspace {
/// Opens the in-diff search prompt with an empty query.
pub(crate) fn begin_search(&mut self) {
self.search = Some(String::new());
}
pub(crate) fn search_input(&mut self, character: char) {
if let Some(query) = self.search.as_mut() {
query.push(character);
}
}
pub(crate) fn search_backspace(&mut self) {
if let Some(query) = self.search.as_mut() {
query.pop();
}
}
pub(crate) fn cancel_search(&mut self) {
self.search = None;
}
/// Whether a source line matches the active (non-empty) search query, case-insensitively.
pub(crate) fn line_matches_search(&self, text: &str) -> bool {
self.search
.as_ref()
.filter(|query| !query.is_empty())
.is_some_and(|query| text.to_lowercase().contains(&query.to_lowercase()))
}
/// Visible-row indices in `file` whose source text matches `needle` (already lowercased),
/// counted like `line_offset` (hunk header + lines, respecting noise folding) so a match row
/// is jumpable.
fn file_match_rows(&self, file: &ReviewFile, needle: &str) -> Vec<usize> {
let mut rows = Vec::new();
let mut row = 0usize;
for group in visible_groups(file, &self.fold) {
let VisibleGroup::Hunk(hunk) = group else {
row += 1;
continue;
};
row += 1; // hunk header
for line in &hunk.lines {
if crate::tabstop::display_text(&line.text).to_lowercase().contains(needle) {
rows.push(row);
}
row += 1;
}
}
rows
}
/// Visible-row indices in the selected file whose source text matches the query.
fn current_file_match_rows(&self, files: &[ReviewFile], query: &str) -> Vec<usize> {
let Some(file) =
self.position.file_id.as_ref().and_then(|id| files.iter().find(|f| &f.id == id))
else {
return Vec::new();
};
self.file_match_rows(file, &query.to_lowercase())
}
/// Jumps the diff cursor to the next/previous search match. Prefers a match past the cursor in
/// the selected file, then walks to the next/previous file (cyclically) that has a match,
/// landing on its first (forward) / last (backward) hit; the final step wraps within the
/// current file. Returns whether a match was found anywhere.
///
/// Find-in-diff is deliberately whole-review, so a hit outside the current chapter re-points
/// the narrative rather than showing a chapter that does not own the match.
pub(crate) fn jump_search(&mut self, review: &GuidedReview, forward: bool) -> bool {
let files = &review.files;
let Some(query) = self.search.as_ref().filter(|q| !q.is_empty()).cloned() else {
return false;
};
let needle = query.to_lowercase();
// A match strictly past the cursor in the current file wins first.
let current_rows = self.current_file_match_rows(files, &query);
let current = self.position.line_offset;
let within = if forward {
current_rows.iter().copied().find(|&row| row > current)
} else {
current_rows.iter().copied().rev().find(|&row| row < current)
};
if let Some(target) = within {
self.select_diff_row(review, target);
return true;
}
// Otherwise scan the other files in order (wrapping); the last step revisits the current
// file, so a single-file query still wraps to its first/last match.
if files.is_empty() {
return false;
}
let count = files.len();
let current_index = self
.position
.file_id
.as_ref()
.and_then(|id| files.iter().position(|file| &file.id == id))
.unwrap_or(0);
for step in 1..=count {
let index = if forward {
(current_index + step) % count
} else {
(current_index + count - step) % count
};
let rows = self.file_match_rows(&files[index], &needle);
let target = if forward { rows.first().copied() } else { rows.last().copied() };
let Some(target) = target else {
continue;
};
if index != current_index {
let file_id = files[index].id.clone();
self.select_file_by_id(review, &file_id);
}
self.select_diff_row(review, target);
return true;
}
false
}
}

View File

@@ -0,0 +1,228 @@
//! Review selection — what a click or a jump selects, and where the position lands after a
//! refresh.
use super::*;
impl GuidedReviewWorkspace {
/// Moves the cursor to `offset` as an explicit jump does (a click, a search hit): within the
/// file's rows, the hunk following the row and the chapter following the hunk.
pub(crate) fn select_diff_row(&mut self, review: &GuidedReview, offset: usize) {
let rows = selected_file_row_count(&self.position, &review.files, &self.fold);
self.position.line_offset = offset.min(rows.saturating_sub(1));
self.sync_hunk_to_offset(&review.files);
self.sync_chapter_to_selection(review);
}
/// Points the review at one place in the guide: a chapter, or a file inside one.
///
/// The only way in from outside the stepping keys — a click on a guide row, a jump from a
/// finding. There is nothing to "open" afterwards, because the detail pane already shows
/// whatever the position lands on.
pub(crate) fn open_guide_target(
&mut self,
review: &GuidedReview,
file_id: Option<&FileId>,
hunk_id: Option<&HunkId>,
chapter_id: Option<&ChapterId>,
) {
if let Some(chapter_id) = chapter_id {
self.position.chapter_id = Some(chapter_id.clone());
let stops = self.stops(review);
if let Some(first) = step_stop(&stops, None, true) {
self.select_stop(review, stops[first]);
}
return;
}
let Some(file_id) = file_id else {
return;
};
let Some(file) = review.files.iter().find(|file| &file.id == file_id) else {
return;
};
match hunk_id.and_then(|id| file.hunks.iter().position(|hunk| &hunk.id == id)) {
Some(index) => self.select_finding_hunk(file, index, None),
None => self.select_file_by_id(review, file_id),
}
self.sync_chapter_to_selection(review);
}
/// Selects a file by id (a click on its rail row): makes it current, focuses
/// its first visible hunk, and re-points the narrative at the owning chapter. Reveals folded
/// content when that is the only way to show the file. No-op for an unknown or empty file.
pub(crate) fn select_file_by_id(&mut self, review: &GuidedReview, file_id: &FileId) {
let Some(file) = review.files.iter().find(|file| &file.id == file_id) else {
return;
};
if file.non_text.is_none() && file.hunks.is_empty() {
return;
}
self.position.file_id = Some(file.id.clone());
// Land on the first hunk the fold leaves open rather than opening the file's churn just
// because it happens to sort first.
match file.hunks.iter().position(|hunk| !self.fold.hides(file, hunk)) {
Some(index) => self.select_hunk(file, index),
None => self.clear_hunk_selection(),
}
self.sync_chapter_to_selection(review);
}
pub(in crate::guided_review) fn select_finding_hunk(
&mut self,
file: &ReviewFile,
index: usize,
line_index: Option<usize>,
) {
self.reveal_if_folded(file, &file.hunks[index]);
self.position.file_id = Some(file.id.clone());
self.position.hunk_id = Some(file.hunks[index].id.clone());
self.position.line_offset = visible_row_offset(file, index, &self.fold)
.saturating_add(usize::from(line_index.is_some()))
.saturating_add(line_index.unwrap_or_default());
}
pub(super) fn select_hunk(&mut self, file: &ReviewFile, index: usize) {
let hunk_id = file.hunks[index].id.clone();
self.position.hunk_id = Some(hunk_id);
self.position.line_offset = visible_row_offset(file, index, &self.fold);
// A no-op within one file; arriving at a narrower one, it keeps the code on screen
self.diff_column_offset = self.diff_column_offset.min(self.column_maximum(file));
}
pub(super) fn clear_hunk_selection(&mut self) {
self.position.hunk_id = None;
self.position.line_offset = 0;
}
/// Re-points the narrative at the chapter owning the current selection.
///
/// Bounded stepping is scoped and can never leave a chapter, but an explicit jump (a click,
/// next-unreviewed, a finding anchor, a search hit) can — and a rail describing chapter 01
/// beside chapter 03's diff is worse than no narrative at all.
pub(in crate::guided_review) fn sync_chapter_to_selection(&mut self, review: &GuidedReview) {
let owning = review.chapters.iter().find(|chapter| {
chapter.items.iter().any(|item| match item {
ReviewItemRef::Hunk(hunk_id) => self.position.hunk_id.as_ref() == Some(hunk_id),
ReviewItemRef::File(file_id) => {
self.position.hunk_id.is_none()
&& self.position.file_id.as_ref() == Some(file_id)
}
})
});
if let Some(chapter) = owning {
self.position.chapter_id = Some(chapter.id.clone());
}
}
/// Opens collapsed content when an explicit jump targets a hunk the fold is hiding, so a
/// selection always shows the thing it selected — and only that file, not the whole review.
fn reveal_if_folded(&mut self, file: &ReviewFile, hunk: &ReviewHunk) {
self.fold.reveal(file, hunk);
}
pub(in crate::guided_review) fn reconcile_folded_selection(&mut self, files: &[ReviewFile]) {
let hunks = files
.iter()
.enumerate()
.flat_map(|(file_index, file)| {
file.hunks
.iter()
.enumerate()
.map(move |(hunk_index, hunk)| (file_index, hunk_index, hunk.id.clone()))
})
.collect::<Vec<_>>();
let Some(start) = self
.position
.hunk_id
.as_ref()
.and_then(|selected| hunks.iter().position(|(_, _, hunk_id)| hunk_id == selected))
else {
return;
};
let Some((file_index, hunk_index, _)) =
hunks.iter().cycle().skip(start).take(hunks.len()).find(
|(file_index, hunk_index, _)| {
let file = &files[*file_index];
!self.fold.hides(file, &file.hunks[*hunk_index])
},
)
else {
return;
};
let (file_index, hunk_index) = (*file_index, *hunk_index);
let file = &files[file_index];
self.position.file_id = Some(file.id.clone());
self.select_hunk(file, hunk_index);
}
/// Keeps a semantic chapter selection when its stable identity survives refresh.
pub(crate) fn reconcile_chapter(&mut self, chapters: &[ReviewChapter]) {
if self
.position
.chapter_id
.as_ref()
.is_some_and(|id| chapters.iter().any(|chapter| &chapter.id == id))
{
return;
}
self.position.chapter_id = chapters.first().map(|chapter| chapter.id.clone());
}
pub(crate) fn reconcile_position(&mut self, files: &[ReviewFile]) {
self.fold.reconcile(files);
let retained = self.position.file_id.as_ref().and_then(|file_id| {
files.iter().find(|file| &file.id == file_id).and_then(|file| {
match &self.position.hunk_id {
Some(hunk_id) => file
.hunks
.iter()
.any(|hunk| &hunk.id == hunk_id)
.then(|| (file_id.clone(), Some(hunk_id.clone()))),
None if file.non_text.is_some() => Some((file_id.clone(), None)),
None => None,
}
})
});
// Open on something the reviewer can actually read: the first hunk the fold leaves open,
// then a non-text item, and only then a file that is nothing but collapsed churn. Landing
// on a collapsed hunk would open the review on a blank pane.
let next = retained.or_else(|| {
files
.iter()
.find_map(|file| {
file.hunks
.iter()
.find(|hunk| !self.fold.hides(file, hunk))
.map(|hunk| (file.id.clone(), Some(hunk.id.clone())))
})
.or_else(|| {
files
.iter()
.find(|file| file.non_text.is_some())
.map(|file| (file.id.clone(), None))
})
.or_else(|| {
files
.iter()
.find(|file| file.is_text() && !file.hunks.is_empty())
.map(|file| (file.id.clone(), None))
})
});
match next {
Some((file_id, hunk_id))
if self.position.file_id.as_ref() == Some(&file_id)
&& self.position.hunk_id == hunk_id => {}
Some((file_id, hunk_id)) => {
self.position = ReviewPosition {
chapter_id: self.position.chapter_id.clone(),
file_id: Some(file_id),
hunk_id,
line_offset: 0,
};
}
None => {
self.position = ReviewPosition::default();
}
}
}
}