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.
This commit is contained in:
Greg Gauthier 2026-03-07 00:22:19 +00:00
parent 8c14977ec6
commit ae8a199ece

View File

@ -81,7 +81,7 @@ Execute this step now. Respond ONLY with the expected output format — no expla
return nil return nil
} }
// discoverFiles — respects package_path param, with smart defaults // discoverFiles — fully generic using recipe metadata + smart defaults
func (r *Runner) discoverFiles() []string { func (r *Runner) discoverFiles() []string {
var files []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 == "." { if root == "." {
// Check for src/ directory (common in some layouts)
if _, err := os.Stat("src"); err == nil { if _, err := os.Stat("src"); err == nil {
root = "src" 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) allowedExt := make(map[string]bool)
for _, lang := range r.Recipe.ProjectLanguages { for _, lang := range r.Recipe.ProjectLanguages {
if exts, ok := r.Recipe.Extensions[lang]; ok { if exts, ok := r.Recipe.Extensions[lang]; ok {
@ -117,8 +115,9 @@ func (r *Runner) discoverFiles() []string {
return nil return nil
} }
if allowedExt[filepath.Ext(path)] { 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) 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) files = append(files, path)
} }
} }