Skip to content

AI-powered, privacy-first CLI assistant for safe terminal commands with local and cloud model support.

License

Notifications You must be signed in to change notification settings

bytestrix/cliai

CLIAI Banner

CLIAI πŸ€–

CI Documentation License: MIT Crates.io

Your intelligent CLI assistant powered by AI

CLIAI is a completely free and open-source command-line AI assistant that helps you with terminal commands, system administration, and general questions. Use your own API keys (OpenAI, Anthropic, etc.) or run locally with Ollama for maximum privacy.

✨ Features

  • πŸ”’ Privacy-First: Local AI processing with Ollama - your data never leaves your machine
  • πŸ”‘ Bring Your Own Key: Use your own OpenAI, Anthropic, or other LLM API keys
  • πŸ†“ Completely Free: No subscriptions, no hidden costs - 100% open source
  • πŸ›‘οΈ Safety-Focused: Multi-level command validation and safety checks
  • ⚑ Fast & Reliable: Built-in performance monitoring and circuit breakers
  • 🎯 Smart Command Generation: Context-aware command suggestions with explanations
  • πŸ“ Copy-Paste Safe: Clean command output without formatting artifacts
  • πŸ”„ Flexible Execution: Auto-execute, confirmation prompts, or manual copy-paste
  • πŸ“Š Comprehensive Testing: Built-in test suite with 50+ scenarios
  • 🎨 Beautiful Interface: Colored output with progress indicators

πŸš€ Quick Start

Prerequisites

Installation

πŸ”¨ From Source (Recommended)

git clone https://github.com/bytestrix/cliai.git
cd cliai
cargo build --release
sudo cp target/release/cliai /usr/local/bin/

πŸ“¦ Via Cargo

cargo install cliai

πŸ“₯ Pre-built Binaries

Download from GitHub Releases:

  • Linux: cliai-linux-x86_64.tar.gz or cliai-linux-aarch64.tar.gz
  • macOS: cliai-macos-x86_64.tar.gz or cliai-macos-aarch64.tar.gz
  • Windows: cliai-windows-x86_64.zip

Setup

  1. Choose your AI provider:

    Option A: Local AI (Ollama - Free & Private)

    # Install Ollama
    curl -fsSL https://ollama.ai/install.sh | sh
    
    # Pull a model (recommended: mistral or llama2)
    ollama pull mistral

    Option B: Cloud AI (Your API Keys)

    # Set your OpenAI API key
    cliai set-key openai sk-your-openai-key-here
    
    # Or use Anthropic Claude
    cliai set-key anthropic your-anthropic-key-here
    
    # Or other supported providers
    cliai list-providers  # See all supported providers
  2. Configure CLIAI:

# Set your preferred model
cliai select mistral              # For Ollama
# or
cliai select gpt-4               # For OpenAI
# or  
cliai select claude-3-sonnet     # For Anthropic

# Optional: Set a custom prefix
cliai set-prefix ai
  1. Start using CLIAI:
cliai "how do I list all files including hidden ones?"
# Output: ls -la
# πŸ’‘ Lists all files including hidden ones with detailed information

cliai "find all Python files in this directory"
# Output: find . -name "*.py"
# πŸ’‘ Recursively searches for Python files in current directory and subdirectories

πŸ“– Usage

Basic Commands

# Ask questions
cliai "how do I check disk usage?"
cliai "what's my IP address?"
cliai "compress this folder"

# Configuration
cliai config                    # Show current settings
cliai list-models              # List available models
cliai list-providers           # List supported AI providers
cliai select <model>           # Switch models
cliai set-key <provider> <key> # Set API key for provider
cliai clear                    # Clear chat history

# API Key Management
cliai set-key openai sk-...    # Set OpenAI API key
cliai set-key anthropic ...    # Set Anthropic API key
cliai remove-key <provider>    # Remove API key
cliai test-key <provider>      # Test API key connection

# Safety & Execution
cliai auto-execute --enable    # Enable auto-execution for safe commands
cliai dry-run --enable         # Preview commands without executing
cliai safety-level high       # Set safety level (low/medium/high)

# Monitoring
cliai provider-status          # Check AI provider status
cliai performance-status       # View performance metrics
cliai test                     # Run comprehensive test suite

Custom Prefix

Set a custom command prefix for easier access:

cliai set-prefix jarvis
# Now you can use: jarvis "list running processes"

Safety Levels

  • Low: Minimal safety checks, allows most commands
  • Medium: Balanced safety with confirmation for risky commands (default)
  • High: Maximum safety, blocks dangerous operations

πŸ—οΈ Architecture

CLIAI follows a modular architecture designed for reliability and extensibility:

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   CLI Interface │────│   Orchestrator   │────│  AI Providers   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                              β”‚                          β”‚
                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”               β”‚
                    β”‚         β”‚         β”‚               β”‚
            β”Œβ”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β” β”Œβ”€β”€β”€β–Όβ”€β”€β”€β”€β” β”Œβ”€β”€β–Όβ”€β”€β”€β”€β”€β”        β”‚
            β”‚ Intent    β”‚ β”‚Context β”‚ β”‚Command β”‚        β”‚
            β”‚Classifier β”‚ β”‚Gathererβ”‚ β”‚Validatorβ”‚       β”‚
            β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”˜        β”‚
                                                        β”‚
                              β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                              β”‚
                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                    β”‚                   β”‚
            β”Œβ”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”
            β”‚Local Ollamaβ”‚    β”‚Cloud Providers β”‚
            β”‚(Privacy)   β”‚    β”‚(Fallback)      β”‚
            β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Core Components

  • Orchestrator: Central coordinator managing AI providers and request routing
  • Intent Classifier: Determines the type of request (command, question, etc.)
  • Context Gatherer: Collects system information for better responses
  • Command Validator: Multi-layer validation with security checks
  • Execution Engine: Safe command execution with multiple modes
  • Performance Monitor: Tracks metrics and system health
  • Circuit Breakers: Automatic failover between providers

AI Provider System

CLIAI supports multiple AI providers for maximum flexibility:

  1. Local Ollama (Free & Private): Complete privacy, offline capable
  2. OpenAI (Your API Key): GPT-3.5, GPT-4, and other OpenAI models
  3. Anthropic (Your API Key): Claude models for advanced reasoning
  4. Other Providers: Additional providers can be easily added

Supported Providers:

  • Ollama (local)
  • OpenAI (gpt-3.5-turbo, gpt-4, gpt-4-turbo)
  • Anthropic (claude-3-sonnet, claude-3-haiku, claude-3-opus)
  • More providers coming soon!

πŸ›‘οΈ Security & Privacy

Privacy Protection

  • Local-First: Primary processing happens on your machine
  • No Data Collection: Commands and prompts are never logged in production
  • Minimal Logging: Only errors and performance metrics are recorded
  • Debug Mode: Explicit consent required for detailed logging

Safety Features

  • Command Validation: Multi-layer validation prevents dangerous commands
  • Placeholder Detection: Catches AI hallucinations and incomplete commands
  • Syntax Checking: Validates command syntax before execution
  • Risk Assessment: Categorizes commands by potential impact
  • Confirmation Prompts: User confirmation for sensitive operations

Safety Levels

# High Safety (Recommended for beginners)
cliai safety-level high

# Medium Safety (Balanced - default)
cliai safety-level medium

# Low Safety (Experienced users)
cliai safety-level low

πŸ§ͺ Testing

CLIAI includes a comprehensive test suite covering 50+ real-world scenarios:

# Run full test suite
cliai test

# Run specific categories
cliai test --categories "file-management,system-info"

# Quick validation
cliai test --quick

# Save results
cliai test --save results.md

Test Categories

  • File Management: File operations, permissions, searching
  • System Info: System monitoring, process management
  • Git Operations: Version control commands
  • Network: Connectivity, downloads, API calls
  • Programming: Development tools, compilation
  • Process Management: Service control, monitoring

βš™οΈ Configuration

CLIAI stores configuration in ~/.config/cliai/config.toml:

model = "mistral"
provider = "ollama"  # or "openai", "anthropic"
auto_execute = false
dry_run = false
safety_level = "Medium"
context_timeout = 5000
ollama_url = "http://localhost:11434"
prefix = "cliai"

# API Keys (stored securely)
[api_keys]
# Keys are encrypted and stored separately for security

API Key Management

CLIAI securely stores your API keys using your system's keyring:

# Set API keys
cliai set-key openai sk-your-key-here
cliai set-key anthropic your-anthropic-key

# Test connections
cliai test-key openai
cliai test-key anthropic

# Remove keys
cliai remove-key openai

πŸ”§ Development

Building from Source

git clone https://github.com/bytestrix/cliai.git
cd cliai
cargo build --release

Running Tests

# Unit tests
cargo test

# Build
cargo build --release

Project Structure

src/
β”œβ”€β”€ main.rs              # CLI interface and main entry point
β”œβ”€β”€ lib.rs               # Library exports
β”œβ”€β”€ agents/              # AI orchestration and provider management
β”‚   β”œβ”€β”€ mod.rs
β”‚   └── profiles.rs
β”œβ”€β”€ config.rs            # Configuration management
β”œβ”€β”€ context.rs           # System context gathering
β”œβ”€β”€ execution.rs         # Command execution engine
β”œβ”€β”€ validation.rs        # Command validation and safety
β”œβ”€β”€ providers.rs         # AI provider implementations
β”œβ”€β”€ history.rs           # Chat history management
β”œβ”€β”€ performance.rs       # Performance monitoring
β”œβ”€β”€ error_handling.rs    # Enhanced error reporting
β”œβ”€β”€ logging.rs           # Privacy-preserving logging
└── test_suite.rs        # Comprehensive testing framework

🀝 Contributing

We welcome contributions! Please see our Contributing Guide for details.

Development Setup

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/amazing-feature
  3. Make your changes
  4. Run tests: cargo test
  5. Commit changes: git commit -m 'Add amazing feature'
  6. Push to branch: git push origin feature/amazing-feature
  7. Open a Pull Request

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details. This means you can use, modify, and distribute the software freely, including for commercial purposes.

πŸ™ Acknowledgments

  • Ollama for making local AI accessible
  • Clap for excellent CLI parsing
  • Tokio for async runtime
  • The Rust community for amazing tools and libraries

πŸ“ž Support


Made with ❀️ by the CLIAI Team

About

AI-powered, privacy-first CLI assistant for safe terminal commands with local and cloud model support.

Resources

License

Code of conduct

Contributing

Stars

Watchers

Forks

Packages

No packages published

Languages