Update recursive_context.py
Browse files- recursive_context.py +56 -1
recursive_context.py
CHANGED
|
@@ -699,4 +699,59 @@ class RecursiveContextManager:
|
|
| 699 |
})
|
| 700 |
|
| 701 |
# 3. Push the entire manifest back to your PRO storage dataset
|
| 702 |
-
self.persistence.save_conversations(full_data)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 699 |
})
|
| 700 |
|
| 701 |
# 3. Push the entire manifest back to your PRO storage dataset
|
| 702 |
+
self.persistence.save_conversations(full_data)
|
| 703 |
+
|
| 704 |
+
# =====================================================================
|
| 705 |
+
# WORKING MEMORY & GIT TOOLS (Paste this at the end of the class)
|
| 706 |
+
# =====================================================================
|
| 707 |
+
def push_to_github(self, commit_message="Auto-backup from Clawdbot"):
|
| 708 |
+
"""Pushes the current workspace to the configured GitHub repository."""
|
| 709 |
+
token = os.getenv("GITHUB_TOKEN")
|
| 710 |
+
repo = os.getenv("GITHUB_REPO")
|
| 711 |
+
if not token or not repo: return "❌ Error: GITHUB_TOKEN or GITHUB_REPO secret is missing."
|
| 712 |
+
remote_url = f"https://{token}@github.com/{repo}.git"
|
| 713 |
+
try:
|
| 714 |
+
if not (self.repo_path / ".git").exists():
|
| 715 |
+
subprocess.run(["git", "init"], cwd=self.repo_path, check=True)
|
| 716 |
+
subprocess.run(["git", "remote", "add", "origin", remote_url], cwd=self.repo_path)
|
| 717 |
+
subprocess.run(["git", "fetch", "origin"], cwd=self.repo_path, check=True) # Fetch first to avoid conflicts
|
| 718 |
+
subprocess.run(["git", "add", "."], cwd=self.repo_path, check=True)
|
| 719 |
+
subprocess.run(["git", "commit", "-m", commit_message], cwd=self.repo_path, capture_output=True, text=True)
|
| 720 |
+
push_res = subprocess.run(["git", "push", "-u", "origin", "main", "--force"], cwd=self.repo_path, capture_output=True, text=True)
|
| 721 |
+
return f"✅ Pushed to GitHub: https://github.com/{repo}" if push_res.returncode == 0 else f"⚠️ Push Failed: {push_res.stderr}"
|
| 722 |
+
except Exception as e: return f"❌ Critical Git Error: {e}"
|
| 723 |
+
|
| 724 |
+
def pull_from_github(self, branch="main"):
|
| 725 |
+
"""Hard reset: Destroys local changes and pulls clean code from GitHub."""
|
| 726 |
+
token = os.getenv("GITHUB_TOKEN")
|
| 727 |
+
repo = os.getenv("GITHUB_REPO")
|
| 728 |
+
if not token or not repo: return "❌ Error: GITHUB_TOKEN or GITHUB_REPO secret is missing."
|
| 729 |
+
remote_url = f"https://{token}@github.com/{repo}.git"
|
| 730 |
+
try:
|
| 731 |
+
if not (self.repo_path / ".git").exists():
|
| 732 |
+
subprocess.run(["git", "init"], cwd=self.repo_path, check=True)
|
| 733 |
+
subprocess.run(["git", "remote", "add", "origin", remote_url], cwd=self.repo_path)
|
| 734 |
+
subprocess.run(["git", "fetch", "origin"], cwd=self.repo_path, check=True)
|
| 735 |
+
res = subprocess.run(["git", "reset", "--hard", f"origin/{branch}"], cwd=self.repo_path, capture_output=True, text=True)
|
| 736 |
+
return f"✅ RESTORED from GitHub/{branch}" if res.returncode == 0 else f"⚠️ Pull Failed: {res.stderr}"
|
| 737 |
+
except Exception as e: return f"❌ Critical Git Error: {e}"
|
| 738 |
+
|
| 739 |
+
def read_working_memory(self) -> str:
|
| 740 |
+
"""Reads the active working memory (whiteboard) content."""
|
| 741 |
+
memory_file = self.repo_path / "memory" / "active_context.md"
|
| 742 |
+
return memory_file.read_text(encoding='utf-8', errors='ignore') if memory_file.exists() else ""
|
| 743 |
+
|
| 744 |
+
def update_working_memory(self, content: str, mode: str = "append") -> str:
|
| 745 |
+
"""Updates the working memory. Modes: 'append' or 'overwrite'."""
|
| 746 |
+
memory_file = self.repo_path / "memory" / "active_context.md"
|
| 747 |
+
try:
|
| 748 |
+
memory_file.parent.mkdir(parents=True, exist_ok=True)
|
| 749 |
+
timestamp = time.strftime("%Y-%m-%d %H:%M:%S")
|
| 750 |
+
if mode == "overwrite":
|
| 751 |
+
final_content = content
|
| 752 |
+
else:
|
| 753 |
+
current = memory_file.read_text(encoding='utf-8', errors='ignore') if memory_file.exists() else ""
|
| 754 |
+
final_content = f"{current}\n- [{timestamp}] {content}"
|
| 755 |
+
memory_file.write_text(final_content, encoding='utf-8')
|
| 756 |
+
return f"✅ Memory updated ({mode})."
|
| 757 |
+
except Exception as e: return f"❌ Error: {e}"
|