Limit search output.

This commit is contained in:
Christian Gunderman
2026-01-28 22:27:49 -08:00
parent cbe4fc9a89
commit 9f0d2b92f0
3 changed files with 93 additions and 7 deletions
+11 -5
View File
@@ -46,6 +46,11 @@ export interface GrepToolParams {
* File pattern to include in the search (e.g. "*.js", "*.{ts,tsx}")
*/
include?: string;
/**
* Max number of matches to return. Defaults to 20,000.
*/
limit?: number;
}
/**
@@ -184,7 +189,7 @@ class GrepToolInvocation extends BaseToolInvocation<
// Collect matches from all search directories
let allMatches: GrepMatch[] = [];
const totalMaxMatches = DEFAULT_TOTAL_MAX_MATCHES;
const totalMaxMatches = this.params.limit ?? DEFAULT_TOTAL_MAX_MATCHES;
// Create a timeout controller to prevent indefinitely hanging searches
const timeoutController = new AbortController();
@@ -352,10 +357,6 @@ class GrepToolInvocation extends BaseToolInvocation<
'--ignore-case',
pattern,
];
if (include) {
gitArgs.push('--', include);
}
try {
const generator = execStreaming('git', gitArgs, {
cwd: absolutePath,
@@ -587,6 +588,11 @@ export class GrepTool extends BaseDeclarativeTool<GrepToolParams, ToolResult> {
description: `Optional: A glob pattern to filter which files are searched (e.g., '*.js', '*.{ts,tsx}', 'src/**'). If omitted, searches all files (respecting potential global ignores).`,
type: 'string',
},
limit: {
description:
'Optional: Max number of matches to return. Defaults to 20,000.',
type: 'integer',
},
},
required: ['pattern'],
type: 'object',
+10 -1
View File
@@ -131,6 +131,11 @@ export interface RipGrepToolParams {
* If true, does not respect .gitignore or default ignores (like build/dist).
*/
no_ignore?: boolean;
/**
* Max number of matches to return. Defaults to 20,000.
*/
limit?: number;
}
/**
@@ -204,7 +209,7 @@ class GrepToolInvocation extends BaseToolInvocation<
const searchDirDisplay = pathParam;
const totalMaxMatches = DEFAULT_TOTAL_MAX_MATCHES;
const totalMaxMatches = this.params.limit ?? DEFAULT_TOTAL_MAX_MATCHES;
if (this.config.getDebugMode()) {
debugLogger.log(`[GrepTool] Total result limit: ${totalMaxMatches}`);
}
@@ -530,6 +535,10 @@ export class RipGrepTool extends BaseDeclarativeTool<
'If true, searches all files including those usually ignored (like in .gitignore, build/, dist/, etc). Defaults to false if omitted.',
type: 'boolean',
},
limit: {
description: 'Max number of matches to return. Defaults to 20,000.',
type: 'integer',
},
},
required: ['pattern'],
type: 'object',