fix(coding-agent-find-tool): corrected find glob ordering by mtime
- Propagated `combinedSignal` into `doGlob` so cancellation is honored during glob execution. - Skipped fallback `doGlob(false)` when `timeoutSignal` was aborted to avoid redundant work. - Sorted `result.matches` by descending `mtime` in JS to return the most recent hits first.
This commit is contained in:
@@ -244,6 +244,7 @@ export class FindTool implements AgentTool<typeof findSchema, FindToolDetails> {
|
||||
maxResults: effectiveLimit,
|
||||
sortByMtime: true,
|
||||
gitignore: useGitignore,
|
||||
signal: combinedSignal,
|
||||
},
|
||||
onMatch,
|
||||
this.session.searchDb,
|
||||
@@ -252,9 +253,12 @@ export class FindTool implements AgentTool<typeof findSchema, FindToolDetails> {
|
||||
|
||||
try {
|
||||
let result = await doGlob(true);
|
||||
if (result.matches.length === 0) {
|
||||
if (result.matches.length === 0 && !timeoutSignal.aborted) {
|
||||
result = await doGlob(false);
|
||||
}
|
||||
// Sort by mtime descending (most recent first) in JS instead of native.
|
||||
// This allows native glob to early-terminate at maxResults.
|
||||
result.matches.sort((a, b) => (b.mtime ?? 0) - (a.mtime ?? 0));
|
||||
matches = result.matches;
|
||||
} catch (error) {
|
||||
if (error instanceof Error && error.name === "AbortError") {
|
||||
|
||||
Reference in New Issue
Block a user