#!/usr/bin/env bash
# Optional: symlink each skills/*/SKILL.md package into ~/.claude/skills and ~/.cursor/skills.
# Does NOT link brain/ (not a SKILL bundle).

set -euo pipefail

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PACK_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
SKILLS="$PACK_ROOT/skills"
DEST_CLAUDE="${HOME}/.claude/skills"
DEST_CURSOR="${HOME}/.cursor/skills"

if [[ ! -d "$SKILLS" ]]; then
  echo "error: expected skills repo at: $SKILLS" >&2
  exit 1
fi

mkdir -p "$DEST_CLAUDE" "$DEST_CURSOR"

count=0
for dir in "$SKILLS"/*/; do
  [[ -f "${dir}SKILL.md" ]] || continue
  name="$(basename "$dir")"
  target="$(cd "$dir" && pwd -P)"
  ln -sfn "$target" "$DEST_CLAUDE/$name"
  ln -sfn "$target" "$DEST_CURSOR/$name"
  echo "linked: $name"
  count=$((count + 1))
done

echo ""
echo "Linked $count skill folders."
echo "Open this repo root as workspace for @skills/... and @brain/... paths."
