feature/recipe_implementation #5

Merged
gmgauthier merged 54 commits from feature/recipe_implementation into master 2026-03-07 23:17:54 +00:00
Showing only changes of commit 40d40f7669 - Show all commits

View File

@ -1,7 +1,7 @@
package recipe
import (
"bufio"
_ "bufio"
"fmt"
"os"
"path/filepath"
@ -31,7 +31,6 @@ func (r *Runner) Run() error {
titleLower := strings.ToLower(step.Title)
// Only two special cases the CLI ever needs to handle
switch {
case strings.Contains(titleLower, "discover") || strings.Contains(titleLower, "find"):
files := r.discoverFiles()
@ -44,7 +43,6 @@ func (r *Runner) Run() error {
continue
default:
// Everything else = pure LLM (works for any language)
prompt := fmt.Sprintf(`Recipe Overview:
%s
@ -79,10 +77,10 @@ Execute this step now. Respond ONLY with the expected output format — no expla
return nil
}
// discoverFiles does a real filesystem scan — generic enough for any Go project
// discoverFiles does a real filesystem scan (used by "Discover files" steps)
func (r *Runner) discoverFiles() []string {
var files []string
root := "internal" // matches the recipe default; we can make it parametric later
root := "internal"
_ = filepath.WalkDir(root, func(path string, d os.DirEntry, err error) error {
if err != nil || d.IsDir() || !strings.HasSuffix(path, ".go") {
@ -101,7 +99,7 @@ func (r *Runner) discoverFiles() []string {
return files
}
// handleApplyStep stays exactly as you had it (dry-run patch + confirmation)
// handleApplyStep (dry-run patch + confirmation)
func (r *Runner) handleApplyStep(previousResults []string) {
if len(previousResults) == 0 {
fmt.Println(" ⚠️ No previous results to apply — skipping.")
@ -126,7 +124,11 @@ func (r *Runner) handleApplyStep(previousResults []string) {
fmt.Println(" Review it, then run with dry_run=false to apply.")
}
var blockRe = regexp.MustCompile(`(?s)^//\s*(.+?\.go)\n```go\n(.*?)\n````)
// regex split across lines to avoid backtick collision
var blockRe = regexp.MustCompile(`(?s)^//\s*(.+?\.go)\n` +
"```go\n" +
`(.*?)\n` +
"```")
func extractCodeBlocks(text string) map[string]string {
blocks := make(map[string]string)
@ -144,13 +146,24 @@ func createUnifiedPatch(blocks map[string]string, patchPath string) error {
if err != nil {
return err
}
defer f.Close()
defer func(f *os.File) {
err := f.Close()
if err != nil {
return
}
}(f)
for path, content := range blocks {
fmt.Fprintf(f, "--- %s\n+++ %s\n@@ -0,0 +1,%d @@\n", path, path, strings.Count(content, "\n")+1)
_, err := fmt.Fprintf(f, "--- %s\n+++ %s\n@@ -0,0 +1,%d @@\n", path, path, strings.Count(content, "\n")+1)
if err != nil {
return err
}
for _, line := range strings.Split(content, "\n") {
fmt.Fprintf(f, "+%s\n", line)
_, err := fmt.Fprintf(f, "+%s\n", line)
if err != nil {
return err
}
}
}
return nil
}
}