Skip to content

Commit cb78200

Browse files
authored
Version 0.1.2 - AI toolkit management for setting up AI-powered development tools and templates (#3)
* Added devhub aikit init that downloads boilerplates and AI rulesets * README for new command and bumped version * Exception and moved toolkit_url
1 parent 8ad421d commit cb78200

File tree

4 files changed

+105
-1
lines changed

4 files changed

+105
-1
lines changed

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,26 @@ Required environment variables:
129129
- `DEVHUB_BASE_URL` - Base URL for DevHub API
130130
- `DEVHUB_SITE_ID` - Site identifier
131131

132+
## AI Toolkit Commands
133+
134+
The DevHub CLI includes AI toolkit management for setting up AI-powered development tools and templates.
135+
136+
### `devhub aikit init`
137+
138+
Downloads and installs the DevHub AI toolkit to your current working directory.
139+
140+
```bash
141+
devhub aikit init
142+
```
143+
144+
This command will:
145+
- Download the latest AI toolkit from the DevHub CLI AI Toolkit repository
146+
- Extract all toolkit files to your current directory
147+
- Skip existing files to avoid overwriting your customizations
148+
- Provide feedback on extracted and skipped files
149+
150+
The AI toolkit includes templates, examples, and utilities for AI-powered development workflows with DevHub.
151+
132152
## Development
133153

134154
To contribute to this tool, first checkout the code. Then create a new virtual environment:

devhub/cli.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from dotenv import load_dotenv
33
import os
44

5+
from .commands.aikit import aikit
56
from .commands.theme import theme
67

78
if 'WORKING_DIR' not in os.environ:
@@ -18,4 +19,5 @@
1819
def cli():
1920
"CLI interface to devhub"
2021

22+
cli.add_command(aikit)
2123
cli.add_command(theme)

devhub/commands/aikit.py

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
import os
2+
import tempfile
3+
import zipfile
4+
import shutil
5+
from urllib.request import urlretrieve
6+
7+
import click
8+
9+
10+
@click.group()
11+
def aikit():
12+
"""AI toolkit commands for DevHub."""
13+
pass
14+
15+
16+
@aikit.command()
17+
def init(toolkit_url='https://github.com/devhub/devhub-cli-ai-toolkit/archive/refs/heads/main.zip'):
18+
"""Initialize AI toolkit by downloading and extracting toolkit files."""
19+
20+
working_dir = os.environ.get('WORKING_DIR', os.getcwd())
21+
22+
click.echo(f'Downloading AI toolkit... {toolkit_url}')
23+
24+
# Create temporary file for download
25+
with tempfile.NamedTemporaryFile(suffix='.zip', delete=False) as temp_file:
26+
temp_filename = temp_file.name
27+
28+
try:
29+
# Download the zip file
30+
urlretrieve(toolkit_url, temp_filename)
31+
click.echo('Download completed.')
32+
33+
# Extract the zip file
34+
click.echo('Extracting toolkit files...')
35+
36+
with zipfile.ZipFile(temp_filename, 'r') as zip_ref:
37+
# Get all file names in the zip
38+
all_files = zip_ref.namelist()
39+
40+
# Filter files that are in the devhub-cli-ai-toolkit-main directory
41+
toolkit_files = [f for f in all_files if f.startswith('devhub-cli-ai-toolkit-main/') and f != 'devhub-cli-ai-toolkit-main/']
42+
43+
extracted_count = 0
44+
skipped_count = 0
45+
46+
for file_path in toolkit_files:
47+
# Remove the root directory prefix
48+
relative_path = file_path[len('devhub-cli-ai-toolkit-main/'):]
49+
50+
# Skip empty relative paths or directories
51+
if not relative_path or file_path.endswith('/'):
52+
continue
53+
54+
target_path = os.path.join(working_dir, relative_path)
55+
56+
# Check if file already exists
57+
if os.path.exists(target_path):
58+
click.echo(f'Skipping existing file: {relative_path}')
59+
skipped_count += 1
60+
continue
61+
62+
# Create directory if it doesn't exist
63+
target_dir = os.path.dirname(target_path)
64+
if target_dir:
65+
os.makedirs(target_dir, exist_ok=True)
66+
67+
# Extract file
68+
with zip_ref.open(file_path) as source, open(target_path, 'wb') as target:
69+
shutil.copyfileobj(source, target)
70+
71+
click.echo(f'Extracted: {relative_path}')
72+
extracted_count += 1
73+
74+
click.echo(click.style(f'AI toolkit initialization completed!', fg='green'))
75+
click.echo(f'Extracted {extracted_count} files, skipped {skipped_count} existing files.')
76+
77+
except Exception as e:
78+
click.echo(click.style(f'Error during AI toolkit initialization: {str(e)}', fg='red'))
79+
finally:
80+
# Clean up temporary file
81+
if os.path.exists(temp_filename):
82+
os.unlink(temp_filename)

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "devhub-cli"
3-
version = "0.1.1"
3+
version = "0.1.2"
44
description = "CLI interface to devhub"
55
readme = "README.md"
66
authors = [{name = "Daniel Rust"}]

0 commit comments

Comments
 (0)