grokkit/internal/recipe/list.go
Greg Gauthier fe25d7fa37
All checks were successful
CI / Test (pull_request) Successful in 1m20s
CI / Lint (pull_request) Successful in 50s
CI / Build (pull_request) Successful in 40s
feat(mcp): implement recipe and prompt listing with handlers
- Add ListRecipes and ListAvailablePrompts functions
- Update MCP server handlers for local/global recipes and prompts
- Add unit tests for analyze, docs, mcp, prompts, recipe, and testgen packages
2026-04-06 15:44:30 +01:00

46 lines
1.1 KiB
Go

package recipe
import (
"os"
"path/filepath"
"strings"
)
// ListRecipes returns a list of recipe names in the given directory.
// It looks for .md files that contain recipe frontmatter.
func ListRecipes(dir string) ([]string, error) {
if dir == "" {
dir = "."
}
var recipes []string
err := filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}
if info.IsDir() {
// Skip hidden directories and common ignore dirs
name := info.Name()
if strings.HasPrefix(name, ".") && name != "." || name == "node_modules" || name == "vendor" {
return filepath.SkipDir
}
return nil
}
if strings.HasSuffix(strings.ToLower(info.Name()), ".md") {
// Simple check for recipe files (contains "Objective:" or "Instructions:")
data, err := os.ReadFile(path)
if err == nil && (strings.Contains(string(data), "**Objective:**") || strings.Contains(string(data), "Objective:")) {
name := strings.TrimSuffix(info.Name(), ".md")
recipes = append(recipes, name)
}
}
return nil
})
return recipes, err
}