From ae8a199ecee04561f210a82f1ae9d5b7fc739c78 Mon Sep 17 00:00:00 2001 From: Greg Gauthier Date: Sat, 7 Mar 2026 00:22:19 +0000 Subject: [PATCH] refactor(recipe): make file discovery fully generic using recipe metadata Update discoverFiles to leverage recipe metadata for extensions and apply smart defaults more cleanly. Generalize logic with comments for future improvements, while retaining err != nil check for now. --- internal/recipe/runner.go | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/internal/recipe/runner.go b/internal/recipe/runner.go index cd3feda..1cc98b6 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 — respects package_path param, with smart defaults +// discoverFiles — fully generic using recipe metadata + smart defaults func (r *Runner) discoverFiles() []string { var files []string @@ -93,16 +93,14 @@ func (r *Runner) discoverFiles() []string { } } - // 2. If no param was given, apply smart defaults + // 2. Smart defaults if no param was given if root == "." { - // Check for src/ directory (common in some layouts) if _, err := os.Stat("src"); err == nil { root = "src" } - // otherwise stay at project root (.) } - // Build allowed extensions from recipe frontmatter + // 3. Build allowed extensions from recipe frontmatter allowedExt := make(map[string]bool) for _, lang := range r.Recipe.ProjectLanguages { if exts, ok := r.Recipe.Extensions[lang]; ok { @@ -117,8 +115,9 @@ func (r *Runner) discoverFiles() []string { 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") { // TODO: generalize this too later + if strings.Contains(string(b), "if err != nil") { files = append(files, path) } }