AI-powered CLI assistant with Gemini LLM command generation and human confirmation
Project description
AI CLI Assistant (LLM Powered)
AI-powered command-line assistant that converts natural language into safe shell commands using Gemini LLM with human-in-the-loop confirmation.
Features
โจ Core Capabilities
- ๐ค Natural Language Processing: Describe what you want to do in plain English
- ๐ง LLM-Powered Command Generation: Uses Gemini API to generate accurate shell commands
- ๐ Safety First: Built-in risk assessment and execution approval workflow
- ๐ Undo/Rollback: Revert executed commands with automatic backup management
- ๐ Multi-Step Planning: Execute complex workflows with automatic plan generation
- ๐พ Context Memory: Maintains conversation context across sessions
๐ง Advanced Features
- ๐ฏ Intent Recognition: NLP-based command categorization (file ops, system, dev, etc.)
- ๐ Fallback Generator: Pattern-based command generation when API unavailable
- ๐ Execution Tracking: Full history of executed commands with timestamps
- โ๏ธ Smart Autocomplete: Context-aware command suggestions
- ๐ Multi-LLM Support: Works with Gemini API or local Ollama instances
Installation
Prerequisites
- Python 3.10+
- Google Gemini API Key (free tier available at ai.google.com)
- PowerShell (Windows) or Bash (Linux/macOS)
Setup
-
Clone the repository
git clone https://github.com/yourusername/ai-cli.git cd ai-cli
-
Install the package
pip install -e .
-
Configure environment Create a
.envfile in the project root:GEMINI_API_KEY=your_api_key_here # Optional: for Ollama fallback OLLAMA_API_URL=http://localhost:11434
Get your free Gemini API key:
- Visit Google AI Studio
- Create a new API key
- Paste it in your
.envfile
-
Verify installation
ai-cli
Usage
Interactive Mode
ai-cli
Then describe what you want to do:
> Clean up all .pyc files in the project
Generated command: find . -name "*.pyc" -type f -delete
Safe to execute? (y/n): y
โ Command executed successfully
Supported Commands
File Operations
> Create a backup of my config file
> Delete all temporary files
> Find files larger than 100MB
> Rename all .txt files to .bak
System Management
> Show disk usage
> Kill process on port 8080
> Restart the Docker service
Development
> Install dependencies from requirements.txt
> Build and test the project
> Format all Python files
Command Flow
- Input โ Natural language description
- Parse โ Intent recognition and command mapping
- Generate โ LLM creates the actual command
- Review โ Risk assessment with execution approval
- Execute โ Command runs with output capture
- Track โ Stores for undo/history
Safety Features
Risk Assessment
Commands are automatically classified by risk level:
- ๐ข LOW: Read operations, non-destructive
- ๐ก MEDIUM: File modifications, package installations
- ๐ด HIGH: System changes, destructive operations
Approval Workflow
Generated command: rm -rf /important/directory
โ ๏ธ HIGH RISK: Destructive file operation
Estimated impact: Permanent deletion
Safe to execute? (y/n): n
โ Command blocked by user
Undo Capability
> undo
Recent commands:
1. mv file.txt file.bak โ
2. rm oldfile.py โ
Undo which? (1): 1
โ Command reverted: file.bak โ file.txt
Project Structure
ai-cli/
โโโ ai_cli/
โ โโโ main.py # Entry point and CLI loop
โ โโโ llm_generator.py # Gemini API integration & fallback
โ โโโ executor.py # Command execution engine
โ โโโ safety.py # Risk assessment module
โ โโโ planner.py # Multi-step plan execution
โ โโโ undo_manager.py # Undo/rollback functionality
โ โโโ context_manager.py # Context and history tracking
โ โโโ intent_parser.py # NLP intent recognition
โ โโโ command_mapper.py # Intent โ command mapping
โ โโโ autocomplete.py # Tab completion support
โโโ setup.py # Package configuration
โโโ .env # API keys (not in git)
โโโ .gitignore # Git ignore patterns
โโโ README.md # This file
Configuration
Environment Variables
# Required
GEMINI_API_KEY=sk_...
# Optional
OLLAMA_API_URL=http://localhost:11434
OLLAMA_MODEL=mistral
SAFETY_LEVEL=medium # low, medium, high
HISTORY_SIZE=100
DEBUG=false
Architecture
Command Generation Flow
User Input
โ
Intent Parser (NLP)
โ
Intent โ Command Mapper
โ
LLM Generator (Gemini API)
โ
Fallback Generator (if needed)
โ
Safety Assessment
โ
User Approval
โ
Executor
Undo System
- Maintains command history with metadata
- Tracks file state changes
- Generates reverse commands automatically
- Supports multi-command rollback
API Keys & Security
Getting a Gemini API Key
- Go to Google AI Studio
- Click "Create API Key"
- Copy the key to your
.envfile - Never commit
.envto git (already in.gitignore)
Free Tier Limits
- 100 requests per minute (sufficient for interactive use)
- 15 requests per day for batch operations
- Upgrade to paid plan for higher limits
Troubleshooting
"API Key not found"
# Check .env exists and has GEMINI_API_KEY
cat .env
"No module named 'spacy'"
# Install NLP dependencies
pip install spacy
python -m spacy download en_core_web_sm
Commands taking too long
- Check API rate limits
- Switch to Ollama for instant generation (local)
- Use fallback generator for common commands
Undo not working
- Check undo history:
ai-cli --history - Ensure backup files exist in
.ai-cli-backups/
Advanced Usage
Batch Mode
echo "Find all .log files" | ai-cli --batch
Dry Run (preview only)
ai-cli --dry-run
> Clean up temp files
[DRY RUN] rm -rf /tmp/*.log
No commands executed
View History
ai-cli --history
Clear History
ai-cli --clear-history
Contributing
Contributions welcome! Areas for improvement:
- Cross-platform command support (Windows/Linux/macOS)
- More fallback patterns for common operations
- Integration with other LLMs (Claude, GPT-4)
- Web UI dashboard
- Docker container support
Limitations & Known Issues
โ ๏ธ Important Notes
- Commands are OS-specific (PowerShell on Windows, Bash on Linux/macOS)
- Some complex multi-step operations may require manual execution
- API rate limits apply during batch operations
- Undo only works for tracked file operations
Dependencies
google-generativeai>=0.3.0 # Gemini API
requests>=2.28.0 # Ollama API
python-dotenv>=0.19.0 # .env support
spacy>=3.0.0 # NLP (optional)
License
MIT License - Feel free to use, modify, and distribute.
Support
- ๐ง Issues: GitHub Issues
- ๐ฌ Discussions: GitHub Discussions
- ๐ Documentation: See ADVANCED_FEATURES.md
Roadmap
- Basic command generation
- Safety checks
- Undo functionality
- Web interface
- Database backend for history
- Custom command templates
- Multi-user support
- Cloud sync
Made with โค๏ธ for command-line enthusiasts
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ai_cli_llm-2.0.0.tar.gz.
File metadata
- Download URL: ai_cli_llm-2.0.0.tar.gz
- Upload date:
- Size: 35.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e9ea4a901f98019fb0d57a698657eed7a790d7110f9fccc60908ad91aa358467
|
|
| MD5 |
8137d1da96b13e2cb238390f386cb947
|
|
| BLAKE2b-256 |
914a723422316c0f5588b1156fc68df3a0d0016ed2cc1949c3cf76944b033387
|
File details
Details for the file ai_cli_llm-2.0.0-py3-none-any.whl.
File metadata
- Download URL: ai_cli_llm-2.0.0-py3-none-any.whl
- Upload date:
- Size: 36.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f00b80a2b2a5d317789b09fd92e8471a4f03f79c2e24136bbe2fa250cd626c4b
|
|
| MD5 |
a03de843831c659d3338b7d2864c3f0f
|
|
| BLAKE2b-256 |
5f69bcaf8cabb9295b2606b4002a736ba34c50b9128bc6cc3753a8ecdfd0384c
|