grokkit/internal/prompts/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

54 lines
1.2 KiB
Go

package prompts
import (
"os"
"path/filepath"
"strings"
)
// ListAvailablePrompts returns a list of available language prompts.
// It scans both project-local and global prompt directories.
func ListAvailablePrompts() []string {
var prompts []string
// Check project-local prompts
localDir := ".grokkit/prompts"
if entries, err := os.ReadDir(localDir); err == nil {
for _, entry := range entries {
if !entry.IsDir() && strings.HasSuffix(entry.Name(), ".md") {
name := strings.TrimSuffix(entry.Name(), ".md")
prompts = append(prompts, name)
}
}
}
// Check global prompts
home := os.Getenv("HOME")
if home == "" {
home = os.Getenv("USERPROFILE")
}
if home != "" {
globalDir := filepath.Join(home, ".config", "grokkit", "prompts")
if entries, err := os.ReadDir(globalDir); err == nil {
for _, entry := range entries {
if !entry.IsDir() && strings.HasSuffix(entry.Name(), ".md") {
name := strings.TrimSuffix(entry.Name(), ".md")
// Avoid duplicates
found := false
for _, p := range prompts {
if p == name {
found = true
break
}
}
if !found {
prompts = append(prompts, name)
}
}
}
}
}
return prompts
}