#!/bin/bash # setup — Install gstack-opencode for OpenCode set -e SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" SKILLS_DIR="$HOME/.config/opencode/skills" GSTACK_SKILLS_DIR="$SKILLS_DIR/gstack" echo "🔧 Installing gstack-opencode..." # 1. Check prerequisites echo "Checking prerequisites..." if ! command -v bun &> /dev/null; then echo "❌ bun is not installed. Install it first: https://bun.sh" exit 1 fi # 2. Build browse binary if not exists if [ ! -f "$SCRIPT_DIR/browse/dist/browse" ]; then echo "Building browse binary..." if [ -d "$SCRIPT_DIR/source" ]; then (cd "$SCRIPT_DIR/source" && bun install && bun build --compile browse/src/cli.ts --outfile "$SCRIPT_DIR/browse/dist/browse") else echo "❌ Source directory not found. Clone gstack first." exit 1 fi fi # 3. Create OpenCode skills directory echo "Creating OpenCode skills directory..." mkdir -p "$GSTACK_SKILLS_DIR" # 4. Symlink skills echo "Linking skills..." for skill_dir in "$SCRIPT_DIR/skills"/*/; do skill_name=$(basename "$skill_dir") target="$GSTACK_SKILLS_DIR/$skill_name" if [ -L "$target" ]; then rm "$target" elif [ -d "$target" ]; then echo "Warning: $target exists and is not a symlink. Skipping." continue fi ln -sf "$skill_dir" "$target" echo " ✓ Linked: $skill_name" done # 5. Create ~/.gstack directories echo "Creating state directories..." mkdir -p ~/.gstack/{sessions,projects,analytics} # 6. Create environment file cat > "$GSTACK_SKILLS_DIR/.env" << EOF export GSTACK_OPENCODE_DIR="$SCRIPT_DIR" export GSTACK_BROWSE="$SCRIPT_DIR/browse/dist/browse" EOF echo "" echo "✅ gstack-opencode installed successfully!" echo "" echo "Skills location: $GSTACK_SKILLS_DIR" echo "Browse binary: $SCRIPT_DIR/browse/dist/browse" echo "" echo "Available skills:" ls -1 "$GSTACK_SKILLS_DIR" | sed 's/^/ \//' | head -28 echo "" echo "To use in your shell, add to your .bashrc/.zshrc:" echo " source $SCRIPT_DIR/bin/gstack-env.sh"