skills 1.0.12 → 1.0.14
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.
- package/dist/cli.js +211 -6
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
// src/cli.ts
|
|
4
|
-
import { spawn } from "child_process";
|
|
4
|
+
import { spawn, spawnSync } from "child_process";
|
|
5
5
|
import {
|
|
6
6
|
writeFileSync,
|
|
7
7
|
readFileSync,
|
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
} from "fs";
|
|
13
13
|
import { basename, join } from "path";
|
|
14
14
|
import { homedir } from "os";
|
|
15
|
+
import { createHash } from "crypto";
|
|
15
16
|
var RESET = "\x1B[0m";
|
|
16
17
|
var BOLD = "\x1B[1m";
|
|
17
18
|
var DIM = "\x1B[38;5;102m";
|
|
@@ -43,9 +44,10 @@ function showBanner() {
|
|
|
43
44
|
console.log();
|
|
44
45
|
console.log(`${DIM}The open agent skills ecosystem${RESET}`);
|
|
45
46
|
console.log();
|
|
46
|
-
console.log(` ${DIM}$${RESET} ${TEXT}npx skills
|
|
47
|
-
console.log(` ${DIM}$${RESET} ${TEXT}npx skills
|
|
48
|
-
console.log(` ${DIM}$${RESET} ${TEXT}npx skills
|
|
47
|
+
console.log(` ${DIM}$${RESET} ${TEXT}npx skills add ${DIM}<package>${RESET} ${DIM}Install a skill${RESET}`);
|
|
48
|
+
console.log(` ${DIM}$${RESET} ${TEXT}npx skills check${RESET} ${DIM}Check for updates${RESET}`);
|
|
49
|
+
console.log(` ${DIM}$${RESET} ${TEXT}npx skills update${RESET} ${DIM}Update all skills${RESET}`);
|
|
50
|
+
console.log(` ${DIM}$${RESET} ${TEXT}npx skills init ${DIM}[name]${RESET} ${DIM}Create a new skill${RESET}`);
|
|
49
51
|
console.log();
|
|
50
52
|
console.log(`${DIM}try:${RESET} npx skills add vercel-labs/agent-skills`);
|
|
51
53
|
console.log();
|
|
@@ -61,16 +63,21 @@ ${BOLD}Commands:${RESET}
|
|
|
61
63
|
add <package> Add a skill package
|
|
62
64
|
e.g. vercel-labs/agent-skills
|
|
63
65
|
https://github.com/vercel-labs/agent-skills
|
|
66
|
+
check Check for available skill updates
|
|
67
|
+
update Update all skills to latest versions
|
|
64
68
|
generate-lock Generate lock file from installed skills
|
|
65
69
|
|
|
66
70
|
${BOLD}Options:${RESET}
|
|
67
71
|
--help, -h Show this help message
|
|
68
72
|
--version, -v Show version number
|
|
73
|
+
--refresh, -r Force refresh from source (check)
|
|
69
74
|
--dry-run Preview changes without writing (generate-lock)
|
|
70
75
|
|
|
71
76
|
${BOLD}Examples:${RESET}
|
|
72
77
|
${DIM}$${RESET} skills init my-skill
|
|
73
78
|
${DIM}$${RESET} skills add vercel-labs/agent-skills
|
|
79
|
+
${DIM}$${RESET} skills check
|
|
80
|
+
${DIM}$${RESET} skills update
|
|
74
81
|
${DIM}$${RESET} skills generate-lock --dry-run
|
|
75
82
|
|
|
76
83
|
Discover more skills at ${TEXT}https://skills.sh/${RESET}
|
|
@@ -178,6 +185,8 @@ var AGENTS_DIR = ".agents";
|
|
|
178
185
|
var SKILLS_SUBDIR = "skills";
|
|
179
186
|
var LOCK_FILE = ".skill-lock.json";
|
|
180
187
|
var SEARCH_API_URL = "https://skills.sh/api/skills/search";
|
|
188
|
+
var CHECK_UPDATES_API_URL = "https://add-skill.vercel.sh/check-updates";
|
|
189
|
+
var CURRENT_LOCK_VERSION = 2;
|
|
181
190
|
function getSkillLockPath() {
|
|
182
191
|
return join(homedir(), AGENTS_DIR, LOCK_FILE);
|
|
183
192
|
}
|
|
@@ -187,11 +196,14 @@ function readSkillLock() {
|
|
|
187
196
|
const content = readFileSync(lockPath, "utf-8");
|
|
188
197
|
const parsed = JSON.parse(content);
|
|
189
198
|
if (typeof parsed.version !== "number" || !parsed.skills) {
|
|
190
|
-
return { version:
|
|
199
|
+
return { version: CURRENT_LOCK_VERSION, skills: {} };
|
|
200
|
+
}
|
|
201
|
+
if (parsed.version < CURRENT_LOCK_VERSION) {
|
|
202
|
+
return { version: CURRENT_LOCK_VERSION, skills: {} };
|
|
191
203
|
}
|
|
192
204
|
return parsed;
|
|
193
205
|
} catch {
|
|
194
|
-
return { version:
|
|
206
|
+
return { version: CURRENT_LOCK_VERSION, skills: {} };
|
|
195
207
|
}
|
|
196
208
|
}
|
|
197
209
|
function writeSkillLock(lock) {
|
|
@@ -301,6 +313,7 @@ async function runGenerateLock(args) {
|
|
|
301
313
|
source: match.source,
|
|
302
314
|
sourceType,
|
|
303
315
|
sourceUrl,
|
|
316
|
+
contentHash: "",
|
|
304
317
|
installedAt: now,
|
|
305
318
|
updatedAt: now
|
|
306
319
|
};
|
|
@@ -325,6 +338,187 @@ async function runGenerateLock(args) {
|
|
|
325
338
|
console.log(`${TEXT}Lock file updated:${RESET} ${DIM}~/.agents/.skill-lock.json${RESET}`);
|
|
326
339
|
}
|
|
327
340
|
}
|
|
341
|
+
function computeContentHash(content) {
|
|
342
|
+
return createHash("sha256").update(content, "utf-8").digest("hex");
|
|
343
|
+
}
|
|
344
|
+
function getSkillContentPath(skillName) {
|
|
345
|
+
return join(homedir(), AGENTS_DIR, SKILLS_SUBDIR, skillName, "SKILL.md");
|
|
346
|
+
}
|
|
347
|
+
function readSkillContent(skillName) {
|
|
348
|
+
const skillPath = getSkillContentPath(skillName);
|
|
349
|
+
try {
|
|
350
|
+
return readFileSync(skillPath, "utf-8");
|
|
351
|
+
} catch {
|
|
352
|
+
return null;
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
async function runCheck(args = []) {
|
|
356
|
+
const forceRefresh = args.includes("--refresh") || args.includes("-r");
|
|
357
|
+
console.log(`${TEXT}Checking for skill updates...${RESET}`);
|
|
358
|
+
console.log();
|
|
359
|
+
const lock = readSkillLock();
|
|
360
|
+
const skillNames = Object.keys(lock.skills);
|
|
361
|
+
if (skillNames.length === 0) {
|
|
362
|
+
console.log(`${DIM}No skills tracked in lock file.${RESET}`);
|
|
363
|
+
console.log(`${DIM}Install skills with${RESET} ${TEXT}npx skills add <package>${RESET}`);
|
|
364
|
+
return;
|
|
365
|
+
}
|
|
366
|
+
const checkRequest = {
|
|
367
|
+
skills: []
|
|
368
|
+
};
|
|
369
|
+
if (forceRefresh) {
|
|
370
|
+
checkRequest.forceRefresh = true;
|
|
371
|
+
}
|
|
372
|
+
for (const skillName of skillNames) {
|
|
373
|
+
const entry = lock.skills[skillName];
|
|
374
|
+
if (!entry)
|
|
375
|
+
continue;
|
|
376
|
+
let contentHash = entry.contentHash;
|
|
377
|
+
if (!contentHash) {
|
|
378
|
+
const content = readSkillContent(skillName);
|
|
379
|
+
if (content) {
|
|
380
|
+
contentHash = computeContentHash(content);
|
|
381
|
+
} else {
|
|
382
|
+
console.log(`${DIM}Skipping ${skillName}: cannot read SKILL.md${RESET}`);
|
|
383
|
+
continue;
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
checkRequest.skills.push({
|
|
387
|
+
name: skillName,
|
|
388
|
+
source: entry.source,
|
|
389
|
+
path: entry.skillPath,
|
|
390
|
+
contentHash
|
|
391
|
+
});
|
|
392
|
+
}
|
|
393
|
+
if (checkRequest.skills.length === 0) {
|
|
394
|
+
console.log(`${DIM}No skills to check.${RESET}`);
|
|
395
|
+
return;
|
|
396
|
+
}
|
|
397
|
+
console.log(`${DIM}Checking ${checkRequest.skills.length} skill(s) for updates...${RESET}`);
|
|
398
|
+
try {
|
|
399
|
+
const response = await fetch(CHECK_UPDATES_API_URL, {
|
|
400
|
+
method: "POST",
|
|
401
|
+
headers: { "Content-Type": "application/json" },
|
|
402
|
+
body: JSON.stringify(checkRequest)
|
|
403
|
+
});
|
|
404
|
+
if (!response.ok) {
|
|
405
|
+
throw new Error(`API error: ${response.status} ${response.statusText}`);
|
|
406
|
+
}
|
|
407
|
+
const data = await response.json();
|
|
408
|
+
console.log();
|
|
409
|
+
if (data.updates.length === 0) {
|
|
410
|
+
console.log(`${TEXT}✓ All skills are up to date${RESET}`);
|
|
411
|
+
} else {
|
|
412
|
+
console.log(`${TEXT}${data.updates.length} update(s) available:${RESET}`);
|
|
413
|
+
console.log();
|
|
414
|
+
for (const update of data.updates) {
|
|
415
|
+
console.log(` ${TEXT}↑${RESET} ${update.name}`);
|
|
416
|
+
console.log(` ${DIM}source: ${update.source}${RESET}`);
|
|
417
|
+
}
|
|
418
|
+
console.log();
|
|
419
|
+
console.log(`${DIM}Run${RESET} ${TEXT}npx skills update${RESET} ${DIM}to update all skills${RESET}`);
|
|
420
|
+
}
|
|
421
|
+
if (data.errors && data.errors.length > 0) {
|
|
422
|
+
console.log();
|
|
423
|
+
console.log(`${DIM}Could not check ${data.errors.length} skill(s):${RESET}`);
|
|
424
|
+
for (const err of data.errors) {
|
|
425
|
+
console.log(` ${DIM}${err.name}: ${err.error}${RESET}`);
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
} catch (error) {
|
|
429
|
+
console.log(`${TEXT}Error checking for updates:${RESET} ${error instanceof Error ? error.message : "Unknown error"}`);
|
|
430
|
+
process.exit(1);
|
|
431
|
+
}
|
|
432
|
+
console.log();
|
|
433
|
+
}
|
|
434
|
+
async function runUpdate() {
|
|
435
|
+
console.log(`${TEXT}Checking for skill updates...${RESET}`);
|
|
436
|
+
console.log();
|
|
437
|
+
const lock = readSkillLock();
|
|
438
|
+
const skillNames = Object.keys(lock.skills);
|
|
439
|
+
if (skillNames.length === 0) {
|
|
440
|
+
console.log(`${DIM}No skills tracked in lock file.${RESET}`);
|
|
441
|
+
console.log(`${DIM}Install skills with${RESET} ${TEXT}npx skills add <package>${RESET}`);
|
|
442
|
+
return;
|
|
443
|
+
}
|
|
444
|
+
const checkRequest = {
|
|
445
|
+
skills: [],
|
|
446
|
+
forceRefresh: true
|
|
447
|
+
};
|
|
448
|
+
for (const skillName of skillNames) {
|
|
449
|
+
const entry = lock.skills[skillName];
|
|
450
|
+
if (!entry)
|
|
451
|
+
continue;
|
|
452
|
+
let contentHash = entry.contentHash;
|
|
453
|
+
if (!contentHash) {
|
|
454
|
+
const content = readSkillContent(skillName);
|
|
455
|
+
if (content) {
|
|
456
|
+
contentHash = computeContentHash(content);
|
|
457
|
+
} else {
|
|
458
|
+
continue;
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
checkRequest.skills.push({
|
|
462
|
+
name: skillName,
|
|
463
|
+
source: entry.source,
|
|
464
|
+
path: entry.skillPath,
|
|
465
|
+
contentHash
|
|
466
|
+
});
|
|
467
|
+
}
|
|
468
|
+
if (checkRequest.skills.length === 0) {
|
|
469
|
+
console.log(`${DIM}No skills to check.${RESET}`);
|
|
470
|
+
return;
|
|
471
|
+
}
|
|
472
|
+
let updates = [];
|
|
473
|
+
try {
|
|
474
|
+
const response = await fetch(CHECK_UPDATES_API_URL, {
|
|
475
|
+
method: "POST",
|
|
476
|
+
headers: { "Content-Type": "application/json" },
|
|
477
|
+
body: JSON.stringify(checkRequest)
|
|
478
|
+
});
|
|
479
|
+
if (!response.ok) {
|
|
480
|
+
throw new Error(`API error: ${response.status} ${response.statusText}`);
|
|
481
|
+
}
|
|
482
|
+
const data = await response.json();
|
|
483
|
+
updates = data.updates;
|
|
484
|
+
} catch (error) {
|
|
485
|
+
console.log(`${TEXT}Error checking for updates:${RESET} ${error instanceof Error ? error.message : "Unknown error"}`);
|
|
486
|
+
process.exit(1);
|
|
487
|
+
}
|
|
488
|
+
if (updates.length === 0) {
|
|
489
|
+
console.log(`${TEXT}✓ All skills are up to date${RESET}`);
|
|
490
|
+
console.log();
|
|
491
|
+
return;
|
|
492
|
+
}
|
|
493
|
+
console.log(`${TEXT}Found ${updates.length} update(s)${RESET}`);
|
|
494
|
+
console.log();
|
|
495
|
+
let successCount = 0;
|
|
496
|
+
let failCount = 0;
|
|
497
|
+
for (const update of updates) {
|
|
498
|
+
const entry = lock.skills[update.name];
|
|
499
|
+
if (!entry)
|
|
500
|
+
continue;
|
|
501
|
+
console.log(`${TEXT}Updating ${update.name}...${RESET}`);
|
|
502
|
+
const result = spawnSync("npx", ["-y", "add-skill", entry.sourceUrl, "--skill", update.name, "-g", "-y"], {
|
|
503
|
+
stdio: ["inherit", "pipe", "pipe"]
|
|
504
|
+
});
|
|
505
|
+
if (result.status === 0) {
|
|
506
|
+
successCount++;
|
|
507
|
+
console.log(` ${TEXT}✓${RESET} Updated ${update.name}`);
|
|
508
|
+
} else {
|
|
509
|
+
failCount++;
|
|
510
|
+
console.log(` ${DIM}✗ Failed to update ${update.name}${RESET}`);
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
console.log();
|
|
514
|
+
if (successCount > 0) {
|
|
515
|
+
console.log(`${TEXT}✓ Updated ${successCount} skill(s)${RESET}`);
|
|
516
|
+
}
|
|
517
|
+
if (failCount > 0) {
|
|
518
|
+
console.log(`${DIM}Failed to update ${failCount} skill(s)${RESET}`);
|
|
519
|
+
}
|
|
520
|
+
console.log();
|
|
521
|
+
}
|
|
328
522
|
function main() {
|
|
329
523
|
const args = process.argv.slice(2);
|
|
330
524
|
if (args.length === 0) {
|
|
@@ -347,6 +541,17 @@ function main() {
|
|
|
347
541
|
console.log();
|
|
348
542
|
runAddSkill(restArgs);
|
|
349
543
|
break;
|
|
544
|
+
case "check":
|
|
545
|
+
showLogo();
|
|
546
|
+
console.log();
|
|
547
|
+
runCheck(restArgs);
|
|
548
|
+
break;
|
|
549
|
+
case "update":
|
|
550
|
+
case "upgrade":
|
|
551
|
+
showLogo();
|
|
552
|
+
console.log();
|
|
553
|
+
runUpdate();
|
|
554
|
+
break;
|
|
350
555
|
case "generate-lock":
|
|
351
556
|
case "gen-lock":
|
|
352
557
|
showLogo();
|