#!/usr/bin/env bash
# `.agents/` is the vendor-neutral home for this project's rules, skills, and
# agent definitions — MiniMax, Gemini, and Codex all read plain files from it.
#
# Claude Code, however, discovers subagents and skills at fixed paths. This
# symlinks them so there is exactly ONE copy of every definition and no drift.
#
#   .agents/scripts/install-claude-agents.sh
set -euo pipefail

root="$(git rev-parse --show-toplevel)"
cd "$root"

mkdir -p .claude

for target in agents skills; do
  link=".claude/$target"
  if [ -e "$link" ] && [ ! -L "$link" ]; then
    echo "refusing: $link exists and is not a symlink — move it aside first" >&2
    exit 1
  fi
  ln -sfn "../.agents/$target" "$link"
  echo "linked $link -> .agents/$target"
done

echo
echo "Claude Code will now load:"
ls -1 .agents/agents/*.md | sed 's|.*/|  agent: |;s|\.md$||'
ls -1d .agents/skills/*/  | sed 's|.*/skills/|  skill: |;s|/$||'
