Code Review & Analysis Commands

VritraAI provides powerful AI-powered code review and analysis tools that help you improve code quality, security, and performance. These commands analyze your code and provide actionable recommendations.

Note: All code review commands require AI to be enabled. Configure your API key using the apikey command.

Comprehensive Code Review

review <file|directory> [--focus=<area>]

AI-powered comprehensive code review that analyzes code for bugs, performance issues, security vulnerabilities, code quality, and best practices.

Features:

  • 🐛 Bugs & Issues: Logic errors, potential crashes, edge cases
  • Performance: Optimization opportunities, algorithmic improvements
  • 🔒 Security: Vulnerabilities, input validation, security best practices
  • 🎯 Code Quality: Readability, maintainability, design patterns
  • Best Practices: Language-specific conventions, modern practices
  • 📊 Metrics: Complexity assessment, code smells

Focus Areas:

You can focus the review on specific areas using the --focus parameter:

  • security - Focus on security vulnerabilities and best practices
  • performance - Focus on performance optimizations and bottlenecks
  • style - Focus on code style, formatting, and conventions

Parameters:

  • file - Single file to review
  • directory - Review all code files in directory
  • --focus=<area> - (Optional) Focus on specific area (security, performance, style)

Examples:

# Review a single file
review app.py

# Review with focus on security
review app.py --focus=security

# Review with focus on performance
review app.py --focus=performance

# Review entire directory
review src/

# Review directory with focus
review src/ --focus=style

Output Format:

The review provides:

  • Specific feedback with line references
  • Severity levels (Critical/High/Medium/Low)
  • Actionable recommendations
  • Code examples for improvements
  • Structured review report

Note: Large files (over 8000 characters) are automatically truncated for analysis. The review will indicate when truncation occurs.

Command Explanation

explain_last

Explain the last executed system command and its output using AI. Automatically analyzes command execution, exit codes, and provides explanations, fixes, and recommendations.

Features:

  • Automatic command logging (system commands and whitelisted built-ins)
  • Output capture including Rich-formatted output
  • Context-aware analysis (OS, working directory, system info)
  • Exit code interpretation
  • Fix suggestions for failed commands
  • Optimization tips for successful commands
  • Related commands suggestions

How It Works:

  1. System commands are automatically logged to ~/.config-vritrasecz/vritraai/lastcmd.log
  2. Command output, exit code, and timestamp are captured
  3. AI analyzes the command execution with full context
  4. Provides comprehensive explanation and recommendations

Examples:

# Execute a command
ls -lah /usr/bin

# Get AI explanation
explain_last

# Execute another command
git status

# Explain it
explain_last

What It Provides:

  • What happened: Explanation of what the command did or attempted to do
  • Why it succeeded/failed: Detailed analysis of exit code and output
  • Fixes/Recommendations: Specific fixes for failures or optimization tips for success
  • Context: How the command relates to current working directory and system environment
  • Possible fixing commands: Commands to fix issues if the command failed

Note: Only system commands and whitelisted built-in commands are logged. VritraAI built-in commands are not logged for explain_last.

Security Vulnerability Scanning

security_scan <file|directory>

AI-powered security vulnerability scan that identifies security issues, vulnerabilities, and provides remediation steps.

Features:

  • 🚨 Critical Vulnerabilities: SQL injection, XSS, code injection, etc.
  • ⚠️ High-Risk Issues: Authentication bypasses, privilege escalation
  • 🔍 Medium-Risk Issues: Information disclosure, weak cryptography
  • 💡 Best Practices: Security hardening recommendations

Security Areas Checked:

  • Input validation and sanitization
  • Authentication and authorization
  • Cryptographic implementations
  • File operations and path traversal
  • Network requests and data transmission
  • Error handling and information disclosure
  • Dependencies and third-party libraries
  • Configuration and secrets management

Parameters:

  • file - Single file to scan
  • directory - Scan all code files in directory

Examples:

# Scan a single file
security_scan app.py

# Scan entire directory
security_scan src/

# Scan specific file types
security_scan handlers/

Output Format:

The security scan provides:

  • Vulnerability descriptions with CVSS-like severity ratings
  • Specific line references
  • Exploitation scenarios
  • Remediation steps
  • Secure code examples
  • Structured security assessment report

Note: When scanning directories with more than 3 files, you'll be prompted for confirmation as it may take a while.

Code Optimization

optimize_code <file> [--type=<focus>]

AI-powered code optimization that provides detailed recommendations for improving performance, memory usage, algorithms, and code structure.

Features:

  • Performance: Execution speed, bottlenecks, algorithmic improvements
  • 💾 Memory: Memory usage, garbage collection, object allocation
  • 🔄 Algorithms: Data structures, time complexity, space complexity
  • 📈 Scalability: Concurrency, parallelization, resource utilization
  • 🎯 Code Structure: Design patterns, architectural improvements

Optimization Types:

You can focus on specific optimization areas using --type:

  • performance - Execution speed, algorithmic efficiency, runtime optimizations
  • memory - Memory usage, object allocation, memory leak prevention
  • algorithm - Algorithmic improvements, data structure choices, complexity reduction
  • readability - Code clarity, maintainability, structural improvements
  • scalability - Scalability, concurrent processing, resource utilization

Parameters:

  • file - File to optimize
  • --type=<focus> - (Optional) Focus on specific optimization type

Examples:

# General optimization
optimize_code app.py

# Performance-focused optimization
optimize_code app.py --type=performance

# Memory-focused optimization
optimize_code app.py --type=memory

# Algorithm-focused optimization
optimize_code app.py --type=algorithm

Output Format:

The optimization provides:

  • Specific optimization recommendations with line references
  • Performance impact estimates (High/Medium/Low)
  • Complexity analysis improvements
  • Complete optimized version of the entire code in a code block
  • Option to save optimized code to a new file

Tip: After optimization, you'll be prompted to save the optimized code. The default filename is originalname_optimized.ext.

Code Refactoring

refactor <file> <description>

AI-powered code refactoring that restructures code based on your description. Supports refactoring patterns and language conversion.

Features:

  • Refactoring with specific goals
  • Common refactoring patterns (extract-method, extract-class, simplify, modernize)
  • Language conversion (convert code from one language to another)
  • Complete refactored code output
  • Option to save refactored code

Common Refactoring Patterns:

  • extract-method - Extract repeated code into reusable methods/functions
  • extract-class - Extract related functionality into separate classes
  • simplify - Simplify complex logic, reduce nesting, improve readability
  • modernize - Update code to use modern language features and best practices
  • single-responsibility - Ensure each function/class has a single responsibility
  • dependency-injection - Apply dependency injection patterns
  • strategy-pattern - Apply strategy pattern for conditional logic

Language Conversion:

The refactor command can also convert code between languages. Use keywords like "convert to", "translate to", "port to", or "rewrite in":

  • Python, JavaScript, TypeScript, Java, Go, Rust, C/C++, Ruby, PHP, Bash

Parameters:

  • file - File to refactor
  • description - Description of refactoring goal or pattern

Examples:

# General refactoring
refactor app.py "improve code organization and readability"

# Extract method pattern
refactor app.py "extract-method"

# Simplify code
refactor app.py "simplify complex logic"

# Modernize code
refactor app.py "modernize to use latest language features"

# Language conversion
refactor script.py "convert to JavaScript"
refactor app.js "translate to Python"
refactor tool.py "port to Go"

Output Format:

The refactoring provides:

  • Explanation of refactoring changes
  • Complete refactored code
  • Option to save refactored code to a new file
  • For language conversion: complete code in target language

Tip: When converting languages, the AI will generate complete, functional code in the target language with appropriate syntax and idioms.

Best Practices

  • Review before committing: Use review before committing code to catch issues early
  • Security first: Run security_scan on sensitive code or before deployment
  • Optimize iteratively: Use optimize_code with specific focus areas for targeted improvements
  • Refactor gradually: Use refactor for specific improvements rather than complete rewrites
  • Learn from explanations: Use explain_last to understand command behavior and learn
  • Review large files: Be aware that files over 8000 characters are truncated for analysis

💡 Pro Tip: Combine these commands for comprehensive code improvement: Start with review to identify issues, use security_scan for security concerns, then optimize_code for performance, and finally refactor for structural improvements.