airun

AIRun πŸš€

AI-Enhanced Universal Script Runner with Automatic Error Fixing

AIRun is a powerful command-line tool that can execute scripts in multiple languages (Python, Shell, Node.js, PHP) with intelligent AI-powered error detection and automatic fixing capabilities.

License: MIT Python 3.8+ Code style: black

✨ Features

πŸš€ Quick Start

Installation

Option 1: Using pip (when published)

pip install airun

Option 2: From source

# Clone the repository
git clone https://github.com/wronai/airun.git
cd airun

# Install with Poetry
poetry install
poetry shell

# Or install with pip
pip install -e .

Option 3: One-line installer

curl -sSL https://raw.githubusercontent.com/wronai/airun/main/scripts/install.sh | bash

Setup Ollama (for local AI)

# Install Ollama
curl -fsSL https://ollama.ai/install.sh | sh

# Start Ollama service
ollama serve

# Download Code Llama model
ollama pull codellama:7b

Initialize Configuration

# Create default configuration
airun config --init

# Check system status
airun doctor

πŸ“– Usage Examples

Basic Script Execution

# Auto-detect and run Python script
airun my_script.py

# Auto-detect and run shell script
airun deploy.sh production

# Force specific language
airun --lang=nodejs app.js

# Run with arguments
airun data_processor.py --input data.csv --output results.json

AI-Enhanced Error Fixing

# Run with automatic error fixing (default)
airun broken_script.py

# Disable automatic fixing
airun --no-fix risky_script.sh

# Interactive mode (confirm before applying fixes)
airun --interactive debug_me.py

# Specify LLM provider
airun --llm=openai:gpt-4 complex_script.py
airun --llm=ollama:codellama:13b performance_critical.py

Analysis and Debugging

# Analyze script without execution
airun analyze my_script.py

# Dry run (validate and show execution plan)
airun run --dry-run script.py

# Verbose output for debugging
airun run --verbose script.py

# Generate analysis report
airun analyze --output=report.json --format=json script.py

Batch Operations

# Run multiple scripts
airun batch script1.py script2.sh script3.js

# Parallel execution
airun batch --parallel *.py

# Stop on first error
airun batch --stop-on-error test_*.py

# Generate execution report
airun batch --report=results.html *.py

Configuration Management

# Show current configuration
airun config --show

# Edit configuration
airun config --edit

# Set configuration values
airun config --set auto_fix=false
airun config --set llm_providers.ollama.base_url=http://localhost:11434

πŸ“‹ Real-World Examples

Example 1: Python Script with Syntax Error

broken_script.py:

import sys
import os

def process_data(filename):
    with open(filename, 'r') as f:
        data = f.read()
    
    # Missing closing parenthesis - syntax error
    result = data.replace('old', 'new'
    return result

if __name__ == "__main__":
    process_data(sys.argv[1])

Run with AIRun:

$ airun broken_script.py data.txt

πŸš€ Executing broken_script.py (python)
❌ Error detected: SyntaxError: unexpected EOF while parsing
πŸ€– Attempting AI fix...
πŸ”§ Applied AI fix, retrying...
βœ… Error fixed successfully!
Data processed successfully
βœ… Execution completed in 1.23s

Example 2: Shell Script with Permission Issues

setup.sh:

#!/bin/bash
mkdir /opt/myapp
cp files/* /opt/myapp/
chmod +x /opt/myapp/start.sh

Run with AIRun:

$ airun setup.sh

πŸš€ Executing setup.sh (shell)
❌ Error detected: Permission denied
πŸ€– Attempting AI fix...
πŸ”§ Applied AI fix, retrying...
# AI adds 'sudo' where needed
βœ… Error fixed successfully!
βœ… Execution completed in 2.45s

Example 3: Node.js with Missing Dependencies

app.js:

const express = require('express');
const missingModule = require('missing-package');

const app = express();
app.listen(3000);

Run with AIRun:

$ airun app.js

πŸš€ Executing app.js (nodejs)
❌ Error detected: Cannot find module 'missing-package'
πŸ€– Attempting AI fix...
πŸ”§ Applied AI fix, retrying...
# AI suggests removing unused import or installing package
βœ… Error fixed successfully!
Server running on port 3000
βœ… Execution completed in 3.12s

βš™οΈ Configuration

Global Configuration

AIRun uses ~/.airun/config.yaml for global settings:

# Core Settings
auto_fix: true
interactive_mode: false
timeout: 300
max_retries: 3

# Default LLM Provider
default_llm: "ollama:codellama"

# LLM Providers
llm_providers:
  ollama:
    base_url: "http://localhost:11434"
    models:
      python: "codellama:7b"
      shell: "codellama:7b"
      nodejs: "codellama:7b"
      php: "codellama:7b"
  
  openai:
    api_key: "${OPENAI_API_KEY}"
    model: "gpt-4"
  
  claude:
    api_key: "${ANTHROPIC_API_KEY}"
    model: "claude-3-sonnet-20240229"

# Script Runners
runners:
  python:
    executable: "python3"
    flags: ["-u"]
  
  shell:
    executable: "bash"
    flags: []
  
  nodejs:
    executable: "node"
    flags: []
  
  php:
    executable: "php"
    flags: []

Project-Specific Configuration

Create .airunner.yaml in your project directory:

# Override global settings for this project
default_llm: "openai:gpt-4"
auto_fix: true

runners:
  python:
    executable: "python3.11"
    flags: ["-u", "-X", "dev"]
  
  nodejs:
    executable: "node"
    flags: ["--experimental-modules"]

# Custom prompts for this project
prompts:
  python:
    system: "You are debugging a Django web application. Consider Django patterns and best practices."

Environment Variables

Override configuration with environment variables:

export AIRUN_AUTO_FIX=false
export AIRUN_DEFAULT_LLM="openai:gpt-4"
export AIRUN_TIMEOUT=600
export OPENAI_API_KEY="your-api-key"
export ANTHROPIC_API_KEY="your-claude-key"

πŸ”§ Advanced Usage

Custom Model Configuration

# Use specific Ollama model
airun --llm=ollama:codellama:13b large_script.py

# Use OpenAI with specific model
airun --llm=openai:gpt-4-turbo complex_analysis.py

# Use Claude for shell scripts
airun --llm=claude:claude-3-opus advanced_deploy.sh

Integration with CI/CD

.github/workflows/ai-test.yml:

name: AI-Enhanced Testing
on: [push, pull_request]

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v3
    - name: Setup AIRun
      run: |
        curl -sSL https://raw.githubusercontent.com/wronai/airun/main/scripts/install.sh | bash
        airun doctor
    - name: Run tests with AI fixing
      run: |
        airun batch --report=test_results.html test_*.py
        airun batch --parallel --max-retries=1 integration_tests/*.sh

IDE Integration

VS Code Task (.vscode/tasks.json):

{
  "version": "2.0.0",
  "tasks": [
    {
      "label": "AIRun: Execute Current File",
      "type": "shell",
      "command": "airun",
      "args": ["${file}"],
      "group": {
        "kind": "build",
        "isDefault": true
      },
      "presentation": {
        "echo": true,
        "reveal": "always",
        "focus": false,
        "panel": "shared"
      }
    }
  ]
}

πŸ› οΈ Development

Setup Development Environment

# Clone repository
git clone https://github.com/wronai/airun.git
cd airun

# Setup development environment
make dev-setup

# Run tests
make test

# Run linting
make lint

# Build package
make build

Running Tests

# Run all tests
make test

# Run with coverage
make test-coverage

# Run specific test file
pytest tests/test_detector.py -v

# Run integration tests (requires real interpreters)
pytest tests/ -m integration

Contributing

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature-name
  3. Make your changes and add tests
  4. Run the test suite: make test
  5. Submit a pull request

πŸ“Š Comparison with Other Tools

Feature AIRun Traditional Runners Other AI Tools
Multi-language support βœ… ❌ ⚠️
Auto error fixing βœ… ❌ ⚠️
Local AI support βœ… ❌ ❌
Script analysis βœ… ❌ ⚠️
Backup/restore βœ… ❌ ❌
Batch execution βœ… ⚠️ ❌
Configuration flexibility βœ… ⚠️ ⚠️

🚨 Safety Features

πŸ€– Supported LLM Providers

Ollama (Local)

OpenAI

Anthropic (Claude)

πŸ“š Documentation

πŸ†˜ Troubleshooting

Common Issues

1. β€œUnable to determine script type”

# Use --lang to force detection
airun --lang=python ambiguous_file.txt

2. β€œRequired executable not found”

# Check system status
airun doctor

# Install missing interpreters
# Ubuntu/Debian: apt install python3 nodejs php-cli
# macOS: brew install python node php

3. β€œOllama connection failed”

# Check if Ollama is running
curl http://localhost:11434/api/tags

# Start Ollama
ollama serve

# Pull required model
ollama pull codellama:7b

4. β€œAI fix failed”

# Try different model
airun --llm=openai:gpt-4 script.py

# Use interactive mode
airun --interactive script.py

# Disable AI fixing for debugging
airun --no-fix script.py

Getting Help

# System diagnosis
airun doctor

# View logs
airun logs --days=7

# Verbose execution
airun run --verbose script.py

# Get configuration template
airun config --init

πŸ“œ License

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

πŸ™ Acknowledgments

⭐ Star History

Star History Chart


Made with ❀️ by the AIRun team

If you find AIRun useful, please consider giving it a star ⭐ and sharing it with others!

AIRun Project Tree Structure

πŸ“ Current Project Structure (as tree command output)

airun/
β”œβ”€β”€ README.md                              βœ… COMPLETE
β”œβ”€β”€ LICENSE                                ❌ MISSING
β”œβ”€β”€ CONTRIBUTING.md                        βœ… COMPLETE
β”œβ”€β”€ CHANGELOG.md                           ❌ MISSING
β”œβ”€β”€ CODE_OF_CONDUCT.md                     ❌ MISSING
β”œβ”€β”€ pyproject.toml                         βœ… COMPLETE
β”œβ”€β”€ poetry.lock                            ❌ GENERATED (after poetry install)
β”œβ”€β”€ Makefile                               βœ… COMPLETE
β”œβ”€β”€ Dockerfile                             βœ… COMPLETE
β”œβ”€β”€ docker-compose.yml                     βœ… COMPLETE
β”œβ”€β”€ .gitignore                             ❌ MISSING
β”œβ”€β”€ .pre-commit-config.yaml                ❌ MISSING
β”œβ”€β”€ .dockerignore                          ❌ MISSING
β”œβ”€β”€ .github/
β”‚   └── workflows/
β”‚       β”œβ”€β”€ ci.yml                         βœ… COMPLETE
β”‚       β”œβ”€β”€ release.yml                    ❌ MISSING
β”‚       └── ISSUE_TEMPLATE/
β”‚           β”œβ”€β”€ bug_report.md              ❌ MISSING
β”‚           β”œβ”€β”€ feature_request.md         ❌ MISSING
β”‚           └── config.yml                 ❌ MISSING
β”œβ”€β”€ airun/
β”‚   β”œβ”€β”€ __init__.py                        βœ… COMPLETE
β”‚   β”œβ”€β”€ __main__.py                        ❌ MISSING
β”‚   β”œβ”€β”€ cli.py                             βœ… COMPLETE (needs imports fix)
β”‚   β”œβ”€β”€ core/
β”‚   β”‚   β”œβ”€β”€ __init__.py                    ❌ MISSING
β”‚   β”‚   β”œβ”€β”€ detector.py                    βœ… COMPLETE
β”‚   β”‚   β”œβ”€β”€ runners.py                     βœ… COMPLETE
β”‚   β”‚   β”œβ”€β”€ config.py                      βœ… COMPLETE
β”‚   β”‚   β”œβ”€β”€ llm_router.py                  ❌ MISSING
β”‚   β”‚   └── ai_fixer.py                    ❌ MISSING
β”‚   β”œβ”€β”€ providers/
β”‚   β”‚   β”œβ”€β”€ __init__.py                    ❌ MISSING
β”‚   β”‚   β”œβ”€β”€ base.py                        ❌ MISSING
β”‚   β”‚   β”œβ”€β”€ ollama.py                      ❌ MISSING
β”‚   β”‚   β”œβ”€β”€ openai.py                      ❌ MISSING
β”‚   β”‚   └── claude.py                      ❌ MISSING
β”‚   β”œβ”€β”€ utils/
β”‚   β”‚   β”œβ”€β”€ __init__.py                    ❌ MISSING
β”‚   β”‚   β”œβ”€β”€ file_ops.py                    ❌ MISSING
β”‚   β”‚   β”œβ”€β”€ logging.py                     ❌ MISSING
β”‚   β”‚   β”œβ”€β”€ validation.py                  ❌ MISSING
β”‚   β”‚   β”œβ”€β”€ analyzer.py                    ❌ MISSING
β”‚   β”‚   β”œβ”€β”€ batch_executor.py              ❌ MISSING
β”‚   β”‚   β”œβ”€β”€ log_viewer.py                  ❌ MISSING
β”‚   β”‚   β”œβ”€β”€ cleaner.py                     ❌ MISSING
β”‚   β”‚   └── examples.py                    ❌ MISSING
β”‚   β”œβ”€β”€ templates/
β”‚   β”‚   β”œβ”€β”€ prompts/
β”‚   β”‚   β”‚   β”œβ”€β”€ python.txt                 ❌ MISSING
β”‚   β”‚   β”‚   β”œβ”€β”€ shell.txt                  ❌ MISSING
β”‚   β”‚   β”‚   β”œβ”€β”€ nodejs.txt                 ❌ MISSING
β”‚   β”‚   β”‚   └── php.txt                    ❌ MISSING
β”‚   β”‚   └── config/
β”‚   β”‚       └── default.yaml               ❌ MISSING
β”‚   └── web/                               ❌ OPTIONAL (future enhancement)
β”‚       β”œβ”€β”€ __init__.py
β”‚       β”œβ”€β”€ app.py
β”‚       └── templates/
β”œβ”€β”€ tests/
β”‚   β”œβ”€β”€ __init__.py                        ❌ MISSING
β”‚   β”œβ”€β”€ conftest.py                        ❌ MISSING
β”‚   β”œβ”€β”€ test_detector.py                   βœ… COMPLETE
β”‚   β”œβ”€β”€ test_runners.py                    βœ… COMPLETE
β”‚   β”œβ”€β”€ test_config.py                     βœ… COMPLETE
β”‚   β”œβ”€β”€ test_cli.py                        βœ… COMPLETE (needs imports fix)
β”‚   β”œβ”€β”€ test_llm_router.py                 ❌ MISSING
β”‚   β”œβ”€β”€ fixtures/
β”‚   β”‚   β”œβ”€β”€ scripts/
β”‚   β”‚   β”‚   β”œβ”€β”€ test.py                    ❌ GENERATED (by Makefile)
β”‚   β”‚   β”‚   β”œβ”€β”€ test.sh                    ❌ GENERATED (by Makefile)
β”‚   β”‚   β”‚   β”œβ”€β”€ test.js                    ❌ GENERATED (by Makefile)
β”‚   β”‚   β”‚   β”œβ”€β”€ test.php                   ❌ GENERATED (by Makefile)
β”‚   β”‚   β”‚   β”œβ”€β”€ broken_python.py           ❌ GENERATED (by Makefile)
β”‚   β”‚   β”‚   β”œβ”€β”€ broken_shell.sh            ❌ GENERATED (by Makefile)
β”‚   β”‚   β”‚   β”œβ”€β”€ broken_node.js             ❌ GENERATED (by Makefile)
β”‚   β”‚   β”‚   └── broken_php.php             ❌ GENERATED (by Makefile)
β”‚   β”‚   └── configs/
β”‚   β”‚       └── test_config.yaml           ❌ MISSING
β”‚   └── integration/
β”‚       β”œβ”€β”€ __init__.py                    ❌ MISSING
β”‚       β”œβ”€β”€ test_end_to_end.py             ❌ MISSING
β”‚       └── test_ollama_integration.py     ❌ MISSING
β”œβ”€β”€ docs/
β”‚   β”œβ”€β”€ index.md                           ❌ MISSING
β”‚   β”œβ”€β”€ installation.md                    ❌ MISSING
β”‚   β”œβ”€β”€ configuration.md                   ❌ MISSING
β”‚   β”œβ”€β”€ usage.md                           ❌ MISSING
β”‚   β”œβ”€β”€ api/
β”‚   β”‚   β”œβ”€β”€ core.md                        ❌ MISSING
β”‚   β”‚   └── providers.md                   ❌ MISSING
β”‚   β”œβ”€β”€ examples/
β”‚   β”‚   β”œβ”€β”€ basic_usage.md                 ❌ MISSING
β”‚   β”‚   └── advanced_config.md             ❌ MISSING
β”‚   └── mkdocs.yml                         ❌ MISSING
β”œβ”€β”€ scripts/
β”‚   β”œβ”€β”€ install.sh                         ❌ MISSING
β”‚   β”œβ”€β”€ setup_ollama.sh                    ❌ MISSING
β”‚   β”œβ”€β”€ setup_dev.sh                       ❌ MISSING
β”‚   β”œβ”€β”€ release.sh                         ❌ MISSING
β”‚   β”œβ”€β”€ benchmark.py                       ❌ MISSING
β”‚   β”œβ”€β”€ profile_runner.py                  ❌ MISSING
β”‚   β”œβ”€β”€ stress_test.py                     ❌ MISSING
β”‚   β”œβ”€β”€ memory_test.py                     ❌ MISSING
β”‚   └── seed_data.py                       ❌ MISSING
β”œβ”€β”€ examples/
β”‚   β”œβ”€β”€ config_examples/
β”‚   β”‚   β”œβ”€β”€ minimal.yaml                   ❌ MISSING
β”‚   β”‚   β”œβ”€β”€ full_featured.yaml             ❌ MISSING
β”‚   β”‚   └── team_config.yaml               ❌ MISSING
β”‚   β”œβ”€β”€ broken_scripts/
β”‚   β”‚   β”œβ”€β”€ syntax_error.py                ❌ MISSING
β”‚   β”‚   β”œβ”€β”€ missing_deps.js                ❌ MISSING
β”‚   β”‚   └── permission_error.sh            ❌ MISSING
β”‚   └── demo/
β”‚       β”œβ”€β”€ run_demo.py                    ❌ MISSING
β”‚       └── showcase.sh                    ❌ MISSING
β”œβ”€β”€ monitoring/                            ❌ OPTIONAL
β”‚   β”œβ”€β”€ prometheus.yml
β”‚   └── grafana/
β”‚       β”œβ”€β”€ dashboards/
β”‚       └── datasources/
β”œβ”€β”€ nginx/                                 ❌ OPTIONAL
β”‚   β”œβ”€β”€ nginx.conf
β”‚   └── ssl/
└── babel.cfg                              ❌ OPTIONAL (i18n)

πŸ”§ Files That Need to be Created/Fixed

🚨 CRITICAL (Required for basic functionality)

Missing Core Modules:

  1. airun/core/__init__.py
  2. airun/core/llm_router.py - LLM provider routing logic
  3. airun/core/ai_fixer.py - AI error fixing implementation
  4. airun/providers/ - Complete LLM provider implementations
  5. airun/utils/ - All utility modules
  6. airun/__main__.py - Entry point for python -m airun

Missing Configuration Files:

  1. .gitignore - Git ignore patterns
  2. .pre-commit-config.yaml - Pre-commit hooks
  3. LICENSE - MIT License file
  4. airun/templates/config/default.yaml - Default configuration

Missing Test Infrastructure:

  1. tests/__init__.py and tests/conftest.py
  2. tests/test_llm_router.py - LLM router tests
  3. tests/fixtures/configs/test_config.yaml - Test configuration

⚠️ IMPORTANT (Required for full functionality)

CLI Import Fixes:

  1. Fix imports in airun/cli.py - Missing imports for new modules
  2. Fix imports in tests/test_cli.py - Test import issues

Installation Scripts:

  1. scripts/install.sh - Production installation script
  2. scripts/setup_ollama.sh - Ollama setup automation
  3. scripts/setup_dev.sh - Development environment setup

Documentation:

  1. docs/mkdocs.yml - MkDocs configuration
  2. CHANGELOG.md - Version history
  3. CODE_OF_CONDUCT.md - Community guidelines

πŸ“ NICE TO HAVE (Enhancement features)

GitHub Templates:

  1. .github/ISSUE_TEMPLATE/ - Issue templates
  2. .github/workflows/release.yml - Release automation

Examples and Demos:

  1. examples/ - Example configurations and scripts
  2. scripts/benchmark.py - Performance benchmarking

Advanced Features:

  1. airun/web/ - Web interface (future)
  2. monitoring/ - Monitoring configurations (optional)

πŸ› οΈ Files That Need Fixes

airun/cli.py Import Issues:

# Missing imports that need to be added:
from .core.llm_router import LLMRouter
from .core.ai_fixer import AIFixer
from .utils.logging import setup_logging, get_logger
from .utils.validation import validate_script_path, validate_llm_provider
from .utils.analyzer import ScriptAnalyzer
from .utils.batch_executor import BatchExecutor
from .utils.log_viewer import LogViewer
from .utils.cleaner import DataCleaner
from .utils.examples import ExampleGenerator

tests/test_cli.py Import Issues:

# Missing imports that need to be added:
from airun2.utils.analyzer import ScriptAnalyzer
from airun2.utils.batch_executor import BatchExecutor

⚑ Priority Order for Creation

Phase 1: Core Functionality (MUST HAVE)

  1. Create all __init__.py files
  2. Implement airun/core/llm_router.py
  3. Implement airun/core/ai_fixer.py
  4. Implement airun/providers/ modules
  5. Create .gitignore and basic config files
  6. Fix CLI imports

Phase 2: Essential Utils (SHOULD HAVE)

  1. Implement airun/utils/ modules
  2. Create test infrastructure files
  3. Create installation scripts
  4. Create basic documentation

Phase 3: Polish & Enhancement (NICE TO HAVE)

  1. Create examples and demos
  2. Add GitHub templates
  3. Create monitoring and advanced features

πŸš€ Quick Start Commands

# After creating missing files, run:
make dev-setup          # Will generate test fixtures
poetry install          # Will create poetry.lock
make create-test-scripts # Will create test script fixtures
make doctor             # Will validate setup

This structure provides a clear roadmap for completing the AIRun project with all necessary components.