Skip to main content

An intelligent terminal assistant that uses OpenAI's GPT-4 to help with complex shell tasks

Project description

SudoThink - Advanced AI Terminal Assistant

An intelligent terminal assistant that uses OpenAI's GPT-4 to help you with complex shell tasks, from simple commands to multi-step workflows.

Features

🚀 Core Capabilities

  • Smart Command Generation: Convert natural language to shell commands
  • Multi-Step Task Planning: Break down complex tasks into executable steps
  • Context Awareness: Understands your system, current directory, and recent commands
  • Automatic Error Recovery: Retry failed commands with error context
  • Interactive Chat Mode: Have conversations with the AI assistant

🎯 Multiple Modes

1. Command Mode (Default)

Generate and execute single shell commands:

ai "find all files larger than 100MB"
ai "show me the top 10 processes by memory usage"

2. Plan Mode

Generate step-by-step plans for complex tasks:

ai "setup a new Python project with virtual environment" plan
ai "backup my documents and sync to cloud storage" plan

3. Explain Mode

Get explanations and analysis of tasks:

ai "what does this command do: docker-compose up -d" explain
ai "how to optimize my system performance" explain

4. Interactive Chat Mode

Have ongoing conversations:

ai-chat

🔧 Advanced Features

Context Awareness

  • System Information: OS, shell, current directory, available commands
  • Command History: Learns from your recent commands
  • Directory Structure: Understands your current workspace
  • Persistent Context: Remembers previous interactions

Smart Error Handling

  • Automatic Retry: When commands fail, automatically generates corrected versions
  • Error Analysis: Includes error messages in retry requests
  • Step-by-Step Recovery: For complex tasks, can retry individual steps

Multi-Step Execution

  • Interactive Steps: Review and approve each step before execution
  • Skip Options: Skip steps that aren't needed
  • Retry Logic: Retry failed steps individually
  • Progress Tracking: Clear indication of current step and progress

Installation

Quick Install (Recommended)

One-liner installation:

curl -fsSL https://raw.githubusercontent.com/vusallyv/sudothink/master/install-oneline.sh | bash

Manual installation:

git clone https://github.com/vusallyv/sudothink.git
cd sudothink
chmod +x install.sh
./install.sh

Alternative Installation Methods

Via pip (Python package)

pip install sudothink

Note: The pip package will be available after publishing to PyPI. For now, use the one-liner or manual installation methods.

Via Homebrew (macOS)

# Add to your tap first
brew tap yourusername/sudothink
brew install sudothink

Note: Homebrew installation requires the tap to be published first. For now, use the one-liner or manual installation methods.

Setup

  1. Set up your OpenAI API key:
export OPENAI_API_KEY="your-api-key-here"
  1. Add to your shell profile (if not done automatically):
echo 'export OPENAI_API_KEY="your-api-key-here"' >> ~/.zshrc
source ~/.zshrc

Usage Examples

Simple Commands

# Find files
ai "find all PDF files in my documents folder"

# System monitoring
ai "show me disk usage for all mounted drives"

# Process management
ai "kill all processes using more than 1GB of memory"

Complex Tasks

# Multi-step setup
ai "setup a new Node.js project with TypeScript, ESLint, and Prettier" plan

# Data processing
ai "download a CSV file, process it with Python, and generate a report" plan

# System maintenance
ai "clean up old log files, update packages, and restart services" plan

Learning and Analysis

# Understand commands
ai "explain what 'docker-compose up -d' does" explain

# Get recommendations
ai "how can I improve my shell productivity" explain

# Debug issues
ai "my Python script is running slowly, help me optimize it" explain

Interactive Mode

ai-chat

# In chat mode:
🤖 You: plan setup a web server
🤖 You: explain what nginx does
🤖 You: find files modified today
🤖 You: exit

Configuration

Environment Variables

  • OPENAI_API_KEY: Your OpenAI API key (required)
  • AI_TRUST_MODE: Set to "true" to run commands without confirmation (use with caution)

Files Created

  • ~/.ai-terminal-context.json: Persistent context and settings
  • ~/.ai-terminal-history.log: Interaction history for learning

Safety Features

Command Confirmation

  • All commands require explicit confirmation before execution
  • Clear display of what command will be run
  • Option to skip or modify commands

Error Handling

  • Automatic detection of command failures
  • Smart retry with error context
  • Graceful handling of API errors

Context Limits

  • Directory structure limited to prevent overwhelming
  • Command history limited to recent entries
  • File size limits on generated content

Advanced Usage

Custom Prompts

You can modify the system prompts in ai.py to customize the AI's behavior:

# In the generate_response method, modify the prompt templates
if mode == "command":
    prompt += """
    YOUR CUSTOM INSTRUCTIONS HERE
    """

Extending Functionality

The modular design makes it easy to add new modes:

  1. Add a new mode to the generate_response method
  2. Update the argument parsing in main()
  3. Add corresponding shell function in ai.zsh

Integration with Other Tools

  • Git Integration: Use with git workflows
  • Docker Support: Container management commands
  • Cloud Services: AWS, GCP, Azure commands
  • Development Tools: IDE integration, build systems

Troubleshooting

Common Issues

"OPENAI_API_KEY not set"

export OPENAI_API_KEY="your-key-here"

Command not found

  • The AI will automatically retry with corrected commands
  • Use explain mode to understand what went wrong

Permission denied

  • Check file permissions
  • Use sudo when appropriate (the AI will suggest this)

Debug Mode

For troubleshooting, you can run the Python script directly:

python3 ai.py "your query" [mode]

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Test thoroughly
  5. Submit a pull request

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments

  • Built with OpenAI's GPT-4 API
  • Inspired by modern CLI tools and AI assistants
  • Designed for developer productivity and system administration

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

sudothink-1.0.1.tar.gz (21.8 kB view details)

Uploaded Source

Built Distribution

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

sudothink-1.0.1-py3-none-any.whl (9.7 kB view details)

Uploaded Python 3

File details

Details for the file sudothink-1.0.1.tar.gz.

File metadata

  • Download URL: sudothink-1.0.1.tar.gz
  • Upload date:
  • Size: 21.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.9

File hashes

Hashes for sudothink-1.0.1.tar.gz
Algorithm Hash digest
SHA256 5769c74a24586588a7bb6c71f2ecefb9fb5c81dfefe58e43d33fd5d347e42d38
MD5 9ded8143551d902eed55083a1ce69f05
BLAKE2b-256 c93d03ab16b4651caa48df9a573bd9c8191da8f44c8a67b5e0a6bc3d86bc369c

See more details on using hashes here.

File details

Details for the file sudothink-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: sudothink-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 9.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.9

File hashes

Hashes for sudothink-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4b10ca7229d9a963eb6f6ab908833f9365eee6b282ba3ccdf4a3cc89d4476bd1
MD5 68d81b22c3524162fa3647b7e2723d44
BLAKE2b-256 afddafc6d9123c59a109fc0e074dc08baea47809983c515a3ed85b9863b16dc2

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