|
| 1 | +#!/usr/bin/env bash |
| 2 | +# |
| 3 | +# install-chat-skills.sh — package and install workbench-* plugin skills into |
| 4 | +# the Claude Mac app's Chat surface via .skill files. |
| 5 | +# |
| 6 | +# Discovers eligible skills in installed @claude-workbench plugins |
| 7 | +# (excluding workbench-core itself), packages each via the skill-creator's |
| 8 | +# package_skill.py, and opens each .skill file with the Mac app to trigger |
| 9 | +# the install dialog. Updates a state file so the SessionStart notice clears. |
| 10 | +# |
| 11 | +# Triggered by the /workbench-core:install-chat-skills slash command, OR |
| 12 | +# run directly: `bash scripts/install-chat-skills.sh` |
| 13 | +# |
| 14 | +# Exit codes: |
| 15 | +# 0 — success or nothing to do |
| 16 | +# 1 — pre-flight failure (jq missing, skill-creator missing, etc.) |
| 17 | + |
| 18 | +set -euo pipefail |
| 19 | + |
| 20 | +PLUGINS_FILE="$HOME/.claude/plugins/installed_plugins.json" |
| 21 | +STATE_FILE="$HOME/.claude-workbench/chat-skills-state.json" |
| 22 | +DIST_DIR="/tmp/workbench-chat-skills" |
| 23 | + |
| 24 | +# ──────────── Pre-flight ──────────── |
| 25 | + |
| 26 | +if [ ! -f "$PLUGINS_FILE" ]; then |
| 27 | + echo "❌ Plugin registry not found at $PLUGINS_FILE" |
| 28 | + exit 1 |
| 29 | +fi |
| 30 | + |
| 31 | +if ! command -v jq >/dev/null 2>&1; then |
| 32 | + echo "❌ jq not installed. Install via: brew install jq" |
| 33 | + exit 1 |
| 34 | +fi |
| 35 | + |
| 36 | +# Find skill-creator's package_skill.py — the install path layout differs |
| 37 | +# slightly between plugin versions, so check both common shapes. |
| 38 | +SKILL_CREATOR_PATH="" |
| 39 | +for candidate_path in $(jq -r ' |
| 40 | + .plugins | to_entries[] |
| 41 | + | select(.key | startswith("skill-creator@")) |
| 42 | + | .value[0].installPath // empty |
| 43 | +' "$PLUGINS_FILE" 2>/dev/null); do |
| 44 | + if [ -f "$candidate_path/skills/skill-creator/scripts/package_skill.py" ]; then |
| 45 | + SKILL_CREATOR_PATH="$candidate_path/skills/skill-creator" |
| 46 | + break |
| 47 | + elif [ -f "$candidate_path/scripts/package_skill.py" ]; then |
| 48 | + SKILL_CREATOR_PATH="$candidate_path" |
| 49 | + break |
| 50 | + fi |
| 51 | +done |
| 52 | + |
| 53 | +if [ -z "$SKILL_CREATOR_PATH" ]; then |
| 54 | + echo "❌ skill-creator plugin not found. Install it first:" |
| 55 | + echo " /plugin install skill-creator@claude-plugins-official" |
| 56 | + exit 1 |
| 57 | +fi |
| 58 | + |
| 59 | +# pyyaml is required by skill-creator's quick_validate.py. |
| 60 | +if ! python3 -c "import yaml" 2>/dev/null; then |
| 61 | + echo "📦 Installing pyyaml (required by skill-creator's validator)..." |
| 62 | + if ! pip3 install pyyaml --break-system-packages --quiet 2>&1; then |
| 63 | + echo "❌ Failed to install pyyaml. Install manually:" |
| 64 | + echo " pip3 install pyyaml --break-system-packages" |
| 65 | + exit 1 |
| 66 | + fi |
| 67 | +fi |
| 68 | + |
| 69 | +# ──────────── Discovery ──────────── |
| 70 | + |
| 71 | +echo "🔍 Scanning workbench plugins for installable skills..." |
| 72 | + |
| 73 | +SKILLS=() |
| 74 | +SKILL_NAMES=() |
| 75 | +PLUGIN_NAMES=() |
| 76 | +PLUGIN_VERSIONS=() |
| 77 | + |
| 78 | +while IFS=$'\t' read -r plugin_path plugin_version; do |
| 79 | + [ -z "$plugin_path" ] && continue |
| 80 | + [ ! -d "$plugin_path/skills" ] && continue |
| 81 | + |
| 82 | + # Plugin name = the directory two levels up from skills/ (cache layout: |
| 83 | + # cache/<marketplace>/<plugin_name>/<version>/skills/...). |
| 84 | + plugin_name="$(echo "$plugin_path" | awk -F/ '{print $(NF-1)}')" |
| 85 | + |
| 86 | + for skill_dir in "$plugin_path/skills"/*/; do |
| 87 | + skill_dir="${skill_dir%/}" |
| 88 | + [ ! -f "$skill_dir/SKILL.md" ] && continue |
| 89 | + |
| 90 | + # `name:` is required by the skill-creator validator. Skip with a notice |
| 91 | + # so the user knows why a skill they expected isn't being installed. |
| 92 | + if grep -q '^name:' "$skill_dir/SKILL.md" 2>/dev/null; then |
| 93 | + SKILLS+=("$skill_dir") |
| 94 | + SKILL_NAMES+=("$(basename "$skill_dir")") |
| 95 | + PLUGIN_NAMES+=("$plugin_name") |
| 96 | + PLUGIN_VERSIONS+=("$plugin_version") |
| 97 | + else |
| 98 | + echo "⚠️ Skipping $plugin_name/$(basename "$skill_dir") — missing 'name:' in frontmatter" |
| 99 | + fi |
| 100 | + done |
| 101 | +done < <(jq -r ' |
| 102 | + .plugins | to_entries[] |
| 103 | + | select(.key | endswith("@claude-workbench")) |
| 104 | + | select(.key | startswith("workbench-core@") | not) |
| 105 | + | .value[0] |
| 106 | + | "\(.installPath)\t\(.version)" |
| 107 | +' "$PLUGINS_FILE") |
| 108 | + |
| 109 | +if [ ${#SKILLS[@]} -eq 0 ]; then |
| 110 | + echo "ℹ️ No installable skills found in dependent plugins." |
| 111 | + # Clear the state file so the warmup notice clears too. |
| 112 | + mkdir -p "$(dirname "$STATE_FILE")" |
| 113 | + echo '{"installed": []}' > "$STATE_FILE" |
| 114 | + exit 0 |
| 115 | +fi |
| 116 | + |
| 117 | +# ──────────── Plan ──────────── |
| 118 | + |
| 119 | +echo "" |
| 120 | +echo "Found ${#SKILLS[@]} skill(s) to install into Claude Chat:" |
| 121 | +for i in "${!SKILLS[@]}"; do |
| 122 | + echo " • ${PLUGIN_NAMES[$i]} / ${SKILL_NAMES[$i]}" |
| 123 | +done |
| 124 | +echo "" |
| 125 | + |
| 126 | +# ──────────── Package and open ──────────── |
| 127 | + |
| 128 | +mkdir -p "$DIST_DIR" |
| 129 | +rm -f "$DIST_DIR"/*.skill |
| 130 | + |
| 131 | +INSTALLED_RECORDS=() |
| 132 | + |
| 133 | +for i in "${!SKILLS[@]}"; do |
| 134 | + skill_dir="${SKILLS[$i]}" |
| 135 | + name="${SKILL_NAMES[$i]}" |
| 136 | + plugin="${PLUGIN_NAMES[$i]}" |
| 137 | + version="${PLUGIN_VERSIONS[$i]}" |
| 138 | + |
| 139 | + echo "📦 Packaging $plugin / $name..." |
| 140 | + cd "$SKILL_CREATOR_PATH" |
| 141 | + if python3 -m scripts.package_skill "$skill_dir" "$DIST_DIR" 2>&1 | tail -3 | grep -q "✅"; then |
| 142 | + echo "🚀 Opening $name.skill — confirm install in the Mac app dialog..." |
| 143 | + open -a "Claude" "$DIST_DIR/$name.skill" 2>&1 || { |
| 144 | + echo "⚠️ Failed to open Claude.app for $name.skill — is the Mac app installed?" |
| 145 | + continue |
| 146 | + } |
| 147 | + INSTALLED_RECORDS+=("$plugin|$name|$version") |
| 148 | + sleep 1.5 # let dialog appear before queueing next |
| 149 | + else |
| 150 | + echo "❌ Packaging failed for $name. Skipping." |
| 151 | + fi |
| 152 | +done |
| 153 | + |
| 154 | +# ──────────── State file update ──────────── |
| 155 | + |
| 156 | +mkdir -p "$(dirname "$STATE_FILE")" |
| 157 | + |
| 158 | +# Build state JSON via jq for safe escaping. |
| 159 | +state_json='{"installed":[]}' |
| 160 | +for record in "${INSTALLED_RECORDS[@]}"; do |
| 161 | + IFS='|' read -r plugin skill version <<< "$record" |
| 162 | + state_json=$(echo "$state_json" | jq \ |
| 163 | + --arg plugin "$plugin" \ |
| 164 | + --arg skill "$skill" \ |
| 165 | + --arg version "$version" \ |
| 166 | + '.installed += [{plugin: $plugin, skill: $skill, version: $version}]') |
| 167 | +done |
| 168 | +echo "$state_json" > "$STATE_FILE" |
| 169 | + |
| 170 | +echo "" |
| 171 | +echo "✅ Done. Verify in Claude Chat that the skills appear." |
| 172 | +echo " State recorded at: $STATE_FILE" |
0 commit comments