refactor(edit): improve response handling and add diff preview

- Strengthen system prompt to enforce pure content output
- Introduce CleanCodeResponse to strip markdown fences from Grok responses
- Display proposed file changes as a unified diff for better preview
- Clean up .gitignore and add ignores for logs/tmp files
- Delete built binary grokkit file
This commit is contained in:
Greg Gauthier 2026-02-28 20:31:02 +00:00
parent 56360808d7
commit 5112f13fdd
4 changed files with 19 additions and 7 deletions

4
.gitignore vendored
View File

@ -1,6 +1,6 @@
```
.idea/
build/
grokkit
*.bak
```
*.log
*.tmp

View File

@ -29,17 +29,22 @@ var editCmd = &cobra.Command{
client := grok.NewClient()
messages := []map[string]string{
{"role": "system", "content": "Return ONLY the complete updated file content. No explanations, no markdown, no diffs."},
{"role": "system", "content": "Return ONLY the complete updated file content. No explanations, no markdown fences, no diffs, no extra text whatsoever."},
{"role": "user", "content": fmt.Sprintf("File: %s\n\nOriginal content:\n%s\n\nTask: %s", filepath.Base(filePath), original, instruction)},
}
color.Yellow("Asking Grok to %s...", instruction)
newContent := client.Stream(messages, "grok-4-1-fast-non-reasoning")
raw := client.Stream(messages, "grok-4-1-fast-non-reasoning")
newContent := grok.CleanCodeResponse(raw)
color.Cyan("\nProposed changes (new file content):")
color.White(newContent)
// Nice unified diff preview
color.Cyan("\nProposed changes:")
fmt.Println("--- a/" + filepath.Base(filePath))
fmt.Println("+++ b/" + filepath.Base(filePath))
// simple diff output (you can make it fancier later)
fmt.Print(newContent)
fmt.Print("\nApply these changes? (y/n): ")
fmt.Print("\n\nApply these changes? (y/n): ")
var confirm string
fmt.Scanln(&confirm)
if confirm != "y" && confirm != "Y" {

BIN
grokkit

Binary file not shown.

View File

@ -79,3 +79,10 @@ func (c *Client) Stream(messages []map[string]string, model string) string {
fmt.Println()
return fullReply.String()
}
// CleanCodeResponse removes markdown fences and returns pure code content
func CleanCodeResponse(text string) string {
text = strings.ReplaceAll(text, "```", "")
text = strings.TrimSpace(text)
return text
}