Skip to main content

AI-powered DevOps assistant with Plan/Build modes

Project description

OpsPilot - AI-powered DevOps Assistant

Tests Lint License: MIT Python 3.11+ Code style: black

OpsPilot is a sophisticated CLI tool for DevOps operations with AI assistance, similar to OpenCode or Claude Code but specialized for DevOps tasks.

Note: This project now features a full Textual TUI with split-screen interface! The simple CLI fallback is available if Textual is not installed.

Features

๐Ÿ”ง Simple Authentication

  • Choose your AI provider (OpenAI, ZhipuAI, Anthropic, or OpenRouter)
  • Provide your API key for the selected provider
  • Automatic model selection for Plan/Build modes
  • OpenRouter: Access to 100+ models from various providers

๐Ÿ“‹ Plan Mode vs Build Mode

  • Plan Mode: Safe planning with reasoning models (GLM-4-Plus, GPT-4)
  • Build Mode: Action-oriented with fast models (GLM-4-Flash, GPT-3.5)
  • Toggle between modes with Tab key

๐Ÿ–ฅ๏ธ Split-Screen TUI Interface

  • Left Pane (30%): Chat history with user/AI messages
  • Right Pane (70%): Terminal output, logs, and markdown rendering
  • Footer: Current mode, model name, authentication status, token usage, and cost

๐Ÿ›ก๏ธ Safety Gates

  • Automatic detection of dangerous commands (rm, kubectl apply, systemctl, etc.)
  • Confirmation dialogs before executing risky operations
  • Secure subprocess execution with timeout controls

๐Ÿ’พ Session Management

  • Persistent conversation history
  • Export sessions (JSON, Markdown, TXT)
  • Session search and organization

Installation

# Clone the repository
git clone https://github.com/cyber-goka/opspilot.git
cd opspilot

# Install OpsPilot
pip install -e .

Or use the installation script:

python install.py

Quick Start

# Install OpsPilot
pip install -e .

# Configure your API key (first time setup)
opspilot config --edit

# Start the TUI application
opspilot start

# Start with specific mode
opspilot start --mode build

# Load existing session
opspilot start --session <session-id>

# View configuration
opspilot config --show

# List sessions
opspilot sessions --list

# Show usage statistics
opspilot stats

Configuration

OpsPilot uses ~/.opspilot/config.yaml for configuration:

Configuration Example

auth:
  provider: zhipu  # Choose: openai, zhipu, anthropic, or openrouter
  api_key: your-api-key-here

Note: When using OpenRouter, you get access to models from multiple providers through a single API key. Popular models include GPT-4, Claude, Gemini, and many others.

Environment Variables

You can also set configuration via environment variables:

export OPSPILOT_API_KEY="your-api-key"
export OPSPILOT_PROVIDER="zhipu"  # openai, zhipu, anthropic, or openrouter

Getting API Keys

Usage Examples

Plan Mode - Safe Planning

User: Help me deploy a Django application to Kubernetes

Assistant: I'll help you plan the Django deployment to Kubernetes. Let me analyze your current setup first.

[Reads Dockerfile, requirements.txt, current directory structure]

Based on my analysis, here's your deployment plan:

## Phase 1: Container Preparation
1. Optimize Dockerfile for production
2. Create .dockerignore file
3. Build and test container locally

## Phase 2: Kubernetes Manifests
1. Create Deployment manifest
2. Create Service manifest
3. Create Ingress configuration
4. Add ConfigMaps for environment variables

## Phase 3: Deployment Strategy
1. Create namespace
2. Apply ConfigMaps first
3. Deploy application
4. Configure monitoring

Switch to Build Mode (Ctrl+T) to execute this plan.

Build Mode - Action Execution

User: Create the Kubernetes deployment manifest

Assistant: I'll create a Kubernetes deployment manifest for your Django application.

[Creates deployment.yaml with optimized settings]

โœ… Created deployment.yaml with:
- 3 replicas with rolling updates
- Resource limits and requests
- Health checks configured
- Environment variables from ConfigMap

The deployment is ready. Would you like me to apply it to the cluster?

CLI Commands

Start Application

opspilot start [OPTIONS]
  --session, -s TEXT    Session ID to load
  --mode, -m TEXT       Start mode (plan|build)
  --config, -c TEXT      Custom config file path

Configuration Management

opspilot config [OPTIONS]
  --show, -s           Show current configuration
  --edit, -e           Edit configuration file
  --reset, -r           Reset to defaults

Session Management

opspilot sessions [OPTIONS]
  --list, -l           List all sessions
  --delete, -d TEXT     Delete session by ID
  --export, -e TEXT     Export session by ID
  --format, -f TEXT     Export format (json|markdown|txt)

Usage Statistics

opspilot stats
# Shows token usage, cost, request count, and context size

Architecture

opspilot/
โ”œโ”€โ”€ opspilot/
โ”‚   โ”œโ”€โ”€ __init__.py      # Package initialization
โ”‚   โ”œโ”€โ”€ main.py          # CLI entry point
โ”‚   โ”œโ”€โ”€ config.py        # Configuration management
โ”‚   โ”œโ”€โ”€ agent/
โ”‚   โ”‚   โ”œโ”€โ”€ core.py      # Agent Think-Act loop
โ”‚   โ”‚   โ”œโ”€โ”€ memory.py    # Chat history
โ”‚   โ”‚   โ””โ”€โ”€ tools/
โ”‚   โ”‚       โ”œโ”€โ”€ system.py # Shell execution
โ”‚   โ”‚       โ””โ”€โ”€ files.py  # File operations
โ”‚   โ””โ”€โ”€ tui/
โ”‚       โ”œโ”€โ”€ app.py       # TUI application
โ”‚       โ”œโ”€โ”€ screens.py   # Modal dialogs
โ”‚       โ””โ”€โ”€ styles.tcss  # CSS styling
โ”œโ”€โ”€ pyproject.toml       # Package configuration
โ”œโ”€โ”€ requirements.txt     # Dependencies
โ”œโ”€โ”€ install.py          # Installation script
โ””โ”€โ”€ README.md           # Documentation

Development

Setup Development Environment

# Clone repository
git clone https://github.com/cyber-goka/opspilot.git
cd opspilot

# Create virtual environment
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate

# Install in development mode
pip install -e ".[dev]"

# Run tests
pytest

# Run with type checking
mypy opspilot/

# Format code
black opspilot/

Project Structure

  • Agent Core: Think-Act loop with mode switching
  • Tools System: Secure file and shell operations
  • Memory Management: Persistent conversation history
  • TUI Framework: Rich terminal interface with Textual
  • Configuration: Flexible authentication and model settings

Safety Features

Dangerous Command Detection

OpsPilot automatically detects and confirms commands containing:

  • File deletion: rm, delete, del
  • System changes: systemctl, service, init
  • Container operations: kubectl apply, docker rm
  • Permission changes: chmod 777, chown
  • System administration: sudo, passwd, crontab

Secure Execution

  • Timeout controls for all commands
  • Working directory restrictions
  • Process isolation and cleanup
  • Comprehensive error handling

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests for new functionality
  5. Submit a pull request

License

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

Support


OpsPilot - Your AI-powered DevOps companion ๐Ÿš€

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

opspilot-0.2.1.tar.gz (58.8 kB view details)

Uploaded Source

Built Distribution

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

opspilot-0.2.1-py3-none-any.whl (66.3 kB view details)

Uploaded Python 3

File details

Details for the file opspilot-0.2.1.tar.gz.

File metadata

  • Download URL: opspilot-0.2.1.tar.gz
  • Upload date:
  • Size: 58.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for opspilot-0.2.1.tar.gz
Algorithm Hash digest
SHA256 7b7290b95e9760a8c2f2da0f4f42470c7a75a33c6bb1a0d4ed96cbade4e6e54e
MD5 8ee866f95b12c9ef40d92b1306217bfa
BLAKE2b-256 c35d4e5d8e8219dfc9f0740fcc845067ec8cd901c9bfb62fc7023131ea6f452d

See more details on using hashes here.

File details

Details for the file opspilot-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: opspilot-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 66.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for opspilot-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c13e09df7f402d3aec8b6b0a39cf6686be23100947eb3921e720335e0d1196ad
MD5 9abf81c4a366a01b1d8533d0896e2abd
BLAKE2b-256 8da0d857f72b89b13a3a1427edc77b0347e308a8cc44578b78af9fad13ff689c

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