MCPcopy Create free account
hub / github.com/Chat2AnyLLM/code-agent-manager / RefreshAll

Method RefreshAll

internal/metadata/refresh.go:131–199  ·  view source on GitHub ↗

RefreshAll downloads every enabled repository for each kind (skill, agent, instruction, plugin), discovers the individual resources inside each repo, and indexes them into SQLite as cached metadata. Each resource — not each repo — becomes one searchable/installable item, so the counts reflect real r

(ctx context.Context)

Source from the content-addressed store, hash-verified

129// goroutine, which keeps the single DB connection safe and the summary
130// deterministic.
131func (svc *Service) RefreshAll(ctx context.Context) (RefreshSummary, error) {
132 if err := svc.store.Init(ctx); err != nil {
133 return RefreshSummary{}, err
134 }
135 summary := RefreshSummary{}
136
137 kinds := []struct {
138 kind string
139 entityKind entities.Kind
140 }{
141 {"skill", entities.KindSkill},
142 {"agent", entities.KindAgent},
143 {"instruction", entities.KindInstruction},
144 {"plugin", entities.KindPlugin},
145 }
146
147 cacheDir := filepath.Join(pathutil.CacheDir(), "metadata-repos")
148 startedAt := timeNow()
149
150 for _, k := range kinds {
151 repos, err := repoconfig.LoadEnabled(k.entityKind)
152 if err != nil {
153 summary.FailedSources = append(summary.FailedSources, fmt.Sprintf("%s: %v", k.kind, err))
154 continue
155 }
156
157 // Build the work list for this kind.
158 var jobs []repoJob
159 for _, entry := range repos {
160 owner := entry.EffectiveOwner()
161 repo := entry.EffectiveName()
162 if owner == "" || repo == "" {
163 continue
164 }
165 jobs = append(jobs, repoJob{
166 owner: owner,
167 repo: repo,
168 branch: entry.EffectiveBranch(),
169 subPath: entry.SubPath(k.entityKind),
170 catalogFile: entry.CatalogFile,
171 })
172 }
173 summary.SourcesScanned += len(jobs)
174
175 // Fan out downloads+discovery; fan in results for serialized DB writes.
176 results := svc.fetchAndDiscover(ctx, k.kind, k.entityKind, cacheDir, jobs)
177 var batch []Item
178 for r := range results {
179 if r.err != "" {
180 summary.FailedSources = append(summary.FailedSources, r.err)
181 continue
182 }
183 batch = append(batch, r.items...)
184 }
185 written, err := svc.store.UpsertItems(ctx, batch)
186 if err != nil {
187 summary.FailedSources = append(summary.FailedSources, fmt.Sprintf("%s: index: %v", k.kind, err))
188 }

Calls 11

fetchAndDiscoverMethod · 0.95
CacheDirFunction · 0.92
LoadEnabledFunction · 0.92
timeNowFunction · 0.85
EffectiveOwnerMethod · 0.80
EffectiveNameMethod · 0.80
EffectiveBranchMethod · 0.80
SubPathMethod · 0.80
UpsertItemsMethod · 0.80
DeleteStaleMethod · 0.80
InitMethod · 0.45