From 631882495fb1c2e900e0624f8d23446c6a2bfc6a Mon Sep 17 00:00:00 2001 From: liwenkai <2020583117@qq.com> Date: Fri, 26 Jun 2026 14:36:08 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=B6=88=E9=99=A4=20clippy=201.96=20?= =?UTF-8?q?=E5=91=8A=E8=AD=A6(=E6=B2=99=E7=AE=B1=E5=A4=9A=E4=BD=99=20cast/?= =?UTF-8?q?return=E3=80=81=E6=97=A2=E6=9C=89=20sort=5Fby=E2=86=92sort=5Fby?= =?UTF-8?q?=5Fkey=E3=80=81cache=20=E7=94=A8=20checked=5Fdiv)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/deep-code-agent/src/sandbox/linux.rs | 24 +++++++++---------- crates/deep-code-agent/src/sandbox/mod.rs | 4 ++-- .../deep-code-agent/src/session_store/json.rs | 2 +- .../deep-code-agent/src/subagent/manager.rs | 2 +- crates/deep-code-runtime/src/threads.rs | 2 +- crates/deep-code-tui/src/commands.rs | 8 +++---- 6 files changed, 20 insertions(+), 22 deletions(-) diff --git a/crates/deep-code-agent/src/sandbox/linux.rs b/crates/deep-code-agent/src/sandbox/linux.rs index 2210561..fbe5f4f 100644 --- a/crates/deep-code-agent/src/sandbox/linux.rs +++ b/crates/deep-code-agent/src/sandbox/linux.rs @@ -40,22 +40,22 @@ const LANDLOCK_ABI: ABI = ABI::V1; /// Always-blocked syscalls (escape / privilege / host-tampering). Limited to /// numbers present on both x86_64 and aarch64. const DANGEROUS_SYSCALLS: &[i64] = &[ - libc::SYS_ptrace as i64, - libc::SYS_mount as i64, - libc::SYS_umount2 as i64, - libc::SYS_pivot_root as i64, - libc::SYS_chroot as i64, - libc::SYS_reboot as i64, - libc::SYS_kexec_load as i64, - libc::SYS_init_module as i64, - libc::SYS_finit_module as i64, - libc::SYS_delete_module as i64, - libc::SYS_bpf as i64, + libc::SYS_ptrace, + libc::SYS_mount, + libc::SYS_umount2, + libc::SYS_pivot_root, + libc::SYS_chroot, + libc::SYS_reboot, + libc::SYS_kexec_load, + libc::SYS_init_module, + libc::SYS_finit_module, + libc::SYS_delete_module, + libc::SYS_bpf, ]; /// Blocked when the policy forbids network. Denying `socket` stops any new /// socket (no network of any family); `connect` is belt-and-suspenders. -const NETWORK_SYSCALLS: &[i64] = &[libc::SYS_socket as i64, libc::SYS_connect as i64]; +const NETWORK_SYSCALLS: &[i64] = &[libc::SYS_socket, libc::SYS_connect]; /// Write-class access rights: everything Landlock can govern minus the /// read/execute rights, so reads stay unrestricted. diff --git a/crates/deep-code-agent/src/sandbox/mod.rs b/crates/deep-code-agent/src/sandbox/mod.rs index 4986c61..87194bb 100644 --- a/crates/deep-code-agent/src/sandbox/mod.rs +++ b/crates/deep-code-agent/src/sandbox/mod.rs @@ -72,12 +72,12 @@ pub fn detect_capabilities() -> SandboxCapabilities { #[cfg(target_os = "linux")] { - return linux::capabilities(); + linux::capabilities() } #[cfg(target_os = "windows")] { - return windows::capabilities(); + windows::capabilities() } #[cfg(not(any(target_os = "macos", target_os = "linux", target_os = "windows")))] diff --git a/crates/deep-code-agent/src/session_store/json.rs b/crates/deep-code-agent/src/session_store/json.rs index 92ca8b6..298b75f 100644 --- a/crates/deep-code-agent/src/session_store/json.rs +++ b/crates/deep-code-agent/src/session_store/json.rs @@ -149,7 +149,7 @@ impl SessionStore for JsonSessionStore { } } - records.sort_by(|left, right| right.updated_at_ms.cmp(&left.updated_at_ms)); + records.sort_by_key(|record| std::cmp::Reverse(record.updated_at_ms)); Ok(records) } diff --git a/crates/deep-code-agent/src/subagent/manager.rs b/crates/deep-code-agent/src/subagent/manager.rs index 23efb1d..603bfcf 100644 --- a/crates/deep-code-agent/src/subagent/manager.rs +++ b/crates/deep-code-agent/src/subagent/manager.rs @@ -72,7 +72,7 @@ impl SubAgentManager { .filter(|agent| agent.session_boot_id.as_deref() == Some(self.session_boot_id.as_str())) .cloned() .collect(); - agents.sort_by(|left, right| right.started_at_ms.cmp(&left.started_at_ms)); + agents.sort_by_key(|agent| std::cmp::Reverse(agent.started_at_ms)); agents } diff --git a/crates/deep-code-runtime/src/threads.rs b/crates/deep-code-runtime/src/threads.rs index 52a6e89..b7f9aef 100644 --- a/crates/deep-code-runtime/src/threads.rs +++ b/crates/deep-code-runtime/src/threads.rs @@ -176,7 +176,7 @@ impl RuntimeThreadStore { pub async fn list_threads(&self) -> Vec { let mut threads = self.inner.lock().await.threads.clone(); - threads.sort_by(|left, right| right.updated_at_ms.cmp(&left.updated_at_ms)); + threads.sort_by_key(|thread| std::cmp::Reverse(thread.updated_at_ms)); threads } diff --git a/crates/deep-code-tui/src/commands.rs b/crates/deep-code-tui/src/commands.rs index b497bfe..fe3dae3 100644 --- a/crates/deep-code-tui/src/commands.rs +++ b/crates/deep-code-tui/src/commands.rs @@ -404,11 +404,9 @@ impl App { /// Cache hit rate as a percentage, or `None` when no prompt tokens were billed. pub(crate) fn cache_hit_percent(hit: u32, miss: u32) -> Option { let total = u64::from(hit) + u64::from(miss); - if total == 0 { - None - } else { - Some((u64::from(hit) * 100 / total) as u8) - } + (u64::from(hit) * 100) + .checked_div(total) + .map(|percent| percent as u8) } pub(crate) fn format_turn_telemetry(telemetry: &TurnTelemetry, currency: CostCurrency) -> String {