#!/usr/bin/env bash
# Generated by @teanis/repo-config. !! DO NOT MODIFY THIS FILE !!

set -euo pipefail

# A new project has no skills yet; `npx skills add <source>` creates skills-lock.json.
if [[ ! -f skills-lock.json ]]; then
  printf 'No skills-lock.json: no skills to install.\n'
  exit 0
fi

npx --yes skills@1.7.0 experimental_install

mkdir -p ./.claude/skills

# Parsed as JSON, so it does not depend on how skills-lock.json is indented. Kept on one line:
# node shims on Windows (Volta) drop a multi-line -e/-p argument.
skill_names=$(node -p 'Object.keys(JSON.parse(require("node:fs").readFileSync("skills-lock.json", "utf8")).skills ?? {}).join("\n")')

while read -r skill_name; do
  skill=".agents/skills/$skill_name"

  if [[ -z "$skill_name" || ! -d "$skill" ]]; then
    continue
  fi

  rm -rf "./.claude/skills/$skill_name"
  cp -R "$skill" "./.claude/skills/$skill_name"
done <<< "$skill_names"
