grokkit/cmd/review.go
Greg Gauthier 99ef10b16b
Some checks failed
CI / Test (push) Successful in 34s
CI / Lint (push) Failing after 19s
CI / Build (push) Successful in 20s
refactor(cmd): extract run funcs and add injectable deps for testability
- Introduce newGrokClient and gitRun vars to allow mocking in tests.
- Refactor commit, commitmsg, history, prdescribe, and review cmds into separate run funcs.
- Update docs, lint, and review to use newGrokClient.
- Add comprehensive unit tests in run_test.go covering happy paths, errors, and edge cases.
- Expand grok client tests with SSE server mocks for Stream* methods.
2026-03-02 20:47:16 +00:00

44 lines
1.1 KiB
Go

package cmd
import (
"fmt"
"github.com/fatih/color"
"github.com/spf13/cobra"
"gmgauthier.com/grokkit/config"
)
var reviewCmd = &cobra.Command{
Use: "review [path]",
Short: "Review the current repository or directory",
Run: runReview,
}
func runReview(cmd *cobra.Command, args []string) {
modelFlag, _ := cmd.Flags().GetString("model")
model := config.GetModel("review", modelFlag)
diff, err := gitRun([]string{"diff", "--no-color"})
if err != nil {
color.Red("Failed to get git diff: %v", err)
return
}
status, err := gitRun([]string{"status", "--short"})
if err != nil {
color.Red("Failed to get git status: %v", err)
return
}
client := newGrokClient()
messages := buildReviewMessages(status, diff)
color.Yellow("Grok is reviewing the repo...")
client.Stream(messages, model)
}
func buildReviewMessages(status, diff string) []map[string]string {
return []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)},
}
}