#!/usr/bin/env bash # # convert.sh — 将智能体 .md 文件转换为各工具专用格式(中文版适配) # # 读取所有智能体目录中的 .md 文件,输出到 integrations//。 # 添加或修改智能体后运行此脚本重新生成集成文件。 # # 用法: # ./scripts/convert.sh [--tool ] [--out ] [--help] # # 支持的工具: # antigravity — Antigravity skill 文件 (~/.gemini/antigravity/skills/) # gemini-cli — Gemini CLI 扩展 (skills/ + gemini-extension.json) # opencode — OpenCode agent 文件 (.opencode/agent/*.md) # cursor — Cursor rule 文件 (.cursor/rules/*.mdc) # trae — Trae rule 文件 (.trae/rules/*.md) # aider — 单文件 CONVENTIONS.md for Aider # windsurf — 单文件 .windsurfrules for Windsurf # openclaw — OpenClaw SOUL.md 文件 (openclaw_workspace//SOUL.md) # qwen — Qwen Code SubAgent 文件 (~/.qwen/agents/*.md) # codex — OpenAI Codex CLI agent 文件 (.codex/agents/*.toml) # deerflow — DeerFlow 2.0 custom skill 文件 (skills/custom//SKILL.md) # workbuddy — WorkBuddy skill 文件 (~/.workbuddy/skills//SKILL.md) # hermes — Hermes Agent skill 文件 (~/.hermes/skills///SKILL.md) # kiro — Kiro agent .md 文件 (.kiro/agents/*.md,带 YAML frontmatter) # qoder — Qoder 自定义智能体文件 (.qoder/agents/*.md) # all — 所有工具(默认) # # 输出到仓库根目录下的 integrations//。 # 此脚本不会修改用户配置目录 — 参见 install.sh。 set -euo pipefail # --- 颜色辅助 --- if [[ -t 1 ]]; then GREEN=$'\033[0;32m'; YELLOW=$'\033[1;33m'; RED=$'\033[0;31m'; BOLD=$'\033[1m'; RESET=$'\033[0m' else GREEN=''; YELLOW=''; RED=''; BOLD=''; RESET='' fi info() { printf "${GREEN}[OK]${RESET} %s\n" "$*"; } warn() { printf "${YELLOW}[!!]${RESET} %s\n" "$*"; } error() { printf "${RED}[ERR]${RESET} %s\n" "$*" >&2; } header() { echo -e "\n${BOLD}$*${RESET}"; } # --- 路径 --- SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)" OUT_DIR="$REPO_ROOT/integrations" TODAY="$(date +%Y-%m-%d)" AGENT_DIRS=( academic design engineering finance game-development hr legal marketing paid-media sales product project-management supply-chain testing support spatial-computing specialized ) # --- 用法 --- usage() { sed -n '3,27p' "$0" | sed 's/^# \{0,1\}//' exit 0 } # --- Frontmatter 辅助函数 --- # 从 YAML frontmatter 中提取单个字段值 get_field() { local field="$1" file="$2" awk -v f="$field" ' /^---$/ { fm++; next } fm == 1 && $0 ~ "^" f ": " { sub("^" f ": ", ""); print; exit } ' "$file" } # 去除 frontmatter,返回正文部分 get_body() { awk 'BEGIN{fm=0} /^---$/{fm++; next} fm>=2{print}' "$1" } # 从文件名生成 slug(适配中文:直接用文件名而非中文 name 字段) # "marketing-douyin-strategist.md" → "marketing-douyin-strategist" slugify_from_file() { basename "$1" .md } # --- 颜色映射 --- resolve_opencode_color() { local c="$1" case "$c" in cyan) echo "#00FFFF" ;; blue) echo "#3498DB" ;; green) echo "#2ECC71" ;; red) echo "#E74C3C" ;; purple) echo "#9B59B6" ;; orange) echo "#F39C12" ;; teal) echo "#008080" ;; indigo) echo "#6366F1" ;; pink) echo "#E84393" ;; gold) echo "#EAB308" ;; amber) echo "#F59E0B" ;; neon-green) echo "#10B981" ;; neon-cyan) echo "#06B6D4" ;; metallic-blue) echo "#3B82F6" ;; yellow) echo "#EAB308" ;; violet) echo "#8B5CF6" ;; rose) echo "#F43F5E" ;; lime) echo "#84CC16" ;; gray) echo "#6B7280" ;; fuchsia) echo "#D946EF" ;; *) echo "$c" ;; esac } # --- 各工具转换器 --- convert_antigravity() { local file="$1" local name description slug outdir outfile body name="$(get_field "name" "$file")" description="$(get_field "description" "$file")" slug="agency-$(slugify_from_file "$file")" body="$(get_body "$file")" outdir="$OUT_DIR/antigravity/$slug" outfile="$outdir/SKILL.md" mkdir -p "$outdir" cat > "$outfile" < "$outfile" < "$outfile" < "$outfile" < "$outfile" < "$outdir/SOUL.md" < "$outdir/AGENTS.md" < "$outdir/IDENTITY.md" < "$outfile" < "$outfile" < "$outfile" < "$outfile" < "$outfile" < "$outfile" < "$outfile" <.md # 参考:https://kiro.dev/docs/chat/subagents/ cat > "$OUT_DIR/kiro/${slug}.md" < "$AIDER_TMP" <<'HEREDOC' # AI 智能体专家团队 — Aider 约定文件 # # 本文件为 Aider 提供完整的 AI 智能体专家阵容。 # 来源:https://github.com/jnMetaCode/agency-agents-zh # # 激活方式:在 Aider 会话中引用智能体名称,例如: # "使用前端开发者智能体帮我审查这个组件" # # 由 scripts/convert.sh 生成 — 请勿手动编辑。 HEREDOC cat > "$WINDSURF_TMP" <<'HEREDOC' # AI 智能体专家团队 — Windsurf 规则文件 # # 完整的 AI 智能体专家阵容。 # 激活方式:在 Windsurf 对话中引用智能体名称。 # # 由 scripts/convert.sh 生成 — 请勿手动编辑。 HEREDOC accumulate_aider() { local file="$1" local name description body name="$(get_field "name" "$file")" description="$(get_field "description" "$file")" body="$(get_body "$file")" cat >> "$AIDER_TMP" < ${description} ${body} HEREDOC } accumulate_windsurf() { local file="$1" local name description body name="$(get_field "name" "$file")" description="$(get_field "description" "$file")" body="$(get_body "$file")" cat >> "$WINDSURF_TMP" < "$OUT_DIR/gemini-cli/gemini-extension.json" <<'HEREDOC' { "name": "agency-agents-zh", "version": "1.0.0" } HEREDOC info "已写入 gemini-extension.json" fi info "已转换 $count 个智能体 ($t)" done if [[ "$tool" == "all" || "$tool" == "aider" ]]; then mkdir -p "$OUT_DIR/aider" cp "$AIDER_TMP" "$OUT_DIR/aider/CONVENTIONS.md" info "已写入 integrations/aider/CONVENTIONS.md" fi if [[ "$tool" == "all" || "$tool" == "windsurf" ]]; then mkdir -p "$OUT_DIR/windsurf" cp "$WINDSURF_TMP" "$OUT_DIR/windsurf/.windsurfrules" info "已写入 integrations/windsurf/.windsurfrules" fi echo "" info "完成。共转换: $total" } main "$@"