init: ClawRoles — role/position definitions for PrismFacet
6 role definitions (developer, manager, operator, mentor, secretary, agent-resource-director) and 6 position definitions. Routers: role.ts and position.ts read ego.json for agent mapping. install.sh: copies routers to PrismFacet, scans roles/ and positions/ directories, registers rules in PrismFacet's rules.json. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
97
install.sh
Executable file
97
install.sh
Executable file
@@ -0,0 +1,97 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
# ClawRoles installer
|
||||
# Installs routers and registers rules into PrismFacet.
|
||||
#
|
||||
# Usage: ./install.sh [--prism-dir <path>]
|
||||
# --prism-dir: PrismFacet plugin directory (default: ~/.openclaw/plugins/prism-facet)
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
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
|
||||
|
||||
if [[ ! -d "$PRISM_DIR" ]]; then
|
||||
echo "Error: PrismFacet not found at $PRISM_DIR"
|
||||
echo "Install PrismFacet first, or specify --prism-dir"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
ROUTERS_DIR="${PRISM_DIR}/routers"
|
||||
RULES_FILE="${PRISM_DIR}/rules.json"
|
||||
|
||||
mkdir -p "$ROUTERS_DIR"
|
||||
|
||||
# 1. Install routers (compile TS to JS via node --experimental-strip-types)
|
||||
echo "Installing routers..."
|
||||
for router_ts in "$SCRIPT_DIR"/routers/*.ts; do
|
||||
name=$(basename "$router_ts" .ts)
|
||||
# Use node to strip types and output JS
|
||||
node --experimental-strip-types -e "
|
||||
import { readFileSync, writeFileSync } from 'fs';
|
||||
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"
|
||||
done
|
||||
|
||||
# 2. Register rules
|
||||
echo "Registering rules..."
|
||||
|
||||
# Load existing rules
|
||||
if [[ -f "$RULES_FILE" ]]; then
|
||||
RULES=$(cat "$RULES_FILE")
|
||||
else
|
||||
RULES="{}"
|
||||
fi
|
||||
|
||||
# Scan roles/ and register role:{name} → ROLE.md path
|
||||
for role_dir in "$SCRIPT_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 " Registered rule: role:${role_name} → ${role_file}"
|
||||
fi
|
||||
done
|
||||
|
||||
# Scan positions/ and register position:{name} → POSITION.md path
|
||||
for pos_dir in "$SCRIPT_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 " Registered rule: position:${pos_name} → ${pos_file}"
|
||||
fi
|
||||
done
|
||||
|
||||
# Write rules
|
||||
echo "$RULES" > "$RULES_FILE"
|
||||
|
||||
echo "Done. Restart OpenClaw gateway to apply changes."
|
||||
Reference in New Issue
Block a user