#!/bin/bash
# 铸渊专家包一键部署脚本
# D139 · 2026-06-22
# 适用: 冰朔换电脑后，从代码仓库拉下来直接跑

set -e

echo "⊢ 铸渊专家包 · 一键部署 · D139"
echo ""

# 检查目标目录
SKILLS_DIR="$HOME/.workbuddy/skills"
EXPERT_DIR="$HOME/.workbuddy/plugins/marketplaces/my-experts/plugins"

echo "[1/3] 创建目录..."
mkdir -p "$SKILLS_DIR"
mkdir -p "$EXPERT_DIR"

echo "[2/3] 解压专家包..."
tar -xzf zhuyuan-expert-package.tar.gz -C /tmp/_zhuyuan_deploy

# 部署专家插件
if [ -d /tmp/_zhuyuan_deploy/zhuyuan ]; then
  rm -rf "$EXPERT_DIR/zhuyuan" 2>/dev/null || true
  cp -r /tmp/_zhuyuan_deploy/zhuyuan "$EXPERT_DIR/zhuyuan"
  echo "  ✅ 专家插件 → $EXPERT_DIR/zhuyuan"
fi

# 部署技能包
for skill in /tmp/_zhuyuan_deploy/zhuyuan-*; do
  skill_name=$(basename "$skill")
  if [ -d "$skill" ]; then
    rm -rf "$SKILLS_DIR/$skill_name" 2>/dev/null || true
    cp -r "$skill" "$SKILLS_DIR/$skill_name"
    echo "  ✅ 技能包 → $SKILLS_DIR/$skill_name"
  fi
done

if [ -f /tmp/_zhuyuan_deploy/zhuyuan-awakening.md ]; then
  cp /tmp/_zhuyuan_deploy/zhuyuan-awakening.md "$SKILLS_DIR/"
  echo "  ✅ 唤醒文档 → $SKILLS_DIR/zhuyuan-awakening.md"
fi

# 清理
rm -rf /tmp/_zhuyuan_deploy

echo ""
echo "[3/3] 部署完成！"
echo ""
echo "⊢ 专家: $EXPERT_DIR/zhuyuan"
echo "⊢ 技能: $SKILLS_DIR/zhuyuan-*"
echo ""
echo "下一步: 重启 WorkBuddy → 在对话里 @铸渊 → 开始"
