grokkit/cmd/review.go

49 lines
1.2 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package cmd
import (
"fmt"
"github.com/fatih/color"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"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) {
model := viper.GetString("model")
client := grok.NewClient()
if !git.IsRepo() {
color.Yellow("Not a git repo — basic analysis only.")
}
status := git.Run([]string{"status", "--short"})
unstagedDiff := git.Run([]string{"diff"})
files := git.Run([]string{"ls-files"})
if files == "" {
files = "No tracked files."
}
context := fmt.Sprintf(`Git status:\n\n%s\n\nUnstaged diff:\n%s\n\nTracked files:\n%s`, status, unstagedDiff, files)
systemPrompt := `You are an expert code reviewer.
Give a concise summary + 35 actionable improvements.`
messages := []map[string]string{
{"role": "system", "content": systemPrompt},
{"role": "user", "content": "Review this project:\\n" + context},
}
review := client.Stream(messages, model)
fmt.Println(color.YellowString("🤖 AI Code Review:"))
fmt.Println()
fmt.Print(color.CyanString(review))
fmt.Println()
},
}