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 (.).
This commit is contained in:
Greg Gauthier 2026-03-07 00:13:57 +00:00
parent f5c73ab291
commit 8c14977ec6

View File

@ -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)
}
}