#!/usr/bin/env bash # Regenerates every image in docs/img from the real interface, with synthetic audit data # (no Wi-Fi hardware needed): `sabia ui` serves the page and the browser answers /api/* from # scripts/screenshots/mock-api.mjs. # # scripts/screenshots.sh [out-dir] # default: docs/img (or $OUT) # # Env: CHROME (default ~/.claude/tools/chrome-claude), PUPPETEER_CORE (default the puppeteer-core # in ~/.claude/tools/node_modules), SABIA (binary to use; default: build target/release/sabia). set -euo pipefail cd "$(dirname "$0")/.." OUT=${1:-${OUT:-docs/img}} CHROME=${CHROME:-$HOME/.claude/tools/chrome-claude} PUPPETEER_CORE=${PUPPETEER_CORE:-$HOME/.claude/tools/node_modules/puppeteer-core/lib/esm/puppeteer/puppeteer-core.js} [ -x "$CHROME" ] || { echo "screenshots: Chrome not found at $CHROME (set CHROME)" >&2; exit 1; } [ -f "$PUPPETEER_CORE" ] || { echo "screenshots: puppeteer-core not found at $PUPPETEER_CORE (set PUPPETEER_CORE)" >&2; exit 1; } # The UI is embedded in the binary at compile time, so rebuild (incremental) unless SABIA is given. if [ -z "${SABIA:-}" ]; then cargo build --release -p sabia-cli; SABIA=target/release/sabia; fi mkdir -p "$OUT" OUT=$(cd "$OUT" && pwd) work=$(mktemp -d) pid= cleanup() { [ -n "$pid" ] && kill "$pid" 2>/dev/null || true; rm -rf "$work"; } trap cleanup EXIT port=$(python3 -c 'import socket; s=socket.socket(); s.bind(("127.0.0.1",0)); print(s.getsockname()[1])') # The audit log goes to the temp dir, never into the repo. "$SABIA" ui --port "$port" --no-open --audit "$work/audit.log" >"$work/ui.log" 2>&1 & pid=$! token= for _ in $(seq 1 50); do token=$(grep -o 'token=[A-Za-z0-9]*' "$work/ui.log" | head -1 | cut -d= -f2 || true) [ -n "$token" ] && break sleep 0.2 done [ -n "$token" ] || { echo "screenshots: could not read the UI token" >&2; cat "$work/ui.log" >&2; exit 1; } version=$(sed -n 's/^version = "\(.*\)"/\1/p' Cargo.toml | head -1) BASE_URL="http://127.0.0.1:$port" TOKEN="$token" OUT="$OUT" VERSION="$version" CHROME="$CHROME" PUPPETEER_CORE="$PUPPETEER_CORE" \ node scripts/screenshots/capture.mjs