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:"-"`