Ripristinato akode update verso il Gitea dell'utente (come in 0.9.2, senza il sync del daemon)

Da 9494b768, e1ce139a e 1c278642: crate akode-update (ultima release da
git.difonzo.net/andrea/imeai-aKode, confronto semver, download solo dallo stesso host, verifica
SHA-256, sostituzione atomica), `akode update [--check]`, riga di avviso nella TUI, controllo in
background all'avvio al massimo ogni 24 h (disattivabile con [update] check_on_startup = false;
non installa mai nulla da solo). Nessun contatto con OpenAI o altri domini; il sistema upstream
(curl chatgpt.com/codex/install.sh, npm, brew) resta rimosso. Lasciato fuori l'allineamento del
daemon (95f4ddcd).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
andrea.difonzo
2026-11-17 14:35:07 +01:00
parent 925917c58c
commit 07ba31d492
22 changed files with 1538 additions and 75 deletions

View File

@@ -1,41 +1,26 @@
//! Diagnoses whether Codex update paths target the running installation.
//! Reports how `akode update` is configured, from local state only.
//!
//! aKode: diagnostics are local only (cached version metadata and install-channel hints).
//! There are no latest-version probes (GitHub, Homebrew) and no desktop appcast probes.
//! The doctor never contacts the release repository; it shows the configured source and the
//! result of the last startup check recorded in `update-check.json`.
use std::path::Path;
use akode_core::config::Config;
use akode_install_context::InstallContext;
use akode_install_context::InstallMethod;
use serde::Deserialize;
use super::CheckStatus;
use super::DoctorCheck;
use super::doctor_install_context;
use super::doctor_managed_by_npm;
const VERSION_FILE_NAME: &str = "version.json";
const CHECK_STATE_FILE_NAME: &str = "update-check.json";
/// Builds the update-health row for the current installation from local state only.
pub(super) async fn updates_check(config: &Config) -> DoctorCheck {
let current_exe = std::env::current_exe().ok();
let install_context = doctor_install_context(current_exe.as_deref());
let mut details = vec![
format!(
"check for update on startup: {}",
config.check_for_update_on_startup
),
format!("update action: {}", update_action_label(&install_context)),
format!("release repository: {}", config.update_repo_url),
format!("check on startup: {}", config.update_check_on_startup),
"update command: akode update".to_string(),
];
let version_file = config.codex_home.join(VERSION_FILE_NAME);
push_cached_version_details(&mut details, &version_file);
if doctor_managed_by_npm(current_exe.as_deref()) {
details
.push("npm update target: not inspected (PATH helpers are not executed)".to_string());
}
details.push("latest version probe: disabled (no network update checks)".to_string());
push_last_check_details(&mut details, &config.codex_home.join(CHECK_STATE_FILE_NAME));
DoctorCheck::new(
"updates.status",
@@ -46,47 +31,38 @@ pub(super) async fn updates_check(config: &Config) -> DoctorCheck {
.details(details)
}
fn push_cached_version_details(details: &mut Vec<String>, version_file: &Path) {
details.push(format!("version cache: {}", version_file.display()));
match std::fs::read_to_string(version_file) {
Ok(contents) => match serde_json::from_str::<VersionInfo>(&contents) {
Ok(info) => {
details.push(format!("cached latest version: {}", info.latest_version));
if let Some(last_checked_at) = info.last_checked_at {
details.push(format!("last checked at: {last_checked_at}"));
}
if let Some(dismissed_version) = info.dismissed_version {
details.push(format!("dismissed version: {dismissed_version}"));
fn push_last_check_details(details: &mut Vec<String>, state_file: &Path) {
match std::fs::read_to_string(state_file) {
Ok(contents) => match serde_json::from_str::<CheckState>(&contents) {
Ok(state) => {
details.push(format!("last checked at: {}", state.last_checked_at));
details.push(format!(
"latest version: {}",
state
.latest_version
.as_deref()
.unwrap_or("no release published")
));
if state.latest_version.as_deref().is_some_and(|latest| {
akode_update::is_newer_str(env!("CARGO_PKG_VERSION"), latest)
}) {
details.push("latest version status: newer version is available".to_string());
}
}
Err(err) => details.push(format!("version cache parse: {err}")),
Err(err) => details.push(format!("update check state parse: {err}")),
},
Err(err) if err.kind() == std::io::ErrorKind::NotFound => {
details.push("version cache: missing".to_string());
details.push("last checked at: never".to_string());
}
Err(err) => details.push(format!("version cache read: {err}")),
}
}
fn update_action_label(context: &InstallContext) -> &'static str {
match &context.method {
InstallMethod::Npm => "npm install -g @openai/codex",
InstallMethod::Bun => "bun install -g @openai/codex",
InstallMethod::VitePlus => "vp install -g @openai/codex",
InstallMethod::Pnpm => "pnpm add -g @openai/codex",
InstallMethod::Brew => "brew upgrade --cask codex",
InstallMethod::Standalone { .. } => "standalone installer",
InstallMethod::Other => "manual or unknown",
Err(err) => details.push(format!("update check state read: {err}")),
}
}
#[derive(Deserialize)]
struct VersionInfo {
latest_version: String,
struct CheckState {
last_checked_at: String,
#[serde(default)]
last_checked_at: Option<String>,
#[serde(default)]
dismissed_version: Option<String>,
latest_version: Option<String>,
}
#[cfg(test)]
@@ -95,27 +71,26 @@ mod tests {
use pretty_assertions::assert_eq;
#[test]
fn update_action_labels_install_contexts() {
fn last_check_details_read_the_startup_check_state() {
let dir = tempfile::tempdir().unwrap();
let state_file = dir.path().join(CHECK_STATE_FILE_NAME);
let mut details = Vec::new();
push_last_check_details(&mut details, &state_file);
assert_eq!(details, vec!["last checked at: never".to_string()]);
std::fs::write(
&state_file,
r#"{"last_checked_at":"2026-11-11T10:00:00Z","latest_version":null}"#,
)
.unwrap();
let mut details = Vec::new();
push_last_check_details(&mut details, &state_file);
assert_eq!(
update_action_label(&InstallContext {
method: InstallMethod::Npm,
package_layout: None,
}),
"npm install -g @openai/codex"
);
assert_eq!(
update_action_label(&InstallContext {
method: InstallMethod::Pnpm,
package_layout: None,
}),
"pnpm add -g @openai/codex"
);
assert_eq!(
update_action_label(&InstallContext {
method: InstallMethod::Other,
package_layout: None,
}),
"manual or unknown"
details,
vec![
"last checked at: 2026-11-11T10:00:00Z".to_string(),
"latest version: no release published".to_string(),
]
);
}
}

View File

@@ -60,6 +60,7 @@ mod sandbox_setup;
mod sandbox_uninstall;
mod state_db_recovery;
#[cfg(not(windows))]
mod update_cmd;
use crate::mcp_cmd::McpCli;
use crate::plugin_cmd::PluginCli;
@@ -154,6 +155,9 @@ enum Subcommand {
/// Generate shell completion scripts.
Completion(CompletionCommand),
/// Update aKode to the latest release published on the configured repository.
Update(update_cmd::UpdateCommand),
/// Diagnose local aKode installation, config, auth, and runtime health.
Doctor(DoctorCommand),
@@ -705,7 +709,7 @@ fn handle_app_exit(
Ok(())
}
/// Run the update action and print the result.
/// Run the daemon update requested from the TUI and print the result.
fn run_update_action(
action: UpdateAction,
cli_executable: Option<&std::path::Path>,
@@ -1461,6 +1465,17 @@ async fn dispatch_cli(
)?;
print_completion(completion_cli);
}
Some(Subcommand::Update(update_cli)) => {
reject_remote_mode_for_subcommand(
root_remote.as_deref(),
root_remote_auth_token_env.as_deref(),
"update",
)?;
let config =
local_config::load_config(&root_config_overrides, LoaderOverrides::default())
.await?;
update_cmd::run(update_cli, &config).await?;
}
Some(Subcommand::Doctor(doctor_cli)) => {
reject_remote_mode_for_subcommand(
root_remote.as_deref(),
@@ -2069,6 +2084,7 @@ fn unsupported_subcommand_name_for_strict_config(
Some(Subcommand::Login(_)) => Some("login"),
Some(Subcommand::Logout(_)) => Some("logout"),
Some(Subcommand::Completion(_)) => Some("completion"),
Some(Subcommand::Update(_)) => Some("update"),
Some(Subcommand::Sandbox(_)) => Some("sandbox"),
Some(Subcommand::Debug(_)) => Some("debug"),
Some(Subcommand::Execpolicy(_)) => Some("execpolicy"),
@@ -3229,6 +3245,24 @@ enabled = true
assert!(matches!(cli.subcommand, Some(Subcommand::Plugin(_))));
}
#[test]
fn update_parses_as_update_subcommand() {
let cli = MultitoolCli::try_parse_from(["akode", "update"]).expect("parse");
assert!(matches!(
cli.subcommand,
Some(Subcommand::Update(update_cmd::UpdateCommand {
check: false
}))
));
let cli = MultitoolCli::try_parse_from(["akode", "update", "--check"]).expect("parse");
assert!(matches!(
cli.subcommand,
Some(Subcommand::Update(update_cmd::UpdateCommand {
check: true
}))
));
}
#[test]
fn archive_merges_scoped_tui_flags() {
let (target, interactive, remote) = finalize_archive_from_args(

View File

@@ -0,0 +1,90 @@
//! `akode update`: installs the latest aKode release from the configured Gitea repository.
//! The release archive is verified against its published SHA-256 before anything changes.
use std::path::PathBuf;
use akode_core::config::Config;
use akode_install_context::InstallContext;
use akode_update::CheckResult;
use akode_update::InstallOutcome;
use akode_update::InstallTarget;
use anyhow::Context;
#[derive(Debug, Default, clap::Parser)]
pub struct UpdateCommand {
/// Only report whether a newer release exists, without installing it.
#[arg(long)]
pub check: bool,
}
pub async fn run(cmd: UpdateCommand, config: &Config) -> anyhow::Result<()> {
let current = env!("CARGO_PKG_VERSION");
let repo_url = config.update_repo_url.as_str();
let client = akode_update::http_client(akode_update::COMMAND_TIMEOUT)?;
println!("Controllo degli aggiornamenti su {repo_url}…");
let release = match akode_update::check(&client, repo_url, current).await? {
CheckResult::UpToDate { latest: None } => {
println!("Nessuna release pubblicata: aKode {current} è la versione più recente.");
return Ok(());
}
CheckResult::UpToDate {
latest: Some(latest),
} => {
println!("aKode {current} è aggiornato (ultima release: {latest}).");
return Ok(());
}
CheckResult::Available(release) => release,
};
if cmd.check {
println!(
"È disponibile aKode {} (installata: {current}). Esegui \"akode update\" per installarla.",
release.version
);
return Ok(());
}
let target = akode_update::current_target()
.context("aKode non pubblica release per questa piattaforma")?;
let install = install_target()?;
println!("Download di aKode {} ({target})…", release.version);
let outcome = akode_update::install_release(&client, repo_url, &release, target, &install)
.await
.context("aggiornamento non riuscito; la versione installata non è stata modificata")?;
match outcome {
InstallOutcome::Binary { backup } => println!(
"aKode aggiornato da {current} a {}. Copia della versione precedente: {}",
release.version,
backup.display()
),
InstallOutcome::Package { backup } => println!(
"Pacchetto aKode aggiornato da {current} a {}. Copia del pacchetto precedente: {}",
release.version,
backup.display()
),
}
if config
.codex_home
.join("packages/app-server-daemon/current")
.symlink_metadata()
.is_ok()
{
println!(
"Il server in background usa ancora il pacchetto precedente: esegui \"akode app-server daemon update --from-cli\" per allinearlo."
);
}
println!("Riavvia aKode per usare la nuova versione.");
Ok(())
}
/// The real file behind the running binary, and its package directory if it is packaged.
fn install_target() -> anyhow::Result<InstallTarget> {
let exe = std::env::current_exe()
.and_then(|exe| exe.canonicalize())
.context("impossibile individuare il binario di aKode in esecuzione")?;
let package_dir = InstallContext::current()
.package_layout
.as_ref()
.filter(|layout| exe.starts_with(layout.bin_dir.as_path()))
.map(|layout| PathBuf::from(layout.package_dir.as_path()));
Ok(InstallTarget { exe, package_dir })
}