From a5af10683da96b2c50bce1596991cb1da594e500 Mon Sep 17 00:00:00 2001 From: VAIBHAVSING Date: Fri, 14 Nov 2025 17:35:37 +0530 Subject: [PATCH] feat(devcontainer): add ai-tools bundle feature Add comprehensive AI development tools bundle as a DevContainer feature. Includes: - GitHub CLI and Copilot CLI extension - Azure CLI for cloud infrastructure - yq YAML processor - tmux with custom Dev8 configuration - CLI wrappers for GPT, Gemini, and integration with Claude - Shell aliases for AI-assisted workflows - Helper scripts for setup and configuration This bundle provides a complete AI-enhanced development environment compatible with official Microsoft DevContainer images. --- .../src/ai-tools/README.md | 199 +++++++++++ .../src/ai-tools/devcontainer-feature.json | 40 +++ .../src/ai-tools/install.sh | 338 ++++++++++++++++++ 3 files changed, 577 insertions(+) create mode 100644 packages/devcontainer-features/src/ai-tools/README.md create mode 100644 packages/devcontainer-features/src/ai-tools/devcontainer-feature.json create mode 100755 packages/devcontainer-features/src/ai-tools/install.sh diff --git a/packages/devcontainer-features/src/ai-tools/README.md b/packages/devcontainer-features/src/ai-tools/README.md new file mode 100644 index 0000000..84ef8cd --- /dev/null +++ b/packages/devcontainer-features/src/ai-tools/README.md @@ -0,0 +1,199 @@ +# Dev8 AI Tools Bundle + +A comprehensive bundle of AI development tools including GitHub CLI, GitHub Copilot, Azure CLI, and convenient CLI wrappers for popular AI APIs. + +## Example Usage + +```json +{ + "features": { + "ghcr.io/dev8-community/devcontainer-features/ai-tools:1": { + "installGithubCLI": true, + "installCopilot": true, + "installAzureCLI": true, + "installYq": true, + "installTmux": true, + "setupShellAliases": true + } + } +} +``` + +## Options + +| Option | Type | Default | Description | +| ------------------- | ------- | ------- | -------------------------------------- | +| `installGithubCLI` | boolean | `true` | Install GitHub CLI (gh) | +| `installCopilot` | boolean | `true` | Install GitHub Copilot CLI extension | +| `installAzureCLI` | boolean | `true` | Install Azure CLI (az) | +| `installYq` | boolean | `true` | Install yq YAML processor | +| `installTmux` | boolean | `true` | Install tmux with custom configuration | +| `setupShellAliases` | boolean | `true` | Setup convenient shell aliases | + +## What it includes + +### Core Tools + +- **GitHub CLI (gh)** - Official GitHub command-line tool +- **GitHub Copilot CLI** - AI-powered code suggestions and explanations +- **Azure CLI (az)** - Microsoft Azure command-line interface +- **yq** - YAML processor for configuration management +- **tmux** - Terminal multiplexer with custom Dev8 configuration + +### AI CLI Wrappers + +- **gpt** - CLI wrapper for OpenAI's GPT models +- **gemini** - CLI wrapper for Google's Gemini AI +- **claude** - Use with the `claude-cli` feature for Anthropic's Claude + +### Shell Aliases + +Convenient aliases for common AI-assisted workflows: + +```bash +git-explain # Explain recent git history with AI +commit-msg # Generate commit messages from staged changes +review # Get AI code review of current changes +explain # Quick explanations from Claude +suggest # GitHub Copilot suggestions +ghx # GitHub Copilot explanations +``` + +## Usage Examples + +### GitHub CLI & Copilot + +```bash +# Authenticate GitHub CLI +gh auth login + +# Setup Copilot +/usr/local/share/dev8-ai-tools/setup-copilot.sh + +# Use Copilot +gh copilot suggest "create a REST API endpoint" +gh copilot explain "docker-compose up -d" +``` + +### OpenAI GPT + +```bash +export OPENAI_API_KEY="your-key" +export GPT_MODEL="gpt-4" # optional, defaults to gpt-4 + +gpt "Explain Docker containers" +echo "def hello():" | gpt "Complete this Python function" +``` + +### Google Gemini + +```bash +export GEMINI_API_KEY="your-key" +export GEMINI_MODEL="gemini-pro" # optional + +gemini "What are DevContainers?" +cat code.py | gemini "Review this code" +``` + +### Azure CLI + +```bash +# Login to Azure +az login + +# List resources +azls # alias for: az resource list --output table + +# Deploy resources +az group create --name myResourceGroup --location eastus +``` + +### tmux + +```bash +# Start tmux session +tmux + +# Keyboard shortcuts (custom config): +# Ctrl-a | - Split horizontally +# Ctrl-a - - Split vertically +# Alt-Arrow - Navigate panes +# Ctrl-a r - Reload config +``` + +## AI-Assisted Workflows + +### Generate commit messages + +```bash +# Stage your changes +git add . + +# Generate and preview commit message +commit-msg + +# Or manually: +git diff --staged | claude "Generate a commit message" +``` + +### Code review + +```bash +# Review uncommitted changes +review + +# Review a specific diff +git diff main...feature-branch | claude --system "You are a code reviewer" "Review this" +``` + +### Explain git history + +```bash +git-explain + +# Or manually: +git log --oneline -10 | claude "Explain this git history" +``` + +## Configuration + +### API Keys + +Set these environment variables in your `.bashrc`, `.zshrc`, or DevContainer configuration: + +```bash +export GITHUB_TOKEN="ghp_..." +export OPENAI_API_KEY="sk-..." +export GEMINI_API_KEY="..." +export ANTHROPIC_API_KEY="sk-ant-..." +``` + +### tmux customization + +Edit `~/.tmux.conf` to customize tmux behavior. The default configuration includes: + +- Mouse support enabled +- Prefix key: `Ctrl-a` +- Easy pane splitting +- Status bar with timestamp + +## Requirements + +- Debian/Ubuntu-based container +- Internet access for API calls +- API keys for respective services + +## Integration with Other Features + +This feature works well with: + +- `ghcr.io/dev8-community/devcontainer-features/supervisor:1` - Workspace monitoring +- `ghcr.io/dev8-community/devcontainer-features/claude-cli:1` - Enhanced Claude CLI + +## More Information + +- [GitHub CLI Documentation](https://cli.github.com/manual/) +- [GitHub Copilot CLI](https://githubnext.com/projects/copilot-cli/) +- [Azure CLI Documentation](https://docs.microsoft.com/en-us/cli/azure/) +- [OpenAI API](https://platform.openai.com/docs) +- [Google Gemini API](https://ai.google.dev/) diff --git a/packages/devcontainer-features/src/ai-tools/devcontainer-feature.json b/packages/devcontainer-features/src/ai-tools/devcontainer-feature.json new file mode 100644 index 0000000..0bb1972 --- /dev/null +++ b/packages/devcontainer-features/src/ai-tools/devcontainer-feature.json @@ -0,0 +1,40 @@ +{ + "id": "ai-tools", + "version": "1.0.0", + "name": "Dev8 AI Tools Bundle", + "description": "Installs a comprehensive bundle of AI development tools including GitHub CLI, Copilot, Azure CLI, and productivity utilities", + "documentationURL": "https://github.com/Dev8-Community/Dev8.dev/tree/main/packages/devcontainer-features/src/ai-tools", + "options": { + "installGithubCLI": { + "type": "boolean", + "default": true, + "description": "Install GitHub CLI (gh)" + }, + "installCopilot": { + "type": "boolean", + "default": true, + "description": "Install GitHub Copilot CLI extension" + }, + "installAzureCLI": { + "type": "boolean", + "default": true, + "description": "Install Azure CLI (az)" + }, + "installYq": { + "type": "boolean", + "default": true, + "description": "Install yq YAML processor" + }, + "installTmux": { + "type": "boolean", + "default": true, + "description": "Install tmux with custom configuration" + }, + "setupShellAliases": { + "type": "boolean", + "default": true, + "description": "Setup convenient shell aliases for AI tools" + } + }, + "installsAfter": ["ghcr.io/devcontainers/features/common-utils"] +} diff --git a/packages/devcontainer-features/src/ai-tools/install.sh b/packages/devcontainer-features/src/ai-tools/install.sh new file mode 100755 index 0000000..6ecaed4 --- /dev/null +++ b/packages/devcontainer-features/src/ai-tools/install.sh @@ -0,0 +1,338 @@ +#!/bin/bash +set -e + +# Dev8 AI Tools Bundle Installation Script +# Installs GitHub CLI, Copilot, Azure CLI, and other AI development tools + +INSTALL_GITHUB_CLI=${INSTALLGITHUBCLI:-"true"} +INSTALL_COPILOT=${INSTALLCOPILOT:-"true"} +INSTALL_AZURE_CLI=${INSTALLAZURECLI:-"true"} +INSTALL_YQ=${INSTALLYQ:-"true"} +INSTALL_TMUX=${INSTALLTMUX:-"true"} +SETUP_SHELL_ALIASES=${SETUPSHELLALIASES:-"true"} + +echo "Installing Dev8 AI Tools Bundle..." + +############################################################################### +# Install GitHub CLI +############################################################################### +if [ "$INSTALL_GITHUB_CLI" = "true" ]; then + echo "Installing GitHub CLI..." + + # Detect architecture + ARCH=$(dpkg --print-architecture 2>/dev/null || echo "amd64") + + curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | \ + dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg 2>/dev/null + chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg + + echo "deb [arch=${ARCH} signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | \ + tee /etc/apt/sources.list.d/github-cli.list > /dev/null + + apt-get update -qq + apt-get install -y gh + + echo "✓ GitHub CLI installed" +fi + +############################################################################### +# Install GitHub Copilot CLI extension +############################################################################### +if [ "$INSTALL_COPILOT" = "true" ] && [ "$INSTALL_GITHUB_CLI" = "true" ]; then + echo "GitHub Copilot CLI will be available after authentication" + echo "Run: gh extension install github/gh-copilot" +fi + +############################################################################### +# Install Azure CLI +############################################################################### +if [ "$INSTALL_AZURE_CLI" = "true" ]; then + echo "Installing Azure CLI..." + curl -sL https://aka.ms/InstallAzureCLIDeb | bash > /dev/null 2>&1 + echo "✓ Azure CLI installed" +fi + +############################################################################### +# Install yq (YAML processor) +############################################################################### +if [ "$INSTALL_YQ" = "true" ]; then + echo "Installing yq..." + + # Detect architecture + ARCH=$(uname -m) + case $ARCH in + x86_64) + YQ_ARCH="amd64" + ;; + aarch64|arm64) + YQ_ARCH="arm64" + ;; + *) + echo "Unsupported architecture for yq: $ARCH" + YQ_ARCH="amd64" + ;; + esac + + wget -q -O /usr/local/bin/yq \ + "https://github.com/mikefarah/yq/releases/latest/download/yq_linux_${YQ_ARCH}" + chmod +x /usr/local/bin/yq + + echo "✓ yq installed" +fi + +############################################################################### +# Install tmux with configuration +############################################################################### +if [ "$INSTALL_TMUX" = "true" ]; then + echo "Installing tmux..." + apt-get update -qq + apt-get install -y tmux + + # Create a default tmux configuration + mkdir -p /etc/skel + cat > /etc/skel/.tmux.conf << 'TMUX_CONF' +# Dev8 tmux configuration + +# Set prefix to Ctrl-a (easier than Ctrl-b) +unbind C-b +set-option -g prefix C-a +bind-key C-a send-prefix + +# Split panes with | and - +bind | split-window -h +bind - split-window -v +unbind '"' +unbind % + +# Switch panes with Alt-arrow without prefix +bind -n M-Left select-pane -L +bind -n M-Right select-pane -R +bind -n M-Up select-pane -U +bind -n M-Down select-pane -D + +# Enable mouse mode +set -g mouse on + +# Set easier window split keys +bind-key v split-window -h +bind-key h split-window -v + +# Easy config reload +bind-key r source-file ~/.tmux.conf \; display-message "Config reloaded" + +# Start windows and panes at 1, not 0 +set -g base-index 1 +setw -g pane-base-index 1 + +# History limit +set-option -g history-limit 10000 + +# Status bar +set -g status-style bg=colour235,fg=colour136 +set -g status-left '#[fg=colour235,bg=colour136,bold] Dev8 ' +set -g status-right '#[fg=colour136,bg=colour235] %Y-%m-%d %H:%M ' +TMUX_CONF + + echo "✓ tmux installed with custom configuration" +fi + +############################################################################### +# Setup AI tool helper scripts +############################################################################### +echo "Setting up AI tool helper scripts..." + +# Create helpers directory +mkdir -p /usr/local/share/dev8-ai-tools + +# GitHub Copilot helper +cat > /usr/local/share/dev8-ai-tools/setup-copilot.sh << 'COPILOT_SCRIPT' +#!/bin/bash +# GitHub Copilot CLI Setup Helper + +if ! command -v gh &> /dev/null; then + echo "Error: GitHub CLI (gh) is not installed" + exit 1 +fi + +if ! gh auth status >/dev/null 2>&1; then + echo "GitHub CLI not authenticated." + echo "Please authenticate with: gh auth login" + exit 1 +fi + +# Install Copilot extension if not already installed +if ! gh extension list | grep -q "github/gh-copilot"; then + echo "Installing GitHub Copilot CLI extension..." + gh extension install github/gh-copilot + echo "✓ GitHub Copilot CLI installed" +else + echo "✓ GitHub Copilot CLI is already installed" +fi + +echo "" +echo "GitHub Copilot CLI is ready!" +echo "Usage:" +echo " gh copilot suggest 'create a function to sort an array'" +echo " gh copilot explain 'git rebase -i HEAD~3'" +COPILOT_SCRIPT + +chmod +x /usr/local/share/dev8-ai-tools/setup-copilot.sh + +# GPT CLI helper (for OpenAI API) +cat > /usr/local/bin/gpt << 'GPT_SCRIPT' +#!/bin/bash +# Simple GPT CLI wrapper for OpenAI API + +if [ -z "$OPENAI_API_KEY" ]; then + echo "Error: OPENAI_API_KEY environment variable not set" >&2 + exit 1 +fi + +PROMPT="$*" +if [ -z "$PROMPT" ] && [ ! -t 0 ]; then + PROMPT=$(cat) +fi + +if [ -z "$PROMPT" ]; then + echo "Usage: gpt " >&2 + echo " or: echo 'prompt' | gpt" >&2 + exit 1 +fi + +MODEL="${GPT_MODEL:-gpt-4}" + +# Escape JSON +ESCAPED=$(echo "$PROMPT" | python3 -c 'import json, sys; print(json.dumps(sys.stdin.read()))') + +curl -s https://api.openai.com/v1/chat/completions \ + -H "Content-Type: application/json" \ + -H "Authorization: Bearer $OPENAI_API_KEY" \ + -d "{ + \"model\": \"$MODEL\", + \"messages\": [{\"role\": \"user\", \"content\": $ESCAPED}] + }" | python3 -c 'import json, sys; print(json.load(sys.stdin)["choices"][0]["message"]["content"])' +GPT_SCRIPT + +chmod +x /usr/local/bin/gpt + +# Gemini CLI helper (for Google AI) +cat > /usr/local/bin/gemini << 'GEMINI_SCRIPT' +#!/bin/bash +# Simple Gemini CLI wrapper for Google AI API + +if [ -z "$GEMINI_API_KEY" ]; then + echo "Error: GEMINI_API_KEY environment variable not set" >&2 + exit 1 +fi + +PROMPT="$*" +if [ -z "$PROMPT" ] && [ ! -t 0 ]; then + PROMPT=$(cat) +fi + +if [ -z "$PROMPT" ]; then + echo "Usage: gemini " >&2 + echo " or: echo 'prompt' | gemini" >&2 + exit 1 +fi + +MODEL="${GEMINI_MODEL:-gemini-pro}" + +# Escape JSON +ESCAPED=$(echo "$PROMPT" | python3 -c 'import json, sys; print(json.dumps(sys.stdin.read()))') + +curl -s "https://generativelanguage.googleapis.com/v1beta/models/${MODEL}:generateContent?key=${GEMINI_API_KEY}" \ + -H "Content-Type: application/json" \ + -d "{ + \"contents\": [{ + \"parts\": [{\"text\": $ESCAPED}] + }] + }" | python3 -c 'import json, sys; print(json.load(sys.stdin)["candidates"][0]["content"]["parts"][0]["text"])' +GEMINI_SCRIPT + +chmod +x /usr/local/bin/gemini + +echo "✓ AI tool helpers installed" + +############################################################################### +# Setup shell aliases +############################################################################### +if [ "$SETUP_SHELL_ALIASES" = "true" ]; then + echo "Setting up shell aliases..." + + cat > /etc/profile.d/dev8-ai-tools.sh << 'ALIASES' +# Dev8 AI Tools Aliases + +# Git helpers with AI +alias git-explain='git log --oneline --decorate | head -10 | claude "Explain this git history"' +alias commit-msg='git diff --staged | claude "Generate a concise commit message for these changes"' + +# Code review +alias review='git diff | claude --system "You are a code reviewer. Provide constructive feedback." "Review this code"' + +# Quick explanations +alias explain='claude --system "You are a helpful programming assistant. Explain things clearly and concisely."' + +# Copilot shortcuts (if available) +if command -v gh &> /dev/null; then + alias suggest='gh copilot suggest' + alias ghx='gh copilot explain' +fi + +# Azure shortcuts +if command -v az &> /dev/null; then + alias azls='az resource list --output table' + alias azlogin='az login' +fi +ALIASES + + echo "✓ Shell aliases configured" +fi + +############################################################################### +# Cleanup +############################################################################### +apt-get clean +rm -rf /var/lib/apt/lists/* + +############################################################################### +# Verify installations +############################################################################### +echo "" +echo "=== Verifying installations ===" + +if [ "$INSTALL_GITHUB_CLI" = "true" ]; then + gh --version | head -1 || echo "✗ GitHub CLI failed" +fi + +if [ "$INSTALL_AZURE_CLI" = "true" ]; then + az version --output tsv 2>/dev/null | head -1 || echo "✗ Azure CLI failed" +fi + +if [ "$INSTALL_YQ" = "true" ]; then + yq --version || echo "✗ yq failed" +fi + +if [ "$INSTALL_TMUX" = "true" ]; then + tmux -V || echo "✗ tmux failed" +fi + +echo "✓ Dev8 AI Tools Bundle installed successfully!" +echo "" +echo "Available tools:" +[ "$INSTALL_GITHUB_CLI" = "true" ] && echo " - gh (GitHub CLI)" +[ "$INSTALL_COPILOT" = "true" ] && echo " - Run /usr/local/share/dev8-ai-tools/setup-copilot.sh to setup Copilot" +[ "$INSTALL_AZURE_CLI" = "true" ] && echo " - az (Azure CLI)" +[ "$INSTALL_YQ" = "true" ] && echo " - yq (YAML processor)" +[ "$INSTALL_TMUX" = "true" ] && echo " - tmux (terminal multiplexer)" +echo " - gpt (OpenAI GPT CLI wrapper)" +echo " - gemini (Google Gemini CLI wrapper)" +echo " - claude (Anthropic Claude CLI - install claude-cli feature)" +echo "" +echo "Set API keys as environment variables:" +echo " - GITHUB_TOKEN (for GitHub CLI & Copilot)" +echo " - OPENAI_API_KEY (for GPT CLI)" +echo " - GEMINI_API_KEY (for Gemini CLI)" +echo " - ANTHROPIC_API_KEY (for Claude CLI)" + +echo "Installation complete!"