fix/markdown_awareness_for_edit #7

Merged
gmgauthier merged 4 commits from fix/markdown_awareness_for_edit into master 2026-03-30 13:05:10 +00:00
Showing only changes of commit ba8d9b1d7e - Show all commits

View File

@ -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{
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)
}