Skip to content

Commit facb420

Browse files
Yogthosyogthos
authored andcommitted
Fix glob-tool: remove unused dep, fix mtime sort, drop noise
- Remove unused 'glob' crate dependency from Cargo.toml - Fix mtime sort: store absolute paths for metadata lookups so sort works correctly when path param is not CWD - Return empty string on no matches (consistent with other tools) - Remove redundant is_skip_dir parent check (WalkBuilder handles .gitignore)
1 parent 6144361 commit facb420

3 files changed

Lines changed: 15 additions & 26 deletions

File tree

Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ base64 = "0.22"
6565
streaming-iterator = { version = "0.1", optional = true }
6666
janetrs = { version = "0.8", optional = true }
6767
html2text = "0.17"
68-
glob = "0.3.3"
6968

7069
[profile.release]
7170
opt-level = "z"

src/agent/tools/glob.rs

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use serde::Deserialize;
55
use std::path::Path;
66

77
use crate::agent::tools::{AskSender, PermCheck, ToolError, check_perm};
8-
use crate::agent::tools::{MAX_FIND_RESULTS, is_skip_dir};
8+
use crate::agent::tools::MAX_FIND_RESULTS;
99

1010
pub struct GlobTool {
1111
pub permission: Option<PermCheck>,
@@ -70,7 +70,7 @@ impl Tool for GlobTool {
7070
async fn definition(&self, _prompt: String) -> ToolDefinition {
7171
ToolDefinition {
7272
name: "glob".to_string(),
73-
description: "Find files matching a glob pattern (e.g., '**/*.rs', 'src/**/*.tsx'). Respects .gitignore. Returns matching file paths sorted by modification time. Use this for natural path pattern matching instead of regex-based find_files."
73+
description: "Find files matching a glob pattern (e.g., '**/*.rs', 'src/**/*.tsx'). Respects .gitignore via ignore crate. Returns matching relative file paths sorted by modification time (newest first). Returns empty string when no files match. Use this for natural path pattern matching instead of regex-based find_files."
7474
.to_string(),
7575
parameters: serde_json::json!({
7676
"type": "object",
@@ -108,7 +108,7 @@ impl Tool for GlobTool {
108108
.filter(|p| p.is_dir())
109109
.unwrap_or_else(|| Path::new("."));
110110

111-
let mut matches: Vec<String> = Vec::new();
111+
let mut matches: Vec<(String, std::path::PathBuf)> = Vec::new();
112112

113113
let walker = WalkBuilder::new(root)
114114
.hidden(false)
@@ -123,25 +123,15 @@ impl Tool for GlobTool {
123123
continue;
124124
}
125125

126-
let path = entry.path();
127-
let relative = path
126+
let abs_path = entry.path().to_path_buf();
127+
let relative = abs_path
128128
.strip_prefix(root)
129-
.unwrap_or(path)
129+
.unwrap_or(&abs_path)
130130
.to_string_lossy()
131131
.into_owned();
132132

133-
// Skip ignored dirs
134-
if let Some(parent) = path.parent() {
135-
if parent
136-
.file_name()
137-
.map_or(false, |n| is_skip_dir(&n.to_string_lossy()))
138-
{
139-
continue;
140-
}
141-
}
142-
143133
if re.is_match(&relative) {
144-
matches.push(relative);
134+
matches.push((relative, abs_path));
145135
}
146136

147137
if matches.len() >= MAX_FIND_RESULTS {
@@ -150,23 +140,24 @@ impl Tool for GlobTool {
150140
}
151141

152142
// Sort by modification time (newest first), fall back to alphabetical
153-
matches.sort_by(|a, b| {
154-
let ma = std::fs::metadata(a)
143+
matches.sort_by(|(_, abs_a), (_, abs_b)| {
144+
let ma = std::fs::metadata(abs_a)
155145
.ok()
156146
.and_then(|m| m.modified().ok());
157-
let mb = std::fs::metadata(b)
147+
let mb = std::fs::metadata(abs_b)
158148
.ok()
159149
.and_then(|m| m.modified().ok());
160150
match (ma, mb) {
161151
(Some(a), Some(b)) => b.cmp(&a),
162-
_ => a.cmp(b),
152+
_ => abs_a.cmp(abs_b),
163153
}
164154
});
165155

166-
if matches.is_empty() {
167-
Ok("no files matched".to_string())
156+
let results: Vec<String> = matches.into_iter().map(|(rel, _)| rel).collect();
157+
if results.is_empty() {
158+
Ok(String::new())
168159
} else {
169-
Ok(matches.join("\n"))
160+
Ok(results.join("\n"))
170161
}
171162
}
172163
}

0 commit comments

Comments
 (0)