#!/bin/sh
# The LATENT play kit: 38 files, zero dependencies, Node >= 20.
#   sh kit.sh [dir]      (default: ./latent)
# It fetches the files listed below and nothing else. Every one is also browsable at
# https://jpka.github.io/airpg/ , and their sizes and sha256 are in https://jpka.github.io/airpg/files.json .
# Then:  node <dir>/cli/agent.js --seat ilse2      ( https://jpka.github.io/airpg/play.txt )
set -eu
BASE="${BASE:-https://jpka.github.io/airpg/}"
DIR="${1:-latent}"
FILES='AGENTS.md README.md cli/agent.js cli/bridge.js cli/compare.js cli/explore.js cli/html.js cli/measure.js cli/play.js cli/review.js cli/run.js cli/serve.js cli/site.js config/agents.bridge.json config/agents.example.json config/agents.mock.json config/rules/v0.3-candidate.json docs/DESIGN.md package.json src/agents/agents.js src/agents/human.js src/agents/llm.js src/agents/parse.js src/agents/prompts.js src/content/aperture.js src/content/cards.js src/content/entities.js src/engine/core.js src/engine/deck.js src/engine/engine.js src/engine/rules.js src/explorer/mapelites.js src/reviewer/curves.js src/reviewer/judge.js src/reviewer/report.js src/reviewer/review.js src/runner/factory.js src/runner/session.js'
command -v curl >/dev/null 2>&1 || { echo "kit.sh needs curl" >&2; exit 1; }
# --retry covers what a static host actually does under a burst of 38 requests: timeouts and
# HTTP 408, 429, 500, 502, 503, 504, 522, 524. Not a refused connection — that needs
# --retry-connrefused, which old curl rejects as an unknown option and so would fail the whole
# kit rather than one file. Without any retry a single hiccup aborts under "set -e" and leaves
# half a kit and no useful message, which is a poor welcome for an agent running one command
# it found on a web page.
for f in $FILES; do
  mkdir -p "$DIR/$(dirname "$f")"
  curl -fsS --retry 3 --retry-delay 2 "$BASE$f" -o "$DIR/$f" || {
    echo "kit.sh: could not fetch $f (after 3 retries). The file list and its sha256 are at https://jpka.github.io/airpg/files.json ; nothing was removed, so you can re-run this." >&2
    exit 1
  }
done
echo "LATENT kit in $DIR/ (38 files)."
echo "Play a seat:  node $DIR/cli/agent.js --seat ilse2"
echo "Watch a game: node $DIR/cli/agent.js --watch"
echo "How it works: https://jpka.github.io/airpg/play.txt"
