diff --git a/.gitignore b/.gitignore index fdf9074..becf222 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ -``` .idea/ build/ grokkit *.bak -``` \ No newline at end of file +*.log +*.tmp \ No newline at end of file diff --git a/cmd/edit.go b/cmd/edit.go index d9b4a57..25ab4f4 100644 --- a/cmd/edit.go +++ b/cmd/edit.go @@ -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" { diff --git a/grokkit b/grokkit deleted file mode 100755 index 6fa5e57..0000000 Binary files a/grokkit and /dev/null differ diff --git a/internal/grok/client.go b/internal/grok/client.go index 89024f2..5d16cb3 100644 --- a/internal/grok/client.go +++ b/internal/grok/client.go @@ -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 +}