54 lines
1.2 KiB
Go
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
|
||
|
|
}
|