A complete AI agency at your fingertips - From frontend wizards to Reddit community ninjas, from whimsy injectors to reality checkers. Each agent is a specialized expert with personality, processes, and proven deliverables.
Shell
fix(openclaw): detect existing agents and report registration failures
Rudy Celekli2ce9ca601a8e
diff --git a/.github/workflows/test-install.yml b/.github/workflows/test-install.ymlindex 4318ac30..749b6ebe 100644--- a/.github/workflows/test-install.yml+++ b/.github/workflows/test-install.yml@@ -28,3 +28,4 @@ jobs:run: |chmod +x scripts/test-install.sh scripts/install.sh./scripts/test-install.sh+ bash scripts/test-install-openclaw-registration.shdiff --git a/scripts/install.sh b/scripts/install.shindex 8fde392a..c214277c 100755--- a/scripts/install.sh+++ b/scripts/install.sh@@ -936,7 +936,15 @@ install_openclaw() {[[ -d "$src" ]] || { err "integrations/openclaw missing. Run convert.sh first."; return 1; }mkdir -p "$dest"if command -v openclaw >/dev/null 2>&1; then- existing_agents=$'\n'"$(openclaw agents list --json 2>/dev/null | sed -n 's/^[[:space:]]*\"id\": \"\\([^\"]*\\)\".*/\\1/p')"$'\n'+ local agents_json+ if ! agents_json="$(openclaw agents list --json 2>/dev/null)"; then+ err "OpenClaw: could not list registered agents; refusing to guess which workspaces need registration."+ return 1+ fi+ # IDs may appear in compact or pretty JSON, and several may share a line.+ # Agent IDs are slugs, so quoted id tokens need no JSON parser dependency.+ existing_agents=$'\n'"$(printf '%s' "$agents_json" | grep -oE '"id"[[:space:]]*:[[:space:]]*"[^"]*"' \+ | sed -E 's/^"id"[[:space:]]*:[[:space:]]*"([^"]*)"$/\1/' || true)"$'\n'filocal dwhile IFS= read -r -d '' d; do@@ -949,7 +957,10 @@ install_openclaw() {install_file "$d/IDENTITY.md" "$dest/$name/IDENTITY.md"if command -v openclaw >/dev/null 2>&1; thenif [[ "$existing_agents" != *$'\n'"$name"$'\n'* ]]; then- openclaw agents add "$name" --workspace "$dest/$name" --non-interactive || true+ if ! openclaw agents add "$name" --workspace "$dest/$name" --non-interactive; then+ err "OpenClaw: failed to register '$name'; the copied workspace is not active."+ return 1+ fififi(( count++ )) || truediff --git a/scripts/test-install-openclaw-registration.sh b/scripts/test-install-openclaw-registration.shnew file mode 100644index 00000000..1daaaa53--- /dev/null+++ b/scripts/test-install-openclaw-registration.sh@@ -0,0 +1,71 @@+#!/usr/bin/env bash+# Existing agents must not be registered again, and failed registration must+# not be reported as a successful OpenClaw install.+set -euo pipefail++SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"+scratch="$(mktemp -d)"+trap 'rm -rf "$scratch"' EXIT+mkdir -p "$scratch/repo/scripts" "$scratch/repo/engineering" \+ "$scratch/repo/integrations/openclaw/example-agent" "$scratch/bin"+cp "$SCRIPT_DIR/install.sh" "$SCRIPT_DIR/lib.sh" "$scratch/repo/scripts/"+cp "$SCRIPT_DIR/../divisions.json" "$scratch/repo/"+cat > "$scratch/repo/engineering/example.md" <<'EOF'+---+name: Example Agent+description: Example+color: blue+---+# Example Agent+EOF+for f in SOUL.md AGENTS.md IDENTITY.md; do+ printf '# Example Agent\n' > "$scratch/repo/integrations/openclaw/example-agent/$f"+done+cat > "$scratch/bin/openclaw" <<'EOF'+#!/usr/bin/env bash+if [[ "$1 $2 $3" == 'agents list --json' ]]; then+ if [[ "$OPENCLAW_TEST_MODE" == list-fail ]]; then+ exit 48+ elif [[ "$OPENCLAW_TEST_MODE" == existing ]]; then+ printf '[{"id":"example-agent"}]\n'+ else+ printf '[]\n'+ fi+elif [[ "$1 $2" == 'agents add' ]]; then+ printf 'add called\n' >> "$OPENCLAW_TEST_LOG"+ exit 47+else+ exit 1+fi+EOF+chmod +x "$scratch/bin/openclaw"++export OPENCLAW_TEST_LOG="$scratch/add.log"+export PATH="$scratch/bin:$PATH"+export HOME="$scratch/home"+export OPENCLAW_TEST_MODE=existing+bash "$scratch/repo/scripts/install.sh" --tool openclaw --agent example-agent \+ --no-convert --path "$scratch/destination" > "$scratch/existing.log" 2>&1+[[ ! -e "$OPENCLAW_TEST_LOG" ]] || {+ echo 'FAIL: compact JSON existing agent was registered again' >&2+ exit 1+}++export OPENCLAW_TEST_MODE=missing+if bash "$scratch/repo/scripts/install.sh" --tool openclaw --agent example-agent \+ --no-convert --path "$scratch/destination" > "$scratch/missing.log" 2>&1; then+ echo 'FAIL: failed OpenClaw registration was reported as successful' >&2+ exit 1+fi+grep -q 'failed to register' "$scratch/missing.log"++rm -f "$OPENCLAW_TEST_LOG"+export OPENCLAW_TEST_MODE=list-fail+if bash "$scratch/repo/scripts/install.sh" --tool openclaw --agent example-agent \+ --no-convert --path "$scratch/destination" > "$scratch/list-fail.log" 2>&1; then+ echo 'FAIL: failed OpenClaw roster query was reported as successful' >&2+ exit 1+fi+grep -q 'could not list registered agents' "$scratch/list-fail.log"+[[ ! -e "$OPENCLAW_TEST_LOG" ]]+echo 'PASS: OpenClaw existing-agent detection and registration failure reporting'