MCPcopy Create free account
hub / github.com/chainloop-dev/chainloop / DiscoverAll

Function DiscoverAll

internal/aiagentconfig/discover.go:66–102  ·  view source on GitHub ↗

DiscoverAll searches basePath for AI agent configuration files and groups them by agent. Only agents with at least one exclusive file match are included. Shared files are appended to each detected agent's file list. Returns a map of agent name → sorted, deduplicated discovered files.

(basePath string)

Source from the content-addressed store, hash-verified

64// Shared files are appended to each detected agent's file list.
65// Returns a map of agent name → sorted, deduplicated discovered files.
66func DiscoverAll(basePath string) (map[string][]DiscoveredFile, error) {
67 sharedFiles, err := matchPatterns(basePath, sharedPatterns)
68 if err != nil {
69 return nil, err
70 }
71
72 result := make(map[string][]DiscoveredFile)
73
74 for _, agent := range agents {
75 files, err := matchPatterns(basePath, agent.patterns)
76 if err != nil {
77 return nil, err
78 }
79
80 if len(files) == 0 {
81 continue
82 }
83
84 // Merge shared files into this agent's list, deduplicating
85 seen := make(map[string]struct{}, len(files)+len(sharedFiles))
86 merged := make([]DiscoveredFile, 0, len(files)+len(sharedFiles))
87 for _, f := range files {
88 seen[f.Path] = struct{}{}
89 merged = append(merged, f)
90 }
91 for _, f := range sharedFiles {
92 if _, ok := seen[f.Path]; !ok {
93 merged = append(merged, f)
94 }
95 }
96
97 sort.Slice(merged, func(i, j int) bool { return merged[i].Path < merged[j].Path })
98 result[agent.name] = merged
99 }
100
101 return result, nil
102}
103
104// matchPatterns expands glob patterns relative to basePath and returns
105// deduplicated, sorted discovered files.

Callers 3

CollectMethod · 0.92
TestDiscoverAllFunction · 0.85

Calls 1

matchPatternsFunction · 0.85

Tested by 2

TestDiscoverAllFunction · 0.68