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
@@ -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())
}