Skip to content

Open-source platform for 3D AI agents. Turn text or a photo into a rigged, animated GLB avatar, give it an LLM brain, memory and a wallet, and embed it anywhere with one web component. Remote MCP server, x402 payments, Three.js, browser-native.

31.9 KB
Raw Blame
<!DOCTYPE html>
<html lang="en">
<head>
	<script>/* three.ws theme boot — no-flash */(function(){try{var m=localStorage.getItem('twx_theme');var l=m==='auto'?(window.matchMedia&&window.matchMedia('(prefers-color-scheme: light)').matches):m==='light';document.documentElement.setAttribute('data-theme',l?'light':'dark');}catch(e){document.documentElement.setAttribute('data-theme','dark');}})();</script>
	<meta charset="utf-8" />
	<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover" />
	<title data-i18n="pipeline.meta_title">Recording Pipeline · three.ws</title>
	<meta name="description" content="Live health of the three.ws data loop: the pump.fun launch recorder, signal intel, ground-truth outcomes, Oracle conviction, the wallet reputation graph, trained weights, and the agents trading on the result — every stage, in real time."  data-i18n-attr="content:pipeline.meta_description"/>
	<link rel="canonical" href="https://three.ws/pipeline" />
	<link rel="icon" href="/favicon.ico" sizes="any" />
	<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
	<link rel="apple-touch-icon" href="/apple-touch-icon.png" />
	<link rel="manifest" href="/manifest.webmanifest" />
	<link rel="stylesheet" href="/style.css" />
	<link rel="stylesheet" href="/nav.css" />
	<link rel="stylesheet" href="/mobile.css" />
	<meta property="og:type" content="website" />
	<meta property="og:title" content="Recording Pipeline · three.ws"  data-i18n-attr="content:pipeline.meta_og_title"/>
	<meta property="og:description" content="The data loop, live: launch recorder → signal intel → ground-truth outcomes → Oracle conviction → reputation graph → trained weights → trading agents."  data-i18n-attr="content:pipeline.meta_og_description"/>
	<meta property="og:url" content="https://three.ws/pipeline" />
	<meta name="twitter:card" content="summary_large_image" />
	<style>
		/* ── Strict monochrome. State is encoded by lightness + opacity, never hue.
		   All values inherit the canonical ramp from /tokens.css (loaded via
		   style.css): --bg-*, --ink*, --surface-*, --stroke*, --radius-*. ── */
		:root {
			--pl-gap: 14px;
			--pl-card-min: 168px;
			/* one neutral ramp for stage "liveness" — bright = flowing, faint = idle */
			--pl-live:   var(--ink-bright, #fff);
			--pl-active: var(--ink, #e8e8e8);
			--pl-idle:   var(--ink-faint, rgba(255,255,255,0.45));
			--pl-down:   var(--ink-dim, #888);
		}
		* { box-sizing: border-box; }
		body {
			margin: 0;
			background: var(--bg-0, #0a0a0a);
			color: var(--ink, #e8e8e8);
			font-family: var(--font-body, 'Inter', system-ui, sans-serif);
			-webkit-font-smoothing: antialiased;
		}
		.pl-main { max-width: 1180px; margin: 0 auto; padding: clamp(18px, 4vw, 40px) clamp(14px, 4vw, 28px) 80px; }

		/* ── Header ───────────────────────────────────────────────────── */
		.pl-head { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 16px 24px; margin-bottom: 8px; }
		.pl-title { font-family: var(--font-display, 'Space Grotesk', sans-serif); font-size: clamp(1.6rem, 4vw, 2.3rem); font-weight: 600; letter-spacing: -0.02em; margin: 0; color: var(--ink-bright, #fff); }
		.pl-sub { color: var(--ink-dim, #888); font-size: 0.9rem; max-width: 56ch; margin: 6px 0 0; line-height: 1.5; }
		.pl-controls { display: flex; align-items: center; gap: 10px; margin-left: auto; }
		.pl-net { display: inline-flex; border: 1px solid var(--stroke, rgba(255,255,255,0.08)); border-radius: var(--radius-pill, 999px); overflow: hidden; }
		.pl-net button { appearance: none; background: transparent; border: 0; color: var(--ink-dim, #888); font: inherit; font-size: 0.78rem; padding: 6px 13px; cursor: pointer; transition: color var(--duration-fast), background var(--duration-fast); }
		.pl-net button[aria-pressed="true"] { background: var(--surface-3, rgba(255,255,255,0.08)); color: var(--ink-bright, #fff); }
		.pl-net button:hover { color: var(--ink, #e8e8e8); }
		.pl-net button:focus-visible { outline: 2px solid var(--ink-bright, #fff); outline-offset: -2px; color: var(--ink-bright, #fff); }
		.pl-refresh { appearance: none; background: var(--surface-1, rgba(255,255,255,0.03)); border: 1px solid var(--stroke, rgba(255,255,255,0.08)); border-radius: var(--radius-md, 10px); color: var(--ink-dim, #888); width: 34px; height: 34px; display: grid; place-items: center; cursor: pointer; transition: color var(--duration-fast), border-color var(--duration-fast), transform var(--duration-base); }
		.pl-refresh:hover { color: var(--ink-bright, #fff); border-color: var(--stroke-strong, rgba(255,255,255,0.14)); }
		.pl-refresh:focus-visible { outline: 2px solid var(--ink-bright, #fff); outline-offset: 2px; color: var(--ink-bright, #fff); }
		.pl-refresh:active { transform: scale(0.94); }
		/* Spins for exactly as long as the request is in flight, never on a timer. */
		.pl-refresh.spin svg { animation: pl-spin .7s linear infinite; }
		@keyframes pl-spin { to { transform: rotate(360deg); } }

		/* ── Overall health banner ───────────────────────────────────── */
		.pl-health { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 18px; margin: 22px 0 26px; padding: 16px 18px; border: 1px solid var(--stroke, rgba(255,255,255,0.08)); border-radius: var(--radius-lg, 14px); background: var(--surface-1, rgba(255,255,255,0.03)); }
		.pl-dot { width: 9px; height: 9px; border-radius: 50%; flex: none; background: var(--pl-down); position: relative; }
		.pl-dot.is-live { background: var(--pl-live); box-shadow: 0 0 0 0 rgba(255,255,255,0.5); animation: pl-pulse 2s infinite; }
		.pl-dot.is-active { background: var(--pl-active); }
		.pl-dot.is-degraded { background: var(--pl-down); animation: pl-blink 1.1s steps(2) infinite; }
		.pl-dot.is-idle, .pl-dot.is-offline, .pl-dot.is-down, .pl-dot.is-unknown { background: transparent; border: 1.5px solid var(--pl-idle); }
		@keyframes pl-pulse { 0% { box-shadow: 0 0 0 0 rgba(255,255,255,0.45); } 70% { box-shadow: 0 0 0 7px rgba(255,255,255,0); } 100% { box-shadow: 0 0 0 0 rgba(255,255,255,0); } }
		@keyframes pl-blink { 50% { opacity: 0.3; } }
		.pl-health-state { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 16px; flex: 1 1 300px; min-width: 0; }
		.pl-health-label { font-family: var(--font-display, sans-serif); font-weight: 600; font-size: 1.05rem; color: var(--ink-bright, #fff); text-transform: capitalize; }
		.pl-health-note { color: var(--ink-dim, #888); font-size: 0.85rem; flex: 1 1 280px; line-height: 1.45; }
		.pl-meta { color: var(--ink-faint, rgba(255,255,255,0.45)); font-size: 0.72rem; font-family: var(--font-mono, monospace); letter-spacing: 0.02em; white-space: nowrap; }

		/* ── Offline call-to-action ──────────────────────────────────── */
		.pl-cta { margin: -8px 0 26px; padding: 16px 18px; border: 1px dashed var(--stroke-strong, rgba(255,255,255,0.14)); border-radius: var(--radius-lg, 14px); background: var(--surface-1, rgba(255,255,255,0.03)); }
		.pl-cta h3 { margin: 0 0 6px; font-size: 0.95rem; color: var(--ink-bright, #fff); font-weight: 600; }
		.pl-cta p { margin: 0; color: var(--ink-dim, #888); font-size: 0.85rem; line-height: 1.5; }
		.pl-cta code { font-family: var(--font-mono, monospace); font-size: 0.8rem; background: var(--surface-3, rgba(255,255,255,0.08)); padding: 1px 6px; border-radius: 5px; color: var(--ink, #e8e8e8); }

		/* ── The flow rail ───────────────────────────────────────────── */
		.pl-flow { display: grid; grid-template-columns: repeat(7, 1fr); gap: var(--pl-gap); align-items: stretch; }
		@media (max-width: 1080px) { .pl-flow { grid-template-columns: repeat(3, 1fr); } }
		@media (max-width: 620px)  { .pl-flow { grid-template-columns: repeat(2, 1fr); } }
		@media (max-width: 400px)  { .pl-flow { grid-template-columns: 1fr; } }

		.pl-stage { position: relative; display: flex; flex-direction: column; min-height: 158px; padding: 14px; border: 1px solid var(--stroke, rgba(255,255,255,0.08)); border-radius: var(--radius-lg, 14px); background: var(--surface-1, rgba(255,255,255,0.03)); transition: border-color var(--duration-base) var(--ease-standard), background var(--duration-base), transform var(--duration-base); opacity: 0; transform: translateY(8px); animation: pl-in .42s var(--ease-standard, cubic-bezier(.2,.8,.2,1)) forwards; }
		.pl-stage:hover { border-color: var(--stroke-strong, rgba(255,255,255,0.14)); background: var(--surface-2, rgba(255,255,255,0.05)); }
		.pl-stage.s-live, .pl-stage.s-active { border-color: var(--stroke-strong, rgba(255,255,255,0.18)); }
		.pl-stage.s-live::before { content: ""; position: absolute; inset: 0; border-radius: inherit; box-shadow: inset 0 0 0 1px rgba(255,255,255,0.10); pointer-events: none; }
		.pl-stage.s-idle, .pl-stage.s-offline, .pl-stage.s-down { opacity: 0; }
		.pl-stage.s-idle { animation-name: pl-in-dim; }
		@keyframes pl-in { to { opacity: 1; transform: none; } }
		@keyframes pl-in-dim { to { opacity: 0.62; transform: none; } }

		/* flow arrows between stages (desktop only) */
		.pl-stage:not(:last-child)::after { content: ""; position: absolute; top: 50%; right: calc(var(--pl-gap) * -1 - 1px); width: var(--pl-gap); height: 1px; background: linear-gradient(90deg, var(--stroke-strong, rgba(255,255,255,0.14)), transparent); transform: translateY(-50%); z-index: 1; }
		@media (max-width: 1080px) { .pl-stage::after { display: none; } }

		.pl-stage-top { display: flex; align-items: center; gap: 7px; margin-bottom: 2px; }
		.pl-stage-n { font-family: var(--font-mono, monospace); font-size: 0.62rem; color: var(--ink-faint, rgba(255,255,255,0.45)); }
		.pl-stage-label { font-family: var(--font-display, sans-serif); font-size: 0.82rem; font-weight: 600; color: var(--ink-bright, #fff); margin: 0; }
		.pl-stage-tag { font-size: 0.66rem; color: var(--ink-dim, #888); margin: 0 0 12px; text-transform: uppercase; letter-spacing: 0.06em; }
		.pl-stat { margin-top: auto; }
		.pl-stat-v { font-family: var(--font-mono, monospace); font-size: 1.55rem; font-weight: 600; color: var(--ink-bright, #fff); line-height: 1; letter-spacing: -0.02em; }
		.pl-stat-v.dim { color: var(--ink-faint, rgba(255,255,255,0.45)); }
		.pl-stat-l { font-size: 0.68rem; color: var(--ink-dim, #888); margin-top: 4px; }
		.pl-subs { list-style: none; margin: 11px 0 0; padding: 11px 0 0; border-top: 1px solid var(--stroke, rgba(255,255,255,0.06)); display: grid; gap: 4px; }
		.pl-subs li { display: flex; justify-content: space-between; gap: 8px; font-size: 0.7rem; color: var(--ink-dim, #888); }
		.pl-subs b { font-family: var(--font-mono, monospace); font-weight: 500; color: var(--ink, #e8e8e8); }
		.pl-stage-dot { margin-left: auto; }
		/* stage cards are links into each surface's detail view */
		a.pl-stage { text-decoration: none; color: inherit; cursor: pointer; }
		a.pl-stage:focus-visible { outline: 2px solid var(--ink-bright, #fff); outline-offset: 2px; }
		.pl-stage-go { position: absolute; right: 12px; bottom: 11px; font-size: 0.82rem; color: var(--ink-faint, rgba(255,255,255,0.45)); opacity: 0; transform: translateX(-3px); transition: opacity var(--duration-fast), transform var(--duration-fast), color var(--duration-fast); }
		a.pl-stage:hover .pl-stage-go, a.pl-stage:focus-visible .pl-stage-go { opacity: 1; transform: none; color: var(--ink-bright, #fff); }

		/* ── Skeleton + error ────────────────────────────────────────── */
		.pl-skel { min-height: 158px; border-radius: var(--radius-lg, 14px); border: 1px solid var(--stroke, rgba(255,255,255,0.08)); background: linear-gradient(90deg, var(--surface-1, rgba(255,255,255,0.03)), var(--surface-3, rgba(255,255,255,0.08)), var(--surface-1, rgba(255,255,255,0.03))); background-size: 200% 100%; animation: pl-shimmer 1.4s linear infinite; }
		@keyframes pl-shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }
		.pl-error { grid-column: 1 / -1; text-align: center; padding: 48px 22px; border: 1px solid var(--stroke, rgba(255,255,255,0.08)); border-radius: var(--radius-lg, 14px); background: var(--surface-1, rgba(255,255,255,0.03)); }
		.pl-error h3 { margin: 0 0 6px; color: var(--ink-bright, #fff); font-size: 1rem; }
		.pl-error p { margin: 0 0 16px; color: var(--ink-dim, #888); font-size: 0.85rem; }
		.pl-btn { appearance: none; background: var(--ink-bright, #fff); color: var(--bg-0, #0a0a0a); border: 0; border-radius: var(--radius-md, 10px); font: inherit; font-weight: 600; font-size: 0.82rem; padding: 9px 18px; cursor: pointer; transition: opacity var(--duration-fast), transform var(--duration-fast); }
		.pl-btn:hover { opacity: 0.9; }
		.pl-btn:active { transform: translateY(1px); }
		.pl-btn:focus-visible { outline: 2px solid var(--ink-bright, #fff); outline-offset: 3px; }

		/* ── Raw endpoints (this board is an API first) ──────────────── */
		.pl-raw { margin: 18px 0 0; color: var(--ink-faint, rgba(255,255,255,0.45)); font-size: 0.72rem; line-height: 1.6; max-width: 74ch; }
		.pl-raw a { color: var(--ink-dim, #888); font-family: var(--font-mono, monospace); text-decoration: none; border-bottom: 1px solid var(--stroke-strong, rgba(255,255,255,0.14)); transition: color var(--duration-fast), border-color var(--duration-fast); }
		.pl-raw a:hover { color: var(--ink-bright, #fff); border-color: var(--ink-bright, #fff); }
		.pl-raw a:focus-visible { outline: 2px solid var(--ink-bright, #fff); outline-offset: 3px; border-radius: 3px; }

		/* ── Legend ──────────────────────────────────────────────────── */
		.pl-legend { display: flex; flex-wrap: wrap; gap: 16px; margin-top: 26px; color: var(--ink-dim, #888); font-size: 0.72rem; }
		.pl-legend span { display: inline-flex; align-items: center; gap: 7px; }
		@media (prefers-reduced-motion: reduce) { * { animation-duration: .001ms !important; } .pl-stage { opacity: 1 !important; transform: none !important; } }
	</style>

	<meta name="robots" content="index, follow, max-image-preview:large, max-snippet:-1">
	<meta property="og:site_name" content="three.ws">
	<meta property="og:locale" content="en_US">
	<meta property="og:image" content="https://three.ws/api/page-og?s=crypto&amp;t=Recording+Pipeline%3A+the+data+loop%2C+live&amp;d=One-glance+health+of+the+closed+loop+that+turns+every+pump.fun+launch+into+a+trade+signal%3A+the+launch+recorder%2C+signal+intel%2C+ground-truth+outcomes%2C+Oracle&amp;p=%2Fpipeline">
	<meta property="og:image:width" content="1200">
	<meta property="og:image:height" content="630">
	<meta property="og:image:type" content="image/png">
	<meta property="og:image:alt" content="Recording Pipeline — the data loop, live — three.ws">
	<meta name="twitter:site" content="@trythreews">
	<meta name="twitter:title" content="Recording Pipeline — the data loop, live · three.ws" data-i18n-attr="content:pipeline.meta_twitter_title">
	<meta name="twitter:description" content="One-glance health of the closed loop that turns every pump.fun launch into a trade signal: the launch recorder, signal intel, ground-truth outcomes, Oracle conviction, the wallet reputation graph, trained weights, and the agents trading on the result — every stage, in real time." data-i18n-attr="content:pipeline.meta_twitter_description">
	<meta name="twitter:image" content="https://three.ws/api/page-og?s=crypto&amp;t=Recording+Pipeline%3A+the+data+loop%2C+live&amp;d=One-glance+health+of+the+closed+loop+that+turns+every+pump.fun+launch+into+a+trade+signal%3A+the+launch+recorder%2C+signal+intel%2C+ground-truth+outcomes%2C+Oracle&amp;p=%2Fpipeline">
	<script type="application/ld+json">{"@context":"https://schema.org","@graph":[{"@type":"WebPage","name":"Recording Pipeline — the data loop, live","description":"One-glance health of the closed loop that turns every pump.fun launch into a trade signal: the launch recorder, signal intel, ground-truth outcomes, Oracle conviction, the wallet reputation graph, trained weights, and the agents trading on the result — every stage, in real time.","url":"https://three.ws/pipeline","isPartOf":{"@type":"WebSite","name":"three.ws","url":"https://three.ws"},"primaryImageOfPage":"https://three.ws/api/page-og?s=crypto&t=Recording+Pipeline+%E2%80%94+the+data+loop%2C+live&d=One-glance+health+of+the+closed+loop+that+turns+every+pump.fun+launch+into+a+trade+signal%3A+the+launch+recorder%2C+signal+intel%2C+ground-truth+outcomes%2C+Oracle+conv&p=%2Fpipeline"}]}</script>
</head>
<body>
	<header class="site-header"><div id="nav-container"></div></header>

	<main class="pl-main">
		<div class="pl-head">
			<div>
				<h1 class="pl-title" data-i18n="pipeline.recording_pipeline">Recording Pipeline</h1>
				<p class="pl-sub" data-i18n="pipeline.the_closed_loop_that_turns_every_pump">The closed loop that turns every pump.fun launch into a trade signal — recorded, scored, labeled, and learned from. Each stage feeds the next.</p>
			</div>
			<div class="pl-controls">
				<div class="pl-net" role="group" aria-label="Network">
					<button data-net="mainnet" aria-pressed="true" data-i18n="pipeline.mainnet">mainnet</button>
					<button data-net="devnet" aria-pressed="false" data-i18n="pipeline.devnet">devnet</button>
				</div>
				<button class="pl-refresh" id="pl-refresh" aria-label="Refresh now" title="Refresh" data-i18n-attr="aria-label:pipeline.refresh_now_arialabel;title:pipeline.refresh_title">
					<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 12a9 9 0 1 1-2.64-6.36"/><path d="M21 3v6h-6"/></svg>
				</button>
			</div>
		</div>

		<div class="pl-health" id="pl-health" hidden>
			<span class="pl-dot" id="pl-health-dot"></span>
			<span class="pl-health-state" role="status">
				<span class="pl-health-label" id="pl-health-label"></span>
				<span class="pl-health-note" id="pl-health-note"></span>
			</span>
			<span class="pl-meta" id="pl-meta"></span>
		</div>

		<!-- Populated from the endpoint's own next_action so the page, the API,
		     and any agent reading it give one answer to "what should happen now". -->
		<div class="pl-cta" id="pl-cta" hidden></div>

		<div class="pl-flow" id="pl-flow">
			<div class="pl-skel"></div><div class="pl-skel"></div><div class="pl-skel"></div>
			<div class="pl-skel"></div><div class="pl-skel"></div><div class="pl-skel"></div><div class="pl-skel"></div>
		</div>

		<div class="pl-legend">
			<span data-i18n-html="pipeline.live_flowing_now"><i class="pl-dot is-live" style="position:static"></i> Live — flowing now</span>
			<span data-i18n-html="pipeline.active_has_data"><i class="pl-dot is-active" style="position:static"></i> Active — has data</span>
			<span data-i18n-html="pipeline.idle_awaiting_upstream"><i class="pl-dot is-idle" style="position:static"></i> Idle — awaiting upstream</span>
			<span data-i18n-html="pipeline.degraded_up_but_stalled"><i class="pl-dot is-degraded" style="position:static"></i> Degraded — up but stalled</span>
		</div>

		<p class="pl-raw" data-i18n-html="pipeline.every_number_on_this_board_comes">Every number on this board comes from one public endpoint: <a id="pl-raw-api" href="/api/pipeline?network=mainnet" target="_blank" rel="noopener">/api/pipeline</a>, which returns the same stages plus a machine-readable next action. The recorder's own liveness detail lives at <a href="/api/sniper/status" target="_blank" rel="noopener">/api/sniper/status</a>.</p>
	</main>

	<script src="/nav.js"></script>
	<script type="module">
		const flow = document.getElementById('pl-flow');
		const healthEl = document.getElementById('pl-health');
		const dotEl = document.getElementById('pl-health-dot');
		const labelEl = document.getElementById('pl-health-label');
		const noteEl = document.getElementById('pl-health-note');
		const metaEl = document.getElementById('pl-meta');
		const ctaEl = document.getElementById('pl-cta');
		const refreshBtn = document.getElementById('pl-refresh');
		const netBtns = [...document.querySelectorAll('.pl-net button')];

		let network = 'mainnet';
		let timer = null;
		// Requests supersede rather than queue: a click on the network toggle or
		// the refresh button while the 8s poll is still in flight must win, or the
		// board paints the previous network's numbers under the new label.
		let seq = 0;
		let inFlightController = null;
		// Live handles on the seven stage cards. The board re-polls every 8s; it
		// patches these in place rather than re-rendering the grid, so a card the
		// user has tabbed to keeps focus and a screen reader is not handed a fresh
		// copy of all seven cards on every tick.
		let cards = null;

		const esc = (s) => String(s ?? '').replace(/[&<>"]/g, (c) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;' }[c]));
		const fmt = (n) => { n = Number(n) || 0; return n >= 1e6 ? (n / 1e6).toFixed(1) + 'M' : n >= 1e3 ? (n / 1e3).toFixed(1) + 'k' : String(n); };
		const ago = (ms) => { if (ms == null) return '—'; const s = Math.round(ms / 1000); if (s < 60) return s + 's ago'; const m = Math.round(s / 60); if (m < 60) return m + 'm ago'; return Math.round(m / 60) + 'h ago'; };
		const since = (iso) => { if (!iso) return '—'; return ago(Date.now() - new Date(iso).getTime()); };
		const setText = (el, v) => { const t = String(v); if (el.textContent !== t) el.textContent = t; };
		const setAttr = (el, k, v) => { if (el.getAttribute(k) !== v) el.setAttribute(k, v); };

		// A stage the endpoint stopped sending must still render as an honest zero.
		// Normalizing once, at the boundary, keeps every model below able to read
		// its fields directly and stops a shape change from turning the whole board
		// into a "couldn't reach the pipeline" error that would be a lie.
		const STAGE_DEFAULTS = {
			recorder: { state: 'unknown' },
			intel: { observed_24h: 0, observed_1h: 0, avg_quality: null, smart_money_touched: 0 },
			outcomes: { labeled: 0, graduated: 0, pumped: 0, rugged: 0 },
			oracle: { scored_total: 0, scored_24h: 0, prime: 0, strong: 0 },
			reputation: { wallets: 0, smart_money: 0 },
			learning: { sample_size: 0, trained_at: null, weights: [] },
			trading: { strategies_armed: 0, open_positions: 0, snipes_24h: 0, trades_24h: 0 },
		};

		function normalize(stages) {
			const out = {};
			for (const key of Object.keys(STAGE_DEFAULTS)) {
				const got = stages && typeof stages[key] === 'object' && stages[key] ? stages[key] : null;
				out[key] = { ...STAGE_DEFAULTS[key], ...got };
			}
			if (!Array.isArray(out.learning.weights)) out.learning.weights = [];
			return out;
		}

		// Each stage derives its visual state + headline + sub-rows from the raw payload.
		// State is purely about data flow — encoded by lightness in the monochrome theme.
		function stageModels(raw) {
			const s = normalize(raw);
			const rec = s.recorder;
			const recState = rec.state === 'live' ? 'live' : rec.state === 'degraded' ? 'degraded'
				: (rec.state === 'down' || rec.state === 'offline' || rec.state === 'unknown') ? rec.state : 'idle';
			const on = (v) => (v > 0 ? 'active' : 'idle');
			return [
				{
					n: '01', label: 'Recorder', tag: 'pump.fun feed', state: recState, href: '/pump-live',
					value: rec.state === 'live' ? 'LIVE' : rec.state === 'degraded' ? 'STALL' : rec.state === 'down' ? 'DOWN' : 'OFF',
					vdim: rec.state !== 'live',
					vlabel: rec.state === 'live' ? (rec.mode || 'live') + ' · ' + (rec.feedLive ? 'feed up' : 'feed down') : (rec.reason || 'not reporting'),
					subs: [['Heartbeat', ago(rec.heartbeatAgeMs)], ['Last event', ago(rec.lastEventAgeMs)], ['Reconnects', rec.reconnects ?? '—']],
				},
				{
					n: '02', label: 'Intel', tag: 'launch signals', state: on(s.intel.observed_24h), href: '/radar',
					value: fmt(s.intel.observed_24h), vdim: !s.intel.observed_24h, vlabel: 'launches recorded · 24h',
					subs: [['Last hour', fmt(s.intel.observed_1h)], ['Avg quality', s.intel.avg_quality ?? '—'], ['Smart-money seen', fmt(s.intel.smart_money_touched)]],
				},
				{
					n: '03', label: 'Outcomes', tag: 'ground truth', state: on(s.outcomes.labeled), href: '/coin-intel',
					value: fmt(s.outcomes.labeled), vdim: !s.outcomes.labeled, vlabel: 'coins labeled',
					subs: [['Graduated', fmt(s.outcomes.graduated)], ['Pumped ≥3×', fmt(s.outcomes.pumped)], ['Rugged', fmt(s.outcomes.rugged)]],
				},
				{
					n: '04', label: 'Oracle', tag: 'conviction', state: on(s.oracle.scored_total), href: '/oracle',
					value: fmt(s.oracle.scored_total), vdim: !s.oracle.scored_total, vlabel: 'coins scored',
					subs: [['Scored · 24h', fmt(s.oracle.scored_24h)], ['Prime tier', fmt(s.oracle.prime)], ['Strong tier', fmt(s.oracle.strong)]],
				},
				{
					n: '05', label: 'Reputation', tag: 'wallet graph', state: on(s.reputation.wallets), href: '/smart-money',
					value: fmt(s.reputation.wallets), vdim: !s.reputation.wallets, vlabel: 'wallets profiled',
					subs: [['Smart money', fmt(s.reputation.smart_money)]],
				},
				{
					n: '06', label: 'Learning', tag: 'trained weights', state: on(s.learning.sample_size), href: '/coin-intel',
					value: fmt(s.learning.sample_size), vdim: !s.learning.sample_size, vlabel: s.learning.sample_size >= 50 ? 'samples trained' : 'samples · needs ≥50',
					subs: s.learning.weights.length
						? s.learning.weights.slice(0, 3).map((w) => [String(w.signal).replace(/_/g, ' '), (w.weight >= 0 ? '+' : '') + Number(w.weight).toFixed(2)])
						: [['Trained', since(s.learning.trained_at)]],
				},
				{
					n: '07', label: 'Trading', tag: 'armed agents', state: (s.trading.snipes_24h + s.trading.trades_24h) > 0 ? 'active' : on(s.trading.strategies_armed), href: '/activity',
					value: fmt(s.trading.snipes_24h + s.trading.trades_24h), vdim: !(s.trading.snipes_24h + s.trading.trades_24h), vlabel: 'snipes + trades · 24h',
					subs: [['Armed', fmt(s.trading.strategies_armed)], ['Open positions', fmt(s.trading.open_positions)], ['Snipes · 24h', fmt(s.trading.snipes_24h)]],
				},
			];
		}

		const subsHtml = (m) => m.subs.map(([k, v]) => `<li><span>${esc(k)}</span><b>${esc(v)}</b></li>`).join('');
		const ariaFor = (m) => `${m.label}: ${m.value}, ${m.vlabel}. Open details`;

		function cardHtml(m, i) {
			return `<a class="pl-stage s-${m.state}" href="${esc(m.href)}" aria-label="${esc(ariaFor(m))}" style="animation-delay:${i * 45}ms">
				<div class="pl-stage-top">
					<span class="pl-stage-n">${m.n}</span>
					<h2 class="pl-stage-label">${esc(m.label)}</h2>
					<span class="pl-dot pl-stage-dot is-${m.state}"></span>
				</div>
				<p class="pl-stage-tag">${esc(m.tag)}</p>
				<div class="pl-stat">
					<div class="pl-stat-v${m.vdim ? ' dim' : ''}">${esc(m.value)}</div>
					<div class="pl-stat-l">${esc(m.vlabel)}</div>
				</div>
				<ul class="pl-subs">${subsHtml(m)}</ul>
				<span class="pl-stage-go" aria-hidden="true">→</span>
			</a>`;
		}

		/** Build the grid once, then patch values in place on every later poll. */
		function paint(models) {
			if (!cards || cards.length !== models.length) {
				flow.innerHTML = models.map(cardHtml).join('');
				cards = [...flow.querySelectorAll('.pl-stage')].map((root) => ({
					root,
					dot: root.querySelector('.pl-stage-dot'),
					value: root.querySelector('.pl-stat-v'),
					vlabel: root.querySelector('.pl-stat-l'),
					subs: root.querySelector('.pl-subs'),
				}));
				return;
			}
			models.forEach((m, i) => {
				const c = cards[i];
				const cls = 'pl-stage s-' + m.state;
				if (c.root.className !== cls) c.root.className = cls;
				setAttr(c.root, 'href', m.href);
				setAttr(c.root, 'aria-label', ariaFor(m));
				const dotCls = 'pl-dot pl-stage-dot is-' + m.state;
				if (c.dot.className !== dotCls) c.dot.className = dotCls;
				setText(c.value, m.value);
				c.value.classList.toggle('dim', !!m.vdim);
				setText(c.vlabel, m.vlabel);
				const rows = subsHtml(m);
				if (c.subs.innerHTML !== rows) c.subs.innerHTML = rows;
			});
		}

		function skeletons() {
			cards = null;
			flow.innerHTML = '<div class="pl-skel"></div>'.repeat(7);
		}

		function renderHealth(data) {
			healthEl.hidden = false;
			const rec = normalize(data.stages).recorder;
			const cls = rec.state === 'degraded' ? 'is-degraded'
				: data.health === 'flowing' ? 'is-live' : data.health === 'recording' ? 'is-active' : 'is-idle';
			if (dotEl.className !== 'pl-dot ' + cls) dotEl.className = 'pl-dot ' + cls;
			setText(labelEl, data.health ?? 'unknown');
			setText(noteEl, rec.state === 'degraded'
				? 'The worker is up but its feed has gone silent, so no new launches are being recorded.'
				: data.health === 'flowing'
				? 'The recorder is live and launches are streaming in, so the full loop is running.'
				: data.health === 'recording'
				? 'The recorder is live; waiting on the next launch to flow downstream.'
				: 'The pipeline is idle. Once the recorder worker starts, every downstream stage activates.');
			setText(metaEl, `${data.network} · updated ${new Date(data.t || Date.now()).toLocaleTimeString([], { hour: '2-digit', minute: '2-digit', second: '2-digit' })}`);
			// Drive the call-to-action straight from the endpoint's own guidance so
			// the page and any agent reading /api/pipeline tell the same story.
			const na = data.next_action || {};
			const actionable = na.step && !['running', 'accumulate', 'await_training'].includes(na.step);
			if (actionable) {
				const html = `<h3>${esc(na.label)}</h3><p>${esc(na.detail)}${na.command ? ` <code>${esc(na.command)}</code>` : ''}</p>`;
				if (ctaEl.innerHTML !== html) ctaEl.innerHTML = html;
				ctaEl.hidden = false;
			} else {
				ctaEl.hidden = true;
			}
		}

		function renderError(message) {
			healthEl.hidden = true;
			ctaEl.hidden = true;
			cards = null;
			flow.innerHTML = `<div class="pl-error" role="alert">
				<h3>Couldn't reach the pipeline</h3>
				<p>${esc(message)}. The board keeps retrying every 8 seconds on its own.</p>
				<button class="pl-btn" id="pl-retry" type="button">Try again</button></div>`;
			document.getElementById('pl-retry')?.addEventListener('click', load);
		}

		async function load() {
			const mine = ++seq;
			inFlightController?.abort();
			const controller = new AbortController();
			inFlightController = controller;
			const asked = network;
			// Re-queried rather than cached: the runtime i18n pass can replace this
			// paragraph after first render, and a stale node would leave the link
			// pointing at whichever network the page booted on.
			document.getElementById('pl-raw-api')?.setAttribute('href', '/api/pipeline?network=' + asked);
			refreshBtn.classList.add('spin');
			flow.setAttribute('aria-busy', 'true');
			try {
				const r = await fetch(`/api/pipeline?network=${asked}`, { headers: { accept: 'application/json' }, signal: controller.signal });
				if (!r.ok) throw new Error('HTTP ' + r.status + ' from the status service');
				const data = await r.json();
				if (mine !== seq) return;
				renderHealth(data);
				paint(stageModels(data.stages));
			} catch (e) {
				if (mine !== seq || e.name === 'AbortError') return;
				renderError(navigator.onLine === false ? 'This device is offline' : e.message);
			} finally {
				if (mine === seq) {
					inFlightController = null;
					refreshBtn.classList.remove('spin');
					flow.setAttribute('aria-busy', 'false');
				}
			}
		}

		function schedule() { clearInterval(timer); timer = setInterval(load, 8000); }

		netBtns.forEach((b) => b.addEventListener('click', () => {
			if (b.dataset.net === network) return;
			network = b.dataset.net;
			netBtns.forEach((x) => x.setAttribute('aria-pressed', String(x.dataset.net === network)));
			skeletons();
			load();
		}));
		refreshBtn.addEventListener('click', load);
		// Pause polling when the tab is hidden — no point burning requests in the background.
		document.addEventListener('visibilitychange', () => { if (document.hidden) clearInterval(timer); else { load(); schedule(); } });

		load();
		schedule();
	</script>
	<!-- Runtime i18n: detects locale, swaps annotated copy, mounts <lang-switcher>. -->
	<script type="module" src="/i18n.js"></script>
</body>
</html>