From ba8d9b1d7ef4c5b7c59c7e6977b36a8c43fc2577 Mon Sep 17 00:00:00 2001 From: Gregory Gauthier Date: Mon, 30 Mar 2026 12:22:50 +0100 Subject: [PATCH] feat(edit): add markdown file support with tailored prompt - Introduce check for .md extension and use technical writer system prompt. - Adjust response cleaning: trim for markdown, use CleanCodeResponse for code. - Remove nolint comment and unnecessary line skipping in removeLastModifiedComments. --- cmd/edit.go | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) 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) }