@workingpayload/agent-skills 2.0.2 → 2.2.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/AuthorGuard/skill.md +110 -0
- package/README.md +29 -15
- package/bin/cli.js +533 -439
- package/package.json +44 -42
- package/scripts/doctor.py +548 -542
- package/scripts/install.py +486 -437
- package/skills-routing.json +28 -2
- package/skills.json +68 -2
package/scripts/install.py
CHANGED
|
@@ -1,437 +1,486 @@
|
|
|
1
|
-
#!/usr/bin/env python3
|
|
2
|
-
"""
|
|
3
|
-
install.py - Install Agent Skills to
|
|
4
|
-
|
|
5
|
-
Usage:
|
|
6
|
-
python scripts/install.py #
|
|
7
|
-
python scripts/install.py --target claude # install to Claude
|
|
8
|
-
python scripts/install.py --target gemini # install to Gemini
|
|
9
|
-
python scripts/install.py --skills CodeSage,UISmith # install specific skills
|
|
10
|
-
python scripts/install.py --force # overwrite existing installs
|
|
11
|
-
python scripts/install.py --dry-run # preview without writing
|
|
12
|
-
python scripts/install.py --validate # validate before installing
|
|
13
|
-
python scripts/install.py --list-installed # show installed skills
|
|
14
|
-
python scripts/install.py --uninstall CodeSage # remove specific skills
|
|
15
|
-
"""
|
|
16
|
-
|
|
17
|
-
import argparse
|
|
18
|
-
import hashlib
|
|
19
|
-
import json
|
|
20
|
-
import os
|
|
21
|
-
import shutil
|
|
22
|
-
import subprocess
|
|
23
|
-
import sys
|
|
24
|
-
from datetime import datetime, timezone
|
|
25
|
-
from pathlib import Path
|
|
26
|
-
|
|
27
|
-
# ---------------------------------------------------------------------------
|
|
28
|
-
# Constants
|
|
29
|
-
# ---------------------------------------------------------------------------
|
|
30
|
-
|
|
31
|
-
SKILL_FILENAMES = ("skill.md", "SKILL.md")
|
|
32
|
-
META_FILE = ".skills-meta.json"
|
|
33
|
-
|
|
34
|
-
INSTALL_DIRS = {
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
"""
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
return False, f"
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
if
|
|
134
|
-
return False,
|
|
135
|
-
|
|
136
|
-
#
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
if
|
|
147
|
-
return False, "
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
if
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
)
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
"
|
|
363
|
-
|
|
364
|
-
default
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""
|
|
3
|
+
install.py - Install Agent Skills to supported AI CLI skill directories.
|
|
4
|
+
|
|
5
|
+
Usage:
|
|
6
|
+
python scripts/install.py # store once and link every target
|
|
7
|
+
python scripts/install.py --target claude # install to Claude
|
|
8
|
+
python scripts/install.py --target gemini # install to Gemini
|
|
9
|
+
python scripts/install.py --skills CodeSage,UISmith # install specific skills
|
|
10
|
+
python scripts/install.py --force # overwrite existing installs
|
|
11
|
+
python scripts/install.py --dry-run # preview without writing
|
|
12
|
+
python scripts/install.py --validate # validate before installing
|
|
13
|
+
python scripts/install.py --list-installed # show installed skills
|
|
14
|
+
python scripts/install.py --uninstall CodeSage # remove specific skills
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
import argparse
|
|
18
|
+
import hashlib
|
|
19
|
+
import json
|
|
20
|
+
import os
|
|
21
|
+
import shutil
|
|
22
|
+
import subprocess
|
|
23
|
+
import sys
|
|
24
|
+
from datetime import datetime, timezone
|
|
25
|
+
from pathlib import Path
|
|
26
|
+
|
|
27
|
+
# ---------------------------------------------------------------------------
|
|
28
|
+
# Constants
|
|
29
|
+
# ---------------------------------------------------------------------------
|
|
30
|
+
|
|
31
|
+
SKILL_FILENAMES = ("skill.md", "SKILL.md")
|
|
32
|
+
META_FILE = ".skills-meta.json"
|
|
33
|
+
|
|
34
|
+
INSTALL_DIRS = {
|
|
35
|
+
"agents": Path.home() / ".agents" / "skills",
|
|
36
|
+
"claude": Path.home() / ".claude" / "skills",
|
|
37
|
+
"copilot": Path.home() / ".copilot" / "skills",
|
|
38
|
+
"codex": Path.home() / ".codex" / "skills",
|
|
39
|
+
"gemini": Path.home() / ".gemini" / "skills",
|
|
40
|
+
"antigravity": Path.home() / ".gemini" / "antigravity" / "skills",
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
CANONICAL_TARGET = "agents"
|
|
44
|
+
|
|
45
|
+
# ---------------------------------------------------------------------------
|
|
46
|
+
# Repo helpers
|
|
47
|
+
# ---------------------------------------------------------------------------
|
|
48
|
+
|
|
49
|
+
def repo_root() -> Path:
|
|
50
|
+
"""Return the root of this repository (parent of this script's directory)."""
|
|
51
|
+
return Path(__file__).resolve().parent.parent
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def find_all_skill_dirs(root: Path) -> dict[str, Path]:
|
|
55
|
+
"""
|
|
56
|
+
Scan repo root for directories containing a skill file.
|
|
57
|
+
Returns {skill_name: skill_file_path}.
|
|
58
|
+
Skill name is derived from the directory name (lowercased, spaces→hyphens).
|
|
59
|
+
"""
|
|
60
|
+
skills: dict[str, Path] = {}
|
|
61
|
+
for d in sorted(root.iterdir()):
|
|
62
|
+
if not d.is_dir():
|
|
63
|
+
continue
|
|
64
|
+
# Skip hidden dirs and the scripts dir itself
|
|
65
|
+
if d.name.startswith(".") or d.name == "scripts":
|
|
66
|
+
continue
|
|
67
|
+
for filename in SKILL_FILENAMES:
|
|
68
|
+
candidate = d / filename
|
|
69
|
+
if candidate.is_file():
|
|
70
|
+
skill_name = d.name.lower().replace(" ", "-")
|
|
71
|
+
skills[skill_name] = candidate
|
|
72
|
+
break
|
|
73
|
+
return skills
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def git_hash(path: Path) -> str:
|
|
77
|
+
"""Return the git object hash for a file, or a content SHA256 fallback."""
|
|
78
|
+
try:
|
|
79
|
+
result = subprocess.run(
|
|
80
|
+
["git", "hash-object", str(path)],
|
|
81
|
+
capture_output=True,
|
|
82
|
+
text=True,
|
|
83
|
+
cwd=str(path.parent),
|
|
84
|
+
)
|
|
85
|
+
if result.returncode == 0:
|
|
86
|
+
return result.stdout.strip()
|
|
87
|
+
except FileNotFoundError:
|
|
88
|
+
pass # git not available
|
|
89
|
+
# Fallback: SHA256 of file content
|
|
90
|
+
digest = hashlib.sha256(path.read_bytes()).hexdigest()
|
|
91
|
+
return f"sha256:{digest[:16]}"
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
# ---------------------------------------------------------------------------
|
|
95
|
+
# Meta file helpers
|
|
96
|
+
# ---------------------------------------------------------------------------
|
|
97
|
+
|
|
98
|
+
def load_meta(install_dir: Path) -> dict:
|
|
99
|
+
meta_path = install_dir / META_FILE
|
|
100
|
+
if meta_path.is_file():
|
|
101
|
+
try:
|
|
102
|
+
return json.loads(meta_path.read_text(encoding="utf-8"))
|
|
103
|
+
except json.JSONDecodeError:
|
|
104
|
+
return {}
|
|
105
|
+
return {}
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
def save_meta(install_dir: Path, meta: dict) -> None:
|
|
109
|
+
install_dir.mkdir(parents=True, exist_ok=True)
|
|
110
|
+
meta_path = install_dir / META_FILE
|
|
111
|
+
meta_path.write_text(json.dumps(meta, indent=2), encoding="utf-8")
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
# ---------------------------------------------------------------------------
|
|
115
|
+
# Validation helper (delegates to scripts/validate.py if available)
|
|
116
|
+
# ---------------------------------------------------------------------------
|
|
117
|
+
|
|
118
|
+
def validate_skill(skill_file: Path) -> tuple[bool, str]:
|
|
119
|
+
"""
|
|
120
|
+
Run a lightweight inline validation on a single skill file.
|
|
121
|
+
Returns (passed, message).
|
|
122
|
+
"""
|
|
123
|
+
try:
|
|
124
|
+
text = skill_file.read_text(encoding="utf-8")
|
|
125
|
+
except OSError as exc:
|
|
126
|
+
return False, f"Cannot read file: {exc}"
|
|
127
|
+
|
|
128
|
+
lines = text.splitlines()
|
|
129
|
+
if len(lines) < 10:
|
|
130
|
+
return False, f"Too short ({len(lines)} lines)"
|
|
131
|
+
|
|
132
|
+
# Check for frontmatter
|
|
133
|
+
if not lines or lines[0].strip() != "---":
|
|
134
|
+
return False, "Missing YAML frontmatter (file must start with ---)"
|
|
135
|
+
|
|
136
|
+
# Extract frontmatter fields
|
|
137
|
+
end_idx = None
|
|
138
|
+
for i, line in enumerate(lines[1:], start=1):
|
|
139
|
+
if line.strip() == "---":
|
|
140
|
+
end_idx = i
|
|
141
|
+
break
|
|
142
|
+
if end_idx is None:
|
|
143
|
+
return False, "Unclosed YAML frontmatter"
|
|
144
|
+
|
|
145
|
+
fm_text = "\n".join(lines[1:end_idx])
|
|
146
|
+
if "name:" not in fm_text:
|
|
147
|
+
return False, "Frontmatter missing 'name' field"
|
|
148
|
+
if "description:" not in fm_text:
|
|
149
|
+
return False, "Frontmatter missing 'description' field"
|
|
150
|
+
|
|
151
|
+
return True, "OK"
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
# ---------------------------------------------------------------------------
|
|
155
|
+
# Core operations
|
|
156
|
+
# ---------------------------------------------------------------------------
|
|
157
|
+
|
|
158
|
+
def list_installed(install_dir: Path) -> None:
|
|
159
|
+
meta = load_meta(install_dir)
|
|
160
|
+
if not meta:
|
|
161
|
+
print("No skills installed.")
|
|
162
|
+
return
|
|
163
|
+
|
|
164
|
+
print("Installed skills:\n")
|
|
165
|
+
header = f"{'Skill':<30} {'Version':<20} {'Installed At'}"
|
|
166
|
+
print(header)
|
|
167
|
+
print("-" * len(header))
|
|
168
|
+
for name, info in sorted(meta.items()):
|
|
169
|
+
version = info.get("version", "unknown")[:12]
|
|
170
|
+
installed_at = info.get("installed_at", "unknown")
|
|
171
|
+
print(f"{name:<30} {version:<20} {installed_at}")
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
def remove_directory_entry(path: Path) -> None:
|
|
175
|
+
"""Remove a real directory or a directory link without traversing links."""
|
|
176
|
+
is_junction = getattr(path, "is_junction", lambda: False)()
|
|
177
|
+
if is_junction:
|
|
178
|
+
os.rmdir(path)
|
|
179
|
+
elif path.is_symlink() or not path.is_dir():
|
|
180
|
+
path.unlink()
|
|
181
|
+
else:
|
|
182
|
+
shutil.rmtree(path)
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
def uninstall_skills(names: list[str], install_dir: Path, dry_run: bool) -> None:
|
|
186
|
+
meta = load_meta(install_dir)
|
|
187
|
+
removed, missing = 0, 0
|
|
188
|
+
|
|
189
|
+
for name in names:
|
|
190
|
+
dest = install_dir / name
|
|
191
|
+
if os.path.lexists(dest):
|
|
192
|
+
print(f" {'[dry-run] ' if dry_run else ''}Removing {name}")
|
|
193
|
+
if not dry_run:
|
|
194
|
+
remove_directory_entry(dest)
|
|
195
|
+
removed += 1
|
|
196
|
+
else:
|
|
197
|
+
print(f" Skill not installed: {name}")
|
|
198
|
+
missing += 1
|
|
199
|
+
|
|
200
|
+
if name in meta and not dry_run:
|
|
201
|
+
del meta[name]
|
|
202
|
+
|
|
203
|
+
if not dry_run:
|
|
204
|
+
save_meta(install_dir, meta)
|
|
205
|
+
|
|
206
|
+
print(f"\nUninstall summary: {removed} removed, {missing} not found.")
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
def install_skills(
|
|
210
|
+
skill_map: dict[str, Path],
|
|
211
|
+
install_dir: Path,
|
|
212
|
+
force: bool,
|
|
213
|
+
dry_run: bool,
|
|
214
|
+
do_validate: bool,
|
|
215
|
+
) -> dict[str, int]:
|
|
216
|
+
if not dry_run:
|
|
217
|
+
install_dir.mkdir(parents=True, exist_ok=True)
|
|
218
|
+
meta = load_meta(install_dir)
|
|
219
|
+
|
|
220
|
+
installed_count = 0
|
|
221
|
+
skipped_count = 0
|
|
222
|
+
failed_count = 0
|
|
223
|
+
|
|
224
|
+
for skill_name, skill_file in sorted(skill_map.items()):
|
|
225
|
+
skill_dir = install_dir / skill_name
|
|
226
|
+
dest_file = skill_dir / "SKILL.md"
|
|
227
|
+
|
|
228
|
+
# Validation gate
|
|
229
|
+
if do_validate:
|
|
230
|
+
passed, msg = validate_skill(skill_file)
|
|
231
|
+
if not passed:
|
|
232
|
+
print(f" FAIL {skill_name}: validation error — {msg}")
|
|
233
|
+
failed_count += 1
|
|
234
|
+
continue
|
|
235
|
+
|
|
236
|
+
# Skip if already installed and not forcing
|
|
237
|
+
if dest_file.exists() and not force:
|
|
238
|
+
print(f" SKIP {skill_name} (already installed; use --force to overwrite)")
|
|
239
|
+
skipped_count += 1
|
|
240
|
+
continue
|
|
241
|
+
|
|
242
|
+
action = "Would store" if dry_run else "Storing"
|
|
243
|
+
print(f" {action} {skill_name}")
|
|
244
|
+
|
|
245
|
+
if not dry_run:
|
|
246
|
+
skill_dir.mkdir(parents=True, exist_ok=True)
|
|
247
|
+
shutil.copy2(str(skill_file), str(dest_file))
|
|
248
|
+
src_dir = skill_file.parent
|
|
249
|
+
for subdir_name in ("scripts", "references", "assets"):
|
|
250
|
+
src_sub = src_dir / subdir_name
|
|
251
|
+
if src_sub.is_dir():
|
|
252
|
+
dest_sub = skill_dir / subdir_name
|
|
253
|
+
if dest_sub.exists():
|
|
254
|
+
shutil.rmtree(str(dest_sub))
|
|
255
|
+
shutil.copytree(str(src_sub), str(dest_sub))
|
|
256
|
+
meta[skill_name] = {
|
|
257
|
+
"name": skill_name,
|
|
258
|
+
"version": git_hash(skill_file),
|
|
259
|
+
"installed_at": datetime.now(timezone.utc).isoformat(),
|
|
260
|
+
"source_path": str(skill_file),
|
|
261
|
+
"filename": str(Path(skill_name) / "SKILL.md"),
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
installed_count += 1
|
|
265
|
+
|
|
266
|
+
if not dry_run:
|
|
267
|
+
save_meta(install_dir, meta)
|
|
268
|
+
|
|
269
|
+
prefix = "[dry-run] " if dry_run else ""
|
|
270
|
+
print(
|
|
271
|
+
f"\n{prefix}Summary: {installed_count} installed, "
|
|
272
|
+
f"{skipped_count} skipped (already exists), "
|
|
273
|
+
f"{failed_count} failed."
|
|
274
|
+
)
|
|
275
|
+
|
|
276
|
+
return {
|
|
277
|
+
"stored": installed_count,
|
|
278
|
+
"skipped": skipped_count,
|
|
279
|
+
"failed": failed_count,
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
|
|
283
|
+
def create_directory_link(source: Path, link: Path) -> None:
|
|
284
|
+
"""Create a directory link, using a junction on Windows."""
|
|
285
|
+
if sys.platform == "win32":
|
|
286
|
+
command = os.environ.get("COMSPEC", "cmd.exe")
|
|
287
|
+
result = subprocess.run(
|
|
288
|
+
[command, "/c", "mklink", "/J", str(link), str(source)],
|
|
289
|
+
capture_output=True,
|
|
290
|
+
text=True,
|
|
291
|
+
)
|
|
292
|
+
if result.returncode != 0:
|
|
293
|
+
raise OSError((result.stderr or result.stdout).strip())
|
|
294
|
+
else:
|
|
295
|
+
link.symlink_to(source, target_is_directory=True)
|
|
296
|
+
|
|
297
|
+
|
|
298
|
+
def link_skills(
|
|
299
|
+
skill_map: dict[str, Path],
|
|
300
|
+
target: str,
|
|
301
|
+
force: bool,
|
|
302
|
+
dry_run: bool,
|
|
303
|
+
) -> dict[str, int]:
|
|
304
|
+
install_dir = INSTALL_DIRS[target]
|
|
305
|
+
canonical_dir = INSTALL_DIRS[CANONICAL_TARGET]
|
|
306
|
+
if not dry_run:
|
|
307
|
+
install_dir.mkdir(parents=True, exist_ok=True)
|
|
308
|
+
meta = load_meta(install_dir)
|
|
309
|
+
linked = skipped = failed = 0
|
|
310
|
+
|
|
311
|
+
print(f"\nTarget: {target}")
|
|
312
|
+
for skill_name, skill_file in sorted(skill_map.items()):
|
|
313
|
+
source = canonical_dir / skill_name
|
|
314
|
+
link = install_dir / skill_name
|
|
315
|
+
if os.path.lexists(link) and not force:
|
|
316
|
+
print(f" SKIP {skill_name} (already exists; use --force to replace with a link)")
|
|
317
|
+
skipped += 1
|
|
318
|
+
continue
|
|
319
|
+
if dry_run:
|
|
320
|
+
print(f" Would link {skill_name}")
|
|
321
|
+
linked += 1
|
|
322
|
+
continue
|
|
323
|
+
try:
|
|
324
|
+
if not (source / "SKILL.md").is_file():
|
|
325
|
+
raise FileNotFoundError("canonical skill is missing")
|
|
326
|
+
if os.path.lexists(link):
|
|
327
|
+
remove_directory_entry(link)
|
|
328
|
+
create_directory_link(source, link)
|
|
329
|
+
meta[skill_name] = {
|
|
330
|
+
"name": skill_name,
|
|
331
|
+
"version": git_hash(skill_file),
|
|
332
|
+
"installed_at": datetime.now(timezone.utc).isoformat(),
|
|
333
|
+
"source_path": str(skill_file),
|
|
334
|
+
"filename": str(Path(skill_name) / "SKILL.md"),
|
|
335
|
+
"linked_from": str(source),
|
|
336
|
+
}
|
|
337
|
+
print(f" OK {skill_name}")
|
|
338
|
+
linked += 1
|
|
339
|
+
except OSError as exc:
|
|
340
|
+
print(f" FAIL {skill_name}: {exc}")
|
|
341
|
+
failed += 1
|
|
342
|
+
|
|
343
|
+
if not dry_run:
|
|
344
|
+
save_meta(install_dir, meta)
|
|
345
|
+
print(f"Summary: {linked} linked, {skipped} skipped, {failed} failed.")
|
|
346
|
+
return {"linked": linked, "skipped": skipped, "failed": failed}
|
|
347
|
+
|
|
348
|
+
|
|
349
|
+
# ---------------------------------------------------------------------------
|
|
350
|
+
# CLI
|
|
351
|
+
# ---------------------------------------------------------------------------
|
|
352
|
+
|
|
353
|
+
def parse_args(argv: list[str] | None = None) -> argparse.Namespace:
|
|
354
|
+
parser = argparse.ArgumentParser(
|
|
355
|
+
description="Install Agent Skills to supported AI CLI skill directories.",
|
|
356
|
+
formatter_class=argparse.RawDescriptionHelpFormatter,
|
|
357
|
+
epilog=__doc__,
|
|
358
|
+
)
|
|
359
|
+
|
|
360
|
+
parser.add_argument(
|
|
361
|
+
"--target", "-t",
|
|
362
|
+
choices=["all", *INSTALL_DIRS.keys()],
|
|
363
|
+
default="all",
|
|
364
|
+
help="Target platform (default: all supported AI CLIs).",
|
|
365
|
+
)
|
|
366
|
+
parser.add_argument(
|
|
367
|
+
"--skills", "-s",
|
|
368
|
+
default=None,
|
|
369
|
+
help="Comma-separated skill names to install (default: all).",
|
|
370
|
+
)
|
|
371
|
+
parser.add_argument(
|
|
372
|
+
"--force",
|
|
373
|
+
action="store_true",
|
|
374
|
+
help="Overwrite existing installed skills.",
|
|
375
|
+
)
|
|
376
|
+
parser.add_argument(
|
|
377
|
+
"--dry-run",
|
|
378
|
+
action="store_true",
|
|
379
|
+
help="Show what would be done without making any changes.",
|
|
380
|
+
)
|
|
381
|
+
parser.add_argument(
|
|
382
|
+
"--validate",
|
|
383
|
+
action="store_true",
|
|
384
|
+
help="Run validation on each skill before installing; skip invalid skills.",
|
|
385
|
+
)
|
|
386
|
+
parser.add_argument(
|
|
387
|
+
"--list-installed",
|
|
388
|
+
action="store_true",
|
|
389
|
+
help="Show currently installed skills with version info.",
|
|
390
|
+
)
|
|
391
|
+
parser.add_argument(
|
|
392
|
+
"--uninstall",
|
|
393
|
+
metavar="NAMES",
|
|
394
|
+
default=None,
|
|
395
|
+
help="Comma-separated skill names to uninstall.",
|
|
396
|
+
)
|
|
397
|
+
|
|
398
|
+
return parser.parse_args(argv)
|
|
399
|
+
|
|
400
|
+
|
|
401
|
+
def main(argv: list[str] | None = None) -> int:
|
|
402
|
+
args = parse_args(argv)
|
|
403
|
+
|
|
404
|
+
targets = list(INSTALL_DIRS) if args.target == "all" else [args.target]
|
|
405
|
+
|
|
406
|
+
# --list-installed
|
|
407
|
+
if args.list_installed:
|
|
408
|
+
for target in targets:
|
|
409
|
+
print(f"\nTarget: {target}")
|
|
410
|
+
list_installed(INSTALL_DIRS[target])
|
|
411
|
+
return 0
|
|
412
|
+
|
|
413
|
+
# --uninstall
|
|
414
|
+
if args.uninstall:
|
|
415
|
+
names = [n.strip().lower().replace(" ", "-") for n in args.uninstall.split(",") if n.strip()]
|
|
416
|
+
removal_order = [target for target in targets if target != CANONICAL_TARGET]
|
|
417
|
+
if CANONICAL_TARGET in targets:
|
|
418
|
+
removal_order.append(CANONICAL_TARGET)
|
|
419
|
+
for target in removal_order:
|
|
420
|
+
install_dir = INSTALL_DIRS[target]
|
|
421
|
+
print(f"\nUninstalling {len(names)} skill(s) from {target}:\n")
|
|
422
|
+
uninstall_skills(names, install_dir, dry_run=args.dry_run)
|
|
423
|
+
return 0
|
|
424
|
+
|
|
425
|
+
# Discover all skills in the repo
|
|
426
|
+
root = repo_root()
|
|
427
|
+
all_skills = find_all_skill_dirs(root)
|
|
428
|
+
|
|
429
|
+
if not all_skills:
|
|
430
|
+
print("ERROR: No skill files found in the repository.")
|
|
431
|
+
return 1
|
|
432
|
+
|
|
433
|
+
# Filter to requested skills if --skills was given
|
|
434
|
+
if args.skills:
|
|
435
|
+
requested = {
|
|
436
|
+
n.strip().lower().replace(" ", "-")
|
|
437
|
+
for n in args.skills.split(",")
|
|
438
|
+
if n.strip()
|
|
439
|
+
}
|
|
440
|
+
unknown = requested - all_skills.keys()
|
|
441
|
+
if unknown:
|
|
442
|
+
print(f"WARNING: Unknown skill(s): {', '.join(sorted(unknown))}")
|
|
443
|
+
skill_map = {k: v for k, v in all_skills.items() if k in requested}
|
|
444
|
+
if not skill_map:
|
|
445
|
+
print("ERROR: No matching skills found.")
|
|
446
|
+
return 1
|
|
447
|
+
else:
|
|
448
|
+
skill_map = all_skills
|
|
449
|
+
|
|
450
|
+
print(f"Skills to process: {len(skill_map)}")
|
|
451
|
+
if args.dry_run:
|
|
452
|
+
print("[DRY RUN — no files will be written]\n")
|
|
453
|
+
print()
|
|
454
|
+
|
|
455
|
+
print("\nCanonical skill store")
|
|
456
|
+
stored = install_skills(
|
|
457
|
+
skill_map=skill_map,
|
|
458
|
+
install_dir=INSTALL_DIRS[CANONICAL_TARGET],
|
|
459
|
+
force=args.force,
|
|
460
|
+
dry_run=args.dry_run,
|
|
461
|
+
do_validate=args.validate,
|
|
462
|
+
)
|
|
463
|
+
totals = {"linked": 0, "skipped": stored["skipped"], "failed": stored["failed"]}
|
|
464
|
+
for target in targets:
|
|
465
|
+
if target == CANONICAL_TARGET:
|
|
466
|
+
continue
|
|
467
|
+
result = link_skills(
|
|
468
|
+
skill_map=skill_map,
|
|
469
|
+
target=target,
|
|
470
|
+
force=args.force,
|
|
471
|
+
dry_run=args.dry_run,
|
|
472
|
+
)
|
|
473
|
+
totals["linked"] += result["linked"]
|
|
474
|
+
totals["skipped"] += result["skipped"]
|
|
475
|
+
totals["failed"] += result["failed"]
|
|
476
|
+
|
|
477
|
+
print(
|
|
478
|
+
f"\nTotal: {stored['stored']} stored, {totals['linked']} linked, "
|
|
479
|
+
f"{totals['skipped']} skipped, {totals['failed']} failed."
|
|
480
|
+
)
|
|
481
|
+
|
|
482
|
+
return 1 if totals["failed"] else 0
|
|
483
|
+
|
|
484
|
+
|
|
485
|
+
if __name__ == "__main__":
|
|
486
|
+
sys.exit(main())
|