Update recursive_context.py
Browse files- recursive_context.py +46 -0
recursive_context.py
CHANGED
|
@@ -398,6 +398,52 @@ class RecursiveContextManager:
|
|
| 398 |
return f"STDOUT: {result.stdout}\nSTDERR: {result.stderr}"
|
| 399 |
except Exception as e:
|
| 400 |
return f"Execution Error: {e}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 401 |
|
| 402 |
# =====================================================================
|
| 403 |
# RECURSIVE SEARCH TOOLS
|
|
|
|
| 398 |
return f"STDOUT: {result.stdout}\nSTDERR: {result.stderr}"
|
| 399 |
except Exception as e:
|
| 400 |
return f"Execution Error: {e}"
|
| 401 |
+
def push_to_github(self, commit_message="Auto-backup from Clawdbot"):
|
| 402 |
+
"""Pushes the current workspace to the configured GitHub repository."""
|
| 403 |
+
token = os.getenv("GITHUB_TOKEN")
|
| 404 |
+
repo = os.getenv("GITHUB_REPO")
|
| 405 |
+
|
| 406 |
+
if not token or not repo:
|
| 407 |
+
return "❌ Error: GITHUB_TOKEN or GITHUB_REPO secret is missing."
|
| 408 |
+
|
| 409 |
+
# authenticated URL
|
| 410 |
+
remote_url = f"https://{token}@github.com/{repo}.git"
|
| 411 |
+
|
| 412 |
+
try:
|
| 413 |
+
# 1. Initialize if needed (Docker containers often lack .git)
|
| 414 |
+
if not (self.repo_path / ".git").exists():
|
| 415 |
+
subprocess.run(["git", "init"], cwd=self.repo_path, check=True)
|
| 416 |
+
subprocess.run(["git", "config", "user.email", "clawdbot@e-t-systems.ai"], cwd=self.repo_path)
|
| 417 |
+
subprocess.run(["git", "config", "user.name", "Clawdbot"], cwd=self.repo_path)
|
| 418 |
+
subprocess.run(["git", "branch", "-M", "main"], cwd=self.repo_path)
|
| 419 |
+
|
| 420 |
+
# 2. Configure Remote (Idempotent)
|
| 421 |
+
# Remove existing remote to ensure token is fresh/correct
|
| 422 |
+
subprocess.run(["git", "remote", "remove", "origin"], cwd=self.repo_path, stderr=subprocess.DEVNULL)
|
| 423 |
+
subprocess.run(["git", "remote", "add", "origin", remote_url], cwd=self.repo_path, check=True)
|
| 424 |
+
|
| 425 |
+
# 3. Add, Commit, Push
|
| 426 |
+
subprocess.run(["git", "add", "."], cwd=self.repo_path, check=True)
|
| 427 |
+
|
| 428 |
+
# Commit (allow empty if nothing changed)
|
| 429 |
+
commit_res = subprocess.run(
|
| 430 |
+
["git", "commit", "-m", commit_message],
|
| 431 |
+
cwd=self.repo_path, capture_output=True, text=True
|
| 432 |
+
)
|
| 433 |
+
|
| 434 |
+
# Push (force is safer for a backup mirror to overwrite conflicts)
|
| 435 |
+
push_res = subprocess.run(
|
| 436 |
+
["git", "push", "-u", "origin", "main", "--force"],
|
| 437 |
+
cwd=self.repo_path, capture_output=True, text=True
|
| 438 |
+
)
|
| 439 |
+
|
| 440 |
+
if push_res.returncode == 0:
|
| 441 |
+
return f"✅ Successfully pushed to GitHub: https://github.com/{repo}"
|
| 442 |
+
else:
|
| 443 |
+
return f"⚠️ Git Push Failed: {push_res.stderr}"
|
| 444 |
+
|
| 445 |
+
except Exception as e:
|
| 446 |
+
return f"❌ Critical Git Error: {e}"
|
| 447 |
|
| 448 |
# =====================================================================
|
| 449 |
# RECURSIVE SEARCH TOOLS
|