#!/bin/bash # Prints an evidence summary for a run (status, attempts, stages with cost, latest quality gates, publication). Run on the control plane. set -euo pipefail RUN="${1:?run id}"; export PATH=/opt/homebrew/opt/postgresql@17/bin:$PATH; DB="${DB:-autoscholar}" q(){ psql -d "$DB" -Atc "$1"; } echo "== run"; q "select status, research_mode, discipline, current_attempt_no||'/'||max_attempts as attempts, total_cost_usd, max_budget_usd, to_char(started_at,'HH24:MI')||'→'||coalesce(to_char(finished_at,'HH24:MI'),'…') as span, coalesce(failure_reason,'') from research_runs where id='$RUN'" echo "== attempts"; q "select attempt_no, status, cost_usd, coalesce(left(error,120),'') from run_attempts where run_id='$RUN' order by attempt_no" echo "== stages (latest attempt)"; q "select s.stage, s.status, s.cost_usd, s.turns, to_char(s.started_at,'HH24:MI:SS')||'→'||coalesce(to_char(s.ended_at,'HH24:MI:SS'),'…') from stage_executions s join run_attempts a on a.id=s.attempt_id where s.run_id='$RUN' and a.attempt_no=(select max(attempt_no) from run_attempts where run_id='$RUN') order by s.started_at" echo "== artifacts"; q "select count(*), sum(bytes) from (select distinct on (path) path, bytes from artifacts where run_id='$RUN' order by path, version desc) t" echo "== policy denials"; q "select count(*) from stage_events where run_id='$RUN' and kind='policy.denied'" echo "== quality gates (latest evaluation)"; q "select gate||' | '||severity||' | '||status||' | '||left(message,110) from quality_gate_results where run_id='$RUN' and evaluation_id=(select evaluation_id from quality_gate_results where run_id='$RUN' order by created_at desc limit 1) order by severity, gate" echo "== decisions"; q "select decision||' | '||decided_by||' | '||left(rationale,140) from publication_decisions where run_id='$RUN' order by created_at" echo "== paper"; q "select p.public_id||' | '||p.slug||' | v'||v.version_no||' | '||p.status from papers p join paper_versions v on v.paper_id=p.id where v.run_id='$RUN'"