Handle new Cursor rules format

Sam Ottenhoff created

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

Change summary

internal/llm/prompt/prompt.go | 31 ++++++++++++++++++++++++++-----
1 file changed, 26 insertions(+), 5 deletions(-)

Detailed changes

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))
+			}
 		}
 	}