#!/bin/sh # Sync agent skills with .chezmoidata/skills.yaml through the Skills CLI: # install every skill in the one declared source, then remove every # CLI-installed skill that came from anywhere else. # skills hash: {{ .skills | toJson | sha256sum }} set -u command -v npx >/dev/null 2>&1 || { echo "warning: npx not found — skipping skills sync" >&2; exit 0; } command -v jq >/dev/null 2>&1 || { echo "warning: jq not found — skipping skills sync" >&2; exit 0; } src={{ .chezmoi.sourceDir | quote }} source={{ .skills.source | quote }} agents={{ .skills.agents | join " " | quote }} lock=${XDG_STATE_HOME:-$HOME/.local/state}/skills/.skill-lock.json skills() { npx -y {{ .skills.cli | quote }} "$@" &2 exit 1 fi # The lock records each skill's source as owner/repo, also for tree URLs. repo=$(printf '%s\n' "$source" | sed -E 's#^https://github\.com/##; s#(\.git)?(/tree/.*)?/?$##') stale=$(jq -r --arg repo "$repo" \ '.skills // {} | to_entries[] | select(.value.source != $repo) | .key' "$lock" 2>/dev/null) if [ -n "$stale" ]; then echo "skills: removing" $stale # shellcheck disable=SC2086 # one word per skill name skills remove -g -y $stale || { echo "error: skills remove failed" >&2; exit 1; } fi