Skip to content
This repository was archived by the owner on Sep 18, 2025. It is now read-only.

Commit f3dccad

Browse files
ottenhoffkujtimiihoxha
authored andcommitted
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
1 parent b3a8dbd commit f3dccad

File tree

1 file changed

+26
-5
lines changed

1 file changed

+26
-5
lines changed

internal/llm/prompt/prompt.go

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"fmt"
55
"os"
66
"path/filepath"
7+
"strings"
78

89
"github.com/opencode-ai/opencode/internal/config"
910
"github.com/opencode-ai/opencode/internal/llm/models"
@@ -13,6 +14,7 @@ import (
1314
var contextFiles = []string{
1415
".github/copilot-instructions.md",
1516
".cursorrules",
17+
".cursor/rules/", // Directory containing multiple rule files
1618
"CLAUDE.md",
1719
"CLAUDE.local.md",
1820
"opencode.md",
@@ -51,11 +53,30 @@ func getContextFromFiles() string {
5153
workDir := config.WorkingDirectory()
5254
var contextContent string
5355

54-
for _, file := range contextFiles {
55-
filePath := filepath.Join(workDir, file)
56-
content, err := os.ReadFile(filePath)
57-
if err == nil {
58-
contextContent += fmt.Sprintf("\n%s\n", string(content))
56+
for _, path := range contextFiles {
57+
// Check if path ends with a slash (indicating a directory)
58+
if strings.HasSuffix(path, "/") {
59+
// Handle directory - read all files within it
60+
dirPath := filepath.Join(workDir, path)
61+
files, err := os.ReadDir(dirPath)
62+
if err == nil {
63+
for _, file := range files {
64+
if !file.IsDir() {
65+
filePath := filepath.Join(dirPath, file.Name())
66+
content, err := os.ReadFile(filePath)
67+
if err == nil {
68+
contextContent += fmt.Sprintf("\n# From %s\n%s\n", file.Name(), string(content))
69+
}
70+
}
71+
}
72+
}
73+
} else {
74+
// Handle individual file as before
75+
filePath := filepath.Join(workDir, path)
76+
content, err := os.ReadFile(filePath)
77+
if err == nil {
78+
contextContent += fmt.Sprintf("\n%s\n", string(content))
79+
}
5980
}
6081
}
6182

0 commit comments

Comments
 (0)