# GitHub Copilot

URL: https://docs.hanzo.ai/docs/dev/integrations/copilot

> GitHub Copilot CLI integration for AI-powered code assistance.

Hanzo Dev includes comprehensive GitHub Copilot integration for AI-powered code assistance directly from the command line.

## Setup

```bash
# Install GitHub CLI and Copilot extension
brew install gh
gh auth login
gh extension install github/copilot

# Auto-setup
dev copilot setup --install --auth
```

## Commands

### Interactive Chat

```bash
dev copilot chat
dev copilot chat --file src/main.rs
dev copilot chat "How do I implement async/await in Rust?"
```

### Code Suggestions

```bash
dev copilot suggest "function to sort array"
dev copilot suggest --file main.rs --language rust
```

### Code Review

```bash
dev copilot review src/lib.rs
dev copilot review main.rs --diff
dev copilot review main.rs --format markdown
```

### Documentation Generation

```bash
dev copilot docs "fn calculate_sum(a: i32, b: i32) -> i32" --type comment
dev copilot docs src/ --type readme --output README.md
dev copilot docs api.rs --type api
```

### Code Explanation

```bash
dev copilot explain "async fn fetch_data() -> Result<String, Error>"
dev copilot explain --file complex_algorithm.rs
dev copilot explain --level expert "impl Iterator for MyStruct"
```

### Shell Commands

```bash
dev copilot shell "find all Rust files and check them with clippy"
dev copilot shell --os macos "compress directory into tar.gz"
dev copilot shell --explain "backup database and compress"
```

### Git Integration

```bash
dev copilot commit --staged
git diff | dev copilot commit --diff -
dev copilot commit --style conventional
```

## Configuration

```toml
# ~/.code/config.toml
[copilot]
enabled = true
auto_suggest = false
code_review = true
chat_enabled = true
model = "gpt-4"
max_tokens = 4096
context_window = 10000
```

## Git Hooks

### Pre-commit

```bash
#!/bin/sh
# .git/hooks/pre-commit
dev copilot review --diff $(git diff --cached --name-only)
```

### Commit Message

```bash
#!/bin/sh
# .git/hooks/prepare-commit-msg
if [ -z "$2" ]; then
  dev copilot commit --staged > "$1"
fi
```

## CI/CD

```yaml
name: AI Code Review
on: [pull_request]
jobs:
  copilot-review:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - name: Install Hanzo Dev
        run: npm install -g @hanzo/dev
      - name: Review Changes
        run: dev copilot review --diff --format markdown > review.md
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
```
