fix: resolve workspace path from openclaw.json for cross-machine compatibility (v2.5.0)

This commit is contained in:
2026-03-19 09:28:20 +10:00
parent 772c964740
commit fe13ea19be
3 changed files with 31 additions and 7 deletions
+1 -5
View File
@@ -124,11 +124,7 @@ for agent in agents:
seen.add(agent_id)
name = agent.get('name', agent_id)
workspace = agent.get('workspace', default_ws if agent_id == 'main' else None)
# Skip agents without a resolvable workspace
if not workspace:
workspace = os.path.join(openclaw_dir, 'workspaces', agent_id)
workspace = agent.get('workspace', default_ws)
# Expand ~ in path
workspace = os.path.expanduser(workspace)
+29 -1
View File
@@ -31,13 +31,14 @@ header() { echo -e "\n${BOLD}$*${RESET}"; }
# Argument parsing
# ---------------------------------------------------------------------------
WORKSPACE="${HOME}/.openclaw/workspace/main"
WORKSPACE_EXPLICIT=false
SHOW_SAMPLE=false
ALL_AGENTS=false
while [[ $# -gt 0 ]]; do
case "$1" in
--workspace)
WORKSPACE="$2"; shift 2 ;;
WORKSPACE="$2"; WORKSPACE_EXPLICIT=true; shift 2 ;;
--sample)
SHOW_SAMPLE=true; shift ;;
--all-agents)
@@ -225,6 +226,33 @@ if $ALL_AGENTS; then
[[ $TOTAL_FAIL -gt 0 ]] && exit 1 || exit 0
fi
# ---------------------------------------------------------------------------
# Resolve WORKSPACE from openclaw.json if not explicitly set via --workspace
# ---------------------------------------------------------------------------
# If not explicitly set, try to derive from the first alive agent in openclaw.json
if ! $WORKSPACE_EXPLICIT && [[ -f "$CONFIG_FILE" ]] && command -v python3 &>/dev/null; then
RESOLVED_WS=$(python3 - "$CONFIG_FILE" "$OPENCLAW_DIR" <<'PYEOF'
import json, sys, os
config_file = sys.argv[1]
openclaw_dir = sys.argv[2]
try:
with open(config_file) as f:
data = json.load(f)
default_ws = data.get('agents', {}).get('defaults', {}).get('workspace', '')
for agent in data.get('agents', {}).get('list', []):
ws = agent.get('workspace', default_ws)
if ws:
print(os.path.expanduser(ws))
break
except Exception:
pass
PYEOF
)
if [[ -n "$RESOLVED_WS" ]]; then
WORKSPACE="$RESOLVED_WS"
fi
fi
# ---------------------------------------------------------------------------
# Header
# ---------------------------------------------------------------------------