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.

Setup

Set up your OpenAI API key as an environment variable:

export OPENAI_API_KEY="your-api-key-here"

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)

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 configured"

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.4.tar.gz (25.9 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.4-py3-none-any.whl (11.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: sudothink-1.0.4.tar.gz
  • Upload date:
  • Size: 25.9 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.4.tar.gz
Algorithm Hash digest
SHA256 356cf112aff3b4ff501132342cb6a3d1f4a6ac2fdb2982b07e767e083d4bffd8
MD5 5f14b2eab095d44c1770d493995dd23d
BLAKE2b-256 274b1e0056a84286031d021b05c9b316cd053d28a7864a09d7ee216c750c9615

See more details on using hashes here.

File details

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

File metadata

  • Download URL: sudothink-1.0.4-py3-none-any.whl
  • Upload date:
  • Size: 11.8 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.4-py3-none-any.whl
Algorithm Hash digest
SHA256 200e686cbf3d9842c80f6ffcd417b8bd677bbf8c5efa9cf7eb860554c75369eb
MD5 41b11346472a6a48d7eac25a8cf7bbf8
BLAKE2b-256 6209fc3377cd516b4ef2ba841c2cc04c132dc1775427b8655b9fbc2009064915

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