Executor-Tyrant-Framework commited on
Commit
c88268c
·
verified ·
1 Parent(s): c8af4ea

Update recursive_context.py

Browse files
Files changed (1) hide show
  1. recursive_context.py +47 -0
recursive_context.py CHANGED
@@ -445,6 +445,53 @@ class RecursiveContextManager:
445
  except Exception as e:
446
  return f"❌ Critical Git Error: {e}"
447
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
448
  def pull_from_github(self, branch="main"):
449
  """Hard reset: Destroys local changes and pulls clean code from GitHub."""
450
  token = os.getenv("GITHUB_TOKEN")
 
445
  except Exception as e:
446
  return f"❌ Critical Git Error: {e}"
447
 
448
+ def push_to_github(self, commit_message="Auto-backup from Clawdbot"):
449
+ """Pushes the current workspace to the configured GitHub repository."""
450
+ token = os.getenv("GITHUB_TOKEN")
451
+ repo = os.getenv("GITHUB_REPO")
452
+
453
+ if not token or not repo:
454
+ return "❌ Error: GITHUB_TOKEN or GITHUB_REPO secret is missing."
455
+
456
+ # authenticated URL
457
+ remote_url = f"https://{token}@github.com/{repo}.git"
458
+
459
+ try:
460
+ # 1. Initialize if needed (Docker containers often lack .git)
461
+ if not (self.repo_path / ".git").exists():
462
+ subprocess.run(["git", "init"], cwd=self.repo_path, check=True)
463
+ subprocess.run(["git", "config", "user.email", "clawdbot@e-t-systems.ai"], cwd=self.repo_path)
464
+ subprocess.run(["git", "config", "user.name", "Clawdbot"], cwd=self.repo_path)
465
+ subprocess.run(["git", "branch", "-M", "main"], cwd=self.repo_path)
466
+
467
+ # 2. Configure Remote (Idempotent)
468
+ # Remove existing remote to ensure token is fresh/correct
469
+ subprocess.run(["git", "remote", "remove", "origin"], cwd=self.repo_path, stderr=subprocess.DEVNULL)
470
+ subprocess.run(["git", "remote", "add", "origin", remote_url], cwd=self.repo_path, check=True)
471
+
472
+ # 3. Add, Commit, Push
473
+ subprocess.run(["git", "add", "."], cwd=self.repo_path, check=True)
474
+
475
+ # Commit (allow empty if nothing changed)
476
+ commit_res = subprocess.run(
477
+ ["git", "commit", "-m", commit_message],
478
+ cwd=self.repo_path, capture_output=True, text=True
479
+ )
480
+
481
+ # Push (force is safer for a backup mirror to overwrite conflicts)
482
+ push_res = subprocess.run(
483
+ ["git", "push", "-u", "origin", "main", "--force"],
484
+ cwd=self.repo_path, capture_output=True, text=True
485
+ )
486
+
487
+ if push_res.returncode == 0:
488
+ return f"✅ Successfully pushed to GitHub: https://github.com/{repo}"
489
+ else:
490
+ return f"⚠️ Git Push Failed: {push_res.stderr}"
491
+
492
+ except Exception as e:
493
+ return f"❌ Critical Git Error: {e}"
494
+
495
  def pull_from_github(self, branch="main"):
496
  """Hard reset: Destroys local changes and pulls clean code from GitHub."""
497
  token = os.getenv("GITHUB_TOKEN")