|
1 | 1 | package prompt
|
2 | 2 |
|
3 | 3 | import (
|
| 4 | + "fmt" |
| 5 | + "os" |
| 6 | + "path/filepath" |
| 7 | + |
4 | 8 | "github.com/kujtimiihoxha/opencode/internal/config"
|
5 | 9 | "github.com/kujtimiihoxha/opencode/internal/llm/models"
|
6 | 10 | )
|
7 | 11 |
|
| 12 | +// contextFiles is a list of potential context files to check for |
| 13 | +var contextFiles = []string{ |
| 14 | + ".github/copilot-instructions.md", |
| 15 | + ".cursorrules", |
| 16 | + "CLAUDE.md", |
| 17 | + "opencode.md", |
| 18 | + "OpenCode.md", |
| 19 | +} |
| 20 | + |
8 | 21 | func GetAgentPrompt(agentName config.AgentName, provider models.ModelProvider) string {
|
| 22 | + basePrompt := "" |
9 | 23 | switch agentName {
|
10 | 24 | case config.AgentCoder:
|
11 |
| - return CoderPrompt(provider) |
| 25 | + basePrompt = CoderPrompt(provider) |
12 | 26 | case config.AgentTitle:
|
13 |
| - return TitlePrompt(provider) |
| 27 | + basePrompt = TitlePrompt(provider) |
14 | 28 | case config.AgentTask:
|
15 |
| - return TaskPrompt(provider) |
| 29 | + basePrompt = TaskPrompt(provider) |
16 | 30 | default:
|
17 |
| - return "You are a helpful assistant" |
| 31 | + basePrompt = "You are a helpful assistant" |
18 | 32 | }
|
| 33 | + |
| 34 | + // Add context from project-specific instruction files if they exist |
| 35 | + contextContent := getContextFromFiles() |
| 36 | + if contextContent != "" { |
| 37 | + return fmt.Sprintf("%s\n\n# Project-Specific Context\n%s", basePrompt, contextContent) |
| 38 | + } |
| 39 | + |
| 40 | + return basePrompt |
| 41 | +} |
| 42 | + |
| 43 | +// getContextFromFiles checks for the existence of context files and returns their content |
| 44 | +func getContextFromFiles() string { |
| 45 | + workDir := config.WorkingDirectory() |
| 46 | + var contextContent string |
| 47 | + |
| 48 | + for _, file := range contextFiles { |
| 49 | + filePath := filepath.Join(workDir, file) |
| 50 | + content, err := os.ReadFile(filePath) |
| 51 | + if err == nil { |
| 52 | + contextContent += fmt.Sprintf("\n%s\n", string(content)) |
| 53 | + } |
| 54 | + } |
| 55 | + |
| 56 | + return contextContent |
19 | 57 | }
|
0 commit comments