grokkit/internal/prompts/analyze.go
Greg Gauthier b24b86723b feat(analyze): implement educational project analysis with language prompts
- Add Go-specific analysis prompt in .grokkit/prompts/go.md
- Expand cmd/analyze.go to discover files, detect language, load prompts, build context, generate report via Grok, and handle output with preview/confirmation
- Integrate analyzeCmd into root command
- Introduce internal/linter/language.go for primary language detection
- Add internal/prompts/analyze.go for loading analysis prompts from project or global locations
2026-03-28 12:36:06 +00:00

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
}