#!/usr/bin/env bash
# Run from the chosen commit's checkout, once per fresh data directory.
# DATA, WORKSPACE, SERVER_PORT, WEB_PORT are supplied by the caller.
set -eu
export T3CODE_DEV_SEED=0 T3CODE_AUTO_BOOTSTRAP_PROJECT_FROM_CWD=0
export T3CODE_ENVIRONMENT_LABEL=Evidence T3CODE_ENVIRONMENT_MACHINE_KIND=laptop
export T3CODE_PORT_OFFSET=$((WEB_PORT - 5733))
# Run these two commands in separate retained terminals:
# node scripts/dev-runner.ts dev:server --home-dir "$DATA" --no-seed --host 127.0.0.1 --port "$SERVER_PORT" --dev-url "http://127.0.0.1:$WEB_PORT"
# node scripts/dev-runner.ts dev:web --home-dir "$DATA" --no-seed --port "$SERVER_PORT" --dev-url "http://127.0.0.1:$WEB_PORT" -- --host 127.0.0.1
mkdir -p "$WORKSPACE"
git -C "$WORKSPACE" init -q --initial-branch=main
git -C "$WORKSPACE" -c user.name=Evidence -c user.email=evidence@example.invalid commit -q --allow-empty -m 'Initial commit'
node apps/server/src/bin.ts project add "$WORKSPACE" --title proj --base-dir "$DATA"
node apps/server/src/bin.ts thread start "$WORKSPACE" go --title go --provider devReplay --model command-output --wait --json --base-dir "$DATA"
# Pair the browser using the server's one-time pairing URL, then open the returned thread.
# Stop only the owner of SERVER_PORT after verifying its cwd is this checkout.
# Restart after Undo with:
# node apps/server/src/bin.ts serve --host 127.0.0.1 --port "$SERVER_PORT" --base-dir "$DATA" --dev-url "http://127.0.0.1:$WEB_PORT"
