Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions evals/grep_search_functionality.eval.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ describe('grep_search_functionality', () => {
});

evalTest('USUALLY_PASSES', {
name: 'should search only within the specified include glob',
name: 'should search only within the specified include_pattern glob',
files: {
'file.js': 'my_function();',
'file.ts': 'my_function();',
Expand All @@ -105,19 +105,19 @@ describe('grep_search_functionality', () => {
undefined,
(args) => {
const params = JSON.parse(args);
return params.include === '*.js';
return params.include_pattern === '*.js';
},
);
expect(
wasToolCalled,
'Expected grep_search to be called with include: "*.js"',
'Expected grep_search to be called with include_pattern: "*.js"',
).toBe(true);

assertModelHasOutput(result);
checkModelOutputContent(result, {
expectedContent: [/file.js/],
forbiddenContent: [/file.ts/],
testName: `${TEST_PREFIX}include glob search`,
testName: `${TEST_PREFIX}include_pattern glob search`,
});
},
});
Expand Down
5 changes: 4 additions & 1 deletion integration-tests/ripgrep-real.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,10 @@ describe('ripgrep-real-direct', () => {
'console.log("hello");\n',
);

const invocation = tool.build({ pattern: 'hello', include: '*.js' });
const invocation = tool.build({
pattern: 'hello',
include_pattern: '*.js',
});
const result = await invocation.execute(new AbortController().signal);

expect(result.llmContent).toContain('Found 1 match');
Expand Down
36 changes: 18 additions & 18 deletions packages/core/src/core/__snapshots__/prompts.test.ts.snap

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/core/src/prompts/snippets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ Use the following guidelines to optimize your search and read patterns.
</guidelines>

<examples>
- **Searching:** utilize search tools like ${GREP_TOOL_NAME} and ${GLOB_TOOL_NAME} with a conservative result count (\`total_max_matches\`) and a narrow scope (\`include\` and \`exclude\` parameters).
- **Searching:** utilize search tools like ${GREP_TOOL_NAME} and ${GLOB_TOOL_NAME} with a conservative result count (\`total_max_matches\`) and a narrow scope (\`include_pattern\` and \`exclude_pattern\` parameters).
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know we had this issue before but it' probably be smart for us to move the parameters include/exclude patterns to variables so that if we change them in one location they change everywhere

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do in a follow-up!

- **Searching and editing:** utilize search tools like ${GREP_TOOL_NAME} with a conservative result count and a narrow scope. Use \`context\`, \`before\`, and/or \`after\` to request enough context to avoid the need to read the file before editing matches.
- **Understanding:** minimize turns needed to understand a file. It's most efficient to read small files in their entirety.
- **Large files:** utilize search tools like ${GREP_TOOL_NAME} and/or ${READ_FILE_TOOL_NAME} called in parallel with 'start_line' and 'end_line' to reduce the impact on context. Minimize extra turns, unless unavoidable due to the file being too large.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ exports[`coreTools snapshots for specific models > Model: gemini-2.5-pro > snaps
"description": "Optional: A regular expression pattern to exclude from the search results. If a line matches both the pattern and the exclude_pattern, it will be omitted.",
"type": "string",
},
"include": {
"include_pattern": {
"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",
},
Expand Down Expand Up @@ -333,7 +333,7 @@ exports[`coreTools snapshots for specific models > Model: gemini-2.5-pro > snaps
"description": "If true, treats the \`pattern\` as a literal string instead of a regular expression. Defaults to false (basic regex) if omitted.",
"type": "boolean",
},
"include": {
"include_pattern": {
"description": "Glob pattern to filter files (e.g., '*.ts', 'src/**'). Recommended for large repositories to reduce noise. Defaults to all files if omitted.",
"type": "string",
},
Expand Down Expand Up @@ -1053,7 +1053,7 @@ exports[`coreTools snapshots for specific models > Model: gemini-3-pro-preview >
"description": "Optional: A regular expression pattern to exclude from the search results. If a line matches both the pattern and the exclude_pattern, it will be omitted.",
"type": "string",
},
"include": {
"include_pattern": {
"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",
},
Expand Down Expand Up @@ -1120,7 +1120,7 @@ exports[`coreTools snapshots for specific models > Model: gemini-3-pro-preview >
"description": "If true, treats the \`pattern\` as a literal string instead of a regular expression. Defaults to false (basic regex) if omitted.",
"type": "boolean",
},
"include": {
"include_pattern": {
"description": "Glob pattern to filter files (e.g., '*.ts', 'src/**'). Recommended for large repositories to reduce noise. Defaults to all files if omitted.",
"type": "string",
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export const DEFAULT_LEGACY_SET: CoreToolSet = {
'Optional: The absolute path to the directory to search within. If omitted, searches the current working directory.',
type: 'string',
},
include: {
include_pattern: {
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',
},
Expand Down Expand Up @@ -143,7 +143,7 @@ export const DEFAULT_LEGACY_SET: CoreToolSet = {
"Directory or file to search. Directories are searched recursively. Relative paths are resolved against current working directory. Defaults to current working directory ('.') if omitted.",
type: 'string',
},
include: {
include_pattern: {
description:
"Glob pattern to filter files (e.g., '*.ts', 'src/**'). Recommended for large repositories to reduce noise. Defaults to all files if omitted.",
type: 'string',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export const GEMINI_3_SET: CoreToolSet = {
'Optional: The absolute path to the directory to search within. If omitted, searches the current working directory.',
type: 'string',
},
include: {
include_pattern: {
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',
},
Expand Down Expand Up @@ -144,7 +144,7 @@ export const GEMINI_3_SET: CoreToolSet = {
"Directory or file to search. Directories are searched recursively. Relative paths are resolved against current working directory. Defaults to current working directory ('.') if omitted.",
type: 'string',
},
include: {
include_pattern: {
description:
"Glob pattern to filter files (e.g., '*.ts', 'src/**'). Recommended for large repositories to reduce noise. Defaults to all files if omitted.",
type: 'string',
Expand Down
10 changes: 5 additions & 5 deletions packages/core/src/tools/grep-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ export async function formatGrepResults(
params: {
pattern: string;
names_only?: boolean;
include?: string;
include_pattern?: string;
// Context params to determine if auto-context should be skipped
context?: number;
before?: number;
Expand All @@ -148,10 +148,10 @@ export async function formatGrepResults(
searchLocationDescription: string,
totalMaxMatches: number,
): Promise<{ llmContent: string; returnDisplay: string }> {
const { pattern, names_only, include } = params;
const { pattern, names_only, include_pattern } = params;

if (allMatches.length === 0) {
const noMatchMsg = `No matches found for pattern "${pattern}" ${searchLocationDescription}${include ? ` (filter: "${include}")` : ''}.`;
const noMatchMsg = `No matches found for pattern "${pattern}" ${searchLocationDescription}${include_pattern ? ` (filter: "${include_pattern}")` : ''}.`;
return { llmContent: noMatchMsg, returnDisplay: `No matches found` };
}

Expand All @@ -171,7 +171,7 @@ export async function formatGrepResults(
if (names_only) {
const filePaths = Object.keys(matchesByFile).sort();
let llmContent = `Found ${filePaths.length} files with matches for pattern "${pattern}" ${searchLocationDescription}${
include ? ` (filter: "${include}")` : ''
include_pattern ? ` (filter: "${include_pattern}")` : ''
}${
wasTruncated
? ` (results limited to ${totalMaxMatches} matches for performance)`
Expand All @@ -184,7 +184,7 @@ export async function formatGrepResults(
};
}

let llmContent = `Found ${matchCount} ${matchTerm} for pattern "${pattern}" ${searchLocationDescription}${include ? ` (filter: "${include}")` : ''}`;
let llmContent = `Found ${matchCount} ${matchTerm} for pattern "${pattern}" ${searchLocationDescription}${include_pattern ? ` (filter: "${include_pattern}")` : ''}`;

if (wasTruncated) {
llmContent += ` (results limited to ${totalMaxMatches} matches for performance)`;
Expand Down
13 changes: 8 additions & 5 deletions packages/core/src/tools/grep.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ describe('GrepTool', () => {
const params: GrepToolParams = {
pattern: 'hello',
dir_path: '.',
include: '*.txt',
include_pattern: '*.txt',
};
expect(grepTool.validateToolParams(params)).toBeNull();
});
Expand Down Expand Up @@ -226,7 +226,10 @@ describe('GrepTool', () => {
}, 30000);

it('should find matches with an include glob', async () => {
const params: GrepToolParams = { pattern: 'hello', include: '*.js' };
const params: GrepToolParams = {
pattern: 'hello',
include_pattern: '*.js',
};
const invocation = grepTool.build(params);
const result = await invocation.execute(abortSignal);
expect(result.llmContent).toContain(
Expand All @@ -247,7 +250,7 @@ describe('GrepTool', () => {
const params: GrepToolParams = {
pattern: 'hello',
dir_path: 'sub',
include: '*.js',
include_pattern: '*.js',
};
const invocation = grepTool.build(params);
const result = await invocation.execute(abortSignal);
Expand Down Expand Up @@ -572,7 +575,7 @@ describe('GrepTool', () => {
it('should generate correct description with pattern and include', () => {
const params: GrepToolParams = {
pattern: 'testPattern',
include: '*.ts',
include_pattern: '*.ts',
};
const invocation = grepTool.build(params);
expect(invocation.getDescription()).toBe("'testPattern' in *.ts");
Expand Down Expand Up @@ -618,7 +621,7 @@ describe('GrepTool', () => {
await fs.mkdir(dirPath, { recursive: true });
const params: GrepToolParams = {
pattern: 'testPattern',
include: '*.ts',
include_pattern: '*.ts',
dir_path: path.join('src', 'app'),
};
const invocation = grepTool.build(params);
Expand Down
22 changes: 11 additions & 11 deletions packages/core/src/tools/grep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export interface GrepToolParams {
/**
* File pattern to include in the search (e.g. "*.js", "*.{ts,tsx}")
*/
include?: string;
include_pattern?: string;

/**
* Optional: A regular expression pattern to exclude from the search results.
Expand Down Expand Up @@ -227,7 +227,7 @@ class GrepToolInvocation extends BaseToolInvocation<
const matches = await this.performGrepSearch({
pattern: this.params.pattern,
path: searchDir,
include: this.params.include,
include_pattern: this.params.include_pattern,
exclude_pattern: this.params.exclude_pattern,
maxMatches: remainingLimit,
max_matches_per_file: this.params.max_matches_per_file,
Expand Down Expand Up @@ -317,7 +317,7 @@ class GrepToolInvocation extends BaseToolInvocation<
private async performGrepSearch(options: {
pattern: string;
path: string; // Expects absolute path
include?: string;
include_pattern?: string;
exclude_pattern?: string;
maxMatches: number;
max_matches_per_file?: number;
Expand All @@ -326,7 +326,7 @@ class GrepToolInvocation extends BaseToolInvocation<
const {
pattern,
path: absolutePath,
include,
include_pattern,
exclude_pattern,
maxMatches,
max_matches_per_file,
Expand Down Expand Up @@ -356,8 +356,8 @@ class GrepToolInvocation extends BaseToolInvocation<
if (max_matches_per_file) {
gitArgs.push('--max-count', max_matches_per_file.toString());
}
if (include) {
gitArgs.push('--', include);
if (include_pattern) {
gitArgs.push('--', include_pattern);
}

try {
Expand Down Expand Up @@ -424,8 +424,8 @@ class GrepToolInvocation extends BaseToolInvocation<
if (max_matches_per_file) {
grepArgs.push('--max-count', max_matches_per_file.toString());
}
if (include) {
grepArgs.push(`--include=${include}`);
if (include_pattern) {
grepArgs.push(`--include=${include_pattern}`);
}
grepArgs.push(pattern);
grepArgs.push('.');
Expand Down Expand Up @@ -471,7 +471,7 @@ class GrepToolInvocation extends BaseToolInvocation<
'GrepLogic: Falling back to JavaScript grep implementation.',
);
strategyUsed = 'javascript fallback';
const globPattern = include ? include : '**/*';
const globPattern = include_pattern ? include_pattern : '**/*';
const ignorePatterns = this.fileExclusions.getGlobExcludes();

const filesStream = globStream(globPattern, {
Expand Down Expand Up @@ -551,8 +551,8 @@ class GrepToolInvocation extends BaseToolInvocation<

getDescription(): string {
let description = `'${this.params.pattern}'`;
if (this.params.include) {
description += ` in ${this.params.include}`;
if (this.params.include_pattern) {
description += ` in ${this.params.include_pattern}`;
}
if (this.params.dir_path) {
const resolvedPath = path.resolve(
Expand Down
17 changes: 10 additions & 7 deletions packages/core/src/tools/ripGrep.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ describe('RipGrepTool', () => {
},
{
name: 'pattern, path, and include',
params: { pattern: 'hello', dir_path: '.', include: '*.txt' },
params: { pattern: 'hello', dir_path: '.', include_pattern: '*.txt' },
expected: null,
},
])(
Expand Down Expand Up @@ -526,7 +526,10 @@ describe('RipGrepTool', () => {
}),
);

const params: RipGrepToolParams = { pattern: 'hello', include: '*.js' };
const params: RipGrepToolParams = {
pattern: 'hello',
include_pattern: '*.js',
};
const invocation = grepTool.build(params);
const result = await invocation.execute(abortSignal);
expect(result.llmContent).toContain(
Expand Down Expand Up @@ -564,7 +567,7 @@ describe('RipGrepTool', () => {
const params: RipGrepToolParams = {
pattern: 'hello',
dir_path: 'sub',
include: '*.js',
include_pattern: '*.js',
};
const invocation = grepTool.build(params);
const result = await invocation.execute(abortSignal);
Expand Down Expand Up @@ -1314,7 +1317,7 @@ describe('RipGrepTool', () => {

const params: RipGrepToolParams = {
pattern: 'content',
include: '*.{ts,tsx}',
include_pattern: '*.{ts,tsx}',
};
const invocation = grepTool.build(params);
const result = await invocation.execute(abortSignal);
Expand Down Expand Up @@ -1350,7 +1353,7 @@ describe('RipGrepTool', () => {

const params: RipGrepToolParams = {
pattern: 'code',
include: 'src/**',
include_pattern: 'src/**',
};
const invocation = grepTool.build(params);
const result = await invocation.execute(abortSignal);
Expand Down Expand Up @@ -1774,7 +1777,7 @@ describe('RipGrepTool', () => {
},
{
name: 'pattern and include',
params: { pattern: 'testPattern', include: '*.ts' },
params: { pattern: 'testPattern', include_pattern: '*.ts' },
expected: "'testPattern' in *.ts within ./",
},
{
Expand Down Expand Up @@ -1849,7 +1852,7 @@ describe('RipGrepTool', () => {
await fs.mkdir(dirPath, { recursive: true });
const params: RipGrepToolParams = {
pattern: 'testPattern',
include: '*.ts',
include_pattern: '*.ts',
dir_path: path.join('src', 'app'),
};
const invocation = grepTool.build(params);
Expand Down
Loading
Loading