From 757f422765c7d54c25b348bd03a380b992dce356 Mon Sep 17 00:00:00 2001 From: Greg Gauthier Date: Sat, 7 Mar 2026 00:34:25 +0000 Subject: [PATCH] refactor(recipe): make search pattern configurable in file discovery - Add SearchPattern field to Recipe struct - Update discoverFiles to use configurable search pattern, defaulting to "if err != nil" - Set default search_pattern in result-refactor.md recipe --- .grokkit/recipes/result-refactor.md | 2 ++ internal/recipe/runner.go | 11 ++++++++--- internal/recipe/types.go | 1 + 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/.grokkit/recipes/result-refactor.md b/.grokkit/recipes/result-refactor.md index bd0890f..90a8fdb 100644 --- a/.grokkit/recipes/result-refactor.md +++ b/.grokkit/recipes/result-refactor.md @@ -20,6 +20,8 @@ extensions: go: - .go +search_pattern: "if err != nil" + allowed_shell_commands: - go test ./... - go fmt ./... diff --git a/internal/recipe/runner.go b/internal/recipe/runner.go index 1cc98b6..f8f8373 100644 --- a/internal/recipe/runner.go +++ b/internal/recipe/runner.go @@ -81,7 +81,7 @@ Execute this step now. Respond ONLY with the expected output format — no expla return nil } -// discoverFiles — fully generic using recipe metadata + smart defaults +// discoverFiles — fully generic using recipe metadata func (r *Runner) discoverFiles() []string { var files []string @@ -110,14 +110,19 @@ func (r *Runner) discoverFiles() []string { } } + // 4. Use the configurable search pattern (defaults to "if err != nil") + searchFor := r.Recipe.SearchPattern + if searchFor == "" { + searchFor = "if err != nil" + } + _ = filepath.WalkDir(root, func(path string, d os.DirEntry, err error) error { if err != nil || d.IsDir() { return nil } if allowedExt[filepath.Ext(path)] { - // For now we still look for "if err != nil" — we can generalize this later with a recipe hint if needed b, _ := os.ReadFile(path) - if strings.Contains(string(b), "if err != nil") { + if strings.Contains(string(b), searchFor) { files = append(files, path) } } diff --git a/internal/recipe/types.go b/internal/recipe/types.go index d59a950..985f607 100644 --- a/internal/recipe/types.go +++ b/internal/recipe/types.go @@ -10,6 +10,7 @@ type Recipe struct { // Generic discovery support (option 2) ProjectLanguages []string `yaml:"project_languages"` Extensions map[string][]string `yaml:"extensions"` + SearchPattern string `yaml:"search_pattern"` // new // Resolved runtime values from --param flags ResolvedParams map[string]any `yaml:"-"`