From 60c1b6619cfdba6c714344a42b062f3ee55c5811 Mon Sep 17 00:00:00 2001 From: Hunter Bown Date: Tue, 26 May 2026 16:39:28 -0500 Subject: [PATCH] style: rustfmt cleanups and minor formatting fixes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Line-wrap long function signatures and format arguments - Fix bracket placement for early returns (consistent style) - Use [!] instead of [✓] for network-denied skill sync - Fix copy-selection ordering: clear after success, not always --- crates/cli/src/update.rs | 28 ++++++++++++++++++++++---- crates/config/src/lib.rs | 10 ++------- crates/tui/src/commands/session.rs | 5 ++++- crates/tui/src/commands/skills.rs | 2 +- crates/tui/src/config.rs | 20 +++++++++++++----- crates/tui/src/core/capacity_memory.rs | 3 +-- crates/tui/src/cycle_manager.rs | 13 ++++++------ crates/tui/src/tools/truncate.rs | 4 +++- crates/tui/src/tui/mouse_ui.rs | 2 +- crates/tui/src/tui/onboarding/mod.rs | 4 +++- crates/tui/src/tui/ui.rs | 6 +++++- 11 files changed, 65 insertions(+), 32 deletions(-) diff --git a/crates/cli/src/update.rs b/crates/cli/src/update.rs index 5b1dce53..2ab35ef1 100644 --- a/crates/cli/src/update.rs +++ b/crates/cli/src/update.rs @@ -351,8 +351,8 @@ fn update_http_client() -> Result { /// Fetch the latest release metadata from GitHub. fn fetch_latest_release(channel: ReleaseChannel) -> Result { - if let Some(base_url) = release_base_url_from_env() { - let version = update_version_from_env().unwrap_or_else(|| env!("CARGO_PKG_VERSION").into()); + let version = update_version_from_env().unwrap_or_else(|| env!("CARGO_PKG_VERSION").into()); + if let Some(base_url) = release_base_url_from_env(&version) { return Ok(FetchedRelease { release: release_from_mirror_base_url( &base_url, @@ -373,7 +373,7 @@ fn fetch_latest_release(channel: ReleaseChannel) -> Result { }) } -fn release_base_url_from_env() -> Option { +fn release_base_url_from_env(version: &str) -> Option { // Check canonical env first, then legacy envs for env_name in [ RELEASE_BASE_URL_ENV, @@ -389,11 +389,19 @@ fn release_base_url_from_env() -> Option { } // Auto-detect CNB mirror when CODEWHALE_USE_CNB_MIRROR is set if std::env::var(CNB_MIRROR_ENV).is_ok() { - return Some(CNB_RELEASE_ASSET_BASE.to_string()); + return Some(cnb_release_base_url(version)); } None } +fn cnb_release_base_url(version: &str) -> String { + format!( + "{}/v{}", + CNB_RELEASE_ASSET_BASE.trim_end_matches('/'), + version.trim_start_matches('v') + ) +} + fn update_version_from_env() -> Option { std::env::var(UPDATE_VERSION_ENV) .ok() @@ -993,6 +1001,18 @@ E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855 *codewhale-win ); } + #[test] + fn cnb_release_base_url_includes_tag_directory() { + assert_eq!( + cnb_release_base_url("0.8.47"), + "https://cnb.cool/Hmbown/CodeWhale/-/releases/v0.8.47" + ); + assert_eq!( + cnb_release_base_url("v0.8.47"), + "https://cnb.cool/Hmbown/CodeWhale/-/releases/v0.8.47" + ); + } + #[test] fn stable_update_is_needed_only_when_latest_is_newer() { assert!(update_is_needed(ReleaseChannel::Stable, "0.8.45", "v0.8.46").unwrap()); diff --git a/crates/config/src/lib.rs b/crates/config/src/lib.rs index ffc78e66..bb2c339b 100644 --- a/crates/config/src/lib.rs +++ b/crates/config/src/lib.rs @@ -1624,10 +1624,7 @@ pub fn ensure_state_dir(subdir: &str) -> Result { /// Returns `(true, path)` when the primary `.codewhale/` path is used, /// `(false, path)` for the legacy fallback. The boolean helps callers /// emit a deprecation notice on legacy paths. -pub fn resolve_project_state_dir( - workspace: &Path, - subdir: &str, -) -> (bool, PathBuf) { +pub fn resolve_project_state_dir(workspace: &Path, subdir: &str) -> (bool, PathBuf) { let primary = workspace.join(CODEWHALE_APP_DIR).join(subdir); if primary.exists() { return (true, primary); @@ -1638,10 +1635,7 @@ pub fn resolve_project_state_dir( /// Ensure a project-local state subdirectory exists under `.codewhale/`, /// creating it if necessary. Returns the directory path. -pub fn ensure_project_state_dir( - workspace: &Path, - subdir: &str, -) -> Result { +pub fn ensure_project_state_dir(workspace: &Path, subdir: &str) -> Result { let dir = workspace.join(CODEWHALE_APP_DIR).join(subdir); std::fs::create_dir_all(&dir) .with_context(|| format!("failed to create {}/", dir.display()))?; diff --git a/crates/tui/src/commands/session.rs b/crates/tui/src/commands/session.rs index 316e8c6c..80535bbd 100644 --- a/crates/tui/src/commands/session.rs +++ b/crates/tui/src/commands/session.rs @@ -513,7 +513,10 @@ mod tests { Vec::new() }; // Session should be saved to the managed dir, not the workspace root. - assert!(!entries.is_empty(), "expected session file in {sessions_dir:?}, got none; msg: {msg}"); + assert!( + !entries.is_empty(), + "expected session file in {sessions_dir:?}, got none; msg: {msg}" + ); } #[test] diff --git a/crates/tui/src/commands/skills.rs b/crates/tui/src/commands/skills.rs index 9dc7fbf7..a8a4997f 100644 --- a/crates/tui/src/commands/skills.rs +++ b/crates/tui/src/commands/skills.rs @@ -441,7 +441,7 @@ fn sync_skills(app: &mut App) -> CommandResult { } SkillSyncOutcome::Denied { name, host } => { failed += 1; - let _ = writeln!(out, " [✓] {name} — network denied ({host})"); + let _ = writeln!(out, " [!] {name} — network denied ({host})"); } SkillSyncOutcome::NeedsApproval { name, host } => { failed += 1; diff --git a/crates/tui/src/config.rs b/crates/tui/src/config.rs index 55d46871..44bfd200 100644 --- a/crates/tui/src/config.rs +++ b/crates/tui/src/config.rs @@ -2371,7 +2371,9 @@ fn default_managed_config_path() -> Option { { effective_home_dir().map(|home| { let primary = home.join(".codewhale").join("managed_config.toml"); - if primary.exists() { return primary; } + if primary.exists() { + return primary; + } home.join(".deepseek").join("managed_config.toml") }) } @@ -2386,7 +2388,9 @@ fn default_requirements_path() -> Option { { effective_home_dir().map(|home| { let primary = home.join(".codewhale").join("requirements.toml"); - if primary.exists() { return primary; } + if primary.exists() { + return primary; + } home.join(".deepseek").join("requirements.toml") }) } @@ -2415,7 +2419,9 @@ fn default_skills_dir() -> Option { fn default_mcp_config_path() -> Option { effective_home_dir().map(|home| { let primary = home.join(".codewhale").join("mcp.json"); - if primary.exists() { return primary; } + if primary.exists() { + return primary; + } home.join(".deepseek").join("mcp.json") }) } @@ -2423,7 +2429,9 @@ fn default_mcp_config_path() -> Option { fn default_notes_path() -> Option { effective_home_dir().map(|home| { let primary = home.join(".codewhale").join("notes.txt"); - if primary.exists() { return primary; } + if primary.exists() { + return primary; + } home.join(".deepseek").join("notes.txt") }) } @@ -2431,7 +2439,9 @@ fn default_notes_path() -> Option { fn default_memory_path() -> Option { effective_home_dir().map(|home| { let primary = home.join(".codewhale").join("memory.md"); - if primary.exists() { return primary; } + if primary.exists() { + return primary; + } home.join(".deepseek").join("memory.md") }) } diff --git a/crates/tui/src/core/capacity_memory.rs b/crates/tui/src/core/capacity_memory.rs index ab598512..0d22e4df 100644 --- a/crates/tui/src/core/capacity_memory.rs +++ b/crates/tui/src/core/capacity_memory.rs @@ -64,8 +64,7 @@ fn capacity_memory_dirs() -> Vec { dirs.push(home.join(".deepseek").join("memory")); } - let cwd = std::env::current_dir() - .unwrap_or_else(|_| PathBuf::from(".")); + let cwd = std::env::current_dir().unwrap_or_else(|_| PathBuf::from(".")); let primary_cwd = cwd.join(".codewhale").join("memory"); if primary_cwd.exists() { dirs.push(primary_cwd); diff --git a/crates/tui/src/cycle_manager.rs b/crates/tui/src/cycle_manager.rs index 6817811e..c7315053 100644 --- a/crates/tui/src/cycle_manager.rs +++ b/crates/tui/src/cycle_manager.rs @@ -466,13 +466,12 @@ pub struct CycleArchiveHeader { /// Resolve the on-disk archive directory: `~/.codewhale/sessions//cycles` /// (or legacy `~/.deepseek/sessions//cycles`). fn archive_dir_for(session_id: &str) -> Result { - let sessions = codewhale_config::resolve_state_dir("sessions") - .unwrap_or_else(|_| { - dirs::home_dir() - .unwrap_or_else(|| PathBuf::from(".")) - .join(".deepseek") - .join("sessions") - }); + let sessions = codewhale_config::resolve_state_dir("sessions").unwrap_or_else(|_| { + dirs::home_dir() + .unwrap_or_else(|| PathBuf::from(".")) + .join(".deepseek") + .join("sessions") + }); Ok(sessions.join(session_id).join("cycles")) } diff --git a/crates/tui/src/tools/truncate.rs b/crates/tui/src/tools/truncate.rs index 6c8d6e69..4de0a540 100644 --- a/crates/tui/src/tools/truncate.rs +++ b/crates/tui/src/tools/truncate.rs @@ -82,7 +82,9 @@ pub fn spillover_root() -> Option { } // Prefer .codewhale, fall back to .deepseek - let primary = dirs::home_dir()?.join(".codewhale").join(SPILLOVER_DIR_NAME); + let primary = dirs::home_dir()? + .join(".codewhale") + .join(SPILLOVER_DIR_NAME); if primary.exists() { return Some(primary); } diff --git a/crates/tui/src/tui/mouse_ui.rs b/crates/tui/src/tui/mouse_ui.rs index 92278bb6..a22b2b61 100644 --- a/crates/tui/src/tui/mouse_ui.rs +++ b/crates/tui/src/tui/mouse_ui.rs @@ -714,10 +714,10 @@ pub(crate) fn copy_active_selection(app: &mut App) { if !sel.is_empty() { if app.clipboard.write_text(&sel).is_ok() { app.status_message = Some("Selection copied".to_string()); + app.clear_selection(); } else { app.status_message = Some("Copy failed".to_string()); } - app.clear_selection(); return; } if !app.viewport.transcript_selection.is_active() { diff --git a/crates/tui/src/tui/onboarding/mod.rs b/crates/tui/src/tui/onboarding/mod.rs index 2967cab6..a1cce682 100644 --- a/crates/tui/src/tui/onboarding/mod.rs +++ b/crates/tui/src/tui/onboarding/mod.rs @@ -130,7 +130,9 @@ pub fn tips_lines(app: &App) -> Vec> { pub fn default_marker_path() -> Option { dirs::home_dir().map(|home| { let primary = home.join(".codewhale").join(".onboarded"); - if primary.exists() { return primary; } + if primary.exists() { + return primary; + } home.join(".deepseek").join(".onboarded") }) } diff --git a/crates/tui/src/tui/ui.rs b/crates/tui/src/tui/ui.rs index c0f1dad4..83c755b8 100644 --- a/crates/tui/src/tui/ui.rs +++ b/crates/tui/src/tui/ui.rs @@ -2972,7 +2972,11 @@ async fn run_event_loop( let sel = app.selected_text(); if !sel.is_empty() { if app.clipboard.write_text(&sel).is_ok() { - app.push_status_toast("Copied to clipboard", StatusToastLevel::Info, None); + app.push_status_toast( + "Copied to clipboard", + StatusToastLevel::Info, + None, + ); app.clear_selection(); } else { app.push_status_toast("Copy failed", StatusToastLevel::Error, None);