Skip to content

Add Feature(build): auto-generate Modelfile and add --regenerate flag#414

Open
gmarav05 wants to merge 1 commit intomodelpack:mainfrom
gmarav05:feature/auto-generate-modelfile
Open

Add Feature(build): auto-generate Modelfile and add --regenerate flag#414
gmarav05 wants to merge 1 commit intomodelpack:mainfrom
gmarav05:feature/auto-generate-modelfile

Conversation

@gmarav05
Copy link

@gmarav05 gmarav05 commented Feb 11, 2026

This PR simplifies the modctl build workflow.

Now, if a Modelfile is missing, it will be generated automatically during build.
A new --regenerate flag is added to force regeneration before building.

Fixes #362

What changed

build auto-generates Modelfile if not found

Added --regenerate flag

Existing behavior will be unchanged if a Modelfile already exists

Tested

  1. Build without Modelfile is working
Screenshot 2026-02-11 at 6 07 06 PM
  1. Build with existing Modelfile is working
Screenshot 2026-02-11 at 6 07 28 PM
  1. Build with --regenerate is working
Screenshot 2026-02-11 at 6 07 50 PM

@gemini-code-assist
Copy link

Summary of Changes

Hello @gmarav05, 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 modctl build command by introducing intelligent Modelfile management. It simplifies the user experience by automating the creation of a default Modelfile when none exists and provides an explicit option to regenerate it, ensuring greater flexibility and ease of use in the build workflow.

Highlights

  • Automated Modelfile Generation: The build process now automatically generates a Modelfile if one is not found in the working directory, streamlining the initial setup for new projects.
  • New --regenerate Flag: A new command-line flag, --regenerate, has been introduced to explicitly force the regeneration of the Modelfile before a build, even if an existing Modelfile is present.

🧠 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.

Changelog
  • cmd/build.go
    • Added new imports for file system operations and Modelfile generation utilities.
    • Introduced the --regenerate boolean flag to the build command.
    • Implemented logic within runBuild to check for Modelfile existence or the --regenerate flag, triggering automatic generation if needed.
    • Updated the build function call to use the dynamically determined Modelfile path.
  • pkg/config/build.go
    • Added a Regenerate boolean field to the Build configuration struct.
    • Initialized the Regenerate field to false in the NewBuild constructor.
Activity
  • The author has provided detailed testing scenarios, including building without a Modelfile, with an existing Modelfile, and with the new --regenerate flag, all confirmed to be working as expected.
  • Screenshots demonstrating the successful execution of each test case have been included in the pull request description.
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

@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 helpful feature to automatically generate a Modelfile during the build process if one is not found, along with a --regenerate flag to force this action. The implementation is mostly solid, but I've identified a few areas for improvement regarding path resolution, error handling, and code clarity in the runBuild function. My suggestions aim to make the new logic more robust and easier to understand. Addressing these points will help prevent potential bugs and improve the maintainability of the code.

Comment on lines 81 to 84
modelfilePath := buildConfig.Modelfile
if modelfilePath == "" {
modelfilePath = filepath.Join(workDir, configmodelfile.DefaultModelfileName)
}

Choose a reason for hiding this comment

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

high

The modelfilePath is not correctly resolved against the workDir. When a relative path is used for the modelfile (which is the default), os.Stat(modelfilePath) will check for the file in the current working directory of the modctl process, not in the specified workDir. This can lead to incorrect behavior, such as failing to find an existing Modelfile or generating a new one in the wrong location. The path should be explicitly joined with workDir if it's relative.

Suggested change
modelfilePath := buildConfig.Modelfile
if modelfilePath == "" {
modelfilePath = filepath.Join(workDir, configmodelfile.DefaultModelfileName)
}
modelfilePath := buildConfig.Modelfile
if modelfilePath == "" {
modelfilePath = filepath.Join(workDir, configmodelfile.DefaultModelfileName)
} else if !filepath.IsAbs(modelfilePath) {
modelfilePath = filepath.Join(workDir, modelfilePath)
}

cmd/build.go Outdated
Comment on lines 86 to 94
shouldGenerate := false

if buildConfig.Regenerate {
fmt.Println("Regenerate flag detected. Regenerating Modelfile...")
shouldGenerate = true
} else if _, err := os.Stat(modelfilePath); os.IsNotExist(err) {
fmt.Println("No Modelfile found. Generating automatically...")
shouldGenerate = true
}

Choose a reason for hiding this comment

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

medium

The error from os.Stat is only checked for os.IsNotExist. Any other error (e.g., permission denied) will be silently ignored. This will cause shouldGenerate to be false, and the build will proceed, likely failing later when trying to read the modelfile. It's better to handle other potential errors from os.Stat explicitly for robustness.

Suggested change
shouldGenerate := false
if buildConfig.Regenerate {
fmt.Println("Regenerate flag detected. Regenerating Modelfile...")
shouldGenerate = true
} else if _, err := os.Stat(modelfilePath); os.IsNotExist(err) {
fmt.Println("No Modelfile found. Generating automatically...")
shouldGenerate = true
}
shouldGenerate := buildConfig.Regenerate
if shouldGenerate {
fmt.Println("Regenerate flag detected. Regenerating Modelfile...")
} else {
_, err := os.Stat(modelfilePath)
if os.IsNotExist(err) {
fmt.Println("No Modelfile found. Generating automatically...")
shouldGenerate = true
} else if err != nil {
return fmt.Errorf("error checking for Modelfile at %s: %w", modelfilePath, err)
}
}

Comment on lines 97 to 104
genConfig := configmodelfile.NewGenerateConfig()
genConfig.Workspace = workDir
genConfig.Output = workDir
genConfig.Overwrite = true

if err := genConfig.Convert(workDir); err != nil {
return fmt.Errorf("failed to prepare modelfile generation: %w", err)
}

Choose a reason for hiding this comment

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

medium

The setup for genConfig is a bit confusing. genConfig.Output is set and then converted to an absolute path inside genConfig.Convert, but this value is never used. The only relevant side effect of genConfig.Convert seems to be making genConfig.Workspace an absolute path. This can be simplified to make the intent clearer and reduce reliance on the side effects of Convert.

Suggested change
genConfig := configmodelfile.NewGenerateConfig()
genConfig.Workspace = workDir
genConfig.Output = workDir
genConfig.Overwrite = true
if err := genConfig.Convert(workDir); err != nil {
return fmt.Errorf("failed to prepare modelfile generation: %w", err)
}
genConfig := configmodelfile.NewGenerateConfig()
absWorkDir, err := filepath.Abs(workDir)
if err != nil {
return fmt.Errorf("failed to resolve workspace path: %w", err)
}
genConfig.Workspace = absWorkDir
genConfig.Overwrite = true

@gmarav05 gmarav05 force-pushed the feature/auto-generate-modelfile branch from e093354 to 8d8dc4b Compare February 11, 2026 14:01
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.

Simplify the user experience for build

1 participant