From c5bdd44e555b9ecb44a4f0903cb4420bad8d14cf Mon Sep 17 00:00:00 2001 From: Greg Gauthier Date: Fri, 6 Mar 2026 22:21:58 +0000 Subject: [PATCH] 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. --- internal/recipe/runner.go | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/internal/recipe/runner.go b/internal/recipe/runner.go index 7e5e23d..57b5325 100644 --- a/internal/recipe/runner.go +++ b/internal/recipe/runner.go @@ -1,7 +1,7 @@ package recipe import ( - _ "bufio" + "bufio" "fmt" "os" "path/filepath" @@ -99,7 +99,7 @@ func (r *Runner) discoverFiles() []string { 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) { if len(previousResults) == 0 { 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.") } -// Flexible regex that works whether Grok puts "// filename" or just "filename" -var blockRe = regexp.MustCompile(`(?s)^(?://\s*)?(.+?\.go)\n` + - "```go\n" + - `(.*?)\n` + - "```") +// Flexible regex — matches both old and new Grok formats +var blockRe = regexp.MustCompile(`(?s)```go\n(?://\s*)?(.+?\.go)\n(.*?)\n````) func extractCodeBlocks(text string) map[string]string { blocks := make(map[string]string) @@ -155,4 +152,4 @@ func createUnifiedPatch(blocks map[string]string, patchPath string) error { } } return nil -} +} \ No newline at end of file