#!/usr/bin/env bash
# Codex wire replay thin launcher (spec/codex-wire-capture-replay.spec.md).
#
# Point the commander's `--codex-bin` at this script to swap the real codex
# engine for the wire replay server: same spawn contract (`--version`,
# `login status`, `app-server ... --listen <ws-url>`), zero runner code
# changes, no codex auth anywhere. The implementation is ReScript
# (HarnessCodexWireReplayBinMain.res); this launcher only resolves the
# compiled module beside this checkout and execs node on it - build first
# with `npx rescript build packages/linzumi-cli-rescript` (the CLI test
# script already does).
#
# Env (read by the bin): LINZUMI_WIRE_REPLAY_CAPTURE (required),
# LINZUMI_WIRE_REPLAY_STRICTNESS, LINZUMI_WIRE_REPLAY_CLOCK,
# LINZUMI_WIRE_REPLAY_REPORT.
set -euo pipefail

here="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
bin_module="$here/../../linzumi-cli-rescript/src/harness/HarnessCodexWireReplayBinMain.res.mjs"

if [[ ! -f "$bin_module" ]]; then
  echo "codex-wire-replay-bin: compiled module missing at $bin_module - run: npx rescript build <repo>/packages/linzumi-cli-rescript" >&2
  exit 66
fi

exec node "$bin_module" "$@"
