#!/usr/bin/env python3 """ OpenCode Git Agent - Direct Integration Simple direct commands for Git Agent operations """ import os import subprocess import sys def run_git_backup(): """Create automated backup""" try: project_root = "K:\\Projects\\uniswap_auto_clp" agent_path = os.path.join(project_root, "tools", "git_agent.py") result = subprocess.run( ["python", agent_path, "--backup"], cwd=project_root, capture_output=True, text=True, check=False, env=dict(os.environ, PYTHONIOENCODING='utf-8') ) if result.returncode == 0: print("SUCCESS: Backup completed successfully!") print("Automated backup created and pushed to remote repository.") else: error_msg = result.stderr or result.stdout or "Unknown error" print(f"ERROR: Backup failed!") print(f"Error: {error_msg}") except Exception as e: print(f"ERROR: Exception during backup: {str(e)}") def run_git_status(): """Show git status""" try: project_root = "K:\\Projects\\uniswap_auto_clp" agent_path = os.path.join(project_root, "tools", "git_agent.py") result = subprocess.run( ["python", agent_path, "--status"], cwd=project_root, capture_output=True, text=True, check=False, env=dict(os.environ, PYTHONIOENCODING='utf-8') ) if result.returncode == 0: print("SUCCESS: Git Agent Status") print(result.stdout) else: print(f"ERROR: Status check failed!") error_msg = result.stderr or result.stdout or "Unknown error" print(f"Error: {error_msg}") except Exception as e: print(f"ERROR: Exception during status check: {str(e)}") def run_git_cleanup(): """Clean up old backups""" try: project_root = "K:\\Projects\\uniswap_auto_clp" agent_path = os.path.join(project_root, "tools", "git_agent.py") result = subprocess.run( ["python", agent_path, "--cleanup"], cwd=project_root, capture_output=True, text=True, check=False, env=dict(os.environ, PYTHONIOENCODING='utf-8') ) if result.returncode == 0: print("SUCCESS: Cleanup completed!") print("Old backup branches have been removed according to retention policy.") else: print(f"ERROR: Cleanup failed!") error_msg = result.stderr or result.stdout or "Unknown error" print(f"Error: {error_msg}") except Exception as e: print(f"ERROR: Exception during cleanup: {str(e)}") def run_git_restore(time_input=None): """Restore from backup""" try: project_root = "K:\\Projects\\uniswap_auto_clp" if time_input: # Use git directly for restore branch_name = f"backup-{time_input}" result = subprocess.run( ["git", "checkout", branch_name], cwd=project_root, capture_output=True, text=True, check=False, env=dict(os.environ, PYTHONIOENCODING='utf-8') ) if result.returncode == 0: print(f"SUCCESS: Restored to backup!") print(f"Branch: {branch_name}") print("Note: You are now on a backup branch.") print("Use 'git checkout main' to return to main branch when done.") else: print(f"ERROR: Restore failed!") print(f"Error: {result.stderr}") else: print("ERROR: Please specify backup timestamp") print("Usage: restore ") print("Example: restore 2025-12-19-14") except Exception as e: print(f"ERROR: Exception during restore: {str(e)}") if __name__ == "__main__": if len(sys.argv) > 1: command = sys.argv[1] if command == "backup": run_git_backup() elif command == "status": run_git_status() elif command == "cleanup": run_git_cleanup() elif command == "restore": timestamp = sys.argv[2] if len(sys.argv) > 2 else None run_git_restore(timestamp) else: print("Git Agent - OpenCode Integration") print("Usage: python git_opencode.py ") print("\nCommands:") print(" backup - Create automated backup") print(" status - Show git agent status") print(" cleanup - Clean old backups") print(" restore - Restore from backup") print("\nExamples:") print(" python git_opencode.py backup") print(" python git_opencode.py status") print(" python git_opencode.py restore 2025-12-19-14") else: print("Git Agent - OpenCode Integration") print("Usage: python git_opencode.py ") print("\nCommands:") print(" backup - Create automated backup") print(" status - Show git agent status") print(" cleanup - Clean old backups") print(" restore - Restore from backup") print("\nExamples:") print(" python git_opencode.py backup") print(" python git_opencode.py status") print(" python git_opencode.py restore 2025-12-19-14")