on main help sign in
fixup suggestions from copilot
f6d6ffdTai Groot
internal/llm/prompt/prompt.go+15−14
@@ -85,13 +85,20 @@ func processContextPaths(workDir string, paths []string) string {
85 // Expand ~ and environment variables before processing
85 // Expand ~ and environment variables before processing
86 p = expandPath(p)
86 p = expandPath(p)
87
87
88− if strings.HasSuffix(p, "/") {
89− // Use absolute path if provided, otherwise join with workDir
88+ // Use absolute path if provided, otherwise join with workDir
90− dirPath := p
89+ fullPath := p
91− if !filepath.IsAbs(p) {
90+ if !filepath.IsAbs(p) {
92− dirPath = filepath.Join(workDir, p)
91+ fullPath = filepath.Join(workDir, p)
92+ }
93+
94+ // Check if the path is a directory using os.Stat
95+ info, err := os.Stat(fullPath)
96+ if err != nil {
97+ return // Skip if path doesn't exist or can't be accessed
93− }
98+ }
99+
100+ if info.IsDir() {
94− filepath.WalkDir(dirPath, func(path string, d os.DirEntry, err error) error {
101+ filepath.WalkDir(fullPath, func(path string, d os.DirEntry, err error) error {
95 if err != nil {
102 if err != nil {
96 return err
103 return err
97 }
104 }
@@ -115,13 +122,7 @@ func processContextPaths(workDir string, paths []string) string {
115 return nil
122 return nil
116 })
123 })
117 } else {
124 } else {
118− // Expand ~ and environment variables before processing
125+ // It's a file, process it directly
119− // Use absolute path if provided, otherwise join with workDir
120− fullPath := p
121− if !filepath.IsAbs(p) {
122− fullPath = filepath.Join(workDir, p)
123− }
124−
125 // Check if we've already processed this file (case-insensitive)
126 // Check if we've already processed this file (case-insensitive)
126 lowerPath := strings.ToLower(fullPath)
127 lowerPath := strings.ToLower(fullPath)
127
128
internal/llm/prompt/prompt_test.go+7−1
@@ -80,7 +80,7 @@ func TestProcessContextPaths(t *testing.T) {
80 t.Fatalf("Failed to create test file: %v", err)
80 t.Fatalf("Failed to create test file: %v", err)
81 }
81 }
82
82
83− // Test with absolute path
83+ // Test with absolute path to file
84 result := processContextPaths("", []string{testFile})
84 result := processContextPaths("", []string{testFile})
85 expected := "# From:" + testFile + "\n" + testContent
85 expected := "# From:" + testFile + "\n" + testContent
86
86
@@ -88,6 +88,12 @@ func TestProcessContextPaths(t *testing.T) {
88 t.Errorf("processContextPaths with absolute path failed.\nGot: %q\nWant: %q", result, expected)
88 t.Errorf("processContextPaths with absolute path failed.\nGot: %q\nWant: %q", result, expected)
89 }
89 }
90
90
91+ // Test with directory path (should process all files in directory)
92+ result = processContextPaths("", []string{tmpDir})
93+ if !strings.Contains(result, testContent) {
94+ t.Errorf("processContextPaths with directory path failed to include file content")
95+ }
96+
91 // Test with tilde expansion (if we can create a file in home directory)
97 // Test with tilde expansion (if we can create a file in home directory)
92 tmpDir := t.TempDir()
98 tmpDir := t.TempDir()
93 t.Setenv("HOME", tmpDir)
99 t.Setenv("HOME", tmpDir)