Introduce support for per-command model defaults in config.toml, overriding global default if set. Update GetModel to accept command name and prioritize: flag > command default > global default. Add example config file and adjust all commands to pass their name. Update tests accordingly.
40 lines
1.1 KiB
Go
40 lines
1.1 KiB
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 reviewCmd = &cobra.Command{
|
|
Use: "review [path]",
|
|
Short: "Review the current repository or directory",
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
modelFlag, _ := cmd.Flags().GetString("model")
|
|
model := config.GetModel("review", modelFlag)
|
|
|
|
client := grok.NewClient()
|
|
diff, err := git.Run([]string{"diff", "--no-color"})
|
|
if err != nil {
|
|
color.Red("Failed to get git diff: %v", err)
|
|
return
|
|
}
|
|
status, err := git.Run([]string{"status", "--short"})
|
|
if err != nil {
|
|
color.Red("Failed to get git status: %v", err)
|
|
return
|
|
}
|
|
|
|
messages := []map[string]string{
|
|
{"role": "system", "content": "You are an expert code reviewer. Give a concise summary + 3-5 actionable improvements."},
|
|
{"role": "user", "content": fmt.Sprintf("Git status:\n%s\n\nGit diff:\n%s", status, diff)},
|
|
}
|
|
color.Yellow("Grok is reviewing the repo...")
|
|
client.Stream(messages, model)
|
|
},
|
|
}
|