- Introduce config.Load() to handle centralized configuration loading in TOML format - Add --model flag support across commands with alias resolution via GetModel - Update root command to load config in PersistentPreRun - Remove redundant config init and set defaults for model and temperature
34 lines
929 B
Go
34 lines
929 B
Go
package cmd
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/fatih/color"
|
|
"github.com/spf13/cobra"
|
|
"gmgauthier.com/grokkit/config"
|
|
"gmgauthier.com/grokkit/internal/git"
|
|
"gmgauthier.com/grokkit/internal/grok"
|
|
)
|
|
|
|
var commitMsgCmd = &cobra.Command{
|
|
Use: "commit-msg",
|
|
Short: "Generate conventional commit message from staged changes",
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
diff := git.Run([]string{"diff", "--cached", "--no-color"})
|
|
if diff == "" {
|
|
color.Yellow("No staged changes!")
|
|
return
|
|
}
|
|
modelFlag, _ := cmd.Flags().GetString("model")
|
|
model := config.GetModel(modelFlag)
|
|
|
|
client := grok.NewClient()
|
|
messages := []map[string]string{
|
|
{"role": "system", "content": "Return ONLY a conventional commit message (type(scope): subject\n\nbody)."},
|
|
{"role": "user", "content": fmt.Sprintf("Staged changes:\n%s", diff)},
|
|
}
|
|
color.Yellow("Generating commit message...")
|
|
client.Stream(messages, model)
|
|
},
|
|
}
|