Skip to content

Conversation

hminooei
Copy link
Contributor

@hminooei hminooei commented Oct 7, 2025

TLDR

Our goal is to optimize the shell commands to promote concise and high-signal outputs, reducing context bloat.

Dive Deeper

Please see

Reviewer Test Plan

No regression on swebench-v and Terminal Bench.

Linked issues / bugs

This PR makes progress on #10270

@hminooei hminooei requested a review from a team as a code owner October 7, 2025 00:09
Copy link
Contributor

Summary of Changes

Hello @hminooei, 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 foundational set of operational guidelines aimed at optimizing the execution and output of shell commands. The primary goal is to foster more concise and high-signal interactions, thereby reducing unnecessary context and improving efficiency. These guidelines cover strategies for minimizing output verbosity using platform-specific quiet flags and for managing extensive command outputs by redirecting them to log files for selective review.

Highlights

  • Shell Command Optimization Guidelines: Introduced new operational guidelines for optimizing shell commands to promote concise and high-signal outputs, aiming to reduce context bloat.
  • Token-Efficient Flags: Added guidance and examples for using token-efficient flags (e.g., -q, --quiet, -s, del /q) on both Linux and Windows to suppress verbose output and only show errors when appropriate.
  • Local File System as Memory: Provided instructions and examples on how to leverage the local file system as memory for commands with long outputs, by redirecting stdout and stderr to log files (e.g., cmd > out.log 2> err.log) and then using tools like sed, tail, head, or cat to read specific parts of these logs.
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 introduces optimizations for shell command usage by updating the agent's operational guidelines. The goal is to encourage more concise and efficient shell interactions, such as using quiet flags and redirecting output to files. My review focuses on improving the clarity and efficiency of these new guidelines. Specifically, I've suggested clarifying the output redirection instructions and, more importantly, updating the example workflow to leverage command exit codes for error checking, which is a more robust and efficient approach than unconditionally checking log files.

Comment on lines +68 to +81
- For commands that usually have long output, use cmd >out.log 2>err.log or cmd > out.log 2> err.log in cmd.exe or cmd > out.log 2> err.log in powershell, to separate the stdout vs stderr.
- Then use sed/tail/head or cmd.exe / powershell equivalent commands to read a specific line range (or all) of the log file.
<example>
user: Run the build and let me know if there are any errors.
model: [tool_call: run_shell_command for 'npm run build > build.log 2> build.err']
(After command execution)
model: The build process is complete. I will now check the error log.
[tool_call: run_shell_command for 'tail -n 10 build.err']
(After noticing errors exist)
model: Read the whole error log to understand the issues.
[tool_call: run_shell_command for 'cat build.err']
(After reading the file)
model: The build failed due to a missing semicolon in src/index.ts and an undefined variable in src/app.ts. Would you like me to fix these issues?
</example>
Copy link
Contributor

Choose a reason for hiding this comment

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

high

The guidance for output redirection and the accompanying example can be improved for clarity and efficiency.

  1. Clarify Redirection Guidance: The current explanation for output redirection is a bit repetitive and platform-specific. A more universal and concise explanation would be easier for the model to understand and apply.
  2. Incorporate Exit Code Check: The example workflow for checking build errors is inefficient. It involves checking the error log file regardless of whether the command succeeded or failed. The run_shell_command tool returns an exit code, which is a much more reliable and efficient way to determine success or failure. The prompt should instruct the model to check the exit code first, and only inspect the error log if the exit code is non-zero.

Here is a suggested improvement for this section:

- For commands with potentially long output, redirect stdout and stderr to files (e.g., `command > out.log 2> err.log`). After the command runs, **check the exit code first**. A non-zero exit code indicates an error, and you should then inspect the `err.log` file.
- Then use `cat`, `tail`, or `head` (or platform equivalents) to read the log files.
<example>
user: Run the build and let me know if there are any errors.
model: [tool_call: run_shell_command for 'npm run build > build.log 2> build.err']
(After command execution, the tool returns a non-zero exit code)
model: The build failed. I will now check the error log to understand the issue.
[tool_call: run_shell_command for 'cat build.err']
(After reading the file)
model: The build failed due to a missing semicolon in src/index.ts and an undefined variable in src/app.ts. Would you like me to fix these issues?
</example>

Comment on lines +180 to +193
- For commands that usually have long output, use cmd >out.log 2>err.log or cmd > out.log 2> err.log in cmd.exe or cmd > out.log 2> err.log in powershell, to separate the stdout vs stderr.
- Then use sed/tail/head or cmd.exe / powershell equivalent commands to read a specific line range (or all) of the log file.
<example>
user: Run the build and let me know if there are any errors.
model: [tool_call: ${ShellTool.Name} for 'npm run build > build.log 2> build.err']
(After command execution)
model: The build process is complete. I will now check the error log.
[tool_call: ${ShellTool.Name} for 'tail -n 10 build.err']
(After noticing errors exist)
model: Read the whole error log to understand the issues.
[tool_call: ${ShellTool.Name} for 'cat build.err']
(After reading the file)
model: The build failed due to a missing semicolon in src/index.ts and an undefined variable in src/app.ts. Would you like me to fix these issues?
</example>
Copy link
Contributor

Choose a reason for hiding this comment

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

high

The guidance for output redirection and the accompanying example can be improved for clarity and efficiency.

  1. Clarify Redirection Guidance: The current explanation for output redirection is a bit repetitive and platform-specific. A more universal and concise explanation would be easier for the model to understand and apply.
  2. Incorporate Exit Code Check: The example workflow for checking build errors is inefficient. It involves checking the error log file regardless of whether the command succeeded or failed. The run_shell_command tool returns an exit code, which is a much more reliable and efficient way to determine success or failure. The prompt should instruct the model to check the exit code first, and only inspect the error log if the exit code is non-zero.

Here is a suggested improvement for this section:

- For commands with potentially long output, redirect stdout and stderr to files (e.g., `command > out.log 2> err.log`). After the command runs, **check the exit code first**. A non-zero exit code indicates an error, and you should then inspect the `err.log` file.
- Then use `cat`, `tail`, or `head` (or platform equivalents) to read the log files.
<example>
user: Run the build and let me know if there are any errors.
model: [tool_call: ${ShellTool.Name} for 'npm run build > build.log 2> build.err']
(After command execution, the tool returns a non-zero exit code)
model: The build failed. I will now check the error log to understand the issue.
[tool_call: ${ShellTool.Name} for 'cat build.err']
(After reading the file)
model: The build failed due to a missing semicolon in src/index.ts and an undefined variable in src/app.ts. Would you like me to fix these issues?
</example>

Copy link

github-actions bot commented Oct 7, 2025

Size Change: +1.65 kB (+0.01%)

Total Size: 17.6 MB

Filename Size Change
./bundle/gemini.js 17.6 MB +1.65 kB (+0.01%)
ℹ️ View Unchanged
Filename Size
./bundle/sandbox-macos-permissive-closed.sb 1.03 kB
./bundle/sandbox-macos-permissive-open.sb 830 B
./bundle/sandbox-macos-permissive-proxied.sb 1.31 kB
./bundle/sandbox-macos-restrictive-closed.sb 3.29 kB
./bundle/sandbox-macos-restrictive-open.sb 3.36 kB
./bundle/sandbox-macos-restrictive-proxied.sb 3.56 kB

compressed-size-action

@hminooei hminooei requested review from anj-s and owenofbrien October 7, 2025 00:37
@hminooei hminooei changed the title first version of shell tool optimizaiton first version of shell tool optimization Oct 7, 2025
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