/* ============================================================
gp-detail.jsx — the audit detail: verdict, linkage checks,
ranked candidate scale (re-rankable), robustness landscape.
============================================================ */
// ---- VERDICT BANNER (presentation varies by tweak: flagStyle) ----
function VerdictBanner({ result, decision, flagStyle }) {
const ok = result.verdict === "VERIFIED";
const c = ok ? "var(--emerald)" : "var(--rose)";
const failTxt = result.failed.map((f) => f.label).join(" · ");
if (flagStyle === "minimal") {
return (
{ok ? "VERIFIED" : "NEEDS REVIEW"}
{ok ? `winner is #${result.winnerRank} of ${result.validCount}` : failTxt}
);
}
if (flagStyle === "stamp") {
return (
SELECTION LINKAGE
winner is #{result.winnerRank} of {result.validCount} scored combos
{ok ? "VERIFIED" : "REVIEW"}
);
}
// default: "banner"
return (
{ok ? "VERIFIED" : "NEEDS REVIEW"}
{ok
? `winner is the top-scoring combo (#${result.winnerRank} of ${result.validCount})`
: failTxt}
{result.checks.filter((x) => x.pass).length}/{result.checks.length} checks
);
}
// ---- LINKAGE CHECKLIST ----
function LinkageChecks({ result }) {
return (
{result.checks.map((chk) => (
{chk.id === "toprank" && !chk.pass && (
winner ranked #{result.winnerRank}
)}
{chk.id === "composite" && !chk.pass && chk.mismatch != null && (
Δ {chk.mismatch > 0 ? "+" : ""}{chk.mismatch.toFixed(3)}
)}
{chk.id === "floor" && chk.pass && chk.margin != null && (
+{(chk.margin * 100).toFixed(1)}pp
)}
))}
);
}
// ---- RANKED CANDIDATE SCALE (re-rankable by any metric) ----
function CandidateScale({ decision, metricKey, setMetricKey, selected, onSelect, showRejected, setShowRejected }) {
const METRICS = window.GP.verify.METRICS;
const metric = window.GP.verify.metricByKey(metricKey);
const winner = decision.winner;
const winnerKey = JSON.stringify(winner.params);
const all = decision.sweep.candidates.map((c, i) => ({ ...c, _i: i }));
const valid = all.filter((c) => c[metricKey] != null && c.composite_score != null);
const rejected = all.filter((c) => c.composite_score == null);
// sort by chosen metric
const sorted = [...valid].sort((a, b) =>
metric.higher ? b[metricKey] - a[metricKey] : a[metricKey] - b[metricKey]);
// normalize for bar widths
const vals = valid.map((c) => c[metricKey]);
const lo = Math.min(...vals), hi = Math.max(...vals);
const span = (hi - lo) || 1;
const fracOf = (v) => metric.higher ? (v - lo) / span : (hi - v) / span;
const floor = decision.win_rate_floor;
const isWinner = (c) => JSON.stringify(c.params) === winnerKey;
const engineTopByMetric = sorted.length && isWinner(sorted[0]);
const paramSummary = (c) => {
const strat = window.GP.STRATEGIES.find((s) => s.id === decision.strategy_id);
return Object.keys(strat.paramSpace).map((k) => `${k.split("_")[0]}=${c.params[k]}`).join(" ");
};
return (
{METRICS.map((m) => (
))}
} />
sorting {sorted.length} scored combos by {metric.label}
{metric.higher ? " (high→low)" : " (low→high)"}
{!engineTopByMetric && (
engine pick is #{sorted.findIndex(isWinner) + 1} by {metric.short}
)}
{sorted.map((c, rank) => {
const win = isWinner(c);
const sel = selected != null && c._i === selected;
const passFloor = c.win_rate_frac >= floor;
const barColor = win ? "var(--emerald)" : passFloor ? "var(--cyan)" : "var(--rose)";
return (
onSelect(sel ? null : c._i)} style={{
display: "grid", gridTemplateColumns: "26px 1fr 64px", alignItems: "center", gap: 10,
padding: "5px 8px", cursor: "pointer", borderRadius: 3,
background: sel ? "var(--bg-2)" : win ? "color-mix(in oklab, var(--emerald) 8%, transparent)" : "transparent",
border: "1px solid " + (win ? "color-mix(in oklab, var(--emerald) 40%, transparent)" : sel ? "var(--line)" : "transparent"),
}}>
#{rank + 1}
{win &&
winner ◆}
{paramSummary(c)}
);
})}
{rejected.length > 0 && (
{showRejected && (
{rejected.map((c) => (
✕
{paramSummary(c)}
{c.rationale}
))}
)}
)}
);
}
// ---- ROBUSTNESS LANDSCAPE ----
function RobustnessPanel({ decision }) {
const rob = window.GP.verify.robustness(decision);
const slice = window.GP.verify.paramSlice(decision);
const ROB_META = {
PLATEAU: { c: "var(--emerald)", txt: "ROBUST PLATEAU", note: "the winner sits on a broad shelf of high scores — low overfit risk" },
SUPPORTED: { c: "var(--cyan)", txt: "SUPPORTED PEAK", note: "several nearby combos also score highly — reasonable confidence" },
NARROW: { c: "var(--amber)", txt: "NARROW PEAK", note: "few neighbors score highly — watch for fragility" },
SPIKE: { c: "var(--rose)", txt: "LONE SPIKE", note: "the winner is an isolated high — elevated overfit risk" },
UNKNOWN: { c: "var(--fg-3)", txt: "INSUFFICIENT", note: "not enough scored combos to judge" },
};
const meta = ROB_META[rob.kind];
const best = Math.max(...slice.points.filter((p) => p.best != null).map((p) => p.best));
const peak = decision.winner.composite_score;
const bandFrac = rob.band / (best || 1);
return (
{meta.txt}
} />
{/* 1-D param slice */}
best composite by {slice.param} (winner highlighted)
{/* 92% band line */}
89% of peak
{slice.points.map((p) => {
const h = p.best != null ? (p.best / best) * 94 : 0;
const strong = p.best != null && p.best >= rob.band;
return (
{p.best != null ? p.best.toFixed(2) : "—"}
{p.value}
);
})}
{/* neighborhood readout */}
{rob.neighborsHigh}
/ {rob.neighborsTotal}
{rob.clearFloorHigh}
{(rob.pctOfPeak * 100).toFixed(0)}%
{meta.note}
);
}
Object.assign(window, { VerdictBanner, LinkageChecks, CandidateScale, RobustnessPanel });