Skip to content

Commit c40e684

Browse files
committed
add context to the prompt
1 parent 8e16048 commit c40e684

File tree

1 file changed

+42
-4
lines changed

1 file changed

+42
-4
lines changed

internal/llm/prompt/prompt.go

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,57 @@
11
package prompt
22

33
import (
4+
"fmt"
5+
"os"
6+
"path/filepath"
7+
48
"github.com/kujtimiihoxha/opencode/internal/config"
59
"github.com/kujtimiihoxha/opencode/internal/llm/models"
610
)
711

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+
821
func GetAgentPrompt(agentName config.AgentName, provider models.ModelProvider) string {
22+
basePrompt := ""
923
switch agentName {
1024
case config.AgentCoder:
11-
return CoderPrompt(provider)
25+
basePrompt = CoderPrompt(provider)
1226
case config.AgentTitle:
13-
return TitlePrompt(provider)
27+
basePrompt = TitlePrompt(provider)
1428
case config.AgentTask:
15-
return TaskPrompt(provider)
29+
basePrompt = TaskPrompt(provider)
1630
default:
17-
return "You are a helpful assistant"
31+
basePrompt = "You are a helpful assistant"
1832
}
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
1957
}

0 commit comments

Comments
 (0)