cxpak 0.10.0

Spends CPU cycles so you don't spend tokens. The LLM gets a briefing packet instead of a flashlight in a dark room.
Documentation
#!/usr/bin/env bash
set -euo pipefail

INSTALL_DIR="${CXPAK_INSTALL_DIR:-${HOME}/.claude/plugins/cxpak/bin}"
GITHUB_REPO="Barnett-Studios/cxpak"
REQUIRED_VERSION="0.10.0"
DRY_RUN=false

for arg in "$@"; do
    case "$arg" in
        --dry-run) DRY_RUN=true ;;
    esac
done

# Helper: check if installed version matches required
version_ok() {
    local bin="$1"
    local installed
    installed="$("$bin" --version 2>/dev/null | awk '{print $2}')" || return 1
    [ "$installed" = "$REQUIRED_VERSION" ]
}

# 1. Check PATH
if command -v cxpak >/dev/null 2>&1; then
    CXPAK_PATH="$(command -v cxpak)"
    if version_ok "$CXPAK_PATH"; then
        if [ "$DRY_RUN" = false ]; then
            echo "$CXPAK_PATH"
        else
            echo "found on PATH: $CXPAK_PATH (v${REQUIRED_VERSION})"
        fi
        exit 0
    fi
    echo "cxpak on PATH is outdated (need v${REQUIRED_VERSION}), upgrading..." >&2
fi

# 2. Check cached install
if [ -x "${INSTALL_DIR}/cxpak" ]; then
    if version_ok "${INSTALL_DIR}/cxpak"; then
        if [ "$DRY_RUN" = false ]; then
            echo "${INSTALL_DIR}/cxpak"
        else
            echo "found cached: ${INSTALL_DIR}/cxpak (v${REQUIRED_VERSION})"
        fi
        exit 0
    fi
    echo "cached cxpak is outdated (need v${REQUIRED_VERSION}), upgrading..." >&2
fi

# 3. Detect platform
OS="$(uname -s)"
ARCH="$(uname -m)"

case "${OS}" in
    Darwin)
        case "${ARCH}" in
            arm64)  TARGET="aarch64-apple-darwin" ;;
            x86_64) TARGET="x86_64-apple-darwin" ;;
            *) echo "Unsupported architecture: ${ARCH}" >&2; exit 1 ;;
        esac
        ;;
    Linux)
        case "${ARCH}" in
            aarch64) TARGET="aarch64-unknown-linux-gnu" ;;
            x86_64)  TARGET="x86_64-unknown-linux-gnu" ;;
            *) echo "Unsupported architecture: ${ARCH}" >&2; exit 1 ;;
        esac
        ;;
    *)
        echo "Unsupported OS: ${OS}" >&2
        exit 1
        ;;
esac

TARBALL="cxpak-${TARGET}.tar.gz"

# Dry run: just print what would be downloaded
if [ "$DRY_RUN" = true ]; then
    echo "would download: ${TARBALL} for ${TARGET}"
    exit 0
fi

# 4. Download latest release
echo "Downloading cxpak v${REQUIRED_VERSION}..." >&2

LATEST_URL="https://github.com/${GITHUB_REPO}/releases/download/v${REQUIRED_VERSION}/${TARBALL}"

mkdir -p "${INSTALL_DIR}"
TMP_DIR="$(mktemp -d)"
trap 'rm -rf "${TMP_DIR}"' EXIT

curl -fsSL "${LATEST_URL}" -o "${TMP_DIR}/${TARBALL}" 2>&1 >&2
tar -xzf "${TMP_DIR}/${TARBALL}" -C "${TMP_DIR}" 2>&1 >&2
cp "${TMP_DIR}/cxpak" "${INSTALL_DIR}/cxpak"
chmod +x "${INSTALL_DIR}/cxpak"

echo "Downloaded cxpak to ${INSTALL_DIR}/cxpak" >&2
echo "${INSTALL_DIR}/cxpak"