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,68 @@
//! Coverage — what a review leaves out, said where the reader starts.
//!
//! Counted, never silent: a review that shows less than the diff has to say so, whether a project
//! asked for the omission or the capture could not hold a file.
use luxe_core::guided_review::GuidedReview;
use ratatui::text::{Line, Span};
use crate::theme::styles::ThemeStyles;
/// The rows saying what this review does not show, in the order they matter.
pub(super) fn coverage_lines(review: &GuidedReview, styles: &ThemeStyles) -> Vec<Line<'static>> {
let mut lines = Vec::new();
if let Some(uncovered) = uncovered_note(review) {
lines.push(Line::from(Span::styled(uncovered, styles.warning)));
}
if review.stats.excluded_files > 0 {
lines.push(Line::from(Span::styled(
format!(
"{} {} excluded by review.exclude",
review.stats.excluded_files,
if review.stats.excluded_files == 1 { "file" } else { "files" }
),
styles.dim,
)));
}
lines
}
/// Names the changed files the capture could not include, a few of them, so a clean review of the
/// rest never reads as a clean review of everything.
fn uncovered_note(review: &GuidedReview) -> Option<String> {
const NAMED: usize = 3;
let paths = &review.source.uncovered_paths;
if paths.is_empty() {
return None;
}
let named: Vec<String> =
paths.iter().take(NAMED).map(|path| luxe_core::paths::display(path)).collect();
let more = match paths.len().saturating_sub(NAMED) {
0 => String::new(),
rest => format!(" and {rest} more"),
};
Some(format!(
"Changed but not shown, too large or not a readable file: {}{more}",
named.join(", ")
))
}
#[cfg(test)]
mod tests {
use super::*;
/// A review missing files names them, a few at a time, and a complete one says nothing.
#[test]
fn a_review_says_which_files_it_could_not_cover() {
let mut review = crate::fixture::fixture_demo_guided_review();
assert_eq!(uncovered_note(&review), None);
review.source.uncovered_paths = vec!["docs/big.md".into()];
let note = uncovered_note(&review).expect("said");
assert!(note.ends_with(": docs/big.md"), "{note}");
review.source.uncovered_paths = ["a", "b", "c", "d", "e"].map(Into::into).to_vec();
let note = uncovered_note(&review).expect("said");
assert!(note.ends_with(": a, b, c and 2 more"), "{note}");
}
}

View File

@@ -0,0 +1,163 @@
//! Brief files — which chapter owns each file, and the file rows the brief lists.
use super::super::context::review_file_status_style;
use crate::app::App;
use luxe_core::guided_review::{
Accounted, FileId, GuidedReview, HunkId, ItemVerdict, ReviewChapter, ReviewFile, ReviewHunk,
ReviewItemRef,
};
use ratatui::text::{Line, Span};
use std::collections::HashMap;
/// Which file owns each id a chapter can reference.
///
/// A chapter names files and hunks by id, and resolving one by scanning every file's every hunk
/// is quadratic in the review — a forty-file change spent a few hundred thousand comparisons a
/// frame answering the same question. Built once per pass and asked per item.
pub(crate) struct FileOwners<'a> {
by_file: HashMap<&'a FileId, &'a ReviewFile>,
by_hunk: HashMap<&'a HunkId, &'a ReviewFile>,
}
impl<'a> FileOwners<'a> {
/// Indexes every file and hunk in `review`.
pub(crate) fn of(review: &'a GuidedReview) -> Self {
let mut by_file = HashMap::with_capacity(review.files.len());
let mut by_hunk = HashMap::new();
for file in &review.files {
by_file.insert(&file.id, file);
for hunk in &file.hunks {
by_hunk.insert(&hunk.id, file);
}
}
Self { by_file, by_hunk }
}
/// The file one chapter item lives in.
fn owner(&self, item: &ReviewItemRef) -> Option<&'a ReviewFile> {
match item {
ReviewItemRef::File(file_id) => self.by_file.get(file_id).copied(),
ReviewItemRef::Hunk(hunk_id) => self.by_hunk.get(hunk_id).copied(),
}
}
/// The files a chapter owns, in the order it lists them.
///
/// A chapter references hunks as often as whole files, so a hunk resolves to the file that
/// holds it and repeats are dropped — otherwise a chapter that touches one file six times
/// lists it six times.
pub(crate) fn chapter_files(&self, chapter: &ReviewChapter) -> Vec<&'a ReviewFile> {
let mut files: Vec<&ReviewFile> = Vec::new();
for item in &chapter.items {
if let Some(file) = self.owner(item) {
if !files.iter().any(|seen| seen.id == file.id) {
files.push(file);
}
}
}
files
}
}
/// One file under its chapter: status, path, its share of the change, and why it is accounted for.
pub(in crate::view::guided_review) fn file_line(
app: &App,
file: &ReviewFile,
selected: bool,
width: usize,
) -> Line<'static> {
use luxe_core::guided_review::ReviewFileStatus as Status;
let styles = &app.theme_styles;
let letter = match file.status {
Status::Added => "A",
Status::Modified => "M",
Status::Deleted => "D",
Status::Renamed => "R",
Status::Copied => "C",
Status::Untracked => "?",
};
let path = file
.new_path
.as_deref()
.or(file.old_path.as_deref())
.map_or_else(|| "(unknown path)".to_owned(), |path| path.display().to_string());
// The path is elided from the left where it must be: the basename is what identifies a file,
// and a pane sized for prose has little room for the rest.
let shown = crate::widgets::elide_path_components(
&path,
width.saturating_sub(FILE_ROW_LEAN + crate::widgets::SELECTION_FRAME + 14).max(8),
);
let mut spans = vec![
Span::styled(format!("{letter} "), review_file_status_style(file.status, app)),
Span::styled(shown, styles.text),
];
spans.extend(change_spans(app, file, &file.hunks.iter().collect::<Vec<_>>()));
// One reason, said once, when it covers the whole file. Repeating it per hunk was how a
// forty-file listing turned into four hundred identical claims.
if let Some(reason) = shared_reason(app, file) {
spans.push(Span::styled(
format!(" {reason}"),
if selected { styles.muted } else { styles.dim },
));
}
// Attention rides on the file it belongs to, where the decision to open it is made — but not
// on the file being read, where the detail pane is already spelling the same concern out in a
// sentence beside its code. A badge there is the warning said twice in two widths.
let mut flags = app.review.flags.iter().filter(|_| !selected);
if let Some(signal) = flags.find(|signal| signal.path.as_deref() == Some(path.as_str())) {
spans.push(Span::styled(format!(" {}", signal.kind.badge()), styles.warning));
}
// Cut from the slab that means *chosen* everywhere else, over the pane's own fill rather than
// the color behind it. The frame is spent on every row, which is what indents the list under
// the chapter that owns it and stops names sliding sideways as the cursor arrives.
crate::widgets::selection_row_on(
spans,
// The lean is spent *outside* the slab, so the room it gets is what is left after it.
width.saturating_sub(FILE_ROW_LEAN),
FILE_ROW_LEAN,
selected,
styles.tool_bg.bg.unwrap_or(styles.slab.canvas),
styles,
)
}
/// Cells a file row leans in under the chapter heading that owns it.
const FILE_ROW_LEAN: usize = 2;
/// The one thing that accounts for *every* hunk in this file, when there is one.
fn shared_reason(app: &App, file: &ReviewFile) -> Option<String> {
let mut reasons =
file.hunks.iter().map(|hunk| match app.review.budget.hunk_verdict(&hunk.id) {
ItemVerdict::Accounted(accounted) => Some(accounted),
ItemVerdict::NeedsReview => None,
});
let first: Accounted = reasons.next()??;
reasons.all(|reason| reason.as_ref() == Some(&first)).then(|| format!("all {}", first.label()))
}
/// `+12 −3` for a text file, or what the change actually was for one with no lines to count.
fn change_spans(app: &App, file: &ReviewFile, owned: &[&ReviewHunk]) -> Vec<Span<'static>> {
let styles = &app.theme_styles;
if let Some(change) = file.non_text.as_ref() {
return vec![Span::styled(format!(" {}", change.summary), styles.muted)];
}
// Git's own figures where it gave them, so the guide and the dock agree about the same file.
// Summing the visible hunks would report the *shown* change, which is a different number the
// moment anything is folded.
let (additions, deletions) = match (file.additions, file.deletions) {
(Some(additions), Some(deletions)) => (additions as usize, deletions as usize),
_ if owned.is_empty() => return Vec::new(),
_ => owned.iter().flat_map(|hunk| hunk.lines.iter()).fold(
(0usize, 0usize),
|(add, del), line| match line.kind {
luxe_core::guided_review::ReviewLineKind::Addition => (add + 1, del),
luxe_core::guided_review::ReviewLineKind::Deletion => (add, del + 1),
_ => (add, del),
},
),
};
vec![
Span::styled(format!(" +{additions}"), styles.success),
Span::styled(format!(" \u{2212}{deletions}"), styles.error),
]
}

View File

@@ -0,0 +1,120 @@
//! Brief notices — where the work came from and what needs the reader's attention.
//!
//! Facts about the review that are worth a row only when they are *bad*. Inside a labeled section
//! that ran whether or not it had anything to say, the one row that mattered would be buried in
//! filler. Here they are silent by default, and each one is a sentence a reviewer would want
//! interrupting them.
use super::{coverage, LARGE_REVIEW_JUDGEMENT_ITEMS};
use crate::app::App;
use luxe_core::guided_review::{AttentionSignal, GuidedReview};
use ratatui::style::Style;
use ratatui::text::{Line, Span};
/// What this review will not tell you unless it is told to, in the order it matters.
///
/// Bounded by construction rather than by a cap: every entry is conditional and rare, and the
/// aggregate harness signals — the only unbounded source — contribute at most one row a kind.
pub(in crate::view::guided_review) fn notice_lines(
app: &App,
review: &GuidedReview,
) -> Vec<Line<'static>> {
let styles = &app.theme_styles;
let mut lines: Vec<Line<'static>> = Vec::new();
if let Some(warning) = unverified_note(review) {
lines.push(Line::from(Span::styled(warning, styles.warning)));
}
// A review this size is not one sitting. Name the smaller unit rather than letting the
// reviewer discover the problem forty hunks in.
if app.review.budget.needs_review > LARGE_REVIEW_JUDGEMENT_ITEMS {
lines.push(Line::from(Span::styled(
"More than one sitting · s picks a smaller source",
styles.warning,
)));
}
// Say why the budget could not help, rather than presenting a wall of work as if that were the
// reviewer's problem. A pull request was written somewhere else, which its reader knows.
if review.context.pull_request.is_none()
&& app.review.budget.needs_review > 0
&& no_provenance(review)
{
lines
.push(Line::from(Span::styled("No record of the work behind this source", styles.dim)));
}
lines.extend(coverage::coverage_lines(review, styles));
// A kind past its cap gets its total, one row each. Every flagged file wears its own badge in
// the contents, so the call-outs' "2 more" would read as two hidden somewhere.
for signal in app.review.attention.iter().filter(|signal| signal.aggregate) {
let total = flagged_total(app, signal.kind);
let said = format!("{total} {}", signal.kind.plural());
lines.push(Line::from(Span::styled(said, attention_style(app, signal))));
}
// What this session did elsewhere is a fact about the session, and a pull request is not it
if let Some(outside) = work_done_outside(app).filter(|_| review.context.pull_request.is_none())
{
// `info`, not a warning: this is a fact about what the review's source is, not a suspicion
// about the change inside it.
lines.push(Line::from(Span::styled(outside, styles.info)));
}
lines
}
/// What the harness knows about whether anything was run, said only when the answer is unwelcome.
///
/// Silent when a command ran after the last edit, because "the tests passed" is the expected state
/// and a row that always renders stops being read. Silent too when there is nothing to judge it
/// against — a `base` or `commit` review has no turn behind it, so it is not *unverified*, it is
/// simply not that kind of source.
fn unverified_note(review: &GuidedReview) -> Option<&'static str> {
let provenance = review.provenance.as_ref()?;
if provenance.written_paths.is_empty() {
return None;
}
if provenance.commands.is_empty() {
Some("No command was run in this work")
} else if !provenance.verified_after_last_edit {
Some("Nothing ran after the last edit")
} else {
None
}
}
/// What this session changed outside the project, or `None` when it stayed inside.
///
/// A review is captured from the project's worktree, so those files are not in it and no amount of
/// reading the diff will reveal them. Saying so is the difference between a review that is
/// *scoped* and one that quietly claims to be the whole session.
fn work_done_outside(app: &App) -> Option<String> {
let external = &app.workspace.as_ref()?.external;
if external.is_empty() {
return None;
}
let files = external.total_files;
Some(format!(
"{files} {} changed elsewhere this session",
if files == 1 { "file" } else { "files" }
))
}
/// Whether the review has no record of the work that produced it (a base/commit review, or a
/// working tree Luxe did not write).
fn no_provenance(review: &GuidedReview) -> bool {
review.provenance.as_ref().is_none_or(|provenance| {
provenance.commands.is_empty() && provenance.written_paths.is_empty()
})
}
/// Color by urgency: a possible credential or a weakened gate outranks an unread edit.
fn attention_style(app: &App, signal: &AttentionSignal) -> Style {
use luxe_core::guided_review::AttentionKind;
match signal.kind {
AttentionKind::SecretShaped | AttentionKind::GateWeakened => app.theme_styles.error,
AttentionKind::BlindEdit => app.theme_styles.warning,
}
}
/// How many lines or files of `kind` the review flags: a credential or a weakened gate is a line,
/// an unread edit a file.
fn flagged_total(app: &App, kind: luxe_core::guided_review::AttentionKind) -> usize {
app.review.flags.iter().filter(|flag| flag.kind == kind).count()
}

View File

@@ -0,0 +1,343 @@
//! Brief pull request — what the author said, the facts about the pull request, and the conversation
//! before this review.
use super::super::diff_render::{display_author, is_feedback, thread_is_feedback};
use super::{bullet_lines, prose_lines};
use crate::app::App;
use ratatui::style::Style;
use ratatui::text::{Line, Span};
/// One row of facts about a pull request: who opened it, and where it stands.
///
/// Drawn in the pane's fixed head under the row that names the pull request, so it is on screen
/// however far the guide has scrolled. Every fact is a word, colored only for emphasis: `draft`,
/// `2 failing`, `changes requested`.
pub(in crate::view::guided_review) fn pull_request_facts(
app: &App,
pr: &luxe_core::guided_review::PullRequestContext,
width: usize,
) -> Vec<Line<'static>> {
use luxe_core::guided_review::{PullRequestStatus, PullRequestVerdict};
let styles = &app.theme_styles;
let separator = || Span::styled(" \u{b7} ", styles.dim);
let mut spans = vec![Span::styled(
match pr.author_is_bot {
true => format!("by {} (bot)", pr.author_name()),
false => format!("by {}", pr.author_name()),
},
styles.text,
)];
let mut fact = |text: String, style: Style| {
spans.push(separator());
spans.push(Span::styled(text, style));
};
if pr.draft {
fact("draft".into(), styles.warning);
}
match pr.status {
PullRequestStatus::Open => {}
PullRequestStatus::Merged => fact("merged".into(), styles.success),
PullRequestStatus::Closed => fact("closed".into(), styles.dim),
}
let checks = pr.checks;
if checks.passed + checks.failed + checks.pending + checks.skipped > 0 {
let mut parts = Vec::new();
if checks.failed > 0 {
parts.push((format!("{} failing", checks.failed), styles.error));
}
if checks.pending > 0 {
parts.push((format!("{} running", checks.pending), styles.warning));
}
if checks.passed > 0 {
let noun = if checks.passed == 1 { "check" } else { "checks" };
parts.push((format!("{} {noun} passed", checks.passed), styles.dim));
}
for (text, style) in parts {
fact(text, style);
}
}
match pr.verdict {
Some(PullRequestVerdict::Approved) => fact("approved".into(), styles.success),
Some(PullRequestVerdict::ChangesRequested) => {
fact("changes requested".into(), styles.warning)
}
Some(PullRequestVerdict::ReviewRequired) => fact("review required".into(), styles.dim),
None => {}
}
crate::widgets::wrap_line(&Line::from(spans), width.max(20))
}
/// The author's description and the issues it says it closes, each under its own heading.
pub(super) fn pull_request_account(
app: &App,
pr: &luxe_core::guided_review::PullRequestContext,
width: usize,
) -> Vec<Line<'static>> {
let styles = &app.theme_styles;
let mut lines = Vec::new();
lines.push(Line::default());
lines.push(Line::from(Span::styled("What the pull request says", styles.accent)));
lines.extend(prose_lines(&pr.title, app, width, " "));
lines.push(Line::from(Span::styled(
format!(" {} \u{2192} {}", pr.head_ref, pr.base_ref),
styles.dim,
)));
let (opening, more) = description_opening(&pr.body);
if opening.is_empty() {
lines.push(Line::from(Span::styled(" The author wrote no description.", styles.dim)));
} else {
lines.push(Line::default());
lines.extend(prose_lines(&opening, app, width, " "));
if more {
lines.push(Line::from(Span::styled(
" The rest of the description is on GitHub \u{b7} o",
styles.dim,
)));
}
}
if !pr.closing_issues.is_empty() {
lines.push(Line::default());
lines.push(Line::from(Span::styled("What it closes", styles.accent)));
for issue in &pr.closing_issues {
let reference = if issue.repository.eq_ignore_ascii_case(&pr.repository) {
format!("#{}", issue.number)
} else {
format!("{}#{}", issue.repository, issue.number)
};
let title = issue.title.as_deref().unwrap_or("could not be read");
lines.extend(bullet_lines(&format!("{reference} {title}"), app, width));
}
if pr.more_closing_issues > 0 {
lines.push(Line::from(Span::styled(
format!(" and {} more", pr.more_closing_issues),
styles.dim,
)));
}
}
lines
}
/// What reviewers already said: a count, then every thread that has no line to sit on.
///
/// Two kinds of thing live here, and GitHub keeps them apart the same way: a *thread* is a review
/// comment on the code, with replies and a resolved state; a *comment* is a post in the pull
/// request's conversation, on no line at all. The threads that do map are drawn under their lines
/// in the diff, so this lists only the rest — outdated, on a whole file, or on a line no hunk shows
/// — and never drops one. A conversation that could not be read says so, rather than looking like
/// one nobody started.
pub(super) fn earlier_conversation_lines(
app: &App,
conversation: &luxe_core::guided_review::EarlierConversation,
width: usize,
) -> Vec<Line<'static>> {
use luxe_core::guided_review::EarlierConversation;
let styles = &app.theme_styles;
let heading = || Line::from(Span::styled("Discussion on GitHub", styles.accent));
let (threads, more, said) = match conversation {
EarlierConversation::Unreadable => {
return vec![
Line::default(),
heading(),
Line::from(Span::styled(
" Could not be read from GitHub \u{b7} o opens the pull request",
styles.dim,
)),
];
}
EarlierConversation::Read { threads, more, said } => (threads, *more, said),
};
// Threads and comments that became feedback are listed there, not here
let as_feedback = threads.iter().filter(|thread| thread_is_feedback(app, thread)).count()
+ said.iter().filter(|entry| is_feedback(app, &entry.id)).count();
let threads: Vec<&luxe_core::guided_review::EarlierThread> =
threads.iter().filter(|thread| !thread_is_feedback(app, thread)).collect();
let said: Vec<&luxe_core::guided_review::ConversationEntry> =
said.iter().filter(|entry| !is_feedback(app, &entry.id)).collect();
if threads.is_empty() && more == 0 && as_feedback == 0 && said.is_empty() {
return Vec::new();
}
let parts = discussion_rollup(&threads, more, as_feedback, said.len());
let summary = format!(" {}", parts.join(" \u{b7} "));
let mut lines = vec![Line::default(), heading(), Line::from(Span::styled(summary, styles.dim))];
lines.extend(off_diff_thread_rows(app, &threads, width));
lines.extend(conversation_entry_rows(app, &said, width));
if more > 0 {
lines.push(Line::from(Span::styled(
format!(" {more} more on GitHub \u{b7} o"),
styles.dim,
)));
}
lines
}
/// The discussion's one-line count: what became feedback, the threads left and how many are
/// unresolved, and the comments in the conversation.
fn discussion_rollup(
threads: &[&luxe_core::guided_review::EarlierThread],
more: usize,
as_feedback: usize,
said: usize,
) -> Vec<String> {
let unresolved = threads.iter().filter(|thread| !thread.resolved).count();
let total = threads.len() + more;
let noun = if total == 1 { "thread" } else { "threads" };
let mut parts = Vec::new();
if as_feedback > 0 {
parts.push(format!("{as_feedback} in your feedback"));
if total > 0 {
parts.push(format!("{total} more {noun}"));
}
} else {
parts.push(format!("{total} {noun}"));
}
if total > 0 {
parts.push(format!("{unresolved} unresolved"));
}
// A conversation with no threads at all still says so, rather than counting zero of them
if total == 0 && as_feedback == 0 {
parts.clear();
}
match said {
0 => {}
1 => parts.push("1 comment".into()),
n => parts.push(format!("{n} comments")),
}
parts
}
/// The threads on code the diff no longer shows, each as where it is and how it opened.
fn off_diff_thread_rows(
app: &App,
threads: &[&luxe_core::guided_review::EarlierThread],
width: usize,
) -> Vec<Line<'static>> {
let styles = &app.theme_styles;
let mut lines = Vec::new();
for thread in threads.iter().filter(|thread| thread.anchor.is_none()) {
let mut place = vec![Span::styled(thread.path.clone(), styles.text)];
let mut facts = Vec::new();
match (thread.file_level, thread.line) {
(true, _) => facts.push("whole file".to_owned()),
(false, Some(line)) if !thread.outdated => {
place.push(Span::styled(format!(":{line}"), styles.text));
}
_ => {}
}
if thread.outdated {
facts.push("outdated".into());
}
if thread.resolved {
facts.push("resolved".into());
}
if !facts.is_empty() {
place.push(Span::styled(format!(" \u{b7} {}", facts.join(" \u{b7} ")), styles.dim));
}
let opening = thread.comments.first();
let author = opening.map_or_else(String::new, |comment| display_author(&comment.author));
let said = opening.and_then(|comment| comment.body.lines().next()).unwrap_or_default();
lines.extend(discussion_item(app, &author, place, said, width));
}
lines
}
/// The comments in the conversation itself, each as who said it and its first line.
fn conversation_entry_rows(
app: &App,
said: &[&luxe_core::guided_review::ConversationEntry],
width: usize,
) -> Vec<Line<'static>> {
let styles = &app.theme_styles;
let mut lines = Vec::new();
for entry in said {
let first = entry.body.lines().map(str::trim).find(|line| !line.is_empty());
let author = display_author(&entry.author);
let place = vec![Span::styled("in the conversation", styles.dim)];
lines.extend(discussion_item(app, &author, place, first.unwrap_or_default(), width));
}
lines
}
/// One entry of the discussion: who and where on one line, what they said under it.
///
/// Built from spans rather than handed to the markdown renderer with the path in backticks, because
/// the quote is a stranger's text and whatever markup it carries must stay text. The name wears the
/// secondary accent and the place the brightest ink, so a reader scanning the list finds both
/// without the quote competing for either.
fn discussion_item(
app: &App,
author: &str,
place: Vec<Span<'static>>,
said: &str,
width: usize,
) -> Vec<Line<'static>> {
let styles = &app.theme_styles;
let budget = width.saturating_sub(3).max(20);
let mut head = vec![
Span::styled(author.to_owned(), styles.accent_secondary),
Span::styled(" \u{b7} ", styles.dim),
];
head.extend(place);
let mut lines = Vec::new();
for (index, row) in crate::widgets::wrap_line(&Line::from(head), budget).into_iter().enumerate()
{
let lead =
if index == 0 { Span::styled(" \u{2022} ", styles.dim) } else { Span::raw(" ") };
let mut spans = vec![lead];
spans.extend(row.spans);
lines.push(Line::from(spans));
}
let said = said.trim();
if !said.is_empty() {
let quote = Line::from(Span::styled(said.to_owned(), styles.muted));
for row in crate::widgets::wrap_line(&quote, budget).into_iter().take(3) {
let mut spans = vec![Span::raw(" ")];
spans.extend(row.spans);
lines.push(Line::from(spans));
}
}
lines
}
/// Characters of a pull request's description the brief shows before pointing at GitHub.
const DESCRIPTION_OPENING_CHARS: usize = 600;
/// The first paragraphs of a description, and whether there is more.
///
/// The guide scrolls to keep the current chapter in view, so a long description in full pushes the
/// chapters down and opens the pane in the middle of someone's prose with its heading gone — which
/// the first real pull request did. The guide's prompt still gets all of it. Template headings and
/// a bare `Fixes #n` are skipped: the issues it closes have their own section.
pub(super) fn description_opening(body: &str) -> (String, bool) {
let paragraphs: Vec<&str> = body
.split("\n\n")
.map(str::trim)
.filter(|paragraph| !paragraph.is_empty())
.filter(|paragraph| !paragraph.starts_with('#') || paragraph.contains('\n'))
.filter(|paragraph| !is_closing_reference(paragraph))
.collect();
let mut opening = String::new();
let mut taken = 0;
for paragraph in &paragraphs {
if taken > 0
&& opening.chars().count() + paragraph.chars().count() > DESCRIPTION_OPENING_CHARS
{
break;
}
if taken > 0 {
opening.push_str("\n\n");
}
opening.push_str(paragraph);
taken += 1;
}
(opening, taken < paragraphs.len())
}
/// `Fixes #12`, `closes owner/repo#3`: a line GitHub reads as a link to an issue, and nothing more.
pub(super) fn is_closing_reference(paragraph: &str) -> bool {
let lower = paragraph.to_ascii_lowercase();
let Some((verb, reference)) = lower.split_once(char::is_whitespace) else { return false };
matches!(verb, "fixes" | "fix" | "closes" | "close" | "resolves" | "resolve")
&& reference.trim().contains('#')
&& !reference.trim().contains(char::is_whitespace)
}