diff --git a/.agent/scripts/coderabbit-cli.sh b/.agent/scripts/coderabbit-cli.sh index 8c83ca0322..f0b512dff9 100755 --- a/.agent/scripts/coderabbit-cli.sh +++ b/.agent/scripts/coderabbit-cli.sh @@ -10,14 +10,19 @@ # Usage: ./coderabbit-cli.sh [command] [options] # Commands: # install - Install CodeRabbit CLI -# setup - Configure API key and settings -# review - Review current changes -# analyze - Analyze specific files or directories +# auth - Authenticate with CodeRabbit (browser-based) +# review - Review uncommitted changes (--plain for AI agents) +# review-all - Review all changes including committed (--plain) # status - Check CodeRabbit CLI status # help - Show this help message # +# CLI Modes: +# --plain - Plain text output (for scripts/AI agents) +# --prompt-only - Minimal output optimized for AI agents +# --base - Compare against specific base branch +# # Author: AI DevOps Framework -# Version: 1.1.1 +# Version: 1.2.0 # License: MIT # Colors for output @@ -280,54 +285,111 @@ load_api_key() { return 0 } -# Review current changes +# Review uncommitted changes (default mode for local development) review_changes() { - print_header "Reviewing current changes with CodeRabbit..." + local mode="${1:-plain}" + local base_branch="${2:-}" + + print_header "Reviewing uncommitted changes with CodeRabbit..." if ! check_cli_installed; then print_error "CodeRabbit CLI not installed. Run: $0 install" return 1 fi - if ! load_api_key; then - return 1 + print_info "Analyzing uncommitted git changes..." + + # Build command based on mode + local cmd="coderabbit" + case "$mode" in + "plain") + cmd="$cmd --plain --type uncommitted" + ;; + "prompt-only") + cmd="$cmd --prompt-only --type uncommitted" + ;; + "interactive") + cmd="$cmd --type uncommitted" + ;; + esac + + # Add base branch if specified + if [[ -n "$base_branch" ]]; then + cmd="$cmd --base $base_branch" fi - print_info "Analyzing current git changes..." - if coderabbit review; then + print_info "Running: $cmd" + if eval "$cmd"; then print_success "Code review completed" return 0 else print_error "Code review failed" return 1 fi - return 0 } -# Analyze specific files or directories -analyze_code() { - local target="${1:-.}" +# Review all changes (committed + uncommitted) +review_all_changes() { + local mode="${1:-plain}" + local base_branch="${2:-}" - print_header "Analyzing code with CodeRabbit: $target" + print_header "Reviewing all changes with CodeRabbit..." if ! check_cli_installed; then print_error "CodeRabbit CLI not installed. Run: $0 install" return 1 fi - if ! load_api_key; then + print_info "Analyzing all git changes (committed + uncommitted)..." + + # Build command based on mode + local cmd="coderabbit" + case "$mode" in + "plain") + cmd="$cmd --plain --type all" + ;; + "prompt-only") + cmd="$cmd --prompt-only --type all" + ;; + "interactive") + cmd="$cmd --type all" + ;; + esac + + # Add base branch if specified + if [[ -n "$base_branch" ]]; then + cmd="$cmd --base $base_branch" + fi + + print_info "Running: $cmd" + if eval "$cmd"; then + print_success "Code review completed" + return 0 + else + print_error "Code review failed" + return 1 + fi +} + +# Authenticate with CodeRabbit (browser-based OAuth) +auth_login() { + print_header "Authenticating with CodeRabbit..." + + if ! check_cli_installed; then + print_error "CodeRabbit CLI not installed. Run: $0 install" return 1 fi - print_info "Running CodeRabbit analysis on: $target" - if coderabbit analyze "$target"; then - print_success "Code analysis completed" + print_info "Opening browser for authentication..." + print_info "Follow the prompts to sign in and copy the access token." + + if coderabbit auth login; then + print_success "Authentication successful" return 0 else - print_error "Code analysis failed" + print_error "Authentication failed" return 1 fi - return 0 } # Check CodeRabbit CLI status @@ -357,40 +419,62 @@ show_help() { echo "Usage: $0 [command] [options]" echo "" echo "Commands:" - echo " install - Install CodeRabbit CLI" - echo " setup - Configure API key and settings" - echo " review - Review current git changes" - echo " analyze - Analyze specific files or directories" - echo " status - Check CodeRabbit CLI status" - echo " help - Show this help message" + echo " install - Install CodeRabbit CLI" + echo " auth - Authenticate with CodeRabbit (browser-based)" + echo " review [mode] [base] - Review uncommitted changes" + echo " review-all [mode] [base] - Review all changes (committed + uncommitted)" + echo " status - Check CodeRabbit CLI status" + echo " reviews - Fetch CodeRabbit reviews from GitHub PRs" + echo " fix - Apply auto-fixes to a file" + echo " help - Show this help message" + echo "" + echo "Review modes:" + echo " plain - Plain text output (default, best for scripts/AI)" + echo " prompt-only - Minimal output optimized for AI agents" + echo " interactive - Full interactive TUI mode" echo "" echo "Examples:" - echo " $0 install" - echo " $0 setup" - echo " $0 review" - echo " $0 analyze .agent/scripts/" - echo " $0 status" + echo " $0 install # Install CLI" + echo " $0 auth # Authenticate (browser)" + echo " $0 review # Review uncommitted (plain mode)" + echo " $0 review prompt-only # Review for AI agents" + echo " $0 review plain develop # Review against develop branch" + echo " $0 review-all # Review all changes" + echo " $0 status # Check CLI status" echo "" - echo "For more information, visit: https://www.coderabbit.ai/cli" + echo "Direct CLI usage (equivalent commands):" + echo " coderabbit --plain # Plain text review" + echo " coderabbit --prompt-only # AI agent optimized" + echo " coderabbit --type uncommitted # Only uncommitted changes" + echo " coderabbit --base develop # Compare against develop" + echo "" + echo "For more information: https://docs.coderabbit.ai/cli/overview" return 0 } # Main function main() { local command="${1:-help}" + local arg2="${2:-}" + local arg3="${3:-}" case "$command" in "install") install_cli ;; + "auth"|"login") + auth_login + ;; "setup") - setup_api_key + # Legacy: redirect to auth + print_warning "setup is deprecated, use 'auth' instead" + auth_login ;; "review") - review_changes + review_changes "$arg2" "$arg3" ;; - "analyze") - analyze_code "$_arg2" + "review-all") + review_all_changes "$arg2" "$arg3" ;; "status") check_status @@ -399,7 +483,7 @@ main() { get_coderabbit_reviews ;; "fix") - apply_coderabbit_fixes "$_arg2" + apply_coderabbit_fixes "$arg2" ;; "help"|"--help"|"-h") show_help diff --git a/.agent/tools/code-review/coderabbit.md b/.agent/tools/code-review/coderabbit.md index 61dc16def0..7aa2fc8117 100644 --- a/.agent/tools/code-review/coderabbit.md +++ b/.agent/tools/code-review/coderabbit.md @@ -1,5 +1,5 @@ --- -description: CodeRabbit AI code review integration +description: CodeRabbit AI code review - CLI and PR integration mode: subagent tools: read: true @@ -12,90 +12,138 @@ tools: task: true --- -# CodeRabbit Analysis Trigger +# CodeRabbit AI Code Review ## Quick Reference -- Purpose: Trigger CodeRabbit AI analysis on pull requests -- Analysis scope: Shell scripts (.agent/scripts/), MCP configs, docs/ -- Goals: Code quality improvements, framework enhancements, documentation quality -- Expected fixes: Variable quoting, error handling, return checks, path handling -- Config validation: JSON schema, env vars, API keys, security -- Docs fixes: Markdown linting, code blocks, links, formatting -- Post-analysis: Review suggestions, apply auto-fixes, test, commit, close PR +- **Purpose**: AI-powered code review via CLI (local) and PR (GitHub/GitLab) +- **CLI Install**: `curl -fsSL https://cli.coderabbit.ai/install.sh | sh` +- **CLI Auth**: `coderabbit auth login` (browser-based OAuth) +- **Review uncommitted**: `coderabbit --plain` or `coderabbit --prompt-only` +- **Review all changes**: `coderabbit --plain --type all` +- **Compare branch**: `coderabbit --plain --base develop` +- **Helper script**: `~/.aidevops/agents/scripts/coderabbit-cli.sh` +- **Docs**: https://docs.coderabbit.ai/cli/overview + +## CLI Modes + +| Mode | Command | Use Case | +|------|---------|----------| +| Plain | `coderabbit --plain` | Scripts, AI agents, readable output | +| Prompt-only | `coderabbit --prompt-only` | AI agent integration (minimal) | +| Interactive | `coderabbit` | Manual review with TUI | + +## Review Types + +| Type | Flag | Description | +|------|------|-------------| +| All | `--type all` | Committed + uncommitted (default) | +| Uncommitted | `--type uncommitted` | Only working directory changes | +| Committed | `--type committed` | Only committed changes | + +## Rate Limits + +- Free: 2 reviews/hour +- Pro: 8 reviews/hour +- Paid users get learnings-powered reviews from codebase history + -This file is created to trigger CodeRabbit analysis and gather auto-fix recommendations. +## Installation -## 🎯 **Analysis Goals** +```bash +# Install CLI +curl -fsSL https://cli.coderabbit.ai/install.sh | sh -### **Code Quality Improvements** +# Restart shell or reload config +source ~/.zshrc -- Identify potential auto-fixes for shell scripts -- Analyze MCP integration code for best practices -- Review documentation for consistency and clarity -- Detect any security or performance issues +# Authenticate (opens browser) +coderabbit auth login +``` -### **Framework Enhancements** +## Usage Examples -- Validate MCP configuration templates -- Review setup and validation scripts -- Analyze error handling patterns -- Check for code duplication or optimization opportunities +### Local Code Review (Before Commit) -### **Documentation Quality** +```bash +# Review uncommitted changes (plain text for AI agents) +coderabbit --plain -- Review Markdown formatting and structure -- Validate code examples and snippets -- Check for broken links or references -- Ensure consistency across documentation files +# Review with minimal output for AI agent integration +coderabbit --prompt-only -## 🔧 **Expected Auto-Fixes** +# Review against specific base branch +coderabbit --plain --base develop -### **Shell Script Improvements** +# Review only uncommitted changes +coderabbit --plain --type uncommitted +``` -- Variable quoting and expansion -- Error handling enhancements -- Function return value checks -- Path handling improvements +### AI Agent Integration -### **Configuration Validation** +For Claude Code, Cursor, or other AI coding agents: -- JSON schema validation -- Environment variable handling -- API key management best practices -- Security configuration reviews +```text +Run coderabbit --prompt-only in the background, let it take as long as it needs, +and fix any critical issues it finds. Ignore nits. +``` -### **Documentation Enhancements** +### Helper Script -- Markdown linting fixes -- Code block language specifications -- Link validation and updates -- Formatting consistency improvements +```bash +# Using aidevops helper script +~/.aidevops/agents/scripts/coderabbit-cli.sh install +~/.aidevops/agents/scripts/coderabbit-cli.sh auth +~/.aidevops/agents/scripts/coderabbit-cli.sh review # plain mode +~/.aidevops/agents/scripts/coderabbit-cli.sh review prompt-only # AI mode +~/.aidevops/agents/scripts/coderabbit-cli.sh review plain develop # vs develop +~/.aidevops/agents/scripts/coderabbit-cli.sh status +``` -## 📊 **Analysis Scope** +## PR-Based Reviews -This analysis covers: +CodeRabbit also provides automatic PR reviews on GitHub/GitLab: -- All shell scripts in `.agent/scripts/` -- MCP configuration templates in `configs/mcp-templates/` -- Documentation files in `docs/` -- Main README.md and configuration files -- Setup and validation automation scripts +1. Install CodeRabbit GitHub App: https://github.com/apps/coderabbitai +2. Reviews appear automatically on PRs +3. Use `@coderabbitai` commands in PR comments -## 🚀 **Post-Analysis Actions** +## Analysis Scope -After CodeRabbit analysis: +CodeRabbit analyzes: -1. Review all suggested improvements -2. Apply auto-fixes where appropriate -3. Implement manual fixes for complex issues -4. Update documentation based on recommendations -5. Re-run validation scripts to ensure functionality -6. Commit improvements and close this PR +- Race conditions, memory leaks, security vulnerabilities +- Logic errors, null pointer exceptions +- Code style and best practices +- Documentation quality ---- +## Expected Fixes + +| Category | Examples | +|----------|----------| +| Shell scripts | Variable quoting, error handling, return checks | +| Security | SQL injection, credential exposure, input validation | +| Performance | Memory leaks, inefficient loops, resource cleanup | +| Documentation | Markdown formatting, code blocks, broken links | + +## Troubleshooting + +```bash +# Check CLI status +coderabbit --version + +# Re-authenticate if token expired +coderabbit auth login + +# Check if in git repo +git status +``` + +## Resources -**This PR will be closed after CodeRabbit analysis is complete and recommendations are implemented.** +- CLI Docs: https://docs.coderabbit.ai/cli/overview +- Claude Code Integration: https://docs.coderabbit.ai/cli/claude-code-integration +- Cursor Integration: https://docs.coderabbit.ai/cli/cursor-integration