grokkit/cmd/commit.go
Greg Gauthier f0858e08c1 refactor(cli): simplify commands and remove TUI dependencies
- Switch chat command from Bubble Tea TUI to basic CLI with bufio.
- Hardcode Grok model in commands, remove Viper config.
- Stream responses directly in client, remove channel-based streaming.
- Add safe previews/backups in edit, simplify prompts across tools.
- Update git helper and trim unused deps in go.mod.
2026-02-28 20:17:12 +00:00

46 lines
1.2 KiB
Go

package cmd
import (
"fmt"
"os/exec"
"github.com/fatih/color"
"github.com/spf13/cobra"
"gmgauthier.com/grokkit/internal/git"
"gmgauthier.com/grokkit/internal/grok"
)
var commitCmd = &cobra.Command{
Use: "commit",
Short: "Generate message and commit 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
}
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...")
msg := client.Stream(messages, "grok-4")
color.Cyan("\nProposed commit message:\n%s", msg)
var confirm string
color.Yellow("Commit with this message? (y/n): ")
fmt.Scanln(&confirm)
if confirm != "y" && confirm != "Y" {
color.Yellow("Aborted.")
return
}
if err := exec.Command("git", "commit", "-m", msg).Run(); err != nil {
color.Red("Git commit failed")
} else {
color.Green("✅ Committed successfully!")
}
},
}