batch3 T4 review fixes: harmonize find_files cap; delegate to file_ops

- file_ops.MAX_FIND_RESULTS: 1000 -> 200 to match existing tool cap and
  preserve LLM behavior
- tools.find_files now delegates to file_ops.findFiles (parallels how
  grep already delegates); drops ~50 LOC of duplicated path resolution
  and rg subprocess
- Drop unused basename import in file_ops

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-15 15:18:44 +00:00
parent 890d229875
commit 89f1b7e862
2 changed files with 20 additions and 50 deletions

View File

@@ -1,5 +1,5 @@
import { readFile, readdir, stat } from 'node:fs/promises';
import { resolve, basename, relative } from 'node:path';
import { resolve, relative } from 'node:path';
import { spawn } from 'node:child_process';
import type { Stats } from 'node:fs';
import { pathGuard, PathScopeError } from './path_guard.js';
@@ -8,7 +8,7 @@ const MAX_FILE_BYTES = 5 * 1024 * 1024;
const DEFAULT_VIEW_LINES = 200;
const MAX_GREP_RESULTS = 200;
const DEFAULT_GREP_RESULTS = 100;
const MAX_FIND_RESULTS = 1000;
const MAX_FIND_RESULTS = 200;
const DEFAULT_FIND_RESULTS = 100;
const MAX_DIR_ENTRIES = 500;
@@ -44,6 +44,7 @@ export interface GrepResult {
export interface FindFilesResult {
files: string[];
total: number;
truncated: boolean;
}
@@ -195,15 +196,18 @@ export async function grep(
export async function findFiles(
projectRoot: string,
pattern?: string,
opts?: { type?: 'file' | 'dir'; max_results?: number }
opts?: { type?: 'file' | 'dir'; max_results?: number; path?: string }
): Promise<FindFilesResult> {
const limit = Math.min(
Math.max(opts?.max_results ?? DEFAULT_FIND_RESULTS, 1),
MAX_FIND_RESULTS
);
const target = opts?.path != null
? await pathGuard(projectRoot, opts.path)
: projectRoot;
const args = ['--files'];
if (pattern) args.push('--glob', pattern);
args.push(projectRoot);
args.push(target);
return new Promise((resolveP, rejectP) => {
const child = spawn('rg', args, { cwd: projectRoot });
@@ -243,6 +247,7 @@ export async function findFiles(
}
resolveP({
files,
total,
truncated: total > files.length,
});
});