- Updated Go analysis prompt for clarity, structure, and educational focus. - Improved buildProjectContext to include shallow key files and cleaner Git remote handling. - Implemented DetectPrimaryLanguage with counting logic and Go bias; added SupportedLanguages. - Enhanced LoadAnalysisPrompt with better language handling, fallbacks, and error clarity.
41 lines
1.1 KiB
Go
41 lines
1.1 KiB
Go
package prompts
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
)
|
|
|
|
// LoadAnalysisPrompt locates and reads a language-specific analysis prompt.
|
|
// Search order (developer-first, project-local preferred):
|
|
// 1. {projectRoot}/.grokkit/prompts/{language}.md
|
|
// 2. ~/.config/grokkit/prompts/{language}.md
|
|
//
|
|
// Returns os.ErrNotExist if none found so the command can give a clear, actionable error.
|
|
func LoadAnalysisPrompt(projectRoot, language string) (path, content string, err error) {
|
|
if language == "" || language == "unknown" {
|
|
language = "go"
|
|
}
|
|
language = strings.ToLower(language)
|
|
|
|
// 1. Project-local (preferred for per-project customization)
|
|
local := filepath.Join(projectRoot, ".grokkit", "prompts", language+".md")
|
|
if data, readErr := os.ReadFile(local); readErr == nil {
|
|
return local, string(data), nil
|
|
}
|
|
|
|
// 2. Global fallback
|
|
home := os.Getenv("HOME")
|
|
if home == "" {
|
|
home = os.Getenv("USERPROFILE") // Windows
|
|
}
|
|
if home != "" {
|
|
global := filepath.Join(home, ".config", "grokkit", "prompts", language+".md")
|
|
if data, readErr := os.ReadFile(global); readErr == nil {
|
|
return global, string(data), nil
|
|
}
|
|
}
|
|
|
|
return "", "", os.ErrNotExist
|
|
}
|