SuperCoder/internal/llm/prompt/prompt.go

64 lines
1.5 KiB
Go
Raw Normal View History

package prompt
import (
2025-04-20 16:52:36 +02:00
"fmt"
"os"
"path/filepath"
2025-04-24 18:25:52 +02:00
"github.com/opencode-ai/opencode/internal/config"
"github.com/opencode-ai/opencode/internal/llm/models"
)
2025-04-20 16:52:36 +02:00
// contextFiles is a list of potential context files to check for
var contextFiles = []string{
".github/copilot-instructions.md",
".cursorrules",
"CLAUDE.md",
2025-04-21 19:48:36 +02:00
"CLAUDE.local.md",
2025-04-20 16:52:36 +02:00
"opencode.md",
2025-04-21 19:48:36 +02:00
"opencode.local.md",
2025-04-20 16:52:36 +02:00
"OpenCode.md",
2025-04-21 19:48:36 +02:00
"OpenCode.local.md",
"OPENCODE.md",
"OPENCODE.local.md",
2025-04-20 16:52:36 +02:00
}
func GetAgentPrompt(agentName config.AgentName, provider models.ModelProvider) string {
2025-04-20 16:52:36 +02:00
basePrompt := ""
switch agentName {
case config.AgentCoder:
2025-04-20 16:52:36 +02:00
basePrompt = CoderPrompt(provider)
case config.AgentTitle:
2025-04-20 16:52:36 +02:00
basePrompt = TitlePrompt(provider)
case config.AgentTask:
2025-04-20 16:52:36 +02:00
basePrompt = TaskPrompt(provider)
default:
2025-04-20 16:52:36 +02:00
basePrompt = "You are a helpful assistant"
}
2025-04-20 16:52:36 +02:00
2025-04-21 19:48:36 +02:00
if agentName == config.AgentCoder || agentName == config.AgentTask {
// Add context from project-specific instruction files if they exist
contextContent := getContextFromFiles()
if contextContent != "" {
return fmt.Sprintf("%s\n\n# Project-Specific Context\n%s", basePrompt, contextContent)
}
2025-04-20 16:52:36 +02:00
}
return basePrompt
}
// getContextFromFiles checks for the existence of context files and returns their content
func getContextFromFiles() string {
workDir := config.WorkingDirectory()
var contextContent string
for _, file := range contextFiles {
filePath := filepath.Join(workDir, file)
content, err := os.ReadFile(filePath)
if err == nil {
contextContent += fmt.Sprintf("\n%s\n", string(content))
}
}
return contextContent
}