grokkit/cmd/review.go
Greg Gauthier 9bd3e1d00e refactor: add error handling and refactor git utilities
- Enhance error checking in all commands using git.Run
- Refactor git helper to return errors properly
- Fix README.md filename typo
- Update .gitignore with additional ignores
- Add fallback for config home dir
- Improve request handling in grok client
2026-03-01 12:08:49 +00:00

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(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)
},
}