Skip to content

feat(cli): add inline natural-language shell expansion#22866

Closed
migarci2 wants to merge 1 commit intogoogle-gemini:mainfrom
migarci2:feat/add-natural-language-shell-prefix
Closed

feat(cli): add inline natural-language shell expansion#22866
migarci2 wants to merge 1 commit intogoogle-gemini:mainfrom
migarci2:feat/add-natural-language-shell-prefix

Conversation

@migarci2
Copy link
Copy Markdown

Title

feat(cli): add inline natural-language shell expansion in shell mode

Body

Summary

Adds inline natural-language command expansion to shell mode.

When shell mode is active, input that starts with ? is treated as a request to
generate a single editable shell command instead of being executed directly.
This covers the gap between “I know the exact shell command” and “I need a full
agent conversation,” while keeping the shell workflow fast and explicit.

Details

This PR adds a shell-mode-only expansion flow rather than introducing a new
agent mode.

Behavior:

  1. In shell mode, a line beginning with ? is intercepted before normal shell
    execution.
  2. The natural-language text after ? is sent to Gemini with a constrained
    prompt that asks for a single shell command only.
  3. The generated command is normalized and inserted back into the input buffer.
  4. The command remains fully editable and is never auto-executed.
  5. A small user hint is shown when the line starts with ?, and a transient
    “Generating shell command...” message is shown while expansion is in flight.

Implementation notes:

  • Added a dedicated shell expansion hook for prompt construction and response
    cleanup.
  • Updated InputPrompt to route ?-prefixed shell input through inline
    expansion.
  • Preserved existing shell editing and execution flow after the command is
    inserted.
  • Kept ? shortcuts help behavior unchanged outside shell mode.
  • Updated relevant shell-mode docs.

This issue is currently labeled priority/p2.

image image image

Related Issues

Closes #21798
Related to #21192

How to Validate

Build and run from the repo root:

npm run generate
npm run build
npm run start

If Gemini auth is not already configured, set an API key first:

export GEMINI_API_KEY=YOUR_API_KEY
npm run generate
npm run build
npm run start

Manual validation:

  1. Start the CLI.
  2. Enter shell mode with !.
  3. Type ? find all .log files older than 7 days.
  4. Confirm a hint appears telling you that Enter will generate an editable
    shell command.
  5. Press Enter.
  6. Confirm the current input is replaced with a generated shell command.
  7. Confirm nothing executes automatically.
  8. Edit the generated command if needed.
  9. Press Enter again to execute it.

Additional prompts to try:

  • ? find all .log files
  • ? show processes using port 3000
  • ? show commits from the last 3 days

Edge cases:

  1. In shell mode, type only ? and press Enter.
    Expected: a short error/hint is shown and nothing executes.
  2. Outside shell mode, type ? on an empty prompt.
    Expected: the existing shortcuts help behavior still works.
  3. In shell mode, type ? ..., generate a command, then edit it manually.
    Expected: normal shell editing behavior is preserved.

Automated checks run:

npm run generate
npm run build --workspace @google/gemini-cli-core
cd packages/cli
npx vitest run src/ui/components/InputPrompt.test.tsx src/ui/hooks/useShellCommandExpansion.test.ts
npx eslint src/ui/components/InputPrompt.tsx src/ui/components/InputPrompt.test.tsx src/ui/hooks/useShellCommandExpansion.ts src/ui/hooks/useShellCommandExpansion.test.ts

Pre-Merge Checklist

  • Updated relevant documentation and README (if needed)
  • Added/updated tests (if needed)
  • Noted breaking changes (none)
  • Validated on required platforms/methods:
    • MacOS
      • npm run
      • npx
      • Docker
      • Podman
      • Seatbelt
    • Windows
      • npm run
      • npx
      • Docker
    • Linux
      • npm run
      • npx
      • Docker

@migarci2 migarci2 requested review from a team as code owners March 17, 2026 22:48
@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 introduces a significant enhancement to the CLI's shell mode by integrating inline natural-language shell command expansion. This feature allows users to quickly translate natural language requests into executable shell commands without leaving the shell context, bridging the gap between direct command input and full agent conversations. It aims to streamline the workflow for users who know what they want to achieve but might not recall the exact command syntax, providing an editable command for safety and flexibility.

Highlights

  • Inline Natural-Language Shell Expansion: Introduced a new feature allowing users in shell mode to type '?' followed by a natural-language request to generate an editable shell command.
  • Non-Executing Command Generation: The generated shell command is inserted into the input buffer for review and editing, and is never automatically executed, ensuring user control.
  • User Feedback and Hints: Implemented transient messages and hints to guide users when initiating a natural-language shell expansion request.
  • Dedicated Expansion Logic: Added a new React hook ('useShellCommandExpansion') and associated logic to handle prompt construction, Gemini API calls, and response parsing for shell command generation.
  • Documentation Updates: Updated the 'commands.md' and 'keyboard-shortcuts.md' documentation to reflect the new '?' prefix behavior in shell mode.
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.

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 introduces an excellent new feature for shell mode: inline natural-language command expansion. When a user prefixes their input with ?, the CLI now uses Gemini to generate a corresponding shell command and inserts it into the prompt for editing and execution. The implementation is robust, leveraging a new React hook useShellCommandExpansion that correctly handles asynchronous operations and cancellations. The feature is well-integrated into the existing InputPrompt component, and the changes include thorough tests and documentation updates. The code quality is high, and I found no critical or high-severity issues.

@gemini-cli gemini-cli Bot added priority/p2 Important but can be addressed in a future release. area/agent Issues related to Core Agent, Tools, Memory, Sub-Agents, Hooks, Agent Quality labels Mar 17, 2026
@gemini-cli
Copy link
Copy Markdown
Contributor

gemini-cli Bot commented Apr 1, 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!

@gemini-cli gemini-cli Bot closed this Apr 1, 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/p2 Important but can be addressed in a future release.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Smart shell mode

1 participant