NLDClient-yudde/.ai/sync-all.sh

108 lines
3.5 KiB
Bash
Raw Normal View History

2026-05-08 13:25:20 +08:00
#!/bin/bash
# sync-all.sh — 将 .ai/ 下的 skills、protocols、agents 同步到各平台目录
# 新增或更新后运行此脚本即可同步到全部平台
2026-05-14 19:37:04 +08:00
# 用法: bash .ai/sync-all.sh
2026-05-08 13:25:20 +08:00
set -e
PLATFORMS=(".cursor" ".claude" ".github" ".kiro")
# ── 1. Sync skills ──────────────────────────────────────────────
SKILLS_SRC=".ai/skills"
echo "=== Syncing skills from $SKILLS_SRC ==="
skill_count=0
for skill_dir in "$SKILLS_SRC"/*/; do
[ -d "$skill_dir" ] || continue
skill=$(basename "$skill_dir")
skill_md="$skill_dir/SKILL.md"
[ -f "$skill_md" ] || continue
for platform in "${PLATFORMS[@]}"; do
target_dir="$platform/skills/$skill"
mkdir -p "$target_dir"
cp "$skill_md" "$target_dir/SKILL.md"
done
echo " ✓ skill: $skill"
((skill_count++))
done
# ── 2. Sync protocols ──────────────────────────────────────────
PROTOCOLS_SRC=".ai/protocols"
echo ""
echo "=== Syncing protocols from $PROTOCOLS_SRC ==="
proto_count=0
if [ -d "$PROTOCOLS_SRC" ]; then
for proto_file in "$PROTOCOLS_SRC"/*.md; do
[ -f "$proto_file" ] || continue
filename=$(basename "$proto_file")
for platform in "${PLATFORMS[@]}"; do
target_dir="$platform/protocols"
mkdir -p "$target_dir"
cp "$proto_file" "$target_dir/$filename"
done
echo " ✓ protocol: $filename"
((proto_count++))
done
fi
# ── 3. Sync agents ─────────────────────────────────────────────
# .ai/agents/*.md → 各平台 agents/ 目录(跳过 .githubCopilot 兼容 Claude agents
2026-05-08 13:25:20 +08:00
AGENTS_SRC=".ai/agents"
echo ""
echo "=== Syncing agents from $AGENTS_SRC ==="
agent_count=0
# 排除 .githubCopilot 直接使用 .claude/agents/
AGENT_PLATFORMS=(".cursor" ".claude" ".kiro")
2026-05-08 13:25:20 +08:00
if [ -d "$AGENTS_SRC" ]; then
for agent_file in "$AGENTS_SRC"/*.md; do
[ -f "$agent_file" ] || continue
2026-05-14 19:37:04 +08:00
base_name=$(basename "$agent_file" .md)
2026-05-08 13:25:20 +08:00
for platform in "${AGENT_PLATFORMS[@]}"; do
2026-05-08 13:25:20 +08:00
target_dir="$platform/agents"
mkdir -p "$target_dir"
cp "$agent_file" "$target_dir/${base_name}.md"
2026-05-08 13:25:20 +08:00
done
2026-05-14 19:37:04 +08:00
echo " ✓ agent: $base_name"
2026-05-08 13:25:20 +08:00
((agent_count++))
done
fi
# ── 4. Sync hooks ──────────────────────────────────────────────
HOOKS_SRC=".ai/hooks"
echo ""
echo "=== Syncing hooks from $HOOKS_SRC ==="
hook_count=0
if [ -d "$HOOKS_SRC" ]; then
for hook_file in "$HOOKS_SRC"/*.md; do
[ -f "$hook_file" ] || continue
filename=$(basename "$hook_file")
for platform in "${PLATFORMS[@]}"; do
target_dir="$platform/hooks"
mkdir -p "$target_dir"
cp "$hook_file" "$target_dir/$filename"
done
echo " ✓ hook: $filename"
((hook_count++))
done
fi
2026-05-08 13:25:20 +08:00
# ── Summary ─────────────────────────────────────────────────────
echo ""
echo "Done. Synced to ${#PLATFORMS[@]} platforms:"
echo " Skills: $skill_count"
echo " Protocols: $proto_count"
echo " Agents: $agent_count"
echo " Hooks: $hook_count"