feat: built-in image generation tool and slash command#20848
feat: built-in image generation tool and slash command#20848jackwotherspoon wants to merge 3 commits intomainfrom
Conversation
Summary of ChangesHello, 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 enhances the CLI's capabilities by integrating advanced image generation and editing functionalities. It allows users to create and modify images directly through command-line prompts, making the CLI a more versatile tool for creative and development workflows. The feature is opt-in via an experimental setting and is designed to work seamlessly with existing Gemini authentication methods. Highlights
Changelog
Activity
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this comment.
Code Review
This pull request introduces a powerful new image generation feature through the GenerateImageTool and a corresponding /image slash command. The implementation is well-structured, with clear separation of concerns between the CLI command parsing and the core tool logic. The new tool includes robust validation, error handling, and support for various generation parameters.
I've identified two high-severity issues. One is related to incomplete validation of the count parameter, which could lead to unhelpful error messages. The other concerns the argument parser for the /image command, which can silently ignore flags, potentially causing user confusion. Addressing these will improve the reliability and user experience of this new feature.
| while (i < parts.length) { | ||
| const part = parts[i]; | ||
| if (part.startsWith('--')) { | ||
| const flagName = part.slice(2).split('=')[0]; | ||
| const inlineValue = part.includes('=') ? part.split('=')[1] : undefined; | ||
|
|
||
| if (inlineValue !== undefined) { | ||
| flags[flagName] = inlineValue; | ||
| } else if (flagName === 'return') { | ||
| flags[flagName] = true; | ||
| } else if (i + 1 < parts.length && !parts[i + 1].startsWith('--')) { | ||
| flags[flagName] = parts[i + 1]; | ||
| i++; | ||
| } | ||
| } | ||
| i++; | ||
| } |
There was a problem hiding this comment.
The argument parser for the /image command can silently ignore flags if they are provided without a required value. For example, if a user runs /image a cat --ratio, the --ratio flag is ignored, and the command proceeds with the default aspect ratio without notifying the user that a value was expected. This can lead to confusing behavior.
I recommend refactoring the parser to be aware of which flags expect values (like --ratio) and which are booleans (like --return). This would allow it to return an error when a flag that requires a value is missing one. For example, you could add an else block to the flag parsing logic to handle cases where a value is expected but not found, and then return an error message to be displayed to the user.
| if (params.count < 1 || params.count > 4) { | ||
| return "The 'count' parameter must be between 1 and 4."; | ||
| } |
There was a problem hiding this comment.
The validation for the count parameter is incomplete. If a non-numeric string is passed for count from the /image command, parseInt will produce NaN. The current validation params.count < 1 || params.count > 4 evaluates to false for NaN, allowing the invalid value to pass. This leads to the tool failing silently without a helpful error message. Please add a check for NaN.
| if (params.count < 1 || params.count > 4) { | |
| return "The 'count' parameter must be between 1 and 4."; | |
| } | |
| if (Number.isNaN(params.count) || params.count < 1 || params.count > 4) { | |
| return "The 'count' parameter must be a number between 1 and 4."; | |
| } |
|
sorry for for offtopic, but what screencap software did you use |
@victornpb totally okay to ask, it is Screen Studio 😎 |
|
Size Change: +23.4 kB (+0.09%) Total Size: 26.6 MB
ℹ️ View Unchanged
|
|
I WANT THIS |
Summary
Introduces a built-in image generation tool and
/imageslash command, enabling users to generate and edit images directly from the CLI using Nano Banana (Gemini) image generation models.Gemini.CLI.-.image.generation.mp4
Details
GenerateImageTooltopackages/corewhich uses@google/genaito interface with Nano Banana models.gemini-3.1-flash-image-preview(NanoBanana 2).USE_GEMINI) or Vertex AI (USE_VERTEX_AI) authentication methods, as "Login with Google" can't support image models currently./image(and/imgalias) slash command topackages/clifor quick image generation.experimental.imageGenerationto toggle this feature.generated-images/).return_to_contextto allow the model to see the generated image for iterative refinement.Related Issues
None (New feature).
How to Validate
Use natural language or
/image./settings.Create an image of a pixel art banana.generated-images/for the output./image make it blue --edit generated-images/banana.png./image a futuristic city --count 3.npm test -w @google/gemini-cli-core -- src/tools/generate-image.test.tsandnpm test -w @google/gemini-cli -- src/ui/commands/imageCommand.test.ts.Pre-Merge Checklist