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)
| 129 | // goroutine, which keeps the single DB connection safe and the summary |
| 130 | // deterministic. |
| 131 | func (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 | } |