Skip to content

refactor(core): Extract tool parameter names as constants#20460

Open
SandyTao520 wants to merge 1 commit intomainfrom
st/feat/prams_refactor
Open

refactor(core): Extract tool parameter names as constants#20460
SandyTao520 wants to merge 1 commit intomainfrom
st/feat/prams_refactor

Conversation

@SandyTao520
Copy link
Contributor

Summary

This PR refactors hardcoded tool parameter names into centralized constants to improve maintainability and reduce the risk of typos across the codebase.

Details

  • Centralized Constants: Parameter names like file_path, dir_path, pattern, command, and others are now defined as exported constants in packages/core/src/tools/definitions/base-declarations.ts.
  • Prompt Snippets: Updated packages/core/src/prompts/snippets.ts to use these constants within prompt examples and guidelines.
  • Tool Declarations: Refactored static toolsets (gemini-3.ts, default-legacy.ts) and dynamic declaration helpers (dynamic-declaration-helpers.ts) to use computed property names for parameters.
  • Exports: Updated packages/core/src/tools/tool-names.ts and packages/core/src/tools/definitions/coreTools.ts to export these new constants for wider use.

Related Issues

Related to #18007

How to Validate

  1. Run npm run build to ensure the project compiles correctly.
  2. Inspect the generated tool declarations to verify that parameter names remain unchanged (e.g., file_path is still file_path in the JSON schema).

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:
    • MacOS
      • npm run

@SandyTao520 SandyTao520 requested a review from a team as a code owner February 26, 2026 17:44
@gemini-cli
Copy link
Contributor

gemini-cli bot commented Feb 26, 2026

Hi @SandyTao520, 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
Contributor

Summary of Changes

Hello @SandyTao520, 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 code maintainability and reduces the risk of typos by centralizing tool parameter names into constants. This refactoring ensures that parameter names are consistently defined and referenced throughout the codebase, making future updates and debugging more efficient.

Highlights

  • Centralized Constants: Extracted hardcoded tool parameter names into new, exported constants in base-declarations.ts for improved maintainability.
  • Prompt Snippets Update: Modified snippets.ts to utilize the new parameter constants within prompt examples and guidelines, enhancing consistency.
  • Tool Declarations Refactoring: Updated static toolsets (gemini-3.ts, default-legacy.ts) and dynamic declaration helpers (dynamic-declaration-helpers.ts) to use computed property names for parameters, referencing the new constants.
  • Export Enhancements: Adjusted tool-names.ts and coreTools.ts to export the newly defined parameter constants, making them widely accessible across the codebase.
Changelog
  • packages/core/src/prompts/snippets.ts
    • Imported new GREP_PARAM, READ_FILE_PARAM, and SHELL_PARAM constants.
    • Updated prompt examples to use the new parameter constants for grep, read_file, and shell tools.
  • packages/core/src/tools/definitions/base-declarations.ts
    • Added numerous shared parameter constants (e.g., PARAM_FILE_PATH, PARAM_DIR_PATH, PARAM_PATTERN).
    • Added tool-specific parameter constants for grep, list_directory, read_file, run_shell_command, write_file, replace, google_web_search, write_todos, web_fetch, read_many_files, save_memory, get_internal_docs, activate_skill, ask_user, exit_plan_mode, and enter_plan_mode tools.
  • packages/core/src/tools/definitions/coreTools.ts
    • Exported all newly defined shared and tool-specific parameter constants from base-declarations.ts.
  • packages/core/src/tools/definitions/dynamic-declaration-helpers.ts
    • Imported new parameter constants (SHELL_PARAM_COMMAND, PARAM_DESCRIPTION, PARAM_DIR_PATH, SHELL_PARAM_IS_BACKGROUND, EXIT_PLAN_PARAM_PLAN_PATH, SKILL_PARAM_NAME).
    • Updated getShellDeclaration to use computed property names with SHELL_PARAM_COMMAND, PARAM_DESCRIPTION, PARAM_DIR_PATH, and SHELL_PARAM_IS_BACKGROUND.
    • Updated getExitPlanModeDeclaration to use computed property names with EXIT_PLAN_PARAM_PLAN_PATH.
    • Updated getActivateSkillDeclaration to use computed property names with SKILL_PARAM_NAME.
  • packages/core/src/tools/definitions/model-family-sets/default-legacy.ts
    • Imported new shared and tool-specific parameter constants.
    • Refactored read_file tool declaration to use PARAM_FILE_PATH, READ_FILE_PARAM_START_LINE, and READ_FILE_PARAM_END_LINE.
    • Refactored write_file tool declaration to use PARAM_FILE_PATH and WRITE_FILE_PARAM_CONTENT.
    • Refactored grep_search tool declaration to use PARAM_PATTERN, PARAM_DIR_PATH, GREP_PARAM_INCLUDE_PATTERN, GREP_PARAM_EXCLUDE_PATTERN, GREP_PARAM_NAMES_ONLY, GREP_PARAM_MAX_MATCHES_PER_FILE, GREP_PARAM_TOTAL_MAX_MATCHES, PARAM_CASE_SENSITIVE, GREP_PARAM_FIXED_STRINGS, GREP_PARAM_CONTEXT, GREP_PARAM_AFTER, GREP_PARAM_BEFORE, and GREP_PARAM_NO_IGNORE.
    • Refactored glob tool declaration to use PARAM_PATTERN, PARAM_DIR_PATH, PARAM_CASE_SENSITIVE, PARAM_RESPECT_GIT_IGNORE, and PARAM_RESPECT_GEMINI_IGNORE.
    • Refactored list_directory tool declaration to use PARAM_DIR_PATH, LS_PARAM_IGNORE, PARAM_FILE_FILTERING_OPTIONS, PARAM_RESPECT_GIT_IGNORE, and PARAM_RESPECT_GEMINI_IGNORE.
    • Refactored replace tool declaration to use PARAM_FILE_PATH, EDIT_PARAM_INSTRUCTION, EDIT_PARAM_OLD_STRING, EDIT_PARAM_NEW_STRING, and EDIT_PARAM_ALLOW_MULTIPLE.
    • Refactored google_web_search tool declaration to use WEB_SEARCH_PARAM_QUERY.
    • Refactored web_fetch tool declaration to use WEB_FETCH_PARAM_PROMPT.
    • Refactored read_many_files tool declaration to use READ_MANY_PARAM_INCLUDE, READ_MANY_PARAM_EXCLUDE, READ_MANY_PARAM_RECURSIVE, READ_MANY_PARAM_USE_DEFAULT_EXCLUDES, PARAM_FILE_FILTERING_OPTIONS, PARAM_RESPECT_GIT_IGNORE, and PARAM_RESPECT_GEMINI_IGNORE.
    • Refactored save_memory tool declaration to use MEMORY_PARAM_FACT.
    • Refactored write_todos tool declaration to use TODOS_PARAM_TODOS.
    • Refactored get_internal_docs tool declaration to use DOCS_PARAM_PATH.
    • Refactored ask_user tool declaration to use ASK_USER_PARAM_QUESTIONS.
    • Refactored enter_plan_mode tool declaration to use PLAN_MODE_PARAM_REASON.
  • packages/core/src/tools/definitions/model-family-sets/gemini-3.ts
    • Imported new shared and tool-specific parameter constants.
    • Refactored read_file tool declaration to use PARAM_FILE_PATH, READ_FILE_PARAM_START_LINE, and READ_FILE_PARAM_END_LINE.
    • Refactored write_file tool declaration to use PARAM_FILE_PATH and WRITE_FILE_PARAM_CONTENT.
    • Refactored grep_search tool declaration to use PARAM_PATTERN, PARAM_DIR_PATH, GREP_PARAM_INCLUDE_PATTERN, GREP_PARAM_EXCLUDE_PATTERN, GREP_PARAM_NAMES_ONLY, GREP_PARAM_MAX_MATCHES_PER_FILE, GREP_PARAM_TOTAL_MAX_MATCHES, PARAM_CASE_SENSITIVE, GREP_PARAM_FIXED_STRINGS, GREP_PARAM_CONTEXT, GREP_PARAM_AFTER, GREP_PARAM_BEFORE, and GREP_PARAM_NO_IGNORE.
    • Refactored glob tool declaration to use PARAM_PATTERN, PARAM_DIR_PATH, PARAM_CASE_SENSITIVE, PARAM_RESPECT_GIT_IGNORE, and PARAM_RESPECT_GEMINI_IGNORE.
    • Refactored list_directory tool declaration to use PARAM_DIR_PATH, LS_PARAM_IGNORE, PARAM_FILE_FILTERING_OPTIONS, PARAM_RESPECT_GIT_IGNORE, and PARAM_RESPECT_GEMINI_IGNORE.
    • Refactored replace tool declaration to use PARAM_FILE_PATH, EDIT_PARAM_INSTRUCTION, EDIT_PARAM_OLD_STRING, EDIT_PARAM_NEW_STRING, and EDIT_PARAM_ALLOW_MULTIPLE.
    • Refactored google_web_search tool declaration to use WEB_SEARCH_PARAM_QUERY.
    • Refactored web_fetch tool declaration to use WEB_FETCH_PARAM_PROMPT.
    • Refactored read_many_files tool declaration to use READ_MANY_PARAM_INCLUDE, READ_MANY_PARAM_EXCLUDE, READ_MANY_PARAM_RECURSIVE, READ_MANY_PARAM_USE_DEFAULT_EXCLUDES, PARAM_FILE_FILTERING_OPTIONS, PARAM_RESPECT_GIT_IGNORE, and PARAM_RESPECT_GEMINI_IGNORE.
    • Refactored save_memory tool declaration to use MEMORY_PARAM_FACT.
    • Refactored write_todos tool declaration to use TODOS_PARAM_TODOS.
    • Refactored get_internal_docs tool declaration to use DOCS_PARAM_PATH.
    • Refactored ask_user tool declaration to use ASK_USER_PARAM_QUESTIONS.
    • Refactored enter_plan_mode tool declaration to use PLAN_MODE_PARAM_REASON.
  • packages/core/src/tools/tool-names.ts
    • Exported all newly defined shared and tool-specific parameter constants from coreTools.ts.
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.

Copy link
Contributor

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

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 is a good step towards improving maintainability by refactoring hardcoded tool parameter names into centralized constants. The changes in the tool definition files and prompt snippets are well-executed. However, the refactoring is critically incomplete as the new constants are not used within the tool implementation files themselves (e.g., grep.ts, shell.ts), where parameters are still accessed via hardcoded strings. This leaves the codebase in an inconsistent state and undermines the primary goal of the PR. I've added a comment with details on how to complete the refactoring.


// ============================================================================
// TOOL NAMES
// SHARED PARAMETER NAMES (used by multiple tools)
Copy link
Contributor

Choose a reason for hiding this comment

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

critical

This is a great refactoring to centralize tool parameter names. However, the refactoring appears to be incomplete. The newly introduced constants are not used in the tool implementation files, where parameter values are still accessed using hardcoded strings. This undermines the goal of improving maintainability and reducing typos, leaving the codebase in an inconsistent state.

To complete this refactoring, the constants should also be used when accessing parameters in the tool implementation files, such as:

  • packages/core/src/tools/edit.ts
  • packages/core/src/tools/grep.ts
  • packages/core/src/tools/memoryTool.ts
  • packages/core/src/tools/read-file.ts
  • packages/core/src/tools/shell.ts
  • packages/core/src/tools/write-file.ts

For example, in packages/core/src/tools/shell.ts, this.params.command should be changed to this.params[SHELL_PARAM_COMMAND].

@github-actions
Copy link

Size Change: +7.02 kB (+0.03%)

Total Size: 25.7 MB

Filename Size Change
./bundle/gemini.js 25.2 MB +7.02 kB (+0.03%)
ℹ️ View Unchanged
Filename Size
./bundle/node_modules/@google/gemini-cli-devtools/dist/client/main.js 221 kB
./bundle/node_modules/@google/gemini-cli-devtools/dist/src/_client-assets.js 227 kB
./bundle/node_modules/@google/gemini-cli-devtools/dist/src/index.js 11.5 kB
./bundle/node_modules/@google/gemini-cli-devtools/dist/src/types.js 132 B
./bundle/sandbox-macos-permissive-open.sb 890 B
./bundle/sandbox-macos-permissive-proxied.sb 1.31 kB
./bundle/sandbox-macos-restrictive-open.sb 3.36 kB
./bundle/sandbox-macos-restrictive-proxied.sb 3.56 kB
./bundle/sandbox-macos-strict-open.sb 4.82 kB
./bundle/sandbox-macos-strict-proxied.sb 5.02 kB

compressed-size-action

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant