Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5bcbc1c81f | ||
|
|
38297c2bf3 | ||
|
|
ac6f2ffaa5 |
Generated
+1
-1
@@ -21,7 +21,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "agent-manager"
|
||||
version = "1.0.0"
|
||||
version = "1.0.1"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"base64",
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "agent-manager"
|
||||
version = "1.0.0"
|
||||
version = "1.0.1"
|
||||
edition = "2021"
|
||||
description = "Manage local AI coding agents: list, install, start, stop, update — with automatic dependency handling and a YAML-driven catalog."
|
||||
license = "MIT"
|
||||
|
||||
@@ -4,7 +4,7 @@ use super::*;
|
||||
use crate::download;
|
||||
use anyhow::{anyhow, bail, Context, Result};
|
||||
use std::cmp::Ordering;
|
||||
use std::path::Path;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
pub fn run(app: &App, check: bool, to: Option<&Path>) -> Result<i32> {
|
||||
let Some(repo) = app.config.settings.self_update_repo.clone() else {
|
||||
@@ -51,19 +51,26 @@ pub fn run(app: &App, check: bool, to: Option<&Path>) -> Result<i32> {
|
||||
let current_exe = std::env::current_exe()?;
|
||||
let dest = to.map(|p| p.to_path_buf()).unwrap_or_else(|| current_exe.clone());
|
||||
let tmpdir = tempfile::tempdir()?;
|
||||
let tmp = tmpdir.path().join("am.new");
|
||||
let tmp = tmpdir.path().join("am.dl");
|
||||
download::download(&picked.url, &tmp, None, true)?;
|
||||
// Release assets are archives (zip on Windows, tar.gz elsewhere):
|
||||
// unpack them and locate the binary inside.
|
||||
let staged = if download::extract_archive(&tmp, tmpdir.path())? {
|
||||
find_binary(tmpdir.path())?
|
||||
} else {
|
||||
tmp
|
||||
};
|
||||
if dest == current_exe && cfg!(windows) {
|
||||
// The running executable is locked on Windows.
|
||||
let new_path = current_exe.with_extension("exe.new");
|
||||
std::fs::copy(&tmp, &new_path)
|
||||
std::fs::copy(&staged, &new_path)
|
||||
.with_context(|| format!("cannot write {}", new_path.display()))?;
|
||||
app.log.success(&format!(
|
||||
"downloaded {tag} to {} — replace the running binary manually",
|
||||
new_path.display()
|
||||
));
|
||||
} else {
|
||||
std::fs::copy(&tmp, &dest)
|
||||
std::fs::copy(&staged, &dest)
|
||||
.with_context(|| format!("cannot write {}", dest.display()))?;
|
||||
#[cfg(unix)]
|
||||
{
|
||||
@@ -79,3 +86,66 @@ pub fn run(app: &App, check: bool, to: Option<&Path>) -> Result<i32> {
|
||||
Ok(0)
|
||||
}
|
||||
}
|
||||
|
||||
/// Locate the binary inside an unpacked release archive.
|
||||
fn find_binary(dir: &Path) -> Result<PathBuf> {
|
||||
let mut entries: Vec<PathBuf> = Vec::new();
|
||||
collect_files(dir, &mut entries);
|
||||
if entries.is_empty() {
|
||||
bail!("no binary found in the release archive");
|
||||
}
|
||||
// Prefer a file named exactly `am` / `am.exe`, otherwise the largest
|
||||
// file (the archive only contains the binary).
|
||||
entries.sort_by_key(|p| {
|
||||
let name = p
|
||||
.file_name()
|
||||
.map(|n| n.to_string_lossy().to_lowercase())
|
||||
.unwrap_or_default();
|
||||
let prefer = name == "am" || name == "am.exe" || name.ends_with(".exe");
|
||||
(
|
||||
!prefer,
|
||||
std::cmp::Reverse(std::fs::metadata(p).map(|m| m.len()).unwrap_or(0)),
|
||||
)
|
||||
});
|
||||
Ok(entries.remove(0))
|
||||
}
|
||||
|
||||
fn collect_files(dir: &Path, out: &mut Vec<PathBuf>) {
|
||||
if let Ok(rd) = std::fs::read_dir(dir) {
|
||||
for e in rd.flatten() {
|
||||
let p = e.path();
|
||||
if p.is_dir() {
|
||||
collect_files(&p, out);
|
||||
} else {
|
||||
out.push(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn find_binary_prefers_am_exe_in_zip_layout() {
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
std::fs::write(dir.path().join("README.md"), "docs").unwrap();
|
||||
std::fs::write(dir.path().join("am-windows-x86_64.exe"), b"exe").unwrap();
|
||||
std::fs::write(dir.path().join("am-linux-x86_64"), b"elf").unwrap();
|
||||
let found = find_binary(dir.path()).unwrap();
|
||||
assert_eq!(
|
||||
found.file_name().unwrap().to_str().unwrap(),
|
||||
"am-windows-x86_64.exe"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn find_binary_falls_back_to_largest_file() {
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
std::fs::write(dir.path().join("am"), b"small").unwrap();
|
||||
std::fs::write(dir.path().join("data.bin"), vec![0u8; 4096]).unwrap();
|
||||
let found = find_binary(dir.path()).unwrap();
|
||||
assert_eq!(found.file_name().unwrap().to_str().unwrap(), "am");
|
||||
}
|
||||
}
|
||||
|
||||
+12
-7
@@ -890,13 +890,18 @@ fn emoji(glyph: &str, style: &str, theme: &Theme, color: bool) -> String {
|
||||
}
|
||||
|
||||
/// One-line status shown before every prompt, with colored emojis:
|
||||
/// ⚙ am v0.2.13 │ 🗂️ cwd │ 73 🤖 · 12 🌐 · 0 📊 │ ⚡ 97ms │ ⏲ 32s
|
||||
/// The last parameter is the duration of the previous command (None before
|
||||
/// the first one).
|
||||
fn print_status(app: &App, started: Instant, last: Option<Duration>) {
|
||||
/// ⚙ am v0.2.13 🪟 bash │ 🗂️ cwd │ 73 🤖 · 12 🌐 · 0 📊 │ ⚡ 97ms │ ⏲ 32s
|
||||
/// `shell` is the active shell-gateway name (issue #44). The last parameter
|
||||
/// is the duration of the previous command (None before the first one).
|
||||
fn print_status(app: &App, started: Instant, last: Option<Duration>, shell: &str) {
|
||||
let color = app.color();
|
||||
let theme = app.theme();
|
||||
let sep = dim(" │ ", theme, color);
|
||||
let shell_part = format!(
|
||||
"{} {}",
|
||||
emoji("🪟", "cyan", theme, color),
|
||||
dim(shell, theme, color)
|
||||
);
|
||||
let cwd = shorten_head(¤t_dir_string(), 30);
|
||||
let folder = format!(
|
||||
"{} {}",
|
||||
@@ -931,7 +936,7 @@ fn print_status(app: &App, started: Instant, last: Option<Duration>) {
|
||||
color,
|
||||
);
|
||||
println!(
|
||||
"{}am v{}{sep}{folder}{sep}{counts}{sep}{last_part}{sep}{elapsed}",
|
||||
"{}am v{}{sep}{shell_part}{sep}{folder}{sep}{counts}{sep}{last_part}{sep}{elapsed}",
|
||||
dim(" ⚙ ", theme, color),
|
||||
env!("CARGO_PKG_VERSION"),
|
||||
);
|
||||
@@ -1142,7 +1147,7 @@ fn run_with_editor(app: &App, session: &mut ShellSession, sid: &str) -> Result<i
|
||||
let mut first_read = true;
|
||||
let mut theme: &'static crate::theme::Theme = app.theme();
|
||||
loop {
|
||||
print_status(app, started, last_duration);
|
||||
print_status(app, started, last_duration, &session.current.name);
|
||||
let signal = match rl.read_line(&prompt) {
|
||||
Ok(signal) => signal,
|
||||
Err(e) => {
|
||||
@@ -1231,7 +1236,7 @@ fn run_plain(app: &App, session: &mut ShellSession, sid: &str) -> Result<i32> {
|
||||
let mut last: Option<DataTable> = None;
|
||||
let mut last_duration: Option<Duration> = None;
|
||||
loop {
|
||||
print_status(app, started, last_duration);
|
||||
print_status(app, started, last_duration, &session.current.name);
|
||||
eprint!("❯ ");
|
||||
std::io::stderr().flush().ok();
|
||||
let mut line = String::new();
|
||||
|
||||
Reference in New Issue
Block a user