Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions devhub/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -18,4 +19,5 @@
def cli():
"CLI interface to devhub"

cli.add_command(aikit)
cli.add_command(theme)
82 changes: 82 additions & 0 deletions devhub/commands/aikit.py
Original file line number Diff line number Diff line change
@@ -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)
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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"}]
Expand Down