#!/usr/bin/env python3
"""
Demo script showing how to use OpenCode CLI
This demonstrates OpenCode capabilities without requiring a running server
"""

import subprocess
import sys
import os

def run_opencode_command(args):
    """Run an OpenCode command and return the result."""
    try:
        # Use the full path to the opencode CLI binary
        cmd = ["/home/wildlama/.hermes/hermes-agent/venv/bin/oc"] + args
        
        print(f"Running: {' '.join(cmd)}")
        
        result = subprocess.run(
            cmd, 
            capture_output=True, 
            text=True,
            timeout=10  # 10 second timeout
        )
        
        if result.returncode == 0:
            print("Success:")
            print(result.stdout)
            return True
        else:
            print("Error occurred:")
            print(f"Return code: {result.returncode}")
            print(f"Stderr: {result.stderr}")
            return False
            
    except subprocess.TimeoutExpired:
        print("Command timed out after 10 seconds")
        return False
    except Exception as e:
        print(f"Exception occurred: {e}")
        return False

def main():
    print("=== OpenCode CLI Demo ===")
    print()
    
    # Show help to demonstrate it's working
    print("1. Getting OpenCode CLI help:")
    run_opencode_command(["--help"])
    print()
    
    # Try the sessions command (should fail gracefully with no server)
    print("2. Trying to list sessions (will show error if no server):")
    run_opencode_command(["sessions"])
    print()
    
    # Show example of creating a session
    print("3. Example of how to create a session:")
    print("   oc create --name 'My First Session'")
    print()
    
    # Show example of sending a message to a session
    print("4. Example of how to send a message to a session:")
    print("   oc send --session-id <session_id> --message 'Hello from OpenCode CLI'")
    print()

if __name__ == "__main__":
    main()