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:
145
crates/luxe-tui/src/guided_review/state/finding_draft.rs
Normal file
145
crates/luxe-tui/src/guided_review/state/finding_draft.rs
Normal file
@@ -0,0 +1,145 @@
|
||||
//! The finding draft — one anchor and the comment written against it, and what saving makes of it.
|
||||
|
||||
use luxe_core::guided_review::{
|
||||
FindingAnchor, FindingId, FindingSeverity, FindingState, ReviewFinding,
|
||||
ReviewSessionValidationError,
|
||||
};
|
||||
|
||||
/// Unsaved reviewer input associated with one immutable diff anchor.
|
||||
///
|
||||
/// One anchor and one piece of prose. The composer briefly asked for a title, a proposed fix and a
|
||||
/// severity around it; all three asked the reviewer to split a thought that arrives whole, and none
|
||||
/// told the agent anything the comment had not already said. Severity survives as a field because
|
||||
/// the verb sets it — `c` means the agent should act, `a` means it must answer and not edit — but
|
||||
/// nothing picks it once the box is open.
|
||||
#[derive(Debug, Clone)]
|
||||
pub(crate) struct FindingDraft {
|
||||
/// The source location captured when the draft opens.
|
||||
pub(crate) anchor: FindingAnchor,
|
||||
/// What this asks of the agent, fixed by the verb that opened the draft
|
||||
pub(crate) severity: FindingSeverity,
|
||||
/// A remediation an *earlier* draft carried, preserved untouched through a reopen.
|
||||
///
|
||||
/// Nothing writes this any more. It exists so reopening a draft persisted by a build that
|
||||
/// still had the field does not silently throw the reviewer's suggestion away on the next save.
|
||||
carried_fix: Option<String>,
|
||||
/// The real editor backing the comment.
|
||||
///
|
||||
/// This is the one place a reviewer writes prose, so it reuses Luxe's composer wholesale and
|
||||
/// behaves like every other text input: a cursor, arrow keys, word operations.
|
||||
editor: crate::editor::Editor,
|
||||
/// Why the last save was rejected, cleared by the next edit. Shown on screen, or `Ctrl+Enter`
|
||||
/// would look like a dead key.
|
||||
pub(crate) error: Option<String>,
|
||||
/// Send this straight to the agent on save instead of holding it as a draft.
|
||||
///
|
||||
/// A question left sitting in a draft answers nothing, so `a` dispatches immediately while `c`
|
||||
/// batches for a later send.
|
||||
pub(crate) dispatch_on_save: bool,
|
||||
/// Existing finding this draft replies to, when it is a thread reply rather than a new comment.
|
||||
pub(crate) reply_to: Option<FindingId>,
|
||||
}
|
||||
|
||||
impl FindingDraft {
|
||||
/// Builds an empty draft against one anchor.
|
||||
pub(crate) fn new(
|
||||
anchor: FindingAnchor,
|
||||
severity: FindingSeverity,
|
||||
dispatch_on_save: bool,
|
||||
reply_to: Option<FindingId>,
|
||||
) -> Self {
|
||||
Self {
|
||||
anchor,
|
||||
severity,
|
||||
carried_fix: None,
|
||||
editor: crate::editor::Editor::new(),
|
||||
error: None,
|
||||
dispatch_on_save,
|
||||
reply_to,
|
||||
}
|
||||
}
|
||||
|
||||
/// The reviewer's comment, read live off the editor.
|
||||
pub(crate) fn body(&self) -> &str {
|
||||
self.editor.current_input()
|
||||
}
|
||||
|
||||
/// Replaces the comment, loading it into the editor.
|
||||
pub(crate) fn set_body(&mut self, text: impl Into<String>) {
|
||||
let text = text.into();
|
||||
self.editor.cancel();
|
||||
self.editor.insert_text(&text);
|
||||
self.error = None;
|
||||
}
|
||||
|
||||
/// Keeps a remediation an earlier build authored, so a reopen does not drop it.
|
||||
pub(crate) fn carry_fix(&mut self, fix: Option<String>) {
|
||||
self.carried_fix = fix.filter(|fix| !fix.trim().is_empty());
|
||||
}
|
||||
|
||||
/// The live editor, so the overlay can draw a real cursor.
|
||||
pub(crate) fn editor(&self) -> &crate::editor::Editor {
|
||||
&self.editor
|
||||
}
|
||||
|
||||
/// The width the field is drawn at, so `↑/↓` moves by the rows the reader sees.
|
||||
pub(crate) fn set_width(&mut self, width: u16) {
|
||||
self.editor.set_viewport_width(width);
|
||||
}
|
||||
|
||||
/// Routes one key to the focused field's editor.
|
||||
///
|
||||
/// `Enter` inserts a newline instead of submitting: the composer's save is `Ctrl+Enter`, and a
|
||||
/// stray `Enter` must never fire the chat submit behind the review.
|
||||
pub(crate) fn handle_key(&mut self, key: crossterm::event::KeyEvent) {
|
||||
use crossterm::event::KeyCode;
|
||||
self.error = None;
|
||||
match key.code {
|
||||
KeyCode::Enter => self.editor.insert_newline(),
|
||||
_ => self.editor.handle_key(key),
|
||||
}
|
||||
}
|
||||
|
||||
/// Inserts pasted text into the focused field.
|
||||
///
|
||||
/// Without this, a paste while the composer was open reached the *chat* editor behind the
|
||||
/// review — from the reviewer's point of view the text simply vanished.
|
||||
pub(crate) fn paste(&mut self, text: &str) {
|
||||
self.error = None;
|
||||
self.editor.paste_text(text);
|
||||
}
|
||||
|
||||
/// The title the comment will carry: its own opening line.
|
||||
///
|
||||
/// There is no title field. Requiring one made the common case — a sentence of feedback — fail
|
||||
/// to save, and once it was optional it became a box that echoed what you were already typing
|
||||
/// into the box above it, one line behind. The durable record still has a title because the
|
||||
/// drawer, the send preview and the agent's message all need something short to name a comment
|
||||
/// by; deriving it costs the reviewer nothing.
|
||||
pub(crate) fn resolved_title(&self) -> String {
|
||||
luxe_core::guided_review::title_from_body(self.body())
|
||||
}
|
||||
|
||||
/// Builds a validated core finding without consuming the local draft.
|
||||
pub(crate) fn to_review_finding(
|
||||
&self,
|
||||
id: FindingId,
|
||||
) -> Result<ReviewFinding, ReviewSessionValidationError> {
|
||||
let finding = ReviewFinding {
|
||||
posted: None,
|
||||
github_thread: None,
|
||||
id,
|
||||
// The session assigns the next `R<n>` on insert; an edit keeps the one it already has.
|
||||
label: String::new(),
|
||||
anchor: self.anchor.clone(),
|
||||
severity: self.severity,
|
||||
title: self.resolved_title(),
|
||||
body: self.body().to_owned(),
|
||||
proposed_fix: self.carried_fix.clone(),
|
||||
state: FindingState::Draft,
|
||||
thread: Vec::new(),
|
||||
};
|
||||
finding.validate()?;
|
||||
Ok(finding)
|
||||
}
|
||||
}
|
||||
143
crates/luxe-tui/src/guided_review/state/opening.rs
Normal file
143
crates/luxe-tui/src/guided_review/state/opening.rs
Normal file
@@ -0,0 +1,143 @@
|
||||
//! Opening and answering — a pull request opened, a stack of them, a fix on another's, and answers
|
||||
//! to one's own threads.
|
||||
|
||||
use luxe_core::guided_review::FindingId;
|
||||
|
||||
/// A branch's review as a stack of pull requests, before it opens.
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub(crate) struct StackOpening {
|
||||
/// The attempt in flight
|
||||
pub(crate) request_id: luxe_core::guided_review::PullRequestOpenId,
|
||||
/// The pull requests, bottom first, once drafted
|
||||
pub(crate) layers: Option<Vec<luxe_core::github::NewPullRequest>>,
|
||||
/// Whether they open as drafts
|
||||
pub(crate) draft: bool,
|
||||
/// Whether it is opening
|
||||
pub(crate) opening: bool,
|
||||
/// Why it cannot, or what stopped it
|
||||
pub(crate) error: Option<String>,
|
||||
}
|
||||
|
||||
/// Fixing someone else's pull request in a worktree, before the session is left to do it.
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub(crate) struct PullRequestFix {
|
||||
/// Number within its repository
|
||||
pub(crate) number: u64,
|
||||
/// The local branch it would be checked out on, once GitHub said it can be
|
||||
pub(crate) branch: Option<String>,
|
||||
/// Why it cannot be, once GitHub said so
|
||||
pub(crate) refusal: Option<String>,
|
||||
/// Unsent comments that go with it
|
||||
pub(crate) comments: usize,
|
||||
}
|
||||
|
||||
/// A branch's pull request, drafted from its review, before it opens.
|
||||
///
|
||||
/// Modal from open to settled, like the post preview: closing it while it opens would lose the
|
||||
/// answer that says where the pull request is.
|
||||
#[derive(Debug, Clone)]
|
||||
pub(crate) struct PullRequestOpening {
|
||||
/// The attempt in flight
|
||||
pub(crate) request_id: luxe_core::guided_review::PullRequestOpenId,
|
||||
/// The draft and what opening it involves, once the engine has read them
|
||||
pub(crate) prepared: Option<PreparedOpening>,
|
||||
/// The field being edited, when one is
|
||||
pub(crate) editing: Option<(OpeningField, crate::editor::Editor)>,
|
||||
/// Rows the description is scrolled down, clamped where it is drawn
|
||||
pub(crate) body_scroll: u16,
|
||||
/// Rows the description can scroll, as last drawn
|
||||
pub(crate) body_room: std::cell::Cell<u16>,
|
||||
/// Whether it has been sent and not yet answered
|
||||
pub(crate) opening: bool,
|
||||
/// The last failure, as a sentence
|
||||
pub(crate) error: Option<String>,
|
||||
}
|
||||
|
||||
/// What opening a pull request involves, as the preview shows it.
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub(crate) struct PreparedOpening {
|
||||
/// The pull request, with the reader's edits
|
||||
pub(crate) pull_request: luxe_core::github::NewPullRequest,
|
||||
/// Whether the branch is on GitHub yet
|
||||
pub(crate) publication: luxe_core::github::Publication,
|
||||
/// Paths with changes not committed
|
||||
pub(crate) uncommitted: usize,
|
||||
/// Subjects of the commits written first
|
||||
pub(crate) commits: Vec<String>,
|
||||
}
|
||||
|
||||
/// The part of a pull request the reader is editing.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum OpeningField {
|
||||
/// The one-line title
|
||||
Title,
|
||||
/// The description
|
||||
Body,
|
||||
}
|
||||
|
||||
/// Answers on their way to your own pull request's review threads.
|
||||
///
|
||||
/// Modal from open to settled, like the post preview, and for the same reason: closing it while
|
||||
/// answers are in flight would drop the results that mark them answered.
|
||||
#[derive(Debug, Clone)]
|
||||
pub(crate) struct ThreadAnswers {
|
||||
/// The attempt in flight
|
||||
pub(crate) request_id: luxe_core::guided_review::ThreadAnswersId,
|
||||
/// One per unanswered thread, in review order
|
||||
pub(crate) rows: Vec<AnswerRow>,
|
||||
/// Row under the cursor
|
||||
pub(crate) selected: usize,
|
||||
/// The reply being written for the selected row, when one is
|
||||
pub(crate) replying: Option<crate::editor::Editor>,
|
||||
/// Whether the fix is on GitHub, once asked: `(pushed, uncommitted)`
|
||||
pub(crate) prepared: Option<(bool, bool)>,
|
||||
/// Whether answers have been sent and not yet reported on
|
||||
pub(crate) sending: bool,
|
||||
/// A failure before any thread was touched
|
||||
pub(crate) error: Option<String>,
|
||||
}
|
||||
|
||||
/// One thread in the answers preview.
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub(crate) struct AnswerRow {
|
||||
/// The finding the thread became
|
||||
pub(crate) finding_id: FindingId,
|
||||
/// Whether to resolve it
|
||||
pub(crate) resolve: bool,
|
||||
/// The reader's reply, empty for none
|
||||
pub(crate) reply: String,
|
||||
/// How the last attempt at this thread went, when it failed
|
||||
pub(crate) error: Option<String>,
|
||||
}
|
||||
|
||||
impl ThreadAnswers {
|
||||
/// Opens on every thread not yet resolved on GitHub, resolving by default the ones the reader
|
||||
/// verified and may resolve.
|
||||
pub(crate) fn new(
|
||||
request_id: luxe_core::guided_review::ThreadAnswersId,
|
||||
findings: &[luxe_core::guided_review::ReviewFinding],
|
||||
) -> Self {
|
||||
let rows = findings
|
||||
.iter()
|
||||
.filter_map(|finding| {
|
||||
let thread = finding.github_thread.as_ref().filter(|thread| !thread.resolved)?;
|
||||
Some(AnswerRow {
|
||||
finding_id: finding.id.clone(),
|
||||
resolve: thread.can_resolve
|
||||
&& finding.state == luxe_core::guided_review::FindingState::Resolved,
|
||||
reply: String::new(),
|
||||
error: None,
|
||||
})
|
||||
})
|
||||
.collect();
|
||||
Self {
|
||||
request_id,
|
||||
rows,
|
||||
selected: 0,
|
||||
replying: None,
|
||||
prepared: None,
|
||||
sending: false,
|
||||
error: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
68
crates/luxe-tui/src/guided_review/state/outcomes.rs
Normal file
68
crates/luxe-tui/src/guided_review/state/outcomes.rs
Normal file
@@ -0,0 +1,68 @@
|
||||
//! Review outcomes — the finish chooser's choices and the commit preview.
|
||||
|
||||
/// A pending commit, showing the messages before any history is written.
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub(crate) struct CommitPreview {
|
||||
/// Collapse every chapter into one commit.
|
||||
pub(crate) squash: bool,
|
||||
/// Whether the request is in flight.
|
||||
pub(crate) running: bool,
|
||||
}
|
||||
|
||||
/// Explicit user choice shown before closing or submitting a review.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub(crate) enum FinishReviewChoice {
|
||||
/// Record an accepted outcome without contacting the agent.
|
||||
Accept,
|
||||
/// Record acceptance and turn the reviewed chapters into commits.
|
||||
AcceptAndCommit,
|
||||
/// Send actionable findings to the active agent.
|
||||
RequestFixes,
|
||||
/// Send review comments without requesting edits.
|
||||
CommentOnly,
|
||||
/// Reply to and resolve your own pull request's threads on GitHub.
|
||||
AnswerOnGitHub,
|
||||
/// Commit the reviewed work, push the branch, and open its pull request.
|
||||
OpenPullRequest,
|
||||
/// Commit the reviewed work chapter by chapter and open it as a stack of pull requests.
|
||||
OpenStack,
|
||||
/// Close the local chooser without changing durable review state.
|
||||
Cancel,
|
||||
}
|
||||
|
||||
impl FinishReviewChoice {
|
||||
/// Moves through the finish-review choices in presentation order; `answers` offers answering
|
||||
/// on GitHub, which only your own pull request's review has, and `opens` offers opening the
|
||||
/// branch's pull request, which only a branch without one has.
|
||||
pub(in crate::guided_review) fn next(
|
||||
self,
|
||||
forward: bool,
|
||||
answers: bool,
|
||||
opens: bool,
|
||||
stacks: bool,
|
||||
) -> Self {
|
||||
const ORDER: [FinishReviewChoice; 8] = [
|
||||
FinishReviewChoice::Accept,
|
||||
FinishReviewChoice::AcceptAndCommit,
|
||||
FinishReviewChoice::RequestFixes,
|
||||
FinishReviewChoice::CommentOnly,
|
||||
FinishReviewChoice::AnswerOnGitHub,
|
||||
FinishReviewChoice::OpenPullRequest,
|
||||
FinishReviewChoice::OpenStack,
|
||||
FinishReviewChoice::Cancel,
|
||||
];
|
||||
let order: Vec<FinishReviewChoice> = ORDER
|
||||
.into_iter()
|
||||
.filter(|choice| answers || *choice != FinishReviewChoice::AnswerOnGitHub)
|
||||
.filter(|choice| opens || *choice != FinishReviewChoice::OpenPullRequest)
|
||||
.filter(|choice| stacks || *choice != FinishReviewChoice::OpenStack)
|
||||
.collect();
|
||||
let index = order.iter().position(|choice| *choice == self).unwrap_or(0);
|
||||
let next = if forward {
|
||||
(index + 1) % order.len()
|
||||
} else {
|
||||
index.checked_sub(1).unwrap_or(order.len() - 1)
|
||||
};
|
||||
order[next]
|
||||
}
|
||||
}
|
||||
91
crates/luxe-tui/src/guided_review/state/post.rs
Normal file
91
crates/luxe-tui/src/guided_review/state/post.rs
Normal file
@@ -0,0 +1,91 @@
|
||||
//! Sending and posting — the send preview, and a review's post to GitHub with its verdict.
|
||||
|
||||
use luxe_core::guided_review::FindingId;
|
||||
|
||||
/// Which comments a pending send will carry, and what it records when it lands.
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub(crate) struct SendPreview {
|
||||
/// Comments excluded by the reviewer; everything else in the session ships.
|
||||
pub(crate) excluded: std::collections::HashSet<FindingId>,
|
||||
/// Row under the cursor.
|
||||
pub(crate) selected: usize,
|
||||
/// Outcome to record on send — `Some` only when the Finish dialog opened this.
|
||||
pub(crate) outcome: Option<luxe_core::guided_review::ReviewOutcome>,
|
||||
/// Mode pinned by the Finish dialog, else derived from what is included.
|
||||
pub(crate) mode: Option<luxe_core::guided_review::ReviewFeedbackMode>,
|
||||
}
|
||||
|
||||
/// A pull request's review on its way to GitHub.
|
||||
///
|
||||
/// Opens by asking GitHub what the preview needs, and stays modal until the post settles: closing
|
||||
/// it mid-post would drop the answer that marks the comments posted, and the next post would send
|
||||
/// them again.
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub(crate) struct GithubPost {
|
||||
/// The attempt in flight, so a late answer to an earlier one is ignored
|
||||
pub(crate) request_id: luxe_core::guided_review::PullRequestPostId,
|
||||
/// Verdict chosen
|
||||
pub(crate) verdict: luxe_core::github::ReviewEvent,
|
||||
/// What GitHub said about the pull request, once it has
|
||||
pub(crate) prepared: Option<PreparedPost>,
|
||||
/// Whether the post has been sent and not yet answered
|
||||
pub(crate) posting: bool,
|
||||
/// The last failure, as a sentence
|
||||
pub(crate) error: Option<String>,
|
||||
/// The item under the cursor: the review itself, then each line comment in order
|
||||
pub(crate) selected: usize,
|
||||
/// Rows the selected item's text is scrolled by
|
||||
pub(crate) scroll: u16,
|
||||
/// The summary the agent is drafting, by its request id
|
||||
pub(crate) drafting: Option<String>,
|
||||
/// When that draft was asked for, so the wait can count
|
||||
pub(crate) drafting_since: Option<std::time::Instant>,
|
||||
/// What the agent said beside the summary it drafted, read with it
|
||||
pub(crate) draft_note: Option<String>,
|
||||
}
|
||||
|
||||
/// What a post's preview needs from GitHub.
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub(crate) struct PreparedPost {
|
||||
/// GitHub's patches, which decide where each comment lands
|
||||
pub(crate) patches: Vec<luxe_core::github::FilePatch>,
|
||||
/// Whether the author pushed after the review was pinned
|
||||
pub(crate) head_moved: bool,
|
||||
/// Whether the reader opened the pull request, so only a comment is possible
|
||||
pub(crate) own_pull_request: bool,
|
||||
}
|
||||
|
||||
impl GithubPost {
|
||||
/// The verdicts GitHub will take from this reader, in the order the dialog lists them.
|
||||
pub(crate) fn verdicts(&self) -> &'static [luxe_core::github::ReviewEvent] {
|
||||
use luxe_core::github::ReviewEvent;
|
||||
if self.prepared.as_ref().is_some_and(|prepared| prepared.own_pull_request) {
|
||||
&[ReviewEvent::Comment]
|
||||
} else {
|
||||
&[ReviewEvent::Comment, ReviewEvent::Approve, ReviewEvent::RequestChanges]
|
||||
}
|
||||
}
|
||||
|
||||
/// Moves the cursor through `count` items, wrapping, and puts the new item's text at its top.
|
||||
pub(crate) fn move_selection(&mut self, forward: bool, count: usize) {
|
||||
if count == 0 {
|
||||
return;
|
||||
}
|
||||
let at = self.selected.min(count - 1);
|
||||
self.selected = if forward { (at + 1) % count } else { (at + count - 1) % count };
|
||||
self.scroll = 0;
|
||||
}
|
||||
|
||||
/// Scrolls the selected item's text; the render clamps it to what there is.
|
||||
pub(crate) fn scroll_by(&mut self, rows: i32) {
|
||||
self.scroll = u16::try_from((i32::from(self.scroll) + rows).max(0)).unwrap_or(u16::MAX);
|
||||
}
|
||||
|
||||
/// Steps the verdict through the ones on offer, wrapping.
|
||||
pub(crate) fn move_verdict(&mut self, forward: bool) {
|
||||
let verdicts = self.verdicts();
|
||||
let at = verdicts.iter().position(|verdict| *verdict == self.verdict).unwrap_or(0);
|
||||
let step = if forward { 1 } else { verdicts.len() - 1 };
|
||||
self.verdict = verdicts[(at + step) % verdicts.len()];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user