|
| 1 | +set -euo pipefail |
| 2 | + |
| 3 | +VERSION="1.0.0" |
| 4 | +REPO_URL="${ARROWCODE_REPO:-https://github.com/Chintanpatel24/arrowcode.git}" |
| 5 | +INSTALL_DIR="${ARROWCODE_DIR:-$HOME/.local/share/arrowcode}" |
| 6 | +BIN_DIR="${ARROWCODE_BIN:-$HOME/.local/bin}" |
| 7 | +DO_LINK=1 |
| 8 | +DO_SETUP=0 |
| 9 | +BRANCH="${ARROWCODE_BRANCH:-main}" |
| 10 | + |
| 11 | +RED=$'\033[0;31m' |
| 12 | +GRN=$'\033[0;32m' |
| 13 | +CYN=$'\033[0;36m' |
| 14 | +DIM=$'\033[2m' |
| 15 | +RST=$'\033[0m' |
| 16 | +BLD=$'\033[1m' |
| 17 | + |
| 18 | +banner() { |
| 19 | + cat <<'EOF' |
| 20 | +
|
| 21 | + █████╗ ██████╗ ██████╗ ██████╗ ██╗ ██╗ ██████╗ ██████╗ ██████╗ ███████╗ |
| 22 | + ██╔══██╗██╔══██╗██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔═══██╗██╔══██╗██╔════╝ |
| 23 | + ███████║██████╔╝██████╔╝██║ ██║██║ █╗ ██║██║ ██║ ██║██║ ██║█████╗ |
| 24 | + ██╔══██║██╔══██╗██╔══██╗██║ ██║██║███╗██║██║ ██║ ██║██║ ██║██╔══╝ |
| 25 | + ██║ ██║██║ ██║██║ ██║╚██████╔╝╚███╔███╔╝╚██████╗╚██████╔╝██████╔╝███████╗ |
| 26 | + ╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═╝ ╚═════╝ ╚══╝╚══╝ ╚═════╝ ╚═════╝ ╚═════╝ ╚══════╝ |
| 27 | +
|
| 28 | + multi-agent swarm coding harness · plan → confirm → ship |
| 29 | +
|
| 30 | +EOF |
| 31 | +} |
| 32 | + |
| 33 | +log() { printf '%s==>%s %s\n' "$CYN" "$RST" "$*"; } |
| 34 | +ok() { printf '%s[ok]%s %s\n' "$GRN" "$RST" "$*"; } |
| 35 | +err() { printf '%s[err]%s %s\n' "$RED" "$RST" "$*" >&2; } |
| 36 | +die() { err "$*"; exit 1; } |
| 37 | + |
| 38 | +usage() { |
| 39 | + cat <<EOF |
| 40 | +ArrowCode installer v${VERSION} |
| 41 | +
|
| 42 | +Usage: install.sh [options] |
| 43 | +
|
| 44 | +Options: |
| 45 | + --dir <path> Install directory (default: ${INSTALL_DIR}) |
| 46 | + --bin <path> Bin directory for symlink (default: ${BIN_DIR}) |
| 47 | + --repo <url> Git clone URL |
| 48 | + --branch <name> Git branch (default: main) |
| 49 | + --no-link Do not create ~/.local/bin/arrowcode symlink |
| 50 | + --setup Run interactive API setup after install |
| 51 | + --help Show this help |
| 52 | +
|
| 53 | +Environment: |
| 54 | + ARROWCODE_DIR, ARROWCODE_BIN, ARROWCODE_REPO, ARROWCODE_BRANCH |
| 55 | +EOF |
| 56 | +} |
| 57 | + |
| 58 | +while [[ $# -gt 0 ]]; do |
| 59 | + case "$1" in |
| 60 | + --dir) INSTALL_DIR="$2"; shift 2 ;; |
| 61 | + --bin) BIN_DIR="$2"; shift 2 ;; |
| 62 | + --repo) REPO_URL="$2"; shift 2 ;; |
| 63 | + --branch) BRANCH="$2"; shift 2 ;; |
| 64 | + --no-link) DO_LINK=0; shift ;; |
| 65 | + --setup) DO_SETUP=1; shift ;; |
| 66 | + --help|-h) usage; exit 0 ;; |
| 67 | + *) die "Unknown option: $1" ;; |
| 68 | + esac |
| 69 | +done |
| 70 | + |
| 71 | +banner |
| 72 | +log "ArrowCode installer v${VERSION}" |
| 73 | + |
| 74 | +# --- Bun --- |
| 75 | +if ! command -v bun >/dev/null 2>&1; then |
| 76 | + log "Bun not found — installing from https://bun.sh" |
| 77 | + curl -fsSL https://bun.sh/install | bash |
| 78 | + export BUN_INSTALL="${BUN_INSTALL:-$HOME/.bun}" |
| 79 | + export PATH="$BUN_INSTALL/bin:$PATH" |
| 80 | + command -v bun >/dev/null 2>&1 || die "Bun install failed. Install manually: https://bun.sh" |
| 81 | +fi |
| 82 | +ok "Bun $(bun --version)" |
| 83 | + |
| 84 | +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" |
| 85 | + |
| 86 | +# Prefer in-place install when running from a full checkout |
| 87 | +if [[ -z "${ARROWCODE_DIR:-}" && -f "$SCRIPT_DIR/package.json" && -f "$SCRIPT_DIR/src/index.ts" ]]; then |
| 88 | + INSTALL_DIR="$SCRIPT_DIR" |
| 89 | + log "Detected local repo — installing in-place: $INSTALL_DIR" |
| 90 | +fi |
| 91 | + |
| 92 | +# --- Clone or update --- |
| 93 | +if [[ -d "$INSTALL_DIR/.git" ]]; then |
| 94 | + log "Updating existing install at $INSTALL_DIR" |
| 95 | + git -C "$INSTALL_DIR" fetch --depth 1 origin "$BRANCH" 2>/dev/null || true |
| 96 | + git -C "$INSTALL_DIR" checkout "$BRANCH" 2>/dev/null || true |
| 97 | + git -C "$INSTALL_DIR" pull --ff-only origin "$BRANCH" 2>/dev/null || \ |
| 98 | + log "git pull skipped (local changes or offline)" |
| 99 | +elif [[ -f "$INSTALL_DIR/package.json" && -f "$INSTALL_DIR/src/index.ts" ]]; then |
| 100 | + log "Using existing directory $INSTALL_DIR" |
| 101 | +else |
| 102 | + log "Cloning $REPO_URL → $INSTALL_DIR" |
| 103 | + mkdir -p "$(dirname "$INSTALL_DIR")" |
| 104 | + if command -v git >/dev/null 2>&1 && git clone --depth 1 --branch "$BRANCH" "$REPO_URL" "$INSTALL_DIR" 2>/dev/null; then |
| 105 | + ok "Cloned repository" |
| 106 | + elif [[ -f "$SCRIPT_DIR/package.json" ]]; then |
| 107 | + log "Clone unavailable — copying local repo from $SCRIPT_DIR" |
| 108 | + mkdir -p "$INSTALL_DIR" |
| 109 | + if command -v rsync >/dev/null 2>&1; then |
| 110 | + rsync -a --exclude node_modules --exclude .git "$SCRIPT_DIR/" "$INSTALL_DIR/" |
| 111 | + else |
| 112 | + cp -R "$SCRIPT_DIR"/. "$INSTALL_DIR"/ |
| 113 | + rm -rf "$INSTALL_DIR/node_modules" 2>/dev/null || true |
| 114 | + fi |
| 115 | + else |
| 116 | + die "git clone failed and no local package.json found. Clone the repo and run ./install.sh" |
| 117 | + fi |
| 118 | +fi |
| 119 | + |
| 120 | +cd "$INSTALL_DIR" |
| 121 | +log "Installing dependencies (bun install)" |
| 122 | +bun install |
| 123 | +ok "Dependencies installed" |
| 124 | + |
| 125 | +chmod +x "$INSTALL_DIR/bin/arrowcode" 2>/dev/null || true |
| 126 | +chmod +x "$INSTALL_DIR/install.sh" 2>/dev/null || true |
| 127 | + |
| 128 | +# Materialize ~/.arrowcode from packaged defaults/ (only creates missing files) |
| 129 | +log "Bootstrapping user home from defaults/ → ~/.arrowcode" |
| 130 | +bun run src/index.ts --init |
| 131 | +ok "User data ready at ~/.arrowcode (created only if missing)" |
| 132 | + |
| 133 | +# Symlink |
| 134 | +if [[ "$DO_LINK" -eq 1 ]]; then |
| 135 | + mkdir -p "$BIN_DIR" |
| 136 | + ln -sfn "$INSTALL_DIR/bin/arrowcode" "$BIN_DIR/arrowcode" |
| 137 | + ln -sfn "$INSTALL_DIR/bin/arrowcode" "$BIN_DIR/ac" |
| 138 | + ok "Linked $BIN_DIR/arrowcode and $BIN_DIR/ac" |
| 139 | + case ":$PATH:" in |
| 140 | + *":$BIN_DIR:"*) ;; |
| 141 | + *) |
| 142 | + log "Add to your shell profile:" |
| 143 | + echo " export PATH=\"$BIN_DIR:\$PATH\"" |
| 144 | + # try append for common shells if interactive-ish |
| 145 | + for rc in "$HOME/.bashrc" "$HOME/.zshrc"; do |
| 146 | + if [[ -f "$rc" ]] && ! grep -q 'ARROWCODE_BIN\|.local/bin' "$rc" 2>/dev/null; then |
| 147 | + echo "" >>"$rc" |
| 148 | + echo "# ArrowCode" >>"$rc" |
| 149 | + echo "export PATH=\"$BIN_DIR:\$PATH\"" >>"$rc" |
| 150 | + ok "Appended PATH to $rc" |
| 151 | + break |
| 152 | + fi |
| 153 | + done |
| 154 | + ;; |
| 155 | + esac |
| 156 | +fi |
| 157 | + |
| 158 | +if [[ "$DO_SETUP" -eq 1 ]]; then |
| 159 | + log "Running interactive setup" |
| 160 | + bun run src/index.ts --setup || true |
| 161 | +fi |
| 162 | + |
| 163 | +echo "" |
| 164 | +printf '%s' "$BLD" |
| 165 | +echo "────────────────────────────────────────────────────────────────" |
| 166 | +echo " ArrowCode installed" |
| 167 | +echo "────────────────────────────────────────────────────────────────" |
| 168 | +printf '%s' "$RST" |
| 169 | +echo " Location : $INSTALL_DIR" |
| 170 | +echo " Binary : $BIN_DIR/arrowcode" |
| 171 | +echo "" |
| 172 | +echo " Next:" |
| 173 | +echo " 1. export PATH=\"$BIN_DIR:\$PATH\" # if needed" |
| 174 | +echo " 2. arrowcode --setup # API key" |
| 175 | +echo " 3. cd your-project && arrowcode" |
| 176 | +echo "" |
| 177 | +echo " Docs: $INSTALL_DIR/README.md" |
| 178 | +echo " $INSTALL_DIR/docs/" |
| 179 | +echo "" |
0 commit comments