Core Concepts

Usage Patterns & Workflows

Learn how to use AI Developer Assistant effectively in your development workflow

Usage Patterns & Workflows

AI Developer Assistant is designed to integrate seamlessly into your development workflow. This guide covers common usage patterns, best practices, and workflow integrations that will help you get the most out of the tool.

Core Usage Patterns

1. Pre-commit Code Review

The most common pattern is reviewing code before committing changes:

# Stage your changes
git add .

# Review staged changes
ai-dev review --staged --verbose

# Generate commit message
ai-dev commit-msg --staged --style conventional

# Commit with generated message
git commit -m "$(ai-dev commit-msg --staged)"

2. Pull Request Workflow

For team collaboration, integrate with pull requests:

# Create PR and get PR number
# Review with GitHub integration
ai-dev review --post-github --github-owner your-org --github-repo your-repo --pr 123

# Generate PR summary
ai-dev pr-summary --pr 123 --include-metrics

# Security scan for PR
ai-dev security-scan --severity high,critical

3. Feature Development Workflow

When developing new features:

# 1. Review new code
ai-dev review --file-patterns "src/features/new-feature/**/*.ts"

# 2. Generate tests
ai-dev test-suggest --file-patterns "src/features/new-feature/**/*.ts" --test-type unit

# 3. Security scan
ai-dev security-scan --file-patterns "src/features/new-feature/**/*.ts"

# 4. Generate documentation
ai-dev docs --file-patterns "src/features/new-feature/**/*.ts" --doc-type "api"

Development Workflows

Daily Development Routine

# Morning routine - review overnight changes
ai-dev review --base HEAD~1 --head HEAD

# During development - quick reviews
ai-dev review --file-patterns "src/**/*.ts" --verbose

# Before lunch - security check
ai-dev security-scan --severity high,critical

# End of day - comprehensive review
ai-dev review --format markdown --output-path daily-review.md

Feature Branch Workflow

# Start new feature
git checkout -b feature/new-feature

# Develop feature...
# Review feature code
ai-dev review --file-patterns "src/features/new-feature/**/*.ts"

# Generate tests for feature
ai-dev test-suggest --file-patterns "src/features/new-feature/**/*.ts"

# Security scan feature
ai-dev security-scan --file-patterns "src/features/new-feature/**/*.ts"

# Generate documentation
ai-dev docs --file-patterns "src/features/new-feature/**/*.ts"

# Commit feature
git add .
git commit -m "$(ai-dev commit-msg --staged)"

Bug Fix Workflow

# Identify bug in specific file
ai-dev review --file-patterns "src/utils/buggy-file.ts" --verbose

# Explain the problematic code
ai-dev explain --file-patterns "src/utils/buggy-file.ts" --level detailed

# Fix the bug...
# Review the fix
ai-dev review --file-patterns "src/utils/buggy-file.ts"

# Generate tests for the fix
ai-dev test-suggest --file-patterns "src/utils/buggy-file.ts" --test-type unit

# Commit fix
git commit -m "$(ai-dev commit-msg --staged)"

Language-Specific Workflows

TypeScript/JavaScript Projects

# Review TypeScript code
ai-dev review --file-patterns "src/**/*.{ts,tsx}"

# Generate Jest tests
ai-dev test-suggest --file-patterns "src/**/*.{ts,tsx}" --framework jest

# Security scan for Node.js
ai-dev security-scan --file-patterns "server/**/*.{ts,js}"

# Generate API documentation
ai-dev docs --file-patterns "src/api/**/*.ts" --doc-type "api" --format jsdoc

Python Projects

# Review Python code
ai-dev review --file-patterns "**/*.py"

# Generate pytest tests
ai-dev test-suggest --file-patterns "**/*.py" --framework pytest

# Security scan for Python
ai-dev security-scan --file-patterns "**/*.py" --categories injection,authentication

# Generate Python documentation
ai-dev docs --file-patterns "**/*.py" --format rst --include-examples

Dart/Flutter Projects

# Review Dart code
ai-dev review --file-patterns "lib/**/*.dart"

# Generate Flutter tests
ai-dev test-suggest --file-patterns "lib/**/*.dart" --framework flutter_test

# Security scan for Flutter
ai-dev security-scan --file-patterns "lib/**/*.dart"

# Generate Flutter documentation
ai-dev docs --file-patterns "lib/**/*.dart" --format markdown

Java Projects

# Review Java code
ai-dev review --file-patterns "src/**/*.java"

# Generate JUnit tests
ai-dev test-suggest --file-patterns "src/**/*.java" --framework junit

# Security scan for Java
ai-dev security-scan --file-patterns "src/**/*.java" --categories injection,authentication

# Generate JavaDoc
ai-dev docs --file-patterns "src/**/*.java" --format javadoc

CI/CD Integration

GitHub Actions Workflow

name: AI Code Review
on: [pull_request]

jobs:
  ai-review:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      
      - name: Setup Node.js
        uses: actions/setup-node@v3
        with:
          node-version: '18'
          
      - name: Install AI Developer Assistant
        run: npm install -g kg6-codex
        
      - name: Run AI Code Review
        run: |
          ai-dev review --post-github \
            --github-owner ${{ github.repository_owner }} \
            --github-repo ${{ github.event.repository.name }} \
            --pr ${{ github.event.number }}
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          GEMINI_API_KEY: ${{ secrets.GEMINI_API_KEY }}
          
      - name: Security Scan
        run: |
          ai-dev security-scan --severity high,critical \
            --format json --output-path security-report.json
          
      - name: Generate Tests
        run: |
          ai-dev test-suggest --format json --output-path test-suggestions.json

GitLab CI Pipeline

stages:
  - ai-review

ai-review:
  stage: ai-review
  image: node:18
  before_script:
    - npm install -g kg6-codex
  script:
    - ai-dev review --format markdown --output-path review.md
    - ai-dev security-scan --severity high,critical
    - ai-dev test-suggest --format json --output-path tests.json
  artifacts:
    reports:
      junit: tests.json
    paths:
      - review.md
      - security-report.json
      - tests.json
  only:
    - merge_requests

Jenkins Pipeline

pipeline {
    agent any
    
    stages {
        stage('AI Review') {
            steps {
                sh 'npm install -g kg6-codex'
                sh 'ai-dev review --format markdown --output-path review.md'
                sh 'ai-dev security-scan --severity high,critical'
                sh 'ai-dev test-suggest --format json --output-path tests.json'
            }
        }
    }
    
    post {
        always {
            archiveArtifacts artifacts: 'review.md,security-report.json,tests.json'
        }
    }
}

IDE Integration

VS Code Tasks

Create .vscode/tasks.json:

{
  "version": "2.0.0",
  "tasks": [
    {
      "label": "AI Code Review",
      "type": "shell",
      "command": "ai-dev",
      "args": ["review", "--file-patterns", "${file}"],
      "group": "build",
      "presentation": {
        "echo": true,
        "reveal": "always",
        "focus": false,
        "panel": "new"
      }
    },
    {
      "label": "AI Security Scan",
      "type": "shell",
      "command": "ai-dev",
      "args": ["security-scan", "--file-patterns", "${file}"],
      "group": "build"
    },
    {
      "label": "AI Test Generation",
      "type": "shell",
      "command": "ai-dev",
      "args": ["test-suggest", "--file-patterns", "${file}"],
      "group": "build"
    }
  ]
}

VS Code Keybindings

Add to keybindings.json:

[
  {
    "key": "ctrl+shift+r",
    "command": "workbench.action.tasks.runTask",
    "args": "AI Code Review"
  },
  {
    "key": "ctrl+shift+s",
    "command": "workbench.action.tasks.runTask",
    "args": "AI Security Scan"
  },
  {
    "key": "ctrl+shift+t",
    "command": "workbench.action.tasks.runTask",
    "args": "AI Test Generation"
  }
]

Shell Integration

Bash Aliases

Add to your .bashrc:

# AI Developer Assistant aliases
alias ai-review="ai-dev review --verbose"
alias ai-security="ai-dev security-scan --severity high,critical"
alias ai-tests="ai-dev test-suggest --include-setup --include-teardown"
alias ai-docs="ai-dev docs --include-examples --include-parameters"
alias ai-explain="ai-dev explain --level detailed"

# Quick review current file
alias ai-file="ai-dev review --file-patterns \$(basename \$(pwd))/\$(git diff --name-only HEAD~1 | head -1)"

# Review last commit
alias ai-last="ai-dev review --base HEAD~1 --head HEAD"

Zsh Functions

Add to your .zshrc:

# AI Developer Assistant functions
ai-review() {
    ai-dev review --verbose "$@"
}

ai-security() {
    ai-dev security-scan --severity high,critical "$@"
}

ai-tests() {
    ai-dev test-suggest --include-setup --include-teardown "$@"
}

# Review current branch
ai-branch() {
    ai-dev review --base main --head HEAD
}

# Review staged changes
ai-staged() {
    ai-dev review --staged --verbose
}

Best Practices

1. Regular Reviews

# Review before every commit
git add .
ai-dev review --staged
git commit -m "$(ai-dev commit-msg --staged)"

# Daily comprehensive review
ai-dev review --format markdown --output-path daily-review.md

2. Security First

# Security scan before deployment
ai-dev security-scan --severity high,critical --include-dependencies

# Regular security audits
ai-dev security-scan --format json --output-path security-audit.json

3. Test Coverage

# Generate tests for new features
ai-dev test-suggest --file-patterns "src/features/**/*.ts" --coverage-target 80

# Generate tests for bug fixes
ai-dev test-suggest --file-patterns "src/bug-fixes/**/*.ts" --test-type unit

4. Documentation

# Generate API documentation
ai-dev docs --file-patterns "src/api/**/*.ts" --doc-type "api"

# Generate README updates
ai-dev docs --file-patterns "src/**/*.ts" --doc-type "readme"

Performance Optimization

Efficient File Patterns

# Be specific with patterns
ai-dev review --file-patterns "src/utils/helper.ts"  # Good
ai-dev review --file-patterns "**/*.ts"              # Less efficient

# Exclude unnecessary files
ai-dev review --exclude-patterns "**/node_modules/**,**/dist/**,**/*.min.js"

Batch Operations

# Review multiple related files together
ai-dev review --file-patterns "src/auth/**/*.ts,src/user/**/*.ts"

# Generate tests for entire module
ai-dev test-suggest --file-patterns "src/modules/user/**/*.ts"

Output Management

# Use appropriate output formats
ai-dev review --format console                    # For quick reviews
ai-dev review --format markdown --output-path review.md  # For sharing
ai-dev review --format json --output-path review.json    # For automation

Troubleshooting Workflows

Debug Mode

# Enable debug mode for troubleshooting
ai-dev review --verbose --debug

# Check configuration
ai-dev config show
ai-dev config validate

Common Issues

# Fix permission issues
chmod +x $(which ai-dev)

# Reinstall if needed
npm uninstall -g kg6-codex
npm install -g kg6-codex

# Test installation
ai-dev --version
ai-dev --help
Start with basic workflows and gradually incorporate more advanced patterns as your team becomes comfortable with AI Developer Assistant. The key is consistency and integration into your existing development process.