#!/bin/sh # ============================================================================ # smart-tree - AI-powered file tree navigator + MCP server # Home: https://i1.is | Source: https://github.com/8b-is/smart-tree # ============================================================================ set -e # Colors G='\033[0;32m' C='\033[0;36m' Y='\033[1;33m' D='\033[0;90m' N='\033[0m' W='\033[1;37m' printf "\n" printf "${C}╔════════════════════════════════════════════════════════════════╗${N}\n" printf "${C}║${N} ${W}smart-tree${N} - AI-powered file tree navigator + MCP server ${C}║${N}\n" printf "${C}║${N} ${D}The AI's favorite way to explore codebases${N} ${C}║${N}\n" printf "${C}╚════════════════════════════════════════════════════════════════╝${N}\n" printf "\n" ARCH="$(uname -m)" OS="$(uname -s)" TARGET="" if [ "$OS" = "Linux" ] && [ "$ARCH" = "x86_64" ]; then TARGET="x86_64-unknown-linux-gnu" elif [ "$OS" = "Linux" ] && [ "$ARCH" = "aarch64" ]; then TARGET="aarch64-unknown-linux-gnu" elif [ "$OS" = "Darwin" ] && [ "$ARCH" = "arm64" ]; then TARGET="aarch64-apple-darwin" elif [ "$OS" = "Darwin" ] && [ "$ARCH" = "x86_64" ]; then TARGET="x86_64-apple-darwin" fi INSTALLED_PREBUILT=0 if [ -n "$TARGET" ] && [ "${1:-}" != "--compile" ]; then printf "${C}→${N} Checking signed release catalogue at https://i1.is/releases/smart-tree/latest.json ...\n" TMPDIR=$(mktemp -d) if curl -fsSL "https://i1.is/releases/smart-tree/latest.json" -o "$TMPDIR/latest.json" 2>/dev/null; then BUILD_ID=$(grep -o '"build_id"[[:space:]]*:[[:space:]]*"[^"]*"' "$TMPDIR/latest.json" | head -n1 | sed 's/.*"build_id"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/') ARCHIVE="st-${TARGET}.tar.gz" URL="https://i1.is/releases/smart-tree/${BUILD_ID}/${ARCHIVE}" if [ -n "$BUILD_ID" ] && curl -fsSL "$URL" -o "$TMPDIR/$ARCHIVE" 2>/dev/null; then curl -fsSL "${URL}.sha256" -o "$TMPDIR/${ARCHIVE}.sha256" 2>/dev/null || true if [ -f "$TMPDIR/${ARCHIVE}.sha256" ] && command -v sha256sum >/dev/null 2>&1; then (cd "$TMPDIR" && sha256sum -c "${ARCHIVE}.sha256" >/dev/null 2>&1) fi tar -xzf "$TMPDIR/$ARCHIVE" -C "$TMPDIR" DEST="${HOME}/.local/bin" mkdir -p "$DEST" for bin in st std m8 n8x; do if [ -f "$TMPDIR/$bin" ]; then install -m 0755 "$TMPDIR/$bin" "$DEST/$bin" fi done INSTALLED_PREBUILT=1 printf "${G}✓${N} Installed signed Smart Tree (${BUILD_ID}) to ${DEST}\n" fi fi rm -rf "$TMPDIR" fi if [ "$INSTALLED_PREBUILT" = "0" ]; then # Check if cargo is installed if ! command -v cargo >/dev/null 2>&1; then printf "${Y}→${N} Cargo not found. Installing Rust first...\n" curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y . "$HOME/.cargo/env" fi printf "${C}→${N} Installing smart-tree from source (https://github.com/8b-is/smart-tree)...\n" cargo install --git https://github.com/8b-is/smart-tree --locked 2>/dev/null || { TMPDIR=$(mktemp -d) git clone https://github.com/8b-is/smart-tree "$TMPDIR/smart-tree" cd "$TMPDIR/smart-tree" cargo build --release mkdir -p "$HOME/.cargo/bin" cp target/release/st "$HOME/.cargo/bin/" cd - >/dev/null rm -rf "$TMPDIR" } fi printf "\n" printf "${G}✓${N} ${W}smart-tree installed successfully!${N}\n" printf "\n" printf "${D}Usage:${N}\n" printf " ${W}st${N} ${D}# Quick overview${N}\n" printf " ${W}st -m context .${N} ${D}# Full context with git info${N}\n" printf " ${W}st -m quantum .${N} ${D}# Compressed for AI contexts${N}\n" printf " ${W}st --mcp${N} ${D}# Run as MCP server${N}\n" printf "\n" printf "${D}Claude Code integration: Add to ~/.claude/mcp_servers.json${N}\n" printf "\n"