Skip to content

fix(core): parse callCommand with shell-quote matching discoveryCommand#19935

Closed
SUNDRAM07 wants to merge 2 commits intogoogle-gemini:mainfrom
SUNDRAM07:fix/19783-callcommand-parsing
Closed

fix(core): parse callCommand with shell-quote matching discoveryCommand#19935
SUNDRAM07 wants to merge 2 commits intogoogle-gemini:mainfrom
SUNDRAM07:fix/19783-callcommand-parsing

Conversation

@SUNDRAM07
Copy link
Copy Markdown

Summary

When tools.callCommand contains arguments (e.g., python3 script.py --call), spawn() received the entire string as a single executable path, causing an ENOENT error. In contrast, tools.discoveryCommand already correctly used shell-quote's parse() to split the command string into an executable and its arguments.

This fix applies the same shell-quote parsing to callCommand in DiscoveredToolInvocation.execute(), making both commands consistent.

Root Cause

In packages/core/src/tools/tool-registry.ts, the DiscoveredToolInvocation.execute() method was passing the raw callCommand string directly to spawn() as the executable:

// Before (broken):
const callCommand = this.config.getToolCallCommand()!;
const child = spawn(callCommand, [this.originalToolName]);

When callCommand was "python3 script.py --call", Node.js tried to find an executable literally named python3 script.py --call, resulting in ENOENT.

Fix

Applied the same shell-quote parse() pattern already used by discoveryCommand:

// After (fixed):
const callCmd = this.config.getToolCallCommand()!;
const callCmdParts = parse(callCmd);
const child = spawn(callCmdParts[0] as string, [
  ...(callCmdParts.slice(1) as string[]),
  this.originalToolName,
]);

Tests

Added two new test cases in tool-registry.test.ts:

  1. callCommand with arguments (python3 script.py --call): Verifies that spawn() receives the executable (python3) and split arguments separately.
  2. Simple callCommand without arguments (my-call-command): Verifies backward compatibility.

All 23 tests pass with zero regressions.

Fixes #19783

@SUNDRAM07 SUNDRAM07 requested a review from a team as a code owner February 22, 2026 19:07
@google-cla
Copy link
Copy Markdown

google-cla bot commented Feb 22, 2026

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @SUNDRAM07, 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 addresses a critical issue where callCommand in DiscoveredToolInvocation.execute() failed to correctly handle commands containing arguments, leading to execution errors. The solution involves integrating shell-quote parsing for callCommand, mirroring the existing robust implementation for discoveryCommand, thereby ensuring consistent and reliable command execution. This change prevents ENOENT errors and improves the stability of tool invocations.

Highlights

  • callCommand Argument Parsing Fix: Resolved an ENOENT error where tools.callCommand with arguments was not correctly parsed by spawn(), by implementing shell-quote parsing.
  • Consistency with discoveryCommand: Aligned callCommand's argument handling with tools.discoveryCommand, which already uses shell-quote for robust parsing.
  • Enhanced Test Coverage: Introduced two new test cases to validate callCommand parsing with and without arguments, ensuring both correct functionality and backward compatibility.
Changelog
  • packages/core/src/tools/tool-registry.test.ts
    • Added a test case to verify callCommand parsing with multiple arguments.
    • Added a test case to ensure backward compatibility for simple callCommand without arguments.
  • packages/core/src/tools/tool-registry.ts
    • Modified DiscoveredToolInvocation.execute() to use shell-quote's parse() function for callCommand before passing it to spawn().
    • Updated spawn() arguments to correctly separate the executable from its arguments.
Activity
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 added the area/agent Issues related to Core Agent, Tools, Memory, Sub-Agents, Hooks, Agent Quality label Feb 22, 2026
Copy link
Copy Markdown
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 correctly fixes a bug where callCommand with arguments would fail. The approach of using shell-quote to parse the command is sound and consistent with how discoveryCommand is handled. The new tests are a great addition, covering both the bug fix and backward compatibility. I've added one critical suggestion to improve the robustness of the command parsing by validating the output from shell-quote to prevent potential runtime errors with complex shell commands.

When tools.callCommand contains arguments (e.g. 'python3 script.py --call'),
spawn() received the entire string as a single executable, causing ENOENT.
discoveryCommand already correctly used shell-quote parse() to split the
command string. This fix applies the same parsing to callCommand.

The parsed output is now validated to ensure all parts are strings,
rejecting commands with unsupported shell operators (e.g. pipes, &&).

Fixes google-gemini#19783
@gemini-cli
Copy link
Copy Markdown
Contributor

gemini-cli bot commented Mar 15, 2026

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!

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Inconsistent parsing of tools.discoveryCommand and tools.callCommand for command-based custom tools

1 participant