-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.py
More file actions
346 lines (277 loc) · 9.75 KB
/
install.py
File metadata and controls
346 lines (277 loc) · 9.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
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
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
#!/usr/bin/env python3
"""
Skills Installer
Install skills from the cycleuser/Skills repository to your local environment.
Supports installation from local directory or GitHub URL.
"""
import argparse
import json
import os
import shutil
import sys
import urllib.request
import zipfile
from pathlib import Path
from typing import Optional
REPO_URL = "https://github.com/cycleuser/Skills"
RAW_URL = "https://raw.githubusercontent.com/cycleuser/Skills/main"
def get_default_install_dir() -> Path:
"""Get default installation directory based on platform."""
home = Path.home()
# Check for existing .opencode directory
opencode_dir = home / ".opencode" / "skills"
if opencode_dir.exists():
return opencode_dir
# Default to .opencode
return opencode_dir
def download_file(url: str, dest: Path) -> bool:
"""Download a file from URL."""
try:
urllib.request.urlretrieve(url, dest)
return True
except Exception as e:
print(f"Error downloading {url}: {e}")
return False
def download_skill_from_github(skill_name: str, install_dir: Path) -> bool:
"""Download a single skill from GitHub."""
skill_dir = install_dir / skill_name
# Create skill directory
skill_dir.mkdir(parents=True, exist_ok=True)
rules_dir = skill_dir / "rules"
rules_dir.mkdir(exist_ok=True)
# Download SKILL.md
skill_url = f"{RAW_URL}/skills/{skill_name}/SKILL.md"
skill_file = skill_dir / "SKILL.md"
if not download_file(skill_url, skill_file):
return False
# Try to download rules
# First, get the list of rules from a registry or try common names
common_rules = [
"registry.md",
"testing-protocol.md",
"quality-metrics.md",
"iteration-workflow.md",
"literature-search.md",
"citation-format.md",
"paper-structure.md",
"writing-style.md",
"pre-development.md",
"interface-design.md",
"documentation.md",
"sample-data.md",
"project-structure.md",
"cli-flags.md",
"api-pattern.md",
"tools-integration.md",
"context-management.md",
"tool-safety.md",
"multi-provider.md",
"memory-systems.md",
"requirement-analysis.md",
"architecture-design.md",
"task-decomposition.md",
]
for rule in common_rules:
rule_url = f"{RAW_URL}/skills/{skill_name}/rules/{rule}"
rule_file = rules_dir / rule
download_file(rule_url, rule_file) # Ignore failures
return True
def install_from_local(source_dir: Path, install_dir: Path, skills: Optional[list] = None) -> bool:
"""Install skills from local directory."""
source_skills = source_dir / "skills"
if not source_skills.exists():
print(f"Error: Skills directory not found at {source_skills}")
return False
# Create install directory
install_dir.mkdir(parents=True, exist_ok=True)
# Get list of skills to install
if skills:
skill_list = skills
else:
skill_list = [d.name for d in source_skills.iterdir() if d.is_dir() and (d / "SKILL.md").exists()]
installed = []
failed = []
for skill_name in skill_list:
source_skill = source_skills / skill_name
dest_skill = install_dir / skill_name
if not source_skill.exists():
print(f" ⚠ Skill not found: {skill_name}")
failed.append(skill_name)
continue
# Remove existing
if dest_skill.exists():
shutil.rmtree(dest_skill)
# Copy skill
shutil.copytree(source_skill, dest_skill)
installed.append(skill_name)
print(f" ✓ Installed: {skill_name}")
print(f"\nInstalled {len(installed)} skill(s)")
if failed:
print(f"Failed: {', '.join(failed)}")
return len(installed) > 0
def install_from_github(install_dir: Path, skills: Optional[list] = None) -> bool:
"""Install skills from GitHub repository."""
print(f"Installing from {REPO_URL}")
# Create install directory
install_dir.mkdir(parents=True, exist_ok=True)
# Default skills to install
if not skills:
skills = [
"skill-manager",
"master-architect",
"python-project-developer",
"software-planner",
"coding-agent-patterns",
"iteration-manager",
"academic-writer",
]
installed = []
failed = []
for skill_name in skills:
print(f" Installing {skill_name}...")
if download_skill_from_github(skill_name, install_dir):
installed.append(skill_name)
print(f" ✓ Installed: {skill_name}")
else:
failed.append(skill_name)
print(f" ✗ Failed: {skill_name}")
print(f"\nInstalled {len(installed)} skill(s)")
if failed:
print(f"Failed: {', '.join(failed)}")
return len(installed) > 0
def list_installed_skills(install_dir: Path) -> list:
"""List installed skills."""
skills = []
for skill_dir in install_dir.iterdir():
if skill_dir.is_dir() and (skill_dir / "SKILL.md").exists():
skills.append(skill_dir.name)
return sorted(skills)
def get_skill_info(skill_path: Path) -> dict:
"""Parse skill metadata from SKILL.md."""
skill_file = skill_path / "SKILL.md"
if not skill_file.exists():
return {}
content = skill_file.read_text()
# Parse frontmatter
if content.startswith("---"):
parts = content.split("---", 2)
if len(parts) >= 3:
frontmatter = parts[1].strip()
info = {}
for line in frontmatter.split("\n"):
if ":" in line:
key, value = line.split(":", 1)
info[key.strip()] = value.strip()
return info
return {}
def show_skill_info(install_dir: Path, skill_name: str):
"""Show detailed information about a skill."""
skill_path = install_dir / skill_name
if not skill_path.exists():
print(f"Skill not found: {skill_name}")
return
info = get_skill_info(skill_path)
print(f"\n{skill_name}")
print("=" * len(skill_name))
print(f"Version: {info.get('version', 'unknown')}")
print(f"Description: {info.get('description', 'No description')}")
# List rules
rules_dir = skill_path / "rules"
if rules_dir.exists():
rules = [r.stem for r in rules_dir.glob("*.md")]
if rules:
print(f"\nRules: {', '.join(rules)}")
def main():
parser = argparse.ArgumentParser(
description="Install and manage skills for AI coding agents"
)
parser.add_argument(
"command",
choices=["install", "list", "info", "uninstall", "update"],
help="Command to execute"
)
parser.add_argument(
"--source",
type=str,
default=None,
help="Source directory or URL (default: GitHub)"
)
parser.add_argument(
"--target",
type=str,
default=None,
help="Target installation directory"
)
parser.add_argument(
"--skills",
type=str,
nargs="+",
default=None,
help="Specific skills to install"
)
parser.add_argument(
"--all",
action="store_true",
help="Install all available skills"
)
args = parser.parse_args()
# Determine install directory
if args.target:
install_dir = Path(args.target)
else:
install_dir = get_default_install_dir()
if args.command == "install":
print(f"Installing skills to: {install_dir}")
if args.source:
source_path = Path(args.source)
if source_path.exists():
success = install_from_local(source_path, install_dir, args.skills)
else:
print(f"Source not found: {args.source}")
sys.exit(1)
else:
success = install_from_github(install_dir, args.skills)
if success:
print("\nInstallation complete!")
print(f"Use '/skills' to list installed skills")
else:
sys.exit(1)
elif args.command == "list":
print(f"Installed skills in: {install_dir}")
skills = list_installed_skills(install_dir)
if skills:
for skill in skills:
info = get_skill_info(install_dir / skill)
desc = info.get("description", "").split("\n")[0][:60]
print(f" {skill:30} {desc}...")
else:
print(" No skills installed")
elif args.command == "info":
if not args.skills:
print("Please specify skill name(s)")
sys.exit(1)
for skill_name in args.skills:
show_skill_info(install_dir, skill_name)
elif args.command == "uninstall":
if not args.skills:
print("Please specify skill name(s) to uninstall")
sys.exit(1)
for skill_name in args.skills:
skill_path = install_dir / skill_name
if skill_path.exists():
shutil.rmtree(skill_path)
print(f"✓ Uninstalled: {skill_name}")
else:
print(f"⚠ Not found: {skill_name}")
elif args.command == "update":
print("Updating skills...")
if args.source:
source_path = Path(args.source)
else:
source_path = Path(__file__).parent
if source_path.exists():
install_from_local(source_path, install_dir, args.skills)
else:
install_from_github(install_dir, args.skills)
if __name__ == "__main__":
main()