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

@@ -185,6 +185,7 @@ impl Args {
| SubCommand::Init(_)
| SubCommand::Models(_)
| SubCommand::Sessions(_)
| SubCommand::Update(_)
| SubCommand::Wire(_),
) => false,
}
@@ -255,6 +256,7 @@ impl Args {
| SubCommand::Mcp(_)
| SubCommand::Models(_)
| SubCommand::Sessions(_)
| SubCommand::Update(_)
| SubCommand::Wire(_),
) => false,
}

View File

@@ -21,10 +21,20 @@ pub(crate) enum SubCommand {
Models(ModelsArgs),
/// List this project's sessions.
Sessions(SessionsArgs),
/// Update Luxe with the command for however it was installed.
Update(UpdateArgs),
/// Summarize a `LUXE_WIRE_LOG` capture.
Wire(WireArgs),
}
/// Update arguments.
#[derive(Parser, Debug)]
pub(crate) struct UpdateArgs {
/// Only say whether a newer release exists, and how to get it.
#[arg(long)]
pub(crate) check: bool,
}
/// Docs arguments.
#[derive(Parser, Debug)]
pub(crate) struct DocsArgs {

View File

@@ -5,11 +5,15 @@ use super::worktree::{
check_out_pull_request, enter_session_worktree, remove_worktree, take_up_issue_in_worktree,
};
/// The one line under the dashboard, or nothing.
/// The one line under the dashboard, or nothing: that an update exists, and how to take it. The
/// versions and the command wait for `/update`, where the reader decides.
fn footer_note(repo_root: &std::path::Path) -> Option<String> {
crate::update_check::cached_notice(repo_root).map(|notice| notice.line())
crate::update_check::cached_notice(repo_root).map(|_| UPDATE_HINT.to_string())
}
/// What the dashboard says when a newer Luxe exists.
const UPDATE_HINT: &str = "Update available · /update";
/// Whether the startup dashboard should be shown.
///
/// Suppressed when resuming, when the session already has its work — `--issue` or `--pr` said
@@ -151,6 +155,12 @@ impl Next<'_> {
remove_worktree(&self.settings.state_root, &path).await;
return Ok(Flow::Leave);
}
TuiExit::Update => {
// The terminal is the reader's again, so the package manager's output reaches them
shutdown_workspace_services().await;
super::update_command::run(false).await?;
return Ok(Flow::Leave);
}
TuiExit::TakeUpIssue(number) => {
// A new session on the issue, in its worktree; the one left stays as it was
shutdown_workspace_services().await;
@@ -342,3 +352,28 @@ pub(super) async fn shutdown_workspace_services() {
tracing::warn!("workspace service shutdown timed out; relying on kill-on-drop reaping");
}
}
#[cfg(test)]
mod tests {
use luxe_core::update::UpdateState;
/// The start screen says only that an update exists and how to take it, and nothing when it
/// does not; the versions and the command wait for `/update`.
///
/// Mutates the environment, which nextest makes safe by giving each test its own process.
#[test]
fn the_footer_says_an_update_is_available_and_how() {
let dir = tempfile::tempdir().expect("tempdir");
let cache = dir.path().join("update.json");
std::env::set_var("LUXE_UPDATE_PATH", &cache);
std::env::set_var("LUXE_UPDATE_CHECK", "1");
let now = std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH).unwrap();
for (latest, footer) in [("99.0.0", Some("Update available · /update")), ("0.0.1", None)] {
let state = UpdateState { latest: Some(latest.into()), checked_at: now.as_secs() };
state.store(&cache).expect("store");
assert_eq!(super::footer_note(dir.path()).as_deref(), footer, "{latest}");
}
std::env::remove_var("LUXE_UPDATE_PATH");
std::env::remove_var("LUXE_UPDATE_CHECK");
}
}

View File

@@ -0,0 +1,142 @@
//! `luxe update` — run the update this install's owner provides, then check that it took.
//!
//! The policy is [`luxe_core::update`]'s: which owner installed this copy, which commands update
//! it, and a refusal where Luxe cannot know them. This runs those commands one program at a time
//! with the terminal attached, so the reader sees the package manager's own output, and Luxe never
//! writes a binary itself. `/update` on the dashboard comes here too, once the TUI has handed the
//! terminal back.
use anyhow::{anyhow, bail, Context};
use luxe_core::update::{self, InstallSource};
use std::path::{Path, PathBuf};
/// Checks for a newer release now and, unless `check_only`, runs the update and checks the result.
pub(crate) async fn run(check_only: bool) -> anyhow::Result<()> {
let current = luxe_core::version::VERSION;
let latest = crate::update_check::check_now()
.await
.map_err(|error| anyhow!("could not check for a newer release: {error}"))?;
if !update::is_newer(&latest, current) {
println!("Luxe {current} is the newest release.");
return Ok(());
}
println!("Luxe {latest} is available (you have {current}).");
let source = InstallSource::detect();
match (source.update_steps(), check_only) {
(Some(steps), false) if !cfg!(windows) => {
run_steps(steps).await?;
report(installed_now(&latest).await)
}
_ => {
println!("{}", instructions(source, check_only, cfg!(windows)));
Ok(())
}
}
}
/// What to tell a reader Luxe will not run an update for: they asked only to check, Windows cannot
/// replace the running program, or no owner's command is known.
fn instructions(source: InstallSource, check_only: bool, windows: bool) -> String {
match source.update_command() {
Some(command) if !check_only && windows => format!(
"Windows can't replace Luxe while it runs, so run this once it has exited: {command}"
),
Some(_) if check_only => format!("Run `luxe update`, or {}.", source.advice()),
_ => format!("To update: {}.", source.advice()),
}
}
/// Runs each step in turn, the terminal attached, stopping at the first that fails.
async fn run_steps(steps: &[&[&str]]) -> anyhow::Result<()> {
for step in steps {
let Some((program, args)) = step.split_first() else { continue };
let line = step.join(" ");
println!("Running: {line}");
let status = tokio::process::Command::new(program)
.args(args)
.status()
.await
.with_context(|| format!("could not start `{program}`"))?;
if !status.success() {
bail!("`{line}` failed ({status}), so Luxe is unchanged");
}
}
Ok(())
}
/// How the update landed, read from the `luxe` a shell would run now.
#[derive(Debug, PartialEq, Eq)]
enum Outcome {
/// It reports the new version
Updated,
/// `PATH` finds another copy first: the update went to one file and the shell runs another
Shadowed { found: PathBuf, updated: PathBuf },
/// The same copy still reports an older version: the package did not have the release yet
NotYet { reported: String },
/// No `luxe` on `PATH`, or none that says its version
Unknown,
}
/// Judges the result from what was found on `PATH`, the copy that ran the update, what the found
/// one reports, and the version the update was for.
fn outcome(found: Option<&Path>, updated: &Path, reported: Option<&str>, latest: &str) -> Outcome {
let Some(found) = found else { return Outcome::Unknown };
if reported.is_some_and(|reported| !update::is_newer(latest, reported)) {
return Outcome::Updated;
}
let same = |a: &Path, b: &Path| {
a.canonicalize().ok().zip(b.canonicalize().ok()).is_some_and(|(a, b)| a == b)
};
if !same(found, updated) {
return Outcome::Shadowed { found: found.to_path_buf(), updated: updated.to_path_buf() };
}
match reported {
Some(reported) => Outcome::NotYet { reported: reported.to_string() },
None => Outcome::Unknown,
}
}
/// The `luxe` a shell would run now, and the outcome it shows.
async fn installed_now(latest: &str) -> Outcome {
let found = luxe_core::program::resolve("luxe");
let reported = match &found {
Some(path) => version_of(path).await,
None => None,
};
let updated = std::env::current_exe().unwrap_or_default();
outcome(found.as_deref(), &updated, reported.as_deref(), latest)
}
/// The version `path --version` prints, as `luxe 0.2.0`.
async fn version_of(path: &Path) -> Option<String> {
let output = tokio::process::Command::new(path).arg("--version").output().await.ok()?;
parse_version(&String::from_utf8_lossy(&output.stdout))
}
/// The version in `--version` output: its last word, when that is semver.
fn parse_version(output: &str) -> Option<String> {
let word = update::normalize_version(output.split_whitespace().last()?);
semver::Version::parse(word).is_ok().then(|| word.to_string())
}
/// Says how it went; an update that did not take effect is an error, so a script can tell.
fn report(outcome: Outcome) -> anyhow::Result<()> {
match outcome {
Outcome::Updated => println!("Updated. Start the new version with `luxe`."),
Outcome::Unknown => println!("The update finished. `luxe --version` will confirm it."),
Outcome::Shadowed { found, updated } => bail!(
"the update went to {}, but `luxe` on your PATH is {}; remove that copy, or put the \
updated one's directory first on PATH",
updated.display(),
found.display()
),
Outcome::NotYet { reported } => bail!(
"the update finished, but `luxe --version` still says {reported}; the new release may \
not have reached your package manager yet, so try again in a while"
),
}
Ok(())
}
#[cfg(test)]
mod tests;

View File

@@ -0,0 +1,69 @@
use super::*;
/// Two files in a temporary directory: the copy the update ran from, and another.
fn copies() -> (tempfile::TempDir, PathBuf, PathBuf) {
let dir = tempfile::tempdir().expect("tempdir");
let updated = dir.path().join("updated-luxe");
let other = dir.path().join("other-luxe");
for path in [&updated, &other] {
std::fs::write(path, b"").expect("a stand-in binary");
}
(dir, updated, other)
}
#[test]
fn the_version_is_the_last_word_when_it_is_semver() {
assert_eq!(parse_version("luxe 0.2.0\n").as_deref(), Some("0.2.0"));
assert_eq!(parse_version("luxe v0.2.0").as_deref(), Some("0.2.0"));
assert_eq!(parse_version("luxe nightly"), None);
assert_eq!(parse_version(""), None);
}
/// The new version reported, or one past it, is a finished update.
#[test]
fn a_copy_reporting_the_new_version_is_updated() {
let (_dir, updated, _) = copies();
assert_eq!(outcome(Some(&updated), &updated, Some("0.2.0"), "0.2.0"), Outcome::Updated);
assert_eq!(outcome(Some(&updated), &updated, Some("0.2.1"), "0.2.0"), Outcome::Updated);
}
/// The loop Codex CLI's users hit: the update lands in one file and the shell runs another.
#[test]
fn another_copy_first_on_path_is_named() {
let (_dir, updated, other) = copies();
let shadowed = outcome(Some(&other), &updated, Some("0.1.0"), "0.2.0");
assert_eq!(shadowed, Outcome::Shadowed { found: other, updated });
}
/// A symlink to the copy that updated is that copy, as the development install's is, so an old
/// version there means the package was behind, not that a second copy is in the way.
#[cfg(unix)]
#[test]
fn a_link_to_the_updated_copy_is_the_same_copy() {
let (dir, updated, _) = copies();
let link = dir.path().join("luxe");
std::os::unix::fs::symlink(&updated, &link).expect("symlink");
let behind = outcome(Some(&link), &updated, Some("0.1.0"), "0.2.0");
assert_eq!(behind, Outcome::NotYet { reported: "0.1.0".into() });
}
#[test]
fn no_luxe_on_path_or_no_version_cannot_be_judged() {
let (_dir, updated, _) = copies();
assert_eq!(outcome(None, &updated, None, "0.2.0"), Outcome::Unknown);
assert_eq!(outcome(Some(&updated), &updated, None, "0.2.0"), Outcome::Unknown);
}
/// Only the reader's own command is ever named, and a check offers `luxe update` beside it.
#[test]
fn the_instructions_name_the_owners_command_or_none() {
let check = instructions(InstallSource::Cargo, true, false);
assert!(check.contains("luxe update") && check.contains("cargo install"), "{check}");
let download = instructions(InstallSource::Archive, false, false);
assert!(download.contains("download it from"), "{download}");
let windows = instructions(InstallSource::Cargo, false, true);
assert!(
windows.contains("once it has exited") && windows.contains("cargo install"),
"{windows}"
);
}