|
2 | 2 | import socket |
3 | 3 | import subprocess |
4 | 4 | import tempfile |
| 5 | +import warnings |
5 | 6 | from pathlib import Path |
6 | 7 |
|
7 | 8 | REPO_URL = "https://github.com/diffpy/cmi-agent-skills" |
8 | | -DIR_NAME = "cmi-skill" |
9 | 9 |
|
10 | 10 |
|
11 | 11 | def ensure_setup(): |
@@ -35,21 +35,31 @@ def agentify(args): |
35 | 35 | elif agent == "codex": |
36 | 36 | skills_dir = ".codex/skills" |
37 | 37 | if system_flag: |
38 | | - destination = Path().home() / skills_dir / DIR_NAME |
| 38 | + dest_dir = Path().home() / skills_dir |
39 | 39 | else: |
40 | | - destination = Path().cwd() / skills_dir / DIR_NAME |
41 | | - if destination.exists() and not args.update: |
42 | | - raise FileExistsError( |
43 | | - f"Agentic skill {DIR_NAME} already exists at {destination}. " |
44 | | - "To overwrite, pass '--update' flag to update the skill" |
45 | | - ) |
| 40 | + dest_dir = Path().cwd() / skills_dir |
46 | 41 | with tempfile.TemporaryDirectory() as tmp: |
47 | 42 | tmp_path = Path(tmp) |
48 | 43 | subprocess.run( |
49 | 44 | ["git", "clone", REPO_URL, str(tmp_path)], |
50 | 45 | check=True, |
51 | 46 | ) |
52 | | - if destination.exists(): |
53 | | - shutil.rmtree(destination) |
54 | | - shutil.copytree(tmp_path / DIR_NAME, destination, dirs_exist_ok=True) |
55 | | - print(f"Agentic skill {DIR_NAME} has been deployed to {destination}") |
| 47 | + for item in tmp_path.iterdir(): |
| 48 | + if item.is_dir(): |
| 49 | + destination = dest_dir / item.name |
| 50 | + if destination.exists(): |
| 51 | + if args.update: |
| 52 | + shutil.rmtree(destination) |
| 53 | + shutil.copytree(item, destination, dirs_exist_ok=True) |
| 54 | + print(f"Updated existing skill at {destination}") |
| 55 | + else: |
| 56 | + warnings.warn( |
| 57 | + f"Skill at {destination} already exists. " |
| 58 | + "Use '--update' flag to overwrite." |
| 59 | + ) |
| 60 | + continue |
| 61 | + else: |
| 62 | + shutil.copytree(item, destination, dirs_exist_ok=True) |
| 63 | + print( |
| 64 | + f"Skill {item.name} has been deployed to {destination}" |
| 65 | + ) |
0 commit comments