Skip to content

feat: Implement script output summarization and refine image routing#14097

Closed
mgajda wants to merge 5 commits intogoogle-gemini:mainfrom
mgajda:my-model-preferences
Closed

feat: Implement script output summarization and refine image routing#14097
mgajda wants to merge 5 commits intogoogle-gemini:mainfrom
mgajda:my-model-preferences

Conversation

@mgajda
Copy link
Copy Markdown

@mgajda mgajda commented Nov 28, 2025

This PR addresses the following:

  • Script Output Summarization: Implements a new routing strategy to summarize lengthy script outputs using the flash-lite model, with options to skip summarization for short outputs.
  • Image Model Routing: Enhances the ImageStrategy to route requests to the flash-lite image model when flash-lite is the preferred general model, and to the pro model otherwise.
  • Refinements: Includes corrections to template literal escaping and test file linting errors.

Addresses issues: #1, #2 (assuming these are the issues I just created).

@mgajda mgajda requested review from a team as code owners November 28, 2025 17:22
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @mgajda, 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 model routing capabilities by introducing two new strategies: one for summarizing lengthy script outputs and another for intelligently handling image-related requests. The script output summarization leverages the "flash-lite" model for efficiency, only summarizing outputs above a certain length and preserving critical excerpts. The image routing dynamically selects between "flash-lite" and "pro" image models based on configuration. These changes aim to optimize model usage, improve performance, and expand the CLI's utility, alongside minor code refinements and new feature documentation.

Highlights

  • Script Output Summarization: Implemented a new routing strategy to summarize long script outputs using the "flash-lite" model, with logic to skip summarization for shorter outputs.
  • Image Model Routing Enhancement: Improved the ImageStrategy to intelligently route requests containing images or explicit image generation prompts to either the "flash-lite" image model or the "pro" image model, based on the user's preferred general model and preview feature settings.
  • Model Configuration & Aliases: Introduced new model aliases and configurations for "gemini-2.5-image" and "gemini-2.5-flash-lite-image", and updated model resolution logic to support these.
  • Shell Tool Output Tagging: Modified the ShellToolInvocation to explicitly tag shell command outputs with a "[SHELL_OUTPUT]" prefix and a "toolSpecificInfo" flag, enabling specific routing strategies.
  • Code Quality & Testing: Corrected template literal escaping in "shell.ts" and added comprehensive unit tests for both the new ImageStrategy and ScriptOutputSummarizationStrategy.
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
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 significant new features for script output summarization and image model routing. I've identified several critical issues that need to be addressed. There's a duplicated strategy in the model router, a critical bug in the shell tool that discards command output, and the new summarization strategy is currently ineffective as it doesn't pass the summarized content to the next stage. Additionally, there are bugs in the new ImageStrategy and its tests. My review includes detailed suggestions to fix these issues.

new FallbackStrategy(),
new OverrideStrategy(),
new ScriptOutputSummarizationStrategy(),
new ScriptOutputSummarizationStrategy(),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

critical

The ScriptOutputSummarizationStrategy is instantiated twice. This will cause the strategy to be executed twice for each routing decision, which is inefficient and may lead to unintended side effects. Please remove the duplicate instance.

} as RoutingContext;

// Mock config to disable preview features
vi.spy10('getPreviewFeatures').mockReturnValue(false);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

critical

There is a typo vi.spy10 which should be vi.spyOn. This will cause the test to fail. Additionally, spyOn requires the object to be spied on as the first argument.

Suggested change
vi.spy10('getPreviewFeatures').mockReturnValue(false);
vi.spyOn(mockConfig, 'getPreviewFeatures').mockReturnValue(false);

Comment on lines +54 to +56
const summaryPrompt = `Summarize the following script output concisely:\n\n\n${actualOutput}\n\n\n\
${actualOutput}
`;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

critical

The actualOutput is duplicated in the summaryPrompt. This makes the prompt unnecessarily long and may confuse the model, leading to poor summaries. Please remove the duplicate.

      const summaryPrompt = `Summarize the following script output concisely:\n\n\n${actualOutput}\n`;

Comment on lines +64 to +76
const summarizedOutput = summaryResult.text;

// Return a decision to use the flash-lite model for the summarized output.
// This implies the next stage of routing or processing will use this summarized output.
// A more advanced mechanism might be needed to *replace* the context for subsequent strategies.
return {
model: DEFAULT_GEMINI_FLASH_MODEL, // Using the default flash-lite alias
metadata: {
source: this.name,
latencyMs: 0, // Placeholder, actual measurement needed
reasoning: `Summarized script output using ${DEFAULT_GEMINI_FLASH_MODEL}.`,
},
};
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

critical

This strategy is currently ineffective. It generates a summary of the script output but does not replace the original long output in the context. As a result, subsequent strategies and the main model will still process the original, unsummarized content, defeating the purpose of this strategy.

The strategy should modify the shellOutputPart.text with the summarizedOutput and then return null to allow other routing strategies to determine the model for the next turn based on the new, summarized content.

      const summarizedOutput = summaryResult.text;

      // Replace the original long output with the summary for subsequent processing.
      shellOutputPart.text = summarizedOutput;

      // Return null to allow other strategies to route based on the summarized content.
      return null;


return {
llmContent,
llmContent: `[SHELL_OUTPUT]\nCommand: ${this.params.command}\nDirectory: ${this.params.dir_path || '\'(root)\''}`, // Corrected llmContent with prefix
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

critical

The llmContent is being overwritten with a string that only contains the command and directory, completely omitting the actual output, errors, and exit code of the shell command. This is a critical bug, as the model will not receive the result of the execution. The [SHELL_OUTPUT] prefix should be prepended to the existing llmContent variable, which already contains the full execution details.

        llmContent: `[SHELL_OUTPUT]\n${llmContent}`,

Comment on lines +35 to +47
const preferredGeneralModel = config.getModel();
// Resolve the general model preference to its concrete name
const resolvedGeneralModel = resolveModel(preferredGeneralModel, config.getPreviewFeatures());

let modelToUse: string;
// Check if the preferred general model is 'flash-lite' based on its name
if (resolvedGeneralModel.includes('flash-lite')) {
// Route to the flash-lite image model
modelToUse = GEMINI_MODEL_ALIAS_FLASH_LITE_IMAGE;
} else {
// Fallback to pro image model or default pro model based on preview flag
modelToUse = config.getPreviewFeatures() ? 'gemini-2.5-pro-image-preview' : DEFAULT_GEMINI_MODEL;
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

The logic for selecting an image model is inconsistent and has a bug. When the preferred model is 'flash-lite', it routes to a preview model regardless of whether preview features are enabled. This could lead to using a preview model when it's not intended. The logic is also inconsistent as it returns a concrete model name for the 'pro' preference but an alias for 'flash-lite'.

I suggest refactoring to consistently handle the preview flag and return concrete model names for both cases to improve clarity and correctness.

Suggested change
const preferredGeneralModel = config.getModel();
// Resolve the general model preference to its concrete name
const resolvedGeneralModel = resolveModel(preferredGeneralModel, config.getPreviewFeatures());
let modelToUse: string;
// Check if the preferred general model is 'flash-lite' based on its name
if (resolvedGeneralModel.includes('flash-lite')) {
// Route to the flash-lite image model
modelToUse = GEMINI_MODEL_ALIAS_FLASH_LITE_IMAGE;
} else {
// Fallback to pro image model or default pro model based on preview flag
modelToUse = config.getPreviewFeatures() ? 'gemini-2.5-pro-image-preview' : DEFAULT_GEMINI_MODEL;
}
const previewEnabled = config.getPreviewFeatures();
let modelToUse: string;
if (!previewEnabled) {
modelToUse = DEFAULT_GEMINI_MODEL;
} else {
const preferredGeneralModel = config.getModel();
const resolvedGeneralModel = resolveModel(preferredGeneralModel, previewEnabled);
if (resolvedGeneralModel.includes('flash-lite')) {
modelToUse = 'gemini-2.5-flash-lite-image-preview';
} else {
modelToUse = 'gemini-2.5-pro-image-preview';
}
}

@jackwotherspoon
Copy link
Copy Markdown
Collaborator

The linked issues are not right, can you please use the pull request template and stop overriding it.

It is also very unclear why this pull request is needed maybe you linked wrong issues and you have other issues you meant?

@jackwotherspoon
Copy link
Copy Markdown
Collaborator

jackwotherspoon commented Nov 28, 2025

Pull requests in general should solve one single contained problem or feature. They should be as small as possible to limit separation of concerns, allow for easy reviews, and be able to be cleanly reverted is something introduces a bug.

This PR does two things by the title, "script output summarization and refine image routing".

These are unrelated features or bugs from what I can quickly see. Thus they should be two separate PRs and not one.

I would also prefer discussion on a GitHub issue prior to PRs. As there is no such thing as a flash lite image model and I am not sure what ImageStrategy is trying to do, our models like Gemini 3 and 2.5 Pro etc are multi-modal, they can take in image data as is... are we trying to create images with the change?

Again this is why we require GitHub issues prior to creating PRs.

@jackwotherspoon
Copy link
Copy Markdown
Collaborator

Closing this for now, please have proper GitHub issues linked and separation of concerns for clean pull requests that we can efficiently review. Appreciate it kindly.

@mgajda
Copy link
Copy Markdown
Author

mgajda commented Nov 28, 2025

Thanks for feedback. Will correct my mistake

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.

2 participants