#!/usr/bin/env bash
set -uo pipefail
umask 077
E="/home/cube/projects/richard/traning coach/.omo/evidence/task26/task26-gates18-20-clarification-normalized-4e9962be49b72951c3b9ed7e1a4fe36d0ca03e757872ae03364c1ab7a790f32b-st_01a0080c";C="/home/cube/projects/richard/traning coach/.omo/evidence/task26/task26-clarification-normalized-successor-4e9962be49b72951c3b9ed7e1a4fe36d0ca03e757872ae03364c1ab7a790f32b";R="/home/cube/projects/richard/hermes-agent";PY="$R/.venv/bin/python";D="4e9962be49b72951c3b9ed7e1a4fe36d0ca03e757872ae03364c1ab7a790f32b"
record(){ local n="$1";shift;local d="$E/artifacts/$n";mkdir -p "$d";printf '%q ' "$@">"$d/command.txt";printf '\n'>>"$d/command.txt";date -u +%Y-%m-%dT%H:%M:%S.%NZ>"$d/started-at-utc.txt";local s e rc pid;s=$(date +%s%N);"$@">"$d/stdout.txt" 2>"$d/stderr.txt"&pid=$!;wait "$pid";rc=$?;e=$(date +%s%N);date -u +%Y-%m-%dT%H:%M:%S.%NZ>"$d/ended-at-utc.txt";echo "$rc">"$d/exit-code.txt";echo "$(((e-s)/1000000))">"$d/duration-ms.txt";(cd "$d"&&sha256sum command.txt started-at-utc.txt ended-at-utc.txt exit-code.txt duration-ms.txt stdout.txt stderr.txt>files.sha256);chmod 600 "$d"/*;return 0;}
record basedpyright-current-final /home/cube/.local/bin/basedpyright --project "$C/source-delta/authenticated-fix-evidence/basedpyright-current.json" --pythonpath "$R/.venv/bin/python" --outputjson
record basedpyright-baseline-final /home/cube/.local/bin/basedpyright --project "$C/source-delta/authenticated-fix-evidence/basedpyright-baseline.json" --pythonpath "$R/.venv/bin/python" --outputjson
record type-classification-final "$PY" -c '
import json,sys
from collections import Counter
from pathlib import Path
root=Path(sys.argv[1]);a=json.loads((root/"basedpyright-current-final/stdout.txt").read_text());b=json.loads((root/"basedpyright-baseline-final/stdout.txt").read_text())
def rows(d):return [(Path(x["file"]).name,x["severity"],x.get("rule"),x["message"]) for x in d["generalDiagnostics"]]
ca,cb=Counter(rows(a)),Counter(rows(b));new=list((ca-cb).elements());removed=list((cb-ca).elements());pack=lambda x:{"file":x[0],"severity":x[1],"rule":x[2],"message":x[3]};r={"candidate_digest":sys.argv[2],"current_summary":a["summary"],"baseline_summary":b["summary"],"inherited_count":sum((ca&cb).values()),"new_diagnostics":list(map(pack,new)),"removed_diagnostics":list(map(pack,removed)),"regression":a["summary"]["errorCount"]-b["summary"]["errorCount"],"status":"PASS" if not new and a["summary"]["errorCount"]==b["summary"]["errorCount"] else "FAIL"};print(json.dumps(r,ensure_ascii=False,sort_keys=True,separators=(",",":")));raise SystemExit(r["status"]!="PASS")
' "$E/artifacts" "$D"
