Skip to content

refactor(core): centralize tool definitions (Group 1: replace, search, grep) - #18944

Merged
aishaneeshah merged 10 commits into
mainfrom
refactor-tools-group-1
Feb 13, 2026
Merged

refactor(core): centralize tool definitions (Group 1: replace, search, grep)#18944
aishaneeshah merged 10 commits into
mainfrom
refactor-tools-group-1

Conversation

@aishaneeshah

@aishaneeshah aishaneeshah commented Feb 12, 2026

Copy link
Copy Markdown
Contributor

Summary

Refactor and centralize core tool definitions for the first group of tools: replace (edit), google_web_search, and grep_search (both basic and advanced implementations).

Details

This PR is part of a larger effort to centralize tool definitions and descriptions in packages/core/src/tools/definitions/coreTools.ts. This specific group includes:

  1. replace (EditTool): Centralized EDIT_DEFINITION and instruction descriptions.
  2. google_web_search (WebSearchTool): Centralized WEB_SEARCH_DEFINITION and fixed a minor typo in the description.
  3. grep_search (GrepTool & RipGrepTool):
    • Centralized GREP_DEFINITION for the basic fallback implementation.
    • Centralized RIP_GREP_DEFINITION for the advanced ripgrep implementation.
    • Maintained the existing logic where both implementations share the grep_search name and are chosen by the configuration at runtime.

Key Verification:

  • Confirmed that the tool schemas and descriptions match the original definitions on the main branch exactly.
  • Updated coreToolsModelSnapshots.test.ts to independently verify both search implementations under the same tool name, ensuring no unintended interface changes.
  • Verified that tool registration logic in config.ts remains unchanged.

Related Issues

Related to the ongoing tool centralization refactor.

How to Validate

  1. Run the centralized tool snapshot tests:
    npm test -w @google/gemini-cli-core -- src/tools/definitions/coreToolsModelSnapshots.test.ts
  2. Verify build and lint:
    npm run build && npm run lint

Pre-Merge Checklist

  • Updated relevant documentation and README (if needed)
  • Added/updated tests (if needed)
  • Noted breaking changes (if any)
  • Validated on required platforms/methods:
    • Linux
      • npm run

Related to #17958

@aishaneeshah
aishaneeshah requested a review from a team as a code owner February 12, 2026 20:13
@gemini-cli

gemini-cli Bot commented Feb 12, 2026

Copy link
Copy Markdown
Contributor

Hi there! Thank you for your contribution to Gemini CLI.

To improve our contribution process and better track changes, we now require all pull requests to be associated with an existing issue, as announced in our recent discussion and as detailed in our CONTRIBUTING.md.

This pull request is being closed because it is not currently linked to an issue. Once you have updated the description of this PR to link an issue (e.g., by adding Fixes #123 or Related to #123), it will be automatically reopened.

How to link an issue:
Add a keyword followed by the issue number (e.g., Fixes #123) in the description of your pull request. For more details on supported keywords and how linking works, please refer to the GitHub Documentation on linking pull requests to issues.

Thank you for your understanding and for being a part of our community!

@gemini-cli gemini-cli Bot closed this Feb 12, 2026
@gemini-cli

gemini-cli Bot commented Feb 12, 2026

Copy link
Copy Markdown
Contributor

Hi @aishaneeshah, thank you so much for your contribution to Gemini CLI! We really appreciate the time and effort you've put into this.

We're making some updates to our contribution process to improve how we track and review changes. Please take a moment to review our recent discussion post: Improving Our Contribution Process & Introducing New Guidelines.

Key Update: Starting January 26, 2026, the Gemini CLI project will require all pull requests to be associated with an existing issue. Any pull requests not linked to an issue by that date will be automatically closed.

Thank you for your understanding and for being a part of our community!

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @aishaneeshah, 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 initiates a significant refactoring effort to centralize the definitions of core tools within the system. By moving tool schemas and descriptions to a single source, it enhances maintainability, reduces duplication, and ensures consistency across various tool implementations. This change specifically targets the replace, google_web_search, and grep_search tools, laying the groundwork for a more organized and scalable tool architecture.

Highlights

  • Centralized Tool Definitions: The definitions for the replace (EditTool), google_web_search (WebSearchTool), and grep_search (GrepTool & RipGrepTool) tools have been moved to a central location in packages/core/src/tools/definitions/coreTools.ts.
  • Refactored Tool Implementations: The EditTool, WebSearchTool, and RipGrepTool classes now import and utilize these centralized definitions, simplifying their constructors and ensuring consistency.
  • Updated Tool Snapshots: Snapshot tests (coreToolsModelSnapshots.test.ts) were updated to reflect the new centralized definitions and to independently verify both basic and advanced grep_search implementations.
  • Improved Tool Name Management: Tool names like EDIT_TOOL_NAME and WEB_SEARCH_TOOL_NAME are now imported directly from the centralized coreTools.ts file, removing redundant local declarations.
Changelog
  • packages/core/src/tools/definitions/snapshots/coreToolsModelSnapshots.test.ts.snap
    • Added new snapshot entries for google_web_search, grep_search_ripgrep, and replace tools for both gemini-2.5-pro and gemini-3-pro-preview models.
  • packages/core/src/tools/definitions/coreTools.ts
    • Added new EDIT_TOOL_NAME and WEB_SEARCH_TOOL_NAME constants.
    • Defined RIP_GREP_DEFINITION with comprehensive parameters for advanced grep functionality.
    • Defined WEB_SEARCH_DEFINITION for the Google Web Search tool.
    • Defined EDIT_DEFINITION for the replace tool, including detailed parameter descriptions and usage guidelines.
  • packages/core/src/tools/definitions/coreToolsModelSnapshots.test.ts
    • Imported RIP_GREP_DEFINITION, EDIT_DEFINITION, and WEB_SEARCH_DEFINITION.
    • Added grep_search_ripgrep, replace, and google_web_search to the list of tools to be snapshotted, ensuring their definitions are captured.
  • packages/core/src/tools/edit.ts
    • Imported EDIT_DEFINITION and resolveToolDeclaration.
    • Refactored the EditTool constructor to use the centralized EDIT_DEFINITION for its description and parameter schema.
    • Overrode the getSchema method to return the resolved EDIT_DEFINITION.
  • packages/core/src/tools/ripGrep.ts
    • Imported RIP_GREP_DEFINITION and resolveToolDeclaration.
    • Refactored the RipGrepTool constructor to use the centralized RIP_GREP_DEFINITION for its description and parameter schema.
    • Overrode the getSchema method to return the resolved RIP_GREP_DEFINITION.
  • packages/core/src/tools/tool-names.ts
    • Imported EDIT_TOOL_NAME and WEB_SEARCH_TOOL_NAME from coreTools.js.
    • Removed redundant local const declarations for WEB_SEARCH_TOOL_NAME and EDIT_TOOL_NAME.
  • packages/core/src/tools/web-search.ts
    • Imported WEB_SEARCH_DEFINITION and resolveToolDeclaration.
    • Refactored the WebSearchTool constructor to use the centralized WEB_SEARCH_DEFINITION for its description and parameter schema.
    • Overrode the getSchema method to return the resolved WEB_SEARCH_DEFINITION.
Activity
  • The author confirmed that tool schemas and descriptions match the original definitions on the main branch exactly.
  • The author updated coreToolsModelSnapshots.test.ts to independently verify both search implementations under the same tool name.
  • The author verified that tool registration logic in config.ts remains unchanged.
  • The author updated relevant documentation and README (if needed).
  • The author added/updated tests (if needed).
  • The author noted no breaking changes.
  • The author validated the changes on Linux using npm run.
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.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

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-cli gemini-cli Bot reopened this Feb 12, 2026
@gemini-cli

gemini-cli Bot commented Feb 12, 2026

Copy link
Copy Markdown
Contributor

Thank you for linking an issue! This pull request has been automatically reopened.

@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

This pull request centralizes tool definitions for replace, google_web_search, and grep_search, improving code organization and maintainability, with snapshot tests correctly updated. However, two high-severity security issues were identified: the LLM edit fixer utility is vulnerable to prompt injection and corruption due to unsafe use of String.prototype.replace when constructing prompts from untrusted data, and the grep_search tool's no_ignore parameter could allow bypassing security-critical ignore rules like .gitignore, potentially exposing sensitive information. Additionally, a minor issue was found in the refactored EDIT_DEFINITION where an extra comma was introduced, which could affect LLM behavior.

Comment on lines +151 to +153
},
include: {
description:

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.

security-high high

The grep_search tool (specifically the RipGrepTool implementation) includes a no_ignore parameter that, when set to true, causes the tool to bypass all file ignore rules (such as .gitignore and .geminiignore). This allows the LLM to search and read potentially sensitive files that are intended to be hidden, such as .env files containing secrets, private keys, or configuration files. Since grep_search is a "read" tool (Kind.Search), it may not require user confirmation in many configurations, allowing an LLM to exfiltrate sensitive data without the user's knowledge if it is tricked via prompt injection.

Consider removing the no_ignore parameter from the tool's public schema to prevent the LLM from bypassing ignore rules. If the functionality is required for users, ensure that its use by the LLM always triggers a high-visibility warning or requires explicit user confirmation.

@github-actions

github-actions Bot commented Feb 12, 2026

Copy link
Copy Markdown

Size Change: +972 B (0%)

Total Size: 24.4 MB

ℹ️ View Unchanged
Filename Size Change
./bundle/gemini.js 24.4 MB +972 B (0%)
./bundle/sandbox-macos-permissive-open.sb 890 B 0 B
./bundle/sandbox-macos-permissive-proxied.sb 1.31 kB 0 B
./bundle/sandbox-macos-restrictive-open.sb 3.36 kB 0 B
./bundle/sandbox-macos-restrictive-proxied.sb 3.56 kB 0 B
./bundle/sandbox-macos-strict-open.sb 4.82 kB 0 B
./bundle/sandbox-macos-strict-proxied.sb 5.02 kB 0 B

compressed-size-action

@gemini-cli gemini-cli Bot added area/agent Issues related to Core Agent, Tools, Memory, Sub-Agents, Hooks, Agent Quality 🔒 maintainer only ⛔ Do not contribute. Internal roadmap item. labels Feb 12, 2026
WebSearchTool.Name,
'GoogleSearch',
'Performs a web search using Google Search (via the Gemini API) and returns the results. This tool is useful for finding information on the internet based on a query.',
WEB_SEARCH_DEFINITION.base.description!,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: It'd be great to see if we can adjust the typings for WEB_SEARCH_DEFINITION to not require a null suppression.

Gemini provided this helpful idea:

Image Image

{ name: 'read_file', definition: READ_FILE_DEFINITION },
{ name: 'write_file', definition: WRITE_FILE_DEFINITION },
{ name: 'grep_search', definition: GREP_DEFINITION },
{ name: 'grep_search_ripgrep', definition: RIP_GREP_DEFINITION },

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Does this change the name of the tool as seen by the model? I think we want that to stay 'grep'.

@aishaneeshah
aishaneeshah added this pull request to the merge queue Feb 13, 2026
Merged via the queue into main with commit b62c656 Feb 13, 2026
27 checks passed
@aishaneeshah
aishaneeshah deleted the refactor-tools-group-1 branch February 13, 2026 02:12
kuishou68 pushed a commit to iOfficeAI/gemini-cli-pro that referenced this pull request Feb 27, 2026
liamhelmer pushed a commit to badal-io/gemini-cli that referenced this pull request Mar 12, 2026
@sripasg sripasg added the size/l A large sized PR label Jun 2, 2026
software-0ficial pushed a commit to software-0ficial/gemini-cli that referenced this pull request Jul 9, 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 🔒 maintainer only ⛔ Do not contribute. Internal roadmap item. size/l A large sized PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants