#!/usr/bin/env bash # 黑手党提案 Agent — 一键安装脚本 # 用法: bash install.sh set -euo pipefail GREEN='\033[0;32m' YELLOW='\033[0;33m' RED='\033[0;31m' NC='\033[0m' info() { printf "${GREEN}[mafia]${NC} %s\n" "$*"; } warn() { printf "${YELLOW}[mafia]${NC} %s\n" "$*"; } error() { printf "${RED}[mafia]${NC} %s\n" "$*" >&2; exit 1; } COPAW_HOME="${COPAW_HOME:-$HOME/.copaw}" AGENT_ID="mafia-expert" WORKSPACE_DIR="$COPAW_HOME/workspaces/$AGENT_ID" SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" REPO_DIR="$(cd "$SCRIPT_DIR/.." && pwd)" # ── 检查 CoPaw 是否已安装 ────────────────────────────────────────────── if ! command -v copaw &>/dev/null && [ ! -f "$COPAW_HOME/bin/copaw" ]; then info "CoPaw 未安装,正在安装..." curl -fsSL https://raw.githubusercontent.com/agentscope-ai/CoPaw/main/scripts/install.sh | bash export PATH="$COPAW_HOME/bin:$PATH" info "正在初始化 CoPaw..." copaw init --defaults --accept-security else info "CoPaw 已安装" export PATH="$COPAW_HOME/bin:$PATH" fi # ── 检查 CoPaw 是否已初始化 ──────────────────────────────────────────── if [ ! -f "$COPAW_HOME/config.json" ]; then info "正在初始化 CoPaw..." copaw init --defaults --accept-security fi # ── 创建 mafia-expert 工作区 ─────────────────────────────────────────── info "创建 $AGENT_ID 工作区..." mkdir -p "$WORKSPACE_DIR/active_skills" mkdir -p "$WORKSPACE_DIR/cases" mkdir -p "$WORKSPACE_DIR/iteration_reports" mkdir -p "$WORKSPACE_DIR/memory" # 复制 Agent 配置文件 cp "$SCRIPT_DIR/AGENTS.md" "$WORKSPACE_DIR/AGENTS.md" cp "$SCRIPT_DIR/SOUL.md" "$WORKSPACE_DIR/SOUL.md" cp "$SCRIPT_DIR/PROFILE.md" "$WORKSPACE_DIR/PROFILE.md" cp "$SCRIPT_DIR/HEARTBEAT.md" "$WORKSPACE_DIR/HEARTBEAT.md" cp "$SCRIPT_DIR/MEMORY.md" "$WORKSPACE_DIR/MEMORY.md" cp "$SCRIPT_DIR/agent.json" "$WORKSPACE_DIR/agent.json" cp "$SCRIPT_DIR/skill.json" "$WORKSPACE_DIR/skill.json" # 复制 Skills cp -r "$SCRIPT_DIR/skills/"* "$WORKSPACE_DIR/active_skills/" info "文件复制完成" # ── 注册到 config.json ───────────────────────────────────────────────── info "注册 $AGENT_ID 到 CoPaw..." python3 -c " import json, os config_path = os.path.expanduser('$COPAW_HOME/config.json') with open(config_path, 'r') as f: cfg = json.load(f) agent_id = '$AGENT_ID' ws_dir = '$WORKSPACE_DIR' if agent_id not in cfg['agents']['profiles']: cfg['agents']['profiles'][agent_id] = { 'id': agent_id, 'workspace_dir': ws_dir, 'enabled': True } if agent_id not in cfg['agents']['agent_order']: cfg['agents']['agent_order'].append(agent_id) with open(config_path, 'w') as f: json.dump(cfg, f, indent=2, ensure_ascii=False) print(' ✅ 注册成功') else: print(' ✅ 已注册,跳过') " # ── 记录仓库路径(用于 Heartbeat git pull)───────────────────────────── echo "$REPO_DIR" > "$WORKSPACE_DIR/.repo_path" info "仓库路径已记录: $REPO_DIR" # ── 完成 ─────────────────────────────────────────────────────────────── echo "" info "════════════════════════════════════════════════" info " 黑手党提案专家 安装完成!" info "════════════════════════════════════════════════" echo "" info "启动方式:" info " copaw app # 打开控制台" info " 然后在左上角切换到 '黑手党提案专家'" echo "" info "更新方式:" info " cd $REPO_DIR && git pull" info " bash agent/install.sh # 重新安装" echo ""