(function () { const byId = id => document.getElementById(id); const count = (rows, key, value) => Number((rows || []).find(row => row[key] === value)?.count || 0); const sum = (rows, predicate) => (rows || []).filter(predicate).reduce((total, row) => total + Number(row.count || 0), 0); function renderHypotheses(rows) { const host = byId("hypothesis-list"); if (!rows?.length) { host.innerHTML = '
No autonomy hypotheses yet. The coordinator is working through the evidence queue.
'; return; } host.innerHTML = rows.slice(0, 7).map(row => { const action = row.action || (row.status === "resolved" ? "MEASURED" : "OPEN"); const direction = row.direction === "positive" ? "positive" : "negative"; return `
${escapeHtml(row.instrument)}
${escapeHtml(row.direction)}
${escapeHtml(String(row.event_type || "event").replaceAll("_", " "))}
${escapeHtml(row.causal_channel || "Evidence-backed market hypothesis")}
${row.evidence_count || 0} evidence source${row.evidence_count === 1 ? "" : "s"}
${row.horizon_days} trading-day horizon
${formatRelative(row.created_at)}
${escapeHtml(action)}
`; }).join(""); } function renderLedger(rows) { const host = byId("decision-ledger"); const decisions = (rows || []).filter(row => row.action); if (!decisions.length) return; host.innerHTML = decisions.map(row => ` ${escapeHtml(row.instrument)} ${escapeHtml(row.action)} ${escapeHtml(row.direction)} ${formatPercent(row.calibrated_probability)} ${row.horizon_days}d ${formatRelative(row.created_at)} `).join(""); } const ORIGIN_LABELS = { live: "Live", historical: "Historical backfill", replay: "Walk-forward replay", }; // live, historical and replay are deliberately never blended. only the live // row is an edge claim, the other two are how the model was taught. function renderOriginSplit(byOrigin, livePredictions) { const host = byId("origin-split"); if (!host) return; const rows = (byOrigin || []).filter(row => row.origin !== "live"); if (!rows.length) { host.innerHTML = ""; return; } host.innerHTML = rows.map(row => { const total = Number(row.total || 0); const label = ORIGIN_LABELS[row.origin] || row.origin; const accuracy = total ? formatPercent(Number(row.correct || 0) / total) : "—"; return `
${escapeHtml(label)}${formatNumber(total)} measured · ${accuracy}
`; }).join(""); byId("origin-note").textContent = livePredictions ? "Historical backfill and walk-forward replay are listed separately. Neither counts toward live edge." : "No live predictions exist yet, so the numbers above are training and replay only — not evidence of live edge."; } function cohortCell(check, format) { if (!check || !check.known) return 'unknown'; return `${format(check.value)} / ${format(check.threshold)}`; } function renderCohorts(rows) { const host = byId("cohort-list"); if (!host) return; if (!rows?.length) { host.innerHTML = 'No calibration snapshots yet.'; return; } host.innerHTML = rows.map(row => { const checks = row.qualification?.checks || {}; const qualified = Boolean(row.qualification?.qualified); const reasons = row.qualification?.reasons || []; const status = qualified ? 'QUALIFIES' : `ABSTAIN
${escapeHtml(reasons.join(" · ") || "does not qualify")}
`; const key = row.legacy_cohort_key ? `${escapeHtml(row.cohort_key || "—")}
legacy key, not comparable to current cohorts
` : escapeHtml(row.cohort_key || "—"); return ` ${key} ${escapeHtml(row.source || "unknown")} ${cohortCell(checks.sample_size, value => formatNumber(value))} ${cohortCell(checks.distinct_instruments, value => formatNumber(value))} ${cohortCell(checks.top_instrument_share, value => formatPercent(value, 0))} ${status} `; }).join(""); } function render(data) { if (!data.enabled) throw new Error(data.reason || "Autonomy is unavailable"); const mode = String(data.mode || "shadow").toUpperCase(); const open = count(data.predictionCounts, "status", "open"); const resolved = count(data.predictionCounts, "status", "resolved"); const byOrigin = data.outcomesByOrigin || []; const livePredictions = (data.predictionsByOrigin || []).filter(row => row.origin === "live") .reduce((total, row) => total + Number(row.count || 0), 0); const outcomes = Number(data.outcomes?.total || 0); const correct = Number(data.outcomes?.correct || 0); const accuracy = outcomes ? correct / outcomes : null; const pendingHistorical = count((data.jobs || []).filter(row => row.lane === "historical"), "status", "pending"); const completedJobs = sum(data.jobs, row => row.status === "complete"); const proposals = sum(data.proposalCounts, row => row.status === "accepted"); const decisions = sum(data.decisionCounts, () => true); byId("execution-mode").textContent = mode; byId("ledger-mode").textContent = mode; byId("runtime-execution").textContent = mode; byId("broker-state").textContent = data.broker?.configured ? `${data.broker.name} connected` : "Broker credentials unavailable"; byId("runtime-state").textContent = `${mode} runtime active`; byId("hero-title").textContent = mode === "PAPER" ? "Duriin is trading in simulation." : "Duriin is learning before it acts."; byId("hero-description").textContent = mode === "PAPER" ? "Every order is backed by measured evidence, empirical calibration and deterministic risk policy. No model has direct execution authority." : "It is turning evidence into hypotheses, waiting for outcomes, and calibrating its judgment without placing broker orders."; byId("metric-open").textContent = formatNumber(open); byId("metric-resolved").textContent = `${formatNumber(resolved)} resolved`; byId("metric-accuracy").textContent = formatPercent(accuracy); byId("metric-sample").textContent = outcomes ? `${formatNumber(outcomes)} measured live outcomes` : (livePredictions ? "Live predictions have not matured yet" : "No live predictions yet"); byId("metric-alpha").textContent = formatPercent(data.outcomes?.average_excess_return, 2); byId("metric-universe").textContent = formatNumber(data.allowlistedInstruments, true); byId("pipe-observe").textContent = formatNumber(completedJobs, true); byId("pipe-propose").textContent = formatNumber(proposals, true); byId("pipe-measure").textContent = formatNumber(outcomes, true); byId("pipe-calibrate").textContent = formatNumber(data.calibration?.length || 0); byId("pipe-act").textContent = formatNumber(decisions); byId("freshness").textContent = `Updated ${formatRelative(data.generatedAt)}`; byId("orbit-value").textContent = formatPercent(accuracy, 0); byId("accuracy-orbit").style.setProperty("--accuracy", `${(accuracy || 0) * 360}deg`); byId("perf-resolved").textContent = formatNumber(outcomes); byId("perf-correct").textContent = formatNumber(correct); byId("perf-cohorts").textContent = formatNumber(data.calibration?.length || 0); if (outcomes) { byId("performance-note").textContent = `Measured on ${outcomes} matured live predictions. Results remain descriptive until the sample is large enough for stable calibration.`; } else if (livePredictions) { byId("performance-note").textContent = `No live prediction has matured yet — ${formatNumber(livePredictions)} are still open. Nothing here is a live track record.`; } else { byId("performance-note").textContent = "No live predictions yet. Everything measured so far is historical backfill or replay, which is training, not a live track record."; } renderOriginSplit(byOrigin, livePredictions); renderCohorts(data.calibration); const replay = data.replay; byId("replay-status").textContent = replay ? replay.status : "Not started"; byId("replay-articles").textContent = replay ? formatNumber(replay.processed_articles || 0) : "—"; byId("replay-evaluations").textContent = replay ? formatNumber(replay.evaluations || 0) : "—"; byId("replay-watermark").textContent = replay?.watermark_at ? formatRelative(replay.watermark_at) : "—"; byId("runtime-queue").textContent = `${formatNumber(pendingHistorical, true)} pending`; byId("runtime-coordinator").textContent = pendingHistorical ? "Processing" : "Watching"; if (data.account) { byId("account-equity").textContent = new Intl.NumberFormat("en-US", { style: "currency", currency: "USD", maximumFractionDigits: 0 }).format(data.account.equity || 0); byId("account-meta").textContent = `${data.account.broker} · sampled ${formatRelative(data.account.captured_at)}`; } renderHypotheses(data.latestPredictions); renderLedger(data.latestPredictions); } api("/admin/api/autonomy/overview").then(render).catch(error => { byId("hero-title").textContent = "Duriin cannot read its autonomy state."; byId("hero-description").textContent = error.message; byId("hypothesis-list").innerHTML = '
Runtime data is unavailable.
'; toast("Autonomy overview unavailable", true); }); })();