@rbbtsn0w/adg 0.6.0-beta.9 → 0.7.0-beta.1

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 +11 -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,1307 +0,0 @@
1
- import {
2
- mkdir,
3
- cp,
4
- access,
5
- readdir,
6
- symlink,
7
- lstat,
8
- rm,
9
- readlink,
10
- readFile,
11
- writeFile,
12
- stat,
13
- realpath,
14
- } from 'fs/promises';
15
- import { existsSync } from 'fs';
16
- import { join, basename, normalize, resolve, sep, relative, dirname, extname } from 'path';
17
- import { homedir, platform } from 'os';
18
- import type { Skill, AgentType, RemoteSkill } from './types.ts';
19
- import type { WellKnownSkill } from './providers/wellknown.ts';
20
- import {
21
- agents,
22
- detectInstalledAgents,
23
- isUniversalAgent,
24
- getEveSubagents,
25
- EVE_SUBAGENTS_DIR,
26
- } from './agents.ts';
27
- import { AGENTS_DIR, SKILLS_SUBDIR } from './constants.ts';
28
- import { parseFrontmatter } from './frontmatter.ts';
29
- import { parseSkillMd } from './skills.ts';
30
-
31
- export type InstallMode = 'symlink' | 'copy';
32
-
33
- interface InstallResult {
34
- success: boolean;
35
- path: string;
36
- canonicalPath?: string;
37
- mode: InstallMode;
38
- symlinkFailed?: boolean;
39
- skipped?: boolean;
40
- error?: string;
41
- }
42
-
43
- /**
44
- * Sanitizes a filename/directory name to prevent path traversal attacks
45
- * and ensures it follows kebab-case convention
46
- * @param name - The name to sanitize
47
- * @returns Sanitized name safe for use in file paths
48
- */
49
- export function sanitizeName(name: string): string {
50
- const sanitized = name
51
- .toLowerCase()
52
- // Replace any sequence of characters that are NOT lowercase letters (a-z),
53
- // digits (0-9), dots (.), or underscores (_) with a single hyphen.
54
- // This converts spaces, special chars, and path traversal attempts (../) into hyphens.
55
- .replace(/[^a-z0-9._]+/g, '-')
56
- // Remove leading/trailing dots and hyphens to prevent hidden files (.) and
57
- // ensure clean directory names. The pattern matches:
58
- // - ^[.\-]+ : one or more dots or hyphens at the start
59
- // - [.\-]+$ : one or more dots or hyphens at the end
60
- .replace(/^[.\-]+|[.\-]+$/g, '');
61
-
62
- // Limit to 255 chars (common filesystem limit), fallback to 'unnamed-skill' if empty
63
- return sanitized.substring(0, 255) || 'unnamed-skill';
64
- }
65
-
66
- /**
67
- * Validates that a path is within an expected base directory
68
- * @param basePath - The expected base directory
69
- * @param targetPath - The path to validate
70
- * @returns true if targetPath is within basePath
71
- */
72
- function isPathSafe(basePath: string, targetPath: string): boolean {
73
- const normalizedBase = normalize(resolve(basePath));
74
- const normalizedTarget = normalize(resolve(targetPath));
75
-
76
- return normalizedTarget.startsWith(normalizedBase + sep) || normalizedTarget === normalizedBase;
77
- }
78
-
79
- function pathsOverlap(pathA: string, pathB: string): boolean {
80
- return isPathSafe(pathA, pathB) || isPathSafe(pathB, pathA);
81
- }
82
-
83
- // Dirent.isDirectory() is false for symlinks; follow and verify the target is a directory.
84
- async function isDirEntryOrSymlinkToDir(
85
- entry: { isDirectory(): boolean; isSymbolicLink(): boolean },
86
- entryPath: string
87
- ): Promise<boolean> {
88
- if (entry.isDirectory()) return true;
89
- if (!entry.isSymbolicLink()) return false;
90
- try {
91
- return (await stat(entryPath)).isDirectory();
92
- } catch {
93
- return false;
94
- }
95
- }
96
-
97
- export function getCanonicalSkillsDir(global: boolean, cwd?: string): string {
98
- const baseDir = global ? homedir() : cwd || process.cwd();
99
- return join(baseDir, AGENTS_DIR, SKILLS_SUBDIR);
100
- }
101
-
102
- /**
103
- * Resolve the skills directory for a specific Eve subagent, relative to the
104
- * project root: `agent/subagents/<name>/skills`. The subagent name is
105
- * sanitized to prevent directory traversal when it originates from user input.
106
- */
107
- export function getEveSubagentSkillsDir(subagent: string, cwd?: string): string {
108
- const baseDir = cwd || process.cwd();
109
- return join(baseDir, EVE_SUBAGENTS_DIR, sanitizeName(subagent), 'skills');
110
- }
111
-
112
- /**
113
- * Gets the base directory for an agent's skills, respecting universal agents.
114
- * Universal agents always use the canonical directory, which prevents
115
- * redundant symlinks and double-listing of skills.
116
- *
117
- * For Eve, an optional `eveSubagent` targets a subagent's skills directory
118
- * (`agent/subagents/<name>/skills`) instead of the root agent's `agent/skills`.
119
- */
120
- export function getAgentBaseDir(
121
- agentType: AgentType,
122
- global: boolean,
123
- cwd?: string,
124
- eveSubagent?: string
125
- ): string {
126
- if (isUniversalAgent(agentType)) {
127
- return getCanonicalSkillsDir(global, cwd);
128
- }
129
-
130
- // Eve subagents are inherently project-scoped — they live under the project's
131
- // agent/ directory, so the `global` flag does not apply here.
132
- if (agentType === 'eve' && eveSubagent) {
133
- return getEveSubagentSkillsDir(eveSubagent, cwd);
134
- }
135
-
136
- const agent = agents[agentType];
137
- const baseDir = global ? homedir() : cwd || process.cwd();
138
-
139
- if (global) {
140
- if (agent.globalSkillsDir === undefined) {
141
- // This should be caught by callers checking support
142
- return join(baseDir, agent.skillsDir);
143
- }
144
- return agent.globalSkillsDir;
145
- }
146
-
147
- return join(baseDir, agent.skillsDir);
148
- }
149
-
150
- function resolveSymlinkTarget(linkPath: string, linkTarget: string): string {
151
- return resolve(dirname(linkPath), linkTarget);
152
- }
153
-
154
- /**
155
- * Cleans and recreates a directory for skill installation.
156
- *
157
- * This ensures:
158
- * 1. Renamed/deleted files from previous installs are removed
159
- * 2. Symlinks (including self-referential ones causing ELOOP) are handled
160
- * when canonical and agent paths resolve to the same location
161
- */
162
- async function cleanAndCreateDirectory(path: string): Promise<void> {
163
- try {
164
- await rm(path, { recursive: true, force: true });
165
- } catch {
166
- // Ignore cleanup errors - mkdir will fail if there's a real problem
167
- }
168
- await mkdir(path, { recursive: true });
169
- }
170
-
171
- /**
172
- * Resolve a path's parent directory through symlinks, keeping the final component.
173
- * This handles the case where a parent directory (e.g., ~/.claude/skills) is a symlink
174
- * to another location (e.g., ~/.agents/skills). In that case, computing relative paths
175
- * from the symlink path produces broken symlinks.
176
- *
177
- * Returns the real path of the parent + the original basename.
178
- * If realpath fails (parent doesn't exist), returns the original resolved path.
179
- */
180
- async function resolveParentSymlinks(path: string): Promise<string> {
181
- const resolved = resolve(path);
182
- const dir = dirname(resolved);
183
- const base = basename(resolved);
184
- try {
185
- const realDir = await realpath(dir);
186
- return join(realDir, base);
187
- } catch {
188
- return resolved;
189
- }
190
- }
191
-
192
- /**
193
- * Creates a symlink, handling cross-platform differences
194
- * Returns true if symlink was created, false if fallback to copy is needed
195
- */
196
- async function createSymlink(target: string, linkPath: string): Promise<boolean> {
197
- try {
198
- const resolvedTarget = resolve(target);
199
- const resolvedLinkPath = resolve(linkPath);
200
-
201
- // Use realpath to handle cases where parent directories are symlinked.
202
- // This prevents deleting the canonical directory if the agent directory
203
- // is a symlink to the canonical location.
204
- const [realTarget, realLinkPath] = await Promise.all([
205
- realpath(resolvedTarget).catch(() => resolvedTarget),
206
- realpath(resolvedLinkPath).catch(() => resolvedLinkPath),
207
- ]);
208
-
209
- if (realTarget === realLinkPath) {
210
- return true;
211
- }
212
-
213
- // Also check with symlinks resolved in parent directories.
214
- // This handles cases where e.g. ~/.claude/skills is a symlink to ~/.agents/skills,
215
- // so ~/.claude/skills/<skill> and ~/.agents/skills/<skill> are physically the same.
216
- const realTargetWithParents = await resolveParentSymlinks(target);
217
- const realLinkPathWithParents = await resolveParentSymlinks(linkPath);
218
-
219
- if (realTargetWithParents === realLinkPathWithParents) {
220
- return true;
221
- }
222
-
223
- try {
224
- const stats = await lstat(linkPath);
225
- if (stats.isSymbolicLink()) {
226
- const existingTarget = await readlink(linkPath);
227
- if (resolveSymlinkTarget(linkPath, existingTarget) === resolvedTarget) {
228
- return true;
229
- }
230
- await rm(linkPath);
231
- } else {
232
- await rm(linkPath, { recursive: true });
233
- }
234
- } catch (err: unknown) {
235
- // ELOOP = circular symlink, ENOENT = doesn't exist
236
- // For ELOOP, try to remove the broken symlink
237
- if (err && typeof err === 'object' && 'code' in err && err.code === 'ELOOP') {
238
- try {
239
- await rm(linkPath, { force: true });
240
- } catch {
241
- // If we can't remove it, symlink creation will fail and trigger copy fallback
242
- }
243
- }
244
- // For ENOENT or other errors, continue to symlink creation
245
- }
246
-
247
- const linkDir = dirname(linkPath);
248
- await mkdir(linkDir, { recursive: true });
249
-
250
- // Use the real (symlink-resolved) parent directory for computing the relative path.
251
- // This ensures the symlink target is correct even when the link's parent dir is a symlink.
252
- const realLinkDir = await resolveParentSymlinks(linkDir);
253
- const relativePath = relative(realLinkDir, target);
254
- const symlinkType = platform() === 'win32' ? 'junction' : undefined;
255
- const symlinkTarget = symlinkType === 'junction' ? resolvedTarget : relativePath;
256
-
257
- await symlink(symlinkTarget, linkPath, symlinkType);
258
- return true;
259
- } catch {
260
- return false;
261
- }
262
- }
263
-
264
- export async function installSkillForAgent(
265
- skill: Skill,
266
- agentType: AgentType,
267
- options: { global?: boolean; cwd?: string; mode?: InstallMode; eveSubagent?: string } = {}
268
- ): Promise<InstallResult> {
269
- const agent = agents[agentType];
270
- const isGlobal = options.global ?? false;
271
- const cwd = options.cwd || process.cwd();
272
- const eveSubagent = options.eveSubagent;
273
-
274
- // Check if agent supports global installation
275
- if (isGlobal && agent.globalSkillsDir === undefined) {
276
- return {
277
- success: false,
278
- path: '',
279
- mode: options.mode ?? 'symlink',
280
- error: `${agent.displayName} does not support global skill installation`,
281
- };
282
- }
283
-
284
- // Sanitize skill name to prevent directory traversal
285
- const rawSkillName = skill.name || basename(skill.path);
286
- const skillName = sanitizeName(rawSkillName);
287
-
288
- const installMode = options.mode ?? 'symlink';
289
-
290
- // Canonical location: .agents/skills/<skill-name>
291
- const canonicalBase =
292
- agentType === 'eve' && installMode === 'symlink'
293
- ? getAgentBaseDir(agentType, isGlobal, cwd, eveSubagent)
294
- : getCanonicalSkillsDir(isGlobal, cwd);
295
- const canonicalDir = join(canonicalBase, skillName);
296
-
297
- // Agent-specific location (for symlink)
298
- const agentBase = getAgentBaseDir(agentType, isGlobal, cwd, eveSubagent);
299
- const agentDir = join(agentBase, skillName);
300
-
301
- // Validate paths
302
- if (!isPathSafe(canonicalBase, canonicalDir)) {
303
- return {
304
- success: false,
305
- path: agentDir,
306
- mode: installMode,
307
- error: 'Invalid skill name: potential path traversal detected',
308
- };
309
- }
310
-
311
- if (!isPathSafe(agentBase, agentDir)) {
312
- return {
313
- success: false,
314
- path: agentDir,
315
- mode: installMode,
316
- error: 'Invalid skill name: potential path traversal detected',
317
- };
318
- }
319
-
320
- try {
321
- // Never install onto (or inside) the source directory. This can happen with
322
- // agent-specific project directories like OpenClaw's "skills" when users run
323
- // `skills add ./skills --all`: the source `./skills/<name>` and destination
324
- // `./skills/<name>` are the same path. Cleaning the destination would delete
325
- // the user's source skill before we can link or copy it.
326
- if (pathsOverlap(skill.path, agentDir)) {
327
- return {
328
- success: true,
329
- path: agentDir,
330
- mode: installMode,
331
- skipped: true,
332
- };
333
- }
334
-
335
- // For copy mode, skip canonical directory and copy directly to agent location
336
- if (installMode === 'copy') {
337
- await cleanAndCreateDirectory(agentDir);
338
- await copyDirectory(skill.path, agentDir, agentType);
339
-
340
- return {
341
- success: true,
342
- path: agentDir,
343
- mode: 'copy',
344
- };
345
- }
346
-
347
- if (pathsOverlap(skill.path, canonicalDir)) {
348
- return {
349
- success: true,
350
- path: canonicalDir,
351
- canonicalPath: canonicalDir,
352
- mode: 'symlink',
353
- skipped: true,
354
- };
355
- }
356
-
357
- // Symlink mode: copy to canonical location and symlink to agent location
358
- await cleanAndCreateDirectory(canonicalDir);
359
- await copyDirectory(skill.path, canonicalDir, agentType);
360
-
361
- // For universal agents with global install, the skill is already in the canonical
362
- // ~/.agents/skills directory. Skip creating a symlink to the agent-specific global dir
363
- // (e.g. ~/.copilot/skills) to avoid duplicates.
364
- if (isGlobal && isUniversalAgent(agentType)) {
365
- return {
366
- success: true,
367
- path: canonicalDir,
368
- canonicalPath: canonicalDir,
369
- mode: 'symlink',
370
- };
371
- }
372
-
373
- // For project-level installs, skip creating symlinks for non-universal agents
374
- // whose config directory doesn't already exist in the project. This prevents
375
- // creating directories like .windsurf/, .kiro/, etc. when those agents aren't
376
- // actually used in this project. The skill is already available in .agents/skills/.
377
- if (!isGlobal && !isUniversalAgent(agentType)) {
378
- const agentRootDir = join(cwd, agents[agentType].skillsDir.split('/')[0]!);
379
- if (!existsSync(agentRootDir)) {
380
- return {
381
- success: true,
382
- path: canonicalDir,
383
- canonicalPath: canonicalDir,
384
- mode: 'symlink',
385
- skipped: true,
386
- };
387
- }
388
- }
389
-
390
- const symlinkCreated = await createSymlink(canonicalDir, agentDir);
391
-
392
- if (!symlinkCreated) {
393
- // Symlink failed, fall back to copy
394
- await cleanAndCreateDirectory(agentDir);
395
- await copyDirectory(skill.path, agentDir, agentType);
396
-
397
- return {
398
- success: true,
399
- path: agentDir,
400
- canonicalPath: canonicalDir,
401
- mode: 'symlink',
402
- symlinkFailed: true,
403
- };
404
- }
405
-
406
- return {
407
- success: true,
408
- path: agentDir,
409
- canonicalPath: canonicalDir,
410
- mode: 'symlink',
411
- };
412
- } catch (error) {
413
- return {
414
- success: false,
415
- path: agentDir,
416
- mode: installMode,
417
- error: error instanceof Error ? error.message : 'Unknown error',
418
- };
419
- }
420
- }
421
-
422
- const EXCLUDE_FILES = new Set(['metadata.json']);
423
- const EXCLUDE_DIRS = new Set(['.git', '__pycache__', '__pypackages__']);
424
-
425
- const isExcluded = (name: string, isDirectory: boolean = false): boolean => {
426
- if (EXCLUDE_FILES.has(name)) return true;
427
- if (isDirectory && EXCLUDE_DIRS.has(name)) return true;
428
- return false;
429
- };
430
-
431
- function stripIgnoredEveFrontmatter(raw: string): string {
432
- const { data, content } = parseFrontmatter(raw);
433
- const eveData: Record<string, unknown> = {};
434
-
435
- if (typeof data.description === 'string') {
436
- eveData.description = data.description;
437
- }
438
- if (typeof data.license === 'string') {
439
- eveData.license = data.license;
440
- }
441
- if (data.metadata && typeof data.metadata === 'object' && !Array.isArray(data.metadata)) {
442
- const metadata = Object.fromEntries(
443
- Object.entries(data.metadata).filter(
444
- (entry): entry is [string, string] => typeof entry[1] === 'string'
445
- )
446
- );
447
- if (Object.keys(metadata).length > 0) {
448
- eveData.metadata = metadata;
449
- }
450
- }
451
-
452
- const keys = Object.keys(eveData);
453
- if (keys.length === 0) {
454
- return content.replace(/^\r?\n/u, '');
455
- }
456
-
457
- const frontmatter = keys.map((key) => `${key}: ${JSON.stringify(eveData[key])}`).join('\n');
458
- return `---\n${frontmatter}\n---\n${content.replace(/^\r?\n/u, '')}`;
459
- }
460
-
461
- async function copyDirectory(src: string, dest: string, agentType?: AgentType): Promise<void> {
462
- await mkdir(dest, { recursive: true });
463
-
464
- const entries = await readdir(src, { withFileTypes: true });
465
-
466
- // Copy files and directories in parallel
467
- await Promise.all(
468
- entries
469
- .filter((entry) => !isExcluded(entry.name, entry.isDirectory()))
470
- .map(async (entry) => {
471
- const srcPath = join(src, entry.name);
472
- const destPath = join(dest, entry.name);
473
-
474
- if (entry.isDirectory()) {
475
- await copyDirectory(srcPath, destPath, agentType);
476
- } else {
477
- try {
478
- if (agentType === 'eve' && entry.name.toLowerCase() === 'skill.md') {
479
- await writeFile(
480
- destPath,
481
- stripIgnoredEveFrontmatter(await readFile(srcPath, 'utf-8'))
482
- );
483
- return;
484
- }
485
-
486
- await cp(srcPath, destPath, {
487
- // If the file is a symlink to elsewhere in a remote skill, it may not
488
- // resolve correctly once it has been copied to the local location.
489
- // `dereference: true` tells Node to copy the file instead of copying
490
- // the symlink. `recursive: true` handles symlinks pointing to directories.
491
- dereference: true,
492
- recursive: true,
493
- });
494
- } catch (err: unknown) {
495
- // Skip broken symlinks (e.g., pointing to absolute paths on another machine)
496
- // instead of aborting the entire install.
497
- if (
498
- err instanceof Error &&
499
- 'code' in err &&
500
- (err as NodeJS.ErrnoException).code === 'ENOENT' &&
501
- entry.isSymbolicLink()
502
- ) {
503
- console.warn(`Skipping broken symlink: ${srcPath}`);
504
- } else {
505
- throw err;
506
- }
507
- }
508
- }
509
- })
510
- );
511
- }
512
-
513
- function isEvePackagedSkill(files: Array<{ path: string; contents?: string }>): boolean {
514
- return files.some((file) => basename(file.path).toLowerCase() === 'skill.md');
515
- }
516
-
517
- function toEveFlatSkillFileName(installName: string): string {
518
- return `${sanitizeName(installName)}.md`;
519
- }
520
-
521
- function getEveFlatSkillMarkdown(files: Array<{ path: string; contents: string }>): string {
522
- const skillFile = files.find((file) => basename(file.path).toLowerCase() === 'skill.md');
523
- if (skillFile) return stripIgnoredEveFrontmatter(skillFile.contents);
524
-
525
- const markdownFile = files.find((file) => extname(file.path).toLowerCase() === '.md');
526
- return markdownFile ? stripIgnoredEveFrontmatter(markdownFile.contents) : '';
527
- }
528
-
529
- export async function isSkillInstalled(
530
- skillName: string,
531
- agentType: AgentType,
532
- options: { global?: boolean; cwd?: string; eveSubagent?: string } = {}
533
- ): Promise<boolean> {
534
- const agent = agents[agentType];
535
- const sanitized = sanitizeName(skillName);
536
-
537
- // Agent doesn't support global installation
538
- if (options.global && agent.globalSkillsDir === undefined) {
539
- return false;
540
- }
541
-
542
- const targetBase = options.global
543
- ? agent.globalSkillsDir!
544
- : agentType === 'eve' && options.eveSubagent
545
- ? getEveSubagentSkillsDir(options.eveSubagent, options.cwd)
546
- : join(options.cwd || process.cwd(), agent.skillsDir);
547
-
548
- const skillDir = join(targetBase, sanitized);
549
-
550
- if (!isPathSafe(targetBase, skillDir)) {
551
- return false;
552
- }
553
-
554
- try {
555
- await access(skillDir);
556
- return true;
557
- } catch {
558
- return false;
559
- }
560
- }
561
-
562
- export function getInstallPath(
563
- skillName: string,
564
- agentType: AgentType,
565
- options: { global?: boolean; cwd?: string; eveSubagent?: string } = {}
566
- ): string {
567
- const agent = agents[agentType];
568
- const cwd = options.cwd || process.cwd();
569
- const sanitized = sanitizeName(skillName);
570
-
571
- const targetBase = getAgentBaseDir(
572
- agentType,
573
- options.global ?? false,
574
- options.cwd,
575
- options.eveSubagent
576
- );
577
- const installPath = join(targetBase, sanitized);
578
-
579
- if (!isPathSafe(targetBase, installPath)) {
580
- throw new Error('Invalid skill name: potential path traversal detected');
581
- }
582
-
583
- return installPath;
584
- }
585
-
586
- /**
587
- * Gets the canonical .agents/skills/<skill> path
588
- */
589
- export function getCanonicalPath(
590
- skillName: string,
591
- options: { global?: boolean; cwd?: string; agent?: AgentType; eveSubagent?: string } = {}
592
- ): string {
593
- const sanitized = sanitizeName(skillName);
594
- const canonicalBase =
595
- options.agent === 'eve'
596
- ? getAgentBaseDir('eve', options.global ?? false, options.cwd, options.eveSubagent)
597
- : getCanonicalSkillsDir(options.global ?? false, options.cwd);
598
- const canonicalPath = join(canonicalBase, sanitized);
599
-
600
- if (!isPathSafe(canonicalBase, canonicalPath)) {
601
- throw new Error('Invalid skill name: potential path traversal detected');
602
- }
603
-
604
- return canonicalPath;
605
- }
606
-
607
- /**
608
- * Install a remote skill from any host provider.
609
- * The skill directory name is derived from the installName field.
610
- * Supports symlink mode (writes to canonical location and symlinks to agent dirs)
611
- * or copy mode (writes directly to each agent dir).
612
- */
613
- export async function installRemoteSkillForAgent(
614
- skill: RemoteSkill,
615
- agentType: AgentType,
616
- options: { global?: boolean; cwd?: string; mode?: InstallMode; eveSubagent?: string } = {}
617
- ): Promise<InstallResult> {
618
- const agent = agents[agentType];
619
- const isGlobal = options.global ?? false;
620
- const cwd = options.cwd || process.cwd();
621
- const installMode = options.mode ?? 'symlink';
622
- const eveSubagent = options.eveSubagent;
623
-
624
- // Check if agent supports global installation
625
- if (isGlobal && agent.globalSkillsDir === undefined) {
626
- return {
627
- success: false,
628
- path: '',
629
- mode: installMode,
630
- error: `${agent.displayName} does not support global skill installation`,
631
- };
632
- }
633
-
634
- // Use installName as the skill directory name
635
- const skillName = sanitizeName(skill.installName);
636
-
637
- // Canonical location: .agents/skills/<skill-name>
638
- const canonicalBase =
639
- agentType === 'eve' && installMode === 'symlink'
640
- ? getAgentBaseDir(agentType, isGlobal, cwd, eveSubagent)
641
- : getCanonicalSkillsDir(isGlobal, cwd);
642
- const canonicalDir = join(canonicalBase, skillName);
643
-
644
- // Agent-specific location (for symlink)
645
- const agentBase = getAgentBaseDir(agentType, isGlobal, cwd, eveSubagent);
646
- const agentDir = join(agentBase, skillName);
647
-
648
- // Validate paths
649
- if (!isPathSafe(canonicalBase, canonicalDir)) {
650
- return {
651
- success: false,
652
- path: agentDir,
653
- mode: installMode,
654
- error: 'Invalid skill name: potential path traversal detected',
655
- };
656
- }
657
-
658
- if (!isPathSafe(agentBase, agentDir)) {
659
- return {
660
- success: false,
661
- path: agentDir,
662
- mode: installMode,
663
- error: 'Invalid skill name: potential path traversal detected',
664
- };
665
- }
666
-
667
- try {
668
- // For copy mode, write directly to agent location
669
- if (installMode === 'copy') {
670
- await cleanAndCreateDirectory(agentDir);
671
- const skillFileName =
672
- agentType === 'eve' ? toEveFlatSkillFileName(skill.installName) : 'SKILL.md';
673
- const skillMdPath = join(agentDir, skillFileName);
674
- await writeFile(
675
- skillMdPath,
676
- agentType === 'eve' ? stripIgnoredEveFrontmatter(skill.content) : skill.content,
677
- 'utf-8'
678
- );
679
-
680
- return {
681
- success: true,
682
- path: agentDir,
683
- mode: 'copy',
684
- };
685
- }
686
-
687
- // Symlink mode: write to canonical location and symlink to agent location
688
- await cleanAndCreateDirectory(canonicalDir);
689
- const skillFileName =
690
- agentType === 'eve' ? toEveFlatSkillFileName(skill.installName) : 'SKILL.md';
691
- const skillMdPath = join(canonicalDir, skillFileName);
692
- await writeFile(
693
- skillMdPath,
694
- agentType === 'eve' ? stripIgnoredEveFrontmatter(skill.content) : skill.content,
695
- 'utf-8'
696
- );
697
-
698
- // For universal agents with global install, skip creating agent-specific symlink
699
- if (isGlobal && isUniversalAgent(agentType)) {
700
- return {
701
- success: true,
702
- path: canonicalDir,
703
- canonicalPath: canonicalDir,
704
- mode: 'symlink',
705
- };
706
- }
707
-
708
- const symlinkCreated = await createSymlink(canonicalDir, agentDir);
709
-
710
- if (!symlinkCreated) {
711
- // Symlink failed, fall back to copy
712
- await cleanAndCreateDirectory(agentDir);
713
- const agentSkillFileName =
714
- agentType === 'eve' ? toEveFlatSkillFileName(skill.installName) : 'SKILL.md';
715
- const agentSkillMdPath = join(agentDir, agentSkillFileName);
716
- await writeFile(
717
- agentSkillMdPath,
718
- agentType === 'eve' ? stripIgnoredEveFrontmatter(skill.content) : skill.content,
719
- 'utf-8'
720
- );
721
-
722
- return {
723
- success: true,
724
- path: agentDir,
725
- canonicalPath: canonicalDir,
726
- mode: 'symlink',
727
- symlinkFailed: true,
728
- };
729
- }
730
-
731
- return {
732
- success: true,
733
- path: agentDir,
734
- canonicalPath: canonicalDir,
735
- mode: 'symlink',
736
- };
737
- } catch (error) {
738
- return {
739
- success: false,
740
- path: agentDir,
741
- mode: installMode,
742
- error: error instanceof Error ? error.message : 'Unknown error',
743
- };
744
- }
745
- }
746
-
747
- /**
748
- * Install a well-known skill with multiple files.
749
- * The skill directory name is derived from the installName field.
750
- * All files from the skill's files map are written to the installation directory.
751
- * Supports symlink mode (writes to canonical location and symlinks to agent dirs)
752
- * or copy mode (writes directly to each agent dir).
753
- */
754
- export async function installWellKnownSkillForAgent(
755
- skill: WellKnownSkill,
756
- agentType: AgentType,
757
- options: { global?: boolean; cwd?: string; mode?: InstallMode; eveSubagent?: string } = {}
758
- ): Promise<InstallResult> {
759
- const agent = agents[agentType];
760
- const isGlobal = options.global ?? false;
761
- const cwd = options.cwd || process.cwd();
762
- const installMode = options.mode ?? 'symlink';
763
- const eveSubagent = options.eveSubagent;
764
-
765
- // Check if agent supports global installation
766
- if (isGlobal && agent.globalSkillsDir === undefined) {
767
- return {
768
- success: false,
769
- path: '',
770
- mode: installMode,
771
- error: `${agent.displayName} does not support global skill installation`,
772
- };
773
- }
774
-
775
- // Use installName as the skill directory name
776
- const skillName = sanitizeName(skill.installName);
777
-
778
- // Canonical location: .agents/skills/<skill-name>
779
- const canonicalBase =
780
- agentType === 'eve' && installMode === 'symlink'
781
- ? getAgentBaseDir(agentType, isGlobal, cwd, eveSubagent)
782
- : getCanonicalSkillsDir(isGlobal, cwd);
783
- const canonicalDir = join(canonicalBase, skillName);
784
-
785
- // Agent-specific location (for symlink)
786
- const agentBase = getAgentBaseDir(agentType, isGlobal, cwd, eveSubagent);
787
- const agentDir = join(agentBase, skillName);
788
-
789
- // Validate paths
790
- if (!isPathSafe(canonicalBase, canonicalDir)) {
791
- return {
792
- success: false,
793
- path: agentDir,
794
- mode: installMode,
795
- error: 'Invalid skill name: potential path traversal detected',
796
- };
797
- }
798
-
799
- if (!isPathSafe(agentBase, agentDir)) {
800
- return {
801
- success: false,
802
- path: agentDir,
803
- mode: installMode,
804
- error: 'Invalid skill name: potential path traversal detected',
805
- };
806
- }
807
-
808
- /**
809
- * Write all skill files to a directory (assumes directory already exists)
810
- */
811
- async function writeSkillFiles(targetDir: string): Promise<void> {
812
- for (const [filePath, content] of skill.files) {
813
- // Validate file path doesn't escape the target directory
814
- const fullPath = join(targetDir, filePath);
815
- if (!isPathSafe(targetDir, fullPath)) {
816
- continue; // Skip files that would escape the directory
817
- }
818
-
819
- // Create parent directories if needed
820
- const parentDir = dirname(fullPath);
821
- if (parentDir !== targetDir) {
822
- await mkdir(parentDir, { recursive: true });
823
- }
824
-
825
- await writeFile(
826
- fullPath,
827
- agentType === 'eve' &&
828
- basename(filePath).toLowerCase() === 'skill.md' &&
829
- typeof content === 'string'
830
- ? stripIgnoredEveFrontmatter(content)
831
- : content
832
- );
833
- }
834
- }
835
-
836
- try {
837
- // For copy mode, write directly to agent location
838
- if (installMode === 'copy') {
839
- await cleanAndCreateDirectory(agentDir);
840
- await writeSkillFiles(agentDir);
841
-
842
- return {
843
- success: true,
844
- path: agentDir,
845
- mode: 'copy',
846
- };
847
- }
848
-
849
- // Symlink mode: write to canonical location and symlink to agent location
850
- await cleanAndCreateDirectory(canonicalDir);
851
- await writeSkillFiles(canonicalDir);
852
-
853
- // For universal agents with global install, skip creating agent-specific symlink
854
- if (isGlobal && isUniversalAgent(agentType)) {
855
- return {
856
- success: true,
857
- path: canonicalDir,
858
- canonicalPath: canonicalDir,
859
- mode: 'symlink',
860
- };
861
- }
862
-
863
- const symlinkCreated = await createSymlink(canonicalDir, agentDir);
864
-
865
- if (!symlinkCreated) {
866
- // Symlink failed, fall back to copy
867
- await cleanAndCreateDirectory(agentDir);
868
- await writeSkillFiles(agentDir);
869
-
870
- return {
871
- success: true,
872
- path: agentDir,
873
- canonicalPath: canonicalDir,
874
- mode: 'symlink',
875
- symlinkFailed: true,
876
- };
877
- }
878
-
879
- return {
880
- success: true,
881
- path: agentDir,
882
- canonicalPath: canonicalDir,
883
- mode: 'symlink',
884
- };
885
- } catch (error) {
886
- return {
887
- success: false,
888
- path: agentDir,
889
- mode: installMode,
890
- error: error instanceof Error ? error.message : 'Unknown error',
891
- };
892
- }
893
- }
894
-
895
- /**
896
- * Install a blob-downloaded skill (fetched from skills.sh download API).
897
- * Similar to installWellKnownSkillForAgent but takes the snapshot file format
898
- * (array of { path, contents }) instead of a Map.
899
- */
900
- export async function installBlobSkillForAgent(
901
- skill: { installName: string; files: Array<{ path: string; contents: string }> },
902
- agentType: AgentType,
903
- options: { global?: boolean; cwd?: string; mode?: InstallMode; eveSubagent?: string } = {}
904
- ): Promise<InstallResult> {
905
- const agent = agents[agentType];
906
- const isGlobal = options.global ?? false;
907
- const cwd = options.cwd || process.cwd();
908
- const installMode = options.mode ?? 'symlink';
909
- const eveSubagent = options.eveSubagent;
910
-
911
- if (isGlobal && agent.globalSkillsDir === undefined) {
912
- return {
913
- success: false,
914
- path: '',
915
- mode: installMode,
916
- error: `${agent.displayName} does not support global skill installation`,
917
- };
918
- }
919
-
920
- const skillName = sanitizeName(skill.installName);
921
- const agentBase = getAgentBaseDir(agentType, isGlobal, cwd, eveSubagent);
922
-
923
- if (agentType === 'eve' && !isEvePackagedSkill(skill.files)) {
924
- const flatSkillPath = join(agentBase, toEveFlatSkillFileName(skill.installName));
925
- if (!isPathSafe(agentBase, flatSkillPath)) {
926
- return {
927
- success: false,
928
- path: flatSkillPath,
929
- mode: installMode,
930
- error: 'Invalid skill name: potential path traversal detected',
931
- };
932
- }
933
-
934
- try {
935
- await mkdir(agentBase, { recursive: true });
936
- await rm(flatSkillPath, { recursive: true, force: true });
937
- await writeFile(flatSkillPath, getEveFlatSkillMarkdown(skill.files), 'utf-8');
938
- return { success: true, path: flatSkillPath, mode: 'copy' };
939
- } catch (error) {
940
- return {
941
- success: false,
942
- path: flatSkillPath,
943
- mode: installMode,
944
- error: error instanceof Error ? error.message : 'Unknown error',
945
- };
946
- }
947
- }
948
-
949
- const canonicalBase =
950
- agentType === 'eve' && installMode === 'symlink'
951
- ? getAgentBaseDir(agentType, isGlobal, cwd, eveSubagent)
952
- : getCanonicalSkillsDir(isGlobal, cwd);
953
- const canonicalDir = join(canonicalBase, skillName);
954
- const agentDir = join(agentBase, skillName);
955
-
956
- if (!isPathSafe(canonicalBase, canonicalDir)) {
957
- return {
958
- success: false,
959
- path: agentDir,
960
- mode: installMode,
961
- error: 'Invalid skill name: potential path traversal detected',
962
- };
963
- }
964
-
965
- if (!isPathSafe(agentBase, agentDir)) {
966
- return {
967
- success: false,
968
- path: agentDir,
969
- mode: installMode,
970
- error: 'Invalid skill name: potential path traversal detected',
971
- };
972
- }
973
-
974
- async function writeSkillFiles(targetDir: string): Promise<void> {
975
- for (const file of skill.files) {
976
- const fullPath = join(targetDir, file.path);
977
- if (!isPathSafe(targetDir, fullPath)) continue;
978
-
979
- const parentDir = dirname(fullPath);
980
- if (parentDir !== targetDir) {
981
- await mkdir(parentDir, { recursive: true });
982
- }
983
-
984
- await writeFile(
985
- fullPath,
986
- agentType === 'eve' && basename(file.path).toLowerCase() === 'skill.md'
987
- ? stripIgnoredEveFrontmatter(file.contents)
988
- : file.contents,
989
- 'utf-8'
990
- );
991
- }
992
- }
993
-
994
- try {
995
- if (installMode === 'copy') {
996
- await cleanAndCreateDirectory(agentDir);
997
- await writeSkillFiles(agentDir);
998
- return { success: true, path: agentDir, mode: 'copy' };
999
- }
1000
-
1001
- // Symlink mode
1002
- await cleanAndCreateDirectory(canonicalDir);
1003
- await writeSkillFiles(canonicalDir);
1004
-
1005
- if (isGlobal && isUniversalAgent(agentType)) {
1006
- return {
1007
- success: true,
1008
- path: canonicalDir,
1009
- canonicalPath: canonicalDir,
1010
- mode: 'symlink',
1011
- };
1012
- }
1013
-
1014
- // For project-level installs, skip creating symlinks for non-universal agents
1015
- // whose config directory doesn't already exist in the project.
1016
- if (!isGlobal && !isUniversalAgent(agentType)) {
1017
- const agentRootDir = join(cwd, agents[agentType].skillsDir.split('/')[0]!);
1018
- if (!existsSync(agentRootDir)) {
1019
- return {
1020
- success: true,
1021
- path: canonicalDir,
1022
- canonicalPath: canonicalDir,
1023
- mode: 'symlink',
1024
- skipped: true,
1025
- };
1026
- }
1027
- }
1028
-
1029
- const symlinkCreated = await createSymlink(canonicalDir, agentDir);
1030
-
1031
- if (!symlinkCreated) {
1032
- await cleanAndCreateDirectory(agentDir);
1033
- await writeSkillFiles(agentDir);
1034
- return {
1035
- success: true,
1036
- path: agentDir,
1037
- canonicalPath: canonicalDir,
1038
- mode: 'symlink',
1039
- symlinkFailed: true,
1040
- };
1041
- }
1042
-
1043
- return {
1044
- success: true,
1045
- path: agentDir,
1046
- canonicalPath: canonicalDir,
1047
- mode: 'symlink',
1048
- };
1049
- } catch (error) {
1050
- return {
1051
- success: false,
1052
- path: agentDir,
1053
- mode: installMode,
1054
- error: error instanceof Error ? error.message : 'Unknown error',
1055
- };
1056
- }
1057
- }
1058
-
1059
- export interface InstalledSkill {
1060
- name: string;
1061
- description: string;
1062
- path: string;
1063
- canonicalPath: string;
1064
- scope: 'project' | 'global';
1065
- agents: AgentType[];
1066
- }
1067
-
1068
- /**
1069
- * Lists all installed skills from canonical locations
1070
- * @param options - Options for listing skills
1071
- * @returns Array of installed skills with metadata
1072
- */
1073
- export async function listInstalledSkills(
1074
- options: {
1075
- global?: boolean;
1076
- cwd?: string;
1077
- agentFilter?: AgentType[];
1078
- } = {}
1079
- ): Promise<InstalledSkill[]> {
1080
- const cwd = options.cwd || process.cwd();
1081
- // Use a Map to deduplicate skills by scope:name
1082
- const skillsMap: Map<string, InstalledSkill> = new Map();
1083
- const scopes: Array<{ global: boolean; path: string; agentType?: AgentType }> = [];
1084
-
1085
- // Detect which agents are actually installed
1086
- const detectedAgents = await detectInstalledAgents();
1087
- const agentFilter = options.agentFilter;
1088
- const agentsToCheck = agentFilter
1089
- ? detectedAgents.filter((a) => agentFilter.includes(a))
1090
- : detectedAgents;
1091
-
1092
- // Determine which scopes to scan
1093
- const scopeTypes: Array<{ global: boolean }> = [];
1094
- if (options.global === undefined) {
1095
- scopeTypes.push({ global: false }, { global: true });
1096
- } else {
1097
- scopeTypes.push({ global: options.global });
1098
- }
1099
-
1100
- // Build list of directories to scan: canonical + each installed agent's directory
1101
- //
1102
- // Scanning workflow:
1103
- //
1104
- // detectInstalledAgents()
1105
- // │
1106
- // ▼
1107
- // for each scope (project / global)
1108
- // │
1109
- // ├──▶ scan canonical dir ──▶ .agents/skills, ~/.agents/skills
1110
- // │
1111
- // ├──▶ scan each installed agent's dir ──▶ .cursor/skills, .claude/skills, ...
1112
- // │
1113
- // ▼
1114
- // deduplicate by skill name
1115
- //
1116
- // Trade-off: More readdir() calls, but most non-existent dirs fail fast.
1117
- // Skills in agent-specific dirs skip the expensive "check all agents" loop.
1118
- //
1119
- for (const { global: isGlobal } of scopeTypes) {
1120
- // Add canonical directory
1121
- scopes.push({ global: isGlobal, path: getCanonicalSkillsDir(isGlobal, cwd) });
1122
-
1123
- // Add each installed agent's skills directory
1124
- for (const agentType of agentsToCheck) {
1125
- const agent = agents[agentType];
1126
- if (isGlobal && agent.globalSkillsDir === undefined) {
1127
- continue;
1128
- }
1129
- const agentDir = isGlobal ? agent.globalSkillsDir! : join(cwd, agent.skillsDir);
1130
- // Avoid duplicate paths
1131
- if (!scopes.some((s) => s.path === agentDir && s.global === isGlobal)) {
1132
- scopes.push({ global: isGlobal, path: agentDir, agentType });
1133
- }
1134
-
1135
- // Eve subagents keep their skills under agent/subagents/<name>/skills.
1136
- // These are project-scoped, so only scan them for the project scope.
1137
- if (agentType === 'eve' && !isGlobal) {
1138
- for (const subagent of getEveSubagents(cwd)) {
1139
- const subagentDir = getEveSubagentSkillsDir(subagent, cwd);
1140
- if (!scopes.some((s) => s.path === subagentDir && s.global === isGlobal)) {
1141
- scopes.push({ global: isGlobal, path: subagentDir, agentType });
1142
- }
1143
- }
1144
- }
1145
- }
1146
-
1147
- // Also scan skill directories for agents NOT in agentsToCheck, in case
1148
- // skills were installed with `--agent <name>` but the agent is no longer
1149
- // detected (e.g. ~/.openclaw was removed). Only add dirs that actually
1150
- // exist on disk to avoid unnecessary readdir errors.
1151
- const allAgentTypes = Object.keys(agents) as AgentType[];
1152
- for (const agentType of allAgentTypes) {
1153
- if (agentsToCheck.includes(agentType)) continue;
1154
- const agent = agents[agentType];
1155
- if (isGlobal && agent.globalSkillsDir === undefined) continue;
1156
- const agentDir = isGlobal ? agent.globalSkillsDir! : join(cwd, agent.skillsDir);
1157
- if (scopes.some((s) => s.path === agentDir && s.global === isGlobal)) continue;
1158
- if (existsSync(agentDir)) {
1159
- scopes.push({ global: isGlobal, path: agentDir, agentType });
1160
- }
1161
- }
1162
- }
1163
-
1164
- for (const scope of scopes) {
1165
- try {
1166
- const entries = await readdir(scope.path, { withFileTypes: true });
1167
-
1168
- for (const entry of entries) {
1169
- const skillDir = join(scope.path, entry.name);
1170
- if (!(await isDirEntryOrSymlinkToDir(entry, skillDir))) continue;
1171
-
1172
- const skillMdPath = join(skillDir, 'SKILL.md');
1173
-
1174
- // Check if SKILL.md exists
1175
- try {
1176
- await stat(skillMdPath);
1177
- } catch {
1178
- // SKILL.md doesn't exist, skip this directory
1179
- continue;
1180
- }
1181
-
1182
- // Parse the skill
1183
- const skill = await parseSkillMd(skillMdPath);
1184
- if (!skill) {
1185
- continue;
1186
- }
1187
-
1188
- const scopeKey = scope.global ? 'global' : 'project';
1189
- const skillKey = `${scopeKey}:${skill.name}`;
1190
-
1191
- // If scanning an agent-specific directory, attribute directly to that agent
1192
- if (scope.agentType) {
1193
- if (skillsMap.has(skillKey)) {
1194
- const existing = skillsMap.get(skillKey)!;
1195
- if (!existing.agents.includes(scope.agentType)) {
1196
- existing.agents.push(scope.agentType);
1197
- }
1198
- } else {
1199
- skillsMap.set(skillKey, {
1200
- name: skill.name,
1201
- description: skill.description,
1202
- path: skillDir,
1203
- canonicalPath: skillDir,
1204
- scope: scopeKey,
1205
- agents: [scope.agentType],
1206
- });
1207
- }
1208
- continue;
1209
- }
1210
-
1211
- // For canonical directory, check which agents have this skill
1212
- const sanitizedSkillName = sanitizeName(skill.name);
1213
- const installedAgents: AgentType[] = [];
1214
-
1215
- for (const agentType of agentsToCheck) {
1216
- const agent = agents[agentType];
1217
-
1218
- if (scope.global && agent.globalSkillsDir === undefined) {
1219
- continue;
1220
- }
1221
-
1222
- const agentBase = getAgentBaseDir(agentType, scope.global, cwd);
1223
- let found = false;
1224
-
1225
- // Try exact directory name matches
1226
- const possibleNames = Array.from(
1227
- new Set([
1228
- entry.name,
1229
- sanitizedSkillName,
1230
- skill.name
1231
- .toLowerCase()
1232
- .replace(/\s+/g, '-')
1233
- .replace(/[\/\\:\0]/g, ''),
1234
- ])
1235
- );
1236
-
1237
- for (const possibleName of possibleNames) {
1238
- const agentSkillDir = join(agentBase, possibleName);
1239
- if (!isPathSafe(agentBase, agentSkillDir)) continue;
1240
-
1241
- try {
1242
- await access(agentSkillDir);
1243
- found = true;
1244
- break;
1245
- } catch {
1246
- // Try next name
1247
- }
1248
- }
1249
-
1250
- // Fallback: scan all directories and check SKILL.md files
1251
- // Handles cases where directory names don't match (e.g., "git-review" vs "Git Review Before Commit")
1252
- if (!found) {
1253
- try {
1254
- const agentEntries = await readdir(agentBase, { withFileTypes: true });
1255
- for (const agentEntry of agentEntries) {
1256
- const candidateDir = join(agentBase, agentEntry.name);
1257
- if (!(await isDirEntryOrSymlinkToDir(agentEntry, candidateDir))) continue;
1258
- if (!isPathSafe(agentBase, candidateDir)) continue;
1259
-
1260
- try {
1261
- const candidateSkillMd = join(candidateDir, 'SKILL.md');
1262
- await stat(candidateSkillMd);
1263
- const candidateSkill = await parseSkillMd(candidateSkillMd);
1264
- if (candidateSkill && candidateSkill.name === skill.name) {
1265
- found = true;
1266
- break;
1267
- }
1268
- } catch {
1269
- // Not a valid skill directory
1270
- }
1271
- }
1272
- } catch {
1273
- // Agent base directory doesn't exist
1274
- }
1275
- }
1276
-
1277
- if (found) {
1278
- installedAgents.push(agentType);
1279
- }
1280
- }
1281
-
1282
- if (skillsMap.has(skillKey)) {
1283
- // Merge agents
1284
- const existing = skillsMap.get(skillKey)!;
1285
- for (const agent of installedAgents) {
1286
- if (!existing.agents.includes(agent)) {
1287
- existing.agents.push(agent);
1288
- }
1289
- }
1290
- } else {
1291
- skillsMap.set(skillKey, {
1292
- name: skill.name,
1293
- description: skill.description,
1294
- path: skillDir,
1295
- canonicalPath: skillDir,
1296
- scope: scopeKey,
1297
- agents: installedAgents,
1298
- });
1299
- }
1300
- }
1301
- } catch {
1302
- // Directory doesn't exist, skip
1303
- }
1304
- }
1305
-
1306
- return Array.from(skillsMap.values());
1307
- }