#!/usr/bin/env bash set -euo pipefail ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" usage() { cat <<'EOF' Usage: gori-agent [arguments] Commands: init setup start stop restart status logs doctor list Instances live under ${GORI_AGENT_ROOT:-$HOME/.gori-agent}/instances/. config.example.json is documentation only and is never used as runtime config. EOF } ensure_build() { if [[ ! -f "$ROOT_DIR/dist/cli.js" || ! -f "$ROOT_DIR/dist/cli/instance-runner.js" ]]; then echo "CLI build output not found; building..." npm run build --prefix "$ROOT_DIR" fi } if [[ $# -eq 0 ]]; then usage exit 1 fi case "$1" in --help|-h) usage exit 0 ;; esac ensure_build exec node "$ROOT_DIR/dist/cli.js" "$@"