style: format seluruh workspace dengan cargo fmt

Menyeragamkan format kode sesuai rustfmt (126 file). Sebelumnya
lefthook pre-commit 'cargo fmt --check' akan gagal pada commit apa pun.
This commit is contained in:
asepharyana
2026-08-27 22:10:28 +07:00
parent 884b19ccb5
commit 7b0b53671f
127 changed files with 1271 additions and 1156 deletions
+38 -12
View File
@@ -74,7 +74,11 @@ impl CastOr<u32> for u128 {
///
/// A UUID-based temporary filename avoids collisions from concurrent writes.
/// Orphaned tmp files are cleaned up on any error after creation.
pub fn write_json_atomic<T: Serialize>(path: &Path, data: &T, mode: Option<u32>) -> std::io::Result<()> {
pub fn write_json_atomic<T: Serialize>(
path: &Path,
data: &T,
mode: Option<u32>,
) -> std::io::Result<()> {
let tmp = path.with_extension(format!("tmp.{}", uuid::Uuid::new_v4()));
let result = (|| -> std::io::Result<()> {
let bytes = serde_json::to_vec_pretty(data)
@@ -95,7 +99,9 @@ pub fn write_json_atomic<T: Serialize>(path: &Path, data: &T, mode: Option<u32>)
std::fs::set_permissions(&tmp, std::fs::Permissions::from_mode(m))?;
}
#[cfg(not(unix))]
{ let _ = m; }
{
let _ = m;
}
}
std::fs::rename(&tmp, path)?;
Ok(())
@@ -160,7 +166,7 @@ pub fn build_workspace_tree(root: &Path, max_files: usize) -> String {
use ignore::WalkBuilder;
let mut tree = String::new();
let mut count = 0;
// hidden(false) allows files like .github to be seen, but it still respects .gitignore
// and ignores .git directories by default.
for entry in WalkBuilder::new(root).hidden(false).build().flatten() {
@@ -168,7 +174,7 @@ pub fn build_workspace_tree(root: &Path, max_files: usize) -> String {
tree.push_str("\n... (truncated)");
break;
}
let path = entry.path();
if let Ok(rel) = path.strip_prefix(root) {
let name = rel.to_string_lossy();
@@ -179,14 +185,14 @@ pub fn build_workspace_tree(root: &Path, max_files: usize) -> String {
let indent = " ".repeat(depth.saturating_sub(1));
let is_dir = entry.file_type().map(|ft| ft.is_dir()).unwrap_or(false);
let suffix = if is_dir { "/" } else { "" };
let filename = entry.file_name().to_string_lossy();
tree.push_str(&format!("{indent}{filename}{suffix}\n"));
count += 1;
}
}
}
tree.trim_end().to_string()
}
@@ -209,14 +215,21 @@ pub fn build_rich_context(root: &Path) -> String {
let os = std::env::consts::OS;
let arch = std::env::consts::ARCH;
let time = chrono::Local::now().to_rfc3339();
ctx.push_str(&format!("Environment: {} ({}), Current Time: {}\n\n", os, arch, time));
ctx.push_str(&format!(
"Environment: {} ({}), Current Time: {}\n\n",
os, arch, time
));
// 2. Custom Rules
let rule_files = [".cursorrules", ".zesdexrules", "claude.md", "agent.md"];
for file in rule_files {
let p = root.join(file);
if let Ok(content) = std::fs::read_to_string(&p) {
ctx.push_str(&format!("### Project Rules ({})\n```\n{}\n```\n\n", file, content.trim()));
ctx.push_str(&format!(
"### Project Rules ({})\n```\n{}\n```\n\n",
file,
content.trim()
));
}
}
@@ -259,7 +272,11 @@ pub fn build_rich_context(root: &Path) -> String {
} else {
content
};
ctx.push_str(&format!("### Tech Stack Manifest ({})\n```\n{}\n```\n\n", file, snippet.trim()));
ctx.push_str(&format!(
"### Tech Stack Manifest ({})\n```\n{}\n```\n\n",
file,
snippet.trim()
));
}
}
@@ -281,7 +298,10 @@ pub fn build_rich_context(root: &Path) -> String {
} else {
content
};
ctx.push_str(&format!("### Project Purpose (README.md)\n```\n{}\n```\n\n", snippet.trim()));
ctx.push_str(&format!(
"### Project Purpose (README.md)\n```\n{}\n```\n\n",
snippet.trim()
));
}
// 7. Recent Git History & Momentum
@@ -297,7 +317,10 @@ pub fn build_rich_context(root: &Path) -> String {
.unwrap_or_default();
if !commits.is_empty() {
ctx.push_str(&format!("### Recent Commits (Momentum)\n```\n{}\n```\n\n", commits));
ctx.push_str(&format!(
"### Recent Commits (Momentum)\n```\n{}\n```\n\n",
commits
));
}
let diff = Command::new("git")
@@ -309,7 +332,10 @@ pub fn build_rich_context(root: &Path) -> String {
.unwrap_or_default();
if !diff.is_empty() {
ctx.push_str(&format!("### Recently Modified Files (Uncommitted)\n```\n{}\n```\n\n", diff));
ctx.push_str(&format!(
"### Recently Modified Files (Uncommitted)\n```\n{}\n```\n\n",
diff
));
}
}