Enhance logging and documentation across utility tools and TUI overlays
- Added tracing instrumentation and improved logging messages in the Pong, Todofinish, and Todowrite tools for better debugging and monitoring. - Enhanced documentation comments for clarity on tool functionalities and workflows. - Implemented tracing in WorkflowRun, NoteFinding, ReadFindings, and HiveMind tools to track execution phases and findings. - Updated TUI overlays (e.g., Bash, Clear Confirm, Editor, Effort Level, Help, Key Input, Learning, Loading, MCP, Model Selector, Plan, Quit Confirm, Rewind, Settings, Todo, Usage) with debug logging to capture rendering details. - Improved the status bar and workflow panel rendering with additional debug information. - Added tracing to various utility functions to facilitate better performance monitoring and error tracking.
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
//! Text search tools: Grep (line matching) and Glob (filename pattern matching).
|
||||
//!
|
||||
//! `Grep` searches file contents recursively with regex or literal fallback.
|
||||
//! `Glob` lists files matching a given glob pattern under a directory.
|
||||
|
||||
use crate::tools::{resolve_path, Tool, ToolCtx};
|
||||
use anyhow::Result;
|
||||
@@ -6,7 +9,12 @@ use globset::{GlobBuilder, GlobSetBuilder};
|
||||
use ignore::Walk;
|
||||
use serde_json::{json, Value};
|
||||
use std::fs;
|
||||
use tracing::{debug, info, instrument, warn};
|
||||
|
||||
/// Search for a regex (or literal) pattern in file contents under a directory.
|
||||
///
|
||||
/// Flow: resolve path → walk files → regex-match each line → collect results.
|
||||
/// Falls back to substring search when the pattern is not a valid regex.
|
||||
pub struct Grep;
|
||||
|
||||
impl Tool for Grep {
|
||||
@@ -35,18 +43,22 @@ impl Tool for Grep {
|
||||
})
|
||||
}
|
||||
|
||||
#[instrument(skip(self, ctx, args))]
|
||||
fn run(&self, ctx: &ToolCtx, args: &Value) -> Result<String> {
|
||||
let pattern = crate::tools::arg_str(args, "pattern")?;
|
||||
let rel = crate::tools::arg_str(args, "path")?;
|
||||
let path = resolve_path(&ctx.workspaces, &rel)?;
|
||||
|
||||
if !path.exists() {
|
||||
warn!(rel = %rel, "grep path does not exist");
|
||||
anyhow::bail!("path '{rel}' does not exist");
|
||||
}
|
||||
if !path.is_dir() {
|
||||
warn!(rel = %rel, "grep path is not a directory");
|
||||
anyhow::bail!("path '{rel}' is not a directory");
|
||||
}
|
||||
|
||||
info!(pattern = %pattern, root = %rel, "grep search starting");
|
||||
let mut results: Vec<(String, usize, String)> = Vec::new();
|
||||
for entry in Walk::new(&path).flatten() {
|
||||
let file_path = entry.path();
|
||||
@@ -75,8 +87,10 @@ impl Tool for Grep {
|
||||
}
|
||||
|
||||
if results.is_empty() {
|
||||
debug!(pattern = %pattern, "grep found no matches");
|
||||
return Ok(format!("no matches found for '{pattern}' in {rel}"));
|
||||
}
|
||||
info!(match_count = results.len(), "grep search completed");
|
||||
let output = results
|
||||
.iter()
|
||||
.map(|(f, line, text)| format!("{f}:{line}:{text}"))
|
||||
@@ -86,6 +100,10 @@ impl Tool for Grep {
|
||||
}
|
||||
}
|
||||
|
||||
/// List files matching a glob pattern under a directory root.
|
||||
///
|
||||
/// Flow: resolve root → build glob set from pattern → walk files → filter by
|
||||
/// glob set → sort results.
|
||||
pub struct Glob;
|
||||
|
||||
impl Tool for Glob {
|
||||
@@ -114,15 +132,18 @@ impl Tool for Glob {
|
||||
})
|
||||
}
|
||||
|
||||
#[instrument(skip(self, ctx, args))]
|
||||
fn run(&self, ctx: &ToolCtx, args: &Value) -> Result<String> {
|
||||
let pat_str = crate::tools::arg_str(args, "pattern")?;
|
||||
let rel = crate::tools::arg_str(args, "path")?;
|
||||
let root = resolve_path(&ctx.workspaces, &rel)?;
|
||||
|
||||
if !root.exists() || !root.is_dir() {
|
||||
warn!(rel = %rel, "glob root is not a valid directory");
|
||||
anyhow::bail!("path '{rel}' is not a valid directory");
|
||||
}
|
||||
|
||||
info!(pattern = %pat_str, root = %rel, "glob search starting");
|
||||
let mut builder = GlobSetBuilder::new();
|
||||
let full_pattern = root.join(&pat_str).display().to_string();
|
||||
builder.add(
|
||||
@@ -146,8 +167,10 @@ impl Tool for Glob {
|
||||
}
|
||||
matches.sort();
|
||||
if matches.is_empty() {
|
||||
debug!(pattern = %pat_str, "glob found no matches");
|
||||
return Ok(format!("no files match '{pat_str}' in {rel}"));
|
||||
}
|
||||
info!(match_count = matches.len(), "glob search completed");
|
||||
Ok(matches.join("\n"))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user