From aaa39c1e8cad6637d0ad36e7b867eb718169a212 Mon Sep 17 00:00:00 2001 From: DiTus Date: Fri, 19 Dec 2025 22:09:45 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20Add=20Git=20Agent=20OpenCode=20i?= =?UTF-8?q?ntegration?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Created git_opencode.py for direct command access - Fixes Unicode encoding issues in git_agent.py - Provides backup, status, cleanup, and restore commands - Simplified OpenCode integration without slash commands - Maintains all Git Agent functionality Ready for OpenCode direct command usage: python tools/git_opencode.py backup python tools/git_opencode.py status python tools/git_opencode.py cleanup python tools/git_opencode.py restore --- tools/git_opencode.py | 159 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 159 insertions(+) create mode 100644 tools/git_opencode.py diff --git a/tools/git_opencode.py b/tools/git_opencode.py new file mode 100644 index 0000000..48cf1e9 --- /dev/null +++ b/tools/git_opencode.py @@ -0,0 +1,159 @@ +#!/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") \ No newline at end of file