Add reusable multi-session skill and five-page project workbench
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Install this self-contained skill without Git history, runtime data or dependencies."""
|
||||
import argparse
|
||||
from datetime import datetime
|
||||
import os
|
||||
from pathlib import Path
|
||||
import shutil
|
||||
import tempfile
|
||||
|
||||
|
||||
def main():
|
||||
parser=argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument('--source',default=str(Path(__file__).resolve().parents[1]))
|
||||
parser.add_argument('--destination')
|
||||
parser.add_argument('--update',action='store_true')
|
||||
args=parser.parse_args()
|
||||
source=Path(args.source).resolve()
|
||||
base=Path(os.environ.get('CODEX_HOME',str(Path.home()/'.codex')))
|
||||
target=Path(args.destination).expanduser().resolve() if args.destination else (base/'skills/project-agent-control').resolve()
|
||||
if not (source/'SKILL.md').is_file() or target==source or source.is_relative_to(target):
|
||||
raise ValueError('Invalid source or destination')
|
||||
if target.is_symlink():
|
||||
raise ValueError('Refusing to replace a symlink')
|
||||
if target.exists() and not args.update:
|
||||
raise ValueError('Destination exists; inspect it before using --update')
|
||||
target.parent.mkdir(parents=True,exist_ok=True)
|
||||
stage=Path(tempfile.mkdtemp(prefix='.agent-workbench-',dir=str(target.parent)))
|
||||
keep=('SKILL.md','README.md','LICENSE','agents','references','scripts','examples','agent_control','assets')
|
||||
ignore=shutil.ignore_patterns('node_modules','__pycache__','*.pyc','.git','.env','*.local.json')
|
||||
for name in keep:
|
||||
item=source/name
|
||||
if item.is_dir():
|
||||
shutil.copytree(item,stage/name,ignore=ignore)
|
||||
elif item.is_file():
|
||||
shutil.copy2(item,stage/name)
|
||||
if target.exists():
|
||||
backup=target.with_name(target.name+'.backup-'+datetime.now().strftime('%Y%m%d%H%M%S'))
|
||||
if backup.exists():
|
||||
raise ValueError('Backup destination exists')
|
||||
os.replace(target,backup)
|
||||
os.replace(stage,target)
|
||||
print(str(target))
|
||||
|
||||
|
||||
if __name__=='__main__':main()
|
||||
Reference in New Issue
Block a user