#!/bin/bash set -euo pipefail # sync_skills.sh — Install/sync IPA Workflow skills from source repos # Usage: ./scripts/sync_skills.sh [--global|--workspace] [--source ] SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" REPO_ROOT="$(dirname "$SCRIPT_DIR")" GLOBAL_DIR="$HOME/.gemini/antigravity/skills" WORKSPACE_DIR=".agent/skills" INSTALL_MODE="global" SOURCE_FILTER="" usage() { echo "Usage: $0 [--global|--workspace] [--source ]" echo "" echo "Options:" echo " --global Install to $GLOBAL_DIR (default)" echo " --workspace Install to $WORKSPACE_DIR (relative to cwd)" echo " --source Only sync skills from named source in skills_sources.json" echo "" exit 1 } while [[ $# -gt 0 ]]; do case "$1" in --global) INSTALL_MODE="global"; shift ;; --workspace) INSTALL_MODE="workspace"; shift ;; --source) SOURCE_FILTER="$2"; shift 2 ;; -h|--help) usage ;; *) echo "Unknown option: $1"; usage ;; esac done if [[ "$INSTALL_MODE" == "global" ]]; then DEST="$GLOBAL_DIR" else DEST="$WORKSPACE_DIR" fi echo "==> Installing skills to: $DEST" mkdir -p "$DEST" # 1. Copy local skills from this repo if [[ -d "$REPO_ROOT/skills" ]]; then echo "==> Syncing local skills..." if command -v rsync &>/dev/null; then rsync -av --exclude='.gitkeep' "$REPO_ROOT/skills/" "$DEST/" else cp -r "$REPO_ROOT/skills/"* "$DEST/" 2>/dev/null || true fi echo "==> Local skills synced." fi # 2. Copy project templates if --workspace if [[ "$INSTALL_MODE" == "workspace" && -d "$REPO_ROOT/templates" ]]; then echo "==> Copying project templates..." if [[ -d "$REPO_ROOT/templates/docs" ]]; then mkdir -p "./docs" for tmpl in "$REPO_ROOT/templates/docs/"*.template; do [[ -f "$tmpl" ]] || continue base="$(basename "$tmpl" .template)" if [[ ! -f "./docs/$base" ]]; then cp "$tmpl" "./docs/$base" echo " Created docs/$base" else echo " Skipped docs/$base (already exists)" fi done fi fi # 3. Sync external sources from skills_sources.json SOURCES_FILE="$REPO_ROOT/skills_sources.json" if [[ -f "$SOURCES_FILE" ]]; then ENTRIES=$(python3 -c " import json, sys with open('$SOURCES_FILE') as f: sources = json.load(f) for s in sources: if '$SOURCE_FILTER' and s.get('name') != '$SOURCE_FILTER': continue print(f\"{s['name']}|{s['url']}|{s.get('path', 'skills')}\") " 2>/dev/null || true) if [[ -n "$ENTRIES" ]]; then while IFS='|' read -r name url path; do echo "==> Syncing external source: $name ($url)" TMP_DIR="/tmp/ag-sync-$name" rm -rf "$TMP_DIR" git clone --depth 1 "$url" "$TMP_DIR" 2>/dev/null if [[ -d "$TMP_DIR/$path" ]]; then if command -v rsync &>/dev/null; then rsync -av --exclude='.gitkeep' "$TMP_DIR/$path/" "$DEST/" else cp -r "$TMP_DIR/$path/"* "$DEST/" 2>/dev/null || true fi fi rm -rf "$TMP_DIR" echo "==> Source '$name' synced." done <<< "$ENTRIES" fi fi echo "==> Done. Skills installed to: $DEST"