Skip to content

Commit 42c3300

Browse files
author
Factory Bot
committed
fix: clippy fixes and add missing TaskStartedEvent import
1 parent 16bf76a commit 42c3300

28 files changed

Lines changed: 131 additions & 159 deletions

File tree

cortex-cli/src/main.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -822,19 +822,19 @@ async fn list_sessions(
822822
}
823823

824824
// Parse session timestamp for date filtering
825-
if since_date.is_some() || until_date.is_some() {
826-
if let Ok(session_time) = DateTime::parse_from_rfc3339(&s.timestamp) {
827-
let session_utc = session_time.with_timezone(&Utc);
828-
if let Some(ref since) = since_date {
829-
if session_utc < *since {
830-
return false;
831-
}
832-
}
833-
if let Some(ref until) = until_date {
834-
if session_utc > *until {
835-
return false;
836-
}
837-
}
825+
if (since_date.is_some() || until_date.is_some())
826+
&& let Ok(session_time) = DateTime::parse_from_rfc3339(&s.timestamp)
827+
{
828+
let session_utc = session_time.with_timezone(&Utc);
829+
if let Some(ref since) = since_date
830+
&& session_utc < *since
831+
{
832+
return false;
833+
}
834+
if let Some(ref until) = until_date
835+
&& session_utc > *until
836+
{
837+
return false;
838838
}
839839
}
840840

cortex-cli/src/run_cmd.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -764,18 +764,18 @@ impl RunCli {
764764
if error_occurred {
765765
// If it was a new session and an error occurred, we should probably clean up
766766
// the history entry so it doesn't pollute the logs with failed runs.
767-
if let SessionMode::New { .. } = &session_mode {
768-
if let Ok(conv_id) = ConversationId::from_string(&session_id) {
769-
let rollout_path =
770-
cortex_engine::rollout::get_rollout_path(&config.cortex_home, &conv_id);
771-
if rollout_path.exists() {
772-
if let Err(e) = std::fs::remove_file(&rollout_path) {
773-
if self.verbose {
774-
eprintln!("Failed to remove failed session history: {}", e);
775-
}
776-
} else if self.verbose {
777-
eprintln!("Removed failed session history: {}", session_id);
767+
if let SessionMode::New { .. } = &session_mode
768+
&& let Ok(conv_id) = ConversationId::from_string(&session_id)
769+
{
770+
let rollout_path =
771+
cortex_engine::rollout::get_rollout_path(&config.cortex_home, &conv_id);
772+
if rollout_path.exists() {
773+
if let Err(e) = std::fs::remove_file(&rollout_path) {
774+
if self.verbose {
775+
eprintln!("Failed to remove failed session history: {}", e);
778776
}
777+
} else if self.verbose {
778+
eprintln!("Removed failed session history: {}", session_id);
779779
}
780780
}
781781
}

cortex-cli/src/uninstall_cmd.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,7 @@ fn collect_windows_items() -> Result<Vec<RemovalItem>> {
558558
}
559559

560560
/// Collect shell completion file locations.
561-
fn collect_completion_items(home_dir: &Path) -> Result<Vec<RemovalItem>> {
561+
fn collect_completion_items(_home_dir: &Path) -> Result<Vec<RemovalItem>> {
562562
let mut items = Vec::new();
563563

564564
#[cfg(not(target_os = "windows"))]
@@ -827,7 +827,7 @@ fn validate_path_safety(path: &Path) -> Result<()> {
827827

828828
/// Clean up shell completion references from rc files.
829829
fn clean_shell_completions() -> Result<()> {
830-
let home_dir = dirs::home_dir().context("Could not determine home directory")?;
830+
let _home_dir = dirs::home_dir().context("Could not determine home directory")?;
831831

832832
#[cfg(not(target_os = "windows"))]
833833
{

cortex-common/src/sanitize.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
//! String and path sanitization utilities
22
3-
use std::path::{Path, PathBuf};
4-
53
/// Sanitize a filename by removing/replacing unsafe characters
64
pub fn sanitize_filename(filename: &str) -> String {
75
filename

cortex-engine/src/auth_manager.rs

Lines changed: 30 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ use secrecy::{ExposeSecret, SecretString};
3636
use serde::{Deserialize, Serialize};
3737
use thiserror::Error;
3838
use tokio::sync::RwLock;
39-
use tracing::{debug, error, info, trace, warn};
39+
use tracing::{debug, info, trace, warn};
4040

4141
/// Default service name for keyring entries.
4242
const KEYRING_SERVICE: &str = "Cortex-cli";
@@ -253,23 +253,14 @@ impl AuthManagerConfig {
253253
}
254254

255255
/// Cached authentication state.
256-
#[derive(Debug)]
256+
#[derive(Debug, Default)]
257257
struct CachedAuth {
258258
/// The cached token.
259259
token: Option<AuthToken>,
260260
/// Time of last refresh.
261261
last_refresh: Option<Instant>,
262262
}
263263

264-
impl Default for CachedAuth {
265-
fn default() -> Self {
266-
Self {
267-
token: None,
268-
last_refresh: None,
269-
}
270-
}
271-
}
272-
273264
/// Centralized authentication manager providing a single source of truth
274265
/// for authentication state across the Cortex CLI application.
275266
///
@@ -328,11 +319,12 @@ impl AuthManager {
328319
// First check cache
329320
{
330321
let cache = self.cache.read().await;
331-
if let Some(ref token) = cache.token {
332-
if !token.is_expired() && !token.expires_soon(self.config.refresh_threshold_secs) {
333-
trace!("AuthManager.auth: returning cached token");
334-
return Ok(token.clone());
335-
}
322+
if let Some(ref token) = cache.token
323+
&& !token.is_expired()
324+
&& !token.expires_soon(self.config.refresh_threshold_secs)
325+
{
326+
trace!("AuthManager.auth: returning cached token");
327+
return Ok(token.clone());
336328
}
337329
}
338330

@@ -392,10 +384,10 @@ impl AuthManager {
392384

393385
// Clear auth file if exists
394386
let auth_file = self.config.cortex_home.join("auth.json");
395-
if auth_file.exists() {
396-
if let Err(e) = tokio::fs::remove_file(&auth_file).await {
397-
warn!("AuthManager.logout: failed to remove auth file: {}", e);
398-
}
387+
if auth_file.exists()
388+
&& let Err(e) = tokio::fs::remove_file(&auth_file).await
389+
{
390+
warn!("AuthManager.logout: failed to remove auth file: {}", e);
399391
}
400392

401393
Ok(())
@@ -511,7 +503,7 @@ impl AuthManager {
511503
.and_then(|t| t.refresh_token().map(|s| s.to_string()))
512504
};
513505

514-
let refresh_token = refresh_token
506+
let _refresh_token = refresh_token
515507
.ok_or_else(|| AuthError::RefreshFailed("No refresh token available".to_string()))?;
516508

517509
// Note: Actual token refresh would be implemented here
@@ -527,11 +519,11 @@ impl AuthManager {
527519
trace!("AuthManager.load_from_storage: loading credentials");
528520

529521
// Check environment variables first if enabled
530-
if self.config.enable_env_api_key {
531-
if let Some(token) = self.load_from_env() {
532-
debug!("AuthManager: loaded credentials from environment");
533-
return Ok(Some(token));
534-
}
522+
if self.config.enable_env_api_key
523+
&& let Some(token) = self.load_from_env()
524+
{
525+
debug!("AuthManager: loaded credentials from environment");
526+
return Ok(Some(token));
535527
}
536528

537529
// Try to load from keyring
@@ -626,23 +618,23 @@ impl AuthManager {
626618
serde_json::from_str(&content).map_err(|e| AuthError::ParseError(e.to_string()))?;
627619

628620
// Check for API key
629-
if let Some(api_key) = auth_data.get("OPENAI_API_KEY").and_then(|v| v.as_str()) {
630-
if !api_key.is_empty() {
631-
return Ok(Some(AuthToken::new(api_key, "Bearer", "openai")));
632-
}
621+
if let Some(api_key) = auth_data.get("OPENAI_API_KEY").and_then(|v| v.as_str())
622+
&& !api_key.is_empty()
623+
{
624+
return Ok(Some(AuthToken::new(api_key, "Bearer", "openai")));
633625
}
634626

635627
// Check for tokens
636-
if let Some(tokens) = auth_data.get("tokens") {
637-
if let Some(access_token) = tokens.get("access_token").and_then(|v| v.as_str()) {
638-
let mut token = AuthToken::new(access_token, "Bearer", "chatgpt");
639-
640-
if let Some(refresh_token) = tokens.get("refresh_token").and_then(|v| v.as_str()) {
641-
token = token.with_refresh_token(refresh_token);
642-
}
628+
if let Some(tokens) = auth_data.get("tokens")
629+
&& let Some(access_token) = tokens.get("access_token").and_then(|v| v.as_str())
630+
{
631+
let mut token = AuthToken::new(access_token, "Bearer", "chatgpt");
643632

644-
return Ok(Some(token));
633+
if let Some(refresh_token) = tokens.get("refresh_token").and_then(|v| v.as_str()) {
634+
token = token.with_refresh_token(refresh_token);
645635
}
636+
637+
return Ok(Some(token));
646638
}
647639

648640
Ok(None)

cortex-engine/src/permission/prompts.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,8 @@ impl PermissionPrompt {
145145
let mut output = String::new();
146146

147147
// Header
148-
output.push_str(&"🔐 Permission Request\n".to_string());
149-
output.push_str(&"─────────────────────\n".to_string());
148+
output.push_str("🔐 Permission Request\n");
149+
output.push_str("─────────────────────\n");
150150

151151
// Tool and action
152152
output.push_str(&format!("Tool: {}\n", self.tool));

cortex-engine/src/sandbox/windows.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ pub async fn spawn_sandboxed_process(
248248
let mut cmd = Command::new(&command[0]);
249249
cmd.args(&command[1..]).current_dir(cwd).envs(env);
250250

251-
return cmd.spawn().map_err(|e| crate::error::CortexError::Io(e));
251+
return cmd.spawn().map_err(crate::error::CortexError::Io);
252252
}
253253

254254
let config = WindowsBackend::create_sandbox_config(policy, writable_roots);
@@ -275,7 +275,7 @@ pub async fn spawn_sandboxed_process(
275275
cmd.env(CORTEX_SANDBOX_NETWORK_DISABLED_ENV_VAR, "1");
276276
}
277277

278-
cmd.spawn().map_err(|e| crate::error::CortexError::Io(e))
278+
cmd.spawn().map_err(crate::error::CortexError::Io)
279279
}
280280
Err(e) => {
281281
warn!(
@@ -287,7 +287,7 @@ pub async fn spawn_sandboxed_process(
287287
let mut cmd = Command::new(&command[0]);
288288
cmd.args(&command[1..]).current_dir(cwd).envs(env);
289289

290-
cmd.spawn().map_err(|e| crate::error::CortexError::Io(e))
290+
cmd.spawn().map_err(crate::error::CortexError::Io)
291291
}
292292
}
293293
}

cortex-engine/src/skills/mod.rs

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -174,12 +174,12 @@ impl SkillMetadata {
174174
}
175175

176176
// Short description validation: max 1024 chars
177-
if let Some(ref short_desc) = self.short_description {
178-
if short_desc.len() > MAX_SHORT_DESCRIPTION_LEN {
179-
return Err(CortexError::InvalidInput(format!(
180-
"Skill short_description must be at most {MAX_SHORT_DESCRIPTION_LEN} characters"
181-
)));
182-
}
177+
if let Some(ref short_desc) = self.short_description
178+
&& short_desc.len() > MAX_SHORT_DESCRIPTION_LEN
179+
{
180+
return Err(CortexError::InvalidInput(format!(
181+
"Skill short_description must be at most {MAX_SHORT_DESCRIPTION_LEN} characters"
182+
)));
183183
}
184184

185185
Ok(())
@@ -355,11 +355,11 @@ impl SkillRegistry {
355355
// This ensures higher priority skills overwrite lower priority ones in the registry
356356

357357
// 4. Admin skills (lowest priority, Unix only)
358-
if let Some(ref admin_dir) = self.admin_dir {
359-
if admin_dir.exists() {
360-
let skills = self.scan_directory(admin_dir, SkillScope::Admin)?;
361-
all_skills.extend(skills);
362-
}
358+
if let Some(ref admin_dir) = self.admin_dir
359+
&& admin_dir.exists()
360+
{
361+
let skills = self.scan_directory(admin_dir, SkillScope::Admin)?;
362+
all_skills.extend(skills);
363363
}
364364

365365
// 3. System/plugin skills
@@ -377,11 +377,11 @@ impl SkillRegistry {
377377
}
378378

379379
// 1. Repo skills (highest priority)
380-
if let Some(ref repo_dir) = self.repo_dir {
381-
if repo_dir.exists() {
382-
let skills = self.scan_directory(repo_dir, SkillScope::Repo)?;
383-
all_skills.extend(skills);
384-
}
380+
if let Some(ref repo_dir) = self.repo_dir
381+
&& repo_dir.exists()
382+
{
383+
let skills = self.scan_directory(repo_dir, SkillScope::Repo)?;
384+
all_skills.extend(skills);
385385
}
386386

387387
// Register all skills (later entries overwrite earlier ones with same name)
@@ -462,10 +462,9 @@ impl SkillRegistry {
462462
if matches!(
463463
ext,
464464
"md" | "py" | "sh" | "js" | "ts" | "json" | "yaml" | "yml" | "txt"
465-
) {
466-
if let Some(name) = path.file_name().and_then(|n| n.to_str()) {
467-
files.push(name.to_string());
468-
}
465+
) && let Some(name) = path.file_name().and_then(|n| n.to_str())
466+
{
467+
files.push(name.to_string());
469468
}
470469

471470
// Include script directories

cortex-engine/src/thread_manager/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ mod tests;
1414

1515
use once_cell::sync::OnceCell;
1616
use std::sync::Arc;
17-
use tokio::sync::RwLock;
1817

1918
pub use state::*;
2019
pub use thread::*;

cortex-engine/src/tools/handlers/edit_file.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,8 @@ fn atomic_write_file(path: &Path, content: &str) -> std::io::Result<()> {
106106
}
107107
}
108108
}
109-
fs::rename(&temp_path, path).map_err(|e| {
109+
fs::rename(&temp_path, path).inspect_err(|e| {
110110
let _ = fs::remove_file(&temp_path);
111-
e
112111
})?;
113112
}
114113

0 commit comments

Comments
 (0)