#!/bin/bash
set -e

# Directory where the app will be hosted
APP_DIR="$HOME/.m4j/claw/app"

# Ensure the directory exists
mkdir -p "$APP_DIR"
cd "$APP_DIR"

# Clone if not exists, otherwise update to latest main
if [ ! -d ".git" ]; then
    echo "Cloning claw repository..."
    git clone git@github.com:maxine4j/claw.git .
else
    echo "Updating claw repository to latest origin/main..."
    git fetch origin
    git reset --hard origin/main
fi

# Run the application
echo "Starting claw..."
bun install
bun run start