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.
JavaScript 3d-generationai-agentsanimationavatardigital-humangenerative-aiglbgltfimage-to-3dllmmcpmcp-servermodel-context-protocolsolanatext-to-3dthreejsweb-componentswebglwebxrx402
fix(agi): stop publishing an internal id as a coin mint in the decision stream
nirholasf3f351301153
diff --git a/api/agi/state.js b/api/agi/state.jsindex 5e94c2f28..5b5f52cd6 100644--- a/api/agi/state.js+++ b/api/agi/state.js@@ -24,7 +24,7 @@ import { limits, clientIp } from '../_lib/rate-limit.js';import { sql } from '../_lib/db.js';import { getTraderStats } from '../_lib/trader-stats.js';import { getReputationRecords, computeReputation, getDecisionsWithOutcomes } from '../_lib/reasoning-ledger.js';-import { isUuid } from '../_lib/validate.js';+import { isUuid, isValidSolanaAddress } from '../_lib/validate.js';const NETWORKS = new Set(['mainnet', 'devnet']);@@ -96,13 +96,29 @@ function ageMs(ts, now) {return Number.isFinite(t) ? now - t : Infinity;}+// Trading verbs, for decisions whose subject is not itself a coin (an exit keyed+// by a position id, say). Kept as a hint on top of the shape test below, never as+// the only signal, so a new verb still classifies correctly the moment its+// subject is a mint.+const TRADE_KINDS = new Set(['snipe', 'buy', 'sell', 'entry', 'exit', 'trade', 'scale', 'hold']);+export function shapeDecision(d, network) {const reconciled = d.outcome_status != null && d.was_correct != null;+ // `subject_ref` is a free-form pointer: a coin mint for a trading call, but an+ // internal id (a tuner arm, say) for an operational one. Publishing the latter+ // as `mint` sent the page to solscan.io/token/<uuid>, a link to nothing. Only a+ // real base58 address is a mint; everything else keeps its raw ref and is+ // classified as operations so a reader can tell the two apart.+ const subjectRef = d.subject_ref ?? null;+ const mint = isValidSolanaAddress(subjectRef) ? subjectRef : null;+ const kind = d.kind;return {id: d.id,seq: Number(d.seq),- kind: d.kind,- mint: d.subject_ref,+ kind,+ subject_ref: subjectRef,+ mint,+ domain: mint || TRADE_KINDS.has(String(kind || '').toLowerCase()) ? 'trade' : 'operations',rationale: d.rationale,confidence: d.confidence != null ? Number(d.confidence) : null,prediction: d.prediction || {},@@ -251,7 +267,9 @@ export default wrap(async (req, res) => {const [stats, repRecords, rawDecisions] = await Promise.all([getTraderStats({ agentId, network, window: 'all', now }),getReputationRecords(agentId).catch(() => []),- getDecisionsWithOutcomes(agentId, { limit: 24 }).catch(() => []),+ // Wide enough that a burst of operational self-tuning calls cannot push every+ // trading decision out of the window the page filters over.+ getDecisionsWithOutcomes(agentId, { limit: 40 }).catch(() => []),]);// A private or missing agent never gets published, whichever path selected it.diff --git a/pages/agi.html b/pages/agi.htmlindex 03d1d9bdc..ed8d6e389 100644--- a/pages/agi.html+++ b/pages/agi.html@@ -7,7 +7,7 @@<title data-i18n="agi.meta_title">The AGI · three.ws</title><metaname="description"- content="The first AGI — narrow by design. A single autonomous agent that is genuinely superhuman at one thing: trading memecoins on pump.fun (Solana), and deliberately nothing else. Watch it think, trade, and be held to a chain-proven track record in real time."+ content="The first AGI, narrow by design. A single autonomous agent that is genuinely superhuman at one thing: trading memecoins on pump.fun (Solana), and deliberately nothing else. Watch its embodied 3D body react to the market, read every decision with its stated confidence, and hold it to a chain-proven track record."data-i18n-attr="content:agi.meta_description"/><meta property="og:type" content="website" /><meta property="og:site_name" content="three.ws" />@@ -15,7 +15,7 @@<meta property="og:title" content="The AGI · three.ws" data-i18n-attr="content:agi.meta_og_title"/><metaproperty="og:description"- content="Artificial general intelligence in a single domain: pump.fun memecoin trading. It reads launches, the wallet graph, and order flow faster than any human — then sizes, enters, and exits on its own. Outside that domain it claims nothing."+ content="Artificial general intelligence in a single domain: pump.fun memecoin trading. It reads launches, the wallet graph, and order flow faster than any human, then sizes, enters, and exits on its own. Outside that domain it claims nothing."data-i18n-attr="content:agi.meta_og_description"/><meta property="og:image" content="https://three.ws/api/page-og?s=crypto&t=The+AGI%3A+narrow+by+design&d=The+first+AGI%2C+narrow+by+design%3A+a+single+autonomous+agent+that+is+genuinely+superhuman+at+one+thing%2C+trading+memecoins+on+pump.fun+%28Solana%29%2C+and+deliberately&p=%2Fagi" /><meta property="og:image:width" content="1200" />@@ -37,10 +37,10 @@<link rel="canonical" href="https://three.ws/agi" /><meta property="og:locale" content="en_US">- <meta property="og:image:alt" content="The AGI — narrow by design — three.ws">- <meta name="twitter:description" content="The first AGI, narrow by design: a single autonomous agent that is genuinely superhuman at one thing — trading memecoins on pump.fun (Solana) — and deliberately nothing else. Watch its embodied 3D body react to the market in real time, read every decision it makes with its stated confidence, and hold it to a chain-proven track record. Outside that one domain, it claims nothing." data-i18n-attr="content:agi.meta_twitter_description">+ <meta property="og:image:alt" content="The AGI: narrow by design. three.ws">+ <meta name="twitter:description" content="The first AGI, narrow by design: a single autonomous agent that is genuinely superhuman at one thing, trading memecoins on pump.fun (Solana), and deliberately nothing else. Watch its embodied 3D body react to the market in real time, read every decision it makes with its stated confidence, and hold it to a chain-proven track record. Outside that one domain, it claims nothing." data-i18n-attr="content:agi.meta_twitter_description"><meta name="twitter:image" content="https://three.ws/api/page-og?s=crypto&t=The+AGI%3A+narrow+by+design&d=The+first+AGI%2C+narrow+by+design%3A+a+single+autonomous+agent+that+is+genuinely+superhuman+at+one+thing%2C+trading+memecoins+on+pump.fun+%28Solana%29%2C+and+deliberately&p=%2Fagi">- <script type="application/ld+json">{"@context":"https://schema.org","@graph":[{"@type":"WebPage","name":"The AGI — narrow by design","description":"The first AGI, narrow by design: a single autonomous agent that is genuinely superhuman at one thing — trading memecoins on pump.fun (Solana) — and deliberately nothing else. Watch its embodied 3D body react to the market in real time, read every decision it makes with its stated confidence, and hold it to a chain-proven track record. Outside that one domain, it claims nothing.","url":"https://three.ws/agi","isPartOf":{"@type":"WebSite","name":"three.ws","url":"https://three.ws"},"primaryImageOfPage":"https://three.ws/api/page-og?s=crypto&t=The+AGI+%E2%80%94+narrow+by+design&d=The+first+AGI%2C+narrow+by+design%3A+a+single+autonomous+agent+that+is+genuinely+superhuman+at+one+thing+%E2%80%94+trading+memecoins+on+pump.fun+%28Solana%29+%E2%80%94+and+deliberately&p=%2Fagi"}]}</script>+ <script type="application/ld+json">{"@context":"https://schema.org","@graph":[{"@type":"WebPage","name":"The AGI: narrow by design","description":"The first AGI, narrow by design: a single autonomous agent that is genuinely superhuman at one thing, trading memecoins on pump.fun (Solana), and deliberately nothing else. Watch its embodied 3D body react to the market in real time, read every decision it makes with its stated confidence, and hold it to a chain-proven track record. Outside that one domain, it claims nothing.","url":"https://three.ws/agi","isPartOf":{"@type":"WebSite","name":"three.ws","url":"https://three.ws"},"primaryImageOfPage":"https://three.ws/api/page-og?s=crypto&t=The+AGI%3A+narrow+by+design&d=The+first+AGI%2C+narrow+by+design%3A+a+single+autonomous+agent+that+is+genuinely+superhuman+at+one+thing%2C+trading+memecoins+on+pump.fun+%28Solana%29%2C+and+deliberately&p=%2Fagi"}]}</script></head><body><header><div id="nav-container"></div></header>diff --git a/src/agi.css b/src/agi.cssindex 5689123ff..b685bc2f6 100644--- a/src/agi.css+++ b/src/agi.css@@ -1,10 +1,10 @@-/* The AGI — flagship surface for the platform's narrow-domain trading agent.+/* The AGI: flagship surface for the platform's narrow-domain trading agent.* Monochrome on near-black, φ-spaced (tokens.css). The one chromatic license is* the mood aura around the embodied body, whose hue is set at runtime from the* live cognition vector (--agi-aura). Semantic green/red only ever mark P&L. *//* This page doesn't load /style.css, so the near-black canvas isn't painted- by default — without this, every --ink/--ink-dim token here renders against+ by default. Without this, every --ink/--ink-dim token here renders againstthe browser's white default background instead of --bg-0. */body {background: var(--bg-0);@@ -124,7 +124,7 @@ body {flex-direction: column;}.agi-stage::before {- /* mood aura — hue/intensity set at runtime via --agi-aura / --agi-aura-strength */+ /* mood aura: hue/intensity set at runtime via --agi-aura / --agi-aura-strength */content: '';position: absolute; inset: 0;background: radial-gradient(60% 55% at 50% 62%, var(--agi-aura, rgba(124, 147, 179, 0.28)), transparent 70%);@@ -176,6 +176,28 @@ body {/* ── live mind (decision stream) ──────────────────────────────────────────── */.agi-mind { min-height: 360px; }+/* Lens over the stream. Only shown once the agent has logged both trading and+ operational calls, so it never appears as a control with nothing to switch. */+.agi-filter { display: flex; flex-wrap: wrap; gap: var(--space-xs); margin-bottom: var(--space-md); }+.agi-chip {+ display: inline-flex; align-items: center; gap: var(--space-2xs);+ padding: var(--space-2xs) var(--space-sm);+ border-radius: var(--radius-pill);+ border: 1px solid var(--stroke);+ background: var(--surface-2);+ color: var(--ink-dim);+ font-family: var(--font-mono);+ font-size: var(--text-2xs);+ letter-spacing: 0.04em;+ cursor: pointer;+ transition: border-color 0.15s ease, background 0.15s ease, color 0.15s ease;+}+.agi-chip:hover { border-color: var(--ink-dim); color: var(--ink); background: var(--surface-3); }+.agi-chip:active { transform: translateY(1px); }+.agi-chip:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }+.agi-chip[aria-pressed='true'] { border-color: var(--ink-bright); color: var(--ink-bright); background: var(--surface-3); }+.agi-chip-n { color: var(--ink-faint); font-variant-numeric: tabular-nums; }+.agi-chip[aria-pressed='true'] .agi-chip-n { color: var(--ink-dim); }.agi-stream { display: flex; flex-direction: column; gap: var(--space-sm); }.agi-thought {border: 1px solid var(--stroke);@@ -193,6 +215,9 @@ body {}.agi-thought-mint a { font-family: var(--font-mono); font-size: var(--text-2xs); color: var(--ink); text-decoration: none; border-bottom: 1px dotted var(--stroke-strong); }.agi-thought-mint a:hover { color: var(--ink-bright); }+/* An operational call's subject is an internal id, not a coin: same slot, but+ plainly not a link to a token. */+.agi-thought-ref { font-family: var(--font-mono); font-size: var(--text-2xs); color: var(--ink-faint); }.agi-thought-time { font-family: var(--font-mono); font-size: var(--text-2xs); color: var(--ink-faint); white-space: nowrap; }.agi-thought-body { font-size: var(--text-md); line-height: 1.5; color: var(--ink); margin: var(--space-2xs) 0; }.agi-thought-meta { display: flex; flex-wrap: wrap; gap: var(--space-sm); align-items: center; font-family: var(--font-mono); font-size: var(--text-2xs); }@@ -220,6 +245,8 @@ body {.agi-stat .k { font-family: var(--font-mono); font-size: var(--text-2xs); letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink-dim); }.agi-stat .v { font-family: var(--font-display); font-size: var(--text-lg); margin-top: 2px; }+.agi-open-head { margin-bottom: var(--space-sm); }+.agi-open-head h3 { font-family: var(--font-display); font-size: var(--text-md); font-weight: 600; margin: 0; letter-spacing: -0.01em; }.agi-positions { display: flex; flex-direction: column; gap: var(--space-2xs); }.agi-position { display: flex; align-items: center; justify-content: space-between; gap: var(--space-sm); padding: var(--space-xs) 0; border-bottom: 1px solid var(--stroke); font-family: var(--font-mono); font-size: var(--text-sm); }.agi-position:last-child { border-bottom: none; }@@ -243,8 +270,12 @@ body {.agi-skel { background: linear-gradient(90deg, var(--surface-1) 25%, var(--surface-2) 37%, var(--surface-1) 63%); background-size: 400% 100%; animation: agi-shimmer 1.4s ease infinite; border-radius: var(--radius-md); }@keyframes agi-shimmer { 0% { background-position: 100% 0; } 100% { background-position: -100% 0; } }.agi-empty, .agi-error { text-align: center; padding: var(--space-xl); color: var(--ink-dim); }-.agi-empty h2 { font-family: var(--font-display); color: var(--ink); margin: 0 0 var(--space-sm); }+.agi-empty h2, .agi-error h2 { font-family: var(--font-display); color: var(--ink); margin: 0 0 var(--space-sm); }+.agi-empty p { margin: 0 auto; max-width: 52ch; line-height: 1.55; }+.agi-empty .agi-btn { margin-top: var(--space-md); }.agi-error { border: 1px solid rgba(248, 113, 113, 0.3); border-radius: var(--radius-lg); background: var(--surface-1); }+.agi-error p { margin: 0 auto; max-width: 54ch; line-height: 1.55; }+.agi-error-actions { display: flex; flex-wrap: wrap; gap: var(--space-sm); justify-content: center; margin-top: var(--space-lg); }/* ── responsive ───────────────────────────────────────────────────────────── */@media (max-width: 900px) {@@ -260,4 +291,5 @@ body {@media (prefers-reduced-motion: reduce) {.agi-thought, .agi-domain-tag .agi-dot, .agi-skel { animation: none; }.agi-stage::before, .agi-stage agent-3d, .agi-ring .agi-ring-val { transition: none; }+ .agi-chip, .agi-btn { transition: none; }}diff --git a/src/agi.js b/src/agi.jsindex dd68f9720..da5b98bfe 100644--- a/src/agi.js+++ b/src/agi.js@@ -1,15 +1,21 @@-// The AGI — frontend surface.+// The AGI: frontend surface.//-// One real, autonomous agent, framed as what it is: a narrow AGI — genuinely+// One real, autonomous agent, framed as what it is: a narrow AGI, genuinely// superhuman at pump.fun memecoin trading and deliberately nothing else. This// page gives that mind a body (the <agent-3d> element, mood-driven from the live// cognition vector) and surrounds it with the proof: a live stream of its actual-// decisions, a chain-proven track record, and its stated doctrine — what it+// decisions, a chain-proven track record, and its stated doctrine: what it// claims, and what it refuses.//// Every number comes from /api/agi/state (real DB / on-chain truth layers). No// sample data: when the platform has no proven trader yet, the page renders a// designed "awakening" state instead of inventing one.+//+// The shell is built ONCE and then patched in place on every poll. It used to be+// re-rendered wholesale, which silently destroyed the mounted <agent-3d> on the+// first 20s tick and left "embodying…" on screen forever: the page's centerpiece+// vanished 20 seconds after load. Only data-bearing regions are replaced now, and+// the stage the body lives in is never touched.import { apiFetch } from './api.js';import { countUp, enterStagger, liveDot, setLiveDot, reducedMotion } from './ui-juice.js';@@ -24,15 +30,17 @@ const state = {el3d: null, // the embodied <agent-3d>embodied: false,lastScore: null, // last reputation value drawn, so the ring only re-sweeps on a real change+ shell: false, // the stable layout has been built+ filter: 'trade', // decision stream lens: 'trade' | 'all'};// ── utilities ─────────────────────────────────────────────────────────────────function esc(s) {return String(s ?? '').replace(/[&<>"']/g, (c) => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }[c]));}-function shortMint(m) { return m ? `${m.slice(0, 4)}…${m.slice(-4)}` : ''; }+function shortRef(m) { return m ? `${m.slice(0, 4)}…${m.slice(-4)}` : ''; }function fmtSol(n) { const v = Number(n) || 0; return `${v >= 0 ? '+' : ''}${v.toFixed(3)}`; }-function fmtPct(n) { if (n == null || !Number.isFinite(Number(n))) return '—'; const v = Number(n); return `${v >= 0 ? '+' : ''}${v.toFixed(1)}%`; }+function fmtPct(n) { if (n == null || !Number.isFinite(Number(n))) return 'n/a'; const v = Number(n); return `${v >= 0 ? '+' : ''}${v.toFixed(1)}%`; }function pnlClass(n) { const v = Number(n) || 0; return v > 0 ? 'agi-pos' : v < 0 ? 'agi-neg' : ''; }function timeAgo(iso) {const t = new Date(iso).getTime();@@ -47,6 +55,7 @@ function solscanToken(mint, network) {if (!mint) return null;return network === 'devnet' ? `https://solscan.io/token/${mint}?cluster=devnet` : `https://solscan.io/token/${mint}`;}+const $ = (sel) => root.querySelector(sel);// ── data ────────────────────────────────────────────────────────────────────async function fetchState() {@@ -59,13 +68,13 @@ async function fetchState() {return res.json();}-// ── embodiment: cognition → 3D body + aura ────────────────────────────────────+// ── embodiment: cognition to 3D body + aura ───────────────────────────────────// Valence ∈ [-1,1], arousal ∈ [0,1]. The aura is the one chromatic license on a-// monochrome surface: hue tracks valence (red→slate→green), strength tracks arousal.+// monochrome surface: hue tracks valence (red/slate/green), strength tracks arousal.function auraFor(valence, arousal) {const v = Math.max(-1, Math.min(1, Number(valence) || 0));const a = Math.max(0, Math.min(1, Number(arousal) || 0));- const hue = v >= 0 ? 210 - v * 65 : 210 + v * 202; // 210 neutral → 145 green / 8 red+ const hue = v >= 0 ? 210 - v * 65 : 210 + v * 202; // 210 neutral, 145 green, 8 redconst sat = Math.round(35 + Math.abs(v) * 45);return {aura: `hsla(${hue.toFixed(0)}, ${sat}%, 56%, 0.42)`,@@ -104,6 +113,10 @@ function mountBody(agent) {el.setAttribute('avatar-chat', 'off');el.setAttribute('responsive', '');el.setAttribute('eager', '');+ // The body is a graphic: name it for screen readers, since the canvas inside+ // carries no text of its own.+ el.setAttribute('role', 'img');+ el.setAttribute('aria-label', agent?.name ? `Live 3D body of ${agent.name}, the trading agent` : 'Live 3D body of the trading agent');if (agent?.id) el.setAttribute('agent-id', agent.id);else el.setAttribute('body', '/avatars/default.glb');// Reveal only once the model is in; until then the boot line shows.@@ -122,33 +135,36 @@ function mountBody(agent) {state.el3d = el;}-// ── render: hero ──────────────────────────────────────────────────────────────-function renderHero(d) {- const { doctrine, cognition: cog, agent } = d;+// ── hero ──────────────────────────────────────────────────────────────────────+function heroActions(agent) {const ledgerHref = agent?.id ? `/ledger/${agent.id}` : '/ledger';- return `- <section class="agi-hero">- <div class="agi-hero-copy">- <span class="agi-domain-tag"><i class="agi-dot"></i> ${esc(doctrine.domain)}</span>- <h1 class="agi-title" id="agi-title">The first AGI.<br /><span class="agi-em">Narrow by design.</span></h1>- <p class="agi-lede">${esc(doctrine.thesis)}</p>- <p class="agi-thesis">It is not a chatbot pretending to be smart. It is a single autonomous agent that out-trades humans at one game, and tells you plainly it can do nothing else.</p>- <div class="agi-hero-actions">- <a class="agi-btn agi-btn-primary" href="${ledgerHref}">Audit its track record →</a>- <a class="agi-btn" href="/trader/${agent?.id || ''}">Live trades</a>- </div>- </div>- <div class="agi-stage" id="agi-stage" aria-label="Live embodiment of the trading agent">- <div class="agi-stage-boot">embodying…</div>- <div class="agi-stage-floor">- <span class="agi-state-pill"><i class="agi-spark"></i> ${esc(cog.label)}</span>- <span class="agi-conviction">${cog.conviction != null ? `conviction ${Math.round(cog.conviction * 100)}%` : 'scanning'}</span>- </div>- </div>- </section>`;+ // With no designated agent yet there is no per-trader page to send anyone to,+ // so the second action points at the platform-wide live trade feed instead of+ // a /trader/ URL with a missing id.+ const second = agent?.id+ ? `<a class="agi-btn" href="/trader/${esc(agent.id)}">Live trades</a>`+ : `<a class="agi-btn" href="/activity">Watch live agent trades</a>`;+ return `<a class="agi-btn agi-btn-primary" href="${esc(ledgerHref)}">Audit its track record →</a>${second}`;}-// ── render: live mind ───────────────────────────────────────────────────────+function updateHero(d) {+ const { doctrine, cognition: cog, agent } = d;+ const domain = $('[data-f="domain"]');+ if (domain) domain.textContent = doctrine.domain;+ const lede = $('[data-f="thesis"]');+ if (lede) lede.textContent = doctrine.thesis;+ const label = $('[data-f="cog-label"]');+ if (label) label.textContent = cog.label;+ const conv = $('[data-f="conviction"]');+ if (conv) conv.textContent = cog.conviction != null ? `conviction ${Math.round(cog.conviction * 100)}%` : 'scanning';+ const actions = $('#agi-actions');+ if (actions) {+ const next = heroActions(agent);+ if (actions.innerHTML !== next) actions.innerHTML = next;+ }+}++// ── the mind (decision stream) ────────────────────────────────────────────────function renderThought(t, network, fresh) {const reconciled = t.outcome?.status === 'reconciled';const verdict = reconciled@@ -158,13 +174,18 @@ function renderThought(t, network, fresh) {: `<span class="agi-verdict pending">open call</span>`;const conf = t.confidence != null ? Math.round(t.confidence * 100) : null;const tokenUrl = solscanToken(t.mint, network);+ // Only a real mint gets a Solscan link. An operational call's subject is an+ // internal id, so it renders as plain text rather than a link to nothing.+ const subject = t.mint+ ? `<span class="agi-thought-mint">${tokenUrl ? `<a href="${esc(tokenUrl)}" target="_blank" rel="noopener">${esc(shortRef(t.mint))}</a>` : esc(shortRef(t.mint))}</span>`+ : t.subject_ref+ ? `<span class="agi-thought-mint agi-thought-ref" title="${esc(t.subject_ref)}">${esc(shortRef(t.subject_ref))}</span>`+ : '';const proof = reconciled && t.outcome.proof_url ? ` · <a href="${esc(t.outcome.proof_url)}" target="_blank" rel="noopener">proof</a>` : '';return `<article class="agi-thought${fresh ? ' agi-fresh' : ''}"><div class="agi-thought-top">- <span class="agi-thought-kind">▸ ${esc(t.kind || 'decision')}- ${t.mint ? `<span class="agi-thought-mint">${tokenUrl ? `<a href="${esc(tokenUrl)}" target="_blank" rel="noopener">${esc(shortMint(t.mint))}</a>` : esc(shortMint(t.mint))}</span>` : ''}- </span>+ <span class="agi-thought-kind">▸ ${esc(t.kind || 'decision')}${subject}</span><span class="agi-thought-time">${esc(timeAgo(t.decided_at))}</span></div>${t.rationale ? `<p class="agi-thought-body">${esc(t.rationale)}</p>` : ''}@@ -175,26 +196,41 @@ function renderThought(t, network, fresh) {</article>`;}-function renderMind(d) {- const list = d.decisions || [];- const body = list.length+function visibleDecisions(d) {+ const all = d.decisions || [];+ return state.filter === 'trade' ? all.filter((t) => t.domain !== 'operations') : all;+}++function updateFilter(d) {+ const all = d.decisions || [];+ const trades = all.filter((t) => t.domain !== 'operations').length;+ const host = $('#agi-filter');+ if (!host) return;+ // The lens only earns its place once the agent logs both kinds of call.+ if (!trades || trades === all.length) { host.hidden = true; host.innerHTML = ''; return; }+ host.hidden = false;+ const chip = (key, label, n) =>+ `<button type="button" class="agi-chip" data-filter="${key}" aria-pressed="${state.filter === key}">${label} <span class="agi-chip-n">${n}</span></button>`;+ host.innerHTML = chip('trade', 'Trading calls', trades) + chip('all', 'Everything it decided', all.length);+}++function updateMind(d) {+ const host = $('#agi-stream-host');+ if (!host) return;+ const list = visibleDecisions(d);+ const total = (d.decisions || []).length;+ host.innerHTML = list.length? `<div class="agi-stream">${list.map((t) => renderThought(t, d.network, !state.seen.has(t.id))).join('')}</div>`- : `<div class="agi-empty"><p>No decisions logged in this window yet. Every call it makes will appear here, with its reasoning, its stated confidence, and, once the trade resolves, whether it was right.</p></div>`;- list.forEach((t) => state.seen.add(t.id));- return `- <section class="agi-card agi-mind">- <div class="agi-section-head">- <h2>The mind, out loud</h2>- <span class="agi-mind-meta">- <span class="agi-section-sub">every call, tamper-evident</span>- ${liveDot('live', { label: 'live' })}- </span>- </div>- ${body}- </section>`;+ : total+ ? `<div class="agi-empty"><p>No trading calls in this window: everything it logged recently was operational self-tuning.</p><button type="button" class="agi-btn" data-filter="all">Show everything it decided</button></div>`+ : `<div class="agi-empty"><p>No decisions logged in this window yet. Every call it makes will appear here, with its reasoning, its stated confidence, and, once the trade resolves, whether it was right.</p></div>`;+ // Mark the whole payload seen, not just the visible slice, so flipping the lens+ // never re-animates a call the reader already watched arrive.+ (d.decisions || []).forEach((t) => state.seen.add(t.id));+ enterStagger(host.querySelectorAll('.agi-thought.agi-fresh'), { step: 60 });}-// ── render: track record ──────────────────────────────────────────────────────+// ── track record ──────────────────────────────────────────────────────────────function ring(score) {const r = 40, c = 2 * Math.PI * r;const pct = Math.max(0, Math.min(100, Number(score) || 0));@@ -218,8 +254,8 @@ function ring(score) {// Sweep the reputation ring from its previous fill to the new one and count the// number up in step. Only animates on a real change; reduced motion lands final.function playRecord() {- const num = root.querySelector('.agi-ring-num b');- const arc = root.querySelector('.agi-ring-val');+ const num = $('.agi-ring-num b');+ const arc = $('.agi-ring-val');if (num) {const to = Number(num.dataset.score) || 0;const from = Number(num.dataset.from) || 0;@@ -240,22 +276,20 @@ function stat(k, v, cls = '') {return `<div class="agi-stat"><div class="k">${esc(k)}</div><div class="v ${cls}">${v}</div></div>`;}-function renderRecord(d) {+function recordMarkup(d) {const p = d.performance;const rep = d.reputation;const agent = d.agent;if (!p) {return `- <section class="agi-card">- <div class="agi-section-head"><h2>Track record</h2></div>- <div class="agi-empty"><p>The track record fills in as soon as the agent closes its first proven trade. Nothing is shown until it's real and on-chain.</p></div>- </section>`;+ <div class="agi-section-head"><h2>Track record</h2></div>+ <div class="agi-empty"><p>The track record fills in as soon as the agent closes its first proven trade. Nothing is shown until it's real and on-chain.</p></div>`;}- const winRate = p.win_rate != null ? `${Math.round(p.win_rate * 100)}%` : '—';- const hit = p.snipe_hit_rate != null ? `${Math.round(p.snipe_hit_rate * 100)}%` : '—';+ const winRate = p.win_rate != null ? `${Math.round(p.win_rate * 100)}%` : 'n/a';+ const hit = p.snipe_hit_rate != null ? `${Math.round(p.snipe_hit_rate * 100)}%` : 'n/a';const positions = (d.positions || []).map((pos) => {const url = solscanToken(pos.mint, d.network);- const label = pos.symbol || shortMint(pos.mint);+ const label = pos.symbol || shortRef(pos.mint);return `<div class="agi-position"><span>${url ? `<a href="${esc(url)}" target="_blank" rel="noopener">${esc(label)}</a>` : esc(label)}</span><span class="${pnlClass(pos.unrealized_pct)}">${fmtPct(pos.unrealized_pct)}</span></div>`;}).join('');const calNote = rep && rep.sample_size@@ -263,70 +297,126 @@ function renderRecord(d) {: `Regressed toward neutral, too few reconciled calls to trust yet.`;const ledgerHref = agent?.id ? `/ledger/${agent.id}` : '/ledger';return `- <section class="agi-card">- <div class="agi-section-head">- <h2>Track record</h2>- <span class="agi-section-sub">${p.verified ? 'verified trader' : 'unverified'}</span>- </div>- <div class="agi-rep">- ${ring(rep ? rep.score : p.score)}- <div class="agi-rep-side">${calNote}</div>+ <div class="agi-section-head">+ <h2>Track record</h2>+ <span class="agi-section-sub">${p.verified ? 'verified trader' : 'unverified'}</span>+ </div>+ <div class="agi-rep">+ ${ring(rep ? rep.score : p.score)}+ <div class="agi-rep-side">${calNote}</div>+ </div>+ <div class="agi-stats">+ ${stat('Win rate', winRate)}+ ${stat('Realized P&L', `<span class="${pnlClass(p.realized_pnl_sol)}">${fmtSol(p.realized_pnl_sol)} SOL</span>`)}+ ${stat('Snipe hit rate', hit)}+ ${stat('ROI', `<span class="${pnlClass(p.roi_pct)}">${fmtPct(p.roi_pct)}</span>`)}+ ${stat('Closed trades', String(p.closed_count ?? 0))}+ ${stat('Coins traded', String(p.unique_coins ?? 0))}+ </div>+ ${positions ? `<div class="agi-section-head agi-open-head"><h3>Open now</h3><span class="agi-section-sub"><span class="${pnlClass(p.unrealized_pnl_sol)}">${fmtSol(p.unrealized_pnl_sol)} SOL unrealized</span></span></div><div class="agi-positions">${positions}</div>` : ''}+ <p class="agi-honesty">Being wrong is visible, that's the point. Every loss above is counted, never hidden. <a href="${esc(ledgerHref)}">Interrogate the full ledger →</a></p>`;+}++function updateRecord(d) {+ const host = $('#agi-record');+ if (!host) return;+ host.innerHTML = recordMarkup(d);+ playRecord();+ const drawn = $('.agi-ring-num b');+ if (drawn) state.lastScore = Number(drawn.dataset.score);+}++// ── doctrine ──────────────────────────────────────────────────────────────────+function updateDoctrine(d) {+ const host = $('#agi-doctrine');+ if (!host) return;+ const { doctrine } = d;+ const next = `+ <div class="agi-doctrine-grid">+ <div class="agi-card agi-claim">+ <h3>What it is</h3>+ <ul class="agi-list">+ <li><span class="agi-mark" aria-hidden="true">✓</span><span>Superhuman at <b>${esc(doctrine.domain)}</b>, reading launches, the wallet graph, and order flow faster and more consistently than a human.</span></li>+ <li><span class="agi-mark" aria-hidden="true">✓</span><span>Fully autonomous: it sizes, enters, and exits on its own, inside hard spend caps and a kill switch.</span></li>+ <li><span class="agi-mark" aria-hidden="true">✓</span><span>Accountable: every decision is logged with its reasoning and reconciled against the real outcome.</span></li>+ </ul></div>- <div class="agi-stats">- ${stat('Win rate', winRate)}- ${stat('Realized P&L', `<span class="${pnlClass(p.realized_pnl_sol)}">${fmtSol(p.realized_pnl_sol)} SOL</span>`)}- ${stat('Snipe hit rate', hit)}- ${stat('ROI', `<span class="${pnlClass(p.roi_pct)}">${fmtPct(p.roi_pct)}</span>`)}- ${stat('Closed trades', String(p.closed_count ?? 0))}- ${stat('Coins traded', String(p.unique_coins ?? 0))}+ <div class="agi-card agi-refuse">+ <h3>What it refuses</h3>+ <ul class="agi-list">+ ${doctrine.refusals.map((r) => `<li><span class="agi-mark" aria-hidden="true">✕</span><span>${esc(r)}</span></li>`).join('')}+ </ul></div>- ${positions ? `<div class="agi-section-head" style="margin-bottom:var(--space-sm)"><h2 style="font-size:var(--text-md)">Open now</h2><span class="agi-section-sub">${pnlClass(p.unrealized_pnl_sol) === 'agi-neg' ? '' : ''}<span class="${pnlClass(p.unrealized_pnl_sol)}">${fmtSol(p.unrealized_pnl_sol)} SOL unrealized</span></span></div><div class="agi-positions">${positions}</div>` : ''}- <p class="agi-honesty">Being wrong is visible, that's the point. Every loss above is counted, never hidden. <a href="${ledgerHref}">Interrogate the full ledger →</a></p>- </section>`;+ </div>`;+ if (host.innerHTML !== next) host.innerHTML = next;}-// ── render: doctrine ──────────────────────────────────────────────────────────-function renderDoctrine(d) {- const { doctrine } = d;- return `- <section class="agi-doctrine">- <div class="agi-doctrine-grid">- <div class="agi-card agi-claim">- <h3>What it is</h3>- <ul class="agi-list">- <li><span class="agi-mark">✓</span><span>Superhuman at <b>${esc(doctrine.domain)}</b>, reading launches, the wallet graph, and order flow faster and more consistently than a human.</span></li>- <li><span class="agi-mark">✓</span><span>Fully autonomous: it sizes, enters, and exits on its own, inside hard spend caps and a kill switch.</span></li>- <li><span class="agi-mark">✓</span><span>Accountable: every decision is logged with its reasoning and reconciled against the real outcome.</span></li>- </ul>- </div>- <div class="agi-card agi-refuse">- <h3>What it refuses</h3>- <ul class="agi-list">- ${doctrine.refusals.map((r) => `<li><span class="agi-mark">✕</span><span>${esc(r)}</span></li>`).join('')}- </ul>+// ── shell ─────────────────────────────────────────────────────────────────────+// Built once, then patched. Nothing in here that the 3D body lives inside is ever+// replaced, so the mounted element survives every poll.+function buildShell() {+ root.innerHTML = `+ <section class="agi-hero">+ <div class="agi-hero-copy">+ <span class="agi-domain-tag"><i class="agi-dot" aria-hidden="true"></i> <span data-f="domain"></span></span>+ <h1 class="agi-title" id="agi-title">The first AGI.<br /><span class="agi-em">Narrow by design.</span></h1>+ <p class="agi-lede" data-f="thesis"></p>+ <p class="agi-thesis">It is not a chatbot pretending to be smart. It is a single autonomous agent that out-trades humans at one game, and tells you plainly it can do nothing else.</p>+ <div class="agi-hero-actions" id="agi-actions"></div>+ </div>+ <div class="agi-stage" id="agi-stage">+ <div class="agi-stage-boot">embodying…</div>+ <div class="agi-stage-floor">+ <span class="agi-state-pill"><i class="agi-spark" aria-hidden="true"></i> <span data-f="cog-label"></span></span>+ <span class="agi-conviction" data-f="conviction"></span></div></div>- </section>`;+ </section>+ <div class="agi-grid">+ <section class="agi-card agi-mind">+ <div class="agi-section-head">+ <h2>The mind, out loud</h2>+ <span class="agi-mind-meta">+ <span class="agi-section-sub">every call, tamper-evident</span>+ ${liveDot('live', { label: 'live' })}+ </span>+ </div>+ <div class="agi-filter" id="agi-filter" role="group" aria-label="Filter the decision stream" hidden></div>+ <div id="agi-stream-host"></div>+ </section>+ <section class="agi-card" id="agi-record"></section>+ </div>+ <section class="agi-doctrine" id="agi-doctrine"></section>`;+ // One delegated handler covers the filter chips and the empty state's escape+ // hatch, so a re-rendered stream never loses its wiring.+ root.addEventListener('click', (e) => {+ const btn = e.target.closest('[data-filter]');+ if (!btn || !root.contains(btn)) return;+ const next = btn.dataset.filter === 'all' ? 'all' : 'trade';+ if (next === state.filter) return;+ state.filter = next;+ if (state.data) { updateFilter(state.data); updateMind(state.data); }+ });+ state.shell = true;}-// ── full render ───────────────────────────────────────────────────────────────function render(d) {- root.innerHTML = renderHero(d) + `<div class="agi-grid">${renderMind(d)}${renderRecord(d)}</div>` + renderDoctrine(d);+ if (!state.shell) buildShell();+ updateHero(d);+ updateFilter(d);+ updateMind(d);+ updateRecord(d);+ updateDoctrine(d);applyAura(d.cognition);mountBody(d.agent);if (state.embodied) applyMood(d.cognition);- // Only the decisions newly seen this tick slide in — the rest are already settled.- enterStagger(root.querySelectorAll('.agi-thought.agi-fresh'), { step: 60 });- playRecord();- const drawn = root.querySelector('.agi-ring-num b');- if (drawn) state.lastScore = Number(drawn.dataset.score);}function renderLoading() {root.innerHTML = `<section class="agi-hero"><div class="agi-hero-copy">- <span class="agi-domain-tag"><i class="agi-dot"></i> memecoin trading · pump.fun</span>+ <span class="agi-domain-tag"><i class="agi-dot" aria-hidden="true"></i> memecoin trading · pump.fun</span><h1 class="agi-title">The first AGI.<br /><span class="agi-em">Narrow by design.</span></h1><div class="agi-skel" style="height:80px;max-width:46ch"></div></div>@@ -336,15 +426,23 @@ function renderLoading() {<section class="agi-card"><div class="agi-skel" style="height:300px"></div></section><section class="agi-card"><div class="agi-skel" style="height:300px"></div></section></div>`;+ state.shell = false;}function renderError() {root.innerHTML = `<div class="agi-error">- <h2 style="font-family:var(--font-display);color:var(--ink)">The agent is unreachable</h2>+ <h2>The agent is unreachable</h2><p>Couldn't load the AGI's live state right now. This is a transient connection issue, the agent keeps trading regardless.</p>- <button class="agi-btn agi-btn-primary" id="agi-retry" type="button">Retry</button>+ <div class="agi-error-actions">+ <button class="agi-btn agi-btn-primary" id="agi-retry" type="button">Retry</button>+ <a class="agi-btn" href="/ledger">Browse the proof ledger</a>+ <a class="agi-btn" href="/activity">Watch live agent trades</a>+ </div></div>`;+ state.shell = false;+ state.el3d = null;+ state.embodied = false;document.getElementById('agi-retry')?.addEventListener('click', () => { renderLoading(); boot(); });}@@ -359,7 +457,7 @@ async function refresh() {if (!state.data) renderError();// Keep the last good render up, but mark the live feed as reconnecting so the// "live" dot tells the truth until the next tick recovers.- else setLiveDot(root.querySelector('.agi-mind'), 'error', 'reconnecting');+ else setLiveDot($('.agi-mind'), 'error', 'reconnecting');}}diff --git a/tests/agi-state.test.js b/tests/agi-state.test.jsindex 28a536187..cf1293453 100644--- a/tests/agi-state.test.js+++ b/tests/agi-state.test.js@@ -34,9 +34,35 @@ describe('shapeDecision', () => {expect(out.seq).toBe(12);expect(out.confidence).toBe(0.72);expect(out.mint).toBe('FeMbDoX7R1Psc4GEcvJdsbNbZA3bfztcyDCatJVJpump');+ expect(out.domain).toBe('trade');expect(out.outcome).toEqual({ status: 'pending' });});+ it('refuses to publish a non-address subject as a mint', () => {+ // The self-tuner keys its decisions by an internal arm uuid. Publishing that+ // as `mint` sent the page to solscan.io/token/<uuid>, a link to nothing.+ const out = shapeDecision(+ decision({ kind: 'optimize', subject_ref: 'bcb3de15-7b9e-4a22-a653-8076f624c908' }),+ 'mainnet',+ );+ expect(out.mint).toBeNull();+ expect(out.subject_ref).toBe('bcb3de15-7b9e-4a22-a653-8076f624c908');+ expect(out.domain).toBe('operations');+ });++ it('classifies a trading verb as a trade even when its subject is not a mint', () => {+ const out = shapeDecision(decision({ kind: 'exit', subject_ref: 'position-4711' }), 'mainnet');+ expect(out.mint).toBeNull();+ expect(out.domain).toBe('trade');+ });++ it('carries a null subject through without inventing one', () => {+ const out = shapeDecision(decision({ kind: 'optimize', subject_ref: null }), 'mainnet');+ expect(out.mint).toBeNull();+ expect(out.subject_ref).toBeNull();+ expect(out.domain).toBe('operations');+ });+it('attaches the on-chain proof url once an outcome is reconciled', () => {const out = shapeDecision(decision({