@rbbtsn0w/adg 0.6.0-beta.10 → 0.6.0-beta.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/README.md +10 -7
  2. package/dist/bin/adg.js +4 -3
  3. package/dist/src/agents/base.js +2 -1
  4. package/dist/src/cli/core-plugin-handlers.js +97 -0
  5. package/dist/src/cli/handlers.js +4 -82
  6. package/dist/src/manifest.js +56 -3
  7. package/dist/src/subprocess.js +53 -0
  8. package/dist/vendor/skills/src/add.js +0 -15
  9. package/dist/vendor/skills/src/git-tree.js +4 -4
  10. package/dist/vendor/skills/src/skill-lock.js +4 -3
  11. package/dist/vendor/skills/src/update.js +9 -73
  12. package/dist/vendor/skills/src/use.js +28 -4
  13. package/docs/branching-and-release.md +52 -0
  14. package/package.json +7 -2
  15. package/schemas/adg-plugin.schema.json +1 -0
  16. package/vendor/skills/PROVENANCE.md +2 -0
  17. package/vendor/skills/package.json +0 -144
  18. package/vendor/skills/src/add.ts +0 -2213
  19. package/vendor/skills/src/agents.ts +0 -811
  20. package/vendor/skills/src/blob.ts +0 -588
  21. package/vendor/skills/src/cli.ts +0 -396
  22. package/vendor/skills/src/constants.ts +0 -3
  23. package/vendor/skills/src/detect-agent.ts +0 -62
  24. package/vendor/skills/src/find.ts +0 -419
  25. package/vendor/skills/src/frontmatter.ts +0 -16
  26. package/vendor/skills/src/git-tree.ts +0 -36
  27. package/vendor/skills/src/git.ts +0 -277
  28. package/vendor/skills/src/install.ts +0 -91
  29. package/vendor/skills/src/installer.ts +0 -1307
  30. package/vendor/skills/src/list.ts +0 -231
  31. package/vendor/skills/src/local-lock.ts +0 -189
  32. package/vendor/skills/src/plugin-manifest.ts +0 -183
  33. package/vendor/skills/src/prompts/search-multiselect.ts +0 -387
  34. package/vendor/skills/src/providers/index.ts +0 -14
  35. package/vendor/skills/src/providers/registry.ts +0 -51
  36. package/vendor/skills/src/providers/types.ts +0 -97
  37. package/vendor/skills/src/providers/wellknown.ts +0 -812
  38. package/vendor/skills/src/remove.ts +0 -335
  39. package/vendor/skills/src/sanitize.ts +0 -65
  40. package/vendor/skills/src/self-cli.ts +0 -20
  41. package/vendor/skills/src/skill-lock.ts +0 -329
  42. package/vendor/skills/src/skills.ts +0 -316
  43. package/vendor/skills/src/source-parser.ts +0 -449
  44. package/vendor/skills/src/sync.ts +0 -478
  45. package/vendor/skills/src/telemetry.ts +0 -226
  46. package/vendor/skills/src/test-utils.ts +0 -73
  47. package/vendor/skills/src/types.ts +0 -129
  48. package/vendor/skills/src/update-source.ts +0 -90
  49. package/vendor/skills/src/update.ts +0 -849
  50. package/vendor/skills/src/use.ts +0 -682
@@ -1,588 +0,0 @@
1
- /**
2
- * Blob-based skill download utilities.
3
- *
4
- * Enables fast skill installation by fetching pre-built skill snapshots
5
- * from the skills.sh download API instead of cloning git repos.
6
- *
7
- * Flow:
8
- * 1. GitHub Trees API → discover SKILL.md locations
9
- * 2. raw.githubusercontent.com → fetch frontmatter to get skill names
10
- * 3. skills.sh/api/download → fetch full file contents from cached blob
11
- */
12
-
13
- import { createHash } from 'node:crypto';
14
- import { parseFrontmatter } from './frontmatter.ts';
15
- import { sanitizeMetadata } from './sanitize.ts';
16
- import type { Skill } from './types.ts';
17
-
18
- // ─── Types ───
19
-
20
- export interface SkillSnapshotFile {
21
- path: string;
22
- contents: string;
23
- }
24
-
25
- export interface SkillDownloadResponse {
26
- files: SkillSnapshotFile[];
27
- hash: string; // skillsComputedHash
28
- }
29
-
30
- /**
31
- * A skill resolved from blob storage, carrying file contents in memory
32
- * instead of referencing a directory on disk.
33
- */
34
- export interface BlobSkill extends Skill {
35
- /** Files from the blob snapshot */
36
- files: SkillSnapshotFile[];
37
- /** skillsComputedHash from the blob snapshot */
38
- snapshotHash: string;
39
- /** Path of the SKILL.md within the repo (e.g., "skills/react-best-practices/SKILL.md") */
40
- repoPath: string;
41
- }
42
-
43
- // ─── Constants ───
44
-
45
- const DOWNLOAD_BASE_URL = process.env.SKILLS_DOWNLOAD_URL || 'https://skills.sh';
46
-
47
- // Repos that self-host their downloads on the blob fast-path
48
- export const BLOB_ALLOWED_REPOS: Record<string, { downloadUrl: (slug: string) => string }> = {
49
- 'zapier/connectors': {
50
- downloadUrl: (slug) =>
51
- `https://connectors-skills.zapier.com/download/${encodeURIComponent(slug)}/snapshot.json`,
52
- },
53
- };
54
-
55
- /** Timeout for individual HTTP fetches (ms) */
56
- const FETCH_TIMEOUT = 10_000;
57
-
58
- // ─── Slug computation ───
59
-
60
- /**
61
- * Convert a skill name to a URL-safe slug.
62
- * Must match the server-side toSkillSlug() exactly.
63
- */
64
- export function toSkillSlug(name: string): string {
65
- return name
66
- .toLowerCase()
67
- .replace(/[\s_]+/g, '-')
68
- .replace(/[^a-z0-9-]/g, '')
69
- .replace(/-+/g, '-')
70
- .replace(/^-|-$/g, '');
71
- }
72
-
73
- // ─── GitHub Trees API ───
74
-
75
- export interface TreeEntry {
76
- path: string;
77
- type: 'blob' | 'tree';
78
- sha: string;
79
- size?: number;
80
- }
81
-
82
- export interface RepoTree {
83
- sha: string;
84
- branch: string;
85
- tree: TreeEntry[];
86
- }
87
-
88
- /**
89
- * Within-process memo: once we've discovered that the GitHub API has
90
- * rate-limited this IP, subsequent calls skip straight to the auth fallback
91
- * instead of burning round trips on requests guaranteed to 403.
92
- */
93
- let _rateLimitedThisSession = false;
94
-
95
- /** For tests only. */
96
- export function resetRepoTreeAuthState(): void {
97
- _rateLimitedThisSession = false;
98
- }
99
-
100
- interface BranchFetchResult {
101
- tree: RepoTree | null;
102
- rateLimited: boolean;
103
- /**
104
- * ADG patch: the unauthenticated request got 401/403/404 — a private or
105
- * access-controlled repo looks identical to "not found" to an anonymous
106
- * caller, so a token may unlock it. Distinct from `rateLimited`.
107
- */
108
- authMayHelp: boolean;
109
- }
110
-
111
- async function fetchTreeBranch(
112
- ownerRepo: string,
113
- branch: string,
114
- token: string | null
115
- ): Promise<BranchFetchResult> {
116
- try {
117
- const url = `https://api.github.com/repos/${ownerRepo}/git/trees/${encodeURIComponent(branch)}?recursive=1`;
118
- const headers: Record<string, string> = {
119
- Accept: 'application/vnd.github.v3+json',
120
- 'User-Agent': 'skills-cli',
121
- };
122
- if (token) {
123
- headers['Authorization'] = `Bearer ${token}`;
124
- }
125
-
126
- const response = await fetch(url, {
127
- headers,
128
- signal: AbortSignal.timeout(FETCH_TIMEOUT),
129
- });
130
-
131
- if (response.ok) {
132
- const data = (await response.json()) as {
133
- sha: string;
134
- tree: TreeEntry[];
135
- };
136
- return {
137
- tree: { sha: data.sha, branch, tree: data.tree },
138
- rateLimited: false,
139
- authMayHelp: false,
140
- };
141
- }
142
-
143
- // GitHub signals rate-limit with 403 + X-RateLimit-Remaining: 0.
144
- const rateLimited =
145
- response.status === 403 && response.headers.get('x-ratelimit-remaining') === '0';
146
- // ADG patch: a 401/403/404 from an UNauthenticated request may just mean the
147
- // repo is private — retry with a token before giving up. GitHub returns 404
148
- // (not 403) for private repos to anonymous callers to avoid leaking existence.
149
- const authMayHelp =
150
- !rateLimited &&
151
- (response.status === 401 || response.status === 403 || response.status === 404);
152
- return { tree: null, rateLimited, authMayHelp };
153
- } catch {
154
- return { tree: null, rateLimited: false, authMayHelp: false };
155
- }
156
- }
157
-
158
- /**
159
- * Fetch the full recursive tree for a GitHub repo.
160
- * Returns the tree data including all entries, or null on failure.
161
- * Tries branches in order: ref (if specified), then main, then master.
162
- *
163
- * Authentication is lazy: by default the call goes out unauthenticated,
164
- * which is enough for the vast majority of users (60 req/hr per IP).
165
- * Only if GitHub responds with a rate-limit 403 do we ask the optional
166
- * `getToken` callback for a token and retry. This avoids invoking
167
- * `gh auth token` on every install, which corporate endpoint security
168
- * tools flag as suspicious credential extraction. See issue #523.
169
- */
170
- export async function fetchRepoTree(
171
- ownerRepo: string,
172
- ref?: string,
173
- getToken?: () => string | null
174
- ): Promise<RepoTree | null> {
175
- const branches = ref ? [ref] : ['HEAD', 'main', 'master'];
176
-
177
- // Fast path: once we've seen a rate limit in this process, don't bother
178
- // retrying unauth on subsequent calls. Go straight to auth.
179
- if (_rateLimitedThisSession && getToken) {
180
- const token = getToken();
181
- if (!token) return null;
182
- for (const branch of branches) {
183
- const result = await fetchTreeBranch(ownerRepo, branch, token);
184
- if (result.tree) return result.tree;
185
- }
186
- return null;
187
- }
188
-
189
- // First pass: unauthenticated.
190
- let rateLimited = false;
191
- let authMayHelp = false;
192
- for (const branch of branches) {
193
- const result = await fetchTreeBranch(ownerRepo, branch, null);
194
- if (result.tree) return result.tree;
195
- if (result.rateLimited) {
196
- // All branches share the same rate-limit bucket on this IP, so it's
197
- // pointless to keep trying other branches in this pass.
198
- rateLimited = true;
199
- break;
200
- }
201
- // ADG patch: remember a possible-private signal, but keep trying the other
202
- // candidate branches unauthenticated first (the repo may just lack `main`).
203
- if (result.authMayHelp) authMayHelp = true;
204
- }
205
-
206
- // ADG patch: fall back to an authenticated retry on EITHER a rate limit or a
207
- // private/forbidden response. Upstream only retried on rate limit, so private
208
- // repos never used the token and always failed.
209
- if ((!rateLimited && !authMayHelp) || !getToken) return null;
210
-
211
- // Only a rate limit is a process-wide condition worth short-circuiting later.
212
- if (rateLimited) _rateLimitedThisSession = true;
213
- const token = getToken();
214
- if (!token) return null;
215
-
216
- for (const branch of branches) {
217
- const result = await fetchTreeBranch(ownerRepo, branch, token);
218
- if (result.tree) return result.tree;
219
- }
220
- return null;
221
- }
222
-
223
- /**
224
- * Extract the folder hash (tree SHA) for a specific skill path from a repo tree.
225
- * This replaces the per-skill GitHub API call previously done in fetchSkillFolderHash().
226
- */
227
- export function getSkillFolderHashFromTree(tree: RepoTree, skillPath: string): string | null {
228
- let folderPath = skillPath.replace(/\\/g, '/');
229
-
230
- // Remove SKILL.md suffix to get folder path (case-insensitive)
231
- if (folderPath.toLowerCase().endsWith('/skill.md')) {
232
- folderPath = folderPath.slice(0, -9);
233
- } else if (folderPath.toLowerCase().endsWith('skill.md')) {
234
- folderPath = folderPath.slice(0, -8);
235
- }
236
- if (folderPath.endsWith('/')) {
237
- folderPath = folderPath.slice(0, -1);
238
- }
239
-
240
- // Root-level skill
241
- if (!folderPath) {
242
- return tree.sha;
243
- }
244
-
245
- const entry = tree.tree.find((e) => e.type === 'tree' && e.path === folderPath);
246
- return entry?.sha ?? null;
247
- }
248
-
249
- // ─── Skill discovery from tree ───
250
-
251
- /** Known directories where SKILL.md files are commonly found (relative to repo root) */
252
- const PRIORITY_PREFIXES = [
253
- '',
254
- 'skills/',
255
- 'skills/.curated/',
256
- 'skills/.experimental/',
257
- 'skills/.system/',
258
- '.agents/skills/',
259
- '.claude/skills/',
260
- '.cline/skills/',
261
- '.codebuddy/skills/',
262
- '.codex/skills/',
263
- '.commandcode/skills/',
264
- '.continue/skills/',
265
- '.github/skills/',
266
- '.goose/skills/',
267
- '.iflow/skills/',
268
- '.junie/skills/',
269
- '.kilocode/skills/',
270
- '.kiro/skills/',
271
- '.mux/skills/',
272
- '.neovate/skills/',
273
- '.opencode/skills/',
274
- '.openhands/skills/',
275
- '.pi/skills/',
276
- '.qoder/skills/',
277
- '.roo/skills/',
278
- '.trae/skills/',
279
- '.windsurf/skills/',
280
- '.zencoder/skills/',
281
- ];
282
-
283
- /**
284
- * Find all SKILL.md file paths in a repo tree.
285
- * Applies the same priority directory logic as discoverSkills().
286
- * If subpath is set, only searches within that subtree.
287
- */
288
- export function findSkillMdPaths(tree: RepoTree, subpath?: string): string[] {
289
- // Find all blob entries that are SKILL.md files (case-insensitive)
290
- const allSkillMds = tree.tree
291
- .filter((e) => e.type === 'blob' && e.path.toLowerCase().endsWith('skill.md'))
292
- .map((e) => e.path);
293
-
294
- // Apply subpath filter
295
- const prefix = subpath ? (subpath.endsWith('/') ? subpath : subpath + '/') : '';
296
- const filtered = prefix
297
- ? allSkillMds.filter((p) => p.startsWith(prefix) || p === prefix + 'SKILL.md')
298
- : allSkillMds;
299
-
300
- if (filtered.length === 0) return [];
301
-
302
- // Check priority directories first (same order as discoverSkills).
303
- // Non-root prefixes also accept depth-2 paths so the blob fast path stays
304
- // in sync with the on-disk walk's catalog-layout discovery.
305
- const priorityResults: string[] = [];
306
- const seen = new Set<string>();
307
- // Mirror of SKIP_DIRS at the top of src/skills.ts. Kept local to avoid
308
- // a cross-file import; if these ever drift, update both.
309
- const SKIP_DIRS = new Set(['node_modules', '.git', 'dist', 'build', '__pycache__']);
310
- const lowerSkillMdSet = new Set(filtered.map((p) => p.toLowerCase()));
311
-
312
- for (const priorityPrefix of PRIORITY_PREFIXES) {
313
- const fullPrefix = prefix + priorityPrefix;
314
- const isContainer = priorityPrefix !== '';
315
-
316
- for (const skillMd of filtered) {
317
- // Check if this SKILL.md is directly inside the priority dir (one level deep)
318
- if (!skillMd.startsWith(fullPrefix)) continue;
319
- const rest = skillMd.slice(fullPrefix.length);
320
-
321
- // Direct SKILL.md in the priority dir (e.g., "skills/SKILL.md")
322
- if (rest.toLowerCase() === 'skill.md') {
323
- if (!seen.has(skillMd)) {
324
- priorityResults.push(skillMd);
325
- seen.add(skillMd);
326
- }
327
- continue;
328
- }
329
-
330
- // SKILL.md one level deep (e.g., "skills/react-best-practices/SKILL.md")
331
- const parts = rest.split('/');
332
- if (parts.length === 2 && parts[1]!.toLowerCase() === 'skill.md') {
333
- if (!seen.has(skillMd)) {
334
- priorityResults.push(skillMd);
335
- seen.add(skillMd);
336
- }
337
- continue;
338
- }
339
-
340
- // SKILL.md two levels deep under a known container prefix
341
- // (e.g., "skills/<category>/<skill>/SKILL.md"). Skip if the parent
342
- // child dir already has its own SKILL.md (no descent past), or if
343
- // any path segment is an ignored directory.
344
- if (
345
- isContainer &&
346
- parts.length === 3 &&
347
- parts[2]!.toLowerCase() === 'skill.md' &&
348
- !SKIP_DIRS.has(parts[0]!) &&
349
- !SKIP_DIRS.has(parts[1]!)
350
- ) {
351
- const parentSkillMd = `${fullPrefix}${parts[0]}/SKILL.md`.toLowerCase();
352
- if (!lowerSkillMdSet.has(parentSkillMd) && !seen.has(skillMd)) {
353
- priorityResults.push(skillMd);
354
- seen.add(skillMd);
355
- }
356
- }
357
- }
358
- }
359
-
360
- // If we found skills in priority dirs, return those
361
- if (priorityResults.length > 0) return priorityResults;
362
-
363
- // Fallback: return all SKILL.md files found (limited to 5 levels deep)
364
- return filtered.filter((p) => {
365
- const depth = p.split('/').length;
366
- return depth <= 6; // 5 levels + the SKILL.md file itself
367
- });
368
- }
369
-
370
- // ─── Fetching skill content ───
371
-
372
- /**
373
- * Fetch a single SKILL.md from raw.githubusercontent.com to get frontmatter.
374
- * Returns the raw content string, or null on failure.
375
- */
376
- async function fetchSkillMdContent(
377
- ownerRepo: string,
378
- branch: string,
379
- skillMdPath: string
380
- ): Promise<string | null> {
381
- try {
382
- const url = `https://raw.githubusercontent.com/${ownerRepo}/${branch}/${skillMdPath}`;
383
- const response = await fetch(url, {
384
- signal: AbortSignal.timeout(FETCH_TIMEOUT),
385
- });
386
- if (!response.ok) return null;
387
- return await response.text();
388
- } catch {
389
- return null;
390
- }
391
- }
392
-
393
- /**
394
- * Fetch a skill's full file contents from the skills.sh download API.
395
- * Returns the files array and content hash, or null on failure.
396
- */
397
- async function fetchSkillDownload(
398
- source: string,
399
- slug: string
400
- ): Promise<SkillDownloadResponse | null> {
401
- try {
402
- const [owner, repo] = source.split('/');
403
- const defaultUrl = `${DOWNLOAD_BASE_URL}/api/download/${encodeURIComponent(owner!)}/${encodeURIComponent(repo!)}/${encodeURIComponent(slug)}`;
404
- // Self-hosted repos build their own URL; otherwise fall back to the default.
405
- const selfHosted = BLOB_ALLOWED_REPOS[source.toLowerCase()]?.downloadUrl(slug);
406
- const url = selfHosted ?? defaultUrl;
407
- const response = await fetch(url, {
408
- signal: AbortSignal.timeout(FETCH_TIMEOUT),
409
- });
410
- if (!response.ok) return null;
411
- return (await response.json()) as SkillDownloadResponse;
412
- } catch {
413
- return null;
414
- }
415
- }
416
-
417
- // ─── Main entry point ───
418
-
419
- export interface BlobInstallResult {
420
- skills: BlobSkill[];
421
- tree: RepoTree;
422
- }
423
-
424
- function computeSnapshotHash(files: SkillSnapshotFile[]): string {
425
- const hash = createHash('sha256');
426
- for (const file of [...files].sort((a, b) => a.path.localeCompare(b.path))) {
427
- hash.update(file.path);
428
- hash.update(file.contents);
429
- }
430
- return hash.digest('hex');
431
- }
432
-
433
- /**
434
- * Attempt to resolve skills from blob storage instead of cloning.
435
- *
436
- * Steps:
437
- * 1. Fetch repo tree from GitHub Trees API
438
- * 2. Discover SKILL.md paths from the tree
439
- * 3. Fetch SKILL.md content from raw.githubusercontent.com (for frontmatter/name)
440
- * 4. Compute slugs and fetch full snapshots from skills.sh download API
441
- *
442
- * Returns the resolved BlobSkills + tree data on success, or null on any failure
443
- * (the caller should fall back to git clone).
444
- *
445
- * @param ownerRepo - e.g., "vercel-labs/agent-skills"
446
- * @param options - subpath, skillFilter, ref, token
447
- */
448
- export async function tryBlobInstall(
449
- ownerRepo: string,
450
- options: {
451
- subpath?: string;
452
- skillFilter?: string;
453
- ref?: string;
454
- getToken?: () => string | null;
455
- includeInternal?: boolean;
456
- } = {}
457
- ): Promise<BlobInstallResult | null> {
458
- // 1. Fetch the full repo tree
459
- const tree = await fetchRepoTree(ownerRepo, options.ref, options.getToken);
460
- if (!tree) return null;
461
-
462
- // 2. Discover SKILL.md paths in the tree
463
- let skillMdPaths = findSkillMdPaths(tree, options.subpath);
464
- if (skillMdPaths.length === 0) return null;
465
-
466
- // 3. If a skill filter is set (owner/repo@skill-name), try to narrow down
467
- if (options.skillFilter) {
468
- const filterSlug = toSkillSlug(options.skillFilter);
469
- const filtered = skillMdPaths.filter((p) => {
470
- // Match by folder name — e.g., "skills/react-best-practices/SKILL.md"
471
- const parts = p.split('/');
472
- if (parts.length < 2) return false;
473
- const folderName = parts[parts.length - 2]!;
474
- return toSkillSlug(folderName) === filterSlug;
475
- });
476
- if (filtered.length > 0) {
477
- skillMdPaths = filtered;
478
- }
479
- // If no match by folder name, we'll try matching by frontmatter name below
480
- }
481
-
482
- // 4. Fetch SKILL.md content from raw.githubusercontent.com in parallel
483
- const mdFetches = await Promise.all(
484
- skillMdPaths.map(async (mdPath) => {
485
- const content = await fetchSkillMdContent(ownerRepo, tree.branch, mdPath);
486
- return { mdPath, content };
487
- })
488
- );
489
-
490
- // Parse frontmatter to get skill names
491
- const parsedSkills: Array<{
492
- mdPath: string;
493
- name: string;
494
- description: string;
495
- content: string;
496
- slug: string;
497
- metadata?: Record<string, unknown>;
498
- }> = [];
499
-
500
- for (const { mdPath, content } of mdFetches) {
501
- if (!content) continue;
502
-
503
- const { data } = parseFrontmatter(content);
504
- if (!data.name || !data.description) continue;
505
- if (typeof data.name !== 'string' || typeof data.description !== 'string') continue;
506
-
507
- // Skip internal skills unless explicitly requested
508
- const isInternal = (data.metadata as Record<string, unknown>)?.internal === true;
509
- if (isInternal && !options.includeInternal) continue;
510
-
511
- const safeName = sanitizeMetadata(data.name);
512
- const safeDescription = sanitizeMetadata(data.description);
513
-
514
- parsedSkills.push({
515
- mdPath,
516
- name: safeName,
517
- description: safeDescription,
518
- content,
519
- slug: toSkillSlug(safeName),
520
- metadata: data.metadata as Record<string, unknown> | undefined,
521
- });
522
- }
523
-
524
- if (parsedSkills.length === 0) return null;
525
-
526
- // Apply skill filter by name if not already filtered by folder name
527
- let filteredSkills = parsedSkills;
528
- if (options.skillFilter) {
529
- const filterSlug = toSkillSlug(options.skillFilter);
530
- const nameFiltered = parsedSkills.filter((s) => s.slug === filterSlug);
531
- if (nameFiltered.length > 0) {
532
- filteredSkills = nameFiltered;
533
- }
534
- // If still no match, let the caller fall back to clone where
535
- // filterSkills() does fuzzy matching
536
- if (filteredSkills.length === 0) return null;
537
- }
538
-
539
- // 5. Fetch full snapshots from skills.sh download API in parallel
540
- const source = ownerRepo.toLowerCase();
541
- const downloads = await Promise.all(
542
- filteredSkills.map(async (skill) => {
543
- const download = await fetchSkillDownload(source, skill.slug);
544
- return { skill, download };
545
- })
546
- );
547
-
548
- // If ANY download failed, fall back to clone — we don't do partial blob installs
549
- const allSucceeded = downloads.every((d) => d.download !== null);
550
- if (!allSucceeded) return null;
551
-
552
- // 6. Convert to BlobSkill objects
553
- const blobSkills: BlobSkill[] = downloads.map(({ skill, download }) => {
554
- // Compute the folder path from the SKILL.md path (e.g., "skills/react-best-practices")
555
- const mdPathLower = skill.mdPath.toLowerCase();
556
- const folderPath = mdPathLower.endsWith('/skill.md')
557
- ? skill.mdPath.slice(0, -9)
558
- : mdPathLower === 'skill.md'
559
- ? ''
560
- : skill.mdPath.slice(0, -(1 + 'SKILL.md'.length));
561
-
562
- // A root-level SKILL.md means the repository root is a skill entrypoint,
563
- // not that the entire repository is installable skill payload. Some cached
564
- // snapshots for root skills contain every repo file; installing those can
565
- // dump thousands of unrelated files into .agents/skills/<name>. Keep root
566
- // skills to their SKILL.md unless/until the skill spec gains an explicit
567
- // include list for supporting files.
568
- const files = folderPath
569
- ? download!.files
570
- : download!.files.filter((file) => file.path.toLowerCase() === 'skill.md');
571
-
572
- return {
573
- name: skill.name,
574
- description: skill.description,
575
- // BlobSkills don't have a disk path — set to empty string.
576
- // The installer uses the files array directly.
577
- path: '',
578
- rawContent: skill.content,
579
- metadata: skill.metadata,
580
- files,
581
- snapshotHash:
582
- files.length === download!.files.length ? download!.hash : computeSnapshotHash(files),
583
- repoPath: skill.mdPath,
584
- };
585
- });
586
-
587
- return { skills: blobSkills, tree };
588
- }