A natural language interface for Linux commands powered by LLMs. This system converts natural language queries into appropriate Linux commands, executes them safely, and returns the results.
┌─────────────┐
│ Query │ User asks in natural language
│ (Natural │ e.g., "help me show list of files in directory"
│ Language) │
└──────┬──────┘
│
v
┌─────────────────────────────────────────────────┐
│ Agent │
│ │
│ ┌─────────────────────────────────────────┐ │
│ │ 1. Query Processing │ │
│ │ - Parse natural language │ │
│ │ - Search commands database │ │
│ └─────────────────────────────────────────┘ │
│ │
│ ┌─────────────────────────────────────────┐ │
│ │ 2. LLM Reasoning │ │
│ │ - Convert query to command │ │
│ │ - Use database context │ │
│ │ - Apply safety checks │ │
│ └─────────────────────────────────────────┘ │
│ │
│ ┌─────────────────────────────────────────┐ │
│ │ 3. Command Execution │ │
│ │ - Execute Linux command │ │
│ │ - Capture output │ │
│ │ - Handle errors │ │
│ └─────────────────────────────────────────┘ │
│ │
│ ┌─────────────────────────────────────────┐ │
│ │ Linux Commands Database │ │
│ │ (60+ commands with descriptions) │ │
│ └─────────────────────────────────────────┘ │
└─────────────────────────────────────────────────┘
│
v
┌──────────────┐
│ Response │ Command output or error message
└──────────────┘
- 🗣️ Natural Language Interface: Ask questions in plain English
- 🤖 LLM-Powered: Uses OpenAI GPT-4 for intelligent command generation
- 📚 Comprehensive Knowledge Base: 60+ Linux commands with detailed documentation
- 🎓 Educational Mode: Learn with explanations, tips, and examples
- 🔗 Command Combinations: 30+ real-world command pipelines
- 🛡️ Safety First: Built-in checks prevent dangerous commands
- 📝 Command History: Track all executed commands
- 🎯 Mock Mode: Works without API key for testing
- ⚡ Interactive & CLI Modes: Use interactively or as single commands
- 💡 Interactive Help: Explain any command with detailed options and tips
-
Clone the repository:
git clone https://github.com/yourusername/sample.ai.git cd sample.ai -
Install dependencies:
pip install -r requirements.txt
-
Set up API key (optional for full functionality):
cp .env.example .env # Edit .env and add your OpenAI API key export OPENAI_API_KEY='your-api-key-here'
Run the agent in interactive mode for continuous queries:
python agent.pyExample session:
Query> help me show list of files in directory
Command: ls -la
------------------------------------------------------------
total 48
drwxr-xr-x 6 user user 4096 Nov 21 10:30 .
drwxr-xr-x 3 user user 4096 Nov 21 10:00 ..
-rw-r--r-- 1 user user 123 Nov 21 10:30 agent.py
...
Query> what's my current directory?
Command: pwd
------------------------------------------------------------
/workspaces/sample.ai
Query> show me running processes
Command: ps aux
------------------------------------------------------------
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.1 18236 3456 ? Ss 10:00 0:00 /sbin/init
...
Execute a single query:
python agent.py "show me disk space usage"Output:
Query: show me disk space usage
Command: df -h
Output:
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 50G 20G 28G 42% /
...
history- View command historyquitorexit- Exit interactive mode
| Natural Language Query | Generated Command |
|---|---|
| "show list of files in directory" | ls -la |
| "what's my current directory?" | pwd |
| "show disk space usage" | df -h |
| "show running processes" | ps aux |
| "show memory usage" | free -h |
| "find all text files" | find . -name '*.txt' |
| "find large files" | find . -type f -size +100M -exec ls -lh {} \; |
| "list by size" | ls -lhS |
| "list by date" | ls -lht |
| "show network connections" | netstat -tuln |
| "show system information" | uname -a |
The system includes powerful learning features:
Query> explain grep
📚 GREP - Search text using patterns
Usage: grep [OPTIONS] PATTERN [FILE]...
Common Options:
-r: Recursive search
-i: Case-insensitive
-n: Show line numbers
Examples with explanations...
💡 Tips and best practices...Query> combinations
🔗 30+ Common Command Combinations:
- Find and delete patterns
- Text processing pipelines
- System monitoring
- And more...Every command executed shows educational info automatically:
- What the command does
- Common options explained
- Pro tips and best practices
See EDUCATIONAL_FEATURES.md for complete learning guide!
Edit config.json to customize:
{
"llm": {
"provider": "openai",
"model": "gpt-4",
"temperature": 0.3
},
"security": {
"enable_dangerous_command_check": true,
"command_timeout_seconds": 30
}
}The system includes a comprehensive database of 60+ Linux commands:
- File Operations: ls, cd, pwd, cat, find, grep
- System Info: ps, top, free, df, du, uname
- Network: netstat, ping, curl, wget, ifconfig
- Package Management: apt, yum
- Service Control: systemctl, service
- And many more...
The agent includes built-in safety checks:
- ❌ Blocks dangerous patterns (e.g.,
rm -rf /,mkfs) - ⏱️ 30-second timeout for command execution
- 🔒 Runs with user permissions (no automatic sudo)
- 📋 Command validation before execution
Without an API key, the agent runs in mock mode using pattern matching:
python agent.py
⚠️ No OPENAI_API_KEY found. Using mock LLM mode.This is useful for:
- Testing the system without API costs
- Demonstrating basic functionality
- Development and debugging
sample.ai/
├── agent.py # Main agent program
├── linux_commands_db.json # Commands database
├── config.json # Configuration file
├── requirements.txt # Python dependencies
├── .env.example # Environment variables template
├── .gitignore # Git ignore rules
└── README.md # This file
- Python 3.7+
- OpenAI API key (optional, for full LLM functionality)
- Linux/Unix environment
Contributions welcome! Please:
- Fork the repository
- Create a feature branch
- Add commands to the database in
linux_commands_db.json - Submit a pull request
MIT License - Feel free to use this project for learning and development.
Q: Commands not executing?
- Check file permissions:
chmod +x agent.py - Verify Python version:
python --version(need 3.7+)
Q: "No OPENAI_API_KEY" warning?
- This is normal - the system will use mock mode
- For full functionality, set the environment variable
Q: Command blocked for safety?
- The system blocks potentially dangerous commands
- Review the command and run manually if intended
- 🔄 Support for command chaining and pipes
- 📊 Better output formatting and visualization
- 🌐 Support for multiple LLM providers (Claude, Llama)
- 🔍 Enhanced command search and suggestions
- 💾 Persistent command history
- 🎨 Syntax highlighting for output
For questions or feedback, please open an issue on GitHub.
Note: Always review generated commands before execution, especially in production environments.