AI-Powered Interactive Shell - Convert natural language to shell commands
Project description
AI-shell - AI-Powered Interactive Shell
🧠 AI-shell is an interactive command-line shell that accepts natural language input and suggests equivalent shell commands using an LLM. It behaves like a real terminal but with AI-powered command generation.
Features
- 🤖 AI-powered: Uses OpenAI API with GPT-4o-mini for intelligent command generation
- 🛡️ Safety first: Built-in safety checker to detect potentially dangerous commands
- 📝 Command logging: All interactions are logged to
~/.ai_shell_history.log - 🎨 Rich UI: Beautiful terminal interface with colors and formatting
- 🔍 Interactive: Real-time command generation and execution
- 📖 Help system: Built-in help and history commands
Installation
From PyPI (Recommended)
pip install ai-shell
From Source
-
Clone the repository:
git clone <repository-url> cd AI-shell
-
Install in development mode:
pip install -e .
-
Set up your OpenAI API key:
# Run the setup script ./setup_env.sh # Edit the .env file with your API key nano .env
Quick Start
After installation, you can start the shell with:
ai-shell
Or run the demo mode:
ai-shell-demo
Usage
Starting the Shell
ai-shell
You'll see a prompt like:
AI-shell>
Natural Language Queries
Type natural language descriptions of what you want to do:
AI-shell> find all PDF files larger than 10MB
💡 Suggested: find . -name "*.pdf" -size +10M
Run this command? [y/N]: y
📤 Executing...
✅ Command executed successfully!
📄 Output:
./documents/report.pdf
./downloads/manual.pdf
Special Commands
:quitor:exit- Exit the shell:help- Show help information:history- Show recent command history:clear- Clear the screen
Example Interactions
AI-shell> delete all .zip files in Downloads
💡 Suggested: rm ~/Downloads/*.zip
Run this command? [y/N]: n
❌ Cancelled
AI-shell> list all python files modified in the last 24 hours
💡 Suggested: find . -name "*.py" -mtime -1
Run this command? [y/N]: y
📤 Executing...
✅ Command executed successfully!
📄 Output:
./main.py
./utils/llm.py
./test_basic.py
Project Structure
AI-shell/
├── main.py # Interactive shell loop
├── llm.py # OpenRouter API integration
├── safety.py # Safety checker for dangerous commands
├── executor.py # Command execution and logging
├── requirements.txt # Python dependencies
├── env.example # Environment variables template
├── setup_env.sh # Environment setup script
├── test_basic.py # Basic functionality tests
└── README.md # This file
Safety Features
The shell includes comprehensive safety checks for:
- File deletion commands (
rm -rf, etc.) - System modification commands (
sudo,chmod 777, etc.) - Dangerous redirects (
> /dev/,> /etc/, etc.) - Shell injection patterns
- Fork bombs and other malicious patterns
- Network commands that pipe to shell
Command History
All interactions are automatically logged to ~/.ai_shell_history.log in JSON format:
{
"timestamp": "2024-01-15T10:30:00",
"original_query": "find all PDF files",
"generated_command": "find . -name \"*.pdf\"",
"working_directory": "/home/user",
"user": "user"
}
API Configuration
The shell uses OpenAI API with the following configuration:
- Model:
gpt-4o-mini - Temperature: 0.1 (for consistent command generation)
- Max tokens: 500
- Timeout: 30 seconds
Environment Variables
You can customize the behavior using environment variables in your .env file:
# Required
OPENAI_API_KEY=your_api_key_here
# Optional
OPENAI_MODEL=gpt-4o-mini
OPENAI_TEMPERATURE=0.1
OPENAI_MAX_TOKENS=500
OPENAI_TIMEOUT=30
AISH_HISTORY_FILE=~/.ai_shell_history.log
AISH_DEBUG=false
Testing
Run the basic tests to verify functionality:
python test_basic.py
Error Handling
- Network timeouts and API errors are handled gracefully
- Dangerous commands trigger warnings but don't prevent execution
- Command execution has a 5-minute timeout
- Failed commands are logged with error details
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
License
This project is open source and available under the MIT License.
Disclaimer
⚠️ Use at your own risk! While this tool includes safety checks, it's still possible to generate and execute dangerous commands. Always review generated commands before execution.
Troubleshooting
Common Issues
- API Key Error: Make sure
OPENAI_API_KEYis set correctly in.env - Import Errors: Install dependencies with
pip install -r requirements.txt - Network Issues: Check your internet connection and API endpoint accessibility
Getting Help
If you encounter issues:
- Check the command history:
cat ~/.ai_shell_history.log - Verify your API key is set:
echo $OPENAI_API_KEY - Run tests:
python test_basic.py - Check the help:
:helpin the shell
Project details
Release history Release notifications | RSS feed
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_shell_cli-0.1.0.tar.gz.
File metadata
- Download URL: ai_shell_cli-0.1.0.tar.gz
- Upload date:
- Size: 16.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
74e45ac9aba5f9e59410ed1c71c412dfde9fa0eb2d132b717591b1dddb313bc2
|
|
| MD5 |
c71f0164426a9c45faca9354d9987fbe
|
|
| BLAKE2b-256 |
efeeab53030e3ee6742c30bc668eb570e4e40d01909993fa2925bb7d2f3e4cec
|
File details
Details for the file ai_shell_cli-0.1.0-py3-none-any.whl.
File metadata
- Download URL: ai_shell_cli-0.1.0-py3-none-any.whl
- Upload date:
- Size: 14.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0f51f20d19bb77e9f5749950549ef740ccb84b3d32159e51445266405e733912
|
|
| MD5 |
5c0b918d1d690516b767e299514c2cf7
|
|
| BLAKE2b-256 |
aa92a3d473ec15392c6156d751141885042d4408a3e829cc4dcc1462549ffb18
|