Introduce new `agent` command that scans .go files in the project, generates an AI-driven plan for changes based on user instruction, and applies edits with previews and backups. Includes integration with Grok client for planning and content generation. Update existing files with timestamp comments as part of the agent's editing demonstration. Add agentCmd to root command.
38 lines
1.1 KiB
Go
38 lines
1.1 KiB
Go
// Current time: 2023-10-05 14:30:00
|
|
|
|
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 prDescribeCmd = &cobra.Command{
|
|
Use: "pr-describe",
|
|
Short: "Generate full PR description from current branch",
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
diff := git.Run([]string{"diff", "main..HEAD", "--no-color"})
|
|
if diff == "" {
|
|
diff = git.Run([]string{"diff", "origin/main..HEAD", "--no-color"})
|
|
}
|
|
if diff == "" {
|
|
color.Yellow("No changes on this branch compared to main/origin/main.")
|
|
return
|
|
}
|
|
modelFlag, _ := cmd.Flags().GetString("model")
|
|
model := config.GetModel(modelFlag)
|
|
|
|
client := grok.NewClient()
|
|
messages := []map[string]string{
|
|
{"role": "system", "content": "Write a professional GitHub PR title + detailed body (changes, motivation, testing notes)."},
|
|
{"role": "user", "content": fmt.Sprintf("Diff:\n%s", diff)},
|
|
}
|
|
color.Yellow("Writing PR description...")
|
|
client.Stream(messages, model)
|
|
},
|
|
} |