package wing import ( "fmt" "os" "path/filepath" "sort" "github.com/mathiasbq/hyperguild/ingestion/internal/brain" ) // legacyDirs are the retired wiki/{concepts,entities,sources}/ layout, not wings. var legacyDirs = map[string]bool{"concepts": true, "entities": true, "sources": true} // KnownWings lists wiki// directories that contain at least one hall // subdirectory, sorted. The retired layout is not a wing. A missing wiki/ is // an error: an unreadable brain must not look like "no wings". func KnownWings(brainDir string) ([]string, error) { entries, err := os.ReadDir(filepath.Join(brainDir, "wiki")) if err != nil { return nil, fmt.Errorf("list wings: %w", err) } var out []string for _, e := range entries { if !e.IsDir() || legacyDirs[e.Name()] || !plainWingName(e.Name()) { continue } subs, err := os.ReadDir(filepath.Join(brainDir, "wiki", e.Name())) if err != nil { continue } for _, s := range subs { if s.IsDir() { out = append(out, e.Name()) break } } } sort.Strings(out) return out, nil } // plainWingName reports whether name is already in the canonical lower-case form // the pipeline writes. Anything else would make the pipeline create a different // wing than the one matched. func plainWingName(name string) bool { return brain.Sanitise(name) == name }