fetchResourceManifest downloads the resource's source repo and reads its manifest, returning both the content and the manifest path relative to the repo root (e.g. "skills/foo/SKILL.md"). The relative path lets callers show users where the content came from. Failures return empty strings so callers
(item Item)
| 459 | // degrade gracefully: install still creates the directory structure, and the |
| 460 | // detail view still renders the indexed metadata without the manifest body. |
| 461 | func (svc *Service) fetchResourceManifest(item Item) (content, manifestRel string) { |
| 462 | if item.RepoOwner == "" || item.RepoName == "" || item.ItemPath == "" { |
| 463 | return "", "" |
| 464 | } |
| 465 | dest := filepath.Join(pathutil.CacheDir(), "metadata-install", item.RepoOwner+"-"+item.RepoName) |
| 466 | _ = os.RemoveAll(dest) |
| 467 | defer os.RemoveAll(dest) |
| 468 | |
| 469 | root, err := svc.fetcher.Fetch(item.RepoOwner, item.RepoName, item.RepoBranch, dest) |
| 470 | if err != nil { |
| 471 | return "", "" |
| 472 | } |
| 473 | |
| 474 | target := filepath.Join(root, filepath.FromSlash(item.ItemPath)) |
| 475 | info, err := os.Stat(target) |
| 476 | if err != nil { |
| 477 | return "", "" |
| 478 | } |
| 479 | manifest := target |
| 480 | if info.IsDir() { |
| 481 | manifest = filepath.Join(target, defaultManifest(item.Kind)) |
| 482 | } |
| 483 | data, err := os.ReadFile(manifest) |
| 484 | if err != nil { |
| 485 | return "", "" |
| 486 | } |
| 487 | return string(data), relPath(root, manifest) |
| 488 | } |
| 489 | |
| 490 | func defaultManifest(kind string) string { |
| 491 | switch kind { |
no test coverage detected