#!/usr/bin/env bash
# 12-iteration harness-vs-naive ablation, both arms on dash1 (clean paired run,
# no host confound). Substrate: real output_length (no completion override),
# replay_time_scale=0.8775 (criterion-A, sim_A>=0.90), Stop-A on (LCA offered
# window), per-probe Stop-A-consistent drain deadline. Harness stops early; naive
# runs the full budget. Run from the repo root on dash1.
set -u
# Re-read the codex token from auth.json right before each arm (capturing it once at
# launch goes stale during a long run -- that is what 401'd naive runs 2/3).
read_key() { export OPENAI_API_KEY=$(python3 -c 'import json,pathlib;print(json.load(open(pathlib.Path.home()/".codex/auth.json"))["OPENAI_API_KEY"])'); }
# codex config.toml points at a dash0-local proxy (127.0.0.1:11235); on dash1 the
# LLM endpoint is reachable directly, so force a direct connection.
export http_proxy= https_proxy= all_proxy= HTTP_PROXY= HTTPS_PROXY= ALL_PROXY= no_proxy='*'
mkdir -p .aituner
rm -rf .aituner/abl12-harness .aituner/abl12-naive .aituner/ABLATION12_DONE

read_key
echo "=== harness ON  (12-iter) start $(date -Is) ==="
PYTHONPATH=src python3 -m aituner.cli study tune \
  --spec configs/examples/dash0_qwen27b_ablation_harness_on.json \
  --store-root .aituner/abl12-harness --max-trials 12 --skip-baseline > .aituner/abl12-harness.log 2>&1
echo "=== harness ON  (12-iter) done  $(date -Is) ==="

read_key
echo "=== naive OFF   (12-iter) start $(date -Is) ==="
PYTHONPATH=src python3 -m aituner.cli study tune \
  --spec configs/examples/dash0_qwen27b_ablation_naive_off.json \
  --store-root .aituner/abl12-naive --max-trials 12 --skip-baseline > .aituner/abl12-naive.log 2>&1
echo "=== naive OFF   (12-iter) done  $(date -Is) ==="

touch .aituner/ABLATION12_DONE
