Skip to content

Conversation

@doringeman
Copy link
Contributor

Add withStandaloneRunner decorator to wrap commands that require a running model runner, ensuring consistent auto-installation behavior across all CLI commands.

Fixes #274.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @doringeman, 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 refactors the command-line interface (CLI) to centralize the initialization and availability checks for the standalone model runner. By introducing a withStandaloneRunner decorator, the PR ensures that all commands requiring a running model runner consistently perform necessary setup, including auto-installation, without duplicating logic across multiple command implementations. This change improves code maintainability, reduces boilerplate, and provides a more robust and consistent user experience across the CLI.

Highlights

  • Centralized Runner Initialization: Introduced a withStandaloneRunner decorator to automatically ensure the model runner is available for CLI commands that require it, streamlining setup and ensuring consistent behavior.
  • Decoupled Runner Checks: Removed redundant ensureStandaloneRunnerAvailable calls from individual command RunE methods, delegating this responsibility to the new withStandaloneRunner decorator.
  • New Utility Functions: Added withStandaloneRunner (a decorator for cobra.Commands) and getStandaloneRunner (for retrieving runner information) in install-runner.go.
  • Improved Command Structure: Refactored root.go to clearly separate runner management commands from commands that depend on a running runner, applying the new decorator to the latter for automatic initialization.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

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

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey - I've found 1 issue, and left some high level feedback:

  • The withStandaloneRunner decorator only wraps RunE and silently no-ops for commands that use Run; if any of the wrapped commands or future additions use Run instead of RunE, they will skip runner initialization—consider either handling Run as well or explicitly enforcing RunE usage for commands in the wrapped set.
  • In withStandaloneRunner you always pass false as the debug argument to ensureStandaloneRunnerAvailable, whereas newRunCmd previously forwarded its debug flag; if the debug setting is still relevant for automatic installation behavior, it might be worth threading that through instead of hardcoding false.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The `withStandaloneRunner` decorator only wraps `RunE` and silently no-ops for commands that use `Run`; if any of the wrapped commands or future additions use `Run` instead of `RunE`, they will skip runner initialization—consider either handling `Run` as well or explicitly enforcing `RunE` usage for commands in the wrapped set.
- In `withStandaloneRunner` you always pass `false` as the `debug` argument to `ensureStandaloneRunnerAvailable`, whereas `newRunCmd` previously forwarded its `debug` flag; if the debug setting is still relevant for automatic installation behavior, it might be worth threading that through instead of hardcoding `false`.

## Individual Comments

### Comment 1
<location> `cmd/cli/commands/install-runner.go:169-175` </location>
<code_context>
+// withStandaloneRunner wraps a command's RunE to ensure the standalone runner
+// is available before executing the command. This is a no-op in unsupported
+// contexts (e.g., Docker Desktop) or if automatic installations have been disabled.
+func withStandaloneRunner(cmd *cobra.Command) *cobra.Command {
+	if cmd.RunE == nil {
+		return cmd
+	}
+	originalRunE := cmd.RunE
+	cmd.RunE = func(cmd *cobra.Command, args []string) error {
+		if _, err := ensureStandaloneRunnerAvailable(cmd.Context(), asPrinter(cmd), false); err != nil {
+			return fmt.Errorf("unable to initialize standalone model runner: %w", err)
+		}
</code_context>

<issue_to_address>
**issue (bug_risk):** `withStandaloneRunner` hardcodes `debug` to `false`, changing behavior for commands that previously passed it through.

Commands like `run` previously called `ensureStandaloneRunnerAvailable` with their `debug` flag, but `withStandaloneRunner` now always passes `false`. If `debug` alters logging or initialization behavior, this will silently drop debug mode even when `--debug` is set. Please pass a per-command debug value into `withStandaloneRunner` (or derive it from `*cobra.Command`) so commands can still propagate their debug state.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

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 a significant refactoring to centralize the standalone model runner initialization logic. By adding a withStandaloneRunner decorator, the repeated checks and auto-installation logic are removed from individual commands and handled in a consistent, centralized manner in root.go. This greatly improves code maintainability and reduces duplication. The changes are well-executed, and I have one minor suggestion for improvement.

Add withStandaloneRunner decorator to wrap commands that require a running model runner, ensuring consistent auto-installation behavior across all CLI commands.

Signed-off-by: Dorin Geman <dorin.geman@docker.com>
@doringeman doringeman force-pushed the cmd-ensure-dmr-container branch from 95907a6 to 1b6f2ce Compare December 22, 2025 13:25
@doringeman doringeman merged commit 536b0b4 into docker:main Dec 22, 2025
9 checks passed
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.

df command doesn't ensure that standalone runner is available

2 participants