#!/usr/bin/env bash set -euo pipefail # ClawRoles installer # # 1. Copies ClawRoles to ~/.openclaw/ClawRoles # 2. Copies role-code-mapper to ~/.openclaw/bin # 3. Installs routers into PrismFacet # 4. Registers rules in PrismFacet's rules.json # # Usage: ./install.sh [--prism-dir ] SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" INSTALL_DIR="${HOME}/.openclaw/ClawRoles" BIN_DIR="${HOME}/.openclaw/bin" PRISM_DIR="${HOME}/.openclaw/plugins/prism-facet" # Parse args while [[ $# -gt 0 ]]; do case "$1" in --prism-dir) PRISM_DIR="$2"; shift 2 ;; *) echo "Unknown option: $1"; exit 1 ;; esac done # 1. Copy ClawRoles to ~/.openclaw/ClawRoles echo "Installing ClawRoles to ${INSTALL_DIR}..." mkdir -p "$INSTALL_DIR" cp -r "$SCRIPT_DIR"/roles "$INSTALL_DIR/" cp -r "$SCRIPT_DIR"/positions "$INSTALL_DIR/" cp -r "$SCRIPT_DIR"/routers "$INSTALL_DIR/" cp -r "$SCRIPT_DIR"/scripts "$INSTALL_DIR/" cp "$SCRIPT_DIR"/install.sh "$INSTALL_DIR/" echo " ClawRoles copied." # 2. Copy role-code-mapper to ~/.openclaw/bin echo "Installing role-code-mapper..." mkdir -p "$BIN_DIR" cp "$SCRIPT_DIR/scripts/role-code-mapper" "$BIN_DIR/role-code-mapper" chmod +x "$BIN_DIR/role-code-mapper" echo " role-code-mapper installed to ${BIN_DIR}/" # 3. Install routers into PrismFacet if [[ ! -d "$PRISM_DIR" ]]; then echo "Warning: PrismFacet not found at $PRISM_DIR — skipping router/rule registration." echo "Run again after installing PrismFacet, or specify --prism-dir." echo "Done (partial)." exit 0 fi ROUTERS_DIR="${PRISM_DIR}/routers" RULES_FILE="${PRISM_DIR}/rules.json" mkdir -p "$ROUTERS_DIR" echo "Installing routers to PrismFacet..." for router_ts in "$INSTALL_DIR"/routers/*.ts; do name=$(basename "$router_ts" .ts) # Strip TypeScript types for JS output sed -E 's/: \{ agentId: string \}//g; s/: string//g' \ "$router_ts" > "${ROUTERS_DIR}/${name}.js" echo " Installed router: $name" done # 4. Register rules in PrismFacet echo "Registering rules..." if [[ -f "$RULES_FILE" ]]; then RULES=$(cat "$RULES_FILE") else RULES="{}" fi # Roles for role_dir in "$INSTALL_DIR"/roles/*/; do role_name=$(basename "$role_dir") role_file="${role_dir}ROLE.md" if [[ -f "$role_file" ]]; then RULES=$(echo "$RULES" | python3 -c " import json, sys d = json.load(sys.stdin) d['role:${role_name}'] = '${role_file}' print(json.dumps(d, indent=2)) ") echo " rule: role:${role_name}" fi done # Positions for pos_dir in "$INSTALL_DIR"/positions/*/; do pos_name=$(basename "$pos_dir") pos_file="${pos_dir}POSITION.md" if [[ -f "$pos_file" ]]; then RULES=$(echo "$RULES" | python3 -c " import json, sys d = json.load(sys.stdin) d['position:${pos_name}'] = '${pos_file}' print(json.dumps(d, indent=2)) ") echo " rule: position:${pos_name}" fi done echo "$RULES" > "$RULES_FILE" echo "Done. Restart OpenClaw gateway to apply changes."