fix(recipe): update regex to match Grok's current output style

Adjust the regex in handleApplyStep to flexibly match both old and new Grok formats for code blocks. Also, remove blank import for bufio as it's now used.
This commit is contained in:
Greg Gauthier 2026-03-06 22:21:58 +00:00
parent b2b8c1a482
commit c5bdd44e55

View File

@ -1,7 +1,7 @@
package recipe package recipe
import ( import (
_ "bufio" "bufio"
"fmt" "fmt"
"os" "os"
"path/filepath" "path/filepath"
@ -99,7 +99,7 @@ func (r *Runner) discoverFiles() []string {
return files return files
} }
// handleApplyStep now uses a more flexible regex that matches both formats Grok uses // handleApplyStep with flexible regex that matches Grok's current output style
func (r *Runner) handleApplyStep(previousResults []string) { func (r *Runner) handleApplyStep(previousResults []string) {
if len(previousResults) == 0 { if len(previousResults) == 0 {
fmt.Println(" ⚠️ No previous results to apply — skipping.") fmt.Println(" ⚠️ No previous results to apply — skipping.")
@ -124,11 +124,8 @@ func (r *Runner) handleApplyStep(previousResults []string) {
fmt.Println(" Review it, then run with dry_run=false to apply.") fmt.Println(" Review it, then run with dry_run=false to apply.")
} }
// Flexible regex that works whether Grok puts "// filename" or just "filename" // Flexible regex — matches both old and new Grok formats
var blockRe = regexp.MustCompile(`(?s)^(?://\s*)?(.+?\.go)\n` + var blockRe = regexp.MustCompile(`(?s)```go\n(?://\s*)?(.+?\.go)\n(.*?)\n````)
"```go\n" +
`(.*?)\n` +
"```")
func extractCodeBlocks(text string) map[string]string { func extractCodeBlocks(text string) map[string]string {
blocks := make(map[string]string) blocks := make(map[string]string)
@ -155,4 +152,4 @@ func createUnifiedPatch(blocks map[string]string, patchPath string) error {
} }
} }
return nil return nil
} }