on main help sign in
fix(config): look for more than just crush.md
898f1eeAmolith
internal/config/init.go+17−8
@@ -4,6 +4,7 @@ import (
4 "fmt"
4 "fmt"
5 "os"
5 "os"
6 "path/filepath"
6 "path/filepath"
7+ "slices"
7 "strings"
8 "strings"
8 "sync/atomic"
9 "sync/atomic"
9)
10)
@@ -50,30 +51,38 @@ func ProjectNeedsInitialization() (bool, error) {
50 return false, fmt.Errorf("failed to check init flag file: %w", err)
51 return false, fmt.Errorf("failed to check init flag file: %w", err)
51 }
52 }
52
53
53− crushExists, err := crushMdExists(cfg.WorkingDir())
54+ someContextFileExists, err := contextPathsExist(cfg.WorkingDir())
54 if err != nil {
55 if err != nil {
55− return false, fmt.Errorf("failed to check for CRUSH.md files: %w", err)
56+ return false, fmt.Errorf("failed to check for context files: %w", err)
56 }
57 }
57− if crushExists {
58+ if someContextFileExists {
58 return false, nil
59 return false, nil
59 }
60 }
60
61
61 return true, nil
62 return true, nil
62}
63}
63
64
64−func crushMdExists(dir string) (bool, error) {
65+func contextPathsExist(dir string) (bool, error) {
65 entries, err := os.ReadDir(dir)
66 entries, err := os.ReadDir(dir)
66 if err != nil {
67 if err != nil {
67 return false, err
68 return false, err
68 }
69 }
69
70
71+ // Create a slice of lowercase filenames for lookup with slices.Contains
72+ var files []string
70 for _, entry := range entries {
73 for _, entry := range entries {
71− if entry.IsDir() {
74+ if !entry.IsDir() {
72− continue
75+ files = append(files, strings.ToLower(entry.Name()))
73 }
76 }
77+ }
78+
79+ // Check if any of the default context paths exist in the directory
80+ for _, path := range defaultContextPaths {
81+ // Extract just the filename from the path
82+ _, filename := filepath.Split(path)
83+ filename = strings.ToLower(filename)
74
84
75− name := strings.ToLower(entry.Name())
85+ if slices.Contains(files, filename) {
76− if name == "crush.md" {
77 return true, nil
86 return true, nil
78 }
87 }
79 }
88 }