#!/bin/bash
# install-paliadin-skill — copy the Paliadin skill into the local Claude
# Code config so the long-lived `claude` pane on this host picks it up.
#
# Run on every host that hosts a Paliadin tmux session — that means:
#   - mRiver (m's laptop, the prod target reached via SSH from paliad.de)
#   - any laptop running paliad's LocalPaliadinService directly
#
# The skill at ~/.claude/skills/paliadin/SKILL.md is what teaches Claude
# to react to `[PALIADIN:<uuid>]` envelopes by writing the response to
# /tmp/paliadin/<uuid>.txt. It survives /clear and fresh sessions because
# Claude's skill router auto-matches by description, not by an in-memory
# system prompt.
#
# Idempotent — re-running after a repo update is the supported way to
# refresh the skill on a host.

set -euo pipefail

src_dir="$(cd "$(dirname "$0")/skills/paliadin" && pwd)"
dst_dir="${CLAUDE_SKILLS_DIR:-$HOME/.claude/skills}/paliadin"

if [[ ! -f "$src_dir/SKILL.md" ]]; then
  echo "install-paliadin-skill: missing $src_dir/SKILL.md" >&2
  exit 1
fi

mkdir -p "$dst_dir"
# Mirror the entire skill tree (SKILL.md + references/), and clear out
# any stale auxiliary files left from a previous shape.
rm -rf "$dst_dir/references"
cp "$src_dir/SKILL.md" "$dst_dir/SKILL.md"
if [[ -d "$src_dir/references" ]]; then
  cp -R "$src_dir/references" "$dst_dir/references"
fi
echo "installed: $dst_dir/"
find "$dst_dir" -type f -printf '  %P\n'
