luxe 0.1.4: remembered models, wheel-driven lists, and a steadier phone app
- luxe starts on the model you last chose in this project, then the last one anywhere. Signing in opens the model picker instead of choosing for you. - Every list in a modal takes the mouse wheel and a draggable scrollbar. - The phone app shows reasoning in full, stays put while you read back through a long session, and shows a question's answer on its card. - On Windows, luxe update replaces the running luxe, and a signed-in install no longer sees setup again. - The file tree no longer shows "engine busy" in a large project, loop output is easier to follow, and the name is written lowercase. The CHANGELOG has the full list.
This commit is contained in:
@@ -8,7 +8,7 @@ mod permission_mode;
|
||||
pub(crate) use commands::*;
|
||||
pub(crate) use permission_mode::PermissionModeArg;
|
||||
|
||||
/// Luxe's command line. `--help` shows the crate description from `Cargo.toml`, not this doc.
|
||||
/// luxe's command line. `--help` shows the crate description from `Cargo.toml`, not this doc.
|
||||
#[derive(Parser, Debug)]
|
||||
#[command(name = "luxe", version, about)]
|
||||
pub(crate) struct Args {
|
||||
@@ -17,7 +17,7 @@ pub(crate) struct Args {
|
||||
pub(crate) headless: bool,
|
||||
|
||||
/// Speak the JSONL front-end protocol on stdio: wire actions in, events out. For editor
|
||||
/// plugins, alternative UIs, and anything driving Luxe as a session rather than a one-shot.
|
||||
/// plugins, alternative UIs, and anything driving luxe as a session rather than a one-shot.
|
||||
/// See `docs/guide/rpc.md`.
|
||||
#[arg(long, conflicts_with = "headless")]
|
||||
pub(crate) rpc: bool,
|
||||
@@ -279,7 +279,7 @@ impl Args {
|
||||
}
|
||||
}
|
||||
|
||||
/// Parse a `--thinking` level name into a `ThinkingLevel`, accepting the same spellings Luxe
|
||||
/// Parse a `--thinking` level name into a `ThinkingLevel`, accepting the same spellings luxe
|
||||
/// displays (`off`..`ultra`, plus `max` as an alias for `ultra`). Returns `None` for unknown input.
|
||||
pub(crate) fn parse_thinking_level(raw: &str) -> Option<luxe_core::provider::ThinkingLevel> {
|
||||
let name = raw.trim().to_ascii_lowercase();
|
||||
|
||||
@@ -7,13 +7,13 @@ use clap::{Parser, Subcommand};
|
||||
pub(crate) enum SubCommand {
|
||||
/// Sign in to a provider, check credentials, or sign out.
|
||||
Auth(AuthArgs),
|
||||
/// Read Luxe's user guide, for this version.
|
||||
/// Read luxe's user guide, for this version.
|
||||
Docs(DocsArgs),
|
||||
/// Check which language servers, debug adapters and tools work on this machine.
|
||||
Doctor,
|
||||
/// Set Luxe up: a theme, a provider, the tools and the start screen.
|
||||
/// Set luxe up: a theme, a provider, the tools and the start screen.
|
||||
Init(InitArgs),
|
||||
/// Join a session another Luxe on this machine is running, speaking the `--rpc` protocol on
|
||||
/// Join a session another luxe on this machine is running, speaking the `--rpc` protocol on
|
||||
/// stdin and stdout.
|
||||
Join(JoinArgs),
|
||||
/// Serve your sessions to your own phone or tablet, through Tailscale.
|
||||
@@ -27,7 +27,7 @@ pub(crate) enum SubCommand {
|
||||
Models(ModelsArgs),
|
||||
/// List this project's sessions.
|
||||
Sessions(SessionsArgs),
|
||||
/// Update Luxe with the command for however it was installed.
|
||||
/// Update luxe with the command for however it was installed.
|
||||
Update(UpdateArgs),
|
||||
/// Summarize a `LUXE_WIRE_LOG` capture.
|
||||
Wire(WireArgs),
|
||||
@@ -109,10 +109,10 @@ pub(crate) struct ModelsArgs {
|
||||
pub(crate) command: ModelsCommand,
|
||||
}
|
||||
|
||||
/// Models subcommand — what Luxe knows about a model, and where it learned it.
|
||||
/// Models subcommand — what luxe knows about a model, and where it learned it.
|
||||
#[derive(Subcommand, Debug)]
|
||||
pub(crate) enum ModelsCommand {
|
||||
/// List known models for the providers Luxe can route to.
|
||||
/// List known models for the providers luxe can route to.
|
||||
List {
|
||||
/// Only this provider.
|
||||
#[arg(long)]
|
||||
@@ -148,7 +148,7 @@ pub(crate) struct InitArgs {
|
||||
/// Join arguments.
|
||||
#[derive(Parser, Debug)]
|
||||
pub(crate) struct JoinArgs {
|
||||
/// The session: its id or the start of it, or the process id of the Luxe running it. Omit
|
||||
/// The session: its id or the start of it, or the process id of the luxe running it. Omit
|
||||
/// it to join the one running in this folder.
|
||||
pub(crate) target: Option<String>,
|
||||
/// List the sessions running on this machine that can be joined, and exit.
|
||||
|
||||
@@ -105,17 +105,11 @@ fn report_success(service: &ProviderAuth, outcome: &LoginOutcome) {
|
||||
field("models", note);
|
||||
}
|
||||
field("saved to", &luxe_core::paths::home_relative(&service.store_path()));
|
||||
if let Some(model) = &outcome.suggested_model {
|
||||
field("model", &format!("{model} {}", style::dim("(now the default)")));
|
||||
}
|
||||
// Advice sits apart from the summary: it's about what to do later, not what just happened.
|
||||
for advice in &outcome.advice {
|
||||
outln!("\n {}", style::dim(advice));
|
||||
}
|
||||
match outcome.suggested_model {
|
||||
Some(_) => outln!("\nRun `luxe` to start, or `/model` to pick another."),
|
||||
None => outln!("\nRun `luxe` to start, then `/model` to pick a model."),
|
||||
}
|
||||
outln!("\nRun `luxe` to start, then `/model` to pick a model.");
|
||||
}
|
||||
|
||||
/// `luxe auth list` — every provider and how it's configured.
|
||||
|
||||
@@ -172,7 +172,7 @@ async fn start_loop(
|
||||
event_rx,
|
||||
running_rx,
|
||||
kickoff,
|
||||
crate::loop_view::LoopView::new(quiet),
|
||||
crate::loop_view::LoopView::new(quiet, phase),
|
||||
)
|
||||
.await?;
|
||||
Ok(())
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
//!
|
||||
//! The guide ships in the binary, so it works offline and always describes the version installed:
|
||||
//! `scripts/guide-bundle.sh` writes every page of `docs/guide/` into `src/guide.md`, and this reads
|
||||
//! that bundle. The agent is told the command exists, so asking Luxe how to configure Luxe gets an
|
||||
//! that bundle. The agent is told the command exists, so asking luxe how to configure luxe gets an
|
||||
//! answer from the manual rather than a guess.
|
||||
|
||||
use crate::cli::args::DocsArgs;
|
||||
@@ -11,7 +11,7 @@ use crate::cli::args::DocsArgs;
|
||||
const BUNDLE: &str = include_str!("../guide.md");
|
||||
|
||||
/// The sidebar's groups, in reading order. `web/src/content.config.ts` holds the same list.
|
||||
const GROUPS: [&str; 5] = ["Get started", "Using Luxe", "Customize", "Extend", "Reference"];
|
||||
const GROUPS: [&str; 5] = ["Get started", "Using luxe", "Customize", "Extend", "Reference"];
|
||||
|
||||
/// The most lines `--search` prints, so a common word cannot flood a tool result.
|
||||
const SEARCH_LIMIT: usize = 40;
|
||||
@@ -74,7 +74,7 @@ pub(crate) fn run(args: &DocsArgs) -> anyhow::Result<()> {
|
||||
/// Every page, under its group, with its summary and how to read it.
|
||||
fn index(pages: &[Page]) -> String {
|
||||
let mut out = String::from(
|
||||
"Luxe's user guide, for this version. `luxe docs <page>` prints a page; \
|
||||
"luxe's user guide, for this version. `luxe docs <page>` prints a page; \
|
||||
`luxe docs --search <words>` finds lines across all of them.\n",
|
||||
);
|
||||
for group in GROUPS {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
//! `luxe doctor` — is the tooling on this machine actually going to work?
|
||||
//!
|
||||
//! Luxe launches language servers and debug adapters; it does not install them, and it does not
|
||||
//! luxe launches language servers and debug adapters; it does not install them, and it does not
|
||||
//! bundle them: installation would mean owning each language's package manager and update policy.
|
||||
//! A broken or absent one can otherwise stay invisible until a tool call comes back empty.
|
||||
//!
|
||||
@@ -63,7 +63,7 @@ async fn language_servers() {
|
||||
let configured: std::collections::HashSet<String> = user.keys().cloned().collect();
|
||||
for language in registry.merge_patches(user) {
|
||||
say(&format!(
|
||||
" FAIL {language:<12} lsp-servers.json gives no `command`, and Luxe ships none"
|
||||
" FAIL {language:<12} lsp-servers.json gives no `command`, and luxe ships none"
|
||||
));
|
||||
}
|
||||
let mut languages: Vec<(&String, &ServerEntry)> = registry.iter().collect();
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
//! `luxe join` — a session another Luxe is running, over stdin and stdout.
|
||||
//! `luxe join` — a session another luxe is running, over stdin and stdout.
|
||||
//!
|
||||
//! The running Luxe shares its session on a local endpoint (`cli::share`), and this command is the
|
||||
//! The running luxe shares its session on a local endpoint (`cli::share`), and this command is the
|
||||
//! plain way in: it picks the session from the records in the runtime folder, connects, and copies
|
||||
//! bytes both ways. What crosses is the `--rpc` protocol untouched, so a client written for
|
||||
//! `luxe --rpc` drives a joined session by launching `luxe join` instead.
|
||||
@@ -63,7 +63,7 @@ fn nothing_to_join(running: &[LiveSession], target: Option<&str>, cwd: &str) ->
|
||||
};
|
||||
if running.is_empty() {
|
||||
return format!(
|
||||
"{wanted}, and none is running on this machine that can be joined. A Luxe shares \
|
||||
"{wanted}, and none is running on this machine that can be joined. A luxe shares \
|
||||
its session unless `joinable` is off or LUXE_JOINABLE=0."
|
||||
);
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ fn sessions() -> Vec<LiveSession> {
|
||||
/// With no target, the session running in this folder is the one joined.
|
||||
///
|
||||
/// The break this catches: ignoring the folder, so `luxe join` in one project lands in another's
|
||||
/// session, or refuses because more than one Luxe is running somewhere.
|
||||
/// session, or refuses because more than one luxe is running somewhere.
|
||||
#[test]
|
||||
fn no_target_joins_the_session_running_here() {
|
||||
let all = sessions();
|
||||
@@ -39,7 +39,7 @@ fn two_sessions_in_the_folder_are_listed_not_guessed() {
|
||||
assert!(error.contains("aaab-2222") && error.contains("cccc-3333"), "{error}");
|
||||
}
|
||||
|
||||
/// A target names a session by the start of its id or by its Luxe's process id.
|
||||
/// A target names a session by the start of its id or by its luxe's process id.
|
||||
///
|
||||
/// The break this catches: matching the id exactly, so the short form the listing invites fails,
|
||||
/// or not accepting a pid, which is what `ps` and herdr show.
|
||||
@@ -62,7 +62,7 @@ fn an_ambiguous_or_empty_target_is_refused() {
|
||||
|
||||
/// Nothing to join says why, and how sharing is turned back on when nothing is running.
|
||||
///
|
||||
/// The break this catches: a bare "not found" when every Luxe has `joinable` off, which leaves the
|
||||
/// The break this catches: a bare "not found" when every luxe has `joinable` off, which leaves the
|
||||
/// reader with nothing to try.
|
||||
#[test]
|
||||
fn nothing_to_join_says_what_is_running() {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
//! `luxe models` — inspect and refresh the model catalog.
|
||||
//!
|
||||
//! Exists mostly for one question: *why does Luxe think my model has a 128k window?* `show`
|
||||
//! Exists mostly for one question: *why does luxe think my model has a 128k window?* `show`
|
||||
//! answers it directly by printing which layer won each field, so a stale cache, a missing
|
||||
//! provider mapping, and a forgotten config override are all distinguishable at a glance.
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ async fn serve(port: u16, allow: Vec<String>, devices: DeviceBook) -> anyhow::Re
|
||||
let logins = allowed_logins(tailnet, allow)?;
|
||||
let access = Access { logins: logins.clone(), devices };
|
||||
let bridge = bridge(port, access, machine).await?;
|
||||
outln!("Luxe remote is listening on http://{}. Ctrl-C stops it.", bridge.address());
|
||||
outln!("luxe remote is listening on http://{}. Ctrl-C stops it.", bridge.address());
|
||||
outln!("It lets in {}, from a paired device.", logins.join(", "));
|
||||
bridge
|
||||
.serve(async {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//! `luxe remote setup` — from nothing to a paired phone, asking before each step that changes
|
||||
//! something outside Luxe.
|
||||
//! something outside luxe.
|
||||
//!
|
||||
//! Four steps: Tailscale is there and signed in; Serve carries `https://<this machine>/` to the
|
||||
//! bridge; a user service runs the bridge at login; and an invitation to scan. Each step that is
|
||||
@@ -108,7 +108,7 @@ fn service_step(port: u16, tailnet: &Tailnet, allow: Vec<String>) {
|
||||
return;
|
||||
}
|
||||
if !confirm("Run the bridge whenever you're signed in, as a user service?") {
|
||||
outln!("Skipped. Run `luxe remote` yourself whenever your devices should reach Luxe.");
|
||||
outln!("Skipped. Run `luxe remote` yourself whenever your devices should reach luxe.");
|
||||
return;
|
||||
}
|
||||
let launch =
|
||||
|
||||
@@ -75,7 +75,7 @@ impl GithubWrites {
|
||||
match self {
|
||||
Self::Allowed => None,
|
||||
Self::NotEnabled => Some(format!(
|
||||
"{kind} publishes to GitHub, which this session does not allow: start Luxe with \
|
||||
"{kind} publishes to GitHub, which this session does not allow: start luxe with \
|
||||
--github-writes to let a client do that"
|
||||
)),
|
||||
Self::ReadOnly => Some(format!(
|
||||
@@ -151,7 +151,7 @@ fn session_refusal(wire: &WireAction, policy: &Policy) -> Option<String> {
|
||||
let switches = matches!(wire, WireAction::NewSession | WireAction::LoadSession(_));
|
||||
if policy.joined && switches {
|
||||
let reason = "would switch the session the terminal is showing: switch it there, or start \
|
||||
another Luxe";
|
||||
another luxe";
|
||||
return Some(format!("{kind} {reason}"));
|
||||
}
|
||||
None
|
||||
|
||||
@@ -447,7 +447,7 @@ fn github_writes_need_the_flag_and_read_only_refuses_them_anyway() {
|
||||
]
|
||||
};
|
||||
for (gate, needle) in [
|
||||
(GithubWrites::NotEnabled, "start Luxe with --github-writes"),
|
||||
(GithubWrites::NotEnabled, "start luxe with --github-writes"),
|
||||
(GithubWrites::ReadOnly, "read-only"),
|
||||
] {
|
||||
for wire in writes() {
|
||||
|
||||
@@ -11,7 +11,7 @@ fn footer_note(repo_root: &std::path::Path) -> Option<String> {
|
||||
crate::update_check::cached_notice(repo_root).map(|_| UPDATE_HINT.to_string())
|
||||
}
|
||||
|
||||
/// What the dashboard says when a newer Luxe exists.
|
||||
/// What the dashboard says when a newer luxe exists.
|
||||
const UPDATE_HINT: &str = "Update available · /update";
|
||||
|
||||
/// Whether the startup dashboard should be shown.
|
||||
@@ -295,7 +295,7 @@ async fn starting_status(
|
||||
/// mid-session shows up without relaunching. The probe is the same menu built after asking every
|
||||
/// connected local server what it is serving — a list that changes the moment somebody loads a
|
||||
/// model, and that only the endpoint knows. An Azure resource is the same question asked of a
|
||||
/// cloud: what is deployed there changes in a portal Luxe never sees. A server that is off leaves
|
||||
/// cloud: what is deployed there changes in a portal luxe never sees. A server that is off leaves
|
||||
/// the record standing.
|
||||
fn model_menu_sources(
|
||||
settings: &crate::engine_setup::AgentSettings,
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
//! `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
|
||||
//! 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.
|
||||
|
||||
@@ -10,6 +10,8 @@ use anyhow::{anyhow, bail, Context};
|
||||
use luxe_core::update::{self, InstallSource};
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
pub(crate) use aside::remove_leftover;
|
||||
|
||||
/// 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;
|
||||
@@ -17,50 +19,62 @@ pub(crate) async fn run(check_only: bool) -> anyhow::Result<()> {
|
||||
.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.");
|
||||
println!("luxe {current} is the newest release.");
|
||||
return Ok(());
|
||||
}
|
||||
println!("Luxe {latest} is available (you have {current}).");
|
||||
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)
|
||||
}
|
||||
(Some(steps), false) => update_with(steps, &latest).await,
|
||||
_ => {
|
||||
println!("{}", instructions(source, check_only, cfg!(windows)));
|
||||
println!("{}", instructions(source, check_only));
|
||||
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 {
|
||||
/// Runs the owner's steps over this copy, then checks the `luxe` a shell finds now.
|
||||
///
|
||||
/// Windows won't let a running program's file be overwritten, and `luxe update` is itself a
|
||||
/// running luxe. It does allow a rename, so the running copy steps aside first and the owner
|
||||
/// writes a new file where it was.
|
||||
async fn update_with(steps: &[&[&str]], latest: &str) -> anyhow::Result<()> {
|
||||
let exe = std::env::current_exe().context("could not find the running luxe")?;
|
||||
let aside = match cfg!(windows) {
|
||||
true => Some(aside::MovedAside::move_running(&exe)?),
|
||||
false => None,
|
||||
};
|
||||
let ran = run_steps(steps, exe.parent()).await;
|
||||
if let Some(aside) = &aside {
|
||||
aside.restore_if_missing()?;
|
||||
}
|
||||
ran?;
|
||||
report(installed_now(latest, &exe).await)
|
||||
}
|
||||
|
||||
/// What to tell a reader luxe will not run an update for: they asked only to check, or no owner's
|
||||
/// command is known.
|
||||
fn instructions(source: InstallSource, check_only: 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<()> {
|
||||
/// Runs each step in turn, the terminal attached, stopping at the first that fails. `beside` is
|
||||
/// the running binary's directory.
|
||||
async fn run_steps(steps: &[&[&str]], beside: Option<&Path>) -> anyhow::Result<()> {
|
||||
for step in steps {
|
||||
let Some((program, args)) = step.split_first() else { continue };
|
||||
let line = step.join(" ");
|
||||
println!("Running: {line}");
|
||||
let beside =
|
||||
std::env::current_exe().ok().and_then(|exe| exe.parent().map(Path::to_path_buf));
|
||||
let status = tokio::process::Command::new(program_path(program, beside.as_deref()))
|
||||
let status = tokio::process::Command::new(program_path(program, beside))
|
||||
.args(args)
|
||||
.status()
|
||||
.await
|
||||
.with_context(|| format!("could not start `{program}`"))?;
|
||||
if !status.success() {
|
||||
bail!("`{line}` failed ({status}), so Luxe is unchanged");
|
||||
bail!("`{line}` failed ({status}), so luxe is unchanged");
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
@@ -108,15 +122,15 @@ fn outcome(found: Option<&Path>, updated: &Path, reported: Option<&str>, latest:
|
||||
}
|
||||
}
|
||||
|
||||
/// The `luxe` a shell would run now, and the outcome it shows.
|
||||
async fn installed_now(latest: &str) -> Outcome {
|
||||
/// The `luxe` a shell would run now, and the outcome it shows. `updated` is where the running copy
|
||||
/// was, read before a Windows update moved it aside.
|
||||
async fn installed_now(latest: &str, updated: &Path) -> 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)
|
||||
outcome(found.as_deref(), updated, reported.as_deref(), latest)
|
||||
}
|
||||
|
||||
/// The version `path --version` prints, as `luxe 0.2.0`.
|
||||
@@ -150,5 +164,7 @@ fn report(outcome: Outcome) -> anyhow::Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
mod aside;
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
|
||||
118
crates/luxe-cli/src/cli/update_command/aside.rs
Normal file
118
crates/luxe-cli/src/cli/update_command/aside.rs
Normal file
@@ -0,0 +1,118 @@
|
||||
//! Moving the running copy aside — how `luxe update` gets out of its own way on Windows.
|
||||
//!
|
||||
//! Windows locks a running program's file against being overwritten or deleted, but not against
|
||||
//! being renamed. The running `luxe.exe` becomes `luxe.exe.old`, the owner's updater writes a new
|
||||
//! `luxe.exe`, and the next launch deletes the leftover once nothing is running from it. Nothing
|
||||
//! here writes a binary: it only renames the one that is already there.
|
||||
|
||||
use anyhow::Context;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
/// The running copy, renamed out of the way of the update.
|
||||
pub(super) struct MovedAside {
|
||||
from: PathBuf,
|
||||
to: PathBuf,
|
||||
}
|
||||
|
||||
impl MovedAside {
|
||||
/// Renames `exe` to its leftover name, clearing a leftover a previous update left behind.
|
||||
pub(super) fn move_running(exe: &Path) -> anyhow::Result<Self> {
|
||||
let to = leftover_path(exe);
|
||||
remove_if_present(&to).with_context(|| {
|
||||
format!("could not remove {}, left by an earlier update", to.display())
|
||||
})?;
|
||||
std::fs::rename(exe, &to).with_context(|| {
|
||||
format!("could not move the running {} aside to update it", exe.display())
|
||||
})?;
|
||||
Ok(Self { from: exe.to_path_buf(), to })
|
||||
}
|
||||
|
||||
/// Puts the running copy back when the update left nothing where it was, so a failed update
|
||||
/// never leaves the reader without a `luxe`.
|
||||
pub(super) fn restore_if_missing(&self) -> anyhow::Result<()> {
|
||||
if self.from.exists() {
|
||||
return Ok(());
|
||||
}
|
||||
std::fs::rename(&self.to, &self.from).with_context(|| {
|
||||
format!(
|
||||
"the update left no luxe behind and {} could not be moved back to {}",
|
||||
self.to.display(),
|
||||
self.from.display()
|
||||
)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/// Deletes the copy an earlier update moved aside, if there is one. Called at launch, when the
|
||||
/// old copy has exited. Still running elsewhere is normal (another session), so a failure is
|
||||
/// only logged and the next launch tries again.
|
||||
pub(crate) fn remove_leftover() {
|
||||
let Ok(exe) = std::env::current_exe() else { return };
|
||||
let leftover = leftover_path(&exe);
|
||||
if let Err(error) = remove_if_present(&leftover) {
|
||||
tracing::debug!(%error, path = %leftover.display(), "leftover from an update is still in use");
|
||||
}
|
||||
}
|
||||
|
||||
/// `luxe.exe` beside itself as `luxe.exe.old`.
|
||||
fn leftover_path(exe: &Path) -> PathBuf {
|
||||
let mut name = exe.file_name().unwrap_or_default().to_os_string();
|
||||
name.push(".old");
|
||||
exe.with_file_name(name)
|
||||
}
|
||||
|
||||
/// Removes `path`; already gone is success.
|
||||
fn remove_if_present(path: &Path) -> std::io::Result<()> {
|
||||
match std::fs::remove_file(path) {
|
||||
Err(error) if error.kind() == std::io::ErrorKind::NotFound => Ok(()),
|
||||
other => other,
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
fn installed() -> (tempfile::TempDir, PathBuf) {
|
||||
let dir = tempfile::tempdir().expect("tempdir");
|
||||
let exe = dir.path().join("luxe.exe");
|
||||
std::fs::write(&exe, b"old").expect("a stand-in binary");
|
||||
(dir, exe)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_leftover_sits_beside_the_binary() {
|
||||
assert_eq!(leftover_path(Path::new("/bin/luxe.exe")), PathBuf::from("/bin/luxe.exe.old"));
|
||||
}
|
||||
|
||||
/// The update writes a new file where the old one was, and the old one is left to delete.
|
||||
#[test]
|
||||
fn an_update_that_wrote_a_new_copy_keeps_it() {
|
||||
let (_dir, exe) = installed();
|
||||
let aside = MovedAside::move_running(&exe).expect("moved");
|
||||
assert!(!exe.exists(), "the name is free for the updater");
|
||||
std::fs::write(&exe, b"new").expect("the updater's copy");
|
||||
aside.restore_if_missing().expect("nothing to restore");
|
||||
assert_eq!(std::fs::read(&exe).expect("read"), b"new");
|
||||
assert_eq!(std::fs::read(leftover_path(&exe)).expect("read"), b"old");
|
||||
}
|
||||
|
||||
/// A failed update puts the running copy back rather than leaving no `luxe` at all.
|
||||
#[test]
|
||||
fn an_update_that_wrote_nothing_puts_the_old_copy_back() {
|
||||
let (_dir, exe) = installed();
|
||||
let aside = MovedAside::move_running(&exe).expect("moved");
|
||||
aside.restore_if_missing().expect("restored");
|
||||
assert_eq!(std::fs::read(&exe).expect("read"), b"old");
|
||||
assert!(!leftover_path(&exe).exists());
|
||||
}
|
||||
|
||||
/// A leftover from the last update is cleared, not a reason to refuse this one.
|
||||
#[test]
|
||||
fn a_leftover_from_last_time_is_replaced() {
|
||||
let (_dir, exe) = installed();
|
||||
std::fs::write(leftover_path(&exe), b"older").expect("a leftover");
|
||||
MovedAside::move_running(&exe).expect("moved");
|
||||
assert_eq!(std::fs::read(leftover_path(&exe)).expect("read"), b"old");
|
||||
}
|
||||
}
|
||||
@@ -69,13 +69,8 @@ fn no_luxe_on_path_or_no_version_cannot_be_judged() {
|
||||
/// 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);
|
||||
let check = instructions(InstallSource::Cargo, true);
|
||||
assert!(check.contains("luxe update") && check.contains("cargo install"), "{check}");
|
||||
let download = instructions(InstallSource::Archive, false, false);
|
||||
let download = instructions(InstallSource::Archive, 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}"
|
||||
);
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ const SECRET_PREFIXES: &[&str] = &["sk-", "sk_live_", "ghp_", "gho_", "xoxb-", "
|
||||
|
||||
/// Minimum run of key-shaped characters after a prefix before it counts as a credential.
|
||||
///
|
||||
/// Without this, reading Luxe's own `redact.rs` — whose source *contains* every prefix — reports a
|
||||
/// Without this, reading luxe's own `redact.rs` — whose source *contains* every prefix — reports a
|
||||
/// leak on every audit. The prefix alone is prose; the prefix plus a key is a secret.
|
||||
const SECRET_BODY: usize = 16;
|
||||
|
||||
|
||||
@@ -184,7 +184,7 @@ fn a_bold_label_outside_the_tools_section_is_not_a_duplicate() {
|
||||
|
||||
#[test]
|
||||
fn a_credential_prefix_in_prose_is_not_a_leak_but_a_real_key_is() {
|
||||
// Reading Luxe's own redact.rs puts every prefix in a tool result; that is not a leak.
|
||||
// Reading luxe's own redact.rs puts every prefix in a tool result; that is not a leak.
|
||||
assert!(looks_like_credential("patterns like sk- and ghp_ and AKIA").is_none());
|
||||
assert!(looks_like_credential("Authorization: Bearer short").is_none());
|
||||
let leak = looks_like_credential("key=sk-abcdefghijklmnopqrstuvwxyz0123")
|
||||
|
||||
@@ -248,7 +248,7 @@ pub(super) fn worktree_notice(
|
||||
)
|
||||
}
|
||||
|
||||
/// Leaves the session's worktree and removes it, saying how it went on the terminal Luxe has
|
||||
/// Leaves the session's worktree and removes it, saying how it went on the terminal luxe has
|
||||
/// just handed back.
|
||||
pub(super) async fn remove_worktree(project: &std::path::Path, path: &std::path::Path) {
|
||||
if let Err(error) = std::env::set_current_dir(project) {
|
||||
|
||||
Reference in New Issue
Block a user