docs: tambah doc comment, logging, dan inline comments di semua 255 file
Meliputi: - File-level //! doc comment: tujuan file, alur kerja, komponen utama - Function-level /// doc comment: apa, parameter, return, flow, edge cases - Struct/enum/trait /// doc comment: peran, field docs - Tracing logging (tracing::info!/debug!/trace!/warn!/error!) di setiap fungsi - Inline comments untuk variable dan branching logic penting - Seluruh 8 crates di workspace: zesdex-backend, zesdex-cms, zesdex-entities, zesdex-iam, zesdex-infra, zesdex-ipc, zesdex-middleware, zesdex-utils - Build: 0 errors, 242/242 tests passed
This commit is contained in:
@@ -1,4 +1,8 @@
|
||||
//! Text search tools: `grep` (line matching) and `glob` (filename pattern matching).
|
||||
//!
|
||||
//! Both tools use `ignore::Walk` under the hood, which respects `.gitignore` and skips
|
||||
//! heavy directories (`.git/`, `node_modules/`, etc.), matching what agents expect
|
||||
//! when searching real codebases.
|
||||
use super::resolve_path;
|
||||
use super::Tool;
|
||||
use super::ToolCtx;
|
||||
@@ -7,6 +11,7 @@ use globset::{GlobBuilder, GlobSetBuilder};
|
||||
use ignore::Walk;
|
||||
use serde_json::{json, Value};
|
||||
use std::fs;
|
||||
use tracing;
|
||||
|
||||
/// Tool that recursively searches text files under a directory for a literal substring.
|
||||
pub struct Grep;
|
||||
@@ -51,13 +56,14 @@ impl Tool for Grep {
|
||||
let pattern = crate::tool::arg_str(args, "pattern")?;
|
||||
let rel = crate::tool::arg_str(args, "path")?;
|
||||
let path = resolve_path(&ctx.workspaces, &rel)?;
|
||||
tracing::debug!(pattern = %pattern, path = %rel, "Grep::run invoked");
|
||||
if !path.exists() {
|
||||
anyhow::bail!("path '{rel}' does not exist");
|
||||
}
|
||||
if !path.is_dir() {
|
||||
anyhow::bail!("path '{rel}' is not a directory");
|
||||
}
|
||||
let mut results: Vec<(String, usize, String)> = Vec::new();
|
||||
let mut results: Vec<(String, usize, String)> = Vec::new(); // (relative_path, line_no, text)
|
||||
for entry in Walk::new(&path).flatten() {
|
||||
let file_path = entry.path();
|
||||
if !file_path.is_file() {
|
||||
@@ -77,6 +83,7 @@ impl Tool for Grep {
|
||||
}
|
||||
}
|
||||
if results.is_empty() {
|
||||
tracing::debug!(pattern = %pattern, "Grep: no matches found");
|
||||
return Ok(format!("no matches found for '{pattern}' in {rel}"));
|
||||
}
|
||||
let output = results
|
||||
@@ -84,6 +91,7 @@ impl Tool for Grep {
|
||||
.map(|(f, line, text)| format!("{f}:{line}:{text}"))
|
||||
.collect::<Vec<_>>()
|
||||
.join("\n");
|
||||
tracing::debug!(count = results.len(), "Grep: matches found");
|
||||
Ok(format!("found {} matches:\n{}", results.len(), output))
|
||||
}
|
||||
}
|
||||
@@ -132,6 +140,7 @@ impl Tool for Glob {
|
||||
let pat_str = crate::tool::arg_str(args, "pattern")?;
|
||||
let rel = crate::tool::arg_str(args, "path")?;
|
||||
let root = resolve_path(&ctx.workspaces, &rel)?;
|
||||
tracing::debug!(pattern = %pat_str, root = %rel, "Glob::run invoked");
|
||||
if !root.exists() || !root.is_dir() {
|
||||
anyhow::bail!("path '{rel}' is not a valid directory");
|
||||
}
|
||||
@@ -155,8 +164,10 @@ impl Tool for Glob {
|
||||
}
|
||||
matches.sort();
|
||||
if matches.is_empty() {
|
||||
tracing::debug!(pattern = %pat_str, "Glob: no files match");
|
||||
return Ok(format!("no files match '{pat_str}' in {rel}"));
|
||||
}
|
||||
tracing::debug!(count = matches.len(), "Glob: files matched");
|
||||
Ok(matches.join("\n"))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user