refactor(recipe): make search pattern configurable in file discovery
- Add SearchPattern field to Recipe struct - Update discoverFiles to use configurable search pattern, defaulting to "if err != nil" - Set default search_pattern in result-refactor.md recipe
This commit is contained in:
parent
ae8a199ece
commit
757f422765
@ -20,6 +20,8 @@ extensions:
|
||||
go:
|
||||
- .go
|
||||
|
||||
search_pattern: "if err != nil"
|
||||
|
||||
allowed_shell_commands:
|
||||
- go test ./...
|
||||
- go fmt ./...
|
||||
|
||||
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
@ -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:"-"`
|
||||
|
||||
Loading…
Reference in New Issue
Block a user