Spaces:
Running
Running
feat: implement state persistence for agents, memory, and extensions across workspace syncs
Browse files- start.sh +24 -0
- workspace-sync.py +23 -1
start.sh
CHANGED
|
@@ -91,6 +91,8 @@ esac
|
|
| 91 |
# ββ Setup directories ββ
|
| 92 |
mkdir -p /home/node/.openclaw/agents/main/sessions
|
| 93 |
mkdir -p /home/node/.openclaw/credentials
|
|
|
|
|
|
|
| 94 |
mkdir -p /home/node/.openclaw/workspace
|
| 95 |
chmod 700 /home/node/.openclaw
|
| 96 |
chmod 700 /home/node/.openclaw/credentials
|
|
@@ -165,6 +167,28 @@ if [ -n "$HF_USERNAME" ] && [ -n "$HF_TOKEN" ]; then
|
|
| 165 |
cd /
|
| 166 |
fi
|
| 167 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 168 |
# ββ Restore persisted WhatsApp credentials (if present) ββ
|
| 169 |
WA_BACKUP_DIR="/home/node/.openclaw/workspace/.huggingclaw-state/credentials/whatsapp/default"
|
| 170 |
WA_CREDS_DIR="/home/node/.openclaw/credentials/whatsapp/default"
|
|
|
|
| 91 |
# ββ Setup directories ββ
|
| 92 |
mkdir -p /home/node/.openclaw/agents/main/sessions
|
| 93 |
mkdir -p /home/node/.openclaw/credentials
|
| 94 |
+
mkdir -p /home/node/.openclaw/memory
|
| 95 |
+
mkdir -p /home/node/.openclaw/extensions
|
| 96 |
mkdir -p /home/node/.openclaw/workspace
|
| 97 |
chmod 700 /home/node/.openclaw
|
| 98 |
chmod 700 /home/node/.openclaw/credentials
|
|
|
|
| 167 |
cd /
|
| 168 |
fi
|
| 169 |
|
| 170 |
+
# ββ Restore persisted OpenClaw state (if present) ββ
|
| 171 |
+
STATE_BACKUP_ROOT="/home/node/.openclaw/workspace/.huggingclaw-state/openclaw"
|
| 172 |
+
restore_state_dir() {
|
| 173 |
+
local name="$1"
|
| 174 |
+
local source_dir="${STATE_BACKUP_ROOT}/${name}"
|
| 175 |
+
local target_dir="/home/node/.openclaw/${name}"
|
| 176 |
+
|
| 177 |
+
if [ ! -d "$source_dir" ]; then
|
| 178 |
+
return
|
| 179 |
+
fi
|
| 180 |
+
|
| 181 |
+
echo "π§ Restoring OpenClaw ${name} state..."
|
| 182 |
+
rm -rf "$target_dir"
|
| 183 |
+
mkdir -p "$(dirname "$target_dir")"
|
| 184 |
+
cp -R "$source_dir" "$target_dir"
|
| 185 |
+
echo " β
${name} restored"
|
| 186 |
+
}
|
| 187 |
+
|
| 188 |
+
restore_state_dir "agents"
|
| 189 |
+
restore_state_dir "memory"
|
| 190 |
+
restore_state_dir "extensions"
|
| 191 |
+
|
| 192 |
# ββ Restore persisted WhatsApp credentials (if present) ββ
|
| 193 |
WA_BACKUP_DIR="/home/node/.openclaw/workspace/.huggingclaw-state/credentials/whatsapp/default"
|
| 194 |
WA_CREDS_DIR="/home/node/.openclaw/credentials/whatsapp/default"
|
workspace-sync.py
CHANGED
|
@@ -15,8 +15,15 @@ import shutil
|
|
| 15 |
import subprocess
|
| 16 |
from pathlib import Path
|
| 17 |
|
| 18 |
-
|
|
|
|
| 19 |
STATE_DIR = WORKSPACE / ".huggingclaw-state"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
WHATSAPP_CREDS_DIR = Path("/home/node/.openclaw/credentials/whatsapp/default")
|
| 21 |
WHATSAPP_BACKUP_DIR = STATE_DIR / "credentials" / "whatsapp" / "default"
|
| 22 |
RESET_MARKER = WORKSPACE / ".reset_credentials"
|
|
@@ -52,6 +59,21 @@ def snapshot_state_into_workspace() -> None:
|
|
| 52 |
This keeps WhatsApp credentials in a hidden folder that is synced together
|
| 53 |
with the workspace, without changing the live credentials location.
|
| 54 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
try:
|
| 56 |
if not WHATSAPP_ENABLED:
|
| 57 |
return
|
|
|
|
| 15 |
import subprocess
|
| 16 |
from pathlib import Path
|
| 17 |
|
| 18 |
+
OPENCLAW_HOME = Path("/home/node/.openclaw")
|
| 19 |
+
WORKSPACE = OPENCLAW_HOME / "workspace"
|
| 20 |
STATE_DIR = WORKSPACE / ".huggingclaw-state"
|
| 21 |
+
OPENCLAW_STATE_BACKUP_DIR = STATE_DIR / "openclaw"
|
| 22 |
+
PERSISTED_STATE_PATHS = {
|
| 23 |
+
"agents": OPENCLAW_HOME / "agents",
|
| 24 |
+
"memory": OPENCLAW_HOME / "memory",
|
| 25 |
+
"extensions": OPENCLAW_HOME / "extensions",
|
| 26 |
+
}
|
| 27 |
WHATSAPP_CREDS_DIR = Path("/home/node/.openclaw/credentials/whatsapp/default")
|
| 28 |
WHATSAPP_BACKUP_DIR = STATE_DIR / "credentials" / "whatsapp" / "default"
|
| 29 |
RESET_MARKER = WORKSPACE / ".reset_credentials"
|
|
|
|
| 59 |
This keeps WhatsApp credentials in a hidden folder that is synced together
|
| 60 |
with the workspace, without changing the live credentials location.
|
| 61 |
"""
|
| 62 |
+
try:
|
| 63 |
+
STATE_DIR.mkdir(parents=True, exist_ok=True)
|
| 64 |
+
|
| 65 |
+
for name, source_path in PERSISTED_STATE_PATHS.items():
|
| 66 |
+
if not source_path.exists():
|
| 67 |
+
continue
|
| 68 |
+
|
| 69 |
+
backup_path = OPENCLAW_STATE_BACKUP_DIR / name
|
| 70 |
+
backup_path.parent.mkdir(parents=True, exist_ok=True)
|
| 71 |
+
if backup_path.exists():
|
| 72 |
+
shutil.rmtree(backup_path, ignore_errors=True)
|
| 73 |
+
shutil.copytree(source_path, backup_path)
|
| 74 |
+
except Exception as e:
|
| 75 |
+
print(f" β οΈ Could not snapshot OpenClaw state: {e}")
|
| 76 |
+
|
| 77 |
try:
|
| 78 |
if not WHATSAPP_ENABLED:
|
| 79 |
return
|