on main help sign in
fixup suggestions from copilot
commitf6d6ffdc01bd72c1682a5f79cafbd17be89f040e authorTai Groot <tai@taigrr.com> dateThu 10 Jul 2025, 18:24 (1 year ago) parentb7935b4
2 files changed+22−15
internal/llm/prompt/prompt.go+15−14 internal/llm/prompt/prompt_test.go+7−1
internal/llm/prompt/prompt.go+15−14
@@ -85,13 +85,20 @@ func processContextPaths(workDir string, paths []string) string {
8585 // Expand ~ and environment variables before processing
8686 p = expandPath(p)
8787
88− if strings.HasSuffix(p, "/") {
89− // Use absolute path if provided, otherwise join with workDir
90− dirPath := p
91− if !filepath.IsAbs(p) {
92− dirPath = filepath.Join(workDir, p)
93− }
94− filepath.WalkDir(dirPath, func(path string, d os.DirEntry, err error) error {
88+ // Use absolute path if provided, otherwise join with workDir
89+ fullPath := p
90+ if !filepath.IsAbs(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
98+ }
99+
100+ if info.IsDir() {
101+ filepath.WalkDir(fullPath, func(path string, d os.DirEntry, err error) error {
95102 if err != nil {
96103 return err
97104 }
@@ -115,13 +122,7 @@ func processContextPaths(workDir string, paths []string) string {
115122 return nil
116123 })
117124 } else {
118− // Expand ~ and environment variables before processing
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+ // It's a file, process it directly
125126 // Check if we've already processed this file (case-insensitive)
126127 lowerPath := strings.ToLower(fullPath)
127128
internal/llm/prompt/prompt_test.go+7−1
@@ -80,7 +80,7 @@ func TestProcessContextPaths(t *testing.T) {
8080 t.Fatalf("Failed to create test file: %v", err)
8181 }
8282
83− // Test with absolute path
83+ // Test with absolute path to file
8484 result := processContextPaths("", []string{testFile})
8585 expected := "# From:" + testFile + "\n" + testContent
8686
@@ -88,6 +88,12 @@ func TestProcessContextPaths(t *testing.T) {
8888 t.Errorf("processContextPaths with absolute path failed.\nGot: %q\nWant: %q", result, expected)
8989 }
9090
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+
9197 // Test with tilde expansion (if we can create a file in home directory)
9298 tmpDir := t.TempDir()
9399 t.Setenv("HOME", tmpDir)