|
| 1 | +--- |
| 2 | +name: setup-caliber |
| 3 | +description: Sets up Caliber for automatic AI agent context sync. Installs pre-commit hooks so CLAUDE.md, Cursor rules, and Copilot instructions update automatically on every commit. Use when Caliber hooks are not yet installed or when the user asks about keeping agent configs in sync. |
| 4 | +--- |
| 5 | + |
| 6 | +# Setup Caliber |
| 7 | + |
| 8 | +Dynamic onboarding for Caliber — automatic AI agent context sync. |
| 9 | +Run all diagnostic steps below on every invocation to determine what's already |
| 10 | +set up and what still needs to be done. |
| 11 | + |
| 12 | +## Instructions |
| 13 | + |
| 14 | +Run these checks in order. For each step, check the current state first, |
| 15 | +then only act if something is missing. |
| 16 | + |
| 17 | +### Step 1: Check if Caliber is installed |
| 18 | + |
| 19 | +```bash |
| 20 | +command -v caliber >/dev/null 2>&1 && caliber --version || echo "NOT_INSTALLED" |
| 21 | +``` |
| 22 | + |
| 23 | +- If a version prints → Caliber is installed globally. Set `CALIBER="caliber"` and move to Step 2. |
| 24 | +- If NOT_INSTALLED → Install it globally (faster for daily use since the pre-commit hook runs on every commit): |
| 25 | + ```bash |
| 26 | + npm install -g @rely-ai/caliber |
| 27 | + ``` |
| 28 | + Set `CALIBER="caliber"`. |
| 29 | + |
| 30 | + If npm fails (permissions, no sudo, etc.), fall back to npx: |
| 31 | + ```bash |
| 32 | + npx @rely-ai/caliber --version 2>/dev/null || echo "NO_NODE" |
| 33 | + ``` |
| 34 | + - If npx works → Set `CALIBER="npx @rely-ai/caliber"`. This works but adds ~500ms per invocation. |
| 35 | + - If NO_NODE → Tell the user: "Caliber requires Node.js >= 20. Install Node first, then run /setup-caliber again." Stop here. |
| 36 | + |
| 37 | +### Step 2: Check if pre-commit hook is installed |
| 38 | + |
| 39 | +```bash |
| 40 | +grep -q "caliber" .git/hooks/pre-commit 2>/dev/null && echo "HOOK_ACTIVE" || echo "NO_HOOK" |
| 41 | +``` |
| 42 | + |
| 43 | +- If HOOK_ACTIVE → Tell the user: "Pre-commit hook is active — configs sync on every commit." Move to Step 3. |
| 44 | +- If NO_HOOK → Tell the user: "I'll install the pre-commit hook so your agent configs sync automatically on every commit." |
| 45 | + ```bash |
| 46 | + $CALIBER hooks --install |
| 47 | + ``` |
| 48 | + |
| 49 | +### Step 3: Detect agents and check if configs exist |
| 50 | + |
| 51 | +First, detect which coding agents are configured in this project: |
| 52 | +```bash |
| 53 | +AGENTS="" |
| 54 | +[ -d .claude ] && AGENTS="claude" |
| 55 | +[ -d .cursor ] && AGENTS="${AGENTS:+$AGENTS,}cursor" |
| 56 | +[ -d .agents ] || [ -f AGENTS.md ] && AGENTS="${AGENTS:+$AGENTS,}codex" |
| 57 | +[ -f .github/copilot-instructions.md ] && AGENTS="${AGENTS:+$AGENTS,}github-copilot" |
| 58 | +echo "DETECTED_AGENTS=${AGENTS:-none}" |
| 59 | +``` |
| 60 | + |
| 61 | +If no agents are detected, ask the user which coding agents they use (Claude Code, Cursor, Codex, GitHub Copilot). |
| 62 | +Build the agent list from their answer as a comma-separated string (e.g. "claude,cursor"). |
| 63 | + |
| 64 | +Then check if agent configs exist: |
| 65 | +```bash |
| 66 | +echo "CLAUDE_MD=$([ -f CLAUDE.md ] && echo exists || echo missing)" |
| 67 | +echo "CURSOR_RULES=$([ -d .cursor/rules ] && ls .cursor/rules/*.mdc 2>/dev/null | wc -l | tr -d ' ' || echo 0)" |
| 68 | +echo "AGENTS_MD=$([ -f AGENTS.md ] && echo exists || echo missing)" |
| 69 | +echo "COPILOT=$([ -f .github/copilot-instructions.md ] && echo exists || echo missing)" |
| 70 | +``` |
| 71 | + |
| 72 | +- If configs exist for the detected agents → Tell the user which configs are present. Move to Step 4. |
| 73 | +- If configs are missing → Tell the user: "No agent configs found. I'll generate them now." |
| 74 | + Use the detected or user-selected agent list: |
| 75 | + ```bash |
| 76 | + $CALIBER init --auto-approve --agent <comma-separated-agents> |
| 77 | + ``` |
| 78 | + For example: `$CALIBER init --auto-approve --agent claude,cursor` |
| 79 | + This generates CLAUDE.md, Cursor rules, AGENTS.md, skills, and sync infrastructure for the specified agents. |
| 80 | + |
| 81 | +### Step 4: Check if configs are fresh |
| 82 | + |
| 83 | +```bash |
| 84 | +$CALIBER score --json --quiet 2>/dev/null | head -1 |
| 85 | +``` |
| 86 | + |
| 87 | +- If score is 80+ → Tell the user: "Your configs are in good shape (score: X/100)." |
| 88 | +- If score is below 80 → Tell the user: "Your configs could be improved (score: X/100). Want me to run a refresh?" |
| 89 | + If yes: |
| 90 | + ```bash |
| 91 | + $CALIBER refresh |
| 92 | + ``` |
| 93 | + |
| 94 | +### Step 5: Ask about team setup |
| 95 | + |
| 96 | +Ask the user: "Are you setting up for yourself only, or for your team too?" |
| 97 | + |
| 98 | +- If **solo** → Continue with solo setup: |
| 99 | + |
| 100 | + Check if session learning is enabled: |
| 101 | + ```bash |
| 102 | + $CALIBER learn status 2>/dev/null | head -3 |
| 103 | + ``` |
| 104 | + - If learning is already enabled → note it in the summary. |
| 105 | + - If not enabled → ask the user: "Caliber can learn from your coding sessions — when you correct a mistake or fix a pattern, it remembers for next time. Enable session learning?" |
| 106 | + If yes: |
| 107 | + ```bash |
| 108 | + $CALIBER learn install |
| 109 | + ``` |
| 110 | + |
| 111 | + Then tell the user: |
| 112 | + "You're all set! Here's what happens next: |
| 113 | + - Every time you commit, Caliber syncs your agent configs automatically |
| 114 | + - Your CLAUDE.md, Cursor rules, and AGENTS.md stay current with your code |
| 115 | + - Run `$CALIBER skills` anytime to discover community skills for your stack" |
| 116 | + |
| 117 | + Then show the summary (see below) and stop. |
| 118 | + |
| 119 | +- If **team** → Check if the GitHub Action already exists: |
| 120 | + ```bash |
| 121 | + [ -f .github/workflows/caliber-sync.yml ] && echo "ACTION_EXISTS" || echo "NO_ACTION" |
| 122 | + ``` |
| 123 | + - If ACTION_EXISTS → Tell the user: "GitHub Action is already configured." |
| 124 | + - If NO_ACTION → Tell the user: "I'll create a GitHub Action that syncs configs nightly and on every PR." |
| 125 | + Write this file to `.github/workflows/caliber-sync.yml`: |
| 126 | + ```yaml |
| 127 | + name: Caliber Sync |
| 128 | + on: |
| 129 | + schedule: |
| 130 | + - cron: '0 3 * * 1-5' |
| 131 | + pull_request: |
| 132 | + types: [opened, synchronize] |
| 133 | + workflow_dispatch: |
| 134 | + jobs: |
| 135 | + sync: |
| 136 | + runs-on: ubuntu-latest |
| 137 | + steps: |
| 138 | + - uses: actions/checkout@v4 |
| 139 | + - uses: caliber-ai-org/ai-setup@v1 |
| 140 | + with: |
| 141 | + mode: sync |
| 142 | + auto-refresh: true |
| 143 | + comment: true |
| 144 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 145 | + env: |
| 146 | + ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }} |
| 147 | + ``` |
| 148 | + Now determine which LLM provider the team uses. Check the local Caliber config: |
| 149 | + ```bash |
| 150 | + $CALIBER config --show 2>/dev/null || echo "NO_CONFIG" |
| 151 | + ``` |
| 152 | + |
| 153 | + Based on the provider, the GitHub Action needs the corresponding secret: |
| 154 | + - **anthropic** → `ANTHROPIC_API_KEY` |
| 155 | + - **openai** → `OPENAI_API_KEY` |
| 156 | + - **vertex** → `VERTEX_PROJECT_ID` and `GOOGLE_APPLICATION_CREDENTIALS` (service account JSON) |
| 157 | + |
| 158 | + Update the workflow env block to match the provider. For example, if using OpenAI: |
| 159 | + ```yaml |
| 160 | + env: |
| 161 | + OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} |
| 162 | + ``` |
| 163 | + |
| 164 | + Then check if the `gh` CLI is available to set the secret: |
| 165 | + ```bash |
| 166 | + command -v gh >/dev/null 2>&1 && echo "GH_AVAILABLE" || echo "NO_GH" |
| 167 | + ``` |
| 168 | + |
| 169 | + - If GH_AVAILABLE → Ask the user for their API key and set it: |
| 170 | + ```bash |
| 171 | + gh secret set ANTHROPIC_API_KEY |
| 172 | + ``` |
| 173 | + (This prompts for the value securely via stdin) |
| 174 | + - If NO_GH → Tell the user exactly what to do: |
| 175 | + "Go to your repo on GitHub → Settings → Secrets and variables → Actions → New repository secret. |
| 176 | + Name: ANTHROPIC_API_KEY (or OPENAI_API_KEY depending on provider) |
| 177 | + Value: your API key" |
| 178 | + |
| 179 | + Finally, offer to commit and push the workflow file: |
| 180 | + ```bash |
| 181 | + git add .github/workflows/caliber-sync.yml |
| 182 | + git commit -m "feat: add Caliber sync GitHub Action" |
| 183 | + git push |
| 184 | + ``` |
| 185 | + |
| 186 | +### Summary |
| 187 | + |
| 188 | +After completing all steps, show the user what's configured: |
| 189 | +
|
| 190 | +``` |
| 191 | +Caliber Setup Complete: |
| 192 | +✓ Caliber installed (vX.X.X) |
| 193 | +✓ Pre-commit hook — configs sync on every commit |
| 194 | +✓ Agent configs — CLAUDE.md, Cursor rules, AGENTS.md |
| 195 | +✓ Config score: X/100 |
| 196 | +✓ GitHub Action — nightly sync + PR checks (team only) |
| 197 | +
|
| 198 | +From now on, every commit keeps all your agent configs in sync automatically. |
| 199 | +``` |
| 200 | +
|
| 201 | +## When to trigger |
| 202 | +
|
| 203 | +- When a developer first opens this project |
| 204 | +- When the user asks about keeping agent configs up to date |
| 205 | +- When the user asks "how do I set up Caliber" or "what is Caliber" |
| 206 | +- When the user sees a message saying "Run /setup-caliber to get set up" |
| 207 | +
|
| 208 | +## When NOT to trigger |
| 209 | +
|
| 210 | +- The user is in the middle of time-sensitive work |
0 commit comments