#!/usr/bin/env bash
# ai_node/run_sampling.sh — deterministic monetary-unit sampling + attributed
# cross-category synthesis + VERIFIED/DERIVED/REFUSED audit envelope on a CSV
# you provide, via the vendored CPA Audit Pack "envelope" module. Auditor-set
# parameters (materiality, seed) are attributed, not chosen by the tool. This
# script computes nothing itself.
set -euo pipefail
HERE="$(cd "$(dirname "$0")" && pwd)"
[ "$#" -ge 1 ] || { echo "usage: $0 <ledger.csv>" >&2; exit 2; }
CSV="$1"
[ -f "$CSV" ] || { echo "no such file: $CSV" >&2; exit 3; }
OUTDIR="$(cd "$(dirname "$CSV")" && pwd)"
BASE="$(basename "$CSV" .csv)"
LEDGER_JSON="$OUTDIR/${BASE}.ai_node_ledger.json"
RESULTS_JSON="$OUTDIR/${BASE}.sampling_results.json"
python3 "$HERE/audit_pack/csv_to_ledger.py" "$CSV" "$LEDGER_JSON"
CPA_AUDIT_LEDGER_JSON="$LEDGER_JSON" \
CPA_AUDIT_LEDGER_TEST_JSON="$OUTDIR/${BASE}.ai_node_no_second_ledger.json" \
CPA_AUDIT_OUT_JSON="$RESULTS_JSON" \
  python3 "$HERE/audit_pack/envelope/run.py"
echo
echo "Full results (sampling, synthesis, envelope, universality guard): $RESULTS_JSON"
