diff --git a/packages/devcontainer-features/src/claude-cli/README.md b/packages/devcontainer-features/src/claude-cli/README.md new file mode 100644 index 0000000..06969f7 --- /dev/null +++ b/packages/devcontainer-features/src/claude-cli/README.md @@ -0,0 +1,115 @@ +# Claude CLI + +A command-line interface for interacting with Anthropic's Claude AI directly from your terminal. + +## Example Usage + +```json +{ + "features": { + "ghcr.io/dev8-community/devcontainer-features/claude-cli:1": { + "version": "1.0.0", + "installShellCompletion": true + } + } +} +``` + +## Options + +| Option | Type | Default | Description | +| ------------------------ | ------- | ---------------- | ----------------------------------------- | +| `version` | string | `1.0.0` | Version of Claude CLI to install | +| `installPath` | string | `/usr/local/bin` | Installation path for Claude CLI | +| `installShellCompletion` | boolean | `true` | Install shell completion for bash and zsh | + +## What it does + +The Claude CLI provides: + +- **Direct API Access**: Interact with Claude AI from your terminal +- **Multiple Models**: Support for all Claude 3 models (Opus, Sonnet, Haiku) +- **Flexible Input**: Accept prompts as arguments or via stdin +- **System Prompts**: Customize Claude's behavior with system prompts +- **Shell Completion**: Tab completion for bash and zsh + +## Usage + +### Basic usage + +```bash +claude "What is a DevContainer?" +``` + +### Pipe input + +```bash +echo "Explain Docker" | claude +``` + +### Specify model + +```bash +claude --model claude-3-opus-20240229 "Complex question" +``` + +### Use system prompt + +```bash +claude --system "You are a helpful coding assistant" "Help me write Python" +``` + +### Available options + +```bash +claude --help +``` + +## Configuration + +Set your Anthropic API key: + +```bash +export ANTHROPIC_API_KEY="your-api-key-here" +# or +export CLAUDE_API_KEY="your-api-key-here" +``` + +Set default model: + +```bash +export CLAUDE_MODEL="claude-3-5-sonnet-20241022" +``` + +## Available Models + +- `claude-3-5-sonnet-20241022` (default) - Best balance of intelligence and speed +- `claude-3-opus-20240229` - Most capable model +- `claude-3-sonnet-20240229` - Balanced performance +- `claude-3-haiku-20240307` - Fastest model + +## Examples + +```bash +# Get code review +git diff | claude --system "You are a code reviewer" "Review this diff" + +# Generate commit messages +git diff --staged | claude "Generate a commit message for these changes" + +# Explain errors +npm test 2>&1 | claude "Explain these test failures" + +# Interactive coding assistant +claude --system "You are a pair programming assistant" "How do I implement authentication?" +``` + +## Requirements + +- `curl` - For making API requests +- `python3` - For JSON parsing +- Anthropic API key + +## More Information + +Get your API key at [console.anthropic.com](https://console.anthropic.com/) diff --git a/packages/devcontainer-features/src/claude-cli/devcontainer-feature.json b/packages/devcontainer-features/src/claude-cli/devcontainer-feature.json new file mode 100644 index 0000000..062a86f --- /dev/null +++ b/packages/devcontainer-features/src/claude-cli/devcontainer-feature.json @@ -0,0 +1,25 @@ +{ + "id": "claude-cli", + "version": "1.0.0", + "name": "Claude CLI", + "description": "Installs Claude CLI - a command-line interface for interacting with Anthropic's Claude AI", + "documentationURL": "https://github.com/Dev8-Community/Dev8.dev/tree/main/packages/devcontainer-features/src/claude-cli", + "options": { + "version": { + "type": "string", + "default": "1.0.0", + "description": "Version of Claude CLI to install" + }, + "installPath": { + "type": "string", + "default": "/usr/local/bin", + "description": "Installation path for Claude CLI" + }, + "installShellCompletion": { + "type": "boolean", + "default": true, + "description": "Install shell completion for bash and zsh" + } + }, + "installsAfter": ["ghcr.io/devcontainers/features/common-utils"] +} diff --git a/packages/devcontainer-features/src/claude-cli/install.sh b/packages/devcontainer-features/src/claude-cli/install.sh new file mode 100755 index 0000000..2ccced9 --- /dev/null +++ b/packages/devcontainer-features/src/claude-cli/install.sh @@ -0,0 +1,271 @@ +#!/bin/bash +set -e + +# Claude CLI Installation Script +# Provides a command-line interface for Anthropic's Claude AI + +VERSION=${VERSION:-"1.0.0"} +INSTALL_PATH=${INSTALLPATH:-"/usr/local/bin"} +INSTALL_SHELL_COMPLETION=${INSTALLSHELLCOMPLETION:-"true"} + +echo "Installing Claude CLI..." + +# Create the claude CLI wrapper script +cat > "$INSTALL_PATH/claude" << 'CLAUDE_SCRIPT' +#!/bin/bash +# Claude CLI - Command-line interface for Anthropic's Claude AI +# Version: 1.0.0 + +set -e + +CLAUDE_API_KEY="${CLAUDE_API_KEY:-${ANTHROPIC_API_KEY}}" +CLAUDE_MODEL="${CLAUDE_MODEL:-claude-3-5-sonnet-20241022}" +CLAUDE_API_URL="${CLAUDE_API_URL:-https://api.anthropic.com/v1/messages}" + +show_help() { + cat << EOF +Claude CLI - Command-line interface for Anthropic's Claude AI + +Usage: + claude [OPTIONS] + echo "prompt" | claude [OPTIONS] + +Options: + -m, --model MODEL Claude model to use (default: $CLAUDE_MODEL) + -t, --temperature N Temperature for responses (0.0-1.0, default: 1.0) + -k, --api-key KEY Anthropic API key (or set CLAUDE_API_KEY env var) + --max-tokens N Maximum tokens in response (default: 4096) + --system TEXT System prompt to guide Claude's behavior + -h, --help Show this help message + +Environment Variables: + CLAUDE_API_KEY Anthropic API key + ANTHROPIC_API_KEY Alternative API key variable + CLAUDE_MODEL Default model to use + CLAUDE_API_URL API endpoint URL + +Examples: + claude "What is DevContainer?" + echo "Explain Docker" | claude + claude --model claude-3-opus-20240229 "Complex question" + claude --system "You are a helpful coding assistant" "Help with Python" + +EOF +} + +# Parse arguments +PROMPT="" +TEMPERATURE="1.0" +MAX_TOKENS="4096" +SYSTEM_PROMPT="" +API_KEY="$CLAUDE_API_KEY" + +while [[ $# -gt 0 ]]; do + case $1 in + -h|--help) + show_help + exit 0 + ;; + -m|--model) + CLAUDE_MODEL="$2" + shift 2 + ;; + -t|--temperature) + TEMPERATURE="$2" + shift 2 + ;; + -k|--api-key) + API_KEY="$2" + shift 2 + ;; + --max-tokens) + MAX_TOKENS="$2" + shift 2 + ;; + --system) + SYSTEM_PROMPT="$2" + shift 2 + ;; + -*) + echo "Unknown option: $1" >&2 + echo "Use --help for usage information" >&2 + exit 1 + ;; + *) + PROMPT="$1" + shift + ;; + esac +done + +# Read from stdin if no prompt provided +if [ -z "$PROMPT" ] && [ ! -t 0 ]; then + PROMPT=$(cat) +fi + +# Validate inputs +if [ -z "$PROMPT" ]; then + echo "Error: No prompt provided" >&2 + echo "Use --help for usage information" >&2 + exit 1 +fi + +if [ -z "$API_KEY" ]; then + echo "Error: API key not found" >&2 + echo "Set CLAUDE_API_KEY or ANTHROPIC_API_KEY environment variable, or use --api-key option" >&2 + exit 1 +fi + +# Escape JSON strings +json_escape() { + python3 -c 'import json, sys; print(json.dumps(sys.stdin.read()))' +} + +# Build JSON payload +ESCAPED_PROMPT=$(echo "$PROMPT" | json_escape) + +if [ -n "$SYSTEM_PROMPT" ]; then + ESCAPED_SYSTEM=$(echo "$SYSTEM_PROMPT" | json_escape) + JSON_PAYLOAD=$(cat <&2 + echo "$BODY" | python3 -m json.tool 2>/dev/null || echo "$BODY" >&2 + exit 1 +fi + +# Extract and display the response +echo "$BODY" | python3 -c ' +import json, sys +try: + data = json.load(sys.stdin) + if "content" in data and len(data["content"]) > 0: + print(data["content"][0]["text"]) + else: + print("Error: Unexpected response format", file=sys.stderr) + print(json.dumps(data, indent=2), file=sys.stderr) + sys.exit(1) +except Exception as e: + print(f"Error parsing response: {e}", file=sys.stderr) + sys.exit(1) +' +CLAUDE_SCRIPT + +# Make the script executable +chmod +x "$INSTALL_PATH/claude" + +echo "✓ Claude CLI installed to $INSTALL_PATH/claude" + +# Install shell completion if requested +if [ "$INSTALL_SHELL_COMPLETION" = "true" ]; then + # Bash completion + BASH_COMPLETION_DIR="/etc/bash_completion.d" + if [ -d "$BASH_COMPLETION_DIR" ]; then + cat > "$BASH_COMPLETION_DIR/claude" << 'BASH_COMPLETION' +# Claude CLI bash completion +_claude_completion() { + local cur prev opts + COMPREPLY=() + cur="${COMP_WORDS[COMP_CWORD]}" + prev="${COMP_WORDS[COMP_CWORD-1]}" + opts="-h --help -m --model -t --temperature -k --api-key --max-tokens --system" + + case "${prev}" in + -m|--model) + COMPREPLY=( $(compgen -W "claude-3-5-sonnet-20241022 claude-3-opus-20240229 claude-3-sonnet-20240229 claude-3-haiku-20240307" -- ${cur}) ) + return 0 + ;; + -k|--api-key|--max-tokens|--system|-t|--temperature) + return 0 + ;; + *) + ;; + esac + + COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) + return 0 +} +complete -F _claude_completion claude +BASH_COMPLETION + echo "✓ Bash completion installed" + fi + + # Zsh completion + ZSH_COMPLETION_DIR="/usr/local/share/zsh/site-functions" + mkdir -p "$ZSH_COMPLETION_DIR" + cat > "$ZSH_COMPLETION_DIR/_claude" << 'ZSH_COMPLETION' +#compdef claude + +_claude() { + local -a opts + opts=( + '(-h --help)'{-h,--help}'[Show help message]' + '(-m --model)'{-m,--model}'[Claude model to use]:model:(claude-3-5-sonnet-20241022 claude-3-opus-20240229 claude-3-sonnet-20240229 claude-3-haiku-20240307)' + '(-t --temperature)'{-t,--temperature}'[Temperature for responses]:temperature:' + '(-k --api-key)'{-k,--api-key}'[Anthropic API key]:api-key:' + '--max-tokens[Maximum tokens in response]:max-tokens:' + '--system[System prompt]:system prompt:' + ) + _arguments $opts +} + +_claude "$@" +ZSH_COMPLETION + echo "✓ Zsh completion installed" +fi + +# Verify installation +if command -v claude &> /dev/null; then + echo "✓ Claude CLI installed successfully!" + echo "" + echo "Usage: claude \"Your prompt here\"" + echo "Set CLAUDE_API_KEY or ANTHROPIC_API_KEY environment variable to use" + echo "Run 'claude --help' for more information" +else + echo "✗ Failed to install Claude CLI" + exit 1 +fi + +echo "Installation complete!" diff --git a/packages/devcontainer-features/src/supervisor/README.md b/packages/devcontainer-features/src/supervisor/README.md new file mode 100644 index 0000000..9953686 --- /dev/null +++ b/packages/devcontainer-features/src/supervisor/README.md @@ -0,0 +1,59 @@ +# Dev8 Workspace Supervisor + +This DevContainer feature installs the Dev8 workspace supervisor - a Go binary that monitors workspace activity, performs backups, and reports health status. + +## Example Usage + +```json +{ + "features": { + "ghcr.io/dev8-community/devcontainer-features/supervisor:1": { + "version": "latest" + } + } +} +``` + +## Options + +| Option | Type | Default | Description | +| ------------- | ------ | ---------------- | --------------------------------------- | +| `version` | string | `latest` | Version of supervisor to install | +| `installPath` | string | `/usr/local/bin` | Installation path for supervisor binary | + +## What it does + +The supervisor provides: + +- **Activity Monitoring**: Tracks CPU, memory, and disk usage +- **Automated Backups**: Periodic workspace backups to Azure Files +- **Health Reporting**: Reports workspace status to the Dev8 agent +- **HTTP API**: Exposes health endpoints for monitoring + +## Configuration + +After installation, configure the supervisor by creating `/etc/dev8/supervisor/config.yaml`: + +```yaml +workspace_dir: /workspaces +monitor_interval: 30s +backup: + enabled: true + interval: 1h + retention: 7d +agent: + enabled: true + url: http://agent:8080 +``` + +## Running the Supervisor + +The supervisor is typically started automatically by the Dev8 platform. To run manually: + +```bash +supervisor +``` + +## More Information + +See the [supervisor documentation](https://github.com/Dev8-Community/Dev8.dev/tree/main/apps/supervisor) for detailed configuration options. diff --git a/packages/devcontainer-features/src/supervisor/devcontainer-feature.json b/packages/devcontainer-features/src/supervisor/devcontainer-feature.json new file mode 100644 index 0000000..2bcdbe1 --- /dev/null +++ b/packages/devcontainer-features/src/supervisor/devcontainer-feature.json @@ -0,0 +1,20 @@ +{ + "id": "supervisor", + "version": "1.0.0", + "name": "Dev8 Workspace Supervisor", + "description": "Installs the Dev8 workspace supervisor for monitoring, backups, and health checks", + "documentationURL": "https://github.com/Dev8-Community/Dev8.dev/tree/main/apps/supervisor", + "options": { + "version": { + "type": "string", + "default": "latest", + "description": "Version of supervisor to install" + }, + "installPath": { + "type": "string", + "default": "/usr/local/bin", + "description": "Installation path for supervisor binary" + } + }, + "installsAfter": ["ghcr.io/devcontainers/features/common-utils"] +} diff --git a/packages/devcontainer-features/src/supervisor/install.sh b/packages/devcontainer-features/src/supervisor/install.sh new file mode 100755 index 0000000..ef40253 --- /dev/null +++ b/packages/devcontainer-features/src/supervisor/install.sh @@ -0,0 +1,102 @@ +#!/bin/bash +set -e + +# Dev8 Workspace Supervisor Installation Script +# This script installs the supervisor binary from GitHub releases + +VERSION=${VERSION:-"latest"} +INSTALL_PATH=${INSTALLPATH:-"/usr/local/bin"} + +echo "Installing Dev8 Workspace Supervisor..." + +# Detect architecture +ARCH=$(uname -m) +case $ARCH in + x86_64) + ARCH="amd64" + ;; + aarch64|arm64) + ARCH="arm64" + ;; + *) + echo "Unsupported architecture: $ARCH" + exit 1 + ;; +esac + +# Detect OS +OS=$(uname -s | tr '[:upper:]' '[:lower:]') + +echo "Detected OS: $OS, Architecture: $ARCH" + +# GitHub repository details +REPO="Dev8-Community/Dev8.dev" +BINARY_NAME="supervisor" + +# Determine download URL +if [ "$VERSION" = "latest" ]; then + echo "Fetching latest release version..." + # For now, we'll build from source since releases may not exist yet + # In production, this would fetch from GitHub releases + + # Check if Go is installed + if ! command -v go &> /dev/null; then + echo "Go is not installed. Installing Go..." + # Download and install Go + GO_VERSION="1.22.0" + wget -q "https://go.dev/dl/go${GO_VERSION}.linux-${ARCH}.tar.gz" + tar -C /usr/local -xzf "go${GO_VERSION}.linux-${ARCH}.tar.gz" + export PATH=$PATH:/usr/local/go/bin + rm "go${GO_VERSION}.linux-${ARCH}.tar.gz" + fi + + # Build supervisor from source + echo "Building supervisor from source..." + TEMP_DIR=$(mktemp -d) + cd "$TEMP_DIR" + + # Clone the repository (or copy if we're in the repo) + if [ -d "/workspaces/Dev8.dev" ]; then + echo "Using local source code..." + cd /workspaces/Dev8.dev/apps/supervisor + else + echo "Cloning repository..." + git clone --depth 1 "https://github.com/${REPO}.git" + cd "Dev8.dev/apps/supervisor" + fi + + # Build the binary + echo "Compiling supervisor..." + cd cmd/supervisor + go build -o "$BINARY_NAME" -ldflags="-s -w" . + + # Install the binary + echo "Installing supervisor to $INSTALL_PATH..." + install -m 755 "$BINARY_NAME" "$INSTALL_PATH/$BINARY_NAME" + + # Cleanup + cd / + rm -rf "$TEMP_DIR" +else + # Download from GitHub releases + DOWNLOAD_URL="https://github.com/${REPO}/releases/download/${VERSION}/supervisor-${OS}-${ARCH}" + echo "Downloading supervisor ${VERSION} from GitHub releases..." + + wget -q "$DOWNLOAD_URL" -O "$INSTALL_PATH/$BINARY_NAME" + chmod +x "$INSTALL_PATH/$BINARY_NAME" +fi + +# Verify installation +if command -v supervisor &> /dev/null; then + echo "✓ Dev8 Workspace Supervisor installed successfully!" + supervisor --version 2>/dev/null || echo "Version: $VERSION" +else + echo "✗ Failed to install supervisor" + exit 1 +fi + +# Create default configuration directory +mkdir -p /etc/dev8/supervisor +echo "✓ Created configuration directory at /etc/dev8/supervisor" + +echo "Installation complete!"