grokkit/cmd/commitmsg.go

36 lines
1008 B
Go
Raw Normal View History

// Last modified: 2026-02-28 22:43:38 GMT
// Current time: 2024-08-07 10:00:00
2026-02-28 18:03:12 +00:00
package cmd
2026-02-28 18:28:27 +00:00
2026-02-28 19:56:23 +00:00
import (
"fmt"
"github.com/fatih/color"
"github.com/spf13/cobra"
"gmgauthier.com/grokkit/config"
2026-02-28 19:56:23 +00:00
"gmgauthier.com/grokkit/internal/git"
"gmgauthier.com/grokkit/internal/grok"
)
2026-02-28 18:28:27 +00:00
var commitMsgCmd = &cobra.Command{
Use: "commit-msg",
Short: "Generate conventional commit message from 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
2026-02-28 19:56:23 +00:00
}
modelFlag, _ := cmd.Flags().GetString("model")
model := config.GetModel(modelFlag)
client := grok.NewClient()
2026-02-28 19:56:23 +00:00
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)},
2026-02-28 19:56:23 +00:00
}
color.Yellow("Generating commit message...")
client.Stream(messages, model)
2026-02-28 18:28:27 +00:00
},
}