Skip to content

feat(tools): add max_results param to glob and improve grep/glob truncation messages - #23155

Closed
netbrah wants to merge 1 commit into
google-gemini:mainfrom
netbrah:feat/glob-max-results-truncation-21694
Closed

netbrah wants to merge 1 commit into
google-gemini:mainfrom
netbrah:feat/glob-max-results-truncation-21694

Conversation

@netbrah

@netbrah netbrah commented Mar 19, 2026 •

Copy link
Copy Markdown

Summary

  • Add max_results optional parameter (default 500) to glob tool to prevent unbounded results from blowing up context windows on large monorepos
  • Improve grep/glob truncation messages from passive prose to structured, actionable warnings the agent can act on
  • Truncation enforced after sort-by-recency so the most recent files are always returned

Details

Glob truncation (new)

  • max_results optional parameter (default 500) added to glob tool schema and GlobToolParams
  • Truncation enforced after sort-by-recency so the most recent files are always returned
  • Both llmContent and returnDisplay surface truncation clearly

Grep truncation messaging (improved)

  • Replaced passive (results limited to N matches for performance) with structured ⚠️ RESULTS TRUNCATED block that instructs the agent to narrow the pattern or increase total_max_matches
  • returnDisplay now shows actual limit: (truncated at 100, more exist) instead of (limited)

Files changed:

  • constants.ts — new DEFAULT_GLOB_MAX_RESULTS = 500
  • base-declarations.ts — new GLOB_PARAM_MAX_RESULTS constant
  • default-legacy.ts, gemini-3.ts — max_results added to glob schema (both model family sets)
  • glob.ts — interface, validation, and execute() truncation logic
  • grep-utils.ts — rewritten truncation messages in formatGrepResults()
  • Updated snapshot, grep, and ripGrep test assertions; added new grep-utils.test.ts

How to Validate

```bash
npm test -w @google/gemini-cli-core -- src/tools/glob.test.ts
npm test -w @google/gemini-cli-core -- src/tools/grep-utils.test.ts
npm test -w @google/gemini-cli-core -- src/tools/grep.test.ts
npm test -w @google/gemini-cli-core -- src/tools/ripGrep.test.ts
npm test -w @google/gemini-cli-core -- src/tools/definitions/coreToolsModelSnapshots.test.ts
```

All 183 tests pass (143 tool tests + 40 snapshot tests). tsc --noEmit clean.

Fixes #21694

@netbrah
netbrah requested a review from a team as a code owner March 19, 2026 21:00
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly improves the usability and predictability of the glob and grep tools by introducing result limits and clearer feedback mechanisms. The primary goal is to prevent context window overflow in large repositories and provide agents with explicit, actionable information when results are truncated, thereby enhancing their ability to refine searches and manage tool outputs effectively.

Highlights

  • Glob Tool Enhancements: Introduced an optional max_results parameter (defaulting to 500) for the glob tool to prevent excessively large result sets from consuming context windows. Truncation is applied after sorting by recency, ensuring the most recent files are always returned.
  • Improved Truncation Messaging: Enhanced the truncation messages for both grep and glob tools. Messages are now structured, actionable warnings that clearly indicate truncation and provide guidance to the agent on how to narrow results or increase limits.
  • Schema and Validation Updates: Updated tool schemas for glob across different model families to include the new max_results parameter with appropriate descriptions and validation rules (must be a positive integer).
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

The pull request successfully implements the max_results parameter for the glob tool, allowing for better control over the number of returned file paths. The truncation messages for both grep and glob tools have been significantly improved to provide more structured and actionable warnings to the agent. The changes include appropriate constant definitions, schema updates, core logic for truncation, and comprehensive test coverage for the new functionality and validation rules. The code is well-tested and adheres to the project's standards.

@netbrah
netbrah force-pushed the feat/glob-max-results-truncation-21694 branch from 3498039 to 72c71c4 Compare March 19, 2026 21:14
@gemini-cli gemini-cli Bot added priority/p1 Important and should be addressed in the near term. area/agent Issues related to Core Agent, Tools, Memory, Sub-Agents, Hooks, Agent Quality labels Mar 19, 2026
…cation messages

Glob tool had no result-count limit — `glob('**/*.ts')` on a large monorepo
returns all paths, silently blowing up context windows. Grep truncation
messages were passive prose the agent couldn't act on.

- Add `max_results` optional parameter (default 500) to glob tool schema
- Enforce truncation after sort-by-recency so most recent files are returned
- Replace passive grep truncation messages with structured actionable warnings
- Surface truncation clearly in both llmContent and returnDisplay

Fixes google-gemini#21694

Made-with: Cursor
@gemini-cli

gemini-cli Bot commented Apr 3, 2026

Copy link
Copy Markdown
Contributor

Hi there! Thank you for your interest in contributing to Gemini CLI.

To ensure we maintain high code quality and focus on our prioritized roadmap, we have updated our contribution policy (see Discussion #17383).

We only guarantee review and consideration of pull requests for issues that are explicitly labeled as 'help wanted'. All other community pull requests are subject to closure after 14 days if they do not align with our current focus areas. For this reason, we strongly recommend that contributors only submit pull requests against issues explicitly labeled as 'help-wanted'.

This pull request is being closed as it has been open for 14 days without a 'help wanted' designation. We encourage you to find and contribute to existing 'help wanted' issues in our backlog! Thank you for your understanding and for being part of our community!

@gemini-cli gemini-cli Bot closed this Apr 3, 2026
@sripasg sripasg added the size/m A medium sized PR label Jun 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/agent Issues related to Core Agent, Tools, Memory, Sub-Agents, Hooks, Agent Quality priority/p1 Important and should be addressed in the near term. size/m A medium sized PR

Projects

None yet

2 participants