Skip to main content

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

  1. Clone the repository:

    git clone <repository-url>
    cd AI-shell
    
  2. Install in development mode:

    pip install -e .
    
  3. 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

  • :quit or :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

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests if applicable
  5. 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

  1. API Key Error: Make sure OPENAI_API_KEY is set correctly in .env
  2. Import Errors: Install dependencies with pip install -r requirements.txt
  3. Network Issues: Check your internet connection and API endpoint accessibility

Getting Help

If you encounter issues:

  1. Check the command history: cat ~/.ai_shell_history.log
  2. Verify your API key is set: echo $OPENAI_API_KEY
  3. Run tests: python test_basic.py
  4. Check the help: :help in the shell

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

ai_shell_cli-0.1.0.tar.gz (16.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ai_shell_cli-0.1.0-py3-none-any.whl (14.9 kB view details)

Uploaded Python 3

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

Hashes for ai_shell_cli-0.1.0.tar.gz
Algorithm Hash digest
SHA256 74e45ac9aba5f9e59410ed1c71c412dfde9fa0eb2d132b717591b1dddb313bc2
MD5 c71f0164426a9c45faca9354d9987fbe
BLAKE2b-256 efeeab53030e3ee6742c30bc668eb570e4e40d01909993fa2925bb7d2f3e4cec

See more details on using hashes here.

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

Hashes for ai_shell_cli-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0f51f20d19bb77e9f5749950549ef740ccb84b3d32159e51445266405e733912
MD5 5c0b918d1d690516b767e299514c2cf7
BLAKE2b-256 aa92a3d473ec15392c6156d751141885042d4408a3e829cc4dcc1462549ffb18

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page