style: format code and apply clippy lint fixes (#941)

This commit is contained in:
Dex Miller
2026-02-06 16:02:57 +08:00
committed by GitHub
parent 92785a8078
commit 95bc0e38df
24 changed files with 135 additions and 127 deletions
+1 -1
View File
@@ -755,7 +755,7 @@ fn launch_macos_open_app(
let output = cmd
.output()
.map_err(|e| format!("启动 {} 失败: {e}", app_name))?;
.map_err(|e| format!("启动 {app_name} 失败: {e}"))?;
if !output.status.success() {
let stderr = String::from_utf8_lossy(&output.stderr);
+2 -2
View File
@@ -12,8 +12,8 @@ mod plugin;
mod prompt;
mod provider;
mod proxy;
mod settings;
mod session_manager;
mod settings;
pub mod skill;
mod stream_check;
mod usage;
@@ -30,8 +30,8 @@ pub use plugin::*;
pub use prompt::*;
pub use provider::*;
pub use proxy::*;
pub use settings::*;
pub use session_manager::*;
pub use settings::*;
pub use skill::*;
pub use stream_check::*;
pub use usage::*;
+1 -1
View File
@@ -20,8 +20,8 @@ mod prompt_files;
mod provider;
mod provider_defaults;
mod proxy;
mod session_manager;
mod services;
mod session_manager;
mod settings;
mod store;
mod tray;
@@ -55,17 +55,12 @@ pub fn load_messages(path: &Path) -> Result<Vec<SessionMessage>, String> {
.and_then(Value::as_str)
.unwrap_or("unknown")
.to_string();
let content = message
.get("content")
.map(extract_text)
.unwrap_or_default();
let content = message.get("content").map(extract_text).unwrap_or_default();
if content.trim().is_empty() {
continue;
}
let ts = value
.get("timestamp")
.and_then(parse_timestamp_to_ms);
let ts = value.get("timestamp").and_then(parse_timestamp_to_ms);
messages.push(SessionMessage { role, content, ts });
}
@@ -127,10 +122,7 @@ fn parse_session(path: &Path) -> Option<SessionMeta> {
None => continue,
};
let text = message
.get("content")
.map(extract_text)
.unwrap_or_default();
let text = message.get("content").map(extract_text).unwrap_or_default();
if text.trim().is_empty() {
continue;
}
@@ -2,8 +2,8 @@ use std::fs::File;
use std::io::{BufRead, BufReader};
use std::path::{Path, PathBuf};
use serde_json::Value;
use regex::Regex;
use serde_json::Value;
use crate::codex_config::get_codex_config_dir;
use crate::session_manager::{SessionMessage, SessionMeta};
@@ -60,17 +60,12 @@ pub fn load_messages(path: &Path) -> Result<Vec<SessionMessage>, String> {
.and_then(Value::as_str)
.unwrap_or("unknown")
.to_string();
let content = payload
.get("content")
.map(extract_text)
.unwrap_or_default();
let content = payload.get("content").map(extract_text).unwrap_or_default();
if content.trim().is_empty() {
continue;
}
let ts = value
.get("timestamp")
.and_then(parse_timestamp_to_ms);
let ts = value.get("timestamp").and_then(parse_timestamp_to_ms);
messages.push(SessionMessage { role, content, ts });
}
@@ -139,10 +134,7 @@ fn parse_session(path: &Path) -> Option<SessionMeta> {
continue;
}
let text = payload
.get("content")
.map(extract_text)
.unwrap_or_default();
let text = payload.get("content").map(extract_text).unwrap_or_default();
if text.trim().is_empty() {
continue;
}
@@ -174,10 +166,9 @@ fn parse_session(path: &Path) -> Option<SessionMeta> {
fn infer_session_id_from_filename(path: &Path) -> Option<String> {
let file_name = path.file_name()?.to_string_lossy();
let re = Regex::new(
r"[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}",
)
.ok()?;
let re =
Regex::new(r"[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}")
.ok()?;
re.find(&file_name).map(|mat| mat.as_str().to_string())
}
@@ -13,7 +13,7 @@ pub fn extract_text(content: &Value) -> String {
Value::String(text) => text.to_string(),
Value::Array(items) => items
.iter()
.filter_map(|item| extract_text_from_item(item))
.filter_map(extract_text_from_item)
.filter(|text| !text.trim().is_empty())
.collect::<Vec<_>>()
.join("\n"),
@@ -68,10 +68,10 @@ pub fn path_basename(value: &str) -> Option<String> {
if trimmed.is_empty() {
return None;
}
let normalized = trimmed.trim_end_matches(|c| c == '/' || c == '\\');
let normalized = trimmed.trim_end_matches(['/', '\\']);
let last = normalized
.split(['/', '\\'])
.last()
.next_back()
.filter(|segment| !segment.is_empty())?;
Some(last.to_string())
}
@@ -32,9 +32,8 @@ fn launch_macos_terminal(command: &str, cwd: Option<&str>) -> Result<(), String>
let script = format!(
r#"tell application "Terminal"
activate
do script "{}"
end tell"#,
escaped
do script "{escaped}"
end tell"#
);
let status = Command::new("osascript")
@@ -59,10 +58,9 @@ fn launch_iterm(command: &str, cwd: Option<&str>) -> Result<(), String> {
activate
create window with default profile
tell current session of current window
write text "{}"
write text "{escaped}"
end tell
end tell"#,
escaped
end tell"#
);
let status = Command::new("osascript")
@@ -88,7 +86,7 @@ fn launch_ghostty(command: &str, cwd: Option<&str>) -> Result<(), String> {
// Note: The user's error output didn't show the working dir arg failure, so we assume flag is okay or we stick to compatible ones.
// Documentation says --working-directory is supported in CLI.
let work_dir_arg = if let Some(dir) = cwd {
format!("--working-directory={}", dir)
format!("--working-directory={dir}")
} else {
"".to_string()
};
@@ -251,7 +249,7 @@ fn build_shell_command(command: &str, cwd: Option<&str>) -> String {
fn shell_escape(value: &str) -> String {
let escaped = value.replace('\\', "\\\\").replace('"', "\\\"");
format!("\"{}\"", escaped)
format!("\"{escaped}\"")
}
fn escape_osascript(value: &str) -> String {