feat: role-code-mapper script + updated install.sh
- scripts/role-code-mapper: echoes role-code for a given role name - install.sh now: 1. Copies ClawRoles to ~/.openclaw/ClawRoles 2. Copies role-code-mapper to ~/.openclaw/bin 3. Installs routers to PrismFacet (if present) 4. Registers rules in PrismFacet rules.json Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
74
install.sh
74
install.sh
@@ -2,12 +2,17 @@
|
|||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
# ClawRoles installer
|
# ClawRoles installer
|
||||||
# Installs routers and registers rules into PrismFacet.
|
#
|
||||||
|
# 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 <path>]
|
# Usage: ./install.sh [--prism-dir <path>]
|
||||||
# --prism-dir: PrismFacet plugin directory (default: ~/.openclaw/plugins/prism-facet)
|
|
||||||
|
|
||||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
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"
|
PRISM_DIR="${HOME}/.openclaw/plugins/prism-facet"
|
||||||
|
|
||||||
# Parse args
|
# Parse args
|
||||||
@@ -18,51 +23,55 @@ while [[ $# -gt 0 ]]; do
|
|||||||
esac
|
esac
|
||||||
done
|
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
|
if [[ ! -d "$PRISM_DIR" ]]; then
|
||||||
echo "Error: PrismFacet not found at $PRISM_DIR"
|
echo "Warning: PrismFacet not found at $PRISM_DIR — skipping router/rule registration."
|
||||||
echo "Install PrismFacet first, or specify --prism-dir"
|
echo "Run again after installing PrismFacet, or specify --prism-dir."
|
||||||
exit 1
|
echo "Done (partial)."
|
||||||
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
ROUTERS_DIR="${PRISM_DIR}/routers"
|
ROUTERS_DIR="${PRISM_DIR}/routers"
|
||||||
RULES_FILE="${PRISM_DIR}/rules.json"
|
RULES_FILE="${PRISM_DIR}/rules.json"
|
||||||
|
|
||||||
mkdir -p "$ROUTERS_DIR"
|
mkdir -p "$ROUTERS_DIR"
|
||||||
|
|
||||||
# 1. Install routers (compile TS to JS via node --experimental-strip-types)
|
echo "Installing routers to PrismFacet..."
|
||||||
echo "Installing routers..."
|
for router_ts in "$INSTALL_DIR"/routers/*.ts; do
|
||||||
for router_ts in "$SCRIPT_DIR"/routers/*.ts; do
|
|
||||||
name=$(basename "$router_ts" .ts)
|
name=$(basename "$router_ts" .ts)
|
||||||
# Use node to strip types and output JS
|
# Strip TypeScript types for JS output
|
||||||
node --experimental-strip-types -e "
|
sed -E 's/: \{ agentId: string \}//g; s/: string//g' \
|
||||||
import { readFileSync, writeFileSync } from 'fs';
|
"$router_ts" > "${ROUTERS_DIR}/${name}.js"
|
||||||
const src = readFileSync('${router_ts}', 'utf8');
|
|
||||||
// Simple type stripping: remove type annotations
|
|
||||||
const js = src
|
|
||||||
.replace(/: \{ agentId: string \}/g, '')
|
|
||||||
.replace(/: string/g, '')
|
|
||||||
.replace(/import type .*/g, '');
|
|
||||||
writeFileSync('${ROUTERS_DIR}/${name}.js', js);
|
|
||||||
" 2>/dev/null || {
|
|
||||||
# Fallback: just copy and strip types manually with sed
|
|
||||||
sed -E 's/: \{ agentId: string \}//g; s/: string//g; s/import type .*//g' \
|
|
||||||
"$router_ts" > "${ROUTERS_DIR}/${name}.js"
|
|
||||||
}
|
|
||||||
echo " Installed router: $name"
|
echo " Installed router: $name"
|
||||||
done
|
done
|
||||||
|
|
||||||
# 2. Register rules
|
# 4. Register rules in PrismFacet
|
||||||
echo "Registering rules..."
|
echo "Registering rules..."
|
||||||
|
|
||||||
# Load existing rules
|
|
||||||
if [[ -f "$RULES_FILE" ]]; then
|
if [[ -f "$RULES_FILE" ]]; then
|
||||||
RULES=$(cat "$RULES_FILE")
|
RULES=$(cat "$RULES_FILE")
|
||||||
else
|
else
|
||||||
RULES="{}"
|
RULES="{}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Scan roles/ and register role:{name} → ROLE.md path
|
# Roles
|
||||||
for role_dir in "$SCRIPT_DIR"/roles/*/; do
|
for role_dir in "$INSTALL_DIR"/roles/*/; do
|
||||||
role_name=$(basename "$role_dir")
|
role_name=$(basename "$role_dir")
|
||||||
role_file="${role_dir}ROLE.md"
|
role_file="${role_dir}ROLE.md"
|
||||||
if [[ -f "$role_file" ]]; then
|
if [[ -f "$role_file" ]]; then
|
||||||
@@ -72,12 +81,12 @@ d = json.load(sys.stdin)
|
|||||||
d['role:${role_name}'] = '${role_file}'
|
d['role:${role_name}'] = '${role_file}'
|
||||||
print(json.dumps(d, indent=2))
|
print(json.dumps(d, indent=2))
|
||||||
")
|
")
|
||||||
echo " Registered rule: role:${role_name} → ${role_file}"
|
echo " rule: role:${role_name}"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
# Scan positions/ and register position:{name} → POSITION.md path
|
# Positions
|
||||||
for pos_dir in "$SCRIPT_DIR"/positions/*/; do
|
for pos_dir in "$INSTALL_DIR"/positions/*/; do
|
||||||
pos_name=$(basename "$pos_dir")
|
pos_name=$(basename "$pos_dir")
|
||||||
pos_file="${pos_dir}POSITION.md"
|
pos_file="${pos_dir}POSITION.md"
|
||||||
if [[ -f "$pos_file" ]]; then
|
if [[ -f "$pos_file" ]]; then
|
||||||
@@ -87,11 +96,10 @@ d = json.load(sys.stdin)
|
|||||||
d['position:${pos_name}'] = '${pos_file}'
|
d['position:${pos_name}'] = '${pos_file}'
|
||||||
print(json.dumps(d, indent=2))
|
print(json.dumps(d, indent=2))
|
||||||
")
|
")
|
||||||
echo " Registered rule: position:${pos_name} → ${pos_file}"
|
echo " rule: position:${pos_name}"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
# Write rules
|
|
||||||
echo "$RULES" > "$RULES_FILE"
|
echo "$RULES" > "$RULES_FILE"
|
||||||
|
|
||||||
echo "Done. Restart OpenClaw gateway to apply changes."
|
echo "Done. Restart OpenClaw gateway to apply changes."
|
||||||
|
|||||||
27
scripts/role-code-mapper
Executable file
27
scripts/role-code-mapper
Executable file
@@ -0,0 +1,27 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
ROLES_DIR="${HOME}/.openclaw/ClawRoles/roles"
|
||||||
|
|
||||||
|
if [[ $# -lt 1 ]]; then
|
||||||
|
echo "Usage: role-code-mapper <role>" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
ROLE="$1"
|
||||||
|
ROLE_FILE="${ROLES_DIR}/${ROLE}/ROLE.md"
|
||||||
|
|
||||||
|
if [[ ! -f "$ROLE_FILE" ]]; then
|
||||||
|
echo "Error: ROLE.md not found for role '${ROLE}'" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Extract role-code from YAML frontmatter
|
||||||
|
CODE=$(sed -n '/^---$/,/^---$/{ /^role-code:/{ s/^role-code:[[:space:]]*//; p; q; } }' "$ROLE_FILE")
|
||||||
|
|
||||||
|
if [[ -z "$CODE" ]]; then
|
||||||
|
echo "Error: role-code not found in ${ROLE_FILE}" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "$CODE"
|
||||||
Reference in New Issue
Block a user