#!/usr/bin/env bash # Install agents (and their skills) from common-skills into a target project. # # Usage: # bash scripts/install-agents.sh # install all agents to ./.kiro/agents # bash scripts/install-agents.sh sdlc commit-message # install specific agents # TARGET_DIR=/path/to/project bash scripts/install-agents.sh # bash scripts/install-agents.sh --target /path/to/dir [agents...] # # Environment: # COMMON_SKILLS_DIR source repo path (default: ~/common-skills) # TARGET_DIR install destination (default: ./.kiro/agents) set -euo pipefail COMMON_SKILLS_DIR="${COMMON_SKILLS_DIR:-$HOME/common-skills}" TARGET_DIR="${TARGET_DIR:-.kiro/agents}" # Parse --target flag if [[ "${1:-}" == "--target" ]]; then TARGET_DIR="$2" shift 2 fi AGENTS_SRC="$COMMON_SKILLS_DIR/.kiro/agents" SKILLS_SRC="$COMMON_SKILLS_DIR/skills" SKILLS_DST="$(dirname "$TARGET_DIR")/skills" if [[ ! -d "$AGENTS_SRC" ]]; then echo "❌ common-skills not found at $COMMON_SKILLS_DIR" echo " Clone it first: git clone ~/common-skills" exit 1 fi # Pull latest git -C "$COMMON_SKILLS_DIR" pull --ff-only 2>/dev/null || true mkdir -p "$TARGET_DIR" mkdir -p "$SKILLS_DST" # Determine which agents to install if [[ $# -gt 0 ]]; then agents=("$@") else agents=($(ls "$AGENTS_SRC" | sed 's/\.json$//')) fi installed_skills=() for agent in "${agents[@]}"; do src="$AGENTS_SRC/${agent}.json" if [[ ! -f "$src" ]]; then echo "⚠️ Agent not found: $agent" continue fi cp "$src" "$TARGET_DIR/${agent}.json" echo "✅ Agent installed: $agent" # Copy prompt file if referenced via file://prompts/ prompt_file=$(grep -oP '(?<=file://prompts/)[^"]+' "$src" || true) if [[ -n "$prompt_file" && -f "$AGENTS_SRC/prompts/$prompt_file" ]]; then mkdir -p "$TARGET_DIR/prompts" cp "$AGENTS_SRC/prompts/$prompt_file" "$TARGET_DIR/prompts/$prompt_file" echo " ↳ Prompt copied: prompts/$prompt_file" fi # Extract skill names from resources: supports file://.kiro/skills//... and skill://.kiro/skills//... skill_refs=$(grep -oP '(?:file|skill)://\.kiro/skills/\K[^/"]+' "$src" | sort -u || true) for skill in $skill_refs; do if [[ "$skill" == "**" ]]; then # wildcard — install all skills for skill_dir in "$SKILLS_SRC"/*/; do skill_name=$(basename "$skill_dir") rm -rf "$SKILLS_DST/$skill_name" cp -r "$skill_dir" "$SKILLS_DST/$skill_name" installed_skills+=("$skill_name") done elif [[ -d "$SKILLS_SRC/$skill" ]]; then rm -rf "$SKILLS_DST/$skill" cp -r "$SKILLS_SRC/$skill" "$SKILLS_DST/$skill" installed_skills+=("$skill") fi done done # Deduplicate and report skills if [[ ${#installed_skills[@]} -gt 0 ]]; then unique_skills=($(printf '%s\n' "${installed_skills[@]}" | sort -u)) for s in "${unique_skills[@]}"; do echo " ↳ Skill synced: $s" done fi echo "" echo "Done." echo " Agents → $TARGET_DIR/" echo " Skills → $SKILLS_DST/"