#!/usr/bin/env python3 """Install the unified LatenTX Agent Skill. Python 3.9+, standard library only. Does not read API keys, call model APIs, or overwrite an existing installation. """ import argparse import hashlib import json import os from pathlib import Path, PurePosixPath import shutil import tempfile import urllib.request BASE = 'https://api.latenth.com/skills/' NAMES = ('latentx',) def download(path): request = urllib.request.Request(BASE + path, headers={'User-Agent': 'LatenTX-Skill-Installer/1'}) with urllib.request.urlopen(request, timeout=30) as response: if not response.url.startswith(BASE): raise ValueError('Unexpected download origin') data = response.read(2_000_001) if len(data) > 2_000_000: raise ValueError('Skill file exceeds size limit') return data def install(name, parent, fetch=download): if name not in NAMES: raise ValueError('Unknown skill') parent = Path(parent).expanduser() destination = parent / name if os.path.lexists(destination): raise FileExistsError(f'{destination} already exists; review changes and back it up before replacing') manifest = json.loads(fetch('manifest.json')) files = manifest['skills'][name]['files'] if not files or len(files) > 50 or 'SKILL.md' not in files: raise ValueError('Invalid package manifest') # Validate all paths before creating files. Never extract remote archives. for filename in files: path = PurePosixPath(filename) if path.is_absolute() or str(path) != filename or any(p in ('..', '.') for p in path.parts) or '\\' in filename or ':' in filename: raise ValueError('Unsafe package path') parent.mkdir(parents=True, exist_ok=True) with tempfile.TemporaryDirectory(prefix='.latentx-download-', dir=parent) as staging: staged = Path(staging) for filename, expected in files.items(): data = fetch(f'{name}/{filename}') if hashlib.sha256(data).hexdigest() != expected: raise ValueError(f'Integrity check failed: {filename}') output = staged / filename output.parent.mkdir(parents=True, exist_ok=True) output.write_bytes(data) # Exclusive creation prevents replacing an existing folder or symlink. destination.mkdir() try: for child in staged.iterdir(): shutil.move(str(child), destination / child.name) except Exception: shutil.rmtree(destination) raise return destination, manifest['version'] def main(): parser = argparse.ArgumentParser(description=__doc__) parser.add_argument('skill', choices=NAMES) group = parser.add_mutually_exclusive_group(required=True) group.add_argument('--agent', choices=('codex', 'claude')) group.add_argument('--dest', type=Path, help='Explicit parent skills directory (e.g. a project-local .claude/skills)') args = parser.parse_args() if args.dest: parent = args.dest elif args.agent == 'codex': parent = Path(os.environ.get('CODEX_HOME', str(Path.home() / '.codex'))) / 'skills' else: parent = Path.home() / '.claude' / 'skills' try: destination, version = install(args.skill, parent) except Exception as error: parser.exit(1, f'Install failed: {error}\n') print(f'Installed {args.skill} ({version}) in {destination}. Start a new agent session to load it.') if __name__ == '__main__': main()