RefreshFromFiles reads *_repos.json files from cfgDir and indexes entries into SQLite.
(ctx context.Context, cfgDir string)
| 52 | |
| 53 | // RefreshFromFiles reads *_repos.json files from cfgDir and indexes entries into SQLite. |
| 54 | func (svc *Service) RefreshFromFiles(ctx context.Context, cfgDir string) (RefreshSummary, error) { |
| 55 | if err := svc.store.Init(ctx); err != nil { |
| 56 | return RefreshSummary{}, err |
| 57 | } |
| 58 | |
| 59 | summary := RefreshSummary{} |
| 60 | files := []struct { |
| 61 | filename string |
| 62 | kind string |
| 63 | }{ |
| 64 | {"skill_repos.json", "skill"}, |
| 65 | {"agent_repos.json", "agent"}, |
| 66 | {"instruction_repos.json", "instruction"}, |
| 67 | {"plugin_repos.json", "plugin"}, |
| 68 | } |
| 69 | |
| 70 | for _, f := range files { |
| 71 | path := filepath.Join(cfgDir, f.filename) |
| 72 | data, err := os.ReadFile(path) |
| 73 | if err != nil { |
| 74 | if os.IsNotExist(err) { |
| 75 | continue |
| 76 | } |
| 77 | summary.FailedSources = append(summary.FailedSources, f.filename) |
| 78 | continue |
| 79 | } |
| 80 | |
| 81 | var repos map[string]json.RawMessage |
| 82 | if err := json.Unmarshal(data, &repos); err != nil { |
| 83 | summary.FailedSources = append(summary.FailedSources, f.filename) |
| 84 | continue |
| 85 | } |
| 86 | |
| 87 | summary.SourcesScanned++ |
| 88 | for key, raw := range repos { |
| 89 | var entry repoEntry |
| 90 | if err := json.Unmarshal(raw, &entry); err != nil { |
| 91 | continue |
| 92 | } |
| 93 | if entry.Enabled != nil && !*entry.Enabled { |
| 94 | continue |
| 95 | } |
| 96 | |
| 97 | item := Item{ |
| 98 | Kind: f.kind, |
| 99 | Name: entryName(entry, key), |
| 100 | Description: entry.Description, |
| 101 | RepoOwner: effectiveOwner(entry), |
| 102 | RepoName: effectiveName(entry), |
| 103 | RepoBranch: effectiveBranch(entry), |
| 104 | ItemPath: entryPath(entry, f.kind), |
| 105 | InstallKey: key, |
| 106 | TargetApps: strings.Join(defaultTargetApps(f.kind), ","), |
| 107 | } |
| 108 | if err := svc.store.UpsertItem(ctx, item); err != nil { |
| 109 | continue |
| 110 | } |
| 111 | summary.ItemsAdded++ |