diff --git a/README.md b/README.md index de95051..95fc8f9 100644 --- a/README.md +++ b/README.md @@ -129,6 +129,26 @@ Required environment variables: - `DEVHUB_BASE_URL` - Base URL for DevHub API - `DEVHUB_SITE_ID` - Site identifier +## AI Toolkit Commands + +The DevHub CLI includes AI toolkit management for setting up AI-powered development tools and templates. + +### `devhub aikit init` + +Downloads and installs the DevHub AI toolkit to your current working directory. + +```bash +devhub aikit init +``` + +This command will: +- Download the latest AI toolkit from the DevHub CLI AI Toolkit repository +- Extract all toolkit files to your current directory +- Skip existing files to avoid overwriting your customizations +- Provide feedback on extracted and skipped files + +The AI toolkit includes templates, examples, and utilities for AI-powered development workflows with DevHub. + ## Development To contribute to this tool, first checkout the code. Then create a new virtual environment: diff --git a/devhub/cli.py b/devhub/cli.py index e6f06e7..cc4d86c 100644 --- a/devhub/cli.py +++ b/devhub/cli.py @@ -2,6 +2,7 @@ from dotenv import load_dotenv import os +from .commands.aikit import aikit from .commands.theme import theme if 'WORKING_DIR' not in os.environ: @@ -18,4 +19,5 @@ def cli(): "CLI interface to devhub" +cli.add_command(aikit) cli.add_command(theme) diff --git a/devhub/commands/aikit.py b/devhub/commands/aikit.py new file mode 100644 index 0000000..2b40b0e --- /dev/null +++ b/devhub/commands/aikit.py @@ -0,0 +1,82 @@ +import os +import tempfile +import zipfile +import shutil +from urllib.request import urlretrieve + +import click + + +@click.group() +def aikit(): + """AI toolkit commands for DevHub.""" + pass + + +@aikit.command() +def init(toolkit_url='https://github.com/devhub/devhub-cli-ai-toolkit/archive/refs/heads/main.zip'): + """Initialize AI toolkit by downloading and extracting toolkit files.""" + + working_dir = os.environ.get('WORKING_DIR', os.getcwd()) + + click.echo(f'Downloading AI toolkit... {toolkit_url}') + + # Create temporary file for download + with tempfile.NamedTemporaryFile(suffix='.zip', delete=False) as temp_file: + temp_filename = temp_file.name + + try: + # Download the zip file + urlretrieve(toolkit_url, temp_filename) + click.echo('Download completed.') + + # Extract the zip file + click.echo('Extracting toolkit files...') + + with zipfile.ZipFile(temp_filename, 'r') as zip_ref: + # Get all file names in the zip + all_files = zip_ref.namelist() + + # Filter files that are in the devhub-cli-ai-toolkit-main directory + toolkit_files = [f for f in all_files if f.startswith('devhub-cli-ai-toolkit-main/') and f != 'devhub-cli-ai-toolkit-main/'] + + extracted_count = 0 + skipped_count = 0 + + for file_path in toolkit_files: + # Remove the root directory prefix + relative_path = file_path[len('devhub-cli-ai-toolkit-main/'):] + + # Skip empty relative paths or directories + if not relative_path or file_path.endswith('/'): + continue + + target_path = os.path.join(working_dir, relative_path) + + # Check if file already exists + if os.path.exists(target_path): + click.echo(f'Skipping existing file: {relative_path}') + skipped_count += 1 + continue + + # Create directory if it doesn't exist + target_dir = os.path.dirname(target_path) + if target_dir: + os.makedirs(target_dir, exist_ok=True) + + # Extract file + with zip_ref.open(file_path) as source, open(target_path, 'wb') as target: + shutil.copyfileobj(source, target) + + click.echo(f'Extracted: {relative_path}') + extracted_count += 1 + + click.echo(click.style(f'AI toolkit initialization completed!', fg='green')) + click.echo(f'Extracted {extracted_count} files, skipped {skipped_count} existing files.') + + except Exception as e: + click.echo(click.style(f'Error during AI toolkit initialization: {str(e)}', fg='red')) + finally: + # Clean up temporary file + if os.path.exists(temp_filename): + os.unlink(temp_filename) \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index 163a2d8..2f75f89 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "devhub-cli" -version = "0.1.1" +version = "0.1.2" description = "CLI interface to devhub" readme = "README.md" authors = [{name = "Daniel Rust"}]