diff --git a/atomic-cli/src/commands/agent/disable.rs b/atomic-cli/src/commands/agent/disable.rs index 154802f8..1452958a 100644 --- a/atomic-cli/src/commands/agent/disable.rs +++ b/atomic-cli/src/commands/agent/disable.rs @@ -210,10 +210,12 @@ impl Disable { /// - `claude-code` → `~/.claude/settings.json` /// - `gemini-cli` → `~/.gemini/settings.json` /// - `agy` → `~/.gemini/config/plugins/atomic/` (plugin) + /// - `codex` → `~/.codex/hooks.json` /// - No `--agent` flag → removes from all agents that have global hooks fn run_global(&self) -> CliResult<()> { use atomic_agent::hooks::agy::AgyHook; use atomic_agent::hooks::claude_code::ClaudeCodeHook; + use atomic_agent::hooks::codex::CodexHook; use atomic_agent::hooks::gemini_cli::GeminiCliHook; let agents: Vec<&str> = if let Some(ref name) = self.agent { @@ -230,6 +232,9 @@ impl Disable { if AgyHook::new().is_installed_global() { found.push("agy"); } + if CodexHook::new().is_installed_global() { + found.push("codex"); + } found }; @@ -295,6 +300,21 @@ impl Disable { } } } + "codex" => { + let hook = CodexHook::new(); + if !hook.is_installed_global() { + continue; + } + match hook.uninstall_global() { + Ok(()) => { + print_success("Removed global hooks from ~/.codex/hooks.json"); + total_removed += 1; + } + Err(e) => { + print_error(&format!("Failed to remove Codex global hooks: {}", e)); + } + } + } "kiro" => { print_success("Kiro hooks are configured through the IDE panel."); println!( @@ -309,7 +329,7 @@ impl Disable { } other => { print_warning(&format!( - "Global disable is not supported for '{}'. Supported agents: claude-code, gemini-cli, agy, kilo, kiro", + "Global disable is not supported for '{}'. Supported agents: claude-code, gemini-cli, agy, codex, kilo, kiro", other )); } diff --git a/atomic-cli/src/commands/agent/enable.rs b/atomic-cli/src/commands/agent/enable.rs index a85c4ca0..a72b07b6 100644 --- a/atomic-cli/src/commands/agent/enable.rs +++ b/atomic-cli/src/commands/agent/enable.rs @@ -128,12 +128,18 @@ impl Command for Enable { // Install for all detected agents let detected = registry.detect(&repo_root); if detected.is_empty() { - // If none detected, try all registered agents - print_warning("No agents detected — installing hooks for all registered agents."); - registry.list() - } else { - detected + // Do not install hooks when no agent is detected. + print_error( + "No agents detected in this repository — nothing to enable with --all.", + ); + print_warning( + "Create a .claude/, .gemini/, or .agents/ directory first, or use --agent .", + ); + return Err(crate::error::CliError::InvalidArgument { + message: "no agents detected for --all".to_string(), + }); } + detected } else if let Some(ref name) = self.agent { // Specific agent requested — validate it exists registry diff --git a/atomic-cli/src/commands/clone/command.rs b/atomic-cli/src/commands/clone/command.rs index 766e2e3e..a604cbd1 100644 --- a/atomic-cli/src/commands/clone/command.rs +++ b/atomic-cli/src/commands/clone/command.rs @@ -529,6 +529,7 @@ impl Clone { } // Apply downloaded changes to the local view + let mut apply_errors = Vec::new(); if stats.changes_downloaded > 0 { print_blank(); progress.phase = ClonePhase::Applying; @@ -536,7 +537,6 @@ impl Clone { // Insert each downloaded change in order to build the graph let insert_options = atomic_repository::InsertOptions::default(); - let mut apply_errors = Vec::new(); for entry in &remote_entries { let hash = match atomic_core::types::Hash::from_base32(entry.hash.as_bytes()) { @@ -657,21 +657,39 @@ impl Clone { progress.phase = ClonePhase::Complete; - // Final summary + // Keep partial output, but return failure when any step failed. print_blank(); - if stats.has_failures() { + if stats.has_failures() || !apply_errors.is_empty() { print_warning(&format!( - "Clone completed with errors: {} downloaded, {} failed", - stats.changes_downloaded, stats.changes_failed - )); - } else { - print_success(&format!( - "Clone complete: {} downloaded into {}/", - format_count(stats.changes_downloaded, "change"), - target_path.display() + "Clone completed with errors: {} downloaded, {} failed to download, {} failed to apply", + stats.changes_downloaded, + stats.changes_failed, + apply_errors.len(), )); + + if self.into_existing { + print_hint( + "Next: run 'atomic git import --incremental' to import the Git checkout.", + ); + } + + // Preserve the partial clone before returning the error. + if let Some(guard) = guard { + guard.disable(); + } + return Err(CliError::Internal(anyhow::anyhow!( + "clone completed with errors ({} download, {} apply)", + stats.changes_failed, + apply_errors.len(), + ))); } + print_success(&format!( + "Clone complete: {} downloaded into {}/", + format_count(stats.changes_downloaded, "change"), + target_path.display() + )); + if self.into_existing { print_hint("Next: run 'atomic git import --incremental' to import the Git checkout."); } diff --git a/atomic-cli/src/commands/git/push.rs b/atomic-cli/src/commands/git/push.rs index 507cffe8..43d5cbc9 100644 --- a/atomic-cli/src/commands/git/push.rs +++ b/atomic-cli/src/commands/git/push.rs @@ -160,10 +160,9 @@ impl Command for Push { print_success(&format!("Pushed to {}/{}", self.remote, current_view)); } Err(e) => { - print_warning(&format!( - "Commit created but push failed: {}. Run 'git push' manually.", - e - )); + // Keep the local commit, but report the failed push. + print_warning("Commit created locally. Run 'git push' manually to retry."); + return Err(e); } } } diff --git a/atomic-cli/src/commands/intent/delete.rs b/atomic-cli/src/commands/intent/delete.rs index a4a03843..6acad684 100644 --- a/atomic-cli/src/commands/intent/delete.rs +++ b/atomic-cli/src/commands/intent/delete.rs @@ -38,6 +38,10 @@ impl Command for IntentDelete { let repo = Repository::open(&root).map_err(CliError::Repository)?; if !self.force { + // Check that the intent exists before prompting. + repo.vault_intent_show(&self.id) + .map_err(CliError::Repository)?; + let prompt = format!( "Discard intent '{}'? This removes the unstarted draft from the vault.", self.id diff --git a/atomic-cli/src/commands/org/delete.rs b/atomic-cli/src/commands/org/delete.rs index 7de0669c..f9a19863 100644 --- a/atomic-cli/src/commands/org/delete.rs +++ b/atomic-cli/src/commands/org/delete.rs @@ -83,8 +83,18 @@ impl Command for OrgDelete { impl OrgDelete { async fn execute(&self) -> CliResult<()> { - // Prompt for confirmation unless --force is set. + let client = build_client(self.org.as_deref(), None).await?; + + // `--force` skips both the precheck and confirmation. if !self.force { + // Check that the organization exists before prompting. + atomic_teams::org::get_org(&client, &self.slug) + .await + .map_err(|e| CliError::RemoteError { + message: e.to_string(), + url: None, + })?; + print_warning(&format!( "This will permanently delete organization '{}' and all its data.", self.slug @@ -103,8 +113,6 @@ impl OrgDelete { } } - let client = build_client(self.org.as_deref(), None).await?; - atomic_teams::org::delete_org(&client, &self.slug) .await .map_err(|e| CliError::RemoteError { diff --git a/atomic-cli/src/commands/pull/command.rs b/atomic-cli/src/commands/pull/command.rs index 0ea83e18..17f6e3c6 100644 --- a/atomic-cli/src/commands/pull/command.rs +++ b/atomic-cli/src/commands/pull/command.rs @@ -105,9 +105,10 @@ pub struct Pull { /// Remote name or URL to pull from. /// /// Can be a configured remote name (like "origin") or a full URL. - /// If not specified, uses the default remote "origin". - #[arg(default_value = DEFAULT_REMOTE)] - pub remote: String, + /// + /// Defaults to the configured remote, then `origin`. + #[arg()] + pub remote: Option, /// Local view to pull into. /// @@ -174,12 +175,12 @@ impl Pull { /// use atomic::commands::pull::Pull; /// /// let pull = Pull::new(); - /// assert_eq!(pull.remote, "origin"); + /// assert!(pull.remote.is_none()); /// assert!(!pull.dry_run); /// ``` pub fn new() -> Self { Self { - remote: DEFAULT_REMOTE.to_string(), + remote: None, to_view: None, from_view: None, dry_run: false, @@ -193,7 +194,7 @@ impl Pull { /// Builder: set the remote name or URL. pub fn with_remote(mut self, remote: impl Into) -> Self { - self.remote = remote.into(); + self.remote = Some(remote.into()); self } @@ -247,24 +248,31 @@ impl Pull { // Internal Helper Methods - /// Resolve the remote URL and any identity hint from the `--identity` flag. - /// - /// Returns `(url, identity_hint)` where `identity_hint` comes solely from - /// the `--identity` CLI flag. If absent, `attach_identity` falls back to - /// URL-subdomain inference. - fn resolve_remote_url(&self, repo: &Repository) -> CliResult<(String, Option)> { + /// Use the explicit remote first, then the repository default. + fn resolve_remote_name(&self, repo: &Repository) -> String { + match &self.remote { + Some(name) => name.clone(), + None => repo + .get_default_remote() + .map(|(name, _entry)| name) + .unwrap_or_else(|_| DEFAULT_REMOTE.to_string()), + } + } + + /// Resolve the remote and optional identity override. + fn resolve_remote_url(&self, repo: &Repository) -> CliResult<(String, String, Option)> { + let remote_name = self.resolve_remote_name(repo); + // If it looks like a URL, use it directly - if self.remote.contains("://") { - return Ok((self.remote.clone(), self.identity.clone())); + if remote_name.contains("://") { + return Ok((remote_name.clone(), remote_name, self.identity.clone())); } // Look up named remote in repository configuration - match repo.get_remote(&self.remote) { - Ok(entry) => Ok((entry.url, self.identity.clone())), + match repo.get_remote(&remote_name) { + Ok(entry) => Ok((remote_name, entry.url, self.identity.clone())), Err(atomic_repository::RepositoryError::RemoteNotFound { .. }) => { - Err(CliError::RemoteNotFound { - name: self.remote.clone(), - }) + Err(CliError::RemoteNotFound { name: remote_name }) } Err(e) => Err(CliError::Repository(e)), } @@ -309,6 +317,7 @@ impl Pull { /// Shows what changes would be pulled without actually pulling them. fn display_dry_run( &self, + remote_name: &str, remote_url: &str, remote_view: &str, to_download: &[PullChange], @@ -321,7 +330,7 @@ impl Pull { println!( "Would pull {} from {} (view: {}):", format_count(to_download.len(), "change"), - self.remote, + remote_name, remote_view ); print_blank(); @@ -373,8 +382,8 @@ impl Pull { let repo_root = find_repository_root()?; let repo = Repository::open(&repo_root).map_err(CliError::Repository)?; - // Resolve remote URL and identity hint - let (remote_url, identity_hint) = self.resolve_remote_url(&repo)?; + // Resolve remote name, URL, and identity hint + let (remote_name, remote_url, identity_hint) = self.resolve_remote_url(&repo)?; // Determine views let local_view = self.get_local_view(&repo); @@ -383,7 +392,7 @@ impl Pull { // Print header println!( "Pulling from {} ({})", - style_view(&self.remote), + style_view(&remote_name), hint(&remote_url) ); @@ -453,7 +462,7 @@ impl Pull { // Handle dry run if self.dry_run { - return self.display_dry_run(&remote_url, &remote_view, &to_download); + return self.display_dry_run(&remote_name, &remote_url, &remote_view, &to_download); } // Check for nothing to pull @@ -594,6 +603,7 @@ impl Pull { } // Materialize the working copy so on-disk files reflect the new state + let mut materialize_failed = false; if stats.has_applied() { let mat_spinner = create_spinner("Updating working copy..."); match repo.materialize() { @@ -604,6 +614,7 @@ impl Pull { ); } Err(e) => { + materialize_failed = true; finish_error(&mat_spinner, "Failed to update working copy"); print_warning(&format!( "Applied {} but failed to update working copy: {}", @@ -703,21 +714,33 @@ impl Pull { } } - // Final summary + // Keep partial output, but return failure when any step failed. print_blank(); - if stats.has_failures() { + if stats.has_failures() || !apply_errors.is_empty() || materialize_failed { print_warning(&format!( - "Pull completed with errors: {} downloaded, {} failed", - stats.changes_downloaded, stats.changes_failed - )); - } else { - print_success(&format!( - "Pull complete: {} downloaded and applied to {}", - format_count(stats.changes_downloaded, "change"), - local_view + "Pull completed with errors: {} downloaded, {} failed to download, {} failed to apply", + stats.changes_downloaded, + stats.changes_failed, + apply_errors.len(), )); + return Err(CliError::Internal(anyhow::anyhow!( + "pull completed with errors ({} download, {} apply{})", + stats.changes_failed, + apply_errors.len(), + if materialize_failed { + ", working copy not updated" + } else { + "" + }, + ))); } + print_success(&format!( + "Pull complete: {} downloaded and applied to {}", + format_count(stats.changes_downloaded, "change"), + local_view + )); + Ok(()) } } @@ -765,7 +788,7 @@ mod tests { fn test_pull_new() { let pull = Pull::new(); - assert_eq!(pull.remote, DEFAULT_REMOTE); + assert!(pull.remote.is_none()); assert!(pull.to_view.is_none()); assert!(pull.from_view.is_none()); assert!(!pull.dry_run); @@ -779,21 +802,21 @@ mod tests { #[test] fn test_pull_default() { let pull: Pull = Default::default(); - assert_eq!(pull.remote, DEFAULT_REMOTE); + assert!(pull.remote.is_none()); } /// Test with_remote builder method. #[test] fn test_pull_with_remote() { let pull = Pull::new().with_remote("upstream"); - assert_eq!(pull.remote, "upstream"); + assert_eq!(pull.remote.as_deref(), Some("upstream")); } /// Test with_remote with URL. #[test] fn test_pull_with_remote_url() { let pull = Pull::new().with_remote("https://example.com/repo"); - assert_eq!(pull.remote, "https://example.com/repo"); + assert_eq!(pull.remote.as_deref(), Some("https://example.com/repo")); } /// Test with_to_view builder method. @@ -861,7 +884,7 @@ mod tests { .with_timeout(120) .with_download_only(true); - assert_eq!(pull.remote, "upstream"); + assert_eq!(pull.remote.as_deref(), Some("upstream")); assert_eq!(pull.to_view, Some("feature".to_string())); assert_eq!(pull.from_view, Some("main".to_string())); assert!(pull.dry_run); @@ -878,7 +901,7 @@ mod tests { let cloned = original.clone(); - assert_eq!(cloned.remote, "test"); + assert_eq!(cloned.remote.as_deref(), Some("test")); assert!(cloned.dry_run); } diff --git a/atomic-cli/src/commands/pull/mod.rs b/atomic-cli/src/commands/pull/mod.rs index a19a9055..1509586e 100644 --- a/atomic-cli/src/commands/pull/mod.rs +++ b/atomic-cli/src/commands/pull/mod.rs @@ -32,7 +32,7 @@ //! atomic pull [OPTIONS] [REMOTE] //! //! Arguments: -//! [REMOTE] Remote name or URL (default: "origin") +//! [REMOTE] Remote name or URL (default: the configured default remote, or "origin") //! //! Options: //! --to-channel Local channel to pull into (default: current) @@ -183,7 +183,7 @@ mod tests { #[test] fn test_pull_reexported() { let pull = Pull::new(); - assert_eq!(pull.remote, DEFAULT_REMOTE); + assert!(pull.remote.is_none()); } /// Verify that PullChange is properly re-exported. diff --git a/atomic-cli/src/commands/push/command.rs b/atomic-cli/src/commands/push/command.rs index d2c177f6..48841f77 100644 --- a/atomic-cli/src/commands/push/command.rs +++ b/atomic-cli/src/commands/push/command.rs @@ -78,9 +78,10 @@ pub struct Push { /// Remote name or URL to push to. /// /// Can be a configured remote name (like "origin") or a full URL. - /// If not specified, uses the default remote "origin". - #[arg(default_value = DEFAULT_REMOTE)] - pub remote: String, + /// + /// Defaults to the configured remote, then `origin`. + #[arg()] + pub remote: Option, /// Remote view to push to. /// @@ -142,12 +143,12 @@ impl Push { /// use atomic::commands::push::Push; /// /// let push = Push::new(); - /// assert_eq!(push.remote, "origin"); + /// assert!(push.remote.is_none()); /// assert!(!push.dry_run); /// ``` pub fn new() -> Self { Self { - remote: DEFAULT_REMOTE.to_string(), + remote: None, to_view: None, from_view: None, dry_run: false, @@ -161,7 +162,7 @@ impl Push { /// Builder: set the remote name or URL. pub fn with_remote(mut self, remote: impl Into) -> Self { - self.remote = remote.into(); + self.remote = Some(remote.into()); self } @@ -177,6 +178,17 @@ impl Push { self } + /// Use the explicit remote first, then the repository default. + fn resolve_remote_name(&self, repo: &Repository) -> String { + match &self.remote { + Some(name) => name.clone(), + None => repo + .get_default_remote() + .map(|(name, _entry)| name) + .unwrap_or_else(|_| DEFAULT_REMOTE.to_string()), + } + } + /// Builder: set the dry-run flag. pub fn with_dry_run(mut self, dry_run: bool) -> Self { self.dry_run = dry_run; @@ -213,24 +225,20 @@ impl Push { self } - /// Resolve the remote URL and any identity hint from the `--identity` flag. - /// - /// Returns `(url, identity_hint)` where `identity_hint` comes solely from - /// the `--identity` CLI flag. If absent, `attach_identity` falls back to - /// URL-subdomain inference. - fn resolve_remote_url(&self, repo: &Repository) -> CliResult<(String, Option)> { + /// Resolve the remote and optional identity override. + fn resolve_remote_url(&self, repo: &Repository) -> CliResult<(String, String, Option)> { + let remote_name = self.resolve_remote_name(repo); + // If it looks like a URL, use it directly - if self.remote.contains("://") { - return Ok((self.remote.clone(), self.identity.clone())); + if remote_name.contains("://") { + return Ok((remote_name.clone(), remote_name, self.identity.clone())); } // Look up named remote in repository configuration - match repo.get_remote(&self.remote) { - Ok(entry) => Ok((entry.url, self.identity.clone())), + match repo.get_remote(&remote_name) { + Ok(entry) => Ok((remote_name, entry.url, self.identity.clone())), Err(atomic_repository::RepositoryError::RemoteNotFound { .. }) => { - Err(CliError::RemoteNotFound { - name: self.remote.clone(), - }) + Err(CliError::RemoteNotFound { name: remote_name }) } Err(e) => Err(CliError::Repository(e)), } @@ -273,6 +281,7 @@ impl Push { /// Display the dry run preview. fn display_dry_run( &self, + remote_name: &str, remote_url: &str, remote_view: &str, to_upload: &[PushChange], @@ -285,7 +294,7 @@ impl Push { println!( "Would push {} to {} (view: {}):", format_count(to_upload.len(), "change"), - self.remote, + remote_name, remote_view ); print_blank(); @@ -308,8 +317,8 @@ impl Push { let repo_root = find_repository_root()?; let repo = Repository::open(&repo_root).map_err(CliError::Repository)?; - // Resolve remote URL and identity hint - let (remote_url, identity_hint) = self.resolve_remote_url(&repo)?; + // Resolve remote name, URL, and identity hint + let (remote_name, remote_url, identity_hint) = self.resolve_remote_url(&repo)?; // Determine views let local_view = self.get_local_view(&repo); @@ -319,7 +328,7 @@ impl Push { // Print header println!( "Pushing to {} ({})", - style_view(&self.remote), + style_view(&remote_name), hint(&remote_url) ); @@ -427,7 +436,7 @@ impl Push { // Handle dry run if self.dry_run { - return self.display_dry_run(&remote_url, &remote_view, &to_upload); + return self.display_dry_run(&remote_name, &remote_url, &remote_view, &to_upload); } // Check for nothing to push @@ -484,7 +493,7 @@ impl Push { print_blank(); print_success(&format!( "Push complete: {} view created on {}", - remote_view, self.remote + remote_view, remote_name )); return Ok(()); } @@ -805,7 +814,7 @@ mod tests { #[test] fn test_push_new() { let push = Push::new(); - assert_eq!(push.remote, "origin"); + assert!(push.remote.is_none()); assert!(push.to_view.is_none()); assert!(push.from_view.is_none()); assert!(!push.dry_run); @@ -818,19 +827,19 @@ mod tests { #[test] fn test_push_default() { let push = Push::default(); - assert_eq!(push.remote, "origin"); + assert!(push.remote.is_none()); } #[test] fn test_push_with_remote() { let push = Push::new().with_remote("upstream"); - assert_eq!(push.remote, "upstream"); + assert_eq!(push.remote.as_deref(), Some("upstream")); } #[test] fn test_push_with_remote_url() { let push = Push::new().with_remote("https://example.com/repo"); - assert_eq!(push.remote, "https://example.com/repo"); + assert_eq!(push.remote.as_deref(), Some("https://example.com/repo")); } #[test] @@ -890,7 +899,7 @@ mod tests { .with_insecure(true) .with_timeout(120); - assert_eq!(push.remote, "upstream"); + assert_eq!(push.remote.as_deref(), Some("upstream")); assert_eq!(push.to_view, Some("main".to_string())); assert_eq!(push.from_view, Some("feature".to_string())); assert!(push.dry_run); @@ -911,7 +920,7 @@ mod tests { #[test] fn test_push_debug() { - let push = Push::new(); + let push = Push::new().with_remote("origin"); let debug_str = format!("{:?}", push); assert!(debug_str.contains("Push")); diff --git a/atomic-cli/src/commands/push/mod.rs b/atomic-cli/src/commands/push/mod.rs index a2dbf970..b3748446 100644 --- a/atomic-cli/src/commands/push/mod.rs +++ b/atomic-cli/src/commands/push/mod.rs @@ -31,7 +31,7 @@ //! atomic push [OPTIONS] [REMOTE] //! //! Arguments: -//! [REMOTE] Remote name or URL (default: "origin") +//! [REMOTE] Remote name or URL (default: the configured default remote, or "origin") //! //! Options: //! --to-channel Remote channel to push to (default: same as local) @@ -147,7 +147,7 @@ mod tests { #[test] fn test_push_reexported() { let push = Push::new(); - assert_eq!(push.remote, DEFAULT_REMOTE); + assert!(push.remote.is_none()); } #[test] diff --git a/atomic-cli/src/commands/query/mod.rs b/atomic-cli/src/commands/query/mod.rs index 0221664d..c4455fd1 100644 --- a/atomic-cli/src/commands/query/mod.rs +++ b/atomic-cli/src/commands/query/mod.rs @@ -1027,6 +1027,16 @@ fn emit_html(query: &str, nodes: &[KgNode], edges: &[KgEdge]) -> String { ) } +/// Truncate display text on character boundaries and append `...`. +fn truncate_display(s: &str, max_chars: usize) -> String { + if s.chars().count() <= max_chars { + s.to_string() + } else { + let kept: String = s.chars().take(max_chars.saturating_sub(3)).collect(); + format!("{}...", kept) + } +} + /// Search the knowledge graph. #[derive(Parser, Debug)] pub struct QueryNodes { @@ -1099,12 +1109,7 @@ impl Command for QueryNodes { let summary_display = if summary.is_empty() { String::new() } else { - let truncated = if summary.len() > 60 { - format!("{}...", &summary[..57]) - } else { - summary.to_string() - }; - format!(" {}", truncated) + format!(" {}", truncate_display(summary, 60)) }; println!(" [{}] {}{}", node.kind, node.id, summary_display); } @@ -1150,12 +1155,7 @@ impl Command for QueryNeighbors { let summary_display = if summary.is_empty() { String::new() } else { - let truncated = if summary.len() > 50 { - format!("{}...", &summary[..47]) - } else { - summary.to_string() - }; - format!(" {}", truncated) + format!(" {}", truncate_display(summary, 50)) }; println!(" [{}] {}{}", node.kind, node.id, summary_display); } @@ -1811,7 +1811,8 @@ impl Command for PlanExec { for node in &result.nodes { print!(" [{}] {}", node.kind, node.label); if let Some(ref s) = node.summary { - let short = if s.len() > 60 { &s[..60] } else { s }; + // Truncate safely for Unicode text. + let short: String = s.chars().take(60).collect(); print!(": {}", short); } println!(); @@ -1831,7 +1832,8 @@ impl Command for PlanExec { if !result.content.is_empty() { println!("\nContent ({} entries):", result.content.len()); for (path, text) in &result.content { - let preview = if text.len() > 100 { &text[..100] } else { text }; + // Truncate safely for Unicode text. + let preview: String = text.chars().take(100).collect(); println!(" {}: {}...", path, preview.replace('\n', " ")); } } @@ -1965,3 +1967,55 @@ impl Command for QueryAsk { Ok(()) } } + +#[cfg(test)] +mod tests { + use super::truncate_display; + + #[test] + fn test_truncate_display_short_ascii_unchanged() { + assert_eq!(truncate_display("hello", 60), "hello"); + } + + #[test] + fn test_truncate_display_long_ascii_truncated() { + let s = "a".repeat(80); + let out = truncate_display(&s, 60); + assert_eq!(out, format!("{}...", "a".repeat(57))); + } + + #[test] + fn test_truncate_display_exact_limit_unchanged() { + let s = "b".repeat(60); + assert_eq!(truncate_display(&s, 60), s); + } + + #[test] + fn test_truncate_display_three_byte_chars_no_panic() { + // Regression test for three-byte characters. + let s = format!("x{}", "\u{20ac}".repeat(40)); + assert!(s.len() > 60); // byte length exceeds the old byte-based check + assert_eq!(truncate_display(&s, 60), s); // 41 chars: no truncation + } + + #[test] + fn test_truncate_display_three_byte_chars_truncated() { + let s = format!("x{}", "\u{20ac}".repeat(80)); // 81 chars, 241 bytes + let out = truncate_display(&s, 60); + assert_eq!(out, format!("x{}...", "\u{20ac}".repeat(56))); + } + + #[test] + fn test_truncate_display_four_byte_chars_within_limit_unchanged() { + // Regression test for four-byte characters. + let s = "\u{1f680}".repeat(40); + assert_eq!(truncate_display(&s, 50), s); + } + + #[test] + fn test_truncate_display_four_byte_chars_truncated() { + let s = "\u{1f680}".repeat(80); + let out = truncate_display(&s, 50); + assert_eq!(out, format!("{}...", "\u{1f680}".repeat(47))); + } +} diff --git a/atomic-cli/src/commands/team/delete.rs b/atomic-cli/src/commands/team/delete.rs index c5521df2..3cb21528 100644 --- a/atomic-cli/src/commands/team/delete.rs +++ b/atomic-cli/src/commands/team/delete.rs @@ -85,8 +85,19 @@ impl Command for TeamDelete { impl TeamDelete { async fn execute(&self) -> CliResult<()> { - // Prompt for confirmation unless --force is set. + let client = build_client(self.org.as_deref(), None).await?; + let org_slug = client.org_slug().to_string(); + + // `--force` skips both the precheck and confirmation. if !self.force { + // Check that the team exists before prompting. + atomic_teams::team::get_team(&client, &org_slug, &self.slug) + .await + .map_err(|e| CliError::RemoteError { + message: e.to_string(), + url: None, + })?; + print_warning(&format!( "This will permanently delete team '{}' and all its memberships and grants.", self.slug @@ -105,9 +116,6 @@ impl TeamDelete { } } - let client = build_client(self.org.as_deref(), None).await?; - let org_slug = client.org_slug().to_string(); - atomic_teams::team::delete_team(&client, &org_slug, &self.slug) .await .map_err(|e| CliError::RemoteError { diff --git a/atomic-cli/src/commands/workspace/delete.rs b/atomic-cli/src/commands/workspace/delete.rs index 4e829fa4..41e91c59 100644 --- a/atomic-cli/src/commands/workspace/delete.rs +++ b/atomic-cli/src/commands/workspace/delete.rs @@ -71,8 +71,13 @@ impl Command for WorkspaceDelete { .map_err(|e| CliError::Internal(anyhow::anyhow!("{}", e)))?; rt.block_on(async { - // Confirm unless --force is set. + let (client, org_slug) = build_client_with_org(self.org.as_deref(), None).await?; + + // `--force` skips both the precheck and confirmation. if !self.force { + // Check that the workspace exists before prompting. + client.get_workspace(&self.slug).await.map_err(remote_err)?; + print_warning(&format!( "This will permanently delete workspace '{}' and all its projects.", self.slug @@ -90,8 +95,6 @@ impl Command for WorkspaceDelete { } } - let (client, org_slug) = build_client_with_org(self.org.as_deref(), None).await?; - client .delete_workspace(&self.slug) .await