install-claude.sh 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. #!/usr/bin/env bash
  2. #
  3. # install-claude.sh
  4. # Installs OpenAgents Control to Claude Code with automatic conversion
  5. #
  6. set -euo pipefail
  7. # Colors
  8. GREEN='\033[0;32m'
  9. YELLOW='\033[1;33m'
  10. RED='\033[0;31m'
  11. NC='\033[0m' # No Color
  12. # Determine paths
  13. SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
  14. REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
  15. OPENCODE_DIR="$REPO_ROOT/.opencode/agent"
  16. CONVERTER_DIR="$SCRIPT_DIR/converter"
  17. PLUGIN_DEST="$HOME/.claude/plugins/openagents-control-bridge"
  18. NODE_BIN="${NODE_BIN:-node}"
  19. echo -e "${GREEN}🚀 OpenAgents Control → Claude Code Installer${NC}"
  20. echo -e " Source: $OPENCODE_DIR"
  21. echo -e " Destination: $PLUGIN_DEST"
  22. echo ""
  23. # Check prerequisites
  24. check_prereqs() {
  25. local missing=()
  26. # Check for node
  27. if ! command -v "$NODE_BIN" >/dev/null 2>&1; then
  28. missing+=("$NODE_BIN")
  29. fi
  30. # Check for bash
  31. if ! command -v bash >/dev/null 2>&1; then
  32. missing+=("bash")
  33. fi
  34. if [ ${#missing[@]} -gt 0 ]; then
  35. echo -e "${RED}✗ Missing required commands: ${missing[*]}${NC}" >&2
  36. echo -e " Install Node.js: https://nodejs.org/" >&2
  37. exit 1
  38. fi
  39. }
  40. # Run converter
  41. run_converter() {
  42. echo -e "${YELLOW}🔄 Converting agents to Claude format...${NC}"
  43. cd "$CONVERTER_DIR"
  44. if ! "$NODE_BIN" src/convert-agents.js 2>&1 | grep -q "Conversion complete"; then
  45. echo -e "${RED}✗ Conversion failed${NC}" >&2
  46. exit 1
  47. fi
  48. echo -e "${GREEN}✅ Conversion complete${NC}"
  49. }
  50. # Install plugin
  51. install_plugin() {
  52. echo -e "${YELLOW}📦 Installing plugin...${NC}"
  53. # Create destination
  54. mkdir -p "$HOME/.claude/plugins"
  55. # Remove old installation
  56. if [ -d "$PLUGIN_DEST" ]; then
  57. echo "🗑️ Removing old installation..."
  58. rm -rf "$PLUGIN_DEST"
  59. fi
  60. # Copy from generated (always fresh conversion)
  61. cp -r "$CONVERTER_DIR/generated" "$PLUGIN_DEST"
  62. echo -e "${GREEN}✅ Installation complete${NC}"
  63. }
  64. # Verify installation
  65. verify() {
  66. if [ ! -f "$PLUGIN_DEST/agents/core/openagent.md" ]; then
  67. echo -e "${RED}✗ Installation verification failed${NC}" >&2
  68. echo " Expected: $PLUGIN_DEST/agents/core/openagent.md" >&2
  69. exit 1
  70. fi
  71. echo ""
  72. echo -e "${GREEN}✨ Installation successful!${NC}"
  73. echo ""
  74. echo "To use with Claude Code:"
  75. echo " claude --plugin-dir $PLUGIN_DEST"
  76. echo ""
  77. echo "Or add to your Claude Code settings for automatic loading:"
  78. echo ' { "plugins": ["openagents-control-bridge"] }'
  79. echo ""
  80. echo "Verify Claude Code installation:"
  81. echo " claude --version"
  82. }
  83. # Main workflow
  84. main() {
  85. check_prereqs
  86. run_converter
  87. install_plugin
  88. verify
  89. }
  90. # Allow specifying custom Node.js binary via NODE_BIN environment variable
  91. main "$@"