Skip to content

foryourhealth111-pixel/Vibe-Skills / bundled/skills/autonomous-builder

autonomous-builder

Flagged

Full-stack software development agent for design, implementation, testing, and deployment. Use when the user explicitly asks for end-to-end project creation, feature development, bug fixing, or code refactoring.

assets/auto-continue.ps1

View on GitHub
# =============================================================================
# Auto-Continue Supervisor Script (Windows PowerShell)
# Generated by: autonomous-builder skill
# Purpose: Self-supervising long-running autonomous operation
# =============================================================================

param(
    [string]$ProjectDir = "{{PROJECT_DIR}}"
)

# Configuration
$BuilderDir = Join-Path $ProjectDir ".builder"
$StateFile = Join-Path $BuilderDir "state.json"
$SupervisorConfig = Join-Path $BuilderDir "supervisor.json"
$LogFile = Join-Path $BuilderDir "supervisor.log"

# Default monitoring settings
$CheckInterval = 60
$SessionTimeout = 300
$MaxRestartAttempts = 10
$RestartCooldown = 5

# Statistics
$script:RestartCount = 0
$script:SessionCount = 0

# =============================================================================
# Utility Functions
# =============================================================================

function Write-Log {
    param([string]$Message)
    $timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
    $logEntry = "[$timestamp] $Message"
    Write-Host $logEntry
    Add-Content -Path $LogFile -Value $logEntry
}

function Load-Config {
    if (Test-Path $SupervisorConfig) {
        try {
            $config = Get-Content $SupervisorConfig | ConvertFrom-Json
            $script:CheckInterval = $config.monitoring.check_interval_seconds
            $script:SessionTimeout = $config.monitoring.session_timeout_seconds
            $script:MaxRestartAttempts = $config.monitoring.max_restart_attempts
            $script:RestartCooldown = $config.monitoring.restart_cooldown_seconds
        }
        catch {
            Write-Log "Warning: Could not load supervisor config, using defaults"
        }
    }
}

function Get-ProjectStatus {
    if (Test-Path $StateFile) {
        try {
            $state = Get-Content $StateFile | ConvertFrom-Json
            return $state.status
        }
        catch {
            return "unknown"
        }
    }
    return "not_initialized"
}

function Get-PendingFeaturesCount {
    if (Test-Path $StateFile) {
        try {
            $state = Get-Content $StateFile | ConvertFrom-Json
            $pending = @($state.features.pending | Where-Object { $_ })
            return $pending.Count
        }
        catch {
            return 0
        }
    }
    return 0
}

function Get-CurrentFeature {
    if (Test-Path $StateFile) {
        try {
            $state = Get-Content $StateFile | ConvertFrom-Json
            return $state.current_feature
        }
        catch {
            return $null
        }
    }
    return $null
}

function Update-Statistics {
    try {
        if (Test-Path $SupervisorConfig) {
            $config = Get-Content $SupervisorConfig | ConvertFrom-Json
            $config.statistics.total_sessions = $script:SessionCount
            $config.statistics.total_restarts = $script:RestartCount
            $config.statistics.last_restart_time = (Get-Date -Format "o")
            $config | ConvertTo-Json -Depth 10 | Set-Content $SupervisorConfig
        }
    }
    catch {
        Write-Log "Warning: Could not update statistics"
    }
}

# =============================================================================
# Health Check Functions
# =============================================================================

function Test-ProgressStall {
    param([string]$LastFeature)

    $currentFeature = Get-CurrentFeature

    if ($LastFeature -eq $currentFeature -and $currentFeature) {
        try {
            $state = Get-Content $StateFile | ConvertFrom-Json
            $ops = $state.loop_detection.progress_check.operations_since_progress
            if ($ops -gt 10) {
                return $true
            }
        }
        catch {}
    }
    return $false
}

function Test-ErrorSpike {
    $errorLogFile = Join-Path $BuilderDir "errors.json"
    if (Test-Path $errorLogFile) {
        try {
            $errors = Get-Content $errorLogFile | ConvertFrom-Json
            $recentErrors = @($errors.errors | Where-Object {
                $errorTime = [DateTime]::Parse($_.timestamp)
                $errorTime -gt (Get-Date).AddMinutes(-5)
            })
            return $recentErrors.Count -gt 5
        }
        catch {}
    }
    return $false
}

# =============================================================================
# Main Supervisor Loop
# =============================================================================

function Start-Supervisor {
    Write-Log "=========================================="
    Write-Log "Autonomous Builder Supervisor Started"
    Write-Log "=========================================="
    Write-Log "Project: $ProjectDir"
    Write-Log "Check Interval: ${CheckInterval}s"
    Write-Log "Session Timeout: ${SessionTimeout}s"
    Write-Log "Max Restart Attempts: $MaxRestartAttempts"
    Write-Log ""

    $lastFeature = ""
    $stallCount = 0

    while ($true) {
        Load-Config

        # Check 1: Project completion
        $status = Get-ProjectStatus
        if ($status -eq "completed") {
            Write-Log "✅ Project completed! Supervisor exiting."
            Write-Log "Total sessions: $script:SessionCount"
            Write-Log "Total restarts: $script:RestartCount"
            Update-Statistics
            return
        }

        # Check 2: Pending features
        $pending = Get-PendingFeaturesCount
        if ($pending -eq 0 -and $status -ne "not_initialized") {
            Write-Log "✅ All features completed! Project done."
            return
        }

        # Check 3: Progress stall
        if (Test-ProgressStall -LastFeature $lastFeature) {
            $stallCount++
            Write-Log "⚠️ Progress stall detected (count: $stallCount)"
            if ($stallCount -ge 3) {
                Write-Log "🔴 Too many stalls. Waiting 60 seconds..."
                Start-Sleep -Seconds 60
                $stallCount = 0
            }
        }
        else {
            $stallCount = 0
        }

        # Check 4: Error spike
        if (Test-ErrorSpike) {
            Write-Log "⚠️ Error spike detected. Recording for analysis."
        }

        # Check 5: Max restart attempts
        if ($script:RestartCount -ge $MaxRestartAttempts) {
            Write-Log "🔴 Max restart attempts reached ($MaxRestartAttempts)"
            Write-Log "Waiting 5 minutes before retry..."
            Start-Sleep -Seconds 300
            $script:RestartCount = 0
        }

        # Start/Resume Claude Session
        $script:SessionCount++
        Write-Log "🚀 Starting Claude session #$script:SessionCount..."
        Write-Log "   Pending features: $pending"
        Write-Log "   Current status: $status"

        # Update statistics before session
        Update-Statistics

        # Run Claude with auto-continue
        # Note: --dangerously-skip-permissions enables unattended operation
        # WARNING: This bypasses all permission prompts - use only in trusted environments
        try {
            $process = Start-Process -FilePath "claude" `
                -ArgumentList "--skill", "autonomous-builder", "--project", $ProjectDir, "--dangerously-skip-permissions" `
                -NoNewWindow -Wait -PassThru -RedirectStandardOutput (Join-Path $BuilderDir "session_output.log") `
                -RedirectStandardError (Join-Path $BuilderDir "session_error.log")

            Write-Log "Session ended with code: $($process.ExitCode)"
        }
        catch {
            Write-Log "Error starting Claude session: $_"
        }

        # Update restart count
        $script:RestartCount++

        # Record current feature for stall detection
        $lastFeature = Get-CurrentFeature

        # Cooldown before restart
        Write-Log "Waiting ${RestartCooldown}s before next session..."
        Start-Sleep -Seconds $RestartCooldown
    }
}

# =============================================================================
# Signal Handlers
# =============================================================================

function Stop-Supervisor {
    Write-Log "Supervisor stopped. Saving state..."
    Update-Statistics
    exit 0
}

# Register Ctrl+C handler
[Console]::TreatControlCAsInput = $false
Register-EngineEvent -SourceIdentifier PowerShell.Exiting -Action {
    Stop-Supervisor
}

# =============================================================================
# Entry Point
# =============================================================================

# Validate project directory
if (-not (Test-Path $ProjectDir)) {
    Write-Host "Error: Project directory not found: $ProjectDir"
    exit 1
}

# Create .builder directory if not exists
if (-not (Test-Path $BuilderDir)) {
    New-Item -ItemType Directory -Path $BuilderDir -Force | Out-Null
}

# Initialize log file
if (-not (Test-Path $LogFile)) {
    New-Item -ItemType File -Path $LogFile -Force | Out-Null
}

# Run supervisor
Start-Supervisor
finishing-a-development-branchobra/superpowersUse when implementation is complete, all tests pass, and you need to decide how to integrate the workStars: 322kUpdated Claude CodeCodexVerifiedInstall
systematic-debuggingobra/superpowersUse when encountering any bug, test failure, or unexpected behavior, before proposing fixesStars: 322kUpdated Claude CodeCodexVerifiedInstall
test-driven-developmentobra/superpowersUse when implementing any feature or bugfix, before writing implementation codeStars: 322kUpdated Claude CodeCodexVerifiedInstall
skill-creatoranthropics/skillsCreate new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an existing skill, run evals to test a skill, benchmark skill performance with variance analysis, or optimize a skill's description for better triggering accuracy.Stars: 198kUpdated Claude CodeCodexVerifiedInstall