#!/bin/sh # LogicPacks installer (macOS, Linux). No sudo, no account. # curl -fsSL https://logicpacks.io/install | sh install the logicpacks CLI # curl -fsSL https://logicpacks.io/install | sh -s -- github.com/owner/repo ...and start working on a repo with AI # (Same file as https://logicpacks.io/lp.sh and https://logicpacks.io/start.) # # Install: # 1. finds Python 3.9+ (on a Mac it only uses /usr/bin/python3 when the Command Line Tools are # installed, so it never pops the "install developer tools" dialog); if none is found it installs # uv into ~/.logicpacks/uv and a private Python 3.12 into ~/.logicpacks/python # 2. downloads lp.pyz named in the release manifest, checks its SHA-256 # 3. installs ~/.logicpacks/bin/lp.pyz and the wrapper ~/.logicpacks/bin/lp (also `logicpacks`), and the # `cryptography` library (pyca, the vetted crypto lp uses) for that Python into ~/.logicpacks/lib/py3X # 4. puts ~/.logicpacks/bin FIRST on PATH in your shell rc files (macOS and Linux ship a printer # command /usr/bin/lp; this keeps `lp` pointing at LogicPacks) # Start (with a repo, or --start to pick a starter). It lists what it will add and asks once, before anything: # 5. an AI agent: uses Claude Code, Codex, Cursor or OpenCode if one is installed. With none, it installs # OpenCode (open source, https://opencode.ai, into ~/.opencode/bin) and uses OpenCode's free model: # no account, no API key # 6. connects LogicPacks to that agent: `logicpacks mcp install --apply` (backs up its config) # 7. `logicpacks add github.com/owner/repo --clone`: clones the repo into this folder, wired to run on # local mocks, so it runs without anyone's API keys # 8. opens the agent in the repo with a starter prompt # Re-running it upgrades in place and skips what is there. # Options: -y (no questions), --start, --agent opencode|claude|codex|cursor, --model provider/model (OpenCode), # --run (one non-interactive agent run that prints its answer, for CI). Environment: LP_MANIFEST= # (release manifest), LP_PYTHON=, LP_NO_MODIFY_PATH=1 (do not edit shell rc files) # Undo: logicpacks uninstall (removes lp, its PATH line and its MCP entries; keeps your vault unless --purge) # OpenCode, if this installed it: rm -rf ~/.opencode ~/.config/opencode ~/.local/share/opencode # A cloned repo is a normal folder: delete it when you are done. set -eu SITE="${LOGICPACKS_SITE:-https://logicpacks.io}" FREE_MODEL="opencode/big-pickle" # OpenCode Zen's free model (no account, no key); more: `opencode models opencode` REPO="" START="" YES="${LOGICPACKS_YES:-}" AGENT="${LOGICPACKS_AGENT:-}" MODEL="${LOGICPACKS_MODEL:-}" RUN="${LOGICPACKS_RUN:-}" while [ $# -gt 0 ]; do case "$1" in -y|--yes) YES=1 ;; --run) RUN=1 ;; --start) START=1 ;; --agent) AGENT="${2:-}"; shift ;; --model) MODEL="${2:-}"; shift ;; -h|--help) echo "Usage: curl -fsSL $SITE/install | sh [-s -- github.com/owner/repo] (details: $SITE/start)"; exit 0 ;; -*) printf 'unknown option %s\n' "$1" >&2; exit 2 ;; *) REPO="$1"; START=1 ;; esac shift done tty_ok() { (exec /dev/null; } ask() { # ask "question" -> REPLY, from the terminal (works under curl | sh) REPLY=""; [ -n "$YES" ] && return 0 tty_ok || { printf 'logicpacks: no terminal to ask on. Rerun with -y: curl -fsSL %s/install | sh -s -- -y %s\n' "$SITE" "$REPO" >&2; exit 1; } printf '%s ' "$1" >/dev/tty; read -r REPLY /dev/null 2>&1; } export PATH="$HOME/.logicpacks/bin:$HOME/.opencode/bin:$PATH" # ---------------------------------------------------------------- start: pick the repo, the agent, and ask once pick_repo() { [ -n "$REPO" ] && return 0 STARTERS="$(curl -fsSL --max-time 10 "$SITE/templates.txt" 2>/dev/null | grep -E '^github\.com/' | head -20 || true)" if [ -n "$STARTERS" ] && [ -z "$YES" ]; then echo "Starters ($SITE/templates):"; echo "$STARTERS" | awk '{n++; printf " %d) %s\n", n, $0}' ask "Pick a number, or paste a GitHub repo:" case "$REPLY" in ''|*[!0-9]*) REPO="$REPLY" ;; *) REPO="$(echo "$STARTERS" | sed -n "${REPLY}p" | awk '{print $1}')" ;; esac else ask "Paste a GitHub repo (owner/repo), or press Enter to start an empty project:"; REPO="$REPLY" fi } plan_start() { # $1 = 1 when lp itself is still to be installed [ "$(id -u)" = 0 ] && { echo "logicpacks: do not run the start flow as root; run it as your normal user (nothing needs sudo)." >&2; exit 1; } have git || { echo "logicpacks: git is required (macOS: xcode-select --install; Debian/Ubuntu/WSL: sudo apt-get install -y git)." >&2; exit 1; } pick_repo SLUG="$(printf '%s' "$REPO" | sed -E 's#^(https?://)?(www\.)?(github\.com|logicpacks\.io)/##; s#\.git$##; s#/+$##' | cut -d/ -f1-2)" if [ -n "$SLUG" ]; then printf '%s' "$SLUG" | grep -Eq '^[A-Za-z0-9][A-Za-z0-9-]*/[A-Za-z0-9._-]+$' || { echo "logicpacks: not a GitHub repo: $REPO (use owner/repo)" >&2; exit 1; } DIR="$PWD/${SLUG#*/}" else DIR="$PWD/my-app"; fi if [ -z "$AGENT" ]; then if have claude; then AGENT=claude; elif have codex; then AGENT=codex elif have cursor-agent; then AGENT=cursor; elif have opencode; then AGENT=opencode; fi fi case "$AGENT" in ''|opencode|claude|codex|cursor) ;; *) echo "logicpacks: --agent must be opencode, claude, codex or cursor" >&2; exit 1 ;; esac NEED="" [ "$1" = 1 ] && NEED="$NEED\n - the logicpacks CLI into ~/.logicpacks (its own Python too, if this computer has none)" if [ -z "$AGENT" ] || { [ "$AGENT" = opencode ] && ! have opencode; }; then have bash || { echo "logicpacks: no AI agent found, and OpenCode's installer needs bash (Alpine: apk add bash)." >&2; exit 1; } AGENT=opencode; NEED="$NEED\n - OpenCode (open source AI agent, opencode.ai) into ~/.opencode/bin, with its free model (no account, no key)" fi NEED="$NEED\n - the LogicPacks MCP server in $AGENT's config (a backup is kept)" [ -n "$SLUG" ] && NEED="$NEED\n - clone github.com/$SLUG into $DIR, set to run on local mocks" printf '\033[1mLogicPacks will:\033[0m'; printf '%b\n' "$NEED\n - then open $AGENT in that folder with a starter prompt" echo "Undo any time: logicpacks uninstall (details: $SITE/start)" ask "Continue? [y/N]" [ -n "$YES" ] || case "$REPLY" in y|Y|yes|YES) ;; *) echo "Nothing installed."; exit 1 ;; esac } [ -n "$START" ] && plan_start 1 # ---------------------------------------------------------------- install lp LP_DIR="$HOME/.logicpacks" BIN="$LP_DIR/bin" say() { printf '%s\n' "$*"; } fail() { printf 'lp install: %s\n' "$*" >&2; exit 1; } command -v curl >/dev/null 2>&1 || fail "curl is required." OS="$(uname -s)" # ---------------------------------------------------------------- Python 3.9+ py_ok() { [ -n "$1" ] && [ -x "$1" ] && "$1" -c 'import sys; sys.exit(0 if sys.version_info >= (3, 9) else 1)' >/dev/null 2>&1; } find_python() { if [ -n "${LP_PYTHON:-}" ] && py_ok "$LP_PYTHON"; then echo "$LP_PYTHON"; return 0; fi # our own private Python from an earlier run for p in "$LP_DIR"/python/cpython-3*/bin/python3; do py_ok "$p" && { echo "$p"; return 0; }; done for p in /opt/homebrew/bin/python3 /usr/local/bin/python3; do py_ok "$p" && { echo "$p"; return 0; }; done if [ "$OS" = "Darwin" ]; then # /usr/bin/python3 is a stub until the Command Line Tools are installed: running it opens a dialog. if xcode-select -p >/dev/null 2>&1 && py_ok /usr/bin/python3; then echo /usr/bin/python3; return 0; fi else for p in $(command -v python3 2>/dev/null) /usr/bin/python3; do py_ok "$p" && { echo "$p"; return 0; }; done fi return 1 } PY="$(find_python || true)" if [ -z "$PY" ]; then say "No Python 3.9+ found: installing a private Python 3.12 for lp in $LP_DIR/python (uv, no sudo)..." mkdir -p "$LP_DIR/uv" curl -fsSL https://astral.sh/uv/install.sh | env UV_INSTALL_DIR="$LP_DIR/uv" INSTALLER_NO_MODIFY_PATH=1 UV_NO_MODIFY_PATH=1 sh >/dev/null \ || fail "could not install uv (https://astral.sh/uv). Install Python 3.9+ yourself and run this again." UV_PYTHON_INSTALL_DIR="$LP_DIR/python" UV_PYTHON_INSTALL_BIN=0 "$LP_DIR/uv/uv" python install 3.12 >/dev/null \ || fail "uv could not install Python 3.12." PY="$(UV_PYTHON_INSTALL_DIR="$LP_DIR/python" "$LP_DIR/uv/uv" python find --managed-python 3.12 2>/dev/null || true)" py_ok "$PY" || fail "Python 3.12 was installed but could not be found." fi say "Python: $PY ($("$PY" -c 'import platform; print(platform.python_version())'))" # ---------------------------------------------------------------- lp.pyz WORK="$(mktemp -d)" trap 'rm -rf "$WORK"' EXIT MAN="" for u in ${LP_MANIFEST:-} https://downloads.logicpacks.io/lp/latest.json https://logicpacks.io/lp/latest.json; do if curl -fsSL --max-time 20 "$u" -o "$WORK/latest.json" 2>/dev/null && grep -q '"sha256"' "$WORK/latest.json"; then MAN="$u"; break; fi done [ -n "$MAN" ] || fail "could not download the lp release manifest (tried ${LP_MANIFEST:-} downloads.logicpacks.io, logicpacks.io)." field() { "$PY" -c 'import json,sys; print(json.load(open(sys.argv[1]))[sys.argv[2]])' "$WORK/latest.json" "$1"; } VERSION="$(field version)"; URL="$(field url)"; SHA="$(field sha256)" say "Downloading lp $VERSION ($URL)..." curl -fsSL "$URL" -o "$WORK/lp.pyz" || fail "download failed: $URL" GOT="$("$PY" -c 'import hashlib,sys; print(hashlib.sha256(open(sys.argv[1],"rb").read()).hexdigest())' "$WORK/lp.pyz")" [ "$GOT" = "$SHA" ] || fail "checksum mismatch (expected $SHA, got $GOT). Nothing was installed." say "Checksum OK." mkdir -p "$BIN" mv -f "$WORK/lp.pyz" "$BIN/lp.pyz" cat > "$BIN/lp.new" <> "$rc"; say "Added ~/.logicpacks/bin to PATH in $rc"; fi done fi "$BIN/lp" --version >/dev/null 2>&1 || fail "lp was installed but does not run: $BIN/lp --version" # the vetted crypto library lp uses (pyca/cryptography), once per Python, into ~/.logicpacks/lib/py3X if PYTHONPATH="$BIN/lp.pyz" "$PY" -c 'import lp.deps' 2>/dev/null; then # lp 1.0.22+; older releases need no extra library CRYPTO="$(PYTHONPATH="$BIN/lp.pyz" "$PY" -m lp.deps)" || fail "could not install the 'cryptography' library for $PY (see above)." say "Crypto library: $CRYPTO" fi say "Installed $("$BIN/lp" --version) at $BIN/lp (also as $BIN/logicpacks)" say "Open a new shell (or run: export PATH=\"\$HOME/.logicpacks/bin:\$PATH\") so \`lp\` is LogicPacks, not the printer command." # ---------------------------------------------------------------- start: agent, MCP, repo on mocks, prompt if [ -z "$START" ] && [ -z "$YES" ] && [ -t 1 ] && tty_ok; then # a person at a terminal (agents never get asked) printf 'Start working on a GitHub repo with an AI agent now? Paste owner/repo (Enter to finish): ' >/dev/tty read -r REPO /dev/null 2>&1 || fail "OpenCode install failed (https://opencode.ai)." fi case "$AGENT" in claude) AB=claude ;; codex) AB=codex ;; cursor) AB=cursor-agent ;; *) AB=opencode ;; esac have "$AB" || fail "$AB is not on PATH." if [ "$AGENT" = opencode ] && [ -z "$MODEL" ]; then # your own OpenCode model if you set one up; otherwise the free one, checked to answer today if [ -s "$HOME/.local/share/opencode/auth.json" ] || grep -qs '"model"' "$HOME/.config/opencode/opencode.json"; then :; else for m in "$FREE_MODEL" $(opencode models opencode 2>/dev/null | grep -- '-free$' || true); do if opencode run -m "$m" "Reply with the single word OK" /dev/null | grep -q OK; then MODEL="$m"; break; fi done if [ -n "$MODEL" ]; then say "Model: $MODEL (OpenCode's free model: no account, no key; prompts go to OpenCode Zen)" else say "OpenCode's free models are busy right now. Bring your own key instead (Anthropic, OpenAI, OpenRouter, ...)." ask "Add a key now with 'opencode auth login'? [y/N]" case "$REPLY" in y|Y|yes) opencode auth login /dev/null 2>&1 && DONE=1 || DONE="" ;; codex) grep -qs '^\[mcp_servers\.logicpacks\]' "$HOME/.codex/config.toml" && DONE=1 || DONE="" ;; cursor) grep -qs '"logicpacks"' "$HOME/.cursor/mcp.json" && DONE=1 || DONE="" ;; *) grep -qs '"logicpacks"' "$HOME/.config/opencode/opencode.json" && DONE=1 || DONE="" ;; esac if [ -n "$DONE" ]; then say "LogicPacks is already connected to $AGENT."; else "$LP" mcp install "$AGENT" --apply; fi if [ -n "$SLUG" ]; then say "Getting github.com/$SLUG..." "$LP" add "github.com/$SLUG" --clone --dir "$DIR" PROMPT="Use logicpacks.io: read this pack, run the app on mocks, explain what it does, and ask me what I want to build or change. (The pack is LOGICPACKS.md in this folder; run commands with ./lp-run.sh.)" else mkdir -p "$DIR" PROMPT="Use logicpacks.io: ask me what I want to build, suggest a starter from $SITE/templates if one fits, then set it up here and run it." fi cd "$DIR" say "Opening $AGENT in $DIR"; say "Prompt: $PROMPT" if [ -n "$RUN" ]; then # one non-interactive run (CI, tests): tools allowed for this run only case "$AGENT" in opencode) OPENCODE_CONFIG_CONTENT='{"permission":{"bash":"allow","edit":"allow","webfetch":"allow","external_directory":"allow","read":"allow"}}' \ exec opencode run ${MODEL:+-m "$MODEL"} "$PROMPT"