From 8c14977ec641e6b2a82495746e36cf44d945ade7 Mon Sep 17 00:00:00 2001 From: Greg Gauthier Date: Sat, 7 Mar 2026 00:13:57 +0000 Subject: [PATCH] feat(recipe): add smart defaults for package_path in file discovery Enhance discoverFiles to respect explicit package_path param if provided. If no param is given, intelligently default to 'src' directory if it exists, otherwise fall back to project root (.). --- internal/recipe/runner.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/internal/recipe/runner.go b/internal/recipe/runner.go index 347ddb1..cd3feda 100644 --- a/internal/recipe/runner.go +++ b/internal/recipe/runner.go @@ -81,11 +81,11 @@ Execute this step now. Respond ONLY with the expected output format — no expla return nil } -// discoverFiles — now fully generic using recipe metadata +// discoverFiles — respects package_path param, with smart defaults func (r *Runner) discoverFiles() []string { var files []string - // Get root from --param or default + // 1. Use explicit --param package_path if provided root := "." if v, ok := r.Recipe.ResolvedParams["package_path"]; ok { if s, ok := v.(string); ok && s != "" { @@ -93,6 +93,15 @@ func (r *Runner) discoverFiles() []string { } } + // 2. If no param was given, apply smart defaults + 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 allowedExt := make(map[string]bool) for _, lang := range r.Recipe.ProjectLanguages { @@ -109,7 +118,7 @@ func (r *Runner) discoverFiles() []string { } if allowedExt[filepath.Ext(path)] { b, _ := os.ReadFile(path) - if strings.Contains(string(b), "if err != nil") { + if strings.Contains(string(b), "if err != nil") { // TODO: generalize this too later files = append(files, path) } }