33 lines
928 B
Go
33 lines
928 B
Go
|
|
package prompts
|
||
|
|
|
||
|
|
import (
|
||
|
|
"os"
|
||
|
|
"path/filepath"
|
||
|
|
)
|
||
|
|
|
||
|
|
// LoadAnalysisPrompt returns the path and content of the best matching prompt.
|
||
|
|
// Search order: {projectRoot}/.grokkit/prompts/{language}.md → ~/.config/grokkit/prompts/{language}.md
|
||
|
|
func LoadAnalysisPrompt(projectRoot, language string) (path, content string, err error) {
|
||
|
|
if language == "" {
|
||
|
|
language = "unknown"
|
||
|
|
}
|
||
|
|
|
||
|
|
// 1. Project-local (preferred)
|
||
|
|
localPath := filepath.Join(projectRoot, ".grokkit", "prompts", language+".md")
|
||
|
|
if data, readErr := os.ReadFile(localPath); readErr == nil {
|
||
|
|
return localPath, string(data), nil
|
||
|
|
}
|
||
|
|
|
||
|
|
// 2. Global config
|
||
|
|
home := os.Getenv("HOME")
|
||
|
|
if home == "" {
|
||
|
|
home = "/root" // fallback for containers
|
||
|
|
}
|
||
|
|
globalPath := filepath.Join(home, ".config", "grokkit", "prompts", language+".md")
|
||
|
|
if data, readErr := os.ReadFile(globalPath); readErr == nil {
|
||
|
|
return globalPath, string(data), nil
|
||
|
|
}
|
||
|
|
|
||
|
|
return "", "", os.ErrNotExist
|
||
|
|
}
|