diff options
| author | Sam Ottenhoff <[email protected]> | 2025-04-25 11:29:15 -0400 |
|---|---|---|
| committer | Kujtim Hoxha <[email protected]> | 2025-04-27 14:17:06 +0200 |
| commit | f3dccad54bcbe4cc9859a64720de549eb70901fe (patch) | |
| tree | 33032cf8bb6465b4ef76674fd2702dd4e690b9b1 /internal | |
| parent | b3a8dbd0d97998488838386d4042678cf170a2cb (diff) | |
| download | opencode-f3dccad54bcbe4cc9859a64720de549eb70901fe.tar.gz opencode-f3dccad54bcbe4cc9859a64720de549eb70901fe.zip | |
Handle new Cursor rules format
1. Check if a path ends with a slash (/)
2. If it does, treat it as a directory and read all files within it
3. For directories like .cursor/rules/, it will scan all files and include their content in the prompt
4. Each file from a directory will be prefixed with "# From filename" for clarity
Diffstat (limited to 'internal')
| -rw-r--r-- | internal/llm/prompt/prompt.go | 31 |
1 files changed, 26 insertions, 5 deletions
diff --git a/internal/llm/prompt/prompt.go b/internal/llm/prompt/prompt.go index 85bd7ffc1..32971f60e 100644 --- a/internal/llm/prompt/prompt.go +++ b/internal/llm/prompt/prompt.go @@ -4,6 +4,7 @@ import ( "fmt" "os" "path/filepath" + "strings" "github.com/opencode-ai/opencode/internal/config" "github.com/opencode-ai/opencode/internal/llm/models" @@ -13,6 +14,7 @@ import ( var contextFiles = []string{ ".github/copilot-instructions.md", ".cursorrules", + ".cursor/rules/", // Directory containing multiple rule files "CLAUDE.md", "CLAUDE.local.md", "opencode.md", @@ -51,11 +53,30 @@ 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)) + for _, path := range contextFiles { + // Check if path ends with a slash (indicating a directory) + if strings.HasSuffix(path, "/") { + // Handle directory - read all files within it + dirPath := filepath.Join(workDir, path) + files, err := os.ReadDir(dirPath) + if err == nil { + for _, file := range files { + if !file.IsDir() { + filePath := filepath.Join(dirPath, file.Name()) + content, err := os.ReadFile(filePath) + if err == nil { + contextContent += fmt.Sprintf("\n# From %s\n%s\n", file.Name(), string(content)) + } + } + } + } + } else { + // Handle individual file as before + filePath := filepath.Join(workDir, path) + content, err := os.ReadFile(filePath) + if err == nil { + contextContent += fmt.Sprintf("\n%s\n", string(content)) + } } } |
