diff --git a/cmd/edit.go b/cmd/edit.go index 53a957d..49b9029 100644 --- a/cmd/edit.go +++ b/cmd/edit.go @@ -35,7 +35,6 @@ var editCmd = &cobra.Command{ os.Exit(1) } - // nolint:gosec // intentional file read from user input original, err := os.ReadFile(filePath) if err != nil { logger.Error("failed to read file", "file", filePath, "error", err) @@ -46,14 +45,28 @@ var editCmd = &cobra.Command{ cleanedOriginal := removeLastModifiedComments(string(original)) client := grok.NewClient() - messages := []map[string]string{ - {"role": "system", "content": "You are an expert programmer. Remove all unnecessary comments including last modified timestamps and ownership comments. Return only the cleaned code with no explanations, no markdown, no extra text."}, - {"role": "user", "content": fmt.Sprintf("File: %s\n\nOriginal content:\n%s\n\nTask: %s", filepath.Base(filePath), cleanedOriginal, instruction)}, + isMarkdown := filepath.Ext(filePath) == ".md" + var messages []map[string]string + if isMarkdown { + messages = []map[string]string{ + {"role": "system", "content": "You are an expert technical writer. Edit markdown content clearly and concisely. Return only the edited markdown with no explanations, no markdown formatting, no extra text."}, + {"role": "user", "content": fmt.Sprintf("File: %s\n\nOriginal content:\n%s\n\nTask: %s", filepath.Base(filePath), cleanedOriginal, instruction)}, + } + } else { + messages = []map[string]string{ + {"role": "system", "content": "You are an expert programmer. Remove all unnecessary comments including last modified timestamps and ownership comments. Return only the cleaned code with no explanations, no markdown, no extra text."}, + {"role": "user", "content": fmt.Sprintf("File: %s\n\nOriginal content:\n%s\n\nTask: %s", filepath.Base(filePath), cleanedOriginal, instruction)}, + } } color.Yellow("Asking Grok to %s...\n", instruction) raw := client.StreamSilent(messages, model) - newContent := grok.CleanCodeResponse(raw) + var newContent string + if isMarkdown { + newContent = strings.TrimSpace(raw) + } else { + newContent = grok.CleanCodeResponse(raw) + } color.Green("✓ Response received") color.Cyan("\nProposed changes:") @@ -92,9 +105,6 @@ func removeLastModifiedComments(content string) string { cleanedLines := make([]string, 0, len(lines)) for _, line := range lines { - if strings.Contains(line, "Last modified") { - continue - } cleanedLines = append(cleanedLines, line) }