From f5e0ae82f4df56fe4925106e06ec80cadbccfed4 Mon Sep 17 00:00:00 2001 From: Vasilito Date: Thu, 7 May 2026 21:08:55 +0100 Subject: [PATCH] fix: harden Cub CLI runtime fallbacks Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus --- .../system/cub/source/cub-cli/src/main.rs | 34 ++++++++++++++++--- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/local/recipes/system/cub/source/cub-cli/src/main.rs b/local/recipes/system/cub/source/cub-cli/src/main.rs index 21a013d1a..debc734d2 100644 --- a/local/recipes/system/cub/source/cub-cli/src/main.rs +++ b/local/recipes/system/cub/source/cub-cli/src/main.rs @@ -210,7 +210,16 @@ fn run_command( fn launch_tui_or_help() -> Result<(), Box> { #[cfg(feature = "tui")] { - cub_tui::run()?; + use std::io::IsTerminal; + + if io::stdin().is_terminal() && io::stdout().is_terminal() { + if let Err(error) = cub_tui::run() { + eprintln!("Failed to launch cub TUI: {error}"); + print_help_text()?; + } + } else { + print_help_text()?; + } return Ok(()); } @@ -425,20 +434,26 @@ fn sync_sources() -> Result<(), Box> { let bur_dir = sync_bur_repo()?; let store = init_cub_store()?; let aur_client = AurClient::new(); - let sample_results = aur_client.search("a", Some("name"))?; + let aur_status = match aur_client.search("a", Some("name")) { + Ok(results) => format!("ok ({})", results.len()), + Err(error) => { + eprintln!("Warning: failed to refresh live AUR metadata: {error}"); + format!("warning ({error})") + } + }; let stamp_path = store.sources_dir().join(AUR_SYNC_STAMP_FILE); fs::write( &stamp_path, format!( - "synced_at_unix = {}\naur_sample_results = {}\n", + "synced_at_unix = {}\naur_status = {:?}\n", current_unix_timestamp(), - sample_results.len() + aur_status ), )?; println!("Refreshed BUR cache at {}.", bur_dir.display()); println!( - "Verified live AUR metadata access and wrote sync stamp to {}.", + "Recorded AUR sync status and wrote sync stamp to {}.", stamp_path.display() ); Ok(()) @@ -683,6 +698,15 @@ fn query_local_files( package: &str, ) -> Result<(), Box> { let package_name = PackageName::new(package.to_string())?; + let library = context.open_library()?; + let installed_packages = library.get_installed_packages()?; + if !installed_packages.contains(&package_name) { + return Err(Box::new(CubError::PackageNotFound(format!( + "{package} is not installed under {}", + context.install_path.display() + )))); + } + let package_state = PackageState::from_sysroot(&context.install_path)?; let install_state = package_state.installed.get(&package_name).ok_or_else(|| { CubError::PackageNotFound(format!("{package} is not installed under {}", context.install_path.display()))