AI CLI is a terminal-based application that combines the power of large language models with Retrieval-Augmented Generation (RAG) capabilities. Built with Rust, it provides an interactive terminal interface for querying documents and running commands with contextual awareness.
- Dual Input Modes: Switch between RAG queries and direct command execution
- Interactive Terminal UI: Built with
ratatuifor a responsive terminal experience - Real-time Document Indexing: Index local files and directories for RAG queries
- Context-Aware Responses: LLM responses enhanced with relevant document context
- Multi-file Support: Process various file types including text, code, and documentation
- Document Scanning: Automatically scans and processes files from specified directories
- Text Chunking: Intelligently breaks down documents into searchable chunks
- Vector Embeddings: Generates embeddings using configured embedding models
- Qdrant Integration: Uses Qdrant vector database for efficient similarity search
- Context Retrieval: Retrieves relevant document chunks based on query similarity
- Split-screen Layout: Dedicated areas for context and responses
- Scrollable Views: Navigate through long context and answer content
- Keyboard Navigation: Full keyboard control with intuitive shortcuts
- Loading Indicators: Visual feedback during processing operations
- Mode Switching: Toggle between RAG and command modes
The application consists of two main components:
- Terminal UI management using
ratatuiandcrossterm - Input handling and state management
- Thread-safe communication between UI and background operations
- Command execution capabilities
- Document processing and indexing pipeline
- Vector embedding generation
- Qdrant database integration
- Query processing and response generation
- MCP integration via
mcp-client-rust(client layer for tools/resources/prompts)
- Rust toolchain (latest stable version)
- Qdrant vector database server
- Access to embedding model API (configured via environment)
- Clone the repository:
git clone <repository-url>
cd aicli- Start Qdrant server:
# Using Docker
docker run -p 6333:6333 -p 6334:6334 qdrant/qdrant- Configure environment variables:
export QDRANT_URL="http://localhost:6334"
export EMBEDDING_MODEL_API_KEY="your-api-key"
export EMBEDDING_MODEL_URL="your-embedding-model-endpoint"- Build the application:
cargo build --release- Run the application:
cargo run- Tab: Switch between RAG and Command modes
- Ctrl+O: Toggle focus between context and answer panels
- Up/Down/PgUp/PgDn: Scroll through content
- Home/End: Jump to beginning/end of content
- Esc/Ctrl+C: Exit the application
- Index Documents: Press
Ctrl+RorF2to index files from configured directories - Ask Questions: Type your query and press Enter to get context-aware responses
- View Context: The top panel shows retrieved document chunks used for generation
- Switch Mode: Press Tab to enter Command mode
- Execute Commands: Type shell commands and press Enter to execute them directly
- View Output: Command results appear in the answer panel
The application uses environment variables for configuration:
# Qdrant database connection
export QDRANT_URL="http://localhost:6334"
export QDRANT_COLLECTION="midjourney" # Default collection name
# Embedding model configuration
export EMBEDDING_MODEL_URL="your-embedding-api-endpoint"
export EMBEDDING_MODEL_API_KEY="your-api-key"
# File scanning configuration
export SCAN_DIRECTORIES="/path/to/documents,/another/path"
export FILE_EXTENSIONS=".txt,.md,.rs,.py,.js" # Comma-separated listaicli uses the mcp-client-rust crate as its MCP client layer.
Configure the MCP server endpoint/command through env vars (stdio example below):
# leave MCP_URL empty when using stdio transport
MCP_URL=
MCP_COMMAND=/Users/sudhirkumar/Desktop/sudhir/gitsudhir/mcp-server-rust/target/release/mcp-server-rust
MCP_ARGS=With your server, the agent can discover and use:
- tools:
greet,calculate-bmi,fetch-weather - resource:
config://app - prompt:
review-code
Quick check:
- Start the app with
cargo run - Ask:
use MCP tool greet with name Alice - Ask:
read MCP resource config://app
aicli/
├── src/
│ └── main.rs # Main application entry point
├── rag/
│ ├── src/
│ │ ├── lib.rs # RAG library main module
│ │ ├── build_prompt.rs # Prompt construction with context
│ │ ├── chunk_text.rs # Text chunking utilities
│ │ ├── config.rs # Configuration management
│ │ ├── embed_chunks.rs # Text embedding generation
│ │ ├── embed_query.rs # Query embedding generation
│ │ ├── generate.rs # Answer generation
│ │ ├── http.rs # HTTP client utilities
│ │ ├── retrieve_chunks.rs # Similarity search and retrieval
│ │ ├── scan_files.rs # File system scanning
│ │ └── store_qdrant.rs # Qdrant database operations
│ └── Cargo.toml # RAG library dependencies
├── Cargo.toml # Main project dependencies
├── Cargo.lock # Dependency lock file
└── README.md # This file
crossterm- Terminal manipulation and event handlingratatui- Terminal user interface frameworkrag- Local RAG library (path dependency)
mcp-client-rust- MCP client transport and protocol handlingreqwest- HTTP client for API callsserde- Serialization/deserializationserde_json- JSON handlingtokio- Async runtime (used by MCP client integration)walkdir- File system traversal
# Development build
cargo build
# Release build
cargo build --releasecargo test- Follow Rust naming conventions
- Use descriptive variable and function names
- Maintain clear separation between UI and business logic
- Handle errors gracefully with meaningful error messages
-
Qdrant Connection Failed
- Ensure Qdrant server is running on the configured port
- Check
QDRANT_URLenvironment variable - Verify network connectivity
-
Embedding Generation Errors
- Check API key and endpoint configuration
- Verify embedding model service availability
- Ensure proper rate limiting compliance
-
File Scanning Issues
- Verify directory permissions
- Check
SCAN_DIRECTORIESconfiguration - Ensure supported file extensions are configured
Enable debug logging by setting the environment variable:
export RUST_LOG=debug- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
- Built with the excellent
ratatuiterminal framework - Powered by Qdrant vector database
- Inspired by modern AI-assisted development tools