@workingpayload/agent-skills 2.0.1 → 2.1.0

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/bin/cli.js CHANGED
@@ -1,436 +1,533 @@
1
- #!/usr/bin/env node
2
-
3
- const { execSync, spawnSync } = require("child_process");
4
- const fs = require("fs");
5
- const path = require("path");
6
- const os = require("os");
7
-
8
- // ── Resolve paths ──────────────────────────────────────────────────
9
- const PKG_ROOT = path.resolve(__dirname, "..");
10
- const SCRIPTS_DIR = path.join(PKG_ROOT, "scripts");
11
- const HOME = os.homedir();
12
-
13
- const TARGETS = {
14
- claude: path.join(HOME, ".claude", "commands"),
15
- gemini: path.join(HOME, ".gemini", "commands"),
16
- antigravity: path.join(HOME, ".gemini", "antigravity", "skills"),
17
- };
18
-
19
- // ── Helpers ────────────────────────────────────────────────────────
20
- function hasPython() {
21
- for (const cmd of ["python3", "python"]) {
22
- try {
23
- execSync(`${cmd} --version`, { stdio: "ignore" });
24
- return cmd;
25
- } catch (_) {}
26
- }
27
- return null;
28
- }
29
-
30
- function runPythonScript(scriptName, args = []) {
31
- const py = hasPython();
32
- if (!py) {
33
- console.error("Error: Python 3 is required but not found in PATH.");
34
- console.error("Install Python 3: https://python.org/downloads/");
35
- process.exit(1);
36
- }
37
- const scriptPath = path.join(SCRIPTS_DIR, scriptName);
38
- if (!fs.existsSync(scriptPath)) {
39
- console.error(`Error: Script not found: ${scriptPath}`);
40
- process.exit(1);
41
- }
42
- const result = spawnSync(py, [scriptPath, ...args], {
43
- stdio: "inherit",
44
- cwd: PKG_ROOT,
45
- });
46
- process.exit(result.status || 0);
47
- }
48
-
49
- function findSkillFiles() {
50
- const skills = [];
51
- const entries = fs.readdirSync(PKG_ROOT, { withFileTypes: true });
52
- for (const entry of entries) {
53
- if (!entry.isDirectory() || entry.name.startsWith(".") || entry.name === "node_modules" || entry.name === "bin" || entry.name === "scripts") continue;
54
- const dir = path.join(PKG_ROOT, entry.name);
55
- for (const fname of ["skill.md", "SKILL.md"]) {
56
- const fpath = path.join(dir, fname);
57
- if (fs.existsSync(fpath)) {
58
- skills.push({ name: entry.name, file: fname, fullPath: fpath, dir: entry.name });
59
- break;
60
- }
61
- }
62
- }
63
- return skills;
64
- }
65
-
66
- function slugify(name) {
67
- return name.toLowerCase().replace(/\s+/g, "-").replace(/[^a-z0-9-]/g, "");
68
- }
69
-
70
- function copyDirSync(src, dest) {
71
- fs.mkdirSync(dest, { recursive: true });
72
- for (const entry of fs.readdirSync(src, { withFileTypes: true })) {
73
- const srcPath = path.join(src, entry.name);
74
- const destPath = path.join(dest, entry.name);
75
- if (entry.isDirectory()) {
76
- copyDirSync(srcPath, destPath);
77
- } else {
78
- fs.copyFileSync(srcPath, destPath);
79
- }
80
- }
81
- }
82
-
83
- // ── Commands ───────────────────────────────────────────────────────
84
-
85
- function cmdInstall(args) {
86
- const flags = parseFlags(args, { target: "t", skills: "s", force: null, "dry-run": null, validate: null });
87
-
88
- // Detect target
89
- let target = flags.target;
90
- if (!target) {
91
- if (fs.existsSync(TARGETS.claude)) target = "claude";
92
- else if (fs.existsSync(TARGETS.antigravity)) target = "antigravity";
93
- else if (fs.existsSync(TARGETS.gemini)) target = "gemini";
94
- else target = "claude"; // default
95
- }
96
- if (!TARGETS[target]) {
97
- console.error(`Unknown target: ${target}. Use "claude", "gemini", or "antigravity".`);
98
- process.exit(1);
99
- }
100
-
101
- const installDir = TARGETS[target];
102
- const dryRun = flags["dry-run"] || false;
103
- const force = flags.force || false;
104
-
105
- // Ensure install directory
106
- if (!dryRun) {
107
- fs.mkdirSync(installDir, { recursive: true });
108
- }
109
-
110
- // Find skills
111
- let skills = findSkillFiles();
112
- if (flags.skills) {
113
- const wanted = new Set(flags.skills.split(",").map(s => s.trim().toLowerCase()));
114
- skills = skills.filter(s => wanted.has(s.name.toLowerCase()) || wanted.has(slugify(s.name)));
115
- }
116
-
117
- console.log(`Target : ${target}`);
118
- console.log(`Install: ${installDir}`);
119
- console.log(`Skills : ${skills.length}`);
120
- if (dryRun) console.log("[DRY RUN — no files will be written]\n");
121
- else console.log();
122
-
123
- let installed = 0, skipped = 0, failed = 0;
124
- const meta = loadMeta(installDir);
125
-
126
- for (const skill of skills) {
127
- const slug = slugify(skill.name);
128
- const dest = path.join(installDir, `${slug}.md`);
129
-
130
- const existsAlready = target === "antigravity"
131
- ? fs.existsSync(path.join(installDir, slug, "SKILL.md"))
132
- : fs.existsSync(dest);
133
- if (existsAlready && !force) {
134
- if (!dryRun) console.log(` SKIP ${slug} (already exists, use --force to overwrite)`);
135
- skipped++;
136
- continue;
137
- }
138
-
139
- if (flags.validate) {
140
- const content = fs.readFileSync(skill.fullPath, "utf8");
141
- const issues = validateSkill(content);
142
- if (issues.length > 0) {
143
- console.log(` FAIL ${slug} — validation errors:`);
144
- issues.forEach(i => console.log(` - ${i}`));
145
- failed++;
146
- continue;
147
- }
148
- }
149
-
150
- if (target === "antigravity") {
151
- // Antigravity uses directory-based skills: each skill is a directory with SKILL.md
152
- const skillDir = path.join(installDir, slug);
153
- const destFile = path.join(skillDir, "SKILL.md");
154
-
155
- if (dryRun) {
156
- console.log(` Would install ${slug}`);
157
- console.log(` src : ${skill.fullPath}`);
158
- console.log(` dest: ${destFile}`);
159
- } else {
160
- try {
161
- fs.mkdirSync(skillDir, { recursive: true });
162
- fs.copyFileSync(skill.fullPath, destFile);
163
- // Copy optional assets (scripts/, references/) if they exist in source
164
- const srcDir = path.dirname(skill.fullPath);
165
- for (const subdir of ["scripts", "references", "assets"]) {
166
- const srcSub = path.join(srcDir, subdir);
167
- if (fs.existsSync(srcSub) && fs.statSync(srcSub).isDirectory()) {
168
- copyDirSync(srcSub, path.join(skillDir, subdir));
169
- }
170
- }
171
- meta[slug] = {
172
- name: slug,
173
- source: skill.fullPath,
174
- installed_at: new Date().toISOString(),
175
- directory: skill.dir,
176
- };
177
- installed++;
178
- console.log(` OK ${slug}`);
179
- } catch (err) {
180
- console.log(` FAIL ${slug} — ${err.message}`);
181
- failed++;
182
- }
183
- }
184
- } else {
185
- if (dryRun) {
186
- console.log(` Would install ${slug}`);
187
- console.log(` src : ${skill.fullPath}`);
188
- console.log(` dest: ${dest}`);
189
- } else {
190
- try {
191
- fs.copyFileSync(skill.fullPath, dest);
192
- meta[slug] = {
193
- name: slug,
194
- source: skill.fullPath,
195
- installed_at: new Date().toISOString(),
196
- directory: skill.dir,
197
- };
198
- installed++;
199
- console.log(` OK ${slug}`);
200
- } catch (err) {
201
- console.log(` FAIL ${slug} — ${err.message}`);
202
- failed++;
203
- }
204
- }
205
- }
206
- }
207
-
208
- if (!dryRun) {
209
- saveMeta(installDir, meta);
210
- }
211
-
212
- console.log(`\n${installed} installed, ${skipped} skipped, ${failed} failed.`);
213
-
214
- if (!dryRun && installed > 0) {
215
- console.log(`\n How to use:`);
216
- if (target === "claude") {
217
- console.log(` In Claude Code, type /<skill-name> to invoke a skill.`);
218
- console.log(` Examples: /codesage, /testcrafter, /dockmaster, /python-master`);
219
- } else if (target === "antigravity") {
220
- console.log(` Skills are now available in Google Antigravity.`);
221
- console.log(` The agent will automatically match skills to your tasks via semantic triggering.`);
222
- console.log(` Installed to: ${installDir}`);
223
- } else {
224
- console.log(` Skills are now available in your Gemini context.`);
225
- }
226
- }
227
- }
228
-
229
- function cmdUninstall(args) {
230
- const flags = parseFlags(args, { target: "t" });
231
- const target = flags.target || "claude";
232
- const installDir = TARGETS[target];
233
- const names = flags._.filter(n => n !== "uninstall");
234
-
235
- if (names.length === 0) {
236
- console.error("Usage: agent-skills uninstall <skill-name> [<skill-name>...] [-t claude|gemini|antigravity]");
237
- process.exit(1);
238
- }
239
-
240
- const meta = loadMeta(installDir);
241
- let removed = 0;
242
-
243
- for (const name of names) {
244
- const slug = slugify(name);
245
- const dest = path.join(installDir, `${slug}.md`);
246
- if (fs.existsSync(dest)) {
247
- fs.unlinkSync(dest);
248
- delete meta[slug];
249
- console.log(` Removed ${slug}`);
250
- removed++;
251
- } else {
252
- console.log(` Not found: ${slug}`);
253
- }
254
- }
255
-
256
- saveMeta(installDir, meta);
257
- console.log(`\n${removed} skill(s) removed.`);
258
- }
259
-
260
- function cmdList(args) {
261
- const flags = parseFlags(args, { target: "t" });
262
- const target = flags.target || "claude";
263
- const installDir = TARGETS[target];
264
-
265
- if (!fs.existsSync(installDir)) {
266
- console.log(`No skills installed for ${target} (${installDir} does not exist).`);
267
- return;
268
- }
269
-
270
- const meta = loadMeta(installDir);
271
- const entries = Object.values(meta);
272
-
273
- if (entries.length === 0) {
274
- console.log(`No skills installed for ${target}.`);
275
- return;
276
- }
277
-
278
- console.log(`Installed skills (${target}): ${entries.length}\n`);
279
- console.log(" Name Installed At");
280
- console.log(" " + "-".repeat(60));
281
- for (const e of entries.sort((a, b) => a.name.localeCompare(b.name))) {
282
- const date = e.installed_at ? e.installed_at.slice(0, 19).replace("T", " ") : "unknown";
283
- console.log(` ${e.name.padEnd(30)} ${date}`);
284
- }
285
- }
286
-
287
- function cmdDoctor(args) {
288
- runPythonScript("doctor.py", args);
289
- }
290
-
291
- function cmdRoute(args) {
292
- runPythonScript("route.py", args);
293
- }
294
-
295
- function cmdValidate(args) {
296
- runPythonScript("validate.py", args);
297
- }
298
-
299
- function cmdScore(args) {
300
- runPythonScript("score.py", args);
301
- }
302
-
303
- function cmdTest(args) {
304
- runPythonScript("test_skill.py", args);
305
- }
306
-
307
- function cmdBuildIndex(args) {
308
- runPythonScript("build_index.py", args);
309
- }
310
-
311
- function cmdHelp() {
312
- console.log(`
313
- agent-skills — AI-powered developer skills for Claude, Gemini, and Antigravity
314
-
315
- Usage:
316
- agent-skills <command> [options]
317
-
318
- Commands:
319
- install Install skills to Claude, Gemini, or Antigravity
320
- -t, --target Target: "claude", "gemini", or "antigravity" (default: auto-detect)
321
- -s, --skills Comma-separated skill names (default: all)
322
- --force Overwrite existing skills
323
- --dry-run Preview without writing files
324
- --validate Validate skills before installing
325
-
326
- uninstall <names> Remove installed skills
327
- -t, --target Target: "claude", "gemini", or "antigravity"
328
-
329
- list List installed skills
330
- -t, --target Target: "claude", "gemini", or "antigravity"
331
-
332
- route "<prompt>" Find the best skill for a task
333
- -n, --top-n Number of results (default: 3)
334
- --json Output as JSON
335
- --interactive Interactive prompt mode
336
-
337
- doctor Check health of installed skills
338
- -t, --target Target: "claude", "gemini", or "antigravity" (default: all)
339
-
340
- validate Lint all skill files
341
- --fix Auto-fix known issues
342
-
343
- score Score all skills on quality metrics
344
- --json Output as JSON
345
-
346
- test Run adversarial tests on all skills
347
-
348
- build-index Regenerate skills.json and skills-routing.json
349
-
350
- Examples:
351
- npx agent-skills install # Install all to Claude
352
- npx agent-skills install -t gemini -s CodeSage,TestCrafter
353
- npx agent-skills install -t antigravity # Install all to Google Antigravity
354
- npx agent-skills route "review my Python code"
355
- npx agent-skills doctor
356
- npx agent-skills list
357
- npx agent-skills score --json > report.json
358
- `);
359
- }
360
-
361
- // ── Utilities ──────────────────────────────────────────────────────
362
-
363
- function parseFlags(args, aliases = {}) {
364
- const result = { _: [] };
365
- let i = 0;
366
- while (i < args.length) {
367
- const arg = args[i];
368
- if (arg.startsWith("--")) {
369
- const key = arg.slice(2);
370
- if (i + 1 < args.length && !args[i + 1].startsWith("-")) {
371
- result[key] = args[++i];
372
- } else {
373
- result[key] = true;
374
- }
375
- } else if (arg.startsWith("-") && arg.length === 2) {
376
- const short = arg.slice(1);
377
- const long = Object.entries(aliases).find(([, v]) => v === short)?.[0];
378
- const key = long || short;
379
- if (i + 1 < args.length && !args[i + 1].startsWith("-")) {
380
- result[key] = args[++i];
381
- } else {
382
- result[key] = true;
383
- }
384
- } else {
385
- result._.push(arg);
386
- }
387
- i++;
388
- }
389
- return result;
390
- }
391
-
392
- function validateSkill(content) {
393
- const issues = [];
394
- if (!content.startsWith("---")) issues.push("Missing frontmatter (---)");
395
- if (!content.match(/^#{1}\s/m)) issues.push("No H1 heading found");
396
- if (!content.match(/^#{2}\s/m)) issues.push("No H2 section found");
397
- if (!content.includes("```")) issues.push("No code examples found");
398
- if (content.length < 500) issues.push("Content too short (< 500 chars)");
399
- return issues;
400
- }
401
-
402
- function loadMeta(installDir) {
403
- const metaPath = path.join(installDir, ".skills-meta.json");
404
- if (fs.existsSync(metaPath)) {
405
- try { return JSON.parse(fs.readFileSync(metaPath, "utf8")); } catch (_) {}
406
- }
407
- return {};
408
- }
409
-
410
- function saveMeta(installDir, meta) {
411
- const metaPath = path.join(installDir, ".skills-meta.json");
412
- fs.writeFileSync(metaPath, JSON.stringify(meta, null, 2) + "\n");
413
- }
414
-
415
- // ── Main ───────────────────────────────────────────────────────────
416
-
417
- const [, , command, ...args] = process.argv;
418
-
419
- switch (command) {
420
- case "install": cmdInstall(args); break;
421
- case "uninstall": cmdUninstall(args); break;
422
- case "list": cmdList(args); break;
423
- case "route": cmdRoute(args); break;
424
- case "doctor": cmdDoctor(args); break;
425
- case "validate": cmdValidate(args); break;
426
- case "score": cmdScore(args); break;
427
- case "test": cmdTest(args); break;
428
- case "build-index": cmdBuildIndex(args); break;
429
- case "help":
430
- case "--help":
431
- case "-h":
432
- case undefined: cmdHelp(); break;
433
- default:
434
- console.error(`Unknown command: ${command}\nRun "agent-skills help" for usage.`);
435
- process.exit(1);
436
- }
1
+ #!/usr/bin/env node
2
+
3
+ const { execSync, spawnSync } = require("child_process");
4
+ const fs = require("fs");
5
+ const path = require("path");
6
+ const os = require("os");
7
+
8
+ // ── Resolve paths ──────────────────────────────────────────────────
9
+ const PKG_ROOT = path.resolve(__dirname, "..");
10
+ const SCRIPTS_DIR = path.join(PKG_ROOT, "scripts");
11
+ const HOME = os.homedir();
12
+
13
+ const TARGETS = {
14
+ agents: {
15
+ label: "Agent Skills compatible CLIs",
16
+ installDir: path.join(HOME, ".agents", "skills"),
17
+ },
18
+ claude: {
19
+ label: "Claude Code",
20
+ installDir: path.join(HOME, ".claude", "skills"),
21
+ },
22
+ copilot: {
23
+ label: "GitHub Copilot CLI",
24
+ installDir: path.join(HOME, ".copilot", "skills"),
25
+ },
26
+ codex: {
27
+ label: "OpenAI Codex CLI",
28
+ installDir: path.join(HOME, ".codex", "skills"),
29
+ },
30
+ gemini: {
31
+ label: "Gemini CLI",
32
+ installDir: path.join(HOME, ".gemini", "skills"),
33
+ },
34
+ antigravity: {
35
+ label: "Google Antigravity",
36
+ installDir: path.join(HOME, ".gemini", "antigravity", "skills"),
37
+ },
38
+ };
39
+ const TARGET_NAMES = Object.keys(TARGETS);
40
+ const CANONICAL_TARGET = "agents";
41
+
42
+ // ── Helpers ────────────────────────────────────────────────────────
43
+ function hasPython() {
44
+ for (const cmd of ["python3", "python"]) {
45
+ try {
46
+ execSync(`${cmd} --version`, { stdio: "ignore" });
47
+ return cmd;
48
+ } catch (_) {}
49
+ }
50
+ return null;
51
+ }
52
+
53
+ function runPythonScript(scriptName, args = []) {
54
+ const py = hasPython();
55
+ if (!py) {
56
+ console.error("Error: Python 3 is required but not found in PATH.");
57
+ console.error("Install Python 3: https://python.org/downloads/");
58
+ process.exit(1);
59
+ }
60
+ const scriptPath = path.join(SCRIPTS_DIR, scriptName);
61
+ if (!fs.existsSync(scriptPath)) {
62
+ console.error(`Error: Script not found: ${scriptPath}`);
63
+ process.exit(1);
64
+ }
65
+ const result = spawnSync(py, [scriptPath, ...args], {
66
+ stdio: "inherit",
67
+ cwd: PKG_ROOT,
68
+ });
69
+ process.exit(result.status || 0);
70
+ }
71
+
72
+ function findSkillFiles() {
73
+ const skills = [];
74
+ const entries = fs.readdirSync(PKG_ROOT, { withFileTypes: true });
75
+ for (const entry of entries) {
76
+ if (!entry.isDirectory() || entry.name.startsWith(".") || entry.name === "node_modules" || entry.name === "bin" || entry.name === "scripts") continue;
77
+ const dir = path.join(PKG_ROOT, entry.name);
78
+ for (const fname of ["skill.md", "SKILL.md"]) {
79
+ const fpath = path.join(dir, fname);
80
+ if (fs.existsSync(fpath)) {
81
+ skills.push({ name: entry.name, file: fname, fullPath: fpath, dir: entry.name });
82
+ break;
83
+ }
84
+ }
85
+ }
86
+ return skills;
87
+ }
88
+
89
+ function slugify(name) {
90
+ return name.toLowerCase().replace(/\s+/g, "-").replace(/[^a-z0-9-]/g, "");
91
+ }
92
+
93
+ function copyDirSync(src, dest) {
94
+ fs.mkdirSync(dest, { recursive: true });
95
+ for (const entry of fs.readdirSync(src, { withFileTypes: true })) {
96
+ const srcPath = path.join(src, entry.name);
97
+ const destPath = path.join(dest, entry.name);
98
+ if (entry.isDirectory()) {
99
+ copyDirSync(srcPath, destPath);
100
+ } else {
101
+ fs.copyFileSync(srcPath, destPath);
102
+ }
103
+ }
104
+ }
105
+
106
+ function resolveTargets(value, defaultToAll = true) {
107
+ const requested = value
108
+ ? value.split(",").map(target => target.trim().toLowerCase()).filter(Boolean)
109
+ : (defaultToAll ? ["all"] : ["claude"]);
110
+ const targets = requested.includes("all") ? TARGET_NAMES : [...new Set(requested)];
111
+ const unknown = targets.filter(target => !TARGETS[target]);
112
+ if (unknown.length > 0) {
113
+ console.error(`Unknown target(s): ${unknown.join(", ")}.`);
114
+ console.error(`Use "all" or a comma-separated list of: ${TARGET_NAMES.join(", ")}.`);
115
+ process.exit(2);
116
+ }
117
+ return targets;
118
+ }
119
+
120
+ function skillPath(installDir, slug) {
121
+ return path.join(installDir, slug, "SKILL.md");
122
+ }
123
+
124
+ function pathEntryExists(entryPath) {
125
+ try {
126
+ fs.lstatSync(entryPath);
127
+ return true;
128
+ } catch (err) {
129
+ if (err.code === "ENOENT") return false;
130
+ throw err;
131
+ }
132
+ }
133
+
134
+ function installCanonicalSkills(skills, options) {
135
+ const { installDir } = TARGETS[CANONICAL_TARGET];
136
+ const { dryRun, force, validate } = options;
137
+
138
+ if (!dryRun) {
139
+ fs.mkdirSync(installDir, { recursive: true });
140
+ }
141
+
142
+ console.log("\nCanonical skill store");
143
+
144
+ let installed = 0, skipped = 0, failed = 0;
145
+ const meta = loadMeta(installDir);
146
+
147
+ for (const skill of skills) {
148
+ const slug = slugify(skill.name);
149
+ const destFile = skillPath(installDir, slug);
150
+ if (fs.existsSync(destFile) && !force) {
151
+ console.log(` SKIP ${slug} (already exists, use --force to overwrite)`);
152
+ skipped++;
153
+ continue;
154
+ }
155
+
156
+ if (validate) {
157
+ const content = fs.readFileSync(skill.fullPath, "utf8");
158
+ const issues = validateSkill(content);
159
+ if (issues.length > 0) {
160
+ console.log(` FAIL ${slug} — validation errors:`);
161
+ issues.forEach(issue => console.log(` - ${issue}`));
162
+ failed++;
163
+ continue;
164
+ }
165
+ }
166
+
167
+ if (dryRun) {
168
+ console.log(` Would store ${slug}`);
169
+ installed++;
170
+ continue;
171
+ }
172
+
173
+ try {
174
+ const skillDir = path.dirname(destFile);
175
+ fs.mkdirSync(skillDir, { recursive: true });
176
+ fs.copyFileSync(skill.fullPath, destFile);
177
+ const srcDir = path.dirname(skill.fullPath);
178
+ for (const subdir of ["scripts", "references", "assets"]) {
179
+ const srcSub = path.join(srcDir, subdir);
180
+ const destSub = path.join(skillDir, subdir);
181
+ if (fs.existsSync(srcSub) && fs.statSync(srcSub).isDirectory()) {
182
+ fs.rmSync(destSub, { recursive: true, force: true });
183
+ copyDirSync(srcSub, destSub);
184
+ }
185
+ }
186
+ meta[slug] = {
187
+ name: slug,
188
+ source: skill.fullPath,
189
+ filename: path.join(slug, "SKILL.md"),
190
+ installed_at: new Date().toISOString(),
191
+ directory: skill.dir,
192
+ };
193
+ installed++;
194
+ console.log(` OK ${slug}`);
195
+ } catch (err) {
196
+ console.log(` FAIL ${slug} — ${err.message}`);
197
+ failed++;
198
+ }
199
+ }
200
+
201
+ if (!dryRun) {
202
+ saveMeta(installDir, meta);
203
+ }
204
+
205
+ console.log(`${installed} installed, ${skipped} skipped, ${failed} failed.`);
206
+ return { installed, skipped, failed };
207
+ }
208
+
209
+ function linkSkillsToTarget(target, skills, options) {
210
+ const { installDir, label } = TARGETS[target];
211
+ const canonicalDir = TARGETS[CANONICAL_TARGET].installDir;
212
+ const { dryRun, force } = options;
213
+
214
+ if (!dryRun) {
215
+ fs.mkdirSync(installDir, { recursive: true });
216
+ }
217
+
218
+ console.log(`\n${label}`);
219
+ let linked = 0, skipped = 0, failed = 0;
220
+ const meta = loadMeta(installDir);
221
+
222
+ for (const skill of skills) {
223
+ const slug = slugify(skill.name);
224
+ const canonicalSkillDir = path.join(canonicalDir, slug);
225
+ const linkPath = path.join(installDir, slug);
226
+
227
+ if (pathEntryExists(linkPath) && !force) {
228
+ console.log(` SKIP ${slug} (already exists, use --force to replace with a link)`);
229
+ skipped++;
230
+ continue;
231
+ }
232
+
233
+ if (dryRun) {
234
+ console.log(` Would link ${slug}`);
235
+ linked++;
236
+ continue;
237
+ }
238
+
239
+ try {
240
+ if (!fs.existsSync(skillPath(canonicalDir, slug))) {
241
+ throw new Error("canonical skill is missing");
242
+ }
243
+ if (pathEntryExists(linkPath)) {
244
+ fs.rmSync(linkPath, { recursive: true, force: true });
245
+ }
246
+ fs.symlinkSync(
247
+ canonicalSkillDir,
248
+ linkPath,
249
+ process.platform === "win32" ? "junction" : "dir",
250
+ );
251
+ meta[slug] = {
252
+ name: slug,
253
+ source: skill.fullPath,
254
+ filename: path.join(slug, "SKILL.md"),
255
+ linked_from: canonicalSkillDir,
256
+ installed_at: new Date().toISOString(),
257
+ directory: skill.dir,
258
+ };
259
+ linked++;
260
+ console.log(` OK ${slug}`);
261
+ } catch (err) {
262
+ console.log(` FAIL ${slug} — ${err.message}`);
263
+ failed++;
264
+ }
265
+ }
266
+
267
+ if (!dryRun) {
268
+ saveMeta(installDir, meta);
269
+ }
270
+
271
+ console.log(`${linked} linked, ${skipped} skipped, ${failed} failed.`);
272
+ return { linked, skipped, failed };
273
+ }
274
+
275
+ // ── Commands ───────────────────────────────────────────────────────
276
+
277
+ function cmdInstall(args) {
278
+ const flags = parseFlags(args, { target: "t", skills: "s", force: null, "dry-run": null, validate: null });
279
+ const targets = resolveTargets(flags.target);
280
+ const dryRun = flags["dry-run"] || false;
281
+ const force = flags.force || false;
282
+
283
+ // Find skills
284
+ let skills = findSkillFiles();
285
+ if (flags.skills) {
286
+ const wanted = new Set(flags.skills.split(",").map(s => s.trim().toLowerCase()));
287
+ skills = skills.filter(s => wanted.has(s.name.toLowerCase()) || wanted.has(slugify(s.name)));
288
+ }
289
+
290
+ const nativeTargets = targets.filter(target => target !== CANONICAL_TARGET);
291
+ console.log(`Preparing ${skills.length} skill(s) for: ${targets.join(", ")}`);
292
+ if (dryRun) console.log("[DRY RUN — no files will be written]");
293
+
294
+ const stored = installCanonicalSkills(skills, {
295
+ dryRun,
296
+ force,
297
+ validate: flags.validate || false,
298
+ });
299
+ const totals = nativeTargets.reduce((summary, target) => {
300
+ const result = linkSkillsToTarget(target, skills, { dryRun, force });
301
+ summary.linked += result.linked;
302
+ summary.skipped += result.skipped;
303
+ summary.failed += result.failed;
304
+ return summary;
305
+ }, { linked: 0, skipped: 0, failed: 0 });
306
+
307
+ const failed = stored.failed + totals.failed;
308
+ console.log(
309
+ `\nTotal: ${stored.installed} stored, ${totals.linked} linked, ` +
310
+ `${stored.skipped + totals.skipped} skipped, ${failed} failed.`,
311
+ );
312
+ if (!dryRun && (stored.installed > 0 || totals.linked > 0)) {
313
+ console.log("\nSkills are available to supported agents automatically and can be invoked by name.");
314
+ }
315
+ if (failed > 0) {
316
+ process.exitCode = 1;
317
+ }
318
+ }
319
+
320
+ function cmdUninstall(args) {
321
+ const flags = parseFlags(args, { target: "t" });
322
+ const targets = resolveTargets(flags.target);
323
+ const removalOrder = [
324
+ ...targets.filter(target => target !== CANONICAL_TARGET),
325
+ ...targets.filter(target => target === CANONICAL_TARGET),
326
+ ];
327
+ const names = flags._.filter(n => n !== "uninstall");
328
+
329
+ if (names.length === 0) {
330
+ console.error("Usage: agent-skills uninstall <skill-name> [<skill-name>...] [-t all|claude|copilot|codex|gemini|antigravity|agents]");
331
+ process.exit(2);
332
+ }
333
+
334
+ let removed = 0;
335
+ for (const target of removalOrder) {
336
+ const installDir = TARGETS[target].installDir;
337
+ const meta = loadMeta(installDir);
338
+ console.log(`\nTarget: ${TARGETS[target].label} (${target})`);
339
+ for (const name of names) {
340
+ const slug = slugify(name);
341
+ const skillDir = path.join(installDir, slug);
342
+ if (pathEntryExists(skillDir)) {
343
+ fs.rmSync(skillDir, { recursive: true, force: true });
344
+ delete meta[slug];
345
+ console.log(` Removed ${slug}`);
346
+ removed++;
347
+ } else {
348
+ console.log(` Not found: ${slug}`);
349
+ }
350
+ }
351
+ if (fs.existsSync(installDir)) saveMeta(installDir, meta);
352
+ }
353
+
354
+ console.log(`\n${removed} skill(s) removed.`);
355
+ }
356
+
357
+ function cmdList(args) {
358
+ const flags = parseFlags(args, { target: "t" });
359
+ const targets = resolveTargets(flags.target);
360
+ for (const target of targets) {
361
+ const installDir = TARGETS[target].installDir;
362
+ console.log(`\nInstalled skills (${target})`);
363
+ if (!fs.existsSync(installDir)) {
364
+ console.log(" None (directory does not exist).");
365
+ continue;
366
+ }
367
+ const entries = Object.values(loadMeta(installDir));
368
+ if (entries.length === 0) {
369
+ console.log(" None.");
370
+ continue;
371
+ }
372
+ console.log(" Name Installed At");
373
+ console.log(" " + "-".repeat(60));
374
+ for (const entry of entries.sort((a, b) => a.name.localeCompare(b.name))) {
375
+ const date = entry.installed_at ? entry.installed_at.slice(0, 19).replace("T", " ") : "unknown";
376
+ console.log(` ${entry.name.padEnd(30)} ${date}`);
377
+ }
378
+ }
379
+ }
380
+
381
+ function cmdDoctor(args) {
382
+ runPythonScript("doctor.py", args);
383
+ }
384
+
385
+ function cmdRoute(args) {
386
+ runPythonScript("route.py", args);
387
+ }
388
+
389
+ function cmdValidate(args) {
390
+ runPythonScript("validate.py", args);
391
+ }
392
+
393
+ function cmdScore(args) {
394
+ runPythonScript("score.py", args);
395
+ }
396
+
397
+ function cmdTest(args) {
398
+ runPythonScript("test_skill.py", args);
399
+ }
400
+
401
+ function cmdBuildIndex(args) {
402
+ runPythonScript("build_index.py", args);
403
+ }
404
+
405
+ function cmdHelp() {
406
+ console.log(`
407
+ agent-skills — portable AI skills for Copilot, Claude, Codex, Gemini, and other agents
408
+
409
+ Usage:
410
+ agent-skills <command> [options]
411
+
412
+ Commands:
413
+ install Store skills once and link them into supported AI CLIs
414
+ -t, --target Target(s): "all", "agents", "claude", "copilot", "codex",
415
+ "gemini", or "antigravity" (comma-separated; default: all)
416
+ -s, --skills Comma-separated skill names (default: all)
417
+ --force Overwrite existing skills
418
+ --dry-run Preview without writing files
419
+ --validate Validate skills before installing
420
+
421
+ uninstall <names> Remove installed skills
422
+ -t, --target Target(s) to remove from (default: all)
423
+
424
+ list List installed skills
425
+ -t, --target Target(s) to list (default: all)
426
+
427
+ route "<prompt>" Find the best skill for a task
428
+ -n, --top-n Number of results (default: 3)
429
+ --json Output as JSON
430
+ --interactive Interactive prompt mode
431
+
432
+ doctor Check health of installed skills
433
+ -t, --target Target: "agents", "claude", "copilot", "codex", "gemini",
434
+ or "antigravity" (default: all)
435
+
436
+ validate Lint all skill files
437
+ --fix Auto-fix known issues
438
+
439
+ score Score all skills on quality metrics
440
+ --json Output as JSON
441
+
442
+ test Run adversarial tests on all skills
443
+
444
+ build-index Regenerate skills.json and skills-routing.json
445
+
446
+ Examples:
447
+ npx agent-skills install # Store once and link every supported CLI
448
+ npx agent-skills install -t copilot,codex # Link only selected AI CLIs
449
+ npx agent-skills install -t gemini -s CodeSage,TestCrafter
450
+ npx agent-skills install -t antigravity # Install all to Google Antigravity
451
+ npx agent-skills route "review my Python code"
452
+ npx agent-skills doctor
453
+ npx agent-skills list
454
+ npx agent-skills score --json > report.json
455
+ `);
456
+ }
457
+
458
+ // ── Utilities ──────────────────────────────────────────────────────
459
+
460
+ function parseFlags(args, aliases = {}) {
461
+ const result = { _: [] };
462
+ let i = 0;
463
+ while (i < args.length) {
464
+ const arg = args[i];
465
+ if (arg.startsWith("--")) {
466
+ const key = arg.slice(2);
467
+ if (i + 1 < args.length && !args[i + 1].startsWith("-")) {
468
+ result[key] = args[++i];
469
+ } else {
470
+ result[key] = true;
471
+ }
472
+ } else if (arg.startsWith("-") && arg.length === 2) {
473
+ const short = arg.slice(1);
474
+ const long = Object.entries(aliases).find(([, v]) => v === short)?.[0];
475
+ const key = long || short;
476
+ if (i + 1 < args.length && !args[i + 1].startsWith("-")) {
477
+ result[key] = args[++i];
478
+ } else {
479
+ result[key] = true;
480
+ }
481
+ } else {
482
+ result._.push(arg);
483
+ }
484
+ i++;
485
+ }
486
+ return result;
487
+ }
488
+
489
+ function validateSkill(content) {
490
+ const issues = [];
491
+ if (!content.startsWith("---")) issues.push("Missing frontmatter (---)");
492
+ if (!content.match(/^#{1}\s/m)) issues.push("No H1 heading found");
493
+ if (!content.match(/^#{2}\s/m)) issues.push("No H2 section found");
494
+ if (!content.includes("```")) issues.push("No code examples found");
495
+ if (content.length < 500) issues.push("Content too short (< 500 chars)");
496
+ return issues;
497
+ }
498
+
499
+ function loadMeta(installDir) {
500
+ const metaPath = path.join(installDir, ".skills-meta.json");
501
+ if (fs.existsSync(metaPath)) {
502
+ try { return JSON.parse(fs.readFileSync(metaPath, "utf8")); } catch (_) {}
503
+ }
504
+ return {};
505
+ }
506
+
507
+ function saveMeta(installDir, meta) {
508
+ const metaPath = path.join(installDir, ".skills-meta.json");
509
+ fs.writeFileSync(metaPath, JSON.stringify(meta, null, 2) + "\n");
510
+ }
511
+
512
+ // ── Main ───────────────────────────────────────────────────────────
513
+
514
+ const [, , command, ...args] = process.argv;
515
+
516
+ switch (command) {
517
+ case "install": cmdInstall(args); break;
518
+ case "uninstall": cmdUninstall(args); break;
519
+ case "list": cmdList(args); break;
520
+ case "route": cmdRoute(args); break;
521
+ case "doctor": cmdDoctor(args); break;
522
+ case "validate": cmdValidate(args); break;
523
+ case "score": cmdScore(args); break;
524
+ case "test": cmdTest(args); break;
525
+ case "build-index": cmdBuildIndex(args); break;
526
+ case "help":
527
+ case "--help":
528
+ case "-h":
529
+ case undefined: cmdHelp(); break;
530
+ default:
531
+ console.error(`Unknown command: ${command}\nRun "agent-skills help" for usage.`);
532
+ process.exit(1);
533
+ }